@ashx-j/lunr 0.2.26 → 0.2.28

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 (697) hide show
  1. package/CHANGELOG.md +25 -1
  2. package/LICENSE +22 -0
  3. package/dist/builtin-extensions/ashxj-thinking.d.ts +1 -1
  4. package/dist/builtin-extensions/ashxj-thinking.d.ts.map +1 -1
  5. package/dist/builtin-extensions/ashxj-thinking.js +1 -1
  6. package/dist/builtin-extensions/ashxj-thinking.js.map +1 -1
  7. package/dist/builtin-extensions/ashxj-tui.d.ts +11 -1
  8. package/dist/builtin-extensions/ashxj-tui.d.ts.map +1 -1
  9. package/dist/builtin-extensions/ashxj-tui.js +6 -10
  10. package/dist/builtin-extensions/ashxj-tui.js.map +1 -1
  11. package/dist/builtin-extensions/lunr-cron.d.ts +4 -5
  12. package/dist/builtin-extensions/lunr-cron.d.ts.map +1 -1
  13. package/dist/builtin-extensions/lunr-cron.js +94 -108
  14. package/dist/builtin-extensions/lunr-cron.js.map +1 -1
  15. package/dist/builtin-extensions/lunr-local-providers/local-servers.d.ts.map +1 -1
  16. package/dist/builtin-extensions/lunr-local-providers/local-servers.js +3 -1
  17. package/dist/builtin-extensions/lunr-local-providers/local-servers.js.map +1 -1
  18. package/dist/builtin-extensions/narumiruna-pi-goal/src/accounting.d.ts.map +1 -1
  19. package/dist/builtin-extensions/narumiruna-pi-goal/src/accounting.js +5 -2
  20. package/dist/builtin-extensions/narumiruna-pi-goal/src/accounting.js.map +1 -1
  21. package/dist/builtin-extensions/narumiruna-pi-goal/src/commands.d.ts.map +1 -1
  22. package/dist/builtin-extensions/narumiruna-pi-goal/src/commands.js +2 -2
  23. package/dist/builtin-extensions/narumiruna-pi-goal/src/commands.js.map +1 -1
  24. package/dist/builtin-extensions/narumiruna-pi-goal/src/goal.d.ts.map +1 -1
  25. package/dist/builtin-extensions/narumiruna-pi-goal/src/goal.js +1 -1
  26. package/dist/builtin-extensions/narumiruna-pi-goal/src/goal.js.map +1 -1
  27. package/dist/builtin-extensions/narumiruna-pi-goal/src/runtime.d.ts.map +1 -1
  28. package/dist/builtin-extensions/narumiruna-pi-goal/src/runtime.js +1 -1
  29. package/dist/builtin-extensions/narumiruna-pi-goal/src/runtime.js.map +1 -1
  30. package/dist/builtin-extensions/pi-intercom/index.d.ts.map +1 -1
  31. package/dist/builtin-extensions/pi-intercom/index.js +2 -2
  32. package/dist/builtin-extensions/pi-intercom/index.js.map +1 -1
  33. package/dist/builtin-extensions/pi-lsp-extension/bemol-extension/index.d.ts +1 -1
  34. package/dist/builtin-extensions/pi-lsp-extension/bemol-extension/index.d.ts.map +1 -1
  35. package/dist/builtin-extensions/pi-lsp-extension/bemol-extension/index.js +1 -1
  36. package/dist/builtin-extensions/pi-lsp-extension/bemol-extension/index.js.map +1 -1
  37. package/dist/builtin-extensions/pi-lsp-extension/src/index.d.ts.map +1 -1
  38. package/dist/builtin-extensions/pi-lsp-extension/src/index.js +1 -15
  39. package/dist/builtin-extensions/pi-lsp-extension/src/index.js.map +1 -1
  40. package/dist/builtin-extensions/pi-lsp-extension/src/lsp-client.d.ts +6 -0
  41. package/dist/builtin-extensions/pi-lsp-extension/src/lsp-client.d.ts.map +1 -1
  42. package/dist/builtin-extensions/pi-lsp-extension/src/lsp-client.js +187 -132
  43. package/dist/builtin-extensions/pi-lsp-extension/src/lsp-client.js.map +1 -1
  44. package/dist/builtin-extensions/pi-lsp-extension/src/lsp-manager.d.ts +8 -0
  45. package/dist/builtin-extensions/pi-lsp-extension/src/lsp-manager.d.ts.map +1 -1
  46. package/dist/builtin-extensions/pi-lsp-extension/src/lsp-manager.js +142 -112
  47. package/dist/builtin-extensions/pi-lsp-extension/src/lsp-manager.js.map +1 -1
  48. package/dist/builtin-extensions/pi-lsp-extension/src/tools/code-rewrite.d.ts +12 -1
  49. package/dist/builtin-extensions/pi-lsp-extension/src/tools/code-rewrite.d.ts.map +1 -1
  50. package/dist/builtin-extensions/pi-lsp-extension/src/tools/code-rewrite.js +14 -7
  51. package/dist/builtin-extensions/pi-lsp-extension/src/tools/code-rewrite.js.map +1 -1
  52. package/dist/builtin-extensions/pi-lsp-extension/src/tree-sitter/rewrite-engine.d.ts +11 -3
  53. package/dist/builtin-extensions/pi-lsp-extension/src/tree-sitter/rewrite-engine.d.ts.map +1 -1
  54. package/dist/builtin-extensions/pi-lsp-extension/src/tree-sitter/rewrite-engine.js +67 -41
  55. package/dist/builtin-extensions/pi-lsp-extension/src/tree-sitter/rewrite-engine.js.map +1 -1
  56. package/dist/builtin-extensions/pi-lsp-extension/src/tree-sitter/search-engine.d.ts +4 -2
  57. package/dist/builtin-extensions/pi-lsp-extension/src/tree-sitter/search-engine.d.ts.map +1 -1
  58. package/dist/builtin-extensions/pi-lsp-extension/src/tree-sitter/search-engine.js +3 -0
  59. package/dist/builtin-extensions/pi-lsp-extension/src/tree-sitter/search-engine.js.map +1 -1
  60. package/dist/builtin-extensions/pi-mcp-adapter/commands.d.ts +2 -1
  61. package/dist/builtin-extensions/pi-mcp-adapter/commands.d.ts.map +1 -1
  62. package/dist/builtin-extensions/pi-mcp-adapter/commands.js +6 -6
  63. package/dist/builtin-extensions/pi-mcp-adapter/commands.js.map +1 -1
  64. package/dist/builtin-extensions/pi-mcp-adapter/config.d.ts +1 -1
  65. package/dist/builtin-extensions/pi-mcp-adapter/config.d.ts.map +1 -1
  66. package/dist/builtin-extensions/pi-mcp-adapter/config.js +11 -5
  67. package/dist/builtin-extensions/pi-mcp-adapter/config.js.map +1 -1
  68. package/dist/builtin-extensions/pi-mcp-adapter/direct-tool-executor.d.ts.map +1 -1
  69. package/dist/builtin-extensions/pi-mcp-adapter/direct-tool-executor.js +2 -2
  70. package/dist/builtin-extensions/pi-mcp-adapter/direct-tool-executor.js.map +1 -1
  71. package/dist/builtin-extensions/pi-mcp-adapter/host-html-template.d.ts.map +1 -1
  72. package/dist/builtin-extensions/pi-mcp-adapter/host-html-template.js +1 -1
  73. package/dist/builtin-extensions/pi-mcp-adapter/host-html-template.js.map +1 -1
  74. package/dist/builtin-extensions/pi-mcp-adapter/index.d.ts.map +1 -1
  75. package/dist/builtin-extensions/pi-mcp-adapter/index.js +48 -40
  76. package/dist/builtin-extensions/pi-mcp-adapter/index.js.map +1 -1
  77. package/dist/builtin-extensions/pi-mcp-adapter/init.d.ts.map +1 -1
  78. package/dist/builtin-extensions/pi-mcp-adapter/init.js +3 -1
  79. package/dist/builtin-extensions/pi-mcp-adapter/init.js.map +1 -1
  80. package/dist/builtin-extensions/pi-mcp-adapter/mcp-auth-flow.d.ts +12 -40
  81. package/dist/builtin-extensions/pi-mcp-adapter/mcp-auth-flow.d.ts.map +1 -1
  82. package/dist/builtin-extensions/pi-mcp-adapter/mcp-auth-flow.js +166 -235
  83. package/dist/builtin-extensions/pi-mcp-adapter/mcp-auth-flow.js.map +1 -1
  84. package/dist/builtin-extensions/pi-mcp-adapter/mcp-callback-server.d.ts +5 -0
  85. package/dist/builtin-extensions/pi-mcp-adapter/mcp-callback-server.d.ts.map +1 -1
  86. package/dist/builtin-extensions/pi-mcp-adapter/mcp-callback-server.js +43 -13
  87. package/dist/builtin-extensions/pi-mcp-adapter/mcp-callback-server.js.map +1 -1
  88. package/dist/builtin-extensions/pi-mcp-adapter/mcp-oauth-provider.d.ts +14 -3
  89. package/dist/builtin-extensions/pi-mcp-adapter/mcp-oauth-provider.d.ts.map +1 -1
  90. package/dist/builtin-extensions/pi-mcp-adapter/mcp-oauth-provider.js +73 -21
  91. package/dist/builtin-extensions/pi-mcp-adapter/mcp-oauth-provider.js.map +1 -1
  92. package/dist/builtin-extensions/pi-mcp-adapter/proxy-modes.d.ts.map +1 -1
  93. package/dist/builtin-extensions/pi-mcp-adapter/proxy-modes.js +4 -4
  94. package/dist/builtin-extensions/pi-mcp-adapter/proxy-modes.js.map +1 -1
  95. package/dist/builtin-extensions/pi-mcp-adapter/server-manager.d.ts.map +1 -1
  96. package/dist/builtin-extensions/pi-mcp-adapter/server-manager.js +2 -2
  97. package/dist/builtin-extensions/pi-mcp-adapter/server-manager.js.map +1 -1
  98. package/dist/builtin-extensions/pi-mcp-adapter/state.d.ts +2 -0
  99. package/dist/builtin-extensions/pi-mcp-adapter/state.d.ts.map +1 -1
  100. package/dist/builtin-extensions/pi-mcp-adapter/state.js.map +1 -1
  101. package/dist/builtin-extensions/pi-ollama-cloud/index.d.ts +1 -1
  102. package/dist/builtin-extensions/pi-ollama-cloud/index.d.ts.map +1 -1
  103. package/dist/builtin-extensions/pi-ollama-cloud/index.js +1 -1
  104. package/dist/builtin-extensions/pi-ollama-cloud/index.js.map +1 -1
  105. package/dist/builtin-extensions/pi-ollama-cloud/models.d.ts +11 -5
  106. package/dist/builtin-extensions/pi-ollama-cloud/models.d.ts.map +1 -1
  107. package/dist/builtin-extensions/pi-ollama-cloud/models.js +12 -32
  108. package/dist/builtin-extensions/pi-ollama-cloud/models.js.map +1 -1
  109. package/dist/builtin-extensions/pi-prompt-template-model/index.d.ts.map +1 -1
  110. package/dist/builtin-extensions/pi-prompt-template-model/index.js +5 -3
  111. package/dist/builtin-extensions/pi-prompt-template-model/index.js.map +1 -1
  112. package/dist/builtin-extensions/pi-prompt-template-model/prompt-loader.d.ts +2 -1
  113. package/dist/builtin-extensions/pi-prompt-template-model/prompt-loader.d.ts.map +1 -1
  114. package/dist/builtin-extensions/pi-prompt-template-model/prompt-loader.js +21 -12
  115. package/dist/builtin-extensions/pi-prompt-template-model/prompt-loader.js.map +1 -1
  116. package/dist/builtin-extensions/pi-prompt-template-model/tool-manager.d.ts.map +1 -1
  117. package/dist/builtin-extensions/pi-prompt-template-model/tool-manager.js +7 -24
  118. package/dist/builtin-extensions/pi-prompt-template-model/tool-manager.js.map +1 -1
  119. package/dist/builtin-extensions/pi-subagents/src/extension/index.d.ts.map +1 -1
  120. package/dist/builtin-extensions/pi-subagents/src/extension/index.js +39 -77
  121. package/dist/builtin-extensions/pi-subagents/src/extension/index.js.map +1 -1
  122. package/dist/builtin-extensions/pi-subagents/src/runs/background/chain-root-attachment.d.ts +4 -1
  123. package/dist/builtin-extensions/pi-subagents/src/runs/background/chain-root-attachment.d.ts.map +1 -1
  124. package/dist/builtin-extensions/pi-subagents/src/runs/background/chain-root-attachment.js +2 -0
  125. package/dist/builtin-extensions/pi-subagents/src/runs/background/chain-root-attachment.js.map +1 -1
  126. package/dist/builtin-extensions/pi-subagents/src/runs/background/notify.d.ts +6 -1
  127. package/dist/builtin-extensions/pi-subagents/src/runs/background/notify.d.ts.map +1 -1
  128. package/dist/builtin-extensions/pi-subagents/src/runs/background/notify.js +17 -31
  129. package/dist/builtin-extensions/pi-subagents/src/runs/background/notify.js.map +1 -1
  130. package/dist/builtin-extensions/pi-subagents/src/runs/background/result-watcher.d.ts.map +1 -1
  131. package/dist/builtin-extensions/pi-subagents/src/runs/background/result-watcher.js +7 -2
  132. package/dist/builtin-extensions/pi-subagents/src/runs/background/result-watcher.js.map +1 -1
  133. package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.d.ts +5 -1
  134. package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.d.ts.map +1 -1
  135. package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.js +78 -42
  136. package/dist/builtin-extensions/pi-subagents/src/runs/background/subagent-runner.js.map +1 -1
  137. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-execution.d.ts.map +1 -1
  138. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-execution.js +8 -1
  139. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/chain-execution.js.map +1 -1
  140. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.d.ts +0 -3
  141. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.d.ts.map +1 -1
  142. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.js +134 -28
  143. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/execution.js.map +1 -1
  144. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.d.ts.map +1 -1
  145. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.js +26 -5
  146. package/dist/builtin-extensions/pi-subagents/src/runs/foreground/subagent-executor.js.map +1 -1
  147. package/dist/builtin-extensions/pi-subagents/src/runs/shared/model-fallback.d.ts +1 -1
  148. package/dist/builtin-extensions/pi-subagents/src/runs/shared/model-fallback.d.ts.map +1 -1
  149. package/dist/builtin-extensions/pi-subagents/src/runs/shared/model-fallback.js +1 -1
  150. package/dist/builtin-extensions/pi-subagents/src/runs/shared/model-fallback.js.map +1 -1
  151. package/dist/builtin-extensions/pi-subagents/src/runs/shared/parallel-utils.d.ts +7 -8
  152. package/dist/builtin-extensions/pi-subagents/src/runs/shared/parallel-utils.d.ts.map +1 -1
  153. package/dist/builtin-extensions/pi-subagents/src/runs/shared/parallel-utils.js +60 -32
  154. package/dist/builtin-extensions/pi-subagents/src/runs/shared/parallel-utils.js.map +1 -1
  155. package/dist/builtin-extensions/pi-subagents/src/shared/session-tokens.d.ts +7 -1
  156. package/dist/builtin-extensions/pi-subagents/src/shared/session-tokens.d.ts.map +1 -1
  157. package/dist/builtin-extensions/pi-subagents/src/shared/session-tokens.js +70 -38
  158. package/dist/builtin-extensions/pi-subagents/src/shared/session-tokens.js.map +1 -1
  159. package/dist/builtin-extensions/pi-subagents/src/shared/types.d.ts +9 -0
  160. package/dist/builtin-extensions/pi-subagents/src/shared/types.d.ts.map +1 -1
  161. package/dist/builtin-extensions/pi-subagents/src/shared/types.js.map +1 -1
  162. package/dist/builtin-extensions/pi-subagents/src/shared/utils.d.ts +1 -1
  163. package/dist/builtin-extensions/pi-subagents/src/shared/utils.d.ts.map +1 -1
  164. package/dist/builtin-extensions/pi-subagents/src/shared/utils.js +15 -5
  165. package/dist/builtin-extensions/pi-subagents/src/shared/utils.js.map +1 -1
  166. package/dist/builtin-extensions/pi-subagents/src/slash/prompt-workflows.d.ts.map +1 -1
  167. package/dist/builtin-extensions/pi-subagents/src/slash/prompt-workflows.js +4 -3
  168. package/dist/builtin-extensions/pi-subagents/src/slash/prompt-workflows.js.map +1 -1
  169. package/dist/builtin-extensions/pi-subagents/src/slash/slash-commands.d.ts.map +1 -1
  170. package/dist/builtin-extensions/pi-subagents/src/slash/slash-commands.js +13 -62
  171. package/dist/builtin-extensions/pi-subagents/src/slash/slash-commands.js.map +1 -1
  172. package/dist/builtin-extensions/pi-subagents/src/tui/render.d.ts +1 -1
  173. package/dist/builtin-extensions/pi-subagents/src/tui/render.d.ts.map +1 -1
  174. package/dist/builtin-extensions/pi-subagents/src/tui/render.js +18 -9
  175. package/dist/builtin-extensions/pi-subagents/src/tui/render.js.map +1 -1
  176. package/dist/builtin-extensions/pi-subagents/src/watchdog/review.d.ts.map +1 -1
  177. package/dist/builtin-extensions/pi-subagents/src/watchdog/review.js +3 -3
  178. package/dist/builtin-extensions/pi-subagents/src/watchdog/review.js.map +1 -1
  179. package/dist/builtin-extensions/pi-tps.d.ts.map +1 -1
  180. package/dist/builtin-extensions/pi-tps.js +28 -17
  181. package/dist/builtin-extensions/pi-tps.js.map +1 -1
  182. package/dist/builtin-extensions/pi-web-access/activity.d.ts +1 -0
  183. package/dist/builtin-extensions/pi-web-access/activity.d.ts.map +1 -1
  184. package/dist/builtin-extensions/pi-web-access/activity.js +27 -5
  185. package/dist/builtin-extensions/pi-web-access/activity.js.map +1 -1
  186. package/dist/builtin-extensions/pi-web-access/bounded-body.d.ts +3 -0
  187. package/dist/builtin-extensions/pi-web-access/bounded-body.d.ts.map +1 -0
  188. package/dist/builtin-extensions/pi-web-access/bounded-body.js +43 -0
  189. package/dist/builtin-extensions/pi-web-access/bounded-body.js.map +1 -0
  190. package/dist/builtin-extensions/pi-web-access/content-page.d.ts +24 -0
  191. package/dist/builtin-extensions/pi-web-access/content-page.d.ts.map +1 -0
  192. package/dist/builtin-extensions/pi-web-access/content-page.js +57 -0
  193. package/dist/builtin-extensions/pi-web-access/content-page.js.map +1 -0
  194. package/dist/builtin-extensions/pi-web-access/extract.d.ts.map +1 -1
  195. package/dist/builtin-extensions/pi-web-access/extract.js +7 -2
  196. package/dist/builtin-extensions/pi-web-access/extract.js.map +1 -1
  197. package/dist/builtin-extensions/pi-web-access/github-extract.d.ts +0 -1
  198. package/dist/builtin-extensions/pi-web-access/github-extract.d.ts.map +1 -1
  199. package/dist/builtin-extensions/pi-web-access/github-extract.js +147 -36
  200. package/dist/builtin-extensions/pi-web-access/github-extract.js.map +1 -1
  201. package/dist/builtin-extensions/pi-web-access/index.d.ts.map +1 -1
  202. package/dist/builtin-extensions/pi-web-access/index.js +48 -73
  203. package/dist/builtin-extensions/pi-web-access/index.js.map +1 -1
  204. package/dist/builtin-extensions/pi-web-access/session-cleanup.d.ts +12 -4
  205. package/dist/builtin-extensions/pi-web-access/session-cleanup.d.ts.map +1 -1
  206. package/dist/builtin-extensions/pi-web-access/session-cleanup.js +35 -12
  207. package/dist/builtin-extensions/pi-web-access/session-cleanup.js.map +1 -1
  208. package/dist/builtin-extensions/pi-web-access/storage.d.ts +9 -6
  209. package/dist/builtin-extensions/pi-web-access/storage.d.ts.map +1 -1
  210. package/dist/builtin-extensions/pi-web-access/storage.js +36 -24
  211. package/dist/builtin-extensions/pi-web-access/storage.js.map +1 -1
  212. package/dist/builtin-extensions/simple-pi-memory.d.ts +1 -1
  213. package/dist/builtin-extensions/simple-pi-memory.d.ts.map +1 -1
  214. package/dist/builtin-extensions/simple-pi-memory.js +1 -1
  215. package/dist/builtin-extensions/simple-pi-memory.js.map +1 -1
  216. package/dist/catalog/models.json +1 -1
  217. package/dist/catalog/providers/google-vertex.json +1 -1
  218. package/dist/catalog/providers/google.json +1 -1
  219. package/dist/catalog/publication.json +3 -3
  220. package/dist/cli/install-cli.d.ts.map +1 -1
  221. package/dist/cli/install-cli.js +38 -30
  222. package/dist/cli/install-cli.js.map +1 -1
  223. package/dist/core/agent-session-runtime.d.ts +13 -0
  224. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  225. package/dist/core/agent-session-runtime.js +75 -11
  226. package/dist/core/agent-session-runtime.js.map +1 -1
  227. package/dist/core/agent-session-services.d.ts +1 -0
  228. package/dist/core/agent-session-services.d.ts.map +1 -1
  229. package/dist/core/agent-session-services.js +1 -0
  230. package/dist/core/agent-session-services.js.map +1 -1
  231. package/dist/core/agent-session.d.ts +46 -21
  232. package/dist/core/agent-session.d.ts.map +1 -1
  233. package/dist/core/agent-session.js +344 -126
  234. package/dist/core/agent-session.js.map +1 -1
  235. package/dist/core/browser/runtime.d.ts +2 -0
  236. package/dist/core/browser/runtime.d.ts.map +1 -1
  237. package/dist/core/browser/runtime.js +80 -45
  238. package/dist/core/browser/runtime.js.map +1 -1
  239. package/dist/core/browser/setup.d.ts.map +1 -1
  240. package/dist/core/browser/setup.js +12 -1
  241. package/dist/core/browser/setup.js.map +1 -1
  242. package/dist/core/cache-stats.d.ts +1 -1
  243. package/dist/core/cache-stats.d.ts.map +1 -1
  244. package/dist/core/cache-stats.js +1 -1
  245. package/dist/core/cache-stats.js.map +1 -1
  246. package/dist/core/compaction/branch-summarization.d.ts +2 -1
  247. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  248. package/dist/core/compaction/branch-summarization.js +1 -0
  249. package/dist/core/compaction/branch-summarization.js.map +1 -1
  250. package/dist/core/compaction/compaction.d.ts +5 -11
  251. package/dist/core/compaction/compaction.d.ts.map +1 -1
  252. package/dist/core/compaction/compaction.js +38 -92
  253. package/dist/core/compaction/compaction.js.map +1 -1
  254. package/dist/core/computer-use/adapter.d.ts.map +1 -1
  255. package/dist/core/computer-use/adapter.js +7 -2
  256. package/dist/core/computer-use/adapter.js.map +1 -1
  257. package/dist/core/computer-use/image.d.ts.map +1 -1
  258. package/dist/core/computer-use/image.js +17 -5
  259. package/dist/core/computer-use/image.js.map +1 -1
  260. package/dist/core/computer-use/schemas.d.ts.map +1 -1
  261. package/dist/core/computer-use/schemas.js +23 -6
  262. package/dist/core/computer-use/schemas.js.map +1 -1
  263. package/dist/core/computer-use/workflow.d.ts.map +1 -1
  264. package/dist/core/computer-use/workflow.js +459 -119
  265. package/dist/core/computer-use/workflow.js.map +1 -1
  266. package/dist/core/context-breakdown.d.ts +2 -2
  267. package/dist/core/context-breakdown.d.ts.map +1 -1
  268. package/dist/core/context-breakdown.js +22 -20
  269. package/dist/core/context-breakdown.js.map +1 -1
  270. package/dist/core/cron/jobs.d.ts +26 -8
  271. package/dist/core/cron/jobs.d.ts.map +1 -1
  272. package/dist/core/cron/jobs.js +357 -232
  273. package/dist/core/cron/jobs.js.map +1 -1
  274. package/dist/core/cron/origin-context.d.ts +1 -0
  275. package/dist/core/cron/origin-context.d.ts.map +1 -1
  276. package/dist/core/cron/origin-context.js.map +1 -1
  277. package/dist/core/cron/scheduler.d.ts +22 -17
  278. package/dist/core/cron/scheduler.d.ts.map +1 -1
  279. package/dist/core/cron/scheduler.js +153 -73
  280. package/dist/core/cron/scheduler.js.map +1 -1
  281. package/dist/core/extensions/index.d.ts +1 -1
  282. package/dist/core/extensions/index.d.ts.map +1 -1
  283. package/dist/core/extensions/index.js.map +1 -1
  284. package/dist/core/extensions/runner.d.ts +1 -0
  285. package/dist/core/extensions/runner.d.ts.map +1 -1
  286. package/dist/core/extensions/runner.js +8 -0
  287. package/dist/core/extensions/runner.js.map +1 -1
  288. package/dist/core/extensions/types.d.ts +11 -1
  289. package/dist/core/extensions/types.d.ts.map +1 -1
  290. package/dist/core/extensions/types.js.map +1 -1
  291. package/dist/core/footer-data-provider.d.ts +4 -0
  292. package/dist/core/footer-data-provider.d.ts.map +1 -1
  293. package/dist/core/footer-data-provider.js +22 -1
  294. package/dist/core/footer-data-provider.js.map +1 -1
  295. package/dist/core/large-subagent-launch.d.ts +1 -1
  296. package/dist/core/large-subagent-launch.d.ts.map +1 -1
  297. package/dist/core/large-subagent-launch.js +7 -7
  298. package/dist/core/large-subagent-launch.js.map +1 -1
  299. package/dist/core/model-registry.d.ts +2 -0
  300. package/dist/core/model-registry.d.ts.map +1 -1
  301. package/dist/core/model-registry.js +5 -0
  302. package/dist/core/model-registry.js.map +1 -1
  303. package/dist/core/model-runtime.d.ts +4 -1
  304. package/dist/core/model-runtime.d.ts.map +1 -1
  305. package/dist/core/model-runtime.js +40 -4
  306. package/dist/core/model-runtime.js.map +1 -1
  307. package/dist/core/package-manager.d.ts.map +1 -1
  308. package/dist/core/package-manager.js.map +1 -1
  309. package/dist/core/permissions.d.ts +3 -3
  310. package/dist/core/permissions.d.ts.map +1 -1
  311. package/dist/core/permissions.js +11 -35
  312. package/dist/core/permissions.js.map +1 -1
  313. package/dist/core/plan-mode.d.ts +5 -13
  314. package/dist/core/plan-mode.d.ts.map +1 -1
  315. package/dist/core/plan-mode.js +126 -116
  316. package/dist/core/plan-mode.js.map +1 -1
  317. package/dist/core/project-trust.d.ts.map +1 -1
  318. package/dist/core/project-trust.js +1 -1
  319. package/dist/core/project-trust.js.map +1 -1
  320. package/dist/core/prompt-resource-bridge.d.ts +12 -0
  321. package/dist/core/prompt-resource-bridge.d.ts.map +1 -0
  322. package/dist/core/prompt-resource-bridge.js +9 -0
  323. package/dist/core/prompt-resource-bridge.js.map +1 -0
  324. package/dist/core/protected-targets.d.ts +6 -0
  325. package/dist/core/protected-targets.d.ts.map +1 -0
  326. package/dist/core/protected-targets.js +45 -0
  327. package/dist/core/protected-targets.js.map +1 -0
  328. package/dist/core/resource-loader.d.ts.map +1 -1
  329. package/dist/core/resource-loader.js +7 -0
  330. package/dist/core/resource-loader.js.map +1 -1
  331. package/dist/core/rollback.d.ts +19 -3
  332. package/dist/core/rollback.d.ts.map +1 -1
  333. package/dist/core/rollback.js +172 -56
  334. package/dist/core/rollback.js.map +1 -1
  335. package/dist/core/runtime-credentials.d.ts +3 -0
  336. package/dist/core/runtime-credentials.d.ts.map +1 -1
  337. package/dist/core/runtime-credentials.js +14 -1
  338. package/dist/core/runtime-credentials.js.map +1 -1
  339. package/dist/core/sdk.d.ts +3 -0
  340. package/dist/core/sdk.d.ts.map +1 -1
  341. package/dist/core/sdk.js +1 -0
  342. package/dist/core/sdk.js.map +1 -1
  343. package/dist/core/session-manager.d.ts +11 -1
  344. package/dist/core/session-manager.d.ts.map +1 -1
  345. package/dist/core/session-manager.js +111 -33
  346. package/dist/core/session-manager.js.map +1 -1
  347. package/dist/core/session-ownership.d.ts.map +1 -1
  348. package/dist/core/session-ownership.js +8 -3
  349. package/dist/core/session-ownership.js.map +1 -1
  350. package/dist/core/session-retention.d.ts.map +1 -1
  351. package/dist/core/session-retention.js +18 -7
  352. package/dist/core/session-retention.js.map +1 -1
  353. package/dist/core/session-startup-settings.d.ts +10 -0
  354. package/dist/core/session-startup-settings.d.ts.map +1 -0
  355. package/dist/core/session-startup-settings.js +70 -0
  356. package/dist/core/session-startup-settings.js.map +1 -0
  357. package/dist/core/subscriptions.d.ts +16 -7
  358. package/dist/core/subscriptions.d.ts.map +1 -1
  359. package/dist/core/subscriptions.js +96 -55
  360. package/dist/core/subscriptions.js.map +1 -1
  361. package/dist/core/trust-manager.d.ts +2 -1
  362. package/dist/core/trust-manager.d.ts.map +1 -1
  363. package/dist/core/trust-manager.js +6 -1
  364. package/dist/core/trust-manager.js.map +1 -1
  365. package/dist/core/update-check.d.ts.map +1 -1
  366. package/dist/core/update-check.js.map +1 -1
  367. package/dist/core/usage-accounting.d.ts +47 -0
  368. package/dist/core/usage-accounting.d.ts.map +1 -0
  369. package/dist/core/usage-accounting.js +205 -0
  370. package/dist/core/usage-accounting.js.map +1 -0
  371. package/dist/core/usage-adapters/kimi-coding.d.ts +2 -2
  372. package/dist/core/usage-adapters/kimi-coding.d.ts.map +1 -1
  373. package/dist/core/usage-adapters/kimi-coding.js +2 -2
  374. package/dist/core/usage-adapters/kimi-coding.js.map +1 -1
  375. package/dist/core/usage-adapters/openai-codex.d.ts +3 -2
  376. package/dist/core/usage-adapters/openai-codex.d.ts.map +1 -1
  377. package/dist/core/usage-adapters/openai-codex.js +3 -3
  378. package/dist/core/usage-adapters/openai-codex.js.map +1 -1
  379. package/dist/core/usage-adapters/xai.d.ts +2 -2
  380. package/dist/core/usage-adapters/xai.d.ts.map +1 -1
  381. package/dist/core/usage-adapters/xai.js +3 -3
  382. package/dist/core/usage-adapters/xai.js.map +1 -1
  383. package/dist/core/usage-adapters/zai.d.ts +2 -2
  384. package/dist/core/usage-adapters/zai.d.ts.map +1 -1
  385. package/dist/core/usage-adapters/zai.js +2 -2
  386. package/dist/core/usage-adapters/zai.js.map +1 -1
  387. package/dist/core/usage-history.d.ts +1 -18
  388. package/dist/core/usage-history.d.ts.map +1 -1
  389. package/dist/core/usage-history.js +46 -114
  390. package/dist/core/usage-history.js.map +1 -1
  391. package/dist/core/usage-service.d.ts +9 -2
  392. package/dist/core/usage-service.d.ts.map +1 -1
  393. package/dist/core/usage-service.js +95 -50
  394. package/dist/core/usage-service.js.map +1 -1
  395. package/dist/gateway/agent-bridge.d.ts +9 -1
  396. package/dist/gateway/agent-bridge.d.ts.map +1 -1
  397. package/dist/gateway/agent-bridge.js +91 -37
  398. package/dist/gateway/agent-bridge.js.map +1 -1
  399. package/dist/gateway/buttons.d.ts +8 -1
  400. package/dist/gateway/buttons.d.ts.map +1 -1
  401. package/dist/gateway/buttons.js +76 -18
  402. package/dist/gateway/buttons.js.map +1 -1
  403. package/dist/gateway/commands.d.ts +1 -0
  404. package/dist/gateway/commands.d.ts.map +1 -1
  405. package/dist/gateway/commands.js +10 -4
  406. package/dist/gateway/commands.js.map +1 -1
  407. package/dist/gateway/cron.d.ts +12 -11
  408. package/dist/gateway/cron.d.ts.map +1 -1
  409. package/dist/gateway/cron.js +65 -56
  410. package/dist/gateway/cron.js.map +1 -1
  411. package/dist/gateway/index.d.ts.map +1 -1
  412. package/dist/gateway/index.js +2 -1
  413. package/dist/gateway/index.js.map +1 -1
  414. package/dist/gateway/mobile-commands.d.ts +1 -0
  415. package/dist/gateway/mobile-commands.d.ts.map +1 -1
  416. package/dist/gateway/mobile-commands.js +69 -15
  417. package/dist/gateway/mobile-commands.js.map +1 -1
  418. package/dist/gateway/presenter.d.ts +12 -2
  419. package/dist/gateway/presenter.d.ts.map +1 -1
  420. package/dist/gateway/presenter.js +73 -38
  421. package/dist/gateway/presenter.js.map +1 -1
  422. package/dist/gateway/router.d.ts +2 -2
  423. package/dist/gateway/router.d.ts.map +1 -1
  424. package/dist/gateway/router.js +17 -2
  425. package/dist/gateway/router.js.map +1 -1
  426. package/dist/gateway/service.d.ts +2 -0
  427. package/dist/gateway/service.d.ts.map +1 -1
  428. package/dist/gateway/service.js +153 -0
  429. package/dist/gateway/service.js.map +1 -1
  430. package/dist/main.d.ts.map +1 -1
  431. package/dist/main.js +86 -33
  432. package/dist/main.js.map +1 -1
  433. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  434. package/dist/modes/interactive/components/assistant-message.js +6 -4
  435. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  436. package/dist/modes/interactive/components/context-view.d.ts.map +1 -1
  437. package/dist/modes/interactive/components/context-view.js +2 -2
  438. package/dist/modes/interactive/components/context-view.js.map +1 -1
  439. package/dist/modes/interactive/components/copyable-text.d.ts.map +1 -1
  440. package/dist/modes/interactive/components/copyable-text.js +3 -2
  441. package/dist/modes/interactive/components/copyable-text.js.map +1 -1
  442. package/dist/modes/interactive/components/extension-editor.d.ts.map +1 -1
  443. package/dist/modes/interactive/components/extension-editor.js +1 -1
  444. package/dist/modes/interactive/components/extension-editor.js.map +1 -1
  445. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  446. package/dist/modes/interactive/components/footer.js +8 -12
  447. package/dist/modes/interactive/components/footer.js.map +1 -1
  448. package/dist/modes/interactive/components/usage-view.d.ts +5 -0
  449. package/dist/modes/interactive/components/usage-view.d.ts.map +1 -1
  450. package/dist/modes/interactive/components/usage-view.js +21 -6
  451. package/dist/modes/interactive/components/usage-view.js.map +1 -1
  452. package/dist/modes/interactive/interactive-mode.d.ts +3 -7
  453. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  454. package/dist/modes/interactive/interactive-mode.js +151 -131
  455. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  456. package/dist/modes/interactive/smooth-streaming.d.ts.map +1 -1
  457. package/dist/modes/interactive/smooth-streaming.js.map +1 -1
  458. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  459. package/dist/modes/rpc/rpc-mode.js +2 -1
  460. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  461. package/dist/node-runtime/{adapter-VFG7WNPX.js → adapter-247RTYLS.js} +4 -5
  462. package/dist/node-runtime/agent-session-services-RTUGP3XR.js +54 -0
  463. package/dist/node-runtime/{brave-UWDA3I22.js → brave-2AFFAXNN.js} +1 -1
  464. package/dist/node-runtime/{builtin-extensions-I2HIFEMY.js → builtin-extensions-N4EUD6SB.js} +8 -7
  465. package/dist/node-runtime/{chunk-QH6YL7VK.js → chunk-252ZVPPF.js} +3 -3
  466. package/dist/node-runtime/{chunk-PCEW76PM.js → chunk-2OIPYKLZ.js} +6 -6
  467. package/dist/node-runtime/{chunk-XBWPBZBN.js → chunk-2SWW7KMW.js} +1 -1
  468. package/dist/node-runtime/{chunk-UQUCFAJ3.js → chunk-2VIW3IMF.js} +40 -7
  469. package/dist/node-runtime/{chunk-UOEDI7RP.js → chunk-4KNKQGHM.js} +2 -2
  470. package/dist/node-runtime/chunk-4QRUZ64T.js +1203 -0
  471. package/dist/node-runtime/{chunk-FQMM2EZ2.js → chunk-64XTQNLA.js} +29 -7
  472. package/dist/node-runtime/{chunk-SPVDBUOS.js → chunk-6O3IW3IA.js} +2 -2
  473. package/dist/node-runtime/{chunk-5ZQXRPMC.js → chunk-6ZZHGUSA.js} +2 -2
  474. package/dist/node-runtime/{chunk-WIF24I7G.js → chunk-APVM5NEU.js} +149 -144
  475. package/dist/node-runtime/{chunk-LWYIVUGV.js → chunk-B2IBAXNX.js} +48 -31
  476. package/dist/node-runtime/{chunk-M3LZLQW2.js → chunk-BDRGN3L2.js} +1 -0
  477. package/dist/node-runtime/{chunk-LJTIVM7I.js → chunk-BMRXLQWQ.js} +464 -160
  478. package/dist/node-runtime/{chunk-GJ2RDBRL.js → chunk-BYC6RKCN.js} +4 -2
  479. package/dist/node-runtime/{chunk-T4DA4XE7.js → chunk-DFMPRAQQ.js} +162 -82
  480. package/dist/node-runtime/{chunk-SN2KSMPQ.js → chunk-DQSCFU7R.js} +13 -7
  481. package/dist/node-runtime/{chunk-UVWCDQYF.js → chunk-E5DQGNJI.js} +455 -278
  482. package/dist/node-runtime/{chunk-4SBQAI4T.js → chunk-EBLAZVSA.js} +2058 -73
  483. package/dist/node-runtime/{chunk-CSFI6YXL.js → chunk-ES6PBSIE.js} +1 -1
  484. package/dist/node-runtime/{chunk-IF24A3FH.js → chunk-EVM653DD.js} +4 -4
  485. package/dist/node-runtime/{chunk-HTFRRDSF.js → chunk-F2SMQ6ES.js} +3 -2
  486. package/dist/node-runtime/chunk-F2V2F4ZG.js +114 -0
  487. package/dist/node-runtime/{chunk-IKU6Y7DL.js → chunk-FE3WZI7F.js} +9 -6
  488. package/dist/node-runtime/{chunk-6VYZ5UFP.js → chunk-FLGEEH27.js} +1 -1
  489. package/dist/node-runtime/{chunk-5EFIU3OM.js → chunk-FTKEZL27.js} +1 -1
  490. package/dist/node-runtime/{chunk-RGQAEOM5.js → chunk-FYIFPFXE.js} +23 -6
  491. package/dist/node-runtime/{chunk-HMBGROQK.js → chunk-GLDXBBL6.js} +3 -3
  492. package/dist/node-runtime/{chunk-KWA4OC2J.js → chunk-H6YBCWKG.js} +1 -1
  493. package/dist/node-runtime/{chunk-2MI5OPMN.js → chunk-HNNHHJAB.js} +68 -50
  494. package/dist/node-runtime/{chunk-I74LN5JG.js → chunk-HUD2RFJW.js} +2 -2
  495. package/dist/node-runtime/{chunk-XHIRAZ26.js → chunk-IAZSK7KK.js} +1 -1
  496. package/dist/node-runtime/{chunk-GYIXXQAO.js → chunk-ICKGAKWX.js} +23 -59
  497. package/dist/node-runtime/{chunk-X3PGBLQ7.js → chunk-IHHTWSXN.js} +9 -9
  498. package/dist/node-runtime/{chunk-DAPBPCBP.js → chunk-IPP5BIV5.js} +25 -3
  499. package/dist/node-runtime/{chunk-QFWG2RVL.js → chunk-IXG6F4NT.js} +11 -0
  500. package/dist/node-runtime/{chunk-L24TPBS4.js → chunk-JEK35V2M.js} +45 -31
  501. package/dist/node-runtime/{chunk-RDDAZOMU.js → chunk-JL4HYQXK.js} +1 -1
  502. package/dist/node-runtime/{chunk-2HMIRK7W.js → chunk-LHV3V67B.js} +5 -5
  503. package/dist/node-runtime/{chunk-UAEOTO52.js → chunk-MNQXDFPV.js} +6 -2
  504. package/dist/node-runtime/{chunk-MPKSOJBT.js → chunk-NHATCSOI.js} +4 -7
  505. package/dist/node-runtime/{chunk-RMQZU2YU.js → chunk-NNNR3QIY.js} +1 -1
  506. package/dist/node-runtime/{chunk-2KIPT4HJ.js → chunk-PWHTSQC4.js} +83 -21
  507. package/dist/node-runtime/{chunk-RWTKOC3B.js → chunk-QBTJG3UM.js} +1 -1
  508. package/dist/node-runtime/{chunk-RCR3XAQY.js → chunk-QT3F6UEV.js} +233 -169
  509. package/dist/node-runtime/{chunk-GS42T6MX.js → chunk-QW3AAHWN.js} +1 -1
  510. package/dist/node-runtime/{chunk-DVQSHCVP.js → chunk-R4WSB2MQ.js} +5 -5
  511. package/dist/node-runtime/{chunk-B4HP6ZWM.js → chunk-RHCGYWO7.js} +1 -1
  512. package/dist/node-runtime/{chunk-2CFDTH5B.js → chunk-RLGY2QIL.js} +45 -59
  513. package/dist/node-runtime/{chunk-CDVHZOOK.js → chunk-RY3FJ6WI.js} +29 -27
  514. package/dist/node-runtime/{chunk-KKUTQQV7.js → chunk-RYRGL7P4.js} +1 -1
  515. package/dist/node-runtime/{chunk-I54LGHWM.js → chunk-STMX7W5I.js} +3 -3
  516. package/dist/node-runtime/chunk-SWWHZ2RI.js +158 -0
  517. package/dist/node-runtime/{chunk-5Q4A37RB.js → chunk-TCT6PCUR.js} +32 -11
  518. package/dist/node-runtime/{chunk-P7XBVXGT.js → chunk-U3YVZ6UC.js} +18 -14
  519. package/dist/node-runtime/{chunk-D5UCKPBQ.js → chunk-UBWW2PID.js} +1 -1
  520. package/dist/node-runtime/{chunk-E75WFZ33.js → chunk-UNUZICC4.js} +3 -3
  521. package/dist/node-runtime/{chunk-RAK2QA2B.js → chunk-UYRKUKFE.js} +4 -4
  522. package/dist/node-runtime/{chunk-LWJXTA6Z.js → chunk-VSUEAI7O.js} +1377 -45
  523. package/dist/node-runtime/{chunk-NAY6UUQZ.js → chunk-WDIVLMOH.js} +1 -1
  524. package/dist/node-runtime/{chunk-E24EO34J.js → chunk-WPXUR3HE.js} +1 -1
  525. package/dist/node-runtime/{chunk-SLVOAQOY.js → chunk-WXYNALHD.js} +113 -1
  526. package/dist/node-runtime/{chunk-KJ6DWS3K.js → chunk-XEOCUEUJ.js} +121 -60
  527. package/dist/node-runtime/chunk-YD3IZAZ7.js +47 -0
  528. package/dist/node-runtime/chunk-YSB6URMT.js +41 -0
  529. package/dist/node-runtime/{chunk-YWOJIGFY.js → chunk-ZEVFBFNF.js} +95 -142
  530. package/dist/node-runtime/{chunk-5B6VKFEV.js → chunk-ZIQUS5QO.js} +1 -1
  531. package/dist/node-runtime/cli-runtime.js +4 -4
  532. package/dist/node-runtime/{command-FSBU2EVZ.js → command-YRT7I2BW.js} +5 -5
  533. package/dist/node-runtime/{commands-NAAL7KNT.js → commands-2ETOWWRA.js} +16 -16
  534. package/dist/node-runtime/{commands-EMBQQVVT.js → commands-D6A6H4TS.js} +11 -18
  535. package/dist/node-runtime/{config-QDD5PUE2.js → config-CU7M7BTK.js} +1 -1
  536. package/dist/node-runtime/{config-D4QUPAHX.js → config-DS7XLMEM.js} +2 -2
  537. package/dist/node-runtime/{direct-tool-executor-4D7UXYU4.js → direct-tool-executor-2QJXVQD2.js} +6 -11
  538. package/dist/node-runtime/{exa-LL64QZR2.js → exa-6VBZNPGE.js} +1 -1
  539. package/dist/node-runtime/{export-html-VM4J2MNR.js → export-html-DBQRRMAY.js} +4 -4
  540. package/dist/node-runtime/{extension-input-E7BJZ35H.js → extension-input-VBBMX7YV.js} +5 -5
  541. package/dist/node-runtime/{extension-selector-WU42XDTU.js → extension-selector-T5AOG5XB.js} +5 -5
  542. package/dist/node-runtime/{extract-EQJE7FZZ.js → extract-BFX2N35A.js} +3 -3
  543. package/dist/node-runtime/{gateway-DQM333YV.js → gateway-V6K2CDWN.js} +51 -42
  544. package/dist/node-runtime/{gemini-search-35OCRFLN.js → gemini-search-C66QHDT6.js} +2 -2
  545. package/dist/node-runtime/{gemini-url-context-UQY3PHHW.js → gemini-url-context-T7DEK73R.js} +3 -3
  546. package/dist/node-runtime/{github-extract-F64RZOEA.js → github-extract-HOGE3D6F.js} +107 -38
  547. package/dist/node-runtime/{goal-NJEE5CTU.js → goal-J7TYMOBK.js} +14 -8
  548. package/dist/node-runtime/index.js +51 -48
  549. package/dist/node-runtime/{init-P5AUV77I.js → init-JBQJIPYI.js} +3 -6
  550. package/dist/node-runtime/{install-cli-NN4YAU44.js → install-cli-INGHIVBY.js} +30 -25
  551. package/dist/node-runtime/interactive-mode-ASZ7APYP.js +75 -0
  552. package/dist/node-runtime/{interactive-view-NGFAMHPW.js → interactive-view-K33PM4OS.js} +8 -8
  553. package/dist/node-runtime/{lsp-manager-3ASUSO4T.js → lsp-manager-S554V5HR.js} +240 -155
  554. package/dist/node-runtime/{lunr-browser-IR7TL3J7.js → lunr-browser-H4FDOR3C.js} +7 -7
  555. package/dist/node-runtime/{lunr-computer-use-Y23CCDIJ.js → lunr-computer-use-VDP2QNRQ.js} +9 -9
  556. package/dist/node-runtime/{lunr-cron-USHC4LXH.js → lunr-cron-WD3YH4CR.js} +93 -80
  557. package/dist/node-runtime/main.js +43 -41
  558. package/dist/node-runtime/{mobile-commands-O5LCHL32.js → mobile-commands-ICUXFW5V.js} +12 -12
  559. package/dist/node-runtime/{model-runtime-OO5HFLWE.js → model-runtime-MZ2JMDV4.js} +4 -4
  560. package/dist/node-runtime/{openai-search-B3MSNCQA.js → openai-search-K72LJDYN.js} +1 -1
  561. package/dist/node-runtime/{package-manager-cli-Q7BL6KZO.js → package-manager-cli-CYM262SI.js} +20 -20
  562. package/dist/node-runtime/{parallel-AI2MNSCU.js → parallel-X724NCNU.js} +1 -1
  563. package/dist/node-runtime/{perplexity-QVJW3I35.js → perplexity-RDHQHVMK.js} +2 -2
  564. package/dist/node-runtime/{pi-intercom-QM53RLTS.js → pi-intercom-NHHEPBMI.js} +2 -2
  565. package/dist/node-runtime/{pi-mcp-adapter-3PHF4KZ4.js → pi-mcp-adapter-PP3GQJQ2.js} +98 -94
  566. package/dist/node-runtime/{pi-ollama-cloud-2F3Y2QNM.js → pi-ollama-cloud-4MNWIMFN.js} +11 -24
  567. package/dist/node-runtime/{pi-prompt-template-model-QWTCGLJU.js → pi-prompt-template-model-FTGELLS5.js} +32 -36
  568. package/dist/node-runtime/{pi-subagents-7IBSSGEW.js → pi-subagents-QPU3OXE4.js} +114 -167
  569. package/dist/node-runtime/{pi-web-access-WTGMNZ32.js → pi-web-access-Z3LP246C.js} +144 -108
  570. package/dist/node-runtime/{print-mode-XQ76CYMT.js → print-mode-2XHN5SUA.js} +3 -3
  571. package/dist/node-runtime/{process-registry-4FAKZQOL.js → process-registry-Q4QWIU33.js} +3 -3
  572. package/dist/node-runtime/{proxy-modes-5FAPSZEZ.js → proxy-modes-VEGC6QG5.js} +8 -15
  573. package/dist/node-runtime/rpc-entry.js +43 -41
  574. package/dist/node-runtime/{rpc-mode-O3XV4SID.js → rpc-mode-32DHJPEJ.js} +4 -4
  575. package/dist/node-runtime/{runtime-4VA6JKNF.js → runtime-EDUUGAQD.js} +56 -46
  576. package/dist/node-runtime/{runtime-EFPPD2UW.js → runtime-UGXM4NPQ.js} +2 -2
  577. package/dist/node-runtime/{runtime-bridges-7WVCLI76.js → runtime-bridges-DNKMNJCF.js} +7 -7
  578. package/dist/node-runtime/{service-MDQIPQ26.js → service-IHLGFLBT.js} +6 -4
  579. package/dist/node-runtime/{session-handoff-GWARVEWT.js → session-handoff-LYH53ESV.js} +4 -4
  580. package/dist/node-runtime/{session-manager-JB5J6XBN.js → session-manager-ZJ3N5Q74.js} +3 -3
  581. package/dist/node-runtime/{session-selector-GIM4DHQ2.js → session-selector-I73U3EIO.js} +7 -7
  582. package/dist/node-runtime/{settings-manager-DJDM5AHM.js → settings-manager-P2TKGYTR.js} +5 -5
  583. package/dist/node-runtime/{setup-JBKOLJ6F.js → setup-H7CCELIL.js} +15 -1
  584. package/dist/node-runtime/{setup-PFBWRNUI.js → setup-OLQ4GXWS.js} +17 -17
  585. package/dist/node-runtime/{src-IVPNZ2BX.js → src-6RV4PXKJ.js} +64 -36
  586. package/dist/node-runtime/{subagent-executor-LPZ4BHWE.js → subagent-executor-UI6SHG3X.js} +412 -288
  587. package/dist/node-runtime/{tavily-WEZFVFP7.js → tavily-KZBFYQB6.js} +1 -1
  588. package/dist/node-runtime/{theme-UOO5RVFN.js → theme-YLVZKKZD.js} +2 -2
  589. package/dist/node-runtime/{trust-manager-MMISNCYO.js → trust-manager-ZCU76D23.js} +2 -2
  590. package/dist/node-runtime/{update-cli-HNMOTNGX.js → update-cli-F3XXJANQ.js} +6 -6
  591. package/dist/node-runtime/{usage-service-LFB2SWYV.js → usage-service-CPAGBED5.js} +1 -1
  592. package/dist/node-runtime/{video-extract-OOZHR7SU.js → video-extract-UPKYIBW3.js} +3 -3
  593. package/dist/node-runtime/{workflow-OHPBEFO4.js → workflow-ICDI4N3J.js} +208 -78
  594. package/dist/node-runtime/{youtube-extract-FNPAUNHU.js → youtube-extract-77NT7FWH.js} +4 -4
  595. package/dist/utils/clipboard-image.d.ts.map +1 -1
  596. package/dist/utils/clipboard-image.js.map +1 -1
  597. package/dist/utils/exif-orientation.d.ts.map +1 -1
  598. package/dist/utils/exif-orientation.js +25 -10
  599. package/dist/utils/exif-orientation.js.map +1 -1
  600. package/dist/utils/image-resize-core.d.ts.map +1 -1
  601. package/dist/utils/image-resize-core.js +2 -0
  602. package/dist/utils/image-resize-core.js.map +1 -1
  603. package/dist/utils/paths.d.ts +4 -0
  604. package/dist/utils/paths.d.ts.map +1 -1
  605. package/dist/utils/paths.js +33 -2
  606. package/dist/utils/paths.js.map +1 -1
  607. package/dist/utils/sanitize-terminal-text.d.ts +7 -0
  608. package/dist/utils/sanitize-terminal-text.d.ts.map +1 -0
  609. package/dist/utils/sanitize-terminal-text.js +67 -0
  610. package/dist/utils/sanitize-terminal-text.js.map +1 -0
  611. package/docs/browser.md +1 -1
  612. package/docs/custom-provider.md +3 -3
  613. package/docs/extensions.md +8 -4
  614. package/docs/features.md +25 -7
  615. package/docs/keybindings.md +1 -1
  616. package/docs/models.md +5 -5
  617. package/docs/packages.md +1 -1
  618. package/docs/providers.md +2 -2
  619. package/docs/rpc.md +7 -7
  620. package/docs/security.md +10 -5
  621. package/docs/sessions.md +2 -2
  622. package/docs/skills.md +1 -1
  623. package/docs/terminal-setup.md +7 -7
  624. package/docs/themes.md +1 -1
  625. package/docs/usage.md +1 -1
  626. package/examples/extensions/auto-commit-on-exit.ts +1 -1
  627. package/examples/extensions/bash-spawn-hook.ts +1 -1
  628. package/examples/extensions/built-in-tool-renderer.ts +1 -1
  629. package/examples/extensions/claude-rules.ts +1 -1
  630. package/examples/extensions/commands.ts +1 -1
  631. package/examples/extensions/custom-compaction.ts +1 -1
  632. package/examples/extensions/custom-provider-anthropic/index.ts +3 -3
  633. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  634. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  635. package/examples/extensions/custom-provider-gitlab-duo/index.ts +1 -1
  636. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  637. package/examples/extensions/doom-overlay/index.ts +1 -1
  638. package/examples/extensions/git-merge-and-resolve.ts +2 -2
  639. package/examples/extensions/gondolin/index.ts +1 -1
  640. package/examples/extensions/gondolin/package-lock.json +2 -2
  641. package/examples/extensions/gondolin/package.json +1 -1
  642. package/examples/extensions/hidden-thinking-label.ts +1 -1
  643. package/examples/extensions/inline-bash.ts +2 -2
  644. package/examples/extensions/input-transform-streaming.ts +2 -2
  645. package/examples/extensions/input-transform.ts +2 -2
  646. package/examples/extensions/interactive-shell.ts +1 -1
  647. package/examples/extensions/kimi-deferred-tools.ts +1 -1
  648. package/examples/extensions/mac-system-theme.ts +1 -1
  649. package/examples/extensions/minimal-mode.ts +1 -1
  650. package/examples/extensions/modal-editor.ts +1 -1
  651. package/examples/extensions/model-status.ts +1 -1
  652. package/examples/extensions/notify.ts +3 -3
  653. package/examples/extensions/overlay-qa-tests.ts +1 -1
  654. package/examples/extensions/overlay-test.ts +1 -1
  655. package/examples/extensions/pirate.ts +1 -1
  656. package/examples/extensions/preset.ts +3 -3
  657. package/examples/extensions/project-trust.ts +4 -4
  658. package/examples/extensions/prompt-customizer.ts +1 -1
  659. package/examples/extensions/rainbow-editor.ts +1 -1
  660. package/examples/extensions/rpc-demo.ts +1 -1
  661. package/examples/extensions/sandbox/index.ts +7 -7
  662. package/examples/extensions/sandbox/package-lock.json +2 -2
  663. package/examples/extensions/sandbox/package.json +1 -1
  664. package/examples/extensions/shutdown-command.ts +5 -5
  665. package/examples/extensions/ssh.ts +2 -2
  666. package/examples/extensions/subagent/README.md +3 -3
  667. package/examples/extensions/subagent/index.ts +2 -2
  668. package/examples/extensions/titlebar-spinner.ts +1 -1
  669. package/examples/extensions/tool-override.ts +1 -1
  670. package/examples/extensions/tools.ts +1 -1
  671. package/examples/extensions/with-deps/package-lock.json +2 -2
  672. package/examples/extensions/with-deps/package.json +1 -1
  673. package/examples/extensions/working-indicator.ts +1 -1
  674. package/examples/extensions/working-message-test.ts +1 -1
  675. package/examples/sdk/01-minimal.ts +1 -1
  676. package/examples/sdk/03-custom-prompt.ts +1 -1
  677. package/examples/sdk/04-skills.ts +1 -1
  678. package/examples/sdk/06-extensions.ts +2 -2
  679. package/examples/sdk/08-prompt-templates.ts +1 -1
  680. package/install-lock/package-lock.json +24 -24
  681. package/install-lock/package.json +2 -2
  682. package/npm-shrinkwrap.json +60 -24
  683. package/package.json +9 -9
  684. package/dist/modes/interactive/components/exit-card.d.ts +0 -22
  685. package/dist/modes/interactive/components/exit-card.d.ts.map +0 -1
  686. package/dist/modes/interactive/components/exit-card.js +0 -69
  687. package/dist/modes/interactive/components/exit-card.js.map +0 -1
  688. package/dist/node-runtime/agent-session-services-5YXS2PLF.js +0 -51
  689. package/dist/node-runtime/chunk-2IDTZAG5.js +0 -1415
  690. package/dist/node-runtime/chunk-3MISGG4S.js +0 -769
  691. package/dist/node-runtime/chunk-4HXHDDCF.js +0 -16
  692. package/dist/node-runtime/chunk-5B5QN3ZQ.js +0 -356
  693. package/dist/node-runtime/chunk-7IQGBKBJ.js +0 -2033
  694. package/dist/node-runtime/chunk-AUXVGBO4.js +0 -19
  695. package/dist/node-runtime/chunk-PTFBPO3C.js +0 -50
  696. package/dist/node-runtime/interactive-mode-YOHZVMKX.js +0 -74
  697. package/dist/node-runtime/mcp-auth-flow-QVLFVLEO.js +0 -33
