@humain/humain-code 0.8.3 → 0.8.4

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 (899) hide show
  1. package/CHANGELOG.md +141 -0
  2. package/dist/bundle/agent-monitor.js +1 -1
  3. package/dist/bundle/chunks/anthropic-messages-42CGJCSR.js +82 -0
  4. package/dist/bundle/chunks/ask-VH7GNX75.js +97 -0
  5. package/dist/bundle/chunks/azure-openai-responses-DOKKMBUN.js +15 -0
  6. package/dist/bundle/chunks/bedrock-converse-stream.js +200 -179
  7. package/dist/bundle/chunks/bowser-UX7KDMIY.js +92 -0
  8. package/dist/bundle/chunks/{chunk-46C6D7UC.js → chunk-2CYGUEQO.js} +1 -1
  9. package/dist/bundle/chunks/chunk-3RXT35Y3.js +3 -0
  10. package/dist/bundle/chunks/chunk-4BNDLR6C.js +177 -0
  11. package/dist/bundle/chunks/{chunk-MPRAQ6ZI.js → chunk-4LGBXPUD.js} +1 -1
  12. package/dist/bundle/chunks/chunk-4SL6URR3.js +90 -0
  13. package/dist/bundle/chunks/{chunk-7LSTTCSC.js → chunk-52642TYH.js} +316 -148
  14. package/dist/bundle/chunks/{chunk-LSRXA7OS.js → chunk-5C5K4EVJ.js} +3 -3
  15. package/dist/bundle/chunks/{chunk-2JNJJ6SZ.js → chunk-5KUCY54O.js} +3 -3
  16. package/dist/bundle/chunks/{chunk-4TDNOR36.js → chunk-625QJSFJ.js} +1 -1
  17. package/dist/bundle/chunks/chunk-73YX5XGR.js +2461 -0
  18. package/dist/bundle/chunks/chunk-7DIRHF4H.js +17 -0
  19. package/dist/bundle/chunks/{chunk-QJB5YI3I.js → chunk-7PAXKU7M.js} +1 -1
  20. package/dist/bundle/chunks/{chunk-R2KD2HFT.js → chunk-7YB3HRRN.js} +83 -196
  21. package/dist/bundle/chunks/{chunk-DCXHRP6C.js → chunk-A2UZYK23.js} +13 -13
  22. package/dist/bundle/chunks/chunk-A5ZMBTTM.js +12 -0
  23. package/dist/bundle/chunks/{chunk-JKX5EGOT.js → chunk-AER66CNP.js} +13 -13
  24. package/dist/bundle/chunks/chunk-ARTF7ZMQ.js +5 -0
  25. package/dist/bundle/chunks/chunk-B3FT6L6S.js +131 -0
  26. package/dist/bundle/chunks/chunk-BIC5BSNX.js +13 -0
  27. package/dist/bundle/chunks/{chunk-JSHKS7VH.js → chunk-BNZZJ4LO.js} +1 -1
  28. package/dist/bundle/chunks/{chunk-4MKATHT2.js → chunk-CG43CMFH.js} +1 -1
  29. package/dist/bundle/chunks/{chunk-2XD7TLKB.js → chunk-CIAXW64K.js} +16 -16
  30. package/dist/bundle/chunks/{chunk-VFLVWPLZ.js → chunk-CKFLQGJN.js} +20 -16
  31. package/dist/bundle/chunks/chunk-D4UCXXDP.js +115 -0
  32. package/dist/bundle/chunks/{chunk-HQMUDHC3.js → chunk-D6ZWWDW5.js} +6 -5
  33. package/dist/bundle/chunks/{chunk-4GB7A76U.js → chunk-EVDQRT3I.js} +225 -348
  34. package/dist/bundle/chunks/{chunk-FJIISX5W.js → chunk-F74XLJPC.js} +195 -192
  35. package/dist/bundle/chunks/chunk-FDRBTGFJ.js +4 -0
  36. package/dist/bundle/chunks/{chunk-E4VUW4RI.js → chunk-FLWO3H5J.js} +12 -12
  37. package/dist/bundle/chunks/{chunk-KLSRGGOH.js → chunk-G2PFPQX7.js} +2 -2
  38. package/dist/bundle/chunks/chunk-GMPJWLZS.js +57 -0
  39. package/dist/bundle/chunks/{chunk-M5TVWJ5T.js → chunk-H35P7ROY.js} +462 -441
  40. package/dist/bundle/chunks/chunk-HCHCYBNK.js +2 -0
  41. package/dist/bundle/chunks/{chunk-7WE77IE3.js → chunk-HRNYDRL7.js} +1 -1
  42. package/dist/bundle/chunks/chunk-HWFAAGYK.js +23 -0
  43. package/dist/bundle/chunks/{chunk-VSXVZVBE.js → chunk-HWXQCJDP.js} +408 -392
  44. package/dist/bundle/chunks/{chunk-PVNXN2TC.js → chunk-II5C7G67.js} +1 -1
  45. package/dist/bundle/chunks/{chunk-F2H47FRF.js → chunk-IMRZP5SC.js} +182 -137
  46. package/dist/bundle/chunks/{chunk-AW24RHGJ.js → chunk-J5YFXMTM.js} +4 -4
  47. package/dist/bundle/chunks/chunk-J64VNQ6D.js +13 -0
  48. package/dist/bundle/chunks/{chunk-65FLSKDA.js → chunk-K5EFEIFP.js} +5 -4
  49. package/dist/bundle/chunks/{chunk-KI7CHPWC.js → chunk-KJ3QRSSY.js} +46 -43
  50. package/dist/bundle/chunks/{cli-6DJO467D.js → chunk-KSEO2LRK.js} +12 -10
  51. package/dist/bundle/chunks/{chunk-HHWVVNGG.js → chunk-MA2WCMSN.js} +2 -2
  52. package/dist/bundle/chunks/{chunk-L4J7SMJB.js → chunk-MAEKQSFU.js} +1 -1
  53. package/dist/bundle/chunks/chunk-MHQNLTZR.js +8 -0
  54. package/dist/bundle/chunks/chunk-MLOUZAVZ.js +122 -0
  55. package/dist/bundle/chunks/chunk-MQYR4Q6X.js +5 -0
  56. package/dist/bundle/chunks/chunk-MXF3KYLZ.js +4 -0
  57. package/dist/bundle/chunks/{chunk-GY663MNP.js → chunk-MZRTVX7F.js} +1 -1
  58. package/dist/bundle/chunks/chunk-MZYHSWHX.js +59 -0
  59. package/dist/bundle/chunks/{chunk-6HTHDVJC.js → chunk-NPVRWPGX.js} +1 -1
  60. package/dist/bundle/chunks/{chunk-BRSLXHED.js → chunk-O44A4E4K.js} +1 -1
  61. package/dist/bundle/chunks/{chunk-T2ZGMEMV.js → chunk-OADQOW67.js} +175 -260
  62. package/dist/bundle/chunks/chunk-OTVHRZ67.js +17 -0
  63. package/dist/bundle/chunks/{chunk-J4GII2EE.js → chunk-P7SLTLSZ.js} +51 -46
  64. package/dist/bundle/chunks/{chunk-7OZNMWAJ.js → chunk-PPGSQZZF.js} +1 -1
  65. package/dist/bundle/chunks/chunk-PYX6ZCC7.js +29 -0
  66. package/dist/bundle/chunks/chunk-PZ7NYBHJ.js +8 -0
  67. package/dist/bundle/chunks/{chunk-VCMXBP5S.js → chunk-QESIDBMW.js} +1 -7
  68. package/dist/bundle/chunks/chunk-QUWVILLB.js +3 -0
  69. package/dist/bundle/chunks/chunk-QZWUXGY7.js +99 -0
  70. package/dist/bundle/chunks/{chunk-MIAXMK5F.js → chunk-QZXLTW7V.js} +8 -7
  71. package/dist/bundle/chunks/chunk-RP6MWUAP.js +4 -0
  72. package/dist/bundle/chunks/{chunk-MUN4ZZZP.js → chunk-SOE25WIS.js} +1143 -1167
  73. package/dist/bundle/chunks/{chunk-JSZBTGI6.js → chunk-SZZ5PNP6.js} +2 -2
  74. package/dist/bundle/chunks/chunk-T5WECB2D.js +7 -0
  75. package/dist/bundle/chunks/{chunk-2NVGOSBN.js → chunk-T7F2TEIS.js} +37 -13
  76. package/dist/bundle/chunks/{chunk-ZSWU5KKA.js → chunk-UOSJTMCL.js} +7 -3
  77. package/dist/bundle/chunks/{chunk-6P6MMQUH.js → chunk-UTRUALFN.js} +3 -3
  78. package/dist/bundle/chunks/{chunk-PWFM6AQQ.js → chunk-V2HTCZRF.js} +70 -67
  79. package/dist/bundle/chunks/{chunk-JX6YIPNK.js → chunk-WCKS2DPT.js} +1 -1
  80. package/dist/bundle/chunks/chunk-XGOJCV6Z.js +2 -0
  81. package/dist/bundle/chunks/chunk-XGSJX23G.js +1151 -0
  82. package/dist/bundle/chunks/{chunk-7WETECIB.js → chunk-Z7BWHPJ2.js} +1 -1
  83. package/dist/bundle/chunks/chunk-ZFFDBTG3.js +17 -0
  84. package/dist/bundle/chunks/cli-NJLV3XDZ.js +3 -0
  85. package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-JEZVYITT.js → cloudflare-workers-ai-system-one-ZAZW4M4B.js} +1 -1
  86. package/dist/bundle/chunks/{compat-4ILE5BEC.js → compat-7UJJAO4E.js} +12 -12
  87. package/dist/bundle/chunks/{curator-server-QB4GITGS.js → curator-server-MW645JI3.js} +2 -2
  88. package/dist/bundle/chunks/{dist-NXHRL2KY.js → dist-7PCCEUQF.js} +2 -2
  89. package/dist/bundle/chunks/{dist-I6CI3CG5.js → dist-I53JI67E.js} +9 -9
  90. package/dist/bundle/chunks/{dist-35STTNYA.js → dist-NI2PTSLH.js} +1 -1
  91. package/dist/bundle/chunks/{dist-CBODG4CA.js → dist-VXQT3DQY.js} +6 -6
  92. package/dist/bundle/chunks/{dist-cjs-EROMDUKS.js → dist-cjs-4JQA6W3S.js} +31 -31
  93. package/dist/bundle/chunks/doctor-KJVAYG3F.js +83 -0
  94. package/dist/bundle/chunks/{easter-egg-3d-VZC5WOYV.js → easter-egg-3d-Z24JLXD4.js} +1 -1
  95. package/dist/bundle/chunks/entry-3EL6GOWK.js +2 -0
  96. package/dist/bundle/chunks/{entry-6XDR2IDE.js → entry-4IMREZBD.js} +80 -79
  97. package/dist/bundle/chunks/{execute-6MEJJF2T.js → execute-C4BZQRPQ.js} +23 -22
  98. package/dist/bundle/chunks/{extract-L373D6O7.js → extract-XVQCIS7D.js} +5 -5
  99. package/dist/bundle/chunks/{flow-implementer-XOP4MG5X.js → flow-implementer-GE2ARQKR.js} +5 -5
  100. package/dist/bundle/chunks/github-copilot.js +57 -56
  101. package/dist/bundle/chunks/google-generative-ai-P2P45MYP.js +22 -0
  102. package/dist/bundle/chunks/google-vertex-SHY4IS5F.js +26 -0
  103. package/dist/bundle/chunks/{host-WOLZCWQQ.js → host-YESS2VAB.js} +1 -1
  104. package/dist/bundle/chunks/{index.bundle-HONF3PUD.js → index.bundle-TZT64KLH.js} +102 -89
  105. package/dist/bundle/chunks/{inprocess-MBKFGDM2.js → inprocess-MGMVI6HN.js} +6 -6
  106. package/dist/bundle/chunks/interactive-mode-HHWOE4FD.js +5 -0
  107. package/dist/bundle/chunks/{llama-cpp-classify-KYZT532X.js → llama-cpp-classify-RSRH4KV2.js} +5 -5
  108. package/dist/bundle/chunks/mistral-conversations-YTMJKHHI.js +42 -0
  109. package/dist/bundle/chunks/{node-N7TPBUJB.js → node-FF6QQQLH.js} +1 -1
  110. package/dist/bundle/chunks/openai-codex-responses-NUCJOJSZ.js +97 -0
  111. package/dist/bundle/chunks/openai-completions-E5NRJUHA.js +91 -0
  112. package/dist/bundle/chunks/{openai-decisions-JMSDGR7K.js → openai-decisions-342J5ZYG.js} +1 -1
  113. package/dist/bundle/chunks/openai-responses-BN5Z4HFI.js +26 -0
  114. package/dist/bundle/chunks/openrouter-images-7RNG3JVF.js +12 -0
  115. package/dist/bundle/chunks/{pdfjs-FE3L72A6.js → pdfjs-LSTLRXQW.js} +1415 -1416
  116. package/dist/bundle/chunks/pi-messages-2L7FV5OK.js +22 -0
  117. package/dist/bundle/chunks/questionnaire-session-XEVAK7JS.js +123 -0
  118. package/dist/bundle/chunks/runtime-2FSZRUG5.js +2 -0
  119. package/dist/bundle/chunks/session-picker-666KJIVM.js +4 -0
  120. package/dist/bundle/chunks/startup-ui-INEVSNGK.js +3 -0
  121. package/dist/bundle/chunks/{trace-command-VM7FBWPE.js → trace-command-BCVMZ5ZD.js} +4 -4
  122. package/dist/bundle/chunks/typesafe-system-one-UJUNSZG4.js +3 -0
  123. package/dist/bundle/chunks/{undici-WVNE45GY.js → undici-7IGAYA4S.js} +1 -1
  124. package/dist/bundle/chunks/virtual-modules-UXSSFNV5.js +29 -0
  125. package/dist/bundle/cli-runtime.js +5 -5
  126. package/dist/bundle/flow/package.json +3 -3
  127. package/dist/bundle/index.js +13 -13
  128. package/dist/bundle/orchestrate/package.json +1 -1
  129. package/dist/bundle/rpc-entry.js +5 -4
  130. package/dist/cli/agent-dir-arg.d.ts +12 -0
  131. package/dist/cli/agent-dir-arg.d.ts.map +1 -0
  132. package/dist/cli/agent-dir-arg.js +15 -0
  133. package/dist/cli/agent-dir-arg.js.map +1 -0
  134. package/dist/cli/args.d.ts +9 -0
  135. package/dist/cli/args.d.ts.map +1 -1
  136. package/dist/cli/args.js +19 -5
  137. package/dist/cli/args.js.map +1 -1
  138. package/dist/cli/auth-check.d.ts +1 -1
  139. package/dist/cli/auth-check.d.ts.map +1 -1
  140. package/dist/cli/auth-check.js +4 -2
  141. package/dist/cli/auth-check.js.map +1 -1
  142. package/dist/cli/doctor-config.d.ts +14 -0
  143. package/dist/cli/doctor-config.d.ts.map +1 -0
  144. package/dist/cli/doctor-config.js +92 -0
  145. package/dist/cli/doctor-config.js.map +1 -0
  146. package/dist/cli/doctor-system.d.ts +12 -0
  147. package/dist/cli/doctor-system.d.ts.map +1 -0
  148. package/dist/cli/doctor-system.js +109 -0
  149. package/dist/cli/doctor-system.js.map +1 -0
  150. package/dist/cli/doctor.d.ts +11 -0
  151. package/dist/cli/doctor.d.ts.map +1 -0
  152. package/dist/cli/doctor.js +323 -0
  153. package/dist/cli/doctor.js.map +1 -0
  154. package/dist/cli/doctor.lazy.d.ts +3 -0
  155. package/dist/cli/doctor.lazy.d.ts.map +1 -0
  156. package/dist/cli/doctor.lazy.js +3 -0
  157. package/dist/cli/doctor.lazy.js.map +1 -0
  158. package/dist/cli/list-models.d.ts.map +1 -1
  159. package/dist/cli/list-models.js +0 -4
  160. package/dist/cli/list-models.js.map +1 -1
  161. package/dist/cli/project-trust.d.ts.map +1 -1
  162. package/dist/cli/project-trust.js +6 -6
  163. package/dist/cli/project-trust.js.map +1 -1
  164. package/dist/cli/startup-ui.d.ts +3 -2
  165. package/dist/cli/startup-ui.d.ts.map +1 -1
  166. package/dist/cli/startup-ui.js +23 -10
  167. package/dist/cli/startup-ui.js.map +1 -1
  168. package/dist/config.d.ts +5 -1
  169. package/dist/config.d.ts.map +1 -1
  170. package/dist/config.js +13 -3
  171. package/dist/config.js.map +1 -1
  172. package/dist/coordination/broker/broker.d.ts +3 -3
  173. package/dist/coordination/broker/broker.d.ts.map +1 -1
  174. package/dist/coordination/broker/broker.js +15 -7
  175. package/dist/coordination/broker/broker.js.map +1 -1
  176. package/dist/core/acceptance-command.d.ts +6 -3
  177. package/dist/core/acceptance-command.d.ts.map +1 -1
  178. package/dist/core/acceptance-command.js +43 -12
  179. package/dist/core/acceptance-command.js.map +1 -1
  180. package/dist/core/acceptance-ledger.d.ts +2 -0
  181. package/dist/core/acceptance-ledger.d.ts.map +1 -1
  182. package/dist/core/acceptance-ledger.js +14 -3
  183. package/dist/core/acceptance-ledger.js.map +1 -1
  184. package/dist/core/agent-session-runtime.d.ts +11 -4
  185. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  186. package/dist/core/agent-session-runtime.js +13 -4
  187. package/dist/core/agent-session-runtime.js.map +1 -1
  188. package/dist/core/agent-session-services.d.ts.map +1 -1
  189. package/dist/core/agent-session-services.js +6 -0
  190. package/dist/core/agent-session-services.js.map +1 -1
  191. package/dist/core/agent-session.d.ts +19 -1
  192. package/dist/core/agent-session.d.ts.map +1 -1
  193. package/dist/core/agent-session.js +131 -36
  194. package/dist/core/agent-session.js.map +1 -1
  195. package/dist/core/auth-storage.d.ts.map +1 -1
  196. package/dist/core/auth-storage.js +7 -1
  197. package/dist/core/auth-storage.js.map +1 -1
  198. package/dist/core/bash-executor.d.ts +3 -1
  199. package/dist/core/bash-executor.d.ts.map +1 -1
  200. package/dist/core/bash-executor.js +18 -8
  201. package/dist/core/bash-executor.js.map +1 -1
  202. package/dist/core/compaction/branch-summarization.d.ts +2 -2
  203. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  204. package/dist/core/compaction/branch-summarization.js +9 -15
  205. package/dist/core/compaction/branch-summarization.js.map +1 -1
  206. package/dist/core/compaction/compaction.d.ts.map +1 -1
  207. package/dist/core/compaction/compaction.js +3 -0
  208. package/dist/core/compaction/compaction.js.map +1 -1
  209. package/dist/core/export-html/index.d.ts.map +1 -1
  210. package/dist/core/export-html/index.js +12 -10
  211. package/dist/core/export-html/index.js.map +1 -1
  212. package/dist/core/export-html/template.js +23 -1
  213. package/dist/core/extensions/runner.d.ts.map +1 -1
  214. package/dist/core/extensions/runner.js +13 -2
  215. package/dist/core/extensions/runner.js.map +1 -1
  216. package/dist/core/extensions/types.d.ts +9 -1
  217. package/dist/core/extensions/types.d.ts.map +1 -1
  218. package/dist/core/extensions/types.js.map +1 -1
  219. package/dist/core/footer-data-provider.d.ts.map +1 -1
  220. package/dist/core/footer-data-provider.js +2 -4
  221. package/dist/core/footer-data-provider.js.map +1 -1
  222. package/dist/core/http-dispatcher.d.ts +5 -2
  223. package/dist/core/http-dispatcher.d.ts.map +1 -1
  224. package/dist/core/http-dispatcher.js +6 -3
  225. package/dist/core/http-dispatcher.js.map +1 -1
  226. package/dist/core/keybindings.d.ts +20 -0
  227. package/dist/core/keybindings.d.ts.map +1 -1
  228. package/dist/core/keybindings.js +4 -1
  229. package/dist/core/keybindings.js.map +1 -1
  230. package/dist/core/mcp-servers.d.ts +29 -0
  231. package/dist/core/mcp-servers.d.ts.map +1 -1
  232. package/dist/core/mcp-servers.js +63 -17
  233. package/dist/core/mcp-servers.js.map +1 -1
  234. package/dist/core/messages.d.ts +4 -0
  235. package/dist/core/messages.d.ts.map +1 -1
  236. package/dist/core/messages.js +10 -2
  237. package/dist/core/messages.js.map +1 -1
  238. package/dist/core/model-config.d.ts +36 -0
  239. package/dist/core/model-config.d.ts.map +1 -1
  240. package/dist/core/model-resolver.js +1 -1
  241. package/dist/core/model-resolver.js.map +1 -1
  242. package/dist/core/model-runtime.d.ts.map +1 -1
  243. package/dist/core/model-runtime.js +6 -2
  244. package/dist/core/model-runtime.js.map +1 -1
  245. package/dist/core/nested-tool-calls.d.ts +6 -5
  246. package/dist/core/nested-tool-calls.d.ts.map +1 -1
  247. package/dist/core/nested-tool-calls.js +1 -3
  248. package/dist/core/nested-tool-calls.js.map +1 -1
  249. package/dist/core/os-secret-store.js +1 -1
  250. package/dist/core/os-secret-store.js.map +1 -1
  251. package/dist/core/package-manager.d.ts +3 -1
  252. package/dist/core/package-manager.d.ts.map +1 -1
  253. package/dist/core/package-manager.js +25 -4
  254. package/dist/core/package-manager.js.map +1 -1
  255. package/dist/core/pi-ai-schemas.d.ts +4 -0
  256. package/dist/core/pi-ai-schemas.d.ts.map +1 -1
  257. package/dist/core/project-trust.d.ts.map +1 -1
  258. package/dist/core/project-trust.js +1 -1
  259. package/dist/core/project-trust.js.map +1 -1
  260. package/dist/core/provider-composer.d.ts +1 -0
  261. package/dist/core/provider-composer.d.ts.map +1 -1
  262. package/dist/core/provider-composer.js +1 -0
  263. package/dist/core/provider-composer.js.map +1 -1
  264. package/dist/core/resolve-config-value.d.ts +4 -0
  265. package/dist/core/resolve-config-value.d.ts.map +1 -1
  266. package/dist/core/resolve-config-value.js +14 -3
  267. package/dist/core/resolve-config-value.js.map +1 -1
  268. package/dist/core/resource-loader.d.ts.map +1 -1
  269. package/dist/core/resource-loader.js +40 -2
  270. package/dist/core/resource-loader.js.map +1 -1
  271. package/dist/core/runtime-credentials.d.ts.map +1 -1
  272. package/dist/core/runtime-credentials.js +11 -7
  273. package/dist/core/runtime-credentials.js.map +1 -1
  274. package/dist/core/sdk.d.ts.map +1 -1
  275. package/dist/core/sdk.js +8 -4
  276. package/dist/core/sdk.js.map +1 -1
  277. package/dist/core/session-manager.d.ts +22 -1
  278. package/dist/core/session-manager.d.ts.map +1 -1
  279. package/dist/core/session-manager.js +227 -37
  280. package/dist/core/session-manager.js.map +1 -1
  281. package/dist/core/settings-defaults.d.ts +10 -1
  282. package/dist/core/settings-defaults.d.ts.map +1 -1
  283. package/dist/core/settings-defaults.js +7 -1
  284. package/dist/core/settings-defaults.js.map +1 -1
  285. package/dist/core/settings-manager.d.ts +14 -4
  286. package/dist/core/settings-manager.d.ts.map +1 -1
  287. package/dist/core/settings-manager.js +48 -15
  288. package/dist/core/settings-manager.js.map +1 -1
  289. package/dist/core/settings-schema.d.ts +20 -2
  290. package/dist/core/settings-schema.d.ts.map +1 -1
  291. package/dist/core/settings-schema.js +27 -4
  292. package/dist/core/settings-schema.js.map +1 -1
  293. package/dist/core/slash-commands.d.ts.map +1 -1
  294. package/dist/core/slash-commands.js +2 -0
  295. package/dist/core/slash-commands.js.map +1 -1
  296. package/dist/core/tools/bash-jobs.js +2 -2
  297. package/dist/core/tools/bash-jobs.js.map +1 -1
  298. package/dist/core/tools/bash.d.ts +3 -0
  299. package/dist/core/tools/bash.d.ts.map +1 -1
  300. package/dist/core/tools/bash.js +78 -46
  301. package/dist/core/tools/bash.js.map +1 -1
  302. package/dist/core/tools/edit-diff.d.ts +7 -1
  303. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  304. package/dist/core/tools/edit-diff.js +139 -75
  305. package/dist/core/tools/edit-diff.js.map +1 -1
  306. package/dist/core/tools/edit.d.ts.map +1 -1
  307. package/dist/core/tools/edit.js +4 -1
  308. package/dist/core/tools/edit.js.map +1 -1
  309. package/dist/core/tools/output-accumulator.d.ts +21 -6
  310. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  311. package/dist/core/tools/output-accumulator.js +90 -76
  312. package/dist/core/tools/output-accumulator.js.map +1 -1
  313. package/dist/core/tools/render-utils.d.ts +7 -2
  314. package/dist/core/tools/render-utils.d.ts.map +1 -1
  315. package/dist/core/tools/render-utils.js +14 -1
  316. package/dist/core/tools/render-utils.js.map +1 -1
  317. package/dist/core/tools/renderers/bash.d.ts.map +1 -1
  318. package/dist/core/tools/renderers/bash.js +9 -3
  319. package/dist/core/tools/renderers/bash.js.map +1 -1
  320. package/dist/core/tools/truncate.d.ts +1 -1
  321. package/dist/core/tools/truncate.d.ts.map +1 -1
  322. package/dist/core/tools/truncate.js +16 -7
  323. package/dist/core/tools/truncate.js.map +1 -1
  324. package/dist/core/tools/write.d.ts.map +1 -1
  325. package/dist/core/tools/write.js +2 -0
  326. package/dist/core/tools/write.js.map +1 -1
  327. package/dist/core/trust-manager.d.ts +2 -0
  328. package/dist/core/trust-manager.d.ts.map +1 -1
  329. package/dist/core/trust-manager.js +5 -4
  330. package/dist/core/trust-manager.js.map +1 -1
  331. package/dist/core/usage-totals.d.ts.map +1 -1
  332. package/dist/core/usage-totals.js +3 -0
  333. package/dist/core/usage-totals.js.map +1 -1
  334. package/dist/extensions/codemode/execute.d.ts.map +1 -1
  335. package/dist/extensions/codemode/execute.js +64 -20
  336. package/dist/extensions/codemode/execute.js.map +1 -1
  337. package/dist/extensions/codemode/renderer.d.ts.map +1 -1
  338. package/dist/extensions/codemode/renderer.js +8 -3
  339. package/dist/extensions/codemode/renderer.js.map +1 -1
  340. package/dist/extensions/codemode/tool.d.ts +5 -0
  341. package/dist/extensions/codemode/tool.d.ts.map +1 -1
  342. package/dist/extensions/codemode/tool.js.map +1 -1
  343. package/dist/extensions/llama/client.d.ts.map +1 -1
  344. package/dist/extensions/llama/client.js +3 -13
  345. package/dist/extensions/llama/client.js.map +1 -1
  346. package/dist/extensions/llama/ui.d.ts.map +1 -1
  347. package/dist/extensions/llama/ui.js +2 -1
  348. package/dist/extensions/llama/ui.js.map +1 -1
  349. package/dist/extensions/mcp/cli.d.ts +7 -0
  350. package/dist/extensions/mcp/cli.d.ts.map +1 -1
  351. package/dist/extensions/mcp/cli.js +35 -8
  352. package/dist/extensions/mcp/cli.js.map +1 -1
  353. package/dist/extensions/mcp/config.d.ts +33 -0
  354. package/dist/extensions/mcp/config.d.ts.map +1 -1
  355. package/dist/extensions/mcp/config.js +11 -2
  356. package/dist/extensions/mcp/config.js.map +1 -1
  357. package/dist/extensions/mcp/index.d.ts +8 -0
  358. package/dist/extensions/mcp/index.d.ts.map +1 -1
  359. package/dist/extensions/mcp/index.js +16 -0
  360. package/dist/extensions/mcp/index.js.map +1 -1
  361. package/dist/extensions/mcp/resources.d.ts +1 -1
  362. package/dist/extensions/mcp/resources.d.ts.map +1 -1
  363. package/dist/extensions/mcp/resources.js +4 -3
  364. package/dist/extensions/mcp/resources.js.map +1 -1
  365. package/dist/extensions/mcp/runtime.d.ts +1 -1
  366. package/dist/extensions/mcp/runtime.d.ts.map +1 -1
  367. package/dist/extensions/mcp/runtime.js +15 -14
  368. package/dist/extensions/mcp/runtime.js.map +1 -1
  369. package/dist/extensions/mcp/tools.d.ts +1 -24
  370. package/dist/extensions/mcp/tools.d.ts.map +1 -1
  371. package/dist/extensions/mcp/tools.js +10 -163
  372. package/dist/extensions/mcp/tools.js.map +1 -1
  373. package/dist/humain/ask-user-question/index.d.ts +4 -0
  374. package/dist/humain/ask-user-question/index.d.ts.map +1 -0
  375. package/dist/humain/ask-user-question/index.js +18 -0
  376. package/dist/humain/ask-user-question/index.js.map +1 -0
  377. package/dist/humain/ask-user-question/vendor/ask/answer-channel.d.ts +38 -0
  378. package/dist/humain/ask-user-question/vendor/ask/answer-channel.d.ts.map +1 -0
  379. package/dist/humain/ask-user-question/vendor/ask/answer-channel.js +97 -0
  380. package/dist/humain/ask-user-question/vendor/ask/answer-channel.js.map +1 -0
  381. package/dist/humain/ask-user-question/vendor/ask/ask-user-question.d.ts +41 -0
  382. package/dist/humain/ask-user-question/vendor/ask/ask-user-question.d.ts.map +1 -0
  383. package/dist/humain/ask-user-question/vendor/ask/ask-user-question.js +441 -0
  384. package/dist/humain/ask-user-question/vendor/ask/ask-user-question.js.map +1 -0
  385. package/dist/humain/ask-user-question/vendor/ask/config.d.ts +39 -0
  386. package/dist/humain/ask-user-question/vendor/ask/config.d.ts.map +1 -0
  387. package/dist/humain/ask-user-question/vendor/ask/config.js +95 -0
  388. package/dist/humain/ask-user-question/vendor/ask/config.js.map +1 -0
  389. package/dist/humain/ask-user-question/vendor/ask/events.d.ts +132 -0
  390. package/dist/humain/ask-user-question/vendor/ask/events.d.ts.map +1 -0
  391. package/dist/humain/ask-user-question/vendor/ask/events.js +50 -0
  392. package/dist/humain/ask-user-question/vendor/ask/events.js.map +1 -0
  393. package/dist/humain/ask-user-question/vendor/ask/index.d.ts +5 -0
  394. package/dist/humain/ask-user-question/vendor/ask/index.d.ts.map +1 -0
  395. package/dist/humain/ask-user-question/vendor/ask/index.js +15 -0
  396. package/dist/humain/ask-user-question/vendor/ask/index.js.map +1 -0
  397. package/dist/humain/ask-user-question/vendor/ask/presentation.d.ts +81 -0
  398. package/dist/humain/ask-user-question/vendor/ask/presentation.d.ts.map +1 -0
  399. package/dist/humain/ask-user-question/vendor/ask/presentation.js +105 -0
  400. package/dist/humain/ask-user-question/vendor/ask/presentation.js.map +1 -0
  401. package/dist/humain/ask-user-question/vendor/ask/reconcile.d.ts +28 -0
  402. package/dist/humain/ask-user-question/vendor/ask/reconcile.d.ts.map +1 -0
  403. package/dist/humain/ask-user-question/vendor/ask/reconcile.js +45 -0
  404. package/dist/humain/ask-user-question/vendor/ask/reconcile.js.map +1 -0
  405. package/dist/humain/ask-user-question/vendor/ask/rpc-fallback.d.ts +41 -0
  406. package/dist/humain/ask-user-question/vendor/ask/rpc-fallback.d.ts.map +1 -0
  407. package/dist/humain/ask-user-question/vendor/ask/rpc-fallback.js +166 -0
  408. package/dist/humain/ask-user-question/vendor/ask/rpc-fallback.js.map +1 -0
  409. package/dist/humain/ask-user-question/vendor/ask/state/build-questionnaire.d.ts +46 -0
  410. package/dist/humain/ask-user-question/vendor/ask/state/build-questionnaire.d.ts.map +1 -0
  411. package/dist/humain/ask-user-question/vendor/ask/state/build-questionnaire.js +247 -0
  412. package/dist/humain/ask-user-question/vendor/ask/state/build-questionnaire.js.map +1 -0
  413. package/dist/humain/ask-user-question/vendor/ask/state/external-editor.d.ts +11 -0
  414. package/dist/humain/ask-user-question/vendor/ask/state/external-editor.d.ts.map +1 -0
  415. package/dist/humain/ask-user-question/vendor/ask/state/external-editor.js +56 -0
  416. package/dist/humain/ask-user-question/vendor/ask/state/external-editor.js.map +1 -0
  417. package/dist/humain/ask-user-question/vendor/ask/state/i18n-bridge.d.ts +6 -0
  418. package/dist/humain/ask-user-question/vendor/ask/state/i18n-bridge.d.ts.map +1 -0
  419. package/dist/humain/ask-user-question/vendor/ask/state/i18n-bridge.js +10 -0
  420. package/dist/humain/ask-user-question/vendor/ask/state/i18n-bridge.js.map +1 -0
  421. package/dist/humain/ask-user-question/vendor/ask/state/key-router.d.ts +57 -0
  422. package/dist/humain/ask-user-question/vendor/ask/state/key-router.d.ts.map +1 -0
  423. package/dist/humain/ask-user-question/vendor/ask/state/key-router.js +357 -0
  424. package/dist/humain/ask-user-question/vendor/ask/state/key-router.js.map +1 -0
  425. package/dist/humain/ask-user-question/vendor/ask/state/questionnaire-session.d.ts +112 -0
  426. package/dist/humain/ask-user-question/vendor/ask/state/questionnaire-session.d.ts.map +1 -0
  427. package/dist/humain/ask-user-question/vendor/ask/state/questionnaire-session.js +240 -0
  428. package/dist/humain/ask-user-question/vendor/ask/state/questionnaire-session.js.map +1 -0
  429. package/dist/humain/ask-user-question/vendor/ask/state/row-intent.d.ts +87 -0
  430. package/dist/humain/ask-user-question/vendor/ask/state/row-intent.d.ts.map +1 -0
  431. package/dist/humain/ask-user-question/vendor/ask/state/row-intent.js +79 -0
  432. package/dist/humain/ask-user-question/vendor/ask/state/row-intent.js.map +1 -0
  433. package/dist/humain/ask-user-question/vendor/ask/state/selectors/contract.d.ts +22 -0
  434. package/dist/humain/ask-user-question/vendor/ask/state/selectors/contract.d.ts.map +1 -0
  435. package/dist/humain/ask-user-question/vendor/ask/state/selectors/contract.js +2 -0
  436. package/dist/humain/ask-user-question/vendor/ask/state/selectors/contract.js.map +1 -0
  437. package/dist/humain/ask-user-question/vendor/ask/state/selectors/derivations.d.ts +27 -0
  438. package/dist/humain/ask-user-question/vendor/ask/state/selectors/derivations.d.ts.map +1 -0
  439. package/dist/humain/ask-user-question/vendor/ask/state/selectors/derivations.js +48 -0
  440. package/dist/humain/ask-user-question/vendor/ask/state/selectors/derivations.js.map +1 -0
  441. package/dist/humain/ask-user-question/vendor/ask/state/selectors/focus.d.ts +13 -0
  442. package/dist/humain/ask-user-question/vendor/ask/state/selectors/focus.d.ts.map +1 -0
  443. package/dist/humain/ask-user-question/vendor/ask/state/selectors/focus.js +15 -0
  444. package/dist/humain/ask-user-question/vendor/ask/state/selectors/focus.js.map +1 -0
  445. package/dist/humain/ask-user-question/vendor/ask/state/selectors/projections.d.ts +14 -0
  446. package/dist/humain/ask-user-question/vendor/ask/state/selectors/projections.d.ts.map +1 -0
  447. package/dist/humain/ask-user-question/vendor/ask/state/selectors/projections.js +96 -0
  448. package/dist/humain/ask-user-question/vendor/ask/state/selectors/projections.js.map +1 -0
  449. package/dist/humain/ask-user-question/vendor/ask/state/state-reducer.d.ts +58 -0
  450. package/dist/humain/ask-user-question/vendor/ask/state/state-reducer.d.ts.map +1 -0
  451. package/dist/humain/ask-user-question/vendor/ask/state/state-reducer.js +310 -0
  452. package/dist/humain/ask-user-question/vendor/ask/state/state-reducer.js.map +1 -0
  453. package/dist/humain/ask-user-question/vendor/ask/state/state.d.ts +68 -0
  454. package/dist/humain/ask-user-question/vendor/ask/state/state.d.ts.map +1 -0
  455. package/dist/humain/ask-user-question/vendor/ask/state/state.js +2 -0
  456. package/dist/humain/ask-user-question/vendor/ask/state/state.js.map +1 -0
  457. package/dist/humain/ask-user-question/vendor/ask/tool/external-answer.d.ts +24 -0
  458. package/dist/humain/ask-user-question/vendor/ask/tool/external-answer.d.ts.map +1 -0
  459. package/dist/humain/ask-user-question/vendor/ask/tool/external-answer.js +114 -0
  460. package/dist/humain/ask-user-question/vendor/ask/tool/external-answer.js.map +1 -0
  461. package/dist/humain/ask-user-question/vendor/ask/tool/format-answer.d.ts +18 -0
  462. package/dist/humain/ask-user-question/vendor/ask/tool/format-answer.d.ts.map +1 -0
  463. package/dist/humain/ask-user-question/vendor/ask/tool/format-answer.js +29 -0
  464. package/dist/humain/ask-user-question/vendor/ask/tool/format-answer.js.map +1 -0
  465. package/dist/humain/ask-user-question/vendor/ask/tool/normalize-params.d.ts +41 -0
  466. package/dist/humain/ask-user-question/vendor/ask/tool/normalize-params.d.ts.map +1 -0
  467. package/dist/humain/ask-user-question/vendor/ask/tool/normalize-params.js +99 -0
  468. package/dist/humain/ask-user-question/vendor/ask/tool/normalize-params.js.map +1 -0
  469. package/dist/humain/ask-user-question/vendor/ask/tool/response-envelope.d.ts +37 -0
  470. package/dist/humain/ask-user-question/vendor/ask/tool/response-envelope.d.ts.map +1 -0
  471. package/dist/humain/ask-user-question/vendor/ask/tool/response-envelope.js +70 -0
  472. package/dist/humain/ask-user-question/vendor/ask/tool/response-envelope.js.map +1 -0
  473. package/dist/humain/ask-user-question/vendor/ask/tool/types.d.ts +129 -0
  474. package/dist/humain/ask-user-question/vendor/ask/tool/types.d.ts.map +1 -0
  475. package/dist/humain/ask-user-question/vendor/ask/tool/types.js +76 -0
  476. package/dist/humain/ask-user-question/vendor/ask/tool/types.js.map +1 -0
  477. package/dist/humain/ask-user-question/vendor/ask/tool/validate-questionnaire.d.ts +21 -0
  478. package/dist/humain/ask-user-question/vendor/ask/tool/validate-questionnaire.d.ts.map +1 -0
  479. package/dist/humain/ask-user-question/vendor/ask/tool/validate-questionnaire.js +49 -0
  480. package/dist/humain/ask-user-question/vendor/ask/tool/validate-questionnaire.js.map +1 -0
  481. package/dist/humain/ask-user-question/vendor/ask/view/component-binding.d.ts +23 -0
  482. package/dist/humain/ask-user-question/vendor/ask/view/component-binding.d.ts.map +1 -0
  483. package/dist/humain/ask-user-question/vendor/ask/view/component-binding.js +16 -0
  484. package/dist/humain/ask-user-question/vendor/ask/view/component-binding.js.map +1 -0
  485. package/dist/humain/ask-user-question/vendor/ask/view/components/inline-input.d.ts +21 -0
  486. package/dist/humain/ask-user-question/vendor/ask/view/components/inline-input.d.ts.map +1 -0
  487. package/dist/humain/ask-user-question/vendor/ask/view/components/inline-input.js +49 -0
  488. package/dist/humain/ask-user-question/vendor/ask/view/components/inline-input.js.map +1 -0
  489. package/dist/humain/ask-user-question/vendor/ask/view/components/multi-select-view.d.ts +43 -0
  490. package/dist/humain/ask-user-question/vendor/ask/view/components/multi-select-view.d.ts.map +1 -0
  491. package/dist/humain/ask-user-question/vendor/ask/view/components/multi-select-view.js +130 -0
  492. package/dist/humain/ask-user-question/vendor/ask/view/components/multi-select-view.js.map +1 -0
  493. package/dist/humain/ask-user-question/vendor/ask/view/components/option-list-view.d.ts +45 -0
  494. package/dist/humain/ask-user-question/vendor/ask/view/components/option-list-view.d.ts.map +1 -0
  495. package/dist/humain/ask-user-question/vendor/ask/view/components/option-list-view.js +39 -0
  496. package/dist/humain/ask-user-question/vendor/ask/view/components/option-list-view.js.map +1 -0
  497. package/dist/humain/ask-user-question/vendor/ask/view/components/preview/markdown-content-cache.d.ts +36 -0
  498. package/dist/humain/ask-user-question/vendor/ask/view/components/preview/markdown-content-cache.d.ts.map +1 -0
  499. package/dist/humain/ask-user-question/vendor/ask/view/components/preview/markdown-content-cache.js +72 -0
  500. package/dist/humain/ask-user-question/vendor/ask/view/components/preview/markdown-content-cache.js.map +1 -0
  501. package/dist/humain/ask-user-question/vendor/ask/view/components/preview/preview-block-renderer.d.ts +61 -0
  502. package/dist/humain/ask-user-question/vendor/ask/view/components/preview/preview-block-renderer.d.ts.map +1 -0
  503. package/dist/humain/ask-user-question/vendor/ask/view/components/preview/preview-block-renderer.js +108 -0
  504. package/dist/humain/ask-user-question/vendor/ask/view/components/preview/preview-block-renderer.js.map +1 -0
  505. package/dist/humain/ask-user-question/vendor/ask/view/components/preview/preview-box-renderer.d.ts +39 -0
  506. package/dist/humain/ask-user-question/vendor/ask/view/components/preview/preview-box-renderer.d.ts.map +1 -0
  507. package/dist/humain/ask-user-question/vendor/ask/view/components/preview/preview-box-renderer.js +76 -0
  508. package/dist/humain/ask-user-question/vendor/ask/view/components/preview/preview-box-renderer.js.map +1 -0
  509. package/dist/humain/ask-user-question/vendor/ask/view/components/preview/preview-layout-decider.d.ts +123 -0
  510. package/dist/humain/ask-user-question/vendor/ask/view/components/preview/preview-layout-decider.d.ts.map +1 -0
  511. package/dist/humain/ask-user-question/vendor/ask/view/components/preview/preview-layout-decider.js +180 -0
  512. package/dist/humain/ask-user-question/vendor/ask/view/components/preview/preview-layout-decider.js.map +1 -0
  513. package/dist/humain/ask-user-question/vendor/ask/view/components/preview/preview-pane.d.ts +108 -0
  514. package/dist/humain/ask-user-question/vendor/ask/view/components/preview/preview-pane.d.ts.map +1 -0
  515. package/dist/humain/ask-user-question/vendor/ask/view/components/preview/preview-pane.js +235 -0
  516. package/dist/humain/ask-user-question/vendor/ask/view/components/preview/preview-pane.js.map +1 -0
  517. package/dist/humain/ask-user-question/vendor/ask/view/components/submit-picker.d.ts +37 -0
  518. package/dist/humain/ask-user-question/vendor/ask/view/components/submit-picker.d.ts.map +1 -0
  519. package/dist/humain/ask-user-question/vendor/ask/view/components/submit-picker.js +47 -0
  520. package/dist/humain/ask-user-question/vendor/ask/view/components/submit-picker.js.map +1 -0
  521. package/dist/humain/ask-user-question/vendor/ask/view/components/tab-bar.d.ts +31 -0
  522. package/dist/humain/ask-user-question/vendor/ask/view/components/tab-bar.d.ts.map +1 -0
  523. package/dist/humain/ask-user-question/vendor/ask/view/components/tab-bar.js +35 -0
  524. package/dist/humain/ask-user-question/vendor/ask/view/components/tab-bar.js.map +1 -0
  525. package/dist/humain/ask-user-question/vendor/ask/view/components/wrapping-select.d.ts +124 -0
  526. package/dist/humain/ask-user-question/vendor/ask/view/components/wrapping-select.d.ts.map +1 -0
  527. package/dist/humain/ask-user-question/vendor/ask/view/components/wrapping-select.js +205 -0
  528. package/dist/humain/ask-user-question/vendor/ask/view/components/wrapping-select.js.map +1 -0
  529. package/dist/humain/ask-user-question/vendor/ask/view/dialog-builder.d.ts +83 -0
  530. package/dist/humain/ask-user-question/vendor/ask/view/dialog-builder.d.ts.map +1 -0
  531. package/dist/humain/ask-user-question/vendor/ask/view/dialog-builder.js +186 -0
  532. package/dist/humain/ask-user-question/vendor/ask/view/dialog-builder.js.map +1 -0
  533. package/dist/humain/ask-user-question/vendor/ask/view/dialog-copy.d.ts +47 -0
  534. package/dist/humain/ask-user-question/vendor/ask/view/dialog-copy.d.ts.map +1 -0
  535. package/dist/humain/ask-user-question/vendor/ask/view/dialog-copy.js +48 -0
  536. package/dist/humain/ask-user-question/vendor/ask/view/dialog-copy.js.map +1 -0
  537. package/dist/humain/ask-user-question/vendor/ask/view/props-adapter.d.ts +58 -0
  538. package/dist/humain/ask-user-question/vendor/ask/view/props-adapter.d.ts.map +1 -0
  539. package/dist/humain/ask-user-question/vendor/ask/view/props-adapter.js +84 -0
  540. package/dist/humain/ask-user-question/vendor/ask/view/props-adapter.js.map +1 -0
  541. package/dist/humain/ask-user-question/vendor/ask/view/scroll-window.d.ts +20 -0
  542. package/dist/humain/ask-user-question/vendor/ask/view/scroll-window.d.ts.map +1 -0
  543. package/dist/humain/ask-user-question/vendor/ask/view/scroll-window.js +55 -0
  544. package/dist/humain/ask-user-question/vendor/ask/view/scroll-window.js.map +1 -0
  545. package/dist/humain/ask-user-question/vendor/ask/view/stateful-view.d.ts +23 -0
  546. package/dist/humain/ask-user-question/vendor/ask/view/stateful-view.d.ts.map +1 -0
  547. package/dist/humain/ask-user-question/vendor/ask/view/stateful-view.js +2 -0
  548. package/dist/humain/ask-user-question/vendor/ask/view/stateful-view.js.map +1 -0
  549. package/dist/humain/ask-user-question/vendor/ask/view/tab-components.d.ts +15 -0
  550. package/dist/humain/ask-user-question/vendor/ask/view/tab-components.d.ts.map +1 -0
  551. package/dist/humain/ask-user-question/vendor/ask/view/tab-components.js +2 -0
  552. package/dist/humain/ask-user-question/vendor/ask/view/tab-components.js.map +1 -0
  553. package/dist/humain/ask-user-question/vendor/ask/view/tab-content-strategy.d.ts +98 -0
  554. package/dist/humain/ask-user-question/vendor/ask/view/tab-content-strategy.d.ts.map +1 -0
  555. package/dist/humain/ask-user-question/vendor/ask/view/tab-content-strategy.js +248 -0
  556. package/dist/humain/ask-user-question/vendor/ask/view/tab-content-strategy.js.map +1 -0
  557. package/dist/humain/ask-user-question/vendor/ask/view/transcript.d.ts +23 -0
  558. package/dist/humain/ask-user-question/vendor/ask/view/transcript.d.ts.map +1 -0
  559. package/dist/humain/ask-user-question/vendor/ask/view/transcript.js +131 -0
  560. package/dist/humain/ask-user-question/vendor/ask/view/transcript.js.map +1 -0
  561. package/dist/humain/ask-user-question/vendor/config/config.d.ts +132 -0
  562. package/dist/humain/ask-user-question/vendor/config/config.d.ts.map +1 -0
  563. package/dist/humain/ask-user-question/vendor/config/config.js +286 -0
  564. package/dist/humain/ask-user-question/vendor/config/config.js.map +1 -0
  565. package/dist/humain/ask-user-question/vendor/config/index.d.ts +2 -0
  566. package/dist/humain/ask-user-question/vendor/config/index.d.ts.map +1 -0
  567. package/dist/humain/ask-user-question/vendor/config/index.js +2 -0
  568. package/dist/humain/ask-user-question/vendor/config/index.js.map +1 -0
  569. package/dist/humain/ask-user-question/vendor/i18n/i18n.d.ts +64 -0
  570. package/dist/humain/ask-user-question/vendor/i18n/i18n.d.ts.map +1 -0
  571. package/dist/humain/ask-user-question/vendor/i18n/i18n.js +185 -0
  572. package/dist/humain/ask-user-question/vendor/i18n/i18n.js.map +1 -0
  573. package/dist/humain/ask-user-question/vendor/i18n/loader.d.ts +44 -0
  574. package/dist/humain/ask-user-question/vendor/i18n/loader.d.ts.map +1 -0
  575. package/dist/humain/ask-user-question/vendor/i18n/loader.js +55 -0
  576. package/dist/humain/ask-user-question/vendor/i18n/loader.js.map +1 -0
  577. package/dist/humain/bedrock-provider/vendor/index.bundle.mjs +26 -16
  578. package/dist/humain/brand-logo.d.ts +2 -0
  579. package/dist/humain/brand-logo.d.ts.map +1 -1
  580. package/dist/humain/brand-logo.js +4 -0
  581. package/dist/humain/brand-logo.js.map +1 -1
  582. package/dist/humain/bundled-extension-names.d.ts +1 -0
  583. package/dist/humain/bundled-extension-names.d.ts.map +1 -1
  584. package/dist/humain/bundled-extension-names.js +1 -0
  585. package/dist/humain/bundled-extension-names.js.map +1 -1
  586. package/dist/humain/checklist/footer-progress.d.ts +7 -0
  587. package/dist/humain/checklist/footer-progress.d.ts.map +1 -0
  588. package/dist/humain/checklist/footer-progress.js +15 -0
  589. package/dist/humain/checklist/footer-progress.js.map +1 -0
  590. package/dist/humain/checklist/glyphs.d.ts +7 -0
  591. package/dist/humain/checklist/glyphs.d.ts.map +1 -0
  592. package/dist/humain/checklist/glyphs.js +8 -0
  593. package/dist/humain/checklist/glyphs.js.map +1 -0
  594. package/dist/humain/checklist/index.d.ts +6 -0
  595. package/dist/humain/checklist/index.d.ts.map +1 -0
  596. package/dist/humain/checklist/index.js +37 -0
  597. package/dist/humain/checklist/index.js.map +1 -0
  598. package/dist/humain/checklist/progress.d.ts +37 -0
  599. package/dist/humain/checklist/progress.d.ts.map +1 -0
  600. package/dist/humain/checklist/progress.js +234 -0
  601. package/dist/humain/checklist/progress.js.map +1 -0
  602. package/dist/humain/checklist/projector.d.ts +53 -0
  603. package/dist/humain/checklist/projector.d.ts.map +1 -0
  604. package/dist/humain/checklist/projector.js +198 -0
  605. package/dist/humain/checklist/projector.js.map +1 -0
  606. package/dist/humain/checklist/sidebar.d.ts +18 -0
  607. package/dist/humain/checklist/sidebar.d.ts.map +1 -0
  608. package/dist/humain/checklist/sidebar.js +38 -0
  609. package/dist/humain/checklist/sidebar.js.map +1 -0
  610. package/dist/humain/checklist/status-segment.d.ts +19 -0
  611. package/dist/humain/checklist/status-segment.d.ts.map +1 -0
  612. package/dist/humain/checklist/status-segment.js +59 -0
  613. package/dist/humain/checklist/status-segment.js.map +1 -0
  614. package/dist/humain/checklist/vendor/add-task-dialog.d.ts +54 -0
  615. package/dist/humain/checklist/vendor/add-task-dialog.d.ts.map +1 -0
  616. package/dist/humain/checklist/vendor/add-task-dialog.js +238 -0
  617. package/dist/humain/checklist/vendor/add-task-dialog.js.map +1 -0
  618. package/dist/humain/checklist/vendor/commands.d.ts +38 -0
  619. package/dist/humain/checklist/vendor/commands.d.ts.map +1 -0
  620. package/dist/humain/checklist/vendor/commands.js +193 -0
  621. package/dist/humain/checklist/vendor/commands.js.map +1 -0
  622. package/dist/humain/checklist/vendor/index.d.ts +3 -0
  623. package/dist/humain/checklist/vendor/index.d.ts.map +1 -0
  624. package/dist/humain/checklist/vendor/index.js +276 -0
  625. package/dist/humain/checklist/vendor/index.js.map +1 -0
  626. package/dist/humain/checklist/vendor/render.d.ts +97 -0
  627. package/dist/humain/checklist/vendor/render.d.ts.map +1 -0
  628. package/dist/humain/checklist/vendor/render.js +354 -0
  629. package/dist/humain/checklist/vendor/render.js.map +1 -0
  630. package/dist/humain/checklist/vendor/settings.d.ts +11 -0
  631. package/dist/humain/checklist/vendor/settings.d.ts.map +1 -0
  632. package/dist/humain/checklist/vendor/settings.js +8 -0
  633. package/dist/humain/checklist/vendor/settings.js.map +1 -0
  634. package/dist/humain/checklist/vendor/store.d.ts +120 -0
  635. package/dist/humain/checklist/vendor/store.d.ts.map +1 -0
  636. package/dist/humain/checklist/vendor/store.js +990 -0
  637. package/dist/humain/checklist/vendor/store.js.map +1 -0
  638. package/dist/humain/checklist/vendor/tools.d.ts +21 -0
  639. package/dist/humain/checklist/vendor/tools.d.ts.map +1 -0
  640. package/dist/humain/checklist/vendor/tools.js +162 -0
  641. package/dist/humain/checklist/vendor/tools.js.map +1 -0
  642. package/dist/humain/checklist/vendor/types.d.ts +188 -0
  643. package/dist/humain/checklist/vendor/types.d.ts.map +1 -0
  644. package/dist/humain/checklist/vendor/types.js +32 -0
  645. package/dist/humain/checklist/vendor/types.js.map +1 -0
  646. package/dist/humain/gateway/catalog.d.ts +1 -0
  647. package/dist/humain/gateway/catalog.d.ts.map +1 -1
  648. package/dist/humain/gateway/catalog.js +1 -0
  649. package/dist/humain/gateway/catalog.js.map +1 -1
  650. package/dist/humain/gateway/client.d.ts +1 -0
  651. package/dist/humain/gateway/client.d.ts.map +1 -1
  652. package/dist/humain/gateway/client.js +8 -1
  653. package/dist/humain/gateway/client.js.map +1 -1
  654. package/dist/humain/gateway/http.d.ts.map +1 -1
  655. package/dist/humain/gateway/http.js +11 -3
  656. package/dist/humain/gateway/http.js.map +1 -1
  657. package/dist/humain/gateway/images.d.ts +3 -0
  658. package/dist/humain/gateway/images.d.ts.map +1 -0
  659. package/dist/humain/gateway/images.js +73 -0
  660. package/dist/humain/gateway/images.js.map +1 -0
  661. package/dist/humain/gateway/provider.js +1 -1
  662. package/dist/humain/gateway/provider.js.map +1 -1
  663. package/dist/humain/hcode/account-store.d.ts.map +1 -1
  664. package/dist/humain/hcode/account-store.js +3 -1
  665. package/dist/humain/hcode/account-store.js.map +1 -1
  666. package/dist/humain/hcode/account.d.ts.map +1 -1
  667. package/dist/humain/hcode/account.js +23 -13
  668. package/dist/humain/hcode/account.js.map +1 -1
  669. package/dist/humain/hcode/images.d.ts.map +1 -1
  670. package/dist/humain/hcode/images.js +19 -13
  671. package/dist/humain/hcode/images.js.map +1 -1
  672. package/dist/humain/hcode/login-failure.d.ts +1 -0
  673. package/dist/humain/hcode/login-failure.d.ts.map +1 -1
  674. package/dist/humain/hcode/login-failure.js +1 -0
  675. package/dist/humain/hcode/login-failure.js.map +1 -1
  676. package/dist/humain/hcode/provider.d.ts.map +1 -1
  677. package/dist/humain/hcode/provider.js +2 -1
  678. package/dist/humain/hcode/provider.js.map +1 -1
  679. package/dist/humain/hcode/run-credential.d.ts +1 -0
  680. package/dist/humain/hcode/run-credential.d.ts.map +1 -1
  681. package/dist/humain/hcode/run-credential.js +12 -4
  682. package/dist/humain/hcode/run-credential.js.map +1 -1
  683. package/dist/humain/index.d.ts.map +1 -1
  684. package/dist/humain/index.js +4 -0
  685. package/dist/humain/index.js.map +1 -1
  686. package/dist/humain/node-provider.d.ts.map +1 -1
  687. package/dist/humain/node-provider.js +37 -8
  688. package/dist/humain/node-provider.js.map +1 -1
  689. package/dist/main.d.ts +1 -1
  690. package/dist/main.d.ts.map +1 -1
  691. package/dist/main.js +36 -26
  692. package/dist/main.js.map +1 -1
  693. package/dist/modes/interactive/chat-viewport.js +1 -1
  694. package/dist/modes/interactive/chat-viewport.js.map +1 -1
  695. package/dist/modes/interactive/components/bash-execution.d.ts +2 -1
  696. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  697. package/dist/modes/interactive/components/bash-execution.js +7 -4
  698. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  699. package/dist/modes/interactive/components/config-selector.js +1 -1
  700. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  701. package/dist/modes/interactive/components/custom-editor.d.ts +2 -0
  702. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  703. package/dist/modes/interactive/components/custom-editor.js +20 -1
  704. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  705. package/dist/modes/interactive/components/extension-editor.d.ts +1 -1
  706. package/dist/modes/interactive/components/extension-editor.js +2 -2
  707. package/dist/modes/interactive/components/extension-editor.js.map +1 -1
  708. package/dist/modes/interactive/components/footer.d.ts +7 -0
  709. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  710. package/dist/modes/interactive/components/footer.js +74 -1
  711. package/dist/modes/interactive/components/footer.js.map +1 -1
  712. package/dist/modes/interactive/components/mermaid.d.ts.map +1 -1
  713. package/dist/modes/interactive/components/mermaid.js +11 -4
  714. package/dist/modes/interactive/components/mermaid.js.map +1 -1
  715. package/dist/modes/interactive/components/model-selector.d.ts +2 -0
  716. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  717. package/dist/modes/interactive/components/model-selector.js +56 -8
  718. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  719. package/dist/modes/interactive/components/oauth-selector.d.ts +13 -1
  720. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  721. package/dist/modes/interactive/components/oauth-selector.js +10 -9
  722. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  723. package/dist/modes/interactive/components/session-selector.js +3 -3
  724. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  725. package/dist/modes/interactive/components/settings-selector.d.ts +4 -3
  726. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  727. package/dist/modes/interactive/components/settings-selector.js +83 -37
  728. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  729. package/dist/modes/interactive/components/settings-submenu.d.ts.map +1 -1
  730. package/dist/modes/interactive/components/settings-submenu.js +3 -3
  731. package/dist/modes/interactive/components/settings-submenu.js.map +1 -1
  732. package/dist/modes/interactive/components/status-indicator.d.ts +18 -7
  733. package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
  734. package/dist/modes/interactive/components/status-indicator.js +70 -24
  735. package/dist/modes/interactive/components/status-indicator.js.map +1 -1
  736. package/dist/modes/interactive/components/status-line.d.ts +16 -0
  737. package/dist/modes/interactive/components/status-line.d.ts.map +1 -0
  738. package/dist/modes/interactive/components/status-line.js +51 -0
  739. package/dist/modes/interactive/components/status-line.js.map +1 -0
  740. package/dist/modes/interactive/components/tool-execution.d.ts +5 -0
  741. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  742. package/dist/modes/interactive/components/tool-execution.js +8 -1
  743. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  744. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
  745. package/dist/modes/interactive/components/visual-truncate.js +11 -3
  746. package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
  747. package/dist/modes/interactive/external-editor.d.ts.map +1 -1
  748. package/dist/modes/interactive/external-editor.js +13 -3
  749. package/dist/modes/interactive/external-editor.js.map +1 -1
  750. package/dist/modes/interactive/interactive-mode.d.ts +17 -1
  751. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  752. package/dist/modes/interactive/interactive-mode.js +232 -108
  753. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  754. package/dist/modes/interactive/program-status-reporter.d.ts +2 -0
  755. package/dist/modes/interactive/program-status-reporter.d.ts.map +1 -1
  756. package/dist/modes/interactive/program-status-reporter.js +4 -0
  757. package/dist/modes/interactive/program-status-reporter.js.map +1 -1
  758. package/dist/modes/interactive/session-share.d.ts.map +1 -1
  759. package/dist/modes/interactive/session-share.js +9 -1
  760. package/dist/modes/interactive/session-share.js.map +1 -1
  761. package/dist/modes/print-mode.d.ts.map +1 -1
  762. package/dist/modes/print-mode.js +34 -7
  763. package/dist/modes/print-mode.js.map +1 -1
  764. package/dist/modes/rpc/jsonl.js +6 -5
  765. package/dist/modes/rpc/jsonl.js.map +1 -1
  766. package/dist/modes/rpc/rpc-client.d.ts +2 -0
  767. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  768. package/dist/modes/rpc/rpc-client.js +9 -2
  769. package/dist/modes/rpc/rpc-client.js.map +1 -1
  770. package/dist/modes/rpc/rpc-mode.d.ts +2 -1
  771. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  772. package/dist/modes/rpc/rpc-mode.js +113 -13
  773. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  774. package/dist/modes/rpc/rpc-types.d.ts +22 -1
  775. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  776. package/dist/modes/rpc/rpc-types.js.map +1 -1
  777. package/dist/modes/uncaught-errors.d.ts +20 -0
  778. package/dist/modes/uncaught-errors.d.ts.map +1 -0
  779. package/dist/modes/uncaught-errors.js +56 -0
  780. package/dist/modes/uncaught-errors.js.map +1 -0
  781. package/dist/package-manager-cli.d.ts.map +1 -1
  782. package/dist/package-manager-cli.js +10 -1
  783. package/dist/package-manager-cli.js.map +1 -1
  784. package/dist/utils/clipboard-image.js +1 -1
  785. package/dist/utils/clipboard-image.js.map +1 -1
  786. package/dist/utils/clipboard.js +2 -2
  787. package/dist/utils/clipboard.js.map +1 -1
  788. package/dist/utils/image-process.d.ts +5 -0
  789. package/dist/utils/image-process.d.ts.map +1 -1
  790. package/dist/utils/image-process.js +22 -4
  791. package/dist/utils/image-process.js.map +1 -1
  792. package/dist/utils/output-files.d.ts +44 -7
  793. package/dist/utils/output-files.d.ts.map +1 -1
  794. package/dist/utils/output-files.js +206 -12
  795. package/dist/utils/output-files.js.map +1 -1
  796. package/dist/utils/piped-stdin.d.ts +21 -0
  797. package/dist/utils/piped-stdin.d.ts.map +1 -0
  798. package/dist/utils/piped-stdin.js +60 -0
  799. package/dist/utils/piped-stdin.js.map +1 -0
  800. package/dist/utils/shell.d.ts +5 -2
  801. package/dist/utils/shell.d.ts.map +1 -1
  802. package/dist/utils/shell.js +77 -8
  803. package/dist/utils/shell.js.map +1 -1
  804. package/dist/utils/syntax-highlight.d.ts +33 -2
  805. package/dist/utils/syntax-highlight.d.ts.map +1 -1
  806. package/dist/utils/syntax-highlight.js +77 -10
  807. package/dist/utils/syntax-highlight.js.map +1 -1
  808. package/dist/utils/tools-manager.d.ts +1 -0
  809. package/dist/utils/tools-manager.d.ts.map +1 -1
  810. package/dist/utils/tools-manager.js +9 -8
  811. package/dist/utils/tools-manager.js.map +1 -1
  812. package/dist/utils/wsl.d.ts +8 -2
  813. package/dist/utils/wsl.d.ts.map +1 -1
  814. package/dist/utils/wsl.js +12 -3
  815. package/dist/utils/wsl.js.map +1 -1
  816. package/docs/cli.md +39 -3
  817. package/docs/codemode.md +7 -3
  818. package/docs/compaction.md +1 -1
  819. package/docs/development.md +6 -0
  820. package/docs/environment-variables.md +3 -2
  821. package/docs/extensions.md +19 -5
  822. package/docs/keybindings.md +2 -0
  823. package/docs/llama-cpp.md +2 -2
  824. package/docs/message-types.md +1 -0
  825. package/docs/models-configuration.md +14 -3
  826. package/docs/models.md +29 -7
  827. package/docs/providers.md +20 -2
  828. package/docs/rpc-commands.md +25 -2
  829. package/docs/rpc.md +20 -0
  830. package/docs/run-preflight.md +2 -2
  831. package/docs/session-format.md +9 -0
  832. package/docs/settings.md +35 -5
  833. package/docs/shell-aliases.md +1 -1
  834. package/docs/slash-commands.md +3 -1
  835. package/docs/terminal-setup.md +25 -0
  836. package/docs/windows.md +2 -1
  837. package/examples/extensions/custom-provider-anthropic/package-lock.json +4 -4
  838. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  839. package/examples/rpc-extension-ui.ts +8 -7
  840. package/npm-shrinkwrap.json +209 -180
  841. package/package.json +26 -20
  842. package/schemas/keybindings.schema.json +12 -0
  843. package/schemas/models.schema.json +20 -7
  844. package/schemas/settings.schema.json +43 -5
  845. package/src/coordination/UPSTREAM.md +27 -1
  846. package/src/coordination/upstream.json +3 -3
  847. package/src/humain/ask-user-question/UPSTREAM.md +31 -0
  848. package/src/humain/ask-user-question/upstream.json +258 -0
  849. package/src/humain/ask-user-question/vendor/ask/LICENSE +21 -0
  850. package/src/humain/ask-user-question/vendor/ask/locales/de.json +38 -0
  851. package/src/humain/ask-user-question/vendor/ask/locales/en.json +41 -0
  852. package/src/humain/ask-user-question/vendor/ask/locales/es.json +38 -0
  853. package/src/humain/ask-user-question/vendor/ask/locales/fr.json +38 -0
  854. package/src/humain/ask-user-question/vendor/ask/locales/pt-BR.json +38 -0
  855. package/src/humain/ask-user-question/vendor/ask/locales/pt.json +38 -0
  856. package/src/humain/ask-user-question/vendor/ask/locales/ru.json +38 -0
  857. package/src/humain/ask-user-question/vendor/ask/locales/uk.json +38 -0
  858. package/src/humain/ask-user-question/vendor/ask/locales/zh.json +40 -0
  859. package/src/humain/ask-user-question/vendor/config/LICENSE +21 -0
  860. package/src/humain/ask-user-question/vendor/i18n/LICENSE +21 -0
  861. package/src/humain/caveman/UPSTREAM.md +44 -11
  862. package/src/humain/caveman/upstream.json +3 -3
  863. package/src/humain/caveman/vendor/NOTICE +4 -0
  864. package/dist/bundle/chunks/anthropic-messages-XFCDMGD6.js +0 -77
  865. package/dist/bundle/chunks/azure-openai-responses-F4KQM3NK.js +0 -15
  866. package/dist/bundle/chunks/bowser-DXKSTXFQ.js +0 -89
  867. package/dist/bundle/chunks/chunk-3E37CJCE.js +0 -34
  868. package/dist/bundle/chunks/chunk-3HVHETMU.js +0 -18
  869. package/dist/bundle/chunks/chunk-6JTCRCNF.js +0 -74
  870. package/dist/bundle/chunks/chunk-B3ZLWVDA.js +0 -80
  871. package/dist/bundle/chunks/chunk-F77J5EQZ.js +0 -3
  872. package/dist/bundle/chunks/chunk-GPLWWO5Q.js +0 -121
  873. package/dist/bundle/chunks/chunk-GV5OVRKK.js +0 -4
  874. package/dist/bundle/chunks/chunk-JBSWWCT5.js +0 -12
  875. package/dist/bundle/chunks/chunk-JWOPWHVH.js +0 -51
  876. package/dist/bundle/chunks/chunk-KRBELWQH.js +0 -7
  877. package/dist/bundle/chunks/chunk-PFBAIRCY.js +0 -56
  878. package/dist/bundle/chunks/chunk-Q5RKNQ2T.js +0 -73
  879. package/dist/bundle/chunks/chunk-QFDZEUFU.js +0 -12
  880. package/dist/bundle/chunks/chunk-SKCJ25SX.js +0 -24
  881. package/dist/bundle/chunks/chunk-UZOIHLNU.js +0 -23
  882. package/dist/bundle/chunks/chunk-YSWDFV2L.js +0 -11
  883. package/dist/bundle/chunks/chunk-YZMQXAJM.js +0 -8
  884. package/dist/bundle/chunks/chunk-ZAHVC5V2.js +0 -3591
  885. package/dist/bundle/chunks/entry-2GZ3PTWQ.js +0 -2
  886. package/dist/bundle/chunks/google-generative-ai-WIASMWS3.js +0 -22
  887. package/dist/bundle/chunks/google-vertex-WSPHRZIZ.js +0 -25
  888. package/dist/bundle/chunks/interactive-mode-3322RQEH.js +0 -5
  889. package/dist/bundle/chunks/mistral-conversations-7JYDDRUT.js +0 -43
  890. package/dist/bundle/chunks/openai-codex-responses-7PAML4NF.js +0 -102
  891. package/dist/bundle/chunks/openai-completions-UJDAIGTK.js +0 -87
  892. package/dist/bundle/chunks/openai-responses-2WNCE6AY.js +0 -26
  893. package/dist/bundle/chunks/openrouter-images-V3UCCO6X.js +0 -8
  894. package/dist/bundle/chunks/pi-messages-TQ7LJUNQ.js +0 -28
  895. package/dist/bundle/chunks/runtime-H7LYNKCZ.js +0 -2
  896. package/dist/bundle/chunks/session-picker-EYKCMFQR.js +0 -4
  897. package/dist/bundle/chunks/startup-ui-7ODOR34R.js +0 -3
  898. package/dist/bundle/chunks/typesafe-system-one-YP7GGN4C.js +0 -3
  899. package/dist/bundle/chunks/virtual-modules-47MGUPYN.js +0 -28
