@tangle-network/agent-eval 0.128.2 → 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 (424) hide show
  1. package/CHANGELOG.md +279 -0
  2. package/README.md +19 -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 +83 -2932
  8. package/dist/analyst/index.d.ts.map +1 -0
  9. package/dist/analyst/index.js +319 -364
  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 -1205
  30. package/dist/belief-state/index.d.ts.map +1 -0
  31. package/dist/belief-state/index.js +1617 -1710
  32. package/dist/belief-state/index.js.map +1 -1
  33. package/dist/benchmarks/index.d.ts +2 -894
  34. package/dist/benchmarks/index.js +2 -59
  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 -6390
  44. package/dist/campaign/index.js +3 -212
  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 -174
  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 -5605
  61. package/dist/contract/index.d.ts.map +1 -0
  62. package/dist/contract/index.js +1730 -1937
  63. package/dist/contract/index.js.map +1 -1
  64. package/dist/control.d.ts +3 -1030
  65. package/dist/control.js +2 -32
  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 -617
  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 +3776 -15120
  122. package/dist/index.d.ts.map +1 -0
  123. package/dist/index.js +11185 -11191
  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 -481
  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 -1298
  196. package/dist/reporting.js +6 -50
  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 +916 -3596
  206. package/dist/rl.d.ts.map +1 -0
  207. package/dist/rl.js +2362 -1751
  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 -1048
  211. package/dist/rollout/index.js +8 -110
  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/run-record-BuoE80Dq.js.map +1 -0
  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 -849
  273. package/dist/supervisor-run/index.js +2 -64
  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 -251
  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 -1174
  298. package/dist/wire/index.d.ts.map +1 -0
  299. package/dist/wire/index.js +2 -81
  300. package/docs/feature-guide.md +1 -1
  301. package/docs/rollout.md +116 -2
  302. package/package.json +18 -10
  303. package/dist/benchmarks/index.js.map +0 -1
  304. package/dist/campaign/index.js.map +0 -1
  305. package/dist/chunk-2JX3CFMB.js +0 -695
  306. package/dist/chunk-2JX3CFMB.js.map +0 -1
  307. package/dist/chunk-2MKQIFS4.js +0 -183
  308. package/dist/chunk-2MKQIFS4.js.map +0 -1
  309. package/dist/chunk-3RF76KTD.js +0 -84
  310. package/dist/chunk-3RF76KTD.js.map +0 -1
  311. package/dist/chunk-5DTSBUL2.js +0 -159
  312. package/dist/chunk-5DTSBUL2.js.map +0 -1
  313. package/dist/chunk-7ZZMD7UK.js +0 -386
  314. package/dist/chunk-7ZZMD7UK.js.map +0 -1
  315. package/dist/chunk-BOD4O7OF.js +0 -40
  316. package/dist/chunk-BOD4O7OF.js.map +0 -1
  317. package/dist/chunk-BYT7ELPS.js +0 -1553
  318. package/dist/chunk-BYT7ELPS.js.map +0 -1
  319. package/dist/chunk-DJKY2TSY.js +0 -2428
  320. package/dist/chunk-DJKY2TSY.js.map +0 -1
  321. package/dist/chunk-DPUHNQLN.js +0 -232
  322. package/dist/chunk-DPUHNQLN.js.map +0 -1
  323. package/dist/chunk-DRYIUNWY.js +0 -622
  324. package/dist/chunk-DRYIUNWY.js.map +0 -1
  325. package/dist/chunk-EJGRPCO3.js +0 -617
  326. package/dist/chunk-EJGRPCO3.js.map +0 -1
  327. package/dist/chunk-EOSZT7PL.js +0 -2001
  328. package/dist/chunk-EOSZT7PL.js.map +0 -1
  329. package/dist/chunk-EZJEIH2R.js +0 -1559
  330. package/dist/chunk-EZJEIH2R.js.map +0 -1
  331. package/dist/chunk-GGE4NNQT.js +0 -65
  332. package/dist/chunk-GGE4NNQT.js.map +0 -1
  333. package/dist/chunk-HHWE3POT.js +0 -94
  334. package/dist/chunk-HHWE3POT.js.map +0 -1
  335. package/dist/chunk-IHQDPH7D.js +0 -171
  336. package/dist/chunk-IHQDPH7D.js.map +0 -1
  337. package/dist/chunk-JHCHEVET.js +0 -274
  338. package/dist/chunk-JHCHEVET.js.map +0 -1
  339. package/dist/chunk-K4DBDHLK.js +0 -158
  340. package/dist/chunk-K4DBDHLK.js.map +0 -1
  341. package/dist/chunk-K6N6XJJX.js +0 -306
  342. package/dist/chunk-K6N6XJJX.js.map +0 -1
  343. package/dist/chunk-MA6HLL3S.js +0 -65
  344. package/dist/chunk-MA6HLL3S.js.map +0 -1
  345. package/dist/chunk-MAZ26DC7.js +0 -99
  346. package/dist/chunk-MAZ26DC7.js.map +0 -1
  347. package/dist/chunk-MHELPNRP.js +0 -1212
  348. package/dist/chunk-MHELPNRP.js.map +0 -1
  349. package/dist/chunk-NACAGYSY.js +0 -1040
  350. package/dist/chunk-NACAGYSY.js.map +0 -1
  351. package/dist/chunk-NKAGIDE2.js +0 -7633
  352. package/dist/chunk-NKAGIDE2.js.map +0 -1
  353. package/dist/chunk-NPCTHQIO.js +0 -91
  354. package/dist/chunk-NPCTHQIO.js.map +0 -1
  355. package/dist/chunk-NYLOYM6N.js +0 -332
  356. package/dist/chunk-NYLOYM6N.js.map +0 -1
  357. package/dist/chunk-ONWEPEDO.js +0 -57
  358. package/dist/chunk-ONWEPEDO.js.map +0 -1
  359. package/dist/chunk-P5W7RQKK.js +0 -576
  360. package/dist/chunk-P5W7RQKK.js.map +0 -1
  361. package/dist/chunk-P6FYH6K4.js +0 -1161
  362. package/dist/chunk-P6FYH6K4.js.map +0 -1
  363. package/dist/chunk-PBE2LOSS.js +0 -669
  364. package/dist/chunk-PBE2LOSS.js.map +0 -1
  365. package/dist/chunk-PC4UYEBM.js +0 -166
  366. package/dist/chunk-PC4UYEBM.js.map +0 -1
  367. package/dist/chunk-PXE2VKMX.js +0 -140
  368. package/dist/chunk-PXE2VKMX.js.map +0 -1
  369. package/dist/chunk-PZ5AY32C.js +0 -10
  370. package/dist/chunk-PZ5AY32C.js.map +0 -1
  371. package/dist/chunk-RZTMDUO7.js +0 -49
  372. package/dist/chunk-RZTMDUO7.js.map +0 -1
  373. package/dist/chunk-S5YLIBFX.js +0 -136
  374. package/dist/chunk-S5YLIBFX.js.map +0 -1
  375. package/dist/chunk-SZLVEKMJ.js +0 -1446
  376. package/dist/chunk-SZLVEKMJ.js.map +0 -1
  377. package/dist/chunk-T4SQEITX.js +0 -95
  378. package/dist/chunk-T4SQEITX.js.map +0 -1
  379. package/dist/chunk-TBL77AUT.js +0 -355
  380. package/dist/chunk-TBL77AUT.js.map +0 -1
  381. package/dist/chunk-TSN7JT6D.js +0 -1646
  382. package/dist/chunk-TSN7JT6D.js.map +0 -1
  383. package/dist/chunk-TT4KNT67.js +0 -124
  384. package/dist/chunk-TT4KNT67.js.map +0 -1
  385. package/dist/chunk-UB2LOJ6Q.js +0 -4461
  386. package/dist/chunk-UB2LOJ6Q.js.map +0 -1
  387. package/dist/chunk-UWZZKKU7.js +0 -237
  388. package/dist/chunk-UWZZKKU7.js.map +0 -1
  389. package/dist/chunk-VBQ3CRKH.js +0 -291
  390. package/dist/chunk-VBQ3CRKH.js.map +0 -1
  391. package/dist/chunk-VGRCHJON.js +0 -163
  392. package/dist/chunk-VGRCHJON.js.map +0 -1
  393. package/dist/chunk-VI2UW6B6.js +0 -162
  394. package/dist/chunk-VI2UW6B6.js.map +0 -1
  395. package/dist/chunk-VLOATJQ2.js +0 -908
  396. package/dist/chunk-VLOATJQ2.js.map +0 -1
  397. package/dist/chunk-VQMK5FMP.js +0 -247
  398. package/dist/chunk-VQMK5FMP.js.map +0 -1
  399. package/dist/chunk-VZSRQ272.js +0 -149
  400. package/dist/chunk-VZSRQ272.js.map +0 -1
  401. package/dist/chunk-WGXIEX7P.js +0 -116
  402. package/dist/chunk-WGXIEX7P.js.map +0 -1
  403. package/dist/chunk-WS3NZZQQ.js +0 -929
  404. package/dist/chunk-WS3NZZQQ.js.map +0 -1
  405. package/dist/chunk-XDWDC2MP.js +0 -695
  406. package/dist/chunk-XDWDC2MP.js.map +0 -1
  407. package/dist/chunk-XPRT64IE.js +0 -766
  408. package/dist/chunk-XPRT64IE.js.map +0 -1
  409. package/dist/chunk-YJBNWCAA.js +0 -1056
  410. package/dist/chunk-YJBNWCAA.js.map +0 -1
  411. package/dist/chunk-ZET2UAYW.js +0 -89
  412. package/dist/chunk-ZET2UAYW.js.map +0 -1
  413. package/dist/chunk-ZUUWPZCV.js +0 -752
  414. package/dist/chunk-ZUUWPZCV.js.map +0 -1
  415. package/dist/control.js.map +0 -1
  416. package/dist/hosted/index.js.map +0 -1
  417. package/dist/matrix/index.js.map +0 -1
  418. package/dist/reporting.js.map +0 -1
  419. package/dist/rollout/index.js.map +0 -1
  420. package/dist/run-campaign-ISHFZ7FJ.js +0 -17
  421. package/dist/run-campaign-ISHFZ7FJ.js.map +0 -1
  422. package/dist/supervisor-run/index.js.map +0 -1
  423. package/dist/traces.js.map +0 -1
  424. package/dist/wire/index.js.map +0 -1
