@crowandraven/evalkeeper 0.17.1 → 0.19.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 (149) hide show
  1. package/dist/decisions.js +1 -1
  2. package/dist/decisions.js.map +1 -1
  3. package/dist/drafts.d.ts +2 -0
  4. package/dist/drafts.js +1 -1
  5. package/dist/drafts.js.map +1 -1
  6. package/dist/glossary.d.ts +25 -14
  7. package/dist/glossary.js +25 -14
  8. package/dist/glossary.js.map +1 -1
  9. package/dist/health.js +2 -2
  10. package/dist/health.js.map +1 -1
  11. package/dist/index.d.ts +3 -0
  12. package/dist/index.js +3 -0
  13. package/dist/index.js.map +1 -1
  14. package/dist/memoryStore.d.ts +2 -1
  15. package/dist/memoryStore.js +9 -0
  16. package/dist/memoryStore.js.map +1 -1
  17. package/dist/next/actions.js +58 -3
  18. package/dist/next/actions.js.map +1 -1
  19. package/dist/prisma/contracts.d.ts +5 -2
  20. package/dist/prisma/contracts.js +7 -1
  21. package/dist/prisma/contracts.js.map +1 -1
  22. package/dist/prisma/index.d.ts +40 -1
  23. package/dist/prisma/index.js +37 -1
  24. package/dist/prisma/index.js.map +1 -1
  25. package/dist/prune.d.ts +43 -10
  26. package/dist/prune.js +42 -13
  27. package/dist/prune.js.map +1 -1
  28. package/dist/react/AddCase.js +11 -5
  29. package/dist/react/AddCase.js.map +1 -1
  30. package/dist/react/AnswerKey.js +7 -4
  31. package/dist/react/AnswerKey.js.map +1 -1
  32. package/dist/react/CaseMenu.d.ts +2 -2
  33. package/dist/react/CaseMenu.js +10 -31
  34. package/dist/react/CaseMenu.js.map +1 -1
  35. package/dist/react/CompareView.js +3 -3
  36. package/dist/react/CompareView.js.map +1 -1
  37. package/dist/react/ConfirmAnswer.js +1 -1
  38. package/dist/react/ConfirmAnswer.js.map +1 -1
  39. package/dist/react/Drawer.d.ts +32 -0
  40. package/dist/react/Drawer.js +60 -0
  41. package/dist/react/Drawer.js.map +1 -0
  42. package/dist/react/HubSections.d.ts +34 -30
  43. package/dist/react/HubSections.js +104 -103
  44. package/dist/react/HubSections.js.map +1 -1
  45. package/dist/react/Menu.d.ts +37 -0
  46. package/dist/react/Menu.js +51 -0
  47. package/dist/react/Menu.js.map +1 -0
  48. package/dist/react/ModelMenu.d.ts +1 -1
  49. package/dist/react/ModelMenu.js +8 -32
  50. package/dist/react/ModelMenu.js.map +1 -1
  51. package/dist/react/RunView.js +24 -4
  52. package/dist/react/RunView.js.map +1 -1
  53. package/dist/react/Spending.d.ts +25 -0
  54. package/dist/react/Spending.js +51 -0
  55. package/dist/react/Spending.js.map +1 -0
  56. package/dist/react/SuiteSections.d.ts +27 -14
  57. package/dist/react/SuiteSections.js +227 -61
  58. package/dist/react/SuiteSections.js.map +1 -1
  59. package/dist/react/app.d.ts +18 -0
  60. package/dist/react/app.js.map +1 -1
  61. package/dist/react/format.d.ts +13 -0
  62. package/dist/react/format.js +13 -0
  63. package/dist/react/format.js.map +1 -1
  64. package/dist/react/index.d.ts +3 -0
  65. package/dist/react/index.js +3 -0
  66. package/dist/react/index.js.map +1 -1
  67. package/dist/react/pieces.d.ts +21 -8
  68. package/dist/react/pieces.js +44 -14
  69. package/dist/react/pieces.js.map +1 -1
  70. package/dist/runner.d.ts +18 -8
  71. package/dist/runner.js +148 -12
  72. package/dist/runner.js.map +1 -1
  73. package/dist/settings.d.ts +12 -0
  74. package/dist/settings.js +18 -0
  75. package/dist/settings.js.map +1 -1
  76. package/dist/spending.d.ts +100 -0
  77. package/dist/spending.js +133 -0
  78. package/dist/spending.js.map +1 -0
  79. package/dist/stats.d.ts +3 -1
  80. package/dist/stats.js +6 -2
  81. package/dist/stats.js.map +1 -1
  82. package/dist/store.d.ts +5 -0
  83. package/dist/suggest.js +17 -12
  84. package/dist/suggest.js.map +1 -1
  85. package/dist/suiteSettings.d.ts +78 -0
  86. package/dist/suiteSettings.js +142 -0
  87. package/dist/suiteSettings.js.map +1 -0
  88. package/dist/suites/crisisRisk.js +3 -3
  89. package/dist/suites/crisisRisk.js.map +1 -1
  90. package/dist/suites/hopelessness.js +6 -6
  91. package/dist/suites/hopelessness.js.map +1 -1
  92. package/dist/suites/injection.js +2 -2
  93. package/dist/suites/injection.js.map +1 -1
  94. package/dist/summary.d.ts +41 -4
  95. package/dist/summary.js +46 -8
  96. package/dist/summary.js.map +1 -1
  97. package/dist/testing.d.ts +19 -0
  98. package/dist/testing.js +61 -0
  99. package/dist/testing.js.map +1 -1
  100. package/dist/todo.d.ts +146 -0
  101. package/dist/todo.js +198 -0
  102. package/dist/todo.js.map +1 -0
  103. package/dist/types.d.ts +46 -7
  104. package/dist/types.js +28 -4
  105. package/dist/types.js.map +1 -1
  106. package/package.json +1 -1
  107. package/schema/evalkeeper.prisma +13 -0
  108. package/src/decisions.ts +1 -1
  109. package/src/drafts.ts +3 -1
  110. package/src/glossary.ts +35 -14
  111. package/src/health.ts +3 -2
  112. package/src/index.ts +3 -0
  113. package/src/memoryStore.ts +15 -1
  114. package/src/next/actions.ts +67 -2
  115. package/src/prisma/contracts.ts +16 -1
  116. package/src/prisma/index.ts +68 -1
  117. package/src/prune.ts +71 -14
  118. package/src/react/AddCase.tsx +13 -11
  119. package/src/react/AnswerKey.tsx +17 -5
  120. package/src/react/CaseMenu.tsx +23 -77
  121. package/src/react/CompareView.tsx +4 -10
  122. package/src/react/ConfirmAnswer.tsx +1 -1
  123. package/src/react/Drawer.tsx +130 -0
  124. package/src/react/HubSections.tsx +180 -414
  125. package/src/react/Menu.tsx +155 -0
  126. package/src/react/ModelMenu.tsx +23 -74
  127. package/src/react/RunView.tsx +46 -3
  128. package/src/react/Spending.tsx +200 -0
  129. package/src/react/SuiteSections.tsx +591 -148
  130. package/src/react/app.ts +18 -0
  131. package/src/react/format.ts +15 -0
  132. package/src/react/index.ts +3 -0
  133. package/src/react/pieces.tsx +57 -18
  134. package/src/runner.ts +199 -13
  135. package/src/settings.ts +20 -0
  136. package/src/spending.ts +209 -0
  137. package/src/stats.ts +8 -2
  138. package/src/store.ts +5 -0
  139. package/src/suggest.ts +21 -14
  140. package/src/suiteSettings.ts +201 -0
  141. package/src/suites/crisisRisk.ts +3 -3
  142. package/src/suites/hopelessness.ts +6 -6
  143. package/src/suites/injection.ts +2 -2
  144. package/src/summary.ts +59 -8
  145. package/src/testing.ts +77 -0
  146. package/src/todo.ts +318 -0
  147. package/src/types.ts +63 -9
  148. package/starter/index.ts +7 -0
  149. package/templates/lib/evalkeeper/actions.ts +20 -0
