@strands-agents/cli 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (453) hide show
  1. package/README.md +217 -133
  2. package/bin/strands.js +1 -5
  3. package/dist/src/{tui/strands-backend.js → agent/backend.js} +90 -28
  4. package/dist/src/agent/backend.js.map +1 -0
  5. package/dist/src/{tui/background/activity.js → agent/background.js} +173 -6
  6. package/dist/src/agent/background.js.map +1 -0
  7. package/dist/src/{tui/agent-configuration.js → agent/configuration.js} +62 -105
  8. package/dist/src/agent/configuration.js.map +1 -0
  9. package/dist/src/agent/context.js +112 -0
  10. package/dist/src/agent/context.js.map +1 -0
  11. package/dist/src/{tui/chat/sdk-projector.js → agent/events.js} +6 -5
  12. package/dist/src/agent/events.js.map +1 -0
  13. package/dist/src/{tui/permissions/file-change-preview.js → agent/file-changes.js} +10 -8
  14. package/dist/src/agent/file-changes.js.map +1 -0
  15. package/dist/src/agent/mcp.js +436 -0
  16. package/dist/src/agent/mcp.js.map +1 -0
  17. package/dist/src/agent/messaging.js +424 -0
  18. package/dist/src/agent/messaging.js.map +1 -0
  19. package/dist/src/agent/permission-rules.js +267 -0
  20. package/dist/src/agent/permission-rules.js.map +1 -0
  21. package/dist/src/agent/permissions.js +288 -0
  22. package/dist/src/agent/permissions.js.map +1 -0
  23. package/dist/src/agent/runtime.js +524 -0
  24. package/dist/src/agent/runtime.js.map +1 -0
  25. package/dist/src/{tui/workspace → agent}/sandbox.js +92 -25
  26. package/dist/src/agent/sandbox.js.map +1 -0
  27. package/dist/src/{tui/chat → agent}/shell.js +1 -1
  28. package/dist/src/agent/shell.js.map +1 -0
  29. package/dist/src/{tui → agent}/skills.js +37 -56
  30. package/dist/src/agent/skills.js.map +1 -0
  31. package/dist/src/{tui/builtin-tools.js → agent/tools.js} +2 -3
  32. package/dist/src/agent/tools.js.map +1 -0
  33. package/dist/src/agent/types.js.map +1 -0
  34. package/dist/src/{tui/voice/session.js → agent/voice.js} +221 -224
  35. package/dist/src/agent/voice.js.map +1 -0
  36. package/dist/src/{tui/acp/projection.js → cli/acp-events.js} +19 -4
  37. package/dist/src/cli/acp-events.js.map +1 -0
  38. package/dist/src/{tui/project/acp.js → cli/acp-python.js} +41 -18
  39. package/dist/src/cli/acp-python.js.map +1 -0
  40. package/dist/src/{tui/acp/server.js → cli/acp.js} +149 -46
  41. package/dist/src/cli/acp.js.map +1 -0
  42. package/dist/src/cli/arguments.js +8 -3
  43. package/dist/src/cli/arguments.js.map +1 -1
  44. package/dist/src/{console.js → cli/console.js} +69 -4
  45. package/dist/src/cli/console.js.map +1 -0
  46. package/dist/src/cli/invocation.js +75 -44
  47. package/dist/src/cli/invocation.js.map +1 -1
  48. package/dist/src/cli/run.js +66 -38
  49. package/dist/src/cli/run.js.map +1 -1
  50. package/dist/src/{tui → cli}/telemetry.js +2 -2
  51. package/dist/src/{tui → cli}/telemetry.js.map +1 -1
  52. package/dist/src/cli/update.js +35 -7
  53. package/dist/src/cli/update.js.map +1 -1
  54. package/dist/src/{tui/mcp/config.js → config/mcp.js} +25 -35
  55. package/dist/src/config/mcp.js.map +1 -0
  56. package/dist/src/{tui → config}/settings.js +78 -130
  57. package/dist/src/config/settings.js.map +1 -0
  58. package/dist/src/config/source.js +87 -0
  59. package/dist/src/config/source.js.map +1 -0
  60. package/dist/src/{tui/config.js → config/store.js} +178 -49
  61. package/dist/src/config/store.js.map +1 -0
  62. package/dist/src/{tui/workspace → config}/trust.js +12 -16
  63. package/dist/src/config/trust.js.map +1 -0
  64. package/dist/src/logging.js +3 -4
  65. package/dist/src/logging.js.map +1 -1
  66. package/dist/src/{tui/provider → model}/aws-config.js +13 -4
  67. package/dist/src/model/aws-config.js.map +1 -0
  68. package/dist/src/{tui/provider/bedrock-catalog.js → model/bedrock.js} +70 -3
  69. package/dist/src/model/bedrock.js.map +1 -0
  70. package/dist/src/{tui/provider → model}/discovery.js +11 -10
  71. package/dist/src/model/discovery.js.map +1 -0
  72. package/dist/src/{tui/provider → model}/environment.js +19 -16
  73. package/dist/src/model/environment.js.map +1 -0
  74. package/dist/src/{tui/model/display.js → model/metadata.js} +6 -1
  75. package/dist/src/model/metadata.js.map +1 -0
  76. package/dist/src/model/packages.js.map +1 -0
  77. package/dist/src/{tui/model → model}/runtime.js +31 -62
  78. package/dist/src/model/runtime.js.map +1 -0
  79. package/dist/src/{tui/model → model}/selection.js +9 -15
  80. package/dist/src/model/selection.js.map +1 -0
  81. package/dist/src/{tui/package-version.js → package-version.js} +6 -0
  82. package/dist/src/package-version.js.map +1 -0
  83. package/dist/src/paths.js +23 -0
  84. package/dist/src/paths.js.map +1 -0
  85. package/dist/src/project/archive.js +461 -0
  86. package/dist/src/project/archive.js.map +1 -0
  87. package/dist/src/{tui/project → project}/export.js +249 -72
  88. package/dist/src/project/export.js.map +1 -0
  89. package/dist/src/{tui/project → project}/import.js +58 -6
  90. package/dist/src/project/import.js.map +1 -0
  91. package/dist/src/{tui/project → project}/module-loader.js +1 -5
  92. package/dist/src/project/module-loader.js.map +1 -0
  93. package/dist/src/{tui/project → project}/packaging.js +25 -8
  94. package/dist/src/project/packaging.js.map +1 -0
  95. package/dist/src/project/portability.js +455 -0
  96. package/dist/src/project/portability.js.map +1 -0
  97. package/dist/src/{tui/project → project}/python.js +46 -31
  98. package/dist/src/project/python.js.map +1 -0
  99. package/dist/src/{tui/project → project}/source.js +45 -26
  100. package/dist/src/project/source.js.map +1 -0
  101. package/dist/src/project/typescript-backend.js +733 -0
  102. package/dist/src/project/typescript-backend.js.map +1 -0
  103. package/dist/src/project/typescript-worker.js +488 -0
  104. package/dist/src/project/typescript-worker.js.map +1 -0
  105. package/dist/src/{tui/project → project}/typescript.js +19 -7
  106. package/dist/src/project/typescript.js.map +1 -0
  107. package/dist/src/project/watch.js +33 -0
  108. package/dist/src/project/watch.js.map +1 -0
  109. package/dist/src/{tui/project → project}/worker.py +358 -106
  110. package/dist/src/session/agent-definition.js +35 -0
  111. package/dist/src/session/agent-definition.js.map +1 -0
  112. package/dist/src/session/catalog.js +156 -0
  113. package/dist/src/session/catalog.js.map +1 -0
  114. package/dist/src/{tui/session → session}/context.js +45 -5
  115. package/dist/src/session/context.js.map +1 -0
  116. package/dist/src/{tui/session → session}/desktop-profile.js +1 -0
  117. package/dist/src/session/desktop-profile.js.map +1 -0
  118. package/dist/src/{tui/session → session}/sessions.js +126 -27
  119. package/dist/src/session/sessions.js.map +1 -0
  120. package/dist/src/terminal/arguments.js +53 -0
  121. package/dist/src/terminal/arguments.js.map +1 -0
  122. package/dist/src/{tui/terminal → terminal}/composer.js +51 -24
  123. package/dist/src/terminal/composer.js.map +1 -0
  124. package/dist/src/terminal/directory-picker.js +182 -0
  125. package/dist/src/terminal/directory-picker.js.map +1 -0
  126. package/dist/src/terminal/ink.js.map +1 -0
  127. package/dist/src/terminal/mouse-input.js.map +1 -0
  128. package/dist/src/terminal/npm.js.map +1 -0
  129. package/dist/src/terminal/open-editor.js +40 -0
  130. package/dist/src/terminal/open-editor.js.map +1 -0
  131. package/dist/src/terminal/open-url.js +26 -0
  132. package/dist/src/terminal/open-url.js.map +1 -0
  133. package/dist/src/terminal/process-tree.js.map +1 -0
  134. package/dist/src/terminal/shell-output.js.map +1 -0
  135. package/dist/src/{tui/terminal → terminal}/terminal.js +40 -2
  136. package/dist/src/terminal/terminal.js.map +1 -0
  137. package/dist/src/{tui/terminal/sanitize.js → terminal/text.js} +40 -6
  138. package/dist/src/terminal/text.js.map +1 -0
  139. package/dist/src/terminal/theme-detection.js +197 -0
  140. package/dist/src/terminal/theme-detection.js.map +1 -0
  141. package/dist/src/{tui/view/fade-in.js → ui/animation.js} +26 -1
  142. package/dist/src/ui/animation.js.map +1 -0
  143. package/dist/src/ui/app.js +176 -0
  144. package/dist/src/ui/app.js.map +1 -0
  145. package/dist/src/ui/chat/attachments.js +135 -0
  146. package/dist/src/ui/chat/attachments.js.map +1 -0
  147. package/dist/src/{tui → ui}/chat/commands.js +55 -7
  148. package/dist/src/ui/chat/commands.js.map +1 -0
  149. package/dist/src/{tui → ui}/chat/controller.js +1176 -345
  150. package/dist/src/ui/chat/controller.js.map +1 -0
  151. package/dist/src/ui/chat/conversations.js +692 -0
  152. package/dist/src/ui/chat/conversations.js.map +1 -0
  153. package/dist/src/{tui → ui}/chat/help.js +11 -5
  154. package/dist/src/ui/chat/help.js.map +1 -0
  155. package/dist/src/ui/chat/panel-state.js +513 -0
  156. package/dist/src/ui/chat/panel-state.js.map +1 -0
  157. package/dist/src/{tui → ui}/chat/projector.js +93 -8
  158. package/dist/src/ui/chat/projector.js.map +1 -0
  159. package/dist/src/ui/chat/prompt.js +176 -0
  160. package/dist/src/ui/chat/prompt.js.map +1 -0
  161. package/dist/src/ui/chat/runtime.js +589 -0
  162. package/dist/src/ui/chat/runtime.js.map +1 -0
  163. package/dist/src/ui/chat/screen.js +1907 -0
  164. package/dist/src/ui/chat/screen.js.map +1 -0
  165. package/dist/src/{tui/chat/controller-helpers.js → ui/chat/state.js} +39 -3
  166. package/dist/src/ui/chat/state.js.map +1 -0
  167. package/dist/src/ui/chat/stream-presentation.js.map +1 -0
  168. package/dist/src/ui/chat/transcript-turn.js +189 -0
  169. package/dist/src/ui/chat/transcript-turn.js.map +1 -0
  170. package/dist/src/{tui/view → ui/chat}/transcript.js +66 -6
  171. package/dist/src/ui/chat/transcript.js.map +1 -0
  172. package/dist/src/ui/chat/types.js +2 -0
  173. package/dist/src/ui/chat/types.js.map +1 -0
  174. package/dist/src/ui/chat/view.js +249 -0
  175. package/dist/src/ui/chat/view.js.map +1 -0
  176. package/dist/src/ui/chat/voice.js +388 -0
  177. package/dist/src/ui/chat/voice.js.map +1 -0
  178. package/dist/src/ui/footer.js +110 -0
  179. package/dist/src/ui/footer.js.map +1 -0
  180. package/dist/src/{tui/view → ui}/frog-canvas.js +47 -50
  181. package/dist/src/ui/frog-canvas.js.map +1 -0
  182. package/dist/src/{tui/view → ui}/frog-drawing.js +36 -29
  183. package/dist/src/ui/frog-drawing.js.map +1 -0
  184. package/dist/src/{tui/view/frog-intro-renderer.js → ui/frog-renderer.js} +63 -46
  185. package/dist/src/ui/frog-renderer.js.map +1 -0
  186. package/dist/src/{tui/view/frog-easter-egg.js → ui/frog.js} +34 -6
  187. package/dist/src/ui/frog.js.map +1 -0
  188. package/dist/src/ui/interaction.js +525 -0
  189. package/dist/src/ui/interaction.js.map +1 -0
  190. package/dist/src/{tui/view → ui}/markdown.js +12 -9
  191. package/dist/src/ui/markdown.js.map +1 -0
  192. package/dist/src/ui/mcp-diagnostics.js +56 -0
  193. package/dist/src/ui/mcp-diagnostics.js.map +1 -0
  194. package/dist/src/ui/media.js +59 -0
  195. package/dist/src/ui/media.js.map +1 -0
  196. package/dist/src/ui/panels/agents.js +97 -0
  197. package/dist/src/ui/panels/agents.js.map +1 -0
  198. package/dist/src/ui/panels/configuration.js +201 -0
  199. package/dist/src/ui/panels/configuration.js.map +1 -0
  200. package/dist/src/ui/panels/context.js +102 -0
  201. package/dist/src/ui/panels/context.js.map +1 -0
  202. package/dist/src/ui/panels/export.js +17 -0
  203. package/dist/src/ui/panels/export.js.map +1 -0
  204. package/dist/src/ui/panels/help.js +22 -0
  205. package/dist/src/ui/panels/help.js.map +1 -0
  206. package/dist/src/ui/panels/models.js +180 -0
  207. package/dist/src/ui/panels/models.js.map +1 -0
  208. package/dist/src/ui/panels/panel.js +122 -0
  209. package/dist/src/ui/panels/panel.js.map +1 -0
  210. package/dist/src/ui/panels/permissions.js +90 -0
  211. package/dist/src/ui/panels/permissions.js.map +1 -0
  212. package/dist/src/ui/panels/sessions.js +54 -0
  213. package/dist/src/ui/panels/sessions.js.map +1 -0
  214. package/dist/src/ui/panels/settings.js +125 -0
  215. package/dist/src/ui/panels/settings.js.map +1 -0
  216. package/dist/src/ui/panels/shared.js +50 -0
  217. package/dist/src/ui/panels/shared.js.map +1 -0
  218. package/dist/src/ui/panels/tasks.js +15 -0
  219. package/dist/src/ui/panels/tasks.js.map +1 -0
  220. package/dist/src/ui/panels/voice.js +142 -0
  221. package/dist/src/ui/panels/voice.js.map +1 -0
  222. package/dist/src/{tui/permissions/settings.js → ui/permission-options.js} +13 -2
  223. package/dist/src/ui/permission-options.js.map +1 -0
  224. package/dist/src/{tui/view → ui}/presentation.js +170 -112
  225. package/dist/src/ui/presentation.js.map +1 -0
  226. package/dist/src/{tui → ui}/run.js +173 -36
  227. package/dist/src/ui/run.js.map +1 -0
  228. package/dist/src/{tui/view/setup-wizard/settings-panel.js → ui/setup/form.js} +6 -6
  229. package/dist/src/ui/setup/form.js.map +1 -0
  230. package/dist/src/ui/setup/menu.js +133 -0
  231. package/dist/src/ui/setup/menu.js.map +1 -0
  232. package/dist/src/{tui/view/setup-wizard → ui/setup}/providers.js +157 -20
  233. package/dist/src/ui/setup/providers.js.map +1 -0
  234. package/dist/src/{tui/view/setup-wizard → ui/setup}/steps.js +193 -147
  235. package/dist/src/ui/setup/steps.js.map +1 -0
  236. package/dist/src/ui/setup/wizard.js +2075 -0
  237. package/dist/src/ui/setup/wizard.js.map +1 -0
  238. package/dist/src/ui/startup.js +147 -0
  239. package/dist/src/ui/startup.js.map +1 -0
  240. package/dist/src/{tui/terminal/size.js → ui/terminal-size.js} +1 -1
  241. package/dist/src/ui/terminal-size.js.map +1 -0
  242. package/dist/src/ui/text-input.js +50 -0
  243. package/dist/src/ui/text-input.js.map +1 -0
  244. package/dist/src/{tui/view → ui}/theme.js +24 -31
  245. package/dist/src/ui/theme.js.map +1 -0
  246. package/dist/src/ui/update.js +126 -0
  247. package/dist/src/ui/update.js.map +1 -0
  248. package/dist/src/usage.js +0 -5
  249. package/dist/src/usage.js.map +1 -1
  250. package/dist/src/values.js +5 -0
  251. package/dist/src/values.js.map +1 -0
  252. package/package.json +16 -8
  253. package/src/agent/voice-sidecar.py +730 -0
  254. package/dist/src/console.js.map +0 -1
  255. package/dist/src/tui/acp/projection.js.map +0 -1
  256. package/dist/src/tui/acp/server.js.map +0 -1
  257. package/dist/src/tui/agent-configuration.js.map +0 -1
  258. package/dist/src/tui/background/activity.js.map +0 -1
  259. package/dist/src/tui/background/inbox.js +0 -120
  260. package/dist/src/tui/background/inbox.js.map +0 -1
  261. package/dist/src/tui/background/tasks.js +0 -98
  262. package/dist/src/tui/background/tasks.js.map +0 -1
  263. package/dist/src/tui/builtin-tools.js.map +0 -1
  264. package/dist/src/tui/chat/commands.js.map +0 -1
  265. package/dist/src/tui/chat/controller-helpers.js.map +0 -1
  266. package/dist/src/tui/chat/controller.js.map +0 -1
  267. package/dist/src/tui/chat/help.js.map +0 -1
  268. package/dist/src/tui/chat/panels.js +0 -407
  269. package/dist/src/tui/chat/panels.js.map +0 -1
  270. package/dist/src/tui/chat/projector.js.map +0 -1
  271. package/dist/src/tui/chat/sdk-projector.js.map +0 -1
  272. package/dist/src/tui/chat/shell.js.map +0 -1
  273. package/dist/src/tui/chat/types.js +0 -2
  274. package/dist/src/tui/chat/types.js.map +0 -1
  275. package/dist/src/tui/config.js.map +0 -1
  276. package/dist/src/tui/configuration-instructions.js +0 -14
  277. package/dist/src/tui/configuration-instructions.js.map +0 -1
  278. package/dist/src/tui/mcp/config.js.map +0 -1
  279. package/dist/src/tui/mcp.js +0 -98
  280. package/dist/src/tui/mcp.js.map +0 -1
  281. package/dist/src/tui/memory-options.js +0 -10
  282. package/dist/src/tui/memory-options.js.map +0 -1
  283. package/dist/src/tui/messaging.js +0 -193
  284. package/dist/src/tui/messaging.js.map +0 -1
  285. package/dist/src/tui/model/context.js +0 -69
  286. package/dist/src/tui/model/context.js.map +0 -1
  287. package/dist/src/tui/model/display.js.map +0 -1
  288. package/dist/src/tui/model/runtime.js.map +0 -1
  289. package/dist/src/tui/model/selection.js.map +0 -1
  290. package/dist/src/tui/npm.js.map +0 -1
  291. package/dist/src/tui/package-version.js.map +0 -1
  292. package/dist/src/tui/permissions/file-change-preview.js.map +0 -1
  293. package/dist/src/tui/permissions/policy.js +0 -222
  294. package/dist/src/tui/permissions/policy.js.map +0 -1
  295. package/dist/src/tui/permissions/settings.js.map +0 -1
  296. package/dist/src/tui/project/acp.js.map +0 -1
  297. package/dist/src/tui/project/archive.js +0 -241
  298. package/dist/src/tui/project/archive.js.map +0 -1
  299. package/dist/src/tui/project/configuration-secrets.js +0 -107
  300. package/dist/src/tui/project/configuration-secrets.js.map +0 -1
  301. package/dist/src/tui/project/configuration.js +0 -201
  302. package/dist/src/tui/project/configuration.js.map +0 -1
  303. package/dist/src/tui/project/export.js.map +0 -1
  304. package/dist/src/tui/project/import.js.map +0 -1
  305. package/dist/src/tui/project/module-loader.js.map +0 -1
  306. package/dist/src/tui/project/packaging.js.map +0 -1
  307. package/dist/src/tui/project/portable-dependencies.js +0 -34
  308. package/dist/src/tui/project/portable-dependencies.js.map +0 -1
  309. package/dist/src/tui/project/portable-mcp.js +0 -118
  310. package/dist/src/tui/project/portable-mcp.js.map +0 -1
  311. package/dist/src/tui/project/python.js.map +0 -1
  312. package/dist/src/tui/project/run.js +0 -116
  313. package/dist/src/tui/project/run.js.map +0 -1
  314. package/dist/src/tui/project/source.js.map +0 -1
  315. package/dist/src/tui/project/typescript.js.map +0 -1
  316. package/dist/src/tui/provider/aws-client.js +0 -67
  317. package/dist/src/tui/provider/aws-client.js.map +0 -1
  318. package/dist/src/tui/provider/aws-config.js.map +0 -1
  319. package/dist/src/tui/provider/bedrock-catalog.js.map +0 -1
  320. package/dist/src/tui/provider/discovery.js.map +0 -1
  321. package/dist/src/tui/provider/environment.js.map +0 -1
  322. package/dist/src/tui/provider/packages.js.map +0 -1
  323. package/dist/src/tui/run.js.map +0 -1
  324. package/dist/src/tui/runtime.js +0 -524
  325. package/dist/src/tui/runtime.js.map +0 -1
  326. package/dist/src/tui/session/agent-definition.js +0 -100
  327. package/dist/src/tui/session/agent-definition.js.map +0 -1
  328. package/dist/src/tui/session/catalog.js +0 -159
  329. package/dist/src/tui/session/catalog.js.map +0 -1
  330. package/dist/src/tui/session/context.js.map +0 -1
  331. package/dist/src/tui/session/conversation-helpers.js +0 -46
  332. package/dist/src/tui/session/conversation-helpers.js.map +0 -1
  333. package/dist/src/tui/session/conversations.js +0 -471
  334. package/dist/src/tui/session/conversations.js.map +0 -1
  335. package/dist/src/tui/session/desktop-profile.js.map +0 -1
  336. package/dist/src/tui/session/options.js +0 -44
  337. package/dist/src/tui/session/options.js.map +0 -1
  338. package/dist/src/tui/session/sessions.js.map +0 -1
  339. package/dist/src/tui/session/voice.js +0 -353
  340. package/dist/src/tui/session/voice.js.map +0 -1
  341. package/dist/src/tui/settings.js.map +0 -1
  342. package/dist/src/tui/skills.js.map +0 -1
  343. package/dist/src/tui/steering.js +0 -67
  344. package/dist/src/tui/steering.js.map +0 -1
  345. package/dist/src/tui/strands-backend.js.map +0 -1
  346. package/dist/src/tui/stream-presentation.js.map +0 -1
  347. package/dist/src/tui/terminal/composer.js.map +0 -1
  348. package/dist/src/tui/terminal/directory-picker.js +0 -76
  349. package/dist/src/tui/terminal/directory-picker.js.map +0 -1
  350. package/dist/src/tui/terminal/ink.js.map +0 -1
  351. package/dist/src/tui/terminal/mouse-input.js.map +0 -1
  352. package/dist/src/tui/terminal/open-url.js +0 -21
  353. package/dist/src/tui/terminal/open-url.js.map +0 -1
  354. package/dist/src/tui/terminal/process-tree.js.map +0 -1
  355. package/dist/src/tui/terminal/sanitize.js.map +0 -1
  356. package/dist/src/tui/terminal/shell-output.js.map +0 -1
  357. package/dist/src/tui/terminal/size.js.map +0 -1
  358. package/dist/src/tui/terminal/terminal.js.map +0 -1
  359. package/dist/src/tui/update-check.js +0 -37
  360. package/dist/src/tui/update-check.js.map +0 -1
  361. package/dist/src/tui/view/agents-panel.js +0 -21
  362. package/dist/src/tui/view/agents-panel.js.map +0 -1
  363. package/dist/src/tui/view/app.js +0 -1061
  364. package/dist/src/tui/view/app.js.map +0 -1
  365. package/dist/src/tui/view/chat-root.js +0 -49
  366. package/dist/src/tui/view/chat-root.js.map +0 -1
  367. package/dist/src/tui/view/chat-view.js +0 -145
  368. package/dist/src/tui/view/chat-view.js.map +0 -1
  369. package/dist/src/tui/view/command-palette.js +0 -15
  370. package/dist/src/tui/view/command-palette.js.map +0 -1
  371. package/dist/src/tui/view/custom-theme-editor.js +0 -301
  372. package/dist/src/tui/view/custom-theme-editor.js.map +0 -1
  373. package/dist/src/tui/view/effort-panel.js +0 -15
  374. package/dist/src/tui/view/effort-panel.js.map +0 -1
  375. package/dist/src/tui/view/export-panel.js +0 -14
  376. package/dist/src/tui/view/export-panel.js.map +0 -1
  377. package/dist/src/tui/view/fade-in.js.map +0 -1
  378. package/dist/src/tui/view/frog-canvas.js.map +0 -1
  379. package/dist/src/tui/view/frog-drawing.js.map +0 -1
  380. package/dist/src/tui/view/frog-easter-egg.js.map +0 -1
  381. package/dist/src/tui/view/frog-intro-renderer.js.map +0 -1
  382. package/dist/src/tui/view/help-footer.js +0 -48
  383. package/dist/src/tui/view/help-footer.js.map +0 -1
  384. package/dist/src/tui/view/interaction.js +0 -352
  385. package/dist/src/tui/view/interaction.js.map +0 -1
  386. package/dist/src/tui/view/markdown.js.map +0 -1
  387. package/dist/src/tui/view/mcp-trust-prompt.js +0 -17
  388. package/dist/src/tui/view/mcp-trust-prompt.js.map +0 -1
  389. package/dist/src/tui/view/media.js +0 -70
  390. package/dist/src/tui/view/media.js.map +0 -1
  391. package/dist/src/tui/view/model-panel.js +0 -77
  392. package/dist/src/tui/view/model-panel.js.map +0 -1
  393. package/dist/src/tui/view/panel-components.js +0 -17
  394. package/dist/src/tui/view/panel-components.js.map +0 -1
  395. package/dist/src/tui/view/panels.js +0 -139
  396. package/dist/src/tui/view/panels.js.map +0 -1
  397. package/dist/src/tui/view/presentation.js.map +0 -1
  398. package/dist/src/tui/view/prompt-editor.js +0 -82
  399. package/dist/src/tui/view/prompt-editor.js.map +0 -1
  400. package/dist/src/tui/view/provider-list.js +0 -14
  401. package/dist/src/tui/view/provider-list.js.map +0 -1
  402. package/dist/src/tui/view/rename-panel.js +0 -11
  403. package/dist/src/tui/view/rename-panel.js.map +0 -1
  404. package/dist/src/tui/view/sessions-panel.js +0 -15
  405. package/dist/src/tui/view/sessions-panel.js.map +0 -1
  406. package/dist/src/tui/view/settings-panel.js +0 -146
  407. package/dist/src/tui/view/settings-panel.js.map +0 -1
  408. package/dist/src/tui/view/setup-wizard/brand.js +0 -34
  409. package/dist/src/tui/view/setup-wizard/brand.js.map +0 -1
  410. package/dist/src/tui/view/setup-wizard/index.js +0 -1638
  411. package/dist/src/tui/view/setup-wizard/index.js.map +0 -1
  412. package/dist/src/tui/view/setup-wizard/opening-menu.js +0 -99
  413. package/dist/src/tui/view/setup-wizard/opening-menu.js.map +0 -1
  414. package/dist/src/tui/view/setup-wizard/path-completion.js +0 -53
  415. package/dist/src/tui/view/setup-wizard/path-completion.js.map +0 -1
  416. package/dist/src/tui/view/setup-wizard/profile-fields.js +0 -29
  417. package/dist/src/tui/view/setup-wizard/profile-fields.js.map +0 -1
  418. package/dist/src/tui/view/setup-wizard/progress.js +0 -43
  419. package/dist/src/tui/view/setup-wizard/progress.js.map +0 -1
  420. package/dist/src/tui/view/setup-wizard/providers.js.map +0 -1
  421. package/dist/src/tui/view/setup-wizard/settings-panel.js.map +0 -1
  422. package/dist/src/tui/view/setup-wizard/steps.js.map +0 -1
  423. package/dist/src/tui/view/setup-wizard/types.js.map +0 -1
  424. package/dist/src/tui/view/setup-wizard/use-provider-discovery.js +0 -143
  425. package/dist/src/tui/view/setup-wizard/use-provider-discovery.js.map +0 -1
  426. package/dist/src/tui/view/startup-view.js +0 -79
  427. package/dist/src/tui/view/startup-view.js.map +0 -1
  428. package/dist/src/tui/view/text-input.js +0 -33
  429. package/dist/src/tui/view/text-input.js.map +0 -1
  430. package/dist/src/tui/view/theme-detection.js +0 -45
  431. package/dist/src/tui/view/theme-detection.js.map +0 -1
  432. package/dist/src/tui/view/theme.js.map +0 -1
  433. package/dist/src/tui/view/transcript-layout.js +0 -60
  434. package/dist/src/tui/view/transcript-layout.js.map +0 -1
  435. package/dist/src/tui/view/transcript-turn.js +0 -135
  436. package/dist/src/tui/view/transcript-turn.js.map +0 -1
  437. package/dist/src/tui/view/transcript.js.map +0 -1
  438. package/dist/src/tui/view/use-party-frame.js +0 -15
  439. package/dist/src/tui/view/use-party-frame.js.map +0 -1
  440. package/dist/src/tui/view/use-spinner.js +0 -14
  441. package/dist/src/tui/view/use-spinner.js.map +0 -1
  442. package/dist/src/tui/voice/session.js.map +0 -1
  443. package/dist/src/tui/workspace/sandbox.js.map +0 -1
  444. package/dist/src/tui/workspace/trust.js.map +0 -1
  445. package/src/tui/voice/sidecar.py +0 -631
  446. /package/dist/src/{tui/view/setup-wizard → agent}/types.js +0 -0
  447. /package/dist/src/{tui/provider → model}/packages.js +0 -0
  448. /package/dist/src/{tui/terminal → terminal}/ink.js +0 -0
  449. /package/dist/src/{tui/terminal → terminal}/mouse-input.js +0 -0
  450. /package/dist/src/{tui → terminal}/npm.js +0 -0
  451. /package/dist/src/{tui/terminal → terminal}/process-tree.js +0 -0
  452. /package/dist/src/{tui/terminal → terminal}/shell-output.js +0 -0
  453. /package/dist/src/{tui → ui/chat}/stream-presentation.js +0 -0
