opencode-swarm-plugin 0.1.0 → 0.2.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 +308 -0
- package/README.md +157 -11
- package/dist/index.js +804 -23
- package/dist/plugin.js +443 -23
- package/package.json +7 -3
- package/src/agent-mail.ts +46 -3
- package/src/index.ts +60 -0
- package/src/learning.integration.test.ts +326 -1
- package/src/storage.integration.test.ts +341 -0
- package/src/storage.ts +679 -0
- package/src/swarm.integration.test.ts +194 -3
- package/src/swarm.ts +185 -32
- package/src/tool-availability.ts +389 -0
package/README.md
CHANGED
|
@@ -3,21 +3,29 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/opencode-swarm-plugin)
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
Multi-agent swarm coordination for [OpenCode](https://opencode.ai) with learning capabilities, beads integration, and Agent Mail.
|
|
7
7
|
|
|
8
8
|
## Overview
|
|
9
9
|
|
|
10
|
-
This plugin provides
|
|
10
|
+
This plugin provides intelligent, self-improving tools for multi-agent workflows in OpenCode:
|
|
11
11
|
|
|
12
12
|
- **Type-safe beads operations** - Zod-validated wrappers around the `bd` CLI with proper error handling
|
|
13
13
|
- **Agent Mail integration** - File reservations, async messaging, and thread coordination between agents
|
|
14
14
|
- **Structured outputs** - Reliable JSON responses with schema validation and retry support
|
|
15
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
|
|
16
20
|
|
|
17
21
|
## Installation
|
|
18
22
|
|
|
19
23
|
```bash
|
|
24
|
+
npm install opencode-swarm-plugin
|
|
25
|
+
# or
|
|
20
26
|
bun add opencode-swarm-plugin
|
|
27
|
+
# or
|
|
28
|
+
pnpm add opencode-swarm-plugin
|
|
21
29
|
```
|
|
22
30
|
|
|
23
31
|
Copy the plugin to your OpenCode plugins directory:
|
|
@@ -30,7 +38,7 @@ Plugins are automatically loaded from `~/.config/opencode/plugin/` - no config f
|
|
|
30
38
|
|
|
31
39
|
> **Note:** The package has two entry points:
|
|
32
40
|
>
|
|
33
|
-
> - `dist/index.js` - Full library exports (schemas, errors, utilities)
|
|
41
|
+
> - `dist/index.js` - Full library exports (schemas, errors, utilities, learning modules)
|
|
34
42
|
> - `dist/plugin.js` - Plugin entry point that only exports the `plugin` function for OpenCode
|
|
35
43
|
|
|
36
44
|
## Prerequisites
|
|
@@ -84,18 +92,46 @@ bd --version
|
|
|
84
92
|
| `agentmail_search` | Search messages (FTS5 syntax) |
|
|
85
93
|
| `agentmail_health` | Check if Agent Mail server is running |
|
|
86
94
|
|
|
95
|
+
### Swarm Tools
|
|
96
|
+
|
|
97
|
+
| Tool | Description |
|
|
98
|
+
| ------------------------------ | ------------------------------------------------------------------------ |
|
|
99
|
+
| `swarm_decompose` | Generate decomposition prompt, optionally queries CASS for similar tasks |
|
|
100
|
+
| `swarm_validate_decomposition` | Validate decomposition response, detect instruction conflicts |
|
|
101
|
+
| `swarm_status` | Get swarm status by epic ID |
|
|
102
|
+
| `swarm_progress` | Report progress on a subtask |
|
|
103
|
+
| `swarm_complete` | Mark subtask complete with UBS bug scan, release reservations |
|
|
104
|
+
| `swarm_record_outcome` | Record outcome for implicit feedback (duration, errors, retries) |
|
|
105
|
+
| `swarm_subtask_prompt` | Generate prompt for spawned subtask agent |
|
|
106
|
+
| `swarm_evaluation_prompt` | Generate self-evaluation prompt |
|
|
107
|
+
|
|
108
|
+
### Structured Output Tools
|
|
109
|
+
|
|
110
|
+
| Tool | Description |
|
|
111
|
+
| -------------------------------- | -------------------------------------------------------- |
|
|
112
|
+
| `structured_extract_json` | Extract JSON from markdown/text with multiple strategies |
|
|
113
|
+
| `structured_validate` | Validate response against named schema |
|
|
114
|
+
| `structured_parse_evaluation` | Parse and validate evaluation response |
|
|
115
|
+
| `structured_parse_decomposition` | Parse and validate task decomposition |
|
|
116
|
+
| `structured_parse_bead_tree` | Parse and validate bead tree for epic creation |
|
|
117
|
+
|
|
87
118
|
### Schemas (for structured outputs)
|
|
88
119
|
|
|
89
120
|
The plugin exports Zod schemas for validated agent responses:
|
|
90
121
|
|
|
91
|
-
| Schema
|
|
92
|
-
|
|
|
93
|
-
| `TaskDecompositionSchema`
|
|
94
|
-
| `EvaluationSchema`
|
|
95
|
-
| `
|
|
96
|
-
| `
|
|
97
|
-
| `
|
|
98
|
-
| `
|
|
122
|
+
| Schema | Purpose |
|
|
123
|
+
| ---------------------------- | -------------------------------------------- |
|
|
124
|
+
| `TaskDecompositionSchema` | Decompose task into parallelizable subtasks |
|
|
125
|
+
| `EvaluationSchema` | Agent self-evaluation of completed work |
|
|
126
|
+
| `WeightedEvaluationSchema` | Evaluation with confidence-weighted criteria |
|
|
127
|
+
| `SwarmStatusSchema` | Swarm progress tracking |
|
|
128
|
+
| `SwarmSpawnResultSchema` | Result of spawning agent swarm |
|
|
129
|
+
| `BeadSchema` | Validated bead data |
|
|
130
|
+
| `EpicCreateResultSchema` | Atomic epic creation result |
|
|
131
|
+
| `FeedbackEventSchema` | Feedback event for learning |
|
|
132
|
+
| `OutcomeSignalsSchema` | Implicit feedback from task outcomes |
|
|
133
|
+
| `DecompositionPatternSchema` | Tracked decomposition pattern |
|
|
134
|
+
| `PatternMaturitySchema` | Pattern maturity state tracking |
|
|
99
135
|
|
|
100
136
|
## Usage Examples
|
|
101
137
|
|
|
@@ -205,6 +241,116 @@ const summary = await tools["agentmail_summarize_thread"]({
|
|
|
205
241
|
});
|
|
206
242
|
```
|
|
207
243
|
|
|
244
|
+
## Learning Capabilities
|
|
245
|
+
|
|
246
|
+
The plugin learns from swarm outcomes to improve future decompositions.
|
|
247
|
+
|
|
248
|
+
### Confidence Decay
|
|
249
|
+
|
|
250
|
+
Evaluation criteria weights decay over time unless revalidated. If a criterion (e.g., `type_safe`) has been historically unreliable, its weight decreases.
|
|
251
|
+
|
|
252
|
+
```typescript
|
|
253
|
+
import {
|
|
254
|
+
calculateDecayedValue,
|
|
255
|
+
calculateCriterionWeight,
|
|
256
|
+
} from "opencode-swarm-plugin";
|
|
257
|
+
|
|
258
|
+
// Value decays by 50% every 90 days (configurable half-life)
|
|
259
|
+
const weight = calculateDecayedValue(timestamp, now, halfLifeDays);
|
|
260
|
+
|
|
261
|
+
// Calculate criterion weight from feedback history
|
|
262
|
+
const criterionWeight = calculateCriterionWeight(feedbackEvents);
|
|
263
|
+
// { criterion: "type_safe", weight: 0.85, helpful_count: 10, harmful_count: 2 }
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### Implicit Feedback Scoring
|
|
267
|
+
|
|
268
|
+
The `swarm_record_outcome` tool tracks task outcomes and infers feedback:
|
|
269
|
+
|
|
270
|
+
- **Fast completion + success** → helpful signal
|
|
271
|
+
- **Slow completion + errors + retries** → harmful signal
|
|
272
|
+
|
|
273
|
+
```typescript
|
|
274
|
+
// Record outcome after completing a subtask
|
|
275
|
+
await tools["swarm_record_outcome"]({
|
|
276
|
+
bead_id: "bd-abc123.1",
|
|
277
|
+
duration_ms: 60000,
|
|
278
|
+
error_count: 0,
|
|
279
|
+
retry_count: 0,
|
|
280
|
+
success: true,
|
|
281
|
+
files_touched: ["src/auth.ts"],
|
|
282
|
+
});
|
|
283
|
+
// Returns feedback events for each criterion
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
### Anti-Pattern Learning
|
|
287
|
+
|
|
288
|
+
Failed decomposition patterns are automatically inverted to anti-patterns:
|
|
289
|
+
|
|
290
|
+
```typescript
|
|
291
|
+
import {
|
|
292
|
+
recordPatternObservation,
|
|
293
|
+
formatAntiPatternsForPrompt,
|
|
294
|
+
} from "opencode-swarm-plugin";
|
|
295
|
+
|
|
296
|
+
// Record pattern failure
|
|
297
|
+
const result = recordPatternObservation(pattern, false, beadId);
|
|
298
|
+
if (result.inversion) {
|
|
299
|
+
// Pattern was inverted: "Split by file type" → "AVOID: Split by file type. Failed 4/5 times (80% failure rate)"
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// Include anti-patterns in decomposition prompts
|
|
303
|
+
const antiPatternContext = formatAntiPatternsForPrompt(patterns);
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
### Pattern Maturity
|
|
307
|
+
|
|
308
|
+
Patterns progress through maturity states: `candidate` → `established` → `proven` (or `deprecated`).
|
|
309
|
+
|
|
310
|
+
```typescript
|
|
311
|
+
import {
|
|
312
|
+
calculateMaturityState,
|
|
313
|
+
getMaturityMultiplier,
|
|
314
|
+
} from "opencode-swarm-plugin";
|
|
315
|
+
|
|
316
|
+
// Calculate state from feedback
|
|
317
|
+
const state = calculateMaturityState(feedbackEvents);
|
|
318
|
+
// "candidate" | "established" | "proven" | "deprecated"
|
|
319
|
+
|
|
320
|
+
// Get weight multiplier for pattern ranking
|
|
321
|
+
const multiplier = getMaturityMultiplier("proven"); // 1.5
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### UBS Pre-Completion Scan
|
|
325
|
+
|
|
326
|
+
The `swarm_complete` tool runs UBS (Ultimate Bug Scanner) on modified files before marking complete:
|
|
327
|
+
|
|
328
|
+
```typescript
|
|
329
|
+
await tools["swarm_complete"]({
|
|
330
|
+
project_key: "/path/to/project",
|
|
331
|
+
agent_name: "BlueLake",
|
|
332
|
+
bead_id: "bd-abc123.1",
|
|
333
|
+
summary: "Implemented auth flow",
|
|
334
|
+
files_touched: ["src/auth.ts", "src/middleware.ts"],
|
|
335
|
+
// skip_ubs_scan: true // Optional: bypass scan
|
|
336
|
+
});
|
|
337
|
+
// Blocks completion if critical bugs found
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### CASS History Context
|
|
341
|
+
|
|
342
|
+
The `swarm_decompose` tool queries CASS (Cross-Agent Session Search) for similar past tasks:
|
|
343
|
+
|
|
344
|
+
```typescript
|
|
345
|
+
await tools["swarm_decompose"]({
|
|
346
|
+
task: "Add user authentication with OAuth",
|
|
347
|
+
max_subtasks: 5,
|
|
348
|
+
query_cass: true, // Default: true
|
|
349
|
+
cass_limit: 3, // Max results to include
|
|
350
|
+
});
|
|
351
|
+
// Includes successful patterns from past decompositions in context
|
|
352
|
+
```
|
|
353
|
+
|
|
208
354
|
## Context Preservation
|
|
209
355
|
|
|
210
356
|
**CRITICAL**: This plugin enforces context-safe defaults to prevent session exhaustion.
|