opencode-swarm-plugin 0.39.1 → 0.42.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 (82) hide show
  1. package/.hive/analysis/eval-failure-analysis-2025-12-25.md +331 -0
  2. package/.hive/analysis/session-data-quality-audit.md +320 -0
  3. package/.hive/eval-results.json +481 -24
  4. package/.hive/issues.jsonl +76 -11
  5. package/.hive/memories.jsonl +159 -1
  6. package/.opencode/eval-history.jsonl +315 -0
  7. package/.turbo/turbo-build.log +5 -5
  8. package/CHANGELOG.md +207 -0
  9. package/README.md +2 -0
  10. package/SCORER-ANALYSIS.md +598 -0
  11. package/bin/eval-gate.test.ts +158 -0
  12. package/bin/eval-gate.ts +74 -0
  13. package/bin/swarm.test.ts +1054 -719
  14. package/bin/swarm.ts +577 -0
  15. package/dist/compaction-hook.d.ts +10 -1
  16. package/dist/compaction-hook.d.ts.map +1 -1
  17. package/dist/compaction-observability.d.ts +173 -0
  18. package/dist/compaction-observability.d.ts.map +1 -0
  19. package/dist/compaction-prompt-scoring.d.ts +1 -0
  20. package/dist/compaction-prompt-scoring.d.ts.map +1 -1
  21. package/dist/eval-capture.d.ts +93 -0
  22. package/dist/eval-capture.d.ts.map +1 -1
  23. package/dist/eval-runner.d.ts +134 -0
  24. package/dist/eval-runner.d.ts.map +1 -0
  25. package/dist/hive.d.ts.map +1 -1
  26. package/dist/index.d.ts +65 -1
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +84043 -28070
  29. package/dist/memory-tools.d.ts +70 -2
  30. package/dist/memory-tools.d.ts.map +1 -1
  31. package/dist/memory.d.ts +37 -0
  32. package/dist/memory.d.ts.map +1 -1
  33. package/dist/observability-tools.d.ts +64 -0
  34. package/dist/observability-tools.d.ts.map +1 -1
  35. package/dist/plugin.js +83570 -27466
  36. package/dist/schemas/task.d.ts +3 -3
  37. package/dist/swarm-orchestrate.d.ts.map +1 -1
  38. package/dist/swarm-prompts.d.ts +32 -1
  39. package/dist/swarm-prompts.d.ts.map +1 -1
  40. package/docs/planning/ADR-009-oh-my-opencode-patterns.md +353 -0
  41. package/evals/ARCHITECTURE.md +1189 -0
  42. package/evals/README.md +113 -0
  43. package/evals/example.eval.ts +3 -4
  44. package/evals/fixtures/compaction-prompt-cases.ts +6 -0
  45. package/evals/scorers/coordinator-discipline.evalite-test.ts +163 -0
  46. package/evals/scorers/coordinator-discipline.ts +82 -2
  47. package/evals/scorers/index.test.ts +146 -0
  48. package/evals/scorers/index.ts +104 -0
  49. package/evals/swarm-decomposition.eval.ts +13 -4
  50. package/examples/commands/swarm.md +291 -21
  51. package/package.json +4 -3
  52. package/src/compaction-hook.ts +258 -110
  53. package/src/compaction-observability.integration.test.ts +139 -0
  54. package/src/compaction-observability.test.ts +187 -0
  55. package/src/compaction-observability.ts +324 -0
  56. package/src/compaction-prompt-scorers.test.ts +10 -9
  57. package/src/compaction-prompt-scoring.ts +7 -5
  58. package/src/eval-capture.test.ts +204 -1
  59. package/src/eval-capture.ts +194 -2
  60. package/src/eval-runner.test.ts +223 -0
  61. package/src/eval-runner.ts +402 -0
  62. package/src/hive.ts +57 -22
  63. package/src/index.ts +54 -1
  64. package/src/memory-tools.test.ts +84 -0
  65. package/src/memory-tools.ts +68 -3
  66. package/src/memory.test.ts +2 -2
  67. package/src/memory.ts +122 -49
  68. package/src/observability-tools.test.ts +13 -0
  69. package/src/observability-tools.ts +277 -0
  70. package/src/swarm-orchestrate.test.ts +162 -0
  71. package/src/swarm-orchestrate.ts +7 -5
  72. package/src/swarm-prompts.test.ts +168 -4
  73. package/src/swarm-prompts.ts +228 -7
  74. package/.env +0 -2
  75. package/.turbo/turbo-test.log +0 -481
  76. package/.turbo/turbo-typecheck.log +0 -1
  77. package/dist/beads.d.ts +0 -386
  78. package/dist/beads.d.ts.map +0 -1
  79. package/dist/schemas/bead-events.d.ts +0 -698
  80. package/dist/schemas/bead-events.d.ts.map +0 -1
  81. package/dist/schemas/bead.d.ts +0 -255
  82. package/dist/schemas/bead.d.ts.map +0 -1
