On this page

0292. Application Actions API (app.actions/v1) and State Deltas

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:

  1. D1 — Projection, not raw state: Applications implement project_state(self) -> json.lib.Value to 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.
  2. D2 — Optimistic concurrency via state_rev: ActionSession maintains a monotonic 1-based rev: i64. Action invocations may supply expected_rev; mismatches fail closed with ActionErrorKind.StaleRev accompanied by a catch-up delta (or fresh snapshot if evicted) so concurrent human or background mutations cannot be silently overwritten.
  3. D3 — Automatic delta vs. snapshot fallback: state_delta computes deterministic RFC-6901 patches (Set, Remove, ReplaceWindow) and compares serialized delta bytes against full-snapshot bytes. It emits WireUpdate.Delta only when delta_bytes <= max_delta_bytes and delta_bytes * 100 <= snapshot_bytes * max_ratio_pct (default 8192 bytes and 75%); otherwise it automatically emits WireUpdate.FullSnapshot.
  4. D4 — State-aware action discovery + risk tags: actions(self) -> vec<ActionSpec> evaluates against live application state and reports enabled: bool, disabled_reason: option<str>, risk: Read | Write | Destructive, requires_approval: bool, and a fail-closed mcp.wire JSON Schema for arguments. ActionSession enforces harness_policy (Deny > Allow > Ask) and ADR-0225 presented-approval invariants before calling app.apply.
  5. D5 — Flat-token 3-tool MCP surface: app_actions_mcp projects any ActionApp onto exactly three MCP tools — app_state, app_actions, and app_act (<= 900 combined schema tokens) — over existing mcp_server.stream (stdio) and mcp_server.sse (loopback HTTP/SSE) transports, keeping agent tool-schema context flat regardless of domain action count.
  6. D6 — Pure plugins, zero kernel changes: All five plugins (state_delta, app_actions_trace, app_actions, app_actions_mcp, app_actions_tui) declare capabilities = [], ship in edition = "2026" per ADR-0290, add zero new Rust CLI subcommands per ADR-0291, and run identically on C and tenon interp backends.
  7. D7 — Pre-release schema discipline: While app.actions/v1 is 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)

Alternatives Considered

Consequences