@tangle-network/agent-eval 2.0.9 → 2.0.11

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 (235) hide show
  1. package/CHANGELOG.md +68 -16
  2. package/dist/adapters/http.d.ts +2 -2
  3. package/dist/{agent-profile-ORN4aArD.d.ts → agent-profile-_JzxgLDM.d.ts} +11 -5
  4. package/dist/{agent-profile-ORN4aArD.d.ts.map → agent-profile-_JzxgLDM.d.ts.map} +1 -1
  5. package/dist/analyst/index.d.ts +14 -14
  6. package/dist/analyst/index.js +31 -10
  7. package/dist/analyst/index.js.map +1 -1
  8. package/dist/{analyze-runs-DT693FJ7.d.ts → analyze-runs-Izz_ZeWg.d.ts} +2 -2
  9. package/dist/{analyze-runs-DT693FJ7.d.ts.map → analyze-runs-Izz_ZeWg.d.ts.map} +1 -1
  10. package/dist/{analyze-runs-CE_5VKh2.js → analyze-runs-xhH2Qxoc.js} +5 -5
  11. package/dist/{analyze-runs-CE_5VKh2.js.map → analyze-runs-xhH2Qxoc.js.map} +1 -1
  12. package/dist/app-grade/index.d.ts +4 -4
  13. package/dist/{benchmark-command-DLg8E4y8.js → benchmark-command-CGQXNFj7.js} +8 -7
  14. package/dist/benchmark-command-CGQXNFj7.js.map +1 -0
  15. package/dist/benchmarks/index.d.ts +5 -5
  16. package/dist/benchmarks/index.d.ts.map +1 -1
  17. package/dist/benchmarks/index.js +18 -9
  18. package/dist/benchmarks/index.js.map +1 -1
  19. package/dist/campaign/index.d.ts +7 -7
  20. package/dist/campaign/index.js +11 -11
  21. package/dist/{campaign-C_S3MOYa.js → campaign-eus7YRs2.js} +13 -13
  22. package/dist/{campaign-C_S3MOYa.js.map → campaign-eus7YRs2.js.map} +1 -1
  23. package/dist/{campaign-evidence-CM4FBOkX.d.ts → campaign-evidence-BOcX4w0r.d.ts} +5 -5
  24. package/dist/{campaign-evidence-CM4FBOkX.d.ts.map → campaign-evidence-BOcX4w0r.d.ts.map} +1 -1
  25. package/dist/{campaign-evidence-BTfzZo1u.js → campaign-evidence-KM5GTsHG.js} +3 -3
  26. package/dist/{campaign-evidence-BTfzZo1u.js.map → campaign-evidence-KM5GTsHG.js.map} +1 -1
  27. package/dist/{chat-client-uQNXGuO4.d.ts → chat-client-BlTooBDA.d.ts} +7 -2
  28. package/dist/{chat-client-uQNXGuO4.d.ts.map → chat-client-BlTooBDA.d.ts.map} +1 -1
  29. package/dist/{chat-client-CvyDOQBv.js → chat-client-Oyot5tyo.js} +2 -2
  30. package/dist/{chat-client-CvyDOQBv.js.map → chat-client-Oyot5tyo.js.map} +1 -1
  31. package/dist/{chat-json-call-DMrwmB-k.js → chat-json-call-DTmv2uNY.js} +2 -2
  32. package/dist/{chat-json-call-DMrwmB-k.js.map → chat-json-call-DTmv2uNY.js.map} +1 -1
  33. package/dist/cli.js +7 -7
  34. package/dist/{cluster-C-K0N2br.d.ts → cluster-BJ0nW3P7.d.ts} +2 -2
  35. package/dist/{cluster-C-K0N2br.d.ts.map → cluster-BJ0nW3P7.d.ts.map} +1 -1
  36. package/dist/{cluster-bootstrap-DXbnIdm8.js → cluster-bootstrap-CTC8Dd30.js} +2 -2
  37. package/dist/{cluster-bootstrap-DXbnIdm8.js.map → cluster-bootstrap-CTC8Dd30.js.map} +1 -1
  38. package/dist/{completion-verifier-DsotH2l3.js → completion-verifier-CCPG2Yc0.js} +3 -3
  39. package/dist/{completion-verifier-DsotH2l3.js.map → completion-verifier-CCPG2Yc0.js.map} +1 -1
  40. package/dist/{completion-verifier-C7wipJOK.d.ts → completion-verifier-CQOC3_bm.d.ts} +2 -2
  41. package/dist/{completion-verifier-C7wipJOK.d.ts.map → completion-verifier-CQOC3_bm.d.ts.map} +1 -1
  42. package/dist/contract/index.d.ts +11 -11
  43. package/dist/contract/index.js +12 -12
  44. package/dist/{default-registry-kps1SOaD.js → default-registry-Rs5uzlfJ.js} +3 -3
  45. package/dist/{default-registry-kps1SOaD.js.map → default-registry-Rs5uzlfJ.js.map} +1 -1
  46. package/dist/{default-registry-Bskl2HzV.d.ts → default-registry-X8McMoUV.d.ts} +6 -6
  47. package/dist/{default-registry-Bskl2HzV.d.ts.map → default-registry-X8McMoUV.d.ts.map} +1 -1
  48. package/dist/{define-agent-eval-Dnh4jXLX.js → define-agent-eval-D8ntOXqV.js} +3 -3
  49. package/dist/{define-agent-eval-Dnh4jXLX.js.map → define-agent-eval-D8ntOXqV.js.map} +1 -1
  50. package/dist/{define-agent-eval-tu3anVlk.d.ts → define-agent-eval-DH5-xi-F.d.ts} +4 -4
  51. package/dist/{define-agent-eval-tu3anVlk.d.ts.map → define-agent-eval-DH5-xi-F.d.ts.map} +1 -1
  52. package/dist/diagnosis/index.d.ts +2 -2
  53. package/dist/diagnosis/index.js +1 -1
  54. package/dist/{dspy-rlm-engine-DQbPdT_o.js → dspy-rlm-engine-ChE1PUM5.js} +3 -3
  55. package/dist/{dspy-rlm-engine-DQbPdT_o.js.map → dspy-rlm-engine-ChE1PUM5.js.map} +1 -1
  56. package/dist/{eval-campaign-DswSn7Gm.js → eval-campaign-BciGnrGy.js} +2 -2
  57. package/dist/{eval-campaign-DswSn7Gm.js.map → eval-campaign-BciGnrGy.js.map} +1 -1
  58. package/dist/{evaluation-C4-tf3Z_.d.ts → evaluation-CjZH6gW0.d.ts} +4 -4
  59. package/dist/{evaluation-C4-tf3Z_.d.ts.map → evaluation-CjZH6gW0.d.ts.map} +1 -1
  60. package/dist/evaluation.d.ts +1 -1
  61. package/dist/{exact-types-CUsSMW3n.d.ts → exact-types-BIHqYBYf.d.ts} +2 -2
  62. package/dist/{exact-types-CUsSMW3n.d.ts.map → exact-types-BIHqYBYf.d.ts.map} +1 -1
  63. package/dist/experiment/index.d.ts +5 -5
  64. package/dist/experiment/index.js +8 -8
  65. package/dist/{external-optimizer-contracts-ZDBfbZ_s.js → external-optimizer-contracts-BFV8lnhl.js} +7 -2
  66. package/dist/{external-optimizer-contracts-ZDBfbZ_s.js.map → external-optimizer-contracts-BFV8lnhl.js.map} +1 -1
  67. package/dist/{external-optimizer-process-CVi1x2nb.js → external-optimizer-process-B6emPodQ.js} +3 -3
  68. package/dist/{external-optimizer-process-CVi1x2nb.js.map → external-optimizer-process-B6emPodQ.js.map} +1 -1
  69. package/dist/{external-optimizer-subprocess-mV-2swJI.js → external-optimizer-subprocess-_O06eDVA.js} +33 -20
  70. package/dist/external-optimizer-subprocess-_O06eDVA.js.map +1 -0
  71. package/dist/{feedback-trajectory-D7hgL6y5.d.ts → feedback-trajectory-CoQPmSJV.d.ts} +3 -3
  72. package/dist/{feedback-trajectory-D7hgL6y5.d.ts.map → feedback-trajectory-CoQPmSJV.d.ts.map} +1 -1
  73. package/dist/{findings-store-CZy5kUDo.js → findings-store-CvYUzQBR.js} +4 -4
  74. package/dist/{findings-store-CZy5kUDo.js.map → findings-store-CvYUzQBR.js.map} +1 -1
  75. package/dist/{index-Cav3abKy.d.ts → index-BSb3fJyZ.d.ts} +81 -19
  76. package/dist/{index-Cav3abKy.d.ts.map → index-BSb3fJyZ.d.ts.map} +1 -1
  77. package/dist/{index-CIqYaySd.d.ts → index-Bk1XEkP7.d.ts} +26 -16
  78. package/dist/index-Bk1XEkP7.d.ts.map +1 -0
  79. package/dist/{index-DmMHTDjT.d.ts → index-BmWw8zN6.d.ts} +9 -9
  80. package/dist/{index-DmMHTDjT.d.ts.map → index-BmWw8zN6.d.ts.map} +1 -1
  81. package/dist/{index--vDCtdaj.d.ts → index-CCOaNmh2.d.ts} +7 -7
  82. package/dist/{index--vDCtdaj.d.ts.map → index-CCOaNmh2.d.ts.map} +1 -1
  83. package/dist/{index-moZnazVj.d.ts → index-Cn9gB5Ca.d.ts} +21 -21
  84. package/dist/{index-moZnazVj.d.ts.map → index-Cn9gB5Ca.d.ts.map} +1 -1
  85. package/dist/{index-Er8TKQ3q.d.ts → index-aRalB_Ma.d.ts} +3 -3
  86. package/dist/{index-Er8TKQ3q.d.ts.map → index-aRalB_Ma.d.ts.map} +1 -1
  87. package/dist/index.d.ts +29 -29
  88. package/dist/index.js +23 -23
  89. package/dist/{integrity-BF0tJK21.js → integrity-DacT3oJ1.js} +2 -2
  90. package/dist/{integrity-BF0tJK21.js.map → integrity-DacT3oJ1.js.map} +1 -1
  91. package/dist/{integrity-BJGstiCh.d.ts → integrity-DotDLWtj.d.ts} +2 -2
  92. package/dist/{integrity-BJGstiCh.d.ts.map → integrity-DotDLWtj.d.ts.map} +1 -1
  93. package/dist/{judge-gate-DANg5FLq.js → judge-gate-CpD3wmcf.js} +2 -2
  94. package/dist/{judge-gate-DANg5FLq.js.map → judge-gate-CpD3wmcf.js.map} +1 -1
  95. package/dist/{llm-client-Dw4x6EdE.js → llm-client-Dk8lBnMh.js} +15 -2
  96. package/dist/{llm-client-Dw4x6EdE.js.map → llm-client-Dk8lBnMh.js.map} +1 -1
  97. package/dist/{llm-judge-DFoSy4Qn.js → llm-judge-DYmEdo3M.js} +3 -3
  98. package/dist/{llm-judge-DFoSy4Qn.js.map → llm-judge-DYmEdo3M.js.map} +1 -1
  99. package/dist/{matrix-OgdWQBQa.d.ts → matrix-BDl7hoBr.d.ts} +2 -2
  100. package/dist/{matrix-OgdWQBQa.d.ts.map → matrix-BDl7hoBr.d.ts.map} +1 -1
  101. package/dist/{measure-validity-plan-B1_qYlsk.d.ts → measure-validity-plan-BReXzcVh.d.ts} +62 -4
  102. package/dist/measure-validity-plan-BReXzcVh.d.ts.map +1 -0
  103. package/dist/{measure-validity-plan-t0YQRzJQ.js → measure-validity-plan-CJkBNzX_.js} +43 -6
  104. package/dist/measure-validity-plan-CJkBNzX_.js.map +1 -0
  105. package/dist/meta-eval/index.d.ts +2 -2
  106. package/dist/meta-eval/index.js +178 -35
  107. package/dist/meta-eval/index.js.map +1 -1
  108. package/dist/multishot/golden/index.d.ts +1 -1
  109. package/dist/multishot/index.d.ts +56 -17
  110. package/dist/multishot/index.d.ts.map +1 -1
  111. package/dist/multishot/index.js +93 -20
  112. package/dist/multishot/index.js.map +1 -1
  113. package/dist/node-transport-DJno8V46.js +62 -0
  114. package/dist/node-transport-DJno8V46.js.map +1 -0
  115. package/dist/openapi.json +1 -1
  116. package/dist/{optimization-method-D4CpYsVA.js → optimization-method-4JlbMxd2.js} +27 -38
  117. package/dist/optimization-method-4JlbMxd2.js.map +1 -0
  118. package/dist/{paired-arms-B6EXnI47.js → paired-arms-CJH5Q0wx.js} +2 -2
  119. package/dist/{paired-arms-B6EXnI47.js.map → paired-arms-CJH5Q0wx.js.map} +1 -1
  120. package/dist/{paired-promotion-decision-xYe881cD.js → paired-promotion-decision-BtfVwEAk.js} +2 -2
  121. package/dist/{paired-promotion-decision-xYe881cD.js.map → paired-promotion-decision-BtfVwEAk.js.map} +1 -1
  122. package/dist/{paired-promotion-decision-DuvRdnsW.d.ts → paired-promotion-decision-DJlI4z_k.d.ts} +2 -2
  123. package/dist/{paired-promotion-decision-DuvRdnsW.d.ts.map → paired-promotion-decision-DJlI4z_k.d.ts.map} +1 -1
  124. package/dist/{paired-promotion-power-DirShsIs.js → paired-promotion-power-DG1avBKf.js} +3 -3
  125. package/dist/{paired-promotion-power-DirShsIs.js.map → paired-promotion-power-DG1avBKf.js.map} +1 -1
  126. package/dist/pipelines/index.js +1 -1
  127. package/dist/{power-DTg6u30w.js → power-COie_o6E.js} +3 -3
  128. package/dist/{power-DTg6u30w.js.map → power-COie_o6E.js.map} +1 -1
  129. package/dist/{prime-protocol-Jm2pWh--.d.ts → prime-protocol-BRMk6dGI.d.ts} +2 -2
  130. package/dist/{prime-protocol-Jm2pWh--.d.ts.map → prime-protocol-BRMk6dGI.d.ts.map} +1 -1
  131. package/dist/{promotion-gate-BXgcORnM.d.ts → promotion-gate-B0VTBoXg.d.ts} +2 -2
  132. package/dist/{promotion-gate-BXgcORnM.d.ts.map → promotion-gate-B0VTBoXg.d.ts.map} +1 -1
  133. package/dist/{promotion-policy-Z5E-C32U.js → promotion-policy-BgI7PsQn.js} +3 -3
  134. package/dist/{promotion-policy-Z5E-C32U.js.map → promotion-policy-BgI7PsQn.js.map} +1 -1
  135. package/dist/{registry-DEZDECdr.d.ts → registry-BeInzotS.d.ts} +4 -4
  136. package/dist/{registry-DEZDECdr.d.ts.map → registry-BeInzotS.d.ts.map} +1 -1
  137. package/dist/reporting.d.ts +4 -4
  138. package/dist/reporting.js +3 -3
  139. package/dist/{research-report-CIgUe1lv.d.ts → research-report-CL5_UqCX.d.ts} +2 -2
  140. package/dist/{research-report-CIgUe1lv.d.ts.map → research-report-CL5_UqCX.d.ts.map} +1 -1
  141. package/dist/{researcher-CY_byuZl.d.ts → researcher-BOpZP_Ja.d.ts} +4 -4
  142. package/dist/{researcher-CY_byuZl.d.ts.map → researcher-BOpZP_Ja.d.ts.map} +1 -1
  143. package/dist/rl.d.ts +7 -7
  144. package/dist/rl.js +4 -4
  145. package/dist/rollout/index.d.ts +2 -2
  146. package/dist/rollout/index.js +1 -1
  147. package/dist/{rollout-B_lrpd9a.js → rollout--rSr43Pd.js} +2 -2
  148. package/dist/{rollout-B_lrpd9a.js.map → rollout--rSr43Pd.js.map} +1 -1
  149. package/dist/{rollout-nodes-Vas6OSxX.js → rollout-nodes-DFxKpIr2.js} +39 -10
  150. package/dist/rollout-nodes-DFxKpIr2.js.map +1 -0
  151. package/dist/{run-improvement-loop-BaPDVbW8.d.ts → run-improvement-loop-BeHu5D9Z.d.ts} +22 -10
  152. package/dist/run-improvement-loop-BeHu5D9Z.d.ts.map +1 -0
  153. package/dist/{runtime-rollouts-Vv-BAqmq.js → runtime-rollouts-CE0MbQPq.js} +54 -7
  154. package/dist/runtime-rollouts-CE0MbQPq.js.map +1 -0
  155. package/dist/search/index.d.ts +2 -2
  156. package/dist/search/index.js +2 -2
  157. package/dist/{search-kernel-BzTeb89p.d.ts → search-kernel-CJZ-ZSV1.d.ts} +3 -3
  158. package/dist/{search-kernel-BzTeb89p.d.ts.map → search-kernel-CJZ-ZSV1.d.ts.map} +1 -1
  159. package/dist/{search-kernel-DOPW08Hx.js → search-kernel-mZc79S6N.js} +4 -4
  160. package/dist/{search-kernel-DOPW08Hx.js.map → search-kernel-mZc79S6N.js.map} +1 -1
  161. package/dist/{search-summary-CYOHZAAy.js → search-summary-CCgP2qXz.js} +3 -3
  162. package/dist/{search-summary-CYOHZAAy.js.map → search-summary-CCgP2qXz.js.map} +1 -1
  163. package/dist/{self-improve-DY8ZY4lY.d.ts → self-improve-B1fsNejr.d.ts} +6 -6
  164. package/dist/{self-improve-DY8ZY4lY.d.ts.map → self-improve-B1fsNejr.d.ts.map} +1 -1
  165. package/dist/{self-improve-CIFqccHV.js → self-improve-C_Bcdmv8.js} +5 -4
  166. package/dist/{self-improve-CIFqccHV.js.map → self-improve-C_Bcdmv8.js.map} +1 -1
  167. package/dist/{sequential-B9iROM1S.d.ts → sequential-CHplorpC.d.ts} +2 -2
  168. package/dist/{sequential-B9iROM1S.d.ts.map → sequential-CHplorpC.d.ts.map} +1 -1
  169. package/dist/{sequential-tZjGysXY.js → sequential-DR-pnYQ7.js} +3 -3
  170. package/dist/{sequential-tZjGysXY.js.map → sequential-DR-pnYQ7.js.map} +1 -1
  171. package/dist/{server-1fzBCxMh.js → server-aZFmRucn.js} +3 -3
  172. package/dist/{server-1fzBCxMh.js.map → server-aZFmRucn.js.map} +1 -1
  173. package/dist/{skillopt-optimization-method-CbHBkopM.js → skillopt-optimization-method-DHk1K757.js} +93 -39
  174. package/dist/skillopt-optimization-method-DHk1K757.js.map +1 -0
  175. package/dist/{statistical-heldout-C7Jjo5nP.js → statistical-heldout-CL_7mI5C.js} +2 -2
  176. package/dist/{statistical-heldout-C7Jjo5nP.js.map → statistical-heldout-CL_7mI5C.js.map} +1 -1
  177. package/dist/{statistics-BPl13X3G.js → statistics-AKnVFnK-.js} +67 -42
  178. package/dist/statistics-AKnVFnK-.js.map +1 -0
  179. package/dist/statistics.d.ts +3 -3
  180. package/dist/statistics.js +1 -1
  181. package/dist/{store-tool-spans-Dq8r0PbJ.d.ts → store-tool-spans-M3WxeRrG.d.ts} +4 -4
  182. package/dist/{store-tool-spans-Dq8r0PbJ.d.ts.map → store-tool-spans-M3WxeRrG.d.ts.map} +1 -1
  183. package/dist/{summary-report-DzbnK81K.js → summary-report-DyBkOC6V.js} +3 -3
  184. package/dist/{summary-report-DzbnK81K.js.map → summary-report-DyBkOC6V.js.map} +1 -1
  185. package/dist/supervisor-run/index.d.ts +12 -2
  186. package/dist/supervisor-run/index.d.ts.map +1 -1
  187. package/dist/supervisor-run/index.js +3 -3
  188. package/dist/{systemone-BuSZTI88.d.ts → systemone-4PadCE4C.d.ts} +7 -7
  189. package/dist/{systemone-BuSZTI88.d.ts.map → systemone-4PadCE4C.d.ts.map} +1 -1
  190. package/dist/{systemone-review-mlfxWdLz.d.ts → systemone-review-DpAXWDkL.d.ts} +2 -2
  191. package/dist/{systemone-review-mlfxWdLz.d.ts.map → systemone-review-DpAXWDkL.d.ts.map} +1 -1
  192. package/dist/systemone.d.ts +3 -3
  193. package/dist/{tool-groups-PNDX8fd-.d.ts → tool-groups-SlnoQNyT.d.ts} +2 -2
  194. package/dist/tool-groups-SlnoQNyT.d.ts.map +1 -0
  195. package/dist/{tool-waste-783VCo1y.js → tool-waste-BZnYSa6J.js} +2 -2
  196. package/dist/{tool-waste-783VCo1y.js.map → tool-waste-BZnYSa6J.js.map} +1 -1
  197. package/dist/{trace-questions-DBtr4jWi.d.ts → trace-questions-ybyF0B6N.d.ts} +2 -2
  198. package/dist/{trace-questions-DBtr4jWi.d.ts.map → trace-questions-ybyF0B6N.d.ts.map} +1 -1
  199. package/dist/trace-repair/index.d.ts +1 -1
  200. package/dist/traces.d.ts +4 -4
  201. package/dist/{tree-CtlQQL1w.js → tree-CiIe-f3f.js} +4 -4
  202. package/dist/{tree-CtlQQL1w.js.map → tree-CiIe-f3f.js.map} +1 -1
  203. package/dist/{types-CKNAzCSA.d.ts → types-B1W3v8dT.d.ts} +3 -3
  204. package/dist/{types-CKNAzCSA.d.ts.map → types-B1W3v8dT.d.ts.map} +1 -1
  205. package/dist/{types-DbeIGi73.d.ts → types-Bte3EsFQ.d.ts} +52 -5
  206. package/dist/types-Bte3EsFQ.d.ts.map +1 -0
  207. package/dist/{types-BO948H-U.d.ts → types-D5XtEH9Q.d.ts} +8 -4
  208. package/dist/{types-BO948H-U.d.ts.map → types-D5XtEH9Q.d.ts.map} +1 -1
  209. package/dist/{types-D-WF1KM3.d.ts → types-xVtEOBhO.d.ts} +31 -8
  210. package/dist/types-xVtEOBhO.d.ts.map +1 -0
  211. package/dist/wire/index.d.ts +4 -4
  212. package/dist/wire/index.js +1 -1
  213. package/dist/world/index.d.ts +1 -1
  214. package/docs/design/statistics-decisions.md +18 -1
  215. package/docs/eval-surface-map.md +1 -1
  216. package/docs/feature-guide.md +1 -1
  217. package/docs/multi-turn-optimization.md +6 -2
  218. package/docs/outcome-validity.md +51 -12
  219. package/docs/public-api.md +17 -16
  220. package/docs/{multi-shot-optimization.md → trajectory-optimization.md} +1 -1
  221. package/package.json +1 -1
  222. package/dist/benchmark-command-DLg8E4y8.js.map +0 -1
  223. package/dist/external-optimizer-subprocess-mV-2swJI.js.map +0 -1
  224. package/dist/index-CIqYaySd.d.ts.map +0 -1
  225. package/dist/measure-validity-plan-B1_qYlsk.d.ts.map +0 -1
  226. package/dist/measure-validity-plan-t0YQRzJQ.js.map +0 -1
  227. package/dist/optimization-method-D4CpYsVA.js.map +0 -1
  228. package/dist/rollout-nodes-Vas6OSxX.js.map +0 -1
  229. package/dist/run-improvement-loop-BaPDVbW8.d.ts.map +0 -1
  230. package/dist/runtime-rollouts-Vv-BAqmq.js.map +0 -1
  231. package/dist/skillopt-optimization-method-CbHBkopM.js.map +0 -1
  232. package/dist/statistics-BPl13X3G.js.map +0 -1
  233. package/dist/tool-groups-PNDX8fd-.d.ts.map +0 -1
  234. package/dist/types-D-WF1KM3.d.ts.map +0 -1
  235. package/dist/types-DbeIGi73.d.ts.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import { r as pairedBootstrap } from "./paired-tests-CXcD_B80.js";
