opencode-swarm-plugin 0.43.0 → 0.44.1

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 (208) hide show
  1. package/bin/cass.characterization.test.ts +422 -0
  2. package/bin/swarm.serve.test.ts +6 -4
  3. package/bin/swarm.test.ts +68 -0
  4. package/bin/swarm.ts +81 -8
  5. package/dist/compaction-prompt-scoring.js +139 -0
  6. package/dist/contributor-tools.d.ts +42 -0
  7. package/dist/contributor-tools.d.ts.map +1 -0
  8. package/dist/eval-capture.js +12811 -0
  9. package/dist/hive.d.ts.map +1 -1
  10. package/dist/index.d.ts +12 -0
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +7728 -62590
  13. package/dist/plugin.js +23833 -78695
  14. package/dist/sessions/agent-discovery.d.ts +59 -0
  15. package/dist/sessions/agent-discovery.d.ts.map +1 -0
  16. package/dist/sessions/index.d.ts +10 -0
  17. package/dist/sessions/index.d.ts.map +1 -0
  18. package/dist/swarm-orchestrate.d.ts.map +1 -1
  19. package/dist/swarm-prompts.d.ts.map +1 -1
  20. package/dist/swarm-review.d.ts.map +1 -1
  21. package/package.json +17 -5
  22. package/.changeset/swarm-insights-data-layer.md +0 -63
  23. package/.hive/analysis/eval-failure-analysis-2025-12-25.md +0 -331
  24. package/.hive/analysis/session-data-quality-audit.md +0 -320
  25. package/.hive/eval-results.json +0 -483
  26. package/.hive/issues.jsonl +0 -138
  27. package/.hive/memories.jsonl +0 -729
  28. package/.opencode/eval-history.jsonl +0 -327
  29. package/.turbo/turbo-build.log +0 -9
  30. package/CHANGELOG.md +0 -2255
  31. package/SCORER-ANALYSIS.md +0 -598
  32. package/docs/analysis/subagent-coordination-patterns.md +0 -902
  33. package/docs/analysis-socratic-planner-pattern.md +0 -504
  34. package/docs/planning/ADR-001-monorepo-structure.md +0 -171
  35. package/docs/planning/ADR-002-package-extraction.md +0 -393
  36. package/docs/planning/ADR-003-performance-improvements.md +0 -451
  37. package/docs/planning/ADR-004-message-queue-features.md +0 -187
  38. package/docs/planning/ADR-005-devtools-observability.md +0 -202
  39. package/docs/planning/ADR-007-swarm-enhancements-worktree-review.md +0 -168
  40. package/docs/planning/ADR-008-worker-handoff-protocol.md +0 -293
  41. package/docs/planning/ADR-009-oh-my-opencode-patterns.md +0 -353
  42. package/docs/planning/ROADMAP.md +0 -368
  43. package/docs/semantic-memory-cli-syntax.md +0 -123
  44. package/docs/swarm-mail-architecture.md +0 -1147
  45. package/docs/testing/context-recovery-test.md +0 -470
  46. package/evals/ARCHITECTURE.md +0 -1189
  47. package/evals/README.md +0 -768
  48. package/evals/compaction-prompt.eval.ts +0 -149
  49. package/evals/compaction-resumption.eval.ts +0 -289
  50. package/evals/coordinator-behavior.eval.ts +0 -307
  51. package/evals/coordinator-session.eval.ts +0 -154
  52. package/evals/evalite.config.ts.bak +0 -15
  53. package/evals/example.eval.ts +0 -31
  54. package/evals/fixtures/compaction-cases.ts +0 -350
  55. package/evals/fixtures/compaction-prompt-cases.ts +0 -311
  56. package/evals/fixtures/coordinator-sessions.ts +0 -328
  57. package/evals/fixtures/decomposition-cases.ts +0 -105
  58. package/evals/lib/compaction-loader.test.ts +0 -248
  59. package/evals/lib/compaction-loader.ts +0 -320
  60. package/evals/lib/data-loader.evalite-test.ts +0 -289
  61. package/evals/lib/data-loader.test.ts +0 -345
  62. package/evals/lib/data-loader.ts +0 -281
  63. package/evals/lib/llm.ts +0 -115
  64. package/evals/scorers/compaction-prompt-scorers.ts +0 -145
  65. package/evals/scorers/compaction-scorers.ts +0 -305
  66. package/evals/scorers/coordinator-discipline.evalite-test.ts +0 -539
  67. package/evals/scorers/coordinator-discipline.ts +0 -325
  68. package/evals/scorers/index.test.ts +0 -146
  69. package/evals/scorers/index.ts +0 -328
  70. package/evals/scorers/outcome-scorers.evalite-test.ts +0 -27
  71. package/evals/scorers/outcome-scorers.ts +0 -349
  72. package/evals/swarm-decomposition.eval.ts +0 -121
  73. package/examples/commands/swarm.md +0 -745
  74. package/examples/plugin-wrapper-template.ts +0 -2426
  75. package/examples/skills/hive-workflow/SKILL.md +0 -212
  76. package/examples/skills/skill-creator/SKILL.md +0 -223
  77. package/examples/skills/swarm-coordination/SKILL.md +0 -292
  78. package/global-skills/cli-builder/SKILL.md +0 -344
  79. package/global-skills/cli-builder/references/advanced-patterns.md +0 -244
  80. package/global-skills/learning-systems/SKILL.md +0 -644
  81. package/global-skills/skill-creator/LICENSE.txt +0 -202
  82. package/global-skills/skill-creator/SKILL.md +0 -352
  83. package/global-skills/skill-creator/references/output-patterns.md +0 -82
  84. package/global-skills/skill-creator/references/workflows.md +0 -28
  85. package/global-skills/swarm-coordination/SKILL.md +0 -995
  86. package/global-skills/swarm-coordination/references/coordinator-patterns.md +0 -235
  87. package/global-skills/swarm-coordination/references/strategies.md +0 -138
  88. package/global-skills/system-design/SKILL.md +0 -213
  89. package/global-skills/testing-patterns/SKILL.md +0 -430
  90. package/global-skills/testing-patterns/references/dependency-breaking-catalog.md +0 -586
  91. package/opencode-swarm-plugin-0.30.7.tgz +0 -0
  92. package/opencode-swarm-plugin-0.31.0.tgz +0 -0
  93. package/scripts/cleanup-test-memories.ts +0 -346
  94. package/scripts/init-skill.ts +0 -222
  95. package/scripts/migrate-unknown-sessions.ts +0 -349
  96. package/scripts/validate-skill.ts +0 -204
  97. package/src/agent-mail.ts +0 -1724
  98. package/src/anti-patterns.test.ts +0 -1167
  99. package/src/anti-patterns.ts +0 -448
  100. package/src/compaction-capture.integration.test.ts +0 -257
  101. package/src/compaction-hook.test.ts +0 -838
  102. package/src/compaction-hook.ts +0 -1204
  103. package/src/compaction-observability.integration.test.ts +0 -139
  104. package/src/compaction-observability.test.ts +0 -187
  105. package/src/compaction-observability.ts +0 -324
  106. package/src/compaction-prompt-scorers.test.ts +0 -475
  107. package/src/compaction-prompt-scoring.ts +0 -300
  108. package/src/dashboard.test.ts +0 -611
  109. package/src/dashboard.ts +0 -462
  110. package/src/error-enrichment.test.ts +0 -403
  111. package/src/error-enrichment.ts +0 -219
  112. package/src/eval-capture.test.ts +0 -1015
  113. package/src/eval-capture.ts +0 -929
  114. package/src/eval-gates.test.ts +0 -306
  115. package/src/eval-gates.ts +0 -218
  116. package/src/eval-history.test.ts +0 -508
  117. package/src/eval-history.ts +0 -214
  118. package/src/eval-learning.test.ts +0 -378
  119. package/src/eval-learning.ts +0 -360
  120. package/src/eval-runner.test.ts +0 -223
  121. package/src/eval-runner.ts +0 -402
  122. package/src/export-tools.test.ts +0 -476
  123. package/src/export-tools.ts +0 -257
  124. package/src/hive.integration.test.ts +0 -2241
  125. package/src/hive.ts +0 -1628
  126. package/src/index.ts +0 -935
  127. package/src/learning.integration.test.ts +0 -1815
  128. package/src/learning.ts +0 -1079
  129. package/src/logger.test.ts +0 -189
  130. package/src/logger.ts +0 -135
  131. package/src/mandate-promotion.test.ts +0 -473
  132. package/src/mandate-promotion.ts +0 -239
  133. package/src/mandate-storage.integration.test.ts +0 -601
  134. package/src/mandate-storage.test.ts +0 -578
  135. package/src/mandate-storage.ts +0 -794
  136. package/src/mandates.ts +0 -540
  137. package/src/memory-tools.test.ts +0 -195
  138. package/src/memory-tools.ts +0 -344
  139. package/src/memory.integration.test.ts +0 -334
  140. package/src/memory.test.ts +0 -158
  141. package/src/memory.ts +0 -527
  142. package/src/model-selection.test.ts +0 -188
  143. package/src/model-selection.ts +0 -68
  144. package/src/observability-tools.test.ts +0 -359
  145. package/src/observability-tools.ts +0 -871
  146. package/src/output-guardrails.test.ts +0 -438
  147. package/src/output-guardrails.ts +0 -381
  148. package/src/pattern-maturity.test.ts +0 -1160
  149. package/src/pattern-maturity.ts +0 -525
  150. package/src/planning-guardrails.test.ts +0 -491
  151. package/src/planning-guardrails.ts +0 -438
  152. package/src/plugin.ts +0 -23
  153. package/src/post-compaction-tracker.test.ts +0 -251
  154. package/src/post-compaction-tracker.ts +0 -237
  155. package/src/query-tools.test.ts +0 -636
  156. package/src/query-tools.ts +0 -324
  157. package/src/rate-limiter.integration.test.ts +0 -466
  158. package/src/rate-limiter.ts +0 -774
  159. package/src/replay-tools.test.ts +0 -496
  160. package/src/replay-tools.ts +0 -240
  161. package/src/repo-crawl.integration.test.ts +0 -441
  162. package/src/repo-crawl.ts +0 -610
  163. package/src/schemas/cell-events.test.ts +0 -347
  164. package/src/schemas/cell-events.ts +0 -807
  165. package/src/schemas/cell.ts +0 -257
  166. package/src/schemas/evaluation.ts +0 -166
  167. package/src/schemas/index.test.ts +0 -199
  168. package/src/schemas/index.ts +0 -286
  169. package/src/schemas/mandate.ts +0 -232
  170. package/src/schemas/swarm-context.ts +0 -115
  171. package/src/schemas/task.ts +0 -161
  172. package/src/schemas/worker-handoff.test.ts +0 -302
  173. package/src/schemas/worker-handoff.ts +0 -131
  174. package/src/skills.integration.test.ts +0 -1192
  175. package/src/skills.test.ts +0 -643
  176. package/src/skills.ts +0 -1549
  177. package/src/storage.integration.test.ts +0 -341
  178. package/src/storage.ts +0 -884
  179. package/src/structured.integration.test.ts +0 -817
  180. package/src/structured.test.ts +0 -1046
  181. package/src/structured.ts +0 -762
  182. package/src/swarm-decompose.test.ts +0 -188
  183. package/src/swarm-decompose.ts +0 -1302
  184. package/src/swarm-deferred.integration.test.ts +0 -157
  185. package/src/swarm-deferred.test.ts +0 -38
  186. package/src/swarm-insights.test.ts +0 -214
  187. package/src/swarm-insights.ts +0 -459
  188. package/src/swarm-mail.integration.test.ts +0 -970
  189. package/src/swarm-mail.ts +0 -739
  190. package/src/swarm-orchestrate.integration.test.ts +0 -282
  191. package/src/swarm-orchestrate.test.ts +0 -548
  192. package/src/swarm-orchestrate.ts +0 -3084
  193. package/src/swarm-prompts.test.ts +0 -1270
  194. package/src/swarm-prompts.ts +0 -2077
  195. package/src/swarm-research.integration.test.ts +0 -701
  196. package/src/swarm-research.test.ts +0 -698
  197. package/src/swarm-research.ts +0 -472
  198. package/src/swarm-review.integration.test.ts +0 -285
  199. package/src/swarm-review.test.ts +0 -879
  200. package/src/swarm-review.ts +0 -709
  201. package/src/swarm-strategies.ts +0 -407
  202. package/src/swarm-worktree.test.ts +0 -501
  203. package/src/swarm-worktree.ts +0 -575
  204. package/src/swarm.integration.test.ts +0 -2377
  205. package/src/swarm.ts +0 -38
  206. package/src/tool-adapter.integration.test.ts +0 -1221
  207. package/src/tool-availability.ts +0 -461
  208. package/tsconfig.json +0 -28
