feat(plugin-sdk): dev server, preflight, auto-PR submit, signing, wizard

Round out the author experience so the loop is create -> dev -> release/submit
without hand-work or a round-trip through registry review.

- `dev`: run a plugin locally with a real request loop and hot reload — no full
  TREK. Injects a ctx that enforces the manifest's granted permissions (an
  ungranted call throws, so you catch a missing grant), backs db:own with a real
  SQLite file (node:sqlite), serves routes under /api and page/widget UI at /ui,
  and reloads on save. Dependency-free (node:http + built-ins).
- `preflight`: run the registry CI checks locally over the network (tag->commit,
  manifest parity, artifact sha256/size, native scan, README quality gate) so a
  green run predicts a green CI.
- `submit`: fork TREK-Plugins, branch off current main, write/merge the entry,
  push, and open the PR — the last manual publishing step, automated.
- `keygen`/`sign` + `--sign` on entry/release/submit: dependency-free Ed25519
  author signatures over the artifact bytes, verified 1:1 against the server's
  TOFU check. Fills authorPublicKey + signature and guards against a key change.
- `create` gains an interactive wizard (id/type/author/permissions) and flags.
- README + Development/Publishing/Permissions wikis document the new flow.

24 tests pass (sign round-trips through a server-shaped verifier; zip reader;
scaffold options; entry signing + key-change guard).
This commit is contained in:
Maurice
2026-07-04 17:07:15 +02:00
committed by Maurice
parent 39f27ef55d
commit cf9be554ac
14 changed files with 962 additions and 66 deletions
+24 -1
View File
@@ -9,10 +9,14 @@ child process** and reaches it only over RPC; the browser part runs in a
## Scaffold
```bash
npx trek-plugin-sdk create my-plugin --type integration|page|widget
npx trek-plugin-sdk create # interactive wizard
npx trek-plugin-sdk create my-plugin --type integration|page|widget # or direct
cd my-plugin
```
The wizard (run `create` with no name) asks for the id, type, author and
permissions; the direct form takes them as flags.
This emits:
```
@@ -23,6 +27,25 @@ my-plugin/
README.md # fill this in — the registry requires a screenshot
```
## Run it locally with hot reload
```bash
npx trek-plugin-sdk dev # http://localhost:4317
```
`dev` loads your `server/index.js` through the same `definePlugin` contract the
host uses and gives you a **real request loop without a full TREK**: a dashboard
listing your routes, the routes served under `/api/<path>`, your page/widget UI
at `/ui`, and a reload on every save. The injected `ctx` **enforces exactly the
permissions your manifest grants** — an ungranted call throws `PERMISSION_DENIED`,
so you catch a missing grant here rather than after install. `db:own` is backed
by a real SQLite file (`.trek-dev/db.sqlite`) when the runtime has `node:sqlite`.
- Hit a route as an unauthenticated request with `?_anon=1` (an `auth: true`
route then returns 401, mirroring the host).
- Feed `ctx.trips` / `ctx.users` by dropping a `dev-fixtures.json` next to the
manifest: `{ "trips": { "1": { "members": [1], "data": { … } } }, "users": {} }`.
## The three plugin types
- **integration** — background logic (jobs, routes) with no UI of its own. Photo-
+5
View File
@@ -77,7 +77,12 @@ flow is in [[Publishing a Plugin|Plugin-Publishing]].
| Command | What it does |
|---|---|
| `trek-plugin create [name]` | Scaffold a plugin. With no name it runs an interactive wizard (id, type, author, permissions); with a name it takes `--type`/`--author`/`--permissions` flags. |
| `trek-plugin dev [dir]` | Run the plugin locally with a real request loop + hot reload — no full TREK. The injected `ctx` enforces your granted permissions, `db:own` is a real SQLite file, routes serve under `/api/<path>`, and page/widget UI at `/ui`. |
| `trek-plugin validate [dir]` | Manifest + layout checks: parses the manifest with the same rules as install, requires a `README.md` (warns if it has no screenshot or still holds template placeholders) and a built `server/index.js`, and warns if the directory name ≠ the plugin id. This is a **subset** of registry CI — CI additionally verifies the release tag/commit, the artifact's sha256, and the README over the network. A local pass predicts a CI pass. |
| `trek-plugin preflight --repo <o/n> --tag <vX>` | Runs the **full** registry CI checks locally over the network (tag→commit, manifest parity, artifact sha256/size, native scan, README quality gate) against your pushed release — so you catch a CI failure before opening the PR. |
| `trek-plugin submit --repo <o/n> --tag <vX>` | Opens the registry PR for you: forks TREK-Plugins, branches off current main, writes/merges `registry/plugins/<id>.json`, pushes, and creates the PR. Requires `gh`. |
| `trek-plugin keygen` / `sign` | `keygen` creates an Ed25519 signing key; `sign` (or `--sign` on `entry`/`release`/`submit`) signs the artifact and fills `authorPublicKey` + `signature` so TREK pins your identity (TOFU). |
| `trek-plugin pack [dir] [--out plugin.zip] [--json]` | Validates, then builds `plugin.zip` in the installer's exact layout (`trek-plugin.json`, `README.md`, `LICENSE`, `package.json` at the root; `server/` and `client/` recursed) and prints its **sha256 + byte size**. Skips `node_modules`, `.git`, `.ts` and `.map` files, and **refuses native binaries** (`.node`, `binding.gyp`, `prebuilds/`) and over-size archives, same as the installer. **`docs/` is intentionally NOT shipped** — the store fetches your screenshot from `docs/screenshot.png` in the repo. |
| `trek-plugin entry --repo <owner/name> --tag <vX.Y.Z> [--zip plugin.zip] [--merge entry.json] [--out file]` | Emits the ready-to-PR registry entry: `commitSha` (resolved from the tag), `downloadUrl`, `sha256` + `size` (from the packed zip), and `minTrekVersion` (derived from the manifest's `trek` range, e.g. `>=3.2.0 <4.0.0` → `3.2.0`). `--merge` prepends this version onto an existing `registry/plugins/<id>.json` for an update, keeping versions newest-first. |
| `trek-plugin release [dir] --repo <owner/name> --tag <vX.Y.Z>` | The one-shot: `pack` → `gh release create` (uploads the zip) → print the registry `entry`. Requires the `gh` CLI authenticated. |
+58 -17
View File
@@ -11,16 +11,18 @@ the mechanical work — you rarely hand-type a hash, size, commit, or JSON field
## The short version
```bash
npx trek-plugin-sdk validate . # manifest + layout sanity
npx trek-plugin-sdk pack . # build plugin.zip, print sha256 + size
gh release create v1.0.0 plugin.zip --repo you/trek-plugin-flight-tracker
npx trek-plugin-sdk entry --repo you/trek-plugin-flight-tracker --tag v1.0.0 \
--out registry/plugins/flight-tracker.json # the ready-to-PR entry
git tag v1.0.0 && git push --tags
npx trek-plugin-sdk release --repo you/trek-plugin-flight-tracker --tag v1.0.0 # pack → GitHub release → entry
npx trek-plugin-sdk preflight --repo you/trek-plugin-flight-tracker --tag v1.0.0 # the CI checks, locally
npx trek-plugin-sdk submit --repo you/trek-plugin-flight-tracker --tag v1.0.0 # opens the registry PR
```
…then open a PR to **TREK-Plugins** adding that one
`registry/plugins/<id>.json` file. `trek-plugin release` collapses the middle
three steps into one command (see below).
`release` builds the artifact, creates the GitHub release, and prints the
registry entry. `preflight` runs the exact registry CI checks against your
pushed release so you don't round-trip through review. `submit` forks
**TREK-Plugins**, writes `registry/plugins/<id>.json`, and opens the PR for you.
Prefer to do the last step by hand? `entry --out registry/plugins/<id>.json`
prints the file and you open the PR yourself.
## 1. Host and build your plugin
@@ -113,12 +115,39 @@ npx trek-plugin-sdk release . --repo you/trek-plugin-flight-tracker --tag v1.0.0
entry to stdout. It accepts `--out`, `--notes`, `--commit`, and `--merge`. (It
requires the `gh` CLI, authenticated.)
## 6. Open a registry PR
## 6. Preflight — run the CI checks locally
You don't have write access, so **fork
[TREK-Plugins](https://github.com/mauriceboe/TREK-Plugins)**, add your generated
file as `registry/plugins/<id>.json`, and open a PR back to `main`. Add **only**
that file — `dist/` is generated on merge, and CI rejects manual edits to it.
Before you open the PR, run the exact registry CI checks against your pushed
release, so you catch what CI would reject without a review round-trip:
```bash
npx trek-plugin-sdk preflight --repo you/trek-plugin-flight-tracker --tag v1.0.0
```
`preflight` mirrors both CI scripts over the network: the tag resolves to the
pinned `commitSha`, the manifest at that commit matches the entry, the released
artifact's **sha256 + size** match and it carries **no native binaries**, and the
README passes the quality gate (required sections, real prose, a resolving
screenshot, permission parity). It also accepts `--entry <file.json>` to check a
hand-written entry. A green preflight predicts a green CI.
## 7. Open the registry PR
The fast path — `submit` does the whole fork/branch/commit/PR dance for you:
```bash
npx trek-plugin-sdk submit --repo you/trek-plugin-flight-tracker --tag v1.0.0
```
It forks [TREK-Plugins](https://github.com/mauriceboe/TREK-Plugins) (once),
branches off the current `main`, writes (or, for an update, merges into)
`registry/plugins/<id>.json`, pushes, and opens the PR — printing its URL. Add
`--draft` for a draft PR, `--registry <owner/name>` for a mirror. (Requires `gh`,
authenticated.)
**By hand instead:** fork the registry, add your generated file as
`registry/plugins/<id>.json`, and open a PR back to `main`. Add **only** that
file — `dist/` is generated on merge, and CI rejects manual edits to it.
The entry follows [`schema/plugin-entry.schema.json`](https://github.com/mauriceboe/TREK-Plugins/blob/main/schema/plugin-entry.schema.json);
[`schema/example-entry.json`](https://github.com/mauriceboe/TREK-Plugins/blob/main/schema/example-entry.json)
@@ -171,16 +200,28 @@ TREK verifies the signature offline (minisign / Ed25519, no external service) an
pins your key on first install (trust-on-first-use): a later release signed with a
different key is refused until an admin re-trusts it.
**One-time — create a key:**
**The easy way — let the SDK do it** (dependency-free Ed25519, no minisign needed):
```bash
npx trek-plugin-sdk keygen # once: writes ~/.trek-plugin/signing.key
npx trek-plugin-sdk release --repo you/repo --tag v1.2.0 --sign
npx trek-plugin-sdk submit --repo you/repo --tag v1.2.0 --sign
```
`--sign` signs the exact artifact bytes and fills both `authorPublicKey` (entry)
and `signature` (version) for you; `submit --sign` even refuses to publish an
update signed with a *different* key than the one already listed, so you can't
lock yourself out by accident. **Back up `~/.trek-plugin/signing.key`** — losing
it means you can't ship signed updates.
**By hand with minisign**, if you prefer:
```bash
minisign -G # writes minisign.key (keep secret) + minisign.pub
```
Put the base64 payload line from `minisign.pub` in your entry as
`authorPublicKey` (stable across versions).
**Each release — sign the artifact:**
`authorPublicKey` (stable across versions), then per release:
```bash
minisign -Sm plugin.zip # writes plugin.zip.minisig