@humain/humain-code 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (650) hide show
  1. package/CHANGELOG.md +139 -0
  2. package/README.md +2 -2
  3. package/dist/bundle/agent-monitor.js +1 -1
  4. package/dist/bundle/chunks/anthropic-messages-UZB5HJE3.js +77 -0
  5. package/dist/bundle/chunks/anthropic.js +25 -24
  6. package/dist/bundle/chunks/azure-openai-responses-J3LCMWPQ.js +15 -0
  7. package/dist/bundle/chunks/bedrock-converse-stream.js +460 -431
  8. package/dist/bundle/chunks/bowser-DXKSTXFQ.js +89 -0
  9. package/dist/bundle/chunks/{chunk-HTA325LJ.js → chunk-2NVGOSBN.js} +1 -1
  10. package/dist/bundle/chunks/{chunk-5B25YXF7.js → chunk-3CGMVKHA.js} +13 -3
  11. package/dist/bundle/chunks/{chunk-SCINMV4X.js → chunk-46C6D7UC.js} +22 -21
  12. package/dist/bundle/chunks/{chunk-RS6PZK35.js → chunk-4EV7CK26.js} +249 -216
  13. package/dist/bundle/chunks/{chunk-T7BXP46S.js → chunk-4SFWYKL5.js} +1848 -1662
  14. package/dist/bundle/chunks/{chunk-TGDPZCSW.js → chunk-4TDNOR36.js} +1 -1
  15. package/dist/bundle/chunks/{chunk-C6VERWRZ.js → chunk-4XF5JX7X.js} +1 -1
  16. package/dist/bundle/chunks/chunk-6HTHDVJC.js +4 -0
  17. package/dist/bundle/chunks/{chunk-2G7YVAVF.js → chunk-7EONJCBE.js} +1 -1
  18. package/dist/bundle/chunks/chunk-7H2WNBX7.js +11 -0
  19. package/dist/bundle/chunks/{chunk-2FYYW6FY.js → chunk-7OZNMWAJ.js} +1 -1
  20. package/dist/bundle/chunks/{chunk-R6YQR7TZ.js → chunk-7WE77IE3.js} +1 -1
  21. package/dist/bundle/chunks/{chunk-Z5YLKK3S.js → chunk-7WETECIB.js} +1 -1
  22. package/dist/bundle/chunks/{chunk-EIC7CQX3.js → chunk-AI7EHDAX.js} +1 -1
  23. package/dist/bundle/chunks/{chunk-KRCX3ZBA.js → chunk-APNPBT7Y.js} +1 -1
  24. package/dist/bundle/chunks/{chunk-4HTVBBJD.js → chunk-ATFZAFMS.js} +2 -2
  25. package/dist/bundle/chunks/{chunk-R5OOX7RW.js → chunk-B47PNNLL.js} +9 -2
  26. package/dist/bundle/chunks/{chunk-AZXVJN6E.js → chunk-C4DHVDYT.js} +1 -1
  27. package/dist/bundle/chunks/{chunk-4PRNKB6V.js → chunk-CET2MXXN.js} +7 -7
  28. package/dist/bundle/chunks/{chunk-66FZJO75.js → chunk-CU6KU7JK.js} +472 -3924
  29. package/dist/bundle/chunks/{chunk-MD7K7RPN.js → chunk-D3KYOSQY.js} +1 -1
  30. package/dist/bundle/chunks/{chunk-I3NDOUHE.js → chunk-DCXHRP6C.js} +1 -1
  31. package/dist/bundle/chunks/{chunk-OB332KMV.js → chunk-DD5UT56Y.js} +46 -32
  32. package/dist/bundle/chunks/{chunk-G4QPSFBF.js → chunk-EMBIUIQ2.js} +216 -223
  33. package/dist/bundle/chunks/{chunk-Q7VXYXY3.js → chunk-ENBDASDN.js} +2 -2
  34. package/dist/bundle/chunks/{chunk-2H3LUS62.js → chunk-FJIISX5W.js} +241 -229
  35. package/dist/bundle/chunks/{chunk-WQOOJP7U.js → chunk-GV5OVRKK.js} +1 -1
  36. package/dist/bundle/chunks/{chunk-KTSJYIYC.js → chunk-HHWVVNGG.js} +1 -1
  37. package/dist/bundle/chunks/{chunk-4JRER4XK.js → chunk-HQMUDHC3.js} +19 -19
  38. package/dist/bundle/chunks/{chunk-WQ7EJQIT.js → chunk-IOLLZXQN.js} +225 -239
  39. package/dist/bundle/chunks/chunk-IXQYPQRQ.js +2079 -0
  40. package/dist/bundle/chunks/{chunk-RU7ADKA7.js → chunk-J4GII2EE.js} +112 -96
  41. package/dist/bundle/chunks/chunk-J5TSAJGC.js +22 -0
  42. package/dist/bundle/chunks/{chunk-QT6ZHDMP.js → chunk-JBSWWCT5.js} +1 -1
  43. package/dist/bundle/chunks/{chunk-P6AXBESH.js → chunk-JV7VHOAY.js} +1119 -1098
  44. package/dist/bundle/chunks/{chunk-PWUDFU5V.js → chunk-JWOPWHVH.js} +4 -4
  45. package/dist/bundle/chunks/{chunk-4V5VL2BO.js → chunk-KLSRGGOH.js} +131 -154
  46. package/dist/bundle/chunks/{chunk-JF7FYXAI.js → chunk-KONLZKPL.js} +7 -6
  47. package/dist/bundle/chunks/{chunk-32QLLD2P.js → chunk-KQXXBQ57.js} +360 -332
  48. package/dist/bundle/chunks/{chunk-UZNIPOGS.js → chunk-L4J7SMJB.js} +1 -1
  49. package/dist/bundle/chunks/chunk-MPRAQ6ZI.js +41 -0
  50. package/dist/bundle/chunks/{chunk-GUHNFZ2Q.js → chunk-NNWNIBLG.js} +20 -19
  51. package/dist/bundle/chunks/{chunk-TWAHPPXN.js → chunk-OVDMYBIT.js} +1307 -1194
  52. package/dist/bundle/chunks/{chunk-WAPZN4KP.js → chunk-P2Y2H7SD.js} +2 -2
  53. package/dist/bundle/chunks/{chunk-PPBDDQHP.js → chunk-PGVDL4KB.js} +7 -6
  54. package/dist/bundle/chunks/{chunk-XHDVDJM7.js → chunk-PVNXN2TC.js} +7 -7
  55. package/dist/bundle/chunks/{chunk-RNBZBCH2.js → chunk-QJB5YI3I.js} +1 -1
  56. package/dist/bundle/chunks/{chunk-I5E7RQ5V.js → chunk-QRYDGY5I.js} +5 -5
  57. package/dist/bundle/chunks/{chunk-4QAXV5T6.js → chunk-R3VDXQW2.js} +9 -9
  58. package/dist/bundle/chunks/chunk-SKCJ25SX.js +24 -0
  59. package/dist/bundle/chunks/chunk-SQ7NTRLJ.js +77 -0
  60. package/dist/bundle/chunks/{chunk-SSRCVJZK.js → chunk-TYN46EVI.js} +5 -5
  61. package/dist/bundle/chunks/{chunk-6E6RHNOU.js → chunk-UXM4WFLH.js} +12 -11
  62. package/dist/bundle/chunks/{chunk-LB4CIS4F.js → chunk-VCMXBP5S.js} +17 -17
  63. package/dist/bundle/chunks/{chunk-N2SNMUD3.js → chunk-VKQNYZUA.js} +1 -1
  64. package/dist/bundle/chunks/{chunk-JYWUOKOI.js → chunk-WBSGWISD.js} +367 -353
  65. package/dist/bundle/chunks/{chunk-3EDMWQ35.js → chunk-WGXMYMPE.js} +17 -15
  66. package/dist/bundle/chunks/chunk-WRYGY5XG.js +24 -0
  67. package/dist/bundle/chunks/{chunk-GRJUKEE3.js → chunk-XVIQYONJ.js} +4 -4
  68. package/dist/bundle/chunks/chunk-YSWDFV2L.js +11 -0
  69. package/dist/bundle/chunks/{chunk-AEWYICBL.js → chunk-Z5UFSRO4.js} +2 -2
  70. package/dist/bundle/chunks/chunk-ZG74NES2.js +2 -0
  71. package/dist/bundle/chunks/chunk-ZTG5OKI7.js +3 -0
  72. package/dist/bundle/chunks/{cli-H4LJNE2V.js → cli-6DJO467D.js} +2 -2
  73. package/dist/bundle/chunks/{cloudflare-workers-ai-system-one-T5R2RVFQ.js → cloudflare-workers-ai-system-one-ETKC6B2S.js} +1 -1
  74. package/dist/bundle/chunks/codemode-worker.js +68 -68
  75. package/dist/bundle/chunks/compat-HS4ARZK3.js +15 -0
  76. package/dist/bundle/chunks/curator-server-TC7RVVN2.js +3600 -0
  77. package/dist/bundle/chunks/dist-35STTNYA.js +37 -0
  78. package/dist/bundle/chunks/{dist-FMWWM4H7.js → dist-5AQPJ2TI.js} +2 -2
  79. package/dist/bundle/chunks/{dist-NHQTBDHT.js → dist-DYB3AR7C.js} +91 -257
  80. package/dist/bundle/chunks/dist-NMEXYUP3.js +11 -0
  81. package/dist/bundle/chunks/dist-cjs-EROMDUKS.js +193 -0
  82. package/dist/bundle/chunks/{easter-egg-3d-BUEOC3NO.js → easter-egg-3d-VVUF3C3X.js} +1 -1
  83. package/dist/bundle/chunks/entry-2GZ3PTWQ.js +2 -0
  84. package/dist/bundle/chunks/{entry-A2CSLKHC.js → entry-SRYLSS5P.js} +3 -3
  85. package/dist/bundle/chunks/{event-streams-7YGFEPBZ.js → event-streams-F67JLS6B.js} +1 -1
  86. package/dist/bundle/chunks/{execute-MY5JSEPV.js → execute-I3WGGPWL.js} +2 -2
  87. package/dist/bundle/chunks/{extract-PTGACPGP.js → extract-QHZTEVJP.js} +68 -65
  88. package/dist/bundle/chunks/{flow-implementer-APJFY4YI.js → flow-implementer-QMN3HKE2.js} +8 -9
  89. package/dist/bundle/chunks/github-copilot.js +55 -45
  90. package/dist/bundle/chunks/google-generative-ai-ZND73WDQ.js +22 -0
  91. package/dist/bundle/chunks/google-vertex-YAH62YRM.js +25 -0
  92. package/dist/bundle/chunks/host-Q565BCXB.js +3 -0
  93. package/dist/bundle/chunks/image-resize-worker.js +3 -3
  94. package/dist/bundle/chunks/{index.bundle-THL4EUSU.js → index.bundle-HONF3PUD.js} +177 -176
  95. package/dist/bundle/chunks/{inprocess-5NP5VJHZ.js → inprocess-453SLFL5.js} +6 -6
  96. package/dist/bundle/chunks/interactive-mode-MVZOJ5OU.js +5 -0
  97. package/dist/bundle/chunks/{llama-cpp-classify-GJAXULWL.js → llama-cpp-classify-Z4GZY4GC.js} +1 -1
  98. package/dist/bundle/chunks/mistral-conversations-7I5JURDP.js +43 -0
  99. package/dist/bundle/chunks/{node-ZFIIS5IM.js → node-IMSYVRPL.js} +53 -30
  100. package/dist/bundle/chunks/{node-UNHECG4X.js → node-MHHE76P4.js} +475 -440
  101. package/dist/bundle/chunks/{openai-codex-responses-S7CMCAOY.js → openai-codex-responses-LTHOMN37.js} +30 -29
  102. package/dist/bundle/chunks/openai-codex.js +9 -8
  103. package/dist/bundle/chunks/{openai-completions-2Z57N7PC.js → openai-completions-W2X635EE.js} +22 -22
  104. package/dist/bundle/chunks/{openai-decisions-JIOJDB4C.js → openai-decisions-TN2GNOYI.js} +1 -1
  105. package/dist/bundle/chunks/{openai-responses-5VBZSTHL.js → openai-responses-DVY4QXOG.js} +4 -5
  106. package/dist/bundle/chunks/{openrouter-images-S6O7DBEJ.js → openrouter-images-SE2JMS44.js} +1 -1
  107. package/dist/bundle/chunks/openrouter.js +9 -8
  108. package/dist/bundle/chunks/pdfjs-FE3L72A6.js +3662 -0
  109. package/dist/bundle/chunks/{pdfjs-decoders-OFXX4HDZ.js → pdfjs-decoders-VCMCTQJ2.js} +1 -1
  110. package/dist/bundle/chunks/pdfjs-jbig2_nowasm_fallback-I4K6AIV4.js +295 -0
  111. package/dist/bundle/chunks/pdfjs-openjpeg-PYQCV6CM.js +590 -0
  112. package/dist/bundle/chunks/pdfjs-openjpeg_nowasm_fallback-G363SGDI.js +775 -0
  113. package/dist/bundle/chunks/{pi-messages-SMLN5J2W.js → pi-messages-WAS6Z5L5.js} +11 -11
  114. package/dist/bundle/chunks/radius.js +8 -7
  115. package/dist/bundle/chunks/{runtime-OYTWXIUM.js → runtime-H7LYNKCZ.js} +1 -1
  116. package/dist/bundle/chunks/session-picker-XNVLSJ22.js +4 -0
  117. package/dist/bundle/chunks/startup-ui-3TCT465D.js +3 -0
  118. package/dist/bundle/chunks/{trace-command-YLDYCL55.js → trace-command-7ORDQ3JS.js} +4 -4
  119. package/dist/bundle/chunks/{typesafe-system-one-7BEL3H5N.js → typesafe-system-one-AAZH6S3I.js} +1 -1
  120. package/dist/bundle/chunks/{undici-C6S56CGI.js → undici-WVNE45GY.js} +1 -1
  121. package/dist/bundle/chunks/virtual-modules-CIVXCEAN.js +28 -0
  122. package/dist/bundle/cli-runtime.js +5 -5
  123. package/dist/bundle/flow/package.json +5 -5
  124. package/dist/bundle/index.js +13 -13
  125. package/dist/bundle/orchestrate/package.json +22 -6
  126. package/dist/bundle/rpc-entry.js +4 -5
  127. package/dist/cli/args.d.ts.map +1 -1
  128. package/dist/cli/args.js +4 -3
  129. package/dist/cli/args.js.map +1 -1
  130. package/dist/cli/config-selector.d.ts.map +1 -1
  131. package/dist/cli/config-selector.js +9 -6
  132. package/dist/cli/config-selector.js.map +1 -1
  133. package/dist/cli/session-picker.d.ts.map +1 -1
  134. package/dist/cli/session-picker.js +9 -6
  135. package/dist/cli/session-picker.js.map +1 -1
  136. package/dist/cli/startup-ui.d.ts.map +1 -1
  137. package/dist/cli/startup-ui.js +8 -4
  138. package/dist/cli/startup-ui.js.map +1 -1
  139. package/dist/cli.js.map +1 -1
  140. package/dist/core/agent-session-runtime.d.ts +11 -0
  141. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  142. package/dist/core/agent-session-runtime.js +19 -0
  143. package/dist/core/agent-session-runtime.js.map +1 -1
  144. package/dist/core/agent-session-services.d.ts +0 -2
  145. package/dist/core/agent-session-services.d.ts.map +1 -1
  146. package/dist/core/agent-session-services.js +0 -2
  147. package/dist/core/agent-session-services.js.map +1 -1
  148. package/dist/core/agent-session.d.ts +31 -39
  149. package/dist/core/agent-session.d.ts.map +1 -1
  150. package/dist/core/agent-session.js +231 -535
  151. package/dist/core/agent-session.js.map +1 -1
  152. package/dist/core/anthropic-subscription-usage.d.ts +4 -2
  153. package/dist/core/anthropic-subscription-usage.d.ts.map +1 -1
  154. package/dist/core/anthropic-subscription-usage.js +32 -16
  155. package/dist/core/anthropic-subscription-usage.js.map +1 -1
  156. package/dist/core/auto-session-namer.js +1 -1
  157. package/dist/core/auto-session-namer.js.map +1 -1
  158. package/dist/core/cache-warmer.d.ts.map +1 -1
  159. package/dist/core/cache-warmer.js +2 -0
  160. package/dist/core/cache-warmer.js.map +1 -1
  161. package/dist/core/exec.d.ts +1 -0
  162. package/dist/core/exec.d.ts.map +1 -1
  163. package/dist/core/exec.js +4 -1
  164. package/dist/core/exec.js.map +1 -1
  165. package/dist/core/export-html/ansi-to-html.d.ts +6 -1
  166. package/dist/core/export-html/ansi-to-html.d.ts.map +1 -1
  167. package/dist/core/export-html/ansi-to-html.js +57 -20
  168. package/dist/core/export-html/ansi-to-html.js.map +1 -1
  169. package/dist/core/export-html/template.js +1 -1
  170. package/dist/core/export-html/tool-renderer.d.ts.map +1 -1
  171. package/dist/core/export-html/tool-renderer.js +2 -3
  172. package/dist/core/export-html/tool-renderer.js.map +1 -1
  173. package/dist/core/extensions/loader.d.ts.map +1 -1
  174. package/dist/core/extensions/loader.js +18 -1
  175. package/dist/core/extensions/loader.js.map +1 -1
  176. package/dist/core/extensions/runner.d.ts.map +1 -1
  177. package/dist/core/extensions/runner.js +5 -0
  178. package/dist/core/extensions/runner.js.map +1 -1
  179. package/dist/core/extensions/types.d.ts +5 -0
  180. package/dist/core/extensions/types.d.ts.map +1 -1
  181. package/dist/core/extensions/types.js.map +1 -1
  182. package/dist/core/flow-implementer.d.ts.map +1 -1
  183. package/dist/core/flow-implementer.js +3 -9
  184. package/dist/core/flow-implementer.js.map +1 -1
  185. package/dist/core/keybindings.d.ts +40 -0
  186. package/dist/core/keybindings.d.ts.map +1 -1
  187. package/dist/core/keybindings.js +5 -0
  188. package/dist/core/keybindings.js.map +1 -1
  189. package/dist/core/model-config.d.ts +13 -0
  190. package/dist/core/model-config.d.ts.map +1 -1
  191. package/dist/core/model-registry.d.ts +3 -0
  192. package/dist/core/model-registry.d.ts.map +1 -1
  193. package/dist/core/model-registry.js +32 -8
  194. package/dist/core/model-registry.js.map +1 -1
  195. package/dist/core/model-resolver.d.ts +0 -1
  196. package/dist/core/model-resolver.d.ts.map +1 -1
  197. package/dist/core/model-resolver.js +3 -10
  198. package/dist/core/model-resolver.js.map +1 -1
  199. package/dist/core/model-runtime.d.ts +18 -7
  200. package/dist/core/model-runtime.d.ts.map +1 -1
  201. package/dist/core/model-runtime.js +41 -8
  202. package/dist/core/model-runtime.js.map +1 -1
  203. package/dist/core/oauth-account-pool.d.ts +5 -0
  204. package/dist/core/oauth-account-pool.d.ts.map +1 -1
  205. package/dist/core/oauth-account-pool.js +34 -3
  206. package/dist/core/oauth-account-pool.js.map +1 -1
  207. package/dist/core/package-manager.d.ts +16 -0
  208. package/dist/core/package-manager.d.ts.map +1 -1
  209. package/dist/core/package-manager.js +46 -3
  210. package/dist/core/package-manager.js.map +1 -1
  211. package/dist/core/pi-ai-schemas.d.ts +1 -0
  212. package/dist/core/pi-ai-schemas.d.ts.map +1 -1
  213. package/dist/core/remote-catalog-provider.d.ts.map +1 -1
  214. package/dist/core/remote-catalog-provider.js +7 -0
  215. package/dist/core/remote-catalog-provider.js.map +1 -1
  216. package/dist/core/resource-loader.d.ts +5 -1
  217. package/dist/core/resource-loader.d.ts.map +1 -1
  218. package/dist/core/resource-loader.js +2 -0
  219. package/dist/core/resource-loader.js.map +1 -1
  220. package/dist/core/run-outcome.d.ts +6 -3
  221. package/dist/core/run-outcome.d.ts.map +1 -1
  222. package/dist/core/run-outcome.js +36 -9
  223. package/dist/core/run-outcome.js.map +1 -1
  224. package/dist/core/run-preflight.d.ts +1 -1
  225. package/dist/core/run-preflight.d.ts.map +1 -1
  226. package/dist/core/run-preflight.js +19 -11
  227. package/dist/core/run-preflight.js.map +1 -1
  228. package/dist/core/sdk.d.ts +0 -6
  229. package/dist/core/sdk.d.ts.map +1 -1
  230. package/dist/core/sdk.js +7 -16
  231. package/dist/core/sdk.js.map +1 -1
  232. package/dist/core/settings-manager.d.ts +0 -5
  233. package/dist/core/settings-manager.d.ts.map +1 -1
  234. package/dist/core/settings-manager.js +0 -9
  235. package/dist/core/settings-manager.js.map +1 -1
  236. package/dist/core/settings-schema.d.ts +0 -4
  237. package/dist/core/settings-schema.d.ts.map +1 -1
  238. package/dist/core/settings-schema.js +0 -1
  239. package/dist/core/settings-schema.js.map +1 -1
  240. package/dist/core/tools/bash-jobs.d.ts.map +1 -1
  241. package/dist/core/tools/bash-jobs.js +2 -9
  242. package/dist/core/tools/bash-jobs.js.map +1 -1
  243. package/dist/core/tools/find.d.ts.map +1 -1
  244. package/dist/core/tools/find.js +28 -16
  245. package/dist/core/tools/find.js.map +1 -1
  246. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  247. package/dist/core/tools/output-accumulator.js +4 -1
  248. package/dist/core/tools/output-accumulator.js.map +1 -1
  249. package/dist/core/tools/read.d.ts +8 -4
  250. package/dist/core/tools/read.d.ts.map +1 -1
  251. package/dist/core/tools/read.js +10 -15
  252. package/dist/core/tools/read.js.map +1 -1
  253. package/dist/core/tools/renderers/read.d.ts.map +1 -1
  254. package/dist/core/tools/renderers/read.js +6 -2
  255. package/dist/core/tools/renderers/read.js.map +1 -1
  256. package/dist/core/tools/subagent-worktree.d.ts.map +1 -1
  257. package/dist/core/tools/subagent-worktree.js +2 -10
  258. package/dist/core/tools/subagent-worktree.js.map +1 -1
  259. package/dist/core/trace-client/credential-store.d.ts.map +1 -1
  260. package/dist/core/trace-client/credential-store.js +9 -5
  261. package/dist/core/trace-client/credential-store.js.map +1 -1
  262. package/dist/extensions/codemode/execute.js +2 -2
  263. package/dist/extensions/codemode/execute.js.map +1 -1
  264. package/dist/extensions/llama/provider.d.ts +1 -1
  265. package/dist/extensions/llama/provider.d.ts.map +1 -1
  266. package/dist/extensions/llama/provider.js +6 -4
  267. package/dist/extensions/llama/provider.js.map +1 -1
  268. package/dist/extensions/usage/account-reconnect.d.ts +5 -0
  269. package/dist/extensions/usage/account-reconnect.d.ts.map +1 -0
  270. package/dist/extensions/usage/account-reconnect.js +12 -0
  271. package/dist/extensions/usage/account-reconnect.js.map +1 -0
  272. package/dist/extensions/usage/hcode-overview.d.ts +6 -19
  273. package/dist/extensions/usage/hcode-overview.d.ts.map +1 -1
  274. package/dist/extensions/usage/hcode-overview.js +86 -100
  275. package/dist/extensions/usage/hcode-overview.js.map +1 -1
  276. package/dist/extensions/usage/index.d.ts.map +1 -1
  277. package/dist/extensions/usage/index.js +74 -98
  278. package/dist/extensions/usage/index.js.map +1 -1
  279. package/dist/extensions/usage/overview.d.ts +22 -17
  280. package/dist/extensions/usage/overview.d.ts.map +1 -1
  281. package/dist/extensions/usage/overview.js +98 -13
  282. package/dist/extensions/usage/overview.js.map +1 -1
  283. package/dist/extensions/usage/popup.d.ts +9 -14
  284. package/dist/extensions/usage/popup.d.ts.map +1 -1
  285. package/dist/extensions/usage/popup.js +78 -165
  286. package/dist/extensions/usage/popup.js.map +1 -1
  287. package/dist/humain/bedrock-provider/vendor/index.bundle.mjs +4 -1
  288. package/dist/humain/flow-command.js +1 -1
  289. package/dist/humain/flow-command.js.map +1 -1
  290. package/dist/humain/flow-loader.d.ts +9 -4
  291. package/dist/humain/flow-loader.d.ts.map +1 -1
  292. package/dist/humain/flow-loader.js +30 -21
  293. package/dist/humain/flow-loader.js.map +1 -1
  294. package/dist/humain/gateway/client.d.ts +3 -1
  295. package/dist/humain/gateway/client.d.ts.map +1 -1
  296. package/dist/humain/gateway/client.js +10 -5
  297. package/dist/humain/gateway/client.js.map +1 -1
  298. package/dist/humain/gateway/login.d.ts.map +1 -1
  299. package/dist/humain/gateway/login.js +160 -53
  300. package/dist/humain/gateway/login.js.map +1 -1
  301. package/dist/humain/hcode/account-store.d.ts +29 -5
  302. package/dist/humain/hcode/account-store.d.ts.map +1 -1
  303. package/dist/humain/hcode/account-store.js +224 -124
  304. package/dist/humain/hcode/account-store.js.map +1 -1
  305. package/dist/humain/hcode/account.d.ts +6 -0
  306. package/dist/humain/hcode/account.d.ts.map +1 -1
  307. package/dist/humain/hcode/account.js +348 -129
  308. package/dist/humain/hcode/account.js.map +1 -1
  309. package/dist/humain/hcode/catalog-watch.d.ts +21 -0
  310. package/dist/humain/hcode/catalog-watch.d.ts.map +1 -0
  311. package/dist/humain/hcode/catalog-watch.js +46 -0
  312. package/dist/humain/hcode/catalog-watch.js.map +1 -0
  313. package/dist/humain/hcode/contracts.d.ts +16 -1
  314. package/dist/humain/hcode/contracts.d.ts.map +1 -1
  315. package/dist/humain/hcode/contracts.js +122 -128
  316. package/dist/humain/hcode/contracts.js.map +1 -1
  317. package/dist/humain/hcode/environment.d.ts +3 -1
  318. package/dist/humain/hcode/environment.d.ts.map +1 -1
  319. package/dist/humain/hcode/environment.js +12 -2
  320. package/dist/humain/hcode/environment.js.map +1 -1
  321. package/dist/humain/hcode/facade.d.ts +26 -6
  322. package/dist/humain/hcode/facade.d.ts.map +1 -1
  323. package/dist/humain/hcode/facade.js +148 -38
  324. package/dist/humain/hcode/facade.js.map +1 -1
  325. package/dist/humain/hcode/http.d.ts +3 -1
  326. package/dist/humain/hcode/http.d.ts.map +1 -1
  327. package/dist/humain/hcode/http.js +44 -23
  328. package/dist/humain/hcode/http.js.map +1 -1
  329. package/dist/humain/hcode/images.d.ts +67 -0
  330. package/dist/humain/hcode/images.d.ts.map +1 -0
  331. package/dist/humain/hcode/images.js +463 -0
  332. package/dist/humain/hcode/images.js.map +1 -0
  333. package/dist/humain/hcode/login-copy.d.ts +28 -0
  334. package/dist/humain/hcode/login-copy.d.ts.map +1 -0
  335. package/dist/humain/hcode/login-copy.js +74 -0
  336. package/dist/humain/hcode/login-copy.js.map +1 -0
  337. package/dist/humain/hcode/login-failure.d.ts +26 -0
  338. package/dist/humain/hcode/login-failure.d.ts.map +1 -0
  339. package/dist/humain/hcode/login-failure.js +50 -0
  340. package/dist/humain/hcode/login-failure.js.map +1 -0
  341. package/dist/humain/hcode/notices.d.ts +24 -1
  342. package/dist/humain/hcode/notices.d.ts.map +1 -1
  343. package/dist/humain/hcode/notices.js +93 -7
  344. package/dist/humain/hcode/notices.js.map +1 -1
  345. package/dist/humain/hcode/provider.d.ts +7 -3
  346. package/dist/humain/hcode/provider.d.ts.map +1 -1
  347. package/dist/humain/hcode/provider.js +123 -19
  348. package/dist/humain/hcode/provider.js.map +1 -1
  349. package/dist/humain/hcode/selection.d.ts +2 -0
  350. package/dist/humain/hcode/selection.d.ts.map +1 -1
  351. package/dist/humain/hcode/selection.js +8 -1
  352. package/dist/humain/hcode/selection.js.map +1 -1
  353. package/dist/humain/hcode/transport.d.ts +13 -10
  354. package/dist/humain/hcode/transport.d.ts.map +1 -1
  355. package/dist/humain/hcode/transport.js +103 -148
  356. package/dist/humain/hcode/transport.js.map +1 -1
  357. package/dist/humain/hcode/wire.d.ts +3 -0
  358. package/dist/humain/hcode/wire.d.ts.map +1 -1
  359. package/dist/humain/hcode/wire.js +11 -0
  360. package/dist/humain/hcode/wire.js.map +1 -1
  361. package/dist/humain/metadata/contracts.d.ts +1 -0
  362. package/dist/humain/metadata/contracts.d.ts.map +1 -1
  363. package/dist/humain/metadata/contracts.js +2 -1
  364. package/dist/humain/metadata/contracts.js.map +1 -1
  365. package/dist/humain/web-access/vendor/anysearch.d.ts.map +1 -1
  366. package/dist/humain/web-access/vendor/anysearch.js +7 -3
  367. package/dist/humain/web-access/vendor/anysearch.js.map +1 -1
  368. package/dist/humain/web-access/vendor/autom.d.ts +4 -0
  369. package/dist/humain/web-access/vendor/autom.d.ts.map +1 -0
  370. package/dist/humain/web-access/vendor/autom.js +191 -0
  371. package/dist/humain/web-access/vendor/autom.js.map +1 -0
  372. package/dist/humain/web-access/vendor/cloro.d.ts +4 -0
  373. package/dist/humain/web-access/vendor/cloro.d.ts.map +1 -0
  374. package/dist/humain/web-access/vendor/cloro.js +236 -0
  375. package/dist/humain/web-access/vendor/cloro.js.map +1 -0
  376. package/dist/humain/web-access/vendor/curator-page.d.ts.map +1 -1
  377. package/dist/humain/web-access/vendor/curator-page.js +7 -1
  378. package/dist/humain/web-access/vendor/curator-page.js.map +1 -1
  379. package/dist/humain/web-access/vendor/curator-server.d.ts.map +1 -1
  380. package/dist/humain/web-access/vendor/curator-server.js +6 -0
  381. package/dist/humain/web-access/vendor/curator-server.js.map +1 -1
  382. package/dist/humain/web-access/vendor/domain-filter-normalization.d.ts +8 -0
  383. package/dist/humain/web-access/vendor/domain-filter-normalization.d.ts.map +1 -1
  384. package/dist/humain/web-access/vendor/domain-filter-normalization.js +37 -0
  385. package/dist/humain/web-access/vendor/domain-filter-normalization.js.map +1 -1
  386. package/dist/humain/web-access/vendor/duckduckgo-rate-limit.d.ts +28 -8
  387. package/dist/humain/web-access/vendor/duckduckgo-rate-limit.d.ts.map +1 -1
  388. package/dist/humain/web-access/vendor/duckduckgo-rate-limit.js +135 -34
  389. package/dist/humain/web-access/vendor/duckduckgo-rate-limit.js.map +1 -1
  390. package/dist/humain/web-access/vendor/duckduckgo.d.ts +1 -1
  391. package/dist/humain/web-access/vendor/duckduckgo.d.ts.map +1 -1
  392. package/dist/humain/web-access/vendor/duckduckgo.js +10 -3
  393. package/dist/humain/web-access/vendor/duckduckgo.js.map +1 -1
  394. package/dist/humain/web-access/vendor/extract.d.ts.map +1 -1
  395. package/dist/humain/web-access/vendor/extract.js +61 -5
  396. package/dist/humain/web-access/vendor/extract.js.map +1 -1
  397. package/dist/humain/web-access/vendor/gemini-search.d.ts +3 -3
  398. package/dist/humain/web-access/vendor/gemini-search.d.ts.map +1 -1
  399. package/dist/humain/web-access/vendor/gemini-search.js +35 -5
  400. package/dist/humain/web-access/vendor/gemini-search.js.map +1 -1
  401. package/dist/humain/web-access/vendor/index.d.ts.map +1 -1
  402. package/dist/humain/web-access/vendor/index.js +8 -1
  403. package/dist/humain/web-access/vendor/index.js.map +1 -1
  404. package/dist/humain/web-access/vendor/page-query.d.ts +5 -0
  405. package/dist/humain/web-access/vendor/page-query.d.ts.map +1 -1
  406. package/dist/humain/web-access/vendor/page-query.js +12 -2
  407. package/dist/humain/web-access/vendor/page-query.js.map +1 -1
  408. package/dist/humain/web-access/vendor/specstream.d.ts +6 -0
  409. package/dist/humain/web-access/vendor/specstream.d.ts.map +1 -0
  410. package/dist/humain/web-access/vendor/specstream.js +253 -0
  411. package/dist/humain/web-access/vendor/specstream.js.map +1 -0
  412. package/dist/humain/web-access/vendor/tool-activation.d.ts.map +1 -1
  413. package/dist/humain/web-access/vendor/tool-activation.js +21 -5
  414. package/dist/humain/web-access/vendor/tool-activation.js.map +1 -1
  415. package/dist/humain/web-access/vendor/upgrade-notice.d.ts +1 -1
  416. package/dist/humain/web-access/vendor/upgrade-notice.js +1 -1
  417. package/dist/humain/web-access/vendor/upgrade-notice.js.map +1 -1
  418. package/dist/humain/web-access/vendor/utils.d.ts +1 -0
  419. package/dist/humain/web-access/vendor/utils.d.ts.map +1 -1
  420. package/dist/humain/web-access/vendor/utils.js +3 -0
  421. package/dist/humain/web-access/vendor/utils.js.map +1 -1
  422. package/dist/humain/web-access/vendor/video-extract.js +2 -2
  423. package/dist/humain/web-access/vendor/video-extract.js.map +1 -1
  424. package/dist/humain/web-access/vendor/web-tool-core.d.ts +13 -0
  425. package/dist/humain/web-access/vendor/web-tool-core.d.ts.map +1 -1
  426. package/dist/humain/web-access/vendor/web-tool-core.js +16 -5
  427. package/dist/humain/web-access/vendor/web-tool-core.js.map +1 -1
  428. package/dist/humain/web-access/vendor/youtube-extract.js +2 -2
  429. package/dist/humain/web-access/vendor/youtube-extract.js.map +1 -1
  430. package/dist/index.d.ts +0 -2
  431. package/dist/index.d.ts.map +1 -1
  432. package/dist/index.js.map +1 -1
  433. package/dist/main.d.ts.map +1 -1
  434. package/dist/main.js +96 -28
  435. package/dist/main.js.map +1 -1
  436. package/dist/modes/diagnostics-stderr.d.ts +4 -0
  437. package/dist/modes/diagnostics-stderr.d.ts.map +1 -0
  438. package/dist/modes/diagnostics-stderr.js +11 -0
  439. package/dist/modes/diagnostics-stderr.js.map +1 -0
  440. package/dist/modes/interactive/components/assistant-message.d.ts +1 -1
  441. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  442. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  443. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  444. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  445. package/dist/modes/interactive/components/config-selector.js +5 -2
  446. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  447. package/dist/modes/interactive/components/extension-selector.d.ts.map +1 -1
  448. package/dist/modes/interactive/components/extension-selector.js +14 -5
  449. package/dist/modes/interactive/components/extension-selector.js.map +1 -1
  450. package/dist/modes/interactive/components/first-time-setup.d.ts +1 -1
  451. package/dist/modes/interactive/components/first-time-setup.d.ts.map +1 -1
  452. package/dist/modes/interactive/components/first-time-setup.js.map +1 -1
  453. package/dist/modes/interactive/components/keybinding-hints.d.ts +2 -0
  454. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
  455. package/dist/modes/interactive/components/keybinding-hints.js +6 -0
  456. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
  457. package/dist/modes/interactive/components/model-selector.d.ts +10 -0
  458. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  459. package/dist/modes/interactive/components/model-selector.js +101 -23
  460. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  461. package/dist/modes/interactive/components/oauth-selector.d.ts +5 -0
  462. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  463. package/dist/modes/interactive/components/oauth-selector.js +17 -6
  464. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  465. package/dist/modes/interactive/components/radius-login-selector.d.ts.map +1 -1
  466. package/dist/modes/interactive/components/radius-login-selector.js +2 -1
  467. package/dist/modes/interactive/components/radius-login-selector.js.map +1 -1
  468. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  469. package/dist/modes/interactive/components/scoped-models-selector.js +13 -6
  470. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  471. package/dist/modes/interactive/components/session-selector.d.ts +8 -1
  472. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  473. package/dist/modes/interactive/components/session-selector.js +41 -9
  474. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  475. package/dist/modes/interactive/components/settings-submenu.d.ts +1 -1
  476. package/dist/modes/interactive/components/settings-submenu.d.ts.map +1 -1
  477. package/dist/modes/interactive/components/settings-submenu.js +5 -1
  478. package/dist/modes/interactive/components/settings-submenu.js.map +1 -1
  479. package/dist/modes/interactive/components/status-indicator.d.ts +0 -17
  480. package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
  481. package/dist/modes/interactive/components/status-indicator.js +1 -78
  482. package/dist/modes/interactive/components/status-indicator.js.map +1 -1
  483. package/dist/modes/interactive/components/themed-text.d.ts +1 -1
  484. package/dist/modes/interactive/components/themed-text.d.ts.map +1 -1
  485. package/dist/modes/interactive/components/themed-text.js.map +1 -1
  486. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
  487. package/dist/modes/interactive/components/thinking-selector.js +5 -1
  488. package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
  489. package/dist/modes/interactive/components/tool-execution.d.ts +1 -1
  490. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  491. package/dist/modes/interactive/components/tool-execution.js +3 -1
  492. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  493. package/dist/modes/interactive/components/trust-selector.d.ts.map +1 -1
  494. package/dist/modes/interactive/components/trust-selector.js +14 -5
  495. package/dist/modes/interactive/components/trust-selector.js.map +1 -1
  496. package/dist/modes/interactive/components/user-message.d.ts +1 -1
  497. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  498. package/dist/modes/interactive/components/user-message.js.map +1 -1
  499. package/dist/modes/interactive/components/visual-truncate.d.ts +2 -2
  500. package/dist/modes/interactive/components/visual-truncate.d.ts.map +1 -1
  501. package/dist/modes/interactive/components/visual-truncate.js.map +1 -1
  502. package/dist/modes/interactive/interactive-mode.d.ts +20 -2
  503. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  504. package/dist/modes/interactive/interactive-mode.js +605 -223
  505. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  506. package/dist/modes/interactive/model-catalog-refresh.d.ts +4 -0
  507. package/dist/modes/interactive/model-catalog-refresh.d.ts.map +1 -1
  508. package/dist/modes/interactive/model-catalog-refresh.js +40 -1
  509. package/dist/modes/interactive/model-catalog-refresh.js.map +1 -1
  510. package/dist/modes/interactive/oauth-account-format.d.ts +6 -2
  511. package/dist/modes/interactive/oauth-account-format.d.ts.map +1 -1
  512. package/dist/modes/interactive/oauth-account-format.js +12 -3
  513. package/dist/modes/interactive/oauth-account-format.js.map +1 -1
  514. package/dist/modes/interactive/session-share.js +2 -0
  515. package/dist/modes/interactive/session-share.js.map +1 -1
  516. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  517. package/dist/modes/interactive/theme/theme.js +1 -0
  518. package/dist/modes/interactive/theme/theme.js.map +1 -1
  519. package/dist/modes/print-mode.d.ts.map +1 -1
  520. package/dist/modes/print-mode.js +30 -32
  521. package/dist/modes/print-mode.js.map +1 -1
  522. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  523. package/dist/modes/rpc/rpc-mode.js +26 -39
  524. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  525. package/dist/modes/rpc/rpc-types.d.ts +1 -0
  526. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  527. package/dist/modes/rpc/rpc-types.js.map +1 -1
  528. package/dist/package-manager-cli.d.ts.map +1 -1
  529. package/dist/package-manager-cli.js +14 -1
  530. package/dist/package-manager-cli.js.map +1 -1
  531. package/dist/utils/abort.d.ts +5 -0
  532. package/dist/utils/abort.d.ts.map +1 -1
  533. package/dist/utils/abort.js +9 -0
  534. package/dist/utils/abort.js.map +1 -1
  535. package/dist/utils/changelog.d.ts.map +1 -1
  536. package/dist/utils/changelog.js +3 -2
  537. package/dist/utils/changelog.js.map +1 -1
  538. package/dist/utils/flush-stdout.d.ts +8 -0
  539. package/dist/utils/flush-stdout.d.ts.map +1 -0
  540. package/dist/utils/flush-stdout.js +23 -0
  541. package/dist/utils/flush-stdout.js.map +1 -0
  542. package/dist/utils/image-process.d.ts +2 -0
  543. package/dist/utils/image-process.d.ts.map +1 -1
  544. package/dist/utils/image-process.js +3 -3
  545. package/dist/utils/image-process.js.map +1 -1
  546. package/dist/utils/image-resize-core.js +2 -2
  547. package/dist/utils/image-resize-core.js.map +1 -1
  548. package/dist/utils/shell.d.ts +2 -0
  549. package/dist/utils/shell.d.ts.map +1 -1
  550. package/dist/utils/shell.js +19 -0
  551. package/dist/utils/shell.js.map +1 -1
  552. package/docs/cli.md +1 -1
  553. package/docs/development.md +0 -13
  554. package/docs/extensions.md +6 -4
  555. package/docs/flow.md +4 -62
  556. package/docs/humain-code-forge-architecture.md +1 -47
  557. package/docs/humain-code-forge-flow-walkthrough.md +1 -1
  558. package/docs/humain-code.md +1 -1
  559. package/docs/keybindings.md +2 -0
  560. package/docs/llama-cpp.md +5 -5
  561. package/docs/models-configuration.md +4 -2
  562. package/docs/nvidia-rtx-llama-cpp.md +5 -5
  563. package/docs/providers.md +14 -9
  564. package/docs/rpc-commands.md +1 -1
  565. package/docs/run-preflight.md +1 -1
  566. package/docs/slash-commands.md +1 -1
  567. package/docs/tui.md +2 -0
  568. package/examples/README.md +0 -3
  569. package/examples/extensions/custom-provider-anthropic/package-lock.json +4 -4
  570. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  571. package/examples/extensions/gondolin/index.ts +4 -7
  572. package/examples/tsconfig.json +96 -76
  573. package/npm-shrinkwrap.json +285 -764
  574. package/package.json +24 -37
  575. package/schemas/keybindings.schema.json +20 -0
  576. package/schemas/models.schema.json +5 -1
  577. package/schemas/settings.schema.json +0 -13
  578. package/src/humain/web-access/UPSTREAM.md +52 -1
  579. package/src/humain/web-access/upstream.json +5 -5
  580. package/src/humain/web-access/vendor/CHANGELOG.md +29 -0
  581. package/dist/bundle/chunks/adaptive-peer-worker-X2ZNZE3S.js +0 -8
  582. package/dist/bundle/chunks/adaptive-session-host-7KDSQV5I.js +0 -162
  583. package/dist/bundle/chunks/anthropic-messages-TQK3FUV3.js +0 -68
  584. package/dist/bundle/chunks/azure-openai-responses-JY7OSLH2.js +0 -15
  585. package/dist/bundle/chunks/chunk-5L4PBYC7.js +0 -11
  586. package/dist/bundle/chunks/chunk-6PNQYO6A.js +0 -10
  587. package/dist/bundle/chunks/chunk-CRN54O4D.js +0 -24
  588. package/dist/bundle/chunks/chunk-CTU2ECLD.js +0 -7
  589. package/dist/bundle/chunks/chunk-DBL35X7L.js +0 -3
  590. package/dist/bundle/chunks/chunk-GME4AWDG.js +0 -23
  591. package/dist/bundle/chunks/chunk-GTILMMUF.js +0 -12
  592. package/dist/bundle/chunks/chunk-J57HOSWD.js +0 -21
  593. package/dist/bundle/chunks/chunk-KQM7ZGL6.js +0 -11
  594. package/dist/bundle/chunks/chunk-MX4Q4W6H.js +0 -214
  595. package/dist/bundle/chunks/chunk-NXA6NEHE.js +0 -54
  596. package/dist/bundle/chunks/chunk-PJACZCIR.js +0 -2
  597. package/dist/bundle/chunks/chunk-T5A6T24H.js +0 -93
  598. package/dist/bundle/chunks/chunk-WCFHG6NO.js +0 -16
  599. package/dist/bundle/chunks/chunk-ZJUU6WOV.js +0 -2052
  600. package/dist/bundle/chunks/compat-ZK2DIW3P.js +0 -15
  601. package/dist/bundle/chunks/dist-EY7YKQHB.js +0 -11
  602. package/dist/bundle/chunks/dist-J5IUPLMH.js +0 -37
  603. package/dist/bundle/chunks/dist-cjs-2SKN226B.js +0 -184
  604. package/dist/bundle/chunks/entry-AL54ZGYO.js +0 -2
  605. package/dist/bundle/chunks/es5-GYTRHFKS.js +0 -77
  606. package/dist/bundle/chunks/google-generative-ai-UL7YEQ6J.js +0 -21
  607. package/dist/bundle/chunks/google-vertex-OTMSPUYH.js +0 -26
  608. package/dist/bundle/chunks/host-75YAHLDR.js +0 -3
  609. package/dist/bundle/chunks/interactive-mode-IW4PIVAQ.js +0 -5
  610. package/dist/bundle/chunks/mistral-conversations-E72Y6OC3.js +0 -43
  611. package/dist/bundle/chunks/pdfjs-AKD6EBKN.js +0 -3614
  612. package/dist/bundle/chunks/pdfjs-jbig2_nowasm_fallback-FH3KJM4H.js +0 -326
  613. package/dist/bundle/chunks/pdfjs-openjpeg-SKR7C34X.js +0 -671
  614. package/dist/bundle/chunks/pdfjs-openjpeg_nowasm_fallback-VUBL7UEE.js +0 -974
  615. package/dist/bundle/chunks/session-picker-DM6S37IF.js +0 -4
  616. package/dist/bundle/chunks/startup-ui-4GGLWNSU.js +0 -3
  617. package/dist/bundle/chunks/virtual-modules-TI3W24YL.js +0 -28
  618. package/dist/core/internal-process.d.ts +0 -23
  619. package/dist/core/internal-process.d.ts.map +0 -1
  620. package/dist/core/internal-process.js +0 -88
  621. package/dist/core/internal-process.js.map +0 -1
  622. package/dist/humain/adaptive-execution.d.ts +0 -51
  623. package/dist/humain/adaptive-execution.d.ts.map +0 -1
  624. package/dist/humain/adaptive-execution.js +0 -100
  625. package/dist/humain/adaptive-execution.js.map +0 -1
  626. package/dist/humain/adaptive-peer-process.d.ts +0 -44
  627. package/dist/humain/adaptive-peer-process.d.ts.map +0 -1
  628. package/dist/humain/adaptive-peer-process.js +0 -159
  629. package/dist/humain/adaptive-peer-process.js.map +0 -1
  630. package/dist/humain/adaptive-peer-worker.d.ts +0 -3
  631. package/dist/humain/adaptive-peer-worker.d.ts.map +0 -1
  632. package/dist/humain/adaptive-peer-worker.js +0 -122
  633. package/dist/humain/adaptive-peer-worker.js.map +0 -1
  634. package/dist/humain/adaptive-runtime-types.d.ts +0 -621
  635. package/dist/humain/adaptive-runtime-types.d.ts.map +0 -1
  636. package/dist/humain/adaptive-runtime-types.js +0 -3
  637. package/dist/humain/adaptive-runtime-types.js.map +0 -1
  638. package/dist/humain/adaptive-session-host.d.ts +0 -113
  639. package/dist/humain/adaptive-session-host.d.ts.map +0 -1
  640. package/dist/humain/adaptive-session-host.js +0 -1838
  641. package/dist/humain/adaptive-session-host.js.map +0 -1
  642. package/dist/utils/deprecation.d.ts +0 -4
  643. package/dist/utils/deprecation.d.ts.map +0 -1
  644. package/dist/utils/deprecation.js +0 -13
  645. package/dist/utils/deprecation.js.map +0 -1
  646. package/examples/plugins/pi-example-plugin/README.md +0 -38
  647. package/examples/plugins/pi-example-plugin/package.json +0 -10
  648. package/examples/plugins/pi-example-plugin/src/contract.ts +0 -13
  649. package/examples/plugins/pi-example-plugin/src/session.ts +0 -24
  650. package/examples/plugins/pi-example-plugin/src/tui.ts +0 -31
