@linxiraos/pi-tui 1.4.13 → 1.5.1
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 +33 -34
- package/dist/types/chat/messages.d.ts +2 -0
- package/dist/types/chat/spotlight.d.ts +8 -3
- package/dist/types/chat/transcript-render-helpers.d.ts +5 -0
- package/dist/types/components/editor.d.ts +4 -1
- package/dist/types/html-form/data.d.ts +56 -0
- package/dist/types/html-form/dialog.d.ts +51 -0
- package/dist/types/html-form/media.d.ts +28 -0
- package/dist/types/html-form/paginate.d.ts +43 -0
- package/dist/types/html-form/parse.d.ts +99 -0
- package/dist/types/overlays/ask-dialog.d.ts +11 -6
- package/dist/types/overlays/copy-targets.d.ts +8 -6
- package/dist/types/overlays/directory-picker.d.ts +62 -0
- package/dist/types/overlays/hook-editor.d.ts +3 -1
- package/dist/types/overlays/hub-frame.d.ts +2 -0
- package/dist/types/overlays/model-hub.d.ts +2 -0
- package/dist/types/overlays/team-hub.d.ts +150 -0
- package/dist/types/render/row-moves.d.ts +41 -0
- package/dist/types/status-line/component.d.ts +5 -0
- package/dist/types/status-line/host.d.ts +2 -2
- package/dist/types/status-line/schema.d.ts +1 -1
- package/dist/types/status-line/types.d.ts +8 -0
- package/dist/types/tools/ask.d.ts +11 -49
- package/dist/types/tools/autoresearch.d.ts +2 -2
- package/dist/types/tools/eval.d.ts +4 -0
- package/dist/types/tools/grouped-file-output.d.ts +2 -0
- package/dist/types/tools/shell-viz.d.ts +6 -2
- package/dist/types/tools/xd-url.d.ts +6 -0
- package/dist/types/windows-input-mode.d.ts +8 -0
- package/package.json +9 -9
- package/src/charts/table-data.ts +18 -5
- package/src/chat/chat-transcript-builder.ts +27 -10
- package/src/chat/image-loading.ts +55 -0
- package/src/chat/messages.d.ts +2 -0
- package/src/chat/messages.ts +3 -0
- package/src/chat/spotlight.d.ts +8 -3
- package/src/chat/spotlight.ts +23 -11
- package/src/chat/tool-execution.ts +5 -0
- package/src/chat/transcript-render-helpers.d.ts +5 -0
- package/src/chat/transcript-render-helpers.ts +13 -0
- package/src/chrome/transcript-container.ts +1 -1
- package/src/components/editor.d.ts +4 -1
- package/src/components/editor.ts +3 -2
- package/src/components/markdown.ts +70 -12
- package/src/html-form/data.d.ts +56 -0
- package/src/html-form/data.ts +177 -0
- package/src/html-form/dialog.ts +1450 -0
- package/src/html-form/media.ts +105 -0
- package/src/html-form/paginate.ts +99 -0
- package/src/html-form/parse.d.ts +99 -0
- package/src/html-form/parse.ts +568 -0
- package/src/lang-from-path.ts +1 -0
- package/src/latex-block.ts +3 -3
- package/src/latex-to-unicode.ts +18 -5
- package/src/overlays/ask-dialog.ts +69 -52
- package/src/overlays/copy-targets.d.ts +8 -6
- package/src/overlays/copy-targets.ts +25 -46
- package/src/overlays/directory-picker.ts +387 -0
- package/src/overlays/hook-editor.ts +16 -15
- package/src/overlays/hub-frame.ts +8 -1
- package/src/overlays/model-hub.ts +12 -2
- package/src/overlays/spotlight-sheet.ts +18 -18
- package/src/overlays/team-hub.ts +901 -0
- package/src/render/row-moves.d.ts +41 -0
- package/src/render/row-moves.ts +109 -0
- package/src/setup/wizard-overlay.ts +7 -3
- package/src/status-line/component.ts +19 -0
- package/src/status-line/footer.ts +2 -2
- package/src/status-line/host.ts +2 -2
- package/src/status-line/presets.ts +6 -6
- package/src/status-line/schema.ts +2 -1
- package/src/status-line/segments.ts +31 -4
- package/src/status-line/startup.ts +1 -1
- package/src/status-line/types.ts +8 -0
- package/src/stdin-buffer.ts +15 -1
- package/src/terminal-capabilities.ts +12 -3
- package/src/terminal.ts +41 -3
- package/src/tools/ask.d.ts +11 -49
- package/src/tools/ask.ts +201 -606
- package/src/tools/autoresearch.ts +2 -2
- package/src/tools/debug.ts +31 -38
- package/src/tools/eval.d.ts +4 -0
- package/src/tools/eval.ts +4 -0
- package/src/tools/grep.ts +38 -16
- package/src/tools/grouped-file-output.d.ts +2 -0
- package/src/tools/grouped-file-output.ts +5 -0
- package/src/tools/shell-viz-render.ts +37 -6
- package/src/tools/shell-viz.d.ts +6 -2
- package/src/tools/shell-viz.ts +19 -6
- package/src/tools/xd-url.d.ts +6 -0
- package/src/tools/xd-url.ts +19 -1
- package/src/tui.ts +129 -1
- package/src/windows-input-mode.d.ts +8 -0
- package/src/windows-input-mode.ts +13 -0
|
@@ -414,7 +414,7 @@ export interface UpdateNotesDetails {
|
|
|
414
414
|
/** Render update-notes tool calls and results. */
|
|
415
415
|
export const updateNotesToolRenderer = {
|
|
416
416
|
renderCall(args, _options, theme): Text {
|
|
417
|
-
const preview = args.append_idea ?? args.body
|
|
417
|
+
const preview = args.append_idea ?? args.body?.slice(0, 100) ?? "";
|
|
418
418
|
return new Text(
|
|
419
419
|
`${theme.fg("toolTitle", theme.bold("update_notes"))} ${theme.fg("muted", truncateToWidth(replaceTabs(preview), 100))}`,
|
|
420
420
|
0,
|
|
@@ -432,4 +432,4 @@ export const updateNotesToolRenderer = {
|
|
|
432
432
|
describeResult(result): NativeToolView | undefined {
|
|
433
433
|
return describeTextResult("update_notes", result, "muted");
|
|
434
434
|
},
|
|
435
|
-
} satisfies ToolRenderer<{ body
|
|
435
|
+
} satisfies ToolRenderer<{ body?: string; append_idea?: string }, UpdateNotesDetails>;
|
package/src/tools/debug.ts
CHANGED
|
@@ -12,6 +12,8 @@ import {
|
|
|
12
12
|
truncateToWidth,
|
|
13
13
|
clipCollapsed,
|
|
14
14
|
} from "../render/render-utils";
|
|
15
|
+
import { sanitizeText } from "@linxiraos/pi-utils";
|
|
16
|
+
import { singleLine } from "../utils";
|
|
15
17
|
import type { NativeToolView, RenderResultOptions, ToolRenderer, ToolRenderResult } from "./renderer";
|
|
16
18
|
import { ansi, kv } from "../native/describe";
|
|
17
19
|
import type { NativeChild } from "../native/node";
|
|
@@ -88,43 +90,20 @@ export function formatSessionSnapshot(snapshot: DebugSessionSnapshot): string[]
|
|
|
88
90
|
return lines;
|
|
89
91
|
}
|
|
90
92
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return `${action} ${truncateToWidth(args.function, TRUNCATE_LENGTHS.TITLE)}`;
|
|
101
|
-
}
|
|
102
|
-
if (args.expression) {
|
|
103
|
-
return `${action} ${truncateToWidth(args.expression, TRUNCATE_LENGTHS.TITLE)}`;
|
|
104
|
-
}
|
|
105
|
-
if (args.command) {
|
|
106
|
-
return `${action} ${truncateToWidth(args.command, TRUNCATE_LENGTHS.TITLE)}`;
|
|
107
|
-
}
|
|
108
|
-
if (args.memory_reference) {
|
|
109
|
-
return `${action} ${truncateToWidth(args.memory_reference, TRUNCATE_LENGTHS.TITLE)}`;
|
|
110
|
-
}
|
|
111
|
-
if (args.instruction_reference) {
|
|
112
|
-
return `${action} ${truncateToWidth(args.instruction_reference, TRUNCATE_LENGTHS.TITLE)}`;
|
|
113
|
-
}
|
|
114
|
-
if (args.data_id) {
|
|
115
|
-
return `${action} ${truncateToWidth(args.data_id, TRUNCATE_LENGTHS.TITLE)}`;
|
|
116
|
-
}
|
|
117
|
-
if (args.name) {
|
|
118
|
-
return `${action} ${truncateToWidth(args.name, TRUNCATE_LENGTHS.TITLE)}`;
|
|
119
|
-
}
|
|
120
|
-
return action;
|
|
93
|
+
/**
|
|
94
|
+
* Model-authored arg text is untrusted: strip ANSI escapes and control
|
|
95
|
+
* characters, then hand the value to the shared single-line projection
|
|
96
|
+
* (`singleLine`: tab expansion + line-break collapse) before it lands in a
|
|
97
|
+
* card row or native head (same treatment as every sibling renderer, e.g.
|
|
98
|
+
* `replaceTabs` in bash.ts).
|
|
99
|
+
*/
|
|
100
|
+
function sanitizeDebugArg(value: string): string {
|
|
101
|
+
return singleLine(sanitizeText(value));
|
|
121
102
|
}
|
|
122
103
|
|
|
123
|
-
/**
|
|
124
|
-
function
|
|
125
|
-
|
|
126
|
-
if (!args) return [action, undefined];
|
|
127
|
-
const target =
|
|
104
|
+
/** Highest-precedence identifying arg for a debug call head; mirrors the summary field order. */
|
|
105
|
+
function debugCallTarget(args: DebugRenderArgs): string | undefined {
|
|
106
|
+
return (
|
|
128
107
|
args.program ||
|
|
129
108
|
(args.file && args.line !== undefined ? `${args.file}:${args.line}` : undefined) ||
|
|
130
109
|
args.function ||
|
|
@@ -134,8 +113,22 @@ function debugCallParts(args: DebugRenderArgs | undefined, fallbackAction: strin
|
|
|
134
113
|
args.instruction_reference ||
|
|
135
114
|
args.data_id ||
|
|
136
115
|
args.name ||
|
|
137
|
-
undefined
|
|
138
|
-
|
|
116
|
+
undefined
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function summarizeDebugCall(args: DebugRenderArgs): string {
|
|
121
|
+
const action = args.action ? sanitizeDebugArg(args.action.replaceAll("_", " ")) : "request";
|
|
122
|
+
const target = debugCallTarget(args);
|
|
123
|
+
return target ? `${action} ${truncateToWidth(sanitizeDebugArg(target), TRUNCATE_LENGTHS.TITLE)}` : action;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Untruncated `[action, target]` for native heads; mirrors {@link summarizeDebugCall}'s field precedence. */
|
|
127
|
+
function debugCallParts(args: DebugRenderArgs | undefined, fallbackAction: string): [string, string | undefined] {
|
|
128
|
+
const action = sanitizeDebugArg((args?.action ?? fallbackAction).replaceAll("_", " "));
|
|
129
|
+
if (!args) return [action, undefined];
|
|
130
|
+
const target = debugCallTarget(args);
|
|
131
|
+
return [action, target === undefined ? undefined : sanitizeDebugArg(target)];
|
|
139
132
|
}
|
|
140
133
|
|
|
141
134
|
function describeDebugResult(
|
|
@@ -197,7 +190,7 @@ export const debugToolRenderer = {
|
|
|
197
190
|
args?: DebugRenderArgs,
|
|
198
191
|
): Component {
|
|
199
192
|
return framedToolCard(theme, () => {
|
|
200
|
-
const action = (args?.action ?? result.details?.action ?? "debug").replaceAll("_", " ");
|
|
193
|
+
const action = sanitizeDebugArg((args?.action ?? result.details?.action ?? "debug").replaceAll("_", " "));
|
|
201
194
|
const success = !options.isPartial && !result.isError;
|
|
202
195
|
const statusIcon = success
|
|
203
196
|
? theme.styledSymbol("tool.debug", "accent")
|
package/src/tools/eval.d.ts
CHANGED
|
@@ -68,6 +68,10 @@ export interface EvalCellResult {
|
|
|
68
68
|
export interface EvalToolDetails {
|
|
69
69
|
cells?: EvalCellResult[];
|
|
70
70
|
images?: ImageContent[];
|
|
71
|
+
/**
|
|
72
|
+
* Call-level status events, written by older builds beside or instead of `cells`; current results
|
|
73
|
+
* keep them on each cell only.
|
|
74
|
+
*/
|
|
71
75
|
statusEvents?: EvalStatusEvent[];
|
|
72
76
|
/** Evictable events dropped from the front of `statusEvents` (see {@link recordStatusEvent}). */
|
|
73
77
|
statusEventsElided?: number;
|
package/src/tools/eval.ts
CHANGED
|
@@ -117,6 +117,10 @@ export interface EvalCellResult {
|
|
|
117
117
|
export interface EvalToolDetails {
|
|
118
118
|
cells?: EvalCellResult[];
|
|
119
119
|
images?: ImageContent[];
|
|
120
|
+
/**
|
|
121
|
+
* Call-level status events, written by older builds beside or instead of `cells`; current results
|
|
122
|
+
* keep them on each cell only.
|
|
123
|
+
*/
|
|
120
124
|
statusEvents?: EvalStatusEvent[];
|
|
121
125
|
/** Evictable events dropped from the front of `statusEvents` (see {@link recordStatusEvent}). */
|
|
122
126
|
statusEventsElided?: number;
|
package/src/tools/grep.ts
CHANGED
|
@@ -11,8 +11,9 @@ import type {
|
|
|
11
11
|
} from "./renderer";
|
|
12
12
|
import { compact } from "../native/describe";
|
|
13
13
|
import type { NativeChild } from "../native/node";
|
|
14
|
+
import { compactText, styledSpans } from "../native/spans";
|
|
14
15
|
import { footnoteText, inlineErrorView, resultText } from "./native-view";
|
|
15
|
-
import { type Theme } from "../theme/theme";
|
|
16
|
+
import { ensureThemeSync, highlightCode, type Theme } from "../theme/theme";
|
|
16
17
|
import type { OutputMeta } from "./output-meta";
|
|
17
18
|
import type { TruncationResult } from "./streaming-output";
|
|
18
19
|
import {
|
|
@@ -32,6 +33,7 @@ import {
|
|
|
32
33
|
formatEmptyMessage,
|
|
33
34
|
formatErrorDetail,
|
|
34
35
|
PREVIEW_LIMITS,
|
|
36
|
+
replaceTabs,
|
|
35
37
|
} from "../render/render-utils";
|
|
36
38
|
import {
|
|
37
39
|
classifyGroupedLines,
|
|
@@ -43,6 +45,7 @@ import {
|
|
|
43
45
|
groupedLinkTargets,
|
|
44
46
|
groupLineIndicesByBlank,
|
|
45
47
|
groupsByFile,
|
|
48
|
+
isGroupedHeader,
|
|
46
49
|
isMatchRow,
|
|
47
50
|
} from "./grouped-file-output";
|
|
48
51
|
|
|
@@ -114,9 +117,11 @@ function grepFlagMeta(args: GrepRenderArgs): string[] {
|
|
|
114
117
|
/**
|
|
115
118
|
* Header subject, `pattern in scope`. A result names the tool's display scope
|
|
116
119
|
* (linked to the original search path); a call falls back to the requested paths.
|
|
120
|
+
* Callers pass the pattern already syntax-colored: the bundled regex grammar also
|
|
121
|
+
* handles incomplete, still-streaming patterns.
|
|
117
122
|
*/
|
|
118
123
|
function grepSubject(
|
|
119
|
-
|
|
124
|
+
subject: string | undefined,
|
|
120
125
|
args: GrepRenderArgs | undefined,
|
|
121
126
|
uiTheme: Theme,
|
|
122
127
|
details?: GrepToolDetails,
|
|
@@ -125,7 +130,7 @@ function grepSubject(
|
|
|
125
130
|
let scope = details?.scopePath || undefined;
|
|
126
131
|
if (scope && searchPath) scope = fileHyperlink(searchPath, scope);
|
|
127
132
|
scope ??= toPathList(args?.path ?? args?.paths).join(", ") || undefined;
|
|
128
|
-
return formatScopedSubject(
|
|
133
|
+
return formatScopedSubject(subject, scope, uiTheme);
|
|
129
134
|
}
|
|
130
135
|
|
|
131
136
|
function grepStatusIcon(uiTheme: Theme): string {
|
|
@@ -141,7 +146,11 @@ export const grepToolRenderer = {
|
|
|
141
146
|
icon: "pending",
|
|
142
147
|
title: "Grep",
|
|
143
148
|
titleColor: "toolTitle",
|
|
144
|
-
description: grepSubject(
|
|
149
|
+
description: grepSubject(
|
|
150
|
+
args.pattern ? highlightCode(replaceTabs(args.pattern), "Regular Expression", uiTheme).join("\n") : "?",
|
|
151
|
+
args,
|
|
152
|
+
uiTheme,
|
|
153
|
+
),
|
|
145
154
|
meta: grepFlagMeta(args),
|
|
146
155
|
},
|
|
147
156
|
uiTheme,
|
|
@@ -162,7 +171,10 @@ export const grepToolRenderer = {
|
|
|
162
171
|
isRecord(rawDetails) && typeof rawDetails.searchPath === "string"
|
|
163
172
|
? rawDetails.searchPath
|
|
164
173
|
: details?.searchPath;
|
|
165
|
-
const
|
|
174
|
+
const pattern = args?.pattern
|
|
175
|
+
? highlightCode(replaceTabs(args.pattern), "Regular Expression", uiTheme).join("\n")
|
|
176
|
+
: undefined;
|
|
177
|
+
const description = grepSubject(pattern, args, uiTheme, details, searchPath);
|
|
166
178
|
|
|
167
179
|
if (result.isError || details?.error) {
|
|
168
180
|
const errorText =
|
|
@@ -245,7 +257,16 @@ export const grepToolRenderer = {
|
|
|
245
257
|
return new Text(lines.join("\n"), 0, 0);
|
|
246
258
|
}
|
|
247
259
|
|
|
248
|
-
const
|
|
260
|
+
const textContent = result.details?.displayContent ?? result.content?.find(c => c.type === "text")?.text ?? "";
|
|
261
|
+
const allLines = textContent.split("\n");
|
|
262
|
+
// Classify the whole output so nested directory headers resolve across blank-line
|
|
263
|
+
// groups. Display paths are cwd-relative (`searchPath` for results that predate
|
|
264
|
+
// `cwd`); a single-file search's headerless lines belong to the searched file.
|
|
265
|
+
const contexts = classifyGroupedLines(allLines, details?.cwd ?? details?.searchPath, details?.searchPath);
|
|
266
|
+
const hasScope = Boolean(details?.scopePath || toPathList(args?.path ?? args?.paths).length > 0);
|
|
267
|
+
const singleFileScope = hasScope && fileCount === 1 && !allLines.some(isGroupedHeader);
|
|
268
|
+
const meta = [formatCount("match", matchCount)];
|
|
269
|
+
if (!singleFileScope) meta.push(formatCount("file", fileCount));
|
|
249
270
|
if (truncated) meta.push(uiTheme.fg("warning", tuiText("grepTruncated", "truncated")));
|
|
250
271
|
const header = renderStatusLine(
|
|
251
272
|
{
|
|
@@ -257,13 +278,6 @@ export const grepToolRenderer = {
|
|
|
257
278
|
},
|
|
258
279
|
uiTheme,
|
|
259
280
|
);
|
|
260
|
-
|
|
261
|
-
const textContent = result.details?.displayContent ?? result.content?.find(c => c.type === "text")?.text ?? "";
|
|
262
|
-
const allLines = textContent.split("\n");
|
|
263
|
-
// Classify the whole output so nested directory headers resolve across blank-line
|
|
264
|
-
// groups. Display paths are cwd-relative (`searchPath` for results that predate
|
|
265
|
-
// `cwd`); a single-file search's headerless lines belong to the searched file.
|
|
266
|
-
const contexts = classifyGroupedLines(allLines, details?.cwd ?? details?.searchPath, details?.searchPath);
|
|
267
281
|
const styleCodeFrame = createCodeFrameStyler(allLines, contexts, "toolOutput", uiTheme);
|
|
268
282
|
const styleLine = createGroupedRowStyler(allLines, contexts, uiTheme, {
|
|
269
283
|
linkTarget: groupedLinkTargets(contexts, textContent, details, rawDetails),
|
|
@@ -340,9 +354,13 @@ export const grepToolRenderer = {
|
|
|
340
354
|
const truncated = Boolean(
|
|
341
355
|
details?.truncated || details?.meta?.truncation || details?.meta?.limits?.columnTruncated,
|
|
342
356
|
);
|
|
357
|
+
const lines = textContent.split("\n");
|
|
343
358
|
const fileCount = details?.fileCount ?? 0;
|
|
359
|
+
const singleFileScope = Boolean(scope) && fileCount === 1 && !lines.some(isGroupedHeader);
|
|
344
360
|
const counts = hasDetailedData
|
|
345
|
-
?
|
|
361
|
+
? singleFileScope
|
|
362
|
+
? formatCount("match", matchCount)
|
|
363
|
+
: `${formatCount("match", matchCount)} · ${formatCount("file", fileCount)}`
|
|
346
364
|
: undefined;
|
|
347
365
|
const head = grepNativeHead(args, compact([scope, counts]));
|
|
348
366
|
const hiddenFiles = options.expanded ? 0 : Math.max(0, fileCount - NATIVE_COLLAPSED_FILES);
|
|
@@ -354,7 +372,7 @@ export const grepToolRenderer = {
|
|
|
354
372
|
tool: truncated ? { ...head, badges: [{ text: "truncated", tone: "warning" }] } : head,
|
|
355
373
|
inline: true,
|
|
356
374
|
body: compact<NativeChild>([
|
|
357
|
-
...describeGroupedOutput(
|
|
375
|
+
...describeGroupedOutput(lines, {
|
|
358
376
|
maxFiles: options.expanded ? undefined : NATIVE_COLLAPSED_FILES,
|
|
359
377
|
file: details?.files?.length === 1 ? details.files[0] : undefined,
|
|
360
378
|
}),
|
|
@@ -374,5 +392,9 @@ function grepNativeHead(args: GrepRenderArgs | undefined, meta?: readonly string
|
|
|
374
392
|
if (paths.length) parts.push(`in ${paths.join(", ")}`);
|
|
375
393
|
parts.push(...grepFlagMeta(args));
|
|
376
394
|
}
|
|
377
|
-
|
|
395
|
+
ensureThemeSync();
|
|
396
|
+
const target = args?.pattern
|
|
397
|
+
? compactText(styledSpans(highlightCode(args.pattern, "Regular Expression").join("\n")))
|
|
398
|
+
: "?";
|
|
399
|
+
return { title: "Grep", target, targetKind: "pattern", meta: parts };
|
|
378
400
|
}
|
|
@@ -54,6 +54,8 @@ export interface FileMatchSection {
|
|
|
54
54
|
export declare function formatFileMatches(files: string[], grouped: boolean, renderFile: (filePath: string) => FileMatchSection): GroupedFilesOutput;
|
|
55
55
|
/** Whether a row of grouped output is a code-frame row the search matched (`*12│…`). */
|
|
56
56
|
export declare function isMatchRow(line: string): boolean;
|
|
57
|
+
/** Whether a row of grouped output is a `#` directory or file header; single-file scopes print none. */
|
|
58
|
+
export declare function isGroupedHeader(line: string): boolean;
|
|
57
59
|
/** Per-line classification of grouped output, used by renderers for file rows and hyperlinks. */
|
|
58
60
|
export interface GroupedLineContext {
|
|
59
61
|
/** Directory header, file header, or any non-header body/content line. */
|
|
@@ -168,6 +168,11 @@ export function isMatchRow(line: string): boolean {
|
|
|
168
168
|
return GROUPED_MATCH_ROW_RE.test(line);
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
+
/** Whether a row of grouped output is a `#` directory or file header; single-file scopes print none. */
|
|
172
|
+
export function isGroupedHeader(line: string): boolean {
|
|
173
|
+
return GROUPED_HEADER_RE.test(line);
|
|
174
|
+
}
|
|
175
|
+
|
|
171
176
|
/** Per-line classification of grouped output, used by renderers for file rows and hyperlinks. */
|
|
172
177
|
export interface GroupedLineContext {
|
|
173
178
|
/** Directory header, file header, or any non-header body/content line. */
|
|
@@ -9,6 +9,16 @@ export function shellVizText(text: string): string {
|
|
|
9
9
|
return replaceTabs(sanitizeText(text)).replace(/[\r\n]/g, " ");
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Nerd Font glyphs that replace the whole `🔇 out|err|silent` /dev/null badge;
|
|
14
|
+
* keyed by the native `badge-discard-*` style token.
|
|
15
|
+
*/
|
|
16
|
+
const DISCARD_ICONS: Record<string, string> = {
|
|
17
|
+
"badge-discard-out": "\u{f164d}", // nf-md-message_off
|
|
18
|
+
"badge-discard-err": "\u{f14bc}", // nf-md-alert_remove
|
|
19
|
+
"badge-discard-all": "\u{f0581}", // nf-md-volume_off
|
|
20
|
+
};
|
|
21
|
+
|
|
12
22
|
function color(style: string | undefined): ThemeColor {
|
|
13
23
|
const tokens = style?.split(" ") ?? [];
|
|
14
24
|
if (tokens.includes("comment")) return "syntaxComment";
|
|
@@ -28,10 +38,12 @@ function segmentText(
|
|
|
28
38
|
presentation: ShellVizPresentation,
|
|
29
39
|
theme: Theme,
|
|
30
40
|
): string {
|
|
31
|
-
const
|
|
41
|
+
const tokens = segment.style?.split(" ") ?? [];
|
|
42
|
+
const discard =
|
|
43
|
+
theme.getSymbolPreset() === "nerd" ? tokens.find(token => Object.hasOwn(DISCARD_ICONS, token)) : undefined;
|
|
44
|
+
const text = discard ? ` ${DISCARD_ICONS[discard]}` : shellVizText(segment.text);
|
|
32
45
|
const inactive =
|
|
33
46
|
(presentation.running && !(segment.active ?? row.active)) || (segment.state ?? row.state) === "skipped";
|
|
34
|
-
const tokens = segment.style?.split(" ") ?? [];
|
|
35
47
|
const semantic = tokens.some(token => ["chip", "badge", "secret"].includes(token));
|
|
36
48
|
const styled = presentation.preferences.layers.color || semantic ? theme.fg(color(segment.style), text) : text;
|
|
37
49
|
const emphasized = inactive
|
|
@@ -42,7 +54,13 @@ function segmentText(
|
|
|
42
54
|
return emphasized;
|
|
43
55
|
}
|
|
44
56
|
|
|
45
|
-
|
|
57
|
+
/** A row split into its gutter/indent/effects lead and the wrappable source text after it. */
|
|
58
|
+
function rowParts(
|
|
59
|
+
row: ShellVizRow,
|
|
60
|
+
presentation: ShellVizPresentation,
|
|
61
|
+
theme: Theme,
|
|
62
|
+
width: number,
|
|
63
|
+
): { lead: string; body: string } {
|
|
46
64
|
const selected =
|
|
47
65
|
presentation.preferences.selectedNode !== undefined &&
|
|
48
66
|
(row.node === presentation.preferences.selectedNode ||
|
|
@@ -54,7 +72,7 @@ function rowText(row: ShellVizRow, presentation: ShellVizPresentation, theme: Th
|
|
|
54
72
|
row.state === "fail" && !rowFailedInSegments && row.role !== "head" && row.role !== "mid" && row.role !== "tail";
|
|
55
73
|
const gutter = failedStatement
|
|
56
74
|
? theme.fg("error", "×")
|
|
57
|
-
: presentation.running && row.active
|
|
75
|
+
: presentation.running && row.segments.some(segment => segment.active)
|
|
58
76
|
? theme.fg("accent", "▶")
|
|
59
77
|
: selected
|
|
60
78
|
? theme.fg("accent", "›")
|
|
@@ -84,11 +102,24 @@ function rowText(row: ShellVizRow, presentation: ShellVizPresentation, theme: Th
|
|
|
84
102
|
return muted ? theme.faint(annotation) : annotation;
|
|
85
103
|
})
|
|
86
104
|
.join(theme.fg("muted", " · "));
|
|
87
|
-
return
|
|
105
|
+
return {
|
|
106
|
+
lead: `${gutter} ${indent}${effect ? `${effect} ` : ""}`,
|
|
107
|
+
body: `${body}${meta}${annotations ? ` ${theme.fg("muted", "‹")} ${annotations} ${theme.fg("muted", "›")}` : ""}`,
|
|
108
|
+
};
|
|
88
109
|
}
|
|
89
110
|
|
|
111
|
+
/**
|
|
112
|
+
* Wrap the row's text under its lead with a hanging indent. Wrapping the lead
|
|
113
|
+
* together with the text would let a long unbreakable token (an embedded regex
|
|
114
|
+
* or URL) drop to its own line: the whitespace-only lead becomes a blank row
|
|
115
|
+
* and the continuation loses the gutter and nesting indent.
|
|
116
|
+
*/
|
|
90
117
|
function rowLines(row: ShellVizRow, presentation: ShellVizPresentation, theme: Theme, width: number): string[] {
|
|
91
|
-
|
|
118
|
+
const { lead, body } = rowParts(row, presentation, theme, width);
|
|
119
|
+
const leadWidth = visibleWidth(lead);
|
|
120
|
+
if (leadWidth >= width) return wrapTextWithAnsi(`${lead}${body}`, Math.max(1, width));
|
|
121
|
+
const hanging = " ".repeat(leadWidth);
|
|
122
|
+
return wrapTextWithAnsi(body, width - leadWidth).map((line, index) => `${index === 0 ? lead : hanging}${line}`);
|
|
92
123
|
}
|
|
93
124
|
|
|
94
125
|
function joinPanes(left: string[], right: string[], width: number, separator: string): string[] {
|
package/src/tools/shell-viz.d.ts
CHANGED
|
@@ -4,8 +4,12 @@ import type { ShellTrace, ShellVizPreferences, ShellVizPresentation } from "@lin
|
|
|
4
4
|
export type ShellVisualizationSource = RunTrace | ShellVisualization;
|
|
5
5
|
/** Bind the immutable snapshot before publishing it; live paints borrow the actual run. */
|
|
6
6
|
export declare function attachShellTrace(snapshot: ShellTrace, trace: RunTrace): void;
|
|
7
|
-
/**
|
|
8
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Historical traces restore their canonical native archive only once per snapshot.
|
|
9
|
+
* `undefined` when the engine rejects the snapshot (e.g. a `tool_result` hook rewrote
|
|
10
|
+
* `script`); callers then render the plain command and output.
|
|
11
|
+
*/
|
|
12
|
+
export declare function shellVisualization(snapshot: ShellTrace): ShellVisualizationSource | undefined;
|
|
9
13
|
/** Python-like Pseudo, all layers enabled, one pane, live, paused, normal speed. */
|
|
10
14
|
export declare function defaultShellVizPreferences(): ShellVizPreferences;
|
|
11
15
|
/** Render through native ownership; an explicit replay cursor never uses the normal output sink. */
|
package/src/tools/shell-viz.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RunTrace, ShellVisualization, type ShellVizOptions } from "@linxiraos/pi-natives";
|
|
2
|
+
import { logger } from "@linxiraos/pi-utils";
|
|
2
3
|
import type {
|
|
3
4
|
ShellTrace,
|
|
4
5
|
ShellVizPreferences,
|
|
@@ -10,21 +11,33 @@ import type {
|
|
|
10
11
|
|
|
11
12
|
/** Native live-run or restored-trace owner; the UI never holds shell syntax. */
|
|
12
13
|
export type ShellVisualizationSource = RunTrace | ShellVisualization;
|
|
13
|
-
|
|
14
|
+
/** Each snapshot's native owner; `null` marks one the engine rejected, so it is not restored again per paint. */
|
|
15
|
+
const visualizations = new WeakMap<ShellTrace, ShellVisualizationSource | null>();
|
|
14
16
|
|
|
15
17
|
/** Bind the immutable snapshot before publishing it; live paints borrow the actual run. */
|
|
16
18
|
export function attachShellTrace(snapshot: ShellTrace, trace: RunTrace): void {
|
|
17
19
|
visualizations.set(snapshot, trace);
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
/**
|
|
21
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Historical traces restore their canonical native archive only once per snapshot.
|
|
24
|
+
* `undefined` when the engine rejects the snapshot (e.g. a `tool_result` hook rewrote
|
|
25
|
+
* `script`); callers then render the plain command and output.
|
|
26
|
+
*/
|
|
27
|
+
export function shellVisualization(snapshot: ShellTrace): ShellVisualizationSource | undefined {
|
|
22
28
|
let visualization = visualizations.get(snapshot);
|
|
23
|
-
if (
|
|
24
|
-
|
|
29
|
+
if (visualization === undefined) {
|
|
30
|
+
try {
|
|
31
|
+
visualization = new ShellVisualization(JSON.stringify(snapshot));
|
|
32
|
+
} catch (error) {
|
|
33
|
+
logger.warn("Stored shell trace cannot be restored; rendering without visualization", {
|
|
34
|
+
error: error instanceof Error ? error.message : String(error),
|
|
35
|
+
});
|
|
36
|
+
visualization = null;
|
|
37
|
+
}
|
|
25
38
|
visualizations.set(snapshot, visualization);
|
|
26
39
|
}
|
|
27
|
-
return visualization;
|
|
40
|
+
return visualization ?? undefined;
|
|
28
41
|
}
|
|
29
42
|
|
|
30
43
|
/** Python-like Pseudo, all layers enabled, one pane, live, paused, normal speed. */
|
package/src/tools/xd-url.d.ts
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
export declare const XD_URL_PREFIX = "xd://";
|
|
3
3
|
/** Returns the canonical tool name from a bare or `xd://`-prefixed spelling. */
|
|
4
4
|
export declare function stripXdUrlPrefix(name: string): string;
|
|
5
|
+
/**
|
|
6
|
+
* Drop peelable trailing selectors that some bridges append to file reads.
|
|
7
|
+
* Device URLs advertise `selectors: "none"`, so these must not become part of
|
|
8
|
+
* the mounted tool name (`wiki_observe:raw`).
|
|
9
|
+
*/
|
|
10
|
+
export declare function stripXdPeelableSelectors(name: string): string;
|
|
5
11
|
/**
|
|
6
12
|
* Parse an `xd://` URL into its device target.
|
|
7
13
|
* Returns `null` for other or malformed URLs and `name: null` for the root.
|
package/src/tools/xd-url.ts
CHANGED
|
@@ -1,11 +1,27 @@
|
|
|
1
1
|
/** Canonical prefix for virtual tool-device URLs. */
|
|
2
2
|
export const XD_URL_PREFIX = "xd://";
|
|
3
3
|
|
|
4
|
+
/** Trailing selectors the Cursor bridge may append; xd devices reject them. */
|
|
5
|
+
const XD_PEELABLE_SELECTOR_RE = /:(?:raw|conflicts)$/i;
|
|
6
|
+
|
|
4
7
|
/** Returns the canonical tool name from a bare or `xd://`-prefixed spelling. */
|
|
5
8
|
export function stripXdUrlPrefix(name: string): string {
|
|
6
9
|
return name.toLowerCase().startsWith(XD_URL_PREFIX) ? name.slice(XD_URL_PREFIX.length) : name;
|
|
7
10
|
}
|
|
8
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Drop peelable trailing selectors that some bridges append to file reads.
|
|
14
|
+
* Device URLs advertise `selectors: "none"`, so these must not become part of
|
|
15
|
+
* the mounted tool name (`wiki_observe:raw`).
|
|
16
|
+
*/
|
|
17
|
+
export function stripXdPeelableSelectors(name: string): string {
|
|
18
|
+
let out = name;
|
|
19
|
+
while (XD_PEELABLE_SELECTOR_RE.test(out)) {
|
|
20
|
+
out = out.replace(XD_PEELABLE_SELECTOR_RE, "");
|
|
21
|
+
}
|
|
22
|
+
return out;
|
|
23
|
+
}
|
|
24
|
+
|
|
9
25
|
/**
|
|
10
26
|
* Parse an `xd://` URL into its device target.
|
|
11
27
|
* Returns `null` for other or malformed URLs and `name: null` for the root.
|
|
@@ -13,7 +29,9 @@ export function stripXdUrlPrefix(name: string): string {
|
|
|
13
29
|
export function parseXdUrl(input: string): { name: string | null } | null {
|
|
14
30
|
const trimmed = input.trim();
|
|
15
31
|
if (!trimmed.toLowerCase().startsWith(XD_URL_PREFIX)) return null;
|
|
16
|
-
|
|
32
|
+
let name = trimmed.slice(XD_URL_PREFIX.length);
|
|
33
|
+
if (name.length === 0) return { name: null };
|
|
34
|
+
name = stripXdPeelableSelectors(name);
|
|
17
35
|
if (name.length === 0) return { name: null };
|
|
18
36
|
if (/[/?#]/.test(name)) return null;
|
|
19
37
|
return { name };
|
package/src/tui.ts
CHANGED
|
@@ -53,6 +53,7 @@ import {
|
|
|
53
53
|
import { onTerminalBackgroundFallbackChange } from "./theme/theme";
|
|
54
54
|
import { compositeLineAt } from "./render/composite";
|
|
55
55
|
import { stripExtensionLinkMarkers } from "./render/extension-links";
|
|
56
|
+
import { applyRowMove, BLANK_ROW, findRowMove, rowMoveSequence, UNKNOWN_ROW } from "./render/row-moves";
|
|
56
57
|
import { tmuxMultiplexer } from "./multiplexers/tmux";
|
|
57
58
|
import { minFrameIntervalMs } from "./frame-rate";
|
|
58
59
|
import {
|
|
@@ -1069,6 +1070,9 @@ export class TUI extends Container {
|
|
|
1069
1070
|
// caps `s` at 7. This bounds spacer lookups and supplies enough context
|
|
1070
1071
|
// above the resize viewport to classify every legal heading exactly.
|
|
1071
1072
|
static readonly #OSC66_MAX_SPACER_ROWS = 6;
|
|
1073
|
+
// Band moves per unsynchronized frame: a streaming shift, the chrome a
|
|
1074
|
+
// history push displaced, and one spare.
|
|
1075
|
+
static readonly #MAX_ROW_MOVES = 3;
|
|
1072
1076
|
// Ghostty can drop Kitty graphics commands sent during its first post-startup
|
|
1073
1077
|
// settle window, leaving only Unicode placeholder cells. Hold the first image
|
|
1074
1078
|
// paint until that window has passed; later images render normally.
|
|
@@ -3864,6 +3868,115 @@ export class TUI extends Container {
|
|
|
3864
3868
|
return `\r${ERASE_LINE}\x1b7\x1b[B\x1b[J\x1b8`;
|
|
3865
3869
|
}
|
|
3866
3870
|
|
|
3871
|
+
/**
|
|
3872
|
+
* Rows of a frame for a terminal that may present any prefix of the write
|
|
3873
|
+
* (no synchronized output), or `undefined` when the frame needs the plain
|
|
3874
|
+
* row-rewrite paths (images, OSC 66 text, stale row preparation, a viewport
|
|
3875
|
+
* taller than the screen).
|
|
3876
|
+
*
|
|
3877
|
+
* Rows bound for scrollback are first made to show their history line, then
|
|
3878
|
+
* pushed with line feeds on the bottom row; surviving rows then shift into
|
|
3879
|
+
* place with DL/IL, and only rows that still differ are rewritten. Every
|
|
3880
|
+
* intermediate screen is the previous frame scrolled or shifted, never a
|
|
3881
|
+
* rewritten row beside its stale copy (the duplicated band a top-down
|
|
3882
|
+
* repaint shows) or an erased band awaiting repaint.
|
|
3883
|
+
*/
|
|
3884
|
+
#movedRowsSequence(
|
|
3885
|
+
width: number,
|
|
3886
|
+
height: number,
|
|
3887
|
+
startTop: number,
|
|
3888
|
+
newTop: number,
|
|
3889
|
+
history: PreparedLines,
|
|
3890
|
+
viewport: PreparedLines,
|
|
3891
|
+
): string | undefined {
|
|
3892
|
+
const window = this.#providerWindow;
|
|
3893
|
+
const rows = viewport.lines.length;
|
|
3894
|
+
if (rows > height || startTop + window.length > height) return undefined;
|
|
3895
|
+
const widthEpoch = getWidthConfigEpoch();
|
|
3896
|
+
const imageProtocol = TERMINAL.imageProtocol;
|
|
3897
|
+
for (const row of this.#providerPreparedRows) {
|
|
3898
|
+
if (
|
|
3899
|
+
row.isImage ||
|
|
3900
|
+
row.width !== width ||
|
|
3901
|
+
row.widthEpoch !== widthEpoch ||
|
|
3902
|
+
row.imageProtocol !== imageProtocol
|
|
3903
|
+
) {
|
|
3904
|
+
return undefined;
|
|
3905
|
+
}
|
|
3906
|
+
}
|
|
3907
|
+
if (viewport.rows.some(row => row.isImage) || history.rows.some(row => row.isImage)) return undefined;
|
|
3908
|
+
if (window.some(isOsc66Line) || viewport.lines.some(isOsc66Line) || history.lines.some(isOsc66Line)) {
|
|
3909
|
+
return undefined;
|
|
3910
|
+
}
|
|
3911
|
+
|
|
3912
|
+
const keys = new Map<string, number>([["", BLANK_ROW]]);
|
|
3913
|
+
const keyOf = (line: string): number => {
|
|
3914
|
+
let key = keys.get(line);
|
|
3915
|
+
if (key === undefined) {
|
|
3916
|
+
key = keys.size;
|
|
3917
|
+
keys.set(line, key);
|
|
3918
|
+
}
|
|
3919
|
+
return key;
|
|
3920
|
+
};
|
|
3921
|
+
// oxlint-disable-next-line unicorn/no-new-array -- screen-height model preallocation
|
|
3922
|
+
const screen: number[] = new Array(height).fill(BLANK_ROW);
|
|
3923
|
+
screen.fill(UNKNOWN_ROW, 0, startTop);
|
|
3924
|
+
for (let index = 0; index < window.length; index++) screen[startTop + index] = keyOf(window[index]!);
|
|
3925
|
+
|
|
3926
|
+
let out = "";
|
|
3927
|
+
// Inserted, deleted, and scrolled-in lines take the current background.
|
|
3928
|
+
let reset = false;
|
|
3929
|
+
const resetOnce = (): string => {
|
|
3930
|
+
if (reset) return "";
|
|
3931
|
+
reset = true;
|
|
3932
|
+
return SEGMENT_RESET;
|
|
3933
|
+
};
|
|
3934
|
+
// Push in screenfuls: physical row r holds combined row `done + r` of the
|
|
3935
|
+
// ledger (history above the old viewport, then the batch, then the
|
|
3936
|
+
// viewport), so each row about to scroll off must show its batch row.
|
|
3937
|
+
const pushed = Math.max(0, startTop + history.lines.length + rows - height);
|
|
3938
|
+
for (let done = 0; done < pushed;) {
|
|
3939
|
+
const count = Math.min(pushed - done, height);
|
|
3940
|
+
for (let r = 0; r < count; r++) {
|
|
3941
|
+
const index = done + r - startTop;
|
|
3942
|
+
if (index < 0) continue;
|
|
3943
|
+
const key = keyOf(history.lines[index]!);
|
|
3944
|
+
if (screen[r] === key) continue;
|
|
3945
|
+
out += `\x1b[${r + 1};1H${this.#lineRewriteSequence(history.rows[index]!, width)}`;
|
|
3946
|
+
screen[r] = key;
|
|
3947
|
+
}
|
|
3948
|
+
out += `${resetOnce()}\x1b[${height};1H${"\n".repeat(count)}`;
|
|
3949
|
+
screen.copyWithin(0, count);
|
|
3950
|
+
screen.fill(BLANK_ROW, height - count);
|
|
3951
|
+
done += count;
|
|
3952
|
+
}
|
|
3953
|
+
|
|
3954
|
+
const base = Math.max(0, startTop - pushed);
|
|
3955
|
+
// oxlint-disable-next-line unicorn/no-new-array -- screen-height model preallocation
|
|
3956
|
+
const target: number[] = new Array(height).fill(BLANK_ROW);
|
|
3957
|
+
target.fill(UNKNOWN_ROW, 0, base);
|
|
3958
|
+
for (let r = base; r < newTop; r++) target[r] = keyOf(history.lines[r + pushed - startTop]!);
|
|
3959
|
+
for (let index = 0; index < rows; index++) target[newTop + index] = keyOf(viewport.lines[index]!);
|
|
3960
|
+
|
|
3961
|
+
for (let moves = 0; moves < TUI.#MAX_ROW_MOVES; moves++) {
|
|
3962
|
+
const move = findRowMove(screen, target, base);
|
|
3963
|
+
if (move === undefined) break;
|
|
3964
|
+
out += `${resetOnce()}${rowMoveSequence(move, height)}`;
|
|
3965
|
+
applyRowMove(screen, move);
|
|
3966
|
+
}
|
|
3967
|
+
for (let r = base; r < newTop + rows; r++) {
|
|
3968
|
+
if (screen[r] === target[r]) continue;
|
|
3969
|
+
const row = r < newTop ? history.rows[r + pushed - startTop]! : viewport.rows[r - newTop]!;
|
|
3970
|
+
out += `\x1b[${r + 1};1H${this.#lineRewriteSequence(row, width)}`;
|
|
3971
|
+
}
|
|
3972
|
+
for (let r = newTop + rows; r < height; r++) {
|
|
3973
|
+
if (screen[r] === BLANK_ROW) continue;
|
|
3974
|
+
out += this.#eraseBelowRow(r, height);
|
|
3975
|
+
break;
|
|
3976
|
+
}
|
|
3977
|
+
return out;
|
|
3978
|
+
}
|
|
3979
|
+
|
|
3867
3980
|
/**
|
|
3868
3981
|
* Physical write transaction: append an ordinary batch, or bottom-split one
|
|
3869
3982
|
* complete replay into a history remainder and final viewport, then serialize
|
|
@@ -4003,7 +4116,22 @@ export class TUI extends Container {
|
|
|
4003
4116
|
this.#providerWindow.length > 0;
|
|
4004
4117
|
buffer += this.#retireImagePlacements(this.#screenImagePlacements, prepared.lines, newTop, !diffable);
|
|
4005
4118
|
for (const sequence of this.#imageBudget.takeTransmits()) append(sequence);
|
|
4006
|
-
|
|
4119
|
+
// Without synchronized output the terminal may show any prefix of this
|
|
4120
|
+
// write, so move surviving rows instead of repainting through them.
|
|
4121
|
+
const moved =
|
|
4122
|
+
!this.#synchronizedOutputEnabled &&
|
|
4123
|
+
geometryStable &&
|
|
4124
|
+
!destructiveReset &&
|
|
4125
|
+
history?.kind !== "replay" &&
|
|
4126
|
+
!this.#forceViewportRepaintOnNextRender &&
|
|
4127
|
+
this.#providerWindow.length > 0 &&
|
|
4128
|
+
pendingAltExit === "" &&
|
|
4129
|
+
this.#screenImagePlacements.size === 0
|
|
4130
|
+
? this.#movedRowsSequence(width, height, startTop, newTop, preparedHistory, prepared)
|
|
4131
|
+
: undefined;
|
|
4132
|
+
if (moved !== undefined) {
|
|
4133
|
+
buffer += moved;
|
|
4134
|
+
} else if (diffable) {
|
|
4007
4135
|
for (let index = 0; index < rows; index++) {
|
|
4008
4136
|
if (
|
|
4009
4137
|
!this.#rowNeedsRewrite(
|