@linxiraos/pi-tui 1.4.11 → 1.4.13
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 +30 -233
- package/README.md +4 -1
- package/THIRD-PARTY-NOTICES.txt +4 -5
- package/dist/types/apps/shell-visualizer.d.ts +24 -0
- package/dist/types/autocomplete.d.ts +20 -0
- package/dist/types/chat/cache-invalidation-marker.d.ts +15 -7
- package/dist/types/chat/chat-transcript-builder.d.ts +5 -3
- package/dist/types/chat/display-preferences.d.ts +2 -0
- package/dist/types/chat/extension-types.d.ts +72 -1
- package/dist/types/chat/image-loading.d.ts +2 -2
- package/dist/types/chat/messages.d.ts +2 -3
- package/dist/types/chat/read-tool-group.d.ts +15 -2
- package/dist/types/chat/skill-message.d.ts +1 -0
- package/dist/types/chat/spotlight.d.ts +203 -0
- package/dist/types/chat/tool-execution.d.ts +26 -5
- package/dist/types/chat/transcript-actions.d.ts +11 -0
- package/dist/types/chat/transcript-browser.d.ts +9 -0
- package/dist/types/chat/transcript-presentation.d.ts +164 -0
- package/dist/types/chat/ttsr-notification.d.ts +2 -0
- package/dist/types/chrome/message-frame.d.ts +2 -0
- package/dist/types/chrome/transcript-container.d.ts +27 -6
- package/dist/types/components/loader.d.ts +0 -2
- package/dist/types/components/markdown.d.ts +11 -1
- package/dist/types/components/settings-list.d.ts +12 -2
- package/dist/types/frame-rate.d.ts +18 -0
- package/dist/types/hotkeys-markdown.d.ts +2 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/keybinding-matchers.d.ts +4 -1
- package/dist/types/kitty-graphics.d.ts +1 -1
- package/dist/types/motion-effects.d.ts +10 -0
- package/dist/types/native/encode.d.ts +2 -0
- package/dist/types/native/measure.d.ts +10 -0
- package/dist/types/native/overlay.d.ts +1 -1
- package/dist/types/native/quiet.d.ts +5 -0
- package/dist/types/native/reconcile.d.ts +6 -1
- package/dist/types/native/spans.d.ts +6 -0
- package/dist/types/native/state.d.ts +4 -0
- package/dist/types/overlays/agent-hub.d.ts +6 -0
- package/dist/types/overlays/link-browser.d.ts +55 -0
- package/dist/types/overlays/running-subagent-badge.d.ts +1 -4
- package/dist/types/overlays/spotlight-sheet.d.ts +36 -0
- package/dist/types/prompt/composer-attachments.d.ts +5 -2
- package/dist/types/prompt/composer-cache.d.ts +7 -2
- package/dist/types/prompt/composer.d.ts +6 -11
- package/dist/types/prompt/custom-editor.d.ts +8 -2
- package/dist/types/prompt/gradient-highlight.d.ts +2 -2
- package/dist/types/prompt/magic-keywords.d.ts +2 -0
- package/dist/types/prompt/model-mention-autocomplete.d.ts +9 -7
- package/dist/types/prompt/model-mention-syntax.d.ts +6 -0
- package/dist/types/prompt/prompt-action-autocomplete.d.ts +2 -1
- package/dist/types/prompt/welcome.d.ts +19 -0
- package/dist/types/render/extension-links.d.ts +0 -6
- package/dist/types/render/index.d.ts +1 -0
- package/dist/types/render/link-hints.d.ts +78 -0
- package/dist/types/render/render-utils.d.ts +0 -2
- package/dist/types/setup/scenes/types.d.ts +8 -0
- package/dist/types/setup/scenes/updates.d.ts +6 -0
- package/dist/types/setup/wizard.d.ts +7 -2
- package/dist/types/spinner-clock.d.ts +34 -0
- package/dist/types/status-line/component.d.ts +8 -4
- package/dist/types/status-line/host.d.ts +62 -0
- package/dist/types/status-line/index.d.ts +1 -0
- package/dist/types/status-line/prompt-cache.d.ts +14 -0
- package/dist/types/status-line/schema.d.ts +1 -1
- package/dist/types/status-line/startup.d.ts +6 -0
- package/dist/types/status-line/types.d.ts +8 -21
- package/dist/types/theme/schema.d.ts +28 -1
- package/dist/types/theme/symbols.d.ts +1 -1
- package/dist/types/theme/theme-class.d.ts +12 -2
- package/dist/types/theme/theme.d.ts +1 -1
- package/dist/types/theme/tui-adapters.d.ts +7 -0
- package/dist/types/thinking.d.ts +12 -0
- package/dist/types/tools/ask.d.ts +1 -1
- package/dist/types/tools/bash.d.ts +21 -0
- package/dist/types/tools/find.d.ts +9 -1
- package/dist/types/tools/grep.d.ts +2 -1
- package/dist/types/tools/grouped-file-output.d.ts +17 -0
- package/dist/types/tools/job-widget.d.ts +2 -2
- package/dist/types/tools/lsp.d.ts +4 -2
- package/dist/types/tools/native-view.d.ts +4 -0
- package/dist/types/tools/renderer.d.ts +9 -1
- package/dist/types/tools/shell-trace.d.ts +10 -0
- package/dist/types/tools/shell-viz-render.d.ts +6 -0
- package/dist/types/tools/shell-viz.d.ts +16 -0
- package/dist/types/tools/wait.d.ts +2 -2
- package/dist/types/tools/web-search-types.d.ts +1 -0
- package/dist/types/tools/write.d.ts +2 -0
- package/dist/types/tui.d.ts +15 -1
- package/package.json +15 -11
- package/src/apps/shell-visualizer.d.ts +24 -0
- package/src/apps/shell-visualizer.ts +167 -0
- package/src/autocomplete.d.ts +20 -0
- package/src/autocomplete.ts +14 -0
- package/src/chat/assistant-message.ts +11 -6
- package/src/chat/cache-invalidation-marker.d.ts +15 -7
- package/src/chat/cache-invalidation-marker.ts +18 -9
- package/src/chat/chat-transcript-builder.d.ts +5 -3
- package/src/chat/chat-transcript-builder.ts +16 -12
- package/src/chat/display-preferences.d.ts +2 -0
- package/src/chat/display-preferences.ts +3 -0
- package/src/chat/extension-types.d.ts +72 -1
- package/src/chat/extension-types.ts +74 -1
- package/src/chat/image-loading.d.ts +2 -2
- package/src/chat/image-loading.ts +2 -2
- package/src/chat/messages.d.ts +2 -3
- package/src/chat/messages.ts +3 -8
- package/src/chat/read-tool-group.d.ts +15 -2
- package/src/chat/read-tool-group.ts +201 -41
- package/src/chat/skill-message.d.ts +1 -0
- package/src/chat/skill-message.ts +4 -0
- package/src/chat/spotlight.d.ts +203 -0
- package/src/chat/spotlight.ts +460 -0
- package/src/chat/tool-execution.d.ts +26 -5
- package/src/chat/tool-execution.ts +360 -38
- package/src/chat/transcript-actions.d.ts +11 -0
- package/src/chat/transcript-actions.ts +13 -1
- package/src/chat/transcript-browser.d.ts +9 -0
- package/src/chat/transcript-browser.ts +18 -0
- package/src/chat/transcript-presentation.d.ts +164 -0
- package/src/chat/transcript-presentation.ts +642 -0
- package/src/chat/ttsr-notification.d.ts +25 -0
- package/src/chat/ttsr-notification.ts +5 -0
- package/src/chrome/message-frame.d.ts +2 -0
- package/src/chrome/message-frame.ts +7 -0
- package/src/chrome/message-notice.d.ts +58 -0
- package/src/chrome/transcript-container.d.ts +27 -6
- package/src/chrome/transcript-container.ts +317 -66
- package/src/components/editor.ts +25 -1
- package/src/components/loader.d.ts +0 -2
- package/src/components/loader.ts +30 -18
- package/src/components/markdown.d.ts +11 -1
- package/src/components/markdown.ts +41 -16
- package/src/components/settings-list.d.ts +12 -2
- package/src/components/settings-list.ts +29 -13
- package/src/frame-rate.d.ts +18 -0
- package/src/frame-rate.ts +36 -0
- package/src/hotkeys-markdown.ts +9 -2
- package/src/index.d.ts +3 -0
- package/src/index.ts +3 -0
- package/src/keybinding-matchers.d.ts +4 -1
- package/src/keybinding-matchers.ts +13 -12
- package/src/kitty-graphics.d.ts +1 -1
- package/src/kitty-graphics.ts +3 -2
- package/src/motion-effects.d.ts +10 -0
- package/src/motion-effects.ts +27 -0
- package/src/native/backend.ts +66 -7
- package/src/native/encode.d.ts +2 -0
- package/src/native/encode.ts +2 -0
- package/src/native/measure.d.ts +10 -0
- package/src/native/measure.ts +185 -0
- package/src/native/overlay.d.ts +1 -1
- package/src/native/overlay.ts +1 -1
- package/src/native/quiet.d.ts +5 -0
- package/src/native/quiet.ts +105 -0
- package/src/native/reconcile.d.ts +6 -1
- package/src/native/reconcile.ts +16 -10
- package/src/native/spans.d.ts +6 -0
- package/src/native/spans.ts +40 -0
- package/src/native/state.d.ts +4 -0
- package/src/native/state.ts +18 -0
- package/src/overlays/agent-hub.ts +15 -2
- package/src/overlays/ask-dialog.ts +1 -0
- package/src/overlays/btw-history-panel.ts +73 -6
- package/src/overlays/link-browser.ts +295 -0
- package/src/overlays/running-subagent-badge.ts +2 -9
- package/src/overlays/settings-defs.ts +1 -1
- package/src/overlays/settings-selector.ts +17 -3
- package/src/overlays/spotlight-sheet.ts +478 -0
- package/src/overlays/usage-dashboard.ts +6 -5
- package/src/prompt/composer-attachments.d.ts +5 -2
- package/src/prompt/composer-attachments.ts +6 -6
- package/src/prompt/composer-cache.ts +17 -16
- package/src/prompt/composer.ts +30 -123
- package/src/prompt/custom-editor.ts +17 -13
- package/src/prompt/gradient-highlight.d.ts +2 -2
- package/src/prompt/gradient-highlight.ts +5 -4
- package/src/prompt/magic-keywords.d.ts +2 -0
- package/src/prompt/magic-keywords.ts +4 -1
- package/src/prompt/model-mention-autocomplete.ts +73 -20
- package/src/prompt/model-mention-syntax.d.ts +6 -0
- package/src/prompt/model-mention-syntax.ts +9 -0
- package/src/prompt/prompt-action-autocomplete.ts +49 -33
- package/src/prompt/tips.txt +1 -0
- package/src/prompt/welcome.ts +104 -2
- package/src/render/extension-links.d.ts +0 -6
- package/src/render/extension-links.ts +0 -20
- package/src/render/index.d.ts +1 -0
- package/src/render/index.ts +1 -0
- package/src/render/link-hints.d.ts +78 -0
- package/src/render/link-hints.ts +299 -0
- package/src/render/render-utils.d.ts +0 -2
- package/src/render/render-utils.ts +0 -5
- package/src/setup/scenes/glyph.ts +1 -1
- package/src/setup/scenes/types.ts +8 -0
- package/src/setup/scenes/updates.ts +116 -0
- package/src/setup/wizard.ts +19 -8
- package/src/spinner-clock.d.ts +34 -0
- package/src/spinner-clock.ts +79 -0
- package/src/status-line/component.ts +145 -53
- package/src/status-line/host.ts +51 -0
- package/src/status-line/index.ts +1 -0
- package/src/status-line/presets.ts +3 -1
- package/src/status-line/prompt-cache.ts +154 -0
- package/src/status-line/schema.ts +1 -1
- package/src/status-line/segments.ts +33 -22
- package/src/status-line/startup.ts +22 -4
- package/src/status-line/types.ts +8 -22
- package/src/stdin-buffer.ts +89 -46
- package/src/terminal-capabilities.ts +3 -3
- package/src/terminal.ts +1 -8
- package/src/theme/loader.ts +3 -2
- package/src/theme/schema.d.ts +28 -1
- package/src/theme/schema.ts +30 -1
- package/src/theme/symbols.d.ts +1 -1
- package/src/theme/symbols.ts +15 -3
- package/src/theme/theme-class.d.ts +12 -2
- package/src/theme/theme-class.ts +23 -0
- package/src/theme/theme-schema.json +1 -1
- package/src/theme/theme.d.ts +1 -1
- package/src/theme/theme.ts +3 -7
- package/src/theme/tui-adapters.d.ts +7 -0
- package/src/theme/tui-adapters.ts +33 -1
- package/src/thinking.d.ts +12 -0
- package/src/thinking.ts +31 -0
- package/src/tools/ask.d.ts +1 -1
- package/src/tools/ask.ts +99 -38
- package/src/tools/ast-edit.ts +51 -32
- package/src/tools/ast-grep.ts +31 -19
- package/src/tools/bash.d.ts +21 -0
- package/src/tools/bash.ts +166 -24
- package/src/tools/find.d.ts +9 -1
- package/src/tools/find.ts +23 -2
- package/src/tools/grep.d.ts +2 -1
- package/src/tools/grep.ts +52 -36
- package/src/tools/grouped-file-output.d.ts +17 -0
- package/src/tools/grouped-file-output.ts +20 -2
- package/src/tools/job-widget.d.ts +2 -2
- package/src/tools/job-widget.ts +2 -2
- package/src/tools/lsp.d.ts +4 -2
- package/src/tools/lsp.ts +537 -642
- package/src/tools/native-view.d.ts +4 -0
- package/src/tools/native-view.ts +8 -2
- package/src/tools/renderer.d.ts +9 -1
- package/src/tools/renderer.ts +9 -1
- package/src/tools/shell-trace.d.ts +10 -0
- package/src/tools/shell-trace.ts +80 -0
- package/src/tools/shell-viz-render.d.ts +6 -0
- package/src/tools/shell-viz-render.ts +156 -0
- package/src/tools/shell-viz.d.ts +16 -0
- package/src/tools/shell-viz.ts +181 -0
- package/src/tools/streaming-output.ts +18 -8
- package/src/tools/wait.d.ts +2 -2
- package/src/tools/wait.ts +39 -34
- package/src/tools/web-search-types.d.ts +1 -0
- package/src/tools/web-search-types.ts +1 -0
- package/src/tools/write.d.ts +2 -0
- package/src/tools/write.ts +2 -0
- package/src/tui.d.ts +15 -1
- package/src/tui.ts +63 -6
- package/src/windows-input-mode.ts +7 -1
- package/dist/types/chat/collab-prompt-message.d.ts +0 -14
- package/dist/types/chrome/collab-qrcode.d.ts +0 -35
- package/src/chat/collab-prompt-message.d.ts +0 -14
- package/src/chat/collab-prompt-message.ts +0 -46
- package/src/chrome/collab-qrcode.ts +0 -99
package/src/tools/bash.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Component } from "../tui";
|
|
2
|
-
import { getProjectDir, jsonContainerEnd } from "@linxiraos/pi-utils";
|
|
2
|
+
import { getProjectDir, jsonContainerEnd, sanitizeText } from "@linxiraos/pi-utils";
|
|
3
3
|
import { highlightCode, type Theme } from "../theme/theme";
|
|
4
4
|
import { renderStatusLine } from "../render/status-line";
|
|
5
5
|
import { framedToolCard, type ToolCardSnapshot } from "../render/tool-card";
|
|
@@ -27,9 +27,20 @@ import type {
|
|
|
27
27
|
RenderResultOptions,
|
|
28
28
|
ToolRenderer,
|
|
29
29
|
} from "./renderer";
|
|
30
|
-
import { INTENT_FIELD, type TspTone } from "@linxiraos/pi-wire";
|
|
30
|
+
import { INTENT_FIELD, type ShellTrace, type ShellVizPresentation, type TspTone } from "@linxiraos/pi-wire";
|
|
31
|
+
import type { SpotlightDetails } from "../chat/spotlight";
|
|
31
32
|
import { plainText } from "../native/spans";
|
|
32
|
-
import {
|
|
33
|
+
import {
|
|
34
|
+
RUN_INPUT_PREVIEW_LINES,
|
|
35
|
+
resultText,
|
|
36
|
+
runBox,
|
|
37
|
+
runFoot,
|
|
38
|
+
runInput,
|
|
39
|
+
runOutput,
|
|
40
|
+
type RunState,
|
|
41
|
+
} from "./native-view";
|
|
42
|
+
import { renderShellVisualization, shellVizText } from "./shell-viz-render";
|
|
43
|
+
import { node } from "../native/describe";
|
|
33
44
|
|
|
34
45
|
/** Default collapsed shell output preview height. */
|
|
35
46
|
export const BASH_DEFAULT_PREVIEW_LINES = DEFAULT_TERMINAL_PREVIEW_LINES;
|
|
@@ -72,6 +83,21 @@ export interface BashToolDetails {
|
|
|
72
83
|
timedOut?: boolean;
|
|
73
84
|
/** Text the command wrote to `out://`, oldest first; transcripts draw each as a reply after the call. */
|
|
74
85
|
replies?: string[];
|
|
86
|
+
/**
|
|
87
|
+
* The embedded shell's live trace of the command (pi-shell `RunTrace`): every frame carries the
|
|
88
|
+
* latest snapshot and the final result the last one. Absent on the PTY and user-shell paths.
|
|
89
|
+
*/
|
|
90
|
+
trace?: ShellTrace;
|
|
91
|
+
/**
|
|
92
|
+
* Working directory the command ran in when the call set one, explicitly or by the
|
|
93
|
+
* executor hoisting a leading `cd <dir>`; absent when it ran in the session cwd.
|
|
94
|
+
* Pairs with {@link trace}: the traced script is the command after hoisting.
|
|
95
|
+
*/
|
|
96
|
+
cwd?: string;
|
|
97
|
+
/** `;` when the hoisted leading cd was `cd <dir>;`, so the card redraws it as written; absent means `&&`. */
|
|
98
|
+
cdSeparator?: ";";
|
|
99
|
+
/** What the session's Spotlight shaping did to the output. */
|
|
100
|
+
spotlight?: SpotlightDetails;
|
|
75
101
|
/** Live ACP update only; completed results refer to released terminals. */
|
|
76
102
|
terminalId?: string;
|
|
77
103
|
service?: {
|
|
@@ -90,7 +116,7 @@ export interface BashToolDetails {
|
|
|
90
116
|
}
|
|
91
117
|
|
|
92
118
|
function escapeBashEnvValueForDisplay(value: unknown): string {
|
|
93
|
-
return String(value)
|
|
119
|
+
return sanitizeText(String(value))
|
|
94
120
|
.replaceAll("\\", "\\\\")
|
|
95
121
|
.replaceAll("\n", "\\n")
|
|
96
122
|
.replaceAll("\r", "\\r")
|
|
@@ -104,7 +130,7 @@ function formatBashEnvAssignments(env: Record<string, unknown> | undefined): str
|
|
|
104
130
|
if (!env || Object.keys(env).length === 0) return "";
|
|
105
131
|
return Object.entries(env)
|
|
106
132
|
.sort(([a], [b]) => a.localeCompare(b))
|
|
107
|
-
.map(([key, value]) => `${key}="${escapeBashEnvValueForDisplay(value)}"`)
|
|
133
|
+
.map(([key, value]) => `${shellVizText(key)}="${escapeBashEnvValueForDisplay(value)}"`)
|
|
108
134
|
.join(" ");
|
|
109
135
|
}
|
|
110
136
|
|
|
@@ -216,6 +242,8 @@ export interface BashRenderArgs {
|
|
|
216
242
|
env?: Record<string, unknown>;
|
|
217
243
|
timeout?: number;
|
|
218
244
|
cwd?: string;
|
|
245
|
+
/** How the `cd <dir>` prefix joins the command: `;` as written by the model, else `&&`. */
|
|
246
|
+
cdSeparator?: ";";
|
|
219
247
|
__partialJson?: string;
|
|
220
248
|
[key: string]: unknown;
|
|
221
249
|
}
|
|
@@ -267,19 +295,23 @@ export function getBashEnvForDisplay(args: BashRenderArgs): Record<string, unkno
|
|
|
267
295
|
* `theme.fg("dim", ...)` form render only the first line as dim.
|
|
268
296
|
*/
|
|
269
297
|
export function formatBashCommandLines(args: BashRenderArgs, uiTheme: Theme): string[] {
|
|
270
|
-
const command = replaceTabs(args.command || "…");
|
|
271
|
-
const
|
|
272
|
-
const displayWorkdir = formatToolWorkingDirectory(args.cwd, cwd);
|
|
273
|
-
const envAssignments = formatBashEnvAssignments(getBashEnvForDisplay(args));
|
|
274
|
-
const prefixParts = ["$"];
|
|
275
|
-
if (displayWorkdir) prefixParts.push(`cd ${displayWorkdir} &&`);
|
|
276
|
-
if (envAssignments) prefixParts.push(envAssignments);
|
|
277
|
-
const prefix = uiTheme.fg("dim", `${prefixParts.join(" ")} `);
|
|
298
|
+
const command = replaceTabs(sanitizeText(args.command || "…"));
|
|
299
|
+
const prefix = bashCommandPrefix(args, uiTheme);
|
|
278
300
|
const highlightedLines = highlightCode(command, "bash");
|
|
279
301
|
if (highlightedLines.length === 0) return [prefix.trimEnd()];
|
|
280
302
|
return highlightedLines.map((line, i) => (i === 0 ? `${prefix}${line}` : line));
|
|
281
303
|
}
|
|
282
304
|
|
|
305
|
+
/** The dim `$ cd <dir> && NAME="…" ` prefix ahead of a command's first line (trailing space included). */
|
|
306
|
+
export function bashCommandPrefix(args: BashRenderArgs, uiTheme: Theme): string {
|
|
307
|
+
const displayWorkdir = formatToolWorkingDirectory(args.cwd, getProjectDir());
|
|
308
|
+
const envAssignments = formatBashEnvAssignments(getBashEnvForDisplay(args));
|
|
309
|
+
const prefixParts = ["$"];
|
|
310
|
+
if (displayWorkdir) prefixParts.push(cdPrefix(displayWorkdir, args.cdSeparator));
|
|
311
|
+
if (envAssignments) prefixParts.push(envAssignments);
|
|
312
|
+
return uiTheme.fg("dim", `${prefixParts.join(" ")} `);
|
|
313
|
+
}
|
|
314
|
+
|
|
283
315
|
/**
|
|
284
316
|
* Plain (unstyled) command line for native views: `cd <dir> && NAME="…" <command>`,
|
|
285
317
|
* built from the same decoded display args (incl. streamed `__partialJson` env) as the ANSI path.
|
|
@@ -288,12 +320,17 @@ export function formatBashCommandText(args: BashRenderArgs): string {
|
|
|
288
320
|
const displayWorkdir = formatToolWorkingDirectory(args.cwd, getProjectDir());
|
|
289
321
|
const envAssignments = formatBashEnvAssignments(getBashEnvForDisplay(args));
|
|
290
322
|
const parts: string[] = [];
|
|
291
|
-
if (displayWorkdir) parts.push(
|
|
323
|
+
if (displayWorkdir) parts.push(cdPrefix(displayWorkdir, args.cdSeparator));
|
|
292
324
|
if (envAssignments) parts.push(envAssignments);
|
|
293
|
-
parts.push(args.command || "…");
|
|
325
|
+
parts.push(replaceTabs(sanitizeText(args.command || "…")));
|
|
294
326
|
return parts.join(" ");
|
|
295
327
|
}
|
|
296
328
|
|
|
329
|
+
/** `cd <dir> &&`, or `cd <dir>;` when the model wrote the hoisted cd with `;`. */
|
|
330
|
+
function cdPrefix(displayWorkdir: string, separator: ";" | undefined): string {
|
|
331
|
+
return `cd ${shellVizText(displayWorkdir)}${separator ?? " &&"}`;
|
|
332
|
+
}
|
|
333
|
+
|
|
297
334
|
/** Bash output with the LLM-facing notices (background, exit, wall time, artifact, truncation) removed. */
|
|
298
335
|
function stripBashNotices(
|
|
299
336
|
rawOutput: string,
|
|
@@ -440,6 +477,30 @@ function toBashRenderArgs<TArgs>(args: TArgs | undefined, config: ShellRendererC
|
|
|
440
477
|
};
|
|
441
478
|
}
|
|
442
479
|
|
|
480
|
+
/** Command-pane lines for the traced script, prefixed with the directory it actually ran in. */
|
|
481
|
+
function visualCommandLines(
|
|
482
|
+
presentation: ShellVizPresentation,
|
|
483
|
+
args: BashRenderArgs,
|
|
484
|
+
details: BashToolDetails | undefined,
|
|
485
|
+
uiTheme: Theme,
|
|
486
|
+
width: number,
|
|
487
|
+
): string[] {
|
|
488
|
+
const scriptArgs = executedScriptArgs(args, details);
|
|
489
|
+
const prefix = bashCommandPrefix(scriptArgs, uiTheme);
|
|
490
|
+
const hasContext =
|
|
491
|
+
!!formatToolWorkingDirectory(scriptArgs.cwd, getProjectDir()) ||
|
|
492
|
+
!!formatBashEnvAssignments(getBashEnvForDisplay(scriptArgs));
|
|
493
|
+
return [...(hasContext ? [prefix.trimEnd()] : []), ...renderShellVisualization(presentation, uiTheme, width, false)];
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Display args for the executed script: the trace holds the command after the executor
|
|
498
|
+
* hoisted any leading `cd`, so its directory comes from the result, not the raw args.
|
|
499
|
+
*/
|
|
500
|
+
function executedScriptArgs(args: BashRenderArgs, details: BashToolDetails | undefined): BashRenderArgs {
|
|
501
|
+
return details?.cwd === undefined ? args : { ...args, cwd: details.cwd, cdSeparator: details.cdSeparator };
|
|
502
|
+
}
|
|
503
|
+
|
|
443
504
|
/** Builds a shell transcript renderer with caller-supplied command labels. */
|
|
444
505
|
export function createShellRenderer<TArgs>(config: ShellRendererConfig<TArgs>) {
|
|
445
506
|
return {
|
|
@@ -449,8 +510,11 @@ export function createShellRenderer<TArgs>(config: ShellRendererConfig<TArgs>) {
|
|
|
449
510
|
// expensive part: defer it to the first paint, once per component,
|
|
450
511
|
// so a rebuild that is replaced before painting never pays for it.
|
|
451
512
|
let cmdLines: string[] | undefined;
|
|
452
|
-
return framedToolCard(uiTheme, () => {
|
|
453
|
-
|
|
513
|
+
return framedToolCard(uiTheme, ({ contentWidth }) => {
|
|
514
|
+
const presentation = options.shellPresentation;
|
|
515
|
+
cmdLines = presentation
|
|
516
|
+
? visualCommandLines(presentation, renderArgs, undefined, uiTheme, contentWidth)
|
|
517
|
+
: (cmdLines ?? formatBashCommandLines(renderArgs, uiTheme));
|
|
454
518
|
const header =
|
|
455
519
|
config.showHeader === false
|
|
456
520
|
? undefined
|
|
@@ -526,6 +590,8 @@ export function createShellRenderer<TArgs>(config: ShellRendererConfig<TArgs>) {
|
|
|
526
590
|
let cachedPreviewWindow: number | undefined;
|
|
527
591
|
let cachedSnapshot: ToolCardSnapshot | undefined;
|
|
528
592
|
let cachedElapsedSecond: number | undefined;
|
|
593
|
+
let cachedTraceKey: string | undefined;
|
|
594
|
+
let cachedPresentation: ShellVizPresentation | undefined;
|
|
529
595
|
const dropSnapshot = () => {
|
|
530
596
|
cachedSnapshot = undefined;
|
|
531
597
|
cachedWidth = undefined;
|
|
@@ -535,6 +601,8 @@ export function createShellRenderer<TArgs>(config: ShellRendererConfig<TArgs>) {
|
|
|
535
601
|
cachedIsPartial = undefined;
|
|
536
602
|
cachedPreviewWindow = undefined;
|
|
537
603
|
cachedElapsedSecond = undefined;
|
|
604
|
+
cachedTraceKey = undefined;
|
|
605
|
+
cachedPresentation = undefined;
|
|
538
606
|
};
|
|
539
607
|
|
|
540
608
|
return framedToolCard(
|
|
@@ -548,7 +616,10 @@ export function createShellRenderer<TArgs>(config: ShellRendererConfig<TArgs>) {
|
|
|
548
616
|
// Get output from context (preferred) or fall back to result content.
|
|
549
617
|
// Strip the LLM-facing notice appended by wrappedExecute so we don't
|
|
550
618
|
// double-print it alongside the styled warning line below.
|
|
551
|
-
const rawOutput =
|
|
619
|
+
const rawOutput =
|
|
620
|
+
options.shellTrace && options.shellPresentation
|
|
621
|
+
? sanitizeText(options.shellPresentation.output)
|
|
622
|
+
: (renderContext?.output ?? result.content?.find(c => c.type === "text")?.text ?? "");
|
|
552
623
|
|
|
553
624
|
const isPartial = options.isPartial === true;
|
|
554
625
|
const previewWindow = previewWindowRows();
|
|
@@ -557,6 +628,13 @@ export function createShellRenderer<TArgs>(config: ShellRendererConfig<TArgs>) {
|
|
|
557
628
|
// second instead of rebuilding every spinner frame.
|
|
558
629
|
const liveElapsedMs = isPartial && details?.wallTimeMs === undefined ? options.elapsedMs : undefined;
|
|
559
630
|
const elapsedSecond = liveElapsedMs === undefined ? undefined : Math.floor(liveElapsedMs / 1000);
|
|
631
|
+
// A traced command redraws on every folded event; its running
|
|
632
|
+
// glyphs spin with the frame (only while the run is live).
|
|
633
|
+
const trace = options.shellTrace ?? details?.trace;
|
|
634
|
+
const traceKey =
|
|
635
|
+
trace === undefined
|
|
636
|
+
? undefined
|
|
637
|
+
: `${trace.seq}:${trace.status === undefined ? (options.spinnerFrame ?? "") : ""}`;
|
|
560
638
|
|
|
561
639
|
if (
|
|
562
640
|
cachedSnapshot !== undefined &&
|
|
@@ -566,7 +644,9 @@ export function createShellRenderer<TArgs>(config: ShellRendererConfig<TArgs>) {
|
|
|
566
644
|
cachedRawOutput === rawOutput &&
|
|
567
645
|
cachedIsPartial === isPartial &&
|
|
568
646
|
cachedPreviewWindow === previewWindow &&
|
|
569
|
-
cachedElapsedSecond === elapsedSecond
|
|
647
|
+
cachedElapsedSecond === elapsedSecond &&
|
|
648
|
+
cachedTraceKey === traceKey &&
|
|
649
|
+
cachedPresentation === options.shellPresentation
|
|
570
650
|
) {
|
|
571
651
|
return cachedSnapshot;
|
|
572
652
|
}
|
|
@@ -618,13 +698,29 @@ export function createShellRenderer<TArgs>(config: ShellRendererConfig<TArgs>) {
|
|
|
618
698
|
const snapshot: ToolCardSnapshot = {
|
|
619
699
|
header,
|
|
620
700
|
phase: isPartial ? "partial" : isError ? (isTimeout ? "warning" : "error") : "success",
|
|
701
|
+
// Shell cards keep the neutral segmented look in every phase: the
|
|
702
|
+
// phase colours status and border, never a background wash. A
|
|
703
|
+
// settled success names its default dim border, so a native host
|
|
704
|
+
// drawing this card gets a muted tone rather than a success tint.
|
|
705
|
+
applyBg: false,
|
|
706
|
+
borderColor: success ? "dim" : undefined,
|
|
621
707
|
footerMeta,
|
|
622
708
|
sections: [
|
|
623
709
|
{
|
|
624
710
|
// Viewport-sized tail window in every state — streaming and final
|
|
625
711
|
// render identically; only ctrl+o uncaps.
|
|
626
712
|
content: capPreviewLines(
|
|
627
|
-
|
|
713
|
+
trace !== undefined && options.shellPresentation
|
|
714
|
+
? visualCommandLines(
|
|
715
|
+
options.shellPresentation,
|
|
716
|
+
renderArgs,
|
|
717
|
+
details,
|
|
718
|
+
uiTheme,
|
|
719
|
+
contentWidth,
|
|
720
|
+
)
|
|
721
|
+
: args
|
|
722
|
+
? (cmdLines ??= formatBashCommandLines(renderArgs, uiTheme))
|
|
723
|
+
: [],
|
|
628
724
|
uiTheme,
|
|
629
725
|
{ expanded },
|
|
630
726
|
),
|
|
@@ -640,6 +736,8 @@ export function createShellRenderer<TArgs>(config: ShellRendererConfig<TArgs>) {
|
|
|
640
736
|
cachedIsPartial = isPartial;
|
|
641
737
|
cachedPreviewWindow = previewWindow;
|
|
642
738
|
cachedElapsedSecond = elapsedSecond;
|
|
739
|
+
cachedTraceKey = traceKey;
|
|
740
|
+
cachedPresentation = options.shellPresentation;
|
|
643
741
|
cachedSnapshot = snapshot;
|
|
644
742
|
return snapshot;
|
|
645
743
|
},
|
|
@@ -655,7 +753,21 @@ export function createShellRenderer<TArgs>(config: ShellRendererConfig<TArgs>) {
|
|
|
655
753
|
body: [
|
|
656
754
|
runBox(
|
|
657
755
|
[
|
|
658
|
-
|
|
756
|
+
options.shell && options.shellPresentation
|
|
757
|
+
? node(
|
|
758
|
+
"shell",
|
|
759
|
+
{
|
|
760
|
+
role: SHELL_INPUT.role,
|
|
761
|
+
presentation: options.shellPresentation,
|
|
762
|
+
lang: "bash",
|
|
763
|
+
replayEpoch: options.shellReplayEpoch,
|
|
764
|
+
liveOrigin: options.executionStarted,
|
|
765
|
+
preview: { lines: RUN_INPUT_PREVIEW_LINES },
|
|
766
|
+
},
|
|
767
|
+
undefined,
|
|
768
|
+
"input",
|
|
769
|
+
)
|
|
770
|
+
: runInput(command, SHELL_INPUT),
|
|
659
771
|
started &&
|
|
660
772
|
runFoot({ state: options.cancelled ? "cancelled" : "running", elapsedMs: options.elapsedMs }),
|
|
661
773
|
],
|
|
@@ -663,6 +775,8 @@ export function createShellRenderer<TArgs>(config: ShellRendererConfig<TArgs>) {
|
|
|
663
775
|
),
|
|
664
776
|
],
|
|
665
777
|
preview: "children",
|
|
778
|
+
// The head stays outside: the segmented run box is the card's only frame.
|
|
779
|
+
inline: true,
|
|
666
780
|
};
|
|
667
781
|
},
|
|
668
782
|
|
|
@@ -684,7 +798,8 @@ export function createShellRenderer<TArgs>(config: ShellRendererConfig<TArgs>) {
|
|
|
684
798
|
const output = stripped.text.trimEnd();
|
|
685
799
|
const expanded = renderContext?.expanded ?? options.expanded;
|
|
686
800
|
const showingFullOutput = expanded && renderContext?.isFullOutput === true;
|
|
687
|
-
const
|
|
801
|
+
const renderArgs = toBashRenderArgs(args, config);
|
|
802
|
+
const command = formatBashCommandText(renderArgs);
|
|
688
803
|
const previewLines = renderContext?.previewLines ?? BASH_DEFAULT_PREVIEW_LINES;
|
|
689
804
|
const state = shellRunState(details, isError, isPartial, options.cancelled === true);
|
|
690
805
|
// Live (a running call, or a parked job still streaming): the call's clock. Settled: the
|
|
@@ -695,10 +810,36 @@ export function createShellRenderer<TArgs>(config: ShellRendererConfig<TArgs>) {
|
|
|
695
810
|
? undefined
|
|
696
811
|
: (details?.wallTimeMs ?? options.elapsedMs);
|
|
697
812
|
const meta = details?.meta;
|
|
813
|
+
// Native hosts render the same engine-produced presentation as the ANSI inspector.
|
|
814
|
+
const trace = options.shell === true ? (options.shellTrace ?? details?.trace) : undefined;
|
|
815
|
+
const presentation = options.shell === true && trace ? options.shellPresentation : undefined;
|
|
816
|
+
// The shell node is the command pane only; the run's ordinary output
|
|
817
|
+
// segment draws what ran: the live result, or the output retained up
|
|
818
|
+
// to the replay cursor while one is held.
|
|
819
|
+
const shownOutput = presentation?.preferences.cursor !== undefined ? presentation.output.trimEnd() : output;
|
|
820
|
+
const displayWorkdir = formatToolWorkingDirectory(
|
|
821
|
+
executedScriptArgs(renderArgs, details).cwd,
|
|
822
|
+
getProjectDir(),
|
|
823
|
+
);
|
|
698
824
|
const box = runBox(
|
|
699
825
|
[
|
|
700
|
-
|
|
701
|
-
|
|
826
|
+
presentation
|
|
827
|
+
? node(
|
|
828
|
+
"shell",
|
|
829
|
+
{
|
|
830
|
+
role: SHELL_INPUT.role,
|
|
831
|
+
presentation,
|
|
832
|
+
replayEpoch: options.shellReplayEpoch,
|
|
833
|
+
liveOrigin: options.executionStarted,
|
|
834
|
+
...(displayWorkdir ? { cwd: displayWorkdir } : {}),
|
|
835
|
+
lang: "bash",
|
|
836
|
+
preview: { lines: RUN_INPUT_PREVIEW_LINES },
|
|
837
|
+
},
|
|
838
|
+
undefined,
|
|
839
|
+
"input",
|
|
840
|
+
)
|
|
841
|
+
: runInput(command, SHELL_INPUT),
|
|
842
|
+
shownOutput.trim().length > 0 && runOutput(shownOutput, { role: "zeta.tool.bash.output", previewLines }),
|
|
702
843
|
runFoot({
|
|
703
844
|
state,
|
|
704
845
|
exitCode: details?.exitCode,
|
|
@@ -714,6 +855,7 @@ export function createShellRenderer<TArgs>(config: ShellRendererConfig<TArgs>) {
|
|
|
714
855
|
body: [box],
|
|
715
856
|
tone: state === "timed-out" ? "warning" : undefined,
|
|
716
857
|
preview: "children",
|
|
858
|
+
inline: true,
|
|
717
859
|
};
|
|
718
860
|
},
|
|
719
861
|
mergeCallAndResult: true,
|
package/src/tools/find.d.ts
CHANGED
|
@@ -25,9 +25,15 @@ export interface FindHit {
|
|
|
25
25
|
/**
|
|
26
26
|
* How much of a search the judge actually covered. `unavailable`: every judge
|
|
27
27
|
* request failed, so an empty result is not evidence of absence. `partial`:
|
|
28
|
-
* some requests failed
|
|
28
|
+
* some requests failed, or the call's deadline cut verification short.
|
|
29
|
+
* `complete`: none failed (or none were needed).
|
|
29
30
|
*/
|
|
30
31
|
export type FindCoverage = "complete" | "partial" | "unavailable";
|
|
32
|
+
/** Verification cut short by the call's deadline: complete passages verified of those routed to it. */
|
|
33
|
+
export interface FindTimeout {
|
|
34
|
+
verified: number;
|
|
35
|
+
passages: number;
|
|
36
|
+
}
|
|
31
37
|
/** Search accounting reported alongside the hits. */
|
|
32
38
|
export interface FindStats {
|
|
33
39
|
/** Eligible files under the root. */
|
|
@@ -62,6 +68,8 @@ export interface FindToolDetails {
|
|
|
62
68
|
hits: FindHit[];
|
|
63
69
|
coverage: FindCoverage;
|
|
64
70
|
stats: FindStats;
|
|
71
|
+
/** Set when the deadline ended verification; the hits are those verified before it. */
|
|
72
|
+
timeout?: FindTimeout;
|
|
65
73
|
elapsedMs: number;
|
|
66
74
|
/** Session cwd; hit paths are relative to it. */
|
|
67
75
|
cwd: string;
|
package/src/tools/find.ts
CHANGED
|
@@ -61,10 +61,17 @@ export interface FindHit {
|
|
|
61
61
|
/**
|
|
62
62
|
* How much of a search the judge actually covered. `unavailable`: every judge
|
|
63
63
|
* request failed, so an empty result is not evidence of absence. `partial`:
|
|
64
|
-
* some requests failed
|
|
64
|
+
* some requests failed, or the call's deadline cut verification short.
|
|
65
|
+
* `complete`: none failed (or none were needed).
|
|
65
66
|
*/
|
|
66
67
|
export type FindCoverage = "complete" | "partial" | "unavailable";
|
|
67
68
|
|
|
69
|
+
/** Verification cut short by the call's deadline: complete passages verified of those routed to it. */
|
|
70
|
+
export interface FindTimeout {
|
|
71
|
+
verified: number;
|
|
72
|
+
passages: number;
|
|
73
|
+
}
|
|
74
|
+
|
|
68
75
|
/** Search accounting reported alongside the hits. */
|
|
69
76
|
export interface FindStats {
|
|
70
77
|
/** Eligible files under the root. */
|
|
@@ -100,6 +107,8 @@ export interface FindToolDetails {
|
|
|
100
107
|
hits: FindHit[];
|
|
101
108
|
coverage: FindCoverage;
|
|
102
109
|
stats: FindStats;
|
|
110
|
+
/** Set when the deadline ended verification; the hits are those verified before it. */
|
|
111
|
+
timeout?: FindTimeout;
|
|
103
112
|
elapsedMs: number;
|
|
104
113
|
/** Session cwd; hit paths are relative to it. */
|
|
105
114
|
cwd: string;
|
|
@@ -304,6 +313,9 @@ export const findToolRenderer = {
|
|
|
304
313
|
];
|
|
305
314
|
const failed = stats.failed > 0 ? `${stats.failed}/${stats.requests} requests failed` : undefined;
|
|
306
315
|
if (failed) meta.push(uiTheme.fg("warning", failed));
|
|
316
|
+
const { timeout } = details;
|
|
317
|
+
if (timeout)
|
|
318
|
+
meta.push(uiTheme.fg("warning", `timed out, ${timeout.verified}/${timeout.passages} passages verified`));
|
|
307
319
|
|
|
308
320
|
if (hits.length === 0) {
|
|
309
321
|
const emptyMeta = ["0 hits", ...scope, `$${stats.cost.toFixed(4)}`, formatDuration(details.elapsedMs)];
|
|
@@ -398,6 +410,10 @@ export const findToolRenderer = {
|
|
|
398
410
|
const scope = details.scopePath === undefined ? undefined : `in ${details.scopePath}`;
|
|
399
411
|
const failed =
|
|
400
412
|
stats.failed > 0 ? [span(`${stats.failed}/${stats.requests} requests failed`, "warning")] : undefined;
|
|
413
|
+
const { timeout } = details;
|
|
414
|
+
const timedOut = timeout
|
|
415
|
+
? [span(`timed out, ${timeout.verified}/${timeout.passages} passages verified`, "warning")]
|
|
416
|
+
: undefined;
|
|
401
417
|
const accounting = [
|
|
402
418
|
`${stats.filesRead} files read`,
|
|
403
419
|
`τ ${threshold.toFixed(2)}`,
|
|
@@ -431,7 +447,12 @@ export const findToolRenderer = {
|
|
|
431
447
|
return {
|
|
432
448
|
tool: findNativeHead(
|
|
433
449
|
query,
|
|
434
|
-
compact([
|
|
450
|
+
compact([
|
|
451
|
+
`${formatCount("hit", hits.length)} · ${formatCount("file", stats.filesRead)}`,
|
|
452
|
+
scope,
|
|
453
|
+
failed,
|
|
454
|
+
timedOut,
|
|
455
|
+
]),
|
|
435
456
|
),
|
|
436
457
|
inline: true,
|
|
437
458
|
body: compact<NativeChild>([
|
package/src/tools/grep.d.ts
CHANGED
|
@@ -61,7 +61,8 @@ export declare const grepToolRenderer: {
|
|
|
61
61
|
}, options: RenderResultContextOptions, uiTheme: Theme, args?: GrepRenderArgs): Component;
|
|
62
62
|
describeCall(args: GrepRenderArgs): NativeToolView;
|
|
63
63
|
/**
|
|
64
|
-
* Inline (§7.3 grep): `Grep “pattern” 5 matches · 2 files
|
|
64
|
+
* Inline (§7.3 grep): `Grep “pattern” in src 5 matches · 2 files`, the scope
|
|
65
|
+
* leading the counts as in the terminal card, then
|
|
65
66
|
* the matches grouped by file; collapsed shows the first two files.
|
|
66
67
|
*/
|
|
67
68
|
describeResult(result: {
|
package/src/tools/grep.ts
CHANGED
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
fitHeaderedRows,
|
|
31
31
|
formatCount,
|
|
32
32
|
formatEmptyMessage,
|
|
33
|
-
|
|
33
|
+
formatErrorDetail,
|
|
34
34
|
PREVIEW_LIMITS,
|
|
35
35
|
} from "../render/render-utils";
|
|
36
36
|
import {
|
|
@@ -39,6 +39,7 @@ import {
|
|
|
39
39
|
createGroupedRowStyler,
|
|
40
40
|
describeGroupedOutput,
|
|
41
41
|
fitGroupsToBudget,
|
|
42
|
+
formatScopedSubject,
|
|
42
43
|
groupedLinkTargets,
|
|
43
44
|
groupLineIndicesByBlank,
|
|
44
45
|
groupsByFile,
|
|
@@ -101,10 +102,30 @@ const EXPANDED_TEXT_LIMIT = PREVIEW_LIMITS.EXPANDED_LINES * 2;
|
|
|
101
102
|
/** Files a collapsed native grep shows (§7.3). */
|
|
102
103
|
const NATIVE_COLLAPSED_FILES = 2;
|
|
103
104
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const
|
|
107
|
-
|
|
105
|
+
/** Flag arguments that differ from the defaults: `case:insensitive`, `gitignore:false`, `skip:N`. */
|
|
106
|
+
function grepFlagMeta(args: GrepRenderArgs): string[] {
|
|
107
|
+
const meta: string[] = [];
|
|
108
|
+
if (args.case === false) meta.push("case:insensitive");
|
|
109
|
+
if (args.gitignore === false) meta.push("gitignore:false");
|
|
110
|
+
if (args.skip !== undefined && args.skip > 0) meta.push(`skip:${args.skip}`);
|
|
111
|
+
return meta;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Header subject, `pattern in scope`. A result names the tool's display scope
|
|
116
|
+
* (linked to the original search path); a call falls back to the requested paths.
|
|
117
|
+
*/
|
|
118
|
+
function grepSubject(
|
|
119
|
+
pattern: string | undefined,
|
|
120
|
+
args: GrepRenderArgs | undefined,
|
|
121
|
+
uiTheme: Theme,
|
|
122
|
+
details?: GrepToolDetails,
|
|
123
|
+
searchPath?: string,
|
|
124
|
+
): string | undefined {
|
|
125
|
+
let scope = details?.scopePath || undefined;
|
|
126
|
+
if (scope && searchPath) scope = fileHyperlink(searchPath, scope);
|
|
127
|
+
scope ??= toPathList(args?.path ?? args?.paths).join(", ") || undefined;
|
|
128
|
+
return formatScopedSubject(pattern || undefined, scope, uiTheme);
|
|
108
129
|
}
|
|
109
130
|
|
|
110
131
|
function grepStatusIcon(uiTheme: Theme): string {
|
|
@@ -115,15 +136,14 @@ function grepStatusIcon(uiTheme: Theme): string {
|
|
|
115
136
|
export const grepToolRenderer = {
|
|
116
137
|
inline: true,
|
|
117
138
|
renderCall(args: GrepRenderArgs, _options: RenderResultOptions, uiTheme: Theme): Component {
|
|
118
|
-
const paths = toPathList(args.path ?? args.paths);
|
|
119
|
-
const meta: string[] = [];
|
|
120
|
-
if (paths.length) meta.push(`in ${paths.join(", ")}`);
|
|
121
|
-
if (args.case === false) meta.push("case:insensitive");
|
|
122
|
-
if (args.gitignore === false) meta.push("gitignore:false");
|
|
123
|
-
if (args.skip !== undefined && args.skip > 0) meta.push(`skip:${args.skip}`);
|
|
124
|
-
|
|
125
139
|
const text = renderStatusLine(
|
|
126
|
-
{
|
|
140
|
+
{
|
|
141
|
+
icon: "pending",
|
|
142
|
+
title: "Grep",
|
|
143
|
+
titleColor: "toolTitle",
|
|
144
|
+
description: grepSubject(args.pattern || "?", args, uiTheme),
|
|
145
|
+
meta: grepFlagMeta(args),
|
|
146
|
+
},
|
|
127
147
|
uiTheme,
|
|
128
148
|
);
|
|
129
149
|
return new Text(text, 0, 0);
|
|
@@ -136,13 +156,24 @@ export const grepToolRenderer = {
|
|
|
136
156
|
args?: GrepRenderArgs,
|
|
137
157
|
): Component {
|
|
138
158
|
const details = result.details;
|
|
159
|
+
// The scope label links to the original (unsanitized) search path.
|
|
160
|
+
const rawDetails = options.renderContext?.rawDetails;
|
|
161
|
+
const searchPath =
|
|
162
|
+
isRecord(rawDetails) && typeof rawDetails.searchPath === "string"
|
|
163
|
+
? rawDetails.searchPath
|
|
164
|
+
: details?.searchPath;
|
|
165
|
+
const description = grepSubject(args?.pattern, args, uiTheme, details, searchPath);
|
|
139
166
|
|
|
140
167
|
if (result.isError || details?.error) {
|
|
141
168
|
const errorText =
|
|
142
169
|
details?.error ||
|
|
143
170
|
result.content?.find(c => c.type === "text")?.text ||
|
|
144
171
|
tuiText("glUnknownError", "Unknown error");
|
|
145
|
-
|
|
172
|
+
const header = renderStatusLine(
|
|
173
|
+
{ icon: "error", title: "Grep", titleColor: "toolTitle", description },
|
|
174
|
+
uiTheme,
|
|
175
|
+
);
|
|
176
|
+
return new Text(`${header}\n${formatErrorDetail(errorText, uiTheme)}`, 0, 0);
|
|
146
177
|
}
|
|
147
178
|
|
|
148
179
|
const hasDetailedData = details?.matchCount !== undefined || details?.fileCount !== undefined;
|
|
@@ -153,7 +184,6 @@ export const grepToolRenderer = {
|
|
|
153
184
|
return new Text(formatEmptyMessage(tuiText("gpNoMatches", "No matches found"), uiTheme), 1, 0);
|
|
154
185
|
}
|
|
155
186
|
const lines = textContent.split("\n").filter(line => line.trim() !== "");
|
|
156
|
-
const description = args?.pattern ?? undefined;
|
|
157
187
|
const header = renderStatusLine(
|
|
158
188
|
{
|
|
159
189
|
iconOverride: grepStatusIcon(uiTheme),
|
|
@@ -185,12 +215,6 @@ export const grepToolRenderer = {
|
|
|
185
215
|
},
|
|
186
216
|
);
|
|
187
217
|
}
|
|
188
|
-
// The scope label links to the original (unsanitized) search path.
|
|
189
|
-
const rawDetails = options.renderContext?.rawDetails;
|
|
190
|
-
const searchPath =
|
|
191
|
-
isRecord(rawDetails) && typeof rawDetails.searchPath === "string"
|
|
192
|
-
? rawDetails.searchPath
|
|
193
|
-
: details?.searchPath;
|
|
194
218
|
|
|
195
219
|
const matchCount = details?.matchCount ?? 0;
|
|
196
220
|
const fileCount = details?.fileCount ?? 0;
|
|
@@ -212,11 +236,8 @@ export const grepToolRenderer = {
|
|
|
212
236
|
: undefined;
|
|
213
237
|
|
|
214
238
|
if (matchCount === 0) {
|
|
215
|
-
const meta = ["0 matches"];
|
|
216
|
-
const scopeMeta = searchScopeMeta(details, searchPath);
|
|
217
|
-
if (scopeMeta) meta.push(scopeMeta);
|
|
218
239
|
const header = renderStatusLine(
|
|
219
|
-
{ icon: "warning", title: "Grep", titleColor: "toolTitle", description
|
|
240
|
+
{ icon: "warning", title: "Grep", titleColor: "toolTitle", description, meta: ["0 matches"] },
|
|
220
241
|
uiTheme,
|
|
221
242
|
);
|
|
222
243
|
const lines = [header, formatEmptyMessage(tuiText("gpNoMatches", "No matches found"), uiTheme)];
|
|
@@ -224,12 +245,8 @@ export const grepToolRenderer = {
|
|
|
224
245
|
return new Text(lines.join("\n"), 0, 0);
|
|
225
246
|
}
|
|
226
247
|
|
|
227
|
-
const
|
|
228
|
-
const meta = [...summaryParts];
|
|
229
|
-
const scopeMeta = searchScopeMeta(details, searchPath);
|
|
230
|
-
if (scopeMeta) meta.push(scopeMeta);
|
|
248
|
+
const meta = [formatCount("match", matchCount), formatCount("file", fileCount)];
|
|
231
249
|
if (truncated) meta.push(uiTheme.fg("warning", tuiText("grepTruncated", "truncated")));
|
|
232
|
-
const description = args?.pattern ?? undefined;
|
|
233
250
|
const header = renderStatusLine(
|
|
234
251
|
{
|
|
235
252
|
...(truncated ? { icon: "warning" as const } : { iconOverride: grepStatusIcon(uiTheme) }),
|
|
@@ -289,7 +306,8 @@ export const grepToolRenderer = {
|
|
|
289
306
|
},
|
|
290
307
|
|
|
291
308
|
/**
|
|
292
|
-
* Inline (§7.3 grep): `Grep “pattern” 5 matches · 2 files
|
|
309
|
+
* Inline (§7.3 grep): `Grep “pattern” in src 5 matches · 2 files`, the scope
|
|
310
|
+
* leading the counts as in the terminal card, then
|
|
293
311
|
* the matches grouped by file; collapsed shows the first two files.
|
|
294
312
|
*/
|
|
295
313
|
describeResult(
|
|
@@ -313,7 +331,7 @@ export const grepToolRenderer = {
|
|
|
313
331
|
) {
|
|
314
332
|
const foot = footnoteText(compact([missingNote]));
|
|
315
333
|
return {
|
|
316
|
-
tool: grepNativeHead(args, compact(["0 matches"
|
|
334
|
+
tool: grepNativeHead(args, compact([scope, "0 matches"])),
|
|
317
335
|
tone: "warning",
|
|
318
336
|
inline: true,
|
|
319
337
|
body: foot ? [foot] : undefined,
|
|
@@ -326,7 +344,7 @@ export const grepToolRenderer = {
|
|
|
326
344
|
const counts = hasDetailedData
|
|
327
345
|
? `${formatCount("match", matchCount)} · ${formatCount("file", fileCount)}`
|
|
328
346
|
: undefined;
|
|
329
|
-
const head = grepNativeHead(args, compact([
|
|
347
|
+
const head = grepNativeHead(args, compact([scope, counts]));
|
|
330
348
|
const hiddenFiles = options.expanded ? 0 : Math.max(0, fileCount - NATIVE_COLLAPSED_FILES);
|
|
331
349
|
const foot = footnoteText(
|
|
332
350
|
compact([hiddenFiles > 0 && formatCount("more file", hiddenFiles), missingNote]),
|
|
@@ -354,9 +372,7 @@ function grepNativeHead(args: GrepRenderArgs | undefined, meta?: readonly string
|
|
|
354
372
|
if (!meta && args) {
|
|
355
373
|
const paths = toPathList(args.path ?? args.paths);
|
|
356
374
|
if (paths.length) parts.push(`in ${paths.join(", ")}`);
|
|
357
|
-
|
|
358
|
-
if (args.gitignore === false) parts.push("gitignore:false");
|
|
359
|
-
if (args.skip !== undefined && args.skip > 0) parts.push(`skip:${args.skip}`);
|
|
375
|
+
parts.push(...grepFlagMeta(args));
|
|
360
376
|
}
|
|
361
377
|
return { title: "Grep", target: args?.pattern || "?", targetKind: "pattern", meta: parts };
|
|
362
378
|
}
|
|
@@ -154,6 +154,18 @@ export declare function fitGroupsToBudget(groups: readonly (readonly number[])[]
|
|
|
154
154
|
* indices lets callers slice parallel arrays (raw lines, styled lines, contexts).
|
|
155
155
|
*/
|
|
156
156
|
export declare function groupLineIndicesByBlank(rawLines: readonly string[]): number[][];
|
|
157
|
+
/** A code-frame row split after its rule: the gutter (match marker, line number, rule) and the source line. */
|
|
158
|
+
export interface CodeFrameRow {
|
|
159
|
+
gutter: string;
|
|
160
|
+
source: string;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Draw the code-frame rows of consecutive source lines: each gutter in
|
|
164
|
+
* `color`, the sources highlighted in `lang` as one run, so a multi-line
|
|
165
|
+
* string or comment keeps its colors. Without a language the sources take
|
|
166
|
+
* `color` too.
|
|
167
|
+
*/
|
|
168
|
+
export declare function renderCodeFrameRun(rows: readonly CodeFrameRow[], lang: string | undefined, color: ThemeColor, theme: Theme): string[];
|
|
157
169
|
/**
|
|
158
170
|
* Styled code-frame rows of grouped search output, highlighted in each owning
|
|
159
171
|
* file's language (`lang` overrides it when the highlighter knows it). A run of
|
|
@@ -163,6 +175,11 @@ export declare function groupLineIndicesByBlank(rawLines: readonly string[]): nu
|
|
|
163
175
|
* undefined, for the caller to style.
|
|
164
176
|
*/
|
|
165
177
|
export declare function createCodeFrameStyler(lines: readonly string[], contexts: readonly GroupedLineContext[], color: ThemeColor, theme: Theme, lang?: string): (index: number) => string | undefined;
|
|
178
|
+
/**
|
|
179
|
+
* Search header subject, `pattern in scope`, with `in` dim so the pattern and
|
|
180
|
+
* the scope read as two parts of one subject. Counts follow it as status meta.
|
|
181
|
+
*/
|
|
182
|
+
export declare function formatScopedSubject(subject: string | undefined, scope: string | undefined, theme: Theme): string | undefined;
|
|
166
183
|
/** One event of {@link walkGroupedOutput}: a directory header, a file header, or a non-blank body line. */
|
|
167
184
|
export type GroupedOutputEvent = {
|
|
168
185
|
readonly kind: "dir";
|