@@ -14,18 +14,16 @@
14
14
  * Modes use this class and add their own I/O layer on top.
15
15
  */
16
16
  import { AsyncLocalStorage } from "node:async_hooks";
17
- import { createHash, randomUUID } from "node:crypto";
17
+ import { randomUUID } from "node:crypto";
18
18
  import { readFileSync } from "node:fs";
19
19
  import { basename, dirname } from "node:path";
20
20
  import { runToolCall, } from "@earendil-works/pi-agent-core";
21
- import { contentText, getAssistantRetryDelayMs, getCurrentSystemMessage, getCurrentSystemPrompt, getCurrentTools, getToolStateChanges, normalizeContext, retryDelayMs, } from "@earendil-works/pi-ai";
21
+ import { contentText, getAssistantRetryDelayMs, getCurrentSystemMessage, getCurrentSystemPrompt, getCurrentTools, retryDelayMs, } from "@earendil-works/pi-ai";
22
22
  import { clampThinkingLevel, cleanupSessionResources, getSupportedThinkingLevels, isContextOverflow, isRecoverableLength, isRetryableAssistantError, modelsAreEqual, resetApiProviders, streamSimple, } from "@earendil-works/pi-ai/compat";
23
- import { adaptiveEvidenceLines, adaptiveStatusText, presentAdaptiveChecklist, selectExecutionEngine, } from "../humain/adaptive-execution.js";
24
23
  import { HUMAIN_OBSERVER_EXTENSION_PATHS } from "../humain/bundled-extension-names.js";
