ADR-0305:
Declarative app_host runner (Ideas #06 + #28)
- Status: Accepted
- Date: 2026-11-28
- Related: ADR-0291 (Freeze Rust, Grow in Tenon), ADR-0225
(
Event.Presentedapproval gating), ADR-0227 (Caps.cluster), ADR-0277 (trap domains), ADR-0292/0300 (app.actions), Wave 1test_capsandscript_host
Context
Every Tenon app hand-wires the same host code: TTY probing,
raw-mode entry and restoration, argv routing, a CLI/Actions
surface, an MCP stdio loop, optional loopback HTTP, trace and
recording flags, state persistence, and plugin extension points.
examples/tui/todo spreads this across
main.tn, live.tn,
mcp_actions.tn and tui_driver, and each
copy re-decides exit codes and approval behaviour.
Decision
Add plugins/app_host/ (app_host.lib,
app_host.ext), pure .tn, zero Rust
changes. An app supplies one type implementing
ActionApp (app_actions),
App (tui) and Persist, and
main.tn shrinks to a run_app call
(plugins/app_host/example/main.tn, 6 lines).
- Functional core, thin shells.
run_headless(env, spec, app, fs, stdin_text) -> HostResultis pure over aHostFsinterface and handles CLI, piped script and MCP stdio. Onlyrun_app,run_interactiveandrun_httptouchCli,TtyandNet. Tests run the core withtest_capsVirtualCliandVirtualFs, so C andinterpbehave identically. - Probe and degrade.
HostEnvcarriestty.is_terminalresults,TERMandNO_COLOR;tui_headless.choose_outputdecides. TUI needs a terminal on stdout and stdin andTERM != dumb. Anything else is headless and strips color. - Exit codes.
0success or--help;2unknown flag, command, action or bad args;1other failure;3an action needing approval is unresolved. Headless never presents, confirms or auto-approves (ADR-0225). A piped script stops at the first such action. - Routing.
state | actions | act NAME [JSON],--mcp,--http [loopback addr],--trace-out,--record x.tui|x.cast,--store. Non-loopback--http, conflicting modes and bad record extensions exit 2. - Store without a rename primitive.
Fsoffers no rename, so saves write a hash-framed copy to<path>.nextand then to<path>. Loading verifies the SHA-256 and falls back to.next; a torn write never loses the last good state. - Interactive driver. Same loop as
tui_driver:wait_ms == -1sleeps idle,Event.Presentedflows from the runtime, caps negotiation honorsCaps.cluster. Added:PollHookscheduling (due hooks arrive asEvent.Feedofpoll:<name>lines and shorten the wait only when due),.tuirecording throughtui.scenario,.castthrough a local asciicast v2 encoder.tui_replayis not used because it does not compile against the currentCapsonmain. - Extension slots (
script_host).ExtRegistrymounts plugins whose api passesscript_host.api.accepts, exposesext.<plugin>.<action>specs, and routes calls as anext.callActionEffectfor the shell to send to ascript_hostsession. Traps and crashes feedscript_host.policy.Health; a disabled plugin loses its actions and its panel renders[ext <p> disabled]while the host and other plugins continue.ext_on_reloadre-enables it. - Loopback HTTP.
http_handlewrapsapp_actions_mcp.handle_sse_postas a pure request-to-response function;run_httpadds a bounded accept loop (max_requests).
Deviations and limits
ttyis not a manifest capability. The package declaresstdin stdout stderr env fs ffi net process traps.- Trap-safe restoration relies on
tty.open(native signal andatexithandlers) plusrun_interactivealways callingcloseand merging errors. Genericimpl Contained for Job<A>is rejected (E0657), sotraps.containaround the generic drive loop is not possible; an app may contain its own concrete steps. - Extension panels are returned as lines
(
ext_panel_lines); wiring them intotui_shelllayout is left to the app. tui_replayandharness_policy/genare stale onmain(E0969, missingCaps.background); they are outside this change.
Consequences
Apps get consistent exit codes, approval safety and surfaces
from one declarative call. New surfaces are added in one place.
Cost: one more plugin and a Persist interface for
apps that want persistence.