opencode-swarm-plugin 0.12.31 → 0.13.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 (49) hide show
  1. package/.beads/issues.jsonl +204 -10
  2. package/.opencode/skills/tdd/SKILL.md +182 -0
  3. package/README.md +165 -17
  4. package/bun.lock +23 -0
  5. package/dist/index.js +4082 -457
  6. package/dist/pglite.data +0 -0
  7. package/dist/pglite.wasm +0 -0
  8. package/dist/plugin.js +4070 -533
  9. package/examples/commands/swarm.md +100 -28
  10. package/examples/skills/beads-workflow/SKILL.md +75 -28
  11. package/examples/skills/swarm-coordination/SKILL.md +165 -21
  12. package/global-skills/swarm-coordination/SKILL.md +116 -58
  13. package/global-skills/testing-patterns/SKILL.md +430 -0
  14. package/global-skills/testing-patterns/references/dependency-breaking-catalog.md +586 -0
  15. package/package.json +11 -5
  16. package/src/index.ts +44 -5
  17. package/src/streams/agent-mail.test.ts +777 -0
  18. package/src/streams/agent-mail.ts +535 -0
  19. package/src/streams/debug.test.ts +500 -0
  20. package/src/streams/debug.ts +629 -0
  21. package/src/streams/effect/ask.integration.test.ts +314 -0
  22. package/src/streams/effect/ask.ts +202 -0
  23. package/src/streams/effect/cursor.integration.test.ts +418 -0
  24. package/src/streams/effect/cursor.ts +288 -0
  25. package/src/streams/effect/deferred.test.ts +357 -0
  26. package/src/streams/effect/deferred.ts +445 -0
  27. package/src/streams/effect/index.ts +17 -0
  28. package/src/streams/effect/layers.ts +73 -0
  29. package/src/streams/effect/lock.test.ts +385 -0
  30. package/src/streams/effect/lock.ts +399 -0
  31. package/src/streams/effect/mailbox.test.ts +260 -0
  32. package/src/streams/effect/mailbox.ts +318 -0
  33. package/src/streams/events.test.ts +628 -0
  34. package/src/streams/events.ts +214 -0
  35. package/src/streams/index.test.ts +229 -0
  36. package/src/streams/index.ts +492 -0
  37. package/src/streams/migrations.test.ts +355 -0
  38. package/src/streams/migrations.ts +269 -0
  39. package/src/streams/projections.test.ts +611 -0
  40. package/src/streams/projections.ts +302 -0
  41. package/src/streams/store.integration.test.ts +548 -0
  42. package/src/streams/store.ts +546 -0
  43. package/src/streams/swarm-mail.ts +552 -0
  44. package/src/swarm-mail.integration.test.ts +970 -0
  45. package/src/swarm-mail.ts +739 -0
  46. package/src/swarm.integration.test.ts +16 -10
  47. package/src/swarm.ts +146 -78
  48. package/src/tool-availability.ts +35 -2
  49. package/global-skills/mcp-tool-authoring/SKILL.md +0 -695
@@ -8,23 +8,47 @@ tags:
8
8
  tools:
9
9
  - swarm_decompose
10
10
  - swarm_complete
11
- - agentmail_init
12
- - agentmail_send
11
+ - swarmmail_init
12
+ - swarmmail_send
13
+ - swarmmail_inbox
14
+ - swarmmail_read_message
15
+ - swarmmail_reserve
16
+ - swarmmail_release
17
+ - skills_use
18
+ - skills_list
19
+ related_skills:
20
+ - testing-patterns
21
+ - system-design
22
+ - cli-builder
13
23
  ---
14
24
 
15
25
  # Swarm Coordination Skill
16
26
 
17
27
  This skill provides guidance for effective multi-agent coordination in OpenCode swarm workflows.
18
28
 
29
+ **IMPORTANT:** This skill references global skills in `global-skills/`. Workers should load domain-specific skills based on their subtask type.
30
+
31
+ ## MANDATORY: Swarm Mail
32
+
33
+ **ALL coordination MUST use `swarmmail_*` tools.** This is non-negotiable.
34
+
35
+ Swarm Mail is embedded (no external server needed) and provides:
36
+
37
+ - File reservations to prevent conflicts
38
+ - Message passing between agents
39
+ - Thread-based coordination tied to beads
40
+
19
41
  ## When to Use Swarm Coordination
