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.
Files changed (79) hide show
  1. package/README.md +214 -13
  2. package/README.zh.md +99 -10
  3. package/lib/agreement.js +46 -0
  4. package/lib/argv.js +66 -0
  5. package/lib/atomic-write.js +38 -0
  6. package/lib/benchmark.js +116 -19
  7. package/lib/calibration.js +90 -0
  8. package/lib/command.js +202 -10
  9. package/lib/compare.js +310 -31
  10. package/lib/dashboard.js +260 -0
  11. package/lib/digest.js +118 -0
  12. package/lib/export.js +50 -0
  13. package/lib/gate.js +293 -0
  14. package/lib/import.js +17 -6
  15. package/lib/index.js +174 -12
  16. package/lib/judge.js +30 -7
  17. package/lib/leaderboard.js +222 -0
  18. package/lib/precision.js +50 -0
  19. package/lib/rejudge.js +107 -0
  20. package/lib/reliability.js +107 -0
  21. package/lib/report.js +285 -11
  22. package/lib/runner.js +189 -33
  23. package/lib/safe-regex.js +74 -0
  24. package/lib/segments.js +15 -0
  25. package/lib/stats.js +63 -0
  26. package/lib/trace.js +19 -2
  27. package/lib/types/agreement.d.ts +33 -0
  28. package/lib/types/argv.d.ts +19 -0
  29. package/lib/types/atomic-write.d.ts +15 -0
  30. package/lib/types/benchmark.d.ts +9 -2
  31. package/lib/types/calibration.d.ts +45 -0
  32. package/lib/types/command.d.ts +58 -0
  33. package/lib/types/compare.d.ts +82 -2
  34. package/lib/types/dashboard.d.ts +24 -0
  35. package/lib/types/digest.d.ts +38 -0
  36. package/lib/types/export.d.ts +17 -0
  37. package/lib/types/gate.d.ts +87 -0
  38. package/lib/types/index.d.ts +8 -4
  39. package/lib/types/judge.d.ts +4 -1
  40. package/lib/types/leaderboard.d.ts +70 -0
  41. package/lib/types/precision.d.ts +44 -0
  42. package/lib/types/rejudge.d.ts +22 -0
  43. package/lib/types/reliability.d.ts +85 -0
  44. package/lib/types/report.d.ts +18 -5
  45. package/lib/types/runner.d.ts +8 -1
  46. package/lib/types/safe-regex.d.ts +24 -0
  47. package/lib/types/segments.d.ts +12 -0
  48. package/lib/types/stats.d.ts +56 -0
  49. package/lib/types/trace.d.ts +7 -0
  50. package/lib/types/types.d.ts +55 -6
  51. package/lib/types/validate.d.ts +57 -0
  52. package/lib/validate.js +155 -0
  53. package/package.json +2 -2
  54. package/src/agreement.ts +60 -0
  55. package/src/argv.ts +63 -0
  56. package/src/atomic-write.ts +38 -0
  57. package/src/benchmark.ts +139 -13
  58. package/src/calibration.ts +113 -0
  59. package/src/command.ts +297 -10
  60. package/src/compare.ts +392 -37
  61. package/src/dashboard.ts +287 -0
  62. package/src/digest.ts +144 -0
  63. package/src/export.ts +57 -0
  64. package/src/gate.ts +383 -0
  65. package/src/import.ts +18 -6
  66. package/src/index.ts +192 -12
  67. package/src/judge.ts +30 -6
  68. package/src/leaderboard.ts +272 -0
  69. package/src/precision.ts +85 -0
  70. package/src/rejudge.ts +112 -0
  71. package/src/reliability.ts +166 -0
  72. package/src/report.ts +303 -11
  73. package/src/runner.ts +182 -35
  74. package/src/safe-regex.ts +79 -0
  75. package/src/segments.ts +16 -0
  76. package/src/stats.ts +104 -0
  77. package/src/trace.ts +19 -2
  78. package/src/types.ts +56 -6
  79. package/src/validate.ts +177 -0
