@iowarp/clio-coder 0.4.2 → 0.4.3

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 (369) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/CONTRIBUTING.md +86 -19
  3. package/README.md +35 -6
  4. package/dist/{acp-TMDQZDIG.js → acp-H2NGRPWO.js} +11 -11
  5. package/dist/{agents-5N5NG3XG.js → agents-TL5LLUQP.js} +54 -53
  6. package/dist/assets/codewiki.json +1 -1
  7. package/dist/{auth-Z5CCBXKQ.js → auth-E5SW4HMS.js} +19 -16
  8. package/dist/{builtins-K6TNDT24.js → builtins-IA7V7FUC.js} +9 -4
  9. package/dist/{chunk-ZW4HH5JJ.js → chunk-2APPQIER.js} +6 -6
  10. package/dist/{chunk-72GZI5EV.js → chunk-2JH2WHGE.js} +2 -2
  11. package/dist/{chunk-UBRFI4HS.js → chunk-2UG5F4C5.js} +127 -47
  12. package/dist/{chunk-UH632ZYL.js → chunk-2UH2KFUP.js} +2 -2
  13. package/dist/{chunk-3F7VUY77.js → chunk-2VIKGWFZ.js} +2 -2
  14. package/dist/{chunk-I66EAJFY.js → chunk-2WZ546HR.js} +267 -232
  15. package/dist/{chunk-RKSR6VSF.js → chunk-4IUZQIJ3.js} +29 -1
  16. package/dist/{chunk-2X4RYJTJ.js → chunk-4UVU7BJ5.js} +2 -2
  17. package/dist/{chunk-M2DAX4F6.js → chunk-4WR7VSYB.js} +2 -2
  18. package/dist/{chunk-5KW52TEP.js → chunk-54CBCGIR.js} +5 -5
  19. package/dist/{chunk-3KIPBMUA.js → chunk-5ICU3EUH.js} +2 -2
  20. package/dist/{chunk-77QIVUZB.js → chunk-5MEZN6CB.js} +4 -4
  21. package/dist/{chunk-O42A54GG.js → chunk-5OIVVPHF.js} +2 -2
  22. package/dist/{chunk-LJID3DYZ.js → chunk-64I3JVYM.js} +2 -2
  23. package/dist/{chunk-4JDLP6ZS.js → chunk-6PTFB5VS.js} +7 -7
  24. package/dist/{chunk-VN3SHNBN.js → chunk-7DICMOS6.js} +2 -2
  25. package/dist/{chunk-HLAFFSEK.js → chunk-7DRAWPTZ.js} +2 -2
  26. package/dist/chunk-7E7I3WLS.js +3762 -0
  27. package/dist/{chunk-YJISEZKC.js → chunk-7ZYNNDKC.js} +6 -6
  28. package/dist/{chunk-I66ZTYNP.js → chunk-AF4YM7Z4.js} +236 -101
  29. package/dist/{chunk-2HFQNRV3.js → chunk-AX2THNSA.js} +12 -12
  30. package/dist/{chunk-PGF63K6I.js → chunk-B4OAX3SI.js} +65 -3
  31. package/dist/{chunk-W6NIE6OW.js → chunk-B4VEBZKF.js} +3 -3
  32. package/dist/{chunk-JBCS7CRR.js → chunk-BEPZRGGU.js} +10 -10
  33. package/dist/{chunk-XGDPUNND.js → chunk-CE5AX47J.js} +2 -2
  34. package/dist/{chunk-I64IFBLB.js → chunk-DWUOQKRU.js} +17 -10
  35. package/dist/{chunk-DZAW46HP.js → chunk-E3TPLWFX.js} +3 -3
  36. package/dist/{chunk-HIICAHCJ.js → chunk-EKCHAPYA.js} +2 -2
  37. package/dist/{chunk-XE3PCIXH.js → chunk-F5JHEYZM.js} +7 -7
  38. package/dist/{chunk-5PFYMY2V.js → chunk-FTMGRKEF.js} +2 -2
  39. package/dist/{chunk-ZNT2M6TG.js → chunk-G76U63X4.js} +17 -17
  40. package/dist/{chunk-34BHNEE3.js → chunk-GHS5EBTQ.js} +58 -7
  41. package/dist/{chunk-2NHR3NAY.js → chunk-GI7YYQ3F.js} +40 -34
  42. package/dist/{chunk-DYHAXKHD.js → chunk-GWZNEVM2.js} +12 -8
  43. package/dist/chunk-GYV6VZOC.js +26 -0
  44. package/dist/{chunk-MQXIVJ35.js → chunk-HAXOFFRH.js} +5 -5
  45. package/dist/{chunk-W4YEMFBX.js → chunk-HEQY7ZFI.js} +2 -2
  46. package/dist/{chunk-IKOZFYBN.js → chunk-I7ZPNEJM.js} +145 -102
  47. package/dist/{chunk-WNP7O5WZ.js → chunk-ID64D7PE.js} +4 -4
  48. package/dist/{chunk-XQRY4DTA.js → chunk-IGLP3ODT.js} +10 -10
  49. package/dist/chunk-IJNZMHLA.js +101 -0
  50. package/dist/{chunk-JWJGP5DQ.js → chunk-INY6HTFL.js} +7 -7
  51. package/dist/{chunk-PBP4B7XR.js → chunk-IUE3Y34X.js} +2 -2
  52. package/dist/{chunk-B74PXLU7.js → chunk-IWT4SF4R.js} +3 -3
  53. package/dist/{chunk-B7HM5Z7T.js → chunk-JDAY6FIL.js} +5 -5
  54. package/dist/{chunk-PJX3WQUQ.js → chunk-JEQ3XTHC.js} +2 -2
  55. package/dist/{chunk-FSP7CMNU.js → chunk-JGRC33J2.js} +50 -4
  56. package/dist/{chunk-X7IARSHT.js → chunk-JKKCYP3C.js} +9 -9
  57. package/dist/{chunk-HJWWJ6IL.js → chunk-JSC3U7TI.js} +16 -4
  58. package/dist/{chunk-SSEYRH53.js → chunk-KK4JZPBQ.js} +19 -140
  59. package/dist/{chunk-IHXBNWMM.js → chunk-KXDSS5WJ.js} +7 -3
  60. package/dist/{chunk-Q4XWMHX6.js → chunk-L47TF46W.js} +2 -2
  61. package/dist/{chunk-O3YUNJZ2.js → chunk-LDJG7DW3.js} +81 -24
  62. package/dist/{chunk-CDNVLKUX.js → chunk-LLDJM5XK.js} +13 -7
  63. package/dist/{chunk-F2I26BDK.js → chunk-MUW2BDDH.js} +4 -4
  64. package/dist/{chunk-HKMD33FO.js → chunk-MWUZBSAQ.js} +79 -76
  65. package/dist/{chunk-QQLGQY2A.js → chunk-N2Z7HLVY.js} +20 -20
  66. package/dist/{chunk-DZEK6CJN.js → chunk-NIQJ66N4.js} +19 -19
  67. package/dist/{chunk-CWVRRIEI.js → chunk-NZMNUPZZ.js} +2 -2
  68. package/dist/{chunk-462T4EGZ.js → chunk-O5CVSAG5.js} +2 -2
  69. package/dist/{chunk-TPEQIQIE.js → chunk-OML5D5V5.js} +8 -8
  70. package/dist/{chunk-IKSLQ4XV.js → chunk-PAJQJ7BS.js} +558 -216
  71. package/dist/{chunk-ZW55JB7N.js → chunk-PUVDKJ2Y.js} +2 -2
  72. package/dist/{chunk-UH347SHR.js → chunk-QWGDJJYJ.js} +11 -11
  73. package/dist/chunk-R6Q67RJH.js +134 -0
  74. package/dist/{chunk-CRFOIAX3.js → chunk-RRNP2ANY.js} +6 -6
  75. package/dist/{chunk-IDNA72AH.js → chunk-RSJ25QSL.js} +2 -2
  76. package/dist/chunk-SKHCAU7K.js +385 -0
  77. package/dist/{chunk-RLYRBIYQ.js → chunk-TM6LQDI3.js} +20 -12
  78. package/dist/chunk-UOIZ7DA4.js +41 -0
  79. package/dist/{chunk-P75RZCJW.js → chunk-UPZU6GE4.js} +3 -3
  80. package/dist/{chunk-MCMZMDAC.js → chunk-V2ANDPVT.js} +4 -4
  81. package/dist/{chunk-AK5XEFVZ.js → chunk-VA5FNYMT.js} +26 -13
  82. package/dist/{chunk-IMXMHHMQ.js → chunk-VW6DOEDG.js} +332 -57
  83. package/dist/{chunk-XOXV5GKE.js → chunk-W6RRQCPQ.js} +16 -7
  84. package/dist/{chunk-CYZW7JHJ.js → chunk-WBKFA554.js} +8 -8
  85. package/dist/{chunk-BO7Y52RY.js → chunk-WCXUNS7U.js} +7 -7
  86. package/dist/{chunk-ZGNYYXQ6.js → chunk-WRBAGUNF.js} +3 -3
  87. package/dist/{chunk-FVDGR2ZL.js → chunk-XIVNBFZS.js} +85 -30
  88. package/dist/{chunk-BYMNWQ7O.js → chunk-XPWWI35G.js} +299 -58
  89. package/dist/{chunk-KPXDY6QF.js → chunk-XRZT5WY5.js} +2 -2
  90. package/dist/{chunk-AZ4WMN4W.js → chunk-Y3CBHOR6.js} +2 -2
  91. package/dist/{chunk-VXMFAE2W.js → chunk-YPC6ZR5L.js} +19 -6
  92. package/dist/{chunk-54ODD65L.js → chunk-YQWYVTMC.js} +4 -4
  93. package/dist/{chunk-M2WXEHER.js → chunk-ZA4VCIGV.js} +2 -2
  94. package/dist/{chunk-7BHIY2MW.js → chunk-ZDN3Y73Y.js} +6 -6
  95. package/dist/{chunk-E7GT7O5N.js → chunk-ZWPRK62N.js} +7 -4
  96. package/dist/cli/index.js +38 -37
  97. package/dist/{clio-7VB377CC.js → clio-CMMK4KRR.js} +7 -7
  98. package/dist/{code-nav-YVLCYA7V.js → code-nav-MDZNQS33.js} +7 -7
  99. package/dist/{components-UBWCQSRW.js → components-UCUQ4QXW.js} +4 -4
  100. package/dist/{config-4HVOS65E.js → config-SVM5P5YI.js} +76 -74
  101. package/dist/{configure-PIWO7B24.js → configure-LE3IK2TJ.js} +26 -24
  102. package/dist/{context-IYEHL3WQ.js → context-2OHRKS42.js} +66 -63
  103. package/dist/{context-N6ZE3LGJ.js → context-E3VC7RX5.js} +15 -11
  104. package/dist/{context-KQYIWPWT.js → context-VNCR7KAG.js} +60 -45
  105. package/dist/{context-clear-G4OGZJDS.js → context-clear-BW4O37TG.js} +61 -59
  106. package/dist/context-map-COB37XXN.js +505 -0
  107. package/dist/{context-working-set-BWLF6LJP.js → context-working-set-VDS25HXZ.js} +17 -16
  108. package/dist/{dispatch-runner-2QQAITS3.js → dispatch-runner-5AHT53RF.js} +85 -74
  109. package/dist/{doctor-LHBD36VU.js → doctor-WNNVO6FY.js} +37 -37
  110. package/dist/{eval-C45FYRJ6.js → eval-7G7SGAYO.js} +285 -114
  111. package/dist/{eval-inventory-6DEJPLBF.js → eval-inventory-Y6QRFOH5.js} +4 -4
  112. package/dist/{evidence-6SHONYAF.js → evidence-VD6736FQ.js} +63 -62
  113. package/dist/{evolve-KRKMV72X.js → evolve-AL3NGVRL.js} +62 -61
  114. package/dist/{extensions-KPZ2UHBB.js → extensions-MOVJ32NM.js} +7 -7
  115. package/dist/{fleet-IVTCKDHT.js → fleet-QZHUMAGI.js} +110 -108
  116. package/dist/{fleet-commands-EDWL3IT7.js → fleet-commands-BAYT5FJZ.js} +10 -10
  117. package/dist/{fleet-decisions-YP3YEFGK.js → fleet-decisions-IREVMRU4.js} +7 -6
  118. package/dist/{fleet-graph-ZFWKHY2M.js → fleet-graph-YCTT3HTI.js} +19 -18
  119. package/dist/{fleet-inspect-FVUNCBML.js → fleet-inspect-QVJTDAVB.js} +55 -54
  120. package/dist/{fleet-preflight-UN5XED4R.js → fleet-preflight-25QAFPK4.js} +4 -4
  121. package/dist/{fleet-validate-XOWC4HSX.js → fleet-validate-5O57AAJ7.js} +23 -22
  122. package/dist/{fleet-verify-UN3SODEL.js → fleet-verify-CPH2W2T6.js} +56 -55
  123. package/dist/{fleet-view-TWHJKCN6.js → fleet-view-SWBR3VGQ.js} +55 -54
  124. package/dist/{init-T2QORQ3Y.js → init-J477LKZH.js} +78 -76
  125. package/dist/{interop-IN5I2A66.js → interop-3FCM6XLG.js} +11 -11
  126. package/dist/{library-LSCATDLZ.js → library-QUQEIUG6.js} +28 -27
  127. package/dist/{memory-HYOKAGGJ.js → memory-SGGSEP65.js} +64 -63
  128. package/dist/{models-2GPMFYCM.js → models-HEKUAXXK.js} +49 -43
  129. package/dist/{monitor-E4ASVUJH.js → monitor-HKU57TYQ.js} +61 -60
  130. package/dist/{orchestrator-DDMPR3PY.js → orchestrator-VDFAEFAI.js} +919 -546
  131. package/dist/{panes-E3RUXOW5.js → panes-DN2SSFOH.js} +3 -3
  132. package/dist/{panes-IXKLOKA2.js → panes-TALGNPZT.js} +8 -8
  133. package/dist/{paths-L7LGY6RN.js → paths-NBMFAIEZ.js} +5 -5
  134. package/dist/reset-EAJFFJVB.js +344 -0
  135. package/dist/{resources-OTRSN34L.js → resources-OVKSEFVE.js} +27 -20
  136. package/dist/{run-5DEYH5QK.js → run-7DP7ZF2J.js} +113 -109
  137. package/dist/{share-IHWTLO3M.js → share-WML67FT3.js} +26 -25
  138. package/dist/{skills-IYMXMKW4.js → skills-SG662R2K.js} +39 -31
  139. package/dist/{skills-eval-DROHSJAR.js → skills-eval-VVZEUU46.js} +74 -73
  140. package/dist/{skills-inventory-D7X4L4ZX.js → skills-inventory-I2E23GET.js} +21 -20
  141. package/dist/{slash-commands-QBM7UZ3B.js → slash-commands-S7MBJDQK.js} +35 -34
  142. package/dist/{steer-Z5DO23FJ.js → steer-2LQOMCPB.js} +3 -3
  143. package/dist/{support-U7QOWY26.js → support-CC2UJBJ6.js} +6 -6
  144. package/dist/{targets-P2FUC4IL.js → targets-4QC3HIEW.js} +48 -45
  145. package/dist/{terminal-lease-YREJ3JX2.js → terminal-lease-TUHIJ6Y2.js} +2 -2
  146. package/dist/{tools-5B7RO6MV.js → tools-TFGJICCU.js} +8 -8
  147. package/dist/{trace-YMGMUM6A.js → trace-FXMXUZUF.js} +7 -7
  148. package/dist/uninstall-5PEVOE5B.js +408 -0
  149. package/dist/upgrade-M4WXY6KN.js +303 -0
  150. package/dist/{usage-ME5MPXGX.js → usage-N7ZNVLEM.js} +147 -102
  151. package/dist/{verifiers-BVZ7IWOO.js → verifiers-DJTP4XX6.js} +15 -15
  152. package/dist/{verify-5K7ZKQFC.js → verify-RWE4PPEK.js} +9 -9
  153. package/dist/{wiki-generate-F5W5QTYY.js → wiki-generate-C7IQOXSP.js} +84 -82
  154. package/dist/{with-panes-BYOJCLAM.js → with-panes-4GCGSL7J.js} +9 -9
  155. package/dist/worker/entry.js +61 -60
  156. package/docs/architecture/artifact-placement.md +1 -0
  157. package/docs/architecture/artifact-versions.md +1 -1
  158. package/docs/architecture/context-engine.md +4 -0
  159. package/docs/architecture/middleware-and-components.md +1 -1
  160. package/docs/architecture/model-catalog.md +21 -10
  161. package/docs/architecture/observability.md +12 -1
  162. package/docs/architecture/prompt-envelope-and-tools.md +2 -0
  163. package/docs/architecture/provider-adapter-cookbook.md +63 -0
  164. package/docs/architecture/safety-model.md +15 -5
  165. package/docs/guide/built-in-agents.md +17 -3
  166. package/docs/guide/commands-and-modes.md +1 -1
  167. package/docs/guide/configuration-and-targets.md +97 -9
  168. package/docs/guide/configuration-reference.md +7 -2
  169. package/docs/guide/environment-variables.md +2 -0
  170. package/docs/guide/installation-and-lifecycle.md +37 -4
  171. package/docs/guide/proactive-memory.md +66 -55
  172. package/docs/guide/skills-marketplace.md +18 -0
  173. package/docs/process/development-pipeline.md +34 -1
  174. package/docs/process/eval-runner.md +67 -3
  175. package/evals/behavioral-model.yaml +3 -2
  176. package/package.json +2 -2
  177. package/skills/README.md +7 -5
  178. package/skills/coding/ast-grep/SKILL.md +101 -30
  179. package/skills/coding/ast-grep/evals.md +26 -0
  180. package/skills/coding/coding-standards/SKILL.md +40 -5
  181. package/skills/coding/coding-standards/evals.md +23 -0
  182. package/skills/coding/prototype/SKILL.md +87 -28
  183. package/skills/coding/prototype/evals.md +19 -0
  184. package/skills/coding/tdd/SKILL.md +80 -53
  185. package/skills/coding/tdd/evals.md +20 -0
  186. package/skills/context/context-handoff/SKILL.md +43 -2
  187. package/skills/context/context-handoff/evals.md +44 -0
  188. package/skills/context/context-prime/SKILL.md +45 -15
  189. package/skills/context/context-prime/evals.md +45 -0
  190. package/skills/git/branch-closeout/SKILL.md +132 -0
  191. package/skills/git/branch-closeout/evals.md +133 -0
  192. package/skills/git/branch-closeout/references/closeout-checklist.md +81 -0
  193. package/skills/git/file-ticket/SKILL.md +77 -63
  194. package/skills/git/file-ticket/assets/issue-template.md +22 -0
  195. package/skills/git/file-ticket/evals.md +31 -26
  196. package/skills/git/file-ticket/references/issue-discovery.md +49 -0
  197. package/skills/git/fix-issue/SKILL.md +87 -64
  198. package/skills/git/fix-issue/evals.md +35 -31
  199. package/skills/git/fix-issue/references/diagnosis-and-rca.md +46 -0
  200. package/skills/git/resolve-merge-conflicts/SKILL.md +100 -51
  201. package/skills/git/resolve-merge-conflicts/evals.md +52 -25
  202. package/skills/git/resolve-merge-conflicts/references/conflict-matrix.md +126 -0
  203. package/skills/git/ship/SKILL.md +103 -67
  204. package/skills/git/ship/assets/pr-template.md +21 -0
  205. package/skills/git/ship/evals.md +44 -28
  206. package/skills/git/ship/references/remote-and-branch-policy.md +62 -0
  207. package/skills/git/worktree-create/SKILL.md +80 -50
  208. package/skills/git/worktree-create/evals.md +40 -33
  209. package/skills/git/worktree-create/references/worktree-setup.md +62 -66
  210. package/skills/git/worktree-merge/SKILL.md +112 -65
  211. package/skills/git/worktree-merge/evals.md +42 -34
  212. package/skills/git/worktree-merge/references/merge-strategies.md +52 -0
  213. package/skills/planning/archify/SKILL.md +196 -0
  214. package/skills/planning/archify/evals.md +65 -0
  215. package/skills/planning/architecture/SKILL.md +61 -12
  216. package/skills/planning/architecture/evals.md +65 -0
  217. package/skills/planning/backlog/SKILL.md +130 -14
  218. package/skills/planning/backlog/evals.md +142 -0
  219. package/skills/planning/prd/SKILL.md +46 -6
  220. package/skills/planning/prd/evals.md +54 -0
  221. package/skills/planning/product-intent/SKILL.md +57 -2
  222. package/skills/planning/product-intent/evals.md +70 -0
  223. package/skills/planning/tech-spec/SKILL.md +53 -2
  224. package/skills/planning/tech-spec/evals.md +73 -0
  225. package/skills/registry.yaml +58 -50
  226. package/skills/remote.yaml +13 -0
  227. package/skills/research/arxiv-literature/SKILL.md +76 -18
  228. package/skills/research/arxiv-literature/evals.md +50 -0
  229. package/skills/research/experiment-protocol/SKILL.md +20 -1
  230. package/skills/research/experiment-protocol/evals.md +23 -0
  231. package/skills/research/scientific-debugging/SKILL.md +23 -1
  232. package/skills/research/scientific-debugging/evals.md +18 -0
  233. package/skills/research/scientific-modernization/SKILL.md +26 -1
  234. package/skills/research/scientific-modernization/evals.md +27 -0
  235. package/skills/skill-marketplace.json +63 -28
  236. package/skills/workflow/cut-it/SKILL.md +65 -5
  237. package/skills/workflow/cut-it/evals.md +101 -0
  238. package/skills/workflow/design-council/SKILL.md +117 -27
  239. package/skills/workflow/design-council/evals.md +161 -0
  240. package/skills/workflow/grill-me/SKILL.md +86 -10
  241. package/skills/workflow/grill-me/evals.md +153 -0
  242. package/skills/workflow/workflow-distiller/SKILL.md +76 -17
  243. package/skills/workflow/workflow-distiller/evals.md +118 -0
  244. package/src/cli/configure-interop.ts +105 -13
  245. package/src/cli/configure-oauth.ts +57 -0
  246. package/src/cli/configure-onboarding.ts +980 -0
  247. package/src/cli/configure-target.ts +594 -0
  248. package/src/cli/configure.ts +1082 -528
  249. package/src/cli/context-map.ts +114 -0
  250. package/src/cli/context.ts +4 -0
  251. package/src/cli/index.ts +1 -0
  252. package/src/cli/lifecycle-presenter.ts +436 -0
  253. package/src/cli/models.ts +10 -2
  254. package/src/cli/modes/print.ts +5 -1
  255. package/src/cli/reset.ts +228 -106
  256. package/src/cli/run.ts +7 -2
  257. package/src/cli/select.ts +664 -0
  258. package/src/cli/skills.ts +9 -2
  259. package/src/cli/targets.ts +3 -0
  260. package/src/cli/uninstall.ts +233 -165
  261. package/src/cli/upgrade.ts +204 -149
  262. package/src/cli/usage.ts +86 -27
  263. package/src/cli/validate-model.ts +3 -3
  264. package/src/core/config.ts +56 -0
  265. package/src/core/external-diagnostic.ts +44 -0
  266. package/src/core/gateway-routing.ts +157 -0
  267. package/src/core/safe-exec.ts +17 -2
  268. package/src/core/skill-activation.ts +89 -2
  269. package/src/domains/agents/builtins/world-knowledge.md +31 -0
  270. package/src/domains/agents/catalog.ts +1 -1
  271. package/src/domains/agents/result-contract.ts +70 -0
  272. package/src/domains/context/wiki/map-seed.ts +589 -0
  273. package/src/domains/context/wiki/plan.ts +2 -2
  274. package/src/domains/dispatch/admission.ts +29 -0
  275. package/src/domains/dispatch/agent-candidates.ts +10 -0
  276. package/src/domains/dispatch/budget-envelope.ts +86 -1
  277. package/src/domains/dispatch/capability-match.ts +1 -0
  278. package/src/domains/dispatch/capacity-lease.ts +17 -0
  279. package/src/domains/dispatch/contract.ts +11 -1
  280. package/src/domains/dispatch/extension.ts +134 -29
  281. package/src/domains/dispatch/types.ts +3 -0
  282. package/src/domains/dispatch/worker-model-metadata.ts +38 -0
  283. package/src/domains/eval/metrics/call-ledger-stream.ts +34 -11
  284. package/src/domains/eval/metrics/token-stream.ts +201 -31
  285. package/src/domains/eval/metrics/tracked.ts +40 -4
  286. package/src/domains/eval/runners/clio-run.ts +5 -2
  287. package/src/domains/eval/schema/suite.ts +28 -0
  288. package/src/domains/eval/schema/verdict.ts +2 -2
  289. package/src/domains/eval/suites/resolve.ts +13 -1
  290. package/src/domains/eval/suites/run.ts +24 -3
  291. package/src/domains/interop/registry.ts +6 -2
  292. package/src/domains/interop/types.ts +4 -0
  293. package/src/domains/lifecycle/migrations/index.ts +4 -0
  294. package/src/domains/memory/task-memory-policy.ts +70 -26
  295. package/src/domains/memory/task-memory-telemetry.ts +1 -0
  296. package/src/domains/middleware/index.ts +0 -1
  297. package/src/domains/middleware/marketplace-offer.ts +3 -35
  298. package/src/domains/middleware/memory-intervention.ts +127 -32
  299. package/src/domains/middleware/memory-step-endpoint.ts +3 -2
  300. package/src/domains/middleware/skills-reminder.ts +31 -2
  301. package/src/domains/observability/compaction-usage.ts +118 -0
  302. package/src/domains/observability/cost.ts +1 -1
  303. package/src/domains/observability/extension.ts +6 -1
  304. package/src/domains/observability/out-of-turn-usage.ts +52 -21
  305. package/src/domains/providers/contract.ts +4 -1
  306. package/src/domains/providers/extension.ts +40 -9
  307. package/src/domains/providers/model-capabilities.ts +9 -0
  308. package/src/domains/providers/model-discovery.ts +2 -0
  309. package/src/domains/providers/model-runtime-capabilities.ts +15 -5
  310. package/src/domains/providers/models/local-models/clio-coder-local-coding-targets.yaml +32 -12
  311. package/src/domains/providers/runtimes/antigravity/antigravity-code.ts +225 -45
  312. package/src/domains/providers/runtimes/common/lmstudio-http.ts +6 -2
  313. package/src/domains/providers/runtimes/common/local-synth.ts +2 -0
  314. package/src/domains/providers/runtimes/protocol/litellm.ts +119 -29
  315. package/src/domains/providers/support.ts +11 -5
  316. package/src/domains/providers/target-model-cache.ts +25 -2
  317. package/src/domains/providers/types/capability-flags.ts +2 -0
  318. package/src/domains/providers/types/runtime-descriptor.ts +20 -1
  319. package/src/domains/providers/types/target-descriptor.ts +19 -0
  320. package/src/domains/resources/index.ts +3 -0
  321. package/src/domains/resources/skills/install.ts +72 -7
  322. package/src/domains/resources/skills/loader.ts +7 -0
  323. package/src/domains/resources/skills/marketplace.ts +63 -11
  324. package/src/domains/safety/autonomy.ts +15 -0
  325. package/src/domains/safety/index.ts +1 -0
  326. package/src/domains/safety/path-policy.ts +1 -1
  327. package/src/domains/safety/policy-engine.ts +34 -11
  328. package/src/domains/safety/protected-artifacts.ts +191 -88
  329. package/src/domains/safety/run-effects.ts +2 -22
  330. package/src/domains/safety/skill-authority.ts +55 -0
  331. package/src/domains/session/compaction/compact.ts +72 -22
  332. package/src/domains/session/entries.ts +6 -0
  333. package/src/domains/session/usage.ts +3 -3
  334. package/src/engine/agent.ts +13 -3
  335. package/src/engine/ai.ts +26 -8
  336. package/src/engine/antigravity/subprocess-runtime.ts +386 -120
  337. package/src/engine/api-registry.ts +3 -0
  338. package/src/engine/apis/openai-completions.ts +117 -14
  339. package/src/engine/external-subprocess.ts +114 -6
  340. package/src/entry/background-model-metadata.ts +18 -0
  341. package/src/entry/compaction-prompt.ts +57 -0
  342. package/src/entry/orchestrator.ts +405 -216
  343. package/src/entry/task-memory-lifecycle.ts +35 -0
  344. package/src/interactive/chat-loop-messages.ts +13 -4
  345. package/src/interactive/chat-loop.ts +65 -2
  346. package/src/interactive/chat-renderer.ts +1 -0
  347. package/src/interactive/cost-overlay.ts +26 -2
  348. package/src/interactive/interactive-slash-runtime.ts +2 -1
  349. package/src/interactive/renderers/worker-entry.ts +32 -0
  350. package/src/interactive/slash-commands.ts +24 -6
  351. package/src/interactive/theme/labels.ts +19 -13
  352. package/src/interactive/turn-context.ts +9 -5
  353. package/src/interactive/turn-recovery.ts +8 -0
  354. package/src/interactive/turn-runtime.ts +27 -11
  355. package/src/interactive/turn-state.ts +7 -0
  356. package/src/interactive/worker-receipts.ts +1 -0
  357. package/src/interactive/worker-stream.ts +6 -1
  358. package/src/tools/context/index.ts +30 -9
  359. package/src/tools/dispatch-arguments.ts +1 -0
  360. package/src/tools/dispatch-event-text.ts +10 -0
  361. package/src/tools/dispatch-plan.ts +1 -0
  362. package/src/tools/dispatch-runner.ts +12 -0
  363. package/src/tools/registry.ts +11 -5
  364. package/src/tools/worker-evidence.ts +3 -1
  365. package/src/worker/spec-contract.ts +4 -0
  366. package/dist/chunk-2Z2IKEXI.js +0 -1554
  367. package/dist/reset-OAQP3W4O.js +0 -230
  368. package/dist/uninstall-N34PCTGJ.js +0 -331
  369. package/dist/upgrade-PXK3S2YM.js +0 -325
