@oh-my-pi/pi-tui 18.6.3 → 18.8.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 (116) hide show
  1. package/CHANGELOG.md +46 -109
  2. package/dist/types/app-keybindings.d.ts +1 -1
  3. package/dist/types/apps/debug/log-viewer.d.ts +4 -0
  4. package/dist/types/apps/debug/raw-sse-buffer.d.ts +2 -0
  5. package/dist/types/autocomplete.d.ts +5 -2
  6. package/dist/types/charts/chart-plan.d.ts +92 -0
  7. package/dist/types/charts/chart-svg.d.ts +30 -0
  8. package/dist/types/charts/table-data.d.ts +107 -0
  9. package/dist/types/chat/assistant-message.d.ts +4 -0
  10. package/dist/types/chat/chat-transcript-builder.d.ts +2 -0
  11. package/dist/types/chat/fence-figure.d.ts +42 -0
  12. package/dist/types/chat/figure-markdown.d.ts +42 -0
  13. package/dist/types/chat/svg-figure.d.ts +33 -0
  14. package/dist/types/chat/svg-source.d.ts +49 -0
  15. package/dist/types/chat/table-chart.d.ts +88 -0
  16. package/dist/types/chat/tool-execution.d.ts +2 -0
  17. package/dist/types/components/editor.d.ts +9 -4
  18. package/dist/types/components/image.d.ts +9 -0
  19. package/dist/types/components/markdown.d.ts +16 -2
  20. package/dist/types/fuzzy.d.ts +29 -1
  21. package/dist/types/keybindings.d.ts +1 -1
  22. package/dist/types/native/backend.d.ts +2 -1
  23. package/dist/types/native/blobs.d.ts +4 -2
  24. package/dist/types/native/encode.d.ts +3 -4
  25. package/dist/types/overlays/agent-transcript-viewer.d.ts +8 -1
  26. package/dist/types/overlays/agents-hub.d.ts +9 -0
  27. package/dist/types/overlays/annotation-overlay.d.ts +5 -2
  28. package/dist/types/overlays/history-search.d.ts +10 -0
  29. package/dist/types/overlays/model-browser.d.ts +31 -3
  30. package/dist/types/overlays/plan-review-overlay.d.ts +3 -2
  31. package/dist/types/prompt/custom-editor.d.ts +7 -4
  32. package/dist/types/prompt/interactive-context-helpers.d.ts +4 -1
  33. package/dist/types/prompt/model-mention-autocomplete.d.ts +1 -1
  34. package/dist/types/render/composite.d.ts +2 -0
  35. package/dist/types/tools/glob.d.ts +4 -0
  36. package/dist/types/tools/renderer.d.ts +22 -0
  37. package/dist/types/tools/streaming-output.d.ts +11 -1
  38. package/dist/types/tools/write.d.ts +8 -1
  39. package/dist/types/utils.d.ts +6 -0
  40. package/package.json +9 -9
  41. package/src/apps/debug/log-viewer.ts +188 -72
  42. package/src/apps/debug/raw-sse-buffer.ts +8 -0
  43. package/src/apps/debug/raw-sse.ts +39 -5
  44. package/src/apps/git/diff-pane.ts +26 -5
  45. package/src/autocomplete.ts +67 -43
  46. package/src/charts/chart-plan.ts +367 -0
  47. package/src/charts/chart-svg.ts +693 -0
  48. package/src/charts/table-data.ts +436 -0
  49. package/src/chat/assistant-message.ts +169 -39
  50. package/src/chat/chat-transcript-builder.ts +4 -0
  51. package/src/chat/fence-figure.ts +80 -0
  52. package/src/chat/figure-markdown.ts +174 -0
  53. package/src/chat/svg-figure.ts +362 -0
  54. package/src/chat/svg-source.ts +188 -0
  55. package/src/chat/table-chart.ts +301 -0
  56. package/src/chat/tool-execution.ts +53 -4
  57. package/src/chrome/transcript-container.ts +7 -1
  58. package/src/components/editor.ts +68 -33
  59. package/src/components/image.ts +27 -1
  60. package/src/components/markdown.ts +80 -304
  61. package/src/fuzzy.ts +115 -30
  62. package/src/keybindings.ts +1 -1
  63. package/src/native/backend.ts +170 -15
  64. package/src/native/blobs.ts +4 -2
  65. package/src/native/encode.ts +58 -31
  66. package/src/overlays/agent-hub-projection.ts +70 -2
  67. package/src/overlays/agent-hub.ts +3 -2
  68. package/src/overlays/agent-transcript-viewer.ts +66 -13
  69. package/src/overlays/agents-hub.ts +28 -8
  70. package/src/overlays/annotation-overlay.ts +179 -80
  71. package/src/overlays/ask-dialog.ts +1 -1
  72. package/src/overlays/copy-selector.ts +30 -8
  73. package/src/overlays/extensions/state-manager.ts +52 -12
  74. package/src/overlays/history-search.ts +100 -7
  75. package/src/overlays/jobs-panel.ts +30 -2
  76. package/src/overlays/model-browser.ts +269 -90
  77. package/src/overlays/model-hub.ts +34 -7
  78. package/src/overlays/oauth-selector.ts +41 -26
  79. package/src/overlays/plan-review-overlay.ts +183 -68
  80. package/src/overlays/rewind-selector.ts +86 -17
  81. package/src/overlays/session-selector.ts +24 -4
  82. package/src/overlays/settings-selector.ts +21 -6
  83. package/src/overlays/tree-selector.ts +20 -4
  84. package/src/overlays/usage-dashboard.ts +12 -15
  85. package/src/prompt/attachment-chips.ts +2 -1
  86. package/src/prompt/composer-attachments.ts +6 -4
  87. package/src/prompt/composer.ts +2 -14
  88. package/src/prompt/custom-editor.ts +48 -19
  89. package/src/prompt/interactive-context-helpers.ts +30 -18
  90. package/src/prompt/macos-spelling.ts +7 -0
  91. package/src/prompt/magic-keywords.ts +11 -2
  92. package/src/prompt/model-mention-autocomplete.ts +14 -14
  93. package/src/prompt/word-completion.ts +38 -5
  94. package/src/render/composite.ts +62 -0
  95. package/src/setup/scenes/splash.ts +109 -45
  96. package/src/status-line/component.ts +220 -64
  97. package/src/status-line/segments.ts +8 -3
  98. package/src/terminal.ts +3 -2
  99. package/src/tools/ast-edit.ts +59 -35
  100. package/src/tools/ast-grep.ts +35 -16
  101. package/src/tools/default-renderer.ts +35 -19
  102. package/src/tools/eval-format/index.ts +28 -2
  103. package/src/tools/eval-format/javascript.ts +7 -5
  104. package/src/tools/eval.ts +164 -78
  105. package/src/tools/glob.ts +23 -6
  106. package/src/tools/grep.ts +81 -48
  107. package/src/tools/lsp.ts +81 -59
  108. package/src/tools/mcp.ts +98 -68
  109. package/src/tools/renderer.ts +27 -0
  110. package/src/tools/streaming-output.ts +120 -48
  111. package/src/tools/task.ts +111 -54
  112. package/src/tools/todo.ts +115 -29
  113. package/src/tools/wait.ts +34 -24
  114. package/src/tools/write.ts +77 -39
  115. package/src/tui.ts +118 -105
  116. package/src/utils.ts +19 -0
