@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
@@ -0,0 +1,62 @@
1
+ /** Pure occupancy calculations for contiguous token segments, independent of themes and renderers. */
2
+ export interface ContextMapSegment<T> {
3
+ readonly id: T;
4
+ readonly tokens: number;
5
+ }
6
+
7
+ export interface ContextMapCell<T> {
8
+ readonly id: T;
9
+ readonly full: boolean;
10
+ }
11
+
12
+ /**
13
+ * Lays `segments` out in order over a `columns` × `rows` grid representing `windowTokens`; each cell takes the
14
+ * segment covering most of it and is `full` at 70% coverage or more. Returns `[]` when the window or grid
15
+ * size is unusable, and omits cells no segment touches.
16
+ */
17
+ export function planContextMap<T>(
18
+ segments: readonly ContextMapSegment<T>[],
19
+ windowTokens: number,
20
+ columns: number,
21
+ rows: number,
22
+ ): ContextMapCell<T>[] {
23
+ if (
24
+ !Number.isFinite(windowTokens) ||
25
+ windowTokens <= 0 ||
26
+ !Number.isInteger(columns) ||
27
+ !Number.isInteger(rows) ||
28
+ columns <= 0 ||
29
+ rows <= 0
30
+ )
31
+ return [];
32
+ const cellCount = columns * rows;
33
+ const tokensPerCell = windowTokens / cellCount;
34
+ const ranges: { id: T; start: number; end: number }[] = [];
35
+ let cursor = 0;
36
+ for (const segment of segments) {
37
+ if (!Number.isFinite(segment.tokens) || segment.tokens <= 0) continue;
38
+ const end = Math.min(windowTokens, cursor + segment.tokens);
39
+ if (end > cursor) ranges.push({ id: segment.id, start: cursor, end });
40
+ cursor = end;
41
+ if (cursor >= windowTokens) break;
42
+ }
43
+ const cells: ContextMapCell<T>[] = [];
44
+ let first = 0;
45
+ for (let index = 0; index < cellCount; index++) {
46
+ const start = index * tokensPerCell;
47
+ const end = (index + 1) * tokensPerCell;
48
+ while (first < ranges.length && ranges[first]!.end <= start) first++;
49
+ let winner: T | undefined;
50
+ let overlap = 0;
51
+ for (let part = first; part < ranges.length && ranges[part]!.start < end; part++) {
52
+ const range = ranges[part]!;
53
+ const covered = Math.min(end, range.end) - Math.max(start, range.start);
54
+ if (covered > overlap) {
55
+ overlap = covered;
56
+ winner = range.id;
57
+ }
58
+ }
59
+ if (winner !== undefined) cells.push({ id: winner, full: overlap / tokensPerCell >= 0.7 });
60
+ }
61
+ return cells;
62
+ }
@@ -0,0 +1,26 @@
1
+ import type { ThemeColor } from "../theme";
2
+ import type { SymbolKey } from "../theme/symbols";
3
+ import type { ContextCategoryId } from "./context-view-model";
4
+
5
+ /** Shared category styles for maps and interactive legends; resolve glyphs at render time. */
6
+ const SYSTEM = { color: "accent", symbol: "context.content" } as const;
7
+ const DETAILS = { color: "customMessageLabel", symbol: "context.content" } as const;
8
+ const TOOLS = { color: "warning", symbol: "context.content" } as const;
9
+ const SKILLS = { color: "success", symbol: "context.content" } as const;
10
+ const MESSAGES = { color: "userMessageText", symbol: "context.messages" } as const;
11
+ const OUTPUT = { color: "muted", symbol: "context.messages" } as const;
12
+ export const CONTEXT_PRESENTATION = {
13
+ "system-prompt": SYSTEM,
14
+ skills: SKILLS,
15
+ "built-in-tools": TOOLS,
16
+ "custom-tools": DETAILS,
17
+ // Shares the System Prompt color; the message glyph tells them apart in the map.
18
+ "user-messages": { color: "accent", symbol: "context.messages" },
19
+ "assistant-messages": MESSAGES,
20
+ "assistant-thinking": DETAILS,
21
+ "tool-calls": TOOLS,
22
+ "tool-output": OUTPUT,
23
+ buffer: { color: "warning", symbol: "context.buffer" },
24
+ free: { color: "dim", symbol: "context.free" },
25
+ } as const satisfies Record<ContextPresentationId, { color: ThemeColor; symbol: SymbolKey }>;
26
+ export type ContextPresentationId = ContextCategoryId | "buffer" | "free";
@@ -0,0 +1,73 @@
1
+ /** Context snapshot shapes shared by the session snapshot builder and the context viewer. */
2
+ import type { ContextBreakdown } from "../status-line/context-usage";
3
+
4
+ interface ContextCategoryDescriptor {
5
+ readonly id: string;
6
+ readonly label: string;
7
+ /** Overview row label when the Overview weight differs from the category's content. */
8
+ readonly overviewLabel?: string;
9
+ /** Listed with its weight but never opened. */
10
+ readonly openable?: false;
11
+ }
12
+
13
+ /** Context categories in display order. */
14
+ export const CONTEXT_CATEGORIES = [
15
+ // The Overview weight excludes the Skills listing; content views keep complete system blocks.
16
+ { id: "system-prompt", label: "System Prompt", overviewLabel: "System Prompt (excluding Skills)" },
17
+ // An estimate of the prompt's skill listing, without entries of its own.
18
+ { id: "skills", label: "Skills", openable: false },
19
+ { id: "built-in-tools", label: "Built-in Tools" },
20
+ { id: "custom-tools", label: "Custom Tools" },
21
+ { id: "user-messages", label: "User / Developer Messages" },
22
+ { id: "assistant-messages", label: "Assistant Messages" },
23
+ { id: "assistant-thinking", label: "Assistant Thinking" },
24
+ { id: "tool-calls", label: "Tool Calls" },
25
+ { id: "tool-output", label: "Tool Output" },
26
+ ] as const satisfies readonly ContextCategoryDescriptor[];
27
+
28
+ export type ContextCategoryId = (typeof CONTEXT_CATEGORIES)[number]["id"];
29
+
30
+ const DESCRIPTORS_BY_ID = new Map<ContextCategoryId, ContextCategoryDescriptor>(
31
+ CONTEXT_CATEGORIES.map(descriptor => [descriptor.id, descriptor]),
32
+ );
33
+
34
+ /** Descriptor of a category id: its label, optional Overview label, and whether it can be opened. */
35
+ export function contextCategoryDescriptor(id: ContextCategoryId): ContextCategoryDescriptor {
36
+ return DESCRIPTORS_BY_ID.get(id)!;
37
+ }
38
+
39
+ export interface ContextThinkingGroup {
40
+ readonly id: string;
41
+ readonly label: string;
42
+ readonly tokens: number;
43
+ readonly interrupted?: boolean;
44
+ }
45
+
46
+ export interface ContextViewEntry {
47
+ readonly id: string;
48
+ readonly label: string;
49
+ readonly text: string;
50
+ /** Aggregation weight for the unscaled replay estimate; shared blocks contribute through their group. */
51
+ readonly tokens: number;
52
+ readonly interrupted?: boolean;
53
+ readonly thinkingGroup?: ContextThinkingGroup;
54
+ readonly path?: string;
55
+ readonly info?: string;
56
+ readonly timestamp?: number;
57
+ readonly callId?: string;
58
+ }
59
+
60
+ export interface ContextViewCategory {
61
+ id: ContextCategoryId;
62
+ key?: string;
63
+ label: string;
64
+ /** Overview attribution weight, not reported usage; may differ from the entry sum (e.g. Skills subtraction). */
65
+ tokens: number;
66
+ entries: ContextViewEntry[];
67
+ children?: ContextViewCategory[];
68
+ }
69
+
70
+ export interface ContextViewData {
71
+ readonly breakdown: ContextBreakdown;
72
+ readonly categories: readonly ContextViewCategory[];
73
+ }
@@ -17,5 +17,6 @@ export * from "./shared";
17
17
  export * from "./streaming-panel";