20
42
 
21
43
  Use swarm coordination when:
44
+
22
45
  - A task has multiple independent subtasks that can run in parallel
23
46
  - The task requires different specializations (e.g., frontend + backend + tests)
24
47
  - Work can be divided by file/module boundaries
25
48
  - Time-to-completion matters and parallelization helps
26
49
 
27
50
  Do NOT use swarm coordination when:
51
+
28
52
  - The task is simple and can be done by one agent
29
53
  - Subtasks have heavy dependencies on each other
30
54
  - The overhead of coordination exceeds the benefit
@@ -34,6 +58,7 @@ Do NOT use swarm coordination when:
34
58
  ### 1. Analyze the Task
35
59
 
36
60
  Before decomposing, understand:
61
+
37
62
  - What are the distinct units of work?
38
63
  - Which parts can run in parallel vs sequentially?
39
64
  - What are the file/module boundaries?
@@ -42,7 +67,8 @@ Before decomposing, understand:
42
67
  ### 2. Choose a Decomposition Strategy
43
68
 
44
69
  **Parallel Strategy** - For independent subtasks:
45
- ```
70
+
71
+ ```text
46
72
  Parent Task: "Add user authentication"
47
73
  ├── Subtask 1: "Create auth API endpoints" (backend)
48
74
  ├── Subtask 2: "Build login/signup forms" (frontend)
@@ -51,7 +77,8 @@ Parent Task: "Add user authentication"
51
77
  ```
52
78
 
53
79
  **Sequential Strategy** - When order matters:
54
- ```
80
+
81
+ ```text
55
82
  Parent Task: "Migrate database schema"
56
83
  ├── Step 1: "Create migration files"
57
84
  ├── Step 2: "Update model definitions"
@@ -60,7 +87,8 @@ Parent Task: "Migrate database schema"
60
87
  ```
61
88
 
62
89
  **Hybrid Strategy** - Mixed dependencies:
63
- ```
90
+
91
+ ```text
64
92
  Parent Task: "Add feature X"
65
93
  ├── Phase 1 (parallel):
66
94
  │ ├── Subtask A: "Design API"
@@ -76,73 +104,189 @@ Parent Task: "Add feature X"
76
104
 
77
105
  When multiple agents work on the same codebase:
78
106
 
79
- 1. **Reserve files before editing** - Use `agentmail_reserve` to claim files
80
- 2. **Respect reservations** - Don't edit files reserved by other agents
81
- 3. **Release when done** - Files auto-release on task completion
82
- 4. **Coordinate on shared files** - If you must edit a reserved file, send a message to the owning agent
107
+ 1. **Initialize Swarm Mail first** - Use `swarmmail_init` before any work
108
+ 2. **Reserve files before editing** - Use `swarmmail_reserve` to claim files
109
+ 3. **Respect reservations** - Don't edit files reserved by other agents
110
+ 4. **Release when done** - Use `swarmmail_release` or let `swarm_complete` handle it
111
+ 5. **Coordinate on shared files** - If you must edit a reserved file, send a message to the owning agent
112
+
113
+ ```typescript
114
+ // Initialize first
115
+ await swarmmail_init({
116
+ project_path: "$PWD",
117
+ task_description: "Working on auth feature",
118
+ });
119
+
120
+ // Reserve files
121
+ await swarmmail_reserve({
122
+ paths: ["src/auth/**"],
123
+ reason: "bd-123: Auth implementation",
124
+ ttl_seconds: 3600,
125
+ });
126
+
127
+ // Work...
128
+
129
+ // Release when done
130
+ await swarmmail_release();
131
+ ```
83
132
 
84
133
  ## Communication Patterns
85
134
 
86
135
  ### Broadcasting Updates
