@agentswf/lab 0.0.0-stage → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +15 -2
  3. package/package.json +46 -4
  4. package/schema/case-check.schema.json +64 -0
  5. package/schema/case-config.schema.json +187 -0
  6. package/schema/case-final.schema.json +48 -0
  7. package/schema/case-good-record.schema.json +70 -0
  8. package/schema/case-grade.schema.json +49 -0
  9. package/schema/case-key.schema.json +117 -0
  10. package/schema/case-label.schema.json +32 -0
  11. package/schema/case-loop-report.schema.json +210 -0
  12. package/schema/case-loop.schema.json +141 -0
  13. package/schema/case-plan.schema.json +117 -0
  14. package/schema/case-previous.schema.json +70 -0
  15. package/schema/case-proposal.schema.json +52 -0
  16. package/schema/case-report.schema.json +892 -0
  17. package/schema/case-run.schema.json +253 -0
  18. package/schema/case-runs.schema.json +125 -0
  19. package/schema/case-score.schema.json +319 -0
  20. package/schema/case-spread.schema.json +110 -0
  21. package/schema/case-trial.schema.json +543 -0
  22. package/schema/case-try.schema.json +113 -0
  23. package/schema/local.json +155 -0
  24. package/src/cli.ts +9 -0
  25. package/src/env/capture.ts +48 -0
  26. package/src/env/compare.ts +201 -0
  27. package/src/env/facts.ts +51 -0
  28. package/src/env/fetch.ts +57 -0
  29. package/src/env/files.ts +228 -0
  30. package/src/env/grade-case.ts +80 -0
  31. package/src/env/grade-helper.ts +352 -0
  32. package/src/env/grader.ts +128 -0
  33. package/src/env/index.ts +727 -0
  34. package/src/env/mock.ts +374 -0
  35. package/src/env/routes.ts +90 -0
  36. package/src/env/sources.ts +19 -0
  37. package/src/env/state.ts +79 -0
  38. package/src/env/trial.ts +182 -0
  39. package/src/format/key.ts +144 -0
  40. package/src/format/loop.ts +178 -0
  41. package/src/format/output.ts +481 -0
  42. package/src/format/records.ts +440 -0
  43. package/src/format/schema-files.ts +64 -0
  44. package/src/format/settings.ts +552 -0
  45. package/src/format/trial-env.ts +64 -0
  46. package/src/format/trial-file.ts +134 -0
  47. package/src/help/awf-lab.txt +29 -0
  48. package/src/help/case.txt +38 -0
  49. package/src/help/config.txt +14 -0
  50. package/src/help/label.txt +12 -0
  51. package/src/help/loop.txt +44 -0
  52. package/src/help/report.txt +20 -0
  53. package/src/help/run.txt +60 -0
  54. package/src/help/runs.txt +10 -0
  55. package/src/help/score.txt +27 -0
  56. package/src/judge/criteria.workflow.ts +237 -0
  57. package/src/judge/version.ts +6 -0
  58. package/src/lab/answer.ts +47 -0
  59. package/src/lab/blame.ts +204 -0
  60. package/src/lab/box.ts +249 -0
  61. package/src/lab/capture-command.ts +298 -0
  62. package/src/lab/capture.ts +234 -0
  63. package/src/lab/check-command.ts +187 -0
  64. package/src/lab/cli.ts +324 -0
  65. package/src/lab/code-graders.ts +108 -0
  66. package/src/lab/columns.ts +138 -0
  67. package/src/lab/command-context.ts +436 -0
  68. package/src/lab/compare.ts +123 -0
  69. package/src/lab/config-command.ts +278 -0
  70. package/src/lab/criteria.ts +69 -0
  71. package/src/lab/dataset.ts +356 -0
  72. package/src/lab/eval-files.ts +185 -0
  73. package/src/lab/expect.ts +79 -0
  74. package/src/lab/facts.ts +59 -0
  75. package/src/lab/families.ts +32 -0
  76. package/src/lab/folders.ts +153 -0
  77. package/src/lab/git.ts +128 -0
  78. package/src/lab/good.ts +224 -0
  79. package/src/lab/grading-stub.txt +8 -0
  80. package/src/lab/grading.ts +332 -0
  81. package/src/lab/inspect.ts +226 -0
  82. package/src/lab/labels.ts +206 -0
  83. package/src/lab/loop-code.ts +255 -0
  84. package/src/lab/loop-command.ts +770 -0
  85. package/src/lab/loop-records.ts +144 -0
  86. package/src/lab/loop.ts +859 -0
  87. package/src/lab/marker.ts +23 -0
  88. package/src/lab/outcome.ts +196 -0
  89. package/src/lab/pooled.ts +106 -0
  90. package/src/lab/project-env.ts +39 -0
  91. package/src/lab/rates.ts +150 -0
  92. package/src/lab/reach.ts +111 -0
  93. package/src/lab/record-copies.ts +202 -0
  94. package/src/lab/refusal.ts +2 -0
  95. package/src/lab/report-command.ts +156 -0
  96. package/src/lab/report.ts +838 -0
  97. package/src/lab/reuse.ts +126 -0
  98. package/src/lab/run-command.ts +853 -0
  99. package/src/lab/run-logs.ts +89 -0
  100. package/src/lab/run-report.ts +259 -0
  101. package/src/lab/runs-command.ts +163 -0
  102. package/src/lab/runs.ts +172 -0
  103. package/src/lab/scaffold.ts +91 -0
  104. package/src/lab/score-command.ts +189 -0
  105. package/src/lab/score.ts +396 -0
  106. package/src/lab/store.ts +383 -0
  107. package/src/lab/text.ts +29 -0
  108. package/src/lab/trial-settings.ts +100 -0
  109. package/src/lab/trial-stub.txt +18 -0
  110. package/src/lab/trial.ts +443 -0
  111. package/src/lab/usage.ts +273 -0
  112. package/src/lab/verdict.ts +161 -0
  113. package/src/lab/workflow-graders.ts +161 -0
  114. package/src/lab/workspace.ts +489 -0
  115. package/src/loop/propose.workflow.ts +84 -0
  116. package/src/shared/allowance.ts +185 -0
  117. package/src/shared/compare/index.ts +3 -0
  118. package/src/shared/compare/paired.ts +397 -0
  119. package/src/shared/compare/stats.ts +139 -0
  120. package/src/shared/compare/types.ts +75 -0
  121. package/src/shared/config.ts +15 -0
  122. package/src/shared/runner.ts +321 -0
  123. package/src/shared/validate.ts +181 -0
  124. package/src/shared/version.ts +41 -0
  125. package/src/write-schemas.ts +10 -0
