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
package/src/dashboard.ts
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self-contained HTML dashboard for a persisted eval run.
|
|
3
|
+
*
|
|
4
|
+
* The output has no external assets or scripts, so it can be opened from a CI
|
|
5
|
+
* artifact, a local temp directory, or an offline machine. Every value that
|
|
6
|
+
* came from the benchmark or the agent is HTML-escaped: a benchmark id or an
|
|
7
|
+
* error string is data, never markup.
|
|
8
|
+
*
|
|
9
|
+
* @module dsh-eval/dashboard
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { writeTextAtomic } from './atomic-write.ts'
|
|
13
|
+
import { computeAgreement } from './agreement.ts'
|
|
14
|
+
import { computeCalibration } from './calibration.ts'
|
|
15
|
+
import { compareRuns, formatCaseValue, formatPValue, pairedCases, pairedCaseSignificance } from './compare.ts'
|
|
16
|
+
import { buildLeaderboard, formatLeaderboardSignificance, type LeaderboardMetric } from './leaderboard.ts'
|
|
17
|
+
import type { RateInterval } from './precision.ts'
|
|
18
|
+
import { computePrecision } from './precision.ts'
|
|
19
|
+
import { computeCoverage, computeReliability } from './reliability.ts'
|
|
20
|
+
import type { EvalRun } from './types.ts'
|
|
21
|
+
|
|
22
|
+
/** Shared inline stylesheet; the page has no external assets. */
|
|
23
|
+
const STYLE = `
|
|
24
|
+
:root{color-scheme:light dark;--bg:#f6f7f9;--fg:#1d2430;--muted:#667085;--line:#e3e7ed;--card:#fff;--accent:#2563eb;--bad:#b42318;--good:#067647}
|
|
25
|
+
@media(prefers-color-scheme:dark){:root{--bg:#11151c;--fg:#e6eaf0;--muted:#98a2b3;--line:#2b3442;--card:#1a202a;--accent:#7aa2ff;--bad:#f97066;--good:#6ce9a6}}
|
|
26
|
+
*{box-sizing:border-box}body{margin:0;background:var(--bg);color:var(--fg);font:14px/1.5 ui-sans-serif,system-ui,-apple-system,"Segoe UI",sans-serif}
|
|
27
|
+
main{max-width:1100px;margin:0 auto;padding:32px 20px 64px}h1{font-size:26px;margin:0 0 4px}h2{font-size:17px;margin:32px 0 12px}
|
|
28
|
+
.sub{color:var(--muted);margin:0 0 24px}.cards{display:grid;grid-template-columns:repeat(auto-fit,minmax(170px,1fr));gap:12px}
|
|
29
|
+
.card{background:var(--card);border:1px solid var(--line);border-radius:12px;padding:16px;display:flex;flex-direction:column;gap:4px}
|
|
30
|
+
.card .label{color:var(--muted);font-size:12px;text-transform:uppercase;letter-spacing:.05em}.card strong{font-size:24px;font-variant-numeric:tabular-nums}
|
|
31
|
+
.note,.muted{color:var(--muted);font-size:12px}table{width:100%;border-collapse:collapse;background:var(--card);border:1px solid var(--line);border-radius:12px;overflow:hidden}
|
|
32
|
+
th,td{padding:9px 12px;text-align:left;border-bottom:1px solid var(--line);font-variant-numeric:tabular-nums}th{color:var(--muted);font-size:12px;text-transform:uppercase;letter-spacing:.04em}
|
|
33
|
+
tr:last-child td{border-bottom:0}code{font-family:ui-monospace,SFMono-Regular,Consolas,monospace}.pill{border-radius:999px;padding:2px 8px;font-size:12px}
|
|
34
|
+
.pill.completed{background:rgba(6,118,71,.12);color:var(--good)}.pill.error{background:rgba(180,35,24,.12);color:var(--bad)}
|
|
35
|
+
.detail{max-width:280px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--muted)}
|
|
36
|
+
.table-wrapper{overflow:auto;max-inline-size:100%;max-block-size:min(500px,80vh);container-type:inline-size;border-radius:12px}
|
|
37
|
+
.table-wrapper table{border-radius:0}.table-wrapper thead{position:sticky;inset-block-start:0;z-index:1;background:var(--card)}
|
|
38
|
+
footer{margin-top:32px;color:var(--muted);font-size:12px}
|
|
39
|
+
`
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Write the dashboard as a standalone HTML file, creating parent directories.
|
|
43
|
+
* @param runs - one run, two for a comparison table, or three+ for a leaderboard.
|
|
44
|
+
* @param path - output path.
|
|
45
|
+
*/
|
|
46
|
+
export async function writeDashboard(
|
|
47
|
+
runs: readonly EvalRun[],
|
|
48
|
+
path: string,
|
|
49
|
+
metric: LeaderboardMetric = 'taskSuccess',
|
|
50
|
+
): Promise<void> {
|
|
51
|
+
await writeTextAtomic(path, renderDashboard(runs, metric))
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Escape text for interpolation into HTML. */
|
|
55
|
+
function esc(value: string): string {
|
|
56
|
+
return value.replace(/[&<>"']/gu, (char) => ({
|
|
57
|
+
'&': '&', '<': '<', '>': '>', '"': '"', "'": ''',
|
|
58
|
+
})[char]!)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Format a rate, or a dash when the metric is ungraded. */
|
|
62
|
+
function rate(value: number | null): string {
|
|
63
|
+
return value === null ? '–' : `${(value * 100).toFixed(1)}%`
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Format a USD price, or a dash when pricing was not configured. */
|
|
67
|
+
function cost(value: number | null): string {
|
|
68
|
+
return value === null ? '–' : `$${value.toFixed(6)}`
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Render a metric as a summary card. */
|
|
72
|
+
function card(label: string, value: string, note: string): string {
|
|
73
|
+
return `<div class="card"><span class="label">${esc(label)}</span><strong>${esc(value)}</strong><span class="note">${esc(note)}</span></div>`
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Render a confidence interval cell. */
|
|
77
|
+
function interval(value: RateInterval): string {
|
|
78
|
+
const range = value.lower === null || value.upper === null
|
|
79
|
+
? ''
|
|
80
|
+
: ` <span class="note">[${rate(value.lower)}, ${rate(value.upper)}]</span>`
|
|
81
|
+
return `${rate(value.rate)}${range} <span class="note">n=${value.trials}</span>`
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Render a table from a header and already-escaped row fragments. */
|
|
85
|
+
function table(headers: readonly string[], rows: readonly string[], label = 'Evaluation data'): string {
|
|
86
|
+
return [
|
|
87
|
+
`<div class="table-wrapper" role="region" tabindex="0" aria-label="${esc(label)}">`,
|
|
88
|
+
'<table><thead><tr>',
|
|
89
|
+
...headers.map(header => `<th scope="col">${esc(header)}</th>`),
|
|
90
|
+
'</tr></thead><tbody>',
|
|
91
|
+
...rows.map(row => `<tr>${row}</tr>`),
|
|
92
|
+
'</tbody></table></div>',
|
|
93
|
+
].join('')
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Render the two-run comparison table from the same rows the markdown report uses. */
|
|
97
|
+
function renderComparison(a: EvalRun, b: EvalRun): string {
|
|
98
|
+
const compared = compareRuns(a, b)
|
|
99
|
+
const rows = compared.filter(row => row.inference === undefined)
|
|
100
|
+
.map(row => [row.metric, row.a, row.b, row.delta]
|
|
101
|
+
.map(value => `<td>${esc(value)}</td>`).join(''))
|
|
102
|
+
const inferenceRows = compared.filter(row => row.inference !== undefined)
|
|
103
|
+
.map(row => `<td>${esc(row.metric)}</td><td>${esc(row.inference!)}</td>`)
|
|
104
|
+
const cases = pairedCases(a, b) ?? []
|
|
105
|
+
const discordant = cases.filter(item => item.outcome !== 'tie').slice(0, 10)
|
|
106
|
+
const caseRows = discordant.map(item => [item.caseId, String(item.trial),
|
|
107
|
+
formatCaseValue(item.a), formatCaseValue(item.b), item.outcome]
|
|
108
|
+
.map(value => `<td>${esc(value)}</td>`).join(''))
|
|
109
|
+
const caseBlock = discordant.length === 0 ? '' : `<h2>Changed cases</h2>${table(
|
|
110
|
+
['Case', 'Trial', 'A', 'B', 'Result'], caseRows, 'Changed cases',
|
|
111
|
+
)}`
|
|
112
|
+
const significance = pairedCaseSignificance(a, b) ?? []
|
|
113
|
+
const confirmed = significance.filter(row =>
|
|
114
|
+
row.verdict === 'significantly-better' || row.verdict === 'significantly-worse')
|
|
115
|
+
const shown = confirmed.slice(0, 10)
|
|
116
|
+
const significanceRows = shown.map(row => [row.caseId, String(row.pairs),
|
|
117
|
+
String(row.wins), String(row.losses), formatPValue(row.adjustedP), row.verdict]
|
|
118
|
+
.map(value => `<td>${esc(value)}</td>`).join(''))
|
|
119
|
+
const truncation = shown.length < confirmed.length
|
|
120
|
+
? `<p class="sub">showing ${shown.length} of ${confirmed.length} confirmed changes</p>` : ''
|
|
121
|
+
const underpowered = significance.filter(row => row.verdict === 'underpowered')
|
|
122
|
+
const powerNote = underpowered.length === 0 ? ''
|
|
123
|
+
: `<p class="sub">${underpowered.length} underpowered cases need at least ${Math.max(...underpowered.map(row => row.requiredPairs))} discordant pairs for this family</p>`
|
|
124
|
+
const significanceBlock = confirmed.length === 0 ? '' : `<h2>Confirmed case changes</h2>`
|
|
125
|
+
+ `<p class="sub">${significance.length} cases · Bonferroni family = ${significance.length} · ${confirmed.length} confirmed</p>`
|
|
126
|
+
+ truncation
|
|
127
|
+
+ table(['Case', 'Pairs', 'B wins', 'A wins', 'Adjusted p', 'Result'], significanceRows,
|
|
128
|
+
'Confirmed case changes')
|
|
129
|
+
return `<h2>Run comparison</h2>${table(['Metric', 'A', 'B', 'B − A'], rows, 'Run comparison')}`
|
|
130
|
+
+ (inferenceRows.length === 0 ? '' : `<h2>Paired inference</h2>${table(['Test', 'Result'], inferenceRows, 'Paired inference')}`)
|
|
131
|
+
+ caseBlock + significanceBlock + powerNote
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Render a standalone overview page for three or more runs. */
|
|
135
|
+
function renderLeaderboardDashboard(runs: readonly EvalRun[], metric: LeaderboardMetric): string {
|
|
136
|
+
const entries = buildLeaderboard(runs.map(run => ({
|
|
137
|
+
label: `${run.benchmark} — ${run.model}`,
|
|
138
|
+
run,
|
|
139
|
+
})), metric)
|
|
140
|
+
const rows = entries.map(entry => [
|
|
141
|
+
String(entry.rank), entry.label, `${entry.completed}/${entry.total}`,
|
|
142
|
+
rate(entry.taskSuccess), rate(entry.strictPassAt1), rate(entry.toolSelection),
|
|
143
|
+
rate(entry.judgeScore), cost(entry.costUsd),
|
|
144
|
+
entry.latencyMs === null ? '–' : `${entry.latencyMs.toFixed(1)} ms`,
|
|
145
|
+
entry.rank === 1 ? 'leader' : entry.gapFromBest === null ? '–' : `-${(entry.gapFromBest * 100).toFixed(1)}pp`,
|
|
146
|
+
formatLeaderboardSignificance(entry.significance),
|
|
147
|
+
].map(value => `<td>${esc(value)}</td>`).join(''))
|
|
148
|
+
return `<!doctype html>
|
|
149
|
+
<html lang="en">
|
|
150
|
+
<head>
|
|
151
|
+
<meta charset="utf-8">
|
|
152
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
153
|
+
<title>dsh-eval leaderboard</title>
|
|
154
|
+
<style>${STYLE}</style>
|
|
155
|
+
</head>
|
|
156
|
+
<body><main>
|
|
157
|
+
<h1>Leaderboard</h1>
|
|
158
|
+
<p class="sub">${entries.length} runs · ranked by ${metric === 'strictPassAt1' ? 'strict pass@1' : 'pooled task success'} · vs leader is a Bonferroni-corrected paired sign-test verdict</p>
|
|
159
|
+
${table(['Rank', 'Run', 'Completed', 'Task', 'Strict pass@1', 'Tool', 'Judge', 'Cost/trial', 'Latency/trial', 'Δ best', 'vs leader'], rows, 'Leaderboard')}
|
|
160
|
+
<footer>Generated by dsh-eval · self-contained page, no external assets</footer>
|
|
161
|
+
</main></body>
|
|
162
|
+
</html>
|
|
163
|
+
`
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Render a standalone HTML dashboard for one, two, or three+ runs.
|
|
168
|
+
* @param runs - one run, two for a comparison table, or three+ for a leaderboard.
|
|
169
|
+
* @returns a complete HTML document.
|
|
170
|
+
*/
|
|
171
|
+
export function renderDashboard(runs: readonly EvalRun[], metric: LeaderboardMetric = 'taskSuccess'): string {
|
|
172
|
+
if (runs.length > 2) return renderLeaderboardDashboard(runs, metric)
|
|
173
|
+
const run = runs[0]!
|
|
174
|
+
const coverage = computeCoverage(run)
|
|
175
|
+
const task = computeReliability(run, 'task')
|
|
176
|
+
const tool = computeReliability(run, 'tool-selection')
|
|
177
|
+
const precision = computePrecision(run)
|
|
178
|
+
const agreement = computeAgreement(run)
|
|
179
|
+
const calibration = computeCalibration(run)
|
|
180
|
+
const aggregate = run.aggregate
|
|
181
|
+
const judge = run.judge
|
|
182
|
+
const cards = [
|
|
183
|
+
card('Completed', `${coverage.completed}/${coverage.total}`, coverage.unscored === 0
|
|
184
|
+
? 'all trials graded'
|
|
185
|
+
: `${coverage.unscored} unscored · ${coverage.timeouts} timeouts · ${coverage.errors} errors`),
|
|
186
|
+
...(task === null ? [] : [
|
|
187
|
+
card('pass@1', rate(task.passAt1), `strict ${rate(task.strictPassAt1)}`),
|
|
188
|
+
card('pass@k', rate(task.passAtK), `${run.cases.filter(result => typeof result.grade?.taskSuccess === 'boolean').length} graded · ${task.cases} cases`),
|
|
189
|
+
]),
|
|
190
|
+
...(precision.latencyP95 === null ? [] : [
|
|
191
|
+
// computePrecision produces p50 and p95 together.
|
|
192
|
+
card('Latency p95', `${precision.latencyP95.toFixed(0)} ms`, `p50 ${precision.latencyP50!.toFixed(0)} ms`),
|
|
193
|
+
]),
|
|
194
|
+
card('Cost', cost(aggregate?.costUsd ?? null), aggregate === null ? 'no metrics' : 'total billed USD'),
|
|
195
|
+
].join('')
|
|
196
|
+
|
|
197
|
+
const reliabilityRows = [task, tool]
|
|
198
|
+
.filter((summary): summary is NonNullable<typeof summary> => summary !== null)
|
|
199
|
+
.map(summary => [
|
|
200
|
+
`<td>${esc(summary.dimension)}</td>`,
|
|
201
|
+
`<td>${rate(summary.passAt1)}</td>`,
|
|
202
|
+
`<td>${rate(summary.strictPassAt1)}</td>`,
|
|
203
|
+
`<td>${rate(summary.passAtK)}</td>`,
|
|
204
|
+
`<td>${rate(summary.passAllK)}</td>`,
|
|
205
|
+
`<td>${summary.flaky.length}</td>`,
|
|
206
|
+
`<td>${summary.unscored}</td>`,
|
|
207
|
+
].join(''))
|
|
208
|
+
const flaky = task === null || task.flaky.length === 0
|
|
209
|
+
? ''
|
|
210
|
+
: `<p class="muted">Flaky cases: ${task.flaky.map(item => `<code>${esc(item.caseId)}</code> ${item.passes}/${item.total}`).join(' · ')}</p>`
|
|
211
|
+
const hardest = task === null || task.hardest.length === 0
|
|
212
|
+
? ''
|
|
213
|
+
: `<p class="muted">Hardest cases: ${task.hardest.map(item => `<code>${esc(item.caseId)}</code> ${rate(item.rate)}`).join(' · ')}</p>`
|
|
214
|
+
|
|
215
|
+
const precisionRows = [
|
|
216
|
+
...(precision.task === null ? [] : [`<td>task success</td><td>${interval(precision.task)}</td>`]),
|
|
217
|
+
...(precision.strictPassAt1 === null ? [] :
|
|
218
|
+
[`<td>strict pass@1 (all trials)</td><td>${interval(precision.strictPassAt1)}</td>`]),
|
|
219
|
+
...(precision.toolSelection === null ? [] : [`<td>tool selection</td><td>${interval(precision.toolSelection)}</td>`]),
|
|
220
|
+
]
|
|
221
|
+
const precisionBlock = precisionRows.length === 0 && precision.latencyP50 === null
|
|
222
|
+
? ''
|
|
223
|
+
: `<h2>Precision</h2>${table(['Metric', 'Bootstrap interval'], precisionRows, 'Precision intervals')}`
|
|
224
|
+
|
|
225
|
+
const agreementBlock = agreement === null ? '' : `
|
|
226
|
+
<h2>Judge / script agreement</h2>
|
|
227
|
+
${table(['Pairs', 'Observed', "Cohen's kappa", 'Judge pass', 'Script pass'], [
|
|
228
|
+
[agreement.pairs, rate(agreement.rate), agreement.kappa.toFixed(2),
|
|
229
|
+
rate(agreement.judgePassed / agreement.pairs), rate(agreement.scriptPassed / agreement.pairs)]
|
|
230
|
+
.map(value => `<td>${esc(String(value))}</td>`).join(''),
|
|
231
|
+
], 'Judge / script agreement')}`
|
|
232
|
+
|
|
233
|
+
const calibrationBlock = calibration === null ? '' : `
|
|
234
|
+
<h2>Judge calibration</h2>
|
|
235
|
+
${table(['Passed mean', 'Failed mean', 'Separation', 'Ranking accuracy', 'Brier'], [[
|
|
236
|
+
rate(calibration.passedMean), rate(calibration.failedMean),
|
|
237
|
+
calibration.separation === null ? '–' : `${calibration.separation >= 0 ? '+' : ''}${(calibration.separation * 100).toFixed(1)}pp`,
|
|
238
|
+
rate(calibration.rankingAccuracy),
|
|
239
|
+
calibration.brier === null ? '–' : calibration.brier.toFixed(3),
|
|
240
|
+
].map(value => `<td>${esc(value)}</td>`).join('')], 'Judge calibration')}
|
|
241
|
+
${calibration.disagreements.length === 0 ? '' : `<p class="note">Review: ${calibration.disagreements
|
|
242
|
+
.map(item => `${esc(item.caseId)} #${item.trial} (script ${item.scriptPassed ? 'pass' : 'fail'}, score ${item.score ?? 'n/a'})`)
|
|
243
|
+
.join(' · ')}</p>`}`
|
|
244
|
+
|
|
245
|
+
const trialRows = run.cases.map(result => [
|
|
246
|
+
`<td><code>${esc(result.caseId)}</code></td>`,
|
|
247
|
+
`<td>${result.trial}</td>`,
|
|
248
|
+
`<td><span class="pill ${esc(result.status)}">${esc(result.status)}</span></td>`,
|
|
249
|
+
`<td>${result.metrics?.steps ?? '–'}</td>`,
|
|
250
|
+
`<td>${result.metrics?.totalTokens ?? '–'}</td>`,
|
|
251
|
+
`<td>${result.metrics?.latencyMs.toFixed(0) ?? '–'}</td>`,
|
|
252
|
+
`<td>${rate(result.grade?.taskSuccess === null || result.grade === undefined
|
|
253
|
+
? null : result.grade.taskSuccess ? 1 : 0)}</td>`,
|
|
254
|
+
`<td>${rate(result.grade?.toolSelectionAccuracy === null || result.grade === undefined
|
|
255
|
+
? null : result.grade.toolSelectionAccuracy ? 1 : 0)}</td>`,
|
|
256
|
+
`<td>${result.judge?.finalAnswerScore === null || result.judge === undefined
|
|
257
|
+
? '–' : result.judge.finalAnswerScore.toFixed(1)}</td>`,
|
|
258
|
+
`<td class="detail">${esc(result.error ?? result.judge?.judgeError ?? '')}</td>`,
|
|
259
|
+
].join(''))
|
|
260
|
+
|
|
261
|
+
return `<!doctype html>
|
|
262
|
+
<html lang="en">
|
|
263
|
+
<head>
|
|
264
|
+
<meta charset="utf-8">
|
|
265
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
266
|
+
<title>${esc(runs.map(item => `${item.benchmark} — ${item.model}`).join(' vs '))}</title>
|
|
267
|
+
<style>
|
|
268
|
+
${STYLE}</style>
|
|
269
|
+
</head>
|
|
270
|
+
<body><main>
|
|
271
|
+
<h1>${esc(run.benchmark)}</h1>
|
|
272
|
+
<p class="sub">${esc(run.model)} · ${new Date(run.createdAt).toISOString()} · ${judge === undefined ? 'no judge' : `judge ${esc(judge.model)}`}${run.benchmarkSha256 === undefined ? '' : ` · source ${esc(run.benchmarkSha256.slice(0, 12))}`}</p>
|
|
273
|
+
${runs.length === 2 ? renderComparison(runs[0]!, runs[1]!) : ''}
|
|
274
|
+
<section class="cards">${cards}</section>
|
|
275
|
+
<h2>Reliability</h2>
|
|
276
|
+
${table(['Dimension', 'pass@1', 'strict', 'pass@k', 'pass^k', 'Flaky', 'Unscored'], reliabilityRows, 'Reliability')}
|
|
277
|
+
${flaky}${hardest}
|
|
278
|
+
${precisionBlock}
|
|
279
|
+
${agreementBlock}
|
|
280
|
+
${calibrationBlock}
|
|
281
|
+
<h2>Trials</h2>
|
|
282
|
+
${table(['Case', 'Trial', 'Status', 'Steps', 'Tokens', 'Latency', 'Task', 'Tool', 'Score', 'Detail'], trialRows, 'Trials')}
|
|
283
|
+
<footer>Generated by dsh-eval · run seed ${run.seed}</footer>
|
|
284
|
+
</main></body>
|
|
285
|
+
</html>
|
|
286
|
+
`
|
|
287
|
+
}
|
package/src/digest.ts
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic content hashing for benchmark provenance.
|
|
3
|
+
*
|
|
4
|
+
* A YAML digest alone misses prompt files, workspace fixtures and replay logs,
|
|
5
|
+
* so the stored benchmark fingerprint folds every resolved input into one
|
|
6
|
+
* SHA-256. Directory entries use code-point ordering (never locale ordering)
|
|
7
|
+
* so the digest is identical on every machine, and symlinks are followed to
|
|
8
|
+
* their real content so an in-directory link cannot hide a changed fixture.
|
|
9
|
+
*
|
|
10
|
+
* @module dsh-eval/digest
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { createHash, type Hash } from 'node:crypto'
|
|
14
|
+
import { realpath, readFile, readdir, stat } from 'node:fs/promises'
|
|
15
|
+
import { join, relative, resolve } from 'node:path'
|
|
16
|
+
import type { Benchmark } from './types.ts'
|
|
17
|
+
|
|
18
|
+
/** Code-point ordering: `localeCompare` varies with the host's ICU locale. */
|
|
19
|
+
function byCodePoint(a: string, b: string): number {
|
|
20
|
+
/* v8 ignore next -- readdir order decides which comparison branch runs. */
|
|
21
|
+
return a < b ? -1 : a > b ? 1 : 0
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Hash a labelled fragment with unambiguous delimiters. */
|
|
25
|
+
function fragment(hash: Hash, label: string, value: string): void {
|
|
26
|
+
hash.update(`${label}\0${value}\0`)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Hash a file or directory tree, following symlinks without revisiting targets. */
|
|
30
|
+
async function hashPath(
|
|
31
|
+
hash: Hash,
|
|
32
|
+
path: string,
|
|
33
|
+
root: string,
|
|
34
|
+
label: string,
|
|
35
|
+
seen: ReadonlySet<string>,
|
|
36
|
+
excluded: ReadonlySet<string>,
|
|
37
|
+
): Promise<void> {
|
|
38
|
+
const absolute = resolve(path)
|
|
39
|
+
let real: string
|
|
40
|
+
try {
|
|
41
|
+
real = await realpath(absolute)
|
|
42
|
+
} catch {
|
|
43
|
+
real = absolute
|
|
44
|
+
}
|
|
45
|
+
if (excluded.has(absolute) || excluded.has(real)) return
|
|
46
|
+
if (seen.has(real)) return
|
|
47
|
+
const visited = new Set(seen)
|
|
48
|
+
visited.add(real)
|
|
49
|
+
let info
|
|
50
|
+
try {
|
|
51
|
+
info = await stat(real)
|
|
52
|
+
} catch (error) {
|
|
53
|
+
/* v8 ignore next -- non-ENOENT stat failures propagate to the caller. */
|
|
54
|
+
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error
|
|
55
|
+
fragment(hash, `${label}-missing`, relative(root, absolute))
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
if (info.isFile()) {
|
|
59
|
+
fragment(hash, label, relative(root, absolute))
|
|
60
|
+
hash.update(await readFile(real))
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
/* v8 ignore next -- sockets/FIFOs are not valid benchmark inputs. */
|
|
64
|
+
if (!info.isDirectory()) return
|
|
65
|
+
const entries = (await readdir(real, { withFileTypes: true }))
|
|
66
|
+
.sort((a, b) => byCodePoint(a.name, b.name))
|
|
67
|
+
for (const entry of entries) {
|
|
68
|
+
await hashPath(hash, join(real, entry.name), root, label, visited, excluded)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** CLI overrides that change the effective benchmark configuration. */
|
|
73
|
+
export interface BenchmarkOverrides {
|
|
74
|
+
trials?: number
|
|
75
|
+
concurrency?: number
|
|
76
|
+
seed?: number
|
|
77
|
+
profile?: string
|
|
78
|
+
dshCommand?: readonly string[]
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Fold CLI overrides into a benchmark digest so provenance cannot report a
|
|
83
|
+
* match for a run whose effective configuration differed from the YAML.
|
|
84
|
+
*/
|
|
85
|
+
export function hashBenchmarkOverrides(baseSha256: string, overrides: BenchmarkOverrides): string {
|
|
86
|
+
const hash = createHash('sha256')
|
|
87
|
+
fragment(hash, 'benchmark-sha256', baseSha256)
|
|
88
|
+
fragment(hash, 'trials', overrides.trials === undefined ? '' : String(overrides.trials))
|
|
89
|
+
fragment(hash, 'concurrency', overrides.concurrency === undefined ? '' : String(overrides.concurrency))
|
|
90
|
+
fragment(hash, 'profile', overrides.profile ?? '')
|
|
91
|
+
fragment(hash, 'dshCommand', (overrides.dshCommand ?? []).join('\u0000'))
|
|
92
|
+
// Version only the seed case: reports written before this override existed
|
|
93
|
+
// must still verify against their original digest.
|
|
94
|
+
if (overrides.seed !== undefined) {
|
|
95
|
+
fragment(hash, 'digest-version', '2')
|
|
96
|
+
fragment(hash, 'seed', String(overrides.seed))
|
|
97
|
+
}
|
|
98
|
+
return hash.digest('hex')
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Options that affect only the digest, not the benchmark itself. */
|
|
102
|
+
export interface BenchmarkDigestOptions {
|
|
103
|
+
/** Absolute paths to omit, e.g. the run report written into a `workspace: .` tree. */
|
|
104
|
+
excludePaths?: readonly string[]
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Hash the benchmark YAML plus every resolved input it reads at run time.
|
|
109
|
+
* @param text - raw benchmark YAML source.
|
|
110
|
+
* @param benchmark - the parsed benchmark with resolved paths.
|
|
111
|
+
* @param options - digest-only exclusions for output artifacts.
|
|
112
|
+
* @returns a stable 64-character hex digest.
|
|
113
|
+
*/
|
|
114
|
+
export async function hashBenchmarkInputs(
|
|
115
|
+
text: string,
|
|
116
|
+
benchmark: Benchmark,
|
|
117
|
+
options: BenchmarkDigestOptions = {},
|
|
118
|
+
): Promise<string> {
|
|
119
|
+
const hash = createHash('sha256')
|
|
120
|
+
const excluded = new Set<string>()
|
|
121
|
+
for (const path of options.excludePaths ?? []) {
|
|
122
|
+
const absolute = resolve(path)
|
|
123
|
+
excluded.add(absolute)
|
|
124
|
+
// Windows temp paths can differ by short-name casing; canonicalize too.
|
|
125
|
+
try {
|
|
126
|
+
excluded.add(await realpath(absolute))
|
|
127
|
+
} catch {
|
|
128
|
+
/* Output paths often do not exist yet; the raw absolute form still applies. */
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const seen = new Set<string>()
|
|
132
|
+
fragment(hash, 'yaml', text)
|
|
133
|
+
for (const caseValue of benchmark.cases) {
|
|
134
|
+
fragment(hash, 'case', caseValue.id)
|
|
135
|
+
fragment(hash, 'prompt', caseValue.prompt)
|
|
136
|
+
if (caseValue.workspace !== undefined) {
|
|
137
|
+
await hashPath(hash, caseValue.workspace, caseValue.workspace, 'workspace', seen, excluded)
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (benchmark.replay !== undefined) {
|
|
141
|
+
await hashPath(hash, benchmark.replay.dir, benchmark.replay.dir, 'replay', seen, excluded)
|
|
142
|
+
}
|
|
143
|
+
return hash.digest('hex')
|
|
144
|
+
}
|
package/src/export.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Flat trial-level CSV export for dsh-eval runs.
|
|
3
|
+
*
|
|
4
|
+
* Reports are the source of truth for aggregate analysis, but spreadsheet and
|
|
5
|
+
* notebook workflows usually want one row per trial. This module derives that
|
|
6
|
+
* view without changing the persisted JSON, and escapes every agent-controlled
|
|
7
|
+
* string so a case id or error message cannot inject a spreadsheet formula.
|
|
8
|
+
*
|
|
9
|
+
* @module dsh-eval/export
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { EvalRun, EvalTrialResult } from './types.ts'
|
|
13
|
+
|
|
14
|
+
/** Column order of the exported CSV. */
|
|
15
|
+
const COLUMNS = [
|
|
16
|
+
'caseId', 'trial', 'status', 'exitCode', 'timedOut', 'error',
|
|
17
|
+
'taskSuccess', 'toolSelectionAccuracy', 'judgeScore', 'hallucination',
|
|
18
|
+
'judgeError', 'steps', 'toolCalls', 'toolSuccess', 'invalidToolCalls', 'retries',
|
|
19
|
+
'inputTokens', 'outputTokens', 'totalTokens', 'costUsd', 'latencyMs',
|
|
20
|
+
'llmMs', 'toolMs', 'ttftMs', 'traceSha256',
|
|
21
|
+
] as const
|
|
22
|
+
|
|
23
|
+
type CellValue = string | number | boolean | null | undefined
|
|
24
|
+
|
|
25
|
+
/** Render one CSV cell, guarding string cells against spreadsheet formulas. */
|
|
26
|
+
function cell(value: CellValue): string {
|
|
27
|
+
if (value === null || value === undefined) return ''
|
|
28
|
+
if (typeof value !== 'string') return String(value)
|
|
29
|
+
const safe = /^[=+\-@\t\r\n ]/u.test(value) ? `'${value}` : value
|
|
30
|
+
return /[",\r\n]/u.test(safe) ? `"${safe.replace(/"/gu, '""')}"` : safe
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Convert one trial into a flat row aligned with {@link COLUMNS}. */
|
|
34
|
+
function row(result: EvalTrialResult): CellValue[] {
|
|
35
|
+
const metrics = result.metrics
|
|
36
|
+
return [
|
|
37
|
+
result.caseId, result.trial, result.status, result.exitCode, result.timedOut,
|
|
38
|
+
result.error, result.grade?.taskSuccess, result.grade?.toolSelectionAccuracy,
|
|
39
|
+
result.judge?.finalAnswerScore ?? null, result.judge?.hallucination ?? null,
|
|
40
|
+
result.judge?.judgeError, metrics?.steps, metrics?.toolCalls, metrics?.toolSuccess,
|
|
41
|
+
metrics?.invalidToolCalls, metrics?.retries, metrics?.tokens.inputTokens,
|
|
42
|
+
metrics?.tokens.outputTokens, metrics?.totalTokens, metrics?.costUsd,
|
|
43
|
+
metrics?.latencyMs, metrics?.llmMs, metrics?.toolMs, metrics?.ttftMs,
|
|
44
|
+
result.traceSha256,
|
|
45
|
+
]
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Render a persisted run as trial-level CSV.
|
|
50
|
+
* @param run - a validated run report.
|
|
51
|
+
* @returns CSV text ending in a newline, with a header row even for empty runs.
|
|
52
|
+
*/
|
|
53
|
+
export function renderTrialsCsv(run: EvalRun): string {
|
|
54
|
+
const lines = [COLUMNS.join(','), ...run.cases.map(result =>
|
|
55
|
+
row(result).map(cell).join(','))]
|
|
56
|
+
return `${lines.join('\r\n')}\r\n`
|
|
57
|
+
}
|