87
- ```
88
- agentmail_send(recipients: ["all"], message: "Completed API endpoints, ready for frontend integration")
136
+
137
+ ```typescript
138
+ swarmmail_send({
139
+ to: ["*"],
140
+ subject: "API Complete",
141
+ body: "Completed API endpoints, ready for frontend integration",
142
+ thread_id: epic_id,
143
+ });
89
144
  ```
90
145
 
91
146
  ### Direct Coordination
92
- ```
93
- agentmail_send(recipients: ["frontend-agent"], message: "Auth API is at /api/auth/*, here's the spec...")
147
+
148
+ ```typescript
149
+ swarmmail_send({
150
+ to: ["frontend-agent"],
151
+ subject: "Auth API Spec",
152
+ body: "Auth API is at /api/auth/*, here's the spec...",
153
+ thread_id: epic_id,
154
+ });
94
155
  ```
95
156
 
96
- ### Blocking on Dependencies
157
+ ### Checking for Messages
158
+
159
+ ```typescript
160
+ // Check inbox (max 5, no bodies for context safety)
161
+ const inbox = await swarmmail_inbox();
162
+
163
+ // Read specific message body
164
+ const message = await swarmmail_read_message({ message_id: N });
97
165
  ```
98
- # Wait for a dependency before proceeding
99
- agentmail_receive(wait: true, filter: "api-complete")
166
+
167
+ ### Reporting Blockers
168
+
169
+ ```typescript
170
+ swarmmail_send({
171
+ to: ["coordinator"],
172
+ subject: "BLOCKED: Need DB schema",
173
+ body: "Can't proceed without users table",
174
+ thread_id: epic_id,
175
+ importance: "urgent",
176
+ });
100
177
  ```
101
178
 
102
179
  ## Best Practices
103
180
 
104
- 1. **Small, focused subtasks** - Each subtask should be completable in one agent session
105
- 2. **Clear boundaries** - Define exactly what files/modules each subtask touches
106
- 3. **Explicit handoffs** - When one task enables another, communicate clearly
107
- 4. **Graceful failures** - If a subtask fails, don't block the whole swarm
108
- 5. **Progress updates** - Use beads to track subtask status
181
+ 1. **Initialize Swarm Mail first** - Always call `swarmmail_init` before any work
182
+ 2. **Small, focused subtasks** - Each subtask should be completable in one agent session
183
+ 3. **Clear boundaries** - Define exactly what files/modules each subtask touches
184
+ 4. **Explicit handoffs** - When one task enables another, communicate clearly
185
+ 5. **Graceful failures** - If a subtask fails, don't block the whole swarm
186
+ 6. **Progress updates** - Use beads to track subtask status
187
+ 7. **Load relevant skills** - Workers should call `skills_use()` based on their task type:
188
+ - Testing work → `skills_use(name="testing-patterns")`
189
+ - Architecture decisions → `skills_use(name="system-design")`
190
+ - CLI development → `skills_use(name="cli-builder")`
191
+ - Multi-agent coordination → `skills_use(name="swarm-coordination")`
109
192
 
110
193
  ## Common Patterns
111
194
 
112
195
  ### Feature Development
196
+
113
197
  ```yaml
114
198
  decomposition:
115
199
  strategy: hybrid
200
+ skills: [system-design, swarm-coordination]
116
201
  phases:
117
202
  - name: design
118
203
  parallel: true
119
204
  subtasks: [api-design, ui-design]
205
+ recommended_skills: [system-design]
120
206
  - name: implement
121
207
  parallel: true
122
208
  subtasks: [backend, frontend]
209
+ recommended_skills: [system-design]
123
210
  - name: validate
124
211
  parallel: true
125
212
  subtasks: [tests, docs, review]
213
+ recommended_skills: [testing-patterns]
126
214
  ```
127
215
 
128
216
  ### Bug Fix Swarm
217
+
129
218
  ```yaml
130
219
  decomposition:
131
220
  strategy: sequential
221
+ skills: [testing-patterns]
132
222
  subtasks:
133
223
  - reproduce-bug
134
224
  - identify-root-cause
135
225
  - implement-fix
136
226
  - add-regression-test
227
+ recommended_skills: [testing-patterns]
137
228
  ```
138
229
 
139
230
  ### Refactoring
