@agentswf/lab 0.3.0 → 0.4.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 (88) hide show
  1. package/package.json +4 -4
  2. package/schema/{case-check.schema.json → lab-check.schema.json} +1 -1
  3. package/schema/{case-config.schema.json → lab-config.schema.json} +1 -1
  4. package/schema/{case-final.schema.json → lab-final.schema.json} +6 -6
  5. package/schema/{case-grade.schema.json → lab-grade.schema.json} +1 -1
  6. package/schema/{case-key.schema.json → lab-key.schema.json} +7 -0
  7. package/schema/{case-label.schema.json → lab-label.schema.json} +3 -3
  8. package/schema/{case-loop-report.schema.json → lab-loop-report.schema.json} +26 -15
  9. package/schema/{case-loop.schema.json → lab-loop.schema.json} +1 -1
  10. package/schema/{case-plan.schema.json → lab-plan.schema.json} +14 -3
  11. package/schema/{case-proposal.schema.json → lab-proposal.schema.json} +3 -3
  12. package/schema/{case-report.schema.json → lab-report.schema.json} +272 -36
  13. package/schema/{case-run.schema.json → lab-run.schema.json} +4 -4
  14. package/schema/{case-runs.schema.json → lab-runs.schema.json} +8 -1
  15. package/schema/{case-score.schema.json → lab-score.schema.json} +2 -2
  16. package/schema/{case-spread.schema.json → lab-spread.schema.json} +6 -6
  17. package/schema/{case-trial.schema.json → lab-trial.schema.json} +9 -9
  18. package/schema/{case-try.schema.json → lab-try.schema.json} +6 -6
  19. package/schema/local.json +3 -3
  20. package/src/env/capture.ts +1 -1
  21. package/src/env/compare.ts +7 -7
  22. package/src/env/fetch.ts +1 -1
  23. package/src/env/files.ts +14 -14
  24. package/src/env/grade-helper.ts +15 -15
  25. package/src/env/grader.ts +5 -2
  26. package/src/env/index.ts +18 -18
  27. package/src/env/trial.ts +5 -2
  28. package/src/format/key.ts +24 -0
  29. package/src/format/loop.ts +20 -19
  30. package/src/format/output.ts +120 -59
  31. package/src/format/records.ts +23 -20
  32. package/src/format/schema-files.ts +30 -30
  33. package/src/format/settings.ts +20 -13
  34. package/src/format/trial-env.ts +9 -6
  35. package/src/help/awf-lab.txt +1 -1
  36. package/src/help/case.txt +5 -4
  37. package/src/help/config.txt +2 -2
  38. package/src/help/label.txt +2 -2
  39. package/src/help/loop.txt +10 -10
  40. package/src/help/report.txt +1 -1
  41. package/src/help/run.txt +11 -10
  42. package/src/help/runs.txt +4 -3
  43. package/src/help/score.txt +4 -3
  44. package/src/lab/blame.ts +1 -1
  45. package/src/lab/box.ts +7 -5
  46. package/src/lab/capture-command.ts +11 -7
  47. package/src/lab/capture.ts +1 -1
  48. package/src/lab/check-command.ts +3 -3
  49. package/src/lab/cli.ts +9 -8
  50. package/src/lab/columns.ts +5 -5
  51. package/src/lab/command-context.ts +7 -7
  52. package/src/lab/compare.ts +8 -8
  53. package/src/lab/config-command.ts +25 -20
  54. package/src/lab/dataset.ts +37 -18
  55. package/src/lab/eval-files.ts +27 -16
  56. package/src/lab/folders.ts +26 -7
  57. package/src/lab/good.ts +1 -1
  58. package/src/lab/grading-stub.txt +2 -2
  59. package/src/lab/inspect.ts +13 -12
  60. package/src/lab/labels.ts +16 -11
  61. package/src/lab/loop-command.ts +68 -64
  62. package/src/lab/loop-records.ts +5 -5
  63. package/src/lab/loop.ts +105 -100
  64. package/src/lab/rates.ts +11 -6
  65. package/src/lab/record-copies.ts +1 -1
  66. package/src/lab/report-command.ts +8 -7
  67. package/src/lab/report.ts +172 -74
  68. package/src/lab/reuse.ts +29 -21
  69. package/src/lab/run-command.ts +304 -199
  70. package/src/lab/run-report.ts +49 -22
  71. package/src/lab/runs-command.ts +35 -27
  72. package/src/lab/scaffold.ts +19 -16
  73. package/src/lab/score-command.ts +72 -64
  74. package/src/lab/score.ts +1 -1
  75. package/src/lab/store.ts +3 -3
  76. package/src/lab/{trial-stub.txt → target-stub.txt} +3 -3
  77. package/src/lab/trial-settings.ts +17 -12
  78. package/src/lab/trial.ts +19 -23
  79. package/src/lab/usage.ts +1 -0
  80. package/src/lab/workflow-graders.ts +4 -1
  81. package/src/lab/workspace.ts +16 -9
  82. package/src/loop/propose.workflow.ts +1 -1
  83. package/src/shared/compare/index.ts +2 -2
  84. package/src/shared/compare/paired.ts +20 -20
  85. package/src/shared/compare/types.ts +4 -4
  86. package/src/write-schemas.ts +3 -3
  87. /package/schema/{case-good-record.schema.json → lab-good-record.schema.json} +0 -0
  88. /package/schema/{case-previous.schema.json → lab-previous.schema.json} +0 -0
package/src/lab/loop.ts CHANGED
@@ -48,9 +48,9 @@ import { Refusal } from "./refusal";
48
48
  import { usd } from "./text";
