@tangle-network/agent-eval 0.120.2 → 0.120.3

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 (171) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/analyst/index.d.ts +3111 -0
  3. package/dist/analyst/index.js +403 -0
  4. package/dist/analyst/index.js.map +1 -0
  5. package/dist/authenticity/index.d.ts +161 -0
  6. package/dist/authenticity/index.js +215 -0
  7. package/dist/authenticity/index.js.map +1 -0
  8. package/dist/belief-state/index.d.ts +1301 -0
  9. package/dist/belief-state/index.js +2152 -0
  10. package/dist/belief-state/index.js.map +1 -0
  11. package/dist/benchmarks/index.d.ts +974 -0
  12. package/dist/benchmarks/index.js +60 -0
  13. package/dist/benchmarks/index.js.map +1 -0
  14. package/dist/builder-eval/index.d.ts +695 -0
  15. package/dist/builder-eval/index.js +366 -0
  16. package/dist/builder-eval/index.js.map +1 -0
  17. package/dist/campaign/index.d.ts +7454 -0
  18. package/dist/campaign/index.js +272 -0
  19. package/dist/campaign/index.js.map +1 -0
  20. package/dist/chunk-3CDFMEMO.js +3878 -0
  21. package/dist/chunk-3CDFMEMO.js.map +1 -0
  22. package/dist/chunk-3RF76KTD.js +84 -0
  23. package/dist/chunk-3RF76KTD.js.map +1 -0
  24. package/dist/chunk-3XH4Y2SS.js +750 -0
  25. package/dist/chunk-3XH4Y2SS.js.map +1 -0
  26. package/dist/chunk-3YYRZDON.js +45 -0
  27. package/dist/chunk-3YYRZDON.js.map +1 -0
  28. package/dist/chunk-5BYTIDZ7.js +550 -0
  29. package/dist/chunk-5BYTIDZ7.js.map +1 -0
  30. package/dist/chunk-5CVUPHJ4.js +2668 -0
  31. package/dist/chunk-5CVUPHJ4.js.map +1 -0
  32. package/dist/chunk-ARU2PZFM.js +312 -0
  33. package/dist/chunk-ARU2PZFM.js.map +1 -0
  34. package/dist/chunk-BOD4O7OF.js +40 -0
  35. package/dist/chunk-BOD4O7OF.js.map +1 -0
  36. package/dist/chunk-CVJP5TMD.js +766 -0
  37. package/dist/chunk-CVJP5TMD.js.map +1 -0
  38. package/dist/chunk-DPZAEKA6.js +880 -0
  39. package/dist/chunk-DPZAEKA6.js.map +1 -0
  40. package/dist/chunk-DTJ6QUQB.js +131 -0
  41. package/dist/chunk-DTJ6QUQB.js.map +1 -0
  42. package/dist/chunk-GGE4NNQT.js +65 -0
  43. package/dist/chunk-GGE4NNQT.js.map +1 -0
  44. package/dist/chunk-H5UD2323.js +286 -0
  45. package/dist/chunk-H5UD2323.js.map +1 -0
  46. package/dist/chunk-HHWE3POT.js +94 -0
  47. package/dist/chunk-HHWE3POT.js.map +1 -0
  48. package/dist/chunk-HKUCJ437.js +787 -0
  49. package/dist/chunk-HKUCJ437.js.map +1 -0
  50. package/dist/chunk-JHCHEVET.js +274 -0
  51. package/dist/chunk-JHCHEVET.js.map +1 -0
  52. package/dist/chunk-K4DBDHLK.js +158 -0
  53. package/dist/chunk-K4DBDHLK.js.map +1 -0
  54. package/dist/chunk-K6N6XJJX.js +306 -0
  55. package/dist/chunk-K6N6XJJX.js.map +1 -0
  56. package/dist/chunk-MA6HLL3S.js +65 -0
  57. package/dist/chunk-MA6HLL3S.js.map +1 -0
  58. package/dist/chunk-MAZ26DC7.js +99 -0
  59. package/dist/chunk-MAZ26DC7.js.map +1 -0
  60. package/dist/chunk-MOXWMGPC.js +577 -0
  61. package/dist/chunk-MOXWMGPC.js.map +1 -0
  62. package/dist/chunk-NJC7U437.js +626 -0
  63. package/dist/chunk-NJC7U437.js.map +1 -0
  64. package/dist/chunk-NMN4WGSJ.js +1030 -0
  65. package/dist/chunk-NMN4WGSJ.js.map +1 -0
  66. package/dist/chunk-NPCTHQIO.js +91 -0
  67. package/dist/chunk-NPCTHQIO.js.map +1 -0
  68. package/dist/chunk-ONWEPEDO.js +57 -0
  69. package/dist/chunk-ONWEPEDO.js.map +1 -0
  70. package/dist/chunk-OYZAPX5G.js +1526 -0
  71. package/dist/chunk-OYZAPX5G.js.map +1 -0
  72. package/dist/chunk-P5MGQ2FY.js +7958 -0
  73. package/dist/chunk-P5MGQ2FY.js.map +1 -0
  74. package/dist/chunk-PC4UYEBM.js +166 -0
  75. package/dist/chunk-PC4UYEBM.js.map +1 -0
  76. package/dist/chunk-PJQFMIOX.js +1182 -0
  77. package/dist/chunk-PJQFMIOX.js.map +1 -0
  78. package/dist/chunk-PXD6ZFNY.js +1107 -0
  79. package/dist/chunk-PXD6ZFNY.js.map +1 -0
  80. package/dist/chunk-PXE2VKMX.js +140 -0
  81. package/dist/chunk-PXE2VKMX.js.map +1 -0
  82. package/dist/chunk-PZ5AY32C.js +10 -0
  83. package/dist/chunk-PZ5AY32C.js.map +1 -0
  84. package/dist/chunk-QBRSJK47.js +622 -0
  85. package/dist/chunk-QBRSJK47.js.map +1 -0
  86. package/dist/chunk-S3UZOQ5Y.js +328 -0
  87. package/dist/chunk-S3UZOQ5Y.js.map +1 -0
  88. package/dist/chunk-SQQED7ZH.js +998 -0
  89. package/dist/chunk-SQQED7ZH.js.map +1 -0
  90. package/dist/chunk-SYV364BL.js +1266 -0
  91. package/dist/chunk-SYV364BL.js.map +1 -0
  92. package/dist/chunk-T4SQEITX.js +95 -0
  93. package/dist/chunk-T4SQEITX.js.map +1 -0
  94. package/dist/chunk-TT4KNT67.js +124 -0
  95. package/dist/chunk-TT4KNT67.js.map +1 -0
  96. package/dist/chunk-U5CHZ5M3.js +357 -0
  97. package/dist/chunk-U5CHZ5M3.js.map +1 -0
  98. package/dist/chunk-ULOKLHIQ.js +1937 -0
  99. package/dist/chunk-ULOKLHIQ.js.map +1 -0
  100. package/dist/chunk-VI2UW6B6.js +162 -0
  101. package/dist/chunk-VI2UW6B6.js.map +1 -0
  102. package/dist/chunk-VQMK5FMP.js +247 -0
  103. package/dist/chunk-VQMK5FMP.js.map +1 -0
  104. package/dist/chunk-VSMTAMNK.js +53 -0
  105. package/dist/chunk-VSMTAMNK.js.map +1 -0
  106. package/dist/chunk-VZSRQ272.js +149 -0
  107. package/dist/chunk-VZSRQ272.js.map +1 -0
  108. package/dist/chunk-WW2A73HW.js +159 -0
  109. package/dist/chunk-WW2A73HW.js.map +1 -0
  110. package/dist/chunk-X4UCIOTZ.js +136 -0
  111. package/dist/chunk-X4UCIOTZ.js.map +1 -0
  112. package/dist/chunk-XJYR7XFV.js +317 -0
  113. package/dist/chunk-XJYR7XFV.js.map +1 -0
  114. package/dist/chunk-ZET2UAYW.js +89 -0
  115. package/dist/chunk-ZET2UAYW.js.map +1 -0
  116. package/dist/chunk-ZMXDQ4K7.js +870 -0
  117. package/dist/chunk-ZMXDQ4K7.js.map +1 -0
  118. package/dist/chunk-ZZUXHH3R.js +99 -0
  119. package/dist/chunk-ZZUXHH3R.js.map +1 -0
  120. package/dist/cli.d.ts +1 -0
  121. package/dist/cli.js +112 -0
  122. package/dist/cli.js.map +1 -0
  123. package/dist/contract/index.d.ts +4972 -0
  124. package/dist/contract/index.js +1654 -0
  125. package/dist/contract/index.js.map +1 -0
  126. package/dist/control.d.ts +1013 -0
  127. package/dist/control.js +34 -0
  128. package/dist/control.js.map +1 -0
  129. package/dist/fuzz.d.ts +759 -0
  130. package/dist/fuzz.js +714 -0
  131. package/dist/fuzz.js.map +1 -0
  132. package/dist/hosted/index.d.ts +730 -0
  133. package/dist/hosted/index.js +14 -0
  134. package/dist/hosted/index.js.map +1 -0
  135. package/dist/index.d.ts +16780 -0
  136. package/dist/index.js +12168 -0
  137. package/dist/index.js.map +1 -0
  138. package/dist/matrix/index.d.ts +155 -0
  139. package/dist/matrix/index.js +8 -0
  140. package/dist/matrix/index.js.map +1 -0
  141. package/dist/meta-eval/index.d.ts +1030 -0
  142. package/dist/meta-eval/index.js +417 -0
  143. package/dist/meta-eval/index.js.map +1 -0
  144. package/dist/multishot/index.d.ts +579 -0
  145. package/dist/multishot/index.js +589 -0
  146. package/dist/multishot/index.js.map +1 -0
  147. package/dist/openapi.json +992 -0
  148. package/dist/pipelines/index.d.ts +567 -0
  149. package/dist/pipelines/index.js +515 -0
  150. package/dist/pipelines/index.js.map +1 -0
  151. package/dist/reporting.d.ts +1277 -0
  152. package/dist/reporting.js +48 -0
  153. package/dist/reporting.js.map +1 -0
  154. package/dist/rl.d.ts +4092 -0
  155. package/dist/rl.js +1724 -0
  156. package/dist/rl.js.map +1 -0
  157. package/dist/run-campaign-75RTPVV5.js +14 -0
  158. package/dist/run-campaign-75RTPVV5.js.map +1 -0
  159. package/dist/storyboard/index.d.ts +279 -0
  160. package/dist/storyboard/index.js +767 -0
  161. package/dist/storyboard/index.js.map +1 -0
  162. package/dist/trace-attributes.d.ts +52 -0
  163. package/dist/trace-attributes.js +62 -0
  164. package/dist/trace-attributes.js.map +1 -0
  165. package/dist/traces.d.ts +2343 -0
  166. package/dist/traces.js +249 -0
  167. package/dist/traces.js.map +1 -0
  168. package/dist/wire/index.d.ts +1252 -0
  169. package/dist/wire/index.js +81 -0
  170. package/dist/wire/index.js.map +1 -0
  171. package/package.json +1 -1
