@linxiraos/pi-tui 1.4.6 → 1.4.9

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 (399) hide show
  1. package/CHANGELOG.md +162 -244
  2. package/README.md +41 -35
  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/charts/table-data.d.ts +4 -2
  7. package/dist/types/chat/assistant-message.d.ts +15 -3
  8. package/dist/types/chat/bash-execution.d.ts +6 -1
  9. package/dist/types/chat/display-preferences.d.ts +2 -0
  10. package/dist/types/chat/eval-execution.d.ts +2 -0
  11. package/dist/types/chat/execution-shared.d.ts +14 -8
  12. package/dist/types/chat/extension-types.d.ts +31 -0
  13. package/dist/types/chat/figure-markdown.d.ts +2 -0
  14. package/dist/types/chat/reply-write.d.ts +48 -0
  15. package/dist/types/chat/svg-figure.d.ts +5 -0
  16. package/dist/types/chat/table-chart.d.ts +6 -3
  17. package/dist/types/chat/tool-execution.d.ts +1 -2
  18. package/dist/types/chat/transcript-outline.d.ts +7 -0
  19. package/dist/types/chat/transcript-render-helpers.d.ts +13 -3
  20. package/dist/types/chrome/dynamic-border.d.ts +6 -0
  21. package/dist/types/chrome/index.d.ts +1 -0
  22. package/dist/types/chrome/transcript-notice.d.ts +35 -0
  23. package/dist/types/chrome/transcript-status.d.ts +21 -9
  24. package/dist/types/components/editor.d.ts +23 -6
  25. package/dist/types/components/image.d.ts +6 -0
  26. package/dist/types/components/loader.d.ts +2 -0
  27. package/dist/types/components/markdown.d.ts +7 -0
  28. package/dist/types/keybinding-matchers.d.ts +7 -0
  29. package/dist/types/native/blobs.d.ts +2 -1
  30. package/dist/types/native/describe.d.ts +4 -2
  31. package/dist/types/native/node.d.ts +2 -3
  32. package/dist/types/native/overlay.d.ts +42 -2
  33. package/dist/types/native/picker.d.ts +4 -4
  34. package/dist/types/native/state.d.ts +4 -0
  35. package/dist/types/overlays/annotation-overlay.d.ts +7 -1
  36. package/dist/types/overlays/annotation-types.d.ts +28 -0
  37. package/dist/types/overlays/btw-history-panel.d.ts +15 -0
  38. package/dist/types/overlays/btw-history.d.ts +24 -0
  39. package/dist/types/overlays/btw-inject.d.ts +22 -0
  40. package/dist/types/overlays/btw-panel.d.ts +7 -0
  41. package/dist/types/overlays/hook-editor.d.ts +2 -0
  42. package/dist/types/overlays/jobs-panel.d.ts +4 -0
  43. package/dist/types/overlays/login-dialog.d.ts +5 -1
  44. package/dist/types/overlays/model-browser.d.ts +11 -2
  45. package/dist/types/overlays/oauth-selector.d.ts +23 -0
  46. package/dist/types/overlays/plan-review-overlay.d.ts +2 -0
  47. package/dist/types/overlays/rewind-selector.d.ts +1 -1
  48. package/dist/types/overlays/session-selector.d.ts +33 -4
  49. package/dist/types/prompt/composer.d.ts +56 -5
  50. package/dist/types/prompt/interactive-context-helpers.d.ts +10 -3
  51. package/dist/types/render/extension-links.d.ts +65 -0
  52. package/dist/types/render/hyperlink.d.ts +25 -7
  53. package/dist/types/render/index.d.ts +1 -0
  54. package/dist/types/render/render-utils.d.ts +23 -1
  55. package/dist/types/setup/scenes/glyph.d.ts +1 -1
  56. package/dist/types/setup/scenes/model.d.ts +1 -1
  57. package/dist/types/setup/scenes/outro.d.ts +5 -4
  58. package/dist/types/setup/scenes/sign-in.d.ts +13 -8
  59. package/dist/types/setup/scenes/types.d.ts +16 -1
  60. package/dist/types/setup/startup-splash.d.ts +1 -1
  61. package/dist/types/setup/wizard-overlay.d.ts +11 -7
  62. package/dist/types/setup/wizard.d.ts +5 -1
  63. package/dist/types/status-line/component.d.ts +1 -1
  64. package/dist/types/status-line/context-usage.d.ts +28 -6
  65. package/dist/types/status-line/host.d.ts +6 -2
  66. package/dist/types/status-line/startup.d.ts +0 -15
  67. package/dist/types/terminal-capabilities.d.ts +1 -1
  68. package/dist/types/theme/symbols.d.ts +3 -1
  69. package/dist/types/theme/theme-class.d.ts +1 -0
  70. package/dist/types/theme/theme.d.ts +1 -24
  71. package/dist/types/theme/tui-adapters.d.ts +2 -0
  72. package/dist/types/thinking.d.ts +8 -6
  73. package/dist/types/tools/ast-grep.d.ts +2 -0
  74. package/dist/types/tools/bash-interactive.d.ts +6 -0
  75. package/dist/types/tools/bash.d.ts +2 -0
  76. package/dist/types/tools/default-renderer.d.ts +6 -4
  77. package/dist/types/tools/eval.d.ts +2 -0
  78. package/dist/types/tools/find.d.ts +1 -1
  79. package/dist/types/tools/grouped-file-output.d.ts +100 -19
  80. package/dist/types/tools/hashline-format.d.ts +5 -0
  81. package/dist/types/tools/irc.d.ts +6 -0
  82. package/dist/types/tools/json-tree.d.ts +23 -4
  83. package/dist/types/tools/lsp.d.ts +2 -0
  84. package/dist/types/tools/mcp.d.ts +6 -5
  85. package/dist/types/tools/native-view.d.ts +3 -1
  86. package/dist/types/tools/output-meta.d.ts +27 -0
  87. package/dist/types/tools/read.d.ts +14 -4
  88. package/dist/types/tools/renderer.d.ts +2 -0
  89. package/dist/types/tools/streaming-output.d.ts +11 -0
  90. package/dist/types/tools/task.d.ts +13 -4
  91. package/dist/types/tools/url-scheme-host.d.ts +17 -0
  92. package/dist/types/tools/wait.d.ts +2 -0
  93. package/dist/types/tools/yield.d.ts +1 -1
  94. package/dist/types/tui.d.ts +19 -2
  95. package/dist/types/utils.d.ts +4 -0
  96. package/package.json +10 -14
  97. package/src/app-keybindings.d.ts +20 -0
  98. package/src/app-keybindings.ts +20 -0
  99. package/src/apps/git/git-tui.ts +10 -17
  100. package/src/apps/git/sidebar.ts +21 -35
  101. package/src/apps/ps-top.ts +4 -12
  102. package/src/apps/session-picker.ts +7 -0
  103. package/src/charts/chart-plan.d.ts +9 -7
  104. package/src/charts/chart-plan.ts +20 -79
  105. package/src/charts/table-data.d.ts +4 -2
  106. package/src/charts/table-data.ts +55 -6
  107. package/src/chat/advisor-message.ts +2 -0
  108. package/src/chat/assistant-message.d.ts +15 -3
  109. package/src/chat/assistant-message.ts +137 -19
  110. package/src/chat/background-tan-message.ts +4 -0
  111. package/src/chat/bash-execution.d.ts +6 -1
  112. package/src/chat/bash-execution.ts +26 -9
  113. package/src/chat/chat-transcript-builder.ts +63 -30
  114. package/src/chat/compaction-summary-message.ts +2 -1
  115. package/src/chat/display-preferences.d.ts +2 -0
  116. package/src/chat/display-preferences.ts +3 -0
  117. package/src/chat/eval-execution.d.ts +2 -0
  118. package/src/chat/eval-execution.ts +14 -7
  119. package/src/chat/execution-shared.d.ts +14 -8
  120. package/src/chat/execution-shared.ts +39 -18
  121. package/src/chat/extension-types.d.ts +31 -0
  122. package/src/chat/extension-types.ts +34 -0
  123. package/src/chat/figure-markdown.d.ts +2 -0
  124. package/src/chat/figure-markdown.ts +6 -4
  125. package/src/chat/read-tool-group.ts +56 -36
  126. package/src/chat/reply-write.d.ts +48 -0
  127. package/src/chat/reply-write.ts +127 -0
  128. package/src/chat/svg-figure.d.ts +5 -0
  129. package/src/chat/svg-figure.ts +55 -16
  130. package/src/chat/table-chart.d.ts +6 -3
  131. package/src/chat/table-chart.ts +29 -6
  132. package/src/chat/tool-execution.d.ts +1 -2
  133. package/src/chat/tool-execution.ts +20 -13
  134. package/src/chat/transcript-outline.d.ts +7 -0
  135. package/src/chat/transcript-outline.ts +27 -0
  136. package/src/chat/transcript-render-helpers.d.ts +13 -3
  137. package/src/chat/transcript-render-helpers.ts +134 -44
  138. package/src/chrome/dynamic-border.d.ts +6 -0
  139. package/src/chrome/dynamic-border.ts +28 -2
  140. package/src/chrome/index.ts +1 -0
  141. package/src/chrome/transcript-notice.d.ts +35 -0
  142. package/src/chrome/transcript-notice.ts +83 -0
  143. package/src/chrome/transcript-status.d.ts +21 -9
  144. package/src/chrome/transcript-status.ts +32 -30
  145. package/src/components/editor.d.ts +23 -6
  146. package/src/components/editor.ts +133 -25
  147. package/src/components/image.d.ts +6 -0
  148. package/src/components/image.ts +13 -0
  149. package/src/components/key-value-list.ts +9 -9
  150. package/src/components/loader.d.ts +2 -0
  151. package/src/components/loader.ts +7 -0
  152. package/src/components/markdown.d.ts +7 -0
  153. package/src/components/markdown.ts +116 -6
  154. package/src/components/section.ts +1 -9
  155. package/src/components/table.ts +1 -9
  156. package/src/hotkeys-markdown.ts +1 -0
  157. package/src/keybinding-matchers.d.ts +7 -0
  158. package/src/keybinding-matchers.ts +13 -0
  159. package/src/native/backend.ts +10 -67
  160. package/src/native/blobs.d.ts +2 -1
  161. package/src/native/blobs.ts +3 -2
  162. package/src/native/describe.d.ts +4 -2
  163. package/src/native/describe.ts +9 -4
  164. package/src/native/node.d.ts +2 -3
  165. package/src/native/node.ts +2 -3
  166. package/src/native/overlay.d.ts +42 -2
  167. package/src/native/overlay.ts +124 -16
  168. package/src/native/picker.d.ts +4 -4
  169. package/src/native/picker.ts +4 -4
  170. package/src/native/state.d.ts +4 -0
  171. package/src/native/state.ts +25 -5
  172. package/src/overlays/advisor-config.ts +1 -10
  173. package/src/overlays/annotation-overlay.ts +125 -37
  174. package/src/overlays/annotation-types.ts +24 -0
  175. package/src/overlays/btw-history-panel.ts +106 -14
  176. package/src/overlays/btw-history.ts +65 -0
  177. package/src/overlays/btw-inject.ts +91 -0
  178. package/src/overlays/btw-panel.ts +53 -12
  179. package/src/overlays/extensions/extension-dashboard.ts +7 -8
  180. package/src/overlays/hook-editor.ts +6 -0
  181. package/src/overlays/hook-selector.ts +2 -2
  182. package/src/overlays/jobs-panel.ts +82 -22
  183. package/src/overlays/login-dialog.ts +39 -31
  184. package/src/overlays/mcp-add-wizard.ts +1 -1
  185. package/src/overlays/model-browser.ts +106 -10
  186. package/src/overlays/model-hub.ts +1 -7
  187. package/src/overlays/model-picker.ts +1 -10
  188. package/src/overlays/oauth-selector.ts +44 -6
  189. package/src/overlays/plan-review-overlay.ts +13 -2
  190. package/src/overlays/rewind-selector.ts +29 -12
  191. package/src/overlays/session-selector.ts +338 -47
  192. package/src/overlays/settings-defs.ts +2 -2
  193. package/src/overlays/tree-selector.ts +83 -27
  194. package/src/overlays/usage-dashboard.ts +9 -18
  195. package/src/prompt/composer.ts +233 -6
  196. package/src/prompt/custom-editor.ts +6 -1
  197. package/src/prompt/emoji-autocomplete.ts +0 -2
  198. package/src/prompt/interactive-context-helpers.ts +29 -4
  199. package/src/render/code-cell.ts +1 -1
  200. package/src/render/extension-links.d.ts +65 -0
  201. package/src/render/extension-links.ts +214 -0
  202. package/src/render/file-list.ts +4 -7
  203. package/src/render/hyperlink.d.ts +25 -7
  204. package/src/render/hyperlink.ts +65 -9
  205. package/src/render/index.d.ts +1 -0
  206. package/src/render/index.ts +1 -0
  207. package/src/render/render-utils.d.ts +23 -1
  208. package/src/render/render-utils.ts +38 -6
  209. package/src/setup/scenes/composer.ts +2 -0
  210. package/src/setup/scenes/glyph.ts +4 -2
  211. package/src/setup/scenes/model.ts +192 -29
  212. package/src/setup/scenes/outro.ts +33 -15
  213. package/src/setup/scenes/sign-in.ts +196 -400
  214. package/src/setup/scenes/theme.ts +2 -0
  215. package/src/setup/scenes/types.ts +18 -1
  216. package/src/setup/startup-splash.ts +8 -7
  217. package/src/setup/wizard-overlay.ts +164 -35
  218. package/src/setup/wizard.ts +11 -2
  219. package/src/status-line/component.ts +4 -10
  220. package/src/status-line/context-usage.ts +72 -21
  221. package/src/status-line/host.ts +6 -2
  222. package/src/status-line/startup.ts +36 -70
  223. package/src/terminal-capabilities.d.ts +1 -1
  224. package/src/terminal-capabilities.ts +5 -0
  225. package/src/terminal.ts +24 -2
  226. package/src/theme/defaults.json +1 -0
  227. package/src/theme/loader.ts +1 -1
  228. package/src/theme/symbols.d.ts +3 -1
  229. package/src/theme/symbols.ts +16 -9
  230. package/src/theme/theme-class.d.ts +1 -0
  231. package/src/theme/theme-class.ts +15 -3
  232. package/src/theme/theme.d.ts +1 -24
  233. package/src/theme/theme.ts +3 -75
  234. package/src/theme/tui-adapters.d.ts +2 -0
  235. package/src/theme/tui-adapters.ts +8 -3
  236. package/src/thinking.d.ts +8 -6
  237. package/src/thinking.ts +17 -11
  238. package/src/tmux.ts +1 -0
  239. package/src/tools/agent-tree.ts +13 -11
  240. package/src/tools/ask.ts +24 -37
  241. package/src/tools/ast-edit.ts +48 -93
  242. package/src/tools/ast-grep.d.ts +2 -0
  243. package/src/tools/ast-grep.ts +31 -67
  244. package/src/tools/bash-interactive.d.ts +49 -0
  245. package/src/tools/bash-interactive.ts +6 -1
  246. package/src/tools/bash.d.ts +2 -0
  247. package/src/tools/bash.ts +9 -0
  248. package/src/tools/default-renderer.d.ts +6 -4
  249. package/src/tools/default-renderer.ts +10 -7
  250. package/src/tools/edit.ts +50 -43
  251. package/src/tools/eval.d.ts +2 -0
  252. package/src/tools/eval.ts +16 -4
  253. package/src/tools/fetch.ts +2 -1
  254. package/src/tools/find.d.ts +1 -1
  255. package/src/tools/find.ts +13 -5
  256. package/src/tools/github.ts +14 -46
  257. package/src/tools/glob.ts +2 -1
  258. package/src/tools/grep.ts +47 -277
  259. package/src/tools/grouped-file-output.d.ts +100 -19
  260. package/src/tools/grouped-file-output.ts +414 -103
  261. package/src/tools/hashline-format.d.ts +5 -0
  262. package/src/tools/hashline-format.ts +5 -0
  263. package/src/tools/irc.d.ts +6 -0
  264. package/src/tools/irc.ts +6 -0
  265. package/src/tools/job-widget.ts +13 -1
  266. package/src/tools/json-tree.d.ts +23 -4
  267. package/src/tools/json-tree.ts +132 -46
  268. package/src/tools/lsp.d.ts +2 -0
  269. package/src/tools/lsp.ts +246 -47
  270. package/src/tools/mcp.d.ts +6 -5
  271. package/src/tools/mcp.ts +20 -12
  272. package/src/tools/native-view.d.ts +3 -1
  273. package/src/tools/native-view.ts +12 -6
  274. package/src/tools/output-meta.d.ts +27 -0
  275. package/src/tools/output-meta.ts +68 -4
  276. package/src/tools/proc-render.ts +3 -3
  277. package/src/tools/read.d.ts +14 -4
  278. package/src/tools/read.ts +20 -5
  279. package/src/tools/renderer.d.ts +2 -0
  280. package/src/tools/renderer.ts +2 -0
  281. package/src/tools/streaming-output.d.ts +11 -0
  282. package/src/tools/streaming-output.ts +41 -0
  283. package/src/tools/task.d.ts +13 -4
  284. package/src/tools/task.ts +100 -97
  285. package/src/tools/url-scheme-host.d.ts +17 -0
  286. package/src/tools/url-scheme-host.ts +21 -0
  287. package/src/tools/vibe.ts +4 -4
  288. package/src/tools/wait.d.ts +2 -0
  289. package/src/tools/wait.ts +8 -5
  290. package/src/tools/write.ts +17 -27
  291. package/src/tools/yield.d.ts +1 -1
  292. package/src/tools/yield.ts +19 -10
  293. package/src/tui.d.ts +19 -2
  294. package/src/tui.ts +134 -24
  295. package/src/utils.d.ts +4 -0
  296. package/src/utils.ts +10 -0
  297. package/dist/types/theme/defaults/index.d.ts +0 -10289
  298. package/src/theme/defaults/alabaster.json +0 -103
  299. package/src/theme/defaults/amethyst.json +0 -106
  300. package/src/theme/defaults/anthracite.json +0 -103
  301. package/src/theme/defaults/basalt.json +0 -101
  302. package/src/theme/defaults/birch.json +0 -105
  303. package/src/theme/defaults/dark-abyss.json +0 -101
  304. package/src/theme/defaults/dark-arctic.json +0 -114
  305. package/src/theme/defaults/dark-aurora.json +0 -105
  306. package/src/theme/defaults/dark-catppuccin.json +0 -117
  307. package/src/theme/defaults/dark-cavern.json +0 -101
  308. package/src/theme/defaults/dark-celestial.json +0 -116
  309. package/src/theme/defaults/dark-copper.json +0 -105
  310. package/src/theme/defaults/dark-cosmos.json +0 -100
  311. package/src/theme/defaults/dark-cyberpunk.json +0 -112
  312. package/src/theme/defaults/dark-dracula.json +0 -108
  313. package/src/theme/defaults/dark-eclipse.json +0 -101
  314. package/src/theme/defaults/dark-ember.json +0 -105
  315. package/src/theme/defaults/dark-equinox.json +0 -100
  316. package/src/theme/defaults/dark-forest.json +0 -106
  317. package/src/theme/defaults/dark-github.json +0 -115
  318. package/src/theme/defaults/dark-gruvbox.json +0 -122
  319. package/src/theme/defaults/dark-lavender.json +0 -105
  320. package/src/theme/defaults/dark-lunar.json +0 -99
  321. package/src/theme/defaults/dark-midnight.json +0 -105
  322. package/src/theme/defaults/dark-monochrome.json +0 -104
  323. package/src/theme/defaults/dark-monokai.json +0 -108
  324. package/src/theme/defaults/dark-nebula.json +0 -100
  325. package/src/theme/defaults/dark-neon-noir.json +0 -110
  326. package/src/theme/defaults/dark-nord.json +0 -108
  327. package/src/theme/defaults/dark-ocean.json +0 -111
  328. package/src/theme/defaults/dark-one.json +0 -110
  329. package/src/theme/defaults/dark-poimandres.json +0 -125
  330. package/src/theme/defaults/dark-rainforest.json +0 -101
  331. package/src/theme/defaults/dark-reef.json +0 -101
  332. package/src/theme/defaults/dark-retro.json +0 -102
  333. package/src/theme/defaults/dark-rose-pine.json +0 -106
  334. package/src/theme/defaults/dark-sakura.json +0 -105
  335. package/src/theme/defaults/dark-slate.json +0 -105
  336. package/src/theme/defaults/dark-solarized.json +0 -107
  337. package/src/theme/defaults/dark-solstice.json +0 -100
  338. package/src/theme/defaults/dark-starfall.json +0 -101
  339. package/src/theme/defaults/dark-sunset.json +0 -109
  340. package/src/theme/defaults/dark-swamp.json +0 -100
  341. package/src/theme/defaults/dark-synthwave.json +0 -113
  342. package/src/theme/defaults/dark-taiga.json +0 -101
  343. package/src/theme/defaults/dark-terminal.json +0 -105
  344. package/src/theme/defaults/dark-tokyo-night.json +0 -111
  345. package/src/theme/defaults/dark-tundra.json +0 -101
  346. package/src/theme/defaults/dark-twilight.json +0 -101
  347. package/src/theme/defaults/dark-volcanic.json +0 -101
  348. package/src/theme/defaults/graphite.json +0 -102
  349. package/src/theme/defaults/index.d.ts +0 -10289
  350. package/src/theme/defaults/index.ts +0 -203
  351. package/src/theme/defaults/light-arctic.json +0 -117
  352. package/src/theme/defaults/light-aurora-day.json +0 -101
  353. package/src/theme/defaults/light-canyon.json +0 -101
  354. package/src/theme/defaults/light-catppuccin.json +0 -116
  355. package/src/theme/defaults/light-cirrus.json +0 -100
  356. package/src/theme/defaults/light-coral.json +0 -105
  357. package/src/theme/defaults/light-cyberpunk.json +0 -106
  358. package/src/theme/defaults/light-dawn.json +0 -100
  359. package/src/theme/defaults/light-dunes.json +0 -101
  360. package/src/theme/defaults/light-eucalyptus.json +0 -105
  361. package/src/theme/defaults/light-forest.json +0 -110
  362. package/src/theme/defaults/light-frost.json +0 -105
  363. package/src/theme/defaults/light-github.json +0 -125
  364. package/src/theme/defaults/light-glacier.json +0 -101
  365. package/src/theme/defaults/light-gruvbox.json +0 -118
  366. package/src/theme/defaults/light-haze.json +0 -100
  367. package/src/theme/defaults/light-honeycomb.json +0 -105
  368. package/src/theme/defaults/light-lagoon.json +0 -101
  369. package/src/theme/defaults/light-lavender.json +0 -105
  370. package/src/theme/defaults/light-meadow.json +0 -101
  371. package/src/theme/defaults/light-mint.json +0 -105
  372. package/src/theme/defaults/light-monochrome.json +0 -111
  373. package/src/theme/defaults/light-ocean.json +0 -109
  374. package/src/theme/defaults/light-one.json +0 -109
  375. package/src/theme/defaults/light-opal.json +0 -101
  376. package/src/theme/defaults/light-orchard.json +0 -101
  377. package/src/theme/defaults/light-paper.json +0 -105
  378. package/src/theme/defaults/light-poimandres.json +0 -125
  379. package/src/theme/defaults/light-prism.json +0 -100
  380. package/src/theme/defaults/light-retro.json +0 -108
  381. package/src/theme/defaults/light-sand.json +0 -105
  382. package/src/theme/defaults/light-savanna.json +0 -101
  383. package/src/theme/defaults/light-solarized.json +0 -112
  384. package/src/theme/defaults/light-soleil.json +0 -100
  385. package/src/theme/defaults/light-sunset.json +0 -109
  386. package/src/theme/defaults/light-synthwave.json +0 -108
  387. package/src/theme/defaults/light-tokyo-night.json +0 -121
  388. package/src/theme/defaults/light-wetland.json +0 -101
  389. package/src/theme/defaults/light-zenith.json +0 -99
  390. package/src/theme/defaults/limestone.json +0 -104
  391. package/src/theme/defaults/mahogany.json +0 -107
  392. package/src/theme/defaults/marble.json +0 -103
  393. package/src/theme/defaults/obsidian.json +0 -101
  394. package/src/theme/defaults/onyx.json +0 -101
  395. package/src/theme/defaults/pearl.json +0 -103
  396. package/src/theme/defaults/porcelain.json +0 -101
  397. package/src/theme/defaults/quartz.json +0 -106
  398. package/src/theme/defaults/sandstone.json +0 -105
  399. package/src/theme/defaults/titanium.json +0 -100
