@oh-my-pi/pi-tui 18.8.8 → 18.9.0

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 (100) hide show
  1. package/CHANGELOG.md +56 -221
  2. package/dist/types/charts/chart-plan.d.ts +595 -13
  3. package/dist/types/charts/chart-svg.d.ts +38 -9
  4. package/dist/types/charts/table-data.d.ts +70 -2
  5. package/dist/types/chat/table-chart.d.ts +3 -2
  6. package/dist/types/chat/user-message.d.ts +12 -1
  7. package/dist/types/chrome/shared.d.ts +9 -0
  8. package/dist/types/chrome/transcript-container.d.ts +1 -0
  9. package/dist/types/components/editor.d.ts +6 -0
  10. package/dist/types/components/form.d.ts +1 -0
  11. package/dist/types/components/markdown.d.ts +7 -0
  12. package/dist/types/components/tree-view.d.ts +7 -0
  13. package/dist/types/kitty-graphics.d.ts +2 -2
  14. package/dist/types/loop-watchdog.d.ts +8 -7
  15. package/dist/types/multiplexers/cmux.d.ts +16 -0
  16. package/dist/types/multiplexers/herdr.d.ts +26 -0
  17. package/dist/types/multiplexers/notify.d.ts +13 -0
  18. package/dist/types/multiplexers/orca.d.ts +12 -0
  19. package/dist/types/multiplexers/screen.d.ts +9 -0
  20. package/dist/types/multiplexers/tmux.d.ts +29 -0
  21. package/dist/types/multiplexers/types.d.ts +100 -0
  22. package/dist/types/multiplexers/wmux.d.ts +12 -0
  23. package/dist/types/multiplexers/zellij.d.ts +12 -0
  24. package/dist/types/overlays/agent-hub-projection.d.ts +4 -3
  25. package/dist/types/overlays/agent-hub-types.d.ts +9 -0
  26. package/dist/types/overlays/annotation-overlay.d.ts +2 -0
  27. package/dist/types/overlays/model-browser.d.ts +9 -1
  28. package/dist/types/overlays/settings-defs.d.ts +1 -0
  29. package/dist/types/overlays/usage-display.d.ts +3 -1
  30. package/dist/types/setup/scenes/types.d.ts +1 -0
  31. package/dist/types/status-line/component.d.ts +2 -0
  32. package/dist/types/status-line/host.d.ts +4 -1
  33. package/dist/types/status-line/types.d.ts +11 -2
  34. package/dist/types/terminal-capabilities.d.ts +24 -32
  35. package/dist/types/terminal-multiplexer.d.ts +127 -14
  36. package/dist/types/terminal.d.ts +12 -4
  37. package/dist/types/theme/schema.d.ts +11 -2
  38. package/dist/types/theme/theme-class.d.ts +7 -0
  39. package/dist/types/tmux.d.ts +1 -4
  40. package/dist/types/tools/eval.d.ts +21 -2
  41. package/dist/types/tools/output-meta.d.ts +11 -1
  42. package/dist/types/tools/streaming-output.d.ts +9 -0
  43. package/package.json +9 -9
  44. package/src/charts/chart-plan.ts +4802 -88
  45. package/src/charts/chart-svg.ts +4315 -351
  46. package/src/charts/table-data.ts +1076 -34
  47. package/src/chat/assistant-message.ts +27 -9
  48. package/src/chat/chat-transcript-builder.ts +1 -3
  49. package/src/chat/svg-figure.ts +45 -8
  50. package/src/chat/table-chart.ts +7 -11
  51. package/src/chat/user-message.ts +40 -2
  52. package/src/chrome/shared.ts +53 -0
  53. package/src/chrome/transcript-container.ts +32 -9
  54. package/src/components/editor.ts +38 -5
  55. package/src/components/form.ts +8 -0
  56. package/src/components/markdown.ts +45 -2
  57. package/src/components/settings-list.ts +2 -0
  58. package/src/components/tree-view.ts +38 -8
  59. package/src/kitty-graphics.ts +4 -4
  60. package/src/loop-watchdog.ts +18 -13
  61. package/src/multiplexers/cmux.ts +29 -0
  62. package/src/multiplexers/herdr.ts +64 -0
  63. package/src/multiplexers/notify.ts +24 -0
  64. package/src/multiplexers/orca.ts +16 -0
  65. package/src/multiplexers/screen.ts +15 -0
  66. package/src/multiplexers/tmux.ts +40 -0
  67. package/src/multiplexers/types.ts +110 -0
  68. package/src/multiplexers/wmux.ts +16 -0
  69. package/src/multiplexers/zellij.ts +24 -0
  70. package/src/overlays/agent-hub-projection.ts +51 -14
  71. package/src/overlays/agent-hub-types.ts +6 -0
  72. package/src/overlays/annotation-overlay.ts +2 -1
  73. package/src/overlays/model-browser.ts +43 -7
  74. package/src/overlays/model-hub.ts +12 -19
  75. package/src/overlays/settings-defs.ts +4 -3
  76. package/src/overlays/settings-selector.ts +10 -1
  77. package/src/overlays/tree-selector.ts +21 -16
  78. package/src/overlays/usage-display.ts +10 -4
  79. package/src/setup/scenes/model.ts +2 -1
  80. package/src/setup/scenes/types.ts +1 -0
  81. package/src/status-line/component.ts +65 -11
  82. package/src/status-line/host.ts +4 -1
  83. package/src/status-line/segments.ts +21 -16
  84. package/src/status-line/types.ts +12 -2
  85. package/src/terminal-capabilities.ts +65 -181
  86. package/src/terminal-multiplexer.ts +112 -33
  87. package/src/terminal.ts +73 -32
  88. package/src/theme/schema-validation.ts +1 -0
  89. package/src/theme/schema.ts +14 -1
  90. package/src/theme/session-color.ts +1 -7
  91. package/src/theme/theme-class.ts +26 -1
  92. package/src/theme/theme-schema.json +5 -1
  93. package/src/theme/theme.ts +7 -4
  94. package/src/tmux.ts +4 -11
  95. package/src/tools/eval.ts +56 -16
  96. package/src/tools/output-meta.ts +23 -3
  97. package/src/tools/streaming-output.ts +29 -2
  98. package/src/tools/todo.ts +4 -1
  99. package/src/tui.ts +33 -18
  100. package/src/windows-input-mode.ts +8 -0