@@ -1,28 +1,38 @@
1
- import { homedir } from 'node:os';
2
- import { resolve } from 'node:path';
3
- import { clonePanel, effortSlider, permissionRequestRows, formatPermissionPanelBody, formatTaskActivity, modelFilters, taskDetailRows, taskDetailTitle, settingsCategoryFilters, settingsRows, taskRows, sanitizeRows, makePanel, modelRows, sessionRows, skillRows, skillDetailRows, permissionSettingsRows, builtinToolRows, mcpRows, mcpOptions, BACKGROUND_TASK_WAIT_TOGGLE, } from './panels.js';
4
- import { LOCAL_COMMAND_NAMES, parseCommandInvocation } from './commands.js';
1
+ import { join, resolve } from 'node:path';
2
+ import { setImmediate } from 'node:timers';
3
+ import { effortSlider, permissionChoosesScope, permissionRequestRows, formatPermissionPanelBody, formatTaskActivity, modelFilters, taskDetailRows, taskDetailTitle, settingsCategoryFilters, settingsRows, taskRows, sanitizeRows, makePanel, modelRows, sessionFilters, sessionRows, skillRows, skillDetailRows, permissionPreset, permissionSettingsRows, permissionSettingsSlider, builtinToolRows, mcpRows, mcpOptions, SETTINGS_SETUP_ACTION, } from './panel-state.js';
4
+ import { commandAssistance as resolveCommandAssistance, LOCAL_COMMAND_NAMES, parseCommandInvocation, unquote, } from './commands.js';
5
5
  import { helpRows } from './help.js';
6
- import { DEFAULT_CHAT_SETTINGS, DEFAULT_SETTINGS_CATEGORY, SETTINGS_CATEGORIES, parseSettingUpdate, } from '../settings.js';
7
- import { agentLaunchCommand } from '../project/import.js';
8
- import {} from '../session/sessions.js';
9
- import { unquote } from '../session/conversation-helpers.js';
10
- import {} from '../messaging.js';
11
- import { modelDisplayName } from '../model/display.js';
12
- import { modelControlErrorMessage } from '../model/selection.js';
13
- import { presentChatStream } from '../stream-presentation.js';
14
- import { errorMessage, sanitizeTerminalText } from '../terminal/sanitize.js';
15
- import { canChooseDirectory } from '../terminal/directory-picker.js';
16
- import { copyTerminalText } from '../terminal/terminal.js';
17
- import { cloneRuntime, cloneTask, isUnresolvedBackgroundTask, readTaskValue, readyBackgroundGeneration, } from './controller-helpers.js';
6
+ import { DEFAULT_CHAT_SETTINGS, DEFAULT_SETTINGS_CATEGORY, SETTINGS_CATEGORIES, parseSettingUpdate, } from '../../config/settings.js';
7
+ import { agentLaunchCommand } from '../../project/import.js';
8
+ import { exportDirectoryName } from '../../project/export.js';
9
+ import { sessionResumeCommand, } from '../../session/sessions.js';
10
+ import { mcpFailure } from '../mcp-diagnostics.js';
11
+ import { peerMessagePrompt } from '../../agent/messaging.js';
12
+ import { modelDisplayName } from '../../model/metadata.js';
13
+ import { modelControlErrorMessage } from '../../model/selection.js';
14
+ import { presentChatStream } from './stream-presentation.js';
15
+ import { errorMessage, sanitizeTerminalText } from '../../terminal/text.js';
16
+ import { canUseNativePicker, chooseDirectory } from '../../terminal/directory-picker.js';
17
+ import { copyTerminalText } from '../../terminal/terminal.js';
18
+ import { expandHome, strandsUserPath } from '../../paths.js';
19
+ import { attachmentContent } from './attachments.js';
20
+ import { configurationDiffs, sanitizeConfigurationSource } from '../../config/source.js';
21
+ import { cloneRuntime, cloneTask, isConfigurationTool, isUnresolvedBackgroundTask, readTaskValue, readyBackgroundGeneration, } from './state.js';
18
22
  import { TurnProjector, projectMessages } from './projector.js';
23
+ import {} from '../../agent/types.js';
19
24
  import {} from './types.js';
20
25
  export * from './types.js';
21
- const EXIT_WORDS = new Set(['exit', 'quit']);
26
+ const EXIT_WORDS = new Set(['exit', 'quit', '/exit']);
27
+ const LIVE_LOCAL_COMMAND_NAMES = new Set(['help', 'settings', 'context', 'model', 'config', 'permissions']);
22
28
  const MAX_PENDING_PEER_MESSAGES = 32;
