@linxiraos/pi-tui 1.4.6 → 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 (278) hide show
  1. package/CHANGELOG.md +194 -195
  2. package/README.md +34 -34
  3. package/dist/types/app-keybindings.d.ts +15 -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/index.d.ts +1 -0
  16. package/dist/types/chrome/transcript-notice.d.ts +35 -0
  17. package/dist/types/chrome/transcript-status.d.ts +20 -8
  18. package/dist/types/components/editor.d.ts +8 -0
  19. package/dist/types/components/markdown.d.ts +7 -0
  20. package/dist/types/native/blobs.d.ts +2 -1
  21. package/dist/types/native/picker.d.ts +4 -4
  22. package/dist/types/overlays/annotation-overlay.d.ts +7 -1
  23. package/dist/types/overlays/annotation-types.d.ts +28 -0
  24. package/dist/types/overlays/login-dialog.d.ts +5 -1
  25. package/dist/types/overlays/model-browser.d.ts +10 -1
  26. package/dist/types/overlays/oauth-selector.d.ts +23 -0
  27. package/dist/types/overlays/plan-review-overlay.d.ts +2 -0
  28. package/dist/types/overlays/rewind-selector.d.ts +1 -1
  29. package/dist/types/overlays/session-selector.d.ts +22 -2
  30. package/dist/types/prompt/composer.d.ts +43 -0
  31. package/dist/types/prompt/interactive-context-helpers.d.ts +10 -3
  32. package/dist/types/render/extension-links.d.ts +65 -0
  33. package/dist/types/render/hyperlink.d.ts +25 -7
  34. package/dist/types/render/index.d.ts +1 -0
  35. package/dist/types/setup/scenes/glyph.d.ts +1 -1
  36. package/dist/types/setup/scenes/model.d.ts +1 -1
  37. package/dist/types/setup/scenes/outro.d.ts +5 -4
  38. package/dist/types/setup/scenes/sign-in.d.ts +13 -8
  39. package/dist/types/setup/scenes/types.d.ts +16 -1
  40. package/dist/types/setup/startup-splash.d.ts +1 -1
  41. package/dist/types/setup/wizard-overlay.d.ts +11 -7
  42. package/dist/types/setup/wizard.d.ts +5 -1
  43. package/dist/types/status-line/component.d.ts +1 -1
  44. package/dist/types/status-line/context-usage.d.ts +28 -6
  45. package/dist/types/status-line/host.d.ts +6 -2
  46. package/dist/types/theme/theme.d.ts +0 -23
  47. package/dist/types/tools/bash-interactive.d.ts +6 -0
  48. package/dist/types/tools/bash.d.ts +2 -0
  49. package/dist/types/tools/default-renderer.d.ts +6 -4
  50. package/dist/types/tools/irc.d.ts +6 -0
  51. package/dist/types/tools/json-tree.d.ts +23 -4
  52. package/dist/types/tools/lsp.d.ts +2 -0
  53. package/dist/types/tools/mcp.d.ts +6 -5
  54. package/dist/types/tools/native-view.d.ts +1 -1
  55. package/dist/types/tools/renderer.d.ts +2 -0
  56. package/dist/types/tools/streaming-output.d.ts +11 -0
  57. package/dist/types/tools/task.d.ts +9 -1
  58. package/dist/types/tools/url-scheme-host.d.ts +17 -0
  59. package/dist/types/tools/yield.d.ts +1 -1
  60. package/dist/types/tui.d.ts +7 -2
  61. package/package.json +10 -14
  62. package/src/app-keybindings.d.ts +15 -0
  63. package/src/app-keybindings.ts +15 -0
  64. package/src/apps/session-picker.ts +7 -0
  65. package/src/charts/chart-plan.d.ts +9 -7
  66. package/src/charts/chart-plan.ts +20 -50
  67. package/src/chat/advisor-message.ts +2 -0
  68. package/src/chat/assistant-message.d.ts +15 -3
  69. package/src/chat/assistant-message.ts +137 -19
  70. package/src/chat/background-tan-message.ts +4 -0
  71. package/src/chat/bash-execution.d.ts +2 -0
  72. package/src/chat/bash-execution.ts +6 -0
  73. package/src/chat/chat-transcript-builder.ts +58 -28
  74. package/src/chat/compaction-summary-message.ts +2 -1
  75. package/src/chat/display-preferences.d.ts +2 -0
  76. package/src/chat/display-preferences.ts +3 -0
  77. package/src/chat/extension-types.d.ts +31 -0
  78. package/src/chat/extension-types.ts +34 -0
  79. package/src/chat/reply-write.d.ts +48 -0
  80. package/src/chat/reply-write.ts +127 -0
  81. package/src/chat/table-chart.d.ts +4 -3
  82. package/src/chat/table-chart.ts +10 -4
  83. package/src/chat/tool-execution.d.ts +1 -2
  84. package/src/chat/tool-execution.ts +20 -13
  85. package/src/chat/transcript-outline.d.ts +7 -0
  86. package/src/chat/transcript-outline.ts +27 -0
  87. package/src/chat/transcript-render-helpers.d.ts +2 -0
  88. package/src/chat/transcript-render-helpers.ts +66 -24
  89. package/src/chrome/index.ts +1 -0
  90. package/src/chrome/transcript-notice.d.ts +35 -0
  91. package/src/chrome/transcript-notice.ts +83 -0
  92. package/src/chrome/transcript-status.d.ts +20 -8
  93. package/src/chrome/transcript-status.ts +29 -29
  94. package/src/components/editor.d.ts +8 -0
  95. package/src/components/editor.ts +10 -1
  96. package/src/components/markdown.d.ts +7 -0
  97. package/src/components/markdown.ts +116 -6
  98. package/src/hotkeys-markdown.ts +1 -0
  99. package/src/native/backend.ts +5 -66
  100. package/src/native/blobs.d.ts +2 -1
  101. package/src/native/blobs.ts +3 -2
  102. package/src/native/picker.d.ts +4 -4
  103. package/src/native/picker.ts +4 -4
  104. package/src/overlays/advisor-config.ts +1 -10
  105. package/src/overlays/annotation-overlay.ts +125 -37
  106. package/src/overlays/annotation-types.ts +24 -0
  107. package/src/overlays/hook-selector.ts +2 -2
  108. package/src/overlays/login-dialog.ts +31 -5
  109. package/src/overlays/mcp-add-wizard.ts +1 -1
  110. package/src/overlays/model-browser.ts +37 -0
  111. package/src/overlays/model-hub.ts +1 -7
  112. package/src/overlays/model-picker.ts +1 -10
  113. package/src/overlays/oauth-selector.ts +44 -6
  114. package/src/overlays/plan-review-overlay.ts +13 -2
  115. package/src/overlays/rewind-selector.ts +29 -12
  116. package/src/overlays/session-selector.ts +313 -42
  117. package/src/overlays/usage-dashboard.ts +5 -12
  118. package/src/prompt/composer.ts +216 -1
  119. package/src/prompt/custom-editor.ts +6 -1
  120. package/src/prompt/emoji-autocomplete.ts +0 -2
  121. package/src/prompt/interactive-context-helpers.ts +29 -4
  122. package/src/render/extension-links.d.ts +65 -0
  123. package/src/render/extension-links.ts +214 -0
  124. package/src/render/hyperlink.d.ts +25 -7
  125. package/src/render/hyperlink.ts +65 -9
  126. package/src/render/index.d.ts +1 -0
  127. package/src/render/index.ts +1 -0
  128. package/src/setup/scenes/composer.ts +2 -0
  129. package/src/setup/scenes/glyph.ts +3 -1
  130. package/src/setup/scenes/model.ts +192 -29
  131. package/src/setup/scenes/outro.ts +33 -15
  132. package/src/setup/scenes/sign-in.ts +196 -400
  133. package/src/setup/scenes/theme.ts +2 -0
  134. package/src/setup/scenes/types.ts +18 -1
  135. package/src/setup/startup-splash.ts +8 -7
  136. package/src/setup/wizard-overlay.ts +164 -35
  137. package/src/setup/wizard.ts +11 -2
  138. package/src/status-line/component.ts +4 -10
  139. package/src/status-line/context-usage.ts +72 -21
  140. package/src/status-line/host.ts +6 -2
  141. package/src/terminal.ts +24 -2
  142. package/src/theme/defaults.json +1 -0
  143. package/src/theme/loader.ts +1 -1
  144. package/src/theme/theme.d.ts +0 -23
  145. package/src/theme/theme.ts +2 -75
  146. package/src/tools/bash-interactive.d.ts +49 -0
  147. package/src/tools/bash-interactive.ts +6 -1
  148. package/src/tools/bash.d.ts +2 -0
  149. package/src/tools/bash.ts +2 -0
  150. package/src/tools/default-renderer.d.ts +6 -4
  151. package/src/tools/default-renderer.ts +9 -6
  152. package/src/tools/eval.ts +14 -4
  153. package/src/tools/irc.d.ts +6 -0
  154. package/src/tools/irc.ts +6 -0
  155. package/src/tools/job-widget.ts +13 -1
  156. package/src/tools/json-tree.d.ts +23 -4
  157. package/src/tools/json-tree.ts +132 -42
  158. package/src/tools/lsp.d.ts +2 -0
  159. package/src/tools/lsp.ts +36 -15
  160. package/src/tools/mcp.d.ts +6 -5
  161. package/src/tools/mcp.ts +20 -12
  162. package/src/tools/native-view.d.ts +1 -1
  163. package/src/tools/native-view.ts +1 -1
  164. package/src/tools/renderer.d.ts +2 -0
  165. package/src/tools/renderer.ts +2 -0
  166. package/src/tools/streaming-output.d.ts +11 -0
  167. package/src/tools/streaming-output.ts +41 -0
  168. package/src/tools/task.d.ts +9 -1
  169. package/src/tools/task.ts +59 -16
  170. package/src/tools/url-scheme-host.d.ts +17 -0
  171. package/src/tools/url-scheme-host.ts +21 -0
  172. package/src/tools/yield.d.ts +1 -1
  173. package/src/tools/yield.ts +18 -9
  174. package/src/tui.d.ts +7 -2
  175. package/src/tui.ts +43 -15
  176. package/dist/types/theme/defaults/index.d.ts +0 -10289
  177. package/src/theme/defaults/alabaster.json +0 -103
  178. package/src/theme/defaults/amethyst.json +0 -106
  179. package/src/theme/defaults/anthracite.json +0 -103
  180. package/src/theme/defaults/basalt.json +0 -101
  181. package/src/theme/defaults/birch.json +0 -105
  182. package/src/theme/defaults/dark-abyss.json +0 -101
  183. package/src/theme/defaults/dark-arctic.json +0 -114
  184. package/src/theme/defaults/dark-aurora.json +0 -105
  185. package/src/theme/defaults/dark-catppuccin.json +0 -117
  186. package/src/theme/defaults/dark-cavern.json +0 -101
  187. package/src/theme/defaults/dark-celestial.json +0 -116
  188. package/src/theme/defaults/dark-copper.json +0 -105
  189. package/src/theme/defaults/dark-cosmos.json +0 -100
  190. package/src/theme/defaults/dark-cyberpunk.json +0 -112
  191. package/src/theme/defaults/dark-dracula.json +0 -108
  192. package/src/theme/defaults/dark-eclipse.json +0 -101
  193. package/src/theme/defaults/dark-ember.json +0 -105
  194. package/src/theme/defaults/dark-equinox.json +0 -100
  195. package/src/theme/defaults/dark-forest.json +0 -106
  196. package/src/theme/defaults/dark-github.json +0 -115
  197. package/src/theme/defaults/dark-gruvbox.json +0 -122
  198. package/src/theme/defaults/dark-lavender.json +0 -105
  199. package/src/theme/defaults/dark-lunar.json +0 -99
  200. package/src/theme/defaults/dark-midnight.json +0 -105
  201. package/src/theme/defaults/dark-monochrome.json +0 -104
  202. package/src/theme/defaults/dark-monokai.json +0 -108
  203. package/src/theme/defaults/dark-nebula.json +0 -100
  204. package/src/theme/defaults/dark-neon-noir.json +0 -110
  205. package/src/theme/defaults/dark-nord.json +0 -108
  206. package/src/theme/defaults/dark-ocean.json +0 -111
  207. package/src/theme/defaults/dark-one.json +0 -110
  208. package/src/theme/defaults/dark-poimandres.json +0 -125
  209. package/src/theme/defaults/dark-rainforest.json +0 -101
  210. package/src/theme/defaults/dark-reef.json +0 -101
  211. package/src/theme/defaults/dark-retro.json +0 -102
  212. package/src/theme/defaults/dark-rose-pine.json +0 -106
  213. package/src/theme/defaults/dark-sakura.json +0 -105
  214. package/src/theme/defaults/dark-slate.json +0 -105
  215. package/src/theme/defaults/dark-solarized.json +0 -107
  216. package/src/theme/defaults/dark-solstice.json +0 -100
  217. package/src/theme/defaults/dark-starfall.json +0 -101
  218. package/src/theme/defaults/dark-sunset.json +0 -109
  219. package/src/theme/defaults/dark-swamp.json +0 -100
  220. package/src/theme/defaults/dark-synthwave.json +0 -113
  221. package/src/theme/defaults/dark-taiga.json +0 -101
  222. package/src/theme/defaults/dark-terminal.json +0 -105
  223. package/src/theme/defaults/dark-tokyo-night.json +0 -111
  224. package/src/theme/defaults/dark-tundra.json +0 -101
  225. package/src/theme/defaults/dark-twilight.json +0 -101
  226. package/src/theme/defaults/dark-volcanic.json +0 -101
  227. package/src/theme/defaults/graphite.json +0 -102
  228. package/src/theme/defaults/index.d.ts +0 -10289
  229. package/src/theme/defaults/index.ts +0 -203
  230. package/src/theme/defaults/light-arctic.json +0 -117
  231. package/src/theme/defaults/light-aurora-day.json +0 -101
  232. package/src/theme/defaults/light-canyon.json +0 -101
  233. package/src/theme/defaults/light-catppuccin.json +0 -116
  234. package/src/theme/defaults/light-cirrus.json +0 -100
  235. package/src/theme/defaults/light-coral.json +0 -105
  236. package/src/theme/defaults/light-cyberpunk.json +0 -106
  237. package/src/theme/defaults/light-dawn.json +0 -100
  238. package/src/theme/defaults/light-dunes.json +0 -101
  239. package/src/theme/defaults/light-eucalyptus.json +0 -105
  240. package/src/theme/defaults/light-forest.json +0 -110
  241. package/src/theme/defaults/light-frost.json +0 -105
  242. package/src/theme/defaults/light-github.json +0 -125
  243. package/src/theme/defaults/light-glacier.json +0 -101
  244. package/src/theme/defaults/light-gruvbox.json +0 -118
  245. package/src/theme/defaults/light-haze.json +0 -100
  246. package/src/theme/defaults/light-honeycomb.json +0 -105
  247. package/src/theme/defaults/light-lagoon.json +0 -101
  248. package/src/theme/defaults/light-lavender.json +0 -105
  249. package/src/theme/defaults/light-meadow.json +0 -101
  250. package/src/theme/defaults/light-mint.json +0 -105
  251. package/src/theme/defaults/light-monochrome.json +0 -111
  252. package/src/theme/defaults/light-ocean.json +0 -109
  253. package/src/theme/defaults/light-one.json +0 -109
  254. package/src/theme/defaults/light-opal.json +0 -101
  255. package/src/theme/defaults/light-orchard.json +0 -101
  256. package/src/theme/defaults/light-paper.json +0 -105
  257. package/src/theme/defaults/light-poimandres.json +0 -125
  258. package/src/theme/defaults/light-prism.json +0 -100
  259. package/src/theme/defaults/light-retro.json +0 -108
  260. package/src/theme/defaults/light-sand.json +0 -105
  261. package/src/theme/defaults/light-savanna.json +0 -101
  262. package/src/theme/defaults/light-solarized.json +0 -112
  263. package/src/theme/defaults/light-soleil.json +0 -100
  264. package/src/theme/defaults/light-sunset.json +0 -109
  265. package/src/theme/defaults/light-synthwave.json +0 -108
  266. package/src/theme/defaults/light-tokyo-night.json +0 -121
  267. package/src/theme/defaults/light-wetland.json +0 -101
  268. package/src/theme/defaults/light-zenith.json +0 -99
  269. package/src/theme/defaults/limestone.json +0 -104
  270. package/src/theme/defaults/mahogany.json +0 -107
  271. package/src/theme/defaults/marble.json +0 -103
  272. package/src/theme/defaults/obsidian.json +0 -101
  273. package/src/theme/defaults/onyx.json +0 -101
  274. package/src/theme/defaults/pearl.json +0 -103
  275. package/src/theme/defaults/porcelain.json +0 -101
  276. package/src/theme/defaults/quartz.json +0 -106
  277. package/src/theme/defaults/sandstone.json +0 -105
  278. package/src/theme/defaults/titanium.json +0 -100
