@agi-fans/dsh-tui 0.21.0 → 0.23.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 (389) hide show
  1. package/LICENSE +26 -0
  2. package/lib/CHANGELOG.md +356 -1
  3. package/lib/chrome/box.d.ts +32 -18
  4. package/lib/chrome/box.js +131 -132
  5. package/lib/chrome/box.js.map +1 -1
  6. package/lib/chrome/code-highlight.d.ts +15 -0
  7. package/lib/chrome/code-highlight.js +61 -5
  8. package/lib/chrome/code-highlight.js.map +1 -1
  9. package/lib/chrome/command-output.d.ts +28 -2
  10. package/lib/chrome/command-output.js +106 -4
  11. package/lib/chrome/command-output.js.map +1 -1
  12. package/lib/chrome/goal-bar.js +1 -1
  13. package/lib/chrome/goal-bar.js.map +1 -1
  14. package/lib/chrome/main-screen-renderer.d.ts +16 -0
  15. package/lib/chrome/main-screen-renderer.js +57 -8
  16. package/lib/chrome/main-screen-renderer.js.map +1 -1
  17. package/lib/chrome/markdown.d.ts +3 -3
  18. package/lib/chrome/markdown.js +101 -32
  19. package/lib/chrome/markdown.js.map +1 -1
  20. package/lib/chrome/md-style.d.ts +5 -2
  21. package/lib/chrome/md-style.js +13 -4
  22. package/lib/chrome/md-style.js.map +1 -1
  23. package/lib/chrome/relative-time.d.ts +17 -0
  24. package/lib/chrome/relative-time.js +36 -0
  25. package/lib/chrome/relative-time.js.map +1 -1
  26. package/lib/chrome/renderer.d.ts +37 -1
  27. package/lib/chrome/renderer.js.map +1 -1
  28. package/lib/chrome/secret-mask.d.ts +35 -0
  29. package/lib/chrome/secret-mask.js +180 -0
  30. package/lib/chrome/secret-mask.js.map +1 -0
  31. package/lib/chrome/status-config.d.ts +161 -51
  32. package/lib/chrome/status-config.js +237 -126
  33. package/lib/chrome/status-config.js.map +1 -1
  34. package/lib/chrome/status-line.d.ts +6 -5
  35. package/lib/chrome/status-line.js +110 -68
  36. package/lib/chrome/status-line.js.map +1 -1
  37. package/lib/chrome/terminal-colors.d.ts +85 -0
  38. package/lib/chrome/terminal-colors.js +230 -0
  39. package/lib/chrome/terminal-colors.js.map +1 -0
  40. package/lib/chrome/terminal-images.d.ts +9 -1
  41. package/lib/chrome/terminal-images.js +27 -4
  42. package/lib/chrome/terminal-images.js.map +1 -1
  43. package/lib/chrome/theme.d.ts +38 -10
  44. package/lib/chrome/theme.js +537 -542
  45. package/lib/chrome/theme.js.map +1 -1
  46. package/lib/chrome/tool-renderers.js +69 -13
  47. package/lib/chrome/tool-renderers.js.map +1 -1
  48. package/lib/chrome/tools-list.d.ts +1 -4
  49. package/lib/chrome/tools-list.js +1 -41
  50. package/lib/chrome/tools-list.js.map +1 -1
  51. package/lib/commands/auth-account.d.ts +9 -0
  52. package/lib/commands/auth-account.js +202 -0
  53. package/lib/commands/auth-account.js.map +1 -0
  54. package/lib/commands/auth-ids.d.ts +25 -0
  55. package/lib/commands/auth-ids.js +27 -0
  56. package/lib/commands/auth-ids.js.map +1 -0
  57. package/lib/commands/auth-input.d.ts +34 -0
  58. package/lib/commands/auth-input.js +96 -0
  59. package/lib/commands/auth-input.js.map +1 -0
  60. package/lib/commands/auth-providers.d.ts +39 -0
  61. package/lib/commands/auth-providers.js +125 -0
  62. package/lib/commands/auth-providers.js.map +1 -0
  63. package/lib/commands/auth.d.ts +12 -20
  64. package/lib/commands/auth.js +264 -627
  65. package/lib/commands/auth.js.map +1 -1
  66. package/lib/commands/btw.d.ts +13 -1
  67. package/lib/commands/btw.js +37 -104
  68. package/lib/commands/btw.js.map +1 -1
  69. package/lib/commands/diff.js +23 -112
  70. package/lib/commands/diff.js.map +1 -1
  71. package/lib/commands/export.d.ts +0 -1
  72. package/lib/commands/export.js +98 -57
  73. package/lib/commands/export.js.map +1 -1
  74. package/lib/commands/files.d.ts +17 -1
  75. package/lib/commands/files.js +68 -114
  76. package/lib/commands/files.js.map +1 -1
  77. package/lib/commands/integrations.d.ts +12 -1
  78. package/lib/commands/integrations.js +120 -23
  79. package/lib/commands/integrations.js.map +1 -1
  80. package/lib/commands/jobs-browser.d.ts +3 -0
  81. package/lib/commands/jobs-browser.js +152 -0
  82. package/lib/commands/jobs-browser.js.map +1 -0
  83. package/lib/commands/jobs.d.ts +12 -8
  84. package/lib/commands/jobs.js +65 -14
  85. package/lib/commands/jobs.js.map +1 -1
  86. package/lib/commands/model.d.ts +3 -0
  87. package/lib/commands/model.js +223 -114
  88. package/lib/commands/model.js.map +1 -1
  89. package/lib/commands/open-external.d.ts +2 -0
  90. package/lib/commands/open-external.js +19 -0
  91. package/lib/commands/open-external.js.map +1 -0
  92. package/lib/commands/permission.js +70 -60
  93. package/lib/commands/permission.js.map +1 -1
  94. package/lib/commands/plugins.js +427 -68
  95. package/lib/commands/plugins.js.map +1 -1
  96. package/lib/commands/schedule-catalog.d.ts +12 -0
  97. package/lib/commands/schedule-catalog.js +41 -0
  98. package/lib/commands/schedule-catalog.js.map +1 -0
  99. package/lib/commands/schedule-history.d.ts +4 -0
  100. package/lib/commands/schedule-history.js +62 -0
  101. package/lib/commands/schedule-history.js.map +1 -0
  102. package/lib/commands/schedule.d.ts +16 -9
  103. package/lib/commands/schedule.js +226 -162
  104. package/lib/commands/schedule.js.map +1 -1
  105. package/lib/commands/session-configuration.d.ts +3 -0
  106. package/lib/commands/session-configuration.js +58 -32
  107. package/lib/commands/session-configuration.js.map +1 -1
  108. package/lib/commands/session.js +118 -97
  109. package/lib/commands/session.js.map +1 -1
  110. package/lib/commands/terminal.d.ts +14 -8
  111. package/lib/commands/terminal.js +32 -185
  112. package/lib/commands/terminal.js.map +1 -1
  113. package/lib/commands/trajectory.js +4 -1
  114. package/lib/commands/trajectory.js.map +1 -1
  115. package/lib/definition.d.ts +226 -29
  116. package/lib/definition.js.map +1 -1
  117. package/lib/index.d.ts +2 -0
  118. package/lib/index.js +2 -0
  119. package/lib/index.js.map +1 -1
  120. package/lib/input/actions.d.ts +51 -0
  121. package/lib/input/actions.js +123 -0
  122. package/lib/input/actions.js.map +1 -0
  123. package/lib/input/composer-files.d.ts +2 -0
  124. package/lib/input/composer-files.js +13 -3
  125. package/lib/input/composer-files.js.map +1 -1
  126. package/lib/input/editor.d.ts +0 -10
  127. package/lib/input/editor.js +11 -9
  128. package/lib/input/editor.js.map +1 -1
  129. package/lib/input/image-paste.d.ts +12 -1
  130. package/lib/input/image-paste.js +86 -1
  131. package/lib/input/image-paste.js.map +1 -1
  132. package/lib/input/key-test.d.ts +5 -0
  133. package/lib/input/key-test.js +19 -0
  134. package/lib/input/key-test.js.map +1 -0
  135. package/lib/input/keybindings-config.d.ts +12 -5
  136. package/lib/input/keybindings-config.js +30 -57
  137. package/lib/input/keybindings-config.js.map +1 -1
  138. package/lib/input/keys.d.ts +18 -0
  139. package/lib/input/keys.js +42 -4
  140. package/lib/input/keys.js.map +1 -1
  141. package/lib/input/wheel-scroll.d.ts +46 -0
  142. package/lib/input/wheel-scroll.js +69 -0
  143. package/lib/input/wheel-scroll.js.map +1 -0
  144. package/lib/locale/index.d.ts +6 -0
  145. package/lib/locale/index.js +32 -0
  146. package/lib/locale/index.js.map +1 -0
  147. package/lib/locale/prompt.d.ts +4 -0
  148. package/lib/locale/prompt.js +24 -0
  149. package/lib/locale/prompt.js.map +1 -0
  150. package/lib/locale/zh.d.ts +1114 -0
  151. package/lib/locale/zh.js +1115 -0
  152. package/lib/locale/zh.js.map +1 -0
  153. package/lib/prompt-intents.d.ts +186 -0
  154. package/lib/prompt-intents.js +131 -0
  155. package/lib/prompt-intents.js.map +1 -0
  156. package/lib/runtime/account-settings.d.ts +18 -0
  157. package/lib/runtime/account-settings.js +241 -0
  158. package/lib/runtime/account-settings.js.map +1 -0
  159. package/lib/runtime/agent-profile.d.ts +3 -3
  160. package/lib/runtime/agent-profile.js +4 -4
  161. package/lib/runtime/agent-profile.js.map +1 -1
  162. package/lib/runtime/btw-policy.js +2 -1
  163. package/lib/runtime/btw-policy.js.map +1 -1
  164. package/lib/runtime/btw.js +1 -2
  165. package/lib/runtime/btw.js.map +1 -1
  166. package/lib/runtime/cancellable.d.ts +75 -0
  167. package/lib/runtime/cancellable.js +76 -0
  168. package/lib/runtime/cancellable.js.map +1 -0
  169. package/lib/runtime/composer-images.d.ts +2 -2
  170. package/lib/runtime/composer-images.js +7 -6
  171. package/lib/runtime/composer-images.js.map +1 -1
  172. package/lib/runtime/composer-shell.d.ts +17 -2
  173. package/lib/runtime/composer-shell.js +133 -41
  174. package/lib/runtime/composer-shell.js.map +1 -1
  175. package/lib/runtime/file-browser.d.ts +19 -0
  176. package/lib/runtime/file-browser.js +291 -0
  177. package/lib/runtime/file-browser.js.map +1 -0
  178. package/lib/runtime/file-recovery-review.d.ts +0 -1
  179. package/lib/runtime/file-recovery-review.js +29 -30
  180. package/lib/runtime/file-recovery-review.js.map +1 -1
  181. package/lib/runtime/file-recovery-store.js +5 -1
  182. package/lib/runtime/file-recovery-store.js.map +1 -1
  183. package/lib/runtime/file-review.d.ts +6 -9
  184. package/lib/runtime/file-review.js +92 -8
  185. package/lib/runtime/file-review.js.map +1 -1
  186. package/lib/runtime/help-reader.d.ts +12 -0
  187. package/lib/runtime/help-reader.js +50 -0
  188. package/lib/runtime/help-reader.js.map +1 -0
  189. package/lib/runtime/hook-settings.d.ts +2 -2
  190. package/lib/runtime/human-interaction.js +1 -1
  191. package/lib/runtime/human-interaction.js.map +1 -1
  192. package/lib/runtime/model-catalog-editor.d.ts +12 -0
  193. package/lib/runtime/model-catalog-editor.js +215 -0
  194. package/lib/runtime/model-catalog-editor.js.map +1 -0
  195. package/lib/runtime/model-settings.d.ts +11 -0
  196. package/lib/runtime/model-settings.js +404 -0
  197. package/lib/runtime/model-settings.js.map +1 -0
  198. package/lib/runtime/plain-tui.d.ts +2 -0
  199. package/lib/runtime/plain-tui.js +7 -1
  200. package/lib/runtime/plain-tui.js.map +1 -1
  201. package/lib/runtime/plugin-settings.d.ts +4 -1
  202. package/lib/runtime/plugin-settings.js +170 -92
  203. package/lib/runtime/plugin-settings.js.map +1 -1
  204. package/lib/runtime/prompt-browser.d.ts +9 -0
  205. package/lib/runtime/prompt-browser.js +19 -0
  206. package/lib/runtime/prompt-browser.js.map +1 -0
  207. package/lib/runtime/provider-local.d.ts +80 -38
  208. package/lib/runtime/provider-local.js +2280 -683
  209. package/lib/runtime/provider-local.js.map +1 -1
  210. package/lib/runtime/reference-reader.d.ts +15 -0
  211. package/lib/runtime/reference-reader.js +78 -0
  212. package/lib/runtime/reference-reader.js.map +1 -0
  213. package/lib/runtime/runner.js +42 -39
  214. package/lib/runtime/runner.js.map +1 -1
  215. package/lib/runtime/session-runtime.js +1 -1
  216. package/lib/runtime/session-runtime.js.map +1 -1
  217. package/lib/runtime/settings-draft.d.ts +21 -0
  218. package/lib/runtime/settings-draft.js +166 -0
  219. package/lib/runtime/settings-draft.js.map +1 -0
  220. package/lib/runtime/settings-preferences.js +1 -1
  221. package/lib/runtime/settings-preferences.js.map +1 -1
  222. package/lib/runtime/startup-notices.d.ts +0 -1
  223. package/lib/runtime/startup-notices.js +35 -4
  224. package/lib/runtime/startup-notices.js.map +1 -1
  225. package/lib/runtime/subagent-model-selection.js +2 -1
  226. package/lib/runtime/subagent-model-selection.js.map +1 -1
  227. package/lib/runtime/subagent-settings.d.ts +14 -0
  228. package/lib/runtime/subagent-settings.js +288 -0
  229. package/lib/runtime/subagent-settings.js.map +1 -0
  230. package/lib/runtime/terminal-modes.d.ts +47 -0
  231. package/lib/runtime/terminal-modes.js +86 -0
  232. package/lib/runtime/terminal-modes.js.map +1 -0
  233. package/lib/runtime/terminal-notifications.d.ts +6 -5
  234. package/lib/runtime/terminal-notifications.js +17 -16
  235. package/lib/runtime/terminal-notifications.js.map +1 -1
  236. package/lib/runtime/terminal-probe.d.ts +38 -0
  237. package/lib/runtime/terminal-probe.js +46 -0
  238. package/lib/runtime/terminal-probe.js.map +1 -0
  239. package/lib/runtime/terminal-session.d.ts +57 -0
  240. package/lib/runtime/terminal-session.js +164 -0
  241. package/lib/runtime/terminal-session.js.map +1 -0
  242. package/lib/runtime/tool-presentation.js.map +1 -1
  243. package/lib/runtime/tool-reader.d.ts +5 -0
  244. package/lib/runtime/tool-reader.js +27 -0
  245. package/lib/runtime/tool-reader.js.map +1 -0
  246. package/lib/runtime/web-settings.d.ts +14 -0
  247. package/lib/runtime/web-settings.js +339 -0
  248. package/lib/runtime/web-settings.js.map +1 -0
  249. package/lib/session/command-attachments.d.ts +17 -0
  250. package/lib/session/command-attachments.js +50 -0
  251. package/lib/session/command-attachments.js.map +1 -0
  252. package/lib/session/context-diagnostics.d.ts +16 -0
  253. package/lib/session/context-diagnostics.js +15 -0
  254. package/lib/session/context-diagnostics.js.map +1 -1
  255. package/lib/session/external-agents.d.ts +3 -1
  256. package/lib/session/external-agents.js +35 -10
  257. package/lib/session/external-agents.js.map +1 -1
  258. package/lib/session/generation-continuation.d.ts +11 -0
  259. package/lib/session/generation-continuation.js +34 -0
  260. package/lib/session/generation-continuation.js.map +1 -0
  261. package/lib/session/goal-controls.d.ts +5 -0
  262. package/lib/session/goal-controls.js +81 -0
  263. package/lib/session/goal-controls.js.map +1 -0
  264. package/lib/session/interaction-adapter.d.ts +7 -3
  265. package/lib/session/interaction-adapter.js +125 -54
  266. package/lib/session/interaction-adapter.js.map +1 -1
  267. package/lib/session/message-queue.d.ts +2 -0
  268. package/lib/session/message-queue.js +102 -17
  269. package/lib/session/message-queue.js.map +1 -1
  270. package/lib/session/package-metadata.d.ts +8 -0
  271. package/lib/session/package-metadata.js +8 -0
  272. package/lib/session/package-metadata.js.map +1 -1
  273. package/lib/session/pending-inputs.d.ts +30 -0
  274. package/lib/session/pending-inputs.js +183 -0
  275. package/lib/session/pending-inputs.js.map +1 -0
  276. package/lib/session/session-configuration.js +1 -1
  277. package/lib/session/session-configuration.js.map +1 -1
  278. package/lib/session/session-controller.d.ts +42 -24
  279. package/lib/session/session-controller.js +534 -106
  280. package/lib/session/session-controller.js.map +1 -1
  281. package/lib/session/session-tree.d.ts +2 -0
  282. package/lib/session/session-tree.js +2 -0
  283. package/lib/session/session-tree.js.map +1 -1
  284. package/lib/session/subagent-roster.d.ts +1 -0
  285. package/lib/session/subagent-roster.js +16 -5
  286. package/lib/session/subagent-roster.js.map +1 -1
  287. package/lib/session/subagent-tracker.d.ts +2 -0
  288. package/lib/session/subagent-tracker.js +18 -0
  289. package/lib/session/subagent-tracker.js.map +1 -1
  290. package/lib/session/tui-settings.d.ts +48 -15
  291. package/lib/session/tui-settings.js +75 -34
  292. package/lib/session/tui-settings.js.map +1 -1
  293. package/lib/session/workflow-projection.d.ts +2 -1
  294. package/lib/session/workflow-projection.js +34 -4
  295. package/lib/session/workflow-projection.js.map +1 -1
  296. package/lib/views/autocomplete.d.ts +28 -9
  297. package/lib/views/autocomplete.js +90 -70
  298. package/lib/views/autocomplete.js.map +1 -1
  299. package/lib/views/context-overview.d.ts +4 -0
  300. package/lib/views/context-overview.js +43 -0
  301. package/lib/views/context-overview.js.map +1 -0
  302. package/lib/views/copy-targets.d.ts +18 -15
  303. package/lib/views/copy-targets.js +35 -60
  304. package/lib/views/copy-targets.js.map +1 -1
  305. package/lib/views/document-reader.d.ts +10 -1
  306. package/lib/views/document-reader.js +76 -9
  307. package/lib/views/document-reader.js.map +1 -1
  308. package/lib/views/event-views.js +71 -17
  309. package/lib/views/event-views.js.map +1 -1
  310. package/lib/views/file-actions.js +21 -0
  311. package/lib/views/file-actions.js.map +1 -1
  312. package/lib/views/file-browser.d.ts +98 -0
  313. package/lib/views/file-browser.js +120 -0
  314. package/lib/views/file-browser.js.map +1 -0
  315. package/lib/views/history-search.js +19 -25
  316. package/lib/views/history-search.js.map +1 -1
  317. package/lib/views/hotkey-format.d.ts +3 -2
  318. package/lib/views/hotkey-format.js +4 -3
  319. package/lib/views/hotkey-format.js.map +1 -1
  320. package/lib/views/hotkeys.d.ts +7 -1
  321. package/lib/views/hotkeys.js +59 -37
  322. package/lib/views/hotkeys.js.map +1 -1
  323. package/lib/views/list-navigation.d.ts +62 -0
  324. package/lib/views/list-navigation.js +73 -0
  325. package/lib/views/list-navigation.js.map +1 -0
  326. package/lib/views/list-view.d.ts +99 -0
  327. package/lib/views/list-view.js +170 -0
  328. package/lib/views/list-view.js.map +1 -0
  329. package/lib/views/prompt-selector.d.ts +54 -4
  330. package/lib/views/prompt-selector.js +349 -162
  331. package/lib/views/prompt-selector.js.map +1 -1
  332. package/lib/views/session-files.d.ts +1 -2
  333. package/lib/views/session-files.js +1 -11
  334. package/lib/views/session-files.js.map +1 -1
  335. package/lib/views/settings-list.d.ts +16 -9
  336. package/lib/views/settings-list.js +171 -315
  337. package/lib/views/settings-list.js.map +1 -1
  338. package/lib/views/tool-actions.d.ts +16 -0
  339. package/lib/views/tool-actions.js +29 -0
  340. package/lib/views/tool-actions.js.map +1 -0
  341. package/lib/views/trajectory-timeline.d.ts +71 -0
  342. package/lib/views/trajectory-timeline.js +143 -0
  343. package/lib/views/trajectory-timeline.js.map +1 -0
  344. package/lib/views/trajectory.d.ts +36 -4
  345. package/lib/views/trajectory.js +842 -190
  346. package/lib/views/trajectory.js.map +1 -1
  347. package/lib/views/transcript-render.d.ts +132 -38
  348. package/lib/views/transcript-render.js +792 -260
  349. package/lib/views/transcript-render.js.map +1 -1
  350. package/lib/views/transcript-search.d.ts +39 -6
  351. package/lib/views/transcript-search.js +46 -11
  352. package/lib/views/transcript-search.js.map +1 -1
  353. package/lib/views/transcript-types.d.ts +64 -5
  354. package/lib/views/transcript-types.js +23 -11
  355. package/lib/views/transcript-types.js.map +1 -1
  356. package/lib/views/workflow.d.ts +16 -0
  357. package/lib/views/workflow.js +42 -0
  358. package/lib/views/workflow.js.map +1 -0
  359. package/package.json +74 -90
  360. package/lib/chrome/welcome-tips.d.ts +0 -11
  361. package/lib/chrome/welcome-tips.js +0 -44
  362. package/lib/chrome/welcome-tips.js.map +0 -1
  363. package/lib/commands/advisor.d.ts +0 -15
  364. package/lib/commands/advisor.js +0 -200
  365. package/lib/commands/advisor.js.map +0 -1
  366. package/lib/commands/loop.d.ts +0 -52
  367. package/lib/commands/loop.js +0 -307
  368. package/lib/commands/loop.js.map +0 -1
  369. package/lib/commands/rate.d.ts +0 -33
  370. package/lib/commands/rate.js +0 -212
  371. package/lib/commands/rate.js.map +0 -1
  372. package/lib/commands/steer.d.ts +0 -5
  373. package/lib/commands/steer.js +0 -24
  374. package/lib/commands/steer.js.map +0 -1
  375. package/lib/commands/worktree.d.ts +0 -5
  376. package/lib/commands/worktree.js +0 -103
  377. package/lib/commands/worktree.js.map +0 -1
  378. package/lib/runtime/terminal-reader.d.ts +0 -11
  379. package/lib/runtime/terminal-reader.js +0 -87
  380. package/lib/runtime/terminal-reader.js.map +0 -1
  381. package/lib/session/steering.d.ts +0 -3
  382. package/lib/session/steering.js +0 -9
  383. package/lib/session/steering.js.map +0 -1
  384. package/lib/views/agent-hub.d.ts +0 -32
  385. package/lib/views/agent-hub.js +0 -209
  386. package/lib/views/agent-hub.js.map +0 -1
  387. package/lib/views/copy-selector.d.ts +0 -54
  388. package/lib/views/copy-selector.js +0 -170
  389. package/lib/views/copy-selector.js.map +0 -1
