@humain/terminal 0.0.6 → 0.0.8

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 (493) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/README.md +17 -10
  3. package/dist/bundle/chunks/anthropic-messages-GDMGYAZB.js +6 -0
  4. package/dist/bundle/chunks/anthropic.js +75 -0
  5. package/dist/bundle/chunks/azure-openai-responses-ZN52D6YC.js +2 -0
  6. package/dist/bundle/chunks/bedrock-converse-stream.js +77 -0
  7. package/dist/bundle/chunks/chunk-3VI4HD7D.js +31 -0
  8. package/dist/bundle/chunks/chunk-6R7UI4IY.js +2 -0
  9. package/dist/bundle/chunks/chunk-72KO4OMP.js +2 -0
  10. package/dist/bundle/chunks/chunk-74NVHVNZ.js +16 -0
  11. package/dist/bundle/chunks/chunk-7DDKXS2Q.js +2 -0
  12. package/dist/bundle/chunks/chunk-ARF4OE6X.js +105 -0
  13. package/dist/bundle/chunks/chunk-BOW22LW6.js +42 -0
  14. package/dist/bundle/chunks/chunk-BZQ53VGE.js +70 -0
  15. package/dist/bundle/chunks/chunk-CBHC6EL7.js +133 -0
  16. package/dist/bundle/chunks/chunk-D7XAASZM.js +4 -0
  17. package/dist/bundle/chunks/chunk-ECWELYBH.js +17 -0
  18. package/dist/bundle/chunks/chunk-GMWCTUPB.js +2 -0
  19. package/dist/bundle/chunks/chunk-H2O6VOXT.js +11 -0
  20. package/dist/bundle/chunks/chunk-JUUC5AZY.js +2 -0
  21. package/dist/bundle/chunks/chunk-JXWJOIH4.js +2 -0
  22. package/dist/bundle/chunks/chunk-L2ZPNLYD.js +2 -0
  23. package/dist/bundle/chunks/chunk-LVVZS2NO.js +12 -0
  24. package/dist/bundle/chunks/chunk-MA4UUCYX.js +18 -0
  25. package/dist/bundle/chunks/chunk-MMFBCF6F.js +5986 -0
  26. package/dist/bundle/chunks/chunk-PGXDEOVV.js +2 -0
  27. package/dist/bundle/chunks/chunk-PJACZCIR.js +2 -0
  28. package/dist/bundle/chunks/chunk-PRRNXB7S.js +2 -0
  29. package/dist/bundle/chunks/chunk-PSKDLDLZ.js +44 -0
  30. package/dist/bundle/chunks/chunk-SGTGQNNP.js +4 -0
  31. package/dist/bundle/chunks/chunk-TEPMHNKQ.js +2 -0
  32. package/dist/bundle/chunks/chunk-TXBQIIIO.js +2 -0
  33. package/dist/bundle/chunks/chunk-WJZ4KLGL.js +2 -0
  34. package/dist/bundle/chunks/chunk-XNGRGP62.js +2 -0
  35. package/dist/bundle/chunks/dist-BXEVYJIO.js +7 -0
  36. package/dist/bundle/chunks/es-P2KNSZYR.js +9 -0
  37. package/dist/bundle/chunks/es5-FGTJ7ZFW.js +2 -0
  38. package/dist/bundle/chunks/event-streams-JOSQQSII.js +2 -0
  39. package/dist/bundle/chunks/extract-2L7ZVN7F.js +106 -0
  40. package/dist/bundle/chunks/github-copilot.js +2 -0
  41. package/dist/bundle/chunks/google-generative-ai-FF7M7XHT.js +2 -0
  42. package/dist/bundle/chunks/google-vertex-YMUBFRBA.js +2 -0
  43. package/dist/bundle/chunks/https-proxy-agent-562J2I52.js +2 -0
  44. package/dist/bundle/chunks/image-resize-worker.js +2 -0
  45. package/dist/bundle/chunks/kimi-coding.js +2 -0
  46. package/dist/bundle/chunks/mistral-conversations-O4M7IQML.js +5 -0
  47. package/dist/bundle/chunks/multipart-parser-FMGQ7342.js +3 -0
  48. package/dist/bundle/chunks/node-XY3CBY3C.js +294 -0
  49. package/dist/bundle/chunks/node-ZHY4LHC7.js +15 -0
  50. package/dist/bundle/chunks/openai-codex-responses-HRVCDY54.js +8 -0
  51. package/dist/bundle/chunks/openai-codex.js +75 -0
  52. package/dist/bundle/chunks/openai-completions-L4AHDQ5D.js +7 -0
  53. package/dist/bundle/chunks/openai-responses-4MWLJHIK.js +2 -0
  54. package/dist/bundle/chunks/openrouter-images-Y2PCWAQH.js +2 -0
  55. package/dist/bundle/chunks/openrouter.js +75 -0
  56. package/dist/bundle/chunks/pdfjs-UKQT3OWY.js +107 -0
  57. package/dist/bundle/chunks/pi-messages-57K43J6J.js +8 -0
  58. package/dist/bundle/chunks/promise-J5TGSM32.js +2 -0
  59. package/dist/bundle/chunks/radius.js +75 -0
  60. package/dist/bundle/chunks/src-QKGKDFSU.js +4 -0
  61. package/dist/bundle/chunks/undici-D6ABF53Q.js +2 -0
  62. package/dist/bundle/chunks/webapi-AFS5FDJJ.js +5 -0
  63. package/dist/bundle/chunks/xai.js +2 -0
  64. package/dist/bundle/cli.js +3 -0
  65. package/dist/bundle/client.js +2 -0
  66. package/dist/bundle/index.js +2 -0
  67. package/dist/bundle/rpc-entry.js +3 -0
  68. package/dist/cli/args.d.ts +1 -0
  69. package/dist/cli/args.d.ts.map +1 -1
  70. package/dist/cli/args.js +29 -9
  71. package/dist/cli/args.js.map +1 -1
  72. package/dist/cli/file-processor.d.ts.map +1 -1
  73. package/dist/cli/file-processor.js +2 -1
  74. package/dist/cli/file-processor.js.map +1 -1
  75. package/dist/cli/startup-ui.d.ts.map +1 -1
  76. package/dist/cli/startup-ui.js +2 -1
  77. package/dist/cli/startup-ui.js.map +1 -1
  78. package/dist/config.d.ts +1 -0
  79. package/dist/config.d.ts.map +1 -1
  80. package/dist/config.js +19 -11
  81. package/dist/config.js.map +1 -1
  82. package/dist/core/agent-session.d.ts +62 -15
  83. package/dist/core/agent-session.d.ts.map +1 -1
  84. package/dist/core/agent-session.js +240 -104
  85. package/dist/core/agent-session.js.map +1 -1
  86. package/dist/core/auth-storage.d.ts.map +1 -1
  87. package/dist/core/auth-storage.js +6 -7
  88. package/dist/core/auth-storage.js.map +1 -1
  89. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  90. package/dist/core/compaction/branch-summarization.js +7 -3
  91. package/dist/core/compaction/branch-summarization.js.map +1 -1
  92. package/dist/core/compaction/compaction.d.ts +9 -3
  93. package/dist/core/compaction/compaction.d.ts.map +1 -1
  94. package/dist/core/compaction/compaction.js +59 -36
  95. package/dist/core/compaction/compaction.js.map +1 -1
  96. package/dist/core/defaults.d.ts +1 -0
  97. package/dist/core/defaults.d.ts.map +1 -1
  98. package/dist/core/defaults.js +9 -0
  99. package/dist/core/defaults.js.map +1 -1
  100. package/dist/core/extensions/index.d.ts +2 -2
  101. package/dist/core/extensions/index.d.ts.map +1 -1
  102. package/dist/core/extensions/index.js +1 -1
  103. package/dist/core/extensions/index.js.map +1 -1
  104. package/dist/core/extensions/loader.d.ts.map +1 -1
  105. package/dist/core/extensions/loader.js +115 -48
  106. package/dist/core/extensions/loader.js.map +1 -1
  107. package/dist/core/extensions/runner.d.ts +5 -0
  108. package/dist/core/extensions/runner.d.ts.map +1 -1
  109. package/dist/core/extensions/runner.js +44 -1
  110. package/dist/core/extensions/runner.js.map +1 -1
  111. package/dist/core/extensions/types.d.ts +56 -10
  112. package/dist/core/extensions/types.d.ts.map +1 -1
  113. package/dist/core/extensions/types.js +3 -0
  114. package/dist/core/extensions/types.js.map +1 -1
  115. package/dist/core/footer-data-provider.d.ts +1 -1
  116. package/dist/core/footer-data-provider.js +1 -1
  117. package/dist/core/footer-data-provider.js.map +1 -1
  118. package/dist/core/keybindings.d.ts +20 -19
  119. package/dist/core/keybindings.d.ts.map +1 -1
  120. package/dist/core/keybindings.js +26 -5
  121. package/dist/core/keybindings.js.map +1 -1
  122. package/dist/core/model-config.d.ts +5 -0
  123. package/dist/core/model-config.d.ts.map +1 -1
  124. package/dist/core/model-config.js +3 -1
  125. package/dist/core/model-config.js.map +1 -1
  126. package/dist/core/model-resolver.d.ts +1 -0
  127. package/dist/core/model-resolver.d.ts.map +1 -1
  128. package/dist/core/model-resolver.js +14 -8
  129. package/dist/core/model-resolver.js.map +1 -1
  130. package/dist/core/models-store.d.ts.map +1 -1
  131. package/dist/core/models-store.js +2 -1
  132. package/dist/core/models-store.js.map +1 -1
  133. package/dist/core/package-manager.d.ts.map +1 -1
  134. package/dist/core/package-manager.js +22 -14
  135. package/dist/core/package-manager.js.map +1 -1
  136. package/dist/core/pi-manifest.d.ts.map +1 -1
  137. package/dist/core/pi-manifest.js +2 -1
  138. package/dist/core/pi-manifest.js.map +1 -1
  139. package/dist/core/remote-catalog-provider.d.ts.map +1 -1
  140. package/dist/core/remote-catalog-provider.js +2 -1
  141. package/dist/core/remote-catalog-provider.js.map +1 -1
  142. package/dist/core/resource-loader.d.ts.map +1 -1
  143. package/dist/core/resource-loader.js +3 -2
  144. package/dist/core/resource-loader.js.map +1 -1
  145. package/dist/core/sdk.d.ts +2 -2
  146. package/dist/core/sdk.d.ts.map +1 -1
  147. package/dist/core/sdk.js +10 -3
  148. package/dist/core/sdk.js.map +1 -1
  149. package/dist/core/session-export.d.ts +4 -0
  150. package/dist/core/session-export.d.ts.map +1 -0
  151. package/dist/core/session-export.js +32 -0
  152. package/dist/core/session-export.js.map +1 -0
  153. package/dist/core/session-manager.d.ts.map +1 -1
  154. package/dist/core/session-manager.js +6 -3
  155. package/dist/core/session-manager.js.map +1 -1
  156. package/dist/core/settings-diagnostics.d.ts +9 -0
  157. package/dist/core/settings-diagnostics.d.ts.map +1 -0
  158. package/dist/core/settings-diagnostics.js +21 -0
  159. package/dist/core/settings-diagnostics.js.map +1 -0
  160. package/dist/core/settings-manager.d.ts +17 -1
  161. package/dist/core/settings-manager.d.ts.map +1 -1
  162. package/dist/core/settings-manager.js +68 -10
  163. package/dist/core/settings-manager.js.map +1 -1
  164. package/dist/core/skills.d.ts.map +1 -1
  165. package/dist/core/skills.js +51 -33
  166. package/dist/core/skills.js.map +1 -1
  167. package/dist/core/slash-commands.d.ts.map +1 -1
  168. package/dist/core/slash-commands.js +2 -1
  169. package/dist/core/slash-commands.js.map +1 -1
  170. package/dist/core/system-prompt.d.ts.map +1 -1
  171. package/dist/core/system-prompt.js +11 -2
  172. package/dist/core/system-prompt.js.map +1 -1
  173. package/dist/core/tools/bash.d.ts +16 -3
  174. package/dist/core/tools/bash.d.ts.map +1 -1
  175. package/dist/core/tools/bash.js +62 -29
  176. package/dist/core/tools/bash.js.map +1 -1
  177. package/dist/core/tools/edit-diff.d.ts +0 -5
  178. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  179. package/dist/core/tools/edit-diff.js +2 -5
  180. package/dist/core/tools/edit-diff.js.map +1 -1
  181. package/dist/core/tools/edit.d.ts.map +1 -1
  182. package/dist/core/tools/edit.js +20 -4
  183. package/dist/core/tools/edit.js.map +1 -1
  184. package/dist/core/tools/index.d.ts +4 -1
  185. package/dist/core/tools/index.d.ts.map +1 -1
  186. package/dist/core/tools/index.js +19 -1
  187. package/dist/core/tools/index.js.map +1 -1
  188. package/dist/core/tools/powershell.d.ts +16 -0
  189. package/dist/core/tools/powershell.d.ts.map +1 -0
  190. package/dist/core/tools/powershell.js +39 -0
  191. package/dist/core/tools/powershell.js.map +1 -0
  192. package/dist/core/tools/subagent.d.ts.map +1 -1
  193. package/dist/core/tools/subagent.js +4 -1
  194. package/dist/core/tools/subagent.js.map +1 -1
  195. package/dist/core/trust-manager.d.ts.map +1 -1
  196. package/dist/core/trust-manager.js +2 -1
  197. package/dist/core/trust-manager.js.map +1 -1
  198. package/dist/extensions/llama/client.d.ts +6 -0
  199. package/dist/extensions/llama/client.d.ts.map +1 -1
  200. package/dist/extensions/llama/client.js +7 -0
  201. package/dist/extensions/llama/client.js.map +1 -1
  202. package/dist/extensions/llama/index.d.ts.map +1 -1
  203. package/dist/extensions/llama/index.js +2 -0
  204. package/dist/extensions/llama/index.js.map +1 -1
  205. package/dist/extensions/llama/provider.d.ts +3 -1
  206. package/dist/extensions/llama/provider.d.ts.map +1 -1
  207. package/dist/extensions/llama/provider.js +29 -4
  208. package/dist/extensions/llama/provider.js.map +1 -1
  209. package/dist/humain/agent-execution-protocol.d.ts +1 -217
  210. package/dist/humain/agent-execution-protocol.d.ts.map +1 -1
  211. package/dist/humain/agent-execution-protocol.js +1 -203
  212. package/dist/humain/agent-execution-protocol.js.map +1 -1
  213. package/dist/humain/bedrock-provider/vendor/index.bundle.mjs +107 -16
  214. package/dist/humain/mcp-adapter/vendor/CHANGELOG.md +82 -0
  215. package/dist/humain/mcp-adapter/vendor/README.md +47 -15
  216. package/dist/humain/mcp-adapter/vendor/cli.js +4 -4
  217. package/dist/humain/mcp-adapter/vendor/commands.ts +5 -3
  218. package/dist/humain/mcp-adapter/vendor/config.ts +46 -5
  219. package/dist/humain/mcp-adapter/vendor/direct-tools.ts +103 -92
  220. package/dist/humain/mcp-adapter/vendor/dist/agent-dir.d.ts +10 -0
  221. package/dist/humain/mcp-adapter/vendor/dist/agent-dir.js +63 -0
  222. package/dist/humain/mcp-adapter/vendor/dist/agent-dir.js.map +1 -0
  223. package/dist/humain/mcp-adapter/vendor/dist/agent-plugin-loader.d.ts +8 -0
  224. package/dist/humain/mcp-adapter/vendor/dist/agent-plugin-loader.js +356 -0
  225. package/dist/humain/mcp-adapter/vendor/dist/agent-plugin-loader.js.map +1 -0
  226. package/dist/humain/mcp-adapter/vendor/dist/config.d.ts +123 -0
  227. package/dist/humain/mcp-adapter/vendor/dist/config.js +1088 -0
  228. package/dist/humain/mcp-adapter/vendor/dist/config.js.map +1 -0
  229. package/dist/humain/mcp-adapter/vendor/dist/mcp-bearer-store.d.ts +24 -0
  230. package/dist/humain/mcp-adapter/vendor/dist/mcp-bearer-store.js +336 -0
  231. package/dist/humain/mcp-adapter/vendor/dist/mcp-bearer-store.js.map +1 -0
  232. package/dist/humain/mcp-adapter/vendor/dist/metadata-cache.d.ts +19 -0
  233. package/dist/humain/mcp-adapter/vendor/dist/metadata-cache.js +319 -0
  234. package/dist/humain/mcp-adapter/vendor/dist/metadata-cache.js.map +1 -0
  235. package/dist/humain/mcp-adapter/vendor/dist/package-mcp-loader.d.ts +2 -0
  236. package/dist/humain/mcp-adapter/vendor/dist/package-mcp-loader.js +156 -0
  237. package/dist/humain/mcp-adapter/vendor/dist/package-mcp-loader.js.map +1 -0
  238. package/dist/humain/mcp-adapter/vendor/dist/resource-tools.d.ts +1 -0
  239. package/dist/humain/mcp-adapter/vendor/dist/resource-tools.js +15 -0
  240. package/dist/humain/mcp-adapter/vendor/dist/resource-tools.js.map +1 -0
  241. package/dist/humain/mcp-adapter/vendor/dist/types.d.ts +566 -0
  242. package/dist/humain/mcp-adapter/vendor/dist/types.js +287 -0
  243. package/dist/humain/mcp-adapter/vendor/dist/types.js.map +1 -0
  244. package/dist/humain/mcp-adapter/vendor/dist/ui-app-bridge-helpers.d.ts +6 -0
  245. package/dist/humain/mcp-adapter/vendor/dist/ui-app-bridge-helpers.js +37 -0
  246. package/dist/humain/mcp-adapter/vendor/dist/ui-app-bridge-helpers.js.map +1 -0
  247. package/dist/humain/mcp-adapter/vendor/dist/ui-stream-types.d.ts +104 -0
  248. package/dist/humain/mcp-adapter/vendor/dist/ui-stream-types.js +59 -0
  249. package/dist/humain/mcp-adapter/vendor/dist/ui-stream-types.js.map +1 -0
  250. package/dist/humain/mcp-adapter/vendor/dist/ui-tool-visibility.d.ts +4 -0
  251. package/dist/humain/mcp-adapter/vendor/dist/ui-tool-visibility.js +27 -0
  252. package/dist/humain/mcp-adapter/vendor/dist/ui-tool-visibility.js.map +1 -0
  253. package/dist/humain/mcp-adapter/vendor/dist/utils.d.ts +32 -0
  254. package/dist/humain/mcp-adapter/vendor/dist/utils.js +338 -0
  255. package/dist/humain/mcp-adapter/vendor/dist/utils.js.map +1 -0
  256. package/dist/humain/mcp-adapter/vendor/failure-backoff.ts +23 -0
  257. package/dist/humain/mcp-adapter/vendor/index.bundle.mjs +4870 -3878
  258. package/dist/humain/mcp-adapter/vendor/index.ts +294 -88
  259. package/dist/humain/mcp-adapter/vendor/init.ts +41 -30
  260. package/dist/humain/mcp-adapter/vendor/lifecycle.ts +16 -8
  261. package/dist/humain/mcp-adapter/vendor/mcp-auth-flow.ts +124 -32
  262. package/dist/humain/mcp-adapter/vendor/mcp-bearer-store.ts +0 -2
  263. package/dist/humain/mcp-adapter/vendor/mcp-code.ts +2 -0
  264. package/dist/humain/mcp-adapter/vendor/mcp-oauth-provider.ts +155 -16
  265. package/dist/humain/mcp-adapter/vendor/mcp-output-guard.ts +95 -7
  266. package/dist/humain/mcp-adapter/vendor/mcp-probe.ts +18 -4
  267. package/dist/humain/mcp-adapter/vendor/mcp-references.ts +376 -0
  268. package/dist/humain/mcp-adapter/vendor/mcp-status.ts +8 -19
  269. package/dist/humain/mcp-adapter/vendor/metadata-cache.ts +20 -12
  270. package/dist/humain/mcp-adapter/vendor/namespace-tools.ts +276 -0
  271. package/dist/humain/mcp-adapter/vendor/package.json +26 -8
  272. package/dist/humain/mcp-adapter/vendor/proxy-modes.ts +128 -32
  273. package/dist/humain/mcp-adapter/vendor/request-headers-command.ts +1 -1
  274. package/dist/humain/mcp-adapter/vendor/search-ranking.ts +2 -0
  275. package/dist/humain/mcp-adapter/vendor/server-manager.ts +69 -12
  276. package/dist/humain/mcp-adapter/vendor/state.ts +1 -3
  277. package/dist/humain/mcp-adapter/vendor/tool-result-renderer.ts +16 -2
  278. package/dist/humain/mcp-adapter/vendor/types.ts +51 -2
  279. package/dist/humain/mcp-adapter/vendor/ui-server.ts +3 -19
  280. package/dist/humain/mcp-adapter/vendor/ui-session.ts +2 -1
  281. package/dist/humain/mcp-adapter/vendor/utils.ts +21 -19
  282. package/dist/humain/mcp-adapter.d.ts.map +1 -1
  283. package/dist/humain/mcp-adapter.js +4 -0
  284. package/dist/humain/mcp-adapter.js.map +1 -1
  285. package/dist/humain/web-access/vendor/chrome-cookies.d.ts +14 -0
  286. package/dist/humain/web-access/vendor/chrome-cookies.d.ts.map +1 -1
  287. package/dist/humain/web-access/vendor/chrome-cookies.js +85 -33
  288. package/dist/humain/web-access/vendor/chrome-cookies.js.map +1 -1
  289. package/dist/humain/web-access/vendor/credential-source.d.ts +1 -1
  290. package/dist/humain/web-access/vendor/credential-source.d.ts.map +1 -1
  291. package/dist/humain/web-access/vendor/credential-source.js +3 -1
  292. package/dist/humain/web-access/vendor/credential-source.js.map +1 -1
  293. package/dist/humain/web-access/vendor/curator-page.d.ts +2 -29
  294. package/dist/humain/web-access/vendor/curator-page.d.ts.map +1 -1
  295. package/dist/humain/web-access/vendor/curator-page.js +10 -1
  296. package/dist/humain/web-access/vendor/curator-page.js.map +1 -1
  297. package/dist/humain/web-access/vendor/curator-server.d.ts +2 -29
  298. package/dist/humain/web-access/vendor/curator-server.d.ts.map +1 -1
  299. package/dist/humain/web-access/vendor/curator-server.js +4 -0
  300. package/dist/humain/web-access/vendor/curator-server.js.map +1 -1
  301. package/dist/humain/web-access/vendor/extract.d.ts +11 -0
  302. package/dist/humain/web-access/vendor/extract.d.ts.map +1 -1
  303. package/dist/humain/web-access/vendor/extract.js +163 -20
  304. package/dist/humain/web-access/vendor/extract.js.map +1 -1
  305. package/dist/humain/web-access/vendor/fetch-params.d.ts +2 -0
  306. package/dist/humain/web-access/vendor/fetch-params.d.ts.map +1 -1
  307. package/dist/humain/web-access/vendor/fetch-params.js +11 -0
  308. package/dist/humain/web-access/vendor/fetch-params.js.map +1 -1
  309. package/dist/humain/web-access/vendor/gemini-adc.d.ts +10 -0
  310. package/dist/humain/web-access/vendor/gemini-adc.d.ts.map +1 -0
  311. package/dist/humain/web-access/vendor/gemini-adc.js +268 -0
  312. package/dist/humain/web-access/vendor/gemini-adc.js.map +1 -0
  313. package/dist/humain/web-access/vendor/gemini-api.d.ts +7 -1
  314. package/dist/humain/web-access/vendor/gemini-api.d.ts.map +1 -1
  315. package/dist/humain/web-access/vendor/gemini-api.js +51 -15
  316. package/dist/humain/web-access/vendor/gemini-api.js.map +1 -1
  317. package/dist/humain/web-access/vendor/gemini-search.d.ts +9 -4
  318. package/dist/humain/web-access/vendor/gemini-search.d.ts.map +1 -1
  319. package/dist/humain/web-access/vendor/gemini-search.js +63 -21
  320. package/dist/humain/web-access/vendor/gemini-search.js.map +1 -1
  321. package/dist/humain/web-access/vendor/gemini-url-context.d.ts.map +1 -1
  322. package/dist/humain/web-access/vendor/gemini-url-context.js +3 -2
  323. package/dist/humain/web-access/vendor/gemini-url-context.js.map +1 -1
  324. package/dist/humain/web-access/vendor/gemini-web-config.d.ts +8 -1
  325. package/dist/humain/web-access/vendor/gemini-web-config.d.ts.map +1 -1
  326. package/dist/humain/web-access/vendor/gemini-web-config.js +49 -4
  327. package/dist/humain/web-access/vendor/gemini-web-config.js.map +1 -1
  328. package/dist/humain/web-access/vendor/gemini-web.d.ts +2 -1
  329. package/dist/humain/web-access/vendor/gemini-web.d.ts.map +1 -1
  330. package/dist/humain/web-access/vendor/gemini-web.js +8 -3
  331. package/dist/humain/web-access/vendor/gemini-web.js.map +1 -1
  332. package/dist/humain/web-access/vendor/github-api.d.ts +1 -1
  333. package/dist/humain/web-access/vendor/github-api.d.ts.map +1 -1
  334. package/dist/humain/web-access/vendor/github-api.js +6 -4
  335. package/dist/humain/web-access/vendor/github-api.js.map +1 -1
  336. package/dist/humain/web-access/vendor/github-extract.d.ts.map +1 -1
  337. package/dist/humain/web-access/vendor/github-extract.js +50 -3
  338. package/dist/humain/web-access/vendor/github-extract.js.map +1 -1
  339. package/dist/humain/web-access/vendor/github-issue-pr.d.ts +27 -0
  340. package/dist/humain/web-access/vendor/github-issue-pr.d.ts.map +1 -0
  341. package/dist/humain/web-access/vendor/github-issue-pr.js +701 -0
  342. package/dist/humain/web-access/vendor/github-issue-pr.js.map +1 -0
  343. package/dist/humain/web-access/vendor/index.d.ts +3 -31
  344. package/dist/humain/web-access/vendor/index.d.ts.map +1 -1
  345. package/dist/humain/web-access/vendor/index.js +643 -530
  346. package/dist/humain/web-access/vendor/index.js.map +1 -1
  347. package/dist/humain/web-access/vendor/kimi-search.d.ts +5 -0
  348. package/dist/humain/web-access/vendor/kimi-search.d.ts.map +1 -0
  349. package/dist/humain/web-access/vendor/kimi-search.js +228 -0
  350. package/dist/humain/web-access/vendor/kimi-search.js.map +1 -0
  351. package/dist/humain/web-access/vendor/openai-search.d.ts +3 -0
  352. package/dist/humain/web-access/vendor/openai-search.d.ts.map +1 -1
  353. package/dist/humain/web-access/vendor/openai-search.js +89 -16
  354. package/dist/humain/web-access/vendor/openai-search.js.map +1 -1
  355. package/dist/humain/web-access/vendor/page-query.d.ts.map +1 -1
  356. package/dist/humain/web-access/vendor/page-query.js +56 -8
  357. package/dist/humain/web-access/vendor/page-query.js.map +1 -1
  358. package/dist/humain/web-access/vendor/ssrf-protection.js +6 -1
  359. package/dist/humain/web-access/vendor/ssrf-protection.js.map +1 -1
  360. package/dist/humain/web-access/vendor/utils.d.ts +12 -0
  361. package/dist/humain/web-access/vendor/utils.d.ts.map +1 -1
  362. package/dist/humain/web-access/vendor/utils.js +343 -1
  363. package/dist/humain/web-access/vendor/utils.js.map +1 -1
  364. package/dist/humain/web-access/vendor/xcrawl.d.ts +4 -0
  365. package/dist/humain/web-access/vendor/xcrawl.d.ts.map +1 -0
  366. package/dist/humain/web-access/vendor/xcrawl.js +251 -0
  367. package/dist/humain/web-access/vendor/xcrawl.js.map +1 -0
  368. package/dist/humain/web-access/vendor/youtube-extract.js +2 -2
  369. package/dist/humain/web-access/vendor/youtube-extract.js.map +1 -1
  370. package/dist/index.d.ts +6 -5
  371. package/dist/index.d.ts.map +1 -1
  372. package/dist/index.js +5 -4
  373. package/dist/index.js.map +1 -1
  374. package/dist/main.d.ts +3 -0
  375. package/dist/main.d.ts.map +1 -1
  376. package/dist/main.js +19 -14
  377. package/dist/main.js.map +1 -1
  378. package/dist/migrations.d.ts.map +1 -1
  379. package/dist/migrations.js +4 -3
  380. package/dist/migrations.js.map +1 -1
  381. package/dist/modes/interactive/components/model-selector.d.ts +9 -3
  382. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  383. package/dist/modes/interactive/components/model-selector.js +53 -10
  384. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  385. package/dist/modes/interactive/components/settings-selector.d.ts +9 -2
  386. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  387. package/dist/modes/interactive/components/settings-selector.js +128 -55
  388. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  389. package/dist/modes/interactive/components/settings-submenu.d.ts +72 -0
  390. package/dist/modes/interactive/components/settings-submenu.d.ts.map +1 -0
  391. package/dist/modes/interactive/components/settings-submenu.js +151 -0
  392. package/dist/modes/interactive/components/settings-submenu.js.map +1 -0
  393. package/dist/modes/interactive/components/thinking-selector.d.ts +15 -3
  394. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
  395. package/dist/modes/interactive/components/thinking-selector.js +68 -17
  396. package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
  397. package/dist/modes/interactive/external-editor.d.ts.map +1 -1
  398. package/dist/modes/interactive/external-editor.js +2 -1
  399. package/dist/modes/interactive/external-editor.js.map +1 -1
  400. package/dist/modes/interactive/interactive-mode.d.ts +15 -0
  401. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  402. package/dist/modes/interactive/interactive-mode.js +224 -130
  403. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  404. package/dist/modes/interactive/session-share.d.ts +16 -0
  405. package/dist/modes/interactive/session-share.d.ts.map +1 -0
  406. package/dist/modes/interactive/session-share.js +188 -0
  407. package/dist/modes/interactive/session-share.js.map +1 -0
  408. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  409. package/dist/modes/interactive/theme/theme.js +6 -5
  410. package/dist/modes/interactive/theme/theme.js.map +1 -1
  411. package/dist/modes/json-event.d.ts +16 -13
  412. package/dist/modes/json-event.d.ts.map +1 -1
  413. package/dist/modes/json-event.js +20 -6
  414. package/dist/modes/json-event.js.map +1 -1
  415. package/dist/modes/rpc/rpc-client.d.ts +7 -0
  416. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  417. package/dist/modes/rpc/rpc-client.js +10 -2
  418. package/dist/modes/rpc/rpc-client.js.map +1 -1
  419. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  420. package/dist/modes/rpc/rpc-mode.js +3 -0
  421. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  422. package/dist/modes/rpc/rpc-types.d.ts +14 -7
  423. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  424. package/dist/modes/rpc/rpc-types.js.map +1 -1
  425. package/dist/package-manager-cli.d.ts +1 -0
  426. package/dist/package-manager-cli.d.ts.map +1 -1
  427. package/dist/package-manager-cli.js +189 -3
  428. package/dist/package-manager-cli.js.map +1 -1
  429. package/dist/utils/changelog.d.ts +1 -1
  430. package/dist/utils/changelog.d.ts.map +1 -1
  431. package/dist/utils/changelog.js +12 -2
  432. package/dist/utils/changelog.js.map +1 -1
  433. package/dist/utils/frontmatter.d.ts.map +1 -1
  434. package/dist/utils/frontmatter.js +2 -1
  435. package/dist/utils/frontmatter.js.map +1 -1
  436. package/dist/utils/management-http.d.ts +5 -3
  437. package/dist/utils/management-http.d.ts.map +1 -1
  438. package/dist/utils/management-http.js +14 -10
  439. package/dist/utils/management-http.js.map +1 -1
  440. package/dist/utils/shell.d.ts +3 -0
  441. package/dist/utils/shell.d.ts.map +1 -1
  442. package/dist/utils/shell.js +23 -9
  443. package/dist/utils/shell.js.map +1 -1
  444. package/dist/utils/syntax-highlight.d.ts +1 -0
  445. package/dist/utils/syntax-highlight.d.ts.map +1 -1
  446. package/dist/utils/syntax-highlight.js +64 -1
  447. package/dist/utils/syntax-highlight.js.map +1 -1
  448. package/dist/utils/text.d.ts +8 -0
  449. package/dist/utils/text.d.ts.map +1 -0
  450. package/dist/utils/text.js +9 -0
  451. package/dist/utils/text.js.map +1 -0
  452. package/dist/utils/version-check.js +4 -4
  453. package/dist/utils/version-check.js.map +1 -1
  454. package/docs/compaction.md +17 -0
  455. package/docs/custom-provider.md +12 -9
  456. package/docs/environment-variables.md +11 -8
  457. package/docs/extensions.md +35 -7
  458. package/docs/json.md +7 -2
  459. package/docs/keybindings.md +9 -9
  460. package/docs/llama-cpp.md +2 -0
  461. package/docs/models.md +8 -2
  462. package/docs/packages.md +2 -2
  463. package/docs/quickstart.md +1 -1
  464. package/docs/rpc.md +32 -3
  465. package/docs/sdk.md +7 -2
  466. package/docs/settings.md +23 -7
  467. package/docs/skills.md +3 -2
  468. package/docs/terminal-setup.md +20 -0
  469. package/docs/usage.md +14 -10
  470. package/docs/windows.md +15 -1
  471. package/examples/extensions/border-status-editor.ts +1 -1
  472. package/examples/extensions/custom-provider-anthropic/package-lock.json +70 -8
  473. package/examples/extensions/custom-provider-anthropic/package.json +2 -2
  474. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  475. package/examples/extensions/git-checkpoint.ts +2 -2
  476. package/examples/extensions/gondolin/package-lock.json +2 -2
  477. package/examples/extensions/gondolin/package.json +1 -1
  478. package/examples/extensions/notify.ts +3 -1
  479. package/examples/extensions/sandbox/package-lock.json +14 -40
  480. package/examples/extensions/sandbox/package.json +2 -2
  481. package/examples/extensions/titlebar-spinner.ts +1 -1
  482. package/examples/extensions/with-deps/package-lock.json +4 -4
  483. package/examples/extensions/with-deps/package.json +1 -1
  484. package/examples/rpc-extension-ui.ts +1 -1
  485. package/examples/sdk/06-extensions.ts +1 -1
  486. package/examples/sdk/README.md +1 -1
  487. package/npm-shrinkwrap.json +293 -221
  488. package/package.json +21 -18
  489. package/src/humain/mcp-adapter/UPSTREAM.md +15 -5
  490. package/src/humain/mcp-adapter/upstream.json +4 -3
  491. package/src/humain/mcp-adapter/vendor/CHANGELOG.md +82 -0
  492. package/src/humain/web-access/UPSTREAM.md +1 -1
  493. package/src/humain/web-access/upstream.json +6 -4
