@linxiraos/pi-tui 1.4.7 → 1.4.10

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 (181) hide show
  1. package/CHANGELOG.md +154 -231
  2. package/README.md +7 -1
  3. package/dist/types/app-keybindings.d.ts +5 -0
  4. package/dist/types/charts/table-data.d.ts +4 -2
  5. package/dist/types/chat/bash-execution.d.ts +4 -1
  6. package/dist/types/chat/eval-execution.d.ts +2 -0
  7. package/dist/types/chat/execution-shared.d.ts +14 -8
  8. package/dist/types/chat/figure-markdown.d.ts +2 -0
  9. package/dist/types/chat/svg-figure.d.ts +5 -0
  10. package/dist/types/chat/table-chart.d.ts +2 -0
  11. package/dist/types/chat/transcript-render-helpers.d.ts +11 -3
  12. package/dist/types/chrome/dynamic-border.d.ts +6 -0
  13. package/dist/types/chrome/transcript-status.d.ts +2 -2
  14. package/dist/types/components/editor.d.ts +15 -6
  15. package/dist/types/components/image.d.ts +6 -0
  16. package/dist/types/components/loader.d.ts +2 -0
  17. package/dist/types/keybinding-matchers.d.ts +7 -0
  18. package/dist/types/native/describe.d.ts +4 -2
  19. package/dist/types/native/node.d.ts +2 -3
  20. package/dist/types/native/overlay.d.ts +42 -2
  21. package/dist/types/native/state.d.ts +4 -0
  22. package/dist/types/overlays/btw-history-panel.d.ts +15 -0
  23. package/dist/types/overlays/btw-history.d.ts +24 -0
  24. package/dist/types/overlays/btw-inject.d.ts +22 -0
  25. package/dist/types/overlays/btw-panel.d.ts +7 -0
  26. package/dist/types/overlays/hook-editor.d.ts +2 -0
  27. package/dist/types/overlays/jobs-panel.d.ts +4 -0
  28. package/dist/types/overlays/model-browser.d.ts +1 -1
  29. package/dist/types/overlays/session-selector.d.ts +11 -2
  30. package/dist/types/prompt/composer.d.ts +13 -5
  31. package/dist/types/render/render-utils.d.ts +23 -1
  32. package/dist/types/setup/scenes/language.d.ts +3 -0
  33. package/dist/types/setup/scenes/types.d.ts +5 -0
  34. package/dist/types/setup/setup-version.d.ts +1 -1
  35. package/dist/types/setup/wizard.d.ts +1 -1
  36. package/dist/types/status-line/startup.d.ts +0 -15
  37. package/dist/types/terminal-capabilities.d.ts +1 -1
  38. package/dist/types/theme/symbols.d.ts +3 -1
  39. package/dist/types/theme/theme-class.d.ts +1 -0
  40. package/dist/types/theme/theme.d.ts +1 -1
  41. package/dist/types/theme/tui-adapters.d.ts +2 -0
  42. package/dist/types/thinking.d.ts +8 -6
  43. package/dist/types/tools/ast-grep.d.ts +2 -0
  44. package/dist/types/tools/eval.d.ts +2 -0
  45. package/dist/types/tools/find.d.ts +1 -1
  46. package/dist/types/tools/grouped-file-output.d.ts +100 -19
  47. package/dist/types/tools/hashline-format.d.ts +5 -0
  48. package/dist/types/tools/native-view.d.ts +2 -0
  49. package/dist/types/tools/output-meta.d.ts +27 -0
  50. package/dist/types/tools/read.d.ts +14 -4
  51. package/dist/types/tools/task.d.ts +4 -3
  52. package/dist/types/tools/wait.d.ts +2 -0
  53. package/dist/types/tui.d.ts +12 -0
  54. package/dist/types/utils.d.ts +4 -0
  55. package/package.json +9 -9
  56. package/src/app-keybindings.d.ts +5 -0
  57. package/src/app-keybindings.ts +5 -0
  58. package/src/apps/git/git-tui.ts +10 -17
  59. package/src/apps/git/sidebar.ts +21 -35
  60. package/src/apps/ps-top.ts +4 -12
  61. package/src/charts/chart-plan.ts +0 -29
  62. package/src/charts/table-data.d.ts +4 -2
  63. package/src/charts/table-data.ts +55 -6
  64. package/src/chat/bash-execution.d.ts +4 -1
  65. package/src/chat/bash-execution.ts +20 -9
  66. package/src/chat/chat-transcript-builder.ts +5 -2
  67. package/src/chat/eval-execution.d.ts +2 -0
  68. package/src/chat/eval-execution.ts +14 -7
  69. package/src/chat/execution-shared.d.ts +14 -8
  70. package/src/chat/execution-shared.ts +39 -18
  71. package/src/chat/figure-markdown.d.ts +2 -0
  72. package/src/chat/figure-markdown.ts +6 -4
  73. package/src/chat/read-tool-group.ts +56 -36
  74. package/src/chat/svg-figure.d.ts +5 -0
  75. package/src/chat/svg-figure.ts +55 -16
  76. package/src/chat/table-chart.d.ts +2 -0
  77. package/src/chat/table-chart.ts +19 -2
  78. package/src/chat/transcript-render-helpers.d.ts +11 -3
  79. package/src/chat/transcript-render-helpers.ts +70 -22
  80. package/src/chrome/dynamic-border.d.ts +6 -0
  81. package/src/chrome/dynamic-border.ts +28 -2
  82. package/src/chrome/transcript-status.d.ts +2 -2
  83. package/src/chrome/transcript-status.ts +5 -3
  84. package/src/components/editor.d.ts +15 -6
  85. package/src/components/editor.ts +123 -24
  86. package/src/components/image.d.ts +6 -0
  87. package/src/components/image.ts +13 -0
  88. package/src/components/key-value-list.ts +9 -9
  89. package/src/components/loader.d.ts +2 -0
  90. package/src/components/loader.ts +7 -0
  91. package/src/components/section.ts +1 -9
  92. package/src/components/table.ts +1 -9
  93. package/src/keybinding-matchers.d.ts +7 -0
  94. package/src/keybinding-matchers.ts +13 -0
  95. package/src/native/backend.ts +7 -3
  96. package/src/native/describe.d.ts +4 -2
  97. package/src/native/describe.ts +9 -4
  98. package/src/native/node.d.ts +2 -3
  99. package/src/native/node.ts +2 -3
  100. package/src/native/overlay.d.ts +42 -2
  101. package/src/native/overlay.ts +124 -16
  102. package/src/native/state.d.ts +4 -0
  103. package/src/native/state.ts +25 -5
  104. package/src/overlays/btw-history-panel.ts +106 -14
  105. package/src/overlays/btw-history.ts +65 -0
  106. package/src/overlays/btw-inject.ts +91 -0
  107. package/src/overlays/btw-panel.ts +53 -12
  108. package/src/overlays/extensions/extension-dashboard.ts +7 -8
  109. package/src/overlays/hook-editor.ts +6 -0
  110. package/src/overlays/jobs-panel.ts +82 -22
  111. package/src/overlays/login-dialog.ts +8 -26
  112. package/src/overlays/model-browser.ts +69 -10
  113. package/src/overlays/session-selector.ts +25 -5
  114. package/src/overlays/settings-defs.ts +2 -2
  115. package/src/overlays/settings-selector.ts +113 -11
  116. package/src/overlays/tree-selector.ts +83 -27
  117. package/src/overlays/usage-dashboard.ts +4 -6
  118. package/src/prompt/composer.ts +17 -5
  119. package/src/render/code-cell.ts +1 -1
  120. package/src/render/file-list.ts +4 -7
  121. package/src/render/render-utils.d.ts +23 -1
  122. package/src/render/render-utils.ts +38 -6
  123. package/src/setup/scenes/glyph.ts +1 -1
  124. package/src/setup/scenes/language.ts +122 -0
  125. package/src/setup/scenes/types.ts +6 -0
  126. package/src/setup/setup-version.ts +1 -1
  127. package/src/setup/wizard.ts +2 -0
  128. package/src/status-line/startup.ts +36 -70
  129. package/src/terminal-capabilities.d.ts +1 -1
  130. package/src/terminal-capabilities.ts +5 -0
  131. package/src/theme/symbols.d.ts +3 -1
  132. package/src/theme/symbols.ts +16 -9
  133. package/src/theme/theme-class.d.ts +1 -0
  134. package/src/theme/theme-class.ts +15 -3
  135. package/src/theme/theme.d.ts +1 -1
  136. package/src/theme/theme.ts +1 -0
  137. package/src/theme/tui-adapters.d.ts +2 -0
  138. package/src/theme/tui-adapters.ts +8 -3
  139. package/src/thinking.d.ts +8 -6
  140. package/src/thinking.ts +17 -11
  141. package/src/tmux.ts +1 -0
  142. package/src/tools/agent-tree.ts +13 -11
  143. package/src/tools/ask.ts +24 -37
  144. package/src/tools/ast-edit.ts +48 -93
  145. package/src/tools/ast-grep.d.ts +2 -0
  146. package/src/tools/ast-grep.ts +31 -67
  147. package/src/tools/bash.ts +7 -0
  148. package/src/tools/default-renderer.ts +1 -1
  149. package/src/tools/edit.ts +50 -43
  150. package/src/tools/eval.d.ts +2 -0
  151. package/src/tools/eval.ts +2 -0
  152. package/src/tools/fetch.ts +2 -1
  153. package/src/tools/find.d.ts +1 -1
  154. package/src/tools/find.ts +13 -5
  155. package/src/tools/github.ts +14 -46
  156. package/src/tools/glob.ts +2 -1
  157. package/src/tools/grep.ts +47 -277
  158. package/src/tools/grouped-file-output.d.ts +100 -19
  159. package/src/tools/grouped-file-output.ts +414 -103
  160. package/src/tools/hashline-format.d.ts +5 -0
  161. package/src/tools/hashline-format.ts +5 -0
  162. package/src/tools/json-tree.ts +1 -5
  163. package/src/tools/lsp.ts +210 -32
  164. package/src/tools/native-view.d.ts +2 -0
  165. package/src/tools/native-view.ts +11 -5
  166. package/src/tools/output-meta.d.ts +27 -0
  167. package/src/tools/output-meta.ts +68 -4
  168. package/src/tools/proc-render.ts +3 -3
  169. package/src/tools/read.d.ts +14 -4
  170. package/src/tools/read.ts +20 -5
  171. package/src/tools/task.d.ts +4 -3
  172. package/src/tools/task.ts +41 -81
  173. package/src/tools/vibe.ts +4 -4
  174. package/src/tools/wait.d.ts +2 -0
  175. package/src/tools/wait.ts +8 -5
  176. package/src/tools/write.ts +17 -27
  177. package/src/tools/yield.ts +1 -1
  178. package/src/tui.d.ts +12 -0
  179. package/src/tui.ts +91 -9
  180. package/src/utils.d.ts +4 -0
  181. package/src/utils.ts +10 -0
