README Source History Refs Reviews Compare Notes Search Review guide refactor(SM-004): add pi-inherited concept references - behavior-mutating events, tool renderers, extension context
9e114716dda3dfeb309f1c7a249f88a92d60ff89
HallucyGenie Agent <agent@hallucygenie.local > · 21 May 2026
SSH signature · not checked
Browse files Compare with HEAD
Changed files (1) Diff layout Auto Unified Split
docs/spec-sm-004-architecture.md Modified +33 / −22 text lines
59 59 | `Session`, `SessionEntry`, `SessionStore`, `AgentEvent`, `EngineEvent`, `AgentLoopConfig` | **SM-006** (`smith-core/`) | Business logic, events, sessions || `Session`, `SessionEntry`, `SessionStore`, `AgentEvent`, `EngineEvent`, `AgentLoopConfig` | **SM-006** (`smith-core/`) | Business logic, events, sessions |60 60 | `Provider` trait, model registry, auth | **SM-007** (`smith-ai/`) | LLM providers || `Provider` trait, model registry, auth | **SM-007** (`smith-ai/`) | LLM providers |61 61 | TUI widgets, `TuiApp`, render loop, themes | **SM-008** (`smith-tui/`) | Terminal rendering || TUI widgets, `TuiApp`, render loop, themes | **SM-008** (`smith-tui/`) | Terminal rendering |62 - | Plugin system, SDK, built-in tools, sandbox | **SM-009** (`smith-harness/`) | Orchestration + plugins |62 + | Plugin system, SDK, built-in tools | **SM-009** (`smith-harness/`) | Orchestration + plugins |63 63 | CLI args, session commands | **SM-010** (`smith-cli/`) | Binary entry point || CLI args, session commands | **SM-010** (`smith-cli/`) | Binary entry point |64 64 | Workspace deps, crate graph | **SM-011** | Workspace manifest || Workspace deps, crate graph | **SM-011** | Workspace manifest |65 65 | Testing strategy | **SM-012** | Test plan || Testing strategy | **SM-012** | Test plan |
66 + | Behavior-mutating event returns | **SM-009** (`smith-harness/`) | Plugin events return typed results (block, transform, cancel, replace) — inherited from pi |67 + | Tool renderers (`renderCall`, `renderResult`) | **SM-009** (`smith-harness/`) + **SM-008** (`smith-tui/`) | Per-tool custom TUI rendering — inherited from pi |68 + | ExtensionContext / ExtensionUIContext | **SM-009** (`smith-harness/`) | Plugin control over agent lifecycle and UI — inherited from pi |69 + | Agent loop hooks (`beforeToolCall`, `afterToolCall`, `shouldStopAfterTurn`) | **SM-006** (`smith-core/`) | Pre/post tool interception and loop control — inherited from pi |67 71 SM-004 is the **architecture narrative** — for type definitions, see the canonical specs above.SM-004 is the **architecture narrative** — for type definitions, see the canonical specs above.258 262 - Add new `SessionEntry` variants- Add new `SessionEntry` variants259 263 - Add new `EngineEvent` variants- Add new `EngineEvent` variants260 264 - Custom `Tool` implementations- Custom `Tool` implementations
265 + - Behavior-mutating hook implementations (`beforeToolCall`, `afterToolCall`) — see SM-006 §agent.rs266 + - Agent loop control callbacks (`shouldStopAfterTurn`, `prepareNextTurn`) — see SM-006 §agent.rs262 268 ## Crate: smith-ai ## Crate: smith-ai 439 445 ### Responsibilities ### Responsibilities 440 446 - Plugin loading (LuaJIT via mlua)- Plugin loading (LuaJIT via mlua)441 - - Plugin SDK (sandboxing, credential access)447 + - Plugin SDK (Lua API, credential access, **ExtensionContext** for agent control, **ExtensionUIContext** for UI interaction)442 448 - Event loop (engine owns it)- Event loop (engine owns it)443 449 - Coordinates core + ai + tui- Coordinates core + ai + tui444 450 - Receives UI events, dispatches to engine- Receives UI events, dispatches to engine461 467 pub struct PluginSdk {pub struct PluginSdk {462 468 // smith.fs.*, smith.env.*, smith.credentials.* // smith.fs.*, smith.env.*, smith.credentials.*
469 + // smith.abort(), smith.shutdown(), smith.getContextUsage()470 + // smith.ui.select(), smith.ui.confirm(), smith.ui.setStatus()466 - ### LuaJIT Sandbox Configuration474 + ### Lua Runtime Restrictions468 476 **Standard libraries**: Keep `string`, `table`, `math`, `coroutine`, `utf8`, `package`**Standard libraries**: Keep `string`, `table`, `math`, `coroutine`, `utf8`, `package`469 477 (with custom searchers). Strip `io`, `os`, `debug`, `getfenv`, `setfenv`.(with custom searchers). Strip `io`, `os`, `debug`, `getfenv`, `setfenv`.471 - **Safe host functions** exposed through a `smith.*` Lua module:479 + **Host functions** exposed through a `smith.*` Lua module:473 - smith.fs.read("path") -- read file (enforced: scoped to project dirs) 474 - smith.fs.write("path", data) -- write file (enforced: scoped to project dirs) 481 + smith.fs.read("path") -- read file482 + smith.fs.write("path", data) -- write file475 483 smith.env.get("HOME") -- read-only env accesssmith.env.get("HOME") -- read-only env access476 484 smith.time.now() -- safe timestampsmith.time.now() -- safe timestamp479 - Path restrictions are enforced by the SDK (Rust), not by plugins. Plugins only have480 - access through `smith.fs.*`. They cannot bypass restrictions because they have no481 - raw filesystem API. The SDK enforces: reads/writes are scoped to smith's working482 - directory or explicitly allowed paths. Plugins are Lua (untrusted), SDK is Rust487 + Plugins have no `io`, `os`, `debug`, `getfenv`, `setfenv` globals. They can only488 + access the filesystem and environment through `smith.fs.*` and `smith.env.*`.489 + No path restrictions or capability grants — the Lua runtime itself is the only490 + guard. Built-in tools and user plugins use the same API.485 492 **Custom require** via `mlua-pkg` crate — composable resolver chain:**Custom require** via `mlua-pkg` crate — composable resolver chain:486 493 - `NativeResolver` — smith's Rust API surface to plugins- `NativeResolver` — smith's Rust API surface to plugins487 - - `FsResolver` — scoped to plugin's own directory only 494 + - `FsResolver` — plugin's own directory488 495 - `MemoryResolver` — embedded modules smith provides- `MemoryResolver` — embedded modules smith provides489 496 - Plugins can be multi-file with nested directories- Plugins can be multi-file with nested directories546 553 /// Lua plugin loader (uses mlua with LuaJIT + mlua-pkg for custom require)/// Lua plugin loader (uses mlua with LuaJIT + mlua-pkg for custom require)547 554 pub struct LuaPluginLoader { /* TODO */ }pub struct LuaPluginLoader { /* TODO */ }549 - // SandboxConfig and Capability are defined canonically in SM-005 (smith/src/config.rs).552 559 ### Extension Points### Extension Points553 560 - New interface types (add to `PluginInterface` hierarchy)- New interface types (add to `PluginInterface` hierarchy)554 561 - New plugin loaders (e.g., native Rust `.so` plugins)- New plugin loaders (e.g., native Rust `.so` plugins)556 - - Plugin-to-plugin communication562 + - Behavior-mutating event handlers (block tool calls, transform input, override system prompts)563 + - Tool custom renderers (`renderCall`, `renderResult`)564 + - Plugin-to-plugin communication via EventBus 558 566 ## Crate: smith-cli## Crate: smith-cli611 619 **LLM bounding mechanisms:****LLM bounding mechanisms:**612 620 1. Tool registry: smith controls which tools the LLM sees — not all tools are exposed1. Tool registry: smith controls which tools the LLM sees — not all tools are exposed613 621 2. Secret proxy: LLM sees `smith:sec:N` identifiers, never real secrets2. Secret proxy: LLM sees `smith:sec:N` identifiers, never real secrets614 - 3 . SDK path restrictions: plugins access filesystem only through `smith.fs.*` (Rust), 615 - which enforces scoping. Plugins have no raw filesystem API and cannot bypass.622 + 3. Lua runtime restrictions: plugins have no `io`, `os`, `debug` globals. They623 + access the filesystem only through `smith.fs.*` (Rust). No capability system. 617 - Security is **configuration**, not confirmation dialogs. Users configure which tools618 - are available. Popups that users learn to auto-accept are theater, not security.625 + Security is primarily **configuration** — users configure which tools are active. 626 + Tools execute without confirmation dialogs. Popups that users learn to627 + auto-accept are theater, not security. Security comes from restricting what628 + tools can do (restricted Lua context, no filesystem escape) and what the LLM629 + sees (secret proxy), not from interrupting the user.620 631 **The secret proxy system** prevents LLM data exfiltration:**The secret proxy system** prevents LLM data exfiltration:621 632 - Every user message and tool output scanned for secret patterns (env vars, tokens, keys)- Every user message and tool output scanned for secret patterns (env vars, tokens, keys)742 753 limit = { type = "number", description = "Max lines", optional = true }, limit = { type = "number", description = "Max lines", optional = true },744 755 execute = function(params) execute = function(params)745 - -- smith.fs.* is the safe, sandboxed file API756 + -- smith.fs.* is the file API746 757 local content = smith.fs.read(params.path) local content = smith.fs.read(params.path)747 758 if params.offset then if params.offset then748 759 content = smith.string.lines(content, params.offset, params.limit) content = smith.string.lines(content, params.offset, params.limit)866 877 - Trait hierarchy for each module- Trait hierarchy for each module867 878 - Extension point catalog- Extension point catalog868 879 - Security model layers- Security model layers869 - - Plugin system design (interfaces, loading, sandboxing )880 + - Plugin system design (interfaces, loading)870 881 - Dependency decisions with rationale- Dependency decisions with rationale871 882 - Open research questions- Open research questions959 970 mod.rs — module root, re-exports mod.rs — module root, re-exports960 971 interface.rs — PluginInterface, Plugin, ToolInterface, WidgetInterface, etc. interface.rs — PluginInterface, Plugin, ToolInterface, WidgetInterface, etc.961 972 loader.rs — PluginLoader trait, LuaPluginLoader loader.rs — PluginLoader trait, LuaPluginLoader962 - sandbox.rs — SandboxConfig, Capability, bytecode caching973 + sdk.rs — Lua SDK module definition, bytecode caching963 974 sdk.rs — smith.* Lua module definition (what plugins can call) sdk.rs — smith.* Lua module definition (what plugins can call)964 975 built-in/ — Lua plugins shipped with smith (NOT in src/)built-in/ — Lua plugins shipped with smith (NOT in src/)