231
+
140
232
  ```yaml
141
233
  decomposition:
142
234
  strategy: parallel
235
+ skills: [testing-patterns, system-design]
143
236
  subtasks:
144
237
  - refactor-module-a
145
238
  - refactor-module-b
146
239
  - update-imports
147
240
  - run-full-test-suite
241
+ recommended_skills: [testing-patterns, system-design]
242
+ ```
243
+
244
+ ## Skill Integration Workflow
245
+
246
+ **For Coordinators:**
247
+
248
+ 1. Initialize Swarm Mail with `swarmmail_init`
249
+ 2. Load `swarm-coordination` skill
250
+ 3. Analyze task type
251
+ 4. Load additional skills based on domain (testing, design, CLI)
252
+ 5. Include skill recommendations in `shared_context` for workers
253
+
254
+ **For Workers:**
255
+
256
+ 1. Initialize Swarm Mail with `swarmmail_init`
257
+ 2. Read `shared_context` from coordinator
258
+ 3. Load recommended skills with `skills_use(name="skill-name")`
259
+ 4. Apply skill knowledge to subtask
260
+ 5. Report progress via `swarmmail_send`
261
+ 6. Complete with `swarm_complete`
262
+
263
+ **Example shared_context:**
264
+
265
+ ```markdown
266
+ ## Context from Coordinator
267
+
268
+ Past similar tasks: [CASS results]
269
+ Project learnings: [semantic-memory results]
270
+
271
+ ## Recommended Skills
272
+
273
+ - skills_use(name="testing-patterns") - for test creation
274
+ - skills_use(name="system-design") - for module boundaries
275
+
276
+ ## Task-Specific Notes
277
+
278
+ [Domain knowledge from coordinator]
148
279
  ```
280
+
281
+ ## Swarm Mail Quick Reference
282
+
283
+ | Tool | Purpose |
284
+ | ------------------------ | ----------------------------------- |
285
+ | `swarmmail_init` | Initialize session (REQUIRED FIRST) |
286
+ | `swarmmail_send` | Send message to agents |
287
+ | `swarmmail_inbox` | Check inbox (max 5, no bodies) |
288
+ | `swarmmail_read_message` | Read specific message body |
289
+ | `swarmmail_reserve` | Reserve files for exclusive editing |
290
+ | `swarmmail_release` | Release file reservations |
291
+ | `swarmmail_ack` | Acknowledge message |
292
+ | `swarmmail_health` | Check database health |
@@ -15,11 +15,13 @@ tools:
15
15
  - swarm_progress
16
16
  - beads_create_epic
17
17
  - beads_query
18
- - agentmail_init
19
- - agentmail_send
20
- - agentmail_inbox
21
- - agentmail_reserve
22
- - agentmail_release
18
+ - swarmmail_init
19
+ - swarmmail_send
20
+ - swarmmail_inbox
21
+ - swarmmail_read_message
22
+ - swarmmail_reserve
23
+ - swarmmail_release
24
+ - swarmmail_health
23
25
  - semantic-memory_find
24
26
  - cass_search
25
27
  - pdf-brain_search
@@ -33,6 +35,16 @@ references:
33
35
 
34
36
  Multi-agent orchestration for parallel task execution. The coordinator breaks work into subtasks, spawns worker agents, monitors progress, and aggregates results.
35
37
 
38
+ ## MANDATORY: Swarm Mail
39
+
40
+ **ALL coordination MUST use `swarmmail_*` tools.** This is non-negotiable.
41
+
42
+ Swarm Mail is embedded (no external server needed) and provides:
43
+
44
+ - File reservations to prevent conflicts
45
+ - Message passing between agents
46
+ - Thread-based coordination tied to beads
47
+
36
48
  ## When to Swarm
37
49
 
38
50
  **DO swarm when:**
@@ -53,19 +65,29 @@ Multi-agent orchestration for parallel task execution. The coordinator breaks wo
53
65
 
54
66
  ## Coordinator Workflow
55
67
 
56
- ### Phase 1: Knowledge Gathering (MANDATORY)
68
+ ### Phase 1: Initialize Swarm Mail (FIRST)
69
+
70
+ ```typescript
71
+ // ALWAYS initialize first - registers you as coordinator
72
+ await swarmmail_init({
73
+ project_path: "$PWD",
74
+ task_description: "Swarm: <task summary>",
75
+ });
76
+ ```
77
+
78
+ ### Phase 2: Knowledge Gathering (MANDATORY)
57
79
 