package/src/react/app.ts CHANGED
@@ -8,6 +8,7 @@ import type { BoardRow } from "../board.js";
8
8
  import type { VersionedSettings } from "../settings.js";
9
9
  import type { AnswerEditorProps, AnySuite } from "../types.js";
10
10
  import { weeklySummary, type WeeklySummary } from "../weekly.js";
11
+ import type { EvalSpending } from "../spending.js";
11
12
 
12
13
  /** A form action: a server action the screens' forms submit to. */
13
14
  export type FormAction = (form: FormData) => Promise<void>;
@@ -45,6 +46,16 @@ export type EvalActions = {
45
46
  setPriority?: FormAction;
46
47
  /** Keeping a split case's answer as right, after checking it. */
47
48
  keepAnswer?: FormAction;
49
+ /** Retiring starter cases a starter update replaced. */
50
+ retireReplacedStarters?: FormAction;
51
+ /** Saving a suite's settings (its target number of cases). */
52
+ saveSuiteSettings?: FormAction;
53
+ /** Saving the daily spending limits; needs your app's `spending`. */
54
+ saveLimits?: FormAction;
55
+ /** Stopping every test now; needs your app's `spending.stopAll`. */
56
+ stopTests?: FormAction;
57
+ /** Lifting a stop early; needs your app's `spending.allow`. */
58
+ allowTests?: FormAction;
48
59
  runWeeklyNow: () => Promise<void>;
49
60
  /** Blind rating; only for an app with the rate page. */
50
61
  rateBlind?: FormAction;
@@ -84,6 +95,13 @@ export type EvalApp = {
84
95
  * description when there is one. Leave it out to skip that list.
85
96
  */
86
97
  features?: { operation: string; label: string; description?: string }[];
98
+ /**
99
+ * What eval tests spent against your daily limits, and the stop. Your
100
+ * app keeps the numbers and enforces the limits; the pages show them
101
+ * (in the page menu, or in a warning when tests are over a limit,
102
+ * stopped, or running) and save the limits. Leave it out to show none.
103
+ */
104
+ spending?: EvalSpending;
87
105
  };
88
106
 
89
107
  /** An `EvalApp` with its suites by key, as the screens read it. */
@@ -45,3 +45,18 @@ export const momentOf = (d: Date, timeZone?: string): string =>
45
45
  * styled as buttons, card titles, and the back link have their own look.
46
46
  */
47
47
  export const LINK = "text-accent hover:underline";
48
+
49
+ /**
50
+ * A tinted background with readable text, from the app's color names
51
+ * (`--color-good`, `--color-warn`, `--color-bad`), so the app's
52
+ * evalkeeper.css decides both themes: no fixed palette colors and no
53
+ * `dark:` variants, which follow the system rather than the app.
54
+ */
55
+ export const TINT = {
56
+ good: "bg-good/15 text-[color-mix(in_srgb,var(--color-good)_55%,var(--color-ink))]",
57
+ warn: "bg-warn/15 text-[color-mix(in_srgb,var(--color-warn)_55%,var(--color-ink))]",
58
+ bad: "bg-bad/10 text-[color-mix(in_srgb,var(--color-bad)_60%,var(--color-ink))]",
59
+ } as const;
60
+
61
+ /** A warning panel's tint: the warn color, faint, behind ink text. */
62
+ export const WARN_PANEL = "bg-warn/10 border border-warn/40";
@@ -28,4 +28,7 @@ export * from "./SideBySideView.js";
28
28
  export * from "./RateView.js";
29
29
  export * from "./FeedbackView.js";
30
30
  export * from "./ModelMenu.js";
31
+ export * from "./Menu.js";
32
+ export * from "./Drawer.js";
33
+ export * from "./Spending.js";
31
34
  export * from "./Tabs.js";
@@ -17,7 +17,9 @@ import {
17
17
  type HealthStanding,
18
18
  type HealthStatus,
19
19
  } from "../health.js";
20
- import { dayOf, momentOf, pct, QUIET_BUTTON } from "./format.js";
20
+ import { dayOf, momentOf, pct, QUIET_BUTTON, TINT } from "./format.js";
21
+ import { SUITE_STATUS_LABEL, type SuiteStatus } from "../todo.js";
22
+ import { SEVERITY_LABEL, type CheckDef } from "../types.js";
21
23
 
22
24
  /**
23
25
  * The pieces Evalkeeper's screens are built from. Each draws Evalkeeper's
@@ -27,12 +29,14 @@ import { dayOf, momentOf, pct, QUIET_BUTTON } from "./format.js";
27
29
  * client components).
28
30
  */
29
31
 
32
+ // Every tone from the app's color names, so its evalkeeper.css decides
33
+ // both themes.
30
34
  const CHIP = {
31
- live: "bg-emerald-100 text-emerald-800 dark:bg-emerald-500/15 dark:text-emerald-300",
32
- fallback: "bg-sky-100 text-sky-800 dark:bg-sky-500/15 dark:text-sky-200",
35
+ live: TINT.good,
36
+ fallback: "bg-ink/10 text-ink",
33
37
  suggested: "bg-accent/10 text-accent",
34
- warn: "bg-amber-100 text-amber-800 dark:bg-amber-500/15 dark:text-amber-200",
35
- serious: "bg-red-50 text-red-800 dark:bg-red-500/10 dark:text-red-200",
38
+ warn: TINT.warn,
39
+ serious: TINT.bad,
36
40
  neutral: "bg-tint text-muted",
37
41
  } as const;
38
42
 
@@ -191,7 +195,7 @@ export function Card(props: CardProps) {
191
195
  );
192
196
  }
