Repository navigation
feat(lazurio): agents work with T3 Code threads through the t3 CLI, and MCP tokens get a ceiling - #91
Conversation
… ceiling An MCP client that cannot open the sign-in page gets its session from `t3 auth session issue --subject mcp-client`, and such a session was always capped at approval-required: it could read a full-access thread but every change to it failed with runtime_mode_escalation_denied. The sign-in's approval page already lets the person choose a ceiling; the CLI could not. `--runtime-mode-ceiling approval-required|auto-accept-edits|auto|full-access` now issues the same ceiling for a headless client. It needs `--subject mcp-client` and the orchestration:operate scope, the only case in which /mcp reads a ceiling, so it is never issued and silently ignored. Without the flag nothing changes. The issued session's JSON and text output name the ceiling. Overlay row 20 (root decision 0210, addendum 3; plan DEV-6676). It is a focused option on an existing capability, so it can be offered upstream. Tests: cli/auth.test.ts issues both kinds through the CLI and checks the access /mcp's own authenticator grants; cliAuthFormat.test.ts the output. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…quest, queue and events
Buddy, and any agent that reaches an Environment over SSH, works with its T3
Code threads as the Environment's owner does (root decision 0210, addendum
3): reads and summarizes them, launches, messages, steers and stops them,
answers their questions, decides their permission requests and follows
them live. The whole Environment is the security boundary (decision 0172):
whoever runs `t3` as its user can already issue any session, so the
commands add no authority, only a way to use it without a token by hand.
- t3 thread list|read|search|launch|send|interrupt|wait|organize|fork
- t3 request list|read|respond|approve|deny
- t3 queue list|read|edit|cancel|reorder|promote
- t3 events [--follow]
Each command finds the running server by the T3 home's runtime state
(--base-dir), issues short sessions from its auth state, keeps the tokens
in memory and revokes them when it ends; nothing new is stored. Thread work
goes through /mcp as a full-access client, the same tools, checks and
failures as any agent. Only what no MCP tool does uses the person's client
surface with orchestration scopes: the thread list with pending requests,
a permission decision as the app's buttons send it, and the live thread
list for `t3 events`. Permission decisions stay off MCP, as upstream keeps
them. `--json` prints the tool's result or {"error":{code,message}}; exit
codes 0 done, 1 refused, 3 T3 not running, 4 wait timed out. A launch
carries no model (decision 0189) and starts in the Lazurio project when no
--project is given. `t3 lazurio capabilities` reports "agentCli": true.
Overlay row 21 (plan DEV-6676). The code lives in apps/server/src/lazurio/;
the seams are one line in binCli.ts and the export of listItemFromShell,
whose item a thread's event line reuses. agentCli.test.ts runs the real CLI
against a live server with the real /mcp transport, auth and access checks,
and T3's scope checks on the client surface; agentCliViews.test.ts covers
the shaping. User guide: docs/user/agent-cli.md.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
agentrozjedemeai
left a comment
There was a problem hiding this comment.
@immakermatty — exact-head review of b5aff06. Two CLI contract defects; no objection to the Environment-local auth design, MCP routing, ceiling refusal rules, overlay rows 20/21, or public-repo Organization boundary.
-
apps/server/src/lazurio/agentCli.ts:1265-1280 —
t3 eventsdoes not accept--json, despite the stated per-command--jsoncontract.t3 events --json --base-dir <home>exits 1 withUnrecognized flag: --jsoninstead of producing JSON lines. Accept the flag (the output can remain JSONL) and cover it in the CLI test. -
apps/server/src/lazurio/agentCli.ts:1031-1037 — the
--for-session/--alwaysconflict fails outsiderun, bypassing its JSON error formatter.t3 request approve nonexistent --for-session --always --json --base-dir <home>exits 1 with empty stdout (and no JSON error), so automation cannot obtain the promised error document. Route this validation through the JSON failure path and test the actual CLI output.
Local isolated checkout: 78 focused tests passed in serial shards (13 + 8 + 57), release contract 37/37, server typecheck and targeted lint/format passed; git diff --check clean. CI: 4 successful, 2 skipped. This review is for the stated SHA only.
…SON, t3 events too Review of #91 (Pablo, review 5586415362) found two breaks in the agent CLI's --json contract: - `t3 events` did not take --json, so `t3 events --json` failed as an unknown flag. It takes it now. Its output stays JSON lines either way; a failure that ends it prints {"error":{code,message}} with --json, and a dropped stream that --follow reconnects says why on standard error. - `t3 request approve --for-session --always` failed outside the code that prints failures, and the runtime does not log these, so it exited 1 with nothing printed at all. The command line is now checked in one place, before anything is read: `run` gains a check step whose failures print like every other, and every check that needs no server moved there (approve's choice, launch's flag combinations, the message of launch, send and queue edit, organize's --until, fork's --run or --checkpoint, respond's --answer or --answers, reorder's --before or --last). Such a command line fails as invalid_request with exit 1 whether or not T3 Code is running; before, the checks inside `run` said T3 Code was not running (exit 3) when it was not. Two exits stay as they were, and the user guide now says so: a wait that times out prints the thread's state and exits 4, and a command line `t3` cannot parse at all prints the command's help and the error as text, which the CLI framework does before any command runs. Overlay row 21 follow-up (plan DEV-6676). Tests: every such command line fails as JSON with exit 1 and leaves the T3 home untouched; Pablo's case against the live server decides nothing; t3 events prints the same lines with --json, and its failure as JSON or on standard error. Co-Authored-By: Claude Opus 5.5 <[email protected]>
agentrozjedemeai
left a comment
There was a problem hiding this comment.
Exact-head re-review of bcf3c36 (delta from b5aff06). The two prior findings are fixed: events accepts --json while preserving JSONL and reporting terminal errors as JSON; approve --for-session --always now goes through runChecked and prints invalid_request with exit 1 before connecting. I checked the other moved validations and the documented parser/wait exceptions; no new defect found. git diff --check is clean. Server/web compatibility and linux-x64 archive passed on this SHA, including agentCli.test.ts 10/10; darwin-arm64 archive is still pending runner availability. This approval is a code/QA verdict only, not a claim that all required CI gates are green or an instruction to merge.
Status: ready for review
Problem
Root decision 0210 and its addendum 3 (HumanAndMachines/Lazurio, merged) put Buddy, the person's own agent, inside their personal Environment. Buddy has to work with T3 Code threads exactly as the person does. That covers:
It must work in every Environment Buddy reaches over the tailnet. There Buddy SSHes in and acts with that Environment's access. Matěj chose the CLI for this: „nejlépe sedí do našeho Lazurio ekosystému … proto máme celou security boundary nadefinovanou jako celý environment, aby takovéhle mechanismy byly validní“ (it fits the Lazurio ecosystem best; that is why the whole Environment is the security boundary, so that mechanisms like this are valid; decision 0172).
Today
t3has no thread commands. An agent outside a thread gets MCP only throught3 auth session issue --subject mcp-client, and such a session's runtime-mode ceiling defaults toapproval-required(EnvironmentAuth.authenticateMcpClient). The CLI could not set it. So the agent can read the person's full-access threads, but every change fails withruntime_mode_escalation_denied. Nothing outside the app can decide a permission request either: MCP leaves approvals out on purpose.Change
Three commits: overlay row 20, and row 21 with its review follow-up (
bcf3c36229, below). They are rebase-friendly: new code lives inapps/server/src/lazurio/, and five upstream files get small, allowlisted hunks.Row 20:
feat(server): t3 auth session issue sets an MCP client's runtime-mode ceilingt3 auth session issue --subject mcp-client --runtime-mode-ceiling approval-required|auto-accept-edits|auto|full-accessissues the ceiling that the MCP sign-in's approval page already grants.--subject mcp-clientandorchestration:operate, the only case in which/mcpreads a ceiling. Anything else is refused rather than issued and silently ignored.approval-required.--jsonand text output name the ceiling.runtimeModeCeilingonEnvironmentAuth.issueSession, whichSessionStorealready signs asrtc, andMCP_CLIENT_SUBJECTis exported.Row 21:
feat(lazurio): agents work with T3 Code threads through t3 thread, request, queue and eventsEvery command takes
--base-dirand--json.t3 thread list--subagentsadds delegated ones). Filters:--project <id or title>,--status(repeatable, e.g.waiting),--settled/--no-settled,--title,--limit(1-100). Prints{threads, total}, withprojectIdandprojectTitleon each item.t3_project_list, thent3_thread_listper projectt3 thread read <id>--view messages|activity,--after,--limit,--itemwith--text-offset,--max-chars.t3_thread_readt3 thread search <query>--project.t3_thread_searcht3 thread launch [message] --title …--projectit starts in the Lazurio project that the managed startup recorded (otherwise--projectis required).--scratch;--base <ref> [--branch] [--from-origin]for a new worktree;--existing-worktree <path>. No model flag: as with the Launchpad's hand-off (decision 0189), it takes the project's default.t3_thread_launcht3 thread send <id> [message]--mode auto|queue|steer|restart;--message-file <path|->for long text.t3_thread_sendt3 thread interrupt <id>--run,--reason).t3_thread_interruptt3 thread wait <id>--timeout, default 10m, at most 1h). On timeout it prints the thread's state (with--jsonthe tool's result,timedOut: true) and exits 4.t3_thread_waitt3 thread organize <id> <action>pin,unpin,settle,unsettle,archive,unarchive,snooze --until <time or 2h>,unsnooze,mark-unread.t3_thread_organizet3 thread fork <id>--run/--checkpoint; optional--title.t3_thread_forkt3 request list [--thread]t3 request read <id>t3 request respond <id> --answer … | --answers '{…}'t3_pending_request_respondt3 request approve <id> [--for-session|--always]accept,acceptForSessionoracceptAlways, only where offered.runtime-request.respond, as the Approve button sends itt3 request deny <id> [--cancel]decline, orcancel.t3 queue list|read|edit|cancel|reorder|promotepromotedefaults to the running turn.t3_queue_*t3 events [--follow]t3_thread_list, plusprojectId,projectTitle,archived,pendingRequest,lastError,sequence), then{"kind":"synced"}. With--followit prints a line only when status, pending request, title, settled, snoozed, archived, latest run or last error changes. Streaming output alone prints nothing. It reconnects on a T3 restart or session expiry and resumes after the lastsequence, giving the reason on stderr. The output is JSON lines with or without--json; with--jsona failure that ends it is an error document, as for every command.--jsonprints the tool's own result, or{"error":{"code","message"}}; without--jsonthe message goes to stderr. The code is the MCP failure code when a tool refused, so agents see the same codes as over MCP.A command line that cannot work fails the same way, before anything is read and whether or not T3 Code is running:
invalid_request, exit 1. Examples are--for-sessionwith--always,--from-originwithout--base,snoozewithout--until, or a message that is missing or given twice. Each command's own checks run in one step ahead of the connection, inside the code that prints failures, so no check can fail silently.Two exits are deliberately not error documents, and the user guide says so:
thread waittimeout: it prints the thread's state and exits 4; the run goes on.t3cannot parse (an unknown flag, a missing argument, a value of the wrong kind): the CLI framework prints the command's help to stdout and the error to stderr as text, and exits 1, with or without--json. It does that before any command runs; a JSON form would mean changing upstream's global runner for everyt3command.Exit codes:
thread waittimed out.t3 lazurio capabilitiesgains"agentCli": true, which is additive. The user guide is the newdocs/user/agent-cli.md, linked whereoutside-agents.mdis (README.md,docs/README.md).outside-agents.mdno longer says that agents without OAuth cannot connect.Auth design, and why it is safe inside the Environment boundary
t3 auth session issueand get an administrative token. The commands add no authority; they only spare an agent from minting and storing a token by hand. This is decision 0172: the Environment is the boundary.--base-dir, ast3 projectandt3 lazuriodo. It issues its own sessions from the home's auth state, keeps the tokens in memory, and revokes them when it ends. The TTL (10 minutes, or the wait's timeout plus 10 minutes, or one hour pereventsconnection) only bounds a killed process. The sessions are labelledt3 agent cli, so they show in Settings → Connections while alive./mcpas anmcp-clientwith the full-access ceiling. That is the most an approved agent may have, and it runs through the same tools,McpToolAccessdeclarations, checks and failure codes as any other agent. There is no second orchestration path.orchestration:read+orchestration:operateonly (never access or relay scopes), for exactly what no MCP tool does:GET /api/orchestration/shell) and a thread's control state (…/threads/:id/bounded, or the whole thread when a request's card is older than that window);runtime-request.respondcommand the web's Approve and Decline buttons dispatch;t3 events.What stays unchanged
approval-requiredunless the flag is given.OrchestratorMcpService.tsonly exportslistItemFromShell, so event lines and list items share one mapping.binCli.tsgains one import and one spread.Verification
apps/server/src/lazurio/agentCli.test.ts, 10 tests. The realt3CLI runs against a live server on 127.0.0.1 over the test home's realEnvironmentAuth. The server has the real/mcptransport withMcpOAuth.layerMcpClientAuthenticator, the realOrchestratorToolkitandThreadToolkitdeclarations, and T3'sRpcScopeAuthorizationon the client-surface routes; only the orchestration services behind them are fakes.t3 auth session issue --subject mcp-clienttoken callingt3_thread_sendon a full-access thread getsruntime_mode_escalation_denied.t3 thread sendsucceeds as a full-access client with no thread of its own. A refusal keeps the tool's own code (thread_not_found) and exits 1. Not3 agent clisession is left afterwards.thread listmerges projects newest-first withtotaland passes filters through;thread readpasses its paging; nothing is dispatched.startsThreadsgrantsfull-access/default. A worktree strategy is passed through. Without a Folder it failstarget_required.request listshows a question and an approval, reading the whole thread only when the card is outside the bounded window.approvedispatchesruntime-request.respond/acceptthrough the WebSocket under T3's scope check.--for-sessionis refused when not offered.denydispatchesdecline. Approving a question is refused.respond --answerdispatches the answer throught3_pending_request_respond.synced, then stop, identical with and without--json. With--follow, an output-only update prints nothing, a status change prints, and after the stream drops it resubscribes withafterSequence= the last sequence. With--jsona failure, one-shot or--follow, is{"error":{"code":"server_not_running",…}}with exit 3; without, the message is on stderr and stdout stays empty.--for-session --always, launch's four flag conflicts and a message given twice, a missing message for send and queue edit,snoozewithout or with a bad--until, fork's--runwith--checkpoint, respond's--answer/--answersand a non-object--answers, reorder's--beforewith--last), plus an unreadable--message-file, each printinvalid_requestwith exit 1 with no server running. Without--jsonthe message is on stderr. The T3 home stays empty, which proves nothing was read: resolving its paths would create its folders. Pablo's exact approve case against the live server prints the error document, exits 1 and decides nothing.waittimeout prints the thread's state and exits 4; no server exits 3 with nothing issued.agentCliViews.test.ts, 7/7: the cross-project merge, pending-request extraction (defaults as in the web's card,not_resumable, missing card), and event dedupe, metadata refreshes, removal and filters.cli/auth.test.ts, 2/2: a ceiling issued through the CLI is the access/mcp's own authenticator grants; without the flag it staysapproval-required; invalid combinations issue nothing.cliAuthFormat.test.ts4/4,lazurio/cli.test.ts10/10,auth/EnvironmentAuth.test.ts,mcp/OrchestratorMcpService.test.ts.node --test scripts/lazurio-release-contract.test.mjs): 37/37 atb5aff065df, including a new seam test. The CI allowlist guard was replayed locally againstUPSTREAM_SHA, and the history has no merge commits.b5aff065df, locally; for the follow-up, in CI): server typecheck (tsc-rs --noEmit) has no new diagnostics, andvp fmt --checkandvp lintare clean on every changed file.node apps/server/src/bin.ts thread list --jsonwith no server prints the JSON error and exits 3.bcf3c36229(Pablo, review 5586415362). Atb5aff065df,t3 events --jsonfailed as an unknown flag, andt3 request approve … --for-session --always --jsonexited 1 with nothing printed: the check failed outside the error printer, and the runtime does not log these failures. A scan of every other command found no other check outside the printer, but those checks ran after the server check, so with T3 down they reportedserver_not_running(exit 3); they now come first. This machine had no disk space fornode_modules, so fork CI was the gate for this commit's tests, typecheck and lint (a frozen install,vp fmt --check, lint, server and web typecheck, and every test file the overlay adds or changes). Locally:oxfmt0.70.0, the lockfile's version, on the changed files; the release contract, 36/37 (the 37th importsagentBrowserSession.tsand needsnode_modules);git diff --check; and the PR preflight. CI onbcf3c36229: Server and web compatibility passed:vp fmt --checkclean; lint 0 errors (the repo's 924 warnings are elsewhere); server and web typecheck with no diagnostic in the changed files; the overlay tests, includingagentCli.test.ts10/10 in a server batch of 918 passed and 13 skipped. CLI archives / Build linux-x64 passed. CLI archives / Build darwin-arm64 never started on the first attempt: GitHub acquired no macOS arm64 runner ("not acquired by Runner of type hosted even after multiple attempts") and cancelled it, so the launcher install that follows it was skipped. Re-runs (attempts 2 and 3 of run 39444589665) ended the same way, about 15 minutes each, with GitHub's notice that macOS arm64 runners are capacity-constrained. Both jobs are required checks, so the macOS build has to be re-run when runners are back (gh run rerun 39444589665 -R Lazurio/t3code --failed); it builds the same bundle that passed on linux-x64.Upstreamable?
apps/server/src/lazurio/toapps/server/src/cli/, without the Lazurio Folder default.Rollout
X.Y.Z-preview.YYYYMMDD.Nfrommain, then canary on Ring 0 (LazurioExampleOrganization, decision 0204), then the stable-lazurio.N.t3 lazurio capabilities→"agentCli": true.Plan DEV-6676. Worktree
.worktrees/productionspace/t3code/DEV-6676-t3-agent-cli(HumanAndMachine-ai Organization).Model and harness: Claude Opus 5.5 in Claude Code.
🤖 Generated with Claude Code