# Documentize.AssemblyChat

Inspects a .NET assembly (local or from NuGet) and answers questions about its API surface.

This project is one of the standalone-publishable plugins under `Plugins/`. It has no
`ProjectReference` to other projects in the repo — every file it needs is linked directly into
its `.csproj` — so it builds and publishes independently of the rest of the solution.

## Requirements

- .NET 10 SDK to build; the .NET 10 runtime is enough to run a published build.
- An Aspose Documentize license file, `documentize.lic`, placed next to the published binary (the plugin runs unlicensed/evaluation mode if it is absent).
- Outbound HTTPS access to the configured LLM endpoint (`EP_API_URL`/`EP_TOKEN` or `DW_API_URL`/`DW_TOKEN` environment variables — see `Documentize.Entities.Llm.LlmOwnerResolver`).

### OS packages

This plugin shells out to the `dotnet` CLI itself (to load/inspect assemblies) and, when a
NuGet package is requested, downloads it over HTTPS from `api.nuget.org` — so it needs the
**.NET SDK** (not just the runtime) and outbound internet access, in addition to the standard
Aspose font/GDI+ requirements used for any generated PDF/SVG output.

#### Windows
1. Install the .NET SDK (not just the runtime): https://dotnet.microsoft.com/download
2. No extra font/GDI+ setup needed.

#### Linux (primary platform)
```bash
sudo apt-get update
sudo apt-get install -y libgdiplus fontconfig fonts-liberation fonts-dejavu-core
# Install the .NET SDK (matching net10.0), e.g. via the official install script:
curl -LO https://dot.net/v1/dotnet-install.sh
chmod +x dotnet-install.sh
./dotnet-install.sh --channel 10.0
```
Outbound HTTPS access to `api.nuget.org` is required when `--nuget-package` is used.

## Build

```bash
dotnet build Documentize.AssemblyChat.csproj -c Release
```

## Publish a standalone build

```bash
# Linux (framework-dependent, needs the .NET 10 runtime installed on the target machine)
dotnet publish Documentize.AssemblyChat.csproj -c Release -r linux-x64 --self-contained false -o ./publish/linux

# Windows
dotnet publish Documentize.AssemblyChat.csproj -c Release -r win-x64 --self-contained false -o ./publish/win

# Fully self-contained (no .NET runtime required on the target machine, larger output)
dotnet publish Documentize.AssemblyChat.csproj -c Release -r linux-x64 --self-contained true -o ./publish/linux-standalone
```

## Run

### From the terminal (Linux) / cmd or PowerShell (Windows)

Using `dotnet run` from source:
```bash
dotnet run --project Documentize.AssemblyChat.csproj -- --command value --query value
```

Using a published build:
```bash
# Linux
./publish/linux/Documentize.AssemblyChat --command value --query value

# Windows (cmd.exe or PowerShell)
.\publish\win\Documentize.AssemblyChat.exe --command value --query value
```

Show all available options:
```bash
./publish/linux/Documentize.AssemblyChat --help
```

### CLI options

| Flag | Type | Default | Description |
|---|---|---|---|
| `--command` | string | `"scan"` | Operation to run (default 'scan'). |
| `--query` | string | `""` | User query/prompt. |
| `--nuget-package` | string | `null` | NuGet package id to analyze; null = none. |
| `--nuget-version` | string | `null` | NuGet package version; null = latest. |
| `--generate-svg` | bool | `false` | Also render an SVG diagram. |
| `--alt` | int | `null` | Optional alternative-rendering index. |

Every plugin also accepts `--task-id <guid>` (alias `--id`) to set the task id used for the
input/output working directories; if omitted, a new GUID is generated.

### Alternative input: base64 task JSON

For compatibility with the Plugin Manager (and as a drop-in alternative to flags), the plugin
also accepts a single base64-encoded JSON argument instead of `--flags`. The JSON uses the same
PascalCase property names as the options above, plus an `"ID"` field for the task id:

```json
{ "ID": "b1e6a4b0-0000-0000-0000-000000000000", "Command": "", "Query": "", "NugetPackage": "", "NugetVersion": "", "GenerateSvg": false, "Alt": 1 }
```

```bash
python3 -c "import base64,json; print(base64.b64encode(json.dumps({ \"ID\": \"b1e6a4b0-0000-0000-0000-000000000000\", \"Command\": \"\", \"Query\": \"\", \"NugetPackage\": \"\", \"NugetVersion\": \"\", \"GenerateSvg\": false, \"Alt\": 1 }).encode()).decode())"
./publish/linux/Documentize.AssemblyChat <base64-string-from-above>
```

### Manager hot-process mode

`--pool` puts the plugin into the Plugin Manager's stdin/stdout worker-pool protocol
(`READY` / `{taskId} {base64}` per line / `DONE:{taskId}` or `FAIL:{taskId}:{msg}`).
This mode is only used by `Documentize.Plugin.Manager` — not intended for direct/manual use.

## Exit codes

| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | The task ran but failed (see stderr for the exception) |
| 2 | Usage/argument error (missing required option, invalid value, `--help`) |
