niceeval 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents/types.d.ts +67 -5
- package/dist/context/types.d.ts +32 -12
- package/dist/i18n/en.d.ts +54 -0
- package/dist/i18n/zh-CN.d.ts +55 -1
- package/dist/o11y/types.d.ts +16 -2
- package/dist/report/aggregate.d.ts +5 -3
- package/dist/report/aggregate.js +32 -5
- package/dist/report/built-ins/experiment-comparison.d.ts +39 -1
- package/dist/report/built-ins/experiment-comparison.js +116 -10
- package/dist/report/built-ins/index.d.ts +1 -0
- package/dist/report/built-ins/index.js +1 -1
- package/dist/report/components.d.ts +8 -2
- package/dist/report/components.js +3 -3
- package/dist/report/compute.d.ts +11 -18
- package/dist/report/compute.js +54 -34
- package/dist/report/flag.d.ts +16 -1
- package/dist/report/flag.js +19 -1
- package/dist/report/format.d.ts +16 -8
- package/dist/report/format.js +27 -12
- package/dist/report/index.d.ts +4 -3
- package/dist/report/index.js +5 -4
- package/dist/report/locale.d.ts +11 -2
- package/dist/report/locale.js +23 -5
- package/dist/report/metrics.d.ts +13 -1
- package/dist/report/metrics.js +65 -14
- package/dist/report/primitives.d.ts +6 -0
- package/dist/report/react/AttemptList.d.ts +2 -2
- package/dist/report/react/AttemptList.js +5 -6
- package/dist/report/react/EvalList.d.ts +1 -1
- package/dist/report/react/EvalList.js +0 -0
- package/dist/report/react/ExperimentComparison.d.ts +8 -0
- package/dist/report/react/ExperimentComparison.js +11 -0
- package/dist/report/react/ExperimentList.d.ts +2 -1
- package/dist/report/react/ExperimentList.js +8 -10
- package/dist/report/react/MetricScatter.js +5 -11
- package/dist/report/react/chart-math.d.ts +23 -6
- package/dist/report/react/chart-math.js +71 -19
- package/dist/report/react/fixtures.d.ts +3 -3
- package/dist/report/react/fixtures.js +21 -14
- package/dist/report/report.d.ts +5 -1
- package/dist/report/report.js +6 -2
- package/dist/report/text/faces.d.ts +1 -1
- package/dist/report/text/faces.js +42 -41
- package/dist/report/text/table.js +36 -5
- package/dist/report/types.d.ts +39 -21
- package/dist/results/types.d.ts +11 -0
- package/dist/runner/feedback/sink.d.ts +110 -0
- package/dist/runner/types.d.ts +513 -22
- package/dist/sandbox/docker.d.ts +23 -2
- package/dist/sandbox/e2b.d.ts +15 -1
- package/dist/sandbox/errors.d.ts +30 -3
- package/dist/sandbox/io-retry.d.ts +17 -0
- package/dist/sandbox/registry.d.ts +2 -0
- package/dist/sandbox/resolve.d.ts +18 -5
- package/dist/sandbox/retry.d.ts +11 -1
- package/dist/sandbox/types.d.ts +39 -5
- package/dist/sandbox/vercel.d.ts +7 -1
- package/dist/scoring/coverage.d.ts +30 -0
- package/dist/scoring/display.d.ts +21 -0
- package/dist/scoring/display.js +120 -0
- package/dist/scoring/types.d.ts +103 -20
- package/dist/shared/aggregate.d.ts +1 -0
- package/dist/shared/aggregate.js +3 -3
- package/dist/shared/types.d.ts +28 -0
- package/dist/tty-line.d.ts +0 -4
- package/dist/util.d.ts +23 -0
- package/docs-site/zh/concepts/adapter.mdx +22 -4
- package/docs-site/zh/concepts/experiment.mdx +1 -1
- package/docs-site/zh/concepts/overview.mdx +6 -6
- package/docs-site/zh/guides/agent-feedback-loop.mdx +28 -26
- package/docs-site/zh/guides/authoring.mdx +33 -0
- package/docs-site/zh/guides/ci-integration.mdx +23 -12
- package/docs-site/zh/guides/connect-your-agent.mdx +29 -3
- package/docs-site/zh/guides/custom-reports.mdx +29 -34
- package/docs-site/zh/guides/dataset-fanout.mdx +25 -3
- package/docs-site/zh/guides/debug-sandbox.mdx +57 -0
- package/docs-site/zh/guides/debugging.mdx +210 -0
- package/docs-site/zh/guides/experiments.mdx +10 -3
- package/docs-site/zh/guides/official-adapters.mdx +26 -2
- package/docs-site/zh/guides/publish-report.mdx +30 -16
- package/docs-site/zh/guides/report-components.mdx +42 -30
- package/docs-site/zh/guides/reporters.mdx +2 -2
- package/docs-site/zh/guides/results-data.mdx +17 -9
- package/docs-site/zh/guides/runner.mdx +17 -7
- package/docs-site/zh/guides/sandbox-agent.mdx +56 -7
- package/docs-site/zh/guides/sandbox-providers.mdx +257 -9
- package/docs-site/zh/guides/scoring-guide.mdx +4 -4
- package/docs-site/zh/guides/viewing-results.mdx +79 -36
- package/docs-site/zh/guides/write-experiment.mdx +5 -3
- package/docs-site/zh/guides/write-send.mdx +17 -1
- package/docs-site/zh/index.mdx +1 -1
- package/docs-site/zh/reference/builtin-agents.mdx +27 -0
- package/docs-site/zh/reference/capabilities.mdx +2 -2
- package/docs-site/zh/reference/cli.mdx +33 -7
- package/docs-site/zh/reference/define-agent.mdx +57 -4
- package/docs-site/zh/reference/define-config.mdx +1 -1
- package/docs-site/zh/reference/define-eval.mdx +42 -9
- package/docs-site/zh/reference/expect.mdx +26 -1
- package/package.json +5 -1
- package/src/agents/ai-sdk-otel.test.ts +1 -0
- package/src/agents/ai-sdk.test.ts +3 -0
- package/src/agents/ai-sdk.ts +3 -0
- package/src/agents/bub-install-spec.test.ts +34 -0
- package/src/agents/bub-install-spec.ts +32 -0
- package/src/agents/bub.ts +31 -32
- package/src/agents/claude-code.test.ts +130 -9
- package/src/agents/claude-code.ts +76 -4
- package/src/agents/codex.test.ts +189 -40
- package/src/agents/codex.ts +155 -14
- package/src/agents/coding-cli-versions.test.ts +15 -0
- package/src/agents/coding-cli-versions.ts +3 -0
- package/src/agents/index.ts +11 -0
- package/src/agents/langgraph.test.ts +204 -0
- package/src/agents/langgraph.ts +495 -0
- package/src/agents/marketplace.ts +85 -0
- package/src/agents/native-config.test.ts +179 -0
- package/src/agents/native-config.ts +267 -0
- package/src/agents/openai-compat.test.ts +1 -0
- package/src/agents/openclaw.test.ts +31 -0
- package/src/agents/openclaw.ts +171 -0
- package/src/agents/plugin-config.test.ts +1 -0
- package/src/agents/sdk-streams.test.ts +79 -0
- package/src/agents/sdk-streams.ts +55 -10
- package/src/agents/skills.test.ts +1 -0
- package/src/agents/streaming.test.ts +3 -9
- package/src/agents/types.ts +68 -5
- package/src/agents/ui-message-stream.test.ts +3 -0
- package/src/cli.ts +411 -108
- package/src/context/context.test.ts +51 -12
- package/src/context/context.ts +161 -29
- package/src/context/session.test.ts +1 -0
- package/src/context/session.ts +114 -6
- package/src/context/types.ts +30 -12
- package/src/define.test.ts +13 -8
- package/src/define.ts +25 -4
- package/src/expect/index.ts +53 -23
- package/src/i18n/en.ts +64 -2
- package/src/i18n/zh-CN.ts +65 -3
- package/src/o11y/cost.test.ts +1 -0
- package/src/o11y/execution-tree.test.ts +1 -20
- package/src/o11y/otlp/mappers/claude-code.test.ts +1 -0
- package/src/o11y/otlp/parse.test.ts +1 -0
- package/src/o11y/otlp/turn-otel.test.ts +1 -0
- package/src/o11y/parsers/bub.test.ts +1 -0
- package/src/o11y/parsers/claude-code.test.ts +1 -34
- package/src/o11y/parsers/openclaw.test.ts +154 -0
- package/src/o11y/parsers/openclaw.ts +310 -0
- package/src/o11y/prices.json +746 -311
- package/src/o11y/tool-names.test.ts +1 -0
- package/src/o11y/types.ts +16 -2
- package/src/report/aggregate.ts +34 -5
- package/src/report/built-in-user-parity.test.tsx +110 -153
- package/src/report/built-ins/experiment-comparison.tsx +173 -13
- package/src/report/built-ins/index.ts +6 -1
- package/src/report/components.tsx +9 -3
- package/src/report/compute.ts +70 -40
- package/src/report/dual-render.test.tsx +194 -67
- package/src/report/flag.ts +30 -2
- package/src/report/format.ts +35 -11
- package/src/report/index.ts +22 -4
- package/src/report/locale.ts +25 -5
- package/src/report/metrics.ts +67 -14
- package/src/report/primitives.tsx +6 -0
- package/src/report/react/AttemptList.tsx +6 -31
- package/src/report/react/EvalList.tsx +0 -0
- package/src/report/react/ExperimentComparison.tsx +68 -0
- package/src/report/react/ExperimentList.tsx +15 -9
- package/src/report/react/MetricScatter.tsx +12 -14
- package/src/report/react/chart-math.test.ts +85 -0
- package/src/report/react/chart-math.ts +101 -22
- package/src/report/react/enhance.js +33 -1
- package/src/report/react/fixtures.ts +24 -17
- package/src/report/react/render.test.tsx +9 -64
- package/src/report/react/styles.css +73 -2
- package/src/report/report.test.ts +306 -98
- package/src/report/report.ts +6 -2
- package/src/report/text/faces.ts +47 -43
- package/src/report/text/table.ts +42 -5
- package/src/report/types.ts +41 -21
- package/src/results/annotated-source.test.ts +62 -9
- package/src/results/annotated-source.ts +64 -6
- package/src/results/attempt-evidence.test.ts +9 -7
- package/src/results/attempt-evidence.ts +15 -8
- package/src/results/attempt-source.ts +6 -3
- package/src/results/copy.ts +145 -55
- package/src/results/host-equivalence.test.ts +8 -6
- package/src/results/index.ts +2 -0
- package/src/results/locator.test.ts +1 -22
- package/src/results/open.ts +7 -1
- package/src/results/publish.ts +149 -0
- package/src/results/results.test.ts +85 -51
- package/src/results/truncate.ts +90 -0
- package/src/results/types.ts +7 -0
- package/src/results/writer.ts +31 -13
- package/src/runner/attempt.test.ts +138 -7
- package/src/runner/attempt.ts +603 -104
- package/src/runner/discover.test.ts +47 -0
- package/src/runner/discover.ts +36 -2
- package/src/runner/eval-source.test.ts +1 -27
- package/src/runner/feedback/agent.test.ts +504 -0
- package/src/runner/feedback/agent.ts +409 -0
- package/src/runner/feedback/ci.test.ts +562 -0
- package/src/runner/feedback/ci.ts +401 -0
- package/src/runner/feedback/coordinator.test.ts +317 -0
- package/src/runner/feedback/coordinator.ts +397 -0
- package/src/runner/feedback/failure.ts +40 -0
- package/src/runner/feedback/human.test.ts +616 -0
- package/src/runner/feedback/human.ts +535 -0
- package/src/runner/feedback/index.ts +66 -0
- package/src/runner/feedback/io.ts +78 -0
- package/src/runner/feedback/profile.test.ts +50 -0
- package/src/runner/feedback/profile.ts +58 -0
- package/src/runner/feedback/reducer.test.ts +395 -0
- package/src/runner/feedback/reducer.ts +260 -0
- package/src/runner/feedback/renderer.ts +82 -0
- package/src/runner/feedback/sink.ts +203 -0
- package/src/runner/feedback/testing.ts +106 -0
- package/src/runner/ledger.test.ts +230 -0
- package/src/runner/ledger.ts +329 -0
- package/src/runner/report.test.ts +128 -3
- package/src/runner/report.ts +33 -9
- package/src/runner/reporters/artifacts.ts +8 -2
- package/src/runner/reporters/braintrust.test.ts +8 -7
- package/src/runner/reporters/braintrust.ts +9 -2
- package/src/runner/reporters/index.ts +2 -2
- package/src/runner/reporters/json.test.ts +162 -0
- package/src/runner/reporters/json.ts +35 -8
- package/src/runner/reporters/shared.ts +1 -5
- package/src/runner/run.test.ts +760 -3
- package/src/runner/run.ts +242 -36
- package/src/runner/sandbox-prep.ts +3 -42
- package/src/runner/timing.ts +158 -0
- package/src/runner/types.ts +518 -22
- package/src/sandbox/checkpoint.test.ts +55 -0
- package/src/sandbox/checkpoint.ts +29 -8
- package/src/sandbox/cli-commands.ts +407 -0
- package/src/sandbox/docker.ts +115 -16
- package/src/sandbox/e2b-agent-template.test.ts +56 -0
- package/src/sandbox/e2b-agent-template.ts +94 -0
- package/src/sandbox/e2b.ts +74 -9
- package/src/sandbox/errors.ts +111 -4
- package/src/sandbox/index.ts +2 -0
- package/src/sandbox/io-retry.test.ts +58 -0
- package/src/sandbox/io-retry.ts +45 -0
- package/src/sandbox/keep-registry.test.ts +86 -0
- package/src/sandbox/keep-registry.ts +142 -0
- package/src/sandbox/keep.ts +178 -0
- package/src/sandbox/paths.test.ts +1 -0
- package/src/sandbox/paths.ts +19 -8
- package/src/sandbox/registry.ts +20 -3
- package/src/sandbox/resolve.ts +76 -11
- package/src/sandbox/retry.test.ts +70 -0
- package/src/sandbox/retry.ts +46 -4
- package/src/sandbox/types.ts +44 -6
- package/src/sandbox/vercel.ts +43 -20
- package/src/scoring/collector.ts +60 -17
- package/src/scoring/coverage.ts +95 -0
- package/src/scoring/diff.ts +81 -0
- package/src/scoring/display.test.ts +121 -0
- package/src/scoring/display.ts +133 -0
- package/src/scoring/evidence.test.ts +189 -0
- package/src/scoring/judge.test.ts +142 -0
- package/src/scoring/judge.ts +15 -18
- package/src/scoring/scoped.ts +217 -50
- package/src/scoring/types.ts +117 -20
- package/src/scoring/verdict.ts +16 -4
- package/src/shared/aggregate.ts +3 -2
- package/src/shared/types.ts +31 -0
- package/src/show/compose.ts +2 -2
- package/src/show/index.ts +21 -1
- package/src/show/render.ts +619 -104
- package/src/show/show.test.ts +235 -19
- package/src/tty-line.ts +8 -26
- package/src/util.test.ts +1 -0
- package/src/util.ts +41 -0
- package/src/view/app/components/AttemptModal.tsx +153 -2
- package/src/view/app/components/CodeView.tsx +32 -11
- package/src/view/app/components/CopyControls.tsx +2 -2
- package/src/view/app/i18n.ts +6 -0
- package/src/view/app/lib/attempt-route.test.ts +1 -0
- package/src/view/app/lib/verdict.ts +7 -9
- package/src/view/artifact-serving.test.ts +2 -1
- package/src/view/client-dist/app.css +1 -1
- package/src/view/client-dist/app.js +17 -17
- package/src/view/data.test.ts +1 -0
- package/src/view/data.ts +11 -1
- package/src/view/index.ts +11 -0
- package/src/view/server.ts +2 -0
- package/src/view/styles.css +3 -0
- package/src/view/view-report.test.ts +6 -5
- package/src/runner/reporters/console.ts +0 -70
- package/src/runner/reporters/live.test.ts +0 -56
- package/src/runner/reporters/live.ts +0 -247
- package/src/runner/reporters/quiet.test.ts +0 -66
- package/src/runner/reporters/quiet.ts +0 -49
- package/src/runner/reporters/table.ts +0 -277
|
@@ -1,277 +0,0 @@
|
|
|
1
|
-
import type { EvalResult, RunSummary, Usage } from "../../types.ts";
|
|
2
|
-
import { t } from "../../i18n/index.ts";
|
|
3
|
-
import { verdictSymbol } from "./shared.ts";
|
|
4
|
-
import { foldEvalVerdict, evalLevelStats as sharedEvalLevelStats } from "../../shared/verdict.ts";
|
|
5
|
-
// 展示口径(耗时/成本/百分比)与聚合小工具(标签/求和/排序)与 view 共用一份实现;
|
|
6
|
-
// console.ts 经这里 re-export formatDuration。
|
|
7
|
-
import { formatCost, formatDuration, formatPercent } from "../../shared/format.ts";
|
|
8
|
-
import { VERDICT_ORDER, avg, displayExperimentName, fallbackExperimentLabel, sumMaybe, totalTokens } from "../../shared/aggregate.ts";
|
|
9
|
-
|
|
10
|
-
export { formatCost, formatDuration } from "../../shared/format.ts";
|
|
11
|
-
|
|
12
|
-
interface ExperimentRow {
|
|
13
|
-
key: string;
|
|
14
|
-
label: string;
|
|
15
|
-
model: string;
|
|
16
|
-
agent: string;
|
|
17
|
-
avgDurationMs: number;
|
|
18
|
-
passRate: number;
|
|
19
|
-
tokens: number;
|
|
20
|
-
cost?: number;
|
|
21
|
-
evals: number;
|
|
22
|
-
passed: number;
|
|
23
|
-
failed: number;
|
|
24
|
-
errored: number;
|
|
25
|
-
skipped: number;
|
|
26
|
-
attempts: number;
|
|
27
|
-
results: EvalResult[];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
interface EvalRow {
|
|
31
|
-
id: string;
|
|
32
|
-
verdict: EvalResult["verdict"];
|
|
33
|
-
reason: string;
|
|
34
|
-
durationMs: number;
|
|
35
|
-
tokens: number;
|
|
36
|
-
cost?: number;
|
|
37
|
-
passedAttempts: number;
|
|
38
|
-
attempts: number;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function renderRunReport(summary: RunSummary): string {
|
|
42
|
-
const rows = aggregateExperimentRows(summary.results);
|
|
43
|
-
const lines: string[] = ["", t("report.table.experimentsTitle")];
|
|
44
|
-
lines.push(renderTable(
|
|
45
|
-
[
|
|
46
|
-
t("report.table.experiment"),
|
|
47
|
-
t("report.table.model"),
|
|
48
|
-
t("report.table.agent"),
|
|
49
|
-
t("report.table.avgDuration"),
|
|
50
|
-
t("report.table.successRate"),
|
|
51
|
-
t("report.table.tokens"),
|
|
52
|
-
t("report.table.cost"),
|
|
53
|
-
t("report.table.result"),
|
|
54
|
-
],
|
|
55
|
-
rows.map((row) => [
|
|
56
|
-
row.label,
|
|
57
|
-
row.model,
|
|
58
|
-
row.agent,
|
|
59
|
-
formatDuration(row.avgDurationMs),
|
|
60
|
-
formatPercent(row.passRate),
|
|
61
|
-
formatTokens(row.tokens),
|
|
62
|
-
formatCost(row.cost),
|
|
63
|
-
formatResult(row),
|
|
64
|
-
]),
|
|
65
|
-
));
|
|
66
|
-
|
|
67
|
-
for (const row of rows) {
|
|
68
|
-
lines.push("", `${t("report.table.evalTitle")} ${row.label}`);
|
|
69
|
-
lines.push(renderTable(
|
|
70
|
-
[
|
|
71
|
-
t("report.table.status"),
|
|
72
|
-
t("report.table.eval"),
|
|
73
|
-
t("report.table.reason"),
|
|
74
|
-
t("report.table.duration"),
|
|
75
|
-
t("report.table.tokens"),
|
|
76
|
-
t("report.table.cost"),
|
|
77
|
-
t("report.table.runs"),
|
|
78
|
-
],
|
|
79
|
-
aggregateEvalRows(row.results).map((evalRow) => [
|
|
80
|
-
formatVerdict(evalRow.verdict),
|
|
81
|
-
evalRow.id,
|
|
82
|
-
evalRow.reason,
|
|
83
|
-
formatDuration(evalRow.durationMs),
|
|
84
|
-
formatTokens(evalRow.tokens),
|
|
85
|
-
formatCost(evalRow.cost),
|
|
86
|
-
`${evalRow.passedAttempts}/${evalRow.attempts}`,
|
|
87
|
-
]),
|
|
88
|
-
{ maxWidth: 120, flexibleColumn: 2 },
|
|
89
|
-
));
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const tok = (summary.usage?.inputTokens ?? 0) + (summary.usage?.outputTokens ?? 0);
|
|
93
|
-
const tokStr = tok > 0 ? `${formatTokens(tok)} tok` : "— tok";
|
|
94
|
-
const cost = summary.estimatedCostUSD !== undefined ? ` · ${formatCost(summary.estimatedCostUSD)}` : "";
|
|
95
|
-
const parts = [
|
|
96
|
-
t("report.summary.passed", { count: summary.passed }),
|
|
97
|
-
t("report.summary.failed", { count: summary.failed }),
|
|
98
|
-
...(summary.errored > 0 ? [t("report.summary.errored", { count: summary.errored })] : []),
|
|
99
|
-
t("report.summary.skipped", { count: summary.skipped }),
|
|
100
|
-
];
|
|
101
|
-
lines.push(t("report.result", {
|
|
102
|
-
parts: parts.join(", "),
|
|
103
|
-
duration: formatDuration(summary.durationMs),
|
|
104
|
-
tokens: tokStr,
|
|
105
|
-
cost,
|
|
106
|
-
}).trimEnd());
|
|
107
|
-
lines.push(t("report.viewHint").trimEnd());
|
|
108
|
-
|
|
109
|
-
return `${lines.join("\n")}\n\n`;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export function formatTokens(n: number): string {
|
|
113
|
-
if (n >= 1000) return `${(n / 1000).toFixed(1)}k`;
|
|
114
|
-
return String(n);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export function formatVerdict(verdict: string): string {
|
|
118
|
-
const sym = verdictSymbol(verdict);
|
|
119
|
-
switch (verdict) {
|
|
120
|
-
case "passed": return `${sym} ${t("report.passed")}`;
|
|
121
|
-
case "failed": return `${sym} ${t("report.failed")}`;
|
|
122
|
-
case "errored": return `${sym} ${t("report.errored")}`;
|
|
123
|
-
case "skipped": return `${sym} ${t("report.skipped")}`;
|
|
124
|
-
default: return `${sym} ${verdict}`;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function aggregateExperimentRows(results: EvalResult[]): ExperimentRow[] {
|
|
129
|
-
const groups = new Map<string, EvalResult[]>();
|
|
130
|
-
for (const result of results) {
|
|
131
|
-
const key = result.experimentId ? `exp|||${result.experimentId}` : `legacy|||${result.agent}|||${result.model ?? ""}`;
|
|
132
|
-
groups.set(key, [...(groups.get(key) ?? []), result]);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return [...groups.entries()]
|
|
136
|
-
.map(([key, groupResults]) => {
|
|
137
|
-
const first = groupResults[0]!;
|
|
138
|
-
const stats = evalLevelStats(groupResults);
|
|
139
|
-
return {
|
|
140
|
-
key,
|
|
141
|
-
label: displayExperimentName(first.experimentId) ?? fallbackExperimentLabel(first),
|
|
142
|
-
model: first.model ?? t("report.table.default"),
|
|
143
|
-
agent: first.agent,
|
|
144
|
-
avgDurationMs: avg(groupResults.map((r) => r.durationMs)),
|
|
145
|
-
passRate: stats.passRate,
|
|
146
|
-
tokens: totalTokens(groupResults.map((r) => r.usage)),
|
|
147
|
-
cost: sumMaybe(groupResults.map((r) => r.estimatedCostUSD)),
|
|
148
|
-
evals: stats.evals,
|
|
149
|
-
passed: stats.passed,
|
|
150
|
-
failed: stats.failed,
|
|
151
|
-
errored: stats.errored,
|
|
152
|
-
skipped: stats.skipped,
|
|
153
|
-
attempts: groupResults.length,
|
|
154
|
-
results: groupResults.slice().sort((a, b) => a.id.localeCompare(b.id) || a.attempt - b.attempt),
|
|
155
|
-
};
|
|
156
|
-
})
|
|
157
|
-
.sort((a, b) => b.passRate - a.passRate || a.label.localeCompare(b.label));
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function aggregateEvalRows(results: EvalResult[]): EvalRow[] {
|
|
161
|
-
const byEval = new Map<string, EvalResult[]>();
|
|
162
|
-
for (const result of results) byEval.set(result.id, [...(byEval.get(result.id) ?? []), result]);
|
|
163
|
-
return [...byEval.entries()]
|
|
164
|
-
.map(([id, evalResults]) => {
|
|
165
|
-
const verdict = foldEvalVerdict(evalResults);
|
|
166
|
-
const representative =
|
|
167
|
-
evalResults.find((r) => r.verdict === verdict) ??
|
|
168
|
-
evalResults.find((r) => r.verdict !== "passed") ??
|
|
169
|
-
evalResults[0]!;
|
|
170
|
-
return {
|
|
171
|
-
id,
|
|
172
|
-
verdict,
|
|
173
|
-
reason: verdict === "passed" ? t("report.passed") : reasonFor(representative),
|
|
174
|
-
durationMs: avg(evalResults.map((r) => r.durationMs)),
|
|
175
|
-
tokens: totalTokens(evalResults.map((r) => r.usage)),
|
|
176
|
-
cost: sumMaybe(evalResults.map((r) => r.estimatedCostUSD)),
|
|
177
|
-
passedAttempts: evalResults.filter((r) => r.verdict === "passed").length,
|
|
178
|
-
attempts: evalResults.length,
|
|
179
|
-
};
|
|
180
|
-
})
|
|
181
|
-
.sort((a, b) => VERDICT_ORDER[a.verdict] - VERDICT_ORDER[b.verdict] || a.id.localeCompare(b.id));
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// 折叠 / 计票口径与 view 同一份实现(src/shared/verdict.ts),CLI 表格和网页榜单永不打架。
|
|
185
|
-
function evalLevelStats(results: EvalResult[]) {
|
|
186
|
-
return sharedEvalLevelStats(results, (r) => r.id);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
function reasonFor(result: EvalResult): string {
|
|
190
|
-
if (result.skipReason) return result.skipReason;
|
|
191
|
-
if (result.error) return truncateOneLine(result.error, 120);
|
|
192
|
-
const failed = result.assertions.filter((a) => !a.passed && a.severity === "gate");
|
|
193
|
-
const assertions = failed.length ? failed : result.assertions.slice(0, 2);
|
|
194
|
-
if (!assertions.length) return "";
|
|
195
|
-
return truncateOneLine(
|
|
196
|
-
assertions
|
|
197
|
-
.map((a) => {
|
|
198
|
-
const threshold = a.threshold !== undefined ? ` ${t("report.assertionThreshold", { score: a.score.toFixed(2), threshold: a.threshold }).trim()}` : "";
|
|
199
|
-
return `${a.severity}: ${a.name}${threshold}`;
|
|
200
|
-
})
|
|
201
|
-
.join(" · "),
|
|
202
|
-
120,
|
|
203
|
-
);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
function formatResult(row: ExperimentRow): string {
|
|
207
|
-
const failures = row.failed + row.errored;
|
|
208
|
-
const suffix = row.skipped > 0 ? ` · ${row.skipped} ${t("report.skipped")}` : "";
|
|
209
|
-
return `${row.passed}/${row.evals} ${t("report.passed")} · ${failures} ${t("report.failed")}${suffix}`;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
function renderTable(headers: string[], rows: string[][], opts: { maxWidth?: number; flexibleColumn?: number } = {}): string {
|
|
219
|
-
const rawRows = [headers, ...rows];
|
|
220
|
-
const widths = headers.map((_, col) => Math.max(...rawRows.map((row) => displayWidth(row[col] ?? ""))));
|
|
221
|
-
const maxWidth = opts.maxWidth ?? 140;
|
|
222
|
-
const tableWidth = widths.reduce((sum, w) => sum + w, 0) + (headers.length - 1) * 3;
|
|
223
|
-
if (tableWidth > maxWidth && opts.flexibleColumn !== undefined) {
|
|
224
|
-
const over = tableWidth - maxWidth;
|
|
225
|
-
widths[opts.flexibleColumn] = Math.max(18, widths[opts.flexibleColumn]! - over);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
const lines = [formatRow(headers, widths), widths.map((w) => "-".repeat(w)).join("-+-")];
|
|
229
|
-
for (const row of rows) lines.push(formatRow(row, widths));
|
|
230
|
-
return lines.join("\n");
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
function formatRow(row: string[], widths: number[]): string {
|
|
234
|
-
return row.map((cell, i) => padEnd(truncateToWidth(cell ?? "", widths[i]!), widths[i]!)).join(" | ");
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
function truncateOneLine(s: string, width: number): string {
|
|
238
|
-
return truncateToWidth(s.replace(/\s+/g, " ").trim(), width);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
function truncateToWidth(s: string, width: number): string {
|
|
242
|
-
if (displayWidth(s) <= width) return s;
|
|
243
|
-
const ellipsis = "…";
|
|
244
|
-
let out = "";
|
|
245
|
-
for (const char of s) {
|
|
246
|
-
if (displayWidth(out + char + ellipsis) > width) break;
|
|
247
|
-
out += char;
|
|
248
|
-
}
|
|
249
|
-
return out + ellipsis;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
function padEnd(s: string, width: number): string {
|
|
253
|
-
return s + " ".repeat(Math.max(0, width - displayWidth(s)));
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
function displayWidth(s: string): number {
|
|
257
|
-
let width = 0;
|
|
258
|
-
for (const char of s) {
|
|
259
|
-
const code = char.codePointAt(0) ?? 0;
|
|
260
|
-
width += isWide(code) ? 2 : 1;
|
|
261
|
-
}
|
|
262
|
-
return width;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
function isWide(code: number): boolean {
|
|
266
|
-
return (
|
|
267
|
-
(code >= 0x1100 && code <= 0x115f) ||
|
|
268
|
-
(code >= 0x2e80 && code <= 0xa4cf) ||
|
|
269
|
-
(code >= 0xac00 && code <= 0xd7a3) ||
|
|
270
|
-
(code >= 0xf900 && code <= 0xfaff) ||
|
|
271
|
-
(code >= 0xfe10 && code <= 0xfe19) ||
|
|
272
|
-
(code >= 0xfe30 && code <= 0xfe6f) ||
|
|
273
|
-
(code >= 0xff00 && code <= 0xff60) ||
|
|
274
|
-
(code >= 0xffe0 && code <= 0xffe6) ||
|
|
275
|
-
(code >= 0x1f300 && code <= 0x1faff)
|
|
276
|
-
);
|
|
277
|
-
}
|