@@ -4,34 +4,37 @@ import {
4
4
  createSyntheticSourceInfo,
5
5
  expandPromptTemplate,
6
6
  formatSkillsForPrompt
7
- } from "./chunk-SN2KSMPQ.js";
7
+ } from "./chunk-DQSCFU7R.js";
8
8
  import {
9
9
  TODO_TOOL_NAMES
10
10
  } from "./chunk-CCCN2UCX.js";
11
11
  import {
12
12
  stripFrontmatter
13
- } from "./chunk-QFWG2RVL.js";
13
+ } from "./chunk-IXG6F4NT.js";
14
14
  import {
15
+ SUBAGENT_CHILD_PERMISSION_ENV,
15
16
  createAllToolDefinitions,
16
17
  createLocalBashOperations,
17
18
  createToolDefinitionFromAgentTool,
19
+ isSubagentChildProcess,
20
+ resolveChildRuntimePermissionMode,
18
21
  wrapToolDefinition
19
- } from "./chunk-YWOJIGFY.js";
22
+ } from "./chunk-ZEVFBFNF.js";
23
+ import {
24
+ stripAnsi
25
+ } from "./chunk-6ZZHGUSA.js";
20
26
  import {
21
27
  DEFAULT_MAX_BYTES,
22
28
  truncateTail
23
29
  } from "./chunk-53YJI7JU.js";
