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 +202 -317
- package/package.json +18 -2
- package/src/advisor.ts +145 -0
- package/src/agent-pool.ts +39 -15
- package/src/agents/_defaults/architect.json +8 -1
- package/src/agents/_defaults/backend.json +9 -1
- package/src/agents/_defaults/debugger.json +8 -1
- package/src/agents/_defaults/devops.json +9 -1
- package/src/agents/_defaults/docs.json +8 -1
- package/src/agents/_defaults/frontend.json +10 -1
- package/src/agents/_defaults/fullstack.json +8 -1
- package/src/agents/_defaults/planner.json +7 -1
- package/src/agents/_defaults/qa.json +8 -1
- package/src/agents/_defaults/researcher.json +8 -1
- package/src/agents/_defaults/reviewer.json +10 -0
- package/src/agents/_defaults/security.json +8 -1
- package/src/index.ts +379 -78
- package/src/monitor.ts +54 -20
- package/src/panel/message-view.ts +2 -2
- package/src/panel/squad-panel.ts +3 -3
- package/src/panel/squad-widget.ts +3 -3
- package/src/panel/task-list.ts +2 -2
- package/src/plan-rules.ts +134 -0
- package/src/planner.ts +18 -14
- package/src/protocol.ts +10 -2
- package/src/scheduler.ts +293 -13
- package/src/skills/squad-code-review/SKILL.md +89 -0
- package/src/skills/squad-collaboration/SKILL.md +5 -1
- package/src/skills/squad-debugging/SKILL.md +61 -0
- package/src/skills/squad-protocol/SKILL.md +19 -0
- package/src/skills/squad-qa-testing/SKILL.md +19 -8
- package/src/skills/squad-supervisor/SKILL.md +85 -11
- package/src/store.ts +27 -1
- package/src/types.ts +49 -2
|
@@ -9,12 +9,52 @@ You are the supervisor of multi-agent squads. Agents work on decomposed tasks in
|
|
|
9
9
|
|
|
10
10
|
## Your Role
|
|
11
11
|
|
|
12
|
-
You are the bridge between the human and the squad
|
|
12
|
+
You are the bridge between the human and the squad, and you wear three hats:
|
|
13
|
+
- **Planner** — when you pass pre-defined `tasks` to the `squad` tool, you replace the planner agent. Follow the same rules it does (see "Acting as the Planner" below)
|
|
14
|
+
- **Supervisor** — monitor progress, handle escalations, relay instructions, steer agents
|
|
15
|
+
- **Reviewer** — when the squad completes, verify the work like a QA agent before reporting success to the user (see "Reviewing Completed Work" below)
|
|
16
|
+
|
|
17
|
+
You:
|
|
13
18
|
- Start squads for complex tasks (use the `squad` tool)
|
|
14
19
|
- Monitor progress and relay status to the user
|
|
15
20
|
- Handle escalations when agents get stuck
|
|
16
21
|
- Send instructions to agents on behalf of the user
|
|
17
|
-
-
|
|
22
|
+
- Review and verify results when the squad completes
|
|
23
|
+
|
|
24
|
+
## Acting as the Planner
|
|
25
|
+
|
|
26
|
+
Providing `tasks` yourself skips the planner agent — so you must apply its rules:
|
|
27
|
+
- 3-7 tasks is usually right — don't over-decompose
|
|
28
|
+
- Task IDs short kebab-case; dependencies reference IDs from the same plan; first task(s) have empty `depends`
|
|
29
|
+
- When tasks share an interface (API endpoints, schema, data formats), create a design/contract task FIRST and make consumers depend on it
|
|
30
|
+
- Include a final QA/verification task if there are user-facing changes
|
|
31
|
+
- Required work only — no optional polish
|
|
32
|
+
|
|
33
|
+
Plans are validated on submission: structural errors (unknown deps, cycles, duplicate IDs, no entry task) are rejected; rule violations come back as ⚠️ warnings in the tool response. **Act on the warnings** — fix them with `squad_modify` `add_task`, or note them for review time. Don't silently ignore them.
|
|
34
|
+
|
|
35
|
+
## Writing Good Task Descriptions
|
|
36
|
+
|
|
37
|
+
When you pass pre-defined `tasks` to the `squad` tool, structure each description with the parts that help (Goal / Context / Output / Boundaries / Verify):
|
|
38
|
+
- **Goal**: the outcome, stated first — not a step-by-step process
|
|
39
|
+
- **Context**: which files, contracts, or dependency outputs to read
|
|
40
|
+
- **Output**: the expected deliverable and format
|
|
41
|
+
- **Boundaries**: what must stay unchanged; what needs escalation instead of guessing
|
|
42
|
+
- **Verify**: the command or check that proves the task is done
|
|
43
|
+
|
|
44
|
+
Scope tasks to required work only. Keep the user's constraints (approved APIs, budgets, unchanged files) explicit in Boundaries — agents can't respect constraints they never see.
|
|
45
|
+
|
|
46
|
+
### Context inheritance (`inheritContext: true`)
|
|
47
|
+
|
|
48
|
+
Agents normally start fresh with only their task description + dependency outputs. Setting `inheritContext: true` on a task forks the current pi session, so the agent inherits this conversation's full context.
|
|
49
|
+
|
|
50
|
+
**Use it when** the task genuinely depends on the discussion — e.g. "implement the design we agreed on above", long requirement threads, or decisions scattered across the conversation that can't be restated briefly.
|
|
51
|
+
|
|
52
|
+
**Avoid it by default**:
|
|
53
|
+
- It's expensive — the agent pays the entire conversation history as input tokens on every turn
|
|
54
|
+
- It's auto-skipped when the estimated session size exceeds 50% of the agent model's context window (a smaller-context model gets NO inherited context, silently degrading to standard behavior — the skip is noted in the task's message log)
|
|
55
|
+
- A well-written task description (Goal/Context/Output/Boundaries/Verify) is usually better than raw history
|
|
56
|
+
|
|
57
|
+
**Rule of thumb**: restate the 3-5 key decisions in the task description first; reach for `inheritContext` only when that's impractical.
|
|
18
58
|
|
|
19
59
|
## When to Use Squad
|
|
20
60
|
|
|
@@ -29,17 +69,42 @@ You are the bridge between the human and the squad. You:
|
|
|
29
69
|
- Simple questions or explanations
|
|
30
70
|
- Tasks a single agent can finish in a few minutes
|
|
31
71
|
|
|
72
|
+
### Squad vs Fleet (when pi-fleet tools are available)
|
|
73
|
+
|
|
74
|
+
If `remote_spawn` / `remote_prompt` / `fleet_status` tools exist in your session, you also have **pi-fleet** (cross-device workers). Division of labor:
|
|
75
|
+
|
|
76
|
+
| Situation | Use |
|
|
77
|
+
|---|---|
|
|
78
|
+
| Parallel work inside THIS repo (agents share the working tree, coordinate on files) | **squad** |
|
|
79
|
+
| Work on another machine, OS, dev-env VM, or different repo; cost/blast-radius isolation | **fleet** (`remote_spawn` + `remote_prompt`) |
|
|
80
|
+
| Big feature locally + validation/deployment on a remote box | **both side by side** — each reports back to you push-based; review each with evidence |
|
|
81
|
+
| Repeated tasks on a remote repo | fleet with `fromBaseline` (warm context) |
|
|
82
|
+
|
|
83
|
+
Rules when combining:
|
|
84
|
+
- Both systems wake you automatically (squad events and `fleet-task-done`) — never poll either
|
|
85
|
+
- Remote work cannot share this repo's working tree: have fleet workers deliver branches/patches, and never assume squad agents can see remote files
|
|
86
|
+
- Review fleet results with `remote_diff`/`remote_read` (costs zero worker tokens) before `remote_accept`
|
|
87
|
+
- If pi-fleet is NOT installed, none of this applies — squad works fully standalone
|
|
88
|
+
|
|
32
89
|
## Monitoring a Running Squad
|
|
33
90
|
|
|
91
|
+
### Never poll — the squad reports to you
|
|
92
|
+
|
|
93
|
+
The `squad` tool is non-blocking and the squad system is **push-based**:
|
|
94
|
+
- **Completion, failure, and escalations wake you automatically** (as `[squad]` messages that trigger your turn)
|
|
95
|
+
- After starting a squad: report the plan to the user and **end your turn**
|
|
96
|
+
- While a squad runs: keep helping the user with other work, or stay idle
|
|
97
|
+
- **NEVER** call `squad_status` in a loop, sleep-wait between checks, or burn turns "monitoring" — that wastes tokens and blocks the user
|
|
98
|
+
|
|
34
99
|
### Passive monitoring (automatic)
|
|
35
100
|
The squad status is injected into your context via `<squad_status>` before each response.
|
|
36
101
|
Read it to stay aware of progress without needing to call tools.
|
|
37
102
|
|
|
38
103
|
### Active monitoring (on-demand)
|
|
39
|
-
Use `squad_status` when:
|
|
104
|
+
Use `squad_status` ONLY when:
|
|
40
105
|
- The user asks "how's the squad doing?"
|
|
41
|
-
- You
|
|
42
|
-
- You want to check a specific squad by ID
|
|
106
|
+
- You were just woken by a squad event and need detail beyond the message
|
|
107
|
+
- You want to check a specific squad by ID at the user's request
|
|
43
108
|
|
|
44
109
|
### What to tell the user
|
|
45
110
|
- Summarize in plain language: "2 of 4 tasks done, tests are running, docs waiting on API"
|
|
@@ -71,6 +136,13 @@ Keep messages **specific and actionable**:
|
|
|
71
136
|
- Good: "Use RS256 for JWT signing. The secret is in env var JWT_SECRET."
|
|
72
137
|
- Bad: "Figure out the auth approach."
|
|
73
138
|
|
|
139
|
+
### Steering a working agent
|
|
140
|
+
Send small, scoped corrections instead of restarting the task:
|
|
141
|
+
- Name exactly what to change and what to keep: "Change only the header component — keep the layout and routes as they are."
|
|
142
|
+
- Add missing information the moment you learn it — don't wait for the agent to get stuck
|
|
143
|
+
- If the user manually edited or reverted files the agent touched, tell the agent immediately so it doesn't overwrite the human's changes
|
|
144
|
+
- If an agent starts doing work that's no longer needed, narrow its scope via `squad_message` or stop it with `squad_modify` `cancel_task` — don't let it burn tokens on obsolete work
|
|
145
|
+
|
|
74
146
|
## Modifying a Running Squad
|
|
75
147
|
|
|
76
148
|
Use `squad_modify` when:
|
|
@@ -80,13 +152,14 @@ Use `squad_modify` when:
|
|
|
80
152
|
- **`pause`** / **`resume`**: Stop/restart the entire squad
|
|
81
153
|
- **`cancel`**: Abort everything (user changed their mind)
|
|
82
154
|
|
|
83
|
-
## After Squad Completes
|
|
155
|
+
## After Squad Completes — Reviewing Completed Work
|
|
84
156
|
|
|
85
|
-
When you receive `[squad] Squad completed
|
|
86
|
-
1.
|
|
87
|
-
2.
|
|
88
|
-
3.
|
|
89
|
-
4.
|
|
157
|
+
When you receive `[squad] Squad completed`, you are the last line of review. Do NOT just relay the summary:
|
|
158
|
+
1. **Check verdicts**: scan task outputs for QA verdicts (`## Verdict: PASS/FAIL/PASS WITH ISSUES`) and note any `PASS WITH ISSUES` minor issues
|
|
159
|
+
2. **Check evidence**: each task's output should include verification evidence (commands + results). If a task claimed done without evidence, run its Verify command yourself (build, test, curl — whatever the task description specified)
|
|
160
|
+
3. **Spot-check integration**: individual tasks passing doesn't guarantee the integrated result works — run the end-to-end check when one exists (app builds, server starts, main flow works)
|
|
161
|
+
4. **Report with evidence**: tell the user what was verified (with the commands/results), and explicitly flag anything unverified or concerning
|
|
162
|
+
5. Suggest next steps if applicable
|
|
90
163
|
|
|
91
164
|
Example:
|
|
92
165
|
> Squad finished all 4 tasks:
|
|
@@ -103,6 +176,7 @@ Example:
|
|
|
103
176
|
|---|---|
|
|
104
177
|
| User asks complex task | Start squad with `squad` tool |
|
|
105
178
|
| User asks "what's happening?" | Read `<squad_status>`, summarize |
|
|
179
|
+
| Squad is running, nothing to do | End your turn — squad events wake you; do NOT poll |
|
|
106
180
|
| Agent escalates | Triage → answer or ask user |
|
|
107
181
|
| User says "tell the backend agent to..." | `squad_message` to that agent |
|
|
108
182
|
| User says "add a task for..." | `squad_modify` with `add_task` |
|
package/src/store.ts
CHANGED
|
@@ -49,6 +49,30 @@ export function getGlobalAgentsDir(): string {
|
|
|
49
49
|
return path.join(SQUAD_HOME, "agents");
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
// ============================================================================
|
|
53
|
+
// Squad Settings (~/.pi/squad/settings.json)
|
|
54
|
+
// ============================================================================
|
|
55
|
+
|
|
56
|
+
import { DEFAULT_SQUAD_SETTINGS, type SquadSettings } from "./types.js";
|
|
57
|
+
|
|
58
|
+
export function getSquadSettingsPath(): string {
|
|
59
|
+
return path.join(SQUAD_HOME, "settings.json");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Load global squad settings, merged over defaults (advisor merged deep) */
|
|
63
|
+
export function loadSquadSettings(): SquadSettings {
|
|
64
|
+
const loaded = readJson<Partial<SquadSettings>>(getSquadSettingsPath());
|
|
65
|
+
return {
|
|
66
|
+
...DEFAULT_SQUAD_SETTINGS,
|
|
67
|
+
...(loaded || {}),
|
|
68
|
+
advisor: { ...DEFAULT_SQUAD_SETTINGS.advisor, ...(loaded?.advisor || {}) },
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function saveSquadSettings(settings: SquadSettings): void {
|
|
73
|
+
writeJsonAtomic(getSquadSettingsPath(), settings);
|
|
74
|
+
}
|
|
75
|
+
|
|
52
76
|
/** Project-local agent directory (overrides global) */
|
|
53
77
|
export function getLocalAgentsDir(projectCwd: string): string {
|
|
54
78
|
return path.join(projectCwd, ".pi", "squad", "agents");
|
|
@@ -245,9 +269,11 @@ export function listSquads(): string[] {
|
|
|
245
269
|
}
|
|
246
270
|
|
|
247
271
|
export function findActiveSquads(): Squad[] {
|
|
272
|
+
// Includes "failed": failure is recoverable (resume resets failed tasks), so
|
|
273
|
+
// failed squads must stay discoverable. All callers filter by status.
|
|
248
274
|
return listSquads()
|
|
249
275
|
.map((id) => loadSquad(id))
|
|
250
|
-
.filter((s): s is Squad => s !== null && (s.status === "running" || s.status === "paused"));
|
|
276
|
+
.filter((s): s is Squad => s !== null && (s.status === "running" || s.status === "paused" || s.status === "failed"));
|
|
251
277
|
}
|
|
252
278
|
|
|
253
279
|
/** List squads filtered by project cwd. If no cwd, returns all. */
|
package/src/types.ts
CHANGED
|
@@ -11,6 +11,8 @@ export interface AgentDef {
|
|
|
11
11
|
description: string;
|
|
12
12
|
/** Override model (null = squad default or pi default) */
|
|
13
13
|
model: string | null;
|
|
14
|
+
/** Thinking level: off, minimal, low, medium, high, xhigh, max (null = pi default) */
|
|
15
|
+
thinking?: string | null;
|
|
14
16
|
/** Override tool list (null = all standard tools) */
|
|
15
17
|
tools: string[] | null;
|
|
16
18
|
/** Tags for planner's automatic agent matching */
|
|
@@ -24,8 +26,47 @@ export interface AgentDef {
|
|
|
24
26
|
/** Agent entry in squad.json — just overrides, references an AgentDef by key */
|
|
25
27
|
export interface SquadAgentEntry {
|
|
26
28
|
model?: string | null;
|
|
29
|
+
thinking?: string | null;
|
|
27
30
|
}
|
|
28
31
|
|
|
32
|
+
/** Valid thinking levels accepted by pi's --thinking flag */
|
|
33
|
+
export const THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"] as const;
|
|
34
|
+
export type ThinkingLevel = (typeof THINKING_LEVELS)[number];
|
|
35
|
+
|
|
36
|
+
// ============================================================================
|
|
37
|
+
// Squad Settings (global, ~/.pi/squad/settings.json)
|
|
38
|
+
// ============================================================================
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Default model/thinking policy for agents whose def doesn't set one.
|
|
42
|
+
* - "main": follow the main pi session's current model / thinking level (default)
|
|
43
|
+
* - "pi-default": let the child pi process resolve its own configured default
|
|
44
|
+
* - any other string: an explicit model id (defaultModel) or thinking level (defaultThinking)
|
|
45
|
+
*/
|
|
46
|
+
export interface SquadSettings {
|
|
47
|
+
defaultModel: string;
|
|
48
|
+
defaultThinking: string;
|
|
49
|
+
advisor: {
|
|
50
|
+
enabled: boolean;
|
|
51
|
+
model: string;
|
|
52
|
+
maxCallsPerTask: number;
|
|
53
|
+
maxTokens: number;
|
|
54
|
+
reasoning: string;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const DEFAULT_SQUAD_SETTINGS: SquadSettings = {
|
|
59
|
+
defaultModel: "main",
|
|
60
|
+
defaultThinking: "main",
|
|
61
|
+
advisor: {
|
|
62
|
+
enabled: true,
|
|
63
|
+
model: "main",
|
|
64
|
+
maxCallsPerTask: 2,
|
|
65
|
+
maxTokens: 8192,
|
|
66
|
+
reasoning: "medium",
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
|
|
29
70
|
// ============================================================================
|
|
30
71
|
// Squad
|
|
31
72
|
// ============================================================================
|
|
@@ -53,6 +94,8 @@ export interface Squad {
|
|
|
53
94
|
status: SquadStatus;
|
|
54
95
|
created: string;
|
|
55
96
|
cwd: string;
|
|
97
|
+
/** Session file of the pi session that created this squad (for inheritContext forks) */
|
|
98
|
+
sessionFile?: string | null;
|
|
56
99
|
/** Agent name → overrides. Keys must exist in .pi/squad/agents/ */
|
|
57
100
|
agents: Record<string, SquadAgentEntry>;
|
|
58
101
|
config: SquadConfig;
|
|
@@ -78,6 +121,9 @@ export interface Task {
|
|
|
78
121
|
agent: string;
|
|
79
122
|
status: TaskStatus;
|
|
80
123
|
depends: string[];
|
|
124
|
+
/** Fork the main pi session so this agent inherits the full conversation context.
|
|
125
|
+
* Skipped automatically if the estimated context exceeds 50% of the agent model's window. */
|
|
126
|
+
inheritContext?: boolean;
|
|
81
127
|
created: string;
|
|
82
128
|
started: string | null;
|
|
83
129
|
completed: string | null;
|
|
@@ -177,7 +223,7 @@ export interface AgentActivity {
|
|
|
177
223
|
modifiedFiles: Set<string>;
|
|
178
224
|
}
|
|
179
225
|
|
|
180
|
-
export type HealthStatus = "healthy" | "idle_warning" | "stuck" | "looping" | "
|
|
226
|
+
export type HealthStatus = "healthy" | "idle_warning" | "stuck" | "looping" | "long_running";
|
|
181
227
|
|
|
182
228
|
// ============================================================================
|
|
183
229
|
// Supervisor
|
|
@@ -196,13 +242,14 @@ export interface SupervisorResult {
|
|
|
196
242
|
// ============================================================================
|
|
197
243
|
|
|
198
244
|
export interface PlannerOutput {
|
|
199
|
-
agents: Record<string, { model?: string }>;
|
|
245
|
+
agents: Record<string, { model?: string; thinking?: string }>;
|
|
200
246
|
tasks: Array<{
|
|
201
247
|
id: string;
|
|
202
248
|
title: string;
|
|
203
249
|
description: string;
|
|
204
250
|
agent: string;
|
|
205
251
|
depends: string[];
|
|
252
|
+
inheritContext?: boolean;
|
|
206
253
|
}>;
|
|
207
254
|
}
|
|
208
255
|
|