opencode-swarm-plugin 0.22.0 → 0.23.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 (128) hide show
  1. package/.turbo/turbo-build.log +9 -0
  2. package/CHANGELOG.md +12 -0
  3. package/README.md +109 -429
  4. package/dist/agent-mail.d.ts +480 -0
  5. package/dist/agent-mail.d.ts.map +1 -0
  6. package/dist/anti-patterns.d.ts +257 -0
  7. package/dist/anti-patterns.d.ts.map +1 -0
  8. package/dist/beads.d.ts +377 -0
  9. package/dist/beads.d.ts.map +1 -0
  10. package/dist/eval-capture.d.ts +206 -0
  11. package/dist/eval-capture.d.ts.map +1 -0
  12. package/dist/index.d.ts +1299 -0
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +498 -4246
  15. package/dist/learning.d.ts +670 -0
  16. package/dist/learning.d.ts.map +1 -0
  17. package/dist/mandate-promotion.d.ts +93 -0
  18. package/dist/mandate-promotion.d.ts.map +1 -0
  19. package/dist/mandate-storage.d.ts +209 -0
  20. package/dist/mandate-storage.d.ts.map +1 -0
  21. package/dist/mandates.d.ts +230 -0
  22. package/dist/mandates.d.ts.map +1 -0
  23. package/dist/output-guardrails.d.ts +125 -0
  24. package/dist/output-guardrails.d.ts.map +1 -0
  25. package/dist/pattern-maturity.d.ts +246 -0
  26. package/dist/pattern-maturity.d.ts.map +1 -0
  27. package/dist/plugin.d.ts +22 -0
  28. package/dist/plugin.d.ts.map +1 -0
  29. package/dist/plugin.js +493 -4241
  30. package/dist/rate-limiter.d.ts +218 -0
  31. package/dist/rate-limiter.d.ts.map +1 -0
  32. package/dist/repo-crawl.d.ts +146 -0
  33. package/dist/repo-crawl.d.ts.map +1 -0
  34. package/dist/schemas/bead.d.ts +255 -0
  35. package/dist/schemas/bead.d.ts.map +1 -0
  36. package/dist/schemas/evaluation.d.ts +161 -0
  37. package/dist/schemas/evaluation.d.ts.map +1 -0
  38. package/dist/schemas/index.d.ts +34 -0
  39. package/dist/schemas/index.d.ts.map +1 -0
  40. package/dist/schemas/mandate.d.ts +336 -0
  41. package/dist/schemas/mandate.d.ts.map +1 -0
  42. package/dist/schemas/swarm-context.d.ts +131 -0
  43. package/dist/schemas/swarm-context.d.ts.map +1 -0
  44. package/dist/schemas/task.d.ts +188 -0
  45. package/dist/schemas/task.d.ts.map +1 -0
  46. package/dist/skills.d.ts +471 -0
  47. package/dist/skills.d.ts.map +1 -0
  48. package/dist/storage.d.ts +260 -0
  49. package/dist/storage.d.ts.map +1 -0
  50. package/dist/structured.d.ts +196 -0
  51. package/dist/structured.d.ts.map +1 -0
  52. package/dist/swarm-decompose.d.ts +201 -0
  53. package/dist/swarm-decompose.d.ts.map +1 -0
  54. package/dist/swarm-mail.d.ts +240 -0
  55. package/dist/swarm-mail.d.ts.map +1 -0
  56. package/dist/swarm-orchestrate.d.ts +708 -0
  57. package/dist/swarm-orchestrate.d.ts.map +1 -0
  58. package/dist/swarm-prompts.d.ts +292 -0
  59. package/dist/swarm-prompts.d.ts.map +1 -0
  60. package/dist/swarm-strategies.d.ts +100 -0
  61. package/dist/swarm-strategies.d.ts.map +1 -0
  62. package/dist/swarm.d.ts +455 -0
  63. package/dist/swarm.d.ts.map +1 -0
  64. package/dist/tool-availability.d.ts +91 -0
  65. package/dist/tool-availability.d.ts.map +1 -0
  66. package/docs/planning/ADR-001-monorepo-structure.md +171 -0
  67. package/docs/planning/ADR-002-package-extraction.md +393 -0
  68. package/docs/planning/ADR-003-performance-improvements.md +451 -0
  69. package/docs/planning/ADR-004-message-queue-features.md +187 -0
  70. package/docs/planning/ADR-005-devtools-observability.md +202 -0
  71. package/docs/planning/ROADMAP.md +368 -0
  72. package/package.json +13 -24
  73. package/src/agent-mail.ts +1 -1
  74. package/src/beads.ts +1 -2
  75. package/src/index.ts +2 -2
  76. package/src/learning.integration.test.ts +66 -11
  77. package/src/mandate-storage.test.ts +3 -3
  78. package/src/storage.ts +78 -10
  79. package/src/swarm-mail.ts +3 -3
  80. package/src/swarm-orchestrate.ts +7 -7
  81. package/src/tool-availability.ts +1 -1
  82. package/tsconfig.json +1 -1
  83. package/.beads/.local_version +0 -1
  84. package/.beads/README.md +0 -81
  85. package/.beads/analysis/skill-architecture-meta-skills.md +0 -1562
  86. package/.beads/config.yaml +0 -62
  87. package/.beads/issues.jsonl +0 -2197
  88. package/.beads/metadata.json +0 -4
  89. package/.gitattributes +0 -3
  90. package/.github/workflows/ci.yml +0 -30
  91. package/.github/workflows/opencode.yml +0 -31
  92. package/.opencode/skills/tdd/SKILL.md +0 -182
  93. package/INTEGRATION_EXAMPLE.md +0 -66
  94. package/VERIFICATION_QUALITY_PATTERNS.md +0 -565
  95. package/bun.lock +0 -286
  96. package/dist/pglite.data +0 -0
  97. package/dist/pglite.wasm +0 -0
  98. package/src/streams/agent-mail.test.ts +0 -777
  99. package/src/streams/agent-mail.ts +0 -535
  100. package/src/streams/debug.test.ts +0 -500
  101. package/src/streams/debug.ts +0 -727
  102. package/src/streams/effect/ask.integration.test.ts +0 -314
  103. package/src/streams/effect/ask.ts +0 -202
  104. package/src/streams/effect/cursor.integration.test.ts +0 -418
  105. package/src/streams/effect/cursor.ts +0 -288
  106. package/src/streams/effect/deferred.test.ts +0 -357
  107. package/src/streams/effect/deferred.ts +0 -445
  108. package/src/streams/effect/index.ts +0 -17
  109. package/src/streams/effect/layers.ts +0 -73
  110. package/src/streams/effect/lock.test.ts +0 -385
  111. package/src/streams/effect/lock.ts +0 -399
  112. package/src/streams/effect/mailbox.test.ts +0 -260
  113. package/src/streams/effect/mailbox.ts +0 -318
  114. package/src/streams/events.test.ts +0 -924
  115. package/src/streams/events.ts +0 -329
  116. package/src/streams/index.test.ts +0 -229
  117. package/src/streams/index.ts +0 -578
  118. package/src/streams/migrations.test.ts +0 -359
  119. package/src/streams/migrations.ts +0 -362
  120. package/src/streams/projections.test.ts +0 -611
  121. package/src/streams/projections.ts +0 -504
  122. package/src/streams/store.integration.test.ts +0 -658
  123. package/src/streams/store.ts +0 -1075
  124. package/src/streams/swarm-mail.ts +0 -552
  125. package/test-bug-fixes.ts +0 -86
  126. package/vitest.integration.config.ts +0 -19
  127. package/vitest.integration.setup.ts +0 -48
  128. package/workflow-integration-analysis.md +0 -876
