Skip to content

feat(providers): add Pi coding agent - #7211

Open
StiensWout wants to merge 262 commits into
pingdotgg:t3code/codex-turn-mappingfrom
StiensWout:t3code/pi-provider
Open

feat(providers): add Pi coding agent#7211
StiensWout wants to merge 262 commits into
pingdotgg:t3code/codex-turn-mappingfrom
StiensWout:t3code/pi-provider

Conversation

@StiensWout

@StiensWout StiensWout commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Problem

Pi users depend on their existing models, auth, extensions, skills, context files, and native session history. T3 Code did not have a Pi provider, and a shallow CLI wrapper would lose the customization and session behavior that make Pi useful.

Solution

This adds Pi as an Early Access provider on Orchestrator V2:

  • T3 speaks Pi's stdio JSONL RPC protocol through the user's own installation and discovers models, thinking levels, commands, skills, and auth from Pi itself.
  • T3 threads use Pi's native session files for resume, current-branch fork, rollback, steering, and session naming.
  • Extension dialogs, notifications, status rows, MCP tools, and resumable subagents project into the existing T3 lifecycle surfaces.
  • The launcher replaces only Pi's conflicting official subagent extension, deduplicates explicit extension arguments, and restores trusted user and project extensions.
  • Pi's session statistics feed the shared composer context meter. The ring tracks the active thread's context window while the popover exposes cumulative tokens processed across that Pi session.
  • Turn settlement, retry and compaction recovery, child cancellation, process teardown, and fork rollback paths fail closed without leaking or corrupting the active native session.

The MCP bridge, resumable subagent work, and per-model thinking support originated in @mwolson's stacked contribution and retain that authorship.

Related work

Closes #397.
Closes #402.
Addresses #6685.

This supersedes the Pi implementations in #2211, #2748, #2800, #2812, #2831, #2856, #3818, #3947, #4355, #4445, #5688, #5882, and #6319.

This incorporates StiensWout#34 by @mwolson.

Validation

  • 33 focused Pi tests, reduced from 48 by removing duplicate helper and branch matrices while strengthening observable lifecycle coverage.
  • Targeted contracts, server, and web typechecks.
  • Targeted changed-file lint and formatting.
  • Both generated Pi extensions parsed independently as TypeScript.
  • Live validation against Pi 0.84.2, including provider discovery, multi-turn context usage, MCP, extension UI, native subagents, steering, rollback, and provider handoff.
  • Mobile parity audited for the shared Codex and Claude surfaces; Pi-specific mobile behavior is intentionally limited to provider identity and model selection.

Proof

Provider discovery

Pi provider discovery

End-to-end Pi turn

Pi end-to-end turn

Context meter persists across turns

The active context stays at 21k/272k while Pi's cumulative session total rises from 90k to 111k after the next completed turn.

Pi context meter persistence

Native resumable subagent

Pi resumable subagent

Native steering

Pi steering

Checkpoint and Pi session-tree rollback

Pi rollback

Stacked on #2829 (t3code/codex-turn-mapping) until that branch lands.

Built by GPT-5.6 Sol in T3 Code through Codex.

juliusmarminge and others added 30 commits August 15, 2026 16:48
Co-authored-by: codex <codex@users.noreply.github.com>
- Document the target orchestration graph, IDs, lifecycles, and capability model
- Add Codex app-server probe fixtures and update the probe test harness
- Introduce orchestration v2 service interfaces and error types
- Add replay runtime, fixtures, and integration coverage
- Update shared contracts and probe transcripts

Co-authored-by: codex <codex@users.noreply.github.com>
- Add Codex adapter and replay harness wiring
- Introduce in-memory orchestration projections and provider registry
- Expand orchestration contracts for turn and runtime events
Co-authored-by: codex <codex@users.noreply.github.com>
- Add context transfer IDs, schemas, and projections
- Support cheap fork creation and Codex native fork rollback
- Cover fork idempotency and replay behavior in tests
- Track remaining projection, context transfer, rollback, capability, and subagent work
- Clarify current V2 baseline and debugger-only follow-ups
- Map fork and merge-back turns into stored handoffs and transfer resolutions
- Add shell snapshot projection support plus coverage tests
- Update replay fixtures and web contracts for the new turn flow
Co-authored-by: codex <codex@users.noreply.github.com>
- Move Codex replay recording into `apps/server`
- Add Claude Agent SDK replay fixtures and test harness
- Update orchestration-v2 fixture scenarios and docs
- Move Claude provider runtime logic into its own module
- Share the SDK query runner between live and replay paths
- Add replay driver error wrapping for unexpected failures
- persist the selected model on run records
- surface run model selection in the debug UI
- update replay fixtures and contracts for the new field
- Record Claude SDK transcripts across multiple prompts and restart/query modes
- Add approval and tool-call replay coverage for new orchestration fixtures
- Update Claude adapter testkit to model open/prompt/permission frames
- Derive Claude SDK query options from runtime policy
- Add read-only replay fixture and policy mapping tests
- Reuse shared approval-policy fixtures across orchestrator tests

