@tangle-network/agent-eval 1.0.29 → 1.0.31

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 (292) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/README.md +1 -0
  3. package/dist/adapters/http.d.ts +2 -2
  4. package/dist/{agent-profile-BF1WLMco.d.ts → agent-profile-BpLyM2kL.d.ts} +2 -2
  5. package/dist/{agent-profile-BF1WLMco.d.ts.map → agent-profile-BpLyM2kL.d.ts.map} +1 -1
  6. package/dist/{agent-profile-cell-3kYxUsK2.d.ts → agent-profile-cell-BTsrta0H.d.ts} +2 -9
  7. package/dist/agent-profile-cell-BTsrta0H.d.ts.map +1 -0
  8. package/dist/agent-profile-cell-CT5JYueM.js.map +1 -1
  9. package/dist/analyst/index.d.ts +13 -13
  10. package/dist/analyst/index.js +11 -11
  11. package/dist/{analyze-runs-BaziIw93.d.ts → analyze-runs-DfUDLaCk.d.ts} +6 -16
  12. package/dist/analyze-runs-DfUDLaCk.d.ts.map +1 -0
  13. package/dist/{analyze-runs-BCSHzqna.js → analyze-runs-YagfYgfx.js} +5 -5
  14. package/dist/{analyze-runs-BCSHzqna.js.map → analyze-runs-YagfYgfx.js.map} +1 -1
  15. package/dist/app-grade/index.d.ts +3 -5
  16. package/dist/app-grade/index.d.ts.map +1 -1
  17. package/dist/app-grade/index.js +2 -6
  18. package/dist/app-grade/index.js.map +1 -1
  19. package/dist/{benchmark-command-DRAHkn4D.js → benchmark-command-wpWa71ul.js} +11 -10
  20. package/dist/benchmark-command-wpWa71ul.js.map +1 -0
  21. package/dist/benchmarks/index.d.ts +7 -6
  22. package/dist/benchmarks/index.d.ts.map +1 -1
  23. package/dist/benchmarks/index.js +13 -5
  24. package/dist/benchmarks/index.js.map +1 -1
  25. package/dist/builder-eval/index.js +1 -1
  26. package/dist/{calibration-Cf-wpqqO.js → calibration-DE2WQmlX.js} +2 -2
  27. package/dist/{calibration-Cf-wpqqO.js.map → calibration-DE2WQmlX.js.map} +1 -1
  28. package/dist/campaign/index.d.ts +8 -8
  29. package/dist/campaign/index.js +14 -14
  30. package/dist/{campaign-Cqz2vk2p.js → campaign-CtdTo5em.js} +15 -15
  31. package/dist/{campaign-Cqz2vk2p.js.map → campaign-CtdTo5em.js.map} +1 -1
  32. package/dist/{campaign-evidence-CVNKiK0q.js → campaign-evidence-BS2-OSFN.js} +4 -4
  33. package/dist/{campaign-evidence-CVNKiK0q.js.map → campaign-evidence-BS2-OSFN.js.map} +1 -1
  34. package/dist/cli.js +9 -8
  35. package/dist/cli.js.map +1 -1
  36. package/dist/{cluster-bootstrap-B0MTOBRU.js → cluster-bootstrap-ClPYIWoX.js} +2 -2
  37. package/dist/{cluster-bootstrap-B0MTOBRU.js.map → cluster-bootstrap-ClPYIWoX.js.map} +1 -1
  38. package/dist/contract/index.d.ts +12 -11
  39. package/dist/contract/index.js +56 -34
  40. package/dist/contract/index.js.map +1 -1
  41. package/dist/{decision-point-CQOczIIH.js → decision-point-DvX1Z4Ue.js} +3 -3
  42. package/dist/{decision-point-CQOczIIH.js.map → decision-point-DvX1Z4Ue.js.map} +1 -1
  43. package/dist/{default-registry-DoIBhuS-.d.ts → default-registry-2Ziw-0sL.d.ts} +7 -7
  44. package/dist/{default-registry-DoIBhuS-.d.ts.map → default-registry-2Ziw-0sL.d.ts.map} +1 -1
  45. package/dist/{default-registry-D-xd7KxV.js → default-registry-DeiYGNKW.js} +3 -3
  46. package/dist/{default-registry-D-xd7KxV.js.map → default-registry-DeiYGNKW.js.map} +1 -1
  47. package/dist/{define-agent-eval-Be2Ser8j.d.ts → define-agent-eval-DmCV1TZo.d.ts} +7 -7
  48. package/dist/{define-agent-eval-Be2Ser8j.d.ts.map → define-agent-eval-DmCV1TZo.d.ts.map} +1 -1
  49. package/dist/{define-agent-eval-BLVewqJm.js → define-agent-eval-GgvRcpNL.js} +7 -7
  50. package/dist/{define-agent-eval-BLVewqJm.js.map → define-agent-eval-GgvRcpNL.js.map} +1 -1
  51. package/dist/diagnosis/index.d.ts +4 -3
  52. package/dist/diagnosis/index.d.ts.map +1 -1
  53. package/dist/diagnosis/index.js +1 -1
  54. package/dist/{dspy-rlm-engine-BS_jxE0P.js → dspy-rlm-engine-DJ_4E-PM.js} +3 -3
  55. package/dist/{dspy-rlm-engine-BS_jxE0P.js.map → dspy-rlm-engine-DJ_4E-PM.js.map} +1 -1
  56. package/dist/{engine-CPBhCLJR.d.ts → engine-yaSDTpEa.d.ts} +2 -2
  57. package/dist/{engine-CPBhCLJR.d.ts.map → engine-yaSDTpEa.d.ts.map} +1 -1
  58. package/dist/{eval-campaign-DpkToY_w.js → eval-campaign-bpSlwr6t.js} +2 -2
  59. package/dist/{eval-campaign-DpkToY_w.js.map → eval-campaign-bpSlwr6t.js.map} +1 -1
  60. package/dist/{evaluation-BjRgUyst.d.ts → evaluation-BQQ2ga5W.d.ts} +4 -4
  61. package/dist/{evaluation-BjRgUyst.d.ts.map → evaluation-BQQ2ga5W.d.ts.map} +1 -1
  62. package/dist/evaluation.d.ts +1 -1
  63. package/dist/{exact-types-DEnrf7NX.d.ts → exact-types-xrjBO9sb.d.ts} +2 -2
  64. package/dist/{exact-types-DEnrf7NX.d.ts.map → exact-types-xrjBO9sb.d.ts.map} +1 -1
  65. package/dist/execution-insight-B-My58JW.d.ts +14 -0
  66. package/dist/execution-insight-B-My58JW.d.ts.map +1 -0
  67. package/dist/experiment/index.d.ts +3 -3
  68. package/dist/experiment/index.js +7 -7
  69. package/dist/{exporters-BKZLt1Px.js → exporters-CfKvJlti.js} +70 -43
  70. package/dist/exporters-CfKvJlti.js.map +1 -0
  71. package/dist/{external-optimizer-process-m9xln7zN.js → external-optimizer-process-jiq4CZD0.js} +2 -2
  72. package/dist/{external-optimizer-process-m9xln7zN.js.map → external-optimizer-process-jiq4CZD0.js.map} +1 -1
  73. package/dist/{external-optimizer-subprocess-GO6s84Ov.js → external-optimizer-subprocess-DUOcOqly.js} +2 -2
  74. package/dist/{external-optimizer-subprocess-GO6s84Ov.js.map → external-optimizer-subprocess-DUOcOqly.js.map} +1 -1
  75. package/dist/failure-cluster-OvKQ0BTq.d.ts +32 -0
  76. package/dist/failure-cluster-OvKQ0BTq.d.ts.map +1 -0
  77. package/dist/{failure-cluster-DOoa7CBg.d.ts → failure-taxonomy-C_SQZ_SJ.d.ts} +2 -30
  78. package/dist/failure-taxonomy-C_SQZ_SJ.d.ts.map +1 -0
  79. package/dist/{feedback-trajectory-DxkG5EPi.d.ts → feedback-trajectory-BbwTH49m.d.ts} +3 -3
  80. package/dist/{feedback-trajectory-DxkG5EPi.d.ts.map → feedback-trajectory-BbwTH49m.d.ts.map} +1 -1
  81. package/dist/{findings-store-CTy71Lnr.js → findings-store-B7JpmgJx.js} +3 -3
  82. package/dist/{findings-store-CTy71Lnr.js.map → findings-store-B7JpmgJx.js.map} +1 -1
  83. package/dist/fuzz.js +1 -1
  84. package/dist/harness-session-lines-hAxOvmtP.js +205 -0
  85. package/dist/harness-session-lines-hAxOvmtP.js.map +1 -0
  86. package/dist/{hf-dataset-Bv114tzB.js → hf-dataset-Cc81I0vQ.js} +65 -141
  87. package/dist/hf-dataset-Cc81I0vQ.js.map +1 -0
  88. package/dist/hosted/index.js +1 -1
  89. package/dist/{index-BI9ecONy.d.ts → index-8hbrQwdR.d.ts} +26 -11
  90. package/dist/index-8hbrQwdR.d.ts.map +1 -0
  91. package/dist/{index-AjfEHHA8.d.ts → index-BFpDeCuS.d.ts} +7 -7
  92. package/dist/{index-AjfEHHA8.d.ts.map → index-BFpDeCuS.d.ts.map} +1 -1
  93. package/dist/{index-DHWFYUVW.d.ts → index-Bcy00QoN.d.ts} +87 -144
  94. package/dist/index-Bcy00QoN.d.ts.map +1 -0
  95. package/dist/{index-BriU7rfL.d.ts → index-BfxYoHGF.d.ts} +226 -6
  96. package/dist/index-BfxYoHGF.d.ts.map +1 -0
  97. package/dist/{index-D-0mg-eu.d.ts → index-BnqugnsM.d.ts} +31 -11
  98. package/dist/index-BnqugnsM.d.ts.map +1 -0
  99. package/dist/{index-C8a9Dyan.d.ts → index-BwJtNdaj.d.ts} +21 -24
  100. package/dist/index-BwJtNdaj.d.ts.map +1 -0
  101. package/dist/{index-VSN1IZQp.d.ts → index-Yec_iihg.d.ts} +4 -3
  102. package/dist/index-Yec_iihg.d.ts.map +1 -0
  103. package/dist/index.d.ts +34 -31
  104. package/dist/index.js +21 -21
  105. package/dist/{integrity-BHM4voOx.js → integrity-BSs9dgKW.js} +3 -3
  106. package/dist/{integrity-BHM4voOx.js.map → integrity-BSs9dgKW.js.map} +1 -1
  107. package/dist/{journal-CTX5uK-n.js → journal-F3msN9OD.js} +5 -399
  108. package/dist/journal-F3msN9OD.js.map +1 -0
  109. package/dist/journal-file-AekB57Er.js +400 -0
  110. package/dist/journal-file-AekB57Er.js.map +1 -0
  111. package/dist/judge-calibration-DnrbQaXI.d.ts +144 -0
  112. package/dist/judge-calibration-DnrbQaXI.d.ts.map +1 -0
  113. package/dist/{judge-gate-DsoI5tx7.js → judge-gate-MP1rHOB4.js} +2 -2
  114. package/dist/{judge-gate-DsoI5tx7.js.map → judge-gate-MP1rHOB4.js.map} +1 -1
  115. package/dist/ledger-core/index.js +3 -2
  116. package/dist/{ledger-core-24IxvmVY.js → ledger-core-COxrkkZi.js} +2 -2
  117. package/dist/{ledger-core-24IxvmVY.js.map → ledger-core-COxrkkZi.js.map} +1 -1
  118. package/dist/{llm-judge-DzAT7Wka.js → llm-judge-Cc33WVHX.js} +102 -27
  119. package/dist/llm-judge-Cc33WVHX.js.map +1 -0
  120. package/dist/{matrix-DdniPG_M.d.ts → matrix-D0fEU0fq.d.ts} +2 -2
  121. package/dist/{matrix-DdniPG_M.d.ts.map → matrix-D0fEU0fq.d.ts.map} +1 -1
  122. package/dist/meta-eval/index.d.ts +3 -3
  123. package/dist/meta-eval/index.js +6 -6
  124. package/dist/{mint-Ck92efNo.js → mint-g8elU5yW.js} +11 -35
  125. package/dist/mint-g8elU5yW.js.map +1 -0
  126. package/dist/multishot/golden/index.d.ts +1 -1
  127. package/dist/multishot/index.d.ts +2 -2
  128. package/dist/openapi.json +1 -1
  129. package/dist/{outcome-observations-DPkH-LHQ.js → outcome-observations-YFFmdGGW.js} +2 -2
  130. package/dist/{outcome-observations-DPkH-LHQ.js.map → outcome-observations-YFFmdGGW.js.map} +1 -1
  131. package/dist/{paired-arms-DjMEtYI9.js → paired-arms-CMSTbLqX.js} +2 -2
  132. package/dist/{paired-arms-DjMEtYI9.js.map → paired-arms-CMSTbLqX.js.map} +1 -1
  133. package/dist/{paired-promotion-decision-DawN2o0G.d.ts → paired-promotion-decision-BBSxTo-h.d.ts} +2 -2
  134. package/dist/{paired-promotion-decision-DawN2o0G.d.ts.map → paired-promotion-decision-BBSxTo-h.d.ts.map} +1 -1
  135. package/dist/{paired-promotion-decision-Bi9__RQS.js → paired-promotion-decision-BoWHWL1i.js} +2 -2
  136. package/dist/{paired-promotion-decision-Bi9__RQS.js.map → paired-promotion-decision-BoWHWL1i.js.map} +1 -1
  137. package/dist/{paired-promotion-power-D03cUj9E.js → paired-promotion-power-BXH3gzvs.js} +3 -3
  138. package/dist/{paired-promotion-power-D03cUj9E.js.map → paired-promotion-power-BXH3gzvs.js.map} +1 -1
  139. package/dist/{pareto-UzjB3ZBk.js → pareto-B226QGVD.js} +54 -47
  140. package/dist/pareto-B226QGVD.js.map +1 -0
  141. package/dist/pipelines/index.d.ts +1 -1
  142. package/dist/pipelines/index.js +1 -1
  143. package/dist/{prime-protocol-RUPtoYiI.d.ts → prime-protocol-3aHqoxSH.d.ts} +2 -2
  144. package/dist/{prime-protocol-RUPtoYiI.d.ts.map → prime-protocol-3aHqoxSH.d.ts.map} +1 -1
  145. package/dist/profile-cell.d.ts +2 -2
  146. package/dist/{promotion-gate-DG_PSJx_.d.ts → promotion-gate-D-ffRHFQ.d.ts} +3 -3
  147. package/dist/{promotion-gate-DG_PSJx_.d.ts.map → promotion-gate-D-ffRHFQ.d.ts.map} +1 -1
  148. package/dist/{promotion-policy-DCgftbnd.js → promotion-policy-CfgRPGx0.js} +4 -4
  149. package/dist/{promotion-policy-DCgftbnd.js.map → promotion-policy-CfgRPGx0.js.map} +1 -1
  150. package/dist/{proposal-findings-CS6LoGGp.js → proposal-findings-BFtn6Lcx.js} +2 -2
  151. package/dist/{proposal-findings-CS6LoGGp.js.map → proposal-findings-BFtn6Lcx.js.map} +1 -1
  152. package/dist/{registry-BqoX13FD.d.ts → registry-x5n4GeBx.d.ts} +3 -3
  153. package/dist/{registry-BqoX13FD.d.ts.map → registry-x5n4GeBx.d.ts.map} +1 -1
  154. package/dist/{release-confidence-B4Xxdpmn.js → release-confidence-baM0TqCx.js} +2 -2
  155. package/dist/{release-confidence-B4Xxdpmn.js.map → release-confidence-baM0TqCx.js.map} +1 -1
  156. package/dist/reporting.d.ts +13 -6
  157. package/dist/reporting.d.ts.map +1 -1
  158. package/dist/reporting.js +5 -5
  159. package/dist/{summary-report-9kwI6jFQ.d.ts → research-report-CUbXuGX-.d.ts} +6 -121
  160. package/dist/research-report-CUbXuGX-.d.ts.map +1 -0
  161. package/dist/{researcher-BuojS14L.d.ts → researcher-D6D7q9uQ.d.ts} +4 -4
  162. package/dist/{researcher-BuojS14L.d.ts.map → researcher-D6D7q9uQ.d.ts.map} +1 -1
  163. package/dist/{reward-hacking-BYiDFbIl.js → reward-hacking-DNiHskry.js} +2 -2
  164. package/dist/{reward-hacking-BYiDFbIl.js.map → reward-hacking-DNiHskry.js.map} +1 -1
  165. package/dist/{reward-hacking-CIdVwVe4.d.ts → reward-hacking-_CAip56v.d.ts} +2 -2
  166. package/dist/{reward-hacking-CIdVwVe4.d.ts.map → reward-hacking-_CAip56v.d.ts.map} +1 -1
  167. package/dist/rl.d.ts +35 -17
  168. package/dist/rl.d.ts.map +1 -1
  169. package/dist/rl.js +116 -24
  170. package/dist/rl.js.map +1 -1
  171. package/dist/rollout/index.d.ts +5 -6
  172. package/dist/rollout/index.js +7 -6
  173. package/dist/{rollout-B86tqluQ.js → rollout-CCh4eSB3.js} +6 -5
  174. package/dist/{rollout-B86tqluQ.js.map → rollout-CCh4eSB3.js.map} +1 -1
  175. package/dist/{rollout-nodes-DhSPJ2X7.js → rollout-nodes-DzmHlPAC.js} +2 -2
  176. package/dist/rollout-nodes-DzmHlPAC.js.map +1 -0
  177. package/dist/{rubric-predictive-validity-Bbi88Aut.d.ts → rubric-predictive-validity-BTN3nNhC.d.ts} +2 -2
  178. package/dist/{rubric-predictive-validity-Bbi88Aut.d.ts.map → rubric-predictive-validity-BTN3nNhC.d.ts.map} +1 -1
  179. package/dist/{rubric-predictive-validity-DL7gJ51F.js → rubric-predictive-validity-Cln7r56F.js} +2 -2
  180. package/dist/{rubric-predictive-validity-DL7gJ51F.js.map → rubric-predictive-validity-Cln7r56F.js.map} +1 -1
  181. package/dist/{run-record-DTTx9Ktr.js → run-record-CbrxTcCO.js} +2 -2
  182. package/dist/{run-record-DTTx9Ktr.js.map → run-record-CbrxTcCO.js.map} +1 -1
  183. package/dist/{run-record-pBlhZizT.d.ts → run-record-hti3ETmO.d.ts} +2 -2
  184. package/dist/{run-record-pBlhZizT.d.ts.map → run-record-hti3ETmO.d.ts.map} +1 -1
  185. package/dist/{runtime-rollouts-BNrm5nC_.js → runtime-rollouts-eO9qpGE9.js} +269 -55
  186. package/dist/{runtime-rollouts-BNrm5nC_.js.map → runtime-rollouts-eO9qpGE9.js.map} +1 -1
  187. package/dist/{schema-PDKQ_iNE.d.ts → schema-BTTzvMnn.d.ts} +24 -5
  188. package/dist/schema-BTTzvMnn.d.ts.map +1 -0
  189. package/dist/{schema-ChIZfnqY.js → schema-b18jtzZw.js} +56 -3
  190. package/dist/schema-b18jtzZw.js.map +1 -0
  191. package/dist/search/index.d.ts +2 -2
  192. package/dist/search/index.js +2 -2
  193. package/dist/{search-kernel-C4XnLKIW.d.ts → search-kernel-IpyhPDQd.d.ts} +287 -276
  194. package/dist/search-kernel-IpyhPDQd.d.ts.map +1 -0
  195. package/dist/{search-ledger-9liYyZf5.js → search-ledger-D_ENQh0d.js} +4 -4
  196. package/dist/{search-ledger-9liYyZf5.js.map → search-ledger-D_ENQh0d.js.map} +1 -1
  197. package/dist/{search-ledger-file-BhOdgYIt.js → search-ledger-file-J8Xh9pU_.js} +3 -3
  198. package/dist/{search-ledger-file-BhOdgYIt.js.map → search-ledger-file-J8Xh9pU_.js.map} +1 -1
  199. package/dist/{search-shipper-B6tMNx1I.js → search-shipper-BUf7s92U.js} +3 -3
  200. package/dist/{search-shipper-B6tMNx1I.js.map → search-shipper-BUf7s92U.js.map} +1 -1
  201. package/dist/{search-summary-CISbbxyr.js → search-summary-B2RpvkkQ.js} +5 -5
  202. package/dist/{search-summary-CISbbxyr.js.map → search-summary-B2RpvkkQ.js.map} +1 -1
  203. package/dist/{sequential-1-T2oi1_.d.ts → sequential-B-zx24n_.d.ts} +2 -2
  204. package/dist/{sequential-1-T2oi1_.d.ts.map → sequential-B-zx24n_.d.ts.map} +1 -1
  205. package/dist/{sequential-Ko7T-zvu.js → sequential-C6k0Wrb7.js} +3 -3
  206. package/dist/{sequential-Ko7T-zvu.js.map → sequential-C6k0Wrb7.js.map} +1 -1
  207. package/dist/{sequential-9TVb5Nu5.js → sequential-pLr7Ukad.js} +3 -3
  208. package/dist/{sequential-9TVb5Nu5.js.map → sequential-pLr7Ukad.js.map} +1 -1
  209. package/dist/{single-run-lock-CUj2tjxT.js → single-run-lock-BSKsoeQF.js} +2 -2
  210. package/dist/{single-run-lock-CUj2tjxT.js.map → single-run-lock-BSKsoeQF.js.map} +1 -1
  211. package/dist/{skillopt-optimization-method-BtX7xXDd.js → skillopt-optimization-method-BnR2yh-a.js} +11 -11
  212. package/dist/{skillopt-optimization-method-BtX7xXDd.js.map → skillopt-optimization-method-BnR2yh-a.js.map} +1 -1
  213. package/dist/{statistical-heldout-Bx1QUDNy.d.ts → statistical-heldout-AvgLVFp6.d.ts} +6 -6
  214. package/dist/{statistical-heldout-Bx1QUDNy.d.ts.map → statistical-heldout-AvgLVFp6.d.ts.map} +1 -1
  215. package/dist/{statistical-heldout-DLO4Ebos.js → statistical-heldout-BvcAVtof.js} +3 -3
  216. package/dist/{statistical-heldout-DLO4Ebos.js.map → statistical-heldout-BvcAVtof.js.map} +1 -1
  217. package/dist/{statistics-CvvC-MPv.js → statistics-CHs0jlsY.js} +184 -2
  218. package/dist/statistics-CHs0jlsY.js.map +1 -0
  219. package/dist/statistics.d.ts +2 -2
  220. package/dist/statistics.js +2 -2
  221. package/dist/{store-tool-spans-kCDPEwjL.d.ts → store-tool-spans-Bm0-YhHG.d.ts} +5 -5
  222. package/dist/{store-tool-spans-kCDPEwjL.d.ts.map → store-tool-spans-Bm0-YhHG.d.ts.map} +1 -1
  223. package/dist/{summary-report-BEhqoxrA.js → summary-report-BgdIlM_w.js} +3 -3
  224. package/dist/{summary-report-BEhqoxrA.js.map → summary-report-BgdIlM_w.js.map} +1 -1
  225. package/dist/summary-report-figures-BoFCoiOP.d.ts +112 -0
  226. package/dist/summary-report-figures-BoFCoiOP.d.ts.map +1 -0
  227. package/dist/supervisor-run/index.d.ts +32 -8
  228. package/dist/supervisor-run/index.d.ts.map +1 -1
  229. package/dist/supervisor-run/index.js +3 -3
  230. package/dist/{systemone-CSwi1hp-.d.ts → systemone-DPVj7a1g.d.ts} +7 -7
  231. package/dist/{systemone-CSwi1hp-.d.ts.map → systemone-DPVj7a1g.d.ts.map} +1 -1
  232. package/dist/{systemone-review-WpWosn3a.d.ts → systemone-review-CrnsTRav.d.ts} +2 -2
  233. package/dist/{systemone-review-WpWosn3a.d.ts.map → systemone-review-CrnsTRav.d.ts.map} +1 -1
  234. package/dist/systemone.d.ts +3 -3
  235. package/dist/systemone.js +1 -1
  236. package/dist/{tool-groups-Bcasvncd.d.ts → tool-groups-5pgmtTmE.d.ts} +3 -3
  237. package/dist/tool-groups-5pgmtTmE.d.ts.map +1 -0
  238. package/dist/{tool-waste-BqSmmPUz.js → tool-waste-DWSohyd3.js} +2 -2
  239. package/dist/{tool-waste-BqSmmPUz.js.map → tool-waste-DWSohyd3.js.map} +1 -1
  240. package/dist/{trace-questions-DI42jXPj.d.ts → trace-questions-ETZDn5ax.d.ts} +3 -3
  241. package/dist/{trace-questions-DI42jXPj.d.ts.map → trace-questions-ETZDn5ax.d.ts.map} +1 -1
  242. package/dist/trace-repair/index.d.ts +2 -2
  243. package/dist/trace-repair/index.js +1 -1
  244. package/dist/traces.d.ts +4 -4
  245. package/dist/training-admission-xaDOlQ_U.d.ts +31 -0
  246. package/dist/training-admission-xaDOlQ_U.d.ts.map +1 -0
  247. package/dist/{tree-D2cNtu9m.js → tree-DA_WI1aV.js} +5 -5
  248. package/dist/{tree-D2cNtu9m.js.map → tree-DA_WI1aV.js.map} +1 -1
  249. package/dist/{types-DbGSC2No.d.ts → types-Dtt11Ppr.d.ts} +2 -2
  250. package/dist/{types-DbGSC2No.d.ts.map → types-Dtt11Ppr.d.ts.map} +1 -1
  251. package/dist/{types-CLGrB4Sv.d.ts → types-_dfu6Ox2.d.ts} +4 -4
  252. package/dist/{types-CLGrB4Sv.d.ts.map → types-_dfu6Ox2.d.ts.map} +1 -1
  253. package/dist/{types-ByrbgALT.d.ts → types-qJwFZTqa.d.ts} +7 -6
  254. package/dist/types-qJwFZTqa.d.ts.map +1 -0
  255. package/dist/{types-CEgIBy0W.d.ts → types-rf0yhJmW.d.ts} +3 -3
  256. package/dist/{types-CEgIBy0W.d.ts.map → types-rf0yhJmW.d.ts.map} +1 -1
  257. package/dist/wire/index.d.ts +1 -1
  258. package/docs/adopt-stack.md +2 -0
  259. package/docs/concepts.md +4 -1
  260. package/docs/design/statistics-decisions.md +17 -0
  261. package/docs/rollout.md +124 -4
  262. package/docs/search-ledger.md +18 -1
  263. package/docs/trace-analysis.md +11 -3
  264. package/package.json +3 -3
  265. package/dist/agent-profile-cell-3kYxUsK2.d.ts.map +0 -1
  266. package/dist/analyze-runs-BaziIw93.d.ts.map +0 -1
  267. package/dist/benchmark-command-DRAHkn4D.js.map +0 -1
  268. package/dist/exporters-BKZLt1Px.js.map +0 -1
  269. package/dist/exporters-dQKYD_Zo.d.ts +0 -159
  270. package/dist/exporters-dQKYD_Zo.d.ts.map +0 -1
  271. package/dist/failure-cluster-DOoa7CBg.d.ts.map +0 -1
  272. package/dist/hf-dataset-Bv114tzB.js.map +0 -1
  273. package/dist/index-BI9ecONy.d.ts.map +0 -1
  274. package/dist/index-BriU7rfL.d.ts.map +0 -1
  275. package/dist/index-C8a9Dyan.d.ts.map +0 -1
  276. package/dist/index-D-0mg-eu.d.ts.map +0 -1
  277. package/dist/index-DHWFYUVW.d.ts.map +0 -1
  278. package/dist/index-VSN1IZQp.d.ts.map +0 -1
  279. package/dist/journal-CTX5uK-n.js.map +0 -1
  280. package/dist/llm-judge-DzAT7Wka.js.map +0 -1
  281. package/dist/mint-Ck92efNo.js.map +0 -1
  282. package/dist/pareto-UzjB3ZBk.js.map +0 -1
  283. package/dist/reward-ap_R9mCH.d.ts +0 -53
  284. package/dist/reward-ap_R9mCH.d.ts.map +0 -1
  285. package/dist/rollout-nodes-DhSPJ2X7.js.map +0 -1
  286. package/dist/schema-ChIZfnqY.js.map +0 -1
  287. package/dist/schema-PDKQ_iNE.d.ts.map +0 -1
  288. package/dist/search-kernel-C4XnLKIW.d.ts.map +0 -1
  289. package/dist/statistics-CvvC-MPv.js.map +0 -1
  290. package/dist/summary-report-9kwI6jFQ.d.ts.map +0 -1
  291. package/dist/tool-groups-Bcasvncd.d.ts.map +0 -1
  292. package/dist/types-ByrbgALT.d.ts.map +0 -1