@@ -0,0 +1,202 @@
1
+ # ADR-005: DevTools + Observability
2
+
3
+ ## Status
4
+
5
+ Proposed
6
+
7
+ ## Context
8
+
9
+ Swarm Mail currently has no visibility:
10
+
11
+ - No UI to inspect events, messages, locks
12
+ - No metrics on latency, queue depth, throughput
13
+ - No distributed tracing across agents
14
+ - Hard to debug coordination issues
15
+
16
+ Need both developer tools (UI + CLI) and production observability (metrics + tracing).
17
+
18
+ ## Decision
19
+
20
+ Build layered observability:
21
+
22
+ ### 1. DevTools UI (SvelteKit)
23
+
24
+ **Stack:**
25
+
26
+ - SvelteKit for SSR + static export
27
+ - Vite for dev server + build
28
+ - Server-Sent Events (SSE) for real-time updates
29
+ - Embeddable static build
30
+
31
+ **Features:**
32
+
33
+ - Event stream viewer (filterable, searchable)
34
+ - Message inbox/outbox per agent
35
+ - File reservation timeline
36
+ - Saga instance tracker (future)
37
+
38
+ **Build:**
39
+
40
+ ```bash
41
+ cd apps/devtools
42
+ bun run build # Static export to apps/devtools/build
43
+ ```
44
+
45
+ **Embed in plugin:**
46
+
47
+ ```typescript
48
+ // Serve static UI at /_swarm/devtools
49
+ const server = serve({
50
+ port: 4000,
51
+ fetch: (req) => {
52
+ if (req.url.startsWith("/_swarm/devtools")) {
53
+ return serveStatic("apps/devtools/build");
54
+ }
55
+ },
56
+ });
57
+ ```
58
+
59
+ ### 2. CLI (@effect/cli)
60
+
61
+ **Commands:**
62
+
63
+ ```bash
64
+ swarm events [--project <key>] [--type <type>] [--tail]
65
+ swarm messages [--agent <name>] [--unread]
66
+ swarm locks [--agent <name>]
67
+ swarm replay --from <sequence> [--to <sequence>]
68
+ swarm metrics
69
+ ```
70
+
71
+ **Implementation:**
72
+
73
+ ```typescript
74
+ import { Command } from "@effect/cli";
75
+
76
+ const eventsCommand = Command.make(
77
+ "events",
78
+ {
79
+ project: Options.string("project").optional,
80
+ type: Options.string("type").optional,
81
+ tail: Options.boolean("tail"),
82
+ },
83
+ ({ project, type, tail }) => {
84
+ // Query events table, optionally --tail with live query
85
+ },
86
+ );
87
+ ```
88
+
89
+ ### 3. Metrics (Prometheus)
90
+
91
+ **Histograms:**
92
+
93
+ - `swarm_message_latency_seconds` - Send to receive time
94
+ - `swarm_lock_contention_seconds` - Time waiting for lock
95
+ - `swarm_queue_depth` - Unread messages per agent
96
+
97
+ **Counters:**
98
+
99
+ - `swarm_events_total{type}` - Events by type
100
+ - `swarm_messages_sent_total{sender, recipient}`
101
+ - `swarm_locks_acquired_total{agent}`
102
+
103
+ **Example:**
104
+
105
+ ```typescript
106
+ import { Registry, Histogram } from 'prom-client'
107
+
108
+ const messageLat ency = new Histogram({
109
+ name: 'swarm_message_latency_seconds',
110
+ help: 'Message delivery latency',
111
+ buckets: [0.01, 0.05, 0.1, 0.5, 1.0, 5.0]
112
+ })
113
+
114
+ // Record latency
115
+ const start = Date.now()
116
+ await sendMessage(msg)
117
+ const latency = (Date.now() - start) / 1000
118
+ messageLatency.observe(latency)
119
+ ```
120
+
121
+ ### 4. Distributed Tracing (OpenTelemetry)
122
+
123
+ **Integration:**
124
+
125
+ ```typescript
126
+ import { @effect/opentelemetry } from '@effect/opentelemetry'
127
+ import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node'
128
+
129
+ const provider = new NodeTracerProvider()
130
+ const tracer = provider.getTracer('swarm-mail')
131
+
132
+ // Trace message send
133
+ const span = tracer.startSpan('sendMessage', {
134
+ attributes: {
135
+ 'swarm.sender': 'AgentA',
136
+ 'swarm.recipient': 'AgentB',
137
+ 'swarm.thread_id': 'bd-123'
138
+ }
139
+ })
140
+
141
+ await sendMessage(msg)
142
+ span.end()
143
+ ```
144
+
145
+ **Trace Propagation:**
146
+
147
+ - Add trace_id to message metadata
148
+ - Worker agents continue traces from parents
149
+ - Visualize full swarm execution flow
150
+
151
+ ## Consequences
152
+
153
+ ### Easier
154
+
155
+ - **Visibility** - See all events, messages, locks in real-time
156
+ - **Debugging** - Trace issues across agents via distributed tracing
157
+ - **Performance** - Identify slow operations via histograms
158
+ - **Operations** - CLI for prod debugging without UI
159
+
160
+ ### More Difficult
161
+
162
+ - **Maintenance** - Another app to maintain (DevTools UI)
163
+ - **Bundle size** - Metrics/tracing deps increase plugin size
164
+ - **Performance overhead** - Instrumentation adds latency
165
+ - **Configuration** - Metrics exporters, trace backends
166
+
167
+ ## Implementation Notes
168
+
169
+ ### Phase 1: CLI (Week 1)
170
+
171
+ - Add @effect/cli dependency
172
+ - Implement events, messages, locks commands
173
+ - Test with real swarm sessions
174
+
175
+ ### Phase 2: DevTools UI (Week 2-3)
176
+
177
+ - Scaffold SvelteKit app
178
+ - Build event stream viewer
179
+ - Add SSE endpoint for real-time updates
180
+ - Static export + embed in plugin
181
+
182
+ ### Phase 3: Metrics (Week 4)
183
+
184
+ - Add prom-client dependency
185
+ - Instrument send/receive latency
186
+ - Add queue depth gauge
187
+ - Expose /metrics endpoint
188
+
189
+ ### Phase 4: Tracing (Week 5)
190
+
191
+ - Add @effect/opentelemetry
192
+ - Instrument message send/receive
193
+ - Propagate trace context
194
+ - Test with Jaeger/Zipkin
195
+
196
+ ### Success Criteria
197
+
198
+ - [ ] CLI can tail events in real-time
199
+ - [ ] DevTools UI shows live message stream
200
+ - [ ] Metrics exposed at /metrics endpoint
201
+ - [ ] Traces visible in Jaeger UI
202
+ - [ ] Documentation for all observability tools
@@ -0,0 +1,368 @@
1
+ # Implementation Roadmap
2
+
3
+ ## Overview
4
+
5
+ This roadmap implements all 5 ADRs in phased releases over 12 weeks. Each phase delivers incremental value and can ship independently.
6
+
7
+ ## Phase 0: Preparation (Week 0)
8
+
9
+ **Goal:** Set up monorepo infrastructure and validate all ADRs
10
+
11
+ **Tasks:**
12
+
13
+ - [ ] Install Turborepo + configure turbo.json
14
+ - [ ] Set up Changesets for versioning
15
+ - [ ] Configure dependency-cruiser for circular dep detection
16
+ - [ ] Create packages/swarm-mail and packages/opencode-swarm-plugin directories
17
+ - [ ] Set up TypeScript project references
18
+ - [ ] Configure CI/CD with Turborepo caching
19
+
20
+ **Deliverables:**
21
+
22
+ - Working monorepo build (`turbo run build`)
23
+ - Published ADRs in docs/planning/
24
+ - CI pipeline running tests for both packages
25
+
26
+ **Success Criteria:**
27
+
28
+ - `bun run build` builds both packages in correct order
29
+ - No circular dependencies detected
30
+ - CI completes in <2 minutes (with caching)
31
+
32
+ ---
33
+
34
+ ## Phase 1: Package Extraction (Weeks 1-2)
35
+
36
+ **Goal:** Extract swarm-mail package and publish to npm
37
+
38
+ **ADRs:** ADR-001, ADR-002
39
+
40
+ **Tasks:**
41
+
42
+ - [ ] Move src/streams/\* to packages/swarm-mail/src/streams/
43
+ - [ ] Move agent-mail.ts, swarm-mail.ts to swarm-mail
44
+ - [ ] Update imports in opencode-swarm-plugin to use swarm-mail
45
+ - [ ] Migrate integration tests
46
+ - [ ] Write swarm-mail README with examples
47
+ - [ ] Add deprecation warnings in opencode-swarm-plugin
48
+ - [ ] Publish swarm-mail@0.1.0 to npm
49
+
50
+ **Deliverables:**
51
+
52
+ - swarm-mail published on npm
53
+ - opencode-swarm-plugin depends on swarm-mail
54
+ - Migration guide for existing users
55
+ - TypeDoc API documentation
56
+
57
+ **Success Criteria:**
58
+
59
+ - All tests pass in both packages
60
+ - swarm-mail works in standalone project
61
+ - No circular dependencies
62
+ - Published tarball <500KB
63
+
64
+ ---
65
+
66
+ ## Phase 2: Performance Optimizations (Weeks 3-4)
67
+
68
+ **Goal:** Replace polling with live queries and add batch operations
69
+
70
+ **ADRs:** ADR-003
71
+
72
+ **Tasks:**
73
+
74
+ - [ ] Create live query wrapper (src/streams/live-query.ts)
75
+ - [ ] Add subscription cleanup tracking
76
+ - [ ] Replace polling in watchInbox()
77
+ - [ ] Replace polling in watchEvents()
78
+ - [ ] Add batch message send API
79
+ - [ ] Add batch event append API
80
+ - [ ] Write integration tests for live queries
81
+ - [ ] Run performance benchmarks (latency, CPU, memory)
82
+
83
+ **Deliverables:**
84
+
85
+ - Live queries for inbox, events, file reservations
86
+ - Batch APIs for messages and events
87
+ - Performance benchmarks showing improvements
88
+ - Feature flag for gradual rollout
89
+
90
+ **Success Criteria:**
91
+
92
+ - Notification latency <50ms (99th percentile)
93
+ - CPU usage <1% in idle state
94
+ - Batch operations 10x faster than individual
95
+ - Memory usage increase <20%
96
+
97
+ **Metrics (Before → After):**
98
+
99
+ - Latency: 250-500ms → <10ms (25-50x improvement)
100
+ - CPU: 5-10% → <1% (5-10x reduction)
101
+ - Queries/sec: 2-4 → 0 (eliminated)
102
+
103
+ ---
104
+
105
+ ## Phase 3: Message Queue Features (Weeks 5-7)
106
+
107
+ **Goal:** Add priority queues, DLQ, TTL, pub/sub
108
+
109
+ **ADRs:** ADR-004
110
+
111
+ **Tasks:**
112
+
113
+ **Week 5: Priority Queues + DLQ**
114
+
115
+ - [ ] Add priority column to messages table
116
+ - [ ] Update getInbox() to ORDER BY priority DESC
117
+ - [ ] Create failed_messages table
118
+ - [ ] Implement retry logic with exponential backoff
119
+ - [ ] Add DLQ viewer to CLI
120
+
121
+ **Week 6: TTL + Pub/Sub**
122
+
123
+ - [ ] Add expires_at column to messages
124
+ - [ ] Implement background TTL cleanup job
125
+ - [ ] Add topic column to messages
126
+ - [ ] Implement subscribeToTopic() using live queries
127
+ - [ ] Support wildcard topic subscriptions
128
+
129
+ **Week 7: Testing + Documentation**
130
+
131
+ - [ ] Write integration tests for all features
132
+ - [ ] Add examples to README
133
+ - [ ] Document retry/DLQ behavior
134
+ - [ ] Document pub/sub patterns
135
+
136
+ **Deliverables:**
137
+
138
+ - Priority queues (4 levels: 0=urgent, 3=low)
139
+ - DLQ with retry tracking
140
+ - TTL with background cleanup
141
+ - Pub/sub with wildcard topics
142
+
143
+ **Success Criteria:**
144
+
145
+ - Priority messages processed first
146
+ - Failed messages retry 3x before DLQ
147
+ - Expired messages cleaned up within 5 minutes
148
+ - Topic subscriptions work with wildcards
149
+
150
+ ---
151
+
152
+ ## Phase 4: DevTools + CLI (Weeks 8-10)
153
+
154
+ **Goal:** Build DevTools UI and CLI for observability
155
+
156
+ **ADRs:** ADR-005
157
+
158
+ **Tasks:**
159
+
160
+ **Week 8: CLI**
161
+
162
+ - [ ] Add @effect/cli dependency
163
+ - [ ] Implement `swarm events` command
164
+ - [ ] Implement `swarm messages` command
165
+ - [ ] Implement `swarm locks` command
166
+ - [ ] Implement `swarm replay` command
167
+ - [ ] Add `--tail` mode for real-time updates
168
+
169
+ **Week 9: DevTools UI**
170
+
171
+ - [ ] Scaffold SvelteKit app in apps/devtools
172
+ - [ ] Build event stream viewer
173
+ - [ ] Build message inbox/outbox viewer
174
+ - [ ] Build file reservation timeline
175
+ - [ ] Add SSE endpoint for real-time updates
176
+
177
+ **Week 10: Integration + Polish**
178
+
179
+ - [ ] Static export of DevTools UI
180
+ - [ ] Embed UI in plugin (serve at /\_swarm/devtools)
181
+ - [ ] Add screenshots to README
182
+ - [ ] Write user guide
183
+
184
+ **Deliverables:**
185
+
186
+ - CLI with 5 commands (events, messages, locks, replay, metrics)
187
+ - DevTools UI (embeddable SvelteKit app)
188
+ - Real-time updates via SSE
189
+ - User guide with screenshots
190
+
191
+ **Success Criteria:**
192
+
193
+ - CLI can tail events in real-time
194
+ - DevTools UI shows live message stream
195
+ - UI works offline (static export)
196
+ - Documentation covers all CLI commands
197
+
198
+ ---
199
+
200
+ ## Phase 5: Metrics + Tracing (Weeks 11-12)
201
+
202
+ **Goal:** Add Prometheus metrics and OpenTelemetry tracing
203
+
204
+ **ADRs:** ADR-005
205
+
206
+ **Tasks:**
207
+
208
+ **Week 11: Metrics**
209
+
210
+ - [ ] Add prom-client dependency
211
+ - [ ] Instrument message send/receive latency
212
+ - [ ] Add lock contention histogram
213
+ - [ ] Add queue depth gauge
214
+ - [ ] Expose /metrics endpoint
215
+ - [ ] Add Grafana dashboard template
216
+
217
+ **Week 12: Tracing**
218
+
219
+ - [ ] Add @effect/opentelemetry dependency
220
+ - [ ] Instrument message send/receive spans
221
+ - [ ] Propagate trace context in messages
222
+ - [ ] Add trace_id to message metadata
223
+ - [ ] Test with Jaeger/Zipkin
224
+ - [ ] Write tracing guide
225
+
226
+ **Deliverables:**
227
+
228
+ - Prometheus metrics at /metrics endpoint
229
+ - OpenTelemetry tracing integration
230
+ - Grafana dashboard template
231
+ - Tracing guide with Jaeger setup
232
+
233
+ **Success Criteria:**
234
+
235
+ - Metrics exposed and scrapeable by Prometheus
236
+ - Traces visible in Jaeger UI
237
+ - Trace propagation across agents works
238
+ - Documentation for all observability tools
239
+
240
+ ---
241
+
242
+ ## Phase 6: Saga Pattern (Future)
243
+
244
+ **Goal:** Implement saga orchestration for long-running workflows
245
+
246
+ **ADRs:** ADR-004 (Phase 5)
247
+
248
+ **Status:** Deferred to v2.0
249
+
250
+ **Tasks:**
251
+
252
+ - [ ] Create saga_instances and saga_steps tables
253
+ - [ ] Add saga coordinator logic
254
+ - [ ] Implement compensation pattern
255
+ - [ ] Add saga viewer to DevTools UI
256
+ - [ ] Write saga pattern examples
257
+
258
+ **Deliverables:**
259
+
260
+ - Saga orchestration pattern
261
+ - Compensation (undo) support
262
+ - Saga viewer in DevTools
263
+ - 3+ example saga workflows
264
+
265
+ ---
266
+
267
+ ## Release Schedule
268
+
269
+ | Version | Phase | Features | ETA |
270
+ | --------- | ----- | ------------------------------ | ------- |
271
+ | **0.1.0** | 1 | swarm-mail package extraction | Week 2 |
272
+ | **0.2.0** | 2 | Live queries, batch operations | Week 4 |
273
+ | **0.3.0** | 3 | Priority, DLQ, TTL, pub/sub | Week 7 |
274
+ | **0.4.0** | 4 | DevTools UI + CLI | Week 10 |
275
+ | **0.5.0** | 5 | Metrics + tracing | Week 12 |
276
+ | **1.0.0** | All | Stable release | Week 13 |
277
+ | **2.0.0** | 6 | Saga pattern (future) | TBD |
278
+
279
+ ---
280
+
281
+ ## Dependencies Between Phases
282
+
283
+ ```
284
+ Phase 0 (Monorepo)
285
+ └──> Phase 1 (Package Extraction)
286
+ └──> Phase 2 (Performance)
287
+ ├──> Phase 3 (Queue Features)
288
+ └──> Phase 4 (DevTools)
289
+ └──> Phase 5 (Metrics/Tracing)
290
+ └──> Phase 6 (Sagas, future)
291
+ ```
292
+
293
+ **Critical Path:** Phases 0→1→2 are sequential. Phases 3-5 can partially overlap after Phase 2.
294
+
295
+ ---
296
+
297
+ ## Risk Mitigation
298
+
299
+ | Risk | Phase | Mitigation |
300
+ | ---------------------------------------- | ----- | --------------------------------------------------------- |
301
+ | Breaking changes during extraction | 1 | Feature branch, comprehensive tests, migration guide |
302
+ | Performance regression with live queries | 2 | Feature flag, benchmark before/after, fallback to polling |
303
+ | Complexity of saga pattern | 6 | Defer to v2.0, gather user feedback first |
304
+ | DevTools UI maintenance burden | 4 | Keep UI minimal, focus on CLI for power users |
305
+ | Metrics overhead | 5 | Make metrics opt-in, minimal instrumentation |
306
+
307
+ ---
308
+
309
+ ## Success Metrics
310
+
311
+ **Phase 1 (Package Extraction):**
312
+
313
+ - swarm-mail used in 3+ external projects within 3 months
314
+ - Zero breaking changes reported by users
315
+
316
+ **Phase 2 (Performance):**
317
+
318
+ - 25x faster notification latency (500ms → <10ms)
319
+ - 5x lower CPU usage (10% → <2%)
320
+
321
+ **Phase 3 (Queue Features):**
322
+
323
+ - 95% of messages processed within priority SLA
324
+ - <1% messages fail to DLQ
325
+
326
+ **Phase 4 (DevTools):**
327
+
328
+ - 80% of developers use DevTools UI for debugging
329
+ - CLI used in 50%+ of support cases
330
+
331
+ **Phase 5 (Metrics/Tracing):**
332
+
333
+ - Metrics dashboard used in production monitoring
334
+ - Distributed traces reduce debugging time by 50%
335
+
336
+ ---
337
+
338
+ ## Post-1.0 Backlog (v2.0+)
339
+
340
+ **Saga Pattern** (ADR-004 Phase 5)
341
+
342
+ - Long-running multi-agent workflows
343
+ - Compensation (undo) support
344
+ - Saga state visualization
345
+
346
+ **Advanced Pub/Sub**
347
+
348
+ - Message routing rules
349
+ - Filter expressions (SQL-like WHERE clauses)
350
+ - At-least-once vs exactly-once delivery guarantees
351
+
352
+ **Multi-Project Support**
353
+
354
+ - Cross-project message routing
355
+ - Project-level isolation
356
+ - Shared infra for mono repos
357
+
358
+ **Performance Tier 2**
359
+
360
+ - Connection pooling for multi-DB scenarios
361
+ - Message batching optimizations
362
+ - SKIP LOCKED for exactly-once semantics
363
+
364
+ **Security**
365
+
366
+ - Message encryption at rest
367
+ - Agent authentication/authorization
368
+ - Audit logging
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "opencode-swarm-plugin",
3
- "version": "0.22.0",
3
+ "version": "0.23.0",
4
4
  "description": "Multi-agent swarm coordination for OpenCode with learning capabilities, beads integration, and Agent Mail",
