@tangle-network/agent-eval 0.217.1 → 0.219.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (258) hide show
  1. package/CHANGELOG.md +57 -1
  2. package/dist/adapters/http.d.ts +3 -3
  3. package/dist/adapters/http.d.ts.map +1 -1
  4. package/dist/adapters/http.js +1 -0
  5. package/dist/adapters/http.js.map +1 -1
  6. package/dist/{agent-profile-DTt8uGP9.d.ts → agent-profile-D01Io2Xw.d.ts} +4 -4
  7. package/dist/{agent-profile-DTt8uGP9.d.ts.map → agent-profile-D01Io2Xw.d.ts.map} +1 -1
  8. package/dist/analyst/index.d.ts +13 -13
  9. package/dist/analyst/index.d.ts.map +1 -1
  10. package/dist/analyst/index.js +10 -10
  11. package/dist/analyst/index.js.map +1 -1
  12. package/dist/{analyze-runs-DyeNcenW.d.ts → analyze-runs-BWAHBDAw.d.ts} +4 -4
  13. package/dist/{analyze-runs-DyeNcenW.d.ts.map → analyze-runs-BWAHBDAw.d.ts.map} +1 -1
  14. package/dist/{benchmark-command-xQK8nOI6.js → benchmark-command-BzmMTnvC.js} +664 -565
  15. package/dist/benchmark-command-BzmMTnvC.js.map +1 -0
  16. package/dist/benchmarks/index.d.ts +5 -5
  17. package/dist/benchmarks/index.js +3 -3
  18. package/dist/benchmarks/index.js.map +1 -1
  19. package/dist/campaign/index.d.ts +8 -8
  20. package/dist/campaign/index.js +11 -11
  21. package/dist/{campaign-CJGkxAQ6.js → campaign-BVPC6ODQ.js} +452 -282
  22. package/dist/campaign-BVPC6ODQ.js.map +1 -0
  23. package/dist/{campaign-evidence-CQYw8_0H.js → campaign-evidence-DunzcJGv.js} +2 -2
  24. package/dist/campaign-evidence-DunzcJGv.js.map +1 -0
  25. package/dist/{chat-client-ldqxYYTN.js → chat-client-CMQ8_h4J.js} +2 -2
  26. package/dist/{chat-client-ldqxYYTN.js.map → chat-client-CMQ8_h4J.js.map} +1 -1
  27. package/dist/{chat-json-call-DavzexSp.js → chat-json-call-BrZKn0L3.js} +2 -2
  28. package/dist/{chat-json-call-DavzexSp.js.map → chat-json-call-BrZKn0L3.js.map} +1 -1
  29. package/dist/cli.js +10 -10
  30. package/dist/{completion-verifier-B_jw6C9p.js → completion-verifier-Cigap8CG.js} +5 -5
  31. package/dist/{completion-verifier-B_jw6C9p.js.map → completion-verifier-Cigap8CG.js.map} +1 -1
  32. package/dist/contract/index.d.ts +11 -11
  33. package/dist/contract/index.js +91 -11
  34. package/dist/contract/index.js.map +1 -1
  35. package/dist/{cost-ledger-D0352Z4d.js → cost-ledger-BGZB6yY2.js} +75 -2
  36. package/dist/cost-ledger-BGZB6yY2.js.map +1 -0
  37. package/dist/{cost-ledger-Jk62OBfF.d.ts → cost-ledger-C1W3ICmP.d.ts} +26 -2
  38. package/dist/cost-ledger-C1W3ICmP.d.ts.map +1 -0
  39. package/dist/{default-registry-ClYjq3QE.js → default-registry-BrKmT01n.js} +310 -278
  40. package/dist/{default-registry-ClYjq3QE.js.map → default-registry-BrKmT01n.js.map} +1 -1
  41. package/dist/{default-registry-DXgLmoDI.d.ts → default-registry-Cwg_QN3d.d.ts} +6 -6
  42. package/dist/{default-registry-DXgLmoDI.d.ts.map → default-registry-Cwg_QN3d.d.ts.map} +1 -1
  43. package/dist/{define-agent-eval-BIkH_gAR.d.ts → define-agent-eval-C2nFhHPu.d.ts} +8 -8
  44. package/dist/{define-agent-eval-BIkH_gAR.d.ts.map → define-agent-eval-C2nFhHPu.d.ts.map} +1 -1
  45. package/dist/{define-agent-eval-BDxNlP3D.js → define-agent-eval-UQY3VbJ2.js} +165 -105
  46. package/dist/define-agent-eval-UQY3VbJ2.js.map +1 -0
  47. package/dist/diagnosis/index.d.ts +2 -2
  48. package/dist/{dspy-rlm-engine-DhdCr1Dc.js → dspy-rlm-engine-Bn_Mt_LW.js} +3 -3
  49. package/dist/{dspy-rlm-engine-DhdCr1Dc.js.map → dspy-rlm-engine-Bn_Mt_LW.js.map} +1 -1
  50. package/dist/{engine-BvZ0R-36.d.ts → engine-BpGGw6cd.d.ts} +3 -3
  51. package/dist/{engine-BvZ0R-36.d.ts.map → engine-BpGGw6cd.d.ts.map} +1 -1
  52. package/dist/eval-campaign-BUMIxKTE.js +393 -0
  53. package/dist/eval-campaign-BUMIxKTE.js.map +1 -0
  54. package/dist/{evaluation-jTjC_QQD.d.ts → evaluation-CBdQt_kr.d.ts} +4 -4
  55. package/dist/{evaluation-jTjC_QQD.d.ts.map → evaluation-CBdQt_kr.d.ts.map} +1 -1
  56. package/dist/evaluation.d.ts +1 -1
  57. package/dist/evaluation.js +1 -1
  58. package/dist/{exact-types-CflbJ9f3.d.ts → exact-types-BYFmYq44.d.ts} +2 -2
  59. package/dist/{exact-types-CflbJ9f3.d.ts.map → exact-types-BYFmYq44.d.ts.map} +1 -1
  60. package/dist/experiment/index.d.ts +24 -1
  61. package/dist/experiment/index.d.ts.map +1 -1
  62. package/dist/experiment/index.js +110 -71
  63. package/dist/experiment/index.js.map +1 -1
  64. package/dist/{exporters-Cl6IeNAu.js → exporters-DWvM16LE.js} +2 -2
  65. package/dist/{exporters-Cl6IeNAu.js.map → exporters-DWvM16LE.js.map} +1 -1
  66. package/dist/{external-optimizer-process-KVFGvYX1.js → external-optimizer-process-wOLfzsCC.js} +2 -2
  67. package/dist/{external-optimizer-process-KVFGvYX1.js.map → external-optimizer-process-wOLfzsCC.js.map} +1 -1
  68. package/dist/{external-optimizer-subprocess-XIHBOSKt.js → external-optimizer-subprocess-D670Oxf2.js} +4 -4
  69. package/dist/{external-optimizer-subprocess-XIHBOSKt.js.map → external-optimizer-subprocess-D670Oxf2.js.map} +1 -1
  70. package/dist/{feedback-trajectory-BWmhRBGu.d.ts → feedback-trajectory-DhB9WzYg.d.ts} +3 -3
  71. package/dist/{feedback-trajectory-BWmhRBGu.d.ts.map → feedback-trajectory-DhB9WzYg.d.ts.map} +1 -1
  72. package/dist/{findings-store-BMVQtEsm.js → findings-store-CvNo712L.js} +6 -6
  73. package/dist/{findings-store-BMVQtEsm.js.map → findings-store-CvNo712L.js.map} +1 -1
  74. package/dist/fuzz.d.ts +1 -1
  75. package/dist/fuzz.js +1 -1
  76. package/dist/{hf-dataset-D9f7-oX7.js → hf-dataset-CKxIJQba.js} +3 -3
  77. package/dist/{hf-dataset-D9f7-oX7.js.map → hf-dataset-CKxIJQba.js.map} +1 -1
  78. package/dist/hosted/index.js +1 -1
  79. package/dist/{index-CX-GAUpw.d.ts → index-CHxwfW5g.d.ts} +2 -2
  80. package/dist/{index-CX-GAUpw.d.ts.map → index-CHxwfW5g.d.ts.map} +1 -1
  81. package/dist/{index-BLGqZ81N.d.ts → index-CVFStrQD.d.ts} +8 -8
  82. package/dist/{index-BLGqZ81N.d.ts.map → index-CVFStrQD.d.ts.map} +1 -1
  83. package/dist/{index-9jJ2fKSX.d.ts → index-CalAsXMR.d.ts} +7 -5
  84. package/dist/index-CalAsXMR.d.ts.map +1 -0
  85. package/dist/{index-CiRwLv2R.d.ts → index-D7fmC-1K.d.ts} +3 -4
  86. package/dist/index-D7fmC-1K.d.ts.map +1 -0
  87. package/dist/{index-BiT6RtNH.d.ts → index-DAXfpVf7.d.ts} +10 -10
  88. package/dist/{index-BiT6RtNH.d.ts.map → index-DAXfpVf7.d.ts.map} +1 -1
  89. package/dist/{index-ZuWx52WG.d.ts → index-Q6DvdcwI.d.ts} +67 -24
  90. package/dist/index-Q6DvdcwI.d.ts.map +1 -0
  91. package/dist/index.d.ts +26 -26
  92. package/dist/index.d.ts.map +1 -1
  93. package/dist/index.js +615 -692
  94. package/dist/index.js.map +1 -1
  95. package/dist/{integrity-DOd9Q86O.js → integrity-C8oUeB0g.js} +322 -197
  96. package/dist/integrity-C8oUeB0g.js.map +1 -0
  97. package/dist/{integrity-_qgZLA5p.d.ts → integrity-CCwvezWS.d.ts} +2 -2
  98. package/dist/{integrity-_qgZLA5p.d.ts.map → integrity-CCwvezWS.d.ts.map} +1 -1
  99. package/dist/{journal-CR4QikYp.js → journal-C7om8Gum.js} +48 -38
  100. package/dist/journal-C7om8Gum.js.map +1 -0
  101. package/dist/judge-gate-Co5tuh57.js.map +1 -1
  102. package/dist/{judge-gate-DsL0yFcb.d.ts → judge-gate-Dc_mXQsL.d.ts} +2 -2
  103. package/dist/judge-gate-Dc_mXQsL.d.ts.map +1 -0
  104. package/dist/{kind-factory-Gy4fXixd.js → kind-factory-BhxbtUsQ.js} +2 -2
  105. package/dist/{kind-factory-Gy4fXixd.js.map → kind-factory-BhxbtUsQ.js.map} +1 -1
  106. package/dist/ledger-core/index.d.ts +1 -1
  107. package/dist/ledger-core/index.js +2 -2
  108. package/dist/ledger-core/lock-holder.d.ts +2 -0
  109. package/dist/ledger-core/lock-holder.js +181 -0
  110. package/dist/ledger-core/lock-holder.js.map +1 -0
  111. package/dist/{ledger-core-DrJhbms9.js → ledger-core-CAxUdDk0.js} +2 -2
  112. package/dist/{ledger-core-DrJhbms9.js.map → ledger-core-CAxUdDk0.js.map} +1 -1
  113. package/dist/{llm-client-BshCREn6.js → llm-client-DXuOTseU.js} +239 -249
  114. package/dist/llm-client-DXuOTseU.js.map +1 -0
  115. package/dist/{llm-judge-C8jMTNNG.js → llm-judge-Cc8vDJh_.js} +648 -459
  116. package/dist/llm-judge-Cc8vDJh_.js.map +1 -0
  117. package/dist/lock-holder-DaJbfpci.d.ts +86 -0
  118. package/dist/lock-holder-DaJbfpci.d.ts.map +1 -0
  119. package/dist/matrix/index.d.ts +2 -2
  120. package/dist/{matrix-DHe-dwVJ.d.ts → matrix-Cf-AGxGh.d.ts} +4 -4
  121. package/dist/{matrix-DHe-dwVJ.d.ts.map → matrix-Cf-AGxGh.d.ts.map} +1 -1
  122. package/dist/meta-eval/index.d.ts +2 -2
  123. package/dist/{mint-zszyYlpA.js → mint-CbdwjTPW.js} +2 -2
  124. package/dist/{mint-zszyYlpA.js.map → mint-CbdwjTPW.js.map} +1 -1
  125. package/dist/{mint-BRZXuwRi.d.ts → mint-CkzpVPdz.d.ts} +3 -3
  126. package/dist/{mint-BRZXuwRi.d.ts.map → mint-CkzpVPdz.d.ts.map} +1 -1
  127. package/dist/multishot/golden/index.d.ts +1 -1
  128. package/dist/multishot/index.d.ts +2 -2
  129. package/dist/multishot/index.js.map +1 -1
  130. package/dist/openapi.json +1 -1
  131. package/dist/{pareto-BzsxidFD.js → pareto-BiBnQXAE.js} +306 -212
  132. package/dist/pareto-BiBnQXAE.js.map +1 -0
  133. package/dist/pipelines/index.d.ts.map +1 -1
  134. package/dist/pipelines/index.js.map +1 -1
  135. package/dist/{prime-protocol-BWG2DQIk.d.ts → prime-protocol-CckHBxGu.d.ts} +3 -3
  136. package/dist/{prime-protocol-BWG2DQIk.d.ts.map → prime-protocol-CckHBxGu.d.ts.map} +1 -1
  137. package/dist/{promotion-gate-DaY95yU6.d.ts → promotion-gate-CkVZHagC.d.ts} +3 -3
  138. package/dist/{promotion-gate-DaY95yU6.d.ts.map → promotion-gate-CkVZHagC.d.ts.map} +1 -1
  139. package/dist/{proposal-findings-BbWidvUk.js → proposal-findings-E1aSC_cU.js} +2 -2
  140. package/dist/{proposal-findings-BbWidvUk.js.map → proposal-findings-E1aSC_cU.js.map} +1 -1
  141. package/dist/{registry-ssNoHzwD.d.ts → registry-B_yG-1jh.d.ts} +5 -5
  142. package/dist/{registry-ssNoHzwD.d.ts.map → registry-B_yG-1jh.d.ts.map} +1 -1
  143. package/dist/{render-C-w2EZ6p.js → render-Cs34y0iX.js} +404 -208
  144. package/dist/render-Cs34y0iX.js.map +1 -0
  145. package/dist/reporting.d.ts +3 -3
  146. package/dist/{researcher-0ABVIdGa.d.ts → researcher-H0p44OYC.d.ts} +5 -5
  147. package/dist/{researcher-0ABVIdGa.d.ts.map → researcher-H0p44OYC.d.ts.map} +1 -1
  148. package/dist/{reward-DrZ71vnf.d.ts → reward-BeUgVVC_.d.ts} +2 -2
  149. package/dist/{reward-DrZ71vnf.d.ts.map → reward-BeUgVVC_.d.ts.map} +1 -1
  150. package/dist/{reward-hacking-E52wq86n.d.ts → reward-hacking-WTxUbtbb.d.ts} +2 -2
  151. package/dist/{reward-hacking-E52wq86n.d.ts.map → reward-hacking-WTxUbtbb.d.ts.map} +1 -1
  152. package/dist/rl.d.ts +8 -8
  153. package/dist/rl.js +4 -4
  154. package/dist/rollout/index.d.ts +3 -3
  155. package/dist/rollout/index.js +5 -5
  156. package/dist/{rollout-D6C50mfA.js → rollout-Dd1ucT_M.js} +5 -5
  157. package/dist/{rollout-D6C50mfA.js.map → rollout-Dd1ucT_M.js.map} +1 -1
  158. package/dist/{rubric-predictive-validity-DiwT8PbL.d.ts → rubric-predictive-validity-noY7uE03.d.ts} +2 -2
  159. package/dist/{rubric-predictive-validity-DiwT8PbL.d.ts.map → rubric-predictive-validity-noY7uE03.d.ts.map} +1 -1
  160. package/dist/{run-record-CaxbLq6Y.d.ts → run-record-C3awiXPf.d.ts} +2 -2
  161. package/dist/{run-record-CaxbLq6Y.d.ts.map → run-record-C3awiXPf.d.ts.map} +1 -1
  162. package/dist/schema-C-ziyJD7.d.ts.map +1 -1
  163. package/dist/{schema-DxcKTzbi.js → schema-CvhfLjtZ.js} +77 -47
  164. package/dist/schema-CvhfLjtZ.js.map +1 -0
  165. package/dist/search/index.d.ts +2 -2
  166. package/dist/search/index.d.ts.map +1 -1
  167. package/dist/search/index.js +2 -2
  168. package/dist/{search-kernel-DxqjBxA-.d.ts → search-kernel-Dloxd6gs.d.ts} +5 -5
  169. package/dist/{search-kernel-DxqjBxA-.d.ts.map → search-kernel-Dloxd6gs.d.ts.map} +1 -1
  170. package/dist/{search-ledger-TUvB5gWH.js → search-ledger-CZRqtFbW.js} +252 -245
  171. package/dist/search-ledger-CZRqtFbW.js.map +1 -0
  172. package/dist/{search-ledger-file-UKCO2r8a.js → search-ledger-file-Bd5Tioq6.js} +3 -3
  173. package/dist/{search-ledger-file-UKCO2r8a.js.map → search-ledger-file-Bd5Tioq6.js.map} +1 -1
  174. package/dist/{search-shipper-Cw2z3-td.js → search-shipper-Dn3NLsuH.js} +3 -3
  175. package/dist/{search-shipper-Cw2z3-td.js.map → search-shipper-Dn3NLsuH.js.map} +1 -1
  176. package/dist/{search-summary-DQIvJsSB.js → search-summary-D4bwYnAE.js} +3 -3
  177. package/dist/{search-summary-DQIvJsSB.js.map → search-summary-D4bwYnAE.js.map} +1 -1
  178. package/dist/{server-DoVbqqtJ.js → server-8TS8XCvg.js} +3 -3
  179. package/dist/{server-DoVbqqtJ.js.map → server-8TS8XCvg.js.map} +1 -1
  180. package/dist/{single-run-lock-U58yf8N6.js → single-run-lock-Dekd8_Wv.js} +7 -7
  181. package/dist/single-run-lock-Dekd8_Wv.js.map +1 -0
  182. package/dist/{skillopt-optimization-method-kyL94-ri.js → skillopt-optimization-method-DLKqdhcR.js} +1384 -1059
  183. package/dist/skillopt-optimization-method-DLKqdhcR.js.map +1 -0
  184. package/dist/{statistical-heldout-C9AbgREN.d.ts → statistical-heldout-3z3I-kJN.d.ts} +3 -3
  185. package/dist/{statistical-heldout-C9AbgREN.d.ts.map → statistical-heldout-3z3I-kJN.d.ts.map} +1 -1
  186. package/dist/{store-otlp-BteDAbHK.js → store-otlp-dyWE3wAG.js} +2 -2
  187. package/dist/{store-otlp-BteDAbHK.js.map → store-otlp-dyWE3wAG.js.map} +1 -1
  188. package/dist/{store-tool-spans-D5l_OfTJ.js → store-tool-spans-DIUgZbzu.js} +3 -3
  189. package/dist/{store-tool-spans-D5l_OfTJ.js.map → store-tool-spans-DIUgZbzu.js.map} +1 -1
  190. package/dist/{store-tool-spans-DZS0HWVf.d.ts → store-tool-spans-DPwXHQkH.d.ts} +7 -7
  191. package/dist/{store-tool-spans-DZS0HWVf.d.ts.map → store-tool-spans-DPwXHQkH.d.ts.map} +1 -1
  192. package/dist/{summary-report-DM7tlml1.d.ts → summary-report-C8V49Jt3.d.ts} +18 -3
  193. package/dist/summary-report-C8V49Jt3.d.ts.map +1 -0
  194. package/dist/supervisor-run/index.d.ts.map +1 -1
  195. package/dist/supervisor-run/index.js +3 -3
  196. package/dist/{systemone-Bp_Ac0p1.d.ts → systemone-DVA7t76V.d.ts} +6 -6
  197. package/dist/{systemone-Bp_Ac0p1.d.ts.map → systemone-DVA7t76V.d.ts.map} +1 -1
  198. package/dist/{systemone-review-CwE6JGIp.d.ts → systemone-review-CUBMuTLi.d.ts} +2 -2
  199. package/dist/{systemone-review-CwE6JGIp.d.ts.map → systemone-review-CUBMuTLi.d.ts.map} +1 -1
  200. package/dist/systemone.d.ts +3 -3
  201. package/dist/{terminal-record-78g6E4vh.js → terminal-record-D4Rv-j1W.js} +241 -193
  202. package/dist/{terminal-record-78g6E4vh.js.map → terminal-record-D4Rv-j1W.js.map} +1 -1
  203. package/dist/{tool-groups-DyNz2JZ_.d.ts → tool-groups-LISbBWCg.d.ts} +3 -3
  204. package/dist/tool-groups-LISbBWCg.d.ts.map +1 -0
  205. package/dist/{trace-questions-xxwgsuMi.d.ts → trace-questions-C42fYEE4.d.ts} +4 -4
  206. package/dist/{trace-questions-xxwgsuMi.d.ts.map → trace-questions-C42fYEE4.d.ts.map} +1 -1
  207. package/dist/trace-repair/index.d.ts +3 -3
  208. package/dist/traces.d.ts +6 -6
  209. package/dist/traces.js +3 -3
  210. package/dist/trajectory-replay/index.d.ts +4 -1
  211. package/dist/trajectory-replay/index.d.ts.map +1 -1
  212. package/dist/trajectory-replay/index.js +854 -823
  213. package/dist/trajectory-replay/index.js.map +1 -1
  214. package/dist/{tree-BGRglkKd.js → tree-DSqwJpL9.js} +122 -14
  215. package/dist/tree-DSqwJpL9.js.map +1 -0
  216. package/dist/{types-CW8ewATZ.d.ts → types-8yQzNm8u.d.ts} +4 -4
  217. package/dist/{types-CW8ewATZ.d.ts.map → types-8yQzNm8u.d.ts.map} +1 -1
  218. package/dist/{types-D8GhJoHk.d.ts → types-CHfn1zg5.d.ts} +70 -72
  219. package/dist/types-CHfn1zg5.d.ts.map +1 -0
  220. package/dist/{types-DtMbFw6U.d.ts → types-D8GXK9Z5.d.ts} +3 -3
  221. package/dist/{types-DtMbFw6U.d.ts.map → types-D8GXK9Z5.d.ts.map} +1 -1
  222. package/dist/{types-D-mgRzlh.d.ts → types-eMhdacVp.d.ts} +2 -2
  223. package/dist/{types-D-mgRzlh.d.ts.map → types-eMhdacVp.d.ts.map} +1 -1
  224. package/dist/wire/index.d.ts +3 -3
  225. package/dist/wire/index.js +1 -1
  226. package/docs/campaign-proposers.md +16 -0
  227. package/docs/concepts.md +31 -0
  228. package/docs/design/statistics-decisions.md +1 -1
  229. package/docs/eval-surface-map.md +1 -0
  230. package/docs/profile-json-identity.md +1 -2
  231. package/docs/public-api.md +100 -88
  232. package/package.json +8 -6
  233. package/dist/benchmark-command-xQK8nOI6.js.map +0 -1
  234. package/dist/campaign-CJGkxAQ6.js.map +0 -1
  235. package/dist/campaign-evidence-CQYw8_0H.js.map +0 -1
  236. package/dist/cost-ledger-D0352Z4d.js.map +0 -1
  237. package/dist/cost-ledger-Jk62OBfF.d.ts.map +0 -1
  238. package/dist/define-agent-eval-BDxNlP3D.js.map +0 -1
  239. package/dist/eval-campaign-BLEfBGbA.js +0 -343
  240. package/dist/eval-campaign-BLEfBGbA.js.map +0 -1
  241. package/dist/index-9jJ2fKSX.d.ts.map +0 -1
  242. package/dist/index-CiRwLv2R.d.ts.map +0 -1
  243. package/dist/index-ZuWx52WG.d.ts.map +0 -1
  244. package/dist/integrity-DOd9Q86O.js.map +0 -1
  245. package/dist/journal-CR4QikYp.js.map +0 -1
  246. package/dist/judge-gate-DsL0yFcb.d.ts.map +0 -1
  247. package/dist/llm-client-BshCREn6.js.map +0 -1
  248. package/dist/llm-judge-C8jMTNNG.js.map +0 -1
  249. package/dist/pareto-BzsxidFD.js.map +0 -1
  250. package/dist/render-C-w2EZ6p.js.map +0 -1
  251. package/dist/schema-DxcKTzbi.js.map +0 -1
  252. package/dist/search-ledger-TUvB5gWH.js.map +0 -1
  253. package/dist/single-run-lock-U58yf8N6.js.map +0 -1
  254. package/dist/skillopt-optimization-method-kyL94-ri.js.map +0 -1
  255. package/dist/summary-report-DM7tlml1.d.ts.map +0 -1
  256. package/dist/tool-groups-DyNz2JZ_.d.ts.map +0 -1
  257. package/dist/tree-BGRglkKd.js.map +0 -1
  258. package/dist/types-D8GhJoHk.d.ts.map +0 -1
