pi-squad 0.7.2 → 0.15.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/README.md CHANGED
@@ -8,6 +8,9 @@ Multi-agent collaboration extension for [pi](https://github.com/badlogic/pi-mono
8
8
  # From npm
9
9
  pi install npm:pi-squad
10
10
 
11
+ # From git
12
+ pi install git:github.com/picassio/pi-squad
13
+
11
14
  # Or symlink for development
12
15
  ln -sf /path/to/pi-squad/src ~/.pi/agent/extensions/squad
13
16
  ```
@@ -22,11 +25,11 @@ Ask pi to do something complex. It calls the `squad` tool automatically:
22
25
  > Build a REST API with authentication, tests, and documentation
23
26
  ```
24
27
 
25
- The planner agent reads your codebase and creates a task breakdown automatically. Or be explicit:
28
+ The planner agent reads your codebase and creates a task breakdown automatically. Or define tasks explicitly:
26
29
 
27
30
  ```
28
31
  > Use squad: goal="Build task API", tasks=[
29
- {id: "api", title: "Build CRUD endpoints with express", agent: "backend"},
32
+ {id: "api", title: "Build CRUD endpoints", agent: "backend"},
30
33
  {id: "tests", title: "Write tests", agent: "qa", depends: ["api"]},
31
34
  {id: "docs", title: "Write README", agent: "docs", depends: ["api"]}
32
35
  ]
@@ -34,421 +37,303 @@ The planner agent reads your codebase and creates a task breakdown automatically
34
37
 
35
38
  ### What Happens
36
39
 
37
- 1. Planner analyzes the codebase and creates tasks (or uses your predefined tasks)
38
- 2. A **live widget** appears above the editor showing task status
39
- 3. Agents spawn as separate pi processes, work in parallel where dependencies allow
40
+ 1. **Planner** analyzes the codebase and creates tasks with dependencies
41
+ 2. A **live widget** appears above the editor showing task progress
42
+ 3. **Specialist agents** spawn as separate pi processes, working in parallel where dependencies allow
40
43
  4. QA agents can trigger **automatic rework loops** when they find bugs
41
- 5. When complete, pi reports the summary notifications don't pollute message history
44
+ 5. On completion, pi receives a summary with each task's output
42
45
  6. Multiple squads can run concurrently across different projects
43
46
 
44
- ## User Interface
47
+ ## Features
45
48
 
46
- ### Widget (above editor)
49
+ ### Dependency-Aware Scheduling
47
50
 
48
- Always visible when a squad is active. Debounced updates with cache key to avoid flicker.
51
+ Tasks define dependencies. The scheduler resolves the DAG, spawns ready tasks up to `maxConcurrency`, and auto-unblocks dependents when tasks complete.
49
52
 
50
53
  ```
51
- squad Build task API 2/3 $0.58 3m12s ^q detail · /squad msg
52
- ✓ api (backend) 2m12s Created CRUD REST API with validation
53
- tests (qa) 45s bash npm test
54
- ◻ docs (docs) ← api
54
+ architect backend ──→ qa
55
+
56
+ architectfrontend ─┘
55
57
  ```
56
58
 
57
- Features:
58
- - Per-task elapsed time (warning color after 3 minutes)
59
- - Live tool call preview for running tasks
60
- - Stale detection — shows `⏳ idle` when agent has no output for 2+ minutes
61
- - Responsive — caps visible tasks on small terminals, shows `+N more` overflow
62
- - Completion duration for finished tasks
63
-
64
- ### Status Bar (footer)
59
+ Architect runs first. Backend and frontend run in parallel after architect completes. QA waits for both.
65
60
 
66
- ```
67
- ⏳ squad 2/3 $0.58
68
- ```
61
+ ### QA Rework Loop
69
62
 
70
- ### Panel (Ctrl+Q)
63
+ When a QA agent outputs `## Verdict: FAIL`, the scheduler automatically:
71
64
 
72
- Centered overlay panel with proper lifecycle management. Press `Ctrl+Q` to open/close.
65
+ 1. Creates a **fix task** for the original agent with QA feedback
66
+ 2. Creates a **retest task** for QA, blocked until the fix completes
67
+ 3. Loops up to `maxRetries` (default: 2), then escalates
73
68
 
74
- **Task list** with sticky summary at bottom:
75
69
  ```
76
- ╭─ squad: Build task API ─────────────────────╮
77
- api (backend) 2m12s │
78
- │ ⏳ tests (qa) 45s │
79
- │ ◻ docs (docs) blocked │
80
- │ │
81
- │ ── tests (live) ───────────────────── │
82
- │ → bash npm test │
83
- │ │
84
- │ 2/3 · $0.58 · 3m │
85
- ├──────────────────────────────────────────────┤
86
- │ ↑↓ nav ⏎ msgs m send p pause ^q close │
87
- ╰──────────────────────────────────────────────╯
70
+ api (backend) qa (qa) ✗ found bug
71
+ api-fix-1 (backend) qa-retest-1 (qa) ✓ all passing
88
72
  ```
89
73
 
90
- **Message view** (Enter on a task) — long text wraps instead of truncating:
91
- ```
92
- ╭─ tests · qa ⏳ ─────────────────────────────╮
93
- │ 10:03 qa │
94
- │ Starting test implementation. Will cover │
95
- │ all CRUD endpoints, validation, and │
96
- │ edge cases for empty input. │
97
- │ 10:04 qa │
98
- │ → write src/tasks.test.js │
99
- │ 10:05 YOU │
100
- │ Also test edge cases for empty input │
101
- │ ─ 65% ─ 24 msgs ─ ↑↓ scroll │
102
- ├──────────────────────────────────────────────┤
103
- │ ↑↓ scroll m send esc back ^q close │
104
- ╰──────────────────────────────────────────────╯
105
- ```
74
+ ### Built-in Engineering Skills
106
75
 
107
- ## Commands
76
+ 9 skills ship with the extension. Every squad agent automatically loads them:
108
77
 
109
- | Command | Description |
78
+ | Skill | Purpose |
110
79
  |---|---|
111
- | `/squad` or `/squad select` | Pick a squad to view (interactive selector) |
112
- | `/squad list` | List squads for current project |
113
- | `/squad all` | List all squads across all projects |
114
- | `/squad agents` | List, view, edit, enable/disable agents |
115
- | `/squad agents <name>` | Quick view of a specific agent |
116
- | `/squad msg [agent] text` | Send message to a running agent |
117
- | `/squad widget` | Toggle live widget on/off |
118
- | `/squad panel` | Toggle overlay panel |
119
- | `/squad cancel` | Cancel running squad |
120
- | `/squad clear` | Dismiss widget, deactivate view |
121
- | `/squad cleanup` | Delete squad data (select one or all) |
122
- | `/squad cleanup all` | Delete all squad data |
123
- | `/squad enable` | Enable pi-squad (tools, widget, system prompt) |
124
- | `/squad disable` | Disable pi-squad completely |
80
+ | `squad-architecture` | API contract definition, shared types, project structure, decision documentation |
81
+ | `squad-backend-dev` | REST conventions, database patterns, auth implementation, error handling, security |
82
+ | `squad-frontend-dev` | React patterns, state management, Tailwind CSS, accessibility, API integration |
83
+ | `squad-qa-testing` | Test strategy, checklist, evidence requirements, verdict format, rework flow |
84
+ | `squad-security-audit` | Vulnerability checklist, common patterns, reporting format |
85
+ | `squad-verification` | Verify before claiming done, evidence-based completion |
86
+ | `squad-collaboration` | Building on others' work, asking questions, sharing knowledge |
87
+ | `squad-protocol` | Communication rules, @mention syntax, completion format |
88
+ | `squad-supervisor` | Squad management guidance for the main pi agent |
125
89
 
126
- ## Keyboard Shortcuts
90
+ Skills are prefixed with `squad-` to avoid conflicts with user or project skills. Squad agents also inherit all skills from the main pi session (user skills, package skills, project skills).
127
91
 
128
- | Key | Context | Action |
129
- |---|---|---|
130
- | `Ctrl+Q` | Anywhere | Toggle squad panel overlay |
131
- | `↑↓` or `jk` | Panel | Navigate tasks / scroll messages |
132
- | `Enter` | Panel task list | View task messages |
133
- | `Esc` | Panel message view | Back to task list |
134
- | `m` | Panel | Send message to selected task's agent |
135
- | `p` | Panel task list | Pause/resume task |
136
- | `x` | Panel task list | Cancel task |
137
- | `q` | Panel task list | Close panel |
92
+ ### 11 Specialist Agents
138
93
 
139
- ## Tools (LLM-callable)
94
+ Bundled agent definitions are copied to `~/.pi/squad/agents/` on first run. Edit them freely — the extension never overwrites existing files.
140
95
 
141
- | Tool | Description |
142
- |---|---|
143
- | `squad` | Start a squad (non-blocking, returns immediately) |
144
- | `squad_status` | Check progress, costs, task states |
145
- | `squad_message` | Send message to a running agent via `steer()` |
146
- | `squad_modify` | Add/cancel/pause/resume tasks, or cancel/resume entire squad |
96
+ | Agent | Role | Tags |
97
+ |---|---|---|
98
+ | `architect` | Software Architect | architecture, design, patterns |
99
+ | `backend` | Backend Engineer | api, server, database, auth |
100
+ | `frontend` | Frontend Engineer | react, ui, css, tailwind, accessibility |
101
+ | `fullstack` | Fullstack Developer | general, coding, implementation |
102
+ | `qa` | QA Engineer | testing, verification, e2e |
103
+ | `reviewer` | Code Reviewer (read-only) | review, code-quality, over-engineering |
104
+ | `security` | Security Engineer | audit, vulnerability, threat-modeling |
105
+ | `debugger` | Debugger & Root Cause Analyst | debugging, investigation, bugs |
106
+ | `devops` | DevOps Engineer | ci-cd, docker, deployment |
107
+ | `docs` | Technical Writer | documentation, readme, api-docs |
108
+ | `researcher` | Research Analyst | research, analysis, exploration |
109
+ | `planner` | Project Planner | planning, architecture, coordination |
147
110
 
148
- 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. Squad notifications use `sendMessage({ display: true })` so they don't pollute the LLM's message history.
111
+ ### Agent Collaboration
149
112
 
150
- ## Multiple Concurrent Squads
113
+ **Chain context**: When task A completes, its output is injected into task B's system prompt. Downstream agents know what was built.
151
114
 
152
- Multiple squads can run in parallel from the same pi session. Each squad has its own scheduler, agent pool, and disk state.
115
+ **Shared filesystem**: All agents work in the same project directory. Upstream agents create files, downstream agents read and modify them.
153
116
 
154
- ```
155
- > Build the auth API → starts squad-1
156
- > Build the dashboard UI → starts squad-2 (runs in parallel)
117
+ **Sibling awareness**: Parallel agents see each other's status and modified files, with warnings about shared file edits.
157
118
 
158
- /squad list → see both, select which to view
159
- /squad select → switch widget/panel focus
160
- ```
119
+ **@mention routing**: Agents write `@frontend what token format?` in their output. The router delivers it in real-time via RPC `steer()`.
161
120
 
162
- All squads run independently in the background. The widget/panel shows whichever squad you're focused on.
121
+ ### Smart Planner
163
122
 
164
- ## QA Rework Loop
123
+ The planner creates task breakdowns with proper dependency ordering:
124
+ - Frontend tasks depend on backend API tasks (so frontend can test against real endpoints)
125
+ - Parallel tasks that share interfaces get a design/architecture task first
126
+ - Task descriptions include specific API paths, schemas, and conventions
165
127
 
166
- When a QA agent outputs `## Verdict: FAIL`, the scheduler automatically:
128
+ When the main agent provides tasks directly (via the `tasks` parameter), unknown agent names are automatically remapped to `fullstack` instead of failing.
167
129
 
168
- 1. **Parses** the failure details from QA output
169
- 2. **Creates a rework task** for the original agent with QA feedback injected into its system prompt
170
- 3. **Creates a retest task** for QA, blocked until the rework completes
171
- 4. After fix, QA re-tests. If still failing, loops up to `maxRetries` (default: 2)
172
- 5. If retry limit exceeded, **escalates** to the main agent for human decision
130
+ ## User Interface
131
+
132
+ ### Widget (above editor)
173
133
 
174
- ### Example flow
134
+ Shows live squad progress. Truncated to terminal width — no wrapping, deterministic height.
175
135
 
176
136
  ```
177
- auth (backend)
178
- qa-auth (qa) found race condition bug
179
- auth-fix-1 (backend) fixed it [auto-created]
180
- qa-auth-retest-1 (qa) — retested, found another issue
181
- → auth-fix-2 (backend) ✓ — fixed again [auto-created]
182
- → qa-auth-retest-2 (qa) ✓ — all tests pass ✓
137
+ squad Build task API 2/3 $0.58 3m12s ^q detail · /squad msg
138
+ api (backend) 2m12s Created CRUD REST API with validation
139
+ tests (qa) 45s bash npm test
140
+ docs (docs) api
183
141
  ```
184
142
 
185
- ### What the rework agent sees
186
-
187
- The rework agent's system prompt includes:
188
- - Original task output (what was built)
189
- - QA feedback (what failed, with specific issues)
190
- - Instructions to make targeted fixes, not rewrite everything
191
-
192
- ### QA verdict format
193
-
194
- QA agents should end their output with a structured verdict:
143
+ ### Status Bar
195
144
 
196
- ```markdown
197
- ## Verdict: PASS
198
- All 42 tests passing. No issues found.
199
145
  ```
200
-
201
- ```markdown
202
- ## Verdict: FAIL
203
-
204
- ## Issues
205
- 1. **[src/auth.ts:45]** JWT expiry not enforced
206
- - Expected: 401 for expired tokens
207
- - Got: 200 (token accepted)
208
- 2. **[src/routes.ts:23]** Missing rate limit on /login
146
+ ⏳ squad 2/3 $0.58
209
147
  ```
210
148
 
211
- ### Configuration
149
+ ### Panel (Ctrl+Q)
212
150
 
213
- ```
214
- config: {
215
- maxConcurrency: 3, // parallel agents (default: 2)
216
- maxRetries: 2, // rework attempts before escalation (default: 2)
217
- }
218
- ```
151
+ Full overlay with task list, live activity preview, and scrollable message view.
219
152
 
220
- ## Sending Messages to Agents
153
+ | Key | Action |
154
+ |---|---|
155
+ | `↑↓` / `jk` | Navigate tasks / scroll messages |
156
+ | `Enter` | View task messages |
157
+ | `Esc` | Back to task list |
158
+ | `m` | Send message to agent |
159
+ | `p` | Pause/resume task |
160
+ | `x` | Cancel task |
161
+ | `Ctrl+Q` / `q` | Close panel |
221
162
 
222
- Three ways:
163
+ ### Slash Commands
223
164
 
224
- 1. **`/squad msg`** type in the main editor
225
- ```
226
- /squad msg Use postgres instead of SQLite
227
- /squad msg backend Use postgres instead of SQLite
228
- ```
165
+ | Command | Description |
166
+ |---|---|
167
+ | `/squad select` | Pick a squad to view |
168
+ | `/squad list` | List project squads |
169
+ | `/squad all` | List all squads |
170
+ | `/squad agents` | Manage agent definitions |
171
+ | `/squad msg [agent] text` | Send message to agent |
172
+ | `/squad widget` | Toggle widget |
173
+ | `/squad panel` | Toggle panel |
174
+ | `/squad cancel` | Cancel running squad |
175
+ | `/squad clear` | Dismiss widget |
176
+ | `/squad cleanup` | Delete squad data |
177
+ | `/squad enable/disable` | Enable/disable the extension |
229
178
 
230
- 2. **`m` key** — press in the panel, opens input dialog
179
+ ## Tools (LLM-callable)
231
180
 
232
- 3. **Natural chat** tell pi, it relays automatically
233
- ```
234
- > Tell the backend agent to use argon2 for password hashing
235
- ```
181
+ | Tool | Description |
182
+ |---|---|
183
+ | `squad` | Start a squad with goal + optional tasks/config |
184
+ | `squad_status` | Check progress, costs, task states |
185
+ | `squad_message` | Send message to a running agent |
186
+ | `squad_modify` | Add/cancel/complete/pause/resume tasks or squads |
236
187
 
237
- Messages are delivered in real-time via RPC `steer()` if the agent is running, or queued for delivery when the agent spawns.
188
+ The main agent sees available agents in its system prompt and squad state when a squad is active.
238
189
 
239
- ## Agents
190
+ ## Configuration
240
191
 
241
- ### 11 Bundled Agents
192
+ ```javascript
193
+ squad({
194
+ goal: "Build the app",
195
+ config: {
196
+ maxConcurrency: 3, // parallel agents (default: 2)
197
+ maxRetries: 2, // QA rework attempts before escalation (default: 2)
198
+ },
199
+ agents: {
200
+ backend: { model: "claude-sonnet-4-20250514" }, // per-agent model override
201
+ architect: { thinking: "high" }, // per-agent thinking level
202
+ },
203
+ })
204
+ ```
242
205
 
243
- On first run, copied to `~/.pi/squad/agents/` for editing.
206
+ ### Context Inheritance
244
207
 
245
- | Agent | Specialty | Tags |
246
- |---|---|---|
247
- | **planner** | Task breakdown and planning | planning, architecture |
248
- | **fullstack** | General-purpose coding | general, coding |
249
- | **architect** | System design, architecture | architecture, design |
250
- | **backend** | APIs, databases, server-side | api, server, database |
251
- | **frontend** | UI/UX, React, CSS | react, ui, css |
252
- | **debugger** | Root cause analysis | debugging, bugs |
253
- | **qa** | Testing, verification | testing, qa, e2e |
254
- | **security** | Security audits | security, audit |
255
- | **docs** | Technical writing | documentation, readme |
256
- | **researcher** | Code exploration, analysis | research, analysis |
257
- | **devops** | CI/CD, infrastructure | ci-cd, docker |
258
-
259
- ### Agent Management
260
-
261
- Use `/squad agents` for interactive management:
208
+ Agents normally start fresh with only their task description, dependency outputs, and squad protocol. Set `inheritContext: true` on a task to fork the main pi session (via `pi --fork`) so that agent inherits the full conversation context:
262
209
 
263
- ```
264
- /squad agents — list all, select to view/edit
265
- /squad agents backend — quick view of specific agent
210
+ ```js
211
+ squad({
212
+ goal: "Implement the design we discussed",
213
+ tasks: [
214
+ { id: "impl", title: "Implement agreed design", agent: "backend",
215
+ description: "Goal: implement the API design agreed in this conversation. Verify: npm test",
216
+ inheritContext: true },
217
+ ],
218
+ })
266
219
  ```
267
220
 
268
- Actions available per agent:
269
- - **View details** name, role, model, tools, tags, prompt, file path
270
- - **Edit in editor** opens the agent JSON file
271
- - **Change model** set a specific model or use default
272
- - **Toggle tools** restrict to specific tools or enable all
273
- - **Enable/Disable** disabled agents are hidden from the planner
221
+ **Caveats:**
222
+ - **Cost**: the agent pays the entire conversation history as input tokens on every turn — use sparingly
223
+ - **Context-window guard**: the fork is skipped automatically when the estimated session size exceeds 50% of the agent model's context window (agents on smaller-context models silently degrade to standard squad context; the skip is recorded in the task's message log and `debug.log`)
224
+ - Requires the main session to have a session file (skipped under `--no-session`)
225
+ - Forked child sessions are stored under `~/.pi/squad/<squad-id>/sessions/`, not in your project's session list
226
+ - Prefer restating the 3-5 key decisions in the task description — reach for `inheritContext` only when that's impractical
274
227
 
275
228
  ### Custom Agents
276
229
 
277
- Create a JSON file in `~/.pi/squad/agents/` (global) or `{project}/.pi/squad/agents/` (project override):
230
+ Create `~/.pi/squad/agents/my-agent.json` (global) or `{project}/.pi/squad/agents/my-agent.json` (project override):
278
231
 
279
232
  ```json
280
233
  {
281
- "name": "ml-engineer",
234
+ "name": "my-agent",
282
235
  "role": "ML Engineer",
283
236
  "description": "Machine learning, PyTorch, data pipelines",
284
- "model": "anthropic/claude-sonnet-4-20250514",
237
+ "model": null,
238
+ "thinking": null,
285
239
  "tools": null,
286
240
  "tags": ["ml", "pytorch", "data"],
287
- "prompt": "You are an ML engineer specializing in PyTorch...",
288
- "disabled": false
241
+ "prompt": "You are an ML engineer specializing in PyTorch..."
289
242
  }
290
243
  ```
291
244
 
292
- - `model`: `null` = pi default. Override with any model ID your provider supports.
293
- - `tools`: `null` = all tools. Array like `["bash", "read", "write", "edit"]` to restrict.
294
- - `tags`: Used by the planner to match agents to tasks automatically.
295
- - `disabled`: `true` = hidden from planner, tasks assigned to this agent will fail.
296
- - Project-local agents override global agents with the same name.
297
-
298
- ## How Agents Collaborate
245
+ - `model`: `null` = squad default (see below). Override per agent or per squad.
246
+ - `thinking`: `null` = squad default. One of `off`, `minimal`, `low`, `medium`, `high`, `xhigh`, `max` (passed via pi's `--thinking` flag). Override per agent or per squad. Also editable via `/squad agents` → "Change thinking".
299
247
 
300
- ### Chain Context (primary)
248
+ ### Default Model & Thinking (`/squad defaults`)
301
249
 
302
- 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 — no need for explicit communication.
250
+ Agents without an explicit `model`/`thinking` follow the squad default policy (stored in `~/.pi/squad/settings.json`):
303
251
 
304
- ### Shared Filesystem
305
-
306
- 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.
307
-
308
- ### Sibling Awareness
309
-
310
- When agents run in parallel, each sees the other's status and modified files in their system prompt:
311
-
312
- ```
313
- # Sibling Tasks
314
- - template-engine [in_progress] — fullstack — Create HTML templates
315
-
316
- ## Files Modified by Other Agents
317
- **fullstack:** src/templateEngine.js, templates/post.html
318
- ⚠️ Coordinate with the owning agent before editing files listed above.
319
- ```
320
-
321
- ### @Mention Routing
322
-
323
- Agents can message each other in real-time:
324
-
325
- ```
326
- Agent output: "@frontend what token format do you need?"
327
- → Router parses @mention
328
- → Delivers to running agent via steer()
329
- → Or queues for delivery when agent spawns
330
- ```
331
-
332
- ### Block Detection
252
+ | Policy | Behavior |
253
+ |---|---|
254
+ | `main` *(default)* | **Follow the main pi session's current model and thinking level** switch models mid-session and new agents follow |
255
+ | `pi-default` | Legacy behavior: the child pi process resolves its own configured default |
256
+ | explicit value | A fixed model id (e.g. `openai-codex/gpt-5.6-terra`) or thinking level |
333
257
 
334
- If an agent says "I'm blocked" or "cannot proceed", the router detects it and escalates to the main agent.
258
+ Change interactively with `/squad defaults`. The planner agent follows the same policy. Resolution order: agent def per-squad override → squad default policy.
259
+ - `tools`: `null` = all tools. Restrict with `["bash", "read", "write", "edit"]`.
260
+ - `tags`: Used by the planner to match agents to tasks automatically.
261
+ - Project-local agents override global agents with the same name.
335
262
 
336
- ## Session Resilience
263
+ ### Advisor — Self-Healing Squads (`/squad advisor`)
337
264
 
338
- ### Crash Recovery
265
+ Modeled on the advisor tool pattern ([pi-advisor](https://github.com/RimuruW/pi-advisor) / Anthropic's advisor strategy): when the health monitor flags an agent as stuck, the squad consults a **stronger advisor model in-process** (via pi-ai, no subprocess) with a curated digest — task, recent messages, recent tool activity — before interrupting you.
339
266
 
340
- When a pi session crashes (tmux dies, SIGKILL, etc.):
341
- - In-progress tasks are automatically **suspended** on next startup
342
- - Squad is marked as **paused**
343
- - Only squads with completed tasks trigger a notification
344
- - Squads with zero progress are silently paused (no noise)
267
+ The advisor returns a verdict (`Course-correct` / `Push through` / `Needs human input`) plus ≤5 action items:
268
+ - **Course-correct / Push through** advice is steered directly into the stuck agent's conversation; escalation suppressed
269
+ - **Needs human input** escalates immediately with the advisor's assessment attached
270
+ - Advisor disabled, exhausted (`maxCallsPerTask`), or failed normal escalation to you
345
271
 
346
- ### Resume
272
+ Configure with `/squad advisor` (on/off, model, max calls per task, reasoning effort). Defaults: **enabled**, model = main session's model, 2 calls/task, medium reasoning. Settings persist in `~/.pi/squad/settings.json` under `advisor`. All consultations are recorded in the task's message log (`from: "advisor"`).
347
273
 
348
- Resume a paused squad across sessions:
274
+ ## Reliability
349
275
 
350
- ```
351
- > Resume the squad
352
- ```
276
+ ### Meaningful Work Check
353
277
 
354
- The agent calls `squad_modify({ action: "resume" })`, which:
355
- 1. Finds the latest paused squad for the project
356
- 2. Creates a fresh scheduler from disk state
357
- 3. Wires up event handlers for completion/failure/escalation
358
- 4. Restarts suspended tasks
278
+ Agents must complete at least 1 LLM turn AND make at least 1 tool call to be marked as "done". Agents that exit cleanly but did no work (rate limit, API error, model not found) are retried once, then failed — never silently marked successful.
359
279
 
360
- All state lives on disk — squads are fully reconstructable from JSON files.
280
+ ### Session Resilience
361
281
 
362
- ### Spawn Resilience
282
+ - In-progress tasks are **suspended** on session crash, **resumed** on next startup
283
+ - Failure is never terminal: `resume` recovers failed squads (failed tasks reset to pending), `complete_task` marks recovered work done and schedules dependents, and a 60s reconcile loop re-derives scheduling from persisted state so out-of-band store edits can't strand ready tasks
284
+ - Squads are fully reconstructable from JSON files on disk
285
+ - Spawn failures are retried once with a 2-second delay
286
+ - All errors logged to `~/.pi/squad/debug.log` (always for errors, `PI_SQUAD_DEBUG=1` for verbose)
363
287
 
364
- Child agent processes occasionally fail during startup (transient resource pressure). The scheduler automatically retries once after a 2-second delay. If the retry also fails, the task is marked failed with a diagnostic log including PID, exit code, stderr, and stdout line count.
288
+ ### Health Monitoring
365
289
 
366
- ## Governance
290
+ The monitor never kills or blocks work on its own — its strongest action is notifying the main Pi session so you (or the main agent) can decide.
367
291
 
368
- | Mechanism | What it does |
369
- |---|---|
370
- | **Dependency DAG** | Blocked tasks never spawn. Auto-unblock when deps complete. |
371
- | **Concurrency control** | `maxConcurrency` limits parallel agents (default: 2) |
372
- | **Health monitoring** | Idle warning (3m), stuck intervention (5m), loop detection (same tool 5x), 30m hard ceiling |
373
- | **QA rework loop** | Auto-creates fix + retest tasks when QA fails (up to `maxRetries`) |
374
- | **Spawn retry** | Retries once on transient startup failures, then fails with diagnostics |
375
- | **File tracking** | Warns agents about files modified by other agents |
376
- | **@mention routing** | Parsed from output, delivered via RPC `steer()` |
377
- | **Escalation** | Blocked agents, stuck agents, retry limit, spawn failure → notify main agent |
378
- | **Clean notifications** | Uses `sendMessage({ display: true })` — visible to user, not in LLM history |
292
+ | Check | Threshold | Action |
293
+ |---|---|---|
294
+ | Idle warning | 3 minutes no output | Steer agent with nudge |
295
+ | Stuck detection | 5 minutes no output | Steer, then escalate to main session |
296
+ | Loop detection | Same tool call 5x | Steer with warning |
297
+ | Long-running check-in | Every 30 minutes total (`PI_SQUAD_CEILING_MS`) | Notify main session work continues |
379
298
 
380
299
  ## Data Layout
381
300
 
382
- All state lives in `~/.pi/squad/`. No database, no daemon, no external services. Writes are atomic (temp file + rename). JSONL reads are fault-tolerant (skip corrupt lines from concurrent writes).
301
+ All state in `~/.pi/squad/`. No database, no daemon. Writes are atomic. JSONL reads skip corrupt lines.
383
302
 
384
303
  ```
385
304
  ~/.pi/squad/
386
- ├── agents/ — agent definitions (user-editable)
387
- ├── backend.json
388
- │ ├── qa.json
389
- │ └── ...
390
- └── {squad-id}/ one directory per squad
391
- ├── squad.json — goal, status, config, cwd
392
- ├── context.json live state snapshot
393
- ├── knowledge/ shared decisions/findings
394
- │ ├── decisions.jsonl
395
- │ └── findings.jsonl
396
- └── {task-id}/ — one directory per task
397
- ├── task.json — status, agent, output, usage, retryOf, qaFeedback
398
- └── messages.jsonl — full conversation log
305
+ ├── agents/ — agent definitions (user-editable)
306
+ ├── debug.log — error and debug logging
307
+ └── {squad-id}/
308
+ ├── squad.json — goal, status, config, cwd
309
+ ├── context.json live state snapshot
310
+ └── {task-id}/
311
+ ├── task.json status, output, usage, retryOf, qaFeedback
312
+ └── messages.jsonl conversation log
399
313
  ```
400
314
 
401
315
  ## Architecture
402
316
 
403
317
  ```
404
318
  src/
405
- ├── index.ts — extension entry: tools, commands, widget, panel, lifecycle
406
- ├── types.ts Squad, Task, Agent, Message types
407
- ├── store.ts — JSON/JSONL file I/O with atomic writes, fault-tolerant reads
408
- ├── scheduler.ts — dependency DAG, concurrency, rework loop, spawn retry, task lifecycle
409
- ├── agent-pool.ts — pi RPC process spawn/steer/kill, diagnostic logging
410
- ├── protocol.ts — system prompt builder (7 sections + rework context)
411
- ├── router.ts — @mention parsing, cross-agent messaging
412
- ├── monitor.ts — health checks: idle/stuck/loop/ceiling
413
- ├── supervisor.ts quality review, block analysis
414
- ├── planner.ts one-shot goal decomposition via LLM
415
- ├── panel/
416
- ├── squad-panel.ts overlay component (ctx.ui.custom with done())
417
- │ ├── squad-widget.ts string[] widget with debounce and cache
418
- │ ├── task-list.ts — task tree with status icons, elapsed time, sticky summary
419
- │ └── message-view.ts — scrollable message log with word wrap, fixed-height layout
420
- ├── skills/
421
- │ ├── supervisor/ — teaches main agent to supervise squads
422
- │ ├── squad-protocol/ — communication rules for child agents
423
- │ ├── collaboration/ — team interaction patterns
424
- │ └── verification/ — verify-before-done + structured QA verdicts
425
- └── agents/_defaults/ — 11 bundled agent definitions
319
+ ├── index.ts — extension entry: tools, commands, widget, panel, lifecycle
320
+ ├── types.ts type definitions
321
+ ├── store.ts — JSON/JSONL file I/O, atomic writes
322
+ ├── scheduler.ts — dependency DAG, concurrency, rework loop, task lifecycle
323
+ ├── agent-pool.ts — pi RPC process management, activity tracking
324
+ ├── protocol.ts — system prompt builder (chain context, sibling awareness, knowledge)
325
+ ├── router.ts — @mention parsing, cross-agent messaging
326
+ ├── monitor.ts — health checks (idle, stuck, loop, long-run notify)
327
+ ├── planner.ts one-shot goal decomposition via LLM
328
+ ├── logger.ts file-based logging (never writes to stderr)
329
+ ├── panel/ — TUI overlay panel and widget
330
+ ├── skills/ 9 bundled skills for agents
331
+ └── agents/_defaults/ 11 bundled agent definitions
426
332
  ```
427
333
 
428
- ## Test Results
429
-
430
- ### Simple (3 tasks, linear chain)
431
- - URL shortener API: 3 tasks, 30 turns, $0.83, 4.5 minutes
432
- - Backend → QA → Docs, all passing
433
-
434
- ### Medium (5 tasks, planner-decomposed)
435
- - Quiz API: 5 tasks, 82 turns, $3.11, 14 minutes
436
- - Planner auto-created: architect → backend → fullstack → QA + docs
437
- - 111 vitest tests passing, 3,637 lines of code
438
-
439
- ### Complex with rework (5 original + 4 auto-rework = 9 tasks)
440
- - Chat API with auth + rooms: 9 tasks, 176 turns, $4.60, 26 minutes
441
- - QA found 2 bugs → 2 automatic rework cycles → both fixed and verified
442
- - Dependency chain with parallel QA and rework loop
443
-
444
- ### Parallel squads (2 squads running simultaneously)
445
- - Bookmarks API (2/2, $0.83) + Notes CLI (6/6 with 2 rework cycles, $1.17)
446
- - Both ran concurrently from the same pi session
447
- - Combined: 12 tasks, 101 turns, $2.00
448
-
449
334
  ## Requirements
450
335
 
451
- - [pi](https://github.com/badlogic/pi-mono) coding agent (v0.63.0+, recommended v0.64.0+)
336
+ - [pi](https://github.com/badlogic/pi-mono) v0.63.0+ (recommended v0.64.0+)
452
337
  - An API key configured in pi (Anthropic, OpenRouter, etc.)
453
338
  - Node.js 18+
454
339