Skip to content

Commit a6bc979

Browse files
DavidBabinecclaude
andcommitted
docs(plugins): update docs for QuickJS bootstrap refactor
- Fix stale server/plugins/quickjsHost.ts path → server/plugins/quickjs/vm.ts across plugin-system.md, README.md, architecture.md, server.md - Add bootstrap source paths to plugin-system.md Related section (bootstrap/src/, bootstrap/generated/, scripts/sync-plugin-bootstrap.ts) - Add new gate and test files to plugin-system.md Related section: plugin-bootstrap-fresh.test.ts, pluginVmPermissions.test.ts, pluginVmLoopDispatch.test.ts - Add plugin-bootstrap-fresh.test.ts to reference/architecture-tests.md Plugin system table Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 3836d57 commit a6bc979

5 files changed

Lines changed: 13 additions & 6 deletions

File tree

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ Quick map from "where do I look for X?" to the canonical file:
221221
| Plugin SDK | `src/core/plugin-sdk/` |
222222
| Plugin permission catalog | `src/core/plugin-sdk/capabilities.ts` |
223223
| Plugin manifest parser | `src/core/plugins/manifest.ts` |
224-
| Plugin sandbox host | `server/plugins/quickjsHost.ts`, `server/plugins/modulePackVm.ts` |
224+
| Plugin sandbox host | `server/plugins/quickjs/vm.ts`, `server/plugins/modulePackVm.ts` |
225225
| Publisher | `src/core/publisher/` |
226226
| TypeBox helpers | `src/core/utils/typeboxHelpers.ts` |
227227
| Error message extraction | `src/core/utils/errorMessage.ts` |

docs/architecture.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ Key properties:
268268
269269
Plugins are zip packages containing a `plugin.json` manifest and bundled entrypoints. The host runs plugin code in a **QuickJS-WASM sandbox**:
270270
271-
- `entrypoints.server` runs in `server/plugins/quickjsHost.ts`
271+
- `entrypoints.server` runs in `server/plugins/quickjs/vm.ts`
272272
- `entrypoints.modules` (canvas module packs) run in `server/plugins/modulePackVm.ts`
273273
- Author-facing API lives in `src/core/plugin-sdk/`
274274
- Host-side runtime (install, activate, deactivate, uninstall) lives in `src/core/plugins/`

docs/features/plugin-system.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ A plugin is a zip package containing a `plugin.json` manifest and one or more Ja
99
## TL;DR
1010

1111
- **Package shape:** a zip containing `plugin.json` plus entrypoint bundles (`server/index.js`, `editor/index.js`, `admin/dashboard.js`, `modules/index.js`, `frontend/*.js`, optional `pack/site.json`).
12-
- **Runtime:** server entrypoint runs in **QuickJS-WASM** (`server/plugins/quickjsHost.ts`). Canvas module packs run in a separate QuickJS VM (`server/plugins/modulePackVm.ts`). No host APIs leak.
12+
- **Runtime:** server entrypoint runs in **QuickJS-WASM** (`server/plugins/quickjs/vm.ts`). Canvas module packs run in a separate QuickJS VM (`server/plugins/modulePackVm.ts`). No host APIs leak.
1313
- **SDK:** every API call goes through `api``api.plugin.*` for plugin metadata + logging, `api.cms.*` for routes, storage, hooks, loops, settings, schedule, pages.
1414
- **Lifecycle:** `install``activate` → (optionally `deactivate` / `migrate`) → `uninstall`. Each hook is async-capable and isolated; if one throws, the host rolls back and parks the plugin in `error`.
1515
- **Permissions:** declared in `plugin.json`, approved by the site owner at install time, enforced by the SDK at runtime. Outbound network also requires `networkAllowedHosts` allowlist.
@@ -677,7 +677,10 @@ Manifest:
677677
- `src/core/plugins/manifest.ts` — manifest parser + validator
678678
- `src/core/plugins/` — host-side runtime
679679
- `server/plugins/runtime.ts` — boot-time plugin activation
680-
- `server/plugins/quickjsHost.ts` — server entrypoint sandbox
680+
- `server/plugins/quickjs/vm.ts` — server entrypoint sandbox (QuickJS VM factory)
681+
- `server/plugins/quickjs/bootstrap/src/` — bootstrap TypeScript source (authored, typed, lintable)
682+
- `server/plugins/quickjs/bootstrap/generated/` — committed bootstrap artifacts (regenerate with `bun run bootstrap:sync`)
683+
- `scripts/sync-plugin-bootstrap.ts` — bundler that writes the generated artifacts
681684
- `server/plugins/modulePackVm.ts` — module pack VM constructor
682685
- `src/core/plugins/modulePackLoader.ts` — module pack lifecycle coordinator (activate, deactivate, reset, VM tracking)
683686
- `server/plugins/package.ts` — install / `assertSandboxSafe`
@@ -696,5 +699,8 @@ Manifest:
696699
- `src/__tests__/architecture/plugin-schedule-invariants.test.ts`
697700
- `src/__tests__/architecture/no-plugin-tab-shells.test.ts`
698701
- `src/__tests__/architecture/sandbox-crypto-bridge.test.ts`
702+
- `src/__tests__/architecture/plugin-bootstrap-fresh.test.ts` — generated bootstrap artifacts match source; fails if `bun run bootstrap:sync` is needed
699703
- `src/__tests__/plugins/gatedFetchSsrf.test.ts` — SSRF guards: allowlist, DNS rebinding, redirect re-validation, redirect cap
700704
- `src/__tests__/plugins/pluginModulePack.test.ts` — module pack activation, re-activation, deactivation, and VM disposal
705+
- `src/__tests__/server/pluginVmPermissions.test.ts` — VM-side permission check: declared-but-not-granted permissions are denied at the VM boundary before host dispatch
706+
- `src/__tests__/server/pluginVmLoopDispatch.test.ts` — loop fetch/preview dispatcher robustness (no-return fallbacks, async-preview detection)