@@ -435,22 +435,15 @@ function clockTime(date: Date): string {
435
435
  }
436
436
 
437
437
  /**
438
- * When a window resets, relative to `nowMs`: `resets 18:00` today, `resets
439
- * Tue 18:00` within the week, `resets 3 Oct` beyond; the title carries the
440
- * absolute date and the countdown.
438
+ * When a window resets, `resetMs` from `nowMs`: the countdown (`resets in
439
+ * 2h30m`), which reads the same in every time zone; the title carries the
440
+ * local date and time.
441
441
  */
442
442
  function resetLabel(nowMs: number, resetMs: number): { text: string; title: string } {
443
443
  const at = new Date(nowMs + resetMs);
444
- const now = new Date(nowMs);
445
- const sameDay = at.toDateString() === now.toDateString();
446
- const text = sameDay
447
- ? `resets ${clockTime(at)}`
448
- : resetMs < 6 * 86_400_000
449
- ? `resets ${WEEKDAY_NAMES[at.getDay()]} ${clockTime(at)}`
450
- : `resets ${at.getDate()} ${MONTH_NAMES[at.getMonth()]}`;
451
444
  return {
452
- text,
453
- title: `Resets ${shortDate(at)} ${at.getFullYear()}, ${clockTime(at)} (in ${formatDuration(resetMs)})`,
445
+ text: `resets in ${formatDuration(resetMs)}`,
446
+ title: `Resets ${shortDate(at)} ${at.getFullYear()}, ${clockTime(at)}`,
454
447
  };
455
448
  }
