pi-squad 0.1.0 → 0.4.14

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # pi-squad
2
2
 
3
- Multi-agent collaboration extension for [pi](https://github.com/badlogic/pi-mono). Decomposes complex tasks into subtasks, assigns specialist agents, manages dependencies, and runs them in parallel — with a live TUI widget, side panel, and full slash command interface.
3
+ Multi-agent collaboration extension for [pi](https://github.com/badlogic/pi-mono). Decomposes complex tasks into subtasks, assigns specialist agents, manages dependencies, runs them in parallel with automatic QA rework loops all with a live TUI widget, overlay panel, and slash commands.
4
4
 
5
5
  ## Install
6
6
 
@@ -12,7 +12,7 @@ pi install npm:pi-squad
12
12
  ln -sf /path/to/pi-squad/src ~/.pi/agent/extensions/squad
13
13
  ```
14
14
 
15
- Pi auto-discovers extensions on startup. No build step.
15
+ Pi auto-discovers extensions on startup. No build step required.
16
16
 
17
17
  ## Quick Start
18
18
 
@@ -22,7 +22,7 @@ Ask pi to do something complex. It calls the `squad` tool automatically:
22
22
  > Build a REST API with authentication, tests, and documentation
23
23
  ```
24
24
 
25
- Or be explicit:
25
+ Or be explicit with predefined tasks:
26
26
 
27
27
  ```
28
28
  > Use squad: goal="Build task API", tasks=[
@@ -34,33 +34,41 @@ Or be explicit:
34
34
 
35
35
  ### What Happens
36
36
 
37
- 1. Extension creates tasks, starts the scheduler
37
+ 1. Extension creates tasks and starts the scheduler
38
38
  2. A **live widget** appears above the editor showing task status
39
- 3. Agents spawn as separate pi processes, work in parallel where deps allow
40
- 4. When complete, pi reports the summary
39
+ 3. Agents spawn as separate pi processes, work in parallel where dependencies allow
40
+ 4. QA agents can trigger **automatic rework loops** when they find bugs
41
+ 5. When complete, pi reports the summary with costs
41
42
 
42
43
  ## User Interface
43
44
 
44
45
  ### Widget (above editor)
45
46
 
46
- Always visible when a squad is active. Updates every 2 seconds.
47
+ Always visible when a squad is active. Component-based, event-driven rendering — updates on every scheduler event with no polling.
47
48
 
48
49
  ```
49
- ⏳ squad Build task API 1/3 $0.58 3m12s ctrl+q panel · /squad
50
- ✓ api (backend) Created CRUD REST API with validation
51
- ⏳ tests (qa) → bash npm test
50
+ ⏳ squad Build task API 2/3 $0.58 3m12s ^q detail · /squad msg
51
+ ✓ api (backend) 2m12s Created CRUD REST API with validation
52
+ ⏳ tests (qa) 45s → bash npm test
52
53
  ◻ docs (docs) ← api
53
54
  ```
54
55
 
56
+ Features:
57
+ - Per-task elapsed time (warning color after 3 minutes)
58
+ - Live tool call preview for running tasks
59
+ - Stale detection — shows `⏳ idle` when agent has no output for 2+ minutes
60
+ - Responsive — caps visible tasks based on terminal height
61
+ - Completion duration for finished tasks
62
+
55
63
  ### Status Bar (footer)
56
64
 
57
65
  ```
58
- ⏳ squad 1/3 $0.58
66
+ ⏳ squad 2/3 $0.58
59
67
  ```
60
68
 
61
69
  ### Panel (Ctrl+Q)
62
70
 
63
- Side panel on wide screens, centered overlay on narrow screens. Press `Ctrl+Q` to toggle focus between the panel and the editor.
71
+ Centered overlay panel. Press `Ctrl+Q` to open/close.
64
72
 
65
73
  **Task list:**
66
74
  ```
@@ -72,9 +80,9 @@ Side panel on wide screens, centered overlay on narrow screens. Press `Ctrl+Q` t
72
80
  │ ── tests (live) ───────────────────── │
73
81
  │ → bash npm test │
74
82
  │ │
75
- 1/3 · $0.58 · 3m │
83
+ 2/3 · $0.58 · 3m │
76
84
  ├──────────────────────────────────────────────┤
77
- │ ↑↓ nav ⏎ msgs m send p pause ^q switch
85
+ │ ↑↓ nav ⏎ msgs m send p pause ^q close
78
86
  ╰──────────────────────────────────────────────╯
79
87
  ```
80
88
 
@@ -88,7 +96,7 @@ Side panel on wide screens, centered overlay on narrow screens. Press `Ctrl+Q` t
88
96
  │ 10:05 YOU │
89
97
  │ Also test edge cases for empty input │
90
98
  ├──────────────────────────────────────────────┤
91
- │ ↑↓ scroll m send esc back ^q switch
99
+ │ ↑↓ scroll m send esc back ^q close
92
100
  ╰──────────────────────────────────────────────╯
93
101
  ```
94
102
 
@@ -99,6 +107,8 @@ Side panel on wide screens, centered overlay on narrow screens. Press `Ctrl+Q` t
99
107
  | `/squad` or `/squad select` | Pick a squad to view (interactive selector) |
100
108
  | `/squad list` | List squads for current project |
101
109
  | `/squad all` | List all squads across all projects |
110
+ | `/squad agents` | List, view, edit, enable/disable agents |
111
+ | `/squad agents <name>` | Quick view of a specific agent |
102
112
  | `/squad msg [agent] text` | Send message to a running agent |
103
113
  | `/squad widget` | Toggle live widget |
104
114
  | `/squad panel` | Toggle overlay panel |
@@ -109,27 +119,81 @@ Side panel on wide screens, centered overlay on narrow screens. Press `Ctrl+Q` t
109
119
 
110
120
  | Key | Context | Action |
111
121
  |---|---|---|
112
- | `Ctrl+Q` | Main editor | Open/focus squad panel |
113
- | `Ctrl+Q` | Panel focused (wide) | Return focus to editor (panel stays visible) |
114
- | `Ctrl+Q` | Panel focused (narrow) | Hide panel |
115
- | `↑↓` | Panel | Navigate tasks / scroll messages |
122
+ | `Ctrl+Q` | Anywhere | Toggle squad panel overlay |
123
+ | `↑↓` or `jk` | Panel | Navigate tasks / scroll messages |
116
124
  | `Enter` | Panel task list | View task messages |
117
125
  | `Esc` | Panel message view | Back to task list |
118
126
  | `m` | Panel | Send message to selected task's agent |
119
127
  | `p` | Panel task list | Pause/resume task |
120
128
  | `x` | Panel task list | Cancel task |
121
- | `q` | Panel task list | Release focus / hide |
129
+ | `q` | Panel task list | Close panel |
122
130
 
123
131
  ## Tools (LLM-callable)
124
132
 
125
133
  | Tool | Description |
126
134
  |---|---|
127
135
  | `squad` | Start a squad (non-blocking, returns immediately) |
128
- | `squad_status` | Check progress, filtered by project |
136
+ | `squad_status` | Check progress, costs, task states |
129
137
  | `squad_message` | Send message to a running agent via `steer()` |
130
- | `squad_modify` | Add/remove/pause/resume/cancel tasks |
138
+ | `squad_modify` | Add/cancel/pause/resume tasks, or cancel/resume entire squad |
139
+
140
+ The main pi agent sees squad state in its system prompt automatically (`<squad_status>` block) and can relay messages, add tasks, or check status on your behalf.
141
+
142
+ ## QA Rework Loop
143
+
144
+ When a QA agent outputs `## Verdict: FAIL`, the scheduler automatically:
145
+
146
+ 1. **Parses** the failure details from QA output
147
+ 2. **Creates a rework task** for the original agent with QA feedback injected into its system prompt
148
+ 3. **Creates a retest task** for QA, blocked until the rework completes
149
+ 4. After fix, QA re-tests. If still failing, loops up to `maxRetries` (default: 2)
150
+ 5. If retry limit exceeded, **escalates** to the main agent for human decision
151
+
152
+ ### Example flow
153
+
154
+ ```
155
+ auth (backend) ✓
156
+ → qa-auth (qa) ✓ — found race condition bug
157
+ → auth-fix-1 (backend) ✓ — fixed it [auto-created]
158
+ → qa-auth-retest-1 (qa) ✓ — retested, found another issue
159
+ → auth-fix-2 (backend) ✓ — fixed again [auto-created]
160
+ → qa-auth-retest-2 (qa) ✓ — all tests pass ✓
161
+ ```
162
+
163
+ ### What the rework agent sees
164
+
165
+ The rework agent's system prompt includes:
166
+ - Original task output (what was built)
167
+ - QA feedback (what failed, with specific issues)
168
+ - Instructions to make targeted fixes, not rewrite everything
169
+
170
+ ### QA verdict format
171
+
172
+ QA agents should end their output with a structured verdict:
173
+
174
+ ```markdown
175
+ ## Verdict: PASS
176
+ All 42 tests passing. No issues found.
177
+ ```
131
178
 
132
- The main pi agent sees squad state in its system prompt automatically and can relay messages, add tasks, or check status on your behalf.
179
+ ```markdown
180
+ ## Verdict: FAIL
181
+
182
+ ## Issues
183
+ 1. **[src/auth.ts:45]** JWT expiry not enforced
184
+ - Expected: 401 for expired tokens
185
+ - Got: 200 (token accepted)
186
+ 2. **[src/routes.ts:23]** Missing rate limit on /login
187
+ ```
188
+
189
+ ### Configuration
190
+
191
+ ```
192
+ config: {
193
+ maxConcurrency: 3, // parallel agents
194
+ maxRetries: 2, // rework attempts before escalation (default: 2)
195
+ }
196
+ ```
133
197
 
134
198
  ## Sending Messages to Agents
135
199
 
@@ -141,30 +205,50 @@ Three ways:
141
205
  /squad msg backend Use postgres instead of SQLite
142
206
  ```
143
207
 
144
- 2. **`m` key** — press in the panel (task list or message view), opens input dialog
208
+ 2. **`m` key** — press in the panel, opens input dialog
145
209
 
146
210
  3. **Natural chat** — tell pi, it relays automatically
147
211
  ```
148
212
  > Tell the backend agent to use argon2 for password hashing
149
213
  ```
150
214
 
215
+ Messages are delivered in real-time via RPC `steer()` if the agent is running, or queued for delivery when the agent spawns.
216
+
151
217
  ## Agents
152
218
 
153
- 11 specialist agents are bundled. On first run, they're copied to `~/.pi/squad/agents/` for editing.
219
+ ### 11 Bundled Agents
154
220
 
155
- | Agent | Specialty |
156
- |---|---|
157
- | **planner** | Task breakdown and planning |
158
- | **fullstack** | General-purpose coding |
159
- | **architect** | System design, architecture |
160
- | **backend** | APIs, databases, server-side |
161
- | **frontend** | UI/UX, React, CSS |
162
- | **debugger** | Root cause analysis |
163
- | **qa** | Testing, verification |
164
- | **security** | Security audits |
165
- | **docs** | Technical writing |
166
- | **researcher** | Code exploration, analysis |
167
- | **devops** | CI/CD, infrastructure |
221
+ On first run, copied to `~/.pi/squad/agents/` for editing.
222
+
223
+ | Agent | Specialty | Tags |
224
+ |---|---|---|
225
+ | **planner** | Task breakdown and planning | planning, architecture |
226
+ | **fullstack** | General-purpose coding | general, coding |
227
+ | **architect** | System design, architecture | architecture, design |
228
+ | **backend** | APIs, databases, server-side | api, server, database |
229
+ | **frontend** | UI/UX, React, CSS | react, ui, css |
230
+ | **debugger** | Root cause analysis | debugging, bugs |
231
+ | **qa** | Testing, verification | testing, qa, e2e |
232
+ | **security** | Security audits | security, audit |
233
+ | **docs** | Technical writing | documentation, readme |
234
+ | **researcher** | Code exploration, analysis | research, analysis |
235
+ | **devops** | CI/CD, infrastructure | ci-cd, docker |
236
+
237
+ ### Agent Management
238
+
239
+ Use `/squad agents` for interactive management:
240
+
241
+ ```
242
+ /squad agents — list all, select to view/edit
243
+ /squad agents backend — quick view of specific agent
244
+ ```
245
+
246
+ Actions available per agent:
247
+ - **View details** — name, role, model, tools, tags, prompt, file path
248
+ - **Edit in editor** — opens the agent JSON file
249
+ - **Change model** — set a specific model or use default
250
+ - **Toggle tools** — restrict to specific tools or enable all
251
+ - **Enable/Disable** — disabled agents are hidden from the planner
168
252
 
169
253
  ### Custom Agents
170
254
 
@@ -178,66 +262,160 @@ Create a JSON file in `~/.pi/squad/agents/` (global) or `{project}/.pi/squad/age
178
262
  "model": "anthropic/claude-sonnet-4-20250514",
179
263
  "tools": null,
180
264
  "tags": ["ml", "pytorch", "data"],
181
- "prompt": "You are an ML engineer specializing in PyTorch..."
265
+ "prompt": "You are an ML engineer specializing in PyTorch...",
266
+ "disabled": false
182
267
  }
183
268
  ```
184
269
 
185
- Project-local agents override global agents with the same name.
270
+ - `model`: `null` = pi default. Override with any model ID your provider supports.
271
+ - `tools`: `null` = all tools. Array like `["bash", "read", "write", "edit"]` to restrict.
272
+ - `tags`: Used by the planner to match agents to tasks.
273
+ - `disabled`: `true` = hidden from planner, tasks assigned to this agent will fail.
274
+ - Project-local agents override global agents with the same name.
186
275
 
187
276
  ## How Agents Collaborate
188
277
 
189
- - **Dependencies** task B waits for task A before starting
190
- - **Chain context** — task A's output is injected into task B's system prompt
191
- - **@mentions** — agents write `@agentname message` to talk to each other in real time
192
- - **Human messages** — sent via panel, `/squad msg`, or the LLM's `squad_message` tool
193
- - **Shared knowledge** — decisions and findings tracked in `knowledge/*.jsonl`
278
+ ### Chain Context (primary)
194
279
 
195
- ## Data
280
+ When task A completes, its **full output** is injected into task B's system prompt as a `# Completed Dependencies` section. Downstream agents read what was built and extend it.
196
281
 
197
- All state lives in `~/.pi/squad/` (global). No database, no daemon, no external services.
282
+ ### Shared Filesystem
283
+
284
+ All agents work in the same project directory. Upstream agents create files, downstream agents read and modify them. Each agent is instructed to read files before writing to avoid conflicts.
285
+
286
+ ### Sibling Awareness
287
+
288
+ When agents run in parallel, each sees the other's status and modified files in their system prompt:
198
289
 
199
290
  ```
200
- ~/.pi/squad/
201
- ├── agents/*.json global agent definitions
202
- └── {squad-id}/
203
- ├── squad.json — metadata (goal, status, cwd, agents, config)
204
- ├── context.json — live state snapshot
205
- └── {task-id}/
206
- ├── task.json — task metadata + output
207
- └── messages.jsonl — conversation log
291
+ # Sibling Tasks
292
+ - template-engine [in_progress] fullstack Create HTML templates
293
+
294
+ ## Files Modified by Other Agents
295
+ **fullstack:** src/templateEngine.js, templates/post.html
296
+ ⚠️ Coordinate with the owning agent before editing files listed above.
208
297
  ```
209
298
 
210
- Each squad stores its project `cwd` in `squad.json`. The `/squad list` command filters by current project. `/squad all` shows everything.
299
+ ### @Mention Routing
300
+
301
+ Agents can message each other in real-time:
211
302
 
212
- Project-local agent overrides: `{project}/.pi/squad/agents/`
303
+ ```
304
+ Agent output: "@frontend what token format do you need?"
305
+ → Router parses @mention
306
+ → Delivers to running agent via steer()
307
+ → Or queues for delivery when agent spawns
308
+ ```
213
309
 
214
- ## Multi-Project Support
310
+ ### Block Detection
215
311
 
216
- Squads are stored globally but scoped to projects by their `cwd` field. Multiple pi sessions can run squads for different projects simultaneously.
312
+ If an agent says "I'm blocked" or "cannot proceed", the router detects it and escalates to the main agent.
313
+
314
+ ## Session Resilience
315
+
316
+ ### Crash Recovery
317
+
318
+ When a pi session crashes (tmux dies, SIGKILL, etc.):
319
+ - In-progress tasks are automatically **suspended** on next startup
320
+ - Squad is marked as **paused**
321
+ - Only squads with completed tasks trigger a notification
322
+
323
+ ### Resume
324
+
325
+ Resume a paused squad across sessions:
217
326
 
218
327
  ```
219
- Session A (cwd: /projects/api) Session B (cwd: /projects/web)
220
- └── squad "build-auth" └── squad "build-dashboard"
221
- both stored in ~/.pi/squad/
222
- filtered by cwd when listing
328
+ > Resume the squad
223
329
  ```
224
330
 
225
- `/squad list` shows squads for the current project. `/squad all` shows all projects.
331
+ The agent calls `squad_modify({ action: "resume" })`, which:
332
+ 1. Finds the latest paused squad for the project
333
+ 2. Creates a fresh scheduler from disk state
334
+ 3. Restarts suspended tasks
226
335
 
227
- Any pi session can browse and view any squad with `/squad select` or `/squad all`.
336
+ All state lives on disk squads are fully reconstructable.
228
337
 
229
338
  ## Governance
230
339
 
231
- - **Dependency enforcement** blocked tasks never spawn, auto-unblock when deps complete
232
- - **Concurrency control** — configurable `maxConcurrency` (default: 2)
233
- - **Health monitoring** idle warning (3m), stuck intervention (5m), loop detection, 30m hard ceiling
234
- - **@mention routing** parsed from agent output, delivered via RPC `steer()`
235
- - **File conflict tracking** warns agents about files modified by others
340
+ | Mechanism | What it does |
341
+ |---|---|
342
+ | **Dependency DAG** | Blocked tasks never spawn. Auto-unblock when deps complete. |
343
+ | **Concurrency control** | `maxConcurrency` limits parallel agents (default: 2) |
344
+ | **Health monitoring** | Idle warning (3m), stuck intervention (5m), loop detection (same tool 5x), 30m hard ceiling |
345
+ | **QA rework loop** | Auto-creates fix + retest tasks when QA fails (up to `maxRetries`) |
346
+ | **File tracking** | Warns agents about files modified by other agents |
347
+ | **@mention routing** | Parsed from output, delivered via RPC `steer()` |
348
+ | **Escalation** | Blocked agents, stuck agents, and retry limit → notify main agent |
349
+
350
+ ## Data Layout
351
+
352
+ All state lives in `~/.pi/squad/`. No database, no daemon, no external services. Writes are atomic (temp file + rename).
353
+
354
+ ```
355
+ ~/.pi/squad/
356
+ ├── agents/ — agent definitions (user-editable)
357
+ │ ├── backend.json
358
+ │ ├── qa.json
359
+ │ └── ...
360
+ └── {squad-id}/ — one directory per squad
361
+ ├── squad.json — goal, status, config, cwd
362
+ ├── context.json — live state snapshot
363
+ ├── knowledge/ — shared decisions/findings
364
+ │ ├── decisions.jsonl
365
+ │ └── findings.jsonl
366
+ └── {task-id}/ — one directory per task
367
+ ├── task.json — status, agent, output, usage
368
+ └── messages.jsonl — full conversation log
369
+ ```
370
+
371
+ ## Architecture
372
+
373
+ ```
374
+ src/
375
+ ├── index.ts — extension entry: tools, commands, widget, panel, lifecycle
376
+ ├── types.ts — Squad, Task, Agent, Message types
377
+ ├── store.ts — JSON/JSONL file I/O with atomic writes
378
+ ├── scheduler.ts — dependency DAG, concurrency, rework loop, task lifecycle
379
+ ├── agent-pool.ts — pi RPC process spawn/steer/kill
380
+ ├── protocol.ts — system prompt builder (7 sections)
381
+ ├── router.ts — @mention parsing, cross-agent messaging
382
+ ├── monitor.ts — health checks: idle/stuck/loop/ceiling
383
+ ├── supervisor.ts — quality review, block analysis
384
+ ├── planner.ts — one-shot goal decomposition via LLM
385
+ ├── panel/
386
+ │ ├── squad-panel.ts — overlay component (ctx.ui.custom with done())
387
+ │ ├── squad-widget.ts — component-based widget (setWidget factory)
388
+ │ ├── task-list.ts — task tree with status icons, elapsed time
389
+ │ └── message-view.ts — scrollable message log per task
390
+ ├── skills/
391
+ │ ├── supervisor/ — teaches main agent to supervise squads
392
+ │ ├── squad-protocol/ — communication rules for child agents
393
+ │ ├── collaboration/ — team interaction patterns
394
+ │ └── verification/ — verify-before-done + structured verdicts
395
+ └── agents/_defaults/ — 11 bundled agent definitions
396
+ ```
397
+
398
+ ## Test Results
399
+
400
+ ### Simple (3 tasks, linear chain)
401
+ - URL shortener API: 3 tasks, $0.83, 4.5 minutes
402
+ - Backend → QA → Docs, all passing
403
+
404
+ ### Medium (6 tasks, diamond dependency)
405
+ - Static blog engine: 6 tasks, $4.56, 24 minutes
406
+ - Markdown parser → HTML converter → site generator → Express server → QA + Docs
407
+ - 87+ tests passing
408
+
409
+ ### Complex (5 original + 4 auto-rework = 9 tasks)
410
+ - Chat API with auth + rooms: 9 tasks, $4.60, 26 minutes
411
+ - QA found 2 bugs → 2 automatic rework cycles → both fixed and verified
412
+ - 176 turns across 5 specialist agents
236
413
 
237
414
  ## Requirements
238
415
 
239
416
  - [pi](https://github.com/badlogic/pi-mono) coding agent
240
417
  - An API key configured in pi (Anthropic, OpenRouter, etc.)
418
+ - Node.js 18+
241
419
 
242
420
  ## License
243
421
 
package/package.json CHANGED
@@ -1,11 +1,15 @@
1
1
  {
2
2
  "name": "pi-squad",
3
- "version": "0.1.0",
3
+ "version": "0.4.14",
4
4
  "description": "Multi-agent collaboration extension for pi — task decomposition, dependency management, parallel execution, TUI panel",
5
5
  "type": "module",
6
6
  "pi": {
7
- "extensions": ["src/index.ts"],
8
- "skills": ["src/skills/squad-protocol", "src/skills/collaboration", "src/skills/verification"]
7
+ "extensions": [
8
+ "src/index.ts"
9
+ ],
10
+ "skills": [
11
+ "src/skills/supervisor"
12
+ ]
9
13
  },
10
14
  "files": [
11
15
  "src",