Skip to content
Source
Sign inSign up
pingdotgg/t3code

[codex] Add Pi provider integration #2831

ClosedAmbitiousRealism2025(GitHub profile, opens in a new tab)wants to merge 3 commits intomain fromrefs/pull/2831/headopened View on GitHub

Summary

Adds Pi as a selectable provider in T3 Code using Pi's local CLI/RPC integration rather than treating it as a generic API provider. The adapter discovers and uses the existing local Pi configuration, surfaces configured Pi models in the selector, supports Pi slash-command metadata in provider discovery, and routes prompts through Pi sessions.

Follow-up fixes in this branch also make Pi prompt timeouts activity-based for long tool-heavy turns and map Pi tool execution events into T3 provider runtime tool lifecycle events so the Work Log can show progress while Pi is using tools.

Implementation Notes

  • Adds Pi provider settings, driver metadata, provider registry wiring, and UI picker metadata.
  • Adds Pi RPC helpers for local model/config discovery, prompt execution, text delta streaming, and tool result extraction.
  • Adds a Pi provider adapter and text generation layer that use existing ~/.pi/agent configuration.
  • Keeps Pi-specific behavior isolated behind the existing provider adapter/runtime contracts.
  • Preserves existing provider behavior for Claude, Codex, OpenCode, Cursor, and ACP providers.

Validation

  • bun install
  • bun fmt
  • bun lint
  • bun typecheck
  • bun run test
  • bunx vitest run src/provider/Layers/PiRpc.test.ts
  • Local Pi RPC smoke against existing ~/.pi/agent config
  • Manual local T3 Code verification with Pi selectable, Pi models visible, basic Pi prompt completing, and Pi tool events observed during a bash-tool prompt

Notes / Risks

  • Pi is a CLI/TUI-backed provider integration, so maintainability depends on Pi RPC event compatibility.
  • Slash-command parity is documented in PI_PARITY.md; commands that are inherently Pi-native are surfaced/documented rather than reimplemented as separate T3 UI features.
  • Long Pi turns are bounded by idle timeout after activity, not by total wall-clock duration, to avoid killing healthy multi-tool Pi runs.

Note

Add Pi provider integration with session management, streaming, and text generation

  • Registers a new pi provider driver kind in contracts, settings, and the built-in driver registry, removing it from the "Coming soon" list in the settings UI.
  • Adds PiRpc.ts with utilities to invoke the Pi CLI as a child process and communicate via newline-delimited JSON RPC, supporting streaming events, abort signals, and per-activity timeouts.
  • Adds PiAdapter.ts implementing the full ProviderAdapterShape for Pi: session lifecycle, streaming assistant text and tool events, attachment handling, turn interruption, and in-memory session state.
  • Adds PiTextGeneration.ts for Pi-backed commit messages, PR content, branch names, and thread titles via the RPC prompt path.
  • Adds PiProvider.ts for provider status checks, model discovery via pi --version and Pi RPC inventory, and slash command surfacing.
  • Risk: Pi integration depends on an external binary resolved from PI_CODING_AGENT_DIR or ~/.pi/agent; misconfiguration or binary absence will surface as probe errors at status-check time.
📊 Macroscope summarized 9c1c57e. 17 files reviewed, 0 issues evaluated, 0 issues filtered, 0 comments posted

🗂️ Filtered Issues

No issues evaluated.

    1. Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro

      Run ID: 275c764f-0fd0-455c-b361-f827f608b4fc

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands and usage tips.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. @@ -0,0 +181,21 @@
      181+ reject(error);
      182+ };
      183+
      184+ const timeoutMs = input.timeoutMs ?? 120_000;
      185+ let timer: ReturnType<typeof setTimeout>;
      186+ const resetTimer = () => {
      187+ clearTimeout(timer);
      188+ // @effect-diagnostics-next-line globalTimers:off
      189+ timer = setTimeout(() => {
      190+ rejectOnce(new Error(`Timed out waiting for Pi RPC. Stderr: ${stderr.trim()}`));
      191+ }, timeoutMs);
      192+ };
      193+
      194+ // @effect-diagnostics-next-line globalTimers:off
      195+ timer = setTimeout(() => {
      196+ rejectOnce(new Error(`Timed out waiting for Pi RPC. Stderr: ${stderr.trim()}`));
      197+ }, timeoutMs);
      198+
      199+ input.signal?.addEventListener("abort", () => {
      200+ rejectOnce(new Error("Pi RPC request was aborted."));
      201+ });
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟢 Low Layers/PiRpc.ts:149

      When an already-aborted AbortSignal is passed, the abort listener is never triggered, so the function spawns the child process and runs to completion or timeout instead of immediately rejecting. Consider checking input.signal?.aborted before spawning and rejecting early if already aborted.

      +    if (input.signal?.aborted) {
      +      rejectOnce(new Error("Pi RPC request was aborted."));
      +      return;
      +    }
      +
           input.signal?.addEventListener("abort", () => {
             rejectOnce(new Error("Pi RPC request was aborted."));
           });
      🤖 Copy this AI Prompt to have your agent fix this:
      In file apps/server/src/provider/Layers/PiRpc.ts around lines 149-201:
      
      When an already-aborted `AbortSignal` is passed, the `abort` listener is never triggered, so the function spawns the child process and runs to completion or timeout instead of immediately rejecting. Consider checking `input.signal?.aborted` before spawning and rejecting early if already aborted.
      
      Evidence trail:
      apps/server/src/provider/Layers/PiRpc.ts lines 139-201 at REVIEWED_COMMIT: no `signal.aborted` check before `spawn()` on line 152; `addEventListener('abort', ...)` on line 199 won't fire for already-aborted signals per Node.js EventTarget spec. Node.js v22+ docs confirm `addEventListener` does not retroactively fire: https://nodejs.org/api/events.html (events.addAbortListener section).
      @@ -0,0 +265,21 @@
      265+ mimeType: attachment.mimeType,
      266+ };
      267+ },
      268+ catch: (cause) =>
      269+ new ProviderAdapterRequestError({
      270+ provider: PROVIDER,
      271+ method: "prompt",
      272+ detail: errorDetail(cause),
      273+ cause,
      274+ }),
      275+ });
      276+
      277+ const startSession: PiAdapterShape["startSession"] = (input) =>
      278+ Effect.gen(function* () {
      279+ if (input.provider !== undefined && input.provider !== PROVIDER) {
      280+ return yield* new ProviderAdapterValidationError({
      281+ provider: PROVIDER,
      282+ operation: "startSession",
      283+ issue: `Expected provider '${PROVIDER}' but received '${input.provider}'.`,
      284+ });
      285+ }
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium Layers/PiAdapter.ts:285

      When startSession replaces an existing session at lines 286-290, it aborts the old session and deletes it from sessions but never emits a session.exited event. This differs from stopSession which emits the event, so downstream consumers cannot track the lifecycle transition when sessions are replaced.

      🤖 Copy this AI Prompt to have your agent fix this:
      In file apps/server/src/provider/Layers/PiAdapter.ts around line 285:
      
      When `startSession` replaces an existing session at lines 286-290, it aborts the old session and deletes it from `sessions` but never emits a `session.exited` event. This differs from `stopSession` which emits the event, so downstream consumers cannot track the lifecycle transition when sessions are replaced.
      
      Evidence trail:
      apps/server/src/provider/Layers/PiAdapter.ts lines 286-290 (startSession replaces existing session without emitting event), lines 686-700 (stopSession emits session.exited event after similar abort+delete), lines 759-761 (streamEvents exposes runtimeEvents queue to consumers).

Sign in to join this conversation.