pi-acp-provider2.0.0
Pi agent provider extension that delegates execution to any Agent Client Protocol (ACP) agent, such as GitHub Copilot CLI or Gemini CLI.
Untested on omp
This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.
Reports 0
No reports yet.
Readme
pi-acp-provider
A Pi provider extension that drives any Agent Client Protocol (ACP) agent, such as GitHub Copilot CLI, Gemini CLI, or any other command that speaks ACP over stdio.
┌────────────────────────────────────────────────────────┐
│ Pi TUI │
│ (Input bar, Stream Renderer, Status line) │
└───────────────────────────▲────────────────────────────┘
│ Pi AssistantMessageEventStream
┌───────────────────────────▼────────────────────────────┐
│ ACP Provider Extension │
│ streamSimple() → ACP client (NDJSON RPC) │
└───────────────────────────┼────────────────────────────┘
│ stdio (stdin / stdout), one process per agent
┌───────────────────────────▼────────────────────────────┐
│ ACP agent (e.g. `copilot --acp`, `gemini …`) │
│ (Autonomous agent, file tools, bash, LSP) │
└────────────────────────────────────────────────────────┘
The ACP agent runs the loop, the same way Zed uses ACP agents: it plans, edits files, runs commands, and streams progress back. Pi still provides what it provides to any model: its tools (served to the agent over MCP and run by Pi, with Pi's approvals, hooks and tool rows), its system prompt (context files, skills, extension sections), its message queue (steering and follow-ups), and its history (resumed and forked sessions, model switches).
Install
pi install npm:pi-acp-provider
Or from git: pi install git:github.com/R-Dson/pi-acp-provider.
To try it for one session without installing: pi -e npm:pi-acp-provider.
Configuration
Declare agents under acp.agents in ~/.pi/agent/settings.json (or
$PI_CODING_AGENT_DIR/settings.json). Each key becomes a model:
/model acp/<key>.
{
"acp": {
"autoApproveTools": true,
"agents": {
"copilot": { "name": "GitHub Copilot", "command": "copilot", "args": ["--acp"] },
"gemini": { "name": "Gemini", "command": "gemini", "args": ["--experimental-acp"] }
}
}
}
The commands above are examples. Check each agent's documentation for the flag that starts its ACP mode. With no agents configured, Pi shows a warning at startup and the provider has no models.
Models and thinking level
Models are discovered automatically. When Pi refreshes its model list (at
interactive startup and whenever /model opens), each agent is started and an
ACP session is opened to read the models it offers. They show up as
acp/<key>/<model id>, e.g. /model acp/copilot/gpt-5. acp/<key> keeps the
agent's own default. The list is saved, so pi -p and offline startups use the
last one found.
Both the ACP configOptions model selector and the older models /
session/set_model API are supported. If the agent exposes a thought_level
option, Pi's thinking level (shift+tab, --thinking) is applied to it; levels
the agent doesn't offer are hidden. Discovery never triggers authMethod
sign-in; that waits for the first prompt.
Each model's context window starts at 128K. Once the agent reports its real
window (size in an ACP usage_update) during a turn, the next model list
refresh publishes that value for the model that ran the turn, and it is saved
with the list. A contextWindow in a ~/.pi/agent/models.json
modelOverrides entry (for example
{ "providers": { "acp": { "modelOverrides": { "claude": { "contextWindow": 1000000 } } } } }
for acp/claude) always wins over both, since Pi applies it on top of the
provider's list.
Agent slash commands
Each agent registers a Pi command named after its key. /<key> <command>
runs a slash command the agent advertises over ACP (available_commands_update),
e.g. /copilot context or /copilot session info for Copilot CLI. Arguments
autocomplete from the agent's current list. /<key> alone lists the commands.
Running one switches to that agent if another model is active, then sends
/<command> as the prompt, which is how ACP agents expect commands.
Per-agent keys:
| Key | Required | Meaning |
|---|---|---|
command |
yes | Executable, spawned in the session cwd. |
args |
no | Arguments, e.g. the agent's ACP flag. Default []. |
name |
no | Display name in the model picker and messages. Default: the key. |
env |
no | Extra environment variables for the agent process. |
authMethod |
no | ACP authenticate method id to use when the agent reports auth_required (see Auth below). |
piTools |
no | both (Pi's tools next to the agent's own), pi (Pi's tools only; needs ownToolsOffMeta), or off. |
mcpTransport |
no | stdio or http for Pi's MCP server. http falls back to stdio when the agent does not advertise it. |
systemPrompt |
no | prompt (in front of the first prompt), session (ACP systemPrompt on session/new; falls back to prompt), or off. |
sessionMeta |
no | Extra _meta for session/new, merged over the preset. |
ownToolsOffMeta |
no | _meta that turns off the agent's own tools. Live sessions merge it in only with piTools: "pi"; isolated requests (summaries) always send it, merged over sessionMeta, whatever piTools says. |
Defaults and presets
Agents start from what every ACP agent supports (the level of Antigravity
and Mistral Vibe): piTools: "both", mcpTransport: "stdio",
systemPrompt: "prompt". Two commands get a preset; any key in settings wins
(env, sessionMeta and ownToolsOffMeta merge key by key):
| Command | Preset |
|---|---|
claude-agent-acp |
piTools: "pi" (tools: [] and strictMcpConfig via _meta.claudeCode.options), mcpTransport: "http", systemPrompt: "session", allowedTools: ["mcp__pi"], env ENABLE_CLAUDEAI_MCP_SERVERS=0 (no claude.ai cloud connectors) and DISABLE_AUTO_COMPACT=1 (Pi owns compaction; also stops the adapter's idle compaction) |
codex-acp |
piTools: "both", mcpTransport: "http", systemPrompt: "session" |
Global keys:
| Key | Env override | Default | Meaning |
|---|---|---|---|
autoApproveTools |
ACP_AUTO_APPROVE |
true |
When false, each permission request opens a select dialog (TUI/RPC) or is denied (print/JSON mode). |
handshakeTimeoutMs |
30000 |
Milliseconds to wait for initialize, session/new, and model or thinking-level changes. |
|
nativeTools |
ACP_NATIVE_TOOLS |
true |
Show agent tool calls as native Pi tool rows. false restores the inline text notices. |
ACP_DEBUG=1 |
off | Wire diagnostics on stderr. |
Behavior
- Lifecycle: each agent's process spawns lazily on first use: model
discovery (see Models and thinking level) or, when discovery has not run,
the first prompt. It stays alive across prompts, and is killed on session shutdown (
/new,/resume, quit, reload). Each agent runs in its own process group, so the whole tree (including tool subprocesses) is killed. Parent signal hooks, shared by all agents, cover exits without a session shutdown. A crashed agent is respawned with a fresh session on the next prompt; a request that was still being prepared when its agent exited fails with a request to send the message again, rather than reaching the respawned agent's sessions. Each NDJSON line from an agent's stdout is capped at 64 MiB by default; an oversized line closes the connection with an error so a runaway agent cannot exhaust host memory. Unexpected provider errors end the Pi stream with an error message instead of leaving the stream open. - Session mapping: one ACP session per Pi session per agent. Pi sessions
that stream at the same time in one Pi process (for example an extension's
side conversation) run in separate ACP sessions of the same agent process,
each with its own Pi tools, and neither cancels the other's turn; streams
to different agents never cancel each other either. A new request still
replaces the running turn of the same agent in the same Pi session. The
agent keeps the conversation on its side, so each prompt carries only what it has
not seen: every queued user message (with images, when the agent accepts
them), plus a
<conversation-history>transcript of any part of Pi's history the session missed (a resumed or forked Pi session, another model's turns, a branch the session did not see). When Pi's history no longer holds the session's latest reply, including an aborted one (tree navigation or a fork to an earlier point, even one that keeps an earlier reply), or a message the session received that a later request still held, or its first message changed (compaction), the provider starts a new ACP session from Pi's history. Pi does not say which messages it saved and which an extension added to one request only, so a message the session received counts only once a later request still holds it, and only if the session actually saw it (a transcript leaves out empty replies and cuts the oldest part when it exceeds 120,000 characters; if the newest message alone exceeds that cap, it is kept and truncated with an explicit truncation note rather than dropped). Messages are keyed by role, timestamp, and a SHA-256 digest of their content, so two distinct messages with the same timestamp and length stay distinct; only two messages with identical role, timestamp, and content collide. An edit that removes a message before a later request has held it is not noticed. - Pi's tools: Pi's current tools are served by an MCP server inside Pi,
as the server
pi(mcp__pi__<tool>in Claude Code). A call ends the Pi message with a real Pi tool call; Pi runs it and the result answers the agent's MCP request, and the ACP turn continues. A changed loadout is served on the nexttools/list(stdio connections also getlist_changed; HTTP connections do not, see Known limitations). The HTTP transport listens on 127.0.0.1 and the stdio relay uses a socket in a private temp directory. Each ACP session gets its own nonce (in the HTTP path, orPI_MCP_SESSIONfor the relay) and its own token, derived from the agent id and nonce with a per-process key and compared in constant time, so a token works only for the agent and session it was issued for (HTTP answers 401 otherwise). The HTTP server caps concurrent connections at- Request bodies and relay request lines are
capped at 8 MiB, and the relay's handshake line, which arrives before the
connection is authenticated, at 4 KiB. Past a cap, HTTP answers 413 and
closes the connection without reading the rest, and the relay connection is
closed before the line is parsed. A call is accepted only from the session
of the running turn, and an ended session's nonce is revoked: HTTP answers
403, its calls still running are cancelled, and its relay connections are
closed. Over HTTP,
initializeissues anMcp-Session-Id; a cancellation sent in a later POST of that MCP session reaches its call, andDELETEcancels the session's calls and ends it. Tools whose root schema usesanyOf,oneOf, orallOfare flattened into a single object schema so agents that reject top-level combinators still load them. This flattening is a lossy compatibility transform: nested combinators are not flattened and branch-level constraints (such asadditionalPropertiesorenum, or conflicting property definitions) can be dropped. Pi still validates every tool call against the original schema. A permission request for a Pi tool is approved without asking, since Pi applies its own approval when it runs the tool, but only when its structure shows it is one: it comes from the running turn's session, which holds a live MCP nonce, it names a tool call that the agent reported and has not reported finished, and every structured tool name present (ACPnameand Claude Code's_meta.claudeCode.toolName, on the request and on each report of the call) names one and the same tool Pi serves, such asmcp__pi__read. Titles, and how the call is shown in Pi, are never trusted. Every other request goes to the normal permission policy. If Pi's MCP server fails to start, an agent withpiTools: "pi"(theclaude-agent-acppreset) ends the turn with an error naming Pi's tool server instead of running with its built-in tools; apiTools: "both"agent goes on without Pi's tools. The next turn tries to start the server again, and a session opened without Pi's tools is then replaced by a new one that has them and first gets the conversation so far as a transcript.
- Request bodies and relay request lines are
capped at 8 MiB, and the relay's handshake line, which arrives before the
connection is authenticated, at 4 KiB. Past a cap, HTTP answers 413 and
closes the connection without reading the rest, and the relay connection is
closed before the line is parsed. A call is accepted only from the session
of the running turn, and an ended session's nonce is revoked: HTTP answers
403, its calls still running are cancelled, and its relay connections are
closed. Over HTTP,
- System prompt: Pi's system prompt goes to each ACP session once (see
systemPrompt), and a changed prompt is sent with the next prompt. - Queue and steering: a message Pi queues while the agent works reaches
the running turn with
_session/steeringwhen the agent advertises it (Claude Code, Codex). Otherwise it rides on the Pi tool result the agent is waiting for (its images as MCP image items), or, when none is pending, is sent as the next prompt once the running one ends. The running turn is not cancelled. A queued message counts as delivered only once the agent accepts the prompt that carries it. If that turn ends early (max_tokens, an abort, an error, a replaced session) or the agent rejects the prompt, the message goes with the next prompt instead, after a one-line note that it arrives late, and never as part of a<conversation-history>transcript. A message the agent rejected twice is dropped, and the error says so. A message no longer on Pi's active branch (after a fork or tree navigation) is not sent. The same holds for the rest of a prompt: a prompt the agent rejected, or one anonPayloadhook failed on, is sent in full again with the next request, its user messages as requests even when Pi keeps the failed reply. Content anonPayloadhook removes or rewrites counts as not sent, so it goes with the next prompt: a user message as a late user block, like a steer, and a removed<conversation-history>seed as a seed again. When a hook rebuilds blocks and two of them are identical, neither counts as sent. - Isolated requests: compaction and branch summaries (
cacheRetention: "none") run in a separate, throwaway agent process, so the live session is not touched. They get no Pi tools, and when the agent hasownToolsOffMeta(theclaude-agent-acppreset) it is sent on that session, merged oversessionMeta, whateverpiToolssays, so the summary cannot run the agent's own tools either. Agents without it get no_metaon that session, not evensessionMeta. Every permission request from an isolated session is answered with a reject option (reject_once, elsereject_always), orcancelledwhen it offers none, without asking the permission policy. Cache-warming requests are answered without contacting the agent. - Streaming: ACP v1
session/updatenotifications.agent_thought_chunkmaps to Pi thinking blocks andagent_message_chunkto text blocks.tool_callandtool_call_updatedrive tool rows (see Tool calls),usage_updaterecords the context window,config_option_updatetracks the session's model and thinking-level settings, andavailable_commands_updatefeeds the agent slash commands. Plans and mode changes are ignored. - Tool calls (
nativeTools, the default): each agent tool call is a native Pi tool row. The provider ends the Pi message at the call with atoolCallblock for theacp_toolmirror tool. Pi runs that tool, which waits for the agent's final report and returns its output or file diffs, and then calls the provider again, which continues the same ACP turn from buffered updates. One ACP turn therefore spans several Pi messages. The row shows the ACP kind, title and locations; the result shows diffs (Pi's diff renderer), text output with live partial updates, and failures. Expand the row to see the raw input and full output.acp_toolhides its own declaration, so no model is offered it; if it is not active (for example with a--toolsallowlist), or withnativeTools: false, tool calls render inline as⚙️ Executing [title]...and✓ title: <first line of output>. - Abort: Pi's abort signal (Ctrl+C) sends
session/canceland finalizes the message as aborted immediately. It answers any open permission prompt withcancelledand leaves the session usable. The next prompt waits (up to 5 s) for the agent to confirm the cancellation; until then the cancelled prompt's updates are dropped and its permission requests answeredcancelled, so they can't leak into the next prompt. If the agent does not confirm in time, the provider gives up on that session: it ends it, revokes its MCP nonce, and sends the next prompt on a new session, which first gets the conversation so far as a transcript. The old session's later updates, permission requests and Pi tool calls are refused. If this happens twice in a row, or the new session fails to open, the agent process is restarted instead. - Permissions:
session/request_permissionis auto-approved by default (allow_once, neverallow_always). SetautoApproveTools: falseto get an interactive select dialog that names the asking agent. Isolated summary requests never get a permission granted (see Isolated requests). - Auth: when an agent answers
session/newwith ACPauth_required(code -32000), the provider callsauthenticatewith the agent's configuredauthMethodand retries once. Without one, the error lists the auth methods the agent advertised ininitialize, so you can sign in with the agent's own CLI or pick a method. A missing command reports a not-found hint naming the agent. The provider registers as ambient-auth so/modelselection never blocks. - Usage: token counts come from the
usageof thesession/promptresult when the agent reports it (unstable ACP field), summed over the ACP turn and recorded on its last Pi message. Cost is zero.
Known limitations
- History the agent missed is sent as a plain-text transcript, not as native records: thinking, images and full tool outputs are left out or clipped.
- How an agent titles calls to Pi's MCP server is matched by pattern (the four
agents above were checked). An unrecognized title is shown as an extra
acp_toolrow next to Pi's own row for the same call. - With
autoApproveTools: false, an agent that asks permission for a Pi tool without a structured tool name, or before it reports the tool call, gets a second prompt from the policy on top of Pi's own approval. - Agents may time out long MCP calls on their side (for example while a Pi tool waits on the user). Claude Code's limit is effectively unbounded; other agents were not measured.
- No ACP client capabilities (
fs,terminal) are offered, so agents use their own file and terminal tools. Other agent→client requests get method-not-found. - Agents connected to Pi's MCP server over HTTP (
mcpTransport: "http", theclaude-agent-acpandcodex-acppresets) are not told when Pi's tool loadout changes (for example when an extension adds or removes a tool). The server offers no server-to-client stream, so only stdio connections getnotifications/tools/list_changed. An HTTP agent sees the new tools only when it lists them again, which an agent may do only once per session. Start a new session with/newafter changing the loadout. Calls to a tool that is no longer served fail with "Pi has no tool named …". - Agents without an
ownToolsOffMetaswitch keep their built-in tools in isolated summary requests. This includes Codex (codex-acp), which has no documented ACP setting that turns them off. Their permission requests there are rejected, but a tool the agent runs without asking permission is not stopped. - A context window the agent reports does not change the running Pi
session: Pi reads the window from the selected model, which it replaces
only when a model is selected or the provider is registered. The reported
window applies after the next model list refresh (opening
/model, or the next startup), once the model is selected again or Pi reloads. - Of Pi's stream hooks,
onPayloadandonProviderStreamEventare honored.onResponseis HTTP-specific and not called.
Development
Running the test suite requires Node.js 22.6 or newer because npm test runs
the TypeScript test files directly with --experimental-strip-types.
npm run typecheck # strict tsc, no emit
npm test # node:test suite against a scripted fake ACP agent (Node 22.6+)
The fake agent (test/fake-agent.mjs) speaks ACP v1 wire shapes and covers
streaming, permissions (string request ids), cancellation, crashes, auth
(auth_required plus authenticate), refusals, and split NDJSON frames. No
real agent or network is needed.
Layout
src/acp.ts: ACP v1 / JSON-RPC wire types and boundary parserssrc/acp-client.ts: child process, NDJSON transport, handshake, sessions, authsrc/provider.ts: the PiProvider: agent clients, session opening, turn dispatch and steering, and isolated requestssrc/models.ts: model discovery, model ids, context windows, and model and thinking-level selectionsrc/live-turn.ts: an ACP turn that spans several Pi messages, and the translation of its updates into Pi eventssrc/message-writer.ts: writes the Pi assistant message, usage, and how a turn endssrc/session-sync.ts: what each ACP session has seen, divergence checks, pending steers, and prompt buildingsrc/pi-tool-bridge.ts: Pi tool calls from the MCP server, per-session tool wiring and nonces, and Pi tool permission checkssrc/native-tools.ts: theacp_toolmirror tool that shows agent tool calls as Pi tool rowssrc/config.ts: settings, env resolution, and agent presetssrc/mcp-server.ts,src/mcp-relay.mjs: Pi's MCP server (HTTP and stdio relay)src/transcript.ts: Pi messages to ACP prompt blocks and history transcriptssrc/index.ts: extension factory (pi.registerProvider, lifecycle wiring)