@@ -12,26 +12,26 @@
12
12
  *
13
13
  * Modes use this class and add their own I/O layer on top.
14
14
  */
15
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
15
+ import { readFileSync } from "node:fs";
16
16
  import { basename, dirname } from "node:path";
17
17
  import { contentText } from "@earendil-works/pi-ai";
18
18
  import { clampThinkingLevel, cleanupSessionResources, getSupportedThinkingLevels, isContextOverflow, isRecoverableLength, isRetryableAssistantError, modelsAreEqual, resetApiProviders, streamSimple, } from "@earendil-works/pi-ai/compat";
19
19
  import { getThemeByName, theme } from "../modes/interactive/theme/theme.js";
20
20
  import { stripFrontmatter } from "../utils/frontmatter.js";
21
- import { resolvePath } from "../utils/paths.js";
22
21
  import { sleep } from "../utils/sleep.js";
23
22
  import { normalizeToolResultImages } from "../utils/tool-result-images.js";
24
23
  import { formatNoApiKeyFoundMessage, formatNoModelSelectedMessage } from "./auth-guidance.js";
25
24
  import { executeBashWithOperations } from "./bash-executor.js";
26
25
  import { calculateContextTokens, collectEntriesForBranchSummary, compact, estimateContextTokens, estimateTokens, generateBranchSummary, prepareCompaction, shouldCompact, } from "./compaction/index.js";
