On this page

ADR-0299: derive StateView (@redact, @window, @summary, State Schema & Diffs)

Context

Agentic and TUI applications exposing live state through app_state / state_delta previously hand-wrote three repetitive, error-prone projections for every state struct:

  1. Manual json.lib.Value object construction (project_state), risking accidentally serializing large binary buffers or leaking secrets in strings/logs/env maps.
  2. Manual collection slicing + pagination metadata (total_*, *_truncated) so large vectors do not overflow LLM context windows.
  3. Manual 1-line status summaries and JSON Schemas matching the projected state shape.

Per ADR-0291 ("Freeze Rust, Grow in Tenon"), this capability belongs in a pure .tn GEN_ABI 2 generator plugin (capabilities = []) with zero Rust compiler changes, leveraging Wave 1's unified json.lib.Value + JsonEntry builders (ADR-0294) and zero-step implicit cached derive materialization (ADR-0295).

Decision

1. New Pure Generator Plugin: plugins/state_view_gen/

We introduce state_view_gen (kind = "generator", capabilities = [], GEN_ABI 2) exporting pub fn StateView(t: std.reflect.Type) -> result<str, str>.

For any annotated struct Foo (with import json.lib { Value, JsonEntry } and import state_view_gen.lib { StateView } in the host module), derive StateView for Foo emits four companion functions:

2. Field Annotations

Using Tenon's existing @key / @key(literal) field attribute grammar (no Rust parser changes):

3. Supported Types & Fail-Closed Guarantees

Supported projected types: str, i64, i32, u8, u32, u64, f64, bool, unit enum (snake_case strings), nested struct (recursive up to depth 14 with cycle detection, honoring nested @omit/@redact/@window), option<T>, vec<T>, and map<str, str|i64|bool> (sorted keys for deterministic diffs).

StateView fails closed (E0966) on non-struct targets, conflicting annotations (e.g. @omit with @redact/@window/@summary), @redact on non-string types, @window on non-vec types or max <= 0, duplicate projected keys (including total_key/*_truncated collisions), struct cycles, unsupported non-omitted types (bytes, non-unit enums, option<option<T>>), or any schema rejected by mcp.wire.schema_supported.

4. Secret Assignment Scrubbing in plugins/state_delta/redact.tn

We extend state_delta.redact with pure helpers used by state_view_gen.rt and redact_value:

Consequences