opencode-swarm-plugin 0.32.0 → 0.34.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 (55) hide show
  1. package/.hive/issues.jsonl +12 -0
  2. package/.hive/memories.jsonl +255 -1
  3. package/.turbo/turbo-build.log +9 -10
  4. package/.turbo/turbo-test.log +343 -337
  5. package/CHANGELOG.md +358 -0
  6. package/README.md +152 -179
  7. package/bin/swarm.test.ts +303 -1
  8. package/bin/swarm.ts +473 -16
  9. package/dist/compaction-hook.d.ts +1 -1
  10. package/dist/compaction-hook.d.ts.map +1 -1
  11. package/dist/index.d.ts +112 -0
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +12380 -131
  14. package/dist/logger.d.ts +34 -0
  15. package/dist/logger.d.ts.map +1 -0
  16. package/dist/observability-tools.d.ts +116 -0
  17. package/dist/observability-tools.d.ts.map +1 -0
  18. package/dist/plugin.js +12254 -119
  19. package/dist/skills.d.ts.map +1 -1
  20. package/dist/swarm-orchestrate.d.ts +105 -0
  21. package/dist/swarm-orchestrate.d.ts.map +1 -1
  22. package/dist/swarm-prompts.d.ts +113 -2
  23. package/dist/swarm-prompts.d.ts.map +1 -1
  24. package/dist/swarm-research.d.ts +127 -0
  25. package/dist/swarm-research.d.ts.map +1 -0
  26. package/dist/swarm-review.d.ts.map +1 -1
  27. package/dist/swarm.d.ts +73 -1
  28. package/dist/swarm.d.ts.map +1 -1
  29. package/evals/compaction-resumption.eval.ts +289 -0
  30. package/evals/coordinator-behavior.eval.ts +307 -0
  31. package/evals/fixtures/compaction-cases.ts +350 -0
  32. package/evals/scorers/compaction-scorers.ts +305 -0
  33. package/evals/scorers/index.ts +12 -0
  34. package/examples/plugin-wrapper-template.ts +297 -8
  35. package/package.json +6 -2
  36. package/src/compaction-hook.test.ts +617 -1
  37. package/src/compaction-hook.ts +291 -18
  38. package/src/index.ts +54 -1
  39. package/src/logger.test.ts +189 -0
  40. package/src/logger.ts +135 -0
  41. package/src/observability-tools.test.ts +346 -0
  42. package/src/observability-tools.ts +594 -0
  43. package/src/skills.integration.test.ts +137 -1
  44. package/src/skills.test.ts +42 -1
  45. package/src/skills.ts +8 -4
  46. package/src/swarm-orchestrate.test.ts +123 -0
  47. package/src/swarm-orchestrate.ts +183 -0
  48. package/src/swarm-prompts.test.ts +553 -1
  49. package/src/swarm-prompts.ts +406 -4
  50. package/src/swarm-research.integration.test.ts +544 -0
  51. package/src/swarm-research.test.ts +698 -0
  52. package/src/swarm-research.ts +472 -0
  53. package/src/swarm-review.test.ts +177 -0
  54. package/src/swarm-review.ts +12 -47
  55. package/src/swarm.ts +6 -3
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,38 +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
- > *"High-variability sequencing of whole-task problems."*
31
- > — 4C/ID Instructional Design Model
60
+ Without Ollama, memory falls back to full-text search (still works, just less semantic).
61
+
62
+ ### Historical Context (CASS)
32
63
 
33
- ## Features
64
+ Queries past AI sessions for similar decompositions:
65
+
66
+ ```bash
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
71
+ ```
34
72
 
35
- - **Swarm Coordination** - Break tasks into parallel subtasks, spawn worker agents
36
- - **Hive Integration** - Git-backed work item tracking with atomic epic creation
37
- - **Agent Mail** - Inter-agent messaging with file reservations
38
- - **Learning System** - Pattern maturity, anti-pattern detection, confidence decay
39
- - **Skills System** - Knowledge injection with bundled and custom skills
40
- - **Checkpoint & Recovery** - Auto-checkpoint at 25/50/75%, survive context death (9 integration tests ✅)
73
+ ### Bug Scanning (UBS)
41
74
 
42
- ## Usage
75
+ Auto-runs on subtask completion:
43
76
 
44
77
  ```bash
45
- /swarm "Add user authentication with OAuth"
78
+ git clone https://github.com/Dicklesworthstone/ultimate_bug_scanner
79
+ cd ultimate_bug_scanner
80
+ pip install -e .
46
81
  ```
47
82
 
