@tangle-network/agent-eval 0.208.2 → 0.210.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 (237) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +1 -1
  3. package/dist/adapters/http.d.ts +2 -2
  4. package/dist/{agent-profile-CEhxR_I3.d.ts → agent-profile-BGyt2z8U.d.ts} +3 -3
  5. package/dist/{agent-profile-CEhxR_I3.d.ts.map → agent-profile-BGyt2z8U.d.ts.map} +1 -1
  6. package/dist/{agent-profile-cell-BHcB-mZX.d.ts → agent-profile-cell-BNp-Js9F.d.ts} +2 -3
  7. package/dist/agent-profile-cell-BNp-Js9F.d.ts.map +1 -0
  8. package/dist/{agent-profile-cell-DcFW4vOc.js → agent-profile-cell-BYc0bxsL.js} +2 -2
  9. package/dist/agent-profile-cell-BYc0bxsL.js.map +1 -0
  10. package/dist/analyst/index.d.ts +12 -12
  11. package/dist/analyst/index.js +5 -5
  12. package/dist/{analyze-runs-GZ0VSwui.js → analyze-runs-3xpby3p2.js} +6 -6
  13. package/dist/analyze-runs-3xpby3p2.js.map +1 -0
  14. package/dist/{analyze-runs-CTJyUplR.d.ts → analyze-runs-BlslTkOJ.d.ts} +4 -4
  15. package/dist/{analyze-runs-CTJyUplR.d.ts.map → analyze-runs-BlslTkOJ.d.ts.map} +1 -1
  16. package/dist/{benchmark-command-BC265T1r.js → benchmark-command-S8tCtkxh.js} +6 -6
  17. package/dist/{benchmark-command-BC265T1r.js.map → benchmark-command-S8tCtkxh.js.map} +1 -1
  18. package/dist/benchmarks/index.d.ts +5 -7
  19. package/dist/benchmarks/index.d.ts.map +1 -1
  20. package/dist/benchmarks/index.js +3 -3
  21. package/dist/builder-eval/index.js +1 -1
  22. package/dist/campaign/index.d.ts +6 -6
  23. package/dist/campaign/index.js +10 -10
  24. package/dist/{campaign-evidence-DW3Krxov.js → campaign-evidence-OcUciD-N.js} +4 -4
  25. package/dist/campaign-evidence-OcUciD-N.js.map +1 -0
  26. package/dist/{campaign-C5pjR-Qn.js → campaign-wvvJA1ps.js} +14 -14
  27. package/dist/{campaign-C5pjR-Qn.js.map → campaign-wvvJA1ps.js.map} +1 -1
  28. package/dist/claude-jsonl-dZir12m6.js +86 -0
  29. package/dist/claude-jsonl-dZir12m6.js.map +1 -0
  30. package/dist/cli.js +7 -7
  31. package/dist/contract/index.d.ts +10 -10
  32. package/dist/contract/index.js +92 -16
  33. package/dist/contract/index.js.map +1 -1
  34. package/dist/counterfactual-DtMWvn7D.js.map +1 -1
  35. package/dist/{default-registry-DZFWY2_E.d.ts → default-registry-Crk3QEy1.d.ts} +6 -6
  36. package/dist/{default-registry-DZFWY2_E.d.ts.map → default-registry-Crk3QEy1.d.ts.map} +1 -1
  37. package/dist/{default-registry-DX5R7_n9.js → default-registry-DF4Yp7HQ.js} +2 -2
  38. package/dist/{default-registry-DX5R7_n9.js.map → default-registry-DF4Yp7HQ.js.map} +1 -1
  39. package/dist/{define-agent-eval-C8zBSbsc.d.ts → define-agent-eval-B_zZY2AZ.d.ts} +7 -7
  40. package/dist/{define-agent-eval-C8zBSbsc.d.ts.map → define-agent-eval-B_zZY2AZ.d.ts.map} +1 -1
  41. package/dist/{define-agent-eval-BjKXcDQp.js → define-agent-eval-CoXXDCMu.js} +7 -7
  42. package/dist/{define-agent-eval-BjKXcDQp.js.map → define-agent-eval-CoXXDCMu.js.map} +1 -1
  43. package/dist/diagnosis/index.d.ts +2 -5
  44. package/dist/diagnosis/index.d.ts.map +1 -1
  45. package/dist/diagnosis/index.js +2 -26
  46. package/dist/diagnosis/index.js.map +1 -1
  47. package/dist/{dspy-rlm-engine-sHwdSxK3.js → dspy-rlm-engine-BpaKVKJA.js} +2 -2
  48. package/dist/{dspy-rlm-engine-sHwdSxK3.js.map → dspy-rlm-engine-BpaKVKJA.js.map} +1 -1
  49. package/dist/{engine-DProXJ7A.d.ts → engine-D-YZ32ZJ.d.ts} +5 -12
  50. package/dist/engine-D-YZ32ZJ.d.ts.map +1 -0
  51. package/dist/{eval-campaign-DU_p8qVt.js → eval-campaign-4byTtqrf.js} +4 -4
  52. package/dist/{eval-campaign-DU_p8qVt.js.map → eval-campaign-4byTtqrf.js.map} +1 -1
  53. package/dist/evaluation.d.ts +2 -2
  54. package/dist/{exact-types-Cq6xXNVR.d.ts → exact-types-DjhfZglz.d.ts} +2 -2
  55. package/dist/{exact-types-Cq6xXNVR.d.ts.map → exact-types-DjhfZglz.d.ts.map} +1 -1
  56. package/dist/experiment/index.d.ts +2 -2
  57. package/dist/experiment/index.js +8 -8
  58. package/dist/{feedback-trajectory-C6Z8PRoF.d.ts → feedback-trajectory-CX01700m.d.ts} +3 -3
  59. package/dist/{feedback-trajectory-C6Z8PRoF.d.ts.map → feedback-trajectory-CX01700m.d.ts.map} +1 -1
  60. package/dist/hosted/index.js +1 -1
  61. package/dist/{index-CbBfavbT.d.ts → index-D0_l25We.d.ts} +21 -42
  62. package/dist/{index-CbBfavbT.d.ts.map → index-D0_l25We.d.ts.map} +1 -1
  63. package/dist/{index-nwNoS582.d.ts → index-DnZdBxCL.d.ts} +14 -11
  64. package/dist/{index-nwNoS582.d.ts.map → index-DnZdBxCL.d.ts.map} +1 -1
  65. package/dist/{index-DkucR0KJ.d.ts → index-UxNTvn-w.d.ts} +6 -6
  66. package/dist/{index-DkucR0KJ.d.ts.map → index-UxNTvn-w.d.ts.map} +1 -1
  67. package/dist/{index-Bzto04CY.d.ts → index-xnhRdqik.d.ts} +9 -20
  68. package/dist/{index-Bzto04CY.d.ts.map → index-xnhRdqik.d.ts.map} +1 -1
  69. package/dist/index.d.ts +28 -37
  70. package/dist/index.d.ts.map +1 -1
  71. package/dist/index.js +28 -90
  72. package/dist/index.js.map +1 -1
  73. package/dist/judge-gate-C59znGmR.js +638 -0
  74. package/dist/judge-gate-C59znGmR.js.map +1 -0
  75. package/dist/judge-gate-D2hCppem.d.ts +439 -0
  76. package/dist/judge-gate-D2hCppem.d.ts.map +1 -0
  77. package/dist/{kind-factory-Cn1lbsAd.js → kind-factory-ivTx6koH.js} +2 -11
  78. package/dist/{kind-factory-Cn1lbsAd.js.map → kind-factory-ivTx6koH.js.map} +1 -1
  79. package/dist/{llm-judge-HLWASwUJ.js → llm-judge-Tr7MBUnf.js} +9 -9
  80. package/dist/llm-judge-Tr7MBUnf.js.map +1 -0
  81. package/dist/{matrix-Cqkk7eYI.d.ts → matrix-jHTsHEkR.d.ts} +2 -2
  82. package/dist/{matrix-Cqkk7eYI.d.ts.map → matrix-jHTsHEkR.d.ts.map} +1 -1
  83. package/dist/meta-eval/index.d.ts +3 -133
  84. package/dist/meta-eval/index.d.ts.map +1 -1
  85. package/dist/meta-eval/index.js +3 -276
  86. package/dist/meta-eval/index.js.map +1 -1
  87. package/dist/{mint-C1W8w5wo.d.ts → mint-CDy-brUR.d.ts} +2 -2
  88. package/dist/{mint-C1W8w5wo.d.ts.map → mint-CDy-brUR.d.ts.map} +1 -1
  89. package/dist/{mint-CWG-s2mI.js → mint-Csor1BLJ.js} +2 -2
  90. package/dist/{mint-CWG-s2mI.js.map → mint-Csor1BLJ.js.map} +1 -1
  91. package/dist/multishot/golden/index.d.ts +1 -1
  92. package/dist/multishot/index.d.ts +2 -2
  93. package/dist/openapi.json +1 -1
  94. package/dist/{paired-arms-CgWT7sHy.js → paired-arms-DzKn0TfY.js} +3 -5
  95. package/dist/{paired-arms-CgWT7sHy.js.map → paired-arms-DzKn0TfY.js.map} +1 -1
  96. package/dist/{paired-binary-b2L3WKqr.js → paired-binary-Q36bhn2R.js} +13 -9
  97. package/dist/paired-binary-Q36bhn2R.js.map +1 -0
  98. package/dist/{paired-promotion-decision-2deJ7sDX.js → paired-promotion-decision-BN6IQTiu.js} +2 -2
  99. package/dist/{paired-promotion-decision-2deJ7sDX.js.map → paired-promotion-decision-BN6IQTiu.js.map} +1 -1
  100. package/dist/pipelines/index.d.ts +1 -1
  101. package/dist/pipelines/index.js +2 -2
  102. package/dist/{prime-protocol-Csr9kcOM.d.ts → prime-protocol-B7et3tI7.d.ts} +2 -2
  103. package/dist/{prime-protocol-Csr9kcOM.d.ts.map → prime-protocol-B7et3tI7.d.ts.map} +1 -1
  104. package/dist/{produced-state-Bzlh09oj.js → produced-state-CKybuR9F.js} +3 -3
  105. package/dist/produced-state-CKybuR9F.js.map +1 -0
  106. package/dist/profile-cell.d.ts +2 -2
  107. package/dist/profile-cell.js +2 -2
  108. package/dist/{promotion-policy-CCmyEH_c.js → promotion-policy-CWW35UWq.js} +3 -3
  109. package/dist/{promotion-policy-CCmyEH_c.js.map → promotion-policy-CWW35UWq.js.map} +1 -1
  110. package/dist/{query-DlV0pdx4.js → query-B1D1qp2Z.js} +2 -2
  111. package/dist/{query-DlV0pdx4.js.map → query-B1D1qp2Z.js.map} +1 -1
  112. package/dist/{query-DBUQhehH.d.ts → query-DK1nWcmp.d.ts} +2 -3
  113. package/dist/{query-DBUQhehH.d.ts.map → query-DK1nWcmp.d.ts.map} +1 -1
  114. package/dist/{registry-DMkmhBQ5.d.ts → registry-BL7H33tj.d.ts} +3 -3
  115. package/dist/{registry-DMkmhBQ5.d.ts.map → registry-BL7H33tj.d.ts.map} +1 -1
  116. package/dist/{release-confidence-CkoXFx9I.d.ts → release-confidence-C4kI7lQi.d.ts} +4 -12
  117. package/dist/release-confidence-C4kI7lQi.d.ts.map +1 -0
  118. package/dist/{release-confidence-CiFg1EPq.js → release-confidence-Dbe9AS_X.js} +2 -2
  119. package/dist/{release-confidence-CiFg1EPq.js.map → release-confidence-Dbe9AS_X.js.map} +1 -1
  120. package/dist/{report-command-pXtxg5YK.js → report-command-CtIIsQKP.js} +3 -28
  121. package/dist/{report-command-pXtxg5YK.js.map → report-command-CtIIsQKP.js.map} +1 -1
  122. package/dist/reporting.d.ts +3 -3
  123. package/dist/reporting.js +3 -3
  124. package/dist/{researcher-CZFZjj-u.d.ts → researcher-DuIJ9IaA.d.ts} +4 -4
  125. package/dist/{researcher-CZFZjj-u.d.ts.map → researcher-DuIJ9IaA.d.ts.map} +1 -1
  126. package/dist/{reward-hacking-Cyk-QHk9.d.ts → reward-hacking-C6Kp54Av.d.ts} +2 -2
  127. package/dist/{reward-hacking-Cyk-QHk9.d.ts.map → reward-hacking-C6Kp54Av.d.ts.map} +1 -1
  128. package/dist/reward-nw2xZGZG.js.map +1 -1
  129. package/dist/rl.d.ts +10 -29
  130. package/dist/rl.d.ts.map +1 -1
  131. package/dist/rl.js +7 -7
  132. package/dist/rl.js.map +1 -1
  133. package/dist/rollout/index.d.ts +3 -3
  134. package/dist/rollout/index.js +4 -4
  135. package/dist/{rollout-l9w3Gdvh.js → rollout-D9bKKBnZ.js} +30 -165
  136. package/dist/rollout-D9bKKBnZ.js.map +1 -0
  137. package/dist/{rubric-predictive-validity-DIUwJJ9Y.d.ts → rubric-predictive-validity-BiNNEjpG.d.ts} +2 -2
  138. package/dist/{rubric-predictive-validity-DIUwJJ9Y.d.ts.map → rubric-predictive-validity-BiNNEjpG.d.ts.map} +1 -1
  139. package/dist/{run-record-BRlM99rX.js → run-record-DlTZ_lqe.js} +3 -13
  140. package/dist/run-record-DlTZ_lqe.js.map +1 -0
  141. package/dist/{run-record-BB290Y9A.js → run-record-ES07wfz9.js} +2 -2
  142. package/dist/{run-record-BB290Y9A.js.map → run-record-ES07wfz9.js.map} +1 -1
  143. package/dist/{run-record-DF-fuu31.d.ts → run-record-p2AYTrCn.d.ts} +3 -7
  144. package/dist/run-record-p2AYTrCn.d.ts.map +1 -0
  145. package/dist/search/index.d.ts +2 -24
  146. package/dist/search/index.d.ts.map +1 -1
  147. package/dist/search/index.js +3 -3
  148. package/dist/{search-kernel-CIie6xig.js → search-kernel-BIXWM7YV.js} +4 -4
  149. package/dist/search-kernel-BIXWM7YV.js.map +1 -0
  150. package/dist/{search-kernel-uKdPVRAe.d.ts → search-kernel-ah2GESe3.d.ts} +3 -3
  151. package/dist/{search-kernel-uKdPVRAe.d.ts.map → search-kernel-ah2GESe3.d.ts.map} +1 -1
  152. package/dist/{search-ledger-CXQPwdWz.js → search-ledger-aMTNQn_m.js} +2 -2
  153. package/dist/{search-ledger-CXQPwdWz.js.map → search-ledger-aMTNQn_m.js.map} +1 -1
  154. package/dist/{search-shipper-DhhofkDX.js → search-shipper-DKXWuLnp.js} +2 -2
  155. package/dist/{search-shipper-DhhofkDX.js.map → search-shipper-DKXWuLnp.js.map} +1 -1
  156. package/dist/{search-summary-BV5uehLd.js → search-summary-nwrtXxC_.js} +3 -3
  157. package/dist/{search-summary-BV5uehLd.js.map → search-summary-nwrtXxC_.js.map} +1 -1
  158. package/dist/{semantic-concept-judge-D1wH-YKc.js → semantic-concept-judge-BQxZyXdN.js} +3 -3
  159. package/dist/{semantic-concept-judge-D1wH-YKc.js.map → semantic-concept-judge-BQxZyXdN.js.map} +1 -1
  160. package/dist/{sequential-DMqr3sni.js → sequential-D-1PPCmM.js} +3 -3
  161. package/dist/{sequential-DMqr3sni.js.map → sequential-D-1PPCmM.js.map} +1 -1
  162. package/dist/{skillopt-optimization-method-Dcnh5Pvr.js → skillopt-optimization-method-DujPOiwD.js} +5 -5
  163. package/dist/{skillopt-optimization-method-Dcnh5Pvr.js.map → skillopt-optimization-method-DujPOiwD.js.map} +1 -1
  164. package/dist/{statistical-heldout-BP6iEJvR.js → statistical-heldout-1Gbmex7v.js} +2 -2
  165. package/dist/{statistical-heldout-BP6iEJvR.js.map → statistical-heldout-1Gbmex7v.js.map} +1 -1
  166. package/dist/{statistical-heldout-DFKtp-Qm.d.ts → statistical-heldout-8RGPIeyo.d.ts} +17 -14
  167. package/dist/statistical-heldout-8RGPIeyo.d.ts.map +1 -0
  168. package/dist/{store-otlp-BA7G1Du-.js → store-otlp-__ebQ6Hn.js} +2 -2
  169. package/dist/{store-otlp-BA7G1Du-.js.map → store-otlp-__ebQ6Hn.js.map} +1 -1
  170. package/dist/{store-tool-spans-DKoVbE-w.js → store-tool-spans-TbRBuIM7.js} +3 -3
  171. package/dist/{store-tool-spans-DKoVbE-w.js.map → store-tool-spans-TbRBuIM7.js.map} +1 -1
  172. package/dist/{store-tool-spans-9YJNMP-z.d.ts → store-tool-spans-wQ9idsnn.d.ts} +5 -5
  173. package/dist/{store-tool-spans-9YJNMP-z.d.ts.map → store-tool-spans-wQ9idsnn.d.ts.map} +1 -1
  174. package/dist/{summary-report-DvvesgR_.d.ts → summary-report-CK0ueoJd.d.ts} +2 -2
  175. package/dist/{summary-report-DvvesgR_.d.ts.map → summary-report-CK0ueoJd.d.ts.map} +1 -1
  176. package/dist/{summary-report-fXurE2TR.js → summary-report-DtdRucM0.js} +3 -3
  177. package/dist/{summary-report-fXurE2TR.js.map → summary-report-DtdRucM0.js.map} +1 -1
  178. package/dist/supervisor-run/index.d.ts +0 -8
  179. package/dist/supervisor-run/index.d.ts.map +1 -1
  180. package/dist/supervisor-run/index.js +36 -71
  181. package/dist/supervisor-run/index.js.map +1 -1
  182. package/dist/{systemone-review-Bt4JcxMc.d.ts → systemone-review-BReh3mvm.d.ts} +2 -2
  183. package/dist/{systemone-review-Bt4JcxMc.d.ts.map → systemone-review-BReh3mvm.d.ts.map} +1 -1
  184. package/dist/systemone.d.ts +3 -3
  185. package/dist/{tool-groups-j19pmOfP.d.ts → tool-groups-v28A-ZAF.d.ts} +3 -3
  186. package/dist/tool-groups-v28A-ZAF.d.ts.map +1 -0
  187. package/dist/{tool-waste-x_E8h9Ih.js → tool-waste-BYt5rdt8.js} +2 -2
  188. package/dist/{tool-waste-x_E8h9Ih.js.map → tool-waste-BYt5rdt8.js.map} +1 -1
  189. package/dist/{tool-waste-DxlebQkx.d.ts → tool-waste-Wi4g6Ekb.d.ts} +2 -2
  190. package/dist/{tool-waste-DxlebQkx.d.ts.map → tool-waste-Wi4g6Ekb.d.ts.map} +1 -1
  191. package/dist/{trace-questions-dRvmsbTk.d.ts → trace-questions-C26UvI3D.d.ts} +3 -3
  192. package/dist/{trace-questions-dRvmsbTk.d.ts.map → trace-questions-C26UvI3D.d.ts.map} +1 -1
  193. package/dist/trace-repair/index.d.ts +2 -9
  194. package/dist/trace-repair/index.d.ts.map +1 -1
  195. package/dist/trace-repair/index.js +1 -1
  196. package/dist/traces.d.ts +6 -8
  197. package/dist/traces.d.ts.map +1 -1
  198. package/dist/traces.js +6 -6
  199. package/dist/trajectory-replay/index.d.ts +0 -2
  200. package/dist/trajectory-replay/index.d.ts.map +1 -1
  201. package/dist/trajectory-replay/index.js +1 -1
  202. package/dist/{tree-CJOXbVcv.js → tree-kc1d80yF.js} +5 -25
  203. package/dist/tree-kc1d80yF.js.map +1 -0
  204. package/dist/{types-CFCUZk0B.d.ts → types-Dv9sYwBB.d.ts} +4 -4
  205. package/dist/{types-CFCUZk0B.d.ts.map → types-Dv9sYwBB.d.ts.map} +1 -1
  206. package/dist/{types-DAPpAkd4.d.ts → types-KEkKkETv.d.ts} +2 -2
  207. package/dist/{types-DAPpAkd4.d.ts.map → types-KEkKkETv.d.ts.map} +1 -1
  208. package/dist/{types-BlSBUNRd.d.ts → types-tWFY6bON.d.ts} +3 -3
  209. package/dist/{types-BlSBUNRd.d.ts.map → types-tWFY6bON.d.ts.map} +1 -1
  210. package/dist/wire/index.d.ts +1 -1
  211. package/docs/concepts.md +13 -0
  212. package/docs/experiment.md +10 -0
  213. package/docs/public-api.md +399 -424
  214. package/docs/trace-analysis.md +3 -0
  215. package/package.json +6 -5
  216. package/dist/agent-profile-cell-BHcB-mZX.d.ts.map +0 -1
  217. package/dist/agent-profile-cell-DcFW4vOc.js.map +0 -1
  218. package/dist/analyze-runs-GZ0VSwui.js.map +0 -1
  219. package/dist/campaign-evidence-DW3Krxov.js.map +0 -1
  220. package/dist/claude-jsonl-CG3JUbTJ.js +0 -211
  221. package/dist/claude-jsonl-CG3JUbTJ.js.map +0 -1
  222. package/dist/engine-DProXJ7A.d.ts.map +0 -1
  223. package/dist/llm-judge-HLWASwUJ.js.map +0 -1
  224. package/dist/paired-binary-b2L3WKqr.js.map +0 -1
  225. package/dist/produced-state-Bzlh09oj.js.map +0 -1
  226. package/dist/release-confidence-CkoXFx9I.d.ts.map +0 -1
  227. package/dist/rollout-l9w3Gdvh.js.map +0 -1
  228. package/dist/run-record-BRlM99rX.js.map +0 -1
  229. package/dist/run-record-DF-fuu31.d.ts.map +0 -1
  230. package/dist/search-kernel-CIie6xig.js.map +0 -1
  231. package/dist/series-convergence-CjO2QdRW.js +0 -43
  232. package/dist/series-convergence-CjO2QdRW.js.map +0 -1
  233. package/dist/series-convergence-hEfKdoi-.d.ts +0 -126
  234. package/dist/series-convergence-hEfKdoi-.d.ts.map +0 -1
  235. package/dist/statistical-heldout-DFKtp-Qm.d.ts.map +0 -1
  236. package/dist/tool-groups-j19pmOfP.d.ts.map +0 -1
  237. package/dist/tree-CJOXbVcv.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"campaign-evidence-OcUciD-N.js","names":[],"sources":["../src/campaign/coverage.ts","../src/integrity/backend-integrity.ts","../src/campaign/surface-identity.ts","../src/experiment/final-evidence.ts","../src/campaign/gates/power-preflight.ts","../src/json-recovery.ts","../src/reflective-mutation.ts","../src/campaign/score-utils.ts","../src/campaign/provenance.ts","../src/attestation.ts","../src/experiment/evidence-receipt.ts","../src/experiment/campaign-evidence.ts"],"sourcesContent":["import { contentHash } from '../verdict-cache'\nimport type {\n CampaignCellResult,\n CampaignResult,\n CampaignScenarioIdentity,\n Scenario,\n} from './types'\n\nexport interface CampaignCoverage {\n complete: boolean\n expectedCellIds: string[]\n scorableCellIds: string[]\n unscorableCells: Array<{ cellId: string; reason: string }>\n}\n\n/** Reject campaign designs whose denominator cannot be identified exactly. */\nexport function assertCampaignDesign<TScenario extends Scenario>(\n scenarios: readonly TScenario[],\n reps: number,\n): void {\n if (!Number.isSafeInteger(reps) || reps < 1) {\n throw new Error('campaign design requires reps to be a positive safe integer')\n }\n const scenarioIds = new Set<string>()\n for (const scenario of scenarios) {\n if (typeof scenario.id !== 'string' || scenario.id.trim().length === 0) {\n throw new Error('campaign design requires every scenario to have a non-empty id')\n }\n if (scenarioIds.has(scenario.id)) {\n throw new Error(`campaign design contains duplicate scenario id '${scenario.id}'`)\n }\n if (typeof scenario.kind !== 'string' || scenario.kind.trim().length === 0) {\n throw new Error('campaign design requires every scenario to have a non-empty kind')\n }\n if (\n scenario.seedGroup !== undefined &&\n (typeof scenario.seedGroup !== 'string' || scenario.seedGroup.trim().length === 0)\n ) {\n throw new Error('campaign design requires seedGroup to be a non-empty string when set')\n }\n scenarioIds.add(scenario.id)\n }\n}\n\n/** Redacted but independently verifiable identity of one complete scenario. */\nexport function campaignScenarioIdentity<TScenario extends Scenario>(\n scenario: TScenario,\n): CampaignScenarioIdentity & Pick<TScenario, 'id' | 'kind'> {\n assertCampaignDesign([scenario], 1)\n return {\n id: scenario.id,\n kind: scenario.kind,\n scenarioDigest: `sha256:${contentHash(scenario)}`,\n }\n}\n\n/** Canonical split identity reconstructed from redacted scenario identities. */\nexport function campaignSplitDigestFromIdentities(\n scenarios: readonly CampaignScenarioIdentity[],\n reps: number,\n): `sha256:${string}` {\n assertCampaignDesign(scenarios, reps)\n for (const scenario of scenarios) {\n if (!/^sha256:[a-f0-9]{64}$/.test(scenario.scenarioDigest)) {\n throw new Error(`campaign scenario '${scenario.id}' has an invalid digest`)\n }\n }\n return `sha256:${contentHash({\n schema: 'tangle.campaign-split',\n scenarios: scenarios.map(({ id, kind, scenarioDigest }) => ({ id, kind, scenarioDigest })),\n reps,\n })}`\n}\n\n/** Canonical identity of the exact scenario payloads and replicate count. */\nexport function campaignSplitDigest<TScenario extends Scenario>(\n scenarios: readonly TScenario[],\n reps: number,\n): `sha256:${string}` {\n assertCampaignDesign(scenarios, reps)\n return campaignSplitDigestFromIdentities(scenarios.map(campaignScenarioIdentity), reps)\n}\n\n/** Refuse a campaign whose retained task identities contradict its split digest. */\nexport function assertCampaignSplitIdentity(\n scenarios: readonly CampaignScenarioIdentity[],\n reps: number,\n splitDigest: string,\n): void {\n if (campaignSplitDigestFromIdentities(scenarios, reps) !== splitDigest) {\n throw new Error('campaign split digest does not match its retained scenario identities')\n }\n}\n\n/** Exact designed-denominator receipt for one campaign. */\nexport function campaignCoverage<TArtifact, TScenario extends Scenario>(\n cells: readonly CampaignCellResult<TArtifact>[],\n scenarios: readonly TScenario[],\n reps: number,\n requireJudgeScore: boolean,\n): CampaignCoverage {\n assertCampaignDesign(scenarios, reps)\n const expectedCellIds = designedCellIds(scenarios, reps)\n const cellsById = new Map<string, CampaignCellResult<TArtifact>[]>()\n for (const cell of cells) {\n const matches = cellsById.get(cell.cellId) ?? []\n matches.push(cell)\n cellsById.set(cell.cellId, matches)\n }\n\n const scorableCellIds: string[] = []\n const unscorableCells: Array<{ cellId: string; reason: string }> = []\n for (const cellId of expectedCellIds) {\n const matches = cellsById.get(cellId) ?? []\n if (matches.length === 0) {\n unscorableCells.push({ cellId, reason: 'missing campaign cell' })\n continue\n }\n if (matches.length > 1) {\n unscorableCells.push({ cellId, reason: `duplicate campaign cell (${matches.length})` })\n continue\n }\n\n const cell = matches[0]!\n const scoreEntries = Object.entries(cell.judgeScores)\n const successfulScores = scoreEntries\n .map(([, score]) => score)\n .filter((score) => score.failed !== true && Number.isFinite(score.composite))\n const nonFiniteScores = scoreEntries.filter(\n ([, score]) =>\n score.failed !== true &&\n (!Number.isFinite(score.composite) ||\n Object.values(score.dimensions).some((value) => !Number.isFinite(value))),\n )\n const reasons: string[] = []\n if (cell.error) reasons.push(cell.error)\n if (cell.artifact === null || cell.artifact === undefined) reasons.push('missing artifact')\n if (!cell.error && requireJudgeScore && successfulScores.length === 0) {\n reasons.push('no successful finite judge score')\n }\n if (scoreEntries.some(([, score]) => score.failed === true)) {\n reasons.push('judge score marked failed')\n }\n const failedPanelJudges = [\n ...new Set(scoreEntries.flatMap(([, score]) => score.failedJudges ?? [])),\n ].sort()\n if (failedPanelJudges.length > 0) {\n reasons.push(`judge panel incomplete: ${failedPanelJudges.join(', ')}`)\n }\n if (nonFiniteScores.length > 0) {\n reasons.push(\n `non-finite judge score: ${nonFiniteScores\n .map(([name]) => name)\n .sort()\n .join(', ')}`,\n )\n }\n\n if (reasons.length > 0) {\n unscorableCells.push({ cellId, reason: reasons.join('; ') })\n } else {\n scorableCellIds.push(cellId)\n }\n }\n\n const expected = new Set(expectedCellIds)\n for (const cell of cells) {\n if (cell.cellId !== `${cell.scenarioId}:${cell.rep}`) {\n unscorableCells.push({\n cellId: cell.cellId,\n reason: 'campaign cell id does not match scenario id and rep',\n })\n continue\n }\n if (!expected.has(cell.cellId)) {\n unscorableCells.push({ cellId: cell.cellId, reason: 'unexpected campaign cell' })\n }\n }\n\n return {\n complete: unscorableCells.length === 0 && scorableCellIds.length === expectedCellIds.length,\n expectedCellIds,\n scorableCellIds,\n unscorableCells,\n }\n}\n\nexport function formatCoverageFailures(coverage: CampaignCoverage): string {\n const shown = coverage.unscorableCells\n .slice(0, 3)\n .map((cell) => `${cell.cellId}: ${cell.reason}`)\n .join('; ')\n const remainder = coverage.unscorableCells.length - Math.min(3, coverage.unscorableCells.length)\n return remainder > 0 ? `${shown}; +${remainder} more` : shown || 'unknown coverage failure'\n}\n\nfunction designedCellIds<TScenario extends Scenario>(\n scenarios: readonly TScenario[],\n reps: number,\n): string[] {\n const ids: string[] = []\n for (const scenario of scenarios) {\n for (let rep = 0; rep < reps; rep++) ids.push(`${scenario.id}:${rep}`)\n }\n return ids\n}\n\n/** Require the complete designed denominator before a final comparison. */\nexport function assertCompleteCampaign<TArtifact, TScenario extends Scenario>(\n campaign: CampaignResult<TArtifact, TScenario>,\n scenarios: readonly TScenario[],\n reps: number,\n requireJudgeScore: boolean,\n label: string,\n): void {\n const coverage = campaignCoverage(campaign.cells, scenarios, reps, requireJudgeScore)\n if (!coverage.complete) {\n throw new Error(\n `${label} is incomplete (${coverage.scorableCellIds.length}/${coverage.expectedCellIds.length} designed cells scorable) — ${formatCoverageFailures(coverage)}. Refusing to compare unequal results.`,\n )\n }\n}\n","/**\n * Backend-integrity guard: distinguish \"agent failed\" from \"eval ran against\n * a stub / unconfigured backend.\" Without this guard a canonical eval can\n * silently report `0/N passed` and look like an agent-quality problem when\n * the LLM was never actually called — the failure mode we just hit running\n * the 4-vertical parallel eval (legal-sandbox-stub returned hard-coded 33-104\n * char strings; gtm/creative defaulted to a cli-bridge that wasn't running).\n *\n * The shape:\n *\n * const report = summarizeBackendIntegrity(records)\n * assertRealBackend(records) // throws BackendIntegrityError if 100% stub\n *\n * A record is \"stub-mode\" if its `tokenUsage.input === 0 && tokenUsage.output === 0`.\n * (`costUsd` alone is unreliable — some backends successfully call LLMs but\n * don't propagate pricing, producing real tokens with $0 cost.)\n *\n * Verdicts:\n * - `real` — at least one record has nonzero token usage\n * - `stub` — every record is stub-mode (eval ran blind)\n * - `mixed` — some records real, some stub (partial backend failure;\n * often the 429-cascade or auth-half-failed case)\n */\n\nimport type { CostReceipt } from '../cost-ledger'\nimport { AgentEvalError } from '../errors'\nimport type { RunRecord } from '../run-record'\n\nexport interface BackendIntegrityReport {\n /** Total records inspected. */\n totalRecords: number\n /** Records with input=0 AND output=0 (a stub fingerprint). */\n stubRecords: number\n /** Records with nonzero token usage (real LLM activity). */\n realRecords: number\n /** Records where output>0 but costUsd=0 (real LLM, broken cost ledger). */\n uncostedRecords: number\n /** Sum of input tokens across all records. */\n totalInputTokens: number\n /** Sum of output tokens across all records. */\n totalOutputTokens: number\n /** Sum of costUsd across all records. */\n totalCostUsd: number\n /** Worst-case integrity verdict. */\n verdict: 'real' | 'mixed' | 'stub'\n /** Human-readable diagnosis suitable for terminal output. */\n diagnosis: string\n}\n\n/**\n * Error thrown when an integrity assertion fails. Caller can pattern-match\n * by `code === 'AGENT_EVAL_BACKEND_STUB'` to differentiate from other\n * errors.\n */\nexport class BackendIntegrityError extends AgentEvalError {\n constructor(\n message: string,\n public readonly report: BackendIntegrityReport,\n ) {\n super('backend_integrity', message)\n }\n}\n\n/**\n * Inspect a batch of RunRecords and return an integrity report. Pure\n * function — no I/O, no logging. The caller decides what to do with the\n * verdict (print warning, throw, gate CI, etc.).\n */\nexport function summarizeBackendIntegrity(\n records: ReadonlyArray<RunRecord>,\n): BackendIntegrityReport {\n return summarizeBackendUsage(\n records.map((record) => ({\n inputTokens: record.tokenUsage.input,\n outputTokens: record.tokenUsage.output,\n costUsd: record.costUsd,\n })),\n )\n}\n\n/** Inspect settled agent calls from the canonical cost ledger. */\nexport function summarizeAgentReceiptIntegrity(\n receipts: ReadonlyArray<CostReceipt>,\n): BackendIntegrityReport {\n return summarizeBackendUsage(\n receipts\n .filter((receipt) => receipt.channel === 'agent')\n .map((receipt) => ({\n inputTokens: receipt.inputTokens,\n outputTokens: receipt.outputTokens,\n costUsd: receipt.costUsd,\n })),\n )\n}\n\ninterface BackendUsage {\n inputTokens: number\n outputTokens: number\n costUsd: number | null\n}\n\nfunction summarizeBackendUsage(records: readonly BackendUsage[]): BackendIntegrityReport {\n const totalRecords = records.length\n let stubRecords = 0\n let realRecords = 0\n let uncostedRecords = 0\n let totalInputTokens = 0\n let totalOutputTokens = 0\n let totalCostUsd = 0\n for (const rec of records) {\n totalInputTokens += rec.inputTokens\n totalOutputTokens += rec.outputTokens\n totalCostUsd += rec.costUsd ?? 0\n if (rec.inputTokens === 0 && rec.outputTokens === 0) stubRecords++\n else realRecords++\n if (rec.outputTokens > 0 && (rec.costUsd === null || rec.costUsd === 0)) uncostedRecords++\n }\n const verdict: BackendIntegrityReport['verdict'] =\n totalRecords === 0\n ? 'stub'\n : stubRecords === totalRecords\n ? 'stub'\n : stubRecords === 0\n ? 'real'\n : 'mixed'\n const diagnosis = buildDiagnosis({\n totalRecords,\n stubRecords,\n realRecords,\n uncostedRecords,\n totalInputTokens,\n totalOutputTokens,\n totalCostUsd,\n verdict,\n })\n return {\n totalRecords,\n stubRecords,\n realRecords,\n uncostedRecords,\n totalInputTokens,\n totalOutputTokens,\n totalCostUsd,\n verdict,\n diagnosis,\n }\n}\n\nfunction buildDiagnosis(r: Omit<BackendIntegrityReport, 'diagnosis'>): string {\n if (r.totalRecords === 0) {\n return 'no records — eval produced zero runs; backend likely failed before first turn'\n }\n if (r.verdict === 'stub') {\n return [\n `all ${r.totalRecords} records have zero token usage — the LLM backend was never called.`,\n 'common causes: --backend sandbox without a sandbox bridge running; stub model returning hard-coded strings;',\n 'auth misconfigured so requests were silently dropped before the LLM. Re-run with --backend tcloud and TANGLE_API_KEY set,',\n 'or boot the cli-bridge / sandbox before invoking the eval.',\n ].join(' ')\n }\n if (r.verdict === 'mixed') {\n const pct = ((r.stubRecords / r.totalRecords) * 100).toFixed(0)\n return [\n `${r.stubRecords}/${r.totalRecords} records (${pct}%) have zero token usage — the backend partially failed.`,\n 'common causes: rate-limit cascade (429s after the first N personas);',\n 'transient auth expiry mid-run; provider outage. Treat the affected records as missing data, not agent failures.',\n ].join(' ')\n }\n // verdict === 'real'\n if (r.uncostedRecords > 0) {\n const pct = ((r.uncostedRecords / r.totalRecords) * 100).toFixed(0)\n return [\n `${r.totalRecords} records with real LLM activity (in=${r.totalInputTokens}, out=${r.totalOutputTokens} tokens).`,\n `${r.uncostedRecords} (${pct}%) have output tokens but costUsd=0. Two distinct roots:`,\n '(a) cost ledger mis-wired — no usage propagation from the runtime stream into RunRecord; or',\n '(b) the model is unpriced at the source (sandbox/router returned $0 despite real tokens).',\n 'For (b), price the measured tokens against the substrate table (estimateCost) instead of leaving $0.',\n ].join(' ')\n }\n return `${r.totalRecords} records with real LLM activity (in=${r.totalInputTokens}, out=${r.totalOutputTokens} tokens, $${r.totalCostUsd.toFixed(4)}).`\n}\n\n/**\n * Throw BackendIntegrityError if the verdict is 'stub' — i.e. every record\n * shows zero LLM activity. Non-strict callers can pass `{ allowMixed: false }`\n * to also reject mixed verdicts (recommended for CI gates).\n *\n * Real backends pass through silently.\n */\nexport function assertRealBackend(\n records: ReadonlyArray<RunRecord>,\n opts: { allowMixed?: boolean } = {},\n): BackendIntegrityReport {\n const report = summarizeBackendIntegrity(records)\n return assertBackendReport(report, opts)\n}\n\nfunction assertBackendReport(\n report: BackendIntegrityReport,\n opts: { allowMixed?: boolean },\n): BackendIntegrityReport {\n const allowMixed = opts.allowMixed ?? true\n if (report.verdict === 'stub') {\n throw new BackendIntegrityError(\n `backend-integrity: ran against a stub or unconfigured backend — ${report.diagnosis}`,\n report,\n )\n }\n if (!allowMixed && report.verdict === 'mixed') {\n throw new BackendIntegrityError(\n `backend-integrity: partial backend failure rejected — ${report.diagnosis}`,\n report,\n )\n }\n return report\n}\n","import { createHash } from 'node:crypto'\nimport { canonicalString } from '../ledger-core/canonical'\nimport type { CodeSurface, ComponentSurface, MutableSurface } from './types'\n\nconst GIT_OBJECT_ID = /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/\nconst SHA256 = /^sha256:[a-f0-9]{64}$/\n\n/** Validate the immutable identity shape; the owning executor verifies the Git objects and patch. */\nexport function assertCodeSurfaceIdentity(surface: unknown): asserts surface is CodeSurface {\n if (!surface || typeof surface !== 'object') {\n throw new TypeError('CodeSurface must be an object')\n }\n const candidate = surface as Partial<CodeSurface>\n if (candidate.kind !== 'code') throw new TypeError('CodeSurface.kind must be \"code\"')\n if (typeof candidate.worktreeRef !== 'string' || candidate.worktreeRef.trim().length === 0) {\n throw new TypeError('CodeSurface.worktreeRef must be a non-empty locator')\n }\n if (typeof candidate.baseRef !== 'string' || candidate.baseRef.trim().length === 0) {\n throw new TypeError('CodeSurface.baseRef must be a non-empty ref label')\n }\n for (const [field, value] of [\n ['baseCommit', candidate.baseCommit],\n ['baseTree', candidate.baseTree],\n ['candidateCommit', candidate.candidateCommit],\n ['candidateTree', candidate.candidateTree],\n ] as const) {\n if (typeof value !== 'string' || !GIT_OBJECT_ID.test(value)) {\n throw new TypeError(`CodeSurface.${field} must be a full Git object id`)\n }\n }\n const patch = candidate.patch\n if (!patch || typeof patch !== 'object' || patch.format !== 'git-diff-binary') {\n throw new TypeError('CodeSurface.patch.format must be \"git-diff-binary\"')\n }\n if (typeof patch.sha256 !== 'string' || !SHA256.test(patch.sha256)) {\n throw new TypeError('CodeSurface.patch.sha256 must be a sha256 digest')\n }\n if (!Number.isSafeInteger(patch.byteLength) || patch.byteLength < 0) {\n throw new TypeError('CodeSurface.patch.byteLength must be a non-negative safe integer')\n }\n}\n\n/** Assert that a value is a valid non-empty component surface. */\nfunction assertComponentSurface(surface: unknown): asserts surface is ComponentSurface {\n if (!surface || typeof surface !== 'object') {\n throw new TypeError('ComponentSurface must be an object')\n }\n const candidate = surface as Partial<ComponentSurface>\n if (candidate.kind !== 'components') {\n throw new TypeError('ComponentSurface.kind must be \"components\"')\n }\n if (\n !candidate.components ||\n typeof candidate.components !== 'object' ||\n Array.isArray(candidate.components)\n ) {\n throw new TypeError('ComponentSurface.components must be an object')\n }\n const entries = Object.entries(candidate.components)\n if (entries.length === 0) {\n throw new TypeError('ComponentSurface.components must not be empty')\n }\n for (const [name, content] of entries) {\n if (!name.trim() || name.trim() !== name) {\n throw new TypeError('ComponentSurface component names must be trimmed and non-empty')\n }\n if (typeof content !== 'string') {\n throw new TypeError(`ComponentSurface component '${name}' must be a string`)\n }\n }\n}\n\n/**\n * Deterministic identity material for a component surface.\n *\n * `canonicalString` orders keys by UTF-16 code unit (RFC 8785), which is a\n * property of the value alone. The previous material ordered them with\n * `localeCompare`, which reads the host's collation — so the same surface\n * could produce two different identities on two machines, and the stored\n * identity would stop matching a recomputation of the identical surface.\n */\nexport function componentSurfaceIdentityMaterial(surface: ComponentSurface): string {\n assertComponentSurface(surface)\n return canonicalString({\n schema: 'tangle.component-surface',\n components: surface.components,\n })\n}\n\n/**\n * The retired material builder, kept PRIVATE and reachable only from\n * {@link surfaceHashMatches}.\n *\n * A surface identity recorded before this release was minted from these bytes.\n * The verify path tries the current material first and falls back to this one,\n * so a stored identity still matches its own surface; nothing mints from it.\n *\n * Every component surface's identity moves, not only one whose names sort\n * differently under the host's collation: RFC 8785 also orders the two\n * top-level keys, so `components` precedes `schema` where this builder emitted\n * them in literal order. The retention window therefore covers every stored\n * component-surface identity, which is why this builder is kept rather than\n * scoped to the mixed-case case.\n */\nfunction retiredComponentSurfaceIdentityMaterial(surface: ComponentSurface): string {\n assertComponentSurface(surface)\n return JSON.stringify({\n schema: 'tangle.component-surface',\n components: Object.fromEntries(\n Object.entries(surface.components).sort(([left], [right]) => left.localeCompare(right)),\n ),\n })\n}\n\n/** Canonical, location-independent identity of a finalized code candidate.\n * Commit metadata is excluded: two commits with the same base, final tree,\n * and patch bytes are the same executable candidate. */\nexport function codeSurfaceIdentityMaterial(surface: CodeSurface): string {\n assertCodeSurfaceIdentity(surface)\n return JSON.stringify({\n schema: 'tangle.code-surface',\n baseCommit: surface.baseCommit,\n baseTree: surface.baseTree,\n candidateTree: surface.candidateTree,\n patch: {\n format: surface.patch.format,\n sha256: surface.patch.sha256,\n byteLength: surface.patch.byteLength,\n },\n })\n}\n\n/** Full SHA-256 content identity for a prompt or finalized code surface. */\nexport function surfaceContentHash(surface: MutableSurface): `sha256:${string}` {\n const material =\n typeof surface === 'string'\n ? surface\n : surface.kind === 'components'\n ? componentSurfaceIdentityMaterial(surface)\n : codeSurfaceIdentityMaterial(surface)\n return `sha256:${createHash('sha256').update(material).digest('hex')}`\n}\n\n/** Short loop key derived from the same content identity as provenance. */\nexport function surfaceHash(surface: MutableSurface): string {\n return surfaceContentHash(surface).slice('sha256:'.length, 'sha256:'.length + 16)\n}\n\n/**\n * Whether `storedHash` is the loop key of `surface`, under the current identity\n * material or the retired one.\n *\n * A stored key is 16 hex characters with no room for a scheme tag, so the\n * scheme cannot be read off the value the way an `agent-profile-cell` id names\n * its own. The verify path therefore tries both, which gives the same property:\n * a key minted by an earlier release still matches its own surface, and a\n * surface that was actually edited matches neither.\n *\n * Only a component surface can differ between the two; a prompt or code surface\n * produces identical material under both, so the second comparison is a no-op\n * for them.\n */\nexport function surfaceHashMatches(surface: MutableSurface, storedHash: string): boolean {\n if (surfaceHash(surface) === storedHash) return true\n if (typeof surface === 'string' || surface.kind !== 'components') return false\n const retired = createHash('sha256')\n .update(retiredComponentSurfaceIdentityMaterial(surface))\n .digest('hex')\n return retired.slice(0, 16) === storedHash\n}\n\n/** Canonical customer-visible description of the exact before/after surfaces. */\nexport function renderSurfaceDiff(\n winnerSurface: MutableSurface,\n baselineSurface: MutableSurface,\n): string {\n if (typeof winnerSurface === 'string' && typeof baselineSurface === 'string') {\n return [\n '--- baseline',\n '+++ winner',\n ...baselineSurface.split('\\n').map((line) => `- ${line}`),\n ...winnerSurface.split('\\n').map((line) => `+ ${line}`),\n ].join('\\n')\n }\n\n const describe = (surface: MutableSurface): string => {\n if (typeof surface === 'string') return '(prompt surface)'\n if (surface.kind === 'components') {\n assertComponentSurface(surface)\n return Object.entries(surface.components)\n .sort(([left], [right]) => left.localeCompare(right))\n .map(([name, content]) => `[${name}]\\n${content}`)\n .join('\\n\\n')\n }\n assertCodeSurfaceIdentity(surface)\n return [\n `baseCommit=${surface.baseCommit}`,\n `baseTree=${surface.baseTree}`,\n `candidateCommit=${surface.candidateCommit}`,\n `candidateTree=${surface.candidateTree}`,\n `patch=${surface.patch.sha256}`,\n `patchBytes=${surface.patch.byteLength}`,\n ...(surface.summary ? [surface.summary] : []),\n ].join('\\n')\n }\n\n return `--- baseline\\n${describe(baselineSurface)}\\n+++ winner\\n${describe(winnerSurface)}`\n}\n\n/** Bind a campaign cache entry to the exact surface and caller-owned execution revision. */\nexport function surfaceDispatchRef(surface: MutableSurface, executionRef = 'anonymous'): string {\n if (!executionRef.trim() || executionRef.trim() !== executionRef) {\n throw new Error('surfaceDispatchRef: executionRef must be trimmed and non-empty')\n }\n return `surface:${executionRef}:${surfaceContentHash(surface)}`\n}\n","import { z } from 'zod'\nimport { compareCodeUnits, type LedgerHash } from '../ledger-core/canonical'\nimport { FileLedgerJournal, type LedgerJournalCodec } from '../ledger-core/journal'\n\nconst identity = z\n .string()\n .min(1)\n .refine((value) => value.trim() === value)\nconst digest = z.string().regex(/^sha256:[a-f0-9]{64}$/)\nconst reservationSchema = z\n .object({\n requestId: identity,\n claimDigest: digest,\n populationId: identity,\n inputDigest: digest,\n unitIds: z.array(identity).min(1),\n })\n .strict()\n\n/** One final dataset reserved for one adaptive decision, across processes and campaigns. */\nexport type FinalEvidenceReservation = z.infer<typeof reservationSchema>\n\nconst measurementSchema = z\n .object({\n evaluatorDigest: digest,\n candidateDigests: z.array(digest).min(1),\n })\n .strict()\n\nexport type FinalEvidenceMeasurement = z.infer<typeof measurementSchema>\n\nconst eventSchema = z.discriminatedUnion('kind', [\n z\n .object({\n kind: z.literal('reserved'),\n eventId: identity,\n reservation: reservationSchema,\n })\n .strict(),\n z\n .object({\n kind: z.literal('exposed'),\n eventId: identity,\n requestId: identity,\n measurement: measurementSchema,\n })\n .strict(),\n])\n\ntype Event = z.infer<typeof eventSchema>\nconst schema = 'agent-eval.final-evidence.v1' as const\nconst entrySchema = z\n .object({\n schema: z.literal(schema),\n sequence: z.number().int().nonnegative(),\n previousHash: digest.nullable(),\n event: eventSchema,\n entryHash: digest,\n })\n .strict()\n\nexport interface FinalEvidenceRecord {\n reservation: FinalEvidenceReservation\n reservationHash: LedgerHash\n exposure: { measurement: FinalEvidenceMeasurement; entryHash: LedgerHash } | null\n}\n\nexport type FinalEvidenceOutcome<T> =\n | { succeeded: true; value: T }\n | { succeeded: false; error: { kind: 'conflict' | 'invalid' | 'unavailable'; message: string } }\n\nexport interface FinalEvidenceLedger {\n reserve(\n input: FinalEvidenceReservation,\n ): Promise<FinalEvidenceOutcome<{ record: FinalEvidenceRecord; replayed: boolean }>>\n expose(\n requestId: string,\n measurement: FinalEvidenceMeasurement,\n ): Promise<FinalEvidenceOutcome<{ record: FinalEvidenceRecord; replayed: boolean }>>\n read(): Promise<FinalEvidenceOutcome<FinalEvidenceRecord[]>>\n}\n\n/** Retains the distinction between invalid input, consumed evidence, and unavailable storage. */\nexport class FinalEvidenceError extends Error {\n constructor(\n readonly kind: 'conflict' | 'invalid' | 'unavailable',\n message: string,\n ) {\n super(message)\n this.name = 'FinalEvidenceError'\n }\n}\n\n/** A consumed or conflicting dataset cannot authorize another adaptive decision. */\nexport class FinalEvidenceConflictError extends FinalEvidenceError {\n constructor(message: string) {\n super('conflict', message)\n this.name = 'FinalEvidenceConflictError'\n }\n}\n\nfunction invalid(message: string): Error {\n return new TypeError(`final evidence: ${message}`)\n}\n\nfunction normalizeReservation(input: FinalEvidenceReservation): FinalEvidenceReservation {\n const parsed = reservationSchema.parse(input)\n if (new Set(parsed.unitIds).size !== parsed.unitIds.length) {\n throw invalid('unitIds must be unique independent source identities')\n }\n return { ...parsed, unitIds: [...parsed.unitIds].sort(compareCodeUnits) }\n}\n\nfunction normalizeMeasurement(input: FinalEvidenceMeasurement): FinalEvidenceMeasurement {\n const parsed = measurementSchema.parse(input)\n return {\n ...parsed,\n candidateDigests: [...new Set(parsed.candidateDigests)].sort(compareCodeUnits),\n }\n}\n\nfunction codec(): LedgerJournalCodec<{ schema: typeof schema }, Event, FinalEvidenceRecord[]> {\n return {\n subject: 'final evidence ledger',\n header: { schema },\n integrityError: (message, options) => new Error(message, options),\n conflictError: (message) => new FinalEvidenceConflictError(message),\n parseEntry: (raw, context) => {\n const decoded = entrySchema.safeParse(raw)\n if (!decoded.success)\n throw new Error(\n `final evidence ledger ${context.path}:${context.line} is invalid: ${decoded.error.message}`,\n )\n const parsed = decoded.data\n return {\n ...parsed,\n previousHash: parsed.previousHash as LedgerHash | null,\n entryHash: parsed.entryHash as LedgerHash,\n }\n },\n checkEntryHeader: (entry) => {\n if (entry.schema !== schema) throw invalid('unsupported ledger schema')\n },\n createProjector: () => {\n const records = new Map<string, FinalEvidenceRecord>()\n const owners = new Map<string, string>()\n const inputOwners = new Map<string, string>()\n return {\n apply: (entry) => {\n const event = entry.event\n if (event.kind === 'reserved') {\n const reservation = normalizeReservation(event.reservation)\n if (\n event.eventId !== `reserve:${reservation.requestId}` ||\n records.has(reservation.requestId)\n ) {\n throw invalid('invalid or duplicate reservation identity')\n }\n const inputOwner = inputOwners.get(reservation.inputDigest)\n if (inputOwner !== undefined) {\n throw new FinalEvidenceConflictError(\n `final input is already reserved by '${inputOwner}'`,\n )\n }\n for (const unitId of reservation.unitIds) {\n const owner = owners.get(unitId)\n if (owner !== undefined) {\n throw new FinalEvidenceConflictError(\n `final unit '${unitId}' is already reserved by '${owner}'`,\n )\n }\n owners.set(unitId, reservation.requestId)\n }\n inputOwners.set(reservation.inputDigest, reservation.requestId)\n records.set(reservation.requestId, {\n reservation,\n reservationHash: entry.entryHash,\n exposure: null,\n })\n } else {\n const record = records.get(event.requestId)\n if (\n event.eventId !== `expose:${event.requestId}` ||\n !record ||\n record.exposure !== null\n ) {\n throw invalid('exposure requires one unexposed reservation')\n }\n record.exposure = {\n measurement: normalizeMeasurement(event.measurement),\n entryHash: entry.entryHash,\n }\n }\n },\n // Records are copied because a later exposure replaces a field of the\n // live record, and a returned projection must not change under its reader.\n snapshot: () => [...records.values()].map((record) => ({ ...record })),\n }\n },\n }\n}\n\nasync function outcome<T>(operation: () => Promise<T>): Promise<FinalEvidenceOutcome<T>> {\n try {\n return { succeeded: true, value: await operation() }\n } catch (error) {\n return {\n succeeded: false,\n error: {\n kind:\n error instanceof FinalEvidenceConflictError\n ? 'conflict'\n : error instanceof TypeError || error instanceof z.ZodError\n ? 'invalid'\n : 'unavailable',\n message: error instanceof Error ? error.message : String(error),\n },\n }\n }\n}\n\n/** Uses the shared locked journal and requires its trusted head on every reopen. */\nexport function openFinalEvidenceLedger(options: { path: string }): FinalEvidenceLedger {\n if (!options.path.trim()) throw invalid('path is empty')\n const journal = new FileLedgerJournal(options.path, codec(), { requireTrustedHead: true })\n return {\n reserve: (input) =>\n outcome(async () => {\n const reservation = normalizeReservation(input)\n const result = await journal.append(\n {\n kind: 'reserved',\n eventId: `reserve:${reservation.requestId}`,\n reservation,\n },\n { pinHead: true },\n )\n const record = result.projection.find(\n (item) => item.reservation.requestId === reservation.requestId,\n )\n if (!record) throw invalid('reserved record is missing after append')\n return { record, replayed: !result.appended }\n }),\n expose: (requestId, input) =>\n outcome(async () => {\n identity.parse(requestId)\n const measurement = normalizeMeasurement(input)\n const result = await journal.append(\n {\n kind: 'exposed',\n eventId: `expose:${requestId}`,\n requestId,\n measurement,\n },\n { pinHead: true },\n )\n const record = result.projection.find((item) => item.reservation.requestId === requestId)\n if (!record) throw invalid('exposed record is missing after append')\n return { record, replayed: !result.appended }\n }),\n read: () => outcome(() => journal.replay()),\n }\n}\n","/**\n * Approximate detectable lift from baseline variance and the intended sample size.\n *\n * Model: the ship rule is `CI.low(paired Δ) > deltaThreshold`. Approximating the\n * bootstrap CI as normal, `CI.low ≈ effect − z·sd_Δ/√n`, so the smallest shippable\n * effect is `MDE = deltaThreshold + z·sd_Δ/√n`. This estimates `sd_Δ` as\n * `√2·sd_baseline`, assuming equal arm variances and zero paired correlation.\n * Actual candidate variance and paired correlation can move the threshold in either direction.\n * This diagnostic does not replace the gate or guarantee a detection probability.\n *\n * Supply one baseline mean per independent observation used by the comparison.\n * With declared source units, repetitions and variants refine those means without increasing n.\n * `selfImprove` attaches this diagnostic after its final measurement.\n */\n\nexport interface PowerPreflightOptions {\n /** Baseline composites at the comparison's independent observation unit. */\n baselineComposites: number[]\n /** Independent paired observations planned for the comparison.\n * Defaults to `baselineComposites.length`. */\n pairedN?: number\n /** The ship gate's effect-size threshold. Default 0.05 (defaultProductionGate). */\n deltaThreshold?: number\n /** CI confidence the gate uses. Default 0.95. */\n confidence?: number\n /** Whether the holdout uses the gate's judge family.\n * More observations cannot establish freedom from systematic scoring bias.\n * Default false. */\n sharedScorerChannel?: boolean\n}\n\nexport interface PowerPreflight {\n /** Paired observations the comparison will have. */\n n: number\n /** Sample standard deviation of baseline observation means. */\n sd: number\n /** Approximate lift needed to put a normal interval above the gate threshold. */\n mde: number\n /** Baseline holdout composite mean. */\n baselineMean: number\n /** Headroom to a perfect 1.0 composite (the largest achievable lift on a [0,1] judge). */\n headroom: number\n /** Whether this approximation exceeds the estimated [0,1] score headroom.\n * This is a planning warning, not a proof that promotion is impossible. */\n underpowered: boolean\n /** True when composites look [0,1]-scaled; headroom/underpowered are only\n * meaningful under that convention (0-100 judges get mde/sd/n but no verdict). */\n scaleAssumed: boolean\n deltaThreshold: number\n confidence: number\n /** Notes unmeasured systematic bias when the gate shares its scoring channel. */\n sharedChannelCaveat?: string\n /** One actionable sentence for humans and logs. */\n recommendation: string\n}\n\n/** Two-sided z for the common confidence levels; interpolation is overkill here. */\nfunction zFor(confidence: number): number {\n if (confidence >= 0.99) return 2.576\n if (confidence >= 0.95) return 1.96\n if (confidence >= 0.9) return 1.645\n return 1.282\n}\n\n/** Estimate detectable lift from baseline independent observations before budgeting a comparison. */\nexport function powerPreflight(opts: PowerPreflightOptions): PowerPreflight {\n const composites = opts.baselineComposites.filter((v) => Number.isFinite(v))\n if (composites.length < 3) {\n throw new Error(\n `powerPreflight: need >= 3 finite baseline composites to estimate variance, got ${composites.length}`,\n )\n }\n const deltaThreshold = opts.deltaThreshold ?? 0.05\n const confidence = opts.confidence ?? 0.95\n const n = opts.pairedN ?? composites.length\n if (n < 2) throw new Error(`powerPreflight: pairedN must be >= 2, got ${n}`)\n\n const mean = composites.reduce((a, b) => a + b, 0) / composites.length\n const variance =\n composites.reduce((a, b) => a + (b - mean) * (b - mean), 0) / (composites.length - 1)\n const sd = Math.sqrt(variance)\n const z = zFor(confidence)\n const mde = deltaThreshold + (z * Math.SQRT2 * sd) / Math.sqrt(n)\n\n const scaleAssumed = composites.every((v) => v >= -0.001 && v <= 1.5)\n const headroom = Math.max(0, 1 - mean)\n const underpowered = scaleAssumed && mde > headroom\n\n const sharedChannelCaveat = opts.sharedScorerChannel\n ? 'Holdout and gate share one scoring channel: systematic judge bias remains outside this estimate. An independent second scoring channel can help test that bias.'\n : undefined\n\n const recommendation = underpowered\n ? `UNDERPOWERED under this approximation: detectable lift ${mde.toFixed(3)} exceeds the ${headroom.toFixed(3)} headroom above the baseline (${mean.toFixed(3)}). Raise paired n using independent observations to ~${Math.ceil(((z * Math.SQRT2 * sd) / Math.max(headroom - deltaThreshold, 0.01)) ** 2)} or reduce observation variance. Recheck with measured paired deltas.`\n : `Approximate detectable lift at n=${n}: ${mde.toFixed(3)} (baseline sd ${sd.toFixed(3)}). Compare this estimate with the effect you expect, then recheck using measured paired deltas.`\n\n return {\n n,\n sd,\n mde,\n baselineMean: mean,\n headroom,\n underpowered,\n scaleAssumed,\n deltaThreshold,\n confidence,\n ...(sharedChannelCaveat ? { sharedChannelCaveat } : {}),\n recommendation: sharedChannelCaveat\n ? `${recommendation} ${sharedChannelCaveat}`\n : recommendation,\n }\n}\n","/**\n * Truncation-tolerant JSON recovery — shared by every parser that reads JSON\n * out of a model response (reflective-mutation proposals, judge scores, the\n * completion-correctness checker).\n *\n * LLMs routinely hit a max_tokens cap mid-emission, leaving a JSON prefix\n * with an unclosed string / object / array and often a dangling key or\n * trailing comma. Throwing on that prefix — and letting the throw fold into\n * a fabricated zero score downstream — is the bug class this module exists\n * to prevent (see `JudgeParseError`'s contract: a synthetic zero is\n * indistinguishable from a real low score). Recovering the complete prefix\n * turns a would-be fabricated zero into a real measurement.\n */\n\n/**\n * Walk the input as JSON-aware (string vs not, escape-aware) and close\n * unclosed `{` / `[` in LIFO order at the tail. If the input was already\n * balanced returns it unchanged. If a string was open at end-of-input we\n * also close it with `\"` first, since a truncated string-mid-value is the\n * most common LLM cap-hit failure mode and JSON.parse cannot proceed\n * without one.\n *\n * Returns null when the structure is unrecoverable (e.g. depth would go\n * negative — that's an *over*-closed prefix, not a truncation).\n */\nexport function autoCloseTruncatedJson(raw: string): string | null {\n const stack: Array<'{' | '['> = []\n let inString = false\n let escaped = false\n for (const c of raw) {\n if (escaped) {\n escaped = false\n continue\n }\n if (inString) {\n if (c === '\\\\') {\n escaped = true\n continue\n }\n if (c === '\"') {\n inString = false\n continue\n }\n continue\n }\n if (c === '\"') {\n inString = true\n continue\n }\n if (c === '{' || c === '[') stack.push(c)\n else if (c === '}') {\n if (stack.pop() !== '{') return null\n } else if (c === ']') {\n if (stack.pop() !== '[') return null\n }\n }\n if (stack.length === 0 && !inString) return raw\n let suffix = ''\n // A truncation right after a backslash leaves an incomplete escape: the\n // closing `\"` we append would be consumed as the escape target and the\n // string would stay open. Complete the escape to a literal backslash first.\n if (escaped) suffix += '\\\\'\n if (inString) suffix += '\"'\n while (stack.length > 0) {\n const opener = stack.pop()!\n suffix += opener === '{' ? '}' : ']'\n }\n return raw + suffix\n}\n\nconst UNPARSEABLE = Symbol('unparseable')\n\nfunction tryParse(candidate: string): unknown {\n try {\n return JSON.parse(candidate)\n } catch {\n return UNPARSEABLE\n }\n}\n\n/** Index of the last `,` that sits outside any string literal, or -1. Cutting\n * there discards a dangling key / half-emitted value at the tail while\n * keeping every complete member before it. */\nfunction lastCommaOutsideString(s: string): number {\n let inString = false\n let escaped = false\n let last = -1\n for (let i = 0; i < s.length; i++) {\n const c = s[i]!\n if (escaped) {\n escaped = false\n continue\n }\n if (inString) {\n if (c === '\\\\') escaped = true\n else if (c === '\"') inString = false\n continue\n }\n if (c === '\"') inString = true\n else if (c === ',') last = i\n }\n return last\n}\n\n/**\n * Best-effort parse of a possibly-truncated JSON payload embedded in model\n * output (prose and markdown fences tolerated). Tries each opener position\n * (earliest `{`/`[` first, then the other when the first yields nothing —\n * prose like `[note] {\"score\":3}` must not poison the slice), and from each\n * start, in order:\n *\n * 1. plain `JSON.parse` of the opener → last-closer slice,\n * 2. auto-closing unclosed structures at the tail\n * (`autoCloseTruncatedJson`),\n * 3. trimming the tail back to the previous complete member boundary (the\n * last comma outside a string) and auto-closing again, repeatedly.\n *\n * Recovers e.g. `{\"correct\": false, \"` → `{ correct: false }` — the exact\n * cap-hit shape that has zeroed real eval rows. Returns the parsed value\n * (always an object or array, given the slice starts at an opener), or\n * `null` when nothing parseable can be recovered. Never throws.\n */\nexport function recoverTruncatedJson(text: string): unknown {\n const objStart = text.indexOf('{')\n const arrStart = text.indexOf('[')\n const starts = [objStart, arrStart].filter((i) => i >= 0).sort((a, b) => a - b)\n for (const start of starts) {\n const recovered = recoverFrom(text.slice(start))\n if (recovered !== UNPARSEABLE) return recovered\n }\n return null\n}\n\nfunction recoverFrom(slice: string): unknown {\n let candidate = slice\n\n const lastClose = Math.max(candidate.lastIndexOf('}'), candidate.lastIndexOf(']'))\n if (lastClose > 0) {\n const balanced = tryParse(candidate.slice(0, lastClose + 1))\n if (balanced !== UNPARSEABLE) return balanced\n }\n\n // Bounded: each iteration strictly shortens the candidate at a comma, so 64\n // covers any realistic member count without risking a pathological spin.\n for (let i = 0; i < 64; i++) {\n const closed = autoCloseTruncatedJson(candidate)\n if (closed !== null) {\n const parsed = tryParse(closed)\n if (parsed !== UNPARSEABLE) return parsed\n }\n const cut = lastCommaOutsideString(candidate)\n if (cut <= 0) return UNPARSEABLE\n candidate = candidate.slice(0, cut)\n }\n return UNPARSEABLE\n}\n","/**\n * Reflective mutation — primitives for trace-conditioned prompt rewriting.\n *\n * Used by `prompt-evolution.ts` (and any consumer running iterative\n * improvement). Given a parent prompt + concrete trace evidence (top trials,\n * bottom trials, missed expectations), produce an LLM-ready prompt that\n * proposes targeted mutations — not blind rephrasings.\n *\n * Why this lives outside `prompt-evolution.ts`: any consumer that wants to\n * run reflective rewriting WITHOUT the population/Pareto machinery can\n * import these primitives directly.\n *\n * Quality bar (vs. naive \"mutate this prompt\"):\n * - Show parent ↔ children diff, not just one variant\n * - Quote specific missed goldens with their match phrases\n * - Surface the model's actual emitted output side-by-side with what was expected\n * - Quote concrete mutation primitives so the model has a vocabulary\n */\n\nimport { autoCloseTruncatedJson } from './json-recovery'\n\n/** Bound on rendered/carried `emitted` evidence. ONE constant shared by the\n * producer (campaignBreakdown's per-scenario excerpt) and this renderer — if\n * the two drifted, the tighter side would silently re-clip carried evidence. */\nexport const EMITTED_EVIDENCE_MAX_CHARS = 2000\n\nexport interface TrialTrace {\n /** Stable id for the trial — surfaces in the prompt for grounding. */\n id: string\n /** Score the trial received on its primary metric. */\n score: number\n /** Candidate inputs the agent was given (e.g., the fixture or scenario). */\n inputName?: string\n /**\n * Goldens / expectations this trial was tested against, with whether each\n * was matched. The reflection prompt quotes the missed ones specifically.\n */\n expectations?: Array<{ id: string; phrase: string; matched: boolean }>\n /** Free-form text — what the agent actually emitted (e.g., findings, plan). */\n emitted?: string\n /** The judge's free-form note on WHY this trial scored low — the failure\n * evidence the reflection targets. Should be a generalizable pattern (which\n * checks/lines/dimensions failed, and how), never case-specific ground\n * truth (that would teach memorization, not capability). */\n failureNote?: string\n /** Optional structured metrics (recall, precision, cost, latency). */\n metrics?: Record<string, number>\n}\n\nexport interface ReflectionContext {\n /** What is being mutated — appears in the system prompt for orientation. */\n target: string\n /** Current variant's payload — JSON-serialised for the prompt. */\n parentPayload: unknown\n /** Best-performing trials this generation. */\n topTrials: TrialTrace[]\n /** Worst-performing trials this generation — the missed-golden source. */\n bottomTrials: TrialTrace[]\n /** How many children the mutator should propose. */\n childCount: number\n /** Optional: domain-specific mutation primitives the model can pick from. */\n mutationPrimitives?: string[]\n}\n\nexport const DEFAULT_MUTATION_PRIMITIVES: string[] = [\n 'Strengthen an imperative (\"should\" → \"must\")',\n 'Add a concrete example pulled from a missed-golden phrase',\n 'Remove a redundant rule that did not improve recall',\n 'Add a counterfactual (\"if X is missing, the score is capped at Y\")',\n 'Reorder sections so the highest-impact rule is first',\n 'Replace abstract language with a domain-specific noun the trial misses',\n]\n\n/**\n * Build the LLM-ready reflection prompt. Output is plain text — pass it as\n * the user message. The system message should be small and stable (e.g.\n * \"Output ONLY a JSON object matching the schema below.\").\n */\nexport function buildReflectionPrompt(ctx: ReflectionContext): string {\n const primitives = ctx.mutationPrimitives ?? DEFAULT_MUTATION_PRIMITIVES\n const sections: string[] = []\n\n sections.push(`# Mutation target: ${ctx.target}`)\n sections.push('')\n sections.push(\n `You are tuning the prompt component named \\`${ctx.target}\\`. The current variant is shown below; you have ${ctx.topTrials.length} top trials and ${ctx.bottomTrials.length} bottom trials as evidence. Propose ${ctx.childCount} mutation${ctx.childCount === 1 ? '' : 's'} that fix specific weaknesses visible in the bottom trials. Avoid blank rephrasings.`,\n )\n sections.push('')\n\n sections.push('## Current variant')\n sections.push('```json')\n sections.push(JSON.stringify(ctx.parentPayload, null, 2))\n sections.push('```')\n sections.push('')\n\n if (ctx.bottomTrials.length > 0) {\n sections.push('## Failures (bottom trials) — what went wrong')\n sections.push('')\n for (const trial of ctx.bottomTrials) {\n sections.push(\n `### Trial \\`${trial.id}\\` — score ${trial.score.toFixed(2)}${trial.inputName ? ` (${trial.inputName})` : ''}`,\n )\n if (trial.failureNote) {\n sections.push('')\n // 1500 chars fits a real traceback / failing-assertion note; clipping\n // mid-traceback would hide the executable-judge evidence the\n // reflection targets.\n sections.push(`**Why it scored low:** ${truncate(trial.failureNote, 1500)}`)\n }\n const missed = (trial.expectations ?? []).filter((e) => !e.matched)\n if (missed.length > 0) {\n sections.push('')\n sections.push('**Missed expectations:**')\n for (const m of missed) {\n sections.push(`- \\`${m.id}\\`: should match phrase \\`${quote(m.phrase)}\\``)\n }\n }\n if (trial.emitted) {\n sections.push('')\n sections.push('**What the agent emitted:**')\n sections.push('```')\n sections.push(truncate(trial.emitted, EMITTED_EVIDENCE_MAX_CHARS))\n sections.push('```')\n }\n sections.push('')\n }\n }\n\n if (ctx.topTrials.length > 0) {\n sections.push('## Successes (top trials) — what to preserve')\n sections.push('')\n for (const trial of ctx.topTrials) {\n sections.push(\n `- \\`${trial.id}\\`: score ${trial.score.toFixed(2)}${trial.inputName ? ` (${trial.inputName})` : ''}`,\n )\n }\n sections.push('')\n }\n\n sections.push('## Allowed mutation primitives')\n sections.push('')\n for (const p of primitives) sections.push(`- ${p}`)\n sections.push('')\n\n sections.push('## Output schema')\n sections.push('')\n sections.push('Respond with a JSON object — no prose, no markdown fences:')\n sections.push('```json')\n sections.push(\n JSON.stringify(\n {\n proposals: [\n {\n label: '<short label, ≤ 40 chars>',\n rationale: '<which failure this targets and which primitive you used>',\n payload: '<full payload of the new variant — same shape as the current variant>',\n },\n ],\n },\n null,\n 2,\n ),\n )\n sections.push('```')\n\n return sections.join('\\n')\n}\n\nfunction truncate(s: string, max: number): string {\n if (s.length <= max) return s\n return `${s.slice(0, max)}… [truncated]`\n}\n\nfunction quote(s: string): string {\n return s.replace(/`/g, '\\\\`')\n}\n\nexport interface ReflectionProposal {\n label: string\n rationale: string\n payload: unknown\n}\n\n/**\n * Parse the model's JSON response back into proposals. Tolerates markdown\n * fences and surrounding prose. Returns at most `maxProposals`.\n */\nexport function parseReflectionResponse(raw: string, maxProposals?: number): ReflectionProposal[] {\n let text = raw.trim()\n if (text.startsWith('```')) text = text.replace(/^```(?:json)?\\n?/, '').replace(/\\n?```$/, '')\n\n // Try to parse as either a JSON object `{proposals: [...]}` or a bare\n // array `[...]`. LLMs frequently emit one or the other depending on how\n // they read the schema example; accept both.\n let parsed: unknown = null\n const objectStart = text.indexOf('{')\n const objectEnd = text.lastIndexOf('}')\n const arrayStart = text.indexOf('[')\n const arrayEnd = text.lastIndexOf(']')\n // Prefer whichever delimiter comes first (the model committed to that shape).\n const tryObjectFirst = objectStart >= 0 && (arrayStart < 0 || objectStart < arrayStart)\n const candidates: string[] = []\n if (tryObjectFirst) {\n if (objectStart >= 0 && objectEnd > objectStart)\n candidates.push(text.slice(objectStart, objectEnd + 1))\n if (arrayStart >= 0 && arrayEnd > arrayStart)\n candidates.push(text.slice(arrayStart, arrayEnd + 1))\n } else {\n if (arrayStart >= 0 && arrayEnd > arrayStart)\n candidates.push(text.slice(arrayStart, arrayEnd + 1))\n if (objectStart >= 0 && objectEnd > objectStart)\n candidates.push(text.slice(objectStart, objectEnd + 1))\n }\n for (const slice of candidates) {\n try {\n parsed = JSON.parse(slice)\n break\n } catch {\n // try next\n }\n }\n\n // Truncation-tolerant fallback: LLMs frequently hit a max_tokens cap\n // mid-emission, leaving N unclosed `}` / `]` at the tail. Close them in\n // order from the deepest unclosed structure outward, by walking the\n // candidate slice and tracking depth, then retrying JSON.parse. This\n // recovers any complete proposals before the cutoff and drops the rest.\n if (parsed == null) {\n for (const slice of candidates) {\n const closed = autoCloseTruncatedJson(slice)\n if (closed != null && closed !== slice) {\n try {\n parsed = JSON.parse(closed)\n break\n } catch {\n // give up on this candidate\n }\n }\n }\n }\n\n if (parsed == null) return []\n\n // Normalize: accept `{proposals: [...]}` or a bare array.\n let proposalsRaw: unknown\n if (Array.isArray(parsed)) {\n proposalsRaw = parsed\n } else if (parsed && typeof parsed === 'object') {\n proposalsRaw = (parsed as { proposals?: unknown }).proposals\n }\n if (!Array.isArray(proposalsRaw)) return []\n\n const out: ReflectionProposal[] = []\n for (const p of proposalsRaw) {\n if (!p || typeof p !== 'object') continue\n const obj = p as { label?: unknown; rationale?: unknown; payload?: unknown }\n if (!('payload' in obj)) continue\n out.push({\n label: typeof obj.label === 'string' ? obj.label : 'mutation',\n rationale: typeof obj.rationale === 'string' ? obj.rationale : '',\n payload: obj.payload,\n })\n if (maxProposals !== undefined && out.length >= maxProposals) break\n }\n return out\n}\n","/**\n * Shared campaign-score reductions used by every optimizer preset\n * (`runOptimization`, external optimization methods, `compareOptimizationMethods`).\n * \"composite of a campaign\" and \"per-scenario / per-dimension breakdown\" so\n * the optimizers cannot drift on how a surface's score is computed.\n */\n\nimport { EMITTED_EVIDENCE_MAX_CHARS } from '../reflective-mutation'\nimport { aggregatePairedHoldout, pairHoldout } from './gates/statistical-heldout'\nimport { projectCampaignCellQuality } from './run-record'\nimport type { CampaignResult, JudgeScore, Scenario } from './types'\n\nexport interface CampaignComparisonUnits {\n pairedCellN: number\n unitIds: string[]\n /** Cells with no complete quality score on either arm. */\n unscoredCellIds: string[]\n /** Present when repetitions and source variants share an independent unit. */\n independentUnitByScenarioId?: Record<string, string>\n}\n\n/** Reduce complete paired cells using the same observation units as held-out inference. */\nexport function pairedCampaignComposites<TArtifact, TScenario extends Scenario>(\n baseline: CampaignResult<TArtifact, TScenario>,\n candidate: CampaignResult<TArtifact, TScenario>,\n independentUnitByScenarioId?: ReadonlyMap<string, string>,\n): {\n before: number[]\n after: number[]\n beforeMean: number\n afterMean: number\n observations: CampaignComparisonUnits\n} {\n const scoresByCell = (campaign: CampaignResult<TArtifact, TScenario>) => {\n const scores = new Map<string, Record<string, JudgeScore>>()\n for (const cell of campaign.cells) {\n if (scores.has(cell.cellId)) {\n throw new Error(`pairedCampaignComposites: duplicate cell '${cell.cellId}'`)\n }\n const quality = projectCampaignCellQuality(cell)\n scores.set(cell.cellId, quality.score === undefined ? {} : quality.successfulJudgeScores)\n }\n return scores\n }\n const scenarioIds = new Set(\n [...baseline.cells, ...candidate.cells].map((cell) => cell.scenarioId),\n )\n const paired = pairHoldout(\n scoresByCell(candidate),\n scoresByCell(baseline),\n scenarioIds,\n (score) => score.composite,\n )\n const observations = aggregatePairedHoldout(paired, independentUnitByScenarioId)\n const scoredCellIds = new Set(paired.cellIds)\n if (observations.before.length === 0) {\n throw new Error('pairedCampaignComposites: campaigns have no paired quality scores')\n }\n return {\n before: observations.before,\n after: observations.after,\n beforeMean:\n observations.before.reduce((sum, score) => sum + score, 0) / observations.before.length,\n afterMean:\n observations.after.reduce((sum, score) => sum + score, 0) / observations.after.length,\n observations: {\n pairedCellN: paired.cellIds.length,\n unitIds: observations.unitIds,\n unscoredCellIds: baseline.cells\n .filter((cell) => !scoredCellIds.has(cell.cellId))\n .map((cell) => cell.cellId)\n .sort(),\n ...(independentUnitByScenarioId\n ? {\n independentUnitByScenarioId: Object.fromEntries(\n [...scenarioIds].sort().map((id) => [id, independentUnitByScenarioId.get(id)!]),\n ),\n }\n : {}),\n },\n }\n}\n\n/** Mean composite across cells with complete task-quality evidence.\n * Partial judge results remain on their cells but never enter this value.\n * A campaign with no complete score has no numeric mean and fails loudly. */\nexport function campaignMeanComposite<TArtifact, TScenario extends Scenario>(\n campaign: CampaignResult<TArtifact, TScenario>,\n): number {\n const mean = campaignMeanCompositeOrNull(campaign)\n if (mean === null) {\n throw new Error('campaignMeanComposite: campaign has no complete cell-quality scores')\n }\n return mean\n}\n\n/** Nullable campaign mean for wire and report fields that represent missing quality. */\nexport function campaignMeanCompositeOrNull<TArtifact, TScenario extends Scenario>(\n campaign: CampaignResult<TArtifact, TScenario>,\n): number | null {\n const scores = campaign.cells.flatMap((cell) => {\n const score = projectCampaignCellQuality(cell).score\n return score === undefined ? [] : [score]\n })\n return scores.length === 0 ? null : scores.reduce((sum, score) => sum + score, 0) / scores.length\n}\n\nexport interface CampaignBreakdown {\n /** Mean score per judge dimension across all cells. */\n dimensions: Record<string, number>\n /** Per-scenario composite (mean over reps + judges) + the judge's free-form\n * `notes` for that scenario (the \"why\" a reflective proposer grounds on) +\n * an optional `emitted` excerpt of the candidate's raw output (the \"what it\n * actually did\" a reflective proposer grounds on). */\n scenarios: Array<{ scenarioId: string; composite: number; notes?: string; emitted?: string }>\n}\n\n/** Per-candidate evidence a reflective/patch proposer grounds its next proposal\n * on: mean score per judge dimension + per-scenario composite. */\nexport function campaignBreakdown<TArtifact, TScenario extends Scenario>(\n campaign: CampaignResult<TArtifact, TScenario>,\n): CampaignBreakdown {\n const dimSums: Record<string, number> = {}\n const dimCounts: Record<string, number> = {}\n const byScenario = new Map<string, number[]>()\n const notesByScenario = new Map<string, Set<string>>()\n const emittedByScenario = new Map<string, { composite: number; text: string }>()\n for (const cell of campaign.cells) {\n const quality = projectCampaignCellQuality(cell)\n if (quality.score === undefined) continue\n const judgeScores = Object.values(quality.successfulJudgeScores)\n const cellComposite = quality.score\n const arr = byScenario.get(cell.scenarioId) ?? []\n arr.push(cellComposite)\n byScenario.set(cell.scenarioId, arr)\n // Carry the candidate's raw output as trajectory evidence when the artifact\n // is a string (the common prompt-tier shape). Across reps, keep the\n // LOWEST-composite cell's output — reflection grounds on the failure, and\n // the bottom-trial excerpt is the one buildReflectionPrompt renders.\n if (typeof cell.artifact === 'string' && cell.artifact.trim().length > 0) {\n const prev = emittedByScenario.get(cell.scenarioId)\n if (!prev || cellComposite < prev.composite) {\n emittedByScenario.set(cell.scenarioId, {\n composite: cellComposite,\n text: cell.artifact.slice(0, EMITTED_EVIDENCE_MAX_CHARS),\n })\n }\n }\n // Collect the judges' free-form notes per scenario (deduped) — the failure\n // evidence the reflective proposer grounds on. Generalizable by contract;\n // the judge must not put case-specific ground truth here.\n for (const s of judgeScores) {\n if (s.notes?.trim()) {\n const set = notesByScenario.get(cell.scenarioId) ?? new Set<string>()\n set.add(s.notes.trim())\n notesByScenario.set(cell.scenarioId, set)\n }\n }\n for (const score of judgeScores) {\n for (const [key, value] of Object.entries(score.dimensions)) {\n if (!Number.isFinite(value)) continue\n dimSums[key] = (dimSums[key] ?? 0) + value\n dimCounts[key] = (dimCounts[key] ?? 0) + 1\n }\n }\n }\n const dimensions: Record<string, number> = {}\n for (const key of Object.keys(dimSums)) {\n const count = dimCounts[key] ?? 0\n dimensions[key] = count > 0 ? (dimSums[key] ?? 0) / count : 0\n }\n const scenarios = [...byScenario.entries()].map(([scenarioId, comps]) => {\n const notesSet = notesByScenario.get(scenarioId)\n const notes = notesSet && notesSet.size > 0 ? [...notesSet].join(' | ') : undefined\n const emitted = emittedByScenario.get(scenarioId)?.text\n return {\n scenarioId,\n composite: comps.reduce((a, b) => a + b, 0) / comps.length,\n ...(notes ? { notes } : {}),\n ...(emitted ? { emitted } : {}),\n }\n })\n return { dimensions, scenarios }\n}\n","/**\n * Loop provenance — the durable, queryable record of WHAT a self-improvement\n * loop did and WHY, plus the OTel spans that let an OTLP collector pivot from\n * an eval-run to the underlying candidate→cell→gate→promote chain.\n *\n * Two artifacts, one source of truth:\n *\n * 1. `LoopProvenanceRecord` — a structured JSON record capturing every\n * candidate (surfaceHash + label + rationale + structured cause), its measured composite,\n * the gate decision + reasons + delta, the held-out lift, the explicit\n * baseline→candidate diff, and BACKEND PROVENANCE (the\n * `assertRealBackend` verdict + worker call count + model). This is the\n * ingestable audit artifact: the +lift recomputes from it, the \"because\n * Z\" rationale survives in it, and a stub backend is detectable from it.\n *\n * 2. `loopProvenanceSpans()` — the same chain emitted as OTLP-ingestable\n * `TraceSpanEvent`s, pivoted on the substrate's standard\n * `tangle.runId` / `tangle.scenarioId` / `tangle.cellId` /\n * `tangle.generation` attributes (the same pivots `/adapters/otel`\n * reads). The hosted `/v1/ingest/traces` endpoint receives the FULL loop,\n * not just the `cost.*` spans `runCampaign` already emits per cell.\n *\n * The record is built from the loop result and its settled cost receipts — no\n * second usage collector can contradict what the measured cells recorded.\n */\n\nimport { createHash } from 'node:crypto'\nimport { join } from 'node:path'\nimport type { CostReceipt } from '../cost-ledger'\nimport { defineEvaluationClaim, type EvaluationClaim } from '../experiment/claim'\nimport type { HostedClient } from '../hosted/client'\nimport type { TraceSpanEvent } from '../hosted/types'\nimport { summarizeAgentReceiptIntegrity } from '../integrity/backend-integrity'\nimport { canonicalString, compareCodeUnits, hashCanonical } from '../ledger-core/canonical'\nimport { assertCampaignSplitIdentity } from './coverage'\nimport type {\n ComparisonCost,\n OptimizationMethodProvenance,\n} from './presets/compare-optimization-methods'\nimport type { RunImprovementLoopResult } from './presets/run-improvement-loop'\nimport {\n type CampaignComparisonUnits,\n campaignMeanComposite,\n pairedCampaignComposites,\n} from './score-utils'\nimport type { CampaignStorage } from './storage'\nimport {\n renderSurfaceDiff,\n surfaceContentHash,\n surfaceHash,\n surfaceHashMatches,\n} from './surface-identity'\nimport type {\n CampaignResult,\n GateContribution,\n GateDecision,\n GateResult,\n GenerationCandidate,\n MutableSurface,\n Scenario,\n} from './types'\n\nexport interface LoopProvenanceCandidate {\n /** Generation index this candidate was proposed in. */\n generation: number\n /** 16-char loop-identity fingerprint (matches `GenerationCandidate.surfaceHash`). */\n surfaceHash: string\n /** Full sha256 content hash — byte-identical-verifiable. */\n contentHash: string\n /** Exact scored rows that produced this candidate's search result. */\n campaignDigest: `sha256:${string}`\n /** Proposer label, when the proposer returned a `ProposedCandidate`. */\n label?: string\n /** Proposer rationale — the \"because Z\". When the proposer returned a bare\n * surface (blind mutator) this is absent. */\n rationale?: string\n /** Proposer-supplied typed attribution, carried unchanged from\n * `GenerationCandidate.attribution`. Opaque here; the producer's schema tag\n * governs interpretation. */\n attribution?: Readonly<Record<string, unknown>>\n /** Whether the candidate completed every designed cell and could be selected. */\n eligibleForPromotion: boolean\n /** Designed-denominator receipt retained even for incomplete candidates. */\n coverage: NonNullable<GenerationCandidate['coverage']>\n /** Mean composite this candidate scored on the search split, or null when unscorable. */\n composite: number | null\n /** Whether this candidate was promoted out of its generation. */\n promoted: boolean\n}\n\nexport interface LoopProvenanceBackend {\n /** `assertRealBackend`-grade verdict over the worker call records. */\n verdict: 'real' | 'mixed' | 'stub'\n /** Number of worker LLM calls captured (the audit's \"worker call count\"). */\n workerCallCount: number\n /** Distinct model ids observed across worker calls. */\n models: string[]\n totalInputTokens: number\n totalOutputTokens: number\n totalCostUsd: number\n}\n\nexport interface LoopProvenanceEvidence {\n search: {\n splitDigest: `sha256:${string}`\n baselineCampaignDigest: `sha256:${string}`\n }\n holdout: {\n splitDigest: `sha256:${string}`\n baselineCampaignDigest: `sha256:${string}`\n winnerCampaignDigest: `sha256:${string}`\n observations?: CampaignComparisonUnits\n neutralized?: {\n contentHash: `sha256:${string}`\n campaignDigest: `sha256:${string}`\n composite: number\n lift: number\n }\n }\n costReceiptsDigest: `sha256:${string}`\n}\n\nexport interface LoopProvenanceOptimizationMethod {\n name: string\n cost: ComparisonCost\n durationMs?: number\n provenance?: OptimizationMethodProvenance\n}\n\n/**\n * The durable provenance record: the baseline and winner measurements, the\n * rationale, the explicit baseline→candidate diff, and backend provenance.\n */\nexport interface LoopProvenanceRecord {\n schema: 'tangle.loop-provenance'\n /** SHA-256 over the canonical record with this field omitted. */\n recordDigest: `sha256:${string}`\n runId: string\n runDir: string\n timestamp: string\n /** Baseline + winner surface content hashes — distinguishable, byte-verifiable. */\n baselineContentHash: string\n winnerContentHash: string\n /** Proposer label/rationale for the promoted change. Absent ⇒ winner == baseline. */\n winnerLabel?: string\n winnerRationale?: string\n /** The explicit baseline→winner unified diff the gate decided on. */\n diff: string\n /** Every candidate across every generation, with its rationale and structured cause. */\n candidates: LoopProvenanceCandidate[]\n /** Complete external method identity and spend, when one authored the candidate. */\n optimizationMethod?: LoopProvenanceOptimizationMethod\n /** Exact campaign, split, surface, and receipt identities behind every summary. */\n evidence: LoopProvenanceEvidence\n /** Baseline composite on the search split that generated the candidates. */\n baselineSearchComposite: number\n claim?: EvaluationClaim\n /** The gate verdict — decision + reasons + contributing gates + delta. */\n gate: {\n decision: GateDecision\n reasons: string[]\n delta?: number\n contributingGates: GateContribution[]\n }\n /** Present iff the loop ran with `holdout: 'deferred'` — the held-out\n * comparison was intentionally not measured in this run, so the holdout\n * composites and `heldOutLift` are ABSENT rather than recorded as a\n * meaningless 0. */\n holdout?: 'deferred'\n /** baseline-on-holdout composite mean. Absent when `holdout === 'deferred'`. */\n baselineHoldoutComposite?: number\n /** winner-on-holdout composite mean. Absent when `holdout === 'deferred'`. */\n winnerHoldoutComposite?: number\n /** winnerHoldout - baselineHoldout — RECOMPUTABLE from this record. Absent\n * when `holdout === 'deferred'` (no held-out measurement ran). */\n heldOutLift?: number\n /** Backend provenance: stub-vs-real verdict + worker call count + models. */\n backend: LoopProvenanceBackend\n totalCostUsd: number\n totalDurationMs: number\n}\n\nexport interface BuildLoopProvenanceArgs<TArtifact, TScenario extends Scenario> {\n runId: string\n runDir: string\n timestamp: string\n baselineSurface: MutableSurface\n winnerSurface: MutableSurface\n winnerLabel?: string\n winnerRationale?: string\n /** Exact baseline campaign on the search split. */\n baselineSearchCampaign: CampaignResult<TArtifact, TScenario>\n /** Per-generation candidate records straight off the loop result. */\n generations: Array<{\n generationIndex: number\n candidates: GenerationCandidate[]\n promoted: string[]\n /** Surfaces measured this generation, keyed by surface hash so the content\n * hash can be computed and the loop identity rechecked from real bytes. */\n surfaces: Array<{\n surfaceHash: string\n surface: MutableSurface\n campaign: CampaignResult<TArtifact, TScenario>\n }>\n }>\n gate: GateResult\n /** Holdout policy the loop ran with. `'deferred'` ⇒ the holdout campaigns\n * below are the shared empty campaign and the record omits the holdout\n * composites + `heldOutLift`. Default `'measured'`. */\n holdout?: 'measured' | 'deferred'\n baselineOnHoldout: CampaignResult<TArtifact, TScenario>\n winnerOnHoldout: CampaignResult<TArtifact, TScenario>\n claim?: EvaluationClaim\n /** Required with a measured claim because campaign identities redact source fields. */\n independentUnitByScenarioId?: ReadonlyMap<string, string>\n neutralizedSurface?: MutableSurface\n neutralizedOnHoldout?: CampaignResult<TArtifact, TScenario>\n /** Settled run-wide receipts — agent calls are the source for backend provenance. */\n costReceipts: ReadonlyArray<CostReceipt>\n totalCostUsd: number\n totalDurationMs: number\n optimizationMethod?: LoopProvenanceOptimizationMethod\n}\n\nexport interface LoopProvenanceArgsFromResult<TArtifact, TScenario extends Scenario> {\n runId: string\n runDir: string\n timestamp: string\n baselineSurface: MutableSurface\n result: RunImprovementLoopResult<TArtifact, TScenario>\n costReceipts: ReadonlyArray<CostReceipt>\n totalCostUsd: number\n totalDurationMs: number\n independentUnitByScenarioId?: ReadonlyMap<string, string>\n}\n\n/** One translation from a completed improvement loop into durable evidence. */\nexport function loopProvenanceArgsFromResult<TArtifact, TScenario extends Scenario>(\n input: LoopProvenanceArgsFromResult<TArtifact, TScenario>,\n): BuildLoopProvenanceArgs<TArtifact, TScenario> {\n const { result } = input\n return {\n runId: input.runId,\n runDir: input.runDir,\n timestamp: input.timestamp,\n baselineSurface: input.baselineSurface,\n winnerSurface: result.winnerSurface,\n ...(result.winnerLabel ? { winnerLabel: result.winnerLabel } : {}),\n ...(result.winnerRationale ? { winnerRationale: result.winnerRationale } : {}),\n baselineSearchCampaign: result.baselineCampaign,\n generations: result.generations.map(({ record, surfaces }) => ({\n generationIndex: record.generationIndex,\n candidates: record.candidates,\n promoted: record.promoted,\n surfaces: surfaces.map(({ surfaceHash, surface, campaign }) => ({\n surfaceHash,\n surface,\n campaign,\n })),\n })),\n gate: result.gateResult,\n ...(result.holdout === 'deferred' ? { holdout: 'deferred' as const } : {}),\n baselineOnHoldout: result.baselineOnHoldout,\n winnerOnHoldout: result.winnerOnHoldout,\n ...(result.claim ? { claim: result.claim } : {}),\n ...(input.independentUnitByScenarioId\n ? { independentUnitByScenarioId: input.independentUnitByScenarioId }\n : {}),\n ...(result.neutralizedSurface && result.neutralizedOnHoldout\n ? {\n neutralizedSurface: result.neutralizedSurface,\n neutralizedOnHoldout: result.neutralizedOnHoldout,\n }\n : {}),\n costReceipts: input.costReceipts,\n totalCostUsd: input.totalCostUsd,\n totalDurationMs: input.totalDurationMs,\n }\n}\n\n/** Build the durable provenance record from a completed loop result. */\nexport function buildLoopProvenanceRecord<TArtifact, TScenario extends Scenario>(\n args: BuildLoopProvenanceArgs<TArtifact, TScenario>,\n): LoopProvenanceRecord {\n if (!args.runId.trim() || !args.runDir.trim()) {\n throw new Error('buildLoopProvenanceRecord: runId and runDir must be non-empty')\n }\n const timestampMs = Date.parse(args.timestamp)\n if (!Number.isFinite(timestampMs) || new Date(timestampMs).toISOString() !== args.timestamp) {\n throw new Error('buildLoopProvenanceRecord: timestamp must be a canonical ISO instant')\n }\n assertGateContributions(args.gate.contributingGates, 'buildLoopProvenanceRecord')\n const agentReceipts = args.costReceipts.filter((receipt) => receipt.channel === 'agent')\n const integrity = summarizeAgentReceiptIntegrity(agentReceipts)\n const models = [...new Set(agentReceipts.map((receipt) => receipt.model))].sort()\n const baselineSearchComposite = campaignMeanComposite(args.baselineSearchCampaign)\n if (!Number.isFinite(baselineSearchComposite)) {\n throw new Error('buildLoopProvenanceRecord: baselineSearchComposite must be finite')\n }\n\n const candidates: LoopProvenanceCandidate[] = []\n let incumbentSurfaceHash = surfaceHash(args.baselineSurface)\n let incumbentComposite = baselineSearchComposite\n let previousGeneration = -1\n for (const gen of args.generations) {\n if (\n !Number.isSafeInteger(gen.generationIndex) ||\n gen.generationIndex !== previousGeneration + 1\n ) {\n throw new Error(\n 'buildLoopProvenanceRecord: generation indices must be contiguous integers starting at zero',\n )\n }\n previousGeneration = gen.generationIndex\n if (gen.candidates.length === 0) {\n throw new Error('buildLoopProvenanceRecord: a recorded generation must contain a candidate')\n }\n if (new Set(gen.promoted).size !== gen.promoted.length || gen.promoted.length > 1) {\n throw new Error(\n 'buildLoopProvenanceRecord: each generation may promote at most one candidate',\n )\n }\n const promotedSet = new Set(gen.promoted)\n const surfaceByHash = new Map(gen.surfaces.map((measured) => [measured.surfaceHash, measured]))\n const candidateByHash = new Map(\n gen.candidates.map((candidate) => [candidate.surfaceHash, candidate]),\n )\n if (candidateByHash.size !== gen.candidates.length) {\n throw new Error('buildLoopProvenanceRecord: duplicate candidate surface hash')\n }\n if (surfaceByHash.size !== gen.surfaces.length) {\n throw new Error('buildLoopProvenanceRecord: duplicate candidate surface entry')\n }\n if (surfaceByHash.size !== candidateByHash.size) {\n throw new Error(\n 'buildLoopProvenanceRecord: every measured candidate requires exactly one surface',\n )\n }\n for (const promotedHash of promotedSet) {\n if (!candidateByHash.has(promotedHash)) {\n throw new Error('buildLoopProvenanceRecord: promoted hash has no measured candidate')\n }\n }\n for (const c of gen.candidates) {\n validateCandidateMeasurement(c, incumbentComposite, promotedSet.has(c.surfaceHash))\n const measured = surfaceByHash.get(c.surfaceHash)\n if (measured === undefined) {\n throw new Error('buildLoopProvenanceRecord: measured candidate is missing its surface')\n }\n const { surface, campaign } = measured\n if (!surfaceHashMatches(surface, c.surfaceHash)) {\n throw new Error(\n 'buildLoopProvenanceRecord: candidate surface hash does not match its surface bytes',\n )\n }\n if (campaign.splitDigest !== args.baselineSearchCampaign.splitDigest) {\n throw new Error(\n 'buildLoopProvenanceRecord: candidate campaign does not match the search split',\n )\n }\n const entry: LoopProvenanceCandidate = {\n generation: gen.generationIndex,\n surfaceHash: c.surfaceHash,\n contentHash: surfaceContentHash(surface),\n campaignDigest: campaignMeasurementDigest(campaign),\n eligibleForPromotion: c.eligibleForPromotion,\n coverage: {\n expectedCells: c.coverage.expectedCells,\n scorableCells: c.coverage.scorableCells,\n unscorableCells: c.coverage.unscorableCells.map((cell) => ({ ...cell })),\n },\n composite: c.composite,\n promoted: promotedSet.has(c.surfaceHash),\n }\n if (c.label) entry.label = c.label\n if (c.rationale) entry.rationale = c.rationale\n if (c.attribution) entry.attribution = c.attribution\n candidates.push(entry)\n }\n const promotedHash = gen.promoted[0]\n if (promotedHash) {\n const promoted = candidateByHash.get(promotedHash)!\n incumbentSurfaceHash = promoted.surfaceHash\n if (promoted.composite === null) {\n throw new Error('buildLoopProvenanceRecord: promoted candidate is missing a composite')\n }\n incumbentComposite = promoted.composite\n }\n }\n if (surfaceHash(args.winnerSurface) !== incumbentSurfaceHash) {\n throw new Error(\n 'buildLoopProvenanceRecord: winner surface does not match the final promoted incumbent',\n )\n }\n\n const holdoutDeferred = args.holdout === 'deferred'\n const claim = args.claim ? defineEvaluationClaim(args.claim) : undefined\n if (claim && !holdoutDeferred && args.independentUnitByScenarioId === undefined) {\n throw new Error('buildLoopProvenanceRecord: a measured claim requires its independent-unit map')\n }\n if (args.baselineOnHoldout.splitDigest !== args.winnerOnHoldout.splitDigest) {\n throw new Error('buildLoopProvenanceRecord: baseline and winner use different holdout splits')\n }\n if ((args.neutralizedSurface === undefined) !== (args.neutralizedOnHoldout === undefined)) {\n throw new Error(\n 'buildLoopProvenanceRecord: neutralized surface and campaign must be supplied together',\n )\n }\n if (\n args.neutralizedOnHoldout &&\n args.neutralizedOnHoldout.splitDigest !== args.baselineOnHoldout.splitDigest\n ) {\n throw new Error(\n 'buildLoopProvenanceRecord: neutralized campaign uses a different holdout split',\n )\n }\n if (holdoutDeferred && args.neutralizedOnHoldout) {\n throw new Error(\n 'buildLoopProvenanceRecord: a deferred holdout cannot include a neutralized measurement',\n )\n }\n const holdoutScores = holdoutDeferred\n ? undefined\n : pairedCampaignComposites(\n args.baselineOnHoldout,\n args.winnerOnHoldout,\n args.independentUnitByScenarioId,\n )\n const holdoutMeasurement =\n holdoutScores === undefined\n ? { kind: 'deferred' as const }\n : {\n kind: 'measured' as const,\n baseline: holdoutScores.beforeMean,\n winner: holdoutScores.afterMean,\n ...(args.neutralizedOnHoldout\n ? {\n neutralized: pairedCampaignComposites(\n args.baselineOnHoldout,\n args.neutralizedOnHoldout,\n args.independentUnitByScenarioId,\n ).afterMean,\n }\n : {}),\n }\n\n const diff =\n surfaceContentHash(args.baselineSurface) === surfaceContentHash(args.winnerSurface)\n ? ''\n : renderSurfaceDiff(args.winnerSurface, args.baselineSurface)\n\n const recordWithoutDigest: Omit<LoopProvenanceRecord, 'recordDigest'> = {\n schema: 'tangle.loop-provenance',\n runId: args.runId,\n runDir: args.runDir,\n timestamp: args.timestamp,\n baselineContentHash: surfaceContentHash(args.baselineSurface),\n winnerContentHash: surfaceContentHash(args.winnerSurface),\n diff,\n candidates,\n evidence: {\n search: {\n splitDigest: args.baselineSearchCampaign.splitDigest,\n baselineCampaignDigest: campaignMeasurementDigest(args.baselineSearchCampaign),\n },\n holdout: {\n splitDigest: args.baselineOnHoldout.splitDigest,\n baselineCampaignDigest: campaignMeasurementDigest(args.baselineOnHoldout),\n winnerCampaignDigest: campaignMeasurementDigest(args.winnerOnHoldout),\n ...(holdoutScores ? { observations: holdoutScores.observations } : {}),\n ...(args.neutralizedSurface &&\n args.neutralizedOnHoldout &&\n holdoutMeasurement.kind === 'measured' &&\n holdoutMeasurement.neutralized !== undefined\n ? {\n neutralized: {\n contentHash: surfaceContentHash(args.neutralizedSurface),\n campaignDigest: campaignMeasurementDigest(args.neutralizedOnHoldout),\n composite: holdoutMeasurement.neutralized,\n lift: holdoutMeasurement.neutralized - holdoutMeasurement.baseline,\n },\n }\n : {}),\n },\n costReceiptsDigest: canonicalDigest(\n [...args.costReceipts].sort((left, right) => compareCodeUnits(left.callId, right.callId)),\n ),\n },\n baselineSearchComposite,\n ...(claim ? { claim } : {}),\n gate: {\n decision: args.gate.decision,\n reasons: args.gate.reasons,\n ...(args.gate.delta === undefined ? {} : { delta: args.gate.delta }),\n contributingGates: args.gate.contributingGates.map((g) => ({\n name: g.name,\n status: g.status,\n detail: durableGateDetail(g.detail),\n })),\n },\n // Deferred holdout records the MODE, never a fabricated 0-lift: the\n // held-out comparison intentionally did not run in this loop.\n ...(holdoutMeasurement.kind === 'deferred'\n ? { holdout: 'deferred' as const }\n : {\n baselineHoldoutComposite: holdoutMeasurement.baseline,\n winnerHoldoutComposite: holdoutMeasurement.winner,\n heldOutLift: holdoutMeasurement.winner - holdoutMeasurement.baseline,\n }),\n backend: {\n verdict: integrity.verdict,\n workerCallCount: integrity.totalRecords,\n models,\n totalInputTokens: integrity.totalInputTokens,\n totalOutputTokens: integrity.totalOutputTokens,\n totalCostUsd: integrity.totalCostUsd,\n },\n totalCostUsd: args.totalCostUsd,\n totalDurationMs: args.totalDurationMs,\n }\n if (args.optimizationMethod) {\n recordWithoutDigest.optimizationMethod = durableOptimizationMethod(args.optimizationMethod)\n }\n if (args.winnerLabel) recordWithoutDigest.winnerLabel = args.winnerLabel\n if (args.winnerRationale) recordWithoutDigest.winnerRationale = args.winnerRationale\n return {\n ...recordWithoutDigest,\n recordDigest: canonicalDigest(recordWithoutDigest),\n }\n}\n\nfunction durableOptimizationMethod(\n value: LoopProvenanceOptimizationMethod,\n): LoopProvenanceOptimizationMethod {\n if (\n !value ||\n typeof value !== 'object' ||\n typeof value.name !== 'string' ||\n !value.name.trim() ||\n value.name.trim() !== value.name\n ) {\n throw new Error('buildLoopProvenanceRecord: optimization method name is invalid')\n }\n if (\n !value.cost ||\n !Number.isFinite(value.cost.totalCostUsd) ||\n value.cost.totalCostUsd < 0 ||\n typeof value.cost.accountingComplete !== 'boolean' ||\n !Array.isArray(value.cost.incompleteReasons) ||\n value.cost.incompleteReasons.some((reason) => typeof reason !== 'string' || !reason.trim()) ||\n value.cost.accountingComplete !== (value.cost.incompleteReasons.length === 0)\n ) {\n throw new Error('buildLoopProvenanceRecord: optimization method cost is invalid')\n }\n if (\n value.durationMs !== undefined &&\n (!Number.isFinite(value.durationMs) || value.durationMs < 0)\n ) {\n throw new Error('buildLoopProvenanceRecord: optimization method duration is invalid')\n }\n try {\n return JSON.parse(canonicalString(value)) as LoopProvenanceOptimizationMethod\n } catch (cause) {\n throw new Error('buildLoopProvenanceRecord: optimization method data must be canonical JSON', {\n cause,\n })\n }\n}\n\n/** Digest the exact campaign fields that can affect a measured comparison. */\nexport function campaignMeasurementDigest<TArtifact, TScenario extends Scenario>(\n campaign: CampaignResult<TArtifact, TScenario>,\n): `sha256:${string}` {\n assertCampaignSplitIdentity(campaign.scenarios, campaign.reps, campaign.splitDigest)\n return canonicalDigest({\n schema: 'tangle.campaign-measurement',\n manifestHash: campaign.manifestHash,\n splitDigest: campaign.splitDigest,\n seed: campaign.seed,\n reps: campaign.reps,\n runDir: campaign.runDir,\n scenarios: campaign.scenarios,\n cells: [...campaign.cells]\n .sort((left, right) => compareCodeUnits(left.cellId, right.cellId))\n .map((cell) => ({\n manifestHash: cell.manifestHash ?? null,\n cellId: cell.cellId,\n scenarioId: cell.scenarioId,\n rep: cell.rep,\n generation: cell.generation ?? null,\n judgeScores: cell.judgeScores,\n costUsd: cell.costUsd,\n costProvenance: cell.costProvenance,\n costCallIds: [...(cell.costCallIds ?? [])].sort(),\n tokenUsage: cell.tokenUsage,\n resolvedModels: [...(cell.resolvedModels ?? [])].sort(),\n resolvedModel: cell.resolvedModel ?? null,\n durationMs: cell.durationMs,\n seed: cell.seed,\n cached: cell.cached,\n errorStage: cell.errorStage ?? null,\n errorJudge: cell.errorJudge ?? null,\n error: cell.error ?? null,\n })),\n })\n}\n\n/** Recompute and validate the self-addressed durable record. */\nexport function verifyLoopProvenanceRecord(record: LoopProvenanceRecord): LoopProvenanceRecord {\n if (record.schema !== 'tangle.loop-provenance') {\n throw new Error('loop provenance has an unsupported schema')\n }\n const { recordDigest, ...recordWithoutDigest } = record\n if (recordDigest !== canonicalDigest(recordWithoutDigest)) {\n throw new Error('loop provenance record digest does not match its contents')\n }\n assertGateContributions(record.gate?.contributingGates, 'loop provenance')\n return record\n}\n\n/** SHA-256 over the RFC 8785 canonical JSON of `value`. Throws\n * `LedgerCanonicalizationError` for a value with no canonical form. */\nexport function canonicalDigest(value: unknown): `sha256:${string}` {\n return hashCanonical(value)\n}\n\nfunction durableGateDetail(detail: unknown): unknown {\n if (detail === undefined) return null\n try {\n return JSON.parse(canonicalString(detail)) as unknown\n } catch (cause) {\n throw new Error('buildLoopProvenanceRecord: gate detail must be canonical JSON', {\n cause,\n })\n }\n}\n\nfunction assertGateContributions(\n value: unknown,\n source: string,\n): asserts value is GateContribution[] {\n if (!Array.isArray(value)) {\n throw new Error(`${source}: gate contributingGates must be an array`)\n }\n const statuses = new Set(['pass', 'fail', 'not_evaluated'])\n for (const [index, contribution] of value.entries()) {\n if (!contribution || typeof contribution !== 'object') {\n throw new Error(`${source}: gate contribution ${index} must be an object`)\n }\n const item = contribution as Record<string, unknown>\n if (typeof item.name !== 'string' || item.name.length === 0) {\n throw new Error(`${source}: gate contribution ${index} must have a non-empty name`)\n }\n if (!statuses.has(String(item.status))) {\n throw new Error(\n `${source}: gate contribution '${item.name}' must have status pass, fail, or not_evaluated`,\n )\n }\n if ('passed' in item) {\n throw new Error(\n `${source}: gate contribution '${item.name}' uses obsolete passed; use status instead`,\n )\n }\n }\n}\n\n/** A candidate's coverage receipt and composite agree, and a promoted\n * candidate is complete and beats the incumbent it replaced. Its lineage is\n * the search ledger's to prove, not this record's. */\nfunction validateCandidateMeasurement(\n candidate: GenerationCandidate,\n incumbentComposite: number,\n promoted: boolean,\n): void {\n const coverage = candidate.coverage\n if (\n !Number.isSafeInteger(coverage.expectedCells) ||\n coverage.expectedCells <= 0 ||\n !Number.isSafeInteger(coverage.scorableCells) ||\n coverage.scorableCells < 0 ||\n coverage.scorableCells > coverage.expectedCells\n ) {\n throw new Error('buildLoopProvenanceRecord: invalid candidate coverage denominator')\n }\n const unscorableIds = new Set<string>()\n for (const failure of coverage.unscorableCells) {\n if (\n typeof failure.cellId !== 'string' ||\n failure.cellId.length === 0 ||\n typeof failure.reason !== 'string' ||\n failure.reason.length === 0 ||\n unscorableIds.has(failure.cellId)\n ) {\n throw new Error('buildLoopProvenanceRecord: invalid candidate coverage failures')\n }\n unscorableIds.add(failure.cellId)\n }\n if (coverage.expectedCells - coverage.scorableCells !== coverage.unscorableCells.length) {\n throw new Error(\n 'buildLoopProvenanceRecord: candidate coverage counts do not match its failures',\n )\n }\n const complete =\n coverage.scorableCells === coverage.expectedCells && coverage.unscorableCells.length === 0\n if (candidate.eligibleForPromotion !== complete) {\n throw new Error(\n 'buildLoopProvenanceRecord: candidate eligibility contradicts its coverage receipt',\n )\n }\n if (complete) {\n if (candidate.composite === null || !Number.isFinite(candidate.composite)) {\n throw new Error('buildLoopProvenanceRecord: complete candidate composite must be finite')\n }\n } else if (candidate.composite !== null && !Number.isFinite(candidate.composite)) {\n throw new Error('buildLoopProvenanceRecord: candidate composite must be finite or null')\n }\n if (\n promoted &&\n (!complete || (candidate.composite ?? Number.NEGATIVE_INFINITY) <= incumbentComposite)\n ) {\n throw new Error('buildLoopProvenanceRecord: promoted candidate must improve the incumbent')\n }\n}\n\n// ── OTel span emission ──────────────────────────────────────────────────\n\nfunction hashId(parts: string[]): string {\n return createHash('sha256').update(parts.join(':')).digest('hex')\n}\n\n/**\n * Build the loop's OTLP-ingestable spans from a provenance record. One root\n * span per loop (`tangle.runId`), one span per generation, one span per\n * candidate (carrying its surfaceHash + label), and one span for the gate\n * decision (carrying reasons + delta + lift). Candidate + gate spans pivot on\n * the same `tangle.runId` / `tangle.generation` attributes `/adapters/otel`\n * reads, so the hosted collector reconstructs the full tree.\n *\n * Times are synthesized monotonically off a single base so the span tree is\n * orderable; the substrate does not retain per-candidate wall-clock starts.\n */\nexport function loopProvenanceSpans(\n record: LoopProvenanceRecord,\n opts: { baseTimeMs?: number } = {},\n): TraceSpanEvent[] {\n const traceId = hashId(['trace', record.runId]).slice(0, 32)\n const baseTimeMs = opts.baseTimeMs ?? (Date.parse(record.timestamp) || Date.now())\n const durationMs = Math.max(1, record.totalDurationMs)\n if (!Number.isSafeInteger(baseTimeMs) || baseTimeMs < 0) {\n throw new RangeError('loop provenance baseTimeMs must be a non-negative safe integer')\n }\n if (!Number.isSafeInteger(durationMs)) {\n throw new RangeError('loop provenance duration must be a safe integer number of milliseconds')\n }\n const baseTime = BigInt(baseTimeMs)\n const baseNano = (baseTime * 1_000_000n).toString()\n const endNano = ((baseTime + BigInt(durationMs)) * 1_000_000n).toString()\n const spans: TraceSpanEvent[] = []\n\n const rootSpanId = hashId(['root', record.runId]).slice(0, 16)\n const rootAttributes: TraceSpanEvent['attributes'] = {\n 'tangle.runId': record.runId,\n 'tangle.runDir': record.runDir,\n 'tangle.baselineContentHash': record.baselineContentHash,\n 'tangle.winnerContentHash': record.winnerContentHash,\n 'tangle.baselineSearchComposite': record.baselineSearchComposite,\n 'tangle.gateDecision': record.gate.decision,\n 'tangle.backendVerdict': record.backend.verdict,\n 'tangle.workerCallCount': record.backend.workerCallCount,\n 'tangle.totalCostUsd': record.totalCostUsd,\n }\n if (record.heldOutLift !== undefined) rootAttributes['tangle.heldOutLift'] = record.heldOutLift\n if (record.holdout) rootAttributes['tangle.holdout'] = record.holdout\n spans.push({\n traceId,\n spanId: rootSpanId,\n name: 'improvement-loop',\n startTimeUnixNano: baseNano,\n endTimeUnixNano: endNano,\n attributes: rootAttributes,\n status: { code: 'OK' },\n 'tangle.runId': record.runId,\n })\n\n // Group candidates by generation for the per-generation parent span.\n const byGen = new Map<number, LoopProvenanceCandidate[]>()\n for (const c of record.candidates) {\n const arr = byGen.get(c.generation) ?? []\n arr.push(c)\n byGen.set(c.generation, arr)\n }\n for (const [generation, cands] of [...byGen.entries()].sort((a, b) => a[0] - b[0])) {\n const genSpanId = hashId(['gen', record.runId, String(generation)]).slice(0, 16)\n const measuredComposites = cands.flatMap((candidate) =>\n candidate.composite === null ? [] : [candidate.composite],\n )\n spans.push({\n traceId,\n spanId: genSpanId,\n parentSpanId: rootSpanId,\n name: `generation-${generation}`,\n startTimeUnixNano: baseNano,\n endTimeUnixNano: endNano,\n attributes: {\n 'tangle.runId': record.runId,\n 'tangle.generation': generation,\n 'tangle.populationSize': cands.length,\n ...(measuredComposites.length > 0\n ? { 'tangle.bestComposite': Math.max(...measuredComposites) }\n : {}),\n },\n 'tangle.runId': record.runId,\n 'tangle.generation': generation,\n })\n for (let i = 0; i < cands.length; i++) {\n const c = cands[i]!\n const candSpanId = hashId(['cand', record.runId, String(generation), c.surfaceHash]).slice(\n 0,\n 16,\n )\n const attributes: TraceSpanEvent['attributes'] = {\n 'tangle.runId': record.runId,\n 'tangle.generation': generation,\n 'tangle.surfaceHash': c.surfaceHash,\n 'tangle.contentHash': c.contentHash,\n 'tangle.eligibleForPromotion': c.eligibleForPromotion,\n 'tangle.expectedCells': c.coverage.expectedCells,\n 'tangle.scorableCells': c.coverage.scorableCells,\n 'tangle.unscorableCells': c.coverage.unscorableCells.length,\n 'tangle.promoted': c.promoted,\n }\n if (c.composite !== null) attributes['tangle.composite'] = c.composite\n if (c.label) attributes['tangle.candidateLabel'] = c.label\n if (c.rationale) attributes['tangle.candidateRationale'] = c.rationale\n spans.push({\n traceId,\n spanId: candSpanId,\n parentSpanId: genSpanId,\n name: `candidate-${c.surfaceHash}`,\n startTimeUnixNano: baseNano,\n endTimeUnixNano: endNano,\n attributes,\n 'tangle.runId': record.runId,\n 'tangle.generation': generation,\n })\n }\n }\n\n // Gate span — child of root, carries the decision/reasons/delta the audit\n // needs and pivots back to the run.\n const gateSpanId = hashId(['gate', record.runId]).slice(0, 16)\n const gateAttributes: TraceSpanEvent['attributes'] = {\n 'tangle.runId': record.runId,\n 'tangle.gateDecision': record.gate.decision,\n 'tangle.gateReasons': JSON.stringify(record.gate.reasons),\n }\n const gateDelta = record.gate.delta ?? record.heldOutLift\n if (gateDelta !== undefined) gateAttributes['tangle.gateDelta'] = gateDelta\n if (record.heldOutLift !== undefined) gateAttributes['tangle.heldOutLift'] = record.heldOutLift\n if (record.baselineHoldoutComposite !== undefined) {\n gateAttributes['tangle.baselineHoldoutComposite'] = record.baselineHoldoutComposite\n }\n if (record.winnerHoldoutComposite !== undefined) {\n gateAttributes['tangle.winnerHoldoutComposite'] = record.winnerHoldoutComposite\n }\n if (record.holdout) gateAttributes['tangle.holdout'] = record.holdout\n spans.push({\n traceId,\n spanId: gateSpanId,\n parentSpanId: rootSpanId,\n name: 'gate-decision',\n startTimeUnixNano: endNano,\n endTimeUnixNano: endNano,\n attributes: gateAttributes,\n status: { code: 'OK' },\n 'tangle.runId': record.runId,\n })\n\n return spans\n}\n\n// ── Durable emission ─────────────────────────────────────────────────────\n\n/** Canonical durable paths under the run dir. */\nexport function provenanceRecordPath(runDir: string): string {\n return join(runDir, 'loop-provenance.json')\n}\n/**\n * Canonical path for the durable OTLP spans JSONL file under a loop run directory.\n */\nexport function provenanceSpansPath(runDir: string): string {\n return join(runDir, 'loop-provenance-spans.jsonl')\n}\n\nexport interface EmitLoopProvenanceResult {\n record: LoopProvenanceRecord\n spans: TraceSpanEvent[]\n /** Absolute paths the record + spans were written to, when storage persists. */\n recordPath: string\n spansPath: string\n}\n\nexport interface EmitLoopProvenanceArgs<TArtifact, TScenario extends Scenario>\n extends BuildLoopProvenanceArgs<TArtifact, TScenario> {\n /** Storage the record + spans are written through. */\n storage: CampaignStorage\n /** When set, the spans are also shipped to the hosted `/v1/ingest/traces`\n * endpoint so the collector receives the full loop, not just `cost.*`. */\n hostedClient?: HostedClient\n}\n\n/**\n * Build the provenance record + OTel spans and persist them durably under the\n * run dir (and ship spans to a hosted collector when one is wired). Returns\n * both artifacts so the caller can assert on / re-derive from them.\n *\n * Fail-loud: the durable write throws on storage failure (a swallowed write is\n * exactly the \"emitted but lost\" failure this closes). The hosted span ship is\n * the one best-effort leg — its failure is logged, not thrown, so an offline\n * collector never fails the loop (the durable artifact is the source of truth).\n */\nexport async function emitLoopProvenance<TArtifact, TScenario extends Scenario>(\n args: EmitLoopProvenanceArgs<TArtifact, TScenario>,\n): Promise<EmitLoopProvenanceResult> {\n const record = buildLoopProvenanceRecord(args)\n const spans = loopProvenanceSpans(record)\n\n args.storage.ensureDir(args.runDir)\n const recordPath = provenanceRecordPath(args.runDir)\n const spansPath = provenanceSpansPath(args.runDir)\n args.storage.write(recordPath, JSON.stringify(record, null, 2))\n args.storage.write(spansPath, spans.map((s) => JSON.stringify(s)).join('\\n'))\n\n if (args.hostedClient) {\n // Best-effort: an offline collector is logged, never thrown; the durable\n // artifact above is the source of truth.\n try {\n await args.hostedClient.ingestTraces(spans)\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err)\n // eslint-disable-next-line no-console -- intentional: hosted span ship is best-effort\n console.warn(`[agent-eval] provenance span ingest failed (continuing): ${msg}`)\n }\n }\n\n return { record, spans, recordPath, spansPath }\n}\n","/**\n * Reproducibility attestation for any serializable report object.\n *\n * `attest()` binds a report to its content address (sha-256 over canonical\n * JSON) AND binds that address to the provenance needed to reproduce it:\n * model versions, seeds, price-table hash, code SHA, inputs hash. The outer\n * `envelopeHash` prevents provenance from being rewritten while leaving the\n * report hash valid.\n *\n * Layering: content-addressing is the substrate's job; cryptographic SIGNING\n * (who vouches for the attestation, key management, transparency logs) is the\n * consumer's layer on top. An `AttestedReport` is a stable byte-identical\n * payload a consumer can sign — the substrate never holds keys.\n *\n * Generic by design: the report parameter is ANY value `canonicalJson`\n * accepts (campaign results, fuzz capsules, scorecards, cost ledgers). Do not\n * couple this module to a specific report schema.\n */\n\nimport { contentHash } from './verdict-cache'\n\n/** Hash scheme identifier carried by every attestation. A verifier rejects\n * unknown algorithms instead of guessing. */\nexport const ATTESTATION_ALGORITHM = 'sha256/canonical-json' as const\n\nexport interface AttestationProvenance {\n /** Every model involved in producing the report, name → version/id. */\n modelVersions: Record<string, string>\n /** RNG seeds the run was driven by, when seeded. */\n seeds?: number[]\n /** Content hash of the price table used for cost figures — cost numbers\n * are only reproducible against the same prices. */\n priceTableHash?: string\n /** Git SHA of the code that produced the report. */\n codeSha: string\n /** Content hash of the input set (scenarios, dataset manifest, ...). */\n inputsHash?: string\n /** ISO-8601 timestamp, caller-supplied — the substrate stays clock-free\n * so attestation is deterministic and testable. */\n createdAt: string\n}\n\nexport interface AttestedReport {\n /** Hex sha-256 over the canonical JSON of the report. */\n reportHash: string\n provenance: AttestationProvenance\n algorithm: typeof ATTESTATION_ALGORITHM\n /** Hex sha-256 over `{ reportHash, provenance, algorithm }`. */\n envelopeHash: string\n}\n\nexport interface AttestationVerification {\n valid: boolean\n /** Populated iff `valid` is false — names the exact mismatch. */\n reason?: string\n}\n\nfunction envelopeMaterial(\n reportHash: string,\n provenance: AttestationProvenance,\n algorithm: typeof ATTESTATION_ALGORITHM,\n): object {\n return { reportHash, provenance, algorithm }\n}\n\n/**\n * Content-address a report and bind it to its provenance. Throws (via\n * `canonicalJson`) if the report or provenance contains undefined / function /\n * symbol / non-finite numbers — an attestation that cannot be unambiguously\n * serialized cannot be trusted.\n */\nexport function attest(report: unknown, provenance: AttestationProvenance): AttestedReport {\n const reportHash = contentHash(report)\n const algorithm = ATTESTATION_ALGORITHM\n return {\n reportHash,\n provenance,\n algorithm,\n envelopeHash: contentHash(envelopeMaterial(reportHash, provenance, algorithm)),\n }\n}\n\n/**\n * Verify a report against its attestation. Returns a typed outcome rather\n * than throwing: an unverifiable report (e.g. one that no longer\n * canonicalizes) is a verification failure with the cause in `reason`, not a\n * crash — verifiers run in pipelines that must record WHY, not die.\n *\n * Both the report hash and the provenance envelope must verify.\n * Missing envelope hashes cannot establish provenance and fail verification.\n */\nexport function verifyAttestation(\n report: unknown,\n attested: AttestedReport,\n): AttestationVerification {\n if (attested.algorithm !== ATTESTATION_ALGORITHM) {\n return {\n valid: false,\n reason: `unknown algorithm '${attested.algorithm}' — this verifier only checks '${ATTESTATION_ALGORITHM}'`,\n }\n }\n if (typeof attested.envelopeHash !== 'string' || !/^[0-9a-f]{64}$/.test(attested.envelopeHash)) {\n return { valid: false, reason: 'attestation envelope hash is missing or invalid' }\n }\n let recomputed: string\n try {\n recomputed = contentHash(report)\n } catch (err) {\n return {\n valid: false,\n reason: `report is not canonicalizable: ${err instanceof Error ? err.message : String(err)}`,\n }\n }\n if (recomputed !== attested.reportHash) {\n return {\n valid: false,\n reason: `report hash mismatch: attested ${attested.reportHash}, recomputed ${recomputed}`,\n }\n }\n\n let envelopeHash: string\n try {\n envelopeHash = contentHash(\n envelopeMaterial(attested.reportHash, attested.provenance, attested.algorithm),\n )\n } catch (err) {\n return {\n valid: false,\n reason: `attestation provenance is not canonicalizable: ${err instanceof Error ? err.message : String(err)}`,\n }\n }\n if (envelopeHash !== attested.envelopeHash) {\n return {\n valid: false,\n reason: `attestation envelope hash mismatch: attested ${attested.envelopeHash}, recomputed ${envelopeHash}`,\n }\n }\n\n return { valid: true }\n}\n","/**\n * Evidence receipts are the join between Runtime execution and Eval promotion.\n *\n * Runtime says what actually ran. Eval says what independently measured it.\n * This receipt binds those worlds without making either package import the other:\n * stable pursuit/run identity, exact candidate/evaluator/environment/input/output\n * content identities, and the authority class that produced the observation.\n *\n * The payload is attested with agent-eval's existing canonical report attestation.\n * Signing/key management deliberately remains outside this substrate; consumers may\n * sign the byte-stable receipt or anchor its attestation in a transparency log.\n */\n\nimport {\n type AttestationProvenance,\n type AttestedReport,\n attest,\n verifyAttestation,\n} from '../attestation'\n\nexport const EVIDENCE_RECEIPT_VERSION = '1.0.0' as const\n\n/** Closed promotion vocabulary. A typo or unknown future kind is never independent by default. */\nexport const EVIDENCE_AUTHORITY_KINDS = [\n 'candidate-self-report',\n 'independent-evaluator',\n 'independent-replication',\n 'human-review',\n 'production-canary',\n] as const\n\nexport type EvidenceAuthorityKind = (typeof EVIDENCE_AUTHORITY_KINDS)[number]\n\nexport const INDEPENDENT_EVIDENCE_AUTHORITY_KINDS = [\n 'independent-evaluator',\n 'independent-replication',\n 'human-review',\n 'production-canary',\n] as const satisfies readonly EvidenceAuthorityKind[]\n\nexport interface EvidenceAuthority {\n readonly kind: EvidenceAuthorityKind\n /** Stable authority/service/person identifier; never inferred from model prose. */\n readonly id: string\n}\n\nexport interface EvidenceBinding {\n readonly schemaVersion: typeof EVIDENCE_RECEIPT_VERSION\n /** Stable objective identity spanning retries, forks, resumes, and multiple runs. */\n readonly pursuitId: string\n /** Concrete execution/evaluation run this evidence was produced from. */\n readonly runId: string\n /** Exact candidate/program/profile bundle under evaluation. */\n readonly candidateDigest: string\n /** Exact evaluator/checker program or registered experiment definition. */\n readonly evaluatorDigest: string\n /** Exact sandbox/container/dependency/environment identity. */\n readonly environmentDigest: string\n /** Commitment to the input set. The hidden inputs themselves need not be exposed. */\n readonly inputSetCommitment: string\n /** Content identity of the raw evaluated output/artifact set. */\n readonly outputDigest: string\n /** Content identity of the evaluation result/report/verdict body. */\n readonly resultDigest: string\n readonly authority: EvidenceAuthority\n /** Optional experiment seal that governed the evaluation. */\n readonly experimentDigest?: string\n /** Optional observer-journal chain tip covering the execution being evaluated. */\n readonly observerDigest?: string\n}\n\nexport interface EvidenceReceipt {\n readonly binding: EvidenceBinding\n readonly attestation: AttestedReport\n}\n\nexport interface EvidenceReceiptVerification {\n readonly valid: boolean\n readonly reason?: string\n}\n\nexport interface CreateEvidenceReceiptInput extends Omit<EvidenceBinding, 'schemaVersion'> {}\n\n/**\n * Mint a content-attested evidence receipt. Required identity fields are deliberately\n * non-optional: unknown evidence stays unknown and cannot accidentally look certified.\n * The attestation's input provenance must equal the receipt commitment so two competing\n * descriptions of the evaluated population cannot coexist inside one valid receipt.\n */\nexport function createEvidenceReceipt(\n input: CreateEvidenceReceiptInput,\n provenance: AttestationProvenance,\n): EvidenceReceipt {\n const inputSetCommitment = requiredIdentity(input.inputSetCommitment, 'inputSetCommitment')\n assertInputCommitment(provenance, inputSetCommitment)\n const binding: EvidenceBinding = Object.freeze({\n schemaVersion: EVIDENCE_RECEIPT_VERSION,\n pursuitId: requiredIdentity(input.pursuitId, 'pursuitId'),\n runId: requiredIdentity(input.runId, 'runId'),\n candidateDigest: requiredIdentity(input.candidateDigest, 'candidateDigest'),\n evaluatorDigest: requiredIdentity(input.evaluatorDigest, 'evaluatorDigest'),\n environmentDigest: requiredIdentity(input.environmentDigest, 'environmentDigest'),\n inputSetCommitment,\n outputDigest: requiredIdentity(input.outputDigest, 'outputDigest'),\n resultDigest: requiredIdentity(input.resultDigest, 'resultDigest'),\n authority: requiredAuthority(input.authority),\n ...(input.experimentDigest === undefined\n ? {}\n : { experimentDigest: requiredIdentity(input.experimentDigest, 'experimentDigest') }),\n ...(input.observerDigest === undefined\n ? {}\n : { observerDigest: requiredIdentity(input.observerDigest, 'observerDigest') }),\n })\n return Object.freeze({ binding, attestation: attest(binding, provenance) })\n}\n\n/**\n * Verify evidence identity and its provenance envelope. Changing the evaluator,\n * model versions, input commitment, or creation record invalidates the evidence.\n */\nexport function verifyEvidenceReceipt(receipt: EvidenceReceipt): EvidenceReceiptVerification {\n if (receipt.binding.schemaVersion !== EVIDENCE_RECEIPT_VERSION) {\n return {\n valid: false,\n reason: `unsupported evidence receipt version '${receipt.binding.schemaVersion}'`,\n }\n }\n try {\n for (const [field, value] of Object.entries({\n pursuitId: receipt.binding.pursuitId,\n runId: receipt.binding.runId,\n candidateDigest: receipt.binding.candidateDigest,\n evaluatorDigest: receipt.binding.evaluatorDigest,\n environmentDigest: receipt.binding.environmentDigest,\n inputSetCommitment: receipt.binding.inputSetCommitment,\n outputDigest: receipt.binding.outputDigest,\n resultDigest: receipt.binding.resultDigest,\n })) {\n requiredIdentity(value, field)\n }\n requiredAuthority(receipt.binding.authority)\n assertInputCommitment(receipt.attestation.provenance, receipt.binding.inputSetCommitment)\n } catch (error) {\n return { valid: false, reason: error instanceof Error ? error.message : String(error) }\n }\n\n return verifyAttestation(receipt.binding, receipt.attestation)\n}\n\n/**\n * Promotion may choose a stricter policy, but this primitive makes the basic separation\n * explicit: only a recognized independent authority is independent. Unknown/forged kinds\n * and candidate self-reports both return false.\n */\nexport function isIndependentEvidence(receipt: EvidenceReceipt): boolean {\n return (INDEPENDENT_EVIDENCE_AUTHORITY_KINDS as readonly string[]).includes(\n receipt.binding.authority?.kind,\n )\n}\n\nfunction requiredAuthority(value: unknown): EvidenceAuthority {\n if (typeof value !== 'object' || value === null || Array.isArray(value)) {\n throw new TypeError('evidence receipt: authority must be an object')\n }\n const authority = value as { kind?: unknown; id?: unknown }\n if (\n typeof authority.kind !== 'string' ||\n !(EVIDENCE_AUTHORITY_KINDS as readonly string[]).includes(authority.kind)\n ) {\n throw new TypeError(`evidence receipt: unknown authority kind '${String(authority.kind)}'`)\n }\n if (typeof authority.id !== 'string') {\n throw new TypeError('evidence receipt: authority.id must be a string')\n }\n return Object.freeze({\n kind: authority.kind as EvidenceAuthorityKind,\n id: requiredIdentity(authority.id, 'authority.id'),\n })\n}\n\nfunction assertInputCommitment(\n provenance: AttestationProvenance,\n inputSetCommitment: string,\n): void {\n if (typeof provenance?.inputsHash !== 'string' || provenance.inputsHash.trim().length === 0) {\n throw new TypeError('evidence receipt: provenance.inputsHash is required')\n }\n if (provenance.inputsHash.trim() !== inputSetCommitment) {\n throw new TypeError(\n 'evidence receipt: provenance.inputsHash must equal binding.inputSetCommitment',\n )\n }\n}\n\nfunction requiredIdentity(value: string, field: string): string {\n const normalized = value.trim()\n if (normalized.length === 0) throw new TypeError(`evidence receipt: ${field} must be non-empty`)\n return normalized\n}\n","import type { AttestationProvenance } from '../attestation'\nimport { assertCampaignSplitIdentity, campaignCoverage } from '../campaign/coverage'\nimport { campaignMeasurementDigest } from '../campaign/provenance'\nimport { surfaceContentHash } from '../campaign/surface-identity'\nimport type { CampaignResult, MutableSurface, Scenario } from '../campaign/types'\nimport { hashCanonical } from '../ledger-core/canonical'\nimport { type CreateEvidenceReceiptInput, createEvidenceReceipt } from './evidence-receipt'\n\n/** Caller-owned execution context. Eval never infers evaluator authority or environment identity. */\nexport type CampaignEvidenceContext = Pick<\n CreateEvidenceReceiptInput,\n | 'pursuitId'\n | 'evaluatorDigest'\n | 'environmentDigest'\n | 'authority'\n | 'experimentDigest'\n | 'observerDigest'\n> & { provenance: Omit<AttestationProvenance, 'inputsHash'> }\n\n/** Bind a complete measured campaign to its executed surface and actual outputs. */\nexport function createCampaignEvidenceReceipt<S extends Scenario, A>(input: {\n campaign: CampaignResult<A, S>\n surface: MutableSurface\n context: CampaignEvidenceContext\n}) {\n const { campaign, surface, context } = input\n assertCampaignSplitIdentity(campaign.scenarios, campaign.reps, campaign.splitDigest)\n const coverage = campaignCoverage(campaign.cells, campaign.scenarios, campaign.reps, true)\n if (campaign.scenarios.length === 0 || !coverage.complete) {\n throw new Error('campaign evidence requires a complete, nonempty measurement')\n }\n const { provenance, ...binding } = context\n return createEvidenceReceipt(\n {\n ...binding,\n runId: campaign.runDir,\n candidateDigest: surfaceContentHash(surface),\n inputSetCommitment: campaign.splitDigest,\n outputDigest: hashCanonical(\n [...campaign.cells]\n .sort((a, b) => (a.cellId < b.cellId ? -1 : a.cellId > b.cellId ? 1 : 0))\n .map((cell) => ({ cellId: cell.cellId, artifact: cell.artifact })),\n ),\n resultDigest: campaignMeasurementDigest(campaign),\n },\n { ...provenance, inputsHash: campaign.splitDigest },\n )\n}\n"],"mappings":";;;;;;;;;;;;AAgBA,SAAgB,qBACd,WACA,MACM;CACN,IAAI,CAAC,OAAO,cAAc,IAAI,KAAK,OAAO,GACxC,MAAM,IAAI,MAAM,6DAA6D;CAE/E,MAAM,8BAAc,IAAI,IAAY;CACpC,KAAK,MAAM,YAAY,WAAW;EAChC,IAAI,OAAO,SAAS,OAAO,YAAY,SAAS,GAAG,KAAK,CAAC,CAAC,WAAW,GACnE,MAAM,IAAI,MAAM,gEAAgE;EAElF,IAAI,YAAY,IAAI,SAAS,EAAE,GAC7B,MAAM,IAAI,MAAM,mDAAmD,SAAS,GAAG,EAAE;EAEnF,IAAI,OAAO,SAAS,SAAS,YAAY,SAAS,KAAK,KAAK,CAAC,CAAC,WAAW,GACvE,MAAM,IAAI,MAAM,kEAAkE;EAEpF,IACE,SAAS,cAAc,KAAA,MACtB,OAAO,SAAS,cAAc,YAAY,SAAS,UAAU,KAAK,CAAC,CAAC,WAAW,IAEhF,MAAM,IAAI,MAAM,sEAAsE;EAExF,YAAY,IAAI,SAAS,EAAE;CAC7B;AACF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AI,cAAc;CACnD,CAAC;AACH;AAEA,SAAS,sBACP,YACA,oBACM;CACN,IAAI,OAAO,YAAY,eAAe,YAAY,WAAW,WAAW,KAAK,CAAC,CAAC,WAAW,GACxF,MAAM,IAAI,UAAU,qDAAqD;CAE3E,IAAI,WAAW,WAAW,KAAK,MAAM,oBACnC,MAAM,IAAI,UACR,+EACF;AAEJ;AAEA,SAAS,iBAAiB,OAAe,OAAuB;CAC9D,MAAM,aAAa,MAAM,KAAK;CAC9B,IAAI,WAAW,WAAW,GAAG,MAAM,IAAI,UAAU,qBAAqB,MAAM,mBAAmB;CAC/F,OAAO;AACT;;;;AClLA,SAAgB,8BAAqD,OAIlE;CACD,MAAM,EAAE,UAAU,SAAS,YAAY;CACvC,4BAA4B,SAAS,WAAW,SAAS,MAAM,SAAS,WAAW;CACnF,MAAM,WAAW,iBAAiB,SAAS,OAAO,SAAS,WAAW,SAAS,MAAM,IAAI;CACzF,IAAI,SAAS,UAAU,WAAW,KAAK,CAAC,SAAS,UAC/C,MAAM,IAAI,MAAM,6DAA6D;CAE/E,MAAM,EAAE,YAAY,GAAG,YAAY;CACnC,OAAO,sBACL;EACE,GAAG;EACH,OAAO,SAAS;EAChB,iBAAiB,mBAAmB,OAAO;EAC3C,oBAAoB,SAAS;EAC7B,cAAc,cACZ,CAAC,GAAG,SAAS,KAAK,CAAC,CAChB,MAAM,GAAG,MAAO,EAAE,SAAS,EAAE,SAAS,KAAK,EAAE,SAAS,EAAE,SAAS,IAAI,CAAE,CAAC,CACxE,KAAK,UAAU;GAAE,QAAQ,KAAK;GAAQ,UAAU,KAAK;EAAS,EAAE,CACrE;EACA,cAAc,0BAA0B,QAAQ;CAClD,GACA;EAAE,GAAG;EAAY,YAAY,SAAS;CAAY,CACpD;AACF"}
