@tangle-network/agent-eval 1.0.0 → 1.0.2

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 (221) hide show
  1. package/CHANGELOG.md +242 -0
  2. package/README.md +2 -1
  3. package/dist/adapters/http.d.ts +2 -2
  4. package/dist/{agreement-irr-BTjDN0i6.js → agreement-irr-w-t3XUTD.js} +2 -2
  5. package/dist/{agreement-irr-BTjDN0i6.js.map → agreement-irr-w-t3XUTD.js.map} +1 -1
  6. package/dist/analyst/index.d.ts +7 -7
  7. package/dist/analyst/index.js +11 -11
  8. package/dist/{analyze-runs-C-pP1sK9.d.ts → analyze-runs-BYyMShsj.d.ts} +2 -2
  9. package/dist/{analyze-runs-C-pP1sK9.d.ts.map → analyze-runs-BYyMShsj.d.ts.map} +1 -1
  10. package/dist/{analyze-runs-Ck68mbgj.js → analyze-runs-Da7P_Mc5.js} +9 -10
  11. package/dist/{analyze-runs-Ck68mbgj.js.map → analyze-runs-Da7P_Mc5.js.map} +1 -1
  12. package/dist/{benchmark-command-DWkc5mzq.js → benchmark-command-BeDZB3BQ.js} +11 -11
  13. package/dist/{benchmark-command-DWkc5mzq.js.map → benchmark-command-BeDZB3BQ.js.map} +1 -1
  14. package/dist/benchmarks/index.d.ts +4 -4
  15. package/dist/benchmarks/index.js +5 -5
  16. package/dist/builder-eval/index.js +1 -1
  17. package/dist/{calibration-6usfVYYo.js → calibration-DLzckXnn.js} +2 -2
  18. package/dist/{calibration-6usfVYYo.js.map → calibration-DLzckXnn.js.map} +1 -1
  19. package/dist/campaign/index.d.ts +5 -5
  20. package/dist/campaign/index.js +10 -10
  21. package/dist/{campaign-DdOgQfp8.js → campaign-DKZiYHUq.js} +15 -15
  22. package/dist/{campaign-DdOgQfp8.js.map → campaign-DKZiYHUq.js.map} +1 -1
  23. package/dist/{campaign-evidence-MjCjkb5a.js → campaign-evidence-BICB3a9Z.js} +3 -3
  24. package/dist/{campaign-evidence-MjCjkb5a.js.map → campaign-evidence-BICB3a9Z.js.map} +1 -1
  25. package/dist/{chat-client-CO3uB33i.js → chat-client-D0me8iwq.js} +2 -2
  26. package/dist/{chat-client-CO3uB33i.js.map → chat-client-D0me8iwq.js.map} +1 -1
  27. package/dist/{chat-json-call-8yUv4LFO.js → chat-json-call-C473CwTt.js} +2 -2
  28. package/dist/{chat-json-call-8yUv4LFO.js.map → chat-json-call-C473CwTt.js.map} +1 -1
  29. package/dist/cli.js +7 -7
  30. package/dist/{cluster-bootstrap-SbaeM44s.js → cluster-bootstrap-hNXESoc1.js} +2 -2
  31. package/dist/{cluster-bootstrap-SbaeM44s.js.map → cluster-bootstrap-hNXESoc1.js.map} +1 -1
  32. package/dist/{completion-verifier-rqbMh5-4.js → completion-verifier-ClmJV_Yc.js} +2 -2
  33. package/dist/{completion-verifier-rqbMh5-4.js.map → completion-verifier-ClmJV_Yc.js.map} +1 -1
  34. package/dist/contract/index.d.ts +8 -8
  35. package/dist/contract/index.js +13 -13
  36. package/dist/{decision-point-lhMgODOR.js → decision-point-CErE7GnP.js} +6 -6
  37. package/dist/decision-point-CErE7GnP.js.map +1 -0
  38. package/dist/{default-registry-B1DstPYg.d.ts → default-registry-DKlKVXMx.d.ts} +22 -6
  39. package/dist/default-registry-DKlKVXMx.d.ts.map +1 -0
  40. package/dist/{default-registry-C1tPEjZ4.js → default-registry-gmDeN0KT.js} +38 -7
  41. package/dist/default-registry-gmDeN0KT.js.map +1 -0
  42. package/dist/{define-agent-eval-CAffiFbN.d.ts → define-agent-eval-B9zPWFSK.d.ts} +6 -6
  43. package/dist/{define-agent-eval-CAffiFbN.d.ts.map → define-agent-eval-B9zPWFSK.d.ts.map} +1 -1
  44. package/dist/{define-agent-eval-Cc15qGik.js → define-agent-eval-BVhGn7VV.js} +6 -6
  45. package/dist/{define-agent-eval-Cc15qGik.js.map → define-agent-eval-BVhGn7VV.js.map} +1 -1
  46. package/dist/{descriptive-cPwITVfy.js → descriptive-BTzLL-aj.js} +46 -3
  47. package/dist/descriptive-BTzLL-aj.js.map +1 -0
  48. package/dist/diagnosis/index.d.ts +2 -2
  49. package/dist/diagnosis/index.js +2 -2
  50. package/dist/{dspy-rlm-engine-jDiWkul6.js → dspy-rlm-engine-C0zR2xiM.js} +2 -2
  51. package/dist/{dspy-rlm-engine-jDiWkul6.js.map → dspy-rlm-engine-C0zR2xiM.js.map} +1 -1
  52. package/dist/{eval-campaign-C_mNDshv.js → eval-campaign-DVqiBoXR.js} +3 -3
  53. package/dist/{eval-campaign-C_mNDshv.js.map → eval-campaign-DVqiBoXR.js.map} +1 -1
  54. package/dist/{evaluation-BPqUvZ66.d.ts → evaluation-B0-KVXaV.d.ts} +4 -2
  55. package/dist/evaluation-B0-KVXaV.d.ts.map +1 -0
  56. package/dist/{evaluation-B8H3GYej.js → evaluation-BBI37mRe.js} +2 -1
  57. package/dist/evaluation-BBI37mRe.js.map +1 -0
  58. package/dist/evaluation.d.ts +1 -1
  59. package/dist/evaluation.js +1 -1
  60. package/dist/{exact-types-D98BKpxo.d.ts → exact-types-CIViGj98.d.ts} +3 -3
  61. package/dist/{exact-types-D98BKpxo.d.ts.map → exact-types-CIViGj98.d.ts.map} +1 -1
  62. package/dist/experiment/index.d.ts +1 -1
  63. package/dist/experiment/index.js +9 -8
  64. package/dist/experiment/index.js.map +1 -1
  65. package/dist/{exporters-B5Ze_RKh.d.ts → exporters-BYBG9b1n.d.ts} +2 -2
  66. package/dist/{exporters-B5Ze_RKh.d.ts.map → exporters-BYBG9b1n.d.ts.map} +1 -1
  67. package/dist/{external-optimizer-process-BRVmaDFe.js → external-optimizer-process-DKgrrX0J.js} +2 -2
  68. package/dist/{external-optimizer-process-BRVmaDFe.js.map → external-optimizer-process-DKgrrX0J.js.map} +1 -1
  69. package/dist/{external-optimizer-subprocess-U616hV_l.js → external-optimizer-subprocess-wzMaA0oN.js} +2 -2
  70. package/dist/{external-optimizer-subprocess-U616hV_l.js.map → external-optimizer-subprocess-wzMaA0oN.js.map} +1 -1
  71. package/dist/{feedback-trajectory-SBGncrCP.d.ts → feedback-trajectory-Ck7K7AhK.d.ts} +2 -2
  72. package/dist/{feedback-trajectory-SBGncrCP.d.ts.map → feedback-trajectory-Ck7K7AhK.d.ts.map} +1 -1
  73. package/dist/{findings-store-B75Dspaq.js → findings-store-DNSvmy8U.js} +4 -4
  74. package/dist/{findings-store-B75Dspaq.js.map → findings-store-DNSvmy8U.js.map} +1 -1
  75. package/dist/fuzz.js +1 -1
  76. package/dist/{index-CUjeTDPv.d.ts → index-Bn-P_XAl.d.ts} +4 -4
  77. package/dist/{index-CUjeTDPv.d.ts.map → index-Bn-P_XAl.d.ts.map} +1 -1
  78. package/dist/{index-B7v2QHlD.d.ts → index-BwutH5i7.d.ts} +4 -4
  79. package/dist/{index-B7v2QHlD.d.ts.map → index-BwutH5i7.d.ts.map} +1 -1
  80. package/dist/{index-aDPVYBIM.d.ts → index-ByJ20lyu.d.ts} +7 -7
  81. package/dist/{index-aDPVYBIM.d.ts.map → index-ByJ20lyu.d.ts.map} +1 -1
  82. package/dist/{index-DUn0GNiZ.d.ts → index-CtcCSO1Y.d.ts} +4 -4
  83. package/dist/{index-DUn0GNiZ.d.ts.map → index-CtcCSO1Y.d.ts.map} +1 -1
  84. package/dist/index.d.ts +17 -17
  85. package/dist/index.js +38 -43
  86. package/dist/index.js.map +1 -1
  87. package/dist/{judge-calibration-DGqlfWW8.js → judge-calibration-D93UCm1k.js} +2 -2
  88. package/dist/{judge-calibration-DGqlfWW8.js.map → judge-calibration-D93UCm1k.js.map} +1 -1
  89. package/dist/{judge-gate-Di_6bifh.js → judge-gate-C9sLLJ-v.js} +3 -3
  90. package/dist/{judge-gate-Di_6bifh.js.map → judge-gate-C9sLLJ-v.js.map} +1 -1
  91. package/dist/kind-factory-VKysp1ds.js.map +1 -1
  92. package/dist/{llm-client-kJ9EOqjt.js → llm-client-BdSiZ4qz.js} +2 -2
  93. package/dist/{llm-client-kJ9EOqjt.js.map → llm-client-BdSiZ4qz.js.map} +1 -1
  94. package/dist/{llm-judge-D6JtIqiU.js → llm-judge-BYBLxREr.js} +14 -14
  95. package/dist/{llm-judge-D6JtIqiU.js.map → llm-judge-BYBLxREr.js.map} +1 -1
  96. package/dist/{matrix-CBUzIZs4.d.ts → matrix-4DcRFJ7Q.d.ts} +2 -2
  97. package/dist/{matrix-CBUzIZs4.d.ts.map → matrix-4DcRFJ7Q.d.ts.map} +1 -1
  98. package/dist/{internal-v6XfOeJW.js → mean-DDFhslBt.js} +48 -2
  99. package/dist/mean-DDFhslBt.js.map +1 -0
  100. package/dist/meta-eval/index.js +7 -7
  101. package/dist/multishot/golden/index.d.ts +1 -1
  102. package/dist/multishot/index.d.ts +2 -2
  103. package/dist/openapi.json +1 -1
  104. package/dist/{outcome-observations-D4snOtUb.js → outcome-observations-ahbNtxuP.js} +3 -3
  105. package/dist/{outcome-observations-D4snOtUb.js.map → outcome-observations-ahbNtxuP.js.map} +1 -1
  106. package/dist/{paired-arms-D5H_58e8.js → paired-arms-C0Vd9bGG.js} +4 -4
  107. package/dist/{paired-arms-D5H_58e8.js.map → paired-arms-C0Vd9bGG.js.map} +1 -1
  108. package/dist/{paired-binary-BR0nwHOA.js → paired-binary-B477lksS.js} +2 -2
  109. package/dist/{paired-binary-BR0nwHOA.js.map → paired-binary-B477lksS.js.map} +1 -1
  110. package/dist/{paired-promotion-decision-BiVumgvM.js → paired-promotion-decision-5Pl_qJLX.js} +3 -3
  111. package/dist/{paired-promotion-decision-BiVumgvM.js.map → paired-promotion-decision-5Pl_qJLX.js.map} +1 -1
  112. package/dist/{paired-tests-C2zUqgUW.js → paired-tests-kASEKpc-.js} +3 -37
  113. package/dist/paired-tests-kASEKpc-.js.map +1 -0
  114. package/dist/{pareto-7_LEmYGG.js → pareto-DY_x3HHg.js} +7 -7
  115. package/dist/{pareto-7_LEmYGG.js.map → pareto-DY_x3HHg.js.map} +1 -1
  116. package/dist/pipelines/index.d.ts +1 -1
  117. package/dist/pipelines/index.js +1 -1
  118. package/dist/{power-and-mde-CHvyDO_H.js → power-and-mde-CRxepy8y.js} +3 -3
  119. package/dist/{power-and-mde-CHvyDO_H.js.map → power-and-mde-CRxepy8y.js.map} +1 -1
  120. package/dist/{promotion-policy-D7B4_jEZ.js → promotion-policy-f79oklG_.js} +4 -4
  121. package/dist/{promotion-policy-D7B4_jEZ.js.map → promotion-policy-f79oklG_.js.map} +1 -1
  122. package/dist/{proposal-findings-WFQrxnfe.js → proposal-findings-duV5flPv.js} +2 -2
  123. package/dist/{proposal-findings-WFQrxnfe.js.map → proposal-findings-duV5flPv.js.map} +1 -1
  124. package/dist/{raw-provider-sink-DDLkP_eF.js → raw-provider-sink-RbaEv2vB.js} +2 -2
  125. package/dist/{raw-provider-sink-DDLkP_eF.js.map → raw-provider-sink-RbaEv2vB.js.map} +1 -1
  126. package/dist/{redact-C_wzC4c_.d.ts → redact-jrT0APTU.d.ts} +50 -35
  127. package/dist/redact-jrT0APTU.d.ts.map +1 -0
  128. package/dist/{redact-D6APJS1d.js → redact-zp_ILC4l.js} +92 -33
  129. package/dist/redact-zp_ILC4l.js.map +1 -0
  130. package/dist/redaction.d.ts +2 -0
  131. package/dist/redaction.js +1 -0
  132. package/dist/{registry-dhdDoAV8.d.ts → registry-CMtGAxOw.d.ts} +2 -2
  133. package/dist/{registry-dhdDoAV8.d.ts.map → registry-CMtGAxOw.d.ts.map} +1 -1
  134. package/dist/{release-confidence-CTUJz5mM.js → release-confidence--1iP-d3x.js} +2 -2
  135. package/dist/{release-confidence-CTUJz5mM.js.map → release-confidence--1iP-d3x.js.map} +1 -1
  136. package/dist/{render-pfAZ7IR4.js → render-CFrJ7M0o.js} +26 -26
  137. package/dist/render-CFrJ7M0o.js.map +1 -0
  138. package/dist/reporting.js +5 -5
  139. package/dist/{reward-hacking-Bjk3MAjh.js → reward-hacking-D-Vi9-fE.js} +3 -3
  140. package/dist/{reward-hacking-Bjk3MAjh.js.map → reward-hacking-D-Vi9-fE.js.map} +1 -1
  141. package/dist/rl.d.ts +3 -3
  142. package/dist/rl.js +9 -9
  143. package/dist/rollout/index.d.ts +4 -4
  144. package/dist/rollout/index.js +1 -1
  145. package/dist/{rollout-BhkMpAJT.js → rollout-BC4u-d_I.js} +3 -3
  146. package/dist/{rollout-BhkMpAJT.js.map → rollout-BC4u-d_I.js.map} +1 -1
  147. package/dist/{rubric-predictive-validity-CQp_M0vy.js → rubric-predictive-validity-BdxXDN6h.js} +2 -2
  148. package/dist/{rubric-predictive-validity-CQp_M0vy.js.map → rubric-predictive-validity-BdxXDN6h.js.map} +1 -1
  149. package/dist/{run-record-BUm-Jggo.js → run-record-B-G2Tu11.js} +2 -2
  150. package/dist/{run-record-BUm-Jggo.js.map → run-record-B-G2Tu11.js.map} +1 -1
  151. package/dist/{schema-DkFJr3Y8.d.ts → schema-CfoA9U_U.d.ts} +28 -2
  152. package/dist/schema-CfoA9U_U.d.ts.map +1 -0
  153. package/dist/search/index.d.ts +2 -2
  154. package/dist/search/index.js +2 -2
  155. package/dist/{search-kernel-CBdwFZ05.d.ts → search-kernel-BjR2Sr7w.d.ts} +2 -2
  156. package/dist/{search-kernel-CBdwFZ05.d.ts.map → search-kernel-BjR2Sr7w.d.ts.map} +1 -1
  157. package/dist/{search-summary-Bt3uuK53.js → search-summary-DedyTdiM.js} +4 -4
  158. package/dist/{search-summary-Bt3uuK53.js.map → search-summary-DedyTdiM.js.map} +1 -1
  159. package/dist/{sequential-De7BTAlV.js → sequential-Zp1tsxqI.js} +2 -2
  160. package/dist/{sequential-De7BTAlV.js.map → sequential-Zp1tsxqI.js.map} +1 -1
  161. package/dist/{server-DA6h3co5.js → server-CPKyf3bz.js} +2 -2
  162. package/dist/{server-DA6h3co5.js.map → server-CPKyf3bz.js.map} +1 -1
  163. package/dist/{skillopt-optimization-method-BKFbJEyz.js → skillopt-optimization-method-DmfZz-2d.js} +9 -9
  164. package/dist/{skillopt-optimization-method-BKFbJEyz.js.map → skillopt-optimization-method-DmfZz-2d.js.map} +1 -1
  165. package/dist/{spans-vZoW__3q.d.ts → spans-CGjHouKM.d.ts} +2 -2
  166. package/dist/{spans-vZoW__3q.d.ts.map → spans-CGjHouKM.d.ts.map} +1 -1
  167. package/dist/{statistical-heldout-C9hz_AF9.js → statistical-heldout-DYF5f10K.js} +3 -3
  168. package/dist/{statistical-heldout-C9hz_AF9.js.map → statistical-heldout-DYF5f10K.js.map} +1 -1
  169. package/dist/{statistical-heldout-Cei036nE.d.ts → statistical-heldout-bU7FBNjR.d.ts} +2 -2
  170. package/dist/{statistical-heldout-Cei036nE.d.ts.map → statistical-heldout-bU7FBNjR.d.ts.map} +1 -1
  171. package/dist/{store-tool-spans-C2g8UYm-.js → store-tool-spans-GGaCijFy.js} +19 -62
  172. package/dist/store-tool-spans-GGaCijFy.js.map +1 -0
  173. package/dist/{store-tool-spans-B3i3fl0A.d.ts → store-tool-spans-lWf6INTH.d.ts} +3 -44
  174. package/dist/store-tool-spans-lWf6INTH.d.ts.map +1 -0
  175. package/dist/{summary-report-BLnTyQKH.js → summary-report-BstMpOfy.js} +6 -7
  176. package/dist/{summary-report-BLnTyQKH.js.map → summary-report-BstMpOfy.js.map} +1 -1
  177. package/dist/supervisor-run/index.d.ts +12 -2
  178. package/dist/supervisor-run/index.d.ts.map +1 -1
  179. package/dist/supervisor-run/index.js +1 -1
  180. package/dist/{systemone-Cw2txK5m.d.ts → systemone-BDVgb6XV.d.ts} +7 -9
  181. package/dist/systemone-BDVgb6XV.d.ts.map +1 -0
  182. package/dist/systemone.d.ts +2 -2
  183. package/dist/systemone.js +2 -2
  184. package/dist/{tool-waste-CLJ46AbT.js → tool-waste-CRJqOASv.js} +3 -3
  185. package/dist/{tool-waste-CLJ46AbT.js.map → tool-waste-CRJqOASv.js.map} +1 -1
  186. package/dist/trace-repair/index.js +2 -2
  187. package/dist/traces.d.ts +18 -39
  188. package/dist/traces.d.ts.map +1 -1
  189. package/dist/traces.js +51 -57
  190. package/dist/traces.js.map +1 -1
  191. package/dist/{tree-DnBkWXun.js → tree-C2N31CoI.js} +5 -6
  192. package/dist/{tree-DnBkWXun.js.map → tree-C2N31CoI.js.map} +1 -1
  193. package/dist/{types-C54Uk_a1.d.ts → types-BF-xQGQn.d.ts} +2 -2
  194. package/dist/{types-C54Uk_a1.d.ts.map → types-BF-xQGQn.d.ts.map} +1 -1
  195. package/dist/{types-C-aOqgt2.d.ts → types-DNB9hIXa.d.ts} +2 -2
  196. package/dist/{types-C-aOqgt2.d.ts.map → types-DNB9hIXa.d.ts.map} +1 -1
  197. package/dist/{types-0oMg7zee.d.ts → types-yofaDmQa.d.ts} +2 -2
  198. package/dist/{types-0oMg7zee.d.ts.map → types-yofaDmQa.d.ts.map} +1 -1
  199. package/dist/wire/index.d.ts +7 -7
  200. package/dist/wire/index.js +1 -1
  201. package/docs/design/statistics-decisions.md +1 -0
  202. package/docs/redaction.md +24 -1
  203. package/docs/systemone.md +6 -0
  204. package/package.json +7 -2
  205. package/dist/decision-point-lhMgODOR.js.map +0 -1
  206. package/dist/default-registry-B1DstPYg.d.ts.map +0 -1
  207. package/dist/default-registry-C1tPEjZ4.js.map +0 -1
  208. package/dist/descriptive-cPwITVfy.js.map +0 -1
  209. package/dist/evaluation-B8H3GYej.js.map +0 -1
  210. package/dist/evaluation-BPqUvZ66.d.ts.map +0 -1
  211. package/dist/internal-v6XfOeJW.js.map +0 -1
  212. package/dist/mean-BPuUNznQ.js +0 -16
  213. package/dist/mean-BPuUNznQ.js.map +0 -1
  214. package/dist/paired-tests-C2zUqgUW.js.map +0 -1
  215. package/dist/redact-C_wzC4c_.d.ts.map +0 -1
  216. package/dist/redact-D6APJS1d.js.map +0 -1
  217. package/dist/render-pfAZ7IR4.js.map +0 -1
  218. package/dist/schema-DkFJr3Y8.d.ts.map +0 -1
  219. package/dist/store-tool-spans-B3i3fl0A.d.ts.map +0 -1
  220. package/dist/store-tool-spans-C2g8UYm-.js.map +0 -1
  221. package/dist/systemone-Cw2txK5m.d.ts.map +0 -1
