niceeval 0.6.1 → 0.7.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.
Files changed (378) hide show
  1. package/INDEX.md +23 -23
  2. package/README.zh.md +6 -6
  3. package/dist/agents/types.d.ts +69 -7
  4. package/dist/context/types.d.ts +32 -12
  5. package/dist/i18n/en.d.ts +54 -0
  6. package/dist/i18n/zh-CN.d.ts +57 -3
  7. package/dist/o11y/types.d.ts +16 -2
  8. package/dist/report/aggregate.d.ts +32 -24
  9. package/dist/report/aggregate.js +158 -50
  10. package/dist/report/built-in/index.d.ts +2 -0
  11. package/dist/report/built-in/index.js +8 -0
  12. package/dist/report/components.d.ts +93 -160
  13. package/dist/report/components.js +377 -114
  14. package/dist/report/compute.d.ts +87 -81
  15. package/dist/report/compute.js +597 -417
  16. package/dist/report/flag.d.ts +32 -6
  17. package/dist/report/flag.js +92 -4
  18. package/dist/report/format.d.ts +19 -11
  19. package/dist/report/format.js +30 -13
  20. package/dist/report/index.d.ts +16 -16
  21. package/dist/report/index.js +20 -21
  22. package/dist/report/load.js +3 -2
  23. package/dist/report/locale.d.ts +57 -33
  24. package/dist/report/locale.js +122 -56
  25. package/dist/report/metrics.d.ts +23 -4
  26. package/dist/report/metrics.js +110 -25
  27. package/dist/report/primitives.d.ts +48 -15
  28. package/dist/report/primitives.js +135 -26
  29. package/dist/report/react/AttemptList.d.ts +9 -7
  30. package/dist/report/react/AttemptList.js +17 -10
  31. package/dist/report/react/DeltaTable.js +19 -18
  32. package/dist/report/react/EvalList.d.ts +4 -4
  33. package/dist/report/react/EvalList.js +0 -0
  34. package/dist/report/react/ExperimentComparison.d.ts +10 -0
  35. package/dist/report/react/ExperimentComparison.js +12 -0
  36. package/dist/report/react/ExperimentList.d.ts +4 -3
  37. package/dist/report/react/ExperimentList.js +17 -18
  38. package/dist/report/react/MetricBars.js +5 -4
  39. package/dist/report/react/MetricLine.js +12 -5
  40. package/dist/report/react/MetricMatrix.js +1 -1
  41. package/dist/report/react/MetricScatter.js +59 -28
  42. package/dist/report/react/MetricTable.js +2 -12
  43. package/dist/report/react/ScopeSummary.d.ts +10 -0
  44. package/dist/report/react/ScopeSummary.js +17 -0
  45. package/dist/report/react/Scoreboard.js +6 -6
  46. package/dist/report/react/cell.js +2 -2
  47. package/dist/report/react/chart-math.d.ts +23 -6
  48. package/dist/report/react/chart-math.js +71 -19
  49. package/dist/report/react/fixtures.d.ts +5 -9
  50. package/dist/report/react/fixtures.js +110 -147
  51. package/dist/report/react/index.d.ts +15 -5
  52. package/dist/report/react/index.js +18 -7
  53. package/dist/report/report.d.ts +137 -16
  54. package/dist/report/report.js +259 -28
  55. package/dist/report/text/faces.d.ts +17 -19
  56. package/dist/report/text/faces.js +253 -184
  57. package/dist/report/text/plot.js +1 -1
  58. package/dist/report/text/table.js +38 -7
  59. package/dist/report/tree.d.ts +90 -40
  60. package/dist/report/tree.js +252 -94
  61. package/dist/report/types.d.ts +247 -284
  62. package/dist/report/types.js +4 -3
  63. package/dist/report/web.d.ts +21 -5
  64. package/dist/report/web.js +42 -16
  65. package/dist/results/select.d.ts +38 -16
  66. package/dist/results/select.js +73 -25
  67. package/dist/results/types.d.ts +49 -14
  68. package/dist/runner/feedback/sink.d.ts +110 -0
  69. package/dist/runner/types.d.ts +513 -22
  70. package/dist/sandbox/docker.d.ts +23 -2
  71. package/dist/sandbox/e2b.d.ts +15 -1
  72. package/dist/sandbox/errors.d.ts +30 -3
  73. package/dist/sandbox/io-retry.d.ts +17 -0
  74. package/dist/sandbox/registry.d.ts +2 -0
  75. package/dist/sandbox/resolve.d.ts +18 -5
  76. package/dist/sandbox/retry.d.ts +11 -1
  77. package/dist/sandbox/types.d.ts +39 -5
  78. package/dist/sandbox/vercel.d.ts +7 -1
  79. package/dist/scoring/coverage.d.ts +30 -0
  80. package/dist/scoring/display.d.ts +21 -0
  81. package/dist/scoring/display.js +120 -0
  82. package/dist/scoring/types.d.ts +103 -20
  83. package/dist/shared/aggregate.d.ts +4 -2
  84. package/dist/shared/aggregate.js +8 -7
  85. package/dist/shared/types.d.ts +28 -0
  86. package/dist/tty-line.d.ts +0 -4
  87. package/dist/util.d.ts +23 -0
  88. package/docs-site/zh/README.md +44 -0
  89. package/docs-site/zh/examples/ai-agent-application.mdx +63 -0
  90. package/docs-site/zh/examples/coding-agent-extensions.mdx +57 -0
  91. package/docs-site/zh/examples/index.mdx +50 -0
  92. package/docs-site/zh/{concepts → explanation}/adapter.mdx +31 -13
  93. package/docs-site/zh/{concepts → explanation}/assert.mdx +7 -7
  94. package/docs-site/zh/{concepts → explanation}/drive.mdx +8 -8
  95. package/docs-site/zh/{concepts → explanation}/evals.mdx +4 -4
  96. package/docs-site/zh/{concepts → explanation}/experiment.mdx +8 -8
  97. package/docs-site/zh/{concepts → explanation}/hitl.mdx +8 -8
  98. package/docs-site/zh/{concepts → explanation}/judge.mdx +5 -5
  99. package/docs-site/zh/{concepts → explanation}/overview.mdx +11 -11
  100. package/docs-site/zh/{guides → explanation}/runner.mdx +18 -8
  101. package/docs-site/zh/{concepts → explanation}/tier.mdx +6 -6
  102. package/docs-site/zh/{guides → how-to}/agent-feedback-loop.mdx +35 -33
  103. package/docs-site/zh/{guides → how-to}/authoring.mdx +35 -2
  104. package/docs-site/zh/{guides → how-to}/ci-integration.mdx +23 -12
  105. package/docs-site/zh/{guides → how-to}/connect-otel.mdx +6 -6
  106. package/docs-site/zh/{guides → how-to}/connect-your-agent.mdx +47 -21
  107. package/docs-site/zh/{guides → how-to}/custom-reports.mdx +34 -39
  108. package/docs-site/zh/{guides → how-to}/dataset-fanout.mdx +25 -3
  109. package/docs-site/zh/{guides → how-to}/experiments.mdx +12 -5
  110. package/docs-site/zh/how-to/publish-report.mdx +105 -0
  111. package/docs-site/zh/{guides → how-to}/reporters.mdx +2 -2
  112. package/docs-site/zh/{guides → how-to}/sandbox-agent.mdx +56 -7
  113. package/docs-site/zh/how-to/sandbox-providers.mdx +350 -0
  114. package/docs-site/zh/{guides → how-to}/scoring-guide.mdx +4 -4
  115. package/docs-site/zh/{guides → how-to}/viewing-results.mdx +82 -39
  116. package/docs-site/zh/{guides → how-to}/write-experiment.mdx +6 -4
  117. package/docs-site/zh/{guides → how-to}/write-send.mdx +30 -14
  118. package/docs-site/zh/index.mdx +24 -26
  119. package/docs-site/zh/introduction.mdx +8 -8
  120. package/docs-site/zh/reference/builtin-agents.mdx +32 -5
  121. package/docs-site/zh/reference/capabilities.mdx +8 -8
  122. package/docs-site/zh/reference/cli.mdx +40 -12
  123. package/docs-site/zh/reference/define-agent.mdx +58 -5
  124. package/docs-site/zh/reference/define-config.mdx +1 -1
  125. package/docs-site/zh/reference/define-eval.mdx +42 -9
  126. package/docs-site/zh/reference/events.mdx +3 -3
  127. package/docs-site/zh/reference/expect.mdx +26 -1
  128. package/docs-site/zh/{guides → reference}/official-adapters.mdx +32 -8
  129. package/docs-site/zh/{guides → reference}/report-components.mdx +45 -33
  130. package/docs-site/zh/{guides → reference}/results-data.mdx +21 -13
  131. package/docs-site/zh/troubleshooting/debug-sandbox.mdx +57 -0
  132. package/docs-site/zh/troubleshooting/debugging.mdx +212 -0
  133. package/docs-site/zh/{quickstart.mdx → tutorials/quickstart.mdx} +5 -17
  134. package/package.json +10 -2
  135. package/src/agents/ai-sdk-otel.test.ts +1 -0
  136. package/src/agents/ai-sdk.test.ts +3 -0
  137. package/src/agents/ai-sdk.ts +3 -0
  138. package/src/agents/bub-install-spec.test.ts +34 -0
  139. package/src/agents/bub-install-spec.ts +32 -0
  140. package/src/agents/bub.ts +31 -32
  141. package/src/agents/claude-code.test.ts +130 -9
  142. package/src/agents/claude-code.ts +76 -4
  143. package/src/agents/codex.test.ts +189 -40
  144. package/src/agents/codex.ts +155 -14
  145. package/src/agents/coding-cli-versions.test.ts +15 -0
  146. package/src/agents/coding-cli-versions.ts +3 -0
  147. package/src/agents/index.ts +13 -2
  148. package/src/agents/langgraph.test.ts +204 -0
  149. package/src/agents/langgraph.ts +495 -0
  150. package/src/agents/marketplace.ts +85 -0
  151. package/src/agents/native-config.test.ts +179 -0
  152. package/src/agents/native-config.ts +267 -0
  153. package/src/agents/openai-compat.test.ts +1 -0
  154. package/src/agents/openai-compat.ts +1 -1
  155. package/src/agents/openclaw.test.ts +31 -0
  156. package/src/agents/openclaw.ts +171 -0
  157. package/src/agents/plugin-config.test.ts +1 -0
  158. package/src/agents/sdk-streams.test.ts +79 -0
  159. package/src/agents/sdk-streams.ts +55 -10
  160. package/src/agents/skills.test.ts +1 -0
  161. package/src/agents/streaming.test.ts +3 -9
  162. package/src/agents/streaming.ts +2 -2
  163. package/src/agents/types.ts +71 -8
  164. package/src/agents/ui-message-stream.test.ts +3 -0
  165. package/src/cli.ts +446 -124
  166. package/src/context/context.test.ts +51 -12
  167. package/src/context/context.ts +162 -30
  168. package/src/context/session.test.ts +2 -1
  169. package/src/context/session.ts +115 -7
  170. package/src/context/types.ts +30 -12
  171. package/src/define.test.ts +13 -8
  172. package/src/define.ts +25 -4
  173. package/src/expect/index.ts +53 -23
  174. package/src/i18n/en.ts +81 -17
  175. package/src/i18n/zh-CN.ts +80 -17
  176. package/src/o11y/cost.test.ts +1 -0
  177. package/src/o11y/execution-tree.test.ts +1 -20
  178. package/src/o11y/otlp/mappers/claude-code.test.ts +1 -0
  179. package/src/o11y/otlp/parse.test.ts +1 -0
  180. package/src/o11y/otlp/turn-otel.test.ts +1 -0
  181. package/src/o11y/parsers/bub.test.ts +1 -0
  182. package/src/o11y/parsers/claude-code.test.ts +1 -34
  183. package/src/o11y/parsers/openclaw.test.ts +154 -0
  184. package/src/o11y/parsers/openclaw.ts +310 -0
  185. package/src/o11y/prices.json +746 -311
  186. package/src/o11y/tool-names.test.ts +1 -0
  187. package/src/o11y/types.ts +16 -2
  188. package/src/report/aggregate.ts +178 -61
  189. package/src/report/built-in/index.tsx +9 -0
  190. package/src/report/components.tsx +625 -279
  191. package/src/report/compute.ts +723 -491
  192. package/src/report/dual-render.test.tsx +741 -1024
  193. package/src/report/flag.ts +104 -12
  194. package/src/report/format.ts +32 -12
  195. package/src/report/index.ts +119 -46
  196. package/src/report/load.ts +3 -2
  197. package/src/report/locale.ts +136 -65
  198. package/src/report/metrics.ts +108 -25
  199. package/src/report/primitives.tsx +196 -45
  200. package/src/report/react/AttemptList.tsx +30 -43
  201. package/src/report/react/DeltaTable.tsx +63 -45
  202. package/src/report/react/EvalList.tsx +0 -0
  203. package/src/report/react/ExperimentComparison.tsx +73 -0
  204. package/src/report/react/ExperimentList.tsx +50 -32
  205. package/src/report/react/MetricBars.tsx +5 -4
  206. package/src/report/react/MetricLine.tsx +13 -8
  207. package/src/report/react/MetricMatrix.tsx +2 -2
  208. package/src/report/react/MetricScatter.tsx +86 -34
  209. package/src/report/react/MetricTable.tsx +4 -76
  210. package/src/report/react/ScopeSummary.tsx +86 -0
  211. package/src/report/react/Scoreboard.tsx +28 -10
  212. package/src/report/react/cell.tsx +2 -2
  213. package/src/report/react/chart-math.test.ts +85 -0
  214. package/src/report/react/chart-math.ts +101 -22
  215. package/src/report/react/enhance.js +89 -5
  216. package/src/report/react/fixtures.ts +114 -154
  217. package/src/report/react/index.tsx +24 -39
  218. package/src/report/react/render.test.tsx +138 -158
  219. package/src/report/react/styles.css +243 -82
  220. package/src/report/report.test.ts +779 -841
  221. package/src/report/report.ts +423 -41
  222. package/src/report/text/faces.ts +290 -193
  223. package/src/report/text/plot.ts +1 -1
  224. package/src/report/text/table.ts +44 -7
  225. package/src/report/tree.ts +362 -104
  226. package/src/report/types.ts +261 -271
  227. package/src/report/web.ts +63 -20
  228. package/src/results/annotated-source.test.ts +62 -9
  229. package/src/results/annotated-source.ts +64 -6
  230. package/src/results/attempt-evidence.test.ts +13 -11
  231. package/src/results/attempt-evidence.ts +20 -13
  232. package/src/results/attempt-source.ts +6 -3
  233. package/src/results/copy.ts +150 -60
  234. package/src/results/host-equivalence.test.ts +34 -20
  235. package/src/results/index.ts +12 -4
  236. package/src/results/locator.test.ts +1 -22
  237. package/src/results/open.ts +15 -5
  238. package/src/results/publish.ts +149 -0
  239. package/src/results/results.test.ts +89 -54
  240. package/src/results/select.ts +104 -34
  241. package/src/results/truncate.ts +90 -0
  242. package/src/results/types.ts +43 -14
  243. package/src/results/writer.ts +31 -13
  244. package/src/runner/attempt.test.ts +138 -7
  245. package/src/runner/attempt.ts +603 -104
  246. package/src/runner/discover.test.ts +47 -0
  247. package/src/runner/discover.ts +36 -2
  248. package/src/runner/eval-source.test.ts +1 -27
  249. package/src/runner/feedback/agent.test.ts +504 -0
  250. package/src/runner/feedback/agent.ts +409 -0
  251. package/src/runner/feedback/ci.test.ts +562 -0
  252. package/src/runner/feedback/ci.ts +401 -0
  253. package/src/runner/feedback/coordinator.test.ts +317 -0
  254. package/src/runner/feedback/coordinator.ts +397 -0
  255. package/src/runner/feedback/failure.ts +40 -0
  256. package/src/runner/feedback/human.test.ts +616 -0
  257. package/src/runner/feedback/human.ts +535 -0
  258. package/src/runner/feedback/index.ts +66 -0
  259. package/src/runner/feedback/io.ts +78 -0
  260. package/src/runner/feedback/profile.test.ts +50 -0
  261. package/src/runner/feedback/profile.ts +58 -0
  262. package/src/runner/feedback/reducer.test.ts +395 -0
  263. package/src/runner/feedback/reducer.ts +260 -0
  264. package/src/runner/feedback/renderer.ts +82 -0
  265. package/src/runner/feedback/sink.ts +203 -0
  266. package/src/runner/feedback/testing.ts +106 -0
  267. package/src/runner/ledger.test.ts +230 -0
  268. package/src/runner/ledger.ts +329 -0
  269. package/src/runner/report.test.ts +128 -3
  270. package/src/runner/report.ts +33 -9
  271. package/src/runner/reporters/artifacts.ts +8 -2
  272. package/src/runner/reporters/braintrust.test.ts +8 -7
  273. package/src/runner/reporters/braintrust.ts +9 -2
  274. package/src/runner/reporters/index.ts +2 -2
  275. package/src/runner/reporters/json.test.ts +162 -0
  276. package/src/runner/reporters/json.ts +35 -8
  277. package/src/runner/reporters/shared.ts +1 -5
  278. package/src/runner/run.test.ts +760 -3
  279. package/src/runner/run.ts +243 -37
  280. package/src/runner/sandbox-prep.ts +3 -42
  281. package/src/runner/timing.ts +158 -0
  282. package/src/runner/types.ts +518 -22
  283. package/src/sandbox/checkpoint.test.ts +55 -0
  284. package/src/sandbox/checkpoint.ts +29 -8
  285. package/src/sandbox/cli-commands.ts +407 -0
  286. package/src/sandbox/docker.ts +115 -16
  287. package/src/sandbox/e2b-agent-template.test.ts +56 -0
  288. package/src/sandbox/e2b-agent-template.ts +94 -0
  289. package/src/sandbox/e2b.ts +74 -9
  290. package/src/sandbox/errors.ts +111 -4
  291. package/src/sandbox/index.ts +2 -0
  292. package/src/sandbox/io-retry.test.ts +58 -0
  293. package/src/sandbox/io-retry.ts +45 -0
  294. package/src/sandbox/keep-registry.test.ts +86 -0
  295. package/src/sandbox/keep-registry.ts +142 -0
  296. package/src/sandbox/keep.ts +178 -0
  297. package/src/sandbox/paths.test.ts +1 -0
  298. package/src/sandbox/paths.ts +19 -8
  299. package/src/sandbox/registry.ts +20 -3
  300. package/src/sandbox/resolve.ts +76 -11
  301. package/src/sandbox/retry.test.ts +70 -0
  302. package/src/sandbox/retry.ts +46 -4
  303. package/src/sandbox/types.ts +44 -6
  304. package/src/sandbox/vercel.ts +43 -20
  305. package/src/scoring/collector.ts +60 -17
  306. package/src/scoring/coverage.ts +95 -0
  307. package/src/scoring/diff.ts +81 -0
  308. package/src/scoring/display.test.ts +121 -0
  309. package/src/scoring/display.ts +133 -0
  310. package/src/scoring/evidence.test.ts +189 -0
  311. package/src/scoring/judge.test.ts +142 -0
  312. package/src/scoring/judge.ts +15 -18
  313. package/src/scoring/scoped.ts +217 -50
  314. package/src/scoring/types.ts +117 -20
  315. package/src/scoring/verdict.ts +16 -4
  316. package/src/shared/aggregate.ts +8 -6
  317. package/src/shared/types.ts +31 -0
  318. package/src/show/compose.ts +50 -67
  319. package/src/show/index.ts +127 -56
  320. package/src/show/render.ts +662 -131
  321. package/src/show/report-host.test.ts +188 -0
  322. package/src/show/report-host.ts +375 -0
  323. package/src/show/show.test.ts +320 -54
  324. package/src/tty-line.ts +8 -26
  325. package/src/util.test.ts +1 -0
  326. package/src/util.ts +41 -0
  327. package/src/view/app/App.test.tsx +69 -0
  328. package/src/view/app/App.tsx +144 -48
  329. package/src/view/app/components/AttemptModal.tsx +423 -11
  330. package/src/view/app/components/CodeView.tsx +41 -14
  331. package/src/view/app/components/CopyControls.tsx +2 -2
  332. package/src/view/app/i18n.ts +37 -17
  333. package/src/view/app/lib/attempt-route.test.ts +1 -0
  334. package/src/view/app/lib/verdict.ts +7 -9
  335. package/src/view/app/main.tsx +13 -8
  336. package/src/view/app/pages/{RunsPage.tsx → AttemptsPage.tsx} +6 -6
  337. package/src/view/app/types.ts +4 -1
  338. package/src/view/artifact-serving.test.ts +2 -1
  339. package/src/view/client-dist/app.css +1 -1
  340. package/src/view/client-dist/app.js +17 -17
  341. package/src/view/data.test.ts +10 -3
  342. package/src/view/data.ts +155 -49
  343. package/src/view/index.ts +56 -41
  344. package/src/view/server.ts +37 -15
  345. package/src/view/shared/types.ts +34 -5
  346. package/src/view/styles.css +227 -0
  347. package/src/view/view-report.test.ts +167 -62
  348. package/dist/report/built-ins/experiment-comparison.d.ts +0 -1
  349. package/dist/report/built-ins/experiment-comparison.js +0 -13
  350. package/dist/report/built-ins/index.d.ts +0 -1
  351. package/dist/report/built-ins/index.js +0 -2
  352. package/dist/report/react/GroupSummary.d.ts +0 -8
  353. package/dist/report/react/GroupSummary.js +0 -8
  354. package/dist/report/react/RunOverview.d.ts +0 -8
  355. package/dist/report/react/RunOverview.js +0 -12
  356. package/docs-site/zh/example/ai-agent-application.mdx +0 -152
  357. package/docs-site/zh/example/claude-code-codex-plugin.mdx +0 -167
  358. package/docs-site/zh/example/claude-code-codex-skill.mdx +0 -152
  359. package/docs-site/zh/example/showcase.mdx +0 -39
  360. package/docs-site/zh/guides/publish-report.mdx +0 -91
  361. package/docs-site/zh/guides/sandbox-providers.mdx +0 -102
  362. package/src/report/built-in-user-parity.test.tsx +0 -640
  363. package/src/report/built-ins/experiment-comparison.tsx +0 -19
  364. package/src/report/built-ins/index.ts +0 -2
  365. package/src/report/react/GroupSummary.tsx +0 -66
  366. package/src/report/react/RunOverview.tsx +0 -109
  367. package/src/runner/reporters/console.ts +0 -70
  368. package/src/runner/reporters/live.test.ts +0 -56
  369. package/src/runner/reporters/live.ts +0 -247
  370. package/src/runner/reporters/quiet.test.ts +0 -66
  371. package/src/runner/reporters/quiet.ts +0 -49
  372. package/src/runner/reporters/table.ts +0 -277
  373. /package/docs-site/zh/{example/tier1-ai-sdk-v7.mdx → examples/integrations/ai-sdk-v7.mdx} +0 -0
  374. /package/docs-site/zh/{example/tier1-claude-sdk.mdx → examples/integrations/claude-sdk.mdx} +0 -0
  375. /package/docs-site/zh/{example/tier1-codex-sdk.mdx → examples/integrations/codex-sdk.mdx} +0 -0
  376. /package/docs-site/zh/{example/tier1-langgraph.mdx → examples/integrations/langgraph.mdx} +0 -0
  377. /package/docs-site/zh/{example/tier1-pi-sdk.mdx → examples/integrations/pi-sdk.mdx} +0 -0
  378. /package/docs-site/zh/{guides → how-to}/fixtures.mdx +0 -0
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { formatMetricValue } from "../format.js";
3
- import { DEFAULT_REPORT_LOCALE, countText, localeText, resolveMetricLabel } from "../locale.js";
4
- import { layoutLabelOffsets, niceTicks } from "./chart-math.js";
3
+ import { DEFAULT_REPORT_LOCALE, countText, localeText, resolveLocalizedText, resolveMetricLabel } from "../locale.js";
4
+ import { niceTicks, placePointLabels } from "./chart-math.js";
5
5
  import { colorClassForKey, seriesClassForKey } from "./colors.js";
