feat: add Pi Coding Agent support
Summary
Closes #840
Add Pi Coding Agent as a first-class agent flavor. Pi has a built-in --mode rpc that speaks JSONL over stdin/stdout. The integration follows the same subprocess pattern as Codex — spawn agent process, communicate via stdio pipes, receive real-time event stream. No ACP dependency.
Feature Coverage
Core features
| Feature | Status | Key files |
|---|---|---|
| Register as agent flavor | ✅ | shared/modes.ts flavors.ts schemas.ts |
CLI command (hapi pi) |
✅ | cli/commands/pi.ts registry.ts |
| Session create / resume / kill | ✅ | cli/pi/session.ts loop.ts runPi.ts |
| Text messaging + streaming output | ✅ | piTransport.ts piMessageAccumulator.ts piEventConverter.ts |
| Abort generation | ✅ | loop.ts |
| Model switching | ✅ | runPi.ts — provider learned from get_state |
| Tool call display | ✅ | piEventConverter.ts |
| Dynamic model discovery | ✅ | CLI auto-discovery → hub callPiRpc → web usePiModels.ts → model dropdown grouped by provider |
| Thinking Level (6 levels) | ✅ | PiThinkingLevelPanel.tsx — auto-filters levels per model's capability |
| Permission mode (default / yolo) | ✅ | PiPermissionPanel.tsx |
| Dedicated Pi composer toolbar | ✅ | Two Pi-specific pill buttons in composer toolbar (model selector + thinking level) with dropdown panels (PiModelPanel.tsx + PiThinkingLevelPanel.tsx). PiPermissionPanel.tsx in settings popover |
| Web UI agent icon | ✅ | AgentFlavorIcon.tsx |
| Context budget bar | ✅ | modelConfig.ts — 200K window |
Extended features
| Feature | Status | Notes |
|---|---|---|
| Skills / slash commands | ✅ Full stack | CLI: get_commands → generic listSlashCommands → web autocomplete |
| Steer (mid-stream steering) | ✅ Transparent | User messages auto-routed as steer when Pi is streaming |
Not implemented (out of scope)
Follow-up, Queue modes, History replay, Compact, Fork, Clone, Switch session, Session stats, HTML export. Wireable via callPiRpc / callPiEndpoint generics when needed.
New vs Modified Files
21 new files:
cli/src/pi/— 8 source files + 5 test filesweb/— 6 Pi UI components +usePiModels.tshook
28 modified existing files across all 4 packages. All changes follow one of three zero-impact patterns:
- Enum / Record extension — add
'pi'key, no existing entries changed - If-else branch addition —
=== 'pi'appended at chain tail - New method addition —
callPiRpc<T>/callPiEndpoint<T>, no existing methods modified
Notable hub-side changes (affect all agents)
sessions.tseffort endpoint usessupportsEffort()from shared flavors instead of hardcodedflavor !== 'claude'syncEngine.applySessionConfigsurfaces actual CLI error messages instead of generic "Missing applied session config"sessionCachenormalizes{ provider, modelId }model object to plain string for DB storage (prevents[object Object])
Notable shared changes
SessionModelRequestSchemaaccepts{ provider, modelId }object form in addition to plain stringMetadataSchemaadds optionalpiAvailableModelsfor offline model list fallbackPiModelSummaryincludesreasoningandthinkingLevelMapfields for per-model thinking level filtering
Known Limitation
Pi's RPC mode has no tool permission approval mechanism — tools execute automatically. HAPI's "approve tool calls from phone" won't work for Pi. The permission selector offers default and yolo only.
Test Coverage
- Unit tests: 29 cases in
cli/src/pi/, all pass - E2E protocol tests: 15 cases against live Pi RPC, 12 pass
- Automated:
bun run typecheckall 3 packages pass,bun run build:websucceeds