opencode-swarm-plugin 0.6.3 → 0.9.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 +7 -80
- package/README.md +170 -606
- package/bin/swarm.ts +620 -0
- package/bun.lock +7 -0
- package/package.json +3 -2
- package/src/agent-mail.ts +401 -44
- package/scripts/setup.ts +0 -371
package/README.md
CHANGED
|
@@ -3,688 +3,252 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/opencode-swarm-plugin)
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
|
|
6
|
-
Multi-agent swarm coordination for [OpenCode](https://opencode.ai)
|
|
6
|
+
Multi-agent swarm coordination for [OpenCode](https://opencode.ai). Break complex tasks into parallel subtasks, spawn agents, coordinate via messaging. The plugin learns from outcomes to improve future decompositions.
|
|
7
7
|
|
|
8
|
-
##
|
|
9
|
-
|
|
10
|
-
This plugin provides intelligent, self-improving tools for multi-agent workflows in OpenCode:
|
|
11
|
-
|
|
12
|
-
- **Type-safe beads operations** - Zod-validated wrappers around the `bd` CLI with proper error handling
|
|
13
|
-
- **Agent Mail integration** - File reservations, async messaging, and thread coordination between agents
|
|
14
|
-
- **Structured outputs** - Reliable JSON responses with schema validation and retry support
|
|
15
|
-
- **Swarm primitives** - Task decomposition, status tracking, and parallel agent coordination
|
|
16
|
-
- **Learning from outcomes** - Confidence decay, implicit feedback scoring, and pattern maturity tracking
|
|
17
|
-
- **Anti-pattern detection** - Automatically learns what decomposition strategies fail and avoids them
|
|
18
|
-
- **Pre-completion validation** - UBS bug scanning before marking tasks complete
|
|
19
|
-
- **History-informed decomposition** - Queries CASS for similar past tasks to inform strategy
|
|
20
|
-
- **Graceful degradation** - Works with whatever tools are available, degrades features when tools missing
|
|
21
|
-
- **Swarm discipline** - Enforces beads tracking, aggressive planning, and agent communication
|
|
22
|
-
|
|
23
|
-
## Quick Start
|
|
24
|
-
|
|
25
|
-
### 1. Install Dependencies
|
|
8
|
+
## Install
|
|
26
9
|
|
|
27
10
|
```bash
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
11
|
+
npm install -g opencode-swarm-plugin
|
|
12
|
+
swarm setup
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
That's it. The setup wizard handles everything:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
┌ opencode-swarm-plugin v0.9.0
|
|
19
|
+
│
|
|
20
|
+
◇ Checking dependencies...
|
|
21
|
+
│
|
|
22
|
+
◆ OpenCode
|
|
23
|
+
◆ Beads
|
|
24
|
+
◆ Go
|
|
25
|
+
▲ Agent Mail (optional)
|
|
26
|
+
▲ Redis (optional)
|
|
27
|
+
│
|
|
28
|
+
◆ Install optional dependencies?
|
|
29
|
+
│ ◻ Agent Mail - Multi-agent coordination
|
|
30
|
+
│ ◻ Redis - Rate limiting
|
|
31
|
+
│
|
|
32
|
+
◇ Setting up OpenCode integration...
|
|
33
|
+
│
|
|
34
|
+
◆ Plugin: ~/.config/opencode/plugins/swarm.ts
|
|
35
|
+
◆ Command: ~/.config/opencode/commands/swarm.md
|
|
36
|
+
◆ Agent: ~/.config/opencode/agents/swarm-planner.md
|
|
37
|
+
│
|
|
38
|
+
└ Setup complete!
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Then in your project:
|
|
36
42
|
|
|
37
43
|
```bash
|
|
38
|
-
|
|
44
|
+
cd your-project
|
|
45
|
+
swarm init
|
|
39
46
|
```
|
|
40
47
|
|
|
41
|
-
|
|
48
|
+
## CLI
|
|
42
49
|
|
|
43
|
-
Create a file at `~/.config/opencode/plugins/swarm.ts`:
|
|
44
|
-
|
|
45
|
-
```ts
|
|
46
|
-
import { SwarmPlugin } from "opencode-swarm-plugin";
|
|
47
|
-
export default SwarmPlugin;
|
|
48
50
|
```
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
```bash
|
|
55
|
-
# Create directories
|
|
56
|
-
mkdir -p ~/.config/opencode/commands ~/.config/opencode/agents
|
|
57
|
-
|
|
58
|
-
# Copy /swarm command
|
|
59
|
-
cp node_modules/opencode-swarm-plugin/examples/commands/swarm.md ~/.config/opencode/commands/
|
|
60
|
-
|
|
61
|
-
# Copy @swarm-planner agent
|
|
62
|
-
cp node_modules/opencode-swarm-plugin/examples/agents/swarm-planner.md ~/.config/opencode/agents/
|
|
51
|
+
swarm setup Interactive installer - checks and installs all dependencies
|
|
52
|
+
swarm doctor Health check - shows status of all dependencies
|
|
53
|
+
swarm init Initialize beads in current project
|
|
54
|
+
swarm version Show version
|
|
55
|
+
swarm help Show help
|
|
63
56
|
```
|
|
64
57
|
|
|
65
|
-
###
|
|
58
|
+
### swarm doctor
|
|
66
59
|
|
|
67
|
-
```bash
|
|
68
|
-
cd your-project
|
|
69
|
-
bd init
|
|
70
60
|
```
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
61
|
+
┌ swarm doctor v0.9.0
|
|
62
|
+
│
|
|
63
|
+
◇ Required dependencies:
|
|
64
|
+
│
|
|
65
|
+
◆ OpenCode v1.0.134
|
|
66
|
+
◆ Beads v0.29.0
|
|
67
|
+
│
|
|
68
|
+
◇ Optional dependencies:
|
|
69
|
+
│
|
|
70
|
+
◆ Go v1.25.2 - Required for Agent Mail
|
|
71
|
+
▲ Agent Mail - not found
|
|
72
|
+
◆ Redis - Rate limiting
|
|
73
|
+
│
|
|
74
|
+
└ All required dependencies installed. 1 optional missing.
|
|
79
75
|
```
|
|
80
76
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
### Required
|
|
84
|
-
|
|
85
|
-
| Dependency | Purpose | Install |
|
|
86
|
-
| ----------------------------------------------- | ------------------------- | --------------------------------- |
|
|
87
|
-
| [OpenCode](https://opencode.ai) | Plugin host | `brew install sst/tap/opencode` |
|
|
88
|
-
| [Beads CLI](https://github.com/joelhooks/beads) | Git-backed issue tracking | `npm install -g @joelhooks/beads` |
|
|
89
|
-
|
|
90
|
-
### Optional (Graceful Degradation)
|
|
91
|
-
|
|
92
|
-
The plugin works without these, but with reduced functionality:
|
|
93
|
-
|
|
94
|
-
| Dependency | Purpose | Without It |
|
|
95
|
-
| ----------------------------------------------------- | ------------------------ | ---------------------------------------- |
|
|
96
|
-
| [Agent Mail](https://github.com/joelhooks/agent-mail) | Multi-agent coordination | No file reservations, no agent messaging |
|
|
97
|
-
| [Redis](https://redis.io) | Rate limiting | Falls back to SQLite |
|
|
98
|
-
| [CASS](https://github.com/Dicklesworthstone/cass) | Historical context | No "similar past tasks" in decomposition |
|
|
99
|
-
| [UBS](https://github.com/joelhooks/ubs) | Bug scanning | No pre-completion validation |
|
|
100
|
-
|
|
101
|
-
### Verify Installation
|
|
77
|
+
### swarm init
|
|
102
78
|
|
|
103
|
-
```bash
|
|
104
|
-
# Check OpenCode
|
|
105
|
-
opencode --version
|
|
106
|
-
|
|
107
|
-
# Check Beads
|
|
108
|
-
bd --version
|
|
109
|
-
|
|
110
|
-
# Check Agent Mail (if using multi-agent)
|
|
111
|
-
curl http://127.0.0.1:8765/health/liveness
|
|
112
|
-
|
|
113
|
-
# Check Redis (optional)
|
|
114
|
-
redis-cli ping
|
|
115
79
|
```
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
80
|
+
┌ swarm init v0.9.0
|
|
81
|
+
│
|
|
82
|
+
◇ Initializing beads...
|
|
83
|
+
◆ Created .beads/ directory
|
|
84
|
+
│
|
|
85
|
+
◆ Create your first bead?
|
|
86
|
+
│ ● Yes / ○ No
|
|
87
|
+
│
|
|
88
|
+
◇ Bead title: Implement user authentication
|
|
89
|
+
◇ Type: Feature
|
|
90
|
+
│
|
|
91
|
+
└ Project initialized!
|
|
127
92
|
```
|
|
128
93
|
|
|
129
|
-
|
|
94
|
+
## Usage
|
|
130
95
|
|
|
131
|
-
|
|
96
|
+
In OpenCode:
|
|
132
97
|
|
|
133
|
-
```ts
|
|
134
|
-
import { SwarmPlugin } from "opencode-swarm-plugin";
|
|
135
|
-
export default SwarmPlugin;
|
|
136
98
|
```
|
|
137
|
-
|
|
138
|
-
OpenCode runs on Bun and loads TypeScript directly - no build step needed.
|
|
139
|
-
|
|
140
|
-
### Plugin Setup (Direct Copy)
|
|
141
|
-
|
|
142
|
-
Alternatively, copy the pre-built bundle:
|
|
143
|
-
|
|
144
|
-
```bash
|
|
145
|
-
mkdir -p ~/.config/opencode/plugins
|
|
146
|
-
cp node_modules/opencode-swarm-plugin/dist/plugin.js ~/.config/opencode/plugins/swarm.js
|
|
99
|
+
/swarm "Add user authentication with OAuth"
|
|
147
100
|
```
|
|
148
101
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
Copy the `/swarm` command and `@swarm-planner` agent:
|
|
102
|
+
Or invoke the planner directly:
|
|
152
103
|
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
mkdir -p ~/.config/opencode/commands
|
|
156
|
-
cp node_modules/opencode-swarm-plugin/examples/commands/swarm.md ~/.config/opencode/commands/
|
|
157
|
-
|
|
158
|
-
# Agent
|
|
159
|
-
mkdir -p ~/.config/opencode/agents
|
|
160
|
-
cp node_modules/opencode-swarm-plugin/examples/agents/swarm-planner.md ~/.config/opencode/agents/
|
|
104
|
+
```
|
|
105
|
+
@swarm-planner "Refactor all components to use hooks"
|
|
161
106
|
```
|
|
162
107
|
|
|
163
|
-
|
|
164
|
-
>
|
|
165
|
-
> - `dist/index.js` - Full library exports (schemas, errors, utilities, learning modules)
|
|
166
|
-
> - `dist/plugin.js` - Plugin entry point that only exports the `plugin` function for OpenCode
|
|
167
|
-
|
|
168
|
-
## Tools Reference
|
|
169
|
-
|
|
170
|
-
### Beads Tools
|
|
171
|
-
|
|
172
|
-
| Tool | Description |
|
|
173
|
-
| ------------------- | ------------------------------------------------------------------- |
|
|
174
|
-
| `beads_create` | Create a new bead with type-safe validation |
|
|
175
|
-
| `beads_create_epic` | Create epic with subtasks in one atomic operation |
|
|
176
|
-
| `beads_query` | Query beads with filters (replaces `bd list`, `bd ready`, `bd wip`) |
|
|
177
|
-
| `beads_update` | Update bead status/description/priority |
|
|
178
|
-
| `beads_close` | Close a bead with reason |
|
|
179
|
-
| `beads_start` | Mark bead as in-progress (shortcut) |
|
|
180
|
-
| `beads_ready` | Get next ready bead (unblocked, highest priority) |
|
|
181
|
-
| `beads_sync` | Sync beads to git and push (MANDATORY at session end) |
|
|
182
|
-
| `beads_link_thread` | Link bead to Agent Mail thread |
|
|
183
|
-
|
|
184
|
-
### Agent Mail Tools
|
|
185
|
-
|
|
186
|
-
| Tool | Description |
|
|
187
|
-
| ---------------------------- | ---------------------------------------------------- |
|
|
188
|
-
| `agentmail_init` | Initialize session (ensure project + register agent) |
|
|
189
|
-
| `agentmail_send` | Send message to other agents |
|
|
190
|
-
| `agentmail_inbox` | Fetch inbox (CONTEXT-SAFE: bodies excluded, limit 5) |
|
|
191
|
-
| `agentmail_read_message` | Fetch ONE message body by ID |
|
|
192
|
-
| `agentmail_summarize_thread` | Summarize thread (PREFERRED over fetching all) |
|
|
193
|
-
| `agentmail_reserve` | Reserve file paths for exclusive editing |
|
|
194
|
-
| `agentmail_release` | Release file reservations |
|
|
195
|
-
| `agentmail_ack` | Acknowledge a message |
|
|
196
|
-
| `agentmail_search` | Search messages (FTS5 syntax) |
|
|
197
|
-
| `agentmail_health` | Check if Agent Mail server is running |
|
|
198
|
-
|
|
199
|
-
## Rate Limiting
|
|
200
|
-
|
|
201
|
-
Client-side, per-agent rate limits prevent abuse and ensure fair resource usage across agents. Uses Redis as primary store (`localhost:6379`) with automatic SQLite fallback (`~/.config/opencode/rate-limits.db`).
|
|
202
|
-
|
|
203
|
-
### Default Limits
|
|
204
|
-
|
|
205
|
-
| Endpoint | Per Minute | Per Hour |
|
|
206
|
-
| ------------------ | ---------- | -------- |
|
|
207
|
-
| `send` | 20 | 200 |
|
|
208
|
-
| `reserve` | 10 | 100 |
|
|
209
|
-
| `release` | 10 | 100 |
|
|
210
|
-
| `ack` | 20 | 200 |
|
|
211
|
-
| `inbox` | 60 | 600 |
|
|
212
|
-
| `read_message` | 60 | 600 |
|
|
213
|
-
| `summarize_thread` | 30 | 300 |
|
|
214
|
-
| `search` | 30 | 300 |
|
|
215
|
-
|
|
216
|
-
### Configuration
|
|
108
|
+
## Dependencies
|
|
217
109
|
|
|
218
|
-
|
|
|
219
|
-
|
|
|
220
|
-
|
|
|
221
|
-
|
|
|
222
|
-
|
|
|
223
|
-
|
|
|
110
|
+
| Dependency | Purpose | Required |
|
|
111
|
+
| --------------------------------------------------------------- | ------------------------------------------- | -------- |
|
|
112
|
+
| [OpenCode](https://opencode.ai) | Plugin host | Yes |
|
|
113
|
+
| [Beads](https://github.com/steveyegge/beads) | Git-backed issue tracking | Yes |
|
|
114
|
+
| [Go](https://go.dev) | Required for Agent Mail | No |
|
|
115
|
+
| [Agent Mail](https://github.com/joelhooks/agent-mail) | Multi-agent coordination, file reservations | No |
|
|
116
|
+
| [CASS](https://github.com/Dicklesworthstone/cass) | Historical context from past sessions | No |
|
|
117
|
+
| [UBS](https://github.com/joelhooks/ubs) | Pre-completion bug scanning | No |
|
|
118
|
+
| [semantic-memory](https://github.com/joelhooks/semantic-memory) | Learning persistence | No |
|
|
119
|
+
| [Redis](https://redis.io) | Rate limiting (SQLite fallback available) | No |
|
|
224
120
|
|
|
225
|
-
|
|
121
|
+
All dependencies are checked and can be installed via `swarm setup`.
|
|
226
122
|
|
|
227
|
-
|
|
228
|
-
- **Redis unavailable** - Automatic SQLite fallback with warning logged; no action needed
|
|
229
|
-
- **SQLite cleanup** - Expired entries cleaned automatically on init
|
|
123
|
+
## Tools Reference
|
|
230
124
|
|
|
231
|
-
### Swarm
|
|
125
|
+
### Swarm
|
|
232
126
|
|
|
233
127
|
| Tool | Description |
|
|
234
128
|
| ------------------------------ | ------------------------------------------------------------------------ |
|
|
235
|
-
| `swarm_init` |
|
|
236
|
-
| `swarm_select_strategy` | Analyze task
|
|
237
|
-
| `swarm_plan_prompt` | Generate strategy-specific planning prompt with CASS
|
|
238
|
-
| `swarm_decompose` | Generate decomposition prompt
|
|
239
|
-
| `swarm_validate_decomposition` | Validate
|
|
240
|
-
| `
|
|
241
|
-
| `
|
|
242
|
-
| `
|
|
243
|
-
| `
|
|
244
|
-
| `
|
|
245
|
-
| `
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
|
252
|
-
|
|
|
253
|
-
| `
|
|
254
|
-
| `
|
|
255
|
-
| `
|
|
256
|
-
| `
|
|
257
|
-
| `
|
|
129
|
+
| `swarm_init` | Initialize swarm session |
|
|
130
|
+
| `swarm_select_strategy` | Analyze task, recommend decomposition strategy (file/feature/risk-based) |
|
|
131
|
+
| `swarm_plan_prompt` | Generate strategy-specific planning prompt with CASS history |
|
|
132
|
+
| `swarm_decompose` | Generate decomposition prompt |
|
|
133
|
+
| `swarm_validate_decomposition` | Validate response, detect file conflicts |
|
|
134
|
+
| `swarm_spawn_subtask` | Generate worker agent prompt with Agent Mail/beads instructions |
|
|
135
|
+
| `swarm_subtask_prompt` | Alias for spawn_subtask |
|
|
136
|
+
| `swarm_status` | Get swarm progress by epic ID |
|
|
137
|
+
| `swarm_progress` | Report subtask progress to coordinator |
|
|
138
|
+
| `swarm_complete` | Complete subtask - runs UBS scan, releases reservations |
|
|
139
|
+
| `swarm_record_outcome` | Record outcome for learning (duration, errors, retries) |
|
|
140
|
+
|
|
141
|
+
### Beads
|
|
142
|
+
|
|
143
|
+
| Tool | Description |
|
|
144
|
+
| ------------------- | ---------------------------------------------- |
|
|
145
|
+
| `beads_create` | Create bead with type-safe validation |
|
|
146
|
+
| `beads_create_epic` | Create epic + subtasks atomically |
|
|
147
|
+
| `beads_query` | Query beads with filters (status, type, ready) |
|
|
148
|
+
| `beads_update` | Update status/description/priority |
|
|
149
|
+
| `beads_close` | Close bead with reason |
|
|
150
|
+
| `beads_start` | Mark bead as in-progress |
|
|
151
|
+
| `beads_ready` | Get next unblocked bead |
|
|
152
|
+
| `beads_sync` | Sync to git and push |
|
|
153
|
+
| `beads_link_thread` | Link bead to Agent Mail thread |
|
|
154
|
+
|
|
155
|
+
### Agent Mail
|
|
156
|
+
|
|
157
|
+
| Tool | Description |
|
|
158
|
+
| ---------------------------- | ---------------------------------------------- |
|
|
159
|
+
| `agentmail_init` | Initialize session, register agent |
|
|
160
|
+
| `agentmail_send` | Send message to agents |
|
|
161
|
+
| `agentmail_inbox` | Fetch inbox (max 5, no bodies - context safe) |
|
|
162
|
+
| `agentmail_read_message` | Fetch single message body by ID |
|
|
163
|
+
| `agentmail_summarize_thread` | Summarize thread (preferred over fetching all) |
|
|
164
|
+
| `agentmail_reserve` | Reserve file paths for exclusive editing |
|
|
165
|
+
| `agentmail_release` | Release file reservations |
|
|
166
|
+
| `agentmail_ack` | Acknowledge message |
|
|
167
|
+
| `agentmail_search` | Search messages by keyword |
|
|
168
|
+
| `agentmail_health` | Check if Agent Mail server is running |
|
|
169
|
+
|
|
170
|
+
### Structured Output
|
|
171
|
+
|
|
172
|
+
| Tool | Description |
|
|
173
|
+
| -------------------------------- | ----------------------------------------------------- |
|
|
174
|
+
| `structured_extract_json` | Extract JSON from markdown/text (multiple strategies) |
|
|
175
|
+
| `structured_validate` | Validate response against schema |
|
|
176
|
+
| `structured_parse_evaluation` | Parse self-evaluation response |
|
|
177
|
+
| `structured_parse_decomposition` | Parse task decomposition response |
|
|
178
|
+
| `structured_parse_bead_tree` | Parse bead tree for epic creation |
|
|
258
179
|
|
|
259
180
|
## Decomposition Strategies
|
|
260
181
|
|
|
261
|
-
|
|
182
|
+
### File-Based
|
|
262
183
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
Best for: Refactoring, migrations, pattern changes across codebase
|
|
266
|
-
|
|
267
|
-
**Keywords**: refactor, migrate, rename, update all, convert, upgrade
|
|
268
|
-
|
|
269
|
-
**Guidelines**:
|
|
184
|
+
Best for: refactoring, migrations, pattern changes
|
|
270
185
|
|
|
271
186
|
- Group files by directory or type
|
|
272
187
|
- Handle shared types/utilities first
|
|
273
188
|
- Minimize cross-directory dependencies
|
|
274
189
|
|
|
275
|
-
|
|
190
|
+
**Keywords**: refactor, migrate, rename, update all, replace
|
|
276
191
|
|
|
277
|
-
|
|
192
|
+
### Feature-Based
|
|
278
193
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
**Guidelines**:
|
|
194
|
+
Best for: new features, adding functionality
|
|
282
195
|
|
|
283
196
|
- Each subtask is a complete vertical slice
|
|
284
197
|
- Start with data layer, then logic, then UI
|
|
285
198
|
- Keep related components together
|
|
286
199
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
Best for: Bug fixes, security issues, critical changes
|
|
200
|
+
**Keywords**: add, implement, build, create, feature
|
|
290
201
|
|
|
291
|
-
|
|
202
|
+
### Risk-Based
|
|
292
203
|
|
|
293
|
-
|
|
204
|
+
Best for: bug fixes, security issues
|
|
294
205
|
|
|
295
206
|
- Write tests FIRST
|
|
296
207
|
- Isolate risky changes
|
|
297
208
|
- Audit similar code for same issue
|
|
298
209
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
Use `swarm_select_strategy` to see the recommended strategy:
|
|
302
|
-
|
|
303
|
-
```typescript
|
|
304
|
-
swarm_select_strategy({ task: "Add user authentication" });
|
|
305
|
-
// Returns: { strategy: "feature-based", confidence: 0.85, reasoning: "..." }
|
|
306
|
-
```
|
|
307
|
-
|
|
308
|
-
Or let `swarm_plan_prompt` auto-select:
|
|
210
|
+
**Keywords**: fix, bug, security, critical, urgent
|
|
309
211
|
|
|
310
|
-
|
|
311
|
-
swarm_plan_prompt({ task: "Refactor all components to use hooks" });
|
|
312
|
-
// Auto-selects file-based strategy
|
|
313
|
-
```
|
|
314
|
-
|
|
315
|
-
## Example Planner Agent
|
|
316
|
-
|
|
317
|
-
The plugin includes an example planner agent at `examples/agents/swarm-planner.md`.
|
|
212
|
+
## Learning
|
|
318
213
|
|
|
319
|
-
|
|
214
|
+
The plugin learns from outcomes:
|
|
320
215
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
```
|
|
328
|
-
@swarm-planner "Add user authentication with OAuth"
|
|
329
|
-
```
|
|
330
|
-
|
|
331
|
-
The planner uses `swarm_select_strategy` and `swarm_plan_prompt` internally to create optimal decompositions.
|
|
332
|
-
|
|
333
|
-
### Schemas (for structured outputs)
|
|
334
|
-
|
|
335
|
-
The plugin exports Zod schemas for validated agent responses:
|
|
336
|
-
|
|
337
|
-
| Schema | Purpose |
|
|
338
|
-
| ---------------------------- | -------------------------------------------- |
|
|
339
|
-
| `TaskDecompositionSchema` | Decompose task into parallelizable subtasks |
|
|
340
|
-
| `EvaluationSchema` | Agent self-evaluation of completed work |
|
|
341
|
-
| `WeightedEvaluationSchema` | Evaluation with confidence-weighted criteria |
|
|
342
|
-
| `SwarmStatusSchema` | Swarm progress tracking |
|
|
343
|
-
| `SwarmSpawnResultSchema` | Result of spawning agent swarm |
|
|
344
|
-
| `BeadSchema` | Validated bead data |
|
|
345
|
-
| `EpicCreateResultSchema` | Atomic epic creation result |
|
|
346
|
-
| `FeedbackEventSchema` | Feedback event for learning |
|
|
347
|
-
| `OutcomeSignalsSchema` | Implicit feedback from task outcomes |
|
|
348
|
-
| `DecompositionPatternSchema` | Tracked decomposition pattern |
|
|
349
|
-
| `PatternMaturitySchema` | Pattern maturity state tracking |
|
|
350
|
-
|
|
351
|
-
## Usage Examples
|
|
352
|
-
|
|
353
|
-
### Basic Bead Creation
|
|
354
|
-
|
|
355
|
-
```typescript
|
|
356
|
-
// Create a bug report with priority
|
|
357
|
-
await tools["beads_create"]({
|
|
358
|
-
title: "Fix login redirect loop",
|
|
359
|
-
type: "bug",
|
|
360
|
-
priority: 1,
|
|
361
|
-
description: "Users stuck in redirect after OAuth callback",
|
|
362
|
-
});
|
|
363
|
-
```
|
|
364
|
-
|
|
365
|
-
### Atomic Epic with Subtasks
|
|
366
|
-
|
|
367
|
-
```typescript
|
|
368
|
-
// Create epic and all subtasks atomically (with rollback hints on failure)
|
|
369
|
-
const result = await tools["beads_create_epic"]({
|
|
370
|
-
epic_title: "Implement user dashboard",
|
|
371
|
-
epic_description: "New dashboard with metrics and activity feed",
|
|
372
|
-
subtasks: [
|
|
373
|
-
{
|
|
374
|
-
title: "Create dashboard layout",
|
|
375
|
-
priority: 2,
|
|
376
|
-
files: ["src/components/Dashboard.tsx"],
|
|
377
|
-
},
|
|
378
|
-
{
|
|
379
|
-
title: "Add metrics API endpoint",
|
|
380
|
-
priority: 2,
|
|
381
|
-
files: ["src/api/metrics.ts"],
|
|
382
|
-
},
|
|
383
|
-
{
|
|
384
|
-
title: "Build activity feed component",
|
|
385
|
-
priority: 3,
|
|
386
|
-
files: ["src/components/ActivityFeed.tsx"],
|
|
387
|
-
},
|
|
388
|
-
],
|
|
389
|
-
});
|
|
390
|
-
```
|
|
391
|
-
|
|
392
|
-
### Agent Mail Coordination
|
|
393
|
-
|
|
394
|
-
```typescript
|
|
395
|
-
// 1. Initialize session
|
|
396
|
-
await tools["agentmail_init"]({
|
|
397
|
-
project_path: "/Users/you/project",
|
|
398
|
-
task_description: "Working on auth refactor",
|
|
399
|
-
});
|
|
400
|
-
// Returns: { agent: { name: "BlueLake", ... } }
|
|
401
|
-
|
|
402
|
-
// 2. Reserve files before editing
|
|
403
|
-
await tools["agentmail_reserve"]({
|
|
404
|
-
paths: ["src/auth/**", "src/middleware/auth.ts"],
|
|
405
|
-
reason: "bd-abc123: Auth refactor",
|
|
406
|
-
ttl_seconds: 3600,
|
|
407
|
-
});
|
|
408
|
-
|
|
409
|
-
// 3. Check inbox (bodies excluded by default)
|
|
410
|
-
const messages = await tools["agentmail_inbox"]({ limit: 5 });
|
|
411
|
-
|
|
412
|
-
// 4. Send status update to other agents
|
|
413
|
-
await tools["agentmail_send"]({
|
|
414
|
-
to: ["RedStone", "GreenCastle"],
|
|
415
|
-
subject: "Auth refactor complete",
|
|
416
|
-
body: "Finished updating the auth middleware. Ready for review.",
|
|
417
|
-
thread_id: "bd-abc123",
|
|
418
|
-
});
|
|
419
|
-
|
|
420
|
-
// 5. Release reservations when done
|
|
421
|
-
await tools["agentmail_release"]({});
|
|
422
|
-
```
|
|
423
|
-
|
|
424
|
-
### Swarm Workflow
|
|
425
|
-
|
|
426
|
-
```typescript
|
|
427
|
-
// 1. Create epic for the work
|
|
428
|
-
const epic = await tools["beads_create_epic"]({
|
|
429
|
-
epic_title: "Add export feature",
|
|
430
|
-
subtasks: [
|
|
431
|
-
{ title: "Export to CSV", files: ["src/export/csv.ts"] },
|
|
432
|
-
{ title: "Export to JSON", files: ["src/export/json.ts"] },
|
|
433
|
-
{ title: "Export to PDF", files: ["src/export/pdf.ts"] },
|
|
434
|
-
],
|
|
435
|
-
});
|
|
436
|
-
|
|
437
|
-
// 2. Each parallel agent reserves its files
|
|
438
|
-
// Agent 1 (BlueLake):
|
|
439
|
-
await tools["agentmail_reserve"]({
|
|
440
|
-
paths: ["src/export/csv.ts"],
|
|
441
|
-
reason: `${epic.subtasks[0].id}: Export to CSV`,
|
|
442
|
-
});
|
|
443
|
-
|
|
444
|
-
// 3. Agents communicate via thread
|
|
445
|
-
await tools["agentmail_send"]({
|
|
446
|
-
to: ["Coordinator"],
|
|
447
|
-
subject: "CSV export complete",
|
|
448
|
-
body: "Implemented CSV export with streaming support.",
|
|
449
|
-
thread_id: epic.epic.id,
|
|
450
|
-
});
|
|
451
|
-
|
|
452
|
-
// 4. Coordinator uses summarize_thread (not fetch all)
|
|
453
|
-
const summary = await tools["agentmail_summarize_thread"]({
|
|
454
|
-
thread_id: epic.epic.id,
|
|
455
|
-
include_examples: true,
|
|
456
|
-
});
|
|
457
|
-
```
|
|
458
|
-
|
|
459
|
-
## Learning Capabilities
|
|
460
|
-
|
|
461
|
-
The plugin learns from swarm outcomes to improve future decompositions.
|
|
462
|
-
|
|
463
|
-
### Confidence Decay
|
|
464
|
-
|
|
465
|
-
Evaluation criteria weights decay over time unless revalidated. If a criterion (e.g., `type_safe`) has been historically unreliable, its weight decreases.
|
|
466
|
-
|
|
467
|
-
```typescript
|
|
468
|
-
import {
|
|
469
|
-
calculateDecayedValue,
|
|
470
|
-
calculateCriterionWeight,
|
|
471
|
-
} from "opencode-swarm-plugin";
|
|
472
|
-
|
|
473
|
-
// Value decays by 50% every 90 days (configurable half-life)
|
|
474
|
-
const weight = calculateDecayedValue(timestamp, now, halfLifeDays);
|
|
475
|
-
|
|
476
|
-
// Calculate criterion weight from feedback history
|
|
477
|
-
const criterionWeight = calculateCriterionWeight(feedbackEvents);
|
|
478
|
-
// { criterion: "type_safe", weight: 0.85, helpful_count: 10, harmful_count: 2 }
|
|
479
|
-
```
|
|
480
|
-
|
|
481
|
-
### Implicit Feedback Scoring
|
|
482
|
-
|
|
483
|
-
The `swarm_record_outcome` tool tracks task outcomes and infers feedback:
|
|
484
|
-
|
|
485
|
-
- **Fast completion + success** → helpful signal
|
|
486
|
-
- **Slow completion + errors + retries** → harmful signal
|
|
487
|
-
|
|
488
|
-
```typescript
|
|
489
|
-
// Record outcome after completing a subtask
|
|
490
|
-
await tools["swarm_record_outcome"]({
|
|
491
|
-
bead_id: "bd-abc123.1",
|
|
492
|
-
duration_ms: 60000,
|
|
493
|
-
error_count: 0,
|
|
494
|
-
retry_count: 0,
|
|
495
|
-
success: true,
|
|
496
|
-
files_touched: ["src/auth.ts"],
|
|
497
|
-
});
|
|
498
|
-
// Returns feedback events for each criterion
|
|
499
|
-
```
|
|
500
|
-
|
|
501
|
-
### Anti-Pattern Learning
|
|
502
|
-
|
|
503
|
-
Failed decomposition patterns are automatically inverted to anti-patterns:
|
|
504
|
-
|
|
505
|
-
```typescript
|
|
506
|
-
import {
|
|
507
|
-
recordPatternObservation,
|
|
508
|
-
formatAntiPatternsForPrompt,
|
|
509
|
-
} from "opencode-swarm-plugin";
|
|
510
|
-
|
|
511
|
-
// Record pattern failure
|
|
512
|
-
const result = recordPatternObservation(pattern, false, beadId);
|
|
513
|
-
if (result.inversion) {
|
|
514
|
-
// Pattern was inverted: "Split by file type" → "AVOID: Split by file type. Failed 4/5 times (80% failure rate)"
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
// Include anti-patterns in decomposition prompts
|
|
518
|
-
const antiPatternContext = formatAntiPatternsForPrompt(patterns);
|
|
519
|
-
```
|
|
520
|
-
|
|
521
|
-
### Pattern Maturity
|
|
522
|
-
|
|
523
|
-
Patterns progress through maturity states: `candidate` → `established` → `proven` (or `deprecated`).
|
|
524
|
-
|
|
525
|
-
```typescript
|
|
526
|
-
import {
|
|
527
|
-
calculateMaturityState,
|
|
528
|
-
getMaturityMultiplier,
|
|
529
|
-
} from "opencode-swarm-plugin";
|
|
530
|
-
|
|
531
|
-
// Calculate state from feedback
|
|
532
|
-
const state = calculateMaturityState(feedbackEvents);
|
|
533
|
-
// "candidate" | "established" | "proven" | "deprecated"
|
|
534
|
-
|
|
535
|
-
// Get weight multiplier for pattern ranking
|
|
536
|
-
const multiplier = getMaturityMultiplier("proven"); // 1.5
|
|
537
|
-
```
|
|
538
|
-
|
|
539
|
-
### UBS Pre-Completion Scan
|
|
540
|
-
|
|
541
|
-
The `swarm_complete` tool runs UBS (Ultimate Bug Scanner) on modified files before marking complete:
|
|
542
|
-
|
|
543
|
-
```typescript
|
|
544
|
-
await tools["swarm_complete"]({
|
|
545
|
-
project_key: "/path/to/project",
|
|
546
|
-
agent_name: "BlueLake",
|
|
547
|
-
bead_id: "bd-abc123.1",
|
|
548
|
-
summary: "Implemented auth flow",
|
|
549
|
-
files_touched: ["src/auth.ts", "src/middleware.ts"],
|
|
550
|
-
// skip_ubs_scan: true // Optional: bypass scan
|
|
551
|
-
});
|
|
552
|
-
// Blocks completion if critical bugs found
|
|
553
|
-
```
|
|
554
|
-
|
|
555
|
-
### CASS History Context
|
|
556
|
-
|
|
557
|
-
The `swarm_decompose` tool queries CASS (Cross-Agent Session Search) for similar past tasks:
|
|
558
|
-
|
|
559
|
-
```typescript
|
|
560
|
-
await tools["swarm_decompose"]({
|
|
561
|
-
task: "Add user authentication with OAuth",
|
|
562
|
-
max_subtasks: 5,
|
|
563
|
-
query_cass: true, // Default: true
|
|
564
|
-
cass_limit: 3, // Max results to include
|
|
565
|
-
});
|
|
566
|
-
// Includes successful patterns from past decompositions in context
|
|
567
|
-
```
|
|
216
|
+
| Mechanism | How It Works |
|
|
217
|
+
| ----------------- | ----------------------------------------------------------- |
|
|
218
|
+
| Confidence decay | Criteria weights fade unless revalidated (90-day half-life) |
|
|
219
|
+
| Implicit feedback | Fast + success = helpful signal, slow + errors = harmful |
|
|
220
|
+
| Pattern maturity | candidate → established → proven (or deprecated) |
|
|
221
|
+
| Anti-patterns | Patterns with >60% failure rate auto-invert |
|
|
568
222
|
|
|
569
223
|
## Context Preservation
|
|
570
224
|
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
### Why These Constraints Exist
|
|
574
|
-
|
|
575
|
-
| Constraint | Default | Reason |
|
|
576
|
-
| -------------------- | ---------------------------- | -------------------------------------------------- |
|
|
577
|
-
| Inbox limit | 5 messages | Fetching 20+ messages with bodies exhausts context |
|
|
578
|
-
| Bodies excluded | `include_bodies: false` | Message bodies can be huge; fetch individually |
|
|
579
|
-
| Summarize over fetch | `summarize_thread` preferred | Get key points, not raw message dump |
|
|
580
|
-
|
|
581
|
-
### The Pattern
|
|
582
|
-
|
|
583
|
-
```typescript
|
|
584
|
-
// WRONG: This can dump thousands of tokens into context
|
|
585
|
-
const messages = await tools["agentmail_inbox"]({
|
|
586
|
-
limit: 20,
|
|
587
|
-
include_bodies: true, // Plugin prevents this
|
|
588
|
-
});
|
|
589
|
-
|
|
590
|
-
// RIGHT: Headers only, then fetch specific messages
|
|
591
|
-
const headers = await tools["agentmail_inbox"]({ limit: 5 });
|
|
592
|
-
const importantMessage = await tools["agentmail_read_message"]({
|
|
593
|
-
message_id: headers[0].id,
|
|
594
|
-
});
|
|
595
|
-
|
|
596
|
-
// BEST: Summarize threads instead of fetching all messages
|
|
597
|
-
const summary = await tools["agentmail_summarize_thread"]({
|
|
598
|
-
thread_id: "bd-abc123",
|
|
599
|
-
});
|
|
600
|
-
```
|
|
601
|
-
|
|
602
|
-
### Hard Caps
|
|
603
|
-
|
|
604
|
-
The plugin enforces these limits regardless of input:
|
|
605
|
-
|
|
606
|
-
- `agentmail_inbox` - Max 5 messages, bodies always excluded
|
|
607
|
-
- Thread summaries use LLM mode for concise output
|
|
608
|
-
- File reservations auto-track for cleanup
|
|
609
|
-
|
|
610
|
-
## Custom Commands
|
|
611
|
-
|
|
612
|
-
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.
|
|
613
|
-
|
|
614
|
-
### Setup /swarm Command
|
|
615
|
-
|
|
616
|
-
Copy the example command to your OpenCode config:
|
|
225
|
+
Hard limits to prevent context exhaustion:
|
|
617
226
|
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
```
|
|
625
|
-
/swarm "Add user authentication with OAuth providers"
|
|
626
|
-
```
|
|
627
|
-
|
|
628
|
-
### How It Works
|
|
629
|
-
|
|
630
|
-
1. **Decompose** - `swarm_decompose` breaks task into subtasks with file assignments
|
|
631
|
-
2. **Create beads** - `beads_create_epic` creates epic + subtasks atomically
|
|
632
|
-
3. **Spawn agents** - `swarm_spawn_subtask` generates prompts WITH Agent Mail/beads instructions
|
|
633
|
-
4. **Parallel work** - Subagents use Agent Mail to communicate, beads to track progress
|
|
634
|
-
5. **Coordination** - Agents report progress, ask questions, announce blockers via Agent Mail
|
|
635
|
-
6. **Completion** - Agents use `swarm_complete` when done
|
|
636
|
-
7. **Cleanup** - `beads_sync` pushes to git
|
|
637
|
-
|
|
638
|
-
### Subagent Capabilities
|
|
227
|
+
| Constraint | Default | Reason |
|
|
228
|
+
| ------------------- | ---------- | ------------------------------ |
|
|
229
|
+
| Inbox limit | 5 messages | Prevents token burn |
|
|
230
|
+
| Bodies excluded | Always | Fetch individually when needed |
|
|
231
|
+
| Summarize preferred | Yes | Key points, not raw dump |
|
|
639
232
|
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
- **Agent Mail** - `agentmail_send`, `agentmail_inbox`, `agentmail_reserve`, etc.
|
|
643
|
-
- **Beads** - `beads_update`, `beads_create`, `swarm_complete`
|
|
644
|
-
- All standard OpenCode tools
|
|
645
|
-
|
|
646
|
-
The prompts tell agents to actively communicate and coordinate.
|
|
647
|
-
|
|
648
|
-
## Error Handling
|
|
233
|
+
## Rate Limiting
|
|
649
234
|
|
|
650
|
-
|
|
235
|
+
Client-side limits (Redis primary, SQLite fallback):
|
|
651
236
|
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
AgentMailNotInitializedError,
|
|
658
|
-
FileReservationConflictError,
|
|
659
|
-
} from "opencode-swarm-plugin";
|
|
237
|
+
| Endpoint | Per Minute | Per Hour |
|
|
238
|
+
| -------- | ---------- | -------- |
|
|
239
|
+
| send | 20 | 200 |
|
|
240
|
+
| reserve | 10 | 100 |
|
|
241
|
+
| inbox | 60 | 600 |
|
|
660
242
|
|
|
661
|
-
|
|
662
|
-
await tools["agentmail_reserve"]({ paths: ["src/index.ts"] });
|
|
663
|
-
} catch (error) {
|
|
664
|
-
if (error instanceof FileReservationConflictError) {
|
|
665
|
-
console.log("Conflicts:", error.conflicts);
|
|
666
|
-
// [{ path: "src/index.ts", holders: ["RedStone"] }]
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
```
|
|
243
|
+
Configure via `OPENCODE_RATE_LIMIT_{ENDPOINT}_PER_MIN` env vars.
|
|
670
244
|
|
|
671
245
|
## Development
|
|
672
246
|
|
|
673
247
|
```bash
|
|
674
|
-
# Install dependencies
|
|
675
248
|
bun install
|
|
676
|
-
|
|
677
|
-
# Type check
|
|
678
249
|
bun run typecheck
|
|
679
|
-
|
|
680
|
-
# Run tests
|
|
681
250
|
bun test
|
|
682
|
-
|
|
683
|
-
# Build for distribution
|
|
684
251
|
bun run build
|
|
685
|
-
|
|
686
|
-
# Clean build artifacts
|
|
687
|
-
bun run clean
|
|
688
252
|
```
|
|
689
253
|
|
|
690
254
|
## License
|