docs/reference/architecture-tests.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ See [docs/features/spotlight.md](../features/spotlight.md).
129129

130130
| Test | What it enforces |
131131
|-----------------------------------------------|----------------------------------------------------------------------------------|
132+
| `plugin-bootstrap-fresh.test.ts` | Generated bootstrap artifacts in `bootstrap/generated/` match a fresh bundle of `bootstrap/src/`. Fails if `bun run bootstrap:sync` is needed. |
132133
| `plugin-sandbox-invariants.test.ts` | No `node:`, `bun:`, `require(`, `process.binding` in plugin bundles. Sandbox-safe assertions.|
133134
| `plugin-boot-resilience.test.ts` | One bad plugin doesn't bring the server down. Crashes are isolated. |
134135
| `plugin-cms-content-surface.test.ts` | All five `cms.content.*` permissions are wired across all sync-points (permission values, capability matrix, permission alias builder, SDK type surface, host-side dispatch). |

docs/server.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The server is a single `Bun.serve` process that boots the DB, runs migrations, a
1414
- **Auth:** session cookie (`SESSION_COOKIE_NAME`) → `findUserBySessionHash``requireCapability(req, db, 'site.read')`. Every state-changing handler starts with one of these guards.
1515
- **DB:** one `DbClient` interface (`server/db/client.ts`) — tagged-template callable returning `{ rows, rowCount }`. Two adapters: `postgres.ts` (via `Bun.sql`) and `sqlite.ts` (via `bun:sqlite`). Selected by `DATABASE_URL`.
1616
- **Repositories** (`server/repositories/`) hold all SQL. Handlers never write SQL directly.
17-
- **Plugins:** `server/plugins/runtime.ts` activates installed plugins at boot; per-plugin code runs in QuickJS-WASM sandboxes (`server/plugins/quickjsHost.ts`, `modulePackVm.ts`).
17+
- **Plugins:** `server/plugins/runtime.ts` activates installed plugins at boot; per-plugin code runs in QuickJS-WASM sandboxes (`server/plugins/quickjs/vm.ts`, `modulePackVm.ts`).
1818
- **Published pages and content rows** are served by `tryServePublicRoute`, which delegates resolution + render to `server/publish/publicRouter.ts` (live render from the JSON snapshot stored in `data_row_versions.snapshot_json`). Uploads + admin SPA assets are served from disk by `tryServeUpload` and `tryServeStaticAsset`.
1919

2020
---
@@ -453,7 +453,7 @@ Plugins ship as zip packages with a `plugin.json` manifest. The host:
453453

454454
1. **Installs** the package (unzips into `uploads/plugins/<id>/<version>/`) — `server/plugins/package.ts`.
455455
2. **Validates** the manifest and scans the bundled JS for forbidden sandbox-incompatible patterns — `assertSandboxSafe` in `package.ts` + `parsePluginManifest` in `src/core/plugins/manifest.ts`.
456-
3. **Activates** the plugin at boot or on user action — `server/plugins/runtime.ts`. Activation loads the server entrypoint into a per-plugin QuickJS-WASM VM (`server/plugins/quickjsHost.ts`) and runs its `activate(api)` lifecycle hook.
456+
3. **Activates** the plugin at boot or on user action — `server/plugins/runtime.ts`. Activation loads the server entrypoint into a per-plugin QuickJS-WASM VM (`server/plugins/quickjs/vm.ts`) and runs its `activate(api)` lifecycle hook.
457457
4. **Routes** plugin-registered HTTP routes through `/admin/api/cms/plugins/<id>/runtime/…` (handled by `handleRuntimeRoutes`).
458458
5. **Brokers** the SDK boundary — `api.cms.routes.*`, `api.cms.storage.*`, `api.cms.hooks.*`, `api.cms.loops.*`, `api.cms.settings.*`, `api.cms.schedule.*`. The SDK shape is defined in `src/core/plugin-sdk/`.
459459

0 commit comments

Comments
 (0)