6
6
  import { cx } from "./format.js";
7
7
  const WIDTH = 640;
@@ -9,22 +9,55 @@ const HEIGHT = 360;
9
9
  const MARGIN = { top: 26, right: 24, bottom: 46, left: 62 };
10
10
  const PLOT_W = WIDTH - MARGIN.left - MARGIN.right;
11
11
  const PLOT_H = HEIGHT - MARGIN.top - MARGIN.bottom;
12
- /** 点的直接标签:experiment id 的末段(完整 id 在 <title> 里)。 */
13
- function pointLabel(key) {
14
- return key.split("/").filter(Boolean).at(-1) ?? key;
12
+ /**
13
+ * 点的直接标签:末段在当前 data 中唯一才缩成末段;重名时逐步加长为能区分它们的最短
14
+ * 路径后缀(完整 id 与两轴值仍进 <title>)。
15
+ */
16
+ function pointLabels(keys) {
17
+ const segsOf = (key) => key.split("/").filter(Boolean);
18
+ const depth = new Map(keys.map((key) => [key, 1]));
19
+ for (;;) {
20
+ const byLabel = new Map();
21
+ for (const key of keys) {
22
+ const segs = segsOf(key);
23
+ const label = segs.slice(-Math.min(depth.get(key), segs.length)).join("/") || key;
24
+ byLabel.set(label, [...(byLabel.get(label) ?? []), key]);
25
+ }
26
+ let grew = false;
27
+ for (const group of byLabel.values()) {
28
+ if (group.length < 2)
29
+ continue;
30
+ for (const key of group) {
31
+ const segs = segsOf(key);
32
+ if (depth.get(key) < segs.length) {
33
+ depth.set(key, depth.get(key) + 1);
34
+ grew = true;
35
+ }
36
+ }
37
+ }
38
+ if (!grew) {
39
+ const out = new Map();
40
+ for (const key of keys) {
41
+ const segs = segsOf(key);
42
+ out.set(key, segs.slice(-Math.min(depth.get(key), segs.length)).join("/") || key);
43
+ }
44
+ return out;
45
+ }
46
+ }
15
47
  }
16
48
  /**
17
- * 一根轴:niceTicks 撑出整齐的值域,值 → 像素做线性映射;
18
- * better: "lower" 时反向,好的一端固定在右 / 上。
49
+ * 一根轴:niceTicks 撑出整齐的值域,值 → 像素做线性映射。轴方向跟随指标的 `better`:
50
+ * `better: "lower"` 的轴反向渲染(值大的一端在左 / 下),「更好」因此恒指向右与上;
51
+ * 刻度标签始终显示真实值,反向只改方向不改数字(docs/feature/reports/library/metric-views.md)。
19
52
  */
20
- function axisScale(values, better, pixelLo, pixelHi) {
53
+ function axisScale(values, pixelLo, pixelHi, invert) {
21
54
  const ticks = niceTicks(Math.min(...values), Math.max(...values), 5);
22
55
  const lo = ticks[0];
23
56
  const hi = ticks[ticks.length - 1];
24
57
  const scale = (v) => {
25
58
  let t = (v - lo) / (hi - lo || 1);
26
- if (better === "lower")
27
- t = 1 - t; // 反向:值越低越靠「好」的一端
59
+ if (invert)
60
+ t = 1 - t;
28
61
  return pixelLo + t * (pixelHi - pixelLo);
29
62
  };
30
63
  return { ticks, scale };
@@ -41,21 +74,25 @@ export function MetricScatter({ data, pointHref, className, locale = DEFAULT_REP
41
74
  return (_jsxs("figure", { className: cx("nre", "nre-metric-scatter", className), children: [_jsx("p", { className: "nre-scatter-empty nre-missing", children: localeText(locale, "scatter.noData", { x: xLabel, y: yLabel }) }), missingNote] }));
42
75
  }
43
76
  const axisLabel = (label, col) => `${label}${col.unit ? `(${col.unit})` : ""}`;
44
- const xScale = axisScale(drawableRows.map((r) => r.x.value), data.x.better, MARGIN.left, MARGIN.left + PLOT_W);
45
- // y 像素轴向下增长:better:"higher" 高值在上 映射到 [bottom, top];"lower" 由 axisScale 反向后同样落到上方
46
- const yScale = axisScale(drawableRows.map((r) => r.y.value), data.y.better, MARGIN.top + PLOT_H, MARGIN.top);
77
+ // 轴方向跟随 better:lower 反向(值大在左 / ),higher 与未声明正向。
78
+ const xScale = axisScale(drawableRows.map((r) => r.x.value), MARGIN.left, MARGIN.left + PLOT_W, data.x.better === "lower");
79
+ // y 像素轴向下增长:正向 = 高值在上 映射到 [bottom, top];lower 反向 = 高值在下。
80
+ const yScale = axisScale(drawableRows.map((r) => r.y.value), MARGIN.top + PLOT_H, MARGIN.top, data.y.better === "lower");
81
+ const labelByKey = pointLabels(drawableRows.map((r) => r.key));
82
+ // 方向提示恒为「越靠右上越好」,仅当两轴都声明 better 时显示——任一轴未声明,
83
+ // 组件不猜「更好」朝哪边,整图无提示。
84
+ const showBetterHint = data.x.better !== undefined && data.y.better !== undefined;
47
85
  const points = drawableRows.map((r) => {
48
86
  const xValue = r.x.value;
49
87
  const yValue = r.y.value;
50
88
  return {
51
89
  key: r.key,
52
90
  series: r.series,
53
- label: pointLabel(r.key),
91
+ label: labelByKey.get(r.key) ?? r.key,
54
92
  xValue,
55
93
  yValue,
56
- // hover 内容:experiment(点键)+ 系列(series,ExperimentComparison 传的是 agent 维度,
57
- // 有则加一行;无系列的散点没有这行)+ 两轴 display samples/total(docs/feature/reports/library.md「MetricScatter」行为清单)
58
- title: `${r.key}${r.series !== undefined ? `\n${r.series}` : ""}\n${xLabel}: ${r.x.display}(${r.x.samples}/${r.x.total})\n${yLabel}: ${r.y.display}(${r.y.samples}/${r.y.total})`,
94
+ // hover 内容:experiment(点键)+ 系列(有则加一行)+ 两轴 display 与 samples/total
95
+ title: `${r.key}${r.series !== undefined ? `\n${r.series}` : ""}\n${xLabel}: ${resolveLocalizedText(r.x.display, locale)}(${r.x.samples}/${r.x.total})\n${yLabel}: ${resolveLocalizedText(r.y.display, locale)}(${r.y.samples}/${r.y.total})`,
59
96
  px: xScale.scale(xValue),
60
97
  py: yScale.scale(yValue),
61
98
  };
@@ -74,22 +111,16 @@ export function MetricScatter({ data, pointHref, className, locale = DEFAULT_REP
74
111
  }
75
112
  for (const list of bySeries.values())
76
113
  list.sort((a, b) => a.xValue - b.xValue);
77
- // 直接标签的防撞布局:靠右的点把标签锚到左侧,重叠的往下推、补 leader line
78
- const positions = points.map((p) => {
79
- const anchorLeft = p.px >= MARGIN.left + PLOT_W * 0.72;
80
- return { cx: p.px, cy: p.py, anchorLeft, width: p.label.length * 6.4 + 10 };
81
- });
82
- const labelOffsets = layoutLabelOffsets(positions);
83
- return (_jsxs("figure", { className: cx("nre", "nre-metric-scatter", className), children: [_jsxs("svg", { className: "nre-scatter-svg", viewBox: `0 0 ${WIDTH} ${HEIGHT}`, role: "img", "aria-label": `${axisLabel(xLabel, data.x)} × ${axisLabel(yLabel, data.y)}`, children: [_jsxs("g", { className: "nre-scatter-grid", children: [yScale.ticks.map((tick) => (_jsx("line", { x1: MARGIN.left, x2: MARGIN.left + PLOT_W, y1: yScale.scale(tick), y2: yScale.scale(tick) }, `gy${tick}`))), xScale.ticks.map((tick) => (_jsx("line", { y1: MARGIN.top, y2: MARGIN.top + PLOT_H, x1: xScale.scale(tick), x2: xScale.scale(tick) }, `gx${tick}`)))] }), _jsx("text", { className: "nre-scatter-better-hint", x: MARGIN.left + PLOT_W - 6, y: MARGIN.top + 14, textAnchor: "end", children: localeText(locale, "scatter.betterHint") }), _jsx("g", { className: "nre-scatter-axis nre-scatter-axis-y", children: yScale.ticks.map((tick) => (_jsx("text", { className: "nre-scatter-tick", x: MARGIN.left - 8, y: yScale.scale(tick) + 3, textAnchor: "end", children: formatMetricValue(tick, data.y.unit) }, `ay${tick}`))) }), _jsx("g", { className: "nre-scatter-axis nre-scatter-axis-x", children: xScale.ticks.map((tick) => (_jsx("text", { className: "nre-scatter-tick", x: xScale.scale(tick), y: MARGIN.top + PLOT_H + 16, textAnchor: "middle", children: formatMetricValue(tick, data.x.unit) }, `ax${tick}`))) }), _jsx("text", { className: "nre-scatter-xlabel", x: MARGIN.left + PLOT_W / 2, y: HEIGHT - 8, textAnchor: "middle", children: axisLabel(xLabel, data.x) }), _jsx("text", { className: "nre-scatter-ylabel", x: 14, y: MARGIN.top + PLOT_H / 2, textAnchor: "middle", transform: `rotate(-90 14 ${MARGIN.top + PLOT_H / 2})`, children: axisLabel(yLabel, data.y) }), seriesOrder.map((series) => {
114
+ // 直接标签的候选位择优布局:锚向、避让方向都由布局按空间决定,画布边界含边距
115
+ const labels = placePointLabels(points.map((p) => ({ cx: p.px, cy: p.py, width: p.label.length * 6.4 + 10 })), { x0: 2, y0: 2, x1: WIDTH - 2, y1: HEIGHT - 2 });
116
+ return (_jsxs("figure", { className: cx("nre", "nre-metric-scatter", className), children: [_jsxs("svg", { className: "nre-scatter-svg", viewBox: `0 0 ${WIDTH} ${HEIGHT}`, role: "img", "aria-label": `${axisLabel(xLabel, data.x)} × ${axisLabel(yLabel, data.y)}`, children: [_jsxs("g", { className: "nre-scatter-grid", children: [yScale.ticks.map((tick) => (_jsx("line", { x1: MARGIN.left, x2: MARGIN.left + PLOT_W, y1: yScale.scale(tick), y2: yScale.scale(tick) }, `gy${tick}`))), xScale.ticks.map((tick) => (_jsx("line", { y1: MARGIN.top, y2: MARGIN.top + PLOT_H, x1: xScale.scale(tick), x2: xScale.scale(tick) }, `gx${tick}`)))] }), showBetterHint && (_jsx("text", { className: "nre-scatter-better-hint", x: MARGIN.left + PLOT_W - 6, y: MARGIN.top + 14, textAnchor: "end", children: localeText(locale, "scatter.betterUpperRight") })), _jsx("g", { className: "nre-scatter-axis nre-scatter-axis-y", children: yScale.ticks.map((tick) => (_jsx("text", { className: "nre-scatter-tick", x: MARGIN.left - 8, y: yScale.scale(tick) + 3, textAnchor: "end", children: formatMetricValue(tick, data.y.unit) }, `ay${tick}`))) }), _jsx("g", { className: "nre-scatter-axis nre-scatter-axis-x", children: xScale.ticks.map((tick) => (_jsx("text", { className: "nre-scatter-tick", x: xScale.scale(tick), y: MARGIN.top + PLOT_H + 16, textAnchor: "middle", children: formatMetricValue(tick, data.x.unit) }, `ax${tick}`))) }), _jsx("text", { className: "nre-scatter-xlabel", x: MARGIN.left + PLOT_W / 2, y: HEIGHT - 8, textAnchor: "middle", children: axisLabel(xLabel, data.x) }), _jsx("text", { className: "nre-scatter-ylabel", x: 14, y: MARGIN.top + PLOT_H / 2, textAnchor: "middle", transform: `rotate(-90 14 ${MARGIN.top + PLOT_H / 2})`, children: axisLabel(yLabel, data.y) }), seriesOrder.map((series) => {
84
117
  const list = bySeries.get(series);
85
118
  if (list.length < 2)
86
119
  return null;
87
120
  return (_jsx("polyline", { className: cx("nre-scatter-line", seriesClassForKey(series)), "data-series": series, points: list.map((p) => `${p.px},${p.py}`).join(" "), fill: "none" }, series));
88
121
  }), points.map((p, i) => {
89
- const { anchorLeft } = positions[i];
90
- const labelX = p.px + (anchorLeft ? -10 : 10);
91
- const labelY = p.py + 4 + labelOffsets[i];
92
- const group = (_jsxs("g", { className: cx("nre-scatter-point", p.series !== undefined ? seriesClassForKey(p.series) : "nre-series-none"), "data-key": p.key, children: [_jsx("title", { children: p.title }), labelOffsets[i] !== 0 && _jsx("line", { className: "nre-leader", x1: p.px, y1: p.py, x2: labelX, y2: labelY - 4 }), _jsx("circle", { className: "nre-scatter-hit", cx: p.px, cy: p.py, r: 12 }), _jsx("circle", { className: "nre-scatter-dot", cx: p.px, cy: p.py, r: 4.5 }), _jsx("text", { className: "nre-scatter-point-label", x: labelX, y: labelY, textAnchor: anchorLeft ? "end" : "start", children: p.label })] }));
122
+ const label = labels[i];
123
+ const group = (_jsxs("g", { className: cx("nre-scatter-point", p.series !== undefined ? seriesClassForKey(p.series) : "nre-series-none"), "data-key": p.key, children: [_jsx("title", { children: p.title }), label.leader && _jsx("line", { className: "nre-leader", x1: p.px, y1: p.py, x2: label.x, y2: label.y - 4 }), _jsx("circle", { className: "nre-scatter-hit", cx: p.px, cy: p.py, r: 12 }), _jsx("circle", { className: "nre-scatter-dot", cx: p.px, cy: p.py, r: 4.5 }), _jsx("text", { className: "nre-scatter-point-label", x: label.x, y: label.y, textAnchor: label.anchor, children: p.label })] }));
93
124
  const row = drawableRows[i];
94
125
  return pointHref ? (_jsx("a", { className: "nre-scatter-point-link", href: pointHref(row), children: group }, p.key)) : (_jsx("g", { children: group }, p.key));
95
126
  })] }), seriesOrder.length > 0 && (_jsx("figcaption", { className: "nre-scatter-legend", children: seriesOrder.map((series) => (_jsx("span", { className: cx("nre-legend-key", "nre-key", colorClassForKey(series)), children: series }, series))) })), missingNote] }));
@@ -3,21 +3,11 @@ import { DEFAULT_REPORT_LOCALE, localeText, resolveMetricLabel } from "../locale
3
3
  import { MetricCellView } from "./cell.js";
4
4
  import { colorClassForKey } from "./colors.js";
5
5
  import { cx } from "./format.js";
6
- /** verdict 计票 pill(「3 passed / 1 failed」):非零判定各一枚,全零如实空。 */
7
- function VerdictTally({ verdicts, locale, }) {
8
- const kinds = ["passed", "failed", "errored", "skipped"].filter((k) => verdicts[k] > 0);
9
- return (_jsxs("span", { className: "nre-verdict-tally", children: [kinds.map((kind) => (_jsxs("span", { className: cx("nre-verdict-pill", `nre-verdict-${kind}`), children: [verdicts[kind], " ", localeText(locale, `verdict.${kind}`)] }, kind))), kinds.length === 0 && _jsx("span", { className: "nre-missing", children: "\u2014" })] }));
10
- }
11
6
  export function MetricTable({ data, attemptHref, filter, className, locale = DEFAULT_REPORT_LOCALE, }) {
12
- const hasMeta = data.rows.some((row) => row.meta !== undefined);
13
- const hasModel = data.rows.some((row) => row.meta?.model !== undefined);
14
- const hasVerdicts = data.rows.some((row) => row.meta?.verdicts !== undefined);
15
- const table = (_jsxs("table", { className: cx("nre", "nre-metric-table", !filter && className), children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { scope: "col", className: "nre-dimension", "data-nre-sort": "", children: data.dimension }), hasMeta && hasModel && (_jsx("th", { scope: "col", className: "nre-meta-col", "data-nre-sort": "", children: localeText(locale, "table.model") })), hasMeta && (_jsx("th", { scope: "col", className: "nre-meta-col", "data-nre-sort": "", children: localeText(locale, "table.agent") })), data.columns.map((col) => (_jsxs("th", { scope: "col", className: "nre-metric-col", "data-nre-sort": "", children: [resolveMetricLabel(col.label, locale, col.key), col.unit && _jsxs("span", { className: "nre-unit", children: ["(", col.unit, ")"] }), col.better && (_jsx("span", { className: "nre-better", title: localeText(locale, col.better === "higher" ? "table.higherBetter" : "table.lowerBetter"), children: col.better === "higher" ? "↑" : "↓" }))] }, col.key))), hasVerdicts && (_jsx("th", { scope: "col", className: "nre-verdicts-col", "data-nre-sort": "", children: localeText(locale, "table.verdicts") }))] }) }), _jsx("tbody", { children: data.rows.map((row) => (_jsxs("tr", { children: [_jsxs("th", { scope: "row", className: cx("nre-row-key", "nre-key", colorClassForKey(row.key)), "data-sort-value": row.key, children: [row.key, row.meta?.evals !== undefined && (_jsxs("div", { className: "nre-row-meta-sub", children: [localeText(locale, "overview.evalsCount", { n: row.meta.evals }), row.meta.attempts !== undefined && row.meta.attempts > row.meta.evals
16
- ? ` · ${localeText(locale, "overview.attemptsCount", { n: row.meta.attempts })}`
17
- : "", row.meta.lastRunAt ? ` · ${localeText(locale, "latestRun", { run: row.meta.lastRunAt })}` : ""] }))] }), hasMeta && hasModel && (_jsx("td", { className: "nre-td nre-meta-cell", "data-sort-value": row.meta?.model ?? "", children: row.meta?.model ?? _jsx("span", { className: "nre-missing", children: "\u2014" }) })), hasMeta && (_jsx("td", { className: "nre-td nre-meta-cell", "data-sort-value": row.meta?.agent ?? "", children: row.meta?.agent ?? _jsx("span", { className: "nre-missing", children: "\u2014" }) })), data.columns.map((col) => {
7
+ const table = (_jsxs("table", { className: cx("nre", "nre-metric-table", !filter && className), children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { scope: "col", className: "nre-dimension", "data-nre-sort": "", children: data.rowDimension }), data.columns.map((col) => (_jsxs("th", { scope: "col", className: "nre-metric-col", "data-nre-sort": "", children: [resolveMetricLabel(col.label, locale, col.key), col.unit && _jsxs("span", { className: "nre-unit", children: ["(", col.unit, ")"] }), col.better && (_jsx("span", { className: "nre-better", title: localeText(locale, col.better === "higher" ? "table.higherBetter" : "table.lowerBetter"), children: col.better === "higher" ? "↑" : "↓" }))] }, col.key)))] }) }), _jsx("tbody", { children: data.rows.map((row) => (_jsxs("tr", { children: [_jsx("th", { scope: "row", className: cx("nre-row-key", "nre-key", colorClassForKey(row.key)), "data-sort-value": row.key, children: row.key }), data.columns.map((col) => {
18
8
  const cell = row.cells[col.key];
19
9
  return (_jsx("td", { className: "nre-td", "data-sort-value": cell?.value ?? "", children: cell ? (_jsx(MetricCellView, { cell: cell, attemptHref: attemptHref, locale: locale })) : (_jsx("span", { className: "nre-empty" })) }, col.key));
20
- }), hasVerdicts && (_jsx("td", { className: "nre-td nre-verdicts-cell", "data-sort-value": row.meta?.verdicts?.passed ?? "", children: row.meta?.verdicts ? (_jsx(VerdictTally, { verdicts: row.meta.verdicts, locale: locale })) : (_jsx("span", { className: "nre-missing", children: "\u2014" })) }))] }, row.key))) })] }));
10
+ })] }, row.key))) })] }));
21
11
  if (!filter)
22
12
  return table;
23
13
  // 过滤输入框渲染在表格前(同一个 wrap 里),enhance.js 经 data-nre-filter 接管;
@@ -0,0 +1,10 @@
1
+ import type { ReactElement } from "react";
2
+ import type { ScopeSummaryData } from "../types.ts";
3
+ import { type ReportLocale } from "../locale.ts";
4
+ export declare function ScopeSummary({ data, votes, className, locale, }: {
5
+ data: ScopeSummaryData;
6
+ /** 显示哪一级计票;默认 "eval"。data 恒携带两级,votes 只选择呈现。 */
7
+ votes?: "eval" | "attempt";
8
+ className?: string;
9
+ locale?: ReportLocale;
10
+ }): ReactElement;
@@ -0,0 +1,17 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { DEFAULT_REPORT_LOCALE, localeText } from "../locale.js";
3
+ import { MetricCellView } from "./cell.js";
4
+ import { cx } from "./format.js";
5
+ function VerdictTallyView({ tally, locale }) {
6
+ const kinds = ["passed", "failed", "errored", "skipped"].filter((k) => tally[k] > 0);
7
+ return (_jsxs("span", { className: "nre-verdict-tally", children: [kinds.map((kind) => (_jsxs("span", { className: cx("nre-verdict-pill", `nre-verdict-${kind}`), children: [tally[kind], " ", localeText(locale, `verdict.${kind}`)] }, kind))), kinds.length === 0 && _jsx("span", { className: "nre-missing", children: "\u2014" })] }));
8
+ }
9
+ export function ScopeSummary({ data, votes = "eval", className, locale = DEFAULT_REPORT_LOCALE, }) {
10
+ const tally = votes === "attempt" ? data.attemptVerdicts : data.evalVerdicts;
11
+ return (_jsxs("div", { className: cx("nre", "nre-scope-summary", className), "data-votes": votes, children: [_jsxs("dl", { className: "nre-scope-kpis", children: [_jsxs("div", { className: "nre-scope-kpi nre-scope-kpi-rate", children: [_jsx("dt", { children: localeText(locale, "scopeSummary.passRate") }), _jsx("dd", { children: _jsx(MetricCellView, { cell: data.endToEndPassRate, locale: locale }) })] }), _jsxs("div", { className: "nre-scope-kpi", children: [_jsx("dt", { children: localeText(locale, "scopeSummary.experiments") }), _jsx("dd", { children: data.experiments })] }), _jsxs("div", { className: "nre-scope-kpi", children: [_jsx("dt", { children: localeText(locale, "scopeSummary.evals") }), _jsx("dd", { children: data.evals })] }), _jsxs("div", { className: "nre-scope-kpi", children: [_jsx("dt", { children: localeText(locale, "scopeSummary.attempts") }), _jsx("dd", { children: data.attempts })] }), _jsxs("div", { className: "nre-scope-kpi nre-scope-kpi-verdicts", children: [_jsx("dt", { children: localeText(locale, votes === "attempt" ? "scopeSummary.votesAttempt" : "scopeSummary.votesEval") }), _jsx("dd", { children: _jsx(VerdictTallyView, { tally: tally, locale: locale }) })] }), _jsxs("div", { className: "nre-scope-kpi", children: [_jsx("dt", { children: localeText(locale, "scopeSummary.totalCost") }), _jsx("dd", { children: _jsx(MetricCellView, { cell: data.totalCostUSD, locale: locale }) })] })] }), data.range.latestStartedAt !== null && (_jsx("p", { className: "nre-scope-summary-range", children: data.range.earliestStartedAt !== null && data.range.earliestStartedAt !== data.range.latestStartedAt
12
+ ? localeText(locale, "scopeSummary.range", {
13
+ from: data.range.earliestStartedAt,
14
+ to: data.range.latestStartedAt,
15
+ })
16
+ : data.range.latestStartedAt }))] }));
17
+ }
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { DEFAULT_REPORT_LOCALE, countText, localeText } from "../locale.js";
2
+ import { DEFAULT_REPORT_LOCALE, countText, localeText, resolveLocalizedText } from "../locale.js";
3
3
  import { colorClassForKey } from "./colors.js";
4
4
  import { cx } from "./format.js";
5
5
  export function Scoreboard({ data, className, locale = DEFAULT_REPORT_LOCALE, }) {
@@ -11,16 +11,16 @@ export function Scoreboard({ data, className, locale = DEFAULT_REPORT_LOCALE, })
11
11
  subjectKeys.push(subject.key);
12
12
  }
13
13
  }
14
- return (_jsxs("section", { className: cx("nre", "nre-scoreboard", className), children: [_jsxs("table", { className: "nre-scoreboard-table", children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { scope: "col", className: "nre-dimension", children: data.dimension }), _jsxs("th", { scope: "col", className: "nre-total-col", children: [localeText(locale, "scoreboard.total"), _jsxs("span", { className: "nre-full-marks", children: ["/ ", data.fullMarks] })] }), subjectKeys.map((key) => (_jsx("th", { scope: "col", className: "nre-subject-col", children: key }, key)))] }) }), _jsx("tbody", { children: data.rows.map((row) => (_jsxs("tr", { children: [_jsx("th", { scope: "row", className: cx("nre-row-key", "nre-key", colorClassForKey(row.key)), children: row.key }), _jsx("td", { className: "nre-total", children: row.total.display }), subjectKeys.map((key) => {
14
+ return (_jsxs("section", { className: cx("nre", "nre-scoreboard", className), children: [_jsxs("table", { className: "nre-scoreboard-table", children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { scope: "col", className: "nre-dimension", children: data.rowDimension }), _jsxs("th", { scope: "col", className: "nre-total-col", children: [localeText(locale, "scoreboard.total"), _jsxs("span", { className: "nre-full-marks", children: ["/ ", data.fullMarks] })] }), subjectKeys.map((key) => (_jsx("th", { scope: "col", className: "nre-subject-col", children: key }, key)))] }) }), _jsx("tbody", { children: data.rows.map((row) => (_jsxs("tr", { children: [_jsx("th", { scope: "row", className: cx("nre-row-key", "nre-key", colorClassForKey(row.key)), children: row.key }), _jsxs("td", { className: "nre-total", children: [resolveLocalizedText(row.total.display, locale), row.total.notRun > 0 && (_jsx("span", { className: "nre-total-not-run", children: countText(locale, "scoreboard.notRun", row.total.notRun) })), row.total.unscorable > 0 && (_jsx("span", { className: "nre-total-unscorable", children: countText(locale, "scoreboard.unscorable", row.total.unscorable) }))] }), subjectKeys.map((key) => {
15
15
  const subject = row.subjects.find((s) => s.key === key);
16
16
  if (!subject)
17
17
  return _jsx("td", { className: "nre-td-empty" }, key);
18
- return (_jsxs("td", { className: "nre-subject", children: [_jsxs("span", { className: "nre-subject-score", title: localeText(locale, "scoreboard.subjectTitle", {
19
- evals: subject.evals,
18
+ return (_jsxs("td", { className: "nre-subject", children: [_jsx("span", { className: "nre-subject-score", title: localeText(locale, "scoreboard.subjectTitle", {
19
+ questions: subject.questions,
20
20
  earned: subject.earned,
21
21
  possible: subject.possible,
22
- }), children: [subject.earned, "/", subject.possible] }), subject.missing > 0 && (_jsx("span", { className: "nre-subject-missing", children: countText(locale, "scoreboard.missing", subject.missing) }))] }, key));
22
+ }), children: resolveLocalizedText(subject.display, locale) }), subject.notRun > 0 && (_jsx("span", { className: "nre-subject-not-run", children: localeText(locale, "scoreboard.notRunText", { n: subject.notRun }) })), subject.unscorable > 0 && (_jsx("span", { className: "nre-subject-unscorable", children: localeText(locale, "scoreboard.unscorableText", { n: subject.unscorable }) }))] }, key));
23
23
  })] }, row.key))) })] }), _jsxs("p", { className: "nre-weights", children: [localeText(locale, "scoreboard.weights"), " ", data.weights.length === 0
24
24
  ? localeText(locale, "scoreboard.allWeights")
25
- : data.weights.map((w) => (_jsxs("span", { className: "nre-weight", children: [w.prefix, " \u00D7", w.weight] }, w.prefix))), data.weights.length > 0 && _jsx("span", { className: "nre-weight-rest", children: localeText(locale, "scoreboard.othersWeight") })] })] }));
25
+ : data.weights.map((w) => (_jsxs("span", { className: "nre-weight", children: [w.prefix, " \u00D7", w.weight] }, w.prefix))), data.weights.length > 0 && _jsx("span", { className: "nre-weight-rest", children: localeText(locale, "scoreboard.othersWeight") })] }), data.ignoredEvals > 0 && (_jsx("p", { className: "nre-scoreboard-ignored", children: countText(locale, "scoreboard.ignored", data.ignoredEvals) }))] }));
26
26
  }
