Skip to content

feat(lazurio): agents work with T3 Code threads through the t3 CLI, and MCP tokens get a ceiling - #91

Merged
immakermatty merged 3 commits into
mainfrom
agent/DEV-6676-t3-agent-cli
Oct 20, 2026
Merged

immakermatty merged 3 commits into
mainfrom
agent/DEV-6676-t3-agent-cli

Conversation

@immakermatty

@immakermatty immakermatty commented Oct 20, 2026 •

Copy link
Copy Markdown

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:

  • reading threads and finding out what happened;
  • getting the status of the ten tasks the person started, and summarizing it;
  • answering a thread's questions in the person's name;
  • launching, stopping, continuing and steering threads, and fixing problems.

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 t3 has no thread commands. An agent outside a thread gets MCP only through t3 auth session issue --subject mcp-client, and such a session's runtime-mode ceiling defaults to approval-required (EnvironmentAuth.authenticateMcpClient). The CLI could not set it. So the agent can read the person's full-access threads, but every change fails with runtime_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 in apps/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 ceiling

t3 auth session issue --subject mcp-client --runtime-mode-ceiling approval-required|auto-accept-edits|auto|full-access issues the ceiling that the MCP sign-in's approval page already grants.

  • It needs --subject mcp-client and orchestration:operate, the only case in which /mcp reads a ceiling. Anything else is refused rather than issued and silently ignored.
  • Without the flag nothing changes: the default stays approval-required.
  • The issued session's --json and text output name the ceiling.
  • Code: an optional runtimeModeCeiling on EnvironmentAuth.issueSession, which SessionStore already signs as rtc, and MCP_CLIENT_SUBJECT is exported.

Row 21: feat(lazurio): agents work with T3 Code threads through t3 thread, request, queue and events

Every command takes --base-dir and --json.

Command What it does Through
t3 thread list Threads across all projects, newest change first. Top-level by default (--subagents adds delegated ones). Filters: --project <id or title>, --status (repeatable, e.g. waiting), --settled/--no-settled, --title, --limit (1-100). Prints {threads, total}, with projectId and projectTitle on each item. t3_project_list, then t3_thread_list per project
t3 thread read <id> State and a page of the timeline: --view messages|activity, --after, --limit, --item with --text-offset, --max-chars. t3_thread_read
t3 thread search <query> Title and message search, optionally in one --project. t3_thread_search
t3 thread launch [message] --title … A new thread. Without --project it starts in the Lazurio project that the managed startup recorded (otherwise --project is 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_launch
t3 thread send <id> [message] --mode auto|queue|steer|restart; --message-file <path|-> for long text. t3_thread_send
t3 thread interrupt <id> Stops the running turn (--run, --reason). t3_thread_interrupt
t3 thread wait <id> Waits for the run to finish (--timeout, default 10m, at most 1h). On timeout it prints the thread's state (with --json the tool's result, timedOut: true) and exits 4. t3_thread_wait
t3 thread organize <id> <action> pin, unpin, settle, unsettle, archive, unarchive, snooze --until <time or 2h>, unsnooze, mark-unread. t3_thread_organize
t3 thread fork <id> From the latest stable point, or --run / --checkpoint; optional --title. t3_thread_fork
t3 request list [--thread] Every pending question and permission request across threads, oldest first. Each has its prompt, offered decisions or questions, and whether it can still be answered. the person's thread list and thread snapshots
t3 request read <id> One request in full. same
t3 request respond <id> --answer … | --answers '{…}' Answers a question in the user's name. t3_pending_request_respond
t3 request approve <id> [--for-session|--always] Decides a permission request: accept, acceptForSession or acceptAlways, only where offered. the person's runtime-request.respond, as the Approve button sends it
t3 request deny <id> [--cancel] decline, or cancel. same
t3 queue list|read|edit|cancel|reorder|promote The queued messages behind a running turn. promote defaults to the running turn. t3_queue_*
t3 events [--follow] One JSON line per thread (the same item as t3_thread_list, plus projectId, projectTitle, archived, pendingRequest, lastError, sequence), then {"kind":"synced"}. With --follow it 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 last sequence, giving the reason on stderr. The output is JSON lines with or without --json; with --json a failure that ends it is an error document, as for every command. the person's live shell stream

