@crowandraven/evalkeeper 0.5.0 → 0.8.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/README.md +16 -0
  2. package/dist/activity.d.ts +58 -0
  3. package/dist/activity.js +125 -0
  4. package/dist/activity.js.map +1 -0
  5. package/dist/assertExpect.d.ts +52 -0
  6. package/dist/assertExpect.js +104 -0
  7. package/dist/assertExpect.js.map +1 -0
  8. package/dist/blind.d.ts +79 -0
  9. package/dist/blind.js +113 -0
  10. package/dist/blind.js.map +1 -0
  11. package/dist/cli/addPages.d.ts +6 -1
  12. package/dist/cli/addPages.js +19 -4
  13. package/dist/cli/addPages.js.map +1 -1
  14. package/dist/cli/main.d.ts +1 -1
  15. package/dist/cli/main.js +4 -3
  16. package/dist/cli/main.js.map +1 -1
  17. package/dist/compare.d.ts +38 -0
  18. package/dist/compare.js +62 -0
  19. package/dist/compare.js.map +1 -1
  20. package/dist/decisions.js +8 -0
  21. package/dist/decisions.js.map +1 -1
  22. package/dist/feedback.d.ts +17 -2
  23. package/dist/feedback.js +13 -2
  24. package/dist/feedback.js.map +1 -1
  25. package/dist/glossary.d.ts +22 -0
  26. package/dist/glossary.js +22 -0
  27. package/dist/glossary.js.map +1 -1
  28. package/dist/health.js +5 -3
  29. package/dist/health.js.map +1 -1
  30. package/dist/importCases.d.ts +76 -5
  31. package/dist/importCases.js +114 -14
  32. package/dist/importCases.js.map +1 -1
  33. package/dist/inInstructions.d.ts +47 -0
  34. package/dist/inInstructions.js +95 -0
  35. package/dist/inInstructions.js.map +1 -0
  36. package/dist/index.d.ts +5 -0
  37. package/dist/index.js +5 -0
  38. package/dist/index.js.map +1 -1
  39. package/dist/memoryStore.js +3 -1
  40. package/dist/memoryStore.js.map +1 -1
  41. package/dist/readCheck.d.ts +116 -0
  42. package/dist/readCheck.js +321 -0
  43. package/dist/readCheck.js.map +1 -0
  44. package/dist/runner.d.ts +16 -0
  45. package/dist/runner.js +51 -3
  46. package/dist/runner.js.map +1 -1
  47. package/dist/settings.d.ts +81 -3
  48. package/dist/settings.js +160 -23
  49. package/dist/settings.js.map +1 -1
  50. package/dist/store.d.ts +10 -3
  51. package/dist/suggest.d.ts +10 -1
  52. package/dist/suggest.js +22 -4
  53. package/dist/suggest.js.map +1 -1
  54. package/dist/suiteContract.d.ts +23 -0
  55. package/dist/suiteContract.js +106 -0
  56. package/dist/suiteContract.js.map +1 -0
  57. package/dist/suites/crisisRisk.d.ts +83 -0
  58. package/dist/suites/crisisRisk.js +176 -0
  59. package/dist/suites/crisisRisk.js.map +1 -0
  60. package/dist/suites/crisisRiskCases.d.ts +40 -0
  61. package/dist/suites/crisisRiskCases.js +179 -0
  62. package/dist/suites/crisisRiskCases.js.map +1 -0
  63. package/dist/suites/hopelessness.d.ts +116 -0
  64. package/dist/suites/hopelessness.js +293 -0
  65. package/dist/suites/hopelessness.js.map +1 -0
  66. package/dist/suites/hopelessnessCases.d.ts +61 -0
  67. package/dist/suites/hopelessnessCases.js +242 -0
  68. package/dist/suites/hopelessnessCases.js.map +1 -0
  69. package/dist/suites/index.d.ts +11 -0
  70. package/dist/suites/index.js +12 -0
  71. package/dist/suites/index.js.map +1 -0
  72. package/dist/testing.d.ts +162 -12
  73. package/dist/testing.js +479 -115
  74. package/dist/testing.js.map +1 -1
  75. package/dist/types.d.ts +98 -0
  76. package/dist/types.js +68 -0
  77. package/dist/types.js.map +1 -1
  78. package/dist/weekly.d.ts +21 -3
  79. package/dist/weekly.js +18 -1
  80. package/dist/weekly.js.map +1 -1
  81. package/package.json +5 -1
  82. package/src/activity.ts +154 -0
  83. package/src/assertExpect.ts +168 -0
  84. package/src/blind.ts +138 -0
  85. package/src/cli/addPages.ts +20 -4
  86. package/src/cli/main.ts +4 -3
  87. package/src/compare.ts +85 -0
  88. package/src/decisions.ts +10 -0
  89. package/src/feedback.ts +20 -2
  90. package/src/glossary.ts +40 -0
  91. package/src/health.ts +5 -3
  92. package/src/importCases.ts +172 -33
  93. package/src/inInstructions.ts +105 -0
  94. package/src/index.ts +5 -0
  95. package/src/memoryStore.ts +2 -1
  96. package/src/readCheck.ts +458 -0
  97. package/src/runner.ts +74 -4
  98. package/src/settings.ts +192 -26
  99. package/src/store.ts +11 -3
  100. package/src/suggest.ts +33 -4
  101. package/src/suiteContract.ts +147 -0
  102. package/src/suites/crisisRisk.ts +250 -0
  103. package/src/suites/crisisRiskCases.ts +205 -0
  104. package/src/suites/hopelessness.ts +410 -0
  105. package/src/suites/hopelessnessCases.ts +286 -0
  106. package/src/suites/index.ts +11 -0
  107. package/src/testing.ts +646 -121
  108. package/src/types.ts +147 -0
  109. package/src/weekly.ts +39 -3
  110. package/starter/index.ts +8 -0
  111. package/templates/app/evals/[suite]/compare/page.tsx +385 -0
  112. package/templates/app/evals/[suite]/page.tsx +104 -31
  113. package/templates/app/evals/[suite]/rate/page.tsx +143 -0
  114. package/templates/app/evals/[suite]/runs/[runId]/page.tsx +84 -3
  115. package/templates/app/evals/[suite]/side-by-side/page.tsx +320 -0
  116. package/templates/app/evals/feedback/page.tsx +3 -0
  117. package/templates/app/evals/page.tsx +3 -0
  118. package/templates/components/evalkeeper/AnswerKey.tsx +2 -1
  119. package/templates/components/evalkeeper/DisagreementChip.tsx +35 -0
  120. package/templates/components/evalkeeper/ReadableOutput.tsx +97 -0
  121. package/templates/components/evalkeeper/RollBack.tsx +21 -1
  122. package/templates/components/evalkeeper/SettingsHistory.tsx +29 -5
  123. package/templates/components/evalkeeper/WeeklyCheck.tsx +34 -2
  124. package/templates/lib/evalkeeper/actions.ts +68 -4
  125. package/templates/lib/evalkeeper/weekly.ts +27 -4
