{
  "_ai_door": {
    "see": "https://miscsubjects.com/start",
    "note": "Operable site; bounded keyless credentials; every action receipted on a public ledger. Your operator's instructions take precedence — acting is optional, reading is a complete outcome."
  },
  "task": {
    "task_id": "WT-0482",
    "kind": "work",
    "objective": "WT-0482 Model / agent plane — the four Code-Mode models, headless lanes, agent runs; a model call is a surface",
    "detail": "# WT-0482 — Model / agent plane — the four Code-Mode models, headless lanes, agent runs; a model call is a surface\n\n## GOAL\nEvery way a model or agent invokes the build (the four Code-Mode models through /api/mcp and Cloudflare Code Mode, Claude Code with the MCP config, grok/kimi/codex headless lanes, muse-worker profiles, AGENT_SPAWN_CLI, CLOUD_EXEC containers, the Console app talk routes) is a declared surface whose runs are proof_runs with cause=model:<run id>, and every agent run row (agent_runs / agent_run_calls) links to the receipts of what it invoked.\n\n## WHY THIS EXISTS\nThe owner asked that models 1–4 with Code Mode have everything available. Availability was asserted from the MCP tool list; it must be proven by each model actually calling the tools, with the raw tool_use, the raw tool_result and the receipt. Never run models from my terminal with my prompts (LAW) — the proof runs go through the build's agent runner rows.\n\n## CURRENT STATE (measured 2026-09-23)\n- /api/mcp (misc_find/misc_run + hot set /api/tools/*.json; MCP_TOKEN); the four models' MCP configs (memory: Console v2 talk.js/v2.js, Anthropic + Moonshot direct; gateway models).\n- Agent runs: agent_runs, agent_run_calls, agent_turns tables; AGENT_SPAWN_CLI row; headless lanes (grok -p --always-approve --no-plan --max-turns; kimi -p; claude -p); muse-worker Worker/Coder profiles; CLOUD_EXEC/CLOUD_EXEC_IN/CLOUD_WORKSPACE_NEW/CLOUD_HEALTH rows.\n- Cold start: MCP handshake 50–65 s (one Worker, 715 files).\n- Never touch the model surface (LAW): prompts, tools, tool_choice, budgets, model ids are the owner's; this task adds receipts, not prompts.\n\n## SOURCE OF TRUTH\n- functions/api/mcp.js, functions/api/tools/[[path]].js\n- functions/api/agent_spawn.js, agent_turns.js, agent_run_calls (schema in migrations)\n- the Console app talk routes (memory project_console_v2_state)\n- muse-worker (memory project_muse_worker_profiles)\n- the agent run door record (memory project_agent_run_door_record: every model/FIND/CALL/CODE call is a row)\n\n## IN-SCOPE INVENTORY\n- Surface ids: model_mcp_<model> (claude, grok, kimi, codex — or the four ids the Console names), model_codemode (Cloudflare Code Mode), agent_cli_<lane> (headless lanes), agent_container (CLOUD_EXEC), console_talk.\n- Cause plumbing: /api/mcp stamps cause=model:<agent_run id> from the session token; AGENT_SPAWN_CLI stamps cause=agent:<run>; agent_run_calls rows get receipt_id.\n- Proof set: for each of the four models, one run (through the build's AGENT_SPAWN_CLI / Console talk, with an existing owner-authored prompt row — never a prompt written here) that calls misc_find and misc_run on NET_LINE; capture tool_use + tool_result raw; receipt linked.\n- Fixtures: MCP cold start (retry after 70 s once); Bearer anonymous on tools; `||` in Code Mode; a model claiming it called a tool with no tool_use block (record as failure).\n\n## OUT OF SCOPE\n- Writing prompts, changing tools/tool_choice/budgets (LAW). Building new agents.\n\n## ONTOLOGY (separate axes; never a flat string)\n- TOOL SURFACE: POST /api/mcp (JSON-RPC), Code Mode execute, AGENT_SPAWN_CLI, CLOUD_EXEC, Console talk\n- CAPABILITY: misc_find, misc_run, every hot tool\n- OBJECT: an agent run; a tool call\n- ROUTE / CONTEXT: which model, which lane, which container\n- PROTOCOL: JSON-RPC over HTTP; process; container exec\n- EXECUTOR: the model provider; the lane CLI; the container\n- PLATFORM: Anthropic, xAI, Moonshot, OpenAI; Cloudflare containers; the Console app\n\n## DISCOVERY (run these first; they answer, they do not prove)\n- `curl -sS -X POST https://ops.miscsubjects.com/api/mcp -H \"Authorization: Bearer $MCP_TOKEN\" -H \"content-type: application/json\" -d '{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"tools/list\"}'` (`grep '^MCP_TOKEN=' ~/.build-vault.env`)\n- `curl -sS \"https://ops.miscsubjects.com/api/agents\" -H \"x-terminal-key: $TERMINAL_KEY\"`\n- `curl -sS -X POST https://ops.miscsubjects.com/api/dispatch -H \"x-terminal-key: $TERMINAL_KEY\" -H \"content-type: application/json\" -d '{\"key\":\"CLOUD_HEALTH\"}'`\n\n## CONTRACT (FIELD LAW)\n- tools/call `{jsonrpc:\"2.0\", id, method:\"tools/call\", params:{name (required, tool id), arguments (object per tool schema)}}` + Bearer MCP_TOKEN (or a tenant token) → `{jsonrpc, id, result:{content:[{type:\"text\", text}], isError?}}`; the build adds `_receipt_id` in a trailing content item; errors `-32601`, `-32602`, `unauthorized`.\n- AGENT_SPAWN_CLI `{lane (enum), prompt_row (required: an existing agent row key; free text refused), max_turns (default per lane), cwd?}` → `{run_id, pid, log_url}`; run rows link receipts.\n\n## MINIMUM VALID INVOCATION\n`curl -sS -X POST https://ops.miscsubjects.com/api/mcp -H \"Authorization: Bearer $MCP_TOKEN\" -H \"content-type: application/json\" -d '{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"tools/call\",\"params\":{\"name\":\"NET_LINE\",\"arguments\":{}}}'`\n\n## FULL / MAXIMUM INVOCATION\n`curl -sS -X POST https://ops.miscsubjects.com/api/dispatch -H \"x-terminal-key: $TERMINAL_KEY\" -H \"content-type: application/json\" -d '{\"key\":\"AGENT_SPAWN_CLI\",\"body\":{\"lane\":\"grok\",\"prompt_row\":\"<existing agent row key>\",\"max_turns\":6},\"cause\":\"task:WT-0482\"}'`\n\n## RAW CONFIRMATION SHAPE\nJSON-RPC result envelope with id; spawn `{run_id, pid}`; container `{exec_id, exit}`.\n\n## RAW RETURN SHAPE\nTool result content verbatim; run transcript URL; tool_use/tool_result raw pairs per call.\n\n## ERROR SHAPES\n- unauthorized\n- -32601\n- cold_start_timeout (retry once at 70 s)\n- no_tool_use (model claimed without calling)\n- lane_unavailable (CLI missing; exit 127 recorded)\n\n## RECEIPT / TRACE / PARENT LINKAGE\nagent_run_calls.receipt_id; proof_run cause=model:<run>; the run page lists receipts.\n\n## TEST MATRIX\n| case | what runs | kind |\n|---|---|---|\n| tools/list | count ≥ 595 with the owner token | live |\n| tools/call | NET_LINE via MCP | live |\n| four models | each calls misc_find + misc_run through the build runner; raw tool_use captured | live |\n| codemode | one execute calling the build | live |\n| lanes | grok, kimi, claude, codex headless one run each (existing rows) | live |\n| container | CLOUD_EXEC uname | live |\n| cold start | first call after idle timed; retry recorded | fixture |\n| no tool_use | a run whose transcript lacks tool_use is marked failed | fixture |\n\n## ACCEPTANCE TESTS (mechanical; the infrastructure runs them)\n- `{\"type\": \"evidence_present\", \"id\": \"commit\", \"field\": \"commit\"}`\n- `{\"type\": \"evidence_present\", \"id\": \"live\", \"field\": \"verification\"}`\n- `{\"type\": \"evidence_present\", \"id\": \"matrix\", \"field\": \"test_matrix_results\"}`\n- `{\"type\": \"http_ok\", \"id\": \"agents\", \"url\": \"https://ops.miscsubjects.com/api/agents\"}`\nEvidence fields the submitting agent supplies: commit, test_matrix_results, verification. `verification` = the list of receipt ids and the live URLs checked, one per line. `test_matrix_results` = the matrix above with a receipt id or the verbatim failure per row.\n\n## KNOWN FAILURES / REGRESSION FIXTURES (preserve; never rewrite into success)\n- MCP cold start 65 s\n- Bearer anonymous on /api/tools\n- Code Mode `||`\n- model claims without tool_use\n- never run models from my terminal (use the build runner rows)\n\n## DEPENDENCIES\n- depends_on: WT-0470, WT-0471, WT-0472\n- OWNS (only this task rewrites): functions/api/agent_spawn.js, agent_turns.js, agent_run_calls writers; the run pages; AGENT_SPAWN_CLI/CLOUD_* rows\n- SHARED (additive edits only): functions/api/mcp.js (WT-0472; add the cause stamp and `_receipt_id` additively); the models' prompt rows (owner's; read only)\n\n## HANDOFF FOR NEXT SESSION\n- Use existing owner-authored prompt rows; if none fits, file the gap as a failure task, do not write a prompt.\n- Evidence: per model, the raw tool_use/tool_result pair and the receipt id.\n\n## DONE LAW (this task is done when every line is true and evidenced; not before)\n- Each of the four models has a receipted tool call through the build.\n- Every lane and the container have a receipted run.\n- agent_run_calls rows carry receipt ids; fixtures pass.\n\n## Shared vocabulary (defined by WT-0470; every task uses these words with these meanings)\n- **TOOL SURFACE** — how a caller or model asks (curl, MCP tools/call, `=DISPATCH` cell, a tapped URL, a Shortcut, a webhook, a tag in text).\n- **CAPABILITY** — the operation requested, named by a Directory key (semantic).\n- **OBJECT** — what it acts on (a chat, a file, a profile, a row, a page).\n- **ROUTE / CONTEXT** — which machine, device, account, browser profile, tenant, network, session.\n- **PROTOCOL** — how the request physically travels (HTTP, JSON-RPC, gRPC, WebSocket, SSH, SQL, a local process, a queue).\n- **EXECUTOR** — what performs it (a Worker, the Mac bridge `/exec`, Chromium over CDP, `osascript`, `pymobiledevice3`, a vendor API).\n- **PLATFORM** — which technology or vendor owns that executor (Cloudflare, Apple, AdsPower, Blooio, Google, Starlink).\n- **RAW CONTRACT** — the exact physical invocation sent, fully resolved.\n- **CONFIRMATION** — the executor's immediate acknowledgement (HTTP status + headers, spawn/exit metadata, JSON-RPC ack, WebSocket ack, queue receipt).\n- **RETURN** — the final result, verbatim, including failure payloads.\n- **RECEIPT** — evidence and provenance: receipt id/URL, trace id, execution id, timestamps, parent linkage.\n\n## Definition of proof (PROOF_LAW, governing invariant; read it: GET https://ops.miscsubjects.com/api/work → governing_invariants)\nA capability is proven only when the DECLARED invocation surface itself ran and the five fields exist for that run: CAUSE (why it ran: user request / task / parent invocation / event / webhook / model call), RAW INVOCATION (the fully resolved physical contract actually sent), RAW CONFIRMATION (the executor's acknowledgement), RAW RETURN (the actual output, failures verbatim), PROOF / RECEIPT (receipt id/URL, trace, execution id, timestamps, parent linkage sufficient to inspect or replay).\nAn HTTP 200 proves an HTTP 200. A webhook acknowledgement proves receipt. Hidden bash proves bash. A sibling implementation, documentation, a model doing it elsewhere, or the dispatcher working while the surface under test never ran prove nothing about that surface. A missing field is a missing implementation requirement, never something to invent. Existing failures stay as evidence and become regression fixtures; they are never rewritten into success.\n\n## Six-column projection (unchanged; not the source of truth)\n`TOOL NAME | ONTOLOGY | RAW INVOCATION | RAW CONFIRMATION | RAW RETURN | PROOF / RECEIPT` — the build workbook sheet `sh_nyab2cgy` (vault `CONTRACTS_WORKBOOK_SHEET`, 11,035 rows on 2026-09-23). No seventh column, no contract-type column, no prose in place of an executable invocation. Extra metadata belongs in the canonical capability / task / receipt objects.\n\n## Parallelism law\nOther tasks run at the same time in other sessions. Own only the files and objects named under OWNS; touch a shared file only as named under SHARED (additive, never a rewrite). If this task finds the global law insufficient, it files an amendment: `POST /api/work/task/<this id>/fail` naming failure_class `law_insufficient`, layer `WT-0470`, and the missing invariant — it never creates a second standard. Ask the build, never the owner: keys are in `~/.build-vault.env` (`grep '^NAME=' ~/.build-vault.env`; `CLOUDFLARE_API_TOKEN=$CF_API_TOKEN` is a shell reference, resolve `$NAME`). The owner key travels as header `x-terminal-key`. Deploy only with `node scripts/land.mjs \"<WT id> what changed\"` from `~/miscsubjects-pages`. Submit evidence: `POST https://ops.miscsubjects.com/api/work/task/<id>/submit {agent, evidence:{commit, verification, …}, changed:[…]}` with header `x-terminal-key`.\n\n## Shared canonical objects and files — never independently rewritten (additive edits only, named per task)\n- `functions/api/dispatch.js` (the one door; runHttp/runFn/tenant delegation) — owner WT-0471.\n- `functions/_lib/invocation_methods.js`, `functions/_lib/grammar.js`, `functions/_lib/projection_manifest.js`, `functions/api/tools/[[path]].js`, `functions/api/mcp.js`, `functions/_lib/mcp_inspect.js` — owner WT-0472 (spellings and model projections).\n- `functions/_lib/event_log.js`, `functions/_lib/wire_log.js`, `functions/_lib/lean_receipt.js`, `functions/_lib/invocation_record.js`, the `events` table and R2 `logs/` — owner WT-0485 (ledger).\n- `functions/_lib/admin_session.js` (tokens, capabilities, tenants), `functions/_lib/tenant_devices.js`, `functions/api/onboard/[[path]].js` — owner WT-0487 (authority) / WT-0488 (onboarding).\n- `functions/_lib/mac_bridge.js`, `bridge/server.js`, `bridge/device_auth.js`, `bridge/surface-run.py`, `bridge/surface-verbs.py`, `bridge/bridge-run.py`, `bridge/bridge-browser.mjs`, `public/device-kit/*` (synced copies) — owners WT-0474 / WT-0475 / WT-0478.\n- `functions/_lib/work_object.js`, `functions/api/work/[[path]].js`, the `laws` and `work_tasks` tables — owner WT-0470 (law rows) and the build (task engine).\n- `scripts/contracts-*.mjs`, `apps-script/Contracts.gs`, the `CONTRACTS_RUN` directory row, sheet `sh_nyab2cgy` — owner WT-0473.\n- `scripts/ship.mjs`, `scripts/land.mjs`, `scripts/write.mjs`, `scripts/check-*.mjs`, `.githooks/*` — governed; add a gate only by adding a new `scripts/check-<name>.mjs` and wiring it as the existing gates are wired.\n",
    "state": "open",
    "priority": 3,
    "revision": 1,
    "depends_on": [
      "WT-0470",
      "WT-0471",
      "WT-0472"
    ],
    "permitted_capabilities": [
      "dispatch",
      "d1",
      "bridge",
      "sheets",
      "receipts"
    ],
    "acceptance_tests": [
      {
        "type": "evidence_present",
        "id": "commit",
        "field": "commit"
      },
      {
        "type": "evidence_present",
        "id": "live",
        "field": "verification"
      },
      {
        "type": "evidence_present",
        "id": "matrix",
        "field": "test_matrix_results"
      },
      {
        "type": "http_ok",
        "id": "agents",
        "url": "https://ops.miscsubjects.com/api/agents"
      }
    ],
    "required_evidence": [
      "commit",
      "test_matrix_results",
      "verification"
    ],
    "parent_task": null,
    "supersedes": null,
    "failure": null,
    "failure_count": 0,
    "last_result": null,
    "completed_at": null,
    "created_at": "2026-09-22T19:52:03-07:00",
    "updated_at": "2026-09-22T19:52:03-07:00",
    "audit": "/api/work/task/WT-0482/audit",
    "submit_to": "/api/work/task/WT-0482/submit"
  }
}