5
5
  "type": "module",
6
- "main": "dist/index.js",
7
- "types": "dist/index.d.ts",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
8
  "bin": {
9
9
  "swarm": "./bin/swarm.ts"
10
10
  },
@@ -14,37 +14,25 @@
14
14
  "types": "./dist/index.d.ts"
15
15
  },
16
16
  "./plugin": {
17
- "import": "./dist/plugin.js"
17
+ "import": "./dist/plugin.js",
18
+ "types": "./dist/plugin.d.ts"
18
19
  }
19
20
  },
20
21
  "scripts": {
21
- "build": "bun build ./src/index.ts --outdir ./dist --target node --external @electric-sql/pglite && bun build ./src/plugin.ts --outfile ./dist/plugin.js --target node --external @electric-sql/pglite",
22
+ "build": "bun build ./src/index.ts --outdir ./dist --target node --external @electric-sql/pglite --external swarm-mail && bun build ./src/plugin.ts --outfile ./dist/plugin.js --target node --external @electric-sql/pglite --external swarm-mail && tsc",
22
23
  "dev": "bun --watch src/index.ts",
23
- "test": "bun test src/schemas src/skills.test.ts src/streams/index.test.ts src/streams/events.test.ts src/streams/projections.test.ts src/streams/migrations.test.ts src/streams/debug.test.ts src/streams/agent-mail.test.ts src/streams/effect/deferred.test.ts src/streams/effect/mailbox.test.ts",
24
- "test:watch": "bun test --watch src/schemas src/skills.test.ts",
25
- "test:integration": "vitest run --config vitest.integration.config.ts",
26
- "test:swarm": "bun test src/swarm-mail.integration.test.ts",
27
- "test:all": "bun run test && bun run test:swarm",
24
+ "test": "bun test --timeout 10000 src/anti-patterns.test.ts src/mandate-promotion.test.ts src/mandate-storage.test.ts src/output-guardrails.test.ts src/pattern-maturity.test.ts src/skills.test.ts src/structured.test.ts src/schemas/",
25
+ "test:integration": "bun test --timeout 60000 src/*.integration.test.ts",
26
+ "test:all": "bun test --timeout 60000 src/",
27
+ "test:watch": "bun test --watch src/",
28
28
  "typecheck": "tsc --noEmit",
29
- "clean": "rm -rf dist",
30
- "eval:dev": "evalite watch evals/",
31
- "eval:run": "evalite run evals/",
32
- "eval:ci": "evalite run evals/ --threshold 80",
33
- "release": "npm run build && npm version patch && git push && npm run publish:otp",
34
- "release:minor": "npm run build && npm version minor && git push && npm run publish:otp",
35
- "release:major": "npm run build && npm version major && git push && npm run publish:otp",
36
- "publish:otp": "bash -c 'source .env && npm publish --otp=$(op item get $NPM_1P_ITEM --otp)'"
29
+ "publish:pkg": "npm publish --access public --provenance"
37
30
  },