@@ -13,11 +13,18 @@ import type { JobSnapshot } from "../tools/wait";
13
13
  import type { DaemonSnapshot } from "../tools/daemon";
14
14
  import { type CustomMessage, type FileMentionMessage, resolveAbortLabel, shouldRenderAbortReason } from "./messages";
15
15
  import { createIrcMessageCard } from "../tools/wait";
16
- import { formatArtifactErrorNotice, type OutputMeta } from "../tools/output-meta";
16
+ import {
17
+ formatArtifactErrorNotice,
18
+ formatMinimizedMeta,
19
+ type MinimizedMeta,
20
+ type OutputMeta,
21
+ } from "../tools/output-meta";
17
22
  import type { OutputArtifactError } from "../tools/streaming-output";
18
- import { replaceTabs, TRUNCATE_LENGTHS, truncateToWidth } from "../render/render-utils";
23
+ import { formatStyledPath, replaceTabs, TRUNCATE_LENGTHS, truncateToWidth } from "../render/render-utils";
19
24
  import { canonicalizeMessage } from "./thinking-display";
20
25
  import { ToolActivityContainer } from "../chrome/tool-activity";
26
+ import { CustomMessageComponent } from "./custom-message";
27
+ import type { MessageRenderer } from "./extension-types";
21
28
  import { type TranscriptBlock } from "../chrome/transcript-container";