@@ -2,7 +2,12 @@ import type { AssistantMessage, ImageContent, TextContent } from "@oh-my-pi/pi-a
2
2
  import { type Component, Container } from "../tui";
3
3
  import { Image, type ImageBudget } from "../components/image";
4
4
  import { ImageProtocol, TERMINAL } from "../terminal-capabilities";
5
- import { Markdown, type MarkdownTheme, rewriteMarkdownLinkDestinations } from "../components/markdown";
5
+ import {
6
+ type DefaultTextStyle,
7
+ Markdown,
8
+ type MarkdownTheme,
9
+ rewriteMarkdownLinkDestinations,
10
+ } from "../components/markdown";
6
11
  import { Spacer } from "../components/spacer";
7
12
  import { Text } from "../components/text";
8
13
  import { formatDuration, formatNumber } from "@oh-my-pi/pi-utils";
@@ -390,6 +395,26 @@ export class AssistantMessageComponent extends Container {
390
395
  this.#textColorTransform = transform;
391
396
  }
392
397
 
398
+ /**
399
+ * Default text style for assistant paragraph Markdown. An explicitly
400
+ * installed transform (live-command output) always wins and keeps its
401
+ * historical paint-everything contract; otherwise the optional
402
+ * `assistantMessageText` theme token paints prose, flagged `proseFg` so
403
+ * markdown sub-elements keep their own `md*` tokens (docs/theme.md).
404
+ * Returns undefined when the token is unset or empty so the terminal
405
+ * default foreground is used byte-for-byte, exactly as before the token
406
+ * existed.
407
+ *
408
+ * The token is re-derived on every rebuild (the theme-change path calls
409
+ * `invalidate()` and rebuilds through the teardown path, which re-consults
410
+ * the active theme), so prose follows theme switches both ways.
411
+ */
412
+ #getProseTextStyle(): DefaultTextStyle | undefined {
413
+ if (this.#textColorTransform) return { color: this.#textColorTransform };
414
+ if (typeof theme === "undefined" || !theme.hasColor("assistantMessageText")) return undefined;
415
+ return { color: (text: string) => theme.fg("assistantMessageText", text), proseFg: true };
416
+ }
417
+
393
418
  #getProseTheme(): MarkdownTheme {
