Skip to content

04 — pi.dev runner (pi) #524

@gewenyu99

Description

@gewenyu99

🔄 Reorientation — 2026-06-19 (depends on #688, #522 · THE headline deliverable)

This is the goal: a feature-flagged pi backend on the #688 abstraction, built on pi.dev
(@earendil-works/pi-coding-agent). The earlier @openai/agents build was a wrong turn and is scrapped
(PRs #586/#587/#590 closed). Re-spec:


Epic: #520 · Behavior change: none (flag off) · Depends on: #522

Summary

Implement the pi backend on pi.dev (@earendil-works/pi-coding-agent) — a Claude-Code-style coding
agent that owns its own tool loop and ships Read/Write/Edit/Bash. It speaks the PostHog gateway directly via
a registered anthropic-messages provider, runs the same commandments + skills as anthropic, and streams
onto the shared TUI bridge. Selected at wizard-runner=pi.

Scope

  • Deps: @earendil-works/pi-coding-agent, @earendil-works/pi-ai. No @openai/agents, no aisdk adapter.
  • Gateway providerregisterProvider(name, { baseUrl: getLlmGatewayUrlFromHost(host), apiKey: <posthog token>, api: 'anthropic-messages', headers: <Bedrock-fallback + wizard metadata/flags> }) (reuse 02 — Shared runner contract + adapters (gateway, MCP, prompt, tools, stream→TUI) #522's header builder). Model via getModel(provider, id) from @earendil-works/pi-ai, same id as the anthropic backend for a clean A/B.
  • SessioncreateAgentSession({ model, resourceLoader: new DefaultResourceLoader({ systemPromptOverride: <commandments> }), customTools, cwd: <install dir>, sessionManager: <in-memory> }); run via session.prompt(prompt).
  • Stream → TUI — map session.subscribe events (message_update text/thinking deltas, tool_execution_start|update|end, turn_*, agent_end) onto the 02 — Shared runner contract + adapters (gateway, MCP, prompt, tools, stream→TUI) #522 stream→TUI bridge (status, todos, dashboard/notebook markers) and the run log.
  • Errors — map terminal/loop errors to AgentErrorType; honor [ABORT]. Degrade gracefully when a dependency (e.g. local MCP) is unavailable.

Acceptance criteria

  • A text-only and a tool-using run complete end-to-end against the gateway through the registered provider.
  • Streaming + markers + todos reach the TUI.
  • Flag stays 0% pi; anthropic unaffected.
  • Unit tests for backend wiring (mocked provider) incl. the abort/stop guard.

Open questions

Files

  • src/lib/agent/runner/backends/pi/

Notes

Skills load via Pi's native file-based discovery — drop the resolved framework SKILL.md into a Pi-scanned
dir (.pi/skills / .agents/skills) before the run (progressive disclosure, the context-mill model). Wizard
capabilities (env-file ops, wizard_ask, PostHog data ops) ride as defineTool custom tools. Per-tool
gating (canUseTool + YARA) is #525.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions