opencode-swarm-plugin 0.44.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.
- package/bin/swarm.serve.test.ts +6 -4
- package/bin/swarm.ts +16 -10
- package/dist/compaction-prompt-scoring.js +139 -0
- package/dist/eval-capture.js +12811 -0
- package/dist/hive.d.ts.map +1 -1
- package/dist/index.js +7644 -62599
- package/dist/plugin.js +23766 -78721
- package/dist/swarm-orchestrate.d.ts.map +1 -1
- package/dist/swarm-prompts.d.ts.map +1 -1
- package/dist/swarm-review.d.ts.map +1 -1
- package/package.json +17 -5
- package/.changeset/swarm-insights-data-layer.md +0 -63
- package/.hive/analysis/eval-failure-analysis-2025-12-25.md +0 -331
- package/.hive/analysis/session-data-quality-audit.md +0 -320
- package/.hive/eval-results.json +0 -483
- package/.hive/issues.jsonl +0 -138
- package/.hive/memories.jsonl +0 -729
- package/.opencode/eval-history.jsonl +0 -327
- package/.turbo/turbo-build.log +0 -9
- package/CHANGELOG.md +0 -2286
- package/SCORER-ANALYSIS.md +0 -598
- package/docs/analysis/subagent-coordination-patterns.md +0 -902
- package/docs/analysis-socratic-planner-pattern.md +0 -504
- package/docs/planning/ADR-001-monorepo-structure.md +0 -171
- package/docs/planning/ADR-002-package-extraction.md +0 -393
- package/docs/planning/ADR-003-performance-improvements.md +0 -451
- package/docs/planning/ADR-004-message-queue-features.md +0 -187
- package/docs/planning/ADR-005-devtools-observability.md +0 -202
- package/docs/planning/ADR-007-swarm-enhancements-worktree-review.md +0 -168
- package/docs/planning/ADR-008-worker-handoff-protocol.md +0 -293
- package/docs/planning/ADR-009-oh-my-opencode-patterns.md +0 -353
- package/docs/planning/ADR-010-cass-inhousing.md +0 -1215
- package/docs/planning/ROADMAP.md +0 -368
- package/docs/semantic-memory-cli-syntax.md +0 -123
- package/docs/swarm-mail-architecture.md +0 -1147
- package/docs/testing/context-recovery-test.md +0 -470
- package/evals/ARCHITECTURE.md +0 -1189
- package/evals/README.md +0 -768
- package/evals/compaction-prompt.eval.ts +0 -149
- package/evals/compaction-resumption.eval.ts +0 -289
- package/evals/coordinator-behavior.eval.ts +0 -307
- package/evals/coordinator-session.eval.ts +0 -154
- package/evals/evalite.config.ts.bak +0 -15
- package/evals/example.eval.ts +0 -31
- package/evals/fixtures/cass-baseline.ts +0 -217
- package/evals/fixtures/compaction-cases.ts +0 -350
- package/evals/fixtures/compaction-prompt-cases.ts +0 -311
- package/evals/fixtures/coordinator-sessions.ts +0 -328
- package/evals/fixtures/decomposition-cases.ts +0 -105
- package/evals/lib/compaction-loader.test.ts +0 -248
- package/evals/lib/compaction-loader.ts +0 -320
- package/evals/lib/data-loader.evalite-test.ts +0 -289
- package/evals/lib/data-loader.test.ts +0 -345
- package/evals/lib/data-loader.ts +0 -281
- package/evals/lib/llm.ts +0 -115
- package/evals/scorers/compaction-prompt-scorers.ts +0 -145
- package/evals/scorers/compaction-scorers.ts +0 -305
- package/evals/scorers/coordinator-discipline.evalite-test.ts +0 -539
- package/evals/scorers/coordinator-discipline.ts +0 -325
- package/evals/scorers/index.test.ts +0 -146
- package/evals/scorers/index.ts +0 -328
- package/evals/scorers/outcome-scorers.evalite-test.ts +0 -27
- package/evals/scorers/outcome-scorers.ts +0 -349
- package/evals/swarm-decomposition.eval.ts +0 -121
- package/examples/commands/swarm.md +0 -745
- package/examples/plugin-wrapper-template.ts +0 -2515
- package/examples/skills/hive-workflow/SKILL.md +0 -212
- package/examples/skills/skill-creator/SKILL.md +0 -223
- package/examples/skills/swarm-coordination/SKILL.md +0 -292
- package/global-skills/cli-builder/SKILL.md +0 -344
- package/global-skills/cli-builder/references/advanced-patterns.md +0 -244
- package/global-skills/learning-systems/SKILL.md +0 -644
- package/global-skills/skill-creator/LICENSE.txt +0 -202
- package/global-skills/skill-creator/SKILL.md +0 -352
- package/global-skills/skill-creator/references/output-patterns.md +0 -82
- package/global-skills/skill-creator/references/workflows.md +0 -28
- package/global-skills/swarm-coordination/SKILL.md +0 -995
- package/global-skills/swarm-coordination/references/coordinator-patterns.md +0 -235
- package/global-skills/swarm-coordination/references/strategies.md +0 -138
- package/global-skills/system-design/SKILL.md +0 -213
- package/global-skills/testing-patterns/SKILL.md +0 -430
- package/global-skills/testing-patterns/references/dependency-breaking-catalog.md +0 -586
- package/opencode-swarm-plugin-0.30.7.tgz +0 -0
- package/opencode-swarm-plugin-0.31.0.tgz +0 -0
- package/scripts/cleanup-test-memories.ts +0 -346
- package/scripts/init-skill.ts +0 -222
- package/scripts/migrate-unknown-sessions.ts +0 -349
- package/scripts/validate-skill.ts +0 -204
- package/src/agent-mail.ts +0 -1724
- package/src/anti-patterns.test.ts +0 -1167
- package/src/anti-patterns.ts +0 -448
- package/src/compaction-capture.integration.test.ts +0 -257
- package/src/compaction-hook.test.ts +0 -838
- package/src/compaction-hook.ts +0 -1204
- package/src/compaction-observability.integration.test.ts +0 -139
- package/src/compaction-observability.test.ts +0 -187
- package/src/compaction-observability.ts +0 -324
- package/src/compaction-prompt-scorers.test.ts +0 -475
- package/src/compaction-prompt-scoring.ts +0 -300
- package/src/contributor-tools.test.ts +0 -133
- package/src/contributor-tools.ts +0 -201
- package/src/dashboard.test.ts +0 -611
- package/src/dashboard.ts +0 -462
- package/src/error-enrichment.test.ts +0 -403
- package/src/error-enrichment.ts +0 -219
- package/src/eval-capture.test.ts +0 -1015
- package/src/eval-capture.ts +0 -929
- package/src/eval-gates.test.ts +0 -306
- package/src/eval-gates.ts +0 -218
- package/src/eval-history.test.ts +0 -508
- package/src/eval-history.ts +0 -214
- package/src/eval-learning.test.ts +0 -378
- package/src/eval-learning.ts +0 -360
- package/src/eval-runner.test.ts +0 -223
- package/src/eval-runner.ts +0 -402
- package/src/export-tools.test.ts +0 -476
- package/src/export-tools.ts +0 -257
- package/src/hive.integration.test.ts +0 -2241
- package/src/hive.ts +0 -1628
- package/src/index.ts +0 -940
- package/src/learning.integration.test.ts +0 -1815
- package/src/learning.ts +0 -1079
- package/src/logger.test.ts +0 -189
- package/src/logger.ts +0 -135
- package/src/mandate-promotion.test.ts +0 -473
- package/src/mandate-promotion.ts +0 -239
- package/src/mandate-storage.integration.test.ts +0 -601
- package/src/mandate-storage.test.ts +0 -578
- package/src/mandate-storage.ts +0 -794
- package/src/mandates.ts +0 -540
- package/src/memory-tools.test.ts +0 -195
- package/src/memory-tools.ts +0 -344
- package/src/memory.integration.test.ts +0 -334
- package/src/memory.test.ts +0 -158
- package/src/memory.ts +0 -527
- package/src/model-selection.test.ts +0 -188
- package/src/model-selection.ts +0 -68
- package/src/observability-tools.test.ts +0 -359
- package/src/observability-tools.ts +0 -871
- package/src/output-guardrails.test.ts +0 -438
- package/src/output-guardrails.ts +0 -381
- package/src/pattern-maturity.test.ts +0 -1160
- package/src/pattern-maturity.ts +0 -525
- package/src/planning-guardrails.test.ts +0 -491
- package/src/planning-guardrails.ts +0 -438
- package/src/plugin.ts +0 -23
- package/src/post-compaction-tracker.test.ts +0 -251
- package/src/post-compaction-tracker.ts +0 -237
- package/src/query-tools.test.ts +0 -636
- package/src/query-tools.ts +0 -324
- package/src/rate-limiter.integration.test.ts +0 -466
- package/src/rate-limiter.ts +0 -774
- package/src/replay-tools.test.ts +0 -496
- package/src/replay-tools.ts +0 -240
- package/src/repo-crawl.integration.test.ts +0 -441
- package/src/repo-crawl.ts +0 -610
- package/src/schemas/cell-events.test.ts +0 -347
- package/src/schemas/cell-events.ts +0 -807
- package/src/schemas/cell.ts +0 -257
- package/src/schemas/evaluation.ts +0 -166
- package/src/schemas/index.test.ts +0 -199
- package/src/schemas/index.ts +0 -286
- package/src/schemas/mandate.ts +0 -232
- package/src/schemas/swarm-context.ts +0 -115
- package/src/schemas/task.ts +0 -161
- package/src/schemas/worker-handoff.test.ts +0 -302
- package/src/schemas/worker-handoff.ts +0 -131
- package/src/sessions/agent-discovery.test.ts +0 -137
- package/src/sessions/agent-discovery.ts +0 -112
- package/src/sessions/index.ts +0 -15
- package/src/skills.integration.test.ts +0 -1192
- package/src/skills.test.ts +0 -643
- package/src/skills.ts +0 -1549
- package/src/storage.integration.test.ts +0 -341
- package/src/storage.ts +0 -884
- package/src/structured.integration.test.ts +0 -817
- package/src/structured.test.ts +0 -1046
- package/src/structured.ts +0 -762
- package/src/swarm-decompose.test.ts +0 -188
- package/src/swarm-decompose.ts +0 -1302
- package/src/swarm-deferred.integration.test.ts +0 -157
- package/src/swarm-deferred.test.ts +0 -38
- package/src/swarm-insights.test.ts +0 -214
- package/src/swarm-insights.ts +0 -459
- package/src/swarm-mail.integration.test.ts +0 -970
- package/src/swarm-mail.ts +0 -739
- package/src/swarm-orchestrate.integration.test.ts +0 -282
- package/src/swarm-orchestrate.test.ts +0 -548
- package/src/swarm-orchestrate.ts +0 -3084
- package/src/swarm-prompts.test.ts +0 -1270
- package/src/swarm-prompts.ts +0 -2077
- package/src/swarm-research.integration.test.ts +0 -701
- package/src/swarm-research.test.ts +0 -698
- package/src/swarm-research.ts +0 -472
- package/src/swarm-review.integration.test.ts +0 -285
- package/src/swarm-review.test.ts +0 -879
- package/src/swarm-review.ts +0 -709
- package/src/swarm-strategies.ts +0 -407
- package/src/swarm-worktree.test.ts +0 -501
- package/src/swarm-worktree.ts +0 -575
- package/src/swarm.integration.test.ts +0 -2377
- package/src/swarm.ts +0 -38
- package/src/tool-adapter.integration.test.ts +0 -1221
- package/src/tool-availability.ts +0 -461
- package/tsconfig.json +0 -28
package/src/eval-gates.test.ts
DELETED
|
@@ -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
|
-
}
|