Skip to content

Commit a6a7e49

Browse files
committed
feat(cli, runtime, core): os serve loads installed plugins, re-verified and dispatched by runtime tier; os plugin disable | enable | uninstall (#27123)
Slice 2 of 3 of ADR-0025 §3.5 M1 (Claim 6485671080). - runtime: installed-plugin-loader.ts (loadInstalledPlugins, verifyInstalledPlugins, dispatchPluginRuntime). Each installation is re-checked before any of its code is imported: its own install dir, disabled, the kept artifact's sha256, the signature over the raw kept bytes against sys_trusted_key (revoked since install refuses), the unpacked tree byte-equal to the artifact, the manifest id/version, then the tier: node imports in process, sandbox/worker/undeclared refused by name. Uninstall finishes at boot with a shared-dir guard. - runtime: the installations file takes a pid lock for every read-modify-write; a stale lock (dead pid, older than 5 min, own pid while unheld, unparseable and older than 1 s) is cleared by the next writer. - core: the archive reader moves here with a bounded inflate (MAX_UNPACKED_ARTIFACT_BYTES); PluginLoader refuses a signature no host verified (recordPluginArtifactVerdict). - cli: serve registers installed plugins before bootstrap; install verifies the signature before inflating and warns on a tier the boot refuses; new disable / enable / uninstall; the shared trust read plugin-trust-read.ts. - spec: the runtime tier's describe text and TSDoc, its pin, the liveness row live-elsewhere -> live; generated reference pages regenerated. Claude-Session: https://claude.ai/code/session_01Utp6CXg4K8dxetvqvU81bD Co-authored-by: Claude <noreply@anthropic.com>
1 parent 10f27b6 commit a6a7e49

37 files changed

Lines changed: 2955 additions & 345 deletions
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
'@objectstack/cli': patch
3+
'@objectstack/runtime': patch
4+
'@objectstack/core': patch
5+
---
6+
7+
feat(cli, runtime, core): `os serve` loads the plugins `os plugin install` installed, re-verifying each before any of its code is imported, and dispatches on the declared `runtime` tier; `os plugin disable | enable | uninstall` (#27123)
8+
9+
Clause-②: no — no key, accepted value or export of `@objectstack/spec` changes; the loader, the commands and the new exports are platform code
10+
Metadata-protocol: none
11+
12+
The second slice of ADR-0025's local install loop (§3.5 M1). Before this, an installed plugin was unpacked and recorded, and nothing loaded it.
13+
14+
- **The boot-time loader** (`@objectstack/runtime`: `loadInstalledPlugins`, `verifyInstalledPlugins`). `os serve` (and `os dev` / `os start` through it) calls it after the config's own `plugins` are registered and before the kernel bootstraps, then `kernel.use`s each plugin that passed, so dependency order and health checks stay the kernel's. For each installation of this project and environment, in this order, the first failing check refuses that plugin by name and nothing of it is imported:
15+
- the record names the directory the store derives for its id and version (`install_dir_unexpected`); nothing is read from or removed under any other;
16+
- a disabled id is skipped, before anything of it is read;
17+
- the kept `artifact.osplugin` hashes to the recorded sha256 (`artifact_changed`, `install_dir_missing`);
18+
- its detached signature, over the raw kept bytes and before anything is inflated, names the recorded key id, the key is `active` in `sys_trusted_key` with the fingerprint the install verified, and it verifies (`signature_missing`, `signature_malformed`, `signature_key_mismatch`, `signature_key_untrusted`, `signature_key_revoked`, `trusted_key_invalid`, `trusted_key_changed`, `signature_invalid`, `trusted_keys_unreadable`). So a key revoked since install refuses the plugin at its next boot. An install admitted under `--trust-unsigned` loads with a warning on every boot;
19+
- the unpacked tree is byte-for-byte the artifact, with no other file and no symbolic link, and the artifact's manifest is the recorded id and version (`tree_changed`, `manifest_mismatch`, `artifact_unreadable`);
20+
- **the tier dispatch point** (`dispatchPluginRuntime`, ADR-0025 §3.6): `runtime: 'node'` imports the entry module in process; `sandbox` and `worker` are refused by name until M3 routes them (`runtime_not_dispatched`), with no in-process fallback; a manifest that declares no tier is refused (`runtime_undeclared`, default-deny);
21+
- the entry module is a file of the artifact (`entry_missing`), it imports (`import_failed`), and it exports a plugin (`not_a_plugin`) by the rule a stack's `plugins` entry takes (a plain bundle is wrapped in `AppPlugin`).
22+
23+
The environment's trusted keys are read once per boot, through the same read-only one-shot boot `os plugin install` reads them through, and only when a signed install needs them; with no installations file nothing is read at all. A refused plugin does not stop the boot: it is printed as one `✗` line naming the refusal, and the banner counts the refusals. An installed plugin never replaces a plugin the boot already registered under the same name (`plugin_name_taken`).
24+
- **The kernel's signature check is real.** `PluginLoader` used to pass any well-formed `signature` a plugin carried. The host that verified the artifact now records its verdict against the plugin object (`recordPluginArtifactVerdict`, `@objectstack/core`), and the loader refuses a plugin whose signature no host verified. No plugin in the repo sets `signature`.
25+
- **`os plugin install`** verifies the signature over the raw bytes before it inflates the archive, and the inflate is bounded (`MAX_UNPACKED_ARTIFACT_BYTES`, 256 MiB; the reader moved to `@objectstack/core` as `readTarGz`, re-exported where the CLI read it). The checks, the write and the record now run under the installations lock. An artifact whose tier the boot does not dispatch installs with a warning naming the refusal, and `--json` carries `boot: { loads, error }`.
26+
- **`os plugin disable ID` / `os plugin enable ID`** keep an installed plugin from loading, or load it again, at the next boot (the package disable-state store, keyed by the plugin environment id). **`os plugin uninstall ID`** marks the installation; the next boot loads nothing of it, removes its directory unless another project sharing the home and environment still records it, drops the record and forgets its disable. Each refuses an id this project has not installed by name (`plugin_not_installed`); `--json` on all three.
27+
- **The installations file takes a lock** for every read-modify-write: `<file>.lock`, created exclusively with the writer's pid. A writer waits up to 10 s for a live holder, then refuses naming it. A lock a crashed process left is cleared by the next writer: its pid is not a live process, or it is older than 5 minutes, or it names the writer's own pid while the writer holds nothing, or it cannot be parsed and is older than a second.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@objectstack/spec': patch
3+
---
4+
5+
docs(spec): the plugin manifest's `runtime` tier is described as enforced at boot for a locally installed plugin — only `node` is loaded, `sandbox` and `worker` are refused until ADR-0025 M3 routes them (#27123)
6+
7+
Clause-②: no — no key or accepted value changes; `node`, `sandbox` and `worker` still parse, and an unset tier is still legal
8+
Metadata-protocol: none
9+
10+
The `.describe()` text and TSDoc of `PluginRuntimeSchema` and the manifest's `runtime` field said load-side enforcement was not implemented. The boot-time loader for plugins `os plugin install` installed now dispatches on the tier before importing anything: `node` loads in process (not isolated), `sandbox` and `worker` are refused by name, and an installed plugin that declares no tier is refused. The text says that, both halves still stated (the cloud marketplace publish gate's HTTP 422 for an unverified publisher requesting `node` is unchanged), and the retracted sentence is pinned absent. A plugin a stack's own `plugins` array names is not dispatched on this key. The liveness ledger's `runtime` row moves from `live-elsewhere` to `live` on the local dispatch point.

‎content/docs/protocol/kernel/lifecycle.mdx‎

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ command, so no `objectstack upgrade …` line on this page is runnable.
1818

1919
**Code-plugin installation is local and partial.** `os plugin install
2020
./x.osplugin` verifies a local artifact's signature against the environment's
21-
trusted keys and its per-file integrity, then unpacks it; nothing loads an
22-
installed plugin at boot yet, and there is no `os plugin enable` or `test`.
21+
trusted keys and its per-file integrity, then unpacks it, and the next
22+
`os serve` re-verifies it and loads it — `runtime: 'node'` only, in process;
23+
`sandbox` and `worker` are refused at boot until
2324
[ADR-0025](https://github.com/objectstack-ai/objectstack/blob/main/docs/adr/0025-plugin-package-distribution.md)
24-
§3.5 M1 records the loader as the next step; see
25-
[Plugin Installation](#plugin-installation) for what an author does today.
25+
M3. `os plugin disable`, `enable` and `uninstall` act at the next boot; there
26+
is no `os plugin test`. See [Plugin Installation](#plugin-installation) for
27+
what an author does today.
2628
</Callout>
2729

2830
ObjectStack manages the complete **lifecycle** of the platform runtime—from initial boot through schema evolution and graceful shutdown, and describes the design intent for plugin installation, upgrades, and rollbacks. The boot sequence is implemented as described; the installation and upgrade flows are design intent (see the callout above).
@@ -201,8 +203,11 @@ class AppPlugin implements Plugin {
201203
records and the platform ships only in part: `os plugin install ./x.osplugin`
202204
verifies a local artifact (its signature against the environment's trusted
203205
keys, its files against the manifest's `integrity` map), unpacks it and
204-
records the installation, writing nothing until every check passes. Download
205-
from the cloud, loading an installed plugin at boot, and the install hooks and
206+
records the installation, writing nothing until every check passes. At the
207+
next boot, `os serve` re-verifies each installation (the kept artifact's
208+
sha256, its signature against the trusted keys as they are now, the unpacked
209+
tree) and loads it by its declared tier: `node` in process, `sandbox` and
210+
`worker` refused by name. Download from the cloud and the install hooks and
206211
registry below have no command and no runtime path. The sections below up to
207212
*Upgrades* describe that design, not a command you can run. See
208213
[What an author does today](#what-an-author-does-today).
@@ -375,8 +380,8 @@ transitions (this page, above), not code hooks; boot-time code goes in
375380
### What an author does today
376381

377382
The one install command for a code plugin is `os plugin install`, for a
378-
signed artifact on local disk, and nothing loads what it installs yet. What
379-
exists, per the
383+
signed artifact on local disk; the next `os serve` loads what it installed.
384+
What exists, per the
380385
[CLI reference](https://github.com/objectstack-ai/objectstack/blob/main/packages/cli/README.md):
381386

382387
- **Runtime plugins** declared in `objectstack.config.ts` `plugins` are loaded
@@ -390,8 +395,12 @@ exists, per the
390395
manifest) are packaged and shipped with `os plugin build`, `os plugin sign`
391396
and `os plugin publish`. A signed `.osplugin` on local disk is installed with
392397
`os plugin install` once its publisher key is trusted (`os plugin keygen`,
393-
`os plugin trust add`); `os serve` does not load installed plugins yet, and a
394-
published `.osplugin` has no `os` command that fetches it from the cloud.
398+
`os plugin trust add`). `os serve` re-verifies and loads it at boot when it
399+
declares `runtime: 'node'` (author code in the host process, not isolated),
400+
refuses `sandbox` and `worker` until they are routed, and prints each refusal
401+
by name; `os plugin disable | enable | uninstall ID` take effect at the next
402+
boot. A published `.osplugin` has no `os` command that fetches it from the
403+
cloud.
395404

396405
See [Plugin System](/docs/plugins) for how kernel plugins are created and
397406
registered.
@@ -920,7 +929,7 @@ Plugin authors must document breaking changes in CHANGELOG.md.
920929

921930
ObjectStack lifecycle management provides:
922931
- **Deterministic Boot:** 7-phase boot sequence with clear error handling
923-
- **Atomic Installations (design):** ADR-0025 calls for transactional, all-or-nothing plugin installs; `os plugin install` verifies a local artifact in full before it writes anything, but nothing loads an installed plugin at boot yet
932+
- **Atomic Installations (design):** ADR-0025 calls for transactional, all-or-nothing plugin installs; `os plugin install` verifies a local artifact in full before it writes anything, and `os serve` re-verifies it before loading it
924933
- **Zero-Downtime Upgrades:** Blue-green and rolling strategies for production
925934
- **Automatic Rollback:** Failed upgrades auto-revert to previous version
926935
- **Health Monitoring:** Built-in health checks validate system state

‎content/docs/references/api/package-api-assembled.mdx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Installed package row whose manifest is the assembled package body
105105
| **navigationContributions** | `{ app: string; group?: string; priority?: integer; items: (object \| … +9 more)[] }[]` | optional | Navigation items this package contributes into apps owned by other packages |
106106
| **engine** | `{ objectstack: string }` | optional | Platform compatibility requirements (legacy; superseded by `engines`) |
107107
| **engines** | `{ platform?: string; protocol?: string }` | optional | Plugin compatibility ranges (ADR-0025 §3.2; supersedes `engine`) |
108-
| **runtime** | `Enum<'node' \| 'sandbox' \| 'worker'>` | optional | Plugin trust tier the plugin declares (ADR-0025 §3.6) — enforced at the cloud marketplace publish gate (unverified publisher requesting `node` → HTTP 422 + manual review); load-side enforcement is NOT implemented, so a locally installed plugin is not isolated by the tier it declares |
108+
| **runtime** | `Enum<'node' \| 'sandbox' \| 'worker'>` | optional | Plugin trust tier the plugin declares (ADR-0025 §3.6) — enforced at the cloud marketplace publish gate (unverified publisher requesting `node` → HTTP 422 + manual review) and at boot for a locally installed plugin: only `node` is loaded (in process, not isolated); `sandbox` and `worker` are refused until ADR-0025 M3 routes them |
109109
| **packaging** | `Enum<'bundled' \| 'manifest-deps'>` | optional | Dependency packaging strategy (ADR-0025 §3.3) |
110110
| **main** | `string` | optional | Entry module of a code-bearing plugin, relative to the plugin root; `os plugin build` bundles it and writes `dist/index.mjs` here in the compiled manifest (ADR-0025 §3.4) |
111111
| **integrity** | `Record<string, string>` | optional | Per-file content digests of the plugin artifact (ADR-0025 §3.2) |
@@ -288,7 +288,7 @@ This schema accepts one of the following structures:
288288
| **navigationContributions** | `{ app: string; group?: string; priority?: integer; items: (object \| … +9 more)[] }[]` | optional | Navigation items this package contributes into apps owned by other packages |
289289
| **engine** | `{ objectstack: string }` | optional | Platform compatibility requirements (legacy; superseded by `engines`) |
290290
| **engines** | `{ platform?: string; protocol?: string }` | optional | Plugin compatibility ranges (ADR-0025 §3.2; supersedes `engine`) |
291-
| **runtime** | `Enum<'node' \| 'sandbox' \| 'worker'>` | optional | Plugin trust tier the plugin declares (ADR-0025 §3.6) — enforced at the cloud marketplace publish gate (unverified publisher requesting `node` → HTTP 422 + manual review); load-side enforcement is NOT implemented, so a locally installed plugin is not isolated by the tier it declares |
291+
| **runtime** | `Enum<'node' \| 'sandbox' \| 'worker'>` | optional | Plugin trust tier the plugin declares (ADR-0025 §3.6) — enforced at the cloud marketplace publish gate (unverified publisher requesting `node` → HTTP 422 + manual review) and at boot for a locally installed plugin: only `node` is loaded (in process, not isolated); `sandbox` and `worker` are refused until ADR-0025 M3 routes them |
292292
| **packaging** | `Enum<'bundled' \| 'manifest-deps'>` | optional | Dependency packaging strategy (ADR-0025 §3.3) |
293293
| **main** | `string` | optional | Entry module of a code-bearing plugin, relative to the plugin root; `os plugin build` bundles it and writes `dist/index.mjs` here in the compiled manifest (ADR-0025 §3.4) |
294294
| **integrity** | `Record<string, string>` | optional | Per-file content digests of the plugin artifact (ADR-0025 §3.2) |
@@ -351,7 +351,7 @@ This schema accepts one of the following structures:
351351
| **navigationContributions** | `{ app: string; group?: string; priority?: integer; items: (object \| … +9 more)[] }[]` | optional | Navigation items this package contributes into apps owned by other packages |
352352
| **engine** | `{ objectstack: string }` | optional | Platform compatibility requirements (legacy; superseded by `engines`) |
353353
| **engines** | `{ platform?: string; protocol?: string }` | optional | Plugin compatibility ranges (ADR-0025 §3.2; supersedes `engine`) |
354-
| **runtime** | `Enum<'node' \| 'sandbox' \| 'worker'>` | optional | Plugin trust tier the plugin declares (ADR-0025 §3.6) — enforced at the cloud marketplace publish gate (unverified publisher requesting `node` → HTTP 422 + manual review); load-side enforcement is NOT implemented, so a locally installed plugin is not isolated by the tier it declares |
354+
| **runtime** | `Enum<'node' \| 'sandbox' \| 'worker'>` | optional | Plugin trust tier the plugin declares (ADR-0025 §3.6) — enforced at the cloud marketplace publish gate (unverified publisher requesting `node` → HTTP 422 + manual review) and at boot for a locally installed plugin: only `node` is loaded (in process, not isolated); `sandbox` and `worker` are refused until ADR-0025 M3 routes them |
355355
| **packaging** | `Enum<'bundled' \| 'manifest-deps'>` | optional | Dependency packaging strategy (ADR-0025 §3.3) |
356356
| **main** | `string` | optional | Entry module of a code-bearing plugin, relative to the plugin root; `os plugin build` bundles it and writes `dist/index.mjs` here in the compiled manifest (ADR-0025 §3.4) |
357357
| **integrity** | `Record<string, string>` | optional | Per-file content digests of the plugin artifact (ADR-0025 §3.2) |

0 commit comments

Comments
 (0)