24
- import {
25
- stripAnsi
26
- } from "./chunk-5ZQXRPMC.js";
27
30
  import {
28
31
  ModelRuntime,
29
32
  isAuthInvalidError,
30
33
  isUsageLimitError
31
- } from "./chunk-KJ6DWS3K.js";
34
+ } from "./chunk-XEOCUEUJ.js";
32
35
  import {
33
36
  SettingsManager
34
- } from "./chunk-I74LN5JG.js";
37
+ } from "./chunk-HUD2RFJW.js";
35
38
  import {
36
39
  DEFAULT_THINKING_LEVEL,
37
40
  calculateContextTokens,
@@ -43,54 +46,70 @@ import {
43
46
  generateBranchSummary,
44
47
  prepareCompaction,
45
48
  shouldCompact
46
- } from "./chunk-GYIXXQAO.js";
49
+ } from "./chunk-ICKGAKWX.js";
47
50
  import {
48
51
  ExtensionRunner,
49
52
  emitSessionShutdownEvent
50
- } from "./chunk-GJ2RDBRL.js";
53
+ } from "./chunk-BYC6RKCN.js";
51
54
  import {
52
55
  getSubagentCancellation
53
56
  } from "./chunk-BBUVIEZB.js";
54
57
  import {
55
- gateToolCall
56
- } from "./chunk-WIF24I7G.js";
58
+ AUTO_MODE_ADDENDUM,
59
+ READ_ONLY_MODE_ADDENDUM,
60
+ deletePermissionContext,
61
+ gateToolCall,
62
+ getPermissionMode,
63
+ initializePermissionContext,
64
+ setPermissionMode
65
+ } from "./chunk-APVM5NEU.js";
57
66
  import {
58
67
  isUserInstructionsPath,
59
68
  loadSelectedUserInstructions
60
- } from "./chunk-M3LZLQW2.js";
69
+ } from "./chunk-BDRGN3L2.js";
61
70
  import {
62
71
  list
63
- } from "./chunk-KKUTQQV7.js";
72
+ } from "./chunk-RYRGL7P4.js";
64
73
  import {
65
74
  sanitizeBinaryOutput
66
- } from "./chunk-CSFI6YXL.js";
75
+ } from "./chunk-ES6PBSIE.js";
67
76
  import {
68
77
  SessionTransferError
69
- } from "./chunk-I54LGHWM.js";
78
+ } from "./chunk-STMX7W5I.js";
70
79
  import {
71
80
  CURRENT_SESSION_VERSION,
72
81
  SessionManager,
73
82
  getDefaultSessionDir,
74
83
  getLatestCompactionEntry
75
- } from "./chunk-2KIPT4HJ.js";
84
+ } from "./chunk-PWHTSQC4.js";
76
85
  import {
77
86
  convertToLlm
78
87
  } from "./chunk-FVDOXRUD.js";