@@ -1,25 +1,25 @@
1
1
  import { s as ValidationError, t as AgentEvalError } from "./errors-Dngq5h35.js";
2
2
  import { a as hashCanonical, i as compareCodeUnits, r as canonicalString } from "./canonical-BsZVgBhW.js";
3
- import { c as agentProfileId, d as harnessAxisOf, i as verifyCompletion, l as agentProfileModelId, s as agentProfileHash, t as extractProducedState } from "./produced-state-Bzlh09oj.js";
4
- import { s as buildAgentProfileCell } from "./agent-profile-cell-DcFW4vOc.js";
3
+ import { c as agentProfileId, d as harnessAxisOf, i as verifyCompletion, l as agentProfileModelId, s as agentProfileHash, t as extractProducedState } from "./produced-state-CKybuR9F.js";
4
+ import { o as buildAgentProfileCell } from "./agent-profile-cell-BYc0bxsL.js";
5
5
  import { r as pairedBootstrap } from "./paired-tests-jbwPdSz5.js";
6
- import { t as comparePairedArms } from "./paired-arms-CgWT7sHy.js";
7
- import { o as pairHoldout } from "./statistical-heldout-BP6iEJvR.js";
8
- import { c as runTaskScore, i as modelHasSnapshot, n as UNKNOWN_MODEL, u as validateRunRecord } from "./run-record-BRlM99rX.js";
6
+ import { t as comparePairedArms } from "./paired-arms-DzKn0TfY.js";
7
+ import { o as pairHoldout } from "./statistical-heldout-1Gbmex7v.js";
8
+ import { c as validateRunRecord, i as modelHasSnapshot, n as UNKNOWN_MODEL, o as runTaskScore } from "./run-record-DlTZ_lqe.js";
9
9
  import { n as contentHash, t as canonicalJson } from "./verdict-cache-BQEsVy9n.js";