package/src/types.ts CHANGED
@@ -28,16 +28,34 @@ export interface BenchmarkCase {
28
28
  prompt: string
29
29
  /** Absolute path to a workspace tree copied into each trial, when provided. */
30
30
  workspace?: string
31
+ /** Per-case timeout in milliseconds; overrides the benchmark timeout. */
32
+ timeoutMs?: number
31
33
  /** Scripted grading annotations, when the case is graded. */
32
34
  expected?: BenchmarkExpectation
33
35
  }
34
36
 
35
37
  /** Expected-tool and check-command annotations for scripted grading. */
36
38
  export interface BenchmarkExpectation {
37
- /** Substring matched against every recorded tool call name. */
39
+ /** Legacy substring matched against every recorded tool call name. */
38
40
  tool?: string
39
- /** Command run in the trial workspace after the agent exits; exit 0 means task success. */
41
+ /** Every listed substring must appear in at least one tool call name. */
42
+ tools?: readonly string[]
43
+ /** At least one listed substring must appear in a tool call name. */
44
+ toolAnyOf?: readonly string[]
45
+ /** A validated regular expression that must match at least one tool call name. */
46
+ toolRegex?: string
47
+ /** None of the listed substrings may appear in any tool call name. */
48
+ toolNot?: readonly string[]
49
+ /** Legacy command string split on whitespace (and quotes) into argv; exit 0 means task success. */
40
50
  check?: string
51
+ /** Preferred structured argv for a check command; no shell interpretation. */
52
+ checkArgv?: readonly string[]
53
+ /** Opt-in shell command for checks needing pipes/redirection; benchmark files must be trusted. */
54
+ checkShell?: string
55
+ /** Known-correct final answer handed to the LLM judge, when the task has one. */
56
+ answer?: string
57
+ /** Regex the final assistant answer must match; sets task success when no check command is configured. */
58
+ answerRegex?: string
41
59
  }
42
60
 
43
61
  /** LLM-judge configuration: scores final answers and flags hallucinations. */