@@ -6,11 +6,11 @@ import {
6
6
  parseRoutingIntent,
7
7
  routePriorForLatencyClass,
8
8
  sameRouteIdentity
9
- } from "./chunk-HIICAHCJ.js";
9
+ } from "./chunk-EKCHAPYA.js";
10
10
  import {
11
11
  hashToolCall,
12
12
  typedValidationSummary
13
- } from "./chunk-IDNA72AH.js";
13
+ } from "./chunk-RSJ25QSL.js";
14
14
  import {
15
15
  describeCallAction
16
16
  } from "./chunk-NEDJ26B5.js";
@@ -29,14 +29,27 @@ import {
29
29
  resolveReadPath
30
30
  } from "./chunk-OQE5J4C6.js";
31
31
  import {
32
- DEFAULT_AUTONOMY_EXPOSURE,
33
- DEFAULT_AUTONOMY_LEVEL,
34
- autonomyAskRejection,
35
- autonomyDenyRejection,
36
- evaluateSkillToolSurface,
37
- isAutonomyLevel,
38
- mapAutonomy
39
- } from "./chunk-FSP7CMNU.js";
32
+ PATH_BOUNDARY_MAX_ENTRIES,
33
+ PathBoundaryError,
34
+ asDirectoryPathBoundary,
35
+ normalizePathBoundaryEntry,
36
+ pathBoundaryCovers,
37
+ resolvePathBoundary
38
+ } from "./chunk-HHV2GANA.js";
39
+ import {
40
+ AGENT_AUTOMATION_AUTHORITIES,
41
+ COUNCIL_BALLOT_SHAPE,
42
+ COUNCIL_BALLOT_VERDICT_MAX_BYTES,
43
+ agentSpecFingerprint,
44
+ classify
45
+ } from "./chunk-B4OAX3SI.js";
46
+ import {
47
+ commandArgumentSegments,
48
+ detectValidationCommand,
49
+ extractCommandDeleteTargets,
50
+ extractCommandWriteTargets,
51
+ toolMutationPaths
52
+ } from "./chunk-I7ZPNEJM.js";
40
53
  import {
41
54
  DEFAULT_MAX_LINES,
42
55
  DEFAULT_TOOL_RESULT_MAX_BYTES,
@@ -52,7 +65,7 @@ import {
52
65
  toolResultDigestFor,
53
66
  truncateHead,
54
67
  truncateTail
55
- } from "./chunk-B7HM5Z7T.js";
68
+ } from "./chunk-JDAY6FIL.js";
56
69
  import {
57
70
  formatSize
58
71
  } from "./chunk-OZNBF4L3.js";
