@oh-my-pi/pi-tui 18.6.1 → 18.7.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.
- package/CHANGELOG.md +50 -58
- package/README.md +6 -2
- package/dist/types/app-keybindings.d.ts +7 -2
- package/dist/types/autocomplete.d.ts +5 -2
- package/dist/types/charts/chart-plan.d.ts +92 -0
- package/dist/types/charts/chart-svg.d.ts +30 -0
- package/dist/types/charts/table-data.d.ts +107 -0
- package/dist/types/chat/assistant-message.d.ts +10 -1
- package/dist/types/chat/chat-transcript-builder.d.ts +3 -0
- package/dist/types/chat/figure-markdown.d.ts +42 -0
- package/dist/types/chat/svg-figure.d.ts +33 -0
- package/dist/types/chat/svg-source.d.ts +49 -0
- package/dist/types/chat/table-chart.d.ts +88 -0
- package/dist/types/chat/user-message.d.ts +2 -2
- package/dist/types/chrome/status-notice.d.ts +15 -3
- package/dist/types/components/editor.d.ts +5 -1
- package/dist/types/components/image.d.ts +23 -0
- package/dist/types/components/input.d.ts +1 -0
- package/dist/types/components/loader.d.ts +5 -6
- package/dist/types/components/markdown.d.ts +9 -0
- package/dist/types/fuzzy.d.ts +14 -0
- package/dist/types/key-hint-format.d.ts +8 -0
- package/dist/types/keybindings.d.ts +1 -1
- package/dist/types/native/backend.d.ts +2 -2
- package/dist/types/native/node.d.ts +6 -0
- package/dist/types/native/overlay.d.ts +3 -3
- package/dist/types/overlays/agent-hub.d.ts +1 -0
- package/dist/types/overlays/agent-transcript-viewer.d.ts +1 -0
- package/dist/types/overlays/agents-hub.d.ts +9 -0
- package/dist/types/overlays/annotation-overlay.d.ts +5 -2
- package/dist/types/overlays/btw-history-panel.d.ts +5 -1
- package/dist/types/overlays/copy-selector.d.ts +1 -0
- package/dist/types/overlays/model-browser.d.ts +25 -3
- package/dist/types/overlays/plan-review-overlay.d.ts +3 -2
- package/dist/types/overlays/rewind-selector.d.ts +1 -0
- package/dist/types/overlays/usage-dashboard.d.ts +4 -4
- package/dist/types/prompt/custom-editor.d.ts +10 -4
- package/dist/types/prompt/interactive-context-helpers.d.ts +3 -0
- package/dist/types/prompt/model-mention-autocomplete.d.ts +1 -1
- package/dist/types/render/composite.d.ts +2 -0
- package/dist/types/space-hold.d.ts +40 -25
- package/dist/types/terminal-capabilities.d.ts +13 -0
- package/dist/types/tools/glob.d.ts +4 -0
- package/dist/types/tui.d.ts +5 -0
- package/dist/types/utils.d.ts +6 -0
- package/package.json +9 -9
- package/src/app-keybindings.ts +6 -1
- package/src/apps/git/diff-pane.ts +42 -16
- package/src/apps/git/git-tui.ts +9 -9
- package/src/apps/git/sidebar.ts +6 -1
- package/src/autocomplete.ts +8 -10
- package/src/charts/chart-plan.ts +367 -0
- package/src/charts/chart-svg.ts +693 -0
- package/src/charts/table-data.ts +436 -0
- package/src/chat/assistant-message.ts +165 -25
- package/src/chat/chat-transcript-builder.ts +8 -0
- package/src/chat/figure-markdown.ts +174 -0
- package/src/chat/svg-figure.ts +364 -0
- package/src/chat/svg-source.ts +188 -0
- package/src/chat/table-chart.ts +301 -0
- package/src/chat/tool-execution.ts +6 -1
- package/src/chat/user-message.ts +16 -5
- package/src/chrome/status-notice.ts +25 -7
- package/src/chrome/transcript-container.ts +13 -4
- package/src/components/editor.ts +66 -30
- package/src/components/image.ts +95 -2
- package/src/components/input.ts +14 -6
- package/src/components/loader.ts +10 -17
- package/src/components/markdown.ts +6 -3
- package/src/fuzzy.ts +59 -19
- package/src/hotkeys-markdown.ts +9 -2
- package/src/key-hint-format.ts +25 -10
- package/src/keybindings.ts +1 -1
- package/src/native/backend.ts +10 -3
- package/src/native/node.ts +6 -0
- package/src/native/overlay.ts +4 -4
- package/src/overlays/agent-hub.ts +4 -0
- package/src/overlays/agent-transcript-viewer.ts +4 -0
- package/src/overlays/agents-hub.ts +14 -1
- package/src/overlays/annotation-overlay.ts +179 -80
- package/src/overlays/ask-dialog.ts +1 -1
- package/src/overlays/btw-history-panel.ts +9 -2
- package/src/overlays/copy-selector.ts +2 -0
- package/src/overlays/extensions/extension-dashboard.ts +4 -4
- package/src/overlays/model-browser.ts +169 -76
- package/src/overlays/pause-screen.ts +2 -2
- package/src/overlays/plan-review-overlay.ts +41 -4
- package/src/overlays/rewind-selector.ts +2 -0
- package/src/overlays/usage-dashboard.ts +17 -8
- package/src/overlays/usage-row.ts +22 -8
- package/src/prompt/composer.ts +2 -14
- package/src/prompt/custom-editor.ts +188 -67
- package/src/prompt/interactive-context-helpers.ts +5 -0
- package/src/prompt/model-mention-autocomplete.ts +14 -14
- package/src/prompt/queued-messages.ts +6 -4
- package/src/render/composite.ts +62 -0
- package/src/space-hold.ts +156 -52
- package/src/status-line/segments.ts +3 -1
- package/src/terminal-capabilities.ts +42 -23
- package/src/tools/glob.ts +23 -6
- package/src/tui.ts +154 -119
- 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
|
+
}
|
|
@@ -1639,7 +1639,12 @@ export class ToolExecutionComponent extends Container {
|
|
|
1639
1639
|
imageData,
|
|
1640
1640
|
imageMimeType,
|
|
1641
1641
|
{ fallbackColor: (s: string) => theme.fg("toolOutput", s) },
|
|
1642
|
-
{
|
|
1642
|
+
{
|
|
1643
|
+
...resolveImageOptions(),
|
|
1644
|
+
budget: this.#ui.imageBudget,
|
|
1645
|
+
imageKey: `te${this.#instanceId}:${i}`,
|
|
1646
|
+
requestRender: () => this.#ui.requestRender(),
|
|
1647
|
+
},
|
|
1643
1648
|
);
|
|
1644
1649
|
this.#imageComponents.push(imageComponent);
|
|
1645
1650
|
this.addChild(imageComponent);
|
package/src/chat/user-message.ts
CHANGED
|
@@ -24,7 +24,13 @@ import type { ReactionTarget } from "./reaction";
|
|
|
24
24
|
import { card, md, node, row, span, text } from "../native/describe";
|
|
25
25
|
import { base64ImageNode } from "../native/blobs";
|
|
26
26
|
import { hasTranscriptActions, runTranscriptAction } from "./transcript-actions";
|
|
27
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
type DescribeContext,
|
|
29
|
+
type NativeChild,
|
|
30
|
+
type NativeNode,
|
|
31
|
+
type NativeUiEvent,
|
|
32
|
+
rootToggleExpanded,
|
|
33
|
+
} from "../native/node";
|
|
28
34
|
import { Memo } from "../native/memo";
|
|
29
35
|
|
|
30
36
|
// OSC 133 shell integration: marks prompt zones for terminal multiplexers.
|
|
@@ -137,6 +143,8 @@ export class UserMessageComponent extends Container implements ReactionTarget {
|
|
|
137
143
|
readonly #tokens: RegExp;
|
|
138
144
|
#reaction: string | undefined;
|
|
139
145
|
#native: NativeNode | undefined;
|
|
146
|
+
/** The terminal's clock {@link #native} was described with. */
|
|
147
|
+
#nativeHour12: boolean | undefined;
|
|
140
148
|
|
|
141
149
|
constructor(text: string, options: UserBubbleOptions = {}) {
|
|
142
150
|
super();
|
|
@@ -184,17 +192,20 @@ export class UserMessageComponent extends Container implements ReactionTarget {
|
|
|
184
192
|
* agent's reaction are chips at the bottom-right, so a reaction landing
|
|
185
193
|
* later updates the frame in place, even deep in scrollback.
|
|
186
194
|
*/
|
|
187
|
-
override describe(): NativeNode {
|
|
188
|
-
|
|
195
|
+
override describe(cx?: DescribeContext): NativeNode {
|
|
196
|
+
// The terminal's clock: Bun's own default locale ignores the user's.
|
|
197
|
+
const hour12 = cx?.hour12;
|
|
198
|
+
if (this.#native && this.#nativeHour12 === hour12) return this.#native;
|
|
199
|
+
this.#nativeHour12 = hour12;
|
|
189
200
|
const children: NativeChild[] = [];
|
|
190
201
|
if (!this.#synthetic && hasTranscriptActions()) {
|
|
191
202
|
const tools: NativeChild[] = [];
|
|
192
203
|
if (this.#timestamp !== undefined) {
|
|
193
204
|
const at = new Date(this.#timestamp);
|
|
194
205
|
tools.push(
|
|
195
|
-
text([span(at.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }), "dim mono")], {
|
|
206
|
+
text([span(at.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", hour12 }), "dim mono")], {
|
|
196
207
|
role: "omp.user.time",
|
|
197
|
-
title: at.toLocaleString(),
|
|
208
|
+
title: at.toLocaleString([], { hour12 }),
|
|
198
209
|
}),
|
|
199
210
|
);
|
|
200
211
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Spacer } from "../components/spacer";
|
|
2
2
|
import { Text } from "../components/text";
|
|
3
|
-
import { node } from "../native/describe";
|
|
3
|
+
import { EMPTY_NODE, node } from "../native/describe";
|
|
4
4
|
import type { NativeNode } from "../native/node";
|
|
5
5
|
import { styledSpans } from "../native/spans";
|
|
6
6
|
import { Container } from "../tui";
|
|
@@ -8,33 +8,51 @@ import { Container } from "../tui";
|
|
|
8
8
|
/** How long a native status toast stays up (ms). */
|
|
9
9
|
const TOAST_TTL = 2400;
|
|
10
10
|
|
|
11
|
+
/** How a {@link StatusNotice} shows. */
|
|
12
|
+
export interface StatusNoticeOptions {
|
|
13
|
+
/** Styles the ANSI line; resolved at render so a theme change re-shapes it. */
|
|
14
|
+
styleFn?: (text: string) => string;
|
|
15
|
+
/**
|
|
16
|
+
* Whether a native terminal toasts it (default). False keeps the notice to
|
|
17
|
+
* the ANSI transcript: background chatter such as MCP connection progress,
|
|
18
|
+
* which would otherwise re-toast on every server that connects or fails.
|
|
19
|
+
*/
|
|
20
|
+
toast?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
11
23
|
/**
|
|
12
24
|
* A transient status notice (`showStatus`: "Thinking blocks: hidden", "Copied
|
|
13
25
|
* to clipboard"). The ANSI render appends a blank row and the dim line to the
|
|
14
26
|
* transcript; a native terminal shows it as a toast instead, so notices never
|
|
15
|
-
* pile up in the history. Updating the text re-shows the toast
|
|
27
|
+
* pile up in the history. Updating the text re-shows the toast; a notice
|
|
28
|
+
* with `toast: false` describes nothing natively.
|
|
16
29
|
*/
|
|
17
30
|
export class StatusNotice extends Container {
|
|
18
31
|
readonly #text: Text;
|
|
19
32
|
#message: string;
|
|
33
|
+
#toast: boolean;
|
|
20
34
|
#native: NativeNode | undefined;
|
|
21
35
|
|
|
22
|
-
constructor(message: string,
|
|
36
|
+
constructor(message: string, options: StatusNoticeOptions = {}) {
|
|
23
37
|
super();
|
|
24
38
|
this.#message = message;
|
|
25
|
-
this.#
|
|
39
|
+
this.#toast = options.toast ?? true;
|
|
40
|
+
this.#text = new Text(message, 1, 0).setStyleFn(options.styleFn);
|
|
26
41
|
this.addChild(new Spacer(1));
|
|
27
42
|
this.addChild(this.#text);
|
|
28
43
|
}
|
|
29
44
|
|
|
30
|
-
setMessage(message: string,
|
|
31
|
-
|
|
45
|
+
setMessage(message: string, options: StatusNoticeOptions = {}): void {
|
|
46
|
+
const toast = options.toast ?? true;
|
|
47
|
+
this.#text.setStyleFn(options.styleFn);
|
|
32
48
|
this.#text.setText(message);
|
|
33
|
-
if (message !== this.#message) this.#native = undefined;
|
|
49
|
+
if (message !== this.#message || toast !== this.#toast) this.#native = undefined;
|
|
34
50
|
this.#message = message;
|
|
51
|
+
this.#toast = toast;
|
|
35
52
|
}
|
|
36
53
|
|
|
37
54
|
override describe(): NativeNode {
|
|
55
|
+
if (!this.#toast) return EMPTY_NODE;
|
|
38
56
|
if (this.#native) return this.#native;
|
|
39
57
|
// Callers may pass pre-styled text; a toast takes plain text.
|
|
40
58
|
const plain = styledSpans(this.#message)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type Component, Container, type HistoryBatch } from "../tui";
|
|
2
2
|
import * as logger from "@oh-my-pi/pi-utils/logger";
|
|
3
3
|
import { popLoopPhase, pushLoopPhase } from "@oh-my-pi/pi-utils";
|
|
4
|
+
import { renderForScrollback } from "../components/image";
|
|
4
5
|
import { col } from "../native/describe";
|
|
5
6
|
import type { NativeNode } from "../native/node";
|
|
6
7
|
import { isNativeSettled, settleNative } from "../native/settle";
|
|
@@ -56,6 +57,12 @@ export interface AppendOnlyTranscriptBlock {
|
|
|
56
57
|
|
|
57
58
|
interface FinalizableBlock {
|
|
58
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;
|
|
59
66
|
/** Render the row that must remain represented under emergency viewport pressure. */
|
|
60
67
|
renderTranscriptBlockEmergencyRow?(width: number): string | undefined;
|
|
61
68
|
}
|
|
@@ -120,7 +127,7 @@ const EMPTY_STABLE_ROWS: readonly TranscriptStableRow[] = [];
|
|
|
120
127
|
|
|
121
128
|
function isFinalized(component: Component): boolean {
|
|
122
129
|
const block = component as Component & FinalizableBlock;
|
|
123
|
-
return block.isTranscriptBlockFinalized?.() ?? true;
|
|
130
|
+
return (block.isTranscriptBlockFinalized?.() ?? true) && block.isTranscriptBlockPending?.() !== true;
|
|
124
131
|
}
|
|
125
132
|
|
|
126
133
|
function blockMode(component: Component): TranscriptBlockMode {
|
|
@@ -1000,9 +1007,11 @@ export class TranscriptContainer extends Container {
|
|
|
1000
1007
|
// Only the range head is sliced by its emitted stable prefix; every other
|
|
1001
1008
|
// entry renders whole, so the append-only verification pass (a second
|
|
1002
1009
|
// full render of the block's stable prefix) is skipped for them. This
|
|
1003
|
-
// keeps a complete-ledger replay at one render per block.
|
|
1004
|
-
|
|
1005
|
-
|
|
1010
|
+
// keeps a complete-ledger replay at one render per block. These rows go
|
|
1011
|
+
// to native scrollback, where nothing can repaint them.
|
|
1012
|
+
const rendered = renderForScrollback(() =>
|
|
1013
|
+
index === start ? this.#renderEntry(entry, width) : trimBlankEdges(entry.component.render(width)),
|
|
1014
|
+
);
|
|
1006
1015
|
const emittedRows = index === start ? this.#renderStablePrefix(entry, entry.emitted, width).length : 0;
|
|
1007
1016
|
const block = rendered.slice(emittedRows);
|
|
1008
1017
|
reached = index + 1;
|