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/CHANGELOG.md CHANGED
@@ -1,5 +1,363 @@
1
1
  # opencode-swarm-plugin
2
2
 
3
+ ## 0.34.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`704c366`](https://github.com/joelhooks/swarm-tools/commit/704c36690fb6fd52cfb9222ddeef3b663dfdb9ed) Thanks [@joelhooks](https://github.com/joelhooks)! - ## 🪵 Pino Logging Infrastructure
8
+
9
+ > "You can't improve what you can't measure." — Peter Drucker
10
+
11
+ Finally, visibility into what the swarm is actually doing.
12
+
13
+ ### What's New
14
+
15
+ **Structured Logging with Pino**
16
+
17
+ - Daily log rotation via `pino-roll` (14-day retention)
18
+ - Logs to `~/.config/swarm-tools/logs/`
19
+ - Module-specific log files (e.g., `compaction.1log`, `swarm.1log`)
20
+ - Pretty mode for development: `SWARM_LOG_PRETTY=1`
21
+
22
+ **Compaction Hook Instrumented**
23
+
24
+ - 14 strategic log points across all phases
25
+ - START: session context, trigger reason
26
+ - GATHER: per-source timing (hive, swarm-mail, skills)
27
+ - DETECT/INJECT: confidence scores, context decisions
28
+ - COMPLETE: duration, success, what was injected
29
+
30
+ **New CLI: `swarm log`**
31
+
32
+ ```bash
33
+ swarm log # Tail recent logs
34
+ swarm log compaction # Filter by module
35
+ swarm log --level warn # Filter by severity
36
+ swarm log --since 1h # Last hour only
37
+ swarm log --json | jq # Pipe to jq for analysis
38
+ ```
39
+
40
+ ### Why This Matters
41
+
42
+ The compaction hook does a LOT of work with zero visibility:
43
+
44
+ - Context injection decisions
45
+ - Data gathering from multiple sources
46
+ - Template rendering and size calculations
47
+
48
+ Now you can answer: "What did compaction do on the last run?"
49
+
50
+ ### Technical Details
51
+
52
+ - Pino + pino-roll for async, non-blocking file writes
53
+ - Child loggers for module namespacing
54
+ - Lazy initialization pattern for test isolation
55
+ - 56 new tests (10 logger + 18 compaction + 28 CLI)
56
+
57
+ Complements existing `DEBUG=swarm:*` env var approach — Pino for structured file logs, debug for stderr filtering.
58
+
59
+ ### Patch Changes
60
+
61
+ - [`b5792bd`](https://github.com/joelhooks/swarm-tools/commit/b5792bd5f6aa4bf3ad9757fe351bc144e84f09af) Thanks [@joelhooks](https://github.com/joelhooks)! - ## 🎯 Coordinators Remember Who They Are
62
+
63
+ Fixed the compaction bug where coordinators lost their identity after context compression.
64
+
65
+ **The Problem:**
66
+ After compaction, coordinators would wake up and start doing worker tasks directly (running tests, editing files) instead of spawning workers. The injected context said "you are a coordinator" but gave worker-style resume commands.
67
+
68
+ **The Fix:**
69
+ `buildDynamicSwarmState()` now generates coordinator-focused context:
70
+
71
+ ```
72
+ ## 🎯 YOU ARE THE COORDINATOR
73
+
74
+ **Primary role:** Orchestrate workers, review their output, unblock dependencies.
75
+ **Spawn workers** for implementation tasks - don't do them yourself.
76
+
77
+ **RESUME STEPS:**
78
+ 1. Check swarm status: `swarm_status(epic_id="bd-actual-id", ...)`
79
+ 2. Check inbox: `swarmmail_inbox(limit=5)`
80
+ 3. For in_progress subtasks: Review with `swarm_review`
81
+ 4. For open subtasks: Spawn workers with `swarm_spawn_subtask`
82
+ 5. For blocked subtasks: Investigate and unblock
83
+ ```
84
+
85
+ Also captures specific swarm state during detection:
86
+
87
+ - Epic ID and title (not placeholders)
88
+ - Subtask counts by status
89
+ - Actual project path
90
+
91
+ **New eval infrastructure:**
92
+
93
+ - `coordinator-behavior.eval.ts` - LLM-as-judge eval testing whether Claude actually behaves like a coordinator given the injected context
94
+ - Scorers for coordinator tools, avoiding worker behaviors, and coordinator mindset
95
+
96
+ > "The coordinator's job is to keep the swarm cooking, not to cook themselves."
97
+
98
+ - Updated dependencies [[`a78a40d`](https://github.com/joelhooks/swarm-tools/commit/a78a40de32eb34d1738b208f2a36929a4ab6cb81), [`5a7c084`](https://github.com/joelhooks/swarm-tools/commit/5a7c084514297b5b9ca5df9459a74f18eb805b8a)]:
99
+ - swarm-mail@1.5.0
100
+
101
+ ## 0.33.0
102
+
103
+ ### Minor Changes
104
+
105
+ - [`c41abcf`](https://github.com/joelhooks/swarm-tools/commit/c41abcfa37292b72fe41e0cf9d25c6612ae75fa2) Thanks [@joelhooks](https://github.com/joelhooks)! - ## 🎓 Skills Grow Up: Discovery Moves to OpenCode
106
+
107
+ > _"The best code is no code at all. Every new line of code you willingly bring into the world is code that has to be debugged, code that has to be read and understood, code that has to be supported."_
108
+ > — Jeff Atwood
109
+
110
+ Skills outgrew the nest. OpenCode is shipping native skills support following the [Agent Skills spec](https://spec.agentskills.com/), and our discovery tools are now redundant. Time to deprecate the scaffolding and let the platform handle what it does best.
111
+
112
+ ### What Changed
113
+
114
+ **Deprecated Tools** (soft deprecation with console warnings):
115
+
116
+ - `skills_list` - OpenCode will handle discovery natively
117
+ - `skills_use` - OpenCode will handle loading via `use skill <name>` syntax
118
+ - `skills_read` - OpenCode will handle resource access transparently
119
+ - `skills_execute` - OpenCode will handle script execution in skill context
120
+
121
+ **Authoring Tools Kept** (fully functional, no changes):
122
+
123
+ - `skills_create` - Create new skills with SKILL.md template
124
+ - `skills_update` - Update existing skill content
125
+ - `skills_init` - Initialize skills directory in projects
126
+ - `skills_add_script` - Add executable scripts to skills
127
+ - `skills_delete` - Remove project skills
128
+
129
+ **Bundled Skills** - All 6 global skills remain intact and spec-compliant:
130
+
131
+ - `testing-patterns` - Feathers seams + Beck's 4 rules
132
+ - `swarm-coordination` - Multi-agent task orchestration
133
+ - `cli-builder` - Command-line interface patterns
134
+ - `learning-systems` - Confidence decay, pattern maturity
135
+ - `skill-creator` - Meta-skill for authoring new skills
136
+ - `system-design` - Architecture decision frameworks
137
+
138
+ ### Why It Matters
139
+
140
+ **Before:** Two overlapping skill systems causing confusion. Agents could use plugin tools OR OpenCode's native syntax, with different behavior and semantics.
141
+
142
+ **After:** One canonical path. OpenCode owns discovery and loading. Plugin owns authoring and validation. Clean separation of concerns.
143
+
144
+ **Benefits:**
145
+
146
+ - No tool conflicts between plugin and platform
147
+ - Native OpenCode syntax (`use skill testing-patterns`) works seamlessly
148
+ - Simpler mental model for users
149
+ - Authoring tools remain for creating spec-compliant skills
150
+
151
+ ### Migration Path
152
+
153
+ **For Discovery/Loading:**
154
+
155
+ ```typescript
156
+ // OLD (deprecated, still works but warns)
157
+ skills_list()
158
+ skills_use(name="testing-patterns")
159
+
160
+ // NEW (OpenCode native syntax)
161
+ use skill testing-patterns
162
+ use skill cli-builder with "building argument parser"
163
+ ```
164
+
165
+ **For Authoring (no change needed):**
166
+
167
+ ```typescript
168
+ // Still fully supported
169
+ skills_create((name = "my-skill"), (description = "Domain expertise"));
170
+ skills_update((name = "my-skill"), (content = "Updated SKILL.md"));
171
+ skills_add_script(
172
+ (skill_name = "my-skill"),
173
+ (script_name = "validate.ts"),
174
+ (content = "...")
175
+ );
176
+ ```
177
+
178
+ ### Backward Compatibility
179
+
180
+ **Yes, with warnings.** Deprecated tools continue to function but emit console warnings directing users to OpenCode's native syntax. No breaking changes in this release.
181
+
182
+ Future major version (v1.0) will remove deprecated discovery tools entirely. Authoring tools remain permanent.
183
+
184
+ ### What This Means for Bundled Skills
185
+
186
+ Nothing changes. All 6 global skills ship with the plugin and are accessible via OpenCode's native `use skill <name>` syntax. They follow the Agent Skills spec and work identically whether loaded via deprecated plugin tools or native OpenCode.
187
+
188
+ The `global-skills/` directory remains the canonical source for our curated skill library.
189
+
190
+ - [`4feebaf`](https://github.com/joelhooks/swarm-tools/commit/4feebafed61caa8e2e8729b44bd415d71afd6834) Thanks [@joelhooks](https://github.com/joelhooks)! - ## 🐝 LLM-Powered Compaction: The Swarm Remembers
191
+
192
+ > "The best way to predict the future is to invent it." — Alan Kay
193
+
194
+ Compaction just got smarter. Instead of static "here's what to preserve" instructions, the swarm now **generates dynamic continuation prompts** with actual state data.
195
+
196
+ **What changed:**
197
+
198
+ The `experimental.session.compacting` hook now uses a three-level fallback chain:
199
+
200
+ 1. **LLM-Generated Prompt** (NEW) - Queries actual swarm state (cells, epics, subtasks), shells out to `opencode run -m <liteModel>` to generate a structured continuation prompt with real IDs, real status, real next actions
201
+ 2. **Static Context** - Falls back to `SWARM_COMPACTION_CONTEXT` if LLM fails
202
+ 3. **Detection Fallback** - For low-confidence swarm detection, injects `SWARM_DETECTION_FALLBACK`
203
+ 4. **None** - No injection if no swarm evidence
204
+
205
+ **Progressive Enhancement:**
206
+
207
+ Uses OpenCode PR #5907's new `output.prompt` API when available:
208
+
209
+ ```typescript
210
+ if ("prompt" in output) {
211
+ output.prompt = llmGeneratedPrompt; // Replaces entire compaction prompt
212
+ } else {
213
+ output.context.push(llmGeneratedPrompt); // Old API fallback
214
+ }
215
+ ```
216
+
217
+ **New interfaces:**
218
+
219
+ - `SwarmStateSnapshot` - Structured state for LLM input
220
+ - `querySwarmState()` - Queries cells via swarm CLI
221
+ - `generateCompactionPrompt()` - Shells out to lite model (30s timeout)
222
+
223
+ **Why it matters:**
224
+
225
+ Before: "Hey, you should preserve swarm state" (agent has to figure out what that means)
226
+ After: "Here's epic bd-xyz with 3/5 subtasks done, bd-xyz.2 is blocked on auth, spawn bd-xyz.4 next"
227
+
228
+ The coordinator wakes up from compaction with **concrete data**, not instructions to go find data.
229
+
230
+ **Backward compatible:** Falls back gracefully on older OpenCode versions or LLM failures.
231
+
232
+ - [`652fd16`](https://github.com/joelhooks/swarm-tools/commit/652fd16ff424eff92ebb3f5da0599caf676de2ce) Thanks [@joelhooks](https://github.com/joelhooks)! - ## 🔭 Observability Stack MVP: See What Your Swarm Is Doing
233
+
234
+ > "You can't improve what you can't measure." — Peter Drucker
235
+
236
+ The swarm just got eyes. This release adds comprehensive observability for multi-agent coordination, answering the eternal question: "Why did my epic fail?"
237
+
238
+ ### What's New
239
+
240
+ **Structured Error Classes** (swarm-mail)
241
+
242
+ - `BaseSwarmError` with rich context: agent, bead_id, epic_id, timestamp, recent events
243
+ - Specialized errors: `ReservationError`, `CheckpointError`, `ValidationError`, `DecompositionError`
244
+ - Every error includes actionable suggestions for resolution
245
+ - Full `toJSON()` serialization for logging and debugging
246
+
247
+ **DEBUG Logging** (swarm-mail)
248
+
249
+ - `DEBUG=swarm:*` environment variable filtering
250
+ - 4 subsystems: `swarm:events`, `swarm:reservations`, `swarm:messages`, `swarm:checkpoints`
251
+ - Zero overhead when disabled
252
+
253
+ **swarm-db CLI** (swarm-mail)
254
+
255
+ ```bash
256
+ # Raw SQL queries (SELECT only, max 1000 rows)
257
+ swarm-db query "SELECT type, COUNT(*) FROM events GROUP BY type"
258
+
259
+ # Pre-built analytics
260
+ swarm-db analytics failed-decompositions --since 7d --format json
261
+
262
+ # List available analytics
263
+ swarm-db list
264
+ ```
265
+
266
+ **10 Pre-built Analytics Queries** (Four Golden Signals mapped)
267
+ | Query | What It Answers |
268
+ |-------|-----------------|
269
+ | `failed-decompositions` | Which strategies are failing? |
270
+ | `strategy-success-rates` | What's working? |
271
+ | `lock-contention` | Where are agents fighting over files? |
272
+ | `agent-activity` | Who's doing what? |
273
+ | `message-latency` | How fast is coordination? |
274
+ | `scope-violations` | Who's touching files they shouldn't? |
275
+ | `task-duration` | How long do tasks take? |
276
+ | `checkpoint-frequency` | Are agents checkpointing enough? |
277
+ | `recovery-success` | Do checkpoints actually help? |
278
+ | `human-feedback` | What are reviewers rejecting? |
279
+
280
+ **Agent-Facing Tools** (opencode-swarm-plugin)
281
+
282
+ ```typescript
283
+ // Query analytics programmatically
284
+ swarm_analytics({
285
+ query: "failed-decompositions",
286
+ since: "7d",
287
+ format: "summary",
288
+ });
289
+
290
+ // Raw SQL for power users (max 50 rows, context-safe)
291
+ swarm_query({ sql: "SELECT * FROM events WHERE type = 'task_blocked'" });
292
+
293
+ // Auto-diagnosis for debugging
294
+ swarm_diagnose({
295
+ epic_id: "bd-123",
296
+ include: ["blockers", "errors", "timeline"],
297
+ });
298
+
299
+ // Learning insights for feedback loops
300
+ swarm_insights({ scope: "epic", metrics: ["success_rate", "avg_duration"] });
301
+ ```
302
+
303
+ ### Why This Matters
304
+
305
+ Before: "The swarm failed. No idea why."
306
+ After: "Strategy X failed 80% of the time due to file conflicts. Switching to Y."
307
+
308
+ Event sourcing was already 80% of the solution. This release adds the diagnostic views to make that data actionable.
309
+
310
+ ### Test Coverage
311
+
312
+ - 588 tests passing
313
+ - 1214 assertions
314
+ - Full TDD: every feature started with a failing test
315
+
316
+ - [`ca9936d`](https://github.com/joelhooks/swarm-tools/commit/ca9936d09b749449ef3c88fd3ec8b937f6ed7c29) Thanks [@joelhooks](https://github.com/joelhooks)! - ## 🔬 Research Phase: Docs Before Decomposition
317
+
318
+ Swarm coordinators now gather documentation BEFORE breaking down tasks. No more workers fumbling through outdated API assumptions.
319
+
320
+ **What's New:**
321
+
322
+ - **swarm/researcher agent** - READ-ONLY doc gatherer that discovers tools, reads lockfiles, fetches version-specific docs, and stores findings in semantic-memory
323
+ - **Pre-decomposition research** - Coordinator analyzes task → identifies tech stack → spawns researchers → injects findings into shared_context
324
+ - **On-demand research for workers** - Workers can spawn researchers when hitting unknowns mid-task
325
+ - **`--check-upgrades` flag** - Compare installed vs latest versions from npm registry
326
+
327
+ **New Tools:**
328
+
329
+ | Tool | Purpose |
330
+ | ------------------------ | ----------------------------------------------------------- |
331
+ | `swarm_discover_tools` | Runtime discovery of available doc tools (MCP, CLI, skills) |
332
+ | `swarm_get_versions` | Parse lockfiles (npm/pnpm/yarn/bun) for installed versions |
333
+ | `swarm_spawn_researcher` | Generate researcher prompt for Task tool |
334
+ | `swarm_research_phase` | Manual trigger for research orchestration |
335
+
336
+ **Architecture:**
337
+
338
+ ```
339
+ Coordinator receives task
340
+
341
+ runResearchPhase(task, projectPath)
342
+
343
+ extractTechStack() → identify technologies
344
+ discoverDocTools() → find available tools
345
+ getInstalledVersions() → read lockfiles
346
+ Spawn researchers (parallel)
347
+ Collect summaries → shared_context
348
+
349
+ Normal decomposition with enriched context
350
+ ```
351
+
352
+ **Why This Matters:**
353
+
354
+ Workers now start with version-specific documentation instead of hallucinating APIs. Researchers store detailed findings in semantic-memory, so future agents don't repeat the research.
355
+
356
+ ### Patch Changes
357
+
358
+ - Updated dependencies [[`652fd16`](https://github.com/joelhooks/swarm-tools/commit/652fd16ff424eff92ebb3f5da0599caf676de2ce)]:
359
+ - swarm-mail@1.4.0
360
+
3
361
  ## 0.32.0
4
362
 
5
363
  ### Minor Changes