@tangle-network/agent-eval 0.129.0 → 0.130.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (427) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +1 -0
  3. package/dist/active-curriculum-C4mk67HP.js +214 -0
  4. package/dist/active-curriculum-C4mk67HP.js.map +1 -0
  5. package/dist/adversarial-smnADNFS.d.ts +21 -0
  6. package/dist/adversarial-smnADNFS.d.ts.map +1 -0
  7. package/dist/analyst/index.d.ts +81 -2872
  8. package/dist/analyst/index.d.ts.map +1 -0
  9. package/dist/analyst/index.js +319 -360
  10. package/dist/analyst/index.js.map +1 -1
  11. package/dist/analyst-BkTS3C58.d.ts +89 -0
  12. package/dist/analyst-BkTS3C58.d.ts.map +1 -0
  13. package/dist/analyst-LsnNpSkm.js +152 -0
  14. package/dist/analyst-LsnNpSkm.js.map +1 -0
  15. package/dist/analyze-runs-C1CavBMk.js +1067 -0
  16. package/dist/analyze-runs-C1CavBMk.js.map +1 -0
  17. package/dist/analyze-runs-FsgYCinh.d.ts +72 -0
  18. package/dist/analyze-runs-FsgYCinh.d.ts.map +1 -0
  19. package/dist/attribute-vocabulary-DLJ6303h.d.ts +54 -0
  20. package/dist/attribute-vocabulary-DLJ6303h.d.ts.map +1 -0
  21. package/dist/authenticity/index.d.ts +81 -79
  22. package/dist/authenticity/index.d.ts.map +1 -0
  23. package/dist/authenticity/index.js +209 -193
  24. package/dist/authenticity/index.js.map +1 -1
  25. package/dist/baseline-HsBvw_dk.js +550 -0
  26. package/dist/baseline-HsBvw_dk.js.map +1 -0
  27. package/dist/baseline-hG3K85h4.d.ts +125 -0
  28. package/dist/baseline-hG3K85h4.d.ts.map +1 -0
  29. package/dist/belief-state/index.d.ts +448 -1188
  30. package/dist/belief-state/index.d.ts.map +1 -0
  31. package/dist/belief-state/index.js +1617 -1709
  32. package/dist/belief-state/index.js.map +1 -1
  33. package/dist/benchmarks/index.d.ts +2 -891
  34. package/dist/benchmarks/index.js +2 -60
  35. package/dist/benchmarks-DviOvUNr.js +754 -0
  36. package/dist/benchmarks-DviOvUNr.js.map +1 -0
  37. package/dist/builder-eval/index.d.ts +150 -662
  38. package/dist/builder-eval/index.d.ts.map +1 -0
  39. package/dist/builder-eval/index.js +356 -345
  40. package/dist/builder-eval/index.js.map +1 -1
  41. package/dist/calibration-CNWWA6K8.js +94 -0
  42. package/dist/calibration-CNWWA6K8.js.map +1 -0
  43. package/dist/campaign/index.d.ts +5 -6381
  44. package/dist/campaign/index.js +3 -213
  45. package/dist/campaign-CBKZvQ1H.js +3885 -0
  46. package/dist/campaign-CBKZvQ1H.js.map +1 -0
  47. package/dist/cli.d.ts +1 -1
  48. package/dist/cli.js +164 -175
  49. package/dist/cli.js.map +1 -1
  50. package/dist/client-C97NMzqi.d.ts +581 -0
  51. package/dist/client-C97NMzqi.d.ts.map +1 -0
  52. package/dist/client-CYzbdJOZ.js +637 -0
  53. package/dist/client-CYzbdJOZ.js.map +1 -0
  54. package/dist/code-agent-session-BjkMTQ7H.js +1390 -0
  55. package/dist/code-agent-session-BjkMTQ7H.js.map +1 -0
  56. package/dist/code-agent-session-DqqgOJaz.d.ts +143 -0
  57. package/dist/code-agent-session-DqqgOJaz.d.ts.map +1 -0
  58. package/dist/concurrency-DIxRZF_J.js +85 -0
  59. package/dist/concurrency-DIxRZF_J.js.map +1 -0
  60. package/dist/contract/index.d.ts +645 -5565
  61. package/dist/contract/index.d.ts.map +1 -0
  62. package/dist/contract/index.js +1730 -1938
  63. package/dist/contract/index.js.map +1 -1
  64. package/dist/control.d.ts +3 -1030
  65. package/dist/control.js +2 -33
  66. package/dist/cost-ledger-DIgQUFZZ.js +801 -0
  67. package/dist/cost-ledger-DIgQUFZZ.js.map +1 -0
  68. package/dist/cost-ledger-Dye6jCgg.d.ts +236 -0
  69. package/dist/cost-ledger-Dye6jCgg.d.ts.map +1 -0
  70. package/dist/dataset-BvtnC8Dc.d.ts +115 -0
  71. package/dist/dataset-BvtnC8Dc.d.ts.map +1 -0
  72. package/dist/default-registry-C-vFCSEc.js +2579 -0
  73. package/dist/default-registry-C-vFCSEc.js.map +1 -0
  74. package/dist/default-registry-CNPo-Vsb.d.ts +540 -0
  75. package/dist/default-registry-CNPo-Vsb.d.ts.map +1 -0
  76. package/dist/emitter-CPBAhxum.js +266 -0
  77. package/dist/emitter-CPBAhxum.js.map +1 -0
  78. package/dist/emitter-DGQGoLyj.d.ts +113 -0
  79. package/dist/emitter-DGQGoLyj.d.ts.map +1 -0
  80. package/dist/errors-8YnH8WlF.js +64 -0
  81. package/dist/errors-8YnH8WlF.js.map +1 -0
  82. package/dist/errors-CEk209JS.d.ts +76 -0
  83. package/dist/errors-CEk209JS.d.ts.map +1 -0
  84. package/dist/eval-campaign-DEm6c8ru.js +349 -0
  85. package/dist/eval-campaign-DEm6c8ru.js.map +1 -0
  86. package/dist/execution-tracks-CpgFPpS5.js +93 -0
  87. package/dist/execution-tracks-CpgFPpS5.js.map +1 -0
  88. package/dist/exporters-q9iL-2Jf.js +148 -0
  89. package/dist/exporters-q9iL-2Jf.js.map +1 -0
  90. package/dist/extract-usage-BrQ8mCLX.js +155 -0
  91. package/dist/extract-usage-BrQ8mCLX.js.map +1 -0
  92. package/dist/failure-cluster-CqcvCcdR.d.ts +59 -0
  93. package/dist/failure-cluster-CqcvCcdR.d.ts.map +1 -0
  94. package/dist/feedback-trajectory-CVaeREXV.d.ts +340 -0
  95. package/dist/feedback-trajectory-CVaeREXV.d.ts.map +1 -0
  96. package/dist/fuzz.d.ts +320 -646
  97. package/dist/fuzz.d.ts.map +1 -0
  98. package/dist/fuzz.js +670 -618
  99. package/dist/fuzz.js.map +1 -1
  100. package/dist/hf-dataset-DBJXXoY1.js +763 -0
  101. package/dist/hf-dataset-DBJXXoY1.js.map +1 -0
  102. package/dist/hosted/index.d.ts +11 -831
  103. package/dist/hosted/index.d.ts.map +1 -0
  104. package/dist/hosted/index.js +2 -37
  105. package/dist/index-2JJSA6-r2.d.ts +926 -0
  106. package/dist/index-2JJSA6-r2.d.ts.map +1 -0
  107. package/dist/index-6N0aYmpW.d.ts +217 -0
  108. package/dist/index-6N0aYmpW.d.ts.map +1 -0
  109. package/dist/index-BAvgST_9.d.ts +131 -0
  110. package/dist/index-BAvgST_9.d.ts.map +1 -0
  111. package/dist/index-BvnJuTGD.d.ts +68 -0
  112. package/dist/index-BvnJuTGD.d.ts.map +1 -0
  113. package/dist/index-C61Wi7yg.d.ts +547 -0
  114. package/dist/index-C61Wi7yg.d.ts.map +1 -0
  115. package/dist/index-CAPUUKaM.d.ts +335 -0
  116. package/dist/index-CAPUUKaM.d.ts.map +1 -0
  117. package/dist/index-DE5fb3EC.d.ts +2244 -0
  118. package/dist/index-DE5fb3EC.d.ts.map +1 -0
  119. package/dist/index-DSC51roc.d.ts +102 -0
  120. package/dist/index-DSC51roc.d.ts.map +1 -0
  121. package/dist/index.d.ts +3755 -15555
  122. package/dist/index.d.ts.map +1 -0
  123. package/dist/index.js +11182 -11216
  124. package/dist/index.js.map +1 -1
  125. package/dist/integrity-BzRbCHzi.js +424 -0
  126. package/dist/integrity-BzRbCHzi.js.map +1 -0
  127. package/dist/integrity-rmVhXWA7.d.ts +61 -0
  128. package/dist/integrity-rmVhXWA7.d.ts.map +1 -0
  129. package/dist/judge-calibration-DFtEMlde.d.ts +146 -0
  130. package/dist/judge-calibration-DFtEMlde.d.ts.map +1 -0
  131. package/dist/ledger-core/index.d.ts +2 -0
  132. package/dist/ledger-core/index.js +2 -0
  133. package/dist/ledger-core-DtZz1RG0.js +388 -0
  134. package/dist/ledger-core-DtZz1RG0.js.map +1 -0
  135. package/dist/llm-client--GR4JbZE.js +687 -0
  136. package/dist/llm-client--GR4JbZE.js.map +1 -0
  137. package/dist/llm-client-B_nIBlYo.d.ts +290 -0
  138. package/dist/llm-client-B_nIBlYo.d.ts.map +1 -0
  139. package/dist/matrix/index.d.ts +3 -155
  140. package/dist/matrix/index.js +2 -8
  141. package/dist/matrix-BzQnu2S6.js +270 -0
  142. package/dist/matrix-BzQnu2S6.js.map +1 -0
  143. package/dist/meta-eval/index.d.ts +4 -1027
  144. package/dist/meta-eval/index.js +393 -390
  145. package/dist/meta-eval/index.js.map +1 -1
  146. package/dist/metrics-C9YY1OcL.js +239 -0
  147. package/dist/metrics-C9YY1OcL.js.map +1 -0
  148. package/dist/mint-yN2M2eh0.js +201 -0
  149. package/dist/mint-yN2M2eh0.js.map +1 -0
  150. package/dist/multi-layer-verifier-BHY1gWAc.d.ts +138 -0
  151. package/dist/multi-layer-verifier-BHY1gWAc.d.ts.map +1 -0
  152. package/dist/multishot/index.d.ts +273 -480
  153. package/dist/multishot/index.d.ts.map +1 -0
  154. package/dist/multishot/index.js +595 -548
  155. package/dist/multishot/index.js.map +1 -1
  156. package/dist/off-policy-DvgzvtIx.js +220 -0
  157. package/dist/off-policy-DvgzvtIx.js.map +1 -0
  158. package/dist/off-policy-mskQw8Mb.d.ts +153 -0
  159. package/dist/off-policy-mskQw8Mb.d.ts.map +1 -0
  160. package/dist/openapi.json +1 -1
  161. package/dist/opencode-sqlite-BGrHeDu3.js +318 -0
  162. package/dist/opencode-sqlite-BGrHeDu3.js.map +1 -0
  163. package/dist/outcome-store-BYHIuO0e.d.ts +65 -0
  164. package/dist/outcome-store-BYHIuO0e.d.ts.map +1 -0
  165. package/dist/outcome-store-ChBKlTd_.js +75 -0
  166. package/dist/outcome-store-ChBKlTd_.js.map +1 -0
  167. package/dist/paired-arms-D9D0wXj2.js +260 -0
  168. package/dist/paired-arms-D9D0wXj2.js.map +1 -0
  169. package/dist/pipelines/index.d.ts +95 -532
  170. package/dist/pipelines/index.d.ts.map +1 -0
  171. package/dist/pipelines/index.js +497 -478
  172. package/dist/pipelines/index.js.map +1 -1
  173. package/dist/pre-registration-DakwTRXk.js +96 -0
  174. package/dist/pre-registration-DakwTRXk.js.map +1 -0
  175. package/dist/propose-review-control-LhIWGzHl.js +1458 -0
  176. package/dist/propose-review-control-LhIWGzHl.js.map +1 -0
  177. package/dist/query-CJ_DX8vl.d.ts +28 -0
  178. package/dist/query-CJ_DX8vl.d.ts.map +1 -0
  179. package/dist/query-Di7eEQ79.js +83 -0
  180. package/dist/query-Di7eEQ79.js.map +1 -0
  181. package/dist/raw-provider-sink-BQd7mzyT.js +201 -0
  182. package/dist/raw-provider-sink-BQd7mzyT.js.map +1 -0
  183. package/dist/raw-provider-sink-BU29Sh8h.d.ts +134 -0
  184. package/dist/raw-provider-sink-BU29Sh8h.d.ts.map +1 -0
  185. package/dist/redact-7Aq1ukl-.js +107 -0
  186. package/dist/redact-7Aq1ukl-.js.map +1 -0
  187. package/dist/release-report-Cz9NKH39.js +603 -0
  188. package/dist/release-report-Cz9NKH39.js.map +1 -0
  189. package/dist/release-report-mvB2G4_J.d.ts +244 -0
  190. package/dist/release-report-mvB2G4_J.d.ts.map +1 -0
  191. package/dist/replay-GnyotH0J.js +1741 -0
  192. package/dist/replay-GnyotH0J.js.map +1 -0
  193. package/dist/replay-OoidtG1E.d.ts +749 -0
  194. package/dist/replay-OoidtG1E.d.ts.map +1 -0
  195. package/dist/reporting.d.ts +6 -1312
  196. package/dist/reporting.js +6 -51
  197. package/dist/researcher-CwTdwXG1.d.ts +314 -0
  198. package/dist/researcher-CwTdwXG1.d.ts.map +1 -0
  199. package/dist/reward-hacking-eAnOsynk.d.ts +224 -0
  200. package/dist/reward-hacking-eAnOsynk.d.ts.map +1 -0
  201. package/dist/reward-hacking-qipEpKvY.js +596 -0
  202. package/dist/reward-hacking-qipEpKvY.js.map +1 -0
  203. package/dist/reward-nw2xZGZG.js +137 -0
  204. package/dist/reward-nw2xZGZG.js.map +1 -0
  205. package/dist/rl.d.ts +760 -4010
  206. package/dist/rl.d.ts.map +1 -0
  207. package/dist/rl.js +2325 -1958
  208. package/dist/rl.js.map +1 -1
  209. package/dist/rolldown-runtime-8H4AJuhK.js +14 -0
  210. package/dist/rollout/index.d.ts +3 -2087
  211. package/dist/rollout/index.js +8 -168
  212. package/dist/rollout-BOYjemfR.js +624 -0
  213. package/dist/rollout-BOYjemfR.js.map +1 -0
  214. package/dist/rubric-predictive-validity-B3xmbmS1.js +141 -0
  215. package/dist/rubric-predictive-validity-B3xmbmS1.js.map +1 -0
  216. package/dist/rubric-predictive-validity-Ku_clp_1.d.ts +74 -0
  217. package/dist/rubric-predictive-validity-Ku_clp_1.d.ts.map +1 -0
  218. package/dist/run-evidence-ClRX_8A9.d.ts +225 -0
  219. package/dist/run-evidence-ClRX_8A9.d.ts.map +1 -0
  220. package/dist/run-record-BuoE80Dq.js +467 -0
  221. package/dist/{chunk-56TAVBOK.js.map → run-record-BuoE80Dq.js.map} +1 -1
  222. package/dist/run-record-CnZu_gjl.d.ts +357 -0
  223. package/dist/run-record-CnZu_gjl.d.ts.map +1 -0
  224. package/dist/run-score-iEEAWiBY.js +41 -0
  225. package/dist/run-score-iEEAWiBY.js.map +1 -0
  226. package/dist/runtime-trajectory-1gyaTOoC.js +93 -0
  227. package/dist/runtime-trajectory-1gyaTOoC.js.map +1 -0
  228. package/dist/runtime-trajectory-BvSZcCHD.d.ts +50 -0
  229. package/dist/runtime-trajectory-BvSZcCHD.d.ts.map +1 -0
  230. package/dist/schema-BtVldJ3T.d.ts +206 -0
  231. package/dist/schema-BtVldJ3T.d.ts.map +1 -0
  232. package/dist/schema-C6DW4ZHR.js +821 -0
  233. package/dist/schema-C6DW4ZHR.js.map +1 -0
  234. package/dist/schema-CRhEY1SO.js +69 -0
  235. package/dist/schema-CRhEY1SO.js.map +1 -0
  236. package/dist/schema-Cef2cFmb.d.ts +408 -0
  237. package/dist/schema-Cef2cFmb.d.ts.map +1 -0
  238. package/dist/semantic-concept-judge-B6cWNJ2K.js +725 -0
  239. package/dist/semantic-concept-judge-B6cWNJ2K.js.map +1 -0
  240. package/dist/sequential-Br0mAPHA.js +148 -0
  241. package/dist/sequential-Br0mAPHA.js.map +1 -0
  242. package/dist/sequential-CYwq6Ff_.d.ts +141 -0
  243. package/dist/sequential-CYwq6Ff_.d.ts.map +1 -0
  244. package/dist/series-convergence-CjO2QdRW.js +43 -0
  245. package/dist/series-convergence-CjO2QdRW.js.map +1 -0
  246. package/dist/series-convergence-ofsqPWhs.d.ts +35 -0
  247. package/dist/series-convergence-ofsqPWhs.d.ts.map +1 -0
  248. package/dist/server-m5D9cvnG.js +1040 -0
  249. package/dist/server-m5D9cvnG.js.map +1 -0
  250. package/dist/skill-usage-C_pXm7lP.d.ts +534 -0
  251. package/dist/skill-usage-C_pXm7lP.d.ts.map +1 -0
  252. package/dist/skillopt-optimization-method-B7wX7XkF.d.ts +1739 -0
  253. package/dist/skillopt-optimization-method-B7wX7XkF.d.ts.map +1 -0
  254. package/dist/skillopt-optimization-method-D4ODwFVV.js +7712 -0
  255. package/dist/skillopt-optimization-method-D4ODwFVV.js.map +1 -0
  256. package/dist/statistics-Cmj6nynr.d.ts +514 -0
  257. package/dist/statistics-Cmj6nynr.d.ts.map +1 -0
  258. package/dist/statistics-CnnxdpOg.js +1437 -0
  259. package/dist/statistics-CnnxdpOg.js.map +1 -0
  260. package/dist/store-CT9YIIve.d.ts +117 -0
  261. package/dist/store-CT9YIIve.d.ts.map +1 -0
  262. package/dist/store-CxJry_cs.d.ts +229 -0
  263. package/dist/store-CxJry_cs.d.ts.map +1 -0
  264. package/dist/storyboard/index.d.ts +84 -203
  265. package/dist/storyboard/index.d.ts.map +1 -0
  266. package/dist/storyboard/index.js +609 -542
  267. package/dist/storyboard/index.js.map +1 -1
  268. package/dist/summary-report-BNs5nmXI.js +862 -0
  269. package/dist/summary-report-BNs5nmXI.js.map +1 -0
  270. package/dist/summary-report-Cj9gdw4i.d.ts +407 -0
  271. package/dist/summary-report-Cj9gdw4i.d.ts.map +1 -0
  272. package/dist/supervisor-run/index.d.ts +2 -959
  273. package/dist/supervisor-run/index.js +2 -65
  274. package/dist/supervisor-run-_lnTLM3z.js +1679 -0
  275. package/dist/supervisor-run-_lnTLM3z.js.map +1 -0
  276. package/dist/task-failure-attributes-CQZlB3et.js +311 -0
  277. package/dist/task-failure-attributes-CQZlB3et.js.map +1 -0
  278. package/dist/test-graded-scenario-BsqWLmPt.js +318 -0
  279. package/dist/test-graded-scenario-BsqWLmPt.js.map +1 -0
  280. package/dist/test-graded-scenario-D1TaI2va.d.ts +141 -0
  281. package/dist/test-graded-scenario-D1TaI2va.d.ts.map +1 -0
  282. package/dist/tools-BmuN627J.js +1085 -0
  283. package/dist/tools-BmuN627J.js.map +1 -0
  284. package/dist/trace-attributes.d.ts +2 -52
  285. package/dist/trace-attributes.js +131 -61
  286. package/dist/trace-attributes.js.map +1 -1
  287. package/dist/traces.d.ts +12 -2365
  288. package/dist/traces.js +12 -252
  289. package/dist/trajectory-D_7rLrvE.js +56 -0
  290. package/dist/trajectory-D_7rLrvE.js.map +1 -0
  291. package/dist/types-DGsxbAEd.d.ts +387 -0
  292. package/dist/types-DGsxbAEd.d.ts.map +1 -0
  293. package/dist/types-k9tZGKUg.d.ts +640 -0
  294. package/dist/types-k9tZGKUg.d.ts.map +1 -0
  295. package/dist/verdict-Dps8_okt.d.ts +37 -0
  296. package/dist/verdict-Dps8_okt.d.ts.map +1 -0
  297. package/dist/wire/index.d.ts +702 -1173
  298. package/dist/wire/index.d.ts.map +1 -0
  299. package/dist/wire/index.js +2 -81
  300. package/package.json +17 -9
  301. package/dist/benchmarks/index.js.map +0 -1
  302. package/dist/campaign/index.js.map +0 -1
  303. package/dist/chunk-2QU3YOPR.js +0 -7374
  304. package/dist/chunk-2QU3YOPR.js.map +0 -1
  305. package/dist/chunk-3OCR4R5I.js +0 -728
  306. package/dist/chunk-3OCR4R5I.js.map +0 -1
  307. package/dist/chunk-3RF76KTD.js +0 -84
  308. package/dist/chunk-3RF76KTD.js.map +0 -1
  309. package/dist/chunk-56TAVBOK.js +0 -698
  310. package/dist/chunk-5DTSBUL2.js +0 -159
  311. package/dist/chunk-5DTSBUL2.js.map +0 -1
  312. package/dist/chunk-7FO3TNPI.js +0 -232
  313. package/dist/chunk-7FO3TNPI.js.map +0 -1
  314. package/dist/chunk-7ZZMD7UK.js +0 -386
  315. package/dist/chunk-7ZZMD7UK.js.map +0 -1
  316. package/dist/chunk-BOD4O7OF.js +0 -40
  317. package/dist/chunk-BOD4O7OF.js.map +0 -1
  318. package/dist/chunk-BSO5JDQH.js +0 -2335
  319. package/dist/chunk-BSO5JDQH.js.map +0 -1
  320. package/dist/chunk-C6LXANRU.js +0 -1550
  321. package/dist/chunk-C6LXANRU.js.map +0 -1
  322. package/dist/chunk-DODXQREJ.js +0 -752
  323. package/dist/chunk-DODXQREJ.js.map +0 -1
  324. package/dist/chunk-DRYIUNWY.js +0 -622
  325. package/dist/chunk-DRYIUNWY.js.map +0 -1
  326. package/dist/chunk-E7QXT7SX.js +0 -183
  327. package/dist/chunk-E7QXT7SX.js.map +0 -1
  328. package/dist/chunk-EG66UGL4.js +0 -341
  329. package/dist/chunk-EG66UGL4.js.map +0 -1
  330. package/dist/chunk-FXTVJPYD.js +0 -576
  331. package/dist/chunk-FXTVJPYD.js.map +0 -1
  332. package/dist/chunk-G7MGMCZD.js +0 -153
  333. package/dist/chunk-G7MGMCZD.js.map +0 -1
  334. package/dist/chunk-GGE4NNQT.js +0 -65
  335. package/dist/chunk-GGE4NNQT.js.map +0 -1
  336. package/dist/chunk-H23X7XKK.js +0 -181
  337. package/dist/chunk-H23X7XKK.js.map +0 -1
  338. package/dist/chunk-HHWE3POT.js +0 -94
  339. package/dist/chunk-HHWE3POT.js.map +0 -1
  340. package/dist/chunk-HPWUNB47.js +0 -289
  341. package/dist/chunk-HPWUNB47.js.map +0 -1
  342. package/dist/chunk-IYCLP2N2.js +0 -766
  343. package/dist/chunk-IYCLP2N2.js.map +0 -1
  344. package/dist/chunk-JHCHEVET.js +0 -274
  345. package/dist/chunk-JHCHEVET.js.map +0 -1
  346. package/dist/chunk-JQSF5DQT.js +0 -701
  347. package/dist/chunk-JQSF5DQT.js.map +0 -1
  348. package/dist/chunk-K4DBDHLK.js +0 -158
  349. package/dist/chunk-K4DBDHLK.js.map +0 -1
  350. package/dist/chunk-K6N6XJJX.js +0 -306
  351. package/dist/chunk-K6N6XJJX.js.map +0 -1
  352. package/dist/chunk-M4YBQKIJ.js +0 -1040
  353. package/dist/chunk-M4YBQKIJ.js.map +0 -1
  354. package/dist/chunk-MA6HLL3S.js +0 -65
  355. package/dist/chunk-MA6HLL3S.js.map +0 -1
  356. package/dist/chunk-MAZ26DC7.js +0 -99
  357. package/dist/chunk-MAZ26DC7.js.map +0 -1
  358. package/dist/chunk-NPCTHQIO.js +0 -91
  359. package/dist/chunk-NPCTHQIO.js.map +0 -1
  360. package/dist/chunk-NY44NC4A.js +0 -1056
  361. package/dist/chunk-NY44NC4A.js.map +0 -1
  362. package/dist/chunk-OIUOT4QD.js +0 -44
  363. package/dist/chunk-OIUOT4QD.js.map +0 -1
  364. package/dist/chunk-ONWEPEDO.js +0 -57
  365. package/dist/chunk-ONWEPEDO.js.map +0 -1
  366. package/dist/chunk-OWN5NPMC.js +0 -152
  367. package/dist/chunk-OWN5NPMC.js.map +0 -1
  368. package/dist/chunk-P6FYH6K4.js +0 -1161
  369. package/dist/chunk-P6FYH6K4.js.map +0 -1
  370. package/dist/chunk-PC4UYEBM.js +0 -166
  371. package/dist/chunk-PC4UYEBM.js.map +0 -1
  372. package/dist/chunk-PC5DOSM7.js +0 -579
  373. package/dist/chunk-PC5DOSM7.js.map +0 -1
  374. package/dist/chunk-PXE2VKMX.js +0 -140
  375. package/dist/chunk-PXE2VKMX.js.map +0 -1
  376. package/dist/chunk-PZ5AY32C.js +0 -10
  377. package/dist/chunk-PZ5AY32C.js.map +0 -1
  378. package/dist/chunk-QB6BDBP2.js +0 -4464
  379. package/dist/chunk-QB6BDBP2.js.map +0 -1
  380. package/dist/chunk-RXHCETDZ.js +0 -536
  381. package/dist/chunk-RXHCETDZ.js.map +0 -1
  382. package/dist/chunk-RZTMDUO7.js +0 -49
  383. package/dist/chunk-RZTMDUO7.js.map +0 -1
  384. package/dist/chunk-SFLLL76A.js +0 -669
  385. package/dist/chunk-SFLLL76A.js.map +0 -1
  386. package/dist/chunk-SZLVEKMJ.js +0 -1446
  387. package/dist/chunk-SZLVEKMJ.js.map +0 -1
  388. package/dist/chunk-T4SQEITX.js +0 -95
  389. package/dist/chunk-T4SQEITX.js.map +0 -1
  390. package/dist/chunk-T6RLYGAD.js +0 -158
  391. package/dist/chunk-T6RLYGAD.js.map +0 -1
  392. package/dist/chunk-TJVT4QFF.js +0 -911
  393. package/dist/chunk-TJVT4QFF.js.map +0 -1
  394. package/dist/chunk-TQ7LNKZ3.js +0 -136
  395. package/dist/chunk-TQ7LNKZ3.js.map +0 -1
  396. package/dist/chunk-U4L7JRPZ.js +0 -1706
  397. package/dist/chunk-U4L7JRPZ.js.map +0 -1
  398. package/dist/chunk-U4PHLT2N.js +0 -419
  399. package/dist/chunk-U4PHLT2N.js.map +0 -1
  400. package/dist/chunk-VCZ5FQYW.js +0 -928
  401. package/dist/chunk-VCZ5FQYW.js.map +0 -1
  402. package/dist/chunk-VI2UW6B6.js +0 -162
  403. package/dist/chunk-VI2UW6B6.js.map +0 -1
  404. package/dist/chunk-VQMK5FMP.js +0 -247
  405. package/dist/chunk-VQMK5FMP.js.map +0 -1
  406. package/dist/chunk-WGXIEX7P.js +0 -116
  407. package/dist/chunk-WGXIEX7P.js.map +0 -1
  408. package/dist/chunk-WVATSFCP.js +0 -1553
  409. package/dist/chunk-WVATSFCP.js.map +0 -1
  410. package/dist/chunk-X4YIBDER.js +0 -1662
  411. package/dist/chunk-X4YIBDER.js.map +0 -1
  412. package/dist/chunk-YQN4ICPP.js +0 -355
  413. package/dist/chunk-YQN4ICPP.js.map +0 -1
  414. package/dist/chunk-ZET2UAYW.js +0 -89
  415. package/dist/chunk-ZET2UAYW.js.map +0 -1
  416. package/dist/chunk-ZHTZ4EYI.js +0 -1212
  417. package/dist/chunk-ZHTZ4EYI.js.map +0 -1
  418. package/dist/control.js.map +0 -1
  419. package/dist/hosted/index.js.map +0 -1
  420. package/dist/matrix/index.js.map +0 -1
  421. package/dist/reporting.js.map +0 -1
  422. package/dist/rollout/index.js.map +0 -1
  423. package/dist/run-campaign-OJJ7CZF4.js +0 -18
  424. package/dist/run-campaign-OJJ7CZF4.js.map +0 -1
  425. package/dist/supervisor-run/index.js.map +0 -1
  426. package/dist/traces.js.map +0 -1
  427. package/dist/wire/index.js.map +0 -1