18
18
  export * from "./tool-activity";
19
19
  export * from "./transcript-container";
20
+ export * from "./transcript-notice";
20
21
  export * from "./transcript-status";
21
22
  export * from "./visual-truncate";
@@ -1,7 +1,7 @@
1
1
  import { type Component, Container, type HistoryBatch } from "../tui";
2
2
  import * as logger from "@linxiraos/pi-utils/logger";
3
3
  import { popLoopPhase, pushLoopPhase } from "@linxiraos/pi-utils";
4
- import { renderForScrollback } from "../components/image";
4
+ import { measureRender, renderForScrollback } from "../components/image";
5
5
  import { col } from "../native/describe";
6
6
  import type { NativeNode } from "../native/node";
7
7
  import { isNativeSettled, settleNative } from "../native/settle";
@@ -97,13 +97,6 @@ interface TranscriptEntry {
97
97
  * state for emitted-row slicing but never emits another mid-stream row.
98
98
  */
99
99
  stableFrozen: boolean;
100
- /**
101
- * Cached "renders at least one image line" result for the settled-image
102
- * flush, keyed by width and image protocol (the probe upgrade re-encodes
103
- * text-fallback blocks into graphics). Rows of a settled block are frozen,
104
- * so a hit is exact.
105
- */
106
- imageScan: { width: number; protocol: string | null; hasImageRows: boolean } | undefined;
107
100
  /**
108
101
  * Head rows of a settled block already in native history while the rest
109
102
  * stays live: pressure commits only the rows that left the screen, so no
@@ -166,6 +159,17 @@ const RETIREMENT_BUDGET_MS = 8;
166
159
  const EMPTY_ROWS: readonly string[] = [];
167
160
  const EMPTY_STABLE_ROWS: readonly TranscriptStableRow[] = [];
168
161
 
162
+ /** A block's full-allocation render taken by {@link TranscriptContainer}'s walk-order measurement. */
163
+ interface MeasuredBlock {
164
+ rows: readonly string[];
165
+ /** Whether the render observed a budgeted image; see {@link measureRender}. */
166
+ images: boolean;
167
+ /** Whether a budgeted image in the block is demoted to its text fallback. */
168
+ demoted: boolean;
169
+ /** Whether a budgeted image has no slot yet from a full pass. */
170
+ unresolved: boolean;
171
+ }
172
+
169
173
  function isFinalized(component: Component): boolean {
170
174
  const block = component as Component & FinalizableBlock;
171
175
  return (block.isTranscriptBlockFinalized?.() ?? true) && block.isTranscriptBlockPending?.() !== true;
@@ -289,7 +293,7 @@ export class TranscriptContainer extends Container {
289
293
  * composition, with no block mutation possible in between; replaying the
290
294
  * first measurement spares every block its second render per frame.
291
295
  */
292
- #frameRows = new Map<TranscriptEntry, readonly string[]>();
296
+ #frameRows = new Map<TranscriptEntry, MeasuredBlock>();
293
297
  #frameRowsWidth = 0;
294
298
  #releaseFailures = new WeakSet<Component>();
295
299
  /** The `children` array `#entries` last mirrored; see {@link #syncEntries}. */
@@ -311,7 +315,6 @@ export class TranscriptContainer extends Container {
311
315
  stableRowCountByWidth: new Map(),
312
316
  emitted: 0,
313
317
  stableFrozen: false,
314
- imageScan: undefined,
315
318
  split: undefined,
316
319
  });
317
320
  // `children` is public and may be edited externally; re-check the whole
@@ -518,41 +521,54 @@ export class TranscriptContainer extends Container {
518
521
  this.#settleFinalized();
519
522
  let total = 0;
520
523
  for (const { entry, index } of this.#liveEntries()) {
521
- const block = this.#liveBlockRows(entry, index, width);
524
+ const block = this.#liveBlock(entry, index, width).rows;
522
525
  if (block.length > 0) total += block.length + (total > 0 ? 1 : 0);
523
526
  if (total > limit) break;
524
527
  }
525
528
  return total;
526
529
  }
527
530
 
528
- /** One live block's un-emitted rows at `width`, rendered against its full-height allocation. */
529
- #liveBlockRows(entry: TranscriptEntry, index: number, width: number): readonly string[] {
530
- const rows = this.#measuredRows(entry, width);
531
+ /** One live block's un-emitted rows at `width`, measured against its full-height allocation. */
532
+ #liveBlock(entry: TranscriptEntry, index: number, width: number): MeasuredBlock {
533
+ const measured = this.#measure(entry, width);
531
534
  const emitted = this.#projectedEmittedRowCount(entry, index, width);
532
- return emitted === 0 ? rows : rows.slice(emitted);
535
+ return emitted === 0
536
+ ? measured
537
+ : {
538
+ rows: measured.rows.slice(emitted),
539
+ images: measured.images,
540
+ demoted: measured.demoted,
541
+ unresolved: measured.unresolved,
542
+ };
533
543
  }
534
544
 
535
545
  /**
536
546
  * One block's blank-trimmed render at its full-height allocation. Inside an
537
547
  * open frame the first measurement of each block is replayed to later ones,
538
548
  * leaving whatever allocation the viewport has since rendered it at.
549
+ *
550
+ * Measurements run in walk order, not display order, so they render under
551
+ * {@link measureRender}: a block whose images they observed must render
552
+ * again in display order before its rows are laid out.
539
553
  */
540
- #measuredRows(entry: TranscriptEntry, width: number): readonly string[] {
541
- if (this.#openFrame === undefined) {
542
- this.#setAllocation(entry.component, Number.MAX_SAFE_INTEGER, this.#lastFrame);
543
- return this.#renderEntry(entry, width);
544
- }
554
+ #measure(entry: TranscriptEntry, width: number): MeasuredBlock {
555
+ if (this.#openFrame === undefined) return this.#measureEntry(entry, width);
545
556
  if (this.#frameRowsWidth !== width) {
546
557
  this.#frameRows.clear();
547
558
  this.#frameRowsWidth = width;
548
559
  }
549
- let rows = this.#frameRows.get(entry);
550
- if (rows === undefined) {
551
- this.#setAllocation(entry.component, Number.MAX_SAFE_INTEGER, this.#lastFrame);
552
- rows = this.#renderEntry(entry, width);
553
- this.#frameRows.set(entry, rows);
560
+ let measured = this.#frameRows.get(entry);
561
+ if (measured === undefined) {
562
+ measured = this.#measureEntry(entry, width);
563
+ this.#frameRows.set(entry, measured);
554
564
  }
555
- return rows;
565
+ return measured;
566
+ }
567
+
568
+ #measureEntry(entry: TranscriptEntry, width: number): MeasuredBlock {
569
+ this.#setAllocation(entry.component, Number.MAX_SAFE_INTEGER, this.#lastFrame);
570
+ const { value: rows, images, demoted, unresolved } = measureRender(() => this.#renderEntry(entry, width));
571
+ return { rows, images, demoted, unresolved };
556
572
  }
557
573
 
558
574
  #closeFrame(): void {
@@ -614,6 +630,7 @@ export class TranscriptContainer extends Container {
614
630
  // show — the whole ledger on a resumed session's first paint (#12933).
615
631
  const shown: Array<{ entry: TranscriptEntry; index: number }> = [];
616
632
  const blocks: (readonly string[])[] = [];
633
+ const measuredImages: boolean[] = [];
617
634
  let unrendered = 0;
618
635
  for (let cursor = live.length - 1; cursor >= 0; cursor--) {
619
636
  if (shown.length > capacity) {
@@ -621,15 +638,15 @@ export class TranscriptContainer extends Container {
621
638
  break;
622
639
  }
623
640
  const candidate = live[cursor]!;
624
- const block = this.#liveBlockRows(candidate.entry, candidate.index, width);
625
- if (block.length === 0) continue;
641
+ const block = this.#liveBlock(candidate.entry, candidate.index, width);
642
+ if (block.rows.length === 0) continue;
626
643
  shown.push(candidate);
627
- blocks.push(block);
644
+ blocks.push(block.rows);
645
+ measuredImages.push(block.images);
628
646
  }
629
647
  shown.reverse();
630
648
  blocks.reverse();
631
- let total = 0;
632
- for (const block of blocks) total += block.length + (total > 0 ? 1 : 0);
649
+ measuredImages.reverse();
633
650
  if (shown.length === 0) {
634
651
  this.#lastViewportSpans = [];
635
652
  return EMPTY_ROWS;
@@ -639,6 +656,19 @@ export class TranscriptContainer extends Container {
639
656
  // emergency layout consults them only where it must.
640
657
  return this.#renderEmergency(shown, live.slice(0, unrendered), width, capacity, frame);
641
658
  }
659
+ // The walk ran newest-first, so the images it measured claimed no
660
+ // display slot (see #measure). Render those blocks again oldest-first:
661
+ // the image budget keeps the newest images live by observation order.
662
+ for (let blockIndex = 0; blockIndex < shown.length; blockIndex++) {
663
+ if (!measuredImages[blockIndex]) continue;
664
+ const { entry, index } = shown[blockIndex]!;
665
+ this.#setAllocation(entry.component, Number.MAX_SAFE_INTEGER, frame);
666
+ blocks[blockIndex] = this.#renderEntry(entry, width).slice(
667
+ this.#projectedEmittedRowCount(entry, index, width),
668
+ );
669
+ }
670
+ let total = 0;
671
+ for (const block of blocks) total += block.length + (total > 0 ? 1 : 0);
642
672
  if (total <= capacity) {
643
673
  const output: string[] = [];
644
674
  const owners: (Component | undefined)[] = [];
@@ -786,7 +816,7 @@ export class TranscriptContainer extends Container {
786
816
  // Only a render publishes a block's stable rows, so the head renders
787
817
  // before its progressive-append eligibility is read.
788
818
  const head = this.#entries[this.#frontier];
789
- if (head !== undefined) this.#measuredRows(head, width);
819
+ if (head !== undefined) this.#measure(head, width);
790
820
  const appendHead =
791
821
  policy === "pressure" &&
792
822
  head?.mode === "appendOnly" &&
@@ -810,7 +840,7 @@ export class TranscriptContainer extends Container {
810
840
  let fits = true;
811
841
  for (let cursor = live.length - 1; cursor >= 0; cursor--) {
812
842
  const candidate = live[cursor]!;
813
- const height = this.#liveBlockRows(candidate.entry, candidate.index, width).length;
843
+ const height = this.#liveBlock(candidate.entry, candidate.index, width).rows.length;
814
844
  if (height > 0) liveRows += height + (liveRows > 0 ? 1 : 0);
815
845
  if (fits) {
816
846
  const next = height > 0 ? tailRows + height + (tailRows > 0 ? 1 : 0) : tailRows;
@@ -940,11 +970,13 @@ export class TranscriptContainer extends Container {
940
970
  width: number,
941
971
  visible: number,
942
972
  ): { rows: readonly string[]; split: RowSplit } | "whole" | undefined {
943
- const measured = this.#measuredRows(entry, width);
973
+ const measured = this.#measure(entry, width).rows;
944
974
  const start = this.#emittedRowCount(entry, width);
945
975
  const cut = measured.length - visible;
946
976
  if (cut <= start) return undefined;
947
- const scrollback = renderForScrollback(() => this.#renderEntry(entry, width));
977
+ // The boundary block stays live, so the viewport renders it in display
978
+ // order; this render precedes the retired blocks and must claim no slot.
979
+ const scrollback = measureRender(() => renderForScrollback(() => this.#renderEntry(entry, width))).value;
948
980
  if (scrollback.length !== measured.length) return undefined;
949
981
  const total = cutBelowWholeImage(scrollback, cut);
950
982
  if (total >= scrollback.length) return "whole";
@@ -1153,7 +1185,7 @@ export class TranscriptContainer extends Container {
1153
1185
  * content stays live: it can repeat committed text but never drop any.
1154
1186
  */
1155
1187
  #splitRowCount(entry: TranscriptEntry, split: RowSplit, width: number): number {
1156
- const rendered = this.#measuredRows(entry, width);
1188
+ const rendered = this.#measure(entry, width).rows;
1157
1189
  if (split.located?.rendered === rendered) return split.located.count;
1158
1190
  let count = 0;
1159
1191
  if (
@@ -1355,10 +1387,10 @@ export class TranscriptContainer extends Container {
1355
1387
  const entry = this.#entries[this.#frontier]!;
1356
1388
  if (entry.state !== "settled") return;
1357
1389
  if (entry.split !== undefined) {
1358
- if (this.#splitRowCount(entry, entry.split, width) < this.#measuredRows(entry, width).length) return;
1390
+ if (this.#splitRowCount(entry, entry.split, width) < this.#measure(entry, width).rows.length) return;
1359
1391
  } else {
1360
1392
  if (entry.mode !== "appendOnly") return;
1361
- const rendered = this.#measuredRows(entry, width);
1393
+ const rendered = this.#measure(entry, width).rows;
1362
1394
  if (entry.emitted !== entry.stableRows.length) return;
1363
1395
  if (this.#renderStablePrefix(entry, entry.emitted, width).length !== rendered.length) return;
1364
1396
  }
@@ -1423,7 +1455,7 @@ export class TranscriptContainer extends Container {
1423
1455
  let hiddenBelow = 0;
1424
1456
  for (const candidate of behind) {
1425
1457
  if (candidate.entry.state !== "active") continue;
1426
- if (this.#liveBlockRows(candidate.entry, candidate.index, width).length > 0) hiddenBelow++;
1458
+ if (this.#liveBlock(candidate.entry, candidate.index, width).rows.length > 0) hiddenBelow++;
1427
1459
  }
1428
1460
  let behindEmergency: { candidate: { entry: TranscriptEntry; index: number }; row: string } | null | undefined;
1429
1461
  const findBehindEmergency = () => {
@@ -1434,7 +1466,7 @@ export class TranscriptContainer extends Container {
1434
1466
  if (candidate.entry.state !== "settled") continue;
1435
1467
  const block = candidate.entry.component as Component & FinalizableBlock;
1436
1468
  if (block.renderTranscriptBlockEmergencyRow === undefined) continue;
1437
- if (this.#liveBlockRows(candidate.entry, candidate.index, width).length === 0) continue;
1469
+ if (this.#liveBlock(candidate.entry, candidate.index, width).rows.length === 0) continue;
1438
1470
  const row = block.renderTranscriptBlockEmergencyRow(width);
1439
1471
  if (row === undefined) continue;
1440
1472
  behindEmergency = { candidate, row };
@@ -1541,28 +1573,27 @@ export class TranscriptContainer extends Container {
1541
1573
  for (let index = this.#frontier; index < this.#entries.length; index++) {
1542
1574
  const entry = this.#entries[index]!;
1543
1575
  if (entry.state !== "settled") break;
1544
- if (this.#hasImageRows(entry, width)) last = index;
1576
+ const state = this.#imageFlushState(entry, width);
1577
+ // Retiring "through" a held block would take it along: stop before it.
1578
+ if (state === "hold") break;
1579
+ if (state === "flush") last = index;
1545
1580
  }
1546
1581
  return last < 0 ? -1 : last + 1;
1547
1582
  }
1548
1583
 
1549
- /** Whether the block's measured rows carry an image sequence (cached per width and protocol). */
1550
- #hasImageRows(entry: TranscriptEntry, width: number): boolean {
1551
- const protocol = TERMINAL.imageProtocol;
1552
- const cached = entry.imageScan;
1553
- if (cached !== undefined && cached.width === width && cached.protocol === protocol) return cached.hasImageRows;
1554
- let hasImageRows = false;
1555
- if (protocol !== null) {
1556
- const rows = this.#measuredRows(entry, width);
1557
- for (let index = 0; index < rows.length; index++) {
1558
- if (TERMINAL.isImageLine(rows[index]!)) {
1559
- hasImageRows = true;
1560
- break;
1561
- }
1562
- }
1563
- }
1564
- entry.imageScan = { width, protocol, hasImageRows };
1565
- return hasImageRows;
1584
+ /**
1585
+ * Whether the block's measured rows carry live graphics that must reach
1586
+ * scrollback early ("flush"), image rows that must keep their viewport rows
1587
+ * ("hold"), or no image at all ("none"). A demoted image renders as its text
1588
+ * fallback, which needs no graphics commit, and an image whose budget slot is
1589
+ * not known yet must wait for a full pass to decide. Re-measured per call
1590
+ * because both answers change with the budget's split.
1591
+ */
1592
+ #imageFlushState(entry: TranscriptEntry, width: number): "none" | "flush" | "hold" {
1593
+ if (TERMINAL.imageProtocol === null) return "none";
1594
+ const measured = this.#measure(entry, width);
1595
+ if (!measured.images) return "none";
1596
+ return measured.demoted || measured.unresolved ? "hold" : "flush";
1566
1597
  }
1567
1598
 
1568
1599
  #liveEntries(): Array<{ entry: TranscriptEntry; index: number }> {
@@ -1609,7 +1640,6 @@ export class TranscriptContainer extends Container {
1609
1640
  stableRowCountByWidth: new Map(),
1610
1641
  emitted: 0,
1611
1642
  stableFrozen: false,
1612
- imageScan: undefined,
1613
1643
  split: undefined,
1614
1644
  },
1615
1645
  );
@@ -0,0 +1,35 @@
1
+ import type { TspText } from "@linxiraos/pi-wire";
2
+ import type { NativeNode } from "../native/node";
3
+ import type { Component } from "../tui";
4
+ import { TranscriptBlock } from "./transcript-container";
5
+ /** How loud an inline transcript notice is; a native terminal styles it as `zeta.notice.<tone>`. */
6
+ export type NoticeTone = "info" | "success" | "warning" | "error";
7
+ /** Optional parts of a {@link noticeRow}. */
8
+ export interface NoticeRowOptions {
9
+ /** Icon name in place of the tone's own (`read` for a file read, `download` for an update). */
10
+ readonly icon?: string;
11
+ readonly key?: string;
12
+ }
13
+ /**
14
+ * One inline transcript notice for a native terminal (`zeta.notice.<tone>`): a
15
+ * leading icon beside the wrapped message. Warnings, errors, background-job
16
+ * completions and prompt file reads all draw as this row, so they read alike.
17
+ * The tone colors the icon (an info notice keeps it quiet); the message spans
18
+ * carry emphasis only (`path`, `mono`, `dim`), never the tone itself.
19
+ */
20
+ export declare function noticeRow(tone: NoticeTone, message: TspText, options?: NoticeRowOptions): NativeNode;
21
+ /**
22
+ * A transcript block that a native terminal draws as one {@link noticeRow}
23
+ * while a text terminal draws `ansi`.
24
+ */
25
+ export declare class TranscriptNotice extends TranscriptBlock {
26
+ #private;
27
+ constructor(native: NativeNode, ansi: readonly Component[]);
28
+ /**
29
+ * `showWarning` / `showError`: a blank row and the `Warning: …` / `Error: …`
30
+ * line in its color in a text terminal; natively the tone's icon and the
31
+ * message, the label left to the icon.
32
+ */
33
+ static line(tone: "warning" | "error", message: string): TranscriptNotice;
34
+ describe(): NativeNode;
35
+ }
@@ -0,0 +1,83 @@
1
+ import type { TspText } from "@linxiraos/pi-wire";
2
+ import { Spacer } from "../components/spacer";
3
+ import { Text } from "../components/text";
4
+ import { node, text } from "../native/describe";
5
+ import type { NativeNode } from "../native/node";
6
+ import { styledSpans } from "../native/spans";
7
+ import { theme } from "../theme";
8
+ import type { Component } from "../tui";
9
+ import { TranscriptBlock } from "./transcript-container";
10
+
11
+ /** How loud an inline transcript notice is; a native terminal styles it as `zeta.notice.<tone>`. */
12
+ export type NoticeTone = "info" | "success" | "warning" | "error";
13
+
14
+ /** Each tone's default icon. */
15
+ const ICONS: Readonly<Record<NoticeTone, string>> = {
16
+ info: "info",
17
+ success: "success",
18
+ warning: "warning",
19
+ error: "error",
20
+ };
21
+
22
+ /**
23
+ * The word a warning or error leads with: a text terminal writes it
24
+ * (`Warning: …`); a native row leaves it to the icon, whose name it becomes
25
+ * for screen readers.
26
+ */
27
+ const LABELS = { warning: "Warning", error: "Error" } as const;
28
+
29
+ /** Optional parts of a {@link noticeRow}. */
30
+ export interface NoticeRowOptions {
31
+ /** Icon name in place of the tone's own (`read` for a file read, `download` for an update). */
32
+ readonly icon?: string;
33
+ readonly key?: string;
34
+ }
35
+
36
+ /**
37
+ * One inline transcript notice for a native terminal (`zeta.notice.<tone>`): a
38
+ * leading icon beside the wrapped message. Warnings, errors, background-job
39
+ * completions and prompt file reads all draw as this row, so they read alike.
40
+ * The tone colors the icon (an info notice keeps it quiet); the message spans
41
+ * carry emphasis only (`path`, `mono`, `dim`), never the tone itself.
42
+ */
43
+ export function noticeRow(tone: NoticeTone, message: TspText, options: NoticeRowOptions = {}): NativeNode {
44
+ const icon = node("icon", {
45
+ name: options.icon ?? ICONS[tone],
46
+ tone: tone === "info" ? undefined : tone,
47
+ aria: tone === "warning" || tone === "error" ? LABELS[tone] : undefined,
48
+ });
49
+ return node(
50
+ "row",
51
+ { role: `zeta.notice.${tone}`, tone, gap: "sm", align: "start" },
52
+ [icon, text(message, { wrap: "word", grow: 1, shrink: 1 })],
53
+ options.key,
54
+ );
55
+ }
56
+
57
+ /**
58
+ * A transcript block that a native terminal draws as one {@link noticeRow}
59
+ * while a text terminal draws `ansi`.
60
+ */
61
+ export class TranscriptNotice extends TranscriptBlock {
62
+ readonly #native: NativeNode;
63
+
64
+ constructor(native: NativeNode, ansi: readonly Component[]) {
65
+ super();
66
+ for (const child of ansi) this.addChild(child);
67
+ this.#native = native;
68
+ }
69
+
70
+ /**
71
+ * `showWarning` / `showError`: a blank row and the `Warning: …` / `Error: …`
72
+ * line in its color in a text terminal; natively the tone's icon and the
73
+ * message, the label left to the icon.
74
+ */
75
+ static line(tone: "warning" | "error", message: string): TranscriptNotice {
76
+ const line = new Text(`${LABELS[tone]}: ${message}`, 1, 0).setStyleFn(t => theme.fg(tone, t));
77
+ return new TranscriptNotice(noticeRow(tone, styledSpans(message)), [new Spacer(1), line]);
78
+ }
79
+
80
+ override describe(): NativeNode {
81
+ return this.#native;
82
+ }
83
+ }
@@ -1,24 +1,36 @@
1
+ import type { TspSpan } from "@linxiraos/pi-wire";
1
2
  import type { NativeNode } from "../native/node";
2
3
  import { type ThemeColor } from "../theme";
3
4
  import { TranscriptBlock } from "./transcript-container";
4
- /** One themed run of a status row. */
5
+ import { type NoticeTone } from "./transcript-notice";
6
+ /** One themed run of a status row's terminal line. */
5
7
  export interface TranscriptStatusPart {
6
8
  readonly text: string;
7
9
  readonly color: ThemeColor;
8
- /** Glyph art (tree connectors) drawn only in rows; native terminals draw their own structure. */
9
- readonly rowsOnly?: boolean;
10
10
  }
11
- /** One compact transcript status row assembled from themed parts, joined by single spaces. */
11
+ /** A status row in a native terminal: its {@link noticeRow}'s tone, icon and message. */
12
+ export interface TranscriptStatusNative {
13
+ readonly tone: NoticeTone;
14
+ /** Icon name in place of the tone's own. */
15
+ readonly icon?: string;
16
+ readonly message: readonly TspSpan[];
17
+ }
18
+ /**
19
+ * One compact transcript status row: the terminal line's themed parts (joined
20
+ * by single spaces, glyphs and brackets included) and the same row natively.
21
+ */
12
22
  export interface TranscriptStatusRow {
13
23
  readonly parts: readonly (TranscriptStatusPart | undefined)[];
14
24
  readonly indent?: number;
25
+ readonly native: TranscriptStatusNative;
15
26
  }
16
- /** Shared compact status-pill block used by notices and background activity. */
27
+ /**
28
+ * Shared compact status block for background activity and prompt file reads:
29
+ * one themed line per row in a text terminal, one notice row per row natively
30
+ * (`zeta.status-block`).
31
+ */
17
32
  export declare class TranscriptStatusBlock extends TranscriptBlock {
18
33
  #private;
19
34
  constructor(rows: readonly TranscriptStatusRow[]);
20
- /** Append a supplemental line such as an artifact warning. */
21
- addLine(parts: readonly (TranscriptStatusPart | undefined)[], indent?: number): void;
22
- /** One wrapped text line per status row. */
23
35
  describe(): NativeNode;
24
36
  }