opencode-swarm-plugin 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.beads/issues.jsonl +487 -0
- package/README.md +107 -12
- package/dist/index.js +38 -38
- package/dist/plugin.js +38 -38
- package/examples/agents/swarm-planner.md +138 -0
- package/examples/commands/swarm.md +277 -0
- package/package.json +1 -1
- package/src/index.ts +12 -0
- package/src/learning.ts +13 -0
- package/src/swarm.integration.test.ts +315 -42
- package/src/swarm.ts +528 -52
package/README.md
CHANGED
|
@@ -131,6 +131,8 @@ Client-side, per-agent rate limits prevent abuse and ensure fair resource usage
|
|
|
131
131
|
| Tool | Description |
|
|
132
132
|
| ------------------------------ | ------------------------------------------------------------------------ |
|
|
133
133
|
| `swarm_init` | Check tool availability, report degraded features |
|
|
134
|
+
| `swarm_select_strategy` | Analyze task and recommend decomposition strategy |
|
|
135
|
+
| `swarm_plan_prompt` | Generate strategy-specific planning prompt with CASS integration |
|
|
134
136
|
| `swarm_decompose` | Generate decomposition prompt, optionally queries CASS for similar tasks |
|
|
135
137
|
| `swarm_validate_decomposition` | Validate decomposition response, detect instruction conflicts |
|
|
136
138
|
| `swarm_status` | Get swarm status by epic ID |
|
|
@@ -138,7 +140,7 @@ Client-side, per-agent rate limits prevent abuse and ensure fair resource usage
|
|
|
138
140
|
| `swarm_complete` | Mark subtask complete with UBS bug scan, release reservations |
|
|
139
141
|
| `swarm_record_outcome` | Record outcome for implicit feedback (duration, errors, retries) |
|
|
140
142
|
| `swarm_subtask_prompt` | Generate prompt for spawned subtask agent (V1 - includes coordination) |
|
|
141
|
-
| `swarm_spawn_subtask` | Generate V2 prompt
|
|
143
|
+
| `swarm_spawn_subtask` | Generate V2 prompt with Agent Mail/beads instructions for subagents |
|
|
142
144
|
| `swarm_complete_subtask` | Handle subtask completion: close bead, create issue beads |
|
|
143
145
|
| `swarm_evaluation_prompt` | Generate self-evaluation prompt |
|
|
144
146
|
|
|
@@ -152,6 +154,80 @@ Client-side, per-agent rate limits prevent abuse and ensure fair resource usage
|
|
|
152
154
|
| `structured_parse_decomposition` | Parse and validate task decomposition |
|
|
153
155
|
| `structured_parse_bead_tree` | Parse and validate bead tree for epic creation |
|
|
154
156
|
|
|
157
|
+
## Decomposition Strategies
|
|
158
|
+
|
|
159
|
+
The plugin supports three decomposition strategies, auto-selected based on task keywords:
|
|
160
|
+
|
|
161
|
+
### File-Based Strategy
|
|
162
|
+
|
|
163
|
+
Best for: Refactoring, migrations, pattern changes across codebase
|
|
164
|
+
|
|
165
|
+
**Keywords**: refactor, migrate, rename, update all, convert, upgrade
|
|
166
|
+
|
|
167
|
+
**Guidelines**:
|
|
168
|
+
|
|
169
|
+
- Group files by directory or type
|
|
170
|
+
- Handle shared types/utilities first
|
|
171
|
+
- Minimize cross-directory dependencies
|
|
172
|
+
|
|
173
|
+
### Feature-Based Strategy
|
|
174
|
+
|
|
175
|
+
Best for: New features, adding functionality
|
|
176
|
+
|
|
177
|
+
**Keywords**: add, implement, build, create, feature, new
|
|
178
|
+
|
|
179
|
+
**Guidelines**:
|
|
180
|
+
|
|
181
|
+
- Each subtask is a complete vertical slice
|
|
182
|
+
- Start with data layer, then logic, then UI
|
|
183
|
+
- Keep related components together
|
|
184
|
+
|
|
185
|
+
### Risk-Based Strategy
|
|
186
|
+
|
|
187
|
+
Best for: Bug fixes, security issues, critical changes
|
|
188
|
+
|
|
189
|
+
**Keywords**: fix, bug, security, critical, urgent, hotfix
|
|
190
|
+
|
|
191
|
+
**Guidelines**:
|
|
192
|
+
|
|
193
|
+
- Write tests FIRST
|
|
194
|
+
- Isolate risky changes
|
|
195
|
+
- Audit similar code for same issue
|
|
196
|
+
|
|
197
|
+
### Strategy Selection
|
|
198
|
+
|
|
199
|
+
Use `swarm_select_strategy` to see the recommended strategy:
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
swarm_select_strategy({ task: "Add user authentication" });
|
|
203
|
+
// Returns: { strategy: "feature-based", confidence: 0.85, reasoning: "..." }
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Or let `swarm_plan_prompt` auto-select:
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
swarm_plan_prompt({ task: "Refactor all components to use hooks" });
|
|
210
|
+
// Auto-selects file-based strategy
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## Example Planner Agent
|
|
214
|
+
|
|
215
|
+
The plugin includes an example planner agent at `examples/agents/swarm-planner.md`.
|
|
216
|
+
|
|
217
|
+
Copy to your OpenCode agents directory:
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
cp examples/agents/swarm-planner.md ~/.config/opencode/agents/
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
Then invoke with:
|
|
224
|
+
|
|
225
|
+
```
|
|
226
|
+
@swarm-planner "Add user authentication with OAuth"
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
The planner uses `swarm_select_strategy` and `swarm_plan_prompt` internally to create optimal decompositions.
|
|
230
|
+
|
|
155
231
|
### Schemas (for structured outputs)
|
|
156
232
|
|
|
157
233
|
The plugin exports Zod schemas for validated agent responses:
|
|
@@ -429,24 +505,43 @@ The plugin enforces these limits regardless of input:
|
|
|
429
505
|
- Thread summaries use LLM mode for concise output
|
|
430
506
|
- File reservations auto-track for cleanup
|
|
431
507
|
|
|
432
|
-
##
|
|
508
|
+
## Custom Commands
|
|
509
|
+
|
|
510
|
+
This plugin provides tools that work with OpenCode's [custom commands](https://opencode.ai/docs/commands). Create a `/swarm` command to orchestrate multi-agent work.
|
|
511
|
+
|
|
512
|
+
### Setup /swarm Command
|
|
433
513
|
|
|
434
|
-
|
|
514
|
+
Copy the example command to your OpenCode config:
|
|
515
|
+
|
|
516
|
+
```bash
|
|
517
|
+
cp examples/commands/swarm.md ~/.config/opencode/command/
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
### Usage
|
|
435
521
|
|
|
436
522
|
```
|
|
437
523
|
/swarm "Add user authentication with OAuth providers"
|
|
438
524
|
```
|
|
439
525
|
|
|
440
|
-
|
|
526
|
+
### How It Works
|
|
527
|
+
|
|
528
|
+
1. **Decompose** - `swarm_decompose` breaks task into subtasks with file assignments
|
|
529
|
+
2. **Create beads** - `beads_create_epic` creates epic + subtasks atomically
|
|
530
|
+
3. **Spawn agents** - `swarm_spawn_subtask` generates prompts WITH Agent Mail/beads instructions
|
|
531
|
+
4. **Parallel work** - Subagents use Agent Mail to communicate, beads to track progress
|
|
532
|
+
5. **Coordination** - Agents report progress, ask questions, announce blockers via Agent Mail
|
|
533
|
+
6. **Completion** - Agents use `swarm_complete` when done
|
|
534
|
+
7. **Cleanup** - `beads_sync` pushes to git
|
|
535
|
+
|
|
536
|
+
### Subagent Capabilities
|
|
537
|
+
|
|
538
|
+
Spawned subagents have **full access** to all plugin tools:
|
|
539
|
+
|
|
540
|
+
- **Agent Mail** - `agentmail_send`, `agentmail_inbox`, `agentmail_reserve`, etc.
|
|
541
|
+
- **Beads** - `beads_update`, `beads_create`, `swarm_complete`
|
|
542
|
+
- All standard OpenCode tools
|
|
441
543
|
|
|
442
|
-
|
|
443
|
-
2. **Create beads** - Use `beads_create_epic` for atomic issue creation
|
|
444
|
-
3. **Initialize agents** - Each agent calls `agentmail_init`
|
|
445
|
-
4. **Reserve files** - Prevent conflicts with `agentmail_reserve`
|
|
446
|
-
5. **Coordinate** - Agents communicate via `agentmail_send`
|
|
447
|
-
6. **Track status** - Use `SwarmStatusSchema` for progress
|
|
448
|
-
7. **Evaluate** - Validate work with `EvaluationSchema`
|
|
449
|
-
8. **Cleanup** - Release reservations and sync beads
|
|
544
|
+
The prompts tell agents to actively communicate and coordinate.
|
|
450
545
|
|
|
451
546
|
## Error Handling
|
|
452
547
|
|
package/dist/index.js
CHANGED
|
@@ -23701,61 +23701,57 @@ Before writing code:
|
|
|
23701
23701
|
4. **Communicate your plan** via Agent Mail if non-trivial
|
|
23702
23702
|
|
|
23703
23703
|
Begin work on your subtask now.`;
|
|
23704
|
-
var SUBTASK_PROMPT_V2 = `You are
|
|
23704
|
+
var SUBTASK_PROMPT_V2 = `You are a swarm agent working on: **{subtask_title}**
|
|
23705
23705
|
|
|
23706
|
-
##
|
|
23707
|
-
**
|
|
23706
|
+
## Identity
|
|
23707
|
+
- **Bead ID**: {bead_id}
|
|
23708
|
+
- **Epic ID**: {epic_id}
|
|
23708
23709
|
|
|
23710
|
+
## Task
|
|
23709
23711
|
{subtask_description}
|
|
23710
23712
|
|
|
23711
|
-
## Files
|
|
23713
|
+
## Files (exclusive reservation)
|
|
23712
23714
|
{file_list}
|
|
23713
23715
|
|
|
23714
|
-
|
|
23716
|
+
Only modify these files. Need others? Message the coordinator.
|
|
23715
23717
|
|
|
23716
23718
|
## Context
|
|
23717
23719
|
{shared_context}
|
|
23718
23720
|
|
|
23719
|
-
##
|
|
23721
|
+
## MANDATORY: Use These Tools
|
|
23720
23722
|
|
|
23721
|
-
|
|
23722
|
-
|
|
23723
|
-
|
|
23724
|
-
|
|
23723
|
+
### Agent Mail - communicate with the swarm
|
|
23724
|
+
\`\`\`typescript
|
|
23725
|
+
// Report progress, ask questions, announce blockers
|
|
23726
|
+
agentmail_send({
|
|
23727
|
+
to: ["coordinator"],
|
|
23728
|
+
subject: "Progress update",
|
|
23729
|
+
body: "What you did or need",
|
|
23730
|
+
thread_id: "{epic_id}"
|
|
23731
|
+
})
|
|
23732
|
+
\`\`\`
|
|
23725
23733
|
|
|
23726
|
-
|
|
23734
|
+
### Beads - track your work
|
|
23735
|
+
- **Blocked?** \`beads_update({ id: "{bead_id}", status: "blocked" })\`
|
|
23736
|
+
- **Found bug?** \`beads_create({ title: "Bug description", type: "bug" })\`
|
|
23737
|
+
- **Done?** \`swarm_complete({ bead_id: "{bead_id}", summary: "What you did", files_touched: [...] })\`
|
|
23727
23738
|
|
|
23728
|
-
|
|
23739
|
+
## Workflow
|
|
23729
23740
|
|
|
23730
|
-
|
|
23731
|
-
|
|
23732
|
-
|
|
23733
|
-
|
|
23734
|
-
|
|
23735
|
-
|
|
23736
|
-
"issues_found": ["any problems or concerns discovered"],
|
|
23737
|
-
"tests_passed": true,
|
|
23738
|
-
"notes": "Any additional context for the coordinator"
|
|
23739
|
-
}
|
|
23740
|
-
\`\`\`
|
|
23741
|
+
1. **Read** the files first
|
|
23742
|
+
2. **Plan** your approach (message coordinator if complex)
|
|
23743
|
+
3. **Implement** the changes
|
|
23744
|
+
4. **Verify** (typecheck, tests)
|
|
23745
|
+
5. **Report** progress via Agent Mail
|
|
23746
|
+
6. **Complete** with swarm_complete when done
|
|
23741
23747
|
|
|
23742
|
-
|
|
23748
|
+
**Never work silently.** Communicate progress and blockers immediately.
|
|
23743
23749
|
|
|
23744
|
-
|
|
23745
|
-
{
|
|
23746
|
-
"success": false,
|
|
23747
|
-
"summary": "What you attempted",
|
|
23748
|
-
"blocker": "Description of what's blocking you",
|
|
23749
|
-
"files_modified": [],
|
|
23750
|
-
"suggestions": ["possible", "solutions"]
|
|
23751
|
-
}
|
|
23752
|
-
\`\`\`
|
|
23753
|
-
|
|
23754
|
-
Begin work now.`;
|
|
23750
|
+
Begin now.`;
|
|
23755
23751
|
function formatSubtaskPromptV2(params) {
|
|
23756
23752
|
const fileList = params.files.length > 0 ? params.files.map((f) => `- \`${f}\``).join(`
|
|
23757
|
-
`) : "(no specific files
|
|
23758
|
-
return SUBTASK_PROMPT_V2.replace("{subtask_title}", params.subtask_title).replace("{subtask_description}", params.subtask_description || "(see title)").replace("{file_list}", fileList).replace("{shared_context}", params.shared_context || "(none
|
|
23753
|
+
`) : "(no specific files - use judgment)";
|
|
23754
|
+
return SUBTASK_PROMPT_V2.replace(/{bead_id}/g, params.bead_id).replace(/{epic_id}/g, params.epic_id).replace("{subtask_title}", params.subtask_title).replace("{subtask_description}", params.subtask_description || "(see title)").replace("{file_list}", fileList).replace("{shared_context}", params.shared_context || "(none)");
|
|
23759
23755
|
}
|
|
23760
23756
|
var EVALUATION_PROMPT = `Evaluate the work completed for this subtask.
|
|
23761
23757
|
|
|
@@ -24357,9 +24353,10 @@ var swarm_subtask_prompt = tool({
|
|
|
24357
24353
|
}
|
|
24358
24354
|
});
|
|
24359
24355
|
var swarm_spawn_subtask = tool({
|
|
24360
|
-
description: "Prepare a subtask for spawning
|
|
24356
|
+
description: "Prepare a subtask for spawning. Returns prompt with Agent Mail/beads instructions.",
|
|
24361
24357
|
args: {
|
|
24362
24358
|
bead_id: tool.schema.string().describe("Subtask bead ID"),
|
|
24359
|
+
epic_id: tool.schema.string().describe("Parent epic bead ID"),
|
|
24363
24360
|
subtask_title: tool.schema.string().describe("Subtask title"),
|
|
24364
24361
|
subtask_description: tool.schema.string().optional().describe("Detailed subtask instructions"),
|
|
24365
24362
|
files: tool.schema.array(tool.schema.string()).describe("Files assigned to this subtask"),
|
|
@@ -24367,6 +24364,8 @@ var swarm_spawn_subtask = tool({
|
|
|
24367
24364
|
},
|
|
24368
24365
|
async execute(args) {
|
|
24369
24366
|
const prompt = formatSubtaskPromptV2({
|
|
24367
|
+
bead_id: args.bead_id,
|
|
24368
|
+
epic_id: args.epic_id,
|
|
24370
24369
|
subtask_title: args.subtask_title,
|
|
24371
24370
|
subtask_description: args.subtask_description || "",
|
|
24372
24371
|
files: args.files,
|
|
@@ -24375,6 +24374,7 @@ var swarm_spawn_subtask = tool({
|
|
|
24375
24374
|
return JSON.stringify({
|
|
24376
24375
|
prompt,
|
|
24377
24376
|
bead_id: args.bead_id,
|
|
24377
|
+
epic_id: args.epic_id,
|
|
24378
24378
|
files: args.files
|
|
24379
24379
|
}, null, 2);
|
|
24380
24380
|
}
|
package/dist/plugin.js
CHANGED
|
@@ -23660,61 +23660,57 @@ Before writing code:
|
|
|
23660
23660
|
4. **Communicate your plan** via Agent Mail if non-trivial
|
|
23661
23661
|
|
|
23662
23662
|
Begin work on your subtask now.`;
|
|
23663
|
-
var SUBTASK_PROMPT_V2 = `You are
|
|
23663
|
+
var SUBTASK_PROMPT_V2 = `You are a swarm agent working on: **{subtask_title}**
|
|
23664
23664
|
|
|
23665
|
-
##
|
|
23666
|
-
**
|
|
23665
|
+
## Identity
|
|
23666
|
+
- **Bead ID**: {bead_id}
|
|
23667
|
+
- **Epic ID**: {epic_id}
|
|
23667
23668
|
|
|
23669
|
+
## Task
|
|
23668
23670
|
{subtask_description}
|
|
23669
23671
|
|
|
23670
|
-
## Files
|
|
23672
|
+
## Files (exclusive reservation)
|
|
23671
23673
|
{file_list}
|
|
23672
23674
|
|
|
23673
|
-
|
|
23675
|
+
Only modify these files. Need others? Message the coordinator.
|
|
23674
23676
|
|
|
23675
23677
|
## Context
|
|
23676
23678
|
{shared_context}
|
|
23677
23679
|
|
|
23678
|
-
##
|
|
23680
|
+
## MANDATORY: Use These Tools
|
|
23679
23681
|
|
|
23680
|
-
|
|
23681
|
-
|
|
23682
|
-
|
|
23683
|
-
|
|
23682
|
+
### Agent Mail - communicate with the swarm
|
|
23683
|
+
\`\`\`typescript
|
|
23684
|
+
// Report progress, ask questions, announce blockers
|
|
23685
|
+
agentmail_send({
|
|
23686
|
+
to: ["coordinator"],
|
|
23687
|
+
subject: "Progress update",
|
|
23688
|
+
body: "What you did or need",
|
|
23689
|
+
thread_id: "{epic_id}"
|
|
23690
|
+
})
|
|
23691
|
+
\`\`\`
|
|
23684
23692
|
|
|
23685
|
-
|
|
23693
|
+
### Beads - track your work
|
|
23694
|
+
- **Blocked?** \`beads_update({ id: "{bead_id}", status: "blocked" })\`
|
|
23695
|
+
- **Found bug?** \`beads_create({ title: "Bug description", type: "bug" })\`
|
|
23696
|
+
- **Done?** \`swarm_complete({ bead_id: "{bead_id}", summary: "What you did", files_touched: [...] })\`
|
|
23686
23697
|
|
|
23687
|
-
|
|
23698
|
+
## Workflow
|
|
23688
23699
|
|
|
23689
|
-
|
|
23690
|
-
|
|
23691
|
-
|
|
23692
|
-
|
|
23693
|
-
|
|
23694
|
-
|
|
23695
|
-
"issues_found": ["any problems or concerns discovered"],
|
|
23696
|
-
"tests_passed": true,
|
|
23697
|
-
"notes": "Any additional context for the coordinator"
|
|
23698
|
-
}
|
|
23699
|
-
\`\`\`
|
|
23700
|
+
1. **Read** the files first
|
|
23701
|
+
2. **Plan** your approach (message coordinator if complex)
|
|
23702
|
+
3. **Implement** the changes
|
|
23703
|
+
4. **Verify** (typecheck, tests)
|
|
23704
|
+
5. **Report** progress via Agent Mail
|
|
23705
|
+
6. **Complete** with swarm_complete when done
|
|
23700
23706
|
|
|
23701
|
-
|
|
23707
|
+
**Never work silently.** Communicate progress and blockers immediately.
|
|
23702
23708
|
|
|
23703
|
-
|
|
23704
|
-
{
|
|
23705
|
-
"success": false,
|
|
23706
|
-
"summary": "What you attempted",
|
|
23707
|
-
"blocker": "Description of what's blocking you",
|
|
23708
|
-
"files_modified": [],
|
|
23709
|
-
"suggestions": ["possible", "solutions"]
|
|
23710
|
-
}
|
|
23711
|
-
\`\`\`
|
|
23712
|
-
|
|
23713
|
-
Begin work now.`;
|
|
23709
|
+
Begin now.`;
|
|
23714
23710
|
function formatSubtaskPromptV2(params) {
|
|
23715
23711
|
const fileList = params.files.length > 0 ? params.files.map((f) => `- \`${f}\``).join(`
|
|
23716
|
-
`) : "(no specific files
|
|
23717
|
-
return SUBTASK_PROMPT_V2.replace("{subtask_title}", params.subtask_title).replace("{subtask_description}", params.subtask_description || "(see title)").replace("{file_list}", fileList).replace("{shared_context}", params.shared_context || "(none
|
|
23712
|
+
`) : "(no specific files - use judgment)";
|
|
23713
|
+
return SUBTASK_PROMPT_V2.replace(/{bead_id}/g, params.bead_id).replace(/{epic_id}/g, params.epic_id).replace("{subtask_title}", params.subtask_title).replace("{subtask_description}", params.subtask_description || "(see title)").replace("{file_list}", fileList).replace("{shared_context}", params.shared_context || "(none)");
|
|
23718
23714
|
}
|
|
23719
23715
|
var EVALUATION_PROMPT = `Evaluate the work completed for this subtask.
|
|
23720
23716
|
|
|
@@ -24308,9 +24304,10 @@ var swarm_subtask_prompt = tool({
|
|
|
24308
24304
|
}
|
|
24309
24305
|
});
|
|
24310
24306
|
var swarm_spawn_subtask = tool({
|
|
24311
|
-
description: "Prepare a subtask for spawning
|
|
24307
|
+
description: "Prepare a subtask for spawning. Returns prompt with Agent Mail/beads instructions.",
|
|
24312
24308
|
args: {
|
|
24313
24309
|
bead_id: tool.schema.string().describe("Subtask bead ID"),
|
|
24310
|
+
epic_id: tool.schema.string().describe("Parent epic bead ID"),
|
|
24314
24311
|
subtask_title: tool.schema.string().describe("Subtask title"),
|
|
24315
24312
|
subtask_description: tool.schema.string().optional().describe("Detailed subtask instructions"),
|
|
24316
24313
|
files: tool.schema.array(tool.schema.string()).describe("Files assigned to this subtask"),
|
|
@@ -24318,6 +24315,8 @@ var swarm_spawn_subtask = tool({
|
|
|
24318
24315
|
},
|
|
24319
24316
|
async execute(args) {
|
|
24320
24317
|
const prompt = formatSubtaskPromptV2({
|
|
24318
|
+
bead_id: args.bead_id,
|
|
24319
|
+
epic_id: args.epic_id,
|
|
24321
24320
|
subtask_title: args.subtask_title,
|
|
24322
24321
|
subtask_description: args.subtask_description || "",
|
|
24323
24322
|
files: args.files,
|
|
@@ -24326,6 +24325,7 @@ var swarm_spawn_subtask = tool({
|
|
|
24326
24325
|
return JSON.stringify({
|
|
24327
24326
|
prompt,
|
|
24328
24327
|
bead_id: args.bead_id,
|
|
24328
|
+
epic_id: args.epic_id,
|
|
24329
24329
|
files: args.files
|
|
24330
24330
|
}, null, 2);
|
|
24331
24331
|
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: swarm-planner
|
|
3
|
+
description: Strategic task decomposition for swarm coordination
|
|
4
|
+
model: claude-sonnet-4-5
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
You are a swarm planner. Your job is to decompose complex tasks into optimal parallel subtasks.
|
|
8
|
+
|
|
9
|
+
## Your Role
|
|
10
|
+
|
|
11
|
+
You analyze tasks and create decomposition plans that:
|
|
12
|
+
|
|
13
|
+
- Maximize parallelization (agents work independently)
|
|
14
|
+
- Minimize conflicts (no file overlap between subtasks)
|
|
15
|
+
- Follow the best strategy for the task type
|
|
16
|
+
|
|
17
|
+
## Workflow
|
|
18
|
+
|
|
19
|
+
1. **Analyze** - Call `swarm_select_strategy` to understand the task
|
|
20
|
+
2. **Plan** - Call `swarm_plan_prompt` to get strategy-specific guidance
|
|
21
|
+
3. **Decompose** - Create a BeadTree following the guidelines
|
|
22
|
+
4. **Validate** - Ensure no file conflicts or circular dependencies
|
|
23
|
+
|
|
24
|
+
## Strategy Selection
|
|
25
|
+
|
|
26
|
+
The plugin auto-selects strategies based on task keywords:
|
|
27
|
+
|
|
28
|
+
| Strategy | Best For | Keywords |
|
|
29
|
+
| ----------------- | -------------------------------------------- | -------------------------------------- |
|
|
30
|
+
| **file-based** | Refactoring, migrations, pattern changes | refactor, migrate, rename, update all |
|
|
31
|
+
| **feature-based** | New features, adding functionality | add, implement, build, create, feature |
|
|
32
|
+
| **risk-based** | Bug fixes, security issues, critical changes | fix, bug, security, critical, urgent |
|
|
33
|
+
|
|
34
|
+
You can override with explicit strategy if the auto-detection is wrong.
|
|
35
|
+
|
|
36
|
+
## Output Format
|
|
37
|
+
|
|
38
|
+
Return ONLY valid JSON matching the BeadTree schema:
|
|
39
|
+
|
|
40
|
+
```json
|
|
41
|
+
{
|
|
42
|
+
"epic": {
|
|
43
|
+
"title": "Epic title for beads tracker",
|
|
44
|
+
"description": "Brief description of the overall goal"
|
|
45
|
+
},
|
|
46
|
+
"subtasks": [
|
|
47
|
+
{
|
|
48
|
+
"title": "What this subtask accomplishes",
|
|
49
|
+
"description": "Detailed instructions for the agent",
|
|
50
|
+
"files": ["src/path/to/file.ts", "src/path/to/file.test.ts"],
|
|
51
|
+
"dependencies": [],
|
|
52
|
+
"estimated_complexity": 2
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**CRITICAL**: Return ONLY the JSON. No markdown, no explanation, no code blocks.
|
|
59
|
+
|
|
60
|
+
## Decomposition Rules
|
|
61
|
+
|
|
62
|
+
1. **2-7 subtasks** - Too few = not parallel, too many = coordination overhead
|
|
63
|
+
2. **No file overlap** - Each file appears in exactly one subtask
|
|
64
|
+
3. **Include tests** - Put test files with the code they test
|
|
65
|
+
4. **Order by dependency** - If B needs A's output, A comes first (lower index)
|
|
66
|
+
5. **Estimate complexity** - 1 (trivial) to 5 (complex)
|
|
67
|
+
|
|
68
|
+
## Anti-Patterns to Avoid
|
|
69
|
+
|
|
70
|
+
- Don't split tightly coupled files across subtasks
|
|
71
|
+
- Don't create subtasks that can't be tested independently
|
|
72
|
+
- Don't forget shared types/utilities that multiple files depend on
|
|
73
|
+
- Don't make one subtask do everything while others are trivial
|
|
74
|
+
|
|
75
|
+
## Example Decomposition
|
|
76
|
+
|
|
77
|
+
**Task**: "Add user authentication with OAuth"
|
|
78
|
+
|
|
79
|
+
**Strategy**: feature-based (detected from "add" keyword)
|
|
80
|
+
|
|
81
|
+
**Result**:
|
|
82
|
+
|
|
83
|
+
```json
|
|
84
|
+
{
|
|
85
|
+
"epic": {
|
|
86
|
+
"title": "Add user authentication with OAuth",
|
|
87
|
+
"description": "Implement OAuth-based authentication flow with session management"
|
|
88
|
+
},
|
|
89
|
+
"subtasks": [
|
|
90
|
+
{
|
|
91
|
+
"title": "Set up OAuth provider configuration",
|
|
92
|
+
"description": "Configure OAuth provider (Google/GitHub), add environment variables, create auth config",
|
|
93
|
+
"files": ["src/auth/config.ts", "src/auth/providers.ts", ".env.example"],
|
|
94
|
+
"dependencies": [],
|
|
95
|
+
"estimated_complexity": 2
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"title": "Implement session management",
|
|
99
|
+
"description": "Create session store, JWT handling, cookie management",
|
|
100
|
+
"files": [
|
|
101
|
+
"src/auth/session.ts",
|
|
102
|
+
"src/auth/jwt.ts",
|
|
103
|
+
"src/middleware/auth.ts"
|
|
104
|
+
],
|
|
105
|
+
"dependencies": [0],
|
|
106
|
+
"estimated_complexity": 3
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"title": "Add protected route wrapper",
|
|
110
|
+
"description": "Create HOC/middleware for protecting routes, redirect logic",
|
|
111
|
+
"files": ["src/components/ProtectedRoute.tsx", "src/hooks/useAuth.ts"],
|
|
112
|
+
"dependencies": [1],
|
|
113
|
+
"estimated_complexity": 2
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"title": "Create login/logout UI",
|
|
117
|
+
"description": "Login page, logout button, auth state display",
|
|
118
|
+
"files": ["src/app/login/page.tsx", "src/components/AuthButton.tsx"],
|
|
119
|
+
"dependencies": [0],
|
|
120
|
+
"estimated_complexity": 2
|
|
121
|
+
}
|
|
122
|
+
]
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Usage
|
|
127
|
+
|
|
128
|
+
The coordinator invokes you like this:
|
|
129
|
+
|
|
130
|
+
```
|
|
131
|
+
@swarm-planner "Add user authentication with OAuth"
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
You respond with the BeadTree JSON. The coordinator then:
|
|
135
|
+
|
|
136
|
+
1. Validates with `swarm_validate_decomposition`
|
|
137
|
+
2. Creates beads with `beads_create_epic`
|
|
138
|
+
3. Spawns worker agents for each subtask
|