@tangle-network/agent-eval 0.220.2 → 0.221.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 (180) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/adapters/http.d.ts +2 -2
  3. package/dist/{agent-profile-D01Io2Xw.d.ts → agent-profile-Bc7ADJY4.d.ts} +2 -2
  4. package/dist/{agent-profile-D01Io2Xw.d.ts.map → agent-profile-Bc7ADJY4.d.ts.map} +1 -1
  5. package/dist/analyst/index.d.ts +77 -78
  6. package/dist/analyst/index.d.ts.map +1 -1
  7. package/dist/analyst/index.js +204 -25
  8. package/dist/analyst/index.js.map +1 -1
  9. package/dist/{analyze-runs-DqPJaJ4X.js → analyze-runs-CHmsykNJ.js} +4 -4
  10. package/dist/{analyze-runs-DqPJaJ4X.js.map → analyze-runs-CHmsykNJ.js.map} +1 -1
  11. package/dist/{analyze-runs-BWAHBDAw.d.ts → analyze-runs-D7In4c3z.d.ts} +2 -2
  12. package/dist/{analyze-runs-BWAHBDAw.d.ts.map → analyze-runs-D7In4c3z.d.ts.map} +1 -1
  13. package/dist/{benchmark-command-Dx0E4a6z.js → benchmark-command-8XQfpUK3.js} +13 -11
  14. package/dist/benchmark-command-8XQfpUK3.js.map +1 -0
  15. package/dist/benchmarks/index.d.ts +4 -4
  16. package/dist/benchmarks/index.js +3 -3
  17. package/dist/calibration-CTwxpJ-t.js +197 -0
  18. package/dist/calibration-CTwxpJ-t.js.map +1 -0
  19. package/dist/campaign/index.d.ts +6 -6
  20. package/dist/campaign/index.js +5 -5
  21. package/dist/{campaign-BVPC6ODQ.js → campaign-Bt6rbWIU.js} +9 -8
  22. package/dist/{campaign-BVPC6ODQ.js.map → campaign-Bt6rbWIU.js.map} +1 -1
  23. package/dist/cli.js +1 -1
  24. package/dist/{completion-verifier-Cigap8CG.js → completion-verifier-YwoeujPl.js} +2 -2
  25. package/dist/{completion-verifier-Cigap8CG.js.map → completion-verifier-YwoeujPl.js.map} +1 -1
  26. package/dist/contract/index.d.ts +10 -10
  27. package/dist/contract/index.js +7 -7
  28. package/dist/decision-point-Co3u3W8k.js +831 -0
  29. package/dist/decision-point-Co3u3W8k.js.map +1 -0
  30. package/dist/default-registry-BMHqNR6_.d.ts +257 -0
  31. package/dist/default-registry-BMHqNR6_.d.ts.map +1 -0
  32. package/dist/{default-registry-ovrIBGmH.js → default-registry-BbFCkqvB.js} +607 -14
  33. package/dist/default-registry-BbFCkqvB.js.map +1 -0
  34. package/dist/{define-agent-eval-C2nFhHPu.d.ts → define-agent-eval-Bsoi2GUV.d.ts} +7 -7
  35. package/dist/{define-agent-eval-C2nFhHPu.d.ts.map → define-agent-eval-Bsoi2GUV.d.ts.map} +1 -1
  36. package/dist/{define-agent-eval-UQY3VbJ2.js → define-agent-eval-CJhECJNL.js} +4 -4
  37. package/dist/{define-agent-eval-UQY3VbJ2.js.map → define-agent-eval-CJhECJNL.js.map} +1 -1
  38. package/dist/diagnosis/index.d.ts +2 -2
  39. package/dist/diagnosis/index.js +1 -1
  40. package/dist/{dspy-rlm-engine-Bn_Mt_LW.js → dspy-rlm-engine-BTy7u0jQ.js} +3 -3
  41. package/dist/{dspy-rlm-engine-Bn_Mt_LW.js.map → dspy-rlm-engine-BTy7u0jQ.js.map} +1 -1
  42. package/dist/{engine-BpGGw6cd.d.ts → engine-BF95CWzH.d.ts} +2 -2
  43. package/dist/{engine-BpGGw6cd.d.ts.map → engine-BF95CWzH.d.ts.map} +1 -1
  44. package/dist/{eval-campaign-BUMIxKTE.js → eval-campaign-DoX5vz3E.js} +2 -2
  45. package/dist/{eval-campaign-BUMIxKTE.js.map → eval-campaign-DoX5vz3E.js.map} +1 -1
  46. package/dist/{evaluation-CBdQt_kr.d.ts → evaluation-D1PGzkPR.d.ts} +3 -3
  47. package/dist/{evaluation-CBdQt_kr.d.ts.map → evaluation-D1PGzkPR.d.ts.map} +1 -1
  48. package/dist/evaluation-wdGyZ7jV.js +147 -0
  49. package/dist/evaluation-wdGyZ7jV.js.map +1 -0
  50. package/dist/evaluation.d.ts +1 -1
  51. package/dist/evaluation.js +1 -136
  52. package/dist/{exact-types-BYFmYq44.d.ts → exact-types-CVn1QxFO.d.ts} +2 -2
  53. package/dist/{exact-types-BYFmYq44.d.ts.map → exact-types-CVn1QxFO.d.ts.map} +1 -1
  54. package/dist/experiment/index.d.ts +3 -3
  55. package/dist/experiment/index.js +2 -2
  56. package/dist/{external-optimizer-process-wOLfzsCC.js → external-optimizer-process-E5yY2SYS.js} +2 -2
  57. package/dist/{external-optimizer-process-wOLfzsCC.js.map → external-optimizer-process-E5yY2SYS.js.map} +1 -1
  58. package/dist/{external-optimizer-subprocess-D670Oxf2.js → external-optimizer-subprocess-DA02c_L6.js} +12 -19
  59. package/dist/{external-optimizer-subprocess-D670Oxf2.js.map → external-optimizer-subprocess-DA02c_L6.js.map} +1 -1
  60. package/dist/{feedback-trajectory-DhB9WzYg.d.ts → feedback-trajectory-BZhVCWuz.d.ts} +3 -3
  61. package/dist/{feedback-trajectory-DhB9WzYg.d.ts.map → feedback-trajectory-BZhVCWuz.d.ts.map} +1 -1
  62. package/dist/finding-composition-8n0fFgVI.js +131 -0
  63. package/dist/finding-composition-8n0fFgVI.js.map +1 -0
  64. package/dist/{findings-store-CvNo712L.js → findings-store-DRiFdoid.js} +4 -4
  65. package/dist/{findings-store-CvNo712L.js.map → findings-store-DRiFdoid.js.map} +1 -1
  66. package/dist/{index-CVFStrQD.d.ts → index-BJZ7s-sv.d.ts} +7 -58
  67. package/dist/index-BJZ7s-sv.d.ts.map +1 -0
  68. package/dist/{index-Q6DvdcwI.d.ts → index-BvX3CFNS.d.ts} +6 -6
  69. package/dist/{index-Q6DvdcwI.d.ts.map → index-BvX3CFNS.d.ts.map} +1 -1
  70. package/dist/index-DWd1gUwR.d.ts +1086 -0
  71. package/dist/index-DWd1gUwR.d.ts.map +1 -0
  72. package/dist/{index-DAXfpVf7.d.ts → index-y7i8l6Y_.d.ts} +8 -8
  73. package/dist/{index-DAXfpVf7.d.ts.map → index-y7i8l6Y_.d.ts.map} +1 -1
  74. package/dist/index.d.ts +18 -17
  75. package/dist/index.d.ts.map +1 -1
  76. package/dist/index.js +15 -15
  77. package/dist/{kind-factory-BhxbtUsQ.js → kind-factory-Dl0PmNQL.js} +2 -2
  78. package/dist/{kind-factory-BhxbtUsQ.js.map → kind-factory-Dl0PmNQL.js.map} +1 -1
  79. package/dist/{llm-judge-Cc8vDJh_.js → llm-judge-3uAeRawE.js} +4 -4
  80. package/dist/{llm-judge-Cc8vDJh_.js.map → llm-judge-3uAeRawE.js.map} +1 -1
  81. package/dist/{matrix-Cf-AGxGh.d.ts → matrix-BXo3PSqM.d.ts} +2 -2
  82. package/dist/{matrix-Cf-AGxGh.d.ts.map → matrix-BXo3PSqM.d.ts.map} +1 -1
  83. package/dist/meta-eval/index.d.ts +3 -638
  84. package/dist/meta-eval/index.js +3 -193
  85. package/dist/meta-eval/index.js.map +1 -1
  86. package/dist/multishot/golden/index.d.ts +1 -1
  87. package/dist/multishot/index.d.ts +2 -2
  88. package/dist/openapi.json +1 -1
  89. package/dist/outcome-observations-FLmRpgYa.js +78 -0
  90. package/dist/outcome-observations-FLmRpgYa.js.map +1 -0
  91. package/dist/{paired-arms-Ct4LTKc1.js → paired-arms-B2ttLc0_.js} +108 -31
  92. package/dist/paired-arms-B2ttLc0_.js.map +1 -0
  93. package/dist/{power-and-mde-N5nU4_Ly.js → power-and-mde-CQX-0weG.js} +2 -2
  94. package/dist/{power-and-mde-N5nU4_Ly.js.map → power-and-mde-CQX-0weG.js.map} +1 -1
  95. package/dist/{prime-protocol-CckHBxGu.d.ts → prime-protocol-BEaqBoQE.d.ts} +2 -2
  96. package/dist/{prime-protocol-CckHBxGu.d.ts.map → prime-protocol-BEaqBoQE.d.ts.map} +1 -1
  97. package/dist/{proposal-findings-E1aSC_cU.js → proposal-findings-D0_zkQ2l.js} +2 -2
  98. package/dist/{proposal-findings-E1aSC_cU.js.map → proposal-findings-D0_zkQ2l.js.map} +1 -1
  99. package/dist/{registry-B_yG-1jh.d.ts → registry-DDKaUrmM.d.ts} +3 -3
  100. package/dist/{registry-B_yG-1jh.d.ts.map → registry-DDKaUrmM.d.ts.map} +1 -1
  101. package/dist/reporting.d.ts +1 -1
  102. package/dist/reporting.js +3 -3
  103. package/dist/rl.d.ts +4 -5
  104. package/dist/rl.d.ts.map +1 -1
  105. package/dist/rl.js +5 -4
  106. package/dist/rl.js.map +1 -1
  107. package/dist/{rubric-predictive-validity-noY7uE03.d.ts → rubric-predictive-validity-Cd5SCtAf.d.ts} +58 -3
  108. package/dist/rubric-predictive-validity-Cd5SCtAf.d.ts.map +1 -0
  109. package/dist/{rubric-predictive-validity-D3_oI72N.js → rubric-predictive-validity-CeKW2GQN.js} +3 -77
  110. package/dist/rubric-predictive-validity-CeKW2GQN.js.map +1 -0
  111. package/dist/search/index.d.ts +2 -2
  112. package/dist/{search-kernel-Dloxd6gs.d.ts → search-kernel-C6__V0IS.d.ts} +2 -2
  113. package/dist/{search-kernel-Dloxd6gs.d.ts.map → search-kernel-C6__V0IS.d.ts.map} +1 -1
  114. package/dist/{skillopt-optimization-method-DLKqdhcR.js → skillopt-optimization-method-D21dH_Bh.js} +4 -4
  115. package/dist/{skillopt-optimization-method-DLKqdhcR.js.map → skillopt-optimization-method-D21dH_Bh.js.map} +1 -1
  116. package/dist/{statistical-heldout-3z3I-kJN.d.ts → statistical-heldout-pD1Yah-0.d.ts} +58 -8
  117. package/dist/statistical-heldout-pD1Yah-0.d.ts.map +1 -0
  118. package/dist/{store-otlp-dyWE3wAG.js → store-otlp-BVZfR168.js} +2 -2
  119. package/dist/{store-otlp-dyWE3wAG.js.map → store-otlp-BVZfR168.js.map} +1 -1
  120. package/dist/{store-tool-spans-DIUgZbzu.js → store-tool-spans-CjYiF4fF.js} +3 -3
  121. package/dist/{store-tool-spans-DIUgZbzu.js.map → store-tool-spans-CjYiF4fF.js.map} +1 -1
  122. package/dist/{store-tool-spans-DPwXHQkH.d.ts → store-tool-spans-DfnwWMFR.d.ts} +4 -4
  123. package/dist/{store-tool-spans-DPwXHQkH.d.ts.map → store-tool-spans-DfnwWMFR.d.ts.map} +1 -1
  124. package/dist/{summary-report-BsXJoYX5.js → summary-report-DHDWxe6p.js} +3 -3
  125. package/dist/{summary-report-BsXJoYX5.js.map → summary-report-DHDWxe6p.js.map} +1 -1
  126. package/dist/systemone-D3MrW63C.d.ts +400 -0
  127. package/dist/systemone-D3MrW63C.d.ts.map +1 -0
  128. package/dist/{systemone-protocol-DKoi1NdK.d.ts → systemone-protocol-Bl2EI2KQ.d.ts} +4 -2
  129. package/dist/{systemone-protocol-DKoi1NdK.d.ts.map → systemone-protocol-Bl2EI2KQ.d.ts.map} +1 -1
  130. package/dist/systemone-protocol.d.ts +2 -2
  131. package/dist/systemone-protocol.js +7 -7
  132. package/dist/systemone-protocol.js.map +1 -1
  133. package/dist/{systemone-review-CUBMuTLi.d.ts → systemone-review-C8DRiT_-.d.ts} +3 -3
  134. package/dist/{systemone-review-CUBMuTLi.d.ts.map → systemone-review-C8DRiT_-.d.ts.map} +1 -1
  135. package/dist/{systemone-review-DzdOJ8I6.js → systemone-review-DFGtIUcf.js} +2 -2
  136. package/dist/{systemone-review-DzdOJ8I6.js.map → systemone-review-DFGtIUcf.js.map} +1 -1
  137. package/dist/systemone.d.ts +5 -5
  138. package/dist/systemone.js +5 -343
  139. package/dist/{tool-groups-LISbBWCg.d.ts → tool-groups-DK1bu5TD.d.ts} +3 -3
  140. package/dist/tool-groups-DK1bu5TD.d.ts.map +1 -0
  141. package/dist/{trace-questions-C42fYEE4.d.ts → trace-questions-D_OKYZ6u.d.ts} +3 -3
  142. package/dist/{trace-questions-C42fYEE4.d.ts.map → trace-questions-D_OKYZ6u.d.ts.map} +1 -1
  143. package/dist/trace-repair/index.d.ts +1 -1
  144. package/dist/traces.d.ts +3 -3
  145. package/dist/traces.js +3 -3
  146. package/dist/{types-DqFMNTgK.js → types-CnWmj8NW.js} +19 -6
  147. package/dist/types-CnWmj8NW.js.map +1 -0
  148. package/dist/{types-CHfn1zg5.d.ts → types-DDKfH-N6.d.ts} +2 -2
  149. package/dist/{types-CHfn1zg5.d.ts.map → types-DDKfH-N6.d.ts.map} +1 -1
  150. package/dist/{types-8yQzNm8u.d.ts → types-DGImvHIr.d.ts} +150 -4
  151. package/dist/types-DGImvHIr.d.ts.map +1 -0
  152. package/dist/{types-D8GXK9Z5.d.ts → types-IERw_HxR.d.ts} +2 -2
  153. package/dist/{types-D8GXK9Z5.d.ts.map → types-IERw_HxR.d.ts.map} +1 -1
  154. package/dist/wire/index.d.ts +1 -1
  155. package/docs/behavioral-trace-questions.md +99 -0
  156. package/docs/experiment.md +27 -0
  157. package/docs/finding-layers.md +54 -1
  158. package/docs/systemone.md +107 -0
  159. package/package.json +1 -1
  160. package/dist/benchmark-command-Dx0E4a6z.js.map +0 -1
  161. package/dist/default-registry-Cwg_QN3d.d.ts +0 -70
  162. package/dist/default-registry-Cwg_QN3d.d.ts.map +0 -1
  163. package/dist/default-registry-ovrIBGmH.js.map +0 -1
  164. package/dist/evaluation.js.map +0 -1
  165. package/dist/index-CVFStrQD.d.ts.map +0 -1
  166. package/dist/judge-gate-Dc_mXQsL.d.ts +0 -453
  167. package/dist/judge-gate-Dc_mXQsL.d.ts.map +0 -1
  168. package/dist/meta-eval/index.d.ts.map +0 -1
  169. package/dist/outcome-store-CNt4iZ67.d.ts +0 -58
  170. package/dist/outcome-store-CNt4iZ67.d.ts.map +0 -1
  171. package/dist/paired-arms-Ct4LTKc1.js.map +0 -1
  172. package/dist/rubric-predictive-validity-D3_oI72N.js.map +0 -1
  173. package/dist/rubric-predictive-validity-noY7uE03.d.ts.map +0 -1
  174. package/dist/statistical-heldout-3z3I-kJN.d.ts.map +0 -1
  175. package/dist/systemone-DVA7t76V.d.ts +0 -135
  176. package/dist/systemone-DVA7t76V.d.ts.map +0 -1
  177. package/dist/systemone.js.map +0 -1
  178. package/dist/tool-groups-LISbBWCg.d.ts.map +0 -1
  179. package/dist/types-8yQzNm8u.d.ts.map +0 -1
  180. package/dist/types-DqFMNTgK.js.map +0 -1
@@ -3,204 +3,14 @@ import { a as hashCanonical, i as compareCodeUnits } from "../canonical-Dq2hOQ8L
3
3
  import { t as mulberry32 } from "../random-DDDcC7YU.js";
4
4
  import { a as selfPreference, i as positionalBias, n as calibrateJudgeContinuous, o as verbosityBias, r as continuousAgreement, t as calibrateJudge } from "../judge-calibration-BkXMIWA4.js";
5
5
  import { s as runMetricExtractor } from "../query-B_RZ36an.js";