@@ -1,1446 +0,0 @@
1
- import {
2
- estimateCost,
3
- isModelPriced
4
- } from "./chunk-VI2UW6B6.js";
5
- import {
6
- extractUsage
7
- } from "./chunk-PXE2VKMX.js";
8
-
9
- // src/contract/intake/code-agent-observation.ts
10
- function observeCodeAgentSession(options) {
11
- const entries = options.entries.filter(isRecord);
12
- const projection = projectionFor(options.source, entries);
13
- const terminal = terminalWithExecution(projection, options.execution);
14
- return {
15
- source: options.source,
16
- sessionId: sessionIdFromEntries(options.source, entries) ?? fallbackSessionId(options.source, options.sourcePath),
17
- finalText: projection.finalText,
18
- terminal,
19
- actions: projection.actions
20
- };
21
- }
22
- function projectionFor(source, entries) {
23
- switch (source) {
24
- case "codex":
25
- return codexProjection(entries);
26
- case "claude-code":
27
- return claudeProjection(entries);
28
- case "opencode":
29
- return openCodeProjection(entries);
30
- case "kimi-code":
31
- return kimiProjection(entries);
32
- case "pi":
33
- return piProjection(entries);
34
- }
35
- }
36
- function codexProjection(entries) {
37
- const actions = [];
38
- const calls = /* @__PURE__ */ new Map();
39
- let finalText = null;
40
- let terminal = "unknown";
41
- let explicitTerminal = false;
42
- for (const entry of entries) {
43
- const entryType = stringField(entry, "type");
44
- const payload = record(entry.payload) ?? {};
45
- const payloadType = stringField(payload, "type");
46
- const timestampMs2 = timestamp(entry.timestamp);
47
- const item = record(entry.item);
48
- if (entryType === "item.started" && item) {
49
- const itemType = stringField(item, "type");
50
- if (isCodexActionItem(itemType)) {
51
- const id = stringField(item, "id") ?? `item-${actions.length}`;
52
- const action = actionFor({
53
- id,
54
- stepIndex: actions.length,
55
- kind: itemType === "file_change" ? "patch" : "tool",
56
- surface: codexItemSurface(itemType, item),
57
- name: codexItemName(itemType, item),
58
- status: "started",
59
- timestampMs: timestampMs2,
60
- metadata: compactMetadata({ sourceEventType: entryType, itemType })
61
- });
62
- calls.set(id, action);
63
- actions.push(action);
64
- }
65
- }
66
- if (entryType === "item.completed" && item) {
67
- const itemType = stringField(item, "type");
68
- if (itemType === "agent_message" || itemType === "message") {
69
- finalText = nonEmpty(stringField(item, "text")) ?? finalText;
70
- }
71
- if (isCodexActionItem(itemType)) {
72
- const id = stringField(item, "id") ?? `item-${actions.length}`;
73
- const status = codexItemStatus(itemType, item);
74
- const existing = calls.get(id);
75
- if (existing) {
76
- existing.status = status;
77
- } else {
78
- const action = actionFor({
79
- id,
80
- stepIndex: actions.length,
81
- kind: itemType === "file_change" ? "patch" : "tool",
82
- surface: codexItemSurface(itemType, item),
83
- name: codexItemName(itemType, item),
84
- status,
85
- timestampMs: timestampMs2,
86
- metadata: compactMetadata({ sourceEventType: entryType, itemType })
87
- });
88
- calls.set(id, action);
89
- actions.push(action);
90
- }
91
- }
92
- }
93
- if (entryType === "response_item") {
94
- if (payloadType === "message" || payloadType === "agent_message") {
95
- finalText = textFromMessagePayload(payload) ?? finalText;
96
- }
97
- if (payloadType === "function_call" || payloadType === "custom_tool_call") {
98
- const id = stringField(payload, "call_id") ?? stringField(payload, "id") ?? `call-${actions.length}`;
99
- const name = stringField(payload, "name") ?? payloadType;
100
- const action = actionFor({
101
- id,
102
- stepIndex: actions.length,
103
- kind: "tool",
104
- surface: surfaceForTool(name),
105
- name,
106
- status: "started",
107
- timestampMs: timestampMs2,
108
- metadata: compactMetadata({ sourceEventType: entryType, payloadType })
109
- });
110
- calls.set(id, action);
111
- actions.push(action);
112
- }
113
- if (payloadType === "function_call_output" || payloadType === "custom_tool_call_output") {
114
- const id = stringField(payload, "call_id") ?? stringField(payload, "id");
115
- const existing = id ? calls.get(id) : void 0;
116
- if (existing) existing.status = looksLikeError(payload.output) ? "failed" : "completed";
117
- }
118
- }
119
- if (entryType === "event_msg") {
120
- if (payloadType === "agent_message") {
121
- finalText = nonEmpty(stringField(payload, "message")) ?? nonEmpty(stringField(payload, "text")) ?? finalText;
122
- }
123
- if (payloadType === "patch_apply_end") {
124
- const patchStatus = typeof payload.success === "boolean" ? payload.success ? "completed" : "failed" : "unknown";
125
- actions.push(
126
- actionFor({
127
- id: stringField(payload, "call_id") ?? `patch-${actions.length}`,
128
- stepIndex: actions.length,
129
- kind: "patch",
130
- surface: "code",
131
- name: "patch",
132
- status: patchStatus,
133
- timestampMs: timestampMs2,
134
- metadata: compactMetadata({ sourceEventType: entryType, payloadType })
135
- })
136
- );
137
- }
138
- if (payloadType === "sub_agent_activity") {
139
- const name = stringField(payload, "kind") ?? "subagent";
140
- actions.push(
141
- actionFor({
142
- id: stringField(payload, "event_id") ?? `subagent-${actions.length}`,
143
- stepIndex: actions.length,
144
- kind: "tool",
145
- surface: "subagent",
146
- name,
147
- status: statusFrom(payload),
148
- timestampMs: timestampMs2,
149
- metadata: compactMetadata({ sourceEventType: entryType, payloadType })
150
- })
151
- );
152
- }
153
- if (payloadType === "task_complete" || payloadType === "turn_aborted") {
154
- const completed = payloadType === "task_complete";
155
- terminal = completed ? "completed" : "failed";
156
- explicitTerminal = true;
157
- actions.push(terminalAction(actions.length, payloadType, completed, timestampMs2));
158
- }
159
- }
160
- if (entryType === "turn.completed" || entryType === "exec_done") {
161
- const completed = entry.success !== false;
162
- terminal = completed ? "completed" : "failed";
163
- explicitTerminal = true;
164
- finalText = nonEmpty(stringField(entry, "message")) ?? finalText;
165
- actions.push(terminalAction(actions.length, entryType, completed, timestampMs2));
166
- }
167
- if (entryType === "turn.failed" || entryType === "error") {
168
- terminal = "failed";
169
- explicitTerminal = true;
170
- actions.push(terminalAction(actions.length, entryType, false, timestampMs2));
171
- }
172
- }
173
- return { finalText, terminal, explicitTerminal, actions };
174
- }
175
- function claudeProjection(entries) {
176
- const actions = [];
177
- const calls = /* @__PURE__ */ new Map();
178
- let finalText = null;
179
- let resultText = null;
180
- let terminal = "unknown";
181
- let explicitTerminal = false;
182
- for (const entry of entries) {
183
- const entryType = stringField(entry, "type");
184
- const timestampMs2 = timestamp(entry.timestamp);
185
- const message = record(entry.message);
186
- const content = Array.isArray(message?.content) ? message.content : [];
187
- if (entryType === "assistant") {
188
- const text = textBlocks(content);
189
- if (text !== null) finalText = text;
190
- for (const value of content) {
191
- const part = record(value);
192
- if (!part) continue;
193
- const partType = stringField(part, "type");
194
- if (partType === "tool_use") {
195
- const id = stringField(part, "id") ?? `tool-${actions.length}`;
196
- const name = stringField(part, "name") ?? "tool";
197
- const action = actionFor({
198
- id,
199
- stepIndex: actions.length,
200
- kind: "tool",
201
- surface: surfaceForTool(name),
202
- name,
203
- status: "started",
204
- timestampMs: timestampMs2,
205
- metadata: compactMetadata({ sourceEventType: entryType, partType })
206
- });
207
- calls.set(id, action);
208
- actions.push(action);
209
- }
210
- }
211
- completeClaudeTools(content, calls);
212
- const stopReason = stringField(message ?? {}, "stop_reason");
213
- if (stopReason === "end_turn") {
214
- terminal = "completed";
215
- explicitTerminal = true;
216
- actions.push(terminalAction(actions.length, stopReason, true, timestampMs2));
217
- }
218
- }
219
- if (entryType === "user") {
220
- completeClaudeTools(content, calls);
221
- }
222
- if (entryType === "tool_use") {
223
- const id = stringField(entry, "id") ?? `tool-${actions.length}`;
224
- const name = stringField(entry, "name") ?? "tool";
225
- const action = actionFor({
226
- id,
227
- stepIndex: actions.length,
228
- kind: "tool",
229
- surface: surfaceForTool(name),
230
- name,
231
- status: "started",
232
- timestampMs: timestampMs2,
233
- metadata: { sourceEventType: entryType }
234
- });
235
- calls.set(id, action);
236
- actions.push(action);
237
- }
238
- if (entryType === "tool_result") {
239
- const id = stringField(entry, "tool_use_id");
240
- const action = id ? calls.get(id) : void 0;
241
- if (action) action.status = entry.is_error === true ? "failed" : "completed";
242
- }
243
- if (entryType === "system") {
244
- const subtype = stringField(entry, "subtype");
245
- const hookName = stringField(entry, "hook_name") ?? stringField(entry, "hookName");
246
- if (subtype?.toLowerCase().includes("hook") || hookName) {
247
- actions.push(
248
- actionFor({
249
- id: stringField(entry, "uuid") ?? `hook-${actions.length}`,
250
- stepIndex: actions.length,
251
- kind: "tool",
252
- surface: "hook",
253
- name: hookName ?? subtype ?? "hook",
254
- status: statusFrom(entry),
255
- timestampMs: timestampMs2,
256
- metadata: compactMetadata({ sourceEventType: entryType, subtype })
257
- })
258
- );
259
- }
260
- }
261
- if (entryType === "pr-link") {
262
- actions.push(terminalAction(actions.length, entryType, true, timestampMs2));
263
- }
264
- if (entryType === "result") {
265
- resultText = nonEmpty(stringField(entry, "result")) ?? resultText;
266
- const subtype = stringField(entry, "subtype");
267
- const completed = entry.is_error !== true && !subtype?.toLowerCase().includes("error");
268
- terminal = completed ? "completed" : "failed";
269
- explicitTerminal = true;
270
- actions.push(terminalAction(actions.length, subtype ?? entryType, completed, timestampMs2));
271
- }
272
- if (entryType === "error") {
273
- terminal = "failed";
274
- explicitTerminal = true;
275
- actions.push(terminalAction(actions.length, entryType, false, timestampMs2));
276
- }
277
- }
278
- return {
279
- finalText: resultText ?? finalText,
280
- terminal,
281
- explicitTerminal,
282
- actions
283
- };
284
- }
285
- function openCodeProjection(entries) {
286
- const actions = [];
287
- const assistantMessageIds = new Set(
288
- entries.filter((entry) => stringField(entry, "role") === "assistant").map((entry) => stringField(entry, "id")).filter((id) => id !== void 0)
289
- );
290
- let finalText = null;
291
- let terminal = "unknown";
292
- let explicitTerminal = false;
293
- for (const entry of entries) {
294
- const entryType = stringField(entry, "type");
295
- const part = record(entry.part) ?? entry;
296
- const partType = stringField(part, "type");
297
- const timestampMs2 = timestamp(entry.timestamp) ?? timestamp(record(entry.time)?.created);
298
- if (entryType === "text" && record(entry.part)) {
299
- finalText = nonEmpty(stringField(part, "text")) ?? finalText;
300
- } else if (partType === "text" && (assistantMessageIds.size === 0 || assistantMessageIds.has(stringField(part, "messageID") ?? ""))) {
301
- finalText = nonEmpty(stringField(part, "text")) ?? finalText;
302
- }
303
- if (entryType === "tool_use" || partType === "tool") {
304
- const state = record(part.state) ?? {};
305
- const name = stringField(part, "tool") ?? "tool";
306
- actions.push(
307
- actionFor({
308
- id: stringField(part, "callID") ?? stringField(part, "id") ?? `tool-${actions.length}`,
309
- stepIndex: actions.length,
310
- kind: "tool",
311
- surface: surfaceForTool(name),
312
- name,
313
- status: statusFrom(state),
314
- timestampMs: timestampMs2,
315
- metadata: compactMetadata({ sourceEventType: entryType, partType })
316
- })
317
- );
318
- }
319
- if (partType === "patch") {
320
- actions.push(
321
- actionFor({
322
- id: stringField(part, "id") ?? `patch-${actions.length}`,
323
- stepIndex: actions.length,
324
- kind: "patch",
325
- surface: "code",
326
- name: "patch",
327
- status: "completed",
328
- timestampMs: timestampMs2,
329
- metadata: compactMetadata({ sourceEventType: entryType, partType })
330
- })
331
- );
332
- }
333
- if (stringField(entry, "role") === "assistant") {
334
- const finish = stringField(entry, "finish");
335
- if (finish === "stop" || finish === "error") {
336
- const completed = finish === "stop";
337
- terminal = completed ? "completed" : "failed";
338
- explicitTerminal = true;
339
- actions.push(terminalAction(actions.length, finish, completed, timestampMs2));
340
- }
341
- }
342
- if (entryType === "error") {
343
- terminal = "failed";
344
- explicitTerminal = true;
345
- actions.push(terminalAction(actions.length, entryType, false, timestampMs2));
346
- }
347
- }
348
- return { finalText, terminal, explicitTerminal, actions };
349
- }
350
- function kimiProjection(entries) {
351
- const actions = [];
352
- const calls = /* @__PURE__ */ new Map();
353
- let finalText = null;
354
- let terminal = "unknown";
355
- let explicitTerminal = false;
356
- for (const entry of entries) {
357
- const timestampMs2 = timestamp(entry.timestamp);
358
- const message = record(entry.message);
359
- const messageType = stringField(message ?? {}, "type");
360
- const payload = record(message?.payload) ?? {};
361
- if (messageType === "ContentPart" && stringField(payload, "type") === "text") {
362
- finalText = nonEmpty(stringField(payload, "text")) ?? nonEmpty(stringField(payload, "content")) ?? finalText;
363
- }
364
- if (messageType === "ToolCall") {
365
- const fn = record(payload.function) ?? {};
366
- const id = stringField(payload, "id") ?? `tool-${actions.length}`;
367
- const name = stringField(fn, "name") ?? "tool";
368
- const action = actionFor({
369
- id,
370
- stepIndex: actions.length,
371
- kind: "tool",
372
- surface: surfaceForTool(name),
373
- name,
374
- status: "started",
375
- timestampMs: timestampMs2,
376
- metadata: { sourceEventType: messageType }
377
- });
378
- calls.set(id, action);
379
- actions.push(action);
380
- }
381
- if (messageType === "ToolResult") {
382
- const id = stringField(payload, "tool_call_id");
383
- const action = id ? calls.get(id) : void 0;
384
- if (action)
385
- action.status = record(payload.return_value)?.is_error === true ? "failed" : "completed";
386
- }
387
- if (messageType === "TurnEnd" || messageType === "StepInterrupted") {
388
- const completed = messageType === "TurnEnd";
389
- terminal = completed ? "completed" : "failed";
390
- explicitTerminal = true;
391
- actions.push(terminalAction(actions.length, messageType, completed, timestampMs2));
392
- }
393
- }
394
- return { finalText, terminal, explicitTerminal, actions };
395
- }
396
- function piProjection(entries) {
397
- const actions = [];
398
- let terminal = "unknown";
399
- let explicitTerminal = false;
400
- for (const entry of entries) {
401
- const nodes = Array.isArray(entry.nodes) ? entry.nodes : [];
402
- for (const value of nodes) {
403
- const node = record(value);
404
- const ir = record(node?.ir) ?? node;
405
- const kind = stringField(ir ?? {}, "kind");
406
- if (kind === "ToolInvocation") {
407
- actions.push(
408
- actionFor({
409
- id: stringField(ir ?? {}, "id") ?? stringField(node ?? {}, "id") ?? `tool-${actions.length}`,
410
- stepIndex: actions.length,
411
- kind: "tool",
412
- surface: "tool",
413
- name: stringField(ir ?? {}, "name") ?? "graph-tool",
414
- status: "started",
415
- timestampMs: timestamp(ir?.createdAt),
416
- metadata: { sourceEventType: "graph-node", graphKind: kind }
417
- })
418
- );
419
- }
420
- if (kind === "ToolResult") {
421
- const prior = [...actions].reverse().find((action) => action.kind === "tool");
422
- if (prior) prior.status = "completed";
423
- }
424
- if (kind === "CompletionDecision") {
425
- terminal = "completed";
426
- explicitTerminal = true;
427
- actions.push(
428
- actionFor({
429
- id: stringField(ir ?? {}, "id") ?? stringField(node ?? {}, "id") ?? `completion-${actions.length}`,
430
- stepIndex: actions.length,
431
- kind: "graph-completion",
432
- surface: "tool",
433
- name: "complete",
434
- status: "completed",
435
- timestampMs: timestamp(ir?.createdAt),
436
- metadata: { sourceEventType: "graph-node", graphKind: kind }
437
- })
438
- );
439
- }
440
- }
441
- }
442
- return { finalText: null, terminal, explicitTerminal, actions };
443
- }
444
- function completeClaudeTools(content, calls) {
445
- for (const value of content) {
446
- const part = record(value);
447
- if (!part || stringField(part, "type") !== "tool_result") continue;
448
- const id = stringField(part, "tool_use_id");
449
- const action = id ? calls.get(id) : void 0;
450
- if (action) action.status = part.is_error === true ? "failed" : "completed";
451
- }
452
- }
453
- function isCodexActionItem(itemType) {
454
- return itemType === "command_execution" || itemType === "mcp_tool_call" || itemType === "collab_tool_call" || itemType === "web_search" || itemType === "file_change";
455
- }
456
- function codexItemSurface(itemType, item) {
457
- if (itemType === "mcp_tool_call") return "mcp";
458
- if (itemType === "collab_tool_call") return "subagent";
459
- if (itemType === "web_search") return "web";
460
- if (itemType === "file_change") return "code";
461
- return surfaceForTool(stringField(item, "name") ?? itemType ?? "tool");
462
- }
463
- function codexItemName(itemType, item) {
464
- if (itemType === "mcp_tool_call") {
465
- const server = stringField(item, "server");
466
- const tool = stringField(item, "tool");
467
- return [server, tool].filter(Boolean).join("/") || "mcp";
468
- }
469
- if (itemType === "collab_tool_call") return stringField(item, "tool") ?? "subagent";
470
- if (itemType === "web_search") return "web_search";
471
- if (itemType === "file_change") return "file_change";
472
- return stringField(item, "name") ?? itemType ?? "tool";
473
- }
474
- function codexItemStatus(itemType, item) {
475
- const status = statusFrom(item);
476
- if (status === "failed") return status;
477
- if (itemType === "command_execution") {
478
- const exitCode = numberField(item, "exit_code");
479
- if (exitCode !== void 0) return exitCode === 0 ? "completed" : "failed";
480
- }
481
- if (itemType === "mcp_tool_call" && record(item.error)) return "failed";
482
- return status === "unknown" || status === "started" ? "completed" : status;
483
- }
484
- function textFromMessagePayload(payload) {
485
- const direct = nonEmpty(stringField(payload, "text"));
486
- if (direct) return direct;
487
- const content = payload.content;
488
- if (typeof content === "string") return nonEmpty(content);
489
- if (Array.isArray(content)) return textBlocks(content);
490
- return null;
491
- }
492
- function textBlocks(values) {
493
- const text = values.map((value) => record(value)).filter((value) => value !== null).filter((value) => stringField(value, "type") === "text").map((value) => stringField(value, "text")).filter((value) => value !== void 0).join("\n");
494
- return nonEmpty(text);
495
- }
496
- function terminalWithExecution(projection, execution) {
497
- if (!execution) {
498
- return { status: projection.terminal, explicit: projection.explicitTerminal };
499
- }
500
- assertExecutionReceipt(execution);
501
- return {
502
- status: execution.exitCode !== 0 || projection.terminal === "failed" ? "failed" : "completed",
503
- explicit: true
504
- };
505
- }
506
- function assertExecutionReceipt(receipt) {
507
- if (!Number.isSafeInteger(receipt.exitCode)) {
508
- throw new Error("code-agent execution exitCode must be a safe integer");
509
- }
510
- for (const [name, value] of [
511
- ["startedAtMs", receipt.startedAtMs],
512
- ["completedAtMs", receipt.completedAtMs]
513
- ]) {
514
- if (value !== void 0 && (!Number.isFinite(value) || value < 0)) {
515
- throw new Error(`code-agent execution ${name} must be a non-negative finite number`);
516
- }
517
- }
518
- if (receipt.startedAtMs !== void 0 && receipt.completedAtMs !== void 0 && receipt.completedAtMs < receipt.startedAtMs) {
519
- throw new Error("code-agent execution completedAtMs precedes startedAtMs");
520
- }
521
- }
522
- function terminalAction(stepIndex, name, completed, timestampMs2) {
523
- return actionFor({
524
- id: `terminal-${stepIndex}`,
525
- stepIndex,
526
- kind: "terminal",
527
- surface: "tool",
528
- name,
529
- status: completed ? "completed" : "failed",
530
- timestampMs: timestampMs2,
531
- metadata: { sourceEventType: name }
532
- });
533
- }
534
- function actionFor(input) {
535
- return input;
536
- }
537
- function surfaceForTool(name) {
538
- const normalized = name.toLowerCase();
539
- if (normalized.startsWith("mcp__") || normalized.includes("mcp_tool")) return "mcp";
540
- if (normalized === "task" || normalized === "agent" || normalized.includes("subagent") || normalized.includes("spawn_agent") || normalized.includes("collab") || normalized.startsWith("multi_agent")) {
541
- return "subagent";
542
- }
543
- if (normalized === "skill" || normalized.includes("skill")) return "skill";
544
- if (normalized.includes("hook")) return "hook";
545
- if (normalized.includes("web_search") || normalized.includes("webfetch") || normalized === "web") {
546
- return "web";
547
- }
548
- if (normalized === "edit" || normalized === "write" || normalized.includes("patch") || normalized.includes("file_change")) {
549
- return "code";
550
- }
551
- return "tool";
552
- }
553
- function statusFrom(value) {
554
- const status = (stringField(value, "status") ?? "").toLowerCase();
555
- if (status === "completed" || status === "success" || status === "succeeded") return "completed";
556
- if (status === "error" || status === "failed" || status === "declined") return "failed";
557
- if (status === "running" || status === "started" || status === "in_progress") return "started";
558
- return "unknown";
559
- }
560
- function compactMetadata(input) {
561
- return Object.fromEntries(Object.entries(input).filter((entry) => entry[1] !== void 0));
562
- }
563
- function sessionIdFromEntries(source, entries) {
564
- for (const entry of entries) {
565
- if (source === "codex") {
566
- const threadId = stringField(entry, "thread_id");
567
- if (threadId) return threadId;
568
- const payload2 = record(entry.payload);
569
- const id = payload2 ? stringField(payload2, "id") : void 0;
570
- if (id) return id;
571
- }
572
- const message = record(entry.message);
573
- const payload = record(message?.payload);
574
- const sessionId = stringField(entry, "sessionID") ?? stringField(entry, "sessionId") ?? stringField(entry, "session_id") ?? stringField(payload ?? {}, "session_id");
575
- if (sessionId) return sessionId;
576
- }
577
- return void 0;
578
- }
579
- function fallbackSessionId(source, sourcePath) {
580
- return `${source}:${sourcePath ?? "unknown-session"}`;
581
- }
582
- function looksLikeError(value) {
583
- if (isRecord(value)) {
584
- if (value.success === false || value.is_error === true) return true;
585
- const exitCode = numberField(value, "exit_code");
586
- if (exitCode !== void 0 && exitCode !== 0) return true;
587
- }
588
- const text = typeof value === "string" ? value : JSON.stringify(value ?? "");
589
- return /\b(?:error|failed|failure)\b|exit(?:_| )code["\s:]+[1-9]/i.test(text);
590
- }
591
- function nonEmpty(value) {
592
- return value !== void 0 && value.length > 0 ? value : null;
593
- }
594
- function isRecord(value) {
595
- return value !== null && typeof value === "object" && !Array.isArray(value);
596
- }
597
- function record(value) {
598
- return isRecord(value) ? value : null;
599
- }
600
- function stringField(value, key) {
601
- const field = value[key];
602
- return typeof field === "string" && field.length > 0 ? field : void 0;
603
- }
604
- function numberField(value, key) {
605
- const field = value[key];
606
- return typeof field === "number" && Number.isFinite(field) ? field : void 0;
607
- }
608
- function timestamp(value) {
609
- if (typeof value === "number" && Number.isFinite(value)) {
610
- return value > 1e12 ? value : value * 1e3;
611
- }
612
- if (typeof value === "string" && value.length > 0) {
613
- const parsed = Date.parse(value);
614
- return Number.isFinite(parsed) ? parsed : void 0;
615
- }
616
- return void 0;
617
- }
618
-
619
- // src/contract/intake/code-agent-session.ts
620
- import { createHash } from "crypto";
621
- function parseCodeAgentJsonl(jsonl) {
622
- const entries = [];
623
- let malformedLines = 0;
624
- for (const line of jsonl.split("\n")) {
625
- const trimmed = line.trim();
626
- if (!trimmed) continue;
627
- try {
628
- entries.push(JSON.parse(trimmed));
629
- } catch {
630
- malformedLines += 1;
631
- }
632
- }
633
- return { entries, malformedLines };
634
- }
635
- function fromCodexSession(options) {
636
- return fromCodeAgentSession("codex", options);
637
- }
638
- function fromClaudeCodeSession(options) {
639
- return fromCodeAgentSession("claude-code", options);
640
- }
641
- function fromOpenCodeSession(options) {
642
- return fromCodeAgentSession("opencode", options);
643
- }
644
- function fromKimiCodeSession(options) {
645
- return fromCodeAgentSession("kimi-code", options);
646
- }
647
- function fromPiSession(options) {
648
- return fromCodeAgentSession("pi", options);
649
- }
650
- var fromPigraphSession = fromPiSession;
651
- function fromCodeAgentSession(source, options) {
652
- const entries = options.entries.filter(isRecord2);
653
- if (entries.length === 0) {
654
- return {
655
- runs: [],
656
- diagnostics: [
657
- {
658
- source,
659
- sessionId: fallbackSessionId2(source, options.sourcePath),
660
- sourcePath: options.sourcePath,
661
- entries: 0,
662
- malformedLines: options.malformedLines ?? 0,
663
- hasExplicitTerminalSignal: false,
664
- hasFinalOutput: false,
665
- hasQualityLabel: false,
666
- hasTokenUsage: false,
667
- hasCost: false,
668
- costKind: "uncaptured",
669
- warnings: ["no parseable session entries"]
670
- }
671
- ],
672
- metrics: [],
673
- observations: []
674
- };
675
- }
676
- const metrics = metricsFor(source, entries);
677
- const sessionId = sessionIdFromEntries2(source, entries) ?? fallbackSessionId2(source, options.sourcePath);
678
- const observation = observeCodeAgentSession({
679
- source,
680
- entries,
681
- sourcePath: options.sourcePath,
682
- execution: options.execution
683
- });
684
- applyObservedSurfaceMetrics(metrics, observation);
685
- const model = withSnapshot(options.model ?? modelFromEntries(source, entries) ?? source);
686
- const tokenUsage = {
687
- input: metrics.inputTokens,
688
- output: metrics.outputTokens,
689
- ...metrics.reasoningTokens > 0 ? { reasoning: metrics.reasoningTokens } : {},
690
- ...metrics.cachedTokens > 0 ? { cached: metrics.cachedTokens } : {},
691
- ...metrics.cacheWriteTokens > 0 ? { cacheWrite: metrics.cacheWriteTokens } : {}
692
- };
693
- const { costUsd, costProvenance } = resolveSessionCost(options.costProvenance, metrics, model);
694
- const qualityScore = finiteScore(options.score);
695
- const invalidQualityScore = options.score !== void 0 && qualityScore === void 0;
696
- const promptHash = options.promptHash ?? hashString(`prompt:${source}:${firstUserText(entries) ?? ""}`);
697
- const configHash = options.configHash ?? hashJson({
698
- source,
699
- model,
700
- sourcePath: options.sourcePath,
701
- cwd: cwdFromEntries(entries),
702
- entryCount: entries.length
703
- });
704
- const explicitTerminal = observation.terminal.explicit;
705
- const warnings = diagnosticsFor(metrics, {
706
- model,
707
- explicitTerminal,
708
- malformedLines: options.malformedLines ?? 0,
709
- hasQualityLabel: qualityScore !== void 0,
710
- invalidQualityScore,
711
- costKind: costProvenance.kind
712
- });
713
- const terminalOutcome = terminalOutcomeFromSession(observation.terminal);
714
- const processExitCode = options.execution?.exitCode;
715
- const splitTag = options.splitTag ?? "holdout";
716
- const run = {
717
- runId: `${source}:${sessionId}`,
718
- experimentId: options.experimentId ?? `${source}-local-sessions`,
719
- candidateId: options.candidateId ?? model,
720
- seed: options.seed ?? stableSeed(sessionId),
721
- model,
722
- promptHash,
723
- configHash,
724
- commitSha: options.commitSha ?? "local-session",
725
- wallMs: metrics.wallMs,
726
- costUsd,
727
- costProvenance,
728
- tokenUsage,
729
- terminalOutcome,
730
- ...terminalOutcome === "failed" ? {
731
- terminalFailureReason: processExitCode !== void 0 && processExitCode !== 0 ? `process exited with code ${processExitCode}` : metrics.turnsAborted > 0 ? "turn aborted" : "session reported terminal failure"
732
- } : {},
733
- outcome: {
734
- ...qualityScore === void 0 ? {} : splitTag === "holdout" ? { holdoutScore: qualityScore } : { searchScore: qualityScore },
735
- raw: {
736
- entries: metrics.entries,
737
- user_messages: metrics.userMessages,
738
- assistant_messages: metrics.assistantMessages,
739
- reasoning_items: metrics.reasoningItems,
740
- tool_calls: metrics.toolCalls,
741
- tool_outputs: metrics.toolOutputs,
742
- tool_errors: metrics.toolErrors,
743
- execution_error_count: metrics.toolErrors,
744
- process_error_count: terminalOutcome === "failed" ? 1 : 0,
745
- unclassified_error_count: metrics.unclassifiedErrors,
746
- ...processExitCode !== void 0 ? { process_exit_code: processExitCode } : {},
747
- patch_attempts: metrics.patchAttempts,
748
- patch_successes: metrics.patchSuccesses,
749
- patch_failures: metrics.patchFailures,
750
- turns_started: metrics.turnsStarted,
751
- turns_completed: metrics.turnsCompleted,
752
- turns_aborted: metrics.turnsAborted,
753
- context_compactions: metrics.contextCompactions,
754
- mcp_calls: metrics.mcpCalls,
755
- subagent_calls: metrics.subagentCalls,
756
- skill_calls: metrics.skillCalls,
757
- hook_calls: metrics.hookCalls,
758
- web_calls: metrics.webCalls,
759
- code_actions: metrics.codeActions,
760
- pr_links: metrics.prLinks,
761
- file_snapshots: metrics.fileSnapshots,
762
- graph_nodes: metrics.graphNodes,
763
- graph_edges: metrics.graphEdges,
764
- action_candidates: metrics.actionCandidates,
765
- verification_reports: metrics.verificationReports,
766
- completion_decisions: metrics.completionDecisions,
767
- reliability_rows: metrics.reliabilityRows,
768
- reliability_lift: metrics.reliabilityLift,
769
- input_tokens: metrics.inputTokens,
770
- output_tokens: metrics.outputTokens,
771
- reasoning_tokens: metrics.reasoningTokens,
772
- cached_tokens: metrics.cachedTokens,
773
- cache_write_tokens: metrics.cacheWriteTokens,
774
- observed_cost_usd: metrics.observedCostUsd,
775
- observed_cost_captured: metrics.observedCostCaptured ? 1 : 0,
776
- estimated_cost_usd: costProvenance.kind === "estimated" ? costProvenance.usd : 0,
777
- process_score: metrics.processScore,
778
- explicit_terminal_signal: explicitTerminal ? 1 : 0,
779
- quality_label_present: qualityScore !== void 0 ? 1 : 0,
780
- cost_observed: costProvenance.kind === "observed" ? 1 : 0,
781
- cost_estimated: costProvenance.kind === "estimated" ? 1 : 0,
782
- cost_uncaptured: costProvenance.kind === "uncaptured" ? 1 : 0,
783
- cost_unknown: costProvenance.kind === "uncaptured" ? 1 : 0
784
- }
785
- },
786
- splitTag,
787
- scenarioId: options.scenarioId ?? sessionId
788
- };
789
- return {
790
- runs: [run],
791
- diagnostics: [
792
- {
793
- source,
794
- sessionId,
795
- sourcePath: options.sourcePath,
796
- entries: entries.length,
797
- malformedLines: options.malformedLines ?? 0,
798
- hasExplicitTerminalSignal: explicitTerminal,
799
- hasFinalOutput: observation.finalText !== null,
800
- hasQualityLabel: qualityScore !== void 0,
801
- hasTokenUsage: metrics.inputTokens > 0 || metrics.outputTokens > 0 || metrics.reasoningTokens > 0 || metrics.cachedTokens > 0 || metrics.cacheWriteTokens > 0,
802
- hasCost: costProvenance.kind !== "uncaptured",
803
- costKind: costProvenance.kind,
804
- warnings
805
- }
806
- ],
807
- metrics: [metrics],
808
- observations: [{ ...observation, sessionId }]
809
- };
810
- }
811
- function terminalOutcomeFromSession(terminal) {
812
- if (!terminal.explicit) return "unknown";
813
- if (terminal.status === "completed") return "succeeded";
814
- if (terminal.status === "failed") return "failed";
815
- return "unknown";
816
- }
817
- function metricsFor(source, entries) {
818
- switch (source) {
819
- case "codex":
820
- return codexMetrics(entries);
821
- case "claude-code":
822
- return claudeCodeMetrics(entries);
823
- case "opencode":
824
- return openCodeMetrics(entries);
825
- case "kimi-code":
826
- return kimiCodeMetrics(entries);
827
- case "pi":
828
- return piMetrics(entries);
829
- }
830
- }
831
- function codexMetrics(entries) {
832
- const metrics = emptyMetrics(entries.length);
833
- const startedToolIds = /* @__PURE__ */ new Set();
834
- let startedAt;
835
- let completedAt;
836
- for (const entry of entries) {
837
- const payload = record2(entry.payload) ?? {};
838
- const entryType = stringField2(entry, "type");
839
- const payloadType = stringField2(payload, "type");
840
- const timestamp2 = timestampMs(entry.timestamp);
841
- if (timestamp2 !== void 0) {
842
- startedAt = startedAt === void 0 ? timestamp2 : Math.min(startedAt, timestamp2);
843
- completedAt = completedAt === void 0 ? timestamp2 : Math.max(completedAt, timestamp2);
844
- }
845
- if (entryType === "turn.started") metrics.turnsStarted += 1;
846
- if (entryType === "turn.completed") {
847
- metrics.turnsCompleted += 1;
848
- addCodexExecUsage(metrics, record2(entry.usage));
849
- }
850
- if (entryType === "turn.failed") metrics.turnsAborted += 1;
851
- if (entryType === "error") metrics.unclassifiedErrors += 1;
852
- const item = record2(entry.item);
853
- if (item && (entryType === "item.started" || entryType === "item.completed")) {
854
- addCodexExecItem(metrics, startedToolIds, entryType, item);
855
- }
856
- if (entryType === "response_item") {
857
- if (payloadType === "function_call" || payloadType === "custom_tool_call")
858
- metrics.toolCalls += 1;
859
- if (payloadType === "function_call_output" || payloadType === "custom_tool_call_output")
860
- metrics.toolOutputs += 1;
861
- if (payloadType === "reasoning") metrics.reasoningItems += 1;
862
- if (payloadType === "message" && stringField2(payload, "role") === "assistant")
863
- metrics.assistantMessages += 1;
864
- }
865
- if (entryType === "event_msg") {
866
- if (payloadType === "user_message") metrics.userMessages += 1;
867
- if (payloadType === "agent_message") metrics.assistantMessages += 1;
868
- if (payloadType === "task_started") {
869
- metrics.turnsStarted += 1;
870
- const started = timestampMs(payload.started_at);
871
- if (started !== void 0) {
872
- startedAt = startedAt === void 0 ? started : Math.min(startedAt, started);
873
- }
874
- }
875
- if (payloadType === "task_complete") {
876
- metrics.turnsCompleted += 1;
877
- const completed = timestampMs(payload.completed_at);
878
- if (completed !== void 0) {
879
- completedAt = completedAt === void 0 ? completed : Math.max(completedAt, completed);
880
- }
881
- const duration = numberField2(payload, "duration_ms");
882
- if (duration !== void 0) metrics.wallMs = Math.max(metrics.wallMs, duration);
883
- }
884
- if (payloadType === "turn_aborted") {
885
- metrics.turnsAborted += 1;
886
- const completed = timestampMs(payload.completed_at);
887
- if (completed !== void 0) {
888
- completedAt = completedAt === void 0 ? completed : Math.max(completedAt, completed);
889
- }
890
- }
891
- if (payloadType === "context_compacted") metrics.contextCompactions += 1;
892
- if (payloadType === "patch_apply_end") {
893
- metrics.patchAttempts += 1;
894
- if (payload.success === true) metrics.patchSuccesses += 1;
895
- else {
896
- metrics.patchFailures += 1;
897
- metrics.toolErrors += 1;
898
- }
899
- }
900
- if (payloadType === "token_count")
901
- setCodexCumulativeUsage(metrics, record2(record2(payload.info)?.total_token_usage));
902
- const result = record2(payload.result);
903
- if (result && "Err" in result) metrics.unclassifiedErrors += 1;
904
- }
905
- }
906
- if (metrics.wallMs === 0 && startedAt !== void 0 && completedAt !== void 0) {
907
- metrics.wallMs = Math.max(0, completedAt - startedAt);
908
- }
909
- metrics.processScore = codexProcessScore(metrics);
910
- return metrics;
911
- }
912
- function addCodexExecItem(metrics, startedToolIds, eventType, item) {
913
- const itemType = stringField2(item, "type");
914
- const itemId = stringField2(item, "id");
915
- const isTool = itemType === "command_execution" || itemType === "mcp_tool_call" || itemType === "collab_tool_call" || itemType === "web_search";
916
- if (eventType === "item.started" && isTool) {
917
- metrics.toolCalls += 1;
918
- if (itemId) startedToolIds.add(itemId);
919
- }
920
- if (eventType === "item.completed" && isTool) {
921
- if (!itemId || !startedToolIds.has(itemId)) metrics.toolCalls += 1;
922
- metrics.toolOutputs += 1;
923
- }
924
- if (eventType !== "item.completed") return;
925
- if (itemType === "agent_message" || itemType === "message") metrics.assistantMessages += 1;
926
- if (itemType === "reasoning") metrics.reasoningItems += 1;
927
- if (itemType === "file_change") {
928
- metrics.patchAttempts += 1;
929
- const status = stringField2(item, "status");
930
- if (status === "completed") metrics.patchSuccesses += 1;
931
- if (status === "failed") {
932
- metrics.patchFailures += 1;
933
- metrics.toolErrors += 1;
934
- }
935
- }
936
- if (itemType === "error") metrics.unclassifiedErrors += 1;
937
- else if (codexExecToolFailed(itemType, item)) metrics.toolErrors += 1;
938
- }
939
- function codexExecToolFailed(itemType, item) {
940
- const status = stringField2(item, "status");
941
- if (itemType === "command_execution") {
942
- const exitCode = numberField2(item, "exit_code");
943
- return status === "failed" || status === "declined" || exitCode !== void 0 && exitCode !== 0;
944
- }
945
- if (itemType === "mcp_tool_call") return status === "failed" || record2(item.error) !== null;
946
- return itemType === "collab_tool_call" && status === "failed";
947
- }
948
- function addCodexExecUsage(metrics, usage) {
949
- const parsed = readUsage(usage);
950
- metrics.inputTokens += parsed.input;
951
- metrics.outputTokens += parsed.output;
952
- metrics.reasoningTokens += parsed.reasoning;
953
- metrics.cachedTokens += parsed.cached;
954
- metrics.cacheWriteTokens += parsed.cacheWrite;
955
- }
956
- function setCodexCumulativeUsage(metrics, usage) {
957
- const parsed = readUsage(usage);
958
- metrics.inputTokens = Math.max(metrics.inputTokens, parsed.input);
959
- metrics.outputTokens = Math.max(metrics.outputTokens, parsed.output);
960
- metrics.reasoningTokens = Math.max(metrics.reasoningTokens, parsed.reasoning);
961
- metrics.cachedTokens = Math.max(metrics.cachedTokens, parsed.cached);
962
- metrics.cacheWriteTokens = Math.max(metrics.cacheWriteTokens, parsed.cacheWrite);
963
- }
964
- function claudeCodeMetrics(entries) {
965
- const metrics = emptyMetrics(entries.length);
966
- let startedAt;
967
- let completedAt;
968
- for (const entry of entries) {
969
- const type = stringField2(entry, "type");
970
- const timestamp2 = timestampMs(entry.timestamp);
971
- if (timestamp2 !== void 0) {
972
- startedAt = startedAt === void 0 ? timestamp2 : Math.min(startedAt, timestamp2);
973
- completedAt = completedAt === void 0 ? timestamp2 : Math.max(completedAt, timestamp2);
974
- }
975
- if (type === "user") metrics.userMessages += 1;
976
- if (type === "assistant") metrics.assistantMessages += 1;
977
- if (type === "pr-link") metrics.prLinks += 1;
978
- if (type === "file-history-snapshot") metrics.fileSnapshots += 1;
979
- const message = record2(entry.message);
980
- if (message) addUsage(metrics, record2(message.usage));
981
- const content = Array.isArray(message?.content) ? message.content : [];
982
- for (const item of content) {
983
- const part = record2(item);
984
- if (!part) continue;
985
- const partType = stringField2(part, "type");
986
- if (partType === "thinking") metrics.reasoningItems += 1;
987
- if (partType === "tool_use") metrics.toolCalls += 1;
988
- if (partType === "tool_result") {
989
- metrics.toolOutputs += 1;
990
- if (part.is_error === true) metrics.toolErrors += 1;
991
- }
992
- }
993
- }
994
- if (startedAt !== void 0 && completedAt !== void 0)
995
- metrics.wallMs = Math.max(0, completedAt - startedAt);
996
- metrics.processScore = claudeProcessScore(metrics);
997
- return metrics;
998
- }
999
- function openCodeMetrics(entries) {
1000
- const metrics = emptyMetrics(entries.length);
1001
- const messageUsage = emptyTokenTotals();
1002
- const partUsage = emptyTokenTotals();
1003
- let messageCost = 0;
1004
- let partCost = 0;
1005
- let messageCostCaptured = false;
1006
- let partCostCaptured = false;
1007
- let startedAt;
1008
- let completedAt;
1009
- for (const entry of entries) {
1010
- const time = record2(entry.time);
1011
- const created = timestampMs(time?.created);
1012
- const completed = timestampMs(time?.completed);
1013
- if (created !== void 0)
1014
- startedAt = startedAt === void 0 ? created : Math.min(startedAt, created);
1015
- if (completed !== void 0)
1016
- completedAt = completedAt === void 0 ? completed : Math.max(completedAt, completed);
1017
- const role = stringField2(entry, "role");
1018
- if (role === "user") metrics.userMessages += 1;
1019
- if (role === "assistant") {
1020
- metrics.assistantMessages += 1;
1021
- const finish = stringField2(entry, "finish");
1022
- if (finish === "stop") metrics.turnsCompleted += 1;
1023
- if (finish === "error") metrics.turnsAborted += 1;
1024
- }
1025
- const type = stringField2(entry, "type");
1026
- if (type === "reasoning") metrics.reasoningItems += 1;
1027
- if (type === "tool") {
1028
- metrics.toolCalls += 1;
1029
- const status = stringField2(record2(entry.state) ?? {}, "status");
1030
- if (status === "completed") metrics.toolOutputs += 1;
1031
- if (status === "error") {
1032
- metrics.toolOutputs += 1;
1033
- metrics.toolErrors += 1;
1034
- }
1035
- }
1036
- if (type === "patch") {
1037
- metrics.patchAttempts += 1;
1038
- metrics.patchSuccesses += 1;
1039
- }
1040
- const cost = numberField2(entry, "cost");
1041
- if (record2(entry.tokens) && role) {
1042
- addUsageTo(messageUsage, record2(entry.tokens));
1043
- if (cost !== void 0) {
1044
- messageCost += cost;
1045
- messageCostCaptured = true;
1046
- }
1047
- } else if (record2(entry.tokens)) {
1048
- addUsageTo(partUsage, record2(entry.tokens));
1049
- if (cost !== void 0) {
1050
- partCost += cost;
1051
- partCostCaptured = true;
1052
- }
1053
- }
1054
- }
1055
- const usage = hasTokenTotals(messageUsage) ? messageUsage : partUsage;
1056
- metrics.inputTokens = usage.input;
1057
- metrics.outputTokens = usage.output;
1058
- metrics.reasoningTokens = usage.reasoning;
1059
- metrics.cachedTokens = usage.cached;
1060
- metrics.cacheWriteTokens = usage.cacheWrite;
1061
- metrics.observedCostUsd = messageCostCaptured ? messageCost : partCost;
1062
- metrics.observedCostCaptured = messageCostCaptured || partCostCaptured;
1063
- if (metrics.wallMs === 0 && startedAt !== void 0 && completedAt !== void 0)
1064
- metrics.wallMs = Math.max(0, completedAt - startedAt);
1065
- metrics.processScore = terminalProcessScore(metrics);
1066
- return metrics;
1067
- }
1068
- function kimiCodeMetrics(entries) {
1069
- const metrics = emptyMetrics(entries.length);
1070
- let startedAt;
1071
- let completedAt;
1072
- for (const entry of entries) {
1073
- const timestamp2 = timestampMs(entry.timestamp);
1074
- if (timestamp2 !== void 0) {
1075
- startedAt = startedAt === void 0 ? timestamp2 : Math.min(startedAt, timestamp2);
1076
- completedAt = completedAt === void 0 ? timestamp2 : Math.max(completedAt, timestamp2);
1077
- }
1078
- const role = stringField2(entry, "role");
1079
- if (role === "user") metrics.userMessages += 1;
1080
- if (role === "assistant") metrics.assistantMessages += 1;
1081
- if (role === "_usage") addUsage(metrics, entry);
1082
- const message = record2(entry.message);
1083
- const messageType = message ? stringField2(message, "type") : void 0;
1084
- const payload = record2(message?.payload) ?? {};
1085
- if (messageType === "TurnBegin") {
1086
- metrics.userMessages += 1;
1087
- metrics.turnsStarted += 1;
1088
- }
1089
- if (messageType === "TurnEnd") metrics.turnsCompleted += 1;
1090
- if (messageType === "StepInterrupted") metrics.turnsAborted += 1;
1091
- if (messageType === "StepBegin") metrics.reasoningItems += 1;
1092
- if (messageType === "ContentPart") {
1093
- const payloadType = stringField2(payload, "type");
1094
- if (payloadType === "think") metrics.reasoningItems += 1;
1095
- if (payloadType === "text") metrics.assistantMessages += 1;
1096
- }
1097
- if (messageType === "ToolCall") metrics.toolCalls += 1;
1098
- if (messageType === "ToolResult") {
1099
- metrics.toolOutputs += 1;
1100
- if (record2(payload.return_value)?.is_error === true) metrics.toolErrors += 1;
1101
- }
1102
- if (messageType === "StatusUpdate") addUsage(metrics, record2(payload.token_usage));
1103
- if (messageType === "Notification") {
1104
- const notification = record2(payload.payload);
1105
- const exitCode = numberField2(notification ?? {}, "exit_code");
1106
- if (notification?.timed_out === true || exitCode !== void 0 && exitCode !== 0) {
1107
- metrics.toolErrors += 1;
1108
- }
1109
- }
1110
- }
1111
- if (startedAt !== void 0 && completedAt !== void 0)
1112
- metrics.wallMs = Math.max(0, completedAt - startedAt);
1113
- metrics.processScore = terminalProcessScore(metrics);
1114
- return metrics;
1115
- }
1116
- function piMetrics(entries) {
1117
- const metrics = emptyMetrics(entries.length);
1118
- let bestReliabilityScore;
1119
- for (const entry of entries) {
1120
- const nodes = Array.isArray(entry.nodes) ? entry.nodes : [];
1121
- const edges = Array.isArray(entry.edges) ? entry.edges : [];
1122
- metrics.graphNodes += nodes.length;
1123
- metrics.graphEdges += edges.length;
1124
- for (const node of nodes) {
1125
- const obj = record2(node);
1126
- const ir = record2(obj?.ir) ?? obj;
1127
- const kind = stringField2(ir ?? {}, "kind");
1128
- if (kind === "ActionCandidate") metrics.actionCandidates += 1;
1129
- if (kind === "ToolInvocation") metrics.toolCalls += 1;
1130
- if (kind === "ToolResult") metrics.toolOutputs += 1;
1131
- if (kind === "VerificationReport") metrics.verificationReports += 1;
1132
- if (kind === "CompletionDecision") {
1133
- metrics.completionDecisions += 1;
1134
- metrics.turnsCompleted += 1;
1135
- }
1136
- }
1137
- const averageReliability = numberField2(entry, "averageNodeReliability");
1138
- if (averageReliability !== void 0)
1139
- bestReliabilityScore = maxOptional(bestReliabilityScore, averageReliability);
1140
- const pessimisticPath = numberField2(entry, "pessimisticPathEstimate");
1141
- if (pessimisticPath !== void 0)
1142
- bestReliabilityScore = maxOptional(bestReliabilityScore, pessimisticPath);
1143
- const rows = Array.isArray(entry.rows) ? entry.rows : [];
1144
- metrics.reliabilityRows += rows.length;
1145
- for (const row of rows) {
1146
- const obj = record2(row);
1147
- if (!obj) continue;
1148
- const lift = numberField2(obj, "lift");
1149
- if (lift !== void 0) metrics.reliabilityLift = Math.max(metrics.reliabilityLift, lift);
1150
- const validated = numberField2(obj, "validatedSuccessEstimate");
1151
- if (validated !== void 0)
1152
- bestReliabilityScore = maxOptional(bestReliabilityScore, validated);
1153
- }
1154
- }
1155
- metrics.processScore = bestReliabilityScore !== void 0 ? clamp01(bestReliabilityScore) : metrics.completionDecisions > 0 ? 1 : 0;
1156
- return metrics;
1157
- }
1158
- function emptyMetrics(entries) {
1159
- return {
1160
- entries,
1161
- userMessages: 0,
1162
- assistantMessages: 0,
1163
- reasoningItems: 0,
1164
- toolCalls: 0,
1165
- toolOutputs: 0,
1166
- toolErrors: 0,
1167
- unclassifiedErrors: 0,
1168
- patchAttempts: 0,
1169
- patchSuccesses: 0,
1170
- patchFailures: 0,
1171
- turnsStarted: 0,
1172
- turnsCompleted: 0,
1173
- turnsAborted: 0,
1174
- contextCompactions: 0,
1175
- mcpCalls: 0,
1176
- subagentCalls: 0,
1177
- skillCalls: 0,
1178
- hookCalls: 0,
1179
- webCalls: 0,
1180
- codeActions: 0,
1181
- prLinks: 0,
1182
- fileSnapshots: 0,
1183
- graphNodes: 0,
1184
- graphEdges: 0,
1185
- actionCandidates: 0,
1186
- verificationReports: 0,
1187
- completionDecisions: 0,
1188
- reliabilityRows: 0,
1189
- reliabilityLift: 0,
1190
- inputTokens: 0,
1191
- outputTokens: 0,
1192
- reasoningTokens: 0,
1193
- cachedTokens: 0,
1194
- cacheWriteTokens: 0,
1195
- observedCostUsd: 0,
1196
- observedCostCaptured: false,
1197
- wallMs: 0,
1198
- processScore: 0
1199
- };
1200
- }
1201
- function codexProcessScore(metrics) {
1202
- const terminalTurns = metrics.turnsCompleted + metrics.turnsAborted;
1203
- const base = terminalTurns > 0 ? metrics.turnsCompleted / terminalTurns : metrics.assistantMessages > 0 ? 0.5 : 0;
1204
- return penalizeErrors(base, metrics);
1205
- }
1206
- function claudeProcessScore(metrics) {
1207
- const base = metrics.prLinks > 0 ? 1 : metrics.assistantMessages > 0 ? 0.75 : 0;
1208
- return penalizeErrors(base, metrics);
1209
- }
1210
- function terminalProcessScore(metrics) {
1211
- const terminalTurns = metrics.turnsCompleted + metrics.turnsAborted;
1212
- const base = terminalTurns > 0 ? metrics.turnsCompleted / terminalTurns : metrics.assistantMessages > 0 ? 0.75 : metrics.toolCalls > 0 ? 0.5 : 0;
1213
- return penalizeErrors(base, metrics);
1214
- }
1215
- function penalizeErrors(base, metrics) {
1216
- const operations = Math.max(1, metrics.toolCalls + metrics.patchAttempts);
1217
- const errorRate = Math.min(1, (metrics.toolErrors + metrics.patchFailures) / operations);
1218
- return clamp01(base * (1 - 0.5 * errorRate));
1219
- }
1220
- function emptyTokenTotals() {
1221
- return { input: 0, output: 0, reasoning: 0, cached: 0, cacheWrite: 0 };
1222
- }
1223
- function hasTokenTotals(usage) {
1224
- return usage.input > 0 || usage.output > 0 || usage.reasoning > 0 || usage.cached > 0 || usage.cacheWrite > 0;
1225
- }
1226
- function addUsage(metrics, usage) {
1227
- const parsed = readUsage(usage);
1228
- metrics.inputTokens += parsed.input;
1229
- metrics.outputTokens += parsed.output;
1230
- metrics.reasoningTokens += parsed.reasoning;
1231
- metrics.cachedTokens += parsed.cached;
1232
- metrics.cacheWriteTokens += parsed.cacheWrite;
1233
- }
1234
- function addUsageTo(totals, usage) {
1235
- const parsed = readUsage(usage);
1236
- totals.input += parsed.input;
1237
- totals.output += parsed.output;
1238
- totals.reasoning += parsed.reasoning;
1239
- totals.cached += parsed.cached;
1240
- totals.cacheWrite += parsed.cacheWrite;
1241
- }
1242
- function readUsage(usage) {
1243
- const parsed = extractUsage(usage);
1244
- return {
1245
- input: parsed?.input ?? 0,
1246
- output: parsed?.output ?? 0,
1247
- reasoning: parsed?.reasoning ?? 0,
1248
- cached: parsed?.cached ?? 0,
1249
- cacheWrite: parsed?.cacheWrite ?? 0
1250
- };
1251
- }
1252
- function resolveSessionCost(explicit, metrics, model) {
1253
- if (explicit) {
1254
- if (explicit.kind === "uncaptured") {
1255
- if (explicit.usd !== null) throw new Error("uncaptured cost must have usd: null");
1256
- return { costUsd: null, costProvenance: explicit };
1257
- }
1258
- if (!Number.isFinite(explicit.usd) || explicit.usd < 0) {
1259
- throw new Error(`${explicit.kind} cost must be a finite, non-negative USD amount`);
1260
- }
1261
- return { costUsd: explicit.usd, costProvenance: explicit };
1262
- }
1263
- if (metrics.observedCostCaptured) {
1264
- const costProvenance = { kind: "observed", usd: metrics.observedCostUsd };
1265
- return { costUsd: metrics.observedCostUsd, costProvenance };
1266
- }
1267
- const hasUsage = metrics.inputTokens > 0 || metrics.outputTokens > 0;
1268
- if (hasUsage && isModelPriced(model)) {
1269
- const costUsd = estimateCost(metrics.inputTokens, metrics.outputTokens, model);
1270
- return { costUsd, costProvenance: { kind: "estimated", usd: costUsd } };
1271
- }
1272
- return { costUsd: null, costProvenance: { kind: "uncaptured", usd: null } };
1273
- }
1274
- function diagnosticsFor(metrics, options) {
1275
- const warnings = [];
1276
- if (options.invalidQualityScore) warnings.push("non-finite task quality score omitted");
1277
- else if (!options.hasQualityLabel) warnings.push("task quality score not supplied");
1278
- if (!options.explicitTerminal) warnings.push("no explicit terminal success/failure signal");
1279
- if (metrics.inputTokens === 0 && metrics.outputTokens === 0 && metrics.reasoningTokens === 0 && metrics.cachedTokens === 0 && metrics.cacheWriteTokens === 0) {
1280
- warnings.push("missing token usage");
1281
- }
1282
- if (options.costKind === "estimated")
1283
- warnings.push("USD cost estimated from token usage and model pricing");
1284
- if (options.costKind === "uncaptured") warnings.push("USD cost uncaptured");
1285
- if (options.costKind === "uncaptured" && !isModelPriced(options.model))
1286
- warnings.push("model pricing unknown");
1287
- if (options.malformedLines > 0)
1288
- warnings.push(`${options.malformedLines} malformed JSONL lines skipped`);
1289
- return warnings;
1290
- }
1291
- function applyObservedSurfaceMetrics(metrics, observation) {
1292
- const actions = observation.actions.filter(
1293
- (action) => action.kind === "tool" || action.kind === "patch"
1294
- );
1295
- metrics.mcpCalls = actions.filter((action) => action.surface === "mcp").length;
1296
- metrics.subagentCalls = actions.filter((action) => action.surface === "subagent").length;
1297
- metrics.skillCalls = actions.filter((action) => action.surface === "skill").length;
1298
- metrics.hookCalls = actions.filter((action) => action.surface === "hook").length;
1299
- metrics.webCalls = actions.filter((action) => action.surface === "web").length;
1300
- metrics.codeActions = actions.filter((action) => action.surface === "code").length;
1301
- }
1302
- function sessionIdFromEntries2(source, entries) {
1303
- for (const entry of entries) {
1304
- if (source === "codex") {
1305
- const threadId = stringField2(entry, "thread_id");
1306
- if (threadId) return threadId;
1307
- const payload2 = record2(entry.payload);
1308
- const id = payload2 ? stringField2(payload2, "id") : void 0;
1309
- if (id) return id;
1310
- }
1311
- const message = record2(entry.message);
1312
- const payload = record2(message?.payload);
1313
- const sessionId = stringField2(entry, "sessionID") ?? stringField2(entry, "sessionId") ?? stringField2(entry, "session_id") ?? stringField2(payload ?? {}, "session_id");
1314
- if (sessionId) return sessionId;
1315
- }
1316
- return void 0;
1317
- }
1318
- function modelFromEntries(source, entries) {
1319
- let providerModel;
1320
- for (const entry of entries) {
1321
- if (source === "codex") {
1322
- const payload = record2(entry.payload);
1323
- const model2 = payload ? stringField2(payload, "model") : void 0;
1324
- if (model2) return model2;
1325
- providerModel = providerModel ?? (payload ? stringField2(payload, "model_provider") : void 0);
1326
- }
1327
- const openCodeModel = stringField2(entry, "modelID");
1328
- if (openCodeModel) {
1329
- const provider = stringField2(entry, "providerID");
1330
- return provider ? `${provider}/${openCodeModel}` : openCodeModel;
1331
- }
1332
- const modelObject = record2(entry.model);
1333
- const nestedModel = stringField2(modelObject ?? {}, "modelID");
1334
- if (nestedModel) {
1335
- const provider = stringField2(modelObject ?? {}, "providerID");
1336
- return provider ? `${provider}/${nestedModel}` : nestedModel;
1337
- }
1338
- const message = record2(entry.message);
1339
- const model = message ? stringField2(message, "model") : void 0;
1340
- if (model) return model;
1341
- }
1342
- return providerModel;
1343
- }
1344
- function cwdFromEntries(entries) {
1345
- for (const entry of entries) {
1346
- const path = record2(entry.path);
1347
- const cwd = stringField2(entry, "cwd") ?? stringField2(path ?? {}, "cwd") ?? stringField2(path ?? {}, "root") ?? (record2(entry.payload) ? stringField2(record2(entry.payload), "cwd") : void 0);
1348
- if (cwd) return cwd;
1349
- }
1350
- return void 0;
1351
- }
1352
- function firstUserText(entries) {
1353
- for (const entry of entries) {
1354
- const payload = record2(entry.payload);
1355
- const payloadType = payload ? stringField2(payload, "type") : void 0;
1356
- if (payloadType === "user_message") return stringField2(payload, "message");
1357
- if (stringField2(entry, "role") === "user") {
1358
- const content = entry.content;
1359
- if (typeof content === "string") return content;
1360
- }
1361
- const wirePayload = record2(record2(entry.message)?.payload);
1362
- const userInput = wirePayload ? stringField2(wirePayload, "user_input") : void 0;
1363
- if (userInput) return userInput;
1364
- const message = record2(entry.message);
1365
- if (message && stringField2(message, "role") === "user") {
1366
- const content = message.content;
1367
- if (typeof content === "string") return content;
1368
- if (Array.isArray(content)) {
1369
- const text = content.map((part) => {
1370
- const obj = record2(part);
1371
- return obj ? stringField2(obj, "text") : void 0;
1372
- }).filter((part) => part !== void 0).join("\n");
1373
- if (text) return text;
1374
- }
1375
- }
1376
- }
1377
- return void 0;
1378
- }
1379
- function fallbackSessionId2(source, sourcePath) {
1380
- return hashString(`${source}:${sourcePath ?? "unknown-session"}`).slice(
1381
- "sha256:".length,
1382
- "sha256:".length + 20
1383
- );
1384
- }
1385
- function withSnapshot(model) {
1386
- const trimmed = model.trim() || "unknown";
1387
- if (trimmed.includes("@") || /-\d{8}$/.test(trimmed) || /-\d{4}-\d{2}-\d{2}$/.test(trimmed)) {
1388
- return trimmed;
1389
- }
1390
- return `${trimmed}@observed-local`;
1391
- }
1392
- function hashJson(value) {
1393
- return hashString(JSON.stringify(value));
1394
- }
1395
- function hashString(value) {
1396
- return `sha256:${createHash("sha256").update(value).digest("hex")}`;
1397
- }
1398
- function stableSeed(value) {
1399
- return createHash("sha256").update(value).digest().readUInt32BE(0);
1400
- }
1401
- function maxOptional(current, next) {
1402
- return current === void 0 ? next : Math.max(current, next);
1403
- }
1404
- function clamp01(value) {
1405
- if (!Number.isFinite(value)) return 0;
1406
- return Math.max(0, Math.min(1, value));
1407
- }
1408
- function finiteScore(value) {
1409
- return value !== void 0 && Number.isFinite(value) ? clamp01(value) : void 0;
1410
- }
1411
- function isRecord2(value) {
1412
- return value !== null && typeof value === "object" && !Array.isArray(value);
1413
- }
1414
- function record2(value) {
1415
- return isRecord2(value) ? value : null;
1416
- }
1417
- function stringField2(obj, key) {
1418
- const value = obj[key];
1419
- return typeof value === "string" && value.length > 0 ? value : void 0;
1420
- }
1421
- function numberField2(obj, key) {
1422
- const value = obj[key];
1423
- return typeof value === "number" && Number.isFinite(value) ? value : void 0;
1424
- }
1425
- function timestampMs(value) {
1426
- if (typeof value === "number" && Number.isFinite(value)) {
1427
- return value > 1e12 ? value : value * 1e3;
1428
- }
1429
- if (typeof value === "string" && value.length > 0) {
1430
- const parsed = Date.parse(value);
1431
- return Number.isFinite(parsed) ? parsed : void 0;
1432
- }
1433
- return void 0;
1434
- }
1435
-
1436
- export {
1437
- observeCodeAgentSession,
1438
- parseCodeAgentJsonl,
1439
- fromCodexSession,
1440
- fromClaudeCodeSession,
1441
- fromOpenCodeSession,
1442
- fromKimiCodeSession,
1443
- fromPiSession,
1444
- fromPigraphSession
1445
- };
1446
- //# sourceMappingURL=chunk-SZLVEKMJ.js.map