@buihongduc132/pi-acp-agents 0.3.1

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.
Files changed (43) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/LICENSE +21 -0
  3. package/README.md +359 -0
  4. package/index.ts +1521 -0
  5. package/package.json +103 -0
  6. package/skills/pi-acp-agents/SKILL.md +112 -0
  7. package/src/acp-widget.ts +379 -0
  8. package/src/adapter-factory.ts +55 -0
  9. package/src/adapters/acpx.ts +215 -0
  10. package/src/adapters/base.ts +117 -0
  11. package/src/adapters/codex.ts +77 -0
  12. package/src/adapters/custom.ts +14 -0
  13. package/src/adapters/gemini.ts +66 -0
  14. package/src/adapters/opencode.ts +101 -0
  15. package/src/config/config.ts +312 -0
  16. package/src/config/types.ts +203 -0
  17. package/src/coordination/alias-resolver.ts +208 -0
  18. package/src/coordination/coordinator.ts +266 -0
  19. package/src/coordination/worker-dispatcher.ts +191 -0
  20. package/src/core/async-executor.ts +149 -0
  21. package/src/core/circuit-breaker.ts +254 -0
  22. package/src/core/client.ts +661 -0
  23. package/src/core/health-monitor.ts +200 -0
  24. package/src/core/protocol-validator.ts +259 -0
  25. package/src/core/session-lifecycle.ts +46 -0
  26. package/src/core/session-manager.ts +64 -0
  27. package/src/extension-safety.ts +200 -0
  28. package/src/logger.ts +92 -0
  29. package/src/management/event-log.ts +31 -0
  30. package/src/management/governance-store.ts +123 -0
  31. package/src/management/heartbeat-parser.ts +92 -0
  32. package/src/management/mailbox-manager.ts +95 -0
  33. package/src/management/runtime-paths.ts +34 -0
  34. package/src/management/safe-mkdir.ts +78 -0
  35. package/src/management/session-archive-store.ts +136 -0
  36. package/src/management/session-name-store.ts +88 -0
  37. package/src/management/task-store.ts +260 -0
  38. package/src/management/worker-store.ts +164 -0
  39. package/src/public-api.ts +72 -0
  40. package/src/settings/agent-config-tui.ts +456 -0
  41. package/src/settings/agents-command.ts +138 -0
  42. package/src/settings/config.ts +201 -0
  43. package/src/settings/configure-tui.ts +135 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,45 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.2.0] - 2025-05-05