2
- import { t as decidePairedPromotion } from "./paired-promotion-decision-xYe881cD.js";
2
+ import { t as decidePairedPromotion } from "./paired-promotion-decision-BtfVwEAk.js";
3
3
  // src/campaign/gates/statistical-heldout.ts
4
4
  /**
5
5
  * Held-out inference pairs execution cells and judge identities before taking
@@ -252,4 +252,4 @@ function dimensionRegressions(candidate, baseline, scenarioIds, criticalDimensio
252
252
  }
253
253
  export { heldoutSignificance as a, dimensionRegressions as i, aggregatePairedHoldout as n, pairHoldout as o, detectScale as r, TIE_WARN_FRACTION as t };
254
254
 
255
- //# sourceMappingURL=statistical-heldout-C7Jjo5nP.js.map
255
+ //# sourceMappingURL=statistical-heldout-CL_7mI5C.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"statistical-heldout-C7Jjo5nP.js","names":[],"sources":["../src/campaign/gates/statistical-heldout.ts"],"sourcesContent":["/**\n * Held-out inference pairs execution cells and judge identities before taking\n * means within registered independent units. Repetitions can improve a unit's\n * precision without increasing n. Ungrouped inference concerns independently\n * sampled execution cells conditional on a fixed scenario roster.\n *\n * The shared paired decision rule selects the estimator and statistical test.\n * Dimension reports retain missing coverage so required safety checks cannot\n * pass through absent evidence. Thresholds use the judge's native score scale.\n */\n\nimport {\n decidePairedPromotion,\n type PairedDecisionMethod,\n type PairedDecisionStatistic,\n type PairedMcNemarEvidence,\n type PairedPromotionDecision,\n} from '../../paired-promotion-decision'\nimport {\n DECISION_PAIRED_DELTA_STATISTIC,\n type PairedBootstrapResult,\n pairedBootstrap,\n} from '../../statistics'\nimport type { JudgeScore } from '../types'\n\n/** Tie fraction at/above which a gate annotates its verdict with the tie share.\n * Tie-domination of the median bites structurally at >= 0.5 (the median is then\n * 0 by construction); 0.4 is a softer warn threshold that flags a run APPROACHING\n * that regime, so an operator sees it before the median goes fully blind. */\nexport const TIE_WARN_FRACTION = 0.4\n\nexport interface PairedHoldout {\n /** Baseline scalar per paired cell (same order as `after`/`cellIds`). */\n before: number[]\n /** Candidate scalar per paired cell. */\n after: number[]\n /** The full cellIds (`scenario:rep`) that paired, in order. */\n cellIds: string[]\n}\n\n/** Campaign cell IDs append a numeric repetition after the scenario's full ID. */\nfunction scenarioIdFromCellId(cellId: string): string {\n const separator = cellId.lastIndexOf(':')\n const repetition = cellId.slice(separator + 1)\n if (\n separator < 1 ||\n cellId.trim() !== cellId ||\n !/^(0|[1-9]\\d*)$/.test(repetition) ||\n !Number.isSafeInteger(Number(repetition))\n ) {\n throw new Error(`pairHoldout: malformed cellId '${cellId}'; expected scenarioId:rep`)\n }\n return cellId.slice(0, separator)\n}\n\n/** Preserve cell pairing before taking equal-weight independent-unit means. */\nexport function aggregatePairedHoldout(\n paired: PairedHoldout,\n independentUnitByScenarioId?: ReadonlyMap<string, string>,\n): { before: number[]; after: number[]; unitIds: string[] } {\n if (\n paired.before.length !== paired.after.length ||\n paired.before.length !== paired.cellIds.length\n ) {\n throw new Error('aggregatePairedHoldout: scores and cellIds must have the same length')\n }\n if (new Set(paired.cellIds).size !== paired.cellIds.length) {\n throw new Error('aggregatePairedHoldout: duplicate cellIds cannot count as new observations')\n }\n if (\n paired.before.some((value) => !Number.isFinite(value)) ||\n paired.after.some((value) => !Number.isFinite(value))\n ) {\n throw new Error('aggregatePairedHoldout: paired scores must be finite')\n }\n if (independentUnitByScenarioId === undefined) {\n return { before: [...paired.before], after: [...paired.after], unitIds: [...paired.cellIds] }\n }\n const scenarioIds = paired.cellIds.map(scenarioIdFromCellId)\n const groups = new Map<string, { before: number; after: number; n: number }>()\n for (let i = 0; i < paired.cellIds.length; i++) {\n const scenarioId = scenarioIds[i]!\n const unitId = independentUnitByScenarioId.get(scenarioId)\n if (typeof unitId !== 'string' || unitId.length === 0 || unitId.trim() !== unitId) {\n throw new Error(\n `aggregatePairedHoldout: missing independent unit for scenario '${scenarioId}'`,\n )\n }\n const group = groups.get(unitId) ?? { before: 0, after: 0, n: 0 }\n group.before += paired.before[i]!\n group.after += paired.after[i]!\n group.n += 1\n groups.set(unitId, group)\n }\n const unitIds = [...groups.keys()].sort()\n return {\n before: unitIds.map((id) => groups.get(id)!.before / groups.get(id)!.n),\n after: unitIds.map((id) => groups.get(id)!.after / groups.get(id)!.n),\n unitIds,\n }\n}\n\n/**\n * Pair candidate vs baseline holdout observations by FULL cellId. `select`\n * pulls the scalar from a cell's judge reports (composite, or a named\n * dimension); a cell contributes the mean of `select` across its judges. Cells\n * whose scenario is not in `scenarioIds`, or where `select` is undefined for\n * every judge on both sides, are skipped. The selected judge IDs must agree\n * within each pair. Throws when the two maps disagree on holdout cell IDs — a\n * load-bearing invariant: the baseline + winner holdout campaigns run the same\n * scenarios with the same seed base, so their cellIds MUST align; a mismatch\n * means a silent pairing bug, not a soft fallback.\n */\nexport function pairHoldout(\n candidate: Map<string, Record<string, JudgeScore>>,\n baseline: Map<string, Record<string, JudgeScore>>,\n scenarioIds: Set<string>,\n select: (s: JudgeScore) => number | undefined,\n): PairedHoldout {\n const cellValues = (\n byCell: Map<string, Record<string, JudgeScore>>,\n cellId: string,\n ): Map<string, number> => {\n const scores = byCell.get(cellId)\n const values = new Map<string, number>()\n if (!scores) return values\n for (const [judgeId, s] of Object.entries(scores)) {\n if (s.failed === true) {\n throw new Error(`pairHoldout: cell '${cellId}' contains a failed judge score`)\n }\n const v = select(s)\n if (typeof v === 'number' && !Number.isFinite(v)) {\n throw new Error(`pairHoldout: cell '${cellId}' contains a non-finite selected score`)\n }\n if (typeof v === 'number') values.set(judgeId, v)\n }\n return values\n }\n\n const inScope = (cellId: string) => scenarioIds.has(scenarioIdFromCellId(cellId))\n const candCells = [...candidate.keys()].filter(inScope).sort()\n const baseCells = [...baseline.keys()].filter(inScope).sort()\n // Alignment invariant — the holdout campaigns share scenarios + seed, so the\n // cell sets must be identical. Differ ⇒ a real pairing bug; fail loud.\n if (candCells.length !== baseCells.length || candCells.some((c, i) => c !== baseCells[i])) {\n throw new Error(\n `pairHoldout: candidate/baseline holdout cells do not align — ` +\n `candidate=[${candCells.join(',')}] baseline=[${baseCells.join(',')}]. ` +\n `Both holdout campaigns must run the same scenarios with the same seed base.`,\n )\n }\n\n const before: number[] = []\n const after: number[] = []\n const cellIds: string[] = []\n for (const cellId of candCells) {\n const b = cellValues(baseline, cellId)\n const a = cellValues(candidate, cellId)\n // A scalar absent on both sides means that dimension was not scored. A\n // one-sided absence is asymmetric evidence loss, never a row to discard.\n if (b.size === 0 && a.size === 0) continue\n if (b.size === 0 || a.size === 0) {\n throw new Error(`pairHoldout: cell '${cellId}' has a selected score on only one arm`)\n }\n if (b.size !== a.size || [...b.keys()].some((id) => !a.has(id))) {\n throw new Error(`pairHoldout: cell '${cellId}' selected judge IDs do not align`)\n }\n const judgeIds = [...b.keys()].sort()\n before.push(meanSelectedScores(judgeIds.map((id) => b.get(id)!)))\n after.push(meanSelectedScores(judgeIds.map((id) => a.get(id)!)))\n cellIds.push(cellId)\n }\n return { before, after, cellIds }\n}\n\nfunction meanSelectedScores(values: number[]): number {\n const first = values[0]!\n // Summing identical fractional scores can round their mean outside the\n // declared binary support. An agreeing judge set preserves its exact value.\n return values.every((value) => value === first)\n ? first\n : values.reduce((sum, value) => sum + value, 0) / values.length\n}\n\nexport interface HeldoutSignificance {\n paired: PairedHoldout\n /**\n * The paired bootstrap on the requested statistic (MEAN by default — see the\n * tie note on `heldoutSignificance`).\n *\n * DIAGNOSTIC, not necessarily the interval the verdict keyed on. On a\n * two-point (pass/fail) outcome the decision routes to Tango's score interval\n * instead, because a percentile bootstrap of the mean over a three-atom\n * lattice is not a valid interval at a nonzero margin. Read\n * `decision.low`/`decision.high` for the interval that actually decided, and\n * `decisionStatistic` for which one it is.\n */\n bootstrap: PairedBootstrapResult\n /** The MEDIAN paired-delta bootstrap, reported as a diagnostic. When many\n * scenarios are tied (both sides solve them), the median is pinned near 0\n * regardless of the mean lift — comparing the two exposes tie-domination. */\n medianBootstrap: PairedBootstrapResult\n /**\n * The full promotion decision: which estimator the outcome's shape admits,\n * the interval it produced, McNemar's exact veto on the two-point path, and\n * whether the interval was zero-width (no evidence in either direction). The\n * single source of `significant`.\n */\n decision: PairedPromotionDecision\n /** Which paired estimator the verdict was decided on. */\n decisionStatistic: PairedDecisionStatistic\n /** McNemar's exact evidence on the two-point path; null otherwise. */\n mcnemar: PairedMcNemarEvidence | null\n /** Fraction of paired observations that are exact ties (|delta| < 1e-9). A\n * high tie fraction is WHY a median-based gate would have missed a real lift;\n * it is the observability the tie fix adds. */\n tieFraction: number\n /** Number of paired observation units, after configured aggregation. */\n n: number\n /** Original matched execution cells, before aggregation. */\n pairedCellN: number\n observationUnit: 'registered' | 'cell'\n /** Registered unit IDs, or cell IDs on the ungrouped path. */\n unitIds: string[]\n /** Effective minimum for the requested target and chosen estimator. */\n minimumRequired: number\n /** Statistical method that carried the decision. */\n decisionMethod: PairedDecisionMethod\n /** Exact one-sided p-value on the small-sample path; otherwise null. */\n pValue: number | null\n /** True iff n >= minimumRequired, the DECIDING interval has nonzero width,\n * its lower bound clears the threshold, and McNemar's exact test does not\n * veto at a non-negative threshold. */\n significant: boolean\n /** Set when n < minimumRequired — too little evidence to claim significance. */\n fewRuns: boolean\n}\n\nexport interface HeldoutSignificanceOptions {\n deltaThreshold?: number\n minProductiveRuns?: number\n confidence?: number\n resamples?: number\n /** Fixed by default for a deterministic, reproducible gate verdict. */\n seed?: number\n statistic?: 'mean' | 'median'\n /** Group full cell pairs into equal-weight independent units before inference. */\n independentUnitByScenarioId?: ReadonlyMap<string, string>\n}\n\n/**\n * Significance of the held-out composite lift: ship only when the lower bound\n * of the interval the outcome's shape ADMITS exceeds `deltaThreshold` (default\n * 0 ⇒ \"confidently positive\"). Interpret `deltaThreshold` in the judge's native\n * scale.\n *\n * The decision is delegated whole to {@link decidePairedPromotion}, the one\n * copy of the rule (`src/paired-promotion-decision.ts`), which `HeldOutGate`\n * also calls. That module's header carries the measurements; the short version\n * is three guards a bare `bootstrap.low > threshold` does not have:\n *\n * - a two-point (pass/fail) outcome decides on Tango's SCORE interval, the\n * only paired-binary construction that stays valid at a nonzero margin;\n * - McNemar's exact test VETOES at any non-negative threshold;\n * - a ZERO-WIDTH interval is refused rather than promoted, in either\n * direction — [0,0] clears every negative threshold and [g,g] clears every\n * threshold below g, and both are an absence of evidence, not a result.\n *\n * Measured on this function before those guards landed, at a nominal 5 %:\n * 14.60 % false promotion at n = 40 on a paired-binary noninferiority boundary,\n * and 88.50 % at n = 6 under a bounded asymmetric null whose true mean paired\n * delta is exactly 0.\n *\n * Continuous mean targets require bootstrap eligibility. Explicit median\n * targets can use the exact sign test at its confidence-dependent minimum.\n */\nexport function heldoutSignificance(\n paired: PairedHoldout,\n opts: HeldoutSignificanceOptions = {},\n): HeldoutSignificance {\n const deltaThreshold = opts.deltaThreshold ?? 0\n const confidence = opts.confidence ?? 0.95\n const resamples = opts.resamples ?? 2000\n const seed = opts.seed ?? 1337\n // DEFAULT to the MEAN paired delta, not the median. The median is destroyed by\n // TIES: whenever both baseline and candidate solve a holdout scenario (a common\n // case once the agent is decent — and INCREASINGLY common as you add holdout\n // scenarios for statistical power), that scenario contributes delta 0. When\n // >=50% of paired cells are ties the median is pinned at 0 regardless of a large,\n // consistent lift on the rest, and the gate holds a genuinely better candidate.\n // (Measured live, supervisor-lab run 6: 40 cells, 20 ties, MEAN +0.177, MEDIAN 0\n // → false hold. Doubling the holdout for \"power\" made it WORSE by adding ties.)\n // The mean equals the reported aggregate lift, ties correctly contribute 0\n // without dominating, and it is the textbook paired-comparison estimator; the\n // median is kept as a reported diagnostic. Callers wanting outlier-robustness at\n // the cost of tie-blindness can still pass `statistic: 'median'`.\n const statistic = opts.statistic ?? 'mean'\n const observations = aggregatePairedHoldout(paired, opts.independentUnitByScenarioId)\n const decision = decidePairedPromotion(observations.before, observations.after, {\n confidence,\n resamples,\n statistic,\n seed,\n threshold: deltaThreshold,\n minPairs: opts.minProductiveRuns,\n })\n // `decision.bootstrap` is null exactly when the score interval decided, so\n // the requested-statistic bootstrap is computed here for the diagnostic\n // field. Same two bootstraps as before on every path.\n const bootstrap =\n decision.bootstrap ??\n pairedBootstrap(observations.before, observations.after, {\n confidence,\n resamples,\n statistic,\n seed,\n })\n const medianBootstrap =\n statistic === 'median'\n ? bootstrap\n : pairedBootstrap(observations.before, observations.after, {\n confidence,\n resamples,\n statistic: 'median',\n seed,\n })\n const n = observations.before.length\n let ties = 0\n for (let i = 0; i < n; i += 1) {\n const after = observations.after[i]!\n const before = observations.before[i]!\n if (Math.abs(after - before) < 1e-9) ties += 1\n }\n const tieFraction = n === 0 ? 0 : ties / n\n return {\n paired,\n bootstrap,\n medianBootstrap,\n decision,\n decisionStatistic: decision.statistic,\n mcnemar: decision.mcnemar,\n tieFraction,\n n,\n pairedCellN: paired.cellIds.length,\n observationUnit: opts.independentUnitByScenarioId === undefined ? 'cell' : 'registered',\n unitIds: observations.unitIds,\n minimumRequired: decision.minimumPairs,\n decisionMethod: decision.method,\n pValue: decision.pValue,\n significant: decision.promote,\n fewRuns: !decision.sufficient,\n }\n}\n\nexport interface DimensionRegression {\n dimension: string\n /** Paired bootstrap on (candidate − baseline). DIAGNOSTIC on a pass/fail\n * dimension, where `ci` carries the interval that decided instead. */\n bootstrap: PairedBootstrapResult\n /** Which paired statistic `bootstrap.low` is the lower bound of. `'mean'`\n * unless the caller asked for the median. `bootstrap.median` still carries\n * the median point estimate either way. */\n bootstrapStatistic: 'median' | 'mean'\n /** The interval `regressed` was decided on, in the dimension'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 dimension; null otherwise. */\n mcnemar: PairedMcNemarEvidence | null\n /** `ci` has zero width — no evidence in either direction. */\n indeterminate: boolean\n /** The bootstrap lower bound is below negative tolerance, or the shared\n * paired test supports a drop exceeding tolerance. Missing coverage and\n * insufficient observations are reported separately. */\n regressed: boolean\n tolerance: number\n n: number\n pairedCellN: number\n observationUnit: 'registered' | 'cell'\n /** Statistical minimum for the configured independent observation unit. */\n minimumRequired: number\n fewRuns: boolean\n /** Both arms lack this dimension on these otherwise matched execution cells. */\n missingCellIds: string[]\n /** Configured scenarios with no paired dimension measurement at all. */\n missingScenarioIds: string[]\n}\n\n/** Detect the native scale of a set of scores: 0-100 when any magnitude clears\n * 1.5, else [0,1]. Used to auto-scale the regression tolerance so a default\n * expressed for [0,1] is not silently a no-op on a 0-100 dimension. */\nexport function detectScale(values: number[]): 1 | 100 {\n return values.some((v) => Math.abs(v) > 1.5) ? 100 : 1\n}\n\n/**\n * Report required-dimension evidence after full pairing and optional unit means.\n * A bootstrap floor breach or a shared paired test supporting a drop marks\n * regression. These two criteria are distinct; `ci` records the shared\n * estimator and `bootstrap` records the floor interval. Missing observations\n * and insufficient n remain explicit for the caller's evidence policy.\n * The default tolerance is 0.05 on [0,1] and 5 on a detected 0-100 scale.\n */\nexport function dimensionRegressions(\n candidate: Map<string, Record<string, JudgeScore>>,\n baseline: Map<string, Record<string, JudgeScore>>,\n scenarioIds: Set<string>,\n criticalDimensions: string[],\n opts: {\n tolerance?: number\n confidence?: number\n resamples?: number\n seed?: number\n /** Paired statistic the CI is computed on. Default `'mean'` — see\n * {@link DECISION_PAIRED_DELTA_STATISTIC} for why the median is not. */\n statistic?: 'mean' | 'median'\n independentUnitByScenarioId?: ReadonlyMap<string, string>\n minProductiveRuns?: number\n } = {},\n): DimensionRegression[] {\n const out: DimensionRegression[] = []\n const expectedCellIds = [...baseline.keys()]\n .filter((cellId) => scenarioIds.has(scenarioIdFromCellId(cellId)))\n .sort()\n for (const dim of criticalDimensions) {\n const paired = pairHoldout(candidate, baseline, scenarioIds, (s) => s.dimensions[dim])\n if (paired.before.length === 0) continue // dimension not scored on this judge\n const observations = aggregatePairedHoldout(paired, opts.independentUnitByScenarioId)\n const measuredCells = new Set(paired.cellIds)\n const measuredScenarios = new Set(paired.cellIds.map(scenarioIdFromCellId))\n const tolerance = opts.tolerance ?? 0.05 * detectScale([...paired.before, ...paired.after])\n const bootstrapStatistic = opts.statistic ?? DECISION_PAIRED_DELTA_STATISTIC\n const shared = {\n confidence: opts.confidence ?? 0.95,\n resamples: opts.resamples ?? 2000,\n statistic: bootstrapStatistic,\n seed: opts.seed ?? 1337,\n minPairs: opts.minProductiveRuns,\n }\n const guard = decidePairedPromotion(observations.before, observations.after, shared)\n const regression = decidePairedPromotion(observations.after, observations.before, {\n ...shared,\n threshold: tolerance,\n })\n const bootstrap =\n guard.bootstrap ?? pairedBootstrap(observations.before, observations.after, shared)\n out.push({\n dimension: dim,\n bootstrap,\n bootstrapStatistic,\n ci: { low: guard.low, high: guard.high },\n decisionStatistic: guard.statistic,\n mcnemar: guard.mcnemar,\n indeterminate: guard.indeterminate,\n // Fires on EITHER burden of proof — see `floorBreached` in\n // `promotion-policy.ts` for the same rule and the reasoning. The CI arm\n // is the contract this interface and `default-production-gate`'s reason\n // string both state (\"CI.low < -tolerance\"), read off the DECIDING\n // interval; the exact-test arm adds the small-sample path where the\n // bootstrap interval is descriptive only.\n // The credible-worst-case arm stays on the BOOTSTRAP — see the same\n // decision in `floorBreached` (`promotion-policy.ts`). On a pass/fail\n // dimension the score interval is ±z²/(n+z²) even when every pair is\n // concordant, so reading the floor off it would flag an unchanged safety\n // dimension as regressed at any realistic n. The PROVEN-drop arm does use\n // the shared rule, which is what closes the fail-open hole that mattered:\n // a genuine pass/fail regression is now judged on an interval valid at\n // the nonzero `tolerance`, instead of a bootstrap that is pinned wherever\n // ties dominate.\n regressed: bootstrap.low < -tolerance || regression.promote,\n tolerance,\n n: observations.before.length,\n pairedCellN: paired.cellIds.length,\n observationUnit: opts.independentUnitByScenarioId === undefined ? 'cell' : 'registered',\n minimumRequired: guard.minimumPairs,\n fewRuns: !guard.sufficient,\n missingCellIds: expectedCellIds.filter((cellId) => !measuredCells.has(cellId)),\n missingScenarioIds: [...scenarioIds].filter((id) => !measuredScenarios.has(id)).sort(),\n })\n }\n return out\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA6BA,MAAa,oBAAoB;;AAYjC,SAAS,qBAAqB,QAAwB;CACpD,MA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,QAAQ,WAAW,CAAC,cAAc,IAAI,MAAM,CAAC;GAC7E,oBAAoB,CAAC,GAAG,WAAW,CAAC,CAAC,QAAQ,OAAO,CAAC,kBAAkB,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK;EACvF,CAAC;CACH;CACA,OAAO;AACT"}
1
+ {"version":3,"file":"statistical-heldout-CL_7mI5C.js","names":[],"sources":["../src/campaign/gates/statistical-heldout.ts"],"sourcesContent":["/**\n * Held-out inference pairs execution cells and judge identities before taking\n * means within registered independent units. Repetitions can improve a unit's\n * precision without increasing n. Ungrouped inference concerns independently\n * sampled execution cells conditional on a fixed scenario roster.\n *\n * The shared paired decision rule selects the estimator and statistical test.\n * Dimension reports retain missing coverage so required safety checks cannot\n * pass through absent evidence. Thresholds use the judge's native score scale.\n */\n\nimport {\n decidePairedPromotion,\n type PairedDecisionMethod,\n type PairedDecisionStatistic,\n type PairedMcNemarEvidence,\n type PairedPromotionDecision,\n} from '../../paired-promotion-decision'\nimport {\n DECISION_PAIRED_DELTA_STATISTIC,\n type PairedBootstrapResult,\n pairedBootstrap,\n} from '../../statistics'\nimport type { JudgeScore } from '../types'\n\n/** Tie fraction at/above which a gate annotates its verdict with the tie share.\n * Tie-domination of the median bites structurally at >= 0.5 (the median is then\n * 0 by construction); 0.4 is a softer warn threshold that flags a run APPROACHING\n * that regime, so an operator sees it before the median goes fully blind. */\nexport const TIE_WARN_FRACTION = 0.4\n\nexport interface PairedHoldout {\n /** Baseline scalar per paired cell (same order as `after`/`cellIds`). */\n before: number[]\n /** Candidate scalar per paired cell. */\n after: number[]\n /** The full cellIds (`scenario:rep`) that paired, in order. */\n cellIds: string[]\n}\n\n/** Campaign cell IDs append a numeric repetition after the scenario's full ID. */\nfunction scenarioIdFromCellId(cellId: string): string {\n const separator = cellId.lastIndexOf(':')\n const repetition = cellId.slice(separator + 1)\n if (\n separator < 1 ||\n cellId.trim() !== cellId ||\n !/^(0|[1-9]\\d*)$/.test(repetition) ||\n !Number.isSafeInteger(Number(repetition))\n ) {\n throw new Error(`pairHoldout: malformed cellId '${cellId}'; expected scenarioId:rep`)\n }\n return cellId.slice(0, separator)\n}\n\n/** Preserve cell pairing before taking equal-weight independent-unit means. */\nexport function aggregatePairedHoldout(\n paired: PairedHoldout,\n independentUnitByScenarioId?: ReadonlyMap<string, string>,\n): { before: number[]; after: number[]; unitIds: string[] } {\n if (\n paired.before.length !== paired.after.length ||\n paired.before.length !== paired.cellIds.length\n ) {\n throw new Error('aggregatePairedHoldout: scores and cellIds must have the same length')\n }\n if (new Set(paired.cellIds).size !== paired.cellIds.length) {\n throw new Error('aggregatePairedHoldout: duplicate cellIds cannot count as new observations')\n }\n if (\n paired.before.some((value) => !Number.isFinite(value)) ||\n paired.after.some((value) => !Number.isFinite(value))\n ) {\n throw new Error('aggregatePairedHoldout: paired scores must be finite')\n }\n if (independentUnitByScenarioId === undefined) {\n return { before: [...paired.before], after: [...paired.after], unitIds: [...paired.cellIds] }\n }\n const scenarioIds = paired.cellIds.map(scenarioIdFromCellId)\n const groups = new Map<string, { before: number; after: number; n: number }>()\n for (let i = 0; i < paired.cellIds.length; i++) {\n const scenarioId = scenarioIds[i]!\n const unitId = independentUnitByScenarioId.get(scenarioId)\n if (typeof unitId !== 'string' || unitId.length === 0 || unitId.trim() !== unitId) {\n throw new Error(\n `aggregatePairedHoldout: missing independent unit for scenario '${scenarioId}'`,\n )\n }\n const group = groups.get(unitId) ?? { before: 0, after: 0, n: 0 }\n group.before += paired.before[i]!\n group.after += paired.after[i]!\n group.n += 1\n groups.set(unitId, group)\n }\n const unitIds = [...groups.keys()].sort()\n return {\n before: unitIds.map((id) => groups.get(id)!.before / groups.get(id)!.n),\n after: unitIds.map((id) => groups.get(id)!.after / groups.get(id)!.n),\n unitIds,\n }\n}\n\n/**\n * Pair candidate vs baseline holdout observations by FULL cellId. `select`\n * pulls the scalar from a cell's judge reports (composite, or a named\n * dimension); a cell contributes the mean of `select` across its judges. Cells\n * whose scenario is not in `scenarioIds`, or where `select` is undefined for\n * every judge on both sides, are skipped. The selected judge IDs must agree\n * within each pair. Throws when the two maps disagree on holdout cell IDs — a\n * load-bearing invariant: the baseline + winner holdout campaigns run the same\n * scenarios with the same seed base, so their cellIds MUST align; a mismatch\n * means a silent pairing bug, not a soft fallback.\n */\nexport function pairHoldout(\n candidate: Map<string, Record<string, JudgeScore>>,\n baseline: Map<string, Record<string, JudgeScore>>,\n scenarioIds: Set<string>,\n select: (s: JudgeScore) => number | undefined,\n): PairedHoldout {\n const cellValues = (\n byCell: Map<string, Record<string, JudgeScore>>,\n cellId: string,\n ): Map<string, number> => {\n const scores = byCell.get(cellId)\n const values = new Map<string, number>()\n if (!scores) return values\n for (const [judgeId, s] of Object.entries(scores)) {\n if (s.failed === true) {\n throw new Error(`pairHoldout: cell '${cellId}' contains a failed judge score`)\n }\n const v = select(s)\n if (typeof v === 'number' && !Number.isFinite(v)) {\n throw new Error(`pairHoldout: cell '${cellId}' contains a non-finite selected score`)\n }\n if (typeof v === 'number') values.set(judgeId, v)\n }\n return values\n }\n\n const inScope = (cellId: string) => scenarioIds.has(scenarioIdFromCellId(cellId))\n const candCells = [...candidate.keys()].filter(inScope).sort()\n const baseCells = [...baseline.keys()].filter(inScope).sort()\n // Alignment invariant — the holdout campaigns share scenarios + seed, so the\n // cell sets must be identical. Differ ⇒ a real pairing bug; fail loud.\n if (candCells.length !== baseCells.length || candCells.some((c, i) => c !== baseCells[i])) {\n throw new Error(\n `pairHoldout: candidate/baseline holdout cells do not align — ` +\n `candidate=[${candCells.join(',')}] baseline=[${baseCells.join(',')}]. ` +\n `Both holdout campaigns must run the same scenarios with the same seed base.`,\n )\n }\n\n const before: number[] = []\n const after: number[] = []\n const cellIds: string[] = []\n for (const cellId of candCells) {\n const b = cellValues(baseline, cellId)\n const a = cellValues(candidate, cellId)\n // A scalar absent on both sides means that dimension was not scored. A\n // one-sided absence is asymmetric evidence loss, never a row to discard.\n if (b.size === 0 && a.size === 0) continue\n if (b.size === 0 || a.size === 0) {\n throw new Error(`pairHoldout: cell '${cellId}' has a selected score on only one arm`)\n }\n if (b.size !== a.size || [...b.keys()].some((id) => !a.has(id))) {\n throw new Error(`pairHoldout: cell '${cellId}' selected judge IDs do not align`)\n }\n const judgeIds = [...b.keys()].sort()\n before.push(meanSelectedScores(judgeIds.map((id) => b.get(id)!)))\n after.push(meanSelectedScores(judgeIds.map((id) => a.get(id)!)))\n cellIds.push(cellId)\n }\n return { before, after, cellIds }\n}\n\nfunction meanSelectedScores(values: number[]): number {\n const first = values[0]!\n // Summing identical fractional scores can round their mean outside the\n // declared binary support. An agreeing judge set preserves its exact value.\n return values.every((value) => value === first)\n ? first\n : values.reduce((sum, value) => sum + value, 0) / values.length\n}\n\nexport interface HeldoutSignificance {\n paired: PairedHoldout\n /**\n * The paired bootstrap on the requested statistic (MEAN by default — see the\n * tie note on `heldoutSignificance`).\n *\n * DIAGNOSTIC, not necessarily the interval the verdict keyed on. On a\n * two-point (pass/fail) outcome the decision routes to Tango's score interval\n * instead, because a percentile bootstrap of the mean over a three-atom\n * lattice is not a valid interval at a nonzero margin. Read\n * `decision.low`/`decision.high` for the interval that actually decided, and\n * `decisionStatistic` for which one it is.\n */\n bootstrap: PairedBootstrapResult\n /** The MEDIAN paired-delta bootstrap, reported as a diagnostic. When many\n * scenarios are tied (both sides solve them), the median is pinned near 0\n * regardless of the mean lift — comparing the two exposes tie-domination. */\n medianBootstrap: PairedBootstrapResult\n /**\n * The full promotion decision: which estimator the outcome's shape admits,\n * the interval it produced, McNemar's exact veto on the two-point path, and\n * whether the interval was zero-width (no evidence in either direction). The\n * single source of `significant`.\n */\n decision: PairedPromotionDecision\n /** Which paired estimator the verdict was decided on. */\n decisionStatistic: PairedDecisionStatistic\n /** McNemar's exact evidence on the two-point path; null otherwise. */\n mcnemar: PairedMcNemarEvidence | null\n /** Fraction of paired observations that are exact ties (|delta| < 1e-9). A\n * high tie fraction is WHY a median-based gate would have missed a real lift;\n * it is the observability the tie fix adds. */\n tieFraction: number\n /** Number of paired observation units, after configured aggregation. */\n n: number\n /** Original matched execution cells, before aggregation. */\n pairedCellN: number\n observationUnit: 'registered' | 'cell'\n /** Registered unit IDs, or cell IDs on the ungrouped path. */\n unitIds: string[]\n /** Effective minimum for the requested target and chosen estimator. */\n minimumRequired: number\n /** Statistical method that carried the decision. */\n decisionMethod: PairedDecisionMethod\n /** Exact one-sided p-value on the small-sample path; otherwise null. */\n pValue: number | null\n /** True iff n >= minimumRequired, the DECIDING interval has nonzero width,\n * its lower bound clears the threshold, and McNemar's exact test does not\n * veto at a non-negative threshold. */\n significant: boolean\n /** Set when n < minimumRequired — too little evidence to claim significance. */\n fewRuns: boolean\n}\n\nexport interface HeldoutSignificanceOptions {\n deltaThreshold?: number\n minProductiveRuns?: number\n confidence?: number\n resamples?: number\n /** Fixed by default for a deterministic, reproducible gate verdict. */\n seed?: number\n statistic?: 'mean' | 'median'\n /** Group full cell pairs into equal-weight independent units before inference. */\n independentUnitByScenarioId?: ReadonlyMap<string, string>\n}\n\n/**\n * Significance of the held-out composite lift: ship only when the lower bound\n * of the interval the outcome's shape ADMITS exceeds `deltaThreshold` (default\n * 0 ⇒ \"confidently positive\"). Interpret `deltaThreshold` in the judge's native\n * scale.\n *\n * The decision is delegated whole to {@link decidePairedPromotion}, the one\n * copy of the rule (`src/paired-promotion-decision.ts`), which `HeldOutGate`\n * also calls. That module's header carries the measurements; the short version\n * is three guards a bare `bootstrap.low > threshold` does not have:\n *\n * - a two-point (pass/fail) outcome decides on Tango's SCORE interval, the\n * only paired-binary construction that stays valid at a nonzero margin;\n * - McNemar's exact test VETOES at any non-negative threshold;\n * - a ZERO-WIDTH interval is refused rather than promoted, in either\n * direction — [0,0] clears every negative threshold and [g,g] clears every\n * threshold below g, and both are an absence of evidence, not a result.\n *\n * Measured on this function before those guards landed, at a nominal 5 %:\n * 14.60 % false promotion at n = 40 on a paired-binary noninferiority boundary,\n * and 88.50 % at n = 6 under a bounded asymmetric null whose true mean paired\n * delta is exactly 0.\n *\n * Continuous mean targets require bootstrap eligibility. Explicit median\n * targets can use the exact sign test at its confidence-dependent minimum.\n */\nexport function heldoutSignificance(\n paired: PairedHoldout,\n opts: HeldoutSignificanceOptions = {},\n): HeldoutSignificance {\n const deltaThreshold = opts.deltaThreshold ?? 0\n const confidence = opts.confidence ?? 0.95\n const resamples = opts.resamples ?? 2000\n const seed = opts.seed ?? 1337\n // DEFAULT to the MEAN paired delta, not the median. The median is destroyed by\n // TIES: whenever both baseline and candidate solve a holdout scenario (a common\n // case once the agent is decent — and INCREASINGLY common as you add holdout\n // scenarios for statistical power), that scenario contributes delta 0. When\n // >=50% of paired cells are ties the median is pinned at 0 regardless of a large,\n // consistent lift on the rest, and the gate holds a genuinely better candidate.\n // (Measured live, supervisor-lab run 6: 40 cells, 20 ties, MEAN +0.177, MEDIAN 0\n // → false hold. Doubling the holdout for \"power\" made it WORSE by adding ties.)\n // The mean equals the reported aggregate lift, ties correctly contribute 0\n // without dominating, and it is the textbook paired-comparison estimator; the\n // median is kept as a reported diagnostic. Callers wanting outlier-robustness at\n // the cost of tie-blindness can still pass `statistic: 'median'`.\n const statistic = opts.statistic ?? 'mean'\n const observations = aggregatePairedHoldout(paired, opts.independentUnitByScenarioId)\n const decision = decidePairedPromotion(observations.before, observations.after, {\n confidence,\n resamples,\n statistic,\n seed,\n threshold: deltaThreshold,\n minPairs: opts.minProductiveRuns,\n })\n // `decision.bootstrap` is null exactly when the score interval decided, so\n // the requested-statistic bootstrap is computed here for the diagnostic\n // field. Same two bootstraps as before on every path.\n const bootstrap =\n decision.bootstrap ??\n pairedBootstrap(observations.before, observations.after, {\n confidence,\n resamples,\n statistic,\n seed,\n })\n const medianBootstrap =\n statistic === 'median'\n ? bootstrap\n : pairedBootstrap(observations.before, observations.after, {\n confidence,\n resamples,\n statistic: 'median',\n seed,\n })\n const n = observations.before.length\n let ties = 0\n for (let i = 0; i < n; i += 1) {\n const after = observations.after[i]!\n const before = observations.before[i]!\n if (Math.abs(after - before) < 1e-9) ties += 1\n }\n const tieFraction = n === 0 ? 0 : ties / n\n return {\n paired,\n bootstrap,\n medianBootstrap,\n decision,\n decisionStatistic: decision.statistic,\n mcnemar: decision.mcnemar,\n tieFraction,\n n,\n pairedCellN: paired.cellIds.length,\n observationUnit: opts.independentUnitByScenarioId === undefined ? 'cell' : 'registered',\n unitIds: observations.unitIds,\n minimumRequired: decision.minimumPairs,\n decisionMethod: decision.method,\n pValue: decision.pValue,\n significant: decision.promote,\n fewRuns: !decision.sufficient,\n }\n}\n\nexport interface DimensionRegression {\n dimension: string\n /** Paired bootstrap on (candidate − baseline). DIAGNOSTIC on a pass/fail\n * dimension, where `ci` carries the interval that decided instead. */\n bootstrap: PairedBootstrapResult\n /** Which paired statistic `bootstrap.low` is the lower bound of. `'mean'`\n * unless the caller asked for the median. `bootstrap.median` still carries\n * the median point estimate either way. */\n bootstrapStatistic: 'median' | 'mean'\n /** The interval `regressed` was decided on, in the dimension'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 dimension; null otherwise. */\n mcnemar: PairedMcNemarEvidence | null\n /** `ci` has zero width — no evidence in either direction. */\n indeterminate: boolean\n /** The bootstrap lower bound is below negative tolerance, or the shared\n * paired test supports a drop exceeding tolerance. Missing coverage and\n * insufficient observations are reported separately. */\n regressed: boolean\n tolerance: number\n n: number\n pairedCellN: number\n observationUnit: 'registered' | 'cell'\n /** Statistical minimum for the configured independent observation unit. */\n minimumRequired: number\n fewRuns: boolean\n /** Both arms lack this dimension on these otherwise matched execution cells. */\n missingCellIds: string[]\n /** Configured scenarios with no paired dimension measurement at all. */\n missingScenarioIds: string[]\n}\n\n/** Detect the native scale of a set of scores: 0-100 when any magnitude clears\n * 1.5, else [0,1]. Used to auto-scale the regression tolerance so a default\n * expressed for [0,1] is not silently a no-op on a 0-100 dimension. */\nexport function detectScale(values: number[]): 1 | 100 {\n return values.some((v) => Math.abs(v) > 1.5) ? 100 : 1\n}\n\n/**\n * Report required-dimension evidence after full pairing and optional unit means.\n * A bootstrap floor breach or a shared paired test supporting a drop marks\n * regression. These two criteria are distinct; `ci` records the shared\n * estimator and `bootstrap` records the floor interval. Missing observations\n * and insufficient n remain explicit for the caller's evidence policy.\n * The default tolerance is 0.05 on [0,1] and 5 on a detected 0-100 scale.\n */\nexport function dimensionRegressions(\n candidate: Map<string, Record<string, JudgeScore>>,\n baseline: Map<string, Record<string, JudgeScore>>,\n scenarioIds: Set<string>,\n criticalDimensions: string[],\n opts: {\n tolerance?: number\n confidence?: number\n resamples?: number\n seed?: number\n /** Paired statistic the CI is computed on. Default `'mean'` — see\n * {@link DECISION_PAIRED_DELTA_STATISTIC} for why the median is not. */\n statistic?: 'mean' | 'median'\n independentUnitByScenarioId?: ReadonlyMap<string, string>\n minProductiveRuns?: number\n } = {},\n): DimensionRegression[] {\n const out: DimensionRegression[] = []\n const expectedCellIds = [...baseline.keys()]\n .filter((cellId) => scenarioIds.has(scenarioIdFromCellId(cellId)))\n .sort()\n for (const dim of criticalDimensions) {\n const paired = pairHoldout(candidate, baseline, scenarioIds, (s) => s.dimensions[dim])\n if (paired.before.length === 0) continue // dimension not scored on this judge\n const observations = aggregatePairedHoldout(paired, opts.independentUnitByScenarioId)\n const measuredCells = new Set(paired.cellIds)\n const measuredScenarios = new Set(paired.cellIds.map(scenarioIdFromCellId))\n const tolerance = opts.tolerance ?? 0.05 * detectScale([...paired.before, ...paired.after])\n const bootstrapStatistic = opts.statistic ?? DECISION_PAIRED_DELTA_STATISTIC\n const shared = {\n confidence: opts.confidence ?? 0.95,\n resamples: opts.resamples ?? 2000,\n statistic: bootstrapStatistic,\n seed: opts.seed ?? 1337,\n minPairs: opts.minProductiveRuns,\n }\n const guard = decidePairedPromotion(observations.before, observations.after, shared)\n const regression = decidePairedPromotion(observations.after, observations.before, {\n ...shared,\n threshold: tolerance,\n })\n const bootstrap =\n guard.bootstrap ?? pairedBootstrap(observations.before, observations.after, shared)\n out.push({\n dimension: dim,\n bootstrap,\n bootstrapStatistic,\n ci: { low: guard.low, high: guard.high },\n decisionStatistic: guard.statistic,\n mcnemar: guard.mcnemar,\n indeterminate: guard.indeterminate,\n // Fires on EITHER burden of proof — see `floorBreached` in\n // `promotion-policy.ts` for the same rule and the reasoning. The CI arm\n // is the contract this interface and `default-production-gate`'s reason\n // string both state (\"CI.low < -tolerance\"), read off the DECIDING\n // interval; the exact-test arm adds the small-sample path where the\n // bootstrap interval is descriptive only.\n // The credible-worst-case arm stays on the BOOTSTRAP — see the same\n // decision in `floorBreached` (`promotion-policy.ts`). On a pass/fail\n // dimension the score interval is ±z²/(n+z²) even when every pair is\n // concordant, so reading the floor off it would flag an unchanged safety\n // dimension as regressed at any realistic n. The PROVEN-drop arm does use\n // the shared rule, which is what closes the fail-open hole that mattered:\n // a genuine pass/fail regression is now judged on an interval valid at\n // the nonzero `tolerance`, instead of a bootstrap that is pinned wherever\n // ties dominate.\n regressed: bootstrap.low < -tolerance || regression.promote,\n tolerance,\n n: observations.before.length,\n pairedCellN: paired.cellIds.length,\n observationUnit: opts.independentUnitByScenarioId === undefined ? 'cell' : 'registered',\n minimumRequired: guard.minimumPairs,\n fewRuns: !guard.sufficient,\n missingCellIds: expectedCellIds.filter((cellId) => !measuredCells.has(cellId)),\n missingScenarioIds: [...scenarioIds].filter((id) => !measuredScenarios.has(id)).sort(),\n })\n }\n return out\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA6BA,MAAa,oBAAoB;;AAYjC,SAAS,qBAAqB,QAAwB;CACpD,MAAM,YAAY,OAAO,YAAY,GAAG;CACxC,MAAM,aAAa,OAAO,MAAM,YAAY,CAAC;CAC7C,IACE,YAAY,KACZ,OAAO,KAAK,MAAM,UAClB,CAAC,iBAAiB,KAAK,UAAU,KACjC,CAAC,OAAO,cAAc,OAAO,UAAU,CAAC,GAExC,MAAM,IAAI,MAAM,kCAAkC,OAAO,2BAA2B;CAEtF,OAAO,OAAO,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1)` for an estimate on the tested
611
611
  * side of the null, and 1 otherwise.
612
612
  *
613
- * The within-unit scope answers whether the score separates rows of the same
614
- * unit: AUC inside each unit weighted by its positive-negative pairs, or
615
- * Spearman inside each unit weighted by its row pairs, where a score constant
616
- * inside a unit counts as no association there.
613
+ * The stratified scope answers whether the score separates rows of the same
614
+ * stratum: AUC inside each stratum weighted by its positive-negative pairs, or
615
+ * Spearman inside each stratum weighted by its row pairs, where a score
616
+ * constant inside a stratum counts as no association there. A resample draws
617
+ * whole units and regroups their rows by stratum. The within-unit scope is the
618
+ * same statistic with each unit its own stratum, so a drawn unit is drawn with
619
+ * its stratum.
617
620
  */
618
621
  function clusteredAssociation(rows, options) {
619
622
  const { statistic } = options;
@@ -622,13 +625,14 @@ function clusteredAssociation(rows, options) {
622
625
  const resamples = options.resamples ?? 1e3;
623
626
  const confidence = options.confidence ?? .95;
624
627
  if (statistic !== "auc" && statistic !== "spearman") throw new ValidationError("clusteredAssociation: statistic must be auc or spearman");
625
- if (scope !== "pooled" && scope !== "within-unit") throw new ValidationError("clusteredAssociation: scope must be pooled or within-unit");
628
+ if (scope !== "pooled" && scope !== "within-unit" && scope !== "stratified") throw new ValidationError("clusteredAssociation: scope must be pooled, within-unit or stratified");
626
629
  if (alternative !== "two-sided" && alternative !== "greater") throw new ValidationError("clusteredAssociation: alternative must be two-sided or greater");
627
630
  if (!Number.isSafeInteger(resamples) || resamples < 1) throw new ValidationError("clusteredAssociation: resamples must be a positive safe integer");
628
631
  for (const [index, row] of rows.entries()) {
629
632
  if (!Number.isFinite(row.x) || !Number.isFinite(row.y)) throw new ValidationError(`clusteredAssociation: rows[${index}] must have finite x and y`);
630
633
  if (statistic === "auc" && row.y !== 0 && row.y !== 1) throw new ValidationError(`clusteredAssociation: rows[${index}].y must be 0 or 1 for auc`);
631
634
  if (typeof row.unit !== "string" || row.unit.length === 0) throw new ValidationError(`clusteredAssociation: rows[${index}].unit must be nonempty`);
635
+ if (scope === "stratified" && (typeof row.stratum !== "string" || row.stratum.length === 0)) throw new ValidationError(`clusteredAssociation: rows[${index}].stratum must be nonempty for the stratified scope`);
632
636
  }
633
637
  const seed = options.seed ?? seedFromData([rows.map((row) => row.x), rows.map((row) => row.y)]);
634
638
  const draws = [];
@@ -653,12 +657,27 @@ function clusteredAssociation(rows, options) {
653
657
  low: NaN,
654
658
  high: NaN
655
659
  };
656
- } else {
657
- const summaries = unitSummaries(statistic, rows);
660
+ } else if (scope === "within-unit") {
661
+ const summaries = stratumSummaries(statistic, rows, (row) => row.unit);
658
662
  estimate = weightedMean(summaries);
659
- n = summaries.reduce((sum, unit) => sum + unit.rows, 0);
663
+ n = summaries.reduce((sum, unit) => sum + unit.rows.length, 0);
660
664
  units = summaries.length;
661
- if (Number.isFinite(estimate) && units >= 2) interval = clusterBootstrap(summaries, (unit) => unit.unit, (sample) => record(weightedMean(sample)), {
665
+ if (Number.isFinite(estimate) && units >= 2) interval = clusterBootstrap(summaries, (unit) => unit.stratum, (sample) => record(weightedMean(sample)), {
666
+ resamples,
667
+ level: confidence,
668
+ seed
669
+ });
670
+ else interval = {
671
+ low: NaN,
672
+ high: NaN
673
+ };
674
+ } else {
675
+ const summaries = stratumSummaries(statistic, rows, (row) => row.stratum);
676
+ estimate = weightedMean(summaries);
677
+ const contributing = summaries.flatMap((stratum) => stratum.rows);
678
+ n = contributing.length;
679
+ units = new Set(contributing.map((row) => row.unit)).size;
680
+ if (Number.isFinite(estimate) && units >= 2) interval = clusterBootstrap(rows, (row) => row.unit, (sample) => record(weightedMean(stratumSummaries(statistic, sample, (row) => row.stratum))), {
662
681
  resamples,
663
682
  level: confidence,
664
683
  seed
@@ -668,7 +687,7 @@ function clusteredAssociation(rows, options) {
668
687
  high: NaN
669
688
  };
670
689
  }
671
- if (!Number.isFinite(estimate) || units < 2) throw new ValidationError(`clusteredAssociation: the ${scope} ${statistic} needs two units with both outcome classes for auc, or variation on both sides`);
690
+ if (!Number.isFinite(estimate) || units < 2) throw new ValidationError(`clusteredAssociation: the ${scope} ${statistic} needs two units with both outcome classes for auc, or variation on both sides, in a comparable unit or stratum`);
672
691
  const nullValue = statistic === "auc" ? .5 : 0;
673
692
  const standardError = sampleStandardDeviation(draws);
674
693
  const distance = estimate - nullValue;
@@ -694,48 +713,54 @@ function clusteredAssociation(rows, options) {
694
713
  };
695
714
  }
696
715
  /**
697
- * The point statistic alone, pooled across units or within them; NaN when it
698
- * is undefined on these rows. Within units it needs `unit` on every row.
716
+ * The point statistic alone, pooled, within units or within strata; NaN when
717
+ * it is undefined on these rows. Within units it needs `unit` on every row,
718
+ * within strata `stratum`.
699
719
  */
700
720
  function associationEstimate(statistic, rows, scope = "pooled") {
701
- if (scope === "within-unit") return weightedMean(unitSummaries(statistic, rows));
721
+ if (scope !== "pooled") {
722
+ const key = scope === "within-unit" ? "unit" : "stratum";
723
+ return weightedMean(stratumSummaries(statistic, rows, (row) => row[key]));
724
+ }
702
725
  const xs = rows.map((row) => row.x);
703
726
  const ys = rows.map((row) => row.y);
704
727
  if (statistic === "auc") return rocAuc(xs, ys) ?? NaN;
705
728
  if (!varies(xs) || !varies(ys)) return NaN;
706
729
  return spearmanR(xs, ys);
707
730
  }
708
- function unitSummaries(statistic, rows) {
709
- const byUnit = /* @__PURE__ */ new Map();
731
+ /** The statistic inside each stratum holding a comparable pair, with its pair-count weight. */
732
+ function stratumSummaries(statistic, rows, stratumOf) {
733
+ const byStratum = /* @__PURE__ */ new Map();
710
734
  for (const row of rows) {
711
- const unit = byUnit.get(row.unit) ?? {
712
- xs: [],
713
- ys: []
714
- };
715
- unit.xs.push(row.x);
716
- unit.ys.push(row.y);
717
- byUnit.set(row.unit, unit);
735
+ const key = stratumOf(row);
736
+ const members = byStratum.get(key);
737
+ if (members) members.push(row);
738
+ else byStratum.set(key, [row]);
718
739
  }
719
740
  const summaries = [];
720
- for (const [unit, { xs, ys }] of byUnit) if (statistic === "auc") {
721
- const positive = ys.reduce((sum, y) => sum + y, 0);
722
- const negative = ys.length - positive;
723
- const value = rocAuc(xs, ys);
724
- if (value === null) continue;
725
- summaries.push({
726
- unit,
727
- rows: ys.length,
728
- value,
729
- weight: positive * negative
730
- });
731
- } else {
732
- if (ys.length < 2 || !varies(ys)) continue;
733
- summaries.push({
734
- unit,
735
- rows: ys.length,
736
- value: varies(xs) ? spearmanR(xs, ys) : 0,
737
- weight: ys.length * (ys.length - 1) / 2
738
- });
741
+ for (const [stratum, members] of byStratum) {
742
+ const xs = members.map((row) => row.x);
743
+ const ys = members.map((row) => row.y);
744
+ if (statistic === "auc") {
745
+ const positive = ys.reduce((sum, y) => sum + y, 0);
746
+ const negative = ys.length - positive;
747
+ const value = rocAuc(xs, ys);
748
+ if (value === null) continue;
749
+ summaries.push({
750
+ stratum,
751
+ rows: members,
752
+ value,
753
+ weight: positive * negative
754
+ });
755
+ } else {
756
+ if (ys.length < 2 || !varies(ys)) continue;
757
+ summaries.push({
758
+ stratum,
759
+ rows: members,
760
+ value: varies(xs) ? spearmanR(xs, ys) : 0,
761
+ weight: ys.length * (ys.length - 1) / 2
762
+ });
763
+ }
739
764
  }
740
765
  return summaries;
741
766
  }
@@ -2321,4 +2346,4 @@ function assertResumable(resume, params) {
2321
2346
  }
2322
2347
  export { selfPreference as $, cliffsDelta as A, simulateClusteredBinaryContrast as B, chiSquared as C, normalTwoSidedPValue as D, linearRegressionSlope as E, summarizeDistribution as F, corpusInterRaterAgreement as G, clusteredAssociation as H, clusterJackknife as I, nominalAgreement as J, corpusInterRaterAgreementFromJudgeScores as K, clusterSignFlipTest as L, interpretCliffs as M, pairedCohensDz as N, studentTTwoSidedPValue as O, percentileNearestRank as P, positionalBias as Q, clusteredBinaryMde as R, holm as S, fisherExactTwoSided as T, normalizeSignedZero as U, associationEstimate as V, rocAuc as W, calibrateJudgeContinuous as X, calibrateJudge as Y, continuousAgreement as Z, passAtK as _, wilcoxonSignedRank as a, benjaminiHochberg as b, pairedMde as c, independentRiskDifference as d, verbosityBias as et, mcnemar as f, pairedRiskDifferenceScore as g, pairedRiskDifferenceExact as h, mannWhitneyU as i, cohensD as j, twoByTwoPValue as k, requiredPairedSampleSize as l, pairedRiskDifference as m, sampleMedian as n, clusterBootstrap as nt, mcnemarPower as o, pairedBinaryScale as p, interRaterReliability as q, summarizeSample as r, placeboBand as rt, mcnemarRequiredN as s, eProcess as t, DEFAULT_BOOTSTRAP_SEED as tt, requiredSampleSize as u, passHatK as v, chiSquaredPValue as w, bonferroni as x, wilson as y, clusteredPairedContrast as z };
2323
2348
 
2324
- //# sourceMappingURL=statistics-BPl13X3G.js.map
2349
+ //# sourceMappingURL=statistics-AKnVFnK-.js.map