58
80
  Before decomposing, query ALL knowledge sources:
59
81
 
60
82
  ```typescript
61
83
  // 1. Past learnings from this project
62
- semantic - memory_find({ query: "<task keywords>", limit: 5 });
84
+ semantic_memory_find({ query: "<task keywords>", limit: 5 });
63
85
 
64
86
  // 2. How similar tasks were solved before
65
87
  cass_search({ query: "<task description>", limit: 5 });
66
88
 
67
89
  // 3. Design patterns and prior art
68
- pdf - brain_search({ query: "<domain concepts>", limit: 5 });
90
+ pdf_brain_search({ query: "<domain concepts>", limit: 5 });
69
91
 
70
92
  // 4. Available skills to inject into workers
71
93
  skills_list();
@@ -73,7 +95,7 @@ skills_list();
73
95
 
74
96
  Synthesize findings into `shared_context` for workers.
75
97
 
76
- ### Phase 2: Decomposition
98
+ ### Phase 3: Decomposition
77
99
 
78
100
  ```typescript
79
101
  // Auto-select strategy and generate decomposition prompt
@@ -97,7 +119,25 @@ await beads_create_epic({
97
119
  });
98
120
  ```
99
121
 
100
- ### Phase 3: Spawn Workers
122
+ ### Phase 4: Reserve Files (via Swarm Mail)
123
+
124
+ ```typescript
125
+ // Reserve files for each subtask BEFORE spawning workers
126
+ await swarmmail_reserve({
127
+ paths: ["src/auth/**"],
128
+ reason: "bd-123: Auth service implementation",
129
+ ttl_seconds: 3600,
130
+ exclusive: true,
131
+ });
132
+ ```
133
+
134
+ **Rules:**
135
+
136
+ - No file overlap between subtasks
137
+ - Coordinator mediates conflicts
138
+ - `swarm_complete` auto-releases
139
+
140
+ ### Phase 5: Spawn Workers
101
141
 
102
142
  ```typescript
