This repository implements an Agent Client Protocol (ACP) adapter for pi (@earendil-works/pi-coding-agent) without modifying pi.
- ACP side: JSON-RPC 2.0 over stdio using
@agentclientprotocol/sdk(TypeScript) - Pi side: spawn
pi --mode rpcand communicate via newline-delimited JSON over stdio
Pi RPC mode is effectively single-session, so the adapter maps:
session/new→ spawn a dedicatedpi --mode rpcprocesssession/prompt→ send{type:"prompt"}to that process and stream events back assession/updatesession/cancel→ send{type:"abort"}
Use @agentclientprotocol/sdk:
ndJsonStream(input, output)to speak ACP over stdionew AgentSideConnection((conn) => new PiAcpAgent(conn, config), stream)
- Do not implement ACP client-side FS/terminal delegation in MVP. Pi already reads/writes and executes locally.
- Ignore
mcpServersfor MVP (accept in params, store in session state). - Stream all pi assistant output as ACP
agent_message_chunkinitially. - Tool events: map pi tool execution events to ACP
tool_call/tool_call_update(as text content).
- Install deps:
npm install - Run in dev:
npm run dev - Build:
npm run build - Smoke test (stdio):
npm run smoke - Lint:
npm run lint - Test:
npm run test
Once the adapter runs, it should behave like an ACP agent on stdio.
Quick sanity test (example):
# Send initialize request via stdin (exact fields depend on ACP SDK version)
# echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":1}}' | node dist/index.js
For real validation, test with an ACP client (e.g. Zed external agent).
- Keep ACP protocol handling in
src/acp/*. - Keep pi RPC subprocess logic in
src/pi-rpc/*. - Prefer small translation functions (pi event → ACP session/update) with unit tests.
- Be strict about streaming and process cleanup (handle exit, drain stdout/stderr, timeouts).
- Avoid producing unnecessary comments! Use comments sparingly to explain non-obvious decisions, not to narrate code.
- Avoid using
anyin TypeScript; prefer explicit types and interfaces. Only useanywhen absolutely necessary (e.g. for untyped external data).
- After making code edits, run formatting before finishing the task. Use
npm run formatwhen it is safe to format the whole worktree; otherwise use the narrowest safe formatter command for the files you touched. - If formatting is skipped or fails, say so explicitly in the final response.
- DO NOT commit unless explicitly asked!
- Current ACP client is Zed
- Local ACP repo with protocol documentation and specs:
~/Dev/learning/agent-client-protocol - Local Zed repo
~/Dev/learning/zed/zed