25
- import { loadAdaptiveExecutionHost } from "../humain/flow-loader.js";
26
24
  import { HCODE_PROVIDER } from "../humain/hcode/http.js";
27
- import { assertHcodeSelection, captureHcodeSelection, HCODE_SELECTION_CHANGED_MESSAGE, HCODE_UNSUPPORTED_THINKING_MESSAGE, hcodeSelectionUnavailable, } from "../humain/hcode/selection.js";
28
- import { validateHcodeImages } from "../humain/hcode/transport.js";
25
+ import { fitHcodeImages, hcodeActivePrompts, hcodeImageMessage, hcodeImageOmissionNotice, observeHcodeImageOmissions, validateHcodeImages, } from "../humain/hcode/images.js";
26
+ import { assertHcodeSelection, captureHcodeSelection, HCODE_SELECTION_CHANGED_MESSAGE, HCODE_UNSUPPORTED_THINKING_MESSAGE, } from "../humain/hcode/selection.js";
29
27
  import { getNodeAccountFailure, } from "../humain/node-account-failure.js";
30
28
  import { formatNodeSwitchNotice, isNodeFallbackTarget, NODE_FALLBACK_NONE_MESSAGE, nodeFailureExhaustedUntil, } from "../humain/node-account-fallback.js";
31
29
  import { HUMAIN_NODE_BASE_URL_ENV, HUMAIN_NODE_PROVIDER } from "../humain/node-provider.js";
