FrankenTerm

Robot Mode (JSON API)

701 words3 min read14 subsectionsFrom the README at ft 0.15.21

On this page14
Output formatsEnvironment variablesImplementation statusState & discoveryReading pane contentSending inputPattern waitingDeferred proof queueSearchEventsAgent Mail outage outboxProfile management (ft-hac7w)Error handlingMCP (Model Context Protocol)

The ft robot subcommand provides machine-optimized output for AI agents. Always use --format toon for token-efficient output when piping results to another AI.

Output formats

Flag Format Use case
--format json JSON Default, easy parsing
--format toon TOON Lower-token AI-to-AI envelopes
--stats Stats on stderr Token-savings visibility

Environment variables

Variable Purpose
FT_OUTPUT_FORMAT Default format (json or toon)
TOON_DEFAULT_FORMAT Fallback default format
FT_WORKSPACE Workspace root directory
FT_ROBOT_FAIL_ON_ERROR 1 makes ft robot exit with status 1 when it printed an ok: false envelope (default: exit 0, the envelope is the result), so ft robot wait-for 0 Done && next stops on a timeout or refusal

Precedence: CLI flag > FT_OUTPUT_FORMAT > TOON_DEFAULT_FORMAT > json

Implementation status

Family Actions Status
ft robot state current pane state shipped
ft robot get-text single / batch / all pane output shipped
ft robot send send text (with policy gate) shipped
ft robot wait-for pattern trigger shipped
ft robot search lexical / semantic / hybrid shipped
ft robot events recent detection events shipped
ft robot approve approve gated action shipped
ft robot agent-mail-outbox retained fallback outbox entries + replay state shipped (read-only fixture/queued-entry surface; not live delivery proof)
ft robot checkpoint save / list / show / delete / rollback shipped for save/list/show/delete; rollback is metadata-only with --dry-run, while non-dry rollback fails closed until an authenticated, incarnation-pinned mux execution contract exists
ft robot context status / rotate / history shipped (native SQLite registry; rotation receipts are durable; raw context content is not stored)
ft robot work claim / release / complete / list / ready / assign shipped (native SQLite work_claims queue)
ft robot fleet status / scale / rebalance / agents shipped (live scale/rebalance plans, dry-run receipts, durable non-dry-run receipt replay, typed mutation/error receipts)
ft robot profile list / show / validate / apply shipped (read paths + dry-run apply + mux-backed non-dry-run apply with durable receipts)

State & discovery

bash
ft robot state                              # JSON
ft robot --format toon state                # compact TOON
ft robot --format toon --stats state        # with token stats on stderr
ft robot state --include-text --tail 20     # pane metadata + per-pane tail output

Response envelope:

json
{
  "ok": true,
  "data": [
    {"pane_id": 0, "title": "claude-code", "domain": "local", "cwd": "/project"}
  ]
}

ft robot state serializes data as a bare PaneState array. The --include-text variant wraps the array in an object:

json
{
  "ok": true,
  "data": {
    "panes": [{"pane_id": 0, "title": "claude-code", "domain": "local"}],
    "tail_lines": 200,
    "escapes_included": false,
    "pane_text": { "0": "…tail…" }
  }
}

Reading pane content

bash
ft robot get-text 0                       # recent output
ft robot get-text 0 --tail 50             # last N lines
ft robot get-text 0 --escapes             # include escape sequences
ft robot get-text --panes 0,1,2 --tail 20 # batch
ft robot get-text --all --tail 10         # all active panes

Sending input

bash
ft robot send 1 "/compact"                          # paste, then a typed Enter submits it
ft robot send 2 "make test" --no-paste              # type the characters instead of pasting
ft robot send 1 "dangerous command" --dry-run       # preview without executing
ft robot send 1 "y" --wait-for "confirmed"          # send and wait for confirmation
ft robot send 1 "/compact" --verify-submit          # return submitted-level SubmitReceipt
ft robot send 1 "/compact" --submit-level working   # require working/output evidence

Pattern waiting

bash
ft robot wait-for 0 "Usage limit" --timeout-secs 3600
ft robot wait-for 0 "Done" --timeout-secs 60

Deferred proof queue

bash
ft proof queue --bead ft-w8 --kind test --package frankenterm-core -- RCH_REQUIRE_REMOTE=1 RCH_NO_SELF_HEALING=1 rch --no-self-healing exec -- env CARGO_TARGET_DIR=/tmp/ft-w8-target cargo test -p frankenterm-core --lib proof_intent
ft proof status --format json
ft proof replay --admission-state admitted --dry-run
ft robot proof status