9
+
10
+ ### Added
11
+
12
+ - Extracted as standalone repository from pi-plugins monorepo
13
+ - Production-grade package structure (files whitelist, engines, scripts)
14
+ - SKILL.md for pi skill discovery
15
+ - GitHub Actions CI workflow
16
+ - Comprehensive test suite (36+ tests)
17
+ - `acp_delegate` — short-lived task delegation
18
+ - `acp_broadcast` — parallel multi-agent broadcast
19
+ - `acp_compare` — structured response comparison
20
+ - TUI widget for session status display
21
+ - Circuit breaker resilience (closed/open/half-open)
22
+ - Background health monitor with stale session cleanup
23
+ - Busy-session mutex (concurrent prompt guard)
24
+ - Per-session JSON-RPC trace logging
25
+ - `/acp-config` slash command
26
+
27
+ ### Changed
28
+
29
+ - Package name: `@walodayeet/pi-acp-agents`
30
+ - Repository: standalone GitHub repo
31
+
32
+ ## [0.1.0] - 2025-05-04
33
+
34
+ ### Added
35
+
36
+ - Initial release within pi-plugins monorepo
37
+ - Core tools: `acp_prompt`, `acp_status`, `acp_session_new`
38
+ - Session management: `acp_session_load`, `acp_session_set_model`, `acp_session_set_mode`
39
+ - `acp_cancel` for ongoing prompt cancellation
40
+ - Gemini CLI adapter with auto-authentication
41
+ - Custom adapter for user-defined ACP commands
42
+ - Config file support at `~/.pi/acp-agents/config.json`
43
+
44
+ [0.2.0]: https://github.com/buihongduc132/pi-acp-agents/releases/tag/v0.2.0
45
+ [0.1.0]: https://github.com/buihongduc132/pi-acp-agents/releases/tag/v0.1.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 walodayeet
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,359 @@
1
+ # @buihongduc132/pi-acp-agents
2
+
3
+ > Multi-agent orchestration for pi — spawn, control, and coordinate ACP-compatible agents (Gemini CLI, Claude, Codex, etc.) as first-class tools within the pi coding agent.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@buihongduc132/pi-acp-agents.svg)](https://www.npmjs.com/package/@buihongduc132/pi-acp-agents)
6
+ [![CI](https://github.com/buihongduc132/pi-acp-agents/actions/workflows/ci.yml/badge.svg)](https://github.com/buihongduc132/pi-acp-agents/actions/workflows/ci.yml)
7
+ [![license](https://img.shields.io/npm/l/@buihongduc132/pi-acp-agents.svg)](https://github.com/buihongduc132/pi-acp-agents/blob/main/LICENSE)
8
+
9
+ ---
10
+
11
+ ## Features
12
+
13
+ - Registers 10 pi tools for ACP agent management
14
+ - Manages session lifecycle (create, load, set model/mode, cancel, dispose)
15
+ - Provides multi-agent coordination (delegate, broadcast, compare)
16
+ - Resilient by default: circuit breaker, stall timeout, health polling
17
+ - TUI widget for real-time session status
18
+ - Adapter pattern: one config format for any ACP agent
19
+
20
+ ---
21
+
22
+ ## Installation
23
+
24
+ ### For Humans
25
+
26
+ ```bash
27
+ npm install @buihongduc132/pi-acp-agents
28
+ ```
29
+
30
+ ### For AI Agents
31
+
32
+ Add to `~/.pi/agent/settings.json`:
33
+
34
+ ```json
35
+ {
36
+ "packages": ["npm:@buihongduc132/pi-acp-agents"]
37
+ }
38
+ ```
39
+
40
+ Or install via pi CLI:
41
+
42
+ ### Humans
43
+
44
+ ```bash
45
+ pi install npm:@buihongduc132/pi-acp-agents
46
+ ```
47
+
48
+ Or with npm directly:
49
+
50
+ ```bash
51
+ npm install @buihongduc132/pi-acp-agents
52
+ ```
53
+
54
+ ### AI Agents (pip install)
55
+
56
+ ```
57
+ pi install npm:@buihongduc132/pi-acp-agents
58
+ ```
59
+
60
+ ### Git-sourced for pi
61
+
62
+ Add to `~/.pi/agent/settings.json`:
63
+
64
+ ```json
65
+ {
66
+ "gitPackages": [
67
+ { "url": "https://github.com/buihongduc132/pi-acp-agents.git" }
68
+ ]
69
+ }
70
+ ```
71
+
72
+ Or clone and link locally:
73
+
74
+ ```bash
75
+ git clone https://github.com/buihongduc132/pi-acp-agents.git
76
+ cd pi-acp-agents && npm install
77
+ ```
78
+
79
+ Then reference the local path in `settings.json`:
80
+
81
+ ```json
82
+ {
83
+ "packages": ["/path/to/pi-acp-agents"]
84
+ }
85
+ ```
86
+ ```
87
+
88
+ ## Quick Start
89
+
90
+ 1. Ensure an ACP agent is installed (e.g., Gemini CLI):
91
+
92
+ ```bash
93
+ gemini --version
94
+ gemini # first run to authenticate
95
+ ```
96
+
97
+ 2. Configure (optional — defaults to gemini):
98
+
99
+ ```bash
100
+ mkdir -p ~/.pi/acp-agents
101
+ cat > ~/.pi/acp-agents/config.json << 'EOF'
102
+ {
103
+ "agent_servers": {
104
+ "gemini": {
105
+ "command": "gemini",
106
+ "args": ["--acp"],
107
+ "default_model": "gemini-2.5-pro"
108
+ }
109
+ },
110
+ "defaultAgent": "gemini"
111
+ }
112
+ EOF
113
+ ```
114
+
115
+ 3. Use in pi:
116
+ ```
117
+ Use the acp_prompt tool to ask gemini "What is the capital of France?"
118
+ ```
119
+
120
+ ---
121
+
122
+ ## Tools
123
+
124
+ ### Session Management (Level 1)
125
+
126
+ Friendly session names are globally unique across ACP sessions, immutable once assigned, persisted in the runtime directory, and remain resolvable after reload for both live and archived sessions.
127
+
128
+ | Tool | Description |
129
+ | ------------ | -------------------------------------------------------------- |
130
+ | `acp_prompt` | Send a prompt to an ACP agent, get the text response |
131
+ | `acp_status` | Show configured agents, active sessions, circuit breaker state |
132
+
133
+ ### Session Lifecycle (Level 2)
134
+
135
+ | Tool | Description |
136
+ | ----------------------- | ------------------------------------------------------ |
137
+ | `acp_session_new` | Create a new isolated session with an agent; optional immutable `session_name`, caller cannot choose fresh session IDs |
138
+ | `acp_session_load` | Load/resume an existing session by ID or friendly name, including archived auto-closed sessions |
139
+ | `acp_session_set_model` | Change the model for an active session by ID or friendly name |
140
+ | `acp_session_set_mode` | Change the mode (thinking level) for an active session by ID or friendly name |
141
+ | `acp_cancel` | Cancel an ongoing prompt by ID or friendly name |
142
+
143
+ ### Multi-Agent Coordination (Level 3)
144
+
145
+ | Tool | Description |
146
+ | --------------- | ---------------------------------------------------- |
147
+ | `acp_delegate` | Delegate a task (short-lived session, auto-disposed) |
148
+ | `acp_broadcast` | Send same prompt to multiple agents in parallel |
149
+ | `acp_compare` | Get responses from multiple agents and compare them |
150
+
151
+ **Commands:** `/acp` — ACP root command with session, prompt, delegate, broadcast, compare, task, message, plan, runtime groups
152
+
153
+ **Compatibility aliases:** `/acp-doctor`, `/acp-config`
154
+
155
+ ---
156
+
157
+ ## Architecture
158
+
159
+ ```
160
+ ┌─────────────────────────────────────────────────┐
161
+ │ pi agent │
162
+ │ │
163
+ │ acp_prompt ──┐ │
164
+ │ acp_status ──┤ │
165
+ │ acp_session ─┤──► AgentCoordinator ──┐ │
166
+ │ acp_cancel ──┤ │ │
167
+ │ acp_compare ─┘ ▼ │
168
+ │ AcpCircuitBreaker │
169
+ │ │ │
170
+ │ ┌────────┴────────┐ │
171
+ │ │ Adapter Factory │ │
172
+ │ └────┬───────┬────┘ │
173
+ │ GeminiAdapter │ │
174
+ │ CustomAdapter │
175
+ │ │ │
176
+ │ AcpClient (stdio) │
177
+ │ │ │
178
+ │ HealthMonitor ◄──────┤
179
+ │ SessionManager │
180
+ └─────────────────────────────────────────────────┘
181
+
182
+ ┌────────┴────────┐
183
+ │ ACP Agent (gemini│
184
+ │ --acp, claude, │
185
+ │ codex, custom) │
186
+ └─────────────────┘
187
+ ```
188
+
189
+ ### Patterns
190
+
191
+ | Pattern | Implementation |
192
+ | ------------------- | ----------------------------------------------------------- |
193
+ | **Adapter** (GoF) | `AcpAgentAdapter` → `GeminiAcpAdapter` / `CustomAcpAdapter` |
194
+ | **Factory** | `createAdapter()` — string dispatch |
195
+ | **Circuit Breaker** | Closed → Open → Half-Open with configurable thresholds |
196
+ | **Health Monitor** | Background polling with distinct 1-hour no-response and completed-idle auto-close |
197
+ | **Coordinator** | Multi-agent delegate/broadcast/compare |
198
+
199
+ ---
200
+
201
+ ## Resilience
202
+
203
+ | Feature | Default | Description |
204
+ | --------------- | ----------------- | ----------------------------------------------------------- |
205
+ | Circuit breaker | 3 failures → open | Auto-recovers after 60s in half-open state |
206
+ | Stall timeout | 1 hour | Per-operation timeout with SIGTERM→SIGKILL escalation |
207
+ | Health polling | 30s | Background monitor enforces separate no-response and completed-idle timers |
208
+ | Busy mutex | per-session | Prevents concurrent prompts on the same session |
209
+ | Process safety | SIGTERM→SIGKILL | Graceful process shutdown with escalation |
210
+ | EPIPE handling | stdin/stdout | Prevents crashes on broken pipes |
211
+ | Non-blocking | all paths | Errors return as tool error results, never unhandled throws |
212
+
213
+ ---
214
+
215
+ ## Configuration
216
+
217
+ Config file: `~/.pi/acp-agents/config.json`
218
+
219
+ ```json
220
+ {
221
+ "agent_servers": {
222
+ "gemini": {
223
+ "command": "gemini",
224
+ "args": ["--acp"],
225
+ "default_model": "gemini-2.5-pro"
226
+ },
227
+ "custom": {
228
+ "command": "/path/to/my-acp-agent",
229
+ "args": ["--mode", "acp"]
230
+ }
231
+ },
232
+ "defaultAgent": "gemini",
233
+ "staleTimeoutMs": 3600000,
234
+ "healthCheckIntervalMs": 30000,
235
+ "circuitBreakerMaxFailures": 3,
236
+ "circuitBreakerResetMs": 60000,
237
+ "stallTimeoutMs": 3600000
238
+ }
239
+ ```
240
+
241
+ ### Global config
242
+
243
+ | Field | Default | Description |
244
+ | --------------------------- | ----------------------- | ----------------------------------------- |
245
+ | `agent_servers` | `{ gemini: {...} }` | Map of agent name → config |
246
+ | `defaultAgent` | `"gemini"` | Agent used when not specified |
247
+ | `staleTimeoutMs` | `3600000` (1 hour) | Auto-close threshold for each separate lifecycle policy: stalled-no-response and completed-idle |
248
+ | `healthCheckIntervalMs` | `30000` (30s) | Background health polling interval |
249
+ | `circuitBreakerMaxFailures` | `3` | Consecutive failures before circuit opens |
250
+ | `circuitBreakerResetMs` | `60000` (60s) | Time before circuit half-opens |
251
+ | `stallTimeoutMs` | `3600000` (1 hour) | Per-operation timeout |
252
+ | `logsDir` | `~/.pi/acp-agents/logs` | Log directory |
253
+
254
+ ### Per-agent config
255
+
256
+ | Field | Required | Description |
257
+ | -------------- | -------- | ----------------------------- |
258
+ | `command` | **yes** | Executable to spawn |
259
+ | `args` | no | Arguments (e.g., `["--acp"]`) |
260
+ | `env` | no | Extra environment variables |
261
+ | `cwd` | no | Working directory override |
262
+ | `default_model` | no | Default model ID |
263
+
264
+ ---
265
+
266
+ ## Logs
267
+
268
+ Central logs: `~/.pi/acp-agents/logs/`
269
+
270
+ - `main.log` — general structured JSON log
271
+ - `session-{id}/trace.jsonl` — per-session ACP JSON-RPC traces
272
+
273
+ ---
274
+
275
+ ## Supported Agents
276
+
277
+ | Agent | Status | Config |
278
+ | --------------- | ------------------------- | ------------------------------------ |
279
+ | **Gemini CLI** | ✅ Built-in adapter | `command: "gemini", args: ["--acp"]` |
280
+ | **Claude Code** | 🔜 Planned | ACP mode pending upstream |
281
+ | **Codex** | 🔜 Planned | ACP mode pending upstream |
282
+ | **Custom** | ✅ Via `CustomAcpAdapter` | Any command speaking ACP over stdio |
283
+
284
+ ---
285
+
286
+ ## Roadmap
287
+
288
+ ### v0.2.x — Current (Foundation)
289
+
290
+ - [x] ACP stdio JSON-RPC client
291
+ - [x] Gemini CLI adapter with auto-auth
292
+ - [x] Session lifecycle (new, load, set model/mode, cancel)
293
+ - [x] Circuit breaker + health monitor
294
+ - [x] Multi-agent: delegate, broadcast, compare
295
+ - [x] TUI widget for session status
296
+ - [x] 148 unit + integration tests
297
+ - [x] CI/CD pipeline with provenance publishing
298
+
299
+ ### v0.3.x — Streaming & Auth
300
+
301
+ - [ ] **Streaming responses** — forward `agent_message_chunk` events to pi in real-time
302
+ - [ ] **Tool use forwarding** — expose ACP agent tool calls back to pi's tool registry
303
+ - [ ] **OAuth/token auth** — support API key and OAuth flows per-agent
304
+ - [ ] **Config hot-reload** — watch config file, reload without restart
305
+ - [ ] **Retry with backoff** — exponential backoff for transient failures
306
+ - [ ] Custom adapter smoke tests
307
+
308
+ ### v0.4.x — Persistence & Recovery
309
+
310
+ - [ ] **Session persistence** — save/restore sessions across pi restarts
311
+ - [ ] **Session sharing** — share ACP sessions between pi instances via file lock
312
+ - [x] **Checkpoint/resume** — archived runtime metadata reopens auto-closed ACP sessions by original session ID
313
+ - [ ] **Metrics export** — Prometheus-compatible metrics (session count, latency, error rate)
314
+
315
+ ### v0.5.x — Advanced Orchestration
316
+
317
+ - [ ] **Agent routing** — automatic agent selection based on task type
318
+ - [ ] **Ensemble mode** — run same prompt across N agents, merge via configurable strategy (vote, rank, consensus)
319
+ - [ ] **Chain-of-agents** — pipe output of one agent as input to next
320
+ - [ ] **Cost tracking** — per-agent, per-session token usage and cost estimation
321
+ - [ ] **Agent health dashboard** — web UI for monitoring all connected agents
322
+
323
+ ### v1.0.0 — Production
324
+
325
+ - [ ] **Stable API** — no breaking changes without major version bump
326
+ - [ ] **Full ACP spec compliance** — implement all optional ACP capabilities
327
+ - [ ] **Multi-platform support** — OpenClaw, Claude Code plugin, standalone MCP server
328
+ - [ ] **Comprehensive docs** — API reference, migration guides, examples
329
+
330
+ ---
331
+
332
+ ## Development
333
+
334
+ ```bash
335
+ npm install
336
+ npm test # run all tests
337
+ npm run test:ci # run with coverage
338
+ npm run typecheck # TypeScript validation
339
+ npm run publish:dry # verify package contents before publish
340
+ ```
341
+
342
+ ### Release process
343
+
344
+ ```bash
345
+ npm run release:patch # 0.2.0 → 0.2.1
346
+ npm run release:minor # 0.2.0 → 0.3.0
347
+ npm run release:beta # 0.2.0 → 0.2.1-beta.0
348
+ git push --follow-tags # triggers CI → auto-publish with provenance
349
+ ```
350
+
351
+ ---
352
+
353
+ ## License
354
+
355
+ MIT
356
+
357
+ ## Attribution
358
+
359
+ Maintained by [buihongduc132](https://github.com/buihongduc132). Forked from [walodayeet/pi-acp-agents](https://github.com/walodayeet/pi-acp-agents).