10
- import { at as resolveRunDir, d as combineComparisonCosts, it as planCampaignRun, lt as cellCachePath, rt as runCampaign, u as executeOptimizationMethod, ut as computeManifestHash, v as labelTrustRank } from "./llm-judge-HLWASwUJ.js";
11
- import { n as campaignCellToRunRecord, r as projectCampaignCellQuality, t as campaignCellCostProvenance } from "./run-record-BB290Y9A.js";
10
+ import { at as resolveRunDir, d as combineComparisonCosts, it as planCampaignRun, lt as cellCachePath, rt as runCampaign, u as executeOptimizationMethod, ut as computeManifestHash, v as labelTrustRank } from "./llm-judge-Tr7MBUnf.js";
11
+ import { n as campaignCellToRunRecord, r as projectCampaignCellQuality, t as campaignCellCostProvenance } from "./run-record-ES07wfz9.js";
12
12
  import { t as CostAccountingIncompleteError } from "./cost-ledger-_IbkejCF.js";
13
- import { B as assertRealBackend, F as surfaceContentHash, H as assertCampaignDesign, K as campaignScenarioIdentity, V as summarizeBackendIntegrity, j as assertCodeSurfaceIdentity } from "./campaign-evidence-DW3Krxov.js";
13
+ import { B as assertCampaignDesign, N as surfaceContentHash, R as assertRealBackend, W as campaignScenarioIdentity, k as assertCodeSurfaceIdentity, z as summarizeBackendIntegrity } from "./campaign-evidence-OcUciD-N.js";
14
14
  import { m as mapConcurrent } from "./journal-DvKCvjty.js";