--json prints the tool's own result, or {"error":{"code","message"}}; without --json the 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-session with --always, --from-origin without --base, snooze without --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 wait timeout: it prints the thread's state and exits 4; the run goes on.
  • A command line t3 cannot 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 every t3 command.

Exit codes:

  • 0 done;
  • 1 refused or invalid;
  • 3 T3 not running for this home (nothing read or changed, no session issued);
  • 4 thread wait timed out.

t3 lazurio capabilities gains "agentCli": true, which is additive. The user guide is the new docs/user/agent-cli.md, linked where outside-agents.md is (README.md, docs/README.md). outside-agents.md no longer says that agents without OAuth cannot connect.

Auth design, and why it is safe inside the Environment boundary

  • Who can use it. Only someone who can read the T3 home: its secrets directory is 0700, owned by the Environment's user. That is exactly who can already run t3 auth session issue and 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.
  • No stored secret. Each command finds the running server through the T3 home's runtime state, honouring --base-dir, as t3 project and t3 lazurio do. 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 per events connection) only bounds a killed process. The sessions are labelled t3 agent cli, so they show in Settings → Connections while alive.
  • Two surfaces, kept apart as T3 keeps them.
    • Everything agents do with threads goes through /mcp as an mcp-client with the full-access ceiling. That is the most an approved agent may have, and it runs through the same tools, McpToolAccess declarations, checks and failure codes as any other agent. There is no second orchestration path.
    • The person's client surface is used, with orchestration:read + orchestration:operate only (never access or relay scopes), for exactly what no MCP tool does:
      • the thread list with pending requests (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);
      • a permission decision, as the same runtime-request.respond command the web's Approve and Decline buttons dispatch;
      • the live shell stream for t3 events.
    • The WebSocket authenticates with a header, so no token appears in a URL.
  • Approvals stay off MCP. Upstream keeps permission decisions out of the MCP tools on purpose, and this PR does not widen that for every full-access agent. Only the person's own surface, used through the owner's CLI, decides them.
  • Loopback only. The CLI talks only to the origin the running server recorded for this home, which is loopback on Lazurio Environments.

What stays unchanged

  • The default ceiling of MCP sessions: approval-required unless the flag is given.
  • MCP tools and their access rules, including no approvals over MCP.
  • The HTTP and WebSocket APIs, contracts and the web, desktop and mobile clients. There is no UI change.
  • How agents inside threads work.
  • OrchestratorMcpService.ts only exports listItemFromShell, so event lines and list items share one mapping.
  • binCli.ts gains one import and one spread.