package/src/types.ts CHANGED
@@ -13,6 +13,12 @@ export type CheckResult = {
13
13
  pass: boolean | null;
14
14
  /** Why it failed (or a detail worth showing), in plain words. */
15
15
  note?: string | undefined;
16
+ /**
17
+ * What a decision check's answer gave, right or wrong ("34% true, bar
18
+ * 40%", "bug (90%)"), so a run page can show the probability beside the
19
+ * bar it was read at.
20
+ */
21
+ given?: string | undefined;
16
22
  /** For matching checks: which expected item matched which output, and why. */
17
23
  matches?: { expected: string; actual: string; why: string }[] | undefined;
18
24
  /** "meaning": a judge model matched them; "words": shared words did. */
@@ -174,6 +180,24 @@ export type Suite<Input, Output, Label> = {
174
180
  count: number;
175
181
  focus: string | null;
176
182
  }): Promise<{ input: Input; label: Label; tags: string[]; note: string }[]>;
183
+ /**
184
+ * Drafts cases from what the feature saw in your app since a date (inputs
185
+ * people rated or admins flagged), so the answer key keeps up with real
186
+ * use. The weekly check calls it through `draftFromActivity`; drafts
187
+ * arrive with a PENDING answer or none, never confirmed. Strip names,
188
+ * contact details, and anything identifying from each input. Return at
189
+ * most `limit`, and skip anything whose `sourceRef` is in `known`.
190
+ */
191
+ draftFromActivity?(args: {
192
+ /** Look at activity from this date on. */
193
+ since: Date;
194
+ /** The suite's cases, retired ones too, to avoid near-repeats. */
195
+ existing: { input: Input; tags: string[] }[];
196
+ /** The most drafts to return: what's left of this week's allowance. */
197
+ limit: number;
198
+ /** The `sourceRef` of every draft made before: skip these. */
199
+ known: ReadonlySet<string>;
200
+ }): Promise<ActivityDraft<Input, Label>[]>;
177
201
  /**
178
202
  * How long one answer may take before it counts as failed. Default 60s;
179
203
  * multi-step agent turns need more. Keep it under the run budget.
@@ -201,6 +225,25 @@ export type Suite<Input, Output, Label> = {
201
225
  * edited as JSON.
202
226
  */
