opencode-swarm-plugin 0.38.0 → 0.40.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.
- package/.env +2 -0
- package/.hive/eval-results.json +26 -0
- package/.hive/issues.jsonl +27 -0
- package/.hive/memories.jsonl +23 -1
- package/.opencode/eval-history.jsonl +12 -0
- package/CHANGELOG.md +182 -0
- package/README.md +29 -12
- package/bin/swarm.test.ts +881 -0
- package/bin/swarm.ts +686 -0
- package/dist/compaction-hook.d.ts +8 -1
- package/dist/compaction-hook.d.ts.map +1 -1
- package/dist/compaction-observability.d.ts +173 -0
- package/dist/compaction-observability.d.ts.map +1 -0
- package/dist/compaction-prompt-scoring.d.ts +124 -0
- package/dist/compaction-prompt-scoring.d.ts.map +1 -0
- package/dist/eval-capture.d.ts +174 -1
- package/dist/eval-capture.d.ts.map +1 -1
- package/dist/eval-gates.d.ts +84 -0
- package/dist/eval-gates.d.ts.map +1 -0
- package/dist/eval-history.d.ts +117 -0
- package/dist/eval-history.d.ts.map +1 -0
- package/dist/eval-learning.d.ts +216 -0
- package/dist/eval-learning.d.ts.map +1 -0
- package/dist/hive.d.ts.map +1 -1
- package/dist/index.d.ts +80 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16098 -651
- package/dist/plugin.js +16012 -756
- package/dist/post-compaction-tracker.d.ts +133 -0
- package/dist/post-compaction-tracker.d.ts.map +1 -0
- package/dist/schemas/task.d.ts +3 -3
- package/dist/swarm-orchestrate.d.ts +23 -0
- package/dist/swarm-orchestrate.d.ts.map +1 -1
- package/dist/swarm-prompts.d.ts +25 -1
- package/dist/swarm-prompts.d.ts.map +1 -1
- package/dist/swarm.d.ts +4 -0
- package/dist/swarm.d.ts.map +1 -1
- package/evals/README.md +702 -105
- package/evals/compaction-prompt.eval.ts +149 -0
- package/evals/coordinator-behavior.eval.ts +8 -8
- package/evals/fixtures/compaction-prompt-cases.ts +305 -0
- package/evals/lib/compaction-loader.test.ts +248 -0
- package/evals/lib/compaction-loader.ts +320 -0
- package/evals/lib/data-loader.test.ts +345 -0
- package/evals/lib/data-loader.ts +107 -6
- package/evals/scorers/compaction-prompt-scorers.ts +145 -0
- package/evals/scorers/compaction-scorers.ts +13 -13
- package/evals/scorers/coordinator-discipline.evalite-test.ts +166 -2
- package/evals/scorers/coordinator-discipline.ts +348 -15
- package/evals/scorers/index.test.ts +146 -0
- package/evals/scorers/index.ts +104 -0
- package/evals/swarm-decomposition.eval.ts +9 -2
- package/examples/commands/swarm.md +291 -21
- package/examples/plugin-wrapper-template.ts +117 -0
- package/package.json +7 -5
- package/scripts/migrate-unknown-sessions.ts +349 -0
- package/src/compaction-capture.integration.test.ts +257 -0
- package/src/compaction-hook.test.ts +42 -0
- package/src/compaction-hook.ts +315 -86
- package/src/compaction-observability.integration.test.ts +139 -0
- package/src/compaction-observability.test.ts +187 -0
- package/src/compaction-observability.ts +324 -0
- package/src/compaction-prompt-scorers.test.ts +299 -0
- package/src/compaction-prompt-scoring.ts +298 -0
- package/src/eval-capture.test.ts +626 -1
- package/src/eval-capture.ts +286 -2
- package/src/eval-gates.test.ts +306 -0
- package/src/eval-gates.ts +218 -0
- package/src/eval-history.test.ts +508 -0
- package/src/eval-history.ts +214 -0
- package/src/eval-learning.test.ts +378 -0
- package/src/eval-learning.ts +360 -0
- package/src/eval-runner.test.ts +96 -0
- package/src/eval-runner.ts +356 -0
- package/src/hive.ts +34 -0
- package/src/index.ts +115 -2
- package/src/memory.test.ts +110 -0
- package/src/memory.ts +34 -0
- package/src/post-compaction-tracker.test.ts +251 -0
- package/src/post-compaction-tracker.ts +237 -0
- package/src/swarm-decompose.ts +2 -2
- package/src/swarm-orchestrate.ts +2 -2
- package/src/swarm-prompts.ts +2 -2
- package/src/swarm-review.ts +3 -3
- package/dist/beads.d.ts +0 -386
- package/dist/beads.d.ts.map +0 -1
- package/dist/schemas/bead-events.d.ts +0 -698
- package/dist/schemas/bead-events.d.ts.map +0 -1
- package/dist/schemas/bead.d.ts +0 -255
- package/dist/schemas/bead.d.ts.map +0 -1
- /package/evals/{evalite.config.ts → evalite.config.ts.bak} +0 -0
|
@@ -0,0 +1,218 @@
|
|
|
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
|
+
}
|