@@ -1,9 +1,9 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { DEFAULT_REPORT_LOCALE, localeText } from "../locale.js";
2
+ import { DEFAULT_REPORT_LOCALE, localeText, resolveLocalizedText } from "../locale.js";
3
3
  export function MetricCellView({ cell, attemptHref, locale = DEFAULT_REPORT_LOCALE, }) {
4
4
  // 全 null(没有任何有效样本)→ 缺数据文案,绝不画 0;total 仍如实入 title
5
5
  if (cell.value === null) {
6
6
  return (_jsx("span", { className: "nre-cell nre-cell-missing", children: _jsx("span", { className: "nre-missing", title: localeText(locale, "cell.noneMeasurableTitle", { total: cell.total }), children: localeText(locale, "cell.missing") }) }));
7
7
  }
8
- return (_jsxs("span", { className: "nre-cell", children: [_jsx("span", { className: "nre-value", title: localeText(locale, "cell.measuredTitle", { samples: cell.samples, total: cell.total }), children: cell.display }), cell.samples < cell.total && (_jsxs("sup", { className: "nre-coverage", title: localeText(locale, "cell.coverageTitle", { samples: cell.samples, total: cell.total }), children: [cell.samples, "/", cell.total] })), attemptHref && cell.refs && cell.refs.length > 0 && (_jsx("span", { className: "nre-refs", children: cell.refs.map((locator, i) => (_jsxs("a", { className: "nre-ref", href: attemptHref(locator), children: ["#", i + 1] }, locator))) }))] }));
8
+ return (_jsxs("span", { className: "nre-cell", children: [_jsx("span", { className: "nre-value", title: localeText(locale, "cell.measuredTitle", { samples: cell.samples, total: cell.total }), children: resolveLocalizedText(cell.display, locale) }), cell.samples < cell.total && (_jsxs("sup", { className: "nre-coverage", title: localeText(locale, "cell.coverageTitle", { samples: cell.samples, total: cell.total }), children: [cell.samples, "/", cell.total] })), attemptHref && cell.refs && cell.refs.length > 0 && (_jsx("span", { className: "nre-refs", children: cell.refs.map((locator, i) => (_jsxs("a", { className: "nre-ref", href: attemptHref(locator), children: ["#", i + 1] }, locator))) }))] }));
9
9
  }