@@ -16,8 +16,8 @@ import { z } from "zod";
16
16
  */
17
17
  export declare const EffortLevelSchema: z.ZodEnum<{
18
18
  small: "small";
19
- trivial: "trivial";
20
19
  medium: "medium";
20
+ trivial: "trivial";
21
21
  large: "large";
22
22
  }>;
23
23
  export type EffortLevel = z.infer<typeof EffortLevelSchema>;
@@ -39,8 +39,8 @@ export declare const DecomposedSubtaskSchema: z.ZodObject<{
39
39
  files: z.ZodArray<z.ZodString>;
40
40
  estimated_effort: z.ZodEnum<{
41
41
  small: "small";
42
- trivial: "trivial";
43
42
  medium: "medium";
43
+ trivial: "trivial";
44
44
  large: "large";
45
45
  }>;
46
46
  risks: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString>>>;
@@ -74,8 +74,8 @@ export declare const TaskDecompositionSchema: z.ZodObject<{
74
74
  files: z.ZodArray<z.ZodString>;
75
75
  estimated_effort: z.ZodEnum<{
76
76
  small: "small";
77
- trivial: "trivial";
78
77
  medium: "medium";
78
+ trivial: "trivial";
79
79
  large: "large";
80
80
  }>;
81
81
  risks: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString>>>;
@@ -1 +1 @@
1
- {"version":3,"file":"swarm-orchestrate.d.ts","sourceRoot":"","sources":["../src/swarm-orchestrate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAaxB,OAAO,EACL,KAAK,aAAa,EAEnB,MAAM,0BAA0B,CAAC;AAsDlC;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE;IAC5C,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,sBAAsB,CAAC,EAAE,MAAM,EAAE,CAAC;IAClC,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAA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\n## \u26A0\uFE0F MAND
77
77
  * Agents use this to assess their work quality before marking complete.
78
78
  */
79
79
  export declare const EVALUATION_PROMPT = "Evaluate the work completed for this subtask.\n\n## Subtask\n**Cell ID**: {bead_id}\n**Title**: {subtask_title}\n\n## Files Modified\n{files_touched}\n\n## Evaluation Criteria\n\nFor each criterion, assess passed/failed and provide brief feedback:\n\n1. **type_safe**: Code compiles without TypeScript errors\n2. **no_bugs**: No obvious bugs, edge cases handled\n3. **patterns**: Follows existing codebase patterns and conventions\n4. **readable**: Code is clear and maintainable\n\n## Response Format\n\n```json\n{\n \"passed\": boolean, // Overall pass/fail\n \"criteria\": {\n \"type_safe\": { \"passed\": boolean, \"feedback\": string },\n \"no_bugs\": { \"passed\": boolean, \"feedback\": string },\n \"patterns\": { \"passed\": boolean, \"feedback\": string },\n \"readable\": { \"passed\": boolean, \"feedback\": string }\n },\n \"overall_feedback\": string,\n \"retry_suggestion\": string | null // If failed, what to fix\n}\n```\n\nIf any criterion fails, the overall evaluation fails and retry_suggestion \nshould describe what needs to be fixed.";
80
+ /**
81
+ * Query recent eval failures from semantic memory
82
+ *
83
+ * Coordinators call this at session start to learn from recent eval regressions.
84
+ * Returns formatted string for injection into coordinator prompts.
85
+ *
86
+ * @returns Formatted string of recent failures (empty if none or memory unavailable)
87
+ */
88
+ export declare function getRecentEvalFailures(): Promise<string>;
89
+ interface PromptInsightsOptions {
90
+ role: "coordinator" | "worker";
91
+ project_key?: string;
92
+ files?: string[];
93
+ domain?: string;
94
+ }
95
+ /**
96
+ * Get swarm insights for prompt injection
97
+ *
98
+ * Queries recent swarm outcomes and semantic memory to surface:
99
+ * - Strategy success rates
100
+ * - Common failure modes
101
+ * - Anti-patterns
102
+ * - File/domain-specific learnings
103
+ *
104
+ * Returns formatted string for injection into coordinator or worker prompts.
105
+ *
106
+ * @param options - Role and filters for insights
107
+ * @returns Formatted insights string (empty if no data or errors)
108
+ */
109
+ export declare function getPromptInsights(options: PromptInsightsOptions): Promise<string>;
80
110
  /**
81
111
  * Format the researcher prompt for a documentation research task
82
112
  */
@@ -112,7 +142,7 @@ export declare function formatSubtaskPromptV2(params: {
112
142
  skills_to_load?: string[];
113
143
  coordinator_notes?: string;
114
144
  };
115
- }): string;
145
+ }): Promise<string>;
116
146
  /**
117
147
  * Format the subtask prompt for a specific agent
118
148
  */
@@ -431,4 +461,5 @@ export declare const promptTools: {
431
461
  }, context: import("@opencode-ai/plugin").ToolContext): Promise<string>;