@@ -0,0 +1,400 @@
1
+ import { lockHolderVerdict, lockIdentity, parseLockHolderRecord, readLockHolderIdentity } from "./ledger-core/lock-holder.js";
2
+ import { randomUUID } from "node:crypto";
3
+ import { closeSync, constants, existsSync, fstatSync, fsyncSync, linkSync, mkdirSync, openSync, readFileSync, readSync, renameSync, rmSync, unlinkSync, writeFileSync, writeSync } from "node:fs";
4
+ import { dirname } from "node:path";
5
+ import { uptime } from "node:os";
6
+ // src/ledger-core/atomic-file-lock.ts
7
+ /** Crash-safe filesystem lock shared by campaign persistence and run exclusion. */
8
+ var AtomicFileLockError = class extends Error {
9
+ name = "AtomicFileLockError";
10
+ };
11
+ /** Report whether another lock path prevents acquisition without modifying it. */
12
+ function probeAtomicFileLock(options) {
13
+ if (existsSync(recoveryPath(options.lockPath))) return {
14
+ acquired: false,
15
+ reason: "recovery"
16
+ };
17
+ const state = ownerState(options.lockPath);
18
+ if (state.state === "held") return {
19
+ acquired: false,
20
+ reason: "held",
21
+ holder: state.owner
22
+ };
23
+ return null;
24
+ }
25
+ /**
26
+ * Try to acquire a complete, uniquely-owned lock inode.
27
+ *
28
+ * A hard link publishes fully-written owner metadata atomically. Stale-owner
29
+ * removal is serialized so one reclaimer cannot delete a new owner's lock.
30
+ */
31
+ function tryAcquireAtomicFileLock(options) {
32
+ const pid = options.pid ?? process.pid;
33
+ if (!Number.isSafeInteger(pid) || pid <= 0) throw new AtomicFileLockError("atomic file lock pid must be a positive integer");
34
+ const owner = {
35
+ ...readLockHolderIdentity(pid),
36
+ nonce: randomUUID()
37
+ };
38
+ for (let attempt = 0; attempt < 8; attempt += 1) {
39
+ if (existsSync(recoveryPath(options.lockPath))) {
40
+ const recovery = tryAcquireRecoveryLease(options.lockPath, owner, attempt);
41
+ if (!recovery) return {
42
+ acquired: false,
43
+ reason: "recovery"
44
+ };
45
+ try {
46
+ return recoverLock(options.lockPath, owner, attempt);
47
+ } finally {
48
+ recovery.release();
49
+ }
50
+ }
51
+ if (tryLinkOwner(options.lockPath, owner, `acquire.${attempt}`)) return acquired(options.lockPath, owner);
52
+ const holder = ownerState(options.lockPath);
53
+ if (holder.state === "missing") continue;
54
+ if (holder.state === "held") return {
55
+ acquired: false,
56
+ reason: "held",
57
+ holder: holder.owner
58
+ };
59
+ const recovery = tryAcquireRecoveryLease(options.lockPath, owner, attempt);
60
+ if (!recovery) return {
61
+ acquired: false,
62
+ reason: "recovery"
63
+ };
64
+ try {
65
+ return recoverLock(options.lockPath, owner, attempt);
66
+ } finally {
67
+ recovery.release();
68
+ }
69
+ }
70
+ throw new AtomicFileLockError(`could not acquire atomic file lock ${options.lockPath}`);
71
+ }
72
+ function tryAcquireRecoveryLease(lockPath, owner, attempt) {
73
+ let leasePath = recoveryPath(lockPath);
74
+ const staleOwners = [];
75
+ for (let depth = 0; depth < 64; depth += 1) {
76
+ const state = ownerState(leasePath);
77
+ if (state.state === "missing") {
78
+ if (!tryLinkOwner(leasePath, owner, `reclaim.${attempt}.${depth}`)) continue;
79
+ return { release: () => {
80
+ for (const stale of staleOwners) releaseOwnedPath(stale.path, stale.owner);
81
+ releaseOwnedPath(leasePath, owner);
82
+ } };
83
+ }
84
+ if (state.state === "held") return null;
85
+ staleOwners.push({
86
+ path: leasePath,
87
+ owner: state.owner
88
+ });
89
+ leasePath = `${leasePath}.next.${state.owner.nonce}`;
90
+ }
91
+ throw new AtomicFileLockError(`atomic file lock recovery chain is too deep (${lockPath})`);
92
+ }
93
+ function recoverLock(lockPath, owner, attempt) {
94
+ const current = ownerState(lockPath);
95
+ if (current.state === "held") return {
96
+ acquired: false,
97
+ reason: "held",
98
+ holder: current.owner
99
+ };
100
+ if (current.state === "stale") {
101
+ const tombstone = `${lockPath}.stale.${owner.nonce}.${attempt}`;
102
+ try {
103
+ renameSync(lockPath, tombstone);
104
+ unlinkSync(tombstone);
105
+ } catch (error) {
106
+ if (!isMissing(error)) throw error;
107
+ }
108
+ }
109
+ if (tryLinkOwner(lockPath, owner, `recovered.${attempt}`)) return acquired(lockPath, owner);
110
+ const holder = ownerState(lockPath);
111
+ if (holder.state === "held") return {
112
+ acquired: false,
113
+ reason: "held",
114
+ holder: holder.owner
115
+ };
116
+ return {
117
+ acquired: false,
118
+ reason: "recovery"
119
+ };
120
+ }
121
+ function acquired(lockPath, owner) {
122
+ return {
123
+ acquired: true,
124
+ lock: {
125
+ owner,
126
+ release: () => releaseOwnedPath(lockPath, owner)
127
+ }
128
+ };
129
+ }
130
+ function tryLinkOwner(lockPath, owner, suffix) {
131
+ const ownerPath = `${lockPath}.${owner.pid}.${owner.nonce}.${suffix}.owner`;
132
+ const descriptor = openSync(ownerPath, constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY, 384);
133
+ try {
134
+ const lock = lockIdentity(fstatSync(descriptor, { bigint: true }));
135
+ writeFileSync(descriptor, `${JSON.stringify({
136
+ ...owner,
137
+ lock
138
+ })}\n`, "utf8");
139
+ } catch (error) {
140
+ closeSync(descriptor);
141
+ unlinkIfExists(ownerPath);
142
+ throw error;
143
+ }
144
+ closeSync(descriptor);
145
+ try {
146
+ linkSync(ownerPath, lockPath);
147
+ return true;
148
+ } catch (error) {
149
+ if (!isAlreadyExists(error)) throw error;
150
+ return false;
151
+ } finally {
152
+ unlinkIfExists(ownerPath);
153
+ }
154
+ }
155
+ /** Only a holder proved dead is stale; an alive or unknown holder keeps the lock. */
156
+ function ownerState(lockPath) {
157
+ const current = readOwner(lockPath);
158
+ if (!current) return { state: "missing" };
159
+ return {
160
+ state: current.torn || lockHolderVerdict(current.record, current.identity).liveness === "dead" ? "stale" : "held",
161
+ owner: current.owner
162
+ };
163
+ }
164
+ function readOwner(lockPath) {
165
+ let descriptor;
166
+ try {
167
+ descriptor = openSync(lockPath, "r");
168
+ } catch (error) {
169
+ if (isMissing(error)) return void 0;
170
+ throw error;
171
+ }
172
+ let contents;
173
+ let identity;
174
+ try {
175
+ identity = lockIdentity(fstatSync(descriptor, { bigint: true }));
176
+ contents = readFileSync(descriptor, "utf8").trim();
177
+ } finally {
178
+ closeSync(descriptor);
179
+ }
180
+ const record = parseOwnerRecord(parseJson(contents));
181
+ if (record) {
182
+ const { lock: _lock, ...owner } = record;
183
+ return {
184
+ owner,
185
+ record,
186
+ identity
187
+ };
188
+ }
189
+ if (!bornBeforeBoot(identity)) throw invalidOwner(lockPath);
190
+ const owner = {
191
+ pid: 0,
192
+ host: "",
193
+ nonce: `torn.${identity.ino}.${identity.birthtimeNs}`
194
+ };
195
+ return {
196
+ owner,
197
+ record: owner,
198
+ identity,
199
+ torn: true
200
+ };
201
+ }
202
+ function parseJson(text) {
203
+ try {
204
+ return JSON.parse(text);
205
+ } catch {
206
+ return;
207
+ }
208
+ }
209
+ /** Boot time from uptime; the 1 s margin covers its rounding, so a lock made just after boot stays live. */
210
+ function bornBeforeBoot(lock) {
211
+ const born = BigInt(lock.birthtimeNs);
212
+ return born > 0n && born < BigInt(Math.floor(Date.now() - uptime() * 1e3 - 1e3)) * 1000000n;
213
+ }
214
+ /**
215
+ * Accept exactly the fields a lock owner writes: a holder record that parses
216
+ * whole, plus the nonce. A record from before holder identity carried only pid,
217
+ * host and nonce; it still parses, and its holder is never proved dead.
218
+ */
219
+ function parseOwnerRecord(value) {
220
+ const holder = parseLockHolderRecord(value);
221
+ if (!holder) return void 0;
222
+ const { nonce, ...rest } = value;
223
+ if (typeof nonce !== "string" || nonce.trim().length === 0) return void 0;
224
+ if (Object.keys(rest).length !== Object.keys(holder).length) return void 0;
225
+ return {
226
+ ...holder,
227
+ nonce
228
+ };
229
+ }
230
+ function invalidOwner(lockPath) {
231
+ return new AtomicFileLockError(`atomic file lock has an invalid owner (${lockPath}); refusing unsafe recovery`);
232
+ }
233
+ function releaseOwnedPath(lockPath, owner) {
234
+ const current = readOwner(lockPath);
235
+ if (!current) return;
236
+ if (canonicalOwner(current.owner) !== canonicalOwner(owner)) throw new AtomicFileLockError(`atomic file lock owner changed before release (${lockPath})`);
237
+ try {
238
+ unlinkSync(lockPath);
239
+ } catch (error) {
240
+ if (!isMissing(error)) throw error;
241
+ }
242
+ }
243
+ function canonicalOwner(owner) {
244
+ return JSON.stringify({
245
+ host: owner.host,
246
+ nonce: owner.nonce,
247
+ pid: owner.pid
248
+ });
249
+ }
250
+ function recoveryPath(lockPath) {
251
+ return `${lockPath}.reclaim`;
252
+ }
253
+ function isAlreadyExists(error) {
254
+ return error instanceof Error && "code" in error && error.code === "EEXIST";
255
+ }
256
+ function isMissing(error) {
257
+ return error instanceof Error && "code" in error && error.code === "ENOENT";
258
+ }
259
+ function unlinkIfExists(path) {
260
+ try {
261
+ unlinkSync(path);
262
+ } catch (error) {
263
+ if (!isMissing(error)) throw error;
264
+ }
265
+ }
266
+ // src/ledger-core/journal-file.ts
267
+ /** Filesystem durability and cross-process exclusion for append-only journal files. */
268
+ /** Append one already-serialized line; the write is fsynced (file and directory)
269
+ * before returning so an acknowledged append survives a crash. */
270
+ function appendLedgerLine(path, line, context) {
271
+ mkdirSync(dirname(path), { recursive: true });
272
+ recoverTornFinalWrite(path, context);
273
+ const fd = openSync(path, constants.O_CREAT | constants.O_WRONLY | constants.O_APPEND, 384);
274
+ try {
275
+ writeAll(fd, Buffer.from(line, "utf8"), context);
276
+ fsyncSync(fd);
277
+ } finally {
278
+ closeSync(fd);
279
+ }
280
+ fsyncDirectory(dirname(path));
281
+ }
282
+ function recoverTornFinalWrite(path, context) {
283
+ let fd;
284
+ try {
285
+ fd = openSync(path, constants.O_RDWR);
286
+ } catch (error) {
287
+ if (error.code === "ENOENT") return;
288
+ throw context.integrityError(`${context.subject} ${path} could not be opened for recovery`, { cause: error });
289
+ }
290
+ try {
291
+ const size = fstatSync(fd).size;
292
+ if (size === 0 || readByte(fd, size - 1) === 10) return;
293
+ const tailStart = findFinalLineStart(fd, size);
294
+ const replacement = Buffer.alloc(size - tailStart, 32);
295
+ replacement[replacement.length - 1] = 10;
296
+ writeAllAt(fd, replacement, tailStart, context);
297
+ fsyncSync(fd);
298
+ } catch (error) {
299
+ throw context.integrityError(`${context.subject} ${path} has an unrecoverable final journal write`, { cause: error });
300
+ } finally {
301
+ closeSync(fd);
302
+ }
303
+ }
304
+ /** Replace a small sidecar file whole: write a temporary sibling, fsync it,
305
+ * then rename over the target. A reader therefore sees the previous contents
306
+ * or the new ones, never a partial file. */
307
+ function writeLedgerFileAtomically(path, contents, context) {
308
+ const directory = dirname(path);
309
+ mkdirSync(directory, { recursive: true });
310
+ const temporaryPath = `${path}.tmp`;
311
+ const fd = openSync(temporaryPath, constants.O_CREAT | constants.O_WRONLY | constants.O_TRUNC, 384);
312
+ try {
313
+ writeAll(fd, Buffer.from(contents, "utf8"), context);
314
+ fsyncSync(fd);
315
+ } finally {
316
+ closeSync(fd);
317
+ }
318
+ renameSync(temporaryPath, path);
319
+ fsyncDirectory(directory);
320
+ }
321
+ /** Remove whatever occupies a sidecar path and fsync its directory, so the
322
+ * removal is as durable as the write that created it. False when the path was
323
+ * already empty. Recursive because a sidecar path holding a directory is one of
324
+ * the states this has to be able to clear, not one it can refuse. */
325
+ function removeLedgerFile(path, context) {
326
+ try {
327
+ rmSync(path, { recursive: true });
328
+ } catch (error) {
329
+ if (error.code === "ENOENT") return false;
330
+ throw context.integrityError(`${context.subject} ${path} could not be removed`, { cause: error });
331
+ }
332
+ fsyncDirectory(dirname(path));
333
+ return true;
334
+ }
335
+ function withLedgerFileLock(path, context, run) {
336
+ const result = tryWithLedgerFileLock(path, context, run);
337
+ if (!result.acquired) throw context.integrityError(`${context.subject} lock is held (${path})`);
338
+ return result.value;
339
+ }
340
+ function tryWithLedgerFileLock(path, context, run) {
341
+ mkdirSync(dirname(path), { recursive: true });
342
+ const lockPath = `${path}.lock`;
343
+ try {
344
+ const acquisition = tryAcquireAtomicFileLock({ lockPath });
345
+ if (!acquisition.acquired) return { acquired: false };
346
+ try {
347
+ return {
348
+ acquired: true,
349
+ value: run()
350
+ };
351
+ } finally {
352
+ acquisition.lock.release();
353
+ }
354
+ } catch (error) {
355
+ if (error instanceof AtomicFileLockError) throw context.integrityError(error.message, { cause: error });
356
+ throw error;
357
+ }
358
+ }
359
+ function writeAll(fd, bytes, context) {
360
+ let offset = 0;
361
+ while (offset < bytes.byteLength) {
362
+ const written = writeSync(fd, bytes, offset, bytes.byteLength - offset);
363
+ if (written <= 0) throw context.integrityError("filesystem wrote zero bytes");
364
+ offset += written;
365
+ }
366
+ }
367
+ function writeAllAt(fd, bytes, position, context) {
368
+ let offset = 0;
369
+ while (offset < bytes.byteLength) {
370
+ const written = writeSync(fd, bytes, offset, bytes.byteLength - offset, position + offset);
371
+ if (written <= 0) throw context.integrityError("filesystem wrote zero bytes");
372
+ offset += written;
373
+ }
374
+ }
375
+ function findFinalLineStart(fd, size) {
376
+ const chunk = Buffer.alloc(Math.min(4096, size));
377
+ let cursor = size;
378
+ while (cursor > 0) {
379
+ const length = Math.min(chunk.byteLength, cursor);
380
+ cursor -= length;
381
+ const read = readSync(fd, chunk, 0, length, cursor);
382
+ for (let index = read - 1; index >= 0; index -= 1) if (chunk[index] === 10) return cursor + index + 1;
383
+ }
384
+ return 0;
385
+ }
386
+ function readByte(fd, position) {
387
+ const byte = Buffer.allocUnsafe(1);
388
+ return readSync(fd, byte, 0, 1, position) === 1 ? byte[0] : -1;
389
+ }
390
+ function fsyncDirectory(path) {
391
+ const fd = openSync(path, constants.O_RDONLY);
392
+ try {
393
+ fsyncSync(fd);
394
+ } finally {
395
+ closeSync(fd);
396
+ }
397
+ }
398
+ export { writeLedgerFileAtomically as a, withLedgerFileLock as i, removeLedgerFile as n, probeAtomicFileLock as o, tryWithLedgerFileLock as r, tryAcquireAtomicFileLock as s, appendLedgerLine as t };
399
+
400
+ //# sourceMappingURL=journal-file-AekB57Er.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"journal-file-AekB57Er.js","names":[],"sources":["../src/ledger-core/atomic-file-lock.ts","../src/ledger-core/journal-file.ts"],"sourcesContent":["/** Crash-safe filesystem lock shared by campaign persistence and run exclusion. */\n\nimport { randomUUID } from 'node:crypto'\nimport {\n closeSync,\n constants,\n existsSync,\n fstatSync,\n linkSync,\n openSync,\n readFileSync,\n renameSync,\n unlinkSync,\n writeFileSync,\n} from 'node:fs'\nimport { uptime } from 'node:os'\nimport {\n type LockHolderIdentity,\n type LockHolderRecord,\n type LockIdentity,\n lockHolderVerdict,\n lockIdentity,\n parseLockHolderRecord,\n readLockHolderIdentity,\n} from './lock-holder'\n\n/**\n * The holder of a lock path. The lock file holds this record plus the identity\n * of its own inode, so `lockHolderVerdict` can prove a crashed holder dead.\n */\nexport interface AtomicFileLockOwner extends LockHolderIdentity {\n readonly nonce: string\n}\n\nexport interface AtomicFileLock {\n readonly owner: AtomicFileLockOwner\n release(): void\n}\n\nexport type AtomicFileLockUnavailable =\n | { readonly acquired: false; readonly reason: 'held'; readonly holder: AtomicFileLockOwner }\n | { readonly acquired: false; readonly reason: 'recovery' }\n\nexport type AtomicFileLockAcquisition =\n | { readonly acquired: true; readonly lock: AtomicFileLock }\n | AtomicFileLockUnavailable\n\nexport interface AtomicFileLockOptions {\n readonly lockPath: string\n readonly pid?: number\n}\n\nexport class AtomicFileLockError extends Error {\n override readonly name = 'AtomicFileLockError'\n}\n\ntype OwnerState =\n | { readonly state: 'missing' }\n | { readonly state: 'stale'; readonly owner: AtomicFileLockOwner }\n | { readonly state: 'held'; readonly owner: AtomicFileLockOwner }\n\n/** Report whether another lock path prevents acquisition without modifying it. */\nexport function probeAtomicFileLock(\n options: AtomicFileLockOptions,\n): AtomicFileLockUnavailable | null {\n if (existsSync(recoveryPath(options.lockPath))) return { acquired: false, reason: 'recovery' }\n const state = ownerState(options.lockPath)\n if (state.state === 'held') {\n return { acquired: false, reason: 'held', holder: state.owner }\n }\n return null\n}\n\n/**\n * Try to acquire a complete, uniquely-owned lock inode.\n *\n * A hard link publishes fully-written owner metadata atomically. Stale-owner\n * removal is serialized so one reclaimer cannot delete a new owner's lock.\n */\nexport function tryAcquireAtomicFileLock(\n options: AtomicFileLockOptions,\n): AtomicFileLockAcquisition {\n const pid = options.pid ?? process.pid\n if (!Number.isSafeInteger(pid) || pid <= 0) {\n throw new AtomicFileLockError('atomic file lock pid must be a positive integer')\n }\n const owner: AtomicFileLockOwner = { ...readLockHolderIdentity(pid), nonce: randomUUID() }\n for (let attempt = 0; attempt < 8; attempt += 1) {\n if (existsSync(recoveryPath(options.lockPath))) {\n const recovery = tryAcquireRecoveryLease(options.lockPath, owner, attempt)\n if (!recovery) return { acquired: false, reason: 'recovery' }\n try {\n return recoverLock(options.lockPath, owner, attempt)\n } finally {\n recovery.release()\n }\n }\n if (tryLinkOwner(options.lockPath, owner, `acquire.${attempt}`)) {\n return acquired(options.lockPath, owner)\n }\n\n const holder = ownerState(options.lockPath)\n if (holder.state === 'missing') continue\n if (holder.state === 'held') {\n return { acquired: false, reason: 'held', holder: holder.owner }\n }\n\n const recovery = tryAcquireRecoveryLease(options.lockPath, owner, attempt)\n if (!recovery) return { acquired: false, reason: 'recovery' }\n try {\n return recoverLock(options.lockPath, owner, attempt)\n } finally {\n recovery.release()\n }\n }\n\n throw new AtomicFileLockError(`could not acquire atomic file lock ${options.lockPath}`)\n}\n\ninterface RecoveryLease {\n release(): void\n}\n\nfunction tryAcquireRecoveryLease(\n lockPath: string,\n owner: AtomicFileLockOwner,\n attempt: number,\n): RecoveryLease | null {\n let leasePath = recoveryPath(lockPath)\n const staleOwners: Array<{ path: string; owner: AtomicFileLockOwner }> = []\n\n for (let depth = 0; depth < 64; depth += 1) {\n const state = ownerState(leasePath)\n if (state.state === 'missing') {\n if (!tryLinkOwner(leasePath, owner, `reclaim.${attempt}.${depth}`)) continue\n return {\n release: () => {\n for (const stale of staleOwners) releaseOwnedPath(stale.path, stale.owner)\n releaseOwnedPath(leasePath, owner)\n },\n }\n }\n if (state.state === 'held') return null\n staleOwners.push({ path: leasePath, owner: state.owner })\n leasePath = `${leasePath}.next.${state.owner.nonce}`\n }\n\n throw new AtomicFileLockError(`atomic file lock recovery chain is too deep (${lockPath})`)\n}\n\nfunction recoverLock(\n lockPath: string,\n owner: AtomicFileLockOwner,\n attempt: number,\n): AtomicFileLockAcquisition {\n const current = ownerState(lockPath)\n if (current.state === 'held') {\n return { acquired: false, reason: 'held', holder: current.owner }\n }\n if (current.state === 'stale') {\n const tombstone = `${lockPath}.stale.${owner.nonce}.${attempt}`\n try {\n renameSync(lockPath, tombstone)\n unlinkSync(tombstone)\n } catch (error) {\n if (!isMissing(error)) throw error\n }\n }\n if (tryLinkOwner(lockPath, owner, `recovered.${attempt}`)) {\n return acquired(lockPath, owner)\n }\n const holder = ownerState(lockPath)\n if (holder.state === 'held') {\n return { acquired: false, reason: 'held', holder: holder.owner }\n }\n return { acquired: false, reason: 'recovery' }\n}\n\nfunction acquired(lockPath: string, owner: AtomicFileLockOwner): AtomicFileLockAcquisition {\n return {\n acquired: true,\n lock: {\n owner,\n release: () => releaseOwnedPath(lockPath, owner),\n },\n }\n}\n\nfunction tryLinkOwner(lockPath: string, owner: AtomicFileLockOwner, suffix: string): boolean {\n const ownerPath = `${lockPath}.${owner.pid}.${owner.nonce}.${suffix}.owner`\n const descriptor = openSync(\n ownerPath,\n constants.O_CREAT | constants.O_EXCL | constants.O_WRONLY,\n 0o600,\n )\n try {\n // A hard link keeps the inode, so this identity is the lock path's once linked.\n const lock = lockIdentity(fstatSync(descriptor, { bigint: true }))\n // No fsync: it waited one journal commit on every fenced write (agent-runtime#2362). A power\n // loss can then leave the linked record empty or torn, which readOwner settles by boot time.\n writeFileSync(descriptor, `${JSON.stringify({ ...owner, lock })}\\n`, 'utf8')\n } catch (error) {\n closeSync(descriptor)\n unlinkIfExists(ownerPath)\n throw error\n }\n closeSync(descriptor)\n\n try {\n linkSync(ownerPath, lockPath)\n return true\n } catch (error) {\n if (!isAlreadyExists(error)) throw error\n return false\n } finally {\n unlinkIfExists(ownerPath)\n }\n}\n\n/** Only a holder proved dead is stale; an alive or unknown holder keeps the lock. */\nfunction ownerState(lockPath: string): OwnerState {\n const current = readOwner(lockPath)\n if (!current) return { state: 'missing' }\n const dead = current.torn || lockHolderVerdict(current.record, current.identity).liveness === 'dead'\n return { state: dead ? 'stale' : 'held', owner: current.owner }\n}\n\ninterface LockFileOwner {\n readonly owner: AtomicFileLockOwner\n readonly record: LockHolderRecord & { readonly nonce: string }\n /** The inode the record was read from, so a verdict compares it with the recorded lock. */\n readonly identity: LockIdentity\n readonly torn?: true\n}\n\nfunction readOwner(lockPath: string): LockFileOwner | undefined {\n let descriptor: number\n try {\n descriptor = openSync(lockPath, 'r')\n } catch (error) {\n if (isMissing(error)) return undefined\n throw error\n }\n let contents: string\n let identity: LockIdentity\n try {\n identity = lockIdentity(fstatSync(descriptor, { bigint: true }))\n contents = readFileSync(descriptor, 'utf8').trim()\n } finally {\n closeSync(descriptor)\n }\n\n const record = parseOwnerRecord(parseJson(contents))\n if (record) {\n const { lock: _lock, ...owner } = record\n return { owner, record, identity }\n }\n // Only a power loss leaves a linked record unreadable; an inode born before this boot has no holder left here.\n if (!bornBeforeBoot(identity)) throw invalidOwner(lockPath)\n const owner = { pid: 0, host: '', nonce: `torn.${identity.ino}.${identity.birthtimeNs}` }\n return { owner, record: owner, identity, torn: true }\n}\n\nfunction parseJson(text: string): unknown {\n try {\n return JSON.parse(text)\n } catch {\n return undefined\n }\n}\n\n/** Boot time from uptime; the 1 s margin covers its rounding, so a lock made just after boot stays live. */\nfunction bornBeforeBoot(lock: LockIdentity): boolean {\n const born = BigInt(lock.birthtimeNs)\n return born > 0n && born < BigInt(Math.floor(Date.now() - uptime() * 1000 - 1000)) * 1_000_000n\n}\n\n/**\n * Accept exactly the fields a lock owner writes: a holder record that parses\n * whole, plus the nonce. A record from before holder identity carried only pid,\n * host and nonce; it still parses, and its holder is never proved dead.\n */\nfunction parseOwnerRecord(value: unknown): LockFileOwner['record'] | undefined {\n const holder = parseLockHolderRecord(value)\n if (!holder) return undefined\n const { nonce, ...rest } = value as Record<string, unknown>\n if (typeof nonce !== 'string' || nonce.trim().length === 0) return undefined\n // A field the holder parse dropped is malformed; refuse it instead of guessing.\n if (Object.keys(rest).length !== Object.keys(holder).length) return undefined\n return { ...holder, nonce }\n}\n\nfunction invalidOwner(lockPath: string): AtomicFileLockError {\n return new AtomicFileLockError(\n `atomic file lock has an invalid owner (${lockPath}); refusing unsafe recovery`,\n )\n}\n\nfunction releaseOwnedPath(lockPath: string, owner: AtomicFileLockOwner): void {\n const current = readOwner(lockPath)\n if (!current) return\n if (canonicalOwner(current.owner) !== canonicalOwner(owner)) {\n throw new AtomicFileLockError(`atomic file lock owner changed before release (${lockPath})`)\n }\n try {\n unlinkSync(lockPath)\n } catch (error) {\n if (!isMissing(error)) throw error\n }\n}\n\nfunction canonicalOwner(owner: AtomicFileLockOwner): string {\n return JSON.stringify({ host: owner.host, nonce: owner.nonce, pid: owner.pid })\n}\n\nfunction recoveryPath(lockPath: string): string {\n return `${lockPath}.reclaim`\n}\n\nfunction isAlreadyExists(error: unknown): boolean {\n return error instanceof Error && 'code' in error && error.code === 'EEXIST'\n}\n\nfunction isMissing(error: unknown): boolean {\n return error instanceof Error && 'code' in error && error.code === 'ENOENT'\n}\n\nfunction unlinkIfExists(path: string): void {\n try {\n unlinkSync(path)\n } catch (error) {\n if (!isMissing(error)) throw error\n }\n}\n","/** Filesystem durability and cross-process exclusion for append-only journal files. */\n\nimport {\n closeSync,\n constants,\n fstatSync,\n fsyncSync,\n mkdirSync,\n openSync,\n readSync,\n renameSync,\n rmSync,\n writeSync,\n} from 'node:fs'\nimport { dirname } from 'node:path'\nimport { AtomicFileLockError, tryAcquireAtomicFileLock } from './atomic-file-lock'\n\n/** How a journal binding reports file-layer faults in its own error taxonomy. */\nexport interface LedgerFileContext {\n /** Noun used in error messages, e.g. 'search ledger'. */\n subject: string\n integrityError(message: string, options?: { cause?: unknown }): Error\n}\n\n/** Append one already-serialized line; the write is fsynced (file and directory)\n * before returning so an acknowledged append survives a crash. */\nexport function appendLedgerLine(path: string, line: string, context: LedgerFileContext): void {\n mkdirSync(dirname(path), { recursive: true })\n recoverTornFinalWrite(path, context)\n const fd = openSync(path, constants.O_CREAT | constants.O_WRONLY | constants.O_APPEND, 0o600)\n try {\n writeAll(fd, Buffer.from(line, 'utf8'), context)\n fsyncSync(fd)\n } finally {\n closeSync(fd)\n }\n fsyncDirectory(dirname(path))\n}\n\nfunction recoverTornFinalWrite(path: string, context: LedgerFileContext): void {\n let fd: number\n try {\n fd = openSync(path, constants.O_RDWR)\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return\n throw context.integrityError(`${context.subject} ${path} could not be opened for recovery`, {\n cause: error,\n })\n }\n\n try {\n const size = fstatSync(fd).size\n if (size === 0 || readByte(fd, size - 1) === 0x0a) return\n const tailStart = findFinalLineStart(fd, size)\n const replacement = Buffer.alloc(size - tailStart, 0x20)\n replacement[replacement.length - 1] = 0x0a\n writeAllAt(fd, replacement, tailStart, context)\n fsyncSync(fd)\n } catch (error) {\n throw context.integrityError(\n `${context.subject} ${path} has an unrecoverable final journal write`,\n { cause: error },\n )\n } finally {\n closeSync(fd)\n }\n}\n\n/** Replace a small sidecar file whole: write a temporary sibling, fsync it,\n * then rename over the target. A reader therefore sees the previous contents\n * or the new ones, never a partial file. */\nexport function writeLedgerFileAtomically(\n path: string,\n contents: string,\n context: LedgerFileContext,\n): void {\n const directory = dirname(path)\n mkdirSync(directory, { recursive: true })\n const temporaryPath = `${path}.tmp`\n const fd = openSync(\n temporaryPath,\n constants.O_CREAT | constants.O_WRONLY | constants.O_TRUNC,\n 0o600,\n )\n try {\n writeAll(fd, Buffer.from(contents, 'utf8'), context)\n fsyncSync(fd)\n } finally {\n closeSync(fd)\n }\n renameSync(temporaryPath, path)\n fsyncDirectory(directory)\n}\n\n/** Remove whatever occupies a sidecar path and fsync its directory, so the\n * removal is as durable as the write that created it. False when the path was\n * already empty. Recursive because a sidecar path holding a directory is one of\n * the states this has to be able to clear, not one it can refuse. */\nexport function removeLedgerFile(path: string, context: LedgerFileContext): boolean {\n try {\n rmSync(path, { recursive: true })\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === 'ENOENT') return false\n throw context.integrityError(`${context.subject} ${path} could not be removed`, {\n cause: error,\n })\n }\n fsyncDirectory(dirname(path))\n return true\n}\n\nexport function withLedgerFileLock<T>(path: string, context: LedgerFileContext, run: () => T): T {\n const result = tryWithLedgerFileLock(path, context, run)\n if (!result.acquired) {\n throw context.integrityError(`${context.subject} lock is held (${path})`)\n }\n return result.value\n}\n\nexport type FileLockResult<T> = { acquired: true; value: T } | { acquired: false }\n\nexport function tryWithLedgerFileLock<T>(\n path: string,\n context: LedgerFileContext,\n run: () => T,\n): FileLockResult<T> {\n mkdirSync(dirname(path), { recursive: true })\n const lockPath = `${path}.lock`\n try {\n const acquisition = tryAcquireAtomicFileLock({ lockPath })\n if (!acquisition.acquired) return { acquired: false }\n try {\n return { acquired: true, value: run() }\n } finally {\n acquisition.lock.release()\n }\n } catch (error) {\n if (error instanceof AtomicFileLockError) {\n throw context.integrityError(error.message, { cause: error })\n }\n throw error\n }\n}\n\nfunction writeAll(fd: number, bytes: Buffer, context: LedgerFileContext): void {\n let offset = 0\n while (offset < bytes.byteLength) {\n const written = writeSync(fd, bytes, offset, bytes.byteLength - offset)\n if (written <= 0) throw context.integrityError('filesystem wrote zero bytes')\n offset += written\n }\n}\n\nfunction writeAllAt(fd: number, bytes: Buffer, position: number, context: LedgerFileContext): void {\n let offset = 0\n while (offset < bytes.byteLength) {\n const written = writeSync(fd, bytes, offset, bytes.byteLength - offset, position + offset)\n if (written <= 0) throw context.integrityError('filesystem wrote zero bytes')\n offset += written\n }\n}\n\nfunction findFinalLineStart(fd: number, size: number): number {\n const chunk = Buffer.alloc(Math.min(4_096, size))\n let cursor = size\n while (cursor > 0) {\n const length = Math.min(chunk.byteLength, cursor)\n cursor -= length\n const read = readSync(fd, chunk, 0, length, cursor)\n for (let index = read - 1; index >= 0; index -= 1) {\n if (chunk[index] === 0x0a) return cursor + index + 1\n }\n }\n return 0\n}\n\nfunction readByte(fd: number, position: number): number {\n const byte = Buffer.allocUnsafe(1)\n const read = readSync(fd, byte, 0, 1, position)\n return read === 1 ? byte[0]! : -1\n}\n\nfunction fsyncDirectory(path: string): void {\n const fd = openSync(path, constants.O_RDONLY)\n try {\n fsyncSync(fd)\n } finally {\n closeSync(fd)\n }\n}\n"],"mappings":";;;;;;;AAoDA,IAAa,sBAAb,cAAyC,MAAM;CAC7C,OAAyB;AAC3B;;AAQA,SAAgB,oBACd,S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AAM,YAAY,MAAM;EAChD,UAAU;EACV,MAAM,OAAO,SAAS,IAAI,OAAO,GAAG,QAAQ,MAAM;EAClD,KAAK,IAAI,QAAQ,OAAO,GAAG,SAAS,GAAG,SAAS,GAC9C,IAAI,MAAM,WAAW,IAAM,OAAO,SAAS,QAAQ;CAEvD;CACA,OAAO;AACT;AAEA,SAAS,SAAS,IAAY,UAA0B;CACtD,MAAM,OAAO,OAAO,YAAY,CAAC;CAEjC,OADa,SAAS,IAAI,MAAM,GAAG,GAAG,QAC5B,MAAM,IAAI,KAAK,KAAM;AACjC;AAEA,SAAS,eAAe,MAAoB;CAC1C,MAAM,KAAK,SAAS,MAAM,UAAU,QAAQ;CAC5C,IAAI;EACF,UAAU,EAAE;CACd,UAAU;EACR,UAAU,EAAE;CACd;AACF"}
@@ -0,0 +1,144 @@
1
+ /**
2
+ * Judge calibration — measure judge quality against human gold + bias.
3
+ *
4
+ * Workflow:
5
+ * 1. Build a golden set: {itemId, humanScore}[].
6
+ * 2. Run candidate judges; each produces {itemId, score}.
7
+ * 3. `calibrateJudge(golden, candidate)` reports κ + Pearson + MAE.
8
+ * 4. `calibrateJudgeContinuous(golden, candidate)` adds quadratic-weighted
9
+ * κ over the un-rounded [0,1] scores plus ICC(2,1), Pearson, Spearman,
10
+ * and bootstrap CIs — use this for fine-grained judges where rounding
11
+ * to int discards information (e.g. 0.78 vs 0.81 both round to 1 and
12
+ * look "perfectly agreed" to integer κ).
13
+ * 5. Run bias probes (positional, verbosity, self-preference) to
14
+ * detect systematic score inflation.
15
+ * 6. For N≥2 judges on the same items, `continuousAgreement(scores)`
16
+ * reports ICC(2,1) + κ_w + Pearson + Spearman with bootstrap CIs.
17
+ *
18
+ * Returns actionable diagnostics, not a single number. Consumers then
19
+ * decide whether to trust the judge, retrain it, or add a tie-breaker.
20
+ */
21
+ interface GoldenItem {
22
+ itemId: string;
23
+ humanScore: number;
24
+ /** Optional group used for per-group bias audits (e.g. model-of-output family). */
25
+ group?: string;
26
+ }
27
+ interface CandidateScore {
28
+ itemId: string;
29
+ score: number;
30
+ /** Optional — enables positional-bias analysis (did order matter?). */
31
+ positionOfAInput?: 'first' | 'second';
32
+ }
33
+ interface CalibrationResult {
34
+ n: number;
35
+ pearson: number;
36
+ /** Cohen's κ with quadratic weights over integer-rounded scores. */
37
+ kappa: number;
38
+ /** Mean absolute error vs human. */
39
+ mae: number;
40
+ /** Worst-5 miscalibrations (largest |judge - human|). */
41
+ worstItems: Array<{
42
+ itemId: string;
43
+ judge: number;
44
+ human: number;
45
+ delta: number;
46
+ }>;
47
+ }
48
+ /**
49
+ * Measure judge quality against human gold labels: computes Cohen's κ, Pearson correlation, and MAE over matched item ids.
50
+ */
51
+ declare function calibrateJudge(golden: GoldenItem[], candidate: CandidateScore[]): CalibrationResult;
52
+ interface PositionalBiasResult {
53
+ /**
54
+ * Score delta (first-position - second-position) averaged across items
55
+ * presented in both positions. Non-zero = positional bias.
56
+ */
57
+ avgDelta: number;
58
+ n: number;
59
+ }
60
+ /**
61
+ * Feed the same items to the judge twice with A/B swapped and pass all
62
+ * results here. Items that don't appear in both positions are ignored.
63
+ */
64
+ declare function positionalBias(scores: CandidateScore[]): PositionalBiasResult;
65
+ interface VerbosityBiasResult {
66
+ /** Pearson correlation between output length and score. Strong positive = verbosity bias. */
67
+ pearson: number;
68
+ n: number;
69
+ }
70
+ declare function verbosityBias(samples: Array<{
71
+ outputLen: number;
72
+ score: number;
73
+ }>): VerbosityBiasResult;
74
+ interface SelfPreferenceResult {
75
+ /** Mean judge score when judge's family matches output's family. */
76
+ inFamilyMean: number;
77
+ outOfFamilyMean: number;
78
+ deltaMean: number;
79
+ n: number;
80
+ }
81
+ /**
82
+ * Pass the same scenarios scored with judge-model X grading outputs from
83
+ * model X (in-family) and model Y (out-of-family). Non-zero delta
84
+ * indicates self-preference.
85
+ */
86
+ declare function selfPreference(samples: Array<{
87
+ score: number;
88
+ inFamily: boolean;
89
+ }>): SelfPreferenceResult;
90
+ interface ContinuousAgreement {
91
+ /** Cohen's κ_w with quadratic weights, computed on raw [0,1] scores. */
92
+ weightedKappa: number;
93
+ /** ICC(2,1): two-way random effects, absolute agreement, single rater. */
94
+ icc: number;
95
+ /** Pearson product-moment correlation (averaged over rater pairs if N>2). */
96
+ pearson: number;
97
+ /** Spearman rank correlation (averaged over rater pairs if N>2). */
98
+ spearman: number;
99
+ /** 95% bootstrap percentile CIs over items. */
100
+ ci: {
101
+ icc: [number, number];
102
+ weightedKappa: [number, number];
103
+ };
104
+ /** Number of complete items (no NaN across raters). */
105
+ n: number;
106
+ /** Number of raters. */
107
+ raters: number;
108
+ }
109
+ interface ContinuousAgreementOptions {
110
+ /** Bootstrap iterations. Default 1000. Set to 0 to skip CIs (CI = [NaN, NaN]). */
111
+ bootstrap?: number;
112
+ /** κ weighting scheme. Default 'quadratic'. */
113
+ weights?: 'linear' | 'quadratic';
114
+ /** PRNG seed for reproducible bootstrap. Default 0xC0FFEE. */
115
+ seed?: number;
116
+ /** Confidence level for percentile CI. Default 0.95. */
117
+ ciLevel?: number;
118
+ }
119
+ /**
120
+ * Inter-rater agreement on continuous (typically [0,1]) scores.
121
+ *
122
+ * `scores` has shape [n_items][n_raters]. Rows with any non-finite entry
123
+ * are dropped. Returns NaN metrics if fewer than 2 raters or 2 complete
124
+ * items remain.
125
+ */
126
+ declare function continuousAgreement(scores: number[][], opts?: ContinuousAgreementOptions): ContinuousAgreement;
127
+ interface ContinuousCalibrationResult extends CalibrationResult {
128
+ /** Cohen's κ_w computed on raw (un-rounded) scores. */
129
+ weightedKappaContinuous: number;
130
+ /** ICC(2,1) treating golden + candidate as two raters. */
131
+ icc: number;
132
+ spearman: number;
133
+ ci: {
134
+ icc: [number, number];
135
+ weightedKappa: [number, number];
136
+ };
137
+ }
138
+ /**
139
+ * Extends `calibrateJudge` with continuous-value agreement metrics while
140
+ * retaining its base calibration summary.
141
+ */
142
+ declare function calibrateJudgeContinuous(golden: GoldenItem[], candidate: CandidateScore[], opts?: ContinuousAgreementOptions): ContinuousCalibrationResult;
143
+ export { ContinuousCalibrationResult as a, SelfPreferenceResult as c, calibrateJudgeContinuous as d, continuousAgreement as f, verbosityBias as h, ContinuousAgreementOptions as i, VerbosityBiasResult as l, selfPreference as m, CandidateScore as n, GoldenItem as o, positionalBias as p, ContinuousAgreement as r, PositionalBiasResult as s, CalibrationResult as t, calibrateJudge as u };
144
+ //# sourceMappingURL=judge-calibration-DnrbQaXI.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"judge-calibration-DnrbQaXI.d.ts","names":[],"sources":["../src/judge-calibration.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;UAwBiB;EACf;EACA;;EAEA;;UAGe;EACf;EACA;;EAEA;;UAGe;EACf;EACA;;EAEA;;EAEA;;EAEA,YAAY;IAAQ;IAAgB;IAAe;IAAe;;;;;;iBAMpD,eACd,QAAQ,cACR,WAAW,mBACV;UA0Bc;;;;;EAKf;EACA;;;;;;iBAOc,eAAe,QAAQ,mBAAmB;UAgBzC;;EAEf;EACA;;iBAGc,cACd,SAAS;EAAQ;EAAmB;KACnC;UAYc;;EAEf;EACA;EACA;EACA;;;;;;;iBAQc,eACd,SAAS;EAAQ;EAAe;KAC/B;UA8Ec;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;IACE;IACA;;;EAGF;;EAEA;;UAGe;;EAEf;;EAEA;;EAEA;;EAEA;;;;;;;;;iBAUc,oBACd,oBACA,OAAM,6BACL;UAoDc,oCAAoC;;EAEnD;;EAEA;EACA;EACA;IACE;IACA;;;;;;;iBAQY,yBACd,QAAQ,cACR,WAAW,kBACX,OAAM,6BACL"}
@@ -1,5 +1,5 @@
1
1
  import { i as JudgeError, s as ValidationError } from "./errors-DeEEV9Vx.js";