23
29
  const TOOL_OUTPUT_EMIT_INTERVAL_MS = 32;
30
+ const RESPONSE_DELAY_NOTICE_MS = 30_000;
24
31
  const EXPORT_PYTHON = 'export:python';
25
32
  const EXPORT_TYPESCRIPT = 'export:typescript';
33
+ const EXPORT_NAME_PREFIX = 'export:name:';
34
+ const EXPORT_SAVE_DEFAULT_PREFIX = 'export:save-default:';
35
+ const EXPORT_SAVE_CUSTOM_PREFIX = 'export:save-custom:';
26
36
  export class ChatController {
27
37
  peerEndpointId;
28
38
  _listeners = new Set();
@@ -33,24 +43,38 @@ export class ChatController {
33
43
  _sessionCache;
34
44
  _sessionRefresh;
35
45
  _sessionGeneration = 0;
46
+ _sessionNaming;
47
+ _sessionRename = Promise.resolve();
36
48
  _skills;
49
+ _skillRefresh;
37
50
  _skillNames = new Set();
38
51
  _mcp;
52
+ _mcpDetails = new Map();
53
+ _mcpStartup;
54
+ _stopWatchingMcpStartup;
39
55
  _settings;
40
56
  _streamPresentation;
41
57
  _setSettings;
42
58
  _requestSetup;
59
+ _awsProfile;
43
60
  _builtinTools;
44
61
  _builtinToolSelection = new Set();
45
62
  _exportAgentProject;
63
+ _useExportedProject;
64
+ _configurationSource;
46
65
  _project;
47
66
  _copyText;
48
67
  _exportedPath;
68
+ _configuration;
69
+ _configurationDiffs;
70
+ /** The configuration before the first change of a turn; diffs accumulate against it for the rest of that turn. */
71
+ _configurationBaseline;
49
72
  _backend;
50
- _activeProjector;
51
- _drainingProjector;
52
- _presentationAbort;
73
+ _execution;
53
74
  _pendingSubmissions = [];
75
+ _pendingSteering = [];
76
+ _steeringDrain;
77
+ _pendingPermissionReplies = new Set();
54
78
  _pendingSubmissionRun;
55
79
  _stopWatchingTasks;
56
80
  _stopWatchingPermissions;
@@ -80,6 +104,8 @@ export class ChatController {
80
104
  _nextPanel = 1;
81
105
  _nextSubmission = 1;
82
106
  _runtime;
107
+ _permissionMode;
108
+ _permissionPreset;
83
109
  _snapshot;
84
110
  constructor(backend, options = {}) {
85
111
  this.peerEndpointId = options.peerEndpointId;
@@ -90,15 +116,22 @@ export class ChatController {
90
116
  this._skillNames.add(name.toLowerCase());
91
117
  }
92
118
  this._mcp = options.mcp;
119
+ this._watchMcpStartup();
93
120
  this._settings = globalThis.structuredClone({ ...DEFAULT_CHAT_SETTINGS, ...options.settings });
94
121
  this._streamPresentation = options.streamPresentation;
95
122
  this._setSettings = options.setSettings;
96
123
  this._requestSetup = options.requestSetup;
124
+ this._awsProfile = options.awsProfile;
97
125
  this._builtinTools = options.builtinTools;
98
126
  this._exportAgentProject = options.exportAgentProject;
127
+ this._useExportedProject = options.useExportedProject;
128
+ this._configurationSource = options.configurationSource;
99
129
  this._project = options.project;
100
130
  this._copyText = options.copyText ?? copyTerminalText;
101
131
  const info = backend.info?.();
132
+ const permissionStatus = backend.permissionStatus?.();
133
+ this._permissionMode = permissionStatus?.mode;
134
+ this._permissionPreset = permissionStatus ? permissionPreset(permissionStatus) : undefined;
102
135
  this._runtime = {
103
136
  agent: backend.name,
104
137
  version: 'development',
@@ -115,10 +148,15 @@ export class ChatController {
115
148
  this._completedTurns = [...options.initialTurns];
116
149
  }
117
150
  else if (options.initialMessages) {
118
- this._completedTurns.push(...projectMessages(options.initialMessages, backend.name));
151
+ this._completedTurns.push(...projectMessages(options.initialMessages, this.name));
119
152
  }
120
153
  this._nextTurn = this._completedTurns.length + 1;
121
154
  this._context = { ...(backend.contextUsage?.() ?? {}) };
155
+ this._refreshConfiguration();
156
+ if (options.initialConfigurationBaseline && this._configuration) {
157
+ this._configurationBaseline = options.initialConfigurationBaseline;
158
+ this._configurationDiffs = configurationDiffs(options.initialConfigurationBaseline.source, this._configuration);
159
+ }
122
160
  this._snapshot = this._createSnapshot();
123
161
  this._stopWatchingTasks = this._backend.watchTasks?.((tasks) => {
124
162
  if (this._closed) {
@@ -149,6 +187,31 @@ export class ChatController {
149
187
  };
150
188
  };
151
189
  getSnapshot = () => this._snapshot;
190
+ get name() {
191
+ return this._runtime.agent;
192
+ }
193
+ setAgentName(name) {
194
+ this._runtime.agent = sanitizeTerminalText(name);
195
+ this._emit();
196
+ }
197
+ async renameAgent(name) {
198
+ const normalized = sanitizeTerminalText(name).replace(/\s+/g, ' ').trim();
199
+ if (!normalized)
200
+ throw new Error('Agent names cannot be empty.');
201
+ if (this._resourceChanging)
202
+ throw new Error('Wait for the current change to finish before renaming the agent.');
203
+ this._resourceChanging = true;
204
+ try {
205
+ if (this._sessions?.current)
206
+ await this._sessions.renameAgent?.(normalized);
207
+ this._activeProjector?.setAgentName(normalized);
208
+ this._completedTurns = this._completedTurns.map((turn) => ({ ...turn, agentName: normalized }));
209
+ this.setAgentName(normalized);
210
+ }
211
+ finally {
212
+ this._finishResourceChange();
213
+ }
214
+ }
152
215
  async captureConversation() {
153
216
  if (!this._backend.captureConversation) {
154
217
  throw new Error('This agent cannot transfer its conversation.');
@@ -158,10 +221,15 @@ export class ChatController {
158
221
  }
159
222
  const session = this._backend.sessionIdentity;
160
223
  const sourceSelection = this._backend.sourceSelection?.();
224
+ const selection = this._backend.modelSelection?.() ?? sourceSelection?.selected;
161
225
  return {
162
226
  snapshot: await this._backend.captureConversation(),
163
227
  completedTurns: [...this._completedTurns],
228
+ ...(this.name !== this._backend.name ? { agentName: this.name } : {}),
229
+ ...(this._configurationBaseline ? { configurationBaseline: this._configurationBaseline } : {}),
164
230
  model: this._runtime.model,
231
+ workspace: this._runtime.cwd,
232
+ ...(selection ? { selection } : {}),
165
233
  ...(session ? { session } : {}),
166
234
  ...(sourceSelection ? { sourceSelection } : {}),
167
235
  };
@@ -173,15 +241,28 @@ export class ChatController {
173
241
  return this._backend;
174
242
  }
175
243
  get busy() {
176
- return (this._activeProjector !== undefined ||
177
- this._drainingProjector !== undefined ||
244
+ return (this._execution !== undefined ||
178
245
  this._pendingSubmissions.length > 0 ||
179
246
  this._pendingSubmissionRun !== undefined ||
180
247
  this._resourceChanging);
181
248
  }
249
+ get _activeProjector() {
250
+ return this._execution?.phase === 'running' ? this._execution.projector : undefined;
251
+ }
182
252
  get hardExitCode() {
183
253
  return this._hardExitCode;
184
254
  }
255
+ get resumeSession() {
256
+ const session = this._sessions?.currentTarget ?? this._backend.sessionIdentity;
257
+ if (!session?.sessionId)
258
+ return undefined;
259
+ return {
260
+ sessionId: session.sessionId,
261
+ sessionDirectory: session.sessionDirectory,
262
+ workspace: session.workspace,
263
+ ...(this._project ? { agentProject: this._project.entrypoint } : {}),
264
+ };
265
+ }
185
266
  actionableCommandToken(input) {
186
267
  if (input.startsWith('!')) {
187
268
  return '!';
@@ -197,7 +278,15 @@ export class ChatController {
197
278
  ? invocation.token
198
279
  : undefined;
199
280
  }
281
+ commandAssistance(input) {
282
+ // Runs per render; skip the skill-command materialization for the common non-command input.
283
+ if (!input.startsWith('/')) {
284
+ return undefined;
285
+ }
286
+ return resolveCommandAssistance(input, this.actionableCommandToken(input), this._skillCommands());
287
+ }
200
288
  async start(firstRequest) {
289
+ setImmediate(() => void this._discoverSkillNames());
201
290
  if (firstRequest) {
202
291
  const prompt = firstRequest.trim();
203
292
  if (prompt.startsWith('!')) {
@@ -208,36 +297,87 @@ export class ChatController {
208
297
  }
209
298
  }
210
299
  }
300
+ follow(prompt, stream) {
301
+ return this._runStream(prompt, stream, 'model');
302
+ }
303
+ async _discoverSkillNames() {
304
+ if (!this._skills || this._backend.protocol !== 'strands') {
305
+ return;
306
+ }
307
+ try {
308
+ this._rememberSkills(await this._listSkills());
309
+ this._emit();
310
+ }
311
+ catch {
312
+ // /skills reports discovery failures when the user opens it.
313
+ }
314
+ }
315
+ _listSkills() {
316
+ if (this._skillRefresh) {
317
+ return this._skillRefresh;
318
+ }
319
+ const refresh = this._skills.list();
320
+ this._skillRefresh = refresh;
321
+ const clearRefresh = () => {
322
+ if (this._skillRefresh === refresh) {
323
+ this._skillRefresh = undefined;
324
+ }
325
+ };
326
+ void refresh.then(clearRefresh, clearRefresh);
327
+ return refresh;
328
+ }
329
+ _rememberSkills(skills) {
330
+ this._skillDetails.clear();
331
+ for (const skill of skills) {
332
+ this._skillDetails.set(skill.name, skill);
333
+ this._skillNames.add(skill.name.toLowerCase());
334
+ }
335
+ }
336
+ _skillCommands() {
337
+ return [...this._skillDetails.values()].map((skill) => ({
338
+ name: skill.name,
339
+ usage: `/${sanitizeTerminalText(skill.name)} [request]`,
340
+ description: skill.description,
341
+ }));
342
+ }
211
343
  async submit(input) {
212
- const prompt = input.trim();
213
- if (!prompt || this._closed) {
344
+ const submission = normalizeChatInput(input);
345
+ const { text: prompt, attachments } = submission;
346
+ if ((!prompt && attachments.length === 0) || this._closed) {
214
347
  return undefined;
215
348
  }
216
- if (EXIT_WORDS.has(prompt.toLowerCase())) {
349
+ // The failure reminder has been on screen while the user typed; any submission counts as seen.
350
+ if (this._mcpStartup?.settled) {
351
+ this._mcpStartup = undefined;
352
+ }
353
+ if (attachments.length === 0 && EXIT_WORDS.has(prompt.toLowerCase())) {
217
354
  this.close();
218
355
  return undefined;
219
356
  }
220
- if (/^\/help(?:\s|$)/iu.test(prompt) && !this._resourceChanging && this._panel?.kind !== 'permission') {
357
+ if (attachments.length === 0 &&
358
+ isLiveLocalCommand(prompt) &&
359
+ !this._resourceChanging &&
360
+ (this._panel?.kind !== 'permission' ||
361
+ ['settings', 'permissions'].includes(parseCommandInvocation(prompt)?.name.toLowerCase() ?? ''))) {
221
362
  return this._executeSubmission(prompt);
222
363
  }
223
- if (this._activeProjector ||
224
- this._drainingProjector ||
225
- this._pendingSubmissionRun ||
226
- this._pendingSubmissions.length > 0) {
227
- return this._enqueueSubmission(prompt);
364
+ if (this._execution || this._pendingSubmissionRun || this._pendingSubmissions.length > 0) {
365
+ return this._enqueueSubmission(submission);
228
366
  }
229
367
  if (this._resourceChanging) {
230
368
  return undefined;
231
369
  }
232
- return this._executeSubmission(prompt);
370
+ return this._executeSubmission(submission);
233
371
  }
234
- enqueuePeerMessage(message) {
372
+ enqueuePeerMessage(message, steerWhileRunning = false) {
235
373
  if (this._closed ||
236
374
  this._resourceChanging ||
237
375
  !this._backend.streamPeer ||
238
376
  this._pendingSubmissions.filter((pending) => pending.kind === 'peer').length >= MAX_PENDING_PEER_MESSAGES) {
239
377
  return false;
240
378
  }
379
+ if (steerWhileRunning && this._queueLiveSteering(peerMessagePrompt(message)))
380
+ return true;
241
381
  this._pendingSubmissions.push({
242
382
  kind: 'peer',
243
383
  id: `queued-${this._nextSubmission++}`,
@@ -260,8 +400,7 @@ export class ChatController {
260
400
  return this.busy ? this._enqueueSubmission(prompt) : this._executeSubmission(prompt);
261
401
  }
262
402
  if (this._resourceChanging &&
263
- !this._activeProjector &&
264
- !this._drainingProjector &&
403
+ !this._execution &&
265
404
  !this._pendingSubmissionRun &&
266
405
  this._pendingSubmissions.length === 0) {
267
406
  return undefined;
@@ -269,50 +408,54 @@ export class ChatController {
269
408
  if (!this.busy) {
270
409
  return this._executeSubmission(prompt);
271
410
  }
272
- if (this._activeProjector && this._backend.queueSteering) {
273
- if (this._backend.queueSteering(prompt)) {
274
- return undefined;
275
- }
411
+ if (this._queueLiveSteering(prompt)) {
412
+ return undefined;
276
413
  }
277
414
  const pending = this._enqueueSubmission(prompt, true);
278
- this.cancel();
415
+ if (!this._steeringDrain) {
416
+ this.cancel();
417
+ }
279
418
  return pending;
280
419
  }
281
420
  steerQueued(id = this._pendingSubmissions.find((pending) => pending.kind === 'user')?.id) {
282
- if (!id || this._closed) {
421
+ if (!id || this._closed)
283
422
  return false;
284
- }
285
- const index = this._pendingSubmissions.findIndex((pending) => pending.id === id);
286
- if (index < 0) {
287
- return false;
288
- }
423
+ const index = this._pendingSubmissions.findIndex((pending) => pending.kind === 'user' && pending.id === id);
289
424
  const pending = this._pendingSubmissions[index];
290
- if (pending.kind !== 'user') {
425
+ if (pending?.kind !== 'user')
291
426
  return false;
427
+ const { text, attachments } = pending.input;
428
+ if (attachments.length === 0 && !/^[!/$]/u.test(text) && this._queueLiveSteering(text)) {
429
+ this._pendingSubmissions.splice(index, 1);
430
+ pending.resolve(undefined);
292
431
  }
293
- if (!pending.prompt.startsWith('!') && this._activeProjector && this._backend.queueSteering) {
294
- if (this._backend.queueSteering(pending.prompt)) {
295
- this._pendingSubmissions.splice(index, 1);
296
- pending.resolve(undefined);
297
- this._emit();
298
- return true;
299
- }
300
- }
301
- if (index > 0) {
432
+ else {
302
433
  this._pendingSubmissions.splice(index, 1);
303
434
  this._pendingSubmissions.unshift(pending);
435
+ if (!this._steeringDrain)
436
+ this.cancel();
304
437
  }
305
- this.cancel();
306
438
  this._emit();
307
439
  return true;
308
440
  }
309
441
  updateQueuedPrompt(id, prompt) {
310
442
  const normalized = prompt.trim();
311
443
  const pending = this._pendingSubmissions.find((candidate) => candidate.kind === 'user' && candidate.id === id);
312
- if (!pending || !normalized) {
444
+ if (!pending)
313
445
  return false;
314
- }
315
- pending.prompt = normalized;
446
+ if (!normalized && pending.input.attachments.length === 0)
447
+ return this.removeQueuedPrompt(id);
448
+ pending.input = { ...pending.input, text: normalized };
449
+ this._emit();
450
+ return true;
451
+ }
452
+ removeQueuedPrompt(id) {
453
+ const index = this._pendingSubmissions.findIndex((pending) => pending.kind === 'user' && pending.id === id);
454
+ const pending = this._pendingSubmissions[index];
455
+ if (pending?.kind !== 'user')
456
+ return false;
457
+ this._pendingSubmissions.splice(index, 1);
458
+ pending.resolve(undefined);
316
459
  this._emit();
317
460
  return true;
318
461
  }
@@ -330,13 +473,18 @@ export class ChatController {
330
473
  this._emit();
331
474
  return true;
332
475
  }
333
- async _executeSubmission(prompt) {
476
+ async _executeSubmission(input) {
477
+ const submission = normalizeChatInput(input);
478
+ const { text: prompt, attachments } = submission;
479
+ if (attachments.length > 0) {
480
+ return this._runPrompt(submission);
481
+ }
334
482
  if (prompt.startsWith('!')) {
335
483
  return this._runShellCommand(prompt);
336
484
  }
337
485
  const directSkill = prompt.startsWith('$') ? parseCommandInvocation(prompt) : undefined;
338
486
  if (directSkill) {
339
- const turn = await this._activateSkillAndRun(directSkill.name, directSkill.argument);
487
+ const turn = await this._activateSkillAndRun(directSkill.name, prompt);
340
488
  if (turn === null) {
341
489
  this._openError('unknown skill', `$${directSkill.name}`, 'Use /skills to list available skills.');
342
490
  return undefined;
@@ -361,32 +509,29 @@ export class ChatController {
361
509
  }
362
510
  this._panel = undefined;
363
511
  this._panelStack.length = 0;
364
- return this._runStream(prompt, this._backend.streamShell(command));
512
+ return this._runStream(prompt, this._backend.streamShell(command), 'shell');
365
513
  }
366
- async _runPrompt(prompt) {
367
- if (this._closed || this._activeProjector || this._drainingProjector || this._resourceChanging) {
514
+ async _runPrompt(input, displayPrompt) {
515
+ if (this._closed || this._execution || this._resourceChanging) {
368
516
  return undefined;
369
517
  }
518
+ const submission = normalizeChatInput(input);
370
519
  this._panel = undefined;
371
520
  this._panelStack.length = 0;
372
- return this._runStream(prompt, this._backend.stream(prompt));
521
+ const prompt = submission.attachments.length === 0 ? submission.text : attachmentContent(submission.text, submission.attachments);
522
+ return this._runStream(displayPrompt ?? submission.text, this._backend.stream(prompt), 'model', undefined, undefined, submission.attachments);
373
523
  }
374
524
  async _runPeerMessage(message) {
375
- if (this._closed ||
376
- this._activeProjector ||
377
- this._drainingProjector ||
378
- this._resourceChanging ||
379
- !this._backend.streamPeer) {
525
+ if (this._closed || this._execution || this._resourceChanging || !this._backend.streamPeer) {
380
526
  return undefined;
381
527
  }
382
528
  this._panel = undefined;
383
529
  this._panelStack.length = 0;
384
- return this._runStream(message.body, this._backend.streamPeer(message), 'peer', message.from);
530
+ return this._runStream(message.body, this._backend.streamPeer(message), 'model', 'peer', message.from);
385
531
  }
386
532
  async _runBackgroundContinuation() {
387
533
  if (this._closed ||
388
- this._activeProjector !== undefined ||
389
- this._drainingProjector !== undefined ||
534
+ this._execution !== undefined ||
390
535
  this._pendingSubmissionRun !== undefined ||
391
536
  this._resourceChanging ||
392
537
  this._pendingSubmissions.some((pending) => pending.kind === 'user') ||
@@ -394,14 +539,35 @@ export class ChatController {
394
539
  !this._backend.hasReadyBackgroundResults?.()) {
395
540
  return;
396
541
  }
397
- await this._runStream('', this._backend.streamBackgroundResults(), 'background');
542
+ await this._runStream('', this._backend.streamBackgroundResults(), 'model', 'background');
398
543
  }
399
- async _runStream(prompt, source, turnSource, peer) {
544
+ async _runStream(prompt, source, mode, turnSource, peer, attachments) {
400
545
  const turnId = `turn-${this._nextTurn++}`;
401
- const projector = new TurnProjector(turnId, prompt, this._backend.name, turnSource, peer);
546
+ const projector = new TurnProjector(turnId, prompt, this.name, turnSource, peer, attachments);
402
547
  const usageGeneration = this._usageGeneration;
403
548
  const presentationAbort = new AbortController();
549
+ const execution = { phase: 'running', projector, presentationAbort };
404
550
  let toolOutputEmitTimer;
551
+ let responseDelayTimer;
552
+ const runningTools = new Set();
553
+ const resetResponseDelay = (event) => {
554
+ if (event?.type === 'tasks')
555
+ return;
556
+ clearTimeout(responseDelayTimer);
557
+ projector.setResponseDelayed(false);
558
+ if (event?.type === 'toolStart' && !event.background)
559
+ runningTools.add(event.toolUseId);
560
+ if (event?.type === 'toolResult')
561
+ runningTools.delete(event.toolUseId);
562
+ if (mode === 'shell' || runningTools.size > 0 || event?.type === 'permission')
563
+ return;
564
+ responseDelayTimer = setTimeout(() => {
565
+ if (this._activeProjector !== projector)
566
+ return;
567
+ projector.setResponseDelayed(true);
568
+ this._emit();
569
+ }, RESPONSE_DELAY_NOTICE_MS);
570
+ };
405
571
  const emitStreamEvent = (event) => {
406
572
  if (event.type !== 'toolOutputDelta') {
407
573
  clearTimeout(toolOutputEmitTimer);
@@ -414,8 +580,8 @@ export class ChatController {
414
580
  this._emit();
415
581
  }, TOOL_OUTPUT_EMIT_INTERVAL_MS);
416
582
  };
417
- this._activeProjector = projector;
418
- this._presentationAbort = presentationAbort;
583
+ this._execution = execution;
584
+ resetResponseDelay();
419
585
  this._emit();
420
586
  const contextBeforeTurn = { ...this._context };
421
587
  try {
@@ -426,6 +592,7 @@ export class ChatController {
426
592
  let next = await stream.next();
427
593
  while (!next.done) {
428
594
  this._handleEvent(projector, next.value, turnContext);
595
+ resetResponseDelay(next.value);
429
596
  emitStreamEvent(next.value);
430
597
  next = await stream.next();
431
598
  }
@@ -439,24 +606,24 @@ export class ChatController {
439
606
  }
440
607
  catch (error) {
441
608
  this._context = contextBeforeTurn;
442
- projector.fail(error);
609
+ const recovery = mode === 'shell' ? undefined : this._failureRecoveryHint(error);
610
+ projector.fail(error, recovery);
443
611
  }
444
612
  finally {
445
613
  clearTimeout(toolOutputEmitTimer);
446
- const wasDetachedByCancellation = this._drainingProjector === projector;
447
- if (!wasDetachedByCancellation) {
448
- this._completedTurns.push(projector.snapshot());
614
+ clearTimeout(responseDelayTimer);
615
+ const steeringDrain = this._drainSteering(projector);
616
+ if (steeringDrain) {
617
+ await steeringDrain;
449
618
  }
450
- if (this._activeProjector === projector) {
451
- this._activeProjector = undefined;
619
+ if (execution.phase === 'running') {
620
+ this._completedTurns.push(projector.snapshot());
452
621
  }
453
- if (wasDetachedByCancellation) {
454
- this._drainingProjector = undefined;
622
+ if (this._execution === execution) {
623
+ this._execution = undefined;
455
624
  }
625
+ this._steeringDrain = undefined;
456
626
  this._clearDeliveredBackgroundTaskNotices();
457
- if (this._presentationAbort === presentationAbort) {
458
- this._presentationAbort = undefined;
459
- }
460
627
  this._emit();
461
628
  if (!this._closed) {
462
629
  await this._applyDeferredModelRestart();
@@ -466,6 +633,15 @@ export class ChatController {
466
633
  }
467
634
  return projector.snapshot();
468
635
  }
636
+ _failureRecoveryHint(error) {
637
+ const message = errorMessage(error);
638
+ const credentials = /credentials?|expiredtoken|security token|sso.*expired/i.test(message);
639
+ const guidance = credentials
640
+ ? 'Refresh your credentials, then resend your message.'
641
+ : 'Check your connection and provider, then resend your message.';
642
+ const session = this.resumeSession;
643
+ return session ? `${guidance}\nTo resume after restarting: ${sessionResumeCommand(session)}` : guidance;
644
+ }
469
645
  _watchTurnUsage(turnId, projector, watch) {
470
646
  let active = true;
471
647
  let unsubscribe = () => { };
@@ -489,11 +665,12 @@ export class ChatController {
489
665
  }
490
666
  if (this._activeProjector === projector ||
491
667
  (!this._activeProjector && this._completedTurns.at(-1)?.id === turnId)) {
492
- const { currentTokens, projectedTokens, contextWindow } = this._context;
668
+ const { currentTokens, projectedTokens, contextWindow, breakdown } = this._context;
493
669
  this._context = {
494
670
  ...(currentTokens !== undefined ? { currentTokens } : {}),
495
671
  ...(projectedTokens !== undefined ? { projectedTokens } : {}),
496
672
  ...(contextWindow !== undefined ? { contextWindow } : {}),
673
+ ...(breakdown ? { breakdown } : {}),
497
674
  ...usage,
498
675
  };
499
676
  }
@@ -513,49 +690,56 @@ export class ChatController {
513
690
  }
514
691
  }
515
692
  cancel() {
516
- if (this._activeProjector) {
517
- const projector = this._activeProjector;
518
- projector.markCancelled();
519
- this._completedTurns.push(projector.snapshot());
520
- this._activeProjector = undefined;
521
- this._drainingProjector = projector;
522
- this._presentationAbort?.abort();
523
- this._backend.cancel();
693
+ const execution = this._execution;
694
+ if (!execution)
695
+ return false;
696
+ const running = execution.phase === 'running';
697
+ if (running) {
698
+ execution.projector.markCancelled();
699
+ this._completedTurns.push(execution.projector.snapshot());
700
+ execution.phase = 'interrupting';
701
+ void this._drainSteering(execution.projector);
702
+ }
703
+ execution.presentationAbort.abort();
704
+ this._backend.cancel();
705
+ if (running)
524
706
  this._emit();
525
- return true;
526
- }
527
- if (this._drainingProjector) {
528
- this._presentationAbort?.abort();
529
- this._backend.cancel();
530
- return true;
531
- }
532
- return false;
707
+ return true;
533
708
  }
534
709
  close(exitCode = 0) {
535
710
  if (this._closed) {
536
711
  return;
537
712
  }
538
713
  this._closed = true;
714
+ this._sessionNaming?.abort();
539
715
  this._stopWatchingUsage();
540
716
  this._backgroundContinuationPending = false;
541
- const interrupted = this._activeProjector !== undefined || this._drainingProjector !== undefined;
717
+ const interrupted = this._execution !== undefined;
542
718
  this._exitCode = interrupted && exitCode === 0 ? 130 : exitCode;
543
- if (interrupted) {
719
+ if (this._execution) {
544
720
  this._hardExitCode = this._exitCode;
545
721
  this._activeProjector?.markCancelled();
546
- this._presentationAbort?.abort();
722
+ this._execution.presentationAbort.abort();
723
+ void this._drainSteering(this._execution.projector);
724
+ this._pendingSteering.length = 0;
547
725
  this._backend.cancel();
548
726
  }
549
727
  this._resolvePendingSubmissions();
550
728
  this._emit();
551
729
  }
552
730
  async dispose() {
731
+ this._closed = true;
732
+ this._sessionNaming?.abort();
553
733
  this._stopWatchingUsage();
554
- if (this._activeProjector || this._drainingProjector) {
555
- this._presentationAbort?.abort();
734
+ if (this._execution) {
735
+ this._execution.presentationAbort.abort();
736
+ void this._drainSteering(this._execution.projector);
737
+ this._pendingSteering.length = 0;
556
738
  this._backend.cancel();
557
739
  }
558
740
  this._resolvePendingSubmissions();
741
+ this._stopWatchingMcpStartup?.();
742
+ this._stopWatchingMcpStartup = undefined;
559
743
  this._stopWatchingTasks?.();
560
744
  this._stopWatchingTasks = undefined;
561
745
  this._stopWatchingPermissions?.();
@@ -564,12 +748,21 @@ export class ChatController {
564
748
  this._listeners.clear();
565
749
  await Promise.allSettled([Promise.resolve().then(() => this._backend.dispose?.()), this._mcp?.dispose()]);
566
750
  }
567
- _enqueueSubmission(prompt, priority = false) {
751
+ _finishResourceChange() {
752
+ this._resourceChanging = false;
753
+ if (this._deferredModelRestart) {
754
+ void this._applyDeferredModelRestart();
755
+ }
756
+ this._startBackgroundContinuation();
757
+ this._startPendingSubmissions();
758
+ this._emit();
759
+ }
760
+ _enqueueSubmission(input, priority = false) {
568
761
  return new Promise((resolve) => {
569
762
  const pending = {
570
763
  kind: 'user',
571
764
  id: `queued-${this._nextSubmission++}`,
572
- prompt,
765
+ input: normalizeChatInput(input),
573
766
  resolve,
574
767
  };
575
768
  if (priority) {
@@ -582,12 +775,91 @@ export class ChatController {
582
775
  this._startPendingSubmissions();
583
776
  });
584
777
  }
778
+ _queueLiveSteering(prompt) {
779
+ if (!this._activeProjector || this._steeringDrain || !this._backend.queueSteering) {
780
+ return false;
781
+ }
782
+ const projector = this._activeProjector;
783
+ let receipt;
784
+ let consumed = false;
785
+ const queued = this._backend.queueSteering(prompt, () => {
786
+ if (consumed || this._closed || (receipt && !this._pendingSteering.includes(receipt))) {
787
+ return;
788
+ }
789
+ consumed = true;
790
+ projector.appendUserMessage(prompt);
791
+ const turn = projector.snapshot();
792
+ const completedIndex = this._completedTurns.findIndex((completed) => completed.id === turn.id);
793
+ if (completedIndex >= 0) {
794
+ const completed = this._completedTurns[completedIndex];
795
+ const received = turn.entries.filter((entry) => entry.type === 'user' && !completed.entries.some((existing) => existing.id === entry.id));
796
+ this._completedTurns[completedIndex] = { ...completed, entries: [...completed.entries, ...received] };
797
+ }
798
+ if (receipt) {
799
+ const index = this._pendingSteering.indexOf(receipt);
800
+ if (index >= 0) {
801
+ this._pendingSteering.splice(index, 1);
802
+ }
803
+ }
804
+ this._emit();
805
+ });
806
+ if (!queued) {
807
+ return false;
808
+ }
809
+ if (consumed) {
810
+ return true;
811
+ }
812
+ receipt = { prompt };
813
+ this._pendingSteering.push(receipt);
814
+ this._emit();
815
+ return true;
816
+ }
817
+ _drainSteering(projector) {
818
+ if (this._steeringDrain?.projector === projector) {
819
+ return this._steeringDrain.pending;
820
+ }
821
+ const drain = { projector };
822
+ this._steeringDrain = drain;
823
+ const failed = (error) => {
824
+ this._pendingSteering.length = 0;
825
+ if (!this._closed) {
826
+ this._addNotice('error', `Steering delivery could not be confirmed: ${errorMessage(error)}`);
827
+ this._emit();
828
+ }
829
+ };
830
+ try {
831
+ const prompts = this._backend.drainSteering?.() ?? [];
832
+ if (Array.isArray(prompts)) {
833
+ this._queueUndeliveredSteering(prompts);
834
+ }
835
+ else {
836
+ drain.pending = prompts.then((undelivered) => this._queueUndeliveredSteering(undelivered), failed);
837
+ }
838
+ }
839
+ catch (error) {
840
+ failed(error);
841
+ }
842
+ return drain.pending;
843
+ }
844
+ _queueUndeliveredSteering(prompts) {
845
+ if (this._closed) {
846
+ return;
847
+ }
848
+ for (const prompt of prompts) {
849
+ const index = this._pendingSteering.findIndex((pending) => pending.prompt === prompt);
850
+ if (index >= 0) {
851
+ this._pendingSteering.splice(index, 1);
852
+ }
853
+ }
854
+ for (const prompt of [...prompts].reverse()) {
855
+ void this._enqueueSubmission(prompt, true);
856
+ }
857
+ }
585
858
  _startPendingSubmissions() {
586
859
  if (this._pendingSubmissionRun ||
587
860
  this._pendingSubmissions.length === 0 ||
588
861
  this._closed ||
589
- this._activeProjector ||
590
- this._drainingProjector ||
862
+ this._execution ||
591
863
  this._resourceChanging) {
592
864
  return;
593
865
  }
@@ -603,7 +875,7 @@ export class ChatController {
603
875
  });
604
876
  }
605
877
  async _drainPendingSubmissions() {
606
- while (!this._closed && !this._activeProjector && !this._drainingProjector && !this._resourceChanging) {
878
+ while (!this._closed && !this._execution && !this._resourceChanging) {
607
879
  if (!this._pendingSubmissions.some((pending) => pending.kind === 'user') &&
608
880
  this._backgroundContinuationPending &&
609
881
  this._backend.hasReadyBackgroundResults?.()) {
@@ -619,7 +891,7 @@ export class ChatController {
619
891
  await this._runPeerMessage(pending.message);
620
892
  }
621
893
  else {
622
- const turn = await this._executeSubmission(pending.prompt);
894
+ const turn = await this._executeSubmission(pending.input);
623
895
  pending.resolve(turn);
624
896
  }
625
897
  }
@@ -643,6 +915,9 @@ export class ChatController {
643
915
  this._emit();
644
916
  return true;
645
917
  }
918
+ async setSettings(settings) {
919
+ return this._applySettings(settings, 'settings');
920
+ }
646
921
  async activatePanelRow(row) {
647
922
  if (!this._panel || !row.value || this._resourceChanging) {
648
923
  return false;
@@ -657,27 +932,34 @@ export class ChatController {
657
932
  await this.submit(`/${row.value.slice('help:command:'.length)}`);
658
933
  }
659
934
  else {
660
- this._pushPanel('detail', selected.label, [], { body: selected.description });
935
+ this._pushPanel({ kind: 'help-detail', title: selected.label, rows: [], body: selected.description });
661
936
  }
662
937
  return true;
663
938
  }
664
939
  case 'effort':
665
940
  case 'models':
941
+ if (row.value.startsWith('aws-profile:')) {
942
+ return this._selectAwsProfile(row.value);
943
+ }
666
944
  return row.value.startsWith('effort:')
667
945
  ? this._selectEffort(row.value.slice('effort:'.length))
668
946
  : this._selectModel(row.value);
669
- case 'skills':
670
- await this.submit(`$${row.value}`);
671
- return true;
672
947
  case 'tasks':
673
- return row.value === BACKGROUND_TASK_WAIT_TOGGLE
674
- ? this._toggleBackgroundTaskWaitMode()
675
- : this._openTaskDetail(row.value);
948
+ return this.openTask(readTaskValue(row.value) ?? '');
676
949
  case 'permissions':
677
950
  return this._updatePermissions(row.value);
678
951
  case 'tools':
679
952
  return this._toggleBuiltinTool(row.value);
953
+ case 'mcp':
954
+ return row.value.startsWith('mcp:toggle:') ? this._toggleMcpServer(row.value) : false;
680
955
  case 'settings':
956
+ if (row.value === SETTINGS_SETUP_ACTION) {
957
+ if (!this._requestSetup) {
958
+ return false;
959
+ }
960
+ this._requestSetup();
961
+ return true;
962
+ }
681
963
  return row.value.startsWith('settings:')
682
964
  ? this._openSettingsCategory(row.value)
683
965
  : this._updateSetting(row.value);
@@ -685,11 +967,37 @@ export class ChatController {
685
967
  if (row.value === 'export:copy-path' || row.value === 'export:copy-command') {
686
968
  return this._copyExport(row.value);
687
969
  }
688
- return row.value === EXPORT_TYPESCRIPT
689
- ? this._exportAgent('typescript')
690
- : row.value === EXPORT_PYTHON
691
- ? this._exportAgent('python')
692
- : false;
970
+ if (row.value === 'export:use-project') {
971
+ return this._useExported();
972
+ }
973
+ if (row.value === EXPORT_TYPESCRIPT || row.value === EXPORT_PYTHON) {
974
+ this._openExportNamePanel(row.value === EXPORT_TYPESCRIPT ? 'typescript' : 'python');
975
+ return true;
976
+ }
977
+ if (row.value.startsWith(EXPORT_NAME_PREFIX)) {
978
+ const [language, encodedName = ''] = row.value.slice(EXPORT_NAME_PREFIX.length).split(':');
979
+ if (language !== 'typescript' && language !== 'python') {
980
+ return false;
981
+ }
982
+ this._openExportDestinationPanel(language, exportDirectoryName(decodeURIComponent(encodedName)));
983
+ return true;
984
+ }
985
+ if (row.value.startsWith(EXPORT_SAVE_DEFAULT_PREFIX) || row.value.startsWith(EXPORT_SAVE_CUSTOM_PREFIX)) {
986
+ const custom = row.value.startsWith(EXPORT_SAVE_CUSTOM_PREFIX);
987
+ const [language, encodedName] = row.value
988
+ .slice((custom ? EXPORT_SAVE_CUSTOM_PREFIX : EXPORT_SAVE_DEFAULT_PREFIX).length)
989
+ .split(':');
990
+ if ((language !== 'typescript' && language !== 'python') || !encodedName) {
991
+ return false;
992
+ }
993
+ const name = decodeURIComponent(encodedName);
994
+ if (!custom) {
995
+ return this._exportAgent(language, strandsUserPath('harnesses', name), 'directory');
996
+ }
997
+ const parent = await chooseDirectory(`Choose where to save ${name}`);
998
+ return parent ? this._exportAgent(language, join(parent, name), 'directory') : true;
999
+ }
1000
+ return false;
693
1001
  case 'permission':
694
1002
  return this._respondPermission(row.value);
695
1003
  default:
@@ -697,7 +1005,15 @@ export class ChatController {
697
1005
  }
698
1006
  }
699
1007
  openContextPanel() {
700
- this._openPanel('context', 'Context usage', []);
1008
+ this._openPanel({ kind: 'context', title: 'Context usage', rows: [] });
1009
+ }
1010
+ refreshConfiguration(resetDiff = false) {
1011
+ if (resetDiff) {
1012
+ this._configurationBaseline = undefined;
1013
+ this._configurationDiffs = undefined;
1014
+ }
1015
+ this._refreshConfiguration(!resetDiff);
1016
+ this._emit();
701
1017
  }
702
1018
  sessionTarget(reference) {
703
1019
  return this._sessions && this._backend.protocol === 'strands'
@@ -718,7 +1034,7 @@ export class ChatController {
718
1034
  this._openError('model change unavailable', modelId, 'This backend cannot change to this model.');
719
1035
  return false;
720
1036
  }
721
- if (this._activeProjector || this._drainingProjector) {
1037
+ if (this._execution) {
722
1038
  const supersededModelId = this._deferredModelRestart;
723
1039
  const supersededNotice = this._notices.find((candidate) => candidate.id === this._deferredModelNoticeId);
724
1040
  if (supersededModelId && supersededNotice) {
@@ -738,6 +1054,7 @@ export class ChatController {
738
1054
  this._context = {};
739
1055
  this._refreshRuntime(typeof selected === 'string' ? selected : modelId);
740
1056
  this._updateOpenModelPanel(modelId);
1057
+ this._openEffortPanelIfAvailable();
741
1058
  this._emit();
742
1059
  return true;
743
1060
  }
@@ -746,7 +1063,7 @@ export class ChatController {
746
1063
  return false;
747
1064
  }
748
1065
  finally {
749
- this._resourceChanging = false;
1066
+ this._finishResourceChange();
750
1067
  }
751
1068
  }
752
1069
  _handleEvent(projector, event, turnContext) {
@@ -765,29 +1082,79 @@ export class ChatController {
765
1082
  return;
766
1083
  }
767
1084
  projector.handle(event);
1085
+ if (event.type === 'toolStart' && isConfigurationTool(event.name)) {
1086
+ if (!this._configurationBaseline || this._configurationBaseline.turnId !== this._configurationTurnId()) {
1087
+ this._configurationDiffs = undefined;
1088
+ }
1089
+ this._refreshConfiguration();
1090
+ }
1091
+ else if (event.type === 'toolResult' && projector.hasTool(isConfigurationTool)) {
1092
+ this._refreshConfiguration(true);
1093
+ }
1094
+ }
1095
+ /** Mirrors background MCP connection progress into the snapshot; failures stay visible until /mcp opens. */
1096
+ _watchMcpStartup() {
1097
+ const startup = this._mcp?.startup;
1098
+ if (!startup) {
1099
+ return;
1100
+ }
1101
+ const refresh = () => {
1102
+ const progress = startup.progress();
1103
+ const settled = progress.connected + progress.failed >= progress.total;
1104
+ if (!settled) {
1105
+ this._mcpStartup = { ...progress, settled: false };
1106
+ return;
1107
+ }
1108
+ this._mcpStartup = progress.failed > 0 ? { ...progress, settled: true } : undefined;
1109
+ this._stopWatchingMcpStartup?.();
1110
+ this._stopWatchingMcpStartup = undefined;
1111
+ };
1112
+ refresh();
1113
+ if (!this._mcpStartup || this._mcpStartup.settled) {
1114
+ return;
1115
+ }
1116
+ this._stopWatchingMcpStartup = startup.subscribe(() => {
1117
+ refresh();
1118
+ this._emit();
1119
+ });
768
1120
  }
769
1121
  _createSnapshot() {
770
1122
  const activeTurn = this._activeProjector?.snapshot();
771
1123
  return {
772
1124
  completedTurns: [...this._completedTurns],
773
1125
  ...(activeTurn ? { activeTurn } : {}),
1126
+ pendingSteering: this._pendingSteering.map(({ prompt }) => sanitizeTerminalText(prompt)),
774
1127
  queuedPrompts: this._pendingSubmissions.map((pending) => ({
775
1128
  id: pending.id,
776
- prompt: sanitizeTerminalText(pending.kind === 'peer' ? pending.message.body : pending.prompt),
1129
+ prompt: pending.kind === 'peer' ? pending.message.body : pending.input.text,
1130
+ ...(pending.kind === 'user' && pending.input.attachments.length > 0
1131
+ ? {
1132
+ attachments: pending.input.attachments.map(({ name, size, kind }) => ({
1133
+ name: sanitizeTerminalText(name),
1134
+ size,
1135
+ kind,
1136
+ })),
1137
+ }
1138
+ : {}),
777
1139
  ...(pending.kind === 'peer'
778
1140
  ? {
779
1141
  source: 'peer',
780
- from: sanitizeTerminalText(pending.message.from.name),
1142
+ from: pending.message.from.name,
781
1143
  }
782
1144
  : {}),
783
1145
  })),
784
1146
  notices: this._notices.map((notice) => ({ ...notice })),
785
1147
  tasks: this._tasks.map(cloneTask),
786
1148
  context: { ...this._context },
787
- status: this._closed ? 'closed' : activeTurn ? 'running' : this._drainingProjector ? 'interrupting' : 'idle',
1149
+ status: this._closed ? 'closed' : (this._execution?.phase ?? 'idle'),
1150
+ ...(this._mcpStartup ? { mcpStartup: { ...this._mcpStartup } } : {}),
788
1151
  ...(this._composerStatus ? { composerStatus: this._composerStatus } : {}),
789
- ...(this._panel ? { panel: clonePanel(this._panel) } : {}),
1152
+ ...(this._panel ? { panel: makePanel(this._panel.id, this._panel) } : {}),
1153
+ ...(this._configuration ? { configuration: this._configuration } : {}),
1154
+ ...(this._configurationDiffs ? { configurationDiffs: this._configurationDiffs } : {}),
790
1155
  runtime: cloneRuntime(this._runtime),
1156
+ ...(this._permissionMode ? { permissionMode: this._permissionMode } : {}),
1157
+ ...(this._permissionPreset ? { permissionPreset: this._permissionPreset } : {}),
791
1158
  settings: globalThis.structuredClone(this._settings),
792
1159
  ...(this._exitCode !== undefined ? { exitCode: this._exitCode } : {}),
793
1160
  };
@@ -803,17 +1170,21 @@ export class ChatController {
803
1170
  const argument = rest.join(' ');
804
1171
  switch (command.toLowerCase()) {
805
1172
  case 'help':
806
- this._openPanel('help', 'Help', helpRows(this._backend, {
807
- sessions: this._sessions !== undefined,
808
- skills: this._skills !== undefined,
809
- mcp: this._mcp !== undefined,
810
- setup: this._requestSetup !== undefined,
811
- tools: this._builtinTools !== undefined,
812
- export: this._exportAgentProject !== undefined,
813
- }), {
1173
+ this._openPanel({
1174
+ kind: 'help',
1175
+ title: 'Help',
1176
+ rows: helpRows(this._backend, {
1177
+ sessions: this._sessions !== undefined,
1178
+ skills: this._skills !== undefined,
1179
+ mcp: this._mcp !== undefined,
1180
+ setup: this._requestSetup !== undefined,
1181
+ tools: this._builtinTools !== undefined,
1182
+ export: this._exportAgentProject !== undefined,
1183
+ config: this._configurationSource !== undefined,
1184
+ }),
814
1185
  searchable: true,
815
1186
  filters: [
816
- { id: 'controls', label: 'Shortcuts' },
1187
+ { id: 'controls', label: 'Controls' },
817
1188
  { id: 'commands', label: 'Commands' },
818
1189
  { id: 'tools', label: 'Tools' },
819
1190
  { id: 'all', label: 'All' },
@@ -846,6 +1217,14 @@ export class ChatController {
846
1217
  case 'sessions':
847
1218
  await (argument ? this._handleSessionsCommand(argument) : this._openSessionsPanel());
848
1219
  break;
1220
+ case 'rename':
1221
+ try {
1222
+ await this.renameAgent(argument);
1223
+ }
1224
+ catch (error) {
1225
+ this._openError('agent rename failed', argument, errorMessage(error));
1226
+ }
1227
+ break;
849
1228
  case 'skills':
850
1229
  await this._openSkillsPanel();
851
1230
  break;
@@ -858,6 +1237,9 @@ export class ChatController {
858
1237
  case 'settings':
859
1238
  this._openSettingsCategory(`settings:${DEFAULT_SETTINGS_CATEGORY}`, true);
860
1239
  break;
1240
+ case 'config':
1241
+ this._openConfigurationPanel(argument);
1242
+ break;
861
1243
  case 'setup':
862
1244
  this._requestSetup?.();
863
1245
  break;
@@ -871,7 +1253,7 @@ export class ChatController {
871
1253
  this.close();
872
1254
  break;
873
1255
  default: {
874
- const turn = await this._activateSkillAndRun(command, argument);
1256
+ const turn = await this._activateSkillAndRun(command, prompt);
875
1257
  if (turn === null) {
876
1258
  this._openError('unknown command', `/${command}`, 'Type / to browse commands or use /skills to list skills.');
877
1259
  }
@@ -888,7 +1270,31 @@ export class ChatController {
888
1270
  }
889
1271
  const choices = this._builtinTools.choices();
890
1272
  this._builtinToolSelection = new Set(choices.filter((choice) => choice.enabled).map((choice) => choice.name));
891
- this._openPanel('tools', 'tools', builtinToolRows(choices, this._builtinToolSelection));
1273
+ this._openPanel({ kind: 'tools', title: 'Tools', rows: builtinToolRows(choices, this._builtinToolSelection) });
1274
+ }
1275
+ _openConfigurationPanel(argument) {
1276
+ const requested = argument.toLowerCase();
1277
+ if (requested && requested !== 'typescript' && requested !== 'python') {
1278
+ this._openError('unknown configuration language', argument, 'Use /config, /config typescript, or /config python.');
1279
+ return;
1280
+ }
1281
+ this._refreshConfiguration();
1282
+ if (!this._configuration) {
1283
+ this._openError('configuration unavailable', '/config', 'This connection does not expose editable agent configuration.');
1284
+ return;
1285
+ }
1286
+ const language = (requested || this._configuration.preferredLanguage);
1287
+ this._openPanel({
1288
+ kind: 'config',
1289
+ title: 'Configuration',
1290
+ rows: [],
1291
+ filters: [
1292
+ { id: 'typescript', label: 'TypeScript' },
1293
+ { id: 'python', label: 'Python' },
1294
+ ],
1295
+ configuration: this._configuration,
1296
+ language,
1297
+ });
892
1298
  }
893
1299
  _toggleBuiltinTool(value) {
894
1300
  if (this._panel?.kind !== 'tools' || !this._builtinTools || !value.startsWith('tools:toggle:')) {
@@ -900,7 +1306,7 @@ export class ChatController {
900
1306
  }
901
1307
  // Keeping the panel id keeps the cursor on the toggled row.
902
1308
  const rows = builtinToolRows(this._builtinTools.choices(), this._builtinToolSelection);
903
- this._panel = makePanel(this._panel.id, 'tools', 'tools', rows, {});
1309
+ this._panel = makePanel(this._panel.id, { kind: 'tools', title: 'Tools', rows });
904
1310
  this._emit();
905
1311
  return true;
906
1312
  }
@@ -918,69 +1324,83 @@ export class ChatController {
918
1324
  return true;
919
1325
  }
920
1326
  _openTasksPanel() {
921
- this._openPanel('tasks', `tasks (${this._tasks.length})`, taskRows(this._tasks, this._backend.backgroundTasksWaitForCompletion?.()));
1327
+ const tasks = taskRows(this._tasks);
1328
+ this._openPanel({
1329
+ kind: 'tasks',
1330
+ title: `Tasks (${tasks.length})`,
1331
+ rows: tasks,
1332
+ searchable: true,
1333
+ });
922
1334
  }
923
- async _toggleBackgroundTaskWaitMode() {
924
- const current = this._backend.backgroundTasksWaitForCompletion?.();
925
- if (current === undefined || !this._backend.setBackgroundTasksWaitForCompletion) {
926
- return false;
927
- }
928
- if (this._hasUnresolvedBackgroundTasks()) {
929
- this._openError('task mode change blocked', 'Wait for completion', 'Background work is still running or waiting to be delivered. Finish or cancel it before rebuilding the agent.');
930
- return false;
931
- }
932
- const next = !current;
933
- this._resourceChanging = true;
934
- this._openPanel('tasks', 'updating background behavior', [
935
- {
936
- label: 'Wait for completion',
937
- description: `Rebuilding the agent with wait for completion ${next ? 'on' : 'off'}.`,
938
- },
939
- ]);
940
- try {
941
- await this._backend.setBackgroundTasksWaitForCompletion(next);
942
- this._context = {};
943
- this._refreshRuntime();
944
- this._openTasksPanel();
945
- return true;
946
- }
947
- catch (error) {
948
- this._openError('task mode change failed', 'Wait for completion', errorMessage(error));
949
- return false;
950
- }
951
- finally {
952
- this._resourceChanging = false;
1335
+ _openEffortPanel() {
1336
+ if (this._openEffortPanelIfAvailable()) {
1337
+ return;
953
1338
  }
1339
+ this._openError('effort unavailable', this._runtime.model, 'This model does not support reasoning effort.');
954
1340
  }
955
- _openEffortPanel() {
1341
+ _openEffortPanelIfAvailable() {
956
1342
  const slider = effortSlider(this._backend.listEfforts?.() ?? []);
957
1343
  if (!slider || slider.disabled) {
958
- this._openError('effort unavailable', this._runtime.model, 'This model does not support reasoning effort.');
959
- return;
1344
+ return false;
960
1345
  }
961
- this._openPanel('effort', 'effort', [], {
962
- slider: { ...slider, focused: true },
1346
+ this._openPanel({
1347
+ kind: 'effort',
1348
+ title: 'Effort',
1349
+ rows: [],
1350
+ slider,
963
1351
  body: `${modelDisplayName(this._runtime.model)}\n${this._runtime.model}`,
964
1352
  });
1353
+ return true;
1354
+ }
1355
+ _selectAwsProfile(value) {
1356
+ const panel = this._panel;
1357
+ if (panel?.kind !== 'models' || !panel.awsProfile || !this._awsProfile)
1358
+ return false;
1359
+ const profile = panel.awsProfile;
1360
+ if (value === 'aws-profile:toggle') {
1361
+ this._panel = { ...panel, awsProfile: { ...profile, open: !profile.open } };
1362
+ this._emit();
1363
+ return true;
1364
+ }
1365
+ const selected = profile.options.find((option) => value === `aws-profile:select:${encodeURIComponent(option.value)}`);
1366
+ if (!selected)
1367
+ return false;
1368
+ if (selected.value !== profile.value) {
1369
+ if (this.busy || this._hasUnresolvedBackgroundTasks()) {
1370
+ this._openError('AWS profile change blocked', selected.label, 'Finish or cancel running work first.');
1371
+ return false;
1372
+ }
1373
+ try {
1374
+ this._awsProfile.select(selected.value);
1375
+ }
1376
+ catch (error) {
1377
+ this._openError('AWS profile change failed', selected.label, errorMessage(error));
1378
+ return false;
1379
+ }
1380
+ }
1381
+ this._panel = { ...panel, awsProfile: { ...profile, open: false } };
1382
+ this._emit();
1383
+ return true;
965
1384
  }
966
1385
  async openModelPanel() {
967
1386
  if (!this._backend.listModels) {
968
1387
  this._openError('models unavailable', this._runtime.model, 'This backend does not expose model selection.');
969
1388
  return;
970
1389
  }
971
- const loading = this._openPanel('models', 'models', [{ label: 'loading', description: 'Discovering models.' }]);
1390
+ const loading = this._openPanel({ kind: 'models', title: 'Models', rows: [], loading: true });
972
1391
  try {
973
1392
  const models = await this._backend.listModels();
974
1393
  if (this._panel?.id !== loading.id) {
975
1394
  return;
976
1395
  }
977
- const efforts = this._backend.listEfforts?.() ?? [];
978
- const slider = effortSlider(efforts);
979
- this._openPanel('models', `models (${models.length})`, modelRows(models, this._runtime.model), {
1396
+ this._openPanel({
1397
+ kind: 'models',
1398
+ title: `Models (${models.length})`,
1399
+ rows: modelRows(models, this._runtime.model),
980
1400
  searchable: true,
981
1401
  filters: modelFilters(models.map((model) => model.catalog).filter((catalog) => !!catalog), this._backend.protocol),
982
- ...(slider ? { slider } : {}),
983
1402
  body: `${modelDisplayName(this._runtime.model)}\n${this._runtime.model}`,
1403
+ ...(this._awsProfile ? { awsProfile: this._awsProfile.get() } : {}),
984
1404
  });
985
1405
  }
986
1406
  catch (error) {
@@ -1014,10 +1434,11 @@ export class ChatController {
1014
1434
  const selected = await this._backend.switchModel(modelId);
1015
1435
  this._context = {};
1016
1436
  this._refreshRuntime(selected ?? modelId);
1017
- if (this._activeProjector || this._drainingProjector) {
1437
+ if (this._execution) {
1018
1438
  this._addNotice('delivered', `Model updated for the next model call: ${modelDisplayName(modelId)}`);
1019
1439
  }
1020
1440
  this._updateOpenModelPanel(modelId);
1441
+ this._openEffortPanelIfAvailable();
1021
1442
  this._emit();
1022
1443
  return true;
1023
1444
  }
@@ -1026,7 +1447,7 @@ export class ChatController {
1026
1447
  return false;
1027
1448
  }
1028
1449
  finally {
1029
- this._resourceChanging = false;
1450
+ this._finishResourceChange();
1030
1451
  }
1031
1452
  }
1032
1453
  async _selectEffort(effort) {
@@ -1043,7 +1464,7 @@ export class ChatController {
1043
1464
  const selected = await this._backend.setEffort(effort);
1044
1465
  this._context = {};
1045
1466
  this._refreshRuntime();
1046
- if ((this._panel?.kind === 'models' || this._panel?.kind === 'effort') && this._panel.slider) {
1467
+ if (this._panel?.kind === 'effort') {
1047
1468
  this._panel = {
1048
1469
  ...this._panel,
1049
1470
  slider: {
@@ -1063,7 +1484,7 @@ export class ChatController {
1063
1484
  return false;
1064
1485
  }
1065
1486
  finally {
1066
- this._resourceChanging = false;
1487
+ this._finishResourceChange();
1067
1488
  }
1068
1489
  }
1069
1490
  async _openSessionsPanel() {
@@ -1073,13 +1494,17 @@ export class ChatController {
1073
1494
  return;
1074
1495
  }
1075
1496
  if (this._sessionCache) {
1076
- const panel = this._showSessionsPanel(sessionsRuntime, this._sessionCache);
1497
+ const panel = this._showSessionsPanel(this._sessionCache);
1077
1498
  void this._refreshSessionsPanel(sessionsRuntime, panel.id);
1078
1499
  return;
1079
1500
  }
1080
- const loading = this._openPanel('sessions', 'sessions', [
1081
- { label: 'loading', description: `Reading ${sessionsRuntime.directory}` },
1082
- ]);
1501
+ const loading = this._openPanel({
1502
+ kind: 'sessions',
1503
+ title: 'Sessions',
1504
+ rows: [{ label: 'loading', description: `Reading ${sessionsRuntime.directory}` }],
1505
+ filters: [{ id: 'all', label: 'All' }],
1506
+ loading: true,
1507
+ });
1083
1508
  await this._refreshSessionsPanel(sessionsRuntime, loading.id);
1084
1509
  }
1085
1510
  async _refreshSessionsPanel(sessionsRuntime, panelId) {
@@ -1089,7 +1514,7 @@ export class ChatController {
1089
1514
  if (generation !== this._sessionGeneration || this._panel?.id !== panelId) {
1090
1515
  return;
1091
1516
  }
1092
- this._showSessionsPanel(sessionsRuntime, sessions, panelId);
1517
+ this._showSessionsPanel(sessions, panelId);
1093
1518
  }
1094
1519
  catch (error) {
1095
1520
  if (generation === this._sessionGeneration && this._panel?.id === panelId && !this._sessionCache) {
@@ -1117,12 +1542,25 @@ export class ChatController {
1117
1542
  void refresh.then(clearRefresh, clearRefresh);
1118
1543
  return refresh;
1119
1544
  }
1120
- _showSessionsPanel(sessionsRuntime, sessions, panelId) {
1121
- const rows = sessionRows(sessions, sessionsRuntime.directory);
1545
+ _showSessionsPanel(sessions, panelId) {
1546
+ const rows = sessionRows(sessions);
1547
+ const filters = sessionFilters(sessions);
1122
1548
  if (!panelId) {
1123
- return this._openPanel('sessions', `sessions (${sessions.length})`, rows, { searchable: true });
1549
+ return this._openPanel({
1550
+ kind: 'sessions',
1551
+ title: `Sessions (${sessions.length})`,
1552
+ rows,
1553
+ searchable: true,
1554
+ filters,
1555
+ });
1124
1556
  }
1125
- const panel = this._makePanel('sessions', `sessions (${sessions.length})`, rows, { searchable: true });
1557
+ const panel = this._makePanel({
1558
+ kind: 'sessions',
1559
+ title: `Sessions (${sessions.length})`,
1560
+ rows,
1561
+ searchable: true,
1562
+ filters,
1563
+ });
1126
1564
  this._panel = { ...panel, id: panelId };
1127
1565
  this._emit();
1128
1566
  return this._panel;
@@ -1134,22 +1572,24 @@ export class ChatController {
1134
1572
  async _handleSessionsCommand(argument) {
1135
1573
  const rename = /^rename(?:\s+([\s\S]+))?$/i.exec(argument);
1136
1574
  if (!rename) {
1137
- this._openError('sessions command failed', `/sessions ${argument}`, 'Use /sessions or /sessions rename <name>.');
1575
+ this._openError('sessions command failed', `/sessions ${argument}`, 'Use /sessions or /sessions rename [name].');
1138
1576
  return;
1139
1577
  }
1140
1578
  const name = rename[1] ?? '';
1141
- if (!name) {
1142
- this._openError('session rename failed', '/sessions rename', 'Use /sessions rename <name>.');
1143
- return;
1144
- }
1145
1579
  if (!this._sessions?.renameCurrent || this._backend.protocol !== 'strands') {
1146
1580
  this._openError('session rename unavailable', name, 'The current backend does not expose a file-backed session.');
1147
1581
  return;
1148
1582
  }
1583
+ this._sessionNaming?.abort();
1584
+ if (!name) {
1585
+ void this._generateSessionName();
1586
+ return;
1587
+ }
1149
1588
  this._resourceChanging = true;
1150
1589
  try {
1151
- const renamed = await this._sessions.renameCurrent(name);
1590
+ const renamed = await this._renameSession(name, this._sessions.current);
1152
1591
  this._runtime.session = renamed.name;
1592
+ this._runtime.sessionName = renamed.name;
1153
1593
  this._invalidateSessions();
1154
1594
  this._sessionCache = this._sessionCache?.map((session) => session.active ? { ...session, name: renamed.name } : session);
1155
1595
  await this._openSessionsPanel();
@@ -1158,30 +1598,84 @@ export class ChatController {
1158
1598
  this._openError('session rename failed', name, errorMessage(error));
1159
1599
  }
1160
1600
  finally {
1161
- this._resourceChanging = false;
1601
+ this._finishResourceChange();
1602
+ }
1603
+ }
1604
+ async _generateSessionName() {
1605
+ if (!this._backend.generateSessionName || !this._sessions?.current) {
1606
+ this._openError('session rename unavailable', '/sessions rename', 'Use /sessions rename <name> on this backend.');
1607
+ return;
1608
+ }
1609
+ const sessionId = this._sessions.current;
1610
+ const request = new AbortController();
1611
+ this._sessionNaming = request;
1612
+ const notice = this._addNotice('running', 'Generating session name');
1613
+ this._emit();
1614
+ try {
1615
+ const name = await this._backend.generateSessionName(request.signal);
1616
+ request.signal.throwIfAborted();
1617
+ const renamed = await this._renameSession(name, sessionId, request.signal);
1618
+ request.signal.throwIfAborted();
1619
+ this._runtime.session = renamed.name;
1620
+ this._runtime.sessionName = renamed.name;
1621
+ this._invalidateSessions();
1622
+ this._sessionCache = undefined;
1623
+ notice.status = 'success';
1624
+ notice.text = `Session renamed: ${renamed.name}`;
1625
+ if (this._panel?.kind === 'sessions') {
1626
+ await this._openSessionsPanel();
1627
+ }
1628
+ }
1629
+ catch (error) {
1630
+ notice.status = request.signal.aborted ? 'delivered' : 'error';
1631
+ notice.text = request.signal.aborted
1632
+ ? 'Session naming cancelled'
1633
+ : `Session rename failed: ${errorMessage(error)}`;
1634
+ }
1635
+ finally {
1636
+ if (this._sessionNaming === request) {
1637
+ this._sessionNaming = undefined;
1638
+ }
1639
+ this._emit();
1162
1640
  }
1163
1641
  }
1642
+ _renameSession(name, sessionId, signal) {
1643
+ const sessions = this._sessions;
1644
+ const renameCurrent = sessions?.renameCurrent?.bind(sessions);
1645
+ if (!sessions || !renameCurrent) {
1646
+ return Promise.reject(new Error('The current backend does not expose a file-backed session.'));
1647
+ }
1648
+ const renamed = this._sessionRename.then(() => {
1649
+ signal?.throwIfAborted();
1650
+ if (sessions.current !== sessionId) {
1651
+ throw new Error('The active session changed before it could be renamed.');
1652
+ }
1653
+ return renameCurrent(name);
1654
+ });
1655
+ this._sessionRename = renamed.catch(() => undefined);
1656
+ return renamed;
1657
+ }
1164
1658
  async _openSkillsPanel() {
1165
1659
  if (!this._skills || this._backend.protocol !== 'strands') {
1166
1660
  this._openError('skills unavailable', 'skills', 'No skills runtime is configured for this backend.');
1167
1661
  return;
1168
1662
  }
1169
- const loading = this._openPanel('skills', 'skills', [
1170
- { label: 'loading', description: 'Parsing configured skills with the Strands SDK.' },
1171
- ]);
1663
+ const loading = this._openPanel({
1664
+ kind: 'skills',
1665
+ title: 'Skills',
1666
+ rows: [{ label: 'loading', description: 'Parsing configured skills with the Strands SDK.' }],
1667
+ });
1172
1668
  try {
1173
- const skills = await this._skills.list();
1669
+ const skills = await this._listSkills();
1174
1670
  if (this._panel?.id !== loading.id) {
1175
1671
  return;
1176
1672
  }
1177
- this._skillDetails.clear();
1178
- for (const skill of skills) {
1179
- this._skillDetails.set(skill.name, skill);
1180
- this._skillNames.add(skill.name.toLowerCase());
1181
- }
1182
- this._openPanel('skills', `skills (${skills.length})`, skillRows(skills), {
1673
+ this._rememberSkills(skills);
1674
+ this._openPanel({
1675
+ kind: 'skills',
1676
+ title: `Skills (${skills.length})`,
1677
+ rows: skillRows(skills),
1183
1678
  searchable: true,
1184
- ...(this._skills.paths?.length ? { body: `Checked: ${this._skills.paths.join(', ')}` } : {}),
1185
1679
  });
1186
1680
  }
1187
1681
  catch (error) {
@@ -1190,28 +1684,30 @@ export class ChatController {
1190
1684
  }
1191
1685
  }
1192
1686
  }
1193
- async _activateSkillAndRun(name, argument) {
1687
+ async _activateSkillAndRun(name, displayPrompt) {
1194
1688
  if (!this._skills || this._backend.protocol !== 'strands') {
1195
1689
  return null;
1196
1690
  }
1197
1691
  this._resourceChanging = true;
1198
- let skill;
1199
1692
  try {
1200
- skill = await this._skills.activate(name);
1693
+ const activation = await this._skills.activate(name);
1694
+ if (!activation) {
1695
+ return null;
1696
+ }
1697
+ const { skill } = activation;
1698
+ this._skillNames.add(skill.name.toLowerCase());
1699
+ this._skillDetails.set(skill.name, skill);
1700
+ // Start this submission before releasing queued work.
1701
+ this._resourceChanging = false;
1702
+ return this._runPrompt(skillInvocationPrompt(activation, displayPrompt), displayPrompt);
1201
1703
  }
1202
1704
  catch (error) {
1203
1705
  this._openError('skill activation failed', name, errorMessage(error));
1204
1706
  return undefined;
1205
1707
  }
1206
1708
  finally {
1207
- this._resourceChanging = false;
1208
- }
1209
- if (!skill) {
1210
- return null;
1709
+ this._finishResourceChange();
1211
1710
  }
1212
- this._skillNames.add(skill.name.toLowerCase());
1213
- this._skillDetails.set(skill.name, skill);
1214
- return this._runPrompt(argument || `Use the ${skill.name} skill.`);
1215
1711
  }
1216
1712
  async _compactConversation() {
1217
1713
  if (!this._backend.compact) {
@@ -1241,9 +1737,8 @@ export class ChatController {
1241
1737
  this._openError('compaction failed', 'compact', errorMessage(error));
1242
1738
  }
1243
1739
  finally {
1244
- this._resourceChanging = false;
1245
1740
  this._composerStatus = undefined;
1246
- this._emit();
1741
+ this._finishResourceChange();
1247
1742
  }
1248
1743
  }
1249
1744
  async _clearConversation() {
@@ -1255,10 +1750,12 @@ export class ChatController {
1255
1750
  this._openError('clear blocked', 'clear', 'Background work is still running or waiting to be delivered. Finish or cancel it before clearing.');
1256
1751
  return;
1257
1752
  }
1753
+ this._sessionNaming?.abort();
1258
1754
  this._resourceChanging = true;
1259
- this._openPanel('progress', 'starting fresh conversation', [
1260
- { label: this._backend.name, description: 'Rebuilding through createHarness() without restoring context.' },
1261
- ]);
1755
+ this._composerStatus = 'Starting fresh conversation...';
1756
+ this._panel = undefined;
1757
+ this._panelStack.length = 0;
1758
+ this._emit();
1262
1759
  try {
1263
1760
  await this._backend.clear();
1264
1761
  this._stopWatchingUsage();
@@ -1274,9 +1771,18 @@ export class ChatController {
1274
1771
  this._stopTaskActivity();
1275
1772
  this._skillDetails.clear();
1276
1773
  this._runtime.session = this._backend.info?.().sessionId ?? 'in-memory';
1774
+ delete this._runtime.sessionName;
1277
1775
  this._invalidateSessions();
1278
1776
  this._sessionCache = undefined;
1279
1777
  this._refreshRuntime();
1778
+ if (this.name !== this._backend.name && this._sessions?.current) {
1779
+ try {
1780
+ await this._sessions.renameAgent?.(this.name);
1781
+ }
1782
+ catch (error) {
1783
+ this._addNotice('error', `Conversation cleared; agent name could not be saved: ${errorMessage(error)}`);
1784
+ }
1785
+ }
1280
1786
  this._panel = undefined;
1281
1787
  this._panelStack.length = 0;
1282
1788
  this._emit();
@@ -1285,7 +1791,8 @@ export class ChatController {
1285
1791
  this._openError('clear failed', 'clear', errorMessage(error));
1286
1792
  }
1287
1793
  finally {
1288
- this._resourceChanging = false;
1794
+ this._composerStatus = undefined;
1795
+ this._finishResourceChange();
1289
1796
  }
1290
1797
  }
1291
1798
  openSkillDetail(name) {
@@ -1293,25 +1800,96 @@ export class ChatController {
1293
1800
  if (!skill) {
1294
1801
  return false;
1295
1802
  }
1296
- this._pushPanel('detail', `skill: ${skill.name}`, skillDetailRows(skill), {
1803
+ this._pushPanel({
1804
+ kind: 'detail',
1805
+ title: `Skill: ${skill.name}`,
1806
+ rows: skillDetailRows(skill),
1297
1807
  body: skill.instructions || '(No instructions.)',
1298
1808
  });
1299
1809
  return true;
1300
1810
  }
1811
+ openMcpDetail(name) {
1812
+ const server = this._mcpDetails.get(name);
1813
+ if (!server || this._resourceChanging || this._closed) {
1814
+ return false;
1815
+ }
1816
+ const failure = server.state === 'failed'
1817
+ ? mcpFailure({ ...server, canRetry: this._mcp?.setEnabled !== undefined && server.canRetry !== false })
1818
+ : undefined;
1819
+ this._pushPanel({
1820
+ kind: 'detail',
1821
+ title: `MCP: ${server.name}`,
1822
+ rows: [
1823
+ ...(failure
1824
+ ? [
1825
+ { label: 'Problem', description: failure.summary },
1826
+ { label: 'Next step', description: failure.guidance },
1827
+ ...(this._mcp?.setEnabled && server.canRetry !== false
1828
+ ? [
1829
+ {
1830
+ label: 'Retry',
1831
+ description: 'Esc back, then R retries with the loaded settings. It does not reread configuration.',
1832
+ },
1833
+ ]
1834
+ : []),
1835
+ ]
1836
+ : [{ label: 'Status', description: server.state }]),
1837
+ ...(server.source ? [{ label: 'Source', description: server.source }] : []),
1838
+ { label: 'Transport', description: server.transport },
1839
+ { label: 'Target', description: server.target },
1840
+ ],
1841
+ body: [
1842
+ ...(server.error ? [`Full error\n${server.error}`] : []),
1843
+ ...(this._mcp?.warnings.length ? [`Configuration warnings\n${this._mcp.warnings.join('\n')}`] : []),
1844
+ ].join('\n\n'),
1845
+ });
1846
+ return true;
1847
+ }
1848
+ async retryMcpServer(name) {
1849
+ const server = this._mcpDetails.get(name);
1850
+ if (!server ||
1851
+ server.canRetry === false ||
1852
+ (server.state !== 'failed' && server.state !== 'disconnected') ||
1853
+ this._panel?.kind !== 'mcp') {
1854
+ return false;
1855
+ }
1856
+ return this._setMcpServerEnabled(name, true, false);
1857
+ }
1858
+ _mcpPanel(servers) {
1859
+ this._mcpDetails.clear();
1860
+ for (const server of servers) {
1861
+ this._mcpDetails.set(server.name, server);
1862
+ }
1863
+ const toggles = this._mcp?.setEnabled !== undefined;
1864
+ return {
1865
+ kind: 'mcp',
1866
+ title: `MCP servers (${servers.length})`,
1867
+ rows: mcpRows(servers, toggles),
1868
+ canRetry: toggles &&
1869
+ servers.some((server) => server.canRetry !== false && (server.state === 'failed' || server.state === 'disconnected')),
1870
+ ...mcpOptions(servers, this._mcp?.paths ?? [], this._mcp?.warnings ?? []),
1871
+ };
1872
+ }
1301
1873
  async _openMcpPanel() {
1302
1874
  if (!this._mcp) {
1303
1875
  this._openError('MCP unavailable', 'mcp', 'No MCP runtime is configured.');
1304
1876
  return;
1305
1877
  }
1306
- const loading = this._openPanel('mcp', 'MCP servers', [
1307
- { label: 'loading', description: 'Checking server connections and tools.' },
1308
- ]);
1878
+ // The panel shows every failure, so the composer reminder is done.
1879
+ if (this._mcpStartup?.settled) {
1880
+ this._mcpStartup = undefined;
1881
+ }
1882
+ const loading = this._openPanel({
1883
+ kind: 'mcp',
1884
+ title: 'MCP servers',
1885
+ rows: [{ label: 'loading', description: 'Checking server connections and tools.' }],
1886
+ });
1309
1887
  try {
1310
1888
  const servers = await this._mcp.list(true);
1311
1889
  if (this._panel?.id !== loading.id) {
1312
1890
  return;
1313
1891
  }
1314
- this._openPanel('mcp', `MCP servers (${servers.length})`, mcpRows(servers), mcpOptions(servers, this._mcp.paths, this._mcp.warnings));
1892
+ this._openPanel(this._mcpPanel(servers));
1315
1893
  }
1316
1894
  catch (error) {
1317
1895
  if (this._panel?.id === loading.id) {
@@ -1319,6 +1897,52 @@ export class ChatController {
1319
1897
  }
1320
1898
  }
1321
1899
  }
1900
+ async _toggleMcpServer(value) {
1901
+ const name = decodeURIComponent(value.slice('mcp:toggle:'.length));
1902
+ const server = this._mcpDetails.get(name);
1903
+ if (!server) {
1904
+ return false;
1905
+ }
1906
+ return this._setMcpServerEnabled(name, server.state === 'disabled', true);
1907
+ }
1908
+ async _setMcpServerEnabled(name, enable, persist) {
1909
+ if (!this._mcp?.setEnabled || this.busy || this._closed) {
1910
+ return false;
1911
+ }
1912
+ const panelId = this._panel?.id;
1913
+ this._resourceChanging = true;
1914
+ this._composerStatus = `${enable ? 'Connecting' : 'Disconnecting'} ${sanitizeTerminalText(name)}...`;
1915
+ this._emit();
1916
+ try {
1917
+ const failure = await this._mcp.setEnabled(name, enable);
1918
+ if (persist) {
1919
+ const disabled = new Set(this._settings.disabledMcpServers);
1920
+ if (enable) {
1921
+ disabled.delete(name);
1922
+ }
1923
+ else {
1924
+ disabled.add(name);
1925
+ }
1926
+ this._settings = { ...this._settings, disabledMcpServers: [...disabled] };
1927
+ await this._setSettings?.({ disabledMcpServers: [...disabled] });
1928
+ }
1929
+ if (failure) {
1930
+ this._addNotice('error', `${name}: ${failure}`);
1931
+ }
1932
+ const servers = await this._mcp.list(true);
1933
+ if (this._panel?.kind === 'mcp' && this._panel.id === panelId && !this._closed) {
1934
+ this._panel = makePanel(this._panel.id, this._mcpPanel(servers));
1935
+ }
1936
+ }
1937
+ catch (error) {
1938
+ this._addNotice('error', `${name}: ${errorMessage(error)}`);
1939
+ }
1940
+ finally {
1941
+ this._composerStatus = undefined;
1942
+ this._finishResourceChange();
1943
+ }
1944
+ return true;
1945
+ }
1322
1946
  async _handlePermissionsCommand(argument) {
1323
1947
  if (!argument) {
1324
1948
  this._openPermissionsPanel();
@@ -1340,29 +1964,35 @@ export class ChatController {
1340
1964
  this._openError('permissions unavailable', this._backend.name, 'Permission configuration is available only for the built-in Strands backend.');
1341
1965
  return;
1342
1966
  }
1343
- const options = {
1344
- ...(status.mode === 'bypassPermissions'
1345
- ? { body: 'WARNING: Permission checks are bypassed. Configured interventions and sandboxing still apply.' }
1346
- : {}),
1967
+ this._permissionMode = status.mode;
1968
+ if (!refresh || !this._permissionPreset) {
1969
+ this._permissionPreset = permissionPreset(status);
1970
+ }
1971
+ const panel = {
1972
+ kind: 'permissions',
1973
+ title: 'Permissions',
1974
+ searchable: true,
1975
+ rows: permissionSettingsRows(status, this._runtime.tools, this._permissionPreset),
1976
+ slider: permissionSettingsSlider(this._permissionPreset),
1347
1977
  };
1348
1978
  if (refresh && this._panel?.kind === 'permissions') {
1349
1979
  const currentId = this._panel.id;
1350
- this._panel = {
1351
- ...this._makePanel('permissions', 'permissions', permissionSettingsRows(status, this._runtime.tools), options),
1352
- id: currentId,
1353
- };
1980
+ this._panel = { ...this._makePanel(panel), id: currentId };
1354
1981
  this._emit();
1355
1982
  return;
1356
1983
  }
1357
- this._openPanel('permissions', 'permissions', permissionSettingsRows(status, this._runtime.tools), options);
1984
+ this._openPanel(panel);
1358
1985
  }
1359
1986
  async _updatePermissions(value) {
1360
1987
  const [prefix, action, encodedValue] = value.split(':');
1361
1988
  if (prefix !== 'permissions' || !action || !encodedValue) {
1362
1989
  return false;
1363
1990
  }
1364
- if (action === 'mode' && (encodedValue === 'default' || encodedValue === 'bypassPermissions')) {
1365
- return this._setPermissionMode(encodedValue);
1991
+ if (action === 'preset' && (encodedValue === 'ask' || encodedValue === 'bypass' || encodedValue === 'custom')) {
1992
+ return this._setPermissionPreset(encodedValue);
1993
+ }
1994
+ if (action === 'deny') {
1995
+ return this._removeDeniedPermission(decodeURIComponent(encodedValue));
1366
1996
  }
1367
1997
  if (action !== 'tool' ||
1368
1998
  !this._backend.allowPermission ||
@@ -1379,6 +2009,7 @@ export class ChatController {
1379
2009
  else {
1380
2010
  await this._backend.allowPermission(toolName);
1381
2011
  }
2012
+ this._permissionPreset = 'custom';
1382
2013
  this._openPermissionsPanel(true);
1383
2014
  return true;
1384
2015
  }
@@ -1387,6 +2018,44 @@ export class ChatController {
1387
2018
  return false;
1388
2019
  }
1389
2020
  }
2021
+ async _removeDeniedPermission(rule) {
2022
+ if (!this._backend.removeDeniedPermission) {
2023
+ return false;
2024
+ }
2025
+ try {
2026
+ await this._backend.removeDeniedPermission(rule);
2027
+ this._openPermissionsPanel(true);
2028
+ return true;
2029
+ }
2030
+ catch (error) {
2031
+ this._openError('permission update failed', rule, errorMessage(error));
2032
+ return false;
2033
+ }
2034
+ }
2035
+ async _setPermissionPreset(preset) {
2036
+ const status = this._backend.permissionStatus?.();
2037
+ if (!status || !this._backend.setPermissionMode || !this._backend.removeAllowedPermission) {
2038
+ this._openError('permissions unavailable', this._backend.name, 'Permission configuration is available only for the built-in Strands backend.');
2039
+ return false;
2040
+ }
2041
+ try {
2042
+ if (preset === 'ask') {
2043
+ for (const toolName of status.allowedTools) {
2044
+ await this._backend.removeAllowedPermission(toolName);
2045
+ }
2046
+ }
2047
+ const mode = preset === 'bypass' ? 'bypassPermissions' : 'default';
2048
+ await this._backend.setPermissionMode(mode);
2049
+ this._permissionMode = mode;
2050
+ this._permissionPreset = preset;
2051
+ this._openPermissionsPanel(true);
2052
+ return true;
2053
+ }
2054
+ catch (error) {
2055
+ this._openError('permission update failed', preset, errorMessage(error));
2056
+ return false;
2057
+ }
2058
+ }
1390
2059
  async _setPermissionMode(mode) {
1391
2060
  if (!this._backend.setPermissionMode) {
1392
2061
  this._openError('permissions unavailable', this._backend.name, 'Permission configuration is available only for the built-in Strands backend.');
@@ -1394,6 +2063,9 @@ export class ChatController {
1394
2063
  }
1395
2064
  try {
1396
2065
  await this._backend.setPermissionMode(mode);
2066
+ this._permissionMode = mode;
2067
+ const status = this._backend.permissionStatus?.();
2068
+ this._permissionPreset = status ? permissionPreset(status) : mode === 'default' ? 'ask' : 'bypass';
1397
2069
  this._openPermissionsPanel(true);
1398
2070
  return true;
1399
2071
  }
@@ -1414,8 +2086,7 @@ export class ChatController {
1414
2086
  this._openError('Export arguments required', '/export', 'Usage: /export <typescript|python> <path.zip>');
1415
2087
  return;
1416
2088
  }
1417
- const path = destination.startsWith('~/') ? resolve(homedir(), destination.slice(2)) : destination;
1418
- await this._exportAgent(language, resolve(this._runtime.cwd, path));
2089
+ await this._exportAgent(language, resolve(this._runtime.cwd, expandHome(destination)));
1419
2090
  }
1420
2091
  _openExportPanel() {
1421
2092
  if (!this._exportAgentProject) {
@@ -1423,32 +2094,58 @@ export class ChatController {
1423
2094
  return;
1424
2095
  }
1425
2096
  this._exportedPath = undefined;
1426
- this._openPanel('export', `Export · ${this._backend.name}`, [
1427
- {
1428
- label: 'TypeScript',
1429
- description: 'Runnable @strands-agents/harness project',
1430
- value: EXPORT_TYPESCRIPT,
1431
- },
1432
- {
1433
- label: 'Python',
1434
- description: 'Runnable strands-harness project',
1435
- value: EXPORT_PYTHON,
1436
- },
1437
- ].filter((row) => !this._project || row.value === `export:${this._project.language}`), {
1438
- body: [
1439
- `Agent: ${this._backend.name}`,
1440
- `Source: ${this._project?.entrypoint ?? 'Current agent configuration'}`,
1441
- `Location: ${this._project?.root ?? this._runtime.cwd}`,
1442
- this._project
1443
- ? `Language: ${this._project.language === 'typescript' ? 'TypeScript' : 'Python'} · preserves authored source`
1444
- : 'Choose a language, then choose where to save the ZIP.',
1445
- ...(!canChooseDirectory()
1446
- ? [`Save with /export ${this._project?.language ?? '<typescript|python>'} <path.zip>.`]
1447
- : []),
1448
- ].join('\n'),
2097
+ this._openPanel({
2098
+ kind: 'export',
2099
+ title: `Export ${this._backend.name}`,
2100
+ rows: [
2101
+ {
2102
+ label: 'Python',
2103
+ description: 'strands-harness project',
2104
+ value: EXPORT_PYTHON,
2105
+ },
2106
+ {
2107
+ label: 'TypeScript',
2108
+ description: '@strands-agents/harness project',
2109
+ value: EXPORT_TYPESCRIPT,
2110
+ },
2111
+ ].filter((row) => !this._project || row.value === `export:${this._project.language}`),
2112
+ body: this._project
2113
+ ? 'Export a separate copy of these source files.'
2114
+ : 'Export a copy, including pending agent changes.',
1449
2115
  });
1450
2116
  }
1451
- async _exportAgent(language, destination) {
2117
+ _openExportNamePanel(language) {
2118
+ const defaultName = exportDirectoryName(this._backend.name);
2119
+ this._pushPanel({
2120
+ kind: 'export',
2121
+ title: 'Name exported folder',
2122
+ rows: [],
2123
+ searchable: true,
2124
+ nameInput: { language, defaultName },
2125
+ body: 'Choose a folder name for this copy.',
2126
+ });
2127
+ }
2128
+ _openExportDestinationPanel(language, name) {
2129
+ const encodedName = encodeURIComponent(name);
2130
+ this._pushPanel({
2131
+ kind: 'export',
2132
+ title: `Save ${language === 'typescript' ? 'TypeScript' : 'Python'} copy`,
2133
+ rows: [
2134
+ {
2135
+ label: 'Default folder',
2136
+ description: `~/.strands/harnesses/${name}`,
2137
+ value: `${EXPORT_SAVE_DEFAULT_PREFIX}${language}:${encodedName}`,
2138
+ },
2139
+ {
2140
+ label: canUseNativePicker() ? 'Choose parent folder' : 'Custom path',
2141
+ description: canUseNativePicker() ? `Browse and save as ${name}` : `/export ${language} <path.zip>`,
2142
+ ...(canUseNativePicker() ? { value: `${EXPORT_SAVE_CUSTOM_PREFIX}${language}:${encodedName}` } : {}),
2143
+ },
2144
+ ],
2145
+ body: 'Choose where to save this copy.',
2146
+ });
2147
+ }
2148
+ async _exportAgent(language, destination, output = 'zip') {
1452
2149
  if (!this._exportAgentProject) {
1453
2150
  return false;
1454
2151
  }
@@ -1458,22 +2155,32 @@ export class ChatController {
1458
2155
  }
1459
2156
  this._resourceChanging = true;
1460
2157
  try {
1461
- const path = await this._exportAgentProject(language, destination);
2158
+ const path = output === 'zip'
2159
+ ? await this._exportAgentProject(language, destination)
2160
+ : await this._exportAgentProject(language, destination, output);
1462
2161
  if (path) {
1463
2162
  this._exportedPath = path;
1464
- this._openPanel('export', 'Export complete', [
1465
- { label: 'Copy path', description: path, value: 'export:copy-path' },
1466
- { label: 'Copy launch command', description: agentLaunchCommand(path), value: 'export:copy-command' },
1467
- ], {
1468
- body: [
1469
- `Agent: ${this._backend.name}`,
1470
- `Source: ${this._project?.entrypoint ?? 'Current agent configuration'}`,
1471
- `Language: ${language === 'typescript' ? 'TypeScript' : 'Python'}`,
1472
- `Saved to: ${path}`,
1473
- ].join('\n'),
2163
+ const switchable = output === 'directory' && this._useExportedProject !== undefined;
2164
+ this._openPanel({
2165
+ kind: 'export',
2166
+ title: 'Export complete',
2167
+ rows: [
2168
+ ...(switchable
2169
+ ? [
2170
+ {
2171
+ label: 'Use for this session',
2172
+ description: 'Edits reload this session',
2173
+ value: 'export:use-project',
2174
+ },
2175
+ ]
2176
+ : []),
2177
+ { label: 'Copy path', description: path, value: 'export:copy-path' },
2178
+ { label: 'Copy launch command', description: agentLaunchCommand(path), value: 'export:copy-command' },
2179
+ ],
2180
+ body: 'Saved a copy. No automatic updates.',
1474
2181
  });
1475
2182
  }
1476
- else if (destination === undefined && !canChooseDirectory()) {
2183
+ else if (destination === undefined && output === 'zip') {
1477
2184
  this._openError('Export path required', '/export', `Use /export ${language} <path.zip> to save this agent.`);
1478
2185
  }
1479
2186
  return path !== undefined;
@@ -1483,9 +2190,20 @@ export class ChatController {
1483
2190
  return false;
1484
2191
  }
1485
2192
  finally {
1486
- this._resourceChanging = false;
2193
+ this._finishResourceChange();
1487
2194
  }
1488
2195
  }
2196
+ _useExported() {
2197
+ if (!this._exportedPath || !this._useExportedProject || this._panel?.kind !== 'export') {
2198
+ return false;
2199
+ }
2200
+ if (this.busy || this._hasUnresolvedBackgroundTasks()) {
2201
+ this._openError('switch failed', this._exportedPath, 'Finish or cancel running work before switching projects.');
2202
+ return true;
2203
+ }
2204
+ this._useExportedProject(this._exportedPath);
2205
+ return true;
2206
+ }
1489
2207
  async _copyExport(action) {
1490
2208
  if (!this._exportedPath || this._panel?.kind !== 'export') {
1491
2209
  return false;
@@ -1522,66 +2240,117 @@ export class ChatController {
1522
2240
  if (!update) {
1523
2241
  return false;
1524
2242
  }
2243
+ return this._applySettings(update, setting.split('=')[0]);
2244
+ }
2245
+ async _applySettings(update, setting) {
1525
2246
  this._resourceChanging = true;
1526
2247
  try {
1527
2248
  await this._setSettings?.(update);
2249
+ this._settings = globalThis.structuredClone({ ...this._settings, ...update });
2250
+ if (this._panel?.kind === 'settings') {
2251
+ this._panel = {
2252
+ ...this._panel,
2253
+ rows: sanitizeRows(settingsRows(this._settings, this._panel.settingsCategory ?? DEFAULT_SETTINGS_CATEGORY, this._requestSetup !== undefined)),
2254
+ };
2255
+ }
2256
+ return true;
1528
2257
  }
1529
2258
  catch (error) {
1530
- this._openError('setting update failed', setting.split('=')[0], errorMessage(error));
2259
+ this._openError('setting update failed', setting, errorMessage(error));
1531
2260
  return false;
1532
2261
  }
1533
2262
  finally {
1534
- this._resourceChanging = false;
2263
+ this._finishResourceChange();
1535
2264
  }
1536
- this._settings = globalThis.structuredClone({ ...this._settings, ...update });
1537
- this._panel = {
1538
- ...this._panel,
1539
- rows: sanitizeRows(settingsRows(this._settings, this._panel.settingsCategory ?? DEFAULT_SETTINGS_CATEGORY)),
1540
- };
1541
- this._emit();
1542
- return true;
1543
2265
  }
1544
2266
  _openSettingsCategory(value, replace = false) {
1545
2267
  const category = SETTINGS_CATEGORIES.find(({ id }) => value === `settings:${id}`);
1546
2268
  if (!category) {
1547
2269
  return false;
1548
2270
  }
1549
- const rows = settingsRows(this._settings, category.id);
1550
- const options = {
2271
+ const rows = settingsRows(this._settings, category.id, this._requestSetup !== undefined);
2272
+ const panel = {
2273
+ kind: 'settings',
2274
+ title: category.label,
2275
+ rows,
1551
2276
  filters: settingsCategoryFilters(),
1552
2277
  settingsCategory: category.id,
1553
- settingsCategories: SETTINGS_CATEGORIES,
1554
2278
  };
1555
2279
  if (replace) {
1556
- this._openPanel('settings', category.label, rows, options);
2280
+ this._openPanel(panel);
1557
2281
  }
1558
2282
  else if (this._panel?.kind === 'settings') {
1559
- this._panel = this._makePanel('settings', category.label, rows, options);
2283
+ this._panel = this._makePanel(panel);
1560
2284
  this._emit();
1561
2285
  }
1562
2286
  else {
1563
- this._pushPanel('settings', category.label, rows, options);
2287
+ this._pushPanel(panel);
1564
2288
  }
1565
2289
  return true;
1566
2290
  }
1567
- _respondPermission(value) {
1568
- const [prefix, encodedRequestId, encodedOptionId] = value.split(':');
1569
- if (prefix !== 'permission' || !encodedRequestId || !encodedOptionId) {
2291
+ async _respondPermission(value) {
2292
+ const [prefix, encodedRequestId, encodedOptionId, encodedRule] = value.split(':');
2293
+ if (prefix !== 'permission' || !encodedRequestId || !encodedOptionId || this._panel?.kind !== 'permission') {
1570
2294
  return false;
1571
2295
  }
2296
+ const request = this._panel.request;
1572
2297
  const requestId = decodeURIComponent(encodedRequestId);
1573
2298
  const optionId = decodeURIComponent(encodedOptionId);
1574
- if (!this._backend.respondPermission?.(requestId, optionId)) {
2299
+ if (this._closed || request.id !== requestId || this._pendingPermissionReplies.has(requestId)) {
1575
2300
  return false;
1576
2301
  }
1577
- this._closePermissionPanel();
1578
- return true;
2302
+ if (optionId === 'back' && this._panel.stage) {
2303
+ const stage = this._panel.stage;
2304
+ this._showPermissionPanel(request, undefined, request.options.findIndex((option) => option.id === stage));
2305
+ return true;
2306
+ }
2307
+ if (encodedRule === undefined && permissionChoosesScope(request, optionId)) {
2308
+ this._showPermissionPanel(request, optionId === 'allow-always' ? 'allow-always' : 'deny-always');
2309
+ return true;
2310
+ }
2311
+ const rule = encodedRule === undefined ? undefined : decodeURIComponent(encodedRule);
2312
+ this._pendingPermissionReplies.add(requestId);
2313
+ try {
2314
+ const response = this._backend.respondPermission?.(requestId, optionId, rule) ?? false;
2315
+ const accepted = typeof response === 'boolean' ? response : await response;
2316
+ if (!accepted || this._closed) {
2317
+ return false;
2318
+ }
2319
+ this._closePermissionPanel(requestId);
2320
+ return true;
2321
+ }
2322
+ catch (error) {
2323
+ if (!this._closed) {
2324
+ this._addNotice('error', `Permission response failed: ${errorMessage(error)}`);
2325
+ this._emit();
2326
+ }
2327
+ return false;
2328
+ }
2329
+ finally {
2330
+ this._pendingPermissionReplies.delete(requestId);
2331
+ }
1579
2332
  }
1580
2333
  _openPermissionPanel(request) {
1581
- this._pushPanel('permission', `Allow ${request.toolName}?`, permissionRequestRows(request), {
2334
+ this._pushPanel(this._permissionPanel(request));
2335
+ }
2336
+ _showPermissionPanel(request, stage, selected) {
2337
+ this._panel = this._makePanel(this._permissionPanel(request, stage, selected));
2338
+ this._emit();
2339
+ }
2340
+ _permissionPanel(request, stage, selected) {
2341
+ return {
2342
+ kind: 'permission',
2343
+ title: stage === 'allow-always'
2344
+ ? `Always allow ${request.toolName} for…`
2345
+ : stage === 'deny-always'
2346
+ ? `Always deny ${request.toolName} for…`
2347
+ : 'Allow tool call?',
2348
+ rows: permissionRequestRows(request, stage),
1582
2349
  body: formatPermissionPanelBody(request),
1583
- ...(request.diff ? { diff: request.diff } : {}),
1584
- });
2350
+ request,
2351
+ ...(stage ? { stage } : {}),
2352
+ ...(selected !== undefined && selected > 0 ? { selected } : {}),
2353
+ };
1585
2354
  }
1586
2355
  _refreshRuntime(model) {
1587
2356
  const info = this._backend.info?.();
@@ -1590,7 +2359,6 @@ export class ChatController {
1590
2359
  : (info?.sessionId ?? (this._backend.protocol === 'strands' ? this._runtime.session : 'not saved'));
1591
2360
  const runtime = {
1592
2361
  ...this._runtime,
1593
- agent: this._backend.name,
1594
2362
  backendId: this._backend.id,
1595
2363
  protocol: this._backend.protocol,
1596
2364
  model: model ?? info?.model ?? this._runtime.model,
@@ -1604,12 +2372,45 @@ export class ChatController {
1604
2372
  delete runtime.effort;
1605
2373
  }
1606
2374
  this._runtime = runtime;
2375
+ this._refreshConfiguration();
1607
2376
  }
1608
- _closePermissionPanel() {
1609
- if (this._panel?.kind !== 'permission') {
2377
+ _refreshConfiguration(trackChanges = false) {
2378
+ if (!this._configurationSource) {
2379
+ return;
2380
+ }
2381
+ try {
2382
+ const previous = this._configuration;
2383
+ const configuration = sanitizeConfigurationSource(this._configurationSource());
2384
+ if (trackChanges && previous) {
2385
+ const turnId = this._configurationTurnId();
2386
+ const current = this._configurationBaseline;
2387
+ const baseline = current && current.turnId === turnId ? current : { turnId, source: previous };
2388
+ this._configurationBaseline = baseline;
2389
+ this._configurationDiffs = configurationDiffs(baseline.source, configuration);
2390
+ }
2391
+ this._configuration = configuration;
2392
+ if (this._panel?.kind === 'config') {
2393
+ this._panel = { ...this._panel, configuration: this._configuration };
2394
+ }
2395
+ }
2396
+ catch {
2397
+ // Keep the last readable configuration while the source is being replaced.
2398
+ }
2399
+ }
2400
+ _configurationTurnId() {
2401
+ return this._activeProjector?.snapshot().id ?? this._completedTurns.at(-1)?.id;
2402
+ }
2403
+ _closePermissionPanel(requestId) {
2404
+ const matches = (panel) => panel.kind === 'permission' && (requestId === undefined || panel.request.id === requestId);
2405
+ const panels = this._panelStack.filter((panel) => !matches(panel));
2406
+ const removed = panels.length !== this._panelStack.length;
2407
+ this._panelStack.splice(0, this._panelStack.length, ...panels);
2408
+ if (this._panel && matches(this._panel)) {
2409
+ this._panel = this._panelStack.pop();
2410
+ }
2411
+ else if (!removed) {
1610
2412
  return;
1611
2413
  }
1612
- this._panel = this._panelStack.pop();
1613
2414
  this._emit();
1614
2415
  }
1615
2416
  _setTasks(tasks) {
@@ -1622,10 +2423,11 @@ export class ChatController {
1622
2423
  this._taskBaselineReady = true;
1623
2424
  }
1624
2425
  if (this._panel?.kind === 'tasks') {
2426
+ const rows = taskRows(this._tasks);
1625
2427
  this._panel = {
1626
2428
  ...this._panel,
1627
- title: `tasks (${this._tasks.length})`,
1628
- rows: sanitizeRows(taskRows(this._tasks, this._backend.backgroundTasksWaitForCompletion?.())),
2429
+ title: `Tasks (${rows.length})`,
2430
+ rows: sanitizeRows(rows),
1629
2431
  };
1630
2432
  }
1631
2433
  if (this._openTaskDetailId) {
@@ -1644,8 +2446,7 @@ export class ChatController {
1644
2446
  if (!this._backgroundContinuationPending ||
1645
2447
  this._backgroundContinuationRun ||
1646
2448
  this._closed ||
1647
- this._activeProjector !== undefined ||
1648
- this._drainingProjector !== undefined ||
2449
+ this._execution !== undefined ||
1649
2450
  this._pendingSubmissionRun !== undefined ||
1650
2451
  this._resourceChanging ||
1651
2452
  this._pendingSubmissions.some((pending) => pending.kind === 'user') ||
@@ -1676,16 +2477,18 @@ export class ChatController {
1676
2477
  _hasUnresolvedBackgroundTasks() {
1677
2478
  return this._tasks.some(isUnresolvedBackgroundTask);
1678
2479
  }
1679
- _openTaskDetail(value) {
1680
- const taskId = readTaskValue(value);
1681
- const task = taskId ? this._tasks.find((candidate) => candidate.id === taskId) : undefined;
1682
- if (!task) {
2480
+ openTask(taskId) {
2481
+ const task = this._tasks.find((candidate) => candidate.id === taskId);
2482
+ if (!task || this._closed || this._resourceChanging || this._panel?.kind === 'permission') {
1683
2483
  return false;
1684
2484
  }
1685
2485
  this._stopTaskActivity();
1686
2486
  this._openTaskDetailId = task.id;
1687
2487
  const activity = this._backend.getTaskActivity?.(task.id);
1688
- this._pushPanel('detail', taskDetailTitle(task, activity), taskDetailRows(task, activity), {
2488
+ this._pushPanel({
2489
+ kind: 'detail',
2490
+ title: taskDetailTitle(task, activity),
2491
+ rows: taskDetailRows(task, activity),
1689
2492
  body: activity ? '' : formatTaskActivity(task),
1690
2493
  followTail: true,
1691
2494
  ...(activity ? { activity } : {}),
@@ -1749,7 +2552,7 @@ export class ChatController {
1749
2552
  }
1750
2553
  _markBackgroundTaskDelivered(taskId) {
1751
2554
  this._deliveredBackgroundTaskIds.add(taskId);
1752
- if (!this._activeProjector && !this._drainingProjector) {
2555
+ if (!this._execution) {
1753
2556
  this._clearDeliveredBackgroundTaskNotices();
1754
2557
  }
1755
2558
  }
@@ -1774,7 +2577,7 @@ export class ChatController {
1774
2577
  }
1775
2578
  async _applyDeferredModelRestart() {
1776
2579
  const modelId = this._deferredModelRestart;
1777
- if (!modelId || this._closed || this._activeProjector || this._drainingProjector || !this._backend.restartModel) {
2580
+ if (!modelId || this._closed || this._execution || this._resourceChanging || !this._backend.restartModel) {
1778
2581
  return;
1779
2582
  }
1780
2583
  this._deferredModelRestart = undefined;
@@ -1802,6 +2605,7 @@ export class ChatController {
1802
2605
  notice.status = 'delivered';
1803
2606
  notice.text = `Model changed to ${modelDisplayName(modelId)}`;
1804
2607
  }
2608
+ this._openEffortPanelIfAvailable();
1805
2609
  }
1806
2610
  catch (error) {
1807
2611
  if (notice) {
@@ -1810,8 +2614,7 @@ export class ChatController {
1810
2614
  }
1811
2615
  }
1812
2616
  finally {
1813
- this._resourceChanging = false;
1814
- this._emit();
2617
+ this._finishResourceChange();
1815
2618
  }
1816
2619
  }
1817
2620
  _updateOpenModelPanel(modelId) {
@@ -1835,36 +2638,64 @@ export class ChatController {
1835
2638
  }
1836
2639
  : next;
1837
2640
  });
1838
- const slider = effortSlider(this._backend.listEfforts?.() ?? []);
1839
- const updated = this._makePanel('models', panel.title, rows, {
2641
+ const updated = this._makePanel({
2642
+ kind: 'models',
2643
+ title: panel.title,
2644
+ rows,
1840
2645
  ...(panel.searchable !== undefined ? { searchable: panel.searchable } : {}),
1841
2646
  ...(panel.filters ? { filters: panel.filters } : {}),
1842
- ...(slider ? { slider } : {}),
1843
2647
  body: `${modelDisplayName(this._runtime.model)}\n${this._runtime.model}`,
2648
+ ...(panel.awsProfile ? { awsProfile: panel.awsProfile } : {}),
1844
2649
  });
1845
2650
  this._panel = { ...updated, id: panel.id };
1846
2651
  }
1847
- _openPanel(kind, title, rows, options = {}) {
1848
- this._panelStack.length = 0;
1849
- const panel = this._makePanel(kind, title, rows, options);
2652
+ _openPanel(input) {
2653
+ if (this._panel?.kind === 'permission') {
2654
+ return this._pushPanel(input);
2655
+ }
2656
+ this._panelStack.length = this._panelStack.findIndex((panel) => panel.kind === 'permission') + 1;
2657
+ const panel = this._makePanel(input);
1850
2658
  this._panel = panel;
1851
2659
  this._emit();
1852
2660
  return panel;
1853
2661
  }
1854
- _pushPanel(kind, title, rows, options) {
2662
+ _pushPanel(input) {
1855
2663
  if (this._panel) {
1856
2664
  this._panelStack.push(this._panel);
1857
2665
  }
1858
- const panel = this._makePanel(kind, title, rows, options);
2666
+ const panel = this._makePanel(input);
1859
2667
  this._panel = panel;
1860
2668
  this._emit();
1861
2669
  return panel;
1862
2670
  }
1863
- _makePanel(kind, title, rows, options) {
1864
- return makePanel(`panel-${this._nextPanel++}`, kind, title, rows, options);
2671
+ _makePanel(input) {
2672
+ return makePanel(`panel-${this._nextPanel++}`, input);
1865
2673
  }
1866
2674
  _openError(title, label, description) {
1867
- this._openPanel('error', title, [{ label, description, tone: 'danger' }]);
2675
+ this._openPanel({ kind: 'error', title, rows: [{ label, description, tone: 'danger' }] });
1868
2676
  }
1869
2677
  }
2678
+ function skillInvocationPrompt(activation, displayPrompt) {
2679
+ return [
2680
+ '<strands_skill_activation>',
2681
+ `The user explicitly invoked the ${activation.skill.name} skill. It is already activated; do not call the skills tool again.`,
2682
+ 'Follow the activated instructions below. Treat text after the leading skill command as the request; if there is none, apply the skill to the current conversation.',
2683
+ '',
2684
+ '<skill_instructions>',
2685
+ activation.content,
2686
+ '</skill_instructions>',
2687
+ '</strands_skill_activation>',
2688
+ '',
2689
+ displayPrompt,
2690
+ ].join('\n');
2691
+ }
2692
+ function isLiveLocalCommand(prompt) {
2693
+ const invocation = parseCommandInvocation(prompt);
2694
+ return invocation?.prefix === '/' && LIVE_LOCAL_COMMAND_NAMES.has(invocation.name.toLowerCase());
2695
+ }
2696
+ function normalizeChatInput(input) {
2697
+ return typeof input === 'string'
2698
+ ? { text: input.trim(), attachments: [] }
2699
+ : { text: input.text.trim(), attachments: [...input.attachments] };
2700
+ }
1870
2701
  //# sourceMappingURL=controller.js.map