432
462
  };
433
463
  };
464
+ export {};
434
465
  //# sourceMappingURL=swarm-prompts.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"swarm-prompts.d.ts","sourceRoot":"","sources":["../src/swarm-prompts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAUH;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,s6EAkET,CAAC;AAEzB;;GAEG;AACH,eAAO,MAAM,6BAA6B,mxDAyDlB,CAAC;AAEzB;;;;;GAKG;AACH,eAAO,MAAM,cAAc,mkFAgFK,CAAC;AAEjC;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,goUAiUnB,CAAC;AAEZ;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,kBAAkB,mgTAuQ9B,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,4pHA4GV,CAAC;AAErB;;;;;GAKG;AACH,eAAO,MAAM,iCAAiC,u+DAyE7C,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,8jCAmCU,CAAC;AAMzC;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE;IAC7C,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,OAAO,CAAC;CACzB,GAAG,MAAM,CAaT;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EA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8
+
9
+ [oh-my-opencode](https://github.com/code-yeongyu/oh-my-opencode) by **code-yeongyu** is the most feature-rich OpenCode plugin in the wild (2961★). After deep analysis of its architecture, we identified several patterns that would significantly strengthen our swarm coordination.
10
+
11
+ ```
12
+ ┌─────────────────────────────────────────────────────────────────┐
13
+ │ │
14
+ │ "Standing on the shoulders of giants" │
15
+ │ │
16
+ │ oh-my-opencode innovations we're adopting: │
17
+ │ • 7-Section Delegation Protocol │
18
+ │ • Compaction Context Injection │
19
+ │ • Preemptive Compaction (80% threshold) │
20
+ │ • Event + Polling Hybrid for completion detection │
21
+ │ • Parallel Execution Minimums │
22
+ │ • Context-Safe Tool Limits │
23
+ │ │
24
+ └─────────────────────────────────────────────────────────────────┘
25
+ ```
26
+
27
+ ### What oh-my-opencode Does Well
28
+
29
+ 1. **Agent System** - Factory-based registry with model-specific configs, BackgroundManager for async execution, structured delegation prompts
30
+ 2. **21 Lifecycle Hooks** - Compaction handling, session recovery, think-mode auto-switching, external hook protocol
31
+ 3. **Background Agents** - Event + polling hybrid, todo-aware completion, fire-and-forget abort
32
+ 4. **LSP/AST Tools** - Zero-config LSP integration, 11 code intelligence tools, context-safe limits
33
+ 5. **Claude Code Compatibility** - Dual-path config loading, 4 independent loaders, auto-migration
34
+ 6. **Plugin Architecture** - Hook mapping pattern, session-scoped state, graceful degradation
35
+
36
+ ### What We Already Have
37
+
38
+ - Swarm Mail for inter-agent messaging
39
+ - File reservations for conflict prevention
40
+ - UBS scan on completion
41
+ - Hive for work item tracking
42
+ - Worktree isolation (ADR-007)
43
+ - Structured review (ADR-007)
44
+
45
+ ### Gaps This ADR Addresses
46
+
47
+ 1. **Coordinator prompts lack structure** - Workers sometimes go rogue
48
+ 2. **Context compaction loses critical info** - Decomposition strategy, dependency graph forgotten
49
+ 3. **No preemptive compaction** - Sessions die at 100% instead of gracefully compacting at 80%
50
+ 4. **Polling-only completion detection** - Slower than event-driven
51
+ 5. **No parallel execution enforcement** - Researchers call tools sequentially
52
+ 6. **Tool outputs can explode context** - No hard limits on results
53
+
54
+ ## Decision
55
+
56
+ ### 1. 7-Section Delegation Protocol
57
+
58
+ Adopt oh-my-opencode's structured delegation format for coordinator → worker handoffs:
59
+
60
+ ```markdown
61
+ ## TASK
62
+ [Specific task description]
63
+
64
+ ## EXPECTED OUTCOME
65
+ [What success looks like]
66
+
67
+ ## REQUIRED SKILLS
68
+ [Domain knowledge needed]
69
+
70
+ ## REQUIRED TOOLS
71
+ [Tools the worker should use]
72
+
73
+ ## MUST DO
74
+ - [Non-negotiable requirements]
75
+ - [Quality gates]
76
+
77
+ ## MUST NOT DO
78
+ - [Forbidden approaches]
79
+ - [Anti-patterns to avoid]
80
+
81
+ ## CONTEXT
82
+ [Shared context from coordinator]
83
+ [Dependency information]
84
+ [What other workers are doing]
85
+ ```
86
+
87
+ **Implementation:** Update `swarm_subtask_prompt` to generate this format.
88
+
89
+ **Why:** Reduces rogue behavior. Workers have clear boundaries and success criteria.
90
+
91
+ ### 2. Compaction Context Injection
92
+
93
+ Preserve critical information through context compaction by injecting a structured prompt BEFORE the summarization API call:
94
+
95
+ ```markdown
96
+ ## 1. User Requests (As-Is)
97
+ [Exact wording of original requests - preserved verbatim]
98
+
99
+ ## 2. Final Goal
100
+ [End result expected from this session]
101
+
102
+ ## 3. Work Completed
103
+ [Files modified, features implemented, problems solved]
104
+
105
+ ## 4. Remaining Tasks
106
+ [Pending items, follow-ups, blocked work]
107
+
108
+ ## 5. MUST NOT Do
109
+ [Forbidden approaches, failed attempts, anti-patterns discovered]
110
+
111
+ ## 6. Swarm State (if applicable)
112
+ [Epic ID, completed subtasks, in-progress workers, dependency graph]
113
+ ```
114
+
115
+ **Implementation:** Add `experimental.session.compacting` hook that injects this prompt.
116
+
117
+ **Why:** Currently compaction loses decomposition strategy, dependency graph, and failed approaches. Workers repeat mistakes.
118
+
119
+ ### 3. Preemptive Compaction
120
+
121
+ Monitor token usage and trigger compaction at 80% threshold instead of waiting for overflow:
122
+
123
+ ```typescript
124
+ // In chat.message or message.updated hook
125
+ const usageRatio = totalTokens / contextLimit;
126
+ if (usageRatio >= 0.8 && !compactionInProgress.has(sessionID)) {
127
+ compactionInProgress.add(sessionID);
128
+ await ctx.client.session.summarize({ ... });
129
+
130
+ // Auto-resume after compaction
131
+ setTimeout(() => {
132
+ ctx.client.session.promptAsync({ parts: [{ text: "Continue" }] });
133
+ }, 500);
134
+ }
135
+ ```
136
+
137
+ **Configuration:**
138
+ ```json
139
+ {
140
+ "preemptive_compaction": {
141
+ "enabled": true,
142
+ "threshold": 0.8,
143
+ "cooldown_seconds": 300
144
+ }
145
+ }
146
+ ```
147
+
148
+ **Why:** Prevents context overflow mid-work. Coordinators and workers survive long-running epics.
149
+
150
+ ### 4. Event + Polling Hybrid for Completion Detection
151
+
152
+ Currently we only poll for worker completion. Add event-driven detection as primary path:
153
+
154
+ ```typescript
155
+ // Primary: Event-driven (fast)
156
+ event: async ({ event }) => {
157
+ if (event.type === "session.idle") {
158
+ const todos = await client.session.todo();
159
+ if (todos.length === 0) {
160
+ markWorkerComplete(event.properties?.info?.id);
161
+ }
162
+ }
163
+ }
164
+
165
+ // Fallback: Polling (reliable)
166
+ setInterval(() => {
167
+ for (const worker of runningWorkers) {
168
+ const status = await client.session.status(worker.sessionID);
169
+ if (status.type === "idle") {
170
+ // Same completion logic
171
+ }
172
+ }
173
+ }, 2000);
174
+ ```
175
+
176
+ **Why:** Events are faster. Polling catches missed events. Hybrid = reliable + fast.
177
+
178
+ ### 5. Parallel Execution Minimums
179
+
180
+ Enforce minimum parallel tool calls for researcher agents:
181
+
182
+ ```markdown
183
+ ## PARALLEL EXECUTION REQUIREMENTS
184
+
185
+ You MUST launch multiple tools simultaneously in your first action.
186
+ Never call tools sequentially unless output depends on prior result.
187
+
188
+ Minimum parallel calls by request type:
189
+ - TYPE A (conceptual): 3+ tools (context7 + pdf-brain + websearch)
190
+ - TYPE B (implementation): 4+ tools (repo-autopsy + grep + ast-grep + read)
191
+ - TYPE C (comprehensive): 6+ tools (all of the above)
192
+
193
+ WRONG:
194
+ 1. Search for X
195
+ 2. Wait for result
196
+ 3. Search for Y
197
+
198
+ RIGHT:
199
+ [Search X | Search Y | Search Z] → single response
200
+ ```
201
+
202
+ **Implementation:** Add to `swarm-researcher` agent prompt. Enforce via output validation.
203
+
204
+ **Why:** Sequential tool calls waste round-trips and burn context. Parallel = faster + cheaper.
205
+
206
+ ### 6. Context-Safe Tool Limits
207
+
208
+ Add hard limits and truncation reporting to tools that can explode context:
209
+
210
+ | Tool | Limit | Truncation Message |
211
+ |------|-------|-------------------|
212
+ | `repo-autopsy_search` | 100 results | `Found 347 results (showing first 100):` |
213
+ | `cass_search` | 50 results | `Found 89 sessions (showing first 50):` |
214
+ | `find-exports` | 50 results | `Found 72 exports (showing first 50):` |
215
+ | `semantic-memory_find` | 20 results | `Found 45 memories (showing first 20):` |
216
+
217
+ **Implementation:**
218
+ ```typescript
219
+ const MAX_RESULTS = 100;
220
+ const total = results.length;
221
+ const truncated = total > MAX_RESULTS;
222
+ const limited = truncated ? results.slice(0, MAX_RESULTS) : results;
223
+
224
+ if (truncated) {
225
+ output.unshift(`Found ${total} results (showing first ${MAX_RESULTS}):`);
226
+ }
227
+ ```
228
+
229
+ **Why:** Unbounded results kill context. Truncation with count lets agent know there's more.
230
+
231
+ ### 7. Todo-Aware Completion (Bonus)
232
+
233
+ Before marking a worker complete, check if it left unfinished work:
234
+
235
+ ```typescript
236
+ async function canMarkComplete(sessionID: string): Promise<boolean> {
237
+ const todos = await client.session.todo({ path: { id: sessionID } });
238
+ const incomplete = todos.filter(t => t.status !== "completed");
239
+
240
+ if (incomplete.length > 0) {
241
+ // Inject continuation prompt
242
+ await client.session.prompt({
243
+ path: { id: sessionID },
244
+ body: { parts: [{ text: "You have incomplete TODOs. Continue working." }] }
245
+ });
246
+ return false;
247
+ }
248
+ return true;
249
+ }
250
+ ```
251
+
252
+ **Why:** Prevents race conditions where worker marks complete before finishing TODO list.
253
+
254
+ ### 8. Think Mode for Complex Decomposition (Bonus)
255
+
256
+ Auto-enable extended thinking when decomposing complex tasks:
257
+
258
+ ```typescript
259
+ // In chat.params hook
260
+ const complexityIndicators = [
261
+ "decompose", "break down", "plan", "architect",
262
+ "refactor across", "migrate", "redesign"
263
+ ];
264
+
265
+ if (complexityIndicators.some(k => prompt.toLowerCase().includes(k))) {
266
+ output.message.model = { modelID: "claude-sonnet-4-5-high" };
267
+ output.message.thinking = { type: "enabled", budget_tokens: 16000 };
268
+ }
269
+ ```
270
+
271
+ **Why:** Complex decomposition benefits from extended reasoning. Auto-switching removes friction.
272
+
273
+ ## Implementation
274
+
275
+ ### Phase 1: Delegation Protocol + Context Injection (Priority)
276
+ 1. Update `swarm_subtask_prompt` with 7-section format
277
+ 2. Add compaction context injection hook
278
+ 3. Test with existing swarm workflows
279
+
280
+ ### Phase 2: Preemptive Compaction + Event Hybrid
281
+ 1. Add token monitoring to coordinator/worker sessions
282
+ 2. Implement 80% threshold compaction with cooldown
283
+ 3. Add event-driven completion detection
284
+ 4. Keep polling as fallback
285
+
286
+ ### Phase 3: Tool Limits + Parallel Enforcement
287
+ 1. Add limits to repo-autopsy, cass, find-exports, semantic-memory
288
+ 2. Update swarm-researcher prompt with parallel minimums
289
+ 3. Add output validation for parallel enforcement
290
+
291
+ ### Phase 4: Bonus Features
292
+ 1. Todo-aware completion check
293
+ 2. Think mode auto-switching for decomposition
294
+
295
+ ## Consequences
296
+
297
+ ### Positive
298
+ - **Better worker behavior**: 7-section protocol reduces rogue actions
299
+ - **Context survives compaction**: Critical info preserved through summarization
300
+ - **No more context overflow**: Preemptive compaction at 80%
301
+ - **Faster completion detection**: Events + polling hybrid
302
+ - **Cheaper research**: Parallel execution reduces round-trips
303
+ - **Predictable tool output**: Hard limits prevent context explosion
304
+
305
+ ### Negative
306
+ - **More complexity**: Additional hooks and state management
307
+ - **Prompt bloat**: 7-section format is verbose (but worth it)
308
+ - **Compaction overhead**: Preemptive compaction adds latency (but prevents crashes)
309
+
310
+ ### Neutral
311
+ - **Attribution**: All patterns credited to code-yeongyu/oh-my-opencode
312
+ - **Not a fork**: We're adopting patterns, not copying code
313
+
314
+ ## Alternatives Considered
315
+
316
+ ### Copy oh-my-opencode Wholesale
317
+ Could fork and adapt. Rejected because:
318
+ - Different architecture (we have Swarm Mail, Hive, etc.)
319
+ - Our patterns complement theirs, not replace
320
+ - Selective adoption is cleaner
321
+
322
+ ### Skip Compaction Handling
323
+ Could rely on OpenCode's built-in compaction. Rejected because:
324
+ - Default compaction loses swarm-specific context
325
+ - Decomposition strategy, dependency graph critical for workers
326
+
327
+ ### Always Use Extended Thinking
328
+ Could enable thinking for all coordinator actions. Rejected because:
329
+ - Overkill for simple tasks
330
+ - Slower and more expensive
331
+ - Auto-detection is smarter
332
+
333
+ ## References
334
+
335
+ - [oh-my-opencode](https://github.com/code-yeongyu/oh-my-opencode) by code-yeongyu - Primary source
336
+ - [ADR-007](./ADR-007-swarm-enhancements-worktree-review.md) - Worktree isolation + structured review
337
+ - [ADR-008](./ADR-008-worker-handoff-protocol.md) - Worker handoff protocol
338
+
339
+ ## Acknowledgments
340
+
341
+ Major thanks to **code-yeongyu** for building oh-my-opencode and open-sourcing these patterns. The OpenCode ecosystem is stronger because of contributions like this.
342
+
343
+ ```
344
+ ┌─────────────────────────────────────────────────────────────────┐
345
+ │ │
346
+ │ 🐝 "Good artists copy, great artists steal" │
347
+ │ — Picasso (probably misattributed) │
348
+ │ │
349
+ │ We're stealing the good stuff and making it ours. │
350
+ │ With proper attribution, of course. │
351
+ │ │
352
+ └─────────────────────────────────────────────────────────────────┘
353
+ ```