dsh-eval 0.1.0-rc.6 → 0.3.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 +66 -6
- package/lib/index.js +28 -3
- package/lib/types/command.d.ts +7 -0
- package/lib/types/compare.d.ts +28 -0
- package/lib/types/import.d.ts +36 -0
- package/lib/types/index.d.ts +12 -1
- package/lib/types/judge.d.ts +76 -0
- package/lib/types/runner.d.ts +3 -0
- package/lib/types/trace.d.ts +15 -0
- package/lib/types/types.d.ts +43 -0
- package/package.json +1 -1
- package/src/benchmark.ts +21 -0
- package/src/command.ts +27 -0
- package/src/compare.ts +135 -2
- package/src/import.ts +327 -0
- package/src/index.ts +33 -3
- package/src/judge.ts +198 -0
- package/src/report.ts +47 -13
- package/src/runner.ts +95 -24
- package/src/trace.ts +43 -0
- package/src/types.ts +46 -0
package/README.md
CHANGED
|
@@ -55,21 +55,81 @@ pricing:
|
|
|
55
55
|
| `cases[].expected` | absent | Scripted grading: `tool` is a substring matched against recorded tool-call names; `check` is a command run in the trial workspace after the agent exits (exit 0 = task success). At least one is required when present. |
|
|
56
56
|
| `pricing` | absent | Per-million-token USD prices keyed by model id; absent models report `costUsd: null`. |
|
|
57
57
|
|
|
58
|
+
### Judge
|
|
59
|
+
|
|
60
|
+
`judge` enables LLM-judge scoring of final answers and hallucination:
|
|
61
|
+
|
|
62
|
+
```yaml
|
|
63
|
+
judge:
|
|
64
|
+
provider: deepseek
|
|
65
|
+
model: deepseek-v4
|
|
66
|
+
rubric: Prefer correct, concise fixes.
|
|
67
|
+
maxScore: 10
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
| Field | Default | Meaning |
|
|
71
|
+
|---|---|---|
|
|
72
|
+
| `provider` | `deepseek` | LLM provider route for the judge call. |
|
|
73
|
+
| `model` | benchmark `model` | Judge model id. |
|
|
74
|
+
| `rubric` | absent | Task rubric appended to the judging prompt. |
|
|
75
|
+
| `maxScore` | `10` | Maximum final-answer score. |
|
|
76
|
+
|
|
77
|
+
The judge builds a strict-JSON prompt from the case and the merged trace. A
|
|
78
|
+
trial carries its verdict (`finalAnswerScore`, `hallucination`, `rationale`)
|
|
79
|
+
when the reply parses; unusable output or a chat failure reads as null verdict
|
|
80
|
+
fields, never as a failed trial. A run with a configured judge fails before
|
|
81
|
+
starting when the host exposes no LLM chat seam.
|
|
82
|
+
|
|
58
83
|
## Metrics
|
|
59
84
|
|
|
60
85
|
The metric fold computes the automatic metrics directly from the session log: `turns`, `steps`, `toolCalls`, `toolResults`, `toolSuccess` plus `toolSuccessRate`, `invalidToolCalls` (results carrying an internal failure identity), `retries` (`llm/retry`), disjoint token buckets and totals, billed context tokens, `llmMs`/`toolMs`/`ttftMs`/`latencyMs`, and `costUsd` when pricing is configured. Scripted grading adds per-trial `taskSuccess` (check-command exit 0) and `toolSelectionAccuracy` (expected-tool match) and pools them into run-level rates. LLM-judge metrics (final-answer score, hallucination) are deferred.
|
|
61
86
|
|
|
87
|
+
Child session logs under the trial's DSH_HOME are merged into the trial trace
|
|
88
|
+
before the fold, so delegated subagent work counts toward steps, tokens, tool
|
|
89
|
+
calls, retries, and latency. LLM-judge verdicts add per-trial
|
|
90
|
+
`finalAnswerScore` and `hallucination` and pool into run-level mean score and
|
|
91
|
+
hallucination rate.
|
|
92
|
+
|
|
62
93
|
## Run report
|
|
63
94
|
|
|
64
95
|
`dsh eval run --out run.json` writes one JSON document per run: benchmark and model identity, per-trial outcomes with absolute trace paths, aggregate metrics (means for counts and wall times, pooled success rate), and pooled grading rates. `dsh eval report run.json` renders the run as markdown. Trial workspaces and traces stay under the run's `tempRoot` (a private temp directory) and are not deleted; remove them when the run is no longer needed.
|
|
65
96
|
|
|
66
97
|
## Comparison
|
|
67
98
|
|
|
68
|
-
`dsh eval compare run-v1.json run-v2.json` renders both runs as a markdown table: benchmark/model identity, completed trials, steps, tool/task/tool-selection rates, invalid calls, retries, tokens, cost, and latency, with signed `B - A` deltas.
|
|
99
|
+
`dsh eval compare run-v1.json run-v2.json` renders both runs as a markdown table: benchmark/model identity, completed trials, steps, tool/task/tool-selection rates, invalid calls, retries, tokens, cost, and latency, with signed `B - A` deltas. When both runs complete the same case x trial keys, the table appends paired statistics: trial count, win/lose/tie on the first available metric (task success, tool selection accuracy, or final-answer score), and mean `B - A` deltas for steps, tokens, and judge score. The runs' `seed` is recorded provenance for the pairing, not a guarantee of identical model output.
|
|
100
|
+
|
|
101
|
+
## Replay (keyless CI)
|
|
102
|
+
|
|
103
|
+
A keyed run records every trial's session log under its `tempRoot`. Copy the
|
|
104
|
+
recorded trial trees into a `replay.dir` and rerun without credentials: the
|
|
105
|
+
spawned harness mounts `@deepseek-ai/dsh-llm-replay`, which reconstructs each
|
|
106
|
+
model stream from the recorded `assistant/chunk` events.
|
|
107
|
+
|
|
108
|
+
```yaml
|
|
109
|
+
replay:
|
|
110
|
+
dir: ./recorded
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
The directory holds one tree per trial named `<caseId>-<trial>/`, with child
|
|
114
|
+
logs riding alongside: `recorded/fix-tests-001-1/session.jsonl`. A missing
|
|
115
|
+
fixture fails that trial, and `judge` cannot be combined with `replay` in one
|
|
116
|
+
run. The npm release of the replay plugin lags the source workspace, so replay
|
|
117
|
+
runs require a source-mode harness checkout.
|
|
118
|
+
|
|
119
|
+
## Importing external traces
|
|
120
|
+
|
|
121
|
+
`dsh eval import codex|claude-code <session.jsonl> --out run.json` imports a
|
|
122
|
+
Codex or Claude Code session log as a one-trial run with folded metrics:
|
|
123
|
+
|
|
124
|
+
- one synthesized turn (and step) per user message;
|
|
125
|
+
- assistant text, tool calls, and tool results mapped into the trace vocabulary;
|
|
126
|
+
- token usage is not part of either external format, so token and cost metrics stay zero.
|
|
127
|
+
|
|
128
|
+
The imported run drops into the same `report`/`compare` pipeline.
|
|
69
129
|
|
|
70
130
|
## Extension points
|
|
71
131
|
|
|
72
|
-
The runner is the only consumer today: `runBenchmark` takes a loaded benchmark and returns the run record, and the report module persists and renders it.
|
|
132
|
+
The runner is the only consumer today: `runBenchmark` takes a loaded benchmark and returns the run record, and the report module persists and renders it. The judge chat seam is injected by the host (a dsh-llm stream) and stubbed in tests, keeping the suite keyless.
|
|
73
133
|
|
|
74
134
|
## Model Experience
|
|
75
135
|
|
|
@@ -81,10 +141,10 @@ None; this package neither assembles nor sends a provider request, so no request
|
|
|
81
141
|
|
|
82
142
|
## Known Limitations and Deferred Work
|
|
83
143
|
|
|
84
|
-
- **
|
|
85
|
-
- **Paired comparison is
|
|
86
|
-
- **
|
|
87
|
-
- **
|
|
144
|
+
- **Judge output is best-effort** — a judge chat failure or unparsable reply yields null verdict fields, and judge calls consume model quota outside the trial's measured cost.
|
|
145
|
+
- **Paired comparison pairs as-is** — trials pair by case id and trial index; `seed` is recorded provenance, not a deterministic guarantee of identical model output, and per-arm leaderboards are not rendered.
|
|
146
|
+
- **Replay binds by first-call order** — the replay plugin keys recorded scripts to live sessions by first-call order, so concurrent subagents replay non-deterministically.
|
|
147
|
+
- **Imported traces lack token usage** — Codex and Claude Code logs do not record provider usage, so imported runs report zero tokens and no cost.
|
|
88
148
|
- **Direct-child timeout only** — a timed-out trial kills the direct dsh process; on Windows its descendants may survive.
|
|
89
149
|
- **Windows launcher commands** — the spawned command runs without a shell, so `.cmd`/`.bat` shims need a direct executable or `node <path>` override (`--dsh "node C:/.../apps/cli/lib/bin.js"`).
|
|
90
150
|
- **No atomic report write** — the run JSON is written in place; a crash mid-write can truncate the report.
|
package/lib/index.js
CHANGED
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
import { loadBenchmark } from "./benchmark.js";
|
|
15
15
|
import { applyEval } from "./command.js";
|
|
16
16
|
import { compareRuns, renderCompareMarkdown } from "./compare.js";
|
|
17
|
+
import { importTraceFile } from "./import.js";
|
|
18
|
+
import { llmJudgeChat } from "./judge.js";
|
|
17
19
|
import { renderMarkdownReport, writeRunReport, loadRunReport } from "./report.js";
|
|
18
20
|
import { runBenchmark } from "./runner.js";
|
|
19
21
|
/** Stable Cordis plugin name. */
|
|
@@ -25,6 +27,16 @@ export const internals = {
|
|
|
25
27
|
stdout: process.stdout,
|
|
26
28
|
stderr: process.stderr,
|
|
27
29
|
};
|
|
30
|
+
/**
|
|
31
|
+
* Resolve the production judge chat seam from the mounted llm service, or
|
|
32
|
+
* undefined when the composition carries no llm service.
|
|
33
|
+
* @param ctx - the plugin context.
|
|
34
|
+
* @returns a chat seam over the llm stream, or undefined without llm.
|
|
35
|
+
*/
|
|
36
|
+
export function resolveJudgeChat(ctx) {
|
|
37
|
+
const llm = ctx.get('llm');
|
|
38
|
+
return llm === undefined ? undefined : llmJudgeChat(llm.stream);
|
|
39
|
+
}
|
|
28
40
|
/** Aggregate-success sentence for the run summary line. */
|
|
29
41
|
function summary(run) {
|
|
30
42
|
const aggregate = run.aggregate;
|
|
@@ -35,17 +47,28 @@ function summary(run) {
|
|
|
35
47
|
const task = taskRate === null || taskRate === undefined
|
|
36
48
|
? ''
|
|
37
49
|
: `, task success ${(taskRate * 100).toFixed(1)}%`;
|
|
38
|
-
|
|
50
|
+
const judgeScore = run.grading?.finalAnswerScore;
|
|
51
|
+
const score = judgeScore === null || judgeScore === undefined
|
|
52
|
+
? ''
|
|
53
|
+
: `, judge score ${judgeScore.toFixed(1)}`;
|
|
54
|
+
return `tool success ${rate}${task}${score}, ${aggregate.steps.toFixed(1)} steps/trial`;
|
|
39
55
|
}
|
|
40
56
|
/**
|
|
41
57
|
* Execute one eval invocation to completion.
|
|
42
58
|
* @param values - the resolved command-line invocation.
|
|
43
59
|
* @param io - output streams for the report and diagnostics.
|
|
60
|
+
* @param services - injected runtime seams, e.g. the LLM-judge chat.
|
|
44
61
|
* @returns the process exit code; nonzero for any failure or a run with no
|
|
45
62
|
* completed trials.
|
|
46
63
|
*/
|
|
47
|
-
export async function executeEval(values, io) {
|
|
64
|
+
export async function executeEval(values, io, services = {}) {
|
|
48
65
|
try {
|
|
66
|
+
if (values.kind === 'import') {
|
|
67
|
+
const run = await importTraceFile(values.format, values.path, values.caseId);
|
|
68
|
+
await writeRunReport(run, values.outPath);
|
|
69
|
+
io.stdout.write(`Wrote ${values.outPath} (1 imported trial, ${summary(run)})\n`);
|
|
70
|
+
return 0;
|
|
71
|
+
}
|
|
49
72
|
if (values.kind === 'report') {
|
|
50
73
|
const run = await loadRunReport(values.runPath);
|
|
51
74
|
io.stdout.write(renderMarkdownReport(run));
|
|
@@ -62,6 +85,7 @@ export async function executeEval(values, io) {
|
|
|
62
85
|
...(values.trials !== undefined ? { trials: values.trials } : {}),
|
|
63
86
|
...(values.dshCommand !== undefined ? { command: values.dshCommand } : {}),
|
|
64
87
|
...(values.profile !== undefined ? { profile: values.profile } : {}),
|
|
88
|
+
...(services.judgeChat !== undefined ? { judgeChat: services.judgeChat } : {}),
|
|
65
89
|
});
|
|
66
90
|
await writeRunReport(run, values.outPath);
|
|
67
91
|
io.stdout.write(`Wrote ${values.outPath} (${run.cases.length} trials, ${summary(run)})\n`);
|
|
@@ -81,8 +105,9 @@ export function apply(ctx) {
|
|
|
81
105
|
const exit = ctx.get('appExit');
|
|
82
106
|
if (exit === undefined)
|
|
83
107
|
throw new Error('eval: the launcher must provide ctx.appExit before the tree mounts');
|
|
108
|
+
const judgeChat = resolveJudgeChat(ctx);
|
|
84
109
|
const values = applyEval(ctx);
|
|
85
110
|
if (values === undefined)
|
|
86
111
|
return;
|
|
87
|
-
void executeEval(values, internals).then((code) => { exit(code); });
|
|
112
|
+
void executeEval(values, internals, { judgeChat }).then((code) => { exit(code); });
|
|
88
113
|
}
|
package/lib/types/command.d.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { Command } from 'commander';
|
|
10
10
|
import type { Context } from '@deepseek-ai/cordis';
|
|
11
|
+
import type { ImportFormat } from './import.ts';
|
|
11
12
|
/** What the eval app resolved from its command line. */
|
|
12
13
|
export type EvalStartupValues = {
|
|
13
14
|
kind: 'run';
|
|
@@ -23,6 +24,12 @@ export type EvalStartupValues = {
|
|
|
23
24
|
kind: 'compare';
|
|
24
25
|
runPathA: string;
|
|
25
26
|
runPathB: string;
|
|
27
|
+
} | {
|
|
28
|
+
kind: 'import';
|
|
29
|
+
format: ImportFormat;
|
|
30
|
+
path: string;
|
|
31
|
+
outPath: string;
|
|
32
|
+
caseId: string;
|
|
26
33
|
};
|
|
27
34
|
/**
|
|
28
35
|
* Build a fresh eval commander program. The root action rejects a bare
|
package/lib/types/compare.d.ts
CHANGED
|
@@ -16,6 +16,34 @@ export interface CompareRow {
|
|
|
16
16
|
/** Signed delta (`b - a`) for numeric rows, or a dash for text rows. */
|
|
17
17
|
delta: string;
|
|
18
18
|
}
|
|
19
|
+
/** Paired same-case statistics over two runs. */
|
|
20
|
+
export interface PairedStats {
|
|
21
|
+
/** Number of case x trial pairs completed in both runs. */
|
|
22
|
+
pairs: number;
|
|
23
|
+
/** Pairs where run B beat run A on the primary metric. */
|
|
24
|
+
wins: number;
|
|
25
|
+
/** Pairs where run A beat run B on the primary metric. */
|
|
26
|
+
losses: number;
|
|
27
|
+
/** Pairs with equal primary-metric outcomes. */
|
|
28
|
+
ties: number;
|
|
29
|
+
/** The metric used for win/lose/tie classification. */
|
|
30
|
+
primaryMetric: 'task success' | 'tool selection accuracy' | 'final answer score';
|
|
31
|
+
/** Mean per-pair step delta (`b - a`), or null when no pair is numeric. */
|
|
32
|
+
meanStepsDelta: number | null;
|
|
33
|
+
/** Mean per-pair token delta (`b - a`), or null when no pair is numeric. */
|
|
34
|
+
meanTokensDelta: number | null;
|
|
35
|
+
/** Mean per-pair judge score delta (`b - a`), or null without judge verdicts. */
|
|
36
|
+
meanScoreDelta: number | null;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Pair both runs' trials by case id and trial index and compute win/lose/tie
|
|
40
|
+
* plus mean deltas. Trials are paired as-is; the runs' `seed` is recorded
|
|
41
|
+
* provenance for the pairing, not a guarantee of identical model output.
|
|
42
|
+
* @param a - the baseline run.
|
|
43
|
+
* @param b - the candidate run.
|
|
44
|
+
* @returns paired statistics, or null when no trial is completed in both runs.
|
|
45
|
+
*/
|
|
46
|
+
export declare function pairedCompare(a: EvalRun, b: EvalRun): PairedStats | null;
|
|
19
47
|
/**
|
|
20
48
|
* Build the comparison rows between two runs.
|
|
21
49
|
* @param a - the baseline run.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-harness trace import: Codex and Claude Code session JSONL become the
|
|
3
|
+
* eval trace vocabulary so report and compare can fold metrics over runs
|
|
4
|
+
* recorded by other agents. Each importer synthesizes one turn (and one step)
|
|
5
|
+
* per user message, preserving assistant text and tool calls/results; model
|
|
6
|
+
* token usage is not part of either external format, so token metrics stay
|
|
7
|
+
* zero.
|
|
8
|
+
*
|
|
9
|
+
* @module dsh-eval/import
|
|
10
|
+
*/
|
|
11
|
+
import type { EvalRun, EvalTrace } from './types.ts';
|
|
12
|
+
/**
|
|
13
|
+
* Import a Codex session JSONL (lines of `response_item` records) as a trace.
|
|
14
|
+
* @param text - the Codex log's UTF-8 text.
|
|
15
|
+
* @param source - the source file path, used for the synthetic session id.
|
|
16
|
+
* @returns the imported trace; non-`response_item` lines are skipped.
|
|
17
|
+
*/
|
|
18
|
+
export declare function importCodexLog(text: string, source: string): EvalTrace;
|
|
19
|
+
/**
|
|
20
|
+
* Import a Claude Code session JSONL (lines of `user`/`assistant` records) as
|
|
21
|
+
* a trace.
|
|
22
|
+
* @param text - the Claude Code log's UTF-8 text.
|
|
23
|
+
* @param source - the source file path, used for the synthetic session id.
|
|
24
|
+
* @returns the imported trace; non-user/assistant lines are skipped.
|
|
25
|
+
*/
|
|
26
|
+
export declare function importClaudeLog(text: string, source: string): EvalTrace;
|
|
27
|
+
/** Import formats the CLI accepts. */
|
|
28
|
+
export type ImportFormat = 'codex' | 'claude-code';
|
|
29
|
+
/**
|
|
30
|
+
* Load an external session log and build a one-trial run record from it.
|
|
31
|
+
* @param format - the external harness format.
|
|
32
|
+
* @param path - the session JSONL path.
|
|
33
|
+
* @param caseId - the imported trial's case id.
|
|
34
|
+
* @returns the run record with one completed trial.
|
|
35
|
+
*/
|
|
36
|
+
export declare function importTraceFile(format: ImportFormat, path: string, caseId: string): Promise<EvalRun>;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import type { Context } from '@deepseek-ai/cordis';
|
|
15
15
|
import { type EvalStartupValues } from './command.ts';
|
|
16
|
+
import { type JudgeChat } from './judge.ts';
|
|
16
17
|
/** Stable Cordis plugin name. */
|
|
17
18
|
export declare const name = "eval";
|
|
18
19
|
/** The launcher-provided command line is the only required service. */
|
|
@@ -28,14 +29,24 @@ export interface EvalIo {
|
|
|
28
29
|
}
|
|
29
30
|
/** The process streams the eval app writes to; tests substitute captures. */
|
|
30
31
|
export declare const internals: EvalIo;
|
|
32
|
+
/**
|
|
33
|
+
* Resolve the production judge chat seam from the mounted llm service, or
|
|
34
|
+
* undefined when the composition carries no llm service.
|
|
35
|
+
* @param ctx - the plugin context.
|
|
36
|
+
* @returns a chat seam over the llm stream, or undefined without llm.
|
|
37
|
+
*/
|
|
38
|
+
export declare function resolveJudgeChat(ctx: Context): JudgeChat | undefined;
|
|
31
39
|
/**
|
|
32
40
|
* Execute one eval invocation to completion.
|
|
33
41
|
* @param values - the resolved command-line invocation.
|
|
34
42
|
* @param io - output streams for the report and diagnostics.
|
|
43
|
+
* @param services - injected runtime seams, e.g. the LLM-judge chat.
|
|
35
44
|
* @returns the process exit code; nonzero for any failure or a run with no
|
|
36
45
|
* completed trials.
|
|
37
46
|
*/
|
|
38
|
-
export declare function executeEval(values: EvalStartupValues, io: EvalIo
|
|
47
|
+
export declare function executeEval(values: EvalStartupValues, io: EvalIo, services?: {
|
|
48
|
+
judgeChat?: JudgeChat | undefined;
|
|
49
|
+
}): Promise<number>;
|
|
39
50
|
/**
|
|
40
51
|
* Mount the eval command-line app: parse the invocation, run it asynchronously,
|
|
41
52
|
* and request launcher exit with the result code.
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLM-judge scoring for dsh-eval: builds a judging prompt from the case and
|
|
3
|
+
* its trace, calls an injected chat seam, and parses the model's strict-JSON
|
|
4
|
+
* verdict into a final-answer score and hallucination flag. The production
|
|
5
|
+
* seam wraps the dsh-llm stream API; tests inject a fake so the suite stays
|
|
6
|
+
* keyless.
|
|
7
|
+
*
|
|
8
|
+
* @module dsh-eval/judge
|
|
9
|
+
*/
|
|
10
|
+
import { type LlmRuntime } from '@deepseek-ai/dsh-llm';
|
|
11
|
+
import type { BenchmarkCase, BenchmarkJudge, EvalJudgeVerdict, EvalTrace } from './types.ts';
|
|
12
|
+
/** One judge chat call: system instructions plus the single task prompt. */
|
|
13
|
+
export interface JudgeChatRequest {
|
|
14
|
+
/** Provider route, e.g. `deepseek`. */
|
|
15
|
+
provider: string;
|
|
16
|
+
/** Judge model id. */
|
|
17
|
+
model: string;
|
|
18
|
+
/** System instructions demanding strict JSON output. */
|
|
19
|
+
system: string;
|
|
20
|
+
/** The task and trace summary to judge. */
|
|
21
|
+
prompt: string;
|
|
22
|
+
}
|
|
23
|
+
/** The injected chat seam; returns the model's raw text reply. */
|
|
24
|
+
export type JudgeChat = (request: JudgeChatRequest) => Promise<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Summarize a trace for the judge: final assistant answer, the distinct tool
|
|
27
|
+
* names called, and the failure counters a hallucination call needs.
|
|
28
|
+
* @param trace - the merged trial trace.
|
|
29
|
+
* @returns a compact human-readable summary.
|
|
30
|
+
*/
|
|
31
|
+
export declare function summarizeTrace(trace: EvalTrace): string;
|
|
32
|
+
/**
|
|
33
|
+
* Build the judge's system instructions and task prompt.
|
|
34
|
+
* @param caseValue - the benchmark case being judged.
|
|
35
|
+
* @param trace - the merged trial trace.
|
|
36
|
+
* @param judge - the judge configuration.
|
|
37
|
+
* @returns the system and prompt texts.
|
|
38
|
+
*/
|
|
39
|
+
export declare function buildJudgePrompt(caseValue: BenchmarkCase, trace: EvalTrace, judge: BenchmarkJudge): {
|
|
40
|
+
system: string;
|
|
41
|
+
prompt: string;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Parse the judge model's strict-JSON reply into a verdict. Unusable output
|
|
45
|
+
* yields null fields, never a fabricated verdict.
|
|
46
|
+
* @param text - the raw model reply.
|
|
47
|
+
* @param maxScore - the configured maximum score.
|
|
48
|
+
* @returns the parsed verdict.
|
|
49
|
+
*/
|
|
50
|
+
export declare function parseJudgeVerdict(text: string, maxScore: number): EvalJudgeVerdict;
|
|
51
|
+
/**
|
|
52
|
+
* Judge one trial through the chat seam.
|
|
53
|
+
* @param caseValue - the benchmark case being judged.
|
|
54
|
+
* @param trace - the merged trial trace.
|
|
55
|
+
* @param judge - the judge configuration.
|
|
56
|
+
* @param chat - the injected chat seam.
|
|
57
|
+
* @returns the parsed verdict; a chat failure rejects.
|
|
58
|
+
*/
|
|
59
|
+
export declare function judgeTrial(caseValue: BenchmarkCase, trace: EvalTrace, judge: BenchmarkJudge, chat: JudgeChat): Promise<EvalJudgeVerdict>;
|
|
60
|
+
/**
|
|
61
|
+
* Judge one trial, converting a chat failure into an all-null verdict so a
|
|
62
|
+
* judge outage reads as unjudged rather than a failed trial.
|
|
63
|
+
* @param caseValue - the benchmark case being judged.
|
|
64
|
+
* @param trace - the merged trial trace.
|
|
65
|
+
* @param judge - the judge configuration.
|
|
66
|
+
* @param chat - the injected chat seam.
|
|
67
|
+
* @returns the parsed verdict, or all-null when the chat call threw.
|
|
68
|
+
*/
|
|
69
|
+
export declare function tryJudgeTrial(caseValue: BenchmarkCase, trace: EvalTrace, judge: BenchmarkJudge, chat: JudgeChat): Promise<EvalJudgeVerdict>;
|
|
70
|
+
/**
|
|
71
|
+
* Build the production chat seam over a dsh-llm stream: one user turn, zero
|
|
72
|
+
* temperature, and text-block assembly of the reply.
|
|
73
|
+
* @param stream - the llm service's stream method.
|
|
74
|
+
* @returns a chat seam reading only text blocks from the stream.
|
|
75
|
+
*/
|
|
76
|
+
export declare function llmJudgeChat(stream: LlmRuntime['stream']): JudgeChat;
|
package/lib/types/runner.d.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* @module dsh-eval/runner
|
|
14
14
|
*/
|
|
15
15
|
import type { Benchmark, EvalRun } from './types.ts';
|
|
16
|
+
import { type JudgeChat } from './judge.ts';
|
|
16
17
|
/** Runtime overrides applied to a loaded benchmark. */
|
|
17
18
|
export interface RunOptions {
|
|
18
19
|
/** Override the benchmark's dsh command argv. */
|
|
@@ -23,6 +24,8 @@ export interface RunOptions {
|
|
|
23
24
|
trials?: number;
|
|
24
25
|
/** Root for trial directories; defaults to the platform temp dir. */
|
|
25
26
|
tempRoot?: string;
|
|
27
|
+
/** LLM-judge chat seam; required when the benchmark configures a judge. */
|
|
28
|
+
judgeChat?: JudgeChat;
|
|
26
29
|
}
|
|
27
30
|
/**
|
|
28
31
|
* Run every case x trial sequentially and aggregate the completed trials.
|
package/lib/types/trace.d.ts
CHANGED
|
@@ -28,3 +28,18 @@ export declare function loadTrace(path: string): Promise<EvalTrace>;
|
|
|
28
28
|
* @returns the newest primary log's absolute path, or null when none exists.
|
|
29
29
|
*/
|
|
30
30
|
export declare function findPrimarySessionLog(root: string): Promise<string | null>;
|
|
31
|
+
/**
|
|
32
|
+
* Find every `session.jsonl` under a DSH_HOME tree, sorted by modification
|
|
33
|
+
* time ascending so the parent session (started first) comes first.
|
|
34
|
+
* @param root - the DSH_HOME directory to scan.
|
|
35
|
+
* @returns absolute log paths in ascending mtime order.
|
|
36
|
+
*/
|
|
37
|
+
export declare function findSessionLogs(root: string): Promise<string[]>;
|
|
38
|
+
/**
|
|
39
|
+
* Merge traces into one timeline: events from every trace sorted by event
|
|
40
|
+
* time, ties broken by source order. The primary trace's header (session id
|
|
41
|
+
* and creation time) labels the merged trace.
|
|
42
|
+
* @param traces - harvested traces, primary first.
|
|
43
|
+
* @returns the merged trace.
|
|
44
|
+
*/
|
|
45
|
+
export declare function mergeTraces(traces: readonly EvalTrace[]): EvalTrace;
|
package/lib/types/types.d.ts
CHANGED
|
@@ -35,6 +35,26 @@ export interface BenchmarkExpectation {
|
|
|
35
35
|
/** Command run in the trial workspace after the agent exits; exit 0 means task success. */
|
|
36
36
|
check?: string;
|
|
37
37
|
}
|
|
38
|
+
/** LLM-judge configuration: scores final answers and flags hallucinations. */
|
|
39
|
+
export interface BenchmarkJudge {
|
|
40
|
+
/** Provider route for the judge call, e.g. `deepseek`. */
|
|
41
|
+
provider: string;
|
|
42
|
+
/** Judge model id; defaults to the benchmark model when unset. */
|
|
43
|
+
model: string;
|
|
44
|
+
/** Optional task rubric appended to the default judging instructions. */
|
|
45
|
+
rubric?: string;
|
|
46
|
+
/** Maximum final-answer score; defaults to 10. */
|
|
47
|
+
maxScore: number;
|
|
48
|
+
}
|
|
49
|
+
/** Keyless replay configuration: recorded session logs replayed instead of live model calls. */
|
|
50
|
+
export interface BenchmarkReplay {
|
|
51
|
+
/**
|
|
52
|
+
* Directory holding one recorded-log tree per trial, named
|
|
53
|
+
* `<caseId>-<trial>/session.jsonl` (child logs ride alongside). A run with
|
|
54
|
+
* a key records these under its `tempRoot`.
|
|
55
|
+
*/
|
|
56
|
+
dir: string;
|
|
57
|
+
}
|
|
38
58
|
/** A validated benchmark document. */
|
|
39
59
|
export interface Benchmark {
|
|
40
60
|
/** Benchmark name; also the run record's `benchmark` field. */
|
|
@@ -55,6 +75,10 @@ export interface Benchmark {
|
|
|
55
75
|
cases: readonly BenchmarkCase[];
|
|
56
76
|
/** Pricing keyed by model id; an absent model reports `costUsd: null`. */
|
|
57
77
|
pricing?: Readonly<Record<string, BenchmarkPricing>>;
|
|
78
|
+
/** LLM-judge configuration, when final-answer scoring is enabled. */
|
|
79
|
+
judge?: BenchmarkJudge;
|
|
80
|
+
/** Keyless replay configuration, when model calls replay from recorded logs. */
|
|
81
|
+
replay?: BenchmarkReplay;
|
|
58
82
|
/** Directory the benchmark document was loaded from; relative paths resolve against it. */
|
|
59
83
|
baseDir: string;
|
|
60
84
|
}
|
|
@@ -129,6 +153,8 @@ export interface EvalTrialResult {
|
|
|
129
153
|
error?: string;
|
|
130
154
|
/** Absolute path of the harvested primary session log. */
|
|
131
155
|
tracePath?: string;
|
|
156
|
+
/** Absolute paths of every harvested session log, primary first. */
|
|
157
|
+
tracePaths?: readonly string[];
|
|
132
158
|
/** The child process's exit code, or null when it was killed. */
|
|
133
159
|
exitCode: number | null;
|
|
134
160
|
/** Whether the trial hit its timeout and killed the child. */
|
|
@@ -137,6 +163,8 @@ export interface EvalTrialResult {
|
|
|
137
163
|
metrics?: EvalCaseMetrics;
|
|
138
164
|
/** Scripted grading outcome for `completed` trials with expectations. */
|
|
139
165
|
grade?: EvalGrade;
|
|
166
|
+
/** LLM-judge verdict for `completed` trials with a configured judge. */
|
|
167
|
+
judge?: EvalJudgeVerdict;
|
|
140
168
|
}
|
|
141
169
|
/** Scripted grading outcome for one trial. */
|
|
142
170
|
export interface EvalGrade {
|
|
@@ -145,12 +173,25 @@ export interface EvalGrade {
|
|
|
145
173
|
/** Whether an expected tool was called, or null when no tool is configured. */
|
|
146
174
|
toolSelectionAccuracy: boolean | null;
|
|
147
175
|
}
|
|
176
|
+
/** LLM-judge verdict for one trial. */
|
|
177
|
+
export interface EvalJudgeVerdict {
|
|
178
|
+
/** Final-answer score within the benchmark's `maxScore`, or null when the judge output was unusable. */
|
|
179
|
+
finalAnswerScore: number | null;
|
|
180
|
+
/** Whether the judge flagged hallucinated content, or null when the judge output was unusable. */
|
|
181
|
+
hallucination: boolean | null;
|
|
182
|
+
/** Judge rationale, when the model returned one. */
|
|
183
|
+
rationale?: string;
|
|
184
|
+
}
|
|
148
185
|
/** Pooled grading rates over completed trials. */
|
|
149
186
|
export interface EvalRunGrading {
|
|
150
187
|
/** Pooled task-success rate, or null when no trial carried a check. */
|
|
151
188
|
taskSuccessRate: number | null;
|
|
152
189
|
/** Pooled tool-selection-accuracy rate, or null when no trial carried an expected tool. */
|
|
153
190
|
toolSelectionAccuracyRate: number | null;
|
|
191
|
+
/** Mean final-answer score over judged trials, or null when nothing was judged. */
|
|
192
|
+
finalAnswerScore: number | null;
|
|
193
|
+
/** Pooled hallucination rate over judged trials, or null when nothing was judged. */
|
|
194
|
+
hallucinationRate: number | null;
|
|
154
195
|
}
|
|
155
196
|
/** A persisted eval run. */
|
|
156
197
|
export interface EvalRun {
|
|
@@ -166,6 +207,8 @@ export interface EvalRun {
|
|
|
166
207
|
seed: number;
|
|
167
208
|
/** Resolved pricing for the benchmark model, or null without one. */
|
|
168
209
|
pricing: BenchmarkPricing | null;
|
|
210
|
+
/** The judge configuration the run used, when one was configured. */
|
|
211
|
+
judge?: BenchmarkJudge;
|
|
169
212
|
/** Root holding every trial's workspace, overlay, and harvested trace. */
|
|
170
213
|
tempRoot: string;
|
|
171
214
|
/** Per-trial outcomes in execution order. */
|
package/package.json
CHANGED
package/src/benchmark.ts
CHANGED
|
@@ -12,6 +12,17 @@ import { load } from 'js-yaml'
|
|
|
12
12
|
import { z } from 'zod'
|
|
13
13
|
import type { Benchmark, BenchmarkCase } from './types.ts'
|
|
14
14
|
|
|
15
|
+
const judgeSchema = z.object({
|
|
16
|
+
provider: z.string().min(1).default('deepseek'),
|
|
17
|
+
model: z.string().min(1).optional(),
|
|
18
|
+
rubric: z.string().min(1).optional(),
|
|
19
|
+
maxScore: z.number().int().positive().default(10),
|
|
20
|
+
}).strict()
|
|
21
|
+
|
|
22
|
+
const replaySchema = z.object({
|
|
23
|
+
dir: z.string().min(1),
|
|
24
|
+
}).strict()
|
|
25
|
+
|
|
15
26
|
const pricingSchema = z.object({
|
|
16
27
|
inputUsdPerMTokens: z.number().nonnegative(),
|
|
17
28
|
cacheReadUsdPerMTokens: z.number().nonnegative(),
|
|
@@ -46,6 +57,8 @@ const benchmarkSchema = z.object({
|
|
|
46
57
|
seed: z.number().int().default(0),
|
|
47
58
|
cases: z.array(benchmarkCaseSchema).min(1),
|
|
48
59
|
pricing: z.record(z.string().min(1), pricingSchema).optional(),
|
|
60
|
+
judge: judgeSchema.optional(),
|
|
61
|
+
replay: replaySchema.optional(),
|
|
49
62
|
}).strict()
|
|
50
63
|
|
|
51
64
|
/**
|
|
@@ -96,6 +109,8 @@ export async function parseBenchmark(text: string, baseDir: string): Promise<Ben
|
|
|
96
109
|
cases.push(await resolveCase(caseValue, baseDir))
|
|
97
110
|
}
|
|
98
111
|
const pricing = parsed.pricing
|
|
112
|
+
const judge = parsed.judge
|
|
113
|
+
const replay = parsed.replay
|
|
99
114
|
return {
|
|
100
115
|
name: parsed.name,
|
|
101
116
|
model: parsed.model,
|
|
@@ -106,6 +121,12 @@ export async function parseBenchmark(text: string, baseDir: string): Promise<Ben
|
|
|
106
121
|
seed: parsed.seed,
|
|
107
122
|
cases,
|
|
108
123
|
...(pricing !== undefined ? { pricing } : {}),
|
|
124
|
+
...(judge !== undefined
|
|
125
|
+
? { judge: { provider: judge.provider, model: judge.model ?? parsed.model, ...(judge.rubric !== undefined ? { rubric: judge.rubric } : {}), maxScore: judge.maxScore } }
|
|
126
|
+
: {}),
|
|
127
|
+
...(replay !== undefined
|
|
128
|
+
? { replay: { dir: isAbsolute(replay.dir) ? replay.dir : resolve(baseDir, replay.dir) } }
|
|
129
|
+
: {}),
|
|
109
130
|
baseDir,
|
|
110
131
|
}
|
|
111
132
|
}
|
package/src/command.ts
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
import { Command } from 'commander'
|
|
11
11
|
import type { Context } from '@deepseek-ai/cordis'
|
|
12
12
|
import { parseCmdline } from '@deepseek-ai/dsh-cmdline'
|
|
13
|
+
import type { ImportFormat } from './import.ts'
|
|
13
14
|
|
|
14
15
|
/** What the eval app resolved from its command line. */
|
|
15
16
|
export type EvalStartupValues =
|
|
@@ -30,6 +31,13 @@ export type EvalStartupValues =
|
|
|
30
31
|
runPathA: string
|
|
31
32
|
runPathB: string
|
|
32
33
|
}
|
|
34
|
+
| {
|
|
35
|
+
kind: 'import'
|
|
36
|
+
format: ImportFormat
|
|
37
|
+
path: string
|
|
38
|
+
outPath: string
|
|
39
|
+
caseId: string
|
|
40
|
+
}
|
|
33
41
|
|
|
34
42
|
/** Options accepted by `eval run`. */
|
|
35
43
|
interface RunCommandOptions {
|
|
@@ -39,6 +47,12 @@ interface RunCommandOptions {
|
|
|
39
47
|
profile?: string
|
|
40
48
|
}
|
|
41
49
|
|
|
50
|
+
/** Options accepted by `eval import`. */
|
|
51
|
+
interface ImportCommandOptions {
|
|
52
|
+
out: string
|
|
53
|
+
caseId: string
|
|
54
|
+
}
|
|
55
|
+
|
|
42
56
|
/** Split a single `--dsh` value into argv on whitespace. */
|
|
43
57
|
function splitCommand(value: string | undefined): readonly string[] | undefined {
|
|
44
58
|
if (value === undefined) return undefined
|
|
@@ -98,6 +112,19 @@ export function evalCommand(publish: (values: EvalStartupValues) => void): Comma
|
|
|
98
112
|
.action((runPathA: string, runPathB: string) => {
|
|
99
113
|
publish({ kind: 'compare', runPathA, runPathB })
|
|
100
114
|
})
|
|
115
|
+
const importer = program.command('import').description('import an external harness session log as a run report')
|
|
116
|
+
importer
|
|
117
|
+
.argument('<format>', 'external harness format: codex or claude-code')
|
|
118
|
+
.argument('<session.jsonl>', 'path to the external session log')
|
|
119
|
+
.option('--out <path>', 'output run JSON path', 'imported-run.json')
|
|
120
|
+
.option('--case-id <id>', 'case id for the imported trial', 'imported')
|
|
121
|
+
.action((format: string, path: string, options: ImportCommandOptions) => {
|
|
122
|
+
if (format !== 'codex' && format !== 'claude-code') {
|
|
123
|
+
program.error('error: import format must be codex or claude-code')
|
|
124
|
+
return
|
|
125
|
+
}
|
|
126
|
+
publish({ kind: 'import', format, path, outPath: options.out, caseId: options.caseId })
|
|
127
|
+
})
|
|
101
128
|
return program
|
|
102
129
|
}
|
|
103
130
|
|