@@ -1,7 +1,7 @@
1
1
  import { f as Run } from "../schema-CkIvnmLU.js";
2
2
  import { a as RunFilter, s as TraceStore } from "../store-CMs5wGXP.js";
3
3
  import { n as FailureClusterReport, r as failureClusterView, t as FailureCluster } from "../failure-cluster-DOoa7CBg.js";
4
- import { t as DiagnosisSpan } from "../spans-vZoW__3q.js";
4
+ import { t as DiagnosisSpan } from "../spans-CGjHouKM.js";
5
5
  import { _ as computeToolUseMetrics, a as JudgeAgreementReport, c as BudgetBreachFinding, f as TrajectoryStep, i as toolWasteView, l as BudgetBreachReport, n as ToolWasteOptions, o as JudgePair, r as ToolWasteReport, s as judgeAgreementView, t as ToolWasteFinding, u as budgetBreachView, v as BaselineOptions } from "../tool-waste-BFG1vwTV.js";
6
6
  /** One step of a run, as the diff reads it. */
7
7
  interface DiffStep {
@@ -1,7 +1,7 @@
1
1
  import { i as isToolSpan } from "../schema-D-xu3MU_.js";
2
2
  import { r as hasCapturedToolArgs, t as argHash } from "../query-CGXzO9d4.js";
3
3
  import { t as executionTrackByLane } from "../execution-tracks-DaDXYwAq.js";
4
- import { a as budgetBreachView, i as failureClusterView, n as computeToolUseMetrics, r as judgeAgreementView, t as toolWasteView } from "../tool-waste-CLJ46AbT.js";
4
+ import { a as budgetBreachView, i as failureClusterView, n as computeToolUseMetrics, r as judgeAgreementView, t as toolWasteView } from "../tool-waste-CRJqOASv.js";
5
5
  // src/pipelines/first-divergence.ts
6
6
  function diffSteps(a, b) {
7
7
  const partnerOfA = /* @__PURE__ */ new Map();
@@ -1,5 +1,5 @@
1
- import { o as normalCdf } from "./paired-arms-D5H_58e8.js";
2
- import { s as zQuantile } from "./internal-v6XfOeJW.js";
1
+ import { o as normalCdf } from "./paired-arms-C0Vd9bGG.js";
2
+ import { u as zQuantile } from "./mean-DDFhslBt.js";
3
3
  // src/statistics/power-and-mde.ts
4
4
  /**
5
5
  * Required N per arm for a two-sample comparison at target effect size,
@@ -96,4 +96,4 @@ function mcnemarPower(opts) {
96
96
  }
97
97
  export { requiredSampleSize as a, requiredPairedSampleSize as i, mcnemarRequiredN as n, pairedMde as r, mcnemarPower as t };
98
98
 
99
- //# sourceMappingURL=power-and-mde-CHvyDO_H.js.map
99
+ //# sourceMappingURL=power-and-mde-CRxepy8y.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"power-and-mde-CHvyDO_H.js","names":[],"sources":["../src/statistics/power-and-mde.ts"],"sourcesContent":["import { normalCdf } from '../math/normal'\nimport { zQuantile } from './internal'\n\n// ── Power analysis + minimum detectable effect ───────────────────────\n\n/**\n * Required N per arm for a two-sample comparison at target effect size,\n * alpha, and power. Normal-approximation formula:\n * n = 2 * ( (z_{1-α/2} + z_{1-β}) / d )^2\n * where d is Cohen's d. Returns Infinity for effect ≤ 0.\n */\nexport function requiredSampleSize(opts: {\n effect: number\n alpha?: number\n power?: number\n twoSided?: boolean\n}): number {\n const effect = opts.effect\n if (!Number.isFinite(effect) || effect <= 0) return Infinity\n const alpha = opts.alpha ?? 0.05\n const power = opts.power ?? 0.8\n const twoSided = opts.twoSided ?? true\n const zAlpha = zQuantile(twoSided ? 1 - alpha / 2 : 1 - alpha)\n const zBeta = zQuantile(power)\n const n = 2 * ((zAlpha + zBeta) / effect) ** 2\n return Math.ceil(n)\n}\n\n/**\n * Required number of paired observations for a target Cohen's dz.\n * Unlike the independent-groups formula, this has no two-arm factor of two.\n *\n * Normal quantiles with no t correction, so treat the result as a LOWER bound:\n * it returns 32 where the exact t-based answer is 34 at dz = 0.5, and 13 where\n * it is 15 at dz = 0.8 — a 6–13 % shortfall precisely in the range a caller\n * consults to decide whether 3–10 repetitions suffice.\n */\nexport function requiredPairedSampleSize(opts: {\n effect: number\n alpha?: number\n power?: number\n twoSided?: boolean\n}): number {\n const effect = opts.effect\n if (!Number.isFinite(effect) || effect <= 0) return Infinity\n const alpha = opts.alpha ?? 0.05\n const power = opts.power ?? 0.8\n const twoSided = opts.twoSided ?? true\n const zAlpha = zQuantile(twoSided ? 1 - alpha / 2 : 1 - alpha)\n const zBeta = zQuantile(power)\n return Math.ceil(((zAlpha + zBeta) / effect) ** 2)\n}\n\n/**\n * Minimum detectable paired effect (standardised units) for a target paired\n * sample size: d_min = (z_{1-α/2} + z_β) / sqrt(n_paired). Multiply by\n * sd(deltas) for score units; treat as a lower bound — Wilcoxon and bootstrap\n * have asymptotic relative efficiency below 1 vs the t-test on heavy tails.\n */\nexport function pairedMde(opts: {\n nPaired: number\n alpha?: number\n power?: number\n twoSided?: boolean\n}): number {\n if (!Number.isFinite(opts.nPaired) || opts.nPaired <= 0) return Infinity\n const alpha = opts.alpha ?? 0.05\n const power = opts.power ?? 0.8\n const twoSided = opts.twoSided ?? true\n const zAlpha = zQuantile(twoSided ? 1 - alpha / 2 : 1 - alpha)\n const zBeta = zQuantile(power)\n return (zAlpha + zBeta) / Math.sqrt(opts.nPaired)\n}\n\n/**\n * Number of paired observations needed for a McNemar test to reach a target\n * power — the pre-registration companion to {@link mcnemar}. Parametrised by the\n * expected discordant-cell probabilities `p10` (P[treatment wins on a pair]) and\n * `p01` (P[control wins]); concordant pairs carry no information, so the count\n * is driven entirely by the discordant rate. Lachin's (1992) asymptotic normal\n * approximation: with discordant rate `pDisc = p10 + p01` and marginal effect\n * `δ = p10 − p01`,\n * n = ( z_{1-α/2}·√pDisc + z_{1-β}·√(pDisc − δ²) )² / δ².\n * Returns Infinity when there is no effect (p10 === p01). Asymptotic — at the\n * tiny discordant counts where the exact {@link mcnemar} differs from the normal\n * approximation, treat the result as a lower bound and prefer the discordant-pair\n * floor.\n */\nexport function mcnemarRequiredN(opts: {\n p10: number\n p01: number\n alpha?: number\n power?: number\n twoSided?: boolean\n}): number {\n const { p10, p01 } = opts\n if (p10 < 0 || p01 < 0 || p10 + p01 > 1) {\n throw new Error(`mcnemarRequiredN: require p10,p01 ≥ 0 and p10+p01 ≤ 1 (got ${p10}, ${p01})`)\n }\n const delta = p10 - p01\n if (delta === 0) return Infinity\n const alpha = opts.alpha ?? 0.05\n const power = opts.power ?? 0.8\n const twoSided = opts.twoSided ?? true\n const pDisc = p10 + p01\n const zAlpha = zQuantile(twoSided ? 1 - alpha / 2 : 1 - alpha)\n const zBeta = zQuantile(power)\n const n =\n (zAlpha * Math.sqrt(pDisc) + zBeta * Math.sqrt(Math.max(0, pDisc - delta * delta))) ** 2 /\n (delta * delta)\n return Math.ceil(n)\n}\n\n/**\n * Power of a McNemar test at a given number of paired observations, the inverse\n * of {@link mcnemarRequiredN} (same Lachin asymptotic model, same parameters).\n * Returns a value in [0, 1]; equals `alpha` when there is no effect.\n */\nexport function mcnemarPower(opts: {\n p10: number\n p01: number\n nPairs: number\n alpha?: number\n twoSided?: boolean\n}): number {\n const { p10, p01, nPairs } = opts\n if (p10 < 0 || p01 < 0 || p10 + p01 > 1) {\n throw new Error(`mcnemarPower: require p10,p01 ≥ 0 and p10+p01 ≤ 1 (got ${p10}, ${p01})`)\n }\n const alpha = opts.alpha ?? 0.05\n const twoSided = opts.twoSided ?? true\n const delta = p10 - p01\n if (delta === 0 || nPairs <= 0) return alpha\n const pDisc = p10 + p01\n const zAlpha = zQuantile(twoSided ? 1 - alpha / 2 : 1 - alpha)\n const denom = Math.sqrt(Math.max(1e-12, pDisc - delta * delta))\n const zBeta = (Math.sqrt(nPairs) * Math.abs(delta) - zAlpha * Math.sqrt(pDisc)) / denom\n return Math.min(1, Math.max(0, normalCdf(zBeta)))\n}\n"],"mappings":";;;;;;;;;AAWA,SAAgB,mBAAmB,MAKxB;CACT,MAAM,SAAS,KAAK;CACpB,IAAI,CAAC,OAAO,SAAS,MAAM,KAAK,UAAU,GAAG,OAAO;CACpD,MAAM,QAAQ,KAAK,SAAS;CAC5B,MAAM,QAAQ,KAAK,SAAS;CAC5B,MAAM,WAAW,KAAK,YAAY;CAGlC,MAAM,IAAI,MAFK,UAAU,WAAW,IAAI,QAAQ,IAAI,IAAI,KAEnC,IADP,UAAU,KACK,KAAK,WAAW;CAC7C,OAAO,KAAK,KAAK,CAAC;AACpB;;;;;;;;;;AAWA,S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,QAAQ;CACX,OAAO,KAAK,KAAK,CAAC;AACpB;;;;;;AAOA,SAAgB,aAAa,MAMlB;CACT,MAAM,EAAE,KAAK,KAAK,WAAW;CAC7B,IAAI,MAAM,KAAK,MAAM,KAAK,MAAM,MAAM,GACpC,MAAM,IAAI,MAAM,0DAA0D,IAAI,IAAI,IAAI,EAAE;CAE1F,MAAM,QAAQ,KAAK,SAAS;CAC5B,MAAM,WAAW,KAAK,YAAY;CAClC,MAAM,QAAQ,MAAM;CACpB,IAAI,UAAU,KAAK,UAAU,GAAG,OAAO;CACvC,MAAM,QAAQ,MAAM;CACpB,MAAM,SAAS,UAAU,WAAW,IAAI,QAAQ,IAAI,IAAI,KAAK;CAC7D,MAAM,QAAQ,KAAK,KAAK,KAAK,IAAI,OAAO,QAAQ,QAAQ,KAAK,CAAC;CAC9D,MAAM,SAAS,KAAK,KAAK,MAAM,IAAI,KAAK,IAAI,KAAK,IAAI,SAAS,KAAK,KAAK,KAAK,KAAK;CAClF,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,UAAU,KAAK,CAAC,CAAC;AAClD"}
1
+ {"version":3,"file":"power-and-mde-CRxepy8y.js","names":[],"sources":["../src/statistics/power-and-mde.ts"],"sourcesContent":["import { normalCdf } from '../math/normal'\nimport { zQuantile } from './internal'\n\n// ── Power analysis + minimum detectable effect ───────────────────────\n\n/**\n * Required N per arm for a two-sample comparison at target effect size,\n * alpha, and power. Normal-approximation formula:\n * n = 2 * ( (z_{1-α/2} + z_{1-β}) / d )^2\n * where d is Cohen's d. Returns Infinity for effect ≤ 0.\n */\nexport function requiredSampleSize(opts: {\n effect: number\n alpha?: number\n power?: number\n twoSided?: boolean\n}): number {\n const effect = opts.effect\n if (!Number.isFinite(effect) || effect <= 0) return Infinity\n const alpha = opts.alpha ?? 0.05\n const power = opts.power ?? 0.8\n const twoSided = opts.twoSided ?? true\n const zAlpha = zQuantile(twoSided ? 1 - alpha / 2 : 1 - alpha)\n const zBeta = zQuantile(power)\n const n = 2 * ((zAlpha + zBeta) / effect) ** 2\n return Math.ceil(n)\n}\n\n/**\n * Required number of paired observations for a target Cohen's dz.\n * Unlike the independent-groups formula, this has no two-arm factor of two.\n *\n * Normal quantiles with no t correction, so treat the result as a LOWER bound:\n * it returns 32 where the exact t-based answer is 34 at dz = 0.5, and 13 where\n * it is 15 at dz = 0.8 — a 6–13 % shortfall precisely in the range a caller\n * consults to decide whether 3–10 repetitions suffice.\n */\nexport function requiredPairedSampleSize(opts: {\n effect: number\n alpha?: number\n power?: number\n twoSided?: boolean\n}): number {\n const effect = opts.effect\n if (!Number.isFinite(effect) || effect <= 0) return Infinity\n const alpha = opts.alpha ?? 0.05\n const power = opts.power ?? 0.8\n const twoSided = opts.twoSided ?? true\n const zAlpha = zQuantile(twoSided ? 1 - alpha / 2 : 1 - alpha)\n const zBeta = zQuantile(power)\n return Math.ceil(((zAlpha + zBeta) / effect) ** 2)\n}\n\n/**\n * Minimum detectable paired effect (standardised units) for a target paired\n * sample size: d_min = (z_{1-α/2} + z_β) / sqrt(n_paired). Multiply by\n * sd(deltas) for score units; treat as a lower bound — Wilcoxon and bootstrap\n * have asymptotic relative efficiency below 1 vs the t-test on heavy tails.\n */\nexport function pairedMde(opts: {\n nPaired: number\n alpha?: number\n power?: number\n twoSided?: boolean\n}): number {\n if (!Number.isFinite(opts.nPaired) || opts.nPaired <= 0) return Infinity\n const alpha = opts.alpha ?? 0.05\n const power = opts.power ?? 0.8\n const twoSided = opts.twoSided ?? true\n const zAlpha = zQuantile(twoSided ? 1 - alpha / 2 : 1 - alpha)\n const zBeta = zQuantile(power)\n return (zAlpha + zBeta) / Math.sqrt(opts.nPaired)\n}\n\n/**\n * Number of paired observations needed for a McNemar test to reach a target\n * power — the pre-registration companion to {@link mcnemar}. Parametrised by the\n * expected discordant-cell probabilities `p10` (P[treatment wins on a pair]) and\n * `p01` (P[control wins]); concordant pairs carry no information, so the count\n * is driven entirely by the discordant rate. Lachin's (1992) asymptotic normal\n * approximation: with discordant rate `pDisc = p10 + p01` and marginal effect\n * `δ = p10 − p01`,\n * n = ( z_{1-α/2}·√pDisc + z_{1-β}·√(pDisc − δ²) )² / δ².\n * Returns Infinity when there is no effect (p10 === p01). Asymptotic — at the\n * tiny discordant counts where the exact {@link mcnemar} differs from the normal\n * approximation, treat the result as a lower bound and prefer the discordant-pair\n * floor.\n */\nexport function mcnemarRequiredN(opts: {\n p10: number\n p01: number\n alpha?: number\n power?: number\n twoSided?: boolean\n}): number {\n const { p10, p01 } = opts\n if (p10 < 0 || p01 < 0 || p10 + p01 > 1) {\n throw new Error(`mcnemarRequiredN: require p10,p01 ≥ 0 and p10+p01 ≤ 1 (got ${p10}, ${p01})`)\n }\n const delta = p10 - p01\n if (delta === 0) return Infinity\n const alpha = opts.alpha ?? 0.05\n const power = opts.power ?? 0.8\n const twoSided = opts.twoSided ?? true\n const pDisc = p10 + p01\n const zAlpha = zQuantile(twoSided ? 1 - alpha / 2 : 1 - alpha)\n const zBeta = zQuantile(power)\n const n =\n (zAlpha * Math.sqrt(pDisc) + zBeta * Math.sqrt(Math.max(0, pDisc - delta * delta))) ** 2 /\n (delta * delta)\n return Math.ceil(n)\n}\n\n/**\n * Power of a McNemar test at a given number of paired observations, the inverse\n * of {@link mcnemarRequiredN} (same Lachin asymptotic model, same parameters).\n * Returns a value in [0, 1]; equals `alpha` when there is no effect.\n */\nexport function mcnemarPower(opts: {\n p10: number\n p01: number\n nPairs: number\n alpha?: number\n twoSided?: boolean\n}): number {\n const { p10, p01, nPairs } = opts\n if (p10 < 0 || p01 < 0 || p10 + p01 > 1) {\n throw new Error(`mcnemarPower: require p10,p01 ≥ 0 and p10+p01 ≤ 1 (got ${p10}, ${p01})`)\n }\n const alpha = opts.alpha ?? 0.05\n const twoSided = opts.twoSided ?? true\n const delta = p10 - p01\n if (delta === 0 || nPairs <= 0) return alpha\n const pDisc = p10 + p01\n const zAlpha = zQuantile(twoSided ? 1 - alpha / 2 : 1 - alpha)\n const denom = Math.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{ r as pairedBootstrap } from "./paired-tests-C2zUqgUW.js";
2
- import { t as decidePairedPromotion } from "./paired-promotion-decision-BiVumgvM.js";
3
- import { o as pairHoldout, r as detectScale } from "./statistical-heldout-C9hz_AF9.js";
1
+ import { r as pairedBootstrap } from "./paired-tests-kASEKpc-.js";
2
+ import { t as decidePairedPromotion } from "./paired-promotion-decision-5Pl_qJLX.js";
3
+ import { o as pairHoldout, r as detectScale } from "./statistical-heldout-DYF5f10K.js";
4
4
  // src/campaign/gates/promotion-policy.ts
5
5
  /**
6
6
  * Build paired evidence for each objective and apply a promotion policy.
@@ -170,4 +170,4 @@ function paretoSignificanceGate(options) {
170
170
  }
171
171
  export { paretoPolicy as n, paretoSignificanceGate as r, buildEvidenceVector as t };
172
172
 
173
- //# sourceMappingURL=promotion-policy-D7B4_jEZ.js.map
173
+ //# sourceMappingURL=promotion-policy-f79oklG_.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"promotion-policy-D7B4_jEZ.js","names":[],"sources":["../src/campaign/gates/promotion-policy.ts"],"sourcesContent":["/**\n * Build paired evidence for each objective and apply a promotion policy.\n * The default policy requires at least one gain and every regression floor to\n * clear. A floor can fail because a larger loss remains plausible; that does\n * not demonstrate an observed regression. Missing evidence stays unresolved.\n * Confidence intervals apply to each axis, without a multiplicity adjustment.\n *\n * Cost and latency remain aggregate constraints because GateContext does not\n * supply paired observations for them. Compose a budget gate when needed.\n */\n\nimport {\n decidePairedPromotion,\n type PairedDecisionMethod,\n type PairedDecisionStatistic,\n type PairedMcNemarEvidence,\n} from '../../paired-promotion-decision'\nimport type { Direction } from '../../pareto'\nimport {\n DECISION_PAIRED_DELTA_STATISTIC,\n type PairedBootstrapResult,\n pairedBootstrap,\n} from '../../statistics'\nimport type { Gate, GateContext, GateDecision, GateResult, JudgeScore, Scenario } from '../types'\nimport { detectScale, pairHoldout } from './statistical-heldout'\n\n/** Where an objective's per-cell scalar comes from. `composite` reads the\n * judge's composite; `dimension` reads a named per-dimension score. */\nexport type ObjectiveSource = { kind: 'composite' } | { kind: 'dimension'; dimension: string }\n\nexport interface PromotionObjective {\n /** Stable label used in reports + `contributingGates`. */\n name: string\n source: ObjectiveSource\n /** 'maximize' (quality dims) or 'minimize' (error/risk/length dims). Orients\n * the paired delta so a positive bootstrap always means \"candidate better\". */\n direction: Direction\n /** Declared binary support {0, binaryScale}, including zero-only observations.\n * Must be finite and positive; paired cell scores must be 0 or this scale.\n * Uses the risk-difference mean and rejects the 'median' statistic. */\n binaryScale?: number\n /** The good-direction paired-delta CI lower bound must EXCEED this to count\n * as a significant gain on this axis. Interpreted in the judge's native\n * scale. Default 0 (⇒ \"confidently better\"). */\n gainThreshold?: number\n /** A floor breach (regression) is declared when the good-direction CI lower\n * bound is below −floorTolerance, or when the exact small-sample test proves\n * a drop past it. Defaults to 0.05 times the declared binary scale, or\n * auto-scales off observed magnitudes (0.05 on [0,1], 5 on 0-100). */\n floorTolerance?: number\n}\n\n/** Per-axis verdict from the shared paired decision rule.\n * 'regressed' includes uncertainty that prevents clearing the regression floor. */\nexport type AxisVerdict = 'improved' | 'regressed' | 'flat' | 'few_runs' | 'indeterminate'\n\nexport interface AxisEvidence {\n name: string\n source: ObjectiveSource\n direction: Direction\n /** Paired bootstrap on the GOOD-DIRECTION delta (oriented by `direction`):\n * a positive value means the candidate is better on this axis.\n *\n * DIAGNOSTIC on a pass/fail axis: there the verdict is decided on Tango's\n * score interval instead, because a percentile bootstrap over a three-atom\n * delta lattice is not a valid interval at the nonzero margin `floorTolerance`\n * and `gainThreshold` create. `ci` carries the interval that decided. */\n bootstrap: PairedBootstrapResult\n /** Which paired statistic `bootstrap.low`/`.high` bracket. `'mean'` unless the\n * caller asked for the median — on a pass/fail axis the median and its whole\n * CI are pinned at 0 by tie domination and can see neither a gain nor a\n * regression. `bootstrap.median` still carries the median point estimate. */\n bootstrapStatistic: 'median' | 'mean'\n /** The interval the axis verdict was actually decided on, good-direction and\n * in the axis's native units. */\n ci: { low: number; high: number }\n /** Which estimator produced `ci`. */\n decisionStatistic: PairedDecisionStatistic\n /** McNemar's exact evidence on a pass/fail axis; null otherwise. */\n mcnemar: PairedMcNemarEvidence | null\n /** `ci` has zero width or non-finite bounds. It cannot establish a gain or\n * clear a regression floor, regardless of the point estimate. */\n indeterminate: boolean\n /** Paired observations contributing to this axis. */\n n: number\n minimumRequired: number\n decisionMethod: PairedDecisionMethod\n gainThreshold: number\n floorTolerance: number\n verdict: AxisVerdict\n}\n\nexport interface EvidenceVector {\n /** One entry per objective — NOTHING averaged across axes. */\n axes: AxisEvidence[]\n /** Smallest paired n across axes that produced observations — the binding\n * evidence-sufficiency constraint. 0 when no axis produced observations. */\n minN: number\n /** Aggregate per-side cost from the gate context (a constraint input, not a\n * CI axis — see the module header). */\n cost: { candidate: number; baseline: number }\n}\n\n/** A promotion strategy: a pure function from the evidence vector to a verdict.\n * Many policies can run over the same `EvidenceVector` and disagree — that's\n * the point (competing strategies, shared evidence). */\nexport type PromotionPolicy = (ev: EvidenceVector) => GateResult\n\nexport interface BuildEvidenceVectorOptions {\n /** Minimum paired observations before an axis can claim significance; below\n * it the axis is `few_runs`. The exact small-sample test may require more\n * observations at the selected confidence. */\n minProductiveRuns?: number\n /** Confidence level for every axis bootstrap. Default 0.95. */\n confidence?: number\n /** Bootstrap resamples. Default 2000. */\n resamples?: number\n /** Fixed bootstrap seed for a deterministic, reproducible verdict. Default 1337. */\n seed?: number\n /** Paired statistic every axis CI is computed on. Default `'mean'` — see\n * {@link DECISION_PAIRED_DELTA_STATISTIC} for why the median is not. */\n statistic?: 'mean' | 'median'\n}\n\n/**\n * The Evidence Bus. For each objective, pair candidate vs baseline by full\n * cellId and bootstrap a CI on the good-direction paired delta. Reuses the\n * exact `pairHoldout` + `pairedBootstrap` machinery the held-out gate uses, so\n * a single source of truth governs pairing granularity + scale handling.\n */\nexport function buildEvidenceVector<TArtifact, TScenario extends Scenario>(\n ctx: GateContext<TArtifact, TScenario>,\n objectives: PromotionObjective[],\n opts: BuildEvidenceVectorOptions = {},\n): EvidenceVector {\n if (objectives.length === 0) {\n throw new Error('buildEvidenceVector: at least 1 objective required')\n }\n const confidence = opts.confidence ?? 0.95\n const resamples = opts.resamples ?? 2000\n const seed = opts.seed ?? 1337\n const baseline = ctx.baselineJudgeScores ?? ctx.judgeScores\n const scenarioIds = new Set(ctx.scenarios.map((s) => s.id))\n\n const axes: AxisEvidence[] = []\n for (const obj of objectives) {\n let select: (s: JudgeScore) => number | undefined\n if (obj.source.kind === 'composite') {\n select = (s) => s.composite\n } else {\n const dim = obj.source.dimension\n select = (s) => s.dimensions[dim]\n }\n const paired = pairHoldout(ctx.judgeScores, baseline, scenarioIds, select)\n // Orient to the good direction: maximize ⇒ bootstrap (candidate − baseline);\n // minimize ⇒ bootstrap (baseline − candidate) by swapping args, so a\n // positive bootstrap always reads as \"candidate better on this axis\".\n const before = obj.direction === 'maximize' ? paired.before : paired.after\n const after = obj.direction === 'maximize' ? paired.after : paired.before\n const n = paired.before.length\n const binaryScale = obj.binaryScale\n const floorTolerance =\n obj.floorTolerance ?? 0.05 * (binaryScale ?? detectScale([...paired.before, ...paired.after]))\n const gainThreshold = obj.gainThreshold ?? 0\n // Axes are decided on the MEAN paired delta — which for a pass/fail axis is\n // exactly the change in success rate. The median is structurally blind on\n // the shapes eval data lands in: with most pairs tied its bootstrap CI\n // collapses to [0,0] and the axis reads 'flat', hiding real gains AND real\n // regressions — pass/fail axes on ANY encoding ({0,1} and the 0-100 one\n // `detectScale` exists for), and low-cardinality axes even below half ties.\n // Orthogonal to `pairedDeltaTest`'s own small-sample switch: that picks the\n // TEST (bootstrap CI at n ≥ 20, exact sign test below), this picks the\n // ESTIMATOR the test is applied to. Both are needed — an exact sign test on\n // a tie-pinned median is still blind.\n const bootstrapStatistic = opts.statistic ?? DECISION_PAIRED_DELTA_STATISTIC\n // Both burdens of proof route through the ONE shared rule\n // (`decidePairedPromotion`), so a pass/fail axis is judged on Tango's score\n // interval — the only paired-binary construction valid at the nonzero\n // margins `gainThreshold` / `floorTolerance` create — and a zero-width\n // interval cannot buy a verdict in either direction.\n const improvement = decidePairedPromotion(before, after, {\n confidence,\n resamples,\n statistic: bootstrapStatistic,\n seed,\n threshold: gainThreshold,\n minPairs: opts.minProductiveRuns,\n binaryScale,\n })\n const regression = decidePairedPromotion(after, before, {\n confidence,\n resamples,\n statistic: bootstrapStatistic,\n seed,\n threshold: floorTolerance,\n minPairs: opts.minProductiveRuns,\n binaryScale,\n })\n const bootstrap =\n improvement.bootstrap ??\n pairedBootstrap(before, after, {\n confidence,\n resamples,\n statistic: bootstrapStatistic,\n seed,\n })\n // A floor breach fires on EITHER burden of proof, because they cover\n // different failures and the floor is the anti-Goodhart guard:\n // - `improvement.low < -floorTolerance` — the CREDIBLE WORST CASE exceeds\n // the tolerance. This is the contract `AxisEvidence.floorTolerance` and\n // `paretoPolicy`'s own reason string state, and it is the conservative\n // posture a safety axis needs: block unless the data can rule the\n // breach out, rather than waiting for the breach to be proven. Read off\n // the DECIDING interval, so a pass/fail axis is not screened by a\n // bootstrap that is pinned wherever ties dominate.\n // - `regression.promote` — a PROVEN drop past the tolerance. Adds the\n // small-sample path, where the decision is an exact sign test because\n // the bootstrap interval is descriptive only.\n // A tied binary axis still has uncertainty about unseen discordant pairs.\n // Its diagnostic bootstrap collapses to zero, so only the deciding score\n // interval can establish that a regression stays within the declared floor.\n const floorBreached = improvement.low < -floorTolerance || regression.promote\n // Floor check precedes the gain check: a credible regression must never be\n // masked as \"improved\". With the defaults (gainThreshold 0, positive floor)\n // the regions are disjoint and order is moot, but a consumer who sets a\n // negative gainThreshold (\"accept small dips\") could otherwise have a real\n // floor breach classified as a gain — anti-Goodhart wins the tie.\n const verdict: AxisVerdict = !improvement.sufficient\n ? 'few_runs'\n : improvement.indeterminate\n ? 'indeterminate'\n : floorBreached\n ? 'regressed'\n : improvement.promote\n ? 'improved'\n : 'flat'\n axes.push({\n name: obj.name,\n source: obj.source,\n direction: obj.direction,\n bootstrap,\n bootstrapStatistic,\n ci: { low: improvement.low, high: improvement.high },\n decisionStatistic: improvement.statistic,\n mcnemar: improvement.mcnemar,\n indeterminate: improvement.indeterminate,\n n,\n minimumRequired: improvement.minimumPairs,\n decisionMethod: improvement.method,\n gainThreshold,\n floorTolerance,\n verdict,\n })\n }\n const ns = axes.map((a) => a.n).filter((n) => n > 0)\n const minN = ns.length > 0 ? Math.min(...ns) : 0\n return { axes, minN, cost: { candidate: ctx.cost.candidate, baseline: ctx.cost.baseline } }\n}\n\n/**\n * Require a supported gain and every configured regression floor to clear.\n * A failed floor holds the candidate, including when uncertainty permits a loss.\n * Missing or indeterminate evidence requires more work; no gain holds release.\n */\nexport const paretoPolicy: PromotionPolicy = (ev) => {\n const contributingGates = ev.axes.map((ax) => ({\n name: `objective:${ax.name}`,\n status:\n ax.verdict === 'regressed'\n ? ('fail' as const)\n : ax.verdict === 'few_runs' || ax.verdict === 'indeterminate'\n ? ('not_evaluated' as const)\n : ('pass' as const),\n detail: {\n direction: ax.direction,\n source: ax.source,\n verdict: ax.verdict,\n n: ax.n,\n deltaMedian: ax.bootstrap.median,\n ciLow: ax.ci.low,\n ciHigh: ax.ci.high,\n decisionStatistic: ax.decisionStatistic,\n decisionMethod: ax.decisionMethod,\n mcnemar: ax.mcnemar,\n indeterminate: ax.indeterminate,\n bootstrapCiLow: ax.bootstrap.low,\n bootstrapCiHigh: ax.bootstrap.high,\n confidence: ax.bootstrap.confidence,\n gainThreshold: ax.gainThreshold,\n floorTolerance: ax.floorTolerance,\n },\n }))\n\n const regressed = ev.axes.filter((a) => a.verdict === 'regressed')\n const insufficient = ev.axes.filter(\n (a) => a.verdict === 'few_runs' || a.verdict === 'indeterminate',\n )\n const improved = ev.axes.filter((a) => a.verdict === 'improved')\n\n let decision: GateDecision\n const reasons: string[] = []\n if (regressed.length > 0) {\n // A gain on another axis cannot excuse an unresolved regression floor.\n decision = 'hold'\n for (const a of regressed) {\n reasons.push(\n `objective '${a.name}' did not clear its regression floor -${a.floorTolerance}: good-direction CI [${a.ci.low.toFixed(3)}, ${a.ci.high.toFixed(3)}] (n=${a.n})`,\n )\n }\n } else if (insufficient.length > 0) {\n // An unresolved axis cannot establish either a gain or a safe floor.\n decision = 'need_more_work'\n for (const a of insufficient) {\n reasons.push(\n a.verdict === 'few_runs'\n ? `objective '${a.name}' has only n=${a.n} paired runs — insufficient evidence to claim significance`\n : `objective '${a.name}' has an indeterminate deciding CI [${a.ci.low}, ${a.ci.high}] — insufficient evidence to clear its regression floor (n=${a.n})`,\n )\n }\n } else if (improved.length > 0) {\n decision = 'ship'\n reasons.push(\n `Supported objective gain: ${improved\n .map(\n (a) =>\n `'${a.name}' +${a.ci.low > 0 ? a.ci.low.toFixed(3) : a.bootstrap.mean.toFixed(3)} (CI.low ${a.ci.low.toFixed(3)})`,\n )\n .join(', ')}; every regression floor cleared`,\n )\n } else {\n // Every floor cleared, but no objective demonstrated a significant gain.\n decision = 'hold'\n reasons.push(\n 'no Pareto improvement: no objective shows a significant gain; every regression floor cleared',\n )\n }\n\n // `delta` surfaces the composite axis if present, else the first axis — a\n // single convenience scalar; the vector lives in `contributingGates`.\n const composite = ev.axes.find((a) => a.source.kind === 'composite') ?? ev.axes[0]\n return { decision, reasons, contributingGates, delta: composite?.bootstrap.median }\n}\n\nexport interface ParetoSignificanceGateOptions extends BuildEvidenceVectorOptions {\n /** The objective vector. Every axis is both a gain source and a safety floor. */\n objectives: PromotionObjective[]\n /** Strategy applied to the evidence vector. Default `paretoPolicy`. Override\n * to run a stricter/looser strategy over the SAME bus (competing policies). */\n policy?: PromotionPolicy\n /** Override the gate name in reports. */\n name?: string\n}\n\n/**\n * Wrap the bus + a policy as a `Gate`. Plugs into the existing\n * `runImprovementLoop({ gate })` slot and composes via `composeGate`; default\n * loop behavior is unchanged because consumers opt in by passing this gate.\n */\nexport function paretoSignificanceGate<TArtifact = unknown, TScenario extends Scenario = Scenario>(\n options: ParetoSignificanceGateOptions,\n): Gate<TArtifact, TScenario> {\n if (options.objectives.length === 0) {\n throw new Error('paretoSignificanceGate: at least 1 objective required')\n }\n const policy = options.policy ?? paretoPolicy\n return {\n name: options.name ?? 'paretoSignificanceGate',\n async decide(ctx: GateContext<TArtifact, TScenario>): Promise<GateResult> {\n const ev = buildEvidenceVector(ctx, options.objectives, options)\n return policy(ev)\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkIA,SAAgB,oBACd,KACA,YACA,OAAmC,CAAC,GACpB;CAChB,IAAI,WAAW,WAAW,GACxB,MAAM,IAAI,MAAM,oDAAoD;CAEtE,MAAM,aAAa,KAAK,cAAc;CACtC,MAAM,YAAY,KAAK,aAAa;CACpC,MAAM,OAAO,KAAK,QAAQ;CAC1B,MAAM,WAAW,IAAI,uBAAuB,IAAI;CAChD,MAAM,cAAc,IAAI,IAAI,IAAI,UAAU,KAAK,MAAM,EAAE,EAAE,CAAC;CAE1D,MAAM,OAAuB,CAAC;CAC9B,KAAK,MAAM,OAAO,YAAY;EAC5B,IAAI;EACJ,IAAI,IAAI,OAAO,SAAS,aACtB,UAAU,MAAM,EAAE;OACb;GACL,MAAM,MAAM,IAAI,OAAO;GACvB,UAAU,MAAM,EAAE,WAAW;EAC/B;EACA,MAAM,SAAS,YAAY,IAAI,aAAa,UAAU,aAAa,MAAM;EAIzE,MAAM,SAAS,IAAI,cAAc,aAAa,OAAO,SAAS,OAAO;EACrE,MAAM,QAAQ,IAAI,cAAc,aAAa,OAAO,QAAQ,OAAO;EACnE,MAAM,IAAI,OAAO,OAAO;EACxB,MAAM,cAAc,IAAI;EACxB,MAAM,iBACJ,IAAI,kBAAkB,OAAQ,eAAe,YAAY,CAAC,GAAG,OAAO,QAAQ,GAAG,OAAO,KAAK,CAAC;EAC9F,MAAM,gBAAgB,IAAI,iBAAiB;EAW3C,MAAM,qBAAqB,KAAK,aAAA;EAMhC,MAAM,cAAc,sBAAsB,QAAQ,OAAO;GACvD;GACA;GACA,WAAW;GACX;GACA,WAAW;GACX,UAAU,KAAK;GACf;EAC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N,8FACF;CACF;CAIA,MAAM,YAAY,GAAG,KAAK,MAAM,MAAM,EAAE,OAAO,SAAS,WAAW,KAAK,GAAG,KAAK;CAChF,OAAO;EAAE;EAAU;EAAS;EAAmB,OAAO,WAAW,UAAU;CAAO;AACpF;;;;;;AAiBA,SAAgB,uBACd,SAC4B;CAC5B,IAAI,QAAQ,WAAW,WAAW,GAChC,MAAM,IAAI,MAAM,uDAAuD;CAEzE,MAAM,SAAS,QAAQ,UAAU;CACjC,OAAO;EACL,MAAM,QAAQ,QAAQ;EACtB,MAAM,OAAO,KAA6D;GACxE,MAAM,KAAK,oBAAoB,KAAK,QAAQ,YAAY,OAAO;GAC/D,OAAO,OAAO,EAAE;EAClB;CACF;AACF"}
1
+ {"version":3,"file":"promotion-policy-f79oklG_.js","names":[],"sources":["../src/campaign/gates/promotion-policy.ts"],"sourcesContent":["/**\n * Build paired evidence for each objective and apply a promotion policy.\n * The default policy requires at least one gain and every regression floor to\n * clear. A floor can fail because a larger loss remains plausible; that does\n * not demonstrate an observed regression. Missing evidence stays unresolved.\n * Confidence intervals apply to each axis, without a multiplicity adjustment.\n *\n * Cost and latency remain aggregate constraints because GateContext does not\n * supply paired observations for them. Compose a budget gate when needed.\n */\n\nimport {\n decidePairedPromotion,\n type PairedDecisionMethod,\n type PairedDecisionStatistic,\n type PairedMcNemarEvidence,\n} from '../../paired-promotion-decision'\nimport type { Direction } from '../../pareto'\nimport {\n DECISION_PAIRED_DELTA_STATISTIC,\n type PairedBootstrapResult,\n pairedBootstrap,\n} from '../../statistics'\nimport type { Gate, GateContext, GateDecision, GateResult, JudgeScore, Scenario } from '../types'\nimport { detectScale, pairHoldout } from './statistical-heldout'\n\n/** Where an objective's per-cell scalar comes from. `composite` reads the\n * judge's composite; `dimension` reads a named per-dimension score. */\nexport type ObjectiveSource = { kind: 'composite' } | { kind: 'dimension'; dimension: string }\n\nexport interface PromotionObjective {\n /** Stable label used in reports + `contributingGates`. */\n name: string\n source: ObjectiveSource\n /** 'maximize' (quality dims) or 'minimize' (error/risk/length dims). Orients\n * the paired delta so a positive bootstrap always means \"candidate better\". */\n direction: Direction\n /** Declared binary support {0, binaryScale}, including zero-only observations.\n * Must be finite and positive; paired cell scores must be 0 or this scale.\n * Uses the risk-difference mean and rejects the 'median' statistic. */\n binaryScale?: number\n /** The good-direction paired-delta CI lower bound must EXCEED this to count\n * as a significant gain on this axis. Interpreted in the judge's native\n * scale. Default 0 (⇒ \"confidently better\"). */\n gainThreshold?: number\n /** A floor breach (regression) is declared when the good-direction CI lower\n * bound is below −floorTolerance, or when the exact small-sample test proves\n * a drop past it. Defaults to 0.05 times the declared binary scale, or\n * auto-scales off observed magnitudes (0.05 on [0,1], 5 on 0-100). */\n floorTolerance?: number\n}\n\n/** Per-axis verdict from the shared paired decision rule.\n * 'regressed' includes uncertainty that prevents clearing the regression floor. */\nexport type AxisVerdict = 'improved' | 'regressed' | 'flat' | 'few_runs' | 'indeterminate'\n\nexport interface AxisEvidence {\n name: string\n source: ObjectiveSource\n direction: Direction\n /** Paired bootstrap on the GOOD-DIRECTION delta (oriented by `direction`):\n * a positive value means the candidate is better on this axis.\n *\n * DIAGNOSTIC on a pass/fail axis: there the verdict is decided on Tango's\n * score interval instead, because a percentile bootstrap over a three-atom\n * delta lattice is not a valid interval at the nonzero margin `floorTolerance`\n * and `gainThreshold` create. `ci` carries the interval that decided. */\n bootstrap: PairedBootstrapResult\n /** Which paired statistic `bootstrap.low`/`.high` bracket. `'mean'` unless the\n * caller asked for the median — on a pass/fail axis the median and its whole\n * CI are pinned at 0 by tie domination and can see neither a gain nor a\n * regression. `bootstrap.median` still carries the median point estimate. */\n bootstrapStatistic: 'median' | 'mean'\n /** The interval the axis verdict was actually decided on, good-direction and\n * in the axis's native units. */\n ci: { low: number; high: number }\n /** Which estimator produced `ci`. */\n decisionStatistic: PairedDecisionStatistic\n /** McNemar's exact evidence on a pass/fail axis; null otherwise. */\n mcnemar: PairedMcNemarEvidence | null\n /** `ci` has zero width or non-finite bounds. It cannot establish a gain or\n * clear a regression floor, regardless of the point estimate. */\n indeterminate: boolean\n /** Paired observations contributing to this axis. */\n n: number\n minimumRequired: number\n decisionMethod: PairedDecisionMethod\n gainThreshold: number\n floorTolerance: number\n verdict: AxisVerdict\n}\n\nexport interface EvidenceVector {\n /** One entry per objective — NOTHING averaged across axes. */\n axes: AxisEvidence[]\n /** Smallest paired n across axes that produced observations — the binding\n * evidence-sufficiency constraint. 0 when no axis produced observations. */\n minN: number\n /** Aggregate per-side cost from the gate context (a constraint input, not a\n * CI axis — see the module header). */\n cost: { candidate: number; baseline: number }\n}\n\n/** A promotion strategy: a pure function from the evidence vector to a verdict.\n * Many policies can run over the same `EvidenceVector` and disagree — that's\n * the point (competing strategies, shared evidence). */\nexport type PromotionPolicy = (ev: EvidenceVector) => GateResult\n\nexport interface BuildEvidenceVectorOptions {\n /** Minimum paired observations before an axis can claim significance; below\n * it the axis is `few_runs`. The exact small-sample test may require more\n * observations at the selected confidence. */\n minProductiveRuns?: number\n /** Confidence level for every axis bootstrap. Default 0.95. */\n confidence?: number\n /** Bootstrap resamples. Default 2000. */\n resamples?: number\n /** Fixed bootstrap seed for a deterministic, reproducible verdict. Default 1337. */\n seed?: number\n /** Paired statistic every axis CI is computed on. Default `'mean'` — see\n * {@link DECISION_PAIRED_DELTA_STATISTIC} for why the median is not. */\n statistic?: 'mean' | 'median'\n}\n\n/**\n * The Evidence Bus. For each objective, pair candidate vs baseline by full\n * cellId and bootstrap a CI on the good-direction paired delta. Reuses the\n * exact `pairHoldout` + `pairedBootstrap` machinery the held-out gate uses, so\n * a single source of truth governs pairing granularity + scale handling.\n */\nexport function buildEvidenceVector<TArtifact, TScenario extends Scenario>(\n ctx: GateContext<TArtifact, TScenario>,\n objectives: PromotionObjective[],\n opts: BuildEvidenceVectorOptions = {},\n): EvidenceVector {\n if (objectives.length === 0) {\n throw new Error('buildEvidenceVector: at least 1 objective required')\n }\n const confidence = opts.confidence ?? 0.95\n const resamples = opts.resamples ?? 2000\n const seed = opts.seed ?? 1337\n const baseline = ctx.baselineJudgeScores ?? ctx.judgeScores\n const scenarioIds = new Set(ctx.scenarios.map((s) => s.id))\n\n const axes: AxisEvidence[] = []\n for (const obj of objectives) {\n let select: (s: JudgeScore) => number | undefined\n if (obj.source.kind === 'composite') {\n select = (s) => s.composite\n } else {\n const dim = obj.source.dimension\n select = (s) => s.dimensions[dim]\n }\n const paired = pairHoldout(ctx.judgeScores, baseline, scenarioIds, select)\n // Orient to the good direction: maximize ⇒ bootstrap (candidate − baseline);\n // minimize ⇒ bootstrap (baseline − candidate) by swapping args, so a\n // positive bootstrap always reads as \"candidate better on this axis\".\n const before = obj.direction === 'maximize' ? paired.before : paired.after\n const after = obj.direction === 'maximize' ? paired.after : paired.before\n const n = paired.before.length\n const binaryScale = obj.binaryScale\n const floorTolerance =\n obj.floorTolerance ?? 0.05 * (binaryScale ?? detectScale([...paired.before, ...paired.after]))\n const gainThreshold = obj.gainThreshold ?? 0\n // Axes are decided on the MEAN paired delta — which for a pass/fail axis is\n // exactly the change in success rate. The median is structurally blind on\n // the shapes eval data lands in: with most pairs tied its bootstrap CI\n // collapses to [0,0] and the axis reads 'flat', hiding real gains AND real\n // regressions — pass/fail axes on ANY encoding ({0,1} and the 0-100 one\n // `detectScale` exists for), and low-cardinality axes even below half ties.\n // Orthogonal to `pairedDeltaTest`'s own small-sample switch: that picks the\n // TEST (bootstrap CI at n ≥ 20, exact sign test below), this picks the\n // ESTIMATOR the test is applied to. Both are needed — an exact sign test on\n // a tie-pinned median is still blind.\n const bootstrapStatistic = opts.statistic ?? DECISION_PAIRED_DELTA_STATISTIC\n // Both burdens of proof route through the ONE shared rule\n // (`decidePairedPromotion`), so a pass/fail axis is judged on Tango's score\n // interval — the only paired-binary construction valid at the nonzero\n // margins `gainThreshold` / `floorTolerance` create — and a zero-width\n // interval cannot buy a verdict in either direction.\n const improvement = decidePairedPromotion(before, after, {\n confidence,\n resamples,\n statistic: bootstrapStatistic,\n seed,\n threshold: gainThreshold,\n minPairs: opts.minProductiveRuns,\n binaryScale,\n })\n const regression = decidePairedPromotion(after, before, {\n confidence,\n resamples,\n statistic: bootstrapStatistic,\n seed,\n threshold: floorTolerance,\n minPairs: opts.minProductiveRuns,\n binaryScale,\n })\n const bootstrap =\n improvement.bootstrap ??\n pairedBootstrap(before, after, {\n confidence,\n resamples,\n statistic: bootstrapStatistic,\n seed,\n })\n // A floor breach fires on EITHER burden of proof, because they cover\n // different failures and the floor is the anti-Goodhart guard:\n // - `improvement.low < -floorTolerance` — the CREDIBLE WORST CASE exceeds\n // the tolerance. This is the contract `AxisEvidence.floorTolerance` and\n // `paretoPolicy`'s own reason string state, and it is the conservative\n // posture a safety axis needs: block unless the data can rule the\n // breach out, rather than waiting for the breach to be proven. Read off\n // the DECIDING interval, so a pass/fail axis is not screened by a\n // bootstrap that is pinned wherever ties dominate.\n // - `regression.promote` — a PROVEN drop past the tolerance. Adds the\n // small-sample path, where the decision is an exact sign test because\n // the bootstrap interval is descriptive only.\n // A tied binary axis still has uncertainty about unseen discordant pairs.\n // Its diagnostic bootstrap collapses to zero, so only the deciding score\n // interval can establish that a regression stays within the declared floor.\n const floorBreached = improvement.low < -floorTolerance || regression.promote\n // Floor check precedes the gain check: a credible regression must never be\n // masked as \"improved\". With the defaults (gainThreshold 0, positive floor)\n // the regions are disjoint and order is moot, but a consumer who sets a\n // negative gainThreshold (\"accept small dips\") could otherwise have a real\n // floor breach classified as a gain — anti-Goodhart wins the tie.\n const verdict: AxisVerdict = !improvement.sufficient\n ? 'few_runs'\n : improvement.indeterminate\n ? 'indeterminate'\n : floorBreached\n ? 'regressed'\n : improvement.promote\n ? 'improved'\n : 'flat'\n axes.push({\n name: obj.name,\n source: obj.source,\n direction: obj.direction,\n bootstrap,\n bootstrapStatistic,\n ci: { low: improvement.low, high: improvement.high },\n decisionStatistic: improvement.statistic,\n mcnemar: improvement.mcnemar,\n indeterminate: improvement.indeterminate,\n n,\n minimumRequired: improvement.minimumPairs,\n decisionMethod: improvement.method,\n gainThreshold,\n floorTolerance,\n verdict,\n })\n }\n const ns = axes.map((a) => a.n).filter((n) => n > 0)\n const minN = ns.length > 0 ? Math.min(...ns) : 0\n return { axes, minN, cost: { candidate: ctx.cost.candidate, baseline: ctx.cost.baseline } }\n}\n\n/**\n * Require a supported gain and every configured regression floor to clear.\n * A failed floor holds the candidate, including when uncertainty permits a loss.\n * Missing or indeterminate evidence requires more work; no gain holds release.\n */\nexport const paretoPolicy: PromotionPolicy = (ev) => {\n const contributingGates = ev.axes.map((ax) => ({\n name: `objective:${ax.name}`,\n status:\n ax.verdict === 'regressed'\n ? ('fail' as const)\n : ax.verdict === 'few_runs' || ax.verdict === 'indeterminate'\n ? ('not_evaluated' as const)\n : ('pass' as const),\n detail: {\n direction: ax.direction,\n source: ax.source,\n verdict: ax.verdict,\n n: ax.n,\n deltaMedian: ax.bootstrap.median,\n ciLow: ax.ci.low,\n ciHigh: ax.ci.high,\n decisionStatistic: ax.decisionStatistic,\n decisionMethod: ax.decisionMethod,\n mcnemar: ax.mcnemar,\n indeterminate: ax.indeterminate,\n bootstrapCiLow: ax.bootstrap.low,\n bootstrapCiHigh: ax.bootstrap.high,\n confidence: ax.bootstrap.confidence,\n gainThreshold: ax.gainThreshold,\n floorTolerance: ax.floorTolerance,\n },\n }))\n\n const regressed = ev.axes.filter((a) => a.verdict === 'regressed')\n const insufficient = ev.axes.filter(\n (a) => a.verdict === 'few_runs' || a.verdict === 'indeterminate',\n )\n const improved = ev.axes.filter((a) => a.verdict === 'improved')\n\n let decision: GateDecision\n const reasons: string[] = []\n if (regressed.length > 0) {\n // A gain on another axis cannot excuse an unresolved regression floor.\n decision = 'hold'\n for (const a of regressed) {\n reasons.push(\n `objective '${a.name}' did not clear its regression floor -${a.floorTolerance}: good-direction CI [${a.ci.low.toFixed(3)}, ${a.ci.high.toFixed(3)}] (n=${a.n})`,\n )\n }\n } else if (insufficient.length > 0) {\n // An unresolved axis cannot establish either a gain or a safe floor.\n decision = 'need_more_work'\n for (const a of insufficient) {\n reasons.push(\n a.verdict === 'few_runs'\n ? `objective '${a.name}' has only n=${a.n} paired runs — insufficient evidence to claim significance`\n : `objective '${a.name}' has an indeterminate deciding CI [${a.ci.low}, ${a.ci.high}] — insufficient evidence to clear its regression floor (n=${a.n})`,\n )\n }\n } else if (improved.length > 0) {\n decision = 'ship'\n reasons.push(\n `Supported objective gain: ${improved\n .map(\n (a) =>\n `'${a.name}' +${a.ci.low > 0 ? a.ci.low.toFixed(3) : a.bootstrap.mean.toFixed(3)} (CI.low ${a.ci.low.toFixed(3)})`,\n )\n .join(', ')}; every regression floor cleared`,\n )\n } else {\n // Every floor cleared, but no objective demonstrated a significant gain.\n decision = 'hold'\n reasons.push(\n 'no Pareto improvement: no objective shows a significant gain; every regression floor cleared',\n )\n }\n\n // `delta` surfaces the composite axis if present, else the first axis — a\n // single convenience scalar; the vector lives in `contributingGates`.\n const composite = ev.axes.find((a) => a.source.kind === 'composite') ?? ev.axes[0]\n return { decision, reasons, contributingGates, delta: composite?.bootstrap.median }\n}\n\nexport interface ParetoSignificanceGateOptions extends BuildEvidenceVectorOptions {\n /** The objective vector. Every axis is both a gain source and a safety floor. */\n objectives: PromotionObjective[]\n /** Strategy applied to the evidence vector. Default `paretoPolicy`. Override\n * to run a stricter/looser strategy over the SAME bus (competing policies). */\n policy?: PromotionPolicy\n /** Override the gate name in reports. */\n name?: string\n}\n\n/**\n * Wrap the bus + a policy as a `Gate`. Plugs into the existing\n * `runImprovementLoop({ gate })` slot and composes via `composeGate`; default\n * loop behavior is unchanged because consumers opt in by passing this gate.\n */\nexport function paretoSignificanceGate<TArtifact = unknown, TScenario extends Scenario = Scenario>(\n options: ParetoSignificanceGateOptions,\n): Gate<TArtifact, TScenario> {\n if (options.objectives.length === 0) {\n throw new Error('paretoSignificanceGate: at least 1 objective required')\n }\n const policy = options.policy ?? paretoPolicy\n return {\n name: options.name ?? 'paretoSignificanceGate',\n async decide(ctx: GateContext<TArtifact, TScenario>): Promise<GateResult> {\n const ev = buildEvidenceVector(ctx, options.objectives, options)\n return policy(ev)\n },\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkIA,SAAgB,oBACd,KACA,YACA,OAAmC,CAAC,GACpB;CAChB,IAAI,WAAW,WAAW,GACxB,MAAM,IAAI,MAAM,oDAAoD;CAEtE,MAAM,aAAa,KAAK,cAAc;CACtC,MAAM,YAAY,KAAK,aAAa;CACpC,MAAM,OAAO,KAAK,QAAQ;CAC1B,MAAM,WAAW,IAAI,uBAAuB,IAAI;CAChD,MAAM,cAAc,IAAI,IAAI,IAAI,UAAU,KAAK,MAAM,EAAE,EAAE,CAAC;CAE1D,MAAM,OAAuB,CAAC;CAC9B,KAAK,MAAM,OAAO,YAAY;EAC5B,IAAI;EACJ,IAAI,IAAI,OAAO,SAAS,aACtB,UAAU,MAAM,EAAE;OACb;GACL,MAAM,MAAM,IAAI,OAAO;GACvB,UAAU,MAAM,EAAE,WAAW;EAC/B;EACA,MAAM,SAAS,YAAY,IAAI,aAAa,UAAU,aAAa,MAAM;EAIzE,MAAM,SAAS,IAAI,cAAc,aAAa,OAAO,SAAS,OAAO;EACrE,MAAM,QAAQ,IAAI,cAAc,aAAa,OAAO,QAAQ,OAAO;EACnE,MAAM,IAAI,OAAO,OAAO;EACxB,MAAM,cAAc,IAAI;EACxB,MAAM,iBACJ,IAAI,kBAAkB,OAAQ,eAAe,YAAY,CAAC,GAAG,OAAO,QAAQ,GAAG,OAAO,KAAK,CAAC;EAC9F,MAAM,gBAAgB,IAAI,iBAAiB;EAW3C,MAAM,qBAAqB,KAAK,aAAA;EAMhC,MAAM,cAAc,sBAAsB,QAAQ,OAAO;GACvD;GACA;GACA,WAAW;GACX;GACA,WAAW;GACX,UAAU,KAAK;GACf;EACF,CAAC;EACD,MAAM,aAAa,sBAAsB,OAAO,QAAQ;GACtD;GACA;GACA,WAAW;GACX;GACA,WAAW;GACX,UAAU,KAAK;GACf;EACF,CAAC;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AAU;EAAS;EAAmB,OAAO,WAAW,UAAU;CAAO;AACpF;;;;;;AAiBA,SAAgB,uBACd,SAC4B;CAC5B,IAAI,QAAQ,WAAW,WAAW,GAChC,MAAM,IAAI,MAAM,uDAAuD;CAEzE,MAAM,SAAS,QAAQ,UAAU;CACjC,OAAO;EACL,MAAM,QAAQ,QAAQ;EACtB,MAAM,OAAO,KAA6D;GACxE,MAAM,KAAK,oBAAoB,KAAK,QAAQ,YAAY,OAAO;GAC/D,OAAO,OAAO,EAAE;EAClB;CACF;AACF"}
@@ -1,4 +1,4 @@
1
- import { S as ProposalFindingSchema } from "./external-optimizer-subprocess-U616hV_l.js";
1
+ import { S as ProposalFindingSchema } from "./external-optimizer-subprocess-wzMaA0oN.js";
2
2
  // src/analyst/proposal-findings.ts
3
3
  /** True when a finding names a source candidate generation may learn from. */
4
4
  function isProposalFinding(finding) {
@@ -22,4 +22,4 @@ function findingLabel(finding, index) {
22
22
  }
23
23
  export { assertProposalFindings as t };
24
24
 
25
- //# sourceMappingURL=proposal-findings-WFQrxnfe.js.map
25
+ //# sourceMappingURL=proposal-findings-duV5flPv.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"proposal-findings-WFQrxnfe.js","names":[],"sources":["../src/analyst/proposal-findings.ts"],"sourcesContent":["import { ProposalFindingSchema } from './finding-scope'\nimport type { ProposalFinding } from './types'\n\n/** True when a finding names a source candidate generation may learn from. */\nfunction isProposalFinding(finding: unknown): finding is ProposalFinding {\n return ProposalFindingSchema.safeParse(finding).success\n}\n\n/**\n * Reject findings whose source has not been explicitly admitted for candidate\n * generation. Search feedback and observed production behavior are allowed;\n * final evaluation data has no allowed origin.\n */\nexport function assertProposalFindings(\n findings: unknown,\n context = 'proposal findings',\n): ReadonlyArray<ProposalFinding> {\n if (!Array.isArray(findings)) {\n throw new TypeError(`${context}: expected an array`)\n }\n const rejected = findings.flatMap((finding, index) =>\n isProposalFinding(finding) ? [] : [findingLabel(finding, index)],\n )\n if (rejected.length > 0) {\n throw new Error(\n `${context}: every finding must match AnalystFinding and declare ` +\n `proposal_origin as search or production. ` +\n `Rejected findings: [${rejected.join(', ')}].`,\n )\n }\n return findings as ReadonlyArray<ProposalFinding>\n}\n\nfunction findingLabel(finding: unknown, index: number): string {\n if (typeof finding !== 'object' || finding === null) return `index ${index}`\n const id = (finding as { finding_id?: unknown }).finding_id\n return typeof id === 'string' && id.length > 0 ? id : `index ${index}`\n}\n"],"mappings":";;;AAIA,SAAS,kBAAkB,SAA8C;CACvE,OAAO,sBAAsB,UAAU,OAAO,CAAC,CAAC;AAClD;;;;;;AAOA,SAAgB,uBACd,UACA,UAAU,qBACsB;CAChC,IAAI,CAAC,MAAM,QAAQ,QAAQ,GACzB,MAAM,IAAI,UAAU,GAAG,QAAQ,oBAAoB;CAErD,MAAM,WAAW,SAAS,SAAS,SAAS,UAC1C,kBAAkB,OAAO,IAAI,CAAC,IAAI,CAAC,aAAa,SAAS,KAAK,CAAC,CACjE;CACA,IAAI,SAAS,SAAS,GACpB,MAAM,IAAI,MACR,GAAG,QAAQ,qHAEc,SAAS,KAAK,IAAI,EAAE,GAC/C;CAEF,OAAO;AACT;AAEA,SAAS,aAAa,SAAkB,OAAuB;CAC7D,IAAI,OAAO,YAAY,YAAY,YAAY,MAAM,OAAO,SAAS;CACrE,MAAM,KAAM,QAAqC;CACjD,OAAO,OAAO,OAAO,YAAY,GAAG,SAAS,IAAI,KAAK,SAAS;AACjE"}
1
+ {"version":3,"file":"proposal-findings-duV5flPv.js","names":[],"sources":["../src/analyst/proposal-findings.ts"],"sourcesContent":["import { ProposalFindingSchema } from './finding-scope'\nimport type { ProposalFinding } from './types'\n\n/** True when a finding names a source candidate generation may learn from. */\nfunction isProposalFinding(finding: unknown): finding is ProposalFinding {\n return ProposalFindingSchema.safeParse(finding).success\n}\n\n/**\n * Reject findings whose source has not been explicitly admitted for candidate\n * generation. Search feedback and observed production behavior are allowed;\n * final evaluation data has no allowed origin.\n */\nexport function assertProposalFindings(\n findings: unknown,\n context = 'proposal findings',\n): ReadonlyArray<ProposalFinding> {\n if (!Array.isArray(findings)) {\n throw new TypeError(`${context}: expected an array`)\n }\n const rejected = findings.flatMap((finding, index) =>\n isProposalFinding(finding) ? [] : [findingLabel(finding, index)],\n )\n if (rejected.length > 0) {\n throw new Error(\n `${context}: every finding must match AnalystFinding and declare ` +\n `proposal_origin as search or production. ` +\n `Rejected findings: [${rejected.join(', ')}].`,\n )\n }\n return findings as ReadonlyArray<ProposalFinding>\n}\n\nfunction findingLabel(finding: unknown, index: number): string {\n if (typeof finding !== 'object' || finding === null) return `index ${index}`\n const id = (finding as { finding_id?: unknown }).finding_id\n return typeof id === 'string' && id.length > 0 ? id : `index ${index}`\n}\n"],"mappings":";;;AAIA,SAAS,kBAAkB,SAA8C;CACvE,OAAO,sBAAsB,UAAU,OAAO,CAAC,CAAC;AAClD;;;;;;AAOA,SAAgB,uBACd,UACA,UAAU,qBACsB;CAChC,IAAI,CAAC,MAAM,QAAQ,QAAQ,GACzB,MAAM,IAAI,UAAU,GAAG,QAAQ,oBAAoB;CAErD,MAAM,WAAW,SAAS,SAAS,SAAS,UAC1C,kBAAkB,OAAO,IAAI,CAAC,IAAI,CAAC,aAAa,SAAS,KAAK,CAAC,CACjE;CACA,IAAI,SAAS,SAAS,GACpB,MAAM,IAAI,MACR,GAAG,QAAQ,qHAEc,SAAS,KAAK,IAAI,EAAE,GAC/C;CAEF,OAAO;AACT;AAEA,SAAS,aAAa,SAAkB,OAAuB;CAC7D,IAAI,OAAO,YAAY,YAAY,YAAY,MAAM,OAAO,SAAS;CACrE,MAAM,KAAM,QAAqC;CACjD,OAAO,OAAO,OAAO,YAAY,GAAG,SAAS,IAAI,KAAK,SAAS;AACjE"}
@@ -1,4 +1,4 @@
1
- import { a as redact } from "./redact-D6APJS1d.js";
1
+ import { o as redact } from "./redact-zp_ILC4l.js";
2
2
  import { promises } from "node:fs";
3
3
  import * as path from "node:path";
4
4
  // src/trace/raw-provider-sink.ts
@@ -160,4 +160,4 @@ function providerFromBaseUrl(baseUrl) {
160
160
  }
161
161
  export { providerFromBaseUrl as a, defaultProviderRedactor as i, InMemoryRawProviderSink as n, NoopRawProviderSink as r, FileSystemRawProviderSink as t };
162
162
 
163
- //# sourceMappingURL=raw-provider-sink-DDLkP_eF.js.map
163
+ //# sourceMappingURL=raw-provider-sink-RbaEv2vB.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"raw-provider-sink-DDLkP_eF.js","names":["fs"],"sources":["../src/trace/raw-provider-sink.ts"],"sourcesContent":["/**\n * RawProviderSink — first-class persistence for the actual HTTP-level\n * request/response bodies of every LLM provider call.\n *\n * Why this is a separate sink from the structured `LlmSpan`:\n *\n * - `LlmSpan` records the *intent* — model name, messages, output text,\n * usage. It's what dashboards read; it's NOT enough for forensics.\n * - When a downstream consumer reports \"the verifier used the wrong route\"\n * or \"tokens look right but reasoning was missing,\" the only way to\n * answer is the raw HTTP body. Span fields can lie (a proxy can echo\n * a different `model` value than what actually answered); the raw\n * response is ground truth.\n *\n * Default behaviour: opt-in. Pass `rawSink` to `LlmClientOptions` (or the\n * matrix runner / BuilderSession sets it up automatically) and every\n * request, response, and error is recorded — including retries, with the\n * attempt index attached so a flaky call's full event chain is recoverable.\n *\n * Redaction is enforced at sink time. The default redactor runs the redaction\n * core (`./redact`, default profile) over headers, bodies and the error\n * message: credential headers and fields are replaced by name, credential and\n * personal-data values by shape. Override via the sink constructor or the\n * per-call `redactor`. The `redactedFields` array on the persisted event lets\n * a reviewer see what was replaced without exposing the values.\n */\n\nimport { promises as fs } from 'node:fs'\nimport * as path from 'node:path'\nimport { redact } from './redact'\n\nexport type RawProviderDirection = 'request' | 'response' | 'error'\n\nexport interface RawProviderEvent {\n /** Stable id. Generated by the sink if omitted. */\n eventId: string\n /** Trace context populated by `LlmClient` when the call is wrapped in a span. */\n runId?: string\n spanId?: string\n /**\n * Logical provider name. Free-form so callers can use whatever id matches\n * their topology (`'openai'`, `'anthropic'`, `'tangle-router'`, …). When\n * omitted, derived from `baseUrl` in `LlmClientOptions`.\n */\n provider: string\n model: string\n /** Endpoint path, e.g. `'/v1/chat/completions'`. */\n endpoint: string\n /** Base URL used for the call (already-normalised — no trailing slash). */\n baseUrl: string\n /** 0-indexed retry attempt. The first attempt is 0; a retried call gets 1, 2, … */\n attemptIndex: number\n direction: RawProviderDirection\n /** Unix ms. */\n timestamp: number\n /** Wall-clock duration of the call leg. Set on `response` and `error` events; null on `request`. */\n durationMs?: number\n statusCode?: number\n requestHeaders?: Record<string, string>\n requestBody?: unknown\n responseHeaders?: Record<string, string>\n responseBody?: unknown\n /** Set on `direction: 'error'` events. */\n errorMessage?: string\n /** JSON Pointers of the fields the redactor replaced ('/requestHeaders/Authorization', '/requestBody/apiKey', …). */\n redactedFields: string[]\n}\n\nexport interface RawProviderSinkFilter {\n runId?: string\n spanId?: string\n direction?: RawProviderDirection\n attemptIndex?: number\n}\n\nexport interface RawProviderSink {\n record(event: RawProviderEvent): Promise<void>\n /** Optional listing — implementations that durably persist (file, db) should support this. */\n list?(filter?: RawProviderSinkFilter): Promise<RawProviderEvent[]>\n /** Optional teardown for backed implementations. */\n close?(): Promise<void>\n}\n\nexport type ProviderRedactor = (event: RawProviderEvent) => RawProviderEvent\n\n/**\n * The default redactor: the redaction core over the parts of an event that\n * carry provider traffic. Every replaced path is added to `redactedFields`.\n */\nexport function defaultProviderRedactor(event: RawProviderEvent): RawProviderEvent {\n const { requestHeaders, requestBody, responseHeaders, responseBody, errorMessage } = event\n const { value, report } = redact({\n requestHeaders,\n requestBody,\n responseHeaders,\n responseBody,\n errorMessage,\n })\n return {\n ...event,\n ...value,\n redactedFields: [\n ...(event.redactedFields ?? []),\n ...report.findings.map((finding) => finding.path),\n ],\n }\n}\n\n// ── In-memory ────────────────────────────────────────────────────────────\n\nexport interface InMemoryRawProviderSinkOptions {\n redactor?: ProviderRedactor\n}\n\nexport class InMemoryRawProviderSink implements RawProviderSink {\n private events: RawProviderEvent[] = []\n private redactor: ProviderRedactor\n\n constructor(opts: InMemoryRawProviderSinkOptions = {}) {\n this.redactor = opts.redactor ?? defaultProviderRedactor\n }\n\n async record(event: RawProviderEvent): Promise<void> {\n this.events.push(this.redactor({ ...event, redactedFields: event.redactedFields ?? [] }))\n }\n\n async list(filter: RawProviderSinkFilter = {}): Promise<RawProviderEvent[]> {\n return this.events.filter(\n (e) =>\n (filter.runId === undefined || e.runId === filter.runId) &&\n (filter.spanId === undefined || e.spanId === filter.spanId) &&\n (filter.direction === undefined || e.direction === filter.direction) &&\n (filter.attemptIndex === undefined || e.attemptIndex === filter.attemptIndex),\n )\n }\n\n size(): number {\n return this.events.length\n }\n}\n\nexport class NoopRawProviderSink implements RawProviderSink {\n async record(): Promise<void> {\n /* no-op */\n }\n /**\n * Returns an empty array. Implemented so `assertRunCaptured` does not\n * trip the `no_raw_sink` issue when a caller explicitly opts out of\n * capture by passing this sink — opt-out is a deliberate choice, not a\n * misconfiguration.\n */\n async list(): Promise<RawProviderEvent[]> {\n return []\n }\n}\n\n// ── Filesystem (NDJSON) ──────────────────────────────────────────────────\n\nexport interface FileSystemRawProviderSinkOptions {\n /** Directory the NDJSON file is written into. Created if missing. */\n dir: string\n /** File name; default `'raw-provider-events.ndjson'`. */\n fileName?: string\n /** Bytes after which the writer rolls over to a new file (default 32 MiB). */\n rollAtBytes?: number\n redactor?: ProviderRedactor\n}\n\nexport class FileSystemRawProviderSink implements RawProviderSink {\n private dir: string\n private fileName: string\n private rollAtBytes: number\n private redactor: ProviderRedactor\n private bytesWritten = 0\n private rollIndex = 0\n private initPromise: Promise<void> | null = null\n\n constructor(opts: FileSystemRawProviderSinkOptions) {\n this.dir = opts.dir\n this.fileName = opts.fileName ?? 'raw-provider-events.ndjson'\n this.rollAtBytes = opts.rollAtBytes ?? 32 * 1024 * 1024\n this.redactor = opts.redactor ?? defaultProviderRedactor\n }\n\n private async ensureInit(): Promise<void> {\n if (!this.initPromise) {\n this.initPromise = fs.mkdir(this.dir, { recursive: true }).then(() => undefined)\n }\n await this.initPromise\n }\n\n private currentPath(): string {\n if (this.rollIndex === 0) return path.join(this.dir, this.fileName)\n return path.join(this.dir, `${this.fileName}.${this.rollIndex}`)\n }\n\n async record(event: RawProviderEvent): Promise<void> {\n await this.ensureInit()\n const redacted = this.redactor({ ...event, redactedFields: event.redactedFields ?? [] })\n const line = `${JSON.stringify(redacted)}\\n`\n if (this.bytesWritten + line.length > this.rollAtBytes && this.bytesWritten > 0) {\n this.rollIndex += 1\n this.bytesWritten = 0\n }\n await fs.appendFile(this.currentPath(), line, 'utf8')\n this.bytesWritten += line.length\n }\n\n async list(filter: RawProviderSinkFilter = {}): Promise<RawProviderEvent[]> {\n await this.ensureInit()\n const out: RawProviderEvent[] = []\n for (let i = 0; i <= this.rollIndex; i++) {\n const file =\n i === 0 ? path.join(this.dir, this.fileName) : path.join(this.dir, `${this.fileName}.${i}`)\n let body: string\n try {\n body = await fs.readFile(file, 'utf8')\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') continue\n throw err\n }\n for (const line of body.split('\\n')) {\n if (!line) continue\n const event = JSON.parse(line) as RawProviderEvent\n if (filter.runId !== undefined && event.runId !== filter.runId) continue\n if (filter.spanId !== undefined && event.spanId !== filter.spanId) continue\n if (filter.direction !== undefined && event.direction !== filter.direction) continue\n if (filter.attemptIndex !== undefined && event.attemptIndex !== filter.attemptIndex)\n continue\n out.push(event)\n }\n }\n return out\n }\n}\n\n// ── Helpers ──────────────────────────────────────────────────────────────\n\n/**\n * Best-effort provider id from a base URL. Falls back to the URL host when\n * none of the well-known patterns match.\n */\nexport function providerFromBaseUrl(baseUrl: string): string {\n const lower = baseUrl.toLowerCase()\n if (lower.includes('api.openai.com')) return 'openai'\n if (lower.includes('api.anthropic.com')) return 'anthropic'\n if (lower.includes('generativelanguage.googleapis.com')) return 'google'\n if (lower.includes('api.together.ai') || lower.includes('api.together.xyz')) return 'together'\n if (lower.includes('api.deepseek.com')) return 'deepseek'\n if (lower.includes('router.tangle.tools')) return 'tangle-router'\n if (lower.includes('api.litellm') || lower.includes('litellm')) return 'litellm'\n try {\n return new URL(baseUrl).host\n } catch {\n return baseUrl\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyFA,SAAgB,wBAAwB,OAA2C;CACjF,MAAM,EAAE,gBAAgB,aAAa,iBAAiB,cAAc,iBAAiB;CACrF,MAAM,EAAE,OAAO,WAAW,OAAO;EAC/B;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,OAAO;EACL,GAAG;EACH,GAAG;EACH,gBAAgB,CACd,GAAI,MAAM,kBAAkB,CAAC,GAC7B,GAAG,OAAO,SAAS,KAAK,YAAY,QAAQ,IAAI,CAClD;CACF;AACF;AAQA,IAAa,0BAAb,MAAgE;CAC9D,SAAqC,CAAC;CACtC;CAEA,YAAY,OAAuC,CAAC,GAAG;EACrD,KAAK,WAAW,KAAK,YAAY;CACnC;CAEA,MAAM,OAAO,OAAwC;EACnD,KAAK,OAAO,KAAK,KAAK,SAAS;GAAE,GAAG;GAAO,gBAAgB,MAAM,kBAAkB,CAAC;EAAE,CAAC,CAAC;CAC1F;CAEA,MAAM,KAAK,SAAgC,CAAC,GAAgC;EAC1E,OAAO,KAAK,OAAO,QAChB,OACE,OAAO,UAAU,KAAA,KAAa,EAAE,UAAU,OAAO,WACjD,OAAO,WAAW,KAAA,KAAa,EAAE,WAAW,OAAO,YACnD,OAAO,cAAc,KAAA,KAAa,EAAE,cAAc,OAAO,eACzD,OAAO,iBAAiB,KAAA,KAAa,EAAE,iBAAiB,OAAO,aACpE;CACF;CAEA,OAAe;EACb,OAAO,KAAK,OAAO;CACrB;AACF;AAEA,IAAa,sBAAb,MAA4D;CAC1D,MAAM,SAAwB,CAE9B;;;;;;;CAOA,MAAM,OAAoC;EACxC,OAAO,CAAC;CACV;AACF;AAcA,IAAa,4BAAb,MAAkE;CAChE;CACA;CACA;CACA;CACA,eAAuB;CACvB,YAAoB;CACpB,cAA4C;CAE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,UAAU;IACtD,MAAM;GACR;GACA,KAAK,MAAM,QAAQ,KAAK,MAAM,IAAI,GAAG;IACnC,IAAI,CAAC,MAAM;IACX,MAAM,QAAQ,KAAK,MAAM,IAAI;IAC7B,IAAI,OAAO,UAAU,KAAA,KAAa,MAAM,UAAU,OAAO,OAAO;IAChE,IAAI,OAAO,WAAW,KAAA,KAAa,MAAM,WAAW,OAAO,QAAQ;IACnE,IAAI,OAAO,cAAc,KAAA,KAAa,MAAM,cAAc,OAAO,WAAW;IAC5E,IAAI,OAAO,iBAAiB,KAAA,KAAa,MAAM,iBAAiB,OAAO,cACrE;IACF,IAAI,KAAK,KAAK;GAChB;EACF;EACA,OAAO;CACT;AACF;;;;;AAQA,SAAgB,oBAAoB,SAAyB;CAC3D,MAAM,QAAQ,QAAQ,YAAY;CAClC,IAAI,MAAM,SAAS,gBAAgB,GAAG,OAAO;CAC7C,IAAI,MAAM,SAAS,mBAAmB,GAAG,OAAO;CAChD,IAAI,MAAM,SAAS,mCAAmC,GAAG,OAAO;CAChE,IAAI,MAAM,SAAS,iBAAiB,KAAK,MAAM,SAAS,kBAAkB,GAAG,OAAO;CACpF,IAAI,MAAM,SAAS,kBAAkB,GAAG,OAAO;CAC/C,IAAI,MAAM,SAAS,qBAAqB,GAAG,OAAO;CAClD,IAAI,MAAM,SAAS,aAAa,KAAK,MAAM,SAAS,SAAS,GAAG,OAAO;CACvE,IAAI;EACF,OAAO,IAAI,IAAI,OAAO,CAAC,CAAC;CAC1B,QAAQ;EACN,OAAO;CACT;AACF"}
1
+ {"version":3,"file":"raw-provider-sink-RbaEv2vB.js","names":["fs"],"sources":["../src/trace/raw-provider-sink.ts"],"sourcesContent":["/**\n * RawProviderSink — first-class persistence for the actual HTTP-level\n * request/response bodies of every LLM provider call.\n *\n * Why this is a separate sink from the structured `LlmSpan`:\n *\n * - `LlmSpan` records the *intent* — model name, messages, output text,\n * usage. It's what dashboards read; it's NOT enough for forensics.\n * - When a downstream consumer reports \"the verifier used the wrong route\"\n * or \"tokens look right but reasoning was missing,\" the only way to\n * answer is the raw HTTP body. Span fields can lie (a proxy can echo\n * a different `model` value than what actually answered); the raw\n * response is ground truth.\n *\n * Default behaviour: opt-in. Pass `rawSink` to `LlmClientOptions` (or the\n * matrix runner / BuilderSession sets it up automatically) and every\n * request, response, and error is recorded — including retries, with the\n * attempt index attached so a flaky call's full event chain is recoverable.\n *\n * Redaction is enforced at sink time. The default redactor runs the redaction\n * core (`./redact`, default profile) over headers, bodies and the error\n * message: credential headers and fields are replaced by name, credential and\n * personal-data values by shape. Override via the sink constructor or the\n * per-call `redactor`. The `redactedFields` array on the persisted event lets\n * a reviewer see what was replaced without exposing the values.\n */\n\nimport { promises as fs } from 'node:fs'\nimport * as path from 'node:path'\nimport { redact } from './redact'\n\nexport type RawProviderDirection = 'request' | 'response' | 'error'\n\nexport interface RawProviderEvent {\n /** Stable id. Generated by the sink if omitted. */\n eventId: string\n /** Trace context populated by `LlmClient` when the call is wrapped in a span. */\n runId?: string\n spanId?: string\n /**\n * Logical provider name. Free-form so callers can use whatever id matches\n * their topology (`'openai'`, `'anthropic'`, `'tangle-router'`, …). When\n * omitted, derived from `baseUrl` in `LlmClientOptions`.\n */\n provider: string\n model: string\n /** Endpoint path, e.g. `'/v1/chat/completions'`. */\n endpoint: string\n /** Base URL used for the call (already-normalised — no trailing slash). */\n baseUrl: string\n /** 0-indexed retry attempt. The first attempt is 0; a retried call gets 1, 2, … */\n attemptIndex: number\n direction: RawProviderDirection\n /** Unix ms. */\n timestamp: number\n /** Wall-clock duration of the call leg. Set on `response` and `error` events; null on `request`. */\n durationMs?: number\n statusCode?: number\n requestHeaders?: Record<string, string>\n requestBody?: unknown\n responseHeaders?: Record<string, string>\n responseBody?: unknown\n /** Set on `direction: 'error'` events. */\n errorMessage?: string\n /** JSON Pointers of the fields the redactor replaced ('/requestHeaders/Authorization', '/requestBody/apiKey', …). */\n redactedFields: string[]\n}\n\nexport interface RawProviderSinkFilter {\n runId?: string\n spanId?: string\n direction?: RawProviderDirection\n attemptIndex?: number\n}\n\nexport interface RawProviderSink {\n record(event: RawProviderEvent): Promise<void>\n /** Optional listing — implementations that durably persist (file, db) should support this. */\n list?(filter?: RawProviderSinkFilter): Promise<RawProviderEvent[]>\n /** Optional teardown for backed implementations. */\n close?(): Promise<void>\n}\n\nexport type ProviderRedactor = (event: RawProviderEvent) => RawProviderEvent\n\n/**\n * The default redactor: the redaction core over the parts of an event that\n * carry provider traffic. Every replaced path is added to `redactedFields`.\n */\nexport function defaultProviderRedactor(event: RawProviderEvent): RawProviderEvent {\n const { requestHeaders, requestBody, responseHeaders, responseBody, errorMessage } = event\n const { value, report } = redact({\n requestHeaders,\n requestBody,\n responseHeaders,\n responseBody,\n errorMessage,\n })\n return {\n ...event,\n ...value,\n redactedFields: [\n ...(event.redactedFields ?? []),\n ...report.findings.map((finding) => finding.path),\n ],\n }\n}\n\n// ── In-memory ────────────────────────────────────────────────────────────\n\nexport interface InMemoryRawProviderSinkOptions {\n redactor?: ProviderRedactor\n}\n\nexport class InMemoryRawProviderSink implements RawProviderSink {\n private events: RawProviderEvent[] = []\n private redactor: ProviderRedactor\n\n constructor(opts: InMemoryRawProviderSinkOptions = {}) {\n this.redactor = opts.redactor ?? defaultProviderRedactor\n }\n\n async record(event: RawProviderEvent): Promise<void> {\n this.events.push(this.redactor({ ...event, redactedFields: event.redactedFields ?? [] }))\n }\n\n async list(filter: RawProviderSinkFilter = {}): Promise<RawProviderEvent[]> {\n return this.events.filter(\n (e) =>\n (filter.runId === undefined || e.runId === filter.runId) &&\n (filter.spanId === undefined || e.spanId === filter.spanId) &&\n (filter.direction === undefined || e.direction === filter.direction) &&\n (filter.attemptIndex === undefined || e.attemptIndex === filter.attemptIndex),\n )\n }\n\n size(): number {\n return this.events.length\n }\n}\n\nexport class NoopRawProviderSink implements RawProviderSink {\n async record(): Promise<void> {\n /* no-op */\n }\n /**\n * Returns an empty array. Implemented so `assertRunCaptured` does not\n * trip the `no_raw_sink` issue when a caller explicitly opts out of\n * capture by passing this sink — opt-out is a deliberate choice, not a\n * misconfiguration.\n */\n async list(): Promise<RawProviderEvent[]> {\n return []\n }\n}\n\n// ── Filesystem (NDJSON) ──────────────────────────────────────────────────\n\nexport interface FileSystemRawProviderSinkOptions {\n /** Directory the NDJSON file is written into. Created if missing. */\n dir: string\n /** File name; default `'raw-provider-events.ndjson'`. */\n fileName?: string\n /** Bytes after which the writer rolls over to a new file (default 32 MiB). */\n rollAtBytes?: number\n redactor?: ProviderRedactor\n}\n\nexport class FileSystemRawProviderSink implements RawProviderSink {\n private dir: string\n private fileName: string\n private rollAtBytes: number\n private redactor: ProviderRedactor\n private bytesWritten = 0\n private rollIndex = 0\n private initPromise: Promise<void> | null = null\n\n constructor(opts: FileSystemRawProviderSinkOptions) {\n this.dir = opts.dir\n this.fileName = opts.fileName ?? 'raw-provider-events.ndjson'\n this.rollAtBytes = opts.rollAtBytes ?? 32 * 1024 * 1024\n this.redactor = opts.redactor ?? defaultProviderRedactor\n }\n\n private async ensureInit(): Promise<void> {\n if (!this.initPromise) {\n this.initPromise = fs.mkdir(this.dir, { recursive: true }).then(() => undefined)\n }\n await this.initPromise\n }\n\n private currentPath(): string {\n if (this.rollIndex === 0) return path.join(this.dir, this.fileName)\n return path.join(this.dir, `${this.fileName}.${this.rollIndex}`)\n }\n\n async record(event: RawProviderEvent): Promise<void> {\n await this.ensureInit()\n const redacted = this.redactor({ ...event, redactedFields: event.redactedFields ?? [] })\n const line = `${JSON.stringify(redacted)}\\n`\n if (this.bytesWritten + line.length > this.rollAtBytes && this.bytesWritten > 0) {\n this.rollIndex += 1\n this.bytesWritten = 0\n }\n await fs.appendFile(this.currentPath(), line, 'utf8')\n this.bytesWritten += line.length\n }\n\n async list(filter: RawProviderSinkFilter = {}): Promise<RawProviderEvent[]> {\n await this.ensureInit()\n const out: RawProviderEvent[] = []\n for (let i = 0; i <= this.rollIndex; i++) {\n const file =\n i === 0 ? path.join(this.dir, this.fileName) : path.join(this.dir, `${this.fileName}.${i}`)\n let body: string\n try {\n body = await fs.readFile(file, 'utf8')\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT') continue\n throw err\n }\n for (const line of body.split('\\n')) {\n if (!line) continue\n const event = JSON.parse(line) as RawProviderEvent\n if (filter.runId !== undefined && event.runId !== filter.runId) continue\n if (filter.spanId !== undefined && event.spanId !== filter.spanId) continue\n if (filter.direction !== undefined && event.direction !== filter.direction) continue\n if (filter.attemptIndex !== undefined && event.attemptIndex !== filter.attemptIndex)\n continue\n out.push(event)\n }\n }\n return out\n }\n}\n\n// ── Helpers ──────────────────────────────────────────────────────────────\n\n/**\n * Best-effort provider id from a base URL. Falls back to the URL host when\n * none of the well-known patterns match.\n */\nexport function providerFromBaseUrl(baseUrl: string): string {\n const lower = baseUrl.toLowerCase()\n if (lower.includes('api.openai.com')) return 'openai'\n if (lower.includes('api.anthropic.com')) return 'anthropic'\n if (lower.includes('generativelanguage.googleapis.com')) return 'google'\n if (lower.includes('api.together.ai') || lower.includes('api.together.xyz')) return 'together'\n if (lower.includes('api.deepseek.com')) return 'deepseek'\n if (lower.includes('router.tangle.tools')) return 'tangle-router'\n if (lower.includes('api.litellm') || lower.includes('litellm')) return 'litellm'\n try {\n return new URL(baseUrl).host\n } catch {\n return baseUrl\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyFA,SAAgB,wBAAwB,OAA2C;CACjF,MAAM,EAAE,gBAAgB,aAAa,iBAAiB,cAAc,iBAAiB;CACrF,MAAM,EAAE,OAAO,WAAW,OAAO;EAC/B;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,OAAO;EACL,GAAG;EACH,GAAG;EACH,gBAAgB,CACd,GAAI,MAAM,kBAAkB,CAAC,GAC7B,GAAG,OAAO,SAAS,KAAK,YAAY,QAAQ,IAAI,CAClD;CACF;AACF;AAQA,IAAa,0BAAb,MAAgE;CAC9D,SAAqC,CAAC;CACtC;CAEA,YAAY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AAS,gBAAgB,GAAG,OAAO;CAC7C,IAAI,MAAM,SAAS,mBAAmB,GAAG,OAAO;CAChD,IAAI,MAAM,SAAS,mCAAmC,GAAG,OAAO;CAChE,IAAI,MAAM,SAAS,iBAAiB,KAAK,MAAM,SAAS,kBAAkB,GAAG,OAAO;CACpF,IAAI,MAAM,SAAS,kBAAkB,GAAG,OAAO;CAC/C,IAAI,MAAM,SAAS,qBAAqB,GAAG,OAAO;CAClD,IAAI,MAAM,SAAS,aAAa,KAAK,MAAM,SAAS,SAAS,GAAG,OAAO;CACvE,IAAI;EACF,OAAO,IAAI,IAAI,OAAO,CAAC,CAAC;CAC1B,QAAQ;EACN,OAAO;CACT;AACF"}
@@ -1,39 +1,54 @@
1
1
  /**
2
- * The redaction core: the one place that decides what must not leave a
3
- * process or a machine. Every trace writer, exporter, uploader and share path
4
- * calls it.
5
- *
6
- * Three profiles, each a superset of the one before:
7
- * - `default` removes credentials, found by key name and by value shape, and
8
- * personal data (email addresses, card numbers, SSNs, phone numbers).
9
- * Content is kept. Strings are capped at 1 MiB.
10
- * - `share` also removes phone, IP and postal-address fields, replaces
11
- * account, user, tenant, session and request identifiers with pseudonyms
12
- * that stay consistent within one call, and caps strings at 64 KiB.
13
- * - `strict` also removes prompt, completion, message, tool payload and other
14
- * raw-content fields and embedded media, and caps strings at 4 KiB.
15
- *
16
- * A string that holds a credential is replaced whole with
17
- * `[REDACTED:<detector>]`. Replacing only the matched span can leave part of a
18
- * secret behind when a pattern's boundary is wrong. Personal data inside prose
19
- * is replaced in place, so the rest of the text stays readable.
20
- *
21
- * `assessShareSafety` reads a value without changing it and returns SAFE,
22
- * SAFE_WITH_WARNINGS, UNSAFE or UNKNOWN. UNKNOWN means the scanner could not
23
- * read part of the value (a cycle, binary data, nesting past the depth limit);
24
- * it is never reported as safe. `redactForShare` redacts and then assesses the
25
- * redacted output, so a detector gap shows up as UNSAFE instead of a leak.
26
- *
27
- * Reports and findings carry paths, categories and detector ids, never the
28
- * values they matched.
2
+ * Canonical snake_case form of a field name, so camelCase, kebab-case, dotted
3
+ * and snake_case spellings match one list: `userPassword`, `user-password` and
4
+ * `user.password` all become `user_password`.
5
+ */
6
+ declare function normalizeKey(key: string): string;
7
+ /**
8
+ * The safety category a field name puts its value in, or undefined for an
9
+ * ordinary field. Token counts and model limits (`inputTokens`, `max_tokens`,
10
+ * `token_count`) and names such as `author` are not credentials.
11
+ */
12
+ declare function classifyKey(key: string): SafetyCategory | undefined;
13
+ interface ValueDetectorOptions {
14
+ /** Conservative scanning treats untyped bare numbers as private; formatted preserves the core's existing policy. */
15
+ numericPolicy?: 'formatted' | 'conservative';
16
+ }
17
+ interface ValueDetector {
18
+ readonly id: string;
19
+ readonly pattern: RegExp;
20
+ readonly requires?: string;
21
+ readonly substringPattern?: RegExp;
22
+ readonly conservativePattern?: RegExp;
23
+ readonly accept?: (match: string, options?: ValueDetectorOptions) => boolean;
24
+ }
25
+ /** Stateless UTF-16 ranges for String.slice. Named `secret` groups preserve surrounding syntax. */
26
+ declare function matchValueDetector(text: string, detector: ValueDetector, options?: ValueDetectorOptions): Generator<{
27
+ start: number;
28
+ end: number;
29
+ }>;
30
+ /**
31
+ * High-confidence credential shapes. A hit replaces the whole string. Each
32
+ * pattern is written without the `g` flag so `test` stays stateless.
29
33
  *
30
- * The key classifier and the credential detector list are adapted from
31
- * agent-inspect (MIT, commit 3c3cbeda). `scripts/redaction-corpus.json` holds
32
- * the must-flag and must-not-flag cases, including the copied agent-inspect
33
- * safety corpus with its MIT notice; `pnpm redaction:corpus` runs this module
34
- * over every case.
34
+ * The provider-branded prefixes below (`sk-ant-`, `AIza`, `ghp_`, `xoxb-`,
35
+ * `AKIA`, `hubcap_`, `eyJ`…) have no leading `\b`. A `\b` word-boundary
36
+ * assertion does not fire between two word characters, so it silently passed
37
+ * a real token when something else glued a word character directly in front
38
+ * of it — a compound identifier like `env.GITHUB_TOKEN_ghp_<token>` (a `_`
39
+ * before `ghp_`) or `BACKUP_AKIA<key>` (a `_` before `AKIA`). These prefixes
40
+ * are distinctive enough on their own, so scanning without that boundary
41
+ * catches the same real credential wherever it is glued, at the cost of no
42
+ * meaningful new false positives (`scripts/redaction-corpus.json` covers
43
+ * both).
35
44
  */
45
+ declare const CREDENTIAL_DETECTORS: readonly ValueDetector[];
46
+ /** Ordered rules. Conservative numeric scanning is explicit; core patterns keep their existing defaults. */
47
+ declare const PERSONAL_DATA_DETECTORS: readonly ValueDetector[];
48
+ /** The first credential detector that matches, or undefined. */
49
+ declare function detectCredential(text: string): string | undefined;
36
50
  type RedactionProfile = 'default' | 'share' | 'strict';
51
+ declare const REDACTION_PROFILES: readonly RedactionProfile[];
37
52
  /** What a finding is about. `media` is embedded binary content (a `data:` URI) no text detector can read. */
38
53
  type SafetyCategory = 'credential' | 'personal-data' | 'identifier' | 'raw-content' | 'media';
39
54
  /**
@@ -41,7 +56,7 @@ type SafetyCategory = 'credential' | 'personal-data' | 'identifier' | 'raw-conte
41
56
  * redaction behavior (saved optimizer inputs, per-span redaction stamps) keys
42
57
  * on it, so bump it whenever a detector, key list, cap or marker changes.
43
58
  */
44
- declare const REDACTION_VERSION = "2.4.0";
59
+ declare const REDACTION_VERSION = "2.5.0";
45
60
  interface RedactionFinding {
46
61
  /** JSON Pointer (RFC 6901) to the value or key that was changed. */
47
62
  path: string;
@@ -137,5 +152,5 @@ declare function redactForShare<T>(value: T, options?: RedactOptions): {
137
152
  report: RedactionReport;
138
153
  verdict: ShareSafetyVerdict;
139
154
  };
140
- export { shareAllowed as _, RedactionProfile as a, ShareSafetyFinding as c, assessShareSafety as d, combineVerdicts as f, redactText as g, redactForShare as h, RedactionFinding as i, ShareSafetyStatus as l, redact as m, REDACTION_VERSION as n, RedactionReport as o, emptyRedactionReport as p, RedactOptions as r, SafetyCategory as s, AssessOptions as t, ShareSafetyVerdict as u };
141
- //# sourceMappingURL=redact-C_wzC4c_.d.ts.map
155
+ export { classifyKey as C, normalizeKey as E, ValueDetectorOptions as S, matchValueDetector as T, redactText as _, RedactionFinding as a, PERSONAL_DATA_DETECTORS as b, SafetyCategory as c, ShareSafetyVerdict as d, assessShareSafety as f, redactForShare as g, redact as h, RedactOptions as i, ShareSafetyFinding as l, emptyRedactionReport as m, REDACTION_PROFILES as n, RedactionProfile as o, combineVerdicts as p, REDACTION_VERSION as r, RedactionReport as s, AssessOptions as t, ShareSafetyStatus as u, shareAllowed as v, detectCredential as w, ValueDetector as x, CREDENTIAL_DETECTORS as y };
156
+ //# sourceMappingURL=redact-jrT0APTU.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redact-jrT0APTU.d.ts","names":[],"sources":["../src/trace/redaction/detectors.ts","../src/trace/redact.ts"],"mappings":";;;;;iBASgB,aAAa;;;;;;iBAmNb,YAAY,cAAc;UAWzB;;EAEf;;UAGe;WACN;WACA,SAAS;WACT;WACA,mBAAmB;WACnB,sBAAsB;WACtB,UAAU,eAAe,UAAU;;;iBAI7B,mBACf,cACA,UAAU,eACV,UAAS,uBACR;EAAY;EAAe;;;;;;;;;;;;;;;;;cAiEjB,+BAA+B;;cA8I/B,kCAAkC;;iBAuF/B,iBAAiB;KC1erB;cAEC,6BAA6B;;KAG9B;;;;;;cAOC;UAEI;;EAEf;EACA,UAAU;EACV;EACA;;UAGe;EACf;EACA,SAAS;;EAET;EACA,YAAY;EACZ;EACA,UAAU;;UAGK;;EAEf,UAAU;;EAEV;;;;;;;;;EASA;;EAEA,SAAS;;UAGM;;EAEf,UAAU;;EAEV;;KAGU;UAEK;EACf,UAAU;EACV;EACA;EACA;;EAEA;;UAGe;EACf,QAAQ;EACR,SAAS;EACT,UAAU;;EAEV;;;iBAkVc,qBAAqB,UAAS,mBAA+B;;;;;;iBAkC7D,OAAO,GACrB,OAAO,GACP,UAAS;EACN,OAAO;EAAG,QAAQ;;;;;;iBAUP,WAAW,cAAc,UAAS;;;;;;;iBAgKlC,kBAAkB,gBAAgB,UAAS,gBAAqB;;;;;iBAoBhE,gBACd,SAAS,kBACT,mBAAmB,sBACnB,iCACC;;iBAsCa,aAAa,SAAS;;;;;;iBAStB,eAAe,GAC7B,OAAO,GACP,UAAS;EACN,OAAO;EAAG,QAAQ;EAAiB,SAAS"}