@crowandraven/evalkeeper 0.7.0 → 0.9.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 (101) hide show
  1. package/README.md +9 -0
  2. package/dist/cli/addPages.d.ts +5 -0
  3. package/dist/cli/addPages.js +15 -3
  4. package/dist/cli/addPages.js.map +1 -1
  5. package/dist/decisions.js +8 -0
  6. package/dist/decisions.js.map +1 -1
  7. package/dist/feedback.d.ts +20 -3
  8. package/dist/feedback.js +16 -3
  9. package/dist/feedback.js.map +1 -1
  10. package/dist/glossary.d.ts +6 -1
  11. package/dist/glossary.js +6 -1
  12. package/dist/glossary.js.map +1 -1
  13. package/dist/importCases.d.ts +15 -4
  14. package/dist/importCases.js +20 -18
  15. package/dist/importCases.js.map +1 -1
  16. package/dist/inInstructions.d.ts +47 -0
  17. package/dist/inInstructions.js +95 -0
  18. package/dist/inInstructions.js.map +1 -0
  19. package/dist/index.d.ts +2 -0
  20. package/dist/index.js +2 -0
  21. package/dist/index.js.map +1 -1
  22. package/dist/reviews.d.ts +172 -0
  23. package/dist/reviews.js +294 -0
  24. package/dist/reviews.js.map +1 -0
  25. package/dist/runner.d.ts +9 -0
  26. package/dist/runner.js +26 -0
  27. package/dist/runner.js.map +1 -1
  28. package/dist/suiteContract.d.ts +12 -5
  29. package/dist/suiteContract.js +47 -7
  30. package/dist/suiteContract.js.map +1 -1
  31. package/dist/suites/attackImport.d.ts +99 -0
  32. package/dist/suites/attackImport.js +283 -0
  33. package/dist/suites/attackImport.js.map +1 -0
  34. package/dist/suites/crisisRisk.d.ts +9 -2
  35. package/dist/suites/crisisRisk.js +8 -3
  36. package/dist/suites/crisisRisk.js.map +1 -1
  37. package/dist/suites/crisisRiskCases.d.ts +4 -3
  38. package/dist/suites/crisisRiskCases.js +4 -3
  39. package/dist/suites/crisisRiskCases.js.map +1 -1
  40. package/dist/suites/crisisRiskReviews.d.ts +15 -0
  41. package/dist/suites/crisisRiskReviews.js +926 -0
  42. package/dist/suites/crisisRiskReviews.js.map +1 -0
  43. package/dist/suites/hopelessness.d.ts +123 -0
  44. package/dist/suites/hopelessness.js +296 -0
  45. package/dist/suites/hopelessness.js.map +1 -0
  46. package/dist/suites/hopelessnessCases.d.ts +62 -0
  47. package/dist/suites/hopelessnessCases.js +243 -0
  48. package/dist/suites/hopelessnessCases.js.map +1 -0
  49. package/dist/suites/hopelessnessReviews.d.ts +15 -0
  50. package/dist/suites/hopelessnessReviews.js +1080 -0
  51. package/dist/suites/hopelessnessReviews.js.map +1 -0
  52. package/dist/suites/index.d.ts +7 -0
  53. package/dist/suites/index.js +7 -0
  54. package/dist/suites/index.js.map +1 -1
  55. package/dist/suites/injection.d.ts +162 -0
  56. package/dist/suites/injection.js +331 -0
  57. package/dist/suites/injection.js.map +1 -0
  58. package/dist/suites/injectionAttacks.d.ts +3 -0
  59. package/dist/suites/injectionAttacks.js +34 -0
  60. package/dist/suites/injectionAttacks.js.map +1 -0
  61. package/dist/testing.d.ts +36 -2
  62. package/dist/testing.js +104 -14
  63. package/dist/testing.js.map +1 -1
  64. package/dist/types.d.ts +27 -0
  65. package/dist/types.js +11 -0
  66. package/dist/types.js.map +1 -1
  67. package/package.json +1 -1
  68. package/src/cli/addPages.ts +16 -3
  69. package/src/decisions.ts +10 -0
  70. package/src/feedback.ts +23 -3
  71. package/src/glossary.ts +11 -1
  72. package/src/importCases.ts +21 -20
  73. package/src/inInstructions.ts +105 -0
  74. package/src/index.ts +2 -0
  75. package/src/reviews.ts +428 -0
  76. package/src/runner.ts +41 -0
  77. package/src/suiteContract.ts +56 -7
  78. package/src/suites/attackImport.ts +327 -0
  79. package/src/suites/crisisRisk.ts +15 -3
  80. package/src/suites/crisisRiskCases.ts +4 -3
  81. package/src/suites/crisisRiskReviews.ts +927 -0
  82. package/src/suites/hopelessness.ts +420 -0
  83. package/src/suites/hopelessnessCases.ts +287 -0
  84. package/src/suites/hopelessnessReviews.ts +1081 -0
  85. package/src/suites/index.ts +7 -0
  86. package/src/suites/injection.ts +463 -0
  87. package/src/suites/injectionAttacks.ts +136 -0
  88. package/src/testing.ts +144 -18
  89. package/src/types.ts +30 -0
  90. package/starter/index.ts +8 -0
  91. package/templates/app/evals/[suite]/compare/page.tsx +10 -0
  92. package/templates/app/evals/[suite]/page.tsx +55 -18
  93. package/templates/app/evals/[suite]/rate/page.tsx +10 -0
  94. package/templates/app/evals/[suite]/runs/[runId]/page.tsx +72 -3
  95. package/templates/app/evals/[suite]/side-by-side/page.tsx +37 -17
  96. package/templates/app/evals/feedback/page.tsx +6 -1
  97. package/templates/app/evals/page.tsx +36 -26
  98. package/templates/components/evalkeeper/AnswerKey.tsx +25 -1
  99. package/templates/components/evalkeeper/ReadableOutput.tsx +97 -0
  100. package/templates/components/evalkeeper/SettingsHistory.tsx +10 -4
  101. package/templates/lib/evalkeeper/actions.ts +4 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inInstructions.js","sourceRoot":"","sources":["../src/inInstructions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,iFAAiF;AACjF,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAE5C,iEAAiE;AACjE,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAU5C;;;;GAIG;AACH,SAAS,OAAO,CAAC,IAAY;IAC3B,OAAO,IAAI;SACR,WAAW,EAAE;SACb,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC;SACrB,OAAO,CAAC,kBAAkB,EAAE,GAAG,CAAC;SAChC,IAAI,EAAE,CAAC;AACZ,CAAC;AAED,uDAAuD;AACvD,SAAS,SAAS,CAAC,KAAc;IAC/B,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAC1D,IAAI,KAAK,IAA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;IAC5D,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC1D,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IACvB,MAAM,KAAK,GAAyB,EAAE,CAAC;IACvC,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;QACtB,IAAI,IAAI,GAAG,EAAE,CAAC;QACd,KAAK,MAAM,GAAG,IAAI,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;YACrC,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;YAC1B,IAAI,CAAC,IAAI;gBAAE,SAAS;YACpB,MAAM,GAAG,GAAG,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;YACrC,MAAM,MAAM,GACV,GAAG,CAAC,MAAM,IAAI,QAAQ,IAAI,CAAC,GAAG,KAAK,IAAI,IAAI,GAAG,CAAC,MAAM,IAAI,QAAQ,CAAC,CAAC;YACrE,IAAI,MAAM,IAAI,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM;gBAAE,IAAI,GAAG,GAAG,CAAC;QACrD,CAAC;QACD,IAAI,IAAI;YAAE,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACtE,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
