@linxiraos/pi-tui 1.4.4 → 1.4.7

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 (363) hide show
  1. package/CHANGELOG.md +208 -207
  2. package/README.md +34 -34
  3. package/dist/types/app-keybindings.d.ts +20 -0
  4. package/dist/types/apps/session-picker.d.ts +5 -0
  5. package/dist/types/charts/chart-plan.d.ts +9 -7
  6. package/dist/types/chat/assistant-message.d.ts +15 -3
  7. package/dist/types/chat/bash-execution.d.ts +2 -0
  8. package/dist/types/chat/display-preferences.d.ts +2 -0
  9. package/dist/types/chat/extension-types.d.ts +31 -0
  10. package/dist/types/chat/reply-write.d.ts +48 -0
  11. package/dist/types/chat/table-chart.d.ts +4 -3
  12. package/dist/types/chat/tool-execution.d.ts +1 -2
  13. package/dist/types/chat/transcript-outline.d.ts +7 -0
  14. package/dist/types/chat/transcript-render-helpers.d.ts +2 -0
  15. package/dist/types/chrome/context-map.d.ts +15 -0
  16. package/dist/types/chrome/context-presentation.d.ts +48 -0
  17. package/dist/types/chrome/context-view-model.d.ts +77 -0
  18. package/dist/types/chrome/index.d.ts +1 -0
  19. package/dist/types/chrome/transcript-notice.d.ts +35 -0
  20. package/dist/types/chrome/transcript-status.d.ts +20 -8
  21. package/dist/types/components/editor.d.ts +8 -0
  22. package/dist/types/components/image.d.ts +20 -0
  23. package/dist/types/components/loader.d.ts +1 -1
  24. package/dist/types/components/markdown.d.ts +7 -0
  25. package/dist/types/native/blobs.d.ts +11 -1
  26. package/dist/types/native/picker.d.ts +4 -4
  27. package/dist/types/overlays/advisor-config.d.ts +6 -0
  28. package/dist/types/overlays/agent-hub-projection.d.ts +3 -1
  29. package/dist/types/overlays/annotation-overlay.d.ts +7 -1
  30. package/dist/types/overlays/annotation-types.d.ts +28 -0
  31. package/dist/types/overlays/ask-dialog.d.ts +12 -3
  32. package/dist/types/overlays/btw-history-panel.d.ts +16 -2
  33. package/dist/types/overlays/btw-history.d.ts +7 -0
  34. package/dist/types/overlays/btw-panel.d.ts +2 -0
  35. package/dist/types/overlays/context-viewer-format.d.ts +42 -0
  36. package/dist/types/overlays/context-viewer-overview.d.ts +70 -0
  37. package/dist/types/overlays/context-viewer.d.ts +25 -0
  38. package/dist/types/overlays/hook-input.d.ts +1 -0
  39. package/dist/types/overlays/login-dialog.d.ts +5 -1
  40. package/dist/types/overlays/mcp-add-wizard.d.ts +2 -0
  41. package/dist/types/overlays/model-browser.d.ts +10 -1
  42. package/dist/types/overlays/oauth-selector.d.ts +23 -0
  43. package/dist/types/overlays/pause-screen.d.ts +13 -3
  44. package/dist/types/overlays/plan-review-overlay.d.ts +2 -0
  45. package/dist/types/overlays/rewind-selector.d.ts +1 -1
  46. package/dist/types/overlays/running-subagent-badge.d.ts +7 -1
  47. package/dist/types/overlays/session-selector.d.ts +22 -2
  48. package/dist/types/prompt/composer.d.ts +43 -0
  49. package/dist/types/prompt/interactive-context-helpers.d.ts +10 -3
  50. package/dist/types/prompt/macos-spelling.d.ts +2 -2
  51. package/dist/types/render/extension-links.d.ts +65 -0
  52. package/dist/types/render/hyperlink.d.ts +38 -7
  53. package/dist/types/render/index.d.ts +1 -0
  54. package/dist/types/render/output-pane.d.ts +1 -1
  55. package/dist/types/render/render-utils.d.ts +7 -1
  56. package/dist/types/setup/scenes/glyph.d.ts +1 -1
  57. package/dist/types/setup/scenes/model.d.ts +1 -1
  58. package/dist/types/setup/scenes/outro.d.ts +5 -4
  59. package/dist/types/setup/scenes/sign-in.d.ts +13 -8
  60. package/dist/types/setup/scenes/types.d.ts +16 -1
  61. package/dist/types/setup/startup-splash.d.ts +1 -1
  62. package/dist/types/setup/wizard-overlay.d.ts +11 -7
  63. package/dist/types/setup/wizard.d.ts +5 -1
  64. package/dist/types/status-line/component.d.ts +3 -3
  65. package/dist/types/status-line/context-usage.d.ts +42 -35
  66. package/dist/types/status-line/host.d.ts +6 -2
  67. package/dist/types/terminal-capabilities.d.ts +7 -0
  68. package/dist/types/theme/symbols.d.ts +1 -1
  69. package/dist/types/theme/theme.d.ts +0 -23
  70. package/dist/types/tools/ask.d.ts +4 -0
  71. package/dist/types/tools/bash-interactive.d.ts +6 -0
  72. package/dist/types/tools/bash.d.ts +2 -0
  73. package/dist/types/tools/default-renderer.d.ts +6 -4
  74. package/dist/types/tools/edit.d.ts +3 -1
  75. package/dist/types/tools/fetch.d.ts +1 -0
  76. package/dist/types/tools/github.d.ts +3 -0
  77. package/dist/types/tools/grouped-file-output.d.ts +2 -0
  78. package/dist/types/tools/irc.d.ts +6 -0
  79. package/dist/types/tools/json-tree.d.ts +23 -4
  80. package/dist/types/tools/lsp.d.ts +2 -0
  81. package/dist/types/tools/mcp.d.ts +7 -6
  82. package/dist/types/tools/native-view.d.ts +1 -1
  83. package/dist/types/tools/read.d.ts +3 -0
  84. package/dist/types/tools/renderer.d.ts +2 -0
  85. package/dist/types/tools/streaming-output.d.ts +11 -0
  86. package/dist/types/tools/task.d.ts +9 -1
  87. package/dist/types/tools/url-scheme-host.d.ts +17 -0
  88. package/dist/types/tools/wait.d.ts +16 -2
  89. package/dist/types/tools/yield.d.ts +1 -1
  90. package/dist/types/tui.d.ts +9 -2
  91. package/dist/types/vim.d.ts +39 -0
  92. package/package.json +10 -14
  93. package/src/app-keybindings.d.ts +20 -0
  94. package/src/app-keybindings.ts +20 -0
  95. package/src/apps/session-picker.ts +7 -0
  96. package/src/charts/chart-plan.d.ts +9 -7
  97. package/src/charts/chart-plan.ts +20 -50
  98. package/src/chat/advisor-message.ts +2 -0
  99. package/src/chat/assistant-message.d.ts +15 -3
  100. package/src/chat/assistant-message.ts +137 -19
  101. package/src/chat/background-tan-message.ts +4 -0
  102. package/src/chat/bash-execution.d.ts +2 -0
  103. package/src/chat/bash-execution.ts +13 -1
  104. package/src/chat/chat-transcript-builder.ts +58 -28
  105. package/src/chat/compaction-summary-message.ts +2 -1
  106. package/src/chat/display-preferences.d.ts +2 -0
  107. package/src/chat/display-preferences.ts +3 -0
  108. package/src/chat/extension-types.d.ts +31 -0
  109. package/src/chat/extension-types.ts +34 -0
  110. package/src/chat/read-tool-group.ts +1 -2
  111. package/src/chat/reply-write.d.ts +48 -0
  112. package/src/chat/reply-write.ts +127 -0
  113. package/src/chat/skill-message.ts +2 -6
  114. package/src/chat/table-chart.d.ts +4 -3
  115. package/src/chat/table-chart.ts +10 -4
  116. package/src/chat/tool-execution.d.ts +1 -2
  117. package/src/chat/tool-execution.ts +20 -13
  118. package/src/chat/transcript-outline.d.ts +7 -0
  119. package/src/chat/transcript-outline.ts +27 -0
  120. package/src/chat/transcript-render-helpers.d.ts +2 -0
  121. package/src/chat/transcript-render-helpers.ts +66 -24
  122. package/src/chrome/context-map.ts +62 -0
  123. package/src/chrome/context-presentation.ts +26 -0
  124. package/src/chrome/context-view-model.ts +73 -0
  125. package/src/chrome/index.ts +1 -0
  126. package/src/chrome/transcript-container.ts +89 -59
  127. package/src/chrome/transcript-notice.d.ts +35 -0
  128. package/src/chrome/transcript-notice.ts +83 -0
  129. package/src/chrome/transcript-status.d.ts +20 -8
  130. package/src/chrome/transcript-status.ts +29 -29
  131. package/src/components/editor.d.ts +8 -0
  132. package/src/components/editor.ts +465 -14
  133. package/src/components/image.d.ts +20 -0
  134. package/src/components/image.ts +83 -18
  135. package/src/components/loader.d.ts +1 -1
  136. package/src/components/loader.ts +1 -1
  137. package/src/components/markdown.d.ts +7 -0
  138. package/src/components/markdown.ts +225 -13
  139. package/src/hotkeys-markdown.ts +2 -0
  140. package/src/native/backend.ts +5 -66
  141. package/src/native/blobs.d.ts +11 -1
  142. package/src/native/blobs.ts +5 -3
  143. package/src/native/picker.d.ts +4 -4
  144. package/src/native/picker.ts +4 -4
  145. package/src/overlays/advisor-config.ts +10 -12
  146. package/src/overlays/agent-hub-projection.d.ts +3 -1
  147. package/src/overlays/agent-hub-projection.ts +6 -5
  148. package/src/overlays/agent-hub.ts +51 -42
  149. package/src/overlays/annotation-overlay.ts +125 -37
  150. package/src/overlays/annotation-types.ts +24 -0
  151. package/src/overlays/ask-dialog.ts +125 -35
  152. package/src/overlays/btw-history-panel.ts +124 -12
  153. package/src/overlays/btw-history.ts +11 -0
  154. package/src/overlays/btw-panel.ts +8 -4
  155. package/src/overlays/context-viewer-format.ts +145 -0
  156. package/src/overlays/context-viewer-overview.ts +381 -0
  157. package/src/overlays/context-viewer.ts +728 -0
  158. package/src/overlays/hook-input.ts +2 -0
  159. package/src/overlays/hook-selector.ts +2 -2
  160. package/src/overlays/login-dialog.ts +31 -5
  161. package/src/overlays/mcp-add-wizard.ts +6 -1
  162. package/src/overlays/model-browser.ts +37 -0
  163. package/src/overlays/model-hub.ts +1 -7
  164. package/src/overlays/model-picker.ts +1 -10
  165. package/src/overlays/oauth-selector.ts +44 -6
  166. package/src/overlays/pause-screen.ts +166 -33
  167. package/src/overlays/plan-review-overlay.ts +13 -2
  168. package/src/overlays/rewind-selector.ts +29 -12
  169. package/src/overlays/running-subagent-badge.ts +12 -1
  170. package/src/overlays/session-selector.ts +313 -42
  171. package/src/overlays/settings-defs.ts +1 -0
  172. package/src/overlays/usage-dashboard.ts +20 -14
  173. package/src/prompt/composer.ts +216 -1
  174. package/src/prompt/custom-editor.ts +6 -1
  175. package/src/prompt/emoji-autocomplete.ts +0 -2
  176. package/src/prompt/interactive-context-helpers.ts +29 -4
  177. package/src/prompt/macos-spelling.ts +24 -15
  178. package/src/render/extension-links.d.ts +65 -0
  179. package/src/render/extension-links.ts +214 -0
  180. package/src/render/hyperlink.d.ts +38 -7
  181. package/src/render/hyperlink.ts +102 -23
  182. package/src/render/index.d.ts +1 -0
  183. package/src/render/index.ts +1 -0
  184. package/src/render/output-pane.d.ts +1 -1
  185. package/src/render/output-pane.ts +60 -17
  186. package/src/render/render-utils.d.ts +7 -1
  187. package/src/render/render-utils.ts +11 -2
  188. package/src/setup/scenes/composer.ts +2 -0
  189. package/src/setup/scenes/glyph.ts +3 -1
  190. package/src/setup/scenes/model.ts +192 -29
  191. package/src/setup/scenes/outro.ts +33 -15
  192. package/src/setup/scenes/sign-in.ts +194 -392
  193. package/src/setup/scenes/theme.ts +2 -0
  194. package/src/setup/scenes/types.ts +18 -1
  195. package/src/setup/startup-splash.ts +8 -7
  196. package/src/setup/wizard-overlay.ts +164 -35
  197. package/src/setup/wizard.ts +11 -2
  198. package/src/status-line/component.ts +10 -14
  199. package/src/status-line/context-usage.ts +122 -597
  200. package/src/status-line/host.ts +6 -2
  201. package/src/terminal-capabilities.d.ts +7 -0
  202. package/src/terminal-capabilities.ts +10 -0
  203. package/src/terminal.ts +24 -2
  204. package/src/theme/defaults.json +1 -0
  205. package/src/theme/loader.ts +1 -1
  206. package/src/theme/symbols.d.ts +1 -1
  207. package/src/theme/symbols.ts +16 -0
  208. package/src/theme/theme.d.ts +0 -23
  209. package/src/theme/theme.ts +2 -75
  210. package/src/tools/ask.d.ts +4 -0
  211. package/src/tools/ask.ts +4 -0
  212. package/src/tools/ast-grep.ts +3 -2
  213. package/src/tools/bash-interactive.d.ts +49 -0
  214. package/src/tools/bash-interactive.ts +6 -1
  215. package/src/tools/bash.d.ts +2 -0
  216. package/src/tools/bash.ts +7 -23
  217. package/src/tools/default-renderer.d.ts +6 -4
  218. package/src/tools/default-renderer.ts +9 -6
  219. package/src/tools/edit.d.ts +3 -1
  220. package/src/tools/edit.ts +8 -4
  221. package/src/tools/eval.ts +14 -4
  222. package/src/tools/fetch.d.ts +1 -0
  223. package/src/tools/fetch.ts +1 -0
  224. package/src/tools/find.ts +3 -10
  225. package/src/tools/github.d.ts +3 -0
  226. package/src/tools/github.ts +23 -3
  227. package/src/tools/glob.ts +4 -3
  228. package/src/tools/grep.ts +3 -4
  229. package/src/tools/grouped-file-output.d.ts +2 -0
  230. package/src/tools/grouped-file-output.ts +8 -2
  231. package/src/tools/irc.d.ts +6 -0
  232. package/src/tools/irc.ts +6 -0
  233. package/src/tools/job-widget.ts +13 -1
  234. package/src/tools/json-tree.d.ts +23 -4
  235. package/src/tools/json-tree.ts +132 -42
  236. package/src/tools/lsp.d.ts +2 -0
  237. package/src/tools/lsp.ts +36 -15
  238. package/src/tools/mcp.d.ts +7 -6
  239. package/src/tools/mcp.ts +41 -15
  240. package/src/tools/native-view.d.ts +1 -1
  241. package/src/tools/native-view.ts +3 -3
  242. package/src/tools/read.d.ts +3 -0
  243. package/src/tools/read.ts +3 -1
  244. package/src/tools/renderer.d.ts +2 -0
  245. package/src/tools/renderer.ts +2 -0
  246. package/src/tools/streaming-output.d.ts +11 -0
  247. package/src/tools/streaming-output.ts +41 -0
  248. package/src/tools/task.d.ts +9 -1
  249. package/src/tools/task.ts +59 -16
  250. package/src/tools/url-scheme-host.d.ts +17 -0
  251. package/src/tools/url-scheme-host.ts +21 -0
  252. package/src/tools/vibe.ts +14 -3
  253. package/src/tools/wait.d.ts +16 -2
  254. package/src/tools/wait.ts +16 -2
  255. package/src/tools/yield.d.ts +1 -1
  256. package/src/tools/yield.ts +18 -9
  257. package/src/tui.d.ts +9 -2
  258. package/src/tui.ts +102 -34
  259. package/src/vim.d.ts +39 -0
  260. package/src/vim.ts +313 -22
  261. package/dist/types/theme/defaults/index.d.ts +0 -10289
  262. package/src/theme/defaults/alabaster.json +0 -103
  263. package/src/theme/defaults/amethyst.json +0 -106
  264. package/src/theme/defaults/anthracite.json +0 -103
  265. package/src/theme/defaults/basalt.json +0 -101
  266. package/src/theme/defaults/birch.json +0 -105
  267. package/src/theme/defaults/dark-abyss.json +0 -101
  268. package/src/theme/defaults/dark-arctic.json +0 -114
  269. package/src/theme/defaults/dark-aurora.json +0 -105
  270. package/src/theme/defaults/dark-catppuccin.json +0 -117
  271. package/src/theme/defaults/dark-cavern.json +0 -101
  272. package/src/theme/defaults/dark-celestial.json +0 -116
  273. package/src/theme/defaults/dark-copper.json +0 -105
  274. package/src/theme/defaults/dark-cosmos.json +0 -100
  275. package/src/theme/defaults/dark-cyberpunk.json +0 -112
  276. package/src/theme/defaults/dark-dracula.json +0 -108
  277. package/src/theme/defaults/dark-eclipse.json +0 -101
  278. package/src/theme/defaults/dark-ember.json +0 -105
  279. package/src/theme/defaults/dark-equinox.json +0 -100
  280. package/src/theme/defaults/dark-forest.json +0 -106
  281. package/src/theme/defaults/dark-github.json +0 -115
  282. package/src/theme/defaults/dark-gruvbox.json +0 -122
  283. package/src/theme/defaults/dark-lavender.json +0 -105
  284. package/src/theme/defaults/dark-lunar.json +0 -99
  285. package/src/theme/defaults/dark-midnight.json +0 -105
  286. package/src/theme/defaults/dark-monochrome.json +0 -104
  287. package/src/theme/defaults/dark-monokai.json +0 -108
  288. package/src/theme/defaults/dark-nebula.json +0 -100
  289. package/src/theme/defaults/dark-neon-noir.json +0 -110
  290. package/src/theme/defaults/dark-nord.json +0 -108
  291. package/src/theme/defaults/dark-ocean.json +0 -111
  292. package/src/theme/defaults/dark-one.json +0 -110
  293. package/src/theme/defaults/dark-poimandres.json +0 -125
  294. package/src/theme/defaults/dark-rainforest.json +0 -101
  295. package/src/theme/defaults/dark-reef.json +0 -101
  296. package/src/theme/defaults/dark-retro.json +0 -102
  297. package/src/theme/defaults/dark-rose-pine.json +0 -106
  298. package/src/theme/defaults/dark-sakura.json +0 -105
  299. package/src/theme/defaults/dark-slate.json +0 -105
  300. package/src/theme/defaults/dark-solarized.json +0 -107
  301. package/src/theme/defaults/dark-solstice.json +0 -100
  302. package/src/theme/defaults/dark-starfall.json +0 -101
  303. package/src/theme/defaults/dark-sunset.json +0 -109
  304. package/src/theme/defaults/dark-swamp.json +0 -100
  305. package/src/theme/defaults/dark-synthwave.json +0 -113
  306. package/src/theme/defaults/dark-taiga.json +0 -101
  307. package/src/theme/defaults/dark-terminal.json +0 -105
  308. package/src/theme/defaults/dark-tokyo-night.json +0 -111
  309. package/src/theme/defaults/dark-tundra.json +0 -101
  310. package/src/theme/defaults/dark-twilight.json +0 -101
  311. package/src/theme/defaults/dark-volcanic.json +0 -101
  312. package/src/theme/defaults/graphite.json +0 -102
  313. package/src/theme/defaults/index.d.ts +0 -10289
  314. package/src/theme/defaults/index.ts +0 -203
  315. package/src/theme/defaults/light-arctic.json +0 -117
  316. package/src/theme/defaults/light-aurora-day.json +0 -101
  317. package/src/theme/defaults/light-canyon.json +0 -101
  318. package/src/theme/defaults/light-catppuccin.json +0 -116
  319. package/src/theme/defaults/light-cirrus.json +0 -100
  320. package/src/theme/defaults/light-coral.json +0 -105
  321. package/src/theme/defaults/light-cyberpunk.json +0 -106
  322. package/src/theme/defaults/light-dawn.json +0 -100
  323. package/src/theme/defaults/light-dunes.json +0 -101
  324. package/src/theme/defaults/light-eucalyptus.json +0 -105
  325. package/src/theme/defaults/light-forest.json +0 -110
  326. package/src/theme/defaults/light-frost.json +0 -105
  327. package/src/theme/defaults/light-github.json +0 -125
  328. package/src/theme/defaults/light-glacier.json +0 -101
  329. package/src/theme/defaults/light-gruvbox.json +0 -118
  330. package/src/theme/defaults/light-haze.json +0 -100
  331. package/src/theme/defaults/light-honeycomb.json +0 -105
  332. package/src/theme/defaults/light-lagoon.json +0 -101
  333. package/src/theme/defaults/light-lavender.json +0 -105
  334. package/src/theme/defaults/light-meadow.json +0 -101
  335. package/src/theme/defaults/light-mint.json +0 -105
  336. package/src/theme/defaults/light-monochrome.json +0 -111
  337. package/src/theme/defaults/light-ocean.json +0 -109
  338. package/src/theme/defaults/light-one.json +0 -109
  339. package/src/theme/defaults/light-opal.json +0 -101
  340. package/src/theme/defaults/light-orchard.json +0 -101
  341. package/src/theme/defaults/light-paper.json +0 -105
  342. package/src/theme/defaults/light-poimandres.json +0 -125
  343. package/src/theme/defaults/light-prism.json +0 -100
  344. package/src/theme/defaults/light-retro.json +0 -108
  345. package/src/theme/defaults/light-sand.json +0 -105
  346. package/src/theme/defaults/light-savanna.json +0 -101
  347. package/src/theme/defaults/light-solarized.json +0 -112
  348. package/src/theme/defaults/light-soleil.json +0 -100
  349. package/src/theme/defaults/light-sunset.json +0 -109
  350. package/src/theme/defaults/light-synthwave.json +0 -108
  351. package/src/theme/defaults/light-tokyo-night.json +0 -121
  352. package/src/theme/defaults/light-wetland.json +0 -101
  353. package/src/theme/defaults/light-zenith.json +0 -99
  354. package/src/theme/defaults/limestone.json +0 -104
  355. package/src/theme/defaults/mahogany.json +0 -107
  356. package/src/theme/defaults/marble.json +0 -103
  357. package/src/theme/defaults/obsidian.json +0 -101
  358. package/src/theme/defaults/onyx.json +0 -101
  359. package/src/theme/defaults/pearl.json +0 -103
  360. package/src/theme/defaults/porcelain.json +0 -101
  361. package/src/theme/defaults/quartz.json +0 -106
  362. package/src/theme/defaults/sandstone.json +0 -105
  363. package/src/theme/defaults/titanium.json +0 -100
