README.md

pi-t3-bridge

pi-t3-bridge is a Pi package that runs Pi as an agent inside T3 Code. It gives a Pi thread the tools T3 expects, and it adds three skill sets, pstack, tstack and bstack, so the thread can plan work, hand parts of it to other models, and check what comes back.

mermaid
1flowchart LR
2 You((You)) --> T3[T3 Code]
3 T3 -->|runs a thread| Pi[Pi agent]
4 subgraph pkg [pi-t3-bridge]
5 Bridge[bridge.ts<br/>cards, goals, workflows, limits]
6 Pstack[pstack.ts<br/>pstack skills, model routing, child sandbox]
7 Tstack[tstack.ts<br/>tstack skills]
8 Bstack[bstack.ts<br/>ship skill]
9 end
10 Pi --> Bridge & Pstack & Tstack & Bstack
11 Bridge -->|MCP| T3
12 Pstack -->|delegate_task| T3
13 T3 -->|child threads| Models[Claude, GPT, and other models]

Requirements

You need Node.js 22.19.0 or later and Pi 1.5.0 or later. T3 Code is needed only if you run Pi threads inside T3 or call T3 tools from Pi.

On Linux, delegated children run in a bwrap sandbox, so you also need the bubblewrap package. If AppArmor stops bwrap, run sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0.

Install

The package is on GitHub only, so you install it with Pi from git.

bash
1pi install git:git.cafe/dynd/pi-t3-bridge # newest commit on main
2pi install git:git.cafe/dynd/pi-t3-bridge@v0.12.2 # one release
3pi -e git:git.cafe/dynd/pi-t3-bridge # one session, nothing saved

pi update --extensions moves an install from main to the newest commit. If you still have the old npm package, run pi remove npm:pi-t3-bridge before you install from git.

Each of the four extensions works on its own, so you can load only the ones you want.

json
1{
2 "packages": [
3 {
4 "source": "git:git.cafe/dynd/pi-t3-bridge",
5 "extensions": ["bridge.ts"]
6 }
7 ]
8}

What is in the package

text
1pi-t3-bridge/
2├── bridge.ts # connects Pi to T3 Code
3├── pstack.ts # serves pstack skills and picks models for subagents
4├── tstack.ts # serves tstack skills
5├── bstack.ts # serves the bstack ship skill
6├── src/bridge/ # code for bridge.ts
7├── src/pstack/ # code for pstack.ts, including the child sandbox
8├── pstack/ # upstream pstack skills, agents, and model defaults
9├── overlay/ # the changes Pi needs on top of pstack/
10├── tstack/ # Theo Browne's tstack skills
11└── bstack/ # ship, full-send cut down to a push to main

Tools and commands

The bridge adds the tools and commands below, and T3 shows most of them as cards in the chat. If another package already has a tool with the same name, e.g. ask from pi-ask, the bridge keeps the other tool and tells you once.

NameWhat it does
tasksShows the task list for the run as a card. With workflowId, it shows a workflow's steps.
planShows a plan card with Approve, Revise, and Cancel buttons.
askAsks you questions as cards and waits for your answers.
create_workflow, get_workflowSave and read a workflow of steps with dependencies and acceptance checks.
launch_workflow_step, reconcile_workflow_stepStart a delegated step in T3, and settle a launch whose result is unknown.
transition_workflowStarts, finishes, retries, or cancels a step, holds a local step for your decision, or records that a worktree step was merged.
create_goalStarts a goal when you or a skill you invoked asks for one, as in Codex.
get_goal, update_goalRead the saved goal, and report completion or a blocker with evidence.
transcriptReturns the session file and session ID.
pstack_modelPicks the model for a subagent. It comes from pstack.ts.
/goalSaves, shows, edits, pauses, resumes, or clears the session's goal.
/t3-usageShows the cost of the thread and its children, the cache hit rate, and which model families are out of usage.
/t3-exhausted <family> [reset time], /t3-recovered <family>Mark a model family as out of usage, or usable again, for every chat on the machine.
/t3-transcriptShows the session file path.