27
- import { DEFAULT_THINKING_LEVEL } from "./defaults.js";
26
+ import { DEFAULT_THINKING_LEVEL, THINKING_LEVEL_OPTIONS } from "./defaults.js";
28
27
  import { exportSessionToHtml } from "./export-html/index.js";
29
28
  import { createToolHtmlRenderer } from "./export-html/tool-renderer.js";
30
29
  import { ExtensionRunner, wrapRegisteredTools, } from "./extensions/index.js";
31
30
  import { emitSessionShutdownEvent } from "./extensions/runner.js";
32
31
  import { ModelRegistry } from "./model-registry.js";
33
32
  import { expandPromptTemplate } from "./prompt-templates.js";
34
- import { CURRENT_SESSION_VERSION, getLatestCompactionEntry } from "./session-manager.js";
33
+ import { exportSessionToJsonl } from "./session-export.js";
34
+ import { getLatestCompactionEntry } from "./session-manager.js";
35
35
  import { createSyntheticSourceInfo } from "./source-info.js";
36
36
  import { buildSystemPrompt } from "./system-prompt.js";
37
37
  import { createLocalBashOperations } from "./tools/bash.js";
@@ -71,8 +71,6 @@ function estimateMessagesTokens(messages) {
71
71
  // ============================================================================
72
72
  // Constants
73
73
  // ============================================================================
74
- /** Standard thinking levels */
75
- const THINKING_LEVELS = ["off", "minimal", "low", "medium", "high"];
76
74
  // ============================================================================
77
75
  // AgentSession Class
78
76
  // ============================================================================
@@ -86,6 +84,8 @@ export class AgentSession {
86
84
  this._followUpMessages = [];
87
85
  /** Messages queued to be included with the next user prompt as context ("asides"). */
88
86
  this._pendingNextTurnMessages = [];
87
+ /** Context-only custom messages queued during a run, flushed once the current turn's tool results are in. */
88
+ this._pendingCustomMessages = [];
89
89
  // Compaction state
90
90
  this._compactionAbortController = undefined;
91
91
  this._autoCompactionAbortController = undefined;
@@ -171,6 +171,14 @@ export class AgentSession {
171
171
  }
172
172
  }
173
173
  }
