@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
@@ -26,6 +26,12 @@ import { isBareMathEnvironment, latexToUnicode } from "../latex-to-unicode";
26
26
  import { plainText } from "../native/spans";
27
27
  import { md } from "../native/describe";
28
28
  import type { DescribeContext, NativeNode } from "../native/node";
29
+ import {
30
+ extensionLinkScheme,
31
+ extensionLinksVersion,
32
+ formatExtensionLink,
33
+ stripExtensionLinkMarkers,
34
+ } from "../render/extension-links";
29
35
  import type { SymbolTheme } from "../symbols";
30
36
  import { TERMINAL } from "../terminal-capabilities";
31
37
  import { getSymbolTheme, getThemeEpoch } from "../theme/theme";
@@ -136,6 +142,40 @@ function fenceOpenAt(text: string, end: number): boolean {
136
142
  return open !== undefined;
137
143
  }
138
144
 
145
+ /**
146
+ * Whether `text` ends inside a code fence the source never closed. The
147
+ * renderer still draws such a fence's closing border, so a caller publishing a
148
+ * settled source prefix must drop that fabricated row: it is not a prefix of
149
+ * the live block, which reaches the border only once the closer arrives.
150
+ */
151
+ export function endsInsideOpenFence(text: string): boolean {
152
+ return fenceOpenAt(text, text.length);
153
+ }
154
+
155
+ /**
156
+ * Offset of the settled prefix of the still-open fence that `text` ends in, or
157
+ * 0 when it holds none.
158
+ *
159
+ * An open fence's body only ever appends: nothing a later chunk adds can
160
+ * change a line that already ended. Those lines are therefore settled, and a
161
+ * stream may publish them into native scrollback instead of leaving the whole
162
+ * block in the mutable viewport until the closing fence finally arrives — a
163
+ * long streamed code block would otherwise lose every row that left the screen
164
+ * (#9780).
165
+ *
166
+ * The cut lands before the last complete line, not after it: a streamed chunk
167
+ * usually ends on a "\n", and the publisher requires non-blank source past the
168
+ * prefix it publishes, so cutting at the final "\n" would publish nothing on
169
+ * exactly those frames. Once the closing fence has arrived, the retained line
170
+ * is the one in front of it.
171
+ */
172
+ function settledFenceBodyEnd(text: string): number {
173
+ const lastBreak = text.lastIndexOf("\n");
174
+ if (lastBreak <= 0) return 0;
175
+ const cut = text.lastIndexOf("\n", lastBreak - 1) + 1;
176
+ return cut > 0 && fenceOpenAt(text, cut) ? cut : 0;
177
+ }
178
+
139
179
  /**
140
180
  * Streaming `md` source for a native terminal, minus a still-growing table row:
141
181
  * the unterminated last line when a GFM table (a run of pipe lines holding a
@@ -1354,6 +1394,15 @@ function inlineHasOpen(tokens: readonly Token[]): boolean {
1354
1394
  return false;
1355
1395
  }
1356
1396
 
1397
+ /** True when the inline token stream holds a link whose scheme an extension claimed. */
1398
+ function hasExtensionLink(tokens: readonly Token[]): boolean {
1399
+ for (const token of tokens) {
1400
+ if (token.type === "link" && typeof token.href === "string" && extensionLinkScheme(token.href)) return true;
1401
+ if ("tokens" in token && Array.isArray(token.tokens) && hasExtensionLink(token.tokens as Token[])) return true;
1402
+ }
1403
+ return false;
1404
+ }
1405
+
1357
1406
  /** Isolated inline lex of a same-line delta. A single-line delta has no block
1358
1407
  * structure, so the isolated inline pass equals the full lex's inline pass
1359
1408
  * (marked's paragraph tokens run the same `inlineTokens` entry point). */
@@ -1764,8 +1813,13 @@ type ListToken = Token & {
1764
1813
  start?: number;
1765
1814
  loose: boolean;
1766
1815
  };
1767
- type TableCellToken = { tokens?: Token[] };
1768
- type TableToken = Token & { header: TableCellToken[]; rows: TableCellToken[][]; raw?: string };
1816
+ type TableCellToken = { tokens?: Token[]; align?: Tokens.TableCell["align"] };
1817
+ type TableToken = Token & {
1818
+ header: TableCellToken[];
1819
+ rows: TableCellToken[][];
1820
+ raw?: string;
1821
+ align?: Array<Tokens.TableCell["align"]>;
1822
+ };
1769
1823
 
1770
1824
  /** `item` as marked lexes it inside a loose list: tight `text` blocks become paragraphs. */
