@ccgv2/pi-acp 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Victor Software House
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,226 @@
1
+ # pi-acp
2
+
3
+ ACP ([Agent Client Protocol](https://agentclientprotocol.com/get-started/introduction)) adapter for [`pi`](https://github.com/badlogic/pi-mono/tree/main/packages/coding-agent) coding agent.
4
+
5
+ `pi-acp` embeds pi directly via the `@earendil-works/pi-coding-agent` SDK and exposes it as an ACP agent over stdio. Each ACP session owns one in-process `AgentSession`.
6
+
7
+ > **Fork notice:** This repository is based on
8
+ > [`victor-software-house/pi-acp`](https://github.com/victor-software-house/pi-acp).
9
+ > This fork adds per-session MCP runtime support, including stdio and Streamable HTTP
10
+ > servers, MCP tool discovery, and exposing those tools to pi as `customTools`.
11
+
12
+ ## Specs and decisions
13
+
14
+ - [`docs/prd/PRD-001-acp-v013-zed-alignment.md`](docs/prd/PRD-001-acp-v013-zed-alignment.md) — active release PRD (v0.5).
15
+ - [`docs/architecture/plan-acp-v013-zed-alignment.md`](docs/architecture/plan-acp-v013-zed-alignment.md) — phased implementation plan.
16
+ - [`docs/adr/`](docs/adr/) — architecture decision records (ADR-0001..ADR-0004).
17
+ - [`docs/architecture/acp-conformance.md`](docs/architecture/acp-conformance.md) — ACP conformance reference.
18
+ - [`docs/architecture/claude-acp-comparison.md`](docs/architecture/claude-acp-comparison.md) — reference comparison against `claude-agent-acp`.
19
+
20
+ ## Status
21
+
22
+ Active development. ACP compliance is improving steadily. Development is centered around [Zed](https://zed.dev) editor support; other ACP clients may have varying levels of compatibility.
23
+
24
+ ## Features
25
+
26
+ - Streams assistant output as ACP `agent_message_chunk`
27
+ - Streams thinking output as ACP `agent_thought_chunk`
28
+ - Maps pi tool execution to ACP `tool_call` / `tool_call_update`
29
+ - Descriptive tool titles (`Read src/index.ts`, `Run ls -la`, `Edit config.ts`)
30
+ - Tool call locations surfaced for follow-along features in clients like Zed
31
+ - For `edit` and `write`, emits ACP structured diffs (`oldText`/`newText`)
32
+ - Tool kinds: `read`, `edit`, `execute` (bash), `other`
33
+ - Session configuration via ACP `configOptions`
34
+ - Model selector (category: `model`)
35
+ - Thinking level selector (category: `thought_level`)
36
+ - Also advertises `modes` and `models` for backward compatibility
37
+ - `session/set_config_option` for changing model or thinking level
38
+ - `config_option_update` emitted when configuration changes
39
+ - Session persistence and lifecycle
40
+ - Multiple concurrent sessions supported
41
+ - pi manages sessions in `~/.pi/agent/sessions/...`
42
+ - `session/list` with title fallback from first user message
43
+ - `session/load` replays structured history (text, thinking, tool calls)
44
+ - `closeSession`, `resumeSession` (stable in ACP v0.12.2+)
45
+ - `unstable_forkSession` (preview)
46
+ - Sessions can be resumed in both `pi` CLI and ACP clients
47
+ - Per-session MCP servers
48
+ - stdio servers with command, arguments, session cwd, and explicit environment overrides
49
+ - Streamable HTTP servers over HTTPS or loopback HTTP
50
+ - MCP tools are exposed to pi as namespaced `customTools`
51
+ - Atomic startup rollback, bounded stderr diagnostics, cancellation, and awaited cleanup
52
+ - Usage and cost tracking
53
+ - `usage_update` emitted after each agent turn with context size and cost
54
+ - `PromptResponse.usage` includes per-turn token counts
55
+ - Slash commands
56
+ - File-based prompt templates from `~/.pi/agent/prompts/` and `<cwd>/.pi/prompts/`
57
+ - Extension commands from pi extensions
58
+ - Skill commands (appear as `/skill:skill-name`)
59
+ - Built-in adapter commands (see below)
60
+ - Authentication via Terminal Auth (ACP Registry support)
61
+ - Startup info block with pi version and context (configurable via `quietStartup` setting)
62
+
63
+ ## Prerequisites
64
+
65
+ - Node.js 24+ (hard requirement, matches pi runtime)
66
+ - Configure `pi` for your model providers/API keys
67
+
68
+ ## Install
69
+
70
+ ### ACP Registry (Zed)
71
+
72
+ Launch the registry with `zed: acp registry` and select `pi ACP`:
73
+
74
+ ```json
75
+ "agent_servers": {
76
+ "pi-acp": {
77
+ "type": "registry"
78
+ }
79
+ }
80
+ ```
81
+
82
+ ### npx (no global install)
83
+
84
+ ```json
85
+ "agent_servers": {
86
+ "pi": {
87
+ "type": "custom",
88
+ "command": "npx",
89
+ "args": ["-y", "@ccgv2/pi-acp"],
90
+ "env": {}
91
+ }
92
+ }
93
+ ```
94
+
95
+ ### Global install
96
+
97
+ ```bash
98
+ npm install -g @ccgv2/pi-acp
99
+ ```
100
+
101
+ ```json
102
+ "agent_servers": {
103
+ "pi": {
104
+ "type": "custom",
105
+ "command": "pi-acp",
106
+ "args": [],
107
+ "env": {}
108
+ }
109
+ }
110
+ ```
111
+
112
+ ### From source
113
+
114
+ ```bash
115
+ npm install
116
+ npm run build
117
+ ```
118
+
119
+ ```json
120
+ "agent_servers": {
121
+ "pi": {
122
+ "type": "custom",
123
+ "command": "node",
124
+ "args": ["/path/to/pi-acp/dist/index.js"],
125
+ "env": {}
126
+ }
127
+ }
128
+ ```
129
+
130
+ ## Built-in commands
131
+
132
+ - `/compact [instructions...]` -- compact session context
133
+ - `/autocompact on|off|toggle` -- toggle automatic compaction
134
+ - `/export` -- export session to HTML
135
+ - `/session` -- show session stats (tokens, messages, cost)
136
+ - `/name <name>` -- set session display name
137
+ - `/steering all|one-at-a-time` -- set steering message delivery mode
138
+ - `/follow-up all|one-at-a-time` -- set follow-up message delivery mode
139
+ - `/changelog` -- show pi changelog
140
+
141
+ ## Authentication
142
+
143
+ Terminal Auth for the [ACP Registry](https://agentclientprotocol.com/get-started/registry):
144
+
145
+ ```bash
146
+ pi-acp --terminal-login
147
+ ```
148
+
149
+ Zed shows an Authenticate banner that launches this automatically.
150
+
151
+ ## Development
152
+
153
+ ```bash
154
+ npm install
155
+ npm run dev # run from src
156
+ npm run build # tsdown -> dist/index.mjs
157
+ npm run typecheck # tsc --noEmit
158
+ npm run lint # biome + oxlint
159
+ npm test # Vitest
160
+ ```
161
+
162
+ Project layout:
163
+
164
+ ```
165
+ src/
166
+ index.ts # stdio entry point
167
+ env.d.ts # ProcessEnv augmentation
168
+ acp/
169
+ agent.ts # PiAcpAgent (ACP Agent interface)
170
+ session.ts # PiAcpSession (wraps AgentSession, translates events)
171
+ auth.ts # AuthMethod builder
172
+ auth-required.ts # auth error detection
173
+ pi-settings.ts # settings reader (Zod schema)
174
+ translate/
175
+ pi-messages.ts # pi message text extraction
176
+ pi-tools.ts # pi tool result text extraction (Zod schema)
177
+ prompt.ts # ACP ContentBlock -> pi message
178
+ pi-auth/
179
+ status.ts # auth detection (Zod schema)
180
+ test/
181
+ helpers/fakes.ts # test doubles
182
+ unit/ # unit tests
183
+ component/ # integration tests
184
+ ```
185
+
186
+ ## Limitations
187
+
188
+ ### MCP behavior
189
+
190
+ - stdio and Streamable HTTP transports are supported. Legacy SSE and unstable ACP-routed MCP transports are rejected.
191
+ - Remote plaintext HTTP is rejected; `http://` is accepted only for `localhost`, `127.0.0.1`, and `::1`.
192
+ - stdio processes inherit only the MCP SDK safe environment allowlist plus explicit ACP `env` entries.
193
+ - Each ACP session owns its MCP connections. Startup is atomic and `session/close` waits for cleanup.
194
+ - `session/load` and `session/fork` rebuild MCP from the request. `session/resume` reuses a live runtime when MCP is omitted and rejects an explicitly different configuration.
195
+
196
+ ### SHOULD-level gaps
197
+
198
+ - **`session/request_permission`** -- pi does not request permission from ACP clients before tool execution.
199
+
200
+ ### Not implemented (MAY / client capabilities)
201
+
202
+ - **`agent_plan`** -- plan updates not emitted before tool execution. pi has no equivalent planning surface.
203
+ - **ACP filesystem delegation** (`fs/read_text_file`, `fs/write_text_file`) -- pi reads/writes locally. Not advertised.
204
+ - **ACP terminal delegation** (`terminal/*`) -- pi executes commands locally. Not advertised.
205
+
206
+ ### Design decisions
207
+
208
+ - pi does not have real session modes (ask/architect/code). The `modes` field exposes thinking levels for backward compatibility with clients that do not support `configOptions`.
209
+ - `configOptions` is the preferred configuration mechanism. Zed uses it exclusively when present.
210
+ - pi-acp uses direct filesystem access rather than delegating reads/writes to the ACP client. This means pi reads on-disk file versions, not unsaved editor buffers.
211
+
212
+ See [docs/architecture/acp-conformance.md](docs/architecture/acp-conformance.md) for detailed conformance status.
213
+
214
+ ## Release
215
+
216
+ Releases are automated via [semantic-release](https://semantic-release.gitbook.io/) on pushes to `main`. The pipeline runs typecheck, lint, tests, and `npm pack --dry-run` before publishing. npm trusted publishing (OIDC) is used -- no long-lived npm tokens.
217
+
218
+ Commit messages must follow [Conventional Commits](https://www.conventionalcommits.org/). Commitlint enforces this locally via lefthook and in CI.
219
+
220
+ ## License
221
+
222
+ MIT (see [LICENSE](LICENSE)).
223
+
224
+ ---
225
+
226
+ Inspired by [svkozak/pi-acp](https://github.com/svkozak/pi-acp).