@tangle-network/agent-eval 0.215.1 → 0.216.1

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 (400) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/dist/adapters/http.d.ts +3 -3
  3. package/dist/{agent-profile-DmzL8KaJ.d.ts → agent-profile-VFcQncbW.d.ts} +5 -5
  4. package/dist/{agent-profile-DmzL8KaJ.d.ts.map → agent-profile-VFcQncbW.d.ts.map} +1 -1
  5. package/dist/{agent-profile-cell-BYc0bxsL.js → agent-profile-cell-BK8mlqlq.js} +3 -3
  6. package/dist/{agent-profile-cell-BYc0bxsL.js.map → agent-profile-cell-BK8mlqlq.js.map} +1 -1
  7. package/dist/agreement-irr-BEWLIF3_.js +186 -0
  8. package/dist/agreement-irr-BEWLIF3_.js.map +1 -0
  9. package/dist/analyst/index.d.ts +487 -14
  10. package/dist/analyst/index.d.ts.map +1 -1
  11. package/dist/analyst/index.js +1547 -12
  12. package/dist/analyst/index.js.map +1 -1
  13. package/dist/{analyze-runs-3xpby3p2.js → analyze-runs-C84irm4i.js} +608 -604
  14. package/dist/analyze-runs-C84irm4i.js.map +1 -0
  15. package/dist/{analyze-runs-BhFLOztS.d.ts → analyze-runs-D68fd-su.d.ts} +17 -15
  16. package/dist/analyze-runs-D68fd-su.d.ts.map +1 -0
  17. package/dist/{baseline-Dm8966du.js → baseline-Udi_PLuT.js} +5 -5
  18. package/dist/{baseline-Dm8966du.js.map → baseline-Udi_PLuT.js.map} +1 -1
  19. package/dist/{benchmark-BywPeAUo.js → benchmark-CXmVVHH2.js} +2 -2
  20. package/dist/{benchmark-BywPeAUo.js.map → benchmark-CXmVVHH2.js.map} +1 -1
  21. package/dist/{benchmark-command-CgpGi7vY.js → benchmark-command-By0vh8q7.js} +71 -70
  22. package/dist/benchmark-command-By0vh8q7.js.map +1 -0
  23. package/dist/benchmarks/index.d.ts +5 -5
  24. package/dist/benchmarks/index.js +3 -3
  25. package/dist/builder-eval/index.js +2 -2
  26. package/dist/campaign/index.d.ts +7 -7
  27. package/dist/campaign/index.js +14 -14
  28. package/dist/{campaign-CpnsCgfz.js → campaign-BudZ70zo.js} +245 -247
  29. package/dist/campaign-BudZ70zo.js.map +1 -0
  30. package/dist/{campaign-evidence-OcUciD-N.js → campaign-evidence-Clrn4hBV.js} +8 -8
  31. package/dist/campaign-evidence-Clrn4hBV.js.map +1 -0
  32. package/dist/{canonical-BsZVgBhW.js → canonical-B2RqLofv.js} +2 -2
  33. package/dist/{canonical-BsZVgBhW.js.map → canonical-B2RqLofv.js.map} +1 -1
  34. package/dist/{chat-client-DthPOYGd.js → chat-client-l-MVDlDk.js} +2 -2
  35. package/dist/{chat-client-DthPOYGd.js.map → chat-client-l-MVDlDk.js.map} +1 -1
  36. package/dist/{chat-json-call-BrKsyspg.js → chat-json-call-puMArmtW.js} +2 -2
  37. package/dist/{chat-json-call-BrKsyspg.js.map → chat-json-call-puMArmtW.js.map} +1 -1
  38. package/dist/{claim-BXcZw-jo.js → claim-q4HQhK1G.js} +4 -4
  39. package/dist/claim-q4HQhK1G.js.map +1 -0
  40. package/dist/cli.js +9 -9
  41. package/dist/cli.js.map +1 -1
  42. package/dist/cluster-bootstrap-qcUWYFl-.js +66 -0
  43. package/dist/cluster-bootstrap-qcUWYFl-.js.map +1 -0
  44. package/dist/contract/index.d.ts +11 -11
  45. package/dist/contract/index.js +1023 -1079
  46. package/dist/contract/index.js.map +1 -1
  47. package/dist/{cost-ledger-D2FnJPBF.js → cost-ledger-BP8V4kUQ.js} +835 -816
  48. package/dist/cost-ledger-BP8V4kUQ.js.map +1 -0
  49. package/dist/{cost-ledger-CO7UyEcQ.d.ts → cost-ledger-Jk62OBfF.d.ts} +12 -47
  50. package/dist/cost-ledger-Jk62OBfF.d.ts.map +1 -0
  51. package/dist/{counterfactual-DtMWvn7D.js → counterfactual-Dn3veueY.js} +2 -2
  52. package/dist/{counterfactual-DtMWvn7D.js.map → counterfactual-Dn3veueY.js.map} +1 -1
  53. package/dist/{default-registry-KP4-Tolz.js → default-registry-COhk9g36.js} +744 -759
  54. package/dist/default-registry-COhk9g36.js.map +1 -0
  55. package/dist/{default-registry-B4B7GMvI.d.ts → default-registry-DzHiGruW.d.ts} +6 -6
  56. package/dist/{default-registry-B4B7GMvI.d.ts.map → default-registry-DzHiGruW.d.ts.map} +1 -1
  57. package/dist/{define-agent-eval-BdfnqXeP.js → define-agent-eval-CNTPzIkp.js} +10 -10
  58. package/dist/define-agent-eval-CNTPzIkp.js.map +1 -0
  59. package/dist/{define-agent-eval-DfXvNho5.d.ts → define-agent-eval-WSck0CZJ.d.ts} +8 -8
  60. package/dist/{define-agent-eval-DfXvNho5.d.ts.map → define-agent-eval-WSck0CZJ.d.ts.map} +1 -1
  61. package/dist/{descriptive-CnU8Yq29.js → descriptive-DboxPZrG.js} +2 -2
  62. package/dist/{descriptive-CnU8Yq29.js.map → descriptive-DboxPZrG.js.map} +1 -1
  63. package/dist/diagnosis/index.d.ts +3 -3
  64. package/dist/diagnosis/index.js +4 -4
  65. package/dist/{dspy-rlm-engine-DZfHM7kT.js → dspy-rlm-engine-LRCu61m5.js} +3 -3
  66. package/dist/{dspy-rlm-engine-DZfHM7kT.js.map → dspy-rlm-engine-LRCu61m5.js.map} +1 -1
  67. package/dist/{effect-sizes-DiH8MGOH.js → effect-sizes-BhzEpXMc.js} +2 -2
  68. package/dist/{effect-sizes-DiH8MGOH.js.map → effect-sizes-BhzEpXMc.js.map} +1 -1
  69. package/dist/{engine-C37HS2kr.d.ts → engine-3A_4jOlI.d.ts} +5 -5
  70. package/dist/{engine-C37HS2kr.d.ts.map → engine-3A_4jOlI.d.ts.map} +1 -1
  71. package/dist/{equal-terms-Blx9Zk5I.js → equal-terms-BtdXayCJ.js} +2 -2
  72. package/dist/{equal-terms-Blx9Zk5I.js.map → equal-terms-BtdXayCJ.js.map} +1 -1
  73. package/dist/{errors-Dngq5h35.js → errors-DVZiqS7K.js} +6 -2
  74. package/dist/{errors-Dngq5h35.js.map → errors-DVZiqS7K.js.map} +1 -1
  75. package/dist/{eval-campaign-4byTtqrf.js → eval-campaign-90jeaCAI.js} +6 -6
  76. package/dist/{eval-campaign-4byTtqrf.js.map → eval-campaign-90jeaCAI.js.map} +1 -1
  77. package/dist/evaluation-6Yoi74gM.d.ts +75 -0
  78. package/dist/evaluation-6Yoi74gM.d.ts.map +1 -0
  79. package/dist/evaluation.d.ts +2 -74
  80. package/dist/evaluation.js +1 -1
  81. package/dist/{exact-types-Dlb73wN4.d.ts → exact-types-ClugMJfI.d.ts} +2 -2
  82. package/dist/{exact-types-Dlb73wN4.d.ts.map → exact-types-ClugMJfI.d.ts.map} +1 -1
  83. package/dist/experiment/index.d.ts +404 -3
  84. package/dist/experiment/index.d.ts.map +1 -1
  85. package/dist/experiment/index.js +313 -19
  86. package/dist/experiment/index.js.map +1 -1
  87. package/dist/{external-optimizer-process-GngofQML.js → external-optimizer-process-BjMGUuds.js} +3 -3
  88. package/dist/{external-optimizer-process-GngofQML.js.map → external-optimizer-process-BjMGUuds.js.map} +1 -1
  89. package/dist/{external-optimizer-subprocess-BUxifb8g.js → external-optimizer-subprocess-BqW0hHcI.js} +791 -532
  90. package/dist/external-optimizer-subprocess-BqW0hHcI.js.map +1 -0
  91. package/dist/{feedback-trajectory-BLN_6fEs.d.ts → feedback-trajectory-C4EG0nNH.d.ts} +5 -8
  92. package/dist/feedback-trajectory-C4EG0nNH.d.ts.map +1 -0
  93. package/dist/fuzz.d.ts +1 -1
  94. package/dist/fuzz.js +3 -3
  95. package/dist/hosted/index.js +1 -1
  96. package/dist/{index-CPJJr98o.d.ts → index-BFRO6chs.d.ts} +3 -2
  97. package/dist/index-BFRO6chs.d.ts.map +1 -0
  98. package/dist/{index-Ch9VxCpK.d.ts → index-BO41eGj5.d.ts} +2 -2
  99. package/dist/{index-Ch9VxCpK.d.ts.map → index-BO41eGj5.d.ts.map} +1 -1
  100. package/dist/{index-B3WBm953.d.ts → index-CyszSg4O.d.ts} +165 -162
  101. package/dist/index-CyszSg4O.d.ts.map +1 -0
  102. package/dist/{index-B7m2uzJL.d.ts → index-DPcngtwt.d.ts} +30 -17
  103. package/dist/index-DPcngtwt.d.ts.map +1 -0
  104. package/dist/{index-tYLUvk_w.d.ts → index-DV-jSzxF.d.ts} +9 -9
  105. package/dist/{index-tYLUvk_w.d.ts.map → index-DV-jSzxF.d.ts.map} +1 -1
  106. package/dist/index.d.ts +1969 -1871
  107. package/dist/index.d.ts.map +1 -1
  108. package/dist/index.js +162 -201
  109. package/dist/index.js.map +1 -1
  110. package/dist/{integrity-BvnVARVl.js → integrity-BXOsAb3i.js} +2 -2
  111. package/dist/{integrity-BvnVARVl.js.map → integrity-BXOsAb3i.js.map} +1 -1
  112. package/dist/{integrity-CCAxGVK6.d.ts → integrity-DAMEDFaC.d.ts} +2 -2
  113. package/dist/{integrity-CCAxGVK6.d.ts.map → integrity-DAMEDFaC.d.ts.map} +1 -1
  114. package/dist/{integrity-BV1ZDf42.js → integrity-dLiDe2kD.js} +2 -5
  115. package/dist/integrity-dLiDe2kD.js.map +1 -0
  116. package/dist/{internal-CRHwS9iz.js → internal-Epl-YBZW.js} +3 -3
  117. package/dist/{internal-CRHwS9iz.js.map → internal-Epl-YBZW.js.map} +1 -1
  118. package/dist/interval-CELpye1n.js +219 -0
  119. package/dist/interval-CELpye1n.js.map +1 -0
  120. package/dist/interval-ohuOJurX.d.ts +47 -0
  121. package/dist/interval-ohuOJurX.d.ts.map +1 -0
  122. package/dist/{journal-DvKCvjty.js → journal-DfRz9kps.js} +2 -2
  123. package/dist/{journal-DvKCvjty.js.map → journal-DfRz9kps.js.map} +1 -1
  124. package/dist/{judge-calibration-N44V04Se.js → judge-calibration-BpCy5XQl.js} +3 -3
  125. package/dist/{judge-calibration-N44V04Se.js.map → judge-calibration-BpCy5XQl.js.map} +1 -1
  126. package/dist/{judge-gate-DNcUrRFA.d.ts → judge-gate-CE7CQAgt.d.ts} +3 -3
  127. package/dist/{judge-gate-DNcUrRFA.d.ts.map → judge-gate-CE7CQAgt.d.ts.map} +1 -1
  128. package/dist/{judge-gate-B1qYnkpi.js → judge-gate-iY9s4L44.js} +3 -3
  129. package/dist/judge-gate-iY9s4L44.js.map +1 -0
  130. package/dist/{kind-factory-AaEhUADH.js → kind-factory-BobI5Jy3.js} +5 -5
  131. package/dist/{kind-factory-AaEhUADH.js.map → kind-factory-BobI5Jy3.js.map} +1 -1
  132. package/dist/ledger-core/index.js +3 -3
  133. package/dist/{ledger-core-B2hahzrt.js → ledger-core-Gq7yp8lP.js} +4 -4
  134. package/dist/{ledger-core-B2hahzrt.js.map → ledger-core-Gq7yp8lP.js.map} +1 -1
  135. package/dist/{llm-client-DQveoxSM.js → llm-client-CyBAoYiX.js} +192 -219
  136. package/dist/llm-client-CyBAoYiX.js.map +1 -0
  137. package/dist/{llm-judge-Cd5s5Ei6.js → llm-judge-CG12SQJq.js} +499 -921
  138. package/dist/llm-judge-CG12SQJq.js.map +1 -0
  139. package/dist/matrix/index.d.ts +2 -2
  140. package/dist/matrix/index.js +1 -1
  141. package/dist/{matrix-DXVAJMLD.d.ts → matrix-DSrSxjjy.d.ts} +4 -4
  142. package/dist/{matrix-DXVAJMLD.d.ts.map → matrix-DSrSxjjy.d.ts.map} +1 -1
  143. package/dist/{matrix-_BV9-Lk5.js → matrix-Dm0BQW7U.js} +7 -11
  144. package/dist/matrix-Dm0BQW7U.js.map +1 -0
  145. package/dist/{paired-tests-jbwPdSz5.js → mean-DHoMiudD.js} +11 -5
  146. package/dist/mean-DHoMiudD.js.map +1 -0
  147. package/dist/meta-eval/index.d.ts +3 -3
  148. package/dist/meta-eval/index.js +9 -70
  149. package/dist/meta-eval/index.js.map +1 -1
  150. package/dist/mint-DNU8QPG4.d.ts +81 -0
  151. package/dist/mint-DNU8QPG4.d.ts.map +1 -0
  152. package/dist/{mint-Csor1BLJ.js → mint-QaD5cA0u.js} +3 -3
  153. package/dist/{mint-Csor1BLJ.js.map → mint-QaD5cA0u.js.map} +1 -1
  154. package/dist/{multiplicity-D9cjmStq.js → multiplicity-DQUFcbW4.js} +2 -2
  155. package/dist/{multiplicity-D9cjmStq.js.map → multiplicity-DQUFcbW4.js.map} +1 -1
  156. package/dist/multishot/golden/index.d.ts +1 -1
  157. package/dist/multishot/golden/index.d.ts.map +1 -1
  158. package/dist/multishot/golden/index.js +3 -6
  159. package/dist/multishot/golden/index.js.map +1 -1
  160. package/dist/multishot/index.d.ts +2 -2
  161. package/dist/multishot/index.js +1 -1
  162. package/dist/nonnegative-number-DvdMxg_f.js +9 -0
  163. package/dist/nonnegative-number-DvdMxg_f.js.map +1 -0
  164. package/dist/openapi.json +1 -1
  165. package/dist/{otel-spans-C8YIJWy1.js → otel-spans-B9tUXRHF.js} +3 -3
  166. package/dist/{otel-spans-C8YIJWy1.js.map → otel-spans-B9tUXRHF.js.map} +1 -1
  167. package/dist/{paired-arms-DzKn0TfY.js → paired-arms-CwMGJsrS.js} +5 -5
  168. package/dist/{paired-arms-DzKn0TfY.js.map → paired-arms-CwMGJsrS.js.map} +1 -1
  169. package/dist/{paired-binary-Q36bhn2R.js → paired-binary-CvpFHfKZ.js} +2 -2
  170. package/dist/{paired-binary-Q36bhn2R.js.map → paired-binary-CvpFHfKZ.js.map} +1 -1
  171. package/dist/{paired-promotion-decision-BN6IQTiu.js → paired-promotion-decision-DsAPYGCm.js} +3 -3
  172. package/dist/{paired-promotion-decision-BN6IQTiu.js.map → paired-promotion-decision-DsAPYGCm.js.map} +1 -1
  173. package/dist/{search-kernel-BztlERLv.js → pareto-Cm6ndrWN.js} +883 -861
  174. package/dist/pareto-Cm6ndrWN.js.map +1 -0
  175. package/dist/pipelines/index.d.ts +2 -2
  176. package/dist/pipelines/index.js +3 -3
  177. package/dist/{power-and-mde-fK5Qocwo.js → power-and-mde-Hj2ubb4B.js} +2 -2
  178. package/dist/{power-and-mde-fK5Qocwo.js.map → power-and-mde-Hj2ubb4B.js.map} +1 -1
  179. package/dist/predicate-FdKmElA_.js +38 -0
  180. package/dist/predicate-FdKmElA_.js.map +1 -0
  181. package/dist/{prime-protocol-DcAK9pC8.js → prime-protocol-CHKgA3a6.js} +2 -2
  182. package/dist/{prime-protocol-DcAK9pC8.js.map → prime-protocol-CHKgA3a6.js.map} +1 -1
  183. package/dist/{prime-protocol-BHia9vDz.d.ts → prime-protocol-HiB9HX7E.d.ts} +3 -3
  184. package/dist/{prime-protocol-BHia9vDz.d.ts.map → prime-protocol-HiB9HX7E.d.ts.map} +1 -1
  185. package/dist/{produced-state-BGp4BX8t.js → produced-state-BsDmnwxc.js} +8 -8
  186. package/dist/{produced-state-BGp4BX8t.js.map → produced-state-BsDmnwxc.js.map} +1 -1
  187. package/dist/profile-cell.js +1 -1
  188. package/dist/{release-confidence-BK2QCB5M.d.ts → promotion-gate-BawrdPYr.d.ts} +102 -102
  189. package/dist/promotion-gate-BawrdPYr.d.ts.map +1 -0
  190. package/dist/{promotion-policy-CWW35UWq.js → promotion-policy-KO57gbyV.js} +4 -4
  191. package/dist/{promotion-policy-CWW35UWq.js.map → promotion-policy-KO57gbyV.js.map} +1 -1
  192. package/dist/{proposal-findings-CXblsskH.js → proposal-findings-CY1xKn_a.js} +2 -36
  193. package/dist/proposal-findings-CY1xKn_a.js.map +1 -0
  194. package/dist/{query-B1D1qp2Z.js → query-BUCZCK7F.js} +3 -3
  195. package/dist/{query-B1D1qp2Z.js.map → query-BUCZCK7F.js.map} +1 -1
  196. package/dist/{random-Dn5fPWkt.js → random-ByUSnV9w.js} +2 -2
  197. package/dist/{random-Dn5fPWkt.js.map → random-ByUSnV9w.js.map} +1 -1
  198. package/dist/{raw-provider-sink-rB2DYxr6.js → raw-provider-sink-DoHz4JNG.js} +2 -2
  199. package/dist/{raw-provider-sink-rB2DYxr6.js.map → raw-provider-sink-DoHz4JNG.js.map} +1 -1
  200. package/dist/{redact-Dk1ZdJEm.js → redact-B5xXKqQ3.js} +97 -98
  201. package/dist/redact-B5xXKqQ3.js.map +1 -0
  202. package/dist/{redact-Cveoq6fJ.d.ts → redact-mtCCcT8z.d.ts} +4 -20
  203. package/dist/redact-mtCCcT8z.d.ts.map +1 -0
  204. package/dist/{registry-CMYIaDgS.d.ts → registry-D7_hm2fK.d.ts} +11 -13
  205. package/dist/registry-D7_hm2fK.d.ts.map +1 -0
  206. package/dist/{release-confidence-Dbe9AS_X.js → release-confidence-CpuP65S5.js} +5 -5
  207. package/dist/{release-confidence-Dbe9AS_X.js.map → release-confidence-CpuP65S5.js.map} +1 -1
  208. package/dist/{report-command-CtIIsQKP.js → report-command-SC9nqb4M.js} +128 -177
  209. package/dist/report-command-SC9nqb4M.js.map +1 -0
  210. package/dist/reporting-html-Kvlc8oMt.js +100 -0
  211. package/dist/reporting-html-Kvlc8oMt.js.map +1 -0
  212. package/dist/reporting.d.ts +3 -3
  213. package/dist/reporting.js +6 -6
  214. package/dist/{researcher-f6mZhh58.d.ts → researcher-CEcfku-T.d.ts} +5 -5
  215. package/dist/{researcher-f6mZhh58.d.ts.map → researcher-CEcfku-T.d.ts.map} +1 -1
  216. package/dist/reward-CpCmAM8L.d.ts +78 -0
  217. package/dist/reward-CpCmAM8L.d.ts.map +1 -0
  218. package/dist/{reward-hacking-BFcQgkux.js → reward-hacking-E0d-WVcP.js} +2 -2
  219. package/dist/{reward-hacking-BFcQgkux.js.map → reward-hacking-E0d-WVcP.js.map} +1 -1
  220. package/dist/{reward-hacking-DHA7c1l8.d.ts → reward-hacking-RVdZ6Kkt.d.ts} +2 -2
  221. package/dist/{reward-hacking-DHA7c1l8.d.ts.map → reward-hacking-RVdZ6Kkt.d.ts.map} +1 -1
  222. package/dist/rl.d.ts +8 -8
  223. package/dist/rl.js +14 -14
  224. package/dist/rollout/index.d.ts +3 -2
  225. package/dist/rollout/index.js +2 -2
  226. package/dist/{rollout-D9bKKBnZ.js → rollout-DZV1t2Wg.js} +2 -2
  227. package/dist/{rollout-D9bKKBnZ.js.map → rollout-DZV1t2Wg.js.map} +1 -1
  228. package/dist/round-decimal-COrKglMh.js +10 -0
  229. package/dist/round-decimal-COrKglMh.js.map +1 -0
  230. package/dist/{rubric-predictive-validity-2SgHxoa5.d.ts → rubric-predictive-validity-C03EC7ZE.d.ts} +2 -2
  231. package/dist/{rubric-predictive-validity-2SgHxoa5.d.ts.map → rubric-predictive-validity-C03EC7ZE.d.ts.map} +1 -1
  232. package/dist/{rubric-predictive-validity-BsgkBfT0.js → rubric-predictive-validity-DaFW70y9.js} +3 -3
  233. package/dist/{rubric-predictive-validity-BsgkBfT0.js.map → rubric-predictive-validity-DaFW70y9.js.map} +1 -1
  234. package/dist/{run-record-DlTZ_lqe.js → run-record-Boc5IUTp.js} +4 -4
  235. package/dist/{run-record-DlTZ_lqe.js.map → run-record-Boc5IUTp.js.map} +1 -1
  236. package/dist/{run-record-D1Hw-Jml.d.ts → run-record-C1E24G2A.d.ts} +2 -2
  237. package/dist/{run-record-D1Hw-Jml.d.ts.map → run-record-C1E24G2A.d.ts.map} +1 -1
  238. package/dist/{run-record-ES07wfz9.js → run-record-C5e7FjhJ.js} +3 -5
  239. package/dist/run-record-C5e7FjhJ.js.map +1 -0
  240. package/dist/search/index.d.ts +46 -32
  241. package/dist/search/index.d.ts.map +1 -1
  242. package/dist/search/index.js +3 -3
  243. package/dist/{search-kernel-BqyBZ9Wm.d.ts → search-kernel-DyNEa6IU.d.ts} +14 -10
  244. package/dist/search-kernel-DyNEa6IU.d.ts.map +1 -0
  245. package/dist/{search-ledger-d7V8o9Lk.js → search-ledger-CVUGLDZp.js} +189 -199
  246. package/dist/search-ledger-CVUGLDZp.js.map +1 -0
  247. package/dist/{search-ledger-file-BqOo-bVo.js → search-ledger-file-DDQUgvCg.js} +4 -4
  248. package/dist/{search-ledger-file-BqOo-bVo.js.map → search-ledger-file-DDQUgvCg.js.map} +1 -1
  249. package/dist/search-ledger-types-p2xKfiDJ.d.ts.map +1 -1
  250. package/dist/{search-shipper-er4pK5_Y.js → search-shipper-BOSD46qv.js} +3 -3
  251. package/dist/{search-shipper-er4pK5_Y.js.map → search-shipper-BOSD46qv.js.map} +1 -1
  252. package/dist/{search-summary-CBvz3u_S.js → search-summary-BQCSWf1g.js} +5 -5
  253. package/dist/{search-summary-CBvz3u_S.js.map → search-summary-BQCSWf1g.js.map} +1 -1
  254. package/dist/{semantic-concept-judge-BPqbwIVs.js → semantic-concept-judge-BQF8te0T.js} +12 -14
  255. package/dist/semantic-concept-judge-BQF8te0T.js.map +1 -0
  256. package/dist/{sequential-D-1PPCmM.js → sequential-Bf_pbE50.js} +5 -5
  257. package/dist/{sequential-D-1PPCmM.js.map → sequential-Bf_pbE50.js.map} +1 -1
  258. package/dist/{sequential-eprocess-D1jKoihe.js → sequential-eprocess-DM_qENCl.js} +2 -2
  259. package/dist/{sequential-eprocess-D1jKoihe.js.map → sequential-eprocess-DM_qENCl.js.map} +1 -1
  260. package/dist/{server-DbcC7xMl.js → server-e9oWO_bN.js} +4 -4
  261. package/dist/{server-DbcC7xMl.js.map → server-e9oWO_bN.js.map} +1 -1
  262. package/dist/{single-run-lock-fVu3MZWH.js → single-run-lock-CV9Eyd_q.js} +2 -2
  263. package/dist/{single-run-lock-fVu3MZWH.js.map → single-run-lock-CV9Eyd_q.js.map} +1 -1
  264. package/dist/{skillopt-optimization-method-Dcepr6QL.js → skillopt-optimization-method-BiwA8nfX.js} +427 -12
  265. package/dist/skillopt-optimization-method-BiwA8nfX.js.map +1 -0
  266. package/dist/{spans-D9_ehFuk.d.ts → spans-BHAUXMGN.d.ts} +2 -2
  267. package/dist/{spans-D9_ehFuk.d.ts.map → spans-BHAUXMGN.d.ts.map} +1 -1
  268. package/dist/{statistical-heldout-1Gbmex7v.js → statistical-heldout-42NlCNDe.js} +3 -3
  269. package/dist/{statistical-heldout-1Gbmex7v.js.map → statistical-heldout-42NlCNDe.js.map} +1 -1
  270. package/dist/{statistical-heldout-CJTj2EoS.d.ts → statistical-heldout-CYpGaoDH.d.ts} +3 -3
  271. package/dist/{statistical-heldout-CJTj2EoS.d.ts.map → statistical-heldout-CYpGaoDH.d.ts.map} +1 -1
  272. package/dist/{store-otlp-DWVhUgEj.js → store-otlp-DJ9dtA5x.js} +135 -132
  273. package/dist/store-otlp-DJ9dtA5x.js.map +1 -0
  274. package/dist/{store-tool-spans-BNICrhsb.js → store-tool-spans-CIX5arAG.js} +7 -7
  275. package/dist/{store-tool-spans-BNICrhsb.js.map → store-tool-spans-CIX5arAG.js.map} +1 -1
  276. package/dist/{store-tool-spans-BNzls3OD.d.ts → store-tool-spans-DdCSPa7C.d.ts} +162 -161
  277. package/dist/store-tool-spans-DdCSPa7C.d.ts.map +1 -0
  278. package/dist/storyboard/index.d.ts.map +1 -1
  279. package/dist/storyboard/index.js +20 -3
  280. package/dist/storyboard/index.js.map +1 -1
  281. package/dist/{student-t-BQeKJx2N.js → student-t-DVPW7CdL.js} +2 -2
  282. package/dist/{student-t-BQeKJx2N.js.map → student-t-DVPW7CdL.js.map} +1 -1
  283. package/dist/{summary-report-DtdRucM0.js → summary-report-V_JACR4Y.js} +526 -614
  284. package/dist/summary-report-V_JACR4Y.js.map +1 -0
  285. package/dist/{summary-report-C-CtItCN.d.ts → summary-report-bdFDXq0b.d.ts} +10 -5
  286. package/dist/summary-report-bdFDXq0b.d.ts.map +1 -0
  287. package/dist/supervisor-run/index.d.ts +154 -150
  288. package/dist/supervisor-run/index.d.ts.map +1 -1
  289. package/dist/supervisor-run/index.js +65 -3
  290. package/dist/supervisor-run/index.js.map +1 -1
  291. package/dist/systemone-BomhHr2c.d.ts +135 -0
  292. package/dist/systemone-BomhHr2c.d.ts.map +1 -0
  293. package/dist/systemone-protocol.js +1 -1
  294. package/dist/{systemone-review-C4dZgrgN.d.ts → systemone-review-CUVcQJu6.d.ts} +2 -2
  295. package/dist/{systemone-review-C4dZgrgN.d.ts.map → systemone-review-CUVcQJu6.d.ts.map} +1 -1
  296. package/dist/{systemone-review-DTClwgmE.js → systemone-review-D7sXwsqq.js} +3 -3
  297. package/dist/{systemone-review-DTClwgmE.js.map → systemone-review-D7sXwsqq.js.map} +1 -1
  298. package/dist/systemone.d.ts +4 -134
  299. package/dist/systemone.js +4 -4
  300. package/dist/{task-failure-attributes-DngaLdE4.js → task-failure-attributes-hEmASjix.js} +2 -2
  301. package/dist/{task-failure-attributes-DngaLdE4.js.map → task-failure-attributes-hEmASjix.js.map} +1 -1
  302. package/dist/{terminal-record-BHocwFw1.js → terminal-record-DZyQZ3pz.js} +14 -10
  303. package/dist/terminal-record-DZyQZ3pz.js.map +1 -0
  304. package/dist/{tool-groups-BKRrtqy4.d.ts → tool-groups-C3NEcdCM.d.ts} +3 -3
  305. package/dist/tool-groups-C3NEcdCM.d.ts.map +1 -0
  306. package/dist/{tool-waste-Wi4g6Ekb.d.ts → tool-waste-BKgvd-TP.d.ts} +30 -30
  307. package/dist/tool-waste-BKgvd-TP.d.ts.map +1 -0
  308. package/dist/{tool-waste-BYt5rdt8.js → tool-waste-BlesqTqW.js} +5 -158
  309. package/dist/tool-waste-BlesqTqW.js.map +1 -0
  310. package/dist/{trace-questions-CLx8vt6t.d.ts → trace-questions-CM2CAocU.d.ts} +4 -4
  311. package/dist/{trace-questions-CLx8vt6t.d.ts.map → trace-questions-CM2CAocU.d.ts.map} +1 -1
  312. package/dist/trace-repair/index.d.ts +3 -3
  313. package/dist/trace-repair/index.d.ts.map +1 -1
  314. package/dist/trace-repair/index.js +7 -13
  315. package/dist/trace-repair/index.js.map +1 -1
  316. package/dist/traces.d.ts +76 -58
  317. package/dist/traces.d.ts.map +1 -1
  318. package/dist/traces.js +9 -9
  319. package/dist/trajectory-replay/index.js +3 -3
  320. package/dist/{tree-rXLW3M_4.js → tree-C1XYeXvy.js} +2277 -2339
  321. package/dist/tree-C1XYeXvy.js.map +1 -0
  322. package/dist/{types-DjOMwGY_.d.ts → types-BqkVmHfv.d.ts} +7 -1
  323. package/dist/types-BqkVmHfv.d.ts.map +1 -0
  324. package/dist/{types-DBZ7keha.d.ts → types-C02qtnG8.d.ts} +4 -46
  325. package/dist/types-C02qtnG8.d.ts.map +1 -0
  326. package/dist/{types-DHb5TI36.d.ts → types-C1tnkEgM.d.ts} +347 -6
  327. package/dist/types-C1tnkEgM.d.ts.map +1 -0
  328. package/dist/{types-DinHtRJp.d.ts → types-Cbe2fWBa.d.ts} +3 -3
  329. package/dist/{types-DinHtRJp.d.ts.map → types-Cbe2fWBa.d.ts.map} +1 -1
  330. package/dist/{types-CGEmVYOk.d.ts → types-Cq8mSbq8.d.ts} +78 -72
  331. package/dist/types-Cq8mSbq8.d.ts.map +1 -0
  332. package/dist/{types-CW5b90JH.js → types-IXD2HJzu.js} +16 -3
  333. package/dist/types-IXD2HJzu.js.map +1 -0
  334. package/dist/{verdict-DhPoXApk.js → verdict-Dl0tiT1X.js} +2 -2
  335. package/dist/{verdict-DhPoXApk.js.map → verdict-Dl0tiT1X.js.map} +1 -1
  336. package/dist/{verdict-cache-BQEsVy9n.js → verdict-cache-Bm8EKL2s.js} +2 -2
  337. package/dist/{verdict-cache-BQEsVy9n.js.map → verdict-cache-Bm8EKL2s.js.map} +1 -1
  338. package/dist/wire/index.d.ts +3 -3
  339. package/dist/wire/index.js +1 -1
  340. package/docs/concepts.md +1 -0
  341. package/docs/design/mlbenchmarks-book-review.md +1 -1
  342. package/docs/design/mlbenchmarks-review/probes.mts +23 -31
  343. package/docs/experiment.md +1 -1
  344. package/docs/finding-layers.md +69 -0
  345. package/package.json +1 -1
  346. package/dist/analyze-runs-3xpby3p2.js.map +0 -1
  347. package/dist/analyze-runs-BhFLOztS.d.ts.map +0 -1
  348. package/dist/ast-DJ6Bc7ab.js +0 -558
  349. package/dist/ast-DJ6Bc7ab.js.map +0 -1
  350. package/dist/ast-hI-vjW6J.d.ts +0 -457
  351. package/dist/ast-hI-vjW6J.d.ts.map +0 -1
  352. package/dist/benchmark-command-CgpGi7vY.js.map +0 -1
  353. package/dist/campaign-CpnsCgfz.js.map +0 -1
  354. package/dist/campaign-evidence-OcUciD-N.js.map +0 -1
  355. package/dist/claim-BXcZw-jo.js.map +0 -1
  356. package/dist/cost-ledger-CO7UyEcQ.d.ts.map +0 -1
  357. package/dist/cost-ledger-D2FnJPBF.js.map +0 -1
  358. package/dist/default-registry-KP4-Tolz.js.map +0 -1
  359. package/dist/define-agent-eval-BdfnqXeP.js.map +0 -1
  360. package/dist/evaluation.d.ts.map +0 -1
  361. package/dist/external-optimizer-subprocess-BUxifb8g.js.map +0 -1
  362. package/dist/feedback-trajectory-BLN_6fEs.d.ts.map +0 -1
  363. package/dist/index-B3WBm953.d.ts.map +0 -1
  364. package/dist/index-B7m2uzJL.d.ts.map +0 -1
  365. package/dist/index-CPJJr98o.d.ts.map +0 -1
  366. package/dist/integrity-BV1ZDf42.js.map +0 -1
  367. package/dist/judge-gate-B1qYnkpi.js.map +0 -1
  368. package/dist/llm-client-DQveoxSM.js.map +0 -1
  369. package/dist/llm-judge-Cd5s5Ei6.js.map +0 -1
  370. package/dist/matrix-_BV9-Lk5.js.map +0 -1
  371. package/dist/mint-DCGoBYhB.d.ts +0 -155
  372. package/dist/mint-DCGoBYhB.d.ts.map +0 -1
  373. package/dist/paired-tests-jbwPdSz5.js.map +0 -1
  374. package/dist/proposal-findings-CXblsskH.js.map +0 -1
  375. package/dist/redact-Cveoq6fJ.d.ts.map +0 -1
  376. package/dist/redact-Dk1ZdJEm.js.map +0 -1
  377. package/dist/registry-CMYIaDgS.d.ts.map +0 -1
  378. package/dist/release-confidence-BK2QCB5M.d.ts.map +0 -1
  379. package/dist/report-command-CtIIsQKP.js.map +0 -1
  380. package/dist/run-record-ES07wfz9.js.map +0 -1
  381. package/dist/search-kernel-BqyBZ9Wm.d.ts.map +0 -1
  382. package/dist/search-kernel-BztlERLv.js.map +0 -1
  383. package/dist/search-ledger-d7V8o9Lk.js.map +0 -1
  384. package/dist/semantic-concept-judge-BPqbwIVs.js.map +0 -1
  385. package/dist/skillopt-optimization-method-Dcepr6QL.js.map +0 -1
  386. package/dist/store-otlp-DWVhUgEj.js.map +0 -1
  387. package/dist/store-tool-spans-BNzls3OD.d.ts.map +0 -1
  388. package/dist/summary-report-C-CtItCN.d.ts.map +0 -1
  389. package/dist/summary-report-DtdRucM0.js.map +0 -1
  390. package/dist/systemone.d.ts.map +0 -1
  391. package/dist/terminal-record-BHocwFw1.js.map +0 -1
  392. package/dist/tool-groups-BKRrtqy4.d.ts.map +0 -1
  393. package/dist/tool-waste-BYt5rdt8.js.map +0 -1
  394. package/dist/tool-waste-Wi4g6Ekb.d.ts.map +0 -1
  395. package/dist/tree-rXLW3M_4.js.map +0 -1
  396. package/dist/types-CGEmVYOk.d.ts.map +0 -1
  397. package/dist/types-CW5b90JH.js.map +0 -1
  398. package/dist/types-DBZ7keha.d.ts.map +0 -1
  399. package/dist/types-DHb5TI36.d.ts.map +0 -1
  400. package/dist/types-DjOMwGY_.d.ts.map +0 -1
@@ -1,13 +1,13 @@
1
- import { a as hashCanonical, r as canonicalString } from "./canonical-BsZVgBhW.js";
1
+ import { a as hashCanonical, r as canonicalString } from "./canonical-B2RqLofv.js";
2
2
  import { t as deepFreezeCanonicalJson } from "./deep-freeze-CurcOQg3.js";
3
- import { C as combineAbortSignals } from "./llm-client-DQveoxSM.js";
4
- import { A as spanEpochMillis, H as findingSubjectGrammarPromptFor, J as snapshotExactExecutionPlan, q as snapshotExactExecutionComponentIdentity, t as createTraceAnalyst } from "./kind-factory-AaEhUADH.js";
3
+ import { a as makeFinding } from "./types-IXD2HJzu.js";
4
+ import { A as spanEpochMillis, H as findingSubjectGrammarPromptFor, J as snapshotExactExecutionPlan, q as snapshotExactExecutionComponentIdentity, t as createTraceAnalyst } from "./kind-factory-BobI5Jy3.js";
5
5
  import { i as validateUsageSettlementTimeout, t as assertValidAnalystUsageReceipt } from "./usage-receipt-Cx3xNeyB.js";
6
6
  import { LLM_CONTEXT_TOKENS, LLM_INPUT_TOKEN_ATTR_KEYS, LLM_OUTPUT_TOKEN_ATTR_KEYS, TOOL_NAME_ATTR_KEYS } from "./trace-attributes.js";
7
7
  import "./otlp-attributes-D9ptWaIJ.js";
8
- import { r as makeFinding } from "./types-CW5b90JH.js";
8
+ import { y as combineAbortSignals } from "./llm-client-CyBAoYiX.js";
9
9
  import { t as executionTrackByLane } from "./execution-tracks-CpgFPpS5.js";
10
- import { t as analyzeSupervisorRunIntegrity } from "./integrity-BV1ZDf42.js";
10
+ import { t as analyzeSupervisorRunIntegrity } from "./integrity-dLiDe2kD.js";
11
11
  import { randomUUID } from "node:crypto";
12
12
  import { z } from "zod";
13
13
  //#region src/feedback-trajectory-review.ts
@@ -1265,564 +1265,336 @@ const DEFAULT_TRACE_ANALYST_KINDS = [
1265
1265
  IMPROVEMENT_KIND_SPEC
1266
1266
  ];
1267
1267
  //#endregion
1268
- //#region src/analyst/registry.ts
1268
+ //#region src/analyst/registry-accounting.ts
1269
+ function exactPlannedAllocation(plan, analystId) {
1270
+ const budget = plan.policy.budget;
1271
+ if (budget.kind === "none") return void 0;
1272
+ const allocated = budget.allocations_usd[analystId];
1273
+ return allocated === null ? void 0 : allocated;
1274
+ }
1275
+ function logUncapturedBudgetWarning(args) {
1276
+ if (args.budgetUsd === void 0 || args.usage.cost.kind !== "uncaptured") return;
1277
+ args.log(`[analyst] WARN ${args.analyst.id} — USD cost uncaptured; budget not reconciled`, {
1278
+ runId: args.runId,
1279
+ budget_usd: args.budgetUsd,
1280
+ cost_captured: false
1281
+ });
1282
+ }
1269
1283
  /**
1270
- * AnalystRegistry — orchestrate N analysts against one run.
1271
- *
1272
- * Owns three responsibilities and only three:
1273
- * 1. Registration — ids must be unique; bad registrations fail loudly
1274
- * at register-time, not run-time.
1275
- * 2. Routing — each analyst declares its `inputKind`; the registry
1276
- * picks the matching field from AnalystRunInputs and skips the
1277
- * analyst with a logged reason if it's missing.
1278
- * 3. Isolation — one analyst's exception MUST NOT stop other analysts.
1279
- * Failed analysts produce zero findings + a 'failed' summary row.
1280
- *
1281
- * Cross-cutting concerns (telemetry, error → finding conversion, cost
1282
- * ingestion, storage rotation) live in `AnalystHooks`. Budget shaping
1283
- * (equal split vs weighted vs custom) lives in `BudgetPolicy`. Both
1284
- * have sensible defaults; consumers override only what they need.
1284
+ * Custom allocation takes priority, then weights, then equal shares.
1285
+ * Each allocation stays within the unspent overall budget.
1285
1286
  */