103
143
  for (const subtask of subtasks) {
@@ -118,25 +158,41 @@ for (const subtask of subtasks) {
118
158
  }
119
159
  ```
120
160
 
121
- ### Phase 4: Monitor & Intervene
161
+ ### Phase 6: Monitor & Intervene
122
162
 
123
163
  ```typescript
124
164
  // Check progress
125
165
  const status = await swarm_status({ epic_id, project_key });
126
166
 
127
- // Check for messages
128
- const inbox = await agentmail_inbox({ limit: 5 });
167
+ // Check for messages from workers
168
+ const inbox = await swarmmail_inbox({ limit: 5 });
169
+
170
+ // Read specific message if needed
171
+ const message = await swarmmail_read_message({ message_id: N });
129
172
 
130
173
  // Intervene if needed (see Intervention Patterns)
131
174
  ```
132
175
 
133
- ### Phase 5: Aggregate & Complete
176
+ ### Phase 7: Aggregate & Complete
134
177
 
135
178
  - Verify all subtasks completed
136
179
  - Run final verification (typecheck, tests)
137
180
  - Close epic with summary
181
+ - Release any remaining reservations
138
182
  - Record outcomes for learning
139
183
 
184
+ ```typescript
185
+ await swarm_complete({
186
+ project_key: "$PWD",
187
+ agent_name: "coordinator",
188
+ bead_id: epic_id,
189
+ summary: "All subtasks complete",
190
+ files_touched: [...],
191
+ });
192
+ await swarmmail_release(); // Release any remaining reservations
193
+ await beads_sync();
194
+ ```
195
+
140
196
  ## Decomposition Strategies
141
197
 
142
198
  Four strategies, auto-selected by task keywords:
@@ -150,37 +206,13 @@ Four strategies, auto-selected by task keywords:
150
206
 
151
207
  See `references/strategies.md` for full details.
152
208
 
153
- ## File Reservation Protocol
154
-
155
- Workers MUST reserve files before editing:
156
-
157
- ```typescript
158
- // Reserve (exclusive by default)
159
- await agentmail_reserve({
160
- paths: ["src/auth/**"],
161
- reason: "bd-123: Auth service implementation",
162
- ttl_seconds: 3600,
163
- });
164
-
165
- // Work...
166
-
167
- // Release (or let swarm_complete handle it)
168
- await agentmail_release({ paths: ["src/auth/**"] });
169
- ```
170
-
171
- **Rules:**
172
-
173
- - No file overlap between subtasks
174
- - Coordinator mediates conflicts
175
- - `swarm_complete` auto-releases
176
-
177
209
  ## Communication Protocol
178
210
 
179
- Workers communicate via Agent Mail with epic ID as thread:
211
+ Workers communicate via Swarm Mail with epic ID as thread:
180
212
 
181
213
  ```typescript
182
214
  // Progress update
183
- agentmail_send({
215
+ swarmmail_send({
184
216
  to: ["coordinator"],
185
217
  subject: "Auth API complete",
186
218
  body: "Endpoints ready at /api/auth/*",
@@ -188,7 +220,7 @@ agentmail_send({
188
220
  });
189
221
 
190
222
  // Blocker
191
- agentmail_send({
223
+ swarmmail_send({
192
224
  to: ["coordinator"],
193
225
  subject: "BLOCKED: Need DB schema",
194
226
  body: "Can't proceed without users table",
@@ -265,25 +297,51 @@ One blocker affects multiple subtasks.
265
297
  - Thread: {epic_id}
266
298
  ```
267
299
 
268
- ## Quick Reference
300
+ ## Swarm Mail Quick Reference
301
+
302
+ | Tool | Purpose |
303
+ | ------------------------ | ----------------------------------- |
304
+ | `swarmmail_init` | Initialize session (REQUIRED FIRST) |
305
+ | `swarmmail_send` | Send message to agents |
306
+ | `swarmmail_inbox` | Check inbox (max 5, no bodies) |
307
+ | `swarmmail_read_message` | Read specific message body |
308
+ | `swarmmail_reserve` | Reserve files for exclusive editing |
309
+ | `swarmmail_release` | Release file reservations |
310
+ | `swarmmail_ack` | Acknowledge message |
311
+ | `swarmmail_health` | Check database health |
312
+
313
+ ## Full Swarm Flow
269
314
 
270
315
  ```typescript
271
- // Full swarm flow
272
- semantic - memory_find({ query }); // 1. Check learnings
273
- cass_search({ query }); // 2. Check history
274
- pdf - brain_search({ query }); // 3. Check patterns
275
- skills_list(); // 4. Check skills
276
-
277
- swarm_plan_prompt({ task }); // 5. Generate decomposition
278
- swarm_validate_decomposition(); // 6. Validate
279
- beads_create_epic(); // 7. Create beads
280
-
281
- swarm_spawn_subtask(); // 8. Spawn workers (loop)
282
- swarm_status(); // 9. Monitor
283
- agentmail_inbox(); // 10. Check messages
284
-
285
- // Workers complete with:
286
- swarm_complete(); // Auto: close bead, release files, notify
316
+ // 1. Initialize Swarm Mail FIRST
317
+ swarmmail_init({ project_path: "$PWD", task_description: "..." });
318
+
319
+ // 2. Gather knowledge
320
+ semantic_memory_find({ query });
321
+ cass_search({ query });
322
+ pdf_brain_search({ query });
323
+ skills_list();
324
+
325
+ // 3. Decompose
326
+ swarm_plan_prompt({ task });
327
+ swarm_validate_decomposition();
328
+ beads_create_epic();
329
+
330
+ // 4. Reserve files
331
+ swarmmail_reserve({ paths, reason, ttl_seconds });
332
+
333
+ // 5. Spawn workers (loop)
334
+ swarm_spawn_subtask();
335
+
336
+ // 6. Monitor
337
+ swarm_status();
338
+ swarmmail_inbox();
339
+ swarmmail_read_message({ message_id });
340
+
341
+ // 7. Complete
342
+ swarm_complete();
343
+ swarmmail_release();
344
+ beads_sync();
287
345
  ```
288
346
 
289
347
  See `references/coordinator-patterns.md` for detailed patterns.