# Plugin manifest

Every plugin has a `phantom-plugin.json` at the top of its package.
Phantom reads it before anything else and refuses the package if any
field is wrong, with the reason.

```json
{
  "sdk": 1,
  "id": "findings-csv",
  "name": "Findings CSV",
  "version": "1.0.0",
  "description": "Exports the findings of a report as a CSV table.",
  "author": "Your name",
  "license": "MIT",
  "homepage": "https://example.com/findings-csv",
  "entry": "plugin.py",
  "permissions": ["reports.read"],
  "contributes": {
    "report_formats": [
      {"id": "csv", "label": "Findings (CSV)", "handler": "export_csv", "extension": "csv", "media_type": "text/csv"}
    ]
  }
}
```

## Fields

| Field | Required | Rule |
|---|---|---|
| `sdk` | yes | `1`, the SDK this Phantom runs |
| `id` | yes | lowercase letters, digits and single hyphens; identifies the plugin across versions |
| `name` | yes | up to 80 characters |
| `version` | yes | `MAJOR.MINOR.PATCH` |
| `description`, `author`, `license` | no | shown in Settings › Plugins |
| `homepage` | no | an `https://` address |
| `entry` | no | the Python file with the handlers, at the top of the package; `plugin.py` by default |
| `permissions` | yes | what the contributions need (below) |
| `contributes` | yes | at least one contribution |

Unknown fields are refused, so a misspelt field never silently does
nothing.

## Permissions

| Permission | Needed by | Means |
|---|---|---|
| `reports.read` | `report_formats` | reads reports you export with it, masked by your export policy |
| `flows.import` | `importers` | turns files you import with it into HTTP history |
| `bodies.read` | `renderers` | reads message bodies you open with it, masked unless you reveal them |
| `findings.send` | `service_adapters` | prepares tickets you send with it to a service you configure; Phantom adds your credential and sends them |

A contribution without its permission is refused, and so is a permission
no contribution uses. The user grants all of a plugin's permissions at
once, or the plugin does not run.

## Contributions

Every contribution has an `id` (unique within its kind), a `label` shown
in the interface, and a `handler`: the name of a public function in the
entry file.

**`report_formats`** also have `extension` (without the dot) and
`media_type`. HTML and SVG are not allowed, because a downloaded file
must never run script in the browser.

**`importers`** have `extensions`: the file extensions the file picker
offers, such as `["xml"]`.

**`renderers`** have `media_types`: exact types such as
`application/json`, or families such as `text/*`.

**`service_adapters`** have a second handler, `parse`, and `auth`: how
Phantom adds the user's credential to the request (`bearer`, `token`,
`basic` with the tracker's account, or `header` with the header named in
`auth_header`, such as `X-Api-Key`).

## Package rules

- A zip of at most 5 MiB that unpacks to at most 20 MiB and 200 files.
- Python, text and data files only (`.py`, `.json`, `.md`, `.txt`,
  `.csv`, `.xml`, `.yaml`, `.toml`, `.cfg`, and `LICENSE`, `NOTICE`,
  `README`).
- No paths that leave the package, no links, no hidden files.
- Compiled Python (`__pycache__`, `.pyc`) is skipped, so only the source
  runs.