@@ -78,8 +96,12 @@ export interface Benchmark {
78
96
  concurrency: number
79
97
  /** Per-trial timeout in milliseconds. */
80
98
  timeoutMs: number
81
- /** Reserved deterministic seed for future paired comparisons. */
99
+ /** Deterministic seed; trial n receives `DSH_EVAL_SEED = seed + n - 1`. */
82
100
  seed: number
101
+ /** SHA-256 of the YAML source plus resolved prompt/workspace/replay inputs. */
102
+ sourceSha256?: string
103
+ /** Permit referenced paths outside the benchmark directory; trusted files only. */
104
+ allowExternalPaths?: boolean
83
105
  /** The benchmark's cases, in order. */
84
106
  cases: readonly BenchmarkCase[]
85
107
  /** Pricing keyed by model id; an absent model reports `costUsd: null`. */
@@ -168,6 +190,8 @@ export interface EvalTrialResult {
168
190
  tracePath?: string
169
191
  /** Absolute paths of every harvested session log, primary first. */
170
192
  tracePaths?: readonly string[]
193
+ /** SHA-256 of the merged trace; lets offline re-judging detect altered logs. */
194
+ traceSha256?: string
171
195
  /** The child process's exit code, or null when it was killed. */
172
196
  exitCode: number | null
173
197
  /** Whether the trial hit its timeout and killed the child. */
@@ -182,7 +206,7 @@ export interface EvalTrialResult {
182
206
 
183
207
  /** Scripted grading outcome for one trial. */
184
208
  export interface EvalGrade {
185
- /** Whether the check command exited 0, or null when no check is configured. */
209
+ /** Whether the check command exited 0 or the answer regex matched; null when neither is configured. */
186
210
  taskSuccess: boolean | null
187
211
  /** Whether an expected tool was called, or null when no tool is configured. */
188
212
  toolSelectionAccuracy: boolean | null
@@ -196,11 +220,13 @@ export interface EvalJudgeVerdict {
196
220
  hallucination: boolean | null
197
221
  /** Judge rationale, when the model returned one. */
198
222
  rationale?: string
223
+ /** Why this verdict is unusable — a failed call or an unparsable reply. */
224
+ judgeError?: string
199
225
  }
200
226
 
201
227
  /** Pooled grading rates over completed trials. */
202
228
  export interface EvalRunGrading {
203
- /** Pooled task-success rate, or null when no trial carried a check. */
229
+ /** Pooled task-success rate, or null when no trial carried a check or answer regex. */
204
230
  taskSuccessRate: number | null
205
231
  /** Pooled tool-selection-accuracy rate, or null when no trial carried an expected tool. */
206
232
  toolSelectionAccuracyRate: number | null
@@ -208,6 +234,18 @@ export interface EvalRunGrading {
208
234
  finalAnswerScore: number | null
209
235
  /** Pooled hallucination rate over judged trials, or null when nothing was judged. */
210
236
  hallucinationRate: number | null
237
+ /** Judge calls that failed or returned unusable output, when a judge was configured. */
238
+ judgeFailures?: number
239
+ }
240
+
241
+ /** Minimal case input needed to re-judge a stored trial without the benchmark file. */
242
+ export interface EvalCaseInput {
243
+ /** Case id matching the trial results. */
244
+ caseId: string
245
+ /** Task text handed to the agent and the judge. */
246
+ prompt: string
247
+ /** Gold answer handed to the judge, when the case had one. */
248
+ answer?: string
211
249
  }
212
250
 
213
251
  /** A persisted eval run. */
@@ -216,11 +254,21 @@ export interface EvalRun {
216
254
  benchmark: string
217
255
  /** Model id the benchmark targeted. */
218
256
  model: string
257
+ /** SHA-256 of the benchmark YAML, resolved inputs and CLI overrides, when known. */
258
+ benchmarkSha256?: string
259
+ /** CLI overrides that changed the effective benchmark configuration. */
260
+ benchmarkOverrides?: {
261
+ trials?: number
262
+ concurrency?: number
263
+ seed?: number
264
+ profile?: string
265
+ dshCommand?: readonly string[]
266
+ }
219
267
  /** Run creation time, epoch milliseconds. */
220
268
  createdAt: number
221
269
  /** Trials per case actually executed. */
222
270
  trials: number
223
- /** Benchmark seed. */
271
+ /** Benchmark seed; also the base for per-trial `DSH_EVAL_SEED` values. */
224
272
  seed: number
225
273
  /** Resolved pricing for the benchmark model, or null without one. */
226
274
  pricing: BenchmarkPricing | null
@@ -230,6 +278,8 @@ export interface EvalRun {
230
278
  tempRoot: string
231
279
  /** Per-trial outcomes in execution order. */
232
280
  cases: readonly EvalTrialResult[]
281
+ /** Case prompts and gold answers, so a stored run can be re-judged. */
282
+ caseInputs?: readonly EvalCaseInput[]
233
283
  /** Mean/pooled metrics over completed trials, or null when none completed. */
234
284
  aggregate: EvalCaseMetrics | null
235
285
  /** Pooled scripted-grading rates over completed trials, or null when ungraded. */
@@ -0,0 +1,177 @@
1
+ /**
2
+ * Benchmark preflight for dsh-eval.
3
+ *
4
+ * A malformed benchmark is best caught before a run spawns agents and spends
5
+ * tokens. Parsing already rejects invalid YAML, regexes and conflicting check
6
+ * modes; this module turns the validated document into a readable summary plus
7
+ * warnings for configurations that run but produce weak evidence.
8
+ *
9
+ * @module dsh-eval/validate
10
+ */
11
+
12
+ import { signTestPower } from './stats.ts'
13
+ import type { Benchmark } from './types.ts'
14
+
15
+ /** Structured preflight result, shared by the markdown and JSON renderers. */
16
+ export interface BenchmarkSummary {
17
+ name: string
18
+ /** SHA-256 of the benchmark YAML source, when parsed from text. */
19
+ sourceSha256: string | null
20
+ model: string
21
+ profile: string
22
+ command: readonly string[]
23
+ trials: number
24
+ concurrency: number
25
+ timeoutMs: number
26
+ seed: number
27
+ cases: number
28
+ gradedCases: number
29
+ goldAnswers: number
30
+ checks: number
31
+ toolConstraints: number
32
+ /** Cases with a per-case timeout override. */
33
+ caseTimeouts: number
34
+ judge: { provider: string; model: string; maxScore: number } | null
35
+ replay: string | null
36
+ pricing: boolean
37
+ warnings: string[]
38
+ }
39
+
40
+ /**
41
+ * Derive a structured preflight summary from a validated benchmark.
42
+ * @param benchmark - a parsed benchmark document.
43
+ * @returns counts, configuration and actionable warnings.
44
+ */
45
+ export function summarizeBenchmark(benchmark: Benchmark): BenchmarkSummary {
46
+ let checks = 0
47
+ let toolConstraints = 0
48
+ let gradedCases = 0
49
+ let goldAnswers = 0
50
+ let shellChecks = 0
51
+ let caseTimeouts = 0
52
+ const warnings: string[] = []
53
+ const caseIds = new Set<string>()
54
+ const duplicateIds = new Set<string>()
55
+ for (const item of benchmark.cases) {
56
+ if (item.timeoutMs !== undefined) caseTimeouts += 1
57
+ if (caseIds.has(item.id)) duplicateIds.add(item.id)
58
+ caseIds.add(item.id)
59
+ const expected = item.expected
60
+ if (expected === undefined) continue
61
+ gradedCases += 1
62
+ if (expected.answer !== undefined) goldAnswers += 1
63
+ if (expected.check !== undefined) checks += 1
64
+ if (expected.checkArgv !== undefined) checks += 1
65
+ const hasCheck = expected.check !== undefined || expected.checkArgv !== undefined
66
+ || expected.checkShell !== undefined
67
+ if (expected.answerRegex !== undefined) {
68
+ if (hasCheck) {
69
+ warnings.push(`case ${item.id} combines a check command with answerRegex — the regex is ignored`)
70
+ } else {
71
+ checks += 1
72
+ }
73
+ }
74
+ if (expected.checkShell !== undefined) {
75
+ checks += 1
76
+ shellChecks += 1
77
+ }
78
+ toolConstraints += [expected.tool, expected.tools, expected.toolAnyOf, expected.toolRegex, expected.toolNot]
79
+ .filter(value => value !== undefined).length
80
+ }
81
+ if (duplicateIds.size > 0) {
82
+ warnings.push(`duplicate case ids (${[...duplicateIds].slice(0, 5).join(', ')}) break pairing and case-input lookup`)
83
+ }
84
+ if (benchmark.trials < 2) {
85
+ warnings.push('one trial per case cannot measure flakiness or pass@k; use at least 2 trials')
86
+ }
87
+ if (gradedCases === 0 && benchmark.judge === undefined) {
88
+ warnings.push('no case has scripted expectations and no judge is configured — the run cannot produce a quality score')
89
+ } else if (gradedCases === 0) {
90
+ warnings.push('no case has scripted expectations — results depend entirely on the judge')
91
+ }
92
+ if (checks === 0 && toolConstraints === 0 && benchmark.judge === undefined) {
93
+ warnings.push('no case checks tool use or task success — the run will produce only cost and latency data')
94
+ }
95
+ if (benchmark.judge !== undefined && goldAnswers === 0) {
96
+ warnings.push('judge is configured but no case supplies a gold answer — score calibration will be weak')
97
+ }
98
+ if (shellChecks > 0) {
99
+ warnings.push(`${shellChecks} shell check(s) need a trusted benchmark file (pipes and redirection are enabled)`)
100
+ }
101
+ const maxPairs = benchmark.cases.length * benchmark.trials
102
+ // Preflight cannot know whether trials will carry step/token metrics, so it
103
+ // assumes the largest inference family the comparison may print.
104
+ const minimumDiscordant = signTestPower(0, benchmark.judge === undefined ? 3 : 4).minimumDiscordant
105
+ if (maxPairs < minimumDiscordant) {
106
+ warnings.push(`at most ${maxPairs} paired trials; a Bonferroni-corrected sign test needs ≥${minimumDiscordant} discordant pairs to reach α=0.05`)
107
+ }
108
+ if (benchmark.replay !== undefined && benchmark.judge === undefined) {
109
+ warnings.push('replay runs have no live judge; use `dsh eval rejudge` after the run if judge scores are needed')
110
+ }
111
+ const judge = benchmark.judge
112
+ return {
113
+ name: benchmark.name,
114
+ sourceSha256: benchmark.sourceSha256 ?? null,
115
+ model: benchmark.model,
116
+ profile: benchmark.profile,
117
+ command: benchmark.command,
118
+ trials: benchmark.trials,
119
+ concurrency: benchmark.concurrency,
120
+ timeoutMs: benchmark.timeoutMs,
121
+ seed: benchmark.seed,
122
+ cases: benchmark.cases.length,
123
+ gradedCases,
124
+ goldAnswers,
125
+ checks,
126
+ toolConstraints,
127
+ caseTimeouts,
128
+ judge: judge === undefined ? null : {
129
+ provider: judge.provider, model: judge.model, maxScore: judge.maxScore,
130
+ },
131
+ replay: benchmark.replay === undefined ? null : benchmark.replay.dir,
132
+ pricing: benchmark.pricing !== undefined,
133
+ warnings,
134
+ }
135
+ }
136
+
137
+ /**
138
+ * Render a validated benchmark summary with actionable warnings.
139
+ * @param benchmark - a parsed benchmark document.
140
+ * @returns markdown ending in a newline.
141
+ */
142
+ export function renderBenchmarkSummary(benchmark: Benchmark): string {
143
+ const summary = summarizeBenchmark(benchmark)
144
+ const lines = [
145
+ `# Benchmark: ${summary.name}`,
146
+ '',
147
+ `- model: ${summary.model}`,
148
+ ...(summary.sourceSha256 === null ? [] : [`- source sha256: ${summary.sourceSha256}`]),
149
+ `- profile: ${summary.profile}`,
150
+ `- command: ${summary.command.join(' ')}`,
151
+ `- trials per case: ${summary.trials}`,
152
+ `- concurrency: ${summary.concurrency}`,
153
+ `- timeout: ${summary.timeoutMs} ms${summary.caseTimeouts === 0 ? '' : ` (${summary.caseTimeouts} per-case override(s))`}`,
154
+ `- seed: ${summary.seed} (trial n receives DSH_EVAL_SEED = ${summary.seed} + n - 1)`,
155
+ `- cases: ${summary.cases} (${summary.gradedCases} graded, ${summary.goldAnswers} with gold answers)`,
156
+ `- expectations: ${summary.checks} check(s), ${summary.toolConstraints} tool constraint(s)`,
157
+ `- judge: ${summary.judge === null ? 'none' : `${summary.judge.model} on ${summary.judge.provider} (max ${summary.judge.maxScore})`}`,
158
+ `- replay: ${summary.replay ?? 'live'}`,
159
+ `- pricing: ${summary.pricing ? 'configured' : 'none'}`,
160
+ '',
161
+ `Validated: ${summary.name} is ready to run.`,
162
+ '',
163
+ ]
164
+ if (summary.warnings.length > 0) {
165
+ lines.push('## Warnings', '', ...summary.warnings.map(warning => `- ${warning}`), '')
166
+ }
167
+ return lines.join('\n')
168
+ }
169
+
170
+ /**
171
+ * Render a preflight summary as machine-readable JSON.
172
+ * @param benchmark - a parsed benchmark document.
173
+ * @returns a JSON string ending in a newline.
174
+ */
175
+ export function renderBenchmarkJson(benchmark: Benchmark): string {
176
+ return `${JSON.stringify(summarizeBenchmark(benchmark))}\n`
177
+ }