opencode-swarm-plugin 0.31.7 → 0.33.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.
Files changed (62) hide show
  1. package/.turbo/turbo-build.log +4 -4
  2. package/.turbo/turbo-test.log +324 -316
  3. package/CHANGELOG.md +394 -0
  4. package/README.md +129 -181
  5. package/bin/swarm.test.ts +31 -0
  6. package/bin/swarm.ts +635 -140
  7. package/dist/compaction-hook.d.ts +1 -1
  8. package/dist/compaction-hook.d.ts.map +1 -1
  9. package/dist/hive.d.ts.map +1 -1
  10. package/dist/index.d.ts +17 -2
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +653 -139
  13. package/dist/memory-tools.d.ts.map +1 -1
  14. package/dist/memory.d.ts +5 -4
  15. package/dist/memory.d.ts.map +1 -1
  16. package/dist/observability-tools.d.ts +116 -0
  17. package/dist/observability-tools.d.ts.map +1 -0
  18. package/dist/plugin.js +648 -136
  19. package/dist/skills.d.ts.map +1 -1
  20. package/dist/swarm-orchestrate.d.ts +29 -5
  21. package/dist/swarm-orchestrate.d.ts.map +1 -1
  22. package/dist/swarm-prompts.d.ts +66 -0
  23. package/dist/swarm-prompts.d.ts.map +1 -1
  24. package/dist/swarm.d.ts +17 -2
  25. package/dist/swarm.d.ts.map +1 -1
  26. package/evals/lib/{data-loader.test.ts → data-loader.evalite-test.ts} +7 -6
  27. package/evals/lib/data-loader.ts +1 -1
  28. package/evals/scorers/{outcome-scorers.test.ts → outcome-scorers.evalite-test.ts} +1 -1
  29. package/examples/plugin-wrapper-template.ts +316 -12
  30. package/global-skills/swarm-coordination/SKILL.md +118 -8
  31. package/package.json +3 -2
  32. package/src/compaction-hook.ts +5 -3
  33. package/src/hive.integration.test.ts +83 -1
  34. package/src/hive.ts +37 -12
  35. package/src/index.ts +25 -1
  36. package/src/mandate-storage.integration.test.ts +601 -0
  37. package/src/memory-tools.ts +6 -4
  38. package/src/memory.integration.test.ts +117 -49
  39. package/src/memory.test.ts +41 -217
  40. package/src/memory.ts +12 -8
  41. package/src/observability-tools.test.ts +346 -0
  42. package/src/observability-tools.ts +594 -0
  43. package/src/repo-crawl.integration.test.ts +441 -0
  44. package/src/skills.integration.test.ts +1192 -0
  45. package/src/skills.test.ts +42 -1
  46. package/src/skills.ts +8 -4
  47. package/src/structured.integration.test.ts +817 -0
  48. package/src/swarm-deferred.integration.test.ts +157 -0
  49. package/src/swarm-deferred.test.ts +38 -0
  50. package/src/swarm-mail.integration.test.ts +15 -19
  51. package/src/swarm-orchestrate.integration.test.ts +282 -0
  52. package/src/swarm-orchestrate.test.ts +123 -0
  53. package/src/swarm-orchestrate.ts +279 -201
  54. package/src/swarm-prompts.test.ts +481 -0
  55. package/src/swarm-prompts.ts +297 -0
  56. package/src/swarm-research.integration.test.ts +544 -0
  57. package/src/swarm-research.test.ts +698 -0
  58. package/src/swarm-research.ts +472 -0
  59. package/src/swarm-review.integration.test.ts +290 -0
  60. package/src/swarm.integration.test.ts +23 -20
  61. package/src/swarm.ts +6 -3
  62. package/src/tool-adapter.integration.test.ts +1221 -0
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # opencode-swarm-plugin
2
2
 
3
- OpenCode plugin for multi-agent swarm coordination with learning capabilities.
3
+ **Multi-agent swarm coordination for OpenCode - break tasks into parallel subtasks, spawn worker agents, learn from outcomes.**
4
4
 