22
29
  import { TranscriptStatusBlock, type TranscriptStatusRow } from "../chrome/transcript-status";
23
30
  import { theme } from "../theme";
@@ -65,7 +72,7 @@ export function buildAsyncResultBlock(message: CustomOrHookMessage): ToolActivit
65
72
  const duration = typeof job.durationMs === "number" ? formatDuration(job.durationMs) : undefined;
66
73
  rows.push({
67
74
  parts: [
68
- { text: `${theme.status.done} Background job completed`, color: "success" },
75
+ { text: `${theme.status.success} Background job completed`, color: "success" },
69
76
  { text: `[${type}]`, color: "dim" },
70
77
  { text: jobId, color: "accent" },
71
78
  duration ? { text: `(${duration})`, color: "dim" } : undefined,
@@ -76,17 +83,56 @@ export function buildAsyncResultBlock(message: CustomOrHookMessage): ToolActivit
76
83
  },
77
84
  });
78
85
  if (job.meta?.artifactError) rows.push(artifactErrorRow(job.meta.artifactError));
86
+ if (job.meta?.minimized) rows.push(minimizedRow(job.meta.minimized));
79
87
  }
80
88
  if (details?.meta?.artifactError) rows.push(artifactErrorRow(details.meta.artifactError));
81
89
  return new ToolActivityContainer(new TranscriptStatusBlock(rows));
82
90
  }
83
91
 
92
+ /** Hosts an extension renderer; relays `display.hideToolActivity` to the nested built-in fallback block. */
93
+ class AsyncResultCard extends CustomMessageComponent {
94
+ readonly #block: ToolActivityContainer;
95
+
96
+ constructor(message: CustomOrHookMessage, renderer: MessageRenderer, block: ToolActivityContainer) {
97
+ super(message as CustomMessage<unknown>, (delegate, options, rendererTheme) => {
98
+ try {
99
+ return renderer(delegate, options, rendererTheme) ?? block;
100
+ } catch {
101
+ return block;
102
+ }
103
+ });
104
+ this.#block = block;
105
+ }
106
+
107
+ setToolActivityVisible(visible: boolean): void {
108
+ this.#block.setToolActivityVisible(visible);
109
+ }
110
+ }
111
+
112
+ /**
113
+ * The `async-result` card for both transcript surfaces: a registered renderer owns it (#14131);
114
+ * the built-in block covers no renderer, a declining renderer, and a throwing one.
115
+ */
116
+ export function buildAsyncResultComponent(
117
+ message: CustomOrHookMessage,
118
+ renderer: MessageRenderer | undefined,
119
+ ): Component & { setExpanded(expanded: boolean): void } {
120
+ const block = buildAsyncResultBlock(message);
121
+ return renderer ? new AsyncResultCard(message, renderer, block) : block;
122
+ }
123
+
84
124
  /** The warning row under a background job whose output artifact could not be saved. */
85
125
  function artifactErrorRow(error: OutputArtifactError): TranscriptStatusRow {
86
126
  const notice = formatArtifactErrorNotice(error);
87
127
  return { parts: [{ text: notice, color: "warning" }], native: { tone: "warning", message: [span(notice)] } };
88
128
  }
89
129
 
130
+ /** The dim row under a background job whose output the minimizer shortened. */
131
+ function minimizedRow(minimized: MinimizedMeta): TranscriptStatusRow {
132
+ const fact = `Minimized: ${formatMinimizedMeta(minimized)}`;
133
+ return { parts: [{ text: fact, color: "dim" }], native: { tone: "info", message: [span(fact, "dim")] } };
134
+ }
135
+
90
136
  /**
91
137
  * Native notice spans for a row's trailing facts (kind, id, duration): each
92
138
  * after a dim ` · `, absent ones skipped.
@@ -106,7 +152,7 @@ export function buildLaunchCompletionBlock(message: CustomOrHookMessage): ToolAc
106
152
  const daemons = details?.daemons ?? [];
107
153
  if (daemons.length === 0 && typeof message.content === "string") {
108
154
  rows.push({
109
- parts: [{ text: `${theme.status.done} ${message.content}`, color: "dim" }],
155
+ parts: [{ text: `${theme.status.success} ${message.content}`, color: "dim" }],
110
156
  native: { tone: "success", message: [span(message.content)] },
111
157
  });
112
158
  }
@@ -122,7 +168,7 @@ export function buildLaunchCompletionBlock(message: CustomOrHookMessage): ToolAc
122
168
  parts: [
123
169
  failed
124
170
  ? { text: `${theme.status.error} ${label}`, color: "error" }
125
- : { text: `${theme.status.done} ${label}`, color: "success" },
171
+ : { text: `${theme.status.success} ${label}`, color: "success" },
126
172
  { text: daemon.name, color: "accent" },
127
173
  exit ? { text: `(${exit})`, color: "dim" } : undefined,
128
174
  duration ? { text: `(${duration})`, color: "dim" } : undefined,
@@ -137,9 +183,9 @@ export function buildLaunchCompletionBlock(message: CustomOrHookMessage): ToolAc
137
183
  }
138
184
 
139
185
  /**
140
- * Render a live IRC traffic custom message (`irc:incoming` / `irc:autoreply` /
141
- * `irc:relay`) as a transcript card. `getExpanded` supplies the live
142
- * expanded-state getter for the cached card.
186
+ * Render an IRC coordination custom message (`irc:incoming` / `irc:autoreply` /
187
+ * `irc:relay` / `irc:workpool`) as a tool-activity card. `getExpanded` supplies
188
+ * the live expanded-state getter for the cached card.
143
189
  */
