# Build a plugin: SDK, manifest and signing

How to build a Truetask plugin: the scaffold, the manifest, contribution points, settings, agent tools, scheduled work, the build's checks, tests and signing.

URL: https://docs.truetask.io/plugins/building

A Truetask plugin is a Svelte frontend and a Python backend, described by a manifest and packed into one `.ttp` file.
You start from a scaffold that already uses every piece, and the full contract is the authoring guide in the Truetask source tree, `docs/plugin-authoring.md`.

## What you need

- Node 20 or newer, and Python 3.11 or newer.
- The two packages: `@truetask/plugin-sdk` for the frontend and `truetask-plugin` for the backend.
  They ship in the Truetask source tree, as `sdk/plugin-sdk` and `sdk/python-plugin`, not on npm or PyPI.
  A plugin in a repository of its own points at them, for example `"@truetask/plugin-sdk": "file:../truetask-source/sdk/plugin-sdk"` in its `package.json`, and installs the Python one with `pip install -e`.
- A throwaway workspace to install into, and its owner's API token for the tests.
  Never test against a workspace people work in: the test teardown deletes the plugin's data.

## Scaffold a plugin

```bash
scripts/tt plugin new shot_review --name "Shot Review"
```

`tt` is `scripts/tt` in the Truetask source tree; put `scripts/` on your PATH and it is `tt plugin new`.
It writes a working plugin with one of every contribution point, drawn the way Truetask's own plugins are: a page of panels with a table, a chart and figures that filter, saved views and filters on its view row, settings in tabs, a backend with its own collections, a migration, the five locales and a test.
Its README says what to change first.

```
shot_review/
  manifest.json            what the plugin declares; the installer validates it
  src/                     the frontend source: built, never shipped
    index.js               one export per contribution, plus commands and activate
  frontend/                the built bundle (git-ignored)
  backend/__init__.py      register(app, sdk): the routes and handlers
  collections/schema.json  the plugin's own shot_review_* collections
  migrations/              up(sdk) per file, in filename order
  locales/                 en, es, fr, de, pt
  tests/                   installs it on a workspace and calls its routes
  vite.config.js
  package.json
```

**The id is a namespace.**
`shot_review` owns every collection named `shot_review_*` and every route under its prefix, and the installer refuses an id whose namespace already holds something.
An id must start with a letter and use lowercase letters, digits and underscores.
Pick it once: renaming it later makes a new plugin.

## The manifest

```json
{
  "id": "shot_review",
  "name": "Shot Review",
  "version": "1.0.0",
  "core": ">=1.3.118 <2.0.0",
  "description": "Review shots frame by frame.",
  "author": "Northwind Traders",
  "icon": "icon.svg",
  "category": "production_tracking",
  "frontend": "frontend/index.js",
  "styles": "frontend/index.css",
  "backend": "backend",
  "collections": "collections/schema.json",
  "permissions": { "collections": { "cards": "read" }, "notify": true },
  "contributions": {}
}
```

| Key | What it is |
| --- | --- |
| `core` | Required. The Truetask versions the plugin runs on, as comparators that must all hold, or `*`. A workspace outside the range refuses the install and says so. |
| `icon` | An `.svg` or `.png` in the package, 64 kB at most, shown at 56 px on its card. Without one the card shows a puzzle piece. |
| `category` | The Integrations section it is listed under: `production_tracking`, `rendering`, `code`, `messaging`, `ai`, `storage`, `developer` or `other` (the default). |
| `permissions` | What it may reach. An admin reads this before agreeing to the install. |
| `contributions` | What it adds, below. |
| `settings` | The settings it needs, which Truetask draws as a form. |

Every path is relative to the package and may not climb out of it.
An unknown contribution point or settings key is refused rather than ignored, so a typo fails the install instead of quietly adding nothing.

### Permissions

- `collections`: `{"<name>": "read" | "write"}` for every core collection the plugin touches.
  Its own `<id>_*` collections are always writable.
  `write` is only allowed on `files`, where it lets the plugin add a file and nothing more.