49
49
  import type { CaseWorkspace } from "./workspace";
50
50
 
51
- // The loop: a proposer changes a copy of the incumbent's code, the copy runs against the incumbent
52
- // on the tuning cases until the dataset's `compare` stops it, and it becomes the incumbent only on
53
- // `better`. Its code and records live in the store, `loops/{id}/`.
51
+ // The loop: a proposer changes a copy of the best version so far, the copy runs against it on the
52
+ // tuning cases until the dataset's `compare` stops it, and it becomes the best version so far only
53
+ // on `better`. Its code and records live in the store, `loops/{id}/`.
54
54
 
55
55
  /** The entry's brief as the loop started with it, beside `loop.json`. */
56
56
  export const BRIEF_FILE = "brief.md";
@@ -159,7 +159,7 @@ export const codeOf = (dir: string, n: number) =>
159
159
  n === 0 ? join(dir, "start") : join(dir, "tries", String(n), "code");
160
160
 
161
161
  /**
162
- * The version a loop's code runs under, in place of `trial.ts`'s: the loop's own id of it, the
162
+ * The version a loop's code runs under, in place of `target.ts`'s: the loop's own id of it, the
163
163
  * start's from the loop's name and when it started, a try's with its number. A loop started again
164
164
  * has another, so it shares no trial with the one before it.
165
165
  */
@@ -172,13 +172,13 @@ const columnOf = (loop: Loop, dir: string, n: number) => ({
172
172
  version: loopVersionOf(loop, n),
173
173
  });
174
174
 
175
- /** The incumbent: the last kept try, or the start. */
176
- export const incumbentOf = (tries: readonly Try[]) =>
177
- tries.filter((t) => t.decision === "kept").at(-1)?.n ?? 0;
175
+ /** The best version so far: the last kept try, or the start. */
176
+ export const bestSoFarOf = (tries: readonly Try[]) =>
177
+ tries.filter((t) => t.outcome === "kept").at(-1)?.n ?? 0;
178
178
 
179
- /** What a try's run gave the loop: its run, how it ended, the verdict on the second column. */
179
+ /** What a try's run gave the loop: its run, how it ended, the decision on the second column. */
180
180
  export type TryRun = {
181
- runId: string;
181
+ labRun: string;
182
182
  /**
183
183
  * `budget`, the cap stopped it; `compare`, the comparison did; `precondition`, the environment;
184
184
  * `stage`, a case named a stage its run never entered.
@@ -188,9 +188,9 @@ export type TryRun = {
188
188
  precondition?: string;
189
189
  /** Under a stage stop, the trial's reason. */
190
190
  stage?: string;
191
- verdict?:
191
+ decision?:
192
192
  | {
193
- verdict: string;
193
+ decision: string;
194
194
  stop: boolean;
195
195
  reason: string;
196
196
  /** The comparison's metrics, the second column's minus the first's. */
@@ -198,7 +198,7 @@ export type TryRun = {
198
198
  }
199
199
  | { error: string };
200
200
  /** The estimates of its own trials and grades, not those it reused. */
201
- spend: number;
201
+ estimate: number;
202
202
  };
203
203
 
204
204
  /** A case that came out differently between a run's two columns, each one's passes. */
@@ -212,7 +212,7 @@ export type LoopDeps = {
212
212
  folders: readonly { dir: string; version: string }[];
213
213
  order: readonly string[];
214
214
  budget: number;
215
- stopOnVerdict: boolean;
215
+ stopOnDecision: boolean;
216
216
  holdout?: boolean;
217
217
  /** Called with the run's id as it starts, before any trial. */
218
218
  started?: (runId: string) => void;
@@ -244,7 +244,7 @@ export type LoopDeps = {
244
244
  code: string;
245
245
  bundle: string;
246
246
  proposer: string;
247
- }): Promise<{ hypothesis?: Hypothesis; why?: string; spend: number; runId?: string }>;
247
+ }): Promise<{ hypothesis?: Hypothesis; why?: string; estimate: number; runId?: string }>;
248
248
  /** Waits while a plan window the loop draws on is nearly used. */
249
249
  waitForAllowance(): Promise<void>;
250
250
  /** The comparison's version, from `grading.ts`, as a loop records it. */
