repositories / smith

smith

There are many coding harnesses - but this one is fast

owned by bugabinga

docs(system): port plugin contracts to wasm component runtime

6a09faad0ab73b8be6268ee19b7479b00f6f1d50

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Changed files (3)

+280 / −44 text lines

Diff layout

.system/board.json

Modified

+8 / −2 text lines

33 "items": {
44 "SMH-ISSUE-R4SEXWVT": {
55 "state": "done",
6 "source": "assess",
7 "updatedAt": "2026-09-11T08:32:58.566Z"
6 "updatedAt": "2026-09-11T08:32:58.566Z",
7 "source": "assess"
8 },
9 "SMH-PLAN-AIAG0001": {
10 "state": "done",
11 "source": "agent",
12 "updatedAt": "2026-09-11T09:20:57.959Z",
13 "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."
814 },
915 "SMH-PLAN-CORE0001": {
1016 "state": "done",

.system/plans/SMH-PLAN-PLUG0001-plugin-harness/index.md

Modified

+168 / −28 text lines

1111# Sandboxed Plugin Harness
13## Entry
13## Outcome
15- Eval and RPC use the shared provider-independent runtime.
16- Agent, tool, provider, and session events are typed and ordered.
15Trusted component packages extend the live agent through bounded, durable, generation-owned contracts.
16Failed load, effect, handler, or reload paths leave explicit evidence and no mixed plugin state.
18## Order
18## Scope
201. Add project trust resolution before project executable configuration or package discovery.
212. Add the wasm host: engine config, artifact validation, determinism knobs, fuel and memory ceilings.
223. Add manifest-based package discovery with contract version and capability requests.
234. Add deterministic module binding, ambiguity diagnostics, and plugin precedence.
245. Add the typed `smith:plugin` WIT world covering filesystem, search, tools, commands, providers, UI, VCS, logging, and lifecycle control.
256. Bridge runtime events and plugin results without exposing internal ownership.
267. Load each plugin into a transactional registration set so failure leaves no active residue.
278. Route built-in commands, presentation, themes, keybindings, prompts, and workflows through the same loader.
289. Add atomic reload with rollback and preserved session continuity.
2910. Wire trusted global, project, and explicit plugin sources into the harness.
3011. Add plugin tooling: init, build, check, dev watch with hot swap, test harness with mocked capabilities.
20This plan delivers executable commands, tools, providers, modules, events, built-in tool artifacts, and plugin tooling.
21It delivers validated generation-owned UI and VCS registrations; their execution remains in `SMH-PLAN-TUIR0001`.
23## Delivery graph
25Each slice leaves one observable path integrated and verified.
27```mermaid
28flowchart LR
29 AIAG["AIAG: shared agent runtime"] --> S1["Trusted transactional command"]
30 S1 --> S2["Durable bounded effects"]
31 S2 --> S3["Bounded composition and fatal failures"]
32 S3 --> S4["Callable modules"]
33 S4 --> S5["Common tool and provider path"]
34 S5 --> S6["Live typed actions"]
35 S6 --> S7["Atomic reload and precedence"]
36 S7 --> S8["Plugin tooling"]
37 S7 --> TUIR["TUIR: UI, VCS, replay surfaces"]
38 S8 --> RELS["RELS: release readiness"]
39 TUIR --> RELS
40```
3242## Interfaces
3646- `smith-harness::plugins`: discovery, binding, registration transactions, reload.
3747- `smith:plugin` WIT world: the only plugin path to host effects.
39## Verification
49## Slices
41- Ambient WASI imports are unavailable; ungranted capabilities fail instantiation.
42- Fuel exhaustion and memory ceilings surface as explicit plugin errors.
43- Project plugins and executable configuration cannot run before trust resolution.
44- Non-interactive untrusted project behavior is skipped with a visible diagnostic.
45- Built-in and user plugins use the same sandbox and registration path.
46- Zero, singleton, ambiguous, and explicit module bindings follow the specification.
47- Failed load or reload leaves no subscriptions, tools, providers, or UI registrations behind.
48- Successful reload preserves the active session and swaps one coherent plugin state.
51### 1. Trusted transactional command
53A trusted built-in or user package contributes one command through the wasm component sandbox.
54Project packages remain undiscovered until trust resolves.
55An explicit path grants one-run trust only to its canonical source.
56Failed instantiation publishes nothing.
58Touches: `smith-harness::wasm`, `smith-harness::trust`, `smith-harness::plugins`, `smith-harness::runtime`, `smith-cli`.
60Verify:
62- Canonical native paths distinguish otherwise-colliding project identities.
63- Manifest and artifact reads cannot escape their declared root.
64- Ambient WASI imports fail validation; ungranted capability imports fail instantiation.
65- Artifact reads, decoding, instantiation, memory and table ceilings, fuel, logs, output, deadline, and cancellation remain bounded.
66- Host effects are unavailable before generation publication.
67- Interactive, eval, and RPC modes expose the same trust outcome and diagnostics.
69### 2. Durable bounded effects
71The command invokes a typed filesystem or search effect through a granted capability.
72The session stores bounded full intent and completion records with stable identity, causal parent, generation, redacted secrets, and three-state mutation evidence.
73Replay exposes the same records without re-execution.
75Touches: `smith::tool`, `smith::session`, `smith-core::tools`, `smith-core::session`, `smith-core::replay`, `smith-harness::plugins`, `smith:plugin` world effect interfaces.
77Verify:
79- Intent persistence failure prevents execution.
80- Success, ordinary failure, cancellation, partial mutation, and completion-persistence failure retain correct evidence.
81- A dangling intent recovers as unknown and never retries automatically.
82- Full bounded effect payloads survive deterministic compressed-frame round trips.
83- Compression preserves traversal, corruption recovery, unknown frames, and allocation bounds.
84- Secret plaintext never enters effect records, diagnostics, or replay.
85- A `--no-session` eval effect records against the temporary store; clean exit removes it, abnormal termination retains it.
87### 3. Bounded composition and fatal failures
89A plugin command uses host-orchestrated structured child work and controlled error handling.
90Ordinary typed guest errors are catchable; cancellation, budgets, sandbox violations, and recording failures are not.
92Touches: `smith-harness::wasm`, `smith-harness::plugins`, `smith:plugin` world task and error interfaces.
94Verify:
96- Child work shares the parent invocation budget and generation pin.
97- Every child finishes or cancels before its parent returns.
98- Calls to one plugin instance never run concurrently.
99- Fan-out cannot multiply resource limits.
100- Error reports retain package, generation, handler, event, and child-task context.
102### 4. Callable modules
104Host and plugin consumers invoke a discovered module through a logical major-versioned handle.
105Singleton binding is automatic; zero and ambiguous binding fail only on consumption; explicit binding is deterministic.
107Touches: `smith-harness::plugins`, `smith:plugin` world module interface.
109Verify:
111- Manifest-based discovery validates bounded contract and artifact sources before instantiation.
112- Undeclared exports remain private.
113- Diagnostics report the consumer and sorted candidates.
114- Explicit bindings must satisfy the requested major contract.
115- Existing logical handles resolve against a newly published conforming generation; active calls finish against their pinned generation.
116- Guest-local state resets after rebinding.
118### 5. Common tool and provider path
120A plugin contributes an executable provider-visible tool and a provider through the same generation and SDK effect boundary.
121Built-in `read`, `write`, `edit`, `bash`, `find`, `grep`, and `ls` become embedded component artifacts over the public typed primitives.
123Touches: `smith::tool`, `smith::provider`, `smith-core::agent`, `smith-ai`, `smith-harness::plugins`, `smith-harness::runtime`, built-in component packages.
125Verify:
127- The provider request and returned tool batch use one pinned generation.
128- Advertised definitions and invoked handlers cannot diverge.
129- Built-in and user tools have identical sandbox, cancellation, validation, effect recording, and error behavior.
130- Provider operations use durable SDK effects without exposing credentials.
131- A missing public primitive blocks migration rather than creating a privileged built-in path.
133### 6. Live typed actions
135An installed handler receives ordered live lifecycle events and returns cancellation, queued input, reload, model, provider, tool, prompt, or runtime-configuration actions.
136Cancellation is immediate; other actions publish only after the current provider stream and complete tool batch.
138Touches: `smith::event`, `smith-core::agent`, `smith-harness::plugins`, `smith-harness::runtime`, eval and RPC event bridges, `smith:plugin` world lifecycle interface.
140Verify:
142- Handler order is deterministic across interface modes.
143- Non-conflicting actions publish atomically between provider requests.
144- Conflicting field mutations are rejected without an implicit winner.
145- Runtime configuration actions do not persist configuration.
146- A failed or over-budget handler emits one diagnostic, remains disabled for its generation, and does not duplicate terminal events.
148### 7. Atomic reload and precedence
150Global, trusted project, explicit, and built-in sources assemble one candidate generation.
151Successful reload replaces the complete installed capability set; failed reload retains the previous generation.
153Touches: `smith-harness::trust`, `smith-harness::plugins`, `smith-harness::runtime`, `smith-core::agent`, `smith:plugin` world registration interfaces.
155Verify:
157- Precedence is built-in, global user, project, then explicit override.
158- Replacement succeeds only where the earlier contract permits it.
159- Removed registrations and subscriptions disappear together.
160- Session, branch, queue, secrets, cancellation, and active-turn state survive reload.
161- An installed `Agent` completes active calls on the old generation and uses the new generation for the next provider request.
162- Failed candidate validation, instantiation, binding, or publication leaves the active generation unchanged.
163- UI and VCS registrations participate in validation, ownership, replacement, and removal without executing deferred behavior.
165### 8. Plugin tooling
167`smith plugin init`, `build`, `check`, `dev`, and `test` cover scaffold, artifact build, lint, hot swap, and hosted testing.
168Tooling dispatches on language adapters; no command assumes the Rust toolchain.
170Touches: `smith-harness::wasm`, `smith-cli`, `smith:plugin` WIT world.
172Verify:
174- Init scaffolds a cargo project with a pinned WIT copy.
175- Build emits artifact and manifest without recompiling at load time.
176- Check rejects ambient imports, growable memories, and capability-versus-grant mismatches with concrete fixes.
177- Dev watch swaps atomically into a running runtime.
178- Test uses mocked capabilities and golden determinism fixtures.
49179- Repeated runs of one artifact with recorded host inputs produce identical outputs.
51181## Exit
53The harness operates through the public sandboxed plugin surface with explicit project trust and no privileged built-in path.
183- Eval and RPC run trusted plugin commands, tools, providers, modules, and event actions through one live harness.
184- Every host effect is bounded, cancellable, attributable, durable, replay-visible, and secret-safe.
185- Built-in coding tools have no privileged effect path.
186- Reload swaps one coherent generation through an installed agent.
187- Plugin tooling scaffolds, builds, validates, hot-swaps, and tests plugins.
188- UI and VCS registrations are ready for `SMH-PLAN-TUIR0001`.
189- Fresh workspace formatting, lint, tests, docs, architecture, audit, and pinned nightly gates pass without warnings.
55191## Stop conditions
193- An effect can begin before durable intent publication.
194- The agent cannot pin one generation through a provider round and tool batch.
195- Runtime mutations cannot wait for a between-request safe point.
196- Plugin execution can escape cancellation or resource budgets.
57197- A built-in requires an effect absent from the public WIT world.
58- Trust must execute project code to determine trust.
59- Reload cannot separate candidate registrations from active state.
60- Deterministic knobs cannot be enforced without unacceptable layout latency.
198- Trust must execute or enumerate project code before deciding trust.
199- Candidate construction can mutate host or active runtime state.
200- Deterministic engine knobs cannot be enforced without unacceptable layout latency.

.system/specs/SMH-SPEC-SPEC0001-smith-specification/index.md

Modified

+104 / −14 text lines

5555Tool calls and results remain correctly paired and ordered.
5656Injected messages never split a tool call from its result.
57Changes to active tools apply only between provider requests.
58### Plugin event boundary
60Plugin handlers run synchronously in deterministic registration order under one bounded invocation budget shared with structured child tasks.
61They return typed actions rather than mutable runtime ownership.
62Actions may request cancellation, queued input, reload, or runtime-only model, provider, tool, prompt, and configuration changes.
63Cancellation applies immediately.
64Other actions are validated as one batch and apply atomically between provider requests, after the current stream and complete tool-result batch.
65Conflicting mutations are rejected; no implicit winner is selected.
67A 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.
68Terminal agent events remain singular.
70```mermaid
71sequenceDiagram
72 participant P as Provider round
73 participant A as Agent boundary
74 participant H as Ordered handlers
75 participant G as Runtime generation
76 P-->>A: Stream and complete tool batch
77 A->>H: Typed lifecycle events
78 H-->>A: Typed action batch
79 A->>A: Validate and reject conflicts
80 A->>G: Publish coherent runtime changes
81 G-->>P: Next request snapshot
82```
5984## Providers, models, and authentication
126151A session is an append-only branching history with stable IDs, parent links, timestamps, and a selected leaf.
127152Entries represent messages, tool activity, model changes, compaction, secret registration, VCS operations, and replay-relevant metadata.
129Session persistence uses length-prefixed CBOR frames.
154Session persistence uses length-prefixed CBOR frames with deterministic, transparent compression for eligible payloads.
155Allocation bounds apply before decoding and throughout decompression.
156Compression preserves frame traversal, frame-level recovery, and byte-preserving round trips of unknown frames.
130158It guarantees:
132160- deterministic encoding,
172200All tools use provider-neutral definitions, bounded output, explicit errors, cancellation, and recorded lifecycle events.
173201Provider-specific constrained sampling is an optional transport capability, not a separate tool contract.
203### Durable effect boundary
205Every invoked SDK host effect is durable, including reads, searches, mutations, processes, provider operations, and VCS operations.
206An effect record contains its bounded canonical input and full bounded output, outcome, plugin generation, stable effect ID, and explicit causal parent.
207Secret plaintext is replaced before persistence.
209Effect intent becomes durable before execution.
210An intent-recording failure prevents execution.
211Completion records mutation state as `applied`, `not-applied`, or `unknown`.
212A missing completion or uncertain partial effect recovers as `unknown` and is never retried automatically.
213Completion-recording failure is terminal and reports the best known mutation state outside the failed record.
215```mermaid
216stateDiagram-v2
217 [*] --> Intent: persist intent
218 Intent --> Running: begin bounded effect
219 Running --> Completed: persist outcome
220 Running --> Unknown: completion missing or uncertain
221 Completed --> [*]: applied, not-applied, or unknown
222 Unknown --> Reconciled: explicit reconciliation
223 Reconciled --> [*]
224```
175226### File effects
177228- Read supports bounded line windows and identifies unsupported binary content.
186237Process termination includes descendants started by the invocation where the platform permits it.
187238Shell output arriving immediately after process exit is not silently truncated.
189Tool mutation is recorded only when the effect succeeds.
190A failed recording step cannot leave a successful mutation presented as unrecorded success.
240Mutation completion records the observed outcome even when execution fails.
241No successful or uncertain mutation is presented as unrecorded success.
192243Compatibility adapters may translate external tool names only when semantics are equivalent.
193244Fuzzy edits, freeform patches, terminal sessions, plans, subagents, permissions, MCP, and semantic search remain plugin behavior.
207258Plugins run in a restricted runtime without direct operating-system, filesystem, environment, network, or clock access.
208259Plugin execution is resource-bounded.
209Host effects are available only through typed Smith SDK functions.
260Host effects are available only through typed Smith SDK component interfaces granted by manifest and trust decisions.
210261Built-in plugins have no privileged effect path.
212263Plugins may contribute:
221272- VCS workflows.
223274Plugin events are ordered and typed.
224A failed plugin load leaves no registrations or subscriptions active.
225Reload either activates one coherent new plugin state or retains the previous state.
275A candidate generation can declare and validate contributions but cannot invoke operational effects or mutate the active runtime before publication.
276A failed load leaves no registrations or subscriptions active.
277Reload publishes one complete generation or retains the previous generation.
279A generation owns every plugin instance, registration, subscription, binding, and contribution.
280Session, branch, queue, secrets, cancellation, and active-turn state live outside the generation and survive reload.
281Guest-local implementation state resets on reload.
282Removed contributions disappear at publication.
283Calls already running complete against their pinned generation; later calls resolve against the published generation.
285Each provider request pins one generation through its response and complete tool-call/result batch.
286The pinned generation supplies both advertised definitions and executable handlers.
287Built-in coding tools are embedded component artifacts loaded through the normal sandbox; they call the same typed host primitives available to user plugins.
289Smith SDK calls may catch ordinary typed guest errors, but not cancellation, budget exhaustion, sandbox violations, or host-effect recording failures.
290Smith 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.
291Fan-out cannot multiply resource limits.
292The budget covers deadline, guest fuel, component memory and table ceilings, host allocations, logs, conversions, and output.
226294Session continuity survives reload.
228296### Discovery and modules
230298Version 1 discovers plugin packages by path convention.
231Each package carries a manifest declaring its plugin artifact, contract version, and requested capabilities.
232Package and artifact identities are deterministic and validated before execution.
299Each package carries a manifest declaring its plugin artifact, world version, and requested capabilities.
300Package, artifact, and manifest identities are deterministic and validated before instantiation.
233301Artifacts failing validation never execute.
302Manifest and artifact reads are bounded before materialization, and canonical paths cannot escape their declared root.
304A module contract is a typed, major-versioned component interface.
305Undeclared exports remain private.
235306A module can have zero, one, or multiple implementations.
236307One implementation binds automatically.
237Zero or ambiguous implementations fail only when consumed, with candidates reported.
238Explicit user binding overrides automatic binding and must match the requested module contract.
308Zero or ambiguous implementations fail only when consumed, with sorted candidates and the consumer reported.
309Explicit user binding overrides automatic binding and must satisfy the requested contract.
311Module consumers use logical major-versioned handles.
312A new invocation resolves each handle against the published generation; nested accesses during an active invocation resolve within its pinned generation.
313Reload can rebind only to an implementation satisfying the same major contract; guest-local state resets.
240315Precedence is built-in, global user, project, then explicit override.
241Later registration replaces earlier registration only where the contract permits replacement.
316Later registration replaces earlier registration only where the earlier contract explicitly permits replacement.
317Installed capabilities are validated as a complete set before atomic replacement or removal.
243319### Project trust
245Project-local executable configuration, plugins, and managed packages do not load before trust is resolved.
321Project-local executable configuration, plugins, modules, and managed packages are not enumerated or loaded before trust is resolved.
322A project trust identity is its lossless, platform-tagged canonical native path.
323Symlink aliases share one decision; distinct native paths cannot collide through text conversion.
246324Interactive mode can ask and persist the decision.
247325Non-interactive modes require an explicit or previously persisted decision to load project-local executable behavior.
326An explicit plugin path grants one-run trust only to that exact canonical source.
327Capability grants resolve at trust time for project plugins and at install time for user plugins.
248328Ignoring untrusted project behavior produces a visible diagnostic.
250330Trust does not remove the plugin sandbox or tool boundaries.
264344Invalid values fail with their source and field path.
265345Unknown values follow the owning schema's explicit policy.
346Handler-requested configuration changes are runtime-only; only explicit user commands persist configuration.
267348## Terminal interface
298379### Eval
300381Eval accepts a prompt, runs the same agent behavior without the TUI, and can emit human-readable or structured output.
301It can persist to a selected session.
382It auto-creates a named session by default.
383`--no-session` runs effects against a temporary session store removed on clean exit and retained after abnormal termination.
384Effects never execute without a durable recording destination.
303386### JSON-RPC
367450- provider catalogs remain usable offline and reject stale refresh publication,
368451- model requests never use unadvertised capabilities,
369452- project plugins cannot execute before trust resolution,
453- every SDK effect has durable intent, completion, causal attribution, and three-state mutation evidence,
454- replay exposes incomplete effects as unknown and never retries them automatically,
455- event handlers are bounded, ordered, and publish conflict-free runtime actions only at safe points,
456- reload atomically replaces one complete generation while active provider rounds remain pinned,
457- callable module handles rebind only to conforming implementations of the same major contract,
370458- built-in and user plugins use the same sandboxed effect APIs,
459- structured child work cannot suppress cancellation or exceed its shared budget,
460- compressed session frames remain bounded, recoverable, traversable, and deterministic,
371461- terminal shutdown restores host state across supported exit paths,
372462- RPC consumers can assemble complete messages from ordered events,
373463- required quality, architecture, documentation, and release gates pass without warnings.