6
+ import { a as validateObservationOptions, i as reduceOutcomeMetric, n as correlationSummary, r as hasVariation, t as assertUniqueObservationIds } from "../outcome-observations-FLmRpgYa.js";
7
+ import { a as rankedProbabilityScore, i as multiclassBrierScore, n as calibrationCurve, r as calibrationFromPairs, t as brierScore } from "../calibration-CTwxpJ-t.js";
6
8
  import { a as judgeGateDecision, c as snapshotFromJudgeAgreement, d as judgeSentinelReport, f as snapshotFromAgreement, h as validateSentinelSnapshot, i as assertJudgeMayGate, l as evalHealthStamp, m as snapshotFromSentinelSet, n as JudgeGateRefusedError, o as measureJudgeAgreement, p as snapshotFromCalibration, r as addCalibrationVerdicts, s as registerCalibrationSet, t as DEFAULT_JUDGE_GATE_POLICY, u as fileSentinelStore } from "../judge-gate-Co5tuh57.js";
7
9
  import { t as computeInterval } from "../interval-Dq9gt7jx.js";
8
10
  import { t as clusterBootstrapMean } from "../cluster-bootstrap-DEwwhl0C.js";
9
- import { a as reduceOutcomeMetric, i as hasVariation, n as assertUniqueObservationIds, o as validateObservationOptions, r as correlationSummary, t as rubricPredictiveValidity } from "../rubric-predictive-validity-D3_oI72N.js";
11
+ import { t as rubricPredictiveValidity } from "../rubric-predictive-validity-CeKW2GQN.js";
10
12
  import { n as InMemoryOutcomeStore, r as OutcomeStoreError, t as FileSystemOutcomeStore } from "../outcome-store-DUcMj-3D.js";
11
13
  import { z } from "zod";
12
- //#region src/meta-eval/calibration.ts
13
- /**
14
- * Calibration curve — binned "if eval says X, what does reality show?"
15
- *
16
- * Companion to correlationStudy. Raw correlation is a single number;
17
- * the calibration curve shows *where* the eval is well-calibrated vs
18
- * overconfident / underconfident. Buckets the eval metric, computes
19
- * mean outcome per bucket, reports expected-calibration-error (ECE).
20
- */
21
- async function calibrationCurve(traceStore, outcomeStore, evalMetric, outcomeMetric, options = {}) {
22
- const settings = {
23
- ...options,
24
- range: options.range === void 0 ? void 0 : { ...options.range }
25
- };
26
- validateCalibrationRequest(evalMetric.id, outcomeMetric, settings);
27
- const extract = evalMetric.extract ?? runMetricExtractor(evalMetric.id);
28
- const metricId = evalMetric.id;
29
- const runs = await traceStore.listRuns();
30
- assertUniqueObservationIds(runs.map((run) => run.runId), "runId");
31
- const outcomes = await outcomeStore.list();
32
- const byRun = /* @__PURE__ */ new Map();
33
- for (const o of outcomes) {
34
- const arr = byRun.get(o.runId) ?? [];
35
- arr.push(o);
36
- byRun.set(o.runId, arr);
37
- }
38
- const pairs = [];
39
- for (const run of runs) {
40
- const os = byRun.get(run.runId);
41
- if (!os?.length) continue;
42
- const x = await extract(run, traceStore);
43
- if (x === null || !Number.isFinite(x)) continue;
44
- const y = reduceOutcomeMetric(os, outcomeMetric, "latest");
45
- if (y === null) continue;
46
- pairs.push({
47
- x,
48
- y
49
- });
50
- }
51
- if (pairs.length < 2) return null;
52
- return calibrationFromPairs(pairs.map((p) => ({
53
- evalScore: p.x,
54
- outcome: p.y
55
- })), metricId, outcomeMetric, settings);
56
- }
57
- /** Measure already joined observations without constructing trace and outcome stores. */
58
- function calibrationFromPairs(inputPairs, evalMetric, outcomeMetric, options = {}) {
59
- validateCalibrationRequest(evalMetric, outcomeMetric, options);
60
- for (const [index, pair] of inputPairs.entries()) if (pair === null || typeof pair !== "object" || !Number.isFinite(pair.evalScore) || !Number.isFinite(pair.outcome)) throw new Error(`calibration pair ${index} must contain finite evalScore and outcome values`);
61
- const pairs = inputPairs;
62
- if (pairs.length < 2) return null;
63
- const numBins = options.bins ?? 10;
64
- const binning = options.binning ?? "equal-width";
65
- const xs = pairs.map((p) => p.evalScore);
66
- const lo = options.range?.lo ?? Math.min(...xs);
67
- const hi = options.range?.hi ?? Math.max(...xs);
68
- const span = hi - lo;
69
- if (!Number.isFinite(span)) throw new Error("calibration range span must be finite");
70
- const clipped = pairs.map((pair) => ({
71
- ...pair,
72
- evalScore: Math.min(hi, Math.max(lo, pair.evalScore))
73
- }));
74
- const bins = [];
75
- if (span === 0 || clipped.every((pair) => pair.evalScore === clipped[0].evalScore)) bins.push(toBin(clipped));
76
- else if (binning === "equal-frequency") {
77
- const sorted = [...clipped].sort((a, b) => a.evalScore - b.evalScore);
78
- const count = Math.min(numBins, sorted.length);
79
- for (let i = 0; i < count; i++) {
80
- const start = Math.floor(i * sorted.length / count);
81
- const end = Math.floor((i + 1) * sorted.length / count);
82
- bins.push(toBin(sorted.slice(start, end)));
83
- }
84
- } else {
85
- const groups = /* @__PURE__ */ new Map();
86
- for (const pair of clipped) {
87
- const index = Math.min(numBins - 1, Math.floor((pair.evalScore - lo) / span * numBins));
88
- const group = groups.get(index) ?? [];
89
- group.push(pair);
90
- groups.set(index, group);
91
- }
92
- for (const [index, chunk] of [...groups].sort(([a], [b]) => a - b)) bins.push(toBin(chunk, lo + span * (index / numBins), lo + span * ((index + 1) / numBins)));
93
- }
94
- const total = bins.reduce((a, b) => a + b.n, 0);
95
- const ece = bins.reduce((a, b) => a + b.n / total * b.gap, 0);
96
- const maxGap = bins.reduce((a, b) => Math.max(a, b.gap), 0);
97
- return {
98
- evalMetric,
99
- outcomeMetric,
100
- n: pairs.length,
101
- bins,
102
- ece,
103
- maxGap
104
- };
105
- }
106
- /**
107
- * Mean squared error of probability forecasts against binary outcomes, Σ(p − y)²/N; always
108
- * forecasting 0.5 scores 0.25. For the reliability table and ECE use `calibrationFromPairs`
109
- * with `range: { lo: 0, hi: 1 }` (`binning: 'equal-frequency'` gives equal-mass bins).
110
- */
111
- function brierScore(pairs) {
112
- if (!pairs.length) throw new Error("Brier score requires at least one pair");
113
- let total = 0;
114
- for (const [index, pair] of pairs.entries()) {
115
- if (pair === null || typeof pair !== "object" || !(pair.evalScore >= 0 && pair.evalScore <= 1) || pair.outcome !== 0 && pair.outcome !== 1) throw new Error(`Brier pair ${index} needs a probability in [0, 1] and an outcome of 0 or 1`);
116
- total += (pair.evalScore - pair.outcome) ** 2;
117
- }
118
- return total / pairs.length;
119
- }
120
- /**
121
- * Multiclass Brier score in its sum form, mean over forecasts of Σₖ(pₖ − yₖ)², range [0, 2].
122
- * With two outcomes it is twice the binary `brierScore`. A uniform forecast over K outcomes
123
- * scores 1 − 1/K. The distribution is not renormalized here: repair provider rounding before
124
- * scoring (`normalizeSystemOneResult` in `/systemone/protocol`), so a defective answer stays
125
- * visible instead of being scored as if it were valid.
126
- */
127
- function multiclassBrierScore(forecasts) {
128
- if (!forecasts.length) throw new Error("multiclass Brier score requires at least one forecast");
129
- let total = 0;
130
- for (const [index, forecast] of forecasts.entries()) {
131
- const entries = categoricalEntries(forecast, index, "multiclass Brier");
132
- for (const [name, probability] of entries) total += (probability - (name === forecast.outcome ? 1 : 0)) ** 2;
133
- }
134
- return total / forecasts.length;
135
- }
136
- /**
137
- * Ranked probability score, mean over forecasts of Σₖ₌₁ᴷ⁻¹(Fₖ − Oₖ)² / (K − 1), where F and O are
138
- * the cumulative forecast and observation, range [0, 1]. Unlike multiclass Brier it charges
139
- * less for mass on a level next to the outcome than for mass far from it, which is the right
140
- * penalty for score questions. With two levels it equals the binary Brier score.
141
- */
142
- function rankedProbabilityScore(forecasts) {
143
- if (!forecasts.length) throw new Error("ranked probability score requires at least one forecast");
144
- let total = 0;
145
- for (const [index, forecast] of forecasts.entries()) {
146
- const probabilities = forecast?.probabilities;
147
- if (!Array.isArray(probabilities) || probabilities.length < 2) throw new Error(`RPS forecast ${index} needs at least two level probabilities`);
148
- assertDistribution(probabilities, `RPS forecast ${index}`);
149
- if (!Number.isInteger(forecast.outcome) || forecast.outcome < 0 || forecast.outcome >= probabilities.length) throw new Error(`RPS forecast ${index} outcome must index one of its ${probabilities.length} levels`);
150
- let cumulative = 0;
151
- let sum = 0;
152
- for (let level = 0; level < probabilities.length - 1; level++) {
153
- cumulative += probabilities[level];
154
- sum += (cumulative - (level >= forecast.outcome ? 1 : 0)) ** 2;
155
- }
156
- total += sum / (probabilities.length - 1);
157
- }
158
- return total / forecasts.length;
159
- }
160
- function categoricalEntries(forecast, index, label) {
161
- if (forecast === null || typeof forecast !== "object" || typeof forecast.outcome !== "string") throw new Error(`${label} forecast ${index} needs probabilities and a string outcome`);
162
- const probabilities = forecast.probabilities;
163
- if (probabilities === null || typeof probabilities !== "object" || Array.isArray(probabilities)) throw new Error(`${label} forecast ${index} probabilities must be an object keyed by outcome`);
164
- const entries = Object.entries(probabilities);
165
- if (entries.length < 2) throw new Error(`${label} forecast ${index} needs at least two outcomes`);
166
- if (!entries.some(([name]) => name === forecast.outcome)) throw new Error(`${label} forecast ${index} has no probability for outcome ${JSON.stringify(forecast.outcome)}`);
167
- assertDistribution(entries.map(([, probability]) => probability), `${label} forecast ${index}`);
168
- return entries;
169
- }
170
- function assertDistribution(probabilities, label) {
171
- let sum = 0;
172
- for (const probability of probabilities) {
173
- if (!(probability >= 0 && probability <= 1)) throw new Error(`${label} has a probability outside [0, 1]: ${probability}`);
174
- sum += probability;
175
- }
176
- if (Math.abs(sum - 1) > 1e-6) throw new Error(`${label} probabilities sum to ${sum}, not 1`);
177
- }
178
- function toBin(chunk, lower, upper) {
179
- const xs = chunk.map((c) => c.evalScore);
180
- const ys = chunk.map((c) => c.outcome);
181
- const evalMean = mean(xs);
182
- const outcomeMean = mean(ys);
183
- return {
184
- lower: lower ?? Math.min(...xs),
185
- upper: upper ?? Math.max(...xs),
186
- n: chunk.length,
187
- evalMean,
188
- outcomeMean,
189
- gap: Math.abs(outcomeMean - evalMean)
190
- };
191
- }
192
- function mean(xs) {
193
- return xs.reduce((sum, value) => sum + value / xs.length, 0);
194
- }
195
- function validateCalibrationRequest(evalMetric, outcomeMetric, options) {
196
- assertUniqueObservationIds([evalMetric], "eval metric");
197
- assertUniqueObservationIds([outcomeMetric], "outcome metric");
198
- if (evalMetric.trim() !== evalMetric || outcomeMetric.trim() !== outcomeMetric) throw new Error("calibration metric identities must not have surrounding whitespace");
199
- if (options.bins !== void 0 && (!Number.isSafeInteger(options.bins) || options.bins < 1)) throw new Error("calibration bins must be a positive safe integer");
200
- if (options.binning !== void 0 && !["equal-width", "equal-frequency"].includes(options.binning)) throw new Error("calibration binning must be equal-width or equal-frequency");
201
- if (options.range !== void 0 && (!Number.isFinite(options.range.lo) || !Number.isFinite(options.range.hi) || !Number.isFinite(options.range.hi - options.range.lo) || options.range.hi < options.range.lo)) throw new Error("calibration range must have finite ordered bounds");
202
- }
203
- //#endregion
204
14
  //#region src/meta-eval/correlation-study.ts
