opencode-swarm-plugin 0.44.0 → 0.44.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. package/bin/swarm.serve.test.ts +6 -4
  2. package/bin/swarm.ts +16 -10
  3. package/dist/compaction-prompt-scoring.js +139 -0
  4. package/dist/eval-capture.js +12811 -0
  5. package/dist/hive.d.ts.map +1 -1
  6. package/dist/index.js +7644 -62599
  7. package/dist/plugin.js +23766 -78721
  8. package/dist/swarm-orchestrate.d.ts.map +1 -1
  9. package/dist/swarm-prompts.d.ts.map +1 -1
  10. package/dist/swarm-review.d.ts.map +1 -1
  11. package/package.json +17 -5
  12. package/.changeset/swarm-insights-data-layer.md +0 -63
  13. package/.hive/analysis/eval-failure-analysis-2025-12-25.md +0 -331
  14. package/.hive/analysis/session-data-quality-audit.md +0 -320
  15. package/.hive/eval-results.json +0 -483
  16. package/.hive/issues.jsonl +0 -138
  17. package/.hive/memories.jsonl +0 -729
  18. package/.opencode/eval-history.jsonl +0 -327
  19. package/.turbo/turbo-build.log +0 -9
  20. package/CHANGELOG.md +0 -2286
  21. package/SCORER-ANALYSIS.md +0 -598
  22. package/docs/analysis/subagent-coordination-patterns.md +0 -902
  23. package/docs/analysis-socratic-planner-pattern.md +0 -504
  24. package/docs/planning/ADR-001-monorepo-structure.md +0 -171
  25. package/docs/planning/ADR-002-package-extraction.md +0 -393
  26. package/docs/planning/ADR-003-performance-improvements.md +0 -451
  27. package/docs/planning/ADR-004-message-queue-features.md +0 -187
  28. package/docs/planning/ADR-005-devtools-observability.md +0 -202
  29. package/docs/planning/ADR-007-swarm-enhancements-worktree-review.md +0 -168
  30. package/docs/planning/ADR-008-worker-handoff-protocol.md +0 -293
  31. package/docs/planning/ADR-009-oh-my-opencode-patterns.md +0 -353
  32. package/docs/planning/ADR-010-cass-inhousing.md +0 -1215
  33. package/docs/planning/ROADMAP.md +0 -368
  34. package/docs/semantic-memory-cli-syntax.md +0 -123
  35. package/docs/swarm-mail-architecture.md +0 -1147
  36. package/docs/testing/context-recovery-test.md +0 -470
  37. package/evals/ARCHITECTURE.md +0 -1189
  38. package/evals/README.md +0 -768
  39. package/evals/compaction-prompt.eval.ts +0 -149
  40. package/evals/compaction-resumption.eval.ts +0 -289
  41. package/evals/coordinator-behavior.eval.ts +0 -307
  42. package/evals/coordinator-session.eval.ts +0 -154
  43. package/evals/evalite.config.ts.bak +0 -15
  44. package/evals/example.eval.ts +0 -31
  45. package/evals/fixtures/cass-baseline.ts +0 -217
  46. package/evals/fixtures/compaction-cases.ts +0 -350
  47. package/evals/fixtures/compaction-prompt-cases.ts +0 -311
  48. package/evals/fixtures/coordinator-sessions.ts +0 -328
  49. package/evals/fixtures/decomposition-cases.ts +0 -105
  50. package/evals/lib/compaction-loader.test.ts +0 -248
  51. package/evals/lib/compaction-loader.ts +0 -320
  52. package/evals/lib/data-loader.evalite-test.ts +0 -289
  53. package/evals/lib/data-loader.test.ts +0 -345
  54. package/evals/lib/data-loader.ts +0 -281
  55. package/evals/lib/llm.ts +0 -115
  56. package/evals/scorers/compaction-prompt-scorers.ts +0 -145
  57. package/evals/scorers/compaction-scorers.ts +0 -305
  58. package/evals/scorers/coordinator-discipline.evalite-test.ts +0 -539
  59. package/evals/scorers/coordinator-discipline.ts +0 -325
  60. package/evals/scorers/index.test.ts +0 -146
  61. package/evals/scorers/index.ts +0 -328
  62. package/evals/scorers/outcome-scorers.evalite-test.ts +0 -27
  63. package/evals/scorers/outcome-scorers.ts +0 -349
  64. package/evals/swarm-decomposition.eval.ts +0 -121
  65. package/examples/commands/swarm.md +0 -745
  66. package/examples/plugin-wrapper-template.ts +0 -2515
  67. package/examples/skills/hive-workflow/SKILL.md +0 -212
  68. package/examples/skills/skill-creator/SKILL.md +0 -223
  69. package/examples/skills/swarm-coordination/SKILL.md +0 -292
  70. package/global-skills/cli-builder/SKILL.md +0 -344
  71. package/global-skills/cli-builder/references/advanced-patterns.md +0 -244
  72. package/global-skills/learning-systems/SKILL.md +0 -644
  73. package/global-skills/skill-creator/LICENSE.txt +0 -202
  74. package/global-skills/skill-creator/SKILL.md +0 -352
  75. package/global-skills/skill-creator/references/output-patterns.md +0 -82
  76. package/global-skills/skill-creator/references/workflows.md +0 -28
  77. package/global-skills/swarm-coordination/SKILL.md +0 -995
  78. package/global-skills/swarm-coordination/references/coordinator-patterns.md +0 -235
  79. package/global-skills/swarm-coordination/references/strategies.md +0 -138
  80. package/global-skills/system-design/SKILL.md +0 -213
  81. package/global-skills/testing-patterns/SKILL.md +0 -430
  82. package/global-skills/testing-patterns/references/dependency-breaking-catalog.md +0 -586
  83. package/opencode-swarm-plugin-0.30.7.tgz +0 -0
  84. package/opencode-swarm-plugin-0.31.0.tgz +0 -0
  85. package/scripts/cleanup-test-memories.ts +0 -346
  86. package/scripts/init-skill.ts +0 -222
  87. package/scripts/migrate-unknown-sessions.ts +0 -349
  88. package/scripts/validate-skill.ts +0 -204
  89. package/src/agent-mail.ts +0 -1724
  90. package/src/anti-patterns.test.ts +0 -1167
  91. package/src/anti-patterns.ts +0 -448
  92. package/src/compaction-capture.integration.test.ts +0 -257
  93. package/src/compaction-hook.test.ts +0 -838
  94. package/src/compaction-hook.ts +0 -1204
  95. package/src/compaction-observability.integration.test.ts +0 -139
  96. package/src/compaction-observability.test.ts +0 -187
  97. package/src/compaction-observability.ts +0 -324
  98. package/src/compaction-prompt-scorers.test.ts +0 -475
  99. package/src/compaction-prompt-scoring.ts +0 -300
  100. package/src/contributor-tools.test.ts +0 -133
  101. package/src/contributor-tools.ts +0 -201
  102. package/src/dashboard.test.ts +0 -611
  103. package/src/dashboard.ts +0 -462
  104. package/src/error-enrichment.test.ts +0 -403
  105. package/src/error-enrichment.ts +0 -219
  106. package/src/eval-capture.test.ts +0 -1015
  107. package/src/eval-capture.ts +0 -929
  108. package/src/eval-gates.test.ts +0 -306
  109. package/src/eval-gates.ts +0 -218
  110. package/src/eval-history.test.ts +0 -508
  111. package/src/eval-history.ts +0 -214
  112. package/src/eval-learning.test.ts +0 -378
  113. package/src/eval-learning.ts +0 -360
  114. package/src/eval-runner.test.ts +0 -223
  115. package/src/eval-runner.ts +0 -402
  116. package/src/export-tools.test.ts +0 -476
  117. package/src/export-tools.ts +0 -257
  118. package/src/hive.integration.test.ts +0 -2241
  119. package/src/hive.ts +0 -1628
  120. package/src/index.ts +0 -940
  121. package/src/learning.integration.test.ts +0 -1815
  122. package/src/learning.ts +0 -1079
  123. package/src/logger.test.ts +0 -189
  124. package/src/logger.ts +0 -135
  125. package/src/mandate-promotion.test.ts +0 -473
  126. package/src/mandate-promotion.ts +0 -239
  127. package/src/mandate-storage.integration.test.ts +0 -601
  128. package/src/mandate-storage.test.ts +0 -578
  129. package/src/mandate-storage.ts +0 -794
  130. package/src/mandates.ts +0 -540
  131. package/src/memory-tools.test.ts +0 -195
  132. package/src/memory-tools.ts +0 -344
  133. package/src/memory.integration.test.ts +0 -334
  134. package/src/memory.test.ts +0 -158
  135. package/src/memory.ts +0 -527
  136. package/src/model-selection.test.ts +0 -188
  137. package/src/model-selection.ts +0 -68
  138. package/src/observability-tools.test.ts +0 -359
  139. package/src/observability-tools.ts +0 -871
  140. package/src/output-guardrails.test.ts +0 -438
  141. package/src/output-guardrails.ts +0 -381
  142. package/src/pattern-maturity.test.ts +0 -1160
  143. package/src/pattern-maturity.ts +0 -525
  144. package/src/planning-guardrails.test.ts +0 -491
  145. package/src/planning-guardrails.ts +0 -438
  146. package/src/plugin.ts +0 -23
  147. package/src/post-compaction-tracker.test.ts +0 -251
  148. package/src/post-compaction-tracker.ts +0 -237
  149. package/src/query-tools.test.ts +0 -636
  150. package/src/query-tools.ts +0 -324
  151. package/src/rate-limiter.integration.test.ts +0 -466
  152. package/src/rate-limiter.ts +0 -774
  153. package/src/replay-tools.test.ts +0 -496
  154. package/src/replay-tools.ts +0 -240
  155. package/src/repo-crawl.integration.test.ts +0 -441
  156. package/src/repo-crawl.ts +0 -610
  157. package/src/schemas/cell-events.test.ts +0 -347
  158. package/src/schemas/cell-events.ts +0 -807
  159. package/src/schemas/cell.ts +0 -257
  160. package/src/schemas/evaluation.ts +0 -166
  161. package/src/schemas/index.test.ts +0 -199
  162. package/src/schemas/index.ts +0 -286
  163. package/src/schemas/mandate.ts +0 -232
  164. package/src/schemas/swarm-context.ts +0 -115
  165. package/src/schemas/task.ts +0 -161
  166. package/src/schemas/worker-handoff.test.ts +0 -302
  167. package/src/schemas/worker-handoff.ts +0 -131
  168. package/src/sessions/agent-discovery.test.ts +0 -137
  169. package/src/sessions/agent-discovery.ts +0 -112
  170. package/src/sessions/index.ts +0 -15
  171. package/src/skills.integration.test.ts +0 -1192
  172. package/src/skills.test.ts +0 -643
  173. package/src/skills.ts +0 -1549
  174. package/src/storage.integration.test.ts +0 -341
  175. package/src/storage.ts +0 -884
  176. package/src/structured.integration.test.ts +0 -817
  177. package/src/structured.test.ts +0 -1046
  178. package/src/structured.ts +0 -762
  179. package/src/swarm-decompose.test.ts +0 -188
  180. package/src/swarm-decompose.ts +0 -1302
  181. package/src/swarm-deferred.integration.test.ts +0 -157
  182. package/src/swarm-deferred.test.ts +0 -38
  183. package/src/swarm-insights.test.ts +0 -214
  184. package/src/swarm-insights.ts +0 -459
  185. package/src/swarm-mail.integration.test.ts +0 -970
  186. package/src/swarm-mail.ts +0 -739
  187. package/src/swarm-orchestrate.integration.test.ts +0 -282
  188. package/src/swarm-orchestrate.test.ts +0 -548
  189. package/src/swarm-orchestrate.ts +0 -3084
  190. package/src/swarm-prompts.test.ts +0 -1270
  191. package/src/swarm-prompts.ts +0 -2077
  192. package/src/swarm-research.integration.test.ts +0 -701
  193. package/src/swarm-research.test.ts +0 -698
  194. package/src/swarm-research.ts +0 -472
  195. package/src/swarm-review.integration.test.ts +0 -285
  196. package/src/swarm-review.test.ts +0 -879
  197. package/src/swarm-review.ts +0 -709
  198. package/src/swarm-strategies.ts +0 -407
  199. package/src/swarm-worktree.test.ts +0 -501
  200. package/src/swarm-worktree.ts +0 -575
  201. package/src/swarm.integration.test.ts +0 -2377
  202. package/src/swarm.ts +0 -38
  203. package/src/tool-adapter.integration.test.ts +0 -1221
  204. package/src/tool-availability.ts +0 -461
  205. package/tsconfig.json +0 -28
@@ -1,995 +0,0 @@
1
- ---
2
- name: swarm-coordination
3
- description: Multi-agent coordination patterns for OpenCode swarm workflows. Use when working on complex tasks that benefit from parallelization, when coordinating multiple agents, or when managing task decomposition. Do NOT use for simple single-agent tasks.
4
- tags:
5
- - swarm
6
- - multi-agent
7
- - coordination
8
- tools:
9
- - swarm_plan_prompt
10
- - swarm_decompose
11
- - swarm_validate_decomposition
12
- - swarm_spawn_subtask
13
- - swarm_complete
14
- - swarm_status
15
- - swarm_progress
16
- - swarm_review
17
- - swarm_review_feedback
18
- - hive_create_epic
19
- - hive_query
20
- - swarmmail_init
21
- - swarmmail_send
22
- - swarmmail_inbox
23
- - swarmmail_read_message
24
- - swarmmail_reserve
25
- - swarmmail_release
26
- - swarmmail_health
27
- - semantic-memory_find
28
- - cass_search
29
- - pdf-brain_search
30
- - skills_list
31
- references:
32
- - references/strategies.md
33
- - references/coordinator-patterns.md
34
- ---
35
-
36
- # Swarm Coordination
37
-
38
- Multi-agent orchestration for parallel task execution. The coordinator breaks work into subtasks, spawns worker agents, monitors progress, and aggregates results.
39
-
40
- ## MANDATORY: Swarm Mail
41
-
42
- **ALL coordination MUST use `swarmmail_*` tools.** This is non-negotiable.
43
-
44
- Swarm Mail is embedded (no external server needed) and provides:
45
-
46
- - File reservations to prevent conflicts
47
- - Message passing between agents
48
- - Thread-based coordination tied to cells
49
-
50
- ## When to Swarm
51
-
52
- **DO swarm when:**
53
-
54
- - Task touches 3+ files
55
- - Natural parallel boundaries exist (frontend/backend/tests)
56
- - Different specializations needed
57
- - Time-to-completion matters
58
-
59
- **DON'T swarm when:**
60
-
61
- - Task is 1-2 files
62
- - Heavy sequential dependencies
63
- - Coordination overhead > benefit
64
- - Tight feedback loop needed
65
-
66
- **Heuristic:** If you can describe the task in one sentence without "and", don't swarm.
67
-
68
- ## Worker Survival Checklist (MANDATORY)
69
-
70
- Every swarm worker MUST follow these 9 steps. No exceptions.
71
-
72
- ```typescript
73
- // 1. INITIALIZE - Register with Swarm Mail
74
- swarmmail_init({
75
- project_path: "/abs/path/to/project",
76
- task_description: "bead-id: Task description"
77
- });
78
-
79
- // 2. QUERY LEARNINGS - Check what past agents learned
80
- semantic_memory_find({
81
- query: "task keywords domain",
82
- limit: 5
83
- });
84
-
85
- // 3. LOAD SKILLS - Get domain expertise
86
- skills_list();
87
- skills_use({ name: "relevant-skill" });
88
-
89
- // 4. RESERVE FILES - Claim exclusive ownership
90
- swarmmail_reserve({
91
- paths: ["src/assigned/**"],
92
- reason: "bead-id: What I'm working on",
93
- ttl_seconds: 3600
94
- });
95
-
96
- // 5. DO WORK
97
- // ... implement changes ...
98
-
99
- // 6. REPORT PROGRESS - Every 30min or at milestones
100
- swarm_progress({
101
- project_key: "/abs/path/to/project",
102
- agent_name: "WorkerName",
103
- bead_id: "bd-123.4",
104
- status: "in_progress",
105
- message: "Auth service 80% complete, testing remaining",
106
- progress_percent: 80
107
- });
108
-
109
- // 7. CHECKPOINT - Before risky operations
110
- swarm_checkpoint({
111
- bead_id: "bd-123.4",
112
- checkpoint_name: "pre-refactor",
113
- reason: "About to refactor auth flow"
114
- });
115
-
116
- // 8. STORE LEARNINGS - Capture what you discovered
117
- semantic_memory_store({
118
- information: "OAuth refresh tokens need 5min buffer...",
119
- metadata: "auth, oauth, tokens"
120
- });
121
-
122
- // 9. COMPLETE - Auto-releases, runs UBS, records outcome
123
- swarm_complete({
124
- project_key: "/abs/path/to/project",
125
- agent_name: "WorkerName",
126
- bead_id: "bd-123.4",
127
- summary: "Auth service implemented with JWT",
128
- files_touched: ["src/auth/service.ts", "src/auth/schema.ts"]
129
- });
130
- ```
131
-
132
- **Why These Steps Matter:**
133
-
134
- | Step | Purpose | Consequence of Skipping |
135
- |------|---------|-------------------------|
136
- | 1. Init | Register identity, enable coordination | Can't send messages, reservations fail |
137
- | 2. Query | Learn from past mistakes | Repeat solved problems, waste time |
138
- | 3. Skills | Load domain expertise | Miss known patterns, lower quality |
139
- | 4. Reserve | Prevent edit conflicts | Merge conflicts, lost work |
140
- | 5. Work | Actually do the task | N/A |
141
- | 6. Progress | Keep coordinator informed | Coordinator assumes stuck, may reassign |
142
- | 7. Checkpoint | Safe rollback point | Can't recover from failures |
143
- | 8. Store | Help future agents | Same bugs recur, no learning |
144
- | 9. Complete | Clean release, learning signal | Reservations leak, no outcome tracking |
145
-
146
- **If your subtask prompt doesn't include these steps, something is wrong with the coordinator.**
147
-
148
- ## Task Clarity Check (BEFORE Decomposing)
149
-
150
- **Before decomposing, ask: Is this task clear enough to parallelize?**
151
-
152
- ### Vague Task Signals (ASK QUESTIONS FIRST)
153
-
154
- | Signal | Example | Problem |
155
- | ------------------------ | ------------------------------ | -------------------------------- |
156
- | No files mentioned | "improve performance" | Where? Which files? |
157
- | Vague verbs | "fix", "update", "make better" | What specifically? |
158
- | Large undefined scope | "refactor the codebase" | Which parts? What pattern? |
159
- | Missing success criteria | "add auth" | OAuth? JWT? Session? What flows? |
160
- | Ambiguous boundaries | "handle errors" | Which errors? Where? How? |
161
-
162
- ### How to Clarify
163
-
164
- ```markdown
165
- The task "<task>" needs clarification before I can decompose it.
166
-
167
- **Question:** [Specific question about scope/files/approach]
168
-
169
- Options:
170
- a) [Option A] - [trade-off]
171
- b) [Option B] - [trade-off]
172
- c) [Option C] - [trade-off]
173
-
174
- I'd recommend (a) because [reason]. Which approach?
175
- ```
176
-
177
- **Rules:**
178
-
179
- - ONE question at a time (don't overwhelm)
180
- - Offer 2-3 concrete options when possible
181
- - Lead with your recommendation and why
182
- - Wait for answer before asking next question
183
-
184
- ### Clear Task Signals (PROCEED to decompose)
185
-
186
- | Signal | Example | Why it's clear |
187
- | ------------------ | ------------------------------ | ---------------- |
188
- | Specific files | "update src/auth/\*.ts" | Scope defined |
189
- | Concrete verbs | "migrate from X to Y" | Action defined |
190
- | Defined scope | "the payment module" | Boundaries clear |
191
- | Measurable outcome | "tests pass", "no type errors" | Success criteria |
192
-
193
- **When in doubt, ask.** A 30-second clarification beats a 30-minute wrong decomposition.
194
-
195
- ## Coordinator Workflow
196
-
197
- ### Phase 0: Socratic Planning (NEW - INTERACTIVE)
198
-
199
- **Before decomposing, engage with the user to clarify the task.**
200
-
201
- Swarm supports three interaction modes:
202
-
203
- | Mode | Flag | Behavior |
204
- |------|------|----------|
205
- | **Full Socratic** | (default) | Ask questions, offer recommendations, collaborative planning |
206
- | **Fast** | `--fast` | Skip questions, proceed with reasonable defaults |
207
- | **Auto** | `--auto` | Minimal interaction, use heuristics for all decisions |
208
- | **Confirm Only** | `--confirm-only` | Show plan, get yes/no, no discussion |
209
-
210
- **Default Flow (Full Socratic):**
211
-
212
- ```typescript
213
- // 1. Analyze task for clarity
214
- const signals = analyzeTaskClarity(task);
215
-
216
- if (signals.needsClarification) {
217
- // 2. Ask ONE question at a time
218
- const question = generateClarifyingQuestion(signals);
219
-
220
- // 3. Offer 2-3 concrete options
221
- const options = generateOptions(signals);
222
-
223
- // 4. Lead with recommendation
224
- const recommendation = selectRecommendation(options);
225
-
226
- // 5. Present to user
227
- console.log(`
228
- The task "${task}" needs clarification before I can decompose it.
229
-
230
- **Question:** ${question}
231
-
232
- Options:
233
- a) ${options[0].description} - ${options[0].tradeoff}
234
- b) ${options[1].description} - ${options[1].tradeoff}
235
- c) ${options[2].description} - ${options[2].tradeoff}
236
-
237
- I'd recommend (${recommendation.letter}) because ${recommendation.reason}. Which approach?
238
- `);
239
-
240
- // 6. Wait for answer, iterate if needed
241
- const answer = await getUserResponse();
242
-
243
- // 7. Ask next question if needed (ONE at a time)
244
- if (needsMoreClarification(answer)) {
245
- // Repeat with next question
246
- }
247
- }
248
-
249
- // 8. Proceed to decomposition once clear
250
- ```
251
-
252
- **Fast Mode (`--fast`):**
253
-
254
- - Skip all questions
255
- - Use reasonable defaults based on task type
256
- - Proceed directly to decomposition
257
-
258
- **Auto Mode (`--auto`):**
259
-
260
- - Zero interaction
261
- - Heuristic-based decisions for all choices
262
- - Use for batch processing or CI
263
-
264
- **Confirm Only (`--confirm-only`):**
265
-
266
- - Generate plan silently
267
- - Show final CellTree
268
- - Get yes/no only
269
-
270
- **Rules for Socratic Mode:**
271
-
272
- - **ONE question at a time** - don't overwhelm
273
- - **Offer concrete options** - not open-ended
274
- - **Lead with recommendation** - save user cognitive load
275
- - **Wait for answer** - don't proceed with assumptions
276
-
277
- ### Phase 1: Initialize Swarm Mail (FIRST)
278
-
279
- ```typescript
280
- // ALWAYS initialize first - registers you as coordinator
281
- await swarmmail_init({
282
- project_path: "$PWD",
283
- task_description: "Swarm: <task summary>",
284
- });
285
- ```
286
-
287
- ### Phase 2: Knowledge Gathering (MANDATORY)
288
-
289
- Before decomposing, query ALL knowledge sources:
290
-
291
- ```typescript
292
- // 1. Past learnings from this project
293
- semantic_memory_find({ query: "<task keywords>", limit: 5 });
294
-
295
- // 2. How similar tasks were solved before
296
- cass_search({ query: "<task description>", limit: 5 });
297
-
298
- // 3. Design patterns and prior art
299
- pdf_brain_search({ query: "<domain concepts>", limit: 5 });
300
-
301
- // 4. Available skills to inject into workers
302
- skills_list();
303
- ```
304
-
305
- Synthesize findings into `shared_context` for workers.
306
-
307
- ### Phase 3: Decomposition (DELEGATE TO SUBAGENT)
308
-
309
- > **⚠️ CRITICAL: Context Preservation Pattern**
310
- >
311
- > **NEVER do planning inline in the coordinator thread.** Decomposition work (file reading, CASS searching, reasoning about task breakdown) consumes massive amounts of context and will exhaust your token budget on long swarms.
312
- >
313
- > **ALWAYS delegate planning to a `swarm/planner` subagent** and receive only the structured CellTree JSON result back.
314
-
315
- **❌ Anti-Pattern (Context-Heavy):**
316
-
317
- ```typescript
318
- // DON'T DO THIS - pollutes main thread context
319
- const plan = await swarm_plan_prompt({ task, ... });
320
- // ... agent reasons about decomposition inline ...
321
- // ... context fills with file contents, analysis ...
322
- const validation = await swarm_validate_decomposition({ ... });
323
- ```
324
-
325
- **✅ Correct Pattern (Context-Lean):**
326
-
327
- ```typescript
328
- // 1. Create planning bead with full context
329
- await hive_create({
330
- title: `Plan: ${taskTitle}`,
331
- type: "task",
332
- description: `Decompose into subtasks. Context: ${synthesizedContext}`,
333
- });
334
-
335
- // 2. Delegate to swarm/planner subagent
336
- const planningResult = await Task({
337
- subagent_type: "swarm/planner",
338
- description: `Decompose task: ${taskTitle}`,
339
- prompt: `
340
- You are a swarm planner. Generate a CellTree for this task.
341
-
342
- ## Task
343
- ${taskDescription}
344
-
345
- ## Synthesized Context
346
- ${synthesizedContext}
347
-
348
- ## Instructions
349
- 1. Use swarm_plan_prompt(task="...", max_subtasks=5, query_cass=true)
350
- 2. Reason about decomposition strategy
351
- 3. Generate CellTree JSON
352
- 4. Validate with swarm_validate_decomposition
353
- 5. Return ONLY the validated CellTree JSON (no analysis, no file contents)
354
-
355
- Output format: Valid CellTree JSON only.
356
- `,
357
- });
358
-
359
- // 3. Parse result (subagent already validated)
360
- const beadTree = JSON.parse(planningResult);
361
-
362
- // 4. Create epic + subtasks atomically
363
- await hive_create_epic({
364
- epic_title: beadTree.epic.title,
365
- epic_description: beadTree.epic.description,
366
- subtasks: beadTree.subtasks,
367
- });
368
- ```
369
-
370
- **Why This Matters:**
371
-
372
- - **Main thread context stays clean** - only receives final JSON, not reasoning
373
- - **Subagent context is disposable** - gets garbage collected after planning
374
- - **Scales to long swarms** - coordinator can manage 10+ workers without exhaustion
375
- - **Faster coordination** - less context = faster responses when monitoring workers
376
-
377
- ### Phase 4: File Ownership (CRITICAL RULE)
378
-
379
- **⚠️ COORDINATORS NEVER RESERVE FILES**
380
-
381
- This is a hard rule. Here's why:
382
-
383
- ```typescript
384
- // ❌ WRONG - Coordinator reserving files
385
- swarmmail_reserve({
386
- paths: ["src/auth/**"],
387
- reason: "bd-123: Auth service implementation"
388
- });
389
- // Then spawns worker... who owns the files?
390
-
391
- // ✅ CORRECT - Worker reserves their own files
392
- // Coordinator includes file list in worker prompt
393
- const prompt = swarm_spawn_subtask({
394
- bead_id: "bd-123.4",
395
- files: ["src/auth/**"], // Files listed here
396
- // ...
397
- });
398
-
399
- // Worker receives prompt with file list
400
- // Worker calls swarmmail_reserve themselves
401
- ```
402
-
403
- **Why This Pattern:**
404
-
405
- | Coordinator Reserves | Worker Reserves |
406
- |---------------------|-----------------|
407
- | Ownership confusion | Clear ownership |
408
- | Who releases? | Worker releases via `swarm_complete` |
409
- | Coordinator must track | Worker manages lifecycle |
410
- | Deadlock risk | Clean handoff |
411
-
412
- **Coordinator Responsibilities:**
413
-
414
- 1. **Plan** which files each worker needs (no overlap)
415
- 2. **Include** file list in worker prompt
416
- 3. **Mediate** conflicts if workers request different files
417
- 4. **Never** call `swarmmail_reserve` themselves
418
-
419
- **Worker Responsibilities:**
420
-
421
- 1. **Read** assigned files from prompt
422
- 2. **Reserve** those files (step 4 of survival checklist)
423
- 3. **Work** exclusively on reserved files
424
- 4. **Release** via `swarm_complete` (automatic)
425
-
426
- ### Phase 5: Spawn Workers
427
-
428
- ```typescript
429
- for (const subtask of subtasks) {
430
- const prompt = await swarm_spawn_subtask({
431
- bead_id: subtask.id,
432
- epic_id: epic.id,
433
- subtask_title: subtask.title,
434
- subtask_description: subtask.description,
435
- files: subtask.files,
436
- shared_context: synthesizedContext,
437
- });
438
-
439
- // Spawn via Task tool
440
- Task({
441
- subagent_type: "swarm/worker",
442
- prompt: prompt.worker_prompt,
443
- });
444
- }
445
- ```
446
-
447
- ### Phase 6: MANDATORY Review Loop (NON-NEGOTIABLE)
448
-
449
- **⚠️ AFTER EVERY Worker Returns, You MUST Complete This Checklist:**
450
-
451
- This is the **quality gate** that prevents shipping broken code. DO NOT skip this.
452
-
453
- ```typescript
454
- // ============================================================
455
- // Step 1: Check Swarm Mail (Worker may have sent messages)
456
- // ============================================================
457
- const inbox = await swarmmail_inbox({ limit: 5 });
458
- const message = await swarmmail_read_message({ message_id: N });
459
-
460
- // ============================================================
461
- // Step 2: Review the Work (Generate review prompt with diff)
462
- // ============================================================
463
- const reviewPrompt = await swarm_review({
464
- project_key: "/abs/path/to/project",
465
- epic_id: "epic-id",
466
- task_id: "subtask-id",
467
- files_touched: ["src/auth/service.ts", "src/auth/service.test.ts"]
468
- });
469
-
470
- // This generates a review prompt that includes:
471
- // - Epic context (what we're trying to achieve)
472
- // - Subtask requirements
473
- // - Git diff of changes
474
- // - Dependency status (what came before, what comes next)
475
-
476
- // ============================================================
477
- // Step 3: Evaluate Against Criteria
478
- // ============================================================
479
- // Ask yourself:
480
- // - Does the work fulfill the subtask requirements?
481
- // - Does it serve the overall epic goal?
482
- // - Does it enable downstream tasks?
483
- // - Type safety, no obvious bugs?
484
-
485
- // ============================================================
486
- // Step 4: Send Feedback (Approve or Request Changes)
487
- // ============================================================
488
- await swarm_review_feedback({
489
- project_key: "/abs/path/to/project",
490
- task_id: "subtask-id",
491
- worker_id: "WorkerName",
492
- status: "approved", // or "needs_changes"
493
- summary: "LGTM - auth service looks solid",
494
- issues: "[]" // or "[{file, line, issue, suggestion}]"
495
- });
496
-
497
- // ============================================================
498
- // Step 5: ONLY THEN Continue
499
- // ============================================================
500
- // If approved:
501
- // - Close the cell
502
- // - Spawn next worker (if dependencies allow)
503
- // - Update swarm status
504
- //
505
- // If needs_changes:
506
- // - Worker gets feedback
507
- // - Worker retries (max 3 attempts)
508
- // - Review again when worker re-submits
509
- //
510
- // If 3 failures:
511
- // - Mark task blocked
512
- // - Escalate to human (architectural problem, not "try harder")
513
- ```
514
-
515
- **❌ Anti-Pattern (Skipping Review):**
516
-
517
- ```typescript
518
- // Worker completes
519
- swarm_complete({ ... });
520
-
521
- // Coordinator immediately spawns next worker
522
- // ⚠️ WRONG - No quality gate!
523
- Task({ subagent_type: "swarm/worker", prompt: nextWorkerPrompt });
524
- ```
525
-
526
- **✅ Correct Pattern (Review Before Proceeding):**
527
-
528
- ```typescript
529
- // Worker completes
530
- swarm_complete({ ... });
531
-
532
- // Coordinator REVIEWS first
533
- swarm_review({ ... });
534
- // ... evaluates changes ...
535
- swarm_review_feedback({ status: "approved" });
536
-
537
- // ONLY THEN spawn next worker
538
- Task({ subagent_type: "swarm/worker", prompt: nextWorkerPrompt });
539
- ```
540
-
541
- **Review Workflow (3-Strike Rule):**
542
-
543
- 1. Worker calls `swarm_complete` → Coordinator notified
544
- 2. Coordinator runs `swarm_review` → Gets diff + epic context
545
- 3. Coordinator evaluates against epic goals
546
- 4. If good: `swarm_review_feedback(status="approved")` → Task closed
547
- 5. If issues: `swarm_review_feedback(status="needs_changes", issues=[...])` → Worker fixes
548
- 6. After 3 rejections → Task marked blocked (architectural problem, not "try harder")
549
-
550
- **Review Criteria:**
551
- - Does work fulfill subtask requirements?
552
- - Does it serve the overall epic goal?
553
- - Does it enable downstream tasks?
554
- - Type safety, no obvious bugs?
555
-
556
- **Monitoring & Intervention:**
557
-
558
- ```typescript
559
- // Check overall swarm status
560
- const status = await swarm_status({ epic_id, project_key });
561
- ```
562
-
563
- ### Phase 7: Aggregate & Complete
564
-
565
- - Verify all subtasks completed
566
- - Run final verification (typecheck, tests)
567
- - Close epic with summary
568
- - Release any remaining reservations
569
- - Record outcomes for learning
570
-
571
- ```typescript
572
- await swarm_complete({
573
- project_key: "$PWD",
574
- agent_name: "coordinator",
575
- bead_id: epic_id,
576
- summary: "All subtasks complete",
577
- files_touched: [...],
578
- });
579
- await swarmmail_release(); // Release any remaining reservations
580
- await hive_sync();
581
- ```
582
-
583
- ## Context Survival Patterns (CRITICAL)
584
-
585
- Long-running swarms exhaust context windows. These patterns keep you alive.
586
-
587
- ### Pattern 1: Query Memory Before Starting
588
-
589
- **Problem:** Repeating solved problems wastes tokens on rediscovery.
590
-
591
- **Solution:** Query semantic memory FIRST.
592
-
593
- ```typescript
594
- // At swarm start (coordinator)
595
- const learnings = await semantic_memory_find({
596
- query: "auth oauth tokens",
597
- limit: 5
598
- });
599
-
600
- // Include in shared_context for workers
601
- const shared_context = `
602
- ## Past Learnings
603
- ${learnings.map(l => `- ${l.information}`).join('\n')}
604
- `;
605
-
606
- // At worker start (survival checklist step 2)
607
- const relevantLearnings = await semantic_memory_find({
608
- query: "task-specific keywords",
609
- limit: 3
610
- });
611
- ```
612
-
613
- **Why:** 5 learnings (~2k tokens) prevent rediscovering solutions (~20k tokens of trial-and-error).
614
-
615
- ### Pattern 2: Checkpoint Before Risky Operations
616
-
617
- **Problem:** Failed experiments consume context without producing value.
618
-
619
- **Solution:** Checkpoint before risky changes.
620
-
621
- ```typescript
622
- // Before refactoring
623
- await swarm_checkpoint({
624
- bead_id: "bd-123.4",
625
- checkpoint_name: "pre-refactor",
626
- reason: "About to change auth flow structure"
627
- });
628
-
629
- // Try risky change...
630
-
631
- // If it fails, restore and try different approach
632
- await swarm_restore_checkpoint({
633
- bead_id: "bd-123.4",
634
- checkpoint_name: "pre-refactor"
635
- });
636
- ```
637
-
638
- **When to Checkpoint:**
639
-
640
- | Operation | Risk | Checkpoint? |
641
- |-----------|------|-------------|
642
- | Add new file | Low | No |
643
- | Refactor across files | High | Yes |
644
- | Change API contract | High | Yes |
645
- | Update dependencies | Medium | Yes |
646
- | Fix typo | Low | No |
647
- | Rewrite algorithm | High | Yes |
648
-
649
- ### Pattern 3: Store Learnings Immediately
650
-
651
- **Problem:** Discoveries get lost in context churn.
652
-
653
- **Solution:** Store learnings as soon as you discover them.
654
-
655
- ```typescript
656
- // ❌ WRONG - Wait until end
657
- // ... debug for 30 minutes ...
658
- // ... find root cause ...
659
- // ... keep working ...
660
- // ... forget to store learning ...
661
-
662
- // ✅ CORRECT - Store immediately when discovered
663
- // ... debug for 30 minutes ...
664
- // ... find root cause ...
665
- await semantic_memory_store({
666
- information: "OAuth refresh tokens need 5min buffer to avoid race conditions. Without buffer, token refresh can fail mid-request if expiry happens between check and use.",
667
- metadata: "auth, oauth, tokens, race-conditions"
668
- });
669
- // ... continue working with peace of mind ...
670
- ```
671
-
672
- **Trigger:** Store a learning whenever you say "Aha!" or "That's why!".
673
-
674
- ### Pattern 4: Progress Reports Trigger Auto-Checkpoints
675
-
676
- **Problem:** Workers forget to checkpoint manually.
677
-
678
- **Solution:** `swarm_progress` auto-checkpoints at milestones.
679
-
680
- ```typescript
681
- // Report progress at 25%, 50%, 75%
682
- await swarm_progress({
683
- project_key: "/abs/path",
684
- agent_name: "WorkerName",
685
- bead_id: "bd-123.4",
686
- status: "in_progress",
687
- progress_percent: 50, // Auto-checkpoint triggered
688
- message: "Auth service half complete"
689
- });
690
- ```
691
-
692
- **Auto-checkpoint thresholds:** 25%, 50%, 75%, 100% (completion).
693
-
694
- ### Pattern 5: Delegate Heavy Research to Subagents
695
-
696
- **Problem:** Reading 10+ files or doing deep CASS searches pollutes main thread.
697
-
698
- **Solution:** Subagent researches, returns summary only.
699
-
700
- ```typescript
701
- // ❌ WRONG - Coordinator reads files inline
702
- const file1 = await read("src/a.ts"); // 500 lines
703
- const file2 = await read("src/b.ts"); // 600 lines
704
- const file3 = await read("src/c.ts"); // 400 lines
705
- // ... context now +1500 lines ...
706
-
707
- // ✅ CORRECT - Subagent reads, summarizes
708
- const summary = await Task({
709
- subagent_type: "explore",
710
- prompt: "Read src/a.ts, src/b.ts, src/c.ts. Summarize the auth flow in 3 bullet points."
711
- });
712
- // ... context +3 bullets, subagent context disposed ...
713
- ```
714
-
715
- **When to Delegate:**
716
-
717
- - Reading >3 files
718
- - Multiple CASS searches
719
- - Deep file tree exploration
720
- - Analyzing large logs
721
-
722
- ### Pattern 6: Use Summaries Over Raw Data
723
-
724
- **Problem:** Full inboxes, file contents, search results exhaust tokens.
725
-
726
- **Solution:** Summaries and previews only.
727
-
728
- ```typescript
729
- // ❌ WRONG - Fetch all message bodies
730
- const inbox = await swarmmail_inbox({ include_bodies: true });
731
-
732
- // ✅ CORRECT - Headers only, read specific messages
733
- const inbox = await swarmmail_inbox({ limit: 5 }); // Headers only
734
- if (inbox.urgent.length > 0) {
735
- const msg = await swarmmail_read_message({ message_id: inbox.urgent[0].id });
736
- }
737
-
738
- // ✅ BETTER - Summarize threads
739
- const summary = await swarmmail_summarize_thread({ thread_id: "bd-123" });
740
- ```
741
-
742
- **Token Budget:**
743
-
744
- | Approach | Tokens |
745
- |----------|--------|
746
- | 10 full messages | ~5k |
747
- | 10 message headers | ~500 |
748
- | Thread summary | ~200 |
749
-
750
- ### Context Survival Checklist
751
-
752
- - [ ] Query semantic memory at start
753
- - [ ] Checkpoint before risky operations
754
- - [ ] Store learnings immediately when discovered
755
- - [ ] Use `swarm_progress` for auto-checkpoints
756
- - [ ] Delegate heavy research to subagents
757
- - [ ] Use summaries over raw data
758
- - [ ] Monitor token usage (stay under 150k)
759
-
760
- **If you're past 150k tokens, you've already lost. These patterns keep you alive.**
761
-
762
- ## Decomposition Strategies
763
-
764
- Four strategies, auto-selected by task keywords:
765
-
766
- | Strategy | Best For | Keywords |
767
- | ------------------ | ----------------------------- | ------------------------------------- |
768
- | **file-based** | Refactoring, migrations | refactor, migrate, rename, update all |
769
- | **feature-based** | New features, vertical slices | add, implement, build, create |
770
- | **risk-based** | Bug fixes, security | fix, bug, security, critical |
771
- | **research-based** | Investigation, discovery | research, investigate, explore |
772
-
773
- See `references/strategies.md` for full details.
774
-
775
- ## Communication Protocol
776
-
777
- Workers communicate via Swarm Mail with epic ID as thread:
778
-
779
- ```typescript
780
- // Progress update
781
- swarmmail_send({
782
- to: ["coordinator"],
783
- subject: "Auth API complete",
784
- body: "Endpoints ready at /api/auth/*",
785
- thread_id: epic_id,
786
- });
787
-
788
- // Blocker
789
- swarmmail_send({
790
- to: ["coordinator"],
791
- subject: "BLOCKED: Need DB schema",
792
- body: "Can't proceed without users table",
793
- thread_id: epic_id,
794
- importance: "urgent",
795
- });
796
- ```
797
-
798
- **Coordinator checks inbox regularly** - don't let workers spin.
799
-
800
- ## Intervention Patterns
801
-
802
- | Signal | Action |
803
- | ----------------------- | ------------------------------------ |
804
- | Worker blocked >5 min | Check inbox, offer guidance |
805
- | File conflict | Mediate, reassign files |
806
- | Worker asking questions | Answer directly |
807
- | Scope creep | Redirect, create new bead for extras |
808
- | Repeated failures | Take over or reassign |
809
-
810
- ## Failure Recovery
811
-
812
- ### Incompatible Outputs
813
-
814
- Two workers produce conflicting results.
815
-
816
- **Fix:** Pick one approach, re-run other with constraint.
817
-
818
- ### Worker Drift
819
-
820
- Worker implements something different than asked.
821
-
822
- **Fix:** Revert, re-run with explicit instructions.
823
-
824
- ### Cascade Failure
825
-
826
- One blocker affects multiple subtasks.
827
-
828
- **Fix:** Unblock manually, reassign dependent work, accept partial completion.
829
-
830
- ## Anti-Patterns
831
-
832
- | Anti-Pattern | Symptom | Fix |
833
- | --------------------------- | ------------------------------------------ | ------------------------------------ |
834
- | **Decomposing Vague Tasks** | Wrong subtasks, wasted agent cycles | Ask clarifying questions FIRST |
835
- | **Mega-Coordinator** | Coordinator editing files | Coordinator only orchestrates |
836
- | **Silent Swarm** | No communication, late conflicts | Require updates, check inbox |
837
- | **Over-Decomposed** | 10 subtasks for 20 lines | 2-5 subtasks max |
838
- | **Under-Specified** | "Implement backend" | Clear goal, files, criteria |
839
- | **Inline Planning** ⚠️ | Context pollution, exhaustion on long runs | Delegate planning to subagent |
840
- | **Heavy File Reading** | Coordinator reading 10+ files | Subagent reads, returns summary only |
841
- | **Deep CASS Drilling** | Multiple cass_search calls inline | Subagent searches, summarizes |
842
- | **Manual Decomposition** | Hand-crafting subtasks without validation | Use swarm_plan_prompt + validation |
843
-
844
- ## Shared Context Template
845
-
846
- ```markdown
847
- ## Project Context
848
-
849
- - Repository: {repo}
850
- - Stack: {tech stack}
851
- - Patterns: {from pdf-brain}
852
-
853
- ## Task Context
854
-
855
- - Epic: {title}
856
- - Goal: {success criteria}
857
- - Constraints: {scope, time}
858
-
859
- ## Prior Art
860
-
861
- - Similar tasks: {from CASS}
862
- - Learnings: {from semantic-memory}
863
-
864
- ## Coordination
865
-
866
- - Active subtasks: {list}
867
- - Reserved files: {list}
868
- - Thread: {epic_id}
869
- ```
870
-
871
- ## Swarm Mail Quick Reference
872
-
873
- | Tool | Purpose |
874
- | ------------------------ | ----------------------------------- |
875
- | `swarmmail_init` | Initialize session (REQUIRED FIRST) |
876
- | `swarmmail_send` | Send message to agents |
877
- | `swarmmail_inbox` | Check inbox (max 5, no bodies) |
878
- | `swarmmail_read_message` | Read specific message body |
879
- | `swarmmail_reserve` | Reserve files for exclusive editing |
880
- | `swarmmail_release` | Release file reservations |
881
- | `swarmmail_ack` | Acknowledge message |
882
- | `swarmmail_health` | Check database health |
883
-
884
- ## Swarm Review Quick Reference
885
-
886
- | Tool | Purpose |
887
- | ------------------------ | ------------------------------------------ |
888
- | `swarm_review` | Generate review prompt with epic context + diff |
889
- | `swarm_review_feedback` | Send approval/rejection to worker (3-strike rule) |
890
-
891
- ## Full Swarm Flow
892
-
893
- ```typescript
894
- // 1. Initialize Swarm Mail FIRST
895
- swarmmail_init({ project_path: "$PWD", task_description: "..." });
896
-
897
- // 2. Gather knowledge
898
- semantic_memory_find({ query });
899
- cass_search({ query });
900
- pdf_brain_search({ query });
901
- skills_list();
902
-
903
- // 3. Decompose
904
- swarm_plan_prompt({ task });
905
- swarm_validate_decomposition();
906
- hive_create_epic();
907
-
908
- // 4. Reserve files
909
- swarmmail_reserve({ paths, reason, ttl_seconds });
910
-
911
- // 5. Spawn workers (loop)
912
- swarm_spawn_subtask();
913
-
914
- // 6. Monitor
915
- swarm_status();
916
- swarmmail_inbox();
917
- swarmmail_read_message({ message_id });
918
-
919
- // 7. Complete
920
- swarm_complete();
921
- swarmmail_release();
922
- hive_sync();
923
- ```
924
-
925
- See `references/coordinator-patterns.md` for detailed patterns.
926
-
927
- ## ASCII Art, Whimsy & Diagrams (MANDATORY)
928
-
929
- **We fucking LOVE visual flair.** Every swarm session should include:
930
-
931
- ### Session Summaries
932
-
933
- When completing a swarm, output a beautiful summary with:
934
-
935
- - ASCII art banner (figlet-style or custom)
936
- - Box-drawing characters for structure
937
- - Architecture diagrams showing what was built
938
- - Stats (files modified, subtasks completed, etc.)
939
- - A memorable quote or cow saying "ship it"
940
-
941
- ### During Coordination
942
-
943
- - Use tables for status updates
944
- - Draw dependency trees with box characters
945
- - Show progress with visual indicators
946
-
947
- ### Examples
948
-
949
- **Session Complete Banner:**
950
-
951
- ```
952
- ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
953
- ┃ 🐝 SWARM COMPLETE 🐝 ┃
954
- ┃ ┃
955
- ┃ Epic: Add Authentication ┃
956
- ┃ Subtasks: 4/4 ✓ ┃
957
- ┃ Files: 12 modified ┃
958
- ┃ ┃
959
- ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
960
- ```
961
-
962
- **Architecture Diagram:**
963
-
964
- ```
965
- ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
966
- │ INPUT │────▶│ PROCESS │────▶│ OUTPUT │
967
- └─────────────┘ └─────────────┘ └─────────────┘
968
- ```
969
-
970
- **Dependency Tree:**
971
-
972
- ```
973
- epic-123
974
- ├── epic-123.1 ✓ Auth service
975
- ├── epic-123.2 ✓ Database schema
976
- ├── epic-123.3 ◐ API routes (in progress)
977
- └── epic-123.4 ○ Tests (pending)
978
- ```
979
-
980
- **Ship It:**
981
-
982
- ```
983
- \ ^__^
984
- \ (oo)\_______
985
- (__)\ )\/\
986
- ||----w |
987
- || ||
988
-
989
- moo. ship it.
990
- ```
991
-
992
- **This is not optional.** PRs get shared on Twitter. Session summaries get screenshot. Make them memorable. Make them beautiful. Make them fun.
993
-
994
- Box-drawing characters: `─ │ ┌ ┐ └ ┘ ├ ┤ ┬ ┴ ┼ ━ ┃ ┏ ┓ ┗ ┛`
995
- Progress indicators: `✓ ✗ ◐ ○ ● ▶ ▷ ★ ☆ 🐝`