5
5
  **🌐 Website:** [swarmtools.ai](https://swarmtools.ai)
6
6
  **📚 Full Documentation:** [swarmtools.ai/docs](https://swarmtools.ai/docs)
@@ -14,35 +14,109 @@ OpenCode plugin for multi-agent swarm coordination with learning capabilities.
14
14
  ╚══════╝ ╚══╝╚══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝
15
15
  ```
16
16
 
17
- ## Install
17
+ ## Quickstart (<2 minutes)
18
+
19
+ ### 1. Install
18
20
 
19
21
  ```bash
20
- # Install
21
22
  npm install -g opencode-swarm-plugin@latest
22
23
  swarm setup
24
+ ```
25
+
26
+ ### 2. Initialize in Your Project
27
+
28
+ ```bash
29
+ cd your-project
30
+ swarm init
31
+ ```
32
+
33
+ ### 3. Run Your First Swarm
34
+
35
+ ```bash
36
+ # Inside OpenCode
37
+ /swarm "Add user authentication with OAuth"
38
+ ```
23
39
 
24
- # For semantic memory (optional but recommended)
40
+ **What happens:**
41
+ - Task decomposed into parallel subtasks (coordinator queries past similar tasks)
42
+ - Worker agents spawn with file reservations
43
+ - Progress tracked with auto-checkpoints at 25/50/75%
44
+ - Completion runs bug scans, releases file locks, records learnings
45
+
46
+ Done. You're swarming.
47
+
48
+ ---
49
+
50
+ ## Optional But Recommended
51
+
52
+ ### Semantic Memory (for pattern learning)
53
+
54
+ ```bash
25
55
  brew install ollama
26
56
  ollama serve &
27
57
  ollama pull mxbai-embed-large
28
58
  ```
29
59
 
30
- ## Features
60
+ Without Ollama, memory falls back to full-text search (still works, just less semantic).
31
61
 
32
- - **Swarm Coordination** - Break tasks into parallel subtasks, spawn worker agents
33
- - **Hive Integration** - Git-backed work item tracking with atomic epic creation
34
- - **Agent Mail** - Inter-agent messaging with file reservations
35
- - **Learning System** - Pattern maturity, anti-pattern detection, confidence decay
36
- - **Skills System** - Knowledge injection with bundled and custom skills
37
- - **Checkpoint & Recovery** - Auto-checkpoint at 25/50/75%, survive context death (9 integration tests ✅)
62
+ ### Historical Context (CASS)
38
63
 
39
- ## Usage
64
+ Queries past AI sessions for similar decompositions:
40
65
 
41
66
  ```bash
42
- /swarm "Add user authentication with OAuth"
67
+ git clone https://github.com/Dicklesworthstone/coding_agent_session_search
68
+ cd coding_agent_session_search
69
+ pip install -e .
70
+ cass index # Run periodically to index new sessions
43
71
  ```
44
72
 
45
- ## Tools Provided
73
+ ### Bug Scanning (UBS)
74
+
75
+ Auto-runs on subtask completion:
76
+
77
+ ```bash
78
+ git clone https://github.com/Dicklesworthstone/ultimate_bug_scanner
79
+ cd ultimate_bug_scanner
80
+ pip install -e .
81
+ ```
82
+
83
+ Check status: `swarm doctor`
84
+
85
+ ---
86
+
87
+ ## Core Concepts
88
+
89
+ ### The Hive 🐝
90
+
91
+ Work items (cells) stored in `.hive/` and synced to git. Each cell is a unit of work - think GitHub issue but local-first.
92
+
93
+ **Cell IDs:** Project-prefixed for clarity (e.g., `swarm-mail-lf2p4u-abc123` not generic `bd-xxx`)
94
+
95
+ ### The Swarm
96
+
97
+ Parallel agents coordinated via **Swarm Mail** (message passing + file reservations). Coordinator spawns workers → workers reserve files → do work → report progress → complete with verification.
98
+
99
+ ### Learning
100
+
101
+ - **Pattern maturity** tracks what decomposition strategies work
102
+ - **Confidence decay** fades unreliable patterns (90-day half-life)
103
+ - **Anti-pattern inversion** auto-marks failing approaches to avoid
104
+ - **Outcome tracking** learns from speed, errors, retries
105
+
106
+ ### Checkpoint & Recovery
107
+
108
+ Auto-saves progress at milestones. Survives context death or crashes. Data stored in embedded libSQL (no external DB needed).
109
+
110
+ **When checkpoints happen:**
111
+ - Auto at 25%, 50%, 75% progress
112
+ - Before risky operations (via `swarm_checkpoint`)
113
+ - On errors (captures error context for recovery)
114
+
115
+ **Recovery:** `swarm_recover(project_key, epic_id)` returns full context to resume work.
116
+
117
+ ---
118
+
119
+ ## Tools Reference
46
120
 
47
121
  ### Hive (Work Item Tracking)
48
122
 
@@ -70,31 +144,21 @@ ollama pull mxbai-embed-large
70
144
  | `swarmmail_reserve` | Reserve files for exclusive edit |
71
145
  | `swarmmail_release` | Release reservations |
72
146
 
73
- ### Swarm (Task Orchestration)
147
+ ### Swarm Orchestration
74
148
 
75
149
  | Tool | Purpose |
76
150
  | ------------------------------ | ----------------------------------------------- |
77
151
  | `swarm_select_strategy` | Analyze task, recommend strategy |
78
152
  | `swarm_decompose` | Generate decomposition prompt (queries CASS) |
79
- | `swarm_delegate_planning` | Delegate planning to planner subagent |
80
153
  | `swarm_validate_decomposition` | Validate response, detect conflicts |
81
- | `swarm_plan_prompt` | Generate strategy-specific decomposition prompt |
82
154
  | `swarm_subtask_prompt` | Generate worker agent prompt |
83
- | `swarm_spawn_subtask` | Prepare subtask for Task tool spawning |
84
- | `swarm_evaluation_prompt` | Generate self-evaluation prompt |
85
- | `swarm_init` | Initialize swarm session |
86
155
  | `swarm_status` | Get swarm progress by epic ID |
87
- | `swarm_progress` | Report subtask progress to coordinator |
88
- | `swarm_complete` | Complete subtask (runs UBS scan, releases) |
89
- | `swarm_record_outcome` | Record outcome for learning |
156
+ | `swarm_progress` | Report subtask progress |
157
+ | `swarm_complete` | Complete subtask (releases reservations) |
90
158
  | `swarm_checkpoint` | Save progress snapshot (auto at 25/50/75%) |
91
- | `swarm_recover` | Resume from checkpoint (returns full context) |
92
- | `swarm_learn` | Extract learnings from outcome |
93
- | `swarm_broadcast` | Send message to all active agents |
94
- | `swarm_accumulate_error` | Track recurring errors (3-strike system) |
95
- | `swarm_check_strikes` | Check if error threshold reached |
96
- | `swarm_get_error_context` | Get context for error pattern |
97
- | `swarm_resolve_error` | Mark error pattern as resolved |
159
+ | `swarm_recover` | Resume from checkpoint |
160
+ | `swarm_review` | Generate review prompt for coordinator |
161
+ | `swarm_review_feedback` | Send approval/rejection to worker (3-strike) |
98
162
 
99
163
  ### Skills (Knowledge Injection)
100
164
 
@@ -105,73 +169,7 @@ ollama pull mxbai-embed-large
105
169
  | `skills_read` | Read skill content |
106
170
  | `skills_create` | Create new skill |
107
171
 
108
- ## Checkpoint & Recovery
109
-
110
- Ensures work survives context compaction or crashes. Proven by 9 integration tests.
111
-
112
- ### Auto-Checkpoint Milestones
113
-
114
- When `swarm_progress` reports 25%, 50%, or 75% completion, a checkpoint is automatically saved to PGLite:
115
-
116
- ```typescript
117
- // Stored in .swarm-mail/ directory (no external database needed)
118
- {
119
- epic_id: "hv-123",
120
- cell_id: "hv-123.1",
121
- strategy: "file-based",
122
- files: ["src/auth.ts", "src/middleware.ts"],
123
- progress_percent: 50,
124
- directives: {
125
- shared_context: "OAuth implementation notes",
126
- skills_to_load: ["testing-patterns"],
127
- coordinator_notes: "Watch for race conditions"
128
- },
129
- recovery: {
130
- last_checkpoint: 1234567890,
131
- files_modified: ["src/auth.ts"],
132
- error_context: "Optional: error details if checkpoint during error"
133
- }
134
- }
135
- ```
136
-
137
- ### Tools
138
-
139
- **swarm_checkpoint** - Manually save a checkpoint:
140
- ```typescript
141
- swarm_checkpoint({
142
- project_key: "/abs/path",
143
- agent_name: "WorkerA",
144
- cell_id: "hv-123.1",
145
- epic_id: "hv-123",
146
- files_modified: ["src/auth.ts"],
147
- progress_percent: 30,
148
- directives: { shared_context: "..." },
149
- error_context: "Optional"
150
- })
151
- ```
152
-
153
- **swarm_recover** - Resume from last checkpoint:
154
- ```typescript
155
- swarm_recover({
156
- project_key: "/abs/path",
157
- epic_id: "hv-123"
158
- })
159
- // Returns:
160
- // {
161
- // found: true,
162
- // context: { epic_id, cell_id, files, strategy, directives, recovery },
163
- // age_seconds: 120
164
- // }
165
- ```
166
-
167
- ### Failure Handling
168
-
169
- Checkpoint failures are **non-fatal**—work continues even if checkpointing fails. Prevents infrastructure from blocking actual work.
170
-
171
- ## Bundled Skills
172
-
173
- Located in `global-skills/`:
174
-
172
+ **Bundled skills:**
175
173
  - **testing-patterns** - 25 dependency-breaking techniques, characterization tests
176
174
  - **swarm-coordination** - Multi-agent decomposition, file reservations
177
175
  - **cli-builder** - Argument parsing, help text, subcommands
@@ -179,85 +177,38 @@ Located in `global-skills/`:
179
177
  - **learning-systems** - Confidence decay, pattern maturity
180
178
  - **skill-creator** - Meta-skill for creating new skills
181
179
 
182
- ## Architecture
183
-
184
- ```
185
- src/
186
- ├── hive.ts # Hive integration (work item tracking)
187
- ├── agent-mail.ts # Agent Mail tools (legacy MCP wrapper)
188
- ├── swarm-mail.ts # Swarm Mail tools (new, uses swarm-mail package)
189
- ├── swarm.ts # Swarm orchestration tools
190
- ├── swarm-orchestrate.ts # Coordinator logic
191
- ├── swarm-decompose.ts # Decomposition strategies
192
- ├── swarm-strategies.ts # Strategy selection
193
- ├── skills.ts # Skills system
194
- ├── learning.ts # Pattern maturity, outcomes
195
- ├── anti-patterns.ts # Anti-pattern detection
196
- ├── structured.ts # JSON parsing utilities
197
- ├── mandates.ts # Mandate system
198
- └── schemas/ # Zod schemas
199
- ```
200
-
201
- ## Dependencies
202
-
203
- ### Required
204
-
205
- | Dependency | Purpose |
206
- |------------|---------|
207
- | [OpenCode](https://opencode.ai) | AI coding agent (the plugin runs inside OpenCode) |
208
-
209
- ### Required for Semantic Memory
180
+ ---
210
181
 
211
- | Dependency | Purpose | Install |
212
- |------------|---------|---------|
213
- | [Ollama](https://ollama.ai) | Embedding model for semantic memory | `brew install ollama && ollama serve & && ollama pull mxbai-embed-large` |
182
+ ## What's New in v0.32
214
183
 
215
- ### Optional (Highly Recommended)
184
+ - **libSQL storage** (embedded SQLite) replaced PGLite - no external DB needed
185
+ - **95% integration test coverage** - checkpoint/recovery proven with 9 tests
186
+ - **Coordinator review gate** - `swarm_review` + `swarm_review_feedback` with 3-strike rule
187
+ - **Smart ID resolution** - partial hashes work like git (`mjhgw0g` matches `opencode-swarm-monorepo-lf2p4u-mjhgw0ggt00`)
188
+ - **Auto-sync at key events** - no more forgotten `hive_sync` calls
189
+ - **Project-prefixed cell IDs** - `swarm-mail-xxx` instead of generic `bd-xxx`
216
190
 
217
- These tools significantly enhance the swarm experience:
191
+ ---
218
192
 
219
- | Tool | Purpose | Install |
220
- |------|---------|---------|
221
- | [CASS](https://github.com/Dicklesworthstone/coding_agent_session_search) | Historical context - queries past sessions for similar decompositions | See below |
222
- | [UBS](https://github.com/Dicklesworthstone/ultimate_bug_scanner) | Bug scanning - runs on subtask completion to catch issues | See below |
223
-
224
- > **Note:** Semantic memory is now embedded in the plugin. No separate installation needed - just install Ollama for vector embeddings.
225
-
226
- #### Installing CASS
193
+ ## Architecture
227
194
 
228
- ```bash
229
- # Clone and install
230
- git clone https://github.com/Dicklesworthstone/coding_agent_session_search
231
- cd coding_agent_session_search
232
- pip install -e .
195
+ Built on [swarm-mail](../swarm-mail) event sourcing primitives. Data stored in libSQL (embedded SQLite).
233
196
 
234
- # Build the index (run periodically to index new sessions)
235
- cass index
236
197
  ```
237
-
238
- #### Installing UBS
239
-
240
- ```bash
241
- # Clone and install
242
- git clone https://github.com/Dicklesworthstone/ultimate_bug_scanner
243
- cd ultimate_bug_scanner
244
- pip install -e .
198
+ src/
199
+ ├── hive.ts # Work item tracking integration
200
+ ├── swarm-mail.ts # Agent coordination tools
201
+ ├── swarm-orchestrate.ts # Coordinator logic (spawns workers)
202
+ ├── swarm-decompose.ts # Task decomposition strategies
203
+ ├── swarm-review.ts # Review gate for completed work
204
+ ├── skills.ts # Knowledge injection system
205
+ ├── learning.ts # Pattern maturity, outcomes
206
+ ├── anti-patterns.ts # Anti-pattern detection
207
+ ├── structured.ts # JSON parsing utilities
208
+ └── schemas/ # Zod validation schemas
245
209
  ```
246
210
 
247
- **Why install these?**
248
-
249
- - **CASS** - When you run `/swarm "Add OAuth"`, the coordinator queries CASS for similar past tasks. Without it, decomposition is based only on the current task description.
250
- - **UBS** - Every `swarm_complete` runs UBS to scan for bugs. Without it, you lose automatic bug detection.
251
- - **Ollama** - Enables vector similarity search for semantic memory. Without it, memory falls back to full-text search (still functional, less semantic).
252
-
253
- Run `swarm doctor` to check which dependencies are installed.
254
-
255
- ### npm Dependencies
256
-
257
- - [swarm-mail](../swarm-mail) - Event sourcing primitives (workspace dependency)
258
- - [@opencode-ai/plugin](https://www.npmjs.com/package/@opencode-ai/plugin) - OpenCode plugin API
259
- - [effect](https://effect.website) - Effect-TS for type-safe composition
260
- - [zod](https://zod.dev) - Schema validation
211
+ ---
261
212
 
262
213
  ## Development
263
214
 
@@ -273,32 +224,29 @@ bun test
273
224
  bun run typecheck
274
225
  ```
275
226
 
227
+ ---
228
+
276
229
  ## CLI
277
230
 
278
231
  ```bash
279
232
  swarm setup # Install and configure
280
- swarm doctor # Check dependencies
233
+ swarm doctor # Check dependencies (CASS, UBS, Ollama)
281
234
  swarm init # Initialize hive in project
282
235
  swarm config # Show config file paths
283
236
  ```
284
237
 
285
- ## Roadmap
286
-
287
- ### Planned Features
238
+ ---
288
239
 
289
- - **Enhanced Learning** - Pattern extraction from successful/failed decompositions
290
- - **Swarm Observability** - Real-time visualization of agent coordination
291
- - **Advanced Strategies** - Risk-based decomposition, critical path optimization
292
- - **Multi-Project Coordination** - Cross-repo dependencies and shared context
293
- - **Learning Export/Import** - Share pattern maturity across teams
240
+ ## Further Reading
294
241
 
295
- ### Experimental
242
+ - **[Full Docs](https://swarmtools.ai/docs)** - Deep dives, patterns, best practices
243
+ - **[swarm-mail Package](../swarm-mail)** - Event sourcing primitives, database layer
244
+ - **[AGENTS.md](../../AGENTS.md)** - Monorepo guide, testing strategy, TDD workflow
296
245
 
297
- - **Auto-healing Swarms** - Agents detect and recover from blockers autonomously
298
- - **Semantic Code Search** - Vector-based codebase exploration for decomposition context
299
- - **Prevention Pipeline Integration** - Auto-generate prevention patterns from debug sessions
246
+ > *"High-variability sequencing of whole-task problems."*
247
+ > 4C/ID Instructional Design Model
300
248
 
301
- See [swarmtools.ai/docs](https://swarmtools.ai/docs) for latest updates and detailed guides.
249
+ ---
302
250
 
303
251
  ## License
304
252
 
package/bin/swarm.test.ts CHANGED
@@ -160,4 +160,35 @@ describe("File operation helpers", () => {
160
160
  expect(logger.logs.length).toBe(0);
161
161
  });
162
162
  });
163
+
164
+ describe("getResearcherAgent", () => {
165
+ // Mock implementation for testing - will match actual implementation
166
+ function getResearcherAgent(model: string): string {
167
+ return `---
168
+ name: swarm-researcher
169
+ description: Research agent for discovering and documenting context
170
+ model: ${model}
171
+ ---
172
+
173
+ READ-ONLY research agent. Never modifies code - only gathers intel and stores findings.`;
174
+ }
175
+
176
+ test("includes model in frontmatter", () => {
177
+ const template = getResearcherAgent("anthropic/claude-haiku-4-5");
178
+
179
+ expect(template).toContain("model: anthropic/claude-haiku-4-5");
180
+ });
181
+
182
+ test("emphasizes READ-ONLY nature", () => {
183
+ const template = getResearcherAgent("anthropic/claude-haiku-4-5");
184
+
185
+ expect(template).toContain("READ-ONLY");
186
+ });
187
+
188
+ test("includes agent name in frontmatter", () => {
189
+ const template = getResearcherAgent("anthropic/claude-haiku-4-5");
190
+
191
+ expect(template).toContain("name: swarm-researcher");
192
+ });
193
+ });
163
194
  });