Workflows

A workflow is a saved list of steps that the agent works through in order, and each step must show evidence before the steps after it can start. The agent creates one with create_workflow when a job has parts that depend on each other or that other models should do in parallel.

text
1create_workflow
2 id: "fix-login"
3 concurrency: 2 # steps that may run at the same time
4 maxAttempts: 2 # tries per step
5 goalId: <optional> # ties the workflow to the saved goal
6 steps:
7 reproduce local shared acceptance [repro-output]
8 fix-api delegated worktree depends on reproduce acceptance [tests-pass]
9 fix-ui delegated worktree depends on reproduce acceptance [screenshot]
10 merge local shared depends on fix-api, fix-ui integrates fix-api, fix-ui

A step runs either in the parent thread or in a child thread. A local step always works in the parent's own checkout, which the schema calls shared. A delegated step runs in a T3 child, either in the same checkout or in its own git worktree.

ExecutorIsolationHow it startsHow it ends
localsharedtransition_workflow with starttransition_workflow with finish and evidence
delegatedshared or worktreelaunch_workflow_step, which calls T3's delegate_tasktransition_workflow with finish, after T3 reports the child done

Step states

A step becomes ready only when every step it depends on has succeeded with evidence for each acceptance ID. A worktree step's output must also be merged by a shared step that lists it in integrates, unless the step that depends on it is that same shared step.

mermaid
1stateDiagram-v2
2 [*] --> pending
3 pending --> ready: dependencies accepted
4 ready --> running: start or launch
5 running --> waiting_for_child: T3 started the child
6 running --> waiting_for_user: launch result unknown, or local wait
7 waiting_for_user --> running: resume, or reconcile as started
8 waiting_for_user --> failed: reconcile as not started
9 running --> succeeded: finish with evidence
10 waiting_for_child --> succeeded: finish after the child is done
11 running --> failed: finish as failed
12 waiting_for_child --> failed: finish as failed
13 waiting_for_child --> cancelled: cancel the child
14 failed --> pending: retry, if attempts remain
15 ready --> cancelled: cancel before start

Launch and finish of a delegated step

The bridge records the intent to launch before it calls T3, so a crash between the two calls never leaves a child the workflow does not know about. After a restart, a step with only an intent moves to waiting_for_user, and the agent checks T3 and calls reconcile_workflow_step.

mermaid
1sequenceDiagram
2 participant Agent
3 participant Bridge
4 participant T3
5 participant Child
6 Agent->>Bridge: launch_workflow_step(stepId, revision, task)
7 Bridge->>Bridge: save launch intent
8 Bridge->>T3: delegate_task
9 T3->>Child: start
10 Bridge->>Bridge: save child task ID, state waiting_for_child
11 Child-->>T3: final result
12 Agent->>Bridge: transition_workflow(finish, evidence)
13 Bridge->>T3: task_status
14 T3-->>Bridge: completed, no pending work
15 Bridge->>Bridge: save result, state succeeded

The bridge accepts a delegated step as finished only when T3 says the child is done, with no question, approval, or child work still pending. Otherwise finish saves the latest child status and leaves the step waiting.

Rules the bridge enforces

The bridge checks every change against the saved workflow, so two calls can't overwrite each other and a stale plan can't run.

text
1on(any workflow change)
2 if revision differs from the saved revision refuse
3 if the workflow belongs to another session or branch refuse
4 if the workflow names a goal that no longer allows work refuse
5 if a second shared step would write the checkout refuse
6 if running steps would exceed concurrency refuse
7 if the step has used all its attempts refuse retry
8 save the new workflow and add 1 to revision

Workflows live as t3.workflow.v1 entries in the session file, so each branch of a session has its own workflows. When a workflow names the saved goal, the goal can't complete until every step of the workflow is accepted, and pausing the goal also cancels the workflow's running children.

Saved goals