@@ -6,16 +6,21 @@
6
6
  * sessions, projections, command routing, and cleanup stay behind one API.
7
7
  * @module @agi-fans/dsh-tui/session-controller
8
8
  */
9
+ import { openGoalControls } from "./goal-controls.js";
10
+ import { continuableFailure } from "./generation-continuation.js";
11
+ import { workflowMemberStatus, workflowOptions } from "../views/workflow.js";
9
12
  import { randomUUID } from 'node:crypto';
10
- import { steerAgent } from "./steering.js";
11
13
  import { openMessageQueue } from "./message-queue.js";
12
14
  import { WorkflowProjection } from "./workflow-projection.js";
13
15
  import { join } from 'node:path';
14
16
  import { createUserMessage, } from '@deepseek-ai/dsh-llm';
15
- import { isUserInvocable } from '@deepseek-ai/dsh-skill';
17
+ import { CommandAttachments, encodeCommandAttachments } from "./command-attachments.js";
18
+ export { encodeCommandAttachments } from "./command-attachments.js";
19
+ import { isModelInvocable, isUserInvocable } from '@deepseek-ai/dsh-skill';
20
+ import { BUILTIN_SLASH_COMMANDS } from "../views/autocomplete.js";
16
21
  import { readColdSessionLog } from '@deepseek-ai/dsh-session-query';
