docs(system): extract plugin system into own spec
0b0647c848a660361c1b01d11ee9bac1ada44359
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
- Parent 1: 12c10600da25
There are many coding harnesses - but this one is fast
0b0647c848a660361c1b01d11ee9bac1ada44359
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
+149 / −93 text lines
+2 / −2 text lines
+1 / −1 text lines
+1 / −1 text lines
new file mode 100644+138 / −0 text lines
---id: SMH-SPEC-PLUG0001type: spectitle: "Plugin System"research: [SMH-RESEARCH-TBKDJHVX, SMH-RESEARCH-WASM0001]---# Plugin System## IntentOne typed plugin system where unprivileged wasm components extend Smith.Built-ins and user plugins share the same contracts, effects, and sandbox; parity is law, not aspiration.Engine mechanics (determinism, fuel, memory ceilings, artifact validation) live in `SMH-SPEC-WASM0001`.Product integration points live in `SMH-SPEC-SPEC0001`.## Runtime and parityPlugins run in a restricted runtime without direct operating-system, filesystem, environment, network, or clock access.Plugin execution is resource-bounded.Host effects are available only through typed Smith SDK component interfaces granted by manifest and trust decisions.Built-in plugins have no privileged effect path.Built-in coding tools are embedded component artifacts loaded through the normal sandbox; they call the same typed host primitives available to user plugins.## ContributionsPlugins may contribute:- tools,- commands,- providers and models,- credential sources,- prompts and context transforms,- event handlers,- themes and keybindings,- layout and render descriptions,- VCS workflows.## GenerationsPlugin events are ordered and typed.A candidate generation can declare and validate contributions but cannot invoke operational effects or mutate the active runtime before publication.A failed load leaves no registrations or subscriptions active.Reload publishes one complete generation or retains the previous generation.A generation owns every plugin instance, registration, subscription, binding, and contribution.Session, branch, queue, secrets, cancellation, and active-turn state live outside the generation and survive reload.Guest-local implementation state resets on reload.Removed contributions disappear at publication.Calls already running complete against their pinned generation; later calls resolve against the published generation.Each provider request pins one generation through its response and complete tool-call/result batch.The pinned generation supplies both advertised definitions and executable handlers.## Budgets and failureSmith SDK calls may catch ordinary typed guest errors, but not cancellation, budget exhaustion, sandbox violations, or host-effect recording failures.Smith SDK child work is structured and host-orchestrated: it shares the parent invocation budget and generation pin, serializes per plugin instance, and finishes or cancels before the parent handler returns.Fan-out cannot multiply resource limits.The budget covers deadline, guest fuel, component memory and table ceilings, host allocations, logs, conversions, and output.## Event boundaryPlugin handlers run synchronously in deterministic registration order under one bounded invocation budget shared with structured child tasks.They return typed actions rather than mutable runtime ownership.Actions may request cancellation, queued input, reload, or runtime-only model, provider, tool, prompt, and configuration changes.Cancellation applies immediately.Other actions are validated as one batch and apply atomically between provider requests, after the current stream and complete tool-result batch.Conflicting mutations are rejected; no implicit winner is selected.A failed or over-budget handler emits one typed diagnostic, is disabled for the current generation, and does not abort the turn unless its event contract requires a decision.Terminal agent events remain singular.```mermaidsequenceDiagram participant P as Provider round participant A as Agent boundary participant H as Ordered handlers participant G as Runtime generation P-->>A: Stream and complete tool batch A->>H: Typed lifecycle events H-->>A: Typed action batch A->>A: Validate and reject conflicts A->>G: Publish coherent runtime changes G-->>P: Next request snapshot```## Discovery and modulesVersion 1 discovers plugin packages by path convention.Each package carries a manifest declaring its plugin artifact, world version, and requested capabilities.Package, artifact, and manifest identities are deterministic and validated before instantiation.Artifacts failing validation never execute.Manifest and artifact reads are bounded before materialization, and canonical paths cannot escape their declared root.A module contract is a typed, major-versioned component interface.Undeclared exports remain private.A module can have zero, one, or multiple implementations.One implementation binds automatically.Zero or ambiguous implementations fail only when consumed, with sorted candidates and the consumer reported.Explicit user binding overrides automatic binding and must satisfy the requested contract.Module consumers use logical major-versioned handles.A new invocation resolves each handle against the published generation; nested accesses during an active invocation resolve within its pinned generation.Reload can rebind only to an implementation satisfying the same major contract; guest-local state resets.Precedence is built-in, global user, project, then explicit override.Later registration replaces earlier registration only where the earlier contract explicitly permits replacement.Installed capabilities are validated as a complete set before atomic replacement or removal.## Project trustProject-local executable configuration, plugins, modules, and managed packages are not enumerated or loaded before trust is resolved.A project trust identity is its lossless, platform-tagged canonical native path.Symlink aliases share one decision; distinct native paths cannot collide through text conversion.Interactive mode can ask and persist the decision.Non-interactive modes require an explicit or previously persisted decision to load project-local executable behavior.An explicit plugin path grants one-run trust only to that exact canonical source.Capability grants resolve at trust time for project plugins and at install time for user plugins.Ignoring untrusted project behavior produces a visible diagnostic.Trust does not remove the plugin sandbox or tool boundaries.## World surfaceIncomplete: the `smith:plugin` world's interface design follows the wasm-limitation review and the research synthesis rules (minimal surface, one grammar, tiny contracts, explicit parameters, two-layer core-plus-grants, mechanical versioning).## Acceptance criteria- Project plugins cannot execute before trust resolution.- Built-in and user plugins use the same sandboxed effect APIs.- Event handlers are bounded, ordered, and publish conflict-free runtime actions only at safe points.- Reload atomically replaces one complete generation while active provider rounds remain pinned.- Callable module handles rebind only to conforming implementations of the same major contract.- Structured child work cannot suppress cancellation or exceed its shared budget.- A failed or over-budget handler disables only itself for the generation.+7 / −89 text lines
Plugin handlers run synchronously in deterministic registration order under one bounded invocation budget shared with structured child tasks.They return typed actions rather than mutable runtime ownership.Actions may request cancellation, queued input, reload, or runtime-only model, provider, tool, prompt, and configuration changes.Cancellation applies immediately.Other actions are validated as one batch and apply atomically between provider requests, after the current stream and complete tool-result batch.Conflicting mutations are rejected; no implicit winner is selected.A failed or over-budget handler emits one typed diagnostic, is disabled for the current generation, and does not abort the turn unless its event contract requires a decision.Terminal agent events remain singular.Plugins run in a restricted runtime without direct operating-system, filesystem, environment, network, or clock access.Plugin execution is resource-bounded.Host effects are available only through typed Smith SDK component interfaces granted by manifest and trust decisions.Built-in plugins have no privileged effect path.Plugins may contribute:- tools,- commands,- providers and models,- prompts and context transforms,- event handlers,- themes and keybindings,- layout and render descriptions,- VCS workflows.Plugin events are ordered and typed.A candidate generation can declare and validate contributions but cannot invoke operational effects or mutate the active runtime before publication.A failed load leaves no registrations or subscriptions active.Reload publishes one complete generation or retains the previous generation.A generation owns every plugin instance, registration, subscription, binding, and contribution.Session, branch, queue, secrets, cancellation, and active-turn state live outside the generation and survive reload.Guest-local implementation state resets on reload.Removed contributions disappear at publication.Calls already running complete against their pinned generation; later calls resolve against the published generation.Each provider request pins one generation through its response and complete tool-call/result batch.The pinned generation supplies both advertised definitions and executable handlers.Built-in coding tools are embedded component artifacts loaded through the normal sandbox; they call the same typed host primitives available to user plugins.Smith SDK calls may catch ordinary typed guest errors, but not cancellation, budget exhaustion, sandbox violations, or host-effect recording failures.Smith SDK child work is structured and host-orchestrated: it shares the parent invocation budget and generation pin, serializes per plugin instance, and finishes or cancels before the parent handler returns.Fan-out cannot multiply resource limits.The budget covers deadline, guest fuel, component memory and table ceilings, host allocations, logs, conversions, and output.Session continuity survives reload.### Discovery and modulesVersion 1 discovers plugin packages by path convention.Each package carries a manifest declaring its plugin artifact, world version, and requested capabilities.Package, artifact, and manifest identities are deterministic and validated before instantiation.Artifacts failing validation never execute.Manifest and artifact reads are bounded before materialization, and canonical paths cannot escape their declared root.A module contract is a typed, major-versioned component interface.Undeclared exports remain private.A module can have zero, one, or multiple implementations.One implementation binds automatically.Zero or ambiguous implementations fail only when consumed, with sorted candidates and the consumer reported.Explicit user binding overrides automatic binding and must satisfy the requested contract.Module consumers use logical major-versioned handles.A new invocation resolves each handle against the published generation; nested accesses during an active invocation resolve within its pinned generation.Reload can rebind only to an implementation satisfying the same major contract; guest-local state resets.Precedence is built-in, global user, project, then explicit override.Later registration replaces earlier registration only where the earlier contract explicitly permits replacement.Installed capabilities are validated as a complete set before atomic replacement or removal.### Project trustProject-local executable configuration, plugins, modules, and managed packages are not enumerated or loaded before trust is resolved.A project trust identity is its lossless, platform-tagged canonical native path.Symlink aliases share one decision; distinct native paths cannot collide through text conversion.Interactive mode can ask and persist the decision.Non-interactive modes require an explicit or previously persisted decision to load project-local executable behavior.An explicit plugin path grants one-run trust only to that exact canonical source.Capability grants resolve at trust time for project plugins and at install time for user plugins.Ignoring untrusted project behavior produces a visible diagnostic.Trust does not remove the plugin sandbox or tool boundaries.- project plugins cannot execute before trust resolution,- plugin system acceptance is defined in `SMH-SPEC-PLUG0001`,- every SDK effect has durable intent, completion, causal attribution, and three-state mutation evidence,- event handlers are bounded, ordered, and publish conflict-free runtime actions only at safe points,- reload atomically replaces one complete generation while active provider rounds remain pinned,- callable module handles rebind only to conforming implementations of the same major contract,- built-in and user plugins use the same sandboxed effect APIs,- structured child work cannot suppress cancellation or exceed its shared budget,