@@ -1,1662 +0,0 @@
1
- import {
2
- DEFAULT_OPENCODE_DB,
3
- findOpencodeSessionsByDirectory,
4
- openOpencodeDb,
5
- parseClaudeEntries,
6
- transcriptFromEntries
7
- } from "./chunk-HPWUNB47.js";
8
- import {
9
- ROLLOUT_SCHEMA,
10
- isRolloutLine
11
- } from "./chunk-PC5DOSM7.js";
12
- import {
13
- unscreenedRewardFields
14
- } from "./chunk-OIUOT4QD.js";
15
-
16
- // src/supervisor-run/types.ts
17
- function unavailable(reason) {
18
- return { unavailable: reason };
19
- }
20
- function isUnavailable(v) {
21
- return typeof v === "object" && v !== null && typeof v.unavailable === "string";
22
- }
23
- function showMeasured(v) {
24
- if (isUnavailable(v)) return `unavailable \u2014 ${v.unavailable}`;
25
- if (v === null) return "null";
26
- return String(v);
27
- }
28
- var NO_SOURCE_LIMITS = {
29
- spendUsd: null,
30
- workerVerdicts: null,
31
- deliverables: null
32
- };
33
- var SUPERVISOR_RUN_SCHEMA = "tangle.supervisor-run@1";
34
- var SUPERVISOR_RUN_ROLLUP_SCHEMA = "tangle.supervisor-run-rollup@1";
35
-
36
- // src/supervisor-run/analyze.ts
37
- function asRecord(v) {
38
- return typeof v === "object" && v !== null ? v : {};
39
- }
40
- function num(v) {
41
- return typeof v === "number" && Number.isFinite(v) ? v : 0;
42
- }
43
- function readSpend(v) {
44
- const rec = asRecord(v);
45
- const tok = asRecord(rec.tokens);
46
- const cacheRead = tok.cacheRead ?? tok.cache_read;
47
- const cacheWrite = tok.cacheWrite ?? tok.cache_write;
48
- return {
49
- tokens: {
50
- input: num(tok.input),
51
- output: num(tok.output),
52
- cacheRead: num(cacheRead),
53
- cacheWrite: num(cacheWrite),
54
- hasCache: cacheRead !== void 0 || cacheWrite !== void 0
55
- },
56
- usd: num(rec.usd)
57
- };
58
- }
59
- var NO_CACHE_COUNTERS = "the journal carries no cache-token counters for this role";
60
- function parseJsonl(text) {
61
- if (text === null) return [];
62
- const out = [];
63
- for (const line2 of text.split("\n")) {
64
- const trimmed = line2.trim();
65
- if (!trimmed) continue;
66
- try {
67
- const parsed = JSON.parse(trimmed);
68
- if (typeof parsed === "object" && parsed !== null) out.push(parsed);
69
- } catch {
70
- }
71
- }
72
- return out;
73
- }
74
- function parseJson(text) {
75
- if (text === null) return null;
76
- try {
77
- const parsed = JSON.parse(text);
78
- return typeof parsed === "object" && parsed !== null ? parsed : null;
79
- } catch {
80
- return null;
81
- }
82
- }
83
- function ms(at) {
84
- if (typeof at !== "string") return null;
85
- const t = Date.parse(at);
86
- return Number.isFinite(t) ? t : null;
87
- }
88
- function parseSupervisorTree(src) {
89
- const events = parseJsonl(src.journal);
90
- const state = parseJson(src.state);
91
- const spawns = [];
92
- const closes = [];
93
- let brainIn = 0;
94
- let brainOut = 0;
95
- let brainCacheRead = 0;
96
- let brainCacheWrite = 0;
97
- let brainHasCache = false;
98
- let brainUsd = 0;
99
- let meteredCount = 0;
100
- let rootId = null;
101
- for (const ev of events) {
102
- const kind = typeof ev.kind === "string" ? ev.kind : "";
103
- const id = typeof ev.id === "string" ? ev.id : "";
104
- if (kind === "spawned") {
105
- const parent = typeof ev.parent === "string" ? ev.parent : null;
106
- const label = typeof ev.label === "string" ? ev.label : "";
107
- if (parent === null && rootId === null) rootId = id;
108
- spawns.push({ id, parent, label, at: ms(ev.at) });
109
- } else if (kind === "settled") {
110
- closes.push({
111
- id,
112
- kind: "settled",
113
- status: typeof ev.status === "string" ? ev.status : null,
114
- verdict: typeof ev.verdict === "string" ? ev.verdict : null,
115
- at: ms(ev.at),
116
- spend: readSpend(ev.spent),
117
- hasSpend: asRecord(ev.spent).tokens !== void 0
118
- });
119
- } else if (kind === "cancelled") {
120
- closes.push({
121
- id,
122
- kind: "cancelled",
123
- status: "cancelled",
124
- verdict: typeof ev.reason === "string" ? ev.reason : null,
125
- at: ms(ev.at),
126
- spend: {
127
- tokens: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, hasCache: false },
128
- usd: 0
129
- },
130
- hasSpend: false
131
- });
132
- } else if (kind === "metered") {
133
- const s = readSpend(ev.spend);
134
- brainIn += s.tokens.input;
135
- brainOut += s.tokens.output;
136
- brainCacheRead += s.tokens.cacheRead;
137
- brainCacheWrite += s.tokens.cacheWrite;
138
- brainHasCache = brainHasCache || s.tokens.hasCache;
139
- brainUsd += s.usd;
140
- meteredCount += 1;
141
- }
142
- }
143
- const workerSpawns = spawns.filter((s) => s.id !== rootId);
144
- const workerIds = new Set(workerSpawns.map((s) => s.id));
145
- const workerCloses = closes.filter((c) => workerIds.has(c.id));
146
- const workerLogs = /* @__PURE__ */ new Map();
147
- for (const w of src.workers ?? []) {
148
- const facts = {
149
- started: null,
150
- finished: false,
151
- finishedAt: null,
152
- passed: null,
153
- finishedPatchBytes: null,
154
- evidenceBytes: 0,
155
- steersQueued: 0,
156
- steersDelivered: 0,
157
- questions: 0
158
- };
159
- for (const req of parseJsonl(w.inbox)) {
160
- if (typeof req.message === "string" && req.message.trim().length > 0) facts.steersQueued += 1;
161
- }
162
- for (const ev of parseJsonl(w.events)) {
163
- const kind = ev.kind;
164
- if (kind === "message") {
165
- if (ev.direction === "up") {
166
- facts.questions += 1;
167
- continue;
168
- }
169
- if (typeof ev.requestId !== "string") facts.steersQueued += 1;
170
- if (ev.delivered === true) facts.steersDelivered += 1;
171
- } else if (kind === "started") {
172
- facts.started = ms(ev.at);
173
- } else if (kind === "finished") {
174
- facts.finished = true;
175
- facts.finishedAt = ms(ev.at);
176
- facts.passed = typeof ev.passed === "boolean" ? ev.passed : null;
177
- facts.finishedPatchBytes = typeof ev.patchBytes === "number" ? ev.patchBytes : null;
178
- facts.evidenceBytes = typeof ev.evidence === "string" ? ev.evidence.length : 0;
179
- }
180
- }
181
- workerLogs.set(w.label, facts);
182
- }
183
- const startedAt = ms(state?.startedAt) ?? spawns[0]?.at ?? null;
184
- const completedAt = ms(state?.completedAt) ?? [...spawns.map((s) => s.at), ...closes.map((c) => c.at)].reduce(
185
- (acc, t) => t === null ? acc : acc === null ? t : Math.max(acc, t),
186
- null
187
- );
188
- return {
189
- rootId,
190
- spawns,
191
- closes,
192
- workerSpawns,
193
- workerCloses,
194
- brain: {
195
- tokensIn: brainIn,
196
- tokensOut: brainOut,
197
- cacheRead: brainCacheRead,
198
- cacheWrite: brainCacheWrite,
199
- hasCache: brainHasCache,
200
- usd: brainUsd,
201
- meteredCount
202
- },
203
- workerLogs,
204
- startedAt,
205
- completedAt
206
- };
207
- }
208
- function analyzeSupervisorRunSources(src, now = Date.now) {
209
- const gaps = [];
210
- const gap = (what, reason) => {
211
- gaps.push(`${what}: ${reason}`);
212
- return unavailable(reason);
213
- };
214
- const journalMissing = src.supRunDir === null ? "no supervisor run dir under <ws>/.loops/supervisor" : "journal.jsonl absent";
215
- const haveJournal = src.journal !== null;
216
- const state = parseJson(src.state);
217
- const result = parseJson(src.result);
218
- const judge = parseJson(src.judge);
219
- const tree = parseSupervisorTree(src);
220
- const { rootId, workerSpawns, workerCloses, startedAt, completedAt } = tree;
221
- const supervisorWallMs = startedAt !== null && completedAt !== null && completedAt >= startedAt ? completedAt - startedAt : !haveJournal ? gap("supervisorWallMs", journalMissing) : gap("supervisorWallMs", "no parseable start/complete timestamps in state.json or journal");
222
- const steerRows = [];
223
- let steerQueuedTotal = 0;
224
- let steerDeliveredTotal = 0;
225
- let upLegMessages = 0;
226
- if (src.workers !== null) {
227
- for (const w of src.workers) {
228
- const facts = tree.workerLogs.get(w.label);
229
- const queued = facts?.steersQueued ?? 0;
230
- const delivered = facts?.steersDelivered ?? 0;
231
- upLegMessages += facts?.questions ?? 0;
232
- steerRows.push({ worker: w.label, queued, delivered });
233
- steerQueuedTotal += queued;
234
- steerDeliveredTotal += delivered;
235
- }
236
- }
237
- const workersGapReason = src.workersMissingReason ?? "workers/ directory absent";
238
- const steers = src.workers === null ? gap("steers", workersGapReason) : steerQueuedTotal;
239
- const steersDelivered = src.workers === null ? unavailable(workersGapReason) : steerDeliveredTotal;
240
- const steersByWorker = src.workers === null ? unavailable(workersGapReason) : steerRows;
241
- const driverSteerCalls = src.driverLog === null ? gap("driverSteerCalls", "driver.log absent") : Math.max(
242
- 0,
243
- (src.driverLog.match(/supervisor_steer/g) ?? []).length - registrationMentions(src.driverLog)
244
- );
245
- const timeline = [];
246
- for (const s of workerSpawns) if (s.at !== null) timeline.push({ at: s.at, delta: 1 });
247
- for (const c of workerCloses) if (c.at !== null) timeline.push({ at: c.at, delta: -1 });
248
- timeline.sort((a, b) => a.at - b.at || a.delta - b.delta);
249
- let waves = 0;
250
- const waveSizes = [];
251
- let closedSinceWaveStart = true;
252
- for (const step of timeline) {
253
- if (step.delta === 1) {
254
- if (closedSinceWaveStart) {
255
- waves += 1;
256
- waveSizes.push(0);
257
- closedSinceWaveStart = false;
258
- }
259
- waveSizes[waveSizes.length - 1] = (waveSizes[waveSizes.length - 1] ?? 0) + 1;
260
- } else {
261
- closedSinceWaveStart = true;
262
- }
263
- }
264
- let live = 0;
265
- let maxConcurrency = 0;
266
- let idleMs = 0;
267
- let sumWorkerWallMs = 0;
268
- let prev = startedAt;
269
- for (const step of timeline) {
270
- if (prev !== null && step.at >= prev) {
271
- const span = step.at - prev;
272
- if (live === 0) idleMs += span;
273
- sumWorkerWallMs += span * live;
274
- }
275
- live += step.delta;
276
- if (live > maxConcurrency) maxConcurrency = live;
277
- prev = step.at;
278
- }
279
- if (prev !== null && completedAt !== null && completedAt >= prev) {
280
- const span = completedAt - prev;
281
- if (live === 0) idleMs += span;
282
- sumWorkerWallMs += span * live;
283
- }
284
- const firstWorkerSpawnAt = workerSpawns.reduce(
285
- (acc, s) => s.at === null ? acc : acc === null ? s.at : Math.min(acc, s.at),
286
- null
287
- );
288
- const firstSettleAt = workerCloses.reduce(
289
- (acc, c) => c.at === null ? acc : acc === null ? c.at : Math.min(acc, c.at),
290
- null
291
- );
292
- const respawns = firstSettleAt === null ? 0 : workerSpawns.filter((s) => s.at !== null && s.at > firstSettleAt).length;
293
- const labelCounts = /* @__PURE__ */ new Map();
294
- for (const s of workerSpawns) labelCounts.set(s.label, (labelCounts.get(s.label) ?? 0) + 1);
295
- const repeatedLabels = [...labelCounts.entries()].filter(([, n]) => n > 1).map(([l]) => l);
296
- const parentOf = new Map(tree.spawns.map((s) => [s.id, s.parent]));
297
- let delegationDepth = 0;
298
- for (const s of workerSpawns) {
299
- let d = 0;
300
- let cur = s.id;
301
- const seen = /* @__PURE__ */ new Set();
302
- while (cur !== null && cur !== rootId && !seen.has(cur)) {
303
- seen.add(cur);
304
- d += 1;
305
- cur = parentOf.get(cur) ?? null;
306
- }
307
- if (d > delegationDepth) delegationDepth = d;
308
- }
309
- const orchestration = {
310
- workersSpawned: haveJournal ? workerSpawns.length : gap("workersSpawned", journalMissing),
311
- workersSettled: haveJournal ? workerCloses.filter((c) => c.kind === "settled").length : unavailable(journalMissing),
312
- workersCancelled: haveJournal ? workerCloses.filter((c) => c.kind === "cancelled").length : unavailable(journalMissing),
313
- steers,
314
- steersDelivered,
315
- steersByWorker,
316
- driverSteerCalls,
317
- waves: haveJournal ? waves : unavailable(journalMissing),
318
- waveSizes: haveJournal ? waveSizes : unavailable(journalMissing),
319
- maxConcurrency: haveJournal ? maxConcurrency : unavailable(journalMissing),
320
- respawns: haveJournal ? respawns : unavailable(journalMissing),
321
- repeatedLabels: haveJournal ? repeatedLabels : unavailable(journalMissing),
322
- delegationDepth: haveJournal ? delegationDepth : unavailable(journalMissing),
323
- timeToFirstSpawnMs: startedAt !== null && firstWorkerSpawnAt !== null ? firstWorkerSpawnAt - startedAt : haveJournal ? unavailable("no worker spawn timestamps") : unavailable(journalMissing),
324
- supervisorWallMs,
325
- idleMs: isUnavailable(supervisorWallMs) ? unavailable(supervisorWallMs.unavailable) : idleMs,
326
- idlePct: isUnavailable(supervisorWallMs) || supervisorWallMs === 0 ? isUnavailable(supervisorWallMs) ? unavailable(supervisorWallMs.unavailable) : unavailable("supervisor wall is 0ms") : round(idleMs / supervisorWallMs * 100, 1),
327
- workerUtilization: isUnavailable(supervisorWallMs) || supervisorWallMs === 0 ? isUnavailable(supervisorWallMs) ? unavailable(supervisorWallMs.unavailable) : unavailable("supervisor wall is 0ms") : round(sumWorkerWallMs / supervisorWallMs, 3)
328
- };
329
- const settledByStatus = {};
330
- const settledVerdicts = {};
331
- for (const c of workerCloses) {
332
- const key = c.status ?? "unknown";
333
- settledByStatus[key] = (settledByStatus[key] ?? 0) + 1;
334
- if (c.verdict !== null) settledVerdicts[c.verdict] = (settledVerdicts[c.verdict] ?? 0) + 1;
335
- }
336
- const verdictLimit = src.limits.workerVerdicts;
337
- let accepted = 0;
338
- let rejected = 0;
339
- let emptyPass = 0;
340
- let evidenceBytes = 0;
341
- for (const w of src.workers ?? []) {
342
- const f = tree.workerLogs.get(w.label);
343
- if (f === void 0 || !f.finished) continue;
344
- evidenceBytes += f.evidenceBytes;
345
- if (f.passed === true) {
346
- if ((f.finishedPatchBytes ?? 0) > 0) accepted += 1;
347
- else emptyPass += 1;
348
- } else if (f.passed === false) rejected += 1;
349
- }
350
- let observeThenRespawn = 0;
351
- let respawnWithoutEvidence = 0;
352
- const spawnTimes = workerSpawns.map((s) => s.at).filter((t) => t !== null).sort((a, b) => a - b);
353
- const closeTimes = workerCloses.map((c) => c.at).filter((t) => t !== null).sort((a, b) => a - b);
354
- for (let i = 1; i < spawnTimes.length; i += 1) {
355
- const prevSpawn = spawnTimes[i - 1];
356
- const thisSpawn = spawnTimes[i];
357
- const sawEvidence = closeTimes.some((t) => t >= prevSpawn && t <= thisSpawn);
358
- if (firstSettleAt !== null && thisSpawn > firstSettleAt) {
359
- if (sawEvidence) observeThenRespawn += 1;
360
- else respawnWithoutEvidence += 1;
361
- }
362
- }
363
- const decision = {
364
- settledByStatus: haveJournal ? settledByStatus : gap("settledByStatus", journalMissing),
365
- settledVerdicts: verdictLimit !== null ? unavailable(verdictLimit) : haveJournal ? settledVerdicts : unavailable(journalMissing),
366
- accepted: verdictLimit !== null ? gap("accepted", verdictLimit) : src.workers === null ? unavailable(workersGapReason) : accepted,
367
- rejected: verdictLimit !== null ? unavailable(verdictLimit) : src.workers === null ? unavailable(workersGapReason) : rejected,
368
- emptyPass: verdictLimit !== null || src.limits.deliverables !== null ? unavailable(verdictLimit ?? src.limits.deliverables) : src.workers === null ? unavailable(workersGapReason) : emptyPass,
369
- observeThenRespawn: haveJournal ? observeThenRespawn : unavailable(journalMissing),
370
- respawnWithoutEvidence: haveJournal ? respawnWithoutEvidence : unavailable(journalMissing),
371
- reviewActions: src.workers === null ? unavailable(workersGapReason) : steerQueuedTotal + upLegMessages,
372
- workerEvidenceBytes: src.workers === null ? unavailable(workersGapReason) : evidenceBytes
373
- };
374
- const journalWorkerIn = workerCloses.reduce((a, c) => a + c.spend.tokens.input, 0);
375
- const journalWorkerOut = workerCloses.reduce((a, c) => a + c.spend.tokens.output, 0);
376
- const journalWorkerUsd = workerCloses.reduce((a, c) => a + c.spend.usd, 0);
377
- const labelById = new Map(tree.workerSpawns.map((s) => [s.id, s.label]));
378
- const workerUsdByLabel = /* @__PURE__ */ new Map();
379
- for (const c of workerCloses) {
380
- const label = labelById.get(c.id);
381
- if (label === void 0) continue;
382
- workerUsdByLabel.set(label, (workerUsdByLabel.get(label) ?? 0) + c.spend.usd);
383
- }
384
- const sq = src.harnessWorkerTokens;
385
- const harnessGapReason = src.harnessMissingReason ?? "harness session store unavailable and journal settled spend is 0";
386
- const workerIn = sq !== null ? journalWorkerIn + sq.input : journalWorkerIn > 0 ? journalWorkerIn : gap("workers.tokensIn", harnessGapReason);
387
- const workerOut = sq !== null ? journalWorkerOut + sq.output : journalWorkerOut > 0 ? journalWorkerOut : unavailable(harnessGapReason);
388
- const stateResult = asRecord(state?.result);
389
- const stateUsd = typeof stateResult.spentUsd === "number" ? stateResult.spentUsd : null;
390
- const usdLimit = src.limits.spendUsd;
391
- const totalUsd = usdLimit !== null ? gap("totalUsd", usdLimit) : stateUsd !== null ? round(stateUsd, 6) : haveJournal ? round(tree.brain.usd + journalWorkerUsd, 6) : gap("totalUsd", journalMissing);
392
- const perWorker = (src.workers ?? []).map((w) => {
393
- const f = tree.workerLogs.get(w.label);
394
- return {
395
- worker: w.label,
396
- wallMs: f?.started != null && f.finishedAt != null ? f.finishedAt - f.started : null,
397
- tokensIn: w.tokensIn ?? null,
398
- tokensOut: w.tokensOut ?? null,
399
- usd: usdLimit !== null ? null : workerUsdByLabel.get(w.label) ?? null,
400
- patchBytes: w.patchBytes ?? f?.finishedPatchBytes ?? null,
401
- passed: f?.passed ?? null
402
- };
403
- });
404
- const walls = perWorker.map((w) => w.wallMs).filter((w) => w !== null).sort((a, b) => a - b);
405
- const brainCalls = parseJsonl(src.brainLog);
406
- const economics = {
407
- brain: {
408
- tokensIn: haveJournal ? tree.brain.tokensIn : gap("brain.tokensIn", journalMissing),
409
- tokensOut: haveJournal ? tree.brain.tokensOut : unavailable(journalMissing),
410
- usd: usdLimit !== null ? unavailable(usdLimit) : haveJournal ? round(tree.brain.usd, 6) : unavailable(journalMissing),
411
- cacheRead: !haveJournal ? unavailable(journalMissing) : tree.brain.hasCache ? tree.brain.cacheRead : unavailable(NO_CACHE_COUNTERS),
412
- cacheWrite: !haveJournal ? unavailable(journalMissing) : tree.brain.hasCache ? tree.brain.cacheWrite : unavailable(NO_CACHE_COUNTERS),
413
- source: haveJournal ? `journal metered events (n=${tree.brain.meteredCount})` : journalMissing
414
- },
415
- brainTruncations: src.brainLog === null ? gap(
416
- "brain.brainTruncations",
417
- src.supRunDir === null ? "no supervisor run dir under <ws>/.loops/supervisor" : "brain.jsonl absent \u2014 loops predates the brain-call tap, so truncation cannot be ruled out"
418
- ) : brainCalls.filter((c) => c.finish_reason === "length").length,
419
- workers: {
420
- tokensIn: workerIn,
421
- tokensOut: workerOut,
422
- cacheRead: sq?.cacheRead !== void 0 ? sq.cacheRead : unavailable(NO_CACHE_COUNTERS),
423
- cacheWrite: sq?.cacheWrite !== void 0 ? sq.cacheWrite : unavailable(NO_CACHE_COUNTERS),
424
- usd: usdLimit !== null ? unavailable(usdLimit) : haveJournal ? round(journalWorkerUsd, 6) : unavailable(journalMissing),
425
- source: sq !== null ? `journal settled spend + ${sq.store} sessions (n=${sq.sessions})` : `journal settled spend only \u2014 ${src.harnessMissingReason ?? "harness session store unavailable"}`
426
- },
427
- totalUsd,
428
- totalUsdSource: usdLimit !== null ? usdLimit : stateUsd !== null ? `state.json result.spentUsd${journalWorkerUsd === 0 ? " \u2014 brain-priced only; worker CLI inference is unpriced (see worker token counts)" : ""}` : haveJournal ? "journal metered + settled usd" : journalMissing,
429
- costPerAcceptedPatchUsd: isUnavailable(totalUsd) ? unavailable(totalUsd.unavailable) : isUnavailable(decision.accepted) ? unavailable(decision.accepted.unavailable) : decision.accepted === 0 ? unavailable("no accepted worker patch (cost has no denominator)") : round(totalUsd / decision.accepted, 6),
430
- workerWallMsDistribution: walls.length === 0 ? unavailable(
431
- src.workers === null ? workersGapReason : "no worker start/finish pairs captured"
432
- ) : {
433
- n: walls.length,
434
- min: walls[0],
435
- p50: quantile(walls, 0.5),
436
- p90: quantile(walls, 0.9),
437
- max: walls[walls.length - 1],
438
- sum: walls.reduce((a, b) => a + b, 0)
439
- },
440
- perWorker: src.workers === null ? unavailable(workersGapReason) : perWorker
441
- };
442
- const patchStats = src.patch === null ? gap("patch", src.limits.deliverables ?? "delivered patch file absent") : parsePatch(src.patch);
443
- const outcome = {
444
- supStatus: pickString(state, "status") ?? pickString(result, "sup_status") ?? gap("supStatus", "no state.json / result.json status"),
445
- supVerdict: pickString(state, "verdict") ?? pickString(result, "sup_verdict") ?? unavailable("no state.json / result.json verdict"),
446
- delivered: typeof stateResult.delivered === "boolean" ? stateResult.delivered : typeof result?.delivered === "boolean" ? result.delivered : unavailable("no delivered flag in state.json or result.json"),
447
- judgeResolved: judge === null ? gap("judge", "judge.json absent") : typeof judge.resolved === "boolean" ? judge.resolved : null,
448
- judgeScore: judge === null ? unavailable("judge.json absent") : typeof judge.score === "number" ? judge.score : null,
449
- judgePassed: judge === null ? unavailable("judge.json absent") : typeof judge.passed === "number" ? judge.passed : null,
450
- judgeTotal: judge === null ? unavailable("judge.json absent") : typeof judge.total === "number" ? judge.total : null,
451
- verifyPass: typeof result?.verify_pass === "boolean" ? result.verify_pass : gap("verifyPass", "result.json absent or has no verify_pass"),
452
- verifyRc: typeof result?.verify_rc === "number" ? result.verify_rc : unavailable("result.json absent or has no verify_rc"),
453
- patch: patchStats,
454
- judgeSource: src.judgeSource
455
- };
456
- return {
457
- schema: SUPERVISOR_RUN_SCHEMA,
458
- runRef: src.runRef,
459
- instanceId: src.instanceId,
460
- arm: src.arm,
461
- supervisorId: rootId !== null ? rootId : unavailable(journalMissing),
462
- generatedAt: new Date(now()).toISOString(),
463
- orchestration,
464
- decision,
465
- economics,
466
- outcome,
467
- gaps,
468
- traceCommand: src.traceCommand ?? "npx --yes @tangle-network/traces@latest analyze --harness opencode --cwd <worker-clone-cwd>"
469
- };
470
- }
471
- function registrationMentions(driverLog) {
472
- let n = 0;
473
- for (const line2 of driverLog.split("\n")) {
474
- if (line2.includes("registered tools:") && line2.includes("supervisor_steer")) n += 1;
475
- }
476
- return n;
477
- }
478
- function pickString(rec, key) {
479
- const v = rec?.[key];
480
- return typeof v === "string" ? v : null;
481
- }
482
- function round(v, digits) {
483
- const f = 10 ** digits;
484
- return Math.round(v * f) / f;
485
- }
486
- function quantile(sorted, q) {
487
- if (sorted.length === 0) return 0;
488
- const idx = Math.min(sorted.length - 1, Math.max(0, Math.ceil(q * sorted.length) - 1));
489
- return sorted[idx];
490
- }
491
- function parsePatch(text) {
492
- const files = /* @__PURE__ */ new Set();
493
- const testFiles = /* @__PURE__ */ new Set();
494
- let added = 0;
495
- let removed = 0;
496
- for (const line2 of text.split("\n")) {
497
- if (line2.startsWith("+++ ")) {
498
- const p = line2.slice(4).trim().replace(/^b\//, "");
499
- if (p !== "/dev/null") {
500
- files.add(p);
501
- if (isTestPath(p)) testFiles.add(p);
502
- }
503
- continue;
504
- }
505
- if (line2.startsWith("--- ") || line2.startsWith("diff --git") || line2.startsWith("index ")) {
506
- continue;
507
- }
508
- if (line2.startsWith("+")) added += 1;
509
- else if (line2.startsWith("-")) removed += 1;
510
- }
511
- return {
512
- files: files.size,
513
- linesAdded: added,
514
- linesRemoved: removed,
515
- testFilesTouched: [...testFiles].sort()
516
- };
517
- }
518
- function isTestPath(p) {
519
- const base = p.split("/").pop() ?? p;
520
- return /(^|\/)(tests?|__tests__|testing|spec)(\/|$)/.test(p) || /\.(test|spec)\.[cm]?[jt]sx?$/.test(base) || /^test_.*\.py$/.test(base) || /_test\.py$/.test(base);
521
- }
522
- function rollupSupervisorRuns(reports) {
523
- const known = (vals) => vals.filter((v) => !isUnavailable(v));
524
- const steerVals = known(reports.map((r) => r.orchestration.steers));
525
- const waveVals = known(reports.map((r) => r.orchestration.waves));
526
- const concVals = known(reports.map((r) => r.orchestration.maxConcurrency));
527
- const utilVals = known(reports.map((r) => r.orchestration.workerUtilization));
528
- const idleVals = known(reports.map((r) => r.orchestration.idlePct));
529
- const spawnVals = known(reports.map((r) => r.orchestration.workersSpawned));
530
- const acceptVals = known(reports.map((r) => r.decision.accepted));
531
- const usdVals = known(reports.map((r) => r.economics.totalUsd));
532
- const resolvedVals = known(reports.map((r) => r.outcome.judgeResolved));
533
- const sum = (xs) => xs.reduce((a, b) => a + b, 0);
534
- const mean = (xs) => xs.length === 0 ? unavailable("no cell reported this metric") : round(sum(xs) / xs.length, 3);
535
- const perCell = reports.map((r) => ({
536
- instanceId: r.instanceId,
537
- arm: r.arm,
538
- steers: r.orchestration.steers,
539
- waves: r.orchestration.waves,
540
- utilization: r.orchestration.workerUtilization,
541
- idlePct: r.orchestration.idlePct,
542
- resolved: r.outcome.judgeResolved,
543
- usd: r.economics.totalUsd
544
- }));
545
- return {
546
- schema: SUPERVISOR_RUN_ROLLUP_SCHEMA,
547
- cells: reports.length,
548
- steersTotal: steerVals.length === 0 ? unavailable("no cell reported a steer count") : sum(steerVals),
549
- cellsWithSteers: steerVals.length === 0 ? unavailable("no cell reported a steer count") : steerVals.filter((n) => n > 0).length,
550
- cellsWithUnavailableSteers: reports.filter((r) => isUnavailable(r.orchestration.steers)).length,
551
- wavesMean: mean(waveVals),
552
- maxConcurrencyMax: concVals.length === 0 ? unavailable("no cell reported concurrency") : Math.max(...concVals),
553
- utilizationMean: mean(utilVals),
554
- idlePctMean: mean(idleVals),
555
- workersSpawnedTotal: spawnVals.length === 0 ? unavailable("no cell reported spawns") : sum(spawnVals),
556
- acceptedTotal: acceptVals.length === 0 ? unavailable("no cell reported acceptance") : sum(acceptVals),
557
- usdTotal: usdVals.length === 0 ? unavailable("no cell reported spend") : round(sum(usdVals), 6),
558
- resolvedCount: resolvedVals.length === 0 ? unavailable("no cell reported a judge verdict") : resolvedVals.filter((v) => v === true).length,
559
- perCell
560
- };
561
- }
562
-
563
- // src/supervisor-run/claude-code-reader.ts
564
- import { readdir, readFile } from "fs/promises";
565
- import { basename, dirname, join } from "path";
566
- var DEFAULT_SPAWN_TOOLS = ["Agent", "Task"];
567
- var DEFAULT_STEER_TOOLS = ["SendMessage"];
568
- var DEFAULT_CANCEL_TOOLS = ["TaskStop", "KillAgent"];
569
- var SPEND_UNPRICED = "Claude Code transcripts record token usage but never a price \u2014 usd is not in the store";
570
- var NO_VERDICTS = "Claude Code runs no per-worker verify step \u2014 a subagent reports prose, not pass/fail";
571
- var NO_DELIVERABLES = "Claude Code retains no per-worker patch \u2014 subagents commit to git, they do not hand back a diff";
572
- var isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
573
- var str = (v) => typeof v === "string" ? v : null;
574
- function blockText(content) {
575
- if (typeof content === "string") return content;
576
- if (!Array.isArray(content)) return "";
577
- const parts = [];
578
- for (const b of content) {
579
- if (isRecord(b) && b.type === "text" && typeof b.text === "string") parts.push(b.text);
580
- }
581
- return parts.join("\n");
582
- }
583
- var tag = (xml, name) => {
584
- const m = xml.match(new RegExp(`<${name}>([\\s\\S]*?)</${name}>`));
585
- return m === null ? null : m[1];
586
- };
587
- function parseNotifications(text, at) {
588
- const out = [];
589
- for (const m of text.matchAll(/<task-notification>[\s\S]*?<\/task-notification>/g)) {
590
- const xml = m[0];
591
- const taskId = tag(xml, "task-id");
592
- if (taskId === null) continue;
593
- out.push({
594
- taskId: taskId.trim(),
595
- toolUseId: tag(xml, "tool-use-id")?.trim() ?? null,
596
- status: tag(xml, "status")?.trim() ?? "unknown",
597
- summary: tag(xml, "summary")?.trim() ?? null,
598
- at
599
- });
600
- }
601
- return out;
602
- }
603
- function threadCalls(entries) {
604
- const uses = [];
605
- const results = /* @__PURE__ */ new Map();
606
- const notifications = [];
607
- let firstAt = null;
608
- let lastAt = null;
609
- for (const entry of entries) {
610
- if (entry.timestamp !== null) {
611
- if (firstAt === null) firstAt = entry.timestamp;
612
- lastAt = entry.timestamp;
613
- }
614
- const content = entry.message.content;
615
- if (entry.type === "assistant") {
616
- if (!Array.isArray(content)) continue;
617
- for (const block of content) {
618
- if (!isRecord(block) || block.type !== "tool_use") continue;
619
- const id = str(block.id);
620
- const name = str(block.name);
621
- if (id === null || name === null) continue;
622
- uses.push({
623
- id,
624
- name,
625
- input: isRecord(block.input) ? block.input : {},
626
- at: entry.timestamp
627
- });
628
- }
629
- continue;
630
- }
631
- if (typeof content === "string") {
632
- notifications.push(...parseNotifications(content, entry.timestamp));
633
- continue;
634
- }
635
- if (!Array.isArray(content)) continue;
636
- for (const block of content) {
637
- if (!isRecord(block)) continue;
638
- if (block.type === "tool_result" && typeof block.tool_use_id === "string") {
639
- results.set(block.tool_use_id, {
640
- id: block.tool_use_id,
641
- at: entry.timestamp,
642
- structured: entry.toolUseResult,
643
- text: blockText(block.content)
644
- });
645
- } else if (block.type === "text" && typeof block.text === "string") {
646
- notifications.push(...parseNotifications(block.text, entry.timestamp));
647
- }
648
- }
649
- }
650
- return { uses, results, notifications, firstAt, lastAt };
651
- }
652
- function spawnedAgentId(result) {
653
- if (result === void 0) return null;
654
- if (isRecord(result.structured)) {
655
- const id = str(result.structured.agentId);
656
- if (id !== null) return id;
657
- }
658
- return result.text.match(/agentId:\s*([A-Za-z0-9_-]+)/)?.[1] ?? null;
659
- }
660
- async function readChildren(dir) {
661
- const names = await readdir(dir).catch(() => null);
662
- if (names === null) return [];
663
- const out = [];
664
- for (const name of names.filter((n) => n.endsWith(".jsonl")).sort()) {
665
- const path = join(dir, name);
666
- const raw = await readFile(path, "utf8").catch(() => null);
667
- if (raw === null) continue;
668
- const entries = parseClaudeEntries(raw);
669
- const projected = transcriptFromEntries(entries, { includeSidechain: true });
670
- const metaRaw = await readFile(path.replace(/\.jsonl$/, ".meta.json"), "utf8").catch(() => null);
671
- let meta = {};
672
- if (metaRaw !== null) {
673
- try {
674
- const parsed = JSON.parse(metaRaw);
675
- if (isRecord(parsed)) meta = parsed;
676
- } catch {
677
- meta = {};
678
- }
679
- }
680
- const agentId = entries.find((e) => e.agentId !== null)?.agentId ?? name.replace(/^agent-/, "").replace(/\.jsonl$/, "");
681
- out.push({
682
- agentId,
683
- path,
684
- description: str(meta.description),
685
- spawnToolUseId: str(meta.toolUseId),
686
- spawnDepth: typeof meta.spawnDepth === "number" ? meta.spawnDepth : null,
687
- entries,
688
- tokensIn: projected.usage.tokensIn,
689
- tokensOut: projected.usage.tokensOut,
690
- cacheRead: projected.usage.cacheRead,
691
- cacheWrite: projected.usage.cacheWrite,
692
- firstAt: projected.startedAt,
693
- lastAt: projected.endedAt,
694
- model: projected.model,
695
- finalReport: [...projected.messages].reverse().find((m) => m.role === "assistant" && typeof m.content === "string")?.content ?? null
696
- });
697
- }
698
- return out;
699
- }
700
- var line = (obj) => JSON.stringify(obj);
701
- async function readClaudeCodeSupervisorRun(opts) {
702
- const spawnTools = new Set(opts.spawnTools ?? DEFAULT_SPAWN_TOOLS);
703
- const steerTools = new Set(opts.steerTools ?? DEFAULT_STEER_TOOLS);
704
- const cancelTools = new Set(opts.cancelTools ?? DEFAULT_CANCEL_TOOLS);
705
- const raw = await readFile(opts.transcriptPath, "utf8").catch(() => null);
706
- const sessionId = basename(opts.transcriptPath).replace(/\.jsonl$/, "");
707
- const runRef = opts.runRef ?? opts.transcriptPath;
708
- const limits = { spendUsd: SPEND_UNPRICED, workerVerdicts: NO_VERDICTS, deliverables: null };
709
- const traceCommand = `npx --yes @tangle-network/traces@latest analyze --harness claude-code --session ${sessionId}`;
710
- if (raw === null) {
711
- return {
712
- runRef,
713
- instanceId: opts.instanceId ?? sessionId,
714
- arm: opts.arm ?? null,
715
- supRunDir: null,
716
- journal: null,
717
- brainLog: null,
718
- state: null,
719
- progress: null,
720
- workers: null,
721
- workersMissingReason: `session transcript unreadable at ${opts.transcriptPath}`,
722
- result: null,
723
- judge: null,
724
- judgeSource: null,
725
- patch: null,
726
- driverLog: null,
727
- harnessWorkerTokens: null,
728
- harnessMissingReason: `session transcript unreadable at ${opts.transcriptPath}`,
729
- limits: { ...limits, deliverables: NO_DELIVERABLES },
730
- traceCommand
731
- };
732
- }
733
- const allEntries = parseClaudeEntries(raw);
734
- const main = threadCalls(allEntries.filter((e) => !e.isSidechain));
735
- const mainTranscript = transcriptFromEntries(allEntries);
736
- const subagentsDir = opts.subagentsDir === void 0 ? join(dirname(opts.transcriptPath), sessionId, "subagents") : opts.subagentsDir;
737
- const children = subagentsDir === null ? [] : await readChildren(subagentsDir);
738
- const childByAgentId = new Map(children.map((c) => [c.agentId, c]));
739
- const childBySpawnToolUseId = new Map(
740
- children.filter((c) => c.spawnToolUseId !== null).map((c) => [c.spawnToolUseId, c])
741
- );
742
- const threads = [{ id: sessionId, calls: main }];
743
- for (const child of children) {
744
- threads.push({ id: child.agentId, calls: threadCalls(child.entries) });
745
- }
746
- const spawns = [];
747
- const steersByTarget = /* @__PURE__ */ new Map();
748
- const cancels = [];
749
- const settles = [];
750
- for (const thread of threads) {
751
- for (const use of thread.calls.uses) {
752
- if (spawnTools.has(use.name)) {
753
- const result = thread.calls.results.get(use.id);
754
- const agentId = spawnedAgentId(result) ?? childBySpawnToolUseId.get(use.id)?.agentId ?? null;
755
- if (agentId === null) continue;
756
- const label = str(use.input.description) ?? childByAgentId.get(agentId)?.description ?? agentId;
757
- spawns.push({
758
- agentId,
759
- parentId: thread.id,
760
- label,
761
- // The spawn is complete when the launch call is answered; the tool_use
762
- // instant is the fallback for a call that never got a result line.
763
- at: result?.at ?? use.at,
764
- model: isRecord(result?.structured) ? str(result.structured.resolvedModel) : null
765
- });
766
- continue;
767
- }
768
- if (steerTools.has(use.name)) {
769
- const target = str(use.input.to) ?? str(use.input.recipient);
770
- if (target === null) continue;
771
- const result = thread.calls.results.get(use.id);
772
- const structured = isRecord(result?.structured) ? result.structured : null;
773
- const delivered = structured?.success === true || str(structured?.resumedAgentId) === target;
774
- const rows = steersByTarget.get(target) ?? [];
775
- rows.push({ at: use.at, delivered });
776
- steersByTarget.set(target, rows);
777
- continue;
778
- }
779
- if (cancelTools.has(use.name)) {
780
- const target = str(use.input.agentId) ?? str(use.input.to) ?? str(use.input.taskId);
781
- if (target !== null) cancels.push({ agentId: target, at: use.at });
782
- }
783
- }
784
- settles.push(...thread.calls.notifications);
785
- }
786
- const spawnedIds = new Set(spawns.map((s) => s.agentId));
787
- const cancelledIds = new Set(
788
- cancels.filter((c) => spawnedIds.has(c.agentId)).map((c) => c.agentId)
789
- );
790
- const startedAt = main.firstAt;
791
- const completedAt = main.lastAt;
792
- const journalLines = [
793
- line({
794
- kind: "spawned",
795
- id: sessionId,
796
- parent: null,
797
- label: `session:${sessionId}`,
798
- at: startedAt
799
- })
800
- ];
801
- for (const s of spawns) {
802
- journalLines.push(
803
- line({ kind: "spawned", id: s.agentId, parent: s.parentId, label: s.label, at: s.at })
804
- );
805
- }
806
- const lastNotification = /* @__PURE__ */ new Map();
807
- for (const n of settles) {
808
- if (!spawnedIds.has(n.taskId)) continue;
809
- lastNotification.set(n.taskId, n);
810
- }
811
- for (const [agentId, n] of lastNotification) {
812
- if (cancelledIds.has(agentId)) continue;
813
- journalLines.push(
814
- line({
815
- kind: "settled",
816
- id: agentId,
817
- status: n.status,
818
- verdict: n.summary,
819
- at: n.at
820
- // No `spent` key: Claude Code prices nothing, and a zeroed spend object
821
- // would read as a $0 worker. `limits.spendUsd` carries the reason.
822
- })
823
- );
824
- }
825
- const lastCancel = /* @__PURE__ */ new Map();
826
- for (const c of cancels) {
827
- if (!spawnedIds.has(c.agentId)) continue;
828
- lastCancel.set(c.agentId, c);
829
- }
830
- for (const c of lastCancel.values()) {
831
- journalLines.push(
832
- line({ kind: "cancelled", id: c.agentId, reason: "stopped by supervisor", at: c.at })
833
- );
834
- }
835
- journalLines.push(
836
- line({
837
- kind: "metered",
838
- id: sessionId,
839
- spend: {
840
- tokens: {
841
- input: mainTranscript.usage.tokensIn,
842
- output: mainTranscript.usage.tokensOut,
843
- cacheRead: mainTranscript.usage.cacheRead,
844
- cacheWrite: mainTranscript.usage.cacheWrite
845
- }
846
- },
847
- at: completedAt
848
- })
849
- );
850
- const settleAtByAgent = new Map(
851
- [...lastNotification.entries()].map(([id, n]) => [id, n.at])
852
- );
853
- const spawnAtByAgent = new Map(spawns.map((s) => [s.agentId, s.at]));
854
- const byLabel = /* @__PURE__ */ new Map();
855
- for (const s of spawns) {
856
- const ids = byLabel.get(s.label) ?? [];
857
- ids.push(s.agentId);
858
- byLabel.set(s.label, ids);
859
- }
860
- const workers = [];
861
- for (const [label, agentIds] of byLabel) {
862
- const events = [];
863
- const inbox = [];
864
- let tokensIn = null;
865
- let tokensOut = null;
866
- let cacheRead = null;
867
- let cacheWrite = null;
868
- let transcriptRef = null;
869
- for (const agentId of agentIds) {
870
- const child = childByAgentId.get(agentId) ?? null;
871
- const startAt = child?.firstAt ?? spawnAtByAgent.get(agentId) ?? null;
872
- const endAt = settleAtByAgent.get(agentId) ?? child?.lastAt ?? null;
873
- if (startAt !== null) events.push(line({ kind: "started", label, at: startAt, agentId }));
874
- for (const steer of steersByTarget.get(agentId) ?? []) {
875
- inbox.push(
876
- line({ id: `${agentId}:${steer.at}`, at: steer.at, worker: label, message: "steer" })
877
- );
878
- events.push(
879
- line({
880
- kind: "message",
881
- label,
882
- direction: "down",
883
- at: steer.at,
884
- requestId: `${agentId}:${steer.at}`,
885
- delivered: steer.delivered
886
- })
887
- );
888
- }
889
- if (endAt !== null) {
890
- events.push(
891
- line({
892
- kind: "finished",
893
- label,
894
- at: endAt,
895
- agentId,
896
- // No `passed` / `patchBytes`: this harness has neither. Emitting
897
- // `passed: false` here would invent a failed worker.
898
- // `evidence` is the child's closing message — what it handed back.
899
- ...child?.finalReport === null || child?.finalReport === void 0 ? {} : { evidence: child.finalReport }
900
- })
901
- );
902
- }
903
- if (child !== null) {
904
- tokensIn = (tokensIn ?? 0) + child.tokensIn;
905
- tokensOut = (tokensOut ?? 0) + child.tokensOut;
906
- cacheRead = (cacheRead ?? 0) + child.cacheRead;
907
- cacheWrite = (cacheWrite ?? 0) + child.cacheWrite;
908
- transcriptRef = child.path;
909
- }
910
- }
911
- workers.push({
912
- label,
913
- events: events.length === 0 ? null : `${events.join("\n")}
914
- `,
915
- inbox: inbox.length === 0 ? null : `${inbox.join("\n")}
916
- `,
917
- patchBytes: null,
918
- transcriptRef,
919
- patchPath: null,
920
- tokensIn,
921
- tokensOut,
922
- cacheRead,
923
- cacheWrite
924
- });
925
- }
926
- const joined = children.length;
927
- const harnessWorkerTokens = joined === 0 ? null : {
928
- store: "claude-code subagent transcripts",
929
- sessions: joined,
930
- input: children.reduce((a, c) => a + c.tokensIn, 0),
931
- output: children.reduce((a, c) => a + c.tokensOut, 0),
932
- cacheRead: children.reduce((a, c) => a + c.cacheRead, 0),
933
- cacheWrite: children.reduce((a, c) => a + c.cacheWrite, 0)
934
- };
935
- const missingChildren = spawns.filter((s) => !childByAgentId.has(s.agentId)).length;
936
- const harnessMissingReason = subagentsDir === null ? "subagent transcript join disabled" : joined === 0 ? `no subagent transcripts under ${subagentsDir}` : missingChildren === 0 ? null : `${missingChildren}/${spawns.length} spawned agents have no retained transcript under ${subagentsDir} (Claude Code prunes them; their tokens are unrecoverable)`;
937
- const liveWorkers = spawns.filter(
938
- (s) => !lastNotification.has(s.agentId) && !cancelledIds.has(s.agentId)
939
- ).length;
940
- const state = JSON.stringify({
941
- id: sessionId,
942
- // Derived, not asserted: a spawned agent with no notification and no stop
943
- // is still running, which is exactly what a live transcript looks like.
944
- status: liveWorkers > 0 ? "running" : "idle",
945
- startedAt,
946
- completedAt,
947
- result: { delivered: null }
948
- });
949
- return {
950
- runRef,
951
- instanceId: opts.instanceId ?? sessionId,
952
- arm: opts.arm ?? null,
953
- supRunDir: subagentsDir,
954
- journal: `${journalLines.join("\n")}
955
- `,
956
- brainLog: null,
957
- state,
958
- progress: null,
959
- workers,
960
- workersMissingReason: null,
961
- result: null,
962
- judge: null,
963
- judgeSource: null,
964
- patch: null,
965
- driverLog: null,
966
- harnessWorkerTokens,
967
- harnessMissingReason,
968
- limits: { ...limits, deliverables: NO_DELIVERABLES },
969
- rootTranscriptRef: opts.transcriptPath,
970
- traceCommand
971
- };
972
- }
973
- function claudeCodeSupervisorRunReader(opts) {
974
- return {
975
- runRef: opts.runRef ?? opts.transcriptPath,
976
- read: () => readClaudeCodeSupervisorRun(opts)
977
- };
978
- }
979
-
980
- // src/supervisor-run/loops-reader.ts
981
- import { appendFile, mkdir, readdir as readdir2, readFile as readFile2, writeFile } from "fs/promises";
982
- import { basename as basename2, join as join2 } from "path";
983
-
984
- // src/supervisor-run/render.ts
985
- function renderSupervisorRunHeadline(r) {
986
- const o = r.orchestration;
987
- const steerNote = isUnavailable(o.steers) ? `unavailable \u2014 ${o.steers.unavailable}` : o.steers === 0 ? "0 (spawn\u2192wait\u2192respawn only; no mid-task steering)" : `${o.steers} queued / ${showMeasured(o.steersDelivered)} delivered`;
988
- return [
989
- `RUN-REPORT ${r.instanceId ?? "?"} [${r.arm ?? "?"}]`,
990
- ` steers=${steerNote}`,
991
- ` waves=${showMeasured(o.waves)} sizes=${isUnavailable(o.waveSizes) ? `unavailable \u2014 ${o.waveSizes.unavailable}` : `[${o.waveSizes.join(",")}]`} workers=${showMeasured(o.workersSpawned)} settled=${showMeasured(o.workersSettled)} cancelled=${showMeasured(o.workersCancelled)}`,
992
- ` concurrency max=${showMeasured(o.maxConcurrency)} utilization=${showMeasured(o.workerUtilization)} idle=${fmtMs(o.idleMs)} (${showMeasured(o.idlePct)}%) wall=${fmtMs(o.supervisorWallMs)}`,
993
- ` respawns=${showMeasured(o.respawns)} evidence\u2192respawn=${showMeasured(r.decision.observeThenRespawn)} blind-respawn=${showMeasured(r.decision.respawnWithoutEvidence)} depth=${showMeasured(o.delegationDepth)}`,
994
- ` accepted=${showMeasured(r.decision.accepted)} rejected=${showMeasured(r.decision.rejected)} empty-pass=${showMeasured(r.decision.emptyPass)}`,
995
- ` brain=$${showMeasured(r.economics.brain.usd)} total=$${showMeasured(r.economics.totalUsd)} judge.resolved=${showMeasured(r.outcome.judgeResolved)} score=${showMeasured(r.outcome.judgeScore)} verify=${showMeasured(r.outcome.verifyPass)}`,
996
- r.gaps.length > 0 ? ` gaps(${r.gaps.length}): ${r.gaps.join("; ")}` : " gaps: none"
997
- ].join("\n");
998
- }
999
- function fmtMs(v) {
1000
- if (isUnavailable(v)) return `unavailable \u2014 ${v.unavailable}`;
1001
- if (v < 1e3) return `${v}ms`;
1002
- const s = v / 1e3;
1003
- if (s < 120) return `${round(s, 1)}s`;
1004
- return `${round(s / 60, 1)}min`;
1005
- }
1006
- function renderSupervisorRunMarkdown(r) {
1007
- const o = r.orchestration;
1008
- const d = r.decision;
1009
- const e = r.economics;
1010
- const out = [];
1011
- out.push(`# Run report \u2014 ${r.instanceId ?? "unknown instance"} [${r.arm ?? "unknown arm"}]`);
1012
- out.push("");
1013
- out.push("```");
1014
- out.push(renderSupervisorRunHeadline(r));
1015
- out.push("```");
1016
- out.push("");
1017
- out.push(`- Run: \`${r.runRef}\``);
1018
- out.push(`- Supervisor: \`${showMeasured(r.supervisorId)}\``);
1019
- out.push(`- Generated: ${r.generatedAt}`);
1020
- out.push("");
1021
- out.push("## Orchestration");
1022
- out.push("");
1023
- out.push("| Metric | Value |");
1024
- out.push("|---|---|");
1025
- out.push(`| Workers spawned | ${showMeasured(o.workersSpawned)} |`);
1026
- out.push(`| Workers settled | ${showMeasured(o.workersSettled)} |`);
1027
- out.push(`| Workers cancelled | ${showMeasured(o.workersCancelled)} |`);
1028
- out.push(`| **Steers (mid-task messages to live workers)** | **${showMeasured(o.steers)}** |`);
1029
- out.push(`| Steers delivered | ${showMeasured(o.steersDelivered)} |`);
1030
- out.push(`| Outer-driver \`supervisor_steer\` calls | ${showMeasured(o.driverSteerCalls)} |`);
1031
- out.push(`| Spawn waves | ${showMeasured(o.waves)} |`);
1032
- out.push(
1033
- `| Wave sizes | ${isUnavailable(o.waveSizes) ? showMeasured(o.waveSizes) : `[${o.waveSizes.join(", ")}]`} |`
1034
- );
1035
- out.push(`| Max concurrency | ${showMeasured(o.maxConcurrency)} |`);
1036
- out.push(`| Respawns (spawns after first settle) | ${showMeasured(o.respawns)} |`);
1037
- out.push(
1038
- `| Repeated labels | ${isUnavailable(o.repeatedLabels) ? showMeasured(o.repeatedLabels) : o.repeatedLabels.length === 0 ? "none" : o.repeatedLabels.join(", ")} |`
1039
- );
1040
- out.push(`| Delegation depth | ${showMeasured(o.delegationDepth)} |`);
1041
- out.push(`| Time to first spawn | ${fmtMs(o.timeToFirstSpawnMs)} |`);
1042
- out.push(`| Supervisor wall | ${fmtMs(o.supervisorWallMs)} |`);
1043
- out.push(`| Idle (zero live workers) | ${fmtMs(o.idleMs)} (${showMeasured(o.idlePct)}%) |`);
1044
- out.push(
1045
- `| Worker utilization (\u03A3 worker wall \xF7 supervisor wall) | ${showMeasured(o.workerUtilization)} |`
1046
- );
1047
- out.push("");
1048
- if (!isUnavailable(o.steersByWorker) && o.steersByWorker.length > 0) {
1049
- out.push("### Steers per worker");
1050
- out.push("");
1051
- out.push("| Worker | Queued | Delivered |");
1052
- out.push("|---|---:|---:|");
1053
- for (const s of o.steersByWorker) out.push(`| \`${s.worker}\` | ${s.queued} | ${s.delivered} |`);
1054
- out.push("");
1055
- } else if (isUnavailable(o.steersByWorker)) {
1056
- out.push(`### Steers per worker
1057
-
1058
- unavailable \u2014 ${o.steersByWorker.unavailable}
1059
- `);
1060
- }
1061
- out.push("## Decision quality");
1062
- out.push("");
1063
- out.push("| Metric | Value |");
1064
- out.push("|---|---|");
1065
- out.push(`| Settled by status | ${fmtCounts(d.settledByStatus)} |`);
1066
- out.push(`| Settled verdicts | ${fmtCounts(d.settledVerdicts)} |`);
1067
- out.push(`| Accepted (verify green + patch bytes) | ${showMeasured(d.accepted)} |`);
1068
- out.push(`| Rejected (verify red) | ${showMeasured(d.rejected)} |`);
1069
- out.push(`| Empty pass (green, no patch) | ${showMeasured(d.emptyPass)} |`);
1070
- out.push(`| Evidence \u2192 respawn sequences | ${showMeasured(d.observeThenRespawn)} |`);
1071
- out.push(
1072
- `| Respawn with no settled evidence in front | ${showMeasured(d.respawnWithoutEvidence)} |`
1073
- );
1074
- out.push(`| Review actions (steers + worker questions) | ${showMeasured(d.reviewActions)} |`);
1075
- out.push(
1076
- `| Worker evidence returned | ${isUnavailable(d.workerEvidenceBytes) ? showMeasured(d.workerEvidenceBytes) : `${d.workerEvidenceBytes} bytes`} |`
1077
- );
1078
- out.push("");
1079
- out.push("## Economics");
1080
- out.push("");
1081
- out.push("| Role | Tokens in | Tokens out | Cache read | Cache write | USD | Source |");
1082
- out.push("|---|---:|---:|---:|---:|---:|---|");
1083
- out.push(
1084
- `| brain | ${showMeasured(e.brain.tokensIn)} | ${showMeasured(e.brain.tokensOut)} | ${showMeasured(e.brain.cacheRead)} | ${showMeasured(e.brain.cacheWrite)} | ${showMeasured(e.brain.usd)} | ${e.brain.source} |`
1085
- );
1086
- out.push(
1087
- `| workers | ${showMeasured(e.workers.tokensIn)} | ${showMeasured(e.workers.tokensOut)} | ${showMeasured(e.workers.cacheRead)} | ${showMeasured(e.workers.cacheWrite)} | ${showMeasured(e.workers.usd)} | ${e.workers.source} |`
1088
- );
1089
- out.push("");
1090
- if (!isUnavailable(e.brainTruncations) && e.brainTruncations > 0) {
1091
- out.push(
1092
- `- **BRAIN OUTPUT TRUNCATED: ${e.brainTruncations} completion(s) hit \`finish_reason: "length"\`** \u2014 the supervisor acted on a half-written plan. Its output ceiling is too low; see \`brain.jsonl\` for the per-call \`req_max_tokens\`.`
1093
- );
1094
- } else {
1095
- out.push(
1096
- `- Brain completions truncated (finish_reason=length): ${showMeasured(e.brainTruncations)}`
1097
- );
1098
- }
1099
- out.push(`- Total USD: ${showMeasured(e.totalUsd)} (source: ${e.totalUsdSource})`);
1100
- out.push(`- Cost per accepted patch: ${showMeasured(e.costPerAcceptedPatchUsd)}`);
1101
- if (isUnavailable(e.workerWallMsDistribution)) {
1102
- out.push(`- Worker wall distribution: unavailable \u2014 ${e.workerWallMsDistribution.unavailable}`);
1103
- } else {
1104
- const w = e.workerWallMsDistribution;
1105
- out.push(
1106
- `- Worker wall (n=${w.n}): min ${fmtMs(w.min)} / p50 ${fmtMs(w.p50)} / p90 ${fmtMs(w.p90)} / max ${fmtMs(w.max)} / \u03A3 ${fmtMs(w.sum)}`
1107
- );
1108
- }
1109
- out.push("");
1110
- if (!isUnavailable(e.perWorker) && e.perWorker.length > 0) {
1111
- out.push("| Worker | Wall | Tokens in | Tokens out | Patch bytes | Verify passed |");
1112
- out.push("|---|---:|---:|---:|---:|---|");
1113
- for (const w of e.perWorker) {
1114
- out.push(
1115
- `| \`${w.worker}\` | ${w.wallMs === null ? "unavailable \u2014 no start/finish pair" : fmtMs(w.wallMs)} | ${w.tokensIn ?? "unavailable \u2014 store does not attribute tokens per worker"} | ${w.tokensOut ?? "unavailable \u2014 store does not attribute tokens per worker"} | ${w.patchBytes ?? "unavailable \u2014 no worker patch file"} | ${w.passed === null ? "unavailable \u2014 no finished event" : String(w.passed)} |`
1116
- );
1117
- }
1118
- out.push("");
1119
- }
1120
- out.push("## Outcome");
1121
- out.push("");
1122
- out.push("| Metric | Value |");
1123
- out.push("|---|---|");
1124
- out.push(`| Supervisor status | ${showMeasured(r.outcome.supStatus)} |`);
1125
- out.push(`| Supervisor verdict | ${showMeasured(r.outcome.supVerdict)} |`);
1126
- out.push(`| Delivered | ${showMeasured(r.outcome.delivered)} |`);
1127
- out.push(`| Judge resolved | ${showMeasured(r.outcome.judgeResolved)} |`);
1128
- out.push(`| Judge score | ${showMeasured(r.outcome.judgeScore)} |`);
1129
- out.push(
1130
- `| Judge passed / total | ${showMeasured(r.outcome.judgePassed)} / ${showMeasured(r.outcome.judgeTotal)} |`
1131
- );
1132
- out.push(
1133
- `| Judge source | ${r.outcome.judgeSource ?? "unavailable \u2014 no judge.json and no ledger row"} |`
1134
- );
1135
- out.push(
1136
- `| Verify gate | pass=${showMeasured(r.outcome.verifyPass)} rc=${showMeasured(r.outcome.verifyRc)} |`
1137
- );
1138
- if (isUnavailable(r.outcome.patch)) {
1139
- out.push(`| Patch | unavailable \u2014 ${r.outcome.patch.unavailable} |`);
1140
- } else {
1141
- const p = r.outcome.patch;
1142
- out.push(
1143
- `| Patch | ${p.files} file(s), +${p.linesAdded}/-${p.linesRemoved}, test files touched: ${p.testFilesTouched.length === 0 ? "none" : p.testFilesTouched.join(", ")} |`
1144
- );
1145
- }
1146
- out.push("");
1147
- out.push("## Gaps");
1148
- out.push("");
1149
- if (r.gaps.length === 0) out.push("None \u2014 every metric above is backed by a present artifact.");
1150
- else for (const g of r.gaps) out.push(`- ${g}`);
1151
- out.push("");
1152
- out.push(
1153
- `> Harness-session view of the same run (model calls, stuck loops, tool errors): \`${r.traceCommand}\``
1154
- );
1155
- out.push("");
1156
- return out.join("\n");
1157
- }
1158
- function fmtCounts(v) {
1159
- if (isUnavailable(v)) return showMeasured(v);
1160
- const entries = Object.entries(v);
1161
- return entries.length === 0 ? "none" : entries.map(([k, n]) => `${k}=${n}`).join(", ");
1162
- }
1163
- function renderSupervisorRollupMarkdown(rollup, title = "Round rollup") {
1164
- const out = [];
1165
- out.push(`# ${title}`);
1166
- out.push("");
1167
- out.push(`- Cells: ${rollup.cells}`);
1168
- out.push(
1169
- `- **Steers across all cells: ${showMeasured(rollup.steersTotal)}** (cells with \u22651 steer: ${showMeasured(rollup.cellsWithSteers)}; cells where the steer count is unavailable: ${rollup.cellsWithUnavailableSteers})`
1170
- );
1171
- out.push(`- Waves per cell (mean): ${showMeasured(rollup.wavesMean)}`);
1172
- out.push(`- Max concurrency observed: ${showMeasured(rollup.maxConcurrencyMax)}`);
1173
- out.push(`- Worker utilization (mean): ${showMeasured(rollup.utilizationMean)}`);
1174
- out.push(`- Idle share (mean): ${showMeasured(rollup.idlePctMean)}%`);
1175
- out.push(
1176
- `- Workers spawned: ${showMeasured(rollup.workersSpawnedTotal)} \xB7 accepted: ${showMeasured(rollup.acceptedTotal)}`
1177
- );
1178
- out.push(
1179
- `- Spend: $${showMeasured(rollup.usdTotal)} \xB7 judged resolved: ${showMeasured(rollup.resolvedCount)}/${rollup.cells}`
1180
- );
1181
- out.push("");
1182
- out.push("| Instance | Arm | Steers | Waves | Utilization | Idle % | Resolved | USD |");
1183
- out.push("|---|---|---:|---:|---:|---:|---|---:|");
1184
- for (const c of rollup.perCell) {
1185
- out.push(
1186
- `| ${c.instanceId ?? "?"} | ${c.arm ?? "?"} | ${showMeasured(c.steers)} | ${showMeasured(c.waves)} | ${showMeasured(c.utilization)} | ${showMeasured(c.idlePct)} | ${showMeasured(c.resolved)} | ${showMeasured(c.usd)} |`
1187
- );
1188
- }
1189
- out.push("");
1190
- return out.join("\n");
1191
- }
1192
-
1193
- // src/supervisor-run/loops-reader.ts
1194
- async function readMaybe(path) {
1195
- return readFile2(path, "utf8").catch(() => null);
1196
- }
1197
- async function findSupervisorRunDirIn(ws) {
1198
- const root = join2(ws, ".loops", "supervisor");
1199
- const entries = await readdir2(root, { withFileTypes: true }).catch(() => []);
1200
- const dirs = entries.filter((e) => e.isDirectory()).map((e) => join2(root, e.name));
1201
- return dirs[0] ?? null;
1202
- }
1203
- async function readLoopsSupervisorRun(runDir, opts = {}) {
1204
- const ws = opts.ws ?? join2(runDir, "ws");
1205
- const supRunDir = await findSupervisorRunDirIn(ws);
1206
- const result = await readMaybe(join2(runDir, "result.json"));
1207
- const resultObj = parseJson(result);
1208
- let workers = null;
1209
- let workersMissingReason = null;
1210
- const workerCwds = [];
1211
- if (supRunDir === null) {
1212
- workersMissingReason = `no supervisor run dir under ${join2(ws, ".loops", "supervisor")}`;
1213
- } else {
1214
- const workersDir = join2(supRunDir, "workers");
1215
- const entries = await readdir2(workersDir).catch(() => null);
1216
- if (entries === null) {
1217
- workersMissingReason = `workers/ directory absent under ${supRunDir}`;
1218
- } else {
1219
- const labels = [
1220
- ...new Set(
1221
- entries.filter((f) => f.endsWith(".ndjson")).map((f) => f.replace(/\.inbox\.ndjson$/, "").replace(/\.ndjson$/, ""))
1222
- )
1223
- ].sort();
1224
- workers = [];
1225
- for (const label of labels) {
1226
- const events = await readMaybe(join2(workersDir, `${label}.ndjson`));
1227
- const inbox = await readMaybe(join2(workersDir, `${label}.inbox.ndjson`));
1228
- const patch = await readMaybe(join2(workersDir, `${label}.patch`));
1229
- workers.push({
1230
- label,
1231
- events,
1232
- inbox,
1233
- patchBytes: patch === null ? null : Buffer.byteLength(patch)
1234
- });
1235
- for (const ev of parseJsonl(events)) {
1236
- if (ev.kind === "started" && typeof ev.cwd === "string") workerCwds.push(ev.cwd);
1237
- }
1238
- }
1239
- }
1240
- }
1241
- let harnessWorkerTokens = null;
1242
- let harnessMissingReason = null;
1243
- if (opts.opencodeDb === null) {
1244
- harnessMissingReason = "opencode join disabled";
1245
- } else if (workerCwds.length === 0) {
1246
- harnessMissingReason = "no worker clone cwds in workers/*.ndjson (nothing to join)";
1247
- } else {
1248
- const db = await openOpencodeDb(opts.opencodeDb ?? DEFAULT_OPENCODE_DB);
1249
- if (db === null) {
1250
- harnessMissingReason = `opencode session store unreadable at ${opts.opencodeDb ?? DEFAULT_OPENCODE_DB}`;
1251
- } else {
1252
- try {
1253
- const seen = /* @__PURE__ */ new Set();
1254
- let sessions = 0;
1255
- let input = 0;
1256
- let output = 0;
1257
- for (const cwd of new Set(workerCwds)) {
1258
- for (const row of findOpencodeSessionsByDirectory(db, cwd)) {
1259
- if (seen.has(row.id)) continue;
1260
- seen.add(row.id);
1261
- sessions += 1;
1262
- input += row.tokensInput;
1263
- output += row.tokensOutput + row.tokensReasoning;
1264
- }
1265
- }
1266
- harnessWorkerTokens = { store: "opencode", sessions, input, output };
1267
- } finally {
1268
- db.close();
1269
- }
1270
- }
1271
- }
1272
- const patchPath = opts.patchPath ?? (typeof resultObj?.patchPath === "string" ? resultObj.patchPath : null);
1273
- let judge = await readMaybe(join2(runDir, "judge.json"));
1274
- let judgeSource = judge === null ? null : join2(runDir, "judge.json");
1275
- if (judge === null && opts.ledgerPath !== void 0) {
1276
- const row = await findLedgerRow(opts.ledgerPath, runDir);
1277
- if (row !== null) {
1278
- judge = JSON.stringify(row);
1279
- judgeSource = `${opts.ledgerPath} (ledger row)`;
1280
- }
1281
- }
1282
- return {
1283
- runRef: runDir,
1284
- instanceId: typeof resultObj?.iid === "string" ? resultObj.iid : instanceIdFromPath(runDir),
1285
- arm: typeof resultObj?.arm === "string" ? resultObj.arm : basename2(runDir),
1286
- supRunDir,
1287
- journal: supRunDir === null ? null : await readMaybe(join2(supRunDir, "journal.jsonl")),
1288
- brainLog: supRunDir === null ? null : await readMaybe(join2(supRunDir, "brain.jsonl")),
1289
- state: supRunDir === null ? null : await readMaybe(join2(supRunDir, "state.json")),
1290
- progress: supRunDir === null ? null : await readMaybe(join2(supRunDir, "progress.ndjson")),
1291
- workers,
1292
- workersMissingReason,
1293
- result,
1294
- judge,
1295
- judgeSource,
1296
- patch: patchPath === null ? null : await readMaybe(patchPath),
1297
- driverLog: await readMaybe(join2(runDir, "driver.log")),
1298
- harnessWorkerTokens,
1299
- harnessMissingReason,
1300
- // loops prices its own inference, runs a verify per worker, and keeps each
1301
- // worker's patch — every fact the analyzer can use is expressible here.
1302
- limits: NO_SOURCE_LIMITS,
1303
- traceCommand: null
1304
- };
1305
- }
1306
- function loopsSupervisorRunReader(runDir, opts = {}) {
1307
- return { runRef: runDir, read: () => readLoopsSupervisorRun(runDir, opts) };
1308
- }
1309
- async function findLedgerRow(ledgerPath, runDir) {
1310
- const rows = parseJsonl(await readMaybe(ledgerPath));
1311
- const exact = rows.find((r) => r.runDir === runDir);
1312
- if (exact !== void 0) return exact;
1313
- const iid = instanceIdFromPath(runDir);
1314
- const arm = basename2(runDir);
1315
- return rows.find((r) => r.iid === iid && r.arm === arm) ?? null;
1316
- }
1317
- function instanceIdFromPath(runDir) {
1318
- const parts = runDir.split("/").filter(Boolean);
1319
- const armIdx = parts.length - 1;
1320
- const iid = parts[armIdx - 1];
1321
- return parts[armIdx - 2] === "runs" && iid !== void 0 ? iid : null;
1322
- }
1323
- async function analyzeSupervisorRun(input, opts = {}) {
1324
- if (typeof input === "string") {
1325
- return analyzeSupervisorRunSources(await readLoopsSupervisorRun(input, opts));
1326
- }
1327
- if (isReader(input)) return analyzeSupervisorRunSources(await input.read());
1328
- return analyzeSupervisorRunSources(input);
1329
- }
1330
- function isReader(input) {
1331
- return typeof input.read === "function";
1332
- }
1333
- async function writeSupervisorRunReport(runDir, opts = {}) {
1334
- const sources = await readLoopsSupervisorRun(runDir, opts);
1335
- const report = analyzeSupervisorRunSources(sources);
1336
- const md = renderSupervisorRunMarkdown(report);
1337
- const dest = opts.reportDir ?? runDir;
1338
- const stem = opts.reportDir === void 0 ? "run-report" : supervisorReportStem(runDir);
1339
- if (opts.reportDir !== void 0) await mkdir(opts.reportDir, { recursive: true }).catch(() => {
1340
- });
1341
- await writeFile(join2(dest, `${stem}.json`), JSON.stringify(report, null, 1)).catch(() => {
1342
- });
1343
- await writeFile(join2(dest, `${stem}.md`), md).catch(() => {
1344
- });
1345
- const headline = renderSupervisorRunHeadline(report);
1346
- if (opts.appendHeadlineTo !== void 0) {
1347
- await appendFile(opts.appendHeadlineTo, `${headline}
1348
- `).catch(() => {
1349
- });
1350
- }
1351
- if (opts.echo !== false) console.log(headline);
1352
- return report;
1353
- }
1354
- function supervisorReportStem(runDir) {
1355
- const parts = runDir.split("/").filter(Boolean);
1356
- const arm = parts[parts.length - 1] ?? "cell";
1357
- const iid = parts[parts.length - 2] ?? "instance";
1358
- const rep = parts.find((p) => /^rep-\d+$/.test(p));
1359
- const armRunsIdx = parts.indexOf("arm-runs");
1360
- const tag2 = armRunsIdx >= 0 ? parts[armRunsIdx + 1] : void 0;
1361
- return [tag2, rep, iid, arm].filter((s) => s !== void 0 && s !== "runs").join(".").replace(/[^A-Za-z0-9._-]/g, "_");
1362
- }
1363
- async function writeSupervisorRunReportSafe(runDir, opts = {}) {
1364
- try {
1365
- return await writeSupervisorRunReport(runDir, opts);
1366
- } catch (err) {
1367
- console.log(
1368
- `RUN-REPORT failed for ${runDir}: ${err instanceof Error ? err.message : String(err)}`
1369
- );
1370
- return null;
1371
- }
1372
- }
1373
- async function reportSupervisorRound(outDir, opts = {}) {
1374
- const runDirs = await findSupervisorRunDirs(outDir);
1375
- const reports = [];
1376
- for (const runDir of runDirs) {
1377
- const r = await writeSupervisorRunReportSafe(runDir, { ...opts, echo: opts.echo ?? false });
1378
- if (r !== null) reports.push(r);
1379
- }
1380
- const rollup = rollupSupervisorRuns(reports);
1381
- const md = renderSupervisorRollupMarkdown(
1382
- rollup,
1383
- opts.title ?? `Round rollup \u2014 ${basename2(outDir)}`
1384
- );
1385
- const dest = opts.reportDir ?? outDir;
1386
- if (opts.reportDir !== void 0) await mkdir(opts.reportDir, { recursive: true }).catch(() => {
1387
- });
1388
- await writeFile(join2(dest, "run-report-round.json"), JSON.stringify(rollup, null, 1)).catch(
1389
- () => {
1390
- }
1391
- );
1392
- await writeFile(join2(dest, "run-report-round.md"), md).catch(() => {
1393
- });
1394
- if (opts.appendHeadlineTo !== void 0) {
1395
- await appendFile(opts.appendHeadlineTo, `${md}
1396
- `).catch(() => {
1397
- });
1398
- }
1399
- if (opts.echo !== false) console.log(md);
1400
- return rollup;
1401
- }
1402
- async function findSupervisorRunDirs(root) {
1403
- const found = [];
1404
- const walk = async (dir, depth) => {
1405
- if (depth > 8) return;
1406
- const entries = await readdir2(dir, { withFileTypes: true }).catch(() => []);
1407
- for (const e of entries) {
1408
- if (!e.isDirectory()) continue;
1409
- if (e.name === "node_modules" || e.name === ".git") continue;
1410
- const full = join2(dir, e.name);
1411
- if (e.name === "runs") {
1412
- const iids = await readdir2(full, { withFileTypes: true }).catch(() => []);
1413
- for (const iid of iids) {
1414
- if (!iid.isDirectory()) continue;
1415
- const arms = await readdir2(join2(full, iid.name), { withFileTypes: true }).catch(() => []);
1416
- for (const arm of arms) if (arm.isDirectory()) found.push(join2(full, iid.name, arm.name));
1417
- }
1418
- continue;
1419
- }
1420
- await walk(full, depth + 1);
1421
- }
1422
- };
1423
- await walk(root, 0);
1424
- return found.sort();
1425
- }
1426
-
1427
- // src/supervisor-run/rollout-nodes.ts
1428
- var EMPTY_COST = {
1429
- usd: null,
1430
- tokens_in: null,
1431
- tokens_out: null,
1432
- tokens_reasoning: null,
1433
- cache_read: null,
1434
- cache_write: null,
1435
- wall_s: null
1436
- };
1437
- function supervisorRunRolloutLines(src, opts = {}) {
1438
- const gaps = [];
1439
- const tree = parseSupervisorTree(src);
1440
- if (src.journal === null) {
1441
- gaps.push(
1442
- `tree: ${src.supRunDir === null ? "no supervisor run dir" : "journal absent"} \u2014 no nodes recoverable`
1443
- );
1444
- return { rootId: null, nodes: [], gaps };
1445
- }
1446
- const state = parseJson(src.state);
1447
- const result = parseJson(src.result);
1448
- const judge = parseJson(src.judge);
1449
- const stateResult = asRecord(state?.result);
1450
- const rootId = tree.rootId;
1451
- const runId = opts.runId ?? rootId ?? src.runRef;
1452
- const suite = opts.suite ?? "supervisor-run";
1453
- const instanceId = src.instanceId ?? src.runRef;
1454
- const split = opts.split ?? "search";
1455
- const capturedAt = opts.capturedAt ?? (/* @__PURE__ */ new Date()).toISOString();
1456
- const base = {
1457
- schema: ROLLOUT_SCHEMA,
1458
- run_id: runId,
1459
- experiment_id: opts.experimentId ?? null,
1460
- candidate_id: opts.candidateId ?? null,
1461
- generation: opts.generation ?? null,
1462
- candidate_index: opts.candidateIndex ?? null,
1463
- task: {
1464
- suite,
1465
- instance_id: instanceId,
1466
- split,
1467
- seed: opts.seed ?? null,
1468
- rep: opts.rep ?? 0
1469
- },
1470
- messages: [],
1471
- tool_defs: []
1472
- };
1473
- const nodes = [];
1474
- if (rootId !== null) {
1475
- const judgeResolved = typeof judge?.resolved === "boolean" ? judge.resolved : null;
1476
- const judgeScore = typeof judge?.score === "number" ? judge.score : null;
1477
- const reward = judgeScore ?? (judgeResolved === null ? null : judgeResolved ? 1 : 0);
1478
- if (reward === null) gaps.push("root.outcome.reward: no judge verdict for this run");
1479
- const wallMs = tree.startedAt !== null && tree.completedAt !== null && tree.completedAt >= tree.startedAt ? tree.completedAt - tree.startedAt : null;
1480
- nodes.push({
1481
- ...base,
1482
- rollout_id: rootId,
1483
- parent_rollout_id: null,
1484
- role: "supervisor",
1485
- policy: {
1486
- harness: opts.supervisorHarness ?? null,
1487
- harness_version: null,
1488
- model: opts.supervisorModel ?? null,
1489
- provider: null,
1490
- profile_commit: null,
1491
- sampling: null
1492
- },
1493
- outcome: {
1494
- // `reward` and `realness_gated` are written by one call, in the module
1495
- // that owns the gate. This is the SECOND producer of rollout rewards —
1496
- // the judge verdict in the supervision run dir, not `mintRolloutRows` —
1497
- // and it wrote `reward` by hand while never stating the flag, so
1498
- // `isLineRealnessGated` was structurally false for every supervisor and
1499
- // worker row ever emitted here. `unscreenedRewardFields` is the honest
1500
- // name for what this producer can claim: a supervision journal carries
1501
- // no `RunRecord.outcome.realness`, so no authenticity gate has run on
1502
- // this score, and `realness_gated: false` states that rather than
1503
- // implying it by omission. These rows stay plain `RolloutLine`s, so a
1504
- // caller feeding them to a training exporter must `assertMinted` first.
1505
- ...unscreenedRewardFields(reward),
1506
- reward_source: src.judgeSource,
1507
- verdict: judge ?? null,
1508
- metrics: {
1509
- arm: src.arm,
1510
- sup_status: typeof state?.status === "string" ? state.status : null,
1511
- sup_verdict: typeof state?.verdict === "string" ? state.verdict : null,
1512
- delivered: typeof stateResult.delivered === "boolean" ? stateResult.delivered : null,
1513
- verify_pass: typeof result?.verify_pass === "boolean" ? result.verify_pass : null,
1514
- started_at: tree.startedAt,
1515
- completed_at: tree.completedAt,
1516
- workers_spawned: tree.workerSpawns.length,
1517
- brain_metered_events: tree.brain.meteredCount
1518
- },
1519
- is_completed: state?.status === "completed",
1520
- is_truncated: false,
1521
- error: null,
1522
- realness_gated: false
1523
- },
1524
- cost: {
1525
- ...EMPTY_COST,
1526
- usd: src.limits.spendUsd !== null ? null : typeof stateResult.spentUsd === "number" ? stateResult.spentUsd : tree.brain.usd,
1527
- tokens_in: tree.brain.tokensIn,
1528
- tokens_out: tree.brain.tokensOut,
1529
- cache_read: tree.brain.hasCache ? tree.brain.cacheRead : null,
1530
- cache_write: tree.brain.hasCache ? tree.brain.cacheWrite : null,
1531
- wall_s: wallMs === null ? null : wallMs / 1e3
1532
- },
1533
- artifacts: {
1534
- patch_path: typeof result?.patchPath === "string" ? result.patchPath : null,
1535
- run_dir: src.supRunDir,
1536
- transcript_ref: src.rootTranscriptRef !== void 0 ? src.rootTranscriptRef : src.supRunDir === null ? null : `${src.supRunDir}/journal.jsonl`
1537
- },
1538
- provenance: {
1539
- captured_at: capturedAt,
1540
- capture: "backfill",
1541
- gap: "supervision journal carries structure and spend, not the brain transcript"
1542
- }
1543
- });
1544
- } else {
1545
- gaps.push("tree.root: no parentless `spawned` event in the journal");
1546
- }
1547
- const closeById = new Map(tree.closes.map((c) => [c.id, c]));
1548
- const sourceByLabel = new Map((src.workers ?? []).map((w) => [w.label, w]));
1549
- for (const spawn of tree.workerSpawns) {
1550
- const close = closeById.get(spawn.id) ?? null;
1551
- const facts = tree.workerLogs.get(spawn.label) ?? null;
1552
- const workerSource = sourceByLabel.get(spawn.label) ?? null;
1553
- const wallMs = facts?.started != null && facts.finishedAt != null ? facts.finishedAt - facts.started : null;
1554
- const reward = facts?.passed === null || facts === null ? null : facts.passed ? 1 : 0;
1555
- if (reward === null) {
1556
- gaps.push(`worker ${spawn.label}: no verify verdict (worker logs absent or unfinished)`);
1557
- }
1558
- nodes.push({
1559
- ...base,
1560
- rollout_id: spawn.id,
1561
- parent_rollout_id: spawn.parent,
1562
- role: "worker",
1563
- policy: {
1564
- harness: opts.workerHarness ?? null,
1565
- harness_version: null,
1566
- model: opts.workerModel ?? null,
1567
- provider: null,
1568
- profile_commit: null,
1569
- sampling: null
1570
- },
1571
- outcome: {
1572
- // Same producer, same claim: a worker reward is a self-verify verdict
1573
- // from the journal that no realness gate has seen.
1574
- ...unscreenedRewardFields(reward),
1575
- reward_source: reward === null ? null : "worker-self-verify",
1576
- verdict: close === null ? null : { kind: close.kind, status: close.status, verdict: close.verdict },
1577
- metrics: {
1578
- label: spawn.label,
1579
- spawned_at: spawn.at,
1580
- settled_at: close?.at ?? null,
1581
- started_at: facts?.started ?? null,
1582
- finished_at: facts?.finishedAt ?? null,
1583
- wall_ms: wallMs,
1584
- patch_bytes: facts?.finishedPatchBytes ?? null,
1585
- evidence_bytes: facts?.evidenceBytes ?? null,
1586
- steers_queued: facts?.steersQueued ?? null,
1587
- steers_delivered: facts?.steersDelivered ?? null,
1588
- questions: facts?.questions ?? null
1589
- },
1590
- is_completed: close?.kind === "settled",
1591
- is_truncated: close?.kind === "cancelled",
1592
- error: close?.kind === "cancelled" ? close.verdict ?? "cancelled" : null,
1593
- realness_gated: false
1594
- },
1595
- // `close.spend` is only a measurement when the close event carried one;
1596
- // a store that never priced this worker must leave null, not 0.
1597
- cost: {
1598
- ...EMPTY_COST,
1599
- usd: src.limits.spendUsd !== null || !close?.hasSpend ? null : close.spend.usd,
1600
- tokens_in: workerSource?.tokensIn ?? (close?.hasSpend ? close.spend.tokens.input : null),
1601
- tokens_out: workerSource?.tokensOut ?? (close?.hasSpend ? close.spend.tokens.output : null),
1602
- // Mirror the tokens_in/out journal fallback so a loops-shaped store whose
1603
- // `settled` spend carries cache counters is not reported as null cache
1604
- // beside real tokens. Gate on `hasCache` — a spend object without cache
1605
- // counters must stay null, not a fabricated 0.
1606
- cache_read: workerSource?.cacheRead ?? (close?.hasSpend && close.spend.tokens.hasCache ? close.spend.tokens.cacheRead : null),
1607
- cache_write: workerSource?.cacheWrite ?? (close?.hasSpend && close.spend.tokens.hasCache ? close.spend.tokens.cacheWrite : null),
1608
- wall_s: wallMs === null ? null : wallMs / 1e3
1609
- },
1610
- // A reader that knows where its worker artifacts live says so; only the
1611
- // loops layout is derivable from `supRunDir`, so guessing it for another
1612
- // store would mint rows pointing at paths that never existed.
1613
- artifacts: {
1614
- patch_path: workerSource?.patchPath !== void 0 ? workerSource.patchPath : src.supRunDir === null ? null : `${src.supRunDir}/workers/${spawn.label}.patch`,
1615
- run_dir: src.supRunDir,
1616
- transcript_ref: workerSource?.transcriptRef !== void 0 ? workerSource.transcriptRef : src.supRunDir === null ? null : `${src.supRunDir}/workers/${spawn.label}.ndjson`
1617
- },
1618
- provenance: {
1619
- captured_at: capturedAt,
1620
- capture: "backfill",
1621
- gap: workerSource?.transcriptRef == null ? "worker transcript lives in the harness session store \u2014 hydrate via src/rollout/readers" : "worker transcript recorded by the harness; messages not inlined into this row"
1622
- }
1623
- });
1624
- }
1625
- const invalid = nodes.filter((n) => !isRolloutLine(n));
1626
- if (invalid.length > 0) {
1627
- gaps.push(`${invalid.length} node(s) failed tangle.rollout.v1 validation`);
1628
- }
1629
- return { rootId, nodes, gaps };
1630
- }
1631
-
1632
- export {
1633
- unavailable,
1634
- isUnavailable,
1635
- showMeasured,
1636
- NO_SOURCE_LIMITS,
1637
- SUPERVISOR_RUN_SCHEMA,
1638
- SUPERVISOR_RUN_ROLLUP_SCHEMA,
1639
- parseSupervisorTree,
1640
- analyzeSupervisorRunSources,
1641
- parsePatch,
1642
- rollupSupervisorRuns,
1643
- DEFAULT_SPAWN_TOOLS,
1644
- DEFAULT_STEER_TOOLS,
1645
- DEFAULT_CANCEL_TOOLS,
1646
- readClaudeCodeSupervisorRun,
1647
- claudeCodeSupervisorRunReader,
1648
- renderSupervisorRunHeadline,
1649
- renderSupervisorRunMarkdown,
1650
- renderSupervisorRollupMarkdown,
1651
- findSupervisorRunDirIn,
1652
- readLoopsSupervisorRun,
1653
- loopsSupervisorRunReader,
1654
- analyzeSupervisorRun,
1655
- writeSupervisorRunReport,
1656
- supervisorReportStem,
1657
- writeSupervisorRunReportSafe,
1658
- reportSupervisorRound,
1659
- findSupervisorRunDirs,
1660
- supervisorRunRolloutLines
1661
- };
1662
- //# sourceMappingURL=chunk-X4YIBDER.js.map