79
88
  import {
80
89
  MEMORY_TOOL_NAMES
81
90
  } from "./chunk-UJOCPOMX.js";
91
+ import {
92
+ getUsageServiceBridge
93
+ } from "./chunk-HNNHHJAB.js";
82
94
  import {
83
95
  SessionOwnership,
84
- canonicalSessionPath
85
- } from "./chunk-UAEOTO52.js";
96
+ canonicalSessionPath,
97
+ writeSessionJson
98
+ } from "./chunk-MNQXDFPV.js";
86
99
  import {
87
100
  measureStartup,
88
101
  time
89
102
  } from "./chunk-PVCDKGR6.js";
103
+ import {
104
+ collectChildUsage,
105
+ collectUsageRequests,
106
+ totalChildUsage,
107
+ totalRequestUsage
108
+ } from "./chunk-SWWHZ2RI.js";
90
109
  import {
91
110
  getThemeByName,
92
111
  theme
93
- } from "./chunk-RDDAZOMU.js";
112
+ } from "./chunk-JL4HYQXK.js";
94
113
  import {
95
114
  CONFIG_DIR_NAME,
96
115
  getAgentDir,
@@ -98,7 +117,7 @@ import {
98
117
  getExamplesPath,
99
118
  getReadmePath,
100
119
  resolvePath
101
- } from "./chunk-FQMM2EZ2.js";
120
+ } from "./chunk-64XTQNLA.js";
102
121
 
103
122
  // packages/coding-agent/dist/core/agent-session-services.js
104
123
  import { join as join7 } from "node:path";
@@ -111,7 +130,7 @@ import { clampThinkingLevel as clampThinkingLevel2 } from "@ashx-j/lunr-ai";
111
130
  // packages/coding-agent/dist/core/agent-session.js
112
131
  import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "node:fs";
113
132
  import { basename, dirname as dirname2, join as join4, resolve as resolve2 } from "node:path";