- `outbound_hosts`: the hosts the backend may call.
  Anything else is refused, redirects included.
  An entry can be `{settings.<field>}`, meaning the host an admin types into that settings field, for a plugin pointed at a service the workspace runs itself.
- `notify`: whether it may send notifications.
- `helper_actions`: whether its pages may open a file or folder on the person's own computer through [Truetask Helper](https://docs.truetask.io/helper/), and read the workspace's storage roots.

A call to a private address, such as a server on the studio network, goes out through a computer a workspace admin lets reach that host, or, on a self-hosted server, through **Allow private network targets**.
The plugin's code is the same either way.

### Contribution points

| Point | What it adds |
| --- | --- |
| `pages` | A page with an address, a sidebar row, a palette entry and its own sharing. |
| `board_views` | A view in a board's view switcher. |
| `card_tabs` | A chip on the task frame that opens the plugin's sheet. |
| `file_viewers` | A viewer for MIME types. Taking over a type the app already draws needs `"override": true`, which the admin sees before install and can switch off. |
| `file_overlays` | A layer drawn over a file preview, such as markup or a frame counter. |
| `file_anchor_kinds` | A way to point a comment at something in a file, such as a frame. |
| `file_rail_sections` | A section in the file viewer's review rail. |
| `menu_rows` | A row in the App menu (`"parent": "app"`) or a board's page menu (`"board"`). |
| `palette_commands` | A command in the command palette. |
| `automation_nodes` | Triggers and actions in the automation builder. |
| `webhook_events` | Events the backend may announce, for webhooks and automations. |
| `jobs` | Work Truetask runs on an interval. |
| `settings_pane` | A pane of the plugin's own under its settings form, for what a form cannot do. |
| `mcp_tools` | Renames, describes or hides the agent tools its routes become. |

An entry names an `export` in the bundle and a `label_key` into the plugin's own locale files, never a literal string.

### Pages and who may open them

A page declares its `section` (`workspace` by default, or `personal`), and an `access` block: one sentence per level (`viewer`, `editor`, `admin`) in the plugin's own words, and where each site role starts.
The levels are always the board's three; a plugin describes them, it does not invent its own.

`routes` marks which of the plugin's routes need more than `viewer`, such as `{ "path": "renders/remove", "method": "POST", "requires": "admin" }`.
Truetask refuses a marked route below its level before the plugin's code runs, for people and agents alike.
In the backend, `sdk.require_page(...)`, `sdk.page_level(...)` and `sdk.require_admin()` cover what a mark cannot.

## Settings

Declare settings in the manifest and Truetask draws the form, stores the values and hands them to agents.

```json
"settings": {
  "fields": [
    { "key": "service_url", "kind": "text", "label_key": "shot_review.settings.url", "required": true },
    { "key": "api_key", "kind": "text", "secret": true, "label_key": "shot_review.settings.key" }
  ],
  "check": { "path": "check", "method": "POST", "label_key": "shot_review.settings.check" }
}
```

- `kind` is `text`, `long_text`, `number`, `boolean` or `choice`, with optional `default`, `placeholder`, `help_key`, `icon` and `validation` (`pattern`, `min`, `max`, `message_key`).
  A plugin declares at most 40 fields.
- `"secret": true` makes a field write-only: stored encrypted, in no answer, no tool and no log.
  Only the plugin's own backend reads it, through `sdk.settings()`.
- `check` names one of the plugin's routes, which the form draws as a button.
  Answer `{"ok": false, "message": "..."}` for a check that ran and found a problem.
- `tabs` splits the form into tabs, each holding some fields or one of the plugin's own components.

