0292.
Application Actions API (app.actions/v1) and State
Deltas
- Status: Accepted (2026-11-27)
- Date: 2026-11-27
- Plan: Application Actions API & State-Delta Control Plane
(
plans/app-actions-api/README.md, Task A01; complements 0225, 0271, 0290, 0291)
Context
Tenon already ships a stateless CLI-to-MCP bridge
(args_mcp), pure Elm-style TUI runtimes
(tui, tui_shell,
tui_headless), a dual-era MCP server
(mcp_server), fail-closed policy/approval enforcement
(harness_policy, ADR-0225),
and an immutable JSON DOM (json). However, AI agents
driving live stateful Tenon applications currently have no
standard control plane: they must either scrape terminal
output/PTYs or rely on bespoke per-app wrappers that re-send full
state snapshots on every turn.
To let any agent inspect, discover, and safely mutate stateful
Tenon apps with low token overhead — and to capture deterministic
trajectories if a specialized local action model is ever justified
— we need a standard, pure-plugin Application Actions API
(app.actions/v1) backed by a deterministic JSON
state-delta engine.
Decision
Adopt the app.actions/v1 architecture governed by
seven locked choices:
- D1 — Projection, not raw state: Applications
implement
project_state(self) -> json.lib.Valueto emit a curated, redacted, bounded view model (with window metadata for large collections). Agents never inspect raw internal structs, caches, or render buffers, and never apply arbitrary patches directly into app memory. - D2 — Optimistic concurrency via
state_rev:ActionSessionmaintains a monotonic 1-basedrev: i64. Action invocations may supplyexpected_rev; mismatches fail closed withActionErrorKind.StaleRevaccompanied by a catch-up delta (or fresh snapshot if evicted) so concurrent human or background mutations cannot be silently overwritten. - D3 — Automatic delta vs. snapshot fallback:
state_deltacomputes deterministic RFC-6901 patches (Set,Remove,ReplaceWindow) and compares serialized delta bytes against full-snapshot bytes. It emitsWireUpdate.Deltaonly whendelta_bytes <= max_delta_bytesanddelta_bytes * 100 <= snapshot_bytes * max_ratio_pct(default8192bytes and75%); otherwise it automatically emitsWireUpdate.FullSnapshot. - D4 — State-aware action discovery + risk
tags:
actions(self) -> vec<ActionSpec>evaluates against live application state and reportsenabled: bool,disabled_reason: option<str>,risk: Read | Write | Destructive,requires_approval: bool, and a fail-closedmcp.wireJSON Schema for arguments.ActionSessionenforcesharness_policy(Deny > Allow > Ask) and ADR-0225 presented-approval invariants before callingapp.apply. - D5 — Flat-token 3-tool MCP surface:
app_actions_mcpprojects anyActionApponto exactly three MCP tools —app_state,app_actions, andapp_act(<= 900combined schema tokens) — over existingmcp_server.stream(stdio) andmcp_server.sse(loopback HTTP/SSE) transports, keeping agent tool-schema context flat regardless of domain action count. - D6 — Pure plugins, zero kernel changes: All
five plugins (
state_delta,app_actions_trace,app_actions,app_actions_mcp,app_actions_tui) declarecapabilities = [], ship inedition = "2026"per ADR-0290, add zero new Rust CLI subcommands per ADR-0291, and run identically on C andtenon interpbackends. - D7 — Pre-release schema discipline: While
app.actions/v1is pre-release, internal fields and helper contracts may evolve cleanly with all callers updated together, without adding legacy compatibility shims or multi-version decoders.
Explicit Deferrals (Phase-3 Go/No-Go Gate)
- No
derive Actions/derive StateDiffgenerator in v1: Perdocs/extension-points.md, prove ergonomics as pure.tnplugins across contrasting apps (examples/tui/todoandcoding-harness-2) before introducing aGEN_ABI 2generator. - No specialized "Tenon Action Model" training in
v1: Validate the wire protocol first with existing
general tool-calling models on the frozen offline
bench/app-actions/suite. Revisitderive Actionsor dedicated action-model training only after the Phase-3 gate passes (measured boilerplate justification, median delta wire payload<= 40%of full snapshot with100%apply_deltaround-trip accuracy,>= 85%general-model completion on the 12 frozen scenarios, and>= 500simulator-verified, zero-contaminationapp.actions.trace/v1trajectories if a local model is pursued).
Alternatives Considered
- Sending full JSON snapshots on every action turn: Simpler, but scales poorly with state size and wastes agent context tokens on unchanged fields.
- Exposing one MCP tool per domain action: Causes tool-schema prompt bloat as apps grow to dozens of actions and cannot cleanly express state-dependent enablement without repeated tool-list refreshes.
- Compiler-level
derive Actionsand raw struct reflection in v1: Violates the plugin-first rule, risks leaking unredacted internal state, and locks in abstractions before real multi-app usage.
Consequences
- Stateful Tenon applications gain a uniform, offline-testable, MCP-native control plane with deterministic state deltas, secret redaction, optimistic concurrency, and fail-closed policy/approval enforcement.
- Both C and
tenon interpbackends remain in strict parity with zero ambient capabilities in the control-plane stack. plugins/state_deltais reusable independently by any Tenon plugin needing deterministic JSON diffing, RFC-6901 patching, secret redaction, or byte-budgeted wire updates.