456
449
 
@@ -1,6 +1,8 @@
1
1
  import { getComposerStyle } from "../components/composer/registry";
2
2
  import { Spacer } from "../components/spacer";
3
3
  import type { StatusLineComponent } from "../status-line/component";
4
+ import { compositeLineAt } from "../render/composite";
5
+ import { type ExtensionLinkLabel, extensionLinkLabels, linkHintTags } from "../render/extension-links";
4
6
  import type { StatusLineSession } from "../status-line/host";
5
7
  import { createStartupStatusLine, type StatusLineStartupData } from "../status-line/startup";
6
8
  import { isInsideTerminalMultiplexer } from "../terminal-multiplexer";
@@ -177,6 +179,46 @@ export function routeViewportClick(spans: readonly ViewportClickSpan[], index: n
177
179
  return [];
178
180
  }
179
181
 
182
+ /** An extension link label drawn on a mutable-viewport line: what a click or hint tag lands on. */
183
+ export interface ViewportLink {
184
+ readonly url: string;
185
+ /** Mutable-viewport line the label is drawn on. */
186
+ readonly row: number;
187
+ /** First cell of the label's part on that line. */
188
+ readonly start: number;
189
+ }
190
+
191
+ /** An extension link label tagged for picking by keyboard in link-hint mode. */
192
+ interface ViewportLinkHint {
193
+ readonly tag: string;
194
+ readonly link: ViewportLink;
195
+ }
196
+
197
+ /**
198
+ * Called once when link-hint mode ends; `reason` is `"crowded"` when a row held more links than
199
+ * their tags could fit side by side, so no tags were drawn.
200
+ */
201
+ export type LinkHintsEnd = (reason?: "crowded") => void;
202
+
203
+ /**
204
+ * The extension link labels drawn on `rows`, top to bottom, a wrapped label once at its first row:
205
+ * a row's first label continues the previous row's last label when that has the same marker id
206
+ * and ends its row.
207
+ */
208
+ function viewportLinkTargets(rows: readonly string[]): ViewportLink[] {
209
+ const targets: ViewportLink[] = [];
210
+ let previous: ExtensionLinkLabel | undefined;
211
+ for (let row = 0; row < rows.length; row++) {
212
+ const labels = extensionLinkLabels(rows[row]!);
213
+ for (const [index, label] of labels.entries()) {
214
+ if (index === 0 && previous?.endsRow && previous.id === label.id) continue;
215
+ targets.push({ url: label.url, row, start: label.start });
216
+ }
217
+ previous = labels.at(-1);
218
+ }
219
+ return targets;
220
+ }
221
+
180
222
  /**
181
223
  * Reserved click-candidate id for the pinned HUD expander row. Checked before
182
224
  * any registry lookup: its `@…:…` charset cannot collide with generated agent
@@ -260,8 +302,18 @@ export class Composer implements TerminalFrameProvider, NativeSurfaceProvider {
260
302
  #retiredHeaderRows: readonly string[] | undefined;
261
303
  /** Click spans of the last `renderFrame` viewport, in viewport coordinates. */
