dsh-eval 0.4.0 → 0.5.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/README.md +214 -13
- package/README.zh.md +99 -10
- package/lib/agreement.js +46 -0
- package/lib/argv.js +66 -0
- package/lib/atomic-write.js +38 -0
- package/lib/benchmark.js +116 -19
- package/lib/calibration.js +90 -0
- package/lib/command.js +202 -10
- package/lib/compare.js +310 -31
- package/lib/dashboard.js +260 -0
- package/lib/digest.js +118 -0
- package/lib/export.js +50 -0
- package/lib/gate.js +293 -0
- package/lib/import.js +17 -6
- package/lib/index.js +174 -12
- package/lib/judge.js +30 -7
- package/lib/leaderboard.js +222 -0
- package/lib/precision.js +50 -0
- package/lib/rejudge.js +107 -0
- package/lib/reliability.js +107 -0
- package/lib/report.js +285 -11
- package/lib/runner.js +189 -33
- package/lib/safe-regex.js +74 -0
- package/lib/segments.js +15 -0
- package/lib/stats.js +63 -0
- package/lib/trace.js +19 -2
- package/lib/types/agreement.d.ts +33 -0
- package/lib/types/argv.d.ts +19 -0
- package/lib/types/atomic-write.d.ts +15 -0
- package/lib/types/benchmark.d.ts +9 -2
- package/lib/types/calibration.d.ts +45 -0
- package/lib/types/command.d.ts +58 -0
- package/lib/types/compare.d.ts +82 -2
- package/lib/types/dashboard.d.ts +24 -0
- package/lib/types/digest.d.ts +38 -0
- package/lib/types/export.d.ts +17 -0
- package/lib/types/gate.d.ts +87 -0
- package/lib/types/index.d.ts +8 -4
- package/lib/types/judge.d.ts +4 -1
- package/lib/types/leaderboard.d.ts +70 -0
- package/lib/types/precision.d.ts +44 -0
- package/lib/types/rejudge.d.ts +22 -0
- package/lib/types/reliability.d.ts +85 -0
- package/lib/types/report.d.ts +18 -5
- package/lib/types/runner.d.ts +8 -1
- package/lib/types/safe-regex.d.ts +24 -0
- package/lib/types/segments.d.ts +12 -0
- package/lib/types/stats.d.ts +56 -0
- package/lib/types/trace.d.ts +7 -0
- package/lib/types/types.d.ts +55 -6
- package/lib/types/validate.d.ts +57 -0
- package/lib/validate.js +155 -0
- package/package.json +2 -2
- package/src/agreement.ts +60 -0
- package/src/argv.ts +63 -0
- package/src/atomic-write.ts +38 -0
- package/src/benchmark.ts +139 -13
- package/src/calibration.ts +113 -0
- package/src/command.ts +297 -10
- package/src/compare.ts +392 -37
- package/src/dashboard.ts +287 -0
- package/src/digest.ts +144 -0
- package/src/export.ts +57 -0
- package/src/gate.ts +383 -0
- package/src/import.ts +18 -6
- package/src/index.ts +192 -12
- package/src/judge.ts +30 -6
- package/src/leaderboard.ts +272 -0
- package/src/precision.ts +85 -0
- package/src/rejudge.ts +112 -0
- package/src/reliability.ts +166 -0
- package/src/report.ts +303 -11
- package/src/runner.ts +182 -35
- package/src/safe-regex.ts +79 -0
- package/src/segments.ts +16 -0
- package/src/stats.ts +104 -0
- package/src/trace.ts +19 -2
- package/src/types.ts +56 -6
- package/src/validate.ts +177 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Crash-safe text output shared by every file-writing CLI command.
|
|
3
|
+
*
|
|
4
|
+
* Writing directly to the destination can leave a truncated file that looks
|
|
5
|
+
* loadable after a crash or a full disk. Staging beside the target and
|
|
6
|
+
* renaming keeps readers on either the old or the new complete document.
|
|
7
|
+
*
|
|
8
|
+
* @module dsh-eval/atomic-write
|
|
9
|
+
*/
|
|
10
|
+
import { randomUUID } from 'node:crypto';
|
|
11
|
+
import { chmod, mkdir, realpath, rename, stat, unlink, writeFile } from 'node:fs/promises';
|
|
12
|
+
import { basename, dirname, join, resolve } from 'node:path';
|
|
13
|
+
/**
|
|
14
|
+
* Write UTF-8 text atomically, creating parent directories as needed.
|
|
15
|
+
* @param path - destination path.
|
|
16
|
+
* @param text - complete file contents.
|
|
17
|
+
*/
|
|
18
|
+
export async function writeTextAtomic(path, text) {
|
|
19
|
+
const absolute = resolve(path);
|
|
20
|
+
// Replace the real target, not the symlink: an `--out` alias must stay valid.
|
|
21
|
+
const destination = await realpath(absolute).catch(() => absolute);
|
|
22
|
+
const directory = dirname(destination);
|
|
23
|
+
await mkdir(directory, { recursive: true });
|
|
24
|
+
const temp = join(directory, `.${basename(destination)}.${process.pid}.${randomUUID()}.tmp`);
|
|
25
|
+
const existing = await stat(destination).catch(() => null);
|
|
26
|
+
try {
|
|
27
|
+
await writeFile(temp, text, 'utf8');
|
|
28
|
+
// Preserve an existing file's permission bits across the rename.
|
|
29
|
+
if (existing !== null)
|
|
30
|
+
await chmod(temp, existing.mode);
|
|
31
|
+
await rename(temp, destination);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
/* v8 ignore next -- cleanup of a failed staged write is best-effort. */
|
|
35
|
+
await unlink(temp).catch(() => { });
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
}
|
package/lib/benchmark.js
CHANGED
|
@@ -5,10 +5,12 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @module dsh-eval/benchmark
|
|
7
7
|
*/
|
|
8
|
-
import { readFile } from 'node:fs/promises';
|
|
9
|
-
import { dirname, isAbsolute, resolve } from 'node:path';
|
|
8
|
+
import { readFile, realpath } from 'node:fs/promises';
|
|
9
|
+
import { dirname, isAbsolute, relative, resolve, sep } from 'node:path';
|
|
10
10
|
import { load } from 'js-yaml';
|
|
11
11
|
import { z } from 'zod';
|
|
12
|
+
import { hashBenchmarkInputs } from "./digest.js";
|
|
13
|
+
import { caseSegment } from "./segments.js";
|
|
12
14
|
const judgeSchema = z.object({
|
|
13
15
|
provider: z.string().min(1).default('deepseek'),
|
|
14
16
|
model: z.string().min(1).optional(),
|
|
@@ -24,15 +26,48 @@ const pricingSchema = z.object({
|
|
|
24
26
|
cacheWriteUsdPerMTokens: z.number().nonnegative(),
|
|
25
27
|
outputUsdPerMTokens: z.number().nonnegative(),
|
|
26
28
|
}).strict();
|
|
29
|
+
/** A non-empty string that the runtime can compile as a Unicode regular expression. */
|
|
30
|
+
function regexSchema(message) {
|
|
31
|
+
return z.string().min(1).refine((value) => {
|
|
32
|
+
try {
|
|
33
|
+
new RegExp(value, 'u');
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}, { message });
|
|
40
|
+
}
|
|
41
|
+
const toolRegexSchema = regexSchema('toolRegex is not a valid regular expression');
|
|
42
|
+
const answerRegexSchema = regexSchema('answerRegex is not a valid regular expression');
|
|
27
43
|
const benchmarkCaseSchema = z.object({
|
|
28
44
|
id: z.string().min(1),
|
|
29
45
|
prompt: z.string().min(1).optional(),
|
|
30
46
|
promptFile: z.string().min(1).optional(),
|
|
31
47
|
workspace: z.string().min(1).optional(),
|
|
48
|
+
timeoutMs: z.number().int().positive().optional(),
|
|
32
49
|
expected: z.object({
|
|
33
50
|
tool: z.string().min(1).optional(),
|
|
51
|
+
tools: z.array(z.string().min(1)).min(1).readonly().optional(),
|
|
52
|
+
toolAnyOf: z.array(z.string().min(1)).min(1).readonly().optional(),
|
|
53
|
+
toolRegex: toolRegexSchema.optional(),
|
|
54
|
+
toolNot: z.array(z.string().min(1)).min(1).readonly().optional(),
|
|
34
55
|
check: z.string().min(1).optional(),
|
|
35
|
-
|
|
56
|
+
checkArgv: z.array(z.string().min(1)).min(1).readonly().optional(),
|
|
57
|
+
checkShell: z.string().min(1).optional(),
|
|
58
|
+
answer: z.string().min(1).optional(),
|
|
59
|
+
answerRegex: answerRegexSchema.optional(),
|
|
60
|
+
}).strict().refine(expectation => expectation.tool !== undefined || expectation.tools !== undefined
|
|
61
|
+
|| expectation.toolAnyOf !== undefined || expectation.toolRegex !== undefined
|
|
62
|
+
|| expectation.toolNot !== undefined || expectation.check !== undefined
|
|
63
|
+
|| expectation.checkArgv !== undefined || expectation.checkShell !== undefined
|
|
64
|
+
|| expectation.answer !== undefined || expectation.answerRegex !== undefined, {
|
|
65
|
+
message: 'expected needs at least one of tool, tools, toolAnyOf, toolRegex, toolNot, check, checkArgv, checkShell, answer or answerRegex',
|
|
66
|
+
}).refine((expectation) => {
|
|
67
|
+
const commands = [expectation.check, expectation.checkArgv, expectation.checkShell]
|
|
68
|
+
.filter(value => value !== undefined);
|
|
69
|
+
return commands.length <= 1;
|
|
70
|
+
}, { message: 'expected accepts at most one of check, checkArgv or checkShell' }).optional(),
|
|
36
71
|
}).strict().refine(caseValue => (caseValue.prompt === undefined) !== (caseValue.promptFile === undefined), { message: 'each case needs exactly one of prompt or promptFile' });
|
|
37
72
|
const benchmarkSchema = z.object({
|
|
38
73
|
name: z.string().min(1),
|
|
@@ -42,12 +77,32 @@ const benchmarkSchema = z.object({
|
|
|
42
77
|
trials: z.number().int().positive().default(1),
|
|
43
78
|
concurrency: z.number().int().positive().default(1),
|
|
44
79
|
timeoutMs: z.number().int().positive().default(600_000),
|
|
80
|
+
allowExternalPaths: z.boolean().default(false),
|
|
45
81
|
seed: z.number().int().default(0),
|
|
46
82
|
cases: z.array(benchmarkCaseSchema).min(1),
|
|
47
83
|
pricing: z.record(z.string().min(1), pricingSchema).optional(),
|
|
48
84
|
judge: judgeSchema.optional(),
|
|
49
85
|
replay: replaySchema.optional(),
|
|
50
|
-
}).strict()
|
|
86
|
+
}).strict().superRefine((parsed, ctx) => {
|
|
87
|
+
// Every trial's private directory is `<caseSegment(id)>-<trial>`. Distinct
|
|
88
|
+
// ids that normalize to one segment (or a plain duplicate) would otherwise
|
|
89
|
+
// share a workspace and DSH_HOME, leaking session logs and metrics across
|
|
90
|
+
// cases. Compare case-insensitively so Windows' case-folding FS is safe too.
|
|
91
|
+
const seen = new Set();
|
|
92
|
+
parsed.cases.forEach((caseValue, index) => {
|
|
93
|
+
const key = caseSegment(caseValue.id).toLowerCase();
|
|
94
|
+
if (seen.has(key)) {
|
|
95
|
+
ctx.addIssue({
|
|
96
|
+
code: 'custom',
|
|
97
|
+
path: ['cases', index, 'id'],
|
|
98
|
+
message: `case id "${caseValue.id}" collides with an earlier case after directory normalization`,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
seen.add(key);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
});
|
|
51
106
|
/**
|
|
52
107
|
* Resolve one parsed case's prompt and workspace against the benchmark
|
|
53
108
|
* directory. Prompt files are read at load time so a run fails before any
|
|
@@ -56,49 +111,85 @@ const benchmarkSchema = z.object({
|
|
|
56
111
|
* @param baseDir - absolute directory the benchmark file lives in.
|
|
57
112
|
* @returns the resolved runtime case.
|
|
58
113
|
*/
|
|
59
|
-
|
|
114
|
+
/**
|
|
115
|
+
* Resolve a referenced path without letting a third-party benchmark read
|
|
116
|
+
* outside its directory. The override is caller-supplied (CLI/API), never
|
|
117
|
+
* taken from the document itself.
|
|
118
|
+
*/
|
|
119
|
+
async function resolveInputPath(value, baseDir, allowExternal, field) {
|
|
120
|
+
const resolved = resolve(baseDir, value);
|
|
121
|
+
if (allowExternal)
|
|
122
|
+
return resolved;
|
|
123
|
+
const rel = relative(baseDir, resolved);
|
|
124
|
+
if (isAbsolute(value) || rel === '..' || rel.startsWith(`..${sep}`) || isAbsolute(rel)) {
|
|
125
|
+
throw new Error(`${field} "${value}" escapes the benchmark directory`);
|
|
126
|
+
}
|
|
127
|
+
// Compare real paths so a symlink inside the directory cannot point at a
|
|
128
|
+
// file outside it. A missing path is left for readFile() to report.
|
|
129
|
+
let real;
|
|
130
|
+
try {
|
|
131
|
+
real = await realpath(resolved);
|
|
132
|
+
}
|
|
133
|
+
catch {
|
|
134
|
+
return resolved;
|
|
135
|
+
}
|
|
136
|
+
const realRoot = await realpath(baseDir);
|
|
137
|
+
const realRel = relative(realRoot, real);
|
|
138
|
+
if (realRel === '..' || realRel.startsWith(`..${sep}`) || isAbsolute(realRel)) {
|
|
139
|
+
throw new Error(`${field} "${value}" escapes the benchmark directory`);
|
|
140
|
+
}
|
|
141
|
+
return resolved;
|
|
142
|
+
}
|
|
143
|
+
async function resolveCase(parsed, baseDir, allowExternalPaths) {
|
|
60
144
|
const prompt = parsed.prompt
|
|
61
|
-
?? await readFile(
|
|
145
|
+
?? await readFile(await resolveInputPath(parsed.promptFile, baseDir, allowExternalPaths, 'promptFile'), 'utf8');
|
|
62
146
|
return {
|
|
63
147
|
id: parsed.id,
|
|
64
148
|
prompt,
|
|
149
|
+
...(parsed.timeoutMs !== undefined ? { timeoutMs: parsed.timeoutMs } : {}),
|
|
65
150
|
...(parsed.workspace !== undefined
|
|
66
|
-
? { workspace:
|
|
151
|
+
? { workspace: await resolveInputPath(parsed.workspace, baseDir, allowExternalPaths, 'workspace') }
|
|
67
152
|
: {}),
|
|
68
153
|
...(parsed.expected !== undefined
|
|
69
154
|
? {
|
|
70
155
|
expected: {
|
|
71
156
|
...(parsed.expected.tool !== undefined ? { tool: parsed.expected.tool } : {}),
|
|
157
|
+
...(parsed.expected.tools !== undefined ? { tools: parsed.expected.tools } : {}),
|
|
158
|
+
...(parsed.expected.toolAnyOf !== undefined ? { toolAnyOf: parsed.expected.toolAnyOf } : {}),
|
|
159
|
+
...(parsed.expected.toolRegex !== undefined ? { toolRegex: parsed.expected.toolRegex } : {}),
|
|
160
|
+
...(parsed.expected.toolNot !== undefined ? { toolNot: parsed.expected.toolNot } : {}),
|
|
72
161
|
...(parsed.expected.check !== undefined ? { check: parsed.expected.check } : {}),
|
|
162
|
+
...(parsed.expected.checkArgv !== undefined ? { checkArgv: parsed.expected.checkArgv } : {}),
|
|
163
|
+
...(parsed.expected.checkShell !== undefined ? { checkShell: parsed.expected.checkShell } : {}),
|
|
164
|
+
...(parsed.expected.answer !== undefined ? { answer: parsed.expected.answer } : {}),
|
|
165
|
+
...(parsed.expected.answerRegex !== undefined ? { answerRegex: parsed.expected.answerRegex } : {}),
|
|
73
166
|
},
|
|
74
167
|
}
|
|
75
168
|
: {}),
|
|
76
169
|
};
|
|
77
170
|
}
|
|
78
|
-
|
|
79
|
-
* Parse benchmark YAML text into a validated runtime document.
|
|
80
|
-
* @param text - the benchmark document's YAML source.
|
|
81
|
-
* @param baseDir - absolute directory used to resolve prompt and workspace paths.
|
|
82
|
-
* @returns the validated benchmark.
|
|
83
|
-
*/
|
|
84
|
-
export async function parseBenchmark(text, baseDir) {
|
|
171
|
+
export async function parseBenchmark(text, baseDir, options = {}) {
|
|
85
172
|
const value = load(text);
|
|
86
173
|
if (typeof value !== 'object' || value === null) {
|
|
87
174
|
throw new Error('benchmark document must be a YAML mapping');
|
|
88
175
|
}
|
|
89
176
|
const parsed = benchmarkSchema.parse(value);
|
|
177
|
+
// `allowExternalPaths` in YAML is accepted for backward compatibility but
|
|
178
|
+
// ignored: only the operator running the CLI/API may widen the boundary.
|
|
179
|
+
const allowExternalPaths = options.allowExternalPaths === true;
|
|
90
180
|
const cases = [];
|
|
91
181
|
for (const caseValue of parsed.cases) {
|
|
92
|
-
cases.push(await resolveCase(caseValue, baseDir));
|
|
182
|
+
cases.push(await resolveCase(caseValue, baseDir, allowExternalPaths));
|
|
93
183
|
}
|
|
94
184
|
const pricing = parsed.pricing;
|
|
95
185
|
const judge = parsed.judge;
|
|
96
186
|
const replay = parsed.replay;
|
|
97
|
-
|
|
187
|
+
const benchmark = {
|
|
98
188
|
name: parsed.name,
|
|
99
189
|
model: parsed.model,
|
|
100
190
|
profile: parsed.profile,
|
|
101
191
|
command: parsed.command,
|
|
192
|
+
allowExternalPaths,
|
|
102
193
|
trials: parsed.trials,
|
|
103
194
|
concurrency: parsed.concurrency,
|
|
104
195
|
timeoutMs: parsed.timeoutMs,
|
|
@@ -109,17 +200,23 @@ export async function parseBenchmark(text, baseDir) {
|
|
|
109
200
|
? { judge: { provider: judge.provider, model: judge.model ?? parsed.model, ...(judge.rubric !== undefined ? { rubric: judge.rubric } : {}), maxScore: judge.maxScore } }
|
|
110
201
|
: {}),
|
|
111
202
|
...(replay !== undefined
|
|
112
|
-
? { replay: { dir:
|
|
203
|
+
? { replay: { dir: await resolveInputPath(replay.dir, baseDir, allowExternalPaths, 'replay.dir') } }
|
|
113
204
|
: {}),
|
|
114
205
|
baseDir,
|
|
115
206
|
};
|
|
207
|
+
return {
|
|
208
|
+
...benchmark,
|
|
209
|
+
sourceSha256: await hashBenchmarkInputs(text, benchmark, {
|
|
210
|
+
...(options.excludeFromDigest === undefined ? {} : { excludePaths: options.excludeFromDigest }),
|
|
211
|
+
}),
|
|
212
|
+
};
|
|
116
213
|
}
|
|
117
214
|
/**
|
|
118
215
|
* Load and validate a benchmark document from disk.
|
|
119
216
|
* @param path - path to the benchmark YAML file.
|
|
120
217
|
* @returns the validated benchmark.
|
|
121
218
|
*/
|
|
122
|
-
export async function loadBenchmark(path) {
|
|
219
|
+
export async function loadBenchmark(path, options = {}) {
|
|
123
220
|
const absolute = resolve(path);
|
|
124
|
-
return parseBenchmark(await readFile(absolute, 'utf8'), dirname(absolute));
|
|
221
|
+
return parseBenchmark(await readFile(absolute, 'utf8'), dirname(absolute), options);
|
|
125
222
|
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Judge calibration diagnostics for dsh-eval.
|
|
3
|
+
*
|
|
4
|
+
* Agreement and kappa say whether the judge and the scripted check reach the
|
|
5
|
+
* same verdict, but a judge can be perfectly calibrated on an all-pass run and
|
|
6
|
+
* still useless for ranking. This module also measures how well the judge's
|
|
7
|
+
* numeric score separates scripted passes from failures, and surfaces the
|
|
8
|
+
* concrete cases where the two views disagree so a rubric can be improved.
|
|
9
|
+
* A normalized score >= 0.5 counts as a judge pass; the hallucination flag is
|
|
10
|
+
* only a fallback for trials whose score is missing, so the disagreement list
|
|
11
|
+
* can explain the score-based separation and ranking figures.
|
|
12
|
+
*
|
|
13
|
+
* @module dsh-eval/calibration
|
|
14
|
+
*/
|
|
15
|
+
/** Normalize a judge score to 0..1 using its run's maxScore when available. */
|
|
16
|
+
function normalizedScore(score, maxScore) {
|
|
17
|
+
if (score === null || score === undefined || !Number.isFinite(score))
|
|
18
|
+
return null;
|
|
19
|
+
if (maxScore === undefined || maxScore <= 0)
|
|
20
|
+
return null;
|
|
21
|
+
return Math.max(0, Math.min(1, score / maxScore));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Compute judge calibration for a run.
|
|
25
|
+
* @param run - a persisted run record.
|
|
26
|
+
* @returns the summary, or null when no trial has both a scripted result and a usable judge verdict.
|
|
27
|
+
*/
|
|
28
|
+
export function computeCalibration(run) {
|
|
29
|
+
const maxScore = run.judge?.maxScore;
|
|
30
|
+
const passed = [];
|
|
31
|
+
const failed = [];
|
|
32
|
+
const disagreements = [];
|
|
33
|
+
let withBoth = 0;
|
|
34
|
+
let brierSum = 0;
|
|
35
|
+
let brierCount = 0;
|
|
36
|
+
for (const result of run.cases) {
|
|
37
|
+
const script = result.grade?.taskSuccess;
|
|
38
|
+
const judge = result.judge;
|
|
39
|
+
if (script === undefined || script === null || judge === undefined)
|
|
40
|
+
continue;
|
|
41
|
+
const score = normalizedScore(judge.finalAnswerScore, maxScore);
|
|
42
|
+
const hallucination = judge.hallucination ?? null;
|
|
43
|
+
// A verdict with neither signal is ungraded, not evidence of agreement.
|
|
44
|
+
if (score === null && hallucination === null)
|
|
45
|
+
continue;
|
|
46
|
+
withBoth += 1;
|
|
47
|
+
if (score !== null) {
|
|
48
|
+
if (script)
|
|
49
|
+
passed.push(score);
|
|
50
|
+
else
|
|
51
|
+
failed.push(score);
|
|
52
|
+
const error = score - (script ? 1 : 0);
|
|
53
|
+
brierSum += error * error;
|
|
54
|
+
brierCount += 1;
|
|
55
|
+
}
|
|
56
|
+
// The score drives calibration; the hallucination flag is a fallback.
|
|
57
|
+
const judgePass = score !== null ? score >= 0.5 : !hallucination;
|
|
58
|
+
if (judgePass !== script) {
|
|
59
|
+
disagreements.push({
|
|
60
|
+
caseId: result.caseId, trial: result.trial, scriptPassed: script,
|
|
61
|
+
score: judge.finalAnswerScore ?? null, hallucination,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
disagreements.sort((a, b) => a.caseId.localeCompare(b.caseId) || a.trial - b.trial);
|
|
66
|
+
disagreements.length = Math.min(disagreements.length, 5);
|
|
67
|
+
if (withBoth === 0)
|
|
68
|
+
return null;
|
|
69
|
+
const mean = (values) => values.length === 0 ? null : values.reduce((sum, value) => sum + value, 0) / values.length;
|
|
70
|
+
const passedMean = mean(passed);
|
|
71
|
+
const failedMean = mean(failed);
|
|
72
|
+
let rankingAccuracy = null;
|
|
73
|
+
if (passed.length > 0 && failed.length > 0) {
|
|
74
|
+
let wins = 0;
|
|
75
|
+
for (const high of passed) {
|
|
76
|
+
for (const low of failed)
|
|
77
|
+
wins += high > low ? 1 : high === low ? 0.5 : 0;
|
|
78
|
+
}
|
|
79
|
+
rankingAccuracy = wins / (passed.length * failed.length);
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
pairs: withBoth,
|
|
83
|
+
passedMean,
|
|
84
|
+
failedMean,
|
|
85
|
+
separation: passedMean === null || failedMean === null ? null : passedMean - failedMean,
|
|
86
|
+
rankingAccuracy,
|
|
87
|
+
brier: brierCount === 0 ? null : brierSum / brierCount,
|
|
88
|
+
disagreements,
|
|
89
|
+
};
|
|
90
|
+
}
|
package/lib/command.js
CHANGED
|
@@ -6,13 +6,19 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @module dsh-eval/command
|
|
8
8
|
*/
|
|
9
|
+
import { resolve } from 'node:path';
|
|
10
|
+
import { splitArgv } from "./argv.js";
|
|
9
11
|
import { Command } from 'commander';
|
|
10
12
|
import { parseCmdline } from '@deepseek-ai/dsh-cmdline';
|
|
11
|
-
/**
|
|
13
|
+
/** Turn an optional `--out` flag into a strictly optional startup value. */
|
|
14
|
+
function optionalOut(options) {
|
|
15
|
+
return options.out === undefined ? {} : { outPath: options.out };
|
|
16
|
+
}
|
|
17
|
+
/** Split a single `--dsh` value into argv, honoring quotes and escapes. */
|
|
12
18
|
function splitCommand(value) {
|
|
13
19
|
if (value === undefined)
|
|
14
20
|
return undefined;
|
|
15
|
-
const command = value
|
|
21
|
+
const command = splitArgv(value);
|
|
16
22
|
return command.length === 0 ? undefined : command;
|
|
17
23
|
}
|
|
18
24
|
/**
|
|
@@ -30,6 +36,36 @@ function positiveInteger(program, flag) {
|
|
|
30
36
|
return parsed;
|
|
31
37
|
};
|
|
32
38
|
}
|
|
39
|
+
/** Build a parser for an integer flag such as a reproducibility seed. */
|
|
40
|
+
function integer(program, flag) {
|
|
41
|
+
return (value) => {
|
|
42
|
+
if (!/^[+-]?\d+$/u.test(value))
|
|
43
|
+
program.error(`error: ${flag} must be an integer`);
|
|
44
|
+
const parsed = Number(value);
|
|
45
|
+
if (!Number.isSafeInteger(parsed))
|
|
46
|
+
program.error(`error: ${flag} must be an integer`);
|
|
47
|
+
return parsed;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/** Build a parser for the leaderboard primary metric flag. */
|
|
51
|
+
function leaderboardMetric(program, flag) {
|
|
52
|
+
return (value) => {
|
|
53
|
+
if (value !== 'taskSuccess' && value !== 'strictPassAt1') {
|
|
54
|
+
program.error(`error: ${flag} must be taskSuccess or strictPassAt1`);
|
|
55
|
+
}
|
|
56
|
+
return value;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** Build a parser for a 0..1 tolerance flag. */
|
|
60
|
+
function unitRatio(program, flag) {
|
|
61
|
+
return (value) => {
|
|
62
|
+
const parsed = Number(value);
|
|
63
|
+
if (!Number.isFinite(parsed) || parsed < 0 || parsed > 1) {
|
|
64
|
+
program.error(`error: ${flag} must be between 0 and 1`);
|
|
65
|
+
}
|
|
66
|
+
return parsed;
|
|
67
|
+
};
|
|
68
|
+
}
|
|
33
69
|
/**
|
|
34
70
|
* Build a fresh eval commander program. The root action rejects a bare
|
|
35
71
|
* invocation; the `run` and `report` actions hand the resolved values to the
|
|
@@ -44,8 +80,20 @@ export function evalCommand(publish) {
|
|
|
44
80
|
.name('dsh --profile eval')
|
|
45
81
|
.description('Run agent evaluations over headless dsh profiles and report trace-based metrics.')
|
|
46
82
|
.helpOption('-h, --help', 'show this help')
|
|
83
|
+
.addHelpText('after', `
|
|
84
|
+
Examples:
|
|
85
|
+
dsh --profile eval validate benchmark.yaml
|
|
86
|
+
dsh --profile eval run benchmark.yaml --out run.json
|
|
87
|
+
dsh --profile eval provenance run.json benchmark.yaml
|
|
88
|
+
dsh --profile eval report run.json --brief
|
|
89
|
+
dsh --profile eval export run.json --out trials.csv
|
|
90
|
+
dsh --profile eval compare base.json candidate.json
|
|
91
|
+
dsh --profile eval dashboard base.json candidate.json --out eval.html
|
|
92
|
+
dsh --profile eval gate candidate.json --baseline base.json --max-drop 0.05
|
|
93
|
+
dsh --profile eval gate candidate.json --baseline base.json --require-significance --json
|
|
94
|
+
`)
|
|
47
95
|
.action(() => {
|
|
48
|
-
program.error('error: eval needs a subcommand: run <benchmark.yaml>
|
|
96
|
+
program.error('error: eval needs a subcommand: run <benchmark.yaml>, validate <benchmark.yaml>, provenance <run.json> <benchmark.yaml>, report <run.json>, compare <a.json> <b.json>, export <run.json>, rejudge <run.json>, dashboard <run.json>, leaderboard <run.json>..., gate <candidate.json>, or import <format> <log.jsonl>');
|
|
49
97
|
});
|
|
50
98
|
const run = program.command('run').description('run a benchmark and write its JSON report');
|
|
51
99
|
run
|
|
@@ -53,32 +101,176 @@ export function evalCommand(publish) {
|
|
|
53
101
|
.option('--out <path>', 'output run JSON path', 'eval-run.json')
|
|
54
102
|
.option('--trials <n>', 'override the benchmark trials count', positiveInteger(program, '--trials'))
|
|
55
103
|
.option('--concurrency <n>', 'override the in-flight trial limit', positiveInteger(program, '--concurrency'))
|
|
104
|
+
.option('--seed <n>', 'override the benchmark base seed', integer(program, '--seed'))
|
|
56
105
|
.option('--dsh <cmd>', 'override the dsh launcher command, space-separated')
|
|
57
106
|
.option('--profile <name>', 'override the spawned dsh profile')
|
|
107
|
+
.option('--quiet', 'suppress per-trial progress lines')
|
|
108
|
+
.option('--allow-external-paths', 'allow benchmark-referenced files outside the benchmark directory (trusted benchmarks only)')
|
|
58
109
|
.action((benchmarkPath, options) => {
|
|
59
|
-
|
|
110
|
+
let dshCommand;
|
|
111
|
+
try {
|
|
112
|
+
dshCommand = splitCommand(options.dsh);
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
/* v8 ignore next -- splitArgv only throws Error instances. */
|
|
116
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
117
|
+
program.error(`error: --dsh: ${detail}`);
|
|
118
|
+
}
|
|
119
|
+
// An explicitly supplied but empty launcher is a typo, not "use the
|
|
120
|
+
// default": silently falling back hides the mistake behind a run whose
|
|
121
|
+
// only symptom is an empty stderr and failed trials.
|
|
122
|
+
if (options.dsh !== undefined && dshCommand === undefined) {
|
|
123
|
+
program.error('error: --dsh must contain a command');
|
|
124
|
+
}
|
|
60
125
|
publish({
|
|
61
126
|
kind: 'run',
|
|
62
127
|
benchmarkPath,
|
|
63
128
|
outPath: options.out,
|
|
64
129
|
...(options.trials !== undefined ? { trials: options.trials } : {}),
|
|
65
130
|
...(options.concurrency !== undefined ? { concurrency: options.concurrency } : {}),
|
|
131
|
+
...(options.seed !== undefined ? { seed: options.seed } : {}),
|
|
66
132
|
...(dshCommand !== undefined ? { dshCommand } : {}),
|
|
67
133
|
...(options.profile !== undefined ? { profile: options.profile } : {}),
|
|
134
|
+
quiet: options.quiet === true,
|
|
135
|
+
allowExternalPaths: options.allowExternalPaths === true,
|
|
68
136
|
});
|
|
69
137
|
});
|
|
70
|
-
const report = program.command('report').description('render a persisted run JSON as markdown');
|
|
138
|
+
const report = program.command('report').description('render a persisted run JSON as markdown or JSON');
|
|
71
139
|
report
|
|
72
140
|
.argument('<run.json>', 'path to a run report')
|
|
73
|
-
.
|
|
74
|
-
|
|
141
|
+
.option('--brief', 'print a compact terminal summary instead of the full report')
|
|
142
|
+
.option('--json', 'emit machine-readable JSON instead of markdown')
|
|
143
|
+
.option('--out <path>', 'write the report to a file instead of stdout')
|
|
144
|
+
.action((runPath, options) => {
|
|
145
|
+
publish({
|
|
146
|
+
kind: 'report',
|
|
147
|
+
runPath,
|
|
148
|
+
...(options.brief ? { brief: true } : {}),
|
|
149
|
+
json: options.json === true,
|
|
150
|
+
...(options.out === undefined ? {} : { outPath: options.out }),
|
|
151
|
+
});
|
|
75
152
|
});
|
|
76
|
-
const compare = program.command('compare').description('compare two persisted run reports as
|
|
153
|
+
const compare = program.command('compare').description('compare two persisted run reports as markdown or JSON');
|
|
77
154
|
compare
|
|
78
155
|
.argument('<run-a.json>', 'baseline run report')
|
|
79
156
|
.argument('<run-b.json>', 'candidate run report')
|
|
80
|
-
.
|
|
81
|
-
|
|
157
|
+
.option('--json', 'emit a machine-readable JSON comparison')
|
|
158
|
+
.option('--out <path>', 'write the comparison to a file instead of stdout')
|
|
159
|
+
.action((runPathA, runPathB, options) => {
|
|
160
|
+
publish({ kind: 'compare', runPathA, runPathB, json: options.json === true, ...optionalOut(options) });
|
|
161
|
+
});
|
|
162
|
+
const exporter = program.command('export').description('export a run report as trial-level CSV');
|
|
163
|
+
exporter
|
|
164
|
+
.argument('<run.json>', 'path to a run report')
|
|
165
|
+
.option('--out <path>', 'write CSV to a file instead of stdout')
|
|
166
|
+
.action((runPath, options) => {
|
|
167
|
+
publish({ kind: 'export', runPath, ...(options.out === undefined ? {} : { outPath: options.out }) });
|
|
168
|
+
});
|
|
169
|
+
const validate = program.command('validate').description('validate a benchmark file and print a preflight summary');
|
|
170
|
+
validate
|
|
171
|
+
.argument('<benchmark.yaml>', 'path to a benchmark document')
|
|
172
|
+
.option('--json', 'emit a machine-readable preflight summary')
|
|
173
|
+
.option('--out <path>', 'write the preflight summary to a file instead of stdout')
|
|
174
|
+
.option('--allow-external-paths', 'allow benchmark-referenced files outside the benchmark directory (trusted benchmarks only)')
|
|
175
|
+
.action((benchmarkPath, options) => {
|
|
176
|
+
publish({
|
|
177
|
+
kind: 'validate', benchmarkPath, json: options.json === true,
|
|
178
|
+
allowExternalPaths: options.allowExternalPaths === true,
|
|
179
|
+
...optionalOut(options),
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
const provenance = program.command('provenance').description('verify a run report against its benchmark inputs');
|
|
183
|
+
provenance
|
|
184
|
+
.argument('<run.json>', 'path to a persisted run report')
|
|
185
|
+
.argument('<benchmark.yaml>', 'path to the benchmark document')
|
|
186
|
+
.option('--json', 'emit a machine-readable verification result')
|
|
187
|
+
.option('--out <path>', 'write the verification result to a file instead of stdout')
|
|
188
|
+
.option('--allow-external-paths', 'allow referenced files outside the benchmark directory (trusted benchmarks only)')
|
|
189
|
+
.action((runPath, benchmarkPath, options) => {
|
|
190
|
+
publish({
|
|
191
|
+
kind: 'provenance', runPath, benchmarkPath,
|
|
192
|
+
json: options.json === true,
|
|
193
|
+
allowExternalPaths: options.allowExternalPaths === true,
|
|
194
|
+
...optionalOut(options),
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
const leaderboard = program.command('leaderboard').description('rank persisted runs by pooled task success or strict pass@1');
|
|
198
|
+
leaderboard
|
|
199
|
+
.argument('<run.json...>', 'paths to run reports')
|
|
200
|
+
.option('--json', 'emit a machine-readable JSON leaderboard')
|
|
201
|
+
.option('--out <path>', 'write the leaderboard to a file instead of stdout')
|
|
202
|
+
.option('--metric <name>', 'primary ranking metric: taskSuccess (default) or strictPassAt1', leaderboardMetric(program, '--metric'))
|
|
203
|
+
.action((runPaths, options) => {
|
|
204
|
+
publish({
|
|
205
|
+
kind: 'leaderboard', runPaths, json: options.json === true,
|
|
206
|
+
...(options.metric === undefined ? {} : { metric: options.metric }),
|
|
207
|
+
...optionalOut(options),
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
const gate = program.command('gate').description('fail a CI build when a candidate run regresses against a baseline');
|
|
211
|
+
gate
|
|
212
|
+
.argument('<candidate.json>', 'path to the candidate run report')
|
|
213
|
+
.option('--baseline <path>', 'path to the trusted baseline run report')
|
|
214
|
+
.option('--max-drop <ratio>', 'largest tolerated quality regression, 0..1', unitRatio(program, '--max-drop'), 0)
|
|
215
|
+
.option('--max-cost-increase <ratio>', 'largest tolerated cost/trial increase over baseline, 0..1', unitRatio(program, '--max-cost-increase'))
|
|
216
|
+
.option('--max-latency-increase <ratio>', 'largest tolerated latency/trial increase over baseline, 0..1', unitRatio(program, '--max-latency-increase'))
|
|
217
|
+
.option('--allow-incomplete', 'do not fail on extra unscored trials')
|
|
218
|
+
.option('--require-significance', 'only fail quality drops confirmed by a paired sign test')
|
|
219
|
+
.option('--json', 'emit a machine-readable JSON verdict instead of markdown')
|
|
220
|
+
.option('--out <path>', 'write the verdict to a file instead of stdout')
|
|
221
|
+
.action((candidatePath, options) => {
|
|
222
|
+
if (options.baseline === undefined)
|
|
223
|
+
program.error('error: gate needs --baseline <path>');
|
|
224
|
+
publish({
|
|
225
|
+
kind: 'gate',
|
|
226
|
+
candidatePath,
|
|
227
|
+
baselinePath: options.baseline,
|
|
228
|
+
maxDrop: options.maxDrop,
|
|
229
|
+
...(options.maxCostIncrease === undefined ? {} : { maxCostIncrease: options.maxCostIncrease }),
|
|
230
|
+
...(options.maxLatencyIncrease === undefined ? {} : { maxLatencyIncrease: options.maxLatencyIncrease }),
|
|
231
|
+
allowIncomplete: options.allowIncomplete === true,
|
|
232
|
+
requireSignificance: options.requireSignificance === true,
|
|
233
|
+
json: options.json === true,
|
|
234
|
+
...optionalOut(options),
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
const dashboard = program.command('dashboard').description('render persisted runs as a standalone HTML dashboard or leaderboard');
|
|
238
|
+
dashboard
|
|
239
|
+
.argument('<run.json...>', 'one run, two to compare, or three+ for a leaderboard')
|
|
240
|
+
.option('--out <path>', 'output HTML path', 'eval-dashboard.html')
|
|
241
|
+
.option('--metric <name>', 'leaderboard metric (3+ runs): taskSuccess or strictPassAt1', leaderboardMetric(program, '--metric'))
|
|
242
|
+
.action((runPaths, options) => {
|
|
243
|
+
publish({
|
|
244
|
+
kind: 'dashboard', runPaths, outPath: options.out,
|
|
245
|
+
...(options.metric === undefined ? {} : { metric: options.metric }),
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
const rejudge = program.command('rejudge').description('re-judge a stored run from its traces without re-running the agent');
|
|
249
|
+
rejudge
|
|
250
|
+
.argument('<run.json>', 'path to a run report with judge config and case inputs')
|
|
251
|
+
.option('--out <path>', 'output run JSON path; must differ from the input', 'rejudged-run.json')
|
|
252
|
+
.option('--judge-model <id>', 'judge model id; also enables overriding the stored judge config')
|
|
253
|
+
.option('--judge-provider <name>', 'judge provider route, default deepseek')
|
|
254
|
+
.option('--judge-rubric <text>', 'rubric appended to the judge prompt')
|
|
255
|
+
.option('--judge-max-score <n>', 'maximum judge score', positiveInteger(program, '--judge-max-score'))
|
|
256
|
+
.action((runPath, options) => {
|
|
257
|
+
const samePath = resolve(runPath).toLowerCase() === resolve(options.out).toLowerCase();
|
|
258
|
+
if (samePath) {
|
|
259
|
+
program.error('error: --out must differ from the input run report');
|
|
260
|
+
}
|
|
261
|
+
publish({
|
|
262
|
+
kind: 'rejudge',
|
|
263
|
+
runPath,
|
|
264
|
+
outPath: options.out,
|
|
265
|
+
...(options.judgeModel === undefined ? {} : {
|
|
266
|
+
judge: {
|
|
267
|
+
provider: options.judgeProvider ?? 'deepseek',
|
|
268
|
+
model: options.judgeModel,
|
|
269
|
+
maxScore: options.judgeMaxScore ?? 10,
|
|
270
|
+
...(options.judgeRubric === undefined ? {} : { rubric: options.judgeRubric }),
|
|
271
|
+
},
|
|
272
|
+
}),
|
|
273
|
+
});
|
|
82
274
|
});
|
|
83
275
|
const importer = program.command('import').description('import an external harness session log as a run report');
|
|
84
276
|
importer
|