@@ -60,56 +73,47 @@ import {
60
73
  byteLength,
61
74
  truncateUtf8
62
75
  } from "./chunk-6XLNIQDB.js";
63
- import {
64
- BASH_HARD_CAP_BYTES,
65
- combineBashOutput,
66
- runBashCommand
67
- } from "./chunk-NMJXSHBJ.js";
68
- import {
69
- PATH_BOUNDARY_MAX_ENTRIES,
70
- PathBoundaryError,
71
- asDirectoryPathBoundary,
72
- normalizePathBoundaryEntry,
73
- pathBoundaryCovers,
74
- resolvePathBoundary
75
- } from "./chunk-HHV2GANA.js";
76
- import {
77
- AGENT_AUTOMATION_AUTHORITIES,
78
- COUNCIL_BALLOT_SHAPE,
79
- COUNCIL_BALLOT_VERDICT_MAX_BYTES,
80
- agentSpecFingerprint,
81
- classify
82
- } from "./chunk-PGF63K6I.js";
83
- import {
84
- detectValidationCommand,
85
- extractCommandDeleteTargets,
86
- extractCommandWriteTargets,
87
- tokenizeShellLike,
88
- toolMutationPaths
89
- } from "./chunk-IKOZFYBN.js";
90
76
  import {
91
77
  typebox_exports
92
78
  } from "./chunk-5B2AEOW5.js";