@@ -65,7 +63,7 @@ import { BUILTIN_PATH_PREFIX, createSyntheticSourceInfo, isSyntheticPath } from
65
63
  import { buildSystemPrompt, buildSystemPromptSections, diffSystemPromptSections, normalizeBuildSystemPromptOptions, } from "./system-prompt.js";
66
64
  import { createLocalBashOperations, getBashToolOwner } from "./tools/bash.js";
67
65
  import { BashJobManager } from "./tools/bash-jobs.js";
68
- import { createAllToolDefinitions, createJobsToolDefinition } from "./tools/index.js";
66
+ import { createAllToolDefinitions } from "./tools/index.js";
69
67
  import { createToolDefinitionFromAgentTool } from "./tools/tool-definition-wrapper.js";
70
68
  import { UsageLedger } from "./usage-ledger.js";
71
69
  import { addUsageToTotals, combineUsage, createUsageTotals, getSessionUsage } from "./usage-totals.js";
@@ -193,6 +191,11 @@ export class AgentSession {
193
191
  _scopedModels;
194
192
  _preparedImageRoute;
195
193
  _queuedUserInputs = new WeakSet();
194
+ _freshImageInputs = new WeakSet();
195
+ _pendingImageEntries = new Set();
196
+ _rejectedImageEntries = new Set();
197
+ _activeImageEntries = [];
198
+ _managedImageRequest;
196
199
  _disposed = false;
197
200
  _modelSelectionRevision = 0;
198
201
  _autoEffortInteractive = false;
@@ -269,7 +272,7 @@ export class AgentSession {
269
272
  _contextEstimate;
270
273
  // Bash execution state
271
274
  _bashAbortControllers = new Set();
272
- _bashJobs = new BashJobManager({ getRunContext: () => this._adaptiveHost?.runContext });
275
+ _bashJobs = new BashJobManager();
273
276
  // Retain replaced/reloaded owners too: removing a declaration does not stop its effects.
274
277
  _bashJobOwners = new Set([this._bashJobs]);
275
278
  _pendingBashMessages = [];
@@ -297,9 +300,11 @@ export class AgentSession {
297
300
  /**
298
301
  * Tools of the restored or reloaded loadout that are not registered yet, such as tools of MCP
299
302
  * servers that are still connecting. They are activated when they are registered, and dropped when
300
- * `setActiveToolsByName()` deactivates a tool or the next agent run starts.
303
+ * `setActiveToolsByName()` deactivates a tool of that loadout or the next agent run starts.
301
304
  */
302
305
  _pendingToolNames = new Set();
306
+ /** The restored or reloaded loadout that `_pendingToolNames` belongs to. */
307
+ _restoredToolNames = new Set();
303
308
  _usesDefaultTools;
304
309
  _defaultToolModifiers;
305
310
  /** Matches the `--tools` entries: tool names or patterns. */
@@ -319,6 +324,8 @@ export class AgentSession {
319
324
  _extensionShutdownHandler;
320
325
  _extensionErrorListener;
321
326
  _extensionErrorUnsubscriber;
327
+ // Set by bindExtensions(): reload() restarts extensions only if the host started them.
328
+ _extensionsBound = false;
322
329
  _modelRuntime;
323
330
  _runPreflight;
324
331
  _usageLedger = UsageLedger.fromEnvironment();
@@ -341,64 +348,12 @@ export class AgentSession {
341
348
  _toolDefinitions = new Map();
342
349
  _toolPromptSnippets = new Map();
343
350
  _toolPromptGuidelines = new Map();
344
- _executionEngineOption;
345
- _adaptiveOptions;
346
- _restoredExecutionEngine;
347
- _adaptiveRecoveryRead = false;
348
- _runExecutionEngine;
349
- _adaptiveHost;
350
- _adaptivePeerTransformContext;
351
- _adaptivePeerPrepareRequest;
352
- _adaptiveCompletion;
353
- _adaptiveSeal;
354
- _adaptiveLegacyJobs;
355
- _adaptiveAdmissionScope = new AsyncLocalStorage();
356
- /** Selection is immutable while a run is owned; saved legacy context is never promoted. */
357
- get executionEngine() {
358
- return (this._runExecutionEngine ??
359
- (this._restoredExecutionEngine === "adaptive-v2" && this._adaptiveRecoveryRead
360
- ? undefined
361
- : this._restoredExecutionEngine) ??
362
- this._executionEngineOption ??
363
- this.settingsManager.getExecutionEngine());
364
- }
365
- /** Evidence-bound local result, shared unchanged by SDK, print, JSON and RPC. */
366
- get adaptiveCompletion() {
367
- return this._adaptiveCompletion;
368
- }
369
351
  _includeHarnessDocs;
370
352
  _baseSystemPromptOptions;
371
353
  /** Prompt options after before_agent_start mutations for the active run. */
372
354
  _runSystemPromptOptions;
373
355
  _timeLimit;
374
356
  constructor(config) {
375
- if (config.executionEngine !== undefined)
376
- selectExecutionEngine(config.executionEngine);
377
- else
378
- config.settingsManager.getExecutionEngine();
379
- if (config.adaptiveExecution !== undefined &&
380
- (!config.adaptiveExecution ||
381
- typeof config.adaptiveExecution !== "object" ||
382
- Array.isArray(config.adaptiveExecution)))
383
- throw new Error("Invalid adaptive execution options");
384
- this._executionEngineOption = config.executionEngine;
385
- this._adaptiveOptions =
386
- config.adaptiveExecution === undefined ? undefined : structuredClone(config.adaptiveExecution);
387
- const saved = config.sessionManager.getBranch();
388
- const selection = saved.findLast((entry) => entry.type === "custom" && entry.customType === "execution-engine");
389
- if (selection?.type === "custom") {
390
- if (!selection.data ||
391
- typeof selection.data !== "object" ||
392
- !("version" in selection.data) ||
393
- selection.data.version !== 1 ||
394
- !("engine" in selection.data))
395
- throw new Error("Invalid persisted execution engine selection");
396
- this._restoredExecutionEngine = selectExecutionEngine(selection.data.engine);
397
- }
398
- else if (saved.some((entry) => entry.type === "custom" && entry.customType === "adaptive-engine-snapshot"))
399
- this._restoredExecutionEngine = "adaptive-v2";
400
- else if (saved.some((entry) => entry.type === "message"))
401
- this._restoredExecutionEngine = "legacy";
402
357
  validateTimeLimitSeconds(config.timeLimitSeconds);
403
358
  if (config.timeLimitSeconds !== undefined) {
404
359
  this._timeLimit = {
@@ -409,9 +364,6 @@ export class AgentSession {
409
364
  };
410
365
  }
411
366
  this.agent = config.agent;
412
- // Capture caller/SDK policy before primary-only projection, compaction and forced-prompt wrappers.
413
- this._adaptivePeerTransformContext = config.agent.transformContext;
414
- this._adaptivePeerPrepareRequest = config.agent.prepareRequest;
415
367
  this.sessionManager = config.sessionManager;
416
368
  this.settingsManager = config.settingsManager;
417
369
  this._scopedModels = config.scopedModels ?? [];
@@ -493,6 +445,48 @@ export class AgentSession {
493
445
  effective = effective.filter((message) => message.timestamp !== pending.timestamp);
494
446
  }
495
447
  }
448
+ const request = this._managedImageRequest;
449
+ this._managedImageRequest = undefined;
450
+ this._pendingImageEntries.clear();
451
+ if (request) {
452
+ const fresh = new Set();
453
+ const rejected = new Set();
454
+ this._activeImageEntries = [];
455
+ for (const input of request.inputs) {
456
+ let present = false;
457
+ for (const message of effective) {
458
+ if (!this._matchesImageInput(input.message, message))
459
+ continue;
460
+ (input.rejected ? rejected : fresh).add(message);
461
+ present = true;
462
+ }
463
+ if (present && !input.rejected)
464
+ this._activeImageEntries.push(input.id);
465
+ }
466
+ const reference = captureHcodeSelection(this._modelRuntime, request.model);
467
+ const fitted = await fitHcodeImages(request.model, effective, {
468
+ autoResizeImages: this.settingsManager.getImageAutoResize(),
469
+ blockImages: this.settingsManager.getBlockImages(),
470
+ }, fresh, rejected);
471
+ assertHcodeSelection(this._modelRuntime, request.model, reference);
472
+ const refused = fitted.omitted.find(({ index }) => fresh.has(effective[index]));
473
+ if (refused) {
474
+ for (const id of this._activeImageEntries)
475
+ this._rejectedImageEntries.add(id);
476
+ throw new Error(hcodeImageMessage(refused.reason, request.model));
477
+ }
478
+ for (const [index, message] of fitted.messages.entries()) {
479
+ if (fresh.has(effective[index]) && "content" in message && Array.isArray(message.content))
480
+ hcodeActivePrompts.add(message.content);
481
+ }
482
+ const [first] = fitted.omitted;
483
+ if (first)
484
+ this._emit({
485
+ type: "request_images_omitted",
486
+ message: hcodeImageOmissionNotice(fitted.omitted.length, first.reason, request.model),
487
+ });
488
+ return fitted.messages;
489
+ }
496
490
  return effective;
497
491
  };
498
492
  this._buildRuntime({
@@ -512,11 +506,6 @@ export class AgentSession {
512
506
  _installOAuthRequestAttribution() {
513
507
  const streamFunction = this.agent.streamFunction;
514
508
  const attributedStream = (model, context, options) => {
515
- if (this._adaptiveHost)
516
- options = {
517
- ...options,
518
- maxTokens: Math.min(options?.maxTokens ?? this._adaptiveHost.maxOutputTokens, this._adaptiveHost.maxOutputTokens),
519
- };
520
509
  // Auxiliary requests share this transport, but only the agent loop's request owns the
521
510
  // assistant message_start event. A concurrent summary must not replace that identity.
522
511
  if (this._auxiliaryRequest.getStore() || !options?.signal || options.signal !== this.agent.signal) {
@@ -762,12 +751,13 @@ export class AgentSession {
762
751
  * binding follows async context, so concurrent sessions sharing one runtime never cross.
763
752
  */
764
753
  _observeRequests(purpose, fn) {
765
- return this._withAdaptiveAdmission(() => this._modelRuntime.observeRequests(this._requestObserver, purpose, fn));
766
- }
767
- _withAdaptiveAdmission(fn) {
768
- if (!this._adaptiveHost || this._adaptiveAdmissionScope.getStore())
769
- return fn();
770
- return this._adaptiveAdmissionScope.run(true, () => this._adaptiveHost.withActAdmission(fn));
754
+ return observeHcodeImageOmissions((message) => this._emit({ type: "request_images_omitted", message }), () => this._modelRuntime.observeRequests(this._requestObserver, purpose, fn), {
755
+ autoResizeImages: this.settingsManager.getImageAutoResize(),
756
+ onImageSizeRefusal: () => {
757
+ for (const id of this._activeImageEntries)
758
+ this._rejectedImageEntries.add(id);
759
+ },
760
+ });
771
761
  }
772
762
  _unregisterRequestOwner;
773
763
  _requestObserver = {
@@ -808,23 +798,7 @@ export class AgentSession {
808
798
  await runner.emitToolResultObserved({ ...observation, type: "tool_result_observed" });
809
799
  }
810
800
  /** `tool_call` handlers. `parentToolCallId` is set for calls another tool made. */
811
- async _beforeToolCall(context, parentToolCallId) {
812
- const { toolCall, args } = context;
813
- if (this._adaptiveHost)
814
- await this._adaptiveHost.beforeTool(toolCall.name, args, !this._baseToolsOverride && this._toolDefinitions.get(toolCall.name)?.sourceInfo.source === "builtin"
815
- ? "native"
816
- : "unqualified");
817
- const result = await this._authorizeToolCall(context, parentToolCallId);
818
- if (this._adaptiveHost) {
819
- this._adaptiveHost.authorizeToolResult(result);
820
- // Extensions may mutate event.input in place; only the final arguments can grant custody.
821
- await this._adaptiveHost.beforeTool(toolCall.name, args, !this._baseToolsOverride && this._toolDefinitions.get(toolCall.name)?.sourceInfo.source === "builtin"
822
- ? "native"
823
- : "unqualified");
824
- }
825
- return result;
826
- }
827
- async _authorizeToolCall({ toolCall, args }, parentToolCallId) {
801
+ async _beforeToolCall({ toolCall, args }, parentToolCallId) {
828
802
  this._acceptanceLedger?.beginToolCall(toolCall.id, toolCall.name, args);
829
803
  const runner = this._extensionRunner;
830
804
  if (!runner.hasHandlers("tool_call")) {
@@ -865,8 +839,8 @@ export class AgentSession {
865
839
  : undefined;
866
840
  const content = hookResult?.content ?? result.content ?? [];
867
841
  // Runs after the extension hook so images injected or replaced by extensions are normalized too.
868
- const resizeOptions = this._limitsModel()?.inputLimits?.images?.resize;
869
842
  const model = this._limitsModel();
843
+ const resizeOptions = model?.inputLimits?.images?.resize;
870
844
  const normalizedContent = model?.provider === HCODE_PROVIDER || (this.model && isVirtualModel(this.model))
871
845
  ? content
872
846
  : await normalizeToolResultImages(content, {
@@ -1107,13 +1081,9 @@ export class AgentSession {
1107
1081
  this._captureForegroundTarget(effectiveModel);
1108
1082
  await this._prepareAccountRequest(effectiveModel.provider, signal);
1109
1083
  const effectiveThinking = revision === this._thinkingSelectionRevision ? thinkingLevel : this.agent.state.thinkingLevel;
1110
- await this._validateManagedInput(effectiveModel, context.messages, effectiveThinking);
1111
- context = await this._normalizeOrdinaryToolImages(context, effectiveModel);
1112
1084
  return {
1113
1085
  ...previous,
1114
- context,
1115
- model: effectiveModel,
1116
- thinkingLevel: effectiveThinking,
1086
+ ...(await this._projectRequest(context, effectiveModel, effectiveThinking, projection)),
1117
1087
  };
1118
1088
  }
1119
1089
  for (const entry of projection.entries)
@@ -1130,6 +1100,7 @@ export class AgentSession {
1130
1100
  ? prepared.route
1131
1101
  : await this._modelRuntime.resolveModel(model, convertToLlm(context.messages), {
1132
1102
  reason: failed ? "retry" : userTurn ? "user" : "continuation",
1103
+ deferThinkingClamp: true,
1133
1104
  thinkingLevel,
1134
1105
  signal,
1135
1106
  failed,
@@ -1147,14 +1118,47 @@ export class AgentSession {
1147
1118
  if (this._exceedsCompactionThreshold(route.model)) {
1148
1119
  // Size the kept tail for the routed model too, not the model of the latest response.
1149
1120
  await this._runAutoCompaction("threshold", false, undefined, route.model.contextWindow);
1150
- ({ previous, context } = await prepare());
1121
+ ({ previous, context, projection } = await prepare());
1151
1122
  }
1152
1123
  await this._prepareAccountRequest(route.model.provider, signal);
1153
- await this._validateManagedInput(route.model, context.messages, route.thinkingLevel);
1154
- context = await this._normalizeOrdinaryToolImages(context, route.model);
1155
- return { ...previous, context, model: route.model, thinkingLevel: route.thinkingLevel };
1124
+ return { ...previous, ...(await this._projectRequest(context, route.model, route.thinkingLevel, projection)) };
1156
1125
  };
1157
1126
  }
1127
+ async _projectRequest(context, model, requestedLevel, projection) {
1128
+ if (model.provider === HCODE_PROVIDER) {
1129
+ this._managedImageRequest = {
1130
+ model,
1131
+ inputs: projection.entries.flatMap(({ sourceEntry: { id }, messages }) => {
1132
+ const rejected = this._rejectedImageEntries.has(id);
1133
+ return rejected || this._pendingImageEntries.has(id)
1134
+ ? messages.map((message) => ({ id, message, rejected }))
1135
+ : [];
1136
+ }),
1137
+ };
1138
+ }
1139
+ context = await this._normalizeOrdinaryToolImages(context, model);
1140
+ if (model.provider === HCODE_PROVIDER && !model.reasoning) {
1141
+ context = {
1142
+ ...context,
1143
+ messages: context.messages.flatMap((message) => {
1144
+ if (message.role !== "assistant" ||
1145
+ message.provider === model.provider ||
1146
+ !message.content.some((block) => block.type === "thinking"))
1147
+ return [message];
1148
+ const content = message.content.filter((block) => block.type !== "thinking");
1149
+ return content.length ? [{ ...message, content }] : [];
1150
+ }),
1151
+ };
1152
+ }
1153
+ const thinkingLevel = clampThinkingLevel(model, requestedLevel);
1154
+ if (thinkingLevel !== requestedLevel) {
1155
+ this._emit({
1156
+ type: "request_thinking_clamped",
1157
+ message: `Thinking level for this request adjusted from ${requestedLevel} to ${thinkingLevel} (${model.id}).`,
1158
+ });
1159
+ }
1160
+ return { context, model, thinkingLevel };
1161
+ }
1158
1162
  async _dispatchTurnEndBoundary(message, toolResults) {
1159
1163
  this._lastActivityOutcome =
1160
1164
  message.stopReason === "aborted" ? "aborted" : message.stopReason === "error" ? "error" : "completed";
@@ -1372,8 +1376,7 @@ export class AgentSession {
1372
1376
  }
1373
1377
  async _emitAgentSettled() {
1374
1378
  this._withdrawControlContinuations();
1375
- if (this.executionEngine === "legacy")
1376
- this._cacheWarmer?.onAgentSettled();
1379
+ this._cacheWarmer?.onAgentSettled();
1377
1380
  this._isAgentRunActive = false;
1378
1381
  this._isEmittingAgentSettled = true;
1379
1382
  try {
@@ -1427,9 +1430,10 @@ export class AgentSession {
1427
1430
  }
1428
1431
  // When a user message starts, check if it's from either queue and remove it BEFORE emitting
1429
1432
  // This ensures the UI sees the updated queue state
1430
- if (event.type === "message_start" && event.message.role === "user") {
1431
- // A failed listener can restore the unstarted suffix, which must still pass validation on redelivery.
1433
+ // A failed listener can restore the unstarted suffix, which must still pass validation on redelivery.
1434
+ if (event.type === "message_start")
1432
1435
  this._queuedUserInputs.delete(event.message);
1436
+ if (event.type === "message_start" && event.message.role === "user") {
1433
1437
  this._overflowRecoveryAttempts = 0;
1434
1438
  const messageText = contentText(event.message.content, "");
1435
1439
  if (this._acceptanceInitialUserPending)
@@ -1471,8 +1475,12 @@ export class AgentSession {
1471
1475
  }
1472
1476
  // A request identity is valid only until the next assistant message_start; drop any left by a request
1473
1477
  // that never produced one.
1474
- if (event.type === "agent_end")
1478
+ if (event.type === "agent_end") {
1475
1479
  this._oauthRequestAccount = undefined;
1480
+ this._pendingImageEntries.clear();
1481
+ this._activeImageEntries = [];
1482
+ this._managedImageRequest = undefined;
1483
+ }
1476
1484
  // Dequeue by the original text before resize hints change it; resume dispatch without dequeuing twice.
1477
1485
  if (event.type === "message_start" &&
1478
1486
  event.message.role === "user" &&
@@ -1527,6 +1535,8 @@ export class AgentSession {
1527
1535
  }
1528
1536
  if (entryId) {
1529
1537
  this._entryIdsByMessage.set(event.message, entryId);
1538
+ if (this._freshImageInputs.delete(event.message))
1539
+ this._pendingImageEntries.add(entryId);
1530
1540
  const input = this._autoEffortInputs.get(event.message);
1531
1541
  if (input !== undefined) {
1532
1542
  this._autoEffortPendingInputs.set(entryId, input);
@@ -1909,6 +1919,7 @@ export class AgentSession {
1909
1919
  this._runPreflight = undefined;
1910
1920
  this._autoEffortController?.abort();
1911
1921
  this._autoEffortPendingInputs.clear();
1922
+ this._rejectedImageEntries.clear();
1912
1923
  void closeSessionFlowControl(this);
1913
1924
  this._withdrawControlContinuations();
1914
1925
  this._agentRunAbortController?.abort();
@@ -2030,11 +2041,14 @@ export class AgentSession {
2030
2041
  setActiveToolsByName(toolNames) {
2031
2042
  const previous = this.getActiveToolNames();
2032
2043
  this._setActiveTools(toolNames);
2033
- // A loadout that deactivates a tool replaces the restored one, whose pending tools are dropped.
2034
- // One that only adds tools, like activating tool_search, keeps them.
2044
+ // A loadout that deactivates a tool of the restored one replaces it, and its pending tools are
2045
+ // dropped. One that only adds tools, like activating tool_search, keeps them, and so does one
2046
+ // that only deactivates tools outside the restored loadout, such as an extension's own tool that
2047
+ // the restore or reload activated as newly registered.
2035
2048
  const active = new Set(this.getActiveToolNames());
2036
- if (previous.some((name) => !active.has(name)))
2049
+ if (previous.some((name) => !active.has(name) && this._restoredToolNames.has(name))) {
2037
2050
  this._pendingToolNames.clear();
2051
+ }
2038
2052
  }
2039
2053
  _setActiveTools(toolNames) {
2040
2054
  const tools = this._applyToolLoadout(toolNames);
@@ -2305,6 +2319,7 @@ export class AgentSession {
2305
2319
  */
2306
2320
  _restoreToolsFromTranscript(modifiers = []) {
2307
2321
  this._pendingToolNames.clear();
2322
+ this._restoredToolNames.clear();
2308
2323
  // All system messages on the branch, including those before a compaction. Compaction snapshots
2309
2324
  // are derived from these, so replaying them gives the current loadout.
2310
2325
  const systemMessages = this.sessionManager
@@ -2325,6 +2340,7 @@ export class AgentSession {
2325
2340
  // Recorded tools that are not registered yet, such as MCP tools of servers still connecting, are
2326
2341
  // activated when they register. Excluded tools never register, so they are not kept pending.
2327
2342
  this._pendingToolNames = new Set(names.filter((name) => this._isAllowedTool(name)));
2343
+ this._restoredToolNames = new Set(applyToolModifiers(getCurrentTools(systemMessages).map((tool) => tool.name), modifiers));
2328
2344
  // Ignores names that are not registered.
2329
2345
  this._setActiveTools(names);
2330
2346
  }
@@ -2335,32 +2351,10 @@ export class AgentSession {
2335
2351
  * Start a run from a user or custom message. The session counts as busy from here on, so
2336
2352
  * messages sent while before_agent_start handlers run are queued into this run instead of
2337
2353
  * starting another, and an abort requested meanwhile aborts the run as soon as it exists.
2338
- * @param trigger Omit only to reread a restored terminal result without admitting a task.
2339
2354
  * @param onStarted Called once the run's messages are prepared, before the first request.
2340
2355
  * @param autoEffortText Raw interactive input the automatic effort judge sees for a user trigger.
2341
2356
  */
2342
- async _startRun(trigger, onStarted, autoEffortText, adaptiveStartingLevel, fileTexts) {
2343
- const recovering = this._restoredExecutionEngine === "adaptive-v2" && !this._adaptiveRecoveryRead;
2344
- if (!trigger && !recovering)
2345
- throw new Error("No restored adaptive terminal completion to read");
2346
- const selectedEngine = recovering
2347
- ? "adaptive-v2"
2348
- : trigger?.messageType === "custom"
2349
- ? "legacy"
2350
- : this._restoredExecutionEngine === "legacy"
2351
- ? "legacy"
2352
- : (this._executionEngineOption ?? this.settingsManager.getExecutionEngine());
2353
- if (selectedEngine === "adaptive-v2" && this._extensionRunner.getFlagValues().get("flow-admission") !== undefined)
2354
- throw new Error("Adaptive execution cannot reinterpret a frozen Flow admission; use its original legacy runtime.");
2355
- const persistSelection = selectedEngine === "adaptive-v2" ||
2356
- this._runExecutionEngine === "adaptive-v2" ||
2357
- this._restoredExecutionEngine === "adaptive-v2";
2358
- this._runExecutionEngine = selectExecutionEngine(selectedEngine);
2359
- if (!recovering && persistSelection) {
2360
- this.sessionManager.appendCustomEntry("execution-engine", { version: 1, engine: selectedEngine });
2361
- this.sessionManager.flush();
2362
- }
2363
- this._adaptiveCompletion = undefined;
2357
+ async _startRun(trigger, onStarted, autoEffortText, fileTexts) {
2364
2358
  const started = performance.now();
2365
2359
  this._isAgentRunActive = true;
2366
2360
  this._agentRunAbortRequested = false;
@@ -2372,276 +2366,13 @@ export class AgentSession {
2372
2366
  this._oauthPoolWarmupFailed = false;
2373
2367
  this._managedRunStopped = false;
2374
2368
  this._foregroundTarget = undefined;
2375
- let messages;
2376
2369
  const runAbortController = new AbortController();
2377
- let adaptiveSignal;
2378
- let detachAdaptiveSignal;
2379
2370
  this._agentRunAbortController = runAbortController;
2371
+ let messages;
2380
2372
  try {
2381
- if (selectedEngine === "adaptive-v2") {
2382
- this._adaptiveCompletion = undefined;
2383
- this._adaptiveSeal = undefined;
2384
- const branch = this.sessionManager.getBranch();
2385
- const selection = branch.findLastIndex((entry) => entry.type === "custom" && entry.customType === "execution-engine");
2386
- // Selection is persisted before admission. Its suffix alone belongs to the interrupted run.
2387
- const runEntries = recovering && selection >= 0 ? branch.slice(selection + 1) : [];
2388
- const previous = runEntries.findLast((entry) => entry.type === "custom" && entry.customType === "adaptive-engine-snapshot");
2389
- const admission = runEntries.findLast((entry) => entry.type === "custom" && entry.customType === "adaptive-engine-admission");
2390
- const completionSeal = runEntries.findLast((entry) => entry.type === "custom" && entry.customType === "adaptive-engine-completion");
2391
- const terminal = previous?.type === "custom" &&
2392
- previous.data !== null &&
2393
- typeof previous.data === "object" &&
2394
- "checkpoint" in previous.data &&
2395
- previous.data.checkpoint === "terminal";
2396
- if (!trigger && !terminal)
2397
- throw new Error("Adaptive completion reread requires a terminal snapshot");
2398
- if (recovering && (previous?.type !== "custom" || admission?.type !== "custom"))
2399
- throw new Error("Adaptive recovery is unsupported without the original persisted admission; no work replayed");
2400
- if (this._bashJobs.list().some((job) => job.status === "running" || job.status === "interrupted"))
2401
- throw new Error("Cannot admit adaptive execution while session jobs are running or cleanup is unconfirmed");
2402
- if (!this.model)
2403
- throw new Error("No adaptive model selected");
2404
- if (trigger?.messageType === "user" &&
2405
- trigger.images?.length &&
2406
- (this.settingsManager.getBlockImages() || !this.model.input.includes("image")))
2407
- throw new Error("Adaptive image capability refused; nothing was dropped or sent");
2408
- this._cacheWarmer?.cancel();
2409
- this._adaptiveHost = await loadAdaptiveExecutionHost({
2410
- cwd: this._cwd,
2411
- startedAt: { wall: Date.now(), monotonic: performance.now() },
2412
- sessionId: this.sessionId,
2413
- text: !trigger
2414
- ? ""
2415
- : trigger.messageType === "user"
2416
- ? trigger.prompt
2417
- : contentText(trigger.message.content, ""),
2418
- facts: [
2419
- ...this._resourceLoader
2420
- .getAgentsFiles()
2421
- .agentsFiles.map((file) => `Project context ${file.path}:\n${file.content}`),
2422
- ...this.sessionManager
2423
- .getBranch()
2424
- .flatMap((entry) => entry.type === "message" && entry.message.role === "user"
2425
- ? [contentText(entry.message.content, "")].filter((text) => text.trim())
2426
- : []),
2427
- ],
2428
- images: trigger?.messageType === "user" ? (trigger.images ?? []) : [],
2429
- model: this.model,
2430
- thinkingLevel: () => this.thinkingLevel,
2431
- runtime: this._modelRuntime,
2432
- authorityIdentity: createHash("sha256")
2433
- .update(JSON.stringify({
2434
- tools: this.getActiveToolNames().map((name) => ({
2435
- name,
2436
- source: this._toolDefinitions.get(name)?.sourceInfo,
2437
- })),
2438
- overrides: !!this._baseToolsOverride,
2439
- extensions: this._resourceLoader
2440
- .getExtensions()
2441
- .extensions.map((extension) => extension.path),
2442
- profile: this._extensionRunner.getFlagValues().get("profile") ?? null,
2443
- flowAdmission: this._extensionRunner.getFlagValues().get("flow-admission") ?? null,
2444
- trusted: this.settingsManager.isProjectTrusted(),
2445
- fallback: this.settingsManager.readOAuthAccountActivationPolicy(this.model.provider),
2446
- nodeFallback: this.model.provider === HUMAIN_NODE_PROVIDER
2447
- ? this._modelRuntime.nodeAccountMetadata.read().policy
2448
- : null,
2449
- }))
2450
- .digest("hex"),
2451
- ...(recovering && admission?.type === "custom" && previous?.type === "custom"
2452
- ? {
2453
- recovery: {
2454
- admission: admission.data,
2455
- snapshot: previous.data,
2456
- completion: completionSeal?.type === "custom" ? completionSeal.data : undefined,
2457
- },
2458
- }
2459
- : {}),
2460
- persistAdmission: (admission) => {
2461
- this.sessionManager.appendCustomEntry("adaptive-engine-admission", admission);
2462
- this.sessionManager.flush();
2463
- },
2464
- signal: runAbortController.signal,
2465
- mode: this._extensionMode === "tui" ? "interactive" : "headless",
2466
- deadline: this._timeLimit ? this._timeLimit.startedAt + this._timeLimit.seconds * 1000 : undefined,
2467
- jobs: this._bashJobs,
2468
- peerTools: () => this.agent.state.tools.filter((tool) => !this._baseToolsOverride &&
2469
- ["read", "ls", "edit", "write"].includes(tool.name) &&
2470
- this._toolDefinitions.get(tool.name)?.sourceInfo.source === "builtin"),
2471
- peerRequest: async (context, signal, maxTokens, state, nativeTools) => {
2472
- const requestContext = { messages: context.messages, tools: state.tools.slice() };
2473
- const prepared = await this._adaptivePeerPrepareRequest?.({
2474
- context: requestContext,
2475
- model: state.model,
2476
- thinkingLevel: state.thinkingLevel,
2477
- }, signal);
2478
- const model = prepared?.model ?? state.model;
2479
- const thinking = prepared?.thinkingLevel ?? state.thinkingLevel;
2480
- const peerContext = prepared?.context ?? requestContext;
2481
- const executableTools = peerContext.tools ?? [];
2482
- // Peer custody covers native implementations only; never ignore a hook's replacement or addition.
2483
- if (executableTools.some((tool) => !nativeTools.includes(tool)))
2484
- throw new Error("Adaptive prepared peer tool additions/replacements are unsupported");
2485
- // Providers replay declarations, not executable tools; retain the same removal policy on later turns.
2486
- const changes = getToolStateChanges(getCurrentTools(peerContext.messages), executableTools);
2487
- const preparedMessages = changes.toolsAdded.length || changes.toolsRemoved.length
2488
- ? [
2489
- ...peerContext.messages,
2490
- { role: "system", content: "", ...changes, timestamp: Date.now() },
2491
- ]
2492
- : peerContext.messages;
2493
- // Request-time transforms must not replace or mutate the retained prepared context.
2494
- const messages = this._adaptivePeerTransformContext
2495
- ? await this._adaptivePeerTransformContext(structuredClone(preparedMessages), signal)
2496
- : preparedMessages;
2497
- const normalized = await this._normalizeOrdinaryToolImages({ ...peerContext, messages }, model);
2498
- const response = await (await this._auxiliaryStreamFunction(model, normalizeContext({
2499
- ...context,
2500
- messages: await this.agent.convertToLlm(normalized.messages),
2501
- }), {
2502
- signal,
2503
- maxTokens,
2504
- reasoning: thinking === "off" ? undefined : thinking,
2505
- thinkingBudgets: this.agent.thinkingBudgets,
2506
- transport: this.agent.transport,
2507
- maxRetryDelayMs: this.agent.maxRetryDelayMs,
2508
- identity: this.agent.identity,
2509
- onPayload: this.agent.onPayload,
2510
- onResponse: this.agent.onResponse,
2511
- onProviderStreamEvent: this.agent.onProviderStreamEvent,
2512
- })).result();
2513
- return {
2514
- response,
2515
- state: {
2516
- model,
2517
- thinkingLevel: thinking,
2518
- tools: executableTools,
2519
- messages: preparedMessages,
2520
- },
2521
- };
2522
- },
2523
- beforePeerTool: (context) => {
2524
- if (this.agent.beforeToolCall !== this._installedBeforeToolCall ||
2525
- !this.getActiveToolNames().includes(context.toolCall.name) ||
2526
- this._toolDefinitions.get(context.toolCall.name)?.sourceInfo.source !== "builtin")
2527
- throw new Error("Adaptive peer tool authority changed");
2528
- return this._authorizeToolCall(context);
2529
- },
2530
- afterPeerTool: (context, signal) => this.agent.afterToolCall?.(context, signal) ?? Promise.resolve(undefined),
2531
- persist: async (snapshot) => {
2532
- if (snapshot.checkpoint === "terminal")
2533
- this._adaptiveSeal = {
2534
- runId: snapshot.budget.identity.runId,
2535
- admissionId: snapshot.budget.identity.admissionId,
2536
- snapshotIdentity: createHash("sha256").update(JSON.stringify(snapshot)).digest("hex"),
2537
- };
2538
- this.sessionManager.appendCustomEntry("adaptive-engine-snapshot", snapshot);
2539
- this.sessionManager.flush();
2540
- },
2541
- publish: (status) => {
2542
- this._emit({ type: "adaptive_status", status });
2543
- if (this._extensionMode === "tui")
2544
- this._extensionUIContext?.setWorkingMessage(adaptiveStatusText(status));
2545
- },
2546
- presentChecklist: (summary, checklist, signal) => presentAdaptiveChecklist(summary, checklist, signal, this._extensionUIContext),
2547
- messages: () => this.messages,
2548
- recordSubmission: (reservation, phase, lane) => {
2549
- this.sessionManager.appendCustomEntry("adaptive-request-attestation", {
2550
- ...reservation,
2551
- phase,
2552
- lane,
2553
- });
2554
- this.sessionManager.flush();
2555
- },
2556
- recordUsage: (provider, model, usage) => {
2557
- const entry = this.sessionManager.appendUsage("adaptive", provider, model, usage);
2558
- this._emit({ type: "entry_appended", entry });
2559
- },
2560
- abortImplementation: () => {
2561
- this.agent.abort();
2562
- this.abortCompaction();
2563
- this.abortRetry();
2564
- },
2565
- wakeJob: (record) => {
2566
- this.sessionManager.appendCustomEntry("adaptive-job-terminal", record);
2567
- this._pendingCustomMessages.push({
2568
- role: "custom",
2569
- customType: "adaptive-job-terminal",
2570
- content: `Owned job ${record.result.job_id} ${record.result.status}; inspect captured output with jobs before treating it as evidence.`,
2571
- display: false,
2572
- timestamp: Date.now(),
2573
- });
2574
- },
2575
- }, {
2576
- ...this._adaptiveOptions,
2577
- ...(adaptiveStartingLevel !== undefined ? { startingLevel: adaptiveStartingLevel } : {}),
2578
- }, this.settingsManager.getAdaptiveExecutionOptions());
2579
- if (!recovering || !terminal)
2580
- onStarted?.();
2581
- const step = await this._adaptiveHost.next();
2582
- if (step.kind === "complete") {
2583
- this._acceptAdaptiveCompletion(step.completion);
2584
- if (recovering)
2585
- this._adaptiveRecoveryRead = true;
2586
- this._adaptiveHost = undefined;
2587
- this._agentRunAbortController = undefined;
2588
- // A terminal reread is not the new task. Keep prompt ownership until that task settles.
2589
- // Interrupted recovery still consumes only its frozen request.
2590
- if (recovering && terminal && trigger) {
2591
- runAbortController.signal.throwIfAborted();
2592
- return this._startRun(trigger, onStarted, autoEffortText, adaptiveStartingLevel, fileTexts);
2593
- }
2594
- await this._emitAgentSettled();
2595
- return;
2596
- }
2597
- if (runtimeStreamFunctions.get(this.agent.streamFunction) !== this._modelRuntime)
2598
- throw new Error("Adaptive primary requires a ModelRuntime-owned stream; custom provider loops are unsupported");
2599
- adaptiveSignal = step.context.signal;
2600
- const abortPrimary = () => {
2601
- this._agentRunAbortRequested = true;
2602
- this.agent.abort();
2603
- this.abortCompaction();
2604
- this.abortRetry();
2605
- };
2606
- adaptiveSignal.addEventListener("abort", abortPrimary, { once: true });
2607
- detachAdaptiveSignal = () => adaptiveSignal?.removeEventListener("abort", abortPrimary);
2608
- if (adaptiveSignal.aborted)
2609
- abortPrimary();
2610
- if (!this._baseToolsOverride) {
2611
- this._adaptiveLegacyJobs = this._baseToolDefinitions.get("jobs");
2612
- this._baseToolDefinitions.set("jobs", createJobsToolDefinition(this._cwd, {
2613
- jobs: this._bashJobs,
2614
- getRunContext: () => this._adaptiveHost?.runContext,
2615
- }));
2616
- this._refreshToolRegistry();
2617
- }
2618
- this._appendAdaptiveWork(step.input);
2619
- if (recovering) {
2620
- trigger = {
2621
- messageType: "user",
2622
- prompt: this._adaptiveHost.prompt.text,
2623
- images: this._adaptiveHost.prompt.images,
2624
- };
2625
- autoEffortText = trigger.prompt;
2626
- }
2627
- }
2628
- if (!trigger)
2629
- throw new Error("Adaptive terminal reread cannot dispatch work");
2630
- const runTrigger = trigger;
2631
- messages = await this._withAdaptiveAdmission(() => this._prepareRun(runTrigger, runAbortController.signal, autoEffortText));
2373
+ messages = await this._prepareRun(trigger, runAbortController.signal, autoEffortText);
2632
2374
  }
2633
2375
  catch (error) {
2634
- detachAdaptiveSignal?.();
2635
- if (selectedEngine === "adaptive-v2")
2636
- runAbortController.abort();
2637
- try {
2638
- await this._finishAdaptiveExecution();
2639
- }
2640
- catch {
2641
- /* Preserve the originating pre-run refusal. */
2642
- }
2643
- if (selectedEngine === "adaptive-v2")
2644
- await this._emitAgentSettled();
2645
2376
  if (this._agentRunAbortController === runAbortController)
2646
2377
  this._agentRunAbortController = undefined;
2647
2378
  this._runSystemPromptOptions = undefined;
@@ -2652,8 +2383,7 @@ export class AgentSession {
2652
2383
  this._modelRuntime.metadata.feature("prompt", Math.round(performance.now() - started), "failure");
2653
2384
  throw error;
2654
2385
  }
2655
- // Adaptive runs retain their own evidence-bound verification and completion authority.
2656
- if (selectedEngine === "legacy" && trigger.messageType === "user" && this._runPreflight) {
2386
+ if (trigger.messageType === "user" && this._runPreflight) {
2657
2387
  this._acceptanceLedger = new AcceptanceLedger(trigger.prompt, () => {
2658
2388
  for (const owner of this._bashJobOwners)
2659
2389
  if (owner.hasActiveEffects)
@@ -2670,8 +2400,7 @@ export class AgentSession {
2670
2400
  // have while idle. No run exists yet, so they cannot split a tool call from its result.
2671
2401
  this._flushPendingBashMessages();
2672
2402
  this._flushPendingCustomMessages();
2673
- if (selectedEngine === "legacy")
2674
- onStarted?.();
2403
+ onStarted?.();
2675
2404
  // Compaction before the prompt may have scheduled a retry; the new prompt replaces it.
2676
2405
  this._failedResponse = undefined;
2677
2406
  this._recordSelection();
@@ -2702,8 +2431,7 @@ export class AgentSession {
2702
2431
  // agent_start applies an abort requested during preparation or warm-up before any provider request.
2703
2432
  await this._observeRequests("chat", () => this.agent.prompt(messages));
2704
2433
  while (!this._agentRunAbortRequested) {
2705
- if (!this._adaptiveHost?.implementationStoppedForReserve &&
2706
- (await this._withAdaptiveAdmission(() => this._handlePostAgentRun()))) {
2434
+ if (await this._handlePostAgentRun()) {
2707
2435
  if (this._agentRunAbortRequested)
2708
2436
  break;
2709
2437
  await this._observeRequests("chat", () => this.agent.continue());
@@ -2711,22 +2439,8 @@ export class AgentSession {
2711
2439
  }
2712
2440
  if (this._agentRunAbortRequested)
2713
2441
  break;
2714
- let continuation = this._adaptiveHost?.implementationStoppedForReserve
2715
- ? false
2716
- : await this._withAdaptiveAdmission(() => this._runBeforeSettleBoundary());
2717
- if (!continuation && this._adaptiveHost) {
2718
- this._adaptiveHost.completeAct();
2719
- const step = await this._adaptiveHost.next();
2720
- if (step.kind === "complete") {
2721
- this._acceptAdaptiveCompletion(step.completion);
2722
- if (recovering)
2723
- this._adaptiveRecoveryRead = true;
2724
- break;
2725
- }
2726
- this._appendAdaptiveWork(step.input);
2727
- continuation = true;
2728
- }
2729
- else if (!continuation && !this._managedRunStopped && this._acceptanceLedger) {
2442
+ let continuation = await this._runBeforeSettleBoundary();
2443
+ if (!continuation && !this._managedRunStopped && this._acceptanceLedger) {
2730
2444
  await this._verifyAcceptance();
2731
2445
  continuation =
2732
2446
  this.agent.hasQueuedMessages() && this._buildBoundaryContext([], "agent_before_settle").canContinue;
@@ -2738,17 +2452,9 @@ export class AgentSession {
2738
2452
  }
2739
2453
  finally {
2740
2454
  try {
2741
- detachAdaptiveSignal?.();
2742
- if (this._adaptiveHost && !this._adaptiveCompletion) {
2743
- if (!adaptiveSignal?.aborted)
2744
- runAbortController.abort();
2745
- await this._finishAdaptiveExecution();
2746
- }
2747
2455
  this._settleAcceptance();
2748
2456
  }
2749
2457
  finally {
2750
- this._adaptiveHost = undefined;
2751
- this._restoreAdaptiveJobs();
2752
2458
  if (this._agentRunAbortRequested)
2753
2459
  this._finishCancelledRetry();
2754
2460
  this._failedResponse = undefined;
@@ -2943,56 +2649,6 @@ export class AgentSession {
2943
2649
  }
2944
2650
  }
2945
2651
  }
2946
- async _finishAdaptiveExecution() {
2947
- const host = this._adaptiveHost;
2948
- if (!host)
2949
- return;
2950
- try {
2951
- host.completeAct();
2952
- this._acceptAdaptiveCompletion(await host.finished);
2953
- }
2954
- finally {
2955
- this._adaptiveHost = undefined;
2956
- this._restoreAdaptiveJobs();
2957
- }
2958
- }
2959
- _restoreAdaptiveJobs() {
2960
- if (!this._adaptiveLegacyJobs)
2961
- return;
2962
- this._baseToolDefinitions.set("jobs", this._adaptiveLegacyJobs);
2963
- this._adaptiveLegacyJobs = undefined;
2964
- this._refreshToolRegistry();
2965
- }
2966
- _acceptAdaptiveCompletion(completion) {
2967
- const seal = this._adaptiveSeal;
2968
- if (seal) {
2969
- this.sessionManager.appendCustomEntry("adaptive-engine-completion", {
2970
- version: 1,
2971
- ...seal,
2972
- verification: completion.verification,
2973
- workflowOutcome: completion.workflowOutcome,
2974
- });
2975
- this.sessionManager.flush();
2976
- this._adaptiveSeal = undefined;
2977
- }
2978
- this._adaptiveCompletion = completion;
2979
- this._emit({ type: "adaptive_completion", completion });
2980
- if (this._extensionMode === "tui") {
2981
- this._extensionUIContext?.setWorkingMessage(undefined);
2982
- this._extensionUIContext?.notify(adaptiveEvidenceLines(completion).join("\n"), completion.verification === "verified" ? "info" : "warning");
2983
- }
2984
- }
2985
- _appendAdaptiveWork(input) {
2986
- this._pendingCustomMessages.push({
2987
- role: "custom",
2988
- customType: "adaptive-work",
2989
- display: false,
2990
- content: `Admitted adaptive primary work: ${JSON.stringify(input)}\n${input.level >= 1 ? "Make a short plan naming affected contracts and checks before mutation. " : ""}Satisfy each criterion, self-check and report limitations. Host-captured checks and a counterexample are required; your prose or JSON cannot certify behavior. Nested model execution is not authorized. ${input.level === 2 ? 'For genuinely independent work, end a short plan with <adaptive_peers>[{"paths":["relative/owned/path"],"task":"bounded independent task","benefit":"why parallel work helps","tokens":30000}]</adaptive_peers>. At most two scopes; give each enough tokens for bounded input plus output on every request. The host admits disjoint scopes and returns collected summaries to you for integration before checking. Do not delegate unsplittable work. ' : ""}If new facts add or refine scope, append <adaptive_updates>{"requirements":[{"kind":"append","acceptance":"new atomic criterion"}],"facts":["observed fact"]}</adaptive_updates>; refine uses kind=refine plus id. This is a proposal only, never evidence/status/removal authority.`,
2991
- timestamp: Date.now(),
2992
- });
2993
- if (this.agent.state.messages.length)
2994
- this._flushPendingCustomMessages();
2995
- }
2996
2652
  /**
2997
2653
  * Prepare a run and return its starting messages: compact first when needed, emit
2998
2654
  * before_agent_start, apply the run's prompt options and tool loadout, and build the starting
@@ -3043,8 +2699,15 @@ export class AgentSession {
3043
2699
  this._autoEffortInputs.set(userMessage, autoEffortText);
3044
2700
  messages.push(userMessage);
3045
2701
  }
3046
- // Inject any pending "nextTurn" messages as context alongside the starting message
2702
+ // Only submitted input, not context generated by before_agent_start, is fresh.
3047
2703
  messages.push(...this._pendingNextTurnMessages);
2704
+ const fresh = messages.slice();
2705
+ for (const message of fresh) {
2706
+ if ("content" in message &&
2707
+ Array.isArray(message.content) &&
2708
+ message.content.some((block) => block.type === "image"))
2709
+ this._freshImageInputs.add(message);
2710
+ }
3048
2711
  for (const msg of result.messages) {
3049
2712
  messages.push({
3050
2713
  role: "custom",
@@ -3073,6 +2736,7 @@ export class AgentSession {
3073
2736
  const userTurn = context.slice(lastResponse + 1).some((message) => message.role === "user");
3074
2737
  prepared = await this._modelRuntime.resolveModel(selection, context, {
3075
2738
  reason: userTurn ? "user" : "continuation",
2739
+ deferThinkingClamp: true,
3076
2740
  thinkingLevel: preparedThinking,
3077
2741
  state: preparedState,
3078
2742
  });
@@ -3085,7 +2749,7 @@ export class AgentSession {
3085
2749
  userMessage.content = [{ type: "text", text }, ...normalized.images];
3086
2750
  }
3087
2751
  if (target?.provider === HCODE_PROVIDER)
3088
- await this._validateManagedInput(target, [...this.messages, ...messages], prepared?.thinkingLevel ?? this.thinkingLevel);
2752
+ await this._validateManagedInput(target, fresh);
3089
2753
  if (prepared && selection)
3090
2754
  this._preparedImageRoute = {
3091
2755
  selection,
@@ -3182,6 +2846,7 @@ export class AgentSession {
3182
2846
  return { text, images };
3183
2847
  }
3184
2848
  async _normalizeOrdinaryToolImages(context, model) {
2849
+ // Managed requests fit the effective transcript after the context hooks.
3185
2850
  if (model.provider === HCODE_PROVIDER)
3186
2851
  return context;
3187
2852
  // History keeps originals for future managed routes; normalize only the resolved ordinary request.
@@ -3223,35 +2888,58 @@ export class AgentSession {
3223
2888
  const selection = this.model;
3224
2889
  if (!selection)
3225
2890
  return;
3226
- const combined = [...context, ...messages];
3227
2891
  const thinkingLevel = this.thinkingLevel;
3228
2892
  if (!isVirtualModel(selection)) {
3229
- await this._validateManagedInput(selection, combined, thinkingLevel);
2893
+ await this._validateManagedInput(selection, messages);
3230
2894
  return;
3231
2895
  }
3232
- const llm = convertToLlm(combined);
2896
+ const llm = convertToLlm([...context, ...messages]);
3233
2897
  if (!llm.some((message) => typeof message.content !== "string" && message.content.some((block) => block.type === "image")))
3234
2898
  return;
3235
2899
  const state = getVirtualModelState(this.sessionManager.getBranch(), selection.provider, selection.id);
3236
2900
  const route = await this._modelRuntime.resolveModel(selection, llm, {
3237
2901
  reason: "user",
2902
+ deferThinkingClamp: true,
3238
2903
  thinkingLevel,
3239
2904
  state,
3240
2905
  signal,
3241
2906
  });
3242
- await this._validateManagedInput(route.model, combined, route.thinkingLevel);
2907
+ await this._validateManagedInput(route.model, messages);
3243
2908
  return { selection, route, thinkingLevel, state };
3244
2909
  }
3245
- async _validateManagedInput(model, messages, thinkingLevel) {
2910
+ // Context hooks clone messages; correlate the original attachment even if a hook changes the surrounding text.
2911
+ _matchesImageInput(input, message) {
2912
+ if (input === message)
2913
+ return true;
2914
+ if (input.role !== "user" && input.role !== "custom")
2915
+ return false;
2916
+ if (message.role !== input.role || message.timestamp !== input.timestamp)
2917
+ return false;
2918
+ if (input.role === "custom" && (message.role !== "custom" || message.customType !== input.customType))
2919
+ return false;
2920
+ const { content } = input;
2921
+ return (Array.isArray(content) &&
2922
+ Array.isArray(message.content) &&
2923
+ message.content.some((block) => block.type === "image" &&
2924
+ content.some((original) => original.type === "image" && block.mimeType === original.mimeType && block.data === original.data)));
2925
+ }
2926
+ /**
2927
+ * Check submitted input before persisting it. Historical images are fitted only in the request projection.
2928
+ */
2929
+ async _validateManagedInput(model, fresh) {
3246
2930
  if (model.provider !== HCODE_PROVIDER)
3247
2931
  return;
3248
2932
  const reference = captureHcodeSelection(this._modelRuntime, model);
3249
- this._assertManagedThinkingLevel(model, thinkingLevel);
3250
- const context = convertToLlm(messages);
3251
- if (this.settingsManager.getBlockImages() &&
3252
- context.some((message) => typeof message.content !== "string" && message.content.some((block) => block.type === "image")))
3253
- throw new Error("HUMAIN Code image attachments are blocked. Remove them or change /settings before sending. Nothing was dropped or sent.");
3254
- await validateHcodeImages(model, context);
2933
+ const fitted = await fitHcodeImages(model, fresh, {
2934
+ autoResizeImages: this.settingsManager.getImageAutoResize(),
2935
+ blockImages: this.settingsManager.getBlockImages(),
2936
+ }, new Set(fresh));
2937
+ const [refused] = fitted.omitted;
2938
+ if (refused) {
2939
+ const message = hcodeImageMessage(refused.reason, model);
2940
+ throw new Error(refused.reason === "blocked" ? `${message} Nothing was dropped or sent.` : message);
2941
+ }
2942
+ await validateHcodeImages(model, convertToLlm(fitted.messages));
3255
2943
  assertHcodeSelection(this._modelRuntime, model, reference);
3256
2944
  }
3257
2945
  async _normalizePromptImages(images, model) {
@@ -3267,8 +2955,6 @@ export class AgentSession {
3267
2955
  resizeOptions: model?.inputLimits?.images?.resize,
3268
2956
  });
3269
2957
  if (!processed.ok) {
3270
- if (this.executionEngine === "adaptive-v2")
3271
- throw new Error(`Adaptive image input refused: ${processed.message}`);
3272
2958
  hints.push(processed.message);
3273
2959
  continue;
3274
2960
  }
@@ -3277,15 +2963,6 @@ export class AgentSession {
3277
2963
  }
3278
2964
  return { images: normalizedImages, hints };
3279
2965
  }
3280
- /** Revalidate a reopened terminal run's evidence without submitting a new task or replaying work. */
3281
- async rereadAdaptiveCompletion() {
3282
- if (!this.isIdle || this._promptPreflightCount > 0)
3283
- throw new Error("Wait for the current session operation before rereading adaptive completion");
3284
- await this._startRun(undefined);
3285
- if (!this._adaptiveCompletion)
3286
- throw new Error("Adaptive terminal completion unavailable");
3287
- return this._adaptiveCompletion;
3288
- }
3289
2966
  /**
3290
2967
  * Send a prompt to the agent.
3291
2968
  * - Handles extension commands (registered via pi.registerCommand) immediately, even during streaming
@@ -3326,7 +3003,7 @@ export class AgentSession {
3326
3003
  this._promptPreflightCount--;
3327
3004
  }
3328
3005
  if (prepared) {
3329
- await this._startRun(prepared.trigger, () => preflightResult?.("started"), prepared.autoEffortText, options?.adaptiveStartingLevel, options?.fileTexts);
3006
+ await this._startRun(prepared.trigger, () => preflightResult?.("started"), prepared.autoEffortText, options?.fileTexts);
3330
3007
  }
3331
3008
  }
3332
3009
  /**
@@ -3557,8 +3234,10 @@ export class AgentSession {
3557
3234
  this._emitQueueUpdate();
3558
3235
  if (autoEffortText !== undefined)
3559
3236
  this._autoEffortInputs.set(message, autoEffortText);
3560
- if (images?.length)
3237
+ if (images?.length) {
3561
3238
  this._queuedMessagesWithImages.add(message);
3239
+ this._freshImageInputs.add(message);
3240
+ }
3562
3241
  this.agent.steer(message);
3563
3242
  }
3564
3243
  /**
@@ -3576,8 +3255,10 @@ export class AgentSession {
3576
3255
  this._emitQueueUpdate();
3577
3256
  if (autoEffortText !== undefined)
3578
3257
  this._autoEffortInputs.set(message, autoEffortText);
3579
- if (images?.length)
3258
+ if (images?.length) {
3580
3259
  this._queuedMessagesWithImages.add(message);
3260
+ this._freshImageInputs.add(message);
3261
+ }
3581
3262
  this.agent.followUp(message);
3582
3263
  }
3583
3264
  /** Normalize queued images at delivery without changing the original automatic-effort input. */
@@ -3635,6 +3316,10 @@ export class AgentSession {
3635
3316
  this._pendingNextTurnMessages.push(appMessage);
3636
3317
  }
3637
3318
  else if (this.isStreaming && options?.triggerTurn !== false) {
3319
+ if (Array.isArray(appMessage.content) && appMessage.content.some((block) => block.type === "image")) {
3320
+ this._freshImageInputs.add(appMessage);
3321
+ this._queuedUserInputs.add(appMessage);
3322
+ }
3638
3323
  if (options?.deliverAs === "followUp") {
3639
3324
  this.agent.followUp(appMessage);
3640
3325
  }
@@ -3790,9 +3475,19 @@ export class AgentSession {
3790
3475
  * @throws Error if no auth is configured for the model
3791
3476
  */
3792
3477
  async setModel(model, options = {}) {
3793
- await this._selectModel(model, options, "set");
3478
+ const notice = await this._selectModel(model, options, "set");
3479
+ if (notice)
3480
+ this._emit({ type: "thinking_level_adjusted", notice });
3481
+ }
3482
+ /** @internal Whether a model selection has started, even if its auth check is still pending. */
3483
+ get hasRequestedModelSelection() {
3484
+ return this._modelSelectionRevision > 0;
3485
+ }
3486
+ /** Select only a model, retaining the live thinking level where the new model supports it. */
3487
+ async setModelKeepingThinking(model, options = {}) {
3488
+ return this._selectModel(model, options, "set", "keep-current");
3794
3489
  }
3795
- async _selectModel(model, options, source) {
3490
+ async _selectModel(model, options, source, thinkingPolicy = "defaults") {
3796
3491
  const started = performance.now();
3797
3492
  let outcome = "failure";
3798
3493
  try {
@@ -3802,7 +3497,7 @@ export class AgentSession {
3802
3497
  if ((source === "set" || reference) && !(await this._modelRuntime.checkAuth(model.provider))) {
3803
3498
  if (reference) {
3804
3499
  assertHcodeSelection(this._modelRuntime, model, reference);
3805
- throw new Error(hcodeSelectionUnavailable(this._modelRuntime));
3500
+ throw new Error("The saved HUMAIN Code sign-in could not authorize model selection. Use /login to sign in again. No model was switched.");
3806
3501
  }
3807
3502
  throw new Error(`No API key for ${model.provider}/${model.id}`);
3808
3503
  }
@@ -3812,11 +3507,15 @@ export class AgentSession {
3812
3507
  ? HCODE_SELECTION_CHANGED_MESSAGE
3813
3508
  : "Model selection changed. Use /model to choose again. No selection was saved.");
3814
3509
  const previousModel = this.model;
3815
- const thinkingLevel = this._getThinkingLevelForModelSwitch(model, options.thinkingLevel);
3510
+ const requestedLevel = thinkingPolicy === "keep-current"
3511
+ ? this.thinkingLevel
3512
+ : this._getThinkingLevelForModelSwitch(model, options.thinkingLevel);
3816
3513
  if (reference) {
3817
3514
  assertHcodeSelection(this._modelRuntime, model, reference);
3818
- this._assertManagedThinkingLevel(model, thinkingLevel);
3515
+ if (options.thinkingLevel !== undefined)
3516
+ this._assertManagedThinkingLevel(model, requestedLevel);
3819
3517
  }
3518
+ const thinkingLevel = thinkingPolicy === "keep-current" || reference ? clampThinkingLevel(model, requestedLevel) : requestedLevel;
3820
3519
  // Apply model
3821
3520
  this.agent.state.model = model;
3822
3521
  markModelSelectionChosen(this.sessionManager);
@@ -3831,6 +3530,8 @@ export class AgentSession {
3831
3530
  this.setThinkingLevel(thinkingLevel);
3832
3531
  await this._emitModelSelect(model, previousModel, source);
3833
3532
  outcome = "success";
3533
+ if (requestedLevel !== thinkingLevel)
3534
+ return `Thinking level adjusted from ${requestedLevel} to ${thinkingLevel}.`;
3834
3535
  }
3835
3536
  finally {
3836
3537
  if (options.signal?.aborted)
@@ -3867,8 +3568,13 @@ export class AgentSession {
3867
3568
  return this._cycleAvailableModel(direction, options);
3868
3569
  }
3869
3570
  async _cycleScopedModel(direction, options) {
3870
- const availableIds = new Set(this._modelRuntime.getAvailableSnapshot().map((model) => `${model.provider}\0${model.id}`));
3871
- const scopedModels = this._scopedModels.filter((scoped) => availableIds.has(`${scoped.model.provider}\0${scoped.model.id}`));
3571
+ const available = new Map(this._modelRuntime.getAvailableSnapshot().map((model) => [`${model.provider}\0${model.id}`, model]));
3572
+ const scopedModels = this._scopedModels.flatMap((scoped) => {
3573
+ const model = available.get(`${scoped.model.provider}\0${scoped.model.id}`);
3574
+ if (!model)
3575
+ return [];
3576
+ return [model.provider === HCODE_PROVIDER ? { ...scoped, model } : scoped];
3577
+ });
3872
3578
  const currentModel = this.model;
3873
3579
  const currentIndex = scopedModels.findIndex((sm) => modelsAreEqual(sm.model, currentModel));
3874
3580
  const nextIndex = getNextCycleIndex(currentIndex, scopedModels.length, direction);
@@ -3880,8 +3586,8 @@ export class AgentSession {
3880
3586
  // - Per-model thinking level overrides take priority over the global default
3881
3587
  // setThinkingLevel clamps to model capabilities.
3882
3588
  // Model persistence does not implicitly rewrite the global thinking default.
3883
- await this._selectModel(next.model, { ...options, thinkingLevel: options.thinkingLevel ?? next.thinkingLevel }, "cycle");
3884
- return { model: next.model, thinkingLevel: this.thinkingLevel, isScoped: true };
3589
+ const notice = await this._selectModel(next.model, { ...options, thinkingLevel: options.thinkingLevel ?? next.thinkingLevel }, "cycle");
3590
+ return { model: next.model, thinkingLevel: this.thinkingLevel, isScoped: true, ...(notice ? { notice } : {}) };
3885
3591
  }
3886
3592
  async _cycleAvailableModel(direction, options) {
3887
3593
  const availableModels = this._modelRuntime.getAvailableSnapshot();
@@ -3893,8 +3599,8 @@ export class AgentSession {
3893
3599
  const nextModel = availableModels[nextIndex];
3894
3600
  // Apply thinking level for the new model.
3895
3601
  // Model persistence does not implicitly rewrite the global thinking default.
3896
- await this._selectModel(nextModel, options, "cycle");
3897
- return { model: nextModel, thinkingLevel: this.thinkingLevel, isScoped: false };
3602
+ const notice = await this._selectModel(nextModel, options, "cycle");
3603
+ return { model: nextModel, thinkingLevel: this.thinkingLevel, isScoped: false, ...(notice ? { notice } : {}) };
3898
3604
  }
3899
3605
  // =========================================================================
3900
3606
  // Thinking Level Management
@@ -4582,6 +4288,7 @@ export class AgentSession {
4582
4288
  if (bindings.onError !== undefined) {
4583
4289
  this._extensionErrorListener = bindings.onError;
4584
4290
  }
4291
+ this._extensionsBound = true;
4585
4292
  this._applyExtensionBindings(this._extensionRunner);
4586
4293
  this._rebuildSystemPrompt(this.getActiveToolNames());
4587
4294
  await this._extensionRunner.emit(this._sessionStartEvent);
@@ -4924,17 +4631,8 @@ export class AgentSession {
4924
4631
  : createAllToolDefinitions(this._cwd, {
4925
4632
  read: { autoResizeImages },
4926
4633
  bash: {
4927
- operations: {
4928
- ...bashOperations,
4929
- exec: (command, cwd, options) => {
4930
- const qualified = this._adaptiveHost?.qualifyShellExecution(command);
4931
- return qualified
4932
- ? bashOperations.exec(qualified.command, cwd, { ...options, env: qualified.env })
4933
- : bashOperations.exec(command, cwd, options);
4934
- },
4935
- },
4634
+ operations: bashOperations,
4936
4635
  jobs: this._bashJobs,
4937
- getRunContext: () => this._adaptiveHost?.runContext,
4938
4636
  outputHeadTail: this.settingsManager.getBashOutputHeadTail(),
4939
4637
  outputCleanup: this.settingsManager.getBashOutputCleanup(),
4940
4638
  commandPrefix: shellCommandPrefix,
@@ -4993,16 +4691,13 @@ export class AgentSession {
4993
4691
  // Tools the new extensions register later, such as MCP tools, are pending until then.
4994
4692
  for (const name of this.getActiveToolNames())
4995
4693
  this._pendingToolNames.add(name);
4694
+ this._restoredToolNames = new Set(this.getActiveToolNames());
4996
4695
  this._buildRuntime({
4997
4696
  activeToolNames: [...this.getActiveToolNames(), ...addedDefaultTools],
4998
4697
  flagValues: previousFlagValues,
4999
4698
  includeAllExtensionTools: true,
5000
4699
  });
5001
- const hasBindings = this._extensionUIContext ||
5002
- this._extensionCommandContextActions ||
5003
- this._extensionShutdownHandler ||
5004
- this._extensionErrorListener;
5005
- if (hasBindings) {
4700
+ if (this._extensionsBound) {
5006
4701
  await options?.beforeSessionStart?.();
5007
4702
  await this._extensionRunner.emit({ type: "session_start", reason: "reload" });
5008
4703
  this._extensionRunner.reportUnhandledMcpServers();
@@ -6247,9 +5942,9 @@ export class AgentSession {
6247
5942
  // Utilities
6248
5943
  // =========================================================================
6249
5944
  /**
6250
- * Get text content of last assistant message.
5945
+ * Get text content of the last assistant reply.
6251
5946
  * Useful for /copy command.
6252
- * @returns Text content, or undefined if no assistant message exists
5947
+ * @returns Text content, or undefined if no assistant message exists or the last reply has no text
6253
5948
  */
6254
5949
  getLastAssistantText() {
6255
5950
  const lastAssistant = this.messages
@@ -6259,8 +5954,9 @@ export class AgentSession {
6259
5954
  if (m.role !== "assistant")
6260
5955
  return false;
6261
5956
  const msg = m;
6262
- // Skip aborted messages with no content
6263
- if (msg.stopReason === "aborted" && msg.content.length === 0)
5957
+ // Skip messages without text from a turn that did not end normally: aborted, failed or only
5958
+ // calling tools (#12119). A reply that ended normally stays the last reply even without text.
5959
+ if (msg.stopReason !== "stop" && !msg.content.some((c) => c.type === "text" && c.text.trim()))
6264
5960
  return false;
6265
5961
  return true;
6266
5962
  });