package/dist/index.d.ts CHANGED
@@ -32,5 +32,7 @@ export * from "./suiteContract.js";
32
32
  export * from "./readCheck.js";
33
33
  export * from "./labels.js";
34
34
  export * from "./blind.js";
35
+ export * from "./inInstructions.js";
35
36
  export * from "./importCases.js";
37
+ export * from "./reviews.js";
36
38
  export * from "./activity.js";
package/dist/index.js CHANGED
@@ -32,8 +32,10 @@ export * from "./suiteContract.js";
32
32
  export * from "./readCheck.js";
33
33
  export * from "./labels.js";
34
34
  export * from "./blind.js";
35
+ export * from "./inInstructions.js";
35
36
  // Server-only (node:crypto): import from "@crowandraven/evalkeeper/runner".
36
37
  // In-memory store for tests and demos: "@crowandraven/evalkeeper/memory".
37
38
  export * from "./importCases.js";
39
+ export * from "./reviews.js";
38
40
  export * from "./activity.js";
39
41
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,4EAA4E;AAC5E,0EAA0E;AAC1E,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,4EAA4E;AAC5E,0EAA0E;AAC1E,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
@@ -0,0 +1,172 @@
1
+ import type { EvalStore, NewLabel } from "./store.js";
2
+ import type { AnySuite } from "./types.js";
3
+ /**
4
+ * Reviews that ship with a suite: a person checked a starter case's answer
5
+ * once, for every app that uses the suite, so it arrives confirmed instead
6
+ * of pending. It's still a person's confirmation, never one made on their
7
+ * behalf: each review names who, when, and what qualifies them, and only
8
+ * counts for the exact input and answer they saw.
9
+ */
10
+ /**
11
+ * Who reviewed a shipped case: the suite's author ("AUTHOR"), or someone
12
+ * with experience in what the suite judges ("EXPERT"), such as a crisis
13
+ * line counselor for the crisis risk suite.
14
+ */
15
+ export type ReviewLevel = "AUTHOR" | "EXPERT";
16
+ /** The `raterRole` on an answer the suite's author reviewed. */
17
+ export declare const AUTHOR_REVIEWED = "SUITE_AUTHOR";
18
+ /** The `raterRole` on an answer an expert reviewed for the suite. */
19
+ export declare const EXPERT_REVIEWED = "SUITE_EXPERT";
20
+ /**
21
+ * The `raterRole` on an attack case's answer (see `injectionCases`),
22
+ * carried from the base case it was made from: an attack shouldn't change
23
+ * the right answer, so its confirmation is the base case's.
24
+ */
25
+ export declare const FROM_BASE_CASE = "FROM_BASE_CASE";
26
+ /**
27
+ * One person's review of one starter case, shipped with the suite. It
28
+ * counts only while the case's input and answer are what the reviewer
29
+ * saw: edit either and the case arrives pending again, and the suite
30
+ * contract fails until the review is redone or removed.
31
+ */
32
+ export type ShippedReview = {
33
+ /** The case reviewed: `starterKey` of its input. */
34
+ case: string;
35
+ /** The answer they confirmed, in the suite's answer shape. */
36
+ label: unknown;
37
+ level: ReviewLevel;
38
+ /** Who reviewed it, shown with the answer. */
39
+ by: string;
40
+ /** What qualifies them ("suite author", "crisis line counselor"). */
41
+ credential: string;
42
+ /** The day they reviewed it, as YYYY-MM-DD. */
43
+ at: string;
44
+ };
45
+ /**
46
+ * A short, stable key for a starter case: a hash of its input. Reviews
47
+ * name cases by it, and `importStarters` uses it as the case's id, so a
48
+ * rerun skips cases already added.
49
+ *
50
+ * @param input - The starter case's input.
51
+ */
52
+ export declare function starterKey(input: unknown): string;
53
+ /**
54
+ * Whether an answer's confirmation shipped with the suite (author or
55
+ * expert reviewed) rather than coming from someone in the app.
56
+ *
57
+ * @param label - The answer, or just its rater role.
58
+ */
59
+ export declare function isShippedReview(label: {
60
+ raterRole: string;
61
+ }): boolean;
62
+ /**
63
+ * What's wrong with a suite's shipped reviews, in plain sentences; empty
64
+ * when every one counts. A review that matches no starter, confirms a
65
+ * different answer than the case has now, or is missing who, what
66
+ * qualifies them, or when, is a problem: `suiteContractProblems` reports
67
+ * these so a stale review is fixed, not silently ignored.
68
+ *
69
+ * @param suite - The suite whose `reviews` to check.
70
+ * @param now - Today; reviews dated after it are a problem.
71
+ */
72
+ export declare function reviewProblems(suite: AnySuite, now?: Date): string[];
73
+ /**
74
+ * The confirmed answer a review adds to a case.
75
+ *
76
+ * @param suite - The suite the review shipped with.
77
+ * @param r - A review that counts (see `reviewProblems`).
78
+ */
79
+ export declare function reviewedLabel(suite: AnySuite, r: ShippedReview): NewLabel;
80
+ /** What adding a suite's shipped reviews did. */
81
+ export type ReviewResult = {
82
+ /** Confirmed answers added from the suite's reviews. */
83
+ reviewed: number;
84
+ /**
85
+ * Cases whose own confirmed or provisional answer, from someone in the
86
+ * app, differs from a shipped review. The app's answer stays; these are
87
+ * listed for a person to look at.
88
+ */
89
+ disagree: {
90
+ caseId: string;
91
+ review: ShippedReview;
92
+ }[];
93
+ /**
94
+ * Cases whose stored input isn't the one reviewed (the suite's leak
95
+ * check changed it when it was added), so their reviews were left out.
96
+ */
97
+ notSeen: {
98
+ caseId: string;
99
+ review: ShippedReview;
100
+ }[];
101
+ };
102
+ /**
103
+ * Adds a suite's shipped reviews to its starter cases already in the
104
+ * store, as confirmed answers. Safe to run again: a review already added
105
+ * is skipped, and one re-signed with a new answer (after the case's
106
+ * answer changed) is added as the newer confirmation. A case whose own
107
+ * confirmed or provisional answer came from someone in the app keeps it:
108
+ * the review is never added over it, and a different answer is reported
109
+ * in `disagree`. A case whose stored input isn't the one reviewed (a leak
110
+ * check changed it) gets no review and is reported in `notSeen`. Reviews
111
+ * that don't count (see `reviewProblems`) are left out. `importStarters`
112
+ * runs it.
113
+ *
114
+ * @param store - Where the suite's cases are.
115
+ * @param suite - The suite whose `reviews` to add.
116
+ * @param source - The `sourceRef` prefix starter cases were added under.
117
+ * @param now - Today; reviews dated after it are left out.
118
+ */
119
+ export declare function addShippedReviews(store: EvalStore, suite: AnySuite, source: string, now?: Date): Promise<ReviewResult>;
120
+ /** One row of a review sheet: a starter case for a reviewer to mark. */
121
+ export type ReviewSheetRow = {
122
+ /** The case: `starterKey` of its input. */
123
+ case: string;
124
+ /** The case's title, as the pages show it. */
125
+ title: string;
126
+ /** The whole input, so the reviewer sees what the model sees. */
127
+ input: string;
128
+ /** The answer to confirm, as stable JSON. */
129
+ answer: string;
130
+ };
131
+ /**
132
+ * A suite's starter cases as rows for a reviewer to mark, in the order
133
+ * the suite lists them. `reviewsFromSheet` turns the rows they confirm
134
+ * into shipped reviews.
135
+ *
136
+ * @param suite - The suite whose `starter` cases to list.
137
+ */
138
+ export declare function reviewSheet(suite: AnySuite): ReviewSheetRow[];
139
+ /** Who reviewed a sheet, for every review it makes. */
140
+ export type Reviewer = Pick<ShippedReview, "level" | "by" | "credential" | "at">;
141
+ /**
142
+ * Turns a marked review sheet into shipped reviews: one for each row the
143
+ * reviewer confirmed ("yes", "y", "ok"), of the case's answer as it is
144
+ * now. Rows left blank are left out. A row naming a case the suite
145
+ * doesn't have, marked anything else, or showing an answer other than the
146
+ * case's answer now (it changed after the sheet was made) stops it: a
147
+ * case whose answer should change is edited in the suite first, then
148
+ * reviewed again on a new sheet.
149
+ *
150
+ * @param suite - The suite the sheet was made from.
151
+ * @param rows - Each row's case, the reviewer's mark, and the answer the
152
+ * sheet showed them (from `reviewSheet`), when the sheet kept it.
153
+ * @param reviewer - Who reviewed it, what qualifies them, and when.
154
+ * @returns The reviews, in the suite's order.
155
+ * @throws When a row names an unknown case or has an unknown mark, or
156
+ * the reviewer is missing who, what qualifies them, or a date.
157
+ */
158
+ export declare function reviewsFromSheet(suite: AnySuite, rows: readonly {
159
+ case: string;
160
+ confirm: string;
161
+ answer?: string;
162
+ }[], reviewer: Reviewer): ShippedReview[];
163
+ /**
164
+ * A suite's reviews with one reviewer's replaced by a new set: everyone
165
+ * else's stay as they were, and theirs (same name and level) are swapped
166
+ * for `next`, so signing a sheet again never duplicates a review.
167
+ *
168
+ * @param existing - The reviews the suite ships now.
169
+ * @param next - The reviews from the newly signed sheet.
170
+ * @param reviewer - Whose reviews `next` replaces.
171
+ */
172
+ export declare function mergeReviews(existing: readonly ShippedReview[], next: readonly ShippedReview[], reviewer: Pick<Reviewer, "level" | "by">): ShippedReview[];
@@ -0,0 +1,294 @@
1
+ import { stableJson } from "./stableJson.js";
2
+ /** The `raterRole` on an answer the suite's author reviewed. */
3
+ export const AUTHOR_REVIEWED = "SUITE_AUTHOR";
4
+ /** The `raterRole` on an answer an expert reviewed for the suite. */
5
+ export const EXPERT_REVIEWED = "SUITE_EXPERT";
6
+ /**
7
+ * The `raterRole` on an attack case's answer (see `injectionCases`),
8
+ * carried from the base case it was made from: an attack shouldn't change
9
+ * the right answer, so its confirmation is the base case's.
10
+ */
11
+ export const FROM_BASE_CASE = "FROM_BASE_CASE";
12
+ const ROLE = {
13
+ AUTHOR: AUTHOR_REVIEWED,
14
+ EXPERT: EXPERT_REVIEWED,
15
+ };
16
+ /**
17
+ * A short, stable key for a starter case: a hash of its input. Reviews
18
+ * name cases by it, and `importStarters` uses it as the case's id, so a
19
+ * rerun skips cases already added.
20
+ *
21
+ * @param input - The starter case's input.
22
+ */
23
+ export function starterKey(input) {
24
+ // FNV-1a: the core stays free of node:crypto; this only names rows.
25
+ let h = 0x811c9dc5;
26
+ for (const ch of stableJson(input)) {
27
+ h ^= ch.charCodeAt(0);
28
+ h = Math.imul(h, 0x01000193) >>> 0;
29
+ }
30
+ return h.toString(16).padStart(8, "0");
31
+ }
32
+ /**
33
+ * Whether an answer's confirmation shipped with the suite (author or
34
+ * expert reviewed) rather than coming from someone in the app.
35
+ *
36
+ * @param label - The answer, or just its rater role.
37
+ */
38
+ export function isShippedReview(label) {
39
+ return (label.raterRole === AUTHOR_REVIEWED || label.raterRole === EXPERT_REVIEWED);
40
+ }
41
+ /** A review's day, or null when it isn't a real YYYY-MM-DD date. */
42
+ function dayOf(at) {
43
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(at))
44
+ return null;
45
+ const d = new Date(`${at}T00:00:00Z`);
46
+ return Number.isNaN(d.getTime()) || d.toISOString().slice(0, 10) !== at
47
+ ? null
48
+ : d;
49
+ }
50
+ /** The suite's answer, parsed, as stable text to compare; null if it doesn't fit. */
51
+ function answerText(suite, label) {
52
+ const parsed = suite.labelValue.safeParse(label);
53
+ return parsed.success ? stableJson(parsed.data) : null;
54
+ }
55
+ /**
56
+ * What's wrong with one review against the suite's starters, in plain
57
+ * sentences; empty when it counts.
58
+ */
59
+ function problemsOf(suite, r, answers, now) {
60
+ const out = [];
61
+ const name = `${suite.key}: the review of case ${r.case}`;
62
+ if (!answers.has(r.case))
63
+ out.push(`${name} matches no starter case; its input changed or it was removed.`);
64
+ else {
65
+ const mine = answerText(suite, r.label);
66
+ if (mine === null)
67
+ out.push(`${name} has an answer that doesn't fit the schema.`);
68
+ else if (mine !== answers.get(r.case))
69
+ out.push(`${name} confirms a different answer than the case has now.`);
70
+ }
71
+ if (!r.by.trim())
72
+ out.push(`${name} doesn't say who reviewed it.`);
73
+ if (!r.credential.trim())
74
+ out.push(`${name} doesn't say what qualifies the reviewer.`);
75
+ const day = dayOf(r.at);
76
+ if (!day)
77
+ out.push(`${name} has no date as YYYY-MM-DD.`);
78
+ // A day starts up to 14 hours before UTC's somewhere (UTC+14), so a
79
+ // review dated today counts wherever today is.
80
+ else if (+day > +now + 14 * 3_600_000)
81
+ out.push(`${name} is dated in the future.`);
82
+ return out;
83
+ }
84
+ /** Each starter's key and its input as stable text. */
85
+ function starterInputs(suite) {
86
+ return new Map((suite.starter ?? []).map((s) => [
87
+ starterKey(s.input),
88
+ stableJson(s.input),
89
+ ]));
90
+ }
91
+ /** Each starter's key and its answer as stable text. */
92
+ function starterAnswers(suite) {
93
+ return new Map((suite.starter ?? []).map((s) => [
94
+ starterKey(s.input),
95
+ answerText(suite, s.label),
96
+ ]));
97
+ }
98
+ /**
99
+ * What's wrong with a suite's shipped reviews, in plain sentences; empty
100
+ * when every one counts. A review that matches no starter, confirms a
101
+ * different answer than the case has now, or is missing who, what
102
+ * qualifies them, or when, is a problem: `suiteContractProblems` reports
103
+ * these so a stale review is fixed, not silently ignored.
104
+ *
105
+ * @param suite - The suite whose `reviews` to check.
106
+ * @param now - Today; reviews dated after it are a problem.
107
+ */
108
+ export function reviewProblems(suite, now = new Date()) {
109
+ const answers = starterAnswers(suite);
110
+ const out = [];
111
+ const seen = new Set();
112
+ for (const r of suite.reviews ?? []) {
113
+ out.push(...problemsOf(suite, r, answers, now));
114
+ const id = `${r.case}|${r.level}|${r.by.trim()}`;
115
+ if (seen.has(id))
116
+ out.push(`${suite.key}: case ${r.case} has the same ${r.level.toLowerCase()} review twice.`);
117
+ seen.add(id);
118
+ }
119
+ return out;
120
+ }
121
+ /**
122
+ * The confirmed answer a review adds to a case.
123
+ *
124
+ * @param suite - The suite the review shipped with.
125
+ * @param r - A review that counts (see `reviewProblems`).
126
+ */
127
+ export function reviewedLabel(suite, r) {
128
+ const who = r.level === "EXPERT" ? "an expert" : "the suite's author";
129
+ return {
130
+ kind: "EXPECTED",
131
+ status: "CONFIRMED",
132
+ value: suite.labelValue.parse(r.label),
133
+ raterRole: ROLE[r.level],
134
+ raterId: r.by.trim(),
135
+ note: `Reviewed by ${who} for the ${suite.label} suite: ${r.by.trim()} (${r.credential.trim()}) confirmed it on ${r.at}.`,
136
+ };
137
+ }
138
+ /** The newest answer someone in the app put to use, if any. */
139
+ function appAnswer(c) {
140
+ return [...c.labels]
141
+ .filter((l) => (l.status === "CONFIRMED" || l.status === "PROVISIONAL") &&
142
+ !isShippedReview(l))
143
+ .sort((a, b) => +b.updatedAt - +a.updatedAt)[0];
144
+ }
145
+ /**
146
+ * Adds a suite's shipped reviews to its starter cases already in the
147
+ * store, as confirmed answers. Safe to run again: a review already added
148
+ * is skipped, and one re-signed with a new answer (after the case's
149
+ * answer changed) is added as the newer confirmation. A case whose own
150
+ * confirmed or provisional answer came from someone in the app keeps it:
151
+ * the review is never added over it, and a different answer is reported
152
+ * in `disagree`. A case whose stored input isn't the one reviewed (a leak
153
+ * check changed it) gets no review and is reported in `notSeen`. Reviews
154
+ * that don't count (see `reviewProblems`) are left out. `importStarters`
155
+ * runs it.
156
+ *
157
+ * @param store - Where the suite's cases are.
158
+ * @param suite - The suite whose `reviews` to add.
159
+ * @param source - The `sourceRef` prefix starter cases were added under.
160
+ * @param now - Today; reviews dated after it are left out.
161
+ */
162
+ export async function addShippedReviews(store, suite, source, now = new Date()) {
163
+ const result = { reviewed: 0, disagree: [], notSeen: [] };
164
+ const reviews = suite.reviews ?? [];
165
+ if (!reviews.length)
166
+ return result;
167
+ const answers = starterAnswers(suite);
168
+ const inputs = starterInputs(suite);
169
+ const counting = reviews.filter((r) => problemsOf(suite, r, answers, now).length === 0);
170
+ const byRef = new Map((await store.listCases(suite.key)).map((c) => [c.sourceRef, c]));
171
+ // Reviews added in this pass, by case: a store may or may not hand back
172
+ // the same case objects, so don't rely on them updating.
173
+ const added = new Set();
174
+ for (const r of counting) {
175
+ const c = byRef.get(`${source}#${r.case}`);
176
+ if (!c)
177
+ continue;
178
+ if (stableJson(c.input) !== inputs.get(r.case)) {
179
+ result.notSeen.push({ caseId: c.id, review: r });
180
+ continue;
181
+ }
182
+ const label = reviewedLabel(suite, r);
183
+ const value = stableJson(label.value);
184
+ const id = `${c.id}|${label.raterRole}|${label.raterId ?? ""}|${value}`;
185
+ if (added.has(id) ||
186
+ c.labels.some((l) => l.raterRole === label.raterRole &&
187
+ l.raterId === label.raterId &&
188
+ stableJson(l.value) === value))
189
+ continue;
190
+ const theirs = appAnswer(c);
191
+ if (theirs) {
192
+ if (stableJson(theirs.value) !== value)
193
+ result.disagree.push({ caseId: c.id, review: r });
194
+ continue;
195
+ }
196
+ await store.addLabel(c.id, label);
197
+ added.add(id);
198
+ if (c.status === "DRAFT" && !added.has(c.id)) {
199
+ await store.setCaseStatus(c.id, "ACTIVE");
200
+ added.add(c.id);
201
+ }
202
+ result.reviewed += 1;
203
+ }
204
+ return result;
205
+ }
206
+ /**
207
+ * A suite's starter cases as rows for a reviewer to mark, in the order
208
+ * the suite lists them. `reviewsFromSheet` turns the rows they confirm
209
+ * into shipped reviews.
210
+ *
211
+ * @param suite - The suite whose `starter` cases to list.
212
+ */
213
+ export function reviewSheet(suite) {
214
+ return (suite.starter ?? []).map((s) => {
215
+ const input = suite.input.parse(s.input);
216
+ return {
217
+ case: starterKey(s.input),
218
+ title: suite.title(input),
219
+ input: suite.describe?.(input) ?? stableJson(s.input),
220
+ answer: stableJson(s.label),
221
+ };
222
+ });
223
+ }
224
+ /** Marks that confirm a row of a review sheet. */
225
+ const CONFIRMS = new Set(["y", "yes", "ok", "confirm", "confirmed"]);
226
+ /**
227
+ * Turns a marked review sheet into shipped reviews: one for each row the
228
+ * reviewer confirmed ("yes", "y", "ok"), of the case's answer as it is
229
+ * now. Rows left blank are left out. A row naming a case the suite
230
+ * doesn't have, marked anything else, or showing an answer other than the
231
+ * case's answer now (it changed after the sheet was made) stops it: a
232
+ * case whose answer should change is edited in the suite first, then
233
+ * reviewed again on a new sheet.
234
+ *
235
+ * @param suite - The suite the sheet was made from.
236
+ * @param rows - Each row's case, the reviewer's mark, and the answer the
237
+ * sheet showed them (from `reviewSheet`), when the sheet kept it.
238
+ * @param reviewer - Who reviewed it, what qualifies them, and when.
239
+ * @returns The reviews, in the suite's order.
240
+ * @throws When a row names an unknown case or has an unknown mark, or
241
+ * the reviewer is missing who, what qualifies them, or a date.
242
+ */
243
+ export function reviewsFromSheet(suite, rows, reviewer) {
244
+ const problems = [];
245
+ if (!reviewer.by.trim())
246
+ problems.push("no reviewer (--by)");
247
+ if (!reviewer.credential.trim())
248
+ problems.push("no credential (--credential)");
249
+ if (!dayOf(reviewer.at))
250
+ problems.push("no date as YYYY-MM-DD (--at)");
251
+ const starters = new Map((suite.starter ?? []).map((s) => [starterKey(s.input), s.label]));
252
+ const confirmed = new Set();
253
+ for (const r of rows) {
254
+ const mark = r.confirm.trim().toLowerCase();
255
+ if (!starters.has(r.case))
256
+ problems.push(`case ${r.case} isn't one of ${suite.key}'s starters`);
257
+ else if (CONFIRMS.has(mark) &&
258
+ r.answer !== undefined &&
259
+ r.answer.trim() !== stableJson(starters.get(r.case)))
260
+ problems.push(`case ${r.case}'s answer changed after the sheet was made; make a new sheet`);
261
+ else if (CONFIRMS.has(mark))
262
+ confirmed.add(r.case);
263
+ else if (mark)
264
+ problems.push(`case ${r.case} is marked "${r.confirm.trim()}"; mark "yes" or leave it blank`);
265
+ }
266
+ if (problems.length)
267
+ throw new Error(`The sheet can't be signed: ${problems.join("; ")}.`);
268
+ return [...starters].flatMap(([key, label]) => confirmed.has(key)
269
+ ? [
270
+ {
271
+ case: key,
272
+ label,
273
+ level: reviewer.level,
274
+ by: reviewer.by.trim(),
275
+ credential: reviewer.credential.trim(),
276
+ at: reviewer.at,
277
+ },
278
+ ]
279
+ : []);
280
+ }
281
+ /**
282
+ * A suite's reviews with one reviewer's replaced by a new set: everyone
283
+ * else's stay as they were, and theirs (same name and level) are swapped
284
+ * for `next`, so signing a sheet again never duplicates a review.
285
+ *
286
+ * @param existing - The reviews the suite ships now.
287
+ * @param next - The reviews from the newly signed sheet.
288
+ * @param reviewer - Whose reviews `next` replaces.
289
+ */
290
+ export function mergeReviews(existing, next, reviewer) {
291
+ const theirs = (r) => r.level === reviewer.level && r.by.trim() === reviewer.by.trim();
292
+ return [...existing.filter((r) => !theirs(r)), ...next];
293
+ }
294
+ //# sourceMappingURL=reviews.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reviews.js","sourceRoot":"","sources":["../src/reviews.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAmB7C,gEAAgE;AAChE,MAAM,CAAC,MAAM,eAAe,GAAG,cAAc,CAAC;AAC9C,qEAAqE;AACrE,MAAM,CAAC,MAAM,eAAe,GAAG,cAAc,CAAC;AAC9C;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,gBAAgB,CAAC;AAE/C,MAAM,IAAI,GAAgC;IACxC,MAAM,EAAE,eAAe;IACvB,MAAM,EAAE,eAAe;CACxB,CAAC;AAsBF;;;;;;GAMG;AACH,MAAM,UAAU,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E,CAAC;IACN,CAAC;IACD,IAAI,QAAQ,CAAC,MAAM;QACjB,MAAM,IAAI,KAAK,CAAC,8BAA8B,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACxE,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAC5C,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC;QAChB,CAAC,CAAC;YACE;gBACE,IAAI,EAAE,GAAG;gBACT,KAAK;gBACL,KAAK,EAAE,QAAQ,CAAC,KAAK;gBACrB,EAAE,EAAE,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE;gBACtB,UAAU,EAAE,QAAQ,CAAC,UAAU,CAAC,IAAI,EAAE;gBACtC,EAAE,EAAE,QAAQ,CAAC,EAAE;aAChB;SACF;QACH,CAAC,CAAC,EAAE,CACP,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAC1B,QAAkC,EAClC,IAA8B,EAC9B,QAAwC;IAExC,MAAM,MAAM,GAAG,CAAC,CAAgB,EAAE,EAAE,CAClC,CAAC,CAAC,KAAK,KAAK,QAAQ,CAAC,KAAK,IAAI,CAAC,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC;IACnE,OAAO,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;AAC1D,CAAC"}
package/dist/runner.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { type ModelCatalog, type ReasoningEffort } from "./models.js";
2
2
  import type { BoardRow } from "./board.js";