79
+ import {
80
+ DEFAULT_AUTONOMY_EXPOSURE,
81
+ DEFAULT_AUTONOMY_LEVEL,
82
+ autonomyAskRejection,
83
+ autonomyDenyRejection,
84
+ evaluateSkillToolSurface,
85
+ isAutonomyLevel,
86
+ mapAutonomy
87
+ } from "./chunk-JGRC33J2.js";
93
88
  import {
94
89
  ToolNames
95
90
  } from "./chunk-K6BSR66V.js";
96
91
  import {
97
- resolveSafeCwd
98
- } from "./chunk-HJWWJ6IL.js";
92
+ BASH_HARD_CAP_BYTES,
93
+ combineBashOutput,
94
+ runBashCommand
95
+ } from "./chunk-NMJXSHBJ.js";
96
+ import {
97
+ boundedExternalDiagnostic
98
+ } from "./chunk-VW6DOEDG.js";
99
99
  import {
100
100
  THINKING_LEVELS
101
101
  } from "./chunk-UXCU4E3T.js";
102
+ import {
103
+ buildSafeToolEnv,
104
+ resolveSafeCwd
105
+ } from "./chunk-JSC3U7TI.js";
102
106
  import {
103
107
  GUARDRAIL_DEFAULTS,
104
108
  isWorkerToolCallCapExceededReason,
105
109
  resolveGuardrail
106
110
  } from "./chunk-S66XZJOF.js";
111
+ import {
112
+ StringEnum
113
+ } from "./chunk-YPC6ZR5L.js";
107
114
  import {
108
115
  clioStateDir
109
116
  } from "./chunk-BYP5D4HI.js";
110
- import {
111
- StringEnum
112
- } from "./chunk-VXMFAE2W.js";
113
117
  import {
114
118
  init_esm_shims
115
119
  } from "./chunk-3R73A4XB.js";