15
15
  import { S as fsCampaignStorage } from "./external-optimizer-subprocess-C0EsxEbI.js";
16
- import "./search-kernel-CIie6xig.js";
17
- import "./search-ledger-CXQPwdWz.js";
18
- import "./search-summary-BV5uehLd.js";
16
+ import "./search-kernel-BIXWM7YV.js";
17
+ import "./search-ledger-aMTNQn_m.js";
18
+ import "./search-summary-nwrtXxC_.js";
19
19
  import { a as scoreAnalystFindings } from "./benchmark-BywPeAUo.js";
20
20
  import "./external-optimizer-process-D2Txd-7D.js";
21
- import "./skillopt-optimization-method-Dcnh5Pvr.js";
22
- import "./sequential-DMqr3sni.js";
21
+ import "./skillopt-optimization-method-DujPOiwD.js";
22
+ import "./sequential-D-1PPCmM.js";
23
23
  import { createHash } from "node:crypto";
24
24
  import { closeSync, constants, existsSync, fstatSync, lstatSync, mkdirSync, mkdtempSync, openSync, readFileSync, readSync, readdirSync, readlinkSync, realpathSync, rmSync, statSync, writeFileSync } from "node:fs";
25
25
  import { z } from "zod";
@@ -3436,4 +3436,4 @@ function resolveWorktreePath(surface, worktreeDir) {
3436
3436
  //#endregion
3437
3437
  export { loadEvalFixtureScenarios as A, FsLabeledScenarioStore as C, neutralizationGate as D, rolloutArgumentDiff as E, analyzeCrossSurfaceInteractions as M, buildTraceAnalystSurfaceDispatch as N, discoverEvalFixtures as O, traceAnalystQualityJudge as P, neutralizeText as S, classifyUngroundedLiterals as T, scoreUserStory as _, autoevalsScorerJudge as a, scopedOptimizationMethod as b, selectDiscriminative as c, finalizeProfileMatrix as d, runProfileMatrixSegment as f, renderScoreboardMarkdown as g, makePlaybackDispatch as h, verifyCodeSurface as i, planEvalFixtureRun as j, loadEvalFixture as k, createRetainedDispatch as l, runProfileMatrix as m, gitWorktreeAdapter as n, phoenixEvaluatorJudge as o, ProfileMatrixError as p, resolveWorktreePath as r, scoreDiscrimination as s, WorktreeAdapterError as t, createProfileMatrixPlan as u, scoreboardSummary as v, LabeledScenarioStoreError as w, sequentialOptimizationMethod as x, userStoryScoreboard as y };
3438
3438
 
3439
- //# sourceMappingURL=campaign-C5pjR-Qn.js.map
3439
+ //# sourceMappingURL=campaign-wvvJA1ps.js.map