Every plugin with settings gets three agent tools at its Admin level: `plugin_<id>_settings_get`, `plugin_<id>_settings_set` and, with a check, `plugin_<id>_settings_check`.
See [Plugin settings](https://docs.truetask.io/plugins/pages#plugin-settings) for what people see.

## The frontend

`src/index.js` exports one component per `export` the manifest names, plus `commands` (handlers for menu rows and palette commands) and `activate`.
Every component reads the host through one object:

```js
import { use_truetask } from '@truetask/plugin-sdk';
const tt = use_truetask();
```

It carries the plugin's own API routes (`tt.api`), the signed-in person, the theme, `t()` for the plugin's strings, `toast`, `icon()`, `store` for the person's own small choices, and `ui`: the app's own pieces.
Draw with those, never with copies of your own:

- `ui.Panels` for a page of panels people resize, swap, dock and fill the page with.
- `ui.Grid` for tables, with column kinds such as `progress`, `state`, `ago`, `person` and `timeline`, and a pinned totals row.
- `ui.DotBars` for charts of square cells.
- `ui.SavedViews` and `ui.SavedFilters` for a page's view row.
- `ui.UserAvatar` and `ui.PersonPicker` for people.
- The app's controls: `Button`, `DropdownMenu`, `ContextMenu`, `Popover`, `Tooltip`, `Select`, `Tabs`, `Input`, `Checkbox`, `Switch`.

Colours come from the host's tokens (`rgb(var(--accent))`, or `token()` from the SDK), so the plugin is right in light and dark.
Every user-facing string is a key in all five locale files.

## The backend

```python
from __future__ import annotations
from typing import TYPE_CHECKING
from fastapi import APIRouter

if TYPE_CHECKING:
    from truetask_plugin import PluginSDK

def register(app, sdk: "PluginSDK") -> None:
    router = APIRouter()

    @router.get("/rows", summary="This plugin's rows")
    async def list_rows(user=sdk.require_user()):
        page = await sdk.records("shot_review_rows").list(per_page=50, sort="-created")
        return {"rows": page["items"]}

    app.include_router(router, prefix=sdk.route_prefix)
```

`register` runs once when an admin turns the plugin on, in the running workspace, with nothing restarted.
Import `truetask_plugin` only under `TYPE_CHECKING`: the workspace hands you its own `sdk`, and the package is not installed there.
Every router goes under `sdk.route_prefix`, or turning the plugin on fails.

| On `sdk` | What it does |
| --- | --- |
| `records(collection)` | Reads and writes a collection at the level the manifest granted. |
| `quote(value)` | Escapes a value for a filter. Use it on anything that came from a request. |
| `settings()` | The plugin's settings, secrets included. |
| `fetch(...)` | Calls a host the manifest named, through Truetask's outbound guard. |
| `on(event, handler)`, `emit(event, data)` | Hears a core event as it happens; announces one of the plugin's own. |
| `action(key, handler)` | The handler for an automation action the manifest declares. |
| `job(key, handler)`, `job_state(key)` | The handler for scheduled work, and where its last run left off. |
| `health(state, detail)` | Says the service the plugin reads stopped answering, or answers again. |
| `audit(action, ...)` | Leaves a row in the workspace audit log for something done outside Truetask, with the person or agent who asked. |
| `notify(...)`, `files.store(...)` | Sends a notification; adds a file. Each needs its permission. |

### Every route is an agent tool

The routes a backend serves are tools for agents, with nothing more to declare: the name comes from the function (`list_rows` becomes `plugin_shot_review_list_rows`), the description from its `summary` and docstring, and the arguments from its parameters and body.
They reach MCP clients, Truetask AI and the automation **Agent** node, and `tools_find` finds them.
Who may call one is the plugin's page: a caller needs a level on it, and a marked route needs that route's level.
A plugin that declares no page gives its tools to everyone signed in, as it does its routes.

A route with neither a `summary` nor a docstring is refused when you pack.
Use `mcp_tools` to rename or re-describe a tool, or `"mcp": false` to keep a route the interface needs, such as a count a toolbar draws, out of the tool list.
A plugin offers at most 40 tools.

### Data and migrations

A plugin's collections are in `collections/schema.json`: base collections only, every name starting with `<id>_`, at most 20 collections of 100 fields.
Truetask sets their rules: any signed-in member reads them, which is what makes realtime work on the plugin's own surfaces, and only the backend writes them.
The schema is applied each time the plugin is turned on, so an upgrade that adds a field has it.

Moving data is a migration: `migrations/*.py`, each with `up(sdk)`, applied once each in filename order.
A fresh install runs them all against empty collections, so each must do nothing when it finds nothing.
Three helpers cover what migrations do: `sdk.migrations.each`, `sdk.migrations.backfill` and `sdk.migrations.ensure`.

### Scheduled work

Declare a job and Truetask runs it, once per workspace, on the interval you give (60 seconds to 1 day, aligned to the clock):

```json
"jobs": [{ "key": "mirror", "label_key": "shot_review.job.mirror", "interval_seconds": 300 }]
```

Hand the handler over with `sdk.job("mirror", mirror)`.
A job slower than its interval skips the next window rather than running twice, and a job that raises marks the plugin **Needs attention** with the exception's last line, so raise with a sentence an admin can act on.
Never start a background task of your own in `register`.

## What the build checks

`npm run build` writes `frontend/index.js` and `frontend/index.css`, and refuses a plugin that would break on a real workspace:

- **The oldest Truetask it runs on.**
  The build reads what the plugin uses (the Svelte that compiles it, its contribution points, permissions and settings keys, and the host pieces its source draws and calls) and refuses a `core` range that starts earlier, naming what needs the newer Truetask and the range to write.
- **No bundled Svelte.**
  Svelte and the SDK stay bare imports that the workspace resolves to its own copy.
  A bundle carrying its own runtime fails the build.
  Keep `vite.config.js` as the SDK's: `export default truetask_plugin();`.
- **Only the host's colours.**
  A `var(--name)` the host does not publish and the plugin does not declare fails the build.

`tt plugin pack` adds its own checks: every route has a description, every file the manifest names is in the package, and the icon is the small image it claims to be.

## Test it

The test harness installs the plugin on a real workspace, turns it on, calls its routes, and uninstalls it with its data afterwards, whether the test passed or not.

```python
from truetask_plugin.testing import Workspace

def test_the_rows_route_answers():
    with Workspace.from_env().running(".") as plugin:
        assert plugin.health == "ok", plugin.health_detail
        assert plugin.get("rows")["rows"] == []
```

```bash
TRUETASK_URL=http://localhost:8090 TRUETASK_API_TOKEN=<the owner's token> python3 -m pytest tests -q
```

The handle also has `agent_tools()` for the tools an agent will be offered, `jobs()` and `run_job(key)` for scheduled work, and the workspace has `audit_rows(...)` to read back what `sdk.audit` wrote.

## Pack and sign

```bash
tt plugin pack .                                 # builds the frontend, writes ../dist/shot_review-1.0.0.ttp
tt plugin sign ../dist/shot_review-1.0.0.ttp     # writes the signature into the package
tt plugin verify ../dist/shot_review-1.0.0.ttp
tt plugin keygen                                 # makes a publisher key; the private half never leaves this machine
```

Without the source tree's `tt`, `npm run build && python3 -m truetask_plugin pack .` writes the same package into the plugin's own `dist/`.

A `.ttp` is a zip with an extension of its own, built deterministically, so the same source gives the same bytes and the same signature.
The source, `node_modules`, `package.json`, lockfiles and tests stay out of it.
`sign` writes every file's checksum and the publisher's signature over them into the package, and a workspace refuses a package with any file changed after signing.

Install it from **Integrations > Install from a file** on a self-hosted workspace.
A workspace installs a package signed by a publisher key it trusts, and an unsigned one only on a self-hosted server whose operator set `PLUGIN_ALLOW_UNSIGNED`, by the workspace owner, after confirming.
Truetask Cloud installs plugins from the catalog only.
See [Installing and managing plugins](https://docs.truetask.io/plugins/installing).

To ship a new version, bump `version` in the manifest, pack and upgrade.
The plugin's data is kept and its new migrations run; upgrades only go forward.

## A plugin is not a sandbox

A plugin's Python runs inside the workspace's API with a full interpreter, and its frontend runs on the app's own Svelte.
The manifest keeps a plugin to what it declared and refuses the rest on the first run, but it does not stop code that sets out to reach further.
Installing a plugin is trusting its author, and the install dialog says so.

## Related

- [Plugins](https://docs.truetask.io/plugins/)
- [Installing and managing plugins](https://docs.truetask.io/plugins/installing)
- [Plugin pages and settings](https://docs.truetask.io/plugins/pages)
- [Deadline](https://docs.truetask.io/plugins/deadline)