@@ -1,22 +1,22 @@
1
1
  import { s as ValidationError, t as AgentEvalError } from "./errors-BcOs5MKW.js";
2
2
  import { a as hashCanonical, i as compareCodeUnits, r as canonicalString } from "./canonical-Dq2hOQ8L.js";
3
- import { c as agentProfileModelId, o as agentProfileHash, r as verifyCompletion, s as agentProfileId, u as harnessAxisOf } from "./completion-verifier-B_jw6C9p.js";
3
+ import { c as agentProfileModelId, o as agentProfileHash, r as verifyCompletion, s as agentProfileId, u as harnessAxisOf } from "./completion-verifier-Cigap8CG.js";
4
4
  import { i as buildAgentProfileCell } from "./agent-profile-cell-B1V1gUZs.js";
5
5
  import { c as validateRunRecord, i as modelHasSnapshot, n as UNKNOWN_MODEL, o as runTaskScore } from "./run-record-DhEJgoPz.js";
6
6
  import { t as comparePairedArms } from "./paired-arms-Ct4LTKc1.js";
7
7
  import { i as pairedBootstrap } from "./mean-BbA_JCzW.js";
8
8
  import { o as pairHoldout } from "./statistical-heldout-Bksv92Th.js";
9
9
  import { n as contentHash, t as canonicalJson } from "./verdict-cache-CL_7tePD.js";