17
22
  import { appendPluginRecord, pluginRecordOf, SessionId, SessionLogOffset } from '@deepseek-ai/dsh-session';
18
- import { queueHostSubagentPrompt } from '@deepseek-ai/dsh-subagent/internal';
23
+ import { queueHostSubagentPrompt, steerHostSubagentPrompt } from '@deepseek-ai/dsh-subagent/internal';
19
24
  import { firstVisibleStreamTime } from "../views/stream-time.js";
20
25
  import { LiveAttemptTracker } from "./live-attempt-tracker.js";
21
26
  import { blocksText } from "./content-text.js";
@@ -33,8 +38,8 @@ import { BTW_PRESET } from "../runtime/btw-policy.js";
33
38
  import { reviewFileRecovery } from "../runtime/file-recovery-review.js";
34
39
  import { isBlankSession, } from "./session-configuration.js";
35
40
  import { stripComposerImageMarkers } from "../input/image-paste.js";
36
- async function setupAgentContext(agentCtx, agent, selection) {
37
- const configured = await configureAgentContext(agentCtx, agent, selection);
41
+ async function setupAgentContext(agentCtx, agent) {
42
+ const configured = await configureAgentContext(agentCtx, agent);
38
43
  await agentCtx.plugin(commandPermission(agent));
39
44
  return configured;
40
45
  }
@@ -45,10 +50,14 @@ function parseControl(line) {
45
50
  return { name: match[1].toLowerCase(), input: match[2]?.trim() ?? '' };
46
51
  }
47
52
  /** Present only the session controls whose owning Harness plugins are composed. */
48
- export function sessionControls(projection) {
53
+ export function sessionControls(projection, livePlan) {
49
54
  const override = projection?.sandboxMode;
55
+ // Host pending is a target value, while the UI projection says whether a
56
+ // change remains. Cancelling a pending change can retain the current target.
57
+ const plan = livePlan === undefined ? projection?.plan
58
+ : { active: livePlan.active, pending: livePlan.pending !== undefined && livePlan.pending !== livePlan.active };
50
59
  return {
51
- ...(projection?.plan === undefined ? {} : { plan: { ...projection.plan } }),
60
+ ...(plan === undefined ? {} : { plan: { ...plan } }),
52
61
  // A logged sandbox override (for example an approved widening) is the mode
53
62
  // actually in force; the preset only describes the user's standing choice.
54
63
  ...(override == null
@@ -286,15 +295,13 @@ function recentSessionStatus(events) {
286
295
  return 'interrupted';
287
296
  }
288
297
  /** Convert the human-visible part of a skill catalog into slash commands. */
289
- export function userSkillCommands(skills) {
290
- return skills.filter(isUserInvocable).map(skill => ({
291
- name: `skill:${skill.name}`,
298
+ export function userSkillCommands(skills, reserved = new Set()) {
299
+ return skills.filter(skill => isUserInvocable(skill) && !reserved.has(skill.name)).map(skill => ({
300
+ name: skill.name,
292
301
  description: compactDescription(skill.description),
302
+ skill: { userOnly: !isModelInvocable(skill) },
293
303
  }));
294
304
  }
295
- function skillNameFromCommand(name) {
296
- return name.startsWith('skill:') ? name.slice('skill:'.length) : name;
297
- }
298
305
  function compactDescription(value, maxLength = 140) {
299
306
  const normalized = value.replace(/\s+/gu, ' ').trim();
300
307
  return normalized.length <= maxLength ? normalized : normalized.slice(0, maxLength - 1).trimEnd() + '…';
@@ -311,24 +318,52 @@ export async function createSubmissionMessage(submission, attachments) {
311
318
  const refs = inputs.length === 0 || attachments === undefined
312
319
  ? []
313
320
  : [...await attachments.saveImages(inputs)];
314
- const content = [
315
- ...(submission.text === '' ? [] : [{ type: 'text', text: submission.text }]),
316
- ...refs.map(attachment => ({ type: 'image', attachment })),
317
- ...(submission.files ?? []).map(attachment => ({ type: 'file', attachment })),
318
- ];
321
+ // A recorded order keeps the picture where the reader put it; without one the
322
+ // message falls back to text followed by its attachments.
323
+ const content = [];
324
+ if (submission.segments === undefined || submission.segments.length === 0) {
325
+ if (submission.text !== '')
326
+ content.push({ type: 'text', text: submission.text });
327
+ for (const attachment of refs)
328
+ content.push({ type: 'image', attachment });
329
+ for (const attachment of submission.files ?? [])
330
+ content.push({ type: 'file', attachment });
331
+ }
332
+ else {
333
+ for (const segment of submission.segments) {
334
+ if (segment.kind === 'text') {
335
+ if (segment.text !== '')
336
+ content.push({ type: 'text', text: segment.text });
337
+ continue;
338
+ }
339
+ if (segment.kind === 'file') {
340
+ const attachment = submission.files?.[segment.index];
341
+ if (attachment !== undefined)
342
+ content.push({ type: 'file', attachment });
343
+ }
344
+ else {
345
+ const attachment = refs[segment.index];
346
+ if (attachment !== undefined)
347
+ content.push({ type: 'image', attachment });
348
+ }
349
+ }
350
+ // An attachment the composer did not mark in the text still belongs to the
351
+ // message: keep it rather than dropping it with the marker.
352
+ const placedImages = new Set(submission.segments.flatMap(segment => segment.kind === 'image' ? [segment.index] : []));
353
+ for (const [index, attachment] of refs.entries()) {
354
+ if (!placedImages.has(index))
355
+ content.push({ type: 'image', attachment });
356
+ }
357
+ const placedFiles = new Set(submission.segments.flatMap(segment => segment.kind === 'file' ? [segment.index] : []));
358
+ for (const [index, attachment] of (submission.files ?? []).entries()) {
359
+ if (!placedFiles.has(index))
360
+ content.push({ type: 'file', attachment });
361
+ }
362
+ }
319
363
  if (content.length === 0)
320
364
  throw new Error('Cannot submit an empty message.');
321
365
  return createUserMessage({ content, source: { kind: 'user' } });
322
366
  }
323
- /** Encode composer drafts for `ctx.commands.execute`. */
324
- export function encodeCommandAttachments(images) {
325
- return images.map(image => ({
326
- type: 'image',
327
- mediaType: image.mediaType,
328
- data: Buffer.from(image.data).toString('base64'),
329
- ...(image.name === undefined ? {} : { name: image.name }),
330
- }));
331
- }
332
367
  /** Rehydrate one durable human inbox message into an editable composer draft. */
333
368
  export async function restoreSubmissionMessage(message, attachments) {
334
369
  const text = blocksText(message.content);
@@ -351,23 +386,51 @@ export async function restoreSubmissionMessage(message, attachments) {
351
386
  };
352
387
  }));
353
388
  const files = message.content.filter((block) => block.type === 'file').map(block => block.attachment);
354
- return { text, images, ...(files.length === 0 ? {} : { files }) };
389
+ let imageIndex = 0, fileIndex = 0;
390
+ const segments = message.content.flatMap(block => {
391
+ if (block.type === 'text')
392
+ return [{ kind: 'text', text: block.text }];
393
+ if (block.type === 'image')
394
+ return [{ kind: 'image', index: imageIndex++ }];
395
+ if (block.type === 'file')
396
+ return [{ kind: 'file', index: fileIndex++ }];
397
+ return [];
398
+ });
399
+ return { text, images, ...(files.length === 0 ? {} : { files }),
400
+ ...(images.length === 0 && files.length === 0 ? {} : { segments }) };
401
+ }
402
+ /** The live selection succeeded, but the profile default still needs saving. */
403
+ export class DefaultModelSaveError extends Error {
404
+ constructor(selection, cause) {
405
+ super(`Session model is now ${selection.provider}/${selection.model}. The default model could not be saved.`, { cause });
406
+ this.name = 'DefaultModelSaveError';
407
+ }
355
408
  }
356
409
  /** Own one switchable top-level Agent and project it onto a TuiService. */
357
410
  export class SessionRuntime {
411
+ #commandAttachments;
358
412
  #workflows = new WorkflowProjection();
359
413
  #ctx;
360
414
  #tui;
361
415
  #active;
362
416
  #recent = [];
363
417
  #archivedSessions = new Set();
364
- #skillCommands = [];
418
+ #skills = [];
419
+ /**
420
+ * Live argument vocabularies, keyed by command.
421
+ *
422
+ * A snapshot rather than a callback into the services: completion runs on every
423
+ * keystroke and must not await a catalog. It is rebuilt whenever the commands
424
+ * are pushed, which is also when a model or provider list can have changed.
425
+ */
426
+ #argumentOptions = new Map();
365
427
  #started = false;
366
428
  #retired = [];
367
429
  // Weak: deduplication must not retain disposed session graphs.
368
430
  #releasedHandles = new WeakSet();
369
431
  #disposed = false;
370
432
  #queueAbort;
433
+ #workflowAbort;
371
434
  #off = [];
372
435
  #tracker;
373
436
  #streamAttempts = new LiveAttemptTracker();
@@ -378,11 +441,21 @@ export class SessionRuntime {
378
441
  #refreshInFlight = null;
379
442
  #refreshDirty = false;
380
443
  #inspectEpoch = 0;
444
+ #inspectDeliveryTail = Promise.resolve();
445
+ #activeInteraction = new AbortController();
446
+ #pendingSends = new Map();
447
+ #inspectDeliveries = new Set();
448
+ #descendantApprovals = new Map();
381
449
  #activationEpoch = 0;
382
450
  #inspectedId;
383
451
  constructor(ctx, tui, options = {}) {
384
452
  this.#ctx = ctx;
385
453
  this.#tui = tui;
454
+ const commands = ctx.get('commands');
455
+ if (commands !== undefined) {
456
+ this.#commandAttachments = new CommandAttachments(commands);
457
+ this.#off.push(() => this.#commandAttachments?.dispose());
458
+ }
386
459
  this.#libraryPath = sessionLibraryPath(options.stateDir);
387
460
  this.#recentRowsPath = options.stateDir === undefined ? undefined : join(options.stateDir, 'recent-sessions.json');
388
461
  this.#tracker = new SubagentTracker({
@@ -401,9 +474,24 @@ export class SessionRuntime {
401
474
  this.#tui.setInspectedSubagent(this.#inspectView(this.#inspectedId));
402
475
  },
403
476
  });
404
- this.#off.push(tui.setSteerHandler(text => { steerAgent(this.agent, text); }));
477
+ const offGoal = tui.setGoalHandler?.(signal => openGoalControls(ctx, tui, this.#requiredAgent(), AbortSignal.any([signal, this.interactionSignal])));
478
+ if (offGoal !== undefined)
479
+ this.#off.push(offGoal);
405
480
  this.#off.push(tui.setQueueHandler(signal => this.openQueue(signal)));
481
+ const offContinue = tui.setContinueHandler?.(async (request) => {
482
+ const agent = this.#requiredAgent();
483
+ if (agent.id !== request.sessionId)
484
+ throw new Error('The continuation belongs to another session.');
485
+ await this.continueGeneration(agent, request.failureSeq);
486
+ });
487
+ if (offContinue !== undefined)
488
+ this.#off.push(offContinue);
406
489
  this.#off.push(tui.onInspectSubagent(id => { void this.#inspectSubagent(id); }));
490
+ const offWorkflow = tui.onInspectWorkflow?.(id => {
491
+ void this.openWorkflow(id).catch(error => { this.#tui.notice(error instanceof Error ? error.message : String(error), { level: 'error' }); });
492
+ });
493
+ if (offWorkflow !== undefined)
494
+ this.#off.push(offWorkflow);
407
495
  this.#off.push(tui.onInspectClose(() => { this.#closeInspect(); }));
408
496
  this.#off.push(tui.onInspectSubmit(submission => { void this.#steerInspected(submission); }));
409
497
  tui.setSessionSearch(async (query, signal) => {
@@ -454,6 +542,7 @@ export class SessionRuntime {
454
542
  this.#off.push(ctx.on('agent/status', (payload) => {
455
543
  if (payload.agent === this.#active?.handle.agent) {
456
544
  tui.setStatus(payload.status, { root: true });
545
+ this.#pushSessionInfo();
457
546
  return;
458
547
  }
459
548
  if (payload.agent.id === this.#inspectedId)
@@ -525,6 +614,10 @@ export class SessionRuntime {
525
614
  if (delta !== undefined)
526
615
  this.#forwardLiveDelta(payload.agent, delta);
527
616
  }, { global: true }));
617
+ this.#off.push(ctx.on('goal/activation-changed', payload => {
618
+ if (payload.sessionId === this.#active?.handle.agent.session.id)
619
+ this.#pushSessionInfo();
620
+ }));
528
621
  if (ctx.get('commands') !== undefined) {
529
622
  this.#off.push(ctx.on('commands/change', () => { this.#pushCommands(); }));
530
623
  }
@@ -550,6 +643,8 @@ export class SessionRuntime {
550
643
  }));
551
644
  }
552
645
  }
646
+ /** Presentation requests from a replaced root must not survive into its successor. */
647
+ get interactionSignal() { return this.#activeInteraction.signal; }
553
648
  get agent() {
554
649
  return this.#active?.handle.agent;
555
650
  }
@@ -562,10 +657,48 @@ export class SessionRuntime {
562
657
  return false;
563
658
  const root = this.#active?.handle.agent;
564
659
  if (root !== undefined) {
565
- this.#ctx.get('subagents')?.interrupt(SessionId(this.#inspectedId), { kind: 'ancestor', agent: root });
660
+ try {
661
+ this.#ctx.get('subagents')?.interrupt(SessionId(this.#inspectedId), { kind: 'ancestor', agent: root });
662
+ }
663
+ catch (error) {
664
+ this.#tui.notice(error instanceof Error ? error.message : String(error), { level: 'error' });
665
+ }
666
+ }
667
+ return true;
668
+ }
669
+ #isOwnedDescendant(agent, root) {
670
+ const agents = this.#ctx.get('agents');
671
+ if (agents?.get(agent.id) !== agent
672
+ || descendantDepth(agent.session, root.id, this.#lookupSession) === undefined)
673
+ return false;
674
+ // Durable lineage alone also matches an independently resumed runtime root.
675
+ let child = agent;
676
+ while (child !== root) {
677
+ const parentId = child.session.header.parentSession;
678
+ const parent = parentId === undefined ? undefined : agents.get(parentId);
679
+ if (parent === undefined || !agents.isOwnedBy(child.id, parent))
680
+ return false;
681
+ child = parent;
566
682
  }
567
683
  return true;
568
684
  }
685
+ /** Accept only live descendants of the active root for shared approval prompts. */
686
+ beginSubagentApproval(agent) {
687
+ const root = this.agent;
688
+ if (root === undefined || !this.#isOwnedDescendant(agent, root))
689
+ return undefined;
690
+ this.#tracker.noteSession(agent.session);
691
+ const abort = new AbortController();
692
+ this.#descendantApprovals.set(abort, root);
693
+ const finish = this.#tracker.beginApprovalRequest(agent.id);
694
+ const off = this.#ctx.on('agent/disposed', event => { if (event.agent === agent)
695
+ abort.abort(); });
696
+ return { label: this.#inspectView(agent.id).label, signal: abort.signal, finish: () => {
697
+ off();
698
+ this.#descendantApprovals.delete(abort);
699
+ finish();
700
+ } };
701
+ }
569
702
  async start() {
570
703
  if (this.#started)
571
704
  return;
@@ -576,77 +709,266 @@ export class SessionRuntime {
576
709
  await this.refreshRecent();
577
710
  await this.#activate(await this.#create(defaults), 'initial');
578
711
  }
579
- /** Submit one human composer value; active turns retain it as a later follow-up. */
712
+ /** Admit a complete composer value through the selected Harness inbox entry. */
580
713
  async send(input, agent = this.#requiredAgent()) {
581
- this.assertActive(agent);
582
714
  const submission = typeof input === 'string' ? { text: input, images: [] } : input;
583
- const message = await createSubmissionMessage(submission, this.#ctx.get('attachments'));
584
- this.assertActive(agent);
585
- agent.followup(message);
715
+ await this.#sendSubmission(submission, agent);
716
+ }
717
+ async #sendSubmission(submission, agent, signal) {
718
+ const assertDelivery = () => {
719
+ signal?.throwIfAborted();
720
+ this.assertActive(agent);
721
+ if (submission.delivery === 'steer' && agent.status !== 'running') {
722
+ throw new Error('Steering needs an active turn. Use Enter to send the next message.');
723
+ }
724
+ };
725
+ assertDelivery();
726
+ this.#pendingSends.set(agent, (this.#pendingSends.get(agent) ?? 0) + 1);
727
+ try {
728
+ const message = await createSubmissionMessage(submission, this.#ctx.get('attachments'));
729
+ assertDelivery();
730
+ this.#tui.pendingInputs?.prepare?.(submission, message.id);
731
+ this.#admit(agent, message, submission.delivery);
732
+ }
733
+ finally {
734
+ const remaining = (this.#pendingSends.get(agent) ?? 1) - 1;
735
+ if (remaining === 0)
736
+ this.#pendingSends.delete(agent);
737
+ else
738
+ this.#pendingSends.set(agent, remaining);
739
+ }
586
740
  }
587
- async openQueue(signal, agent = this.#requiredAgent()) {
741
+ #admit(agent, message, delivery) {
742
+ const offset = agent.session.snapshotEvents().length;
743
+ try {
744
+ if (delivery === 'steer')
745
+ agent.steer(message);
746
+ else
747
+ agent.followup(message);
748
+ }
749
+ catch (error) {
750
+ // An event subscriber may throw after admission, even after the message was claimed.
751
+ // Only a pre-admission failure may return the submission to the composer.
752
+ const accepted = agent.session.snapshotEvents().slice(offset).some(event => event.type === 'agent/inbox/spliced' && event.data.inserted.some(item => item.id === message.id));
753
+ if (!accepted)
754
+ throw error;
755
+ this.#tui.notice(error instanceof Error ? error.message : String(error), { level: 'error' });
756
+ }
757
+ }
758
+ #assertCanRepeat(agent, signal) {
759
+ signal?.throwIfAborted();
588
760
  this.assertActive(agent);
589
761
  if (this.#inspectedId !== undefined)
590
- throw new Error('Return to the parent session to manage queued messages.');
591
- if (this.#queueAbort !== undefined)
762
+ throw new Error('Return to the parent session to continue or resend a prompt.');
763
+ if (agent.status !== 'idle' || this.#pendingSends.has(agent))
764
+ throw new Error('Wait for the current work to finish before continuing or resending.');
765
+ if (agent.inbox.nextTurn.length > 0 || agent.inbox.nextStep.some(message => message.source.kind === 'user')
766
+ || (this.#tui.pendingInputs?.list().length ?? 0) > 0)
767
+ throw new Error('Resolve pending input in /queue before continuing or resending.');
768
+ if (this.#descendantApprovals.size > 0 || this.#ctx.get('sessionProjections')?.snapshot(agent.session).values.userQuestions?.active.some(question => question.state !== 'continued')) {
769
+ throw new Error('Answer the pending question or approval before continuing or resending.');
770
+ }
771
+ }
772
+ /** Wake an eligible failed generation with empty retry input; never duplicate the original prompt. */
773
+ async continueGeneration(agent = this.#requiredAgent(), expectedFailure, signal) {
774
+ this.#assertCanRepeat(agent, signal);
775
+ await agent.runMaintenance(async (maintenance) => {
776
+ maintenance.throwIfAborted();
777
+ this.#assertCanRepeat(agent, signal);
778
+ const failure = continuableFailure(agent.session.snapshotEvents());
779
+ if (failure === undefined || expectedFailure !== undefined && expectedFailure !== failure) {
780
+ throw new Error('No recoverable model failure is available to continue. Use /retry to resend the last prompt.');
781
+ }
782
+ this.#admit(agent, createUserMessage({ content: [], source: { kind: 'retry' } }));
783
+ });
784
+ }
785
+ /** Explicitly resend the complete latest human message with a fresh Harness identity. */
786
+ async retryLastPrompt(agent = this.#requiredAgent(), signal) {
787
+ this.#assertCanRepeat(agent, signal);
788
+ return agent.runMaintenance(async (maintenance) => {
789
+ maintenance.throwIfAborted();
790
+ this.#assertCanRepeat(agent, signal);
791
+ const previous = agent.session.snapshotEvents().findLast(event => event.type === 'user/message'
792
+ && event.data.source.kind === 'user' && event.data.content.length > 0);
793
+ if (previous?.type !== 'user/message')
794
+ return false;
795
+ this.#admit(agent, createUserMessage({ content: previous.data.content, source: { kind: 'user' } }));
796
+ return true;
797
+ });
798
+ }
799
+ /** Resolve one visible live inbox, retaining its identity across asynchronous UI work. */
800
+ #queueTarget() {
801
+ const root = this.#requiredAgent();
802
+ const inspectedId = this.#inspectedId;
803
+ if (inspectedId !== undefined && !this.#inspectView(inspectedId).writable)
804
+ throw new Error('This subagent is read-only.');
805
+ const agent = inspectedId === undefined ? root : this.#ctx.get('agents')?.get(SessionId(inspectedId));
806
+ if (agent === undefined)
807
+ throw new Error('This subagent is not loaded locally. Send it a message to continue before managing its queue.');
808
+ const check = () => {
809
+ this.assertActive(root);
810
+ if (this.#inspectedId !== inspectedId || inspectedId !== undefined && !this.#isOwnedDescendant(agent, root)) {
811
+ throw new Error('The queue session is no longer active.');
812
+ }
813
+ };
814
+ check();
815
+ return { agent, check, ...(inspectedId === undefined ? {} : { label: this.#inspectView(inspectedId).label }) };
816
+ }
817
+ async openQueue(signal, requestingAgent) {
818
+ if (requestingAgent !== undefined)
819
+ this.assertActive(requestingAgent);
820
+ const target = this.#queueTarget();
821
+ const { agent } = target;
822
+ if (this.#queueAbort !== undefined && !this.#queueAbort.signal.aborted)
592
823
  throw new Error('Message Queue is already open.');
824
+ // Validate recall state before opening; child views must never list parent delivery entries.
825
+ this.#tui.pendingInputs.list();
593
826
  const abort = new AbortController();
594
827
  this.#queueAbort = abort;
595
828
  const onAbort = () => { abort.abort(signal.reason); };
596
829
  signal.addEventListener('abort', onAbort, { once: true });
597
830
  if (signal.aborted)
598
831
  onAbort();
832
+ const off = this.#ctx.on('agent/disposed', event => { if (event.agent === agent)
833
+ abort.abort(); });
599
834
  try {
600
- await openMessageQueue({ agent, tui: this.#tui, signal: abort.signal, assertActive: () => { this.assertActive(agent); },
835
+ await openMessageQueue({ agent, signal: abort.signal, assertActive: target.check,
836
+ ...(target.label === undefined ? {} : { ownerLabel: target.label }),
837
+ tui: {
838
+ prompt: request => this.#tui.prompt(request), notice: (text, options) => this.#tui.notice(text, options),
839
+ restoreInput: submission => this.#tui.restoreInput(submission, agent.id),
840
+ pendingInputs: target.label === undefined ? this.#tui.pendingInputs : { list: () => [], update: () => false },
841
+ },
601
842
  restore: message => restoreSubmissionMessage(message, this.#ctx.get('attachments')) });
602
843
  }
844
+ catch (error) {
845
+ if (!abort.signal.aborted)
846
+ throw error;
847
+ }
603
848
  finally {
849
+ off();
604
850
  signal.removeEventListener('abort', onAbort);
605
851
  if (this.#queueAbort === abort)
606
852
  this.#queueAbort = undefined;
607
853
  }
608
854
  }
609
- /** Remove and rehydrate the newest durable human follow-up for queue browsing. */
610
- async editLatestFollowup(agent = this.#requiredAgent()) {
611
- this.assertActive(agent);
855
+ /** Inspect durable membership; only a currently running, owned local member can be opened. */
856
+ async openWorkflow(id) {
857
+ const root = this.#requiredAgent();
858
+ const inspectedId = this.#inspectedId;
859
+ this.#workflowAbort?.abort();
860
+ const abort = new AbortController();
861
+ this.#workflowAbort = abort;
862
+ const check = () => {
863
+ abort.signal.throwIfAborted();
864
+ this.assertActive(root);
865
+ if (this.#inspectedId !== inspectedId)
866
+ throw new Error('The workflow session is no longer active.');
867
+ };
868
+ const canOpen = (run, member) => {
869
+ const child = this.#ctx.get('agents')?.get(SessionId(member.childId));
870
+ return workflowMemberStatus(run, member) === 'open' && child?.status === 'running'
871
+ && child.session.header.parentSession === root.id && this.#isOwnedDescendant(child, root) && this.#tracker.owns(child.id);
872
+ };
873
+ try {
874
+ let lastRun;
875
+ let lastOpen = '';
876
+ let options = [];
877
+ const refresh = () => {
878
+ check();
879
+ const run = this.#workflows.get(id);
880
+ if (run === undefined)
881
+ throw new Error('This workflow is no longer available.');
882
+ const open = run.members.filter(member => canOpen(run, member)).map(member => member.seq).join(',');
883
+ if (run !== lastRun || open !== lastOpen) {
884
+ options = workflowOptions(run, member => canOpen(run, member));
885
+ lastRun = run;
886
+ lastOpen = open;
887
+ }
888
+ return options;
889
+ };
890
+ let selected;
891
+ while (!abort.signal.aborted) {
892
+ const answer = await this.#tui.prompt({ title: 'Workflow',
893
+ question: 'Browse phases and members. Only running local members can be opened.',
894
+ localize: ['title', 'question'], notify: false, options: refresh(), refreshOptions: refresh,
895
+ presentation: 'tree', filterable: true, allowCustom: false, submitLabel: 'open',
896
+ emptyText: 'No matching workflow members.', signal: abort.signal,
897
+ ...(selected === undefined ? {} : { initialValue: selected }) });
898
+ if (answer === null)
899
+ return;
900
+ check();
901
+ selected = answer;
902
+ const run = this.#workflows.get(id);
903
+ const member = run?.members.find(member => `member:${member.seq}` === answer);
904
+ if (run === undefined || member === undefined || !canOpen(run, member)) {
905
+ this.#tui.notice('This workflow member is no longer available to open.');
906
+ continue;
907
+ }
908
+ await this.#inspectSubagent(member.childId);
909
+ return;
910
+ }
911
+ }
912
+ catch (error) {
913
+ if (!abort.signal.aborted)
914
+ throw error;
915
+ }
916
+ finally {
917
+ if (this.#workflowAbort === abort)
918
+ this.#workflowAbort = undefined;
919
+ }
920
+ }
921
+ /** Rehydrate before withdrawing so navigation or missing attachments leave the inbox intact. */
922
+ async editLatestFollowup(request) {
923
+ request?.signal.throwIfAborted();
924
+ const target = this.#queueTarget();
925
+ const { agent } = target;
926
+ if (request?.sessionId !== undefined && request.sessionId !== agent.id)
927
+ throw new Error('The queue session is no longer active.');
612
928
  const message = agent.inbox.nextTurn.findLast(candidate => candidate.source.kind === 'user');
613
929
  if (message === undefined)
614
930
  return undefined;
615
931
  const submission = await restoreSubmissionMessage(message, this.#ctx.get('attachments'));
616
- this.assertActive(agent);
617
- return agent.inbox.remove(message.id) ? { ...submission, literal: true } : undefined;
932
+ request?.signal.throwIfAborted();
933
+ target.check();
934
+ return agent.inbox.remove(message.id) ? { ...submission, literal: true, delivery: 'queue' } : undefined;
618
935
  }
619
936
  /** Execute a plugin-owned slash command, falling back to user-invocable skills. */
620
- async execute(line, signal, images = []) {
937
+ async execute(input, signal, images = []) {
938
+ const submission = typeof input === 'string' ? { text: input, images } : input;
939
+ const { text: line } = submission;
940
+ images = submission.images;
621
941
  const commandLine = stripComposerImageMarkers(line, images);
622
942
  const parsed = parseControl(commandLine);
623
943
  if (parsed === undefined)
624
944
  return false;
625
945
  const commands = this.#ctx.get('commands');
946
+ const agent = this.#requiredAgent();
947
+ const staged = this.#commandAttachments?.stage(agent, submission);
626
948
  const execution = await (async () => {
627
949
  try {
628
- return await commands?.execute(this.#requiredAgent(), commandLine, encodeCommandAttachments(images), signal);
950
+ return await commands?.execute(agent, commandLine, staged?.attachments ?? encodeCommandAttachments(images), signal);
629
951
  }
630
952
  finally {
953
+ staged?.dispose();
631
954
  await this.#disposeRetired();
632
955
  }
633
956
  })();
634
957
  if (execution === undefined) {
635
- const skill = await this.#findUserSkill(skillNameFromCommand(parsed.name), signal);
958
+ const skill = await this.#findUserSkill(parsed.name, signal);
959
+ signal.throwIfAborted();
960
+ this.assertActive(agent);
636
961
  if (skill === undefined)
637
962
  return false;
638
- if (images.length > 0) {
639
- this.#tui.restoreInput({ text: line, images });
640
- this.#tui.notice(`/${parsed.name} does not accept image attachments`, { level: 'error' });
641
- return true;
642
- }
643
- await this.send('/' + skill.name + (parsed.input === '' ? '' : ' ' + parsed.input));
963
+ await this.#sendSubmission(submission, agent, signal);
644
964
  return true;
645
965
  }
646
966
  const result = execution.result;
647
- if (result.kind === 'error' && images.length > 0)
648
- this.#tui.restoreInput({ text: line, images });
649
- if (result.text !== undefined) {
967
+ if (result.kind === 'error' && (images.length > 0 || submission.files?.length))
968
+ this.#tui.restoreInput(submission, agent.session.id);
969
+ const presented = result.kind === 'success' && result.sourceEventSeq !== undefined
970
+ && agent.session.snapshotEvents().some(event => event.seq === result.sourceEventSeq && event.type === 'compaction/summary');
971
+ if (result.text !== undefined && !presented) {
650
972
  if (result.kind === 'error')
651
973
  this.#tui.notice(result.text, { level: 'error', focus: true });
652
974
  else
@@ -665,10 +987,10 @@ export class SessionRuntime {
665
987
  get recentSessions() {
666
988
  return this.#recent;
667
989
  }
668
- /** Current model selection for the active Agent. */
990
+ /** Current model selection for the active Agent, read from its durable projection. */
669
991
  selection(agent = this.#requiredAgent()) {
670
992
  this.assertActive(agent);
671
- const current = this.#requiredActive().selection.current;
993
+ const current = agent.model.current();
672
994
  if (current === undefined)
673
995
  throw new Error('active agent has no model selection');
674
996
  return current;
@@ -677,34 +999,42 @@ export class SessionRuntime {
677
999
  async changeSelection(agent, selection, info, options) {
678
1000
  this.assertActive(agent);
679
1001
  const active = this.#requiredActive();
680
- active.selection.current = selection;
681
1002
  const resolved = info ?? await this.#resolveModelInfo(selection);
1003
+ this.assertActive(agent);
1004
+ const current = agent.model.current();
1005
+ if (current?.provider !== selection.provider || current.model !== selection.model || current.reasoningEffort !== selection.reasoningEffort) {
1006
+ agent.model.select(selection);
1007
+ }
682
1008
  active.contextWindow = resolved?.context?.contextWindow;
683
1009
  const status = modelStatus(selection, resolved);
684
1010
  active.reasoningEffort = status.reasoningEffort;
685
- if (options?.persist !== false) {
686
- await this.#ctx.get('agentDefaultModel')?.saveSelection(selection);
687
- }
688
1011
  this.#tui.setModel(status.model, status.reasoningEffort);
689
1012
  this.#pushSessionInfo();
1013
+ if (options?.persist !== false) {
1014
+ try {
1015
+ await this.#ctx.get('agentDefaultModel')?.saveSelection(selection);
1016
+ }
1017
+ catch (error) {
1018
+ throw new DefaultModelSaveError(selection, error);
1019
+ }
1020
+ }
690
1021
  }
691
1022
  /** Start a new top-level session with the current model selection. */
692
- async newSession(agent) {
1023
+ async newSession(agent, presetId) {
693
1024
  this.assertActive(agent);
694
- await this.#activate(await this.#create(this.selection(agent)), 'new');
1025
+ await this.#activate(await this.#create(this.selection(agent), presetId), 'new');
695
1026
  await this.refreshRecent();
696
1027
  }
697
1028
  /** Replace the active top-level session with one durable session. */
698
1029
  async resumeSession(agent, id, signal) {
699
1030
  this.assertActive(agent);
700
1031
  const selection = this.selection(agent);
701
- const ref = { current: selection, assembled: undefined };
702
1032
  let configured;
703
1033
  const handle = await this.#ctx.agents.resume({
704
1034
  resumeSessionId: SessionId(id),
705
1035
  agentOptions: { provider: selection.provider, model: selection.model },
706
1036
  signal,
707
- setup: async (agentCtx, agent) => { configured = await setupAgentContext(agentCtx, agent, ref); },
1037
+ setup: async (agentCtx, agent) => { configured = await setupAgentContext(agentCtx, agent); },
708
1038
  });
709
1039
  const configuration = configured;
710
1040
  if (configuration === undefined) {
@@ -713,7 +1043,6 @@ export class SessionRuntime {
713
1043
  }
714
1044
  await this.#activate({
715
1045
  handle,
716
- selection: ref,
717
1046
  contextWindow: undefined,
718
1047
  reasoningEffort: undefined,
719
1048
  agentPreset: configuration.agentPreset,
@@ -729,12 +1058,11 @@ export class SessionRuntime {
729
1058
  return;
730
1059
  }
731
1060
  const selection = this.selection(agent);
732
- const ref = { current: selection, assembled: undefined };
733
1061
  const handle = await this.#ctx.agents.resume({
734
1062
  resumeSessionId: SessionId(id),
735
1063
  agentOptions: { provider: selection.provider, model: selection.model },
736
1064
  signal,
737
- setup: async (agentCtx, agent) => { await setupAgentContext(agentCtx, agent, ref); },
1065
+ setup: async (agentCtx, agent) => { await setupAgentContext(agentCtx, agent); },
738
1066
  });
739
1067
  try {
740
1068
  this.#ctx.sessionTitle.rename(handle.agent.session, title);
@@ -803,7 +1131,7 @@ export class SessionRuntime {
803
1131
  return {
804
1132
  label: label === undefined ? node.label : `◆ ${label} · ${node.label}`,
805
1133
  value: node.id, ...(node.parentId === undefined ? {} : { parentValue: node.parentId }),
806
- preview: node.preview, description: node.description,
1134
+ preview: node.preview, previewFormat: node.previewFormat, description: node.description,
807
1135
  submitLabel: node.kind === 'turn' ? 'edit from here' : 'continue branch',
808
1136
  ...(node.current ? { badge: { label: 'Current', tone: 'success' } } : {}),
809
1137
  };
@@ -815,7 +1143,7 @@ export class SessionRuntime {
815
1143
  { key: 'Alt+B', label: markedOnly ? 'full tree' : 'marked nodes', valuePrefix: 'marked:', scope: 'list' },
816
1144
  ...(this.#ctx.get('omdshFileRecovery') === undefined ? [] : [{ key: 'Alt+R', label: 'restore Turn files', valuePrefix: 'restore:' }]),
817
1145
  ],
818
- ...(selectedId === undefined ? {} : { initialValue: selectedId }), presentation: 'fullscreen-tree', filterable: true, allowCustom: false, signal,
1146
+ ...(selectedId === undefined ? {} : { initialValue: selectedId }), presentation: 'tree', filterable: true, allowCustom: false, signal,
819
1147
  });
820
1148
  if (answer === null)
821
1149
  return;
@@ -855,7 +1183,7 @@ export class SessionRuntime {
855
1183
  const label = await this.#tui.prompt({
856
1184
  title: 'Label Conversation Node', question: `Label for ${node.label}`,
857
1185
  initialInput: draft, detail: error ?? 'Up to 120 characters. Alt+U in the tree clears a label.',
858
- allowCustom: true, notify: false, signal,
1186
+ signal,
859
1187
  });
860
1188
  if (label === null)
861
1189
  break;
@@ -921,7 +1249,6 @@ export class SessionRuntime {
921
1249
  }));
922
1250
  this.assertActive(agent);
923
1251
  const selection = this.selection(agent);
924
- const ref = { current: selection, assembled: undefined };
925
1252
  const active = this.#requiredActive();
926
1253
  let configured;
927
1254
  const handle = await this.#ctx.agents.create({
@@ -936,7 +1263,7 @@ export class SessionRuntime {
936
1263
  inheritedEventCount: SessionLogOffset(selected.branchIndex),
937
1264
  agentOptions: { provider: selection.provider, model: selection.model },
938
1265
  signal,
939
- setup: async (agentCtx, agent) => { configured = await setupAgentContext(agentCtx, agent, ref); },
1266
+ setup: async (agentCtx, agent) => { configured = await setupAgentContext(agentCtx, agent); },
940
1267
  });
941
1268
  try {
942
1269
  this.assertActive(agent);
@@ -952,7 +1279,6 @@ export class SessionRuntime {
952
1279
  }
953
1280
  await this.#activate({
954
1281
  handle,
955
- selection: ref,
956
1282
  contextWindow: undefined,
957
1283
  reasoningEffort: undefined,
958
1284
  agentPreset: configuration.agentPreset,
@@ -1057,6 +1383,38 @@ export class SessionRuntime {
1057
1383
  }
1058
1384
  });
1059
1385
  }
1386
+ /**
1387
+ * Rebuild the argument vocabularies the composer completes.
1388
+ *
1389
+ * A snapshot, because completion runs per keystroke: `/model provider/model`,
1390
+ * `/resume <id>` and `/login <provider>` are all names that already exist in
1391
+ * this process, so the reader types toward them instead of opening a picker.
1392
+ */
1393
+ async #refreshArgumentOptions() {
1394
+ const options = new Map();
1395
+ const llm = this.#ctx.get('llm');
1396
+ if (llm !== undefined) {
1397
+ const models = [];
1398
+ const providers = [];
1399
+ for (const provider of llm.listProviders()) {
1400
+ providers.push({ value: provider.id, ...(provider.name === undefined ? {} : { description: provider.name }) });
1401
+ for (const model of await llm.listModels(provider.id)) {
1402
+ models.push({
1403
+ value: `${provider.id}/${model.id}`,
1404
+ ...(model.name === undefined ? {} : { description: model.name }),
1405
+ });
1406
+ }
1407
+ }
1408
+ options.set('model', models);
1409
+ options.set('login', providers);
1410
+ }
1411
+ options.set('resume', this.#recent.map(row => ({
1412
+ value: row.id,
1413
+ ...(row.title === undefined ? {} : { description: row.title }),
1414
+ })));
1415
+ this.#argumentOptions = options;
1416
+ this.#pushCommands();
1417
+ }
1060
1418
  async refreshRecent() {
1061
1419
  // Coalesce concurrent callers: the recent list is one snapshot, and a
1062
1420
  // burst of title/status events must not queue a read of every stored log.
@@ -1079,6 +1437,9 @@ export class SessionRuntime {
1079
1437
  }
1080
1438
  async #refreshRecentNow() {
1081
1439
  this.#archivedSessions = new Set(readSessionLibrary(this.#libraryPath).archived);
1440
+ // The recent list is what `/resume` completes from, so a refresh of one is a
1441
+ // refresh of the other. Deferred to avoid recursing through #pushCommands.
1442
+ queueMicrotask(() => { void this.#refreshArgumentOptions().catch(() => { }); });
1082
1443
  const persistence = this.#ctx.get('sessionPersistence');
1083
1444
  if (persistence === undefined) {
1084
1445
  this.#recent = [];
@@ -1150,10 +1511,15 @@ export class SessionRuntime {
1150
1511
  }
1151
1512
  async dispose() {
1152
1513
  this.#queueAbort?.abort(new Error('session runtime disposed'));
1514
+ this.#workflowAbort?.abort();
1515
+ for (const abort of this.#descendantApprovals.keys())
1516
+ abort.abort();
1153
1517
  if (this.#disposed)
1154
1518
  return;
1155
1519
  this.#disposed = true;
1520
+ this.#activeInteraction.abort();
1156
1521
  this.#activationEpoch += 1;
1522
+ this.#cancelInspectDeliveries();
1157
1523
  this.#inspectedId = undefined;
1158
1524
  this.#tracker.reset();
1159
1525
  this.#tui.setInspectedSubagent(undefined);
@@ -1173,15 +1539,14 @@ export class SessionRuntime {
1173
1539
  this.#releasedHandles.add(handle);
1174
1540
  await this.#disposeHandles(handles);
1175
1541
  }
1176
- async #create(selection) {
1177
- const ref = { current: selection, assembled: undefined };
1178
- const preset = await this.#ctx.agentPresets.resolve();
1542
+ async #create(selection, presetId) {
1543
+ const preset = await this.#ctx.agentPresets.resolve(presetId);
1179
1544
  let configured;
1180
1545
  const handle = await this.#ctx.agents.create({
1181
1546
  sessionId: SessionId('session-' + randomUUID()),
1182
1547
  meta: { cwd: process.cwd(), agentPreset: preset.id },
1183
1548
  agentOptions: { provider: selection.provider, model: selection.model },
1184
- setup: async (agentCtx, agent) => { configured = await setupAgentContext(agentCtx, agent, ref); },
1549
+ setup: async (agentCtx, agent) => { configured = await setupAgentContext(agentCtx, agent); },
1185
1550
  });
1186
1551
  const configuration = configured;
1187
1552
  if (configuration === undefined) {
@@ -1190,7 +1555,6 @@ export class SessionRuntime {
1190
1555
  }
1191
1556
  return {
1192
1557
  handle,
1193
- selection: ref,
1194
1558
  contextWindow: undefined,
1195
1559
  reasoningEffort: undefined,
1196
1560
  agentPreset: configuration.agentPreset,
@@ -1235,6 +1599,9 @@ export class SessionRuntime {
1235
1599
  const previous = this.#active;
1236
1600
  const epoch = ++this.#activationEpoch;
1237
1601
  this.#queueAbort?.abort(new Error('active session changed'));
1602
+ this.#workflowAbort?.abort();
1603
+ this.#activeInteraction.abort();
1604
+ this.#activeInteraction = new AbortController();
1238
1605
  this.#active = next;
1239
1606
  void this.#claimWorkspace(next);
1240
1607
  try {
@@ -1268,6 +1635,8 @@ export class SessionRuntime {
1268
1635
  // and the activation failure remains the actionable error.
1269
1636
  try {
1270
1637
  if (this.#activationEpoch === epoch) {
1638
+ this.#activeInteraction.abort();
1639
+ this.#activeInteraction = new AbortController();
1271
1640
  this.#active = previous;
1272
1641
  if (previous !== undefined) {
1273
1642
  try {
@@ -1300,8 +1669,12 @@ export class SessionRuntime {
1300
1669
  }
1301
1670
  /** Show one active session on the terminal: transcript, tools, controls, model. */
1302
1671
  #presentAgent(active, reason = 'open') {
1672
+ for (const [abort, root] of this.#descendantApprovals)
1673
+ if (root !== active.handle.agent)
1674
+ abort.abort();
1303
1675
  this.#workflows.reset(active.handle.agent.session.snapshotEvents());
1304
1676
  const agent = active.handle.agent;
1677
+ this.#cancelInspectDeliveries();
1305
1678
  this.#inspectedId = undefined;
1306
1679
  this.#tui.setInspectedSubagent(undefined);
1307
1680
  this.#tui.setStatus(agent.status);
@@ -1331,13 +1704,18 @@ export class SessionRuntime {
1331
1704
  #pushCommands() {
1332
1705
  const agent = this.agent;
1333
1706
  const runtime = agent === undefined ? [] : (this.#ctx.get('commands')?.list(agent) ?? []);
1334
- const commands = runtime.map(command => ({
1335
- name: command.name,
1336
- description: command.description,
1337
- ...(command.input?.hint === undefined ? {} : { inputHint: command.input.hint }),
1338
- }));
1339
- const names = new Set(commands.map(command => command.name));
1340
- for (const skill of this.#skillCommands) {
1707
+ const commands = runtime.map(command => {
1708
+ const options = this.#argumentOptions.get(command.name);
1709
+ return {
1710
+ name: command.name,
1711
+ description: command.description,
1712
+ ...(command.input?.hint === undefined ? {} : { inputHint: command.input.hint }),
1713
+ ...(options === undefined ? {} : { complete: (prefix) => matchArgumentOptions(options, prefix) }),
1714
+ };
1715
+ });
1716
+ const names = new Set([...commands.map(command => command.name),
1717
+ ...BUILTIN_SLASH_COMMANDS.flatMap(command => [command.name, ...(command.aliases ?? [])])]);
1718
+ for (const skill of userSkillCommands(this.#skills, names)) {
1341
1719
  if (names.has(skill.name))
1342
1720
  continue;
1343
1721
  commands.push(skill);
@@ -1359,14 +1737,14 @@ export class SessionRuntime {
1359
1737
  const agent = this.agent;
1360
1738
  const skills = this.#ctx.get('skills');
1361
1739
  if (agent === undefined || skills === undefined) {
1362
- this.#skillCommands = [];
1740
+ this.#skills = [];
1363
1741
  }
1364
1742
  else {
1365
1743
  const cwd = currentWorkingDirectory(this.#ctx, agent.session);
1366
1744
  const list = await skills.list({ cwd, scope: agent, signal });
1367
1745
  if (this.#disposed || this.agent !== agent || currentWorkingDirectory(this.#ctx, agent.session) !== cwd)
1368
1746
  return;
1369
- this.#skillCommands = userSkillCommands(list);
1747
+ this.#skills = list;
1370
1748
  }
1371
1749
  this.#pushCommands();
1372
1750
  }
@@ -1413,6 +1791,7 @@ export class SessionRuntime {
1413
1791
  id,
1414
1792
  label: view?.label ?? id,
1415
1793
  phase: view?.phase ?? fallbackPhase,
1794
+ needsApproval: view?.needsApproval === true,
1416
1795
  ...(mode === undefined ? {} : { mode }),
1417
1796
  writable: isSteerableSubagent(mode),
1418
1797
  };
@@ -1438,6 +1817,7 @@ export class SessionRuntime {
1438
1817
  #replaceTranscript(agent, reason = 'refresh') {
1439
1818
  this.#tui.setWorkingDirectory?.(currentWorkingDirectory(this.#ctx, agent.session));
1440
1819
  const events = agent.session.snapshotEvents();
1820
+ this.#tui.pendingInputs?.reconcile?.(agent.id, new Set(events.flatMap(event => event.type === 'agent/inbox/spliced' ? event.data.inserted.map(message => message.id) : [])));
1441
1821
  this.#tracker.observeCatalog(agent.session, events);
1442
1822
  this.#tui.replaceSession(events, this.#ctx.get('tuiToolPresentation')?.session(agent, events), agent.status, reason);
1443
1823
  this.#replayLivePrefix(agent.session.id);
@@ -1451,10 +1831,18 @@ export class SessionRuntime {
1451
1831
  if (agent !== undefined)
1452
1832
  this.#replaceTranscript(agent);
1453
1833
  }
1834
+ #cancelInspectDeliveries() {
1835
+ for (const delivery of this.#inspectDeliveries)
1836
+ delivery.abort();
1837
+ this.#inspectDeliveries.clear();
1838
+ }
1454
1839
  #closeInspect() {
1455
1840
  if (this.#inspectedId === undefined)
1456
1841
  return;
1457
1842
  this.#inspectEpoch += 1;
1843
+ this.#queueAbort?.abort(new Error('viewed session changed'));
1844
+ this.#workflowAbort?.abort();
1845
+ this.#cancelInspectDeliveries();
1458
1846
  this.#inspectedId = undefined;
1459
1847
  this.#tui.setInspectedSubagent(undefined);
1460
1848
  const agent = this.#active?.handle.agent;
@@ -1499,6 +1887,12 @@ export class SessionRuntime {
1499
1887
  }
1500
1888
  if (request !== this.#inspectEpoch)
1501
1889
  return;
1890
+ if (this.#inspectedId !== id) {
1891
+ this.#queueAbort?.abort(new Error('viewed session changed'));
1892
+ this.#workflowAbort?.abort();
1893
+ this.#cancelInspectDeliveries();
1894
+ }
1895
+ this.#tui.pendingInputs?.reconcile?.(id, new Set(events.flatMap(event => event.type === 'agent/inbox/spliced' ? event.data.inserted.map(message => message.id) : [])));
1502
1896
  this.#inspectedId = id;
1503
1897
  if (cwd !== undefined)
1504
1898
  this.#tui.setWorkingDirectory?.(cwd);
@@ -1512,12 +1906,12 @@ export class SessionRuntime {
1512
1906
  const childId = this.#inspectedId;
1513
1907
  const root = this.#active?.handle.agent;
1514
1908
  if (childId === undefined || root === undefined) {
1515
- this.#tui.restoreInput(submission);
1909
+ this.#tui.restoreInput(submission, childId);
1516
1910
  return;
1517
1911
  }
1518
1912
  const view = this.#inspectView(childId);
1519
1913
  if (!view.writable) {
1520
- this.#tui.restoreInput(submission);
1914
+ this.#tui.restoreInput(submission, childId);
1521
1915
  this.#tui.notice('This subagent is a completed run and cannot take more messages.');
1522
1916
  return;
1523
1917
  }
@@ -1529,34 +1923,60 @@ export class SessionRuntime {
1529
1923
  : this.#ctx.get('agents')?.get(SessionId(parentId));
1530
1924
  const subagents = this.#ctx.get('subagents');
1531
1925
  if (parent === undefined || subagents === undefined) {
1532
- this.#tui.restoreInput(submission);
1926
+ this.#tui.restoreInput(submission, childId);
1533
1927
  this.#tui.notice(parent === undefined
1534
1928
  ? 'The parent of this subagent is not live, so it cannot take a follow-up.'
1535
1929
  : 'Subagent follow-up is unavailable in this composition.');
1536
1930
  return;
1537
1931
  }
1932
+ const previous = this.#inspectDeliveryTail;
1933
+ let release = () => { };
1934
+ this.#inspectDeliveryTail = new Promise(resolve => { release = resolve; });
1935
+ const delivery = new AbortController();
1936
+ this.#inspectDeliveries.add(delivery);
1937
+ let cancelUpload = () => { };
1938
+ const cancelled = new Promise((_resolve, reject) => {
1939
+ cancelUpload = () => { reject(delivery.signal.reason); };
1940
+ delivery.signal.addEventListener('abort', cancelUpload, { once: true });
1941
+ });
1538
1942
  try {
1539
- const message = await createSubmissionMessage(submission, this.#ctx.get('attachments'));
1540
- if (this.#inspectedId !== childId || this.#active?.handle.agent !== root) {
1541
- this.#tui.restoreInput(submission);
1542
- return;
1543
- }
1544
- await queueHostSubagentPrompt(subagents, parent, SessionId(childId), message.content, { kind: 'user' }, new AbortController().signal);
1943
+ // Recalled messages can include attachments; admission must retain submission order.
1944
+ await Promise.race([previous, cancelled]);
1945
+ delivery.signal.throwIfAborted();
1946
+ // Attachment storage need not support cancellation; release the draft now
1947
+ // and ignore a later upload result before crossing Harness admission.
1948
+ const message = await Promise.race([createSubmissionMessage(submission, this.#ctx.get('attachments')), cancelled]);
1949
+ delivery.signal.removeEventListener('abort', cancelUpload);
1950
+ delivery.signal.throwIfAborted();
1951
+ if (this.#inspectedId !== childId || this.#active?.handle.agent !== root)
1952
+ throw new Error('The viewed session changed before delivery.');
1953
+ const send = submission.delivery === 'steer' ? steerHostSubagentPrompt : queueHostSubagentPrompt;
1954
+ const messageId = await send(subagents, parent, SessionId(childId), message.content, { kind: 'user' }, delivery.signal);
1955
+ this.#tui.pendingInputs?.prepare?.(submission, messageId);
1956
+ this.#tui.pendingInputs?.acknowledge?.(submission);
1545
1957
  }
1546
1958
  catch (error) {
1547
- this.#tui.restoreInput(submission);
1548
- this.#tui.notice(error instanceof Error ? error.message : String(error), { level: 'error' });
1959
+ this.#tui.restoreInput(submission, childId);
1960
+ if (!delivery.signal.aborted)
1961
+ this.#tui.notice(error instanceof Error ? error.message : String(error), { level: 'error' });
1962
+ }
1963
+ finally {
1964
+ delivery.signal.removeEventListener('abort', cancelUpload);
1965
+ this.#inspectDeliveries.delete(delivery);
1966
+ release();
1549
1967
  }
1550
1968
  }
1551
1969
  #sessionControls(active, projection) {
1552
- const controls = sessionControls(projection);
1553
- const livePlan = this.#ctx.get('planMode')?.get(active.handle.agent);
1970
+ const liveGoal = this.#ctx.get('goals')?.get(active.handle.agent);
1971
+ const controls = sessionControls(projection, this.#ctx.get('planMode')?.get(active.handle.agent));
1972
+ if (controls.goal !== undefined && liveGoal !== undefined && liveGoal.id === projection?.goal?.goal.id && liveGoal.revision === projection?.goal?.goal.revision) {
1973
+ controls.goal.activation = liveGoal.activation;
1974
+ }
1975
+ const failure = active.handle.agent.status === 'idle' ? continuableFailure(active.handle.agent.session.snapshotEvents()) : undefined;
1554
1976
  return {
1555
1977
  ...controls,
1978
+ ...(failure === undefined ? {} : { continuation: failure }),
1556
1979
  agentPreset: active.agentPreset,
1557
- ...(livePlan === undefined
1558
- ? {}
1559
- : { plan: { active: livePlan.active, pending: livePlan.pending !== undefined } }),
1560
1980
  };
1561
1981
  }
1562
1982
  /** Read one client-visible snapshot. Host-only projection state is never consulted. */
@@ -1592,4 +2012,12 @@ export class SessionRuntime {
1592
2012
  }
1593
2013
  }
1594
2014
  }
2015
+ /** Candidates for an argument prefix, matched the way the command list matches. */
2016
+ export function matchArgumentOptions(options, prefix) {
2017
+ const lower = prefix.trim().toLowerCase();
2018
+ if (lower === '')
2019
+ return options;
2020
+ return options.filter(option => option.value.toLowerCase().includes(lower)
2021
+ || (option.description ?? '').toLowerCase().includes(lower));
2022
+ }
1595
2023
  //# sourceMappingURL=session-controller.js.map