On this page

0280. Runtime plugins in Tenon script

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

  1. Scope. A script plugin is a Tenon package (one .tn or a directory with tenon.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 declare extern (FFI), natives, generators or new platforms; those stay in compiled and process plugins. The checker rejects them: E09xx (allocate at implementation).
  2. Engine: subprocess interpreter. The host spawns tenon-script <plugin-dir> via plugins/proc and keeps one session per plugin. tenon-script is the tenon binary built interpreter-only (no C toolchain step); it checks the plugin, then serves framed codec binary messages on stdio, like the ffi-host child (interp_ffi.rs FramedChild). 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.
  3. API: one interface, typed messages. The host package declares, e.g. interface HarnessPlugin { fn handle(self, msg: HostMsg) -> Reply<Self> } with struct Reply<S> { state: S, out: vec<PluginMsg> }, mirroring Agent.step -> Transition<Self> so agents learn one shape. HostMsg (Init, Key, Command, Prompt, Render, ToolCall, ...) and PluginMsg (Bind, AddCommand, Theme, Status, PromptEdit, ToolResult, Request) are closed enums with derived codecs. tenon gen derives the plugin-side dispatcher main and the host-side ScriptPlugin proxy from the interface. With ADR-0275 interface values the proxy can sit in the same vec<HarnessPlugin> as compiled plugins; before it, hosts hold vec<ScriptPlugin>.
  4. Capabilities. The child runs under process.sandbox(fs, net) (0096, Landlock + seccomp) with fs restricted 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 a PluginMsg.Request the 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.
  5. Traps and crashes. Each handle call runs in a trap domain (0277); a trap returns Trapped to the host and the plugin keeps its last good state. A dead or hung child (deadline + kill) is reported as Trapped { kind: "plugin exited" }. Restart policy is the host plugin's (default: restart once, then disable and show it in the status line).
  6. Versioning. The manifest names api = "<host>.plugin/<major>"; hosts accept the same major (0076 requirements). New HostMsg variants are minor: the generated dispatcher replies Unsupported for unknown variants, so old plugins keep working.
  7. Discovery and reload. $XDG_CONFIG_HOME/<app>/plugins/* (default ~/.config/<app>/plugins/), sorted by name. Optional pinning: plugins.lock with a sha256 per plugin tree; --strict-plugins refuses unpinned or changed ones. Reload is a host command (and optional mtime poll on idle): restart the session, replay Init; state survives only if the plugin handles Snapshot/Restore messages.
  8. 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

Alternatives considered

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

  1. Protocol + [plugin] kind = "script" manifest check, E09xx for extern/natives. Files: crates/tenon/src/{plugin_kit,toml,driver}.rs, docs/spec/script-plugins.md. Frozen: no. Agent: Claude Sonnet.
  2. tenon-script serve 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.
  3. tenon gen derive of dispatcher + ScriptPlugin proxy from a host interface. Files: crates/tenon/src/ generator modules, plugins/codec. Frozen: no. Agent: Claude Opus.
  4. plugins/script_host: discovery, lock file, sandboxed spawn via plugins/proc, restart policy, reload. Frozen: no. Agent: Claude Sonnet.
  5. Adopt in tui_shell (keys, commands, status) and coding harness (tools, prompt hooks), journal records. Files: plugins/tui_shell/*, ../coding-harness, and plugins/agent/journal.tn if 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.

  1. Engine: subprocess tenon-script now, wasm later? Default: yes.
  2. Ship tenon-script inside app distributions, or require a Tenon install? Default: ship.
  3. Pinning default: optional lock, or required? Default: optional; --strict-plugins opts in.
  4. Hot reload by mtime polling or explicit command only? Default: command, poll opt-in.
  5. Is the coding harness the first adopter (before tui_shell)? Default: harness first.