Co-authored-by: codex <codex@users.noreply.github.com>
- add active steering and interrupt-restart replay fixtures
- update Claude adapter/orchestrator turn handling for steering
- refresh replay and integration test coverage
- add interrupt and mid-tool replay fixtures for Claude and Codex
- log Claude Agent SDK protocol frames to native event traces
- project Codex commandExecution start events into orchestration updates
- Map Cursor SDK agents and runs to V2 thread and turn lifecycles
- Update MCP capability, tool, and testing guidance for SDK-based injection
Co-authored-by: codex <codex@users.noreply.github.com>
Co-authored-by: codex <codex@users.noreply.github.com>
Co-authored-by: codex <codex@users.noreply.github.com>
Record provider fixtures for continued forks and sibling merge-backs, exercise context survival end to end, and stop completed run listeners from consuming later provider events.

Co-authored-by: codex <codex@users.noreply.github.com>
Allow a pending merge-back to be consumed while changing providers and deliver both the provider-switch history and fork delta to the selected provider.

Co-authored-by: codex <codex@users.noreply.github.com>
Send full canonical target-thread context when a provider switch consumes a merge-back, and cover returning to an existing provider thread after a cross-provider fork.

Co-authored-by: codex <codex@users.noreply.github.com>
- Require operate scope for v2 command dispatch
- Allow read scope for v2 thread and shell subscriptions
Co-authored-by: codex <codex@users.noreply.github.com>
Co-authored-by: codex <codex@users.noreply.github.com>
- Register orchestration tools on the MCP HTTP server
- Grant orchestration capability to MCP sessions
- Add service and integration coverage for delegated tasks and thread creation
- Wire Cursor adapter and provider session handling into orchestration v2
- Add replay fixtures, recording script, and coverage for Cursor turn flows
- Update docs and debug timeline mapping for Cursor events
- split streaming assistant and reasoning output into separate segments
- filter hidden interruption artifacts from projections and replay fixtures
- keep visible timeline positions stable when upserting streamed items
StiensWout and others added 2 commits August 16, 2026 19:27
Stop aborts pi's in-flight tools, which pi reports as tool_execution_end
with isError. Mapping every error end to failed painted a red failed
command card under a correctly interrupted run. Error ends on an
interrupted turn now close as interrupted, and aborted subagent tasks
follow the same rule, matching how OpenCode presents the same path.
Reported from the provider manual live-test pass.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Five spec-fidelity fixes against pi's rpc.md:
- a session_before_switch extension veto now fails the resume instead of
  silently adopting whichever session stayed active
- failed compactions surface as a failed compaction item with the error
  instead of disappearing
- empty input/editor dialog answers deliver as values (the spec's
  'extension receives ""'), no longer converted to cancels
- editor dialogs show their prefill inside the question text so the user
  is not editing blind
- text generation passes --no-extensions so an unanswerable extension
  dialog cannot stall commit-message generation until its timeout

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Comment thread apps/server/src/orchestration-v2/Adapters/PiAdapterV2.ts Outdated
Comment thread apps/server/src/orchestration-v2/Adapters/PiRpc.ts
Comment thread apps/server/src/orchestration-v2/Adapters/PiRpc.ts
Comment thread apps/server/src/orchestration-v2/Adapters/PiAdapterV2.ts
Comment thread apps/server/src/orchestration-v2/Adapters/PiAdapterV2.ts
Comment thread apps/server/src/orchestration-v2/Adapters/PiAdapterV2.ts Outdated
Comment thread apps/server/src/orchestration-v2/Adapters/PiAdapterV2.ts
Six review findings from the protocol-gap round:

- A recovered auto-retry no longer terminalizes as failed. Pi emits the
  erroring `message_end` before retrying, and `auto_retry_end` success left
  that failure in place, so `agent_settled` failed the whole turn.
- A failed `prompt` send finalizes the turn again. The fire-and-forget
  change moved the send off `request`, dropping the cleanup, so a send
  failure left `activeTurn` set and wedged every later turn.
- `startTurn` now holds the session permit, so a new turn cannot start while
  the previous `finalizeTurn` is still awaiting `get_entries`. That race let
  the old finalizer capture the new turn's entry and publish idle after the
  new turn had already published active.
- `switch_session` clears the model and thinking baselines too, so
  "Pi default"/"inherit" cannot replay the previous session's defaults.
- Termination re-checks liveness before SIGTERM and before escalating to
  SIGKILL. Signalling a pid that already exited can hit an unrelated process
  once the OS recycles the pid or pgid.