48
- ## Tools Provided
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
49
120
 
50
121
  ### Hive (Work Item Tracking)
51
122
 
@@ -73,31 +144,21 @@ ollama pull mxbai-embed-large
73
144
  | `swarmmail_reserve` | Reserve files for exclusive edit |
74
145
  | `swarmmail_release` | Release reservations |
75
146
 
76
- ### Swarm (Task Orchestration)
147
+ ### Swarm Orchestration
77
148
 
78
149
  | Tool | Purpose |
79
150
  | ------------------------------ | ----------------------------------------------- |
80
151
  | `swarm_select_strategy` | Analyze task, recommend strategy |
81
152
  | `swarm_decompose` | Generate decomposition prompt (queries CASS) |
82
- | `swarm_delegate_planning` | Delegate planning to planner subagent |
83
153
  | `swarm_validate_decomposition` | Validate response, detect conflicts |
84
- | `swarm_plan_prompt` | Generate strategy-specific decomposition prompt |
85
154
  | `swarm_subtask_prompt` | Generate worker agent prompt |
86
- | `swarm_spawn_subtask` | Prepare subtask for Task tool spawning |
87
- | `swarm_evaluation_prompt` | Generate self-evaluation prompt |
88
- | `swarm_init` | Initialize swarm session |
89
155
  | `swarm_status` | Get swarm progress by epic ID |
90
- | `swarm_progress` | Report subtask progress to coordinator |
156
+ | `swarm_progress` | Report subtask progress |
91
157
  | `swarm_complete` | Complete subtask (releases reservations) |
92
- | `swarm_record_outcome` | Record outcome for learning |
93
158
  | `swarm_checkpoint` | Save progress snapshot (auto at 25/50/75%) |