3
3
  import type { CaseRecord, EvalSet, EvalStore, RunRecord } from "./store.js";
4
+ import { type CaseInInstructions } from "./inInstructions.js";
4
5
  import { type ActivityDraftResult } from "./activity.js";
5
6
  import { confirmedLabel, isProvisional } from "./labels.js";
6
7
  export { confirmedLabel, isProvisional };
@@ -35,6 +36,13 @@ export type RunnerOptions = {
35
36
  * marks older tests out of date.
36
37
  */
37
38
  promptVersion: (operation: string) => string | Promise<string>;
39
+ /**
40
+ * Everything the operation's model is told, as text: system text, prompt
41
+ * templates, schema and tool descriptions (`instructionParts` in
42
+ * `@crowandraven/evalkeeper-ai-sdk`, from the parts you hash). Lets
43
+ * `casesInInstructions` warn when a case was copied into them.
44
+ */
45
+ instructionTexts?: (operation: string) => string[] | Promise<string[]>;
38
46
  /**
39
47
  * The live reasoning setting for an operation; null: the model's own.
40
48
  * Defaults to the route's, when `route` is given.
@@ -219,6 +227,7 @@ export declare function createRunner(opts: RunnerOptions): {
219
227
  disagreements: import("./compare.js").Disagreement[];
220
228
  caveats: string[];
221
229
  } | null>;
230
+ casesInInstructions: (suiteKey: string) => Promise<CaseInInstructions[]>;
222
231
  };
223
232
  /** What createRunner returns. */
224
233
  export type Runner = ReturnType<typeof createRunner>;
package/dist/runner.js CHANGED
@@ -13,6 +13,7 @@ import { pickQuickSet } from "./quickSet.js";
13
13
  import { stableJson } from "./stableJson.js";
14
14
  import { suiteMetrics } from "./stats.js";
15
15
  import { withTimeout } from "./timeout.js";
16
+ import { casesInInstructions, } from "./inInstructions.js";
16
17
  import { draftFromActivity as draftCases, } from "./activity.js";
17
18
  import { SCHEDULED } from "./weekly.js";
18
19
  import { confirmedLabel, isProvisional } from "./labels.js";
@@ -589,6 +590,30 @@ export function createRunner(opts) {
589
590
  caveats,
590
591
  };
591
592
  }