174
+ // A turn ends after its assistant message and every tool result has been appended,
175
+ // so this is the first point in the run where a context-only custom message can be
176
+ // inserted without landing between a tool call and its result. Flushing after the
177
+ // extension and listener dispatch above also picks up messages that turn_end
178
+ // handlers queued.
179
+ if (event.type === "turn_end") {
180
+ this._flushPendingCustomMessages();
181
+ }
174
182
  };
175
183
  this.agent = config.agent;
176
184
  this.sessionManager = config.sessionManager;
@@ -307,18 +315,33 @@ export class AgentSession {
307
315
  };
308
316
  };
309
317
  }
318
+ async _compactBeforeNextAssistantResponse(context) {
319
+ const model = this.model;
320
+ const settings = this.settingsManager.getCompactionSettings();
321
+ if (!model ||
322
+ model.contextWindow <= 0 ||
323
+ !shouldCompact(estimateContextTokens(context.messages).tokens, model.contextWindow, settings)) {
324
+ return context;
325
+ }
326
+ await this._runAutoCompaction("threshold", false);
327
+ return {
328
+ ...context,
329
+ messages: this.agent.state.messages.slice(),
330
+ };
331
+ }
310
332
  _installAgentNextTurnRefresh() {
311
333
  const previousPrepareNextTurnWithContext = this.agent.prepareNextTurnWithContext ??
312
334
  (this.agent.prepareNextTurn
313
335
  ? async (_turn, signal) => await this.agent.prepareNextTurn?.(signal)
314
336
  : undefined);
315
337
  this.agent.prepareNextTurnWithContext = async (turn, signal) => {
316
- const previousSnapshot = await previousPrepareNextTurnWithContext?.(turn, signal);
317
- const previousContext = previousSnapshot?.context ?? turn.context;
338
+ const context = await this._compactBeforeNextAssistantResponse(turn.context);
339
+ const previousSnapshot = await previousPrepareNextTurnWithContext?.({ ...turn, context }, signal);
340
+ const nextContext = previousSnapshot?.context ?? context;
318
341
  return {
319
342
  ...previousSnapshot,
320
343
  context: {
321
- ...previousContext,
344
+ ...nextContext,
322
345
  systemPrompt: this._systemPromptOverride ?? this._baseSystemPrompt,
323
346
  tools: this.agent.state.tools.slice(),
324
347
  },
@@ -343,6 +366,11 @@ export class AgentSession {
343
366
  followUp: [...this._followUpMessages],
344
367
  });
345
368
  }
369
+ async _emitSessionCompactFailed(event) {
370
+ if (this._extensionRunner.hasHandlers("session_compact_failed")) {
371
+ await this._extensionRunner.emit({ type: "session_compact_failed", ...event });
372
+ }
373
+ }
346
374
  _getIdleWaitPromise() {
347
375
  if (!this._idleWaitPromise) {
348
376
  this._idleWaitPromise = new Promise((resolve) => {
@@ -730,6 +758,7 @@ export class AgentSession {
730
758
  finally {
731
759
  this._systemPromptOverride = undefined;
732
760
  this._flushPendingBashMessages();
761
+ this._flushPendingCustomMessages();
733
762
  await this._emitAgentSettled();
734
763
  }
735
764
  }
@@ -819,8 +848,9 @@ export class AgentSession {
819
848
  preflightResult?.(true);
820
849
  return;
821
850
  }
822
- // Flush any pending bash messages before the new prompt
851
+ // Flush any pending bash and custom messages before the new prompt
823
852
  this._flushPendingBashMessages();
853
+ this._flushPendingCustomMessages();
824
854
  // Validate model
825
855
  if (!this.model) {
826
856
  throw new Error(formatNoModelSelectedMessage());
@@ -1034,8 +1064,9 @@ export class AgentSession {
1034
1064
  /**
1035
1065
  * Send a custom message to the session. Creates a CustomMessageEntry.
1036
1066
  *
1037
- * Handles three cases:
1067
+ * Handles four cases:
1038
1068
  * - Streaming: queues message, processed when loop pulls from queue
1069
+ * - Streaming + triggerTurn false: appended to state/session once the current turn ends
1039
1070
  * - Not streaming + triggerTurn: appends to state/session, starts new turn
1040
1071
  * - Not streaming + no trigger: appends to state/session, no turn
1041
1072
  *
@@ -1067,11 +1098,34 @@ export class AgentSession {
1067
1098
  else if (options?.triggerTurn) {
1068
1099
  await this._runAgentPrompt(appMessage);
1069
1100
  }
1101
+ else if (this.isStreaming) {
1102
+ // Appending now would put the message between an assistant tool call and its
1103
+ // result, which providers that validate message order reject on replay. Defer
1104
+ // to the end of the turn. Nothing is emitted yet: message events must not
1105
+ // describe messages the session tree does not contain.
1106
+ this._pendingCustomMessages.push(appMessage);
1107
+ }
1070
1108
  else {
1071
- this.agent.state.messages.push(appMessage);
1072
- this.sessionManager.appendCustomMessageEntry(message.customType, message.content, message.display, message.details);
1073
- this._emit({ type: "message_start", message: appMessage });
1074
- this._emit({ type: "message_end", message: appMessage });
1109
+ this._appendCustomMessage(appMessage);
1110
+ }
1111
+ }
1112
+ _appendCustomMessage(appMessage) {
1113
+ this.agent.state.messages.push(appMessage);
1114
+ this.sessionManager.appendCustomMessageEntry(appMessage.customType, appMessage.content, appMessage.display, appMessage.details);
1115
+ this._emit({ type: "message_start", message: appMessage });
1116
+ this._emit({ type: "message_end", message: appMessage });
1117
+ }
1118
+ /**
1119
+ * Append custom messages queued while the agent was running.
1120
+ * Called once the current turn's tool results are in agent state and session history.
1121
+ */
1122
+ _flushPendingCustomMessages() {
1123
+ if (this._pendingCustomMessages.length === 0)
1124
+ return;
1125
+ const pending = this._pendingCustomMessages;
1126
+ this._pendingCustomMessages = [];
1127
+ for (const appMessage of pending) {
1128
+ this._appendCustomMessage(appMessage);
1075
1129
  }
1076
1130
  }
1077
1131
  /**
@@ -1169,35 +1223,55 @@ export class AgentSession {
1169
1223
  }
1170
1224
  /**
1171
1225
  * Set model directly.
1172
- * Validates that auth is configured, saves to session and settings.
1226
+ * Validates that auth is configured and saves to the session transcript.
1227
+ * Persists to global defaults only when options.persist is true.
1173
1228
  * @throws Error if no auth is configured for the model
1174
1229
  */
1175
- async setModel(model) {
1230
+ async setModel(model, options = {}) {
1176
1231
  if (!(await this._modelRuntime.checkAuth(model.provider))) {
1177
1232
  throw new Error(`No API key for ${model.provider}/${model.id}`);
1178
1233
  }
1179
1234
  const previousModel = this.model;
1180
- const thinkingLevel = this._getThinkingLevelForModelSwitch();
1235
+ const thinkingLevel = this._getThinkingLevelForModelSwitch(model);
1181
1236
  this.agent.state.model = model;
1182
1237
  this.sessionManager.appendModelChange(model.provider, model.id);
1183
- this.settingsManager.setDefaultModelAndProvider(model.provider, model.id);
1184
- // Re-clamp thinking level for new model's capabilities
1238
+ if (options.persist) {
1239
+ this.settingsManager.setDefaultModelAndProvider(model.provider, model.id);
1240
+ this._addPersistedDefaultToNonEmptyScope(model);
1241
+ }
1242
+ // Apply thinking level for the new model.
1243
+ // Per-model thinking level overrides take priority over the global default.
1244
+ // Model persistence does not implicitly rewrite the global thinking default.
1185
1245
  this.setThinkingLevel(thinkingLevel);
1186
1246
  await this._emitModelSelect(model, previousModel, "set");
1187
1247
  }
1248
+ _addPersistedDefaultToNonEmptyScope(model) {
1249
+ if (this._scopedModels.length === 0)
1250
+ return;
1251
+ if (this._scopedModels.some((scoped) => modelsAreEqual(scoped.model, model)))
1252
+ return;
1253
+ this._scopedModels = [...this._scopedModels, { model }];
1254
+ const enabledModels = this.settingsManager.getEnabledModels();
1255
+ if (!enabledModels?.length)
1256
+ return;
1257
+ const modelReference = `${model.provider}/${model.id}`;
1258
+ if (enabledModels.some((pattern) => pattern.toLowerCase() === modelReference.toLowerCase()))
1259
+ return;
1260
+ this.settingsManager.setEnabledModels([...enabledModels, modelReference]);
1261
+ }
1188
1262
  /**
1189
1263
  * Cycle to next/previous model.
1190
1264
  * Uses scoped models (from --models flag) if available, otherwise all available models.
1191
1265
  * @param direction - "forward" (default) or "backward"
1192
1266
  * @returns The new model info, or undefined if only one model available
1193
1267
  */
1194
- async cycleModel(direction = "forward") {
1268
+ async cycleModel(direction = "forward", options = {}) {
1195
1269
  if (this._scopedModels.length > 0) {
1196
- return this._cycleScopedModel(direction);
1270
+ return this._cycleScopedModel(direction, options);
1197
1271
  }
1198
- return this._cycleAvailableModel(direction);
1272
+ return this._cycleAvailableModel(direction, options);
1199
1273
  }
1200
- async _cycleScopedModel(direction) {
1274
+ async _cycleScopedModel(direction, options) {
1201
1275
  const availableIds = new Set(this._modelRuntime.getAvailableSnapshot().map((model) => `${model.provider}\0${model.id}`));
1202
1276
  const scopedModels = this._scopedModels.filter((scoped) => availableIds.has(`${scoped.model.provider}\0${scoped.model.id}`));
1203
1277
  if (scopedModels.length <= 1)
@@ -1209,20 +1283,24 @@ export class AgentSession {
1209
1283
  const len = scopedModels.length;
1210
1284
  const nextIndex = direction === "forward" ? (currentIndex + 1) % len : (currentIndex - 1 + len) % len;
1211
1285
  const next = scopedModels[nextIndex];
1212
- const thinkingLevel = this._getThinkingLevelForModelSwitch(next.thinkingLevel);
1286
+ const thinkingLevel = this._getThinkingLevelForModelSwitch(next.model, next.thinkingLevel);
1213
1287
  // Apply model
1214
1288
  this.agent.state.model = next.model;
1215
1289
  this.sessionManager.appendModelChange(next.model.provider, next.model.id);
1216
- this.settingsManager.setDefaultModelAndProvider(next.model.provider, next.model.id);
1217
- // Apply thinking level.
1218
- // - Explicit scoped model thinking level overrides current session level
1219
- // - Undefined scoped model thinking level inherits the current session preference
1290
+ if (options.persist) {
1291
+ this.settingsManager.setDefaultModelAndProvider(next.model.provider, next.model.id);
1292
+ this._addPersistedDefaultToNonEmptyScope(next.model);
1293
+ }
1294
+ // Apply thinking level for the new model.
1295
+ // - Explicit scoped model thinking level overrides defaults
1296
+ // - Per-model thinking level overrides take priority over the global default
1220
1297
  // setThinkingLevel clamps to model capabilities.
1298
+ // Model persistence does not implicitly rewrite the global thinking default.
1221
1299
  this.setThinkingLevel(thinkingLevel);
1222
1300
  await this._emitModelSelect(next.model, currentModel, "cycle");
1223
1301
  return { model: next.model, thinkingLevel: this.thinkingLevel, isScoped: true };
1224
1302
  }
1225
- async _cycleAvailableModel(direction) {
1303
+ async _cycleAvailableModel(direction, options) {
1226
1304
  const availableModels = this._modelRuntime.getAvailableSnapshot();
1227
1305
  if (availableModels.length <= 1)
1228
1306
  return undefined;
@@ -1233,11 +1311,15 @@ export class AgentSession {
1233
1311
  const len = availableModels.length;
1234
1312
  const nextIndex = direction === "forward" ? (currentIndex + 1) % len : (currentIndex - 1 + len) % len;
1235
1313
  const nextModel = availableModels[nextIndex];
1236
- const thinkingLevel = this._getThinkingLevelForModelSwitch();
1314
+ const thinkingLevel = this._getThinkingLevelForModelSwitch(nextModel);
1237
1315
  this.agent.state.model = nextModel;
1238
1316
  this.sessionManager.appendModelChange(nextModel.provider, nextModel.id);
1239
- this.settingsManager.setDefaultModelAndProvider(nextModel.provider, nextModel.id);
1240
- // Re-clamp thinking level for new model's capabilities
1317
+ if (options.persist) {
1318
+ this.settingsManager.setDefaultModelAndProvider(nextModel.provider, nextModel.id);
1319
+ this._addPersistedDefaultToNonEmptyScope(nextModel);
1320
+ }
1321
+ // Apply thinking level for the new model.
1322
+ // Model persistence does not implicitly rewrite the global thinking default.
1241
1323
  this.setThinkingLevel(thinkingLevel);
1242
1324
  await this._emitModelSelect(nextModel, currentModel, "cycle");
1243
1325
  return { model: nextModel, thinkingLevel: this.thinkingLevel, isScoped: false };
@@ -1248,20 +1330,21 @@ export class AgentSession {
1248
1330
  /**
1249
1331
  * Set thinking level.
1250
1332
  * Clamps to model capabilities based on available thinking levels.
1251
- * Saves to session and settings only if the level actually changes.
1333
+ * Saves the clamped level to the session transcript only if the level actually changes.
1334
+ * Persists the requested level to global defaults only when options.persist is true.
1252
1335
  */
1253
- setThinkingLevel(level) {
1336
+ setThinkingLevel(level, options = {}) {
1254
1337
  const availableLevels = this.getAvailableThinkingLevels();
1255
1338
  const effectiveLevel = availableLevels.includes(level) ? level : this._clampThinkingLevel(level, availableLevels);
1256
1339
  // Only persist if actually changing
1257
1340
  const previousLevel = this.agent.state.thinkingLevel;
1258
1341
  const isChanging = effectiveLevel !== previousLevel;
1259
1342
  this.agent.state.thinkingLevel = effectiveLevel;
1343
+ if (options.persist) {
1344
+ this.settingsManager.setDefaultThinkingLevel(level);
1345
+ }
1260
1346
  if (isChanging) {
1261
1347
  this.sessionManager.appendThinkingLevelChange(effectiveLevel);
1262
- if (this.supportsThinking() || effectiveLevel !== "off") {
1263
- this.settingsManager.setDefaultThinkingLevel(effectiveLevel);
1264
- }
1265
1348
  this._emit({ type: "thinking_level_changed", level: effectiveLevel });
1266
1349
  void this._extensionRunner.emit({
1267
1350
  type: "thinking_level_select",
@@ -1274,14 +1357,14 @@ export class AgentSession {
1274
1357
  * Cycle to next thinking level.
1275
1358
  * @returns New level, or undefined if model doesn't support thinking
1276
1359
  */
1277
- cycleThinkingLevel() {
1360
+ cycleThinkingLevel(options = {}) {
1278
1361
  if (!this.supportsThinking())
1279
1362
  return undefined;
1280
1363
  const levels = this.getAvailableThinkingLevels();
1281
1364
  const currentIndex = levels.indexOf(this.thinkingLevel);
1282
1365
  const nextIndex = (currentIndex + 1) % levels.length;
1283
1366
  const nextLevel = levels[nextIndex];
1284
- this.setThinkingLevel(nextLevel);
1367
+ this.setThinkingLevel(nextLevel, options);
1285
1368
  return nextLevel;
1286
1369
  }
1287
1370
  /**
@@ -1290,7 +1373,7 @@ export class AgentSession {
1290
1373
  */
1291
1374
  getAvailableThinkingLevels() {
1292
1375
  if (!this.model)
1293
- return THINKING_LEVELS;
1376
+ return [...THINKING_LEVEL_OPTIONS];
1294
1377
  return getSupportedThinkingLevels(this.model);
1295
1378
  }
1296
1379
  /**
@@ -1299,14 +1382,18 @@ export class AgentSession {
1299
1382
  supportsThinking() {
1300
1383
  return !!this.model?.reasoning;
1301
1384
  }
1302
- _getThinkingLevelForModelSwitch(explicitLevel) {
1385
+ _getThinkingLevelForModelSwitch(targetModel, explicitLevel) {
1303
1386
  if (explicitLevel !== undefined) {
1304
1387
  return explicitLevel;
1305
1388
  }
1306
- if (!this.supportsThinking()) {
1307
- return this.settingsManager.getDefaultThinkingLevel() ?? DEFAULT_THINKING_LEVEL;
1389
+ // Per-model default takes priority when switching to a model that has one
1390
+ if (targetModel) {
1391
+ const perModel = this.settingsManager.getModelThinkingLevel(targetModel.provider, targetModel.id);
1392
+ if (perModel !== undefined) {
1393
+ return perModel;
1394
+ }
1308
1395
  }
1309
- return this.thinkingLevel;
1396
+ return this.settingsManager.getDefaultThinkingLevel() ?? this.thinkingLevel ?? DEFAULT_THINKING_LEVEL;
1310
1397
  }
1311
1398
  _clampThinkingLevel(level, _availableLevels) {
1312
1399
  return this.model ? clampThinkingLevel(this.model, level) : "off";
@@ -1337,15 +1424,30 @@ export class AgentSession {
1337
1424
  // =========================================================================
1338
1425
  // Compaction
1339
1426
  // =========================================================================
1427
+ /** Generate Pi's built-in compaction summary for manual and automatic compaction. */
1428
+ async _runDefaultCompaction(preparation, requestModel, apiKey, headers, customInstructions, signal, env, reason) {
1429
+ return compact(preparation, requestModel, apiKey, headers, customInstructions, signal, this.thinkingLevel, this.agent.streamFunction, env, this.settingsManager.getRetrySettings(), this._summarizationRetryCallbacks({ source: "compaction", reason }), undefined);
1430
+ }
1340
1431
  /**
1341
1432
  * Manually compact the session context.
1342
- * Aborts current agent operation first.
1433
+ *
1434
+ * This is the manual entry point used by `/compact`, RPC, and extensions. It is
1435
+ * separate from automatic threshold/overflow compaction, which enters through
1436
+ * `_checkCompaction()` and `_runAutoCompaction()`. After preparation and the
1437
+ * `session_before_compact` hook, both paths call the lower-level `compact()`
1438
+ * function imported from `./compaction/index.ts`, unless the hook cancels or
1439
+ * supplies a custom result.
1440
+ *
1441
+ * Aborts the current agent operation first. Manual compaction never retries or
1442
+ * continues the interrupted agent turn.
1443
+ *
1343
1444
  * @param customInstructions Optional instructions for the compaction summary
1344
1445
  */
1345
1446
  async compact(customInstructions) {
1346
1447
  await this.abort();
1347
1448
  this._compactionAbortController = new AbortController();
1348
1449
  this._emit({ type: "compaction_start", reason: "manual" });
1450
+ let fromExtension = false;
1349
1451
  try {
1350
1452
  if (!this.model) {
1351
1453
  throw new Error(formatNoModelSelectedMessage());
@@ -1363,7 +1465,6 @@ export class AgentSession {
1363
1465
  throw new Error("Nothing to compact (session too small)");
1364
1466
  }
1365
1467
  let extensionCompaction;
1366
- let fromExtension = false;
1367
1468
  if (this._extensionRunner.hasHandlers("session_before_compact")) {
1368
1469
  const result = (await this._extensionRunner.emit({
1369
1470
  type: "session_before_compact",
@@ -1396,8 +1497,8 @@ export class AgentSession {
1396
1497
  details = extensionCompaction.details;
1397
1498
  }
1398
1499
  else {
1399
- // Generate compaction result
1400
- const result = await compact(preparation, requestModel, apiKey, headers, customInstructions, this._compactionAbortController.signal, this.thinkingLevel, this.agent.streamFunction, env, this.settingsManager.getRetrySettings(), this._summarizationRetryCallbacks({ source: "compaction", reason: "manual" }));
1500
+ // Shared default summary generator, also used by automatic compaction.
1501
+ const result = await this._runDefaultCompaction(preparation, requestModel, apiKey, headers, customInstructions, this._compactionAbortController.signal, env, "manual");
1401
1502
  summary = result.summary;
1402
1503
  firstKeptEntryId = result.firstKeptEntryId;
1403
1504
  tokensBefore = result.tokensBefore;
@@ -1445,6 +1546,7 @@ export class AgentSession {
1445
1546
  catch (error) {
1446
1547
  const message = error instanceof Error ? error.message : String(error);
1447
1548
  const aborted = message === "Compaction cancelled" || (error instanceof Error && error.name === "AbortError");
1549
+ const errorMessage = aborted ? undefined : `Compaction failed: ${message}`;
1448
1550
  this._compactionAbortController = undefined;
1449
1551
  this._emit({
1450
1552
  type: "compaction_end",
@@ -1452,7 +1554,14 @@ export class AgentSession {
1452
1554
  result: undefined,
1453
1555
  aborted,
1454
1556
  willRetry: false,
1455
- errorMessage: aborted ? undefined : `Compaction failed: ${message}`,
1557
+ errorMessage,
1558
+ });
1559
+ await this._emitSessionCompactFailed({
1560
+ reason: "manual",
1561
+ errorMessage,
1562
+ aborted,
1563
+ willRetry: false,
1564
+ fromExtension,
1456
1565
  });
1457
1566
  throw error;
1458
1567
  }
@@ -1474,16 +1583,25 @@ export class AgentSession {
1474
1583
  this._branchSummaryAbortController?.abort();
1475
1584
  }
1476
1585
  /**
1477
- * Check if compaction is needed and run it.
1478
- * Called after agent_end and before prompt submission.
1586
+ * Dispatch automatic compaction after `agent_end` or before prompt submission.
1587
+ * Manual compaction does not call this method; it enters through `compact()`.
1588
+ *
1589
+ * Automatic cases:
1590
+ * 1. Overflow with retry: a context-overflow error or recoverable length stop;
1591
+ * remove the failed assistant message, compact, and retry the turn once.
1592
+ * 2. Overflow without retry: a successful response exceeded the configured
1593
+ * context window; compact but preserve the completed response.
1594
+ * 3. Threshold without retry: valid or estimated context usage crossed the
1595
+ * configured threshold; compact without retrying the completed response.
1479
1596
  *
1480
- * Two cases:
1481
- * 1. Recoverable failure: LLM returned context overflow or stopped below its desired output limit;
1482
- * remove the assistant message, compact, and auto-retry once
1483
- * 2. Threshold: Context over threshold, compact, NO auto-retry (user continues manually)
1597
+ * Each case calls `_runAutoCompaction()`. After preparation and the
1598
+ * `session_before_compact` hook, that method calls the lower-level `compact()`
1599
+ * function imported from `./compaction/index.ts`, unless the hook cancels or
1600
+ * supplies a custom result.
1484
1601
  *
1485
1602
  * @param assistantMessage The assistant message to check
1486
1603
  * @param skipAbortedCheck If false, include aborted messages (for pre-prompt check). Default: true
1604
+ * @returns Whether the post-run loop should call `agent.continue()` for overflow recovery or queued messages
1487
1605
  */
1488
1606
  async _checkCompaction(assistantMessage, skipAbortedCheck = true) {
1489
1607
  const settings = this.settingsManager.getCompactionSettings();
@@ -1506,38 +1624,49 @@ export class AgentSession {
1506
1624
  if (assistantIsFromBeforeCompaction) {
1507
1625
  return false;
1508
1626
  }
1509
- // Case 1: Recoverable failure. Explicit/silent context overflow still uses context metadata.
1627
+ // Automatic cases 1 and 2: context overflow.
1510
1628
  // A length stop is recoverable when output ended below the model's original desired limit,
1511
1629
  // independent of the configured context size or any context-clamped provider request limit.
1512
- // A successful response over the configured window should compact but must not retry: the
1513
- // assistant answer already completed and agent.continue() cannot continue from an assistant.
1630
+ const contextOverflow = sameModel && isContextOverflow(assistantMessage, contextWindow);
1514
1631
  const recoverableLength = sameModel && isRecoverableLength(assistantMessage, this.model?.maxTokens ?? 0);
1515
- if (sameModel && (isContextOverflow(assistantMessage, contextWindow) || recoverableLength)) {
1632
+ if (contextOverflow || recoverableLength) {
1516
1633
  const willRetry = assistantMessage.stopReason !== "stop";
1634
+ // Case 2: the response completed successfully. Compact, but do not retry because
1635
+ // agent.continue() cannot continue from a completed assistant response.
1517
1636
  if (!willRetry) {
1518
1637
  return await this._runAutoCompaction("overflow", false);
1519
1638
  }
1520
1639
  if (this._overflowRecoveryAttempted) {
1640
+ const errorMessage = contextOverflow
1641
+ ? "Context overflow recovery failed after one compact-and-retry attempt. Try reducing context or switching to a larger-context model."
1642
+ : "Truncated response recovery failed after one compact-and-retry attempt.";
1521
1643
  this._emit({
1522
1644
  type: "compaction_end",
1523
1645
  reason: "overflow",
1524
1646
  result: undefined,
1525
1647
  aborted: false,
1526
1648
  willRetry: false,
1527
- errorMessage: "Context overflow recovery failed after one compact-and-retry attempt. Try reducing context or switching to a larger-context model.",
1649
+ errorMessage,
1650
+ });
1651
+ await this._emitSessionCompactFailed({
1652
+ reason: "overflow",
1653
+ errorMessage,
1654
+ aborted: false,
1655
+ willRetry: false,
1656
+ fromExtension: false,
1528
1657
  });
1529
1658
  return false;
1530
1659
  }
1660
+ // Case 1: remove the failed or truncated message from agent state, compact, and
1661
+ // retry once. The message remains in session history but is excluded from retry context.
1531
1662
  this._overflowRecoveryAttempted = true;
1532
- // Remove the failed or truncated message from agent state. It remains in session history,
1533
- // but must not be included in the compact-and-retry context.
1534
1663
  const messages = this.agent.state.messages;
1535
1664
  if (messages.length > 0 && messages[messages.length - 1].role === "assistant") {
1536
1665
  this.agent.state.messages = messages.slice(0, -1);
1537
1666
  }
1538
1667
  return await this._runAutoCompaction("overflow", willRetry);
1539
1668
  }
1540
- // Case 2: Threshold - context is getting large
1669
+ // Case 3: threshold compaction without retry.
1541
1670
  // For error messages or all-zero usage messages, estimate from the last valid response.
1542
1671
  // This ensures sessions that hit persistent API errors (e.g. 529) or malformed zero-usage
1543
1672
  // responses can still compact and do not reset context accounting.
@@ -1546,16 +1675,18 @@ export class AgentSession {
1546
1675
  if (assistantMessage.stopReason === "error" || directContextTokens === 0) {
1547
1676
  const messages = this.agent.state.messages;
1548
1677
  const estimate = estimateContextTokens(messages);
1549
- if (estimate.lastUsageIndex === null)
1550
- return false; // No usage data at all
1551
- // Verify the usage source is post-compaction. Kept pre-compaction messages
1552
- // have stale usage reflecting the old (larger) context and would falsely
1553
- // trigger compaction right after one just finished.
1554
- const usageMsg = messages[estimate.lastUsageIndex];
1555
- if (compactionEntry &&
1556
- usageMsg.role === "assistant" &&
1557
- usageMsg.timestamp <= new Date(compactionEntry.timestamp).getTime()) {
1558
- return false;
1678
+ // Without provider usage, estimate.tokens is the pure message-size estimate.
1679
+ // Only usage-backed estimates need the stale pre-compaction check.
1680
+ if (estimate.lastUsageIndex !== null) {
1681
+ // Verify the usage source is post-compaction. Kept pre-compaction messages
1682
+ // have stale usage reflecting the old (larger) context and would falsely
1683
+ // trigger compaction right after one just finished.
1684
+ const usageMsg = messages[estimate.lastUsageIndex];
1685
+ if (compactionEntry &&
1686
+ usageMsg.role === "assistant" &&
1687
+ usageMsg.timestamp <= new Date(compactionEntry.timestamp).getTime()) {
1688
+ return false;
1689
+ }
1559
1690
  }
1560
1691
  contextTokens = estimate.tokens;
1561
1692
  }
@@ -1568,11 +1699,19 @@ export class AgentSession {
1568
1699
  return false;
1569
1700
  }
1570
1701
  /**
1571
- * Internal: Run auto-compaction with events.
1702
+ * Execute threshold or overflow compaction. Manual compaction uses
1703
+ * `AgentSession.compact()` instead. Both paths call the lower-level `compact()`
1704
+ * function imported from `./compaction/index.ts` after preparation and extension
1705
+ * interception.
1706
+ *
1707
+ * @param reason Automatic trigger selected by `_checkCompaction()`
1708
+ * @param willRetry Whether to continue the interrupted turn after overflow compaction
1709
+ * @returns Whether the post-run loop should call `agent.continue()`
1572
1710
  */
1573
1711
  async _runAutoCompaction(reason, willRetry) {
1574
1712
  const settings = this.settingsManager.getCompactionSettings();
1575
1713
  let started = false;
1714
+ let fromExtension = false;
1576
1715
  try {
1577
1716
  if (!this.model) {
1578
1717
  return false;
@@ -1587,7 +1726,6 @@ export class AgentSession {
1587
1726
  this._autoCompactionAbortController = new AbortController();
1588
1727
  started = true;
1589
1728
  let extensionCompaction;
1590
- let fromExtension = false;
1591
1729
  if (this._extensionRunner.hasHandlers("session_before_compact")) {
1592
1730
  const extensionResult = (await this._extensionRunner.emit({
1593
1731
  type: "session_before_compact",
@@ -1606,6 +1744,12 @@ export class AgentSession {
1606
1744
  aborted: true,
1607
1745
  willRetry: false,
1608
1746
  });
1747
+ await this._emitSessionCompactFailed({
1748
+ reason,
1749
+ aborted: true,
1750
+ willRetry: false,
1751
+ fromExtension: false,
1752
+ });
1609
1753
  return false;
1610
1754
  }
1611
1755
  if (extensionResult?.compaction) {
@@ -1627,8 +1771,8 @@ export class AgentSession {
1627
1771
  details = extensionCompaction.details;
1628
1772
  }
1629
1773
  else {
1630
- // Generate compaction result
1631
- const compactResult = await compact(preparation, requestModel, apiKey, headers, undefined, this._autoCompactionAbortController.signal, this.thinkingLevel, this.agent.streamFunction, env, this.settingsManager.getRetrySettings(), this._summarizationRetryCallbacks({ source: "compaction", reason }));
1774
+ // Shared default summary generator, also used by manual compaction.
1775
+ const compactResult = await this._runDefaultCompaction(preparation, requestModel, apiKey, headers, undefined, this._autoCompactionAbortController.signal, env, reason);
1632
1776
  summary = compactResult.summary;
1633
1777
  firstKeptEntryId = compactResult.firstKeptEntryId;
1634
1778
  tokensBefore = compactResult.tokensBefore;
@@ -1643,6 +1787,12 @@ export class AgentSession {
1643
1787
  aborted: true,
1644
1788
  willRetry: false,
1645
1789
  });
1790
+ await this._emitSessionCompactFailed({
1791
+ reason,
1792
+ aborted: true,
1793
+ willRetry: false,
1794
+ fromExtension,
1795
+ });
1646
1796
  return false;
1647
1797
  }
1648
1798
  this.sessionManager.appendCompaction(summary, firstKeptEntryId, tokensBefore, details, fromExtension, usage);
@@ -1689,15 +1839,23 @@ export class AgentSession {
1689
1839
  catch (error) {
1690
1840
  const errorMessage = error instanceof Error ? error.message : "compaction failed";
1691
1841
  if (started) {
1842
+ const formattedErrorMessage = reason === "overflow"
1843
+ ? `Context overflow recovery failed: ${errorMessage}`
1844
+ : `Auto-compaction failed: ${errorMessage}`;
1692
1845
  this._emit({
1693
1846
  type: "compaction_end",
1694
1847
  reason,
1695
1848
  result: undefined,
1696
1849
  aborted: false,
1697
1850
  willRetry: false,
1698
- errorMessage: reason === "overflow"
1699
- ? `Context overflow recovery failed: ${errorMessage}`
1700
- : `Auto-compaction failed: ${errorMessage}`,
1851
+ errorMessage: formattedErrorMessage,
1852
+ });
1853
+ await this._emitSessionCompactFailed({
1854
+ reason,
1855
+ errorMessage: formattedErrorMessage,
1856
+ aborted: false,
1857
+ willRetry: false,
1858
+ fromExtension,
1701
1859
  });
1702
1860
  }
1703
1861
  return false;
@@ -2585,29 +2743,7 @@ export class AgentSession {
2585
2743
  * @returns The resolved output file path.
2586
2744
  */
2587
2745
  exportToJsonl(outputPath) {
2588
- const filePath = resolvePath(outputPath ?? `session-${new Date().toISOString().replace(/[:.]/g, "-")}.jsonl`, process.cwd());
2589
- const dir = dirname(filePath);
2590
- if (!existsSync(dir)) {
2591
- mkdirSync(dir, { recursive: true });
2592
- }
2593
- const header = {
2594
- type: "session",
2595
- version: CURRENT_SESSION_VERSION,
2596
- id: this.sessionManager.getSessionId(),
2597
- timestamp: new Date().toISOString(),
2598
- cwd: this.sessionManager.getCwd(),
2599
- };
2600
- const branchEntries = this.sessionManager.getBranch();
2601
- const lines = [JSON.stringify(header)];
2602
- // Re-chain parentIds to form a linear sequence
2603
- let prevId = null;
2604
- for (const entry of branchEntries) {
2605
- const linear = { ...entry, parentId: prevId };
2606
- lines.push(JSON.stringify(linear));
2607
- prevId = entry.id;
2608
- }
2609
- writeFileSync(filePath, `${lines.join("\n")}\n`);
2610
- return filePath;
2746
+ return exportSessionToJsonl(this.sessionManager, outputPath);
2611
2747
  }
2612
2748
  // =========================================================================
2613
2749
  // Utilities