@crowandraven/evalkeeper 0.4.1 → 0.7.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.
- package/README.md +7 -0
- package/dist/activity.d.ts +58 -0
- package/dist/activity.js +125 -0
- package/dist/activity.js.map +1 -0
- package/dist/assertExpect.d.ts +52 -0
- package/dist/assertExpect.js +104 -0
- package/dist/assertExpect.js.map +1 -0
- package/dist/blind.d.ts +79 -0
- package/dist/blind.js +113 -0
- package/dist/blind.js.map +1 -0
- package/dist/cli/addPages.d.ts +34 -0
- package/dist/cli/addPages.js +91 -11
- package/dist/cli/addPages.js.map +1 -1
- package/dist/cli/main.d.ts +1 -1
- package/dist/cli/main.js +9 -0
- package/dist/cli/main.js.map +1 -1
- package/dist/compare.d.ts +38 -0
- package/dist/compare.js +62 -0
- package/dist/compare.js.map +1 -1
- package/dist/glossary.d.ts +20 -0
- package/dist/glossary.js +20 -0
- package/dist/glossary.js.map +1 -1
- package/dist/health.js +5 -3
- package/dist/health.js.map +1 -1
- package/dist/importCases.d.ts +76 -5
- package/dist/importCases.js +114 -14
- package/dist/importCases.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/memoryStore.js +3 -1
- package/dist/memoryStore.js.map +1 -1
- package/dist/readCheck.d.ts +116 -0
- package/dist/readCheck.js +321 -0
- package/dist/readCheck.js.map +1 -0
- package/dist/runner.d.ts +7 -0
- package/dist/runner.js +25 -3
- package/dist/runner.js.map +1 -1
- package/dist/settings.d.ts +81 -3
- package/dist/settings.js +160 -23
- package/dist/settings.js.map +1 -1
- package/dist/store.d.ts +10 -3
- package/dist/suggest.d.ts +10 -1
- package/dist/suggest.js +22 -4
- package/dist/suggest.js.map +1 -1
- package/dist/suiteContract.d.ts +17 -0
- package/dist/suiteContract.js +69 -0
- package/dist/suiteContract.js.map +1 -0
- package/dist/suites/crisisRisk.d.ts +83 -0
- package/dist/suites/crisisRisk.js +176 -0
- package/dist/suites/crisisRisk.js.map +1 -0
- package/dist/suites/crisisRiskCases.d.ts +40 -0
- package/dist/suites/crisisRiskCases.js +179 -0
- package/dist/suites/crisisRiskCases.js.map +1 -0
- package/dist/suites/index.d.ts +9 -0
- package/dist/suites/index.js +10 -0
- package/dist/suites/index.js.map +1 -0
- package/dist/testing.d.ts +140 -8
- package/dist/testing.js +420 -125
- package/dist/testing.js.map +1 -1
- package/dist/types.d.ts +92 -0
- package/dist/types.js +68 -0
- package/dist/types.js.map +1 -1
- package/dist/weekly.d.ts +21 -3
- package/dist/weekly.js +18 -1
- package/dist/weekly.js.map +1 -1
- package/package.json +5 -1
- package/src/activity.ts +154 -0
- package/src/assertExpect.ts +168 -0
- package/src/blind.ts +138 -0
- package/src/cli/addPages.ts +119 -17
- package/src/cli/main.ts +11 -0
- package/src/compare.ts +85 -0
- package/src/glossary.ts +36 -0
- package/src/health.ts +5 -3
- package/src/importCases.ts +172 -33
- package/src/index.ts +4 -0
- package/src/memoryStore.ts +2 -1
- package/src/readCheck.ts +458 -0
- package/src/runner.ts +33 -4
- package/src/settings.ts +192 -26
- package/src/store.ts +11 -3
- package/src/suggest.ts +33 -4
- package/src/suiteContract.ts +101 -0
- package/src/suites/crisisRisk.ts +250 -0
- package/src/suites/crisisRiskCases.ts +205 -0
- package/src/suites/index.ts +9 -0
- package/src/testing.ts +564 -127
- package/src/types.ts +141 -0
- package/src/weekly.ts +39 -3
- package/templates/app/evals/[suite]/compare/page.tsx +375 -0
- package/templates/app/evals/[suite]/page.tsx +55 -19
- package/templates/app/evals/[suite]/rate/page.tsx +133 -0
- package/templates/app/evals/[suite]/runs/[runId]/page.tsx +12 -0
- package/templates/app/evals/[suite]/side-by-side/page.tsx +300 -0
- package/templates/components/evalkeeper/DisagreementChip.tsx +35 -0
- package/templates/components/evalkeeper/RollBack.tsx +21 -1
- package/templates/components/evalkeeper/SettingsHistory.tsx +20 -2
- package/templates/components/evalkeeper/WeeklyCheck.tsx +34 -2
- package/templates/lib/evalkeeper/actions.ts +68 -4
- package/templates/lib/evalkeeper/weekly.ts +27 -4
package/src/health.ts
CHANGED
|
@@ -103,9 +103,11 @@ export function suiteHealth(
|
|
|
103
103
|
const change = s && !s.same;
|
|
104
104
|
if (change)
|
|
105
105
|
details.push(
|
|
106
|
-
s.
|
|
107
|
-
?
|
|
108
|
-
:
|
|
106
|
+
s.retestLive
|
|
107
|
+
? (s.reasons[0] ?? `Test ${s.live.label} again.`)
|
|
108
|
+
: s.keepLive
|
|
109
|
+
? `A better fallback is suggested: ${s.fallback?.label}.`
|
|
110
|
+
: `${s.live.label} is suggested over ${liveRow.label}.`,
|
|
109
111
|
);
|
|
110
112
|
if (testedModels < 2)
|
|
111
113
|
details.push("Only one model tested: test others to compare.");
|
package/src/importCases.ts
CHANGED
|
@@ -22,10 +22,13 @@ export type ImportedCase = {
|
|
|
22
22
|
* each one on the pages before tests use it. Provisional: tests use them
|
|
23
23
|
* now, every score says it rests on unreviewed answers, and the rows carry
|
|
24
24
|
* `tag` so the review queue is findable. Use provisional only when the
|
|
25
|
-
* owner said so; `allowedBy` and `at` record who and when.
|
|
26
|
-
*
|
|
25
|
+
* owner said so; `allowedBy` and `at` record who and when. Confirmed: only
|
|
26
|
+
* for answers a person already reviewed in the system they come from;
|
|
27
|
+
* `confirmedBy` and `at` read who and when from each row, and the import
|
|
28
|
+
* is refused unless every row names both. Answers drafted by an agent or
|
|
29
|
+
* scraped from somewhere are never imported confirmed.
|
|
27
30
|
*/
|
|
28
|
-
export type ImportAnswers =
|
|
31
|
+
export type ImportAnswers<Row = never> =
|
|
29
32
|
| { status: "PENDING" }
|
|
30
33
|
| {
|
|
31
34
|
status: "PROVISIONAL";
|
|
@@ -37,6 +40,21 @@ export type ImportAnswers =
|
|
|
37
40
|
at?: Date;
|
|
38
41
|
/** Added to each row's tags; default "needs-review". */
|
|
39
42
|
tag?: string;
|
|
43
|
+
}
|
|
44
|
+
| {
|
|
45
|
+
status: "CONFIRMED";
|
|
46
|
+
/**
|
|
47
|
+
* The person who confirmed this row's answer in the old system,
|
|
48
|
+
* recorded as the rater. Never defaulted: a row without one stops
|
|
49
|
+
* the import.
|
|
50
|
+
*/
|
|
51
|
+
confirmedBy: (row: Row) => string | null | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* When they confirmed it: a Date, or text `Date` can read. Never
|
|
54
|
+
* defaulted: a row without one, or with one in the future, stops
|
|
55
|
+
* the import.
|
|
56
|
+
*/
|
|
57
|
+
at: (row: Row) => Date | string | null | undefined;
|
|
40
58
|
};
|
|
41
59
|
|
|
42
60
|
/** A row that couldn't be imported, and why. */
|
|
@@ -57,14 +75,71 @@ export class CaseImportError extends Error {
|
|
|
57
75
|
}
|
|
58
76
|
}
|
|
59
77
|
|
|
78
|
+
/** What a suite's leak check removed from one imported case. */
|
|
79
|
+
export type ImportLeak = {
|
|
80
|
+
/** The row's id within its source. */
|
|
81
|
+
id: string;
|
|
82
|
+
/** A plain line for each item removed. */
|
|
83
|
+
removed: string[];
|
|
84
|
+
};
|
|
85
|
+
|
|
60
86
|
/** What an import did. */
|
|
61
87
|
export type ImportResult = {
|
|
62
88
|
/** Cases created. */
|
|
63
89
|
added: number;
|
|
64
90
|
/** Rows imported before (by source and id), left alone. */
|
|
65
91
|
skipped: number;
|
|
92
|
+
/**
|
|
93
|
+
* The cases added that the suite's `withoutLeaks` changed, and what it
|
|
94
|
+
* removed from each, for a person to check. Empty without a leak check.
|
|
95
|
+
*/
|
|
96
|
+
removed: ImportLeak[];
|
|
66
97
|
};
|
|
67
98
|
|
|
99
|
+
/**
|
|
100
|
+
* Runs a suite's leak check (`withoutLeaks`) on an input about to be
|
|
101
|
+
* frozen into a case, and checks the result still fits the suite's input.
|
|
102
|
+
* Without a leak check, the input comes back as it was. Use it wherever
|
|
103
|
+
* cases are made outside `importCases`, such as an "add case" action.
|
|
104
|
+
*
|
|
105
|
+
* @param suite - The suite the case belongs to.
|
|
106
|
+
* @param input - The case's input, already checked against `suite.input`.
|
|
107
|
+
* @param sourceRef - What the case was made from, or null when added by
|
|
108
|
+
* hand.
|
|
109
|
+
* @returns The input to freeze, and what was removed from it.
|
|
110
|
+
* @throws When the leak check returns an input that doesn't fit the suite.
|
|
111
|
+
*/
|
|
112
|
+
export function withoutLeaks(
|
|
113
|
+
suite: AnySuite,
|
|
114
|
+
input: unknown,
|
|
115
|
+
sourceRef: string | null,
|
|
116
|
+
): { input: unknown; removed: string[] } {
|
|
117
|
+
if (!suite.withoutLeaks) return { input, removed: [] };
|
|
118
|
+
const out = suite.withoutLeaks(input, { sourceRef });
|
|
119
|
+
const parsed = suite.input.safeParse(out.input);
|
|
120
|
+
if (!parsed.success)
|
|
121
|
+
throw new Error(
|
|
122
|
+
`the leak check left an input that doesn't fit: ${parsed.error.issues[0]?.message ?? "invalid"}`,
|
|
123
|
+
);
|
|
124
|
+
return { input: parsed.data, removed: out.removed };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** A note line saying what a leak check removed; null when nothing. */
|
|
128
|
+
export function leakNote(removed: readonly string[]): string | null {
|
|
129
|
+
return removed.length
|
|
130
|
+
? `Removed before freezing, as learned from this case: ${removed.join("; ")}.`
|
|
131
|
+
: null;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** A date read from a row: a Date, or text Date can read; null if neither. */
|
|
135
|
+
function dateOf(v: Date | string | null | undefined): Date | null {
|
|
136
|
+
if (v === null || v === undefined || v === "") return null;
|
|
137
|
+
const d = v instanceof Date ? v : new Date(v);
|
|
138
|
+
return Number.isNaN(d.getTime()) ? null : d;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const day = (d: Date) => d.toISOString().slice(0, 10);
|
|
142
|
+
|
|
68
143
|
const sourceRefOf = (source: string, id: string) => `${source}#${id}`;
|
|
69
144
|
|
|
70
145
|
/**
|
|
@@ -77,6 +152,14 @@ const sourceRefOf = (source: string, id: string) => `${source}#${id}`;
|
|
|
77
152
|
* Splits: "DEV" for cases you tune against, "TEST" for a held-out file,
|
|
78
153
|
* "auto" (the default) for new cases, split like cases added by hand.
|
|
79
154
|
*
|
|
155
|
+
* A suite with a leak check (`withoutLeaks`) has it run on every input
|
|
156
|
+
* before it's frozen; `removed` in the result lists what it took out of
|
|
157
|
+
* each case, and the case's note says so too.
|
|
158
|
+
*
|
|
159
|
+
* Answers arrive pending unless `answers` says otherwise (see
|
|
160
|
+
* `ImportAnswers`); import them confirmed only when a person reviewed
|
|
161
|
+
* them in the old system, naming who and when on every row.
|
|
162
|
+
*
|
|
80
163
|
* Run it against your development database; an app's own guard should
|
|
81
164
|
* refuse a production one.
|
|
82
165
|
*
|
|
@@ -90,6 +173,20 @@ const sourceRefOf = (source: string, id: string) => `${source}#${id}`;
|
|
|
90
173
|
* map: (r) => ({ id: r.id, input: { body: r.text }, label: { queue: r.queue } }),
|
|
91
174
|
* split: "TEST",
|
|
92
175
|
* });
|
|
176
|
+
*
|
|
177
|
+
* // Answers people already reviewed in an old harness:
|
|
178
|
+
* await importCases({
|
|
179
|
+
* store,
|
|
180
|
+
* suite: ticketTriage,
|
|
181
|
+
* source: "old-harness",
|
|
182
|
+
* rows,
|
|
183
|
+
* map,
|
|
184
|
+
* answers: {
|
|
185
|
+
* status: "CONFIRMED",
|
|
186
|
+
* confirmedBy: (r) => r.reviewer,
|
|
187
|
+
* at: (r) => r.reviewedAt,
|
|
188
|
+
* },
|
|
189
|
+
* });
|
|
93
190
|
* ```
|
|
94
191
|
*/
|
|
95
192
|
export async function importCases<Row>(opts: {
|
|
@@ -100,15 +197,21 @@ export async function importCases<Row>(opts: {
|
|
|
100
197
|
rows: readonly Row[];
|
|
101
198
|
map: (row: Row, index: number) => ImportedCase;
|
|
102
199
|
split?: "DEV" | "TEST" | "auto";
|
|
103
|
-
answers?: ImportAnswers
|
|
200
|
+
answers?: ImportAnswers<Row>;
|
|
104
201
|
}): Promise<ImportResult> {
|
|
105
202
|
const { store, suite, source } = opts;
|
|
106
|
-
const answers = opts.answers ?? { status: "PENDING"
|
|
203
|
+
const answers: ImportAnswers<Row> = opts.answers ?? { status: "PENDING" };
|
|
204
|
+
const now = new Date();
|
|
107
205
|
|
|
108
206
|
// 1. Map and check every row before writing anything.
|
|
109
207
|
const problems: ImportProblem[] = [];
|
|
110
208
|
const seen = new Set<string>();
|
|
111
|
-
const mapped: (ImportedCase & {
|
|
209
|
+
const mapped: (ImportedCase & {
|
|
210
|
+
input: unknown;
|
|
211
|
+
label: unknown;
|
|
212
|
+
removed: string[];
|
|
213
|
+
confirmed: { by: string; at: Date } | null;
|
|
214
|
+
})[] = [];
|
|
112
215
|
opts.rows.forEach((row, i) => {
|
|
113
216
|
let c: ImportedCase;
|
|
114
217
|
try {
|
|
@@ -141,7 +244,30 @@ export async function importCases<Row>(opts: {
|
|
|
141
244
|
});
|
|
142
245
|
else label = l.data;
|
|
143
246
|
}
|
|
144
|
-
|
|
247
|
+
let confirmed: { by: string; at: Date } | null = null;
|
|
248
|
+
if (answers.status === "CONFIRMED") {
|
|
249
|
+
const by = answers.confirmedBy(row)?.trim();
|
|
250
|
+
const at = dateOf(answers.at(row));
|
|
251
|
+
if (!by)
|
|
252
|
+
problems.push({ id, problem: "no person who confirmed the answer" });
|
|
253
|
+
if (!at)
|
|
254
|
+
problems.push({ id, problem: "no date the answer was confirmed" });
|
|
255
|
+
else if (at > now)
|
|
256
|
+
problems.push({ id, problem: "a confirmation date in the future" });
|
|
257
|
+
if (by && at) confirmed = { by, at };
|
|
258
|
+
}
|
|
259
|
+
if (!input.success) return;
|
|
260
|
+
let cleaned: { input: unknown; removed: string[] };
|
|
261
|
+
try {
|
|
262
|
+
cleaned = withoutLeaks(suite, input.data, sourceRefOf(source, c.id));
|
|
263
|
+
} catch (e) {
|
|
264
|
+
problems.push({
|
|
265
|
+
id,
|
|
266
|
+
problem: e instanceof Error ? e.message : String(e),
|
|
267
|
+
});
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
mapped.push({ ...c, ...cleaned, label, confirmed });
|
|
145
271
|
});
|
|
146
272
|
if (problems.length) throw new CaseImportError(source, problems);
|
|
147
273
|
|
|
@@ -155,6 +281,7 @@ export async function importCases<Row>(opts: {
|
|
|
155
281
|
answers.status === "PROVISIONAL" ? (answers.at ?? new Date()) : null;
|
|
156
282
|
let added = 0;
|
|
157
283
|
let skipped = 0;
|
|
284
|
+
const removed: ImportLeak[] = [];
|
|
158
285
|
for (const c of mapped) {
|
|
159
286
|
const sourceRef = sourceRefOf(source, c.id);
|
|
160
287
|
if (refs.has(sourceRef)) {
|
|
@@ -168,31 +295,43 @@ export async function importCases<Row>(opts: {
|
|
|
168
295
|
: nextSplit(counts));
|
|
169
296
|
counts[split] += 1;
|
|
170
297
|
const labels: NewLabel[] = [];
|
|
171
|
-
if (c.label !== null)
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
298
|
+
if (c.label !== null) {
|
|
299
|
+
if (answers.status === "PROVISIONAL")
|
|
300
|
+
labels.push({
|
|
301
|
+
kind: "EXPECTED",
|
|
302
|
+
status: "PROVISIONAL",
|
|
303
|
+
value: c.label,
|
|
304
|
+
raterRole: "AGENT",
|
|
305
|
+
raterId: answers.rater,
|
|
306
|
+
note: `Drafted by ${answers.rater}; ${answers.allowedBy} allowed testing on it before review (${at ? day(at) : ""}).`,
|
|
307
|
+
});
|
|
308
|
+
else if (c.confirmed)
|
|
309
|
+
labels.push({
|
|
310
|
+
kind: "EXPECTED",
|
|
311
|
+
status: "CONFIRMED",
|
|
312
|
+
value: c.label,
|
|
313
|
+
raterRole: "REVIEWER",
|
|
314
|
+
raterId: c.confirmed.by,
|
|
315
|
+
note: `Imported as reviewed from ${source}: ${c.confirmed.by} confirmed it there on ${day(c.confirmed.at)}.`,
|
|
316
|
+
});
|
|
317
|
+
else
|
|
318
|
+
labels.push({
|
|
319
|
+
kind: "EXPECTED",
|
|
320
|
+
status: "PENDING",
|
|
321
|
+
value: c.label,
|
|
322
|
+
raterRole: "IMPORT",
|
|
323
|
+
raterId: null,
|
|
324
|
+
note: null,
|
|
325
|
+
});
|
|
326
|
+
}
|
|
191
327
|
const tags = [...(c.tags ?? [])];
|
|
192
328
|
if (answers.status === "PROVISIONAL" && c.label !== null) {
|
|
193
329
|
const tag = answers.tag ?? "needs-review";
|
|
194
330
|
if (!tags.includes(tag)) tags.push(tag);
|
|
195
331
|
}
|
|
332
|
+
const note = [c.note ?? null, leakNote(c.removed)]
|
|
333
|
+
.filter((n): n is string => !!n)
|
|
334
|
+
.join(" ");
|
|
196
335
|
const data: NewCase = {
|
|
197
336
|
suite: suite.key,
|
|
198
337
|
input: c.input,
|
|
@@ -200,19 +339,18 @@ export async function importCases<Row>(opts: {
|
|
|
200
339
|
split,
|
|
201
340
|
// In use only with an answer tests may grade against.
|
|
202
341
|
status:
|
|
203
|
-
c.label !== null && answers.status
|
|
204
|
-
? "ACTIVE"
|
|
205
|
-
: "DRAFT",
|
|
342
|
+
c.label !== null && answers.status !== "PENDING" ? "ACTIVE" : "DRAFT",
|
|
206
343
|
source: "IMPORT",
|
|
207
344
|
sourceRef,
|
|
208
|
-
note:
|
|
345
|
+
note: note || null,
|
|
209
346
|
labels,
|
|
210
347
|
};
|
|
211
348
|
await store.createCase(data);
|
|
212
349
|
refs.add(sourceRef);
|
|
213
350
|
added += 1;
|
|
351
|
+
if (c.removed.length) removed.push({ id: c.id, removed: c.removed });
|
|
214
352
|
}
|
|
215
|
-
return { added, skipped };
|
|
353
|
+
return { added, skipped, removed };
|
|
216
354
|
}
|
|
217
355
|
|
|
218
356
|
/** A short, stable id for a starter case: a hash of its input. */
|
|
@@ -229,7 +367,8 @@ function starterId(input: unknown): string {
|
|
|
229
367
|
/**
|
|
230
368
|
* Adds a suite's `starter` cases as drafts with pending answers, for a
|
|
231
369
|
* person to confirm on the pages. Safe to run again: starters already
|
|
232
|
-
* added (by their input) are skipped.
|
|
370
|
+
* added (by their input) are skipped. A suite's leak check runs on each,
|
|
371
|
+
* as in `importCases`.
|
|
233
372
|
*/
|
|
234
373
|
export function importStarters(
|
|
235
374
|
store: EvalStore,
|
package/src/index.ts
CHANGED
|
@@ -28,7 +28,11 @@ export * from "./weekly.js";
|
|
|
28
28
|
export * from "./settings.js";
|
|
29
29
|
export * from "./decisions.js";
|
|
30
30
|
export * from "./store.js";
|
|
31
|
+
export * from "./suiteContract.js";
|
|
32
|
+
export * from "./readCheck.js";
|
|
31
33
|
export * from "./labels.js";
|
|
34
|
+
export * from "./blind.js";
|
|
32
35
|
// Server-only (node:crypto): import from "@crowandraven/evalkeeper/runner".
|
|
33
36
|
// In-memory store for tests and demos: "@crowandraven/evalkeeper/memory".
|
|
34
37
|
export * from "./importCases.js";
|
|
38
|
+
export * from "./activity.js";
|
package/src/memoryStore.ts
CHANGED
|
@@ -195,7 +195,8 @@ export function memoryStore(): EvalStore &
|
|
|
195
195
|
const at = now();
|
|
196
196
|
const l = { ...data, id: id("label"), createdAt: at, updatedAt: at };
|
|
197
197
|
c.labels.push(l);
|
|
198
|
-
|
|
198
|
+
// A skip isn't an answer: it leaves the case as tests last saw it.
|
|
199
|
+
if (data.status !== "SKIPPED") c.updatedAt = at;
|
|
199
200
|
return l;
|
|
200
201
|
},
|
|
201
202
|
async setLabelStatus(labelId, status) {
|