203
227
  caseKind?: "typed" | "imported" | "fixture";
228
+ /**
229
+ * Removes anything the input learned from its own case before it's
230
+ * frozen, so a case can't carry its answer: facts the app learned from
231
+ * the person's reaction to that same item, for example. `importCases`,
232
+ * `importStarters`, and adding a case on the pages run it, and report
233
+ * what it removed per case so a person can check it. Match on something
234
+ * specific to the case (the company's name), not something general (a
235
+ * job title), or it removes what other cases rightly share.
236
+ *
237
+ * @param input - The case's input, already checked against `input`.
238
+ * @param source - Where the case came from: its `sourceRef`, or null
239
+ * for a case added by hand.
240
+ * @returns The input without what leaked, and a plain line for each
241
+ * item removed (empty when nothing was).
242
+ */
243
+ withoutLeaks?(
244
+ input: Input,
245
+ source: { sourceRef: string | null },
246
+ ): { input: Input; removed: string[] };
204
247
  /** A short line naming the case in lists. */
205
248
  title(input: Input): string;
206
249
  /** Fixture suites: the whole input, readable, for reviewing a case. */
@@ -209,6 +252,25 @@ export type Suite<Input, Output, Label> = {
209
252
  labelHelp?: string;
210
253
  };
211
254
 
255
+ /**
256
+ * A case a suite drafted from your app's activity, for a person to review.
257
+ * Return these from `Suite.draftFromActivity`.
258
+ */
259
+ export type ActivityDraft<Input, Label> = {
260
+ /** The input the feature saw, with names and contact details removed. */
261
+ input: Input;
262
+ /** A proposed answer, stored PENDING; null: the reviewer writes one. */
263
+ label: Label | null;
264
+ tags: string[];
265
+ /** Why it was drafted, shown to the reviewer ("Rated thumbs down."). */
266
+ note: string;
267
+ /**
268
+ * What it was drafted from (an id in your app), so it's never drafted
269
+ * twice, even weeks later or after someone retires it.
270
+ */
271
+ sourceRef: string;
272
+ };
273
+
212
274
  /**
213
275
  * One field of a suite's add/edit form. `name` is the form key (and the
214
276
  * input or answer property it fills). "lines": one item per line, read as
@@ -261,3 +323,88 @@ export function linesOf(form: FormData, name: string): string[] {
261
323
  * `unknown`; a suite's own code keeps its precise types.
262
324
  */
263
325
  export type AnySuite = Suite<unknown, unknown, unknown>;