The queue is a fail-closed proof-debt surface. Status and dry-run replay explain what would run; live replay refuses stale source hashes and never replaces a remote-required RCH proof with local Cargo.

Search

bash
ft robot search "error: compilation failed"
ft robot search "rate limit" --pane 0
ft robot search "warning" --limit 5
ft robot search "compilation failed" --mode hybrid

Events

bash
ft robot events --limit 10
ft robot events --pane 0
ft robot events --rule-id "codex.usage.reached"   # exact rule id match
ft robot events --unhandled

Agent Mail outage outbox

bash
ft robot agent-mail-outbox
ft robot --format toon agent-mail-outbox --entry fixtures/agent-mail-outage-spool/valid/agent-mail-unavailable.json

ft robot agent-mail-outbox reads retained fallback outbox fixtures and additional queued-entry JSON files. It is for outage review and replay planning, not live service repair: queued entries, dry-run-ok rows, and fixture replay logs are not Agent Mail delivery proof until a replay receipt records a delivered message id. The command is read-only and never restarts, repairs, or reconstructs the shared Agent Mail service.

Profile management (ft-hac7w)

The ft robot profile family is the ship-first proof of the robot-contract methodology (BR-RC-ROBOT-CONTRACT.1). Its contract doctrine (idempotency rules, failure semantics, side-effect surface, concurrency contract) is the canonical example for every other robot family. See docs/robot-contracts/profile.md.

bash
ft robot profile list
ft robot profile list --role agent
ft robot profile list --tag claude-code
ft robot profile show codex_ws
ft robot profile apply codex_ws --count 3
ft robot profile apply codex_ws --count 3 --dry-run
ft robot profile validate codex_ws
ft robot profile create codex_ws --role agent --command codex --cwd . \
    --tag codex --env OPENAI_LOG=warn --bootstrap "/status"   # persist a profile so apply can spawn it

Profiles live in the agent_profiles table and are created with ft robot profile create (nothing else defines them; the name must be unique).

Family contract:

Action Idempotency Failure semantics Side effects
list Idempotent MustNotPartiallyMutate read-only
show Idempotent MustNotPartiallyMutate read-only
apply Receipt-based replay for the same request Live compensation can fail; inspect rollback and per-pane effects tables: agent_profiles; mux: spawns count panes
validate Idempotent MustNotPartiallyMutate read-only
create Not idempotent: a repeated name fails with robot.profile.already_exists and changes nothing MustNotPartiallyMutate tables: agent_profiles (one row)

Concurrency: the model's intended contract is serialization per profile name. Live requests also share mux capacity and mutation state; cross-process serialization, retries, and compensation require their own proof. A saved idempotency receipt does not make arbitrary concurrent external effects atomic.

json
$ ft robot --format json profile apply codex_ws --count 3
{
  "ok": true,
  "data": {
    "profile_name": "codex_ws",
    "panes_spawned": [10, 11, 12],
    "dry_run": false,
    "requested_agents": 3,
    "spawned_agents": 3,
    "skipped_existing_agents": 0,
    "idempotency_key": "<profiles_applied_log content_hash>",
    "mutation_idempotency_key": "<fleet mutation key>",
    "rollback_status": "succeeded",
    "idempotent_replay": false,
    "mutation_receipt": { "...": "full fleet mutation receipt" }
  },
  "elapsed_ms": 37
}

Error handling

Robot mode returns structured errors using the flat envelope shape (error, error_code, and hint are sibling top-level fields, not nested):

json
{
  "ok": false,
  "error": "Pane 99 not found",
  "error_code": "robot.pane_not_found",
  "hint": "Use 'ft robot state' to list available panes",
  "elapsed_ms": 1,
  "version": "0.2.0",
  "now": 1747371700000,
  "schema_version": 1
}

Error codes include robot.pane_not_found, robot.timeout, robot.wezterm_not_running, robot.mux_version_skew (the CLI and the running FrankenTerm.app are from different releases; the hint names both codec generations), robot.policy_denied, robot.require_approval, robot.storage_error, robot.feature_not_available, robot.fleet.inventory_unavailable, robot.profile.spawn_failed, and the full robot.fleet.* typed envelope family.

MCP (Model Context Protocol)

bash
cargo build --profile release-interactive --features mcp
ft mcp serve                                # MCP server over stdio

MCP covers a subset of Robot Mode (plus MCP-only mission lifecycle and steer-plan tools); docs/robot-contracts/mcp-robot-surface-matrix.md lists which families are mirrored, partial, or robot-only. See docs/mcp-api-spec.md for the tool list and docs/json-schema/ for response schemas.