repositories / smith

smith

There are many coding harnesses - but this one is fast

owned by bugabinga

refactor(SM-004): add pi-inherited concept references - behavior-mutating events, tool renderers, extension context

9e114716dda3dfeb309f1c7a249f88a92d60ff89

HallucyGenie Agent <agent@hallucygenie.local> ·

SSH signature · not checked

Browse filesCompare with HEAD

Changed files (1)

+33 / −22 text lines

Diff layout

docs/spec-sm-004-architecture.md

Modified

+33 / −22 text lines

5959| `Session`, `SessionEntry`, `SessionStore`, `AgentEvent`, `EngineEvent`, `AgentLoopConfig` | **SM-006** (`smith-core/`) | Business logic, events, sessions |
6060| `Provider` trait, model registry, auth | **SM-007** (`smith-ai/`) | LLM providers |
6161| 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 |
6363| CLI args, session commands | **SM-010** (`smith-cli/`) | Binary entry point |
6464| Workspace deps, crate graph | **SM-011** | Workspace manifest |
6565| 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 |
6771SM-004 is the **architecture narrative** — for type definitions, see the canonical specs above.
258262- Add new `SessionEntry` variants
259263- Add new `EngineEvent` variants
260264- Custom `Tool` implementations
265- Behavior-mutating hook implementations (`beforeToolCall`, `afterToolCall`) — see SM-006 §agent.rs
266- Agent loop control callbacks (`shouldStopAfterTurn`, `prepareNextTurn`) — see SM-006 §agent.rs
262268## Crate: smith-ai
439445### Responsibilities
440446- 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)
442448- Event loop (engine owns it)
443449- Coordinates core + ai + tui
444450- Receives UI events, dispatches to engine
461467pub struct PluginSdk {
462468 // smith.fs.*, smith.env.*, smith.credentials.*
469 // smith.abort(), smith.shutdown(), smith.getContextUsage()
470 // smith.ui.select(), smith.ui.confirm(), smith.ui.setStatus()
464472```
466### LuaJIT Sandbox Configuration
474### Lua Runtime Restrictions
468476**Standard libraries**: Keep `string`, `table`, `math`, `coroutine`, `utf8`, `package`
469477(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:
472480```lua
473smith.fs.read("path") -- read file (enforced: scoped to project dirs)
474smith.fs.write("path", data) -- write file (enforced: scoped to project dirs)
481smith.fs.read("path") -- read file
482smith.fs.write("path", data) -- write file
475483smith.env.get("HOME") -- read-only env access
476484smith.time.now() -- safe timestamp
477485```
479Path restrictions are enforced by the SDK (Rust), not by plugins. Plugins only have
480access through `smith.fs.*`. They cannot bypass restrictions because they have no
481raw filesystem API. The SDK enforces: reads/writes are scoped to smith's working
482directory or explicitly allowed paths. Plugins are Lua (untrusted), SDK is Rust
483(trusted).
487Plugins have no `io`, `os`, `debug`, `getfenv`, `setfenv` globals. They can only
488access the filesystem and environment through `smith.fs.*` and `smith.env.*`.
489No path restrictions or capability grants — the Lua runtime itself is the only
490guard. Built-in tools and user plugins use the same API.
485492**Custom require** via `mlua-pkg` crate — composable resolver chain:
486493- `NativeResolver` — smith's Rust API surface to plugins
487- `FsResolver` — scoped to plugin's own directory only
494- `FsResolver` — plugin's own directory
488495- `MemoryResolver` — embedded modules smith provides
489496- Plugins can be multi-file with nested directories
546553/// Lua plugin loader (uses mlua with LuaJIT + mlua-pkg for custom require)
547554pub struct LuaPluginLoader { /* TODO */ }
549// SandboxConfig and Capability are defined canonically in SM-005 (smith/src/config.rs).
550557```
552559### Extension Points
553560- New interface types (add to `PluginInterface` hierarchy)
554561- New plugin loaders (e.g., native Rust `.so` plugins)
555- Sandbox policies
556- Plugin-to-plugin communication
562- 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
558566## Crate: smith-cli
611619**LLM bounding mechanisms:**
6126201. Tool registry: smith controls which tools the LLM sees — not all tools are exposed
6136212. Secret proxy: LLM sees `smith:sec:N` identifiers, never real secrets
6143. SDK path restrictions: plugins access filesystem only through `smith.fs.*` (Rust),
615 which enforces scoping. Plugins have no raw filesystem API and cannot bypass.
6223. Lua runtime restrictions: plugins have no `io`, `os`, `debug` globals. They
623 access the filesystem only through `smith.fs.*` (Rust). No capability system.
617Security is **configuration**, not confirmation dialogs. Users configure which tools
618are available. Popups that users learn to auto-accept are theater, not security.
625Security is primarily **configuration** — users configure which tools are active.
626Tools execute without confirmation dialogs. Popups that users learn to
627auto-accept are theater, not security. Security comes from restricting what
628tools can do (restricted Lua context, no filesystem escape) and what the LLM
629sees (secret proxy), not from interrupting the user.
620631**The secret proxy system** prevents LLM data exfiltration:
621632- Every user message and tool output scanned for secret patterns (env vars, tokens, keys)
742753 limit = { type = "number", description = "Max lines", optional = true },
743754 },
744755 execute = function(params)
745 -- smith.fs.* is the safe, sandboxed file API
756 -- smith.fs.* is the file API
746757 local content = smith.fs.read(params.path)
747758 if params.offset then
748759 content = smith.string.lines(content, params.offset, params.limit)
866877- Trait hierarchy for each module
867878- Extension point catalog
868879- Security model layers
869- Plugin system design (interfaces, loading, sandboxing)
880- Plugin system design (interfaces, loading)
870881- Dependency decisions with rationale
871882- Open research questions
959970 mod.rs — module root, re-exports
960971 interface.rs — PluginInterface, Plugin, ToolInterface, WidgetInterface, etc.
961972 loader.rs — PluginLoader trait, LuaPluginLoader
962 sandbox.rs — SandboxConfig, Capability, bytecode caching
973 sdk.rs — Lua SDK module definition, bytecode caching
963974 sdk.rs — smith.* Lua module definition (what plugins can call)
964975built-in/ — Lua plugins shipped with smith (NOT in src/)
965976 tools/