@@ -1326,6 +1330,14 @@ function normalizeDispatchIntent(raw, checks) {
1326
1330
 
1327
1331
  // src/domains/dispatch/budget-envelope.ts
1328
1332
  init_esm_shims();
1333
+ var NATIVE_CLIO_CONTROLS = ["tool-calls", "read-reserve", "synthesis", "attempt-cap"];
1334
+ var EXTERNAL_CLIO_CONTROLS = [
1335
+ "single-launch",
1336
+ "wall-clock",
1337
+ "output-cap",
1338
+ "cancellation",
1339
+ "result-contract"
1340
+ ];
1329
1341
  var BudgetAdmissionError = class extends Error {
1330
1342
  code;
1331
1343
  constructor(code, message) {
@@ -1368,6 +1380,8 @@ function cloneDispatchBudgetRequest(value, prefix = "budget") {
1368
1380
  return { ...phase, ...retryRevision === void 0 ? {} : { retryRevision } };
1369
1381
  }
1370
1382
  function freezeEnvelope(envelope) {
1383
+ Object.freeze(envelope.enforcement.clioControls);
1384
+ Object.freeze(envelope.enforcement);
1371
1385
  Object.freeze(envelope.policy.default);
1372
1386
  Object.freeze(envelope.policy.maximum);
1373
1387
  Object.freeze(envelope.policy);
@@ -1506,6 +1520,15 @@ function resolveToolBudgetEnvelope(input) {
1506
1520
  const authoredMaximum = input.policy.maximum ?? input.policy;
1507
1521
  return freezeEnvelope({
1508
1522
  version: 1,
1523
+ enforcement: input.enforcement === "external-one-shot" ? {
1524
+ classification: "external-one-shot",
1525
+ perTool: "unobserved-not-enforced",
1526
+ clioControls: [...EXTERNAL_CLIO_CONTROLS]
1527
+ } : {
1528
+ classification: "native-per-tool",
1529
+ perTool: "enforced",
1530
+ clioControls: [...NATIVE_CLIO_CONTROLS]
1531
+ },
1509
1532
  policy: {
1510
1533
  recipeId: input.recipeId,
1511
1534
  default: {
@@ -1541,7 +1564,8 @@ function formatBudgetRequest(envelope) {
1541
1564
  function formatEffectiveBudget(envelope) {
1542
1565
  const budget = envelope.effective;
1543
1566
  const revision = budget.revision ? `, result revision ${budget.revision.toolCalls}/${budget.revision.readReserve}` : "";
1544
- return `${budget.toolCalls}/${budget.readReserve}${revision}, lifetime cap ${budget.hardCap}, synthesis=${budget.synthesis ? "on" : "off"}`;
1567
+ const enforcement = envelope.enforcement.classification === "external-one-shot" ? "external one-shot; per-tool unobserved/not enforced" : "native per-tool enforced";
1568
+ return `${budget.toolCalls}/${budget.readReserve}${revision}, lifetime cap ${budget.hardCap}, synthesis=${budget.synthesis ? "on" : "off"}; ${enforcement}`;
1545
1569
  }
1546
1570
  function formatBudgetReasons(envelope) {
1547
1571
  return envelope.reasons.length === 0 ? "none" : envelope.reasons.map((reason) => reason.code).join(",");
@@ -1555,6 +1579,9 @@ var BUDGET_REASON_CODES = /* @__PURE__ */ new Set([
1555
1579
  "revision-growth-authorized",
1556
1580
  "revision-growth-denied"
1557
1581
  ]);
1582
+ function isExactStringArray(value, expected) {
1583
+ return value.length === expected.length && value.every((item, index) => item === expected[index]);
1584
+ }
1558
1585
  function cloneRunToolBudgetEnvelope(value) {
1559
1586
  try {
1560
1587
  if (!isRecord3(value) || value.version !== 1 || !isRecord3(value.policy) || !isRecord3(value.effective)) {
@@ -1589,8 +1616,40 @@ function cloneRunToolBudgetEnvelope(value) {
1589
1616
  }
1590
1617
  reasons.push({ code: reason.code, detail: reason.detail });
1591
1618
  }
1619
+ const enforcement = (() => {
1620
+ if (value.enforcement === void 0) {
1621
+ return {
1622
+ classification: "native-per-tool",
1623
+ perTool: "enforced",
1624
+ clioControls: [...NATIVE_CLIO_CONTROLS]
1625
+ };
1626
+ }
1627
+ if (!isRecord3(value.enforcement) || !Array.isArray(value.enforcement.clioControls)) return null;
1628
+ if (Object.keys(value.enforcement).some(
1629
+ (key) => key !== "classification" && key !== "perTool" && key !== "clioControls"
1630
+ )) {
1631
+ return null;
1632
+ }
1633
+ if (value.enforcement.classification === "external-one-shot" && value.enforcement.perTool === "unobserved-not-enforced" && isExactStringArray(value.enforcement.clioControls, EXTERNAL_CLIO_CONTROLS)) {
1634
+ return {
1635
+ classification: "external-one-shot",
1636
+ perTool: "unobserved-not-enforced",
1637
+ clioControls: [...EXTERNAL_CLIO_CONTROLS]
1638
+ };
1639
+ }
1640
+ if (value.enforcement.classification === "native-per-tool" && value.enforcement.perTool === "enforced" && isExactStringArray(value.enforcement.clioControls, NATIVE_CLIO_CONTROLS)) {
1641
+ return {
1642
+ classification: "native-per-tool",
1643
+ perTool: "enforced",
1644
+ clioControls: [...NATIVE_CLIO_CONTROLS]
1645
+ };
1646
+ }
1647
+ return null;
1648
+ })();
1649
+ if (enforcement === null) return void 0;
1592
1650
  return freezeEnvelope({
1593
1651
  version: 1,
1652
+ enforcement,
1594
1653
  policy: {
1595
1654
  recipeId,
1596
1655
  default: { ...defaultPhase, synthesis: value.policy.default.synthesis },
@@ -1795,6 +1854,10 @@ var TASK_TYPE_RULES = [
1795
1854
  ["debug", /\b(debug|fix|bug|crash|failure|broken|regression)\b/i],
1796
1855
  ["refactor", /\b(refactor|clean ?up|restructure|rename|extract|simplify)\b/i],
1797
1856
  ["config", /\b(config|configuration|settings|setup|install|ci pipeline|workflow file)\b/i],
1857
+ [
1858
+ "world_knowledge",
1859
+ /\b(?:open[- ]world|ecosystem landscape|industry landscape|state of (?:the )?art|current alternatives|latest alternatives|advisory second opinion)\b/i
1860
+ ],
1798
1861
  ["research", /\b(research|investigate|explore|survey|compare|find out)\b/i],
1799
1862
  ["code_read", /\b(read|explain|understand|summarize|describe|walk through|map|locate|trace)\b/i],
1800
1863
  ["code_write", /\b(write|implement|add|create|build|develop|introduce)\b/i]
@@ -1870,6 +1933,11 @@ function agentRouteCandidates(input) {
1870
1933
  var TASK_SIGNALS = {
1871
1934
  code_read: { ids: ["scout"], tags: ["reconnaissance", "symbols", "codewiki"], contracts: ["scout-report"] },
1872
1935
  research: { ids: ["researcher"], tags: ["sources", "external-context", "papers"], contracts: ["research-report"] },
1936
+ world_knowledge: {
1937
+ ids: ["world-knowledge"],
1938
+ tags: ["open-world", "ecosystem", "current-context", "second-opinion"],
1939
+ contracts: ["world-knowledge-report"]
1940
+ },
1873
1941
  code_review: { ids: ["verifier"], tags: ["review", "verification"], contracts: ["verifier-report"] },
1874
1942
  debug: { ids: ["debugger"], tags: ["debugging", "root-cause"], contracts: ["debugger-report"] },
1875
1943
  test: { ids: ["verifier", "tester"], tags: ["tests", "validation", "regression"], contracts: ["verifier-report"] },
@@ -2836,6 +2904,7 @@ var AUTO_BASELINE_BY_TASK_TYPE = {
2836
2904
  // Read-only shapes.
2837
2905
  code_review: "verifier",
2838
2906
  research: "researcher",
2907
+ world_knowledge: "world-knowledge",
2839
2908
  code_read: "scout",
2840
2909
  unknown: "scout"
2841
2910
  };
@@ -3163,10 +3232,10 @@ function taskViews(args) {
3163
3232
  const sharedNode = str(args.node);
3164
3233
  const sharedTarget = str(args.target);
3165
3234
  return tasks.map((item) => {
3166
- const record2 = isRecord6(item) ? item : {};
3235
+ const record3 = isRecord6(item) ? item : {};
3167
3236
  const view = {
3168
- agent: str(record2.agent) ?? sharedAgent,
3169
- task: str(item) ?? str(record2.task) ?? "(invalid task)",
3237
+ agent: str(record3.agent) ?? sharedAgent,
3238
+ task: str(item) ?? str(record3.task) ?? "(invalid task)",
3170
3239
  routeApproval: null,
3171
3240
  agentSelection: null,
3172
3241
  stepId: null,
@@ -3177,23 +3246,23 @@ function taskViews(args) {
3177
3246
  agentDecision: null,
3178
3247
  wave: null
3179
3248
  };
3180
- const briefing = "briefing" in record2 ? str(record2.briefing) : str(args.briefing);
3249
+ const briefing = "briefing" in record3 ? str(record3.briefing) : str(args.briefing);
3181
3250
  if (briefing !== void 0) view.briefing = briefing;
3182
- const worktree = "worktree" in record2 ? record2.worktree : args.worktree;
3251
+ const worktree = "worktree" in record3 ? record3.worktree : args.worktree;
3183
3252
  if (worktree === true) {
3184
3253
  view.worktree = true;
3185
- const apply = "apply" in record2 ? record2.apply : args.apply;
3254
+ const apply = "apply" in record3 ? record3.apply : args.apply;
3186
3255
  view.apply = apply === "preserve" ? "preserve" : "merge";
3187
3256
  }
3188
- const model = str(record2.model) ?? sharedModel;
3257
+ const model = str(record3.model) ?? sharedModel;
3189
3258
  if (model !== void 0) view.model = model;
3190
- const node = str(record2.node) ?? sharedNode;
3259
+ const node = str(record3.node) ?? sharedNode;
3191
3260
  if (node !== void 0) view.node = node;
3192
- const target = str(record2.target) ?? sharedTarget;
3261
+ const target = str(record3.target) ?? sharedTarget;
3193
3262
  if (target !== void 0) view.target = target;
3194
- const failover = failoverModeOf(record2.failover) ?? failoverModeOf(args.failover);
3263
+ const failover = failoverModeOf(record3.failover) ?? failoverModeOf(args.failover);
3195
3264
  if (failover !== void 0) view.failover = failover;
3196
- const rawCandidates = "allowedCandidates" in record2 ? record2.allowedCandidates : args.allowedCandidates;
3265
+ const rawCandidates = "allowedCandidates" in record3 ? record3.allowedCandidates : args.allowedCandidates;
3197
3266
  const candidates = canonicalCandidates(rawCandidates);
3198
3267
  if (failover === "approved" && candidates !== null) view.allowedCandidates = candidates;
3199
3268
  return view;
@@ -3414,6 +3483,7 @@ var RESULT_CONTRACT_KINDS = /* @__PURE__ */ new Set([
3414
3483
  "council-report",
3415
3484
  "debugger-report",
3416
3485
  "research-report",
3486
+ "world-knowledge-report",
3417
3487
  "mutation-report",
3418
3488
  "provenance-report",
3419
3489
  "oracle-report",
@@ -4073,7 +4143,8 @@ ${guidance}`,
4073
4143
  return { kind: "blocked", reason, decision: blocked };
4074
4144
  }
4075
4145
  function skillSurfaceBlockedVerdict(decision, tool, violation) {
4076
- const reason = violation.disallowedBy.length > 0 ? `${tool} is disallowed by the active skill(s) ${violation.disallowedBy.join(", ")} (disallowed-tools). The narrowing ends when the skill policy's turn or worker run ends. Work within the skill workflow; if it genuinely needs this step, use ask_user when available or state the blocker in your reply.` : `${tool} is outside the tool surface declared by the active skill(s) ${violation.skills.join(", ")}. Tools are narrowed to: ${(violation.mergedAllowedTools ?? []).join(", ")} (plus context and ask_user). The narrowing ends when the skill policy's turn or worker run ends. Work within the skill workflow; if it genuinely needs this step, use ask_user when available or state the blocker in your reply.`;
4146
+ const lifetime = violation.carriedSurface ? "The narrowing stays active for the rest of the session, across the operator's later turns, until a different skill replaces it or the operator clears it with /skill off." : "The narrowing ends when the skill policy's turn or worker run ends.";
4147
+ const reason = violation.disallowedBy.length > 0 ? `${tool} is disallowed by the active skill(s) ${violation.disallowedBy.join(", ")} (disallowed-tools). ${lifetime} Work within the skill workflow; if it genuinely needs this step, use ask_user when available or state the blocker in your reply.` : `${tool} is outside the tool surface declared by the active skill(s) ${violation.skills.join(", ")}. Tools are narrowed to: ${(violation.mergedAllowedTools ?? []).join(", ")} (plus context and ask_user). ${lifetime} Work within the skill workflow; if it genuinely needs this step, use ask_user when available or state the blocker in your reply.`;
4077
4148
  const blocked = {
4078
4149
  kind: "block",
4079
4150
  classification: decision.classification,
@@ -4230,7 +4301,8 @@ var RUNTIME_API_FAMILIES = [
4230
4301
  "rerank-http",
4231
4302
  "embeddings-http",
4232
4303
  "claude-agent-sdk",
4233
- "claude-code-subprocess"
4304
+ "claude-code-subprocess",
4305
+ "external-agent-subprocess"
4234
4306
  ];
4235
4307
  var RUNTIME_AUTHS = [
4236
4308
  "api-key",
@@ -4303,15 +4375,15 @@ function readString(value, source, options) {
4303
4375
  if (!options?.allowEmpty && value.length === 0) throw new Error(`${source} must be a non-empty string`);
4304
4376
  return value;
4305
4377
  }
4306
- function readOptionalString(record2, key, source) {
4307
- if (record2[key] !== void 0) readString(record2[key], `${source}.${key}`);
4378
+ function readOptionalString(record3, key, source) {
4379
+ if (record3[key] !== void 0) readString(record3[key], `${source}.${key}`);
4308
4380
  }
4309
- function readOptionalBoolean(record2, key, source) {
4310
- const value = record2[key];
4381
+ function readOptionalBoolean(record3, key, source) {
4382
+ const value = record3[key];
4311
4383
  if (value !== void 0 && typeof value !== "boolean") throw new Error(`${source}.${key} must be a boolean`);
4312
4384
  }
4313
- function readOptionalNumber(record2, key, source) {
4314
- const value = record2[key];
4385
+ function readOptionalNumber(record3, key, source) {
4386
+ const value = record3[key];
4315
4387
  if (value !== void 0 && (typeof value !== "number" || !Number.isFinite(value))) {
4316
4388
  throw new Error(`${source}.${key} must be a finite number`);
4317
4389
  }
@@ -4322,15 +4394,15 @@ function readEnum(value, source, allowed) {
4322
4394
  }
4323
4395
  return value;
4324
4396
  }
4325
- function readOptionalEnum(record2, key, source, allowed) {
4326
- if (record2[key] !== void 0) readEnum(record2[key], `${source}.${key}`, allowed);
4397
+ function readOptionalEnum(record3, key, source, allowed) {
4398
+ if (record3[key] !== void 0) readEnum(record3[key], `${source}.${key}`, allowed);
4327
4399
  }
4328
4400
  function readStringArray(value, source) {
4329
4401
  if (!Array.isArray(value)) throw new Error(`${source} must be an array`);
4330
4402
  return value.map((item, index) => readString(item, `${source}[${index}]`));
4331
4403
  }
4332
- function readOptionalStringArray(record2, key, source) {
4333
- if (record2[key] !== void 0) readStringArray(record2[key], `${source}.${key}`);
4404
+ function readOptionalStringArray(record3, key, source) {
4405
+ if (record3[key] !== void 0) readStringArray(record3[key], `${source}.${key}`);
4334
4406
  }
4335
4407
  function validateProtectedModels(value) {
4336
4408
  if (value === void 0) return;
@@ -4397,6 +4469,9 @@ function validateCapabilityPatch(value, source) {
4397
4469
  for (const key of ["contextWindow", "maxTokens"]) {
4398
4470
  readOptionalNumber(caps, key, source);
4399
4471
  }
4472
+ if (caps.thinkingControlRuntime !== void 0) {
4473
+ readEnum(caps.thinkingControlRuntime, `${source}.thinkingControlRuntime`, ["lmstudio", "llamacpp"]);
4474
+ }
4400
4475
  for (const key of ["toolCallFormat", "thinkingFormat", "structuredOutputs"]) {
4401
4476
  readOptionalString(caps, key, source);
4402
4477
  }
@@ -4698,31 +4773,112 @@ import { spawn } from "node:child_process";
4698
4773
 
4699
4774
  // src/engine/external-subprocess.ts
4700
4775
  init_esm_shims();
4776
+ async function* readBoundedLines(readable, options) {
4777
+ let segments = [];
4778
+ let lineBytes = 0;
4779
+ let totalBytes = 0;
4780
+ let discarding = false;
4781
+ const finishLine = () => {
4782
+ if (discarding) {
4783
+ segments = [];
4784
+ lineBytes = 0;
4785
+ discarding = false;
4786
+ return { kind: "oversized" };
4787
+ }
4788
+ if (lineBytes === 0) return { kind: "line", line: "" };
4789
+ const joined = Buffer.concat(segments, lineBytes);
4790
+ segments = [];
4791
+ lineBytes = 0;
4792
+ const end = joined.at(-1) === 13 ? joined.length - 1 : joined.length;
4793
+ return { kind: "line", line: joined.subarray(0, end).toString("utf8") };
4794
+ };
4795
+ for await (const raw of readable) {
4796
+ const chunk = Buffer.isBuffer(raw) ? raw : Buffer.from(String(raw));
4797
+ totalBytes += chunk.byteLength;
4798
+ if (totalBytes > options.maxTotalBytes) throw new Error("external stdout exceeded the cumulative output limit");
4799
+ let offset = 0;
4800
+ while (offset < chunk.length) {
4801
+ const newline = chunk.indexOf(10, offset);
4802
+ const end = newline === -1 ? chunk.length : newline;
4803
+ const piece = chunk.subarray(offset, end);
4804
+ if (!discarding && piece.length > 0) {
4805
+ if (lineBytes + piece.length > options.maxLineBytes) {
4806
+ segments = [];
4807
+ lineBytes = 0;
4808
+ discarding = true;
4809
+ } else {
4810
+ segments.push(piece);
4811
+ lineBytes += piece.length;
4812
+ }
4813
+ }
4814
+ if (newline === -1) break;
4815
+ const line = finishLine();
4816
+ if (line) yield line;
4817
+ offset = newline + 1;
4818
+ }
4819
+ }
4820
+ if (discarding || lineBytes > 0) {
4821
+ const line = finishLine();
4822
+ if (line) yield line;
4823
+ }
4824
+ }
4701
4825
  async function readStderr(child) {
4702
- let stderr = "";
4826
+ let tail = Buffer.alloc(0);
4703
4827
  for await (const chunk of child.stderr) {
4704
- stderr += String(chunk);
4705
- if (stderr.length > 8192) stderr = stderr.slice(-8192);
4706
- }
4707
- return stderr;
4828
+ const bytes = Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk));
4829
+ tail = Buffer.concat([tail, bytes]);
4830
+ if (tail.byteLength > 8192) tail = tail.subarray(tail.byteLength - 8192);
4831
+ }
4832
+ return boundedExternalDiagnostic(tail.toString("utf8"));
4833
+ }
4834
+ function createProcessTreeTerminator(child, graceMs = 1500) {
4835
+ let sent = false;
4836
+ let timer = null;
4837
+ const signal = (name) => {
4838
+ if (child.exitCode !== null) return;
4839
+ if (child.pid && process.platform !== "win32") {
4840
+ try {
4841
+ process.kill(-child.pid, name);
4842
+ return;
4843
+ } catch {
4844
+ }
4845
+ }
4846
+ child.kill(name);
4847
+ };
4848
+ return {
4849
+ terminate() {
4850
+ if (sent) return;
4851
+ sent = true;
4852
+ signal("SIGTERM");
4853
+ timer = setTimeout(() => signal("SIGKILL"), graceMs);
4854
+ },
4855
+ cleanup() {
4856
+ if (timer) clearTimeout(timer);
4857
+ timer = null;
4858
+ }
4859
+ };
4708
4860
  }
4709
4861
  function waitForClose(child) {
4710
4862
  return new Promise((resolve) => {
4711
- child.once("error", () => resolve(1));
4712
- child.once("close", (code) => resolve(code ?? 1));
4863
+ let settled = false;
4864
+ const finish = (code) => {
4865
+ if (settled) return;
4866
+ settled = true;
4867
+ resolve(code);
4868
+ };
4869
+ child.once("error", () => finish(1));
4870
+ child.once("close", (code) => finish(code ?? 1));
4713
4871
  });
4714
4872
  }
4715
4873
 
4716
4874
  // src/engine/antigravity/subprocess-runtime.ts
4717
4875
  var ANTIGRAVITY_BINARY = "agy";
4718
- var ZERO_USAGE = {
4719
- input: 0,
4720
- output: 0,
4721
- cacheRead: 0,
4722
- cacheWrite: 0,
4723
- totalTokens: 0,
4724
- cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
4725
- };
4876
+ var ANTIGRAVITY_MAX_STREAM_LINE_BYTES = 1024 * 1024;
4877
+ var ANTIGRAVITY_MAX_STREAM_BYTES = 8 * 1024 * 1024;
4878
+ var ANTIGRAVITY_MAX_RESPONSE_BYTES = 4 * 1024 * 1024;
4879
+ var ANTIGRAVITY_MAX_PROMPT_BYTES = 4 * 1024 * 1024;
4880
+ var MAX_PROTOCOL_DIAGNOSTICS = 32;
4881
+ var MAX_CONVERSATION_ID_BYTES = 4096;
4726
4882
  function antigravitySubprocessConfigForAutonomy(level, env = process.env) {
4727
4883
  if (level === "full-auto" && env.CLIO_CODER_ALLOW_EXTERNAL_FULL_ACCESS === "1") {
4728
4884
  return {
@@ -4739,7 +4895,7 @@ function antigravitySubprocessConfigForAutonomy(level, env = process.env) {
4739
4895
  if (level === "read-only") {
4740
4896
  return { extraArgs: ["--mode", "plan", "--sandbox"], dangerousBypass: false, externalMode: "plan+sandbox" };
4741
4897
  }
4742
- return { extraArgs: [], dangerousBypass: false, externalMode: "agy-settings-default" };
4898
+ return { extraArgs: ["--mode", "accept-edits"], dangerousBypass: false, externalMode: "accept-edits" };
4743
4899
  }
4744
4900
  function buildAntigravityPrompt(input) {
4745
4901
  const parts = [];
@@ -4752,114 +4908,314 @@ function buildAntigravityPrompt(input) {
4752
4908
  parts.push(input.task);
4753
4909
  return parts.join("\n\n");
4754
4910
  }
4755
- function buildAgyArgs(input) {
4911
+ function buildAgyStdinLine(input) {
4912
+ const content = buildAntigravityPrompt(input);
4913
+ if (Buffer.byteLength(content, "utf8") > ANTIGRAVITY_MAX_PROMPT_BYTES) {
4914
+ throw new Error(`Antigravity work order exceeded ${ANTIGRAVITY_MAX_PROMPT_BYTES} bytes`);
4915
+ }
4916
+ return `${JSON.stringify({ event: "user", message: { content } })}
4917
+ `;
4918
+ }
4919
+ function buildAgyArgs(input, gateEnv = process.env) {
4756
4920
  assertToolProfileEnforceable(input.toolProfile, "antigravity-code");
4757
- const permission = antigravitySubprocessConfigForAutonomy(input.autonomy);
4758
- const args = ["--print", ...permission.extraArgs];
4921
+ const permission = antigravitySubprocessConfigForAutonomy(input.autonomy, gateEnv);
4922
+ const args = [
4923
+ ...permission.extraArgs,
4924
+ "--input-format",
4925
+ "stream-json",
4926
+ "--output-format",
4927
+ "stream-json",
4928
+ "--disable-slash-commands"
4929
+ ];
4759
4930
  if (input.wireModelId.trim().length > 0) args.push("--model", input.wireModelId.trim());
4760
- args.push(buildAntigravityPrompt(input));
4761
4931
  return args;
4762
4932
  }
4763
- function buildAssistantMessage(input) {
4764
- const message = {
4765
- role: "assistant",
4766
- content: [{ type: "text", text: input.text }],
4767
- api: "google-generative-ai",
4768
- provider: "google",
4769
- model: input.model,
4770
- usage: ZERO_USAGE,
4771
- stopReason: input.aborted ? "aborted" : input.exitCode === 0 ? "stop" : "error",
4772
- timestamp: Date.now()
4933
+ function record2(value) {
4934
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
4935
+ }
4936
+ function parseAntigravityStreamLine(line) {
4937
+ let decoded;
4938
+ try {
4939
+ decoded = JSON.parse(line);
4940
+ } catch {
4941
+ return null;
4942
+ }
4943
+ const envelope = record2(decoded);
4944
+ if (!envelope || typeof envelope.event !== "string") return null;
4945
+ if (envelope.event === "init") {
4946
+ return {
4947
+ event: "init",
4948
+ conversationId: typeof envelope.conversation_id === "string" ? envelope.conversation_id : null,
4949
+ model: typeof envelope.model === "string" ? envelope.model : null
4950
+ };
4951
+ }
4952
+ if (envelope.event === "step_update") {
4953
+ const update = record2(envelope.step_update);
4954
+ if (!update) return null;
4955
+ if (update.step_type !== "agent_response" || typeof update.text_delta !== "string") {
4956
+ return { event: "other" };
4957
+ }
4958
+ return {
4959
+ event: "text",
4960
+ conversationId: typeof update.conversation_id === "string" ? update.conversation_id : null,
4961
+ delta: update.text_delta
4962
+ };
4963
+ }
4964
+ if (envelope.event === "result") {
4965
+ const result = record2(envelope.result);
4966
+ return result ? { event: "result", result } : null;
4967
+ }
4968
+ return { event: "other" };
4969
+ }
4970
+ function finite(value) {
4971
+ return typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.min(value, Number.MAX_SAFE_INTEGER) : 0;
4972
+ }
4973
+ function normalizeUsage(raw) {
4974
+ const source = record2(raw) ?? {};
4975
+ const input = finite(source.input_tokens);
4976
+ const output = finite(source.output_tokens);
4977
+ const cacheRead = finite(source.cache_read_tokens);
4978
+ const reasoningTokens = finite(source.thinking_tokens);
4979
+ const usage = {
4980
+ input,
4981
+ output,
4982
+ cacheRead,
4983
+ cacheWrite: 0,
4984
+ totalTokens: finite(source.total_tokens) || input + output + reasoningTokens,
4985
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }
4773
4986
  };
4774
- if (input.exitCode !== 0 && !input.aborted) {
4775
- const detail = input.stderr.trim();
4776
- if (detail.length > 0) message.errorMessage = detail;
4987
+ if (reasoningTokens > 0) usage.reasoningTokens = reasoningTokens;
4988
+ return usage;
4989
+ }
4990
+ function appendBoundedText(current, delta) {
4991
+ if (Buffer.byteLength(current, "utf8") + Buffer.byteLength(delta, "utf8") > ANTIGRAVITY_MAX_RESPONSE_BYTES) {
4992
+ throw new Error(`Antigravity response exceeded ${ANTIGRAVITY_MAX_RESPONSE_BYTES} bytes`);
4777
4993
  }
4778
- return message;
4994
+ return current + delta;
4995
+ }
4996
+ function boundedProviderField(value, field) {
4997
+ if (typeof value !== "string") return "";
4998
+ if (Buffer.byteLength(value, "utf8") > ANTIGRAVITY_MAX_RESPONSE_BYTES) {
4999
+ throw new Error(`Antigravity terminal ${field} exceeded ${ANTIGRAVITY_MAX_RESPONSE_BYTES} bytes`);
5000
+ }
5001
+ return value;
5002
+ }
5003
+ function boundedConversationId(value) {
5004
+ if (typeof value !== "string" || value.length === 0) return null;
5005
+ return Buffer.byteLength(value, "utf8") <= MAX_CONVERSATION_ID_BYTES ? value : null;
5006
+ }
5007
+ function protocolFailure(state, detail) {
5008
+ if (state.protocolDiagnostics.length < MAX_PROTOCOL_DIAGNOSTICS) state.protocolDiagnostics.push(detail);
4779
5009
  }
4780
5010
  function emitTextDelta(emit, state, delta) {
4781
5011
  if (delta.length === 0) return;
4782
- state.text += delta;
4783
- const message = buildAssistantMessage({
4784
- model: state.model,
4785
- text: state.text,
4786
- exitCode: 0,
4787
- aborted: false,
4788
- stderr: ""
4789
- });
5012
+ state.text = appendBoundedText(state.text, delta);
4790
5013
  if (!state.started) {
4791
5014
  state.started = true;
4792
- emit({ type: "message_start", message });
5015
+ emit({
5016
+ type: "message_start",
5017
+ message: buildAssistantMessage({
5018
+ model: state.model,
5019
+ text: "",
5020
+ result: null,
5021
+ conversationId: null,
5022
+ exitCode: 0,
5023
+ aborted: false,
5024
+ diagnostic: ""
5025
+ })
5026
+ });
4793
5027
  }
4794
5028
  emit({
4795
5029
  type: "message_update",
4796
- message,
4797
- assistantMessageEvent: {
4798
- type: "text_delta",
4799
- contentIndex: 0,
4800
- delta,
4801
- partial: message
4802
- }
5030
+ assistantMessageEvent: { type: "text_delta", contentIndex: 0, delta }
4803
5031
  });
4804
5032
  }
4805
- async function readStdout(child, emit, state) {
4806
- for await (const chunk of child.stdout) {
4807
- emitTextDelta(emit, state, String(chunk));
5033
+ async function readStream(child, emit, state) {
5034
+ for await (const bounded of readBoundedLines(child.stdout, {
5035
+ maxLineBytes: ANTIGRAVITY_MAX_STREAM_LINE_BYTES,
5036
+ maxTotalBytes: ANTIGRAVITY_MAX_STREAM_BYTES
5037
+ })) {
5038
+ if (bounded.kind === "oversized") {
5039
+ protocolFailure(state, "oversized structured output line");
5040
+ continue;
5041
+ }
5042
+ const line = bounded.line;
5043
+ if (!line.trim()) continue;
5044
+ const event = parseAntigravityStreamLine(line);
5045
+ if (!event) {
5046
+ protocolFailure(state, "unreadable structured output line");
5047
+ continue;
5048
+ }
5049
+ if (state.terminalSeen) {
5050
+ protocolFailure(state, "event after terminal result");
5051
+ continue;
5052
+ }
5053
+ switch (event.event) {
5054
+ case "init":
5055
+ if (state.initSeen) {
5056
+ protocolFailure(state, "duplicate init event");
5057
+ break;
5058
+ }
5059
+ state.initSeen = true;
5060
+ state.conversationId = boundedConversationId(event.conversationId);
5061
+ if (event.model?.trim()) state.model = event.model.trim();
5062
+ break;
5063
+ case "text":
5064
+ if (!state.initSeen) {
5065
+ protocolFailure(state, "text event before init");
5066
+ break;
5067
+ }
5068
+ state.conversationId = boundedConversationId(event.conversationId) ?? state.conversationId;
5069
+ emitTextDelta(emit, state, event.delta);
5070
+ break;
5071
+ case "result":
5072
+ if (!state.initSeen) {
5073
+ protocolFailure(state, "terminal result before init");
5074
+ break;
5075
+ }
5076
+ state.terminalSeen = true;
5077
+ state.result = event.result;
5078
+ state.conversationId = boundedConversationId(event.result.conversation_id) ?? state.conversationId;
5079
+ break;
5080
+ case "other":
5081
+ if (!state.initSeen) protocolFailure(state, "event before init");
5082
+ break;
5083
+ }
4808
5084
  }
4809
5085
  }
4810
- function startAntigravityWorkerRun(input, emit) {
4811
- const args = buildAgyArgs(input);
4812
- const child = spawn(ANTIGRAVITY_BINARY, args, {
4813
- cwd: process.cwd(),
4814
- env: process.env,
4815
- stdio: ["ignore", "pipe", "pipe"]
5086
+ function resultDiagnostic(input) {
5087
+ if (input.aborted) return "Antigravity run was cancelled";
5088
+ if (input.spawnError) return input.spawnError;
5089
+ if (input.streamError) return input.streamError;
5090
+ if (input.protocolDiagnostics.length > 0) {
5091
+ return `Antigravity structured output violated the protocol: ${input.protocolDiagnostics.join("; ")}`;
5092
+ }
5093
+ if (input.result === null) {
5094
+ return "Antigravity CLI ended without a terminal stream result. Update `agy` and verify stream-json support.";
5095
+ }
5096
+ if (input.result.status !== "SUCCESS") {
5097
+ const providerError = boundedProviderField(input.result.error, "error").trim();
5098
+ return providerError || `Antigravity returned terminal status ${String(input.result.status ?? "missing")}`;
5099
+ }
5100
+ if (input.exitCode !== 0) return `Antigravity returned SUCCESS but exited with status ${input.exitCode}`;
5101
+ if (typeof input.result.response !== "string") return "Antigravity SUCCESS result omitted its required response";
5102
+ return "";
5103
+ }
5104
+ function buildAssistantMessage(input) {
5105
+ const succeeded = !input.aborted && input.exitCode === 0 && input.result?.status === "SUCCESS" && typeof input.result.response === "string" && input.diagnostic.length === 0;
5106
+ const message = {
5107
+ role: "assistant",
5108
+ content: [{ type: "text", text: input.text }],
5109
+ api: "external-agent-subprocess",
5110
+ provider: "antigravity",
5111
+ model: input.model,
5112
+ usage: normalizeUsage(input.result?.usage),
5113
+ stopReason: input.aborted ? "aborted" : succeeded ? "stop" : "error",
5114
+ timestamp: Date.now()
5115
+ };
5116
+ if (input.conversationId) message.responseId = input.conversationId;
5117
+ if (input.diagnostic) message.errorMessage = boundedExternalDiagnostic(input.diagnostic);
5118
+ return message;
5119
+ }
5120
+ function startAntigravityWorkerRun(input, emit, dependencies = {}) {
5121
+ const sourceEnv = dependencies.environment ?? process.env;
5122
+ const args = buildAgyArgs(input, sourceEnv);
5123
+ const stdinLine = buildAgyStdinLine(input);
5124
+ const workspaceRoot = dependencies.workspaceRoot ?? process.cwd();
5125
+ const cwd = resolveSafeCwd(input.cwd, workspaceRoot);
5126
+ const child = spawn(dependencies.binary ?? ANTIGRAVITY_BINARY, args, {
5127
+ cwd,
5128
+ env: buildSafeToolEnv({}, sourceEnv),
5129
+ detached: process.platform !== "win32",
5130
+ stdio: ["pipe", "pipe", "pipe"]
4816
5131
  });
4817
- const streamState = { started: false, text: "", model: input.wireModelId };
5132
+ const streamState = {
5133
+ started: false,
5134
+ text: "",
5135
+ model: input.wireModelId,
5136
+ result: null,
5137
+ conversationId: null,
5138
+ initSeen: false,
5139
+ terminalSeen: false,
5140
+ protocolDiagnostics: []
5141
+ };
4818
5142
  let aborted = false;
4819
- let killTimer = null;
5143
+ let spawnError = "";
5144
+ let streamError = "";
5145
+ const terminator = createProcessTreeTerminator(child, dependencies.killGraceMs ?? 1500);
4820
5146
  const abort = () => {
5147
+ if (child.exitCode !== null) return;
4821
5148
  aborted = true;
4822
- if (child.killed) return;
4823
- child.kill("SIGTERM");
4824
- killTimer = setTimeout(() => {
4825
- if (!child.killed) child.kill("SIGKILL");
4826
- }, 1500);
5149
+ terminator.terminate();
4827
5150
  };
4828
- if (input.signal) {
4829
- if (input.signal.aborted) abort();
4830
- else input.signal.addEventListener("abort", abort, { once: true });
4831
- }
5151
+ const onAbort = () => abort();
5152
+ if (input.signal?.aborted) abort();
5153
+ else input.signal?.addEventListener("abort", onAbort, { once: true });
5154
+ child.once("error", (cause) => {
5155
+ spawnError = cause.code === "ENOENT" ? "Antigravity CLI (`agy`) is not installed or not on PATH." : boundedExternalDiagnostic(cause.message);
5156
+ });
5157
+ child.stdin.on("error", (cause) => {
5158
+ if (!aborted) spawnError ||= boundedExternalDiagnostic(`could not send work order to Antigravity: ${cause.message}`);
5159
+ });
5160
+ child.stdin.end(stdinLine);
4832
5161
  const promise = (async () => {
4833
5162
  emit({ type: "agent_start" });
4834
- const stderrPromise = readStderr(child);
4835
- const stdoutPromise = readStdout(child, emit, streamState);
4836
- const exitCode = await waitForClose(child);
4837
- await stdoutPromise.catch(() => {
4838
- });
4839
- const stderr = await stderrPromise.catch(() => "");
4840
- if (killTimer) clearTimeout(killTimer);
4841
- const finalText = streamState.text || (exitCode === 0 ? "" : stderr.trim());
4842
- const finalMessage = buildAssistantMessage({
4843
- model: streamState.model,
4844
- text: finalText,
4845
- exitCode,
4846
- aborted,
4847
- stderr
4848
- });
4849
- if (!streamState.started) emit({ type: "message_start", message: finalMessage });
4850
- emit({ type: "message_end", message: finalMessage });
4851
- const messages = [finalMessage];
4852
- emit({ type: "agent_end", messages });
4853
- if (exitCode !== 0 && stderr.trim().length > 0 && !aborted) {
4854
- process.stderr.write(`[worker:antigravity-code] ${stderr.trim()}
5163
+ try {
5164
+ const stderrPromise = readStderr(child);
5165
+ const stdoutPromise = readStream(child, emit, streamState).catch((cause) => {
5166
+ streamError = boundedExternalDiagnostic(cause instanceof Error ? cause.message : String(cause));
5167
+ terminator.terminate();
5168
+ });
5169
+ const exitCode = await waitForClose(child);
5170
+ await stdoutPromise;
5171
+ const stderr = await stderrPromise.catch(
5172
+ (cause) => boundedExternalDiagnostic(cause instanceof Error ? cause.message : String(cause))
5173
+ );
5174
+ let terminalResponse = "";
5175
+ try {
5176
+ terminalResponse = boundedProviderField(streamState.result?.response, "response");
5177
+ } catch (cause) {
5178
+ streamError ||= boundedExternalDiagnostic(cause instanceof Error ? cause.message : String(cause));
5179
+ }
5180
+ let diagnostic = "";
5181
+ try {
5182
+ diagnostic = resultDiagnostic({
5183
+ result: streamState.result,
5184
+ exitCode,
5185
+ spawnError,
5186
+ stderr,
5187
+ protocolDiagnostics: streamState.protocolDiagnostics,
5188
+ streamError,
5189
+ aborted
5190
+ });
5191
+ } catch (cause) {
5192
+ diagnostic = boundedExternalDiagnostic(cause instanceof Error ? cause.message : String(cause));
5193
+ }
5194
+ const finalText = terminalResponse || streamState.text;
5195
+ const finalMessage = buildAssistantMessage({
5196
+ model: streamState.model,
5197
+ text: finalText,
5198
+ result: streamState.result,
5199
+ conversationId: streamState.conversationId,
5200
+ exitCode,
5201
+ aborted,
5202
+ diagnostic
5203
+ });
5204
+ if (!streamState.started) emit({ type: "message_start", message: finalMessage });
5205
+ emit({ type: "message_end", message: finalMessage });
5206
+ const messages = [finalMessage];
5207
+ emit({ type: "agent_end", messages });
5208
+ if (finalMessage.stopReason === "error" && diagnostic && !aborted) {
5209
+ process.stderr.write(`[worker:antigravity-code] ${boundedExternalDiagnostic(diagnostic)}
4855
5210
  `);
5211
+ }
5212
+ return { messages, exitCode: finalMessage.stopReason === "stop" ? 0 : 1 };
5213
+ } finally {
5214
+ terminator.cleanup();
5215
+ input.signal?.removeEventListener("abort", onAbort);
4856
5216
  }
4857
- return { messages, exitCode: exitCode === 0 ? 0 : 1 };
4858
5217
  })();
4859
- return {
4860
- promise,
4861
- abort
4862
- };
5218
+ return { promise, abort };
4863
5219
  }
4864
5220
 
4865
5221
  // src/engine/claude/subprocess-runtime.ts
@@ -4926,17 +5282,17 @@ function buildClaudeCodeArgs(input) {
4926
5282
  args.push(buildClaudeCodePrompt(input));
4927
5283
  return args;
4928
5284
  }
4929
- function finite(value) {
5285
+ function finite2(value) {
4930
5286
  return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : 0;
4931
5287
  }
4932
- function normalizeUsage(raw, totalCostUsd = 0) {
4933
- const record2 = typeof raw === "object" && raw !== null ? raw : {};
4934
- const input = finite(record2.input_tokens) + finite(record2.inputTokens) + finite(record2.input) + finite(record2.prompt_tokens) + finite(record2.promptTokens);
4935
- const output = finite(record2.output_tokens) + finite(record2.outputTokens) + finite(record2.output) + finite(record2.completion_tokens) + finite(record2.completionTokens);
4936
- const cacheRead = finite(record2.cache_read_input_tokens) + finite(record2.cacheReadInputTokens) + finite(record2.cacheRead) + finite(record2.cacheReadTokens);
4937
- const cacheWrite = finite(record2.cache_creation_input_tokens) + finite(record2.cacheCreationInputTokens) + finite(record2.cacheWrite) + finite(record2.cacheWriteTokens);
5288
+ function normalizeUsage2(raw, totalCostUsd = 0) {
5289
+ const record3 = typeof raw === "object" && raw !== null ? raw : {};
5290
+ const input = finite2(record3.input_tokens) + finite2(record3.inputTokens) + finite2(record3.input) + finite2(record3.prompt_tokens) + finite2(record3.promptTokens);
5291
+ const output = finite2(record3.output_tokens) + finite2(record3.outputTokens) + finite2(record3.output) + finite2(record3.completion_tokens) + finite2(record3.completionTokens);
5292
+ const cacheRead = finite2(record3.cache_read_input_tokens) + finite2(record3.cacheReadInputTokens) + finite2(record3.cacheRead) + finite2(record3.cacheReadTokens);
5293
+ const cacheWrite = finite2(record3.cache_creation_input_tokens) + finite2(record3.cacheCreationInputTokens) + finite2(record3.cacheWrite) + finite2(record3.cacheWriteTokens);
4938
5294
  const totalTokens = input + output + cacheRead + cacheWrite;
4939
- const total = finite(totalCostUsd) + finite(record2.costUSD) + finite(record2.cost_usd);
5295
+ const total = finite2(totalCostUsd) + finite2(record3.costUSD) + finite2(record3.cost_usd);
4940
5296
  return {
4941
5297
  input,
4942
5298
  output,
@@ -4946,8 +5302,8 @@ function normalizeUsage(raw, totalCostUsd = 0) {
4946
5302
  cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total }
4947
5303
  };
4948
5304
  }
4949
- function nestedRecord(record2, key) {
4950
- const value = record2[key];
5305
+ function nestedRecord(record3, key) {
5306
+ const value = record3[key];
4951
5307
  return typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
4952
5308
  }
4953
5309
  function extractContentText(content) {
@@ -4955,34 +5311,34 @@ function extractContentText(content) {
4955
5311
  let out = "";
4956
5312
  for (const block of content) {
4957
5313
  if (typeof block !== "object" || block === null) continue;
4958
- const record2 = block;
4959
- if (record2.type === "text" && typeof record2.text === "string") out += record2.text;
5314
+ const record3 = block;
5315
+ if (record3.type === "text" && typeof record3.text === "string") out += record3.text;
4960
5316
  }
4961
5317
  return out;
4962
5318
  }
4963
- function extractDelta(record2) {
4964
- const delta = nestedRecord(record2, "delta");
5319
+ function extractDelta(record3) {
5320
+ const delta = nestedRecord(record3, "delta");
4965
5321
  if (delta && typeof delta.text === "string") return delta.text;
4966
5322
  if (delta && typeof delta.thinking === "string") return "";
4967
- const contentBlock = nestedRecord(record2, "content_block");
5323
+ const contentBlock = nestedRecord(record3, "content_block");
4968
5324
  if (contentBlock && contentBlock.type === "text" && typeof contentBlock.text === "string") return contentBlock.text;
4969
- if (typeof record2.delta === "string") return record2.delta;
5325
+ if (typeof record3.delta === "string") return record3.delta;
4970
5326
  return "";
4971
5327
  }
4972
- function assistantTextFromEvent(record2) {
4973
- const message = nestedRecord(record2, "message");
5328
+ function assistantTextFromEvent(record3) {
5329
+ const message = nestedRecord(record3, "message");
4974
5330
  if (message) return extractContentText(message.content);
4975
- return extractContentText(record2.content);
5331
+ return extractContentText(record3.content);
4976
5332
  }
4977
- function resultText(record2) {
4978
- if (!record2) return "";
4979
- return typeof record2.result === "string" ? record2.result : "";
5333
+ function resultText(record3) {
5334
+ if (!record3) return "";
5335
+ return typeof record3.result === "string" ? record3.result : "";
4980
5336
  }
4981
- function resultError(record2, stderr) {
4982
- if (record2) {
4983
- if (typeof record2.error === "string") return record2.error;
4984
- if (Array.isArray(record2.errors)) return record2.errors.map(String).join("; ");
4985
- if (record2.subtype !== void 0 && record2.subtype !== "success") return String(record2.subtype);
5337
+ function resultError(record3, stderr) {
5338
+ if (record3) {
5339
+ if (typeof record3.error === "string") return record3.error;
5340
+ if (Array.isArray(record3.errors)) return record3.errors.map(String).join("; ");
5341
+ if (record3.subtype !== void 0 && record3.subtype !== "success") return String(record3.subtype);
4986
5342
  }
4987
5343
  return stderr.trim();
4988
5344
  }
@@ -4994,7 +5350,7 @@ function buildAssistantMessage2(input) {
4994
5350
  api: "claude-code-subprocess",
4995
5351
  provider: "anthropic",
4996
5352
  model: input.model,
4997
- usage: normalizeUsage(input.result?.usage, finite(input.result?.total_cost_usd)),
5353
+ usage: normalizeUsage2(input.result?.usage, finite2(input.result?.total_cost_usd)),
4998
5354
  stopReason: input.aborted ? "aborted" : input.exitCode === 0 ? "stop" : "error",
4999
5355
  timestamp: Date.now()
5000
5356
  };
@@ -5041,18 +5397,18 @@ async function readJsonLines(child, emit, state) {
5041
5397
  continue;
5042
5398
  }
5043
5399
  if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) continue;
5044
- const record2 = parsed;
5045
- if (record2.type === "system" && typeof record2.model === "string") state.model = record2.model;
5046
- if (record2.type === "result") {
5047
- state.result = record2;
5400
+ const record3 = parsed;
5401
+ if (record3.type === "system" && typeof record3.model === "string") state.model = record3.model;
5402
+ if (record3.type === "result") {
5403
+ state.result = record3;
5048
5404
  continue;
5049
5405
  }
5050
- if (record2.type === "assistant") {
5051
- const text = assistantTextFromEvent(record2);
5406
+ if (record3.type === "assistant") {
5407
+ const text = assistantTextFromEvent(record3);
5052
5408
  if (text.length > 0 && text.length >= state.text.length) state.text = text;
5053
5409
  continue;
5054
5410
  }
5055
- emitTextDelta2(emit, state, extractDelta(record2));
5411
+ emitTextDelta2(emit, state, extractDelta(record3));
5056
5412
  }
5057
5413
  }
5058
5414
  function startClaudeCodeWorkerRun(input, emit) {
@@ -5815,7 +6171,7 @@ function toolWritesOpaquely(toolName) {
5815
6171
  var GIT_PATH_MUTATIONS = /* @__PURE__ */ new Set(["mv", "rm"]);
5816
6172
  function gitPathOperands(command) {
5817
6173
  const targets = [];
5818
- for (const segment of splitCommandSegments(command)) {
6174
+ for (const segment of commandArgumentSegments(command)) {
5819
6175
  if (segment[0] !== "git") continue;
5820
6176
  const subcommand = segment[1];
5821
6177
  if (subcommand === void 0 || !GIT_PATH_MUTATIONS.has(subcommand)) continue;
@@ -5826,20 +6182,6 @@ function gitPathOperands(command) {
5826
6182
  }
5827
6183
  return targets;
5828
6184
  }
5829
- function splitCommandSegments(command) {
5830
- const segments = [];
5831
- let current = [];
5832
- for (const token of tokenizeShellLike(command)) {
5833
- if (token === ";" || token === "&&" || token === "||" || token === "|") {
5834
- if (current.length > 0) segments.push(current);
5835
- current = [];
5836
- continue;
5837
- }
5838
- current.push(token);
5839
- }
5840
- if (current.length > 0) segments.push(current);
5841
- return segments;
5842
- }
5843
6185
  function commandOf(args) {
5844
6186
  const command = args?.command;
5845
6187
  return typeof command === "string" && command.length > 0 ? command : null;
@@ -6042,9 +6384,9 @@ import { performance as performance2 } from "node:perf_hooks";
6042
6384
  function isRecord7(value) {
6043
6385
  return typeof value === "object" && value !== null && !Array.isArray(value);
6044
6386
  }
6045
- function stringField(record2, ...keys) {
6387
+ function stringField(record3, ...keys) {
6046
6388
  for (const key of keys) {
6047
- const value = record2[key];
6389
+ const value = record3[key];
6048
6390
  if (typeof value === "string" && value.trim().length > 0) return value.trim();
6049
6391
  }
6050
6392
  return void 0;
@@ -6417,4 +6759,4 @@ export {
6417
6759
  isTerminalRunEnvelope,
6418
6760
  runKindSupportsLiveSteering
6419
6761
  };
6420
- //# sourceMappingURL=chunk-IKSLQ4XV.js.map
6762
+ //# sourceMappingURL=chunk-PAJQJ7BS.js.map