114
- import { clampThinkingLevel, cleanupSessionResources, getSupportedThinkingLevels, isContextOverflow, isRetryableAssistantError, modelsAreEqual, resetApiProviders, streamSimple } from "@ashx-j/lunr-ai/compat";
133
+ import { clampThinkingLevel, cleanupSessionResources, estimateContextTokens as estimateRequestContextTokens, getSupportedThinkingLevels, isContextOverflow, isRetryableAssistantError, modelsAreEqual, resetApiProviders, streamSimple } from "@ashx-j/lunr-ai/compat";
115
134
 
116
135
  // packages/coding-agent/dist/utils/sleep.js
117
136
  function sleep(ms, signal) {
@@ -232,6 +251,10 @@ var ModelRegistry = class {
232
251
  constructor(runtime) {
233
252
  this.runtime = runtime;
234
253
  }
254
+ /** Owner-bound usage bridge for deferred footer rendering. */
255
+ getUsageServiceBridge() {
256
+ return getUsageServiceBridge(this.runtime);
257
+ }
235
258
  /** Reload models.json asynchronously. Await before making synchronous registry reads. */
236
259
  refresh() {
237
260
  return this.runtime.reloadConfig();
@@ -343,15 +366,20 @@ function disableRollbackForSession(sessionId) {
343
366
  }
344
367
  function pruneTurns(ctx) {
345
368
  let maxTurns = ctx.settingsManager?.getRollbackTurns() ?? 2;
346
- for (; ctx.turns.length > maxTurns; ) {
347
- let old = ctx.turns.shift();
348
- old && cleanupTurnFiles(ctx, old);
369
+ for (; ctx.turns.filter((turn) => !turn.recovery).length > maxTurns; ) {
370
+ let index = ctx.turns.findIndex((turn) => !turn.recovery);
371
+ if (index < 0)
372
+ break;
373
+ let [old] = ctx.turns.splice(index, 1);
374
+ cleanupTurnFiles(ctx, old);
349
375
  }
350
376
  }
351
377
  function beginTurn(cwd, sessionId) {
352
378
  let ctx = getContext(sessionId);
353
379
  if (!isRollbackEnabled(ctx.sessionId))
354
380
  return;
381
+ for (let pending of ctx.turns.filter((turn2) => turn2.recovery))
382
+ pending.recovery.newerTurnStarted = !0, persistRecoveryProgress(ctx, pending);
355
383
  cwd && (ctx.lastCwd = cwd), ctx.currentTurnIndex++;
356
384
  let turn = { turnIndex: ctx.currentTurnIndex, cwd, files: /* @__PURE__ */ new Map() };
357
385
  ctx.turns.push(turn), pruneTurns(ctx), cwd && ctx.settingsManager?.getRollbackScope() === "tree" && captureTreeBaseline(ctx, cwd);
@@ -496,6 +524,7 @@ function readManifest(path) {
496
524
  let files = parsed.files;
497
525
  return {
498
526
  cwd: typeof parsed.cwd == "string" ? parsed.cwd : void 0,
527
+ recovery: parseRecoveryProgress(parsed.recovery),
499
528
  files: files && typeof files == "object" && !Array.isArray(files) ? files : {}
500
529
  };
501
530
  }
@@ -504,6 +533,31 @@ function readManifest(path) {
504
533
  return { files: {} };
505
534
  }
506
535
  }
536
+ function parseRecoveryProgress(value) {
537
+ if (!value || typeof value != "object")
538
+ return;
539
+ let progress = value;
540
+ if (!(typeof progress.turnsToConsume != "number" || !Number.isInteger(progress.turnsToConsume) || progress.turnsToConsume < 1 || !Array.isArray(progress.completed) || !progress.completed.every((path) => typeof path == "string")))
541
+ return {
542
+ targetUserId: typeof progress.targetUserId == "string" ? progress.targetUserId : void 0,
543
+ turnsToConsume: progress.turnsToConsume,
544
+ completed: progress.completed,
545
+ pending: typeof progress.pending == "string" ? progress.pending : void 0,
546
+ newerTurnStarted: progress.newerTurnStarted === !0
547
+ };
548
+ }
549
+ function persistRecoveryProgress(ctx, turn) {
550
+ let turnDir = getTurnDir(ctx, turn.turnIndex);
551
+ mkdirSync(turnDir, { recursive: !0 });
552
+ let manifest = { cwd: turn.cwd, recovery: turn.recovery, files: {} };
553
+ for (let [path, snap] of turn.files)
554
+ manifest.files[path] = {
555
+ existed: snap.existed,
556
+ createdByTool: snap.createdByTool,
557
+ snapFile: snap.existed ? snapFileName(path) : void 0
558
+ };
559
+ writeSessionJson(join3(turnDir, "manifest.json"), manifest);
560
+ }
507
561
  function loadPersistedTurns(ctx) {
508
562
  try {
509
563
  let sessionDir = join3(ROLLBACK_BASE, ctx.sessionId);
@@ -525,7 +579,7 @@ function loadPersistedTurns(ctx) {
525
579
  }
526
580
  files.set(absPath, { existed: meta.existed, content, createdByTool: meta.createdByTool });
527
581
  }
528
- loaded.push({ turnIndex, cwd: manifest.cwd, files });
582
+ loaded.push({ turnIndex, cwd: manifest.cwd, files, recovery: manifest.recovery });
529
583
  }
530
584
  loaded.sort((a, b) => a.turnIndex - b.turnIndex), ctx.turns = loaded, ctx.currentTurnIndex = loaded.length > 0 ? loaded[loaded.length - 1].turnIndex : -1, pruneTurns(ctx);
531
585
  } catch {
@@ -564,42 +618,99 @@ function warnExternalModification(ctx, message) {
564
618
  }
565
619
  }
566
620
  }
621
+ function recoveryTurn(ctx) {
622
+ return ctx.turns.find((turn) => turn.recovery) ?? [...ctx.turns].reverse().find((turn) => turn.files.size > 0);
623
+ }
624
+ function getRollbackTargetUserId(sessionId) {
625
+ return recoveryTurn(getContext(sessionId))?.recovery?.targetUserId;
626
+ }
627
+ function getRollbackRecoveryBlockReason(sessionId) {
628
+ let ctx = getContext(sessionId), pending = ctx.turns.find((turn) => turn.recovery);
629
+ if (pending?.recovery && (pending.recovery.newerTurnStarted || ctx.turns.some((turn) => turn.turnIndex > pending.turnIndex + pending.recovery.turnsToConsume - 1)))
630
+ return "Automatic rollback retry is unavailable after newer turns. Chat and files are unchanged. Use /new to continue in a separate chat; this does not repair the retained recovery. Snapshots remain available for manual recovery.";
631
+ }
567
632
  function peekRollbackTurnsConsumed(sessionId) {
568
633
  let ctx = getContext(sessionId);
569
- if (!isRollbackEnabled(ctx.sessionId) || ctx.turns.length === 0)
634
+ if (!isRollbackEnabled(ctx.sessionId))
570
635
  return 0;
571
- let consumed = 0;
572
- for (let i = ctx.turns.length - 1; i >= 0 && (consumed++, !(ctx.turns[i].files.size > 0)); i--)
573
- ;
574
- return consumed;
636
+ let turn = recoveryTurn(ctx);
637
+ return turn?.recovery?.turnsToConsume ?? (turn ? ctx.turns.length - ctx.turns.indexOf(turn) : ctx.turns.length);
638
+ }
639
+ function commitRollbackTurn(sessionId, turnIndex) {
640
+ let ctx = getContext(sessionId), blocked = getRollbackRecoveryBlockReason(sessionId);
641
+ if (blocked)
642
+ throw new Error(blocked);
643
+ let index = ctx.turns.findIndex((turn2) => turn2.turnIndex === turnIndex);
644
+ if (index < 0)
645
+ return;
646
+ let turn = ctx.turns[index];
647
+ if (!turn.recovery || [...turn.files.keys()].some((path) => !turn.recovery?.completed.includes(path)))
648
+ throw new Error("Rollback still has unrestored files.");
649
+ let count = 1;
650
+ for (; index + count < ctx.turns.length && ctx.turns[index + count].files.size === 0; )
651
+ count++;
652
+ for (let removed of ctx.turns.splice(index, count))
653
+ cleanupTurnFiles(ctx, removed);
575
654
  }
576
- function rollbackLastTurn(sessionId) {
577
- let ctx = getContext(sessionId), empty = { restored: [], deleted: [], turnsConsumed: 0 };
655
+ function rollbackLastTurn(sessionId, options = {}) {
656
+ let ctx = getContext(sessionId), result = { restored: [], deleted: [], failed: [], complete: !0, turnsConsumed: 0 };
578
657
  if (!isRollbackEnabled(ctx.sessionId))
579
- return empty;
580
- let turnsConsumed = 0;
581
- for (; ctx.turns.length > 0 && ctx.turns[ctx.turns.length - 1].files.size === 0; ) {
582
- let skipped = ctx.turns.pop();
583
- skipped && (cleanupTurnFiles(ctx, skipped), turnsConsumed++);
584
- }
585
- if (ctx.turns.length === 0)
586
- return empty;
587
- turnsConsumed++;
588
- let turn = ctx.turns[ctx.turns.length - 1], capture = ctx.settingsManager?.getRollbackCapture() ?? "copies", restored = [], deleted = [];
589
- for (let [absPath, snap] of turn.files)
658
+ return result;
659
+ let blocked = getRollbackRecoveryBlockReason(ctx.sessionId);
660
+ if (blocked)
661
+ throw new Error(blocked);
662
+ let turn = recoveryTurn(ctx) ?? (options.deferCommit ? ctx.turns[0] : void 0);
663
+ if (!turn) {
664
+ for (let empty of ctx.turns.splice(0))
665
+ cleanupTurnFiles(ctx, empty);
666
+ return result;
667
+ }
668
+ result.turnIndex = turn.turnIndex, turn.recovery ??= {
669
+ turnsToConsume: peekRollbackTurnsConsumed(ctx.sessionId),
670
+ completed: [],
671
+ targetUserId: options.targetUserId
672
+ }, turn.recovery.targetUserId ??= options.targetUserId, persistRecoveryProgress(ctx, turn);
673
+ let capture = ctx.settingsManager?.getRollbackCapture() ?? "copies";
674
+ for (let [absPath, snap] of turn.files) {
675
+ if (turn.recovery.completed.includes(absPath))
676
+ continue;
677
+ let wasPending = turn.recovery.pending === absPath;
590
678
  try {
591
- if (!isWithinAllowedRoots(absPath, turn)) {
592
- warnExternalModification(ctx, `Rollback skipped ${absPath}: outside the session working directory or lunR config dir.`);
679
+ if (turn.recovery.pending === absPath) {
680
+ if (!(snap.existed ? snap.content && existsSync(absPath) && readFileSync(absPath).equals(snap.content) : !existsSync(absPath))) {
681
+ result.failed.push({
682
+ path: absPath,
683
+ error: "Previous recovery outcome is uncertain. Restore this path from its retained snapshot before retrying."
684
+ });
685
+ continue;
686
+ }
687
+ turn.recovery.completed.push(absPath), turn.recovery.pending = void 0, persistRecoveryProgress(ctx, turn);
593
688
  continue;
594
689
  }
595
- if (snap.existed && snap.content) {
596
- if (!snap.createdByTool && existsSync(absPath) && readFileSync(absPath).equals(snap.content))
597
- continue;
598
- mkdirSync(dirname(absPath), { recursive: !0 }), writeFileSync(absPath, snap.content), restored.push(absPath);
599
- } else snap.existed || (snap.createdByTool || capture === "hybrid" || capture === "shadow-git") && existsSync(absPath) && (unlinkSync(absPath), deleted.push(absPath));
600
- } catch {
690
+ if (!isWithinAllowedRoots(absPath, turn))
691
+ throw warnExternalModification(ctx, `Rollback skipped ${absPath}: outside the session working directory or lunR config dir.`), new Error("Outside the allowed rollback roots.");
692
+ if (turn.recovery.pending) {
693
+ result.failed.push({
694
+ path: absPath,
695
+ error: "Resolve the uncertain recovery path before continuing this turn."
696
+ });
697
+ continue;
698
+ }
699
+ if (snap.existed && !snap.content)
700
+ throw new Error("Snapshot content is unavailable.");
701
+ turn.recovery.pending = absPath, persistRecoveryProgress(ctx, turn), snap.existed && snap.content ? !snap.createdByTool && existsSync(absPath) && readFileSync(absPath).equals(snap.content) || (mkdirSync(dirname(absPath), { recursive: !0 }), writeFileSync(absPath, snap.content), result.restored.push(absPath)) : (snap.createdByTool || capture === "hybrid" || capture === "shadow-git") && existsSync(absPath) && (unlinkSync(absPath), result.deleted.push(absPath)), turn.recovery.completed.push(absPath), turn.recovery.pending = void 0, persistRecoveryProgress(ctx, turn);
702
+ } catch (error) {
703
+ if (!wasPending && turn.recovery.pending === absPath) {
704
+ turn.recovery.pending = void 0;
705
+ try {
706
+ persistRecoveryProgress(ctx, turn);
707
+ } catch {
708
+ }
709
+ }
710
+ result.failed.push({ path: absPath, error: error instanceof Error ? error.message : String(error) });
601
711
  }
602
- return cleanupTurnFiles(ctx, turn), ctx.turns.pop(), { restored, deleted, turnsConsumed };
712
+ }
713
+ return result.complete = result.failed.length === 0, result.complete && !options.deferCommit && (result.turnsConsumed = turn.recovery.turnsToConsume, commitRollbackTurn(ctx.sessionId, turn.turnIndex)), result;
603
714
  }
604
715
  function migrateRollbackSession(oldSessionId, newSessionId) {
605
716
  if (oldSessionId === newSessionId)
@@ -805,7 +916,12 @@ var THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"
805
916
  _retryAbortController = void 0;
806
917
  _retryAttempt = 0;
807
918
  // Bash execution state
808
- _bashAbortController = void 0;
919
+ _bashOperations = /* @__PURE__ */ new Map();
920
+ _operations = /* @__PURE__ */ new Set();
921
+ _closing = !1;
922
+ _disposed = !1;
923
+ _drainPromise;
924
+ _shutdownPromise;
809
925
  _pendingBashMessages = [];
810
926
  // Extension system
811
927
  _extensionRunner;
@@ -838,12 +954,14 @@ var THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"
838
954
  _baseSystemPrompt = "";
839
955
  _baseSystemPromptOptions;
840
956
  _systemPromptOverride;
841
- // lunr: core-owned system-prompt append (read-only mode addendum) applied on top of base/override
957
+ // Optional host-owned prompt append, separate from session permission guidance.
842
958
  _systemPromptAppend;
843
959
  // lunr: core-owned tool-call gates (read-only mode) checked before extension tool_call handlers
844
960
  _toolCallGates = [];
845
961
  constructor(config) {
846
- this.agent = config.agent, this.sessionManager = config.sessionManager, this.settingsManager = config.settingsManager, this._scopedModels = config.scopedModels ?? [], this._resourceLoader = config.resourceLoader, this._customTools = config.customTools ?? [], this._cwd = config.cwd, this._agentDir = config.agentDir ?? getAgentDir(), this._modelRuntime = config.modelRuntime, this._syncOpenAIServiceTier(), this._extensionRunnerRef = config.extensionRunnerRef, this._initialActiveToolNames = config.initialActiveToolNames, this._allowedToolNames = config.allowedToolNames ? new Set(config.allowedToolNames) : void 0, this._excludedToolNames = config.excludedToolNames ? new Set(config.excludedToolNames) : void 0, this._baseToolsOverride = config.baseToolsOverride, this._sessionStartEvent = config.sessionStartEvent ?? { type: "session_start", reason: "startup" };
962
+ this.agent = config.agent, this.sessionManager = config.sessionManager, this.settingsManager = config.settingsManager;
963
+ let permissionMode = config.permissionMode ?? (isSubagentChildProcess() ? resolveChildRuntimePermissionMode(process.env[SUBAGENT_CHILD_PERMISSION_ENV]) : void 0) ?? this.sessionManager.getPermissionMode() ?? this.settingsManager.getDefaultPermissionMode();
964
+ initializePermissionContext(this.sessionId, permissionMode, config.permissionMode), this._scopedModels = config.scopedModels ?? [], this._resourceLoader = config.resourceLoader, this._customTools = config.customTools ?? [], this._cwd = config.cwd, this._agentDir = config.agentDir ?? getAgentDir(), this._modelRuntime = config.modelRuntime, this._syncOpenAIServiceTier(), this._extensionRunnerRef = config.extensionRunnerRef, this._initialActiveToolNames = config.initialActiveToolNames, this._allowedToolNames = config.allowedToolNames ? new Set(config.allowedToolNames) : void 0, this._excludedToolNames = config.excludedToolNames ? new Set(config.excludedToolNames) : void 0, this._baseToolsOverride = config.baseToolsOverride, this._sessionStartEvent = config.sessionStartEvent ?? { type: "session_start", reason: "startup" };
847
965
  let waitInterruptionOwner = { register: () => this._registerSubagentWaitInterruption() };
848
966
  for (let identity of new Set([this.sessionId, this.sessionFile].filter((value) => !!value)))
849
967
  this._unregisterSubagentWaitInterruptionOwners.push(registerSubagentWaitInterruptionOwner(identity, waitInterruptionOwner));
@@ -961,8 +1079,12 @@ var THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"
961
1079
  _installAgentNextTurnRefresh() {
962
1080
  let previousPrepareNextTurnWithContext = this.agent.prepareNextTurnWithContext ?? (this.agent.prepareNextTurn ? async (_turn, signal) => await this.agent.prepareNextTurn?.(signal) : void 0);
963
1081
  this.agent.prepareNextTurnWithContext = async (turn, signal) => {
964
- let previousSnapshot = await previousPrepareNextTurnWithContext?.(turn, signal), previousContext = previousSnapshot?.context ?? turn.context, model = this.model, settings = this.settingsManager.getCompactionSettings();
965
- if (model?.provider === "openai-codex" && settings.enabled && shouldCompact(estimateContextTokens(previousContext.messages).tokens, model.contextWindow, settings)) {
1082
+ let previousSnapshot = await previousPrepareNextTurnWithContext?.(turn, signal), previousContext = {
1083
+ ...previousSnapshot?.context ?? turn.context,
1084
+ systemPrompt: this._withSystemPromptAppend(this._systemPromptOverride ?? this._baseSystemPrompt),
1085
+ tools: this.agent.state.tools.slice()
1086
+ }, model = this.model, settings = this.settingsManager.getCompactionSettings();
1087
+ if (model?.provider === "openai-codex" && settings.enabled && shouldCompact(estimateRequestContextTokens({ ...previousContext, messages: convertToLlm(previousContext.messages) }).tokens, model.contextWindow, settings)) {
966
1088
  let previousCompactionId = getLatestCompactionEntry(this.sessionManager.getBranch())?.id;
967
1089
  await this._runAutoCompaction("threshold", !0);
968
1090
  let currentCompaction = getLatestCompactionEntry(this.sessionManager.getBranch());
@@ -1031,7 +1153,7 @@ var THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"
1031
1153
  }
1032
1154
  }
1033
1155
  }
1034
- if (await this._emitExtensionEvent(event), this._emit(event.type === "agent_end" ? { ...event, willRetry: this._willRetryAfterAgentEnd(event) } : event), event.type === "message_end" && (event.message.role === "custom" ? this.sessionManager.appendCustomMessageEntry(event.message.customType, event.message.content, event.message.display, event.message.details) : (event.message.role === "user" || event.message.role === "assistant" || event.message.role === "toolResult") && this.sessionManager.appendMessage(event.message), event.message.role === "assistant")) {
1156
+ if (event.type === "message_end" && this._activePromptRun?.completion?.messages.push(event.message), await this._emitExtensionEvent(event), this._emit(event.type === "agent_end" ? { ...event, willRetry: this._willRetryAfterAgentEnd(event) } : event), event.type === "message_end" && (event.message.role === "custom" ? this.sessionManager.appendCustomMessageEntry(event.message.customType, event.message.content, event.message.display, event.message.details) : (event.message.role === "user" || event.message.role === "assistant" || event.message.role === "toolResult") && this.sessionManager.appendMessage(event.message), event.message.role === "assistant")) {
1035
1157
  this._lastAssistantMessage = event.message;
1036
1158
  let assistantMsg = event.message;
1037
1159
  assistantMsg.stopReason !== "error" && (this._overflowRecoveryAttempted = !1), assistantMsg.stopReason !== "error" && this._retryAttempt > 0 && (this._emit({
@@ -1182,18 +1304,53 @@ var THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"
1182
1304
  this.transferring = value, value && this._invalidateWaitPromptHandoffs("Session transfer interrupted the pending prompt.");
1183
1305
  }
1184
1306
  assertCanStartWork() {
1185
- if (this.sessionManager.assertWritable(), this.transferring)
1307
+ if (this.sessionManager.assertWritable(), this._closing)
1308
+ throw new Error("Session is closing. New work is not accepted.");
1309
+ if (this.transferring)
1186
1310
  throw new Error("Session transfer is in progress. Wait or reclaim the session.");
1187
1311
  }
1188
- dispose() {
1189
- this._invalidateWaitPromptHandoffs("Session closed before the pending prompt could run.");
1190
- for (let unregister of this._unregisterSubagentWaitInterruptionOwners.splice(0))
1191
- unregister();
1312
+ /** Stop admission synchronously, retaining listeners and session ownership. */
1313
+ stopAdmission() {
1314
+ this._closing = !0, this._invalidateWaitPromptHandoffs("Session closed before the pending prompt could run.");
1315
+ }
1316
+ async _trackOperation(operation) {
1317
+ let settle = () => {
1318
+ }, completion = new Promise((resolve3) => {
1319
+ settle = resolve3;
1320
+ });
1321
+ this._operations.add(completion);
1192
1322
  try {
1193
- this.abortRetry(), this.abortCompaction(), this.abortBranchSummary(), this.abortBash(), this.agent.abort();
1194
- } catch {
1323
+ return await operation();
1324
+ } finally {
1325
+ this._operations.delete(completion), settle();
1326
+ }
1327
+ }
1328
+ /** Cancel owned work and wait for final persistence before extension shutdown. */
1329
+ drain() {
1330
+ return this._drainPromise ? this._drainPromise : (this.stopAdmission(), this._activePromptRun && (this._activePromptRun.gracefulStopRequested = !0), this.abortRetry(), this.abortCompaction(), this.abortBranchSummary(), this.abortBash(), this.clearQueue(), this.agent.abort(), this._drainPromise = (async () => {
1331
+ await Promise.all([...this._operations]), await this.waitForIdle(), await this.agent.waitForIdle(), this._flushPendingBashMessages();
1332
+ })(), this._drainPromise);
1333
+ }
1334
+ /** Await cancellation and persistence, then release listeners and ownership. */
1335
+ shutdown() {
1336
+ return this._shutdownPromise || (this._shutdownPromise = this.drain().then(() => this._disposeSettled())), this._shutdownPromise;
1337
+ }
1338
+ /** Compatibility wrapper. Use await shutdown() when release must be complete. */
1339
+ dispose() {
1340
+ if (this._operations.size === 0 && !this._isAgentRunActive && !this.agent.state.isStreaming) {
1341
+ this.stopAdmission(), this._disposeSettled();
1342
+ return;
1343
+ }
1344
+ this.shutdown().catch(() => {
1345
+ });
1346
+ }
1347
+ _disposeSettled() {
1348
+ if (!this._disposed) {
1349
+ this._disposed = !0;
1350
+ for (let unregister of this._unregisterSubagentWaitInterruptionOwners.splice(0))
1351
+ unregister();
1352
+ this._extensionRunner.invalidate("This extension ctx is stale after session replacement or reload. Do not use a captured pi or command ctx after ctx.newSession(), ctx.fork(), ctx.switchSession(), or ctx.reload(). For newSession, fork, and switchSession, move post-replacement work into withSession and use the ctx passed to withSession. For reload, do not use the old ctx after await ctx.reload()."), this._disconnectFromAgent(), this._eventListeners = [], cleanupSessionResources(this.sessionId), deletePermissionContext(this.sessionId), this.sessionManager.dispose();
1195
1353
  }
1196
- this._extensionRunner.invalidate("This extension ctx is stale after session replacement or reload. Do not use a captured pi or command ctx after ctx.newSession(), ctx.fork(), ctx.switchSession(), or ctx.reload(). For newSession, fork, and switchSession, move post-replacement work into withSession and use the ctx passed to withSession. For reload, do not use the old ctx after await ctx.reload()."), this._disconnectFromAgent(), this._eventListeners = [], cleanupSessionResources(this.sessionId), this.sessionManager.dispose();
1197
1354
  }
1198
1355
  // =========================================================================
1199
1356
  // Read-only State Access
@@ -1245,10 +1402,20 @@ var THINKING_LEVELS = ["off", "minimal", "low", "medium", "high", "xhigh", "max"
1245
1402
  let next = text && text.trim().length > 0 ? text : void 0;
1246
1403
  next !== this._systemPromptAppend && (this._systemPromptAppend = next, this.agent.state.systemPrompt = this._withSystemPromptAppend(this._systemPromptOverride ?? this._baseSystemPrompt));
1247
1404
  }
1405
+ get permissionMode() {
1406
+ return getPermissionMode(this.sessionId);
1407
+ }
1408
+ _permissionAddendum(mode) {
1409
+ return mode === "read-only" ? READ_ONLY_MODE_ADDENDUM : mode === "auto" ? AUTO_MODE_ADDENDUM : void 0;
1410
+ }
1411
+ /** Update the same permission context consulted by headless and interactive tools. */
1412
+ setPermissionMode(mode) {
1413
+ this.assertCanStartWork(), setPermissionMode(mode, this.sessionId), this.sessionManager.setPermissionMode(mode), this.agent.state.systemPrompt = this._withSystemPromptAppend(this._systemPromptOverride ?? this._baseSystemPrompt);
1414
+ }
1248
1415
  _withSystemPromptAppend(prompt) {
1249
- return this._systemPromptAppend ? `${prompt}
1416
+ return [prompt, this._permissionAddendum(this.permissionMode), this._systemPromptAppend].filter(Boolean).join(`
1250
1417
 
1251
- ${this._systemPromptAppend}` : prompt;
1418
+ `);
1252
1419
  }
1253
1420
  /** Current retry attempt (0 if not retrying) */
1254
1421
  get retryAttempt() {
@@ -1410,24 +1577,46 @@ ${this._systemPromptAppend}` : prompt;
1410
1577
  for (let reservation of handoff.reservations.splice(0))
1411
1578
  reservation.reject(error);
1412
1579
  }
1413
- async _runAgentPrompt(messages) {
1580
+ _reservePromptRun() {
1581
+ if (this.assertCanStartWork(), this._isAgentRunActive || this._manualCompactionPromise)
1582
+ throw new Error("Agent is already processing. Specify streamingBehavior ('steer' or 'followUp') to queue the message.");
1414
1583
  let run = { waits: /* @__PURE__ */ new Set(), gracefulStopRequested: !1 };
1415
- this._activePromptRun = run, this._isAgentRunActive = !0;
1416
- try {
1417
- for (await this.agent.prompt(messages); await this._handlePostAgentRun(run); )
1418
- await this.agent.continue();
1419
- } finally {
1420
- this._activePromptRun === run && (this._activePromptRun = void 0), this._systemPromptOverride = void 0, this._flushPendingBashMessages(), await this._emitAgentSettled();
1421
- }
1584
+ return this._activePromptRun = run, this._isAgentRunActive = !0, run;
1585
+ }
1586
+ async _releasePromptRun(run) {
1587
+ this._activePromptRun === run && (this._activePromptRun = void 0, this._systemPromptOverride = void 0, this._flushPendingBashMessages(), await this._emitAgentSettled());
1588
+ }
1589
+ async _runAgentPrompt(messages, owner) {
1590
+ let run = owner ?? this._reservePromptRun();
1591
+ await this._trackOperation(async () => {
1592
+ try {
1593
+ if (this.assertCanStartWork(), run.gracefulStopRequested)
1594
+ throw new Error("Prompt was cancelled during preparation.");
1595
+ for (await this.agent.prompt(Array.isArray(messages) ? messages : [messages], {
1596
+ consumeFollowUps: !run.completion
1597
+ }); await this._handlePostAgentRun(run) && !(run.gracefulStopRequested || this._closing || run.completion?.cancelled); )
1598
+ await this.agent.continue({ consumeFollowUps: !run.completion });
1599
+ if (run.completion) {
1600
+ let completion = run.completion;
1601
+ run.completion = void 0, completion.detach?.();
1602
+ let hasQueuedWork = !run.gracefulStopRequested && !this._closing && this.agent.hasQueuedMessages();
1603
+ if (hasQueuedWork || await this._releasePromptRun(run), completion.settle(), hasQueuedWork)
1604
+ for (await this.agent.continueQueued(); await this._handlePostAgentRun(run) && !(run.gracefulStopRequested || this._closing); )
1605
+ await this.agent.continue();
1606
+ }
1607
+ } finally {
1608
+ await this._releasePromptRun(run);
1609
+ }
1610
+ });
1422
1611
  }
1423
1612
  async _handlePostAgentRun(run) {
1424
1613
  let msg = this._lastAssistantMessage;
1425
- return this._lastAssistantMessage = void 0, !msg || run.gracefulStopRequested ? !1 : msg.stopReason === "error" && this._isRotationError(msg) && await this._tryRotateSubscriptionKey(msg) || this._isRetryableError(msg) && await this._prepareRetry(msg) || msg.stopReason === "error" && this._isRetryableError(msg) && await this._tryRotateSubscriptionKey(msg) || (msg.stopReason === "error" && this._retryAttempt > 0 && (this._emit({
1614
+ return this._lastAssistantMessage = void 0, !msg || run.gracefulStopRequested || run.completion?.signal?.aborted ? !1 : msg.stopReason === "error" && this._isRotationError(msg) && await this._tryRotateSubscriptionKey(msg) || this._isRetryableError(msg) && await this._prepareRetry(msg) || msg.stopReason === "error" && this._isRetryableError(msg) && await this._tryRotateSubscriptionKey(msg) || (msg.stopReason === "error" && this._retryAttempt > 0 && (this._emit({
1426
1615
  type: "auto_retry_end",
1427
1616
  success: !1,
1428
1617
  attempt: this._retryAttempt,
1429
1618
  finalError: msg.errorMessage
1430
- }), this._retryAttempt = 0), await this._checkCompaction(msg)) ? !0 : this.agent.hasQueuedMessages();
1619
+ }), this._retryAttempt = 0), await this._checkCompaction(msg)) ? !0 : !run.completion && this.agent.hasQueuedMessages();
1431
1620
  }
1432
1621
  /**
1433
1622
  * Send a prompt to the agent.
@@ -1440,23 +1629,72 @@ ${this._systemPromptAppend}` : prompt;
1440
1629
  */
1441
1630
  async prompt(text, options) {
1442
1631
  this.assertCanStartWork();
1443
- let preflightResult = options?.preflightResult, prepared, messages;
1444
- try {
1445
- if (prepared = await this._preparePromptInput(text, options, this.isStreaming ? options?.streamingBehavior : void 0), !prepared) {
1446
- preflightResult?.(!0);
1447
- return;
1632
+ let commandName = text.startsWith("/") ? text.slice(1).split(" ")[0] : void 0;
1633
+ if ((options?.expandPromptTemplates ?? !0) && commandName && this._extensionRunner.getCommand(commandName)) {
1634
+ try {
1635
+ await this._tryExecuteExtensionCommand(text), options?.preflightResult?.(!0);
1636
+ } catch (error) {
1637
+ throw options?.preflightResult?.(!1), error;
1448
1638
  }
1449
- if (this.isStreaming) {
1639
+ return;
1640
+ }
1641
+ return this._trackOperation(() => this._prompt(text, options));
1642
+ }
1643
+ async _prompt(text, options, completion) {
1644
+ let run, accepted = !1;
1645
+ try {
1646
+ this.assertCanStartWork();
1647
+ let wasStreaming = this.isStreaming;
1648
+ if (wasStreaming) {
1450
1649
  if (!options?.streamingBehavior)
1451
1650
  throw new Error("Agent is already processing. Specify streamingBehavior ('steer' or 'followUp') to queue the message.");
1452
- options.streamingBehavior === "followUp" ? await this._queueFollowUp(prepared.text, prepared.images) : await this._queueSteer(prepared.text, prepared.images), preflightResult?.(!0);
1651
+ } else if (run = this._reservePromptRun(), run.completion = completion, completion?.signal) {
1652
+ let owner = run, cancel = () => {
1653
+ this._activePromptRun !== owner || owner.completion !== completion || (completion.cancelled = !0, this.agent.abort(), this.abortRetry(), this._autoCompactionAbortController?.abort());
1654
+ };
1655
+ completion.signal.addEventListener("abort", cancel, { once: !0 }), completion.detach = () => completion.signal?.removeEventListener("abort", cancel), completion.signal.throwIfAborted();
1656
+ }
1657
+ let prepared = await this._preparePromptInput(text, options, wasStreaming ? options?.streamingBehavior : void 0);
1658
+ if (this.assertCanStartWork(), run?.completion?.signal?.throwIfAborted(), run?.gracefulStopRequested)
1659
+ throw new Error("Prompt was cancelled during preparation.");
1660
+ if (!prepared) {
1661
+ accepted = !0, options?.preflightResult?.(!0);
1662
+ return;
1663
+ }
1664
+ if (wasStreaming && this.isStreaming) {
1665
+ options?.streamingBehavior === "followUp" ? await this._queueFollowUp(prepared.text, prepared.images) : await this._queueSteer(prepared.text, prepared.images), accepted = !0, options?.preflightResult?.(!0);
1453
1666
  return;
1454
1667
  }
1455
- messages = await this._createPromptMessages(prepared);
1668
+ run ??= this._reservePromptRun(), run.completion = completion;
1669
+ let messages = await this._createPromptMessages(prepared);
1670
+ if (this.assertCanStartWork(), run.completion?.signal?.throwIfAborted(), run.gracefulStopRequested)
1671
+ throw new Error("Prompt was cancelled during preparation.");
1672
+ accepted = !0, options?.preflightResult?.(!0), await this._runAgentPrompt(messages, run);
1456
1673
  } catch (error) {
1457
- throw preflightResult?.(!1), error;
1674
+ throw accepted || options?.preflightResult?.(!1), error;
1675
+ } finally {
1676
+ completion?.detach?.(), run && await this._releasePromptRun(run);
1458
1677
  }
1459
- preflightResult?.(!0), await this._runAgentPrompt(messages);
1678
+ }
1679
+ /**
1680
+ * Admit one scheduled request, including steering, retries and compaction.
1681
+ * Completes before later follow-ups; signal cancellation belongs only to this request.
1682
+ */
1683
+ async promptWithCompletion(text, options) {
1684
+ if (this.assertCanStartWork(), !this.isIdle || this.isBashRunning || this.isCompacting || this.pendingMessageCount > 0)
1685
+ throw new Error("Session is busy. Retry the scheduled prompt after its work settles.");
1686
+ text.startsWith("/") && (options?.expandPromptTemplates ?? !0) && this._throwIfExtensionCommand(text), options?.signal?.throwIfAborted();
1687
+ let messages = [];
1688
+ return new Promise((resolve3, reject) => {
1689
+ let completion = {
1690
+ messages,
1691
+ signal: options?.signal,
1692
+ settle: () => {
1693
+ completion.cancelled ? reject(completion.signal?.reason) : resolve3({ messages });
1694
+ }
1695
+ };
1696
+ this._trackOperation(() => this._prompt(text, options, completion)).then(completion.settle, reject);
1697
+ });
1460
1698
  }
1461
1699
  async _preparePromptInput(text, options, streamingBehavior) {
1462
1700
  let expandPromptTemplates = options?.expandPromptTemplates ?? !0;
@@ -1503,7 +1741,8 @@ ${this._systemPromptAppend}` : prompt;
1503
1741
  return result?.systemPrompt !== void 0 ? (this._systemPromptOverride = result.systemPrompt, this.agent.state.systemPrompt = this._withSystemPromptAppend(result.systemPrompt)) : (this._systemPromptOverride = void 0, this.agent.state.systemPrompt = this._withSystemPromptAppend(this._baseSystemPrompt)), messages;
1504
1742
  }
1505
1743
  async interruptSubagentWaitWithPrompt(text, options) {
1506
- let acceptance = this._waitPromptAcceptance.then(() => this._reserveWaitPrompt(text, options));
1744
+ this.assertCanStartWork();
1745
+ let previousAcceptance = this._waitPromptAcceptance, acceptance = this._trackOperation(() => previousAcceptance.then(() => this._reserveWaitPrompt(text, options)));
1507
1746
  return this._waitPromptAcceptance = acceptance.then(() => {
1508
1747
  }, () => {
1509
1748
  }), acceptance;
@@ -1528,6 +1767,8 @@ ${this._systemPromptAppend}` : prompt;
1528
1767
  } catch (error) {
1529
1768
  throw handoff.reservations.length === 0 && this._waitPromptHandoff === handoff && (this._waitPromptHandoff = void 0), error;
1530
1769
  }
1770
+ if (this.assertCanStartWork(), handoff.generation !== this._waitPromptGeneration)
1771
+ throw new Error("Pending prompt was cancelled during preparation.");
1531
1772
  if (!prepared)
1532
1773
  return handoff.reservations.length === 0 && this._waitPromptHandoff === handoff && (this._waitPromptHandoff = void 0), { completion: Promise.resolve() };
1533
1774
  let resolveCompletion = () => {
@@ -1539,15 +1780,15 @@ ${this._systemPromptAppend}` : prompt;
1539
1780
  }
1540
1781
  async _drainWaitPromptHandoff(handoff) {
1541
1782
  for (await this.waitForIdle(); this._waitPromptHandoff === handoff && handoff.generation === this._waitPromptGeneration && handoff.reservations.length > 0; ) {
1542
- let reservation = handoff.reservations[0];
1783
+ let reservation = handoff.reservations[0], run;
1543
1784
  try {
1544
- this.assertCanStartWork();
1785
+ this.assertCanStartWork(), run = this._reservePromptRun();
1545
1786
  let messages = await this._createPromptMessages(reservation.input);
1546
- handoff.accepting = !1, await this._runAgentPrompt(messages), reservation.resolve();
1787
+ handoff.accepting = !1, await this._runAgentPrompt(messages, run), reservation.resolve();
1547
1788
  } catch (error) {
1548
1789
  reservation.reject(error);
1549
1790
  } finally {
1550
- handoff.reservations[0] === reservation && handoff.reservations.shift();
1791
+ run && await this._releasePromptRun(run), handoff.reservations[0] === reservation && handoff.reservations.shift();
1551
1792
  }
1552
1793
  }
1553
1794
  handoff.accepting = !1, this._waitPromptHandoff === handoff && (this._waitPromptHandoff = void 0);
@@ -1734,7 +1975,9 @@ ${args}` : skillBlock;
1734
1975
  * Abort current operation and wait for agent to become idle.
1735
1976
  */
1736
1977
  async abort() {
1737
- this._invalidateWaitPromptHandoffs("The active run was aborted before the pending prompt could run."), this.abortRetry(), this.agent.abort(), await this.waitForIdle();
1978
+ this._invalidateWaitPromptHandoffs("The active run was aborted before the pending prompt could run."), this.abortRetry(), this._activePromptRun && !this.agent.signal && (this._activePromptRun.gracefulStopRequested = !0);
1979
+ let bash = [...this._bashOperations.values()];
1980
+ this.abortBash(), this.agent.abort(), await this.waitForIdle(), await Promise.all(bash);
1738
1981
  }
1739
1982
  async waitForIdle() {
1740
1983
  this.isIdle || await this._getIdleWaitPromise();
@@ -1896,12 +2139,13 @@ ${args}` : skillBlock;
1896
2139
  * @param customInstructions Optional instructions for the compaction summary
1897
2140
  */
1898
2141
  async compact(customInstructions) {
2142
+ this.assertCanStartWork();
1899
2143
  let existing = this._latestCompactionResult();
1900
2144
  if (existing)
1901
2145
  return existing;
1902
2146
  if (this._manualCompactionPromise)
1903
2147
  return this._manualCompactionPromise;
1904
- let promise = this._compact(customInstructions);
2148
+ let promise = this._trackOperation(() => this._compact(customInstructions));
1905
2149
  this._manualCompactionPromise = promise;
1906
2150
  try {
1907
2151
  return await promise;
@@ -1910,13 +2154,13 @@ ${args}` : skillBlock;
1910
2154
  }
1911
2155
  }
1912
2156
  async _compact(customInstructions) {
1913
- this._disconnectFromAgent(), await this.abort();
2157
+ await this.abort(), this.assertCanStartWork();
1914
2158
  let existing = this._latestCompactionResult();
1915
2159
  if (existing)
1916
- return this._reconnectToAgent(), existing;
1917
- this._compactionAbortController = new AbortController(), this._emit({ type: "compaction_start", reason: "manual" });
2160
+ return existing;
2161
+ this._disconnectFromAgent(), this._compactionAbortController = new AbortController();
1918
2162
  try {
1919
- if (!this.model)
2163
+ if (this._emit({ type: "compaction_start", reason: "manual" }), !this.model)
1920
2164
  throw new Error(formatNoModelSelectedMessage());
1921
2165
  let { apiKey, headers, env } = await this._getSummarizationRequestAuth(this.model), pathEntries = this.sessionManager.getBranch(), settings = this.settingsManager.getCompactionSettings(), preparation = prepareCompaction(pathEntries, settings);
1922
2166
  if (!preparation)
@@ -1940,7 +2184,7 @@ ${args}` : skillBlock;
1940
2184
  if (extensionCompaction)
1941
2185
  summary = extensionCompaction.summary, firstKeptEntryId = extensionCompaction.firstKeptEntryId, tokensBefore = extensionCompaction.tokensBefore, details = extensionCompaction.details;
1942
2186
  else {
1943
- let result = await compact(preparation, this.model, apiKey, headers, customInstructions, this._compactionAbortController.signal, this.thinkingLevel, this.agent.streamFn, env);
2187
+ let result = await compact(preparation, this.model, apiKey, headers, customInstructions, this._compactionAbortController.signal, this.thinkingLevel, this.agent.streamFn, env, (response) => this.sessionManager.appendRequestUsage("compaction", response));
1944
2188
  summary = result.summary, firstKeptEntryId = result.firstKeptEntryId, tokensBefore = result.tokensBefore, details = result.details;
1945
2189
  }
1946
2190
  if (this._compactionAbortController.signal.aborted)
@@ -2089,7 +2333,7 @@ ${args}` : skillBlock;
2089
2333
  if (extensionCompaction)
2090
2334
  summary = extensionCompaction.summary, firstKeptEntryId = extensionCompaction.firstKeptEntryId, tokensBefore = extensionCompaction.tokensBefore, details = extensionCompaction.details;
2091
2335
  else {
2092
- let compactResult = await compact(preparation, this.model, apiKey, headers, void 0, this._autoCompactionAbortController.signal, this.thinkingLevel, this.agent.streamFn, env);
2336
+ let compactResult = await compact(preparation, this.model, apiKey, headers, void 0, this._autoCompactionAbortController.signal, this.thinkingLevel, this.agent.streamFn, env, (response) => this.sessionManager.appendRequestUsage("compaction", response));
2093
2337
  summary = compactResult.summary, firstKeptEntryId = compactResult.firstKeptEntryId, tokensBefore = compactResult.tokensBefore, details = compactResult.details;
2094
2338
  }
2095
2339
  if (this._autoCompactionAbortController.signal.aborted)
@@ -2122,7 +2366,7 @@ ${args}` : skillBlock;
2122
2366
  let messages = this.agent.state.messages, lastMsg = messages[messages.length - 1];
2123
2367
  return lastMsg?.role === "assistant" && lastMsg.stopReason === "error" && (this.agent.state.messages = messages.slice(0, -1)), !0;
2124
2368
  }
2125
- return this.agent.hasQueuedMessages();
2369
+ return !this._activePromptRun?.completion && this.agent.hasQueuedMessages();
2126
2370
  } catch (error) {
2127
2371
  let errorMessage = error instanceof Error ? error.message : "compaction failed";
2128
2372
  return started && this._emit({
@@ -2303,6 +2547,7 @@ ${args}` : skillBlock;
2303
2547
  }, {
2304
2548
  getModel: () => this.resolvedCatalogModel(),
2305
2549
  isIdle: () => this.isIdle,
2550
+ promptWithCompletion: (text, options) => this.promptWithCompletion(text, options),
2306
2551
  isProjectTrusted: () => this.settingsManager.isProjectTrusted(),
2307
2552
  getSignal: () => this.agent.signal,
2308
2553
  abort: () => {
@@ -2476,16 +2721,13 @@ ${args}` : skillBlock;
2476
2721
  * false when rotation is impossible, leaving the error as the final message.
2477
2722
  */
2478
2723
  async _tryRotateSubscriptionKey(message) {
2479
- let model = this.model;
2480
- if (!model)
2724
+ let requestKey = this._modelRuntime.getRequestSubscriptionKey(message);
2725
+ if (!requestKey)
2481
2726
  return !1;
2482
- let providerId = model.provider;
2727
+ let providerId = requestKey.providerId;
2483
2728
  if (this._modelRuntime.hasRuntimeApiKey(providerId))
2484
2729
  return !1;
2485
- let manager = this._modelRuntime.subscriptionManager;
2486
- if ((await manager.list(providerId)).length < 2)
2487
- return !1;
2488
- let errorMessage = message.errorMessage ?? "Unknown error", entry = await manager.rotateOnFailure(providerId, errorMessage);
2730
+ let manager = this._modelRuntime.subscriptionManager, errorMessage = message.errorMessage ?? "Unknown error", entry = await manager.rotateOnFailure(providerId, errorMessage, requestKey.fingerprint);
2489
2731
  if (!entry)
2490
2732
  return !1;
2491
2733
  this._retryAttempt > 0 && this._emit({ type: "auto_retry_end", success: !0, attempt: this._retryAttempt }), this._retryAttempt = 0;
@@ -2523,17 +2765,21 @@ ${args}` : skillBlock;
2523
2765
  * @param options.operations Custom BashOperations for remote execution
2524
2766
  */
2525
2767
  async executeBash(command, onChunk, options) {
2526
- this.assertCanStartWork(), this._bashAbortController = new AbortController();
2527
- let prefix = this.settingsManager.getShellCommandPrefix(), shellPath = this.settingsManager.getShellPath(), resolvedCommand = prefix ? `${prefix}
2528
- ${command}` : command;
2768
+ this.assertCanStartWork();
2769
+ let controller = new AbortController(), settle = () => {
2770
+ }, completion = new Promise((resolve3) => {
2771
+ settle = resolve3;
2772
+ });
2773
+ this._bashOperations.set(controller, completion), this._operations.add(completion);
2529
2774
  try {
2530
- let result = await executeBashWithOperations(resolvedCommand, this.sessionManager.getCwd(), options?.operations ?? createLocalBashOperations({ shellPath, sessionId: this.sessionId }), {
2775
+ let prefix = this.settingsManager.getShellCommandPrefix(), shellPath = this.settingsManager.getShellPath(), resolvedCommand = prefix ? `${prefix}
2776
+ ${command}` : command, result = await executeBashWithOperations(resolvedCommand, this.sessionManager.getCwd(), options?.operations ?? createLocalBashOperations({ shellPath, sessionId: this.sessionId }), {
2531
2777
  onChunk,
2532
- signal: this._bashAbortController.signal
2778
+ signal: controller.signal
2533
2779
  });
2534
2780
  return this.recordBashResult(command, result, options), result;
2535
2781
  } finally {
2536
- this._bashAbortController = void 0;
2782
+ this._bashOperations.delete(controller), this._operations.delete(completion), settle();
2537
2783
  }
2538
2784
  }
2539
2785
  /**
@@ -2555,14 +2801,15 @@ ${command}` : command;
2555
2801
  this.isStreaming ? this._pendingBashMessages.push(bashMessage) : (this.agent.state.messages.push(bashMessage), this.sessionManager.appendMessage(bashMessage));
2556
2802
  }
2557
2803
  /**
2558
- * Cancel running bash command.
2804
+ * Cancel every running direct bash operation.
2559
2805
  */
2560
2806
  abortBash() {
2561
- this._bashAbortController?.abort();
2807
+ for (let controller of this._bashOperations.keys())
2808
+ controller.abort();
2562
2809
  }
2563
2810
  /** Whether a bash command is currently running */
2564
2811
  get isBashRunning() {
2565
- return this._bashAbortController !== void 0;
2812
+ return this._bashOperations.size > 0;
2566
2813
  }
2567
2814
  /** Whether there are pending bash messages waiting to be flushed */
2568
2815
  get hasPendingBashMessages() {
@@ -2605,6 +2852,11 @@ ${command}` : command;
2605
2852
  * @returns Result with editorText (if user message) and cancelled status
2606
2853
  */
2607
2854
  async navigateTree(targetId, options = {}) {
2855
+ if (this.assertCanStartWork(), this._branchSummaryAbortController)
2856
+ throw new Error("Tree navigation is already in progress.");
2857
+ return this._trackOperation(() => this._navigateTree(targetId, options));
2858
+ }
2859
+ async _navigateTree(targetId, options = {}) {
2608
2860
  let oldLeafId = this.sessionManager.getLeafId();
2609
2861
  if (targetId === oldLeafId)
2610
2862
  return { cancelled: !1 };
@@ -2647,7 +2899,8 @@ ${command}` : command;
2647
2899
  customInstructions,
2648
2900
  replaceInstructions,
2649
2901
  reserveTokens: branchSummarySettings.reserveTokens,
2650
- streamFn: this.agent.streamFn
2902
+ streamFn: this.agent.streamFn,
2903
+ onUsage: (response) => this.sessionManager.appendRequestUsage("branch-summary", response)
2651
2904
  });
2652
2905
  if (result.aborted)
2653
2906
  return { cancelled: !0, aborted: !0 };
@@ -2658,6 +2911,8 @@ ${command}` : command;
2658
2911
  modifiedFiles: result.modifiedFiles || []
2659
2912
  };
2660
2913
  } else extensionSummary && (summaryText = extensionSummary.summary, summaryDetails = extensionSummary.details);
2914
+ if (this._branchSummaryAbortController.signal.aborted)
2915
+ return { cancelled: !0, aborted: !0 };
2661
2916
  let newLeafId, editorText, editorImages;
2662
2917
  targetEntry.type === "message" && targetEntry.message.role === "user" ? (newLeafId = targetEntry.parentId, editorText = this._extractUserMessageText(targetEntry.message.content), editorImages = this._extractUserMessageImages(targetEntry.message.content)) : targetEntry.type === "custom_message" ? (newLeafId = targetEntry.parentId, editorText = typeof targetEntry.content == "string" ? targetEntry.content : targetEntry.content.filter((c) => c.type === "text").map((c) => c.text).join("")) : newLeafId = targetId;
2663
2918
  let summaryEntry;
@@ -2703,10 +2958,12 @@ ${command}` : command;
2703
2958
  /**
2704
2959
  * Get session statistics. Aggregates over ALL session entries (including
2705
2960
  * history that was compacted away), so token/cost totals reflect what was
2706
- * actually billed across the session.
2961
+ * reported or estimated across requests incurred in this session.
2707
2962
  */
2708
2963
  getSessionStats() {
2709
- let userMessages = 0, assistantMessages = 0, toolResults = 0, totalMessages = 0, toolCalls = 0, totalInput = 0, totalOutput = 0, totalCacheRead = 0, totalCacheWrite = 0, totalCost = 0;
2964
+ let userMessages = 0, assistantMessages = 0, toolResults = 0, totalMessages = 0, toolCalls = 0, entries = this.sessionManager.getEntries(), parentUsage = totalRequestUsage(collectUsageRequests(entries)), childUsage = totalChildUsage(collectChildUsage(entries)), combinedUsage = { ...parentUsage };
2965
+ for (let key of Object.keys(combinedUsage))
2966
+ combinedUsage[key] += childUsage[key];
2710
2967
  for (let entry of this.sessionManager.getEntries()) {
2711
2968
  if (entry.type !== "message")
2712
2969
  continue;
@@ -2720,8 +2977,6 @@ ${command}` : command;
2720
2977
  assistantMessages++;
2721
2978
  let assistantMsg = message;
2722
2979
  Array.isArray(assistantMsg.content) && (toolCalls += assistantMsg.content.filter((c) => c.type === "toolCall").length);
2723
- let usage = assistantMsg.usage;
2724
- totalInput += usage.input, totalOutput += usage.output, totalCacheRead += usage.cacheRead, totalCacheWrite += usage.cacheWrite, totalCost += usage.cost.total;
2725
2980
  }
2726
2981
  }
2727
2982
  return {
@@ -2733,13 +2988,16 @@ ${command}` : command;
2733
2988
  toolResults,
2734
2989
  totalMessages,
2735
2990
  tokens: {
2736
- input: totalInput,
2737
- output: totalOutput,
2738
- cacheRead: totalCacheRead,
2739
- cacheWrite: totalCacheWrite,
2740
- total: totalInput + totalOutput + totalCacheRead + totalCacheWrite
2991
+ input: parentUsage.input,
2992
+ output: parentUsage.output,
2993
+ cacheRead: parentUsage.cacheRead,
2994
+ cacheWrite: parentUsage.cacheWrite,
2995
+ total: parentUsage.total
2741
2996
  },
2742
- cost: totalCost,
2997
+ cost: parentUsage.cost,
2998
+ parentUsage,
2999
+ childUsage,
3000
+ combinedUsage,
2743
3001
  contextUsage: this.getContextUsage()
2744
3002
  };
2745
3003
  }
@@ -2750,27 +3008,16 @@ ${command}` : command;
2750
3008
  let contextWindow = model.contextWindow ?? 0;
2751
3009
  if (contextWindow <= 0)
2752
3010
  return;
2753
- let branchEntries = this.sessionManager.getBranch(), latestCompaction = getLatestCompactionEntry(branchEntries);
2754
- if (latestCompaction) {
2755
- let compactionIndex = branchEntries.lastIndexOf(latestCompaction), hasPostCompactionUsage = !1;
2756
- for (let i = branchEntries.length - 1; i > compactionIndex; i--) {
2757
- let entry = branchEntries[i];
2758
- if (entry.type === "message" && entry.message.role === "assistant") {
2759
- let assistant = entry.message;
2760
- if (assistant.stopReason !== "aborted" && assistant.stopReason !== "error" && calculateContextTokens(assistant.usage) > 0) {
2761
- hasPostCompactionUsage = !0;
2762
- break;
2763
- }
2764
- }
2765
- }
2766
- if (!hasPostCompactionUsage)
2767
- return { tokens: null, contextWindow, percent: null };
2768
- }
2769
- let estimate = estimateContextTokens(this.messages), percent = estimate.tokens / contextWindow * 100;
3011
+ let estimate = estimateRequestContextTokens({
3012
+ systemPrompt: this.systemPrompt,
3013
+ tools: this.agent.state.tools,
3014
+ messages: convertToLlm(this.messages)
3015
+ }), percent = estimate.tokens / contextWindow * 100;
2770
3016
  return {
2771
3017
  tokens: estimate.tokens,
2772
3018
  contextWindow,
2773
- percent
3019
+ percent,
3020
+ estimated: estimate.lastUsageIndex === null || estimate.trailingTokens > 0
2774
3021
  };
2775
3022
  }
2776
3023
  /**
@@ -2780,7 +3027,7 @@ ${command}` : command;
2780
3027
  */
2781
3028
  async exportToHtml(outputPath) {
2782
3029
  let [{ exportSessionToHtml }, { createToolHtmlRenderer }] = await Promise.all([
2783
- import("./export-html-VM4J2MNR.js"),
3030
+ import("./export-html-DBQRRMAY.js"),
2784
3031
  import("./tool-renderer-MV5O452K.js")
2785
3032
  ]), configuredThemeName = this.settingsManager.getTheme(), themeName = configuredThemeName && getThemeByName(configuredThemeName) ? configuredThemeName : void 0, toolRenderer = createToolHtmlRenderer({
2786
3033
  getToolDefinition: (name) => this.getToolDefinition(name),
@@ -2946,13 +3193,36 @@ var AgentSessionRuntime = class {
2946
3193
  _modelFallbackMessage;
2947
3194
  detached = !1;
2948
3195
  transferring = !1;
3196
+ replacement;
3197
+ teardown;
3198
+ closing = !1;
3199
+ async withReplacement(operation) {
3200
+ if (this.closing || this.replacement || this.transferring)
3201
+ throw new Error("Session lifecycle change is already in progress.");
3202
+ let promise = Promise.resolve().then(operation);
3203
+ this.replacement = promise;
3204
+ try {
3205
+ return await promise;
3206
+ } finally {
3207
+ this.replacement === promise && (this.replacement = void 0);
3208
+ }
3209
+ }
2949
3210
  get isDetached() {
2950
3211
  return this.detached;
2951
3212
  }
3213
+ /** Correlated prompt entry for scheduled hosts; never queues across a lifecycle change. */
3214
+ promptWithCompletion(text, options) {
3215
+ return this.detached || this.closing || this.replacement || this.transferring ? Promise.reject(new Error("Session lifecycle change is in progress. Retry the scheduled prompt later.")) : this.session.promptWithCompletion(text, options);
3216
+ }
2952
3217
  async releaseForTransfer(options = {}) {
3218
+ if (this.closing || this.replacement || this.transferring)
3219
+ throw new SessionTransferError("Session transfer is already in progress.", "busy");
3220
+ return this.withReplacement(() => this.releaseForTransferOwned(options));
3221
+ }
3222
+ async releaseForTransferOwned(options) {
2953
3223
  if (options.signal?.throwIfAborted(), this.detached)
2954
3224
  return;
2955
- if (this.transferring)
3225
+ if (this.closing || this.transferring)
2956
3226
  throw new SessionTransferError("Session transfer is already in progress.", "busy");
2957
3227
  this.transferring = !0, this.session.setTransferring(!0);
2958
3228
  let hasAttachedWork = () => getSubagentCancellation(this.session.sessionId)?.hasActiveRuns() || getSubagentCancellation(this.session.sessionFile ?? "")?.hasActiveRuns() || list().some((entry) => entry.status !== "exited" && (!entry.sessionId || entry.sessionId === this.session.sessionId)), busy = () => this.session.isStreaming || this.session.isCompacting || this.session.isBashRunning || this.session.isRetrying || this.session.pendingMessageCount > 0;
@@ -3023,12 +3293,28 @@ var AgentSessionRuntime = class {
3023
3293
  ...options
3024
3294
  }))?.cancel === !0 } : { cancelled: !1 };
3025
3295
  }
3026
- async teardownCurrent(reason, targetSessionFile) {
3027
- this.detached || (await emitSessionShutdownEvent(this.session.extensionRunner, {
3028
- type: "session_shutdown",
3029
- reason,
3030
- targetSessionFile
3031
- }), this.beforeSessionInvalidate?.(reason), this.session.dispose(), this.detached = !0);
3296
+ teardownCurrent(reason, targetSessionFile) {
3297
+ if (this.teardown)
3298
+ return this.teardown;
3299
+ if (this.detached)
3300
+ return Promise.resolve();
3301
+ let session = this.session;
3302
+ return session.stopAdmission(), this.teardown = (async () => {
3303
+ await session.drain();
3304
+ try {
3305
+ await emitSessionShutdownEvent(session.extensionRunner, {
3306
+ type: "session_shutdown",
3307
+ reason,
3308
+ targetSessionFile
3309
+ });
3310
+ } finally {
3311
+ try {
3312
+ this.beforeSessionInvalidate?.(reason);
3313
+ } finally {
3314
+ await session.shutdown(), this.detached = !0;
3315
+ }
3316
+ }
3317
+ })(), this.teardown;
3032
3318
  }
3033
3319
  async teardownForReplacement(reason, sessionManager) {
3034
3320
  try {
@@ -3038,12 +3324,15 @@ var AgentSessionRuntime = class {
3038
3324
  }
3039
3325
  }
3040
3326
  apply(result) {
3041
- this.detached = !1, this._session = result.session, this._services = result.services, this._diagnostics = result.diagnostics, this._modelFallbackMessage = result.modelFallbackMessage, this.onRuntimeApplied?.(result);
3327
+ this.detached = !1, this.teardown = void 0, this._session = result.session, this.closing && this._session.stopAdmission(), this._services = result.services, this._diagnostics = result.diagnostics, this._modelFallbackMessage = result.modelFallbackMessage, this.onRuntimeApplied?.(result);
3042
3328
  }
3043
3329
  async finishSessionReplacement(withSession) {
3044
3330
  this.rebindSession && await this.rebindSession(this.session), withSession && await withSession(this.session.createReplacedSessionContext());
3045
3331
  }
3046
3332
  async switchSession(sessionPath, options) {
3333
+ return this.withReplacement(() => this.switchSessionOwned(sessionPath, options));
3334
+ }
3335
+ async switchSessionOwned(sessionPath, options) {
3047
3336
  if (!this.detached && this.session.sessionFile && canonicalSessionPath(sessionPath) === canonicalSessionPath(this.session.sessionFile))
3048
3337
  return { cancelled: !1 };
3049
3338
  let beforeResult = this.detached ? { cancelled: !1 } : await this.emitBeforeSwitch("resume", sessionPath);
@@ -3064,6 +3353,9 @@ var AgentSessionRuntime = class {
3064
3353
  })), await this.finishSessionReplacement(options?.withSession), { cancelled: !1 };
3065
3354
  }
3066
3355
  async newSession(options) {
3356
+ return this.withReplacement(() => this.newSessionOwned(options));
3357
+ }
3358
+ async newSessionOwned(options) {
3067
3359
  let beforeResult = await this.emitBeforeSwitch("new");
3068
3360
  if (beforeResult.cancelled)
3069
3361
  return beforeResult;
@@ -3076,6 +3368,9 @@ var AgentSessionRuntime = class {
3076
3368
  })), options?.setup && (await options.setup(this.session.sessionManager), this.session.agent.state.messages = this.session.sessionManager.buildSessionContext().messages), await this.finishSessionReplacement(options?.withSession), { cancelled: !1 };
3077
3369
  }
3078
3370
  async fork(entryId, options) {
3371
+ return this.withReplacement(() => this.forkOwned(entryId, options));
3372
+ }
3373
+ async forkOwned(entryId, options) {
3079
3374
  let position = options?.position ?? "before";
3080
3375
  if ((await this.emitBeforeFork(entryId, { position })).cancelled)
3081
3376
  return { cancelled: !0 };
@@ -3132,6 +3427,9 @@ var AgentSessionRuntime = class {
3132
3427
  * @throws {MissingSessionCwdError} When the imported session cwd cannot be resolved and no override is provided.
3133
3428
  */
3134
3429
  async importFromJsonl(inputPath, cwdOverride) {
3430
+ return this.withReplacement(() => this.importFromJsonlOwned(inputPath, cwdOverride));
3431
+ }
3432
+ async importFromJsonlOwned(inputPath, cwdOverride) {
3135
3433
  let resolvedPath = resolvePath(inputPath);
3136
3434
  if (!existsSync4(resolvedPath))
3137
3435
  throw new SessionImportFileNotFoundError(resolvedPath);
@@ -3163,7 +3461,8 @@ var AgentSessionRuntime = class {
3163
3461
  })), await this.finishSessionReplacement(), { cancelled: !1 };
3164
3462
  }
3165
3463
  async dispose() {
3166
- await this.teardownCurrent("quit");
3464
+ this.closing = !0, this.session.stopAdmission(), this.replacement && await this.replacement.catch(() => {
3465
+ }), await this.teardownCurrent("quit");
3167
3466
  }
3168
3467
  };
3169
3468
  async function createAgentSessionRuntime(createRuntime, options) {
@@ -3285,7 +3584,8 @@ async function createOwnedAgentSession(options) {
3285
3584
  allowedToolNames,
3286
3585
  excludedToolNames,
3287
3586
  extensionRunnerRef,
3288
- sessionStartEvent: options.sessionStartEvent
3587
+ sessionStartEvent: options.sessionStartEvent,
3588
+ permissionMode: options.permissionMode
3289
3589
  }), extensionsResult = resourceLoader.getExtensions();
3290
3590
  return {
3291
3591
  session,
@@ -3377,7 +3677,8 @@ async function createAgentSessionFromServices(options) {
3377
3677
  excludeTools: options.excludeTools,
3378
3678
  noTools: options.noTools,
3379
3679
  customTools: options.customTools,
3380
- sessionStartEvent: options.sessionStartEvent
3680
+ sessionStartEvent: options.sessionStartEvent,
3681
+ permissionMode: options.permissionMode
3381
3682
  });
3382
3683
  }
3383
3684
 
@@ -3394,7 +3695,10 @@ export {
3394
3695
  disableRollbackForSession,
3395
3696
  beginTurn,
3396
3697
  captureTreeChanges,
3698
+ getRollbackTargetUserId,
3699
+ getRollbackRecoveryBlockReason,
3397
3700
  peekRollbackTurnsConsumed,
3701
+ commitRollbackTurn,
3398
3702
  rollbackLastTurn,
3399
3703
  migrateRollbackSession,
3400
3704
  clearRollback,