10
- import { $ as planCampaignRun, Q as runCampaign, et as resolveRunDir, nt as cellCachePath, rt as computeManifestHash, s as executeOptimizationMethod, u as combineComparisonCosts } from "./llm-judge-C8jMTNNG.js";
10
+ import { $ as planCampaignRun, Q as runCampaign, et as resolveRunDir, nt as cellCachePath, rt as computeManifestHash, s as executeOptimizationMethod, u as combineComparisonCosts } from "./llm-judge-Cc8vDJh_.js";
11
11
  import { n as campaignCellToRunRecord, r as projectCampaignCellQuality, t as campaignCellCostProvenance } from "./run-record-CysKLB93.js";
12
- import { C as assertCodeSurfaceIdentity, D as surfaceContentHash, M as assertRealBackend, N as summarizeBackendIntegrity, P as assertCampaignDesign, R as campaignScenarioIdentity } from "./campaign-evidence-CQYw8_0H.js";
13
- import { a as mapConcurrent } from "./journal-CR4QikYp.js";
14
- import { M as fsCampaignStorage } from "./external-optimizer-subprocess-XIHBOSKt.js";
15
- import "./pareto-BzsxidFD.js";
16
- import "./search-ledger-TUvB5gWH.js";
17
- import "./search-summary-DQIvJsSB.js";
18
- import "./external-optimizer-process-KVFGvYX1.js";
19
- import "./skillopt-optimization-method-kyL94-ri.js";
12
+ import { C as assertCodeSurfaceIdentity, D as surfaceContentHash, M as assertRealBackend, N as summarizeBackendIntegrity, P as assertCampaignDesign, R as campaignScenarioIdentity } from "./campaign-evidence-DunzcJGv.js";
13
+ import { a as mapConcurrent } from "./journal-C7om8Gum.js";
14
+ import { M as fsCampaignStorage } from "./external-optimizer-subprocess-D670Oxf2.js";
15
+ import "./pareto-BiBnQXAE.js";
16
+ import "./search-ledger-CZRqtFbW.js";
17
+ import "./search-summary-D4bwYnAE.js";
18
+ import "./external-optimizer-process-wOLfzsCC.js";
19
+ import "./skillopt-optimization-method-DLKqdhcR.js";
20
20
  import "./sequential-CimQrbjv.js";