2
- import { lt as meanOrNull } from "./statistics-CvvC-MPv.js";
2
+ import { mt as meanOrNull } from "./statistics-CHs0jlsY.js";
3
3
  import { o as backoffMs, s as isTransientLlmError } from "./llm-client-Bj-TooRS.js";
4
4
  import { t as computeInterval } from "./interval-Bd2f4CRT.js";
5
5
  // src/series-convergence.ts
@@ -702,4 +702,4 @@ function snapshotFromJudgeAgreement(agreement, options = {}) {
702
702
  }
703
703
  export { analyzeSeries as _, judgeGateDecision as a, snapshotFromJudgeAgreement as c, judgeSentinelReport as d, snapshotFromAgreement as f, withJudgeRetry as g, validateSentinelSnapshot as h, assertJudgeMayGate as i, evalHealthStamp as l, snapshotFromSentinelSet as m, JudgeGateRefusedError as n, measureJudgeAgreement as o, snapshotFromCalibration as p, addCalibrationVerdicts as r, registerCalibrationSet as s, DEFAULT_JUDGE_GATE_POLICY as t, fileSentinelStore as u };
704
704
 
705
- //# sourceMappingURL=judge-gate-DsoI5tx7.js.map
705
+ //# sourceMappingURL=judge-gate-MP1rHOB4.js.map