- Windows tears down the whole tree with `taskkill /T`, matching
  `AcpSessionRuntime`. `process.kill` reached only pi itself and left
  extension subprocesses holding inherited stdio handles.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Comment thread apps/server/src/orchestration-v2/Adapters/PiAdapterV2.ts Outdated
Capability rejections surfaced their internal diagnostic string, so a
checkpoint revert on a provider without rollback support showed 'pi
cannot satisfy rollback_snapshot for command <uuid>: rollback must
return a providerInstanceId thread snapshot'. userFacingDispatchErrorMessage
now renders known policy rejections as provider-named prose ('Pi did not
report its rewound conversation state, so the checkpoint was not
restored.') and keeps the diagnostic form for logs and unknown codes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Comment thread apps/server/src/orchestration-v2/UserFacingErrors.ts
Pi core has no MCP client. V2 already minted a scoped t3-code bearer
before openSession. This writes a T3-owned extension into the server
cache and spawns pi --mode rpc --extension <that file> with T3_MCP_URL
and T3_MCP_BEARER_TOKEN. Each MCP tool is registered under its original
name. User launchArgs are preserved. The first turn receives the shared
orchestration instructions.
Official subagent uses --no-session, so T3 could project cards but could
not open the child. Inject a T3-owned override that persists --session,
reports sessionFile, and binds each result as a child thread. Follow-up
sends allocate a new RPC and resume with switch_session.

Duplicate subagent registrations abort Pi, so spawn disables extension
discovery and drops the official tool from launchArgs.
Pi discovery used one High-capped picker for every reasoning model.
get_available_thinking_levels is session-scoped, so catalog discovery
now reads each get_available_models thinkingLevelMap instead. Extra
High and Max appear only when the map has a non-null entry.
Comment thread apps/server/src/orchestration-v2/Adapters/piT3SubagentExtensionSource.ts Outdated
Comment thread apps/server/src/orchestration-v2/Adapters/piT3McpInjection.ts Outdated
Comment thread apps/server/src/orchestration-v2/Adapters/PiAdapterV2.ts
Comment thread apps/server/src/orchestration-v2/Adapters/piT3McpInjection.ts
StiensWout and others added 2 commits August 17, 2026 07:53
…3 tools

The T3 subagent override spawns pi with --no-extensions, which silently
cost users every other extension they had installed. Re-discover the
user's extensions (agent dir, plus project .pi/extensions only under
standing trust) and re-add them with explicit --extension flags. Child
subagent spawns now also attach the T3 MCP extension so t3_thread_*
tools survive the nested spawn.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Closes the remaining coverage gaps against pi's RPC surface:

- forkThread clones pi's session tree and switches the live process back
  to the source, so T3-side thread forks map to native clones.
- readThreadSnapshot reconstructs the conversation from get_entries,
  giving handoff and preview surfaces a real transcript.
- setStatus/setWidget extension calls project as keyed live work-log
  rows that update in place and close on settle.
- Session-start extension dialogs (e.g. project trust) are buffered and
  attached to the next turn instead of being cancelled unseen.
- Stop-with-restart aborts the turn and terminates the pi process, and
  transport death during an interrupt reads as interrupted, not failed.
- A recovered auto-compaction clears the stashed model error so the
  turn completes instead of reporting the pre-compaction failure.
- Opening a subagent's child thread while its task is still running is
  refused with a clear message instead of corrupting the child session.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Comment thread apps/server/src/orchestration-v2/Adapters/PiAdapterV2.ts Outdated
Comment thread apps/server/src/orchestration-v2/Adapters/PiAdapterV2.ts Outdated
Comment thread apps/server/src/orchestration-v2/Adapters/PiAdapterV2.ts
Comment thread apps/server/src/orchestration-v2/Adapters/PiAdapterV2.ts
StiensWout and others added 2 commits August 17, 2026 08:09
Prepending T3 orchestration instructions to the first user message meant
the message no longer started with "/", so pi never expanded slash
commands (extension commands, prompt templates, skills) on a thread's
first turn. Found live: /t3-demo reached the model as plain text.

The T3 MCP extension now delivers the same instructions through pi's
real system-prompt channel (a before_agent_start hook), and the adapter
sends the user's text untouched.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Comment thread apps/server/src/orchestration-v2/Adapters/PiAdapterV2.ts Outdated
Comment thread apps/server/src/orchestration-v2/Adapters/PiAdapterV2.ts
Comment thread apps/server/src/orchestration-v2/Adapters/PiAdapterV2.ts

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7ab3f16. Configure here.

Comment thread apps/server/src/orchestration-v2/Adapters/PiAdapterV2.ts
@juliusmarminge
juliusmarminge force-pushed the t3code/codex-turn-mapping branch from 519c42a to 4c55679 Compare August 17, 2026 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL 1,000+ changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants