@oh-my-pi/pi-tui 18.8.7 → 18.8.9
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 +52 -86
- package/dist/types/charts/chart-plan.d.ts +11 -5
- package/dist/types/charts/chart-svg.d.ts +11 -7
- package/dist/types/charts/table-data.d.ts +6 -1
- package/dist/types/chat/execution-shared.d.ts +6 -5
- package/dist/types/keybinding-matchers.d.ts +3 -0
- package/dist/types/kitty-graphics.d.ts +2 -2
- package/dist/types/multiplexers/cmux.d.ts +16 -0
- package/dist/types/multiplexers/herdr.d.ts +26 -0
- package/dist/types/multiplexers/notify.d.ts +13 -0
- package/dist/types/multiplexers/orca.d.ts +12 -0
- package/dist/types/multiplexers/screen.d.ts +9 -0
- package/dist/types/multiplexers/tmux.d.ts +29 -0
- package/dist/types/multiplexers/types.d.ts +100 -0
- package/dist/types/multiplexers/wmux.d.ts +12 -0
- package/dist/types/multiplexers/zellij.d.ts +12 -0
- package/dist/types/overlays/annotation-overlay.d.ts +12 -0
- package/dist/types/overlays/annotation-types.d.ts +2 -0
- package/dist/types/overlays/hook-selector.d.ts +9 -4
- package/dist/types/overlays/model-browser.d.ts +2 -2
- package/dist/types/overlays/model-hub.d.ts +21 -4
- package/dist/types/overlays/session-observer-registry.d.ts +2 -0
- package/dist/types/overlays/usage-dashboard.d.ts +3 -1
- package/dist/types/status-line/types.d.ts +3 -3
- package/dist/types/terminal-capabilities.d.ts +24 -32
- package/dist/types/terminal-multiplexer.d.ts +127 -14
- package/dist/types/terminal.d.ts +5 -4
- package/dist/types/theme/symbols.d.ts +1 -1
- package/dist/types/tmux.d.ts +1 -4
- package/dist/types/tools/eval.d.ts +1 -1
- package/dist/types/tools/native-view.d.ts +47 -0
- package/dist/types/tools/renderer.d.ts +15 -2
- package/dist/types/tui.d.ts +20 -0
- package/dist/types/vim.d.ts +19 -5
- package/package.json +9 -9
- package/src/charts/chart-plan.ts +152 -12
- package/src/charts/chart-svg.ts +479 -126
- package/src/charts/table-data.ts +43 -8
- package/src/chat/execution-shared.ts +42 -25
- package/src/chat/svg-figure.ts +45 -8
- package/src/chat/tool-execution.ts +9 -2
- package/src/components/editor.ts +182 -5
- package/src/keybinding-matchers.ts +6 -2
- package/src/kitty-graphics.ts +4 -4
- package/src/multiplexers/cmux.ts +29 -0
- package/src/multiplexers/herdr.ts +64 -0
- package/src/multiplexers/notify.ts +24 -0
- package/src/multiplexers/orca.ts +16 -0
- package/src/multiplexers/screen.ts +15 -0
- package/src/multiplexers/tmux.ts +40 -0
- package/src/multiplexers/types.ts +110 -0
- package/src/multiplexers/wmux.ts +16 -0
- package/src/multiplexers/zellij.ts +24 -0
- package/src/overlays/agent-hub.ts +7 -3
- package/src/overlays/annotation-overlay.ts +87 -6
- package/src/overlays/annotation-types.ts +2 -0
- package/src/overlays/hook-selector.ts +12 -5
- package/src/overlays/model-browser.ts +3 -3
- package/src/overlays/model-hub.ts +107 -27
- package/src/overlays/session-observer-registry.ts +10 -2
- package/src/overlays/usage-dashboard.ts +70 -23
- package/src/prompt/composer.ts +1 -0
- package/src/status-line/component.ts +12 -8
- package/src/status-line/segments.ts +10 -11
- package/src/status-line/types.ts +3 -3
- package/src/terminal-capabilities.ts +65 -181
- package/src/terminal-multiplexer.ts +112 -33
- package/src/terminal.ts +34 -28
- package/src/theme/session-color.ts +1 -7
- package/src/theme/symbols.ts +5 -0
- package/src/theme/theme.ts +7 -4
- package/src/tmux.ts +4 -11
- package/src/tools/bash.ts +82 -31
- package/src/tools/eval.ts +149 -123
- package/src/tools/native-view.ts +102 -1
- package/src/tools/renderer.ts +15 -2
- package/src/tui.ts +86 -12
- package/src/vim.ts +333 -18
package/src/charts/table-data.ts
CHANGED
|
@@ -45,7 +45,10 @@ export interface NumberCell {
|
|
|
45
45
|
readonly toFigure?: string;
|
|
46
46
|
/** `a–b`: `b`, in the same base units. */
|
|
47
47
|
readonly upper?: number;
|
|
48
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* `a/b`: `b`. {@link analyzeTable} reads a score (`12/12`, `154/160`) as the
|
|
50
|
+
* percent of `b` reached; a pair (`85 / 147` under `Edit / read calls`) keeps `a`.
|
|
51
|
+
*/
|
|
49
52
|
readonly denominator?: number;
|
|
50
53
|
}
|
|
51
54
|
|
|
@@ -77,6 +80,8 @@ export interface TableColumn {
|
|
|
77
80
|
readonly unit: string;
|
|
78
81
|
/** Numeric cells disagree on dimension (a metric-per-row table). */
|
|
79
82
|
readonly mixed: boolean;
|
|
83
|
+
/** Numeric cells are mostly scores out of a total (`12/12`), read as percent of it. */
|
|
84
|
+
readonly scores: boolean;
|
|
80
85
|
/** Every numeric data cell holds the same value: an echoed setting, not a measure. */
|
|
81
86
|
readonly constant: boolean;
|
|
82
87
|
/** Share of numeric cells written with an explicit sign. */
|
|
@@ -220,7 +225,7 @@ export function parseCell(markdown: string): Cell {
|
|
|
220
225
|
const text = plain.text.replace(MARKS, "").replace(/\s+/g, " ").trim();
|
|
221
226
|
const emphasis = plain.emphasis;
|
|
222
227
|
const other = (kind: OtherCell["kind"]): OtherCell => ({ kind, text: plain.text, emphasis });
|
|
223
|
-
if (MISSING
|
|
228
|
+
if (Object.hasOwn(MISSING, text.toLowerCase())) return other("missing");
|
|
224
229
|
if (DATE.test(text)) return other("date");
|
|
225
230
|
if (TIME.test(text)) return other("time");
|
|
226
231
|
if (VERSION.test(text)) return other("version");
|
|
@@ -257,7 +262,7 @@ export function parseCell(markdown: string): Cell {
|
|
|
257
262
|
let dim: Dimension = groups.cur ? "currency" : "count";
|
|
258
263
|
let factor = 1;
|
|
259
264
|
if (unit) {
|
|
260
|
-
const known =
|
|
265
|
+
const known = knownUnit(unit);
|
|
261
266
|
if (known) {
|
|
262
267
|
[dim, factor] = known;
|
|
263
268
|
} else if (unit.includes("/")) {
|
|
@@ -274,7 +279,7 @@ export function parseCell(markdown: string): Cell {
|
|
|
274
279
|
if (groups.cur) unit = groups.cur;
|
|
275
280
|
// `24–72 h`: the unit after the range's end applies to its start too.
|
|
276
281
|
const range = RANGE_TAIL.exec(rest);
|
|
277
|
-
const rangeUnit = range?.[2] ? (
|
|
282
|
+
const rangeUnit = range?.[2] ? knownUnit(range[2]) : undefined;
|
|
278
283
|
if (!unit && rangeUnit) {
|
|
279
284
|
[dim, factor] = rangeUnit;
|
|
280
285
|
unit = range![2]!;
|
|
@@ -314,14 +319,26 @@ function toNumber(written: string): number {
|
|
|
314
319
|
/** Factor of a unit written after the second number of a range or transition; the first number's when absent. */
|
|
315
320
|
function tailFactor(unit: string | undefined, fallback: number): number {
|
|
316
321
|
if (!unit) return fallback;
|
|
317
|
-
|
|
318
|
-
|
|
322
|
+
return knownUnit(unit)?.[1] ?? fallback;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/** Dimension and base factor of `unit`, cased spellings first; own keys only, so `constructor` is no unit. */
|
|
326
|
+
function knownUnit(unit: string): readonly [Dimension, number] | undefined {
|
|
327
|
+
if (Object.hasOwn(CASED_UNITS, unit)) return CASED_UNITS[unit];
|
|
328
|
+
const lower = unit.toLowerCase();
|
|
329
|
+
return Object.hasOwn(UNITS, lower) ? UNITS[lower] : undefined;
|
|
319
330
|
}
|
|
320
331
|
|
|
321
332
|
/** Read a table's columns and rows for charting. Cells are the raw Markdown of each cell. */
|
|
322
333
|
export function analyzeTable(header: readonly string[], rows: readonly (readonly string[])[]): TableAnalysis {
|
|
323
|
-
const
|
|
324
|
-
const
|
|
334
|
+
const headers = header.map(cell => plainCell(cell).text);
|
|
335
|
+
const parsed = rows.map(row => {
|
|
336
|
+
const cells = headers.map((_, index) => parseCell(row[index] ?? ""));
|
|
337
|
+
// `Edit / read calls | 85 / 147`: a spaced slash in the row's name pairs two values.
|
|
338
|
+
const paired = cells.some(cell => cell.kind === "text" && PAIR_SLASH.test(cell.text));
|
|
339
|
+
return cells.map((cell, index) => (paired || PAIR_SLASH.test(headers[index]!) ? cell : asScore(cell)));
|
|
340
|
+
});
|
|
341
|
+
const draft = headers.map((text, index) => readColumn(index, text, parsed));
|
|
325
342
|
const labels = draft.filter(column => column.role === "label" || column.role === "temporal");
|
|
326
343
|
const label =
|
|
327
344
|
labels[0] ?? draft.find(column => column.role === "sequence") ?? draft.find(column => column.role === "index");
|
|
@@ -338,6 +355,22 @@ export function analyzeTable(header: readonly string[], rows: readonly (readonly
|
|
|
338
355
|
|
|
339
356
|
type DraftColumn = Omit<TableColumn, "constant">;
|
|
340
357
|
|
|
358
|
+
/** A spaced slash naming two values (`p50 / p95`, `median / max`) rather than a path or a score. */
|
|
359
|
+
const PAIR_SLASH = /\S \/ \S/;
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* A whole-number `a/b` with `a ≤ b` as the percent of `b` it reached; any
|
|
363
|
+
* other cell unchanged, a list like `327 / 333 / 339` included.
|
|
364
|
+
*/
|
|
365
|
+
function asScore(cell: Cell): Cell {
|
|
366
|
+
if (!isNumber(cell) || cell.dim !== "fraction" || !cell.denominator) return cell;
|
|
367
|
+
const { value, denominator } = cell;
|
|
368
|
+
if (!Number.isInteger(value) || !Number.isInteger(denominator) || value > denominator) return cell;
|
|
369
|
+
const after = cell.text.indexOf(cell.figure);
|
|
370
|
+
if (after < 0 || /^\s*\//.test(cell.text.slice(after + cell.figure.length))) return cell;
|
|
371
|
+
return { ...cell, dim: "percent", value: (100 * value) / denominator };
|
|
372
|
+
}
|
|
373
|
+
|
|
341
374
|
function readColumn(index: number, header: string, parsed: readonly (readonly Cell[])[]): DraftColumn {
|
|
342
375
|
const cells = resolveMinutes(parsed.map(row => row[index]!));
|
|
343
376
|
const present = cells.filter(cell => cell.kind !== "missing");
|
|
@@ -358,6 +391,7 @@ function readColumn(index: number, header: string, parsed: readonly (readonly Ce
|
|
|
358
391
|
for (const group of dims.values()) if (group.length > dominant.length) dominant = group;
|
|
359
392
|
const dim = dominant[0]?.dim;
|
|
360
393
|
const mixed = numbers.length > 0 && dominant.length / numbers.length < 0.8;
|
|
394
|
+
const scored = numbers.filter(cell => cell.dim === "percent" && cell.denominator !== undefined).length;
|
|
361
395
|
const unit = dim === "currency" || dim === "rate" ? (dominant[0]?.unit ?? "") : "";
|
|
362
396
|
|
|
363
397
|
const trimmed = header.trim();
|
|
@@ -385,6 +419,7 @@ function readColumn(index: number, header: string, parsed: readonly (readonly Ce
|
|
|
385
419
|
dim,
|
|
386
420
|
unit,
|
|
387
421
|
mixed,
|
|
422
|
+
scores: numbers.length > 0 && scored / numbers.length >= 0.8,
|
|
388
423
|
signedShare: numbers.length ? numbers.filter(cell => cell.signed).length / numbers.length : 0,
|
|
389
424
|
arrowShare: numbers.length ? numbers.filter(cell => cell.to !== undefined).length / numbers.length : 0,
|
|
390
425
|
};
|
|
@@ -20,6 +20,7 @@ import { DEFAULT_TERMINAL_PREVIEW_LINES, expandKeyHint } from "../render/render-
|
|
|
20
20
|
import type { TspCardStatus, TspSpan, TspText, TspTone } from "@oh-my-pi/pi-wire";
|
|
21
21
|
import { card, node, span, text } from "../native/describe";
|
|
22
22
|
import type { NativeChild, NativeNode } from "../native/node";
|
|
23
|
+
import { runBox, runFoot, runInput, runOutput, type RunState } from "../tools/native-view";
|
|
23
24
|
|
|
24
25
|
/** Output rows shown while an execution is collapsed. */
|
|
25
26
|
export const PREVIEW_LINES = 20;
|
|
@@ -190,7 +191,7 @@ export interface ExecutionToolInput {
|
|
|
190
191
|
/** Tool name for the head icon (`bash`, `eval`). */
|
|
191
192
|
readonly name: string;
|
|
192
193
|
readonly title: string;
|
|
193
|
-
/** The command / cell source
|
|
194
|
+
/** The command / cell source: the run box's input and the head's Copy command. */
|
|
194
195
|
readonly command: string;
|
|
195
196
|
readonly lang: string;
|
|
196
197
|
/** Excluded from context (`!!`/`$$`). */
|
|
@@ -208,39 +209,55 @@ export interface ExecutionToolInput {
|
|
|
208
209
|
readonly artifactError?: OutputArtifactError;
|
|
209
210
|
}
|
|
210
211
|
|
|
212
|
+
const EXECUTION_RUN_STATE: Record<ExecutionStatus, RunState> = {
|
|
213
|
+
running: "running",
|
|
214
|
+
complete: "done",
|
|
215
|
+
cancelled: "cancelled",
|
|
216
|
+
error: "failed",
|
|
217
|
+
};
|
|
218
|
+
|
|
211
219
|
/**
|
|
212
|
-
* A user `!`/`$` run as the agent's `tool` frame (§6.6):
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
220
|
+
* A user `!`/`$` run as the agent's `tool` frame (§6.6): a head with a `you`
|
|
221
|
+
* badge (plus `not sent` when excluded from context) and the command for Copy
|
|
222
|
+
* command; the body is one run box — the source, the output as an `ansi` mini
|
|
223
|
+
* terminal following its tail, and the foot (state, time, truncation) — with
|
|
224
|
+
* any images below it. Timer, exit chip and cancelled note stay head data.
|
|
216
225
|
*/
|
|
217
226
|
export function describeExecutionTool(input: ExecutionToolInput): NativeNode {
|
|
218
227
|
const running = input.status === "running";
|
|
219
|
-
const
|
|
220
|
-
if (input.output) body.push(node("ansi", { text: input.output, follow: running }, undefined, "output"));
|
|
221
|
-
if (input.images) body.push(...input.images);
|
|
222
|
-
const notes: string[] = [];
|
|
223
|
-
if (input.truncation) notes.push(formatTruncationMetaNotice(input.truncation));
|
|
224
|
-
if (input.artifactError) notes.push(formatArtifactErrorNotice(input.artifactError));
|
|
225
|
-
if (notes.length > 0) {
|
|
226
|
-
body.push({
|
|
227
|
-
...text([span(notes.join(" · "), "muted")], { wrap: "word", role: "omp.tool.notice" }),
|
|
228
|
-
key: "foot",
|
|
229
|
-
});
|
|
230
|
-
}
|
|
228
|
+
const shell = input.name === "bash";
|
|
231
229
|
const ms = Math.max(0, Math.round((input.endedAt ?? performance.now()) - input.startedAt));
|
|
230
|
+
const state = EXECUTION_RUN_STATE[input.status];
|
|
231
|
+
const box = runBox(
|
|
232
|
+
[
|
|
233
|
+
runInput(input.command, {
|
|
234
|
+
role: shell ? "omp.tool.bash.command" : "omp.tool.eval.input",
|
|
235
|
+
lang: input.lang,
|
|
236
|
+
wrap: shell,
|
|
237
|
+
}),
|
|
238
|
+
input.output.length > 0 &&
|
|
239
|
+
runOutput(input.output, {
|
|
240
|
+
role: shell ? "omp.tool.bash.output" : "omp.tool.eval.output",
|
|
241
|
+
previewLines: DEFAULT_TERMINAL_PREVIEW_LINES,
|
|
242
|
+
}),
|
|
243
|
+
runFoot({
|
|
244
|
+
state,
|
|
245
|
+
exitCode: input.exitCode,
|
|
246
|
+
elapsedMs: ms,
|
|
247
|
+
meta: { truncation: input.truncation, artifactError: input.artifactError },
|
|
248
|
+
}),
|
|
249
|
+
],
|
|
250
|
+
{ key: "run", tone: state === "failed" ? "error" : undefined },
|
|
251
|
+
);
|
|
232
252
|
const badges: { text: string; tone?: TspTone; title?: string }[] = [{ text: "you", tone: "user" }];
|
|
233
253
|
if (input.excluded) badges.push({ text: "not sent", title: "Not sent to the model", tone: "muted" });
|
|
234
|
-
const hasBody = body.length > 0;
|
|
235
254
|
return node(
|
|
236
255
|
"tool",
|
|
237
256
|
{
|
|
238
257
|
role: input.role,
|
|
239
258
|
name: input.name,
|
|
240
259
|
title: input.title,
|
|
241
|
-
|
|
242
|
-
targetKind: "command",
|
|
243
|
-
lang: input.lang,
|
|
260
|
+
command: input.command,
|
|
244
261
|
badges,
|
|
245
262
|
status: EXECUTION_CARD_STATUS[input.status],
|
|
246
263
|
age: running ? ms : undefined,
|
|
@@ -248,11 +265,11 @@ export function describeExecutionTool(input: ExecutionToolInput): NativeNode {
|
|
|
248
265
|
exit: input.status === "error" ? input.exitCode : undefined,
|
|
249
266
|
note: input.status === "cancelled" ? "cancelled" : undefined,
|
|
250
267
|
frame: "card",
|
|
251
|
-
collapsible:
|
|
252
|
-
collapsed:
|
|
253
|
-
preview:
|
|
268
|
+
collapsible: true,
|
|
269
|
+
collapsed: !input.expanded,
|
|
270
|
+
preview: "children",
|
|
254
271
|
},
|
|
255
|
-
|
|
272
|
+
[box, ...(input.images ?? [])],
|
|
256
273
|
);
|
|
257
274
|
}
|
|
258
275
|
|
package/src/chat/svg-figure.ts
CHANGED
|
@@ -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
|
-
/**
|
|
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. */
|
|
@@ -111,10 +111,13 @@ function resolveEditModeForTool(toolName: string, tool: AgentTool | undefined):
|
|
|
111
111
|
|
|
112
112
|
type ToolRendererStage = "call" | "result";
|
|
113
113
|
|
|
114
|
-
/**
|
|
114
|
+
/**
|
|
115
|
+
* A renderer's preview as the fallback card's clamp (`tail` becomes a head
|
|
116
|
+
* clamp of the same size; `children` leaves the clamping to the body's own previews).
|
|
117
|
+
*/
|
|
115
118
|
function cardPreview(preview: NativeToolView["preview"]): TspPreview | undefined {
|
|
116
119
|
if (preview === undefined) return { lines: DEFAULT_TERMINAL_PREVIEW_LINES };
|
|
117
|
-
if (preview === "none") return undefined;
|
|
120
|
+
if (preview === "none" || preview === "children") return undefined;
|
|
118
121
|
if (preview !== "auto" && "tail" in preview) return { lines: preview.tail };
|
|
119
122
|
return preview;
|
|
120
123
|
}
|
|
@@ -1025,6 +1028,7 @@ export class ToolExecutionComponent extends Container {
|
|
|
1025
1028
|
target: head?.target,
|
|
1026
1029
|
targetKind: head?.targetKind,
|
|
1027
1030
|
lang: head?.lang,
|
|
1031
|
+
command: head?.command,
|
|
1028
1032
|
href: head?.href,
|
|
1029
1033
|
meta: head?.meta,
|
|
1030
1034
|
badges: badges.length > 0 ? badges : undefined,
|
|
@@ -1124,11 +1128,14 @@ export class ToolExecutionComponent extends Container {
|
|
|
1124
1128
|
* A renderer that throws falls back to the generic card.
|
|
1125
1129
|
*/
|
|
1126
1130
|
#nativeView(): NativeToolView {
|
|
1131
|
+
const status = this.#nativeStatus();
|
|
1127
1132
|
const options: RenderResultContextOptions = {
|
|
1128
1133
|
expanded: this.#expanded,
|
|
1129
1134
|
isPartial: this.#isPartial,
|
|
1130
1135
|
argsComplete: this.#argsComplete,
|
|
1131
1136
|
executionStarted: this.#executionStarted,
|
|
1137
|
+
elapsedMs: this.#elapsedMs(status),
|
|
1138
|
+
cancelled: status === "cancelled",
|
|
1132
1139
|
renderContext: this.#buildRenderContext(),
|
|
1133
1140
|
};
|
|
1134
1141
|
// Custom tools (MCP, extensions) carry their own describe hooks, mirroring
|
package/src/components/editor.ts
CHANGED
|
@@ -83,6 +83,7 @@ const VIM_MODE_LABELS: Record<VimMode, string | undefined> = {
|
|
|
83
83
|
normal: "NORMAL",
|
|
84
84
|
visual: "VISUAL",
|
|
85
85
|
"visual-line": "VISUAL",
|
|
86
|
+
replace: "REPLACE",
|
|
86
87
|
};
|
|
87
88
|
|
|
88
89
|
const PASSTHROUGH_COLOR = (text: string): string => text;
|
|
@@ -672,7 +673,9 @@ export class Editor implements Component, Focusable {
|
|
|
672
673
|
// Emacs-style kill ring
|
|
673
674
|
#killRing = new KillRing();
|
|
674
675
|
/** Previous edit, for kill/yank chaining, undo coalescing, and the provisional space after a Tab word accept. */
|
|
675
|
-
#lastAction: "kill" | "yank" | "type-word" | "accept-word" | null = null;
|
|
676
|
+
#lastAction: "kill" | "yank" | "type-word" | "accept-word" | "replace" | null = null;
|
|
677
|
+
/** Graphemes overwritten in the current `R` session, so Backspace can restore them. */
|
|
678
|
+
#replaceLog: { line: number; col: number; removed: string; text: string }[] = [];
|
|
676
679
|
|
|
677
680
|
// Character jump mode
|
|
678
681
|
#jumpMode: "forward" | "backward" | null = null;
|
|
@@ -2252,18 +2255,43 @@ export class Editor implements Component, Focusable {
|
|
|
2252
2255
|
return this.isShowingAutocomplete() ? false : this.#runVimKey("escape", vim);
|
|
2253
2256
|
}
|
|
2254
2257
|
if (vim.mode === "insert") return false;
|
|
2258
|
+
if (vim.mode === "replace") {
|
|
2259
|
+
if (canonical === "backspace" || matchesKey(data, "backspace") || matchesKey(data, "shift+backspace")) {
|
|
2260
|
+
this.#replaceBackspace();
|
|
2261
|
+
return true;
|
|
2262
|
+
}
|
|
2263
|
+
const replacing = extractPrintableText(data);
|
|
2264
|
+
if (replacing) {
|
|
2265
|
+
for (const seg of segmenter.segment(replacing)) this.#overwriteReplaceGrapheme(seg.segment);
|
|
2266
|
+
return true;
|
|
2267
|
+
}
|
|
2268
|
+
}
|
|
2255
2269
|
|
|
2270
|
+
// `f`/`t`/`r` are waiting for a character. Space is that character; arrows and other named
|
|
2271
|
+
// keys cancel, instead of being rewritten to `h`/`l` and inserted or searched for.
|
|
2272
|
+
const awaitingTarget = /[fFtTr]$/.test(vim.pendingText);
|
|
2273
|
+
if (awaitingTarget && (canonical === "space" || data === " ")) return this.#runVimKey(" ", vim);
|
|
2256
2274
|
const mapped = canonical === undefined ? undefined : VIM_NAV_KEYS[canonical];
|
|
2275
|
+
if (awaitingTarget && mapped !== undefined) return this.#runVimKey("escape", vim);
|
|
2257
2276
|
if (mapped !== undefined) return this.#runVimKey(mapped, vim);
|
|
2258
2277
|
|
|
2259
|
-
// Control chords carry no printable text and stay with the host.
|
|
2278
|
+
// Control chords, Enter, and Tab carry no printable text and stay with the host. A half-typed
|
|
2279
|
+
// command (`r`, `f`, `d`) is cancelled first, like character-jump mode, so it cannot outlive a
|
|
2280
|
+
// submit and swallow the first key of the next prompt.
|
|
2260
2281
|
const printable = extractPrintableText(data);
|
|
2261
|
-
if (!printable)
|
|
2282
|
+
if (!printable) {
|
|
2283
|
+
if (vim.pending) this.#runVimKey("escape", vim);
|
|
2284
|
+
return false;
|
|
2285
|
+
}
|
|
2262
2286
|
|
|
2263
2287
|
// Batched stdin can deliver several keystrokes at once, so replay the run one grapheme at a
|
|
2264
|
-
// time. A command that drops out of Normal mode part-way (`iabc`) turns the rest of
|
|
2265
|
-
//
|
|
2288
|
+
// time. A command that drops out of Normal mode part-way (`iabc`, `Rxx`) turns the rest of
|
|
2289
|
+
// the run into literal text or replace-mode overwrites rather than more Normal commands.
|
|
2266
2290
|
for (const seg of segmenter.segment(printable)) {
|
|
2291
|
+
if (vim.mode === "replace") {
|
|
2292
|
+
this.#overwriteReplaceGrapheme(seg.segment);
|
|
2293
|
+
continue;
|
|
2294
|
+
}
|
|
2267
2295
|
if (this.#runVimKey(seg.segment, vim)) continue;
|
|
2268
2296
|
this.#insertCharacter(printable.slice(seg.index));
|
|
2269
2297
|
return true;
|
|
@@ -2284,11 +2312,22 @@ export class Editor implements Component, Focusable {
|
|
|
2284
2312
|
if (vim.mode !== before || vim.pendingText !== pendingBefore || this.vimSelectedLines !== selectedLinesBefore) {
|
|
2285
2313
|
this.onVimModeChange?.(vim.mode);
|
|
2286
2314
|
}
|
|
2315
|
+
if (before === "replace" && vim.mode !== "replace") this.#replaceLog.length = 0;
|
|
2316
|
+
if (vim.mode === "replace" && before !== "replace") this.#replaceLog.length = 0;
|
|
2287
2317
|
return true;
|
|
2288
2318
|
}
|
|
2289
2319
|
|
|
2290
2320
|
#applyVimCommands(commands: readonly VimCommand[]): void {
|
|
2291
2321
|
for (const command of commands) {
|
|
2322
|
+
// A delete or other edit in replace mode invalidates Backspace restores. Motions do not.
|
|
2323
|
+
if (
|
|
2324
|
+
this.#vim?.mode === "replace" &&
|
|
2325
|
+
command.kind !== "move" &&
|
|
2326
|
+
command.kind !== "mode" &&
|
|
2327
|
+
command.kind !== "yank"
|
|
2328
|
+
) {
|
|
2329
|
+
this.#replaceLog.length = 0;
|
|
2330
|
+
}
|
|
2292
2331
|
switch (command.kind) {
|
|
2293
2332
|
case "move":
|
|
2294
2333
|
this.#moveVimCursor(command.to);
|
|
@@ -2320,12 +2359,133 @@ export class Editor implements Component, Focusable {
|
|
|
2320
2359
|
case "undo":
|
|
2321
2360
|
this.#applyUndo();
|
|
2322
2361
|
break;
|
|
2362
|
+
case "replace":
|
|
2363
|
+
this.#replaceVimSpan(command.from, command.to, command.text);
|
|
2364
|
+
break;
|
|
2365
|
+
case "join":
|
|
2366
|
+
this.#joinVimLines(command.fromLine, command.lines);
|
|
2367
|
+
break;
|
|
2368
|
+
case "indent":
|
|
2369
|
+
this.#indentVimLines(command.fromLine, command.toLine, command.out);
|
|
2370
|
+
break;
|
|
2323
2371
|
}
|
|
2324
2372
|
}
|
|
2325
2373
|
this.#clampVimCursor();
|
|
2326
2374
|
this.invalidate();
|
|
2327
2375
|
}
|
|
2328
2376
|
|
|
2377
|
+
#replaceVimSpan(from: VimPosition, to: VimPosition, text: string): void {
|
|
2378
|
+
const line = this.#state.lines[from.line] ?? "";
|
|
2379
|
+
if (this.#spanCutsAtomicToken(line, from.col, to.col)) return;
|
|
2380
|
+
this.#recordUndoState();
|
|
2381
|
+
this.#lastAction = null;
|
|
2382
|
+
this.#state.lines[from.line] = line.slice(0, from.col) + text + line.slice(to.col);
|
|
2383
|
+
this.#state.cursorLine = from.line;
|
|
2384
|
+
let last = from.col;
|
|
2385
|
+
for (const seg of segmenter.segment(text)) last = from.col + seg.index;
|
|
2386
|
+
this.#setCursorCol(last);
|
|
2387
|
+
this.#afterVimEdit();
|
|
2388
|
+
}
|
|
2389
|
+
|
|
2390
|
+
#overwriteReplaceGrapheme(grapheme: string): void {
|
|
2391
|
+
const lineIdx = this.#state.cursorLine;
|
|
2392
|
+
const line = this.#state.lines[lineIdx] ?? "";
|
|
2393
|
+
const col = this.#state.cursorCol;
|
|
2394
|
+
if (this.#atomicTokenAt(line, col)) return;
|
|
2395
|
+
// Any other edit since the last overwrite (setText, `x`, paste) resets `#lastAction`, which
|
|
2396
|
+
// makes the logged columns meaningless; start a fresh undo step and a fresh log.
|
|
2397
|
+
if (this.#lastAction !== "replace") {
|
|
2398
|
+
this.#recordUndoState();
|
|
2399
|
+
this.#replaceLog.length = 0;
|
|
2400
|
+
}
|
|
2401
|
+
this.#lastAction = "replace";
|
|
2402
|
+
// Editing a recalled prompt makes it a draft, so Up/Down at an edge move the cursor again
|
|
2403
|
+
// instead of navigating history over the overwritten text (same as `#afterVimEdit`).
|
|
2404
|
+
this.#historyIndex = -1;
|
|
2405
|
+
const end = col >= line.length ? col : nextGraphemeStart(line, col);
|
|
2406
|
+
const removed = line.slice(col, end);
|
|
2407
|
+
this.#state.lines[lineIdx] = line.slice(0, col) + grapheme + line.slice(end);
|
|
2408
|
+
this.#replaceLog.push({ line: lineIdx, col, removed, text: grapheme });
|
|
2409
|
+
this.#setCursorCol(col + grapheme.length);
|
|
2410
|
+
this.#notifyChange();
|
|
2411
|
+
}
|
|
2412
|
+
|
|
2413
|
+
#replaceBackspace(): void {
|
|
2414
|
+
if (this.#lastAction !== "replace") {
|
|
2415
|
+
this.#replaceLog.length = 0;
|
|
2416
|
+
return;
|
|
2417
|
+
}
|
|
2418
|
+
const entry = this.#replaceLog.pop();
|
|
2419
|
+
if (!entry) return;
|
|
2420
|
+
const line = this.#state.lines[entry.line] ?? "";
|
|
2421
|
+
const stillThere = line.slice(entry.col, entry.col + entry.text.length) === entry.text;
|
|
2422
|
+
const atCursor = this.#state.cursorLine === entry.line && this.#state.cursorCol === entry.col + entry.text.length;
|
|
2423
|
+
if (!stillThere) return;
|
|
2424
|
+
if (!atCursor) {
|
|
2425
|
+
this.#replaceLog.push(entry);
|
|
2426
|
+
return;
|
|
2427
|
+
}
|
|
2428
|
+
this.#state.lines[entry.line] =
|
|
2429
|
+
line.slice(0, entry.col) + entry.removed + line.slice(entry.col + entry.text.length);
|
|
2430
|
+
this.#setCursorCol(entry.col);
|
|
2431
|
+
this.#notifyChange();
|
|
2432
|
+
}
|
|
2433
|
+
|
|
2434
|
+
#joinVimLines(fromLine: number, span: number): void {
|
|
2435
|
+
const start = Math.max(0, Math.min(fromLine, this.#state.lines.length - 1));
|
|
2436
|
+
const last = Math.min(start + Math.max(span, 2) - 1, this.#state.lines.length - 1);
|
|
2437
|
+
if (last <= start) return;
|
|
2438
|
+
this.#recordUndoState();
|
|
2439
|
+
let text = this.#state.lines[start] ?? "";
|
|
2440
|
+
let cursor = text.length;
|
|
2441
|
+
for (let i = start + 1; i <= last; i++) {
|
|
2442
|
+
const raw = this.#state.lines[i] ?? "";
|
|
2443
|
+
let trim = /^[ \t]*/.exec(raw)?.[0].length ?? 0;
|
|
2444
|
+
const token = this.#atomicTokenAt(raw, 0);
|
|
2445
|
+
if (token && token.start < trim) trim = token.start;
|
|
2446
|
+
const next = raw.slice(trim);
|
|
2447
|
+
const at = text.length;
|
|
2448
|
+
if (i === start + 1) cursor = at;
|
|
2449
|
+
// Vim join: no extra space after whitespace, before `)`, or for an empty line; two spaces after `.!?`.
|
|
2450
|
+
const gap =
|
|
2451
|
+
text.length === 0 || next.length === 0 || /[ \t]$/.test(text) || next.startsWith(")")
|
|
2452
|
+
? ""
|
|
2453
|
+
: /[.!?]$/.test(text)
|
|
2454
|
+
? " "
|
|
2455
|
+
: " ";
|
|
2456
|
+
text += gap + next;
|
|
2457
|
+
}
|
|
2458
|
+
this.#state.lines.splice(start, last - start + 1, text);
|
|
2459
|
+
this.#state.cursorLine = start;
|
|
2460
|
+
this.#setCursorCol(cursor);
|
|
2461
|
+
this.#lastAction = null;
|
|
2462
|
+
this.#afterVimEdit();
|
|
2463
|
+
}
|
|
2464
|
+
|
|
2465
|
+
#indentVimLines(fromLine: number, toLine: number, out: boolean): void {
|
|
2466
|
+
const first = Math.max(0, Math.min(fromLine, this.#state.lines.length - 1));
|
|
2467
|
+
const last = Math.max(first, Math.min(toLine, this.#state.lines.length - 1));
|
|
2468
|
+
// Two spaces, not Vim's shiftwidth of 8: a prompt draft should not jump a tab stop. A leading tab shifts by one tab so the line keeps its own indent style.
|
|
2469
|
+
// Empty lines stay empty, as in Vim, so shifting a paragraph never leaves trailing blanks.
|
|
2470
|
+
const next = this.#state.lines.slice(first, last + 1).map(line => {
|
|
2471
|
+
const text = line ?? "";
|
|
2472
|
+
if (!out) return text.length === 0 ? text : (text.startsWith("\t") ? "\t" : " ") + text;
|
|
2473
|
+
if (text.startsWith("\t")) return text.slice(1);
|
|
2474
|
+
const spaces = /^ */.exec(text)?.[0].length ?? 0;
|
|
2475
|
+
return text.slice(Math.min(2, spaces));
|
|
2476
|
+
});
|
|
2477
|
+
if (next.every((line, i) => line === (this.#state.lines[first + i] ?? ""))) return;
|
|
2478
|
+
this.#recordUndoState();
|
|
2479
|
+
for (let i = first; i <= last; i++) this.#state.lines[i] = next[i - first] ?? "";
|
|
2480
|
+
this.#state.cursorLine = first;
|
|
2481
|
+
const landed = this.#state.lines[first] ?? "";
|
|
2482
|
+
let col = 0;
|
|
2483
|
+
while (col < landed.length && /\s/.test(landed.charAt(col))) col++;
|
|
2484
|
+
this.#setCursorCol(col);
|
|
2485
|
+
this.#lastAction = null;
|
|
2486
|
+
this.#afterVimEdit();
|
|
2487
|
+
}
|
|
2488
|
+
|
|
2329
2489
|
#moveVimCursor(to: VimPosition): void {
|
|
2330
2490
|
this.#state.cursorLine = Math.max(0, Math.min(to.line, this.#state.lines.length - 1));
|
|
2331
2491
|
const line = this.#state.lines[this.#state.cursorLine] ?? "";
|
|
@@ -3409,6 +3569,23 @@ export class Editor implements Component, Focusable {
|
|
|
3409
3569
|
return undefined;
|
|
3410
3570
|
}
|
|
3411
3571
|
|
|
3572
|
+
/** True when `[from, to)` overlaps a placeholder. Counted `r` must no-op rather than split it.
|
|
3573
|
+
* One pass over the line's matches, so a long counted replace stays linear. */
|
|
3574
|
+
#spanCutsAtomicToken(line: string, from: number, to: number): boolean {
|
|
3575
|
+
const re = this.#getAtomicTokenRe();
|
|
3576
|
+
if (re === undefined) return false;
|
|
3577
|
+
re.lastIndex = 0;
|
|
3578
|
+
for (;;) {
|
|
3579
|
+
const match = re.exec(line);
|
|
3580
|
+
if (match === null || match.index >= to) return false;
|
|
3581
|
+
if (match[0].length === 0) {
|
|
3582
|
+
re.lastIndex = match.index + 1;
|
|
3583
|
+
continue;
|
|
3584
|
+
}
|
|
3585
|
+
if (match.index + match[0].length > from) return true;
|
|
3586
|
+
}
|
|
3587
|
+
}
|
|
3588
|
+
|
|
3412
3589
|
/** Expand the half-open range [start, end) so it never cuts through an atomic
|
|
3413
3590
|
* placeholder token: a boundary landing inside a token pulls the whole token in. */
|
|
3414
3591
|
#expandRangeOverAtomicTokens(line: string, start: number, end: number): { start: number; end: number } {
|
|
@@ -53,11 +53,15 @@ export function matchesSelectPageDown(data: string): boolean {
|
|
|
53
53
|
return getKeybindings().matches(data, "tui.select.pageDown");
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
/** Effective external-editor key: the first bound key, or Ctrl+G when unbound. */
|
|
57
|
+
export function appExternalEditorKey(): KeyId {
|
|
58
|
+
return getKeybindings().getKeys("app.editor.external")[0] ?? "ctrl+g";
|
|
59
|
+
}
|
|
60
|
+
|
|
56
61
|
/** Match the external-editor keybinding, falling back to Ctrl+G when unbound. */
|
|
57
62
|
export function matchesAppExternalEditor(data: string): boolean {
|
|
58
63
|
const keybindings = getKeybindings();
|
|
59
|
-
|
|
60
|
-
if (externalEditorKeys.length > 0) {
|
|
64
|
+
if (keybindings.getKeys("app.editor.external").length > 0) {
|
|
61
65
|
return keybindings.matches(data, "app.editor.external");
|
|
62
66
|
}
|
|
63
67
|
return matchesKey(data, "ctrl+g");
|
package/src/kitty-graphics.ts
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* forms. Protocol gating (`imageProtocol === Kitty`) lives in the caller.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import {
|
|
18
|
+
import { isInsideTerminalMultiplexer, terminalMultiplexerSessions } from "./terminal-multiplexer";
|
|
19
19
|
import { wrapTmuxPassthroughIfNeeded } from "./tmux";
|
|
20
20
|
|
|
21
21
|
/** Kitty Unicode placeholder base character (U+10EEEE, Plane 16 PUA). */
|
|
@@ -67,8 +67,8 @@ export interface KittyGraphicsFeatures {
|
|
|
67
67
|
* cannot use cursor-positioned placements because the outer terminal does not
|
|
68
68
|
* know pane scroll/reflow state. An explicit `PI_FORCE_IMAGE_PROTOCOL=kitty`
|
|
69
69
|
* opts into placeholders under any multiplexer — matching `timg -pk`.
|
|
70
|
-
* Automatic
|
|
71
|
-
* that
|
|
70
|
+
* Automatic fallback stays off inside multiplexers whose pane marker does not
|
|
71
|
+
* prove that a Kitty renderer is enabled (Herdr's is experimental).
|
|
72
72
|
*
|
|
73
73
|
* `PI_NO_KITTY_PLACEHOLDERS=1` and `PI_KITTY_PLACEHOLDERS=0` remain hard
|
|
74
74
|
* opt-outs; `PI_KITTY_PLACEHOLDERS=1` explicitly opts in anywhere else.
|
|
@@ -81,7 +81,7 @@ export function detectKittyUnicodePlaceholdersSupport(terminalId: string, env: N
|
|
|
81
81
|
if (force === "0" || force === "false" || force === "off" || force === "no" || force === "n") return false;
|
|
82
82
|
const insideMultiplexer = isInsideTerminalMultiplexer(env);
|
|
83
83
|
if (insideMultiplexer && env.PI_FORCE_IMAGE_PROTOCOL?.trim().toLowerCase() === "kitty") return true;
|
|
84
|
-
if (
|
|
84
|
+
if (terminalMultiplexerSessions(env).some(multiplexer => multiplexer.imagesRequireOverride)) return false;
|
|
85
85
|
return (
|
|
86
86
|
terminalId === "kitty" ||
|
|
87
87
|
terminalId === "ghostty" ||
|