394
419
  if (this.#markdownTheme) return this.#markdownTheme;
395
420
  const base = getMarkdownTheme();
@@ -1269,14 +1294,7 @@ export class AssistantMessageComponent extends Container {
1269
1294
  /** Markdown for a text or thinking block; live children and stable-row renders share it so stable rows prefix the block render. */
1270
1295
  #createMarkdown(kind: StablePartKind, text: string): Markdown {
1271
1296
  return kind === "text"
1272
- ? new Markdown(
1273
- text,
1274
- 1,
1275
- 0,
1276
- this.#getProseTheme(),
1277
- this.#textColorTransform ? { color: this.#textColorTransform } : undefined,
1278
- 0,
1279
- )
1297
+ ? new Markdown(text, 1, 0, this.#getProseTheme(), this.#getProseTextStyle(), 0)
1280
1298
  : new Markdown(text, 1, 0, getMarkdownTheme(), {
1281
1299
  color: (value: string) => theme.fg("thinkingText", value),
1282
1300
  italic: true,
@@ -223,9 +223,7 @@ export class ChatTranscriptBuilder {
223
223
  }
224
224
  if (previous.canBeDisplacedBy(nextToolName)) {
225
225
  this.#todoSnapshot = null;
226
- if (this.container.canRemoveBlock(previous)) {
227
- this.container.removeChild(previous);
228
- }
226
+ this.container.removeChild(previous);
229
227
  previous.seal();
230
228
  return;
231
229
  }
@@ -13,7 +13,7 @@
13
13
  * places it 1:1: any resampling, even 0.99×, blurs every glyph edge.
14
14
  */
15
15
  import { rasterizeSvg } from "@oh-my-pi/pi-natives";
16
- import { logger } from "@oh-my-pi/pi-utils";
16
+ import { hexToOklch, hueDistance, logger, oklchCusp, oklchToHex } from "@oh-my-pi/pi-utils";
17
17
  import { Image, type ImageBudget, imageMaxColumns } from "../components/image";
18
18
  import { fencedCode, type Markdown } from "../components/markdown";
19
19
  import { type CellDimensions, getCellDimensions, getImageDimensions } from "../terminal-capabilities";
@@ -30,7 +30,10 @@ const MAX_EDGE_PX = 4096;
30
30
  /** Share of the terminal's rows one figure may fill, so it fits on screen whole. */
31
31
  const MAX_VIEWPORT_SHARE = 0.8;
32
32
 
33
- /** Foreground theme colors behind the figure tokens (`var(--name)`); `surface` is the selection background. */
33
+ /**
34
+ * Foreground theme colors behind the figure tokens (`var(--name)`); `surface`
35
+ * is the selection background and `c1`…`c6` come from {@link seriesColors}.
36
+ */
34
37
  const PALETTE: Readonly<Record<string, ThemeColor>> = {
35
38
  fg: "text",
36
39
  muted: "muted",
@@ -39,21 +42,55 @@ const PALETTE: Readonly<Record<string, ThemeColor>> = {
39
42
  success: "success",
40
43
  warning: "warning",
41
44
  error: "error",
42
- c1: "syntaxKeyword",
43
- c2: "syntaxString",
44
- c3: "syntaxFunction",
45
- c4: "syntaxType",
46
- c5: "syntaxNumber",
47
- c6: "syntaxVariable",
48
45
  };
49
46
 
47
+ /** Hue families (OKLCH degrees) the series colors draw from: blue, orange, green, purple, pink, teal. */
48
+ const SERIES_HUES = [255, 55, 145, 305, 0, 200];
49
+ /** Gold, for a sixth series when the accent's hue crowds out two families. */
50
+ const RESERVE_HUE = 90;
51
+ /** Least hue distance between a family and the accent's hue for both to lead series. */
52
+ const MIN_SERIES_HUE_GAP = 30;
53
+ /** Chroma below which the accent reads as gray and blue leads instead. */
54
+ const MIN_ACCENT_CHROMA = 0.04;
55
+ /** Lightness band of series colors: deep enough for labels on light surfaces, bright enough on dark ones. */
56
+ const SERIES_LIGHTNESS = { light: [0.52, 0.66], dark: [0.68, 0.82] } as const;
57
+ /** Chroma ceiling: vivid, not neon. */
58
+ const SERIES_CHROMA = 0.19;
59
+
50
60
  /** The active theme's color per figure token, for resolving a figure with `prepareSvg`. */
51
61
  export function svgFigurePalette(): Record<string, string> {
52
62
  const palette: Record<string, string> = { surface: theme.getBgHex("selectedBg") };
53
63
  for (const token in PALETTE) palette[token] = theme.getColorHex(PALETTE[token]!);
64
+ seriesColors(palette.accent!, theme.isLight).forEach((color, at) => {
65
+ palette[`c${at + 1}`] = color;
66
+ });
54
67
  return palette;
55
68
  }
56
69
 
70
+ /**
71
+ * Six series colors of even visual weight, in the manner of Apple's system
72
+ * palette: led by the theme accent's hue (blue when the accent is gray), each
73
+ * next hue the family farthest from those already taken. Every hue sits at
74
+ * its gamut cusp clamped into the theme's {@link SERIES_LIGHTNESS} band, so
75
+ * orange stays orange and blue stays deep.
76
+ */
77
+ function seriesColors(accent: string, light: boolean): string[] {
78
+ const { c, h } = hexToOklch(accent);
79
+ const lead = c >= MIN_ACCENT_CHROMA ? h : SERIES_HUES[0]!;
80
+ const hues = [lead];
81
+ const pool = SERIES_HUES.filter(hue => hueDistance(hue, lead) >= MIN_SERIES_HUE_GAP);
82
+ while (pool.length > 0) {
83
+ const gaps = pool.map(hue => Math.min(...hues.map(taken => hueDistance(hue, taken))));
84
+ hues.push(pool.splice(gaps.indexOf(Math.max(...gaps)), 1)[0]!);
85
+ }
86
+ if (hues.length < 6) hues.push(RESERVE_HUE);
87
+ const [low, high] = SERIES_LIGHTNESS[light ? "light" : "dark"];
88
+ return hues.slice(0, 6).map(hue => {
89
+ const cusp = oklchCusp(hue);
90
+ return oklchToHex({ l: Math.min(high, Math.max(low, cusp.l)), c: Math.min(SERIES_CHROMA, cusp.c), h: hue });
91
+ });
92
+ }
93
+
57
94
  let figuresEnabled = true;
58
95
 
59
96
  /** Turn lifting ```svg fences into images on or off (the host's `tui.renderSvg`); the host rebuilds the transcript after. */
@@ -3,15 +3,15 @@
3
3
  * `tui.autoGraph`). {@link splitTableCharts} cuts a Markdown block after each
4
4
  * top-level table that gets a chart; {@link lookupTableChart} plans, builds
5
5
  * and draws that chart — locally under `always`, through the host's
6
- * model-backed {@link TableChartPlanner} for multi-series tables under
7
- * `smart` — and caches it per table source. {@link TableChartFigure} shows it
6
+ * model-backed {@link TableChartPlanner} under `smart` for the tables
7
+ * {@link shouldJudge} picks — and caches it per table source. {@link TableChartFigure} shows it
8
8
  * as a rasterized terminal image; {@link describeTableChart} hands a TSP
9
9
  * terminal the SVG itself. Both resolve the figure tokens against the live
10
10
  * theme, so a chart follows theme switches like the prose around it.
11
11
  */
12
12
  import { logger } from "@oh-my-pi/pi-utils";
13
13
  import type { Token, Tokens } from "@oh-my-pi/pi-utils/marked";
14
- import { type ChartPlan, buildChart, planChart, worthCharting } from "../charts/chart-plan";
14
+ import { type ChartPlan, buildChart, planChart, shouldJudge, worthCharting } from "../charts/chart-plan";
15
15
  import { chartAlt, renderChartSvg } from "../charts/chart-svg";
16
16
  import { analyzeTable, type TableAnalysis } from "../charts/table-data";
17
17
  import type { ImageBudget } from "../components/image";
@@ -25,13 +25,14 @@ import { SvgFigure, svgFigurePalette } from "./svg-figure";
25
25
  import { prepareSvg } from "./svg-source";
26
26
 
27
27
  /**
28
- * `smart`: a model picks the kind and columns of multi-series tables;
28
+ * `smart`: a model refines the local guess where meaning decides (kind,
29
+ * columns, row names, ordering, polarity, focus, title; see {@link shouldJudge});
29
30
  * `always`: the local best guess charts every table it reads as numeric;
30
31
  * `off`: tables stay tables.
31
32
  */
32
33
  export type TableChartMode = "smart" | "always" | "off";
33
34
 
34
- /** A multi-series table the host's planner picks a chart for. */
35
+ /** A table the host's planner picks a chart for ({@link shouldJudge}). */
35
36
  export interface TableChartRequest {
36
37
  /** The table's Markdown source. */
37
38
  readonly markdown: string;
@@ -176,12 +177,7 @@ function chartEntry(table: Tokens.Table): ChartEntry {
176
177
  table.rows.map(row => row.map(cell => cell.text)),
177
178
  );
178
179
  const guess = planChart(analysis);
179
- const smart =
180
- guess !== undefined &&
181
- chartMode === "smart" &&
182
- chartPlanner !== undefined &&
183
- analysis.measures.length >= 2 &&
184
- analysis.rows.length >= 3;
180
+ const smart = chartMode === "smart" && chartPlanner !== undefined && shouldJudge(analysis, guess);
185
181
  const entry: ChartEntry = { analysis, guess, smart };
186
182
  if (!smart) entry.chart = guess ? drawChart(analysis, guess, true) : null;
187
183
  charts.set(key, entry);
@@ -1,4 +1,5 @@
1
- import { applyBackgroundToLine, padding, visibleWidth } from "../utils";
1
+ import { applyBackgroundToLine, padding, stripTerminalSequences, visibleWidth } from "../utils";
2
+ import type { AnimationFrame, TranscriptPresentationTarget } from "../chrome/transcript-container";
2
3
  import { type Component, Container } from "../tui";
3
4
  import { Disclosure } from "../components/disclosure";
4
5
  import { Markdown } from "../components/markdown";
@@ -124,7 +125,8 @@ export function userBubbleColor(
124
125
  * (see {@link ReactionTarget}) drawn right-aligned in the bubble's top padding row;
125
126
  * a live-steered message carries a `*` marker left-aligned in the same row.
126
127
  */
127
- export class UserMessageComponent extends Container implements ReactionTarget {
128
+ export class UserMessageComponent extends Container implements ReactionTarget, TranscriptPresentationTarget {
129
+ #allocation = Number.POSITIVE_INFINITY;
128
130
  // Memoized OSC 133 zone wrapping keyed on the underlying container render
129
131
  // (same source ref ⇒ identical rows ⇒ reuse the wrapped copy). Keeps this
130
132
  // component reference-stable for the transcript's incremental assembly and
@@ -287,11 +289,47 @@ export class UserMessageComponent extends Container implements ReactionTarget {
287
289
  return applyBackgroundToLine(` ${marker}${padding(gap)}${emoji}`, width, this.#bgColor);
288
290
  }
289
291
 
292
+ /** Apply the transcript allocator's current viewport reservation. */
293
+ setTranscriptAllocation(rows: number, _frame?: AnimationFrame): void {
294
+ this.#allocation = Math.max(0, Math.trunc(rows));
295
+ }
296
+
297
+ isTranscriptBlockFinalized(): boolean {
298
+ return true;
299
+ }
300
+
301
+ /**
302
+ * Single-row emergency representation for the overflow transcript layout:
303
+ * renders the first content line instead of the blank top padding row, and
304
+ * omits OSC 133 shell integration markers so moving live blocks across the
305
+ * viewport does not leave stale prompt marks on lines it no longer occupies.
306
+ */
307
+ renderTranscriptBlockEmergencyRow(width: number): string | undefined {
308
+ return this.#selectEmergencyRow(super.render(width));
309
+ }
310
+
311
+ #selectEmergencyRow(lines: readonly string[]): string | undefined {
312
+ if (lines.length === 0) return undefined;
313
+ if (lines.length >= 3) {
314
+ for (let i = 1; i < lines.length - 1; i++) {
315
+ if (stripTerminalSequences(lines[i]!).trim().length > 0) {
316
+ return lines[i];
317
+ }
318
+ }
319
+ return lines[1];
320
+ }
321
+ return lines[0];
322
+ }
323
+
290
324
  override render(width: number): readonly string[] {
291
325
  const lines = super.render(width);
292
326
  if (lines.length === 0) {
293
327
  return lines;
294
328
  }
329
+ if (this.#allocation === 1) {
330
+ const emergency = this.#selectEmergencyRow(lines);
331
+ if (emergency !== undefined) return [emergency];
332
+ }
295
333
  if (this.#zoneSource === lines && this.#zoneLines !== undefined) {
296
334
  return this.#zoneLines;
297
335
  }
@@ -10,6 +10,59 @@ export function sanitizeStatusText(text: string): string {
10
10
  return sanitizeDisplaySingleLine(text).replace(/ +/g, " ").trim();
11
11
  }
12
12
 
13
+ /** 7-bit SGR (`ESC [ <params> m`) — the one escape family a hook status may keep. */
14
+ const SGR_RE = /\x1b\[[0-9;:]*m/g;
15
+ const SGR_RESET = "\x1b[0m";
16
+ const WHITESPACE_RE = /\s/;
17
+
18
+ /**
19
+ * Like {@link sanitizeStatusText}, but keeps 7-bit SGR so extensions can colour
20
+ * `ctx.ui.setStatus` text. Every other escape (OSC links/titles, DCS/PM/APC,
21
+ * 7- and 8-bit CSI), C0/C1, lone surrogates, newlines and tabs are sanitized at
22
+ * least as strictly as in `sanitizeStatusText`; space runs collapse and edges
23
+ * trim (`String#trim` whitespace) by visible text, regardless of SGR placement.
24
+ * A styled result always ends with `\x1b[0m`.
25
+ */
26
+ export function sanitizeHookStatusText(input: string): string {
27
+ // Drop lone surrogates before splitting, as `sanitizeText` does, so stripped escapes
28
+ // cannot fuse surrogate halves from neighbouring chunks into a new character.
29
+ const wellFormed = input.toWellFormed();
30
+ const text = wellFormed === input ? input : wellFormed.replaceAll("\ufffd", "");
31
+ SGR_RE.lastIndex = 0;
32
+ if (!SGR_RE.test(text)) return sanitizeStatusText(text); // byte-identical for unstyled input
33
+ let out = "";
34
+ // SGR codes and whitespace seen since the last visible char, in source order.
35
+ let pending = "";
36
+ let lastWasSpace = false;
37
+ let hasVisible = false;
38
+ let cursor = 0;
39
+ SGR_RE.lastIndex = 0;
40
+ for (;;) {
41
+ const match = SGR_RE.exec(text);
42
+ // `sanitizeText` runs `Bun.stripANSI` only when an ESC is present; a chunk between SGR
43
+ // codes often has none, so strip explicitly to drop 8-bit (C1) sequence payloads.
44
+ const chunk = sanitizeDisplaySingleLine(Bun.stripANSI(text.slice(cursor, match ? match.index : text.length)));
45
+ for (const ch of chunk) {
46
+ if (WHITESPACE_RE.test(ch)) {
47
+ // Leading whitespace drops; ASCII space runs collapse even across SGR codes.
48
+ if (hasVisible && !(ch === " " && lastWasSpace)) pending += ch;
49
+ lastWasSpace = ch === " ";
50
+ continue;
51
+ }
52
+ out += pending + ch;
53
+ pending = "";
54
+ lastWasSpace = false;
55
+ hasVisible = true;
56
+ }
57
+ if (!match) break;
58
+ pending += match[0];
59
+ cursor = match.index + match[0].length;
60
+ }
61
+ if (!hasVisible) return "";
62
+ // Trailing whitespace trims; trailing SGR codes stay (they never contain whitespace).
63
+ return out + pending.replace(/\s+/g, "") + SGR_RESET;
64
+ }
65
+
13
66
  // ═══════════════════════════════════════════════════════════════════════════
14
67
  // Tab Bar Theme
15
68
  // ═══════════════════════════════════════════════════════════════════════════
@@ -232,10 +232,15 @@ export class TranscriptContainer extends Container {
232
232
  this.#entriesUnverified = true;
233
233
  }
234
234
 
235
+ /** Removes `component` if {@link canRemoveBlock} allows it; otherwise does nothing. */
235
236
  override removeChild(component: Component): void {
236
- if (this.children.indexOf(component) < 0 || !this.canRemoveBlock(component)) return;
237
- super.removeChild(component);
238
- this.#entries = this.#entries.filter(candidate => candidate.component !== component);
237
+ const index = this.#removableIndex(component);
238
+ if (index < 0) return;
239
+ // #removableIndex synced entries, which now mirror children index for
240
+ // index. This class renders through its own entries, never Container's
241
+ // memoized render, so splicing children directly is the whole removal.
242
+ this.children.splice(index, 1);
243
+ this.#entries.splice(index, 1);
239
244
  this.#frontier = Math.min(this.#frontier, this.#entries.length);
240
245
  this.#childStartRows.delete(component);
241
246
  }
@@ -290,14 +295,24 @@ export class TranscriptContainer extends Container {
290
295
 
291
296
  /** Whether a transient block may be discarded without leaving tape history. */
292
297
  canRemoveBlock(component: Component): boolean {
298
+ return this.#removableIndex(component) >= 0;
299
+ }
300
+
301
+ /**
302
+ * Syncs entries, then returns `component`'s index if it can be discarded
303
+ * without leaving tape history (not committed, not emitted, not in an
304
+ * offered batch), else -1.
305
+ */
306
+ #removableIndex(component: Component): number {
293
307
  this.#syncEntries();
294
- const index = this.#entries.findIndex(entry => entry.component === component);
295
- if (index < 0) return false;
308
+ // Removable blocks are transient ones near the live tail, so search from there.
309
+ const index = this.#entries.findLastIndex(entry => entry.component === component);
310
+ if (index < 0) return -1;
296
311
  const entry = this.#entries[index]!;
297
- if (entry.state === "committed" || entry.emitted > 0) return false;
298
- if (this.#offered?.kind === "commit" && index < this.#offered.end) return false;
299
- if (this.#offered?.kind === "append" && index === this.#offered.entry) return false;
300
- return true;
312
+ if (entry.state === "committed" || entry.emitted > 0) return -1;
313
+ if (this.#offered?.kind === "commit" && index < this.#offered.end) return -1;
314
+ if (this.#offered?.kind === "append" && index === this.#offered.entry) return -1;
315
+ return index;
301
316
  }
302
317
 
303
318
  /**
@@ -1186,6 +1201,14 @@ export class TranscriptContainer extends Container {
1186
1201
  continue;
1187
1202
  }
1188
1203
  this.#setAllocation(candidate.entry.component, 1, frame);
1204
+ const emergency = (
1205
+ candidate.entry.component as Component & FinalizableBlock
1206
+ ).renderTranscriptBlockEmergencyRow?.(width);
1207
+ if (emergency !== undefined) {
1208
+ output.push(emergency);
1209
+ owners.push(candidate.entry.component);
1210
+ continue;
1211
+ }
1189
1212
  const rendered = this.#renderEntry(candidate.entry, width).slice(
1190
1213
  this.#projectedEmittedRowCount(candidate.entry, candidate.index, width),
1191
1214
  );
@@ -771,6 +771,12 @@ export class Editor implements Component, Focusable {
771
771
  * cursor. The host styles it (ANSI allowed). Re-evaluated on every render, so hosts can derive
772
772
  * it from live state. */
773
773
  placeholder?: () => string | undefined;
774
+ /** Whole-message prediction for the next prompt, painted as ghost text after the cursor while
775
+ * the single-line buffer is a strict prefix of it, the cursor sits at its end, and no
776
+ * autocomplete is open. A shown prediction replaces the {@link placeholder}; Tab or Right inserts
777
+ * the rest without submitting. Must be a single line. Re-evaluated on every render, so hosts can
778
+ * derive it from live state. */
779
+ prediction?: () => string | undefined;
774
780
 
775
781
  // Custom top border (for status line integration). Either an eager `content`
776
782
  // (set once, reused every frame) or a `provider` that recomputes lazily just
@@ -1678,7 +1684,10 @@ export class Editor implements Component, Focusable {
1678
1684
 
1679
1685
  const placeholder = this.#getPlaceholder();
1680
1686
  const nativePlaceholder =
1681
- this.describePlaceholder !== undefined && !this.#autocompleteState && this.#isEditorEmpty()
1687
+ this.describePlaceholder !== undefined &&
1688
+ !this.#autocompleteState &&
1689
+ this.#isEditorEmpty() &&
1690
+ !this.#getPredictionSuffix()
1682
1691
  ? this.describePlaceholder()
1683
1692
  : placeholder && plainText(placeholder).trim();
1684
1693
  const atLineEnd = cursorCol >= (lines[cursorLine]?.length ?? 0);
@@ -2211,8 +2220,8 @@ export class Editor implements Component, Focusable {
2211
2220
  this.#moveCursor(1, 0); // Cursor movement (within text or history entry)
2212
2221
  }
2213
2222
  } else if (kb.matchesCanonical(canonical, "tui.editor.cursorRight")) {
2214
- // Right walks over the ghost word completion as if it were typed: no trailing space.
2215
- if (this.#acceptWordCompletion({ space: false })) return;
2223
+ // Right walks over the ghost prediction or word completion as if it were typed: no trailing space.
2224
+ if (this.#acceptPrediction() || this.#acceptWordCompletion({ space: false })) return;
2216
2225
  this.#moveCursor(0, 1);
2217
2226
  } else if (kb.matchesCanonical(canonical, "tui.editor.cursorLeft")) {
2218
2227
  // Left
@@ -4626,6 +4635,7 @@ export class Editor implements Component, Focusable {
4626
4635
  }
4627
4636
 
4628
4637
  async #handleTabCompletion(): Promise<void> {
4638
+ if (this.#acceptPrediction()) return;
4629
4639
  if (this.#acceptWordCompletion({ space: true })) return;
4630
4640
  if (!this.#autocompleteProvider) return;
4631
4641
 
@@ -4663,6 +4673,13 @@ export class Editor implements Component, Focusable {
4663
4673
  if (space) this.#lastAction = "accept-word";
4664
4674
  return true;
4665
4675
  }
4676
+ /** Insert the rest of the shown {@link prediction}, if any. Never submits. */
4677
+ #acceptPrediction(): boolean {
4678
+ const suffix = this.#getPredictionSuffix();
4679
+ if (!suffix) return false;
4680
+ this.#insertTextAtCursor(suffix);
4681
+ return true;
4682
+ }
4666
4683
 
4667
4684
  async #showSpellingSuggestions(): Promise<void> {
4668
4685
  const cursorLine = this.#state.cursorLine;
@@ -4917,7 +4934,7 @@ export class Editor implements Component, Focusable {
4917
4934
 
4918
4935
  /**
4919
4936
  * Get inline hint text to show as dim ghost text after the cursor.
4920
- * Checks selected autocomplete item's hint first, then falls back to provider.
4937
+ * Checks the selected autocomplete item's hint first, then the prediction, then the provider.
4921
4938
  */
4922
4939
  #getInlineHint(): string | null {
4923
4940
  // Check selected autocomplete item for a hint
@@ -4926,6 +4943,9 @@ export class Editor implements Component, Focusable {
4926
4943
  return selected?.hint ?? null;
4927
4944
  }
4928
4945
 
4946
+ const prediction = this.#getPredictionSuffix();
4947
+ if (prediction) return prediction;
4948
+
4929
4949
  // Fall back to provider's getInlineHint
4930
4950
  if (this.#autocompleteProvider?.getInlineHint) {
4931
4951
  const hint = this.#autocompleteProvider.getInlineHint(
@@ -4939,9 +4959,22 @@ export class Editor implements Component, Focusable {
4939
4959
  return this.#getWordCompletion();
4940
4960
  }
4941
4961
  #getPlaceholder(): string | undefined {
4942
- if (this.#autocompleteState || !this.#isEditorEmpty()) return undefined;
4962
+ if (this.#autocompleteState || !this.#isEditorEmpty() || this.#getPredictionSuffix()) return undefined;
4943
4963
  return this.placeholder?.() || undefined;
4944
4964
  }
4965
+ /** The part of {@link prediction} not yet typed, or `null` when no prediction is shown. */
4966
+ #getPredictionSuffix(): string | null {
4967
+ if (this.#autocompleteState) return null;
4968
+ const prediction = this.prediction?.();
4969
+ if (!prediction) return null;
4970
+ const { lines, cursorCol } = this.#state;
4971
+ if (lines.length !== 1) return null;
4972
+ const typed = lines[0] ?? "";
4973
+ if (cursorCol !== typed.length || typed.length >= prediction.length || !prediction.startsWith(typed)) {
4974
+ return null;
4975
+ }
4976
+ return prediction.slice(typed.length);
4977
+ }
4945
4978
  /** Typing `typed` where it diverges from the shown ghost completion rejects that ghost. */
4946
4979
  #reportTypedPastWordCompletion(typed: string): void {
4947
4980
  if (!this.#textAssistProvider?.wordCompletionFeedback) return;
@@ -96,6 +96,10 @@ class OptionalText implements Component {
96
96
  this.#text = new StyledText("", style, token);
97
97
  }
98
98
 
99
+ get value(): string {
100
+ return this.#value;
101
+ }
102
+
99
103
  describe(cx: DescribeContext): NativeNode {
100
104
  return this.#value ? this.#text.describe(cx) : this.#hidden;
101
105
  }
@@ -199,6 +203,10 @@ export class FormField implements Component, Focusable, MouseRoutable {
199
203
  return this.#focused;
200
204
  }
201
205
 
206
+ get hasError(): boolean {
207
+ return this.#error.value !== "";
208
+ }
209
+
202
210
  get debugChildren(): readonly Component[] {
203
211
  return [this.control];
204
212
  }
@@ -1313,6 +1313,13 @@ function objectId(o: object): number {
1313
1313
  export interface DefaultTextStyle {
1314
1314
  /** Foreground color function */
1315
1315
  color?: (text: string) => string;
1316
+ /**
1317
+ * The `color` foreground is prose-level: semantically-themed markdown spans
1318
+ * (headings, links) keep their own `md*` theme colors instead of being
1319
+ * painted over by it, while plain text runs still use `color`. Unset keeps
1320
+ * the historical behavior where `color` paints every run.
1321
+ */
1322
+ proseFg?: boolean;
1316
1323
  /** Background color function */
1317
1324
  bgColor?: (text: string) => string;
1318
1325
  /** Bold text */
@@ -1389,6 +1396,8 @@ export interface MarkdownTheme {
1389
1396
  interface InlineStyleContext {
1390
1397
  applyText: (text: string) => string;
1391
1398
  stylePrefix: string;
1399
+ /** True when the context came from the component's own default style (vs. a caller-supplied one). */
1400
+ isDefault?: boolean;
1392
1401
  }
1393
1402
 
1394
1403
  type ListToken = Token & {
@@ -3290,6 +3299,37 @@ export class Markdown implements Component {
3290
3299
  return {
3291
3300
  applyText: (text: string) => this.#applyDefaultStyle(text),
3292
3301
  stylePrefix: this.#getDefaultStylePrefix(),
3302
+ isDefault: true,
3303
+ };
3304
+ }
3305
+
3306
+ /**
3307
+ * Style context for semantically-themed spans (headings, links) under a
3308
+ * `proseFg` default style: plain runs keep the prose foreground, but the
3309
+ * span's own `md*` theme color must stay the innermost (winning) SGR, so
3310
+ * `applyText` keeps decorations (bold/italic/…) while dropping the
3311
+ * prose color. Non-`proseFg` styles and caller-supplied contexts pass
3312
+ * through unchanged.
3313
+ */
3314
+ #proseFgExemptContext(styleContext: InlineStyleContext | undefined): InlineStyleContext | undefined {
3315
+ // A caller-supplied context (blockquote identity styling) already governs
3316
+ // this subtree and wins; exemption applies only to the component's own
3317
+ // default style (undefined resolves to it downstream), and stays applied
3318
+ // through nested recursion.
3319
+ if (styleContext && !styleContext.isDefault) return styleContext;
3320
+ if (!this.#defaultTextStyle?.color || !this.#defaultTextStyle?.proseFg) return styleContext;
3321
+ const applyExceptColor = (text: string): string => {
3322
+ let styled = text;
3323
+ if (this.#defaultTextStyle?.bold) styled = this.#theme.bold(styled);
3324
+ if (this.#defaultTextStyle?.italic) styled = this.#theme.italic(styled);
3325
+ if (this.#defaultTextStyle?.strikethrough) styled = this.#theme.strikethrough(styled);
3326
+ if (this.#defaultTextStyle?.underline) styled = this.#theme.underline(styled);
3327
+ return styled;
3328
+ };
3329
+ return {
3330
+ applyText: applyExceptColor,
3331
+ stylePrefix: this.#getStylePrefix(applyExceptColor),
3332
+ isDefault: true,
3293
3333
  };
3294
3334
  }
3295
3335
 
@@ -3321,7 +3361,7 @@ export class Markdown implements Component {
3321
3361
  case "heading": {
3322
3362
  const headingLevel = token.depth;
3323
3363
  const headingPrefix = `${"#".repeat(headingLevel)} `;
3324
- const headingText = this.#renderInlineTokens(token.tokens || [], styleContext);
3364
+ const headingText = this.#renderInlineTokens(token.tokens || [], this.#proseFgExemptContext(styleContext));
3325
3365
  const headingPlainText = plainInlineTokens(token.tokens || []);
3326
3366
  let styledHeading: string;
3327
3367
  if (headingLevel === 1 && TERMINAL.textSizing) {
@@ -3639,7 +3679,10 @@ export class Markdown implements Component {
3639
3679
 
3640
3680
  case "link": {
3641
3681
  markHtmlItemWhenContent(token.text);
3642
- const linkText = this.#renderInlineTokens(token.tokens || [], resolvedStyleContext);
3682
+ const linkText = this.#renderInlineTokens(
3683
+ token.tokens || [],
3684
+ this.#proseFgExemptContext(resolvedStyleContext),
3685
+ );
3643
3686
  const styledLinkText = this.#theme.link(this.#theme.underline(linkText));
3644
3687
  const href = typeof token.href === "string" ? token.href : "";
3645
3688
  const target = (href && this.#theme.resolveLink?.(href)) || href;
@@ -346,6 +346,8 @@ export class SettingsList implements Component {
346
346
  return { row: id, option: component.selectList.getSelectedItem()?.value };
347
347
  }
348
348
  if (component instanceof TextFormField) {
349
+ // Native inline text editing has no error slot; show the form until corrected.
350
+ if (component.hasError) return null;
349
351
  const draft = component.getValue();
350
352
  return {
351
353
  row: id,