21
21
  import { createHash } from "node:crypto";
22
22
  import { closeSync, constants, existsSync, fstatSync, lstatSync, mkdirSync, mkdtempSync, openSync, readFileSync, readSync, readdirSync, readlinkSync, realpathSync, rmSync, statSync } from "node:fs";
@@ -24,6 +24,145 @@ import { z } from "zod";
24
24
  import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
25
25
  import { devNull, tmpdir } from "node:os";
26
26
  import { execFileSync } from "node:child_process";
27
+ //#region src/campaign/cost-breakdown.ts
28
+ /** Read the source rates for this execution, never a copied model price table.
29
+ * inputTokens includes cachedTokens. Seat credits are standard model credits;
30
+ * discounts and MCP charges require provider observations, not token guesses.
31
+ * The existing USD receipt remains the Router charge. Sandbox is additional.
32
+ */
33
+ async function measureCampaignCost(input) {
34
+ const sources = [];
35
+ const unknown = {
36
+ kind: "uncaptured",
37
+ usd: null
38
+ };
39
+ if (input.routerUsd !== void 0) finite(input.routerUsd, "routerUsd");
40
+ const result = {
41
+ router: input.routerUsd === void 0 ? unknown : {
42
+ kind: "observed",
43
+ usd: input.routerUsd
44
+ },
45
+ sandbox: unknown,
46
+ seatCredits: {
47
+ kind: "uncaptured",
48
+ credits: null,
49
+ reason: "No seat usage supplied"
50
+ },
51
+ sources
52
+ };
53
+ const read = async (url) => {
54
+ const response = await fetch(url, { signal: input.signal ? AbortSignal.any([input.signal, AbortSignal.timeout(15e3)]) : AbortSignal.timeout(15e3) });
55
+ if (!response.ok) throw new Error(`Rate source HTTP ${response.status}`);
56
+ if (Number(response.headers.get("content-length")) > 1e6) throw new Error("Rate source too large");
57
+ const chunks = [];
58
+ let bytes = 0;
59
+ for await (const chunk of response.body ?? []) {
60
+ bytes += chunk.byteLength;
61
+ if (bytes > 1e6) throw new Error("Rate source too large");
62
+ chunks.push(chunk);
63
+ }
64
+ const text = Buffer.concat(chunks).toString("utf8");
65
+ return {
66
+ text,
67
+ snapshot: {
68
+ url,
69
+ readAt: (/* @__PURE__ */ new Date()).toISOString(),
70
+ sha256: createHash("sha256").update(text).digest("hex")
71
+ }
72
+ };
73
+ };
74
+ if (input.sandbox) {
75
+ for (const [key, value] of Object.entries(input.sandbox)) if (key !== "pool") finite(value, `sandbox.${key}`);
76
+ try {
77
+ const { text, snapshot } = await read("https://sandbox.tangle.tools/v1/pricing/sandboxes");
78
+ const card = JSON.parse(text).pools?.[input.sandbox.pool ?? "general"];
79
+ const rates = {};
80
+ for (const key of [
81
+ "cpuCoreHourUsd",
82
+ "memoryGBHourUsd",
83
+ "diskGBHourUsd",
84
+ "minChargeHourUsd"
85
+ ]) {
86
+ finite(card?.[key], key);
87
+ rates[key] = card[key];
88
+ }
89
+ const s = input.sandbox;
90
+ const usd = Math.max(rates.minChargeHourUsd, s.cpu * rates.cpuCoreHourUsd + s.memoryGB * rates.memoryGBHourUsd + s.diskGB * rates.diskGBHourUsd) * s.seconds / 3600;
91
+ finite(usd, "sandbox USD estimate");
92
+ result.sandbox = {
93
+ kind: "estimated",
94
+ usd
95
+ };
96
+ sources.push({
97
+ ...snapshot,
98
+ rates
99
+ });
100
+ } catch {}
101
+ }
102
+ if (input.seat) {
103
+ const { usage, model } = input.seat;
104
+ if (usage.usageUnknown || usage.cachedTokens === void 0) {
105
+ result.seatCredits = {
106
+ kind: "uncaptured",
107
+ credits: null,
108
+ reason: "Seat token or cached-input usage is unknown"
109
+ };
110
+ return result;
111
+ }
112
+ for (const key of [
113
+ "inputTokens",
114
+ "cachedTokens",
115
+ "outputTokens"
116
+ ]) {
117
+ const value = usage[key];
118
+ if (!Number.isSafeInteger(value) || value < 0) throw new Error(`seat.${key} must be a known nonnegative token count`);
119
+ }
120
+ if (usage.cachedTokens > usage.inputTokens) throw new Error("cachedTokens exceeds inputTokens");
121
+ try {
122
+ const { text, snapshot } = await read("https://docs.z.ai/devpack/overview.md");
123
+ const modelName = model.split("/").at(-1).toLowerCase();
124
+ const section = text.split("#### Credit Calculation")[1]?.split("#### Estimated Token Allowance")[0];
125
+ if (!section) throw new Error("Credit calculation section unavailable");
126
+ const matching = [...section.matchAll(/<tr>\s*([\s\S]*?)<\/tr>/gu)].filter((row) => {
127
+ return [...row[1].matchAll(/<td\b[^>]*>([\s\S]*?)<\/td>/gu)].map((cell) => cell[1].trim()).some((cell) => cell.split(/\\|\n|</u)[0].trim().toLowerCase() === modelName);
128
+ });
129
+ if (matching.length !== 1) throw new Error(`No unique live credit row for '${model}'`);
130
+ const rateCells = [...matching[0][1].matchAll(/<td\b[^>]*>([\s\S]*?)<\/td>/gu)].map((cell) => cell[1].trim()).slice(-3);
131
+ if (rateCells.length !== 3 || rateCells.some((cell) => !/^(?:\d+)(?:\.\d+)?$/u.test(cell))) throw new Error("Invalid live credit multipliers");
132
+ const multipliers = rateCells.map(Number);
133
+ for (const rate of multipliers) finite(rate, "credit multiplier");
134
+ const divisor = Number(section.match(/Model credit usage[^\n]*\/\s*([\d,]+)/u)?.[1]?.replaceAll(",", ""));
135
+ if (!Number.isFinite(divisor) || divisor <= 0) throw new Error("No live credit divisor");
136
+ const [fresh, cached, output] = multipliers;
137
+ const credits = ((usage.inputTokens - usage.cachedTokens) * fresh + usage.cachedTokens * cached + usage.outputTokens * output) / divisor;
138
+ finite(credits, "standard seat credits");
139
+ result.seatCredits = {
140
+ kind: "estimated",
141
+ credits
142
+ };
143
+ sources.push({
144
+ ...snapshot,
145
+ rates: {
146
+ inputMultiplier: fresh,
147
+ cachedInputMultiplier: cached,
148
+ outputMultiplier: output,
149
+ divisor
150
+ }
151
+ });
152
+ } catch (error) {
153
+ result.seatCredits = {
154
+ kind: "uncaptured",
155
+ credits: null,
156
+ reason: error instanceof Error ? error.message : "Credit source unavailable"
157
+ };
158
+ }
159
+ }
160
+ return result;
161
+ }
162
+ function finite(value, label) {
163
+ if (typeof value !== "number" || !Number.isFinite(value) || value < 0) throw new Error(`${label} must be finite and nonnegative`);
164
+ }
165
+ //#endregion
27
166
  //#region src/campaign/cross-surface-context.ts