@@ -0,0 +1,838 @@
1
+ import type { LabelRecord, RunRecord } from "../format/records";
2
+ import { columnLabel, sharedParams } from "./columns";
3
+ import type { ColumnVerdict } from "./compare";
4
+ import { familyOf } from "./families";
5
+ import { type Agreement, JUDGE_CHECK, type PersonAgreement } from "./labels";
6
+ import type { CaseRow, StoredTrialView } from "./outcome";
7
+ import {
8
+ factsOf,
9
+ newestEntries,
10
+ PRECONDITION_STOP,
11
+ preconditionFailure,
12
+ stageFailure,
13
+ trialOutcome,
14
+ votersOf,
15
+ } from "./outcome";
16
+ import { agreements, type Pooled, poolNumbers } from "./pooled";
17
+ import { describeDifference, describeRates, pairedDifference, ratesOf } from "./rates";
18
+ import { describeFolder, median, plural, seconds, usd } from "./text";
19
+ import { type CaseVerdict, EXITS, type ExitCode, exitCodeOf } from "./verdict";
20
+
21
+ const MARK: Record<CaseVerdict, string> = { passed: "✓", failed: "✗", flaky: "~", unclear: "?" };
22
+
23
+ export type RunReport = {
24
+ run: RunRecord;
25
+ rows: CaseRow[];
26
+ trials: StoredTrialView[];
27
+ /** Criteria in the keys, not judged yet. */
28
+ criteria: number;
29
+ /** Grades `score` would make again: a key or grader changed since; or why it couldn't tell. */
30
+ stale?: number | { unread: string };
31
+ /** The rows of each column but the reference, in the run's `columns` order. */
32
+ others?: readonly CaseRow[][];
33
+ /** The person's labels on this run's trials, and how the lab agrees with them. */
34
+ person?: PersonAgreement;
35
+ /** `compare`'s verdict on each column but the reference, in `columns` order. */
36
+ verdicts?: readonly ColumnVerdict[];
37
+ /** Each case's tags, from its key as it is now. */
38
+ tagsOf?: (caseName: string) => readonly string[];
39
+ /** The labeled trials the current judge graded, across the dataset's runs. */
40
+ judgeLabeled?: { labeled: number; needsWork: number };
41
+ /** The `manual` graders `grading.ts` lists. */
42
+ manual?: ReadonlySet<string>;
43
+ /** The `sentences` graders that decide; absent, a grade with an agent is one. */
44
+ judges?: ReadonlySet<string>;
45
+ /** Whose grades decide each case, from the current dataset and keys; all when unread. */
46
+ decidersOf?: (caseName: string) => ReadonlySet<string> | undefined;
47
+ /** Why no grader grades a case, from its key as it is now. */
48
+ ungradedOf?: (caseName: string) => string | undefined;
49
+ /** The run's own plan was printed just before: its header says the run's id alone. */
50
+ followsPlan?: boolean;
51
+ };
52
+
53
+ const percent = (count: number, of: number) =>
54
+ of === 0 ? "" : ` (${Math.round((count / of) * 100)}%)`;
55
+
56
+ function describePooled(pooled: Pooled): string {
57
+ if ("count" in pooled) return `${pooled.count}/${pooled.of}${percent(pooled.count, pooled.of)}`;
58
+ const m = median(pooled.values)!;
59
+ return `median ${Number.isInteger(m) ? m : m.toFixed(2)}`;
60
+ }
61
+
62
+ /**
63
+ * What the deciding `sentences` graders did, your checkout's column: splits, criteria judged from
64
+ * saved files, trials not judged because a grader before them failed them, and the marks on the
65
+ * judge itself.
66
+ */
67
+ function judgeLines(
68
+ trials: readonly StoredTrialView[],
69
+ criteria: number,
70
+ labeled: { labeled: number; needsWork: number } | undefined,
71
+ manual: ReadonlySet<string>,
72
+ judges: ReadonlySet<string> | undefined,
73
+ ): string[] {
74
+ const own = trials.filter((t) => t.record.column === 0);
75
+ // Unlisted, a `sentences` grade is the one that carries the agent it judged with.
76
+ const judged = own.flatMap((t) =>
77
+ newestEntries(t.scores).filter((e) =>
78
+ judges ? judges.has(e.grader) : e.agent && !manual.has(e.grader),
79
+ ),
80
+ );
81
+ if (judged.length === 0) {
82
+ return criteria > 0
83
+ ? [
84
+ `criteria not judged: ${criteria} ${criteria === 1 ? "criterion" : "criteria"} in the keys`,
85
+ ]
86
+ : [];
87
+ }
88
+ const lines: string[] = [];
89
+ const parts = judged.flatMap((e) => (e.skipped || e.errored ? [] : (e.parts ?? [])));
90
+ const split = parts.filter((p) => p.settled === "majority").length;
91
+ const unsettled = parts.filter((p) => p.settled === "unsettled").length;
92
+ const read = parts.filter((p) => (p.data as { readNotRun?: boolean } | undefined)?.readNotRun);
93
+ const skipped = judged.filter((e) => e.skipped).length;
94
+ lines.push(
95
+ [
96
+ `sentences judged ${parts.length}`,
97
+ ...(split > 0 ? [`split 2–1 ${split}`] : []),
98
+ ...(unsettled > 0 ? [`unsettled ${unsettled}`] : []),
99
+ ...(read.length > 0 ? [`read, not run ${read.length}`] : []),
100
+ ...(skipped > 0
101
+ ? [`not judged on ${plural(skipped, "trial")} a grader before it failed`]
102
+ : []),
103
+ ].join(" · "),
104
+ );
105
+ const agent = judged.find((e) => e.agent)?.agent;
106
+ if (agent) {
107
+ // Checked once the person labeled enough trials this judge graded, some of them needing
108
+ // work: a judge that passes everything can't clear it on good ones alone.
109
+ const have = labeled ?? { labeled: 0, needsWork: 0 };
110
+ const checked = have.labeled >= JUDGE_CHECK.labeled && have.needsWork >= JUDGE_CHECK.needsWork;
111
+ const short = checked
112
+ ? ""
113
+ : `, not checked against a person (labeled ${have.labeled} of ${JUDGE_CHECK.labeled}, needs-work ${have.needsWork} of ${JUDGE_CHECK.needsWork}: awf-lab label)`;
114
+ const family = familyOf(agent.model, agent.harness);
115
+ const shared = family
116
+ ? [...new Set(own.flatMap((t) => t.record.models))].filter((m) => familyOf(m) === family)
117
+ : [];
118
+ lines.push(
119
+ [
120
+ `judge: ${agent.harness}/${agent.model} ×${votersOf(agent)}${short}`,
121
+ ...(family === undefined ? ["family unknown"] : []),
122
+ ...(shared.length > 0
123
+ ? [`shares the ${family} family with the workflow's ${shared.join(", ")}`]
124
+ : []),
125
+ ].join(" · "),
126
+ );
127
+ }
128
+ return lines;
129
+ }
130
+
131
+ /**
132
+ * Each `manual` grader of your checkout's column, graded by `score --grader`: on how many trials,
133
+ * at what grading cost, and on how many its verdict differs from the trial's. A manual
134
+ * `sentences` is set against the deciding one's verdict, judge against judge. Which is right is
135
+ * for the person's labels to say.
136
+ */
137
+ function manualLines(
138
+ trials: readonly StoredTrialView[],
139
+ manual: ReadonlySet<string>,
140
+ decidersOf: RunReport["decidersOf"],
141
+ ): string[] {
142
+ const graders = new Map<string, { trials: number; cost: number; differ: number }>();
143
+ for (const t of trials.filter((t) => t.record.column === 0)) {
144
+ const newest = newestEntries(t.scores);
145
+ const deciders = decidersOf?.(t.record.case);
146
+ const judge = newest.find((e) => e.agent && !manual.has(e.grader));
147
+ const { outcome } = trialOutcome(t.record, t.scores, deciders);
148
+ for (const e of newest.filter((e) => manual.has(e.grader) && !e.errored && !e.skipped)) {
149
+ const into = graders.get(e.grader) ?? { trials: 0, cost: 0, differ: 0 };
150
+ graders.set(e.grader, into);
151
+ into.trials++;
152
+ into.cost += e.estimate ?? 0;
153
+ const against = e.agent && judge ? judge.verdict : outcome;
154
+ if (e.verdict && (against === "passed" || against === "failed") && against !== e.verdict) {
155
+ into.differ++;
156
+ }
157
+ }
158
+ }
159
+ return [...graders].map(
160
+ ([name, g]) =>
161
+ `manual: ${name} on ${plural(g.trials, "trial")}${g.cost > 0 ? ` · grading ${usd(g.cost)}` : ""} · differs from the deciding verdict on ${g.differ}`,
162
+ );
163
+ }
164
+
165
+ /** Each stage's median time over these trials, in the order the stages first ran; or none. */
166
+ function stageLine(trials: readonly StoredTrialView[]): string | undefined {
167
+ const order: string[] = [];
168
+ const times = new Map<string, number[]>();
169
+ // A trial that errored, stopped or failed in the workflow's body was cut short: left out.
170
+ for (const t of trials.filter(
171
+ (t) => !t.record.errored && !t.record.workflowError && t.record.stopped === undefined,
172
+ )) {
173
+ for (const [stage, ms] of Object.entries(t.record.stageMs ?? {})) {
174
+ if (!times.has(stage)) {
175
+ order.push(stage);
176
+ times.set(stage, []);
177
+ }
178
+ times.get(stage)!.push(ms);
179
+ }
180
+ }
181
+ if (order.length === 0) return undefined;
182
+ return order.map((stage) => `${stage} ${seconds(median(times.get(stage)!)!)}`).join(" · ");
183
+ }
184
+
185
+ /** Pooled numbers in a line: each grader's, by name. */
186
+ function pooledText(pooled: ReturnType<typeof poolNumbers>): string {
187
+ const each = [...pooled.graders].map(
188
+ ([grader, numbers]) =>
189
+ `${grader} ${[...numbers].map(([name, n]) => `${name} ${describePooled(n)}`).join(", ")}`,
190
+ );
191
+ const left =
192
+ pooled.left > 0 ? `; ${plural(pooled.left, "trial")} the workflow failed left out` : "";
193
+ return `${each.join(" · ")}${left}`;
194
+ }
195
+
196
+ /** Of these trials, how many are another column's, said after a count. */
197
+ function elsewhere(run: RunRecord, trials: readonly StoredTrialView[]): string {
198
+ const counts = new Map<number, number>();
199
+ for (const t of trials) {
200
+ if (t.record.column > 0) counts.set(t.record.column, (counts.get(t.record.column) ?? 0) + 1);
201
+ }
202
+ return [...counts].map(([column, n]) => `, ${n} in ${columnLabel(run, column)}`).join("");
203
+ }
204
+
205
+ const agreed = (a: Agreement) =>
206
+ [
207
+ ...(a.good.labeled > 0 ? [`good ${a.good.labeled}, passed ${a.good.agreed}`] : []),
208
+ ...(a.needsWork.labeled > 0
209
+ ? [`needs-work ${a.needsWork.labeled}, failed ${a.needsWork.agreed}`]
210
+ : []),
211
+ ].join(" · ");
212
+
213
+ /**
214
+ * The person's labels against the lab's verdicts: good and needs-work apart, since a lab that
215
+ * passes everything agrees with a mostly good set; each deciding grader's; each disagreement.
216
+ */
217
+ function personLines(run: RunRecord, person: PersonAgreement): string[] {
218
+ const labeled = person.good.labeled + person.needsWork.labeled + person.notCompared;
219
+ const lines = [
220
+ `labels: ${plural(labeled, "trial")} · ${agreed(person) || "none compared"}${person.notCompared > 0 ? ` · ${person.notCompared} neither passed nor failed` : ""}`,
221
+ ];
222
+ for (const grader of person.graders) {
223
+ const cost = grader.cost > 0 ? ` · grading ${usd(grader.cost)}` : "";
224
+ const manual = grader.deciding ? "" : ", manual";
225
+ lines.push(` ${grader.grader}${manual}: ${agreed(grader)}${cost}`);
226
+ }
227
+ for (const d of person.disagreements) {
228
+ const where = d.column > 0 ? ` (${columnLabel(run, d.column)})` : "";
229
+ lines.push(
230
+ ` disagrees: ${d.case} trial ${d.trial}${where} labeled ${d.mark}${d.note ? `: ${d.note}` : ""}; the lab: ${d.outcome}`,
231
+ );
232
+ }
233
+ return lines;
234
+ }
235
+
236
+ /** Each case's tags, and how each column did on them: passed of cases, and which failed. */
237
+ export function tagRows(
238
+ rows: readonly CaseRow[],
239
+ tagsOf: (name: string) => readonly string[],
240
+ ): { tag: string; cases: number; passed: number; failing: string[] }[] {
241
+ const tags = [...new Set(rows.flatMap((r) => tagsOf(r.name)))].sort();
242
+ return tags.map((tag) => {
243
+ const tagged = rows.filter((r) => tagsOf(r.name).includes(tag) && r.tally.verdict);
244
+ return {
245
+ tag,
246
+ cases: tagged.length,
247
+ passed: tagged.filter((r) => r.tally.verdict === "passed").length,
248
+ failing: tagged.filter((r) => failing(r.tally.verdict)).map((r) => r.name),
249
+ };
250
+ });
251
+ }
252
+
253
+ function tagLines(
254
+ run: RunRecord,
255
+ rows: readonly CaseRow[],
256
+ others: readonly CaseRow[][],
257
+ tagsOf: (name: string) => readonly string[],
258
+ ): string[] {
259
+ const mine = tagRows(rows, tagsOf);
260
+ if (mine.length === 0) return [];
261
+ const theirs = others.map((column) => tagRows(column, tagsOf));
262
+ return [
263
+ "by tag:",
264
+ ...mine.map((t, i) => {
265
+ const elsewhere = theirs.map(
266
+ (column, c) => ` · ${columnLabel(run, c + 1)} ${column[i]!.passed}/${column[i]!.cases}`,
267
+ );
268
+ return ` ${t.tag.padEnd(16)} ${t.passed}/${t.cases} passed${elsewhere.join("")}${t.failing.length > 0 ? ` · failing: ${t.failing.join(", ")}` : ""}`;
269
+ }),
270
+ ];
271
+ }
272
+
273
+ /** The numbers and agreement lines, your checkout's column. */
274
+ function gradersLines(
275
+ trials: readonly StoredTrialView[],
276
+ decidersOf: RunReport["decidersOf"],
277
+ ): string[] {
278
+ const own = trials.filter((t) => t.record.column === 0);
279
+ const lines: string[] = [];
280
+ const pooled = poolNumbers(own);
281
+ if (pooled.graders.size > 0) lines.push(`numbers: ${pooledText(pooled)}`);
282
+ for (const pair of agreements(own, decidersOf)) {
283
+ const said = [
284
+ ...(pair.verdicts.of > 0
285
+ ? [`the same verdict on ${pair.verdicts.alike} of ${plural(pair.verdicts.of, "trial")}`]
286
+ : []),
287
+ ...(pair.parts.of > 0
288
+ ? [`the same label on ${pair.parts.alike} of ${plural(pair.parts.of, "part")}`]
289
+ : []),
290
+ ];
291
+ lines.push(`agreement, ${pair.a} and ${pair.b}: ${said.join("; ")}`);
292
+ }
293
+ return lines;
294
+ }
295
+
296
+ const failing = (v: CaseVerdict | undefined) => v === "failed" || v === "flaky" || v === "unclear";
297
+
298
+ /** Each case of yours beside the same case in another column, and the passes between them. */
299
+ function pairedRows(rows: readonly CaseRow[], column: readonly CaseRow[]) {
300
+ return rows.flatMap((mine) => {
301
+ const theirs = column.find((r) => r.name === mine.name);
302
+ return theirs ? [{ mine, theirs, gap: theirs.tally.passed - mine.tally.passed }] : [];
303
+ });
304
+ }
305
+
306
+ /** A case's passes and verdict, as the columns' differences show it: `1/2 flaky`. */
307
+ const showRow = (row: CaseRow) =>
308
+ `${row.tally.passed}/${row.tally.trials} ${row.tally.verdict ?? row.tally.none ?? ""}`.trim();
309
+
310
+ /** The pairs that came out differently: verdicts differ, or passes by 2 or more; largest first. */
311
+ function cameOutDifferently(pairs: ReturnType<typeof pairedRows>) {
312
+ return pairs
313
+ .filter((p) => p.mine.tally.verdict !== p.theirs.tally.verdict || Math.abs(p.gap) >= 2)
314
+ .sort((a, b) => Math.abs(b.gap) - Math.abs(a.gap));
315
+ }
316
+
317
+ /** The cases that came out differently in another column, as the report lists them. */
318
+ export function differingCases(
319
+ rows: readonly CaseRow[],
320
+ column: readonly CaseRow[],
321
+ ): { case: string; a: string; b: string }[] {
322
+ return cameOutDifferently(pairedRows(rows, column)).map(({ mine, theirs }) => ({
323
+ case: mine.name,
324
+ a: showRow(mine),
325
+ b: showRow(theirs),
326
+ }));
327
+ }
328
+
329
+ /**
330
+ * With more than one column: each column's folder and verdicts, the cases that came out
331
+ * differently (verdicts differ, or passes by 2 or more), largest difference first, and how many
332
+ * cases had more passes on each side. No column is called better: that is `compare`'s.
333
+ */
334
+ function columnLines(
335
+ run: RunRecord,
336
+ rows: readonly CaseRow[],
337
+ others: readonly CaseRow[][],
338
+ trials: readonly StoredTrialView[],
339
+ verdicts: readonly ColumnVerdict[] | undefined,
340
+ ): string[] {
341
+ const reference = columnLabel(run, 0);
342
+ const width = Math.max(14, ...run.columns.map((_, i) => columnLabel(run, i).length + 2));
343
+ const lines = [
344
+ `${"columns".padEnd(width + 2)}passed failed flaky unclear time, median est. cost, median`,
345
+ ];
346
+ const row = (label: string, list: readonly CaseRow[], column: number) => {
347
+ const n = (v: CaseVerdict) => String(list.filter((r) => r.tally.verdict === v).length);
348
+ const ran = trials.filter((t) => t.record.column === column && t.record.runId);
349
+ const ms = median(ran.map((t) => t.record.ms));
350
+ const cost = median(
351
+ ran.flatMap((t) => (t.record.estimate !== undefined ? [t.record.estimate] : [])),
352
+ );
353
+ lines.push(
354
+ ` ${label.padEnd(width)}${n("passed").padEnd(8)}${n("failed").padEnd(8)}${n("flaky").padEnd(7)}${n("unclear").padEnd(9)}${(ms !== undefined ? seconds(ms) : "-").padEnd(14)}${cost !== undefined ? usd(cost) : "-"}`,
355
+ );
356
+ };
357
+ row(reference, rows, 0);
358
+ for (const [i, column] of others.entries()) row(columnLabel(run, i + 1), column, i + 1);
359
+ // A budget that stopped the run part way leaves columns short of different cases.
360
+ const notRun = run.columns.map((_, i) => {
361
+ const ran = new Set(trials.filter((t) => t.record.column === i).map((t) => t.record.case));
362
+ return run.asked.map((a) => a.case).filter((name) => !ran.has(name));
363
+ });
364
+ if (notRun.some((names) => names.join() !== notRun[0]!.join())) {
365
+ for (const [i, names] of notRun.entries()) {
366
+ if (names.length > 0) {
367
+ lines.push(
368
+ ` ${columnLabel(run, i)}: ${plural(names.length, "case")} not run (${names.join(", ")})`,
369
+ );
370
+ }
371
+ }
372
+ }
373
+ // A dataset graded by numbers compares by them: each other column's, as yours are below.
374
+ for (const i of others.keys()) {
375
+ const pooled = poolNumbers(trials.filter((t) => t.record.column === i + 1));
376
+ if (pooled.graders.size > 0) {
377
+ lines.push(` numbers, ${columnLabel(run, i + 1)}: ${pooledText(pooled)}`);
378
+ }
379
+ }
380
+ // With no trial passed or failed in any column, as when every case is graded by numbers only,
381
+ // the pass and fail lines would only say that nothing did.
382
+ const decided = new Set(["passed", "failed", "stopped", "undecided"]);
383
+ const passFail = [rows, ...others].some((list) =>
384
+ list.some((r) => r.outcomes.some((o) => decided.has(o))),
385
+ );
386
+ others.forEach((column, i) => {
387
+ const label = columnLabel(run, i + 1);
388
+ const pairs = pairedRows(rows, column);
389
+ const differ = cameOutDifferently(pairs);
390
+ if (passFail) {
391
+ if (differ.length > 0) {
392
+ lines.push(`came out differently in ${label}, largest difference first`);
393
+ for (const { mine, theirs } of differ) {
394
+ lines.push(
395
+ ` ${mine.name.padEnd(20)} ${reference} ${showRow(mine)} · ${label} ${showRow(theirs)}`,
396
+ );
397
+ }
398
+ } else lines.push(`no case came out differently in ${label}`);
399
+ const more = pairs.filter((p) => p.gap > 0).length;
400
+ const fewer = pairs.filter((p) => p.gap < 0).length;
401
+ lines.push(
402
+ `more passes: ${label} on ${plural(more, "case")}, ${reference} on ${plural(fewer, "case")}`,
403
+ );
404
+ const difference = pairedDifference(rows, column);
405
+ if (difference) lines.push(`difference from ${reference}: ${describeDifference(difference)}`);
406
+ }
407
+ const said = verdicts?.[i];
408
+ if (said && "error" in said) lines.push(`compare, ${label}: could not tell: ${said.error}`);
409
+ else if (said) {
410
+ const { verdict } = said;
411
+ lines.push(
412
+ `compare, ${label}: ${verdict.verdict}${verdict.stop ? "" : ", more trials may tell"} · ${verdict.reason}`,
413
+ );
414
+ }
415
+ });
416
+ if (passFail) {
417
+ lines.push(`rates, ${reference}: ${describeRates(ratesOf(rows))}`);
418
+ for (const [i, column] of others.entries()) {
419
+ lines.push(`rates, ${columnLabel(run, i + 1)}: ${describeRates(ratesOf(column))}`);
420
+ }
421
+ }
422
+ if (run.asked.every((a) => a.trials === 1)) {
423
+ lines.push("One trial each: these are examples, not rates.");
424
+ } else if (!verdicts) {
425
+ lines.push("No compare in grading.ts says which is better. Read the cases.");
426
+ }
427
+ return lines;
428
+ }
429
+
430
+ const cell = (row: CaseRow | undefined) =>
431
+ row
432
+ ? `${row.tally.verdict ?? row.tally.none ?? "-"} ${row.tally.passed}/${row.tally.trials}`
433
+ : "-";
434
+
435
+ /**
436
+ * `report --md`: the run as Markdown to paste into a pull request or an issue: a table of cases
437
+ * by column, each column's rates and its difference and verdict against the reference.
438
+ */
439
+ export function markdownOf(report: RunReport): string {
440
+ const { run, rows, others = [], verdicts } = report;
441
+ const { exit } = renderRun(report);
442
+ const labels = run.columns.map((_, i) => columnLabel(run, i));
443
+ const lines = [
444
+ `### ${run.dataset} · run ${run.id}`,
445
+ "",
446
+ `${plural(run.asked.length, "case")} · ${plural(report.trials.length, "trial")}${run.columns.length > 1 ? ` in ${run.columns.length} columns` : ""} · exit ${exit}${exit === 3 ? "" : `: ${EXITS[exit]}`}`,
447
+ "",
448
+ `| case | ${labels.join(" | ")} |`,
449
+ `| --- | ${labels.map(() => "---").join(" | ")} |`,
450
+ ...rows.map(
451
+ (row) =>
452
+ `| ${row.name} | ${[cell(row), ...others.map((o) => cell(o.find((r) => r.name === row.name)))].join(" | ")} |`,
453
+ ),
454
+ "",
455
+ `- **${labels[0]}**: ${describeRates(ratesOf(rows))}`,
456
+ ];
457
+ for (const [i, column] of others.entries()) {
458
+ const difference = pairedDifference(rows, column);
459
+ const said = verdicts?.[i];
460
+ lines.push(
461
+ `- **${labels[i + 1]}**: ${describeRates(ratesOf(column))}${difference ? `; ${describeDifference(difference)}` : ""}${said && !("error" in said) ? `; compare: ${said.verdict.verdict}, ${said.verdict.reason}` : ""}`,
462
+ );
463
+ }
464
+ return lines.join("\n");
465
+ }
466
+
467
+ /** `run` and `report`'s text, and the exit code from your checkout's column. */
468
+ export function renderRun({
469
+ run,
470
+ rows,
471
+ trials,
472
+ criteria,
473
+ stale,
474
+ decidersOf,
475
+ others = [],
476
+ person,
477
+ judgeLabeled,
478
+ manual = new Set(),
479
+ judges,
480
+ tagsOf = () => [],
481
+ ungradedOf = () => undefined,
482
+ followsPlan = false,
483
+ verdicts: compared,
484
+ }: RunReport): {
485
+ text: string;
486
+ exit: ExitCode;
487
+ } {
488
+ const partial = run.finished === undefined || run.broke !== undefined;
489
+ const preconditionStop = run.stopped === "precondition";
490
+ const exit = exitCodeOf({ cases: rows, partial, preconditionStop });
491
+ const notRun = Math.max(
492
+ 0,
493
+ run.asked.reduce((n, a) => n + a.trials, 0) * run.columns.length - trials.length,
494
+ );
495
+ const counts = new Set(run.asked.map((a) => a.trials));
496
+ const each =
497
+ counts.size === 1 ? `${plural([...counts][0]!, "trial")} each` : "trials per case as asked";
498
+ // After its plan, which said the dataset, the code and the parameters, a run says what is new.
499
+ const lines = [
500
+ followsPlan
501
+ ? `run ${run.id}${partial ? " (partial)" : ""}`
502
+ : `${run.dataset} · ${plural(run.asked.length, "case")} · ${each} · run ${run.id}${partial ? " (partial)" : ""}`,
503
+ // The plan named each folder and its version.
504
+ ...(followsPlan
505
+ ? []
506
+ : [
507
+ `code: ${describeFolder({ ...run.folders[0]!, path: undefined })} · version ${run.folders[0]!.version}`,
508
+ ...run.folders
509
+ .slice(1)
510
+ .map(
511
+ (folder, i) =>
512
+ `against ${i + 1}: ${describeFolder(folder)} · version ${folder.version}`,
513
+ ),
514
+ ]),
515
+ ...(sharedParams(run).length > 0 && !followsPlan
516
+ ? [`params: ${sharedParams(run).join(" ")}`]
517
+ : []),
518
+ ...(run.stopped
519
+ ? [
520
+ run.stopped === "precondition"
521
+ ? `stopped: ${PRECONDITION_STOP}: ${preconditionFailure(trials) ?? "no trial says which"}; ${plural(notRun, "trial")} not run`
522
+ : run.stopped === "stage"
523
+ ? `stopped: ${stageFailure(trials) ?? "a stage a case named was never entered"}; ${plural(notRun, "trial")} not run`
524
+ : `${run.stopped === "budget" ? "stopped at --budget" : "stopped by the comparison"}: ${plural(notRun, "trial")} not run`,
525
+ ]
526
+ : []),
527
+ ...(run.columns.length > run.folders.length && !followsPlan
528
+ ? [`reference column: ${columnLabel(run, 0)}; the exit code and history are its`]
529
+ : []),
530
+ "",
531
+ ];
532
+ const line = (row: CaseRow, extra = "") => {
533
+ const history =
534
+ row.history.length > 0 ? ` history ${row.history.map((v) => MARK[v]).join("")}` : "";
535
+ const alsoFails = others.flatMap((column, i) => {
536
+ const there = column.find((r) => r.name === row.name)?.tally.verdict;
537
+ return failing(row.tally.verdict) && failing(there)
538
+ ? [`also fails in ${columnLabel(run, i + 1)}`]
539
+ : [];
540
+ });
541
+ const note = row.tally.note;
542
+ const said = [
543
+ ...row.notes,
544
+ ...(row.why ? [row.why] : []),
545
+ ...(note ? [note] : []),
546
+ ...alsoFails,
547
+ ];
548
+ return ` ${row.name.padEnd(20)} ${`${row.tally.passed}/${row.tally.trials}`.padEnd(5)} ${extra}${said.join("; ")}${history}`;
549
+ };
550
+ const section = (title: string, list: CaseRow[], extra?: (row: CaseRow) => string) => {
551
+ if (list.length === 0) return;
552
+ lines.push(title, ...list.map((row) => line(row, extra?.(row))));
553
+ };
554
+ const must = rows.filter((r) => !r.knownFailing);
555
+ const known = rows.filter((r) => r.knownFailing);
556
+ const nowPassing = known.filter((r) => r.tally.verdict === "passed");
557
+ section(
558
+ "failed, must pass",
559
+ must.filter((r) => r.tally.verdict === "failed"),
560
+ );
561
+ section(
562
+ "flaky",
563
+ must.filter((r) => r.tally.verdict === "flaky"),
564
+ );
565
+ section(
566
+ "unclear",
567
+ must.filter((r) => r.tally.verdict === "unclear"),
568
+ );
569
+ section(
570
+ "known failing",
571
+ known.filter((r) => r.tally.verdict !== "passed"),
572
+ );
573
+ section("known failing, now passing", nowPassing, (row) =>
574
+ row.tally.trials >= 3
575
+ ? "remove known-failing from its key? "
576
+ : "confirm with --trials 3 before removing known-failing; ",
577
+ );
578
+ section(
579
+ "passed, with notes",
580
+ must.filter((r) => r.tally.verdict === "passed" && r.notes.length > 0),
581
+ );
582
+ section(
583
+ "no verdict",
584
+ rows.filter((r) => r.tally.none),
585
+ (row) => {
586
+ const why =
587
+ row.tally.none === "not graded" ? (ungradedOf(row.name) ?? "no grader applies") : undefined;
588
+ const head = `${row.tally.none}${why ? `: ${why}` : ""}`;
589
+ const said = row.notes.length > 0 || row.why || row.tally.note;
590
+ return said ? `${head}${why ? "; " : ": "}` : head;
591
+ },
592
+ );
593
+ if (lines.at(-1) !== "") lines.push("");
594
+ if (others.length > 0) lines.push(...columnLines(run, rows, others, trials, compared), "");
595
+
596
+ // Each count once, and only when it is some: a zero says nothing.
597
+ const counted = (label: string, n: number, extra = "") =>
598
+ n > 0 ? [`${label} ${n}${extra}`] : [];
599
+ const verdicts = (v: CaseVerdict) => must.filter((r) => r.tally.verdict === v).length;
600
+ const tallies = [
601
+ ...counted("passed", verdicts("passed")),
602
+ ...counted("failed", verdicts("failed")),
603
+ ...counted("flaky", verdicts("flaky")),
604
+ ...counted("unclear", verdicts("unclear")),
605
+ ...counted(
606
+ "known failing",
607
+ known.length,
608
+ nowPassing.length > 0 ? ` (${nowPassing.length} now passing)` : "",
609
+ ),
610
+ ...counted("no verdict", rows.filter((r) => r.tally.none).length),
611
+ ];
612
+ if (tallies.length > 0) lines.push(tallies.join(" · "));
613
+ if (others.length === 0 && ratesOf(rows).cases > 0) {
614
+ lines.push(`rate: ${describeRates(ratesOf(rows))}`);
615
+ }
616
+ const tags = tagLines(run, rows, others, tagsOf);
617
+ if (tags.length > 0) lines.push(...tags);
618
+ const views = trials.map((t) => ({
619
+ ...t,
620
+ view: trialOutcome(t.record, t.scores, decidersOf?.(t.record.case)),
621
+ }));
622
+ const errored = views.filter((t) => t.view.outcome === "errored");
623
+ const by = (who: string) => errored.filter((t) => t.view.errored?.by === who).length;
624
+ const blame = ["dataset", "grading", "harness", "provider", "lab"]
625
+ .filter((who) => by(who) > 0)
626
+ .map((who) => `${by(who)} by ${who}`);
627
+ const reusedCount = trials.filter((t) => t.record.reused).length;
628
+ lines.push(
629
+ [
630
+ `trials ${trials.length}${run.columns.length > 1 ? ` in ${run.columns.length} columns` : ""}`,
631
+ ...counted("reused", reusedCount),
632
+ ...counted(
633
+ "errored",
634
+ errored.length,
635
+ `${blame.length > 0 ? ` (${blame.join(", ")})` : ""}${elsewhere(run, errored)}`,
636
+ ),
637
+ ...counted("undecided", views.filter((t) => t.view.outcome === "undecided").length),
638
+ ...counted("leaked", views.filter((t) => t.view.outcome === "leaked").length),
639
+ ].join(" · "),
640
+ );
641
+ const ran = views.filter((t) => t.view.outcome !== "errored" && t.record.runId);
642
+ const ms = median(ran.map((t) => t.record.ms));
643
+ const priced = ran.filter((t) => t.record.estimate !== undefined);
644
+ const cost = median(priced.map((t) => t.record.estimate!));
645
+ const total = trials.reduce((sum, t) => sum + (t.record.estimate ?? 0), 0);
646
+ const reusedCost = trials
647
+ .filter((t) => t.record.reused)
648
+ .reduce((sum, t) => sum + (t.record.estimate ?? 0), 0);
649
+ const grading = trials.reduce(
650
+ (sum, t) =>
651
+ sum +
652
+ t.scores.reduce(
653
+ (s, score) => s + score.entries.reduce((e, x) => e + (x.estimate ?? 0), 0),
654
+ 0,
655
+ ),
656
+ 0,
657
+ );
658
+ // A run with no agents costs nothing to price; one whose agents' count is unknown may.
659
+ const noAgents = total === 0 && ran.every((t) => t.record.agents === 0);
660
+ const unpriced = ran.some(
661
+ (t) =>
662
+ (t.record.estimate === undefined && t.record.agents !== 0) ||
663
+ (t.record.priced ?? 0) < (t.record.agents ?? 0),
664
+ );
665
+ if (ms !== undefined) {
666
+ lines.push(
667
+ [
668
+ `time per trial, median ${seconds(ms)}`,
669
+ ...(noAgents
670
+ ? ["the workflow ran no agents"]
671
+ : [
672
+ ...(cost !== undefined ? [`est. cost per trial, median ${usd(cost)}`] : []),
673
+ `all trials ${usd(total)}${reusedCost > 0 ? `, ${usd(reusedCost)} of it reused trials, run before` : ""}${unpriced ? ", partly unpriced" : ""}`,
674
+ ]),
675
+ ...(grading > 0 ? [`grading ${usd(grading)}`] : []),
676
+ ].join(" · "),
677
+ );
678
+ }
679
+ lines.push(...gradersLines(trials, decidersOf));
680
+ // With one trial per case, a stage's time across cases is worth a line; with more, `--case`.
681
+ if (run.asked.every((a) => a.trials === 1)) {
682
+ const stages = stageLine(trials.filter((t) => t.record.column === 0));
683
+ if (stages) lines.push(`time per stage, median across cases: ${stages}`);
684
+ }
685
+ if (typeof stale === "number" && stale > 0) {
686
+ lines.push(
687
+ `${plural(stale, "grade")} out of date, a key or grader changed: awf-lab score ${run.id.slice(-4)}`,
688
+ );
689
+ } else if (typeof stale === "object") {
690
+ lines.push(`grades: couldn't check whether any is out of date: ${stale.unread}`);
691
+ }
692
+ lines.push(...judgeLines(trials, criteria, judgeLabeled, manual, judges));
693
+ lines.push(...manualLines(trials, manual, decidersOf));
694
+ if (person) lines.push(...personLines(run, person));
695
+ lines.push(sandboxLine(run), "");
696
+ const why =
697
+ exit === 3
698
+ ? preconditionStop
699
+ ? `the run stopped: ${PRECONDITION_STOP}`
700
+ : partial
701
+ ? run.broke !== undefined
702
+ ? `the run is partial: the lab broke (${run.broke})`
703
+ : "the run is partial"
704
+ : !rows.some((r) => r.tally.verdict || r.tally.none === "graded by numbers")
705
+ ? "no case was graded"
706
+ : "a case is flaky or unclear"
707
+ : EXITS[exit];
708
+ lines.push(`exit ${exit}: ${why}`);
709
+ return { text: lines.join("\n"), exit };
710
+ }
711
+
712
+ /** One case in full: each trial's result, facts, refusals and grades, and how to open its logs. */
713
+ export function renderCase({
714
+ run,
715
+ row,
716
+ trials,
717
+ logsCommand,
718
+ deciders,
719
+ others = [],
720
+ labels = new Map(),
721
+ }: {
722
+ run: RunRecord;
723
+ row: CaseRow;
724
+ trials: readonly StoredTrialView[];
725
+ /** How to open a trial's logs, by its id. */
726
+ logsCommand: (trialId: string) => string;
727
+ deciders?: ReadonlySet<string> | undefined;
728
+ /** This case's row in each other column. */
729
+ others?: readonly (CaseRow | undefined)[];
730
+ /** The person's labels, by trial id. */
731
+ labels?: ReadonlyMap<string, LabelRecord>;
732
+ }): string {
733
+ const tally = (r: CaseRow) =>
734
+ `${r.tally.verdict ?? r.tally.none ?? "no trials"} ${r.tally.passed}/${r.tally.trials}`;
735
+ const lines = [
736
+ `${row.name} · run ${run.id} · ${tally(row)}`,
737
+ ...others.flatMap((other, i) => (other ? [`${columnLabel(run, i + 1)}: ${tally(other)}`] : [])),
738
+ ];
739
+ const stages = stageLine(trials.filter((t) => t.record.column === 0));
740
+ if (stages) lines.push(`time per stage, median: ${stages}`);
741
+ for (const trial of trials) {
742
+ const { record } = trial;
743
+ const view = trialOutcome(record, trial.scores, deciders);
744
+ lines.push(
745
+ "",
746
+ `trial ${record.trial}${record.column > 0 ? ` (${columnLabel(run, record.column)})` : ""}: ${view.outcome}${record.runId ? ` · id ${record.runId}` : ""} · ${seconds(record.ms)}`,
747
+ );
748
+ const label = record.runId ? labels.get(record.runId) : undefined;
749
+ if (label) lines.push(` labeled ${label.mark}${label.note ? `: ${label.note}` : ""}`);
750
+ else if (record.runId)
751
+ lines.push(` label: awf-lab label ${record.runId} --good | --needs-work "{note}"`);
752
+ if (record.errored) {
753
+ lines.push(
754
+ ` errored by ${record.errored.by} in ${record.errored.phase}${record.errored.code ? ` (${record.errored.code})` : ""}: ${record.errored.reason}`,
755
+ );
756
+ }
757
+ if (record.workflowError) lines.push(` the workflow erred: ${record.workflowError}`);
758
+ if (record.stopped) lines.push(` stopped: ${record.stopped}`);
759
+ if (record.leaked) lines.push(" leaked: the key turned up where the workflow ran");
760
+ for (const refused of record.refused) {
761
+ lines.push(` refused in ${refused.phase}: ${refused.message}`);
762
+ }
763
+ for (const unused of record.unused) lines.push(` ${unused} was faked but never called`);
764
+ if (record.reach && !record.reach.ok) {
765
+ for (const problem of record.reach.problems) lines.push(` reach: ${problem}`);
766
+ }
767
+ const facts = factsOf(trial.scores);
768
+ if (facts) lines.push(` facts: ${JSON.stringify(facts)}`);
769
+ if (record.runFacts) lines.push(` run facts: ${JSON.stringify(record.runFacts)}`);
770
+ if (record.result !== undefined) lines.push(` result: ${JSON.stringify(record.result)}`);
771
+ for (const entry of newestEntries(trial.scores)) {
772
+ const verdict = entry.errored
773
+ ? `errored: ${entry.errored.reason}`
774
+ : entry.skipped
775
+ ? "not graded: a grader before it failed the trial"
776
+ : (entry.verdict ??
777
+ (entry.notApplies ? `does not apply: ${entry.notApplies}` : "numbers only"));
778
+ const about = [
779
+ ...(entry.version ? [entry.version] : []),
780
+ ...(deciders && !deciders.has(entry.grader) ? ["not in the verdict"] : []),
781
+ ...(entry.estimate !== undefined ? [`est. ${usd(entry.estimate)}`] : []),
782
+ ...(entry.runId ? [`run ${entry.runId}`] : []),
783
+ ];
784
+ lines.push(
785
+ ` ${entry.grader}: ${verdict}${about.length > 0 ? ` (${about.join(", ")})` : ""}`,
786
+ );
787
+ for (const [name, number] of Object.entries(entry.numbers ?? {})) {
788
+ lines.push(
789
+ ` ${name}: ${"count" in number ? `${number.count}/${number.of}` : number.value}`,
790
+ );
791
+ }
792
+ // A reason a part's own line already says, as its why, is said once.
793
+ const parts = new Set(
794
+ (entry.parts ?? []).filter((p) => p.why && p.why.trim() !== "").map((p) => p.about),
795
+ );
796
+ for (const reason of entry.reasons.filter((r) => !parts.has(r.about))) {
797
+ lines.push(` ${reason.about}: ${reason.text}`);
798
+ }
799
+ for (const part of entry.parts ?? []) {
800
+ const settled = part.settled && part.settled !== "agreed" ? ` [${part.settled}]` : "";
801
+ const read = (part.data as { readNotRun?: boolean } | undefined)?.readNotRun
802
+ ? " (read, not run)"
803
+ : "";
804
+ lines.push(
805
+ ` ${part.about}: ${part.verdict ?? part.label}${settled}${read}${part.why ? ` · ${part.why}` : ""}`,
806
+ );
807
+ // A split is worth reading vote by vote; an agreement is its why.
808
+ if (part.settled && part.settled !== "agreed" && part.settled !== "given") {
809
+ for (const vote of part.votes ?? []) {
810
+ const said = vote.verdict ?? vote.label ?? "no answer";
811
+ lines.push(
812
+ ` ${vote.by}${vote.role ? ` (${vote.role})` : ""}: ${said}${vote.why ? ` · ${vote.why}` : ""}`,
813
+ );
814
+ }
815
+ }
816
+ }
817
+ }
818
+ if (record.files.length > 0) lines.push(` files: ${record.files.join(", ")}`);
819
+ if (record.runId) lines.push(` logs: ${logsCommand(record.runId)}`);
820
+ }
821
+ return lines.join("\n");
822
+ }
823
+
824
+ const SANDBOX_TEXT = {
825
+ lab: "the lab's box around each trial, srt, reading no key; the workflow's own set aside",
826
+ workflow: "the workflow's own, its agents' reach checked against sandbox.network",
827
+ } as const;
828
+
829
+ /** Who isolated the trials: one line, naming each column's when their `trial.ts`s differ. */
830
+ function sandboxLine(run: RunRecord): string {
831
+ const byColumn = run.columns.map((c) => run.folders[c.folder]?.sandbox.by ?? "lab");
832
+ const kinds = new Set(byColumn);
833
+ if (kinds.size <= 1) return `sandbox: ${SANDBOX_TEXT[byColumn[0] ?? "lab"]}`;
834
+ const each = byColumn.map(
835
+ (by, i) => `${columnLabel(run, i)} ${by === "lab" ? "the lab's box" : "the workflow's own"}`,
836
+ );
837
+ return `sandbox: by column, ${each.join(", ")}`;
838
+ }