38
31
  "dependencies": {
39
- "@clack/prompts": "^0.11.0",
40
- "@effect/schema": "^0.75.5",
41
- "@electric-sql/pglite": "0.3.14",
42
32
  "@opencode-ai/plugin": "^1.0.134",
43
- "effect": "^3.19.12",
44
33
  "gray-matter": "^4.0.3",
45
34
  "ioredis": "^5.4.1",
46
- "minimatch": "^10.1.1",
47
- "nanoid": "^5.1.6",
35
+ "swarm-mail": "workspace:*",
48
36
  "zod": "4.1.8"
49
37
  },
50
38
  "devDependencies": {
@@ -53,6 +41,7 @@
53
41
  "ai": "6.0.0-beta.150",
54
42
  "bun-types": "^1.3.4",
55
43
  "evalite": "^1.0.0-beta.10",
44
+ "turbo": "^2.6.3",
56
45
  "typescript": "^5.7.0",
57
46
  "vitest": "^4.0.15"
58
47
  },
package/src/agent-mail.ts CHANGED
@@ -31,7 +31,7 @@ import { tool } from "@opencode-ai/plugin";
31
31
  import { z } from "zod";
32
32
  import { isToolAvailable, warnMissingTool } from "./tool-availability";
33
33
  import { getRateLimiter, type RateLimiter } from "./rate-limiter";
34
- import type { MailSessionState } from "./streams/events";
34
+ import type { MailSessionState } from "swarm-mail";
35
35
 
36
36
  // ============================================================================
37
37
  // Configuration
package/src/beads.ts CHANGED
@@ -104,8 +104,7 @@ import {
104
104
  type BeadCreateArgs,
105
105
  type EpicCreateResult,
106
106
  } from "./schemas";
107
- import { createEvent } from "./streams/events";
108
- import { appendEvent } from "./streams/store";
107
+ import { createEvent, appendEvent } from "swarm-mail";
109
108
 
110
109
  /**
111
110
  * Custom error for bead operations
package/src/index.ts CHANGED
@@ -320,12 +320,12 @@ export {
320
320
  } from "./swarm-mail";
321
321
 
322
322
  /**
323
- * Re-export shared types from streams/events
323
+ * Re-export shared types from swarm-mail package
324
324
  *
325
325
  * Includes:
326
326
  * - MailSessionState - Shared session state type for Agent Mail and Swarm Mail
327
327
  */
328
- export { type MailSessionState } from "./streams/events";
328
+ export { type MailSessionState } from "swarm-mail";
329
329
 
330
330
  /**
331
331
  * Re-export structured module