@@ -1,644 +0,0 @@
1
- ---
2
- name: learning-systems
3
- description: Implicit feedback scoring, confidence decay, and anti-pattern detection. Use when understanding how the swarm plugin learns from outcomes, implementing learning loops, or debugging why patterns are being promoted or deprecated. Unique to opencode-swarm-plugin.
4
- ---
5
-
6
- # Learning Systems
7
-
8
- The swarm plugin learns from task outcomes to improve decomposition quality over time. Three interconnected systems track pattern effectiveness: implicit feedback scoring, confidence decay, and pattern maturity progression.
9
-
10
- ## Implicit Feedback Scoring
11
-
12
- Convert task outcomes into learning signals without explicit user feedback.
13
-
14
- ### What Gets Scored
15
-
16
- **Duration signals:**
17
-
18
- - Fast (<5 min) = helpful (1.0)
19
- - Medium (5-30 min) = neutral (0.6)
20
- - Slow (>30 min) = harmful (0.2)
21
-
22
- **Error signals:**
23
-
24
- - 0 errors = helpful (1.0)
25
- - 1-2 errors = neutral (0.6)
26
- - 3+ errors = harmful (0.2)
27
-
28
- **Retry signals:**
29
-
30
- - 0 retries = helpful (1.0)
31
- - 1 retry = neutral (0.7)
32
- - 2+ retries = harmful (0.3)
33
-
34
- **Success signal:**
35
-
36
- - Success = 1.0 (40% weight)
37
- - Failure = 0.0
38
-
39
- ### Weighted Score Calculation
40
-
41
- ```typescript
42
- rawScore = success * 0.4 + duration * 0.2 + errors * 0.2 + retries * 0.2;
43
- ```
44
-
45
- **Thresholds:**
46
-
47
- - rawScore >= 0.7 → helpful
48
- - rawScore <= 0.4 → harmful
49
- - 0.4 < rawScore < 0.7 → neutral
50
-
51
- ### Recording Outcomes
52
-
53
- Call `swarm_record_outcome` after subtask completion:
54
-
55
- ```typescript
56
- swarm_record_outcome({
57
- bead_id: "bd-123.1",
58
- duration_ms: 180000, // 3 minutes
59
- error_count: 0,
60
- retry_count: 0,
61
- success: true,
62
- files_touched: ["src/auth.ts"],
63
- strategy: "file-based",
64
- });
65
- ```
66
-
67
- **Fields tracked:**
68
-
69
- - `bead_id` - subtask identifier
70
- - `duration_ms` - time from start to completion
71
- - `error_count` - errors encountered (from ErrorAccumulator)
72
- - `retry_count` - number of retry attempts
73
- - `success` - whether subtask completed successfully
74
- - `files_touched` - modified file paths
75
- - `strategy` - decomposition strategy used (optional)
76
- - `failure_mode` - classification if success=false (optional)
77
- - `failure_details` - error context (optional)
78
-
79
- ## Confidence Decay
80
-
81
- Evaluation criteria weights fade unless revalidated. Prevents stale patterns from dominating future decompositions.
82
-
83
- ### Half-Life Formula
84
-
85
- ```
86
- decayed_value = raw_value * 0.5^(age_days / 90)
87
- ```
88
-
89
- **Decay timeline:**
90
-
91
- - Day 0: 100% weight
92
- - Day 90: 50% weight
93
- - Day 180: 25% weight
94
- - Day 270: 12.5% weight
95
-
96
- ### Criterion Weight Calculation
97
-
98
- Aggregate decayed feedback events:
99
-
100
- ```typescript
101
- helpfulSum = sum(helpful_events.map((e) => e.raw_value * decay(e.timestamp)));
102
- harmfulSum = sum(harmful_events.map((e) => e.raw_value * decay(e.timestamp)));
103
- weight = max(0.1, helpfulSum / (helpfulSum + harmfulSum));
104
- ```
105
-
106
- **Weight floor:** minimum 0.1 prevents complete zeroing
107
-
108
- ### Revalidation
109
-
110
- Recording new feedback resets decay timer for that criterion:
111
-
112
- ```typescript
113
- {
114
- criterion: "type_safe",
115
- weight: 0.85,
116
- helpful_count: 12,
117
- harmful_count: 3,
118
- last_validated: "2024-12-12T00:00:00Z", // Reset on new feedback
119
- half_life_days: 90,
120
- }
121
- ```
122
-
123
- ### When Criteria Get Deprecated
124
-
125
- ```typescript
126
- total = helpful_count + harmful_count;
127
- harmfulRatio = harmful_count / total;
128
-
129
- if (total >= 3 && harmfulRatio > 0.3) {
130
- // Deprecate criterion - reduce impact to 0
131
- }
132
- ```
133
-
134
- ## Pattern Maturity States
135
-
136
- Patterns progress through lifecycle based on feedback accumulation:
137
-
138
- **candidate** → **established** → **proven** (or **deprecated**)
139
-
140
- ### State Transitions
141
-
142
- **candidate (initial state):**
143
-
144
- - Total feedback < 3 events
145
- - Not enough data to judge
146
- - Multiplier: 0.5x
147
-
148
- **established:**
149
-
150
- - Total feedback >= 3 events
151
- - Has track record but not proven
152
- - Multiplier: 1.0x
153
-
154
- **proven:**
155
-
156
- - Decayed helpful >= 5 AND
157
- - Harmful ratio < 15%
158
- - Multiplier: 1.5x
159
-
160
- **deprecated:**
161
-
162
- - Harmful ratio > 30% AND
163
- - Total feedback >= 3 events
164
- - Multiplier: 0x (excluded)
165
-
166
- ### Decay Applied to State Calculation
167
-
168
- State determination uses decayed counts, not raw counts:
169
-
170
- ```typescript
171
- const { decayedHelpful, decayedHarmful } =
172
- calculateDecayedCounts(feedbackEvents);
173
- const total = decayedHelpful + decayedHarmful;
174
- const harmfulRatio = decayedHarmful / total;
175
-
176
- // State logic applies to decayed values
177
- ```
178
-
179
- Old feedback matters less. Pattern must maintain recent positive signal to stay proven.
180
-
181
- ### Manual State Changes
182
-
183
- **Promote to proven:**
184
-
185
- ```typescript
186
- promotePattern(maturity); // External validation confirms effectiveness
187
- ```
188
-
189
- **Deprecate:**
190
-
191
- ```typescript
192
- deprecatePattern(maturity, "Causes file conflicts in 80% of cases");
193
- ```
194
-
195
- Cannot promote deprecated patterns. Must reset.
196
-
197
- ### Multipliers in Decomposition
198
-
199
- Apply maturity multiplier to pattern scores:
200
-
201
- ```typescript
202
- const multipliers = {
203
- candidate: 0.5,
204
- established: 1.0,
205
- proven: 1.5,
206
- deprecated: 0,
207
- };
208
-
209
- pattern_score = base_score * multipliers[maturity.state];
210
- ```
211
-
212
- Proven patterns get 50% boost, deprecated patterns excluded entirely.
213
-
214
- ## Anti-Pattern Inversion
215
-
216
- Failed patterns auto-convert to anti-patterns at >60% failure rate.
217
-
218
- ### Inversion Threshold
219
-
220
- ```typescript
221
- const total = pattern.success_count + pattern.failure_count;
222
-
223
- if (total >= 3 && pattern.failure_count / total >= 0.6) {
224
- invertToAntiPattern(pattern, reason);
225
- }
226
- ```
227
-
228
- **Minimum observations:** 3 total (prevents hasty inversion)
229
- **Failure ratio:** 60% (3+ failures in 5 attempts)
230
-
231
- ### Inversion Process
232
-
233
- **Original pattern:**
234
-
235
- ```typescript
236
- {
237
- id: "pattern-123",
238
- content: "Split by file type",
239
- kind: "pattern",
240
- is_negative: false,
241
- success_count: 2,
242
- failure_count: 5,
243
- }
244
- ```
245
-
246
- **Inverted anti-pattern:**
247
-
248
- ```typescript
249
- {
250
- id: "anti-pattern-123",
251
- content: "AVOID: Split by file type. Failed 5/7 times (71% failure rate)",
252
- kind: "anti_pattern",
253
- is_negative: true,
254
- success_count: 2,
255
- failure_count: 5,
256
- reason: "Failed 5/7 times (71% failure rate)",
257
- }
258
- ```
259
-
260
- ### Recording Observations
261
-
262
- Track pattern outcomes to accumulate success/failure counts:
263
-
264
- ```typescript
265
- recordPatternObservation(
266
- pattern,
267
- success: true, // or false
268
- beadId: "bd-123.1",
269
- )
270
-
271
- // Returns:
272
- {
273
- pattern: updatedPattern,
274
- inversion?: {
275
- original: pattern,
276
- inverted: antiPattern,
277
- reason: "Failed 5/7 times (71% failure rate)",
278
- }
279
- }
280
- ```
281
-
282
- ### Pattern Extraction
283
-
284
- Auto-detect strategies from decomposition descriptions:
285
-
286
- ```typescript
287
- extractPatternsFromDescription(
288
- "We'll split by file type, one file per subtask",
289
- );
290
-
291
- // Returns: ["Split by file type", "One file per subtask"]
292
- ```
293
-
294
- **Detected strategies:**
295
-
296
- - Split by file type
297
- - Split by component
298
- - Split by layer (UI/logic/data)
299
- - Split by feature
300
- - One file per subtask
301
- - Handle shared types first
302
- - Separate API routes
303
- - Tests alongside implementation
304
- - Tests in separate subtask
305
- - Maximize parallelization
306
- - Sequential execution order
307
- - Respect dependency chain
308
-
309
- ### Using Anti-Patterns in Prompts
310
-
311
- Format for decomposition prompt inclusion:
312
-
313
- ```typescript
314
- formatAntiPatternsForPrompt(patterns);
315
- ```
316
-
317
- **Output:**
318
-
319
- ```markdown
320
- ## Anti-Patterns to Avoid
321
-
322
- Based on past failures, avoid these decomposition strategies:
323
-
324
- - AVOID: Split by file type. Failed 12/15 times (80% failure rate)
325
- - AVOID: One file per subtask. Failed 8/10 times (80% failure rate)
326
- ```
327
-
328
- ## Error Accumulator
329
-
330
- Track errors during subtask execution for retry prompts and outcome scoring.
331
-
332
- ### Error Types
333
-
334
- ```typescript
335
- type ErrorType =
336
- | "validation" // Schema/type errors
337
- | "timeout" // Task exceeded time limit
338
- | "conflict" // File reservation conflicts
339
- | "tool_failure" // Tool invocation failed
340
- | "unknown"; // Unclassified
341
- ```
342
-
343
- ### Recording Errors
344
-
345
- ```typescript
346
- errorAccumulator.recordError(
347
- beadId: "bd-123.1",
348
- errorType: "validation",
349
- message: "Type error in src/auth.ts",
350
- options: {
351
- stack_trace: "...",
352
- tool_name: "typecheck",
353
- context: "After adding OAuth types",
354
- }
355
- )
356
- ```
357
-
358
- ### Generating Error Context
359
-
360
- Format accumulated errors for retry prompts:
361
-
362
- ```typescript
363
- const context = await errorAccumulator.getErrorContext(
364
- beadId: "bd-123.1",
365
- includeResolved: false,
366
- )
367
- ```
368
-
369
- **Output:**
370
-
371
- ```markdown
372
- ## Previous Errors
373
-
374
- The following errors were encountered during execution:
375
-
376
- ### validation (2 errors)
377
-
378
- - **Type error in src/auth.ts**
379
- - Context: After adding OAuth types
380
- - Tool: typecheck
381
- - Time: 12/12/2024, 10:30 AM
382
-
383
- - **Missing import in src/session.ts**
384
- - Tool: typecheck
385
- - Time: 12/12/2024, 10:35 AM
386
-
387
- **Action Required**: Address these errors before proceeding. Consider:
388
-
389
- - What caused each error?
390
- - How can you prevent similar errors?
391
- - Are there patterns across error types?
392
- ```
393
-
394
- ### Resolving Errors
395
-
396
- Mark errors resolved after fixing:
397
-
398
- ```typescript
399
- await errorAccumulator.resolveError(errorId);
400
- ```
401
-
402
- Resolved errors excluded from retry context by default.
403
-
404
- ### Error Statistics
405
-
406
- Get error counts for outcome tracking:
407
-
408
- ```typescript
409
- const stats = await errorAccumulator.getErrorStats("bd-123.1")
410
-
411
- // Returns:
412
- {
413
- total: 5,
414
- unresolved: 2,
415
- by_type: {
416
- validation: 3,
417
- timeout: 1,
418
- tool_failure: 1,
419
- }
420
- }
421
- ```
422
-
423
- Use `total` for `error_count` in outcome signals.
424
-
425
- ## Using the Learning System
426
-
427
- ### Integration Points
428
-
429
- **1. During decomposition (swarm_plan_prompt):**
430
-
431
- - Query CASS for similar tasks
432
- - Load pattern maturity records
433
- - Include proven patterns in prompt
434
- - Exclude deprecated patterns
435
-
436
- **2. During execution:**
437
-
438
- - ErrorAccumulator tracks errors
439
- - Record retry attempts
440
- - Track duration from start to completion
441
-
442
- **3. After completion (swarm_complete):**
443
-
444
- - Record outcome signals
445
- - Score implicit feedback
446
- - Update pattern observations
447
- - Check for anti-pattern inversions
448
- - Update maturity states
449
-
450
- ### Full Workflow Example
451
-
452
- ```typescript
453
- // 1. Decomposition phase
454
- const cass_results = cass_search({ query: "user authentication", limit: 5 });
455
- const patterns = loadPatterns(); // Get maturity records
456
- const prompt = swarm_plan_prompt({
457
- task: "Add OAuth",
458
- context: formatPatternsWithMaturityForPrompt(patterns),
459
- query_cass: true,
460
- });
461
-
462
- // 2. Execution phase
463
- const errorAccumulator = new ErrorAccumulator();
464
- const startTime = Date.now();
465
-
466
- try {
467
- // Work happens...
468
- await implement_subtask();
469
- } catch (error) {
470
- await errorAccumulator.recordError(
471
- bead_id,
472
- classifyError(error),
473
- error.message,
474
- );
475
- retryCount++;
476
- }
477
-
478
- // 3. Completion phase
479
- const duration = Date.now() - startTime;
480
- const errorStats = await errorAccumulator.getErrorStats(bead_id);
481
-
482
- swarm_record_outcome({
483
- bead_id,
484
- duration_ms: duration,
485
- error_count: errorStats.total,
486
- retry_count: retryCount,
487
- success: true,
488
- files_touched: modifiedFiles,
489
- strategy: "file-based",
490
- });
491
-
492
- // 4. Learning updates
493
- const scored = scoreImplicitFeedback({
494
- bead_id,
495
- duration_ms: duration,
496
- error_count: errorStats.total,
497
- retry_count: retryCount,
498
- success: true,
499
- timestamp: new Date().toISOString(),
500
- strategy: "file-based",
501
- });
502
-
503
- // Update patterns
504
- for (const pattern of extractedPatterns) {
505
- const { pattern: updated, inversion } = recordPatternObservation(
506
- pattern,
507
- scored.type === "helpful",
508
- bead_id,
509
- );
510
-
511
- if (inversion) {
512
- console.log(`Pattern inverted: ${inversion.reason}`);
513
- storeAntiPattern(inversion.inverted);
514
- }
515
- }
516
- ```
517
-
518
- ### Configuration Tuning
519
-
520
- Adjust thresholds based on project characteristics:
521
-
522
- ```typescript
523
- const learningConfig = {
524
- halfLifeDays: 90, // Decay speed
525
- minFeedbackForAdjustment: 3, // Min observations for weight adjustment
526
- maxHarmfulRatio: 0.3, // Max harmful % before deprecating criterion
527
- fastCompletionThresholdMs: 300000, // 5 min = fast
528
- slowCompletionThresholdMs: 1800000, // 30 min = slow
529
- maxErrorsForHelpful: 2, // Max errors before marking harmful
530
- };
531
-
532
- const antiPatternConfig = {
533
- minObservations: 3, // Min before inversion
534
- failureRatioThreshold: 0.6, // 60% failure triggers inversion
535
- antiPatternPrefix: "AVOID: ",
536
- };
537
-
538
- const maturityConfig = {
539
- minFeedback: 3, // Min for leaving candidate state
540
- minHelpful: 5, // Decayed helpful threshold for proven
541
- maxHarmful: 0.15, // Max 15% harmful for proven
542
- deprecationThreshold: 0.3, // 30% harmful triggers deprecation
543
- halfLifeDays: 90,
544
- };
545
- ```
546
-
547
- ### Debugging Pattern Issues
548
-
549
- **Why is pattern not proven?**
550
-
551
- Check decayed counts:
552
-
553
- ```typescript
554
- const feedback = await getFeedback(patternId);
555
- const { decayedHelpful, decayedHarmful } = calculateDecayedCounts(feedback);
556
-
557
- console.log({ decayedHelpful, decayedHarmful });
558
- // Need: decayedHelpful >= 5 AND harmfulRatio < 0.15
559
- ```
560
-
561
- **Why was pattern inverted?**
562
-
563
- Check observation counts:
564
-
565
- ```typescript
566
- const total = pattern.success_count + pattern.failure_count;
567
- const failureRatio = pattern.failure_count / total;
568
-
569
- console.log({ total, failureRatio });
570
- // Inverts if: total >= 3 AND failureRatio >= 0.6
571
- ```
572
-
573
- **Why is criterion weight low?**
574
-
575
- Check feedback events:
576
-
577
- ```typescript
578
- const events = await getFeedbackByCriterion("type_safe");
579
- const weight = calculateCriterionWeight(events);
580
-
581
- console.log(weight);
582
- // Shows: helpful vs harmful counts, last_validated date
583
- ```
584
-
585
- ## Storage Interfaces
586
-
587
- ### FeedbackStorage
588
-
589
- Persist feedback events for criterion weight calculation:
590
-
591
- ```typescript
592
- interface FeedbackStorage {
593
- store(event: FeedbackEvent): Promise<void>;
594
- getByCriterion(criterion: string): Promise<FeedbackEvent[]>;
595
- getByBead(beadId: string): Promise<FeedbackEvent[]>;
596
- getAll(): Promise<FeedbackEvent[]>;
597
- }
598
- ```
599
-
600
- ### ErrorStorage
601
-
602
- Persist errors for retry prompts:
603
-
604
- ```typescript
605
- interface ErrorStorage {
606
- store(entry: ErrorEntry): Promise<void>;
607
- getByBead(beadId: string): Promise<ErrorEntry[]>;
608
- getUnresolvedByBead(beadId: string): Promise<ErrorEntry[]>;
609
- markResolved(id: string): Promise<void>;
610
- getAll(): Promise<ErrorEntry[]>;
611
- }
612
- ```
613
-
614
- ### PatternStorage
615
-
616
- Persist decomposition patterns:
617
-
618
- ```typescript
619
- interface PatternStorage {
620
- store(pattern: DecompositionPattern): Promise<void>;
621
- get(id: string): Promise<DecompositionPattern | null>;
622
- getAll(): Promise<DecompositionPattern[]>;
623
- getAntiPatterns(): Promise<DecompositionPattern[]>;
624
- getByTag(tag: string): Promise<DecompositionPattern[]>;
625
- findByContent(content: string): Promise<DecompositionPattern[]>;
626
- }
627
- ```
628
-
629
- ### MaturityStorage
630
-
631
- Persist pattern maturity records:
632
-
633
- ```typescript
634
- interface MaturityStorage {
635
- store(maturity: PatternMaturity): Promise<void>;
636
- get(patternId: string): Promise<PatternMaturity | null>;
637
- getAll(): Promise<PatternMaturity[]>;
638
- getByState(state: MaturityState): Promise<PatternMaturity[]>;
639
- storeFeedback(feedback: MaturityFeedback): Promise<void>;
640
- getFeedback(patternId: string): Promise<MaturityFeedback[]>;
641
- }
642
- ```
643
-
644
- In-memory implementations provided for testing. Production should use persistent storage (file-based JSONL or SQLite).