@@ -1,5 +1,5 @@
1
+ // Derived in part from Pi-Bolt (MIT, Copyright (c) 2026 OpenSec (Pi-Bolt)), commit 9933992aea68a951b3b831c754a8e77525fcbae5; adapted for HUMAIN Code CLI.
1
2
  import { open } from "node:fs/promises";
2
- import { finished } from "node:stream/promises";
3
3
  import { createOutputFileStream } from "../../utils/output-files.js";
4
4
  import { OutputCleanup } from "./output-cleanup.js";
5
5
  import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, truncateTail } from "./truncate.js";
@@ -35,10 +35,9 @@ export class OutputAccumulator {
35
35
  currentLineBytes = 0;
36
36
  hasOpenLine = false;
37
37
  finished = false;
38
- tempFilePath;
39
- tempFileStream;
40
- tempFileDone;
41
- pendingDrain;
38
+ tempFile;
39
+ rawTail = "";
40
+ totalRawDecodedBytes = 0;
42
41
  constructor(options = {}) {
43
42
  this.cleanup = options.cleanup ? new OutputCleanup() : undefined;
44
43
  this.headAndTail = options.headAndTail ?? false;
@@ -54,15 +53,9 @@ export class OutputAccumulator {
54
53
  }
55
54
  this.totalRawBytes += data.length;
56
55
  const decoded = this.decoder.decode(data, { stream: true });
57
- this.appendDecodedText(this.cleanup ? this.cleanup.append(decoded) : decoded);
58
- if (this.cleanup || this.tempFileStream || this.shouldUseTempFile()) {
59
- this.ensureTempFile();
60
- const stream = this.tempFileStream;
61
- if (stream.errored)
62
- throw stream.errored;
63
- stream.write(data);
64
- if (stream.writableNeedDrain)
65
- return this.waitForDrain();
56
+ this.appendOutput(decoded);
57
+ if (this.cleanup || this.tempFile || this.shouldUseTempFile()) {
58
+ return this.ensureTempFile().write(data);
66
59
  }
67
60
  else if (data.length > 0) {
68
61
  this.rawChunks.push(data);
@@ -73,9 +66,10 @@ export class OutputAccumulator {
73
66
  return;
74
67
  }
75
68
  this.finished = true;
76
- const decoded = this.decoder.decode();
77
- this.appendDecodedText(this.cleanup ? this.cleanup.append(decoded) + this.cleanup.finish() : decoded);
78
- if (this.shouldUseTempFile()) {
69
+ this.appendOutput(this.decoder.decode());
70
+ if (this.cleanup)
71
+ this.appendDecodedText(this.cleanup.finish());
72
+ if (this.cleanup || this.shouldUseTempFile()) {
79
73
  this.ensureTempFile();
80
74
  }
81
75
  }
@@ -85,16 +79,16 @@ export class OutputAccumulator {
85
79
  const snapshot = this.contentSnapshot(options);
86
80
  if (!this.cleanup)
87
81
  return snapshot;
88
- const content = `${snapshot.content}\n\n[Output cleanup applied (terminal controls, CR overwrites, repeated/blank lines). Raw output: ${snapshot.fullOutputPath}. Use read with offset/limit, or grep the saved file.]`;
82
+ const recovery = snapshot.fullOutputFile?.kind === "saved"
83
+ ? `Raw output: ${snapshot.fullOutputFile.path}. Use read with offset/limit, or grep the saved file.`
84
+ : `Could not save the raw output: ${snapshot.fullOutputFile?.kind === "failed" ? snapshot.fullOutputFile.error : "no output file"}`;
85
+ const content = `${snapshot.content}\n\n[Output cleanup applied (terminal controls, CR overwrites, repeated/blank lines). ${recovery}]`;
89
86
  return { ...snapshot, content, truncation: { ...snapshot.truncation, content } };
90
87
  }
91
88
  contentSnapshot(options) {
92
89
  if (this.headAndTail)
93
90
  return this.headAndTailSnapshot();
94
- // Clipping drops the partial first line of the retained tail. When the tail is only the end of
95
- // one over-long line, that is everything, so show the end of that line instead.
96
- const snapshotText = this.getSnapshotText() || this.tailText;
97
- const tailTruncation = truncateTail(snapshotText, {
91
+ const tailTruncation = truncateTail(this.getRetainedText(), {
98
92
  maxLines: this.maxLines,
99
93
  maxBytes: this.maxBytes,
100
94
  });
@@ -114,29 +108,28 @@ export class OutputAccumulator {
114
108
  if (options.persistIfTruncated && truncation.truncated) {
115
109
  this.ensureTempFile();
116
110
  }
117
- return {
118
- content: truncation.content,
119
- truncation,
120
- fullOutputPath: this.tempFilePath,
121
- };
111
+ return { content: truncation.content, truncation, ...this.snapshotFile() };
122
112
  }
113
+ /** Flush and close the temp file. Never rejects: a failed file shows up as `failed` in later snapshots. */
123
114
  async closeTempFile() {
124
- if (!this.tempFileStream) {
125
- return;
126
- }
127
- this.tempFileStream.end();
128
- await this.tempFileDone;
115
+ await this.tempFile?.close();
129
116
  }
130
117
  /**
131
118
  * The complete output, for callers that can take more than the display snapshot. Call after
132
119
  * `finish()` and `closeTempFile()`. Output longer than `maxBytes` raw bytes keeps its first and
133
- * last `maxBytes / 2` bytes around an omission marker.
120
+ * last `maxBytes / 2` bytes around an omission marker. When the temp file could not be saved, only
121
+ * the retained tail is left: up to its last `maxBytes` bytes, behind the same marker when output is
122
+ * missing.
134
123
  */
135
124
  async readFullOutput(maxBytes) {
136
- if (!this.tempFilePath) {
125
+ const fullOutputFile = this.tempFile?.result;
126
+ if (!fullOutputFile) {
137
127
  return { content: new TextDecoder().decode(Buffer.concat(this.rawChunks)), truncated: false };
138
128
  }
139
- const file = await open(this.tempFilePath, "r");
129
+ if (fullOutputFile.kind === "failed") {
130
+ return this.readRetainedOutput(maxBytes);
131
+ }
132
+ const file = await open(fullOutputFile.path, "r");
140
133
  try {
141
134
  const size = (await file.stat()).size;
142
135
  if (size <= maxBytes) {
@@ -180,11 +173,15 @@ export class OutputAccumulator {
180
173
  outputBytes = byteLength(head) + tail.outputBytes;
181
174
  outputLines = (head ? head.split("\n").length - Number(head.endsWith("\n")) : 0) + tail.outputLines;
182
175
  const omitted = this.totalDecodedBytes - outputBytes;
183
- content = `${head}\n\n[... ${omitted} bytes omitted; showing head and tail (8 KiB / 2,000-line limit). Full output: ${this.tempFilePath}. Use read with offset/limit, or grep the saved file. Do not infer success from truncated output.]\n\n${tail.content}`;
176
+ const file = this.tempFile?.result;
177
+ const recovery = file?.kind === "failed"
178
+ ? `Could not save the full output: ${file.error}.`
179
+ : `Full output: ${file?.path}. Use read with offset/limit, or grep the saved file.`;
180
+ content = `${head}\n\n[... ${omitted} bytes omitted; showing head and tail (8 KiB / 2,000-line limit). ${recovery} Do not infer success from truncated output.]\n\n${tail.content}`;
184
181
  }
185
182
  return {
186
183
  content,
187
- fullOutputPath: this.tempFilePath,
184
+ ...this.snapshotFile(),
188
185
  truncation: {
189
186
  content,
190
187
  truncated,
@@ -203,6 +200,31 @@ export class OutputAccumulator {
203
200
  getLastLineBytes() {
204
201
  return this.currentLineBytes;
205
202
  }
203
+ snapshotFile() {
204
+ const file = this.tempFile?.result;
205
+ return { fullOutputFile: file, ...(file?.kind === "saved" ? { fullOutputPath: file.path } : {}) };
206
+ }
207
+ appendOutput(decoded) {
208
+ if (!this.cleanup) {
209
+ this.appendDecodedText(decoded);
210
+ return;
211
+ }
212
+ // Structured output is raw even when cleanup is on; retain a bounded raw recovery tail.
213
+ this.totalRawDecodedBytes += byteLength(decoded);
214
+ const raw = this.rawTail + decoded;
215
+ if (raw.length > this.maxRollingBytes) {
216
+ let cut = raw.length - this.maxRollingBytes;
217
+ const code = raw.charCodeAt(cut);
218
+ if (code >= 0xdc00 && code <= 0xdfff)
219
+ cut++;
220
+ // Detach the suffix so retaining it cannot keep an entire oversized read alive.
221
+ this.rawTail = Buffer.from(raw.slice(cut), "utf-8").toString("utf-8");
222
+ }
223
+ else {
224
+ this.rawTail = raw;
225
+ }
226
+ this.appendDecodedText(this.cleanup.append(decoded));
227
+ }
206
228
  appendDecodedText(text) {
207
229
  if (text.length === 0) {
208
230
  return;
@@ -267,6 +289,31 @@ export class OutputAccumulator {
267
289
  this.tailText = buffer.subarray(start).toString("utf-8");
268
290
  this.tailBytes = byteLength(this.tailText);
269
291
  }
292
+ /**
293
+ * The retained tail, for display and as the fallback of `readFullOutput()`. Clipping drops the partial
294
+ * first line of the tail. When the tail is only the end of one over-long line (plus blank lines),
295
+ * nothing is left, so it keeps the end of that line instead.
296
+ */
297
+ getRetainedText() {
298
+ const clippedText = this.getSnapshotText();
299
+ return clippedText.trim().length === 0 ? this.tailText : clippedText;
300
+ }
301
+ /** The retained tail within `maxBytes`, marked as truncated only when output is missing. */
302
+ readRetainedOutput(maxBytes) {
303
+ let bytes = Buffer.from(this.cleanup ? this.rawTail : this.getRetainedText(), "utf-8");
304
+ if (bytes.length > maxBytes) {
305
+ let start = bytes.length - maxBytes;
306
+ while (start < bytes.length && (bytes[start] & 0xc0) === 0x80)
307
+ start++;
308
+ bytes = bytes.subarray(start);
309
+ }
310
+ const tail = bytes.toString("utf-8");
311
+ const omitted = (this.cleanup ? this.totalRawDecodedBytes : this.totalDecodedBytes) - bytes.length;
312
+ if (omitted === 0) {
313
+ return { content: tail, truncated: false };
314
+ }
315
+ return { content: `[... ${omitted} bytes omitted ...]\n\n${tail}`, truncated: true };
316
+ }
270
317
  getSnapshotText() {
271
318
  if (this.tailStartsAtLineBoundary) {
272
319
  return this.tailText;
@@ -278,49 +325,16 @@ export class OutputAccumulator {
278
325
  return (this.totalRawBytes > this.maxBytes || this.totalDecodedBytes > this.maxBytes || this.totalLines > this.maxLines);
279
326
  }
280
327
  ensureTempFile() {
281
- if (this.tempFilePath) {
282
- return;
328
+ if (this.tempFile) {
329
+ return this.tempFile;
283
330
  }
284
- const { path, stream } = createOutputFileStream(this.tempFilePrefix, ".log");
285
- this.tempFilePath = path;
286
- this.tempFileStream = stream;
287
- // Own errors immediately, including failures before the caller starts closing the file.
288
- this.tempFileDone = finished(stream, { cleanup: true });
289
- void this.tempFileDone.catch(() => { });
331
+ const tempFile = createOutputFileStream(this.tempFilePrefix, ".log");
332
+ this.tempFile = tempFile;
290
333
  for (const chunk of this.rawChunks) {
291
- this.tempFileStream.write(chunk);
334
+ tempFile.write(chunk);
292
335
  }
293
336
  this.rawChunks = [];
294
- }
295
- waitForDrain() {
296
- if (this.pendingDrain)
297
- return this.pendingDrain;
298
- const stream = this.tempFileStream;
299
- this.pendingDrain = new Promise((resolve, reject) => {
300
- const cleanup = () => {
301
- stream.off("drain", onDrain);
302
- stream.off("error", onError);
303
- stream.off("close", onClose);
304
- stream.off("finish", onDrain);
305
- this.pendingDrain = undefined;
306
- };
307
- const onDrain = () => {
308
- cleanup();
309
- resolve();
310
- };
311
- const onError = (error) => {
312
- cleanup();
313
- reject(error);
314
- };
315
- const onClose = () => onError(stream.errored ?? new Error("Output file closed before draining"));
316
- stream.once("drain", onDrain);
317
- stream.once("error", onError);
318
- stream.once("close", onClose);
319
- stream.once("finish", onDrain);
320
- });
321
- // Custom operations may still send synchronously; closeTempFile also reports write failures.
322
- void this.pendingDrain.catch(() => { });
323
- return this.pendingDrain;
337
+ return tempFile;
324
338
  }
325
339
  }
326
340
  //# sourceMappingURL=output-accumulator.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"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C,CAAC;QACH,6FAA6F;QAC7F,KAAK,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QACvC,OAAO,IAAI,CAAC,YAAY,CAAC;IAC1B,CAAC;CACD","sourcesContent":["// Derived in part from Pi-Bolt (MIT, Copyright (c) 2026 OpenSec (Pi-Bolt)), commit 9933992aea68a951b3b831c754a8e77525fcbae5; adapted for HUMAIN Code CLI.\nimport type { WriteStream } from \"node:fs\";\nimport { open } from \"node:fs/promises\";\nimport { finished } from \"node:stream/promises\";\nimport { createOutputFileStream } from \"../../utils/output-files.ts\";\nimport { OutputCleanup } from \"./output-cleanup.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, type TruncationResult, truncateTail } from \"./truncate.ts\";\n\nexport interface OutputAccumulatorOptions {\n\tmaxLines?: number;\n\tmaxBytes?: number;\n\ttempFilePrefix?: string;\n\t/** Retain half the byte and line budgets from each end instead of only the tail. */\n\theadAndTail?: boolean;\n\t/** Clean decoded display text before truncation, preserving raw output in the spill file. */\n\tcleanup?: boolean;\n}\n\nexport interface OutputSnapshot {\n\tcontent: string;\n\ttruncation: TruncationResult;\n\tfullOutputPath?: string;\n}\n\nexport interface FullOutput {\n\tcontent: string;\n\t/** Whether `content` omits part of the output. */\n\ttruncated: boolean;\n}\n\nfunction byteLength(text: string): number {\n\treturn Buffer.byteLength(text, \"utf-8\");\n}\n\n/**\n * Incrementally tracks streaming output with bounded memory.\n *\n * Appends decode chunks with a streaming UTF-8 decoder, keeps only a decoded\n * tail for display snapshots, and opens a temp file when the full output needs\n * to be preserved. Opt-in cleanup additionally buffers the current line and final\n * identical-line run, so its memory follows the largest pending line.\n */\nexport class OutputAccumulator {\n\tprivate readonly maxLines: number;\n\tprivate readonly maxBytes: number;\n\tprivate readonly maxRollingBytes: number;\n\tprivate readonly tempFilePrefix: string;\n\tprivate readonly decoder = new TextDecoder();\n\tprivate readonly cleanup: OutputCleanup | undefined;\n\tprivate readonly headAndTail: boolean;\n\tprivate headText = \"\";\n\tprivate headComplete = false;\n\n\tprivate rawChunks: Buffer[] = [];\n\tprivate tailText = \"\";\n\tprivate tailBytes = 0;\n\tprivate tailStartsAtLineBoundary = true;\n\tprivate totalRawBytes = 0;\n\tprivate totalDecodedBytes = 0;\n\tprivate completedLines = 0;\n\tprivate totalLines = 0;\n\tprivate currentLineBytes = 0;\n\tprivate hasOpenLine = false;\n\tprivate finished = false;\n\n\tprivate tempFilePath: string | undefined;\n\tprivate tempFileStream: WriteStream | undefined;\n\tprivate tempFileDone: Promise<void> | undefined;\n\tprivate pendingDrain: Promise<void> | undefined;\n\n\tconstructor(options: OutputAccumulatorOptions = {}) {\n\t\tthis.cleanup = options.cleanup ? new OutputCleanup() : undefined;\n\t\tthis.headAndTail = options.headAndTail ?? false;\n\t\tthis.maxLines = options.maxLines ?? DEFAULT_MAX_LINES;\n\t\tthis.maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;\n\t\tthis.maxRollingBytes = Math.max(this.maxBytes * 2, 1);\n\t\tthis.tempFilePrefix = options.tempFilePrefix ?? \"pi-output\";\n\t}\n\n\t/** Accept a chunk; await the returned promise before sending another chunk. */\n\tappend(data: Buffer): void | Promise<void> {\n\t\tif (this.finished) {\n\t\t\tthrow new Error(\"Cannot append to a finished output accumulator\");\n\t\t}\n\n\t\tthis.totalRawBytes += data.length;\n\t\tconst decoded = this.decoder.decode(data, { stream: true });\n\t\tthis.appendDecodedText(this.cleanup ? this.cleanup.append(decoded) : decoded);\n\n\t\tif (this.cleanup || this.tempFileStream || this.shouldUseTempFile()) {\n\t\t\tthis.ensureTempFile();\n\t\t\tconst stream = this.tempFileStream!;\n\t\t\tif (stream.errored) throw stream.errored;\n\t\t\tstream.write(data);\n\t\t\tif (stream.writableNeedDrain) return this.waitForDrain();\n\t\t} else if (data.length > 0) {\n\t\t\tthis.rawChunks.push(data);\n\t\t}\n\t}\n\n\tfinish(): void {\n\t\tif (this.finished) {\n\t\t\treturn;\n\t\t}\n\t\tthis.finished = true;\n\t\tconst decoded = this.decoder.decode();\n\t\tthis.appendDecodedText(this.cleanup ? this.cleanup.append(decoded) + this.cleanup.finish() : decoded);\n\t\tif (this.shouldUseTempFile()) {\n\t\t\tthis.ensureTempFile();\n\t\t}\n\t}\n\n\tsnapshot(options: { persistIfTruncated?: boolean } = {}): OutputSnapshot {\n\t\tif (this.cleanup) this.ensureTempFile();\n\t\tconst snapshot = this.contentSnapshot(options);\n\t\tif (!this.cleanup) return snapshot;\n\t\tconst content = `${snapshot.content}\\n\\n[Output cleanup applied (terminal controls, CR overwrites, repeated/blank lines). Raw output: ${snapshot.fullOutputPath}. Use read with offset/limit, or grep the saved file.]`;\n\t\treturn { ...snapshot, content, truncation: { ...snapshot.truncation, content } };\n\t}\n\n\tprivate contentSnapshot(options: { persistIfTruncated?: boolean }): OutputSnapshot {\n\t\tif (this.headAndTail) return this.headAndTailSnapshot();\n\t\t// Clipping drops the partial first line of the retained tail. When the tail is only the end of\n\t\t// one over-long line, that is everything, so show the end of that line instead.\n\t\tconst snapshotText = this.getSnapshotText() || this.tailText;\n\t\tconst tailTruncation = truncateTail(snapshotText, {\n\t\t\tmaxLines: this.maxLines,\n\t\t\tmaxBytes: this.maxBytes,\n\t\t});\n\t\tconst truncated = this.totalLines > this.maxLines || this.totalDecodedBytes > this.maxBytes;\n\t\tconst truncatedBy = truncated\n\t\t\t? (tailTruncation.truncatedBy ?? (this.totalDecodedBytes > this.maxBytes ? \"bytes\" : \"lines\"))\n\t\t\t: null;\n\t\tconst truncation: TruncationResult = {\n\t\t\t...tailTruncation,\n\t\t\ttruncated,\n\t\t\ttruncatedBy,\n\t\t\ttotalLines: this.totalLines,\n\t\t\ttotalBytes: this.totalDecodedBytes,\n\t\t\tmaxLines: this.maxLines,\n\t\t\tmaxBytes: this.maxBytes,\n\t\t};\n\n\t\tif (options.persistIfTruncated && truncation.truncated) {\n\t\t\tthis.ensureTempFile();\n\t\t}\n\n\t\treturn {\n\t\t\tcontent: truncation.content,\n\t\t\ttruncation,\n\t\t\tfullOutputPath: this.tempFilePath,\n\t\t};\n\t}\n\n\tasync closeTempFile(): Promise<void> {\n\t\tif (!this.tempFileStream) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.tempFileStream.end();\n\t\tawait this.tempFileDone;\n\t}\n\n\t/**\n\t * The complete output, for callers that can take more than the display snapshot. Call after\n\t * `finish()` and `closeTempFile()`. Output longer than `maxBytes` raw bytes keeps its first and\n\t * last `maxBytes / 2` bytes around an omission marker.\n\t */\n\tasync readFullOutput(maxBytes: number): Promise<FullOutput> {\n\t\tif (!this.tempFilePath) {\n\t\t\treturn { content: new TextDecoder().decode(Buffer.concat(this.rawChunks)), truncated: false };\n\t\t}\n\t\tconst file = await open(this.tempFilePath, \"r\");\n\t\ttry {\n\t\t\tconst size = (await file.stat()).size;\n\t\t\tif (size <= maxBytes) {\n\t\t\t\treturn { content: new TextDecoder().decode(await file.readFile()), truncated: false };\n\t\t\t}\n\t\t\tconst headBytes = Math.floor(maxBytes / 2);\n\t\t\tconst tailBytes = maxBytes - headBytes;\n\t\t\tconst head = Buffer.alloc(headBytes);\n\t\t\tconst tail = Buffer.alloc(tailBytes);\n\t\t\tawait file.read(head, 0, headBytes, 0);\n\t\t\tawait file.read(tail, 0, tailBytes, size - tailBytes);\n\t\t\t// Cut at character boundaries: streaming decode holds back an incomplete trailing sequence,\n\t\t\t// and the tail skips leading continuation bytes.\n\t\t\tconst headText = new TextDecoder().decode(head, { stream: true });\n\t\t\tlet tailStart = 0;\n\t\t\twhile (tailStart < tail.length && (tail[tailStart] & 0xc0) === 0x80) tailStart++;\n\t\t\tconst tailText = new TextDecoder().decode(tail.subarray(tailStart));\n\t\t\tconst omitted = size - headBytes - tailBytes;\n\t\t\treturn { content: `${headText}\\n\\n[... ${omitted} bytes omitted ...]\\n\\n${tailText}`, truncated: true };\n\t\t} finally {\n\t\t\tawait file.close();\n\t\t}\n\t}\n\n\tprivate headAndTailSnapshot(): OutputSnapshot {\n\t\tconst truncated = this.totalLines > this.maxLines || this.totalDecodedBytes > this.maxBytes;\n\t\tlet content = this.tailText;\n\t\tlet outputBytes = this.totalDecodedBytes;\n\t\tlet outputLines = this.totalLines;\n\t\tif (truncated) {\n\t\t\tthis.ensureTempFile();\n\t\t\tconst head = this.headText\n\t\t\t\t.split(\"\\n\")\n\t\t\t\t.slice(0, Math.floor(this.maxLines / 2))\n\t\t\t\t.join(\"\\n\");\n\t\t\tconst tail = truncateTail(this.tailText, {\n\t\t\t\tmaxBytes: this.maxBytes - Math.floor(this.maxBytes / 2),\n\t\t\t\tmaxLines: this.maxLines - Math.floor(this.maxLines / 2),\n\t\t\t});\n\t\t\toutputBytes = byteLength(head) + tail.outputBytes;\n\t\t\toutputLines = (head ? head.split(\"\\n\").length - Number(head.endsWith(\"\\n\")) : 0) + tail.outputLines;\n\t\t\tconst omitted = this.totalDecodedBytes - outputBytes;\n\t\t\tcontent = `${head}\\n\\n[... ${omitted} bytes omitted; showing head and tail (8 KiB / 2,000-line limit). Full output: ${this.tempFilePath}. Use read with offset/limit, or grep the saved file. Do not infer success from truncated output.]\\n\\n${tail.content}`;\n\t\t}\n\t\treturn {\n\t\t\tcontent,\n\t\t\tfullOutputPath: this.tempFilePath,\n\t\t\ttruncation: {\n\t\t\t\tcontent,\n\t\t\t\ttruncated,\n\t\t\t\ttruncatedBy: truncated ? (this.totalDecodedBytes > this.maxBytes ? \"bytes\" : \"lines\") : null,\n\t\t\t\ttotalBytes: this.totalDecodedBytes,\n\t\t\t\ttotalLines: this.totalLines,\n\t\t\t\toutputBytes,\n\t\t\t\toutputLines,\n\t\t\t\tmaxBytes: this.maxBytes,\n\t\t\t\tmaxLines: this.maxLines,\n\t\t\t\tlastLinePartial: false,\n\t\t\t\tfirstLineExceedsLimit: false,\n\t\t\t},\n\t\t};\n\t}\n\n\tgetLastLineBytes(): number {\n\t\treturn this.currentLineBytes;\n\t}\n\n\tprivate appendDecodedText(text: string): void {\n\t\tif (text.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst bytes = byteLength(text);\n\t\tif (this.headAndTail && !this.headComplete) {\n\t\t\tconst limit = Math.floor(this.maxBytes / 2);\n\t\t\tconst head = Buffer.from(this.headText + text.slice(0, limit));\n\t\t\t// This text is already decoded; preserve a literal BOM while holding back incomplete UTF-8.\n\t\t\tthis.headText = new TextDecoder(\"utf-8\", { ignoreBOM: true }).decode(head.subarray(0, limit), {\n\t\t\t\tstream: true,\n\t\t\t});\n\t\t\tthis.headComplete = head.length >= limit;\n\t\t}\n\t\tthis.totalDecodedBytes += bytes;\n\t\tconst tailLength = this.tailText.length;\n\t\tif (this.tailBytes + bytes > this.maxRollingBytes * 2 && bytes === text.length && this.tailBytes === tailLength) {\n\t\t\t// Both ASCII: keep the same byte tail without joining and re-encoding oversized pipe reads.\n\t\t\tconst start = tailLength + bytes - this.maxRollingBytes;\n\t\t\tconst before =\n\t\t\t\tstart - 1 < tailLength ? this.tailText.charCodeAt(start - 1) : text.charCodeAt(start - 1 - tailLength);\n\t\t\tthis.tailStartsAtLineBoundary = before === 0x0a;\n\t\t\t// Copy only the retained suffix so a V8 sliced string cannot keep the oversized parent alive.\n\t\t\tthis.tailText = Buffer.from(\n\t\t\t\tstart >= tailLength ? text.slice(start - tailLength) : this.tailText.slice(start) + text,\n\t\t\t\t\"utf-8\",\n\t\t\t).toString(\"utf-8\");\n\t\t\tthis.tailBytes = this.maxRollingBytes;\n\t\t} else {\n\t\t\tthis.tailText += text;\n\t\t\tthis.tailBytes += bytes;\n\t\t\tif (this.tailBytes > this.maxRollingBytes * 2) {\n\t\t\t\tthis.trimTail();\n\t\t\t}\n\t\t}\n\n\t\tlet newlines = 0;\n\t\tlet lastNewline = -1;\n\t\tfor (let i = text.indexOf(\"\\n\"); i !== -1; i = text.indexOf(\"\\n\", i + 1)) {\n\t\t\tnewlines++;\n\t\t\tlastNewline = i;\n\t\t}\n\t\tif (newlines === 0) {\n\t\t\tthis.currentLineBytes += bytes;\n\t\t\tthis.hasOpenLine = true;\n\t\t} else {\n\t\t\tthis.completedLines += newlines;\n\t\t\tconst tail = text.slice(lastNewline + 1);\n\t\t\tthis.currentLineBytes = byteLength(tail);\n\t\t\tthis.hasOpenLine = tail.length > 0;\n\t\t}\n\t\tthis.totalLines = this.completedLines + (this.hasOpenLine ? 1 : 0);\n\t}\n\n\tprivate trimTail(): void {\n\t\tconst buffer = Buffer.from(this.tailText, \"utf-8\");\n\t\tif (buffer.length <= this.maxRollingBytes) {\n\t\t\tthis.tailBytes = buffer.length;\n\t\t\treturn;\n\t\t}\n\n\t\tlet start = buffer.length - this.maxRollingBytes;\n\t\twhile (start < buffer.length && (buffer[start] & 0xc0) === 0x80) {\n\t\t\tstart++;\n\t\t}\n\n\t\tthis.tailStartsAtLineBoundary = start === 0 ? this.tailStartsAtLineBoundary : buffer[start - 1] === 0x0a;\n\t\tthis.tailText = buffer.subarray(start).toString(\"utf-8\");\n\t\tthis.tailBytes = byteLength(this.tailText);\n\t}\n\n\tprivate getSnapshotText(): string {\n\t\tif (this.tailStartsAtLineBoundary) {\n\t\t\treturn this.tailText;\n\t\t}\n\n\t\tconst firstNewline = this.tailText.indexOf(\"\\n\");\n\t\treturn firstNewline === -1 ? this.tailText : this.tailText.slice(firstNewline + 1);\n\t}\n\n\tprivate shouldUseTempFile(): boolean {\n\t\treturn (\n\t\t\tthis.totalRawBytes > this.maxBytes || this.totalDecodedBytes > this.maxBytes || this.totalLines > this.maxLines\n\t\t);\n\t}\n\n\tprivate ensureTempFile(): void {\n\t\tif (this.tempFilePath) {\n\t\t\treturn;\n\t\t}\n\t\tconst { path, stream } = createOutputFileStream(this.tempFilePrefix, \".log\");\n\t\tthis.tempFilePath = path;\n\t\tthis.tempFileStream = stream;\n\t\t// Own errors immediately, including failures before the caller starts closing the file.\n\t\tthis.tempFileDone = finished(stream, { cleanup: true });\n\t\tvoid this.tempFileDone.catch(() => {});\n\t\tfor (const chunk of this.rawChunks) {\n\t\t\tthis.tempFileStream.write(chunk);\n\t\t}\n\t\tthis.rawChunks = [];\n\t}\n\n\tprivate waitForDrain(): Promise<void> {\n\t\tif (this.pendingDrain) return this.pendingDrain;\n\t\tconst stream = this.tempFileStream!;\n\t\tthis.pendingDrain = new Promise<void>((resolve, reject) => {\n\t\t\tconst cleanup = () => {\n\t\t\t\tstream.off(\"drain\", onDrain);\n\t\t\t\tstream.off(\"error\", onError);\n\t\t\t\tstream.off(\"close\", onClose);\n\t\t\t\tstream.off(\"finish\", onDrain);\n\t\t\t\tthis.pendingDrain = undefined;\n\t\t\t};\n\t\t\tconst onDrain = () => {\n\t\t\t\tcleanup();\n\t\t\t\tresolve();\n\t\t\t};\n\t\t\tconst onError = (error: Error) => {\n\t\t\t\tcleanup();\n\t\t\t\treject(error);\n\t\t\t};\n\t\t\tconst onClose = () => onError(stream.errored ?? new Error(\"Output file closed before draining\"));\n\t\t\tstream.once(\"drain\", onDrain);\n\t\t\tstream.once(\"error\", onError);\n\t\t\tstream.once(\"close\", onClose);\n\t\t\tstream.once(\"finish\", onDrain);\n\t\t});\n\t\t// Custom operations may still send synchronously; closeTempFile also reports write failures.\n\t\tvoid this.pendingDrain.catch(() => {});\n\t\treturn this.pendingDrain;\n\t}\n}\n"]}
1
+ {"version":3,"file":"output-accumulator.js","sourceRoot":"","sources":["../../../src/core/tools/output-accumulator.ts"],"names":[],"mappings":"AAAA,0JAA0J;AAC1J,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,sBAAsB,EAAgD,MAAM,6BAA6B,CAAC;AACnH,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAyB,YAAY,EAAE,MAAM,eAAe,CAAC;AA2B1G,SAAS,UAAU,CAAC,IAAY;IAC/B,OAAO,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACzC,CAAC;AA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AC,QAAQ,CAAC,KAAK,CAAC,YAAY,GAAG,CAAC,CAAC,CAAC;IACpF,CAAC;IAEO,iBAAiB;QACxB,OAAO,CACN,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,QAAQ,CAC/G,CAAC;IACH,CAAC;IAEO,cAAc;QACrB,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,OAAO,IAAI,CAAC,QAAQ,CAAC;QACtB,CAAC;QACD,MAAM,QAAQ,GAAG,sBAAsB,CAAC,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;QACrE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACpC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;QACD,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;QACpB,OAAO,QAAQ,CAAC;IACjB,CAAC;CACD","sourcesContent":["// Derived in part from Pi-Bolt (MIT, Copyright (c) 2026 OpenSec (Pi-Bolt)), commit 9933992aea68a951b3b831c754a8e77525fcbae5; adapted for HUMAIN Code CLI.\nimport { open } from \"node:fs/promises\";\nimport { createOutputFileStream, type OutputFileResult, type OutputFileStream } from \"../../utils/output-files.ts\";\nimport { OutputCleanup } from \"./output-cleanup.ts\";\nimport { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, type TruncationResult, truncateTail } from \"./truncate.ts\";\n\nexport interface OutputAccumulatorOptions {\n\tmaxLines?: number;\n\tmaxBytes?: number;\n\ttempFilePrefix?: string;\n\t/** Retain half the byte and line budgets from each end instead of only the tail. */\n\theadAndTail?: boolean;\n\t/** Clean decoded display text before truncation, preserving raw output in the spill file. */\n\tcleanup?: boolean;\n}\n\nexport interface OutputSnapshot {\n\tcontent: string;\n\ttruncation: TruncationResult;\n\t/** Set once the full output goes to a file. While output streams in, `saved` means the file is being written. */\n\tfullOutputFile?: OutputFileResult;\n\t/** The saved file path, when available. */\n\tfullOutputPath?: string;\n}\n\nexport interface FullOutput {\n\tcontent: string;\n\t/** Whether `content` omits part of the output. */\n\ttruncated: boolean;\n}\n\nfunction byteLength(text: string): number {\n\treturn Buffer.byteLength(text, \"utf-8\");\n}\n\n/**\n * Incrementally tracks streaming output with bounded memory.\n *\n * Appends decode chunks with a streaming UTF-8 decoder, keeps only a decoded\n * tail for display snapshots, and opens a temp file when the full output needs\n * to be preserved. Opt-in cleanup additionally buffers the current line and final\n * identical-line run, so its memory follows the largest pending line.\n */\nexport class OutputAccumulator {\n\tprivate readonly maxLines: number;\n\tprivate readonly maxBytes: number;\n\tprivate readonly maxRollingBytes: number;\n\tprivate readonly tempFilePrefix: string;\n\tprivate readonly decoder = new TextDecoder();\n\tprivate readonly cleanup: OutputCleanup | undefined;\n\tprivate readonly headAndTail: boolean;\n\tprivate headText = \"\";\n\tprivate headComplete = false;\n\n\tprivate rawChunks: Buffer[] = [];\n\tprivate tailText = \"\";\n\tprivate tailBytes = 0;\n\tprivate tailStartsAtLineBoundary = true;\n\tprivate totalRawBytes = 0;\n\tprivate totalDecodedBytes = 0;\n\tprivate completedLines = 0;\n\tprivate totalLines = 0;\n\tprivate currentLineBytes = 0;\n\tprivate hasOpenLine = false;\n\tprivate finished = false;\n\n\tprivate tempFile: OutputFileStream | undefined;\n\tprivate rawTail = \"\";\n\tprivate totalRawDecodedBytes = 0;\n\n\tconstructor(options: OutputAccumulatorOptions = {}) {\n\t\tthis.cleanup = options.cleanup ? new OutputCleanup() : undefined;\n\t\tthis.headAndTail = options.headAndTail ?? false;\n\t\tthis.maxLines = options.maxLines ?? DEFAULT_MAX_LINES;\n\t\tthis.maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;\n\t\tthis.maxRollingBytes = Math.max(this.maxBytes * 2, 1);\n\t\tthis.tempFilePrefix = options.tempFilePrefix ?? \"pi-output\";\n\t}\n\n\t/** Accept a chunk; await the returned promise before sending another chunk. */\n\tappend(data: Buffer): void | Promise<void> {\n\t\tif (this.finished) {\n\t\t\tthrow new Error(\"Cannot append to a finished output accumulator\");\n\t\t}\n\n\t\tthis.totalRawBytes += data.length;\n\t\tconst decoded = this.decoder.decode(data, { stream: true });\n\t\tthis.appendOutput(decoded);\n\n\t\tif (this.cleanup || this.tempFile || this.shouldUseTempFile()) {\n\t\t\treturn this.ensureTempFile().write(data);\n\t\t} else if (data.length > 0) {\n\t\t\tthis.rawChunks.push(data);\n\t\t}\n\t}\n\n\tfinish(): void {\n\t\tif (this.finished) {\n\t\t\treturn;\n\t\t}\n\t\tthis.finished = true;\n\t\tthis.appendOutput(this.decoder.decode());\n\t\tif (this.cleanup) this.appendDecodedText(this.cleanup.finish());\n\t\tif (this.cleanup || this.shouldUseTempFile()) {\n\t\t\tthis.ensureTempFile();\n\t\t}\n\t}\n\n\tsnapshot(options: { persistIfTruncated?: boolean } = {}): OutputSnapshot {\n\t\tif (this.cleanup) this.ensureTempFile();\n\t\tconst snapshot = this.contentSnapshot(options);\n\t\tif (!this.cleanup) return snapshot;\n\t\tconst recovery =\n\t\t\tsnapshot.fullOutputFile?.kind === \"saved\"\n\t\t\t\t? `Raw output: ${snapshot.fullOutputFile.path}. Use read with offset/limit, or grep the saved file.`\n\t\t\t\t: `Could not save the raw output: ${snapshot.fullOutputFile?.kind === \"failed\" ? snapshot.fullOutputFile.error : \"no output file\"}`;\n\t\tconst content = `${snapshot.content}\\n\\n[Output cleanup applied (terminal controls, CR overwrites, repeated/blank lines). ${recovery}]`;\n\t\treturn { ...snapshot, content, truncation: { ...snapshot.truncation, content } };\n\t}\n\n\tprivate contentSnapshot(options: { persistIfTruncated?: boolean }): OutputSnapshot {\n\t\tif (this.headAndTail) return this.headAndTailSnapshot();\n\t\tconst tailTruncation = truncateTail(this.getRetainedText(), {\n\t\t\tmaxLines: this.maxLines,\n\t\t\tmaxBytes: this.maxBytes,\n\t\t});\n\t\tconst truncated = this.totalLines > this.maxLines || this.totalDecodedBytes > this.maxBytes;\n\t\tconst truncatedBy = truncated\n\t\t\t? (tailTruncation.truncatedBy ?? (this.totalDecodedBytes > this.maxBytes ? \"bytes\" : \"lines\"))\n\t\t\t: null;\n\t\tconst truncation: TruncationResult = {\n\t\t\t...tailTruncation,\n\t\t\ttruncated,\n\t\t\ttruncatedBy,\n\t\t\ttotalLines: this.totalLines,\n\t\t\ttotalBytes: this.totalDecodedBytes,\n\t\t\tmaxLines: this.maxLines,\n\t\t\tmaxBytes: this.maxBytes,\n\t\t};\n\n\t\tif (options.persistIfTruncated && truncation.truncated) {\n\t\t\tthis.ensureTempFile();\n\t\t}\n\n\t\treturn { content: truncation.content, truncation, ...this.snapshotFile() };\n\t}\n\n\t/** Flush and close the temp file. Never rejects: a failed file shows up as `failed` in later snapshots. */\n\tasync closeTempFile(): Promise<void> {\n\t\tawait this.tempFile?.close();\n\t}\n\n\t/**\n\t * The complete output, for callers that can take more than the display snapshot. Call after\n\t * `finish()` and `closeTempFile()`. Output longer than `maxBytes` raw bytes keeps its first and\n\t * last `maxBytes / 2` bytes around an omission marker. When the temp file could not be saved, only\n\t * the retained tail is left: up to its last `maxBytes` bytes, behind the same marker when output is\n\t * missing.\n\t */\n\tasync readFullOutput(maxBytes: number): Promise<FullOutput> {\n\t\tconst fullOutputFile = this.tempFile?.result;\n\t\tif (!fullOutputFile) {\n\t\t\treturn { content: new TextDecoder().decode(Buffer.concat(this.rawChunks)), truncated: false };\n\t\t}\n\t\tif (fullOutputFile.kind === \"failed\") {\n\t\t\treturn this.readRetainedOutput(maxBytes);\n\t\t}\n\t\tconst file = await open(fullOutputFile.path, \"r\");\n\t\ttry {\n\t\t\tconst size = (await file.stat()).size;\n\t\t\tif (size <= maxBytes) {\n\t\t\t\treturn { content: new TextDecoder().decode(await file.readFile()), truncated: false };\n\t\t\t}\n\t\t\tconst headBytes = Math.floor(maxBytes / 2);\n\t\t\tconst tailBytes = maxBytes - headBytes;\n\t\t\tconst head = Buffer.alloc(headBytes);\n\t\t\tconst tail = Buffer.alloc(tailBytes);\n\t\t\tawait file.read(head, 0, headBytes, 0);\n\t\t\tawait file.read(tail, 0, tailBytes, size - tailBytes);\n\t\t\t// Cut at character boundaries: streaming decode holds back an incomplete trailing sequence,\n\t\t\t// and the tail skips leading continuation bytes.\n\t\t\tconst headText = new TextDecoder().decode(head, { stream: true });\n\t\t\tlet tailStart = 0;\n\t\t\twhile (tailStart < tail.length && (tail[tailStart] & 0xc0) === 0x80) tailStart++;\n\t\t\tconst tailText = new TextDecoder().decode(tail.subarray(tailStart));\n\t\t\tconst omitted = size - headBytes - tailBytes;\n\t\t\treturn { content: `${headText}\\n\\n[... ${omitted} bytes omitted ...]\\n\\n${tailText}`, truncated: true };\n\t\t} finally {\n\t\t\tawait file.close();\n\t\t}\n\t}\n\n\tprivate headAndTailSnapshot(): OutputSnapshot {\n\t\tconst truncated = this.totalLines > this.maxLines || this.totalDecodedBytes > this.maxBytes;\n\t\tlet content = this.tailText;\n\t\tlet outputBytes = this.totalDecodedBytes;\n\t\tlet outputLines = this.totalLines;\n\t\tif (truncated) {\n\t\t\tthis.ensureTempFile();\n\t\t\tconst head = this.headText\n\t\t\t\t.split(\"\\n\")\n\t\t\t\t.slice(0, Math.floor(this.maxLines / 2))\n\t\t\t\t.join(\"\\n\");\n\t\t\tconst tail = truncateTail(this.tailText, {\n\t\t\t\tmaxBytes: this.maxBytes - Math.floor(this.maxBytes / 2),\n\t\t\t\tmaxLines: this.maxLines - Math.floor(this.maxLines / 2),\n\t\t\t});\n\t\t\toutputBytes = byteLength(head) + tail.outputBytes;\n\t\t\toutputLines = (head ? head.split(\"\\n\").length - Number(head.endsWith(\"\\n\")) : 0) + tail.outputLines;\n\t\t\tconst omitted = this.totalDecodedBytes - outputBytes;\n\t\t\tconst file = this.tempFile?.result;\n\t\t\tconst recovery =\n\t\t\t\tfile?.kind === \"failed\"\n\t\t\t\t\t? `Could not save the full output: ${file.error}.`\n\t\t\t\t\t: `Full output: ${file?.path}. Use read with offset/limit, or grep the saved file.`;\n\t\t\tcontent = `${head}\\n\\n[... ${omitted} bytes omitted; showing head and tail (8 KiB / 2,000-line limit). ${recovery} Do not infer success from truncated output.]\\n\\n${tail.content}`;\n\t\t}\n\t\treturn {\n\t\t\tcontent,\n\t\t\t...this.snapshotFile(),\n\t\t\ttruncation: {\n\t\t\t\tcontent,\n\t\t\t\ttruncated,\n\t\t\t\ttruncatedBy: truncated ? (this.totalDecodedBytes > this.maxBytes ? \"bytes\" : \"lines\") : null,\n\t\t\t\ttotalBytes: this.totalDecodedBytes,\n\t\t\t\ttotalLines: this.totalLines,\n\t\t\t\toutputBytes,\n\t\t\t\toutputLines,\n\t\t\t\tmaxBytes: this.maxBytes,\n\t\t\t\tmaxLines: this.maxLines,\n\t\t\t\tlastLinePartial: false,\n\t\t\t\tfirstLineExceedsLimit: false,\n\t\t\t},\n\t\t};\n\t}\n\n\tgetLastLineBytes(): number {\n\t\treturn this.currentLineBytes;\n\t}\n\n\tprivate snapshotFile(): Pick<OutputSnapshot, \"fullOutputFile\" | \"fullOutputPath\"> {\n\t\tconst file = this.tempFile?.result;\n\t\treturn { fullOutputFile: file, ...(file?.kind === \"saved\" ? { fullOutputPath: file.path } : {}) };\n\t}\n\n\tprivate appendOutput(decoded: string): void {\n\t\tif (!this.cleanup) {\n\t\t\tthis.appendDecodedText(decoded);\n\t\t\treturn;\n\t\t}\n\t\t// Structured output is raw even when cleanup is on; retain a bounded raw recovery tail.\n\t\tthis.totalRawDecodedBytes += byteLength(decoded);\n\t\tconst raw = this.rawTail + decoded;\n\t\tif (raw.length > this.maxRollingBytes) {\n\t\t\tlet cut = raw.length - this.maxRollingBytes;\n\t\t\tconst code = raw.charCodeAt(cut);\n\t\t\tif (code >= 0xdc00 && code <= 0xdfff) cut++;\n\t\t\t// Detach the suffix so retaining it cannot keep an entire oversized read alive.\n\t\t\tthis.rawTail = Buffer.from(raw.slice(cut), \"utf-8\").toString(\"utf-8\");\n\t\t} else {\n\t\t\tthis.rawTail = raw;\n\t\t}\n\t\tthis.appendDecodedText(this.cleanup.append(decoded));\n\t}\n\n\tprivate appendDecodedText(text: string): void {\n\t\tif (text.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst bytes = byteLength(text);\n\t\tif (this.headAndTail && !this.headComplete) {\n\t\t\tconst limit = Math.floor(this.maxBytes / 2);\n\t\t\tconst head = Buffer.from(this.headText + text.slice(0, limit));\n\t\t\t// This text is already decoded; preserve a literal BOM while holding back incomplete UTF-8.\n\t\t\tthis.headText = new TextDecoder(\"utf-8\", { ignoreBOM: true }).decode(head.subarray(0, limit), {\n\t\t\t\tstream: true,\n\t\t\t});\n\t\t\tthis.headComplete = head.length >= limit;\n\t\t}\n\t\tthis.totalDecodedBytes += bytes;\n\t\tconst tailLength = this.tailText.length;\n\t\tif (this.tailBytes + bytes > this.maxRollingBytes * 2 && bytes === text.length && this.tailBytes === tailLength) {\n\t\t\t// Both ASCII: keep the same byte tail without joining and re-encoding oversized pipe reads.\n\t\t\tconst start = tailLength + bytes - this.maxRollingBytes;\n\t\t\tconst before =\n\t\t\t\tstart - 1 < tailLength ? this.tailText.charCodeAt(start - 1) : text.charCodeAt(start - 1 - tailLength);\n\t\t\tthis.tailStartsAtLineBoundary = before === 0x0a;\n\t\t\t// Copy only the retained suffix so a V8 sliced string cannot keep the oversized parent alive.\n\t\t\tthis.tailText = Buffer.from(\n\t\t\t\tstart >= tailLength ? text.slice(start - tailLength) : this.tailText.slice(start) + text,\n\t\t\t\t\"utf-8\",\n\t\t\t).toString(\"utf-8\");\n\t\t\tthis.tailBytes = this.maxRollingBytes;\n\t\t} else {\n\t\t\tthis.tailText += text;\n\t\t\tthis.tailBytes += bytes;\n\t\t\tif (this.tailBytes > this.maxRollingBytes * 2) {\n\t\t\t\tthis.trimTail();\n\t\t\t}\n\t\t}\n\n\t\tlet newlines = 0;\n\t\tlet lastNewline = -1;\n\t\tfor (let i = text.indexOf(\"\\n\"); i !== -1; i = text.indexOf(\"\\n\", i + 1)) {\n\t\t\tnewlines++;\n\t\t\tlastNewline = i;\n\t\t}\n\t\tif (newlines === 0) {\n\t\t\tthis.currentLineBytes += bytes;\n\t\t\tthis.hasOpenLine = true;\n\t\t} else {\n\t\t\tthis.completedLines += newlines;\n\t\t\tconst tail = text.slice(lastNewline + 1);\n\t\t\tthis.currentLineBytes = byteLength(tail);\n\t\t\tthis.hasOpenLine = tail.length > 0;\n\t\t}\n\t\tthis.totalLines = this.completedLines + (this.hasOpenLine ? 1 : 0);\n\t}\n\n\tprivate trimTail(): void {\n\t\tconst buffer = Buffer.from(this.tailText, \"utf-8\");\n\t\tif (buffer.length <= this.maxRollingBytes) {\n\t\t\tthis.tailBytes = buffer.length;\n\t\t\treturn;\n\t\t}\n\n\t\tlet start = buffer.length - this.maxRollingBytes;\n\t\twhile (start < buffer.length && (buffer[start] & 0xc0) === 0x80) {\n\t\t\tstart++;\n\t\t}\n\n\t\tthis.tailStartsAtLineBoundary = start === 0 ? this.tailStartsAtLineBoundary : buffer[start - 1] === 0x0a;\n\t\tthis.tailText = buffer.subarray(start).toString(\"utf-8\");\n\t\tthis.tailBytes = byteLength(this.tailText);\n\t}\n\n\t/**\n\t * The retained tail, for display and as the fallback of `readFullOutput()`. Clipping drops the partial\n\t * first line of the tail. When the tail is only the end of one over-long line (plus blank lines),\n\t * nothing is left, so it keeps the end of that line instead.\n\t */\n\tprivate getRetainedText(): string {\n\t\tconst clippedText = this.getSnapshotText();\n\t\treturn clippedText.trim().length === 0 ? this.tailText : clippedText;\n\t}\n\n\t/** The retained tail within `maxBytes`, marked as truncated only when output is missing. */\n\tprivate readRetainedOutput(maxBytes: number): FullOutput {\n\t\tlet bytes = Buffer.from(this.cleanup ? this.rawTail : this.getRetainedText(), \"utf-8\");\n\t\tif (bytes.length > maxBytes) {\n\t\t\tlet start = bytes.length - maxBytes;\n\t\t\twhile (start < bytes.length && (bytes[start] & 0xc0) === 0x80) start++;\n\t\t\tbytes = bytes.subarray(start);\n\t\t}\n\t\tconst tail = bytes.toString(\"utf-8\");\n\t\tconst omitted = (this.cleanup ? this.totalRawDecodedBytes : this.totalDecodedBytes) - bytes.length;\n\t\tif (omitted === 0) {\n\t\t\treturn { content: tail, truncated: false };\n\t\t}\n\t\treturn { content: `[... ${omitted} bytes omitted ...]\\n\\n${tail}`, truncated: true };\n\t}\n\n\tprivate getSnapshotText(): string {\n\t\tif (this.tailStartsAtLineBoundary) {\n\t\t\treturn this.tailText;\n\t\t}\n\n\t\tconst firstNewline = this.tailText.indexOf(\"\\n\");\n\t\treturn firstNewline === -1 ? this.tailText : this.tailText.slice(firstNewline + 1);\n\t}\n\n\tprivate shouldUseTempFile(): boolean {\n\t\treturn (\n\t\t\tthis.totalRawBytes > this.maxBytes || this.totalDecodedBytes > this.maxBytes || this.totalLines > this.maxLines\n\t\t);\n\t}\n\n\tprivate ensureTempFile(): OutputFileStream {\n\t\tif (this.tempFile) {\n\t\t\treturn this.tempFile;\n\t\t}\n\t\tconst tempFile = createOutputFileStream(this.tempFilePrefix, \".log\");\n\t\tthis.tempFile = tempFile;\n\t\tfor (const chunk of this.rawChunks) {\n\t\t\ttempFile.write(chunk);\n\t\t}\n\t\tthis.rawChunks = [];\n\t\treturn tempFile;\n\t}\n}\n"]}
@@ -33,13 +33,19 @@ export declare function formatToolCallWithArgs(title: string, args: unknown, the
33
33
  /** Duration as `4.2s` below a minute, then `1m 30s` and `2h 3m 4s`. */
34
34
  export declare function formatToolDuration(ms: number): string;
35
35
  /** Renderer state of {@link startToolTimer} and {@link toolTimerText}, kept in `ToolRenderContext.state`. */
36
- interface ToolTimerState {
36
+ export interface ToolTimerState {
37
37
  startedAt?: number;
38
38
  endedAt?: number;
39
39
  interval?: ReturnType<typeof setInterval>;
40
40
  }
41
41
  /** Start the row's clock once execution starts. Call from `renderCall`. */
42
42
  export declare function startToolTimer(context: ToolRenderContext<ToolTimerState>): void;
43
+ /**
44
+ * Stop the row's clock for good: for a row that gets no final result (it left the transcript, or its run ended).
45
+ * Otherwise its 1 s timer keeps asking for frames, and keeps the row alive, for the rest of the session
46
+ * (Pi-Bolt 4adb6bb99).
47
+ */
48
+ export declare function stopToolTimer(state: ToolTimerState): void;
43
49
  /**
44
50
  * The row's timing line, from `renderResult`: `Elapsed 4.2s` while the result is partial, redrawn
45
51
  * every second, and `Took 4.2s` once it is final. Undefined when the row has no start time and no
@@ -50,5 +56,4 @@ export declare function invalidArgText(theme: Theme): string;
50
56
  export declare function renderToolPath(rawPath: string | null, theme: Theme, cwd: string, options?: {
51
57
  emptyFallback?: string;
52
58
  }): string;
53
- export {};
54
59
  //# sourceMappingURL=render-utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"render-utils.d.ts","sourceRoot":"","sources":["../../../src/core/tools/render-utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAWvE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AAIpE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAGjD;AAED,wBAAgB,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAIjF;AAED;;;GAGG;AACH,wBAAgB,GAAG,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAIjD;AAoCD,gGAAgG;AAChG,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAU3E;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MA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AAE,CAAC,WAAW,GAAG,YAAY,CAAC,EAAE,CAAC;IACxC,OAAO,EAAE,QAAQ,CAAC;CAClB,CAAC;AAIF;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,GAAG,MAAM,CAqB5G;AAED,uEAAuE;AACvE,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAUrD;AAED,6GAA6G;AAC7G,MAAM,WAAW,cAAc;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;CAC1C;AAED,2EAA2E;AAC3E,wBAAgB,cAAc,CAAC,OAAO,EAAE,iBAAiB,CAAC,cAAc,CAAC,GAAG,IAAI,CAM/E;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI,CAMzD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,iBAAiB,CAAC,cAAc,CAAC,EAAE,SAAS,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAkBhH;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAEnD;AAED,wBAAgB,cAAc,CAC7B,OAAO,EAAE,MAAM,GAAG,IAAI,EACtB,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE;IAAE,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,GAClC,MAAM,CAKR"}
@@ -148,6 +148,19 @@ export function startToolTimer(context) {
148
148
  state.endedAt = undefined;
149
149
  }
150
150
  }
151
+ /**
152
+ * Stop the row's clock for good: for a row that gets no final result (it left the transcript, or its run ended).
153
+ * Otherwise its 1 s timer keeps asking for frames, and keeps the row alive, for the rest of the session
154
+ * (Pi-Bolt 4adb6bb99).
155
+ */
156
+ export function stopToolTimer(state) {
157
+ if (state.startedAt !== undefined)
158
+ state.endedAt ??= Date.now();
159
+ if (state.interval) {
160
+ clearInterval(state.interval);
161
+ state.interval = undefined;
162
+ }
163
+ }
151
164
  /**
152
165
  * The row's timing line, from `renderResult`: `Elapsed 4.2s` while the result is partial, redrawn
153
166
  * every second, and `Took 4.2s` once it is final. Undefined when the row has no start time and no
@@ -155,7 +168,7 @@ export function startToolTimer(context) {
155
168
  */
156
169
  export function toolTimerText(context, isPartial) {
157
170
  const state = context.state;
158
- if (state.startedAt !== undefined && isPartial && !state.interval) {
171
+ if (state.startedAt !== undefined && state.endedAt === undefined && isPartial && !state.interval) {
159
172
  state.interval = setInterval(() => context.invalidate(), 1000);
160
173
  }
161
174
  if (!isPartial || context.isError) {
@@ -1 +1 @@
1
- {"version":3,"file":"render-utils.js","sourceRoot":"","sources":["../../../src/core/tools/render-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EACN,eAAe,EACf,kBAAkB,EAClB,SAAS,EACT,aAAa,EAEb,oBAAoB,EACpB,wBAAwB,EACxB,cAAc,GACd,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAG5D,MAAM,UAAU,WAAW,CAAC,IAAa;IACxC,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,EAAE,CAAC;IACxC,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,UAAkB,EAAE,OAAe,EAAE,GAAW;IACxE,IAAI,CAAC,eAAe,EAAE,CAAC,UAAU;QAAE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,CAAC,SAAS,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS;QAAE,OAAO,QAAQ,kBAAkB,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;IAC5G,IAAI,KAAK,CAAC,SAAS,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACpD,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;IAC5C,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,IAAI,kBAAkB,CAAC,OAAO,GAAG,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;AAC7F,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAY;IAC1C,OAAO,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,cAAc,CAC7B,OAAsB,EACtB,KAAY,EACZ,GAAW,EACX,OAAoC;IAEpC,IAAI,OAAO,KAAK,IAAI;QAAE,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC;IACnD,MAAM,KAAK,GAAG,OAAO,IAAI,OAAO,EAAE,aAAa,CAAC;IAChD,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC,EAAE,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;IACjD,OAAO,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;AACrE,CAAC","sourcesContent":["import { pathToFileURL } from \"node:url\";\nimport type { ImageContent, TextContent } from \"@earendil-works/pi-ai\";\nimport {\n\tgetCapabilities,\n\tgetImageDimensions,\n\thyperlink,\n\timageFallback,\n\ttype SanitizedTerminalText,\n\tsanitizeTerminalText,\n\tsanitizeTerminalTextFrom,\n\tstartsWithText,\n} from \"@earendil-works/pi-tui\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { stripAnsi } from \"../../utils/ansi.ts\";\nimport { resolvePath, shortenHomePath } from \"../../utils/paths.ts\";\nimport { sanitizeBinaryOutput } from \"../../utils/shell.ts\";\nimport type { ToolRenderContext } from \"../extensions/types.ts\";\n\nexport function shortenPath(path: unknown): string {\n\tif (typeof path !== \"string\") return \"\";\n\treturn shortenHomePath(path);\n}\n\nexport function linkPath(styledText: string, rawPath: string, cwd: string): string {\n\tif (!getCapabilities().hyperlinks) return styledText;\n\tconst absolutePath = resolvePath(rawPath, cwd);\n\treturn hyperlink(styledText, pathToFileURL(absolutePath).href);\n}\n\n/**\n * A tool call argument as text to show, or null when it is not a string. The model wrote it: escape sequences in it are\n * removed (sanitizeTerminalText()), so it cannot draw over the call's header or its command line.\n */\nexport function str(value: unknown): string | null {\n\tif (typeof value === \"string\") return sanitizeArgument(value);\n\tif (value == null) return \"\";\n\treturn null;\n}\n\n/**\n * Long arguments str() sanitised last, most recent last. An argument streaming in (a file's content) is shown again for\n * each chunk: what was sanitised of it the time before is kept, and only the text added since is gone through.\n */\nconst sanitizedArguments: SanitizedTerminalText[] = [];\nconst SANITIZED_ARGUMENTS_KEPT = 4;\n/** Shorter arguments (a path, a pattern) are sanitised whole: that costs less than looking for them. */\nconst SANITIZED_ARGUMENT_MIN_LENGTH = 1024;\n\n/** sanitizeTerminalText(text), from what a shorter text it begins with was sanitised to when there is one. */\nfunction sanitizeArgument(text: string): string {\n\tif (text.length < SANITIZED_ARGUMENT_MIN_LENGTH) return sanitizeTerminalText(text);\n\tlet previous: SanitizedTerminalText | undefined;\n\tfor (let i = sanitizedArguments.length - 1; i >= 0; i--) {\n\t\tconst entry = sanitizedArguments[i];\n\t\tif (startsWithText(text, entry.raw)) {\n\t\t\tprevious = entry;\n\t\t\tsanitizedArguments.splice(i, 1);\n\t\t\tbreak;\n\t\t}\n\t}\n\tconst sanitized = sanitizeTerminalTextFrom(text, previous);\n\tsanitizedArguments.push(sanitized);\n\tif (sanitizedArguments.length > SANITIZED_ARGUMENTS_KEPT) {\n\t\tsanitizedArguments.shift();\n\t}\n\treturn sanitized.text;\n}\n\nfunction parseLineNumber(value: unknown): number | undefined {\n\tif (typeof value === \"string\" && value.trim() !== \"\") value = Number(value);\n\treturn typeof value === \"number\" && Number.isFinite(value) ? value : undefined;\n}\n\n/** Format finite numbers or numeric strings as a read line range, omitting malformed ranges. */\nexport function formatReadLineRange(offset: unknown, limit: unknown): string {\n\t// Strict schemas represent omitted optional arguments as null.\n\tif (offset == null && limit == null) return \"\";\n\tconst start = offset == null ? 1 : parseLineNumber(offset);\n\tif (start === undefined) return \"\";\n\tif (limit == null) return `:${start}`;\n\tconst count = parseLineNumber(limit);\n\tif (count === undefined) return \"\";\n\tconst end = start + count - 1;\n\treturn `:${start}${end ? `-${end}` : \"\"}`;\n}\n\nexport function replaceTabs(text: string): string {\n\treturn text.replace(/\\t/g, \" \");\n}\n\nexport function normalizeDisplayText(text: string): string {\n\treturn text.replace(/\\r/g, \"\");\n}\n\nexport function getTextOutput(\n\tresult: { content: Array<{ type: string; text?: string; data?: string; mimeType?: string }> } | undefined,\n\tshowImages: boolean,\n): string {\n\tif (!result) return \"\";\n\n\tconst textBlocks = result.content.filter((c) => c.type === \"text\");\n\tconst imageBlocks = result.content.filter((c) => c.type === \"image\");\n\n\tlet output = textBlocks.map((c) => sanitizeBinaryOutput(stripAnsi(c.text || \"\")).replace(/\\r/g, \"\")).join(\"\\n\");\n\n\tconst caps = getCapabilities();\n\tif (imageBlocks.length > 0 && (!caps.images || !showImages)) {\n\t\tconst imageIndicators = imageBlocks\n\t\t\t.map((img) => {\n\t\t\t\tconst mimeType = img.mimeType ?? \"image/unknown\";\n\t\t\t\tconst dims =\n\t\t\t\t\timg.data && img.mimeType ? (getImageDimensions(img.data, img.mimeType) ?? undefined) : undefined;\n\t\t\t\treturn imageFallback(mimeType, dims);\n\t\t\t})\n\t\t\t.join(\"\\n\");\n\t\toutput = output ? `${output}\\n${imageIndicators}` : imageIndicators;\n\t}\n\n\treturn output;\n}\n\nexport type ToolRenderResultLike<TDetails> = {\n\tcontent: (TextContent | ImageContent)[];\n\tdetails: TDetails;\n};\n\nconst COLLAPSED_ARGS_CHARS = 100;\n\n/**\n * Generic tool call header: the title followed by the arguments. Collapsed, they are `key=value`\n * pairs on the title line, cut to {@link COLLAPSED_ARGS_CHARS}. Expanded, each is a `key: value`\n * line below the title, with strings shown raw and continuation lines indented.\n */\nexport function formatToolCallWithArgs(title: string, args: unknown, theme: Theme, expanded: boolean): string {\n\t// (The title can come from an MCP server, the arguments from the model: sanitizeTerminalText() keeps escape sequences in\n\t// either from acting on the terminal. JSON.stringify() escapes C0 controls, but not DEL and C1 controls.)\n\tconst header = theme.fg(\"toolTitle\", theme.bold(sanitizeTerminalText(title)));\n\tif (args == null) return header;\n\tconst entries =\n\t\ttypeof args === \"object\" && !Array.isArray(args)\n\t\t\t? Object.entries(args)\n\t\t\t: ([[\"args\", args]] as [string, unknown][]);\n\tif (entries.length === 0) return header;\n\tif (expanded) {\n\t\tconst lines = entries.map(([key, value]) => {\n\t\t\tconst text = typeof value === \"string\" ? value : (JSON.stringify(value, null, 2) ?? String(value));\n\t\t\tconst shown = replaceTabs(sanitizeTerminalText(text)).replace(/\\r/g, \"\");\n\t\t\treturn ` ${sanitizeTerminalText(key)}: ${shown.split(\"\\n\").join(\"\\n \")}`;\n\t\t});\n\t\treturn `${header}\\n${theme.fg(\"muted\", lines.join(\"\\n\"))}`;\n\t}\n\tconst pairs = entries.map(([key, value]) => `${key}=${JSON.stringify(value) ?? String(value)}`).join(\" \");\n\tconst preview = pairs.length > COLLAPSED_ARGS_CHARS ? `${pairs.slice(0, COLLAPSED_ARGS_CHARS - 3)}...` : pairs;\n\treturn `${header} ${theme.fg(\"muted\", sanitizeTerminalText(preview))}`;\n}\n\n/** Duration as `4.2s` below a minute, then `1m 30s` and `2h 3m 4s`. */\nexport function formatToolDuration(ms: number): string {\n\tconst seconds = ms / 1000;\n\tif (seconds < 60) return `${seconds.toFixed(1)}s`;\n\n\tconst totalSeconds = Math.floor(seconds);\n\tconst minutes = Math.floor(totalSeconds / 60);\n\tconst remainder = totalSeconds % 60;\n\tif (minutes < 60) return `${minutes}m ${remainder}s`;\n\n\treturn `${Math.floor(minutes / 60)}h ${minutes % 60}m ${remainder}s`;\n}\n\n/** Renderer state of {@link startToolTimer} and {@link toolTimerText}, kept in `ToolRenderContext.state`. */\ninterface ToolTimerState {\n\tstartedAt?: number;\n\tendedAt?: number;\n\tinterval?: ReturnType<typeof setInterval>;\n}\n\n/** Start the row's clock once execution starts. Call from `renderCall`. */\nexport function startToolTimer(context: ToolRenderContext<ToolTimerState>): void {\n\tconst state = context.state;\n\tif (context.executionStarted && state.startedAt === undefined) {\n\t\tstate.startedAt = Date.now();\n\t\tstate.endedAt = undefined;\n\t}\n}\n\n/**\n * The row's timing line, from `renderResult`: `Elapsed 4.2s` while the result is partial, redrawn\n * every second, and `Took 4.2s` once it is final. Undefined when the row has no start time and no\n * recorded duration.\n */\nexport function toolTimerText(context: ToolRenderContext<ToolTimerState>, isPartial: boolean): string | undefined {\n\tconst state = context.state;\n\tif (state.startedAt !== undefined && isPartial && !state.interval) {\n\t\tstate.interval = setInterval(() => context.invalidate(), 1000);\n\t}\n\tif (!isPartial || context.isError) {\n\t\tstate.endedAt ??= Date.now();\n\t\tif (state.interval) {\n\t\t\tclearInterval(state.interval);\n\t\t\tstate.interval = undefined;\n\t\t}\n\t}\n\t// A final result's recorded duration wins: it is monotonic and survives reloads. The renderer's own clock is the\n\t// fallback for live progress and for results stored without one.\n\tif (!isPartial && context.durationMs !== undefined) return `Took ${formatToolDuration(context.durationMs)}`;\n\tif (state.startedAt === undefined) return undefined;\n\tconst endTime = state.endedAt ?? Date.now();\n\treturn `${isPartial ? \"Elapsed\" : \"Took\"} ${formatToolDuration(endTime - state.startedAt)}`;\n}\n\nexport function invalidArgText(theme: Theme): string {\n\treturn theme.fg(\"error\", \"[invalid arg]\");\n}\n\nexport function renderToolPath(\n\trawPath: string | null,\n\ttheme: Theme,\n\tcwd: string,\n\toptions?: { emptyFallback?: string },\n): string {\n\tif (rawPath === null) return invalidArgText(theme);\n\tconst value = rawPath || options?.emptyFallback;\n\tif (!value) return theme.fg(\"toolOutput\", \"...\");\n\treturn linkPath(theme.fg(\"accent\", shortenPath(value)), value, cwd);\n}\n"]}
1
+ {"version":3,"file":"render-utils.js","sourceRoot":"","sources":["../../../src/core/tools/render-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EACN,eAAe,EACf,kBAAkB,EAClB,SAAS,EACT,aAAa,EAEb,oBAAoB,EACpB,wBAAwB,EACxB,cAAc,GACd,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAG5D,MAAM,UAAU,WAAW,CAAC,IAAa;IACxC,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,EAAE,CAAC;IACxC,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,UAAkB,EAAE,OAAe,EAAE,GAAW;IACxE,IAAI,CAAC,eAAe,EAAE,CAAC,UAAU;QAAE,OAAO,UAAU,CAAC;IACrD,MAAM,YAAY,GAAG,WAAW,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IAC/C,OAAO,SAAS,CAAC,UAAU,EAAE,aAAa,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,CAAC;AAChE,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,GAAG,CAAC,KAAc;IACjC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,gBAAgB,CAAC,KAAK,CAAC,CAAC;IAC9D,IAAI,KA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H,iEAAiE;IACjE,IAAI,CAAC,SAAS,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS;QAAE,OAAO,QAAQ,kBAAkB,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;IAC5G,IAAI,KAAK,CAAC,SAAS,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACpD,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;IAC5C,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,IAAI,kBAAkB,CAAC,OAAO,GAAG,KAAK,CAAC,SAAS,CAAC,EAAE,CAAC;AAC7F,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAY;IAC1C,OAAO,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,cAAc,CAC7B,OAAsB,EACtB,KAAY,EACZ,GAAW,EACX,OAAoC;IAEpC,IAAI,OAAO,KAAK,IAAI;QAAE,OAAO,cAAc,CAAC,KAAK,CAAC,CAAC;IACnD,MAAM,KAAK,GAAG,OAAO,IAAI,OAAO,EAAE,aAAa,CAAC;IAChD,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC,EAAE,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;IACjD,OAAO,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;AACrE,CAAC","sourcesContent":["import { pathToFileURL } from \"node:url\";\nimport type { ImageContent, TextContent } from \"@earendil-works/pi-ai\";\nimport {\n\tgetCapabilities,\n\tgetImageDimensions,\n\thyperlink,\n\timageFallback,\n\ttype SanitizedTerminalText,\n\tsanitizeTerminalText,\n\tsanitizeTerminalTextFrom,\n\tstartsWithText,\n} from \"@earendil-works/pi-tui\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { stripAnsi } from \"../../utils/ansi.ts\";\nimport { resolvePath, shortenHomePath } from \"../../utils/paths.ts\";\nimport { sanitizeBinaryOutput } from \"../../utils/shell.ts\";\nimport type { ToolRenderContext } from \"../extensions/types.ts\";\n\nexport function shortenPath(path: unknown): string {\n\tif (typeof path !== \"string\") return \"\";\n\treturn shortenHomePath(path);\n}\n\nexport function linkPath(styledText: string, rawPath: string, cwd: string): string {\n\tif (!getCapabilities().hyperlinks) return styledText;\n\tconst absolutePath = resolvePath(rawPath, cwd);\n\treturn hyperlink(styledText, pathToFileURL(absolutePath).href);\n}\n\n/**\n * A tool call argument as text to show, or null when it is not a string. The model wrote it: escape sequences in it are\n * removed (sanitizeTerminalText()), so it cannot draw over the call's header or its command line.\n */\nexport function str(value: unknown): string | null {\n\tif (typeof value === \"string\") return sanitizeArgument(value);\n\tif (value == null) return \"\";\n\treturn null;\n}\n\n/**\n * Long arguments str() sanitised last, most recent last. An argument streaming in (a file's content) is shown again for\n * each chunk: what was sanitised of it the time before is kept, and only the text added since is gone through.\n */\nconst sanitizedArguments: SanitizedTerminalText[] = [];\nconst SANITIZED_ARGUMENTS_KEPT = 4;\n/** Shorter arguments (a path, a pattern) are sanitised whole: that costs less than looking for them. */\nconst SANITIZED_ARGUMENT_MIN_LENGTH = 1024;\n\n/** sanitizeTerminalText(text), from what a shorter text it begins with was sanitised to when there is one. */\nfunction sanitizeArgument(text: string): string {\n\tif (text.length < SANITIZED_ARGUMENT_MIN_LENGTH) return sanitizeTerminalText(text);\n\tlet previous: SanitizedTerminalText | undefined;\n\tfor (let i = sanitizedArguments.length - 1; i >= 0; i--) {\n\t\tconst entry = sanitizedArguments[i];\n\t\tif (startsWithText(text, entry.raw)) {\n\t\t\tprevious = entry;\n\t\t\tsanitizedArguments.splice(i, 1);\n\t\t\tbreak;\n\t\t}\n\t}\n\tconst sanitized = sanitizeTerminalTextFrom(text, previous);\n\tsanitizedArguments.push(sanitized);\n\tif (sanitizedArguments.length > SANITIZED_ARGUMENTS_KEPT) {\n\t\tsanitizedArguments.shift();\n\t}\n\treturn sanitized.text;\n}\n\nfunction parseLineNumber(value: unknown): number | undefined {\n\tif (typeof value === \"string\" && value.trim() !== \"\") value = Number(value);\n\treturn typeof value === \"number\" && Number.isFinite(value) ? value : undefined;\n}\n\n/** Format finite numbers or numeric strings as a read line range, omitting malformed ranges. */\nexport function formatReadLineRange(offset: unknown, limit: unknown): string {\n\t// Strict schemas represent omitted optional arguments as null.\n\tif (offset == null && limit == null) return \"\";\n\tconst start = offset == null ? 1 : parseLineNumber(offset);\n\tif (start === undefined) return \"\";\n\tif (limit == null) return `:${start}`;\n\tconst count = parseLineNumber(limit);\n\tif (count === undefined) return \"\";\n\tconst end = start + count - 1;\n\treturn `:${start}${end ? `-${end}` : \"\"}`;\n}\n\nexport function replaceTabs(text: string): string {\n\treturn text.replace(/\\t/g, \" \");\n}\n\nexport function normalizeDisplayText(text: string): string {\n\treturn text.replace(/\\r/g, \"\");\n}\n\nexport function getTextOutput(\n\tresult: { content: Array<{ type: string; text?: string; data?: string; mimeType?: string }> } | undefined,\n\tshowImages: boolean,\n): string {\n\tif (!result) return \"\";\n\n\tconst textBlocks = result.content.filter((c) => c.type === \"text\");\n\tconst imageBlocks = result.content.filter((c) => c.type === \"image\");\n\n\tlet output = textBlocks.map((c) => sanitizeBinaryOutput(stripAnsi(c.text || \"\")).replace(/\\r/g, \"\")).join(\"\\n\");\n\n\tconst caps = getCapabilities();\n\tif (imageBlocks.length > 0 && (!caps.images || !showImages)) {\n\t\tconst imageIndicators = imageBlocks\n\t\t\t.map((img) => {\n\t\t\t\tconst mimeType = img.mimeType ?? \"image/unknown\";\n\t\t\t\tconst dims =\n\t\t\t\t\timg.data && img.mimeType ? (getImageDimensions(img.data, img.mimeType) ?? undefined) : undefined;\n\t\t\t\treturn imageFallback(mimeType, dims);\n\t\t\t})\n\t\t\t.join(\"\\n\");\n\t\toutput = output ? `${output}\\n${imageIndicators}` : imageIndicators;\n\t}\n\n\treturn output;\n}\n\nexport type ToolRenderResultLike<TDetails> = {\n\tcontent: (TextContent | ImageContent)[];\n\tdetails: TDetails;\n};\n\nconst COLLAPSED_ARGS_CHARS = 100;\n\n/**\n * Generic tool call header: the title followed by the arguments. Collapsed, they are `key=value`\n * pairs on the title line, cut to {@link COLLAPSED_ARGS_CHARS}. Expanded, each is a `key: value`\n * line below the title, with strings shown raw and continuation lines indented.\n */\nexport function formatToolCallWithArgs(title: string, args: unknown, theme: Theme, expanded: boolean): string {\n\t// (The title can come from an MCP server, the arguments from the model: sanitizeTerminalText() keeps escape sequences in\n\t// either from acting on the terminal. JSON.stringify() escapes C0 controls, but not DEL and C1 controls.)\n\tconst header = theme.fg(\"toolTitle\", theme.bold(sanitizeTerminalText(title)));\n\tif (args == null) return header;\n\tconst entries =\n\t\ttypeof args === \"object\" && !Array.isArray(args)\n\t\t\t? Object.entries(args)\n\t\t\t: ([[\"args\", args]] as [string, unknown][]);\n\tif (entries.length === 0) return header;\n\tif (expanded) {\n\t\tconst lines = entries.map(([key, value]) => {\n\t\t\tconst text = typeof value === \"string\" ? value : (JSON.stringify(value, null, 2) ?? String(value));\n\t\t\tconst shown = replaceTabs(sanitizeTerminalText(text)).replace(/\\r/g, \"\");\n\t\t\treturn ` ${sanitizeTerminalText(key)}: ${shown.split(\"\\n\").join(\"\\n \")}`;\n\t\t});\n\t\treturn `${header}\\n${theme.fg(\"muted\", lines.join(\"\\n\"))}`;\n\t}\n\tconst pairs = entries.map(([key, value]) => `${key}=${JSON.stringify(value) ?? String(value)}`).join(\" \");\n\tconst preview = pairs.length > COLLAPSED_ARGS_CHARS ? `${pairs.slice(0, COLLAPSED_ARGS_CHARS - 3)}...` : pairs;\n\treturn `${header} ${theme.fg(\"muted\", sanitizeTerminalText(preview))}`;\n}\n\n/** Duration as `4.2s` below a minute, then `1m 30s` and `2h 3m 4s`. */\nexport function formatToolDuration(ms: number): string {\n\tconst seconds = ms / 1000;\n\tif (seconds < 60) return `${seconds.toFixed(1)}s`;\n\n\tconst totalSeconds = Math.floor(seconds);\n\tconst minutes = Math.floor(totalSeconds / 60);\n\tconst remainder = totalSeconds % 60;\n\tif (minutes < 60) return `${minutes}m ${remainder}s`;\n\n\treturn `${Math.floor(minutes / 60)}h ${minutes % 60}m ${remainder}s`;\n}\n\n/** Renderer state of {@link startToolTimer} and {@link toolTimerText}, kept in `ToolRenderContext.state`. */\nexport interface ToolTimerState {\n\tstartedAt?: number;\n\tendedAt?: number;\n\tinterval?: ReturnType<typeof setInterval>;\n}\n\n/** Start the row's clock once execution starts. Call from `renderCall`. */\nexport function startToolTimer(context: ToolRenderContext<ToolTimerState>): void {\n\tconst state = context.state;\n\tif (context.executionStarted && state.startedAt === undefined) {\n\t\tstate.startedAt = Date.now();\n\t\tstate.endedAt = undefined;\n\t}\n}\n\n/**\n * Stop the row's clock for good: for a row that gets no final result (it left the transcript, or its run ended).\n * Otherwise its 1 s timer keeps asking for frames, and keeps the row alive, for the rest of the session\n * (Pi-Bolt 4adb6bb99).\n */\nexport function stopToolTimer(state: ToolTimerState): void {\n\tif (state.startedAt !== undefined) state.endedAt ??= Date.now();\n\tif (state.interval) {\n\t\tclearInterval(state.interval);\n\t\tstate.interval = undefined;\n\t}\n}\n\n/**\n * The row's timing line, from `renderResult`: `Elapsed 4.2s` while the result is partial, redrawn\n * every second, and `Took 4.2s` once it is final. Undefined when the row has no start time and no\n * recorded duration.\n */\nexport function toolTimerText(context: ToolRenderContext<ToolTimerState>, isPartial: boolean): string | undefined {\n\tconst state = context.state;\n\tif (state.startedAt !== undefined && state.endedAt === undefined && isPartial && !state.interval) {\n\t\tstate.interval = setInterval(() => context.invalidate(), 1000);\n\t}\n\tif (!isPartial || context.isError) {\n\t\tstate.endedAt ??= Date.now();\n\t\tif (state.interval) {\n\t\t\tclearInterval(state.interval);\n\t\t\tstate.interval = undefined;\n\t\t}\n\t}\n\t// A final result's recorded duration wins: it is monotonic and survives reloads. The renderer's own clock is the\n\t// fallback for live progress and for results stored without one.\n\tif (!isPartial && context.durationMs !== undefined) return `Took ${formatToolDuration(context.durationMs)}`;\n\tif (state.startedAt === undefined) return undefined;\n\tconst endTime = state.endedAt ?? Date.now();\n\treturn `${isPartial ? \"Elapsed\" : \"Took\"} ${formatToolDuration(endTime - state.startedAt)}`;\n}\n\nexport function invalidArgText(theme: Theme): string {\n\treturn theme.fg(\"error\", \"[invalid arg]\");\n}\n\nexport function renderToolPath(\n\trawPath: string | null,\n\ttheme: Theme,\n\tcwd: string,\n\toptions?: { emptyFallback?: string },\n): string {\n\tif (rawPath === null) return invalidArgText(theme);\n\tconst value = rawPath || options?.emptyFallback;\n\tif (!value) return theme.fg(\"toolOutput\", \"...\");\n\treturn linkPath(theme.fg(\"accent\", shortenPath(value)), value, cwd);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../../../src/core/tools/renderers/bash.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AAMH,OAAO,KAAK,EAAE,cAAc,EAA2B,MAAM,2BAA2B,CAAC;AAOzF,eAAO,MAAM,uBAAuB,MAAM,CAAC;AA4E3C,uGAAuG;AACvG,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,YAAY,GAAG,cAAc,CAAC,CAkBlH"}
1
+ {"version":3,"file":"bash.d.ts","sourceRoot":"","sources":["../../../../src/core/tools/renderers/bash.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AAMH,OAAO,KAAK,EAAE,cAAc,EAA2B,MAAM,2BAA2B,CAAC;AAOzF,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAiF3C,uGAAuG;AACvG,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,YAAY,GAAG,cAAc,CAAC,CAkBlH"}
@@ -27,11 +27,14 @@ function rebuildBashResultRenderComponent(component, result, options, showImages
27
27
  let output = getTextOutput(result, showImages).trim();
28
28
  const truncation = result.details?.truncation;
29
29
  const fullOutputPath = result.details?.fullOutputPath;
30
- if (!options.isPartial && truncation?.truncated && fullOutputPath && output.endsWith("]")) {
30
+ const fullOutputError = result.details?.fullOutputError;
31
+ // The model's footer names the file or why it could not be saved; the warning below says the same.
32
+ const footerMarker = fullOutputPath ?? fullOutputError;
33
+ if (!options.isPartial && truncation?.truncated && footerMarker && output.endsWith("]")) {
31
34
  const footerStart = output.lastIndexOf("\n\n[");
32
35
  if (footerStart !== -1 &&
33
36
  output.startsWith("\n\n[Showing ", footerStart) &&
34
- output.slice(footerStart).includes(fullOutputPath)) {
37
+ output.slice(footerStart).includes(footerMarker)) {
35
38
  output = output.slice(0, footerStart).trimEnd();
36
39
  }
37
40
  }
@@ -54,11 +57,14 @@ function rebuildBashResultRenderComponent(component, result, options, showImages
54
57
  }));
55
58
  }
56
59
  }
57
- if (truncation?.truncated || fullOutputPath) {
60
+ if (truncation?.truncated || fullOutputPath || fullOutputError) {
58
61
  const warnings = [];
59
62
  if (fullOutputPath) {
60
63
  warnings.push(`Full output: ${fullOutputPath}`);
61
64
  }
65
+ else if (fullOutputError) {
66
+ warnings.push(`Could not save the full output: ${fullOutputError}`);
67
+ }
62
68
  if (truncation?.truncated) {
63
69
  if (truncation.truncatedBy === "lines") {
64
70
  warnings.push(`Truncated: showing ${truncation.outputLines} of ${truncation.totalLines} lines`);