@@ -0,0 +1,417 @@
1
+ import {
2
+ calibrationCurve,
3
+ calibrationFromPairs
4
+ } from "../chunk-NPCTHQIO.js";
5
+ import {
6
+ analyzeSeries
7
+ } from "../chunk-BOD4O7OF.js";
8
+ import {
9
+ FileSystemOutcomeStore,
10
+ InMemoryOutcomeStore
11
+ } from "../chunk-3RF76KTD.js";
12
+ import {
13
+ rubricPredictiveValidity
14
+ } from "../chunk-X4UCIOTZ.js";
15
+ import {
16
+ pearsonR,
17
+ spearmanR
18
+ } from "../chunk-PJQFMIOX.js";
19
+ import {
20
+ aggregateLlm,
21
+ llmSpans
22
+ } from "../chunk-ZET2UAYW.js";
23
+ import "../chunk-MA6HLL3S.js";
24
+ import {
25
+ ValidationError
26
+ } from "../chunk-ONWEPEDO.js";
27
+ import "../chunk-PZ5AY32C.js";
28
+
29
+ // src/meta-eval/correlation-study.ts
30
+ async function correlationStudy(traceStore, outcomeStore, evalMetrics, outcomeMetricNames, options = {}) {
31
+ const runs = await traceStore.listRuns();
32
+ const outcomes = await outcomeStore.list(options.outcomeFilter);
33
+ const outcomesByRun = /* @__PURE__ */ new Map();
34
+ for (const o of outcomes) {
35
+ const arr = outcomesByRun.get(o.runId) ?? [];
36
+ arr.push(o);
37
+ outcomesByRun.set(o.runId, arr);
38
+ }
39
+ const reduction = options.reduction ?? "latest";
40
+ const maxLag = options.maxCaptureLagMs ?? Infinity;
41
+ const pairs = [];
42
+ for (const em of evalMetrics) {
43
+ for (const om of outcomeMetricNames) {
44
+ pairs.push({ evalMetric: em.id, outcomeMetric: om, xs: [], ys: [] });
45
+ }
46
+ }
47
+ let joined = 0;
48
+ let skipped = 0;
49
+ for (const run of runs) {
50
+ const os = outcomesByRun.get(run.runId);
51
+ if (!os || os.length === 0) {
52
+ skipped++;
53
+ continue;
54
+ }
55
+ const eligible = os.filter((o) => o.capturedAt - run.startedAt <= maxLag);
56
+ if (eligible.length === 0) {
57
+ skipped++;
58
+ continue;
59
+ }
60
+ for (const em of evalMetrics) {
61
+ const extract = em.extract ?? defaultExtract(em.id);
62
+ const x = await extract(run, traceStore);
63
+ if (x === null || !Number.isFinite(x)) continue;
64
+ for (const om of outcomeMetricNames) {
65
+ const values = eligible.map((o) => o.metrics[om]).filter((v) => typeof v === "number" && Number.isFinite(v));
66
+ if (values.length === 0) continue;
67
+ const y = reduce(values, reduction, eligible);
68
+ if (y === null) continue;
69
+ const pair = pairs.find((p) => p.evalMetric === em.id && p.outcomeMetric === om);
70
+ pair.xs.push(x);
71
+ pair.ys.push(y);
72
+ }
73
+ }
74
+ joined++;
75
+ }
76
+ const results = pairs.filter((p) => p.xs.length >= 3).map((p) => {
77
+ const pearson = pearsonR(p.xs, p.ys);
78
+ const spearman = spearmanR(p.xs, p.ys);
79
+ const pearsonCi95 = bootstrapPearsonCi(p.xs, p.ys, options.bootstrapIterations ?? 500);
80
+ const verdict = Math.abs(pearson) >= 0.7 ? "strong" : Math.abs(pearson) >= 0.4 ? "moderate" : "weak";
81
+ return {
82
+ evalMetric: p.evalMetric,
83
+ outcomeMetric: p.outcomeMetric,
84
+ n: p.xs.length,
85
+ pearson,
86
+ spearman,
87
+ pearsonCi95,
88
+ verdict
89
+ };
90
+ });
91
+ return { pairs: results, joinedSamples: joined, skippedRuns: skipped };
92
+ }
93
+ function reduce(values, kind, outcomes) {
94
+ if (values.length === 0) return null;
95
+ if (kind === "mean") return values.reduce((a, b) => a + b, 0) / values.length;
96
+ if (kind === "max") return Math.max(...values);
97
+ const latest = [...outcomes].sort((a, b) => b.capturedAt - a.capturedAt)[0];
98
+ if (!latest) return null;
99
+ const latestKey = Object.keys(latest.metrics)[0];
100
+ const v = latestKey !== void 0 ? latest.metrics[latestKey] : void 0;
101
+ const paired = outcomes.map((o) => {
102
+ const k = Object.keys(o.metrics)[0];
103
+ return {
104
+ at: o.capturedAt,
105
+ v: k !== void 0 ? values.find((x) => o.metrics[k] === x) : void 0
106
+ };
107
+ }).filter((p) => p.v !== void 0);
108
+ if (paired.length === 0) return v ?? null;
109
+ return paired.sort((a, b) => b.at - a.at)[0]?.v ?? null;
110
+ }
111
+ function bootstrapPearsonCi(xs, ys, iterations) {
112
+ const n = xs.length;
113
+ if (n < 3) return { lower: NaN, upper: NaN };
114
+ const rs = [];
115
+ for (let b = 0; b < iterations; b++) {
116
+ const rx = new Array(n);
117
+ const ry = new Array(n);
118
+ for (let i = 0; i < n; i++) {
119
+ const idx = Math.floor(Math.random() * n);
120
+ rx[i] = xs[idx];
121
+ ry[i] = ys[idx];
122
+ }
123
+ const r = pearsonR(rx, ry);
124
+ if (Number.isFinite(r)) rs.push(r);
125
+ }
126
+ rs.sort((a, b) => a - b);
127
+ if (rs.length === 0) return { lower: NaN, upper: NaN };
128
+ return {
129
+ lower: rs[Math.floor(0.025 * rs.length)],
130
+ upper: rs[Math.min(rs.length - 1, Math.floor(0.975 * rs.length))]
131
+ };
132
+ }
133
+ function defaultExtract(metric) {
134
+ return async (run, store) => {
135
+ switch (metric) {
136
+ case "score":
137
+ case "overallScore":
138
+ return run.outcome?.score ?? null;
139
+ case "pass":
140
+ return run.outcome?.pass === true ? 1 : 0;
141
+ case "durationMs":
142
+ return run.endedAt && run.startedAt ? run.endedAt - run.startedAt : null;
143
+ case "costUsd": {
144
+ const llm = await llmSpans(store, run.runId);
145
+ return aggregateLlm(llm).costUsd;
146
+ }
147
+ case "inputTokens": {
148
+ const llm = await llmSpans(store, run.runId);
149
+ return aggregateLlm(llm).inputTokens;
150
+ }
151
+ default:
152
+ return null;
153
+ }
154
+ };
155
+ }
156
+
157
+ // src/meta-eval/sentinel.ts
158
+ var SENTINEL_METRIC_NAMES = ["irr", "calibrationKappa", "sentinelPassRate"];
159
+ function parseIso(value, label) {
160
+ const ms = typeof value === "string" ? Date.parse(value) : NaN;
161
+ if (!Number.isFinite(ms)) {
162
+ throw new ValidationError(
163
+ `judge-sentinel: ${label} is not a parseable ISO timestamp: ${JSON.stringify(value)}`
164
+ );
165
+ }
166
+ return ms;
167
+ }
168
+ function validateSentinelSnapshot(snapshot, source = "snapshot") {
169
+ parseIso(snapshot.at, `${source}.at`);
170
+ if (typeof snapshot.judgeId !== "string" || snapshot.judgeId.length === 0) {
171
+ throw new ValidationError(`judge-sentinel: ${source}.judgeId must be a non-empty string`);
172
+ }
173
+ if (typeof snapshot.judgeModel !== "string" || snapshot.judgeModel.length === 0) {
174
+ throw new ValidationError(`judge-sentinel: ${source}.judgeModel must be a non-empty string`);
175
+ }
176
+ if (snapshot.metrics === null || typeof snapshot.metrics !== "object") {
177
+ throw new ValidationError(`judge-sentinel: ${source}.metrics must be an object (may be empty)`);
178
+ }
179
+ for (const [key, value] of Object.entries(snapshot.metrics)) {
180
+ if (!SENTINEL_METRIC_NAMES.includes(key)) {
181
+ throw new ValidationError(
182
+ `judge-sentinel: ${source}.metrics carries unknown key "${key}" \u2014 known: ${SENTINEL_METRIC_NAMES.join(", ")}`
183
+ );
184
+ }
185
+ if (value !== void 0 && !Number.isFinite(value)) {
186
+ throw new ValidationError(
187
+ `judge-sentinel: ${source}.metrics.${key} is not a finite number: ${String(value)}`
188
+ );
189
+ }
190
+ }
191
+ }
192
+ function snapshotFromCalibration(report, meta) {
193
+ const kappa = "weightedKappaContinuous" in report ? report.weightedKappaContinuous : report.kappa;
194
+ if (!Number.isFinite(kappa)) {
195
+ throw new ValidationError(
196
+ `snapshotFromCalibration: \u03BA is not finite (n=${report.n}) \u2014 calibrate against \u22652 joined golden items before snapshotting`
197
+ );
198
+ }
199
+ const snapshot = { ...meta, metrics: { calibrationKappa: kappa } };
200
+ validateSentinelSnapshot(snapshot);
201
+ return snapshot;
202
+ }
203
+ function snapshotFromAgreement(report, meta) {
204
+ const irr = "overallIcc" in report ? report.overallIcc : report.icc;
205
+ if (!Number.isFinite(irr)) {
206
+ throw new ValidationError(
207
+ "snapshotFromAgreement: ICC is not finite \u2014 agreement needs \u22652 raters and \u22652 complete items"
208
+ );
209
+ }
210
+ const snapshot = { ...meta, metrics: { irr } };
211
+ validateSentinelSnapshot(snapshot);
212
+ return snapshot;
213
+ }
214
+ function snapshotFromSentinelSet(scores, golden, meta, options = {}) {
215
+ const tolerance = options.tolerance ?? 0.1;
216
+ if (!Number.isFinite(tolerance) || tolerance < 0) {
217
+ throw new ValidationError(
218
+ `snapshotFromSentinelSet: tolerance must be a finite number \u2265 0, got ${tolerance}`
219
+ );
220
+ }
221
+ const goldenById = /* @__PURE__ */ new Map();
222
+ for (const item of golden) {
223
+ if (!Number.isFinite(item.humanScore)) {
224
+ throw new ValidationError(
225
+ `snapshotFromSentinelSet: golden item "${item.itemId}" has a non-finite humanScore`
226
+ );
227
+ }
228
+ if (goldenById.has(item.itemId)) {
229
+ throw new ValidationError(`snapshotFromSentinelSet: duplicate golden itemId "${item.itemId}"`);
230
+ }
231
+ goldenById.set(item.itemId, item.humanScore);
232
+ }
233
+ let joined = 0;
234
+ let passed = 0;
235
+ for (const s of scores) {
236
+ const human = goldenById.get(s.itemId);
237
+ if (human === void 0) continue;
238
+ if (!Number.isFinite(s.score)) {
239
+ throw new ValidationError(
240
+ `snapshotFromSentinelSet: judge score for item "${s.itemId}" is not finite`
241
+ );
242
+ }
243
+ joined++;
244
+ if (Math.abs(s.score - human) <= tolerance) passed++;
245
+ }
246
+ if (joined === 0) {
247
+ throw new ValidationError(
248
+ "snapshotFromSentinelSet: no judge scores joined the golden set \u2014 itemIds mismatch or empty sentinel run"
249
+ );
250
+ }
251
+ const snapshot = { ...meta, metrics: { sentinelPassRate: passed / joined } };
252
+ validateSentinelSnapshot(snapshot);
253
+ return snapshot;
254
+ }
255
+ function inMemorySentinelStore(initial = []) {
256
+ for (const s of initial) validateSentinelSnapshot(s);
257
+ const items = initial.map((s) => ({ ...s, metrics: { ...s.metrics } }));
258
+ return {
259
+ async append(snapshot) {
260
+ validateSentinelSnapshot(snapshot);
261
+ items.push({ ...snapshot, metrics: { ...snapshot.metrics } });
262
+ },
263
+ async history(judgeId) {
264
+ const all = items.map((s) => ({ ...s, metrics: { ...s.metrics } }));
265
+ return judgeId === void 0 ? all : all.filter((s) => s.judgeId === judgeId);
266
+ }
267
+ };
268
+ }
269
+ function fileSentinelStore(path) {
270
+ return {
271
+ async append(snapshot) {
272
+ validateSentinelSnapshot(snapshot);
273
+ const fs = await import("fs/promises");
274
+ const pathMod = await import("path");
275
+ await fs.mkdir(pathMod.dirname(path), { recursive: true });
276
+ await fs.appendFile(path, `${JSON.stringify(snapshot)}
277
+ `, "utf8");
278
+ },
279
+ async history(judgeId) {
280
+ const fs = await import("fs/promises");
281
+ let raw;
282
+ try {
283
+ raw = await fs.readFile(path, "utf8");
284
+ } catch (err) {
285
+ if (err.code === "ENOENT") return [];
286
+ throw err;
287
+ }
288
+ const lines = raw.split("\n");
289
+ const snapshots = [];
290
+ for (let i = 0; i < lines.length; i++) {
291
+ const line = lines[i];
292
+ if (line.trim().length === 0) continue;
293
+ let parsed;
294
+ try {
295
+ parsed = JSON.parse(line);
296
+ } catch (err) {
297
+ throw new ValidationError(
298
+ `judge-sentinel: store at ${path} has a corrupt JSONL line ${i + 1}: ${err.message}`
299
+ );
300
+ }
301
+ const snapshot = parsed;
302
+ validateSentinelSnapshot(snapshot, `${path}:${i + 1}`);
303
+ snapshots.push(snapshot);
304
+ }
305
+ return judgeId === void 0 ? snapshots : snapshots.filter((s) => s.judgeId === judgeId);
306
+ }
307
+ };
308
+ }
309
+ var MS_PER_DAY = 864e5;
310
+ function judgeSentinelReport(history, opts) {
311
+ const asOfMs = parseIso(opts.asOf, "asOf");
312
+ const minIrr = opts.thresholds?.minIrr ?? 0.6;
313
+ const maxKappaDrop = opts.thresholds?.maxKappaDrop ?? 0.15;
314
+ const maxSentinelDrop = opts.thresholds?.maxSentinelDrop ?? 0.1;
315
+ const staleAfterDays = opts.thresholds?.staleAfterDays ?? 30;
316
+ const byJudge = /* @__PURE__ */ new Map();
317
+ for (const snapshot of history) {
318
+ validateSentinelSnapshot(snapshot);
319
+ const atMs = parseIso(snapshot.at, `snapshot.at (judge "${snapshot.judgeId}")`);
320
+ const arr = byJudge.get(snapshot.judgeId) ?? [];
321
+ arr.push({ ...snapshot, atMs });
322
+ byJudge.set(snapshot.judgeId, arr);
323
+ }
324
+ const perJudge = [];
325
+ const alarms = [];
326
+ const insufficientHistory = [];
327
+ for (const judgeId of [...byJudge.keys()].sort()) {
328
+ const snaps = byJudge.get(judgeId).sort((a, b) => a.atMs - b.atMs);
329
+ const newest = snaps[snaps.length - 1];
330
+ const ageDays = (asOfMs - newest.atMs) / MS_PER_DAY;
331
+ if (ageDays > staleAfterDays) {
332
+ alarms.push(
333
+ `judge "${judgeId}": stale \u2014 newest snapshot ${newest.at} is ${ageDays.toFixed(1)}d old vs asOf (limit ${staleAfterDays}d)`
334
+ );
335
+ }
336
+ let changeIdx = -1;
337
+ for (let i = 1; i < snaps.length; i++) {
338
+ if (snaps[i].judgeModel !== snaps[i - 1].judgeModel) changeIdx = i;
339
+ }
340
+ if (changeIdx >= 0) {
341
+ const recalibrated = snaps.slice(changeIdx).some(
342
+ (s) => Number.isFinite(s.metrics.calibrationKappa) || Number.isFinite(s.metrics.sentinelPassRate)
343
+ );
344
+ if (!recalibrated) {
345
+ alarms.push(
346
+ `judge "${judgeId}": model changed "${snaps[changeIdx - 1].judgeModel}" \u2192 "${snaps[changeIdx].judgeModel}" at ${snaps[changeIdx].at} with no post-change calibration snapshot \u2014 silent-upgrade trap; rerun calibrateJudge or the sentinel set against the new model`
347
+ );
348
+ }
349
+ }
350
+ for (const metric of SENTINEL_METRIC_NAMES) {
351
+ const values = snaps.filter((s) => typeof s.metrics[metric] === "number").map((s) => s.metrics[metric]);
352
+ if (values.length === 0) continue;
353
+ const convergence = analyzeSeries(values, opts.convergence);
354
+ if (convergence.state === "insufficient-data")
355
+ insufficientHistory.push(`${judgeId}:${metric}`);
356
+ const current = values[values.length - 1];
357
+ const baseline = values[0];
358
+ const drift = current - baseline;
359
+ const reasons = [];
360
+ if (convergence.state === "drifting-down") {
361
+ reasons.push(
362
+ `convergence state drifting-down (tail run ${convergence.tailRun}, window mean ${convergence.windowMean.toFixed(3)})`
363
+ );
364
+ }
365
+ if (metric === "irr" && current < minIrr) {
366
+ reasons.push(`irr ${current.toFixed(3)} below floor ${minIrr}`);
367
+ }
368
+ if (metric === "calibrationKappa" && baseline - current > maxKappaDrop) {
369
+ reasons.push(
370
+ `calibrationKappa dropped ${(baseline - current).toFixed(3)} from baseline ${baseline.toFixed(3)} (limit ${maxKappaDrop})`
371
+ );
372
+ }
373
+ if (metric === "sentinelPassRate" && baseline - current > maxSentinelDrop) {
374
+ reasons.push(
375
+ `sentinelPassRate dropped ${(baseline - current).toFixed(3)} from baseline ${baseline.toFixed(3)} (limit ${maxSentinelDrop})`
376
+ );
377
+ }
378
+ const alarmed = reasons.length > 0;
379
+ const trend = {
380
+ judgeId,
381
+ metric,
382
+ state: convergence.state,
383
+ current,
384
+ baseline,
385
+ drift,
386
+ alarmed
387
+ };
388
+ if (alarmed) {
389
+ trend.reason = reasons.join("; ");
390
+ alarms.push(`judge "${judgeId}" ${metric}: ${trend.reason}`);
391
+ }
392
+ perJudge.push(trend);
393
+ }
394
+ }
395
+ return { perJudge, alarms, healthy: alarms.length === 0, insufficientHistory };
396
+ }
397
+ function evalHealthStamp(report) {
398
+ return { healthy: report.healthy, alarms: [...report.alarms] };
399
+ }
400
+ export {
401
+ FileSystemOutcomeStore,
402
+ InMemoryOutcomeStore,
403
+ SENTINEL_METRIC_NAMES,
404
+ calibrationCurve,
405
+ calibrationFromPairs,
406
+ correlationStudy,
407
+ evalHealthStamp,
408
+ fileSentinelStore,
409
+ inMemorySentinelStore,
410
+ judgeSentinelReport,
411
+ rubricPredictiveValidity,
412
+ snapshotFromAgreement,
413
+ snapshotFromCalibration,
414
+ snapshotFromSentinelSet,
415
+ validateSentinelSnapshot
416
+ };
417
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/meta-eval/correlation-study.ts","../../src/meta-eval/sentinel.ts"],"sourcesContent":["/**\n * Correlation study — \"does our eval score predict real-world outcomes?\"\n *\n * This is the load-bearing signal. Takes a TraceStore + OutcomeStore,\n * joins on runId, computes Pearson + Spearman + bootstrap CI for every\n * (evalMetric, outcomeMetric) pair the caller declares.\n *\n * Without this number the framework is ornamental. With it and r > 0.6\n * the framework is a moat — no other agent-eval tool publishes one.\n */\n\nimport { pearsonR, spearmanR } from '../statistics'\nimport { aggregateLlm, llmSpans } from '../trace/query'\nimport type { Run } from '../trace/schema'\nimport type { TraceStore } from '../trace/store'\nimport type { DeploymentOutcome, OutcomeFilter, OutcomeStore } from './outcome-store'\n\nexport interface EvalMetricSpec {\n id: string\n /** Extract a scalar from a run (defaults cover score/pass/durationMs/costUsd/tokens). */\n extract?: (run: Run, store: TraceStore) => Promise<number | null>\n}\n\nexport interface OutcomePair {\n evalMetric: string\n outcomeMetric: string\n}\n\nexport interface CorrelationResult {\n evalMetric: string\n outcomeMetric: string\n n: number\n pearson: number\n spearman: number\n /** 95% bootstrap CI for Pearson. */\n pearsonCi95: { lower: number; upper: number }\n /** Rough verdict: 'strong' ≥ 0.7, 'moderate' ≥ 0.4, else 'weak'. */\n verdict: 'strong' | 'moderate' | 'weak'\n}\n\nexport interface CorrelationStudyResult {\n pairs: CorrelationResult[]\n joinedSamples: number\n skippedRuns: number\n}\n\nexport interface CorrelationStudyOptions {\n /** Only join outcomes captured within this window after run.startedAt. */\n maxCaptureLagMs?: number\n /** Restrict to a subset of outcomes (cohort, region, source). */\n outcomeFilter?: OutcomeFilter\n /** Which outcome per run to use when multiple exist. Default 'latest'. */\n reduction?: 'latest' | 'mean' | 'max'\n /** Bootstrap iterations for the CI. Default 500. */\n bootstrapIterations?: number\n}\n\nexport async function correlationStudy(\n traceStore: TraceStore,\n outcomeStore: OutcomeStore,\n evalMetrics: EvalMetricSpec[],\n outcomeMetricNames: string[],\n options: CorrelationStudyOptions = {},\n): Promise<CorrelationStudyResult> {\n const runs = await traceStore.listRuns()\n const outcomes = await outcomeStore.list(options.outcomeFilter)\n const outcomesByRun = new Map<string, DeploymentOutcome[]>()\n for (const o of outcomes) {\n const arr = outcomesByRun.get(o.runId) ?? []\n arr.push(o)\n outcomesByRun.set(o.runId, arr)\n }\n\n const reduction = options.reduction ?? 'latest'\n const maxLag = options.maxCaptureLagMs ?? Infinity\n\n const pairs: Array<{ evalMetric: string; outcomeMetric: string; xs: number[]; ys: number[] }> = []\n for (const em of evalMetrics) {\n for (const om of outcomeMetricNames) {\n pairs.push({ evalMetric: em.id, outcomeMetric: om, xs: [], ys: [] })\n }\n }\n\n let joined = 0\n let skipped = 0\n for (const run of runs) {\n const os = outcomesByRun.get(run.runId)\n if (!os || os.length === 0) {\n skipped++\n continue\n }\n const eligible = os.filter((o) => o.capturedAt - run.startedAt <= maxLag)\n if (eligible.length === 0) {\n skipped++\n continue\n }\n\n for (const em of evalMetrics) {\n const extract = em.extract ?? defaultExtract(em.id)\n const x = await extract(run, traceStore)\n if (x === null || !Number.isFinite(x)) continue\n\n for (const om of outcomeMetricNames) {\n const values = eligible\n .map((o) => o.metrics[om])\n .filter((v): v is number => typeof v === 'number' && Number.isFinite(v))\n if (values.length === 0) continue\n const y = reduce(values, reduction, eligible)\n if (y === null) continue\n const pair = pairs.find((p) => p.evalMetric === em.id && p.outcomeMetric === om)!\n pair.xs.push(x)\n pair.ys.push(y)\n }\n }\n joined++\n }\n\n const results: CorrelationResult[] = pairs\n .filter((p) => p.xs.length >= 3)\n .map((p) => {\n const pearson = pearsonR(p.xs, p.ys)\n const spearman = spearmanR(p.xs, p.ys)\n const pearsonCi95 = bootstrapPearsonCi(p.xs, p.ys, options.bootstrapIterations ?? 500)\n const verdict: CorrelationResult['verdict'] =\n Math.abs(pearson) >= 0.7 ? 'strong' : Math.abs(pearson) >= 0.4 ? 'moderate' : 'weak'\n return {\n evalMetric: p.evalMetric,\n outcomeMetric: p.outcomeMetric,\n n: p.xs.length,\n pearson,\n spearman,\n pearsonCi95,\n verdict,\n }\n })\n\n return { pairs: results, joinedSamples: joined, skippedRuns: skipped }\n}\n\n// ── Helpers ──────────────────────────────────────────────────────────\n\nfunction reduce(\n values: number[],\n kind: 'latest' | 'mean' | 'max',\n outcomes: DeploymentOutcome[],\n): number | null {\n if (values.length === 0) return null\n if (kind === 'mean') return values.reduce((a, b) => a + b, 0) / values.length\n if (kind === 'max') return Math.max(...values)\n // 'latest': pick the outcome captured last, then lookup its metric\n const latest = [...outcomes].sort((a, b) => b.capturedAt - a.capturedAt)[0]\n if (!latest) return null\n const latestKey = Object.keys(latest.metrics)[0]\n const v = latestKey !== undefined ? latest.metrics[latestKey] : undefined\n // For 'latest' we already have `values` aligned; use the last-captured one\n const paired = outcomes\n .map((o) => {\n const k = Object.keys(o.metrics)[0]\n return {\n at: o.capturedAt,\n v: k !== undefined ? values.find((x) => o.metrics[k] === x) : undefined,\n }\n })\n .filter((p) => p.v !== undefined)\n if (paired.length === 0) return v ?? null\n return paired.sort((a, b) => b.at - a.at)[0]?.v ?? null\n}\n\nfunction bootstrapPearsonCi(\n xs: number[],\n ys: number[],\n iterations: number,\n): { lower: number; upper: number } {\n const n = xs.length\n if (n < 3) return { lower: NaN, upper: NaN }\n const rs: number[] = []\n for (let b = 0; b < iterations; b++) {\n const rx: number[] = new Array(n)\n const ry: number[] = new Array(n)\n for (let i = 0; i < n; i++) {\n const idx = Math.floor(Math.random() * n)\n rx[i] = xs[idx]!\n ry[i] = ys[idx]!\n }\n const r = pearsonR(rx, ry)\n if (Number.isFinite(r)) rs.push(r)\n }\n rs.sort((a, b) => a - b)\n if (rs.length === 0) return { lower: NaN, upper: NaN }\n return {\n lower: rs[Math.floor(0.025 * rs.length)]!,\n upper: rs[Math.min(rs.length - 1, Math.floor(0.975 * rs.length))]!,\n }\n}\n\nfunction defaultExtract(metric: string): (run: Run, store: TraceStore) => Promise<number | null> {\n return async (run, store) => {\n switch (metric) {\n case 'score':\n case 'overallScore':\n return run.outcome?.score ?? null\n case 'pass':\n return run.outcome?.pass === true ? 1 : 0\n case 'durationMs':\n return run.endedAt && run.startedAt ? run.endedAt - run.startedAt : null\n case 'costUsd': {\n const llm = await llmSpans(store, run.runId)\n return aggregateLlm(llm).costUsd\n }\n case 'inputTokens': {\n const llm = await llmSpans(store, run.runId)\n return aggregateLlm(llm).inputTokens\n }\n default:\n return null\n }\n }\n}\n","/**\n * Judge sentinel — eval trustworthiness as a continuously measured,\n * alarmed trend.\n *\n * Judges are models; models change underneath us; calibration decays.\n * This module composes three existing instruments into one loop:\n *\n * snapshot — adapters turn real instrument outputs (`calibrateJudge` /\n * `calibrateJudgeContinuous`, `corpusInterRaterAgreement` /\n * `continuousAgreement`, a rerun sentinel golden set) into\n * `SentinelSnapshot`s\n * series — `analyzeSeries` (src/series-convergence) classifies each\n * judge×metric history as stabilized / drifting / noisy\n * alarm — `judgeSentinelReport` turns trends + thresholds into named\n * alarms; `evalHealthStamp` is the tiny object a campaign\n * attaches to its verdicts\n *\n * Alarm conditions:\n * - convergence state `drifting-down` on any tracked metric\n * - irr below `minIrr`\n * - calibrationKappa / sentinelPassRate dropped vs the series baseline\n * beyond `maxKappaDrop` / `maxSentinelDrop`\n * - judge model changed with no post-change golden-grounded snapshot\n * (the silent-upgrade trap: judges agreeing with each other after a\n * model swap proves nothing — only re-measuring against gold does)\n * - newest snapshot older than `staleAfterDays` relative to `asOf`\n *\n * Wire-in: run the snapshot adapters from a post-campaign hook or a\n * nightly job, append to a `SentinelStore`, then compute\n * `judgeSentinelReport(await store.history(), { asOf })` with `asOf` =\n * the campaign timestamp. Attach `evalHealthStamp(report)` to campaign\n * verdicts: an alarmed sentinel means every downstream verdict carries\n * an integrity warning until the judge is recalibrated.\n *\n * The module is clock-free — every timestamp (`at`, `asOf`) is\n * caller-supplied ISO-8601, so reports are reproducible.\n */\n\nimport { ValidationError } from '../errors'\nimport type {\n CalibrationResult,\n CandidateScore,\n ContinuousAgreement,\n ContinuousCalibrationResult,\n GoldenItem,\n} from '../judge-calibration'\nimport {\n analyzeSeries,\n type SeriesConvergenceOptions,\n type SeriesConvergenceResult,\n} from '../series-convergence'\nimport type { CorpusAgreementReport } from '../statistics'\n\nexport const SENTINEL_METRIC_NAMES = ['irr', 'calibrationKappa', 'sentinelPassRate'] as const\n\nexport type SentinelMetricName = (typeof SENTINEL_METRIC_NAMES)[number]\n\nexport interface SentinelMetrics {\n /** Inter-rater reliability — ICC(2,1) from agreement instruments. */\n irr?: number\n /** Weighted κ vs the human golden set (`calibrateJudge*`). */\n calibrationKappa?: number\n /** Fraction of a fixed sentinel golden set the judge still scores within tolerance. */\n sentinelPassRate?: number\n}\n\nexport interface SentinelSnapshot {\n /** Caller-supplied ISO-8601 timestamp — the module never reads a clock. */\n at: string\n judgeId: string\n /** Exact model identity behind the judge (pin the full version string). */\n judgeModel: string\n /**\n * Metrics measured at `at`. May be empty: an empty-metrics snapshot is a\n * model-change marker — it records the new `judgeModel` immediately and\n * the silent-upgrade alarm stays raised until a golden-grounded snapshot\n * (calibrationKappa or sentinelPassRate) follows.\n */\n metrics: SentinelMetrics\n}\n\n/** Identity + timestamp the caller supplies alongside an instrument output. */\nexport interface SnapshotMeta {\n at: string\n judgeId: string\n judgeModel: string\n}\n\nfunction parseIso(value: string, label: string): number {\n const ms = typeof value === 'string' ? Date.parse(value) : NaN\n if (!Number.isFinite(ms)) {\n throw new ValidationError(\n `judge-sentinel: ${label} is not a parseable ISO timestamp: ${JSON.stringify(value)}`,\n )\n }\n return ms\n}\n\n/** Shape guard for snapshots crossing a boundary (store append, JSONL load, report input). */\nexport function validateSentinelSnapshot(snapshot: SentinelSnapshot, source = 'snapshot'): void {\n parseIso(snapshot.at, `${source}.at`)\n if (typeof snapshot.judgeId !== 'string' || snapshot.judgeId.length === 0) {\n throw new ValidationError(`judge-sentinel: ${source}.judgeId must be a non-empty string`)\n }\n if (typeof snapshot.judgeModel !== 'string' || snapshot.judgeModel.length === 0) {\n throw new ValidationError(`judge-sentinel: ${source}.judgeModel must be a non-empty string`)\n }\n if (snapshot.metrics === null || typeof snapshot.metrics !== 'object') {\n throw new ValidationError(`judge-sentinel: ${source}.metrics must be an object (may be empty)`)\n }\n for (const [key, value] of Object.entries(snapshot.metrics)) {\n if (!(SENTINEL_METRIC_NAMES as readonly string[]).includes(key)) {\n // A typo'd key would silently never trend — reject instead.\n throw new ValidationError(\n `judge-sentinel: ${source}.metrics carries unknown key \"${key}\" — known: ${SENTINEL_METRIC_NAMES.join(', ')}`,\n )\n }\n if (value !== undefined && !Number.isFinite(value)) {\n throw new ValidationError(\n `judge-sentinel: ${source}.metrics.${key} is not a finite number: ${String(value)}`,\n )\n }\n }\n}\n\n// ── Snapshot adapters — real instrument output → SentinelSnapshot ───\n\n/**\n * From `calibrateJudge` / `calibrateJudgeContinuous` output. Prefers the\n * un-rounded continuous κ_w when the report carries one (integer κ\n * discards information for [0,1] judges).\n */\nexport function snapshotFromCalibration(\n report: CalibrationResult | ContinuousCalibrationResult,\n meta: SnapshotMeta,\n): SentinelSnapshot {\n const kappa = 'weightedKappaContinuous' in report ? report.weightedKappaContinuous : report.kappa\n if (!Number.isFinite(kappa)) {\n throw new ValidationError(\n `snapshotFromCalibration: κ is not finite (n=${report.n}) — calibrate against ≥2 joined golden items before snapshotting`,\n )\n }\n const snapshot: SentinelSnapshot = { ...meta, metrics: { calibrationKappa: kappa } }\n validateSentinelSnapshot(snapshot)\n return snapshot\n}\n\n/**\n * From `corpusInterRaterAgreement` (statistics.ts) or `continuousAgreement`\n * (judge-calibration.ts) output. IRR = ICC(2,1) — the reliability\n * coefficient both instruments compute. For ensemble-level agreement,\n * `meta.judgeId` names the ensemble and `meta.judgeModel` pins its\n * composition (e.g. a joined list of member model strings).\n */\nexport function snapshotFromAgreement(\n report: CorpusAgreementReport | ContinuousAgreement,\n meta: SnapshotMeta,\n): SentinelSnapshot {\n const irr = 'overallIcc' in report ? report.overallIcc : report.icc\n if (!Number.isFinite(irr)) {\n throw new ValidationError(\n 'snapshotFromAgreement: ICC is not finite — agreement needs ≥2 raters and ≥2 complete items',\n )\n }\n const snapshot: SentinelSnapshot = { ...meta, metrics: { irr } }\n validateSentinelSnapshot(snapshot)\n return snapshot\n}\n\nexport interface SentinelSetOptions {\n /** Max |judge − human| for an item to count as passed. Default 0.1 (tuned for [0,1] scores). */\n tolerance?: number\n}\n\n/**\n * From a rerun of a fixed sentinel golden set: the same `GoldenItem`s the\n * judge was originally calibrated on, re-scored periodically. Pass rate =\n * fraction of joined items where the judge stays within `tolerance` of the\n * human score. Items the judge didn't score are excluded from the\n * denominator; zero joined items is an error, not a 0% pass rate.\n */\nexport function snapshotFromSentinelSet(\n scores: CandidateScore[],\n golden: GoldenItem[],\n meta: SnapshotMeta,\n options: SentinelSetOptions = {},\n): SentinelSnapshot {\n const tolerance = options.tolerance ?? 0.1\n if (!Number.isFinite(tolerance) || tolerance < 0) {\n throw new ValidationError(\n `snapshotFromSentinelSet: tolerance must be a finite number ≥ 0, got ${tolerance}`,\n )\n }\n const goldenById = new Map<string, number>()\n for (const item of golden) {\n if (!Number.isFinite(item.humanScore)) {\n throw new ValidationError(\n `snapshotFromSentinelSet: golden item \"${item.itemId}\" has a non-finite humanScore`,\n )\n }\n if (goldenById.has(item.itemId)) {\n throw new ValidationError(`snapshotFromSentinelSet: duplicate golden itemId \"${item.itemId}\"`)\n }\n goldenById.set(item.itemId, item.humanScore)\n }\n let joined = 0\n let passed = 0\n for (const s of scores) {\n const human = goldenById.get(s.itemId)\n if (human === undefined) continue\n if (!Number.isFinite(s.score)) {\n throw new ValidationError(\n `snapshotFromSentinelSet: judge score for item \"${s.itemId}\" is not finite`,\n )\n }\n joined++\n if (Math.abs(s.score - human) <= tolerance) passed++\n }\n if (joined === 0) {\n throw new ValidationError(\n 'snapshotFromSentinelSet: no judge scores joined the golden set — itemIds mismatch or empty sentinel run',\n )\n }\n const snapshot: SentinelSnapshot = { ...meta, metrics: { sentinelPassRate: passed / joined } }\n validateSentinelSnapshot(snapshot)\n return snapshot\n}\n\n// ── Persistence ──────────────────────────────────────────────────────\n\nexport interface SentinelStore {\n append(snapshot: SentinelSnapshot): Promise<void>\n /** All snapshots (optionally for one judge), in append order. */\n history(judgeId?: string): Promise<SentinelSnapshot[]>\n}\n\nexport function inMemorySentinelStore(initial: SentinelSnapshot[] = []): SentinelStore {\n for (const s of initial) validateSentinelSnapshot(s)\n const items = initial.map((s) => ({ ...s, metrics: { ...s.metrics } }))\n return {\n async append(snapshot) {\n validateSentinelSnapshot(snapshot)\n items.push({ ...snapshot, metrics: { ...snapshot.metrics } })\n },\n async history(judgeId) {\n const all = items.map((s) => ({ ...s, metrics: { ...s.metrics } }))\n return judgeId === undefined ? all : all.filter((s) => s.judgeId === judgeId)\n },\n }\n}\n\n/**\n * JSONL store — one snapshot per line, appended atomically per call.\n * A corrupt or shape-invalid line is a loud error naming the file and\n * line number: a sentinel history that silently drops records would\n * defeat the drift detection it exists to provide.\n */\nexport function fileSentinelStore(path: string): SentinelStore {\n return {\n async append(snapshot) {\n validateSentinelSnapshot(snapshot)\n const fs = await import('node:fs/promises')\n const pathMod = await import('node:path')\n await fs.mkdir(pathMod.dirname(path), { recursive: true })\n await fs.appendFile(path, `${JSON.stringify(snapshot)}\\n`, 'utf8')\n },\n async history(judgeId) {\n const fs = await import('node:fs/promises')\n let raw: string\n try {\n raw = await fs.readFile(path, 'utf8')\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') return []\n throw err\n }\n const lines = raw.split('\\n')\n const snapshots: SentinelSnapshot[] = []\n for (let i = 0; i < lines.length; i++) {\n const line = lines[i]!\n if (line.trim().length === 0) continue\n let parsed: unknown\n try {\n parsed = JSON.parse(line)\n } catch (err) {\n throw new ValidationError(\n `judge-sentinel: store at ${path} has a corrupt JSONL line ${i + 1}: ${(err as Error).message}`,\n )\n }\n const snapshot = parsed as SentinelSnapshot\n validateSentinelSnapshot(snapshot, `${path}:${i + 1}`)\n snapshots.push(snapshot)\n }\n return judgeId === undefined ? snapshots : snapshots.filter((s) => s.judgeId === judgeId)\n },\n }\n}\n\n// ── Trend report ─────────────────────────────────────────────────────\n\nexport interface SentinelThresholds {\n /** Floor for irr — below it the judge ensemble is unreliable regardless of trend. Default 0.6. */\n minIrr?: number\n /** Max tolerated calibrationKappa drop vs the series baseline. Default 0.15. */\n maxKappaDrop?: number\n /** Max tolerated sentinelPassRate drop vs the series baseline. Default 0.1. */\n maxSentinelDrop?: number\n /** Newest snapshot older than this (days, vs asOf) = the sentinel itself went blind. Default 30. */\n staleAfterDays?: number\n}\n\nexport interface JudgeSentinelOptions {\n /** Caller-supplied ISO timestamp staleness is measured against. */\n asOf: string\n thresholds?: SentinelThresholds\n /** Forwarded to `analyzeSeries` (window, stableCv, driftRun). */\n convergence?: SeriesConvergenceOptions\n}\n\nexport interface SentinelTrend {\n judgeId: string\n metric: SentinelMetricName\n /** Verbatim `analyzeSeries` state for this judge×metric history. */\n state: SeriesConvergenceResult['state']\n /** Newest value in the series. */\n current: number\n /** Oldest value in the series — the reference the drop thresholds compare against. */\n baseline: number\n /** current − baseline (signed; negative = decayed). */\n drift: number\n alarmed: boolean\n reason?: string\n}\n\nexport interface SentinelReport {\n perJudge: SentinelTrend[]\n alarms: string[]\n healthy: boolean\n /**\n * `judgeId:metric` pairs with too few snapshots for the convergence\n * machine. Named, not counted — a blind spot you can't see is a blind\n * spot you won't fix. Floor/drop checks still apply to thin series, so\n * insufficient history alone never masks an alarm.\n */\n insufficientHistory: string[]\n}\n\nconst MS_PER_DAY = 86_400_000\n\nexport function judgeSentinelReport(\n history: SentinelSnapshot[],\n opts: JudgeSentinelOptions,\n): SentinelReport {\n const asOfMs = parseIso(opts.asOf, 'asOf')\n const minIrr = opts.thresholds?.minIrr ?? 0.6\n const maxKappaDrop = opts.thresholds?.maxKappaDrop ?? 0.15\n const maxSentinelDrop = opts.thresholds?.maxSentinelDrop ?? 0.1\n const staleAfterDays = opts.thresholds?.staleAfterDays ?? 30\n\n const byJudge = new Map<string, Array<SentinelSnapshot & { atMs: number }>>()\n for (const snapshot of history) {\n validateSentinelSnapshot(snapshot)\n const atMs = parseIso(snapshot.at, `snapshot.at (judge \"${snapshot.judgeId}\")`)\n const arr = byJudge.get(snapshot.judgeId) ?? []\n arr.push({ ...snapshot, atMs })\n byJudge.set(snapshot.judgeId, arr)\n }\n\n const perJudge: SentinelTrend[] = []\n const alarms: string[] = []\n const insufficientHistory: string[] = []\n\n for (const judgeId of [...byJudge.keys()].sort()) {\n const snaps = byJudge.get(judgeId)!.sort((a, b) => a.atMs - b.atMs)\n const newest = snaps[snaps.length - 1]!\n\n const ageDays = (asOfMs - newest.atMs) / MS_PER_DAY\n if (ageDays > staleAfterDays) {\n alarms.push(\n `judge \"${judgeId}\": stale — newest snapshot ${newest.at} is ${ageDays.toFixed(1)}d old vs asOf (limit ${staleAfterDays}d)`,\n )\n }\n\n // Silent-upgrade trap: only the latest model change matters for current\n // trust, and only golden-grounded metrics clear it — irr alone proves\n // judges still agree with each other, not that they're still right.\n let changeIdx = -1\n for (let i = 1; i < snaps.length; i++) {\n if (snaps[i]!.judgeModel !== snaps[i - 1]!.judgeModel) changeIdx = i\n }\n if (changeIdx >= 0) {\n const recalibrated = snaps\n .slice(changeIdx)\n .some(\n (s) =>\n Number.isFinite(s.metrics.calibrationKappa) ||\n Number.isFinite(s.metrics.sentinelPassRate),\n )\n if (!recalibrated) {\n alarms.push(\n `judge \"${judgeId}\": model changed \"${snaps[changeIdx - 1]!.judgeModel}\" → \"${snaps[changeIdx]!.judgeModel}\" at ${snaps[changeIdx]!.at} with no post-change calibration snapshot — silent-upgrade trap; rerun calibrateJudge or the sentinel set against the new model`,\n )\n }\n }\n\n for (const metric of SENTINEL_METRIC_NAMES) {\n const values = snaps\n .filter((s) => typeof s.metrics[metric] === 'number')\n .map((s) => s.metrics[metric]!)\n if (values.length === 0) continue\n\n const convergence = analyzeSeries(values, opts.convergence)\n if (convergence.state === 'insufficient-data')\n insufficientHistory.push(`${judgeId}:${metric}`)\n\n const current = values[values.length - 1]!\n const baseline = values[0]!\n const drift = current - baseline\n const reasons: string[] = []\n if (convergence.state === 'drifting-down') {\n reasons.push(\n `convergence state drifting-down (tail run ${convergence.tailRun}, window mean ${convergence.windowMean.toFixed(3)})`,\n )\n }\n if (metric === 'irr' && current < minIrr) {\n reasons.push(`irr ${current.toFixed(3)} below floor ${minIrr}`)\n }\n if (metric === 'calibrationKappa' && baseline - current > maxKappaDrop) {\n reasons.push(\n `calibrationKappa dropped ${(baseline - current).toFixed(3)} from baseline ${baseline.toFixed(3)} (limit ${maxKappaDrop})`,\n )\n }\n if (metric === 'sentinelPassRate' && baseline - current > maxSentinelDrop) {\n reasons.push(\n `sentinelPassRate dropped ${(baseline - current).toFixed(3)} from baseline ${baseline.toFixed(3)} (limit ${maxSentinelDrop})`,\n )\n }\n\n const alarmed = reasons.length > 0\n const trend: SentinelTrend = {\n judgeId,\n metric,\n state: convergence.state,\n current,\n baseline,\n drift,\n alarmed,\n }\n if (alarmed) {\n trend.reason = reasons.join('; ')\n alarms.push(`judge \"${judgeId}\" ${metric}: ${trend.reason}`)\n }\n perJudge.push(trend)\n }\n }\n\n return { perJudge, alarms, healthy: alarms.length === 0, insufficientHistory }\n}\n\n// ── Verdict stamp ────────────────────────────────────────────────────\n\nexport interface EvalHealthStamp {\n healthy: boolean\n alarms: string[]\n}\n\n/**\n * The object a campaign attaches to its verdicts. Compute it from the\n * sentinel report in a post-campaign hook (or a nightly job feeding the\n * next day's campaigns) and store it alongside the verdict payload.\n * `healthy: false` means the judges that produced those verdicts have an\n * unresolved drift / decay / silent-upgrade / staleness alarm — treat the\n * verdicts as carrying an integrity warning until recalibration clears it.\n */\nexport function evalHealthStamp(report: SentinelReport): EvalHealthStamp {\n return { healthy: report.healthy, alarms: [...report.alarms] }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyDA,eAAsB,iBACpB,YACA,cACA,aACA,oBACA,UAAmC,CAAC,GACH;AACjC,QAAM,OAAO,MAAM,WAAW,SAAS;AACvC,QAAM,WAAW,MAAM,aAAa,KAAK,QAAQ,aAAa;AAC9D,QAAM,gBAAgB,oBAAI,IAAiC;AAC3D,aAAW,KAAK,UAAU;AACxB,UAAM,MAAM,cAAc,IAAI,EAAE,KAAK,KAAK,CAAC;AAC3C,QAAI,KAAK,CAAC;AACV,kBAAc,IAAI,EAAE,OAAO,GAAG;AAAA,EAChC;AAEA,QAAM,YAAY,QAAQ,aAAa;AACvC,QAAM,SAAS,QAAQ,mBAAmB;AAE1C,QAAM,QAA0F,CAAC;AACjG,aAAW,MAAM,aAAa;AAC5B,eAAW,MAAM,oBAAoB;AACnC,YAAM,KAAK,EAAE,YAAY,GAAG,IAAI,eAAe,IAAI,IAAI,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC;AAAA,IACrE;AAAA,EACF;AAEA,MAAI,SAAS;AACb,MAAI,UAAU;AACd,aAAW,OAAO,MAAM;AACtB,UAAM,KAAK,cAAc,IAAI,IAAI,KAAK;AACtC,QAAI,CAAC,MAAM,GAAG,WAAW,GAAG;AAC1B;AACA;A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