/goal <objective> saves one objective on the session branch and starts work on it. When the agent stops before it has finished, the bridge asks it to continue, until the agent reports completion with evidence or reports a blocker.

text
1active
2 completion with current evidence complete
3 the same blocker for 3 cycles blocked
4 Stop, or a restored session paused
5paused or blocked
6 /goal resume active
7any state
8 /goal clear no goal
CommandResult
/goalShows the objective, status, and reason, without a model request.
/goal <objective>Starts a goal when no unfinished goal exists.
/goal -- <objective>Starts a goal whose first word is a command word, e.g. edit.
/goal edit <objective>Changes an unfinished goal, and drops its old evidence.
/goal pause, /goal resume, /goal clearPause, restart, or remove the goal.

The agent proposes acceptance conditions, and each condition may name a command and its exit code, or a file and the text it must contain. When the agent reports completion, the bridge checks each one against fresh evidence. Like Codex, the goal never waits for your approval, and only you pause it. The agent marks it blocked after the same blocker stops it three cycles running.

text
1update_goal(status: complete)
2 if there are no conditions refuse
3 if a question, approval, child, or linked workflow is pending refuse
4 if the files changed since the evidence refuse, gather fresh evidence
5 run each command and file check
6 if every condition has current evidence mark complete

In T3, press Stop before you send a goal command, because T3 refuses commands while the thread is busy. In a terminal or over RPC, you can send them at any time. With pi -p "/goal <objective>", Pi waits for the goal's run to end before it exits.

Goals have no token or time budget, and normal permissions still apply. Opening, reloading, or cloning a session pauses an active goal, so only /goal resume starts work again.

T3's /clear starts a new Pi session in the same thread. The bridge moves an unfinished goal and the facts its evidence cites into the new session, paused, so /goal resume goes on with a fresh context and /goal clear drops it. Workflows stay in the old session, because their steps belong to it, and the bridge names the ones it left behind. Pi's own /new outside T3 starts with no goal.

Status line

The bridge shows up to three lines next to the composer. T3 shows them above the chat box as Pi · …, and the Pi terminal shows them in its footer. Each line disappears when it has nothing to say.

LineExample
The unfinished goalGoal active: Ship the widget with a passing build
Each unfinished workflow, with its finished stepsWorkflow fix-login 2/4
Model families out of usageclaude out until 13:03 UTC

Plan approval

T3's own Plan mode does nothing in a Pi thread, because T3 doesn't send the Plan setting to Pi. The agent uses the plan tool instead, and while the plan card waits for you, the bridge blocks every tool that can change files.

mermaid
1stateDiagram-v2
2 [*] --> open
3 open --> waiting: agent calls plan
4 waiting --> approved: Approve
5 waiting --> revising: Revise
6 waiting --> cancelled: Cancel
7 revising --> waiting: agent calls plan again
8 cancelled --> open: you send a new message
9 approved --> [*]: write tools run again

Read-only tools still run while the card waits, so the agent can keep reading files. If the card can't render, the plan appears in a selection dialog instead.

Reply checks

When a run is about to stop, the bridge checks the last reply with fixed rules. No model judges the reply, so the same reply always gets the same result.

text
1on(run about to stop)
2 if the reply hit the output limit
3 continue, at most twice per prompt
4 else if the session has a UI and is not a child
5 if the closing asks for a login, token, key, or password
6 and request_secret is on
7 tell the agent to call request_secret
8 else if the closing waits on you ("once you've", "let me know when")
9 tell the agent to do the task, or ask with the ask tool
10 else if the last 5 lines of prose ask a question
11 tell the agent to ask with the ask tool, or drop an offer
12 or a question whose only sensible answer is yes

Each of the last three rules fires at most once per prompt. A question or a request in plain text ends the run, and nobody sees it until much later. These rules send the agent back to put it on a card that waits for your answer, so the run goes on once you answer. "Let me know if you want more" is an offer, not a wait, and "Nothing needed from you" asks for nothing, so neither counts. An instruction such as "run /reload" or "you'll need to restart", even under "What I need from you", doesn't block the run, so it doesn't count either. Code blocks don't count, and inline code counts only for its words, so STRIPE_SECRET_KEY names a secret but a ? in a regex is not a question.