28
167
  function validateCrossSurfaceInput(input) {
29
168
  assertNonEmptyUnique(input.taskOrder, "taskOrder");
@@ -2036,6 +2175,9 @@ const anchorEntrySchema = z.object({
2036
2175
  bytes: z.number().int().positive(),
2037
2176
  digest
2038
2177
  }).strict();
2178
+ function fail(message) {
2179
+ throw new ValidationError(`retained dispatch: ${message}`);
2180
+ }
2039
2181
  /**
2040
2182
  * Persist dispatch intent before an external call and its validated result afterward.
2041
2183
  * Replays settled calls; never repeats an uncertain call or refunds its allowance.
@@ -2047,157 +2189,192 @@ const anchorEntrySchema = z.object({
2047
2189
  function createRetainedDispatch(options) {
2048
2190
  if (!options.runDir.trim()) throw new ValidationError("retained dispatch requires a run directory");
2049
2191
  const storage = options.storage ?? fsCampaignStorage();
2050
- const parse = options.parse;
2051
2192
  const header = headerSchema.parse({
2052
2193
  kind: "retained-dispatch-v1",
2053
2194
  scope: hashCanonical(options.scope),
2054
2195
  limits: Object.entries(options.limits).sort(([a], [b]) => compareCodeUnits(a, b))
2055
2196
  });
2056
2197
  if (!header.limits.length) throw new ValidationError("retained dispatch requires named allowances");
2057
- const limits = new Map(header.limits);
2058
- const counts = /* @__PURE__ */ new Map();
2059
- const calls = /* @__PURE__ */ new Map();
2198
+ const journal = {
2199
+ storage,
2200
+ parse: options.parse,
2201
+ header,
2202
+ limits: new Map(header.limits),
2203
+ counts: /* @__PURE__ */ new Map(),
2204
+ calls: /* @__PURE__ */ new Map(),
2205
+ indexPath: join(options.runDir, "dispatches.jsonl"),
2206
+ scopePath: join(options.runDir, "dispatch-scope.json"),
2207
+ anchorPath: join(options.runDir, "dispatch-anchor.jsonl"),
2208
+ receiptsDir: join(options.runDir, "dispatch-results"),
2209
+ scopeText: canonicalString(header),
2210
+ scopeDigest: hashCanonical(header),
2211
+ retainedText: "",
2212
+ revision: 0,
2213
+ chain: null,
2214
+ opened: false
2215
+ };
2060
2216
  const active = /* @__PURE__ */ new Map();
2061
- const indexPath = join(options.runDir, "dispatches.jsonl");
2062
- const scopePath = join(options.runDir, "dispatch-scope.json");
2063
- const anchorPath = join(options.runDir, "dispatch-anchor.jsonl");
2064
- const scopeText = canonicalString(header);
2065
- const scopeDigest = hashCanonical(header);
2066
- const receiptsDir = join(options.runDir, "dispatch-results");
2067
- const resultPath = (id) => join(receiptsDir, `${id.slice(7)}.json`);
2068
2217
  storage.ensureDir(options.runDir);
2069
- storage.ensureDir(receiptsDir);
2070
- let retainedText = "";
2071
- let revision = 0;
2072
- let chain = null;
2073
- let opened = false;
2074
- const fail = (message) => {
2075
- throw new ValidationError(`retained dispatch: ${message}`);
2076
- };
2077
- const apply = (event) => {
2078
- const existing = calls.get(event.id);
2079
- if (event.kind === "started") {
2080
- const limit = limits.get(event.lane);
2081
- const count = counts.get(event.lane) ?? 0;
2082
- if (existing || limit === void 0 || count >= limit) fail("invalid or over-budget dispatch history");
2083
- calls.set(event.id, { lane: event.lane });
2084
- counts.set(event.lane, count + 1);
2085
- } else {
2086
- if (!existing || existing.receipt) return fail("settlement has no unique pending dispatch");
2087
- existing.receipt = event.receipt;
2088
- }
2089
- };
2090
- const readAnchor = () => {
2091
- const content = storage.read(anchorPath);
2092
- if (content === void 0 && storage.exists(anchorPath)) fail("cannot read durable anchor");
2093
- const text = content ?? "";
2094
- if (text && !text.endsWith("\n")) fail("durable anchor is torn");
2095
- const entries = [];
2096
- let previous = 0;
2097
- const lines = text.split("\n");
2098
- if (lines.at(-1) === "") lines.pop();
2099
- if (lines.some((line) => !line)) fail("durable anchor contains an empty record");
2100
- for (const line of lines) {
2101
- const entry = anchorEntrySchema.parse(JSON.parse(line));
2102
- if (entry.scope !== scopeDigest) fail("durable anchor scope changed");
2103
- if (entry.bytes <= previous) fail("durable anchor is not append-only");
2104
- previous = entry.bytes;
2105
- entries.push(entry);
2106
- }
2107
- return {
2108
- text,
2109
- entries
2110
- };
2111
- };
2112
- const refresh = () => {
2113
- if (storage.read(scopePath) !== scopeText) fail("scope anchor is missing or changed");
2114
- const stored = storage.read(indexPath);
2115
- if (stored === void 0 && storage.exists(indexPath)) fail("cannot read existing history");
2116
- const text = stored ?? "";
2117
- if (!text.startsWith(retainedText) || text && !text.endsWith("\n")) fail("history was truncated, replaced or torn");
2118
- const { entries } = readAnchor();
2119
- const bytes = Buffer.byteLength(text);
2120
- const applied = Buffer.byteLength(retainedText);
2121
- if (text && !entries.length) fail("durable anchor is missing");
2122
- const highWater = entries[entries.length - 1];
2123
- if (highWater && bytes !== highWater.bytes) {
2124
- if (bytes < highWater.bytes) fail("history was truncated below its durable anchor");
2125
- fail("history extends beyond its durable anchor");
2126
- }
2127
- let offset = 0;
2128
- let running = null;
2129
- let entryIndex = 0;
2130
- let seenHeader = opened;
2131
- for (const line of text.split("\n")) {
2132
- if (!line) continue;
2133
- running = hashCanonical([running, line]);
2134
- offset += Buffer.byteLength(line) + 1;
2135
- while (entryIndex < entries.length && entries[entryIndex].bytes === offset) {
2136
- if (entries[entryIndex].digest !== running) fail("history diverges from its durable anchor");
2137
- entryIndex += 1;
2138
- }
2139
- if (offset <= applied) continue;
2140
- if (!seenHeader) {
2141
- const value = JSON.parse(line);
2142
- if (hashCanonical(headerSchema.parse(value)) !== hashCanonical(header)) fail("resume changed its scope or allowances");
2143
- seenHeader = true;
2144
- } else apply(eventSchema.parse(JSON.parse(line)));
2218
+ storage.ensureDir(journal.receiptsDir);
2219
+ openJournal(journal, options.requireExisting);
2220
+ return {
2221
+ /** The input binds all behavior-affecting request material, not just a caller-selected nonce. */
2222
+ run(request) {
2223
+ const id = hashCanonical([
2224
+ header.scope,
2225
+ request.lane,
2226
+ request.input
2227
+ ]);
2228
+ const pending = active.get(id);
2229
+ if (pending) return pending;
2230
+ const promise = dispatchOnce(journal, id, request);
2231
+ active.set(id, promise);
2232
+ promise.finally(() => {
2233
+ active.delete(id);
2234
+ }).catch(() => {});
2235
+ return promise;
2236
+ },
2237
+ /** Counts include uncertain dispatches, which keep their reservation. No pricing is inferred. */
2238
+ committed() {
2239
+ refreshJournal(journal);
2240
+ return new Map(header.limits.map(([lane]) => [lane, journal.counts.get(lane) ?? 0]));
2145
2241
  }
2146
- if (entries.length && entryIndex !== entries.length) fail("history diverges from its durable anchor");
2147
- chain = running;
2148
- retainedText = text;
2149
- revision = bytes;
2150
- opened = seenHeader;
2151
2242
  };
2152
- const append = (event) => {
2153
- const encoded = canonicalString(event);
2154
- const line = `${encoded}\n`;
2155
- const next = storage.append(indexPath, line, revision);
2156
- if (next === void 0) {
2157
- refresh();
2158
- return false;
2159
- }
2160
- if (next !== revision + Buffer.byteLength(line)) fail("storage returned an invalid append revision");
2161
- chain = hashCanonical([chain, encoded]);
2162
- retainedText += line;
2163
- revision = next;
2164
- if (event.kind === "retained-dispatch-v1") opened = true;
2165
- else apply(event);
2166
- return true;
2243
+ }
2244
+ /** Fold one journal event into the per-lane counts and pending-call map. */
2245
+ function applyEvent(journal, event) {
2246
+ const existing = journal.calls.get(event.id);
2247
+ if (event.kind === "started") {
2248
+ const limit = journal.limits.get(event.lane);
2249
+ const count = journal.counts.get(event.lane) ?? 0;
2250
+ if (existing || limit === void 0 || count >= limit) fail("invalid or over-budget dispatch history");
2251
+ journal.calls.set(event.id, { lane: event.lane });
2252
+ journal.counts.set(event.lane, count + 1);
2253
+ } else {
2254
+ if (!existing || existing.receipt) fail("settlement has no unique pending dispatch");
2255
+ existing.receipt = event.receipt;
2256
+ }
2257
+ }
2258
+ /** Read the durable anchor file, refusing a torn, empty-record, foreign-scope or non-monotonic one. */
2259
+ function readAnchor(journal) {
2260
+ const { storage, anchorPath } = journal;
2261
+ const content = storage.read(anchorPath);
2262
+ if (content === void 0 && storage.exists(anchorPath)) fail("cannot read durable anchor");
2263
+ const text = content ?? "";
2264
+ if (text && !text.endsWith("\n")) fail("durable anchor is torn");
2265
+ const entries = [];
2266
+ let previous = 0;
2267
+ const lines = text.split("\n");
2268
+ if (lines.at(-1) === "") lines.pop();
2269
+ if (lines.some((line) => !line)) fail("durable anchor contains an empty record");
2270
+ for (const line of lines) {
2271
+ const entry = anchorEntrySchema.parse(JSON.parse(line));
2272
+ if (entry.scope !== journal.scopeDigest) fail("durable anchor scope changed");
2273
+ if (entry.bytes <= previous) fail("durable anchor is not append-only");
2274
+ previous = entry.bytes;
2275
+ entries.push(entry);
2276
+ }
2277
+ return {
2278
+ text,
2279
+ entries
2167
2280
  };
2168
- const advanceAnchor = () => {
2169
- const currentChain = chain ?? fail("cannot anchor an empty history");
2170
- if (revision <= 0) fail("cannot anchor an empty history");
2171
- const { text, entries } = readAnchor();
2172
- const last = entries[entries.length - 1];
2173
- if (last) {
2174
- if (last.bytes > revision) fail("history is behind its durable anchor");
2175
- if (last.bytes === revision) {
2176
- if (last.digest !== currentChain) fail("history diverges from its durable anchor");
2177
- return;
2178
- }
2281
+ }
2282
+ /** Re-read the journal, prove it extends what was applied and matches its anchor, and apply the new events. */
2283
+ function refreshJournal(journal) {
2284
+ const { storage } = journal;
2285
+ if (storage.read(journal.scopePath) !== journal.scopeText) fail("scope anchor is missing or changed");
2286
+ const stored = storage.read(journal.indexPath);
2287
+ if (stored === void 0 && storage.exists(journal.indexPath)) fail("cannot read existing history");
2288
+ const text = stored ?? "";
2289
+ if (!text.startsWith(journal.retainedText) || text && !text.endsWith("\n")) fail("history was truncated, replaced or torn");
2290
+ const { entries } = readAnchor(journal);
2291
+ const bytes = Buffer.byteLength(text);
2292
+ const applied = Buffer.byteLength(journal.retainedText);
2293
+ if (text && !entries.length) fail("durable anchor is missing");
2294
+ const highWater = entries[entries.length - 1];
2295
+ if (highWater && bytes !== highWater.bytes) {
2296
+ if (bytes < highWater.bytes) fail("history was truncated below its durable anchor");
2297
+ fail("history extends beyond its durable anchor");
2298
+ }
2299
+ let offset = 0;
2300
+ let running = null;
2301
+ let entryIndex = 0;
2302
+ let seenHeader = journal.opened;
2303
+ for (const line of text.split("\n")) {
2304
+ if (!line) continue;
2305
+ running = hashCanonical([running, line]);
2306
+ offset += Buffer.byteLength(line) + 1;
2307
+ while (entryIndex < entries.length && entries[entryIndex].bytes === offset) {
2308
+ if (entries[entryIndex].digest !== running) fail("history diverges from its durable anchor");
2309
+ entryIndex += 1;
2179
2310
  }
2180
- const line = `${canonicalString({
2181
- kind: "retained-dispatch-anchor-v1",
2182
- scope: scopeDigest,
2183
- bytes: revision,
2184
- digest: currentChain
2185
- })}\n`;
2186
- const next = storage.append(anchorPath, line, Buffer.byteLength(text));
2187
- if (next === void 0) {
2188
- const concurrent = readAnchor().entries.at(-1);
2189
- if (concurrent?.bytes === revision && concurrent.digest === chain) return;
2190
- fail("durable anchor append is busy; retry with the same run directory");
2311
+ if (offset <= applied) continue;
2312
+ if (!seenHeader) {
2313
+ const value = JSON.parse(line);
2314
+ if (hashCanonical(headerSchema.parse(value)) !== hashCanonical(journal.header)) fail("resume changed its scope or allowances");
2315
+ seenHeader = true;
2316
+ } else applyEvent(journal, eventSchema.parse(JSON.parse(line)));
2317
+ }
2318
+ if (entries.length && entryIndex !== entries.length) fail("history diverges from its durable anchor");
2319
+ journal.chain = running;
2320
+ journal.retainedText = text;
2321
+ journal.revision = bytes;
2322
+ journal.opened = seenHeader;
2323
+ }
2324
+ /** Compare-and-append one event; a lost race refreshes the journal and returns false. */
2325
+ function appendEvent(journal, event) {
2326
+ const encoded = canonicalString(event);
2327
+ const line = `${encoded}\n`;
2328
+ const next = journal.storage.append(journal.indexPath, line, journal.revision);
2329
+ if (next === void 0) {
2330
+ refreshJournal(journal);
2331
+ return false;
2332
+ }
2333
+ if (next !== journal.revision + Buffer.byteLength(line)) fail("storage returned an invalid append revision");
2334
+ journal.chain = hashCanonical([journal.chain, encoded]);
2335
+ journal.retainedText += line;
2336
+ journal.revision = next;
2337
+ if (event.kind === "retained-dispatch-v1") journal.opened = true;
2338
+ else applyEvent(journal, event);
2339
+ return true;
2340
+ }
2341
+ /** Record the journal's current length and digest in the durable anchor. */
2342
+ function advanceAnchor(journal) {
2343
+ const currentChain = journal.chain ?? fail("cannot anchor an empty history");
2344
+ if (journal.revision <= 0) fail("cannot anchor an empty history");
2345
+ const { text, entries } = readAnchor(journal);
2346
+ const last = entries[entries.length - 1];
2347
+ if (last) {
2348
+ if (last.bytes > journal.revision) fail("history is behind its durable anchor");
2349
+ if (last.bytes === journal.revision) {
2350
+ if (last.digest !== currentChain) fail("history diverges from its durable anchor");
2351
+ return;
2191
2352
  }
2192
- if (next !== Buffer.byteLength(text) + Buffer.byteLength(line)) fail("storage returned an invalid durable anchor revision");
2193
- };
2194
- /** An event takes effect only after both its journal append and its anchor entry are durable. */
2195
- const commit = (event) => {
2196
- if (!append(event)) return false;
2197
- advanceAnchor();
2198
- return true;
2199
- };
2200
- if (options.requireExisting && (!storage.exists(scopePath) || !storage.exists(indexPath) || !storage.exists(anchorPath))) fail("required retained history is missing");
2353
+ }
2354
+ const line = `${canonicalString({
2355
+ kind: "retained-dispatch-anchor-v1",
2356
+ scope: journal.scopeDigest,
2357
+ bytes: journal.revision,
2358
+ digest: currentChain
2359
+ })}\n`;
2360
+ const next = journal.storage.append(journal.anchorPath, line, Buffer.byteLength(text));
2361
+ if (next === void 0) {
2362
+ const concurrent = readAnchor(journal).entries.at(-1);
2363
+ if (concurrent?.bytes === journal.revision && concurrent.digest === journal.chain) return;
2364
+ fail("durable anchor append is busy; retry with the same run directory");
2365
+ }
2366
+ if (next !== Buffer.byteLength(text) + Buffer.byteLength(line)) fail("storage returned an invalid durable anchor revision");
2367
+ }
2368
+ /** An event takes effect only after both its journal append and its anchor entry are durable. */
2369
+ function commitEvent(journal, event) {
2370
+ if (!appendEvent(journal, event)) return false;
2371
+ advanceAnchor(journal);
2372
+ return true;
2373
+ }
2374
+ /** Create or verify the scope anchor, load existing history, and commit the header on a fresh journal. */
2375
+ function openJournal(journal, requireExisting) {
2376
+ const { storage, scopePath, indexPath, anchorPath, scopeText } = journal;
2377
+ if (requireExisting && (!storage.exists(scopePath) || !storage.exists(indexPath) || !storage.exists(anchorPath))) fail("required retained history is missing");
2201
2378
  if (storage.exists(scopePath)) {
2202
2379
  if (storage.read(scopePath) !== scopeText) fail("resume changed its scope or allowances");
2203
2380
  if (!storage.read(indexPath)?.trim()) fail("dispatch history is missing or empty");
@@ -2209,145 +2386,138 @@ function createRetainedDispatch(options) {
2209
2386
  if (storage.read(scopePath) !== scopeText || !storage.read(indexPath)?.trim()) fail("scope initialization is busy; retry the same scope");
2210
2387
  } else if (created !== Buffer.byteLength(scopeText)) fail("storage returned an invalid scope revision");
2211
2388
  }
2212
- refresh();
2213
- if (!opened && !commit(header) && !opened) fail("history is busy; retry with the same run directory");
2214
- const readResult = (id) => {
2215
- const content = storage.read(resultPath(id));
2216
- if (content === void 0) return void 0;
2217
- const result = resultSchema.parse(JSON.parse(content));
2218
- if (result.id !== id) return fail("retained result dispatch id mismatch");
2219
- if (hashCanonical(result.value) !== result.receipt) return fail("retained result digest mismatch");
2220
- const value = parse(result.value);
2221
- if (hashCanonical(value) !== result.receipt) return fail("result decoder changed retained output");
2222
- return {
2223
- value,
2224
- receipt: result.receipt
2225
- };
2389
+ refreshJournal(journal);
2390
+ if (!journal.opened && !commitEvent(journal, journal.header) && !journal.opened) fail("history is busy; retry with the same run directory");
2391
+ }
2392
+ /** Read and verify a retained result file, or undefined when none was written. */
2393
+ function readResult(journal, id) {
2394
+ const content = journal.storage.read(resultPath(journal, id));
2395
+ if (content === void 0) return void 0;
2396
+ const result = resultSchema.parse(JSON.parse(content));
2397
+ if (result.id !== id) return fail("retained result dispatch id mismatch");
2398
+ if (hashCanonical(result.value) !== result.receipt) return fail("retained result digest mismatch");
2399
+ const value = journal.parse(result.value);
2400
+ if (hashCanonical(value) !== result.receipt) return fail("result decoder changed retained output");
2401
+ return {
2402
+ value,
2403
+ receipt: result.receipt
2226
2404
  };
2227
- const settle = (id, receipt) => {
2228
- while (true) {
2229
- const existing = calls.get(id);
2230
- if (existing?.receipt) {
2231
- if (existing.receipt !== receipt) fail("settled result digest mismatch");
2232
- return;
2233
- }
2234
- if (!existing) fail("settlement has no pending dispatch");
2235
- const previousRevision = revision;
2236
- if (commit({
2237
- kind: "settled",
2238
- id,
2239
- receipt
2240
- })) return;
2241
- if (revision === previousRevision) fail("settlement is busy; retained result awaits reconciliation");
2405
+ }
2406
+ function resultPath(journal, id) {
2407
+ return join(journal.receiptsDir, `${id.slice(7)}.json`);
2408
+ }
2409
+ /** Commit the settlement of a dispatch whose result is already durable. */
2410
+ function settle(journal, id, receipt) {
2411
+ while (true) {
2412
+ const existing = journal.calls.get(id);
2413
+ if (existing?.receipt) {
2414
+ if (existing.receipt !== receipt) fail("settled result digest mismatch");
2415
+ return;
2242
2416
  }
2243
- };
2244
- const load = (id, receipt) => {
2245
- const result = readResult(id);
2246
- if (!result) return fail("settled result is missing");
2247
- if (result.receipt !== receipt) return fail("settled result digest mismatch");
2248
- return {
2249
- succeeded: true,
2250
- value: result.value,
2251
- dispatchId: id,
2252
- receiptDigest: receipt,
2253
- replayed: true
2254
- };
2255
- };
2417
+ if (!existing) fail("settlement has no pending dispatch");
2418
+ const previousRevision = journal.revision;
2419
+ if (commitEvent(journal, {
2420
+ kind: "settled",
2421
+ id,
2422
+ receipt
2423
+ })) return;
2424
+ if (journal.revision === previousRevision) fail("settlement is busy; retained result awaits reconciliation");
2425
+ }
2426
+ }
2427
+ /** Replay a settled dispatch from its retained result. */
2428
+ function loadSettled(journal, id, receipt) {
2429
+ const result = readResult(journal, id);
2430
+ if (!result) return fail("settled result is missing");
2431
+ if (result.receipt !== receipt) return fail("settled result digest mismatch");
2256
2432
  return {
2257
- /** The input binds all behavior-affecting request material, not just a caller-selected nonce. */
2258
- run(request) {
2259
- const { lane, dispatch, signal } = request;
2260
- const id = hashCanonical([
2261
- header.scope,
2262
- lane,
2263
- request.input
2264
- ]);
2265
- const pending = active.get(id);
2266
- if (pending) return pending;
2267
- const work = async () => {
2268
- if (!limits.has(lane)) return fail("unknown allowance lane");
2269
- refresh();
2270
- while (true) {
2271
- const existing = calls.get(id);
2272
- if (existing) {
2273
- if (existing.receipt) return load(id, existing.receipt);
2274
- const result = readResult(id);
2275
- if (!result) return {
2276
- succeeded: false,
2277
- reason: "outcome_unknown",
2278
- dispatchId: id
2279
- };
2280
- settle(id, result.receipt);
2281
- return {
2282
- succeeded: true,
2283
- value: result.value,
2284
- dispatchId: id,
2285
- receiptDigest: result.receipt,
2286
- replayed: true
2287
- };
2288
- }
2289
- signal?.throwIfAborted();
2290
- if ((counts.get(lane) ?? 0) >= limits.get(lane)) return {
2291
- succeeded: false,
2292
- reason: "allowance_exhausted",
2293
- dispatchId: id
2294
- };
2295
- const previousRevision = revision;
2296
- if (commit({
2297
- kind: "started",
2298
- id,
2299
- lane
2300
- })) break;
2301
- if (revision === previousRevision) return fail("history is busy; retry with the same input");
2302
- }
2303
- let value;
2304
- try {
2305
- signal?.throwIfAborted();
2306
- value = parse(await dispatch());
2307
- } catch (error) {
2308
- return {
2309
- succeeded: false,
2310
- reason: "outcome_unknown",
2311
- dispatchId: id,
2312
- diagnostic: error instanceof Error ? error.message : String(error)
2313
- };
2314
- }
2315
- const encoded = canonicalString(value);
2316
- const decoded = JSON.parse(encoded);
2317
- const retainedValue = parse(decoded);
2318
- if (canonicalString(retainedValue) !== encoded) return fail("result decoder is not stable across serialization");
2319
- const receipt = hashCanonical(decoded);
2320
- const retainedResult = canonicalString({
2321
- kind: "retained-dispatch-result-v1",
2322
- id,
2323
- receipt,
2324
- value: decoded
2325
- });
2326
- const file = resultPath(id);
2327
- if (storage.append(file, retainedResult, 0) === void 0 && storage.read(file) !== retainedResult) fail("cannot retain dispatch result");
2328
- settle(id, receipt);
2329
- return {
2330
- succeeded: true,
2331
- value: retainedValue,
2332
- dispatchId: id,
2333
- receiptDigest: receipt,
2334
- replayed: false
2335
- };
2433
+ succeeded: true,
2434
+ value: result.value,
2435
+ dispatchId: id,
2436
+ receiptDigest: receipt,
2437
+ replayed: true
2438
+ };
2439
+ }
2440
+ /** Replay a known dispatch, or commit its started intent; returns the outcome when no call should be made. */
2441
+ function claimDispatch(journal, id, lane, signal) {
2442
+ while (true) {
2443
+ const existing = journal.calls.get(id);
2444
+ if (existing) {
2445
+ if (existing.receipt) return loadSettled(journal, id, existing.receipt);
2446
+ const result = readResult(journal, id);
2447
+ if (!result) return {
2448
+ succeeded: false,
2449
+ reason: "outcome_unknown",
2450
+ dispatchId: id
2451
+ };
2452
+ settle(journal, id, result.receipt);
2453
+ return {
2454
+ succeeded: true,
2455
+ value: result.value,
2456
+ dispatchId: id,
2457
+ receiptDigest: result.receipt,
2458
+ replayed: true
2336
2459
  };
2337
- const promise = work();
2338
- active.set(id, promise);
2339
- promise.finally(() => {
2340
- active.delete(id);
2341
- }).catch(() => {});
2342
- return promise;
2343
- },
2344
- /** Counts include uncertain dispatches, which keep their reservation. No pricing is inferred. */
2345
- committed() {
2346
- refresh();
2347
- return new Map(header.limits.map(([lane]) => [lane, counts.get(lane) ?? 0]));
2348
2460
  }
2461
+ signal?.throwIfAborted();
2462
+ if ((journal.counts.get(lane) ?? 0) >= journal.limits.get(lane)) return {
2463
+ succeeded: false,
2464
+ reason: "allowance_exhausted",
2465
+ dispatchId: id
2466
+ };
2467
+ const previousRevision = journal.revision;
2468
+ if (commitEvent(journal, {
2469
+ kind: "started",
2470
+ id,
2471
+ lane
2472
+ })) return void 0;
2473
+ if (journal.revision === previousRevision) return fail("history is busy; retry with the same input");
2474
+ }
2475
+ }
2476
+ /** Retain a dispatched value's result file, settle it, and return the decoded outcome. */
2477
+ function retainResult(journal, id, value) {
2478
+ const encoded = canonicalString(value);
2479
+ const decoded = JSON.parse(encoded);
2480
+ const retainedValue = journal.parse(decoded);
2481
+ if (canonicalString(retainedValue) !== encoded) return fail("result decoder is not stable across serialization");
2482
+ const receipt = hashCanonical(decoded);
2483
+ const retainedResult = canonicalString({
2484
+ kind: "retained-dispatch-result-v1",
2485
+ id,
2486
+ receipt,
2487
+ value: decoded
2488
+ });
2489
+ const file = resultPath(journal, id);
2490
+ if (journal.storage.append(file, retainedResult, 0) === void 0 && journal.storage.read(file) !== retainedResult) fail("cannot retain dispatch result");
2491
+ settle(journal, id, receipt);
2492
+ return {
2493
+ succeeded: true,
2494
+ value: retainedValue,
2495
+ dispatchId: id,
2496
+ receiptDigest: receipt,
2497
+ replayed: false
2349
2498
  };
2350
2499
  }
2500
+ /** Replay, claim an allowance, call the dispatch once, and retain its result. */
2501
+ async function dispatchOnce(journal, id, request) {
2502
+ const { lane, dispatch, signal } = request;
2503
+ if (!journal.limits.has(lane)) return fail("unknown allowance lane");
2504
+ refreshJournal(journal);
2505
+ const claimed = claimDispatch(journal, id, lane, signal);
2506
+ if (claimed) return claimed;
2507
+ let value;
2508
+ try {
2509
+ signal?.throwIfAborted();
2510
+ value = journal.parse(await dispatch());
2511
+ } catch (error) {
2512
+ return {
2513
+ succeeded: false,
2514
+ reason: "outcome_unknown",
2515
+ dispatchId: id,
2516
+ diagnostic: error instanceof Error ? error.message : String(error)
2517
+ };
2518
+ }
2519
+ return retainResult(journal, id, value);
2520
+ }
2351
2521
  //#endregion
2352
2522
  //#region src/campaign/scenario-selection.ts
2353
2523
  const DEFAULT_SATURATION_CEILING = .999;
@@ -2925,6 +3095,6 @@ function resolveWorktreePath(surface, worktreeDir) {
2925
3095
  return verifyCodeSurface(surface, worktreeDir).path;
2926
3096
  }
2927
3097
  //#endregion
2928
- export { analyzeCrossSurfaceInteractions as S, neutralizationGate as _, createRetainedDispatch as a, loadEvalFixtureScenarios as b, runProfileMatrixSegment as c, scoreUserStory as d, scoreboardSummary as f, neutralizeText as g, sequentialOptimizationMethod as h, scoreDiscrimination as i, runProfileMatrix as l, scopedOptimizationMethod as m, resolveWorktreePath as n, createProfileMatrixPlan as o, userStoryScoreboard as p, verifyCodeSurface as r, finalizeProfileMatrix as s, gitWorktreeAdapter as t, renderScoreboardMarkdown as u, discoverEvalFixtures as v, planEvalFixtureRun as x, loadEvalFixture as y };
3098
+ export { measureCampaignCost as C, analyzeCrossSurfaceInteractions as S, neutralizationGate as _, createRetainedDispatch as a, loadEvalFixtureScenarios as b, runProfileMatrixSegment as c, scoreUserStory as d, scoreboardSummary as f, neutralizeText as g, sequentialOptimizationMethod as h, scoreDiscrimination as i, runProfileMatrix as l, scopedOptimizationMethod as m, resolveWorktreePath as n, createProfileMatrixPlan as o, userStoryScoreboard as p, verifyCodeSurface as r, finalizeProfileMatrix as s, gitWorktreeAdapter as t, renderScoreboardMarkdown as u, discoverEvalFixtures as v, planEvalFixtureRun as x, loadEvalFixture as y };
2929
3099
 
2930
- //# sourceMappingURL=campaign-CJGkxAQ6.js.map
3100
+ //# sourceMappingURL=campaign-BVPC6ODQ.js.map