193
197
 
194
- /** A small rounded label: Live, Fallback, Retires …, serious, minor. */
198
+ /** A small rounded label: Live, Fallback, Retires …, Must pass. */
195
199
  export function Chip(props: ChipProps) {
196
200
  const C = useSwapped("Chip");
197
201
  if (C) return createElement(C, props);
@@ -234,13 +238,18 @@ function flagChips(f: HealthFlag): { text: string; tone: ChipTone }[] {
234
238
  ...(f.serious
235
239
  ? [
236
240
  {
237
- text: `${f.serious} serious under bar`,
241
+ text: `${f.serious} must-pass ${f.serious === 1 ? "check" : "checks"} under ${f.serious === 1 ? "its" : "their"} aim`,
238
242
  tone: "serious" as const,
239
243
  },
240
244
  ]
241
245
  : []),
242
246
  ...(f.minor
243
- ? [{ text: `${f.minor} minor under bar`, tone: "warn" as const }]
247
+ ? [
248
+ {
249
+ text: `${f.minor} nice-to-have ${f.minor === 1 ? "check" : "checks"} under ${f.minor === 1 ? "its" : "their"} aim`,
250
+ tone: "warn" as const,
251
+ },
252
+ ]
244
253
  : []),
245
254
  ];
246
255
  case "suggestLive":
@@ -278,9 +287,42 @@ export function StandingBadge({ standing }: { standing: HealthStanding }) {
278
287
  return <Chip tone={STANDING_TONE[standing]}>{STANDING_LABEL[standing]}</Chip>;
279
288
  }
280
289
 
290
+ const SUITE_STATUS_TONE: Record<SuiteStatus, ChipTone> = {
291
+ attention: "warn",
292
+ unknown: "neutral",
293
+ healthy: "live",
294
+ };
295
+
296
+ /**
297
+ * A suite's status on the hub and its page: Needs attention (amber), Can't
298
+ * tell yet (gray), or Healthy (green). Each color means only that.
299
+ */
300
+ export function SuiteStatusBadge({ status }: { status: SuiteStatus }) {
301
+ return (
302
+ <Chip tone={SUITE_STATUS_TONE[status]}>{SUITE_STATUS_LABEL[status]}</Chip>
303
+ );
304
+ }
305
+
306
+ /** A check's severity as the pages say it: Must pass, or Nice to have. */
307
+ export function SeverityChip({ severity }: { severity: CheckDef["severity"] }) {
308
+ return (
309
+ <Chip
310
+ tone={
311
+ severity === "serious"
312
+ ? "serious"
313
+ : severity === "moderate"
314
+ ? "warn"
315
+ : "neutral"
316
+ }
317
+ >
318
+ {SEVERITY_LABEL[severity]}
319
+ </Chip>
320
+ );
321
+ }
322
+
281
323
  /**
282
- * The reasons behind a suite's standing as one plain line ("1 serious
283
- * under bar · New fallback suggested"), for under its name. Provisional
324
+ * The reasons behind a suite's standing as one plain line ("1 must-pass
325
+ * check under its aim · New fallback suggested"), for under its name. Provisional
284
326
  * answers are left out: a choice, not a problem, so the card says it in a
285
327
  * footnote instead.
286
328
  */
@@ -289,8 +331,9 @@ export function HealthReasons({ flags }: { flags: readonly HealthFlag[] }) {
289
331
  .filter((f) => f.kind !== "provisional" && f.kind !== "good")
290
332
  .flatMap(flagChips);
291
333
  if (!reasons.length) return null;
292
- // Each in its standing's color with an icon, so it reads at a glance
293
- // without another row of chips.
334
+ // Each in its standing's color, urgent ones with an alert icon, so it
335
+ // reads at a glance without another row of chips. The others get no
336
+ // icon: an (i) is only ever a tip you can open.
294
337
  return (
295
338
  <ul className="flex flex-wrap gap-x-4 gap-y-1 text-sm font-medium">
296
339
  {reasons.map((r) => {
@@ -306,11 +349,7 @@ export function HealthReasons({ flags }: { flags: readonly HealthFlag[] }) {
306
349
  : "text-ink"
307
350
  }`}
308
351
  >
309
- {urgent ? (
310
- <CircleAlert aria-hidden className="h-4 w-4 shrink-0" />
311
- ) : (
312
- <Info aria-hidden className="h-4 w-4 shrink-0 text-muted" />
313
- )}
352
+ {urgent && <CircleAlert aria-hidden className="h-4 w-4 shrink-0" />}
314
353
  {r.text}
315
354
  </li>
316
355
  );
@@ -320,7 +359,7 @@ export function HealthReasons({ flags }: { flags: readonly HealthFlag[] }) {
320
359
  }
321
360
 
322
361
  /**
323
- * A suite's health as chips naming each reason ("2 serious under bar",
362
+ * A suite's health as chips naming each reason ("2 must-pass checks under their aim",
324
363
  * "New fallback suggested", "Add cases (33 of 50)"), so a card says why at
325
364
  * a glance; its details say more.
326
365
  */
package/src/runner.ts CHANGED
@@ -16,7 +16,13 @@ import {
16
16
  import type { BoardRow } from "./board.js";
17
17
  import { allPassed } from "./stats.js";
18
18
  import { pickQuickSet } from "./quickSet.js";
19
- import { answerKeyHealth } from "./prune.js";
19
+ import {
20
+ EASY_FLOOR_CASES,
21
+ EASY_MIN_MODELS,
22
+ answerKeyHealth,
23
+ withRounds,
24
+ type CaseResult,
25
+ } from "./prune.js";
20
26
  import { stableJson } from "./stableJson.js";
21
27
  import { suiteMetrics, type ScoredOutput } from "./stats.js";
22
28
  import type {
@@ -42,6 +48,14 @@ export { confirmedLabel, isProvisional };
42
48
  import { injectionSuitesOf, type AnySuite, type CheckResult } from "./types.js";
43
49
  import { injectionCases } from "./suites/injection.js";
44
50
  import { at } from "./util.js";
51
+ import { targetCasesOf } from "./summary.js";
52
+ import {
53
+ NO_SUITE_SETTINGS,
54
+ effectiveChecks,
55
+ levelsOf,
56
+ type SuiteSettings,
57
+ type SuiteSettingsStore,
58
+ } from "./suiteSettings.js";
45
59
  import { mustGet } from "./util.js";
46
60
 
47
61
  /**
@@ -130,6 +144,13 @@ export type RunnerOptions = {
130
144
  * fallback model, so nobody spends a test on a model that's going away.
131
145
  */
132
146
  retiringOnBoard?: "always" | "inUse";
147
+ /**
148
+ * Where settings a person adjusts on a suite's page are kept (its target
149
+ * number of cases). `memoryStore` and `prismaSuiteSettingsStore` are
150
+ * ones. Without it, every suite uses its values in code, and the page
151
+ * offers no Suite settings.
152
+ */
153
+ suiteSettings?: SuiteSettingsStore;
133
154
  };
134
155
 
135
156
  /**
@@ -520,7 +541,10 @@ export function createRunner(opts: RunnerOptions) {
520
541
  label: parsed?.success ? parsed.data : null,
521
542
  };
522
543
  });
523
- const extra = suite.gradeTogether(answers);
544
+ // Marked, so the case is known to matter to others (never easy).
545
+ const extra = suite
546
+ .gradeTogether(answers)
547
+ .map((cs) => cs.map((c) => ({ ...c, together: true })));
524
548
  await mapLimit(
525
549
  group.map((o, i) => ({ o, add: extra[i] ?? [] })),
526
550
  6,
@@ -540,8 +564,22 @@ export function createRunner(opts: RunnerOptions) {
540
564
  /** Only these cases' answers count; all when absent. */
541
565
  caseIds?: ReadonlySet<string>,
542
566
  ): Promise<RunMetrics> {
543
- const outputs = (await store.listOutputs(run.id)).filter(
544
- (o) => !caseIds || caseIds.has(o.caseId),
567
+ const levels = levelsOf(suite.checks);
568
+ // Each result keeps the level it was graded at, so a nice-to-have miss
569
+ // never fails an answer wherever the answer is read.
570
+ const outputs = await Promise.all(
571
+ (await store.listOutputs(run.id))
572
+ .filter((o) => !caseIds || caseIds.has(o.caseId))
573
+ .map(async (o) => {
574
+ if (!o.scores) return o;
575
+ const stamped = o.scores.map((c) => {
576
+ const level = levels[c.key];
577
+ return level ? { ...c, level } : c;
578
+ });
579
+ if (stamped.some((c, i) => c.level !== o.scores?.[i]?.level))
580
+ await store.setOutputScores(o.id, stamped);
581
+ return { ...o, scores: stamped };
582
+ }),
545
583
  );
546
584
  const scored: ScoredOutput[] = outputs.map((o) => ({
547
585
  caseId: o.caseId,
@@ -558,6 +596,7 @@ export function createRunner(opts: RunnerOptions) {
558
596
  ),
559
597
  judgeCostUsd,
560
598
  failureReason: commonError(outputs.map((o) => o.error)),
599
+ levels,
561
600
  };
562
601
  }
563
602
 
@@ -572,7 +611,7 @@ export function createRunner(opts: RunnerOptions) {
572
611
  if (!run || run.status !== "RUNNING") return;
573
612
  const leg = o.leg ?? 1;
574
613
  try {
575
- const suite = suiteOrThrow(run.suite);
614
+ const suite = await effectiveSuite(run.suite);
576
615
  const cases = await casesFor(suite.key, run.set);
577
616
  const since = new Date(Date.now() - REUSE_DAYS * 86_400_000);
578
617
  const jobs = cases.flatMap((c) =>
@@ -724,7 +763,7 @@ export function createRunner(opts: RunnerOptions) {
724
763
  async function rescoreRun(runId: string) {
725
764
  const run = await store.getRun(runId);
726
765
  if (!run) return;
727
- const suite = suiteOrThrow(run.suite);
766
+ const suite = await effectiveSuite(run.suite);
728
767
  const cases = new Map(
729
768
  (await store.listCases(suite.key)).map((c) => [c.id, c]),
730
769
  );
@@ -792,11 +831,127 @@ export function createRunner(opts: RunnerOptions) {
792
831
  * the tags spread, from the board's current tests.
793
832
  */
794
833
  async function answerKeyHealthOf(suiteKey: string, today = new Date()) {
795
- const [b, cases] = await Promise.all([
834
+ const [b, cases, target] = await Promise.all([
796
835
  board(suiteKey),
797
836
  store.listCases(suiteKey),
837
+ targetCases(suiteKey),
798
838
  ]);
799
- return answerKeyHealth(cases, b.caseResults, today);
839
+ const rounds = await easyRounds(suiteKey, cases, target);
840
+ return answerKeyHealth(
841
+ cases,
842
+ withRounds(b.caseResults, rounds),
843
+ today,
844
+ null,
845
+ target,
846
+ );
847
+ }
848
+
849
+ /**
850
+ * A suite's saved settings (its target number of cases), or none saved
851
+ * when there's no `suiteSettings` store or it can't be read: a page
852
+ * still loads, on the suite's values in code.
853
+ */
854
+ async function suiteSettingsOf(suiteKey: string): Promise<SuiteSettings> {
855
+ if (!opts.suiteSettings) return NO_SUITE_SETTINGS;
856
+ try {
857
+ return await opts.suiteSettings.getSuiteSettings(suiteKey);
858
+ } catch {
859
+ return NO_SUITE_SETTINGS;
860
+ }
861
+ }
862
+
863
+ /**
864
+ * A suite's target number of cases: saved in its settings, else its
865
+ * `targetCases`, else TARGET_CASES. It sets the floor for retiring easy
866
+ * cases, how many drafts to ask for, and when the page asks for more.
867
+ */
868
+ async function targetCases(suiteKey: string): Promise<number> {
869
+ return targetCasesOf(
870
+ suiteOrThrow(suiteKey),
871
+ await suiteSettingsOf(suiteKey),
872
+ );
873
+ }
874
+
875
+ /**
876
+ * A suite with a person's levels and aims (Suite settings) in place of
877
+ * its checks' own: what grading, the board, and the pages use.
878
+ */
879
+ async function effectiveSuite(suiteKey: string): Promise<AnySuite> {
880
+ const suite = suiteOrThrow(suiteKey);
881
+ if (!opts.suiteSettings) return suite;
882
+ const saved = await suiteSettingsOf(suite.key);
883
+ return { ...suite, checks: effectiveChecks(suite.checks, saved) };
884
+ }
885
+
886
+ /**
887
+ * Saves a suite's settings, as a person changed them on its page.
888
+ * Throws without a `suiteSettings` store.
889
+ */
890
+ async function saveSuiteSettings(
891
+ suiteKey: string,
892
+ settings: SuiteSettings,
893
+ by: string | null,
894
+ ): Promise<void> {
895
+ if (!opts.suiteSettings)
896
+ throw new Error(
897
+ "Suite settings need a place to keep them: pass suiteSettings to createRunner.",
898
+ );
899
+ await opts.suiteSettings.saveSuiteSettings(
900
+ suiteOrThrow(suiteKey).key,
901
+ settings,
902
+ by,
903
+ );
904
+ }
905
+
906
+ /**
907
+ * Per case, the rounds of testing it passed (EASY_MIN_ROUNDS): days on
908
+ * which at least EASY_MIN_MODELS models were tested on it and every one
909
+ * got it fully right (all repeats), counted only after its answer last
910
+ * changed. Empty when the suite has its floor of cases in use or fewer
911
+ * (its target number of cases, EASY_FLOOR_CASES by default): nothing can
912
+ * be retired then, so the history isn't read.
913
+ */
914
+ async function easyRounds(
915
+ suiteKey: string,
916
+ cases?: readonly CaseRecord[],
917
+ floor: number = EASY_FLOOR_CASES,
918
+ ): Promise<Record<string, number>> {
919
+ const all = cases ?? (await store.listCases(suiteKey));
920
+ const inUse = all.filter(
921
+ (c) => c.status !== "RETIRED" && confirmedLabel(c.labels),
922
+ );
923
+ if (inUse.length <= floor) return {};
924
+ const since = new Map(
925
+ inUse.map((c) => {
926
+ const l = confirmedLabel(c.labels);
927
+ return [c.id, Math.max(+c.updatedAt, l ? +l.updatedAt : 0)];
928
+ }),
929
+ );
930
+ const runs = (await store.listRuns(suiteKey, { status: "SUCCEEDED" })).map(
931
+ (r) => ({ ...r, day: r.startedAt.toISOString().slice(0, 10) }),
932
+ );
933
+ const outputs = await outputsByRun(runs.map((r) => r.id));
934
+ // case → day → model → right on every answer that day
935
+ const seen = new Map<string, Map<string, Map<string, boolean>>>();
936
+ for (const r of runs) {
937
+ for (const o of outputs.get(r.id) ?? []) {
938
+ const after = since.get(o.caseId);
939
+ if (after === undefined || +r.startedAt <= after) continue;
940
+ const days =
941
+ seen.get(o.caseId) ?? new Map<string, Map<string, boolean>>();
942
+ const models = days.get(r.day) ?? new Map<string, boolean>();
943
+ const right = !o.error && allPassed(o.scores ?? []);
944
+ models.set(r.model, (models.get(r.model) ?? true) && right);
945
+ days.set(r.day, models);
946
+ seen.set(o.caseId, days);
947
+ }
948
+ }
949
+ const rounds: Record<string, number> = {};
950
+ for (const [caseId, days] of seen)
951
+ rounds[caseId] = [...days.values()].filter(
952
+ (m) => m.size >= EASY_MIN_MODELS && [...m.values()].every(Boolean),
953
+ ).length;
954
+ return rounds;
800
955
  }
801
956
 
802
957
  /**
@@ -805,6 +960,9 @@ export function createRunner(opts: RunnerOptions) {
805
960
  * Returns how many it retired.
806
961
  */
807
962
  async function retireEasy(suiteKey: string): Promise<number> {
963
+ // Regraded first, so every compared case is marked as such (tests
964
+ // graded before the mark existed have none).
965
+ if (suiteOrThrow(suiteKey).gradeTogether) await rescoreRecent(suiteKey);
808
966
  const { easyToRetire } = await answerKeyHealthOf(suiteKey);
809
967
  for (const c of easyToRetire) await store.setCaseStatus(c.id, "RETIRED");
810
968
  if (easyToRetire.length) await rescoreRecent(suiteKey);
@@ -930,7 +1088,7 @@ export function createRunner(opts: RunnerOptions) {
930
1088
  * the two answers side by side.
931
1089
  */
932
1090
  async function compare(suiteKey: string, a: string, b: string) {
933
- const suite = suiteOrThrow(suiteKey);
1091
+ const suite = await effectiveSuite(suiteKey);
934
1092
  const [ra, rb] = await Promise.all([store.getRun(a), store.getRun(b)]);
935
1093
  if (
936
1094
  !ra ||
@@ -1013,7 +1171,12 @@ export function createRunner(opts: RunnerOptions) {
1013
1171
  async function board(suiteKey: string) {
1014
1172
  if (!opts.route || !opts.candidates)
1015
1173
  throw new Error("The board needs the route and candidates options");
1016
- const suite = suiteOrThrow(suiteKey);
1174
+ // With a person's levels and aims, so every page reads the same checks.
1175
+ const suite = await effectiveSuite(suiteKey);
1176
+ const levels = levelsOf(suite.checks);
1177
+ const sameLevels = (r: RunRecord) =>
1178
+ !r.metrics?.levels ||
1179
+ Object.entries(levels).every(([k, l]) => r.metrics?.levels?.[k] === l);
1017
1180
  const [route, cases, prompt] = await Promise.all([
1018
1181
  opts.route(suite.operation),
1019
1182
  casesFor(suite.key, "ALL"),
@@ -1049,7 +1212,10 @@ export function createRunner(opts: RunnerOptions) {
1049
1212
  const liveCap = route.maxOutputTokens ?? null;
1050
1213
  // A test at another temperature or output cap than the live ones
1051
1214
  // answered differently.
1215
+ // Tests graded at other levels need a rescore (free); tests from
1216
+ // before levels were kept count as current.
1052
1217
  const isCurrent = (r: RunRecord) =>
1218
+ sameLevels(r) &&
1053
1219
  r.datasetVersion === current &&
1054
1220
  r.promptVersion === prompt &&
1055
1221
  (r.temperature ?? null) === liveTemperature &&
@@ -1219,14 +1385,27 @@ export function createRunner(opts: RunnerOptions) {
1219
1385
  a.label.localeCompare(b.label),
1220
1386
  );
1221
1387
  // How each case fared across current, complete tests: easy and split cases.
1222
- const caseResults: Record<string, { passed: number; models: number }> = {};
1388
+ const caseResults: Record<string, CaseResult> = {};
1223
1389
  for (const row of rows) {
1224
1390
  if (row.variant || !row.test || row.test.stale || row.test.failedAnswers)
1225
1391
  continue;
1392
+ // Each model once per case: right only if every repeat was right.
1393
+ const byCase = new Map<string, { right: boolean; ranked: boolean }>();
1226
1394
  for (const x of outputsOf(row.test.runId)) {
1227
- const c = (caseResults[x.caseId] ??= { passed: 0, models: 0 });
1395
+ const had = byCase.get(x.caseId) ?? { right: true, ranked: false };
1396
+ byCase.set(x.caseId, {
1397
+ right: had.right && allPassed(x.checks),
1398
+ // Compared with other cases (a ranking): others' results need it.
1399
+ ranked:
1400
+ had.ranked ||
1401
+ Boolean(x.checks?.some((k) => k.together && k.pass !== null)),
1402
+ });
1403
+ }
1404
+ for (const [caseId, r] of byCase) {
1405
+ const c = (caseResults[caseId] ??= { passed: 0, models: 0 });
1228
1406
  c.models++;
1229
- if (allPassed(x.checks)) c.passed++;
1407
+ if (r.right) c.passed++;
1408
+ if (r.ranked) c.ranked = true;
1230
1409
  }
1231
1410
  }
1232
1411
  return {
@@ -1352,6 +1531,13 @@ export function createRunner(opts: RunnerOptions) {
1352
1531
  rescoreRecent,
1353
1532
  answerKeyHealth: answerKeyHealthOf,
1354
1533
  retireEasy,
1534
+ easyRounds,
1535
+ targetCases,
1536
+ effectiveSuite,
1537
+ suiteSettings: suiteSettingsOf,
1538
+ saveSuiteSettings,
1539
+ /** Whether suite settings can be saved (a `suiteSettings` store). */
1540
+ canSaveSuiteSettings: opts.suiteSettings !== undefined,
1355
1541
  retireStaleDrafts,
1356
1542
  stopStuckRuns,
1357
1543
  compare,
package/src/settings.ts CHANGED
@@ -197,6 +197,26 @@ export class SettingsConflict extends Error {
197
197
  }
198
198
  }
199
199
 
200
+ /**
201
+ * A feature's live settings, or null when it has none yet (no version,
202
+ * and no default in code). Use it where one feature with no settings must
203
+ * not break a page that shows many.
204
+ *
205
+ * @param settings - Your versioned settings (`createSettings`).
206
+ * @param operation - The feature.
207
+ */
208
+ export async function currentSettings(
209
+ settings: Pick<VersionedSettings, "current">,
210
+ operation: string,
211
+ ): Promise<{ settings: Settings; version: SettingsVersion | null } | null> {
212
+ try {
213
+ return await settings.current(operation);
214
+ } catch (e) {
215
+ if (e instanceof NoSettingsError) return null;
216
+ throw e;
217
+ }
218
+ }
219
+
200
220
  /**
201
221
  * A feature has no settings: no version yet, and no default in code. Apps
202
222
  * whose models are chosen in an admin page, not in code, see this until