262
304
  #lastClickSpans: ViewportClickSpan[] = [];
305
+ /** Rows of the last `renderFrame` viewport, before the hover band; read to hit-test extension links. */
306
+ #lastViewportRows: readonly string[] = [];
263
307
  /** Click-candidate id under the pointer, painted with the hover band. Id-anchored so it follows streaming rows. */
264
308
  #hoveredClickId: string | undefined;
309
+ /**
310
+ * Keyboard link-hint mode: the tags drawn over the extension links on screen (`undefined` until
311
+ * the first frame after `startLinkHints` assigns them), the letters typed so far, and what to run
312
+ * when the mode ends for any reason.
313
+ */
314
+ #linkHints: { hints: ViewportLinkHint[] | undefined; typed: string; onEnd: LinkHintsEnd } | undefined;
315
+ /** Width of the last painted viewport, which `#lastViewportRows` was laid out for. */
316
+ #lastViewportWidth = 0;
265
317
  // Hard-row prefix currently above the native viewport. The first resize
266
318
  // frame may pull part of it down before the normal buffer is borrowed.
267
319
  #retiredHeaderStart = 0;
@@ -403,6 +455,8 @@ export class Composer implements TerminalFrameProvider, NativeSurfaceProvider {
403
455
  const transcriptIndex = roots.findIndex(root => root instanceof TranscriptContainer);
404
456
  if (transcriptIndex < 0) {
405
457
  this.#lastClickSpans = [];
458
+ this.#lastViewportRows = [];
459
+ this.#syncLinkHints([], 0);
406
460
  const viewport: string[] = [];
407
461
  for (const root of roots) {
408
462
  const rendered = root.render(width);
@@ -512,11 +566,95 @@ export class Composer implements TerminalFrameProvider, NativeSurfaceProvider {
512
566
  for (const span of activeSpans) shift(span, before.length - drop);
513
567
  for (const span of afterSpans) shift(span, slack + before.length + active.length - drop);
514
568
  this.#lastClickSpans = spans;
569
+ this.#lastViewportRows = mutable;
570
+ this.#lastViewportWidth = width;
571
+ this.#syncLinkHints(mutable, width);
515
572
  if (history !== undefined && this.#offeredHistory?.source === "header") {
516
573
  const visibleHeaderRows = Math.max(0, rows - (mutable.length + drop));
517
574
  this.#retiredHeaderStart = Math.max(0, history.rows.length - visibleHeaderRows);
518
575
  }
519
- return { history, viewport: this.#paintHoverBand(mutable, spans) };
576
+ return { history, viewport: this.#paintLinkHints(this.#paintHoverBand(mutable, spans), width) };
577
+ }
578
+
579
+ /**
580
+ * Keep link-hint tags on what `rows` show. The first frame after `startLinkHints` tags its
581
+ * labels; later frames keep the tags while the tagged labels are still drawn first, in the same
582
+ * order and columns (rows may scroll, links may be added below), and otherwise end the mode, so a
583
+ * tag never picks a label no longer drawn under it. Every frame ends the mode as `"crowded"` when
584
+ * some row has more tag cells than `width` (a resize can narrow it), since tags drawn side by
585
+ * side could not all be read.
586
+ */
587
+ #syncLinkHints(rows: readonly string[], width: number): void {
588
+ const state = this.#linkHints;
589
+ if (state === undefined) return;
590
+ const targets = viewportLinkTargets(rows);
591
+ const hints = state.hints;
592
+ if (hints === undefined) {
593
+ state.hints = linkHintTags(targets.length).map((tag, index) => ({ tag, link: targets[index]! }));
594
+ if (state.hints.length === 0) {
595
+ this.#endLinkHints();
596
+ return;
597
+ }
598
+ } else {
599
+ const unchanged =
600
+ targets.length >= hints.length &&
601
+ hints.every(({ link }, index) => link.url === targets[index]!.url && link.start === targets[index]!.start);
602
+ if (!unchanged) {
603
+ this.#endLinkHints();
604
+ return;
605
+ }
606
+ state.hints = hints.map(({ tag }, index) => ({ tag, link: targets[index]! }));
607
+ }
608
+ const cells = new Map<number, number>();
609
+ for (const { tag, link } of state.hints) cells.set(link.row, (cells.get(link.row) ?? 0) + tag.length);
610
+ if ([...cells.values()].some(count => count > width)) this.#endLinkHints("crowded");
611
+ }
612
+
613
+ #endLinkHints(reason?: "crowded"): void {
614
+ const state = this.#linkHints;
615
+ if (state === undefined) return;
616
+ this.#linkHints = undefined;
617
+ state.onEnd(reason);
618
+ }
619
+
620
+ /**
621
+ * Draw every tag the typed letters still lead to over the start of its label. Tags on one row
622
+ * never overlap: one that would land on an earlier tag moves right, and tags that would run past
623
+ * the right edge move left, so each stays readable as long as the row has room for them all.
624
+ */
625
+ #paintLinkHints(viewport: string[], width: number): string[] {
626
+ const state = this.#linkHints;
627
+ if (state?.hints === undefined) return viewport;
628
+ const rows = new Map<number, { tag: string; col: number }[]>();
629
+ for (const { tag, link } of state.hints) {
630
+ if (viewport[link.row] === undefined || !tag.startsWith(state.typed)) continue;
631
+ let row = rows.get(link.row);
632
+ if (!row) rows.set(link.row, (row = []));
633
+ row.push({ tag, col: link.start });
634
+ }
635
+ const painted = [...viewport];
636
+ for (const [index, tags] of rows) {
637
+ tags.sort((a, b) => a.col - b.col);
638
+ let free = 0;
639
+ for (const placed of tags) {
640
+ placed.col = Math.max(placed.col, free);
641
+ free = placed.col + placed.tag.length;
642
+ }
643
+ let limit = width;
644
+ for (let i = tags.length - 1; i >= 0; i--) {
645
+ const placed = tags[i]!;
646
+ placed.col = Math.max(0, Math.min(placed.col, limit - placed.tag.length));
647
+ limit = placed.col;
648
+ }
649
+ let line = painted[index]!;
650
+ for (const { tag, col } of tags) {
651
+ // Raw SGR like the hover highlight: chalk's inverse/bold drop out when it detects no color.
652
+ const styled = `\x1b[1;7m${theme.fg("accent", tag)}\x1b[22;27m`;
653
+ line = compositeLineAt(line, styled, col, tag.length, width);
654
+ }
655
+ painted[index] = line;
656
+ }
657
+ return painted;
520
658
  }
521
659
 
522
660
  /**
@@ -635,6 +773,17 @@ export class Composer implements TerminalFrameProvider, NativeSurfaceProvider {
635
773
  return routeViewportClick(this.#lastClickSpans, index);
636
774
  }
637
775
 
776
+ /**
777
+ * The extension-owned link label drawn at cell `col` of a mutable-viewport line, or `undefined`.
778
+ * Only links whose scheme an extension registered match; see `extensionLinkLabels`.
779
+ */
780
+ viewportLinkAt(index: number, col: number): ViewportLink | undefined {
781
+ const line = this.#lastViewportRows[index];
782
+ if (line === undefined || col < 0) return undefined;
783
+ const label = extensionLinkLabels(line).find(label => col >= label.start && col < label.end);
784
+ return label && { url: label.url, row: index, start: label.start };
785
+ }
786
+
638
787
  /**
639
788
  * Point the hover band at a click-candidate id (or clear it). Takes effect
640
789
  * on the next frame; callers repaint only when the target actually changes.
@@ -643,6 +792,55 @@ export class Composer implements TerminalFrameProvider, NativeSurfaceProvider {
643
792
  this.#hoveredClickId = id;
644
793
  }
645
794
 
795
+ /** How many extension link labels the last frame drew; a label wrapped across rows counts once. */
796
+ viewportLinkCount(): number {
797
+ return viewportLinkTargets(this.#lastViewportRows).length;
798
+ }
799
+
800
+ /**
801
+ * Enter keyboard link-hint mode: the next frame draws a tag over each extension link label it
802
+ * shows. `onEnd` runs once when the mode ends: a pick, a cancel, a key no tag starts with, a
803
+ * repaint that no longer draws the tagged labels where they were, or (`"crowded"`) a row with
804
+ * too many links for their tags to fit side by side.
805
+ */
806
+ startLinkHints(onEnd: LinkHintsEnd): void {
807
+ this.#endLinkHints();
808
+ this.#linkHints = { hints: undefined, typed: "", onEnd };
809
+ }
810
+
811
+ /** Whether link-hint mode is on. */
812
+ get linkHintsActive(): boolean {
813
+ return this.#linkHints !== undefined;
814
+ }
815
+
816
+ /**
817
+ * Type one letter of a tag. Returns the link whose whole tag is now typed, `true` while the
818
+ * letters still lead to several tags, and `false` when none starts with them. The mode ends on
819
+ * a pick or a miss.
820
+ */
821
+ typeLinkHint(letter: string): ViewportLink | boolean {
822
+ const state = this.#linkHints;
823
+ if (state === undefined) return false;
824
+ // A key typed before the tags were first painted picks among the labels last drawn.
825
+ if (state.hints === undefined) this.#syncLinkHints(this.#lastViewportRows, this.#lastViewportWidth);
826
+ const hints = this.#linkHints?.hints;
827
+ if (hints === undefined) return false;
828
+ const typed = state.typed + letter.toLowerCase();
829
+ const matching = hints.filter(hint => hint.tag.startsWith(typed));
830
+ const picked = matching.length === 1 && matching[0]!.tag === typed ? matching[0]!.link : undefined;
831
+ if (matching.length === 0 || picked !== undefined) {
832
+ this.#endLinkHints();
833
+ return picked ?? false;
834
+ }
835
+ state.typed = typed;
836
+ return true;
837
+ }
838
+
839
+ /** Leave link-hint mode without picking a link. */
840
+ cancelLinkHints(): void {
841
+ this.#endLinkHints();
842
+ }
843
+
646
844
  /** Acknowledges one accepted header, replay, or transcript batch. */
647
845
  acknowledgeHistory(id: number): void {
648
846
  const offered = this.#offeredHistory;
@@ -940,6 +1138,9 @@ export class Composer implements TerminalFrameProvider, NativeSurfaceProvider {
940
1138
  start(options: ComposerStartOptions = {}): void {
941
1139
  if (this.#started || this.#stopped) return;
942
1140
  this.#started = true;
1141
+ // A TSP terminal keeps (and draws) what is typed until startup releases
1142
+ // the held input, standing in for the kernel echo other terminals give.
1143
+ this.#editor.nativeTypeahead = options.deferInput === true;
943
1144
  this.ui.start({ clearScrollback: options.clearScrollback === true, deferInput: options.deferInput === true });
944
1145
  if (options.playWelcomeIntro !== false) this.playWelcomeIntro();
945
1146
  // Deferred input identifies the CLI prepaint handoff. Flush the queued
@@ -1023,9 +1224,23 @@ export class Composer implements TerminalFrameProvider, NativeSurfaceProvider {
1023
1224
  /** Update the canonical editor reference after InteractiveMode remounts a custom editor. */
1024
1225
  setEditor(editor: CustomEditor): void {
1025
1226
  this.ui.replaceHeldFocus(this.#editor, editor);
1227
+ editor.nativeTypeahead = this.#editor.nativeTypeahead;
1026
1228
  this.#editor = editor;
1027
1229
  }
1028
1230
 
1231
+ /**
1232
+ * End the startup input hold once the app's handlers are wired: the TSP
1233
+ * terminal sends the typing it kept, and the keys the TUI held replay
1234
+ * ({@link TUI.releaseHeldInput}). Idempotent.
1235
+ */
1236
+ releaseHeldInput(): void {
1237
+ if (this.#editor.nativeTypeahead) {
1238
+ this.#editor.nativeTypeahead = false;
1239
+ this.ui.requestRender();
1240
+ }
1241
+ this.ui.releaseHeldInput();
1242
+ }
1243
+
1029
1244
  /**
1030
1245
  * Mount the session-aware status component into the slot below the editor,
1031
1246
  * retiring the startup status line; the caller installs the real top-border
@@ -1063,7 +1063,12 @@ export class CustomEditor extends Editor {
1063
1063
  /** Editing is available during bootstrap; atomic sends wait until submission is wired and enabled
1064
1064
  * and no dictation is still writing into the draft. */
1065
1065
  protected override get nativeSendable(): boolean {
1066
- return this.onSubmit !== undefined && !this.disableSubmit && !dictationHoldsDraft(this.composerState().dictation);
1066
+ return (
1067
+ !this.nativeKeyPassthrough &&
1068
+ this.onSubmit !== undefined &&
1069
+ !this.disableSubmit &&
1070
+ !dictationHoldsDraft(this.composerState().dictation)
1071
+ );
1067
1072
  }
1068
1073
  /** The quoted-title placeholder, kept while the title stands so the editor node stays reused. */
1069
1074
  #titlePlaceholder: { title: string; text: TspText } | undefined;
@@ -52,8 +52,6 @@ const EMOTICONS: ReadonlyArray<readonly [pattern: string, char: string]> = [
52
52
  ["<3", "❤️"],
53
53
  ["xD", "😆"],
54
54
  ["XD", "😆"],
55
- ["B)", "😎"],
56
- ["8)", "😎"],
57
55
  ];
58
56
 
59
57
  const MAX_SUGGESTIONS = 12;
@@ -3,12 +3,17 @@ import type { AssistantMessage, Model, TextContent } from "@linxiraos/pi-ai";
3
3
  import { getMarkdownLinkUrls } from "../index";
4
4
  import { EMPTY_LINK_TARGETS } from "../render/render-utils";
5
5
  import type { ImageBudget } from "../components/image";
6
- import type { AssistantThinkingRenderer } from "../chat/extension-types";
6
+ import type { AssistantTextRenderer, AssistantThinkingRenderer } from "../chat/extension-types";
7
7
  import { AssistantMessageComponent } from "../chat/assistant-message";
8
+ import { ReplyWriteComponent } from "../chat/reply-write";
8
9
  /** Session display capabilities supplied unchanged by the interactive host. */
9
10
  export interface AssistantMessageSession {
10
11
  readonly model?: Model;
11
- readonly extensionRunner?: { getAssistantThinkingRenderers(): readonly AssistantThinkingRenderer[] };
12
+ readonly extensionRunner?: {
13
+ getAssistantThinkingRenderers(): readonly AssistantThinkingRenderer[];
14
+ /** Empty while the setting that enables them is off; hosts predating it may omit it. */
15
+ getAssistantTextRenderers?(): readonly AssistantTextRenderer[];
16
+ };
12
17
  }
13
18
 
14
19
  /** Host state required to construct and refresh assistant transcript segments. */
@@ -109,12 +114,15 @@ export function assistantMessageLinkTargets(
109
114
  /**
110
115
  * Construct an {@link AssistantMessageComponent} wired to the live context's
111
116
  * thinking/image settings. `message` is omitted for the streaming placeholder
112
- * component and supplied when rendering a persisted turn.
117
+ * component and supplied when rendering a persisted turn. `contentOffset` is
118
+ * the index in the full reply of the first block of a segment drawn after a
119
+ * tool call, so extension text renderers see the reply's own block indexes.
113
120
  */
114
121
  export function createAssistantMessageComponent(
115
122
  ctx: AssistantMessageHost,
116
123
  message?: AssistantMessage,
117
124
  linkTargets: ReadonlyMap<string, string> = getAssistantMessageLinkTargets(ctx),
125
+ contentOffset = 0,
118
126
  ): AssistantMessageComponent {
119
127
  const component = new AssistantMessageComponent(
120
128
  message,
@@ -125,7 +133,25 @@ export function createAssistantMessageComponent(
125
133
  ctx.proseOnlyThinking,
126
134
  linkTargets,
127
135
  ctx.expandThinkingBlocks,
136
+ { renderers: ctx.viewSession.extensionRunner?.getAssistantTextRenderers?.() ?? [], contentOffset },
128
137
  );
138
+ applyHostDisplay(ctx, component);
139
+ return component;
140
+ }
141
+
142
+ /** Construct a {@link ReplyWriteComponent} (an `out://` write) drawn like the context's assistant prose. */
143
+ export function createReplyWriteComponent(ctx: AssistantMessageHost): ReplyWriteComponent {
144
+ const component = new ReplyWriteComponent({
145
+ requestRender: () => ctx.ui.requestRender(),
146
+ imageBudget: ctx.ui.imageBudget,
147
+ linkTargets: getAssistantMessageLinkTargets(ctx),
148
+ });
149
+ applyHostDisplay(ctx, component);
150
+ return component;
151
+ }
152
+
153
+ /** Apply the context's image, chart, expansion, and scrollback-publication display state. */
154
+ function applyHostDisplay(ctx: AssistantMessageHost, component: AssistantMessageComponent): void {
129
155
  component.setImagesVisible(ctx.assistantImagesVisible);
130
156
  component.setTableChartsVisible(ctx.tableChartsVisible);
131
157
  component.setToolResultImagesVisible(!ctx.hideToolActivity);
@@ -136,5 +162,4 @@ export function createAssistantMessageComponent(
136
162
  const compat = ctx.viewSession.model?.compat;
137
163
  const wireRevisable = compat !== undefined && "streamRevision" in compat && compat.streamRevision === "possible";
138
164
  component.setMidStreamPublication(!wireRevisable);
139
- return component;
140
165
  }
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Set the registered schemes (lowercase, without `:`). Bumps {@link extensionLinksVersion} on any
3
+ * change so cached markdown renders are redrawn.
4
+ */
5
+ export declare function setExtensionLinks(next: Iterable<string>): void;
6
+ /** Changes whenever the scheme set changes; part of the markdown render cache key. */
7
+ export declare function extensionLinksVersion(): number;
8
+ /**
9
+ * Whether activating a registered-scheme link (a click or a hint tag) reaches its extension: a
10
+ * scheme is registered and the terminal is plain.
11
+ */
12
+ export declare function extensionLinksRouted(): boolean;
13
+ /**
14
+ * Set by the interactive product: whether the user has a way to pick a link drawn now (a bound
15
+ * hint key, mouse clicks). `undefined` when nothing in this process can pick one.
16
+ */
17
+ export declare function setExtensionLinkPicking(provider: (() => boolean) | undefined): void;
18
+ /**
19
+ * Whether a registered-scheme link drawn now can be activated: links are routed and the product
20
+ * offers a way to pick them. Process-wide, so a UI-less extension runner (a subagent's, whose
21
+ * transcript the user may focus) answers like the interactive one.
22
+ */
23
+ export declare function extensionLinkClicksAvailable(): boolean;
24
+ /** The registered scheme `href` uses, or `undefined` for every other link. */
25
+ export declare function extensionLinkScheme(href: string): string | undefined;
26
+ /**
27
+ * Draw an extension link's label: dotted-underlined (plain underline where the terminal has no
28
+ * styled underlines, re-applied after any style reset inside it) and wrapped in the OSC 8 marker
29
+ * {@link extensionLinkLabels} reads back in a plain terminal; as given in Tern's native view. Never
30
+ * followed by a ` (url)` suffix. `key` tells apart links of one URL drawn near each other; it must
31
+ * not change between renders of the same text, or rows rendered twice stop matching.
32
+ */
33
+ export declare function formatExtensionLink(label: string, href: string, key: string): string;
34
+ /**
35
+ * Tags for `count` links in keyboard link-hint mode: single letters while they suffice, otherwise
36
+ * two letters each, so no tag is a prefix of another. At most the alphabet squared (676) are made;
37
+ * links past that stay untagged.
38
+ */
39
+ export declare function linkHintTags(count: number): string[];
40
+ /**
41
+ * `line` without omp's extension-link markers (the OSC 8 open and close around each label), for
42
+ * terminal output. Every other hyperlink is kept as is.
43
+ */
44
+ export declare function stripExtensionLinkMarkers(line: string): string;
45
+ /** One extension link label drawn on a rendered row (before {@link stripExtensionLinkMarkers}). */
46
+ export interface ExtensionLinkLabel {
47
+ readonly url: string;
48
+ /**
49
+ * The marker's params, unique to each drawn link and repeated on every row a wrapped label
50
+ * spans, so a row's parts of one label can be told from an adjacent label of the same URL.
51
+ */
52
+ readonly id: string;
53
+ /** First 0-based cell the label covers. */
54
+ readonly start: number;
55
+ /** Cell just past the label. */
56
+ readonly end: number;
57
+ /** Whether only blank cells follow the label on its row, so a wrapped label may go on below. */
58
+ readonly endsRow: boolean;
59
+ }
60
+ /**
61
+ * The extension link labels drawn on a rendered row, left to right. Only omp's own markers with a
62
+ * registered scheme match, so ordinary hyperlinks (even of a registered scheme) and rows drawn for
63
+ * a scheme that is no longer registered never do.
64
+ */
65
+ export declare function extensionLinkLabels(line: string): ExtensionLinkLabel[];