hapi icon indicating copy to clipboard operation
hapi copied to clipboard

feat: add Pi Coding Agent support

Open zhushanwen321 opened this issue 5 months ago • 0 comments

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 files
  • web/ — 6 Pi UI components + usePiModels.ts hook

28 modified existing files across all 4 packages. All changes follow one of three zero-impact patterns:

  1. Enum / Record extension — add 'pi' key, no existing entries changed
  2. If-else branch addition — === 'pi' appended at chain tail
  3. New method addition — callPiRpc<T> / callPiEndpoint<T>, no existing methods modified

Notable hub-side changes (affect all agents)

  • sessions.ts effort endpoint uses supportsEffort() from shared flavors instead of hardcoded flavor !== 'claude'
  • syncEngine.applySessionConfig surfaces actual CLI error messages instead of generic "Missing applied session config"
  • sessionCache normalizes { provider, modelId } model object to plain string for DB storage (prevents [object Object])

Notable shared changes

  • SessionModelRequestSchema accepts { provider, modelId } object form in addition to plain string
  • MetadataSchema adds optional piAvailableModels for offline model list fallback
  • PiModelSummary includes reasoning and thinkingLevelMap fields 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 typecheck all 3 packages pass, bun run build:web succeeds

zhushanwen321 avatar Jun 10 '26 06:06 zhushanwen321