@@ -261,7 +261,7 @@ export type LoopRequest = {
261
261
  /** The tuning cases: those the entry picks of the cases the dataset doesn't hold out. */
262
262
  tuning: readonly CaseInfo[];
263
263
  holdout: readonly string[];
264
- rounds: number;
264
+ tries: number;
265
265
  /** This command's cap on its estimates: a loop keeps none of its own. */
266
266
  budget: number;
267
267
  /** What the entry says now; a new loop records it, and a resumed one was checked against it. */
@@ -387,10 +387,10 @@ function startOrResume(request: LoopRequest, deps: LoopDeps): Loop {
387
387
  * What a loop's records are estimated at so far: its spread, every try decided and one cut short,
388
388
  * and every final check. `report --loop` gives it; a command's `--budget` counts only its own.
389
389
  */
390
- export function loopSpend(
390
+ export function loopEstimates(
391
391
  dir: string,
392
392
  estimatedIn: LoopDeps["estimatedIn"],
393
- ): { spread: number; tries: number; pending?: { n: number; spend: number }; finals: number } {
393
+ ): { spread: number; tries: number; pending?: { n: number; estimate: number }; finals: number } {
394
394
  const deps = { estimatedIn } as Pick<LoopDeps, "estimatedIn">;
395
395
  const file = join(dir, SPREAD_FILE);
396
396
  const spread = existsSync(file) ? readChecked<Spread>(file, SpreadSchema) : undefined;
@@ -399,10 +399,12 @@ export function loopSpend(
399
399
  const pending = tryLedger(join(dir, "tries", String(n)), deps).total();
400
400
  return {
401
401
  spread:
402
- spread && "spend" in spread ? spread.spend : tryLedger(join(dir, "spread"), deps).total(),
403
- tries: tries.reduce((sum, t) => sum + t.spend.proposer + t.spend.trials, 0),
404
- ...(pending > 0 ? { pending: { n, spend: pending } } : {}),
405
- finals: readFinals(dir).reduce((sum, f) => sum + f.spend, 0),
402
+ spread && "estimate" in spread
403
+ ? spread.estimate
404
+ : tryLedger(join(dir, "spread"), deps).total(),
405
+ tries: tries.reduce((sum, t) => sum + t.estimate.proposer + t.estimate.trials, 0),
406
+ ...(pending > 0 ? { pending: { n, estimate: pending } } : {}),
407
+ finals: readFinals(dir).reduce((sum, f) => sum + f.estimate, 0),
406
408
  };
407
409
  }
408
410
 
@@ -423,7 +425,7 @@ function tryLedger(tryDir: string, deps: Pick<LoopDeps, "estimatedIn">) {
423
425
  .filter(Boolean)
424
426
  .reduce((sum, line) => sum + (JSON.parse(line) as { usd: number }).usd, 0)
425
427
  : 0;
426
- const spend = () => ({ proposer: proposer(), trials: deps.estimatedIn(runs()) });
428
+ const estimate = () => ({ proposer: proposer(), trials: deps.estimatedIn(runs()) });
427
429
  return {
428
430
  started(runId: string) {
429
431
  mkdirSync(tryDir, { recursive: true });
@@ -432,9 +434,9 @@ function tryLedger(tryDir: string, deps: Pick<LoopDeps, "estimatedIn">) {
432
434
  proposed(usd: number, runId?: string) {
433
435
  appendFileSync(proposerFile, `${JSON.stringify({ usd, ...(runId ? { runId } : {}) })}\n`);
434
436
  },
435
- spend,
437
+ estimate,
436
438
  total: () => {
437
- const { proposer, trials } = spend();
439
+ const { proposer, trials } = estimate();
438
440
  return proposer + trials;
439
441
  },
440
442
  };
@@ -444,9 +446,9 @@ export const digestOf = (bytes: Uint8Array) =>
444
446
  `sha256:${createHash("sha256").update(bytes).digest("hex")}`;
445
447
 
446
448
  /**
447
- * Tries until the rounds, the cap or a stall. Each try: the incumbent runs on the tuning cases (its
449
+ * Tries until --tries, the cap or a stall. Each try: the best version so far runs on the tuning cases (its
448
450
  * trials reused where nothing changed), the proposer changes a copy of it from that feedback, the
449
- * change's scope is checked, and the copy runs against the incumbent case by case until `compare`
451
+ * change's scope is checked, and the copy runs against it case by case until `compare`
450
452
  * stops it. Every try is written once, so a loop resumes where it stopped, its estimates summed
451
453
  * from its own records.
452
454
  */
@@ -472,21 +474,21 @@ export async function runLoop(request: LoopRequest, deps: LoopDeps): Promise<Loo
472
474
  if (!fresh) deps.log(`loop ${loopIdOf(loop)} goes on`);
473
475
  // The budget is this command's: what the loop's records already hold is counted under it, so
474
476
  // the sums below run over the loop's whole history.
475
- const spent = loopSpend(dir, deps.estimatedIn);
476
- const cap = request.budget + spent.spread + spent.tries + (spent.pending?.spend ?? 0);
477
- let estimated = tries.reduce((sum, t) => sum + t.spend.proposer + t.spend.trials, 0);
477
+ const earlier = loopEstimates(dir, deps.estimatedIn);
478
+ const cap = request.budget + earlier.spread + earlier.tries + (earlier.pending?.estimate ?? 0);
479
+ let estimated = tries.reduce((sum, t) => sum + t.estimate.proposer + t.estimate.trials, 0);
478
480
  const capped = (what: string): LoopOutcome => ({
479
481
  exit: 3,
480
482
  why: `this command's estimates reach its --budget of ${usd(request.budget)}${what}: loop run ${loop.name} again goes on`,
481
483
  });
482
484
  const unready = (ran: TryRun, what: string): LoopOutcome => ({
483
485
  exit: 3,
484
- why: `${what} ${ran.runId} stopped: ${PRECONDITION_STOP}: ${ran.precondition ?? "no trial says which"}; nothing decided: awf-lab loop run ${loop.name} again once it holds`,
486
+ why: `${what} ${ran.labRun} stopped: ${PRECONDITION_STOP}: ${ran.precondition ?? "no trial says which"}; nothing decided: awf-lab loop run ${loop.name} again once it holds`,
485
487
  });
486
488
  // A stage never entered is the dataset's, and would be again in every run: nothing decided.
487
489
  const misnamed = (ran: TryRun, what: string): LoopOutcome => ({
488
490
  exit: 3,
489
- why: `${what} ${ran.runId} stopped: ${ran.stage ?? "a stage the case named was never entered"}; nothing decided`,
491
+ why: `${what} ${ran.labRun} stopped: ${ran.stage ?? "a stage the case named was never entered"}; nothing decided`,
490
492
  });
491
493
  const spreadFile = join(dir, SPREAD_FILE);
492
494
  const spreadLedger = tryLedger(join(dir, "spread"), deps);
@@ -500,32 +502,32 @@ export async function runLoop(request: LoopRequest, deps: LoopDeps): Promise<Loo
500
502
  if (left() <= 0) return capped(" by the start's spread");
501
503
  await deps.waitForAllowance();
502
504
  deps.log(`the start twice, on ${tuning.length} tuning cases`);
503
- // Two columns of the same code: reuse gives each its own trials, and try 1's incumbent
504
- // reuses them, so the spread costs one more run of the start, once.
505
+ // Two columns of the same code: reuse gives each its own trials, and try 1's run of the
506
+ // start reuses them, so the spread costs one more run of the start, once.
505
507
  const ran = await deps.runFolders({
506
508
  folders: [columnOf(loop, dir, 0), columnOf(loop, dir, 0)],
507
509
  order: loop.tuning,
508
510
  budget: left(),
509
- stopOnVerdict: false,
511
+ stopOnDecision: false,
510
512
  started: spreadLedger.started,
511
513
  });
512
514
  if (ran.stopped === "budget" || left() <= 0) {
513
- return capped(` by the start's spread, run ${ran.runId}`);
515
+ return capped(` by the start's spread, run ${ran.labRun}`);
514
516
  }
515
517
  if (ran.stopped === "precondition") return unready(ran, "the start's spread: its run");
516
518
  if (ran.stopped === "stage") return misnamed(ran, "the start's spread: its run");
517
519
  // A column with no trial of the workflow's measures nothing; unrecorded, a resume measures again.
518
- if ([0, 1].some((column) => deps.feedback(ran.runId, column).trials.length === 0)) {
520
+ if ([0, 1].some((column) => deps.feedback(ran.labRun, column).trials.length === 0)) {
519
521
  return {
520
522
  exit: 3,
521
- why: `the start's spread: every trial of a column of run ${ran.runId} was errored or leaked, so it measures nothing; nothing decided: awf-lab report ${ran.runId}`,
523
+ why: `the start's spread: every trial of a column of run ${ran.labRun} was errored or leaked, so it measures nothing; nothing decided: awf-lab report ${ran.labRun}`,
522
524
  };
523
525
  }
524
- const measured = spreadOf(ran, deps.differed(ran.runId), {
526
+ const measured = spreadOf(ran, deps.differed(ran.labRun), {
525
527
  at: deps.now().toISOString(),
526
528
  trials: loop.trials,
527
529
  cases: tuning.length,
528
- spend: spreadLedger.total(),
530
+ estimate: spreadLedger.total(),
529
531
  });
530
532
  writeJson(spreadFile, measured, "wx");
531
533
  deps.log(spreadLine(measured));
@@ -536,8 +538,8 @@ export async function runLoop(request: LoopRequest, deps: LoopDeps): Promise<Loo
536
538
  }
537
539
  // Before the first try: a try is kept only once it wins enough cases, and it can win only one the
538
540
  // start doesn't always pass. Too few such, and no try could be kept, however good.
539
- if (tries.length === 0 && spread && "runId" in spread) {
540
- const room = await deps.room(spread.runId);
541
+ if (tries.length === 0 && spread && "labRun" in spread) {
542
+ const room = await deps.room(spread.labRun);
541
543
  if (room && room.canWin < room.needed) {
542
544
  return {
543
545
  exit: 3,
@@ -545,7 +547,7 @@ export async function runLoop(request: LoopRequest, deps: LoopDeps): Promise<Loo
545
547
  };
546
548
  }
547
549
  }
548
- estimated += spread && "spend" in spread ? spread.spend : spreadLedger.total();
550
+ estimated += spread && "estimate" in spread ? spread.estimate : spreadLedger.total();
549
551
  const unsteady = spread && "unsteady" in spread ? spread.unsteady : undefined;
550
552
  /** What a try's why says of the start's spread: the cases it moved on that also moved alone. */
551
553
  const againstSpread = (runId: string) => {
@@ -560,7 +562,7 @@ export async function runLoop(request: LoopRequest, deps: LoopDeps): Promise<Loo
560
562
  /** One try, decided; or why the loop stops before it is. */
561
563
  const oneTry = async (): Promise<LoopOutcome | undefined> => {
562
564
  const n = tries.length + 1;
563
- const parent = incumbentOf(tries);
565
+ const parent = bestSoFarOf(tries);
564
566
  const tryDir = join(dir, "tries", String(n));
565
567
  const code = codeOf(dir, n);
566
568
  // What this try is estimated at, from records it keeps across a cut: the runs it started, read from
@@ -568,19 +570,19 @@ export async function runLoop(request: LoopRequest, deps: LoopDeps): Promise<Loo
568
570
  const ledger = tryLedger(tryDir, deps);
569
571
  const left = () => cap - estimated - ledger.total();
570
572
  if (left() <= 0) return capped("");
571
- const decide = (fields: Omit<Try, "kind" | "n" | "at" | "parent" | "spend">) => {
573
+ const decide = (fields: Omit<Try, "kind" | "n" | "at" | "parent" | "estimate">) => {
572
574
  const record: Try = {
573
575
  kind: TRY_KIND,
574
576
  n,
575
577
  at: deps.now().toISOString(),
576
578
  parent,
577
579
  ...fields,
578
- spend: ledger.spend(),
580
+ estimate: ledger.estimate(),
579
581
  };
580
582
  writeJson(join(tryDir, "try.json"), record, "wx");
581
583
  tries.push(record);
582
- estimated += record.spend.proposer + record.spend.trials;
583
- deps.log(`try ${n}: ${record.decision}: ${record.why}`);
584
+ estimated += record.estimate.proposer + record.estimate.trials;
585
+ deps.log(`try ${n}: ${record.outcome}: ${record.why}`);
584
586
  return record;
585
587
  };
586
588
 
@@ -597,19 +599,22 @@ export async function runLoop(request: LoopRequest, deps: LoopDeps): Promise<Loo
597
599
  }
598
600
  mkdirSync(tryDir, { recursive: true });
599
601
  await deps.waitForAllowance();
600
- deps.log(`try ${n}: the incumbent, try ${parent}, on ${tuning.length} tuning cases`);
602
+ deps.log(
603
+ `try ${n}: the best version so far, try ${parent}, on ${tuning.length} tuning cases`,
604
+ );
601
605
  const fed = await deps.runFolders({
602
606
  folders: [columnOf(loop, dir, parent)],
603
607
  order: loop.tuning,
604
608
  budget: left(),
605
- stopOnVerdict: false,
609
+ stopOnDecision: false,
606
610
  started: ledger.started,
607
611
  });
608
612
  if (fed.stopped === "budget" || left() <= 0)
609
- return capped(` by the incumbent's run ${fed.runId}`);
610
- if (fed.stopped === "precondition") return unready(fed, `try ${n}: the incumbent's run`);
611
- if (fed.stopped === "stage") return misnamed(fed, `try ${n}: the incumbent's run`);
612
- const feedback = deps.feedback(fed.runId, 0);
613
+ return capped(` by the best version so far's run ${fed.labRun}`);
614
+ if (fed.stopped === "precondition")
615
+ return unready(fed, `try ${n}: the best version so far's run`);
616
+ if (fed.stopped === "stage") return misnamed(fed, `try ${n}: the best version so far's run`);
617
+ const feedback = deps.feedback(fed.labRun, 0);
613
618
  const others = feedback.others;
614
619
  if (others.length > 0) {
615
620
  const shown = others.slice(0, OTHERS_SHOWN);
@@ -618,13 +623,13 @@ export async function runLoop(request: LoopRequest, deps: LoopDeps): Promise<Loo
618
623
  `try ${n}: ${others.length} trial${others.length === 1 ? "" : "s"} not the workflow's, left out of the proposer's feedback:`,
619
624
  );
620
625
  for (const line of shown) deps.log(` ${line}`);
621
- if (more > 0) deps.log(` and ${more} more: awf-lab report ${fed.runId}`);
626
+ if (more > 0) deps.log(` and ${more} more: awf-lab report ${fed.labRun}`);
622
627
  }
623
628
  // Nothing of the workflow's to learn from: a proposal would be a guess, at the proposer's cost.
624
629
  if (feedback.trials.length === 0) {
625
630
  return {
626
631
  exit: 3,
627
- why: `try ${n}: every trial of the incumbent's run ${fed.runId} was errored or leaked, so the proposer has nothing to read; nothing decided: awf-lab report ${fed.runId}`,
632
+ why: `try ${n}: every trial of the best version so far's run ${fed.labRun} was errored or leaked, so the proposer has nothing to read; nothing decided: awf-lab report ${fed.labRun}`,
628
633
  };
629
634
  }
630
635
  branchCode(codeOf(dir, parent), code, request.top);
@@ -634,10 +639,10 @@ export async function runLoop(request: LoopRequest, deps: LoopDeps): Promise<Loo
634
639
  writeJson(join(bundle, "feedback.json"), feedback.trials);
635
640
  writeJson(
636
641
  join(bundle, "history.json"),
637
- tries.map(({ n, parent, decision, why, hypothesis, changed }) => ({
642
+ tries.map(({ n, parent, outcome, why, hypothesis, changed }) => ({
638
643
  n,
639
644
  parent,
640
- decision,
645
+ outcome,
641
646
  why,
642
647
  ...(hypothesis ? { hypothesis } : {}),
643
648
  changed,
@@ -647,7 +652,7 @@ export async function runLoop(request: LoopRequest, deps: LoopDeps): Promise<Loo
647
652
  comparison: loop.comparison,
648
653
  cases: tuning.length,
649
654
  trials: loop.trials,
650
- spendLeft: Number(left().toFixed(2)),
655
+ budgetLeft: Number(left().toFixed(2)),
651
656
  // The files a try may edit, relative to `code/{root}`: `allow` and not `deny`, and never
652
657
  // `alwaysDenied`'s.
653
658
  edit: {
@@ -662,10 +667,10 @@ export async function runLoop(request: LoopRequest, deps: LoopDeps): Promise<Loo
662
667
  await deps.waitForAllowance();
663
668
  deps.log(`try ${n}: proposing against try ${parent}`);
664
669
  const answer = await deps.propose({ tryDir, code, bundle, proposer: loop.proposer });
665
- ledger.proposed(answer.spend, answer.runId);
670
+ ledger.proposed(answer.estimate, answer.runId);
666
671
  if (!answer.hypothesis) {
667
672
  decide({
668
- decision: "failed",
673
+ outcome: "failed",
669
674
  why: answer.why ?? "the proposer gave no hypothesis",
670
675
  changed: [],
671
676
  });
@@ -676,8 +681,8 @@ export async function runLoop(request: LoopRequest, deps: LoopDeps): Promise<Loo
676
681
  proposal = {
677
682
  kind: PROPOSAL_KIND,
678
683
  hypothesis: answer.hypothesis,
679
- spend: answer.spend,
680
- feedback: fed.spend,
684
+ estimate: answer.estimate,
685
+ feedback: fed.estimate,
681
686
  ...(answer.runId ? { runId: answer.runId } : {}),
682
687
  };
683
688
  writeJson(proposalFile, proposal, "wx");
@@ -694,7 +699,7 @@ export async function runLoop(request: LoopRequest, deps: LoopDeps): Promise<Loo
694
699
  ...outsideGit(code, request.top),
695
700
  ];
696
701
  if (problems.length > 0) {
697
- decide({ decision: "refused", why: problems.join("; "), hypothesis, changed });
702
+ decide({ outcome: "refused", why: problems.join("; "), hypothesis, changed });
698
703
  return undefined;
699
704
  }
700
705
  if (left() <= 0) return capped(` by try ${n}'s proposer`);
@@ -703,41 +708,41 @@ export async function runLoop(request: LoopRequest, deps: LoopDeps): Promise<Loo
703
708
  folders: [columnOf(loop, dir, parent), columnOf(loop, dir, n)],
704
709
  order: loop.tuning,
705
710
  budget: left(),
706
- stopOnVerdict: true,
711
+ stopOnDecision: true,
707
712
  started: ledger.started,
708
713
  });
709
- if (ran.stopped === "budget") return capped(` during try ${n}'s run ${ran.runId}`);
714
+ if (ran.stopped === "budget") return capped(` during try ${n}'s run ${ran.labRun}`);
710
715
  if (ran.stopped === "precondition") return unready(ran, `try ${n}: its run`);
711
716
  if (ran.stopped === "stage") return misnamed(ran, `try ${n}: its run`);
712
- const verdict = ran.verdict && "verdict" in ran.verdict ? ran.verdict : undefined;
717
+ const decided = ran.decision && "decision" in ran.decision ? ran.decision : undefined;
713
718
  decide({
714
- decision: !verdict ? "failed" : verdict.verdict === "better" ? "kept" : "discarded",
715
- why: verdict
716
- ? `${verdict.verdict}${verdict.stop ? "" : ", not stopped"}: ${verdict.reason}${againstSpread(ran.runId)}`
717
- : ran.verdict && "error" in ran.verdict
718
- ? `the comparison failed: ${ran.verdict.error}`
719
+ outcome: !decided ? "failed" : decided.decision === "better" ? "kept" : "discarded",
720
+ why: decided
721
+ ? `${decided.decision}${decided.stop ? "" : ", not stopped"}: ${decided.reason}${againstSpread(ran.labRun)}`
722
+ : ran.decision && "error" in ran.decision
723
+ ? `the comparison failed: ${ran.decision.error}`
719
724
  : "no comparison: the dataset has no compare",
720
725
  hypothesis,
721
726
  changed,
722
- runId: ran.runId,
723
- verdict: verdict?.verdict ?? null,
727
+ labRun: ran.labRun,
728
+ decision: decided?.decision ?? null,
724
729
  });
725
730
  return undefined;
726
731
  };
727
732
  // A stall stops this command, not the loop: run it again, after a look, and it goes on.
728
733
  const before = tries.length;
729
- for (let round = 0; round < request.rounds; round++) {
734
+ for (let made = 0; made < request.tries; made++) {
730
735
  const stopped = await oneTry();
731
736
  if (stopped) return stopped;
732
737
  const recent = tries.slice(before).slice(-STALL);
733
- if (recent.length === STALL && recent.every((t) => t.decision !== "kept")) {
738
+ if (recent.length === STALL && recent.every((t) => t.outcome !== "kept")) {
734
739
  return {
735
740
  exit: 0,
736
741
  why: `${STALL} tries in a row kept nothing: look at them before running more; run the loop again to go on`,
737
742
  };
738
743
  }
739
744
  }
740
- return { exit: 0, why: `${request.rounds} round${request.rounds === 1 ? "" : "s"} run` };
745
+ return { exit: 0, why: `${request.tries} ${request.tries === 1 ? "try" : "tries"} made` };
741
746
  }
742
747
 
743
748
  /**
@@ -753,7 +758,7 @@ export async function runFinal(
753
758
  if (loop.holdout.length === 0) {
754
759
  throw new Refusal(`${loop.dataset} holds out no case: nothing for a final check`);
755
760
  }
756
- const kept = incumbentOf(readTries(request.dir));
761
+ const kept = bestSoFarOf(readTries(request.dir));
757
762
  if (kept === 0)
758
763
  return { exit: 1, why: `loop ${loop.name} kept nothing: there is nothing to check` };
759
764
  await checkGood(deps, loop.holdout, "held-out");
@@ -761,40 +766,40 @@ export async function runFinal(
761
766
  folders: [columnOf(loop, request.dir, 0), columnOf(loop, request.dir, kept)],
762
767
  order: loop.holdout,
763
768
  budget: request.budget,
764
- stopOnVerdict: false,
769
+ stopOnDecision: false,
765
770
  holdout: true,
766
771
  });
767
772
  // Not a check: nothing recorded, so the next is not counted as asked again.
768
773
  if (ran.stopped === "precondition") {
769
774
  return {
770
775
  exit: 3,
771
- why: `the final check's run ${ran.runId} stopped: ${PRECONDITION_STOP}: ${ran.precondition ?? "no trial says which"}; run it again once it holds`,
776
+ why: `the final check's run ${ran.labRun} stopped: ${PRECONDITION_STOP}: ${ran.precondition ?? "no trial says which"}; run it again once it holds`,
772
777
  };
773
778
  }
774
779
  if (ran.stopped === "stage") {
775
780
  return {
776
781
  exit: 3,
777
- why: `the final check's run ${ran.runId} stopped: ${ran.stage ?? "a stage the case named was never entered"}`,
782
+ why: `the final check's run ${ran.labRun} stopped: ${ran.stage ?? "a stage the case named was never entered"}`,
778
783
  };
779
784
  }
780
785
  const finals = join(request.dir, "finals");
781
786
  mkdirSync(finals, { recursive: true });
782
787
  const k = readFinals(request.dir).length + 1;
783
- const verdict = ran.verdict && "verdict" in ran.verdict ? ran.verdict : undefined;
784
- const why = verdict
785
- ? `${verdict.verdict}: ${verdict.reason}`
786
- : ran.verdict && "error" in ran.verdict
787
- ? `the comparison failed: ${ran.verdict.error}`
788
+ const decided = ran.decision && "decision" in ran.decision ? ran.decision : undefined;
789
+ const why = decided
790
+ ? `${decided.decision}: ${decided.reason}`
791
+ : ran.decision && "error" in ran.decision
792
+ ? `the comparison failed: ${ran.decision.error}`
788
793
  : "no comparison";
789
794
  const record: Final = {
790
795
  kind: FINAL_KIND,
791
796
  k,
792
797
  at: deps.now().toISOString(),
793
- incumbent: kept,
794
- runId: ran.runId,
795
- verdict: verdict?.verdict ?? null,
798
+ kept,
799
+ labRun: ran.labRun,
800
+ decision: decided?.decision ?? null,
796
801
  why,
797
- spend: ran.spend,
802
+ estimate: ran.estimate,
798
803
  };
799
804
  writeJson(join(finals, `${k}.json`), record, "wx");
800
805
  const again = k > 1 ? ` (checked ${k - 1} time${k > 2 ? "s" : ""} before)` : "";
@@ -804,26 +809,26 @@ export async function runFinal(
804
809
  };
805
810
  }
806
811
 
807
- type MeasuredSpread = Extract<Spread, { runId: string }>;
812
+ type MeasuredSpread = Extract<Spread, { labRun: string }>;
808
813
 
809
814
  /** The spread's record, from its run: the comparison of the start with itself. */
810
815
  function spreadOf(
811
816
  ran: TryRun,
812
817
  unsteady: Differed[],
813
- at: { at: string; trials: number; cases: number; spend: number },
818
+ at: { at: string; trials: number; cases: number; estimate: number },
814
819
  ): MeasuredSpread {
815
- const verdict = ran.verdict && "verdict" in ran.verdict ? ran.verdict : undefined;
816
- const primary = verdict?.metrics?.find((m) => m.role === "primary");
820
+ const decided = ran.decision && "decision" in ran.decision ? ran.decision : undefined;
821
+ const primary = decided?.metrics?.find((m) => m.role === "primary");
817
822
  return {
818
823
  kind: SPREAD_KIND,
819
824
  at: at.at,
820
- runId: ran.runId,
825
+ labRun: ran.labRun,
821
826
  trials: at.trials,
822
827
  cases: at.cases,
823
- verdict: verdict?.verdict ?? null,
828
+ decision: decided?.decision ?? null,
824
829
  ...(primary ? { primary: { name: primary.name, difference: primary.difference } } : {}),
825
830
  unsteady,
826
- spend: at.spend,
831
+ estimate: at.estimate,
827
832
  };
828
833
  }
829
834
 
@@ -832,7 +837,7 @@ function spreadLine(spread: MeasuredSpread): string {
832
837
  const { primary, unsteady } = spread;
833
838
  const by = primary
834
839
  ? `${primary.name} ${primary.difference === null ? "no difference" : `${primary.difference >= 0 ? "+" : ""}${primary.difference.toFixed(2)}`}`
835
- : (spread.verdict ?? "no comparison");
840
+ : (spread.decision ?? "no comparison");
836
841
  const names = unsteady.length > 0 ? ` (${unsteady.map((d) => d.case).join(", ")})` : "";
837
842
  return `the start twice: ${by}, ${unsteady.length} of ${spread.cases} cases differed${names}`;
838
843
  }
@@ -848,9 +853,9 @@ export function spreadWarningOf(dir: string): string | undefined {
848
853
 
849
854
  /** The warning when the comparison told the start from itself; a resume can't change trials. */
850
855
  function spreadWarning(spread: Spread | undefined, name: string): string | undefined {
851
- if (!spread || !("runId" in spread)) return undefined;
852
- if (spread.verdict !== "better" && spread.verdict !== "worse") return undefined;
853
- return `the comparison told the start from itself (${spread.verdict}): its verdicts are noise-prone at ${spread.trials} trial${spread.trials === 1 ? "" : "s"}; raise the entry's trials, and loop run ${name} --new starts another`;
856
+ if (!spread || !("labRun" in spread)) return undefined;
857
+ if (spread.decision !== "better" && spread.decision !== "worse") return undefined;
858
+ return `the comparison told the start from itself (${spread.decision}): its decisions are noise-prone at ${spread.trials} trial${spread.trials === 1 ? "" : "s"}; raise the entry's trials, and loop run ${name} --new starts another`;
854
859
  }
855
860
 
856
861
  /** Copies a boxed run's records into the store's, where `awf logs` finds them. */
package/src/lab/rates.ts CHANGED
@@ -125,15 +125,18 @@ const pct = (x: number) => `${Math.round(x * 100)}%`;
125
125
  const range = ([lo, hi]: Interval) => `${Math.round(lo * 100)}–${pct(hi)}`;
126
126
  const points = (x: number) => `${x > 0 ? "+" : x < 0 ? "−" : ""}${Math.abs(Math.round(x * 100))}`;
127
127
 
128
- /** `5/7 cases passed, 95% 36–92% · mean per case 81%, 95% 62–100% · pass^3 4/7 · pass@3 6/7`. */
128
+ /**
129
+ * `5/7 cases passed, 95% CI 36–92% · mean per case 81%, 95% CI 62–100% · pass^3 4/7 · pass@3 6/7`.
130
+ * The mean is left out when it is the share of cases passed, as when every case's trials agree.
131
+ */
129
132
  export function describeRates(rates: Rates): string {
130
133
  if (rates.cases === 0) return "no case graded";
131
134
  const parts = [
132
- `${rates.passed}/${rates.cases} cases passed${rates.interval ? `, 95% ${range(rates.interval)}` : ""}`,
135
+ `${rates.passed}/${rates.cases} cases passed${rates.interval ? `, 95% CI ${range(rates.interval)}` : ""}`,
133
136
  ];
134
- if (rates.mean) {
137
+ if (rates.mean && Math.abs(rates.mean.mean - rates.passed / rates.cases) > 1e-9) {
135
138
  parts.push(
136
- `mean per case ${pct(rates.mean.mean)}${rates.mean.interval ? `, 95% ${range(rates.mean.interval)}` : ""}`,
139
+ `mean per case ${pct(rates.mean.mean)}${rates.mean.interval ? `, 95% CI ${range(rates.mean.interval)}` : ""}`,
137
140
  );
138
141
  }
139
142
  if (rates.k !== undefined) {
@@ -143,8 +146,10 @@ export function describeRates(rates: Rates): string {
143
146
  return parts.join(" · ");
144
147
  }
145
148
 
146
- /** `−14 points, 95% −40 to +11: no difference shown`. */
149
+ /** `−14 points, 95% CI −40 to +11: no difference shown`. */
147
150
  export function describeDifference(d: NonNullable<ReturnType<typeof pairedDifference>>): string {
148
- const interval = d.interval ? `, 95% ${points(d.interval[0])} to ${points(d.interval[1])}` : "";
151
+ const interval = d.interval
152
+ ? `, 95% CI ${points(d.interval[0])} to ${points(d.interval[1])}`
153
+ : "";
149
154
  return `${points(d.mean)} points on ${plural(d.cases, "case")}${interval}${d.shown ? "" : ": no difference shown"}`;
150
155
  }
@@ -156,7 +156,7 @@ function reusedRuns(runDir: string): string[] {
156
156
  trialSlots(runDir).flatMap((slot) => {
157
157
  const pointer = join(runDir, slot, REUSED_FILE);
158
158
  return existsSync(pointer)
159
- ? [(JSON.parse(readFileSync(pointer, "utf8")) as TrialRef).run]
159
+ ? [(JSON.parse(readFileSync(pointer, "utf8")) as TrialRef).labRun]
160
160
  : [];
161
161
  }),
162
162
  ),
@@ -1,4 +1,4 @@
1
- import type { CaseReport } from "../format/output";
1
+ import type { LabReport } from "../format/output";
2
2
  import {
3
3
  type Context,
4
4
  chooseRun,
@@ -70,7 +70,7 @@ export async function report(context: Context, names: readonly string[]): Promis
70
70
  );
71
71
  }
72
72
  let graders: LabGrader[] | undefined;
73
- let stale: CaseReport["stale"];
73
+ let stale: LabReport["stale"];
74
74
  const trials = readTrials(workspace.store, run.id);
75
75
  if (info) {
76
76
  try {
@@ -93,7 +93,7 @@ export async function report(context: Context, names: readonly string[]): Promis
93
93
  ),
94
94
  ...(stale !== undefined ? { stale } : {}),
95
95
  });
96
- const { rows, others, verdicts, exit } = report;
96
+ const { rows, others, decisions, exit } = report;
97
97
  if (context.options.case) {
98
98
  const row = rows.find((r) => r.name === context.options.case);
99
99
  if (!row) {
@@ -126,12 +126,12 @@ export async function report(context: Context, names: readonly string[]): Promis
126
126
  run,
127
127
  row,
128
128
  trials: own,
129
- logsCommand: (trialId) => {
130
- const trial = own.find((t) => t.record.runId === trialId)?.record;
129
+ logsCommand: (trialId, shown) => {
130
+ const trial = own.find((t) => t.record.trialId === trialId)?.record;
131
131
  const bin = trial?.awf.bin ?? "awf";
132
132
  const folder =
133
133
  run.folders[run.columns[trial?.column ?? 0]?.folder ?? 0] ?? run.folders[0]!;
134
- return `(cd ${folder.path} && bun --no-env-file ${bin} logs ${trialId} --run-root ${runRoot})`;
134
+ return `(cd ${folder.path} && bun --no-env-file ${bin} logs ${shown} --run-root ${runRoot})`;
135
135
  },
136
136
  deciders: bars.get(row.name)?.deciders,
137
137
  others: others.map((column) => column.find((r) => r.name === row.name)),
@@ -146,7 +146,8 @@ export async function report(context: Context, names: readonly string[]): Promis
146
146
  others,
147
147
  trials,
148
148
  criteria: 0,
149
- ...(verdicts ? { verdicts } : {}),
149
+ decidersOf: (name) => bars.get(name)?.deciders,
150
+ ...(decisions ? { decisions } : {}),
150
151
  }),
151
152
  );
152
153
  } else if (context.options.json) {