c-breakout-claude 1.0.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 +21 -0
- package/README.md +326 -0
- package/bin/c-breakout-cli.js +164 -0
- package/docs/quickstart.md +268 -0
- package/package.json +47 -0
- package/scripts/install.js +55 -0
- package/scripts/uninstall.js +35 -0
- package/skills/c-breakout.md +1410 -0
|
@@ -0,0 +1,1410 @@
|
|
|
1
|
+
# C-Breakout: Distributed Task Execution
|
|
2
|
+
|
|
3
|
+
Break down large tasks and distribute them across independent Claude Code instances, each with its own context budget.
|
|
4
|
+
|
|
5
|
+
## Commands
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
/c-breakout summarize <file-pattern> Summarize files using separate sub-agents
|
|
9
|
+
/c-breakout distribute <task> Break down and distribute a complex task
|
|
10
|
+
/c-breakout orchestrate <project-goal> Orchestrate project with specialized agents (RECOMMENDED)
|
|
11
|
+
/c-breakout tasks Analyze todo list and farm out independent tasks
|
|
12
|
+
/c-breakout status [run-id] Check status of running sub-agents
|
|
13
|
+
/c-breakout results [run-id] Get results from a completed run
|
|
14
|
+
/c-breakout resume <run-id> Resume an interrupted run
|
|
15
|
+
/c-breakout history Show run history for current project
|
|
16
|
+
/c-breakout cancel [run-id] Cancel running sub-agents
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Integration with TodoWrite (Auto-Detection)
|
|
20
|
+
|
|
21
|
+
**CRITICAL: These steps apply automatically after EVERY TodoWrite operation throughout the session.**
|
|
22
|
+
|
|
23
|
+
### After TodoWrite completes:
|
|
24
|
+
|
|
25
|
+
1. **Silently analyze the current todo list:**
|
|
26
|
+
- Group tasks by likely file overlap
|
|
27
|
+
- Identify sequential dependencies (keywords: "after", "once", "then", "test for")
|
|
28
|
+
- Count truly independent groups (no file conflicts, no dependencies)
|
|
29
|
+
|
|
30
|
+
2. **Check trigger conditions:**
|
|
31
|
+
```
|
|
32
|
+
independent_groups = count of groups with no overlaps
|
|
33
|
+
context_percent = current context usage
|
|
34
|
+
|
|
35
|
+
if independent_groups >= 4:
|
|
36
|
+
→ Inform with one-liner (don't ask)
|
|
37
|
+
elif independent_groups == 3:
|
|
38
|
+
→ Ask user
|
|
39
|
+
elif context_percent > 60 AND independent_groups >= 3:
|
|
40
|
+
→ Warn about context and suggest
|
|
41
|
+
else:
|
|
42
|
+
→ Skip (no suggestion)
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
3. **Present suggestion inline:**
|
|
46
|
+
- Don't make it a separate message
|
|
47
|
+
- Add it after the TodoWrite confirmation
|
|
48
|
+
- Keep it brief (one-liner format for 4+ groups)
|
|
49
|
+
|
|
50
|
+
**Example flow:**
|
|
51
|
+
```
|
|
52
|
+
User: Add these 5 tasks to the list
|
|
53
|
+
Claude: [Uses TodoWrite to add tasks]
|
|
54
|
+
Claude: "Todos updated. 💡 I can farm out 4 independent task groups to parallel agents, saving main session context. Run `/c-breakout tasks` when ready.
|
|
55
|
+
|
|
56
|
+
For now, let me start with [task from main session group]..."
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Context-Aware Monitoring
|
|
60
|
+
|
|
61
|
+
**Monitor context usage throughout the session and proactively suggest c-breakout when appropriate.**
|
|
62
|
+
|
|
63
|
+
### When to check:
|
|
64
|
+
- Before starting a large task (reading many files, implementing complex feature)
|
|
65
|
+
- When context feels "heavy" (lots of conversation history, multiple file reads)
|
|
66
|
+
- When user asks for something that will consume significant context
|
|
67
|
+
|
|
68
|
+
### Context-based suggestions:
|
|
69
|
+
|
|
70
|
+
**If context > 60% AND independent tasks exist:**
|
|
71
|
+
```
|
|
72
|
+
⚠️ Context at {X}%. I can offload {N} independent tasks to parallel agents, freeing up ~{Y}% of context. Run `/c-breakout tasks`?
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
**If context > 80%:**
|
|
76
|
+
```
|
|
77
|
+
⚠️ Context critically high at {X}%. Strong recommendation to use `/c-breakout tasks` to offload {N} tasks before continuing.
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**When user requests batch file operations:**
|
|
81
|
+
```
|
|
82
|
+
User: "Read all files in src/components/"
|
|
83
|
+
Claude: [Globs pattern, finds 15 files]
|
|
84
|
+
Claude: "Found 15 files. 💡 I can summarize these in parallel using `/c-breakout summarize src/components/**/*.ts` to preserve context. Want to use c-breakout or read them directly?"
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## Auto-Breakout Guidelines
|
|
90
|
+
|
|
91
|
+
**IMPORTANT: These guidelines apply automatically throughout the session, not just when user explicitly invokes /c-breakout.**
|
|
92
|
+
|
|
93
|
+
### Automatic Detection Triggers
|
|
94
|
+
|
|
95
|
+
**After every TodoWrite operation:**
|
|
96
|
+
1. Analyze the updated todo list for independent task groups
|
|
97
|
+
2. Count groups with no file overlap or sequential dependencies
|
|
98
|
+
3. Apply auto-suggestion rules below
|
|
99
|
+
|
|
100
|
+
**During session when context is high:**
|
|
101
|
+
1. If context usage > 60% AND independent tasks exist → Suggest breakout
|
|
102
|
+
2. If context usage > 80% → Strongly suggest breakout
|
|
103
|
+
|
|
104
|
+
### Auto-Suggestion Rules
|
|
105
|
+
|
|
106
|
+
#### Suggest with one-liner (don't ask, just inform):
|
|
107
|
+
1. **4+ independent task groups** detected
|
|
108
|
+
- Format: "💡 I can farm out {N} independent task groups to parallel agents, saving main session context. Run `/c-breakout tasks` when ready."
|
|
109
|
+
- Then continue working on main session tasks
|
|
110
|
+
|
|
111
|
+
2. **File summarization requested for 5+ files**
|
|
112
|
+
- Format: "💡 I can summarize these {N} files in parallel using `/c-breakout summarize {pattern}` to preserve context."
|
|
113
|
+
- Then ask: "Want me to use c-breakout or read them directly?"
|
|
114
|
+
|
|
115
|
+
3. **User explicitly mentions "parallel", "distribute", or "breakout"**
|
|
116
|
+
- Automatically invoke `/c-breakout` with appropriate mode
|
|
117
|
+
|
|
118
|
+
4. **Context usage > 60% AND 3+ independent tasks available**
|
|
119
|
+
- Format: "⚠️ Context at {X}%. I can offload {N} independent tasks to free up space. Run `/c-breakout tasks`?"
|
|
120
|
+
|
|
121
|
+
#### Ask first (edge cases):
|
|
122
|
+
1. **3 independent task groups** (borderline)
|
|
123
|
+
- Format: "I see 3 independent task groups. Want to use `/c-breakout tasks` to parallelize?"
|
|
124
|
+
|
|
125
|
+
2. **Tasks might have subtle dependencies**
|
|
126
|
+
- Present analysis and ask for confirmation
|
|
127
|
+
|
|
128
|
+
3. **First time suggesting breakout in this session**
|
|
129
|
+
- Add brief explanation: "C-breakout runs tasks in separate sessions, preserving our main context."
|
|
130
|
+
|
|
131
|
+
#### Never auto-suggest:
|
|
132
|
+
1. Tasks have sequential dependencies
|
|
133
|
+
2. Single cohesive feature that shouldn't be split
|
|
134
|
+
3. User is debugging/investigating (needs continuity)
|
|
135
|
+
4. Less than 3 independent units of work
|
|
136
|
+
5. User is in the middle of implementing something
|
|
137
|
+
|
|
138
|
+
### Detailed Suggestion Format
|
|
139
|
+
|
|
140
|
+
When suggesting (4+ groups or high context):
|
|
141
|
+
```
|
|
142
|
+
💡 C-Breakout Opportunity
|
|
143
|
+
|
|
144
|
+
I can distribute {N} independent task groups to parallel agents:
|
|
145
|
+
- Group 1: {task names} → ~{X} files
|
|
146
|
+
- Group 2: {task names} → ~{Y} files
|
|
147
|
+
- Group 3: {task names} → ~{Z} files
|
|
148
|
+
|
|
149
|
+
Keeping in main session:
|
|
150
|
+
- {dependent tasks}
|
|
151
|
+
|
|
152
|
+
This frees up main context and speeds up completion. Run `/c-breakout tasks` when ready.
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
When asking (3 groups or edge cases):
|
|
156
|
+
```
|
|
157
|
+
I notice 3 independent task groups that could run in parallel. Want to use `/c-breakout tasks`?
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## Tracking & History
|
|
163
|
+
|
|
164
|
+
### Directory Structure
|
|
165
|
+
```
|
|
166
|
+
/tmp/c-breakout/
|
|
167
|
+
└── {RUN_ID}/
|
|
168
|
+
├── state.json # Full run state (for resume)
|
|
169
|
+
├── pids.txt # List of sub-agent PIDs
|
|
170
|
+
├── agent_001.json # Output from sub-agent 1
|
|
171
|
+
├── agent_002.json # Output from sub-agent 2
|
|
172
|
+
├── combined_results.md # All results combined
|
|
173
|
+
└── errors.log # Error log for failures
|
|
174
|
+
|
|
175
|
+
{PROJECT_DIR}/.claude/
|
|
176
|
+
├── c-breakout-runs.md # History of all runs for this project
|
|
177
|
+
└── c-breakout-{RUN_ID}.md # Results saved to project
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### state.json format (enables resume)
|
|
181
|
+
```json
|
|
182
|
+
{
|
|
183
|
+
"run_id": "20260109_143022",
|
|
184
|
+
"status": "running|completed|failed|cancelled|interrupted",
|
|
185
|
+
"mode": "summarize|distribute|tasks",
|
|
186
|
+
"project_dir": "/path/to/project",
|
|
187
|
+
"started": "2026-01-09T14:30:22+08:00",
|
|
188
|
+
"completed": null,
|
|
189
|
+
"total_cost": 0.00,
|
|
190
|
+
"config": {
|
|
191
|
+
"max_concurrent": 3,
|
|
192
|
+
"max_retries": 2,
|
|
193
|
+
"batch_size": 5
|
|
194
|
+
},
|
|
195
|
+
"agents": [
|
|
196
|
+
{
|
|
197
|
+
"id": "001",
|
|
198
|
+
"type": "file|task",
|
|
199
|
+
"target": "src/api.ts",
|
|
200
|
+
"description": "Summarize API module",
|
|
201
|
+
"pid": 12345,
|
|
202
|
+
"status": "pending|running|completed|failed|retrying",
|
|
203
|
+
"retries": 0,
|
|
204
|
+
"output_file": "agent_001.json",
|
|
205
|
+
"error": null,
|
|
206
|
+
"started": null,
|
|
207
|
+
"completed": null,
|
|
208
|
+
"cost": 0.00
|
|
209
|
+
}
|
|
210
|
+
],
|
|
211
|
+
"batches": [
|
|
212
|
+
{
|
|
213
|
+
"id": "batch_001",
|
|
214
|
+
"files": ["src/utils/a.ts", "src/utils/b.ts", "src/utils/c.ts"],
|
|
215
|
+
"agent_id": "001"
|
|
216
|
+
}
|
|
217
|
+
]
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
---
|
|
222
|
+
|
|
223
|
+
## Mode: `summarize`
|
|
224
|
+
|
|
225
|
+
**Purpose:** Read multiple files and create concise but comprehensive summaries, each in a separate sub-agent to preserve main session context.
|
|
226
|
+
|
|
227
|
+
**Usage:**
|
|
228
|
+
```
|
|
229
|
+
/c-breakout summarize src/api/*.ts
|
|
230
|
+
/c-breakout summarize src/models/ src/utils/
|
|
231
|
+
/c-breakout summarize package.json tsconfig.json README.md
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
**Steps:**
|
|
235
|
+
|
|
236
|
+
### 1. Resolve files and plan batching
|
|
237
|
+
```bash
|
|
238
|
+
# Expand patterns
|
|
239
|
+
files=$(find {patterns} -type f)
|
|
240
|
+
|
|
241
|
+
# Get file sizes for batching decisions
|
|
242
|
+
for f in $files; do
|
|
243
|
+
wc -l "$f"
|
|
244
|
+
done
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
**Batching rules:**
|
|
248
|
+
- Files < 50 lines: batch up to 10 files per agent
|
|
249
|
+
- Files 50-200 lines: batch up to 5 files per agent
|
|
250
|
+
- Files 200-500 lines: batch up to 3 files per agent
|
|
251
|
+
- Files > 500 lines: 1 file per agent
|
|
252
|
+
|
|
253
|
+
### 2. Create run directory and state
|
|
254
|
+
```bash
|
|
255
|
+
RUN_ID=$(date +%Y%m%d_%H%M%S)
|
|
256
|
+
mkdir -p /tmp/c-breakout/$RUN_ID
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
Initialize state.json with all agents in "pending" status.
|
|
260
|
+
|
|
261
|
+
### 3. Show plan to user
|
|
262
|
+
```
|
|
263
|
+
## C-Breakout: Summarize Mode
|
|
264
|
+
|
|
265
|
+
**Run ID:** {RUN_ID}
|
|
266
|
+
**Files to summarize:** {total_count}
|
|
267
|
+
**Batches:** {batch_count} (batching small files for efficiency)
|
|
268
|
+
|
|
269
|
+
| Batch | Files | Est. Lines |
|
|
270
|
+
|-------|-------|------------|
|
|
271
|
+
| 001 | src/utils/a.ts, b.ts, c.ts | 120 |
|
|
272
|
+
| 002 | src/api.ts | 450 |
|
|
273
|
+
| 003 | src/models.ts | 380 |
|
|
274
|
+
|
|
275
|
+
**Max concurrent agents:** 3
|
|
276
|
+
**Estimated cost:** ~${estimate}
|
|
277
|
+
|
|
278
|
+
Proceed? [Y/n]
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
### 4. Launch sub-agents with concurrency control
|
|
282
|
+
|
|
283
|
+
Launch up to `max_concurrent` agents at a time. As each completes, launch the next pending one.
|
|
284
|
+
|
|
285
|
+
**Sub-agent prompt for file summarization:**
|
|
286
|
+
```
|
|
287
|
+
You are a file analysis sub-agent. Create comprehensive yet concise summaries.
|
|
288
|
+
|
|
289
|
+
## Files to Analyze
|
|
290
|
+
{file_list_with_paths}
|
|
291
|
+
|
|
292
|
+
## Instructions
|
|
293
|
+
1. Read each file completely
|
|
294
|
+
2. Create a structured summary capturing ALL important details
|
|
295
|
+
|
|
296
|
+
## Summary Format (for each file)
|
|
297
|
+
|
|
298
|
+
# {filename}
|
|
299
|
+
|
|
300
|
+
## Purpose
|
|
301
|
+
{1-2 sentence description}
|
|
302
|
+
|
|
303
|
+
## Exports
|
|
304
|
+
- {export}: {description}
|
|
305
|
+
|
|
306
|
+
## Key Functions
|
|
307
|
+
### {functionName}
|
|
308
|
+
- Signature: `{signature}`
|
|
309
|
+
- Purpose: {description}
|
|
310
|
+
- Returns: {return_type}
|
|
311
|
+
|
|
312
|
+
## Data Structures
|
|
313
|
+
### {TypeName}
|
|
314
|
+
{fields}
|
|
315
|
+
|
|
316
|
+
## Dependencies
|
|
317
|
+
- {import}: {usage}
|
|
318
|
+
|
|
319
|
+
## Notes
|
|
320
|
+
{important_details}
|
|
321
|
+
|
|
322
|
+
---
|
|
323
|
+
|
|
324
|
+
Be thorough - capture all public APIs, types, and significant implementation details.
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
**Launch command:**
|
|
328
|
+
```bash
|
|
329
|
+
claude -p "{prompt}" --model haiku --output-format json \
|
|
330
|
+
> /tmp/c-breakout/$RUN_ID/agent_{id}.json 2>&1 &
|
|
331
|
+
echo $! >> /tmp/c-breakout/$RUN_ID/pids.txt
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
### 5. Monitor with progress streaming
|
|
335
|
+
|
|
336
|
+
Poll every 5 seconds:
|
|
337
|
+
```bash
|
|
338
|
+
# Check which PIDs are still running
|
|
339
|
+
for pid in $(cat pids.txt); do
|
|
340
|
+
if ps -p $pid > /dev/null 2>&1; then
|
|
341
|
+
echo "running"
|
|
342
|
+
else
|
|
343
|
+
echo "done"
|
|
344
|
+
fi
|
|
345
|
+
done
|
|
346
|
+
|
|
347
|
+
# Check output files for completion
|
|
348
|
+
for f in agent_*.json; do
|
|
349
|
+
if [ -s "$f" ]; then
|
|
350
|
+
# Parse status from JSON
|
|
351
|
+
jq -r '.is_error // false' "$f"
|
|
352
|
+
fi
|
|
353
|
+
done
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
**Progress display (update in place if possible):**
|
|
357
|
+
```
|
|
358
|
+
C-Breakout Progress: 3/7 agents complete (42%)
|
|
359
|
+
[=========== ]
|
|
360
|
+
- agent_001: completed ✓
|
|
361
|
+
- agent_002: completed ✓
|
|
362
|
+
- agent_003: completed ✓
|
|
363
|
+
- agent_004: running...
|
|
364
|
+
- agent_005: running...
|
|
365
|
+
- agent_006: pending
|
|
366
|
+
- agent_007: pending
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
### 6. Handle errors and retry
|
|
370
|
+
|
|
371
|
+
When an agent fails:
|
|
372
|
+
1. Log error to errors.log
|
|
373
|
+
2. If retries < max_retries, increment and relaunch
|
|
374
|
+
3. If max retries exceeded, mark as failed and continue
|
|
375
|
+
|
|
376
|
+
```bash
|
|
377
|
+
# Check for errors in output
|
|
378
|
+
if jq -e '.is_error == true' agent_001.json > /dev/null; then
|
|
379
|
+
error_msg=$(jq -r '.error_message' agent_001.json)
|
|
380
|
+
echo "[$(date -Iseconds)] agent_001 failed: $error_msg" >> errors.log
|
|
381
|
+
|
|
382
|
+
# Update state for retry
|
|
383
|
+
# Relaunch if retries < max_retries
|
|
384
|
+
fi
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
### 7. Collect and save results
|
|
388
|
+
|
|
389
|
+
After all agents complete (or fail):
|
|
390
|
+
```bash
|
|
391
|
+
# Combine successful results
|
|
392
|
+
for f in agent_*.json; do
|
|
393
|
+
if jq -e '.is_error != true' "$f" > /dev/null 2>&1; then
|
|
394
|
+
jq -r '.result' "$f"
|
|
395
|
+
echo -e "\n---\n"
|
|
396
|
+
fi
|
|
397
|
+
done > combined_results.md
|
|
398
|
+
|
|
399
|
+
# Calculate total cost
|
|
400
|
+
total_cost=$(jq -s 'map(.total_cost_usd // 0) | add' agent_*.json)
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
### 8. Save to project and update history
|
|
404
|
+
|
|
405
|
+
```bash
|
|
406
|
+
# Save results to project
|
|
407
|
+
cp combined_results.md "{PROJECT_DIR}/.claude/c-breakout-$RUN_ID.md"
|
|
408
|
+
|
|
409
|
+
# Update history (prepend to c-breakout-runs.md)
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
### 9. Display final report
|
|
413
|
+
```
|
|
414
|
+
## C-Breakout Complete
|
|
415
|
+
|
|
416
|
+
**Run ID:** {RUN_ID}
|
|
417
|
+
**Mode:** Summarize
|
|
418
|
+
**Status:** {completed|completed_with_errors}
|
|
419
|
+
|
|
420
|
+
| Metric | Value |
|
|
421
|
+
|--------|-------|
|
|
422
|
+
| Files processed | {count} |
|
|
423
|
+
| Successful | {success_count} |
|
|
424
|
+
| Failed | {fail_count} |
|
|
425
|
+
| Total cost | ${total_cost} |
|
|
426
|
+
| Duration | {duration} |
|
|
427
|
+
|
|
428
|
+
**Results saved to:**
|
|
429
|
+
- {PROJECT_DIR}/.claude/c-breakout-{RUN_ID}.md
|
|
430
|
+
|
|
431
|
+
{if errors}
|
|
432
|
+
**Errors encountered:**
|
|
433
|
+
- agent_003: {error_message}
|
|
434
|
+
- agent_005: {error_message}
|
|
435
|
+
{/if}
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
---
|
|
439
|
+
|
|
440
|
+
## Mode: `tasks`
|
|
441
|
+
|
|
442
|
+
**Purpose:** Analyze the current todo list, identify independent task groups, and farm them out to sub-agents while keeping dependent tasks in the main session.
|
|
443
|
+
|
|
444
|
+
**Usage:**
|
|
445
|
+
```
|
|
446
|
+
/c-breakout tasks
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
**Steps:**
|
|
450
|
+
|
|
451
|
+
### 1. Read current todo list
|
|
452
|
+
|
|
453
|
+
Access the current todo list from the conversation context.
|
|
454
|
+
|
|
455
|
+
### 2. Analyze task dependencies
|
|
456
|
+
|
|
457
|
+
For each task, determine:
|
|
458
|
+
1. **Files it will likely touch** (infer from task description)
|
|
459
|
+
2. **Dependencies on other tasks** (must task X complete before task Y?)
|
|
460
|
+
3. **Groupings** (related tasks that should stay together)
|
|
461
|
+
|
|
462
|
+
**Dependency indicators:**
|
|
463
|
+
- "after", "once", "when X is done" → sequential dependency
|
|
464
|
+
- Same file modifications → should be same agent or sequential
|
|
465
|
+
- "test for X", "verify X" → depends on X
|
|
466
|
+
- Shared state/context requirements → same session
|
|
467
|
+
|
|
468
|
+
### 3. Form independent groups
|
|
469
|
+
|
|
470
|
+
```
|
|
471
|
+
Analysis of 8 todo items:
|
|
472
|
+
|
|
473
|
+
Group A (Main Session - has dependencies):
|
|
474
|
+
- Task 1: Add login endpoint
|
|
475
|
+
- Task 2: Add logout endpoint
|
|
476
|
+
- Task 3: Write auth tests (depends on 1,2)
|
|
477
|
+
Files: src/auth/*.ts, tests/auth.test.ts
|
|
478
|
+
Reason: Internal dependencies, should stay sequential
|
|
479
|
+
|
|
480
|
+
Group B (Can distribute):
|
|
481
|
+
- Task 4: Refactor database models
|
|
482
|
+
Files: src/models/*.ts
|
|
483
|
+
Reason: Independent, no overlap
|
|
484
|
+
|
|
485
|
+
Group C (Can distribute):
|
|
486
|
+
- Task 5: Add pagination to API
|
|
487
|
+
- Task 6: Add sorting to API
|
|
488
|
+
Files: src/api/list.ts, src/api/utils.ts
|
|
489
|
+
Reason: Related but independent of other groups
|
|
490
|
+
|
|
491
|
+
Group D (Can distribute):
|
|
492
|
+
- Task 7: Update README
|
|
493
|
+
- Task 8: Add JSDoc comments to utils
|
|
494
|
+
Files: README.md, src/utils/*.ts
|
|
495
|
+
Reason: Documentation, independent
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
### 4. Present plan to user
|
|
499
|
+
|
|
500
|
+
```
|
|
501
|
+
## C-Breakout: Tasks Mode
|
|
502
|
+
|
|
503
|
+
**Run ID:** {RUN_ID}
|
|
504
|
+
**Todo items analyzed:** 8
|
|
505
|
+
**Independent groups found:** 3 (can run in parallel)
|
|
506
|
+
|
|
507
|
+
### Main Session (keeping these - have dependencies)
|
|
508
|
+
- Task 1: Add login endpoint
|
|
509
|
+
- Task 2: Add logout endpoint
|
|
510
|
+
- Task 3: Write auth tests
|
|
511
|
+
|
|
512
|
+
### Distributing to Sub-Agents
|
|
513
|
+
|
|
514
|
+
| Group | Tasks | Files | Agent |
|
|
515
|
+
|-------|-------|-------|-------|
|
|
516
|
+
| B | Refactor database models | src/models/*.ts | 001 |
|
|
517
|
+
| C | Add pagination, Add sorting | src/api/*.ts | 002 |
|
|
518
|
+
| D | Update README, Add JSDoc | README.md, src/utils/*.ts | 003 |
|
|
519
|
+
|
|
520
|
+
**Potential conflicts:** None detected
|
|
521
|
+
**Estimated cost:** ~${estimate}
|
|
522
|
+
|
|
523
|
+
Proceed? [Y/n]
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
### 5. Launch task agents
|
|
527
|
+
|
|
528
|
+
**Sub-agent prompt for task execution:**
|
|
529
|
+
```
|
|
530
|
+
You are a task execution sub-agent working on a specific part of a larger project.
|
|
531
|
+
|
|
532
|
+
## Working Directory
|
|
533
|
+
{absolute_path}
|
|
534
|
+
|
|
535
|
+
## Your Tasks
|
|
536
|
+
{numbered_list_of_tasks}
|
|
537
|
+
|
|
538
|
+
## Context
|
|
539
|
+
{relevant_background_from_main_session}
|
|
540
|
+
|
|
541
|
+
## Files You May Modify
|
|
542
|
+
{list_of_files_for_this_group}
|
|
543
|
+
|
|
544
|
+
## Files You Must NOT Modify (assigned to other agents)
|
|
545
|
+
{files_for_other_groups}
|
|
546
|
+
|
|
547
|
+
## Acceptance Criteria
|
|
548
|
+
{specific_criteria_per_task}
|
|
549
|
+
|
|
550
|
+
## Instructions
|
|
551
|
+
1. Read any additional files needed for context
|
|
552
|
+
2. Implement each task completely
|
|
553
|
+
3. Verify your changes work (run relevant tests if applicable)
|
|
554
|
+
4. Output a summary of what you changed per task
|
|
555
|
+
|
|
556
|
+
Format your final output as:
|
|
557
|
+
|
|
558
|
+
## Task: {task_name}
|
|
559
|
+
**Status:** Complete|Partial|Failed
|
|
560
|
+
**Files changed:**
|
|
561
|
+
- {file}: {what_changed}
|
|
562
|
+
**Notes:** {any_issues_or_decisions}
|
|
563
|
+
|
|
564
|
+
---
|
|
565
|
+
|
|
566
|
+
Begin now.
|
|
567
|
+
```
|
|
568
|
+
|
|
569
|
+
### 6. Update main session todo list
|
|
570
|
+
|
|
571
|
+
After launching sub-agents:
|
|
572
|
+
1. Mark distributed tasks as "distributed to c-breakout {RUN_ID}"
|
|
573
|
+
2. Keep only main session tasks active
|
|
574
|
+
3. Continue working on main session tasks
|
|
575
|
+
|
|
576
|
+
### 7. Collect results and reconcile
|
|
577
|
+
|
|
578
|
+
When sub-agents complete:
|
|
579
|
+
1. Parse their outputs
|
|
580
|
+
2. Update todo list with completion status
|
|
581
|
+
3. Apply any file changes (verify no conflicts)
|
|
582
|
+
4. Report results
|
|
583
|
+
|
|
584
|
+
---
|
|
585
|
+
|
|
586
|
+
## Mode: `distribute`
|
|
587
|
+
|
|
588
|
+
**Purpose:** Break a complex task into independent sub-tasks, each executed by a separate sub-agent.
|
|
589
|
+
|
|
590
|
+
**Usage:**
|
|
591
|
+
```
|
|
592
|
+
/c-breakout distribute Implement user authentication with login, logout, and session management
|
|
593
|
+
/c-breakout distribute Refactor the API layer to use consistent error handling
|
|
594
|
+
```
|
|
595
|
+
|
|
596
|
+
**Steps:**
|
|
597
|
+
|
|
598
|
+
### 1. Analyze the task
|
|
599
|
+
- Read relevant files to understand scope
|
|
600
|
+
- Identify natural decomposition points
|
|
601
|
+
- Check for dependencies
|
|
602
|
+
|
|
603
|
+
### 2. Decompose into sub-tasks
|
|
604
|
+
|
|
605
|
+
Each sub-task must be:
|
|
606
|
+
- **Self-contained:** Completable without other sub-tasks
|
|
607
|
+
- **Independent:** Minimal file overlap with other sub-tasks
|
|
608
|
+
- **Clear:** Specific files and acceptance criteria
|
|
609
|
+
|
|
610
|
+
### 3. Present breakdown
|
|
611
|
+
```
|
|
612
|
+
## C-Breakout: Distribute Mode
|
|
613
|
+
|
|
614
|
+
**Run ID:** {RUN_ID}
|
|
615
|
+
**Original task:** {task}
|
|
616
|
+
|
|
617
|
+
**Sub-tasks:**
|
|
618
|
+
|
|
619
|
+
| # | Task | Files | Deliverable |
|
|
620
|
+
|---|------|-------|-------------|
|
|
621
|
+
| 1 | Create user model and migrations | src/models/user.ts, migrations/ | User schema |
|
|
622
|
+
| 2 | Implement auth service | src/services/auth.ts | Login/logout logic |
|
|
623
|
+
| 3 | Add auth API endpoints | src/api/auth.ts | REST endpoints |
|
|
624
|
+
| 4 | Write auth tests | tests/auth.test.ts | Test coverage |
|
|
625
|
+
|
|
626
|
+
**Dependencies:** Task 4 depends on 1-3 (will run after others complete)
|
|
627
|
+
**Parallel tasks:** 1, 2, 3
|
|
628
|
+
**Sequential tasks:** 4
|
|
629
|
+
|
|
630
|
+
Proceed? [Y/n]
|
|
631
|
+
```
|
|
632
|
+
|
|
633
|
+
### 4. Execute with dependency awareness
|
|
634
|
+
|
|
635
|
+
1. Launch independent tasks in parallel
|
|
636
|
+
2. Wait for dependencies before launching dependent tasks
|
|
637
|
+
3. Track progress and handle errors
|
|
638
|
+
|
|
639
|
+
### 5. Collect and integrate results
|
|
640
|
+
|
|
641
|
+
---
|
|
642
|
+
|
|
643
|
+
## Mode: `orchestrate`
|
|
644
|
+
|
|
645
|
+
**Purpose:** Intelligently orchestrate complex projects using specialized agents with minimal context overhead. The orchestrator analyzes the project, classifies tasks by type, and assigns specialized agents with only the tools they need.
|
|
646
|
+
|
|
647
|
+
**Usage:**
|
|
648
|
+
```
|
|
649
|
+
/c-breakout orchestrate "Implement user authentication system"
|
|
650
|
+
/c-breakout orchestrate "Refactor backend API and add comprehensive tests"
|
|
651
|
+
/c-breakout orchestrate "Deploy application with CI/CD pipeline"
|
|
652
|
+
```
|
|
653
|
+
|
|
654
|
+
**Benefits:**
|
|
655
|
+
- **43-50% token reduction** vs standard distribute mode
|
|
656
|
+
- **Better reliability** - Agents only have access to tools they need
|
|
657
|
+
- **Scalable** - Can handle 100+ tasks efficiently
|
|
658
|
+
- **Cost optimized** - Uses Haiku for specialized agents, Sonnet for orchestrator
|
|
659
|
+
|
|
660
|
+
**Architecture:**
|
|
661
|
+
```
|
|
662
|
+
ORCHESTRATOR (Sonnet, full context)
|
|
663
|
+
├─→ PLANNER agents (Haiku, Read/Grep/WebSearch)
|
|
664
|
+
├─→ DEV agents (Haiku, Read/Write/Edit/Bash)
|
|
665
|
+
└─→ DEPLOY agents (Haiku, Bash/Read)
|
|
666
|
+
```
|
|
667
|
+
|
|
668
|
+
---
|
|
669
|
+
|
|
670
|
+
### Phase 1: Orchestrator Planning
|
|
671
|
+
|
|
672
|
+
**Step 1: Create run directory and initialize**
|
|
673
|
+
```bash
|
|
674
|
+
RUN_ID=$(date +%Y%m%d_%H%M%S)
|
|
675
|
+
mkdir -p /tmp/c-breakout/$RUN_ID
|
|
676
|
+
```
|
|
677
|
+
|
|
678
|
+
**Step 2: Launch orchestrator agent**
|
|
679
|
+
|
|
680
|
+
The orchestrator is a full-context Sonnet agent that analyzes the project and creates an execution plan.
|
|
681
|
+
|
|
682
|
+
**Orchestrator prompt:**
|
|
683
|
+
```
|
|
684
|
+
You are the C-Breakout Orchestrator Agent for distributed project execution.
|
|
685
|
+
|
|
686
|
+
## Project Goal
|
|
687
|
+
{project_goal}
|
|
688
|
+
|
|
689
|
+
## Your Mission
|
|
690
|
+
Analyze this project and create a detailed execution plan with specialized agents.
|
|
691
|
+
|
|
692
|
+
## Steps
|
|
693
|
+
|
|
694
|
+
### 1. Project Analysis
|
|
695
|
+
- Read relevant project files to understand current state
|
|
696
|
+
- Identify scope and requirements
|
|
697
|
+
- List all files that will be involved
|
|
698
|
+
|
|
699
|
+
### 2. Create Work Breakdown Structure (WBS)
|
|
700
|
+
Break the project into discrete tasks. Each task should be:
|
|
701
|
+
- Clear and actionable
|
|
702
|
+
- Testable/verifiable
|
|
703
|
+
- Estimated effort (S/M/L)
|
|
704
|
+
|
|
705
|
+
### 3. Classify Tasks by Agent Type
|
|
706
|
+
|
|
707
|
+
**PLANNER agents** (Research, exploration, analysis)
|
|
708
|
+
- Tools: Read, Grep, Glob, WebSearch
|
|
709
|
+
- Use for: Understanding codebase, research, architecture decisions
|
|
710
|
+
- Examples: "Analyze current auth implementation", "Research best practices"
|
|
711
|
+
|
|
712
|
+
**DEV agents** (Implementation, testing)
|
|
713
|
+
- Tools: Read, Write, Edit, Bash
|
|
714
|
+
- Use for: Writing code, implementing features, running tests
|
|
715
|
+
- Examples: "Implement login endpoint", "Write unit tests"
|
|
716
|
+
|
|
717
|
+
**DEPLOY agents** (Deployment, operations)
|
|
718
|
+
- Tools: Bash, Read
|
|
719
|
+
- Use for: Running commands, deployment scripts, CI/CD
|
|
720
|
+
- Examples: "Deploy to staging", "Run migrations"
|
|
721
|
+
|
|
722
|
+
### 4. Identify Dependencies
|
|
723
|
+
Mark which tasks must complete before others can start.
|
|
724
|
+
Use format: "Task X blocks Task Y"
|
|
725
|
+
|
|
726
|
+
### 5. Generate Agent Prompts
|
|
727
|
+
For each task, create a focused prompt that includes:
|
|
728
|
+
- Task description
|
|
729
|
+
- Relevant file paths
|
|
730
|
+
- Acceptance criteria
|
|
731
|
+
- Any context from project analysis
|
|
732
|
+
|
|
733
|
+
### 6. Output Execution Plan
|
|
734
|
+
|
|
735
|
+
Output a JSON plan in this exact format:
|
|
736
|
+
|
|
737
|
+
{
|
|
738
|
+
"project_goal": "...",
|
|
739
|
+
"analysis_summary": "Brief summary of project state",
|
|
740
|
+
"agents": {
|
|
741
|
+
"planner": [
|
|
742
|
+
{
|
|
743
|
+
"id": "P001",
|
|
744
|
+
"task": "Task description",
|
|
745
|
+
"prompt": "Full prompt for agent",
|
|
746
|
+
"files": ["file1.ts", "file2.ts"],
|
|
747
|
+
"estimated_tokens": 5000,
|
|
748
|
+
"blocks": []
|
|
749
|
+
}
|
|
750
|
+
],
|
|
751
|
+
"dev": [
|
|
752
|
+
{
|
|
753
|
+
"id": "D001",
|
|
754
|
+
"task": "Task description",
|
|
755
|
+
"prompt": "Full prompt for agent",
|
|
756
|
+
"files": ["file1.ts"],
|
|
757
|
+
"estimated_tokens": 8000,
|
|
758
|
+
"blocks": ["P001"]
|
|
759
|
+
}
|
|
760
|
+
],
|
|
761
|
+
"deploy": [
|
|
762
|
+
{
|
|
763
|
+
"id": "DPL001",
|
|
764
|
+
"task": "Task description",
|
|
765
|
+
"prompt": "Full prompt for agent",
|
|
766
|
+
"files": [],
|
|
767
|
+
"estimated_tokens": 3000,
|
|
768
|
+
"blocks": ["D001", "D002"]
|
|
769
|
+
}
|
|
770
|
+
]
|
|
771
|
+
},
|
|
772
|
+
"execution_order": [
|
|
773
|
+
["P001", "P002"], // Wave 1: parallel
|
|
774
|
+
["D001", "D002", "D003"], // Wave 2: parallel (after wave 1)
|
|
775
|
+
["DPL001"] // Wave 3: sequential (after wave 2)
|
|
776
|
+
],
|
|
777
|
+
"estimated_cost": {
|
|
778
|
+
"orchestrator": 0.05,
|
|
779
|
+
"planner_agents": 0.10,
|
|
780
|
+
"dev_agents": 0.40,
|
|
781
|
+
"deploy_agents": 0.05,
|
|
782
|
+
"total": 0.60
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
## Critical Guidelines
|
|
787
|
+
- Be thorough in project analysis - read key files
|
|
788
|
+
- Create specific, actionable tasks
|
|
789
|
+
- Classify agents correctly based on tools needed
|
|
790
|
+
- Identify all dependencies to avoid conflicts
|
|
791
|
+
- Keep agent prompts focused and clear
|
|
792
|
+
|
|
793
|
+
Begin analysis now.
|
|
794
|
+
```
|
|
795
|
+
|
|
796
|
+
**Step 3: Execute orchestrator**
|
|
797
|
+
```bash
|
|
798
|
+
claude --model sonnet \
|
|
799
|
+
-p "$ORCHESTRATOR_PROMPT" \
|
|
800
|
+
--output-format json \
|
|
801
|
+
> /tmp/c-breakout/$RUN_ID/plan.json 2>&1
|
|
802
|
+
```
|
|
803
|
+
|
|
804
|
+
**Step 4: Parse and present plan to user**
|
|
805
|
+
```bash
|
|
806
|
+
python3 << 'EOF'
|
|
807
|
+
import json
|
|
808
|
+
|
|
809
|
+
with open(f'/tmp/c-breakout/{RUN_ID}/plan.json') as f:
|
|
810
|
+
data = json.load(f)
|
|
811
|
+
plan = json.loads(data['result'])
|
|
812
|
+
|
|
813
|
+
print("## C-Breakout: Orchestrate Mode")
|
|
814
|
+
print(f"\n**Run ID:** {RUN_ID}")
|
|
815
|
+
print(f"**Project Goal:** {plan['project_goal']}")
|
|
816
|
+
print(f"\n**Analysis:** {plan['analysis_summary']}")
|
|
817
|
+
print("\n### Specialized Agents\n")
|
|
818
|
+
print(f"| Type | Count | Tools | Est. Cost |")
|
|
819
|
+
print(f"|------|-------|-------|-----------|")
|
|
820
|
+
print(f"| Planner | {len(plan['agents']['planner'])} | Read, Grep, WebSearch | ${plan['estimated_cost']['planner_agents']:.2f} |")
|
|
821
|
+
print(f"| Dev | {len(plan['agents']['dev'])} | Read, Write, Edit, Bash | ${plan['estimated_cost']['dev_agents']:.2f} |")
|
|
822
|
+
print(f"| Deploy | {len(plan['agents']['deploy'])} | Bash, Read | ${plan['estimated_cost']['deploy_agents']:.2f} |")
|
|
823
|
+
print(f"\n**Total Cost:** ${plan['estimated_cost']['total']:.2f}")
|
|
824
|
+
print(f"**Orchestrator Cost:** ${plan['estimated_cost']['orchestrator']:.2f}")
|
|
825
|
+
print(f"\n**Execution Waves:** {len(plan['execution_order'])}")
|
|
826
|
+
|
|
827
|
+
# Show task breakdown
|
|
828
|
+
print("\n### Tasks by Agent Type\n")
|
|
829
|
+
for agent_type in ['planner', 'dev', 'deploy']:
|
|
830
|
+
if plan['agents'][agent_type]:
|
|
831
|
+
print(f"\n**{agent_type.upper()} AGENTS:**")
|
|
832
|
+
for agent in plan['agents'][agent_type]:
|
|
833
|
+
deps = f" (blocked by: {', '.join(agent['blocks'])})" if agent['blocks'] else ""
|
|
834
|
+
print(f" • [{agent['id']}] {agent['task']}{deps}")
|
|
835
|
+
|
|
836
|
+
print("\nProceed with execution? [Y/n]")
|
|
837
|
+
EOF
|
|
838
|
+
```
|
|
839
|
+
|
|
840
|
+
---
|
|
841
|
+
|
|
842
|
+
### Phase 2: Execute Specialized Agents
|
|
843
|
+
|
|
844
|
+
**Step 1: Save plan to state**
|
|
845
|
+
```bash
|
|
846
|
+
# Save full plan to state.json
|
|
847
|
+
python3 << EOF
|
|
848
|
+
import json
|
|
849
|
+
|
|
850
|
+
with open('/tmp/c-breakout/$RUN_ID/plan.json') as f:
|
|
851
|
+
plan_data = json.load(f)
|
|
852
|
+
plan = json.loads(plan_data['result'])
|
|
853
|
+
|
|
854
|
+
# Create state.json with all agents
|
|
855
|
+
state = {
|
|
856
|
+
"run_id": "$RUN_ID",
|
|
857
|
+
"status": "running",
|
|
858
|
+
"mode": "orchestrate",
|
|
859
|
+
"project_dir": "$(pwd)",
|
|
860
|
+
"started": "$(date -Iseconds)",
|
|
861
|
+
"completed": None,
|
|
862
|
+
"total_cost": 0.00,
|
|
863
|
+
"orchestrator_cost": plan_data['total_cost_usd'],
|
|
864
|
+
"config": {
|
|
865
|
+
"max_concurrent": 100,
|
|
866
|
+
"max_retries": 2
|
|
867
|
+
},
|
|
868
|
+
"plan": plan,
|
|
869
|
+
"agents": []
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
# Add all agents from plan
|
|
873
|
+
for agent_type in ['planner', 'dev', 'deploy']:
|
|
874
|
+
for agent_spec in plan['agents'][agent_type]:
|
|
875
|
+
state['agents'].append({
|
|
876
|
+
"id": agent_spec['id'],
|
|
877
|
+
"type": agent_type,
|
|
878
|
+
"task": agent_spec['task'],
|
|
879
|
+
"prompt": agent_spec['prompt'],
|
|
880
|
+
"files": agent_spec['files'],
|
|
881
|
+
"blocks": agent_spec['blocks'],
|
|
882
|
+
"pid": None,
|
|
883
|
+
"status": "pending",
|
|
884
|
+
"retries": 0,
|
|
885
|
+
"output_file": f"agent_{agent_spec['id']}.json",
|
|
886
|
+
"error": None,
|
|
887
|
+
"started": None,
|
|
888
|
+
"completed": None,
|
|
889
|
+
"cost": 0.00
|
|
890
|
+
})
|
|
891
|
+
|
|
892
|
+
with open('/tmp/c-breakout/$RUN_ID/state.json', 'w') as f:
|
|
893
|
+
json.dump(state, f, indent=2)
|
|
894
|
+
|
|
895
|
+
print(f"State initialized with {len(state['agents'])} agents")
|
|
896
|
+
EOF
|
|
897
|
+
```
|
|
898
|
+
|
|
899
|
+
**Step 2: Launch agents by wave**
|
|
900
|
+
|
|
901
|
+
Execute agents in waves according to dependencies:
|
|
902
|
+
|
|
903
|
+
```bash
|
|
904
|
+
# Agent launch function with specialized tools
|
|
905
|
+
launch_specialized_agent() {
|
|
906
|
+
local agent_id=$1
|
|
907
|
+
local agent_type=$2
|
|
908
|
+
local prompt=$3
|
|
909
|
+
local output_file=$4
|
|
910
|
+
|
|
911
|
+
# Determine tool allowlist based on agent type
|
|
912
|
+
case $agent_type in
|
|
913
|
+
planner)
|
|
914
|
+
tools="Read,Grep,Glob,WebSearch"
|
|
915
|
+
;;
|
|
916
|
+
dev)
|
|
917
|
+
tools="Read,Write,Edit,Bash,Grep,Glob"
|
|
918
|
+
;;
|
|
919
|
+
deploy)
|
|
920
|
+
tools="Bash,Read"
|
|
921
|
+
;;
|
|
922
|
+
esac
|
|
923
|
+
|
|
924
|
+
# Launch with minimal context
|
|
925
|
+
echo "$prompt" | claude \
|
|
926
|
+
--model haiku \
|
|
927
|
+
--allowed-tools "$tools" \
|
|
928
|
+
--disable-slash-commands \
|
|
929
|
+
--no-session-persistence \
|
|
930
|
+
--output-format json \
|
|
931
|
+
--print \
|
|
932
|
+
> "$output_file" 2>&1 &
|
|
933
|
+
|
|
934
|
+
local pid=$!
|
|
935
|
+
echo "$pid" >> /tmp/c-breakout/$RUN_ID/pids.txt
|
|
936
|
+
|
|
937
|
+
# Update state with PID
|
|
938
|
+
python3 << PYEOF
|
|
939
|
+
import json
|
|
940
|
+
with open('/tmp/c-breakout/$RUN_ID/state.json', 'r+') as f:
|
|
941
|
+
state = json.load(f)
|
|
942
|
+
for agent in state['agents']:
|
|
943
|
+
if agent['id'] == '$agent_id':
|
|
944
|
+
agent['pid'] = $pid
|
|
945
|
+
agent['status'] = 'running'
|
|
946
|
+
agent['started'] = '$(date -Iseconds)'
|
|
947
|
+
break
|
|
948
|
+
f.seek(0)
|
|
949
|
+
json.dump(state, f, indent=2)
|
|
950
|
+
f.truncate()
|
|
951
|
+
PYEOF
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
# Execute waves
|
|
955
|
+
python3 << 'WAVEPY'
|
|
956
|
+
import json
|
|
957
|
+
import subprocess
|
|
958
|
+
import time
|
|
959
|
+
|
|
960
|
+
with open('/tmp/c-breakout/$RUN_ID/state.json') as f:
|
|
961
|
+
state = json.load(f)
|
|
962
|
+
|
|
963
|
+
plan = state['plan']
|
|
964
|
+
agents_by_id = {a['id']: a for a in state['agents']}
|
|
965
|
+
|
|
966
|
+
print(f"Executing {len(plan['execution_order'])} waves...")
|
|
967
|
+
|
|
968
|
+
for wave_num, wave in enumerate(plan['execution_order'], 1):
|
|
969
|
+
print(f"\n=== Wave {wave_num}/{len(plan['execution_order'])} ===")
|
|
970
|
+
print(f"Launching {len(wave)} agents in parallel...")
|
|
971
|
+
|
|
972
|
+
# Launch all agents in this wave
|
|
973
|
+
for agent_id in wave:
|
|
974
|
+
agent = agents_by_id[agent_id]
|
|
975
|
+
print(f" • Launching [{agent_id}] {agent['task'][:50]}...")
|
|
976
|
+
|
|
977
|
+
subprocess.run([
|
|
978
|
+
'bash', '-c',
|
|
979
|
+
f"launch_specialized_agent '{agent_id}' '{agent['type']}' '{agent['prompt']}' '/tmp/c-breakout/$RUN_ID/agent_{agent_id}.json'"
|
|
980
|
+
])
|
|
981
|
+
|
|
982
|
+
# Wait for wave to complete
|
|
983
|
+
print(f"Waiting for wave {wave_num} to complete...")
|
|
984
|
+
all_done = False
|
|
985
|
+
while not all_done:
|
|
986
|
+
time.sleep(5)
|
|
987
|
+
all_done = True
|
|
988
|
+
for agent_id in wave:
|
|
989
|
+
pid = agents_by_id[agent_id]['pid']
|
|
990
|
+
try:
|
|
991
|
+
subprocess.run(['ps', '-p', str(pid)], check=True, capture_output=True)
|
|
992
|
+
all_done = False
|
|
993
|
+
except:
|
|
994
|
+
pass
|
|
995
|
+
|
|
996
|
+
print(f"✓ Wave {wave_num} complete")
|
|
997
|
+
|
|
998
|
+
print("\n✓ All waves complete!")
|
|
999
|
+
WAVEPY
|
|
1000
|
+
```
|
|
1001
|
+
|
|
1002
|
+
**Step 3: Monitor progress**
|
|
1003
|
+
|
|
1004
|
+
Display real-time progress as agents complete:
|
|
1005
|
+
|
|
1006
|
+
```bash
|
|
1007
|
+
# Progress monitor (runs in background)
|
|
1008
|
+
monitor_progress() {
|
|
1009
|
+
while true; do
|
|
1010
|
+
python3 << 'PY'
|
|
1011
|
+
import json
|
|
1012
|
+
import os
|
|
1013
|
+
|
|
1014
|
+
with open('/tmp/c-breakout/$RUN_ID/state.json') as f:
|
|
1015
|
+
state = json.load(f)
|
|
1016
|
+
|
|
1017
|
+
total = len(state['agents'])
|
|
1018
|
+
completed = sum(1 for a in state['agents'] if a['status'] == 'completed')
|
|
1019
|
+
running = sum(1 for a in state['agents'] if a['status'] == 'running')
|
|
1020
|
+
failed = sum(1 for a in state['agents'] if a['status'] == 'failed')
|
|
1021
|
+
|
|
1022
|
+
progress = (completed / total * 100) if total > 0 else 0
|
|
1023
|
+
|
|
1024
|
+
print(f"\rProgress: {completed}/{total} ({progress:.0f}%) | Running: {running} | Failed: {failed}", end='', flush=True)
|
|
1025
|
+
PY
|
|
1026
|
+
sleep 5
|
|
1027
|
+
|
|
1028
|
+
# Check if all done
|
|
1029
|
+
if [ $(grep -c '"status": "completed"' /tmp/c-breakout/$RUN_ID/state.json) -eq $(jq '.agents | length' /tmp/c-breakout/$RUN_ID/state.json) ]; then
|
|
1030
|
+
break
|
|
1031
|
+
fi
|
|
1032
|
+
done
|
|
1033
|
+
}
|
|
1034
|
+
```
|
|
1035
|
+
|
|
1036
|
+
---
|
|
1037
|
+
|
|
1038
|
+
### Phase 3: Aggregate Results
|
|
1039
|
+
|
|
1040
|
+
**Step 1: Collect agent outputs**
|
|
1041
|
+
```bash
|
|
1042
|
+
python3 << 'EOF'
|
|
1043
|
+
import json
|
|
1044
|
+
import os
|
|
1045
|
+
|
|
1046
|
+
run_dir = f'/tmp/c-breakout/{RUN_ID}'
|
|
1047
|
+
|
|
1048
|
+
# Load state
|
|
1049
|
+
with open(f'{run_dir}/state.json') as f:
|
|
1050
|
+
state = json.load(f)
|
|
1051
|
+
|
|
1052
|
+
results = {
|
|
1053
|
+
'planner': [],
|
|
1054
|
+
'dev': [],
|
|
1055
|
+
'deploy': []
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
total_cost = state['orchestrator_cost']
|
|
1059
|
+
|
|
1060
|
+
# Collect results from each agent
|
|
1061
|
+
for agent in state['agents']:
|
|
1062
|
+
output_file = f"{run_dir}/{agent['output_file']}"
|
|
1063
|
+
if os.path.exists(output_file):
|
|
1064
|
+
with open(output_file) as f:
|
|
1065
|
+
output = json.load(f)
|
|
1066
|
+
if not output.get('is_error'):
|
|
1067
|
+
results[agent['type']].append({
|
|
1068
|
+
'id': agent['id'],
|
|
1069
|
+
'task': agent['task'],
|
|
1070
|
+
'result': output.get('result', ''),
|
|
1071
|
+
'cost': output.get('total_cost_usd', 0)
|
|
1072
|
+
})
|
|
1073
|
+
total_cost += output.get('total_cost_usd', 0)
|
|
1074
|
+
|
|
1075
|
+
# Save aggregated results
|
|
1076
|
+
with open(f'{run_dir}/results.json', 'w') as f:
|
|
1077
|
+
json.dump({
|
|
1078
|
+
'project_goal': state['plan']['project_goal'],
|
|
1079
|
+
'total_cost': total_cost,
|
|
1080
|
+
'results_by_type': results
|
|
1081
|
+
}, f, indent=2)
|
|
1082
|
+
|
|
1083
|
+
print(f"Results aggregated. Total cost: ${total_cost:.2f}")
|
|
1084
|
+
EOF
|
|
1085
|
+
```
|
|
1086
|
+
|
|
1087
|
+
**Step 2: Generate final report**
|
|
1088
|
+
```python
|
|
1089
|
+
## C-Breakout: Orchestrate Complete
|
|
1090
|
+
|
|
1091
|
+
**Run ID:** {RUN_ID}
|
|
1092
|
+
**Project Goal:** {project_goal}
|
|
1093
|
+
|
|
1094
|
+
### Results Summary
|
|
1095
|
+
|
|
1096
|
+
| Agent Type | Completed | Failed | Cost |
|
|
1097
|
+
|------------|-----------|--------|------|
|
|
1098
|
+
| Planner | {planner_success}/{planner_total} | {planner_failed} | ${planner_cost:.2f} |
|
|
1099
|
+
| Dev | {dev_success}/{dev_total} | {dev_failed} | ${dev_cost:.2f} |
|
|
1100
|
+
| Deploy | {deploy_success}/{deploy_total} | {deploy_failed} | ${deploy_cost:.2f} |
|
|
1101
|
+
|
|
1102
|
+
**Total Cost:** ${total_cost:.2f}
|
|
1103
|
+
**Token Savings vs Standard:** {savings_pct:.0f}%
|
|
1104
|
+
|
|
1105
|
+
### Completed Tasks
|
|
1106
|
+
|
|
1107
|
+
{list_of_completed_tasks}
|
|
1108
|
+
|
|
1109
|
+
**Results saved to:**
|
|
1110
|
+
- {PROJECT_DIR}/.claude/c-breakout-{RUN_ID}.md
|
|
1111
|
+
- /tmp/c-breakout/{RUN_ID}/results.json
|
|
1112
|
+
```
|
|
1113
|
+
|
|
1114
|
+
---
|
|
1115
|
+
|
|
1116
|
+
### Error Handling for Orchestrate Mode
|
|
1117
|
+
|
|
1118
|
+
**Orchestrator planning failure:**
|
|
1119
|
+
- Retry with more specific instructions
|
|
1120
|
+
- Fall back to standard distribute mode
|
|
1121
|
+
|
|
1122
|
+
**Agent tool access errors:**
|
|
1123
|
+
- If agent requests blocked tool, log warning
|
|
1124
|
+
- Retry agent with expanded toolset if critical
|
|
1125
|
+
- Report misclassification to improve orchestrator
|
|
1126
|
+
|
|
1127
|
+
**Dependency deadlock:**
|
|
1128
|
+
- Detect circular dependencies
|
|
1129
|
+
- Warn user and request manual intervention
|
|
1130
|
+
|
|
1131
|
+
---
|
|
1132
|
+
|
|
1133
|
+
### Configuration for Orchestrate Mode
|
|
1134
|
+
|
|
1135
|
+
Add to default config:
|
|
1136
|
+
|
|
1137
|
+
```json
|
|
1138
|
+
{
|
|
1139
|
+
"orchestrate": {
|
|
1140
|
+
"orchestrator_model": "sonnet",
|
|
1141
|
+
"agent_model": "haiku",
|
|
1142
|
+
"max_concurrent": 100,
|
|
1143
|
+
"agent_types": {
|
|
1144
|
+
"planner": {
|
|
1145
|
+
"tools": ["Read", "Grep", "Glob", "WebSearch"],
|
|
1146
|
+
"avg_overhead_tokens": 12000
|
|
1147
|
+
},
|
|
1148
|
+
"dev": {
|
|
1149
|
+
"tools": ["Read", "Write", "Edit", "Bash", "Grep", "Glob"],
|
|
1150
|
+
"avg_overhead_tokens": 10000
|
|
1151
|
+
},
|
|
1152
|
+
"deploy": {
|
|
1153
|
+
"tools": ["Bash", "Read"],
|
|
1154
|
+
"avg_overhead_tokens": 8000
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
```
|
|
1160
|
+
|
|
1161
|
+
---
|
|
1162
|
+
|
|
1163
|
+
## Mode: `status`
|
|
1164
|
+
|
|
1165
|
+
**Purpose:** Check status of running sub-agents.
|
|
1166
|
+
|
|
1167
|
+
**Usage:**
|
|
1168
|
+
```
|
|
1169
|
+
/c-breakout status # Latest run
|
|
1170
|
+
/c-breakout status {RUN_ID} # Specific run
|
|
1171
|
+
```
|
|
1172
|
+
|
|
1173
|
+
**Steps:**
|
|
1174
|
+
|
|
1175
|
+
1. Find run directory (latest or specified)
|
|
1176
|
+
2. Read state.json
|
|
1177
|
+
3. Check PID status for running agents
|
|
1178
|
+
4. Display formatted status
|
|
1179
|
+
|
|
1180
|
+
**Output:**
|
|
1181
|
+
```
|
|
1182
|
+
## C-Breakout Status
|
|
1183
|
+
|
|
1184
|
+
**Run ID:** 20260109_143022
|
|
1185
|
+
**Mode:** tasks
|
|
1186
|
+
**Started:** 2026-01-09 14:30:22 (5m 23s ago)
|
|
1187
|
+
**Status:** running
|
|
1188
|
+
|
|
1189
|
+
| Agent | Target | Status | Retries | Duration |
|
|
1190
|
+
|-------|--------|--------|---------|----------|
|
|
1191
|
+
| 001 | Database models | completed ✓ | 0 | 2m 15s |
|
|
1192
|
+
| 002 | API pagination | running | 0 | 3m 02s |
|
|
1193
|
+
| 003 | Documentation | failed ✗ | 2 | - |
|
|
1194
|
+
|
|
1195
|
+
**Progress:** 1/3 complete (33%)
|
|
1196
|
+
**Cost so far:** $0.45
|
|
1197
|
+
|
|
1198
|
+
**Errors:**
|
|
1199
|
+
- agent_003: Rate limit exceeded (max retries reached)
|
|
1200
|
+
```
|
|
1201
|
+
|
|
1202
|
+
---
|
|
1203
|
+
|
|
1204
|
+
## Mode: `results`
|
|
1205
|
+
|
|
1206
|
+
**Purpose:** Get results from a completed run.
|
|
1207
|
+
|
|
1208
|
+
**Usage:**
|
|
1209
|
+
```
|
|
1210
|
+
/c-breakout results # Latest run
|
|
1211
|
+
/c-breakout results {RUN_ID} # Specific run
|
|
1212
|
+
```
|
|
1213
|
+
|
|
1214
|
+
**Steps:**
|
|
1215
|
+
|
|
1216
|
+
1. Read combined_results.md from run directory
|
|
1217
|
+
2. If not exists, aggregate from agent outputs
|
|
1218
|
+
3. Display formatted results
|
|
1219
|
+
4. Show cost summary
|
|
1220
|
+
|
|
1221
|
+
---
|
|
1222
|
+
|
|
1223
|
+
## Mode: `resume`
|
|
1224
|
+
|
|
1225
|
+
**Purpose:** Resume an interrupted or failed run.
|
|
1226
|
+
|
|
1227
|
+
**Usage:**
|
|
1228
|
+
```
|
|
1229
|
+
/c-breakout resume {RUN_ID}
|
|
1230
|
+
```
|
|
1231
|
+
|
|
1232
|
+
**Steps:**
|
|
1233
|
+
|
|
1234
|
+
1. Read state.json from run directory
|
|
1235
|
+
2. Identify incomplete agents (pending, running, failed with retries left)
|
|
1236
|
+
3. Show resume plan:
|
|
1237
|
+
```
|
|
1238
|
+
## C-Breakout Resume
|
|
1239
|
+
|
|
1240
|
+
**Run ID:** {RUN_ID}
|
|
1241
|
+
**Original start:** {timestamp}
|
|
1242
|
+
**Status when interrupted:** {status}
|
|
1243
|
+
|
|
1244
|
+
**Completed (will skip):**
|
|
1245
|
+
- agent_001: Database models ✓
|
|
1246
|
+
- agent_002: API pagination ✓
|
|
1247
|
+
|
|
1248
|
+
**Will resume:**
|
|
1249
|
+
- agent_003: Documentation (was: failed, retries: 1/2)
|
|
1250
|
+
- agent_004: Testing (was: pending)
|
|
1251
|
+
|
|
1252
|
+
Proceed? [Y/n]
|
|
1253
|
+
```
|
|
1254
|
+
4. Relaunch incomplete agents
|
|
1255
|
+
5. Continue normal monitoring
|
|
1256
|
+
|
|
1257
|
+
---
|
|
1258
|
+
|
|
1259
|
+
## Mode: `history`
|
|
1260
|
+
|
|
1261
|
+
**Purpose:** Show run history for current project.
|
|
1262
|
+
|
|
1263
|
+
**Usage:**
|
|
1264
|
+
```
|
|
1265
|
+
/c-breakout history
|
|
1266
|
+
```
|
|
1267
|
+
|
|
1268
|
+
**Steps:**
|
|
1269
|
+
|
|
1270
|
+
1. Read {PROJECT_DIR}/.claude/c-breakout-runs.md
|
|
1271
|
+
2. Display formatted history
|
|
1272
|
+
|
|
1273
|
+
**Output:**
|
|
1274
|
+
```
|
|
1275
|
+
## C-Breakout History
|
|
1276
|
+
|
|
1277
|
+
**Project:** claude-config
|
|
1278
|
+
|
|
1279
|
+
| Run ID | Date | Mode | Status | Agents | Cost | Duration |
|
|
1280
|
+
|--------|------|------|--------|--------|------|----------|
|
|
1281
|
+
| 20260109_143022 | 2026-01-09 | tasks | completed | 3 | $0.89 | 8m 45s |
|
|
1282
|
+
| 20260108_091500 | 2026-01-08 | summarize | completed | 7 | $1.23 | 12m 30s |
|
|
1283
|
+
| 20260107_160000 | 2026-01-07 | distribute | failed | 4 | $0.45 | 5m 12s |
|
|
1284
|
+
|
|
1285
|
+
**Total runs:** 3
|
|
1286
|
+
**Total cost:** $2.57
|
|
1287
|
+
|
|
1288
|
+
View details: `/c-breakout results {RUN_ID}`
|
|
1289
|
+
```
|
|
1290
|
+
|
|
1291
|
+
### History file format ({PROJECT_DIR}/.claude/c-breakout-runs.md)
|
|
1292
|
+
```markdown
|
|
1293
|
+
# C-Breakout Run History
|
|
1294
|
+
|
|
1295
|
+
| Run ID | Date | Mode | Status | Agents | Cost | Duration | Summary |
|
|
1296
|
+
|--------|------|------|--------|--------|------|----------|---------|
|
|
1297
|
+
| 20260109_143022 | 2026-01-09 | tasks | completed | 3 | $0.89 | 8m 45s | Distributed todo tasks |
|
|
1298
|
+
| 20260108_091500 | 2026-01-08 | summarize | completed | 7 | $1.23 | 12m 30s | Summarized src/api/ |
|
|
1299
|
+
```
|
|
1300
|
+
|
|
1301
|
+
---
|
|
1302
|
+
|
|
1303
|
+
## Mode: `cancel`
|
|
1304
|
+
|
|
1305
|
+
**Purpose:** Cancel running sub-agents.
|
|
1306
|
+
|
|
1307
|
+
**Usage:**
|
|
1308
|
+
```
|
|
1309
|
+
/c-breakout cancel # Latest run
|
|
1310
|
+
/c-breakout cancel {RUN_ID} # Specific run
|
|
1311
|
+
```
|
|
1312
|
+
|
|
1313
|
+
**Steps:**
|
|
1314
|
+
|
|
1315
|
+
1. Read PIDs from run directory
|
|
1316
|
+
2. Kill all running processes
|
|
1317
|
+
3. Update state.json to "cancelled"
|
|
1318
|
+
4. Report what was cancelled
|
|
1319
|
+
|
|
1320
|
+
---
|
|
1321
|
+
|
|
1322
|
+
## Error Handling
|
|
1323
|
+
|
|
1324
|
+
### Retry Logic
|
|
1325
|
+
- Max retries: 2 (configurable)
|
|
1326
|
+
- Retry on: timeout, rate limit, transient errors
|
|
1327
|
+
- No retry on: invalid prompt, permission denied, out of context
|
|
1328
|
+
|
|
1329
|
+
### Error Aggregation
|
|
1330
|
+
All errors logged to `{RUN_DIR}/errors.log`:
|
|
1331
|
+
```
|
|
1332
|
+
[2026-01-09T14:35:22+08:00] agent_003 attempt 1: Rate limit exceeded
|
|
1333
|
+
[2026-01-09T14:36:22+08:00] agent_003 attempt 2: Rate limit exceeded
|
|
1334
|
+
[2026-01-09T14:37:22+08:00] agent_003 FAILED: Max retries exceeded
|
|
1335
|
+
```
|
|
1336
|
+
|
|
1337
|
+
### Partial Success
|
|
1338
|
+
If some agents fail but others succeed:
|
|
1339
|
+
- Save successful results
|
|
1340
|
+
- Report failures clearly
|
|
1341
|
+
- Allow resume for failed agents
|
|
1342
|
+
|
|
1343
|
+
---
|
|
1344
|
+
|
|
1345
|
+
## Configuration
|
|
1346
|
+
|
|
1347
|
+
Default config (can be overridden):
|
|
1348
|
+
```json
|
|
1349
|
+
{
|
|
1350
|
+
"max_concurrent": 100,
|
|
1351
|
+
"max_retries": 2,
|
|
1352
|
+
"batch_small_files": true,
|
|
1353
|
+
"small_file_threshold": 50,
|
|
1354
|
+
"progress_interval": 5,
|
|
1355
|
+
"model": "haiku",
|
|
1356
|
+
"orchestrate": {
|
|
1357
|
+
"orchestrator_model": "sonnet",
|
|
1358
|
+
"agent_model": "haiku",
|
|
1359
|
+
"agent_types": {
|
|
1360
|
+
"planner": {
|
|
1361
|
+
"tools": ["Read", "Grep", "Glob", "WebSearch"],
|
|
1362
|
+
"avg_overhead_tokens": 12000
|
|
1363
|
+
},
|
|
1364
|
+
"dev": {
|
|
1365
|
+
"tools": ["Read", "Write", "Edit", "Bash", "Grep", "Glob"],
|
|
1366
|
+
"avg_overhead_tokens": 10000
|
|
1367
|
+
},
|
|
1368
|
+
"deploy": {
|
|
1369
|
+
"tools": ["Bash", "Read"],
|
|
1370
|
+
"avg_overhead_tokens": 8000
|
|
1371
|
+
}
|
|
1372
|
+
}
|
|
1373
|
+
}
|
|
1374
|
+
}
|
|
1375
|
+
```
|
|
1376
|
+
|
|
1377
|
+
**Model options:**
|
|
1378
|
+
- `haiku` (default) - Fastest and cheapest, ideal for most distributed tasks
|
|
1379
|
+
- `sonnet` - Use for orchestrator in orchestrate mode, or for complex task reasoning
|
|
1380
|
+
- `opus` - Use only for highly complex tasks requiring maximum capability
|
|
1381
|
+
|
|
1382
|
+
**Orchestrate mode:**
|
|
1383
|
+
- Orchestrator uses `sonnet` for intelligent project planning
|
|
1384
|
+
- Specialized agents use `haiku` with minimal toolsets (43-50% token savings)
|
|
1385
|
+
- Agent types automatically classified: planner, dev, deploy
|
|
1386
|
+
|
|
1387
|
+
---
|
|
1388
|
+
|
|
1389
|
+
## Integration with Checkpoints
|
|
1390
|
+
|
|
1391
|
+
When creating a checkpoint after using c-breakout, include:
|
|
1392
|
+
- Run IDs used during session
|
|
1393
|
+
- Summary of what was distributed
|
|
1394
|
+
- Link to results files
|
|
1395
|
+
|
|
1396
|
+
Example in checkpoint:
|
|
1397
|
+
```markdown
|
|
1398
|
+
**C-Breakout runs:**
|
|
1399
|
+
- 20260109_143022 (tasks): Distributed 3 task groups, $0.89
|
|
1400
|
+
```
|
|
1401
|
+
|
|
1402
|
+
---
|
|
1403
|
+
|
|
1404
|
+
## Notes
|
|
1405
|
+
|
|
1406
|
+
- Each sub-agent runs in a completely separate Claude Code session
|
|
1407
|
+
- Main session context only receives summaries/results, not full processing
|
|
1408
|
+
- Use `status` to monitor progress without consuming main session context
|
|
1409
|
+
- State files enable resume after interruption
|
|
1410
|
+
- History persists per-project for audit trail
|