docs(system): port plugin contracts to wasm component runtime
6a09faad0ab73b8be6268ee19b7479b00f6f1d50
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
- Parent 1: c363c47eca45
There are many coding harnesses - but this one is fast
6a09faad0ab73b8be6268ee19b7479b00f6f1d50
Oliver Jan Krylow <oliver@bugabinga.net> ·
unsigned
+280 / −44 text lines
+8 / −2 text lines
"updatedAt": "2026-09-11T08:32:58.566Z", "source": "assess" }, "SMH-PLAN-AIAG0001": { "state": "done", "source": "agent", "updatedAt": "2026-09-11T09:20:57.959Z", "note": "cargo x check exit 0, 107 tests pass; 11 order items verified incl. 3 conformance-proven adapters, catalog validation, agent loop with paired tool turns, failover router, eval+rpc e2e."+168 / −28 text lines
1. Add project trust resolution before project executable configuration or package discovery.2. Add the wasm host: engine config, artifact validation, determinism knobs, fuel and memory ceilings.3. Add manifest-based package discovery with contract version and capability requests.4. Add deterministic module binding, ambiguity diagnostics, and plugin precedence.5. Add the typed `smith:plugin` WIT world covering filesystem, search, tools, commands, providers, UI, VCS, logging, and lifecycle control.6. Bridge runtime events and plugin results without exposing internal ownership.7. Load each plugin into a transactional registration set so failure leaves no active residue.8. Route built-in commands, presentation, themes, keybindings, prompts, and workflows through the same loader.9. Add atomic reload with rollback and preserved session continuity.10. Wire trusted global, project, and explicit plugin sources into the harness.11. Add plugin tooling: init, build, check, dev watch with hot swap, test harness with mocked capabilities.This plan delivers executable commands, tools, providers, modules, events, built-in tool artifacts, and plugin tooling.It delivers validated generation-owned UI and VCS registrations; their execution remains in `SMH-PLAN-TUIR0001`.## Delivery graphEach slice leaves one observable path integrated and verified.```mermaidflowchart LR AIAG["AIAG: shared agent runtime"] --> S1["Trusted transactional command"] S1 --> S2["Durable bounded effects"] S2 --> S3["Bounded composition and fatal failures"] S3 --> S4["Callable modules"] S4 --> S5["Common tool and provider path"] S5 --> S6["Live typed actions"] S6 --> S7["Atomic reload and precedence"] S7 --> S8["Plugin tooling"] S7 --> TUIR["TUIR: UI, VCS, replay surfaces"] S8 --> RELS["RELS: release readiness"] TUIR --> RELS```- Ambient WASI imports are unavailable; ungranted capabilities fail instantiation.- Fuel exhaustion and memory ceilings surface as explicit plugin errors.- Project plugins and executable configuration cannot run before trust resolution.- Non-interactive untrusted project behavior is skipped with a visible diagnostic.- Built-in and user plugins use the same sandbox and registration path.- Zero, singleton, ambiguous, and explicit module bindings follow the specification.- Failed load or reload leaves no subscriptions, tools, providers, or UI registrations behind.- Successful reload preserves the active session and swaps one coherent plugin state.### 1. Trusted transactional commandA trusted built-in or user package contributes one command through the wasm component sandbox.Project packages remain undiscovered until trust resolves.An explicit path grants one-run trust only to its canonical source.Failed instantiation publishes nothing.Touches: `smith-harness::wasm`, `smith-harness::trust`, `smith-harness::plugins`, `smith-harness::runtime`, `smith-cli`.Verify:- Canonical native paths distinguish otherwise-colliding project identities.- Manifest and artifact reads cannot escape their declared root.- Ambient WASI imports fail validation; ungranted capability imports fail instantiation.- Artifact reads, decoding, instantiation, memory and table ceilings, fuel, logs, output, deadline, and cancellation remain bounded.- Host effects are unavailable before generation publication.- Interactive, eval, and RPC modes expose the same trust outcome and diagnostics.### 2. Durable bounded effectsThe command invokes a typed filesystem or search effect through a granted capability.The session stores bounded full intent and completion records with stable identity, causal parent, generation, redacted secrets, and three-state mutation evidence.Replay exposes the same records without re-execution.Touches: `smith::tool`, `smith::session`, `smith-core::tools`, `smith-core::session`, `smith-core::replay`, `smith-harness::plugins`, `smith:plugin` world effect interfaces.Verify:- Intent persistence failure prevents execution.- Success, ordinary failure, cancellation, partial mutation, and completion-persistence failure retain correct evidence.- A dangling intent recovers as unknown and never retries automatically.- Full bounded effect payloads survive deterministic compressed-frame round trips.- Compression preserves traversal, corruption recovery, unknown frames, and allocation bounds.- Secret plaintext never enters effect records, diagnostics, or replay.- A `--no-session` eval effect records against the temporary store; clean exit removes it, abnormal termination retains it.### 3. Bounded composition and fatal failuresA plugin command uses host-orchestrated structured child work and controlled error handling.Ordinary typed guest errors are catchable; cancellation, budgets, sandbox violations, and recording failures are not.Touches: `smith-harness::wasm`, `smith-harness::plugins`, `smith:plugin` world task and error interfaces.Verify:- Child work shares the parent invocation budget and generation pin.- Every child finishes or cancels before its parent returns.- Calls to one plugin instance never run concurrently.- Fan-out cannot multiply resource limits.- Error reports retain package, generation, handler, event, and child-task context.### 4. Callable modulesHost and plugin consumers invoke a discovered module through a logical major-versioned handle.Singleton binding is automatic; zero and ambiguous binding fail only on consumption; explicit binding is deterministic.Touches: `smith-harness::plugins`, `smith:plugin` world module interface.Verify:- Manifest-based discovery validates bounded contract and artifact sources before instantiation.- Undeclared exports remain private.- Diagnostics report the consumer and sorted candidates.- Explicit bindings must satisfy the requested major contract.- Existing logical handles resolve against a newly published conforming generation; active calls finish against their pinned generation.- Guest-local state resets after rebinding.### 5. Common tool and provider pathA plugin contributes an executable provider-visible tool and a provider through the same generation and SDK effect boundary.Built-in `read`, `write`, `edit`, `bash`, `find`, `grep`, and `ls` become embedded component artifacts over the public typed primitives.Touches: `smith::tool`, `smith::provider`, `smith-core::agent`, `smith-ai`, `smith-harness::plugins`, `smith-harness::runtime`, built-in component packages.Verify:- The provider request and returned tool batch use one pinned generation.- Advertised definitions and invoked handlers cannot diverge.- Built-in and user tools have identical sandbox, cancellation, validation, effect recording, and error behavior.- Provider operations use durable SDK effects without exposing credentials.- A missing public primitive blocks migration rather than creating a privileged built-in path.### 6. Live typed actionsAn installed handler receives ordered live lifecycle events and returns cancellation, queued input, reload, model, provider, tool, prompt, or runtime-configuration actions.Cancellation is immediate; other actions publish only after the current provider stream and complete tool batch.Touches: `smith::event`, `smith-core::agent`, `smith-harness::plugins`, `smith-harness::runtime`, eval and RPC event bridges, `smith:plugin` world lifecycle interface.Verify:- Handler order is deterministic across interface modes.- Non-conflicting actions publish atomically between provider requests.- Conflicting field mutations are rejected without an implicit winner.- Runtime configuration actions do not persist configuration.- A failed or over-budget handler emits one diagnostic, remains disabled for its generation, and does not duplicate terminal events.### 7. Atomic reload and precedenceGlobal, trusted project, explicit, and built-in sources assemble one candidate generation.Successful reload replaces the complete installed capability set; failed reload retains the previous generation.Touches: `smith-harness::trust`, `smith-harness::plugins`, `smith-harness::runtime`, `smith-core::agent`, `smith:plugin` world registration interfaces.Verify:- Precedence is built-in, global user, project, then explicit override.- Replacement succeeds only where the earlier contract permits it.- Removed registrations and subscriptions disappear together.- Session, branch, queue, secrets, cancellation, and active-turn state survive reload.- An installed `Agent` completes active calls on the old generation and uses the new generation for the next provider request.- Failed candidate validation, instantiation, binding, or publication leaves the active generation unchanged.- UI and VCS registrations participate in validation, ownership, replacement, and removal without executing deferred behavior.### 8. Plugin tooling`smith plugin init`, `build`, `check`, `dev`, and `test` cover scaffold, artifact build, lint, hot swap, and hosted testing.Tooling dispatches on language adapters; no command assumes the Rust toolchain.Touches: `smith-harness::wasm`, `smith-cli`, `smith:plugin` WIT world.Verify:- Init scaffolds a cargo project with a pinned WIT copy.- Build emits artifact and manifest without recompiling at load time.- Check rejects ambient imports, growable memories, and capability-versus-grant mismatches with concrete fixes.- Dev watch swaps atomically into a running runtime.- Test uses mocked capabilities and golden determinism fixtures.The harness operates through the public sandboxed plugin surface with explicit project trust and no privileged built-in path.- Eval and RPC run trusted plugin commands, tools, providers, modules, and event actions through one live harness.- Every host effect is bounded, cancellable, attributable, durable, replay-visible, and secret-safe.- Built-in coding tools have no privileged effect path.- Reload swaps one coherent generation through an installed agent.- Plugin tooling scaffolds, builds, validates, hot-swaps, and tests plugins.- UI and VCS registrations are ready for `SMH-PLAN-TUIR0001`.- Fresh workspace formatting, lint, tests, docs, architecture, audit, and pinned nightly gates pass without warnings.+104 / −14 text lines
Changes to active tools apply only between provider requests.### Plugin 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```A session is an append-only branching history with stable IDs, parent links, timestamps, and a selected leaf.Entries represent messages, tool activity, model changes, compaction, secret registration, VCS operations, and replay-relevant metadata.Session persistence uses length-prefixed CBOR frames.Session persistence uses length-prefixed CBOR frames with deterministic, transparent compression for eligible payloads.Allocation bounds apply before decoding and throughout decompression.Compression preserves frame traversal, frame-level recovery, and byte-preserving round trips of unknown frames.All tools use provider-neutral definitions, bounded output, explicit errors, cancellation, and recorded lifecycle events.Provider-specific constrained sampling is an optional transport capability, not a separate tool contract.### Durable effect boundaryEvery invoked SDK host effect is durable, including reads, searches, mutations, processes, provider operations, and VCS operations.An effect record contains its bounded canonical input and full bounded output, outcome, plugin generation, stable effect ID, and explicit causal parent.Secret plaintext is replaced before persistence.Effect intent becomes durable before execution.An intent-recording failure prevents execution.Completion records mutation state as `applied`, `not-applied`, or `unknown`.A missing completion or uncertain partial effect recovers as `unknown` and is never retried automatically.Completion-recording failure is terminal and reports the best known mutation state outside the failed record.```mermaidstateDiagram-v2 [*] --> Intent: persist intent Intent --> Running: begin bounded effect Running --> Completed: persist outcome Running --> Unknown: completion missing or uncertain Completed --> [*]: applied, not-applied, or unknown Unknown --> Reconciled: explicit reconciliation Reconciled --> [*]```Process termination includes descendants started by the invocation where the platform permits it.Fuzzy edits, freeform patches, terminal sessions, plans, subagents, permissions, MCP, and semantic search remain plugin behavior.Plugins run in a restricted runtime without direct operating-system, filesystem, environment, network, or clock access.Host effects are available only through typed Smith SDK functions.Host effects are available only through typed Smith SDK component interfaces granted by manifest and trust decisions.A failed plugin load leaves no registrations or subscriptions active.Reload either activates one coherent new plugin state or retains the previous state.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.Manifest and artifact reads are bounded before materialization, and canonical paths cannot escape their declared root.Zero or ambiguous implementations fail only when consumed, with candidates reported.Explicit user binding overrides automatic binding and must match the requested module contract.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.Later registration replaces earlier registration only where the contract permits replacement.Project-local executable configuration, plugins, and managed packages do not load before trust is resolved.Project-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.Non-interactive modes require an explicit or previously persisted decision to load project-local executable behavior.Handler-requested configuration changes are runtime-only; only explicit user commands persist configuration.Eval accepts a prompt, runs the same agent behavior without the TUI, and can emit human-readable or structured output.It can persist to a selected session.- every SDK effect has durable intent, completion, causal attribution, and three-state mutation evidence,- replay exposes incomplete effects as unknown and never retries them automatically,- 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,