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