niceeval 0.9.1 → 0.10.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 (428) hide show
  1. package/INDEX.md +31 -33
  2. package/dist/agents/types.d.ts +20 -17
  3. package/dist/context/types.d.ts +21 -21
  4. package/dist/i18n/en.d.ts +10 -2
  5. package/dist/i18n/zh-CN.d.ts +14 -6
  6. package/dist/o11y/execution-tree.d.ts +103 -0
  7. package/dist/o11y/otlp/select.d.ts +22 -0
  8. package/dist/report/{react → assets}/colors.d.ts +8 -0
  9. package/dist/report/{react → assets}/colors.js +23 -0
  10. package/dist/report/built-in/index.d.ts +2 -2
  11. package/dist/report/built-in/index.js +2 -2
  12. package/dist/report/built-in/standard.d.ts +8 -1
  13. package/dist/report/built-in/standard.js +17 -7
  14. package/dist/report/components/attempt-detail/AttemptAssertions.d.ts +6 -0
  15. package/dist/report/components/attempt-detail/AttemptAssertions.js +17 -0
  16. package/dist/report/components/attempt-detail/AttemptConversation.d.ts +6 -0
  17. package/dist/report/components/attempt-detail/AttemptConversation.js +34 -0
  18. package/dist/report/components/attempt-detail/AttemptDiagnostics.d.ts +6 -0
  19. package/dist/report/components/attempt-detail/AttemptDiagnostics.js +7 -0
  20. package/dist/report/components/attempt-detail/AttemptDiff.d.ts +6 -0
  21. package/dist/report/components/attempt-detail/AttemptDiff.js +11 -0
  22. package/dist/report/components/attempt-detail/AttemptError.d.ts +6 -0
  23. package/dist/report/components/attempt-detail/AttemptError.js +16 -0
  24. package/dist/report/components/attempt-detail/AttemptFixPrompt.d.ts +6 -0
  25. package/dist/report/components/attempt-detail/AttemptFixPrompt.js +7 -0
  26. package/dist/report/components/attempt-detail/AttemptSource.d.ts +6 -0
  27. package/dist/report/components/attempt-detail/AttemptSource.js +27 -0
  28. package/dist/report/components/attempt-detail/AttemptSummary.d.ts +8 -0
  29. package/dist/report/components/attempt-detail/AttemptSummary.js +20 -0
  30. package/dist/report/components/attempt-detail/AttemptTimeline.d.ts +6 -0
  31. package/dist/report/components/attempt-detail/AttemptTimeline.js +28 -0
  32. package/dist/report/components/attempt-detail/AttemptTrace.d.ts +6 -0
  33. package/dist/report/components/attempt-detail/AttemptTrace.js +29 -0
  34. package/dist/report/components/attempt-detail/AttemptUsage.d.ts +6 -0
  35. package/dist/report/components/attempt-detail/AttemptUsage.js +20 -0
  36. package/dist/report/components/attempt-detail/compute.d.ts +24 -0
  37. package/dist/report/components/attempt-detail/compute.js +254 -0
  38. package/dist/report/components/attempt-detail/faces.d.ts +14 -0
  39. package/dist/report/components/attempt-detail/faces.js +235 -0
  40. package/dist/report/components/attempt-detail/index.d.ts +38 -0
  41. package/dist/report/components/attempt-detail/index.js +527 -0
  42. package/dist/report/{react → components}/cell.d.ts +5 -3
  43. package/dist/report/{react → components}/cell.js +3 -3
  44. package/dist/report/{react → components/entity-lists}/AttemptList.d.ts +8 -4
  45. package/dist/report/{react → components/entity-lists}/AttemptList.js +16 -10
  46. package/dist/report/{react → components/entity-lists}/EvalList.d.ts +3 -3
  47. package/dist/report/{react → components/entity-lists}/EvalList.js +0 -0
  48. package/dist/report/{react → components/entity-lists}/ExperimentList.d.ts +3 -3
  49. package/dist/report/{react → components/entity-lists}/ExperimentList.js +10 -10
  50. package/dist/report/components/entity-lists/compute.d.ts +23 -0
  51. package/dist/report/components/entity-lists/compute.js +171 -0
  52. package/dist/report/components/entity-lists/faces.d.ts +5 -0
  53. package/dist/report/components/entity-lists/faces.js +174 -0
  54. package/dist/report/components/entity-lists/index.d.ts +51 -0
  55. package/dist/report/components/entity-lists/index.js +165 -0
  56. package/dist/report/{react → components}/fixtures.d.ts +2 -2
  57. package/dist/report/{react → components}/fixtures.js +1 -1
  58. package/dist/report/{react → components/metric-views}/DeltaTable.d.ts +2 -2
  59. package/dist/report/{react → components/metric-views}/DeltaTable.js +4 -4
  60. package/dist/report/{react → components/metric-views}/MetricBars.d.ts +3 -3
  61. package/dist/report/{react → components/metric-views}/MetricBars.js +3 -3
  62. package/dist/report/{react → components/metric-views}/MetricLine.d.ts +2 -2
  63. package/dist/report/{react → components/metric-views}/MetricLine.js +8 -5
  64. package/dist/report/{react → components/metric-views}/MetricMatrix.d.ts +3 -3
  65. package/dist/report/{react → components/metric-views}/MetricMatrix.js +4 -4
  66. package/dist/report/components/metric-views/MetricScatter.d.ts +11 -0
  67. package/dist/report/{react → components/metric-views}/MetricScatter.js +26 -23
  68. package/dist/report/{react → components/metric-views}/MetricTable.d.ts +3 -3
  69. package/dist/report/{react → components/metric-views}/MetricTable.js +4 -4
  70. package/dist/report/{react → components/metric-views}/Scoreboard.d.ts +2 -2
  71. package/dist/report/{react → components/metric-views}/Scoreboard.js +3 -3
  72. package/dist/report/components/metric-views/compute.d.ts +89 -0
  73. package/dist/report/{compute.js → components/metric-views/compute.js} +32 -415
  74. package/dist/report/components/metric-views/faces.d.ts +13 -0
  75. package/dist/report/components/metric-views/faces.js +381 -0
  76. package/dist/report/components/metric-views/index.d.ts +50 -0
  77. package/dist/report/components/metric-views/index.js +273 -0
  78. package/dist/report/{text → components/metric-views}/plot.js +1 -1
  79. package/dist/report/components/shared-compute.d.ts +22 -0
  80. package/dist/report/components/shared-compute.js +47 -0
  81. package/dist/report/components/shared-faces.d.ts +9 -0
  82. package/dist/report/components/shared-faces.js +26 -0
  83. package/dist/report/components/shared.d.ts +68 -0
  84. package/dist/report/components/shared.js +125 -0
  85. package/dist/report/{react → components/site-components}/CopyFixPrompt.d.ts +2 -2
  86. package/dist/report/{react → components/site-components}/CopyFixPrompt.js +2 -2
  87. package/dist/report/{react → components/site-components}/HeroCard.d.ts +2 -2
  88. package/dist/report/{react → components/site-components}/HeroCard.js +2 -2
  89. package/dist/report/{react → components/site-components}/ScopeWarnings.d.ts +2 -2
  90. package/dist/report/{react → components/site-components}/ScopeWarnings.js +3 -3
  91. package/dist/report/{react → components/site-components}/TraceWaterfall.d.ts +3 -3
  92. package/dist/report/{react → components/site-components}/TraceWaterfall.js +5 -5
  93. package/dist/report/components/site-components/compute.d.ts +28 -0
  94. package/dist/report/components/site-components/compute.js +132 -0
  95. package/dist/report/components/site-components/faces.d.ts +21 -0
  96. package/dist/report/components/site-components/faces.js +75 -0
  97. package/dist/report/components/site-components/index.d.ts +74 -0
  98. package/dist/report/components/site-components/index.js +220 -0
  99. package/dist/report/{scope-warnings.d.ts → components/site-components/scope-warnings.d.ts} +2 -2
  100. package/dist/report/{scope-warnings.js → components/site-components/scope-warnings.js} +2 -2
  101. package/dist/report/{react → components/summaries}/ScopeSummary.d.ts +2 -2
  102. package/dist/report/{react → components/summaries}/ScopeSummary.js +17 -8
  103. package/dist/report/components/summaries/compute.d.ts +7 -0
  104. package/dist/report/components/summaries/compute.js +51 -0
  105. package/dist/report/components/summaries/faces.d.ts +7 -0
  106. package/dist/report/components/summaries/faces.js +38 -0
  107. package/dist/report/components/summaries/index.d.ts +27 -0
  108. package/dist/report/components/summaries/index.js +78 -0
  109. package/dist/report/definition/grid-layout.d.ts +50 -0
  110. package/dist/report/definition/grid-layout.js +89 -0
  111. package/dist/report/{primitives.d.ts → definition/primitives.d.ts} +34 -4
  112. package/dist/report/{primitives.js → definition/primitives.js} +101 -10
  113. package/dist/report/{report.d.ts → definition/report.d.ts} +36 -65
  114. package/dist/report/{report.js → definition/report.js} +58 -90
  115. package/dist/report/{text/table.d.ts → definition/table-text.d.ts} +2 -2
  116. package/dist/report/{text/table.js → definition/table-text.js} +2 -2
  117. package/dist/report/{tree.d.ts → definition/tree.d.ts} +43 -11
  118. package/dist/report/{tree.js → definition/tree.js} +9 -11
  119. package/dist/report/index.d.ts +33 -18
  120. package/dist/report/index.js +23 -14
  121. package/dist/report/{aggregate.d.ts → model/aggregate.d.ts} +12 -4
  122. package/dist/report/{aggregate.js → model/aggregate.js} +28 -8
  123. package/dist/report/{flag.d.ts → model/flag.d.ts} +14 -1
  124. package/dist/report/{flag.js → model/flag.js} +35 -0
  125. package/dist/report/{format.d.ts → model/format.d.ts} +11 -5
  126. package/dist/report/{format.js → model/format.js} +48 -4
  127. package/dist/report/{locale.d.ts → model/locale.d.ts} +17 -17
  128. package/dist/report/{locale.js → model/locale.js} +31 -33
  129. package/dist/report/{metrics.d.ts → model/metrics.d.ts} +2 -2
  130. package/dist/report/{metrics.js → model/metrics.js} +2 -2
  131. package/dist/report/{types.d.ts → model/types.d.ts} +140 -20
  132. package/dist/report/react/index.d.ts +32 -21
  133. package/dist/report/react/index.js +33 -21
  134. package/dist/report/{load.d.ts → runtime/load.d.ts} +1 -1
  135. package/dist/report/{load.js → runtime/load.js} +1 -1
  136. package/dist/report/runtime/text.d.ts +67 -0
  137. package/dist/report/runtime/text.js +114 -0
  138. package/dist/report/runtime/web.d.ts +35 -0
  139. package/dist/report/runtime/web.js +70 -0
  140. package/dist/results/annotated-source.d.ts +87 -0
  141. package/dist/results/attempt-evidence.d.ts +74 -0
  142. package/dist/results/attempt-source.d.ts +15 -0
  143. package/dist/results/select.d.ts +11 -1
  144. package/dist/results/select.js +27 -5
  145. package/dist/runner/eval-selection.d.ts +26 -0
  146. package/dist/runner/feedback/sink.d.ts +26 -1
  147. package/dist/runner/types.d.ts +149 -23
  148. package/dist/sandbox/docker.d.ts +6 -0
  149. package/dist/sandbox/types.d.ts +23 -21
  150. package/dist/scoring/display.d.ts +7 -2
  151. package/dist/scoring/display.js +42 -4
  152. package/dist/scoring/types.d.ts +3 -3
  153. package/dist/shared/aggregate.d.ts +14 -0
  154. package/dist/shared/aggregate.js +31 -0
  155. package/dist/shared/types.d.ts +6 -1
  156. package/docs-site/images/logo-dark.svg +7 -0
  157. package/docs-site/images/logo.svg +6 -5
  158. package/docs-site/zh/README.md +8 -7
  159. package/docs-site/zh/examples/ai-agent-application.mdx +5 -5
  160. package/docs-site/zh/examples/coding-agent-extensions.mdx +4 -4
  161. package/docs-site/zh/examples/index.mdx +3 -3
  162. package/docs-site/zh/examples/integrations/ai-sdk-v7.mdx +1 -1
  163. package/docs-site/zh/examples/integrations/claude-sdk.mdx +3 -3
  164. package/docs-site/zh/examples/integrations/codex-sdk.mdx +3 -3
  165. package/docs-site/zh/examples/integrations/langgraph.mdx +3 -3
  166. package/docs-site/zh/examples/integrations/pi-sdk.mdx +2 -2
  167. package/docs-site/zh/explanation/adapter.mdx +19 -19
  168. package/docs-site/zh/explanation/assert.mdx +9 -9
  169. package/docs-site/zh/explanation/drive.mdx +4 -4
  170. package/docs-site/zh/explanation/evals.mdx +8 -8
  171. package/docs-site/zh/explanation/experiment.mdx +8 -8
  172. package/docs-site/zh/explanation/hitl.mdx +13 -13
  173. package/docs-site/zh/explanation/judge.mdx +3 -3
  174. package/docs-site/zh/explanation/overview.mdx +7 -7
  175. package/docs-site/zh/explanation/runner.mdx +11 -11
  176. package/docs-site/zh/explanation/tier.mdx +6 -6
  177. package/docs-site/zh/index.mdx +14 -14
  178. package/docs-site/zh/introduction.mdx +13 -16
  179. package/docs-site/zh/reference/builtin-agents.mdx +61 -28
  180. package/docs-site/zh/reference/capabilities.mdx +7 -27
  181. package/docs-site/zh/reference/cli.mdx +35 -32
  182. package/docs-site/zh/reference/define-agent.mdx +32 -31
  183. package/docs-site/zh/reference/define-config.mdx +6 -6
  184. package/docs-site/zh/reference/define-eval.mdx +33 -20
  185. package/docs-site/zh/reference/events.mdx +4 -4
  186. package/docs-site/zh/reference/expect.mdx +3 -3
  187. package/docs-site/zh/reference/official-adapters.mdx +17 -17
  188. package/docs-site/zh/reference/report-components.mdx +193 -121
  189. package/docs-site/zh/reference/results-data.mdx +13 -13
  190. package/docs-site/zh/troubleshooting/debug-sandbox.mdx +11 -11
  191. package/docs-site/zh/troubleshooting/debugging.mdx +40 -16
  192. package/docs-site/zh/{how-to → tutorials}/agent-feedback-loop.mdx +38 -38
  193. package/docs-site/zh/tutorials/agent-onboarding.mdx +100 -0
  194. package/docs-site/zh/tutorials/authoring.mdx +211 -0
  195. package/docs-site/zh/{how-to → tutorials}/ci-integration.mdx +8 -8
  196. package/docs-site/zh/{how-to → tutorials}/connect-otel.mdx +22 -22
  197. package/docs-site/zh/{how-to → tutorials}/connect-your-agent.mdx +58 -63
  198. package/docs-site/zh/tutorials/custom-reports.mdx +453 -0
  199. package/docs-site/zh/{how-to → tutorials}/dataset-fanout.mdx +4 -4
  200. package/docs-site/zh/tutorials/experiments.mdx +103 -0
  201. package/docs-site/zh/{how-to → tutorials}/fixtures.mdx +9 -9
  202. package/docs-site/zh/{how-to → tutorials}/publish-report.mdx +6 -6
  203. package/docs-site/zh/tutorials/quickstart.mdx +18 -18
  204. package/docs-site/zh/{how-to → tutorials}/reporters.mdx +6 -6
  205. package/docs-site/zh/{how-to → tutorials}/sandbox-agent.mdx +6 -6
  206. package/docs-site/zh/{how-to → tutorials}/sandbox-providers.mdx +41 -19
  207. package/docs-site/zh/{how-to → tutorials}/scoring-guide.mdx +4 -4
  208. package/docs-site/zh/{how-to → tutorials}/viewing-results.mdx +49 -49
  209. package/docs-site/zh/tutorials/write-experiment.mdx +355 -0
  210. package/docs-site/zh/{how-to → tutorials}/write-send.mdx +40 -40
  211. package/package.json +8 -4
  212. package/src/agents/bub.ts +21 -8
  213. package/src/agents/claude-code.ts +23 -10
  214. package/src/agents/codex.test.ts +22 -7
  215. package/src/agents/codex.ts +22 -9
  216. package/src/agents/index.ts +2 -2
  217. package/src/agents/openai-compat.ts +1 -1
  218. package/src/agents/post-setup.ts +45 -22
  219. package/src/agents/streaming.ts +1 -1
  220. package/src/agents/types.ts +20 -17
  221. package/src/agents/ui-message-stream.test.ts +10 -0
  222. package/src/agents/ui-message-stream.ts +12 -1
  223. package/src/cli.ts +71 -57
  224. package/src/context/types.ts +21 -21
  225. package/src/define.ts +13 -0
  226. package/src/i18n/en.ts +27 -12
  227. package/src/i18n/zh-CN.ts +27 -12
  228. package/src/index.ts +2 -0
  229. package/src/report/{react → assets}/colors.ts +22 -0
  230. package/src/report/{react → assets}/enhance.js +1 -33
  231. package/src/report/{react → assets}/styles.css +124 -106
  232. package/src/report/built-in/index.tsx +2 -2
  233. package/src/report/built-in/standard.tsx +18 -6
  234. package/src/report/components/attempt-detail/AttemptAssertions.tsx +67 -0
  235. package/src/report/components/attempt-detail/AttemptConversation.tsx +110 -0
  236. package/src/report/components/attempt-detail/AttemptDiagnostics.tsx +38 -0
  237. package/src/report/components/attempt-detail/AttemptDiff.tsx +35 -0
  238. package/src/report/components/attempt-detail/AttemptError.tsx +31 -0
  239. package/src/report/components/attempt-detail/AttemptFixPrompt.tsx +26 -0
  240. package/src/report/components/attempt-detail/AttemptSource.tsx +80 -0
  241. package/src/report/components/attempt-detail/AttemptSummary.tsx +74 -0
  242. package/src/report/components/attempt-detail/AttemptTimeline.tsx +108 -0
  243. package/src/report/components/attempt-detail/AttemptTrace.tsx +63 -0
  244. package/src/report/components/attempt-detail/AttemptUsage.tsx +29 -0
  245. package/src/report/components/attempt-detail/attempt-components.test.tsx +680 -0
  246. package/src/report/components/attempt-detail/compute.ts +287 -0
  247. package/src/report/components/attempt-detail/faces.ts +257 -0
  248. package/src/report/components/attempt-detail/index.tsx +583 -0
  249. package/src/report/components/attempt-detail/validate.test.ts +235 -0
  250. package/src/report/{react → components}/cell.tsx +6 -3
  251. package/src/report/{report.test.ts → components/compute.test.ts} +316 -46
  252. package/src/report/{react → components/entity-lists}/AttemptList.tsx +24 -16
  253. package/src/report/{react → components/entity-lists}/EvalList.tsx +0 -0
  254. package/src/report/{react → components/entity-lists}/ExperimentList.tsx +23 -20
  255. package/src/report/components/entity-lists/compute.ts +196 -0
  256. package/src/report/components/entity-lists/faces.ts +207 -0
  257. package/src/report/components/entity-lists/index.tsx +241 -0
  258. package/src/report/components/entity-lists/validate.test.ts +114 -0
  259. package/src/report/{react → components}/fixtures.ts +2 -2
  260. package/src/report/{react → components/metric-views}/DeltaTable.tsx +5 -5
  261. package/src/report/{react → components/metric-views}/MetricBars.tsx +5 -5
  262. package/src/report/{react → components/metric-views}/MetricLine.tsx +9 -6
  263. package/src/report/{react → components/metric-views}/MetricMatrix.tsx +6 -6
  264. package/src/report/{react → components/metric-views}/MetricScatter.tsx +41 -33
  265. package/src/report/{react → components/metric-views}/MetricTable.tsx +6 -6
  266. package/src/report/{react → components/metric-views}/Scoreboard.tsx +4 -4
  267. package/src/report/{compute.ts → components/metric-views/compute.ts} +51 -477
  268. package/src/report/components/metric-views/faces.ts +423 -0
  269. package/src/report/components/metric-views/index.tsx +352 -0
  270. package/src/report/{text → components/metric-views}/plot.ts +1 -1
  271. package/src/report/components/metric-views/validate.test.ts +211 -0
  272. package/src/report/{react → components}/render.test.tsx +47 -17
  273. package/src/report/components/shared-compute.ts +59 -0
  274. package/src/report/components/shared-faces.ts +30 -0
  275. package/src/report/components/shared.ts +192 -0
  276. package/src/report/{react → components/site-components}/CopyFixPrompt.tsx +3 -3
  277. package/src/report/{react → components/site-components}/HeroCard.tsx +3 -3
  278. package/src/report/{react → components/site-components}/ScopeWarnings.tsx +4 -4
  279. package/src/report/{react → components/site-components}/TraceWaterfall.tsx +13 -10
  280. package/src/report/components/site-components/compute.ts +144 -0
  281. package/src/report/components/site-components/faces.ts +80 -0
  282. package/src/report/components/site-components/index.tsx +265 -0
  283. package/src/report/{scope-warnings.ts → components/site-components/scope-warnings.ts} +3 -3
  284. package/src/report/{site-components.test.tsx → components/site-components/site-components.test.tsx} +23 -21
  285. package/src/report/components/site-components/validate.test.ts +89 -0
  286. package/src/report/{react → components/summaries}/ScopeSummary.tsx +26 -11
  287. package/src/report/components/summaries/compute.ts +56 -0
  288. package/src/report/components/summaries/faces.ts +48 -0
  289. package/src/report/components/summaries/index.tsx +127 -0
  290. package/src/report/components/summaries/validate.test.ts +49 -0
  291. package/src/report/definition/grid-layout.test.ts +124 -0
  292. package/src/report/definition/grid-layout.ts +146 -0
  293. package/src/report/{primitives.tsx → definition/primitives.tsx} +168 -18
  294. package/src/report/{report.ts → definition/report.ts} +98 -165
  295. package/src/report/{shell-head.test.ts → definition/shell-head.test.ts} +2 -2
  296. package/src/report/{text/table.ts → definition/table-text.ts} +4 -4
  297. package/src/report/{tree.ts → definition/tree.ts} +56 -20
  298. package/src/report/index.ts +126 -66
  299. package/src/report/{aggregate.ts → model/aggregate.ts} +31 -9
  300. package/src/report/{flag.ts → model/flag.ts} +39 -1
  301. package/src/report/{format.ts → model/format.ts} +59 -5
  302. package/src/report/{locale.ts → model/locale.ts} +34 -36
  303. package/src/report/{metrics.ts → model/metrics.ts} +3 -3
  304. package/src/report/{types.ts → model/types.ts} +143 -22
  305. package/src/report/react/index.tsx +52 -26
  306. package/src/report/{dual-render.test.tsx → runtime/dual-render.test.tsx} +564 -49
  307. package/src/report/runtime/host.test.ts +44 -0
  308. package/src/report/runtime/host.ts +138 -0
  309. package/src/report/{load.ts → runtime/load.ts} +1 -1
  310. package/src/report/runtime/text.ts +192 -0
  311. package/src/report/runtime/web.ts +106 -0
  312. package/src/results/attempt-evidence.ts +5 -1
  313. package/src/results/host-equivalence.test.ts +53 -2
  314. package/src/results/select.ts +29 -5
  315. package/src/runner/attempt.test.ts +48 -1
  316. package/src/runner/attempt.ts +62 -42
  317. package/src/runner/cleanup-timeout.test.ts +16 -0
  318. package/src/runner/cleanup-timeout.ts +23 -0
  319. package/src/runner/discover.ts +1 -2
  320. package/src/runner/eval-selection.test.ts +187 -0
  321. package/src/runner/eval-selection.ts +109 -0
  322. package/src/runner/experiment-cleanup-registry.test.ts +89 -0
  323. package/src/runner/experiment-cleanup-registry.ts +39 -0
  324. package/src/runner/experiment-labels.test.ts +71 -0
  325. package/src/runner/feedback/agent.test.ts +33 -1
  326. package/src/runner/feedback/agent.ts +12 -16
  327. package/src/runner/feedback/ci.test.ts +35 -1
  328. package/src/runner/feedback/ci.ts +16 -18
  329. package/src/runner/feedback/coordinator.ts +28 -0
  330. package/src/runner/feedback/human.test.ts +108 -1
  331. package/src/runner/feedback/human.ts +71 -21
  332. package/src/runner/feedback/reducer.test.ts +64 -0
  333. package/src/runner/feedback/reducer.ts +26 -0
  334. package/src/runner/feedback/sink.ts +40 -1
  335. package/src/runner/fingerprint.ts +2 -1
  336. package/src/runner/report.test.ts +14 -0
  337. package/src/runner/report.ts +3 -1
  338. package/src/runner/run.test.ts +390 -12
  339. package/src/runner/run.ts +259 -26
  340. package/src/runner/sandbox-selection.test.ts +13 -3
  341. package/src/runner/sandbox-selection.ts +4 -2
  342. package/src/runner/types.ts +158 -23
  343. package/src/sandbox/docker.ts +7 -0
  344. package/src/sandbox/e2b.ts +12 -13
  345. package/src/sandbox/types.ts +23 -21
  346. package/src/scoring/display.test.ts +28 -2
  347. package/src/scoring/display.ts +38 -5
  348. package/src/scoring/types.ts +3 -3
  349. package/src/shared/aggregate.test.ts +52 -0
  350. package/src/shared/aggregate.ts +29 -0
  351. package/src/shared/types.ts +6 -1
  352. package/src/show/command.test.ts +34 -0
  353. package/src/show/command.ts +16 -0
  354. package/src/show/compose.ts +1 -1
  355. package/src/show/index.ts +56 -20
  356. package/src/show/render.ts +15 -239
  357. package/src/show/show.test.ts +127 -34
  358. package/src/view/app/App.test.tsx +1 -1
  359. package/src/view/app/App.tsx +119 -47
  360. package/src/view/app/i18n.ts +7 -147
  361. package/src/view/app/lib/attempt-dialog.test.ts +65 -0
  362. package/src/view/app/lib/attempt-dialog.ts +69 -0
  363. package/src/view/app/main.tsx +0 -1
  364. package/src/view/app/types.ts +3 -86
  365. package/src/view/artifact-serving.test.ts +22 -38
  366. package/src/view/client-dist/app.css +1 -1
  367. package/src/view/client-dist/app.js +15 -22
  368. package/src/view/data.test.ts +48 -36
  369. package/src/view/data.ts +105 -83
  370. package/src/view/index.ts +1 -1
  371. package/src/view/server.ts +32 -2
  372. package/src/view/shared/types.ts +6 -31
  373. package/src/view/site-parity.test.ts +24 -1
  374. package/src/view/site.ts +144 -17
  375. package/src/view/styles.css +0 -805
  376. package/src/view/view-report.test.ts +141 -22
  377. package/dist/report/components.d.ts +0 -179
  378. package/dist/report/components.js +0 -544
  379. package/dist/report/compute.d.ts +0 -139
  380. package/dist/report/react/ExperimentComparison.d.ts +0 -10
  381. package/dist/report/react/ExperimentComparison.js +0 -12
  382. package/dist/report/react/MetricScatter.d.ts +0 -9
  383. package/dist/report/react/format.d.ts +0 -3
  384. package/dist/report/react/format.js +0 -7
  385. package/dist/report/text/faces.d.ts +0 -45
  386. package/dist/report/text/faces.js +0 -671
  387. package/dist/report/web.d.ts +0 -32
  388. package/dist/report/web.js +0 -48
  389. package/docs-site/zh/how-to/authoring.mdx +0 -162
  390. package/docs-site/zh/how-to/custom-reports.mdx +0 -414
  391. package/docs-site/zh/how-to/experiments.mdx +0 -86
  392. package/docs-site/zh/how-to/write-experiment.mdx +0 -164
  393. package/src/report/components.tsx +0 -925
  394. package/src/report/react/ExperimentComparison.tsx +0 -73
  395. package/src/report/react/format.ts +0 -9
  396. package/src/report/text/faces.ts +0 -767
  397. package/src/report/web.ts +0 -77
  398. package/src/show/report-host.test.ts +0 -205
  399. package/src/show/report-host.ts +0 -389
  400. package/src/view/app/components/AttemptModal.tsx +0 -496
  401. package/src/view/app/components/CodeView.test.tsx +0 -142
  402. package/src/view/app/components/CodeView.tsx +0 -310
  403. package/src/view/app/components/CopyControls.tsx +0 -106
  404. package/src/view/app/components/Trace.tsx +0 -100
  405. package/src/view/app/components/Transcript.tsx +0 -157
  406. package/src/view/app/components/ui/badge.tsx +0 -21
  407. package/src/view/app/lib/artifact-url.ts +0 -17
  408. package/src/view/app/lib/attempt-route.test.ts +0 -80
  409. package/src/view/app/lib/attempt-route.ts +0 -52
  410. package/src/view/app/lib/format.ts +0 -70
  411. package/src/view/app/lib/guards.test.ts +0 -108
  412. package/src/view/app/lib/guards.ts +0 -71
  413. package/src/view/app/lib/rows.ts +0 -22
  414. package/src/view/app/lib/transcript-data.tsx +0 -151
  415. package/src/view/app/lib/verdict.ts +0 -23
  416. package/src/view/app/shared.ts +0 -8
  417. /package/dist/report/{react → components/metric-views}/chart-math.d.ts +0 -0
  418. /package/dist/report/{react → components/metric-views}/chart-math.js +0 -0
  419. /package/dist/report/{text → components/metric-views}/plot.d.ts +0 -0
  420. /package/dist/report/{react → components/site-components}/PoweredBy.d.ts +0 -0
  421. /package/dist/report/{react → components/site-components}/PoweredBy.js +0 -0
  422. /package/dist/report/{text/layout.d.ts → model/text-layout.d.ts} +0 -0
  423. /package/dist/report/{text/layout.js → model/text-layout.js} +0 -0
  424. /package/dist/report/{types.js → model/types.js} +0 -0
  425. /package/src/report/{react → components/metric-views}/chart-math.test.ts +0 -0
  426. /package/src/report/{react → components/metric-views}/chart-math.ts +0 -0
  427. /package/src/report/{react → components/site-components}/PoweredBy.tsx +0 -0
  428. /package/src/report/{text/layout.ts → model/text-layout.ts} +0 -0