Verification

  • apps/server/src/lazurio/agentCli.test.ts, 10 tests. The real t3 CLI runs against a live server on 127.0.0.1 over the test home's real EnvironmentAuth. The server has the real /mcp transport with McpOAuth.layerMcpClientAuthenticator, the real OrchestratorToolkit and ThreadToolkit declarations, and T3's RpcScopeAuthorization on the client-surface routes; only the orchestration services behind them are fakes.
    • The gap and the fix: a t3 auth session issue --subject mcp-client token calling t3_thread_send on a full-access thread gets runtime_mode_escalation_denied. t3 thread send succeeds 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. No t3 agent cli session is left afterwards.
    • Read-only commands: thread list merges projects newest-first with total and passes filters through; thread read passes its paging; nothing is dispatched.
    • Launch: it goes to the Folder project with no model, and T3's startsThreads grants full-access/default. A worktree strategy is passed through. Without a Folder it fails target_required.
    • The approve path: request list shows a question and an approval, reading the whole thread only when the card is outside the bounded window. approve dispatches runtime-request.respond / accept through the WebSocket under T3's scope check. --for-session is refused when not offered. deny dispatches decline. Approving a question is refused. respond --answer dispatches the answer through t3_pending_request_respond.
    • The events stream: snapshot lines, then 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 with afterSequence = the last sequence. With --json a failure, one-shot or --follow, is {"error":{"code":"server_not_running",…}} with exit 3; without, the message is on stderr and stdout stays empty.
    • A command line that cannot work: 14 cases (approve's --for-session --always, launch's four flag conflicts and a message given twice, a missing message for send and queue edit, snooze without or with a bad --until, fork's --run with --checkpoint, respond's --answer/--answers and a non-object --answers, reorder's --before with --last), plus an unreadable --message-file, each print invalid_request with exit 1 with no server running. Without --json the 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.
    • Exit codes: wait timeout 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 stays approval-required; invalid combinations issue nothing.
  • Existing tests still pass: cliAuthFormat.test.ts 4/4, lazurio/cli.test.ts 10/10, auth/EnvironmentAuth.test.ts, mcp/OrchestratorMcpService.test.ts.
  • Release contract (node --test scripts/lazurio-release-contract.test.mjs): 37/37 at b5aff065df, including a new seam test. The CI allowlist guard was replayed locally against UPSTREAM_SHA, and the history has no merge commits.
  • Static checks (at b5aff065df, locally; for the follow-up, in CI): server typecheck (tsc-rs --noEmit) has no new diagnostics, and vp fmt --check and vp lint are clean on every changed file.
  • Smoke test: node apps/server/src/bin.ts thread list --json with no server prints the JSON error and exits 3.
  • Review follow-up bcf3c36229 (Pablo, review 5586415362). At b5aff065df, t3 events --json failed as an unknown flag, and t3 request approve … --for-session --always --json exited 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 reported server_not_running (exit 3); they now come first. This machine had no disk space for node_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: oxfmt 0.70.0, the lockfile's version, on the changed files; the release contract, 36/37 (the 37th imports agentBrowserSession.ts and needs node_modules); git diff --check; and the PR preflight. CI on bcf3c36229: Server and web compatibility passed: vp fmt --check clean; lint 0 errors (the repo's 924 warnings are elsewhere); server and web typecheck with no diagnostic in the changed files; the overlay tests, including agentCli.test.ts 10/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.
  • Not done: a run against a live T3 install. The developer's live T3 home must not be opened read-write, and that is what the commands would do. The contract tests cover the real transport, auth and access layers. A live check belongs on Ring 0 after a preview.

Upstreamable?

  • Row 20, yes. It is a focused configuration option for an established capability: the ceiling the MCP approval already grants. That fits CONTRIBUTING's configuration route without prior feature approval.
  • Row 21, not as is. It is a new workflow, so upstream needs an approved Ideas discussion first. The code is upstream-shaped, with services and no new server surface. It would move from apps/server/src/lazurio/ to apps/server/src/cli/, without the Lazurio Folder default.

Rollout

  • A fork release through the release channel: first a preview X.Y.Z-preview.YYYYMMDD.N from main, then canary on Ring 0 (LazurioExampleOrganization, decision 0204), then the stable -lazurio.N.
  • After that, Matěj's personal Environment, where the Buddy pilot runs.
  • Buddy and Machines can detect support with t3 lazurio capabilities → "agentCli": true.
  • There is no Platform dependency.

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

immakermatty and others added 2 commits October 20, 2026 15:59
… 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 agentrozjedemeai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

  1. apps/server/src/lazurio/agentCli.ts:1265-1280 — t3 events does not accept --json, despite the stated per-command --json contract. t3 events --json --base-dir <home> exits 1 with Unrecognized flag: --json instead of producing JSON lines. Accept the flag (the output can remain JSONL) and cover it in the CLI test.

  2. apps/server/src/lazurio/agentCli.ts:1031-1037 — the --for-session/--always conflict fails outside run, 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 agentrozjedemeai left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants