opencodekit 0.18.1 → 0.18.3

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 (131) hide show
  1. package/dist/index.js +161 -38
  2. package/dist/template/.opencode/.version +1 -1
  3. package/dist/template/.opencode/AGENTS.md +39 -9
  4. package/dist/template/.opencode/AGENT_ALIGNMENT.md +6 -6
  5. package/dist/template/.opencode/agent/build.md +7 -103
  6. package/dist/template/.opencode/agent/general.md +0 -52
  7. package/dist/template/.opencode/agent/plan.md +10 -0
  8. package/dist/template/.opencode/agent/runner.md +79 -0
  9. package/dist/template/.opencode/command/create.md +13 -1
  10. package/dist/template/.opencode/command/init-context.md +20 -6
  11. package/dist/template/.opencode/command/init-user.md +18 -16
  12. package/dist/template/.opencode/command/lfg.md +3 -4
  13. package/dist/template/.opencode/command/ship.md +6 -48
  14. package/dist/template/.opencode/command/start.md +20 -3
  15. package/dist/template/.opencode/command/verify.md +12 -17
  16. package/dist/template/.opencode/context/README.md +29 -0
  17. package/dist/template/.opencode/memory/_templates/{STATE.md → state.md} +1 -1
  18. package/dist/template/.opencode/memory.db +0 -0
  19. package/dist/template/.opencode/memory.db-shm +0 -0
  20. package/dist/template/.opencode/memory.db-wal +0 -0
  21. package/dist/template/.opencode/opencode.json +131 -7
  22. package/dist/template/.opencode/package.json +1 -1
  23. package/dist/template/.opencode/plugin/lib/memory-helpers.ts +51 -16
  24. package/dist/template/.opencode/plugin/lib/memory-hooks.ts +1 -1
  25. package/dist/template/.opencode/skill/accessibility-audit/SKILL.md +11 -5
  26. package/dist/template/.opencode/skill/agent-browser/SKILL.md +55 -18
  27. package/dist/template/.opencode/skill/agent-teams/SKILL.md +12 -1
  28. package/dist/template/.opencode/skill/augment-context-engine/SKILL.md +11 -1
  29. package/dist/template/.opencode/skill/beads/SKILL.md +57 -390
  30. package/dist/template/.opencode/skill/beads/references/BEST_PRACTICES.md +27 -0
  31. package/dist/template/.opencode/skill/beads/references/EXAMPLES.md +45 -0
  32. package/dist/template/.opencode/skill/beads/references/FILE_CLAIMING.md +101 -0
  33. package/dist/template/.opencode/skill/beads/references/GIT_SYNC.md +25 -0
  34. package/dist/template/.opencode/skill/beads/references/HIERARCHY.md +71 -0
  35. package/dist/template/.opencode/skill/beads/references/MULTI_AGENT.md +40 -0
  36. package/dist/template/.opencode/skill/beads/references/SESSION_PROTOCOL.md +61 -0
  37. package/dist/template/.opencode/skill/beads/references/TASK_CREATION.md +38 -0
  38. package/dist/template/.opencode/skill/beads/references/TROUBLESHOOTING.md +38 -0
  39. package/dist/template/.opencode/skill/beads-bridge/SKILL.md +10 -10
  40. package/dist/template/.opencode/skill/brainstorming/SKILL.md +13 -0
  41. package/dist/template/.opencode/skill/chrome-devtools/SKILL.md +11 -1
  42. package/dist/template/.opencode/skill/cloudflare/SKILL.md +87 -67
  43. package/dist/template/.opencode/skill/compaction/SKILL.md +11 -3
  44. package/dist/template/.opencode/skill/condition-based-waiting/SKILL.md +11 -25
  45. package/dist/template/.opencode/skill/context-engineering/SKILL.md +13 -2
  46. package/dist/template/.opencode/skill/context-initialization/SKILL.md +11 -1
  47. package/dist/template/.opencode/skill/context-management/SKILL.md +13 -1
  48. package/dist/template/.opencode/skill/core-data-expert/SKILL.md +13 -2
  49. package/dist/template/.opencode/skill/deep-research/SKILL.md +5 -8
  50. package/dist/template/.opencode/skill/defense-in-depth/SKILL.md +13 -0
  51. package/dist/template/.opencode/skill/design-system-audit/SKILL.md +9 -3
  52. package/dist/template/.opencode/skill/development-lifecycle/SKILL.md +51 -0
  53. package/dist/template/.opencode/skill/dispatching-parallel-agents/SKILL.md +19 -30
  54. package/dist/template/.opencode/skill/executing-plans/SKILL.md +36 -0
  55. package/dist/template/.opencode/skill/figma/SKILL.md +11 -1
  56. package/dist/template/.opencode/skill/finishing-a-development-branch/SKILL.md +31 -0
  57. package/dist/template/.opencode/skill/frontend-design/SKILL.md +13 -3
  58. package/dist/template/.opencode/skill/gemini-large-context/SKILL.md +11 -0
  59. package/dist/template/.opencode/skill/index-knowledge/SKILL.md +11 -1
  60. package/dist/template/.opencode/skill/jira/SKILL.md +11 -1
  61. package/dist/template/.opencode/skill/memory-system/SKILL.md +13 -1
  62. package/dist/template/.opencode/skill/mockup-to-code/SKILL.md +9 -3
  63. package/dist/template/.opencode/skill/mqdh/SKILL.md +11 -1
  64. package/dist/template/.opencode/skill/obsidian/SKILL.md +11 -1
  65. package/dist/template/.opencode/skill/opensrc/SKILL.md +18 -6
  66. package/dist/template/.opencode/skill/pdf-extract/SKILL.md +11 -1
  67. package/dist/template/.opencode/skill/playwright/SKILL.md +11 -1
  68. package/dist/template/.opencode/skill/playwriter/SKILL.md +11 -1
  69. package/dist/template/.opencode/skill/polar/SKILL.md +11 -1
  70. package/dist/template/.opencode/skill/prd/SKILL.md +13 -4
  71. package/dist/template/.opencode/skill/prd-task/SKILL.md +13 -3
  72. package/dist/template/.opencode/skill/ralph/SKILL.md +4 -8
  73. package/dist/template/.opencode/skill/react-best-practices/SKILL.md +24 -16
  74. package/dist/template/.opencode/skill/receiving-code-review/SKILL.md +22 -0
  75. package/dist/template/.opencode/skill/requesting-code-review/SKILL.md +30 -2
  76. package/dist/template/.opencode/skill/resend/SKILL.md +11 -1
  77. package/dist/template/.opencode/skill/root-cause-tracing/SKILL.md +12 -23
  78. package/dist/template/.opencode/skill/session-management/SKILL.md +11 -1
  79. package/dist/template/.opencode/skill/sharing-skills/SKILL.md +11 -0
  80. package/dist/template/.opencode/skill/skill-creator/SKILL.md +12 -11
  81. package/dist/template/.opencode/skill/source-code-research/SKILL.md +20 -266
  82. package/dist/template/.opencode/skill/source-code-research/references/analysis-tips.md +43 -0
  83. package/dist/template/.opencode/skill/source-code-research/references/anti-patterns.md +36 -0
  84. package/dist/template/.opencode/skill/source-code-research/references/common-patterns.md +57 -0
  85. package/dist/template/.opencode/skill/source-code-research/references/example-workflow.md +60 -0
  86. package/dist/template/.opencode/skill/source-code-research/references/further-reading.md +5 -0
  87. package/dist/template/.opencode/skill/source-code-research/references/source-structure.md +45 -0
  88. package/dist/template/.opencode/skill/stitch/SKILL.md +11 -1
  89. package/dist/template/.opencode/skill/structured-edit/SKILL.md +13 -0
  90. package/dist/template/.opencode/skill/subagent-driven-development/SKILL.md +13 -14
  91. package/dist/template/.opencode/skill/supabase/SKILL.md +11 -1
  92. package/dist/template/.opencode/skill/supabase-postgres-best-practices/SKILL.md +23 -15
  93. package/dist/template/.opencode/skill/swarm-coordination/SKILL.md +23 -923
  94. package/dist/template/.opencode/skill/swarm-coordination/references/architecture.md +39 -0
  95. package/dist/template/.opencode/skill/swarm-coordination/references/delegation-worker-protocol.md +145 -0
  96. package/dist/template/.opencode/skill/swarm-coordination/references/dependency-graph.md +50 -0
  97. package/dist/template/.opencode/skill/swarm-coordination/references/drift-check.md +90 -0
  98. package/dist/template/.opencode/skill/swarm-coordination/references/integration-beads.md +20 -0
  99. package/dist/template/.opencode/skill/swarm-coordination/references/launch-flow.md +186 -0
  100. package/dist/template/.opencode/skill/swarm-coordination/references/reconciler.md +172 -0
  101. package/dist/template/.opencode/skill/swarm-coordination/references/tier-enforcement.md +78 -0
  102. package/dist/template/.opencode/skill/swarm-coordination/references/tmux-integration.md +134 -0
  103. package/dist/template/.opencode/skill/swift-concurrency/SKILL.md +22 -2
  104. package/dist/template/.opencode/skill/swiftui-expert-skill/SKILL.md +58 -19
  105. package/dist/template/.opencode/skill/systematic-debugging/SKILL.md +25 -25
  106. package/dist/template/.opencode/skill/test-driven-development/SKILL.md +19 -15
  107. package/dist/template/.opencode/skill/testing-anti-patterns/SKILL.md +13 -0
  108. package/dist/template/.opencode/skill/testing-skills-with-subagents/SKILL.md +13 -15
  109. package/dist/template/.opencode/skill/tool-priority/SKILL.md +13 -0
  110. package/dist/template/.opencode/skill/ui-ux-research/SKILL.md +9 -3
  111. package/dist/template/.opencode/skill/using-git-worktrees/SKILL.md +37 -0
  112. package/dist/template/.opencode/skill/using-skills/SKILL.md +13 -0
  113. package/dist/template/.opencode/skill/v0/SKILL.md +11 -1
  114. package/dist/template/.opencode/skill/v1-run/SKILL.md +11 -1
  115. package/dist/template/.opencode/skill/vercel-deploy-claimable/SKILL.md +14 -2
  116. package/dist/template/.opencode/skill/verification-before-completion/SKILL.md +22 -0
  117. package/dist/template/.opencode/skill/verification-before-completion/references/VERIFICATION_PROTOCOL.md +67 -0
  118. package/dist/template/.opencode/skill/visual-analysis/SKILL.md +9 -3
  119. package/dist/template/.opencode/skill/web-design-guidelines/SKILL.md +12 -5
  120. package/dist/template/.opencode/skill/writing-plans/SKILL.md +13 -0
  121. package/dist/template/.opencode/skill/writing-skills/SKILL.md +26 -421
  122. package/dist/template/.opencode/skill/writing-skills/references/anti-patterns.md +25 -0
  123. package/dist/template/.opencode/skill/writing-skills/references/claude-search-optimization.md +140 -0
  124. package/dist/template/.opencode/skill/writing-skills/references/discovery-workflow.md +11 -0
  125. package/dist/template/.opencode/skill/writing-skills/references/file-organization.md +32 -0
  126. package/dist/template/.opencode/skill/writing-skills/references/flowcharts-and-examples.md +57 -0
  127. package/dist/template/.opencode/skill/writing-skills/references/rationalization-hardening.md +75 -0
  128. package/dist/template/.opencode/skill/writing-skills/references/testing-skill-types.md +52 -0
  129. package/package.json +15 -4
  130. /package/dist/template/.opencode/memory/_templates/{PROJECT.md → project.md} +0 -0
  131. /package/dist/template/.opencode/memory/_templates/{ROADMAP.md → roadmap.md} +0 -0
@@ -7,11 +7,22 @@ description: >
7
7
  and graceful shutdown patterns.
8
8
  version: "2.1.0"
9
9
  license: MIT
10
+ tags: [agent-coordination, workflow]
11
+ dependencies: [beads-bridge]
10
12
  ---
11
13
 
12
14
  # Swarm Coordination - Kimi K2.5 PARL Multi-Agent Execution
13
15
 
14
- Coordinate multiple agents working on independent tasks in parallel using Kimi K2.5 PARL (Parallel-Agent Reinforcement Learning) patterns.
16
+ ## When to Use
17
+
18
+ - Implementing plans with 3+ independent tasks that can run in parallel
19
+ - You need structured coordination, monitoring, and delegation across many agents
20
+
21
+ ## When NOT to Use
22
+
23
+ - Single-task or tightly sequential work without parallelizable groups
24
+ - Simple 1–2 file changes better handled by a single agent
25
+
15
26
 
16
27
  ## Overview
17
28
 
@@ -58,694 +69,6 @@ Coordinate multiple agents working on independent tasks in parallel using Kimi K
58
69
  - **Progress Visualization**: Real-time TUI with beautiful markdown blocks
59
70
  - **Dependency Graphs**: DAG-based task scheduling with critical path analysis
60
71
 
61
- ## Architecture
62
-
63
- ```
64
- ┌─────────────────────────────────────────────────────────────────┐
65
- │ BUILD AGENT (Leader) │
66
- │ - Parses plan into tasks │
67
- │ - Creates delegation packets │
68
- │ - Spawns worker agents via Task tool │
69
- │ - Monitors progress via swarm tool │
70
- │ - Synthesizes final results │
71
- └─────────────────────────────────────────────────────────────────┘
72
- │ │ │
73
- ▼ ▼ ▼
74
- ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
75
- │ WORKER-1 │ │ WORKER-2 │ │ WORKER-3 │
76
- │ (general) │ │ (general) │ │ (general) │
77
- │ │ │ │ │ │
78
- │ - Read │ │ - Read │ │ - Read │
79
- │ delegation│ │ delegation│ │ delegation│
80
- │ - Execute │ │ - Execute │ │ - Execute │
81
- │ - Report │ │ - Report │ │ - Report │
82
- └─────────────┘ └─────────────┘ └─────────────┘
83
- │ │ │
84
- └────────────────────┼────────────────────┘
85
-
86
- ┌─────────────────┐
87
- │ RECONCILER │
88
- │ │
89
- │ - Watch CI │
90
- │ - Detect broken │
91
- │ - Spawn fixes │
92
- └─────────────────┘
93
-
94
-
95
- ┌─────────────────┐
96
- │ PROGRESS + │
97
- │ TODO PERSIST │
98
- └─────────────────┘
99
- ```
100
-
101
- ## Reconciler Agent Pattern (Self-Healing)
102
-
103
- The reconciler is the key to scaling beyond 50+ agents. Without reconciliation, broken builds cascade and the swarm collapses. The reconciler provides **continuous self-healing** by watching for failures and spawning targeted fix tasks.
104
-
105
- ### When to Use Reconciler
106
-
107
- - **50+ agents** running in parallel → **REQUIRED**
108
- - **10-50 agents** → Recommended
109
- - **<10 agents** → Optional (leader can handle)
110
-
111
- ### Reconciler Responsibilities
112
-
113
- 1. **Watch CI/Build Status**: Monitor build gates continuously
114
- 2. **Detect Failures**: Identify which worker caused the failure
115
- 3. **Analyze Root Cause**: Determine if it's a merge conflict, test failure, or type error
116
- 4. **Spawn Fix Tasks**: Create targeted fix tasks with context about what failed
117
- 5. **Verify Fix**: Wait for fix to pass gates before continuing
118
-
119
- ### Reconciler vs Leader
120
-
121
- | Aspect | Leader | Reconciler |
122
- | -------------- | ----------------------------- | ----------------------------- |
123
- | Focus | Orchestration, spawning | Recovery, fixing |
124
- | Runs | At swarm start, between waves | Continuously during execution |
125
- | On failure | Spawns workers | Spawns fix tasks |
126
- | Failure impact | Can't start work | Wave can't complete |
127
-
128
- ### Implementing Reconciler
129
-
130
- The reconciler runs in a loop during swarm execution:
131
-
132
- ```typescript
133
- // Reconciler runs in background during swarm execution
134
- async function runReconciler(teamName: string, buildCommand: string) {
135
- while (swarmActive) {
136
- // 1. Check build status
137
- const status = await swarm({
138
- operation: "monitor",
139
- operation: "status",
140
- team_name: teamName,
141
- });
142
- const stats = JSON.parse(status).summary;
143
-
144
- // 2. If there are errors, investigate
145
- if (stats.errors > 0) {
146
- // 3. Get error details
147
- const errors = await getWorkerErrors(teamName);
148
-
149
- for (const error of errors) {
150
- // 4. Analyze root cause
151
- const cause = await analyzeError(error);
152
-
153
- // 5. Spawn fix task
154
- const fixBead = await br create({
155
- title: `Fix: ${cause.summary}`,
156
- type: "bug",
157
- description: `Detected by reconciler: ${error.message}. Root cause: ${cause.rootCause}. Suggested fix: ${cause.suggestion}`,
158
- });
159
-
160
- // 6. Assign to targeted worker
161
- await Task({
162
- subagent_type: "general",
163
- description: `Fix ${error.worker}`,
164
- prompt: `Fix the error in ${error.file}.
165
-
166
- Error: ${error.message}
167
- Root cause: ${cause.rootCause}
168
- Suggested fix: ${cause.suggestion}
169
-
170
- Run: ${buildCommand}
171
- Verify: npm run typecheck && npm run lint`,
172
- });
173
- }
174
- }
175
-
176
- // Wait before next check
177
- await sleep(30000); // Check every 30 seconds
178
- }
179
- }
180
- ```
181
-
182
- ### Error Analysis Patterns
183
-
184
- The reconciler categorizes errors:
185
-
186
- | Error Type | Detection | Fix Strategy |
187
- | -------------- | -------------------------------- | ---------------------------- |
188
- | Merge conflict | "CONFLICT" in output, git status | Re-base, resolve, force push |
189
- | Type error | "typecheck failed" | Fix types, run typecheck |
190
- | Test failure | "test failed", "expect" mismatch | Fix test or implementation |
191
- | Lint error | "lint failed", formatting issues | Run lint:fix |
192
- | Build error | "build failed", bundler errors | Fix imports, dependencies |
193
-
194
- ### Spawning Fix Tasks
195
-
196
- When the reconciler spawns a fix task, it includes:
197
-
198
- ```typescript
199
- // Create fix task with full context
200
- await br create({
201
- title: `Fix: ${error.type} in ${error.file}`,
202
- type: "bug",
203
- description: `## Error Detected
204
- - Worker: ${error.worker}
205
- - File: ${error.file}
206
- - Error: ${error.message}
207
- - Timestamp: ${error.timestamp}
208
-
209
- ## Root Cause Analysis
210
- ${cause.explanation}
211
-
212
- ## Suggested Fix
213
- ${cause.suggestion}
214
-
215
- ## Verification
216
- Run: ${buildCommand}
217
- Must pass before wave can complete.`,
218
- });
219
- ```
220
-
221
- ### Reconciler in Wave Execution
222
-
223
- Add reconciler monitoring to each wave:
224
-
225
- ```typescript
226
- // Execute wave with reconciler
227
- async function executeWaveWithReconciler(wave, teamName) {
228
- // Start reconciler in background
229
- const reconciler = runReconciler(teamName, "npm run typecheck && npm run lint");
230
-
231
- // Execute workers in this wave
232
- await Promise.all(wave.tasks.map(spawnWorker));
233
-
234
- // Wait for all workers + reconciler to complete
235
- await reconciler;
236
-
237
- // Verify wave output before proceeding
238
- await bash("npm run typecheck && npm run lint");
239
- }
240
- ```
241
-
242
- ### Example: Full Swarm with Reconciler
243
-
244
- ```typescript
245
- // Full swarm execution with reconciler
246
- async function runSwarmWithReconciler(tasks, teamName) {
247
- // 1. Analyze and create waves
248
- const waves = createWaves(tasks);
249
-
250
- // 2. Execute each wave with reconciler
251
- for (const wave of waves) {
252
- console.log(`Executing wave ${wave.number} with ${wave.tasks.length} tasks`);
253
-
254
- // Start reconciler for this wave
255
- const reconcilerPromise = runReconciler(teamName, "npm run typecheck && npm run lint");
256
-
257
- // Spawn workers
258
- await Promise.all(wave.tasks.map((task) => spawnWorker(task, teamName)));
259
-
260
- // Wait for reconciler to finish fixing any errors
261
- await reconcilerPromise;
262
-
263
- // Verify wave output
264
- const result = await bash("npm run typecheck && npm run lint");
265
- if (!result.success) {
266
- throw new Error(`Wave ${wave.number} failed gates`);
267
- }
268
-
269
- console.log(`Wave ${wave.number} complete`);
270
- }
271
- }
272
- ```
273
-
274
- ## Drift Check After Each Wave
275
-
276
- After every wave completes and before starting the next, run a **drift check** to verify the codebase has not deviated from the intended state. Accumulated drift between waves is the primary cause of cascading failures in large swarms.
277
-
278
- **Drift** = any difference between actual codebase state and the plan's expected state at a wave boundary.
279
-
280
- ### What to Check
281
-
282
- | Check | Command | Passing Condition |
283
- | ----------------- | -------------------------------------------------- | ------------------------------ |
284
- | Build gates | `npm run typecheck && npm run lint` | Zero errors |
285
- | Unexpected files | `git diff --name-only HEAD` | Only planned files modified |
286
- | Missing artifacts | Verify expected files exist | All declared outputs present |
287
- | Scope adherence | Compare `git status` vs wave's declared file scope | No out-of-scope files modified |
288
-
289
- ### Drift Check Protocol
290
-
291
- Run after every wave, before spawning the next:
292
-
293
- ```typescript
294
- async function driftCheckAfterWave(wave: Wave, expectedFiles: string[]) {
295
- console.log(`\n=== DRIFT CHECK: Wave ${wave.number} ===`);
296
-
297
- // 1. Build gates must pass
298
- const gates = await bash("npm run typecheck && npm run lint");
299
- if (!gates.success) {
300
- throw new Error(`Wave ${wave.number} drift: build gates failed\n${gates.output}`);
301
- }
302
-
303
- // 2. Detect unexpected file modifications
304
- const changedFiles = await bash("git diff --name-only HEAD");
305
- const actualFiles = changedFiles.output.trim().split("\n").filter(Boolean);
306
- const unexpected = actualFiles.filter((f) => !expectedFiles.includes(f));
307
-
308
- if (unexpected.length > 0) {
309
- console.warn(`⚠️ Unexpected files modified in wave ${wave.number}:`);
310
- unexpected.forEach((f) => console.warn(` - ${f}`));
311
- }
312
-
313
- // 3. Verify declared artifacts exist
314
- for (const artifact of wave.expectedArtifacts ?? []) {
315
- const exists = await bash(`test -f ${artifact} && echo "ok" || echo "missing"`);
316
- if (exists.output.trim() === "missing") {
317
- throw new Error(`Wave ${wave.number} drift: expected artifact missing: ${artifact}`);
318
- }
319
- }
320
-
321
- console.log(`✓ Drift check passed: Wave ${wave.number}`);
322
- }
323
- ```
324
-
325
- ### Integration in Wave Execution
326
-
327
- Call drift check between every wave:
328
-
329
- ```typescript
330
- for (let i = 0; i < waves.length; i++) {
331
- const wave = waves[i];
332
- const reconciler = runReconciler(teamName, "npm run typecheck && npm run lint");
333
-
334
- await Promise.all(wave.tasks.map((task) => spawnWorker(task, teamName)));
335
- await reconciler;
336
-
337
- // MANDATORY: Drift check before next wave
338
- await driftCheckAfterWave(
339
- wave,
340
- wave.tasks.flatMap((t) => t.assignedFiles),
341
- );
342
-
343
- console.log(`✓ Wave ${i + 1}/${waves.length} complete and verified`);
344
- }
345
- ```
346
-
347
- ### Drift Response Protocol
348
-
349
- | Drift Type | Severity | Action |
350
- | ------------------------ | -------- | ------------------------------------------------ |
351
- | Build gate failure | Critical | Stop swarm, run reconciler, fix before next wave |
352
- | Unexpected file modified | Warning | Review change, revert if out of scope |
353
- | Missing artifact | Critical | Re-run failed worker task, verify output |
354
- | Scope creep | Warning | Escalate to user if >3 unexpected files changed |
355
-
356
- ### When Drift Is Unrecoverable
357
-
358
- If drift check fails twice in a row on the same wave:
359
-
360
- 1. **Stop the swarm** - don't start next wave
361
- 2. **Report to user**: exact drift details, failing gate output, list of unexpected files
362
- 3. **Rollback option**: use `git reset --hard <wave-N-start-tag>` (see `executing-plans` skill)
363
- 4. **Never paper over drift** - proceeding with known drift compounds into cascading failure
364
-
365
- ## Swarm Launch Flow - PARL Pattern (7 Steps)
366
-
367
- ### Step 0: Task Analysis (Anti-Serial-Collapse + Dependency Graph)
368
-
369
- Analyze the user's actual task to determine optimal swarm strategy:
370
-
371
- ```typescript
372
- // 1. Classify the task and build dependency graph
373
- const analysis = await swarm({
374
- operation: "plan",
375
- operation: "analyze",
376
- task: "<user's request from input>",
377
- files: "<detected files from glob/grep>",
378
- });
379
-
380
- // Returns:
381
- // - type: "search" | "batch" | "writing" | "sequential" | "mixed"
382
- // - recommended_agents: number
383
- // - phases: [{ name, role, agent_count, dependencies }]
384
- // - coupling: "high" | "medium" | "low"
385
- // - confidence: "high" | "medium" | "low"
386
- // - dependency_graph: { nodes, edges, critical_path, parallelizable_groups }
387
-
388
- const plan = JSON.parse(analysis);
389
-
390
- // 2. Check for serial collapse
391
- const check = await swarm({
392
- operation: "plan",
393
- operation: "check",
394
- task: "<user's request>",
395
- files: String(plan.file_count),
396
- recommended_agents: plan.classification.recommended_agents,
397
- });
398
-
399
- // If serial collapse detected, force parallelization
400
- if (check.serial_collapse_detected) {
401
- console.log(`⚠️ Serial collapse detected: ${check.warning_signs.join(", ")}`);
402
- console.log(`✓ Adjusting to ${check.suggested_agents} agents`);
403
- }
404
-
405
- // 3. Use dependency graph for spawn ordering
406
- const { parallelizable_groups, critical_path } = plan.dependency_graph;
407
- console.log(`Critical path: ${critical_path.join(" → ")}`);
408
- console.log(`Parallel groups: ${parallelizable_groups.length}`);
409
- ```
410
-
411
- ### Step 1: Session Setup (Push Beads to Todos)
412
-
413
- Make Beads tasks visible to subagents:
414
-
415
- ```typescript
416
- // Push Beads to OpenCode todos (subagents see via todoread)
417
- await swarm({ operation: "sync", operation: "push", filter: "open" });
418
-
419
- // Check for existing swarm state
420
- const status = await swarm({
421
- operation: "monitor",
422
- operation: "status",
423
- team_name: "plan-implementation",
424
- });
425
- const stats = JSON.parse(status).summary;
426
-
427
- if (stats.total_workers > 0) {
428
- console.log(`Found existing swarm with ${stats.total_workers} workers`);
429
- // Render current progress
430
- const ui = await swarm({
431
- operation: "monitor",
432
- operation: "render_block",
433
- team_name: "plan-implementation",
434
- });
435
- console.log(ui);
436
- }
437
- ```
438
-
439
- ### Step 2: Create Delegation Packets
440
-
441
- For each task, create a delegation packet:
442
-
443
- ```typescript
444
- swarm({
445
- operation: "delegate",
446
- bead_id: "task-1",
447
- title: "Implement auth service",
448
- expected_outcome: "Auth service with JWT tokens, tests pass",
449
- required_tools: "read, grep, lsp, edit, bash",
450
- must_do: "LSP before edits, run npm test after changes",
451
- must_not_do: "No new dependencies, don't edit config files",
452
- acceptance_checks: "typecheck: npm run typecheck, lint: npm run lint, test: npm test",
453
- context: "See .beads/artifacts/task-1/spec.md for requirements",
454
- write: true,
455
- });
456
- ```
457
-
458
- ### Step 3: Spawn Worker Agents (Using Dependency Groups)
459
-
460
- Use parallelizable_groups from dependency graph for proper ordering:
461
-
462
- ```typescript
463
- // Spawn workers in dependency order
464
- for (const group of plan.dependency_graph.parallelizable_groups) {
465
- // All tasks in this group can run in parallel
466
- const spawnPromises = group.map((taskId) => {
467
- const node = plan.dependency_graph.nodes.find((n) => n.id === taskId);
468
- return Task({
469
- subagent_type: "general",
470
- description: `Execute ${taskId}`,
471
- prompt: `Execute bead ${taskId}: ${node.content}
472
-
473
- Read delegation packet at: .beads/artifacts/${taskId}/delegation.md
474
-
475
- Files: ${node.assignedFiles.join(", ")}
476
- Phase: ${node.phase}
477
- Worker: ${node.worker}
478
- Team: plan-implementation
479
-
480
- Requirements:
481
- 1. Follow all MUST DO constraints
482
- 2. Avoid all MUST NOT DO items
483
- 3. Run acceptance checks before claiming done
484
- 4. Report progress via swarm monitor`,
485
- });
486
- });
487
-
488
- // Wait for parallel group to complete before starting next
489
- await Promise.all(spawnPromises);
490
- }
491
- ```
492
-
493
- ### Step 4: Monitor Progress (Real-time TUI + Persistence)
494
-
495
- Monitor with beautiful block UI, progress tracking, and auto-persistence:
496
-
497
- ```typescript
498
- let allComplete = false;
499
- while (!allComplete) {
500
- // Option A: Render beautiful TUI block
501
- const ui = await swarm({
502
- operation: "monitor",
503
- operation: "render_block",
504
- team_name: "plan-implementation",
505
- });
506
- console.log(ui); // Markdown block with tables, emojis, progress
507
-
508
- // Option B: Get detailed status
509
- const status = await swarm({
510
- operation: "monitor",
511
- operation: "status",
512
- team_name: "plan-implementation",
513
- });
514
- const stats = JSON.parse(status).summary;
515
- // Returns: total_workers, completed, working, errors, messages
516
-
517
- // Check completion
518
- allComplete = stats.completed === stats.total_workers;
519
-
520
- if (!allComplete) {
521
- // Wait before checking again
522
- await new Promise((r) => setTimeout(r, 2000)); // Wait 2s
523
- }
524
- }
525
- ```
526
-
527
- ### Step 5: Synthesize Results
528
-
529
- When all workers complete:
530
-
531
- ```typescript
532
- // 1. Get final status
533
- const finalStatus = await swarm({
534
- operation: "monitor",
535
- operation: "status",
536
- team_name: "plan-implementation",
537
- });
538
-
539
- // 2. Run full verification
540
- await bash("npm run typecheck && npm run lint && npm test");
541
-
542
- // 3. Pull completed todos back to Beads
543
- await swarm({ operation: "sync", operation: "pull" });
544
-
545
- // 4. Clear swarm data
546
- await swarm({ operation: "monitor", operation: "clear", team_name: "plan-implementation" });
547
-
548
- // 5. Close parent bead
549
- await bash("br close parent-task --reason 'Swarm completed all subtasks'");
550
- ```
551
-
552
- ## Dependency Graph Features
553
-
554
- The `swarm` tool's plan operation includes full dependency graph analysis:
555
-
556
- ### Structure
557
-
558
- ```typescript
559
- interface DependencyGraph {
560
- nodes: TaskNode[]; // Individual tasks
561
- edges: Edge[]; // Dependencies between tasks
562
- critical_path: string[]; // Longest dependency chain
563
- parallelizable_groups: string[][]; // Tasks that can run in parallel
564
- }
565
-
566
- interface TaskNode {
567
- id: string;
568
- content: string;
569
- phase: string;
570
- worker: string;
571
- status: "pending" | "in_progress" | "completed";
572
- priority: "high" | "medium" | "low";
573
- blockedBy: string[]; // Tasks this depends on
574
- blocks: string[]; // Tasks that depend on this
575
- assignedFiles: string[]; // Files assigned to this task
576
- }
577
- ```
578
-
579
- ### Usage
580
-
581
- ```typescript
582
- const analysis = await swarm({
583
- operation: "plan",
584
- operation: "analyze",
585
- task: "Refactor API layer",
586
- files: "src/api/users.ts,src/api/posts.ts,src/api/auth.ts",
587
- });
588
-
589
- const plan = JSON.parse(analysis);
590
-
591
- // Critical path shows the longest dependency chain
592
- // Focus attention here for optimal completion time
593
- console.log(`Critical path: ${plan.dependency_graph.critical_path.join(" → ")}`);
594
-
595
- // Parallelizable groups show which tasks can run simultaneously
596
- // Each group must complete before starting the next
597
- for (let i = 0; i < plan.dependency_graph.parallelizable_groups.length; i++) {
598
- const group = plan.dependency_graph.parallelizable_groups[i];
599
- console.log(`Wave ${i + 1}: ${group.join(", ")} (${group.length} parallel tasks)`);
600
- }
601
- ```
602
-
603
- ## Todo Persistence for Cross-Session Recovery
604
-
605
- ## Delegation Packet Structure
606
-
607
- ```markdown
608
- # Delegation Packet
609
-
610
- - TASK: task-1 - Implement auth service
611
- - EXPECTED OUTCOME: Auth service with JWT tokens, tests pass
612
- - REQUIRED TOOLS:
613
- - read
614
- - grep
615
- - lsp
616
- - edit
617
- - bash
618
- - MUST DO:
619
- - LSP before edits
620
- - Run npm test after changes
621
- - Follow existing code patterns
622
- - MUST NOT DO:
623
- - No new dependencies
624
- - Don't edit config files
625
- - Don't modify shared utilities
626
- - ACCEPTANCE CHECKS:
627
- - typecheck: npm run typecheck
628
- - lint: npm run lint
629
- - test: npm test
630
- - CONTEXT:
631
- See .beads/artifacts/task-1/spec.md for requirements
632
- ```
633
-
634
- ## Worker Protocol (Updated with Progress Tracking)
635
-
636
- Workers follow this execution pattern:
637
-
638
- ### 1. Read Delegation
639
-
640
- ```typescript
641
- // First action: read the delegation packet
642
- read({ filePath: ".beads/artifacts/<task-id>/delegation.md" });
643
- ```
644
-
645
- ### 2. Announce Start with Progress
646
-
647
- ```typescript
648
- await swarm({
649
- operation: "monitor",
650
- operation: "progress_update",
651
- team_name: "plan-implementation",
652
- worker_id: "worker-1",
653
- phase: "explore", // or "generate", "reflect", etc.
654
- progress: 0,
655
- status: "working",
656
- file: "src/api/users.ts", // current file being worked on
657
- });
658
- ```
659
-
660
- ### 3. Execute Task with Progress Updates
661
-
662
- Follow the MUST DO constraints. Avoid MUST NOT DO items. Use required tools only.
663
-
664
- Report progress every 25%:
665
-
666
- ```typescript
667
- // At 25%, 50%, 75% completion
668
- await swarm({
669
- operation: "monitor",
670
- operation: "progress_update",
671
- team_name: "plan-implementation",
672
- worker_id: "worker-1",
673
- phase: "explore",
674
- progress: 25, // or 50, 75
675
- status: "working",
676
- file: "src/api/users.ts",
677
- });
678
- ```
679
-
680
- ### 4. Run Acceptance Checks
681
-
682
- ```bash
683
- # Run each check from the delegation packet
684
- npm run typecheck
685
- npm run lint
686
- npm test
687
- ```
688
-
689
- ### 5. Report Completion
690
-
691
- ```typescript
692
- // Mark as completed
693
- await swarm({
694
- operation: "monitor",
695
- operation: "progress_update",
696
- team_name: "plan-implementation",
697
- worker_id: "worker-1",
698
- phase: "explore",
699
- progress: 100,
700
- status: "completed",
701
- file: "src/api/users.ts",
702
- });
703
- ```
704
-
705
- ## Error Handling
706
-
707
- ### Worker Fails Acceptance Checks
708
-
709
- Workers report failures via progress updates with error status:
710
-
711
- ```typescript
712
- // Worker reports error via progress update
713
- await swarm({
714
- operation: "monitor",
715
- operation: "progress_update",
716
- team_name: "plan-implementation",
717
- worker_id: "worker-1",
718
- phase: "explore",
719
- progress: 75,
720
- status: "error",
721
- message: "typecheck failed: missing type for AuthToken",
722
- });
723
- ```
724
-
725
- ### Leader Response
726
-
727
- 1. Check worker status via `swarm({ operation: "monitor", operation: "status" })`
728
- 2. Review error details in progress entries
729
- 3. Decide: fix locally or reassign to new worker
730
-
731
- ### Worker Gets Blocked
732
-
733
- Workers should report blockers via progress updates:
734
-
735
- ```typescript
736
- // Worker reports blocker via progress update
737
- await swarm({
738
- operation: "monitor",
739
- operation: "progress_update",
740
- team_name: "plan-implementation",
741
- worker_id: "worker-2",
742
- phase: "explore",
743
- progress: 50,
744
- status: "blocked",
745
- message: "Need auth service types from worker-1",
746
- });
747
- ```
748
-
749
72
  ## When to Use Swarm vs Single Agent
750
73
 
751
74
  | Scenario | Approach |
@@ -756,27 +79,6 @@ await swarm({
756
79
  | Cross-domain work (FE/BE/DB) | Swarm |
757
80
  | Time-sensitive parallel work | Swarm |
758
81
 
759
- ## Integration with Beads
760
-
761
- Swarm works on top of Beads:
762
-
763
- 1. **Session start**: `swarm sync push` to make tasks visible
764
- 2. **Leader claims parent** bead
765
- 3. **Workers claim child** beads (via delegation packets)
766
- 4. **Progress tracked** via `swarm monitor progress_update`
767
- 5. **Completion syncs** back via `swarm sync pull`
768
- 6. **Close parent** bead with `br close`
769
-
770
- ```typescript
771
- // Full integration workflow
772
- await swarm({ operation: "sync", action: "push" }); // Make Beads visible
773
- // ... spawn swarm ...
774
- await swarm({ operation: "monitor", action: "render_block", team_name: "..." }); // Monitor progress
775
- // ... monitor completion ...
776
- await swarm({ operation: "sync", action: "pull" }); // Sync completed back
777
- await bash("br close parent-task --reason 'Swarm completed'");
778
- ```
779
-
780
82
  ## Quick Reference - Kimi K2.5 PARL Pattern
781
83
 
782
84
  ```
@@ -834,141 +136,6 @@ SHUTDOWN:
834
136
  - `monitor`: Progress tracking + visualization (actions: progress_update, render_block, status, clear)
835
137
  - `sync`: Beads ↔ OpenCode todos (actions: push, pull, create_shared, get_shared, update_shared, list_shared)
836
138
 
837
- ## Tmux Integration (Visual Swarm Monitoring)
838
-
839
- Enable real-time visualization of swarm workers in separate tmux panes.
840
-
841
- ### Setup
842
-
843
- 1. Start OpenCode inside tmux:
844
-
845
- ```bash
846
- tmux new -s opencode
847
- opencode
848
- ```
849
-
850
- 2. The tmux tool auto-detects when running inside tmux and uses these defaults:
851
- - Layout: `main-vertical` (leader left, workers right)
852
- - Main pane size: 60%
853
- - Auto-cleanup: enabled
854
-
855
- ### Detecting Tmux
856
-
857
- ```typescript
858
- // Check if running inside tmux
859
- const status = await tmux({ operation: "detect" });
860
- const { available, inside_session } = JSON.parse(status);
861
-
862
- if (!inside_session) {
863
- console.log("Tip: Run inside tmux for visual swarm monitoring");
864
- console.log("Start with: tmux new -s opencode");
865
- }
866
- ```
867
-
868
- ### Spawning Worker Panes
869
-
870
- When spawning workers, create visual panes:
871
-
872
- ```typescript
873
- // Before spawning worker via Task tool
874
- if (inside_session) {
875
- // Create pane for this worker
876
- const pane = await tmux({
877
- operation: "spawn",
878
- worker_id: "worker-1",
879
- title: "Explorer: auth.ts",
880
- size: 40, // 40% width
881
- });
882
-
883
- const { pane_id } = JSON.parse(pane);
884
-
885
- // Send command to pane (optional - for visual feedback)
886
- await tmux({
887
- operation: "send",
888
- pane_id,
889
- command: `echo "🔍 Worker-1: Exploring auth.ts..."`,
890
- });
891
- }
892
-
893
- // Spawn the actual worker
894
- await Task({
895
- subagent_type: "general",
896
- description: "Execute worker-1",
897
- prompt: `...`,
898
- });
899
- ```
900
-
901
- ### Layout Options
902
-
903
- | Layout | Description | Best For |
904
- | ----------------- | ------------------------------------- | ----------------------------- |
905
- | `main-vertical` | Main pane left, workers stacked right | Default, good for 2-4 workers |
906
- | `main-horizontal` | Main pane top, workers below | Wide monitors |
907
- | `tiled` | Equal grid for all panes | Many workers (5+) |
908
- | `even-horizontal` | Equal width columns | 2-3 workers |
909
- | `even-vertical` | Equal height rows | 2-3 workers |
910
-
911
- ```typescript
912
- // Change layout dynamically
913
- await tmux({
914
- operation: "layout",
915
- layout: "tiled", // When many workers spawn
916
- });
917
- ```
918
-
919
- ### Monitoring Worker Output
920
-
921
- ```typescript
922
- // Capture output from a worker's pane
923
- const output = await tmux({
924
- operation: "capture",
925
- pane_id: "%5",
926
- });
927
-
928
- // Check what the worker is doing
929
- console.log(JSON.parse(output).output);
930
- ```
931
-
932
- ### Cleanup
933
-
934
- ```typescript
935
- // Kill specific pane when worker completes
936
- await tmux({
937
- operation: "kill",
938
- pane_id: "%5",
939
- });
940
-
941
- // Or cleanup all spawned panes at end of swarm
942
- await tmux({
943
- operation: "cleanup",
944
- });
945
- ```
946
-
947
- ### User Commands
948
-
949
- | Action | Keys |
950
- | ----------------------- | ------------- |
951
- | Switch to next pane | `Ctrl+B →` |
952
- | Switch to previous pane | `Ctrl+B ←` |
953
- | Zoom current pane | `Ctrl+B z` |
954
- | Detach (keep running) | `Ctrl+B d` |
955
- | Reattach | `tmux attach` |
956
- | List all panes | `Ctrl+B w` |
957
-
958
- ### Watch Command
959
-
960
- Use `/swarm-watch` for real-time progress monitoring:
961
-
962
- ```bash
963
- /swarm-watch my-swarm-team
964
- ```
965
-
966
- This renders the beautiful TUI block and shows:
967
-
968
- - Worker progress percentages
969
- - Current files being worked on
970
- - Completion status
971
-
972
139
  ## Rules
973
140
 
974
141
  1. **Leader spawns, workers execute** - Clear role separation
@@ -983,81 +150,14 @@ This renders the beautiful TUI block and shows:
983
150
  10. **Use reconciler at scale** - Required for 50+ agents, recommended for 10+
984
151
  11. **Reconciler watches continuously** - Spawns fix tasks on detected failures
985
152
 
986
- ## Tier Enforcement (Longshot Pattern)
987
-
988
- For multi-agent execution at scale (10+ agents), enforce explicit tier hierarchy. This is the Longshot pattern that enabled 200 agents to build Minecraft.
989
-
990
- ### Tier System
991
-
992
- | Tier | Role | Swarm Equivalent | Responsibility |
993
- | --------------- | --------------------- | ---------------- | -------------------------------------------------------------- |
994
- | **planner** | Lead orchestrator | Build agent | Analyzes scope, decomposes into sub-tasks, coordinates workers |
995
- | **sub-planner** | Mid-level coordinator | N/A | Takes planner output, further decomposes, assigns to workers |
996
- | **worker** | Execution agent | Worker agents | Executes assigned work, reports progress |
997
-
998
- ### When Tiers Are Required
999
-
1000
- - **<10 agents**: Optional - flat decomposition works
1001
- - **10-50 agents**: Recommended - planner + workers
1002
- - **50+ agents**: Required - planner + sub-planners + workers
1003
-
1004
- ### Enforcing Tier Boundaries
1005
-
1006
- The swarm leader enforces tier boundaries:
1007
-
1008
- ```typescript
1009
- // Tier enforcement in swarm execution
1010
- async function enforceTiers(waves, tierConfig) {
1011
- // Wave 1: Planner tasks only
1012
- const planners = waves.filter((w) => w.tier === "planner");
1013
- await executeWave(planners);
1014
-
1015
- // Wave 2: Sub-planner tasks (if any)
1016
- const subPlanners = waves.filter((w) => w.tier === "sub-planner");
1017
- await executeWave(subPlanners);
1018
-
1019
- // Wave 3+: Worker tasks
1020
- const workers = waves.filter((w) => w.tier === "worker");
1021
- await executeWave(workers);
1022
- }
1023
- ```
1024
-
1025
- ### Handoff Contracts Between Tiers
1026
-
1027
- Each tier must declare handoff contracts:
1028
-
1029
- ```typescript
1030
- // Planner declares what it produces for sub-planners
1031
- const plannerHandoff = {
1032
- produces: [
1033
- { artifact: "docs/auth-design.md", format: "markdown" },
1034
- { artifact: "tasks/auth-tasks.json", format: "json" },
1035
- ],
1036
- consumedBy: ["sub-planner-auth"],
1037
- };
1038
-
1039
- // Worker declares what it consumes from sub-planners
1040
- const workerHandoff = {
1041
- consumes: [{ artifact: "tasks/auth-tasks.json", format: "json" }],
1042
- produces: [{ artifact: "src/auth/service.ts", format: "typescript" }],
1043
- };
1044
- ```
1045
-
1046
- ### Anti-Pattern: Flat Decomposition at Scale
1047
-
1048
- Without tiers, 20 agents get 20 flat tasks → chaos:
1049
-
1050
- - Workers step on each other
1051
- - No coordination between related work
1052
- - Merge conflicts everywhere
1053
- - No clear ownership
1054
-
1055
- With tiers (Longshot pattern):
1056
-
1057
- ```
1058
- Lead Planner → Sub-planner A → Worker 1, 2, 3
1059
- → Sub-planner B → Worker 4, 5, 6
1060
- Sub-planner C → Worker 7, 8, 9
1061
- ```
1062
-
1063
- This mirrors real engineering orgs: lead → tech lead → IC. The architecture is the differentiator.
153
+ ## References
154
+
155
+ - `references/architecture.md` - Swarm architecture diagram
156
+ - `references/reconciler.md` - Reconciler pattern, error analysis, and fix task spawning
157
+ - `references/drift-check.md` - Drift checks after each wave and recovery protocol
158
+ - `references/launch-flow.md` - PARL swarm launch flow with step-by-step code
159
+ - `references/dependency-graph.md` - Dependency graph structures and usage
160
+ - `references/delegation-worker-protocol.md` - Delegation packet structure, worker protocol, and error handling
161
+ - `references/integration-beads.md` - Swarm integration workflow with Beads
162
+ - `references/tmux-integration.md` - Tmux monitoring setup and commands
163
+ - `references/tier-enforcement.md` - Tier enforcement (Longshot pattern)