593
+ /**
594
+ * The suite's cases in use or in draft whose text appears in its
595
+ * operation's instructions (see `casesInInstructions`), for a warning on
596
+ * the suite page. Empty without `instructionTexts`.
597
+ */
598
+ async function casesInInstructionsFor(suiteKey) {
599
+ const suite = suiteOrThrow(suiteKey);
600
+ if (!opts.instructionTexts)
601
+ return [];
602
+ const [texts, cases] = await Promise.all([
603
+ opts.instructionTexts(suite.operation),
604
+ store.listCases(suite.key),
605
+ ]);
606
+ return casesInInstructions(cases
607
+ .filter((c) => c.status !== "RETIRED")
608
+ .map((c) => {
609
+ const parsed = suite.input.safeParse(c.input);
610
+ return {
611
+ id: c.id,
612
+ title: parsed.success ? suite.title(parsed.data) : "A case",
613
+ input: c.input,
614
+ };
615
+ }), texts);
616
+ }
592
617
  /**
593
618
  * The model board for one suite: every model the operation can use, with
594
619
  * its latest test on every case in use, and how it compares with the
@@ -799,6 +824,7 @@ export function createRunner(opts) {
799
824
  rescoreRecent,
800
825
  stopStuckRuns,
801
826
  compare,
827
+ casesInInstructions: casesInInstructionsFor,
802
828
  };
803
829
  }
804
830
  //# sourceMappingURL=runner.js.map