dsh-eval 0.3.0 → 0.4.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/README.md +8 -2
- package/README.zh.md +75 -26
- package/lib/benchmark.js +125 -0
- package/lib/command.js +109 -0
- package/lib/compare.js +194 -0
- package/lib/import.js +318 -0
- package/lib/index.js +2 -1
- package/lib/judge.js +165 -0
- package/lib/metrics.js +196 -0
- package/lib/report.js +126 -0
- package/lib/runner.js +355 -0
- package/lib/stats.js +112 -0
- package/lib/trace.js +136 -0
- package/lib/types/command.d.ts +1 -0
- package/lib/types/compare.d.ts +9 -6
- package/lib/types/index.d.ts +1 -1
- package/lib/types/runner.d.ts +12 -1
- package/lib/types/stats.d.ts +61 -0
- package/lib/types/types.d.ts +2 -0
- package/lib/types.js +8 -0
- package/package.json +29 -22
- package/src/benchmark.ts +2 -0
- package/src/command.ts +20 -5
- package/src/compare.ts +38 -17
- package/src/index.ts +2 -1
- package/src/runner.ts +31 -4
- package/src/stats.ts +147 -0
- package/src/types.ts +2 -0
- package/LICENSE +0 -21
package/lib/trace.js
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session-log harvesting and parsing for dsh-eval. A trial's headless dsh
|
|
3
|
+
* writes a plain-JSONL session log under its DSH_HOME; the importer reads the
|
|
4
|
+
* header line, decodes every event row (packed chunk rows included) through
|
|
5
|
+
* the session package's storage decoder, and enforces seq continuity.
|
|
6
|
+
*
|
|
7
|
+
* @module dsh-eval/trace
|
|
8
|
+
*/
|
|
9
|
+
import { readFile, readdir, stat } from 'node:fs/promises';
|
|
10
|
+
import { join } from 'node:path';
|
|
11
|
+
import { decodeStorageRecord, SessionId } from '@deepseek-ai/dsh-session';
|
|
12
|
+
import { z } from 'zod';
|
|
13
|
+
const headerSchema = z.object({
|
|
14
|
+
type: z.literal('session'),
|
|
15
|
+
id: z.string().min(1),
|
|
16
|
+
createdAt: z.number().nonnegative(),
|
|
17
|
+
}).loose();
|
|
18
|
+
/**
|
|
19
|
+
* Parse a plain-JSONL session log into a trace.
|
|
20
|
+
* @param text - the log file's UTF-8 text, header line first.
|
|
21
|
+
* @returns the parsed trace.
|
|
22
|
+
* @throws when the header is missing or malformed, a row is not valid JSON,
|
|
23
|
+
* or event seqs are not contiguous.
|
|
24
|
+
*/
|
|
25
|
+
export function parseSessionLog(text) {
|
|
26
|
+
const lines = text.split(/\r?\n/u).filter(line => line.trim() !== '');
|
|
27
|
+
if (lines.length === 0)
|
|
28
|
+
throw new Error('empty session log');
|
|
29
|
+
const header = headerSchema.parse(JSON.parse(lines[0]));
|
|
30
|
+
const events = [];
|
|
31
|
+
for (let index = 1; index < lines.length; index++) {
|
|
32
|
+
const line = lines[index];
|
|
33
|
+
let record;
|
|
34
|
+
try {
|
|
35
|
+
record = JSON.parse(line);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
throw new Error(`corrupt session log: invalid JSON at line ${index + 1}`);
|
|
39
|
+
}
|
|
40
|
+
for (const event of decodeStorageRecord(record)) {
|
|
41
|
+
if (event.seq !== events.length) {
|
|
42
|
+
throw new Error(`corrupt session log: seq gap at line ${index + 1} (expected ${events.length}, got ${event.seq})`);
|
|
43
|
+
}
|
|
44
|
+
events.push(event);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
sessionId: SessionId(header.id),
|
|
49
|
+
createdAt: header.createdAt,
|
|
50
|
+
events,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Load and parse the primary session log at a path.
|
|
55
|
+
* @param path - absolute path to a `session.jsonl` file.
|
|
56
|
+
* @returns the parsed trace.
|
|
57
|
+
*/
|
|
58
|
+
export async function loadTrace(path) {
|
|
59
|
+
return parseSessionLog(await readFile(path, 'utf8'));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Find the newest primary `session.jsonl` under a DSH_HOME tree, descending
|
|
63
|
+
* into directories without following symlinks.
|
|
64
|
+
* @param root - the DSH_HOME directory to scan.
|
|
65
|
+
* @returns the newest primary log's absolute path, or null when none exists.
|
|
66
|
+
*/
|
|
67
|
+
export async function findPrimarySessionLog(root) {
|
|
68
|
+
let entries;
|
|
69
|
+
try {
|
|
70
|
+
entries = await readdir(root, { withFileTypes: true });
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
let best = null;
|
|
76
|
+
for (const entry of entries) {
|
|
77
|
+
if (entry.isDirectory()) {
|
|
78
|
+
const found = await findPrimarySessionLog(join(root, entry.name));
|
|
79
|
+
if (found !== null) {
|
|
80
|
+
const mtime = (await stat(found)).mtimeMs;
|
|
81
|
+
if (best === null || mtime > best.mtime)
|
|
82
|
+
best = { path: found, mtime };
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else if (entry.isFile() && entry.name === 'session.jsonl') {
|
|
86
|
+
const mtime = (await stat(join(root, entry.name))).mtimeMs;
|
|
87
|
+
if (best === null || mtime > best.mtime)
|
|
88
|
+
best = { path: join(root, entry.name), mtime };
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return best?.path ?? null;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Find every `session.jsonl` under a DSH_HOME tree, sorted by modification
|
|
95
|
+
* time ascending so the parent session (started first) comes first.
|
|
96
|
+
* @param root - the DSH_HOME directory to scan.
|
|
97
|
+
* @returns absolute log paths in ascending mtime order.
|
|
98
|
+
*/
|
|
99
|
+
export async function findSessionLogs(root) {
|
|
100
|
+
let entries;
|
|
101
|
+
try {
|
|
102
|
+
entries = await readdir(root, { withFileTypes: true });
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
return [];
|
|
106
|
+
}
|
|
107
|
+
const found = [];
|
|
108
|
+
for (const entry of entries) {
|
|
109
|
+
if (entry.isDirectory()) {
|
|
110
|
+
for (const nested of await findSessionLogs(join(root, entry.name))) {
|
|
111
|
+
found.push({ path: nested, mtime: (await stat(nested)).mtimeMs });
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else if (entry.isFile() && entry.name === 'session.jsonl') {
|
|
115
|
+
found.push({ path: join(root, entry.name), mtime: (await stat(join(root, entry.name))).mtimeMs });
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return found.sort((a, b) => a.mtime - b.mtime).map(entry => entry.path);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Merge traces into one timeline: events from every trace sorted by event
|
|
122
|
+
* time, ties broken by source order. The primary trace's header (session id
|
|
123
|
+
* and creation time) labels the merged trace.
|
|
124
|
+
* @param traces - harvested traces, primary first.
|
|
125
|
+
* @returns the merged trace.
|
|
126
|
+
*/
|
|
127
|
+
export function mergeTraces(traces) {
|
|
128
|
+
const primary = traces[0];
|
|
129
|
+
if (primary === undefined)
|
|
130
|
+
throw new Error('mergeTraces requires at least one trace');
|
|
131
|
+
const events = traces
|
|
132
|
+
.flatMap((trace, source) => trace.events.map(event => ({ event, source })))
|
|
133
|
+
.sort((a, b) => a.event.time - b.event.time || a.source - b.source)
|
|
134
|
+
.map(entry => entry.event);
|
|
135
|
+
return { sessionId: primary.sessionId, createdAt: primary.createdAt, events };
|
|
136
|
+
}
|
package/lib/types/command.d.ts
CHANGED
package/lib/types/compare.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* @module dsh-eval/compare
|
|
6
6
|
*/
|
|
7
7
|
import type { EvalRun } from './types.ts';
|
|
8
|
+
import { type PairedDelta, type SignTestOutcome } from './stats.ts';
|
|
8
9
|
/** One compared metric row. */
|
|
9
10
|
export interface CompareRow {
|
|
10
11
|
/** Metric label. */
|
|
@@ -28,12 +29,14 @@ export interface PairedStats {
|
|
|
28
29
|
ties: number;
|
|
29
30
|
/** The metric used for win/lose/tie classification. */
|
|
30
31
|
primaryMetric: 'task success' | 'tool selection accuracy' | 'final answer score';
|
|
31
|
-
/**
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
|
|
32
|
+
/** Exact two-sided sign test over the discordant pairs of the primary metric. */
|
|
33
|
+
test: SignTestOutcome;
|
|
34
|
+
/** Paired step delta (`b - a`) with its bootstrap interval, or null when no pair is numeric. */
|
|
35
|
+
stepsDelta: PairedDelta | null;
|
|
36
|
+
/** Paired token delta (`b - a`) with its bootstrap interval, or null when no pair is numeric. */
|
|
37
|
+
tokensDelta: PairedDelta | null;
|
|
38
|
+
/** Paired judge-score delta (`b - a`) with its bootstrap interval, or null without verdicts. */
|
|
39
|
+
scoreDelta: PairedDelta | null;
|
|
37
40
|
}
|
|
38
41
|
/**
|
|
39
42
|
* Pair both runs' trials by case id and trial index and compute win/lose/tie
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* dsh-eval
|
|
2
|
+
* dsh-eval — agent evaluation over headless dsh profiles.
|
|
3
3
|
*
|
|
4
4
|
* The eval bundle mounts this command-line plugin over dsh-base. It parses
|
|
5
5
|
* `dsh --profile eval run <benchmark.yaml>` / `report <run.json>`, spawns one
|
package/lib/types/runner.d.ts
CHANGED
|
@@ -22,13 +22,24 @@ export interface RunOptions {
|
|
|
22
22
|
profile?: string;
|
|
23
23
|
/** Override the benchmark's trials per case. */
|
|
24
24
|
trials?: number;
|
|
25
|
+
/** Override the benchmark's in-flight trial limit. */
|
|
26
|
+
concurrency?: number;
|
|
25
27
|
/** Root for trial directories; defaults to the platform temp dir. */
|
|
26
28
|
tempRoot?: string;
|
|
27
29
|
/** LLM-judge chat seam; required when the benchmark configures a judge. */
|
|
28
30
|
judgeChat?: JudgeChat;
|
|
29
31
|
}
|
|
30
32
|
/**
|
|
31
|
-
* Run every case x trial
|
|
33
|
+
* Run every case x trial through a bounded worker pool and aggregate the
|
|
34
|
+
* completed trials.
|
|
35
|
+
*
|
|
36
|
+
* Trials are independent by construction — each owns a private temp directory,
|
|
37
|
+
* workspace copy, and DSH_HOME — so the only thing serial execution buys is
|
|
38
|
+
* determinism. The pool keeps that anyway: results land at their task index, so
|
|
39
|
+
* the run record stays in case-then-trial order no matter how the workers
|
|
40
|
+
* interleave. The first failure to escape `runCaseTrial` stops the remaining
|
|
41
|
+
* workers and rejects the run, which is the same contract as the serial loop.
|
|
42
|
+
*
|
|
32
43
|
* @param benchmark - the loaded benchmark.
|
|
33
44
|
* @param options - runtime overrides and test seams.
|
|
34
45
|
* @returns the completed run record, written by the caller.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Paired-comparison statistics for cross-run reports: an exact two-sided sign
|
|
3
|
+
* test over paired outcomes, and a seeded bootstrap confidence interval for a
|
|
4
|
+
* paired mean delta.
|
|
5
|
+
*
|
|
6
|
+
* Both are distribution-free on purpose. A benchmark run yields few paired
|
|
7
|
+
* trials (single digits to low tens), the per-trial deltas are integers with
|
|
8
|
+
* long tails, and the question is "on the same case, did B beat A" — which a
|
|
9
|
+
* paired sign test answers exactly, without a normality or symmetry assumption
|
|
10
|
+
* the data cannot support. Ties carry no sign and drop out of the test, as the
|
|
11
|
+
* sign test requires.
|
|
12
|
+
*
|
|
13
|
+
* The bootstrap resamples the observed deltas with replacement, so its interval
|
|
14
|
+
* needs no shape assumption either, and it is seeded so that re-running
|
|
15
|
+
* `compare` on the same reports prints a byte-identical table.
|
|
16
|
+
*
|
|
17
|
+
* @module dsh-eval/stats
|
|
18
|
+
*/
|
|
19
|
+
/** Outcome of an exact two-sided sign test. */
|
|
20
|
+
export interface SignTestOutcome {
|
|
21
|
+
/** Discordant pairs (`wins + losses`); ties drop out of the test. */
|
|
22
|
+
discordant: number;
|
|
23
|
+
/** Exact two-sided p-value; 1 when every pair tied. */
|
|
24
|
+
pValue: number;
|
|
25
|
+
}
|
|
26
|
+
/** A paired mean delta with its bootstrap interval. */
|
|
27
|
+
export interface PairedDelta {
|
|
28
|
+
/** Mean per-pair delta (`b - a`). */
|
|
29
|
+
mean: number;
|
|
30
|
+
/** Lower interval bound, or null when fewer than two pairs are available. */
|
|
31
|
+
lower: number | null;
|
|
32
|
+
/** Upper interval bound, or null when fewer than two pairs are available. */
|
|
33
|
+
upper: number | null;
|
|
34
|
+
/** Pairs contributing to the mean. */
|
|
35
|
+
pairs: number;
|
|
36
|
+
}
|
|
37
|
+
/** Knobs for {@link pairedDelta}; defaults keep reports reproducible. */
|
|
38
|
+
export interface BootstrapOptions {
|
|
39
|
+
/** Interval confidence, default `0.95`. */
|
|
40
|
+
confidence?: number;
|
|
41
|
+
/** Resample count, default `2000`. */
|
|
42
|
+
resamples?: number;
|
|
43
|
+
/** PRNG seed, default `0`. */
|
|
44
|
+
seed?: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Exact two-sided sign test. Under the null hypothesis a discordant pair is a
|
|
48
|
+
* win or a loss with equal probability, so the win count is Binomial(n, 1/2)
|
|
49
|
+
* and the p-value doubles the smaller tail.
|
|
50
|
+
* @param wins - pairs where B beat A.
|
|
51
|
+
* @param losses - pairs where A beat B.
|
|
52
|
+
* @returns the discordant count and the exact p-value in `[0, 1]`.
|
|
53
|
+
*/
|
|
54
|
+
export declare function signTest(wins: number, losses: number): SignTestOutcome;
|
|
55
|
+
/**
|
|
56
|
+
* Mean paired delta with a percentile bootstrap interval.
|
|
57
|
+
* @param deltas - per-pair differences (`b - a`).
|
|
58
|
+
* @param options - confidence, resample count, and PRNG seed.
|
|
59
|
+
* @returns the mean and interval, or null when `deltas` is empty.
|
|
60
|
+
*/
|
|
61
|
+
export declare function pairedDelta(deltas: readonly number[], options?: BootstrapOptions): PairedDelta | null;
|
package/lib/types/types.d.ts
CHANGED
|
@@ -67,6 +67,8 @@ export interface Benchmark {
|
|
|
67
67
|
command: readonly string[];
|
|
68
68
|
/** Trials per case. */
|
|
69
69
|
trials: number;
|
|
70
|
+
/** Case x trial executions allowed in flight at once; defaults to 1 (serial). */
|
|
71
|
+
concurrency: number;
|
|
70
72
|
/** Per-trial timeout in milliseconds. */
|
|
71
73
|
timeoutMs: number;
|
|
72
74
|
/** Reserved deterministic seed for future paired comparisons. */
|
package/lib/types.js
ADDED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-eval",
|
|
3
3
|
"description": "Agent evaluation platform: benchmark YAML, headless run orchestration, trace-based metrics, and run reports",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
"type": "git",
|
|
10
10
|
"url": "git+https://github.com/hccccc01333/dsh-eval.git"
|
|
11
11
|
},
|
|
12
|
+
"homepage": "https://github.com/hccccc01333/dsh-eval#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/hccccc01333/dsh-eval/issues"
|
|
15
|
+
},
|
|
12
16
|
"type": "module",
|
|
13
17
|
"main": "lib/index.js",
|
|
14
18
|
"types": "lib/types/index.d.ts",
|
|
@@ -23,21 +27,22 @@
|
|
|
23
27
|
},
|
|
24
28
|
"./types": {
|
|
25
29
|
"types": "./lib/types/types.d.ts",
|
|
26
|
-
"default": "./lib/types
|
|
30
|
+
"default": "./lib/types.js"
|
|
27
31
|
},
|
|
28
32
|
"./cordis.patch.yml": "./cordis.patch.yml",
|
|
29
33
|
"./src/*": "./src/*",
|
|
30
34
|
"./package.json": "./package.json"
|
|
31
35
|
},
|
|
32
36
|
"files": [
|
|
33
|
-
"lib
|
|
34
|
-
"lib
|
|
37
|
+
"lib/**/*.js",
|
|
38
|
+
"lib/**/*.d.ts",
|
|
35
39
|
"cordis.patch.yml",
|
|
36
|
-
"lib/types/**/*.js",
|
|
37
|
-
"lib/types/**/*.d.ts",
|
|
38
40
|
"src/**/*.ts"
|
|
39
41
|
],
|
|
40
42
|
"license": "MIT",
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=22.19.0"
|
|
45
|
+
},
|
|
41
46
|
"keywords": [
|
|
42
47
|
"deepseek-harness",
|
|
43
48
|
"dsh",
|
|
@@ -51,6 +56,14 @@
|
|
|
51
56
|
"patch": "./cordis.patch.yml"
|
|
52
57
|
}
|
|
53
58
|
},
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "tsc -p tsconfig.build.json",
|
|
61
|
+
"prepack": "npm run build",
|
|
62
|
+
"test": "vitest run",
|
|
63
|
+
"test:coverage": "vitest run --coverage",
|
|
64
|
+
"test:pack": "node scripts/pack-smoke.mjs",
|
|
65
|
+
"typecheck": "tsc --noEmit"
|
|
66
|
+
},
|
|
54
67
|
"dependencies": {
|
|
55
68
|
"commander": "^15.0.0",
|
|
56
69
|
"js-yaml": "^4.2.0",
|
|
@@ -65,24 +78,18 @@
|
|
|
65
78
|
"@deepseek-ai/dsh-session": "^0.1.0-rc.6"
|
|
66
79
|
},
|
|
67
80
|
"devDependencies": {
|
|
81
|
+
"@deepseek-ai/cordis": "^4.0.1",
|
|
82
|
+
"@deepseek-ai/cordis-plugin-include": "^1.0.6",
|
|
83
|
+
"@deepseek-ai/cordis-plugin-loader": "^1.0.2",
|
|
84
|
+
"@deepseek-ai/dsh-cmdline": "^0.1.0-rc.6",
|
|
85
|
+
"@deepseek-ai/dsh-invariants": "^0.1.0-rc.6",
|
|
86
|
+
"@deepseek-ai/dsh-llm": "^0.1.0-rc.6",
|
|
87
|
+
"@deepseek-ai/dsh-llm-retry": "^0.1.0-rc.6",
|
|
88
|
+
"@deepseek-ai/dsh-session": "^0.1.0-rc.6",
|
|
68
89
|
"@types/js-yaml": "^4.0.9",
|
|
69
90
|
"@types/node": "^22.20.0",
|
|
70
91
|
"@vitest/coverage-v8": "4.1.10",
|
|
71
92
|
"typescript": "^6.0.3",
|
|
72
|
-
"vitest": "^4.1.8"
|
|
73
|
-
"@deepseek-ai/cordis": "^4.0.1",
|
|
74
|
-
"@deepseek-ai/cordis-plugin-include": "^1.0.6",
|
|
75
|
-
"@deepseek-ai/cordis-plugin-loader": "^1.0.2",
|
|
76
|
-
"@deepseek-ai/dsh-cmdline": "^0.1.0-rc.5",
|
|
77
|
-
"@deepseek-ai/dsh-invariants": "^0.1.0-rc.5",
|
|
78
|
-
"@deepseek-ai/dsh-llm": "^0.1.0-rc.5",
|
|
79
|
-
"@deepseek-ai/dsh-llm-retry": "^0.1.0-rc.5",
|
|
80
|
-
"@deepseek-ai/dsh-session": "^0.1.0-rc.5"
|
|
81
|
-
},
|
|
82
|
-
"scripts": {
|
|
83
|
-
"build": "tsc -p tsconfig.build.json",
|
|
84
|
-
"test": "vitest run",
|
|
85
|
-
"test:coverage": "vitest run --coverage",
|
|
86
|
-
"typecheck": "tsc --noEmit"
|
|
93
|
+
"vitest": "^4.1.8"
|
|
87
94
|
}
|
|
88
|
-
}
|
|
95
|
+
}
|
package/src/benchmark.ts
CHANGED
|
@@ -53,6 +53,7 @@ const benchmarkSchema = z.object({
|
|
|
53
53
|
profile: z.string().min(1).default('headless'),
|
|
54
54
|
command: z.array(z.string().min(1)).default(['dsh']),
|
|
55
55
|
trials: z.number().int().positive().default(1),
|
|
56
|
+
concurrency: z.number().int().positive().default(1),
|
|
56
57
|
timeoutMs: z.number().int().positive().default(600_000),
|
|
57
58
|
seed: z.number().int().default(0),
|
|
58
59
|
cases: z.array(benchmarkCaseSchema).min(1),
|
|
@@ -117,6 +118,7 @@ export async function parseBenchmark(text: string, baseDir: string): Promise<Ben
|
|
|
117
118
|
profile: parsed.profile,
|
|
118
119
|
command: parsed.command,
|
|
119
120
|
trials: parsed.trials,
|
|
121
|
+
concurrency: parsed.concurrency,
|
|
120
122
|
timeoutMs: parsed.timeoutMs,
|
|
121
123
|
seed: parsed.seed,
|
|
122
124
|
cases,
|
package/src/command.ts
CHANGED
|
@@ -19,6 +19,7 @@ export type EvalStartupValues =
|
|
|
19
19
|
benchmarkPath: string
|
|
20
20
|
outPath: string
|
|
21
21
|
trials?: number
|
|
22
|
+
concurrency?: number
|
|
22
23
|
dshCommand?: readonly string[]
|
|
23
24
|
profile?: string
|
|
24
25
|
}
|
|
@@ -43,6 +44,7 @@ export type EvalStartupValues =
|
|
|
43
44
|
interface RunCommandOptions {
|
|
44
45
|
out: string
|
|
45
46
|
trials?: number
|
|
47
|
+
concurrency?: number
|
|
46
48
|
dsh?: string
|
|
47
49
|
profile?: string
|
|
48
50
|
}
|
|
@@ -60,6 +62,21 @@ function splitCommand(value: string | undefined): readonly string[] | undefined
|
|
|
60
62
|
return command.length === 0 ? undefined : command
|
|
61
63
|
}
|
|
62
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Build a commander option parser for a positive-integer flag, so `--trials`
|
|
67
|
+
* and `--concurrency` reject the same inputs with the same message shape.
|
|
68
|
+
* @param program - the program to error through.
|
|
69
|
+
* @param flag - the flag name, for the error text.
|
|
70
|
+
* @returns the parser.
|
|
71
|
+
*/
|
|
72
|
+
function positiveInteger(program: Command, flag: string): (value: string) => number {
|
|
73
|
+
return (value) => {
|
|
74
|
+
const parsed = Number(value)
|
|
75
|
+
if (!Number.isInteger(parsed) || parsed <= 0) program.error(`error: ${flag} must be a positive integer`)
|
|
76
|
+
return parsed
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
63
80
|
/**
|
|
64
81
|
* Build a fresh eval commander program. The root action rejects a bare
|
|
65
82
|
* invocation; the `run` and `report` actions hand the resolved values to the
|
|
@@ -81,11 +98,8 @@ export function evalCommand(publish: (values: EvalStartupValues) => void): Comma
|
|
|
81
98
|
run
|
|
82
99
|
.argument('<benchmark.yaml>', 'path to the benchmark document')
|
|
83
100
|
.option('--out <path>', 'output run JSON path', 'eval-run.json')
|
|
84
|
-
.option('--trials <n>', 'override the benchmark trials count', (
|
|
85
|
-
|
|
86
|
-
if (!Number.isInteger(parsed) || parsed <= 0) program.error('error: --trials must be a positive integer')
|
|
87
|
-
return parsed
|
|
88
|
-
})
|
|
101
|
+
.option('--trials <n>', 'override the benchmark trials count', positiveInteger(program, '--trials'))
|
|
102
|
+
.option('--concurrency <n>', 'override the in-flight trial limit', positiveInteger(program, '--concurrency'))
|
|
89
103
|
.option('--dsh <cmd>', 'override the dsh launcher command, space-separated')
|
|
90
104
|
.option('--profile <name>', 'override the spawned dsh profile')
|
|
91
105
|
.action((benchmarkPath: string, options: RunCommandOptions) => {
|
|
@@ -95,6 +109,7 @@ export function evalCommand(publish: (values: EvalStartupValues) => void): Comma
|
|
|
95
109
|
benchmarkPath,
|
|
96
110
|
outPath: options.out,
|
|
97
111
|
...(options.trials !== undefined ? { trials: options.trials } : {}),
|
|
112
|
+
...(options.concurrency !== undefined ? { concurrency: options.concurrency } : {}),
|
|
98
113
|
...(dshCommand !== undefined ? { dshCommand } : {}),
|
|
99
114
|
...(options.profile !== undefined ? { profile: options.profile } : {}),
|
|
100
115
|
})
|
package/src/compare.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import type { EvalRun, EvalTrialResult } from './types.ts'
|
|
9
|
+
import { pairedDelta, signTest, type PairedDelta, type SignTestOutcome } from './stats.ts'
|
|
9
10
|
|
|
10
11
|
/** One compared metric row. */
|
|
11
12
|
export interface CompareRow {
|
|
@@ -31,12 +32,14 @@ export interface PairedStats {
|
|
|
31
32
|
ties: number
|
|
32
33
|
/** The metric used for win/lose/tie classification. */
|
|
33
34
|
primaryMetric: 'task success' | 'tool selection accuracy' | 'final answer score'
|
|
34
|
-
/**
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
|
|
35
|
+
/** Exact two-sided sign test over the discordant pairs of the primary metric. */
|
|
36
|
+
test: SignTestOutcome
|
|
37
|
+
/** Paired step delta (`b - a`) with its bootstrap interval, or null when no pair is numeric. */
|
|
38
|
+
stepsDelta: PairedDelta | null
|
|
39
|
+
/** Paired token delta (`b - a`) with its bootstrap interval, or null when no pair is numeric. */
|
|
40
|
+
tokensDelta: PairedDelta | null
|
|
41
|
+
/** Paired judge-score delta (`b - a`) with its bootstrap interval, or null without verdicts. */
|
|
42
|
+
scoreDelta: PairedDelta | null
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
/** Render a nullable number with a dash placeholder. */
|
|
@@ -56,6 +59,19 @@ function formatDelta(a: number | null, b: number | null, unit: 'pp' | '' = ''):
|
|
|
56
59
|
return `${delta >= 0 ? '+' : ''}${delta.toFixed(1)}${unit}`
|
|
57
60
|
}
|
|
58
61
|
|
|
62
|
+
/** Render a paired delta with its bootstrap interval when the sample allows one. */
|
|
63
|
+
function formatPairedDelta(delta: PairedDelta): string {
|
|
64
|
+
const mean = formatDelta(0, delta.mean)
|
|
65
|
+
return delta.lower === null || delta.upper === null
|
|
66
|
+
? mean
|
|
67
|
+
: `${mean} [95% CI ${formatDelta(0, delta.lower)}, ${formatDelta(0, delta.upper)}]`
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Render an exact p-value, collapsing anything below the print precision. */
|
|
71
|
+
function formatPValue(pValue: number): string {
|
|
72
|
+
return pValue < 0.001 ? '<0.001' : pValue.toFixed(3)
|
|
73
|
+
}
|
|
74
|
+
|
|
59
75
|
/** A metric that can classify a paired winner. */
|
|
60
76
|
type PairedMetric = 'task success' | 'tool selection accuracy' | 'final answer score'
|
|
61
77
|
|
|
@@ -133,17 +149,16 @@ export function pairedCompare(a: EvalRun, b: EvalRun): PairedStats | null {
|
|
|
133
149
|
scoreDeltas.push(bScore - aScore)
|
|
134
150
|
}
|
|
135
151
|
}
|
|
136
|
-
const mean = (values: readonly number[]): number | null =>
|
|
137
|
-
values.length === 0 ? null : values.reduce((total, value) => total + value, 0) / values.length
|
|
138
152
|
return {
|
|
139
153
|
pairs: pairs.length,
|
|
140
154
|
wins,
|
|
141
155
|
losses,
|
|
142
156
|
ties,
|
|
143
157
|
primaryMetric,
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
158
|
+
test: signTest(wins, losses),
|
|
159
|
+
stepsDelta: pairedDelta(stepDeltas),
|
|
160
|
+
tokensDelta: pairedDelta(tokenDeltas),
|
|
161
|
+
scoreDelta: pairedDelta(scoreDeltas),
|
|
147
162
|
}
|
|
148
163
|
}
|
|
149
164
|
|
|
@@ -193,14 +208,20 @@ export function compareRuns(a: EvalRun, b: EvalRun): CompareRow[] {
|
|
|
193
208
|
b: '–',
|
|
194
209
|
delta: '–',
|
|
195
210
|
},
|
|
196
|
-
|
|
197
|
-
metric:
|
|
211
|
+
{
|
|
212
|
+
metric: `paired ${paired.primaryMetric} p (sign test)`,
|
|
213
|
+
a: '–',
|
|
214
|
+
b: '–',
|
|
215
|
+
delta: `${formatPValue(paired.test.pValue)} (n=${paired.test.discordant})`,
|
|
216
|
+
},
|
|
217
|
+
...(paired.stepsDelta === null ? [] : [{
|
|
218
|
+
metric: 'paired steps delta (B-A)', a: '–', b: '–', delta: formatPairedDelta(paired.stepsDelta),
|
|
198
219
|
}]),
|
|
199
|
-
...(paired.
|
|
200
|
-
metric: 'paired tokens delta (B-A)', a: '–', b: '–', delta:
|
|
220
|
+
...(paired.tokensDelta === null ? [] : [{
|
|
221
|
+
metric: 'paired tokens delta (B-A)', a: '–', b: '–', delta: formatPairedDelta(paired.tokensDelta),
|
|
201
222
|
}]),
|
|
202
|
-
...(paired.
|
|
203
|
-
metric: 'paired final-answer delta (B-A)', a: '–', b: '–', delta:
|
|
223
|
+
...(paired.scoreDelta === null ? [] : [{
|
|
224
|
+
metric: 'paired final-answer delta (B-A)', a: '–', b: '–', delta: formatPairedDelta(paired.scoreDelta),
|
|
204
225
|
}]),
|
|
205
226
|
)
|
|
206
227
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* dsh-eval
|
|
2
|
+
* dsh-eval — agent evaluation over headless dsh profiles.
|
|
3
3
|
*
|
|
4
4
|
* The eval bundle mounts this command-line plugin over dsh-base. It parses
|
|
5
5
|
* `dsh --profile eval run <benchmark.yaml>` / `report <run.json>`, spawns one
|
|
@@ -99,6 +99,7 @@ export async function executeEval(
|
|
|
99
99
|
const benchmark = await loadBenchmark(values.benchmarkPath)
|
|
100
100
|
const run = await runBenchmark(benchmark, {
|
|
101
101
|
...(values.trials !== undefined ? { trials: values.trials } : {}),
|
|
102
|
+
...(values.concurrency !== undefined ? { concurrency: values.concurrency } : {}),
|
|
102
103
|
...(values.dshCommand !== undefined ? { command: values.dshCommand } : {}),
|
|
103
104
|
...(values.profile !== undefined ? { profile: values.profile } : {}),
|
|
104
105
|
...(services.judgeChat !== undefined ? { judgeChat: services.judgeChat } : {}),
|
package/src/runner.ts
CHANGED
|
@@ -34,6 +34,8 @@ export interface RunOptions {
|
|
|
34
34
|
profile?: string
|
|
35
35
|
/** Override the benchmark's trials per case. */
|
|
36
36
|
trials?: number
|
|
37
|
+
/** Override the benchmark's in-flight trial limit. */
|
|
38
|
+
concurrency?: number
|
|
37
39
|
/** Root for trial directories; defaults to the platform temp dir. */
|
|
38
40
|
tempRoot?: string
|
|
39
41
|
/** LLM-judge chat seam; required when the benchmark configures a judge. */
|
|
@@ -343,7 +345,16 @@ async function runCaseTrial(
|
|
|
343
345
|
}
|
|
344
346
|
|
|
345
347
|
/**
|
|
346
|
-
* Run every case x trial
|
|
348
|
+
* Run every case x trial through a bounded worker pool and aggregate the
|
|
349
|
+
* completed trials.
|
|
350
|
+
*
|
|
351
|
+
* Trials are independent by construction — each owns a private temp directory,
|
|
352
|
+
* workspace copy, and DSH_HOME — so the only thing serial execution buys is
|
|
353
|
+
* determinism. The pool keeps that anyway: results land at their task index, so
|
|
354
|
+
* the run record stays in case-then-trial order no matter how the workers
|
|
355
|
+
* interleave. The first failure to escape `runCaseTrial` stops the remaining
|
|
356
|
+
* workers and rejects the run, which is the same contract as the serial loop.
|
|
357
|
+
*
|
|
347
358
|
* @param benchmark - the loaded benchmark.
|
|
348
359
|
* @param options - runtime overrides and test seams.
|
|
349
360
|
* @returns the completed run record, written by the caller.
|
|
@@ -361,13 +372,29 @@ export async function runBenchmark(benchmark: Benchmark, options: RunOptions = {
|
|
|
361
372
|
...benchmark,
|
|
362
373
|
...(options.profile !== undefined ? { profile: options.profile } : {}),
|
|
363
374
|
...(options.command !== undefined ? { command: options.command } : {}),
|
|
375
|
+
...(options.concurrency !== undefined ? { concurrency: options.concurrency } : {}),
|
|
364
376
|
}
|
|
365
|
-
const
|
|
377
|
+
const tasks: { caseValue: Benchmark['cases'][number]; trial: number }[] = []
|
|
366
378
|
for (const caseValue of effective.cases) {
|
|
367
|
-
for (let trial = 1; trial <= trials; trial++) {
|
|
368
|
-
|
|
379
|
+
for (let trial = 1; trial <= trials; trial++) tasks.push({ caseValue, trial })
|
|
380
|
+
}
|
|
381
|
+
const results: EvalTrialResult[] = Array.from({ length: tasks.length })
|
|
382
|
+
let failure: { error: unknown } | undefined
|
|
383
|
+
let cursor = 0
|
|
384
|
+
const worker = async (): Promise<void> => {
|
|
385
|
+
while (failure === undefined) {
|
|
386
|
+
const index = cursor++
|
|
387
|
+
const task = tasks[index]
|
|
388
|
+
if (task === undefined) return
|
|
389
|
+
try {
|
|
390
|
+
results[index] = await runCaseTrial(effective, task.caseValue, task.trial, root, options.judgeChat)
|
|
391
|
+
} catch (error) {
|
|
392
|
+
failure = { error }
|
|
393
|
+
}
|
|
369
394
|
}
|
|
370
395
|
}
|
|
396
|
+
await Promise.all(Array.from({ length: Math.min(effective.concurrency, tasks.length) }, worker))
|
|
397
|
+
if (failure !== undefined) throw failure.error
|
|
371
398
|
const completed = results.filter(
|
|
372
399
|
(result): result is EvalTrialResult & { metrics: NonNullable<EvalTrialResult['metrics']> } =>
|
|
373
400
|
result.status === 'completed' && result.metrics !== undefined,
|