@@ -51,6 +51,8 @@ export interface ExtensionAskDialogResultItem {
51
51
  customInputImages?: ImageContent[];
52
52
  note?: string;
53
53
  noteImages?: ImageContent[];
54
+ /** Label of the option the note is on; unset when it is on the custom answer. */
55
+ noteOption?: string;
54
56
  timedOut?: boolean;
55
57
  }
56
58
 
@@ -145,14 +147,21 @@ interface AskDialogCallbacks {
145
147
  ): Promise<AskDialogPromptValue | undefined>;
146
148
  }
147
149
 
150
+ /**
151
+ * Routes typing to a composer draft that was in progress when the dialog
152
+ * opened, so in-flight keystrokes never answer by accident. The up/down select
153
+ * keys are the explicit hand-off: they release the guard for the rest of the
154
+ * dialog's life and the draft stays parked (intact) beneath it.
155
+ */
148
156
  interface AskDialogInputGuard {
149
157
  isBlocked(): boolean;
150
158
  handleInput(keyData: string): void;
159
+ /** Shown after the release keys while the guard holds input. */
151
160
  hint: string;
152
161
  /** Mirror the guard's blocked state onto the proxied draft surface each
153
162
  * render, so a draft that owns input shows a visible insertion cursor even
154
- * though this dialog holds TUI focus. */
155
- syncPresentation?(): void;
163
+ * though this dialog holds TUI focus, and drops it once the dialog takes over. */
164
+ syncPresentation?(blocked: boolean): void;
156
165
  }
