opencode-swarm-plugin@0.45.1
Patch Changes
-
df219d8Thanks @joelhooks! - ##swarm capture- The CLI Stays Dumb, The Plugin Stays Dumber"To conform to the principle of dependency inversion, we must isolate this abstraction from the details of the problem."
— Robert C. Martin, Clean Code┌─────────────────────────────────────────────────────────────┐ │ │ │ ~/.config/opencode/plugin/swarm.ts │ │ ┌─────────────────────────────────────────────────────┐ │ │ │ │ │ │ │ spawn("swarm", ["capture", "--session", ...]) │───┼──► swarm capture │ │ │ │ │ │ │ // No imports from opencode-swarm-plugin │ │ │ │ │ // Version always matches CLI │ │ ▼ │ │ // Fire and forget │ │ captureCompactionEvent() │ │ │ │ │ └─────────────────────────────────────────────────────┘ │ │ │ └─────────────────────────────────────────────────────────────┘The Problem: Plugin wrapper was importing
captureCompactionEventdirectly from the npm package. When installed globally, this import could fail or use a stale version.The Fix: Shell out to
swarm captureCLI command instead. The CLI is always the installed version, so no version mismatch.New command:
swarm capture --session <id> --epic <id> --type <type> [--payload <json>] # Types: detection_complete, prompt_generated, context_injected, # resumption_started, tool_call_tracked
Design principle: The plugin wrapper in
~/.config/opencode/plugin/swarm.tsshould be as dumb as possible. All logic lives in the CLI/npm package. Users never need to update their local plugin file for new features - justnpm update.Files changed:
bin/swarm.ts- Addedcapturecommandexamples/plugin-wrapper-template.ts- Uses CLI instead of import
-
ff29b26Thanks @joelhooks! - ## 🔧 Fix CLI Breaking on npm Install"The best code is no code at all."
— Jeff Atwood┌─────────────────────────────────────────────────────────────┐ │ BEFORE: npm install → "Cannot find module '../src/index'" │ ├─────────────────────────────────────────────────────────────┤ │ │ │ bin/swarm.ts ──import──► ../src/query-tools.js ❌ │ │ │ │ Published package: │ │ ├── bin/swarm.ts (raw TypeScript) │ │ ├── dist/ (compiled JS) │ │ └── src/ ❌ NOT PUBLISHED │ │ │ ├─────────────────────────────────────────────────────────────┤ │ AFTER: npm install → works │ ├─────────────────────────────────────────────────────────────┤ │ │ │ dist/bin/swarm.js ──bundled──► all deps inlined ✅ │ │ │ │ Published package: │ │ ├── dist/bin/swarm.js (compiled, bundled) │ │ └── dist/ (all modules) │ │ │ └─────────────────────────────────────────────────────────────┘The Problem:
CLI used dynamic imports pointing to
../src/which doesn't exist in published packages. This brokebun install -g opencode-swarm-pluginwith "Cannot find module" errors.The Fix:
- Compile CLI to dist/ - Added
bin/swarm.tsto build entries - Static imports - Replaced 20 dynamic imports with static ones (bundler resolves them)
- Update bin path -
package.jsonbin now points to./dist/bin/swarm.js
Why dynamic imports were wrong:
- "Lazy loading for performance" on an M4 Max is absurd
- Bun tree-shakes unused imports anyway
- Dynamic imports bypass bundler resolution
- Paths break when
src/isn't published
What changed:
scripts/build.ts- Added CLI build entrypackage.json- bin points to compiled outputbin/swarm.ts- All imports now static, paths relative to src/
Testing:
# Build bun run build # Test locally node dist/bin/swarm.js version # Test global install bun install -g . swarm version
- Compile CLI to dist/ - Added
-
24a986eThanks @joelhooks! - ## 🐝 Plugin Wrapper Now Fully Self-Contained┌──────────────────────────────────────────────────────────┐ │ │ │ ~/.config/opencode/plugin/swarm.ts │ │ │ │ ┌────────────────────────────────────────────────────┐ │ │ │ BEFORE: import { ... } from "opencode-swarm-plugin"│ │ │ │ ↓ │ │ │ │ 💥 Cannot find module 'evalite/runner' │ │ │ └────────────────────────────────────────────────────┘ │ │ │ │ ┌────────────────────────────────────────────────────┐ │ │ │ AFTER: // Inlined swarm detection (~250 lines) │ │ │ │ // Zero imports from npm package │ │ │ │ ↓ │ │ │ │ ✅ Works everywhere │ │ │ └────────────────────────────────────────────────────┘ │ │ │ └──────────────────────────────────────────────────────────┘Problem: Plugin wrapper in
~/.config/opencode/plugin/swarm.tswas importing fromopencode-swarm-pluginnpm package. The package hasevaliteas a dependency, which isn't available in OpenCode's plugin context. Result: trace trap on startup.Solution: Inline all swarm detection logic directly into the plugin wrapper template:
SwarmProjection,ToolCallEvent,SubtaskState,EpicStatetypesprojectSwarmState()- event fold for deterministic statehasSwarmSignature()- quick check for epic + spawnisSwarmActive()- check for pending workgetSwarmSummary()- human-readable status
Design Principle: The plugin wrapper must be FULLY SELF-CONTAINED:
- NO imports from
opencode-swarm-pluginnpm package - All logic either inlined OR shells out to
swarmCLI - Users never need to update their local plugin for new features
After updating: Copy the new template to your local plugin:
cp ~/.config/opencode/plugin/swarm.ts ~/.config/opencode/plugin/swarm.ts.bak # Then reinstall: bun add -g opencode-swarm-plugin # Or copy from examples/plugin-wrapper-template.ts