opencode-swarm-plugin 0.13.0 → 0.13.2
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 +4 -0
- package/dist/index.js +62 -19
- package/dist/plugin.js +62 -19
- package/examples/commands/swarm.md +50 -22
- package/examples/plugin-wrapper-template.ts +117 -1
- package/examples/skills/swarm-coordination/SKILL.md +109 -56
- package/global-skills/swarm-coordination/SKILL.md +116 -58
- package/package.json +1 -1
- package/src/swarm.integration.test.ts +16 -10
- package/src/swarm.ts +62 -19
package/.beads/issues.jsonl
CHANGED
|
@@ -1428,6 +1428,10 @@
|
|
|
1428
1428
|
{"id":"opencode-swarm-plugin-qgd2n","title":"Update test bead","description":"Updated description","status":"closed","priority":2,"issue_type":"task","created_at":"2025-12-13T11:16:36.35338-08:00","updated_at":"2025-12-13T11:16:40.1931-08:00","closed_at":"2025-12-13T11:16:40.1931-08:00"}
|
|
1429
1429
|
{"id":"opencode-swarm-plugin-qgt38","title":"Document SubtaskSpec estimated_complexity scale","description":"src/schemas/bead.ts:106 - `estimated_complexity: z.number().int().min(1).max(5)` - scale meaning not documented. Add JSDoc: \"/** Complexity estimate (1=trivial, 5=very complex) */\"","status":"open","priority":3,"issue_type":"chore","created_at":"2025-12-10T09:06:10.789511-08:00","updated_at":"2025-12-10T09:06:10.789511-08:00"}
|
|
1430
1430
|
{"id":"opencode-swarm-plugin-qhr0","title":"Cleanup task","description":"","status":"closed","priority":3,"issue_type":"chore","created_at":"2025-12-08T08:22:16.521307-08:00","updated_at":"2025-12-08T08:22:19.112363-08:00","closed_at":"2025-12-08T08:22:19.112363-08:00"}
|
|
1431
|
+
{"id":"opencode-swarm-plugin-qkscs","title":"Production Hardening: Logging, Cleanup, and N+1 Fixes","description":"Fix 3 production readiness gaps in Swarm Mail to improve reliability and debuggability","status":"open","priority":1,"issue_type":"epic","created_at":"2025-12-13T13:27:21.122378-08:00","updated_at":"2025-12-13T13:27:21.122378-08:00"}
|
|
1432
|
+
{"id":"opencode-swarm-plugin-qkscs.1","title":"Fix N+1 queries in store.ts message and reservation handlers","description":"","status":"open","priority":1,"issue_type":"task","created_at":"2025-12-13T13:27:21.179002-08:00","updated_at":"2025-12-13T13:27:21.179002-08:00","dependencies":[{"issue_id":"opencode-swarm-plugin-qkscs.1","depends_on_id":"opencode-swarm-plugin-qkscs","type":"parent-child","created_at":"2025-12-13T13:27:21.180631-08:00","created_by":"daemon"}]}
|
|
1433
|
+
{"id":"opencode-swarm-plugin-qkscs.2","title":"Implement expired reservation cleanup in projections.ts","description":"","status":"open","priority":1,"issue_type":"task","created_at":"2025-12-13T13:27:21.234033-08:00","updated_at":"2025-12-13T13:27:21.234033-08:00","dependencies":[{"issue_id":"opencode-swarm-plugin-qkscs.2","depends_on_id":"opencode-swarm-plugin-qkscs","type":"parent-child","created_at":"2025-12-13T13:27:21.235438-08:00","created_by":"daemon"}]}
|
|
1434
|
+
{"id":"opencode-swarm-plugin-qkscs.3","title":"Add structured logging for critical operations","description":"","status":"open","priority":1,"issue_type":"task","created_at":"2025-12-13T13:27:21.287551-08:00","updated_at":"2025-12-13T13:27:21.287551-08:00","dependencies":[{"issue_id":"opencode-swarm-plugin-qkscs.3","depends_on_id":"opencode-swarm-plugin-qkscs","type":"parent-child","created_at":"2025-12-13T13:27:21.288503-08:00","created_by":"daemon"}]}
|
|
1431
1435
|
{"id":"opencode-swarm-plugin-ql5z","title":"Test bug with priority","description":"This is a critical bug","status":"closed","priority":0,"issue_type":"bug","created_at":"2025-12-08T08:14:28.392972-08:00","updated_at":"2025-12-08T08:14:30.889299-08:00","closed_at":"2025-12-08T08:14:30.889299-08:00"}
|
|
1432
1436
|
{"id":"opencode-swarm-plugin-qlrp","title":"Update test bead","description":"Updated description","status":"closed","priority":2,"issue_type":"task","created_at":"2025-12-08T08:56:55.899992-08:00","updated_at":"2025-12-08T08:56:58.219456-08:00","closed_at":"2025-12-08T08:56:58.219456-08:00"}
|
|
1433
1437
|
{"id":"opencode-swarm-plugin-qlzm","title":"Update test bead","description":"Updated description","status":"closed","priority":2,"issue_type":"task","created_at":"2025-12-08T11:10:25.282262-08:00","updated_at":"2025-12-08T11:10:27.598379-08:00","closed_at":"2025-12-08T11:10:27.598379-08:00"}
|
package/dist/index.js
CHANGED
|
@@ -32968,21 +32968,64 @@ Only modify these files. Need others? Message the coordinator.
|
|
|
32968
32968
|
|
|
32969
32969
|
{error_context}
|
|
32970
32970
|
|
|
32971
|
-
## [
|
|
32972
|
-
|
|
32973
|
-
|
|
32974
|
-
|
|
32975
|
-
|
|
32971
|
+
## [MANDATORY: SWARM MAIL]
|
|
32972
|
+
|
|
32973
|
+
**YOU MUST USE SWARM MAIL FOR ALL COORDINATION.** This is non-negotiable.
|
|
32974
|
+
|
|
32975
|
+
### Initialize FIRST (before any work)
|
|
32976
|
+
\`\`\`
|
|
32977
|
+
swarmmail_init(project_path="$PWD", task_description="{subtask_title}")
|
|
32978
|
+
\`\`\`
|
|
32979
|
+
|
|
32980
|
+
### Reserve Files (if not already reserved by coordinator)
|
|
32981
|
+
\`\`\`
|
|
32982
|
+
swarmmail_reserve(paths=[...files...], reason="{bead_id}: {subtask_title}")
|
|
32983
|
+
\`\`\`
|
|
32984
|
+
|
|
32985
|
+
### Check Inbox Regularly
|
|
32986
|
+
\`\`\`
|
|
32987
|
+
swarmmail_inbox() # Check for coordinator messages
|
|
32988
|
+
swarmmail_read_message(message_id=N) # Read specific message
|
|
32989
|
+
\`\`\`
|
|
32990
|
+
|
|
32991
|
+
### Report Progress (REQUIRED - don't work silently)
|
|
32992
|
+
\`\`\`
|
|
32993
|
+
swarmmail_send(
|
|
32994
|
+
to=["coordinator"],
|
|
32995
|
+
subject="Progress: {bead_id}",
|
|
32996
|
+
body="<what you did, blockers, questions>",
|
|
32997
|
+
thread_id="{epic_id}"
|
|
32998
|
+
)
|
|
32999
|
+
\`\`\`
|
|
33000
|
+
|
|
33001
|
+
### When Blocked
|
|
33002
|
+
\`\`\`
|
|
33003
|
+
swarmmail_send(
|
|
33004
|
+
to=["coordinator"],
|
|
33005
|
+
subject="BLOCKED: {bead_id}",
|
|
33006
|
+
body="<blocker description, what you need>",
|
|
33007
|
+
importance="high",
|
|
33008
|
+
thread_id="{epic_id}"
|
|
33009
|
+
)
|
|
33010
|
+
beads_update(id="{bead_id}", status="blocked")
|
|
33011
|
+
\`\`\`
|
|
33012
|
+
|
|
33013
|
+
### Release Files When Done
|
|
33014
|
+
\`\`\`
|
|
33015
|
+
swarmmail_release() # Or let swarm_complete handle it
|
|
33016
|
+
\`\`\`
|
|
32976
33017
|
|
|
32977
|
-
|
|
32978
|
-
|
|
33018
|
+
## [OTHER TOOLS]
|
|
33019
|
+
### Beads
|
|
33020
|
+
- beads_update(id, status) - Mark blocked if stuck
|
|
33021
|
+
- beads_create(title, type) - Log new bugs found
|
|
32979
33022
|
|
|
32980
33023
|
### Skills (if available)
|
|
32981
|
-
- skills_list
|
|
32982
|
-
- skills_use
|
|
33024
|
+
- skills_list() - Discover available skills
|
|
33025
|
+
- skills_use(name) - Activate skill for specialized guidance
|
|
32983
33026
|
|
|
32984
|
-
### Completion
|
|
32985
|
-
- swarm_complete
|
|
33027
|
+
### Completion (REQUIRED)
|
|
33028
|
+
- swarm_complete(project_key, agent_name, bead_id, summary, files_touched)
|
|
32986
33029
|
|
|
32987
33030
|
## [LEARNING]
|
|
32988
33031
|
As you work, note reusable patterns, best practices, or domain insights:
|
|
@@ -32991,15 +33034,15 @@ As you work, note reusable patterns, best practices, or domain insights:
|
|
|
32991
33034
|
- Good skills have clear "when to use" descriptions with actionable instructions
|
|
32992
33035
|
- Skills make swarms smarter over time
|
|
32993
33036
|
|
|
32994
|
-
## [
|
|
32995
|
-
1.
|
|
32996
|
-
2.
|
|
32997
|
-
3.
|
|
32998
|
-
4.
|
|
32999
|
-
|
|
33000
|
-
|
|
33037
|
+
## [WORKFLOW]
|
|
33038
|
+
1. **swarmmail_init** - Initialize session FIRST
|
|
33039
|
+
2. Read assigned files
|
|
33040
|
+
3. Implement changes
|
|
33041
|
+
4. **swarmmail_send** - Report progress to coordinator
|
|
33042
|
+
5. Verify (typecheck)
|
|
33043
|
+
6. **swarm_complete** - Mark done, release reservations
|
|
33001
33044
|
|
|
33002
|
-
**Never work silently
|
|
33045
|
+
**CRITICAL: Never work silently. Send progress updates via swarmmail_send every significant milestone.**
|
|
33003
33046
|
|
|
33004
33047
|
Begin now.`;
|
|
33005
33048
|
function formatSubtaskPromptV2(params) {
|
package/dist/plugin.js
CHANGED
|
@@ -32831,21 +32831,64 @@ Only modify these files. Need others? Message the coordinator.
|
|
|
32831
32831
|
|
|
32832
32832
|
{error_context}
|
|
32833
32833
|
|
|
32834
|
-
## [
|
|
32835
|
-
|
|
32836
|
-
|
|
32837
|
-
|
|
32838
|
-
|
|
32834
|
+
## [MANDATORY: SWARM MAIL]
|
|
32835
|
+
|
|
32836
|
+
**YOU MUST USE SWARM MAIL FOR ALL COORDINATION.** This is non-negotiable.
|
|
32837
|
+
|
|
32838
|
+
### Initialize FIRST (before any work)
|
|
32839
|
+
\`\`\`
|
|
32840
|
+
swarmmail_init(project_path="$PWD", task_description="{subtask_title}")
|
|
32841
|
+
\`\`\`
|
|
32842
|
+
|
|
32843
|
+
### Reserve Files (if not already reserved by coordinator)
|
|
32844
|
+
\`\`\`
|
|
32845
|
+
swarmmail_reserve(paths=[...files...], reason="{bead_id}: {subtask_title}")
|
|
32846
|
+
\`\`\`
|
|
32847
|
+
|
|
32848
|
+
### Check Inbox Regularly
|
|
32849
|
+
\`\`\`
|
|
32850
|
+
swarmmail_inbox() # Check for coordinator messages
|
|
32851
|
+
swarmmail_read_message(message_id=N) # Read specific message
|
|
32852
|
+
\`\`\`
|
|
32853
|
+
|
|
32854
|
+
### Report Progress (REQUIRED - don't work silently)
|
|
32855
|
+
\`\`\`
|
|
32856
|
+
swarmmail_send(
|
|
32857
|
+
to=["coordinator"],
|
|
32858
|
+
subject="Progress: {bead_id}",
|
|
32859
|
+
body="<what you did, blockers, questions>",
|
|
32860
|
+
thread_id="{epic_id}"
|
|
32861
|
+
)
|
|
32862
|
+
\`\`\`
|
|
32863
|
+
|
|
32864
|
+
### When Blocked
|
|
32865
|
+
\`\`\`
|
|
32866
|
+
swarmmail_send(
|
|
32867
|
+
to=["coordinator"],
|
|
32868
|
+
subject="BLOCKED: {bead_id}",
|
|
32869
|
+
body="<blocker description, what you need>",
|
|
32870
|
+
importance="high",
|
|
32871
|
+
thread_id="{epic_id}"
|
|
32872
|
+
)
|
|
32873
|
+
beads_update(id="{bead_id}", status="blocked")
|
|
32874
|
+
\`\`\`
|
|
32875
|
+
|
|
32876
|
+
### Release Files When Done
|
|
32877
|
+
\`\`\`
|
|
32878
|
+
swarmmail_release() # Or let swarm_complete handle it
|
|
32879
|
+
\`\`\`
|
|
32839
32880
|
|
|
32840
|
-
|
|
32841
|
-
|
|
32881
|
+
## [OTHER TOOLS]
|
|
32882
|
+
### Beads
|
|
32883
|
+
- beads_update(id, status) - Mark blocked if stuck
|
|
32884
|
+
- beads_create(title, type) - Log new bugs found
|
|
32842
32885
|
|
|
32843
32886
|
### Skills (if available)
|
|
32844
|
-
- skills_list
|
|
32845
|
-
- skills_use
|
|
32887
|
+
- skills_list() - Discover available skills
|
|
32888
|
+
- skills_use(name) - Activate skill for specialized guidance
|
|
32846
32889
|
|
|
32847
|
-
### Completion
|
|
32848
|
-
- swarm_complete
|
|
32890
|
+
### Completion (REQUIRED)
|
|
32891
|
+
- swarm_complete(project_key, agent_name, bead_id, summary, files_touched)
|
|
32849
32892
|
|
|
32850
32893
|
## [LEARNING]
|
|
32851
32894
|
As you work, note reusable patterns, best practices, or domain insights:
|
|
@@ -32854,15 +32897,15 @@ As you work, note reusable patterns, best practices, or domain insights:
|
|
|
32854
32897
|
- Good skills have clear "when to use" descriptions with actionable instructions
|
|
32855
32898
|
- Skills make swarms smarter over time
|
|
32856
32899
|
|
|
32857
|
-
## [
|
|
32858
|
-
1.
|
|
32859
|
-
2.
|
|
32860
|
-
3.
|
|
32861
|
-
4.
|
|
32862
|
-
|
|
32863
|
-
|
|
32900
|
+
## [WORKFLOW]
|
|
32901
|
+
1. **swarmmail_init** - Initialize session FIRST
|
|
32902
|
+
2. Read assigned files
|
|
32903
|
+
3. Implement changes
|
|
32904
|
+
4. **swarmmail_send** - Report progress to coordinator
|
|
32905
|
+
5. Verify (typecheck)
|
|
32906
|
+
6. **swarm_complete** - Mark done, release reservations
|
|
32864
32907
|
|
|
32865
|
-
**Never work silently
|
|
32908
|
+
**CRITICAL: Never work silently. Send progress updates via swarmmail_send every significant milestone.**
|
|
32866
32909
|
|
|
32867
32910
|
Begin now.`;
|
|
32868
32911
|
function formatSubtaskPromptV2(params) {
|
|
@@ -15,19 +15,31 @@ $ARGUMENTS
|
|
|
15
15
|
|
|
16
16
|
**Default: Feature branch + PR with context sync.**
|
|
17
17
|
|
|
18
|
+
## MANDATORY: Swarm Mail
|
|
19
|
+
|
|
20
|
+
**ALL coordination MUST use `swarmmail_*` tools.** This is non-negotiable.
|
|
21
|
+
|
|
22
|
+
Swarm Mail is embedded (no external server needed) and provides:
|
|
23
|
+
|
|
24
|
+
- File reservations to prevent conflicts
|
|
25
|
+
- Message passing between agents
|
|
26
|
+
- Thread-based coordination tied to beads
|
|
27
|
+
|
|
18
28
|
## Workflow
|
|
19
29
|
|
|
20
|
-
### 1. Initialize
|
|
30
|
+
### 1. Initialize Swarm Mail (FIRST)
|
|
21
31
|
|
|
22
|
-
```
|
|
23
|
-
|
|
32
|
+
```bash
|
|
33
|
+
swarmmail_init(project_path="$PWD", task_description="Swarm: <task summary>")
|
|
24
34
|
```
|
|
25
35
|
|
|
36
|
+
This registers you as the coordinator agent.
|
|
37
|
+
|
|
26
38
|
### 2. Knowledge Gathering (MANDATORY)
|
|
27
39
|
|
|
28
40
|
**Before decomposing, query ALL knowledge sources:**
|
|
29
41
|
|
|
30
|
-
```
|
|
42
|
+
```bash
|
|
31
43
|
# Past learnings from this project
|
|
32
44
|
semantic-memory_find(query="<task keywords>", limit=5)
|
|
33
45
|
|
|
@@ -43,7 +55,7 @@ skills_list()
|
|
|
43
55
|
|
|
44
56
|
**Load coordinator skills based on task type:**
|
|
45
57
|
|
|
46
|
-
```
|
|
58
|
+
```bash
|
|
47
59
|
# For swarm coordination (ALWAYS load this)
|
|
48
60
|
skills_use(name="swarm-coordination")
|
|
49
61
|
|
|
@@ -75,20 +87,20 @@ git push -u origin HEAD
|
|
|
75
87
|
|
|
76
88
|
Use strategy selection and planning:
|
|
77
89
|
|
|
78
|
-
```
|
|
90
|
+
```bash
|
|
79
91
|
swarm_select_strategy(task="<the task>")
|
|
80
92
|
swarm_plan_prompt(task="<the task>", strategy="<auto or selected>", context="<synthesized knowledge>")
|
|
81
93
|
```
|
|
82
94
|
|
|
83
95
|
Follow the prompt to create a BeadTree, then validate:
|
|
84
96
|
|
|
85
|
-
```
|
|
97
|
+
```bash
|
|
86
98
|
swarm_validate_decomposition(response="<your BeadTree JSON>")
|
|
87
99
|
```
|
|
88
100
|
|
|
89
101
|
### 5. Create Beads
|
|
90
102
|
|
|
91
|
-
```
|
|
103
|
+
```bash
|
|
92
104
|
beads_create_epic(epic_title="<task>", subtasks=[{title, files, priority}...])
|
|
93
105
|
```
|
|
94
106
|
|
|
@@ -99,13 +111,13 @@ Rules:
|
|
|
99
111
|
- 3-7 beads per swarm
|
|
100
112
|
- No file overlap between subtasks
|
|
101
113
|
|
|
102
|
-
### 6. Reserve Files
|
|
114
|
+
### 6. Reserve Files (via Swarm Mail)
|
|
103
115
|
|
|
104
|
-
```
|
|
105
|
-
|
|
116
|
+
```bash
|
|
117
|
+
swarmmail_reserve(paths=[<files>], reason="<bead-id>: <description>", ttl_seconds=3600)
|
|
106
118
|
```
|
|
107
119
|
|
|
108
|
-
No two agents should edit the same file.
|
|
120
|
+
No two agents should edit the same file. Reservations prevent conflicts.
|
|
109
121
|
|
|
110
122
|
### 7. Spawn Agents
|
|
111
123
|
|
|
@@ -113,7 +125,7 @@ No two agents should edit the same file.
|
|
|
113
125
|
|
|
114
126
|
For each subtask:
|
|
115
127
|
|
|
116
|
-
```
|
|
128
|
+
```bash
|
|
117
129
|
swarm_spawn_subtask(
|
|
118
130
|
bead_id="<id>",
|
|
119
131
|
epic_id="<epic>",
|
|
@@ -140,15 +152,16 @@ See full skill list with skills_list().
|
|
|
140
152
|
|
|
141
153
|
Then spawn:
|
|
142
154
|
|
|
143
|
-
```
|
|
155
|
+
```bash
|
|
144
156
|
Task(subagent_type="swarm/worker", description="<bead-title>", prompt="<from swarm_spawn_subtask>")
|
|
145
157
|
```
|
|
146
158
|
|
|
147
159
|
### 8. Monitor (unless --no-sync)
|
|
148
160
|
|
|
149
|
-
```
|
|
161
|
+
```bash
|
|
150
162
|
swarm_status(epic_id="<epic-id>", project_key="$PWD")
|
|
151
|
-
|
|
163
|
+
swarmmail_inbox() # Check for worker messages
|
|
164
|
+
swarmmail_read_message(message_id=N) # Read specific message
|
|
152
165
|
```
|
|
153
166
|
|
|
154
167
|
**Intervention triggers:**
|
|
@@ -160,14 +173,15 @@ agentmail_inbox()
|
|
|
160
173
|
|
|
161
174
|
If incompatibilities spotted, broadcast:
|
|
162
175
|
|
|
163
|
-
```
|
|
164
|
-
|
|
176
|
+
```bash
|
|
177
|
+
swarmmail_send(to=["*"], subject="Coordinator Update", body="<guidance>", importance="high", thread_id="<epic-id>")
|
|
165
178
|
```
|
|
166
179
|
|
|
167
180
|
### 9. Complete
|
|
168
181
|
|
|
169
|
-
```
|
|
182
|
+
```bash
|
|
170
183
|
swarm_complete(project_key="$PWD", agent_name="<your-name>", bead_id="<epic-id>", summary="<done>", files_touched=[...])
|
|
184
|
+
swarmmail_release() # Release any remaining reservations
|
|
171
185
|
beads_sync()
|
|
172
186
|
```
|
|
173
187
|
|
|
@@ -177,6 +191,19 @@ beads_sync()
|
|
|
177
191
|
gh pr create --title "feat: <epic title>" --body "## Summary\n<bullets>\n\n## Beads\n<list>"
|
|
178
192
|
```
|
|
179
193
|
|
|
194
|
+
## Swarm Mail Quick Reference
|
|
195
|
+
|
|
196
|
+
| Tool | Purpose |
|
|
197
|
+
| ------------------------ | ----------------------------------- |
|
|
198
|
+
| `swarmmail_init` | Initialize session (REQUIRED FIRST) |
|
|
199
|
+
| `swarmmail_send` | Send message to agents |
|
|
200
|
+
| `swarmmail_inbox` | Check inbox (max 5, no bodies) |
|
|
201
|
+
| `swarmmail_read_message` | Read specific message body |
|
|
202
|
+
| `swarmmail_reserve` | Reserve files for exclusive editing |
|
|
203
|
+
| `swarmmail_release` | Release file reservations |
|
|
204
|
+
| `swarmmail_ack` | Acknowledge message |
|
|
205
|
+
| `swarmmail_health` | Check database health |
|
|
206
|
+
|
|
180
207
|
## Strategy Reference
|
|
181
208
|
|
|
182
209
|
| Strategy | Best For | Keywords | Recommended Skills |
|
|
@@ -201,13 +228,14 @@ gh pr create --title "feat: <epic title>" --body "## Summary\n<bullets>\n\n## Be
|
|
|
201
228
|
|
|
202
229
|
## Quick Checklist
|
|
203
230
|
|
|
231
|
+
- [ ] **swarmmail_init** called FIRST
|
|
204
232
|
- [ ] Knowledge gathered (semantic-memory, CASS, pdf-brain, skills)
|
|
205
233
|
- [ ] Strategy selected
|
|
206
234
|
- [ ] BeadTree validated (no file conflicts)
|
|
207
235
|
- [ ] Epic + subtasks created
|
|
208
|
-
- [ ] Files reserved
|
|
236
|
+
- [ ] Files reserved via **swarmmail_reserve**
|
|
209
237
|
- [ ] Workers spawned in parallel
|
|
210
|
-
- [ ] Progress monitored
|
|
238
|
+
- [ ] Progress monitored via **swarmmail_inbox**
|
|
211
239
|
- [ ] PR created (or pushed to main)
|
|
212
240
|
|
|
213
|
-
Begin with knowledge gathering now.
|
|
241
|
+
Begin with swarmmail_init and knowledge gathering now.
|
|
@@ -383,6 +383,113 @@ const agentmail_health = tool({
|
|
|
383
383
|
execute: (args, ctx) => execTool("agentmail_health", args, ctx),
|
|
384
384
|
});
|
|
385
385
|
|
|
386
|
+
// =============================================================================
|
|
387
|
+
// Swarm Mail Tools (Embedded - Primary)
|
|
388
|
+
// =============================================================================
|
|
389
|
+
|
|
390
|
+
const swarmmail_init = tool({
|
|
391
|
+
description: "Initialize Swarm Mail session (REQUIRED FIRST)",
|
|
392
|
+
args: {
|
|
393
|
+
project_path: tool.schema.string().describe("Absolute path to the project"),
|
|
394
|
+
agent_name: tool.schema.string().optional().describe("Custom agent name"),
|
|
395
|
+
task_description: tool.schema
|
|
396
|
+
.string()
|
|
397
|
+
.optional()
|
|
398
|
+
.describe("Task description"),
|
|
399
|
+
},
|
|
400
|
+
execute: (args, ctx) => execTool("swarmmail_init", args, ctx),
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
const swarmmail_send = tool({
|
|
404
|
+
description: "Send message to other agents via Swarm Mail",
|
|
405
|
+
args: {
|
|
406
|
+
to: tool.schema
|
|
407
|
+
.array(tool.schema.string())
|
|
408
|
+
.describe("Recipient agent names"),
|
|
409
|
+
subject: tool.schema.string().describe("Message subject"),
|
|
410
|
+
body: tool.schema.string().describe("Message body"),
|
|
411
|
+
thread_id: tool.schema
|
|
412
|
+
.string()
|
|
413
|
+
.optional()
|
|
414
|
+
.describe("Thread ID for grouping"),
|
|
415
|
+
importance: tool.schema
|
|
416
|
+
.enum(["low", "normal", "high", "urgent"])
|
|
417
|
+
.optional()
|
|
418
|
+
.describe("Message importance"),
|
|
419
|
+
ack_required: tool.schema
|
|
420
|
+
.boolean()
|
|
421
|
+
.optional()
|
|
422
|
+
.describe("Require acknowledgment"),
|
|
423
|
+
},
|
|
424
|
+
execute: (args, ctx) => execTool("swarmmail_send", args, ctx),
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
const swarmmail_inbox = tool({
|
|
428
|
+
description: "Fetch inbox (CONTEXT-SAFE: bodies excluded, max 5 messages)",
|
|
429
|
+
args: {
|
|
430
|
+
limit: tool.schema
|
|
431
|
+
.number()
|
|
432
|
+
.max(5)
|
|
433
|
+
.optional()
|
|
434
|
+
.describe("Max messages (max 5)"),
|
|
435
|
+
urgent_only: tool.schema
|
|
436
|
+
.boolean()
|
|
437
|
+
.optional()
|
|
438
|
+
.describe("Only urgent messages"),
|
|
439
|
+
},
|
|
440
|
+
execute: (args, ctx) => execTool("swarmmail_inbox", args, ctx),
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
const swarmmail_read_message = tool({
|
|
444
|
+
description: "Fetch ONE message body by ID",
|
|
445
|
+
args: {
|
|
446
|
+
message_id: tool.schema.number().describe("Message ID"),
|
|
447
|
+
},
|
|
448
|
+
execute: (args, ctx) => execTool("swarmmail_read_message", args, ctx),
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
const swarmmail_reserve = tool({
|
|
452
|
+
description: "Reserve file paths for exclusive editing",
|
|
453
|
+
args: {
|
|
454
|
+
paths: tool.schema
|
|
455
|
+
.array(tool.schema.string())
|
|
456
|
+
.describe("File paths/patterns"),
|
|
457
|
+
ttl_seconds: tool.schema.number().optional().describe("Reservation TTL"),
|
|
458
|
+
exclusive: tool.schema.boolean().optional().describe("Exclusive lock"),
|
|
459
|
+
reason: tool.schema.string().optional().describe("Reservation reason"),
|
|
460
|
+
},
|
|
461
|
+
execute: (args, ctx) => execTool("swarmmail_reserve", args, ctx),
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
const swarmmail_release = tool({
|
|
465
|
+
description: "Release file reservations",
|
|
466
|
+
args: {
|
|
467
|
+
paths: tool.schema
|
|
468
|
+
.array(tool.schema.string())
|
|
469
|
+
.optional()
|
|
470
|
+
.describe("Paths to release"),
|
|
471
|
+
reservation_ids: tool.schema
|
|
472
|
+
.array(tool.schema.number())
|
|
473
|
+
.optional()
|
|
474
|
+
.describe("Reservation IDs"),
|
|
475
|
+
},
|
|
476
|
+
execute: (args, ctx) => execTool("swarmmail_release", args, ctx),
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
const swarmmail_ack = tool({
|
|
480
|
+
description: "Acknowledge a message",
|
|
481
|
+
args: {
|
|
482
|
+
message_id: tool.schema.number().describe("Message ID"),
|
|
483
|
+
},
|
|
484
|
+
execute: (args, ctx) => execTool("swarmmail_ack", args, ctx),
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
const swarmmail_health = tool({
|
|
488
|
+
description: "Check Swarm Mail database health",
|
|
489
|
+
args: {},
|
|
490
|
+
execute: (args, ctx) => execTool("swarmmail_health", args, ctx),
|
|
491
|
+
});
|
|
492
|
+
|
|
386
493
|
// =============================================================================
|
|
387
494
|
// Structured Tools
|
|
388
495
|
// =============================================================================
|
|
@@ -794,7 +901,7 @@ export const SwarmPlugin: Plugin = async (
|
|
|
794
901
|
beads_ready,
|
|
795
902
|
beads_sync,
|
|
796
903
|
beads_link_thread,
|
|
797
|
-
// Agent Mail
|
|
904
|
+
// Agent Mail (Legacy MCP)
|
|
798
905
|
agentmail_init,
|
|
799
906
|
agentmail_send,
|
|
800
907
|
agentmail_inbox,
|
|
@@ -805,6 +912,15 @@ export const SwarmPlugin: Plugin = async (
|
|
|
805
912
|
agentmail_ack,
|
|
806
913
|
agentmail_search,
|
|
807
914
|
agentmail_health,
|
|
915
|
+
// Swarm Mail (Embedded - Primary)
|
|
916
|
+
swarmmail_init,
|
|
917
|
+
swarmmail_send,
|
|
918
|
+
swarmmail_inbox,
|
|
919
|
+
swarmmail_read_message,
|
|
920
|
+
swarmmail_reserve,
|
|
921
|
+
swarmmail_release,
|
|
922
|
+
swarmmail_ack,
|
|
923
|
+
swarmmail_health,
|
|
808
924
|
// Structured
|
|
809
925
|
structured_extract_json,
|
|
810
926
|
structured_validate,
|
|
@@ -8,8 +8,12 @@ tags:
|
|
|
8
8
|
tools:
|
|
9
9
|
- swarm_decompose
|
|
10
10
|
- swarm_complete
|
|
11
|
-
-
|
|
12
|
-
-
|
|
11
|
+
- swarmmail_init
|
|
12
|
+
- swarmmail_send
|
|
13
|
+
- swarmmail_inbox
|
|
14
|
+
- swarmmail_read_message
|
|
15
|
+
- swarmmail_reserve
|
|
16
|
+
- swarmmail_release
|
|
13
17
|
- skills_use
|
|
14
18
|
- skills_list
|
|
15
19
|
related_skills:
|
|
@@ -24,6 +28,16 @@ This skill provides guidance for effective multi-agent coordination in OpenCode
|
|
|
24
28
|
|
|
25
29
|
**IMPORTANT:** This skill references global skills in `global-skills/`. Workers should load domain-specific skills based on their subtask type.
|
|
26
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
|
+
|
|
27
41
|
## When to Use Swarm Coordination
|
|
28
42
|
|
|
29
43
|
Use swarm coordination when:
|
|
@@ -54,7 +68,7 @@ Before decomposing, understand:
|
|
|
54
68
|
|
|
55
69
|
**Parallel Strategy** - For independent subtasks:
|
|
56
70
|
|
|
57
|
-
```
|
|
71
|
+
```text
|
|
58
72
|
Parent Task: "Add user authentication"
|
|
59
73
|
├── Subtask 1: "Create auth API endpoints" (backend)
|
|
60
74
|
├── Subtask 2: "Build login/signup forms" (frontend)
|
|
@@ -64,7 +78,7 @@ Parent Task: "Add user authentication"
|
|
|
64
78
|
|
|
65
79
|
**Sequential Strategy** - When order matters:
|
|
66
80
|
|
|
67
|
-
```
|
|
81
|
+
```text
|
|
68
82
|
Parent Task: "Migrate database schema"
|
|
69
83
|
├── Step 1: "Create migration files"
|
|
70
84
|
├── Step 2: "Update model definitions"
|
|
@@ -74,7 +88,7 @@ Parent Task: "Migrate database schema"
|
|
|
74
88
|
|
|
75
89
|
**Hybrid Strategy** - Mixed dependencies:
|
|
76
90
|
|
|
77
|
-
```
|
|
91
|
+
```text
|
|
78
92
|
Parent Task: "Add feature X"
|
|
79
93
|
├── Phase 1 (parallel):
|
|
80
94
|
│ ├── Subtask A: "Design API"
|
|
@@ -90,40 +104,87 @@ Parent Task: "Add feature X"
|
|
|
90
104
|
|
|
91
105
|
When multiple agents work on the same codebase:
|
|
92
106
|
|
|
93
|
-
1. **
|
|
94
|
-
2. **
|
|
95
|
-
3. **
|
|
96
|
-
4. **
|
|
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
|
+
```
|
|
97
132
|
|
|
98
133
|
## Communication Patterns
|
|
99
134
|
|
|
100
135
|
### Broadcasting Updates
|
|
101
136
|
|
|
102
|
-
```
|
|
103
|
-
|
|
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
|
+
});
|
|
104
144
|
```
|
|
105
145
|
|
|
106
146
|
### Direct Coordination
|
|
107
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
|
+
});
|
|
108
155
|
```
|
|
109
|
-
agentmail_send(recipients: ["frontend-agent"], message: "Auth API is at /api/auth/*, here's the spec...")
|
|
110
|
-
```
|
|
111
156
|
|
|
112
|
-
###
|
|
157
|
+
### Checking for Messages
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
// Check inbox (max 5, no bodies for context safety)
|
|
161
|
+
const inbox = await swarmmail_inbox();
|
|
113
162
|
|
|
163
|
+
// Read specific message body
|
|
164
|
+
const message = await swarmmail_read_message({ message_id: N });
|
|
114
165
|
```
|
|
115
|
-
|
|
116
|
-
|
|
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
|
+
});
|
|
117
177
|
```
|
|
118
178
|
|
|
119
179
|
## Best Practices
|
|
120
180
|
|
|
121
|
-
1. **
|
|
122
|
-
2. **
|
|
123
|
-
3. **
|
|
124
|
-
4. **
|
|
125
|
-
5. **
|
|
126
|
-
6. **
|
|
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:
|
|
127
188
|
- Testing work → `skills_use(name="testing-patterns")`
|
|
128
189
|
- Architecture decisions → `skills_use(name="system-design")`
|
|
129
190
|
- CLI development → `skills_use(name="cli-builder")`
|
|
@@ -136,7 +197,7 @@ agentmail_receive(wait: true, filter: "api-complete")
|
|
|
136
197
|
```yaml
|
|
137
198
|
decomposition:
|
|
138
199
|
strategy: hybrid
|
|
139
|
-
skills: [system-design, swarm-coordination]
|
|
200
|
+
skills: [system-design, swarm-coordination]
|
|
140
201
|
phases:
|
|
141
202
|
- name: design
|
|
142
203
|
parallel: true
|
|
@@ -157,7 +218,7 @@ decomposition:
|
|
|
157
218
|
```yaml
|
|
158
219
|
decomposition:
|
|
159
220
|
strategy: sequential
|
|
160
|
-
skills: [testing-patterns]
|
|
221
|
+
skills: [testing-patterns]
|
|
161
222
|
subtasks:
|
|
162
223
|
- reproduce-bug
|
|
163
224
|
- identify-root-cause
|
|
@@ -171,7 +232,7 @@ decomposition:
|
|
|
171
232
|
```yaml
|
|
172
233
|
decomposition:
|
|
173
234
|
strategy: parallel
|
|
174
|
-
skills: [testing-patterns, system-design]
|
|
235
|
+
skills: [testing-patterns, system-design]
|
|
175
236
|
subtasks:
|
|
176
237
|
- refactor-module-a
|
|
177
238
|
- refactor-module-b
|
|
@@ -184,17 +245,20 @@ decomposition:
|
|
|
184
245
|
|
|
185
246
|
**For Coordinators:**
|
|
186
247
|
|
|
187
|
-
1.
|
|
188
|
-
2.
|
|
189
|
-
3.
|
|
190
|
-
4.
|
|
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
|
|
191
253
|
|
|
192
254
|
**For Workers:**
|
|
193
255
|
|
|
194
|
-
1.
|
|
195
|
-
2.
|
|
196
|
-
3.
|
|
197
|
-
4.
|
|
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`
|
|
198
262
|
|
|
199
263
|
**Example shared_context:**
|
|
200
264
|
|
|
@@ -214,26 +278,15 @@ Project learnings: [semantic-memory results]
|
|
|
214
278
|
[Domain knowledge from coordinator]
|
|
215
279
|
```
|
|
216
280
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
### Refactoring
|
|
230
|
-
|
|
231
|
-
```yaml
|
|
232
|
-
decomposition:
|
|
233
|
-
strategy: parallel
|
|
234
|
-
subtasks:
|
|
235
|
-
- refactor-module-a
|
|
236
|
-
- refactor-module-b
|
|
237
|
-
- update-imports
|
|
238
|
-
- run-full-test-suite
|
|
239
|
-
```
|
|
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
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
211
|
+
Workers communicate via Swarm Mail with epic ID as thread:
|
|
180
212
|
|
|
181
213
|
```typescript
|
|
182
214
|
// Progress update
|
|
183
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
//
|
|
286
|
-
|
|
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.
|
package/package.json
CHANGED
|
@@ -1315,24 +1315,29 @@ describe("Swarm Prompt V2 (with Agent Mail/Beads)", () => {
|
|
|
1315
1315
|
describe("SUBTASK_PROMPT_V2", () => {
|
|
1316
1316
|
it("contains expected sections", () => {
|
|
1317
1317
|
// Check all main sections are present in the template
|
|
1318
|
-
expect(SUBTASK_PROMPT_V2).toContain("
|
|
1318
|
+
expect(SUBTASK_PROMPT_V2).toContain("[TASK]");
|
|
1319
1319
|
expect(SUBTASK_PROMPT_V2).toContain("{subtask_title}");
|
|
1320
1320
|
expect(SUBTASK_PROMPT_V2).toContain("{subtask_description}");
|
|
1321
1321
|
|
|
1322
|
-
expect(SUBTASK_PROMPT_V2).toContain("
|
|
1322
|
+
expect(SUBTASK_PROMPT_V2).toContain("[FILES]");
|
|
1323
1323
|
expect(SUBTASK_PROMPT_V2).toContain("{file_list}");
|
|
1324
1324
|
|
|
1325
|
-
expect(SUBTASK_PROMPT_V2).toContain("
|
|
1325
|
+
expect(SUBTASK_PROMPT_V2).toContain("[CONTEXT]");
|
|
1326
1326
|
expect(SUBTASK_PROMPT_V2).toContain("{shared_context}");
|
|
1327
1327
|
|
|
1328
|
-
expect(SUBTASK_PROMPT_V2).toContain("
|
|
1328
|
+
expect(SUBTASK_PROMPT_V2).toContain("[WORKFLOW]");
|
|
1329
1329
|
});
|
|
1330
1330
|
|
|
1331
|
-
it("DOES contain
|
|
1332
|
-
// V2 prompt tells agents to USE
|
|
1333
|
-
expect(SUBTASK_PROMPT_V2).toContain("
|
|
1334
|
-
expect(SUBTASK_PROMPT_V2).toContain("
|
|
1331
|
+
it("DOES contain Swarm Mail instructions (MANDATORY)", () => {
|
|
1332
|
+
// V2 prompt tells agents to USE Swarm Mail - this is non-negotiable
|
|
1333
|
+
expect(SUBTASK_PROMPT_V2).toContain("SWARM MAIL");
|
|
1334
|
+
expect(SUBTASK_PROMPT_V2).toContain("swarmmail_init");
|
|
1335
|
+
expect(SUBTASK_PROMPT_V2).toContain("swarmmail_send");
|
|
1336
|
+
expect(SUBTASK_PROMPT_V2).toContain("swarmmail_inbox");
|
|
1337
|
+
expect(SUBTASK_PROMPT_V2).toContain("swarmmail_reserve");
|
|
1338
|
+
expect(SUBTASK_PROMPT_V2).toContain("swarmmail_release");
|
|
1335
1339
|
expect(SUBTASK_PROMPT_V2).toContain("thread_id");
|
|
1340
|
+
expect(SUBTASK_PROMPT_V2).toContain("non-negotiable");
|
|
1336
1341
|
});
|
|
1337
1342
|
|
|
1338
1343
|
it("DOES contain beads instructions", () => {
|
|
@@ -1344,10 +1349,11 @@ describe("Swarm Prompt V2 (with Agent Mail/Beads)", () => {
|
|
|
1344
1349
|
expect(SUBTASK_PROMPT_V2).toContain("swarm_complete");
|
|
1345
1350
|
});
|
|
1346
1351
|
|
|
1347
|
-
it("instructs agents to communicate", () => {
|
|
1352
|
+
it("instructs agents to communicate via swarmmail", () => {
|
|
1348
1353
|
expect(SUBTASK_PROMPT_V2).toContain("Never work silently");
|
|
1349
|
-
expect(SUBTASK_PROMPT_V2).toContain("
|
|
1354
|
+
expect(SUBTASK_PROMPT_V2).toContain("progress");
|
|
1350
1355
|
expect(SUBTASK_PROMPT_V2).toContain("coordinator");
|
|
1356
|
+
expect(SUBTASK_PROMPT_V2).toContain("CRITICAL");
|
|
1351
1357
|
});
|
|
1352
1358
|
});
|
|
1353
1359
|
});
|
package/src/swarm.ts
CHANGED
|
@@ -709,21 +709,64 @@ Only modify these files. Need others? Message the coordinator.
|
|
|
709
709
|
|
|
710
710
|
{error_context}
|
|
711
711
|
|
|
712
|
-
## [
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
712
|
+
## [MANDATORY: SWARM MAIL]
|
|
713
|
+
|
|
714
|
+
**YOU MUST USE SWARM MAIL FOR ALL COORDINATION.** This is non-negotiable.
|
|
715
|
+
|
|
716
|
+
### Initialize FIRST (before any work)
|
|
717
|
+
\`\`\`
|
|
718
|
+
swarmmail_init(project_path="$PWD", task_description="{subtask_title}")
|
|
719
|
+
\`\`\`
|
|
720
|
+
|
|
721
|
+
### Reserve Files (if not already reserved by coordinator)
|
|
722
|
+
\`\`\`
|
|
723
|
+
swarmmail_reserve(paths=[...files...], reason="{bead_id}: {subtask_title}")
|
|
724
|
+
\`\`\`
|
|
725
|
+
|
|
726
|
+
### Check Inbox Regularly
|
|
727
|
+
\`\`\`
|
|
728
|
+
swarmmail_inbox() # Check for coordinator messages
|
|
729
|
+
swarmmail_read_message(message_id=N) # Read specific message
|
|
730
|
+
\`\`\`
|
|
731
|
+
|
|
732
|
+
### Report Progress (REQUIRED - don't work silently)
|
|
733
|
+
\`\`\`
|
|
734
|
+
swarmmail_send(
|
|
735
|
+
to=["coordinator"],
|
|
736
|
+
subject="Progress: {bead_id}",
|
|
737
|
+
body="<what you did, blockers, questions>",
|
|
738
|
+
thread_id="{epic_id}"
|
|
739
|
+
)
|
|
740
|
+
\`\`\`
|
|
741
|
+
|
|
742
|
+
### When Blocked
|
|
743
|
+
\`\`\`
|
|
744
|
+
swarmmail_send(
|
|
745
|
+
to=["coordinator"],
|
|
746
|
+
subject="BLOCKED: {bead_id}",
|
|
747
|
+
body="<blocker description, what you need>",
|
|
748
|
+
importance="high",
|
|
749
|
+
thread_id="{epic_id}"
|
|
750
|
+
)
|
|
751
|
+
beads_update(id="{bead_id}", status="blocked")
|
|
752
|
+
\`\`\`
|
|
753
|
+
|
|
754
|
+
### Release Files When Done
|
|
755
|
+
\`\`\`
|
|
756
|
+
swarmmail_release() # Or let swarm_complete handle it
|
|
757
|
+
\`\`\`
|
|
717
758
|
|
|
718
|
-
|
|
719
|
-
|
|
759
|
+
## [OTHER TOOLS]
|
|
760
|
+
### Beads
|
|
761
|
+
- beads_update(id, status) - Mark blocked if stuck
|
|
762
|
+
- beads_create(title, type) - Log new bugs found
|
|
720
763
|
|
|
721
764
|
### Skills (if available)
|
|
722
|
-
- skills_list
|
|
723
|
-
- skills_use
|
|
765
|
+
- skills_list() - Discover available skills
|
|
766
|
+
- skills_use(name) - Activate skill for specialized guidance
|
|
724
767
|
|
|
725
|
-
### Completion
|
|
726
|
-
- swarm_complete
|
|
768
|
+
### Completion (REQUIRED)
|
|
769
|
+
- swarm_complete(project_key, agent_name, bead_id, summary, files_touched)
|
|
727
770
|
|
|
728
771
|
## [LEARNING]
|
|
729
772
|
As you work, note reusable patterns, best practices, or domain insights:
|
|
@@ -732,15 +775,15 @@ As you work, note reusable patterns, best practices, or domain insights:
|
|
|
732
775
|
- Good skills have clear "when to use" descriptions with actionable instructions
|
|
733
776
|
- Skills make swarms smarter over time
|
|
734
777
|
|
|
735
|
-
## [
|
|
736
|
-
1.
|
|
737
|
-
2.
|
|
738
|
-
3.
|
|
739
|
-
4.
|
|
740
|
-
|
|
741
|
-
|
|
778
|
+
## [WORKFLOW]
|
|
779
|
+
1. **swarmmail_init** - Initialize session FIRST
|
|
780
|
+
2. Read assigned files
|
|
781
|
+
3. Implement changes
|
|
782
|
+
4. **swarmmail_send** - Report progress to coordinator
|
|
783
|
+
5. Verify (typecheck)
|
|
784
|
+
6. **swarm_complete** - Mark done, release reservations
|
|
742
785
|
|
|
743
|
-
**Never work silently
|
|
786
|
+
**CRITICAL: Never work silently. Send progress updates via swarmmail_send every significant milestone.**
|
|
744
787
|
|
|
745
788
|
Begin now.`;
|
|
746
789
|
|