157
166
 
158
167
  interface AskDialogOptions {
@@ -404,7 +413,7 @@ function describeAnswer(question: ExtensionAskDialogQuestion, state: QuestionSta
404
413
  push(optionLabelSpans(question, index, labels[index] ?? option.label));
405
414
  });
406
415
  if (state.customInput !== undefined) push([span(`“${normalizedInlineInput(state.customInput)}”`)]);
407
- const note = noteForSubmittedAnswer(question, state)?.trim();
416
+ const note = noteForSubmittedAnswer(question, state)?.text.trim();
408
417
  if (note) spans.push(span(" ✎ ", "dim"), span(normalizedInlineInput(note), "em"));
409
418
  return spans;
410
419
  }
@@ -448,13 +457,17 @@ function clearNoteUnlessRow(state: QuestionState, rowKey: string): void {
448
457
  if (state.noteRowKey !== undefined && state.noteRowKey !== rowKey) clearNote(state);
449
458
  }
450
459
 
451
- function noteForSubmittedAnswer(question: ExtensionAskDialogQuestion, state: QuestionState): string | undefined {
460
+ /** The note that goes out with the answer (its row is part of it), and the option it is on (unset for Other). */
461
+ function noteForSubmittedAnswer(
462
+ question: ExtensionAskDialogQuestion,
463
+ state: QuestionState,
464
+ ): { text: string; option?: string } | undefined {
452
465
  if (state.note === undefined || state.noteRowKey === undefined) return undefined;
453
- if (state.noteRowKey === "other") return state.customInput !== undefined ? state.note : undefined;
466
+ if (state.noteRowKey === "other") return state.customInput !== undefined ? { text: state.note } : undefined;
454
467
  const match = /^option:(\d+)$/.exec(state.noteRowKey);
455
468
  const optionIndex = match?.[1] === undefined ? Number.NaN : Number.parseInt(match[1], 10);
456
469
  const option = Number.isInteger(optionIndex) ? question.options[optionIndex] : undefined;
457
- return option && state.selectedOptions.has(option.label) ? state.note : undefined;
470
+ return option && state.selectedOptions.has(option.label) ? { text: state.note, option: option.label } : undefined;
458
471
  }
459
472
 
460
473
  function renderRowLabel(
@@ -581,10 +594,18 @@ export class AskDialogComponent implements Component {
581
594
  #native: NativeNode | undefined;
582
595
  /** Input-guard blocked state {@link #native} was described with (the guard flips outside this dialog). */
583
596
  #nativeBlocked = false;
597
+ /** Set once the user explicitly takes the dialog (up/down, or a pointer action) while a draft held input. */
598
+ #guardReleased = false;
584
599
  /** When the countdown runs out (epoch ms), for the native ring. */
585
600
  #countdownDeadline = 0;
586
601
  /** Once-a-second re-describe while the native countdown ring is shown. */
587
602
  #ringTick: NodeJS.Timeout | undefined;
603
+ /**
604
+ * The answer whose pick just moved the dialog on to the next question. Note annotates it, not the
605
+ * next question's highlighted row, until that question is answered or any other input arrives:
606
+ * a Tern click commits a single-choice row, so picking then pressing Note is the mouse flow.
607
+ */
608
+ #justAnswered: { questionIndex: number; rowKey: string } | undefined;
588
609
  readonly #panel: OverlayPanel;
589
610
  readonly #headerRegion: PanelRows;
590
611
  readonly #bodyRegion: PanelRows;
@@ -682,6 +703,7 @@ export class AskDialogComponent implements Component {
682
703
  // closed/prompt guards, matching HookSelector/HookInput semantics.
683
704
  this.#countdown?.reset();
684
705
  this.#native = undefined;
706
+ if (keyData !== "n" && keyData !== "N") this.#justAnswered = undefined;
685
707
  if (matchesSelectCancel(keyData)) {
686
708
  this.#finishCancel();
687
709
  return;
@@ -696,9 +718,15 @@ export class AskDialogComponent implements Component {
696
718
  this.toggleQuestionExpansion();
697
719
  return;
698
720
  }
699
- const inputGuard = this.options.inputGuard;
700
- if (inputGuard?.isBlocked()) {
701
- inputGuard.handleInput(keyData);
721
+ if (this.#guardBlocks()) {
722
+ if (
723
+ getKeybindings().matches(keyData, "tui.select.up") ||
724
+ getKeybindings().matches(keyData, "tui.select.down")
725
+ ) {
726
+ this.#releaseGuard();
727
+ return;
728
+ }
729
+ this.options.inputGuard?.handleInput(keyData);
702
730
  this.#requestRender();
703
731
  return;
704
732
  }
@@ -723,7 +751,7 @@ export class AskDialogComponent implements Component {
723
751
  // Keep the proxied draft's cursor visible while it owns input (the editor
724
752
  // renders as the next sibling in the same container, so this lands in the
725
753
  // same frame).
726
- this.options.inputGuard?.syncPresentation?.();
754
+ this.options.inputGuard?.syncPresentation?.(this.#guardBlocks());
727
755
  if (this.#hidden) return this.#renderHidden(width);
728
756
  const innerWidth = Math.max(1, width - 4);
729
757
  this.#contentWidth = innerWidth;
@@ -768,10 +796,9 @@ export class AskDialogComponent implements Component {
768
796
  * countdown, Hide, then Note, Skip and the primary Submit/Next).
769
797
  */
770
798
  describe(cx: DescribeContext): NativeNode {
771
- const inputGuard = this.options.inputGuard;
772
799
  // Same draft-cursor mirroring as render(): the proxied draft describes itself next to this dialog.
773
- inputGuard?.syncPresentation?.();
774
- const blocked = inputGuard?.isBlocked() ?? false;
800
+ const blocked = this.#guardBlocks();
801
+ this.options.inputGuard?.syncPresentation?.(blocked);
775
802
  const ring = this.#countdown !== undefined && cx.supports("meter");
776
803
  if (ring) this.#startRingTick();
777
804
  if (this.#native && this.#nativeBlocked === blocked) return this.#native;
@@ -985,7 +1012,10 @@ export class AskDialogComponent implements Component {
985
1012
  if (blocked && inputGuard) {
986
1013
  return actionBar([
987
1014
  ...lead,
988
- text([span(plainText(inputGuard.hint), "muted")], { truncate: "end", role: "zeta.ask.summary" }),
1015
+ text([span(plainText(this.#guardHint(inputGuard)), "muted")], {
1016
+ truncate: "end",
1017
+ role: "zeta.ask.summary",
1018
+ }),
989
1019
  skip,
990
1020
  ]);
991
1021
  }
@@ -1006,7 +1036,10 @@ export class AskDialogComponent implements Component {
1006
1036
  tone: "accent",
1007
1037
  title: question?.multi ? `${enterLabel} enter · Toggle space` : `${enterLabel} enter`,
1008
1038
  });
1009
- const note = actionButton("Note", "note", { keys: "n", title: "Add a note to the highlighted answer n" });
1039
+ const note = actionButton("Note", "note", {
1040
+ keys: "n",
1041
+ title: "Add a note to the highlighted answer, or to the one just picked n",
1042
+ });
1010
1043
  return actionBar([...lead, null, note, skip, submit]);
1011
1044
  }
1012
1045
 
@@ -1014,11 +1047,12 @@ export class AskDialogComponent implements Component {
1014
1047
  * Pointer actions: a tab click switches to it; a click on an answer row is
1015
1048
  * Enter on it (Space for a multi-select option, so it toggles; its
1016
1049
  * double-click `activate` is Enter); the action bar's Submit, Note and Skip
1017
- * run exactly what Enter, `n` and Esc run on the highlighted row; Hide/Show
1050
+ * run what Enter (see {@link #pressEnter} for Other), `n` and Esc run on the highlighted row; Hide/Show
1018
1051
  * collapse and restore the dialog.
1019
1052
  */
1020
1053
  handleNativeEvent(event: NativeUiEvent): void {
1021
1054
  if (this.#closed || this.#promptActive) return;
1055
+ if (event.type !== "action" || event.act !== "note") this.#justAnswered = undefined;
1022
1056
  if (event.type === "action") {
1023
1057
  if (event.act === "cancel") {
1024
1058
  this.#finishCancel();
@@ -1028,13 +1062,16 @@ export class AskDialogComponent implements Component {
1028
1062
  this.#setHidden(event.act === "hide");
1029
1063
  return;
1030
1064
  }
1031
- if (this.#hidden || this.options.inputGuard?.isBlocked()) return;
1065
+ if (this.#hidden) return;
1066
+ // A pointer action on the dialog is an explicit hand-off from the draft.
1067
+ this.#releaseGuardForPointer();
1032
1068
  if (event.act === "submit") this.#pressEnter();
1033
1069
  else if (event.act === "note") this.#pressNote();
1034
1070
  return;
1035
1071
  }
1036
1072
  if (event.type !== "select" && event.type !== "activate") return;
1037
- if (this.#hidden || this.options.inputGuard?.isBlocked()) return;
1073
+ if (this.#hidden) return;
1074
+ this.#releaseGuardForPointer();
1038
1075
  const key = leafKey(event.key);
1039
1076
  if (key === "tabs") {
1040
1077
  if (!this.#hasSubmitTab()) return;
@@ -1062,7 +1099,13 @@ export class AskDialogComponent implements Component {
1062
1099
  this.#requestRender();
1063
1100
  }
1064
1101
 
1065
- /** Enter: submit on the Review tab, else commit the highlighted row. */
1102
+ /**
1103
+ * The action bar's Submit/Next: submit on the Review tab, else commit the highlighted row —
1104
+ * except Other, whose row (click or Enter) already opens the editor. Reopening it here trapped a
1105
+ * cancelled Other: Next kept bringing the editor back instead of moving on. With a Review tab to
1106
+ * land on, Next keeps any custom answer and moves on; a lone single-select question has nowhere
1107
+ * to go but submitting nothing, so it still asks.
1108
+ */
1066
1109
  #pressEnter(): void {
1067
1110
  this.#countdown?.reset();
1068
1111
  if (this.#isSubmitTab()) {
@@ -1072,18 +1115,38 @@ export class AskDialogComponent implements Component {
1072
1115
  const active = this.#activeQuestionState();
1073
1116
  const rowItem = active ? this.#questionRows(active.question)[active.state.cursorIndex] : undefined;
1074
1117
  if (!active || !rowItem) return;
1118
+ if (rowItem.kind === "other" && this.#hasSubmitTab()) {
1119
+ this.#advanceAfterQuestion(active.state.customInput === undefined ? undefined : rowItem.key);
1120
+ return;
1121
+ }
1075
1122
  this.#commitRow(active.question, active.state, rowItem, true);
1076
1123
  this.#requestRender();
1077
1124
  }
1078
1125
 
1079
- /** `n`: a note on the highlighted row (questions only). */
1126
+ /** `n`: a note on the {@link #noteTarget} row (questions only). */
1080
1127
  #pressNote(): void {
1081
1128
  if (this.#isSubmitTab()) return;
1082
1129
  this.#countdown?.reset();
1130
+ const target = this.#noteTarget();
1131
+ if (target) void this.#promptForNote(target.question, target.state, target.rowItem);
1132
+ }
1133
+
1134
+ /**
1135
+ * The row a note goes to: the answer just picked while the question it moved on to is still
1136
+ * unanswered, else the highlighted row.
1137
+ */
1138
+ #noteTarget(): { question: ExtensionAskDialogQuestion; state: QuestionState; rowItem: QuestionRow } | undefined {
1083
1139
  const active = this.#activeQuestionState();
1084
- const rowItem = active ? this.#questionRows(active.question)[active.state.cursorIndex] : undefined;
1085
- if (!active || !rowItem) return;
1086
- void this.#promptForNote(active.question, active.state, rowItem);
1140
+ if (!active) return undefined;
1141
+ const last = this.#justAnswered;
1142
+ if (last && last.questionIndex !== this.#currentQuestionIndex() && !isAnswered(active.state)) {
1143
+ const question = this.#questions[last.questionIndex];
1144
+ const state = this.#states[last.questionIndex];
1145
+ const rowItem = question ? this.#questionRows(question).find(row => row.key === last.rowKey) : undefined;
1146
+ if (question && state && rowItem) return { question, state, rowItem };
1147
+ }
1148
+ const rowItem = this.#questionRows(active.question)[active.state.cursorIndex];
1149
+ return rowItem ? { question: active.question, state: active.state, rowItem } : undefined;
1087
1150
  }
1088
1151
 
1089
1152
  /** Re-describe once a second while a countdown ring is shown (the ring's value is data, not a terminal clock). */
@@ -1169,16 +1232,39 @@ export class AskDialogComponent implements Component {
1169
1232
  this.#requestRender();
1170
1233
  }
1171
1234
 
1235
+ /** True while a draft that predates the dialog still owns typing. */
1236
+ #guardBlocks(): boolean {
1237
+ return !this.#guardReleased && (this.options.inputGuard?.isBlocked() ?? false);
1238
+ }
1239
+
1240
+ /** Up/down hand the keyboard to the dialog for good; the draft stays untouched beneath it. */
1241
+ #releaseGuard(): void {
1242
+ this.#guardReleased = true;
1243
+ this.#native = undefined;
1244
+ this.#hidden = false;
1245
+ this.#requestRender();
1246
+ }
1247
+
1248
+ #releaseGuardForPointer(): void {
1249
+ if (!this.#guardBlocks()) return;
1250
+ this.#guardReleased = true;
1251
+ this.#native = undefined;
1252
+ }
1253
+
1254
+ #guardHint(inputGuard: AskDialogInputGuard): string {
1255
+ return `${editorKeys("tui.select.up", "tui.select.down")} answer · ${inputGuard.hint}`;
1256
+ }
1257
+
1172
1258
  /** Hidden: one line in the composer's place — title (with countdown), the question clipped to fit, and how to bring it back. */
1173
1259
  #renderHidden(width: number): readonly string[] {
1174
1260
  const hideKey = editorKey("app.ask.hide");
1175
1261
  const enter = formatKeyHint("enter");
1176
1262
  const inputGuard = this.options.inputGuard;
1177
- const blocked = inputGuard?.isBlocked() ?? false;
1263
+ const blocked = this.#guardBlocks();
1178
1264
  // While a draft owns input, Enter goes to the draft, so only the hide key restores.
1179
1265
  const show = blocked ? hideKey : hideKey ? `${hideKey}/${enter}` : enter;
1180
1266
  const hints: string[] = [];
1181
- if (blocked && inputGuard) hints.push(inputGuard.hint);
1267
+ if (blocked && inputGuard) hints.push(this.#guardHint(inputGuard));
1182
1268
  if (show) hints.push(`${show} show`);
1183
1269
  hints.push(`${editorKey("tui.select.cancel")} cancel`);
1184
1270
  const hint = theme.fg("dim", ` · ${hints.join(" · ")}`);
@@ -1262,7 +1348,7 @@ export class AskDialogComponent implements Component {
1262
1348
  const enter = formatKeyHint("enter");
1263
1349
  const upDown = editorKeys("tui.select.up", "tui.select.down");
1264
1350
  const inputGuard = this.options.inputGuard;
1265
- if (inputGuard?.isBlocked()) return `${inputGuard.hint}${this.#expandHint()} · ${cancel}`;
1351
+ if (inputGuard && this.#guardBlocks()) return `${this.#guardHint(inputGuard)}${this.#expandHint()} · ${cancel}`;
1266
1352
  if (this.#isSubmitTab()) {
1267
1353
  const scroll = indicator ? ` ${indicator} scroll ·` : "";
1268
1354
  return `${enter} submit · ${upDown} scroll ·${scroll} ${cancel}`;
@@ -1334,9 +1420,7 @@ export class AskDialogComponent implements Component {
1334
1420
  const rowItem = rows[state.cursorIndex];
1335
1421
  if (!rowItem) return;
1336
1422
  if (keyData === "n" || keyData === "N") {
1337
- if (rowItem.kind === "option" || rowItem.kind === "other") {
1338
- void this.#promptForNote(question, state, rowItem);
1339
- }
1423
+ this.#pressNote();
1340
1424
  return;
1341
1425
  }
1342
1426
  const isEnter = matchesKey(keyData, "enter") || matchesKey(keyData, "return") || keyData === "\n";
@@ -1364,7 +1448,7 @@ export class AskDialogComponent implements Component {
1364
1448
  // focused option; Space toggles. Advances to the next question
1365
1449
  // (submitting only for a single-question dialog), matching
1366
1450
  // single-select Enter (#8252).
1367
- this.#advanceAfterQuestion();
1451
+ this.#advanceAfterQuestion(state.selectedOptions.has(option.label) ? rowItem.key : undefined);
1368
1452
  return;
1369
1453
  }
1370
1454
  if (state.selectedOptions.has(option.label)) {
@@ -1380,7 +1464,7 @@ export class AskDialogComponent implements Component {
1380
1464
  state.customInput = undefined;
1381
1465
  state.customInputImages = undefined;
1382
1466
  clearNoteUnlessRow(state, rowItem.key);
1383
- this.#advanceAfterQuestion();
1467
+ this.#advanceAfterQuestion(rowItem.key);
1384
1468
  }
1385
1469
 
1386
1470
  #handleSubmitTabInput(keyData: string): void {
@@ -1405,8 +1489,13 @@ export class AskDialogComponent implements Component {
1405
1489
  this.#submitScrollOffset = 0;
1406
1490
  }
1407
1491
 
1408
- #advanceAfterQuestion(): void {
1492
+ /** Move past the current question; `answeredRowKey` is the row whose pick did it, for {@link #noteTarget}. */
1493
+ #advanceAfterQuestion(answeredRowKey?: string): void {
1409
1494
  const current = this.#currentQuestionIndex();
1495
+ this.#justAnswered =
1496
+ answeredRowKey !== undefined && this.#questions.length > 1
1497
+ ? { questionIndex: current, rowKey: answeredRowKey }
1498
+ : undefined;
1410
1499
  if (this.#questions.length === 1) {
1411
1500
  this.#finishSubmit();
1412
1501
  return;
@@ -1458,7 +1547,7 @@ export class AskDialogComponent implements Component {
1458
1547
  this.#activeTabIndex = this.#submitTabIndex();
1459
1548
  this.#submitScrollOffset = 0;
1460
1549
  } else {
1461
- this.#advanceAfterQuestion();
1550
+ this.#advanceAfterQuestion(rowItem.key);
1462
1551
  }
1463
1552
  } finally {
1464
1553
  this.#promptActive = false;
@@ -1590,7 +1679,7 @@ export class AskDialogComponent implements Component {
1590
1679
  const label = questionTabLabel(question, index);
1591
1680
  const answer = renderAnswerSummary(question, state);
1592
1681
  allLines.push(`${theme.fg("dim", `${index + 1}. ${label}:`)} ${answer}`);
1593
- const submittedNote = noteForSubmittedAnswer(question, state);
1682
+ const submittedNote = noteForSubmittedAnswer(question, state)?.text;
1594
1683
  if (submittedNote?.trim()) {
1595
1684
  const note = normalizedInlineInput(submittedNote);
1596
1685
  allLines.push(
@@ -1724,8 +1813,9 @@ export class AskDialogComponent implements Component {
1724
1813
  selectedOptions,
1725
1814
  customInput: state.customInput,
1726
1815
  customInputImages: state.customInputImages,
1727
- note,
1816
+ note: note?.text,
1728
1817
  noteImages: note === undefined ? undefined : state.noteImages,
1818
+ noteOption: note?.option,
1729
1819
  timedOut: state.timedOut || undefined,
1730
1820
  });
1731
1821
  }
@@ -1,3 +1,4 @@
1
+ import type { ImageContent } from "@linxiraos/pi-ai";
1
2
  import {
2
3
  type Component,
3
4
  type Focusable,
@@ -15,8 +16,12 @@ import {
15
16
  type BtwHistoryTurn,
16
17
  getBtwCopyText,
17
18
  getBtwLatestTurn,
19
+ getBtwTopicLabel,
18
20
  getBtwTurns,
19
21
  } from "./btw-history";
22
+ import { compactImageMarkers, formatVisionMarker } from "../prompt/composer-attachments";
23
+ import { extractImagePastePathsFromText } from "../prompt/custom-editor";
24
+ import { BracketedPasteHandler } from "../bracketed-paste";
20
25
  import { getMarkdownTheme, type ThemeColor, theme } from "../theme/theme";
21
26
  import {
22
27
  matchesSelectCancel,
@@ -39,13 +44,28 @@ import type { NativeChild, NativeNode, NativeScroll, NativeUiEvent } from "../na
39
44
  import { col, md, node, span, text } from "../native/describe";
40
45
  import { actionBar, actionButton } from "../native/overlay";
41
46
 
47
+ /** The turns as shown: a titled topic's opening question displays as its title, e.g. `/sitrep`. */
48
+ function getDisplayTurns(record: BtwHistoryRecord): readonly BtwHistoryTurn[] {
49
+ const turns = getBtwTurns(record);
50
+ return record.title === undefined ? turns : [{ ...turns[0]!, question: record.title }, ...turns.slice(1)];
51
+ }
52
+
42
53
  interface BtwHistoryPanelOptions {
43
54
  records: readonly BtwHistoryRecord[];
44
55
  onClose: () => void;
45
56
  onCopy: (record: BtwHistoryRecord) => void;
46
57
  onCancel: (record: BtwHistoryRecord) => void;
47
58
  canFollowUp?: (record: BtwHistoryRecord) => boolean;
48
- onFollowUp?: (record: BtwHistoryRecord, question: string, signal: AbortSignal) => Promise<boolean>;
59
+ onFollowUp?: (
60
+ record: BtwHistoryRecord,
61
+ question: string,
62
+ signal: AbortSignal,
63
+ images?: ImageContent[],
64
+ ) => Promise<boolean>;
65
+ /** Read a clipboard image into the follow-up (an empty paste, as terminals send for one). */
66
+ onPasteImage?: () => Promise<unknown>;
67
+ /** Attach an image file whose path was pasted or dropped into the follow-up. */
68
+ onPasteImagePath?: (path: string) => Promise<void>;
49
69
  /** Configured push-to-talk keys for a follow-up composer. */
50
70
  spaceHoldKeys?: readonly KeyId[];
51
71
  spaceHold?: (input: Input) => SpaceHoldHandler;
@@ -63,6 +83,11 @@ interface FollowUpComposer {
63
83
  recordId: string;
64
84
  input: Input;
65
85
  abortController: AbortController;
86
+ /** Images pasted into this follow-up, numbered by their `[Image #N]` markers. */
87
+ images: ImageContent[];
88
+ /** Image pastes still loading, in paste order; Enter waits for them. */
89
+ pendingPastes: { settled: boolean; text: string | undefined }[];
90
+ submitQueued: boolean;
66
91
  notice?: string;
67
92
  }
68
93
 
@@ -126,6 +151,7 @@ export class BtwHistoryPanel implements Component, Focusable {
126
151
  #listHeight = 1;
127
152
  #focused = false;
128
153
  #composer: FollowUpComposer | undefined;
154
+ readonly #pasteHandler = new BracketedPasteHandler();
129
155
  #followUpPending = false;
130
156
  #followLatest = false;
131
157
  #turns: RenderedTurn[] = [];
@@ -305,7 +331,14 @@ export class BtwHistoryPanel implements Component, Focusable {
305
331
  input.placeholder = "Ask about this answer…";
306
332
  if (this.#options.spaceHoldKeys !== undefined) input.spaceHold.keys = this.#options.spaceHoldKeys;
307
333
  input.spaceHold.handler = this.#options.spaceHold?.(input);
308
- const composer: FollowUpComposer = { recordId: record.id, input, abortController: new AbortController() };
334
+ const composer: FollowUpComposer = {
335
+ recordId: record.id,
336
+ input,
337
+ abortController: new AbortController(),
338
+ images: [],
339
+ pendingPastes: [],
340
+ submitQueued: false,
341
+ };
309
342
  input.onEscape = () => {
310
343
  composer.abortController.abort();
311
344
  this.#composer = undefined;
@@ -322,7 +355,11 @@ export class BtwHistoryPanel implements Component, Focusable {
322
355
 
323
356
  async #submitFollowUp(composer: FollowUpComposer, value: string): Promise<void> {
324
357
  if (this.#followUpPending || this.#composer !== composer) return;
325
- const question = value.trim();
358
+ if (composer.pendingPastes.length > 0) {
359
+ composer.submitQueued = true;
360
+ return;
361
+ }
362
+ let question = value.trim();
326
363
  if (!question) {
327
364
  composer.notice = "Enter a follow-up question.";
328
365
  return;
@@ -335,8 +372,20 @@ export class BtwHistoryPanel implements Component, Focusable {
335
372
  this.#followUpPending = true;
336
373
  composer.notice = "Starting follow-up…";
337
374
  this.#options.requestRender();
375
+ let images: ImageContent[] | undefined;
376
+ if (composer.images.length > 0) {
377
+ // Path pastes attach as they finish loading; submit numbers images in text order.
378
+ const compacted = compactImageMarkers(question, composer.images.length, { byAppearance: true });
379
+ images = compacted ? compacted.keep.map(index => composer.images[index]!) : composer.images;
380
+ if (compacted) question = compacted.text.trim();
381
+ }
338
382
  try {
339
- const accepted = await this.#options.onFollowUp!(record, question, composer.abortController.signal);
383
+ const accepted = await this.#options.onFollowUp!(
384
+ record,
385
+ question,
386
+ composer.abortController.signal,
387
+ images?.length ? images : undefined,
388
+ );
340
389
  if (this.#composer !== composer) return;
341
390
  if (accepted) {
342
391
  this.#composer = undefined;
@@ -361,14 +410,74 @@ export class BtwHistoryPanel implements Component, Focusable {
361
410
  return this.#composer?.input.capturesInput(data) ?? false;
362
411
  }
363
412
 
364
- /** Enhanced clipboard pastes belong only to the active composer. */
413
+ /** False while a follow-up is sent: it already took its images, and the composer clears after. */
414
+ get acceptsImages(): boolean {
415
+ return this.#composer !== undefined && !this.#followUpPending;
416
+ }
417
+
418
+ /** Attach an image to the follow-up; returns its `[Image #N, WxH]` marker to paste. */
419
+ attachImage(image: ImageContent, dims?: { width: number; height: number }): string | undefined {
420
+ const composer = this.#composer;
421
+ if (!composer || this.#followUpPending) return undefined;
422
+ composer.images.push(image);
423
+ return formatVisionMarker("image", composer.images.length, dims);
424
+ }
425
+
426
+ /** Reserve ordered delivery for an image paste. Completion delivers its marker once, or releases on undefined. */
427
+ beginPaste(): (text: string | undefined) => boolean {
428
+ const composer = this.#composer;
429
+ if (!composer) return () => false;
430
+ const pending: { settled: boolean; text: string | undefined } = { settled: false, text: undefined };
431
+ composer.pendingPastes.push(pending);
432
+ return text => {
433
+ if (this.#composer !== composer || pending.settled) return false;
434
+ pending.settled = true;
435
+ pending.text = text;
436
+ // A failed read releases the wait, but must not send the follow-up without its image.
437
+ if (!text) composer.submitQueued = false;
438
+ let delivered = 0;
439
+ for (const paste of composer.pendingPastes) {
440
+ if (!paste.settled) break;
441
+ if (paste.text) composer.input.pasteText(paste.text);
442
+ delivered++;
443
+ }
444
+ composer.pendingPastes.splice(0, delivered);
445
+ if (composer.pendingPastes.length === 0 && composer.submitQueued) {
446
+ composer.submitQueued = false;
447
+ void this.#submitFollowUp(composer, composer.input.getValue());
448
+ }
449
+ this.#options.requestRender();
450
+ return !!text;
451
+ };
452
+ }
453
+
454
+ /** Enhanced clipboard pastes belong only to the active composer, behind any image still loading. */
365
455
  pasteText(text: string): void {
366
- if (!this.#composer) return;
367
- this.#composer.input.pasteText(text);
456
+ const composer = this.#composer;
457
+ if (!composer) return;
458
+ if (composer.pendingPastes.length > 0) this.beginPaste()(text);
459
+ else composer.input.pasteText(text);
368
460
  this.#options.requestRender();
369
461
  }
462
+
463
+ /** A pasted image path or an empty (clipboard image) paste attaches an image; other text is typed. */
464
+ #paste(content: string): void {
465
+ const imagePaths = extractImagePastePathsFromText(content);
466
+ if (content.length === 0 && this.#options.onPasteImage) void this.#options.onPasteImage();
467
+ else if (imagePaths && this.#options.onPasteImagePath) {
468
+ for (const path of imagePaths) void this.#options.onPasteImagePath(path);
469
+ } else this.pasteText(content);
470
+ }
471
+
370
472
  handleInput(data: string): void {
371
473
  if (this.#composer) {
474
+ const paste = this.#pasteHandler.process(data);
475
+ if (paste.handled) {
476
+ if (paste.pasteContent !== undefined) this.#paste(paste.pasteContent);
477
+ if (paste.remaining.length > 0) this.handleInput(paste.remaining);
478
+ this.#options.requestRender();
479
+ return;
480
+ }
372
481
  // The input owns every key it handles, including panel shortcuts and
373
482
  // pasted text; the line keys it ignores still scroll the answer above.
374
483
  if (!this.#composer.input.handleInput(data)) this.#scrollDetail(data);
@@ -564,7 +673,7 @@ export class BtwHistoryPanel implements Component, Focusable {
564
673
  if (followUps > 0) detail.push(span(` · ${followUps} follow-up${followUps === 1 ? "" : "s"}`));
565
674
  const status = describeStatus(getBtwLatestTurn(record).status);
566
675
  // The question is markdown: its `code` reads as mono, without the backticks.
567
- const label = sanitizeDisplayLine(record.question)
676
+ const label = sanitizeDisplayLine(getBtwTopicLabel(record))
568
677
  .split(/`([^`]+)`/)
569
678
  .flatMap((part, index) => (part ? [span(part, index % 2 === 1 ? "mono" : undefined)] : []));
570
679
  return node("item", { label, detail, ...(status ? { value: status } : {}) }, undefined, record.id);
@@ -580,7 +689,7 @@ export class BtwHistoryPanel implements Component, Focusable {
580
689
 
581
690
  /** The selected side question as a short document: the asked question titles each answer. */
582
691
  #describeThread(record: BtwHistoryRecord): NativeNode {
583
- const turns = getBtwTurns(record);
692
+ const turns = getDisplayTurns(record);
584
693
  const children: NativeChild[] = turns.map((turn, index) => this.#describeTurn(turn, index, `turn-${index}`));
585
694
  if (this.#composer) children.push(this.#describeComposer(this.#composer));
586
695
  return node("col", { role: "zeta.btw.thread" }, children, "thread");
@@ -703,7 +812,7 @@ export class BtwHistoryPanel implements Component, Focusable {
703
812
  const time = theme.fg("dim", this.#timeFormat.format(record.createdAt));
704
813
  const badge = theme.fg(status.color, status.label);
705
814
  const prefix = `${cursor} ${time} ${badge} `;
706
- const question = sanitizeDisplayLine(record.question);
815
+ const question = sanitizeDisplayLine(getBtwTopicLabel(record));
707
816
  const snippet = truncateToWidth(
708
817
  question,
709
818
  Math.max(0, contentWidth - (rowSpan === 2 ? 2 : visibleWidth(prefix))),
@@ -796,7 +905,7 @@ export class BtwHistoryPanel implements Component, Focusable {
796
905
  lines.push(...wrapTextWithAnsi(theme.fg("success", "✓ Copied to clipboard"), inner), "");
797
906
  }
798
907
  if (record) {
799
- const turns = getBtwTurns(record);
908
+ const turns = getDisplayTurns(record);
800
909
  for (let index = 0; index < turns.length; index++) {
801
910
  const cached = this.#renderTurn(turns[index]!, this.#turns[index], inner);
802
911
  this.#turns[index] = cached;
@@ -871,7 +980,10 @@ export class BtwHistoryPanel implements Component, Focusable {
871
980
  const availableRows = Math.max(1, height - chrome - 1);
872
981
  if (availableRows >= 2) {
873
982
  composerLines.push(
874
- theme.fg("dim", truncateToWidth(`Topic: ${sanitizeDisplayLine(record?.question ?? "")}`, inner)),
983
+ theme.fg(
984
+ "dim",
985
+ truncateToWidth(`Topic: ${sanitizeDisplayLine(record ? getBtwTopicLabel(record) : "")}`, inner),
986
+ ),
875
987
  );
876
988
  }
877
989
  if (composer.notice && availableRows >= 3) {
@@ -1,5 +1,9 @@
1
+ import type { ImageContent } from "@linxiraos/pi-ai";
2
+
1
3
  export interface BtwHistoryTurn {
2
4
  question: string;
5
+ /** Images attached to the question, sent again with it on later follow-ups. */
6
+ images?: readonly ImageContent[];
3
7
  answer: string;
4
8
  status: "running" | "complete" | "cancelled" | "error" | "interrupted";
5
9
  createdAt: number;
@@ -10,9 +14,16 @@ export interface BtwHistoryTurn {
10
14
  export interface BtwHistoryRecord extends BtwHistoryTurn {
11
15
  id: string;
12
16
  leafId: string | null;
17
+ /** Display heading for the topic, e.g. `/sitrep`; `question` keeps the full text sent to the model. */
18
+ title?: string;
13
19
  followUps?: readonly BtwHistoryTurn[];
14
20
  }
15
21
 
22
+ /** The topic's display heading: its title, else the opening question. */
23
+ export function getBtwTopicLabel(record: BtwHistoryRecord): string {
24
+ return record.title ?? record.question;
25
+ }
26
+
16
27
  export function getBtwLatestTurn(record: BtwHistoryRecord): BtwHistoryTurn {
17
28
  return record.followUps?.at(-1) ?? record;
18
29
  }
@@ -14,6 +14,8 @@ type BtwPanelState = "running" | "complete" | "branching" | "aborted" | "error";
14
14
 
15
15
  interface BtwPanelComponentOptions {
16
16
  question: string;
17
+ /** Heading shown instead of `/btw <question>`, e.g. `/sitrep the migration` for a side command. */
18
+ title?: string;
17
19
  tui: TUI;
18
20
  canBranch?: () => boolean;
19
21
  canFollowUp?: () => boolean;
@@ -30,15 +32,13 @@ export class BtwPanelComponent extends OverlayPanel {
30
32
  #closed = false;
31
33
  #copied = false;
32
34
  #baseTitle: string;
33
- readonly #question: string;
34
35
  readonly #content: StreamingPanelContent;
35
36
  #native: { node: NativeNode; canFollowUp: boolean; canBranch: boolean } | undefined;
36
37
 
37
38
  constructor(options: BtwPanelComponentOptions) {
38
- const baseTitle = `/btw ${replaceTabs(options.question)}`;
39
+ const baseTitle = replaceTabs(options.title ?? `/btw ${options.question}`);
39
40
  super(baseTitle, "zeta.overlay.btw");
40
41
  this.#baseTitle = baseTitle;
41
- this.#question = replaceTabs(options.question);
42
42
  this.#tui = options.tui;
43
43
  this.#canBranch = options.canBranch;
44
44
  this.#canFollowUp = options.canFollowUp;
@@ -138,7 +138,11 @@ export class BtwPanelComponent extends OverlayPanel {
138
138
  const memo = this.#native;
139
139
  if (memo && memo.canFollowUp === canFollowUp && memo.canBranch === canBranch) return memo.node;
140
140
  // Inline in the dock, styled as a sheet by role: a borderless column headed by the question.
141
- const title = text([span("/btw", "accent"), span(` ${this.#question}`)], { truncate: "end", lines: 1 });
141
+ // The command word is the accent; the rest of the heading is the question or arguments.
142
+ const space = this.#baseTitle.indexOf(" ");
143
+ const command = space === -1 ? this.#baseTitle : this.#baseTitle.slice(0, space);
144
+ const rest = space === -1 ? "" : this.#baseTitle.slice(space);
145
+ const title = text([span(command, "accent"), ...(rest ? [span(rest)] : [])], { truncate: "end", lines: 1 });
142
146
  const live = this.#state === "running" || this.#state === "branching";
143
147
  const head = node("row", { role: "zeta.sheet.head", gap: "sm", align: "center" }, [
144
148
  ...(live ? [node("spinner", {})] : []),