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,306 +0,0 @@
1
- /**
2
- * Tests for progressive eval gates
3
- *
4
- * TDD approach:
5
- * RED: Tests written first, all failing
6
- * GREEN: Minimal implementation to pass
7
- * REFACTOR: Clean up while keeping tests green
8
- */
9
- import { afterEach, beforeEach, describe, expect, test } from "bun:test";
10
- import * as fs from "node:fs";
11
- import { checkGate } from "./eval-gates.js";
12
- import { recordEvalRun } from "./eval-history.js";
13
-
14
- const TEST_PROJECT = "/tmp/eval-gates-test";
15
-
16
- beforeEach(() => {
17
- // Clean slate for each test
18
- if (fs.existsSync(TEST_PROJECT)) {
19
- fs.rmSync(TEST_PROJECT, { recursive: true });
20
- }
21
- fs.mkdirSync(TEST_PROJECT, { recursive: true });
22
- });
23
-
24
- afterEach(() => {
25
- // Cleanup
26
- if (fs.existsSync(TEST_PROJECT)) {
27
- fs.rmSync(TEST_PROJECT, { recursive: true });
28
- }
29
- });
30
-
31
- /**
32
- * Helper to create run history
33
- */
34
- function seedHistory(evalName: string, scores: number[]): void {
35
- for (let i = 0; i < scores.length; i++) {
36
- recordEvalRun(TEST_PROJECT, {
37
- timestamp: new Date(Date.now() + i * 1000).toISOString(),
38
- eval_name: evalName,
39
- score: scores[i],
40
- run_count: i + 1,
41
- });
42
- }
43
- }
44
-
45
- describe("checkGate - Bootstrap Phase (<10 runs)", () => {
46
- test("always passes with 0 runs", () => {
47
- const result = checkGate(TEST_PROJECT, "my-eval", 0.5);
48
-
49
- expect(result.passed).toBe(true);
50
- expect(result.phase).toBe("bootstrap");
51
- expect(result.message).toContain("Bootstrap phase");
52
- });
53
-
54
- test("always passes with 9 runs, even with score drop", () => {
55
- seedHistory("my-eval", [0.9, 0.88, 0.87, 0.86, 0.85, 0.84, 0.83, 0.82, 0.81]);
56
-
57
- const result = checkGate(TEST_PROJECT, "my-eval", 0.5); // 50% drop
58
-
59
- expect(result.passed).toBe(true);
60
- expect(result.phase).toBe("bootstrap");
61
- expect(result.message).toContain("Bootstrap phase");
62
- });
63
-
64
- test("provides run count in message", () => {
65
- seedHistory("my-eval", [0.8, 0.8, 0.8]);
66
-
67
- const result = checkGate(TEST_PROJECT, "my-eval", 0.75);
68
-
69
- expect(result.message).toContain("3/10");
70
- });
71
- });
72
-
73
- describe("checkGate - Stabilization Phase (10-50 runs)", () => {
74
- test("exactly 10 runs enters stabilization", () => {
75
- seedHistory("my-eval", Array(10).fill(0.85));
76
-
77
- const result = checkGate(TEST_PROJECT, "my-eval", 0.84);
78
-
79
- expect(result.phase).toBe("stabilization");
80
- });
81
-
82
- test("passes with <10% regression", () => {
83
- seedHistory("my-eval", Array(15).fill(0.9));
84
-
85
- const result = checkGate(TEST_PROJECT, "my-eval", 0.82); // 8.8% drop
86
-
87
- expect(result.passed).toBe(true);
88
- expect(result.phase).toBe("stabilization");
89
- expect(result.message).toContain("acceptable");
90
- });
91
-
92
- test("WARNS on >10% regression but still passes", () => {
93
- seedHistory("my-eval", Array(15).fill(0.9));
94
-
95
- const result = checkGate(TEST_PROJECT, "my-eval", 0.8); // 11.1% drop
96
-
97
- expect(result.passed).toBe(true); // Still passes in stabilization
98
- expect(result.phase).toBe("stabilization");
99
- expect(result.message).toContain("regression");
100
- expect(result.message).toMatch(/10%|11%/); // Should mention threshold
101
- });
102
-
103
- test("edge case: exactly 10% regression", () => {
104
- seedHistory("my-eval", Array(20).fill(0.9));
105
-
106
- const result = checkGate(TEST_PROJECT, "my-eval", 0.81); // Exactly 10% drop
107
-
108
- expect(result.passed).toBe(true);
109
- expect(result.phase).toBe("stabilization");
110
- });
111
-
112
- test("passes with score improvement", () => {
113
- seedHistory("my-eval", Array(25).fill(0.8));
114
-
115
- const result = checkGate(TEST_PROJECT, "my-eval", 0.95);
116
-
117
- expect(result.passed).toBe(true);
118
- expect(result.message).toContain("acceptable");
119
- });
120
-
121
- test("exactly 50 runs still in stabilization", () => {
122
- seedHistory("my-eval", Array(50).fill(0.85));
123
-
124
- const result = checkGate(TEST_PROJECT, "my-eval", 0.84);
125
-
126
- expect(result.phase).toBe("stabilization");
127
- });
128
- });
129
-
130
- describe("checkGate - Production Phase (>50 runs + variance <0.1)", () => {
131
- test("enters production with 51 stable runs", () => {
132
- seedHistory("my-eval", Array(51).fill(0.85));
133
-
134
- const result = checkGate(TEST_PROJECT, "my-eval", 0.84);
135
-
136
- expect(result.phase).toBe("production");
137
- });
138
-
139
- test("FAILS on >5% regression in production", () => {
140
- seedHistory("my-eval", Array(60).fill(0.9));
141
-
142
- const result = checkGate(TEST_PROJECT, "my-eval", 0.84); // 6.7% drop
143
-
144
- expect(result.passed).toBe(false);
145
- expect(result.phase).toBe("production");
146
- expect(result.message).toContain("FAIL");
147
- expect(result.message).toMatch(/5%|6%/);
148
- });
149
-
150
- test("passes with <5% regression in production", () => {
151
- seedHistory("my-eval", Array(60).fill(0.9));
152
-
153
- const result = checkGate(TEST_PROJECT, "my-eval", 0.86); // 4.4% drop
154
-
155
- expect(result.passed).toBe(true);
156
- expect(result.phase).toBe("production");
157
- expect(result.message).toContain("acceptable");
158
- });
159
-
160
- test("edge case: exactly 5% regression", () => {
161
- seedHistory("my-eval", Array(60).fill(0.9));
162
-
163
- const result = checkGate(TEST_PROJECT, "my-eval", 0.855); // Exactly 5% drop
164
-
165
- expect(result.passed).toBe(true);
166
- expect(result.phase).toBe("production");
167
- });
168
-
169
- test("stays in stabilization if variance too high (>0.1) despite >50 runs", () => {
170
- // Need significant wild variance to push above 0.1
171
- // From memory: 60 stable + 50 alternating wild = variance ~0.103
172
- const stableRuns = Array(60).fill(0.85);
173
- const wildRuns = Array(50)
174
- .fill(0)
175
- .map((_, i) => (i % 2 === 0 ? 0.1 : 0.9));
176
- seedHistory("my-eval", [...stableRuns, ...wildRuns]);
177
-
178
- const result = checkGate(TEST_PROJECT, "my-eval", 0.84);
179
-
180
- expect(result.phase).toBe("stabilization");
181
- expect(result.message).toContain("variance");
182
- });
183
-
184
- test("passes with score improvement in production", () => {
185
- seedHistory("my-eval", Array(60).fill(0.8));
186
-
187
- const result = checkGate(TEST_PROJECT, "my-eval", 0.95);
188
-
189
- expect(result.passed).toBe(true);
190
- expect(result.phase).toBe("production");
191
- });
192
- });
193
-
194
- describe("checkGate - Baseline Calculation", () => {
195
- test("uses mean of all historical scores as baseline", () => {
196
- // Need 10+ runs to exit bootstrap and see baseline in message
197
- seedHistory("my-eval", [0.8, 0.85, 0.9, 0.95, 1.0, 0.9, 0.9, 0.9, 0.9, 0.9]); // mean = 0.9
198
-
199
- const result = checkGate(TEST_PROJECT, "my-eval", 0.88);
200
-
201
- // 0.88 is ~2.2% drop from 0.9 mean (within stabilization tolerance)
202
- expect(result.passed).toBe(true);
203
- expect(result.message).toContain("0.90"); // Should show baseline
204
- });
205
-
206
- test("handles different eval names independently", () => {
207
- seedHistory("eval-a", Array(15).fill(0.9));
208
- seedHistory("eval-b", Array(15).fill(0.5));
209
-
210
- const resultA = checkGate(TEST_PROJECT, "eval-a", 0.88);
211
- const resultB = checkGate(TEST_PROJECT, "eval-b", 0.48);
212
-
213
- expect(resultA.passed).toBe(true);
214
- expect(resultB.passed).toBe(true);
215
- });
216
- });
217
-
218
- describe("checkGate - Edge Cases", () => {
219
- test("handles score of 0", () => {
220
- seedHistory("my-eval", Array(15).fill(0.8));
221
-
222
- const result = checkGate(TEST_PROJECT, "my-eval", 0);
223
-
224
- expect(result.passed).toBe(true); // Still passes in stabilization with warning
225
- expect(result.message).toContain("regression");
226
- });
227
-
228
- test("handles perfect score of 1.0", () => {
229
- seedHistory("my-eval", Array(15).fill(0.9));
230
-
231
- const result = checkGate(TEST_PROJECT, "my-eval", 1.0);
232
-
233
- expect(result.passed).toBe(true);
234
- });
235
-
236
- test("handles no history file (first run)", () => {
237
- // No seedHistory call - empty project
238
-
239
- const result = checkGate(TEST_PROJECT, "my-eval", 0.75);
240
-
241
- expect(result.passed).toBe(true);
242
- expect(result.phase).toBe("bootstrap");
243
- });
244
-
245
- test("handles baseline of 0 (avoid division by zero)", () => {
246
- seedHistory("my-eval", Array(15).fill(0));
247
-
248
- const result = checkGate(TEST_PROJECT, "my-eval", 0.5);
249
-
250
- expect(result.passed).toBe(true);
251
- expect(result.message).not.toContain("NaN");
252
- expect(result.message).not.toContain("Infinity");
253
- });
254
- });
255
-
256
- describe("checkGate - Configurable Thresholds", () => {
257
- test("accepts custom stabilization threshold", () => {
258
- seedHistory("my-eval", Array(15).fill(0.9));
259
-
260
- // 15% regression with custom 20% threshold - should pass
261
- const result = checkGate(TEST_PROJECT, "my-eval", 0.765, {
262
- stabilizationThreshold: 0.2, // 20% instead of default 10%
263
- });
264
-
265
- expect(result.passed).toBe(true);
266
- expect(result.phase).toBe("stabilization");
267
- expect(result.message).toContain("acceptable");
268
- });
269
-
270
- test("accepts custom production threshold", () => {
271
- seedHistory("my-eval", Array(60).fill(0.9));
272
-
273
- // 7% regression with custom 10% threshold - should pass
274
- const result = checkGate(TEST_PROJECT, "my-eval", 0.837, {
275
- productionThreshold: 0.1, // 10% instead of default 5%
276
- });
277
-
278
- expect(result.passed).toBe(true);
279
- expect(result.phase).toBe("production");
280
- });
281
-
282
- test("custom threshold makes test fail when exceeded", () => {
283
- seedHistory("my-eval", Array(60).fill(0.9));
284
-
285
- // 7% regression with custom 3% threshold - should fail
286
- const result = checkGate(TEST_PROJECT, "my-eval", 0.837, {
287
- productionThreshold: 0.03, // 3% instead of default 5%
288
- });
289
-
290
- expect(result.passed).toBe(false);
291
- expect(result.phase).toBe("production");
292
- expect(result.message).toContain("FAIL");
293
- });
294
-
295
- test("partial config uses defaults for unspecified thresholds", () => {
296
- seedHistory("my-eval", Array(15).fill(0.9));
297
-
298
- // Only override production threshold
299
- const result = checkGate(TEST_PROJECT, "my-eval", 0.88, {
300
- productionThreshold: 0.01,
301
- // stabilizationThreshold not specified - uses default 0.1
302
- });
303
-
304
- expect(result.passed).toBe(true); // 2.2% regression < 10% stabilization default
305
- });
306
- });
package/src/eval-gates.ts DELETED
@@ -1,218 +0,0 @@
1
- /**
2
- * Progressive Eval Gates
3
- *
4
- * Enforces quality gates based on eval history and current phase:
5
- * - Bootstrap (<10 runs): Always pass, collect data
6
- * - Stabilization (10-50 runs): Pass but warn on >10% regression
7
- * - Production (>50 runs + variance <0.1): Fail on >5% regression
8
- *
9
- * @module eval-gates
10
- */
11
- import { calculateVariance, getPhase, getScoreHistory } from "./eval-history.js";
12
-
13
- /**
14
- * Result from a gate check
15
- */
16
- export interface GateResult {
17
- /** Whether the gate passed */
18
- passed: boolean;
19
- /** Current phase */
20
- phase: "bootstrap" | "stabilization" | "production";
21
- /** Human-readable message */
22
- message: string;
23
- /** Baseline score (mean of history) */
24
- baseline?: number;
25
- /** Current score */
26
- currentScore: number;
27
- /** Regression percentage (negative = improvement) */
28
- regressionPercent?: number;
29
- }
30
-
31
- /**
32
- * Configuration for gate thresholds
33
- */
34
- export interface GateConfig {
35
- /** Regression threshold for stabilization phase (default: 0.1 = 10%) */
36
- stabilizationThreshold?: number;
37
- /** Regression threshold for production phase (default: 0.05 = 5%) */
38
- productionThreshold?: number;
39
- }
40
-
41
- /**
42
- * Default regression thresholds by phase
43
- */
44
- export const DEFAULT_THRESHOLDS = {
45
- stabilization: 0.1, // 10% regression warning
46
- production: 0.05, // 5% regression failure
47
- } as const;
48
-
49
- /**
50
- * Calculate baseline score (mean of all historical scores)
51
- */
52
- function calculateBaseline(history: ReturnType<typeof getScoreHistory>, currentScore: number): number {
53
- if (history.length === 0) {
54
- return currentScore;
55
- }
56
- return history.reduce((sum, run) => sum + run.score, 0) / history.length;
57
- }
58
-
59
- /**
60
- * Calculate regression percentage from baseline
61
- *
62
- * Returns 0 if baseline is 0 to avoid division by zero.
63
- * Positive = regression (score dropped), negative = improvement
64
- */
65
- function calculateRegression(baseline: number, currentScore: number): number {
66
- if (baseline === 0) {
67
- return 0;
68
- }
69
- return (baseline - currentScore) / baseline;
70
- }
71
-
72
- /**
73
- * Format regression message with scores
74
- */
75
- function formatRegressionMessage(
76
- regressionPercent: number,
77
- baseline: number,
78
- currentScore: number,
79
- ): string {
80
- return `${(regressionPercent * 100).toFixed(1)}% regression (baseline: ${baseline.toFixed(2)}, current: ${currentScore.toFixed(2)})`;
81
- }
82
-
83
- /**
84
- * Check if the current eval score passes the quality gate
85
- *
86
- * Progressive gates adapt based on data maturity:
87
- * - **Bootstrap (<10 runs)**: Always pass, focus on collecting baseline data
88
- * - **Stabilization (10-50 runs)**: Warn on >10% regression (default), but pass
89
- * - **Production (>50 runs + variance <0.1)**: Fail on >5% regression (default)
90
- *
91
- * **Baseline calculation**: Mean of all historical scores for this eval (not just last run).
92
- *
93
- * **Regression formula**: `(baseline - current) / baseline`
94
- * - Positive = regression (score dropped)
95
- * - Negative = improvement
96
- * - Returns 0 if baseline is 0 (avoids division by zero)
97
- *
98
- * **Variance threshold (0.1)**: High variance keeps eval in stabilization phase even with >50 runs.
99
- * This prevents premature production gates when scores are still unstable.
100
- *
101
- * **CI Integration**: Production gates can fail PRs. Use `swarm eval status` to check phase before merging.
102
- *
103
- * @param projectPath - Absolute path to project root (contains `.opencode/eval-history.jsonl`)
104
- * @param evalName - Name of the eval (e.g., "swarm-decomposition", "coordinator-behavior")
105
- * @param currentScore - Current score to check (typically 0-1 range)
106
- * @param config - Optional threshold configuration (defaults: stabilization=0.1, production=0.05)
107
- * @returns Gate check result with pass/fail, phase, baseline, regression details
108
- *
109
- * @example
110
- * ```typescript
111
- * import { checkGate } from "./eval-gates.js";
112
- *
113
- * const result = checkGate("/path/to/project", "swarm-decomposition", 0.89);
114
- *
115
- * if (!result.passed) {
116
- * console.error(`❌ Gate FAILED: ${result.message}`);
117
- * process.exit(1); // Fail CI
118
- * }
119
- *
120
- * console.log(`✅ ${result.phase} phase: ${result.message}`);
121
- * ```
122
- *
123
- * @example
124
- * ```typescript
125
- * // Custom thresholds for sensitive eval
126
- * const result = checkGate("/path", "critical-eval", 0.92, {
127
- * stabilizationThreshold: 0.05, // 5% threshold in stabilization
128
- * productionThreshold: 0.02, // 2% threshold in production
129
- * });
130
- * ```
131
- */
132
- export function checkGate(
133
- projectPath: string,
134
- evalName: string,
135
- currentScore: number,
136
- config?: GateConfig,
137
- ): GateResult {
138
- const thresholds = {
139
- stabilization: config?.stabilizationThreshold ?? DEFAULT_THRESHOLDS.stabilization,
140
- production: config?.productionThreshold ?? DEFAULT_THRESHOLDS.production,
141
- };
142
-
143
- const phase = getPhase(projectPath, evalName);
144
- const history = getScoreHistory(projectPath, evalName);
145
-
146
- // Bootstrap phase - always pass
147
- if (phase === "bootstrap") {
148
- return {
149
- passed: true,
150
- phase: "bootstrap",
151
- message: `Bootstrap phase (${history.length}/10 runs) - collecting data`,
152
- currentScore,
153
- };
154
- }
155
-
156
- // Calculate baseline and regression
157
- const baseline = calculateBaseline(history, currentScore);
158
- const regressionPercent = calculateRegression(baseline, currentScore);
159
- const regressionMsg = formatRegressionMessage(regressionPercent, baseline, currentScore);
160
-
161
- // Stabilization phase - warn on regression but pass
162
- if (phase === "stabilization") {
163
- if (regressionPercent > thresholds.stabilization) {
164
- return {
165
- passed: true,
166
- phase: "stabilization",
167
- message: `Stabilization phase: ${regressionMsg} - exceeds ${(thresholds.stabilization * 100).toFixed(0)}% threshold but still passing`,
168
- baseline,
169
- currentScore,
170
- regressionPercent,
171
- };
172
- }
173
-
174
- // Check if we have high variance (>50 runs but can't enter production)
175
- if (history.length > 50) {
176
- const scores = history.map((run) => run.score);
177
- const variance = calculateVariance(scores);
178
- return {
179
- passed: true,
180
- phase: "stabilization",
181
- message: `Stabilization phase: ${regressionMsg} - acceptable. High variance (${variance.toFixed(3)}) prevents production phase.`,
182
- baseline,
183
- currentScore,
184
- regressionPercent,
185
- };
186
- }
187
-
188
- return {
189
- passed: true,
190
- phase: "stabilization",
191
- message: `Stabilization phase: ${regressionMsg} - acceptable`,
192
- baseline,
193
- currentScore,
194
- regressionPercent,
195
- };
196
- }
197
-
198
- // Production phase - fail on regression exceeding threshold
199
- if (regressionPercent > thresholds.production) {
200
- return {
201
- passed: false,
202
- phase: "production",
203
- message: `Production phase FAIL: ${regressionMsg} - exceeds ${(thresholds.production * 100).toFixed(0)}% threshold`,
204
- baseline,
205
- currentScore,
206
- regressionPercent,
207
- };
208
- }
209
-
210
- return {
211
- passed: true,
212
- phase: "production",
213
- message: `Production phase: ${regressionMsg} - acceptable`,
214
- baseline,
215
- currentScore,
216
- regressionPercent,
217
- };
218
- }