205
15
  /**
206
16
  * Correlation study — "does our eval score predict real-world outcomes?"
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/meta-eval/calibration.ts","../../src/meta-eval/correlation-study.ts","../../src/meta-eval/evaluator-admission.ts","../../src/meta-eval/plants.ts"],"sourcesContent":["/**\n * Calibration curve — binned \"if eval says X, what does reality show?\"\n *\n * Companion to correlationStudy. Raw correlation is a single number;\n * the calibration curve shows *where* the eval is well-calibrated vs\n * overconfident / underconfident. Buckets the eval metric, computes\n * mean outcome per bucket, reports expected-calibration-error (ECE).\n */\n\nimport { runMetricExtractor } from '../trace/query'\nimport type { TraceStore } from '../trace/store'\nimport type { EvalMetricSpec } from './correlation-study'\nimport { assertUniqueObservationIds, reduceOutcomeMetric } from './outcome-observations'\nimport type { DeploymentOutcome, OutcomeStore } from './outcome-store'\n\nexport interface CalibrationBin {\n lower: number\n upper: number\n n: number\n evalMean: number\n outcomeMean: number\n /** |outcomeMean − evalMean|; contributes to ECE weighted by n/total. */\n gap: number\n}\n\nexport interface CalibrationReport {\n evalMetric: string\n outcomeMetric: string\n n: number\n bins: CalibrationBin[]\n /** Expected Calibration Error — Σ (n_i/N) × |outcomeMean_i − evalMean_i|. */\n ece: number\n /** Largest observed difference between a bin's mean score and mean outcome. */\n maxGap: number\n}\n\nexport interface CalibrationOptions {\n /** Positive integer; empty bins are omitted. Default 10. */\n bins?: number\n /** Equal-width (fixed bin edges) or equal-frequency (quantile bins). */\n binning?: 'equal-width' | 'equal-frequency'\n /** Clip eval values to [lo, hi] before binning. */\n range?: { lo: number; hi: number }\n}\n\nexport interface CalibrationPair {\n evalScore: number\n outcome: number\n}\n\nexport async function calibrationCurve(\n traceStore: TraceStore,\n outcomeStore: OutcomeStore,\n evalMetric: EvalMetricSpec,\n outcomeMetric: string,\n options: CalibrationOptions = {},\n): Promise<CalibrationReport | null> {\n const settings = {\n ...options,\n range: options.range === undefined ? undefined : { ...options.range },\n }\n validateCalibrationRequest(evalMetric.id, outcomeMetric, settings)\n const extract = evalMetric.extract ?? runMetricExtractor(evalMetric.id)\n const metricId = evalMetric.id\n const runs = await traceStore.listRuns()\n assertUniqueObservationIds(\n runs.map((run) => run.runId),\n 'runId',\n )\n const outcomes = await outcomeStore.list()\n const byRun = new Map<string, DeploymentOutcome[]>()\n for (const o of outcomes) {\n const arr = byRun.get(o.runId) ?? []\n arr.push(o)\n byRun.set(o.runId, arr)\n }\n\n const pairs: Array<{ x: number; y: number }> = []\n for (const run of runs) {\n const os = byRun.get(run.runId)\n if (!os?.length) continue\n const x = await extract(run, traceStore)\n if (x === null || !Number.isFinite(x)) continue\n const y = reduceOutcomeMetric(os, outcomeMetric, 'latest')\n if (y === null) continue\n pairs.push({ x, y })\n }\n if (pairs.length < 2) return null\n\n return calibrationFromPairs(\n pairs.map((p) => ({ evalScore: p.x, outcome: p.y })),\n metricId,\n outcomeMetric,\n settings,\n )\n}\n\n/** Measure already joined observations without constructing trace and outcome stores. */\nexport function calibrationFromPairs(\n inputPairs: readonly CalibrationPair[],\n evalMetric: string,\n outcomeMetric: string,\n options: CalibrationOptions = {},\n): CalibrationReport | null {\n validateCalibrationRequest(evalMetric, outcomeMetric, options)\n for (const [index, pair] of inputPairs.entries()) {\n if (\n pair === null ||\n typeof pair !== 'object' ||\n !Number.isFinite(pair.evalScore) ||\n !Number.isFinite(pair.outcome)\n ) {\n throw new Error(`calibration pair ${index} must contain finite evalScore and outcome values`)\n }\n }\n const pairs = inputPairs\n if (pairs.length < 2) return null\n\n const numBins = options.bins ?? 10\n const binning = options.binning ?? 'equal-width'\n const xs = pairs.map((p) => p.evalScore)\n const lo = options.range?.lo ?? Math.min(...xs)\n const hi = options.range?.hi ?? Math.max(...xs)\n const span = hi - lo\n if (!Number.isFinite(span)) throw new Error('calibration range span must be finite')\n const clipped = pairs.map((pair) => ({\n ...pair,\n evalScore: Math.min(hi, Math.max(lo, pair.evalScore)),\n }))\n\n const bins: CalibrationBin[] = []\n if (span === 0 || clipped.every((pair) => pair.evalScore === clipped[0]!.evalScore)) {\n bins.push(toBin(clipped))\n } else if (binning === 'equal-frequency') {\n const sorted = [...clipped].sort((a, b) => a.evalScore - b.evalScore)\n const count = Math.min(numBins, sorted.length)\n for (let i = 0; i < count; i++) {\n const start = Math.floor((i * sorted.length) / count)\n const end = Math.floor(((i + 1) * sorted.length) / count)\n bins.push(toBin(sorted.slice(start, end)))\n }\n } else {\n const groups = new Map<number, CalibrationPair[]>()\n for (const pair of clipped) {\n const index = Math.min(numBins - 1, Math.floor(((pair.evalScore - lo) / span) * numBins))\n const group = groups.get(index) ?? []\n group.push(pair)\n groups.set(index, group)\n }\n for (const [index, chunk] of [...groups].sort(([a], [b]) => a - b)) {\n bins.push(toBin(chunk, lo + span * (index / numBins), lo + span * ((index + 1) / numBins)))\n }\n }\n\n const total = bins.reduce((a, b) => a + b.n, 0)\n const ece = bins.reduce((a, b) => a + (b.n / total) * b.gap, 0)\n const maxGap = bins.reduce((a, b) => Math.max(a, b.gap), 0)\n\n return { evalMetric, outcomeMetric, n: pairs.length, bins, ece, maxGap }\n}\n\n/**\n * Mean squared error of probability forecasts against binary outcomes, Σ(p − y)²/N; always\n * forecasting 0.5 scores 0.25. For the reliability table and ECE use `calibrationFromPairs`\n * with `range: { lo: 0, hi: 1 }` (`binning: 'equal-frequency'` gives equal-mass bins).\n */\nexport function brierScore(pairs: readonly CalibrationPair[]): number {\n if (!pairs.length) throw new Error('Brier score requires at least one pair')\n let total = 0\n for (const [index, pair] of pairs.entries()) {\n if (\n pair === null ||\n typeof pair !== 'object' ||\n !(pair.evalScore >= 0 && pair.evalScore <= 1) ||\n (pair.outcome !== 0 && pair.outcome !== 1)\n ) {\n throw new Error(`Brier pair ${index} needs a probability in [0, 1] and an outcome of 0 or 1`)\n }\n total += (pair.evalScore - pair.outcome) ** 2\n }\n return total / pairs.length\n}\n\n/** One categorical forecast: a distribution over named outcomes and the outcome that occurred. */\nexport interface CategoricalForecast {\n /** Probability per outcome name. Must sum to 1 within 1e-6 and include `outcome`. */\n probabilities: Readonly<Record<string, number>>\n outcome: string\n}\n\n/**\n * Multiclass Brier score in its sum form, mean over forecasts of Σₖ(pₖ − yₖ)², range [0, 2].\n * With two outcomes it is twice the binary `brierScore`. A uniform forecast over K outcomes\n * scores 1 − 1/K. The distribution is not renormalized here: repair provider rounding before\n * scoring (`normalizeSystemOneResult` in `/systemone/protocol`), so a defective answer stays\n * visible instead of being scored as if it were valid.\n */\nexport function multiclassBrierScore(forecasts: readonly CategoricalForecast[]): number {\n if (!forecasts.length) throw new Error('multiclass Brier score requires at least one forecast')\n let total = 0\n for (const [index, forecast] of forecasts.entries()) {\n const entries = categoricalEntries(forecast, index, 'multiclass Brier')\n for (const [name, probability] of entries) {\n total += (probability - (name === forecast.outcome ? 1 : 0)) ** 2\n }\n }\n return total / forecasts.length\n}\n\n/** One ordinal forecast: probabilities in level order, lowest level first. */\nexport interface OrdinalForecast {\n probabilities: readonly number[]\n /** Index into `probabilities` of the level that occurred. */\n outcome: number\n}\n\n/**\n * Ranked probability score, mean over forecasts of Σₖ₌₁ᴷ⁻¹(Fₖ − Oₖ)² / (K − 1), where F and O are\n * the cumulative forecast and observation, range [0, 1]. Unlike multiclass Brier it charges\n * less for mass on a level next to the outcome than for mass far from it, which is the right\n * penalty for score questions. With two levels it equals the binary Brier score.\n */\nexport function rankedProbabilityScore(forecasts: readonly OrdinalForecast[]): number {\n if (!forecasts.length) throw new Error('ranked probability score requires at least one forecast')\n let total = 0\n for (const [index, forecast] of forecasts.entries()) {\n const probabilities = forecast?.probabilities\n if (!Array.isArray(probabilities) || probabilities.length < 2) {\n throw new Error(`RPS forecast ${index} needs at least two level probabilities`)\n }\n assertDistribution(probabilities, `RPS forecast ${index}`)\n if (\n !Number.isInteger(forecast.outcome) ||\n forecast.outcome < 0 ||\n forecast.outcome >= probabilities.length\n ) {\n throw new Error(\n `RPS forecast ${index} outcome must index one of its ${probabilities.length} levels`,\n )\n }\n let cumulative = 0\n let sum = 0\n for (let level = 0; level < probabilities.length - 1; level++) {\n cumulative += probabilities[level]!\n sum += (cumulative - (level >= forecast.outcome ? 1 : 0)) ** 2\n }\n total += sum / (probabilities.length - 1)\n }\n return total / forecasts.length\n}\n\nfunction categoricalEntries(\n forecast: CategoricalForecast,\n index: number,\n label: string,\n): [string, number][] {\n if (forecast === null || typeof forecast !== 'object' || typeof forecast.outcome !== 'string') {\n throw new Error(`${label} forecast ${index} needs probabilities and a string outcome`)\n }\n const probabilities = forecast.probabilities\n if (probabilities === null || typeof probabilities !== 'object' || Array.isArray(probabilities)) {\n throw new Error(`${label} forecast ${index} probabilities must be an object keyed by outcome`)\n }\n const entries = Object.entries(probabilities)\n if (entries.length < 2) throw new Error(`${label} forecast ${index} needs at least two outcomes`)\n if (!entries.some(([name]) => name === forecast.outcome)) {\n throw new Error(\n `${label} forecast ${index} has no probability for outcome ${JSON.stringify(forecast.outcome)}`,\n )\n }\n assertDistribution(\n entries.map(([, probability]) => probability),\n `${label} forecast ${index}`,\n )\n return entries\n}\n\nfunction assertDistribution(probabilities: readonly number[], label: string): void {\n let sum = 0\n for (const probability of probabilities) {\n if (!(probability >= 0 && probability <= 1)) {\n throw new Error(`${label} has a probability outside [0, 1]: ${probability}`)\n }\n sum += probability\n }\n if (Math.abs(sum - 1) > 1e-6) throw new Error(`${label} probabilities sum to ${sum}, not 1`)\n}\n\nfunction toBin(chunk: CalibrationPair[], lower?: number, upper?: number): CalibrationBin {\n const xs = chunk.map((c) => c.evalScore)\n const ys = chunk.map((c) => c.outcome)\n const evalMean = mean(xs)\n const outcomeMean = mean(ys)\n return {\n lower: lower ?? Math.min(...xs),\n upper: upper ?? Math.max(...xs),\n n: chunk.length,\n evalMean,\n outcomeMean,\n gap: Math.abs(outcomeMean - evalMean),\n }\n}\n\nfunction mean(xs: number[]): number {\n return xs.reduce((sum, value) => sum + value / xs.length, 0)\n}\n\nfunction validateCalibrationRequest(\n evalMetric: string,\n outcomeMetric: string,\n options: CalibrationOptions,\n): void {\n assertUniqueObservationIds([evalMetric], 'eval metric')\n assertUniqueObservationIds([outcomeMetric], 'outcome metric')\n if (evalMetric.trim() !== evalMetric || outcomeMetric.trim() !== outcomeMetric) {\n throw new Error('calibration metric identities must not have surrounding whitespace')\n }\n if (options.bins !== undefined && (!Number.isSafeInteger(options.bins) || options.bins < 1)) {\n throw new Error('calibration bins must be a positive safe integer')\n }\n if (\n options.binning !== undefined &&\n !['equal-width', 'equal-frequency'].includes(options.binning)\n ) {\n throw new Error('calibration binning must be equal-width or equal-frequency')\n }\n if (\n options.range !== undefined &&\n (!Number.isFinite(options.range.lo) ||\n !Number.isFinite(options.range.hi) ||\n !Number.isFinite(options.range.hi - options.range.lo) ||\n options.range.hi < options.range.lo)\n ) {\n throw new Error('calibration range must have finite ordered bounds')\n }\n}\n","/**\n * Correlation study — \"does our eval score predict real-world outcomes?\"\n *\n * Joins traces and outcomes by runId and reports descriptive correlations.\n * Independent runs are the bootstrap observation unit.\n * Association alone does not establish causation or held-out predictive performance.\n */\n\nimport { runMetricExtractor } from '../trace/query'\nimport type { Run } from '../trace/schema'\nimport type { TraceStore } from '../trace/store'\nimport {\n assertUniqueObservationIds,\n correlationSummary,\n hasVariation,\n reduceOutcomeMetric,\n validateObservationOptions,\n} from './outcome-observations'\nimport type { DeploymentOutcome, OutcomeFilter, OutcomeStore } from './outcome-store'\n\nexport interface EvalMetricSpec {\n id: string\n /** Extract a scalar from a run. Omit it and `id` must name one of\n * `RUN_METRICS`; any other `id` is refused. */\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 } | null\n /** 95% bootstrap CI for Spearman; null when no resample is estimable. */\n spearmanCi95: { lower: number; upper: number } | null\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 /** Declared pairs without an estimable correlation, including their usable sample count. */\n excludedPairs: Array<\n OutcomePair & {\n n: number\n reason: 'insufficient_samples' | 'constant_eval_metric' | 'constant_outcome'\n }\n >\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 /** Seed for the bootstrap resampler. Absent, the seed is derived from the\n * paired observations, so the same study reproduces the same interval. */\n seed?: 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 reduction = options.reduction ?? 'latest'\n const iterations = options.bootstrapIterations ?? 500\n const seed = options.seed\n validateObservationOptions(reduction, iterations, seed)\n assertUniqueObservationIds(\n evalMetrics.map((metric) => metric.id),\n 'eval metric',\n )\n assertUniqueObservationIds(outcomeMetricNames, 'outcome metric')\n const maxLag = options.maxCaptureLagMs ?? Infinity\n if (maxLag < 0 || Number.isNaN(maxLag)) {\n throw new Error('maxCaptureLagMs must be nonnegative')\n }\n const extractors = evalMetrics.map((metric) => ({\n ...metric,\n extract: metric.extract ?? runMetricExtractor(metric.id),\n }))\n const metricNames = [...outcomeMetricNames]\n const runs = await traceStore.listRuns()\n assertUniqueObservationIds(\n runs.map((run) => run.runId),\n 'runId',\n )\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 pairs: Array<{ evalMetric: string; outcomeMetric: string; xs: number[]; ys: number[] }> = []\n for (const em of extractors) {\n for (const om of metricNames) {\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) => {\n const lag = o.capturedAt - run.startedAt\n return lag >= 0 && lag <= maxLag\n })\n if (eligible.length === 0) {\n skipped++\n continue\n }\n\n let joinedThisRun = false\n for (const em of extractors) {\n const x = await em.extract(run, traceStore)\n if (x === null || !Number.isFinite(x)) continue\n\n for (const om of metricNames) {\n const y = reduceOutcomeMetric(eligible, om, reduction)\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 joinedThisRun = true\n }\n }\n if (joinedThisRun) joined++\n else skipped++\n }\n\n const excludedPairs: CorrelationStudyResult['excludedPairs'] = []\n const results: CorrelationResult[] = []\n for (const p of pairs) {\n const reason =\n p.xs.length < 3\n ? 'insufficient_samples'\n : !hasVariation(p.xs)\n ? 'constant_eval_metric'\n : !hasVariation(p.ys)\n ? 'constant_outcome'\n : null\n if (reason !== null) {\n excludedPairs.push({\n evalMetric: p.evalMetric,\n outcomeMetric: p.outcomeMetric,\n n: p.xs.length,\n reason,\n })\n continue\n }\n const summary = correlationSummary(p.xs, p.ys, iterations, seed)\n const verdict: CorrelationResult['verdict'] =\n Math.abs(summary.pearson) >= 0.7\n ? 'strong'\n : Math.abs(summary.pearson) >= 0.4\n ? 'moderate'\n : 'weak'\n results.push({\n evalMetric: p.evalMetric,\n outcomeMetric: p.outcomeMetric,\n n: p.xs.length,\n ...summary,\n verdict,\n })\n }\n return { pairs: results, excludedPairs, joinedSamples: joined, skippedRuns: skipped }\n}\n","import { z } from 'zod'\nimport { ValidationError } from '../errors'\nimport { type ComputedInterval, computeInterval } from '../experiment/ast/interval'\nimport { compareCodeUnits, hashCanonical, type LedgerHash } from '../ledger-core/canonical'\n\nconst identity = z\n .string()\n .min(1)\n .refine((value) => value.trim() === value)\nexport const evaluatorAdmissionPolicySchema = z\n .object({\n confidence: z.number().finite().gt(0).lt(1),\n maxFalseAcceptanceRate: z.number().finite().min(0).lt(1),\n maxFalseRejectionRate: z.number().finite().min(0).lt(1),\n })\n .strict()\n\n/** Register both error limits before inspecting audit judgments. */\nexport type EvaluatorAdmissionPolicy = z.infer<typeof evaluatorAdmissionPolicySchema>\n\nexport const evaluatorAuditObservationSchema = z\n .object({\n id: identity,\n independentUnitId: identity,\n evidenceRef: identity,\n expected: z.enum(['accept', 'reject']),\n observed: z.enum(['accept', 'reject', 'unknown']),\n exposure: z.enum(['fresh', 'development']),\n })\n .strict()\n\n/** Actual control judgments. Variants from one source retain one independent identity. */\nexport type EvaluatorAuditObservation = z.infer<typeof evaluatorAuditObservationSchema>\n\nconst inputSchema = z\n .object({\n evaluatorDigest: z.string().regex(/^sha256:[a-f0-9]{64}$/),\n population: identity,\n samplingFrame: identity,\n authority: z\n .object({\n evaluatorAuthorId: identity,\n auditorId: identity,\n independenceEvidenceRef: identity,\n })\n .strict(),\n policy: evaluatorAdmissionPolicySchema,\n observations: z.array(evaluatorAuditObservationSchema),\n })\n .strict()\n\nexport type EvaluatorAuditInput = z.infer<typeof inputSchema>\n\nexport interface EvaluatorErrorRate {\n /** Eligible control judgments in this class, including unknown judgments. */\n cases: number\n independentUnits: number\n /** Units with at least one observed mistake. */\n errorUnits: number\n /** Units with unknown judgments and no observed mistake yet. */\n unresolvedUnits: number\n unknownCases: number\n /** Missing judgments do not become measured zeros. */\n errorRate: number | null\n /** Exact bounds conservatively include every possible outcome of unknown judgments. */\n interval: ComputedInterval | null\n limit: number\n verdict: 'pass' | 'fail' | 'inconclusive'\n}\n\nexport interface EvaluatorAdmissionReport {\n evaluatorDigest: LedgerHash\n policyDigest: LedgerHash\n inputDigest: LedgerHash\n reportDigest: LedgerHash\n population: string\n samplingFrame: string\n authority: EvaluatorAuditInput['authority']\n policy: EvaluatorAdmissionPolicy\n /** Joint coverage for the two reported error-rate intervals. */\n confidence: number\n intervalConfidence: number\n verdict: 'admit' | 'reject' | 'inconclusive'\n reasons: string[]\n observations: EvaluatorAuditObservation[]\n coverage: {\n cases: number\n independentUnits: number\n eligibleCases: number\n eligibleIndependentUnits: number\n excludedCases: number\n unknownCases: number\n }\n exclusions: Array<{ id: string; independentUnitId: string; reason: 'development-exposure' }>\n falseAcceptance: EvaluatorErrorRate\n falseRejection: EvaluatorErrorRate\n}\n\nfunction errorRate(\n rows: readonly EvaluatorAuditObservation[],\n expected: 'accept' | 'reject',\n limit: number,\n level: number,\n): EvaluatorErrorRate {\n const cases = rows.filter((row) => row.expected === expected)\n const units = new Map<string, { error: boolean; unknown: boolean }>()\n for (const row of cases) {\n const unit = units.get(row.independentUnitId) ?? { error: false, unknown: false }\n unit.unknown ||= row.observed === 'unknown'\n unit.error ||= row.observed !== 'unknown' && row.observed !== expected\n units.set(row.independentUnitId, unit)\n }\n const n = units.size\n const errorUnits = [...units.values()].filter((unit) => unit.error).length\n const unresolvedUnits = [...units.values()].filter((unit) => unit.unknown && !unit.error).length\n const unknownCases = cases.filter((row) => row.observed === 'unknown').length\n // Unknown judgments contribute to n; their most favorable and adverse outcomes bound the rate.\n const interval =\n n === 0\n ? null\n : {\n lower: computeInterval(\n { kind: 'clopper-pearson', level },\n {\n kind: 'binomial',\n successes: errorUnits,\n trials: n,\n },\n ).lower,\n upper: computeInterval(\n { kind: 'clopper-pearson', level },\n {\n kind: 'binomial',\n successes: errorUnits + unresolvedUnits,\n trials: n,\n },\n ).upper,\n level,\n }\n const verdict =\n interval && interval.lower > limit\n ? 'fail'\n : interval && interval.upper <= limit\n ? 'pass'\n : 'inconclusive'\n return {\n cases: cases.length,\n independentUnits: n,\n errorUnits,\n unresolvedUnits,\n unknownCases,\n errorRate: n === 0 || unresolvedUnits > 0 ? null : errorUnits / n,\n interval,\n limit,\n verdict,\n }\n}\n\nfunction eligibleControls<\n T extends Pick<EvaluatorAuditObservation, 'id' | 'independentUnitId' | 'exposure'>,\n>(observations: T[]) {\n const ids = new Set<string>()\n for (const row of observations) {\n if (ids.has(row.id))\n throw new ValidationError(`duplicate evaluator audit observation '${row.id}'`)\n ids.add(row.id)\n }\n observations.sort((a, b) => compareCodeUnits(a.id, b.id))\n const developmentUnits = new Set(\n observations\n .filter((row) => row.exposure === 'development')\n .map((row) => row.independentUnitId),\n )\n const eligible = observations.filter((row) => !developmentUnits.has(row.independentUnitId))\n const exclusions = observations\n .filter((row) => developmentUnits.has(row.independentUnitId))\n .map((row) => ({\n id: row.id,\n independentUnitId: row.independentUnitId,\n reason: 'development-exposure' as const,\n }))\n return { eligible, exclusions }\n}\n\nfunction simultaneousIntervalConfidence(confidence: number): number {\n const level = 1 - (1 - confidence) / 2\n if (level >= 1)\n throw new ValidationError(\n 'evaluator audit confidence is too close to one for simultaneous intervals',\n )\n return level\n}\n\nconst capacitySchema = z\n .object({\n policy: evaluatorAdmissionPolicySchema,\n controls: z\n .array(evaluatorAuditObservationSchema.omit({ observed: true, evidenceRef: true }))\n .default([]),\n })\n .strict()\n\nexport type EvaluatorAuditPlanInput = z.input<typeof capacitySchema>\n\n/** The zero-error eligibility floor, not a statistical power calculation. */\nfunction zeroErrorUpperBound(trials: number, level: number): number {\n return -Math.expm1(Math.log((1 - level) / 2) / trials)\n}\n\nfunction minimumAuditUnits(limit: number, level: number): number | null {\n if (limit === 0) return null\n const estimate = Math.ceil(Math.log((1 - level) / 2) / Math.log1p(-limit))\n if (!Number.isFinite(estimate) || estimate > Number.MAX_SAFE_INTEGER) return null\n const clears = (trials: number) => zeroErrorUpperBound(trials, level) <= limit\n let minimum = Math.max(1, estimate)\n while (minimum > 1 && clears(minimum - 1)) minimum -= 1\n while (!clears(minimum)) {\n if (minimum === Number.MAX_SAFE_INTEGER) return null\n minimum += 1\n }\n return minimum\n}\n\n/**\n * Can the fixed control roster meet the policy even with zero errors?\n * Planning uses the admission rule's exact bounds and source-unit exclusions.\n * It accepts no judgments or authority and returns no admission report.\n */\nexport function planEvaluatorAudit(input: EvaluatorAuditPlanInput) {\n const parsed = capacitySchema.safeParse(input)\n if (!parsed.success)\n throw new ValidationError(`invalid evaluator audit plan: ${parsed.error.message}`)\n const { policy, controls } = parsed.data\n const { eligible } = eligibleControls(controls)\n const level = simultaneousIntervalConfidence(policy.confidence)\n const capacity = (expected: EvaluatorAuditObservation['expected'], limit: number) => {\n const independentUnits = new Set(\n eligible.filter((row) => row.expected === expected).map((row) => row.independentUnitId),\n ).size\n const bestPossibleUpperBound =\n independentUnits === 0 ? null : zeroErrorUpperBound(independentUnits, level)\n const minimumIndependentUnits = minimumAuditUnits(limit, level)\n return {\n independentUnits,\n bestPossibleUpperBound,\n limit,\n minimumIndependentUnits,\n additionalIndependentUnits:\n minimumIndependentUnits === null\n ? null\n : Math.max(0, minimumIndependentUnits - independentUnits),\n }\n }\n const falseAcceptance = capacity('reject', policy.maxFalseAcceptanceRate)\n const falseRejection = capacity('accept', policy.maxFalseRejectionRate)\n const sufficient = [falseAcceptance, falseRejection].every(\n (rate) => rate.bestPossibleUpperBound !== null && rate.bestPossibleUpperBound <= rate.limit,\n )\n return { sufficient, falseAcceptance, falseRejection }\n}\n\nexport type EvaluatorAuditPlan = ReturnType<typeof planEvaluatorAudit>\n\n/**\n * Audit frozen judgments using independent source units and exact binomial bounds.\n * A unit fails a class when any control in that class is misjudged.\n * The execution owner enforces auditor separation, fresh sampling, and evidence authenticity.\n */\nexport function auditEvaluator(input: EvaluatorAuditInput): EvaluatorAdmissionReport {\n const parsed = inputSchema.safeParse(input)\n if (!parsed.success) throw new ValidationError(`invalid evaluator audit: ${parsed.error.message}`)\n const audit = parsed.data\n if (audit.authority.evaluatorAuthorId === audit.authority.auditorId) {\n throw new ValidationError('evaluator admission requires a separate declared audit authority')\n }\n const { eligible, exclusions } = eligibleControls(audit.observations)\n const intervalConfidence = simultaneousIntervalConfidence(audit.policy.confidence)\n const falseAcceptance = errorRate(\n eligible,\n 'reject',\n audit.policy.maxFalseAcceptanceRate,\n intervalConfidence,\n )\n const falseRejection = errorRate(\n eligible,\n 'accept',\n audit.policy.maxFalseRejectionRate,\n intervalConfidence,\n )\n const rates = [falseAcceptance, falseRejection]\n const verdict = rates.some((rate) => rate.verdict === 'fail')\n ? 'reject'\n : rates.every((rate) => rate.verdict === 'pass')\n ? 'admit'\n : 'inconclusive'\n const reasons: string[] = []\n for (const [name, rate] of [\n ['false acceptance', falseAcceptance],\n ['false rejection', falseRejection],\n ] as const) {\n if (rate.independentUnits === 0) reasons.push(`${name}: no eligible independent units`)\n else if (rate.unknownCases > 0)\n reasons.push(`${name}: ${rate.unknownCases} judgments are unknown`)\n if (rate.verdict === 'fail') reasons.push(`${name}: lower error bound exceeds ${rate.limit}`)\n else if (rate.verdict === 'inconclusive' && rate.interval)\n reasons.push(`${name}: upper error bound does not establish the required limit`)\n }\n if (verdict === 'admit')\n reasons.push(\n 'both error bounds meet the registered limits, including the worst case for unknown judgments',\n )\n const body: Omit<EvaluatorAdmissionReport, 'reportDigest'> = {\n evaluatorDigest: audit.evaluatorDigest as LedgerHash,\n policyDigest: hashCanonical(audit.policy),\n inputDigest: hashCanonical(audit),\n population: audit.population,\n samplingFrame: audit.samplingFrame,\n authority: audit.authority,\n policy: audit.policy,\n confidence: audit.policy.confidence,\n intervalConfidence,\n verdict,\n reasons,\n observations: audit.observations,\n coverage: {\n cases: audit.observations.length,\n independentUnits: new Set(audit.observations.map((row) => row.independentUnitId)).size,\n eligibleCases: eligible.length,\n eligibleIndependentUnits: new Set(eligible.map((row) => row.independentUnitId)).size,\n excludedCases: exclusions.length,\n unknownCases: eligible.filter((row) => row.observed === 'unknown').length,\n },\n exclusions,\n falseAcceptance,\n falseRejection,\n }\n return { ...body, reportDigest: hashCanonical(body) }\n}\n\nconst probabilityThresholdsSchema = z\n .object({\n rejectAtOrBelow: z.number().finite().min(0).max(1),\n acceptAtOrAbove: z.number().finite().min(0).max(1),\n })\n .strict()\n .refine((value) => value.rejectAtOrBelow < value.acceptAtOrAbove, {\n message: 'rejection and acceptance thresholds must not overlap',\n })\nconst probabilityObservationSchema = evaluatorAuditObservationSchema\n .omit({ observed: true })\n .extend({ acceptProbability: z.number().finite().min(0).max(1).nullable() })\n .strict()\nconst probabilityAuditSchema = inputSchema.extend({\n thresholds: probabilityThresholdsSchema,\n observations: z.array(probabilityObservationSchema),\n})\n\n/** A frozen caller-owned rule over P(accept), not the provider's entropy/confidence statistic. */\nexport type ProbabilityPolicyAuditInput = z.infer<typeof probabilityAuditSchema>\n\nexport interface ProbabilityPolicyAuditReport extends EvaluatorAdmissionReport {\n probabilityPolicy: {\n sourceEvaluatorDigest: LedgerHash\n thresholds: ProbabilityPolicyAuditInput['thresholds']\n /** Retain probabilities by observation id so the reported mapping can be reproduced. */\n observations: Array<{ id: string; acceptProbability: number | null }>\n }\n}\n\n/**\n * Audit a fixed probability-to-decision rule with the existing independent-unit error bounds.\n * No threshold search, model calls, promotion, or assumption of calibrated probabilities.\n * Null scores and the open interval between thresholds remain unknown, never correct by default.\n */\nexport function auditProbabilityPolicy(\n input: ProbabilityPolicyAuditInput,\n): ProbabilityPolicyAuditReport {\n const parsed = probabilityAuditSchema.safeParse(input)\n if (!parsed.success) {\n throw new ValidationError(`invalid probability policy audit: ${parsed.error.message}`)\n }\n const { thresholds, observations, ...source } = parsed.data\n observations.sort((a, b) => compareCodeUnits(a.id, b.id))\n const probabilityPolicy = {\n sourceEvaluatorDigest: source.evaluatorDigest as LedgerHash,\n thresholds,\n observations: observations.map(({ id, acceptProbability }) => ({ id, acceptProbability })),\n }\n const audit = auditEvaluator({\n ...source,\n evaluatorDigest: hashCanonical({\n kind: 'probability-policy-v1',\n sourceEvaluatorDigest: source.evaluatorDigest,\n thresholds,\n }),\n observations: observations.map(({ acceptProbability, ...observation }) => ({\n ...observation,\n observed:\n acceptProbability === null\n ? 'unknown'\n : acceptProbability >= thresholds.acceptAtOrAbove\n ? 'accept'\n : acceptProbability <= thresholds.rejectAtOrBelow\n ? 'reject'\n : 'unknown',\n })),\n })\n const { reportDigest: _baseDigest, ...baseReport } = audit\n const body = {\n ...baseReport,\n // Bind the actual probabilities too, including changes that select the same action.\n inputDigest: hashCanonical(parsed.data),\n probabilityPolicy,\n }\n return { ...body, reportDigest: hashCanonical(body) }\n}\n","/**\n * Plants — seeded known-wrong items that measure the grader, not the work.\n *\n * A grading run reports how the work scored. It cannot report whether the\n * grader would have noticed a wrong answer, because every item it saw was\n * authored in good faith. A plant closes that hole: an item authored wrong by\n * construction is mixed into the live set, graded by the same path as\n * everything else, and the share of plants the grader refused is the catch\n * rate.\n *\n * Measured motive: a sibling lab ran a deliverable gate that accepted any\n * non-empty submission. It produced six false certifications in seventeen\n * deliveries, and no agent lied — the gate never asked a question the format\n * could fail. A catch rate is the number that would have shown it on day one.\n *\n * This module composes existing primitives rather than adding parallel ones:\n *\n * - A plant IS a {@link GoldenItem} from `../judge-calibration`. Its\n * `humanScore` is the grade a working grader owes the item, so the same\n * array feeds `calibrateJudge` unchanged.\n * - The grader's output is `CandidateScore[]`, the array `calibrateJudge` and\n * `snapshotFromSentinelSet` already consume.\n * - \"Caught\" is `snapshotFromSentinelSet`'s join with the labels inverted:\n * the grade lands on the side of `acceptThreshold` the seed demands.\n * - The manifest is sealed with `hashCanonical` from `../ledger-core/canonical`,\n * the digest the sealed-experiment path uses, so the answer key cannot be\n * revised once the results are in.\n *\n * Authoring the wrong item is the step before all of that, and it is where the\n * measurement silently breaks. {@link plantByPerturbation} takes a claim a\n * grader verified and alters exactly one load-bearing value in its evidence,\n * so the grader is asked a question it must fail. Hand-rolled perturbation\n * bumps a number that is part of an identity — `python3`, `file42.txt`, `1.5`,\n * `utf-8` — and the check stops EXECUTING; the plant then measures the\n * environment rather than the grader. {@link perturbEvidence} refuses those\n * digit runs by construction.\n *\n * Blindness has two halves, and this module owns one. It never puts a plant\n * flag on a graded item: `seedPlants` returns the mixed set and a manifest,\n * and only the manifest knows which ids are seeded. Keeping the manifest out\n * of the graded workspace and publishing its `seal` before grading is the\n * caller's half; {@link catchRate} refuses a manifest whose contents no longer\n * match its seal.\n *\n * Refusals, because a catch rate that cannot refuse is not a measurement:\n *\n * - a seeded id with no result makes the report `incomplete`, never a rate\n * over the results that did come back;\n * - zero seeded plants makes it `not_evaluated`, never 1.0;\n * - a result for an id the manifest never handed out is refused outright.\n */\n\nimport { CaptureIntegrityError, ValidationError } from '../errors'\nimport type { GoldenItem } from '../judge-calibration'\nimport { hashCanonical, type LedgerHash } from '../ledger-core/canonical'\nimport { mulberry32 } from '../statistics/random'\n\n/**\n * How a plant item was authored wrong. The class is reported separately in\n * {@link CatchRateReport.byKind} because a grader is routinely sharp on one\n * and blind to another.\n */\nexport type PlantKind =\n /** A load-bearing value is altered: a number off by one, a comparison flipped. */\n | 'wrong-value'\n /** The item carries its own check, and that check passes without testing the claim. */\n | 'self-certifying'\n /** The check names an input that does not exist, so it cannot run at all. */\n | 'unreachable-input'\n /** A copy of an item already in the set, which is owed a duplicate flag rather than a second grade. */\n | 'duplicate'\n\nconst PLANT_KINDS: readonly PlantKind[] = [\n 'wrong-value',\n 'self-certifying',\n 'unreachable-input',\n 'duplicate',\n]\n\n/** What a working grader owes a seeded item. */\nexport type PlantExpectation = 'reject' | 'accept'\n\nconst PLANT_EXPECTATIONS: readonly PlantExpectation[] = ['reject', 'accept']\n\n/** The label boundary a plant record is checked against at definition time. */\nconst RECORD_LABEL_BOUNDARY = 0.5\n\nexport interface Plant {\n /** Name of the plant record. Reported in `missedIds` and `missingIds`. */\n id: string\n kind: PlantKind\n /** The seeded item, indistinguishable from a real one once mixed. */\n item: GoldenItem\n /** The verdict a working grader owes this item. */\n expectedVerdict: PlantExpectation\n}\n\n/**\n * Build one plant record and refuse an incoherent one.\n *\n * The refusal that matters is the last: a record whose `expectedVerdict`\n * disagrees with `item.humanScore` inverts the measurement silently, because\n * the same item then reads as wrong here and as correct to every calibration\n * instrument that joins on the id.\n *\n * `item` is copied field by field so a later mutation of the caller's object\n * cannot change what the manifest sealed, and `group` is dropped when it is\n * absent so the record always has a canonical JSON form.\n */\nexport function definePlant(input: {\n id: string\n kind: PlantKind\n item: GoldenItem\n expectedVerdict: PlantExpectation\n}): Plant {\n const { id, kind, item, expectedVerdict } = input\n if (typeof id !== 'string' || id.trim() === '') {\n throw new ValidationError('definePlant: id must be a non-empty string')\n }\n if (!PLANT_KINDS.includes(kind)) {\n throw new ValidationError(\n `definePlant: plant \"${id}\" has kind ${JSON.stringify(kind)}; expected one of ${PLANT_KINDS.join(', ')}`,\n )\n }\n if (!PLANT_EXPECTATIONS.includes(expectedVerdict)) {\n throw new ValidationError(\n `definePlant: plant \"${id}\" has expectedVerdict ${JSON.stringify(expectedVerdict)}; expected one of ${PLANT_EXPECTATIONS.join(', ')}`,\n )\n }\n if (typeof item.itemId !== 'string' || item.itemId.trim() === '') {\n throw new ValidationError(`definePlant: plant \"${id}\" has an empty item.itemId`)\n }\n if (!Number.isFinite(item.humanScore) || item.humanScore < 0 || item.humanScore > 1) {\n throw new ValidationError(\n `definePlant: plant \"${id}\" has humanScore ${item.humanScore}; expected a finite number in [0, 1]`,\n )\n }\n if (item.group !== undefined && typeof item.group !== 'string') {\n throw new ValidationError(`definePlant: plant \"${id}\" has a non-string item.group`)\n }\n if (item.humanScore === RECORD_LABEL_BOUNDARY) {\n throw new ValidationError(\n `definePlant: plant \"${id}\" has humanScore ${RECORD_LABEL_BOUNDARY}, which states neither a rejection nor an acceptance`,\n )\n }\n const labelSays: PlantExpectation = item.humanScore < RECORD_LABEL_BOUNDARY ? 'reject' : 'accept'\n if (labelSays !== expectedVerdict) {\n throw new ValidationError(\n `definePlant: plant \"${id}\" expects the grader to ${expectedVerdict} it, but humanScore ${item.humanScore} says ${labelSays}`,\n )\n }\n return {\n id,\n kind,\n item: {\n itemId: item.itemId,\n humanScore: item.humanScore,\n ...(item.group === undefined ? {} : { group: item.group }),\n },\n expectedVerdict,\n }\n}\n\n/**\n * A claim's executable evidence: the command a grader runs and the output it\n * must produce.\n */\nexport interface PlantEvidence {\n /** The command a grader runs to test the claim. */\n check?: string\n /** The output that command must produce for the claim to stand. */\n expect?: string\n}\n\n/** Which evidence field {@link perturbEvidence} altered. */\nexport type PerturbedField = 'check' | 'expect'\n\n/** How {@link perturbEvidence} altered it. */\nexport type PerturbationKind = 'number-off-by-one' | 'comparison-flipped'\n\nexport interface EvidencePerturbation {\n /** The evidence with exactly one value altered. */\n evidence: PlantEvidence\n /** Which field changed. */\n field: PerturbedField\n /** How it changed. */\n how: PerturbationKind\n /**\n * The exact substring that was replaced. A comparison token carries its\n * surrounding spaces, because the spaces are what make ` -ge ` a comparison\n * and not part of a word.\n */\n original: string\n /** What replaced it. */\n perturbed: string\n}\n\n/**\n * Characters that make a digit run part of something larger than a number.\n *\n * A run that touches one of these is an identity — `python3`, `file42.txt`,\n * `1.5`, `utf-8` — and bumping it renames a program, a file, a version, or an\n * encoding instead of falsifying the claim. The check then stops EXECUTING,\n * and a plant that cannot run measures the environment rather than the grader:\n * it reads as caught, for a reason that has nothing to do with the seeded\n * defect.\n */\nconst NUMBER_GLUE = /[A-Za-z0-9_./-]/\n\n/**\n * Comparison tokens that mean one thing only, each with its inversion.\n *\n * A bare `>` or `<` is absent on purpose: in a shell check it is a\n * redirection, so flipping it rewrites where output goes rather than what the\n * test asks, and the check stops testing the claim.\n */\nconst COMPARISON_FLIPS: readonly (readonly [string, string])[] = [\n [' -ge ', ' -lt '],\n [' -gt ', ' -le '],\n [' -le ', ' -gt '],\n [' -lt ', ' -ge '],\n [' -eq ', ' -ne '],\n [' -ne ', ' -eq '],\n ['>=', '<'],\n ['<=', '>'],\n ['==', '!='],\n ['!=', '=='],\n]\n\ninterface Span {\n start: number\n end: number\n}\n\n/**\n * The last digit run in `text` that is a number and nothing else, or null.\n *\n * The last is taken because a measured value trails its label — `count=42`,\n * `n>=5 OK cells=8` — and because the choice has to be deterministic: the same\n * claim must always yield the same plant, or two runs of the same authoring\n * step seed two different answer keys for one item.\n */\nfunction lastStandaloneNumber(text: string): Span | null {\n const digits = /\\d+/g\n let found: Span | null = null\n let match = digits.exec(text)\n while (match !== null) {\n const start = match.index\n const end = start + match[0].length\n // charAt returns '' outside the string, and NUMBER_GLUE never matches ''.\n if (!NUMBER_GLUE.test(text.charAt(start - 1)) && !NUMBER_GLUE.test(text.charAt(end))) {\n found = { start, end }\n }\n match = digits.exec(text)\n }\n return found\n}\n\n/**\n * The first flippable comparison in `text`, or null.\n *\n * Any single flip inverts the test wherever it sits, so unlike the number rule\n * there is no safety ordering among the matches. The first is taken so the\n * result is fixed by the head of the command and does not move when a later\n * comparison is added.\n */\nfunction firstComparison(text: string): { span: Span; flipped: string } | null {\n for (let index = 0; index < text.length; index += 1) {\n for (const [token, flipped] of COMPARISON_FLIPS) {\n if (text.startsWith(token, index)) {\n return { span: { start: index, end: index + token.length }, flipped }\n }\n }\n }\n return null\n}\n\nfunction replaceSpan(text: string, span: Span, value: string): string {\n return text.slice(0, span.start) + value + text.slice(span.end)\n}\n\n/**\n * Rebuild the evidence with one field replaced. An absent field is dropped\n * rather than set to undefined, so the record always has a canonical JSON form.\n */\nfunction withField(\n check: string | undefined,\n expect: string | undefined,\n field: PerturbedField,\n value: string,\n): PlantEvidence {\n const nextCheck = field === 'check' ? value : check\n const nextExpect = field === 'expect' ? value : expect\n return {\n ...(nextCheck === undefined ? {} : { check: nextCheck }),\n ...(nextExpect === undefined ? {} : { expect: nextExpect }),\n }\n}\n\nfunction offByOne(\n check: string | undefined,\n expect: string | undefined,\n field: PerturbedField,\n text: string,\n span: Span,\n): EvidencePerturbation {\n const original = text.slice(span.start, span.end)\n const perturbed = (BigInt(original) + 1n).toString()\n return {\n evidence: withField(check, expect, field, replaceSpan(text, span, perturbed)),\n field,\n how: 'number-off-by-one',\n original,\n perturbed,\n }\n}\n\n/**\n * Derive a known-wrong version of a claim's evidence by altering exactly one\n * value, or return null when no value can be altered safely.\n *\n * Exactly one value changes. A perturbation that moves two does not name the\n * defect it seeded, so a grader that catches it says nothing about which defect\n * the grader can see.\n *\n * The preference order IS the safety order:\n *\n * 1. the last standalone number in `expect` — it falsifies the claim while the\n * command still runs exactly as it did;\n * 2. a flipped comparison in `check` — it inverts a test that was passing;\n * 3. the last standalone number in `check` — last because a number in a command\n * can name an input (a port, a width, a version) rather than a threshold,\n * and renaming an input breaks execution, not the claim.\n *\n * \"Standalone\" excludes a digit run glued to a word, a dot, a slash, or a\n * hyphen: `python3`, `file42.txt`, `1.5`, `utf-8`. That exclusion is why this\n * helper exists. Hand-rolled perturbation bumps one of those, the check stops\n * executing, and the plant measures the environment instead of the grader.\n *\n * A number is bumped with BigInt, so a value wider than\n * `Number.MAX_SAFE_INTEGER` moves by exactly one. Bumped as a `number` it\n * rounds back to itself, and the plant is then a correct claim the grader is\n * right to verify.\n */\nexport function perturbEvidence(evidence: PlantEvidence): EvidencePerturbation | null {\n const check = typeof evidence.check === 'string' ? evidence.check : undefined\n const expect = typeof evidence.expect === 'string' ? evidence.expect : undefined\n\n if (expect !== undefined) {\n const span = lastStandaloneNumber(expect)\n if (span !== null) return offByOne(check, expect, 'expect', expect, span)\n }\n if (check !== undefined) {\n const comparison = firstComparison(check)\n if (comparison !== null) {\n return {\n evidence: withField(\n check,\n expect,\n 'check',\n replaceSpan(check, comparison.span, comparison.flipped),\n ),\n field: 'check',\n how: 'comparison-flipped',\n original: check.slice(comparison.span.start, comparison.span.end),\n perturbed: comparison.flipped,\n }\n }\n const span = lastStandaloneNumber(check)\n if (span !== null) return offByOne(check, expect, 'check', check, span)\n }\n return null\n}\n\nexport interface PerturbedPlant {\n plant: Plant\n /** The perturbed evidence to write into the item the grader is handed. */\n evidence: PlantEvidence\n field: PerturbedField\n how: PerturbationKind\n original: string\n perturbed: string\n}\n\n/**\n * Derive a reject-direction plant from a claim a grader verified, by perturbing\n * one value.\n *\n * {@link definePlant} takes a {@link GoldenItem} and never authors a wrong item\n * from a right one, so until now every caller hand-rolled the perturbation.\n * This is that step, done once and the same way every time: the claim's\n * evidence is altered by {@link perturbEvidence}, the result is a `wrong-value`\n * plant the grader owes a `reject`, and the record itself is built by\n * `definePlant` so every refusal there still applies — in particular the one\n * that catches an `expectedVerdict` its `humanScore` contradicts.\n *\n * Returns null when nothing in the evidence can be perturbed. That is not a\n * failure: a claim with no executable evidence cannot be made wrong in a way a\n * grader could execute, and seeding it would measure prose.\n *\n * Refuses an empty `id` or `itemId`. Both name the record — one in the manifest\n * and in `missedIds`, the other in the join with the results — and a miss\n * nobody can look up is not a measurement.\n */\nexport function plantByPerturbation(input: {\n id: string\n itemId: string\n evidence: PlantEvidence\n /** Score for the perturbed item. Must sit below the run's accept threshold. Default 0. */\n humanScore?: number\n group?: string\n}): PerturbedPlant | null {\n const { id, itemId, evidence, humanScore = 0, group } = input\n if (typeof id !== 'string' || id.trim() === '') {\n throw new ValidationError('plantByPerturbation: id must be a non-empty string')\n }\n if (typeof itemId !== 'string' || itemId.trim() === '') {\n throw new ValidationError(`plantByPerturbation: plant \"${id}\" has an empty itemId`)\n }\n const perturbation = perturbEvidence(evidence)\n if (perturbation === null) return null\n const plant = definePlant({\n id,\n kind: 'wrong-value',\n item: { itemId, humanScore, ...(group === undefined ? {} : { group }) },\n expectedVerdict: 'reject',\n })\n return {\n plant,\n evidence: perturbation.evidence,\n field: perturbation.field,\n how: perturbation.how,\n original: perturbation.original,\n perturbed: perturbation.perturbed,\n }\n}\n\nexport interface PlantManifest {\n /**\n * Digest over the seeded order, the plants, and the threshold. Publish it\n * before the grading run: a manifest edited afterwards to match the results\n * no longer matches its seal, and {@link catchRate} refuses it.\n */\n seal: LedgerHash\n /** The seed that fixed the mix order. */\n seed: number\n /** The grade at or above which the graded policy's own gate accepts an item. */\n acceptThreshold: number\n /** Every item id in the seeded set, in the order handed out. */\n itemIds: string[]\n /** The seeded plants. This is the answer key; keep it out of the graded workspace. */\n plants: Plant[]\n}\n\nexport interface SeededGradingSet {\n /**\n * The mixed set in seeded order. Operator-side: it still carries every\n * item's `humanScore`, so hand the graded policy the payload each `itemId`\n * names, never this array.\n */\n items: GoldenItem[]\n manifest: PlantManifest\n}\n\nexport interface SeedPlantsOptions {\n /**\n * Fixes the mix order. The same dataset, plants, threshold, and seed always\n * produce the same seeded order and the same seal.\n */\n seed?: number\n /**\n * The grade at or above which the graded policy's own gate accepts an item.\n * Supply the threshold your gate uses; the default suits a judge scoring in\n * [0, 1] with a pass at the midpoint.\n */\n acceptThreshold?: number\n}\n\n/**\n * Mix plants into a grading set and seal which items they are.\n *\n * Refusals: a duplicate id anywhere in the mixed set (the join is by id, so a\n * repeat makes one of the two unscoreable), a plant whose item id collides\n * with a dataset item (it would shadow real work and grade it as a plant), a\n * dataset item with no usable label, and a plant whose expectation the run's\n * `acceptThreshold` contradicts.\n */\nexport function seedPlants(\n dataset: readonly GoldenItem[],\n plants: readonly Plant[],\n options: SeedPlantsOptions = {},\n): SeededGradingSet {\n const seed = options.seed ?? 7\n const acceptThreshold = options.acceptThreshold ?? 0.5\n if (!Number.isFinite(seed)) {\n throw new ValidationError(`seedPlants: seed must be a finite number, got ${seed}`)\n }\n if (!Number.isFinite(acceptThreshold) || acceptThreshold <= 0 || acceptThreshold > 1) {\n throw new ValidationError(\n `seedPlants: acceptThreshold must be a finite number in (0, 1], got ${acceptThreshold}`,\n )\n }\n\n const datasetItems: GoldenItem[] = []\n const seen = new Set<string>()\n for (const item of dataset) {\n if (typeof item.itemId !== 'string' || item.itemId.trim() === '') {\n throw new ValidationError('seedPlants: a dataset item has an empty itemId')\n }\n if (!Number.isFinite(item.humanScore)) {\n throw new ValidationError(\n `seedPlants: dataset item \"${item.itemId}\" has a non-finite humanScore`,\n )\n }\n if (seen.has(item.itemId)) {\n throw new ValidationError(`seedPlants: duplicate dataset itemId \"${item.itemId}\"`)\n }\n seen.add(item.itemId)\n datasetItems.push({\n itemId: item.itemId,\n humanScore: item.humanScore,\n ...(item.group === undefined ? {} : { group: item.group }),\n })\n }\n\n const sealedPlants: Plant[] = []\n const plantIds = new Set<string>()\n for (const plant of plants) {\n const record = definePlant(plant)\n if (plantIds.has(record.id)) {\n throw new ValidationError(`seedPlants: duplicate plant id \"${record.id}\"`)\n }\n if (seen.has(record.item.itemId)) {\n throw new ValidationError(\n `seedPlants: plant \"${record.id}\" reuses itemId \"${record.item.itemId}\", which is already in the set`,\n )\n }\n const thresholdSays: PlantExpectation =\n record.item.humanScore >= acceptThreshold ? 'accept' : 'reject'\n if (thresholdSays !== record.expectedVerdict) {\n throw new ValidationError(\n `seedPlants: plant \"${record.id}\" expects the grader to ${record.expectedVerdict} it, but humanScore ${record.item.humanScore} is on the ${thresholdSays} side of acceptThreshold ${acceptThreshold}`,\n )\n }\n plantIds.add(record.id)\n seen.add(record.item.itemId)\n sealedPlants.push(record)\n }\n\n const items = shuffled(\n [...datasetItems, ...sealedPlants.map((plant) => plant.item)],\n mulberry32(seed),\n )\n const itemIds = items.map((item) => item.itemId)\n const manifest: PlantManifest = {\n seal: sealManifest({ seed, acceptThreshold, itemIds, plants: sealedPlants }),\n seed,\n acceptThreshold,\n itemIds,\n plants: sealedPlants,\n }\n return { items, manifest }\n}\n\n/**\n * Order by one independent uniform key per item, which is a uniform\n * permutation and a pure function of the seed. A comparator that returns a\n * fresh random sign instead is neither: it is not a consistent ordering, so\n * the permutation it produces is biased and depends on the sort algorithm.\n */\nfunction shuffled<T>(items: readonly T[], random: () => number): T[] {\n return items\n .map((item) => ({ item, key: random() }))\n .sort((left, right) => left.key - right.key)\n .map((entry) => entry.item)\n}\n\nfunction sealManifest(contents: Omit<PlantManifest, 'seal'>): LedgerHash {\n return hashCanonical({\n scheme: 'agent-eval.plant-manifest.v1',\n seed: contents.seed,\n acceptThreshold: contents.acceptThreshold,\n itemIds: contents.itemIds,\n plants: contents.plants,\n })\n}\n\n/**\n * One grader outcome for one item. `score: null` says the grader ran and\n * declined to decide — the check never tested the item's defect. Any\n * `CandidateScore` from a judge run is already a valid outcome.\n */\nexport interface PlantOutcome {\n itemId: string\n score: number | null\n}\n\n/**\n * `evaluated` — a rate stands. `incomplete` — a seeded id had no result.\n * `not_evaluated` — nothing was seeded, or nothing seeded was decided.\n */\nexport type CatchRateStatus = 'evaluated' | 'incomplete' | 'not_evaluated'\n\nexport interface PlantKindCounts {\n seeded: number\n caught: number\n missed: number\n indecisive: number\n /** caught / (caught + missed), or null when the report is not `evaluated`. */\n rate: number | null\n}\n\n/**\n * How the same grader treated the unseeded items of the same set. No labels\n * are needed to read it: a grader that refuses everything scores `rate` 1.0\n * on reject-plants, and a `rejectionRate` of 1.0 here is what separates that\n * reflex from discrimination.\n */\nexport interface UnseededRejection {\n n: number\n decided: number\n rejected: number\n /** rejected / decided, or null when nothing unseeded was decided. */\n rejectionRate: number | null\n}\n\nexport interface CatchRateReport {\n status: CatchRateStatus\n /** Why the status is not `evaluated`. Absent when it is. */\n reason?: string\n seeded: number\n caught: number\n missed: number\n /**\n * The grader returned a result and declined to decide. Counted apart: it\n * enters neither side of `rate`.\n */\n indecisive: number\n /** caught / (caught + missed), or null unless the status is `evaluated`. */\n rate: number | null\n /** One entry per kind actually seeded. A kind nobody seeded is absent, never zero. */\n byKind: Partial<Record<PlantKind, PlantKindCounts>>\n /** Plant ids the grader graded as the seed says it must not. */\n missedIds: string[]\n /** Plant ids with no result at all — the reason a status is `incomplete`. */\n missingIds: string[]\n unseeded: UnseededRejection\n}\n\n/**\n * Score a grading run against its sealed manifest.\n *\n * Refusals: a manifest whose contents no longer match its seal, a result for\n * an id the manifest never handed out, and a repeated result id. Each says\n * the results and the manifest describe different runs, and a rate computed\n * across two runs is a fabrication.\n */\nexport function catchRate(\n results: readonly PlantOutcome[],\n manifest: PlantManifest,\n): CatchRateReport {\n const expectedSeal = sealManifest({\n seed: manifest.seed,\n acceptThreshold: manifest.acceptThreshold,\n itemIds: manifest.itemIds,\n plants: manifest.plants,\n })\n if (expectedSeal !== manifest.seal) {\n throw new CaptureIntegrityError(\n `catchRate: manifest contents hash to ${expectedSeal} but the manifest carries seal ${manifest.seal} — the plant set changed after it was sealed`,\n )\n }\n\n const handedOut = new Set(manifest.itemIds)\n const scoreByItemId = new Map<string, number | null>()\n for (const result of results) {\n if (!handedOut.has(result.itemId)) {\n throw new ValidationError(\n `catchRate: result for \"${result.itemId}\", which this manifest never handed out`,\n )\n }\n if (scoreByItemId.has(result.itemId)) {\n throw new ValidationError(`catchRate: duplicate result for \"${result.itemId}\"`)\n }\n if (result.score !== null && !Number.isFinite(result.score)) {\n throw new ValidationError(\n `catchRate: result for \"${result.itemId}\" has score ${result.score}; expected a finite number or null`,\n )\n }\n scoreByItemId.set(result.itemId, result.score)\n }\n\n const byKind: Partial<Record<PlantKind, PlantKindCounts>> = {}\n const missedIds: string[] = []\n const missingIds: string[] = []\n let caught = 0\n let missed = 0\n let indecisive = 0\n\n for (const plant of manifest.plants) {\n let counts = byKind[plant.kind]\n if (counts === undefined) {\n counts = { seeded: 0, caught: 0, missed: 0, indecisive: 0, rate: null }\n byKind[plant.kind] = counts\n }\n counts.seeded += 1\n if (!scoreByItemId.has(plant.item.itemId)) {\n missingIds.push(plant.id)\n continue\n }\n const score = scoreByItemId.get(plant.item.itemId) ?? null\n if (score === null) {\n indecisive += 1\n counts.indecisive += 1\n continue\n }\n const graderSaid: PlantExpectation = score >= manifest.acceptThreshold ? 'accept' : 'reject'\n if (graderSaid === plant.expectedVerdict) {\n caught += 1\n counts.caught += 1\n } else {\n missed += 1\n counts.missed += 1\n missedIds.push(plant.id)\n }\n }\n\n const seeded = manifest.plants.length\n const decided = caught + missed\n const report: CatchRateReport = {\n status: 'evaluated',\n seeded,\n caught,\n missed,\n indecisive,\n rate: null,\n byKind,\n missedIds,\n missingIds,\n unseeded: unseededRejection(manifest, scoreByItemId),\n }\n\n if (seeded === 0) {\n return {\n ...report,\n status: 'not_evaluated',\n reason: 'no plant was seeded, so the grader was never asked a question it could fail',\n }\n }\n if (missingIds.length > 0) {\n return {\n ...report,\n status: 'incomplete',\n reason: `${missingIds.length} of ${seeded} seeded plants have no result: ${missingIds.join(', ')}`,\n }\n }\n if (decided === 0) {\n return {\n ...report,\n status: 'not_evaluated',\n reason: `all ${seeded} seeded plants are indecisive: no check tested the seeded defect`,\n }\n }\n\n for (const counts of Object.values(byKind)) {\n const kindDecided = counts.caught + counts.missed\n counts.rate = kindDecided === 0 ? null : counts.caught / kindDecided\n }\n report.rate = caught / decided\n return report\n}\n\nfunction unseededRejection(\n manifest: PlantManifest,\n scoreByItemId: ReadonlyMap<string, number | null>,\n): UnseededRejection {\n const plantItemIds = new Set(manifest.plants.map((plant) => plant.item.itemId))\n let n = 0\n let decided = 0\n let rejected = 0\n for (const itemId of manifest.itemIds) {\n if (plantItemIds.has(itemId)) continue\n n += 1\n const score = scoreByItemId.get(itemId)\n if (score === undefined || score === null) continue\n decided += 1\n if (score < manifest.acceptThreshold) rejected += 1\n }\n return { n, decided, rejected, rejectionRate: decided === 0 ? null : rejected /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AAI,MAAM,GAAG;EAC9B,KAAK;EACL,MAAM,QAAQ,cAAc,IAAI,MAAM;EACtC,IAAI,UAAU,KAAA,KAAa,UAAU,MAAM;EAC3C,WAAW;EACX,IAAI,QAAQ,SAAS,iBAAiB,YAAY;CACpD;CACA,OAAO;EAAE;EAAG;EAAS;EAAU,eAAe,YAAY,IAAI,OAAO,WAAW;CAAQ;AAC1F"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/meta-eval/correlation-study.ts","../../src/meta-eval/evaluator-admission.ts","../../src/meta-eval/plants.ts"],"sourcesContent":["/**\n * Correlation study — \"does our eval score predict real-world outcomes?\"\n *\n * Joins traces and outcomes by runId and reports descriptive correlations.\n * Independent runs are the bootstrap observation unit.\n * Association alone does not establish causation or held-out predictive performance.\n */\n\nimport { runMetricExtractor } from '../trace/query'\nimport type { Run } from '../trace/schema'\nimport type { TraceStore } from '../trace/store'\nimport {\n assertUniqueObservationIds,\n correlationSummary,\n hasVariation,\n reduceOutcomeMetric,\n validateObservationOptions,\n} from './outcome-observations'\nimport type { DeploymentOutcome, OutcomeFilter, OutcomeStore } from './outcome-store'\n\nexport interface EvalMetricSpec {\n id: string\n /** Extract a scalar from a run. Omit it and `id` must name one of\n * `RUN_METRICS`; any other `id` is refused. */\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 } | null\n /** 95% bootstrap CI for Spearman; null when no resample is estimable. */\n spearmanCi95: { lower: number; upper: number } | null\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 /** Declared pairs without an estimable correlation, including their usable sample count. */\n excludedPairs: Array<\n OutcomePair & {\n n: number\n reason: 'insufficient_samples' | 'constant_eval_metric' | 'constant_outcome'\n }\n >\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 /** Seed for the bootstrap resampler. Absent, the seed is derived from the\n * paired observations, so the same study reproduces the same interval. */\n seed?: 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 reduction = options.reduction ?? 'latest'\n const iterations = options.bootstrapIterations ?? 500\n const seed = options.seed\n validateObservationOptions(reduction, iterations, seed)\n assertUniqueObservationIds(\n evalMetrics.map((metric) => metric.id),\n 'eval metric',\n )\n assertUniqueObservationIds(outcomeMetricNames, 'outcome metric')\n const maxLag = options.maxCaptureLagMs ?? Infinity\n if (maxLag < 0 || Number.isNaN(maxLag)) {\n throw new Error('maxCaptureLagMs must be nonnegative')\n }\n const extractors = evalMetrics.map((metric) => ({\n ...metric,\n extract: metric.extract ?? runMetricExtractor(metric.id),\n }))\n const metricNames = [...outcomeMetricNames]\n const runs = await traceStore.listRuns()\n assertUniqueObservationIds(\n runs.map((run) => run.runId),\n 'runId',\n )\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 pairs: Array<{ evalMetric: string; outcomeMetric: string; xs: number[]; ys: number[] }> = []\n for (const em of extractors) {\n for (const om of metricNames) {\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) => {\n const lag = o.capturedAt - run.startedAt\n return lag >= 0 && lag <= maxLag\n })\n if (eligible.length === 0) {\n skipped++\n continue\n }\n\n let joinedThisRun = false\n for (const em of extractors) {\n const x = await em.extract(run, traceStore)\n if (x === null || !Number.isFinite(x)) continue\n\n for (const om of metricNames) {\n const y = reduceOutcomeMetric(eligible, om, reduction)\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 joinedThisRun = true\n }\n }\n if (joinedThisRun) joined++\n else skipped++\n }\n\n const excludedPairs: CorrelationStudyResult['excludedPairs'] = []\n const results: CorrelationResult[] = []\n for (const p of pairs) {\n const reason =\n p.xs.length < 3\n ? 'insufficient_samples'\n : !hasVariation(p.xs)\n ? 'constant_eval_metric'\n : !hasVariation(p.ys)\n ? 'constant_outcome'\n : null\n if (reason !== null) {\n excludedPairs.push({\n evalMetric: p.evalMetric,\n outcomeMetric: p.outcomeMetric,\n n: p.xs.length,\n reason,\n })\n continue\n }\n const summary = correlationSummary(p.xs, p.ys, iterations, seed)\n const verdict: CorrelationResult['verdict'] =\n Math.abs(summary.pearson) >= 0.7\n ? 'strong'\n : Math.abs(summary.pearson) >= 0.4\n ? 'moderate'\n : 'weak'\n results.push({\n evalMetric: p.evalMetric,\n outcomeMetric: p.outcomeMetric,\n n: p.xs.length,\n ...summary,\n verdict,\n })\n }\n return { pairs: results, excludedPairs, joinedSamples: joined, skippedRuns: skipped }\n}\n","import { z } from 'zod'\nimport { ValidationError } from '../errors'\nimport { type ComputedInterval, computeInterval } from '../experiment/ast/interval'\nimport { compareCodeUnits, hashCanonical, type LedgerHash } from '../ledger-core/canonical'\n\nconst identity = z\n .string()\n .min(1)\n .refine((value) => value.trim() === value)\nexport const evaluatorAdmissionPolicySchema = z\n .object({\n confidence: z.number().finite().gt(0).lt(1),\n maxFalseAcceptanceRate: z.number().finite().min(0).lt(1),\n maxFalseRejectionRate: z.number().finite().min(0).lt(1),\n })\n .strict()\n\n/** Register both error limits before inspecting audit judgments. */\nexport type EvaluatorAdmissionPolicy = z.infer<typeof evaluatorAdmissionPolicySchema>\n\nexport const evaluatorAuditObservationSchema = z\n .object({\n id: identity,\n independentUnitId: identity,\n evidenceRef: identity,\n expected: z.enum(['accept', 'reject']),\n observed: z.enum(['accept', 'reject', 'unknown']),\n exposure: z.enum(['fresh', 'development']),\n })\n .strict()\n\n/** Actual control judgments. Variants from one source retain one independent identity. */\nexport type EvaluatorAuditObservation = z.infer<typeof evaluatorAuditObservationSchema>\n\nconst inputSchema = z\n .object({\n evaluatorDigest: z.string().regex(/^sha256:[a-f0-9]{64}$/),\n population: identity,\n samplingFrame: identity,\n authority: z\n .object({\n evaluatorAuthorId: identity,\n auditorId: identity,\n independenceEvidenceRef: identity,\n })\n .strict(),\n policy: evaluatorAdmissionPolicySchema,\n observations: z.array(evaluatorAuditObservationSchema),\n })\n .strict()\n\nexport type EvaluatorAuditInput = z.infer<typeof inputSchema>\n\nexport interface EvaluatorErrorRate {\n /** Eligible control judgments in this class, including unknown judgments. */\n cases: number\n independentUnits: number\n /** Units with at least one observed mistake. */\n errorUnits: number\n /** Units with unknown judgments and no observed mistake yet. */\n unresolvedUnits: number\n unknownCases: number\n /** Missing judgments do not become measured zeros. */\n errorRate: number | null\n /** Exact bounds conservatively include every possible outcome of unknown judgments. */\n interval: ComputedInterval | null\n limit: number\n verdict: 'pass' | 'fail' | 'inconclusive'\n}\n\nexport interface EvaluatorAdmissionReport {\n evaluatorDigest: LedgerHash\n policyDigest: LedgerHash\n inputDigest: LedgerHash\n reportDigest: LedgerHash\n population: string\n samplingFrame: string\n authority: EvaluatorAuditInput['authority']\n policy: EvaluatorAdmissionPolicy\n /** Joint coverage for the two reported error-rate intervals. */\n confidence: number\n intervalConfidence: number\n verdict: 'admit' | 'reject' | 'inconclusive'\n reasons: string[]\n observations: EvaluatorAuditObservation[]\n coverage: {\n cases: number\n independentUnits: number\n eligibleCases: number\n eligibleIndependentUnits: number\n excludedCases: number\n unknownCases: number\n }\n exclusions: Array<{ id: string; independentUnitId: string; reason: 'development-exposure' }>\n falseAcceptance: EvaluatorErrorRate\n falseRejection: EvaluatorErrorRate\n}\n\nfunction errorRate(\n rows: readonly EvaluatorAuditObservation[],\n expected: 'accept' | 'reject',\n limit: number,\n level: number,\n): EvaluatorErrorRate {\n const cases = rows.filter((row) => row.expected === expected)\n const units = new Map<string, { error: boolean; unknown: boolean }>()\n for (const row of cases) {\n const unit = units.get(row.independentUnitId) ?? { error: false, unknown: false }\n unit.unknown ||= row.observed === 'unknown'\n unit.error ||= row.observed !== 'unknown' && row.observed !== expected\n units.set(row.independentUnitId, unit)\n }\n const n = units.size\n const errorUnits = [...units.values()].filter((unit) => unit.error).length\n const unresolvedUnits = [...units.values()].filter((unit) => unit.unknown && !unit.error).length\n const unknownCases = cases.filter((row) => row.observed === 'unknown').length\n // Unknown judgments contribute to n; their most favorable and adverse outcomes bound the rate.\n const interval =\n n === 0\n ? null\n : {\n lower: computeInterval(\n { kind: 'clopper-pearson', level },\n {\n kind: 'binomial',\n successes: errorUnits,\n trials: n,\n },\n ).lower,\n upper: computeInterval(\n { kind: 'clopper-pearson', level },\n {\n kind: 'binomial',\n successes: errorUnits + unresolvedUnits,\n trials: n,\n },\n ).upper,\n level,\n }\n const verdict =\n interval && interval.lower > limit\n ? 'fail'\n : interval && interval.upper <= limit\n ? 'pass'\n : 'inconclusive'\n return {\n cases: cases.length,\n independentUnits: n,\n errorUnits,\n unresolvedUnits,\n unknownCases,\n errorRate: n === 0 || unresolvedUnits > 0 ? null : errorUnits / n,\n interval,\n limit,\n verdict,\n }\n}\n\nfunction eligibleControls<\n T extends Pick<EvaluatorAuditObservation, 'id' | 'independentUnitId' | 'exposure'>,\n>(observations: T[]) {\n const ids = new Set<string>()\n for (const row of observations) {\n if (ids.has(row.id))\n throw new ValidationError(`duplicate evaluator audit observation '${row.id}'`)\n ids.add(row.id)\n }\n observations.sort((a, b) => compareCodeUnits(a.id, b.id))\n const developmentUnits = new Set(\n observations\n .filter((row) => row.exposure === 'development')\n .map((row) => row.independentUnitId),\n )\n const eligible = observations.filter((row) => !developmentUnits.has(row.independentUnitId))\n const exclusions = observations\n .filter((row) => developmentUnits.has(row.independentUnitId))\n .map((row) => ({\n id: row.id,\n independentUnitId: row.independentUnitId,\n reason: 'development-exposure' as const,\n }))\n return { eligible, exclusions }\n}\n\nfunction simultaneousIntervalConfidence(confidence: number): number {\n const level = 1 - (1 - confidence) / 2\n if (level >= 1)\n throw new ValidationError(\n 'evaluator audit confidence is too close to one for simultaneous intervals',\n )\n return level\n}\n\nconst capacitySchema = z\n .object({\n policy: evaluatorAdmissionPolicySchema,\n controls: z\n .array(evaluatorAuditObservationSchema.omit({ observed: true, evidenceRef: true }))\n .default([]),\n })\n .strict()\n\nexport type EvaluatorAuditPlanInput = z.input<typeof capacitySchema>\n\n/** The zero-error eligibility floor, not a statistical power calculation. */\nfunction zeroErrorUpperBound(trials: number, level: number): number {\n return -Math.expm1(Math.log((1 - level) / 2) / trials)\n}\n\nfunction minimumAuditUnits(limit: number, level: number): number | null {\n if (limit === 0) return null\n const estimate = Math.ceil(Math.log((1 - level) / 2) / Math.log1p(-limit))\n if (!Number.isFinite(estimate) || estimate > Number.MAX_SAFE_INTEGER) return null\n const clears = (trials: number) => zeroErrorUpperBound(trials, level) <= limit\n let minimum = Math.max(1, estimate)\n while (minimum > 1 && clears(minimum - 1)) minimum -= 1\n while (!clears(minimum)) {\n if (minimum === Number.MAX_SAFE_INTEGER) return null\n minimum += 1\n }\n return minimum\n}\n\n/**\n * Can the fixed control roster meet the policy even with zero errors?\n * Planning uses the admission rule's exact bounds and source-unit exclusions.\n * It accepts no judgments or authority and returns no admission report.\n */\nexport function planEvaluatorAudit(input: EvaluatorAuditPlanInput) {\n const parsed = capacitySchema.safeParse(input)\n if (!parsed.success)\n throw new ValidationError(`invalid evaluator audit plan: ${parsed.error.message}`)\n const { policy, controls } = parsed.data\n const { eligible } = eligibleControls(controls)\n const level = simultaneousIntervalConfidence(policy.confidence)\n const capacity = (expected: EvaluatorAuditObservation['expected'], limit: number) => {\n const independentUnits = new Set(\n eligible.filter((row) => row.expected === expected).map((row) => row.independentUnitId),\n ).size\n const bestPossibleUpperBound =\n independentUnits === 0 ? null : zeroErrorUpperBound(independentUnits, level)\n const minimumIndependentUnits = minimumAuditUnits(limit, level)\n return {\n independentUnits,\n bestPossibleUpperBound,\n limit,\n minimumIndependentUnits,\n additionalIndependentUnits:\n minimumIndependentUnits === null\n ? null\n : Math.max(0, minimumIndependentUnits - independentUnits),\n }\n }\n const falseAcceptance = capacity('reject', policy.maxFalseAcceptanceRate)\n const falseRejection = capacity('accept', policy.maxFalseRejectionRate)\n const sufficient = [falseAcceptance, falseRejection].every(\n (rate) => rate.bestPossibleUpperBound !== null && rate.bestPossibleUpperBound <= rate.limit,\n )\n return { sufficient, falseAcceptance, falseRejection }\n}\n\nexport type EvaluatorAuditPlan = ReturnType<typeof planEvaluatorAudit>\n\n/**\n * Audit frozen judgments using independent source units and exact binomial bounds.\n * A unit fails a class when any control in that class is misjudged.\n * The execution owner enforces auditor separation, fresh sampling, and evidence authenticity.\n */\nexport function auditEvaluator(input: EvaluatorAuditInput): EvaluatorAdmissionReport {\n const parsed = inputSchema.safeParse(input)\n if (!parsed.success) throw new ValidationError(`invalid evaluator audit: ${parsed.error.message}`)\n const audit = parsed.data\n if (audit.authority.evaluatorAuthorId === audit.authority.auditorId) {\n throw new ValidationError('evaluator admission requires a separate declared audit authority')\n }\n const { eligible, exclusions } = eligibleControls(audit.observations)\n const intervalConfidence = simultaneousIntervalConfidence(audit.policy.confidence)\n const falseAcceptance = errorRate(\n eligible,\n 'reject',\n audit.policy.maxFalseAcceptanceRate,\n intervalConfidence,\n )\n const falseRejection = errorRate(\n eligible,\n 'accept',\n audit.policy.maxFalseRejectionRate,\n intervalConfidence,\n )\n const rates = [falseAcceptance, falseRejection]\n const verdict = rates.some((rate) => rate.verdict === 'fail')\n ? 'reject'\n : rates.every((rate) => rate.verdict === 'pass')\n ? 'admit'\n : 'inconclusive'\n const reasons: string[] = []\n for (const [name, rate] of [\n ['false acceptance', falseAcceptance],\n ['false rejection', falseRejection],\n ] as const) {\n if (rate.independentUnits === 0) reasons.push(`${name}: no eligible independent units`)\n else if (rate.unknownCases > 0)\n reasons.push(`${name}: ${rate.unknownCases} judgments are unknown`)\n if (rate.verdict === 'fail') reasons.push(`${name}: lower error bound exceeds ${rate.limit}`)\n else if (rate.verdict === 'inconclusive' && rate.interval)\n reasons.push(`${name}: upper error bound does not establish the required limit`)\n }\n if (verdict === 'admit')\n reasons.push(\n 'both error bounds meet the registered limits, including the worst case for unknown judgments',\n )\n const body: Omit<EvaluatorAdmissionReport, 'reportDigest'> = {\n evaluatorDigest: audit.evaluatorDigest as LedgerHash,\n policyDigest: hashCanonical(audit.policy),\n inputDigest: hashCanonical(audit),\n population: audit.population,\n samplingFrame: audit.samplingFrame,\n authority: audit.authority,\n policy: audit.policy,\n confidence: audit.policy.confidence,\n intervalConfidence,\n verdict,\n reasons,\n observations: audit.observations,\n coverage: {\n cases: audit.observations.length,\n independentUnits: new Set(audit.observations.map((row) => row.independentUnitId)).size,\n eligibleCases: eligible.length,\n eligibleIndependentUnits: new Set(eligible.map((row) => row.independentUnitId)).size,\n excludedCases: exclusions.length,\n unknownCases: eligible.filter((row) => row.observed === 'unknown').length,\n },\n exclusions,\n falseAcceptance,\n falseRejection,\n }\n return { ...body, reportDigest: hashCanonical(body) }\n}\n\nconst probabilityThresholdsSchema = z\n .object({\n rejectAtOrBelow: z.number().finite().min(0).max(1),\n acceptAtOrAbove: z.number().finite().min(0).max(1),\n })\n .strict()\n .refine((value) => value.rejectAtOrBelow < value.acceptAtOrAbove, {\n message: 'rejection and acceptance thresholds must not overlap',\n })\nconst probabilityObservationSchema = evaluatorAuditObservationSchema\n .omit({ observed: true })\n .extend({ acceptProbability: z.number().finite().min(0).max(1).nullable() })\n .strict()\nconst probabilityAuditSchema = inputSchema.extend({\n thresholds: probabilityThresholdsSchema,\n observations: z.array(probabilityObservationSchema),\n})\n\n/** A frozen caller-owned rule over P(accept), not the provider's entropy/confidence statistic. */\nexport type ProbabilityPolicyAuditInput = z.infer<typeof probabilityAuditSchema>\n\nexport interface ProbabilityPolicyAuditReport extends EvaluatorAdmissionReport {\n probabilityPolicy: {\n sourceEvaluatorDigest: LedgerHash\n thresholds: ProbabilityPolicyAuditInput['thresholds']\n /** Retain probabilities by observation id so the reported mapping can be reproduced. */\n observations: Array<{ id: string; acceptProbability: number | null }>\n }\n}\n\n/**\n * Audit a fixed probability-to-decision rule with the existing independent-unit error bounds.\n * No threshold search, model calls, promotion, or assumption of calibrated probabilities.\n * Null scores and the open interval between thresholds remain unknown, never correct by default.\n */\nexport function auditProbabilityPolicy(\n input: ProbabilityPolicyAuditInput,\n): ProbabilityPolicyAuditReport {\n const parsed = probabilityAuditSchema.safeParse(input)\n if (!parsed.success) {\n throw new ValidationError(`invalid probability policy audit: ${parsed.error.message}`)\n }\n const { thresholds, observations, ...source } = parsed.data\n observations.sort((a, b) => compareCodeUnits(a.id, b.id))\n const probabilityPolicy = {\n sourceEvaluatorDigest: source.evaluatorDigest as LedgerHash,\n thresholds,\n observations: observations.map(({ id, acceptProbability }) => ({ id, acceptProbability })),\n }\n const audit = auditEvaluator({\n ...source,\n evaluatorDigest: hashCanonical({\n kind: 'probability-policy-v1',\n sourceEvaluatorDigest: source.evaluatorDigest,\n thresholds,\n }),\n observations: observations.map(({ acceptProbability, ...observation }) => ({\n ...observation,\n observed:\n acceptProbability === null\n ? 'unknown'\n : acceptProbability >= thresholds.acceptAtOrAbove\n ? 'accept'\n : acceptProbability <= thresholds.rejectAtOrBelow\n ? 'reject'\n : 'unknown',\n })),\n })\n const { reportDigest: _baseDigest, ...baseReport } = audit\n const body = {\n ...baseReport,\n // Bind the actual probabilities too, including changes that select the same action.\n inputDigest: hashCanonical(parsed.data),\n probabilityPolicy,\n }\n return { ...body, reportDigest: hashCanonical(body) }\n}\n","/**\n * Plants — seeded known-wrong items that measure the grader, not the work.\n *\n * A grading run reports how the work scored. It cannot report whether the\n * grader would have noticed a wrong answer, because every item it saw was\n * authored in good faith. A plant closes that hole: an item authored wrong by\n * construction is mixed into the live set, graded by the same path as\n * everything else, and the share of plants the grader refused is the catch\n * rate.\n *\n * Measured motive: a sibling lab ran a deliverable gate that accepted any\n * non-empty submission. It produced six false certifications in seventeen\n * deliveries, and no agent lied — the gate never asked a question the format\n * could fail. A catch rate is the number that would have shown it on day one.\n *\n * This module composes existing primitives rather than adding parallel ones:\n *\n * - A plant IS a {@link GoldenItem} from `../judge-calibration`. Its\n * `humanScore` is the grade a working grader owes the item, so the same\n * array feeds `calibrateJudge` unchanged.\n * - The grader's output is `CandidateScore[]`, the array `calibrateJudge` and\n * `snapshotFromSentinelSet` already consume.\n * - \"Caught\" is `snapshotFromSentinelSet`'s join with the labels inverted:\n * the grade lands on the side of `acceptThreshold` the seed demands.\n * - The manifest is sealed with `hashCanonical` from `../ledger-core/canonical`,\n * the digest the sealed-experiment path uses, so the answer key cannot be\n * revised once the results are in.\n *\n * Authoring the wrong item is the step before all of that, and it is where the\n * measurement silently breaks. {@link plantByPerturbation} takes a claim a\n * grader verified and alters exactly one load-bearing value in its evidence,\n * so the grader is asked a question it must fail. Hand-rolled perturbation\n * bumps a number that is part of an identity — `python3`, `file42.txt`, `1.5`,\n * `utf-8` — and the check stops EXECUTING; the plant then measures the\n * environment rather than the grader. {@link perturbEvidence} refuses those\n * digit runs by construction.\n *\n * Blindness has two halves, and this module owns one. It never puts a plant\n * flag on a graded item: `seedPlants` returns the mixed set and a manifest,\n * and only the manifest knows which ids are seeded. Keeping the manifest out\n * of the graded workspace and publishing its `seal` before grading is the\n * caller's half; {@link catchRate} refuses a manifest whose contents no longer\n * match its seal.\n *\n * Refusals, because a catch rate that cannot refuse is not a measurement:\n *\n * - a seeded id with no result makes the report `incomplete`, never a rate\n * over the results that did come back;\n * - zero seeded plants makes it `not_evaluated`, never 1.0;\n * - a result for an id the manifest never handed out is refused outright.\n */\n\nimport { CaptureIntegrityError, ValidationError } from '../errors'\nimport type { GoldenItem } from '../judge-calibration'\nimport { hashCanonical, type LedgerHash } from '../ledger-core/canonical'\nimport { mulberry32 } from '../statistics/random'\n\n/**\n * How a plant item was authored wrong. The class is reported separately in\n * {@link CatchRateReport.byKind} because a grader is routinely sharp on one\n * and blind to another.\n */\nexport type PlantKind =\n /** A load-bearing value is altered: a number off by one, a comparison flipped. */\n | 'wrong-value'\n /** The item carries its own check, and that check passes without testing the claim. */\n | 'self-certifying'\n /** The check names an input that does not exist, so it cannot run at all. */\n | 'unreachable-input'\n /** A copy of an item already in the set, which is owed a duplicate flag rather than a second grade. */\n | 'duplicate'\n\nconst PLANT_KINDS: readonly PlantKind[] = [\n 'wrong-value',\n 'self-certifying',\n 'unreachable-input',\n 'duplicate',\n]\n\n/** What a working grader owes a seeded item. */\nexport type PlantExpectation = 'reject' | 'accept'\n\nconst PLANT_EXPECTATIONS: readonly PlantExpectation[] = ['reject', 'accept']\n\n/** The label boundary a plant record is checked against at definition time. */\nconst RECORD_LABEL_BOUNDARY = 0.5\n\nexport interface Plant {\n /** Name of the plant record. Reported in `missedIds` and `missingIds`. */\n id: string\n kind: PlantKind\n /** The seeded item, indistinguishable from a real one once mixed. */\n item: GoldenItem\n /** The verdict a working grader owes this item. */\n expectedVerdict: PlantExpectation\n}\n\n/**\n * Build one plant record and refuse an incoherent one.\n *\n * The refusal that matters is the last: a record whose `expectedVerdict`\n * disagrees with `item.humanScore` inverts the measurement silently, because\n * the same item then reads as wrong here and as correct to every calibration\n * instrument that joins on the id.\n *\n * `item` is copied field by field so a later mutation of the caller's object\n * cannot change what the manifest sealed, and `group` is dropped when it is\n * absent so the record always has a canonical JSON form.\n */\nexport function definePlant(input: {\n id: string\n kind: PlantKind\n item: GoldenItem\n expectedVerdict: PlantExpectation\n}): Plant {\n const { id, kind, item, expectedVerdict } = input\n if (typeof id !== 'string' || id.trim() === '') {\n throw new ValidationError('definePlant: id must be a non-empty string')\n }\n if (!PLANT_KINDS.includes(kind)) {\n throw new ValidationError(\n `definePlant: plant \"${id}\" has kind ${JSON.stringify(kind)}; expected one of ${PLANT_KINDS.join(', ')}`,\n )\n }\n if (!PLANT_EXPECTATIONS.includes(expectedVerdict)) {\n throw new ValidationError(\n `definePlant: plant \"${id}\" has expectedVerdict ${JSON.stringify(expectedVerdict)}; expected one of ${PLANT_EXPECTATIONS.join(', ')}`,\n )\n }\n if (typeof item.itemId !== 'string' || item.itemId.trim() === '') {\n throw new ValidationError(`definePlant: plant \"${id}\" has an empty item.itemId`)\n }\n if (!Number.isFinite(item.humanScore) || item.humanScore < 0 || item.humanScore > 1) {\n throw new ValidationError(\n `definePlant: plant \"${id}\" has humanScore ${item.humanScore}; expected a finite number in [0, 1]`,\n )\n }\n if (item.group !== undefined && typeof item.group !== 'string') {\n throw new ValidationError(`definePlant: plant \"${id}\" has a non-string item.group`)\n }\n if (item.humanScore === RECORD_LABEL_BOUNDARY) {\n throw new ValidationError(\n `definePlant: plant \"${id}\" has humanScore ${RECORD_LABEL_BOUNDARY}, which states neither a rejection nor an acceptance`,\n )\n }\n const labelSays: PlantExpectation = item.humanScore < RECORD_LABEL_BOUNDARY ? 'reject' : 'accept'\n if (labelSays !== expectedVerdict) {\n throw new ValidationError(\n `definePlant: plant \"${id}\" expects the grader to ${expectedVerdict} it, but humanScore ${item.humanScore} says ${labelSays}`,\n )\n }\n return {\n id,\n kind,\n item: {\n itemId: item.itemId,\n humanScore: item.humanScore,\n ...(item.group === undefined ? {} : { group: item.group }),\n },\n expectedVerdict,\n }\n}\n\n/**\n * A claim's executable evidence: the command a grader runs and the output it\n * must produce.\n */\nexport interface PlantEvidence {\n /** The command a grader runs to test the claim. */\n check?: string\n /** The output that command must produce for the claim to stand. */\n expect?: string\n}\n\n/** Which evidence field {@link perturbEvidence} altered. */\nexport type PerturbedField = 'check' | 'expect'\n\n/** How {@link perturbEvidence} altered it. */\nexport type PerturbationKind = 'number-off-by-one' | 'comparison-flipped'\n\nexport interface EvidencePerturbation {\n /** The evidence with exactly one value altered. */\n evidence: PlantEvidence\n /** Which field changed. */\n field: PerturbedField\n /** How it changed. */\n how: PerturbationKind\n /**\n * The exact substring that was replaced. A comparison token carries its\n * surrounding spaces, because the spaces are what make ` -ge ` a comparison\n * and not part of a word.\n */\n original: string\n /** What replaced it. */\n perturbed: string\n}\n\n/**\n * Characters that make a digit run part of something larger than a number.\n *\n * A run that touches one of these is an identity — `python3`, `file42.txt`,\n * `1.5`, `utf-8` — and bumping it renames a program, a file, a version, or an\n * encoding instead of falsifying the claim. The check then stops EXECUTING,\n * and a plant that cannot run measures the environment rather than the grader:\n * it reads as caught, for a reason that has nothing to do with the seeded\n * defect.\n */\nconst NUMBER_GLUE = /[A-Za-z0-9_./-]/\n\n/**\n * Comparison tokens that mean one thing only, each with its inversion.\n *\n * A bare `>` or `<` is absent on purpose: in a shell check it is a\n * redirection, so flipping it rewrites where output goes rather than what the\n * test asks, and the check stops testing the claim.\n */\nconst COMPARISON_FLIPS: readonly (readonly [string, string])[] = [\n [' -ge ', ' -lt '],\n [' -gt ', ' -le '],\n [' -le ', ' -gt '],\n [' -lt ', ' -ge '],\n [' -eq ', ' -ne '],\n [' -ne ', ' -eq '],\n ['>=', '<'],\n ['<=', '>'],\n ['==', '!='],\n ['!=', '=='],\n]\n\ninterface Span {\n start: number\n end: number\n}\n\n/**\n * The last digit run in `text` that is a number and nothing else, or null.\n *\n * The last is taken because a measured value trails its label — `count=42`,\n * `n>=5 OK cells=8` — and because the choice has to be deterministic: the same\n * claim must always yield the same plant, or two runs of the same authoring\n * step seed two different answer keys for one item.\n */\nfunction lastStandaloneNumber(text: string): Span | null {\n const digits = /\\d+/g\n let found: Span | null = null\n let match = digits.exec(text)\n while (match !== null) {\n const start = match.index\n const end = start + match[0].length\n // charAt returns '' outside the string, and NUMBER_GLUE never matches ''.\n if (!NUMBER_GLUE.test(text.charAt(start - 1)) && !NUMBER_GLUE.test(text.charAt(end))) {\n found = { start, end }\n }\n match = digits.exec(text)\n }\n return found\n}\n\n/**\n * The first flippable comparison in `text`, or null.\n *\n * Any single flip inverts the test wherever it sits, so unlike the number rule\n * there is no safety ordering among the matches. The first is taken so the\n * result is fixed by the head of the command and does not move when a later\n * comparison is added.\n */\nfunction firstComparison(text: string): { span: Span; flipped: string } | null {\n for (let index = 0; index < text.length; index += 1) {\n for (const [token, flipped] of COMPARISON_FLIPS) {\n if (text.startsWith(token, index)) {\n return { span: { start: index, end: index + token.length }, flipped }\n }\n }\n }\n return null\n}\n\nfunction replaceSpan(text: string, span: Span, value: string): string {\n return text.slice(0, span.start) + value + text.slice(span.end)\n}\n\n/**\n * Rebuild the evidence with one field replaced. An absent field is dropped\n * rather than set to undefined, so the record always has a canonical JSON form.\n */\nfunction withField(\n check: string | undefined,\n expect: string | undefined,\n field: PerturbedField,\n value: string,\n): PlantEvidence {\n const nextCheck = field === 'check' ? value : check\n const nextExpect = field === 'expect' ? value : expect\n return {\n ...(nextCheck === undefined ? {} : { check: nextCheck }),\n ...(nextExpect === undefined ? {} : { expect: nextExpect }),\n }\n}\n\nfunction offByOne(\n check: string | undefined,\n expect: string | undefined,\n field: PerturbedField,\n text: string,\n span: Span,\n): EvidencePerturbation {\n const original = text.slice(span.start, span.end)\n const perturbed = (BigInt(original) + 1n).toString()\n return {\n evidence: withField(check, expect, field, replaceSpan(text, span, perturbed)),\n field,\n how: 'number-off-by-one',\n original,\n perturbed,\n }\n}\n\n/**\n * Derive a known-wrong version of a claim's evidence by altering exactly one\n * value, or return null when no value can be altered safely.\n *\n * Exactly one value changes. A perturbation that moves two does not name the\n * defect it seeded, so a grader that catches it says nothing about which defect\n * the grader can see.\n *\n * The preference order IS the safety order:\n *\n * 1. the last standalone number in `expect` — it falsifies the claim while the\n * command still runs exactly as it did;\n * 2. a flipped comparison in `check` — it inverts a test that was passing;\n * 3. the last standalone number in `check` — last because a number in a command\n * can name an input (a port, a width, a version) rather than a threshold,\n * and renaming an input breaks execution, not the claim.\n *\n * \"Standalone\" excludes a digit run glued to a word, a dot, a slash, or a\n * hyphen: `python3`, `file42.txt`, `1.5`, `utf-8`. That exclusion is why this\n * helper exists. Hand-rolled perturbation bumps one of those, the check stops\n * executing, and the plant measures the environment instead of the grader.\n *\n * A number is bumped with BigInt, so a value wider than\n * `Number.MAX_SAFE_INTEGER` moves by exactly one. Bumped as a `number` it\n * rounds back to itself, and the plant is then a correct claim the grader is\n * right to verify.\n */\nexport function perturbEvidence(evidence: PlantEvidence): EvidencePerturbation | null {\n const check = typeof evidence.check === 'string' ? evidence.check : undefined\n const expect = typeof evidence.expect === 'string' ? evidence.expect : undefined\n\n if (expect !== undefined) {\n const span = lastStandaloneNumber(expect)\n if (span !== null) return offByOne(check, expect, 'expect', expect, span)\n }\n if (check !== undefined) {\n const comparison = firstComparison(check)\n if (comparison !== null) {\n return {\n evidence: withField(\n check,\n expect,\n 'check',\n replaceSpan(check, comparison.span, comparison.flipped),\n ),\n field: 'check',\n how: 'comparison-flipped',\n original: check.slice(comparison.span.start, comparison.span.end),\n perturbed: comparison.flipped,\n }\n }\n const span = lastStandaloneNumber(check)\n if (span !== null) return offByOne(check, expect, 'check', check, span)\n }\n return null\n}\n\nexport interface PerturbedPlant {\n plant: Plant\n /** The perturbed evidence to write into the item the grader is handed. */\n evidence: PlantEvidence\n field: PerturbedField\n how: PerturbationKind\n original: string\n perturbed: string\n}\n\n/**\n * Derive a reject-direction plant from a claim a grader verified, by perturbing\n * one value.\n *\n * {@link definePlant} takes a {@link GoldenItem} and never authors a wrong item\n * from a right one, so until now every caller hand-rolled the perturbation.\n * This is that step, done once and the same way every time: the claim's\n * evidence is altered by {@link perturbEvidence}, the result is a `wrong-value`\n * plant the grader owes a `reject`, and the record itself is built by\n * `definePlant` so every refusal there still applies — in particular the one\n * that catches an `expectedVerdict` its `humanScore` contradicts.\n *\n * Returns null when nothing in the evidence can be perturbed. That is not a\n * failure: a claim with no executable evidence cannot be made wrong in a way a\n * grader could execute, and seeding it would measure prose.\n *\n * Refuses an empty `id` or `itemId`. Both name the record — one in the manifest\n * and in `missedIds`, the other in the join with the results — and a miss\n * nobody can look up is not a measurement.\n */\nexport function plantByPerturbation(input: {\n id: string\n itemId: string\n evidence: PlantEvidence\n /** Score for the perturbed item. Must sit below the run's accept threshold. Default 0. */\n humanScore?: number\n group?: string\n}): PerturbedPlant | null {\n const { id, itemId, evidence, humanScore = 0, group } = input\n if (typeof id !== 'string' || id.trim() === '') {\n throw new ValidationError('plantByPerturbation: id must be a non-empty string')\n }\n if (typeof itemId !== 'string' || itemId.trim() === '') {\n throw new ValidationError(`plantByPerturbation: plant \"${id}\" has an empty itemId`)\n }\n const perturbation = perturbEvidence(evidence)\n if (perturbation === null) return null\n const plant = definePlant({\n id,\n kind: 'wrong-value',\n item: { itemId, humanScore, ...(group === undefined ? {} : { group }) },\n expectedVerdict: 'reject',\n })\n return {\n plant,\n evidence: perturbation.evidence,\n field: perturbation.field,\n how: perturbation.how,\n original: perturbation.original,\n perturbed: perturbation.perturbed,\n }\n}\n\nexport interface PlantManifest {\n /**\n * Digest over the seeded order, the plants, and the threshold. Publish it\n * before the grading run: a manifest edited afterwards to match the results\n * no longer matches its seal, and {@link catchRate} refuses it.\n */\n seal: LedgerHash\n /** The seed that fixed the mix order. */\n seed: number\n /** The grade at or above which the graded policy's own gate accepts an item. */\n acceptThreshold: number\n /** Every item id in the seeded set, in the order handed out. */\n itemIds: string[]\n /** The seeded plants. This is the answer key; keep it out of the graded workspace. */\n plants: Plant[]\n}\n\nexport interface SeededGradingSet {\n /**\n * The mixed set in seeded order. Operator-side: it still carries every\n * item's `humanScore`, so hand the graded policy the payload each `itemId`\n * names, never this array.\n */\n items: GoldenItem[]\n manifest: PlantManifest\n}\n\nexport interface SeedPlantsOptions {\n /**\n * Fixes the mix order. The same dataset, plants, threshold, and seed always\n * produce the same seeded order and the same seal.\n */\n seed?: number\n /**\n * The grade at or above which the graded policy's own gate accepts an item.\n * Supply the threshold your gate uses; the default suits a judge scoring in\n * [0, 1] with a pass at the midpoint.\n */\n acceptThreshold?: number\n}\n\n/**\n * Mix plants into a grading set and seal which items they are.\n *\n * Refusals: a duplicate id anywhere in the mixed set (the join is by id, so a\n * repeat makes one of the two unscoreable), a plant whose item id collides\n * with a dataset item (it would shadow real work and grade it as a plant), a\n * dataset item with no usable label, and a plant whose expectation the run's\n * `acceptThreshold` contradicts.\n */\nexport function seedPlants(\n dataset: readonly GoldenItem[],\n plants: readonly Plant[],\n options: SeedPlantsOptions = {},\n): SeededGradingSet {\n const seed = options.seed ?? 7\n const acceptThreshold = options.acceptThreshold ?? 0.5\n if (!Number.isFinite(seed)) {\n throw new ValidationError(`seedPlants: seed must be a finite number, got ${seed}`)\n }\n if (!Number.isFinite(acceptThreshold) || acceptThreshold <= 0 || acceptThreshold > 1) {\n throw new ValidationError(\n `seedPlants: acceptThreshold must be a finite number in (0, 1], got ${acceptThreshold}`,\n )\n }\n\n const datasetItems: GoldenItem[] = []\n const seen = new Set<string>()\n for (const item of dataset) {\n if (typeof item.itemId !== 'string' || item.itemId.trim() === '') {\n throw new ValidationError('seedPlants: a dataset item has an empty itemId')\n }\n if (!Number.isFinite(item.humanScore)) {\n throw new ValidationError(\n `seedPlants: dataset item \"${item.itemId}\" has a non-finite humanScore`,\n )\n }\n if (seen.has(item.itemId)) {\n throw new ValidationError(`seedPlants: duplicate dataset itemId \"${item.itemId}\"`)\n }\n seen.add(item.itemId)\n datasetItems.push({\n itemId: item.itemId,\n humanScore: item.humanScore,\n ...(item.group === undefined ? {} : { group: item.group }),\n })\n }\n\n const sealedPlants: Plant[] = []\n const plantIds = new Set<string>()\n for (const plant of plants) {\n const record = definePlant(plant)\n if (plantIds.has(record.id)) {\n throw new ValidationError(`seedPlants: duplicate plant id \"${record.id}\"`)\n }\n if (seen.has(record.item.itemId)) {\n throw new ValidationError(\n `seedPlants: plant \"${record.id}\" reuses itemId \"${record.item.itemId}\", which is already in the set`,\n )\n }\n const thresholdSays: PlantExpectation =\n record.item.humanScore >= acceptThreshold ? 'accept' : 'reject'\n if (thresholdSays !== record.expectedVerdict) {\n throw new ValidationError(\n `seedPlants: plant \"${record.id}\" expects the grader to ${record.expectedVerdict} it, but humanScore ${record.item.humanScore} is on the ${thresholdSays} side of acceptThreshold ${acceptThreshold}`,\n )\n }\n plantIds.add(record.id)\n seen.add(record.item.itemId)\n sealedPlants.push(record)\n }\n\n const items = shuffled(\n [...datasetItems, ...sealedPlants.map((plant) => plant.item)],\n mulberry32(seed),\n )\n const itemIds = items.map((item) => item.itemId)\n const manifest: PlantManifest = {\n seal: sealManifest({ seed, acceptThreshold, itemIds, plants: sealedPlants }),\n seed,\n acceptThreshold,\n itemIds,\n plants: sealedPlants,\n }\n return { items, manifest }\n}\n\n/**\n * Order by one independent uniform key per item, which is a uniform\n * permutation and a pure function of the seed. A comparator that returns a\n * fresh random sign instead is neither: it is not a consistent ordering, so\n * the permutation it produces is biased and depends on the sort algorithm.\n */\nfunction shuffled<T>(items: readonly T[], random: () => number): T[] {\n return items\n .map((item) => ({ item, key: random() }))\n .sort((left, right) => left.key - right.key)\n .map((entry) => entry.item)\n}\n\nfunction sealManifest(contents: Omit<PlantManifest, 'seal'>): LedgerHash {\n return hashCanonical({\n scheme: 'agent-eval.plant-manifest.v1',\n seed: contents.seed,\n acceptThreshold: contents.acceptThreshold,\n itemIds: contents.itemIds,\n plants: contents.plants,\n })\n}\n\n/**\n * One grader outcome for one item. `score: null` says the grader ran and\n * declined to decide — the check never tested the item's defect. Any\n * `CandidateScore` from a judge run is already a valid outcome.\n */\nexport interface PlantOutcome {\n itemId: string\n score: number | null\n}\n\n/**\n * `evaluated` — a rate stands. `incomplete` — a seeded id had no result.\n * `not_evaluated` — nothing was seeded, or nothing seeded was decided.\n */\nexport type CatchRateStatus = 'evaluated' | 'incomplete' | 'not_evaluated'\n\nexport interface PlantKindCounts {\n seeded: number\n caught: number\n missed: number\n indecisive: number\n /** caught / (caught + missed), or null when the report is not `evaluated`. */\n rate: number | null\n}\n\n/**\n * How the same grader treated the unseeded items of the same set. No labels\n * are needed to read it: a grader that refuses everything scores `rate` 1.0\n * on reject-plants, and a `rejectionRate` of 1.0 here is what separates that\n * reflex from discrimination.\n */\nexport interface UnseededRejection {\n n: number\n decided: number\n rejected: number\n /** rejected / decided, or null when nothing unseeded was decided. */\n rejectionRate: number | null\n}\n\nexport interface CatchRateReport {\n status: CatchRateStatus\n /** Why the status is not `evaluated`. Absent when it is. */\n reason?: string\n seeded: number\n caught: number\n missed: number\n /**\n * The grader returned a result and declined to decide. Counted apart: it\n * enters neither side of `rate`.\n */\n indecisive: number\n /** caught / (caught + missed), or null unless the status is `evaluated`. */\n rate: number | null\n /** One entry per kind actually seeded. A kind nobody seeded is absent, never zero. */\n byKind: Partial<Record<PlantKind, PlantKindCounts>>\n /** Plant ids the grader graded as the seed says it must not. */\n missedIds: string[]\n /** Plant ids with no result at all — the reason a status is `incomplete`. */\n missingIds: string[]\n unseeded: UnseededRejection\n}\n\n/**\n * Score a grading run against its sealed manifest.\n *\n * Refusals: a manifest whose contents no longer match its seal, a result for\n * an id the manifest never handed out, and a repeated result id. Each says\n * the results and the manifest describe different runs, and a rate computed\n * across two runs is a fabrication.\n */\nexport function catchRate(\n results: readonly PlantOutcome[],\n manifest: PlantManifest,\n): CatchRateReport {\n const expectedSeal = sealManifest({\n seed: manifest.seed,\n acceptThreshold: manifest.acceptThreshold,\n itemIds: manifest.itemIds,\n plants: manifest.plants,\n })\n if (expectedSeal !== manifest.seal) {\n throw new CaptureIntegrityError(\n `catchRate: manifest contents hash to ${expectedSeal} but the manifest carries seal ${manifest.seal} — the plant set changed after it was sealed`,\n )\n }\n\n const handedOut = new Set(manifest.itemIds)\n const scoreByItemId = new Map<string, number | null>()\n for (const result of results) {\n if (!handedOut.has(result.itemId)) {\n throw new ValidationError(\n `catchRate: result for \"${result.itemId}\", which this manifest never handed out`,\n )\n }\n if (scoreByItemId.has(result.itemId)) {\n throw new ValidationError(`catchRate: duplicate result for \"${result.itemId}\"`)\n }\n if (result.score !== null && !Number.isFinite(result.score)) {\n throw new ValidationError(\n `catchRate: result for \"${result.itemId}\" has score ${result.score}; expected a finite number or null`,\n )\n }\n scoreByItemId.set(result.itemId, result.score)\n }\n\n const byKind: Partial<Record<PlantKind, PlantKindCounts>> = {}\n const missedIds: string[] = []\n const missingIds: string[] = []\n let caught = 0\n let missed = 0\n let indecisive = 0\n\n for (const plant of manifest.plants) {\n let counts = byKind[plant.kind]\n if (counts === undefined) {\n counts = { seeded: 0, caught: 0, missed: 0, indecisive: 0, rate: null }\n byKind[plant.kind] = counts\n }\n counts.seeded += 1\n if (!scoreByItemId.has(plant.item.itemId)) {\n missingIds.push(plant.id)\n continue\n }\n const score = scoreByItemId.get(plant.item.itemId) ?? null\n if (score === null) {\n indecisive += 1\n counts.indecisive += 1\n continue\n }\n const graderSaid: PlantExpectation = score >= manifest.acceptThreshold ? 'accept' : 'reject'\n if (graderSaid === plant.expectedVerdict) {\n caught += 1\n counts.caught += 1\n } else {\n missed += 1\n counts.missed += 1\n missedIds.push(plant.id)\n }\n }\n\n const seeded = manifest.plants.length\n const decided = caught + missed\n const report: CatchRateReport = {\n status: 'evaluated',\n seeded,\n caught,\n missed,\n indecisive,\n rate: null,\n byKind,\n missedIds,\n missingIds,\n unseeded: unseededRejection(manifest, scoreByItemId),\n }\n\n if (seeded === 0) {\n return {\n ...report,\n status: 'not_evaluated',\n reason: 'no plant was seeded, so the grader was never asked a question it could fail',\n }\n }\n if (missingIds.length > 0) {\n return {\n ...report,\n status: 'incomplete',\n reason: `${missingIds.length} of ${seeded} seeded plants have no result: ${missingIds.join(', ')}`,\n }\n }\n if (decided === 0) {\n return {\n ...report,\n status: 'not_evaluated',\n reason: `all ${seeded} seeded plants are indecisive: no check tested the seeded defect`,\n }\n }\n\n for (const counts of Object.values(byKind)) {\n const kindDecided = counts.caught + counts.missed\n counts.rate = kindDecided === 0 ? null : counts.caught / kindDecided\n }\n report.rate = caught / decided\n return report\n}\n\nfunction unseededRejection(\n manifest: PlantManifest,\n scoreByItemId: ReadonlyMap<string, number | null>,\n): UnseededRejection {\n const plantItemIds = new Set(manifest.plants.map((plant) => plant.item.itemId))\n let n = 0\n let decided = 0\n let rejected = 0\n for (const itemId of manifest.itemIds) {\n if (plantItemIds.has(itemId)) continue\n n += 1\n const score = scoreByItemId.get(itemId)\n if (score === undefined || score === null) continue\n decided += 1\n if (score < manifest.acceptThreshold) rejected += 1\n }\n return { n, decided, rejected, rejectionRate: decided === 0 ? null : rejected / decided }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAyEA,eAAsB,iBACpB,YACA,cACA,aACA,oBACA,UAAmC,CAAC,GACH;CACjC,MAAM,YAAY,QAAQ,aAAa;CACvC,MAAM,aAAa,QAAQ,uBAAuB;CAClD,MAAM,OAAO,QAAQ;CACrB,2BAA2B,WAAW,YAAY,IAAI;CACtD,2BACE,YAAY,KAAK,WAAW,OAAO,EAAE,GACrC,aACF;CACA,2BAA2B,oBAAoB,gBAAgB;CAC/D,MAAM,SAAS,QAAQ,mBAAmB;CAC1C,IAAI,SAAS,KAAK,OAAO,MAAM,MAAM,GACnC,MAAM,IAAI,MAAM,qCAAqC;CAEvD,MAAM,aAAa,YAAY,KAAK,YAAY;EAC9C,GAAG;EACH,SAAS,OAAO,WAAW,mBAAmB,OAAO,EAAE;CACzD,EAAE;CACF,MAAM,cAAc,CAAC,GAAG,kBAAkB;CAC1C,MAAM,OAAO,MAAM,WAAW,SAAS;CACvC,2BACE,KAAK,KAAK,QAAQ,IAAI,KAAK,GAC3B,OACF;CACA,MAAM,WAAW,MAAM,aAAa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S,iBAAiB,YAAY;CACpD;CACA,OAAO;EAAE;EAAG;EAAS;EAAU,eAAe,YAAY,IAAI,OAAO,WAAW;CAAQ;AAC1F"}
@@ -1,4 +1,4 @@
1
- import { A as MultishotTransportRequest, D as MultishotToolDefinition, T as MultishotResult, c as RunMultishotMatrixResult, f as RunMultishotOptions, s as RunMultishotMatrixOptions, w as MultishotPersona } from "../../matrix-Cf-AGxGh.js";
1
+ import { A as MultishotTransportRequest, D as MultishotToolDefinition, T as MultishotResult, c as RunMultishotMatrixResult, f as RunMultishotOptions, s as RunMultishotMatrixOptions, w as MultishotPersona } from "../../matrix-BXo3PSqM.js";
2
2
  //#region src/multishot/golden/compare.d.ts
3
3
  interface CompareOptions {
4
4
  /** Stop after this many mismatches. A structural divergence high in the
@@ -1,5 +1,5 @@
1
- import { C as JudgeDimension, w as JudgeScore } from "../types-CHfn1zg5.js";
2
- import { A as MultishotTransportRequest, C as MultishotMessage, D as MultishotToolDefinition, E as MultishotShape, M as MultishotTransportToolCall, N as assertMultishotShotResult, O as MultishotToolExecutor, S as MultishotFatalToolError, T as MultishotResult, _ as renderDimensions, a as MultishotCellOutput, b as MultishotArtifact, c as RunMultishotMatrixResult, d as MultishotShot, f as RunMultishotOptions, g as MultishotJudgeConfig, h as JudgeRunResult, i as ConversationJudgeInput, j as MultishotTransportResponse, k as MultishotTransport, l as computeCellComposite, m as DEFAULT_JUDGE_MODEL, n as CellCompositeInput, o as MultishotJudges, p as runMultishot, r as CellCompositeScore, s as RunMultishotMatrixOptions, t as ArtifactJudgeInput, u as runMultishotMatrix, v as renderJsonFooter, w as MultishotPersona, x as MultishotDriverEmptyError, y as runJudge } from "../matrix-Cf-AGxGh.js";
1
+ import { C as JudgeDimension, w as JudgeScore } from "../types-DDKfH-N6.js";
2
+ import { A as MultishotTransportRequest, C as MultishotMessage, D as MultishotToolDefinition, E as MultishotShape, M as MultishotTransportToolCall, N as assertMultishotShotResult, O as MultishotToolExecutor, S as MultishotFatalToolError, T as MultishotResult, _ as renderDimensions, a as MultishotCellOutput, b as MultishotArtifact, c as RunMultishotMatrixResult, d as MultishotShot, f as RunMultishotOptions, g as MultishotJudgeConfig, h as JudgeRunResult, i as ConversationJudgeInput, j as MultishotTransportResponse, k as MultishotTransport, l as computeCellComposite, m as DEFAULT_JUDGE_MODEL, n as CellCompositeInput, o as MultishotJudges, p as runMultishot, r as CellCompositeScore, s as RunMultishotMatrixOptions, t as ArtifactJudgeInput, u as runMultishotMatrix, v as renderJsonFooter, w as MultishotPersona, x as MultishotDriverEmptyError, y as runJudge } from "../matrix-BXo3PSqM.js";
3
3
  import { AgentProfile } from "@tangle-network/agent-interface";
4
4
  //#region src/multishot/cost.d.ts
5
5
  /**
package/dist/openapi.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "openapi": "3.1.0",
3
3
  "info": {
4
4
  "title": "@tangle-network/agent-eval — wire protocol",
5
- "version": "0.220.2",
5
+ "version": "0.221.0",
6
6
  "description": "HTTP and stdio RPC interface to agent-eval. The TypeScript runtime is the source of truth; this spec is the contract that cross-language clients (Python, Rust, Go) generate from.\n\nWire-protocol version: 1.1.0. Bumps on breaking changes to request/response schemas.",
7
7
  "contact": {
8
8
  "name": "Tangle Network",