0280. Runtime plugins in Tenon script
- Status: Accepted (maintainer, 2026-11-22; recommended defaults for all open questions; frozen-file edits listed here approved)
- Date: 2026-11-22
- Plan: backlog R17; relates to M15.3 (
wasm-host), M14 coding harness - Review: depends on 0277 (D5) and 0275 (D3), both Proposed
Context
Users of a Tenon TUI or agent harness want to add keybindings,
commands, themes, tools, prompt hooks and status-line widgets
without rebuilding the app. Today every extension is compiled in:
source plugins under plugins/ with manifests
(0088/0076/0091), or process plugins pinned by
exec_hash and called once per request through
Process.call_plugin (0099). Neither lets an end user
drop a .tn file into a config directory. The
reference interpreter (0003) already runs any checked program
without a C compiler (except FFI, 0152) and has fuel and deadline
limits (0017). The compiled host is C; the interpreter is Rust in
crates/tenon. wasm-host (M15.3) is
planned but has no backend or runtime yet.
plugins/proc (0267) already spawns children with
stdin/stdout pipes, read/write/
close_stdin, process groups and reaping.
Decision
- Scope. A script plugin is a Tenon
package (one
.tnor a directory withtenon.toml,[plugin] kind = "script") loaded at run time. It implements one host-declared interface and reaches the world only through host messages and the capabilities the host grants. It cannot declareextern(FFI), natives, generators or new platforms; those stay in compiled and process plugins. The checker rejects them: E09xx (allocate at implementation). - Engine: subprocess interpreter. The host
spawns
tenon-script <plugin-dir>viaplugins/procand keeps one session per plugin.tenon-scriptis thetenonbinary built interpreter-only (no C toolchain step); it checks the plugin, then serves framedcodecbinary messages on stdio, like the ffi-host child (interp_ffi.rsFramedChild). Chosen over in-process (linking the Rust interpreter into a C host is a new embedding ABI and shares the crash domain) and wasm (M15.3 does not exist). One box, one extra process per plugin, OS-level isolation for free. - API: one interface, typed messages. The host
package declares, e.g.
interface HarnessPlugin { fn handle(self, msg: HostMsg) -> Reply<Self> }withstruct Reply<S> { state: S, out: vec<PluginMsg> }, mirroringAgent.step -> Transition<Self>so agents learn one shape.HostMsg(Init,Key,Command,Prompt,Render,ToolCall, ...) andPluginMsg(Bind,AddCommand,Theme,Status,PromptEdit,ToolResult,Request) are closed enums with derived codecs.tenon genderives the plugin-side dispatchermainand the host-sideScriptPluginproxy from the interface. With ADR-0275 interface values the proxy can sit in the samevec<HarnessPlugin>as compiled plugins; before it, hosts holdvec<ScriptPlugin>. - Capabilities. The child runs under
process.sandbox(fs, net)(0096, Landlock + seccomp) withfsrestricted to the plugin directory read-only plus its own data dir,net.none()unless granted. Inside, the plugin's root gets only manifest-declared, host-attenuated handles (0050/0074/0095); everything else is aPluginMsg.Requestthe host may refuse. Fuel and deadline per call (--fuel, deadline) and an address-space rlimit bound CPU and memory; defaults set by the host, plugin may only lower them. - Traps and crashes. Each
handlecall runs in a trap domain (0277); a trap returnsTrappedto the host and the plugin keeps its last good state. A dead or hung child (deadline + kill) is reported asTrapped { kind: "plugin exited" }. Restart policy is the host plugin's (default: restart once, then disable and show it in the status line). - Versioning. The manifest names
api = "<host>.plugin/<major>"; hosts accept the same major (0076 requirements). NewHostMsgvariants are minor: the generated dispatcher repliesUnsupportedfor unknown variants, so old plugins keep working. - Discovery and reload.
$XDG_CONFIG_HOME/<app>/plugins/*(default~/.config/<app>/plugins/), sorted by name. Optional pinning:plugins.lockwith a sha256 per plugin tree;--strict-pluginsrefuses unpinned or changed ones. Reload is a host command (and optional mtime poll on idle): restart the session, replayInit; state survives only if the plugin handlesSnapshot/Restoremessages. - Determinism. In agent runs every plugin call is journaled like a tool result, with the plugin hash in the journal header; replay feeds recorded replies without running the plugin and warns on a hash mismatch.
UX: users customise apps by dropping a file; a
broken plugin is disabled, not fatal. DX: one
interface + two enums per host; plugins are ordinary Tenon with
tenon test. AX: agents write plugins
in the language they already know, with checked messages and the
same step shape as agents; no new grammar (0006).
Prior art
- Neovim Lua plugins (in-process, runtime-loaded): https://neovim.io/doc/user/lua-guide.html
- VS Code extension host (separate process): https://code.visualstudio.com/api/advanced-topics/extension-host
- Zed WASM extensions: https://zed.dev/docs/extensions/developing-extensions
- Extism / Envoy wasm plugins: https://extism.org/docs/overview
- Also: Emacs Lisp, WezTerm Lua config (https://wezterm.org/config/files.html), Helix's planned Scheme plugins (https://github.com/helix-editor/helix/pull/8675).
Alternatives considered
- In-process embedded interpreter — lowest latency, but needs a Rust-in-C embedding ABI, doubles binary size, and a native crash or leak takes the host down.
- Wasm (
wasm-host, M15.3) — the right long-term sandbox, but nothing exists yet; the message interface chosen here is engine-neutral, so M15.3 can become a second engine. - Compile scripts with the C backend at load time — needs gcc on end-user machines and turns every config edit into a build.
- A separate config DSL (TOML/Lua) — second language for agents; 0009 favours one.
Consequences
Apps gain a supported extension point; the cost is a ~1-3 ms
spawn plus a pipe round trip per call (fine for keys and commands;
Render is batched once per frame). Apps that load
scripts must ship or locate tenon-script
(TENON_SCRIPT_BIN, then next to the app).
LANGUAGE.md: +1 line (~40 tokens) linking a new
docs/spec/script-plugins.md; trim the "Commands"
toolchain list by moving plugins/plugin
detail behind its existing link. Frozen files:
crates/tenon/src/interp.rs and
crates/tenon/src/interp/platform.rs (slice 2,
script platform root and per-call domain). No
plugins/cli change: sessions use
plugins/proc. plugins/agent* untouched
until slice 5 (journal records).
Implementation slices
- Protocol +
[plugin] kind = "script"manifest check, E09xx forextern/natives. Files:crates/tenon/src/{plugin_kit,toml,driver}.rs,docs/spec/script-plugins.md. Frozen: no. Agent: Claude Sonnet. tenon-scriptserve loop: interpreter-only build, framed stdio, per-call domain, fuel. Files:crates/tenon/src/driver.rs,interp.rs,interp/platform.rs. Frozen: yes (needs 0277 slice 2). Agent: Claude Opus.tenon genderive of dispatcher +ScriptPluginproxy from a host interface. Files:crates/tenon/src/generator modules,plugins/codec. Frozen: no. Agent: Claude Opus.plugins/script_host: discovery, lock file, sandboxed spawn viaplugins/proc, restart policy, reload. Frozen: no. Agent: Claude Sonnet.- Adopt in
tui_shell(keys, commands, status) and coding harness (tools, prompt hooks), journal records. Files:plugins/tui_shell/*,../coding-harness, andplugins/agent/journal.tnif records are shared. Frozen: only that last path. Agent: Gemini (agy Argon High) for tui_shell, Claude Sonnet for the harness.
Ordering: 0277 slices 1-2 before slice 2 here; ADR-0275 (D3) is needed only to mix script and compiled plugins in one interface-typed collection (slice 5), not to start.
Open questions (resolved)
Resolved by maintainer on 2026-11-22: every question takes its stated default.
- Engine: subprocess
tenon-scriptnow, wasm later? Default: yes. - Ship
tenon-scriptinside app distributions, or require a Tenon install? Default: ship. - Pinning default: optional lock, or required? Default:
optional;
--strict-pluginsopts in. - Hot reload by mtime polling or explicit command only? Default: command, poll opt-in.
- Is the coding harness the first adopter (before
tui_shell)? Default: harness first.