@@ -0,0 +1,301 @@
1
+ /**
2
+ * Charts drawn under numeric tables in assistant answers (the host's
3
+ * `tui.autoGraph`). {@link splitTableCharts} cuts a Markdown block after each
4
+ * top-level table that gets a chart; {@link lookupTableChart} plans, builds
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
8
+ * as a rasterized terminal image; {@link describeTableChart} hands a TSP
9
+ * terminal the SVG itself. Both resolve the figure tokens against the live
10
+ * theme, so a chart follows theme switches like the prose around it.
11
+ */
12
+ import { logger } from "@oh-my-pi/pi-utils";
13
+ import type { Token, Tokens } from "@oh-my-pi/pi-utils/marked";
14
+ import { type ChartPlan, buildChart, planChart, worthCharting } from "../charts/chart-plan";
15
+ import { chartAlt, renderChartSvg } from "../charts/chart-svg";
16
+ import { analyzeTable, type TableAnalysis } from "../charts/table-data";
17
+ import type { ImageBudget } from "../components/image";
18
+ import { lexDocument } from "../components/markdown";
19
+ import { node } from "../native/describe";
20
+ import { registerNativeBlob } from "../native/blobs";
21
+ import type { NativeNode } from "../native/node";
22
+ import { getThemeEpoch } from "../theme";
23
+ import type { Component } from "../tui";
24
+ import { SvgFigure, svgFigurePalette } from "./svg-figure";
25
+ import { prepareSvg } from "./svg-source";
26
+
27
+ /**
28
+ * `smart`: a model picks the kind and columns of multi-series tables;
29
+ * `always`: the local best guess charts every table it reads as numeric;
30
+ * `off`: tables stay tables.
31
+ */
32
+ export type TableChartMode = "smart" | "always" | "off";
33
+
34
+ /** A multi-series table the host's planner picks a chart for. */
35
+ export interface TableChartRequest {
36
+ /** The table's Markdown source. */
37
+ readonly markdown: string;
38
+ readonly table: TableAnalysis;
39
+ /** The local best guess; the planner may keep it. */
40
+ readonly guess: ChartPlan;
41
+ }
42
+
43
+ /**
44
+ * Picks the chart for a multi-series table under `smart`: a plan, or `null`
45
+ * for no chart. A rejection falls back to the local guess.
46
+ */
47
+ export type TableChartPlanner = (request: TableChartRequest) => Promise<ChartPlan | null>;
48
+
49
+ /** A drawn chart, ready to resolve against the theme. */
50
+ export interface TableChart {
51
+ /** SVG colored with figure tokens (`var(--accent)`, …). */
52
+ readonly svg: string;
53
+ readonly alt: string;
54
+ /** Size in SVG user units. */
55
+ readonly width: number;
56
+ readonly height: number;
57
+ }
58
+
59
+ /** The chart under a table: drawn, none, or a smart pick on its way (the promise settles once the cache holds it). */
60
+ export type ChartLookup = TableChart | null | Promise<void>;
61
+
62
+ /** One run of a Markdown block: prose (ending at a charted table), or the chart drawn after that table. */
63
+ export type ChartSegment =
64
+ | { readonly kind: "markdown"; readonly text: string }
65
+ | { readonly kind: "chart"; readonly table: Tokens.Table };
66
+
67
+ /** Tables cached per source; a long session keeps its recent charts without growing without bound. */
68
+ const CACHE_LIMIT = 256;
69
+ /** SVG user units per terminal column (16 per row on 1:2 cells), sizing native images. */
70
+ const UNITS_PER_COLUMN = 8;
71
+ /** A GFM delimiter row (`|---|:--:|`), the cheap test before lexing a block. */
72
+ const DELIMITER_ROW = /^ {0,3}\|?[ \t]*:?-+:?[ \t]*\|/m;
73
+
74
+ /** A table read once per source: its local guess and, once known, its chart. */
75
+ interface ChartEntry {
76
+ readonly analysis: TableAnalysis;
77
+ readonly guess: ChartPlan | undefined;
78
+ /** The host's planner picks this table's chart. */
79
+ readonly smart: boolean;
80
+ /** `undefined` until drawn (or judged chartless). */
81
+ chart?: TableChart | null;
82
+ pending?: Promise<void>;
83
+ }
84
+
85
+ let chartMode: TableChartMode = "off";
86
+ let chartPlanner: TableChartPlanner | undefined;
87
+ const charts = new Map<string, ChartEntry>();
88
+ /** The theme-resolved native blob last registered for a chart. */
89
+ const kNativeBlob = Symbol("tableChart.nativeBlob");
90
+
91
+ interface NativeTagged extends TableChart {
92
+ [kNativeBlob]?: { epoch: number; blob: string };
93
+ }
94
+
95
+ /** Set how tables become charts (the host's `tui.autoGraph`) and its `smart` planner; the host rebuilds the transcript after. */
96
+ export function setTableCharts(mode: TableChartMode, planner?: TableChartPlanner): void {
97
+ chartMode = mode;
98
+ chartPlanner = planner;
99
+ charts.clear();
100
+ }
101
+
102
+ /** How assistant tables currently become charts. */
103
+ export function tableChartMode(): TableChartMode {
104
+ return chartMode;
105
+ }
106
+
107
+ /** Whether `markdown` may hold a table {@link splitTableCharts} would chart. */
108
+ export function hasChartTable(markdown: string): boolean {
109
+ return chartMode !== "off" && markdown.includes("|") && DELIMITER_ROW.test(markdown);
110
+ }
111
+
112
+ /**
113
+ * Split `markdown` after each top-level table that has (or may get) a chart.
114
+ * A table still streaming at the block's tail is left whole: rows may follow.
115
+ */
116
+ export function splitTableCharts(markdown: string, streaming: boolean): ChartSegment[] {
117
+ if (chartMode === "off") return [{ kind: "markdown", text: markdown }];
118
+ const tokens = lexDocument(markdown);
119
+ const segments: ChartSegment[] = [];
120
+ let prose = "";
121
+ tokens.forEach((token, index) => {
122
+ prose += token.raw;
123
+ if (!isTable(token)) return;
124
+ const closed = !streaming || tokens.slice(index + 1).some(next => next.type !== "space");
125
+ const entry = closed ? chartEntry(token) : undefined;
126
+ if (!entry?.guess || entry.chart === null) return;
127
+ segments.push({ kind: "markdown", text: prose }, { kind: "chart", table: token });
128
+ prose = "";
129
+ });
130
+ if (prose.trim() || segments.length === 0) segments.push({ kind: "markdown", text: prose });
131
+ return segments;
132
+ }
133
+
134
+ function isTable(token: Token): token is Tokens.Table {
135
+ return token.type === "table";
136
+ }
137
+
138
+ /**
139
+ * The chart for `table` under the current mode, read once per table source.
140
+ * Under `smart` the first lookup of a multi-series table asks the planner.
141
+ */
142
+ export function lookupTableChart(table: Tokens.Table): ChartLookup {
143
+ if (chartMode === "off") return null;
144
+ const entry = chartEntry(table);
145
+ if (entry.chart !== undefined) return entry.chart;
146
+ if (entry.pending) return entry.pending;
147
+ const { analysis, guess } = entry;
148
+ entry.pending = chartPlanner!({ markdown: table.raw, table: analysis, guess: guess! }).then(
149
+ plan => {
150
+ entry.chart = plan ? drawChart(analysis, plan) : null;
151
+ },
152
+ (error: unknown) => {
153
+ logger.debug("Smart table chart failed; drawing the local guess", { error: String(error) });
154
+ entry.chart = drawChart(analysis, guess!, true);
155
+ },
156
+ );
157
+ return entry.pending;
158
+ }
159
+
160
+ /**
161
+ * `table` read under the current mode, cached per source. A table the local
162
+ * guess decides is drawn at once; a smart pick waits for its first lookup.
163
+ */
164
+ function chartEntry(table: Tokens.Table): ChartEntry {
165
+ const key = table.raw;
166
+ const cached = charts.get(key);
167
+ if (cached) {
168
+ // Re-insert so eviction drops the least recently read table.
169
+ charts.delete(key);
170
+ charts.set(key, cached);
171
+ return cached;
172
+ }
173
+ if (charts.size >= CACHE_LIMIT) charts.delete(charts.keys().next().value!);
174
+ const analysis = analyzeTable(
175
+ table.header.map(cell => cell.text),
176
+ table.rows.map(row => row.map(cell => cell.text)),
177
+ );
178
+ 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;
185
+ const entry: ChartEntry = { analysis, guess, smart };
186
+ if (!smart) entry.chart = guess ? drawChart(analysis, guess, true) : null;
187
+ charts.set(key, entry);
188
+ return entry;
189
+ }
190
+
191
+ /**
192
+ * Draw `plan`. A guess must also pass {@link worthCharting}; a model's pick
193
+ * already judged the chart worth drawing.
194
+ */
195
+ function drawChart(analysis: TableAnalysis, plan: ChartPlan, guessed = false): TableChart | null {
196
+ const spec = buildChart(analysis, plan);
197
+ if (!spec || (guessed && !worthCharting(spec))) return null;
198
+ return { ...renderChartSvg(spec), alt: chartAlt(spec) };
199
+ }
200
+
201
+ /**
202
+ * A native `image` node drawing `chart` from its SVG — no raster — resolved
203
+ * against the active theme; rebuilt when the theme changes.
204
+ */
205
+ export function describeTableChart(chart: TableChart, key: string): NativeNode {
206
+ const epoch = getThemeEpoch();
207
+ const tagged: NativeTagged = chart;
208
+ let entry = tagged[kNativeBlob];
209
+ if (entry?.epoch !== epoch) {
210
+ const svg = prepareSvg(chart.svg, svgFigurePalette());
211
+ entry = { epoch, blob: registerNativeBlob(new TextEncoder().encode(svg), "image/svg+xml") };
212
+ tagged[kNativeBlob] = entry;
213
+ }
214
+ return node(
215
+ "image",
216
+ {
217
+ blob: entry.blob,
218
+ alt: chart.alt,
219
+ w: chart.width,
220
+ h: chart.height,
221
+ max: { w: `${Math.round(chart.width / UNITS_PER_COLUMN)}ch` },
222
+ },
223
+ undefined,
224
+ key,
225
+ );
226
+ }
227
+
228
+ export interface TableChartFigureOptions {
229
+ /** Shared inline-image budget. */
230
+ budget?: ImageBudget;
231
+ /** The chart's rows changed outside a text update: its pick or raster landed. */
232
+ onChange: () => void;
233
+ }
234
+
235
+ /**
236
+ * The chart under one table, as a terminal image a blank row below it. Looks
237
+ * the chart up on first render — a block rebuilt mid-stream never asks for a
238
+ * pick it drops — and renders nothing until it is drawn, or when the table
239
+ * gets no chart.
240
+ */
241
+ export class TableChartFigure implements Component {
242
+ readonly #options: TableChartFigureOptions;
243
+ readonly #figure: SvgFigure;
244
+ #table: Tokens.Table | undefined;
245
+ /** `undefined` while not looked up or waiting for a pick. */
246
+ #chart: TableChart | null | undefined;
247
+ #waiting = false;
248
+ #disposed = false;
249
+
250
+ constructor(options: TableChartFigureOptions) {
251
+ this.#options = options;
252
+ this.#figure = new SvgFigure({ budget: options.budget, onChange: options.onChange });
253
+ }
254
+
255
+ /** Point the figure at `table`. */
256
+ update(table: Tokens.Table): void {
257
+ if (table.raw === this.#table?.raw) return;
258
+ this.#table = table;
259
+ this.#chart = undefined;
260
+ this.#waiting = false;
261
+ }
262
+
263
+ /** Whether the chart is still being looked up, picked or drawn. */
264
+ get pending(): boolean {
265
+ return this.#table !== undefined && (this.#chart === undefined || (this.#chart !== null && this.#figure.pending));
266
+ }
267
+
268
+ render(width: number): readonly string[] {
269
+ if (this.#chart === undefined && !this.#waiting) this.#resolve();
270
+ if (!this.#chart) return [];
271
+ const rows = this.#figure.render(width);
272
+ return rows.length ? ["", ...rows] : rows;
273
+ }
274
+
275
+ invalidate(): void {
276
+ this.#figure.invalidate();
277
+ }
278
+
279
+ dispose(): void {
280
+ this.#disposed = true;
281
+ this.#figure.dispose();
282
+ }
283
+
284
+ #resolve(): void {
285
+ const table = this.#table;
286
+ if (!table) return;
287
+ const found = lookupTableChart(table);
288
+ if (found instanceof Promise) {
289
+ this.#waiting = true;
290
+ void found.then(() => {
291
+ if (this.#disposed || this.#table !== table) return;
292
+ this.#waiting = false;
293
+ this.#resolve();
294
+ this.#options.onChange();
295
+ });
296
+ return;
297
+ }
298
+ this.#chart = found;
299
+ if (found) this.#figure.update(found.svg, true);
300
+ }
301
+ }
@@ -48,6 +48,7 @@ import {
48
48
  import type { XdevMountedState } from "../tools/xdev";
49
49
  import { isFramedBlockComponent, markFramedBlockComponent, renderStatusLine, WidthAwareText } from "../render/index";
50
50
  import { cachedPngConversion, convertImageToPngShared, imagePayloadKey } from "./image-loading";
51
+ import { FenceFigure } from "./fence-figure";
51
52
  import { sanitizeWithOptionalSixelPassthrough } from "../render/sixel";
52
53
  import { renderDiff } from "../chrome/diff";
53
54
  import { type AnimationFrame, trimBlankEdges } from "../chrome/transcript-container";
@@ -301,6 +302,8 @@ export class ToolExecutionComponent extends Container {
301
302
  #multiFileBoxes: (Box | Spacer)[] = []; // Extra boxes for multi-file edit results
302
303
  #imageComponents: Image[] = [];
303
304
  #imageSpacers: Spacer[] = [];
305
+ /** The renderer's {@link ToolRenderer.figure} drawing; kept across rebuilds while its language is unchanged, so it redraws in place and its raster survives them. */
306
+ #figure: FenceFigure | undefined;
304
307
  readonly #instanceId = ++toolExecutionInstanceSeq;
305
308
  #toolName: string;
306
309
  #toolLabel: string;
@@ -759,6 +762,11 @@ export class ToolExecutionComponent extends Container {
759
762
  }
760
763
  }
761
764
 
765
+ /** Whether the result's figure still waits for its raster; the transcript holds retirement meanwhile. */
766
+ isTranscriptBlockPending(): boolean {
767
+ return this.#toolActivityVisible && this.#figure?.pending === true;
768
+ }
769
+
762
770
  /**
763
771
  * Whether this block is ready to retire as immutable history. Partial
764
772
  * results, including detached background tasks, remain active and mutable
@@ -941,11 +949,13 @@ export class ToolExecutionComponent extends Container {
941
949
 
942
950
  /**
943
951
  * The native `collapsed` prop: the transcript's expand state, except that a
944
- * call streaming its body (edit, write) stays open until it settles, then
952
+ * view that asks to be {@link NativeToolView.open} never starts folded, and
953
+ * a call streaming its body (edit, write) stays open until it settles, then
945
954
  * folds like a finished thought. The user's own toggle still wins meanwhile:
946
955
  * the terminal keeps local collapse state until this prop changes.
947
956
  */
948
- #nativeCollapsed(status: TspCardStatus): boolean {
957
+ #nativeCollapsed(status: TspCardStatus, view: NativeToolView): boolean {
958
+ if (view.open) return false;
949
959
  const live = status === "pending" || status === "running";
950
960
  return !this.#expanded && !(live && streamsBody(this.#toolName));
951
961
  }
@@ -1008,7 +1018,7 @@ export class ToolExecutionComponent extends Container {
1008
1018
  intent: typeof intent === "string" && intent ? plainText(intent) : undefined,
1009
1019
  frame: inline ? "inline" : "card",
1010
1020
  collapsible: hasBody,
1011
- collapsed: hasBody ? this.#nativeCollapsed(status) : undefined,
1021
+ collapsed: hasBody ? this.#nativeCollapsed(status, view) : undefined,
1012
1022
  preview: hasBody ? (preview === "auto" ? { lines: DEFAULT_TERMINAL_PREVIEW_LINES } : preview) : undefined,
1013
1023
  tools: view.tools,
1014
1024
  tone: view.tone,
@@ -1076,7 +1086,7 @@ export class ToolExecutionComponent extends Container {
1076
1086
  tone: view.tone ?? NATIVE_STATUS_TONE[status],
1077
1087
  status,
1078
1088
  collapsible: hasBody,
1079
- collapsed: hasBody ? this.#nativeCollapsed(status) : undefined,
1089
+ collapsed: hasBody ? this.#nativeCollapsed(status, view) : undefined,
1080
1090
  preview: hasBody ? cardPreview(view.preview) : undefined,
1081
1091
  },
1082
1092
  children,
@@ -1132,6 +1142,7 @@ export class ToolExecutionComponent extends Container {
1132
1142
  body: [...(callView.body ?? []), ...(resultView.body ?? [])],
1133
1143
  tone: resultView.tone ?? callView.tone,
1134
1144
  preview: resultView.preview ?? callView.preview,
1145
+ open: resultView.open ?? callView.open,
1135
1146
  inline: resultView.inline ?? callView.inline,
1136
1147
  tools: resultView.tools ?? callView.tools,
1137
1148
  };
@@ -1611,6 +1622,7 @@ export class ToolExecutionComponent extends Container {
1611
1622
  this.removeChild(spacer);
1612
1623
  }
1613
1624
  this.#imageSpacers = [];
1625
+ this.#syncFigure();
1614
1626
 
1615
1627
  if (this.#result) {
1616
1628
  const imageBlocks = this.#getAllImageBlocks();
@@ -1654,6 +1666,43 @@ export class ToolExecutionComponent extends Container {
1654
1666
  this.#renderedImageCount = this.#imageComponents.length;
1655
1667
  }
1656
1668
 
1669
+ /**
1670
+ * Mount the built-in renderer's figure under the card and feed it the fence
1671
+ * as it stands: the mounted one stays while its language is unchanged, so it
1672
+ * redraws in place as the args stream.
1673
+ */
1674
+ #syncFigure(): void {
1675
+ const result = this.#result;
1676
+ const renderer = this.#tool?.renderCall || this.#tool?.renderResult ? undefined : this.#renderer;
1677
+ const fence =
1678
+ this.#isBenignSkip() || isNativeRendering()
1679
+ ? undefined
1680
+ : renderer?.figure?.(
1681
+ this.#args,
1682
+ result && { content: result.content, details: result.details, isError: result.isError },
1683
+ this.#renderState,
1684
+ );
1685
+ const drawable = fence !== undefined && FenceFigure.draws(fence, { showImages: this.#showImages });
1686
+ let figure = this.#figure;
1687
+ if (figure && (!drawable || figure.lang !== fence.lang)) {
1688
+ this.removeChild(figure);
1689
+ figure.dispose();
1690
+ figure = this.#figure = undefined;
1691
+ }
1692
+ if (!drawable) return;
1693
+ if (!figure) {
1694
+ figure = this.#figure = new FenceFigure(fence.lang, {
1695
+ budget: this.#ui.imageBudget,
1696
+ onChange: () => {
1697
+ this.#blockVersion++;
1698
+ this.#ui.requestRender();
1699
+ },
1700
+ });
1701
+ this.addChild(figure);
1702
+ }
1703
+ figure.update(fence);
1704
+ }
1705
+
1657
1706
  #getCallArgsForRender(): unknown {
1658
1707
  const renderArgs = this.#args;
1659
1708
  if (!isEditLikeToolName(this.#toolName)) {
@@ -57,6 +57,12 @@ export interface AppendOnlyTranscriptBlock {
57
57
 
58
58
  interface FinalizableBlock {
59
59
  isTranscriptBlockFinalized?(): boolean;
60
+ /**
61
+ * A finalized block whose rows still wait on async work (an SVG figure's
62
+ * raster). Retirement holds until it lands: committed rows can never be
63
+ * repainted, so retiring early would freeze a placeholder into scrollback.
64
+ */
65
+ isTranscriptBlockPending?(): boolean;
60
66
  /** Render the row that must remain represented under emergency viewport pressure. */
61
67
  renderTranscriptBlockEmergencyRow?(width: number): string | undefined;
62
68
  }
@@ -121,7 +127,7 @@ const EMPTY_STABLE_ROWS: readonly TranscriptStableRow[] = [];
121
127
 
122
128
  function isFinalized(component: Component): boolean {
123
129
  const block = component as Component & FinalizableBlock;
124
- return block.isTranscriptBlockFinalized?.() ?? true;
130
+ return (block.isTranscriptBlockFinalized?.() ?? true) && block.isTranscriptBlockPending?.() !== true;
125
131
  }
126
132
 
127
133
  function blockMode(component: Component): TranscriptBlockMode {