Inside T3, T3 offers request_secret only through tool_search, so a model rarely finds it. The bridge declares it to the model in every T3 thread that has a UI and is not a child, so a secret card is one call away, like ask.

Usage limits and resume

The bridge keeps one record of which model families are out of usage, and every Pi session on the machine reads it. When a child fails with a usage limit, the bridge marks its family as out until the reset time, and pstack sends new work to another family.

mermaid
1sequenceDiagram
2 participant Parent
3 participant Bridge
4 participant T3
5 Parent->>T3: delegate_task (Claude)
6 T3-->>Bridge: child failed, usage limit
7 Bridge->>Bridge: mark claude as out until the reset
8 Parent->>T3: delegate_task (next family)

When the main thread's own account runs out, the agent can't call any tool. The bridge then asks T3 to post a resume message into the thread just after the reset time.

Shell time limit

The bridge stops any shell command after 300 seconds, in the main thread and in children. A command can ask for a shorter limit but not a longer one, and you can change the limit with bashTimeoutSeconds.

T3 tools from a terminal

When you run Pi in a terminal, the bridge connects it to the MCP server of the T3 Code app on your machine, so you can start and message T3 threads from the terminal.

text
1on(session start)
2 if Pi runs inside a T3 thread
3 use the tools T3 gives the thread
4 else
5 if the saved token is missing or expires within a day
6 sign in with the t3 CLI, no browser needed
7 connect to mcpUrl
8 show "connected, N tools" or the error in the status bar

The token lasts 30 days and is saved in ~/.local/state/pi-t3/t3-mcp.json. When mcpUrl points at a T3 server on another machine, sign in with /mcp login t3 instead.

The pstack extension

The pstack extension serves the pstack skills, which reach Pi through t3-pstack. The poteto-mode skill picks the workflow that fits your request, e.g. a bug fix, a feature, a design review, or a PR watch.

text
1on(Pi start)
2 copy pstack/ to ~/.local/state/pi-t3/pstack-overlay/<hash>/
3 apply each change in overlay/ to the copy
4 serve the skills from the copy

The pstack/ folder keeps the upstream text unchanged, and overlay/ holds the changes Pi needs. If an overlay change no longer matches a new upstream version, the tests fail and name the file.

Model routing

The pstack_model tool returns the T3 target for a subagent, based on its role, job, and size.

text
1pstack_model(role, job, size)
2 if size is L refuse, so the agent splits the job
3 if the model sheet names a model use it
4 else look up job and size in pstack/models.json
5 if the model's family is out use the same tier in the next family
6 return the target for delegate_task
JobSize S (30 min, 5 files)Size M (90 min, 15 files)
mechanicalHaiku 5.5, lowSonnet 5.5, medium
checkGPT 6 Luna, lowHaiku 5.5, medium
researchMuse Spark 1.3, mediumMuse Wonder 1.0, medium
implementGPT 6.1 Sol, mediumSonnet 5.5, high
hardOpus 5.5, highOpus 5.5, high
review panelOpus 5.5, Muse Wonder Full 1.0, GPT 6.1 Solsame
design panelOpus 5.5, Muse Wonder Full 1.0, GPT 6 Astrasame

To choose your own models, run the setup-pstack skill. It writes a model sheet at ~/.config/pi-t3-bridge/models.md, and a line of session hook: off in the sheet stops the poteto-mode note on each prompt.

Limits for delegated children

When a session starts with a complete pstack brief, the extension treats it as a delegated child and holds it to the limits in the brief. The child can't lift the limits through anything it writes.

text
1on(tool call)
2 if the first message is not a "# Task:" brief
3 your own session, no limits
4 else if the brief is complete
5 child: sandboxed shell, writes only to listed files, time and disk limits
6 else if T3 started the session as a delegated task
7 block every tool and list what the brief is missing
8 else
9 your own session, no limits