@@ -0,0 +1,423 @@
1
+ // 指标图形族(MetricTable / MetricMatrix / MetricBars / Scoreboard / MetricScatter /
2
+ // MetricLine / DeltaTable)的 text 面:同一份算好的数据,渲染成终端字符
3
+ // (niceeval show 的形态)。与 web 面共守诚实契约:排序随 better、samples < total 角标、
4
+ // 缺数据 — 不补 0、截断报剩余。零 react、零 IO、纯同步。
5
+
6
+ import type {
7
+ DeltaData,
8
+ LineData,
9
+ MatrixData,
10
+ MetricCell,
11
+ MetricColumn,
12
+ ScatterData,
13
+ ScoreboardData,
14
+ TableData,
15
+ } from "../../model/types.ts";
16
+ import type { TextContext } from "../../definition/tree.ts";
17
+ import type { TableColumn, TableRow } from "../../definition/primitives.tsx";
18
+ import { formatMetricValue, formatPlainNumber } from "../../model/format.ts";
19
+ import { countText, localeText, resolveLocalizedText, resolveMetricLabel, type ReportLocale } from "../../model/locale.ts";
20
+ import { padDisplay, stringWidth, textBar } from "../../model/text-layout.ts";
21
+ import { renderTableText } from "../../definition/table-text.ts";
22
+ import { renderCharPlot, renderCoordinateTable, type PlotPoint } from "./plot.ts";
23
+ import { cellText, missingText, MISSING_MARK } from "../shared-faces.ts";
24
+
25
+ // ───────────────────────── MetricTable ─────────────────────────
26
+
27
+ export function tableText(data: TableData, ctx: TextContext): string {
28
+ const locale = ctx.locale;
29
+ const columns: TableColumn[] = [
30
+ { key: "dimension", header: data.rowDimension },
31
+ // 指标列的键用序号,不用 metric name —— 维度名和指标名在同一个命名空间里,可能撞键。
32
+ ...data.columns.map((c, i) => ({ key: `metric${i}`, header: resolveMetricLabel(c.label, locale, c.key) })),
33
+ ];
34
+ const rows: TableRow[] = data.rows.map((row) => {
35
+ const cells: Record<string, string | null> = { dimension: row.key };
36
+ data.columns.forEach((col, i) => {
37
+ const cell = row.cells[col.key];
38
+ cells[`metric${i}`] = cell ? cellText(cell, locale) : null;
39
+ });
40
+ return { key: row.key, cells };
41
+ });
42
+ return renderTableText({ columns: columns as unknown as [TableColumn, ...TableColumn[]], rows, locale }, ctx);
43
+ }
44
+
45
+ // ───────────────────────── MetricMatrix ─────────────────────────
46
+
47
+ export function matrixText(data: MatrixData, ctx: TextContext): string {
48
+ // 表体全是维度键与 display,没有 chrome 文案;"next:" 是命令提示,不本地化。
49
+ const locale = ctx.locale;
50
+ const rowKeys: string[] = [];
51
+ const columnKeys: string[] = [];
52
+ const byPosition = new Map<string, MetricCell>();
53
+ for (const entry of data.cells) {
54
+ if (!rowKeys.includes(entry.row)) rowKeys.push(entry.row);
55
+ if (!columnKeys.includes(entry.column)) columnKeys.push(entry.column);
56
+ byPosition.set(JSON.stringify([entry.row, entry.column]), entry.cell);
57
+ }
58
+ const columns: TableColumn[] = [
59
+ { key: "dimension", header: data.rowDimension },
60
+ ...columnKeys.map((column, i) => ({ key: `column${i}`, header: column })),
61
+ ];
62
+ const rows: TableRow[] = rowKeys.map((row) => {
63
+ const cells: Record<string, string | null> = { dimension: row };
64
+ columnKeys.forEach((column, i) => {
65
+ const cell = byPosition.get(JSON.stringify([row, column]));
66
+ cells[`column${i}`] = cell ? cellText(cell, locale) : null; // 稀疏格子在文本里以 — 呈现,不编数
67
+ });
68
+ return { key: row, cells };
69
+ });
70
+ const table = renderTableText({ columns: columns as unknown as [TableColumn, ...TableColumn[]], rows, locale }, ctx);
71
+
72
+ // 下钻命令:行维度是 eval 时,指向最值得看的一行(先挑有缺格的,再挑按 better 最差的)
73
+ if (data.rowDimension !== "eval" || rowKeys.length === 0) return table;
74
+ const better = data.metric.better ?? "higher";
75
+ let next: string | undefined;
76
+ let worst: { key: string; value: number } | undefined;
77
+ for (const row of rowKeys) {
78
+ let sum = 0;
79
+ let count = 0;
80
+ for (const column of columnKeys) {
81
+ const cell = byPosition.get(JSON.stringify([row, column]));
82
+ if (!cell || cell.value === null) {
83
+ next ??= row;
84
+ continue;
85
+ }
86
+ sum += cell.value;
87
+ count += 1;
88
+ }
89
+ if (count > 0) {
90
+ const value = sum / count;
91
+ const isWorse = worst === undefined || (better === "higher" ? value < worst.value : value > worst.value);
92
+ if (isWorse) worst = { key: row, value };
93
+ }
94
+ }
95
+ next ??= worst?.key;
96
+ return next === undefined ? table : `${table}\n\nnext: niceeval show ${next}`;
97
+ }
98
+
99
+ // ───────────────────────── MetricBars(矩阵数据的另一种摆法)─────────────────────────
100
+
101
+ const BAR_WIDTH = 20;
102
+
103
+ export function barsText(data: MatrixData, ctx: TextContext): string {
104
+ const locale = ctx.locale;
105
+ const groupKeys: string[] = [];
106
+ const seriesKeys: string[] = [];
107
+ const byPosition = new Map<string, MetricCell>();
108
+ for (const entry of data.cells) {
109
+ if (!groupKeys.includes(entry.row)) groupKeys.push(entry.row);
110
+ if (!seriesKeys.includes(entry.column)) seriesKeys.push(entry.column);
111
+ byPosition.set(JSON.stringify([entry.row, entry.column]), entry.cell);
112
+ }
113
+ const better = data.metric.better ?? "higher";
114
+ // 条长刻度:% 的天然域是 [0,1],其余以全图最大值为满条
115
+ const values = data.cells.map((c) => c.cell.value).filter((v): v is number => v !== null);
116
+ const maxValue = values.length > 0 ? Math.max(...values) : 0;
117
+ const ratioOf = (value: number) => (data.metric.unit === "%" ? value : maxValue === 0 ? 0 : value / maxValue);
118
+
119
+ const seriesWidth = Math.max(...seriesKeys.map((k) => stringWidth(k)), 0);
120
+ const lines: string[] = [];
121
+ for (const group of groupKeys) {
122
+ lines.push(group);
123
+ const entries = seriesKeys.map((series) => ({
124
+ series,
125
+ cell: byPosition.get(JSON.stringify([group, series])),
126
+ }));
127
+ // 组内按值排序,方向随 better(缺数据沉底)
128
+ entries.sort((a, b) => {
129
+ const va = a.cell?.value ?? null;
130
+ const vb = b.cell?.value ?? null;
131
+ if (va === null && vb === null) return 0;
132
+ if (va === null) return 1;
133
+ if (vb === null) return -1;
134
+ return better === "lower" ? va - vb : vb - va;
135
+ });
136
+ for (const { series, cell } of entries) {
137
+ const label = padDisplay(series, seriesWidth);
138
+ if (!cell || cell.value === null) {
139
+ lines.push(` ${label} ${MISSING_MARK}`);
140
+ continue;
141
+ }
142
+ lines.push(` ${label} ${textBar(ratioOf(cell.value), BAR_WIDTH)} ${cellText(cell, locale)}`);
143
+ }
144
+ }
145
+ return lines.join("\n");
146
+ }
147
+
148
+ // ───────────────────────── Scoreboard ─────────────────────────
149
+
150
+ export function scoreboardText(data: ScoreboardData, ctx: TextContext): string {
151
+ const locale = ctx.locale;
152
+ const subjectKeys: string[] = [];
153
+ for (const row of data.rows) {
154
+ for (const subject of row.subjects) {
155
+ if (!subjectKeys.includes(subject.key)) subjectKeys.push(subject.key);
156
+ }
157
+ }
158
+ const columns: TableColumn[] = [
159
+ { key: "dimension", header: data.rowDimension },
160
+ { key: "total", header: localeText(locale, "scoreboard.totalText") },
161
+ ...subjectKeys.map((key, i) => ({ key: `subject${i}`, header: key })),
162
+ ];
163
+ const rows: TableRow[] = data.rows.map((row) => {
164
+ const totalNotes = [
165
+ ...(row.total.notRun > 0 ? [localeText(locale, "scoreboard.notRunText", { n: row.total.notRun })] : []),
166
+ ...(row.total.unscorable > 0 ? [localeText(locale, "scoreboard.unscorableText", { n: row.total.unscorable })] : []),
167
+ ];
168
+ const cells: Record<string, string | null> = {
169
+ dimension: row.key,
170
+ total: `${resolveLocalizedText(row.total.display, locale)}/${data.fullMarks}${totalNotes.length > 0 ? ` ${totalNotes.join(" ")}` : ""}`,
171
+ };
172
+ subjectKeys.forEach((key, i) => {
173
+ const subject = row.subjects.find((s) => s.key === key);
174
+ if (!subject) {
175
+ cells[`subject${i}`] = null;
176
+ return;
177
+ }
178
+ const score = `${formatPlainNumber(subject.earned)}/${formatPlainNumber(subject.possible)}`;
179
+ const notes = [
180
+ ...(subject.notRun > 0 ? [localeText(locale, "scoreboard.notRunText", { n: subject.notRun })] : []),
181
+ ...(subject.unscorable > 0 ? [localeText(locale, "scoreboard.unscorableText", { n: subject.unscorable })] : []),
182
+ ];
183
+ cells[`subject${i}`] = notes.length > 0 ? `${score} ${notes.join(" ")}` : score;
184
+ });
185
+ return { key: row.key, cells };
186
+ });
187
+ const table = renderTableText({ columns: columns as unknown as [TableColumn, ...TableColumn[]], rows, locale }, ctx);
188
+ const footnotes: string[] = [];
189
+ if (data.weights.length > 0) {
190
+ const weights = data.weights.map((w) => `${w.prefix} ×${w.weight}`).join(" · ");
191
+ footnotes.push(`${localeText(locale, "scoreboard.weights")} ${weights} · ${localeText(locale, "scoreboard.othersWeight")}`);
192
+ }
193
+ if (data.ignoredEvals > 0) footnotes.push(countText(locale, "scoreboard.ignored", data.ignoredEvals));
194
+ return footnotes.length > 0 ? `${table}\n${footnotes.join("\n")}` : table;
195
+ }
196
+
197
+ // ───────────────────────── MetricScatter ─────────────────────────
198
+
199
+ const POINT_MARKS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
200
+
201
+ function axisLabel(col: MetricColumn, locale: ReportLocale): string {
202
+ return resolveMetricLabel(col.label, locale, col.key);
203
+ }
204
+
205
+ /**
206
+ * 方向提示:轴向已随 better 反正(lower 反向),「更好」恒指向右上,文案恒为
207
+ * 「越靠右上越好」;仅当 x、y 都声明 better 时显示——任一轴未声明,组件不猜
208
+ * 「更好」朝哪边,整图无提示(返回 undefined)。
209
+ */
210
+ function betterCornerText(x: MetricColumn, y: MetricColumn, locale: ReportLocale): string | undefined {
211
+ if (x.better === undefined || y.better === undefined) return undefined;
212
+ return localeText(locale, "scatter.betterUpperRight");
213
+ }
214
+
215
+ /** 轴标题行:"<x label>(越低越好) × <y label>"——better 方向如实标注,不虚构轴向。 */
216
+ function scatterHeading(data: ScatterData, locale: ReportLocale): string {
217
+ const withBetter = (col: MetricColumn) => {
218
+ const label = axisLabel(col, locale);
219
+ if (col.better === undefined) return label;
220
+ return `${label}(${localeText(locale, col.better === "lower" ? "table.lowerBetter" : "table.higherBetter")})`;
221
+ };
222
+ return `${withBetter(data.x)} × ${withBetter(data.y)}`;
223
+ }
224
+
225
+ export interface ScatterTextOptions {
226
+ /** series 内按 x 升序成线:坐标图内不画折线,图例以 ` → ` 串联并给逐段位移摘要。 */
227
+ connect?: boolean;
228
+ }
229
+
230
+ /** 位移摘要里的带符号差值;`%` 的差是百分点,单位写 pt(docs/feature/reports/show/default-report.md)。 */
231
+ function signedDelta(value: number, unit?: string): string {
232
+ const text = formatMetricValue(value, unit);
233
+ const signed = value >= 0 ? `+${text}` : text;
234
+ return unit === "%" ? signed.replace("%", "pt") : signed;
235
+ }
236
+
237
+ export function scatterText(data: ScatterData, ctx: TextContext, opts?: ScatterTextOptions): string {
238
+ const locale = ctx.locale;
239
+ const connect = opts?.connect === true && data.seriesDimension !== undefined;
240
+ const drawable = data.rows.filter((r) => r.x.value !== null && r.y.value !== null);
241
+ const missing = data.rows.length - drawable.length;
242
+ const footnotes: string[] = [];
243
+ if (missing > 0) footnotes.push(countText(locale, "pointsMissing", missing));
244
+
245
+ const axes = { x: axisLabel(data.x, locale), y: axisLabel(data.y, locale) };
246
+ // 0 个可画点:x/y 指标没有可用数据(与 web 面同一事实)。
247
+ if (drawable.length === 0) {
248
+ return [localeText(locale, "scatter.noData", axes), ...footnotes].join("\n");
249
+ }
250
+ // 标题行尾标注归类维度(· 按 <series> 归类)。
251
+ const heading =
252
+ data.seriesDimension !== undefined
253
+ ? `${scatterHeading(data, locale)} · ${localeText(locale, "scatter.groupedBy", { dim: data.seriesDimension })}`
254
+ : scatterHeading(data, locale);
255
+
256
+ // 标记分配顺序即图例顺序:series 按显示键字典序、series 内按 x 原始值升序;
257
+ // 无 series 时保持点键字典序(rows 本身已按维度 key 排序)。
258
+ const ordered =
259
+ data.seriesDimension === undefined
260
+ ? drawable
261
+ : [...drawable].sort((a, b) => {
262
+ const sa = a.series ?? "";
263
+ const sb = b.series ?? "";
264
+ if (sa !== sb) return sa < sb ? -1 : 1;
265
+ return (a.x.value as number) - (b.x.value as number);
266
+ });
267
+
268
+ // 点太密排不下时降级为坐标表,不硬挤
269
+ if (ordered.length > POINT_MARKS.length || ctx.width < 44) {
270
+ const table = renderCoordinateTable(
271
+ ordered.map((r) => ({
272
+ key: r.key,
273
+ x: resolveLocalizedText(r.x.display, locale),
274
+ y: resolveLocalizedText(r.y.display, locale),
275
+ })),
276
+ { key: data.pointDimension, x: axes.x, y: axes.y },
277
+ );
278
+ return [heading, "", table, ...footnotes].join("\n");
279
+ }
280
+
281
+ const points: PlotPoint[] = ordered.map((r, i) => ({
282
+ mark: POINT_MARKS[i],
283
+ x: r.x.value as number,
284
+ y: r.y.value as number,
285
+ }));
286
+ // series 分组(ordered 已按 series、x 排好序);connect 的折线只进 web 面,
287
+ // text 面用图例的 → 串联 + 位移摘要表达同一条线,坐标图内不画折线。
288
+ const rowsBySeries = new Map<string, typeof ordered>();
289
+ for (const r of ordered) {
290
+ if (r.series === undefined) continue;
291
+ const list = rowsBySeries.get(r.series) ?? [];
292
+ list.push(r);
293
+ rowsBySeries.set(r.series, list);
294
+ }
295
+
296
+ const plot = renderCharPlot({
297
+ width: ctx.width,
298
+ points,
299
+ lines: [],
300
+ xLabel: axes.x,
301
+ yLabel: axes.y,
302
+ formatX: (v) => formatMetricValue(v, data.x.unit),
303
+ formatY: (v) => formatMetricValue(v, data.y.unit),
304
+ // 轴方向跟随 better(与 web 面同规则):lower 反向,higher 与未声明正向。
305
+ invertX: data.x.better === "lower",
306
+ invertY: data.y.better === "lower",
307
+ });
308
+
309
+ const markByKey = new Map(ordered.map((r, i) => [r.key, POINT_MARKS[i]]));
310
+ let legend: string;
311
+ if (data.seriesDimension === undefined) {
312
+ legend = ordered.map((r) => `${markByKey.get(r.key)} ${r.key}`).join(" ");
313
+ } else {
314
+ // 图例一行一个 series:行首 series 显示键,后接线上各点;connect 用 → 串联并给逐段位移摘要。
315
+ const seriesWidth = Math.max(...[...rowsBySeries.keys()].map(stringWidth));
316
+ const lines: string[] = [];
317
+ for (const [series, list] of rowsBySeries) {
318
+ const parts = list.map((r) => `${markByKey.get(r.key)} ${r.key}`);
319
+ lines.push(`${padDisplay(series, seriesWidth)} ${parts.join(connect ? " → " : " ")}`);
320
+ if (connect) {
321
+ for (let i = 1; i < list.length; i++) {
322
+ const a = list[i - 1];
323
+ const b = list[i];
324
+ const dy = signedDelta((b.y.value as number) - (a.y.value as number), data.y.unit);
325
+ const dx = signedDelta((b.x.value as number) - (a.x.value as number), data.x.unit);
326
+ lines.push(`${" ".repeat(seriesWidth + 2)}└ ${axes.y} ${dy} · ${axes.x} ${dx}`);
327
+ }
328
+ }
329
+ }
330
+ legend = lines.join("\n");
331
+ }
332
+ const hint = betterCornerText(data.x, data.y, locale);
333
+ return [heading, plot, "", ...(hint !== undefined ? [hint] : []), legend, ...footnotes].join("\n");
334
+ }
335
+
336
+ // ───────────────────────── MetricLine ─────────────────────────
337
+
338
+ export function lineText(data: LineData, ctx: TextContext): string {
339
+ const locale = ctx.locale;
340
+ const drawable = data.rows.filter((r) => r.x !== null && r.y.value !== null);
341
+ const missing = data.rows.length - drawable.length;
342
+ const footnotes: string[] = [];
343
+ if (missing > 0) footnotes.push(countText(locale, "pointsMissing", missing));
344
+
345
+ if (drawable.length === 0) return [missingText(locale), ...footnotes].join("\n");
346
+
347
+ const xLabel = resolveMetricLabel(data.x.label, locale, data.x.key);
348
+
349
+ // 系列 → 字母;无系列 = 单系列
350
+ const seriesKeys: string[] = [];
351
+ for (const r of drawable) {
352
+ const key = r.series ?? "";
353
+ if (!seriesKeys.includes(key)) seriesKeys.push(key);
354
+ }
355
+
356
+ if (seriesKeys.length > POINT_MARKS.length || ctx.width < 44) {
357
+ const table = renderCoordinateTable(
358
+ drawable.map((r) => ({
359
+ key: r.series !== undefined ? `${r.series} (${r.key})` : r.key,
360
+ x: resolveLocalizedText(r.xDisplay, locale),
361
+ y: resolveLocalizedText(r.y.display, locale),
362
+ })),
363
+ { key: data.seriesDimension ?? xLabel, x: xLabel, y: axisLabel(data.y, locale) },
364
+ );
365
+ return [table, ...footnotes].join("\n");
366
+ }
367
+
368
+ const markOf = (r: LineData["rows"][number]) => POINT_MARKS[seriesKeys.indexOf(r.series ?? "")];
369
+ const points: PlotPoint[] = drawable.map((r) => ({
370
+ mark: markOf(r),
371
+ x: r.x as number,
372
+ y: r.y.value as number,
373
+ }));
374
+ const lines = seriesKeys.map((key) =>
375
+ drawable
376
+ .filter((r) => (r.series ?? "") === key)
377
+ .map((r) => ({ x: r.x as number, y: r.y.value as number }))
378
+ .sort((a, b) => a.x - b.x),
379
+ );
380
+
381
+ const plot = renderCharPlot({
382
+ width: ctx.width,
383
+ points,
384
+ lines: lines.filter((l) => l.length > 1),
385
+ xLabel,
386
+ yLabel: axisLabel(data.y, locale),
387
+ formatX: (v) => formatMetricValue(v, data.x.unit),
388
+ formatY: (v) => formatMetricValue(v, data.y.unit),
389
+ });
390
+ const legend = seriesKeys
391
+ .map((key, i) => `${POINT_MARKS[i]} ${key === "" ? axisLabel(data.y, locale) : key}`)
392
+ .join(" ");
393
+ return [plot, "", legend, ...footnotes].join("\n");
394
+ }
395
+
396
+ // ───────────────────────── DeltaTable ─────────────────────────
397
+
398
+ export function deltaText(data: DeltaData, ctx: TextContext): string {
399
+ const locale = ctx.locale;
400
+ // 0 对不是错误:明确空态并报告配对域实验数(派生形态携带;字面形态缺省按 0)。
401
+ if (data.rows.length === 0) {
402
+ return localeText(locale, "delta.empty", { experiments: data.experiments ?? 0 });
403
+ }
404
+ const columns: TableColumn[] = [
405
+ { key: "pair", header: localeText(locale, "delta.pairHeader") },
406
+ ...data.columns.map((c, i) => ({ key: `metric${i}`, header: resolveMetricLabel(c.label, locale, c.key) })),
407
+ ];
408
+ const rows: TableRow[] = data.rows.map((row) => {
409
+ const cells: Record<string, string | null> = { pair: resolveLocalizedText(row.label, locale) };
410
+ data.columns.forEach((col, i) => {
411
+ const cell = row.cells[col.key];
412
+ if (!cell) {
413
+ cells[`metric${i}`] = null;
414
+ return;
415
+ }
416
+ const a = cell.a.value === null ? MISSING_MARK : resolveLocalizedText(cell.a.display, locale);
417
+ const b = cell.b.value === null ? MISSING_MARK : resolveLocalizedText(cell.b.display, locale);
418
+ cells[`metric${i}`] = `${a} → ${b} ${resolveLocalizedText(cell.display, locale)}`;
419
+ });
420
+ return { key: row.key, cells };
421
+ });
422
+ return renderTableText({ columns: columns as unknown as [TableColumn, ...TableColumn[]], rows, locale }, ctx);
423
+ }