@@ -1,14 +1,31 @@
1
1
  /** [min, max] 区间上生成 count 个左右的“整齐”刻度(Heckbert nice-numbers)。 */
2
2
  export declare function niceTicks(min: number, max: number, count?: number): number[];
3
- export interface LabelInput {
3
+ export interface PointLabelInput {
4
4
  cx: number;
5
5
  cy: number;
6
+ /** 标签文本的估算宽度(px)。 */
6
7
  width: number;
7
- /** true = 文字锚在点左侧(text-anchor: end),false = 锚在右侧(text-anchor: start)。 */
8
- anchorLeft: boolean;
8
+ }
9
+ /** 标签允许占用的画布范围(含坐标轴边距,标签可以借用空白边距)。 */
10
+ export interface LabelBounds {
11
+ x0: number;
12
+ y0: number;
13
+ x1: number;
14
+ y1: number;
15
+ }
16
+ export interface PlacedPointLabel {
17
+ /** <text> 的锚点坐标(y 为文字基线)。 */
18
+ x: number;
19
+ y: number;
20
+ anchor: "start" | "end" | "middle";
21
+ /** 标签不在点左右紧邻位:渲染层补 leader line 连回原点。 */
22
+ leader: boolean;
9
23
  }
10
24
  /**
11
- * 贪心地把互相重叠的直接标签往下推开(按 y 排序、逐个查重叠再下移),点本身位置不变。
12
- * 散点常见同分不同价的聚簇,这一步避免标签叠成一团糊字。
25
+ * 散点直接标签的候选位择优布局(docs/feature/reports/library.md「MetricScatter」):
26
+ * 每个标签在点四周由近及远的候选环上打分——与已放置标签的重叠、与任何数据点的重叠、
27
+ * 越出画布的面积、离点距离逐项累加,取代价最小的候选。存在无冲突候选时标签必不遮点、
28
+ * 不叠标签、不越界;全候选冲突时取重叠最小者,绝不丢标签。重合点簇因此向不同方向散开,
29
+ * 而不是单向堆叠压到下方的数据点上。
13
30
  */
14
- export declare function layoutLabelOffsets(items: LabelInput[], lineHeight?: number, padX?: number): number[];
31
+ export declare function placePointLabels(points: PointLabelInput[], bounds: LabelBounds): PlacedPointLabel[];
@@ -1,5 +1,4 @@
1
- // 通用图表数值工具:round-number 刻度生成与标签防撞布局,零依赖纯函数。
2
- // 从 src/view/app/lib/chart.ts 迁来(view 侧从这里 re-export),报告组件与 view 共用同一份。
1
+ // 通用图表数值工具:round-number 刻度生成与点标签布局,零依赖纯函数。
3
2
  function niceNumber(range, round) {
4
3
  if (range <= 0)
5
4
  return 1;
@@ -43,26 +42,79 @@ export function niceTicks(min, max, count = 5) {
43
42
  ticks.push(Number(v.toFixed(10)));
44
43
  return ticks;
45
44
  }
45
+ /** 标签框高度(基线上方 10px、下方 2px,对应 11px 字号)。 */
46
+ const LABEL_ASCENT = 10;
47
+ const LABEL_DESCENT = 2;
48
+ /** 数据点视为边长 2×DOT_R 的方形障碍(点半径 4.5 + 命中余量)。 */
49
+ const DOT_R = 6;
50
+ /** 紧邻位与点的水平间距;候选环按它逐环外扩。 */
51
+ const NEAR = 10;
52
+ const RINGS = [NEAR, NEAR + 12, NEAR + 26];
53
+ function labelBoxAt(x, y, anchor, width) {
54
+ const x0 = anchor === "start" ? x : anchor === "end" ? x - width : x - width / 2;
55
+ return { x0, y0: y - LABEL_ASCENT, x1: x0 + width, y1: y + LABEL_DESCENT };
56
+ }
57
+ function overlapArea(a, b) {
58
+ const w = Math.min(a.x1, b.x1) - Math.max(a.x0, b.x0);
59
+ const h = Math.min(a.y1, b.y1) - Math.max(a.y0, b.y0);
60
+ return w > 0 && h > 0 ? w * h : 0;
61
+ }
62
+ function outOfBoundsArea(box, bounds) {
63
+ const total = (box.x1 - box.x0) * (box.y1 - box.y0);
64
+ const w = Math.min(box.x1, bounds.x1) - Math.max(box.x0, bounds.x0);
65
+ const h = Math.min(box.y1, bounds.y1) - Math.max(box.y0, bounds.y0);
66
+ const inside = w > 0 && h > 0 ? w * h : 0;
67
+ return total - inside;
68
+ }
69
+ /** 一个点在距离 d 的候选环:左右紧邻、四个斜角、正上正下。顺序即同代价时的偏好序。 */
70
+ function ringCandidates(p, d) {
71
+ const diag = d * 0.75;
72
+ return [
73
+ { x: p.cx + d, y: p.cy + 4, anchor: "start" },
74
+ { x: p.cx - d, y: p.cy + 4, anchor: "end" },
75
+ { x: p.cx + diag, y: p.cy - diag - 2, anchor: "start" },
76
+ { x: p.cx - diag, y: p.cy - diag - 2, anchor: "end" },
77
+ { x: p.cx, y: p.cy - d - LABEL_DESCENT - 2, anchor: "middle" },
78
+ { x: p.cx + diag, y: p.cy + diag + LABEL_ASCENT, anchor: "start" },
79
+ { x: p.cx - diag, y: p.cy + diag + LABEL_ASCENT, anchor: "end" },
80
+ { x: p.cx, y: p.cy + d + LABEL_ASCENT + 2, anchor: "middle" },
81
+ ];
82
+ }
46
83
  /**
47
- * 贪心地把互相重叠的直接标签往下推开(按 y 排序、逐个查重叠再下移),点本身位置不变。
48
- * 散点常见同分不同价的聚簇,这一步避免标签叠成一团糊字。
84
+ * 散点直接标签的候选位择优布局(docs/feature/reports/library.md「MetricScatter」):
85
+ * 每个标签在点四周由近及远的候选环上打分——与已放置标签的重叠、与任何数据点的重叠、
86
+ * 越出画布的面积、离点距离逐项累加,取代价最小的候选。存在无冲突候选时标签必不遮点、
87
+ * 不叠标签、不越界;全候选冲突时取重叠最小者,绝不丢标签。重合点簇因此向不同方向散开,
88
+ * 而不是单向堆叠压到下方的数据点上。
49
89
  */
50
- export function layoutLabelOffsets(items, lineHeight = 14, padX = 4) {
51
- const offsets = new Array(items.length).fill(0);
52
- const order = [...items.keys()].sort((a, b) => items[a].cy - items[b].cy || items[a].cx - items[b].cx);
53
- const placed = [];
90
+ export function placePointLabels(points, bounds) {
91
+ const dots = points.map((p) => ({ x0: p.cx - DOT_R, y0: p.cy - DOT_R, x1: p.cx + DOT_R, y1: p.cy + DOT_R }));
92
+ const placedBoxes = [];
93
+ const result = new Array(points.length);
94
+ // 由上到下、由左到右逐个放置,布局确定可复现
95
+ const order = [...points.keys()].sort((a, b) => points[a].cy - points[b].cy || points[a].cx - points[b].cx);
54
96
  for (const i of order) {
55
- const it = items[i];
56
- const x0 = it.anchorLeft ? it.cx - it.width : it.cx;
57
- const x1 = it.anchorLeft ? it.cx : it.cx + it.width;
58
- let y = it.cy;
59
- let guard = 0;
60
- while (guard < 40 && placed.some((p) => x0 < p.x1 + padX && x1 > p.x0 - padX && Math.abs(y - p.y) < lineHeight)) {
61
- y += lineHeight;
62
- guard++;
97
+ const p = points[i];
98
+ let best = null;
99
+ for (let ring = 0; ring < RINGS.length; ring++) {
100
+ const candidates = ringCandidates(p, RINGS[ring]);
101
+ for (let c = 0; c < candidates.length; c++) {
102
+ const candidate = candidates[c];
103
+ const box = labelBoxAt(candidate.x, candidate.y, candidate.anchor, p.width);
104
+ let cost = 0;
105
+ for (const placed of placedBoxes)
106
+ cost += overlapArea(box, placed) * 4;
107
+ for (const dot of dots)
108
+ cost += overlapArea(box, dot) * 3;
109
+ cost += outOfBoundsArea(box, bounds) * 6;
110
+ cost += ring * 8 + c * 0.5; // 近环、偏好序靠前者优先,只作同冲突程度下的排序
111
+ if (best === null || cost < best.cost) {
112
+ best = { candidate, box, cost, leader: !(ring === 0 && c <= 1) };
113
+ }
114
+ }
63
115
  }
64
- placed.push({ x0, x1, y });
65
- offsets[i] = y - it.cy;
116
+ placedBoxes.push(best.box);
117
+ result[i] = { ...best.candidate, leader: best.leader };
66
118
  }
67
- return offsets;
119
+ return result;
68
120
  }
@@ -1,19 +1,15 @@
1
- import type { AttemptListItem, DeltaData, EvalListItem, ExperimentListItem, GroupSummaryData, LineData, MatrixData, MetricColumn, OverviewData, ScatterData, ScoreboardData, TableData } from "../types.ts";
1
+ import type { AttemptListItem, DeltaData, EvalListItem, ExperimentListItem, LineData, MatrixData, MetricColumn, ScatterData, ScopeSummaryData, ScoreboardData, TableData } from "../types.ts";
2
2
  export declare const passRateColumn: MetricColumn;
3
3
  export declare const codeLinesColumn: MetricColumn;
4
4
  export declare const costColumn: MetricColumn;
5
- export declare const overviewData: OverviewData;
6
- export declare const overviewWithCost: OverviewData;
7
- /** GroupSummary.data 的产物形态:eval 级折叠计票 + 旧 GroupSelector 口径的通过率(包成 MetricCell)。 */
8
- export declare const groupSummaryData: GroupSummaryData;
9
- export declare const tableData: TableData<"pass-rate" | "code-lines">;
10
- /** rows: "experiment" 的榜单形态:行携带 agent/model 元信息与 eval 级折叠计票。 */
11
- export declare const tableDataWithMeta: TableData<"pass-rate">;
5
+ /** scopeSummaryData 的产物形态:两级计票恒随行,成功率与总成本是官方 MetricCell。 */
6
+ export declare const scopeSummaryData: ScopeSummaryData;
7
+ export declare const tableData: TableData;
12
8
  export declare const matrixData: MatrixData;
13
9
  export declare const scoreboardData: ScoreboardData;
14
10
  export declare const scatterData: ScatterData;
15
11
  export declare const lineData: LineData;
16
- export declare const deltaData: DeltaData<"pass-rate" | "cost">;
12
+ export declare const deltaData: DeltaData;
17
13
  export declare const attemptListItems: AttemptListItem[];
18
14
  export declare const evalListItems: EvalListItem[];
19
15
  export declare const experimentListItems: ExperimentListItem[];