1286
- /** A post-start exact-run failure; completed work remains attached for accounting and review. */
1287
- var ExactAnalystRunExecutionError = class extends Error {
1288
- name = "ExactAnalystRunExecutionError";
1289
- result;
1290
- constructor(message, result, options) {
1291
- super(message, options);
1292
- const snapshot = snapshotExactAnalystRunReceipt(result, "ExactAnalystRunExecutionError result");
1293
- if (snapshot.completion.status !== "failed") throw new TypeError("ExactAnalystRunExecutionError result must be a failed receipt");
1294
- this.result = snapshot;
1295
- }
1296
- };
1297
- var AnalystRegistry = class {
1298
- analysts = /* @__PURE__ */ new Map();
1299
- options;
1300
- constructor(options = {}) {
1301
- this.options = options;
1302
- }
1303
- register(analyst) {
1304
- const id = analyst.id;
1305
- const version = analyst.version;
1306
- const cost = analyst.cost;
1307
- if (!id) throw new Error("AnalystRegistry.register: analyst.id is required");
1308
- if (this.analysts.has(id)) throw new Error(`AnalystRegistry.register: duplicate analyst id "${id}"`);
1309
- if (!version) throw new Error(`AnalystRegistry.register: analyst "${id}" must declare a version`);
1310
- if (cost.kind === "deterministic" && cost.settlement_timeout_ms !== void 0) throw new TypeError(`AnalystRegistry.register: deterministic analyst "${id}" cannot declare settlement_timeout_ms`);
1311
- if (cost.settlement_timeout_ms !== void 0) validateUsageSettlementTimeout(cost.settlement_timeout_ms);
1312
- this.analysts.set(id, analyst);
1313
- }
1314
- list() {
1315
- return Array.from(this.analysts.values()).map((a) => ({
1316
- id: a.id,
1317
- description: a.description,
1318
- version: a.version,
1319
- cost: a.cost
1320
- }));
1321
- }
1322
- async run(runId, inputs, runOpts = {}) {
1323
- for await (const ev of this.runStream(runId, inputs, runOpts)) if (ev.type === "run-completed") return ev.result;
1324
- throw new Error("AnalystRegistry.run: stream completed without run-completed event");
1325
- }
1326
- /** Run exactly the ordered analysts and complete policy supplied by the caller. */
1327
- async runExact(runId, inputs, runOpts) {
1328
- for await (const ev of this.runExactStream(runId, inputs, runOpts)) if (ev.type === "run-completed") return ev.result;
1329
- throw new Error("AnalystRegistry.runExact: stream completed without run-completed event");
1330
- }
1331
- /** Streaming counterpart to {@link runExact}. */
1332
- async *runExactStream(runId, inputs, runOpts) {
1333
- for await (const event of this.executePlanStream(this.normalizeExactPlan(runId, inputs, runOpts))) yield event;
1334
- }
1335
- /**
1336
- * Streaming counterpart to `run()`. Emits `AnalystRunEvent` values
1337
- * in real time — `run-started`, then per-analyst `skipped` /
1338
- * `started` / `completed`, then a terminal `run-completed` whose
1339
- * payload is the full `AnalystRunResult`. UIs use this to render
1340
- * progress; persistence consumers use `run()` and read the result.
1341
- *
1342
- * Hooks (`onBeforeAnalyze` / `onAfterAnalyze` / `onError` /
1343
- * `onComplete`) fire as before — streaming is additive, not a hook
1344
- * replacement.
1345
- */
1346
- async *runStream(runId, inputs, runOpts = {}) {
1347
- yield* this.executePlanStream(this.normalizeLegacyPlan(runId, inputs, runOpts));
1348
- }
1349
- normalizeLegacyPlan(runId, inputs, runOpts) {
1350
- const timeoutMs = validateTimeout(runOpts.timeoutMs) ?? null;
1351
- const budget = runOpts.budget ?? this.options.defaultBudget;
1352
- validateBudgetPolicy(budget);
1353
- return {
1354
- runId,
1355
- prepared: this.selectAnalysts(runOpts).map((analyst) => ({
1356
- analyst,
1357
- input: this.routeInput(analyst, inputs)
1358
- })),
1359
- budget: budget ? {
1360
- kind: "dynamic",
1361
- policy: budget
1362
- } : { kind: "none" },
1363
- totalTimeoutMs: timeoutMs,
1364
- signal: runOpts.signal ?? null,
1365
- costLedger: runOpts.costLedger ?? null,
1366
- costPhase: runOpts.costPhase ?? null,
1367
- tags: runOpts.tags ?? null,
1368
- priorFindings: runOpts.priorFindings ?? null,
1369
- chainFindings: runOpts.chainFindings ?? false,
1370
- hooks: this.options.hooks ?? {},
1371
- chat: this.options.chat,
1372
- log: this.options.log ?? (() => {}),
1373
- executionSnapshot: void 0
1374
- };
1375
- }
1376
- normalizeExactPlan(runId, inputs, runOpts) {
1377
- const exactRunId = snapshotExactRunId(runId);
1378
- const exact = snapshotExactRegistryRunOpts(runOpts);
1379
- const selected = normalizeExactAnalysts(this.selectExactAnalysts(exact.analystIds));
1380
- const registryChat = this.options.chat;
1381
- const registryChatIdentity = this.options.chatIdentity;
1382
- const registryHooks = this.options.hooks;
1383
- const registryHooksIdentity = this.options.hooksIdentity;
1384
- if (exact.useRegistryChat && registryChat === void 0) throw new TypeError("ExactRegistryRunOpts.useRegistryChat is true but the registry has no chat client");
1385
- if (exact.applyRegistryHooks && !hasRegistryHooks(registryHooks)) throw new TypeError("ExactRegistryRunOpts.applyRegistryHooks is true but the registry has no lifecycle hooks");
1386
- const inputSnapshot = snapshotAnalystRunInputChannels(inputs);
1387
- const prepared = selected.map((analyst) => ({
1388
- analyst,
1389
- input: this.routeInput(analyst, inputSnapshot)
1390
- }));
1391
- if (exact.missingInputMode === "abort") {
1392
- const missing = prepared.find((candidate) => candidate.input.kind === "missing")?.analyst;
1393
- if (missing) throw new TypeError(`ExactRegistryRunOpts.missingInputMode abort preflight found no "${missing.inputKind}" input for "${missing.id}"`);
1287
+ function allocateBudget(policy, args) {
1288
+ if (!policy) return void 0;
1289
+ if (policy.allocate) {
1290
+ const allocated = policy.allocate({
1291
+ analyst: args.analyst,
1292
+ totalUsd: policy.totalUsd,
1293
+ remainingUsd: args.remainingUsd,
1294
+ runningCount: args.runningCount
1295
+ });
1296
+ if (allocated === void 0) {
1297
+ if (policy.totalUsd !== void 0) throw new Error(`BudgetPolicy.allocate('${args.analyst.id}') cannot return undefined when totalUsd is set`);
1298
+ return;
1394
1299
  }
1395
- const hooksIdentity = exact.applyRegistryHooks && registryHooks ? requireExactComponentIdentity(registryHooksIdentity, "registry hooks") : null;
1396
- const chatIdentity = exact.useRegistryChat ? requireExactComponentIdentity(registryChatIdentity, "registry chat") : null;
1397
- const costLedgerIdentity = exact.costLedger === null ? null : requireExactComponentIdentity(exact.costLedgerIdentity ?? void 0, "cost ledger");
1398
- const executionSnapshot = exactExecutionSnapshot(selected, exact, exactFixedBudgets(exact.budget, prepared.filter((candidate) => candidate.input.kind === "present").map((candidate) => candidate.analyst), selected), costLedgerIdentity, hooksIdentity, chatIdentity);
1399
- return {
1400
- runId: exactRunId,
1401
- prepared,
1402
- budget: { kind: "none" },
1403
- totalTimeoutMs: exact.totalTimeoutMs,
1404
- signal: exact.signal,
1405
- costLedger: exact.costLedger,
1406
- costPhase: exact.costPhase,
1407
- tags: exact.tags,
1408
- priorFindings: exact.priorFindings,
1409
- chainFindings: exact.chainFindings,
1410
- hooks: exact.applyRegistryHooks && registryHooks ? snapshotHooks(registryHooks) : {},
1411
- chat: exact.useRegistryChat && registryChat ? snapshotChat(registryChat) : void 0,
1412
- log: () => {},
1413
- executionSnapshot
1414
- };
1300
+ assertBudgetAmount(allocated, `BudgetPolicy.allocate('${args.analyst.id}')`);
1301
+ return args.remainingUsd === void 0 ? allocated : Math.min(allocated, args.remainingUsd);
1415
1302
  }
1416
- async *executePlanStream(plan) {
1417
- const exact = plan.executionSnapshot !== void 0;
1418
- if (exact && plan.signal?.aborted) throw abortReason(plan.signal);
1419
- const correlationId = `ar_${randomUUID().slice(0, 12)}`;
1420
- const log = plan.log;
1421
- const startedAt = (/* @__PURE__ */ new Date()).toISOString();
1422
- const started = Date.now();
1423
- const timeoutSignal = plan.totalTimeoutMs === null ? void 0 : AbortSignal.timeout(plan.totalTimeoutMs);
1424
- const runSignal = combineAbortSignals(plan.signal ?? void 0, timeoutSignal);
1425
- const deadlineMs = plan.totalTimeoutMs === null ? void 0 : started + plan.totalTimeoutMs;
1426
- const runnable = plan.prepared.filter((candidate) => candidate.input.kind === "present").map((candidate) => candidate.analyst);
1427
- let remainingUsd = plan.budget.kind === "dynamic" ? plan.budget.policy.totalUsd : void 0;
1428
- const weights = plan.budget.kind === "dynamic" ? plan.budget.policy.weights : void 0;
1429
- const totalWeight = weights && plan.budget.kind === "dynamic" && plan.budget.policy.totalUsd != null && !plan.budget.policy.allocate && runnable.length > 0 ? runnable.reduce((sum, analyst) => sum + analystWeight(weights, analyst.id), 0) : void 0;
1430
- if (totalWeight === 0) throw new Error("BudgetPolicy.weights must allocate positive weight to a runnable analyst");
1431
- const upstreamFindings = [];
1432
- yield snapshotExecutionEvent({
1433
- type: "run-started",
1434
- run_id: plan.runId,
1435
- correlation_id: correlationId,
1436
- started_at: startedAt,
1437
- analyst_ids: plan.prepared.map(({ analyst }) => analyst.id),
1438
- ...plan.executionSnapshot === void 0 ? {} : { execution_plan: plan.executionSnapshot }
1439
- }, exact);
1440
- const executions = [];
1441
- let executionFailure;
1442
- for (const { analyst, input } of plan.prepared) {
1443
- const t0 = Date.now();
1444
- if (runSignal?.aborted) {
1445
- const summary = abortedBeforeStartSummary(analyst, runSignal);
1446
- executions.push({
1447
- summary,
1448
- findings: [],
1449
- budgetDebitUsd: 0
1450
- });
1451
- log(`[analyst] skip ${analyst.id} — run aborted`, {
1452
- runId: plan.runId,
1453
- reason: summary.reason
1454
- });
1455
- yield snapshotExecutionEvent({
1456
- type: "analyst-skipped",
1457
- summary
1458
- }, exact);
1459
- if (exact) {
1460
- executionFailure = abortReason(runSignal);
1461
- break;
1462
- }
1463
- continue;
1464
- }
1465
- if (input.kind === "missing") {
1466
- const summary = {
1467
- analyst_id: analyst.id,
1468
- status: "skipped",
1469
- reason: `missing input of kind '${analyst.inputKind}'`,
1470
- findings_count: 0,
1471
- latency_ms: 0,
1472
- usage: zeroUsage()
1473
- };
1474
- const execution = {
1475
- summary,
1476
- findings: [],
1477
- budgetDebitUsd: 0
1478
- };
1479
- executions.push(execution);
1480
- log(`[analyst] skip ${analyst.id} — missing input`, {
1481
- runId: plan.runId,
1482
- kind: analyst.inputKind
1483
- });
1484
- const hookValues = snapshotAfterHookValues(summary, [], exact);
1485
- try {
1486
- await waitForHook(plan.hooks.onAfterAnalyze ? () => plan.hooks.onAfterAnalyze?.({
1487
- analyst,
1488
- summary: hookValues.summary,
1489
- findings: hookValues.findings,
1490
- runId: plan.runId
1491
- }) : void 0, runSignal);
1492
- } catch (error) {
1493
- if (!exact) throw error;
1494
- executionFailure = error;
1495
- }
1496
- yield snapshotExecutionEvent({
1497
- type: "analyst-skipped",
1498
- summary
1499
- }, exact);
1500
- if (executionFailure !== void 0) break;
1501
- continue;
1502
- }
1503
- const allocatedUsd = plan.executionSnapshot === void 0 ? allocateBudget(plan.budget.kind === "dynamic" ? plan.budget.policy : void 0, {
1504
- analyst,
1505
- remainingUsd,
1506
- runningCount: runnable.length,
1507
- totalWeight
1508
- }) : exactPlannedAllocation(plan.executionSnapshot, analyst.id);
1509
- const budgetCeilingUsd = plan.executionSnapshot === void 0 ? remainingUsd : allocatedUsd;
1510
- const usageReceipts = [];
1511
- const contextTags = plan.tags === null ? void 0 : { ...plan.tags };
1512
- const priorFindings = selectPriorFindings(plan.priorFindings ?? void 0, analyst.id);
1513
- const chainedFindings = plan.chainFindings && upstreamFindings.length > 0 ? [...upstreamFindings] : void 0;
1514
- const ctx = {
1515
- runId: plan.runId,
1516
- correlationId,
1517
- deadlineMs,
1518
- budgetUsd: allocatedUsd,
1519
- costLedger: plan.costLedger ?? void 0,
1520
- costPhase: plan.costPhase ?? void 0,
1521
- chat: plan.chat,
1522
- tags: contextTags,
1523
- log: (message, fields) => log(`[${analyst.id}] ${message}`, {
1524
- runId: plan.runId,
1525
- correlationId,
1526
- ...fields
1527
- }),
1528
- signal: runSignal,
1529
- priorFindings,
1530
- upstreamFindings: chainedFindings,
1531
- recordUsage: (receipt) => {
1532
- if (!exact) {
1533
- assertValidAnalystUsageReceipt(receipt);
1534
- usageReceipts.push(receipt);
1535
- return;
1536
- }
1537
- usageReceipts.push(snapshotUsageReceiptOnce(receipt, `AnalystRegistry.runExact analyst "${analyst.id}" usage`));
1538
- }
1539
- };
1540
- if (exact) {
1541
- if (contextTags) deepFreezeCanonicalJson(contextTags);
1542
- if (priorFindings) deepFreezeCanonicalJson(priorFindings);
1543
- if (chainedFindings) deepFreezeCanonicalJson(chainedFindings);
1544
- Object.freeze(ctx);
1545
- }
1546
- try {
1547
- await waitForHook(plan.hooks.onBeforeAnalyze ? () => plan.hooks.onBeforeAnalyze?.({
1548
- analyst,
1549
- ctx,
1550
- runId: plan.runId
1551
- }) : void 0, runSignal);
1552
- } catch (error) {
1553
- if (!exact) throw error;
1554
- executionFailure = error;
1555
- break;
1556
- }
1557
- if (runSignal?.aborted) {
1558
- const summary = abortedBeforeStartSummary(analyst, runSignal, Date.now() - t0);
1559
- executions.push({
1560
- summary,
1561
- findings: [],
1562
- budgetDebitUsd: 0
1563
- });
1564
- yield snapshotExecutionEvent({
1565
- type: "analyst-skipped",
1566
- summary
1567
- }, exact);
1568
- if (exact) {
1569
- executionFailure = abortReason(runSignal);
1570
- break;
1571
- }
1572
- continue;
1573
- }
1574
- let effectiveBudget;
1575
- try {
1576
- effectiveBudget = validateEffectiveBudget(ctx.budgetUsd, budgetCeilingUsd, analyst.id);
1577
- } catch (error) {
1578
- if (!exact) throw error;
1579
- executionFailure = error;
1580
- break;
1581
- }
1582
- const analystContext = exact ? ctx : { ...ctx };
1583
- const executionSignal = exact ? ctx.signal : runSignal;
1584
- yield snapshotExecutionEvent({
1585
- type: "analyst-started",
1586
- analyst_id: analyst.id,
1587
- started_at: new Date(t0).toISOString()
1588
- }, exact);
1589
- let findings;
1590
- let summary;
1591
- let lifecycleFailure;
1592
- let analysisFailure;
1593
- try {
1594
- if (runSignal?.aborted) throw abortReason(runSignal);
1595
- findings = snapshotExecutionFindings(await waitForOperation(analyst.analyze(input.value, analystContext), executionSignal, analystAbortGraceMs(analyst)), exact, `AnalystRegistry.runExact analyst "${analyst.id}" findings`);
1596
- } catch (error) {
1597
- const cause = error instanceof Error ? error : new Error(String(error));
1598
- analysisFailure = cause;
1599
- let hookFindings = [];
1600
- if (!executionSignal?.aborted) try {
1601
- hookFindings = snapshotExecutionFindings(await waitForHook(plan.hooks.onError ? () => plan.hooks.onError?.({
1602
- analyst,
1603
- error: cause,
1604
- runId: plan.runId
1605
- }) : void 0, executionSignal) ?? [], exact, `AnalystRegistry.runExact analyst "${analyst.id}" onError findings`);
1606
- } catch (error) {
1607
- lifecycleFailure = error;
1608
- }
1609
- findings = hookFindings;
1610
- }
1611
- let usage;
1612
- try {
1613
- usage = resolveUsage(analyst, usageReceipts, exact);
1614
- } catch (error) {
1615
- if (!exact) throw error;
1616
- executionFailure = error;
1617
- break;
1618
- }
1619
- if (analysisFailure === void 0) {
1620
- summary = {
1621
- analyst_id: analyst.id,
1622
- status: "ok",
1623
- findings_count: findings.length,
1624
- latency_ms: Date.now() - t0,
1625
- usage,
1626
- ...exact ? { allocated_budget_usd: effectiveBudget ?? null } : {}
1627
- };
1628
- log(`[analyst] ok ${analyst.id}`, {
1629
- runId: plan.runId,
1630
- findings: findings.length,
1631
- latency_ms: summary.latency_ms,
1632
- cost_usd: knownCostUsd(usage),
1633
- cost_kind: usage.cost.kind,
1634
- input_tokens: usage.tokens?.input ?? null,
1635
- output_tokens: usage.tokens?.output ?? null
1636
- });
1637
- } else {
1638
- const errorClass = analysisFailure.constructor.name || "Error";
1639
- const errorMessage = exact && analysisFailure.message.length === 0 ? "Analyst failed without an error message" : analysisFailure.message;
1640
- summary = {
1641
- analyst_id: analyst.id,
1642
- status: "failed",
1643
- findings_count: findings.length,
1644
- latency_ms: Date.now() - t0,
1645
- usage,
1646
- ...exact ? { allocated_budget_usd: effectiveBudget ?? null } : {},
1647
- error: {
1648
- class: errorClass,
1649
- message: errorMessage
1650
- }
1651
- };
1652
- log(`[analyst] FAIL ${analyst.id}`, {
1653
- runId: plan.runId,
1654
- error_class: errorClass,
1655
- error: errorMessage,
1656
- cost_usd: knownCostUsd(usage),
1657
- cost_kind: usage.cost.kind
1658
- });
1659
- }
1660
- logUncapturedBudgetWarning({
1661
- analyst,
1662
- runId: plan.runId,
1663
- budgetUsd: effectiveBudget,
1664
- usage,
1665
- log
1666
- });
1667
- const execution = {
1668
- summary,
1669
- findings,
1670
- budgetDebitUsd: budgetDebit(summary.usage, effectiveBudget)
1671
- };
1672
- if (exact) try {
1673
- executionCost([...executions, execution], true);
1674
- } catch (error) {
1675
- executionFailure = error;
1676
- break;
1677
- }
1678
- executions.push(execution);
1679
- if (plan.budget.kind === "dynamic" && remainingUsd !== void 0) remainingUsd = Math.max(0, remainingUsd - execution.budgetDebitUsd);
1680
- if (plan.chainFindings) upstreamFindings.push(...findings);
1681
- if (lifecycleFailure !== void 0) {
1682
- if (!exact) throw lifecycleFailure;
1683
- executionFailure = lifecycleFailure;
1684
- break;
1685
- }
1686
- const hookValues = snapshotAfterHookValues(summary, findings, exact);
1687
- try {
1688
- await waitForHook(plan.hooks.onAfterAnalyze ? () => plan.hooks.onAfterAnalyze?.({
1689
- analyst,
1690
- summary: hookValues.summary,
1691
- findings: hookValues.findings,
1692
- runId: plan.runId
1693
- }) : void 0, executionSignal);
1694
- } catch (error) {
1695
- if (!exact) throw error;
1696
- executionFailure = error;
1697
- break;
1698
- }
1699
- yield snapshotExecutionEvent({
1700
- type: "analyst-completed",
1701
- summary,
1702
- findings
1703
- }, exact);
1704
- if (exact && runSignal?.aborted) {
1705
- executionFailure = abortReason(runSignal);
1706
- break;
1707
- }
1303
+ if (policy.totalUsd == null) return void 0;
1304
+ const allocated = policy.weights ? policy.totalUsd * analystWeight(policy.weights, args.analyst.id) / args.totalWeight : policy.totalUsd / Math.max(1, args.runningCount);
1305
+ return args.remainingUsd === void 0 ? allocated : Math.min(allocated, args.remainingUsd);
1306
+ }
1307
+ function validateBudgetPolicy(policy) {
1308
+ if (!policy) return;
1309
+ if (policy.totalUsd !== void 0) assertBudgetAmount(policy.totalUsd, "BudgetPolicy.totalUsd");
1310
+ for (const [analystId, weight] of Object.entries(policy.weights ?? {})) assertBudgetAmount(weight, `BudgetPolicy.weights['${analystId}']`);
1311
+ }
1312
+ function assertBudgetAmount(value, field) {
1313
+ if (!Number.isFinite(value) || value < 0) throw new Error(`${field} must be a non-negative finite number`);
1314
+ }
1315
+ function validateEffectiveBudget(budgetUsd, remainingUsd, analystId) {
1316
+ if (budgetUsd !== void 0) assertBudgetAmount(budgetUsd, `AnalystContext.budgetUsd for '${analystId}'`);
1317
+ if (remainingUsd === void 0) return budgetUsd;
1318
+ if (budgetUsd === void 0) throw new Error(`AnalystContext.budgetUsd for '${analystId}' cannot be removed while an overall budget remains`);
1319
+ if (budgetUsd > remainingUsd) throw new Error(`AnalystContext.budgetUsd for '${analystId}' (${budgetUsd}) exceeds the remaining overall budget (${remainingUsd})`);
1320
+ return budgetUsd;
1321
+ }
1322
+ function analystWeight(weights, analystId) {
1323
+ const weight = weights[analystId] ?? 1;
1324
+ assertBudgetAmount(weight, `BudgetPolicy.weights['${analystId}']`);
1325
+ return weight;
1326
+ }
1327
+ function zeroUsage() {
1328
+ return {
1329
+ calls: 0,
1330
+ tokens: {
1331
+ input: 0,
1332
+ output: 0
1333
+ },
1334
+ cost: {
1335
+ kind: "observed",
1336
+ usd: 0
1708
1337
  }
1709
- const summaries = executions.map(({ summary }) => summary);
1710
- const findings = executions.flatMap((execution) => execution.findings);
1711
- const cost = executionCost(executions, exact);
1712
- const baseResult = {
1713
- run_id: plan.runId,
1714
- correlation_id: correlationId,
1715
- started_at: startedAt,
1716
- ended_at: (/* @__PURE__ */ new Date()).toISOString(),
1717
- findings,
1718
- per_analyst: summaries,
1719
- total_cost_usd: cost.known,
1720
- total_cost_provenance: cost.provenance
1721
- };
1722
- if (plan.executionSnapshot === void 0) {
1723
- await waitForHook(plan.hooks.onComplete ? () => plan.hooks.onComplete?.({ result: baseResult }) : void 0, runSignal);
1724
- yield {
1725
- type: "run-completed",
1726
- result: baseResult
1727
- };
1728
- return;
1338
+ };
1339
+ }
1340
+ function resolveUsage(analyst, receipts, exact = false) {
1341
+ if (receipts.length > 0) return mergeUsageReceipts(receipts, exact);
1342
+ if (analyst.cost.kind === "deterministic") return zeroUsage();
1343
+ return {
1344
+ calls: null,
1345
+ tokens: null,
1346
+ cost: {
1347
+ kind: "uncaptured",
1348
+ usd: null
1349
+ }
1350
+ };
1351
+ }
1352
+ function mergeUsageReceipts(receipts, exact = false) {
1353
+ const calls = receipts.every((receipt) => receipt.calls !== null) ? usageSum(receipts.map((receipt) => receipt.calls ?? 0), exact, "calls", true) : null;
1354
+ const tokens = receipts.every((receipt) => receipt.tokens !== null) ? Object.fromEntries([
1355
+ "input",
1356
+ "output",
1357
+ "reasoning",
1358
+ "cached",
1359
+ "cacheWrite"
1360
+ ].flatMap((field) => field === "input" || field === "output" || receipts.some((receipt) => receipt.tokens?.[field] !== void 0) ? [[field, usageSum(receipts.map((receipt) => receipt.tokens?.[field] ?? 0), exact, `tokens.${field}`, true)]] : [])) : null;
1361
+ const cost = aggregateCostProvenance(receipts.map((receipt) => receipt.cost), exact);
1362
+ return {
1363
+ calls,
1364
+ tokens,
1365
+ cost,
1366
+ ...cost.kind === "uncaptured" ? { knownCostUsd: usageSum(receipts.map(knownCostUsd), exact, "known cost") } : {}
1367
+ };
1368
+ }
1369
+ function knownCostUsd(receipt) {
1370
+ return receipt.cost.kind === "uncaptured" ? receipt.knownCostUsd ?? 0 : receipt.cost.usd;
1371
+ }
1372
+ function budgetDebit(receipt, allocatedUsd) {
1373
+ const known = knownCostUsd(receipt);
1374
+ return receipt.cost.kind === "uncaptured" && allocatedUsd !== void 0 ? Math.max(known, allocatedUsd) : known;
1375
+ }
1376
+ function aggregateCostProvenance(costs, exact = false) {
1377
+ if (costs.some((cost) => cost.kind === "uncaptured")) return {
1378
+ kind: "uncaptured",
1379
+ usd: null
1380
+ };
1381
+ const usd = usageSum(costs.map((cost) => cost.usd ?? 0), exact, "captured cost");
1382
+ return costs.some((cost) => cost.kind === "estimated") ? {
1383
+ kind: "estimated",
1384
+ usd
1385
+ } : {
1386
+ kind: "observed",
1387
+ usd
1388
+ };
1389
+ }
1390
+ function executionCost(executions, exact) {
1391
+ const usages = executions.map((execution) => execution.summary.usage);
1392
+ return {
1393
+ known: usageSum(usages.map(knownCostUsd), exact, "run known cost"),
1394
+ provenance: aggregateCostProvenance(usages.map((usage) => usage.cost), exact)
1395
+ };
1396
+ }
1397
+ function usageSum(values, exact, field, integer = false) {
1398
+ const sum = values.reduce((total, value) => total + value, 0);
1399
+ if (exact && (integer ? !Number.isSafeInteger(sum) : !Number.isFinite(sum))) throw new RangeError(`exact analyst usage ${field} aggregate ${integer ? "exceeds a safe integer" : "is not finite"}`);
1400
+ return sum;
1401
+ }
1402
+ //#endregion
1403
+ //#region src/analyst/registry-plan.ts
1404
+ function normalizeLegacyPlan(runId, inputs, runOpts, analysts, options) {
1405
+ const timeoutMs = validateTimeout(runOpts.timeoutMs) ?? null;
1406
+ const budget = runOpts.budget ?? options.defaultBudget;
1407
+ validateBudgetPolicy(budget);
1408
+ return {
1409
+ runId,
1410
+ prepared: selectAnalysts(analysts, runOpts).map((analyst) => ({
1411
+ analyst,
1412
+ input: routeInput(analyst, inputs)
1413
+ })),
1414
+ budget: budget ? {
1415
+ kind: "dynamic",
1416
+ policy: budget
1417
+ } : { kind: "none" },
1418
+ totalTimeoutMs: timeoutMs,
1419
+ signal: runOpts.signal ?? null,
1420
+ costLedger: runOpts.costLedger ?? null,
1421
+ costPhase: runOpts.costPhase ?? null,
1422
+ tags: runOpts.tags ?? null,
1423
+ priorFindings: runOpts.priorFindings ?? null,
1424
+ chainFindings: runOpts.chainFindings ?? false,
1425
+ hooks: options.hooks ?? {},
1426
+ chat: options.chat,
1427
+ log: options.log ?? (() => {}),
1428
+ executionSnapshot: void 0
1429
+ };
1430
+ }
1431
+ function routeInput(analyst, inputs) {
1432
+ switch (analyst.inputKind) {
1433
+ case "trace-store": {
1434
+ const value = inputs.traceStore;
1435
+ return value ? {
1436
+ kind: "present",
1437
+ value
1438
+ } : { kind: "missing" };
1729
1439
  }
1730
- let completeResult;
1731
- if (executionFailure === void 0) try {
1732
- completeResult = snapshotExactAnalystRunReceipt({
1733
- ...baseResult,
1734
- execution_plan: plan.executionSnapshot,
1735
- completion: { status: "complete" }
1736
- }, "AnalystRegistry.runExact result");
1737
- await waitForHook(plan.hooks.onComplete ? () => plan.hooks.onComplete?.({ result: completeResult }) : void 0, runSignal);
1738
- } catch (error) {
1739
- executionFailure = error;
1440
+ case "artifact-dir": {
1441
+ const value = inputs.artifactDir;
1442
+ return value ? {
1443
+ kind: "present",
1444
+ value
1445
+ } : { kind: "missing" };
1740
1446
  }
1741
- if (runSignal?.aborted) executionFailure ??= abortReason(runSignal);
1742
- if (executionFailure === void 0 && completeResult) {
1743
- yield snapshotExecutionEvent({
1744
- type: "run-completed",
1745
- result: completeResult
1746
- }, true);
1747
- return;
1447
+ case "run-record": {
1448
+ const value = inputs.runRecord;
1449
+ return value ? {
1450
+ kind: "present",
1451
+ value
1452
+ } : { kind: "missing" };
1748
1453
  }
1749
- const cause = executionFailure instanceof Error ? executionFailure : new Error(String(executionFailure));
1750
- const errorClass = cause.constructor.name || "Error";
1751
- const errorMessage = cause.message.trim().length === 0 ? "Exact analyst run failed without a message" : cause.message;
1752
- throw new ExactAnalystRunExecutionError(`exact analyst run failed after starting: ${errorMessage}; partial result is attached`, {
1753
- ...baseResult,
1754
- execution_plan: plan.executionSnapshot,
1755
- completion: {
1756
- status: "failed",
1757
- error: {
1758
- class: errorClass,
1759
- message: errorMessage
1760
- }
1761
- }
1762
- }, { cause });
1763
- }
1764
- selectAnalysts(opts) {
1765
- let candidates = Array.from(this.analysts.values());
1766
- if (opts.only?.length) {
1767
- const only = new Set(opts.only);
1768
- candidates = candidates.filter((a) => only.has(a.id));
1454
+ case "judge-input": {
1455
+ const value = inputs.judgeInput;
1456
+ return value ? {
1457
+ kind: "present",
1458
+ value
1459
+ } : { kind: "missing" };
1769
1460
  }
1770
- if (opts.skip?.length) {
1771
- const skip = new Set(opts.skip);
1772
- candidates = candidates.filter((a) => !skip.has(a.id));
1461
+ case "custom": {
1462
+ const value = inputs.custom?.[analyst.id];
1463
+ return value !== void 0 ? {
1464
+ kind: "present",
1465
+ value
1466
+ } : { kind: "missing" };
1773
1467
  }
1774
- return candidates;
1775
1468
  }
1776
- selectExactAnalysts(ids) {
1777
- return ids.map((id) => {
1778
- const analyst = this.analysts.get(id);
1779
- if (!analyst) throw new Error(`ExactRegistryRunOpts.analystIds names unknown analyst "${id}"`);
1780
- return {
1781
- registeredId: id,
1782
- analyst
1783
- };
1784
- });
1469
+ }
1470
+ function selectAnalysts(analysts, opts) {
1471
+ let candidates = Array.from(analysts.values());
1472
+ if (opts.only?.length) {
1473
+ const only = new Set(opts.only);
1474
+ candidates = candidates.filter((a) => only.has(a.id));
1785
1475
  }
1786
- routeInput(analyst, inputs) {
1787
- switch (analyst.inputKind) {
1788
- case "trace-store": {
1789
- const value = inputs.traceStore;
1790
- return value ? {
1791
- kind: "present",
1792
- value
1793
- } : { kind: "missing" };
1794
- }
1795
- case "artifact-dir": {
1796
- const value = inputs.artifactDir;
1797
- return value ? {
1798
- kind: "present",
1799
- value
1800
- } : { kind: "missing" };
1801
- }
1802
- case "run-record": {
1803
- const value = inputs.runRecord;
1804
- return value ? {
1805
- kind: "present",
1806
- value
1807
- } : { kind: "missing" };
1808
- }
1809
- case "judge-input": {
1810
- const value = inputs.judgeInput;
1811
- return value ? {
1812
- kind: "present",
1813
- value
1814
- } : { kind: "missing" };
1815
- }
1816
- case "custom": {
1817
- const value = inputs.custom?.[analyst.id];
1818
- return value !== void 0 ? {
1819
- kind: "present",
1820
- value
1821
- } : { kind: "missing" };
1822
- }
1823
- }
1476
+ if (opts.skip?.length) {
1477
+ const skip = new Set(opts.skip);
1478
+ candidates = candidates.filter((a) => !skip.has(a.id));
1824
1479
  }
1825
- };
1480
+ return candidates;
1481
+ }
1482
+ function validateTimeout(timeoutMs) {
1483
+ if (timeoutMs === void 0) return void 0;
1484
+ if (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0 || timeoutMs > 2147483647) throw new TypeError("RegistryRunOpts.timeoutMs must be a positive safe integer no greater than 2147483647");
1485
+ return timeoutMs;
1486
+ }
1487
+ //#endregion
1488
+ //#region src/analyst/registry-snapshot.ts
1489
+ /** Immutable snapshots at exact execution's untrusted input and observational boundaries. */
1490
+ function canonicalJsonSnapshot(value, label) {
1491
+ let snapshot;
1492
+ try {
1493
+ snapshot = JSON.parse(canonicalString(value));
1494
+ } catch (cause) {
1495
+ throw new TypeError(`${label} must be canonical JSON`, { cause });
1496
+ }
1497
+ return deepFreezeCanonicalJson(snapshot);
1498
+ }
1499
+ function snapshotUsageReceiptOnce(receipt, context) {
1500
+ const data = readOwnFields(receipt, [
1501
+ "calls",
1502
+ "tokens",
1503
+ "cost",
1504
+ "knownCostUsd"
1505
+ ], context);
1506
+ data.tokens = data.tokens === null ? null : readOwnFields(data.tokens, [
1507
+ "input",
1508
+ "output",
1509
+ "reasoning",
1510
+ "cached",
1511
+ "cacheWrite"
1512
+ ], `${context} tokens`);
1513
+ data.cost = readOwnFields(data.cost, ["kind", "usd"], `${context} cost`);
1514
+ const snapshot = canonicalJsonSnapshot(data, context);
1515
+ assertValidAnalystUsageReceipt(snapshot, context);
1516
+ return snapshot;
1517
+ }
1518
+ function readOwnFields(value, fields, context) {
1519
+ if (!isPlainRecord(value)) throw new TypeError(`${context} must be a plain object`);
1520
+ const unexpected = Object.keys(value).filter((key) => !fields.includes(key));
1521
+ if (unexpected.length > 0) throw new TypeError(`${context} contains unknown fields: ${unexpected.sort().join(", ")}`);
1522
+ return Object.fromEntries(fields.flatMap((field) => Object.hasOwn(value, field) ? [[field, value[field]]] : []));
1523
+ }
1524
+ function isPlainRecord(value) {
1525
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
1526
+ const prototype = Object.getPrototypeOf(value);
1527
+ return prototype === Object.prototype || prototype === null;
1528
+ }
1529
+ function snapshotExecutionFindings(findings, exact, context) {
1530
+ return exact ? deepFreezeCanonicalJson(snapshotAnalystFindings(findings, context)) : findings;
1531
+ }
1532
+ function snapshotAfterHookValues(summary, findings, exact) {
1533
+ if (!exact) return {
1534
+ summary,
1535
+ findings
1536
+ };
1537
+ return {
1538
+ summary: canonicalJsonSnapshot(summary, "AnalystRegistry.runExact onAfterAnalyze summary"),
1539
+ findings: deepFreezeCanonicalJson(snapshotAnalystFindings(findings, "AnalystRegistry.runExact onAfterAnalyze findings"))
1540
+ };
1541
+ }
1542
+ function snapshotExecutionEvent(event, exact) {
1543
+ return exact ? canonicalJsonSnapshot(event, "AnalystRegistry.runExact event") : event;
1544
+ }
1545
+ //#endregion
1546
+ //#region src/analyst/registry-exact-plan.ts
1547
+ /** Validate and freeze every input and identity before an exact analyst run starts. */
1548
+ function normalizeExactPlan(runId, inputs, runOpts, analysts, options) {
1549
+ const exactRunId = snapshotExactRunId(runId);
1550
+ const exact = snapshotExactRegistryRunOpts(runOpts);
1551
+ const selected = normalizeExactAnalysts(selectExactAnalysts(analysts, exact.analystIds));
1552
+ const registryChat = options.chat;
1553
+ const registryChatIdentity = options.chatIdentity;
1554
+ const registryHooks = options.hooks;
1555
+ const registryHooksIdentity = options.hooksIdentity;
1556
+ if (exact.useRegistryChat && registryChat === void 0) throw new TypeError("ExactRegistryRunOpts.useRegistryChat is true but the registry has no chat client");
1557
+ if (exact.applyRegistryHooks && !hasRegistryHooks(registryHooks)) throw new TypeError("ExactRegistryRunOpts.applyRegistryHooks is true but the registry has no lifecycle hooks");
1558
+ const inputSnapshot = snapshotAnalystRunInputChannels(inputs);
1559
+ const prepared = selected.map((analyst) => ({
1560
+ analyst,
1561
+ input: routeInput(analyst, inputSnapshot)
1562
+ }));
1563
+ if (exact.missingInputMode === "abort") {
1564
+ const missing = prepared.find((candidate) => candidate.input.kind === "missing")?.analyst;
1565
+ if (missing) throw new TypeError(`ExactRegistryRunOpts.missingInputMode abort preflight found no "${missing.inputKind}" input for "${missing.id}"`);
1566
+ }
1567
+ const hooksIdentity = exact.applyRegistryHooks && registryHooks ? requireExactComponentIdentity(registryHooksIdentity, "registry hooks") : null;
1568
+ const chatIdentity = exact.useRegistryChat ? requireExactComponentIdentity(registryChatIdentity, "registry chat") : null;
1569
+ const costLedgerIdentity = exact.costLedger === null ? null : requireExactComponentIdentity(exact.costLedgerIdentity ?? void 0, "cost ledger");
1570
+ const executionSnapshot = exactExecutionSnapshot(selected, exact, exactFixedBudgets(exact.budget, prepared.filter((candidate) => candidate.input.kind === "present").map((candidate) => candidate.analyst), selected), costLedgerIdentity, hooksIdentity, chatIdentity);
1571
+ return {
1572
+ runId: exactRunId,
1573
+ prepared,
1574
+ budget: { kind: "none" },
1575
+ totalTimeoutMs: exact.totalTimeoutMs,
1576
+ signal: exact.signal,
1577
+ costLedger: exact.costLedger,
1578
+ costPhase: exact.costPhase,
1579
+ tags: exact.tags,
1580
+ priorFindings: exact.priorFindings,
1581
+ chainFindings: exact.chainFindings,
1582
+ hooks: exact.applyRegistryHooks && registryHooks ? snapshotHooks(registryHooks) : {},
1583
+ chat: exact.useRegistryChat && registryChat ? snapshotChat(registryChat) : void 0,
1584
+ log: () => {},
1585
+ executionSnapshot
1586
+ };
1587
+ }
1588
+ function selectExactAnalysts(analysts, ids) {
1589
+ return ids.map((id) => {
1590
+ const analyst = analysts.get(id);
1591
+ if (!analyst) throw new Error(`ExactRegistryRunOpts.analystIds names unknown analyst "${id}"`);
1592
+ return {
1593
+ registeredId: id,
1594
+ analyst
1595
+ };
1596
+ });
1597
+ }
1826
1598
  const exactRunFields = [
1827
1599
  "analystIds",
1828
1600
  "budget",
@@ -2057,45 +1829,6 @@ function exactPriorFindingsSnapshot(findings) {
2057
1829
  digest: hashCanonical(record)
2058
1830
  };
2059
1831
  }
2060
- function canonicalJsonSnapshot(value, label) {
2061
- let snapshot;
2062
- try {
2063
- snapshot = JSON.parse(canonicalString(value));
2064
- } catch (cause) {
2065
- throw new TypeError(`${label} must be canonical JSON`, { cause });
2066
- }
2067
- return deepFreezeCanonicalJson(snapshot);
2068
- }
2069
- function snapshotUsageReceiptOnce(receipt, context) {
2070
- const data = readOwnFields(receipt, [
2071
- "calls",
2072
- "tokens",
2073
- "cost",
2074
- "knownCostUsd"
2075
- ], context);
2076
- data.tokens = data.tokens === null ? null : readOwnFields(data.tokens, [
2077
- "input",
2078
- "output",
2079
- "reasoning",
2080
- "cached",
2081
- "cacheWrite"
2082
- ], `${context} tokens`);
2083
- data.cost = readOwnFields(data.cost, ["kind", "usd"], `${context} cost`);
2084
- const snapshot = canonicalJsonSnapshot(data, context);
2085
- assertValidAnalystUsageReceipt(snapshot, context);
2086
- return snapshot;
2087
- }
2088
- function readOwnFields(value, fields, context) {
2089
- if (!isPlainRecord(value)) throw new TypeError(`${context} must be a plain object`);
2090
- const unexpected = Object.keys(value).filter((key) => !fields.includes(key));
2091
- if (unexpected.length > 0) throw new TypeError(`${context} contains unknown fields: ${unexpected.sort().join(", ")}`);
2092
- return Object.fromEntries(fields.flatMap((field) => Object.hasOwn(value, field) ? [[field, value[field]]] : []));
2093
- }
2094
- function isPlainRecord(value) {
2095
- if (!value || typeof value !== "object" || Array.isArray(value)) return false;
2096
- const prototype = Object.getPrototypeOf(value);
2097
- return prototype === Object.prototype || prototype === null;
2098
- }
2099
1832
  function exactFixedBudgets(exact, runnable, selected) {
2100
1833
  if (exact === null) return {};
2101
1834
  const allocations = Object.fromEntries(selected.map((analyst) => [analyst.id, null]));
@@ -2105,45 +1838,372 @@ function exactFixedBudgets(exact, runnable, selected) {
2105
1838
  for (const analyst of runnable) allocations[analyst.id] = each;
2106
1839
  return deepFreezeCanonicalJson(allocations);
2107
1840
  }
2108
- const totalWeight = runnable.reduce((sum, analyst) => sum + exact.weights[analyst.id], 0);
2109
- if (totalWeight === 0) throw new Error("ExactRegistryRunOpts weighted budget must allocate positive weight to a runnable analyst");
2110
- for (const analyst of runnable) allocations[analyst.id] = exact.totalUsd * exact.weights[analyst.id] / totalWeight;
2111
- return deepFreezeCanonicalJson(allocations);
2112
- }
2113
- function snapshotExecutionFindings(findings, exact, context) {
2114
- return exact ? deepFreezeCanonicalJson(snapshotAnalystFindings(findings, context)) : findings;
2115
- }
2116
- function snapshotAfterHookValues(summary, findings, exact) {
2117
- if (!exact) return {
2118
- summary,
2119
- findings
2120
- };
2121
- return {
2122
- summary: canonicalJsonSnapshot(summary, "AnalystRegistry.runExact onAfterAnalyze summary"),
2123
- findings: deepFreezeCanonicalJson(snapshotAnalystFindings(findings, "AnalystRegistry.runExact onAfterAnalyze findings"))
1841
+ const totalWeight = runnable.reduce((sum, analyst) => sum + exact.weights[analyst.id], 0);
1842
+ if (totalWeight === 0) throw new Error("ExactRegistryRunOpts weighted budget must allocate positive weight to a runnable analyst");
1843
+ for (const analyst of runnable) allocations[analyst.id] = exact.totalUsd * exact.weights[analyst.id] / totalWeight;
1844
+ return deepFreezeCanonicalJson(allocations);
1845
+ }
1846
+ //#endregion
1847
+ //#region src/analyst/registry-execution.ts
1848
+ /** Execute one prepared plan with serial analyst isolation, lifecycle hooks, and accounting. */
1849
+ /** A post-start exact-run failure; completed work remains attached for accounting and review. */
1850
+ var ExactAnalystRunExecutionError = class extends Error {
1851
+ name = "ExactAnalystRunExecutionError";
1852
+ result;
1853
+ constructor(message, result, options) {
1854
+ super(message, options);
1855
+ const snapshot = snapshotExactAnalystRunReceipt(result, "ExactAnalystRunExecutionError result");
1856
+ if (snapshot.completion.status !== "failed") throw new TypeError("ExactAnalystRunExecutionError result must be a failed receipt");
1857
+ this.result = snapshot;
1858
+ }
1859
+ };
1860
+ async function* executePlanStream(plan) {
1861
+ const exact = plan.executionSnapshot !== void 0;
1862
+ if (exact && plan.signal?.aborted) throw abortReason(plan.signal);
1863
+ const correlationId = `ar_${randomUUID().slice(0, 12)}`;
1864
+ const log = plan.log;
1865
+ const startedAt = (/* @__PURE__ */ new Date()).toISOString();
1866
+ const started = Date.now();
1867
+ const timeoutSignal = plan.totalTimeoutMs === null ? void 0 : AbortSignal.timeout(plan.totalTimeoutMs);
1868
+ const runSignal = combineAbortSignals(plan.signal ?? void 0, timeoutSignal);
1869
+ const deadlineMs = plan.totalTimeoutMs === null ? void 0 : started + plan.totalTimeoutMs;
1870
+ const runnable = plan.prepared.filter((candidate) => candidate.input.kind === "present").map((candidate) => candidate.analyst);
1871
+ let remainingUsd = plan.budget.kind === "dynamic" ? plan.budget.policy.totalUsd : void 0;
1872
+ const weights = plan.budget.kind === "dynamic" ? plan.budget.policy.weights : void 0;
1873
+ const totalWeight = weights && plan.budget.kind === "dynamic" && plan.budget.policy.totalUsd != null && !plan.budget.policy.allocate && runnable.length > 0 ? runnable.reduce((sum, analyst) => sum + analystWeight(weights, analyst.id), 0) : void 0;
1874
+ if (totalWeight === 0) throw new Error("BudgetPolicy.weights must allocate positive weight to a runnable analyst");
1875
+ const upstreamFindings = [];
1876
+ yield snapshotExecutionEvent({
1877
+ type: "run-started",
1878
+ run_id: plan.runId,
1879
+ correlation_id: correlationId,
1880
+ started_at: startedAt,
1881
+ analyst_ids: plan.prepared.map(({ analyst }) => analyst.id),
1882
+ ...plan.executionSnapshot === void 0 ? {} : { execution_plan: plan.executionSnapshot }
1883
+ }, exact);
1884
+ const executions = [];
1885
+ let executionFailure;
1886
+ for (const { analyst, input } of plan.prepared) {
1887
+ const t0 = Date.now();
1888
+ if (runSignal?.aborted) {
1889
+ const summary = abortedBeforeStartSummary(analyst, runSignal);
1890
+ executions.push({
1891
+ summary,
1892
+ findings: [],
1893
+ budgetDebitUsd: 0
1894
+ });
1895
+ log(`[analyst] skip ${analyst.id} — run aborted`, {
1896
+ runId: plan.runId,
1897
+ reason: summary.reason
1898
+ });
1899
+ yield snapshotExecutionEvent({
1900
+ type: "analyst-skipped",
1901
+ summary
1902
+ }, exact);
1903
+ if (exact) {
1904
+ executionFailure = abortReason(runSignal);
1905
+ break;
1906
+ }
1907
+ continue;
1908
+ }
1909
+ if (input.kind === "missing") {
1910
+ const summary = {
1911
+ analyst_id: analyst.id,
1912
+ status: "skipped",
1913
+ reason: `missing input of kind '${analyst.inputKind}'`,
1914
+ findings_count: 0,
1915
+ latency_ms: 0,
1916
+ usage: zeroUsage()
1917
+ };
1918
+ const execution = {
1919
+ summary,
1920
+ findings: [],
1921
+ budgetDebitUsd: 0
1922
+ };
1923
+ executions.push(execution);
1924
+ log(`[analyst] skip ${analyst.id} — missing input`, {
1925
+ runId: plan.runId,
1926
+ kind: analyst.inputKind
1927
+ });
1928
+ const hookValues = snapshotAfterHookValues(summary, [], exact);
1929
+ try {
1930
+ await waitForHook(plan.hooks.onAfterAnalyze ? () => plan.hooks.onAfterAnalyze?.({
1931
+ analyst,
1932
+ summary: hookValues.summary,
1933
+ findings: hookValues.findings,
1934
+ runId: plan.runId
1935
+ }) : void 0, runSignal);
1936
+ } catch (error) {
1937
+ if (!exact) throw error;
1938
+ executionFailure = error;
1939
+ }
1940
+ yield snapshotExecutionEvent({
1941
+ type: "analyst-skipped",
1942
+ summary
1943
+ }, exact);
1944
+ if (executionFailure !== void 0) break;
1945
+ continue;
1946
+ }
1947
+ const allocatedUsd = plan.executionSnapshot === void 0 ? allocateBudget(plan.budget.kind === "dynamic" ? plan.budget.policy : void 0, {
1948
+ analyst,
1949
+ remainingUsd,
1950
+ runningCount: runnable.length,
1951
+ totalWeight
1952
+ }) : exactPlannedAllocation(plan.executionSnapshot, analyst.id);
1953
+ const budgetCeilingUsd = plan.executionSnapshot === void 0 ? remainingUsd : allocatedUsd;
1954
+ const usageReceipts = [];
1955
+ const contextTags = plan.tags === null ? void 0 : { ...plan.tags };
1956
+ const priorFindings = selectPriorFindings(plan.priorFindings ?? void 0, analyst.id);
1957
+ const chainedFindings = plan.chainFindings && upstreamFindings.length > 0 ? [...upstreamFindings] : void 0;
1958
+ const ctx = {
1959
+ runId: plan.runId,
1960
+ correlationId,
1961
+ deadlineMs,
1962
+ budgetUsd: allocatedUsd,
1963
+ costLedger: plan.costLedger ?? void 0,
1964
+ costPhase: plan.costPhase ?? void 0,
1965
+ chat: plan.chat,
1966
+ tags: contextTags,
1967
+ log: (message, fields) => log(`[${analyst.id}] ${message}`, {
1968
+ runId: plan.runId,
1969
+ correlationId,
1970
+ ...fields
1971
+ }),
1972
+ signal: runSignal,
1973
+ priorFindings,
1974
+ upstreamFindings: chainedFindings,
1975
+ recordUsage: (receipt) => {
1976
+ if (!exact) {
1977
+ assertValidAnalystUsageReceipt(receipt);
1978
+ usageReceipts.push(receipt);
1979
+ return;
1980
+ }
1981
+ usageReceipts.push(snapshotUsageReceiptOnce(receipt, `AnalystRegistry.runExact analyst "${analyst.id}" usage`));
1982
+ }
1983
+ };
1984
+ if (exact) {
1985
+ if (contextTags) deepFreezeCanonicalJson(contextTags);
1986
+ if (priorFindings) deepFreezeCanonicalJson(priorFindings);
1987
+ if (chainedFindings) deepFreezeCanonicalJson(chainedFindings);
1988
+ Object.freeze(ctx);
1989
+ }
1990
+ try {
1991
+ await waitForHook(plan.hooks.onBeforeAnalyze ? () => plan.hooks.onBeforeAnalyze?.({
1992
+ analyst,
1993
+ ctx,
1994
+ runId: plan.runId
1995
+ }) : void 0, runSignal);
1996
+ } catch (error) {
1997
+ if (!exact) throw error;
1998
+ executionFailure = error;
1999
+ break;
2000
+ }
2001
+ if (runSignal?.aborted) {
2002
+ const summary = abortedBeforeStartSummary(analyst, runSignal, Date.now() - t0);
2003
+ executions.push({
2004
+ summary,
2005
+ findings: [],
2006
+ budgetDebitUsd: 0
2007
+ });
2008
+ yield snapshotExecutionEvent({
2009
+ type: "analyst-skipped",
2010
+ summary
2011
+ }, exact);
2012
+ if (exact) {
2013
+ executionFailure = abortReason(runSignal);
2014
+ break;
2015
+ }
2016
+ continue;
2017
+ }
2018
+ let effectiveBudget;
2019
+ try {
2020
+ effectiveBudget = validateEffectiveBudget(ctx.budgetUsd, budgetCeilingUsd, analyst.id);
2021
+ } catch (error) {
2022
+ if (!exact) throw error;
2023
+ executionFailure = error;
2024
+ break;
2025
+ }
2026
+ const analystContext = exact ? ctx : { ...ctx };
2027
+ const executionSignal = exact ? ctx.signal : runSignal;
2028
+ yield snapshotExecutionEvent({
2029
+ type: "analyst-started",
2030
+ analyst_id: analyst.id,
2031
+ started_at: new Date(t0).toISOString()
2032
+ }, exact);
2033
+ let findings;
2034
+ let summary;
2035
+ let lifecycleFailure;
2036
+ let analysisFailure;
2037
+ try {
2038
+ if (runSignal?.aborted) throw abortReason(runSignal);
2039
+ findings = snapshotExecutionFindings(await waitForOperation(analyst.analyze(input.value, analystContext), executionSignal, analystAbortGraceMs(analyst)), exact, `AnalystRegistry.runExact analyst "${analyst.id}" findings`);
2040
+ } catch (error) {
2041
+ const cause = error instanceof Error ? error : new Error(String(error));
2042
+ analysisFailure = cause;
2043
+ let hookFindings = [];
2044
+ if (!executionSignal?.aborted) try {
2045
+ hookFindings = snapshotExecutionFindings(await waitForHook(plan.hooks.onError ? () => plan.hooks.onError?.({
2046
+ analyst,
2047
+ error: cause,
2048
+ runId: plan.runId
2049
+ }) : void 0, executionSignal) ?? [], exact, `AnalystRegistry.runExact analyst "${analyst.id}" onError findings`);
2050
+ } catch (error) {
2051
+ lifecycleFailure = error;
2052
+ }
2053
+ findings = hookFindings;
2054
+ }
2055
+ let usage;
2056
+ try {
2057
+ usage = resolveUsage(analyst, usageReceipts, exact);
2058
+ } catch (error) {
2059
+ if (!exact) throw error;
2060
+ executionFailure = error;
2061
+ break;
2062
+ }
2063
+ if (analysisFailure === void 0) {
2064
+ summary = {
2065
+ analyst_id: analyst.id,
2066
+ status: "ok",
2067
+ findings_count: findings.length,
2068
+ latency_ms: Date.now() - t0,
2069
+ usage,
2070
+ ...exact ? { allocated_budget_usd: effectiveBudget ?? null } : {}
2071
+ };
2072
+ log(`[analyst] ok ${analyst.id}`, {
2073
+ runId: plan.runId,
2074
+ findings: findings.length,
2075
+ latency_ms: summary.latency_ms,
2076
+ cost_usd: knownCostUsd(usage),
2077
+ cost_kind: usage.cost.kind,
2078
+ input_tokens: usage.tokens?.input ?? null,
2079
+ output_tokens: usage.tokens?.output ?? null
2080
+ });
2081
+ } else {
2082
+ const errorClass = analysisFailure.constructor.name || "Error";
2083
+ const errorMessage = exact && analysisFailure.message.length === 0 ? "Analyst failed without an error message" : analysisFailure.message;
2084
+ summary = {
2085
+ analyst_id: analyst.id,
2086
+ status: "failed",
2087
+ findings_count: findings.length,
2088
+ latency_ms: Date.now() - t0,
2089
+ usage,
2090
+ ...exact ? { allocated_budget_usd: effectiveBudget ?? null } : {},
2091
+ error: {
2092
+ class: errorClass,
2093
+ message: errorMessage
2094
+ }
2095
+ };
2096
+ log(`[analyst] FAIL ${analyst.id}`, {
2097
+ runId: plan.runId,
2098
+ error_class: errorClass,
2099
+ error: errorMessage,
2100
+ cost_usd: knownCostUsd(usage),
2101
+ cost_kind: usage.cost.kind
2102
+ });
2103
+ }
2104
+ logUncapturedBudgetWarning({
2105
+ analyst,
2106
+ runId: plan.runId,
2107
+ budgetUsd: effectiveBudget,
2108
+ usage,
2109
+ log
2110
+ });
2111
+ const execution = {
2112
+ summary,
2113
+ findings,
2114
+ budgetDebitUsd: budgetDebit(summary.usage, effectiveBudget)
2115
+ };
2116
+ if (exact) try {
2117
+ executionCost([...executions, execution], true);
2118
+ } catch (error) {
2119
+ executionFailure = error;
2120
+ break;
2121
+ }
2122
+ executions.push(execution);
2123
+ if (plan.budget.kind === "dynamic" && remainingUsd !== void 0) remainingUsd = Math.max(0, remainingUsd - execution.budgetDebitUsd);
2124
+ if (plan.chainFindings) upstreamFindings.push(...findings);
2125
+ if (lifecycleFailure !== void 0) {
2126
+ if (!exact) throw lifecycleFailure;
2127
+ executionFailure = lifecycleFailure;
2128
+ break;
2129
+ }
2130
+ const hookValues = snapshotAfterHookValues(summary, findings, exact);
2131
+ try {
2132
+ await waitForHook(plan.hooks.onAfterAnalyze ? () => plan.hooks.onAfterAnalyze?.({
2133
+ analyst,
2134
+ summary: hookValues.summary,
2135
+ findings: hookValues.findings,
2136
+ runId: plan.runId
2137
+ }) : void 0, executionSignal);
2138
+ } catch (error) {
2139
+ if (!exact) throw error;
2140
+ executionFailure = error;
2141
+ break;
2142
+ }
2143
+ yield snapshotExecutionEvent({
2144
+ type: "analyst-completed",
2145
+ summary,
2146
+ findings
2147
+ }, exact);
2148
+ if (exact && runSignal?.aborted) {
2149
+ executionFailure = abortReason(runSignal);
2150
+ break;
2151
+ }
2152
+ }
2153
+ const summaries = executions.map(({ summary }) => summary);
2154
+ const findings = executions.flatMap((execution) => execution.findings);
2155
+ const cost = executionCost(executions, exact);
2156
+ const baseResult = {
2157
+ run_id: plan.runId,
2158
+ correlation_id: correlationId,
2159
+ started_at: startedAt,
2160
+ ended_at: (/* @__PURE__ */ new Date()).toISOString(),
2161
+ findings,
2162
+ per_analyst: summaries,
2163
+ total_cost_usd: cost.known,
2164
+ total_cost_provenance: cost.provenance
2124
2165
  };
2125
- }
2126
- function exactPlannedAllocation(plan, analystId) {
2127
- const budget = plan.policy.budget;
2128
- if (budget.kind === "none") return void 0;
2129
- const allocated = budget.allocations_usd[analystId];
2130
- return allocated === null ? void 0 : allocated;
2131
- }
2132
- function snapshotExecutionEvent(event, exact) {
2133
- return exact ? canonicalJsonSnapshot(event, "AnalystRegistry.runExact event") : event;
2134
- }
2135
- function logUncapturedBudgetWarning(args) {
2136
- if (args.budgetUsd === void 0 || args.usage.cost.kind !== "uncaptured") return;
2137
- args.log(`[analyst] WARN ${args.analyst.id} — USD cost uncaptured; budget not reconciled`, {
2138
- runId: args.runId,
2139
- budget_usd: args.budgetUsd,
2140
- cost_captured: false
2141
- });
2142
- }
2143
- function validateTimeout(timeoutMs) {
2144
- if (timeoutMs === void 0) return void 0;
2145
- if (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0 || timeoutMs > 2147483647) throw new TypeError("RegistryRunOpts.timeoutMs must be a positive safe integer no greater than 2147483647");
2146
- return timeoutMs;
2166
+ if (plan.executionSnapshot === void 0) {
2167
+ await waitForHook(plan.hooks.onComplete ? () => plan.hooks.onComplete?.({ result: baseResult }) : void 0, runSignal);
2168
+ yield {
2169
+ type: "run-completed",
2170
+ result: baseResult
2171
+ };
2172
+ return;
2173
+ }
2174
+ let completeResult;
2175
+ if (executionFailure === void 0) try {
2176
+ completeResult = snapshotExactAnalystRunReceipt({
2177
+ ...baseResult,
2178
+ execution_plan: plan.executionSnapshot,
2179
+ completion: { status: "complete" }
2180
+ }, "AnalystRegistry.runExact result");
2181
+ await waitForHook(plan.hooks.onComplete ? () => plan.hooks.onComplete?.({ result: completeResult }) : void 0, runSignal);
2182
+ } catch (error) {
2183
+ executionFailure = error;
2184
+ }
2185
+ if (runSignal?.aborted) executionFailure ??= abortReason(runSignal);
2186
+ if (executionFailure === void 0 && completeResult) {
2187
+ yield snapshotExecutionEvent({
2188
+ type: "run-completed",
2189
+ result: completeResult
2190
+ }, true);
2191
+ return;
2192
+ }
2193
+ const cause = executionFailure instanceof Error ? executionFailure : new Error(String(executionFailure));
2194
+ const errorClass = cause.constructor.name || "Error";
2195
+ const errorMessage = cause.message.trim().length === 0 ? "Exact analyst run failed without a message" : cause.message;
2196
+ throw new ExactAnalystRunExecutionError(`exact analyst run failed after starting: ${errorMessage}; partial result is attached`, {
2197
+ ...baseResult,
2198
+ execution_plan: plan.executionSnapshot,
2199
+ completion: {
2200
+ status: "failed",
2201
+ error: {
2202
+ class: errorClass,
2203
+ message: errorMessage
2204
+ }
2205
+ }
2206
+ }, { cause });
2147
2207
  }
2148
2208
  async function waitForOperation(operation, signal, abortGraceMs) {
2149
2209
  if (!signal) return operation;
@@ -2211,137 +2271,7 @@ function abortedBeforeStartSummary(analyst, signal, latencyMs = 0) {
2211
2271
  function abortReason(signal) {
2212
2272
  return signal.reason instanceof Error ? signal.reason : new DOMException("The operation was aborted", "AbortError");
2213
2273
  }
2214
- /**
2215
- * Default budget allocator: prefer the custom `allocate` callback if
2216
- * provided; else weighted split when weights are set; else equal split
2217
- * across `runningCount`. Returns undefined when no totalUsd is known.
2218
- */
2219
- function allocateBudget(policy, args) {
2220
- if (!policy) return void 0;
2221
- if (policy.allocate) {
2222
- const allocated = policy.allocate({
2223
- analyst: args.analyst,
2224
- totalUsd: policy.totalUsd,
2225
- remainingUsd: args.remainingUsd,
2226
- runningCount: args.runningCount
2227
- });
2228
- if (allocated === void 0) {
2229
- if (policy.totalUsd !== void 0) throw new Error(`BudgetPolicy.allocate('${args.analyst.id}') cannot return undefined when totalUsd is set`);
2230
- return;
2231
- }
2232
- assertBudgetAmount(allocated, `BudgetPolicy.allocate('${args.analyst.id}')`);
2233
- return args.remainingUsd === void 0 ? allocated : Math.min(allocated, args.remainingUsd);
2234
- }
2235
- if (policy.totalUsd == null) return void 0;
2236
- const allocated = policy.weights ? policy.totalUsd * analystWeight(policy.weights, args.analyst.id) / args.totalWeight : policy.totalUsd / Math.max(1, args.runningCount);
2237
- return args.remainingUsd === void 0 ? allocated : Math.min(allocated, args.remainingUsd);
2238
- }
2239
- function validateBudgetPolicy(policy) {
2240
- if (!policy) return;
2241
- if (policy.totalUsd !== void 0) assertBudgetAmount(policy.totalUsd, "BudgetPolicy.totalUsd");
2242
- for (const [analystId, weight] of Object.entries(policy.weights ?? {})) assertBudgetAmount(weight, `BudgetPolicy.weights['${analystId}']`);
2243
- }
2244
- function assertBudgetAmount(value, field) {
2245
- if (!Number.isFinite(value) || value < 0) throw new Error(`${field} must be a non-negative finite number`);
2246
- }
2247
- function validateEffectiveBudget(budgetUsd, remainingUsd, analystId) {
2248
- if (budgetUsd !== void 0) assertBudgetAmount(budgetUsd, `AnalystContext.budgetUsd for '${analystId}'`);
2249
- if (remainingUsd === void 0) return budgetUsd;
2250
- if (budgetUsd === void 0) throw new Error(`AnalystContext.budgetUsd for '${analystId}' cannot be removed while an overall budget remains`);
2251
- if (budgetUsd > remainingUsd) throw new Error(`AnalystContext.budgetUsd for '${analystId}' (${budgetUsd}) exceeds the remaining overall budget (${remainingUsd})`);
2252
- return budgetUsd;
2253
- }
2254
- function analystWeight(weights, analystId) {
2255
- const weight = weights[analystId] ?? 1;
2256
- assertBudgetAmount(weight, `BudgetPolicy.weights['${analystId}']`);
2257
- return weight;
2258
- }
2259
- function zeroUsage() {
2260
- return {
2261
- calls: 0,
2262
- tokens: {
2263
- input: 0,
2264
- output: 0
2265
- },
2266
- cost: {
2267
- kind: "observed",
2268
- usd: 0
2269
- }
2270
- };
2271
- }
2272
- function resolveUsage(analyst, receipts, exact = false) {
2273
- if (receipts.length > 0) return mergeUsageReceipts(receipts, exact);
2274
- if (analyst.cost.kind === "deterministic") return zeroUsage();
2275
- return {
2276
- calls: null,
2277
- tokens: null,
2278
- cost: {
2279
- kind: "uncaptured",
2280
- usd: null
2281
- }
2282
- };
2283
- }
2284
- function mergeUsageReceipts(receipts, exact = false) {
2285
- const calls = receipts.every((receipt) => receipt.calls !== null) ? usageSum(receipts.map((receipt) => receipt.calls ?? 0), exact, "calls", true) : null;
2286
- const tokens = receipts.every((receipt) => receipt.tokens !== null) ? Object.fromEntries([
2287
- "input",
2288
- "output",
2289
- "reasoning",
2290
- "cached",
2291
- "cacheWrite"
2292
- ].flatMap((field) => field === "input" || field === "output" || receipts.some((receipt) => receipt.tokens?.[field] !== void 0) ? [[field, usageSum(receipts.map((receipt) => receipt.tokens?.[field] ?? 0), exact, `tokens.${field}`, true)]] : [])) : null;
2293
- const cost = aggregateCostProvenance(receipts.map((receipt) => receipt.cost), exact);
2294
- return {
2295
- calls,
2296
- tokens,
2297
- cost,
2298
- ...cost.kind === "uncaptured" ? { knownCostUsd: usageSum(receipts.map(knownCostUsd), exact, "known cost") } : {}
2299
- };
2300
- }
2301
- function knownCostUsd(receipt) {
2302
- return receipt.cost.kind === "uncaptured" ? receipt.knownCostUsd ?? 0 : receipt.cost.usd;
2303
- }
2304
- function budgetDebit(receipt, allocatedUsd) {
2305
- const known = knownCostUsd(receipt);
2306
- return receipt.cost.kind === "uncaptured" && allocatedUsd !== void 0 ? Math.max(known, allocatedUsd) : known;
2307
- }
2308
- function aggregateCostProvenance(costs, exact = false) {
2309
- if (costs.some((cost) => cost.kind === "uncaptured")) return {
2310
- kind: "uncaptured",
2311
- usd: null
2312
- };
2313
- const usd = usageSum(costs.map((cost) => cost.usd ?? 0), exact, "captured cost");
2314
- return costs.some((cost) => cost.kind === "estimated") ? {
2315
- kind: "estimated",
2316
- usd
2317
- } : {
2318
- kind: "observed",
2319
- usd
2320
- };
2321
- }
2322
- function executionCost(executions, exact) {
2323
- const usages = executions.map((execution) => execution.summary.usage);
2324
- return {
2325
- known: usageSum(usages.map(knownCostUsd), exact, "run known cost"),
2326
- provenance: aggregateCostProvenance(usages.map((usage) => usage.cost), exact)
2327
- };
2328
- }
2329
- function usageSum(values, exact, field, integer = false) {
2330
- const sum = values.reduce((total, value) => total + value, 0);
2331
- if (exact && (integer ? !Number.isSafeInteger(sum) : !Number.isFinite(sum))) throw new RangeError(`exact analyst usage ${field} aggregate ${integer ? "exceeds a safe integer" : "is not finite"}`);
2332
- return sum;
2333
- }
2334
- /**
2335
- * Resolve the `priorFindings` slice an analyst sees.
2336
- *
2337
- * - Array form → the analyst sees only findings whose `analyst_id`
2338
- * matches its own id, so a kind never reads
2339
- * another kind's history by accident.
2340
- * - Record form → the analyst gets the entry keyed by its id, with
2341
- * the `'*'` wildcard appended (in that order). Use
2342
- * the wildcard when several kinds should see the same
2343
- * historical findings.
2344
- */
2274
+ /** Return the analyst's own history, followed by any broadcast findings. */
2345
2275
  function selectPriorFindings(source, analystId) {
2346
2276
  if (!source) return void 0;
2347
2277
  if (Array.isArray(source)) {
@@ -2355,6 +2285,61 @@ function selectPriorFindings(source, analystId) {
2355
2285
  return merged.length > 0 ? merged : void 0;
2356
2286
  }
2357
2287
  //#endregion
2288
+ //#region src/analyst/registry.ts
2289
+ var AnalystRegistry = class {
2290
+ analysts = /* @__PURE__ */ new Map();
2291
+ options;
2292
+ constructor(options = {}) {
2293
+ this.options = options;
2294
+ }
2295
+ register(analyst) {
2296
+ const id = analyst.id;
2297
+ const version = analyst.version;
2298
+ const cost = analyst.cost;
2299
+ if (!id) throw new Error("AnalystRegistry.register: analyst.id is required");
2300
+ if (this.analysts.has(id)) throw new Error(`AnalystRegistry.register: duplicate analyst id "${id}"`);
2301
+ if (!version) throw new Error(`AnalystRegistry.register: analyst "${id}" must declare a version`);
2302
+ if (cost.kind === "deterministic" && cost.settlement_timeout_ms !== void 0) throw new TypeError(`AnalystRegistry.register: deterministic analyst "${id}" cannot declare settlement_timeout_ms`);
2303
+ if (cost.settlement_timeout_ms !== void 0) validateUsageSettlementTimeout(cost.settlement_timeout_ms);
2304
+ this.analysts.set(id, analyst);
2305
+ }
2306
+ list() {
2307
+ return Array.from(this.analysts.values()).map((a) => ({
2308
+ id: a.id,
2309
+ description: a.description,
2310
+ version: a.version,
2311
+ cost: a.cost
2312
+ }));
2313
+ }
2314
+ async run(runId, inputs, runOpts = {}) {
2315
+ for await (const ev of this.runStream(runId, inputs, runOpts)) if (ev.type === "run-completed") return ev.result;
2316
+ throw new Error("AnalystRegistry.run: stream completed without run-completed event");
2317
+ }
2318
+ /** Run exactly the ordered analysts and complete policy supplied by the caller. */
2319
+ async runExact(runId, inputs, runOpts) {
2320
+ for await (const ev of this.runExactStream(runId, inputs, runOpts)) if (ev.type === "run-completed") return ev.result;
2321
+ throw new Error("AnalystRegistry.runExact: stream completed without run-completed event");
2322
+ }
2323
+ /** Streaming counterpart to {@link runExact}. */
2324
+ async *runExactStream(runId, inputs, runOpts) {
2325
+ for await (const event of executePlanStream(normalizeExactPlan(runId, inputs, runOpts, this.analysts, this.options))) yield event;
2326
+ }
2327
+ /**
2328
+ * Streaming counterpart to `run()`. Emits `AnalystRunEvent` values
2329
+ * in real time — `run-started`, then per-analyst `skipped` /
2330
+ * `started` / `completed`, then a terminal `run-completed` whose
2331
+ * payload is the full `AnalystRunResult`. UIs use this to render
2332
+ * progress; persistence consumers use `run()` and read the result.
2333
+ *
2334
+ * Hooks (`onBeforeAnalyze` / `onAfterAnalyze` / `onError` /
2335
+ * `onComplete`) fire as before — streaming is additive, not a hook
2336
+ * replacement.
2337
+ */
2338
+ async *runStream(runId, inputs, runOpts = {}) {
2339
+ yield* executePlanStream(normalizeLegacyPlan(runId, inputs, runOpts, this.analysts, this.options));
2340
+ }
2341
+ };
2342
+ //#endregion
2358
2343
  //#region src/analyst/default-registry.ts
2359
2344
  function buildDefaultAnalystRegistry(options = {}) {
2360
2345
  if (options.definitions && !options.engine) throw new TypeError("buildDefaultAnalystRegistry: definitions require an engine — a definition cannot run without one");
@@ -2366,4 +2351,4 @@ function buildDefaultAnalystRegistry(options = {}) {
2366
2351
  //#endregion
2367
2352
  export { completedAnalystReviewQuality as _, KNOWLEDGE_POISONING_KIND_SPEC as a, validateAnalystReviewDecisions as b, FAILURE_MODE_KIND_SPEC as c, emitControlIntegrityFindings as d, behavioralAnalyst as f, assertUniqueFindingIds as g, analystRunDigest as h, DEFAULT_TRACE_ANALYST_KINDS as i, CONTROL_INTEGRITY_ANALYST as l, analystFindingDigest as m, AnalystRegistry as n, KNOWLEDGE_GAP_KIND_SPEC as o, deriveEfficiencyFindings as p, ExactAnalystRunExecutionError as r, IMPROVEMENT_KIND_SPEC as s, buildDefaultAnalystRegistry as t, ControlIntegrityAnalyst as u, readAnalystReview as v, snapshotAnalystRun as y };
2368
2353
 
2369
- //# sourceMappingURL=default-registry-KP4-Tolz.js.map
2354
+ //# sourceMappingURL=default-registry-COhk9g36.js.map