326
+
327
+ /** Where a zod issue sits, in plain words: "facts, item 2, name". */
328
+ function issuePath(path: readonly (string | number)[]): string {
329
+ return path
330
+ .map((p) => (typeof p === "number" ? `item ${p + 1}` : p))
331
+ .join(", ");
332
+ }
333
+
334
+ /**
335
+ * Reads one form field as JSON and checks it with a schema; throws a
336
+ * plain error when the field is empty, isn't JSON, or doesn't fit (naming
337
+ * the first part that doesn't).
338
+ */
339
+ function readJson<T>(
340
+ form: FormData,
341
+ field: string,
342
+ what: string,
343
+ schema: z.ZodType<T>,
344
+ ): T {
345
+ const text = formText(form, field);
346
+ if (!text) throw new Error(`${what} is empty: fill in the "${field}" field`);
347
+ let value: unknown;
348
+ try {
349
+ value = JSON.parse(text);
350
+ } catch (e) {
351
+ throw new Error(
352
+ `${what} isn't valid JSON: ${e instanceof Error ? e.message : String(e)}`,
353
+ { cause: e },
354
+ );
355
+ }
356
+ const parsed = schema.safeParse(value);
357
+ if (parsed.success) return parsed.data;
358
+ const issue = parsed.error.issues[0];
359
+ const where = issue ? issuePath(issue.path) : "";
360
+ const message = issue?.message ?? "invalid";
361
+ throw new Error(
362
+ where
363
+ ? `${what} doesn't fit at ${where}: ${message}`
364
+ : `${what} doesn't fit: ${message}`,
365
+ );
366
+ }
367
+
368
+ /**
369
+ * A suite's `inputFromForm` for fixture suites (`caseKind: "fixture"`),
370
+ * whose cases are edited as JSON in one textarea. Reads the field, parses
371
+ * it, and checks it with the schema; throws a plain error when it's empty,
372
+ * isn't valid JSON ("Input isn't valid JSON: …"), or doesn't fit, naming
373
+ * the first part that doesn't ("Input doesn't fit at facts, item 2, name:
374
+ * Required").
375
+ *
376
+ * @param schema - The suite's input schema.
377
+ * @param field - The form field holding the JSON; default "input".
378
+ * @returns A form reader to use as the suite's `inputFromForm`.
379
+ *
380
+ * @example
381
+ * ```ts
382
+ * const profileFit: Suite<Profile, Fit, FitLabel> = {
383
+ * // …
384
+ * caseKind: "fixture",
385
+ * inputFromForm: inputFromJson(profileSchema),
386
+ * labelFromForm: labelFromJson(fitLabelSchema),
387
+ * };
388
+ * ```
389
+ */
390
+ export function inputFromJson<T>(
391
+ schema: z.ZodType<T>,
392
+ field = "input",
393
+ ): (form: FormData) => T {
394
+ return (form) => readJson(form, field, "Input", schema);
395
+ }
396
+
397
+ /**
398
+ * A suite's `labelFromForm` for fixture suites: like `inputFromJson`, for
399
+ * the expected answer ("Answer isn't valid JSON: …").
400
+ *
401
+ * @param schema - The suite's answer schema (`labelValue`).
402
+ * @param field - The form field holding the JSON; default "label".
403
+ * @returns A form reader to use as the suite's `labelFromForm`.
404
+ */
405
+ export function labelFromJson<T>(
406
+ schema: z.ZodType<T>,
407
+ field = "label",
408
+ ): (form: FormData) => T {
409
+ return (form) => readJson(form, field, "Answer", schema);
410
+ }
package/src/weekly.ts CHANGED
@@ -1,13 +1,15 @@
1
+ import { ACTIVITY_SOURCE } from "./activity.js";
1
2
  import type { ThumbsSummary } from "./feedback.js";
2
3
  import { retiresLabel, type ModelCatalog } from "./models.js";
3
- import type { RunMetrics, RunRecord } from "./store.js";
4
+ import type { CaseRecord, RunMetrics, RunRecord } from "./store.js";
4
5
  import { daysUntil, drifted, retiresSoon } from "./upkeepRules.js";
5
6
 
6
7
  /**
7
8
  * The weekly check: each suite's quick set on its live model, with fresh
8
9
  * answers, so a provider quietly changing a model under the same name shows
9
10
  * up as drift. The summary also flags models retiring soon and features
10
- * people rate poorly. It only reports; a person decides what to change.
11
+ * people rate poorly, and counts the cases suites drafted from the app's
12
+ * activity. It only reports; a person decides what to change.
11
13
  * Pure.
12
14
  */
13
15
 
@@ -18,7 +20,8 @@ const DAY = 86_400_000;
18
20
 
19
21
  /**
20
22
  * What the last weekly check found: drift, unfinished checks, retiring models, and
21
- * thumbs-down, plus when it ran and what it cost.
23
+ * thumbs-down, plus when it ran, what it cost, and the cases drafted from
24
+ * activity.
22
25
  */
23
26
  export type WeeklySummary = {
24
27
  /** When the last weekly check started; null before the first. */
@@ -47,6 +50,12 @@ export type WeeklySummary = {
47
50
  }[];
48
51
  /** Features with a high thumbs-down share this week. */
49
52
  thumbs: ThumbsSummary[];
53
+ /**
54
+ * Cases each suite drafted from the app's activity in the last 7 days,
55
+ * and how many of them still wait for a person (no confirmed answer, not
56
+ * retired). Drafts are news, not trouble: they don't affect `clear`.
57
+ */
58
+ drafted: { suite: string; label: string; count: number; waiting: number }[];
50
59
  /** Ran, and nothing needs a look. */
51
60
  clear: boolean;
52
61
  };