1771
1825
  function loosenListItem(item: Tokens.ListItem): Tokens.ListItem {
@@ -1819,6 +1873,63 @@ function formatHyperlink(text: string, target: string): string {
1819
1873
  return `\x1b]8;;${safeTarget}\x07${text}\x1b]8;;\x07`;
1820
1874
  }
1821
1875
 
1876
+ const CODE_ESCAPE_RE = /\x1b(?:\[[0-?]*[ -/]*[@-~]|\][^\x07\x1b]*(?:\x07|\x1b\\))/y;
1877
+ const CODE_URL_RE = /(?<![A-Za-z0-9+.-])https?:\/\/[^\s\x00-\x1f\x7f<>"'`]+/g;
1878
+ const CODE_URL_TRAILING_RE = /[.,;:!?]+$/;
1879
+ const CODE_URL_OPENERS: Partial<Record<string, string>> = { ")": "(", "]": "[", "}": "{" };
1880
+
1881
+ /** Whether `url` ends in a closing bracket that has no matching opener inside it. */
1882
+ function endsWithUnbalancedCloser(url: string): boolean {
1883
+ const closer = url.at(-1) ?? "";
1884
+ const opener = CODE_URL_OPENERS[closer];
1885
+ return opener !== undefined && url.split(closer).length > url.split(opener).length;
1886
+ }
1887
+
1888
+ /**
1889
+ * Wrap each http(s) URL in a highlighted code row with an OSC 8 hyperlink.
1890
+ * The row is hard-wrapped later; wrapTextWithAnsi reopens the link on every
1891
+ * fragment, so terminals open the whole URL instead of only the first visual
1892
+ * line. URLs are located in the visible text so syntax-highlight escapes
1893
+ * inside them stay in place and the visible width is unchanged.
1894
+ */
1895
+ function linkifyCodeUrls(line: string): string {
1896
+ if (!TERMINAL.hyperlinks || !line.includes("://") || line.includes("\x1b]8;")) {
1897
+ return line;
1898
+ }
1899
+
1900
+ let visible = "";
1901
+ const offsets: number[] = [];
1902
+ for (let i = 0; i < line.length;) {
1903
+ if (line.charCodeAt(i) === 0x1b) {
1904
+ CODE_ESCAPE_RE.lastIndex = i;
1905
+ const match = CODE_ESCAPE_RE.exec(line);
1906
+ if (match) {
1907
+ i += match[0].length;
1908
+ continue;
1909
+ }
1910
+ }
1911
+ offsets.push(i);
1912
+ visible += line[i];
1913
+ i++;
1914
+ }
1915
+
1916
+ let result = "";
1917
+ let copied = 0;
1918
+ for (const match of visible.matchAll(CODE_URL_RE)) {
1919
+ let url = match[0].replace(CODE_URL_TRAILING_RE, "");
1920
+ // A closer only belongs to the URL when it balances an opener inside it.
1921
+ while (endsWithUnbalancedCloser(url)) {
1922
+ url = url.slice(0, -1).replace(CODE_URL_TRAILING_RE, "");
1923
+ }
1924
+ if (!/:\/\/./.test(url)) continue;
1925
+ const start = offsets[match.index] ?? 0;
1926
+ const end = (offsets[match.index + url.length - 1] ?? start) + 1;
1927
+ result += line.slice(copied, start) + formatHyperlink(line.slice(start, end), url);
1928
+ copied = end;
1929
+ }
1930
+ return copied === 0 ? line : result + line.slice(copied);
1931
+ }
1932
+
1822
1933
  function isAsciiTextSizingPayload(text: string): boolean {
1823
1934
  for (let i = 0; i < text.length; i++) {
1824
1935
  const code = text.charCodeAt(i);
@@ -2067,6 +2178,7 @@ interface RenderSignature {
2067
2178
  defaultTextStyleId: number;
2068
2179
  imageProtocol: string;
2069
2180
  hyperlinks: boolean;
2181
+ extensionLinks: number;
2070
2182
  textSizing: boolean;
2071
2183
  bgColorProbe: string;
2072
2184
  headingProbe: string;
@@ -2238,6 +2350,8 @@ export class Markdown implements Component {
2238
2350
  #cachedText?: string;
2239
2351
  #cachedWidth?: number;
2240
2352
  #cachedLines?: readonly string[];
2353
+ // Extension-link routing changes how links draw without changing text or width.
2354
+ #cachedExtensionLinks?: number;
2241
2355
  #transientRenderCache = false;
2242
2356
 
2243
2357
  // Streaming-lex cache: the largest blank-line-bounded prefix of #text whose
@@ -2260,6 +2374,12 @@ export class Markdown implements Component {
2260
2374
  // The frozen prefix's leading run in front of the first of those openers:
2261
2375
  // no append can change its tokens, so getLastRenderStableText publishes it.
2262
2376
  #streamSettledText?: string;
2377
+ // The complete lines inside a still-open fence, with the fence's opening
2378
+ // line in front of them: an open fence never reaches a "\n\n" boundary, so
2379
+ // #streamSettledText holds nothing for it and a long streamed code block
2380
+ // would stay unretirable until the closing fence arrived. Kept while the
2381
+ // source extends it, so the published prefix never shrinks.
2382
+ #streamFenceSettledText?: string;
2263
2383
  // The text in front of the newest top-level item of a list that is still
2264
2384
  // streaming as the last block. Once an item's marker line has ended, no
2265
2385
  // append can add to the items in front of it, and #renderList draws each
@@ -2311,6 +2431,9 @@ export class Markdown implements Component {
2311
2431
  #fastTail?: FastTailRecipe; // undefined = disarmed
2312
2432
  // B+ capture plumbing: #renderContentLines records the last rendered paragraph row.
2313
2433
  #lastTailCapture?: { kind: "paragraph"; open: boolean; rowInput: string; rowRaw: string };
2434
+ /** Top-level token index and running count of the extension links drawn in it; see `#renderContentLines`. */
2435
+ #extensionLinkBlock = 0;
2436
+ #extensionLinkOrdinal = 0;
2314
2437
  #ignoreTight = false;
2315
2438
  #native?: { text: string; stream: boolean; node: NativeNode };
2316
2439
  setIgnoreTight(ignore: boolean): this {
@@ -2455,9 +2578,31 @@ export class Markdown implements Component {
2455
2578
  */
2456
2579
  getLastRenderStableText(): string {
2457
2580
  if (!this.#transientRenderCache) return "";
2458
- const settled = this.#streamSettledText ?? "";
2581
+ // An open fence has no "\n\n" boundary, so the block walk above settles
2582
+ // nothing inside it. Its finished lines are settled all the same: no
2583
+ // append can change a line that already ended. Publish them, or a long
2584
+ // streamed code block (SQL, logs) stays unretirable in the mutable
2585
+ // viewport and its top rows are dropped as it outgrows the screen.
2586
+ const source = streamingMarkdownSource(this.#text);
2587
+ let fence = this.#streamFenceSettledText;
2588
+ if (fence !== undefined && !source.startsWith(fence)) {
2589
+ // A non-append edit rewound the text below what was published. Drop
2590
+ // the stored prefix as well: keeping it would fail this check on
2591
+ // every later frame and leave the block unretirable for the rest of
2592
+ // the stream.
2593
+ fence = undefined;
2594
+ this.#streamFenceSettledText = undefined;
2595
+ }
2596
+ const body = settledFenceBodyEnd(source);
2597
+ if (body > (fence?.length ?? 0)) {
2598
+ fence = source.slice(0, body);
2599
+ this.#streamFenceSettledText = fence;
2600
+ }
2601
+ let text = this.#streamSettledText ?? "";
2459
2602
  const list = this.#streamListSettledText;
2460
- return list !== undefined && list.length > settled.length ? list : settled;
2603
+ if (list !== undefined && list.length > text.length) text = list;
2604
+ if (fence !== undefined && fence.length > text.length) text = fence;
2605
+ return text;
2461
2606
  }
2462
2607
 
2463
2608
  get transientRenderCache(): boolean {
@@ -2491,6 +2636,7 @@ export class Markdown implements Component {
2491
2636
  this.#streamingHighlightCache = undefined;
2492
2637
  this.#streamingListCache = undefined;
2493
2638
  this.#streamRewound = undefined;
2639
+ this.#streamFenceSettledText = undefined;
2494
2640
  }
2495
2641
  this.invalidate();
2496
2642
  }
@@ -2852,7 +2998,12 @@ export class Markdown implements Component {
2852
2998
  // instance at the same width (e.g. resize debounce, repeated redraws).
2853
2999
  // Returning the cached reference is load-bearing: parents memoize their
2854
3000
  // concatenation on reference equality.
2855
- if (this.#cachedLines && this.#cachedText === this.#text && this.#cachedWidth === width) {
3001
+ if (
3002
+ this.#cachedLines &&
3003
+ this.#cachedText === this.#text &&
3004
+ this.#cachedWidth === width &&
3005
+ this.#cachedExtensionLinks === extensionLinksVersion()
3006
+ ) {
2856
3007
  return this.#cachedLines;
2857
3008
  }
2858
3009
 
@@ -2865,6 +3016,7 @@ export class Markdown implements Component {
2865
3016
  this.#cachedText = this.#text;
2866
3017
  this.#cachedWidth = width;
2867
3018
  this.#cachedLines = EMPTY_RENDER_LINES;
3019
+ this.#cachedExtensionLinks = extensionLinksVersion();
2868
3020
  return EMPTY_RENDER_LINES;
2869
3021
  }
2870
3022
 
@@ -2949,6 +3101,8 @@ export class Markdown implements Component {
2949
3101
  // into a table on a marker-free delta (`| --` + `--- | -`).
2950
3102
  !FAST_TABLE_DELIM_ROW_RE.test(grownLastLine) &&
2951
3103
  (!markerDelta || (!this.#lastTailCapture?.open && !pairSeamHazard && !inlineHasOpen(deltaTokens!))) &&
3104
+ // Extension link markers are numbered per block; a delta rendered alone can't continue that.
3105
+ !(deltaTokens && hasExtensionLink(deltaTokens)) &&
2952
3106
  !FAST_URL_ANYWHERE_RE.test(seamWindow) &&
2953
3107
  // A link or math span the grown row leaves open renders speculatively closed: re-lex.
2954
3108
  speculativeInlineClose(grownLastLine) === undefined
@@ -2989,6 +3143,7 @@ export class Markdown implements Component {
2989
3143
  this.#cachedText = this.#text;
2990
3144
  this.#cachedWidth = width;
2991
3145
  this.#cachedLines = fastResult;
3146
+ this.#cachedExtensionLinks = signature.extensionLinks;
2992
3147
  this.#fastTail = {
2993
3148
  lines: fastResult,
2994
3149
  source: this.#text,
@@ -3051,6 +3206,7 @@ export class Markdown implements Component {
3051
3206
  this.#cachedText = this.#text;
3052
3207
  this.#cachedWidth = width;
3053
3208
  this.#cachedLines = cached;
3209
+ this.#cachedExtensionLinks = signature.extensionLinks;
3054
3210
  return cached;
3055
3211
  }
3056
3212
  }
@@ -3084,6 +3240,7 @@ export class Markdown implements Component {
3084
3240
  this.#cachedText = this.#text;
3085
3241
  this.#cachedWidth = width;
3086
3242
  this.#cachedLines = result;
3243
+ this.#cachedExtensionLinks = signature.extensionLinks;
3087
3244
 
3088
3245
  const fastEligible =
3089
3246
  this.transientRenderCache &&
@@ -3138,6 +3295,7 @@ export class Markdown implements Component {
3138
3295
  defaultTextStyleId: this.#defaultTextStyle ? objectId(this.#defaultTextStyle) : -1,
3139
3296
  imageProtocol: TERMINAL.imageProtocol ?? "",
3140
3297
  hyperlinks: TERMINAL.hyperlinks,
3298
+ extensionLinks: extensionLinksVersion(),
3141
3299
  textSizing: TERMINAL.textSizing,
3142
3300
  bgColorProbe,
3143
3301
  headingProbe,
@@ -3150,7 +3308,7 @@ export class Markdown implements Component {
3150
3308
  }
3151
3309
 
3152
3310
  #renderCacheKey(normalizedText: string, signature: RenderSignature): string {
3153
- return `${normalizedText}\x00${signature.width}\x00${signature.paddingX}\x00${signature.paddingY}\x00${signature.codeBlockIndent}\x00${signature.themeId}\x00${signature.defaultTextStyleId}\x00${signature.imageProtocol}\x00${signature.hyperlinks ? 1 : 0}\x00${signature.textSizing ? 1 : 0}\x00${signature.bgColorProbe}\x00${signature.headingProbe}\x00${signature.symbolsProbe}`;
3311
+ return `${normalizedText}\x00${signature.width}\x00${signature.paddingX}\x00${signature.paddingY}\x00${signature.codeBlockIndent}\x00${signature.themeId}\x00${signature.defaultTextStyleId}\x00${signature.imageProtocol}\x00${signature.hyperlinks ? 1 : 0}\x00${signature.extensionLinks}\x00${signature.textSizing ? 1 : 0}\x00${signature.bgColorProbe}\x00${signature.headingProbe}\x00${signature.symbolsProbe}`;
3154
3312
  }
3155
3313
 
3156
3314
  #renderStreamingContentLines(
@@ -3226,6 +3384,7 @@ export class Markdown implements Component {
3226
3384
  if (cache.defaultTextStyleId !== signature.defaultTextStyleId) return undefined;
3227
3385
  if (cache.imageProtocol !== signature.imageProtocol) return undefined;
3228
3386
  if (cache.hyperlinks !== signature.hyperlinks) return undefined;
3387
+ if (cache.extensionLinks !== signature.extensionLinks) return undefined;
3229
3388
  if (cache.textSizing !== signature.textSizing) return undefined;
3230
3389
  if (cache.bgColorProbe !== signature.bgColorProbe) return undefined;
3231
3390
  if (cache.headingProbe !== signature.headingProbe) return undefined;
@@ -3316,6 +3475,7 @@ export class Markdown implements Component {
3316
3475
  if (cache.defaultTextStyleId !== signature.defaultTextStyleId) return start;
3317
3476
  if (cache.imageProtocol !== signature.imageProtocol) return start;
3318
3477
  if (cache.hyperlinks !== signature.hyperlinks) return start;
3478
+ if (cache.extensionLinks !== signature.extensionLinks) return start;
3319
3479
  if (cache.textSizing !== signature.textSizing) return start;
3320
3480
  if (cache.bgColorProbe !== signature.bgColorProbe) return start;
3321
3481
  if (cache.headingProbe !== signature.headingProbe) return start;
@@ -3350,6 +3510,10 @@ export class Markdown implements Component {
3350
3510
  const token = tokens[i];
3351
3511
  const nextToken = tokens[i + 1];
3352
3512
  const tokenWrappedRowStart = wrappedLines.length;
3513
+ // Extension links are numbered per top-level block, across its nested inline runs, so
3514
+ // identical links on neighbouring rows draw distinct markers that every render repeats.
3515
+ this.#extensionLinkBlock = i;
3516
+ this.#extensionLinkOrdinal = 0;
3353
3517
  const renderedTokenLines = this.#renderToken(token, contentWidth, nextToken?.type);
3354
3518
  for (const renderedRow of renderedTokenLines) {
3355
3519
  // Lists wrap while their structural prefixes are still available, so
@@ -3483,7 +3647,8 @@ export class Markdown implements Component {
3483
3647
  const tokenText = "text" in token && typeof token.text === "string" ? token.text : "";
3484
3648
  const lang = "lang" in token && typeof token.lang === "string" ? token.lang : undefined;
3485
3649
  const addBodyLine = (line: string): void => {
3486
- bodyLines.push(renderedLine(literalCode ? line : codeIndent + line, literalCode));
3650
+ const linked = linkifyCodeUrls(line);
3651
+ bodyLines.push(renderedLine(literalCode ? linked : codeIndent + linked, literalCode));
3487
3652
  };
3488
3653
 
3489
3654
  const streaming = this.transientRenderCache && !this.#renderingStablePrefix;
@@ -3801,7 +3966,8 @@ export class Markdown implements Component {
3801
3966
  const headingText = this.#renderInlineTokens(token.tokens || [], this.#proseFgExemptContext(styleContext));
3802
3967
  const headingPlainText = plainInlineTokens(token.tokens || []);
3803
3968
  let styledHeading: string;
3804
- if (headingLevel === 1 && TERMINAL.textSizing) {
3969
+ // A sized heading draws plain text, which would drop a clickable extension link's marker.
3970
+ if (headingLevel === 1 && TERMINAL.textSizing && stripExtensionLinkMarkers(headingText) === headingText) {
3805
3971
  const plainWidth = visibleWidth(headingPlainText);
3806
3972
  if (plainWidth > 0 && 2 * plainWidth <= width) {
3807
3973
  const sizedHeading = encodeTextSizedHeading(headingPlainText, 2);
@@ -4120,8 +4286,15 @@ export class Markdown implements Component {
4120
4286
  token.tokens || [],
4121
4287
  this.#proseFgExemptContext(resolvedStyleContext),
4122
4288
  );
4123
- const styledLinkText = this.#theme.link(this.#theme.underline(linkText));
4124
4289
  const href = typeof token.href === "string" ? token.href : "";
4290
+ // An extension owns this link: no suffix, and no hyperlink the terminal could open.
4291
+ // Its label gets its own (dotted) underline instead of the web-link one.
4292
+ if (href && extensionLinkScheme(href)) {
4293
+ const key = `${this.#extensionLinkBlock}\0${this.#extensionLinkOrdinal++}`;
4294
+ result += formatExtensionLink(this.#theme.link(linkText), href, key) + stylePrefix;
4295
+ break;
4296
+ }
4297
+ const styledLinkText = this.#theme.link(this.#theme.underline(linkText));
4125
4298
  const target = (href && this.#theme.resolveLink?.(href)) || href;
4126
4299
  const clickableLinkText = formatHyperlink(styledLinkText, target);
4127
4300
  // If link text matches href, only show the link once. A missing
@@ -4283,7 +4456,13 @@ export class Markdown implements Component {
4283
4456
 
4284
4457
  // Process item tokens; nested-list lines arrive structurally tagged and
4285
4458
  // already carry their own full indent.
4286
- const itemLines = this.#renderListItem(item.tokens || [], depth, width, styleContext);
4459
+ const itemLines = this.#renderListItem(
4460
+ item.tokens || [],
4461
+ depth,
4462
+ width,
4463
+ Math.max(1, width - visibleWidth(continuationIndent)),
4464
+ styleContext,
4465
+ );
4287
4466
 
4288
4467
  if (itemLines.length > 0) {
4289
4468
  const firstLine = itemLines[0]!;
@@ -4335,11 +4514,13 @@ export class Markdown implements Component {
4335
4514
  tokens: Token[],
4336
4515
  parentDepth: number,
4337
4516
  width: number,
4517
+ contentWidth: number,
4338
4518
  styleContext?: InlineStyleContext,
4339
4519
  ): RenderedListItemLine[] {
4340
4520
  const lines: RenderedListItemLine[] = [];
4341
4521
 
4342
- for (const token of tokens) {
4522
+ for (let i = 0; i < tokens.length; i++) {
4523
+ const token = tokens[i]!;
4343
4524
  if (token.type === "list") {
4344
4525
  // Nested list - render with one additional indent level
4345
4526
  // These lines carry their own indent, so tag them for pass-through
@@ -4379,6 +4560,10 @@ export class Markdown implements Component {
4379
4560
  lines.push({ ...bodyLine, nested: false });
4380
4561
  }
4381
4562
  lines.push({ text: this.#theme.codeBlockBorder("```"), nested: false });
4563
+ } else if (token.type === "table") {
4564
+ for (const row of this.#renderTable(token as TableToken, contentWidth, tokens[i + 1]?.type, styleContext)) {
4565
+ lines.push({ text: row, nested: false });
4566
+ }
4382
4567
  } else if (isMathToken(token)) {
4383
4568
  // Display math block inside a list item: stack fractions / matrix rows.
4384
4569
  const apply = styleContext?.applyText ?? ((t: string) => this.#applyDefaultStyle(t));
@@ -4445,6 +4630,26 @@ export class Markdown implements Component {
4445
4630
  });
4446
4631
  }
4447
4632
 
4633
+ /**
4634
+ * Pad a table cell to the width of its column, following the column's GFM
4635
+ * alignment: a right-aligned cell ends at the column's right edge, a
4636
+ * centered one is surrounded by padding, and anything else stays flush left.
4637
+ */
4638
+ #alignCellText(text: string, width: number, align: Tokens.TableCell["align"]): string {
4639
+ const gap = Math.max(0, width - visibleWidth(text));
4640
+ if (gap === 0) return text;
4641
+ switch (align) {
4642
+ case "right":
4643
+ return padding(gap) + text;
4644
+ case "center": {
4645
+ const left = Math.floor(gap / 2);
4646
+ return padding(left) + text + padding(gap - left);
4647
+ }
4648
+ default:
4649
+ return text + padding(gap);
4650
+ }
4651
+ }
4652
+
4448
4653
  /**
4449
4654
  * Render a table with width-aware cell wrapping.
4450
4655
  * Cells that don't fit are wrapped to multiple lines.
@@ -4586,6 +4791,12 @@ export class Markdown implements Component {
4586
4791
  const h = t.horizontal;
4587
4792
  const v = t.vertical;
4588
4793
 
4794
+ // GFM alignment belongs to the column: the marker in the delimiter row
4795
+ // applies to the header and to every body cell below it.
4796
+ const columnAligns: Array<Tokens.TableCell["align"]> = token.header.map(
4797
+ (cell, i) => cell.align ?? token.align?.[i] ?? null,
4798
+ );
4799
+
4589
4800
  // Render top border
4590
4801
  const topBorderCells = columnWidths.map(w => h.repeat(w));
4591
4802
  lines.push(`${t.topLeft}${h}${topBorderCells.join(`${h}${t.teeDown}${h}`)}${h}${t.topRight}`);
@@ -4600,7 +4811,7 @@ export class Markdown implements Component {
4600
4811
  for (let lineIdx = 0; lineIdx < headerLineCount; lineIdx++) {
4601
4812
  const rowParts = headerCellLines.map((cellLines, colIdx) => {
4602
4813
  const text = cellLines[lineIdx] || "";
4603
- const padded = text + padding(Math.max(0, columnWidths[colIdx] - visibleWidth(text)));
4814
+ const padded = this.#alignCellText(text, columnWidths[colIdx], columnAligns[colIdx] ?? null);
4604
4815
  return this.#theme.bold(padded);
4605
4816
  });
4606
4817
  lines.push(`${v} ${rowParts.join(` ${v} `)} ${v}`);
@@ -4644,7 +4855,8 @@ export class Markdown implements Component {
4644
4855
  for (let lineIdx = 0; lineIdx < rowLineCount; lineIdx++) {
4645
4856
  const rowParts = rowCellLines.map((cellLines, colIdx) => {
4646
4857
  const text = cellLines[lineIdx] || "";
4647
- return text + padding(Math.max(0, columnWidths[colIdx] - visibleWidth(text)));
4858
+ const align = row[colIdx]?.align ?? columnAligns[colIdx] ?? null;
4859
+ return this.#alignCellText(text, columnWidths[colIdx], align);
4648
4860
  });
4649
4861
  lines.push(`${v} ${rowParts.join(` ${v} `)} ${v}`);
4650
4862
  }
@@ -135,10 +135,12 @@ function hotkeyGroups(bindings: HotkeysMarkdownBindings): HotkeyGroup[] {
135
135
  { keys: [act("app.history.search")], action: "Search prompt history" },
136
136
  { keys: [act("app.tools.expand")], action: "Toggle tool output expansion" },
137
137
  { keys: [act("app.tools.toggleVisibility")], action: "Toggle tool activity visibility" },
138
+ { keys: [act("app.links.hint")], action: "Pick an extension link on screen by its tag" },
138
139
  { keys: [act("app.ask.hide")], action: "Hide/show a pending ask question" },
139
140
  { keys: [act("app.approval.approve")], action: "Approve a pending tool call" },
140
141
  { keys: [act("app.thinking.toggle")], action: "Toggle thinking block visibility" },
141
142
  { keys: [act("app.editor.external")], action: "Edit message in external editor" },
143
+ { keys: [act("app.local.open")], action: "Open a local:// file in external editor" },
142
144
  { keys: [act("app.retry")], action: "Retry last failed assistant turn" },
143
145
  { keys: [act("app.clipboard.pasteImage")], action: "Paste image or text from clipboard" },
144
146
  {
@@ -39,15 +39,7 @@ import {
39
39
  type TspOp,
40
40
  } from "@linxiraos/pi-wire";
41
41
  import type { Terminal } from "../terminal";
42
- import {
43
- bindTheme,
44
- getCurrentThemeName,
45
- getNativeThemePalette,
46
- getNativeThemePaletteKey,
47
- isLightTheme,
48
- type NativeThemePalette,
49
- setNativeSymbolPreset,
50
- } from "../theme/theme";
42
+ import { getCurrentThemeName, isLightTheme, setNativeSymbolPreset } from "../theme/theme";
51
43
  import type { Component, OverlayOptions, RenderScheduler, RenderTimer } from "../tui";
52
44
  import { TspDocument } from "./apply";
53
45
  import { getNativeBlob, type NativeBlob } from "./blobs";
@@ -206,9 +198,10 @@ function sameSet(a: ReadonlySet<string>, b: ReadonlySet<string>): boolean {
206
198
  /**
207
199
  * Kinds newer than some Tern builds that answer `TERM_PROGRAM=tern`: used only
208
200
  * once the real `hello` lists them, so the optimistic start never emits a node
209
- * an older terminal cannot draw (`media`: files Tern loads by path).
201
+ * an older terminal cannot draw (`media`: files Tern loads by path; `json`:
202
+ * raw JSON values Tern draws as its own tree).
210
203
  */
211
- const UNASSUMED_KINDS: Partial<Record<TspKind, true>> = { media: true };
204
+ const UNASSUMED_KINDS: Partial<Record<TspKind, true>> = { media: true, json: true };
212
205
 
213
206
  /**
214
207
  * The reply a v1 terminal is assumed to give before its real `hello` arrives
@@ -313,11 +306,6 @@ export class NativeBackend {
313
306
  #sawResize = false;
314
307
  #live = false;
315
308
  #overlayNodes = new Map<Component, { key: string; node: NativeNode }>();
316
- #unbindTheme: (() => void) | undefined;
317
- #palette: NativeThemePalette | undefined;
318
- #paletteKey: string | undefined;
319
- /** Serialized palette last sent, to skip resends of an unchanged theme. */
320
- #paletteSent: string | undefined;
321
309
  /** Pending delivery owns bytes until sent or confirmed held; settled descriptions may already be released. */
322
310
  #blobs = new Map<string, NativeBlob | "sent">();
323
311
  /** `blobs` queries sent, oldest first: the terminal answers each once, in order. */
@@ -366,54 +354,11 @@ export class NativeBackend {
366
354
  if (this.#live) return;
367
355
  this.#live = true;
368
356
  this.#useNerdSymbols(true);
369
- this.#watchTheme();
370
357
  this.#open(this.#inline);
371
358
  setNativeRendering(true);
372
359
  this.render();
373
360
  }
374
361
 
375
- /**
376
- * Any theme swap (switch, selector preview, auto light/dark, file reload)
377
- * schedules a render; `render()` resends the palette when it changed, so
378
- * bursts coalesce into one `t` and no frame is needed for it.
379
- */
380
- #watchTheme(): void {
381
- this.#unbindTheme?.();
382
- let initial = true;
383
- this.#unbindTheme = bindTheme(() => {
384
- if (initial) return;
385
- this.#host.requestRender();
386
- });
387
- initial = false;
388
- }
389
-
390
- /** The current palette, recomputed only when its inputs changed. */
391
- #currentPalette(): NativeThemePalette {
392
- const key = getNativeThemePaletteKey();
393
- if (this.#palette === undefined || key !== this.#paletteKey) {
394
- this.#paletteKey = key;
395
- this.#palette = getNativeThemePalette();
396
- }
397
- return this.#palette;
398
- }
399
-
400
- /** Send the palette to `surface` (right after its `o`, before any `f`). */
401
- #sendPalette(surface: Surface): void {
402
- const palette = this.#currentPalette();
403
- if (!palette.dark && !palette.light) return;
404
- this.#paletteSent = JSON.stringify(palette);
405
- this.#write("t", { sf: surface.id, ...palette });
406
- }
407
-
408
- /** Resend the palette to every open surface when the theme changed since it was sent. */
409
- #refreshPalette(): void {
410
- const key = this.#paletteKey;
411
- const palette = this.#currentPalette();
412
- if (key === this.#paletteKey || JSON.stringify(palette) === this.#paletteSent) return;
413
- this.#sendPalette(this.#inline);
414
- if (this.#screen) this.#sendPalette(this.#screen);
415
- }
416
-
417
362
  /**
418
363
  * Tern's font carries every Nerd Font glyph, and it never answers the Glyph
419
364
  * Protocol, so icons come from the nerd preset (process-local, not the
@@ -435,8 +380,6 @@ export class NativeBackend {
435
380
  this.#close(this.#inline, keep);
436
381
  this.#inline.doc?.close();
437
382
  setNativeRendering(false);
438
- this.#unbindTheme?.();
439
- this.#unbindTheme = undefined;
440
383
  this.#useNerdSymbols(false);
441
384
  this.#clearStallTimer();
442
385
  // Replies no longer reach the backend: forget the queries outright.
@@ -455,7 +398,6 @@ export class NativeBackend {
455
398
  this.#applyHello(hello);
456
399
  this.#live = true;
457
400
  this.#useNerdSymbols(true);
458
- this.#watchTheme();
459
401
  this.#resetBlobs();
460
402
  const surface = this.#inline;
461
403
  surface.reconciler.detachLive();
@@ -466,7 +408,6 @@ export class NativeBackend {
466
408
  surface.focus = null;
467
409
  surface.dirty = false;
468
410
  this.#write("o", { id: surface.id, mode: "inline", title: "omp", role: SESSION_ROLE, adopt: true });
469
- this.#sendPalette(surface);
470
411
  // After the `o`, as in `start()`.
471
412
  setNativeRendering(true);
472
413
  this.render();
@@ -508,7 +449,6 @@ export class NativeBackend {
508
449
  /** Reconcile and send a frame, unless the target surface is out of credits. */
509
450
  render(): void {
510
451
  if (!this.#live) return;
511
- this.#refreshPalette();
512
452
  const overlays = this.#host.overlays();
513
453
  let fullscreen = -1;
514
454
  for (let i = overlays.length - 1; i >= 0; i--) {
@@ -608,7 +548,6 @@ export class NativeBackend {
608
548
 
609
549
  #open(surface: Surface): void {
610
550
  this.#write("o", { id: surface.id, mode: surface.mode, title: "omp", role: surface.role });
611
- this.#sendPalette(surface);
612
551
  }
613
552
 
614
553
  #close(surface: Surface, keep: boolean): void {
@@ -776,7 +715,7 @@ export class NativeBackend {
776
715
  }
777
716
  }
778
717
 
779
- #write(verb: "o" | "f" | "t" | "x" | "q", body: unknown): void {
718
+ #write(verb: "o" | "f" | "x" | "q", body: unknown): void {
780
719
  this.#record("out", verb, undefined, body);
781
720
  this.#host.terminal.write(encodeTspJson(verb, body, undefined, this.#limit));
782
721
  }
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Content-addressed binary blobs (images) for `image` nodes.
3
+ *
4
+ * `describe()` registers the bytes and puts the returned id in `image.p.blob`;
5
+ * the native backend delivers each referenced blob once per terminal
6
+ * connection (asking the terminal first which it holds, or through its blob
7
+ * cache), else uploads it with verb `b` before the frame that first
8
+ * references it.
9
+ */
1
10
  import type { TspProps } from "@linxiraos/pi-wire";
2
11
  import type { NativeChild, NativeNode } from "./node";
3
12
  export interface NativeBlob {
@@ -20,7 +29,8 @@ export declare function base64ImageNode(data: string, mimeType: string, p?: Omit
20
29
  /**
21
30
  * Props that make an `image` node open the file at `filePath` (as a `file://` URL, the TSP
22
31
  * open-target form): a click zooms the image in the terminal, and the file opens from its
23
- * context menu. Empty without a file.
32
+ * context menu. Always uses a local file URL because the open action runs locally,
33
+ * even when remote file handlers are configured. Empty without a file.
24
34
  */
25
35
  export declare function openableImageProps(filePath: string | undefined): Pick<TspProps<"image">, "href" | "actions">;
26
36
  /**
@@ -7,8 +7,8 @@
7
7
  * cache), else uploads it with verb `b` before the frame that first
8
8
  * references it.
9
9
  */
10
- import * as url from "node:url";
11
10
  import type { TspProps } from "@linxiraos/pi-wire";
11
+ import { tryFileUri } from "../render/hyperlink";
12
12
  import { resolveImageOptions } from "../render/render-utils";
13
13
  import { getImageDimensions } from "../terminal-capabilities";
14
14
  import { node } from "./describe";
@@ -97,10 +97,12 @@ export function base64ImageNode(
97
97
  /**
98
98
  * Props that make an `image` node open the file at `filePath` (as a `file://` URL, the TSP
99
99
  * open-target form): a click zooms the image in the terminal, and the file opens from its
100
- * context menu. Empty without a file.
100
+ * context menu. Always uses a local file URL because the open action runs locally,
101
+ * even when remote file handlers are configured. Empty without a file.
101
102
  */
102
103
  export function openableImageProps(filePath: string | undefined): Pick<TspProps<"image">, "href" | "actions"> {
103
- return filePath ? { href: url.pathToFileURL(filePath).href, actions: { menu: ["open"] } } : {};
104
+ const href = filePath ? tryFileUri(filePath, { local: true }) : undefined;
105
+ return href ? { href, actions: { menu: ["open"] } } : {};
104
106
  }
105
107
 
106
108
  /**