94
- | `swarm_recover` | Resume from checkpoint (returns full context) |
95
- | `swarm_learn` | Extract learnings from outcome |
96
- | `swarm_broadcast` | Send message to all active agents |
97
- | `swarm_accumulate_error` | Track recurring errors (3-strike system) |
98
- | `swarm_check_strikes` | Check if error threshold reached |
99
- | `swarm_get_error_context` | Get context for error pattern |
100
- | `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) |
101
162
 
102
163
  ### Skills (Knowledge Injection)
103
164
 
@@ -108,73 +169,7 @@ ollama pull mxbai-embed-large
108
169
  | `skills_read` | Read skill content |
109
170
  | `skills_create` | Create new skill |
110
171
 
111
- ## Checkpoint & Recovery
112
-
113
- Ensures work survives context compaction or crashes. Proven by 9 integration tests.
114
-
115
- ### Auto-Checkpoint Milestones
116
-
117
- When `swarm_progress` reports 25%, 50%, or 75% completion, a checkpoint is automatically saved to libSQL:
118
-
119
- ```typescript
120
- // Stored in system temp directory (no external database needed)
121
- {
122
- epic_id: "hv-123",
123
- cell_id: "hv-123.1",
124
- strategy: "file-based",
125
- files: ["src/auth.ts", "src/middleware.ts"],
126
- progress_percent: 50,
127
- directives: {
128
- shared_context: "OAuth implementation notes",
129
- skills_to_load: ["testing-patterns"],
130
- coordinator_notes: "Watch for race conditions"
131
- },
132
- recovery: {
133
- last_checkpoint: 1234567890,
134
- files_modified: ["src/auth.ts"],
135
- error_context: "Optional: error details if checkpoint during error"
136
- }
137
- }
138
- ```
139
-
140
- ### Tools
141
-
142
- **swarm_checkpoint** - Manually save a checkpoint:
143
- ```typescript
144
- swarm_checkpoint({
145
- project_key: "/abs/path",
146
- agent_name: "WorkerA",
147
- cell_id: "hv-123.1",
148
- epic_id: "hv-123",
149
- files_modified: ["src/auth.ts"],
150
- progress_percent: 30,
151
- directives: { shared_context: "..." },
152
- error_context: "Optional"
153
- })
154
- ```
155
-
156
- **swarm_recover** - Resume from last checkpoint:
157
- ```typescript
158
- swarm_recover({
159
- project_key: "/abs/path",
160
- epic_id: "hv-123"
161
- })
162
- // Returns:
163
- // {
164
- // found: true,
165
- // context: { epic_id, cell_id, files, strategy, directives, recovery },
166
- // age_seconds: 120
167
- // }
168
- ```
169
-
170
- ### Failure Handling
171
-
172
- Checkpoint failures are **non-fatal**—work continues even if checkpointing fails. Prevents infrastructure from blocking actual work.
173
-
174
- ## Bundled Skills
175
-
176
- Located in `global-skills/`:
177
-
172
+ **Bundled skills:**
178
173
  - **testing-patterns** - 25 dependency-breaking techniques, characterization tests
179
174
  - **swarm-coordination** - Multi-agent decomposition, file reservations
180
175
  - **cli-builder** - Argument parsing, help text, subcommands
@@ -182,85 +177,45 @@ Located in `global-skills/`:
182
177
  - **learning-systems** - Confidence decay, pattern maturity
183
178
  - **skill-creator** - Meta-skill for creating new skills
184
179
 
185
- ## Architecture
186
-
187
- ```
188
- src/
189
- ├── hive.ts # Hive integration (work item tracking)
190
- ├── agent-mail.ts # Agent Mail tools (legacy MCP wrapper)
191
- ├── swarm-mail.ts # Swarm Mail tools (new, uses swarm-mail package)
192
- ├── swarm.ts # Swarm orchestration tools
193
- ├── swarm-orchestrate.ts # Coordinator logic
194
- ├── swarm-decompose.ts # Decomposition strategies
195
- ├── swarm-strategies.ts # Strategy selection
196
- ├── skills.ts # Skills system
197
- ├── learning.ts # Pattern maturity, outcomes
198
- ├── anti-patterns.ts # Anti-pattern detection
199
- ├── structured.ts # JSON parsing utilities
200
- ├── mandates.ts # Mandate system
201
- └── schemas/ # Zod schemas
202
- ```
203
-
204
- ## Dependencies
180
+ ---
205
181
 
206
- ### Required
182
+ ## What's New in v0.33
207
183
 
208
- | Dependency | Purpose |
209
- |------------|---------|
210
- | [OpenCode](https://opencode.ai) | AI coding agent (the plugin runs inside OpenCode) |
184
+ - **Pino logging infrastructure** - Structured JSON logs with daily rotation to `~/.config/swarm-tools/logs/`
185
+ - **Compaction hook instrumented** - 14 log points across all phases (START, GATHER, RENDER, DECIDE, COMPLETE)
186
+ - **`swarm log` CLI** - Query/tail logs with module, level, and time filters
187
+ - **Analytics queries** - 5 pre-built queries based on Four Golden Signals (latency, traffic, errors, saturation, conflicts)
211
188
 
212
- ### Required for Semantic Memory
189
+ ### v0.32
213
190
 
214
- | Dependency | Purpose | Install |
215
- |------------|---------|---------|
216
- | [Ollama](https://ollama.ai) | Embedding model for semantic memory | `brew install ollama && ollama serve & && ollama pull mxbai-embed-large` |
191
+ - **libSQL storage** (embedded SQLite) replaced PGLite - no external DB needed
192
+ - **95% integration test coverage** - checkpoint/recovery proven with 9 tests
193
+ - **Coordinator review gate** - `swarm_review` + `swarm_review_feedback` with 3-strike rule
194
+ - **Smart ID resolution** - partial hashes work like git (`mjhgw0g` matches `opencode-swarm-monorepo-lf2p4u-mjhgw0ggt00`)
195
+ - **Auto-sync at key events** - no more forgotten `hive_sync` calls
196
+ - **Project-prefixed cell IDs** - `swarm-mail-xxx` instead of generic `bd-xxx`
217
197
 
218
- ### Optional (Highly Recommended)
198
+ ---
219
199
 
220
- These tools significantly enhance the swarm experience:
221
-
222
- | Tool | Purpose | Install |
223
- |------|---------|---------|
224
- | [CASS](https://github.com/Dicklesworthstone/coding_agent_session_search) | Historical context - queries past sessions for similar decompositions | See below |
225
- | [UBS](https://github.com/Dicklesworthstone/ultimate_bug_scanner) | Bug scanning - runs on subtask completion to catch issues | See below |
226
-
227
- > **Note:** Semantic memory is now embedded in the plugin. No separate installation needed - just install Ollama for vector embeddings.
228
-
229
- #### Installing CASS
200
+ ## Architecture
230
201
 
231
- ```bash
232
- # Clone and install
233
- git clone https://github.com/Dicklesworthstone/coding_agent_session_search
234
- cd coding_agent_session_search
235
- pip install -e .
202
+ Built on [swarm-mail](../swarm-mail) event sourcing primitives. Data stored in libSQL (embedded SQLite).
236
203
 