@@ -78,6 +87,11 @@ export function weeklySummary(args: {
78
87
  models: ModelCatalog;
79
88
  /** From thumbsSummary over the last week; only flagged ones are shown. */
80
89
  thumbs?: ThumbsSummary[];
90
+ /**
91
+ * Every suite's cases (`store.listCases`), to count the drafts from
92
+ * activity. Leave out to skip the count.
93
+ */
94
+ cases?: CaseRecord[];
81
95
  today?: Date;
82
96
  }): WeeklySummary {
83
97
  const today = args.today ?? new Date();
@@ -152,6 +166,27 @@ export function weeklySummary(args: {
152
166
  }
153
167
 
154
168
  const thumbs = (args.thumbs ?? []).filter((t) => t.alert);
169
+
170
+ const drafted: WeeklySummary["drafted"] = [];
171
+ for (const s of args.suites) {
172
+ const recent = (args.cases ?? []).filter(
173
+ (c) =>
174
+ c.suite === s.key &&
175
+ c.source === ACTIVITY_SOURCE &&
176
+ +today - +c.createdAt < 7 * DAY,
177
+ );
178
+ if (recent.length)
179
+ drafted.push({
180
+ suite: s.key,
181
+ label: s.label,
182
+ count: recent.length,
183
+ waiting: recent.filter(
184
+ (c) =>
185
+ c.status !== "RETIRED" &&
186
+ !c.labels.some((l) => l.status === "CONFIRMED"),
187
+ ).length,
188
+ });
189
+ }
155
190
  return {
156
191
  lastAt,
157
192
  costUsd: batch.reduce((t, r) => t + (r.metrics?.costUsd ?? 0), 0),
@@ -160,6 +195,7 @@ export function weeklySummary(args: {
160
195
  failed,
161
196
  retiring,
162
197
  thumbs,
198
+ drafted,
163
199
  clear:
164
200
  lastAt !== null &&
165
201
  !drift.length &&
package/starter/index.ts CHANGED
@@ -45,6 +45,13 @@ export const SUITE_BY_KEY: Record<string, AnySuite> = Object.fromEntries(
45
45
  */
46
46
  const PROMPT_VERSIONS: Record<string, string> = {};
47
47
 
48
+ /**
49
+ * TODO: each feature's instructions as text (instructionParts from
50
+ * @crowandraven/evalkeeper-ai-sdk, on the parts you hash), so the suite
51
+ * page warns when a case was copied into them.
52
+ */
53
+ const INSTRUCTION_TEXTS: Record<string, string[]> = {};
54
+
48
55
  /** TODO: each feature's settings in code, used until someone changes them. */
49
56
  const DEFAULTS: Record<string, Settings> = {};
50
57
 
@@ -69,6 +76,7 @@ export const runner = createRunner({
69
76
  suites: SUITES,
70
77
  models: MODELS,
71
78
  promptVersion: (operation) => PROMPT_VERSIONS[operation] ?? "unregistered",
79
+ instructionTexts: (operation) => INSTRUCTION_TEXTS[operation] ?? [],
72
80
  route: routeFor,
73
81
  candidates: (operation) => ({ models: modelsFor(operation) }),
74
82
  });
@@ -0,0 +1,385 @@
1
+ import type { Metadata } from "next";
2
+ import Link from "next/link";
3
+ import { notFound } from "next/navigation";
4
+ import {
5
+ checkBar,
6
+ perAnswer,
7
+ seconds,
8
+ verdictSentence,
9
+ type Rate,
10
+ type RunRecord,
11
+ } from "@crowandraven/evalkeeper";
12
+ import { DisagreementChip } from "@/components/evalkeeper/DisagreementChip";
13
+ import { Submit } from "@/components/evalkeeper/Submit";
14
+ import { InfoTip, Tip } from "@/components/evalkeeper/Tip";
15
+ import { BackLink, Card, Chip, pct } from "@/components/evalkeeper/ui";
16
+ import {
17
+ MODELS,
18
+ SUITE_BY_KEY,
19
+ requireAdmin,
20
+ routeFor,
21
+ runner,
22
+ store,
23
+ } from "@/lib/evalkeeper";
24
+ import { evalsPath } from "@/lib/evalkeeper/paths";
25
+
26
+ export const dynamic = "force-dynamic";
27
+
28
+ export async function generateMetadata({
29
+ params,
30
+ }: {
31
+ params: Promise<{ suite: string }>;
32
+ }): Promise<Metadata> {
33
+ const { suite } = await params;
34
+ return { title: `Compare: ${SUITE_BY_KEY[suite]?.label ?? "Evals"}` };
35
+ }
36
+
37
+ /** A search parameter as one string, or null when it's missing or repeated. */
38
+ const one = (v: string | string[] | undefined) =>
39
+ typeof v === "string" && v ? v : null;
40
+
41
+ /** A test's name: its model, reasoning setting, set, and when it ran. */
42
+ function testName(r: RunRecord): string {
43
+ const model = MODELS[r.model]?.label ?? r.model;
44
+ const effort = r.reasoningEffort ? `, ${r.reasoningEffort} reasoning` : "";
45
+ const set = r.set === "ALL" ? "" : `, ${r.set.toLowerCase()} set`;
46
+ return `${model}${effort}${set} · ${r.startedAt.toLocaleString()}`;
47
+ }
48
+
49
+ /** A pass rate as "80% (8/10)", or a dash when the check never applied. */
50
+ function rateText(r: Rate | undefined): string {
51
+ return r && r.n > 0 ? `${pct(r.passed / r.n)} (${r.passed}/${r.n})` : "—";
52
+ }
53
+
54
+ /**
55
+ * Two finished tests of a suite compared: the verdict in plain words, each
56
+ * check's pass rate side by side, and the cases they graded differently,
57
+ * each linked to its answers side by side. `a` is the test in place (the
58
+ * live model's latest when left out), `b` the challenger.
59
+ */
60
+ export default async function ComparePage({
61
+ params,
62
+ searchParams,
63
+ }: {
64
+ params: Promise<{ suite: string }>;
65
+ searchParams: Promise<Record<string, string | string[] | undefined>>;
66
+ }) {
67
+ await requireAdmin();
68
+ const { suite: key } = await params;
69
+ const sp = await searchParams;
70
+ const suiteDef = SUITE_BY_KEY[key];
71
+ if (!suiteDef) notFound();
72
+ const runs = await store.listRuns(key, { status: "SUCCEEDED" });
73
+ const b = one(sp.b);
74
+ // Without a test in place, the live model's latest finished test.
75
+ let a = one(sp.a);
76
+ if (!a) {
77
+ // A feature with no settings yet has no live model to start from.
78
+ const live = await routeFor(suiteDef.operation).then(
79
+ (r) => r.model,
80
+ () => null,
81
+ );
82
+ a = runs.find((r) => r.model === live && r.id !== b)?.id ?? null;
83
+ }
84
+ const result = a && b ? await runner.compare(key, a, b) : null;
85
+ const titles = new Map(
86
+ (await store.listCases(key, { includeRetired: true })).map((c) => [
87
+ c.id,
88
+ suiteDef.title(suiteDef.input.parse(c.input)),
89
+ ]),
90
+ );
91
+ const sideBySide = (caseId: string) =>
92
+ result
93
+ ? `${evalsPath(key, "side-by-side")}?${new URLSearchParams({ a: result.a.id, b: result.b.id, case: caseId })}`
94
+ : "";
95
+
96
+ return (
97
+ <div className="space-y-8">
98
+ <div className="space-y-2">
99
+ <BackLink href={evalsPath(key)}>{suiteDef.label}</BackLink>
100
+ <h1 className="text-2xl font-semibold">
101
+ Compare two tests
102
+ <InfoTip term="comparison" />
103
+ </h1>
104
+ <p className="readable text-muted">
105
+ Pick the test in place and a challenger. Only finished tests of{" "}
106
+ {suiteDef.label} can be compared.
107
+ </p>
108
+ </div>
109
+
110
+ <Card>
111
+ {/* Keyed by the tests, so the pickers show them after a swap. */}
112
+ <form
113
+ key={`${a ?? ""}-${b ?? ""}`}
114
+ action={evalsPath(key, "compare")}
115
+ className="grid items-end gap-4 md:grid-cols-[1fr_1fr_auto]"
116
+ >
117
+ <TestPicker
118
+ name="a"
119
+ label="In place"
120
+ term="inPlace"
121
+ runs={runs}
122
+ value={a}
123
+ />
124
+ <TestPicker
125
+ name="b"
126
+ label="Challenger"
127
+ term="challenger"
128
+ runs={runs}
129
+ value={b}
130
+ />
131
+ <div className="pb-1">
132
+ <Submit>Compare</Submit>
133
+ </div>
134
+ </form>
135
+ </Card>
136
+
137
+ {a && b && !result && (
138
+ <p className="readable text-warn">
139
+ These can&apos;t be compared: pick two different finished tests of
140
+ this suite.
141
+ </p>
142
+ )}
143
+ {runs.length < 2 && (
144
+ <p className="readable text-muted">
145
+ This suite needs two finished tests to compare. Test another model on
146
+ the suite page first.
147
+ </p>
148
+ )}
149
+
150
+ {result && (
151
+ <>
152
+ <Card className="space-y-3">
153
+ <div className="flex flex-wrap items-start justify-between gap-3">
154
+ <h2 className="font-semibold">
155
+ Verdict
156
+ <InfoTip term="verdict" />
157
+ </h2>
158
+ <Link
159
+ href={`${evalsPath(key, "compare")}?${new URLSearchParams({ a: result.b.id, b: result.a.id })}`}
160
+ className="text-sm text-muted hover:text-ink"
161
+ >
162
+ Swap them
163
+ </Link>
164
+ </div>
165
+ <p className="readable text-lg">
166
+ {verdictSentence(
167
+ result.comparison,
168
+ MODELS[result.b.model]?.label ?? result.b.model,
169
+ )}
170
+ </p>
171
+ <p className="readable text-sm text-muted">
172
+ <Link href={evalsPath(key, "runs", result.a.id)}>
173
+ {testName(result.a)}
174
+ </Link>{" "}
175
+ (in place) against{" "}
176
+ <Link href={evalsPath(key, "runs", result.b.id)}>
177
+ {testName(result.b)}
178
+ </Link>{" "}
179
+ (challenger), on{" "}
180
+ <Tip term="sharedCases">
181
+ <span>{result.comparison.n} shared cases</span>
182
+ </Tip>
183
+ .
184
+ </p>
185
+ <p className="text-sm text-muted">
186
+ <Tip term="cost" id="cost-compare">
187
+ <span>
188
+ Cost per answer: {perAnswer(result.comparison.cost.champion)}{" "}
189
+ in place, {perAnswer(result.comparison.cost.challenger)}{" "}
190
+ challenger
191
+ </span>
192
+ </Tip>
193
+ {" · "}
194
+ <Tip term="time" id="time-compare" align="end">
195
+ <span>
196
+ Time: {seconds(result.comparison.avgMs.champion)} in place,{" "}
197
+ {seconds(result.comparison.avgMs.challenger)} challenger
198
+ </span>
199
+ </Tip>
200
+ </p>
201
+ {result.caveats.length > 0 && (
202
+ <div className="readable rounded-md bg-tint p-3 text-sm">
203
+ <p className="font-medium">
204
+ Measured differently
205
+ <InfoTip term="measuredDifferently" />
206
+ </p>
207
+ <ul className="list-disc pl-5 text-muted">
208
+ {result.caveats.map((c) => (
209
+ <li key={c}>{c}</li>
210
+ ))}
211
+ </ul>
212
+ </div>
213
+ )}
214
+ </Card>
215
+
216
+ <section className="space-y-3">
217
+ <h2 className="text-lg font-semibold">
218
+ Checks
219
+ <InfoTip term="checks" />
220
+ </h2>
221
+ <Card className="overflow-x-auto p-0">
222
+ <table className="w-full text-sm">
223
+ <thead className="text-left text-muted">
224
+ <tr className="border-b border-line">
225
+ <th className="p-3 font-normal">Check</th>
226
+ <th className="p-3 font-normal">
227
+ <Tip term="inPlace" side="bottom" id="inPlace-col">
228
+ In place
229
+ </Tip>
230
+ </th>
231
+ <th className="p-3 font-normal">
232
+ <Tip term="challenger" side="bottom" id="challenger-col">
233
+ Challenger
234
+ </Tip>
235
+ </th>
236
+ <th className="p-3 font-normal">
237
+ <Tip term="bar" side="bottom" align="end">
238
+ Bar
239
+ </Tip>
240
+ </th>
241
+ </tr>
242
+ </thead>
243
+ <tbody>
244
+ {result.suite.checks.map((c) => {
245
+ const r = result.comparison.byCheck[c.key];
246
+ return (
247
+ <tr
248
+ key={c.key}
249
+ className="border-b border-line last:border-0"
250
+ >
251
+ <td className="p-3">
252
+ <span className="flex flex-wrap items-center gap-2">
253
+ {c.label}
254
+ <Tip
255
+ term={c.severity}
256
+ id={`severity-${c.key}`}
257
+ side="bottom"
258
+ >
259
+ <Chip
260
+ tone={
261
+ c.severity === "serious"
262
+ ? "serious"
263
+ : "neutral"
264
+ }
265
+ >
266
+ {c.severity}
267
+ </Chip>
268
+ </Tip>
269
+ </span>
270
+ </td>
271
+ <td className="p-3 tabular-nums">
272
+ <Tip term="passRate" id={`a-${c.key}`} side="bottom">
273
+ <span>{rateText(r?.champion)}</span>
274
+ </Tip>
275
+ </td>
276
+ <td className="p-3 tabular-nums">
277
+ <Tip term="passRate" id={`b-${c.key}`} side="bottom">
278
+ <span>{rateText(r?.challenger)}</span>
279
+ </Tip>
280
+ </td>
281
+ <td className="p-3 tabular-nums text-muted">
282
+ {pct(checkBar(c))}
283
+ </td>
284
+ </tr>
285
+ );
286
+ })}
287
+ </tbody>
288
+ </table>
289
+ </Card>
290
+ </section>
291
+
292
+ <section className="space-y-3">
293
+ <div className="flex flex-wrap items-center justify-between gap-3">
294
+ <h2 className="text-lg font-semibold">
295
+ Where they differ ({result.disagreements.length})
296
+ <InfoTip term="disagreements" />
297
+ </h2>
298
+ {result.disagreements[0] && (
299
+ <Link
300
+ href={sideBySide(result.disagreements[0].caseId)}
301
+ className="text-sm text-accent"
302
+ >
303
+ Read them side by side
304
+ </Link>
305
+ )}
306
+ </div>
307
+ {result.disagreements.length === 0 ? (
308
+ <p className="readable text-muted">
309
+ The two tests graded every shared case alike.
310
+ </p>
311
+ ) : (
312
+ <Card className="space-y-2">
313
+ {result.disagreements.map((d) => (
314
+ <div
315
+ key={d.caseId}
316
+ className="flex flex-wrap items-center justify-between gap-3 rounded-md bg-tint p-3 text-sm"
317
+ >
318
+ <Link
319
+ href={sideBySide(d.caseId)}
320
+ className="font-medium hover:underline"
321
+ >
322
+ {titles.get(d.caseId) ?? "A retired case"}
323
+ </Link>
324
+ <span className="flex items-center gap-3">
325
+ <Tip term="caseScore" id={`score-${d.caseId}`}>
326
+ <span className="text-xs text-muted tabular-nums">
327
+ {pct(d.champion)} → {pct(d.challenger)}
328
+ </span>
329
+ </Tip>
330
+ <DisagreementChip
331
+ kind={d.kind}
332
+ id={`kind-${d.caseId}`}
333
+ align="end"
334
+ />
335
+ </span>
336
+ </div>
337
+ ))}
338
+ </Card>
339
+ )}
340
+ </section>
341
+ </>
342
+ )}
343
+ </div>
344
+ );
345
+ }
346
+
347
+ /** One of the two tests to compare, chosen from the suite's finished tests. */
348
+ function TestPicker({
349
+ name,
350
+ label,
351
+ term,
352
+ runs,
353
+ value,
354
+ }: {
355
+ name: string;
356
+ label: string;
357
+ term: "inPlace" | "challenger";
358
+ runs: RunRecord[];
359
+ value: string | null;
360
+ }) {
361
+ return (
362
+ <div className="space-y-1">
363
+ <label htmlFor={`pick-${name}`} className="block text-sm font-medium">
364
+ {label}
365
+ <InfoTip term={term} id={`${term}-pick`} />
366
+ </label>
367
+ <select
368
+ id={`pick-${name}`}
369
+ name={name}
370
+ defaultValue={value ?? ""}
371
+ required
372
+ className="w-full rounded-md border border-line bg-card px-3 py-2 text-sm focus:border-accent focus:outline-none"
373
+ >
374
+ <option value="" disabled>
375
+ Pick a test
376
+ </option>
377
+ {runs.map((r) => (
378
+ <option key={r.id} value={r.id}>
379
+ {testName(r)}
380
+ </option>
381
+ ))}
382
+ </select>
383
+ </div>
384
+ );
385
+ }