@@ -1,3 +1,4 @@
1
+ import type { AssistantMessage } from "@linxiraos/pi-ai";
1
2
  import type { Component, TUI } from "../tui";
2
3
  import type { Theme } from "../theme/theme";
3
4
  import type { CustomMessage, HookMessage } from "./messages";
@@ -17,6 +18,36 @@ export interface AssistantThinkingRenderContext {
17
18
  requestRender(): void;
18
19
  }
19
20
  export type AssistantThinkingRenderer = (context: AssistantThinkingRenderContext, theme: Theme) => Component | undefined;
21
+ export interface AssistantTextRenderContext {
22
+ /**
23
+ * The message being drawn; `message.timestamp` identifies the reply for `ctx.ui.rerenderMessage()`.
24
+ * After a tool call this is only the segment drawn there, so its `content` does not hold the whole reply.
25
+ * A deep copy: editing it, at any depth, cannot change the stored reply.
26
+ */
27
+ message: AssistantMessage;
28
+ /**
29
+ * The text block's index in the full reply's `content`, also when the reply is drawn in segments
30
+ * around tool calls; not an index into `message.content` for a segment. It counts the content as
31
+ * currently stored: a transcript rebuild that drops tool calls left without a result shifts later
32
+ * blocks down, so do not persist it as a permanent key.
33
+ */
34
+ contentIndex: number;
35
+ /** The block's markdown as drawn so far, after any earlier renderer. */
36
+ text: string;
37
+ /** True while the block may still grow; false for its final render, a block sealed at a tool call, and later redraws. */
38
+ streaming: boolean;
39
+ }
40
+ /**
41
+ * Display-only transform of one assistant text block: returns the markdown to draw, or `undefined`
42
+ * to draw `context.text` unchanged. The session, exports and model context keep the original text.
43
+ */
44
+ export type AssistantTextRenderer = (context: AssistantTextRenderContext) => string | undefined;
45
+ /** Extension text renderers for one assistant component, and where its content starts in the full reply. */
46
+ export interface AssistantTextRendering {
47
+ renderers: readonly AssistantTextRenderer[];
48
+ /** Index in the full reply's `content` of this component's first block; a segment after a tool call starts past it. */
49
+ contentOffset: number;
50
+ }
20
51
  export interface HookMessageRenderOptions {
21
52
  /** Whether the view is expanded */
22
53
  expanded: boolean;
@@ -1,3 +1,4 @@
1
+ import type { AssistantMessage } from "@linxiraos/pi-ai";
1
2
  import type { Component, TUI } from "../tui";
2
3
  import type { Theme } from "../theme/theme";
3
4
  import type { CustomMessage, HookMessage } from "./messages";
@@ -30,6 +31,39 @@ export type AssistantThinkingRenderer = (
30
31
  theme: Theme,
31
32
  ) => Component | undefined;
32
33
 
34
+ export interface AssistantTextRenderContext {
35
+ /**
36
+ * The message being drawn; `message.timestamp` identifies the reply for `ctx.ui.rerenderMessage()`.
37
+ * After a tool call this is only the segment drawn there, so its `content` does not hold the whole reply.
38
+ * A deep copy: editing it, at any depth, cannot change the stored reply.
39
+ */
40
+ message: AssistantMessage;
41
+ /**
42
+ * The text block's index in the full reply's `content`, also when the reply is drawn in segments
43
+ * around tool calls; not an index into `message.content` for a segment. It counts the content as
44
+ * currently stored: a transcript rebuild that drops tool calls left without a result shifts later
45
+ * blocks down, so do not persist it as a permanent key.
46
+ */
47
+ contentIndex: number;
48
+ /** The block's markdown as drawn so far, after any earlier renderer. */
49
+ text: string;
50
+ /** True while the block may still grow; false for its final render, a block sealed at a tool call, and later redraws. */
51
+ streaming: boolean;
52
+ }
53
+
54
+ /**
55
+ * Display-only transform of one assistant text block: returns the markdown to draw, or `undefined`
56
+ * to draw `context.text` unchanged. The session, exports and model context keep the original text.
57
+ */
58
+ export type AssistantTextRenderer = (context: AssistantTextRenderContext) => string | undefined;
59
+
60
+ /** Extension text renderers for one assistant component, and where its content starts in the full reply. */
61
+ export interface AssistantTextRendering {
62
+ renderers: readonly AssistantTextRenderer[];
63
+ /** Index in the full reply's `content` of this component's first block; a segment after a tool call starts past it. */
64
+ contentOffset: number;
65
+ }
66
+
33
67
  export interface HookMessageRenderOptions {
34
68
  /** Whether the view is expanded */
35
69
  expanded: boolean;
@@ -8,6 +8,8 @@ export interface FigureMarkdownOptions {
8
8
  charts: boolean;
9
9
  /** Shared inline-image budget for the figures. */
10
10
  budget?: ImageBudget;
11
+ /** Rows each figure may fill, read on every render; callers reserve prose, chrome and separators themselves. Unset or `undefined` takes a share of the terminal viewport. */
12
+ maxRows?: () => number | undefined;
11
13
  /** A figure's rows changed outside a text update (raster landed, fell back to code). */
12
14
  onChange: () => void;
13
15
  }
@@ -14,6 +14,8 @@ export interface FigureMarkdownOptions {
14
14
  charts: boolean;
15
15
  /** Shared inline-image budget for the figures. */
16
16
  budget?: ImageBudget;
17
+ /** Rows each figure may fill, read on every render; callers reserve prose, chrome and separators themselves. Unset or `undefined` takes a share of the terminal viewport. */
18
+ maxRows?: () => number | undefined;
17
19
  /** A figure's rows changed outside a text update (raster landed, fell back to code). */
18
20
  onChange: () => void;
19
21
  }
@@ -108,8 +110,8 @@ export class FigureMarkdown extends Container {
108
110
  return old;
109
111
  }
110
112
  reshaped = true;
111
- const { budget, onChange } = this.#options;
112
- return { kind: "chart", figure: new TableChartFigure({ budget, onChange }), table: segment.table };
113
+ const { budget, maxRows, onChange } = this.#options;
114
+ return { kind: "chart", figure: new TableChartFigure({ budget, maxRows, onChange }), table: segment.table };
113
115
  }
114
116
  if (segment.kind === "markdown") {
115
117
  const text = segment.text.trim();
@@ -127,10 +129,10 @@ export class FigureMarkdown extends Container {
127
129
  return old;
128
130
  }
129
131
  reshaped = true;
130
- const { markdown, budget, onChange } = this.#options;
132
+ const { markdown, budget, maxRows, onChange } = this.#options;
131
133
  return {
132
134
  kind: "svg",
133
- figure: new SvgFigure({ markdown, budget, onChange }),
135
+ figure: new SvgFigure({ markdown, budget, maxRows, onChange }),
134
136
  source: segment.source,
135
137
  closed: segment.closed,
136
138
  };
@@ -3,7 +3,7 @@ import type { AssistantMessage, Usage } from "@linxiraos/pi-ai";
3
3
  import { type Component } from "../tui";
4
4
  import { Container } from "../tui";
5
5
  import { Text } from "../components/text";
6
- import { getLanguageFromPath, theme } from "../theme";
6
+ import { getLanguageFromPath, theme, type ThemeColor } from "../theme";
7
7
  import { parseLineRanges, selectorLineRanges } from "../tools/line-ranges";
8
8
  import {
9
9
  type ReadRenderArgs,
@@ -12,8 +12,15 @@ import {
12
12
  readResultIsMarkdown,
13
13
  readSourceFsPath,
14
14
  splitPathAndSel,
15
+ splitReadQuery,
15
16
  } from "../tools/read";
16
- import { PREVIEW_LIMITS, shortenPath } from "../render/render-utils";
17
+ import {
18
+ FILE_NAME_COLOR,
19
+ formatStatusIcon,
20
+ formatStyledPath,
21
+ PREVIEW_LIMITS,
22
+ shortenPath,
23
+ } from "../render/render-utils";
17
24
  import { fileHyperlink, renderCodeCell, renderMarkdownCell } from "../render";
18
25
  import { wrapTreeLine } from "../render/hanging-wrap";
19
26
  import { wrapTextWithAnsi } from "../utils";
@@ -21,7 +28,7 @@ import { canonicalizeMessage } from "./thinking-display";
21
28
  import { internalUrlSchemeSpec, splitUrlScheme } from "../tools/url-scheme-host";
22
29
  import type { ToolExecutionHandle } from "./tool-execution";
23
30
  import { formatUsageRow } from "../overlays/usage-row";
24
- import { formatCount, sanitizeText, sanitizeTextDeep } from "@linxiraos/pi-utils";
31
+ import { formatCount, isUrlLikePath, sanitizeText, sanitizeTextDeep } from "@linxiraos/pi-utils";
25
32
  import type { TspCardStatus, TspSpan, TspText } from "@linxiraos/pi-wire";
26
33
  import type { NativeToolHead } from "../tools/renderer";
27
34
  import { card, code, keyed, md, node, span, text, withHidden } from "../native/describe";
@@ -34,7 +41,7 @@ import {
34
41
  } from "../native/node";
35
42
  import { plainText } from "../native/spans";
36
43
  import { Memo } from "../native/memo";
37
- import { fileHref, fileRow, inlineErrorView } from "../tools/native-view";
44
+ import { fileHref, fileRow, inlineErrorView, urlHref } from "../tools/native-view";
38
45
 
39
46
  /**
40
47
  * Extract the read call's target path. `path` is the canonical arg; `file_path`
@@ -158,6 +165,21 @@ const COLLAPSED_PREVIEW_LINES = PREVIEW_LIMITS.OUTPUT_COLLAPSED;
158
165
  */
159
166
  const TRIMMED_BODY_PREVIEW = { lines: 1000 } as const;
160
167
 
168
+ /** How a read path is painted: its path (`isUrl` for a whole URL) and its selectors' color. */
169
+ interface PathPaint {
170
+ path(filePath: string, isUrl: boolean): string;
171
+ selectors: ThemeColor;
172
+ }
173
+
174
+ /** A `Read <path>` header line keeps the accent subject color. */
175
+ const HEADER_PATH_PAINT: PathPaint = { path: filePath => theme.fg("accent", filePath), selectors: "accent" };
176
+
177
+ /** Group rows share the tool-body path style with muted selectors. */
178
+ const ROW_PATH_PAINT: PathPaint = {
179
+ path: (filePath, isUrl) => (isUrl ? theme.fg(FILE_NAME_COLOR, filePath) : formatStyledPath(filePath, theme)),
180
+ selectors: "muted",
181
+ };
182
+
161
183
  /** Native item tone per read status; successful reads stay neutral. */
162
184
  const READ_STATUS_TONE: Record<ReadEntry["status"], "pending" | "warning" | "error" | undefined> = {
163
185
  success: undefined,
@@ -695,7 +717,7 @@ export class ReadToolGroupComponent extends Container implements ToolExecutionHa
695
717
  return {
696
718
  target: filePath ? `${filePath}${split.sel ? `:${split.sel}` : ""}` : "…",
697
719
  targetKind: "path",
698
- href: fileHref(linkPathForTargets(row.targets)),
720
+ href: fileHref(linkPathForTargets(row.targets)) ?? urlHref(split.path),
699
721
  meta: correctedFrom ? [`corrected from ${shortenPath(correctedFrom)}`] : undefined,
700
722
  badges: conflicts
701
723
  ? [{ text: `${conflicts} conflict${conflicts === 1 ? "" : "s"}`, tone: "warning" }]
@@ -718,7 +740,7 @@ export class ReadToolGroupComponent extends Container implements ToolExecutionHa
718
740
  : undefined;
719
741
  return fileRow(shortenPath(split.sel ? split.path : row.targetPath), {
720
742
  range: split.sel ? `:${split.sel}` : undefined,
721
- href: fileHref(linkPathForTargets(row.targets)),
743
+ href: fileHref(linkPathForTargets(row.targets)) ?? urlHref(split.path),
722
744
  icon: status === "error" ? "x-circle" : undefined,
723
745
  tone: READ_STATUS_TONE[status],
724
746
  chip: conflicts ? { text: `${conflicts} conflict${conflicts === 1 ? "" : "s"}` } : undefined,
@@ -914,8 +936,8 @@ export class ReadToolGroupComponent extends Container implements ToolExecutionHa
914
936
  if (displayRows.length === 1) {
915
937
  const row = displayRows[0]!;
916
938
  if (!this.#shouldRenderPreviewRow(row)) {
917
- const statusSymbol = this.#formatStatus(this.#statusForTargets(row.targets));
918
- const pathDisplay = this.#formatRowPath(row);
939
+ const statusSymbol = formatStatusIcon(this.#statusForTargets(row.targets), theme);
940
+ const pathDisplay = this.#formatRowPath(row, HEADER_PATH_PAINT);
919
941
  const lines = [` ${statusSymbol} ${theme.fg("toolTitle", theme.bold("Read"))} ${pathDisplay}`.trimEnd()];
920
942
  const usageRows = this.#usageRowsBySummaryRow(displayRows).get(0) ?? [];
921
943
  this.#appendUsageRows(lines, usageRows, " ");
@@ -1080,16 +1102,17 @@ export class ReadToolGroupComponent extends Container implements ToolExecutionHa
1080
1102
 
1081
1103
  #formatRow(row: ReadSummaryRow): string {
1082
1104
  const status = this.#statusForTargets(row.targets);
1083
- const statusPrefix = status === "success" ? "" : `${this.#formatStatus(status)} `;
1105
+ const statusPrefix = status === "success" ? "" : `${formatStatusIcon(status, theme)} `;
1084
1106
  return `${statusPrefix}${this.#formatRowPath(row)}`;
1085
1107
  }
1086
1108
 
1087
- #formatRowPath(row: ReadSummaryRow): string {
1088
- return this.#formatPathValue(row.targetPath, {
1109
+ #formatRowPath(row: ReadSummaryRow, paint = ROW_PATH_PAINT): string {
1110
+ return this.#formatPathValue(row.targetPath, paint, {
1089
1111
  correctedFrom: this.#correctedFromForTargets(row.targets),
1090
1112
  conflictCount: this.#conflictCountForTargets(row.targets),
1091
1113
  line: firstSelectorLineForTargets(row.targets),
1092
1114
  linkPath: linkPathForTargets(row.targets),
1115
+ basePath: row.basePath,
1093
1116
  });
1094
1117
  }
1095
1118
 
@@ -1137,25 +1160,35 @@ export class ReadToolGroupComponent extends Container implements ToolExecutionHa
1137
1160
 
1138
1161
  #formatPathValue(
1139
1162
  value: string,
1140
- options: { correctedFrom?: string; conflictCount?: number; line?: number; linkPath?: string } = {},
1163
+ paint: PathPaint,
1164
+ options: {
1165
+ correctedFrom?: string;
1166
+ conflictCount?: number;
1167
+ line?: number;
1168
+ linkPath?: string;
1169
+ /** The path `value` selects from; merged selectors (`1-5,…,9`) do not parse back out of it. */
1170
+ basePath?: string;
1171
+ } = {},
1141
1172
  ): string {
1142
- const split = splitPathAndSel(value);
1143
- const selectorSuffix = split.sel ? `:${split.sel}` : "";
1144
- const baseValue = split.sel ? split.path : value;
1145
- const filePath = shortenPath(baseValue);
1146
- let pathDisplay = filePath ? theme.fg("accent", filePath) : theme.fg("toolOutput", "…");
1173
+ const { basePath } = options;
1174
+ const split =
1175
+ basePath !== undefined && value.startsWith(`${basePath}:`)
1176
+ ? { path: basePath, sel: value.slice(basePath.length + 1) }
1177
+ : splitPathAndSel(value);
1178
+ // `?q=…` queries read like selectors: they follow the path, outside its link.
1179
+ const target = splitReadQuery(split.sel ? split.path : value);
1180
+ const filePath = shortenPath(target.path);
1181
+ const selectors = split.sel ? `${target.query ?? ""}:${split.sel}` : (target.query ?? "");
1182
+ let pathDisplay = filePath ? paint.path(filePath, isUrlLikePath(target.path)) : theme.fg("toolOutput", "…");
1147
1183
  if (filePath && options.linkPath) {
1148
1184
  const linkOptions = options.line !== undefined ? { line: options.line } : undefined;
1149
1185
  pathDisplay = fileHyperlink(options.linkPath, pathDisplay, linkOptions);
1150
1186
  }
1151
- if (selectorSuffix) {
1152
- pathDisplay += theme.fg("accent", selectorSuffix);
1153
- }
1187
+ if (selectors) pathDisplay += theme.fg(paint.selectors, selectors);
1154
1188
  if (options.correctedFrom) {
1155
1189
  pathDisplay += theme.fg("dim", ` (corrected from ${shortenPath(options.correctedFrom)})`);
1156
1190
  }
1157
- pathDisplay += this.#formatConflictBadge(options.conflictCount);
1158
- return pathDisplay;
1191
+ return pathDisplay + this.#formatConflictBadge(options.conflictCount);
1159
1192
  }
1160
1193
 
1161
1194
  #formatConflictBadge(conflictCount: number | undefined): string {
@@ -1174,7 +1207,7 @@ export class ReadToolGroupComponent extends Container implements ToolExecutionHa
1174
1207
  const lang = getLanguageFromPath(split.path);
1175
1208
  const pathValue = shortenPath(entry.path);
1176
1209
  const pathDisplay = pathValue
1177
- ? this.#formatPathValue(entry.path, {
1210
+ ? this.#formatPathValue(entry.path, HEADER_PATH_PAINT, {
1178
1211
  correctedFrom: entry.correctedFrom,
1179
1212
  conflictCount: entry.conflictCount,
1180
1213
  line: firstSelectorLine(split.sel),
@@ -1252,17 +1285,4 @@ export class ReadToolGroupComponent extends Container implements ToolExecutionHa
1252
1285
  #shouldRenderPreview(entry: ReadEntry): boolean {
1253
1286
  return this.#showContentPreview && entry.contentText !== undefined;
1254
1287
  }
1255
-
1256
- #formatStatus(status: ReadEntry["status"]): string {
1257
- if (status === "success") {
1258
- return theme.fg("text", theme.status.enabled);
1259
- }
1260
- if (status === "warning") {
1261
- return theme.fg("warning", theme.status.warning);
1262
- }
1263
- if (status === "error") {
1264
- return theme.fg("error", theme.status.error);
1265
- }
1266
- return theme.fg("dim", theme.status.pending);
1267
- }
1268
1288
  }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Replies: text the agent sends to a scheme whose writes are `reply`-scoped (`out://`)
3
+ * is its mid-turn message to the user, drawn as assistant prose so it can answer
4
+ * without ending its turn.
5
+ * - A `write` call to a reply URL draws as {@link ReplyWriteComponent}, streaming as the
6
+ * call's arguments arrive, instead of a tool card.
7
+ * - Text a tool's commands write there (`printf … > out://` in bash) arrives in the
8
+ * tool's result `details.replies` ({@link toolResultReplies}); transcripts draw each
9
+ * one as a prose block after the call ({@link replyDisplayMessage}).
10
+ */
11
+ import type { AssistantMessage } from "@linxiraos/pi-ai";
12
+ import type { ImageBudget } from "../components/image";
13
+ import { AssistantMessageComponent } from "./assistant-message";
14
+ import type { ToolExecutionHandle, ToolResultFrame } from "./tool-execution";
15
+ /**
16
+ * Whether a `toolName` call writes to a reply URL. `undefined` while streamed args cannot tell yet:
17
+ * no path so far, or a path that could still grow into a reply URL (`ou`, `out:/`). Callers holding
18
+ * final args treat `undefined` as `false`.
19
+ */
20
+ export declare function isReplyWrite(toolName: string, args: unknown): boolean | undefined;
21
+ /** Display options of a reply block; the rest of its presentation follows the assistant prose defaults. */
22
+ export interface ReplyWriteOptions {
23
+ /** Repaint request for figures and images that finish loading after a render. */
24
+ readonly requestRender?: () => void;
25
+ readonly imageBudget?: ImageBudget;
26
+ /** Resolved local destinations of Markdown links, as for assistant text. */
27
+ readonly linkTargets?: ReadonlyMap<string, string>;
28
+ }
29
+ /** Replies a tool result carries in `details.replies` (text its commands wrote to a reply URL), oldest first. */
30
+ export declare function toolResultReplies(details: unknown): readonly string[];
31
+ /** Assistant message drawing reply text. No provider turn backs it, so its identity fields stay empty. */
32
+ export declare function replyDisplayMessage(text: string, errorMessage?: string): AssistantMessage;
33
+ /**
34
+ * A reply write ({@link isReplyWrite}) drawn as assistant prose. The call's lifecycle arrives
35
+ * through {@link ToolExecutionHandle}: streamed args grow the text, final args settle it, and
36
+ * the result seals the block, a failure showing its error under the text. It is a reply, not
37
+ * tool activity, so hiding tool activity leaves it on screen.
38
+ */
39
+ export declare class ReplyWriteComponent extends AssistantMessageComponent implements ToolExecutionHandle {
40
+ #private;
41
+ constructor(options?: ReplyWriteOptions);
42
+ updateArgs(args: unknown): void;
43
+ setArgsComplete(): void;
44
+ setExecutionStarted(): void;
45
+ updateResult(result: ToolResultFrame, isPartial?: boolean): void;
46
+ parkAsBackground(): void;
47
+ seal(): void;
48
+ }
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Replies: text the agent sends to a scheme whose writes are `reply`-scoped (`out://`)
3
+ * is its mid-turn message to the user, drawn as assistant prose so it can answer
4
+ * without ending its turn.
5
+ * - A `write` call to a reply URL draws as {@link ReplyWriteComponent}, streaming as the
6
+ * call's arguments arrive, instead of a tool card.
7
+ * - Text a tool's commands write there (`printf … > out://` in bash) arrives in the
8
+ * tool's result `details.replies` ({@link toolResultReplies}); transcripts draw each
9
+ * one as a prose block after the call ({@link replyDisplayMessage}).
10
+ */
11
+ import type { AssistantMessage, Usage } from "@linxiraos/pi-ai";
12
+ import { isRecord } from "@linxiraos/pi-utils";
13
+ import type { ImageBudget } from "../components/image";
14
+ import { internalUrlSchemeSpec, internalUrlSchemeSpecs, splitUrlScheme } from "../tools/url-scheme-host";
15
+ import { AssistantMessageComponent } from "./assistant-message";
16
+ import type { ToolExecutionHandle, ToolResultFrame } from "./tool-execution";
17
+
18
+ /**
19
+ * Whether a `toolName` call writes to a reply URL. `undefined` while streamed args cannot tell yet:
20
+ * no path so far, or a path that could still grow into a reply URL (`ou`, `out:/`). Callers holding
21
+ * final args treat `undefined` as `false`.
22
+ */
23
+ export function isReplyWrite(toolName: string, args: unknown): boolean | undefined {
24
+ if (toolName !== "write") return false;
25
+ if (!isRecord(args)) return undefined;
26
+ const target = typeof args.path === "string" ? args.path : args.file_path;
27
+ if (typeof target !== "string") return undefined;
28
+ const url = splitUrlScheme(target);
29
+ if (url) return internalUrlSchemeSpec(url.scheme)?.write?.scope === "reply";
30
+ const lower = target.toLowerCase();
31
+ for (const [scheme, spec] of internalUrlSchemeSpecs()) {
32
+ if (spec.write?.scope === "reply" && `${scheme}://`.startsWith(lower)) return undefined;
33
+ }
34
+ return false;
35
+ }
36
+
37
+ /** Display options of a reply block; the rest of its presentation follows the assistant prose defaults. */
38
+ export interface ReplyWriteOptions {
39
+ /** Repaint request for figures and images that finish loading after a render. */
40
+ readonly requestRender?: () => void;
41
+ readonly imageBudget?: ImageBudget;
42
+ /** Resolved local destinations of Markdown links, as for assistant text. */
43
+ readonly linkTargets?: ReadonlyMap<string, string>;
44
+ }
45
+
46
+ const NO_USAGE: Usage = {
47
+ input: 0,
48
+ output: 0,
49
+ cacheRead: 0,
50
+ cacheWrite: 0,
51
+ totalTokens: 0,
52
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
53
+ };
54
+
55
+ /** Replies a tool result carries in `details.replies` (text its commands wrote to a reply URL), oldest first. */
56
+ export function toolResultReplies(details: unknown): readonly string[] {
57
+ if (!isRecord(details) || !Array.isArray(details.replies)) return [];
58
+ return details.replies.filter((reply): reply is string => typeof reply === "string");
59
+ }
60
+
61
+ /** Assistant message drawing reply text. No provider turn backs it, so its identity fields stay empty. */
62
+ export function replyDisplayMessage(text: string, errorMessage?: string): AssistantMessage {
63
+ return {
64
+ role: "assistant",
65
+ content: [{ type: "text", text }],
66
+ api: "",
67
+ provider: "",
68
+ model: "",
69
+ usage: NO_USAGE,
70
+ stopReason: errorMessage === undefined ? "stop" : "error",
71
+ errorMessage,
72
+ timestamp: 0,
73
+ };
74
+ }
75
+
76
+ /**
77
+ * A reply write ({@link isReplyWrite}) drawn as assistant prose. The call's lifecycle arrives
78
+ * through {@link ToolExecutionHandle}: streamed args grow the text, final args settle it, and
79
+ * the result seals the block, a failure showing its error under the text. It is a reply, not
80
+ * tool activity, so hiding tool activity leaves it on screen.
81
+ */
82
+ export class ReplyWriteComponent extends AssistantMessageComponent implements ToolExecutionHandle {
83
+ #text = "";
84
+ #argsComplete = false;
85
+
86
+ constructor(options: ReplyWriteOptions = {}) {
87
+ super(undefined, false, options.requestRender, [], options.imageBudget, true, options.linkTargets);
88
+ }
89
+
90
+ updateArgs(args: unknown): void {
91
+ const text = isRecord(args) && typeof args.content === "string" ? args.content : "";
92
+ if (text === this.#text || this.isTranscriptBlockFinalized()) return;
93
+ this.#text = text;
94
+ this.#draw();
95
+ }
96
+
97
+ setArgsComplete(): void {
98
+ if (this.#argsComplete || this.isTranscriptBlockFinalized()) return;
99
+ this.#argsComplete = true;
100
+ this.#draw();
101
+ }
102
+
103
+ setExecutionStarted(): void {}
104
+
105
+ updateResult(result: ToolResultFrame, isPartial = false): void {
106
+ if (isPartial || this.isTranscriptBlockFinalized()) return;
107
+ this.#argsComplete = true;
108
+ const error = result.isError
109
+ ? result.content
110
+ .filter(block => block.type === "text")
111
+ .map(block => block.text ?? "")
112
+ .join("\n")
113
+ : undefined;
114
+ this.updateContent(replyDisplayMessage(this.#text, error));
115
+ this.markTranscriptBlockFinalized();
116
+ }
117
+
118
+ parkAsBackground(): void {}
119
+
120
+ seal(): void {
121
+ this.markTranscriptBlockFinalized();
122
+ }
123
+
124
+ #draw(): void {
125
+ this.updateContent(replyDisplayMessage(this.#text), { transient: !this.#argsComplete });
126
+ }
127
+ }
@@ -16,6 +16,11 @@ export interface SvgFigureOptions {
16
16
  markdown?: (text: string) => Markdown;
17
17
  /** Shared inline-image budget; superseded rasters are released from it. */
18
18
  budget?: ImageBudget;
19
+ /**
20
+ * Rows the figure may fill, fallback code included, read on every render;
21
+ * zero hides it. Unset or `undefined` takes a share of the terminal viewport.
22
+ */
23
+ maxRows?: () => number | undefined;
19
24
  /** The figure's rows changed outside a text update: a raster landed or rendering fell back to code. */
20
25
  onChange: () => void;
21
26
  }
@@ -113,6 +113,11 @@ export interface SvgFigureOptions {
113
113
  markdown?: (text: string) => Markdown;
114
114
  /** Shared inline-image budget; superseded rasters are released from it. */
115
115
  budget?: ImageBudget;
116
+ /**
117
+ * Rows the figure may fill, fallback code included, read on every render;
118
+ * zero hides it. Unset or `undefined` takes a share of the terminal viewport.
119
+ */
120
+ maxRows?: () => number | undefined;
116
121
  /** The figure's rows changed outside a text update: a raster landed or rendering fell back to code. */
117
122
  onChange: () => void;
118
123
  }
@@ -149,12 +154,15 @@ interface Attempt {
149
154
 
150
155
  let nextFigureId = 0;
151
156
 
152
- /** Cells a figure rendered at `width` may fill: the image's width, a share of the viewport, and the raster edge cap. */
153
- function limitsFor(width: number, cell: CellDimensions): Limits {
154
- const viewportRows = Math.floor((process.stdout.rows || 24) * MAX_VIEWPORT_SHARE);
157
+ /** Cells a figure rendered at `width` may fill: the image's width, the caller's row ceiling (or a share of the viewport), and the raster edge cap. */
158
+ function limitsFor(
159
+ width: number,
160
+ cell: CellDimensions,
161
+ maxRows = Math.floor((process.stdout.rows || 24) * MAX_VIEWPORT_SHARE),
162
+ ): Limits {
155
163
  return {
156
164
  columns: Math.min(imageMaxColumns(width), Math.floor(MAX_EDGE_PX / cell.widthPx)),
157
- rows: Math.max(1, Math.min(viewportRows, Math.floor(MAX_EDGE_PX / cell.heightPx))),
165
+ rows: Math.max(1, Math.min(maxRows, Math.floor(MAX_EDGE_PX / cell.heightPx))),
158
166
  };
159
167
  }
160
168
 
@@ -178,7 +186,14 @@ export class SvgFigure implements Component {
178
186
  /** Last render width; rasters wait for the first render to know their room. */
179
187
  #width: number | undefined;
180
188
  #image: { raster: Raster; component: Image } | undefined;
181
- #fallback: { source: string; md: Markdown } | undefined;
189
+ #fallback:
190
+ | {
191
+ source: string;
192
+ md: Markdown;
193
+ /** `rows` cut to a ceiling, kept so unchanged frames return the same array. */
194
+ clip?: { of: readonly string[]; rows: readonly string[] };
195
+ }
196
+ | undefined;
182
197
  #placeholder: readonly string[] | undefined;
183
198
 
184
199
  constructor(options: SvgFigureOptions) {
@@ -203,21 +218,34 @@ export class SvgFigure implements Component {
203
218
 
204
219
  /** Whether the final source still waits for its raster (or for failing to render). */
205
220
  get pending(): boolean {
206
- return this.#final && this.#raster?.source !== this.#source && this.#failed !== this.#source;
221
+ return (
222
+ this.#maxRows() !== 0 && this.#final && this.#raster?.source !== this.#source && this.#failed !== this.#source
223
+ );
224
+ }
225
+
226
+ /** The caller's row ceiling, if any; a surface shorter than its chrome leaves none. */
227
+ #maxRows(): number | undefined {
228
+ const rows = this.#options.maxRows?.();
229
+ return rows === undefined ? undefined : Math.max(0, Math.floor(rows));
207
230
  }
208
231
 
209
232
  render(width: number): readonly string[] {
210
233
  // Width, cell size and theme are render-time inputs; a change re-rasterizes.
211
234
  this.#width = width;
212
235
  this.#schedule();
213
- if (this.#failed === this.#source) return this.#fallbackRows(width);
236
+ const maxRows = this.#maxRows();
237
+ if (maxRows === 0) return [];
238
+ if (this.#failed === this.#source) return this.#fallbackRows(width, maxRows);
214
239
  const raster = this.#raster;
215
240
  if (!raster) {
216
241
  if (!this.#options.markdown) return [];
217
242
  this.#placeholder ??= [` ${theme.fg("dim", "Drawing SVG…")}`];
218
243
  return this.#placeholder;
219
244
  }
220
- return this.#imageFor(raster).render(width);
245
+ const rows = this.#imageFor(raster, maxRows).render(width);
246
+ // A SIXEL band is six pixels whole: cells shorter than that reserve more
247
+ // rows than the ceiling, and a cut band would draw nothing anyway.
248
+ return maxRows !== undefined && rows.length > maxRows ? [] : rows;
221
249
  }
222
250
 
223
251
  invalidate(): void {
@@ -247,7 +275,7 @@ export class SvgFigure implements Component {
247
275
  const attempt = this.#attempt;
248
276
  if (this.#failed === this.#source) return false;
249
277
  const cell = getCellDimensions();
250
- const limits = limitsFor(width, cell);
278
+ const limits = limitsFor(width, cell, this.#maxRows());
251
279
  return (
252
280
  attempt === undefined ||
253
281
  attempt.source !== this.#source ||
@@ -280,6 +308,7 @@ export class SvgFigure implements Component {
280
308
  #schedule(): void {
281
309
  const width = this.#width;
282
310
  if (this.#disposed || this.#rasterizing || width === undefined) return;
311
+ if (this.#maxRows() === 0) return;
283
312
  if (this.#final && this.#timer) {
284
313
  clearTimeout(this.#timer);
285
314
  this.#timer = undefined;
@@ -302,7 +331,7 @@ export class SvgFigure implements Component {
302
331
  const attempt: Attempt = {
303
332
  source: this.#source,
304
333
  cell,
305
- limits: limitsFor(width, cell),
334
+ limits: limitsFor(width, cell, this.#maxRows()),
306
335
  themeEpoch: getThemeEpoch(),
307
336
  final: this.#final,
308
337
  };
@@ -364,13 +393,17 @@ export class SvgFigure implements Component {
364
393
  /**
365
394
  * The image for `raster` over the whole cells it was padded to. At the
366
395
  * cell size and room it was drawn for that box is its pixels exactly; a
367
- * raster outdated by a resize is scaled by {@link Image} until its redraw lands.
396
+ * raster outdated by a resize is scaled by {@link Image} until its redraw
397
+ * lands. A caller's ceiling (`maxRows`) refits the shown image at once.
368
398
  */
369
- #imageFor(raster: Raster): Image {
399
+ #imageFor(raster: Raster, maxRows = Number.POSITIVE_INFINITY): Image {
370
400
  const current = this.#image;
371
- if (current?.raster === raster) return current.component;
372
401
  const columns = raster.widthPx / raster.cell.widthPx;
373
- const rows = raster.heightPx / raster.cell.heightPx;
402
+ const rows = Math.min(raster.heightPx / raster.cell.heightPx, maxRows);
403
+ if (current?.raster === raster) {
404
+ current.component.setMaxHeightCells(rows);
405
+ return current.component;
406
+ }
374
407
  const component = new Image(
375
408
  raster.data,
376
409
  "image/png",
@@ -390,12 +423,18 @@ export class SvgFigure implements Component {
390
423
  }
391
424
 
392
425
  /** The source as the fenced code block it was written as, fenced longer than any backtick run inside. */
393
- #fallbackRows(width: number): readonly string[] {
426
+ #fallbackRows(width: number, maxRows?: number): readonly string[] {
394
427
  const source = this.#source;
395
428
  if (!this.#options.markdown) return [];
396
429
  if (this.#fallback?.source !== source) {
397
430
  this.#fallback = { source, md: this.#options.markdown(fencedCode("svg", source)) };
398
431
  }
399
- return this.#fallback.md.render(width);
432
+ const fallback = this.#fallback;
433
+ const rows = fallback.md.render(width);
434
+ if (maxRows === undefined || rows.length <= maxRows) return rows;
435
+ if (fallback.clip?.of !== rows || fallback.clip.rows.length !== maxRows) {
436
+ fallback.clip = { of: rows, rows: rows.slice(0, maxRows) };
437
+ }
438
+ return fallback.clip.rows;
400
439
  }
401
440
  }