dsh-eval 0.2.0 → 0.3.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 +33 -3
- package/README.zh.md +69 -26
- package/lib/benchmark.js +123 -0
- package/lib/command.js +97 -0
- package/lib/compare.js +177 -0
- package/lib/import.js +318 -0
- package/lib/index.js +8 -1
- package/lib/judge.js +165 -0
- package/lib/metrics.js +196 -0
- package/lib/report.js +126 -0
- package/lib/runner.js +326 -0
- package/lib/trace.js +136 -0
- package/lib/types/command.d.ts +7 -0
- package/lib/types/import.d.ts +36 -0
- package/lib/types/index.d.ts +1 -1
- package/lib/types/types.d.ts +11 -0
- package/lib/types.js +8 -0
- package/package.json +25 -22
- package/src/benchmark.ts +9 -0
- package/src/command.ts +27 -0
- package/src/import.ts +327 -0
- package/src/index.ts +8 -1
- package/src/runner.ts +56 -16
- package/src/types.ts +12 -0
- package/LICENSE +0 -21
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ dsh eval report eval-run.json
|
|
|
13
13
|
dsh eval compare eval-v1.json eval-v2.json
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
`dsh eval` is a launcher alias for `--profile eval`; the eval profile composes `dsh-base` plus this bundle. Each trial spawns the benchmark-configured `dsh` command (default `dsh`) against the benchmark-configured profile (default `headless`) with a private temp workspace, an isolated `DSH_HOME`, and a patch overlay forcing plain-JSONL persistence and non-interactive workspace-write/never-approval permissions. The harvested primary session log becomes the trial's trace
|
|
16
|
+
`dsh eval` is a launcher alias for `--profile eval`; the eval profile composes `dsh-base` plus this bundle. Each trial spawns the benchmark-configured `dsh` command (default `dsh`) against the benchmark-configured profile (default `headless`) with a private temp workspace, an isolated `DSH_HOME`, and a patch overlay forcing plain-JSONL persistence and non-interactive workspace-write/never-approval permissions. The harvested primary session log becomes the trial's trace, and subagent child logs under the trial's `DSH_HOME` are merged into it before the metric fold.
|
|
17
17
|
|
|
18
18
|
## Benchmark document
|
|
19
19
|
|
|
@@ -82,7 +82,7 @@ starting when the host exposes no LLM chat seam.
|
|
|
82
82
|
|
|
83
83
|
## Metrics
|
|
84
84
|
|
|
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.
|
|
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.
|
|
86
86
|
|
|
87
87
|
Child session logs under the trial's DSH_HOME are merged into the trial trace
|
|
88
88
|
before the fold, so delegated subagent work counts toward steps, tokens, tool
|
|
@@ -98,6 +98,35 @@ hallucination rate.
|
|
|
98
98
|
|
|
99
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
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.
|
|
129
|
+
|
|
101
130
|
## Extension points
|
|
102
131
|
|
|
103
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.
|
|
@@ -114,7 +143,8 @@ None; this package neither assembles nor sends a provider request, so no request
|
|
|
114
143
|
|
|
115
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.
|
|
116
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.
|
|
117
|
-
- **Replay
|
|
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.
|
|
118
148
|
- **Direct-child timeout only** — a timed-out trial kills the direct dsh process; on Windows its descendants may survive.
|
|
119
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"`).
|
|
120
150
|
- **No atomic report write** — the run JSON is written in place; a crash mid-write can truncate the report.
|
package/README.zh.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# `dsh-eval`
|
|
2
2
|
|
|
3
|
-
English
|
|
3
|
+
[English](README.md) | 中文
|
|
4
4
|
|
|
5
|
-
基于 headless dsh profile 的 Agent 评测:一份 benchmark YAML
|
|
5
|
+
基于 headless dsh profile 的 Agent 评测:一份 benchmark YAML 文档,每个 case × trial 一个 headless dsh 子进程,从持久化 session 日志收获 trace,自动折叠指标,并产出 JSON/Markdown 运行报告。
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
本包同时是一个 bundle 和一个命令行应用。装进 profile 后即可运行评测:
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
10
|
dsh plugin --profile eval add dsh-eval
|
|
@@ -13,7 +13,7 @@ dsh eval report eval-run.json
|
|
|
13
13
|
dsh eval compare eval-v1.json eval-v2.json
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
`dsh eval` 是 `--profile eval`
|
|
16
|
+
`dsh eval` 是 `--profile eval` 的启动器别名,eval profile 由 `dsh-base` 加本 bundle 组成。每个 trial 以 benchmark 配置的 `dsh` 命令(默认 `dsh`)和配置的 profile(默认 `headless`)启动,带有独立的临时工作区、隔离的 `DSH_HOME`,以及一层强制纯 JSONL 持久化和非交互 workspace-write/never-approval 权限的补丁。收获的主 session 日志即该 trial 的 trace;该 trial `DSH_HOME` 下的子 agent 日志会在指标折叠前合并进来。
|
|
17
17
|
|
|
18
18
|
## Benchmark 文档
|
|
19
19
|
|
|
@@ -40,52 +40,95 @@ pricing:
|
|
|
40
40
|
outputUsdPerMTokens: 1.10
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
| 字段 | 默认 | 含义 |
|
|
43
|
+
| 字段 | 默认值 | 含义 |
|
|
46
44
|
|---|---|---|
|
|
47
|
-
| `name` | 必填 | Benchmark
|
|
45
|
+
| `name` | 必填 | Benchmark 名称,同时写入 run 记录的 `benchmark` 字段。 |
|
|
48
46
|
| `model` | 必填 | 用于定价查找与运行报告的模型 id。 |
|
|
49
47
|
| `profile` | `headless` | 每个 trial 启动的 dsh profile。 |
|
|
50
48
|
| `command` | `[dsh]` | dsh 启动器 argv。 |
|
|
51
49
|
| `trials` | `1` | 每个 case 的 trial 数。 |
|
|
52
|
-
| `timeoutMs` | `600000` | 每个 trial
|
|
53
|
-
| `seed` | `0` |
|
|
54
|
-
| `cases[].id` | 必填 |
|
|
55
|
-
| `cases[].prompt` / `cases[].promptFile` | 二选一 | 任务文本,内联或相对 benchmark
|
|
50
|
+
| `timeoutMs` | `600000` | 每个 trial 的超时;到期杀掉直接子进程。 |
|
|
51
|
+
| `seed` | `0` | 为将来的确定性配对比较预留。 |
|
|
52
|
+
| `cases[].id` | 必填 | 稳定的 case id。 |
|
|
53
|
+
| `cases[].prompt` / `cases[].promptFile` | 二选一 | 任务文本,内联或相对 benchmark 文件解析。 |
|
|
56
54
|
| `cases[].workspace` | 缺省 | 复制进每个 trial 的工作区树,相对或绝对路径。 |
|
|
57
|
-
| `
|
|
55
|
+
| `cases[].expected` | 缺省 | 脚本化评分:`tool` 是对记录到的工具调用名做子串匹配;`check` 是 agent 退出后在 trial 工作区运行的命令(退出码 0 = 任务成功)。填了就必须至少给一个。 |
|
|
56
|
+
| `pricing` | 缺省 | 以模型 id 为键的每百万 token 美元价;未配置的模型报 `costUsd: null`。 |
|
|
57
|
+
|
|
58
|
+
### Judge
|
|
59
|
+
|
|
60
|
+
`judge` 开启对最终答案与幻觉的 LLM 评审:
|
|
61
|
+
|
|
62
|
+
```yaml
|
|
63
|
+
judge:
|
|
64
|
+
provider: deepseek
|
|
65
|
+
model: deepseek-v4
|
|
66
|
+
rubric: Prefer correct, concise fixes.
|
|
67
|
+
maxScore: 10
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
| 字段 | 默认值 | 含义 |
|
|
71
|
+
|---|---|---|
|
|
72
|
+
| `provider` | `deepseek` | judge 调用走的 LLM provider 路由。 |
|
|
73
|
+
| `model` | benchmark 的 `model` | judge 使用的模型 id。 |
|
|
74
|
+
| `rubric` | 缺省 | 追加到评审 prompt 的任务评分标准。 |
|
|
75
|
+
| `maxScore` | `10` | 最终答案得分的上限。 |
|
|
76
|
+
|
|
77
|
+
judge 用 case 与合并后的 trace 构造一个严格 JSON 的 prompt。回复可解析时,trial 带上裁决字段(`finalAnswerScore`、`hallucination`、`rationale`);输出不可用或 chat 调用失败只记为空的裁决字段,绝不记为失败的 trial。配置了 judge 但宿主没有暴露 LLM chat seam 时,run 在启动前就失败。
|
|
58
78
|
|
|
59
79
|
## 指标
|
|
60
80
|
|
|
61
|
-
|
|
81
|
+
指标折叠直接从 session 日志计算自动指标:`turns`、`steps`、`toolCalls`、`toolResults`、`toolSuccess` 与 `toolSuccessRate`、`invalidToolCalls`(携带内部失败身份的 result)、`retries`(`llm/retry`)、互不重叠的 token 桶与合计、计费上下文 token、`llmMs`/`toolMs`/`ttftMs`/`latencyMs`,以及配置了定价后的 `costUsd`。脚本化评分增加每个 trial 的 `taskSuccess`(check 命令退出码 0)与 `toolSelectionAccuracy`(命中预期工具),并合并为 run 级比率。
|
|
82
|
+
|
|
83
|
+
trial `DSH_HOME` 下的子 session 日志在折叠前合并进 trial trace,因此委派给子 agent 的工作也计入 steps、token、工具调用、重试与延迟。judge 裁决增加每个 trial 的 `finalAnswerScore` 与 `hallucination`,并合并为 run 级平均分与幻觉率。
|
|
62
84
|
|
|
63
85
|
## 运行报告
|
|
64
86
|
|
|
65
|
-
`dsh eval run --out run.json` 每次运行写一份 JSON:benchmark 与模型标识、每个 trial 的结果与绝对 trace
|
|
87
|
+
`dsh eval run --out run.json` 每次运行写一份 JSON:benchmark 与模型标识、每个 trial 的结果与绝对 trace 路径、聚合指标(计数与耗时为均值,成功率为合并值)、合并后的评分比率。`dsh eval report run.json` 把 run 渲染为 Markdown。trial 工作区与 trace 保留在 run 的 `tempRoot`(私有临时目录)中且不会被删除,run 不再需要时自行清理。
|
|
66
88
|
|
|
67
89
|
## 对比
|
|
68
90
|
|
|
69
|
-
`dsh eval compare run-v1.json run-v2.json` 把两个 run 渲染成
|
|
91
|
+
`dsh eval compare run-v1.json run-v2.json` 把两个 run 渲染成 Markdown 表:benchmark/模型标识、完成的 trial 数、steps、工具/任务/工具选择成功率、无效调用、重试、token、成本与延迟,并给出带符号的 `B - A` 差值。当两个 run 完成的 case × trial 键完全一致时,表尾追加配对统计:trial 数、按第一个可用指标(任务成功、工具选择准确率、最终答案得分)的胜/负/平,以及 steps、token、judge 得分的 `B - A` 均值差。两个 run 的 `seed` 是配对的可追溯出处,不保证模型输出一致。
|
|
92
|
+
|
|
93
|
+
## 回放(keyless CI)
|
|
94
|
+
|
|
95
|
+
带 key 的 run 会把每个 trial 的 session 日志记录在其 `tempRoot` 下。把这些录制好的 trial 目录拷进 `replay.dir`,即可在无凭据的情况下重跑:被启动的 harness 会挂载 `@deepseek-ai/dsh-llm-replay`,从录制下来的 `assistant/chunk` 事件重建每一次模型流。
|
|
96
|
+
|
|
97
|
+
```yaml
|
|
98
|
+
replay:
|
|
99
|
+
dir: ./recorded
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
该目录下每个 trial 一棵树,命名为 `<caseId>-<trial>/`,子日志与其并列:`recorded/fix-tests-001-1/session.jsonl`。缺夹具会让该 trial 失败;`judge` 不能与 `replay` 出现在同一个 run 里。回放插件的 npm 发布版滞后于源码工作区,因此回放需要源码模式的 harness 检出。
|
|
103
|
+
|
|
104
|
+
## 导入外部 trace
|
|
105
|
+
|
|
106
|
+
`dsh eval import codex|claude-code <session.jsonl> --out run.json` 把 Codex 或 Claude Code 的 session 日志导入成一个单 trial 的 run,并折叠出指标:
|
|
107
|
+
|
|
108
|
+
- 每条 user 消息合成一个 turn(以及一个 step);
|
|
109
|
+
- assistant 文本、工具调用与工具结果映射进 trace 词汇表;
|
|
110
|
+
- 两种外部格式都不记录 token 用量,因此 token 与成本指标保持为零。
|
|
111
|
+
|
|
112
|
+
导入的 run 直接进入同一套 `report`/`compare` 流水线。
|
|
70
113
|
|
|
71
114
|
## 扩展点
|
|
72
115
|
|
|
73
|
-
|
|
116
|
+
目前只有一个消费者:`runBenchmark` 接收已加载的 benchmark 并返回 run 记录,report 模块负责持久化与渲染。judge 的 chat seam 由宿主注入(一个 dsh-llm 流),测试中用桩替换,因此测试套件保持 keyless。
|
|
74
117
|
|
|
75
118
|
## Model Experience
|
|
76
119
|
|
|
77
|
-
|
|
120
|
+
无。benchmark runner 只读取持久化的 session 日志并启动 headless 子进程,自身不注册 prompt 段落、工具 schema 或任何面向模型的行为。
|
|
78
121
|
|
|
79
122
|
#### KV Cache effect
|
|
80
123
|
|
|
81
|
-
|
|
124
|
+
无。本包既不组装也不发送 provider 请求,因此不存在需要保留或失效的请求前缀。
|
|
82
125
|
|
|
83
|
-
##
|
|
126
|
+
## 已知限制与延后项
|
|
84
127
|
|
|
85
|
-
- **
|
|
86
|
-
-
|
|
87
|
-
-
|
|
88
|
-
-
|
|
89
|
-
- **超时只杀直接子进程** ——
|
|
90
|
-
- **Windows 启动器命令** ——
|
|
128
|
+
- **judge 输出是尽力而为** —— judge chat 失败或回复无法解析时,裁决字段为空;judge 调用消耗的模型额度不计入 trial 的计量成本。
|
|
129
|
+
- **配对对比按现状配对** —— trial 按 case id 与 trial 序号配对;`seed` 是记录下来的出处,并不确定性保证模型输出一致,按实验组(arm)的排行榜尚未渲染。
|
|
130
|
+
- **回放按首次调用顺序绑定** —— 回放插件按首次调用顺序把录制脚本对应到实时 session,因此并发子 agent 的回放是非确定性的。
|
|
131
|
+
- **导入的 trace 没有 token 用量** —— Codex 与 Claude Code 日志不记录 provider 用量,导入的 run 报零 token 且无成本。
|
|
132
|
+
- **超时只杀直接子进程** —— 超时的 trial 只杀直接 dsh 进程;在 Windows 上它的后代进程可能存活。
|
|
133
|
+
- **Windows 启动器命令** —— 启动的子进程不经过 shell,`.cmd`/`.bat` shim 需要直接可执行文件或 `node <path>` 覆盖(`--dsh "node C:/.../apps/cli/lib/bin.js"`)。
|
|
91
134
|
- **报告写入非原子** —— run JSON 原地写入,写入中途崩溃可能截断报告。
|
package/lib/benchmark.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Benchmark document loading and validation for dsh-eval. YAML parses with
|
|
3
|
+
* js-yaml's safe loader; zod validates the parsed shape; prompt files and
|
|
4
|
+
* workspaces resolve against the benchmark file's directory.
|
|
5
|
+
*
|
|
6
|
+
* @module dsh-eval/benchmark
|
|
7
|
+
*/
|
|
8
|
+
import { readFile } from 'node:fs/promises';
|
|
9
|
+
import { dirname, isAbsolute, resolve } from 'node:path';
|
|
10
|
+
import { load } from 'js-yaml';
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
const judgeSchema = z.object({
|
|
13
|
+
provider: z.string().min(1).default('deepseek'),
|
|
14
|
+
model: z.string().min(1).optional(),
|
|
15
|
+
rubric: z.string().min(1).optional(),
|
|
16
|
+
maxScore: z.number().int().positive().default(10),
|
|
17
|
+
}).strict();
|
|
18
|
+
const replaySchema = z.object({
|
|
19
|
+
dir: z.string().min(1),
|
|
20
|
+
}).strict();
|
|
21
|
+
const pricingSchema = z.object({
|
|
22
|
+
inputUsdPerMTokens: z.number().nonnegative(),
|
|
23
|
+
cacheReadUsdPerMTokens: z.number().nonnegative(),
|
|
24
|
+
cacheWriteUsdPerMTokens: z.number().nonnegative(),
|
|
25
|
+
outputUsdPerMTokens: z.number().nonnegative(),
|
|
26
|
+
}).strict();
|
|
27
|
+
const benchmarkCaseSchema = z.object({
|
|
28
|
+
id: z.string().min(1),
|
|
29
|
+
prompt: z.string().min(1).optional(),
|
|
30
|
+
promptFile: z.string().min(1).optional(),
|
|
31
|
+
workspace: z.string().min(1).optional(),
|
|
32
|
+
expected: z.object({
|
|
33
|
+
tool: z.string().min(1).optional(),
|
|
34
|
+
check: z.string().min(1).optional(),
|
|
35
|
+
}).strict().refine(expectation => expectation.tool !== undefined || expectation.check !== undefined, { message: 'expected needs at least one of tool or check' }).optional(),
|
|
36
|
+
}).strict().refine(caseValue => (caseValue.prompt === undefined) !== (caseValue.promptFile === undefined), { message: 'each case needs exactly one of prompt or promptFile' });
|
|
37
|
+
const benchmarkSchema = z.object({
|
|
38
|
+
name: z.string().min(1),
|
|
39
|
+
model: z.string().min(1),
|
|
40
|
+
profile: z.string().min(1).default('headless'),
|
|
41
|
+
command: z.array(z.string().min(1)).default(['dsh']),
|
|
42
|
+
trials: z.number().int().positive().default(1),
|
|
43
|
+
timeoutMs: z.number().int().positive().default(600_000),
|
|
44
|
+
seed: z.number().int().default(0),
|
|
45
|
+
cases: z.array(benchmarkCaseSchema).min(1),
|
|
46
|
+
pricing: z.record(z.string().min(1), pricingSchema).optional(),
|
|
47
|
+
judge: judgeSchema.optional(),
|
|
48
|
+
replay: replaySchema.optional(),
|
|
49
|
+
}).strict();
|
|
50
|
+
/**
|
|
51
|
+
* Resolve one parsed case's prompt and workspace against the benchmark
|
|
52
|
+
* directory. Prompt files are read at load time so a run fails before any
|
|
53
|
+
* trial starts.
|
|
54
|
+
* @param parsed - the zod-validated case document.
|
|
55
|
+
* @param baseDir - absolute directory the benchmark file lives in.
|
|
56
|
+
* @returns the resolved runtime case.
|
|
57
|
+
*/
|
|
58
|
+
async function resolveCase(parsed, baseDir) {
|
|
59
|
+
const prompt = parsed.prompt
|
|
60
|
+
?? await readFile(resolve(baseDir, parsed.promptFile), 'utf8');
|
|
61
|
+
return {
|
|
62
|
+
id: parsed.id,
|
|
63
|
+
prompt,
|
|
64
|
+
...(parsed.workspace !== undefined
|
|
65
|
+
? { workspace: isAbsolute(parsed.workspace) ? parsed.workspace : resolve(baseDir, parsed.workspace) }
|
|
66
|
+
: {}),
|
|
67
|
+
...(parsed.expected !== undefined
|
|
68
|
+
? {
|
|
69
|
+
expected: {
|
|
70
|
+
...(parsed.expected.tool !== undefined ? { tool: parsed.expected.tool } : {}),
|
|
71
|
+
...(parsed.expected.check !== undefined ? { check: parsed.expected.check } : {}),
|
|
72
|
+
},
|
|
73
|
+
}
|
|
74
|
+
: {}),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Parse benchmark YAML text into a validated runtime document.
|
|
79
|
+
* @param text - the benchmark document's YAML source.
|
|
80
|
+
* @param baseDir - absolute directory used to resolve prompt and workspace paths.
|
|
81
|
+
* @returns the validated benchmark.
|
|
82
|
+
*/
|
|
83
|
+
export async function parseBenchmark(text, baseDir) {
|
|
84
|
+
const value = load(text);
|
|
85
|
+
if (typeof value !== 'object' || value === null) {
|
|
86
|
+
throw new Error('benchmark document must be a YAML mapping');
|
|
87
|
+
}
|
|
88
|
+
const parsed = benchmarkSchema.parse(value);
|
|
89
|
+
const cases = [];
|
|
90
|
+
for (const caseValue of parsed.cases) {
|
|
91
|
+
cases.push(await resolveCase(caseValue, baseDir));
|
|
92
|
+
}
|
|
93
|
+
const pricing = parsed.pricing;
|
|
94
|
+
const judge = parsed.judge;
|
|
95
|
+
const replay = parsed.replay;
|
|
96
|
+
return {
|
|
97
|
+
name: parsed.name,
|
|
98
|
+
model: parsed.model,
|
|
99
|
+
profile: parsed.profile,
|
|
100
|
+
command: parsed.command,
|
|
101
|
+
trials: parsed.trials,
|
|
102
|
+
timeoutMs: parsed.timeoutMs,
|
|
103
|
+
seed: parsed.seed,
|
|
104
|
+
cases,
|
|
105
|
+
...(pricing !== undefined ? { pricing } : {}),
|
|
106
|
+
...(judge !== undefined
|
|
107
|
+
? { judge: { provider: judge.provider, model: judge.model ?? parsed.model, ...(judge.rubric !== undefined ? { rubric: judge.rubric } : {}), maxScore: judge.maxScore } }
|
|
108
|
+
: {}),
|
|
109
|
+
...(replay !== undefined
|
|
110
|
+
? { replay: { dir: isAbsolute(replay.dir) ? replay.dir : resolve(baseDir, replay.dir) } }
|
|
111
|
+
: {}),
|
|
112
|
+
baseDir,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Load and validate a benchmark document from disk.
|
|
117
|
+
* @param path - path to the benchmark YAML file.
|
|
118
|
+
* @returns the validated benchmark.
|
|
119
|
+
*/
|
|
120
|
+
export async function loadBenchmark(path) {
|
|
121
|
+
const absolute = resolve(path);
|
|
122
|
+
return parseBenchmark(await readFile(absolute, 'utf8'), dirname(absolute));
|
|
123
|
+
}
|
package/lib/command.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The eval app's commander program: `run <benchmark.yaml>` executes a
|
|
3
|
+
* benchmark and writes its JSON report; `report <run.json>` renders one as
|
|
4
|
+
* markdown. Parsing follows the cmdline contract: the action publishes an
|
|
5
|
+
* ordinary service, and help or a rejection publishes nothing.
|
|
6
|
+
*
|
|
7
|
+
* @module dsh-eval/command
|
|
8
|
+
*/
|
|
9
|
+
import { Command } from 'commander';
|
|
10
|
+
import { parseCmdline } from '@deepseek-ai/dsh-cmdline';
|
|
11
|
+
/** Split a single `--dsh` value into argv on whitespace. */
|
|
12
|
+
function splitCommand(value) {
|
|
13
|
+
if (value === undefined)
|
|
14
|
+
return undefined;
|
|
15
|
+
const command = value.trim().split(/\s+/u).filter(part => part !== '');
|
|
16
|
+
return command.length === 0 ? undefined : command;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Build a fresh eval commander program. The root action rejects a bare
|
|
20
|
+
* invocation; the `run` and `report` actions hand the resolved values to the
|
|
21
|
+
* publish callback. The callback, not a Cordis service, carries the values
|
|
22
|
+
* because the plugin's own fiber is not yet active when the parse action runs
|
|
23
|
+
* and a strict `ctx.get` would miss a just-provided service.
|
|
24
|
+
* @param publish - receives the resolved invocation once a subcommand runs.
|
|
25
|
+
* @returns the configured program.
|
|
26
|
+
*/
|
|
27
|
+
export function evalCommand(publish) {
|
|
28
|
+
const program = new Command()
|
|
29
|
+
.name('dsh --profile eval')
|
|
30
|
+
.description('Run agent evaluations over headless dsh profiles and report trace-based metrics.')
|
|
31
|
+
.helpOption('-h, --help', 'show this help')
|
|
32
|
+
.action(() => {
|
|
33
|
+
program.error('error: eval needs a subcommand: run <benchmark.yaml> or report <run.json>');
|
|
34
|
+
});
|
|
35
|
+
const run = program.command('run').description('run a benchmark and write its JSON report');
|
|
36
|
+
run
|
|
37
|
+
.argument('<benchmark.yaml>', 'path to the benchmark document')
|
|
38
|
+
.option('--out <path>', 'output run JSON path', 'eval-run.json')
|
|
39
|
+
.option('--trials <n>', 'override the benchmark trials count', (value) => {
|
|
40
|
+
const parsed = Number(value);
|
|
41
|
+
if (!Number.isInteger(parsed) || parsed <= 0)
|
|
42
|
+
program.error('error: --trials must be a positive integer');
|
|
43
|
+
return parsed;
|
|
44
|
+
})
|
|
45
|
+
.option('--dsh <cmd>', 'override the dsh launcher command, space-separated')
|
|
46
|
+
.option('--profile <name>', 'override the spawned dsh profile')
|
|
47
|
+
.action((benchmarkPath, options) => {
|
|
48
|
+
const dshCommand = splitCommand(options.dsh);
|
|
49
|
+
publish({
|
|
50
|
+
kind: 'run',
|
|
51
|
+
benchmarkPath,
|
|
52
|
+
outPath: options.out,
|
|
53
|
+
...(options.trials !== undefined ? { trials: options.trials } : {}),
|
|
54
|
+
...(dshCommand !== undefined ? { dshCommand } : {}),
|
|
55
|
+
...(options.profile !== undefined ? { profile: options.profile } : {}),
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
const report = program.command('report').description('render a persisted run JSON as markdown');
|
|
59
|
+
report
|
|
60
|
+
.argument('<run.json>', 'path to a run report')
|
|
61
|
+
.action((runPath) => {
|
|
62
|
+
publish({ kind: 'report', runPath });
|
|
63
|
+
});
|
|
64
|
+
const compare = program.command('compare').description('compare two persisted run reports as a markdown table');
|
|
65
|
+
compare
|
|
66
|
+
.argument('<run-a.json>', 'baseline run report')
|
|
67
|
+
.argument('<run-b.json>', 'candidate run report')
|
|
68
|
+
.action((runPathA, runPathB) => {
|
|
69
|
+
publish({ kind: 'compare', runPathA, runPathB });
|
|
70
|
+
});
|
|
71
|
+
const importer = program.command('import').description('import an external harness session log as a run report');
|
|
72
|
+
importer
|
|
73
|
+
.argument('<format>', 'external harness format: codex or claude-code')
|
|
74
|
+
.argument('<session.jsonl>', 'path to the external session log')
|
|
75
|
+
.option('--out <path>', 'output run JSON path', 'imported-run.json')
|
|
76
|
+
.option('--case-id <id>', 'case id for the imported trial', 'imported')
|
|
77
|
+
.action((format, path, options) => {
|
|
78
|
+
if (format !== 'codex' && format !== 'claude-code') {
|
|
79
|
+
program.error('error: import format must be codex or claude-code');
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
publish({ kind: 'import', format, path, outPath: options.out, caseId: options.caseId });
|
|
83
|
+
});
|
|
84
|
+
return program;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Parse the launcher's inner arguments with the eval program and return what
|
|
88
|
+
* the invoked command published.
|
|
89
|
+
* @param ctx - plugin context carrying `cmdlineArgs` and `appExit`.
|
|
90
|
+
* @returns the resolved invocation, or undefined when help or an error exited.
|
|
91
|
+
*/
|
|
92
|
+
export function applyEval(ctx) {
|
|
93
|
+
let resolved;
|
|
94
|
+
const program = evalCommand((values) => { resolved = values; });
|
|
95
|
+
parseCmdline(ctx, program);
|
|
96
|
+
return resolved;
|
|
97
|
+
}
|
package/lib/compare.js
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-run comparison for dsh-eval: two persisted run reports become a row
|
|
3
|
+
* list of metric values and deltas, rendered as a markdown table.
|
|
4
|
+
*
|
|
5
|
+
* @module dsh-eval/compare
|
|
6
|
+
*/
|
|
7
|
+
/** Render a nullable number with a dash placeholder. */
|
|
8
|
+
function formatNumber(value, digits = 1) {
|
|
9
|
+
return value === null ? '–' : value.toFixed(digits);
|
|
10
|
+
}
|
|
11
|
+
/** Render a nullable rate as percent with a dash placeholder. */
|
|
12
|
+
function formatRate(value) {
|
|
13
|
+
return value === null ? '–' : `${(value * 100).toFixed(1)}%`;
|
|
14
|
+
}
|
|
15
|
+
/** Render a signed delta between two nullable numbers. */
|
|
16
|
+
function formatDelta(a, b, unit = '') {
|
|
17
|
+
if (a === null || b === null)
|
|
18
|
+
return '–';
|
|
19
|
+
const delta = unit === 'pp' ? (b - a) * 100 : b - a;
|
|
20
|
+
return `${delta >= 0 ? '+' : ''}${delta.toFixed(1)}${unit}`;
|
|
21
|
+
}
|
|
22
|
+
/** Read one trial's primary-metric outcome, or null when the trial lacks it. */
|
|
23
|
+
function metricOutcome(result, metric) {
|
|
24
|
+
if (metric === 'task success')
|
|
25
|
+
return result.grade?.taskSuccess ?? null;
|
|
26
|
+
if (metric === 'tool selection accuracy')
|
|
27
|
+
return result.grade?.toolSelectionAccuracy ?? null;
|
|
28
|
+
return result.judge?.finalAnswerScore ?? null;
|
|
29
|
+
}
|
|
30
|
+
/** Pick the first metric with data in every paired trial of a run. */
|
|
31
|
+
function pickMetric(pairs) {
|
|
32
|
+
for (const metric of ['task success', 'tool selection accuracy', 'final answer score']) {
|
|
33
|
+
if (pairs.every(pair => metricOutcome(pair.a, metric) !== null && metricOutcome(pair.b, metric) !== null)) {
|
|
34
|
+
return metric;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return 'final answer score';
|
|
38
|
+
}
|
|
39
|
+
/** Classify one pair: 1 for a B win, -1 for an A win, 0 for a tie. */
|
|
40
|
+
function pairSign(aValue, bValue) {
|
|
41
|
+
if (aValue === null || bValue === null)
|
|
42
|
+
return 0;
|
|
43
|
+
if (typeof aValue === 'boolean' || typeof bValue === 'boolean') {
|
|
44
|
+
const aBool = aValue === true;
|
|
45
|
+
const bBool = bValue === true;
|
|
46
|
+
return bBool === aBool ? 0 : (bBool ? 1 : -1);
|
|
47
|
+
}
|
|
48
|
+
return bValue > aValue ? 1 : (bValue < aValue ? -1 : 0);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Pair both runs' trials by case id and trial index and compute win/lose/tie
|
|
52
|
+
* plus mean deltas. Trials are paired as-is; the runs' `seed` is recorded
|
|
53
|
+
* provenance for the pairing, not a guarantee of identical model output.
|
|
54
|
+
* @param a - the baseline run.
|
|
55
|
+
* @param b - the candidate run.
|
|
56
|
+
* @returns paired statistics, or null when no trial is completed in both runs.
|
|
57
|
+
*/
|
|
58
|
+
export function pairedCompare(a, b) {
|
|
59
|
+
const byKey = new Map();
|
|
60
|
+
for (const result of b.cases) {
|
|
61
|
+
if (result.status === 'completed')
|
|
62
|
+
byKey.set(`${result.caseId}\u0000${result.trial}`, result);
|
|
63
|
+
}
|
|
64
|
+
const pairs = [];
|
|
65
|
+
for (const result of a.cases) {
|
|
66
|
+
if (result.status !== 'completed')
|
|
67
|
+
continue;
|
|
68
|
+
const match = byKey.get(`${result.caseId}\u0000${result.trial}`);
|
|
69
|
+
if (match !== undefined)
|
|
70
|
+
pairs.push({ a: result, b: match });
|
|
71
|
+
}
|
|
72
|
+
if (pairs.length === 0)
|
|
73
|
+
return null;
|
|
74
|
+
const primaryMetric = pickMetric(pairs);
|
|
75
|
+
let wins = 0;
|
|
76
|
+
let losses = 0;
|
|
77
|
+
let ties = 0;
|
|
78
|
+
const stepDeltas = [];
|
|
79
|
+
const tokenDeltas = [];
|
|
80
|
+
const scoreDeltas = [];
|
|
81
|
+
for (const pair of pairs) {
|
|
82
|
+
const sign = pairSign(metricOutcome(pair.a, primaryMetric), metricOutcome(pair.b, primaryMetric));
|
|
83
|
+
if (sign > 0)
|
|
84
|
+
wins += 1;
|
|
85
|
+
else if (sign < 0)
|
|
86
|
+
losses += 1;
|
|
87
|
+
else
|
|
88
|
+
ties += 1;
|
|
89
|
+
const aMetrics = pair.a.metrics;
|
|
90
|
+
const bMetrics = pair.b.metrics;
|
|
91
|
+
if (aMetrics !== undefined && bMetrics !== undefined) {
|
|
92
|
+
stepDeltas.push(bMetrics.steps - aMetrics.steps);
|
|
93
|
+
tokenDeltas.push(bMetrics.totalTokens - aMetrics.totalTokens);
|
|
94
|
+
}
|
|
95
|
+
const aScore = pair.a.judge?.finalAnswerScore;
|
|
96
|
+
const bScore = pair.b.judge?.finalAnswerScore;
|
|
97
|
+
if (aScore !== null && aScore !== undefined && bScore !== null && bScore !== undefined) {
|
|
98
|
+
scoreDeltas.push(bScore - aScore);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const mean = (values) => values.length === 0 ? null : values.reduce((total, value) => total + value, 0) / values.length;
|
|
102
|
+
return {
|
|
103
|
+
pairs: pairs.length,
|
|
104
|
+
wins,
|
|
105
|
+
losses,
|
|
106
|
+
ties,
|
|
107
|
+
primaryMetric,
|
|
108
|
+
meanStepsDelta: mean(stepDeltas),
|
|
109
|
+
meanTokensDelta: mean(tokenDeltas),
|
|
110
|
+
meanScoreDelta: mean(scoreDeltas),
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Build the comparison rows between two runs.
|
|
115
|
+
* @param a - the baseline run.
|
|
116
|
+
* @param b - the candidate run.
|
|
117
|
+
* @returns the row list in display order.
|
|
118
|
+
*/
|
|
119
|
+
export function compareRuns(a, b) {
|
|
120
|
+
const completed = (run) => run.cases.filter(result => result.status === 'completed').length;
|
|
121
|
+
const rates = (selector, label, unit) => {
|
|
122
|
+
const aValue = selector(a);
|
|
123
|
+
const bValue = selector(b);
|
|
124
|
+
return {
|
|
125
|
+
metric: label,
|
|
126
|
+
a: unit === 'pp' ? formatRate(aValue) : formatNumber(aValue),
|
|
127
|
+
b: unit === 'pp' ? formatRate(bValue) : formatNumber(bValue),
|
|
128
|
+
delta: unit === 'pp' ? formatDelta(aValue, bValue, 'pp') : formatDelta(aValue, bValue),
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
const numeric = (selector, label) => rates(selector, label, '');
|
|
132
|
+
const rows = [
|
|
133
|
+
{ metric: 'benchmark', a: a.benchmark, b: b.benchmark, delta: '–' },
|
|
134
|
+
{ metric: 'model', a: a.model, b: b.model, delta: '–' },
|
|
135
|
+
numeric(run => completed(run), 'completed trials'),
|
|
136
|
+
numeric(run => run.aggregate?.steps ?? null, 'steps/trial'),
|
|
137
|
+
rates(run => run.aggregate?.toolSuccessRate ?? null, 'tool success', 'pp'),
|
|
138
|
+
rates(run => run.grading?.taskSuccessRate ?? null, 'task success', 'pp'),
|
|
139
|
+
rates(run => run.grading?.toolSelectionAccuracyRate ?? null, 'tool selection accuracy', 'pp'),
|
|
140
|
+
numeric(run => run.aggregate?.invalidToolCalls ?? null, 'invalid tool calls/trial'),
|
|
141
|
+
numeric(run => run.aggregate?.retries ?? null, 'retries/trial'),
|
|
142
|
+
numeric(run => run.aggregate?.totalTokens ?? null, 'tokens/trial'),
|
|
143
|
+
numeric(run => run.aggregate?.costUsd ?? null, 'cost/trial (USD)'),
|
|
144
|
+
numeric(run => run.aggregate?.latencyMs ?? null, 'latency/trial (ms)'),
|
|
145
|
+
];
|
|
146
|
+
const paired = pairedCompare(a, b);
|
|
147
|
+
if (paired !== null) {
|
|
148
|
+
rows.push({ metric: 'paired trials', a: String(paired.pairs), b: String(paired.pairs), delta: '–' }, {
|
|
149
|
+
metric: `paired ${paired.primaryMetric} (B/A/ties)`,
|
|
150
|
+
a: `${paired.wins}/${paired.losses}/${paired.ties}`,
|
|
151
|
+
b: '–',
|
|
152
|
+
delta: '–',
|
|
153
|
+
}, ...(paired.meanStepsDelta === null ? [] : [{
|
|
154
|
+
metric: 'paired steps delta (B-A)', a: '–', b: '–', delta: formatDelta(0, paired.meanStepsDelta),
|
|
155
|
+
}]), ...(paired.meanTokensDelta === null ? [] : [{
|
|
156
|
+
metric: 'paired tokens delta (B-A)', a: '–', b: '–', delta: formatDelta(0, paired.meanTokensDelta),
|
|
157
|
+
}]), ...(paired.meanScoreDelta === null ? [] : [{
|
|
158
|
+
metric: 'paired final-answer delta (B-A)', a: '–', b: '–', delta: formatDelta(0, paired.meanScoreDelta),
|
|
159
|
+
}]));
|
|
160
|
+
}
|
|
161
|
+
return rows;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Render comparison rows as a markdown table.
|
|
165
|
+
* @param rows - the rows from {@link compareRuns}.
|
|
166
|
+
* @returns the markdown text.
|
|
167
|
+
*/
|
|
168
|
+
export function renderCompareMarkdown(rows) {
|
|
169
|
+
return [
|
|
170
|
+
'# Compare',
|
|
171
|
+
'',
|
|
172
|
+
'| metric | run A | run B | delta (B - A) |',
|
|
173
|
+
'|---|---|---|---|',
|
|
174
|
+
...rows.map(row => `| ${row.metric} | ${row.a} | ${row.b} | ${row.delta} |`),
|
|
175
|
+
'',
|
|
176
|
+
].join('\n');
|
|
177
|
+
}
|