237
- # Build the index (run periodically to index new sessions)
238
- cass index
239
204
  ```
240
-
241
- #### Installing UBS
242
-
243
- ```bash
244
- # Clone and install
245
- git clone https://github.com/Dicklesworthstone/ultimate_bug_scanner
246
- cd ultimate_bug_scanner
247
- pip install -e .
205
+ src/
206
+ ├── hive.ts # Work item tracking integration
207
+ ├── swarm-mail.ts # Agent coordination tools
208
+ ├── swarm-orchestrate.ts # Coordinator logic (spawns workers)
209
+ ├── swarm-decompose.ts # Task decomposition strategies
210
+ ├── swarm-review.ts # Review gate for completed work
211
+ ├── skills.ts # Knowledge injection system
212
+ ├── learning.ts # Pattern maturity, outcomes
213
+ ├── anti-patterns.ts # Anti-pattern detection
214
+ ├── structured.ts # JSON parsing utilities
215
+ └── schemas/ # Zod validation schemas
248
216
  ```
249
217
 
250
- **Why install these?**
251
-
252
- - **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.
253
- - **UBS** - Run manually on code to catch bugs before commit. Not integrated into swarm workflow but recommended for pre-commit validation.
254
- - **Ollama** - Enables vector similarity search for semantic memory. Without it, memory falls back to full-text search (still functional, less semantic).
255
-
256
- Run `swarm doctor` to check which dependencies are installed.
257
-
258
- ### npm Dependencies
259
-
260
- - [swarm-mail](../swarm-mail) - Event sourcing primitives (workspace dependency)
261
- - [@opencode-ai/plugin](https://www.npmjs.com/package/@opencode-ai/plugin) - OpenCode plugin API
262
- - [effect](https://effect.website) - Effect-TS for type-safe composition
263
- - [zod](https://zod.dev) - Schema validation
218
+ ---
264
219
 
265
220
  ## Development
266
221
 
@@ -276,32 +231,50 @@ bun test
276
231
  bun run typecheck
277
232
  ```
278
233
 
234
+ ---
235
+
279
236
  ## CLI
280
237
 
281
238
  ```bash
282
239
  swarm setup # Install and configure
283
- swarm doctor # Check dependencies
240
+ swarm doctor # Check dependencies (CASS, UBS, Ollama)
284
241
  swarm init # Initialize hive in project
285
242
  swarm config # Show config file paths
286
243
  ```
287
244
 
288
- ## Roadmap
245
+ ### Logging & Observability
289
246
 
290
- ### Planned Features
247
+ Structured Pino logging with daily rotation:
291
248
 
292
- - **Enhanced Learning** - Pattern extraction from successful/failed decompositions
293
- - **Swarm Observability** - Real-time visualization of agent coordination
294
- - **Advanced Strategies** - Risk-based decomposition, critical path optimization
295
- - **Multi-Project Coordination** - Cross-repo dependencies and shared context
296
- - **Learning Export/Import** - Share pattern maturity across teams
249
+ ```bash
250
+ # Enable pretty logging during development
251
+ SWARM_LOG_PRETTY=1 opencode
252
+
253
+ # Query logs
254
+ swarm log # Tail recent logs
255
+ swarm log compaction # Filter by module
256
+ swarm log --level warn # Filter by level (warn+)
257
+ swarm log --since 1h # Last hour
258
+ swarm log --json | jq # Pipe to jq for analysis
259
+ ```
297
260
 
298
- ### Experimental
261
+ **Log files:** `~/.config/swarm-tools/logs/`
262
+ - `swarm.1log`, `swarm.2log`, ... (main logs)
263
+ - `compaction.1log`, ... (module-specific)
264
+ - Daily rotation, 14-day retention
299
265
 
300
- - **Auto-healing Swarms** - Agents detect and recover from blockers autonomously
301
- - **Semantic Code Search** - Vector-based codebase exploration for decomposition context
302
- - **Prevention Pipeline Integration** - Auto-generate prevention patterns from debug sessions
266
+ ---
267
+
268
+ ## Further Reading
269
+
270
+ - **[Full Docs](https://swarmtools.ai/docs)** - Deep dives, patterns, best practices
271
+ - **[swarm-mail Package](../swarm-mail)** - Event sourcing primitives, database layer
272
+ - **[AGENTS.md](../../AGENTS.md)** - Monorepo guide, testing strategy, TDD workflow
273
+
274
+ > *"High-variability sequencing of whole-task problems."*
275
+ > — 4C/ID Instructional Design Model
303
276
 
304
- See [swarmtools.ai/docs](https://swarmtools.ai/docs) for latest updates and detailed guides.
277
+ ---
305
278
 
306
279
  ## License
307
280