A brief is complete when its header names the job, size, time limit, and disk limit, and it has all seven sections of pstack/skills/poteto-mode/brief.md. The child writes its report from commands it ran itself, and the parent reads the report from ledger.jsonl when it checks the task.

The child sandbox

A delegated child runs every shell command in a sandbox, which is sandbox-exec on macOS and bwrap on Linux and WSL2. The child can write to its own work and to package manager caches, and everything else stays read-only.

text
1writable inside the sandbox
2├── <workdir>/ # the child's checkout
3├── <git dir>/ # so git commit works, except hooks/ and config
4├── ~/.cache, ~/.npm, ~/.local/share/uv, ~/.local/share/mise
5├── <pnpm store>/
6├── <system temp folder>/ # also $TMPDIR and $XDG_RUNTIME_DIR
7└── /dev

Install scripts don't run inside the sandbox, because a prepare such as lefthook install would fail on the read-only hooks. On Linux each child also gets its own process namespace, so a stray pkill can't reach the host.

Chrome and Electron need --no-sandbox inside the child, and a pi run inside a child needs PI_CODING_AGENT_DIR set to a writable copy of ~/.pi/agent. Native Windows and WSL1 have no sandbox, so the bridge blocks a child's shell commands there unless you set childSandbox to "off".

The tstack extension

The tstack extension serves Theo Browne's skills from tstack/skills. They cover the PR cycle, from file-pr through babysit-pr, plus council, sol-loop, full-send, full-stop, takeover, modernize, and leaving-pr-comments.

The bstack extension

The bstack extension serves one skill, ship, which you start by saying "ship it". It is tstack's full-send with steps cut. One lead model does the work and commits to the default branch, with no PR, sol-loop or council.

text
1finish the change and prove it
2run the CI config's commands locally
3git pull --rebase, then git push origin HEAD:main # never force
4gh run watch on main
5 red -> git revert, push, fix forward

It still files a PR when you ask for one, when the branch is protected, when you can't push, when the repo requires PRs, or when a push to main deploys to users.

Settings and files

The bridge reads ~/.config/pi-t3/config.json again on each prompt, and every key is optional. If a value is invalid, only that key falls back to its default.

KeyDefaultMeaning
bashTimeoutSeconds300The longest a shell command can run, in seconds.
childSandbox"on"With "off", child commands run with no sandbox on every platform.
mcpUrlhttp://127.0.0.1:3773/mcpThe T3 MCP address for Pi in a terminal. It applies on the next /new, /reload, or start.
text
1~/.config/
2├── pi-t3/config.json # bridge settings
3└── pi-t3-bridge/models.md # model sheet from setup-pstack
4~/.local/state/pi-t3/
5├── accounts.json # model families that are out of usage
6├── ledger.jsonl # one line per delegated brief, with cost and report
7├── t3-mcp.json # T3 MCP token for Pi in a terminal
8└── pstack-overlay/ # pstack skills with the Pi changes applied

XDG_CONFIG_HOME and XDG_STATE_HOME replace ~/.config and ~/.local/state when they are set.

Data handling

The package has no server and sends no telemetry. Any file a skill asks the agent to read goes to your model provider, and the PR tools use your GitHub CLI login.

Development

The repository uses npm, and some tests need Docker to run Linux containers.

bash
1npm install
2npm test # node:test suites for the bridge and the pstack scripts
3npm run typecheck
4npm run check # Ultracite lint and format check

The pstack/ folder is a git subtree of t3-pstack, so you take upstream changes with git merge -X subtree=pstack pstack-upstream. Put Pi changes in overlay/, and leave pstack/ as upstream wrote it.

License

The package uses the MIT license. See LICENSE and NOTICE.md for the copyright holders, who include Lauren Tan, Cursor, and Christian Bager Bach Houmann. The skills in tstack/ keep their own MIT license from Theo Browne, in tstack/LICENSE.