docs: resolve plugin design TODOs into SPEC §9 (#1)
f3e2b0374f8a87811a454df4ad119ea2c32a0822
Oliver Jan Krylow <oliver@bugabinga.net> ·
SSH signature · not checked
- Parent 1: 96ef3c2742e7
* docs: resolve plugin design TODOs into SPEC §9
Close the open design-doc TODO sections by reconciling them into the
canonical spec. New SPEC §9 subsections:
- §9.15 Dependency Resolution — presence + API-generation checks,
topological load order, cycle detection; no version-range solving in v1.
- §9.16 Plugin Hot-Reload — whole-domain replacement, triggers, rollback,
session continuity, dependents rebinding.
- §9.17 Plugin Error Model — per-phase fault isolation; host never crashes.
- §9.18 Inter-Plugin Messaging Bus — smith.bus.* namespaced pub/sub.
Also: fix §9.10 to name LuaLS/EmmyLua as the canonical annotation dialect
with required tags; add smith.bus.* to the namespace list; add
`smith plugins reload` to §10.2 CLI surface.
Convert PLUGIN-SDK-DESIGN.md and AI-CRATE-DESIGN.md TODO checklists into
resolution tables pointing each item to its canonical SPEC section or
implementation tracker.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB
* docs: add host configuration reload contract (SPEC §9.19)
Plugin reload (§9.16) covered plugin code; Smith's own settings also need
runtime reload. New §9.19 mirrors the §9.16 contract shape:
- scope: re-evaluate config cascade layers 1-4; CLI flags stay fixed,
- triggers: /reload-config command via smith.config.reload(), config file
watch, and automatic re-evaluation after a plugin reload changes
layer-3 contributions,
- sequence: validate + re-resolve models fully, swap atomically, roll back
on any failure with exact key path,
- effects: theme, keybindings, active tools, resolved model; then a
config_changed plugin event with changed key paths,
- continuity: in-flight turns and tool executions keep old values; config
reload never touches plugin domains or the session,
- restart-only set: CLI flags, XDG dirs, session identity, run mode,
bundled providers.json.
Cross-refs wired in §5.6 (cascade), §9.8 (event), §9.10 (smith.config.*),
§9.11 (/reload-config built-in).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB
* docs: expose config reload to RPC mode (SPEC §9.19, §10.2)
RPC clients (e.g. IDE integrations editing config on the user's behalf)
need to trigger a host config reload without restarting the process. Add
the config/reload JSON-RPC method as a §9.19 trigger; the response carries
changed key paths on success or the validation failure verbatim. Eval mode
stays startup-only.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB
* docs: record deferred RPC method catalog intent (SPEC §10.2)
The RPC surface is expected to mirror the Lua SDK surface (§9.10) with
mode-specific additions and omissions, not define an independent API.
Pin that intent so the future catalog spec starts from §9.10.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB
* feat(prototypes): p02 lua interface descriptor — PASS
Proves SPEC §9.6 candidate 1: plain Lua descriptors + runtime validation
support community-defined plugin interfaces.
Evidence (cargo run, exit 0):
- conforming implementation passes with zero diagnostics,
- missing function fails with exact path (impl/missing_fn.lua.cancel),
- wrong shape fails with expected/actual (status: expected function, got
string),
- extra implementation fields are hidden through the interface view,
- runtime arg validation rejects bad call types naming fn/param
(mlua reports Lua integers as "integer", not "number").
Also add prototypes/.cargo/config.toml capping lints at warn for
disposable prototype code; production zero-warnings policy unchanged.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB
* feat(prototypes): p06 session codec recovery — PASS with finding
Proves SPEC §6.6 recovery claims for length-prefixed CBOR sequences:
- truncated tail (mid-body and mid-prefix) stops parsing; prior entries
survive,
- corrupt entry BODY skips precisely with warning (framing intact),
- unknown future variants are distinguishable from corruption via
two-stage decode (ciborium::Value, then typed), preserved raw, and
survive a v1 rewrite → v2 read roundtrip.
Finding for §6.6: "corrupt entry: skip + warn if possible" holds only
while the length prefix is intact. A corrupted length prefix
desynchronizes framing; all subsequent entries are unrecoverable and
indistinguishable from truncation. Spec should state this boundary.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB
* feat(prototypes): p07 streamfn agent loop — PASS with finding
Proves SPEC §5.4 + §6.1-§6.4: a miniature agent loop drives text/tool/
done provider events through StreamFn only (no provider impl imports)
and produces deterministic AgentEvent sequences. BeforeToolCall hooks
allow/block/replace-args all verified; blocked calls never execute the
tool and surface to the provider as error tool results.
Finding for §6.4: blocked-call event semantics are unspecified — this
prototype chose ToolExecutionStart + ToolExecutionEnd(is_error) plus an
error tool result fed to the provider. Spec should state the contract.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB
* feat(prototypes): p04 plugin install/uninstall — PASS with findings
Proves SPEC §9.2/§9.3/§9.5: local-path + git-URL install into
data_dir/smith/plugins/<org>/<name>/, name charset + smith/* namespace
enforcement, restricted empty-env manifest evaluation (os/require
blocked, pure data only), smith_api default 1 + future-generation
refusal, no entry-code execution during install (armed side effect did
not fire), duplicate refusal without --force, uninstall keeps data by
default / --purge-data removes it / project plugins never touched.
Key findings (2×P1): manifest FILENAME (smith-plugin.lua) is never
stated in §9.2; git implementation boundary (gix vs shell-out) still
open — prototype shelled out to system git behind the boundary.
Plus P2/P3: --force semantics, duplicate definition, .git stripping,
data-dir lifecycle, exact restricted-env contents, staged validation
before copy.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB
* feat(prototypes): p03 subagent ecosystem simulation — PASS with findings
Proves SPEC §9.6: interface packages prevent ecosystem fragmentation
under realistic 5-plugin composition (interface pkg, conforming impl,
incompatible impl, pure-Lua adapter, consumer UI). Consumer targets only
the interface view; user config swaps alice <-> bob-adapted with zero
consumer changes; direct incompatible binding fails naming plugin,
interface+generation, exact missing functions, actual exports, and an
adapter hint.
Key findings (2×P1): §9.6 lacks adapter registration semantics (invented
`adapts` + make-factory convention); no user-override config syntax for
interface->implementation binding exists anywhere (invented
`interfaces = { ["community/subagent"] = "org/name" }`). Plus P2/P3:
manifest `interfaces`/`implements` field shapes undefined, conformance
check timing (load vs bind) unstated, singleton vs per-consumer instance
semantics open.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB
* feat(prototypes): p05 provider fetch normalize — PASS with disproof
Proves SPEC §7.3: pi.dev-primary field-level recursive merge with
catwalk gap-fill at field/model/provider granularity; providers.json
stays runtime authority (generate emits stdout suggestion + reviewable
patch, writes nothing); every change op carries path, old/new value,
and source attribution; two genuinely unresolvable conflict classes
(ambiguous-primary-source, type-mismatch-vs-curated-registry) are
detected, excluded, and reported explicitly.
DISPROOF: byte-for-byte unknown-field preservation is impossible with
default serde_json (keys re-sort alphabetically); preservation is
semantic (Value-equal) only. §7.3 must say which it means.
Key findings (2×P1): source-vs-curated-registry merge granularity
undefined (subtree merge would clobber curated cost objects); no
conflict taxonomy/policy exists at all. Plus P2: PR-agent exit-code
contract, replace_models carrier undefined, no canonical provider/
model schema.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB
* feat(prototypes): p08 tui testbackend — PASS with findings
Proves SPEC §8.8 + §17: ratatui TestBackend renders are deterministic
cell-by-cell (symbol + fg/bg/modifier), match a checked-in snapshot,
run fully headless (no crossterm dep, no TTY), and Lua theme tables
validated by a Rust schema drive widget styles; invalid themes are
rejected with exact path errors.
Key findings (2×P1): §8.8 has no theme schema at all (keys, nesting,
color format, missing-key policy all invented here); §17 snapshot
contract is undefined and text-only snapshots CANNOT catch theme
regressions — theme swap changed styles while text stayed byte-equal,
so theme snapshots require style-aware cell comparison. Plus P2:
invalid-user-theme runtime fallback policy unstated.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB
* feat(prototypes): p09 memory arena allocation — PASS with disproof
25/25 checks against the SMITH-MEMORY-ALLOCATION-PROFILE workload bands
(release numbers, synthetic fixtures generated at runtime to PLAN shapes
within 2.5% — multi-MiB fixtures deliberately not committed):
- discovery is O(session count): 535 sessions from 54.8KiB of a
41.64MiB corpus (0.13%), 4 allocs/session, 3.1ms,
- full load/replay stays inside research resident bands up to the
29.78MiB pathological session (69ms, 4.6MiB message intact),
- virtual scroll is O(visible rows): 41 allocs/frame constant across a
143x entry-count spread, giant message capped by lazy viewport wrap,
- request-build at ~250k tokens: transient peak 2.43MiB, zero live
growth over 50 builds,
- bumpalo scratch: render-window -100% allocator calls, x0.19 elapsed
(clear KEEP); request-build -99% calls but x1.00 elapsed and +22%
peak (marginal).
DISPROOF: arenas are not a latency win for request-build — serde_json
serialization dominates; the win is allocator-call pressure only.
Findings: adopt scratch-only-bumpalo policy (never persisted data,
stable IDs + owned strings); SPEC must require lazy metadata-only
session discovery (P1) and viewport-capped row materialization.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB
* feat(prototypes): p10 lua plugin heap limit — PASS with disproofs
Core question answered: Lua::set_memory_limit() WORKS and enforces
under mlua 0.10.5 + vendored LuaJIT (GC64 accepts mlua's tracking
allocator) — PLAN's "may not work under LuaJIT" warning does not hold
for the locked feature set. oom-table rejected at exactly the 16 MiB
quota (overshoot 0 bytes) with recoverable mlua MemoryError; state
reusable after gc_collect; host survives; isolated plugin B unaffected
by A's OOM. Host-created Lua strings ARE charged to the quota.
DISPROOFS:
- shared-state per-plugin quotas impossible: only a whole-state limit
exists; B got charged at A's retained 15.3MiB,
- Lua quota does NOT count host-side Rust allocations (8MiB userdata
payload registered 632 bytes) — domain teardown must bound those,
- hook-based fallback never fires under active JIT (0 fires over 3e6
iterations; interpreter-only, ~3.4x slowdown).
Findings: quota domain = one Lua state per plugin (aligns with §9.16
domains); scope quota wording to the Lua heap; CI-verify enforcement
per target (non-GC64 LuaJIT returns MemoryControlNotAvailable).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB
* feat(prototypes): p11 plugin memory domain reload — PASS, validates §9.16
The §9.16 full contract is implementable exactly as written: one
PluginDomain owns Lua state, descriptors, generation-keyed hook/tool
registries, bus subscription tokens, render cache, bump scratch, and a
cancellation token; reload = construct D' -> atomic swap -> drop D with
a single Drop impl and zero per-resource cleanup graph.
Evidence: 100 reload cycles plateau (growth <=77KB over 80 cycles,
tolerance 3MB; Lua used_memory constant; threads joined every drop);
reload latency avg 3.8-4.0ms incl. 450 registrations; rollback on
broken entry keeps old domain serving with partial D' registrations
discarded; 31MB Lua heap 100% reclaimed by domain drop; set_memory_limit
enforceable under vendored LuaJIT (corroborates p10); every escape path
(stale registry entry, leaked bus token, escaped thread) detected and
rejected via generation gating — 0 stale callbacks ran.
Finding (P2): a raw mlua::Function cloned out of the registry PANICS
("Lua instance is destroyed") after domain drop — abort-grade under the
no-panic invariant. §9.16 must mandate: callbacks reachable only through
the generation-keyed registry, every dispatch path generation-gates
before touching Lua. P3: memory plateau (not instantaneous RSS drop) is
the enforceable observable.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB
* docs: fold p02-p11 prototype evidence into SPEC
All ten prototypes ran to completion (result blocks in
prototypes/PLAN.md). Evidence-driven spec changes:
- §9.6 rewritten from prototype-gated stub to validated contract: plain
Lua descriptors canonical (Teal/annotation candidates rejected),
adapter convention (adapts + make factory), binding config syntax +
precedence, bind-time conformance with required diagnostics,
singleton-per-binding views (p02, p03).
- §9.2: manifest filename smith-plugin.lua canonical; empty restricted
manifest env stated; interfaces/implements/heap_limit fields (p03, p04).
- §9.5: staged validation before copy, duplicate definition, --force =
full replacement with data preserved, .git stripped; git boundary
evidence recorded (p04).
- §9.14: plugin heap quota — per-plugin Lua state domain, Lua-heap scope,
set_memory_limit enforcement (exact under vendored LuaJIT), loud
failure where unavailable, OOM -> domain replacement (p10).
- §9.16: generation-keyed callback discipline (raw handle use-after-drop
panics), audit-sweep escape detection, plateau as the enforceable
memory observable (p11).
- §6.4: blocked-call event contract (p07).
- §6.6: recovery boundaries — body-corruption skippable, length-prefix
corruption loses the tail, two-stage unknown-vs-corrupt decode (p06).
- §7.3: leaf-field merge granularity, conflict taxonomy + non-zero exit
contract, semantic (not byte) unknown-field preservation,
replace_models scoped to plugin overrides (p05).
- §8.8: theme schema contract (#rrggbb, path errors, fallback to
built-in on invalid user theme); §17.7: style-aware snapshot contract
(text-only cannot catch theme regressions) (p08).
- §13.1 Memory Policy: lazy metadata-only discovery, viewport-capped
row materialization, scratch-only bumpalo with measured keep/drop
gates, request-peak test gate (p09). bumpalo added to §2.3 deps.
- §18: campaign recorded.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB
* docs: pin provider schema and record Teal rejection (SPEC §7.3, §9.6)
Follow-ups from the p05/Teal discussion:
- §7.3: canonical provider/model JSON Schema at
smith-ai/src/providers.schema.json, validated (jsonschema crate) at
three boundaries: fetch-providers sources after normalization,
checked-in providers.json in CI, and smith.provider.register tables
at runtime. cost is always a per-token-price object, never a scalar —
the shape ambiguity behind p05's type-mismatch conflict class becomes
a source-boundary validation error. Unknown fields stay schema-legal
to keep the preservation rule intact.
- §9.6: Teal rejection rationale recorded (compile-time guarantees
evaporate at the runtime boundary; ecosystem bifurcation risk) and
replaced by generated typing: interface descriptors mechanically emit
LuaLS ---@class stubs via xtask doc-gen, so authors get editor-time
checking against the same descriptor the runtime validates.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB
* docs: adopt models.dev as primary provider source, decouple from pi
SPEC §7.3 reworked per project direction: pi is a philosophical guide,
not a dependency — Smith has no data or format coupling to it.
- Source priority: models.dev api.json primary (open, community-
maintained, CI-validated schema), catwalk fills gaps; pi.dev removed.
- Canonical schema: Smith does not invent one — it adopts the
models.dev shape (cost per-million-token USD object with cache/
reasoning/audio variants, limit {context,input,output}, modalities,
capability flags) as a pinned local JSON Schema snapshot at a
recorded upstream version, validated offline at the same three
boundaries; upstream evolution reviewed like a dependency bump.
Smith maps registry shapes into §5.7 ModelMetadata internally.
- Provider-data PR automation reworded agent-neutral.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB
* docs: fold design/plans/research normative content into SPEC, retire absorbed docs
Docs-tree audit (3 parallel reviews vs SPEC) found normative content
living outside the canonical spec. Folded:
From design docs (now deleted — fully absorbed):
- §9.8: canonical event catalog with per-event can-block matrix +
Lua handler return-table contracts,
- §9.9: exact ctx object shape (ui/session/model/cwd/signal),
- §9.10: missing namespaces (shortcut, credentials, active_tools,
send_message), tool/command/shortcut registration shapes, provider
merge rules + unregister APIs,
- §9.13: smith.vcs.* function surface with return shapes,
- §7.4: auth.json layout, auth_types (api_key/oauth/organization),
OAuth config/credential fields + callback-server login flow,
- §7.2: reasoning-in-content quirk; non-SSE JSON error with HTTP 200
must become ProviderEvent::Error (P12-proven),
- §8.3: probe contract (once/session, 100ms fail-conservative,
ImageProtocol=Kitty|Sixel, kitty-keyboard push/pop, CSI ?2026),
- §8.6: runtime-c2rust, side-by-side diffs, overlay anchor/size model,
- §8.7: layout primitive shapes (Size, BorderStyle, split_ratio, Panel),
- §8.11 (new): deferred v1 TUI scope.
From plans (PROTOTYPE-REPORT deleted after absorbing its two open
findings):
- §6.11: zstd per-entry inflation for small traces -> block-level or
min-size threshold,
- §16: doc resolution order (embedded -> share/smith/docs ->
SMITH_DOCS_PATH); §10.2: dotted help addressing; §6.8: system-prompt
SDK self-learn bootstrap.
From research (files kept, leakage folded or relabeled):
- §17.10 (new): CI — hermeticity rules, gate tiers, agent CI-safety
rules, Android/Termux lane posture,
- §17.4: overall 85% coverage, merge-block <80%; §17.5: ci profile;
§17.9: ±5% warn / ±10% fail bench thresholds,
- §2.3: anyhow/toml/regex/tokio-stream (decided in research, absent),
- research fixes: license + similar version + jsonschema status
reconciled to SPEC; clippy extended lints marked candidates;
RESEARCH-NOTES Rust-trait/WASM design marked rejected alternative;
stale "hooks smith lacks" note corrected (§6.4 has them).
AGENTS.md navigation updated. Lint set ruling: §3.2 stays canonical
as-is; research list is candidates only.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB
* docs: update PROJECT-INVARIANTS §2 tree after design-doc absorption
User-approved edit to the protected file: remove the deleted docs/design/
entries, note SPEC.md is self-contained, mark research/ as non-normative
evidence, add the prototypes/ tree, and record the change in the log.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LABEHeVpg74oyZNtWLUWpB
---------
Co-authored-by: Claude <noreply@anthropic.com>