144
190
  export function buildIrcMessageCard(message: CustomOrHookMessage, getExpanded: () => boolean): Component {
145
191
  const details = (
@@ -161,19 +207,21 @@ export function buildIrcMessageCard(message: CustomOrHookMessage, getExpanded: (
161
207
  : message.customType === "irc:workpool"
162
208
  ? ("workpool" as const)
163
209
  : ("relay" as const);
164
- return createIrcMessageCard(
165
- {
166
- kind,
167
- from: details?.from,
168
- to: details?.to,
169
- body: kind === "incoming" ? details?.message : details?.body,
170
- replyTo: details?.replyTo,
171
- timestamp: message.timestamp,
172
- pool: details?.pool,
173
- mode: details?.mode,
174
- },
175
- getExpanded,
176
- theme,
210
+ return new ToolActivityContainer(
211
+ createIrcMessageCard(
212
+ {
213
+ kind,
214
+ from: details?.from,
215
+ to: details?.to,
216
+ body: kind === "incoming" ? details?.message : details?.body,
217
+ replyTo: details?.replyTo,
218
+ timestamp: message.timestamp,
219
+ pool: details?.pool,
220
+ mode: details?.mode,
221
+ },
222
+ getExpanded,
223
+ theme,
224
+ ),
177
225
  );
178
226
  }
179
227
 
@@ -201,7 +249,7 @@ export function buildFileMentionBlock(files: FileMentionMessage["files"], indent
201
249
  parts: [
202
250
  { text: theme.tree.last, color: "dim" },
203
251
  { text: "Read", color: "muted" },
204
- { text: file.path, color: "accent" },
252
+ { text: formatStyledPath(file.path, theme) },
205
253
  { text: `(${detail})`, color: "dim" },
206
254
  ],
207
255
  indent,
@@ -13,6 +13,12 @@ export declare class DynamicBorder implements Component {
13
13
  #private;
14
14
  constructor(color?: (str: string) => string);
15
15
  invalidate(): void;
16
+ /**
17
+ * Pre-styled text set into the rule after a short lead (`─── label ────`);
18
+ * undefined draws a plain rule. A function label is re-read every render,
19
+ * for live text such as a spinner.
20
+ */
21
+ setLabel(label: string | (() => string) | undefined): void;
16
22
  /** Native terminals draw their own chrome; a border rule describes nothing. */
17
23
  describe(): NativeNode;
18
24
  render(width: number): readonly string[];
@@ -1,4 +1,5 @@
1
1
  import type { Component } from "../tui";
2
+ import { truncateToWidth, visibleWidth } from "../utils";
2
3
  import { fgOrPlain, theme } from "../theme/index";
3
4
  import type { NativeNode } from "../native/node";
4
5
  import { EMPTY_NODE } from "../native/describe";
@@ -13,7 +14,9 @@ import { EMPTY_NODE } from "../native/describe";
13
14
  */
14
15
  export class DynamicBorder implements Component {
15
16
  #color: (str: string) => string;
17
+ #label: string | (() => string) | undefined;
16
18
  #cachedWidth = -1;
19
+ #cachedLabel: string | undefined;
17
20
  #cachedLines: string[] | undefined;
18
21
 
19
22
  constructor(color: (str: string) => string = str => fgOrPlain("border", str)) {
@@ -25,19 +28,42 @@ export class DynamicBorder implements Component {
25
28
  this.#cachedLines = undefined;
26
29
  }
27
30
 
31
+ /**
32
+ * Pre-styled text set into the rule after a short lead (`─── label ────`);
33
+ * undefined draws a plain rule. A function label is re-read every render,
34
+ * for live text such as a spinner.
35
+ */
36
+ setLabel(label: string | (() => string) | undefined): void {
37
+ if (label === this.#label) return;
38
+ this.#label = label;
39
+ this.invalidate();
40
+ }
41
+
28
42
  /** Native terminals draw their own chrome; a border rule describes nothing. */
29
43
  describe(): NativeNode {
30
44
  return EMPTY_NODE;
31
45
  }
32
46
 
33
47
  render(width: number): readonly string[] {
34
- if (this.#cachedLines && this.#cachedWidth === width) {
48
+ const label = typeof this.#label === "function" ? this.#label() : this.#label;
49
+ if (this.#cachedLines && this.#cachedWidth === width && this.#cachedLabel === label) {
35
50
  return this.#cachedLines;
36
51
  }
37
52
  const horizontal = typeof theme === "undefined" ? "─" : theme.boxRound.horizontal;
38
- const lines = [this.#color(horizontal.repeat(Math.max(1, width)))];
53
+ const lines = [this.#rule(horizontal, Math.max(1, width), label)];
39
54
  this.#cachedWidth = width;
55
+ this.#cachedLabel = label;
40
56
  this.#cachedLines = lines;
41
57
  return lines;
42
58
  }
59
+
60
+ #rule(horizontal: string, width: number, label: string | undefined): string {
61
+ const lead = horizontal.repeat(3);
62
+ // The label sits between single spaces and leaves at least one rule cell after it.
63
+ const labelRoom = width - visibleWidth(lead) - 3;
64
+ if (!label || labelRoom < 1) return this.#color(horizontal.repeat(width));
65
+ const fitted = ` ${truncateToWidth(label, labelRoom)} `;
66
+ const rest = width - visibleWidth(lead) - visibleWidth(fitted);
67
+ return `${this.#color(lead)}${fitted}${this.#color(horizontal.repeat(rest))}`;
68
+ }
43
69
  }
@@ -3,10 +3,10 @@ import type { NativeNode } from "../native/node";
3
3
  import { type ThemeColor } from "../theme";
4
4
  import { TranscriptBlock } from "./transcript-container";
5
5
  import { type NoticeTone } from "./transcript-notice";
6
- /** One themed run of a status row's terminal line. */
6
+ /** One run of a status row's terminal line, in `color` unless the text is already styled. */
7
7
  export interface TranscriptStatusPart {
8
8
  readonly text: string;
9
- readonly color: ThemeColor;
9
+ readonly color?: ThemeColor;
10
10
  }
11
11
  /** A status row in a native terminal: its {@link noticeRow}'s tone, icon and message. */
12
12
  export interface TranscriptStatusNative {
@@ -6,10 +6,10 @@ import { type ThemeColor, theme } from "../theme";
6
6
  import { TranscriptBlock } from "./transcript-container";
7
7
  import { type NoticeTone, noticeRow } from "./transcript-notice";
8
8
 
9
- /** One themed run of a status row's terminal line. */
9
+ /** One run of a status row's terminal line, in `color` unless the text is already styled. */
10
10
  export interface TranscriptStatusPart {
11
11
  readonly text: string;
12
- readonly color: ThemeColor;
12
+ readonly color?: ThemeColor;
13
13
  }
14
14
 
15
15
  /** A status row in a native terminal: its {@link noticeRow}'s tone, icon and message. */
@@ -41,7 +41,9 @@ export class TranscriptStatusBlock extends TranscriptBlock {
41
41
  constructor(rows: readonly TranscriptStatusRow[]) {
42
42
  super();
43
43
  for (const row of rows) {
44
- const styled = row.parts.flatMap(part => (part ? [theme.fg(part.color, part.text)] : []));
44
+ const styled = row.parts.flatMap(part =>
45
+ part ? [part.color ? theme.fg(part.color, part.text) : part.text] : [],
46
+ );
45
47
  this.addChild(new Text(styled.join(" "), row.indent ?? 1, 0));
46
48
  }
47
49
  this.#native = col(
@@ -157,12 +157,21 @@ export declare class Editor implements Component, Focusable {
157
157
  * cursor. The host styles it (ANSI allowed). Re-evaluated on every render, so hosts can derive
158
158
  * it from live state. */
159
159
  placeholder?: () => string | undefined;
160
- /** Whole-message prediction for the next prompt, painted as ghost text after the cursor while
161
- * the single-line buffer is a strict prefix of it, the cursor sits at its end, and no
162
- * autocomplete is open. A shown prediction replaces the {@link placeholder}; Tab or Right inserts
163
- * the rest without submitting. Must be a single line. Re-evaluated on every render, so hosts can
164
- * derive it from live state. */
165
- prediction?: () => string | undefined;
160
+ /** Whole-message predictions for the next prompt, most likely first. The first one the single-line
161
+ * buffer is a strict prefix of is painted as ghost text after the cursor while the cursor sits at
162
+ * its end and no autocomplete is open. A shown prediction replaces the {@link placeholder}; Tab or
163
+ * Right inserts the rest without submitting. A buffer the user typed keeps the ghost even when it
164
+ * equals a shorter prediction; once Tab, Right, or the list has inserted one of two or more
165
+ * predictions, no ghost extends it to a longer one, and Tab instead opens a list of all of them
166
+ * that swaps the whole line, also without submitting. Each must be a single line. Re-evaluated on
167
+ * every render, so hosts can derive them from live state. */
168
+ predictions?: () => readonly string[] | undefined;
169
+ /** Called with the prediction's index in {@link predictions} after Tab or Right inserts the rest of
170
+ * a shown prediction, or the alternatives list swaps a different one into the buffer. */
171
+ onPredictionAccepted?: (index: number) => void;
172
+ /** Called for each frame that paints a prediction as ghost text: a terminal frame that draws at
173
+ * least one cell of it, or a native frame that carries it as the editor's ghost. */
174
+ onPredictionShown?: () => void;
166
175
  constructor(theme: EditorTheme);
167
176
  /** Return bounded editor content, cursor, and transient child state for debug inspection. */
168
177
  debugState(): Record<string, unknown>;
@@ -71,6 +71,7 @@ import {
71
71
  export type { EditorBorderStyle, EditorTopBorder };
72
72
 
73
73
  import { type SelectItem, SelectList, type SelectListLayoutOptions, type SelectListTheme } from "./select-list";
74
+ import { editorKey } from "../chrome/keybinding-hints";
74
75
 
75
76
  /** The TSP root an {@link Editor.describeLayout} hook builds around the `editor` node. */
76
77
  export interface NativeEditorLayout {
@@ -866,9 +867,19 @@ export class Editor implements Component, Focusable {
866
867
  #autocompleteList?: SelectList;
867
868
  #autocompleteState: "regular" | "force" | "assist" | null = null;
868
869
  #textAssistReplacement:
869
- | { line: number; startCol: number; endCol: number; original: string; cursorOffset: number }
870
+ | {
871
+ line: number;
872
+ startCol: number;
873
+ endCol: number;
874
+ original: string;
875
+ cursorOffset: number;
876
+ /** The list offers {@link predictions} for the whole line rather than spelling replacements. */
877
+ prediction?: boolean;
878
+ }
870
879
  | undefined;
871
880
  #autocompletePrefix: string = "";
881
+ /** The line a prediction insert (Tab, Right, or the alternatives list) left in the buffer; any later edit clears it. */
882
+ #insertedPrediction: string | undefined;
872
883
  /** False while the popup's untouched top row is a description-only slash hit ({@link AutocompleteItem.descriptionMatch}): Enter then submits the typed text. */
873
884
  #enterAcceptsSelection = true;
874
885
  #autocompleteRequestId: number = 0;
@@ -945,12 +956,21 @@ export class Editor implements Component, Focusable {
945
956
  * cursor. The host styles it (ANSI allowed). Re-evaluated on every render, so hosts can derive
946
957
  * it from live state. */
947
958
  placeholder?: () => string | undefined;
948
- /** Whole-message prediction for the next prompt, painted as ghost text after the cursor while
949
- * the single-line buffer is a strict prefix of it, the cursor sits at its end, and no
950
- * autocomplete is open. A shown prediction replaces the {@link placeholder}; Tab or Right inserts
951
- * the rest without submitting. Must be a single line. Re-evaluated on every render, so hosts can
952
- * derive it from live state. */
953
- prediction?: () => string | undefined;
959
+ /** Whole-message predictions for the next prompt, most likely first. The first one the single-line
960
+ * buffer is a strict prefix of is painted as ghost text after the cursor while the cursor sits at
961
+ * its end and no autocomplete is open. A shown prediction replaces the {@link placeholder}; Tab or
962
+ * Right inserts the rest without submitting. A buffer the user typed keeps the ghost even when it
963
+ * equals a shorter prediction; once Tab, Right, or the list has inserted one of two or more
964
+ * predictions, no ghost extends it to a longer one, and Tab instead opens a list of all of them
965
+ * that swaps the whole line, also without submitting. Each must be a single line. Re-evaluated on
966
+ * every render, so hosts can derive them from live state. */
967
+ predictions?: () => readonly string[] | undefined;
968
+ /** Called with the prediction's index in {@link predictions} after Tab or Right inserts the rest of
969
+ * a shown prediction, or the alternatives list swaps a different one into the buffer. */
970
+ onPredictionAccepted?: (index: number) => void;
971
+ /** Called for each frame that paints a prediction as ghost text: a terminal frame that draws at
972
+ * least one cell of it, or a native frame that carries it as the editor's ghost. */
973
+ onPredictionShown?: () => void;
954
974
 
955
975
  // Custom top border (for status line integration). Either an eager `content`
956
976
  // (set once, reused every frame) or a `provider` that recomputes lazily just
@@ -1599,6 +1619,10 @@ export class Editor implements Component, Focusable {
1599
1619
  // against the cursor, or the placeholder flush right.
1600
1620
  const placeholder = this.#getPlaceholder();
1601
1621
  const inlineHint = placeholder ? null : this.#getInlineHint();
1622
+ // Whether the hint is the prediction, and how many of its cells this frame draws: a full row,
1623
+ // an unfocused hardware-cursor row, or the IME-safe layout can leave it unpainted.
1624
+ const hintIsPrediction = inlineHint !== null && inlineHint === this.#getPredictionSuffix();
1625
+ let hintCellsPainted = 0;
1602
1626
  const hintStyle = this.#theme.hintStyle ?? ((t: string) => `\x1b[2m${t}\x1b[0m`);
1603
1627
  const hintTail = (avail: number): { text: string; width: number } | undefined => {
1604
1628
  if (placeholder) {
@@ -1713,6 +1737,7 @@ export class Editor implements Component, Focusable {
1713
1737
  } else if (tail) {
1714
1738
  displayText = before + marker + tail.text;
1715
1739
  displayWidth += tail.width;
1740
+ hintCellsPainted += tail.width;
1716
1741
  } else if (after.length === 0 && !isSideBordered && displayWidth >= lineContentWidth) {
1717
1742
  displayText = this.#renderTerminalCursorMarker(before, marker, lineContentWidth);
1718
1743
  } else {
@@ -1759,6 +1784,7 @@ export class Editor implements Component, Focusable {
1759
1784
  const tail = hintTail(Math.max(0, lineContentWidth - displayWidth - overrideWidth));
1760
1785
  displayText = before + marker + this.cursorOverride + (tail?.text ?? "");
1761
1786
  displayWidth += overrideWidth + (tail?.width ?? 0);
1787
+ hintCellsPainted += tail?.width ?? 0;
1762
1788
  }
1763
1789
  } else {
1764
1790
  // Cursor is at the end - add thin cursor glyph
@@ -1773,6 +1799,7 @@ export class Editor implements Component, Focusable {
1773
1799
  const tail = hintTail(Math.max(0, lineContentWidth - displayWidth - cursorWidth));
1774
1800
  displayText = before + marker + cursor + (tail?.text ?? "");
1775
1801
  displayWidth += cursorWidth + (tail?.width ?? 0);
1802
+ hintCellsPainted += tail?.width ?? 0;
1776
1803
  }
1777
1804
  if (displayWidth > lineContentWidth && paddingX > 0) {
1778
1805
  cursorPaddingOverflow = displayWidth - lineContentWidth;
@@ -1815,6 +1842,7 @@ export class Editor implements Component, Focusable {
1815
1842
  }),
1816
1843
  );
1817
1844
  }
1845
+ if (hintIsPrediction && hintCellsPainted > 0) this.onPredictionShown?.();
1818
1846
 
1819
1847
  const bottomRow = style.renderBottom(chromeCtx);
1820
1848
  if (bottomRow !== undefined) result.push(bottomRow);
@@ -1879,6 +1907,7 @@ export class Editor implements Component, Focusable {
1879
1907
  : placeholder && plainText(placeholder).trim();
1880
1908
  const atLineEnd = cursorCol >= (lines[cursorLine]?.length ?? 0);
1881
1909
  const ghost = nativePlaceholder || !atLineEnd ? null : this.#getInlineHint();
1910
+ if (ghost && ghost === this.#getPredictionSuffix()) this.onPredictionShown?.();
1882
1911
  const vim = this.#vim;
1883
1912
  let anchor: number | null = null;
1884
1913
  if (vim?.visual && vim.anchor !== null) {
@@ -2135,7 +2164,7 @@ export class Editor implements Component, Focusable {
2135
2164
  kb.matchesCanonical(canonical, "tui.input.tab") ||
2136
2165
  rightArrowAccepts)
2137
2166
  ) {
2138
- this.#applySpellingSuggestion();
2167
+ this.#applyAssistReplacement();
2139
2168
  return;
2140
2169
  }
2141
2170
  // Let the autocomplete list handle navigation and selection
@@ -3265,6 +3294,7 @@ export class Editor implements Component, Focusable {
3265
3294
 
3266
3295
  #notifyChange(text?: string): void {
3267
3296
  this.#textRevision++;
3297
+ this.#insertedPrediction = undefined;
3268
3298
  this.onChange?.(text ?? this.getText());
3269
3299
  }
3270
3300
 
@@ -5082,7 +5112,7 @@ export class Editor implements Component, Focusable {
5082
5112
  // A pointer pick on the popup (TSP `select`/`activate`) accepts it like Tab.
5083
5113
  list.onSelect = item => {
5084
5114
  if (this.#autocompleteList !== list) return;
5085
- if (this.#autocompleteState === "assist") this.#applySpellingSuggestion();
5115
+ if (this.#autocompleteState === "assist") this.#applyAssistReplacement();
5086
5116
  else this.#acceptAutocompleteSelection(item);
5087
5117
  };
5088
5118
  return list;
@@ -5090,6 +5120,7 @@ export class Editor implements Component, Focusable {
5090
5120
 
5091
5121
  async #handleTabCompletion(): Promise<void> {
5092
5122
  if (this.#acceptPrediction()) return;
5123
+ if (this.#showPredictionAlternatives()) return;
5093
5124
  if (this.#acceptWordCompletion({ space: true })) return;
5094
5125
  if (!this.#autocompleteProvider) return;
5095
5126
 
@@ -5127,11 +5158,37 @@ export class Editor implements Component, Focusable {
5127
5158
  if (space) this.#lastAction = "accept-word";
5128
5159
  return true;
5129
5160
  }
5130
- /** Insert the rest of the shown {@link prediction}, if any. Never submits. */
5161
+ /** Insert the rest of the shown prediction, if any. Never submits. */
5131
5162
  #acceptPrediction(): boolean {
5132
- const suffix = this.#getPredictionSuffix();
5133
- if (!suffix) return false;
5134
- this.#insertTextAtCursor(suffix);
5163
+ const shown = this.#getShownPrediction();
5164
+ if (!shown) return false;
5165
+ this.#insertTextAtCursor(shown.suffix);
5166
+ this.#insertedPrediction = this.#state.lines[0];
5167
+ this.onPredictionAccepted?.(shown.index);
5168
+ return true;
5169
+ }
5170
+
5171
+ /** Open the list of every prediction over a buffer that equals one of them, that one selected. */
5172
+ #showPredictionAlternatives(): boolean {
5173
+ const alternatives = this.#getPredictionAlternatives();
5174
+ if (!alternatives) return false;
5175
+ const original = this.#state.lines[0] ?? "";
5176
+ this.#autocompletePrefix = original;
5177
+ this.#autocompleteList = this.#createAutocompleteList(
5178
+ "",
5179
+ alternatives.choices.map(value => ({ value, label: value })),
5180
+ );
5181
+ this.#autocompleteList.setSelectedIndex(alternatives.index);
5182
+ this.#autocompleteState = "assist";
5183
+ this.#textAssistReplacement = {
5184
+ line: 0,
5185
+ startCol: 0,
5186
+ endCol: original.length,
5187
+ original,
5188
+ cursorOffset: 0,
5189
+ prediction: true,
5190
+ };
5191
+ this.onAutocompleteUpdate?.();
5135
5192
  return true;
5136
5193
  }
5137
5194
 
@@ -5174,7 +5231,7 @@ export class Editor implements Component, Focusable {
5174
5231
  this.onAutocompleteUpdate?.();
5175
5232
  }
5176
5233
 
5177
- #applySpellingSuggestion(): void {
5234
+ #applyAssistReplacement(): void {
5178
5235
  const replacement = this.#textAssistReplacement;
5179
5236
  const selected = this.#autocompleteList?.getSelectedItem();
5180
5237
  if (!replacement || !selected) {
@@ -5182,8 +5239,13 @@ export class Editor implements Component, Focusable {
5182
5239
  return;
5183
5240
  }
5184
5241
  const line = this.#state.lines[replacement.line] ?? "";
5185
- if (line.slice(replacement.startCol, replacement.endCol) !== replacement.original) {
5242
+ // A mismatch means the list went stale; picking the prediction already in the buffer changes nothing.
5243
+ if (
5244
+ line.slice(replacement.startCol, replacement.endCol) !== replacement.original ||
5245
+ (replacement.prediction && selected.value === replacement.original)
5246
+ ) {
5186
5247
  this.#cancelAutocomplete();
5248
+ this.onAutocompleteUpdate?.();
5187
5249
  return;
5188
5250
  }
5189
5251
  this.#recordUndoState();
@@ -5195,6 +5257,11 @@ export class Editor implements Component, Focusable {
5195
5257
  this.#cancelAutocomplete();
5196
5258
  this.onAutocompleteUpdate?.();
5197
5259
  this.#notifyChange();
5260
+ if (replacement.prediction) {
5261
+ this.#insertedPrediction = selected.value;
5262
+ const index = this.predictions?.()?.indexOf(selected.value) ?? -1;
5263
+ if (index >= 0) this.onPredictionAccepted?.(index);
5264
+ }
5198
5265
  }
5199
5266
  async #handleSlashCommandCompletion(): Promise<void> {
5200
5267
  await this.#tryTriggerAutocomplete();
@@ -5400,7 +5467,8 @@ export class Editor implements Component, Focusable {
5400
5467
 
5401
5468
  /**
5402
5469
  * Get inline hint text to show as dim ghost text after the cursor.
5403
- * Checks the selected autocomplete item's hint first, then the prediction, then the provider.
5470
+ * Checks the selected autocomplete item's hint first, then the prediction and its alternatives,
5471
+ * then the provider.
5404
5472
  */
5405
5473
  #getInlineHint(): string | null {
5406
5474
  // Check selected autocomplete item for a hint
@@ -5411,7 +5479,12 @@ export class Editor implements Component, Focusable {
5411
5479
 
5412
5480
  const prediction = this.#getPredictionSuffix();
5413
5481
  if (prediction) return prediction;
5414
-
5482
+ const alternatives = this.#getPredictionAlternatives();
5483
+ if (alternatives) {
5484
+ // Tab opens the alternatives list from here; without a bound key there is nothing to hint.
5485
+ const tab = editorKey("tui.input.tab");
5486
+ if (tab) return ` ${tab} ${alternatives.choices.length - 1} more`;
5487
+ }
5415
5488
  // Fall back to provider's getInlineHint
5416
5489
  if (this.#autocompleteProvider?.getInlineHint) {
5417
5490
  const hint = this.#autocompleteProvider.getInlineHint(
@@ -5428,18 +5501,44 @@ export class Editor implements Component, Focusable {
5428
5501
  if (this.#autocompleteState || !this.#isEditorEmpty() || this.#getPredictionSuffix()) return undefined;
5429
5502
  return this.placeholder?.() || undefined;
5430
5503
  }
5431
- /** The part of {@link prediction} not yet typed, or `null` when no prediction is shown. */
5504
+ /** The part of the shown prediction not yet typed, or `null` when no prediction is shown. */
5432
5505
  #getPredictionSuffix(): string | null {
5506
+ return this.#getShownPrediction()?.suffix ?? null;
5507
+ }
5508
+ /**
5509
+ * The prediction painted as ghost text: the first one the single-line buffer is a strict prefix of,
5510
+ * with the cursor at its end and no autocomplete open. None while the buffer is a prediction insert
5511
+ * that equals one of two or more predictions, so Tab opens their list rather than extending to a
5512
+ * longer one; a buffer the user typed keeps its ghost.
5513
+ */
5514
+ #getShownPrediction(): { index: number; suffix: string } | null {
5433
5515
  if (this.#autocompleteState) return null;
5434
- const prediction = this.prediction?.();
5435
- if (!prediction) return null;
5516
+ const predictions = this.predictions?.();
5517
+ if (!predictions?.length) return null;
5436
5518
  const { lines, cursorCol } = this.#state;
5437
5519
  if (lines.length !== 1) return null;
5438
5520
  const typed = lines[0] ?? "";
5439
- if (cursorCol !== typed.length || typed.length >= prediction.length || !prediction.startsWith(typed)) {
5440
- return null;
5441
- }
5442
- return prediction.slice(typed.length);
5521
+ if (cursorCol !== typed.length) return null;
5522
+ if (predictions.length > 1 && typed === this.#insertedPrediction && predictions.includes(typed)) return null;
5523
+ const index = predictions.findIndex(
5524
+ prediction => typed.length < prediction.length && prediction.startsWith(typed),
5525
+ );
5526
+ return index < 0 ? null : { index, suffix: predictions[index]!.slice(typed.length) };
5527
+ }
5528
+ /**
5529
+ * Two or more predictions, and which one the single-line buffer equals with the cursor at its end:
5530
+ * Tab then opens the list of all of them.
5531
+ */
5532
+ #getPredictionAlternatives(): { choices: readonly string[]; index: number } | null {
5533
+ if (this.#autocompleteState) return null;
5534
+ const choices = this.predictions?.();
5535
+ if (!choices || choices.length < 2) return null;
5536
+ const { lines, cursorCol } = this.#state;
5537
+ if (lines.length !== 1) return null;
5538
+ const typed = lines[0] ?? "";
5539
+ if (cursorCol !== typed.length) return null;
5540
+ const index = choices.indexOf(typed);
5541
+ return index < 0 ? null : { choices, index };
5443
5542
  }
5444
5543
  /** Typing `typed` where it diverges from the shown ghost completion rejects that ghost. */
5445
5544
  #reportTypedPastWordCompletion(typed: string): void {
@@ -207,6 +207,12 @@ export declare class Image implements Component {
207
207
  /** Return source metadata without exposing the encoded image buffer. */
208
208
  debugState(): Record<string, unknown>;
209
209
  invalidate(): void;
210
+ /**
211
+ * Refit to a new row ceiling; a SIXEL reserves its rows until the off-thread
212
+ * encode lands. A demoted fallback keeps the height already drawn only
213
+ * within the new ceiling: the owner chose to shrink the block.
214
+ */
215
+ setMaxHeightCells(maxHeightCells: number): void;
210
216
  releaseRenderCaches(): void;
211
217
  /**
212
218
  * A native `image` backed by a content-addressed blob; the terminal fits
@@ -773,6 +773,19 @@ export class Image implements Component {
773
773
  this.#cachedWidth = undefined;
774
774
  }
775
775
 
776
+ /**
777
+ * Refit to a new row ceiling; a SIXEL reserves its rows until the off-thread
778
+ * encode lands. A demoted fallback keeps the height already drawn only
779
+ * within the new ceiling: the owner chose to shrink the block.
780
+ */
781
+ setMaxHeightCells(maxHeightCells: number): void {
782
+ if (this.#options.maxHeightCells === maxHeightCells) return;
783
+ this.#options.maxHeightCells = maxHeightCells;
784
+ this.#renderedGraphicRows = Math.min(this.#renderedGraphicRows, maxHeightCells);
785
+ this.#native = undefined;
786
+ this.invalidate();
787
+ }
788
+
776
789
  releaseRenderCaches(): void {
777
790
  this.#cachedLines = undefined;
778
791
  this.#cachedWidth = undefined;
@@ -2,7 +2,15 @@ import { compactText, styleSpans } from "../native/spans";
2
2
  import { node } from "../native/describe";
3
3
  import type { DescribeContext, NativeNode } from "../native/node";
4
4
  import type { Component } from "../tui";
5
- import { Ellipsis, getWidthConfigEpoch, replaceTabs, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "../utils";
5
+ import {
6
+ Ellipsis,
7
+ finiteWidth,
8
+ getWidthConfigEpoch,
9
+ singleLine,
10
+ truncateToWidth,
11
+ visibleWidth,
12
+ wrapTextWithAnsi,
13
+ } from "../utils";
6
14
 
7
15
  /** One label/value entry in a {@link KeyValueList}. */
8
16
  export interface KeyValueRow {
@@ -21,14 +29,6 @@ export interface KeyValueListOptions {
21
29
  readonly labelOverflow?: "allow" | "truncate";
22
30
  }
23
31
 
24
- function finiteWidth(width: number): number {
25
- return Number.isFinite(width) ? Math.max(0, Math.trunc(width)) : 0;
26
- }
27
-
28
- function singleLine(text: string): string {
29
- return replaceTabs(text).replace(/[\r\n]+/g, " ");
30
- }
31
-
32
32
  /** A bounded ANSI-aware label/value list with replaceable rows and aligned wrapped continuations. */
33
33
  export class KeyValueList implements Component {
34
34
  #rows: readonly KeyValueRow[];