@xynogen/pix-pretty 1.29.0 → 1.30.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/package.json +3 -2
- package/src/command-preview.ts +77 -0
- package/src/diff-render.ts +3 -3
- package/src/highlight.ts +41 -0
- package/src/renderers.ts +4 -2
- package/src/shell-tool.ts +32 -41
- package/src/test-utils.ts +3 -0
- package/src/types.ts +4 -0
- package/src/utils.ts +63 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xynogen/pix-pretty",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.30.1",
|
|
4
4
|
"description": "Enhanced tool output rendering with syntax highlighting, file icons, tree views, diff rendering, and FFF search",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"./modal-frame": "./src/modal-frame.ts",
|
|
30
30
|
"./provider-picker": "./src/provider-picker.ts",
|
|
31
31
|
"./shell-tool": "./src/shell-tool.ts",
|
|
32
|
+
"./command-preview": "./src/command-preview.ts",
|
|
32
33
|
"./tool-status": "./src/tool-status.ts",
|
|
33
34
|
"./test-utils": "./src/test-utils.ts",
|
|
34
35
|
"./transient-error": "./src/transient-error.ts",
|
|
@@ -67,7 +68,7 @@
|
|
|
67
68
|
"access": "public"
|
|
68
69
|
},
|
|
69
70
|
"dependencies": {
|
|
70
|
-
"@xynogen/pix-runtime": "^0.
|
|
71
|
+
"@xynogen/pix-runtime": "^0.13.0",
|
|
71
72
|
"chalk": "^4.1.2",
|
|
72
73
|
"cli-highlight": "^2.1.11",
|
|
73
74
|
"@ff-labs/fff-node": "^0.10.6",
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { Text, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
|
|
2
|
+
import { hlBlock } from "./highlight.ts";
|
|
3
|
+
import type { ThemeLike } from "./types.ts";
|
|
4
|
+
|
|
5
|
+
export function commandPreview(
|
|
6
|
+
header: string,
|
|
7
|
+
code: string,
|
|
8
|
+
language: string | undefined,
|
|
9
|
+
theme: Pick<ThemeLike, "fg">,
|
|
10
|
+
state: Record<string, unknown>,
|
|
11
|
+
invalidate: () => void,
|
|
12
|
+
expanded = false,
|
|
13
|
+
indent = 2,
|
|
14
|
+
) {
|
|
15
|
+
type Slot = { code: string; language: string | undefined; theme: typeof theme; styled: string };
|
|
16
|
+
let slot = state.commandPreview as Slot | undefined;
|
|
17
|
+
if (!slot || slot.code !== code || slot.language !== language || slot.theme !== theme) {
|
|
18
|
+
slot = { code, language, theme, styled: theme.fg("dim", code) };
|
|
19
|
+
state.commandPreview = slot;
|
|
20
|
+
const pending = slot;
|
|
21
|
+
void hlBlock(code, language, theme).then(
|
|
22
|
+
(lines) => {
|
|
23
|
+
if (state.commandPreview !== pending) return;
|
|
24
|
+
pending.styled = lines.join("\n");
|
|
25
|
+
invalidate();
|
|
26
|
+
},
|
|
27
|
+
() => {
|
|
28
|
+
/* Plain text remains available if highlighting fails. */
|
|
29
|
+
},
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
const current = slot;
|
|
33
|
+
let replacement: string | undefined;
|
|
34
|
+
return {
|
|
35
|
+
setText(value: string) {
|
|
36
|
+
replacement = value;
|
|
37
|
+
},
|
|
38
|
+
getText: () => replacement ?? `${header}${theme.fg("muted", " · ")}${current.styled}`,
|
|
39
|
+
invalidate() {},
|
|
40
|
+
render(width: number): string[] {
|
|
41
|
+
if (replacement !== undefined)
|
|
42
|
+
return replacement ? new Text(replacement, 0, 0).render(width) : [];
|
|
43
|
+
const separator = theme.fg("muted", " · ");
|
|
44
|
+
if (!code.includes("\n") && visibleWidth(header) + 3 + visibleWidth(code) <= width) {
|
|
45
|
+
return new Text(`${header}${separator}${current.styled}`, 0, 0).render(width);
|
|
46
|
+
}
|
|
47
|
+
// ponytail: wrap without rewriting shell syntax or quoted strings. Add a shell parser only for semantic formatting.
|
|
48
|
+
const padding = " ".repeat(indent);
|
|
49
|
+
const lines = wrapTextWithAnsi(current.styled, Math.max(1, width - indent));
|
|
50
|
+
const shown = expanded ? lines : lines.slice(0, 16);
|
|
51
|
+
return [
|
|
52
|
+
truncateToWidth(`${header}${separator}`, width, "…"),
|
|
53
|
+
...shown.map((line) => `${padding}${line}`),
|
|
54
|
+
...(shown.length < lines.length
|
|
55
|
+
? [theme.fg("muted", `${padding}… +${lines.length - shown.length} lines`)]
|
|
56
|
+
: []),
|
|
57
|
+
];
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function collapsedCommandRow(header: string, command: string, theme: Pick<ThemeLike, "fg">) {
|
|
63
|
+
let text = `${header}${theme.fg("muted", " · ")}${theme.fg("dim", command.replace(/\s+/g, " ").trim())}`;
|
|
64
|
+
let replaced = false;
|
|
65
|
+
return {
|
|
66
|
+
setText(value: string) {
|
|
67
|
+
text = value;
|
|
68
|
+
replaced = true;
|
|
69
|
+
},
|
|
70
|
+
getText: () => text,
|
|
71
|
+
invalidate() {},
|
|
72
|
+
render(width: number): string[] {
|
|
73
|
+
if (replaced) return text ? new Text(text, 0, 0).render(width) : [];
|
|
74
|
+
return [truncateToWidth(text, width, "…")];
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
}
|
package/src/diff-render.ts
CHANGED
|
@@ -14,7 +14,7 @@ import { MAX_HL_CHARS, MAX_RENDER_LINES, WORD_DIFF_MIN_SIM } from "./config.ts";
|
|
|
14
14
|
import type { DiffLine, ParsedDiff } from "./diff.ts";
|
|
15
15
|
import { hlBlock } from "./highlight.ts";
|
|
16
16
|
import type { BundledLanguage, FgTheme } from "./types.ts";
|
|
17
|
-
import { termW as utilsTermW } from "./utils.ts";
|
|
17
|
+
import { BODY_PAD, termW as utilsTermW } from "./utils.ts";
|
|
18
18
|
|
|
19
19
|
// ---------------------------------------------------------------------------
|
|
20
20
|
// Env-overridable color/threshold helpers (mirror pi-diff)
|
|
@@ -668,7 +668,7 @@ export async function renderUnified(
|
|
|
668
668
|
|
|
669
669
|
out.push(rule(tw));
|
|
670
670
|
if (diff.lines.length > vis.length) {
|
|
671
|
-
out.push(`${BG_BASE}${FG_DIM}
|
|
671
|
+
out.push(`${BG_BASE}${FG_DIM}${BODY_PAD}… ${diff.lines.length - vis.length} more lines${RST}`);
|
|
672
672
|
}
|
|
673
673
|
return out.join("\n");
|
|
674
674
|
}
|
|
@@ -850,7 +850,7 @@ export async function renderSplit(
|
|
|
850
850
|
|
|
851
851
|
out.push(`${rule(half)}${FG_RULE}┊${RST}${rule(half)}`);
|
|
852
852
|
if (rows.length > vis.length) {
|
|
853
|
-
out.push(`${BG_BASE}${FG_DIM}
|
|
853
|
+
out.push(`${BG_BASE}${FG_DIM}${BODY_PAD}… ${rows.length - vis.length} more lines${RST}`);
|
|
854
854
|
}
|
|
855
855
|
return out.join("\n");
|
|
856
856
|
}
|
package/src/highlight.ts
CHANGED
|
@@ -35,11 +35,52 @@ function forceChalkColor(): void {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
// highlight.js bash only colors shell builtins, so `sleep`, `df`, `tail` stay plain.
|
|
39
|
+
// Add the standard external commands to its built_in list.
|
|
40
|
+
export const BASH_COMMANDS =
|
|
41
|
+
"awk basename cat chgrp chmod chown cp curl cut date dd df diff dirname du env file find " +
|
|
42
|
+
"free git grep gzip head hostname id kill ln ls mkdir mktemp mv nohup pgrep pkill ps rm " +
|
|
43
|
+
"rmdir sed seq sleep sort ssh scp tail tar tee touch tr uname uniq wc which whoami xargs";
|
|
44
|
+
|
|
45
|
+
// Windows native executables plus common cross-platform CLIs. highlight.js powershell
|
|
46
|
+
// only knows cmdlets and aliases, so `ipconfig` or `git` would stay plain.
|
|
47
|
+
export const POWERSHELL_COMMANDS =
|
|
48
|
+
"arp assoc attrib bcdedit certutil chkdsk choco cipher clip cmd cmdkey cscript curl diskpart " +
|
|
49
|
+
"docker driverquery fc find findstr format fsutil ftp getmac git gpresult gpupdate hostname " +
|
|
50
|
+
"icacls ipconfig klist logoff make msiexec nbtstat net netsh netstat nltest node npm npx " +
|
|
51
|
+
"nslookup pathping pip ping pnpm powercfg powershell pwsh python reg regsvr32 robocopy route " +
|
|
52
|
+
"scoop sfc shutdown ssh scp systeminfo takeown taskkill tasklist tar tracert tree uv " +
|
|
53
|
+
"w32tm wevtutil where whoami winget wmic xcopy bun cargo go yarn";
|
|
54
|
+
|
|
55
|
+
// ponytail: reach the highlight.js instance cli-highlight already loaded instead of
|
|
56
|
+
// declaring a second dependency. Pin highlight.js directly if cli-highlight drops it.
|
|
57
|
+
function extendBuiltIns(): void {
|
|
58
|
+
try {
|
|
59
|
+
const { createRequire } = require("node:module") as typeof import("node:module");
|
|
60
|
+
const sub = createRequire(require.resolve("cli-highlight"));
|
|
61
|
+
const hljs = sub("highlight.js");
|
|
62
|
+
for (const [name, commands] of [
|
|
63
|
+
["bash", BASH_COMMANDS],
|
|
64
|
+
["powershell", POWERSHELL_COMMANDS],
|
|
65
|
+
] as const) {
|
|
66
|
+
const grammar = sub(`highlight.js/lib/languages/${name}`);
|
|
67
|
+
hljs.registerLanguage(name, (h: unknown) => {
|
|
68
|
+
const def = grammar(h);
|
|
69
|
+
def.keywords.built_in += ` ${commands}`;
|
|
70
|
+
return def;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
} catch {
|
|
74
|
+
/* keep the stock grammars */
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
38
78
|
function cliHighlight(): CliHighlight | null {
|
|
39
79
|
if (_hl) return _hl;
|
|
40
80
|
try {
|
|
41
81
|
forceChalkColor();
|
|
42
82
|
_hl = require("cli-highlight") as CliHighlight;
|
|
83
|
+
extendBuiltIns();
|
|
43
84
|
} catch {
|
|
44
85
|
_hl = null;
|
|
45
86
|
}
|
package/src/renderers.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { hlBlock } from "./highlight.ts";
|
|
|
8
8
|
import { dirIcon, fileColor, fileIcon } from "./icons.ts";
|
|
9
9
|
import { lang } from "./lang.ts";
|
|
10
10
|
import type { FgTheme } from "./types.ts";
|
|
11
|
-
import { lnum, normalizeLineEndings, pluralize, rule, termW } from "./utils.ts";
|
|
11
|
+
import { BODY_PAD, lnum, normalizeLineEndings, pluralize, rule, termW } from "./utils.ts";
|
|
12
12
|
|
|
13
13
|
/** Layout controls for {@link renderFileContent}. */
|
|
14
14
|
export interface RenderFileContentOptions {
|
|
@@ -68,7 +68,9 @@ export async function renderFileContent(
|
|
|
68
68
|
|
|
69
69
|
out.push(rule(tw));
|
|
70
70
|
if (total > maxLines) {
|
|
71
|
-
out.push(
|
|
71
|
+
out.push(
|
|
72
|
+
`${FG_DIM}${BODY_PAD}… ${pluralize(total - maxLines, "more line")} (${total} total)${RST}`,
|
|
73
|
+
);
|
|
72
74
|
}
|
|
73
75
|
return out.join("\n");
|
|
74
76
|
}
|
package/src/shell-tool.ts
CHANGED
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import type { AgentToolUpdateCallback, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
12
|
-
import { truncateToWidth } from "@earendil-works/pi-tui";
|
|
13
12
|
import { type CollapseState, tickCollapse } from "@xynogen/pix-runtime/collapse";
|
|
14
|
-
import {
|
|
13
|
+
import { resolveBaseBackground } from "./ansi.ts";
|
|
14
|
+
import { collapsedCommandRow, commandPreview } from "./command-preview.ts";
|
|
15
15
|
import { MAX_PREVIEW_LINES } from "./config.ts";
|
|
16
16
|
import { renderBashOutput } from "./renderers.ts";
|
|
17
17
|
import type { ToolContext } from "./tools/context.ts";
|
|
@@ -24,17 +24,20 @@ import type {
|
|
|
24
24
|
ToolResultLike,
|
|
25
25
|
} from "./types.ts";
|
|
26
26
|
import {
|
|
27
|
+
BODY_PAD,
|
|
28
|
+
bodyLine,
|
|
27
29
|
dotJoin,
|
|
28
30
|
fillToolBackground,
|
|
31
|
+
formatCollapsedToolRow,
|
|
32
|
+
formatToolCallTitle,
|
|
29
33
|
frameToolResult,
|
|
30
34
|
getErrorMessage,
|
|
31
35
|
getTextContent,
|
|
32
36
|
hideCollapsedToolCall,
|
|
33
37
|
isTextContent,
|
|
34
|
-
|
|
38
|
+
moreLines,
|
|
35
39
|
renderToolError,
|
|
36
40
|
ruleFrame,
|
|
37
|
-
sectionRule,
|
|
38
41
|
setResultDetails,
|
|
39
42
|
termW,
|
|
40
43
|
unframeToolResult,
|
|
@@ -95,8 +98,8 @@ export function registerShellTool(
|
|
|
95
98
|
ctx: ToolContext,
|
|
96
99
|
options: ShellToolOptions,
|
|
97
100
|
): void {
|
|
98
|
-
const { cwd, TextComponent
|
|
99
|
-
const { name,
|
|
101
|
+
const { cwd, TextComponent } = ctx;
|
|
102
|
+
const { name, failurePattern } = options;
|
|
100
103
|
const origTool = createTool(cwd);
|
|
101
104
|
|
|
102
105
|
pi.registerTool({
|
|
@@ -145,30 +148,21 @@ export function registerShellTool(
|
|
|
145
148
|
resolveBaseBackground(theme);
|
|
146
149
|
const displayCmdRaw = (args.command ?? "").trim();
|
|
147
150
|
const text = renderCtx.lastComponent ?? new TextComponent("", 0, 0);
|
|
148
|
-
const label = theme
|
|
151
|
+
const label = formatToolCallTitle(theme, name, renderCtx);
|
|
149
152
|
const collapseState = renderCtx.state as CollapseState;
|
|
150
153
|
if (hideCollapsedToolCall(collapseState, renderCtx.expanded, (value) => text.setText(value)))
|
|
151
154
|
return text;
|
|
152
155
|
const timeout = args.timeout ? ` ${theme.fg("muted", `(${args.timeout}s timeout)`)}` : "";
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
const reserve = Math.max(0, availableWidth - timeout.length);
|
|
163
|
-
const displayCmd = truncateToWidth(
|
|
164
|
-
theme.fg("dim", baseCmd),
|
|
165
|
-
Math.max(1, reserve - prefix.length),
|
|
166
|
-
"…",
|
|
156
|
+
return commandPreview(
|
|
157
|
+
label + timeout,
|
|
158
|
+
displayCmdRaw,
|
|
159
|
+
name === "powershell" ? "powershell" : "bash",
|
|
160
|
+
theme,
|
|
161
|
+
renderCtx.state,
|
|
162
|
+
renderCtx.invalidate,
|
|
163
|
+
renderCtx.expanded,
|
|
164
|
+
3,
|
|
167
165
|
);
|
|
168
|
-
text.setText(
|
|
169
|
-
fillToolBackground(`${prefix}${displayCmd}${timeout}`, BG_BASE, terminalWidth?.()),
|
|
170
|
-
);
|
|
171
|
-
return text;
|
|
172
166
|
},
|
|
173
167
|
|
|
174
168
|
renderResult(
|
|
@@ -203,18 +197,13 @@ export function registerShellTool(
|
|
|
203
197
|
lc > 0 && `${lc} ${lc === 1 ? "line" : "lines"}`,
|
|
204
198
|
durationMs > 0 && formatDuration(durationMs, "bash"),
|
|
205
199
|
]);
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
summarize(String(d.command ?? "")),
|
|
211
|
-
meta,
|
|
212
|
-
status,
|
|
213
|
-
terminalWidth?.(),
|
|
214
|
-
),
|
|
200
|
+
return collapsedCommandRow(
|
|
201
|
+
formatCollapsedToolRow(theme, name, "", meta, status).trimEnd(),
|
|
202
|
+
String(d.command ?? ""),
|
|
203
|
+
theme,
|
|
215
204
|
);
|
|
216
205
|
} else {
|
|
217
|
-
text.setText(fillToolBackground(
|
|
206
|
+
text.setText(fillToolBackground(`${BODY_PAD}${theme.fg("muted", "done")}`));
|
|
218
207
|
}
|
|
219
208
|
return text;
|
|
220
209
|
}
|
|
@@ -237,16 +226,14 @@ export function registerShellTool(
|
|
|
237
226
|
|
|
238
227
|
const maxShow = renderCtx.expanded ? lineCount : MAX_PREVIEW_LINES;
|
|
239
228
|
const show = lines.slice(0, maxShow);
|
|
240
|
-
const footer =
|
|
241
|
-
lineCount > maxShow ? [`${FG_DIM} … ${lineCount - maxShow} more lines${RST}`] : [];
|
|
229
|
+
const footer = lineCount > maxShow ? [moreLines(lineCount - maxShow, theme)] : [];
|
|
242
230
|
// Every result (including single-line) is framed; the rules follow exit
|
|
243
231
|
// status: green ok, red failure. The `✓ exit N` header is dropped — the
|
|
244
232
|
// collapsed row already carries status.
|
|
245
233
|
const exitCode = d.exitCode as number | null;
|
|
246
234
|
const statusKey = exitCode === null || exitCode === 0 ? "success" : "error";
|
|
247
235
|
const paint = (s: string) => theme.fg(statusKey, s);
|
|
248
|
-
const
|
|
249
|
-
const body = show.map((line) => ` ${sectionRule(line, theme, sw) ?? line}`);
|
|
236
|
+
const body = show.map((line) => bodyLine(line, theme));
|
|
250
237
|
const out = isPartial ? [...body, ...footer] : ruleFrame(body, footer, termW(), paint);
|
|
251
238
|
text.setText(fillToolBackground(out.join("\n")));
|
|
252
239
|
return text;
|
|
@@ -257,11 +244,15 @@ export function registerShellTool(
|
|
|
257
244
|
if (isPartial) {
|
|
258
245
|
const liveLines = normalizeShellText(String(fallbackText)).split("\n").slice(-5);
|
|
259
246
|
text.setText(
|
|
260
|
-
fillToolBackground(
|
|
247
|
+
fillToolBackground(
|
|
248
|
+
liveLines.map((line) => bodyLine(line, theme, (l) => theme.fg("dim", l))).join("\n"),
|
|
249
|
+
),
|
|
261
250
|
);
|
|
262
251
|
return text;
|
|
263
252
|
}
|
|
264
|
-
text.setText(
|
|
253
|
+
text.setText(
|
|
254
|
+
fillToolBackground(`${BODY_PAD}${theme.fg("dim", String(fallbackText).slice(0, 120))}`),
|
|
255
|
+
);
|
|
265
256
|
return completed();
|
|
266
257
|
},
|
|
267
258
|
});
|
package/src/test-utils.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -65,6 +65,10 @@ export type RenderContextLike<
|
|
|
65
65
|
state: TState;
|
|
66
66
|
expanded: boolean;
|
|
67
67
|
isError: boolean;
|
|
68
|
+
/** Pi sets this to false when the tool returns its final result. */
|
|
69
|
+
isPartial?: boolean;
|
|
70
|
+
executionStarted?: boolean;
|
|
71
|
+
argsComplete?: boolean;
|
|
68
72
|
invalidate: () => void;
|
|
69
73
|
/** Stable id for this tool execution — used to key resize invalidators. */
|
|
70
74
|
toolCallId?: string;
|
package/src/utils.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
RST,
|
|
14
14
|
} from "./ansi.ts";
|
|
15
15
|
import { MAX_PREVIEW_LINES } from "./config.ts";
|
|
16
|
+
import { icon } from "./icon-catalog.ts";
|
|
16
17
|
import type {
|
|
17
18
|
FgTheme,
|
|
18
19
|
TextComponentCtor,
|
|
@@ -304,6 +305,33 @@ type CollapsedToolTheme = {
|
|
|
304
305
|
bold: (text: string) => string;
|
|
305
306
|
};
|
|
306
307
|
|
|
308
|
+
/** Use the host lifecycle fields so every call has the same status marker. */
|
|
309
|
+
export function formatToolCallTitle(
|
|
310
|
+
theme: {
|
|
311
|
+
fg: (role: "muted" | "warning" | "error" | "success" | "toolTitle", text: string) => string;
|
|
312
|
+
bold?: (text: string) => string;
|
|
313
|
+
},
|
|
314
|
+
tool: string,
|
|
315
|
+
context: { executionStarted?: boolean; isPartial?: boolean; isError?: boolean } = {},
|
|
316
|
+
): string {
|
|
317
|
+
const complete = context.isPartial === false;
|
|
318
|
+
const role = complete
|
|
319
|
+
? context.isError
|
|
320
|
+
? "error"
|
|
321
|
+
: "success"
|
|
322
|
+
: context.executionStarted
|
|
323
|
+
? "warning"
|
|
324
|
+
: "muted";
|
|
325
|
+
const marker = complete
|
|
326
|
+
? context.isError
|
|
327
|
+
? "status.error"
|
|
328
|
+
: "status.ok"
|
|
329
|
+
: context.executionStarted
|
|
330
|
+
? "status.running"
|
|
331
|
+
: "status.pending";
|
|
332
|
+
return `${theme.fg(role, padIcon(icon(marker)))} ${theme.fg("toolTitle", theme.bold?.(tool) ?? tool)}`;
|
|
333
|
+
}
|
|
334
|
+
|
|
307
335
|
/** Format the shared one-row content without assuming a render shell. */
|
|
308
336
|
export function formatCollapsedToolRow(
|
|
309
337
|
theme: CollapsedToolTheme,
|
|
@@ -312,9 +340,11 @@ export function formatCollapsedToolRow(
|
|
|
312
340
|
meta = "",
|
|
313
341
|
status: CollapsedToolStatus = "success",
|
|
314
342
|
): string {
|
|
315
|
-
const
|
|
343
|
+
const marker = padIcon(
|
|
344
|
+
icon(status === "success" ? "status.ok" : status === "error" ? "status.error" : "status.warn"),
|
|
345
|
+
);
|
|
316
346
|
const parts = [
|
|
317
|
-
`${theme.fg(status,
|
|
347
|
+
`${theme.fg(status, marker)} ${theme.fg("toolTitle", theme.bold(tool))}`,
|
|
318
348
|
target ? theme.fg("dim", target) : "",
|
|
319
349
|
meta ? `${theme.fg("muted", "·")} ${theme.fg("muted", meta)}` : "",
|
|
320
350
|
].filter(Boolean);
|
|
@@ -424,17 +454,11 @@ export function renderDimPreview(
|
|
|
424
454
|
const highlight = opts.highlight;
|
|
425
455
|
const output = normalizeLineEndings(text).trim() || "done";
|
|
426
456
|
const lines = output.split("\n");
|
|
427
|
-
const sw = Math.max(8, termW() - 4); // section-rule width inside the 2-space indent
|
|
428
457
|
const body = lines
|
|
429
458
|
.slice(0, maxLines)
|
|
430
|
-
.map(
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
const header = opts.header ? ` ${theme.fg("dim", opts.header)}` : undefined;
|
|
434
|
-
const overflow =
|
|
435
|
-
lines.length > maxLines
|
|
436
|
-
? ` ${theme.fg("muted", `… ${pluralize(lines.length - maxLines, "more line")}`)}`
|
|
437
|
-
: undefined;
|
|
459
|
+
.map((line) => bodyLine(line, theme, (l) => dimLineWithHighlight(l, theme, highlight)));
|
|
460
|
+
const header = opts.header ? `${BODY_PAD}${theme.fg("dim", opts.header)}` : undefined;
|
|
461
|
+
const overflow = lines.length > maxLines ? moreLines(lines.length - maxLines, theme) : undefined;
|
|
438
462
|
|
|
439
463
|
if (opts.frame) {
|
|
440
464
|
// One shape regardless of line count: a single framed box, no floating
|
|
@@ -533,6 +557,9 @@ export function rule(w: number, paint?: RulePaint, style: RuleStyle = "solid"):
|
|
|
533
557
|
return paint ? paint(glyphs) : `${FG_RULE}${glyphs}${RST}`;
|
|
534
558
|
}
|
|
535
559
|
|
|
560
|
+
/** Narrow theme for helpers that paint only `muted`. Pi's Theme and FgTheme both fit. */
|
|
561
|
+
type MutedTheme = { fg: (key: "muted", text: string) => string };
|
|
562
|
+
|
|
536
563
|
/** Matches an `=== label ===` separator line (a common shell/echo idiom). */
|
|
537
564
|
const SECTION_RE = /^\s*={2,}\s*(.+?)\s*={2,}\s*$/;
|
|
538
565
|
|
|
@@ -546,7 +573,7 @@ const SECTION_RULE_LEAD = 4;
|
|
|
546
573
|
* so the divider aligns with the surrounding tool frame. Label and rule both
|
|
547
574
|
* use the muted role — theme-driven, ANSI-safe.
|
|
548
575
|
*/
|
|
549
|
-
export function sectionRule(line: string, theme:
|
|
576
|
+
export function sectionRule(line: string, theme: MutedTheme, width: number): string | null {
|
|
550
577
|
const m = SECTION_RE.exec(line);
|
|
551
578
|
if (!m || hasAnsi(line)) return null;
|
|
552
579
|
const label = ` ${m[1]} `;
|
|
@@ -557,6 +584,30 @@ export function sectionRule(line: string, theme: FgTheme, width: number): string
|
|
|
557
584
|
return theme.fg("muted", `${"─".repeat(lead)}${label}${"─".repeat(tail)}`);
|
|
558
585
|
}
|
|
559
586
|
|
|
587
|
+
/**
|
|
588
|
+
* One tool-result body line, aligned under the tool title. An `=== label ===` line
|
|
589
|
+
* becomes a full-width section rule. Other lines go through `paint`.
|
|
590
|
+
*/
|
|
591
|
+
/**
|
|
592
|
+
* Body indent: one tab. pi-tui renders `\t` as 3 cells, the title column after
|
|
593
|
+
* the 2-cell status icon + space.
|
|
594
|
+
*/
|
|
595
|
+
export const BODY_PAD = "\t";
|
|
596
|
+
|
|
597
|
+
export function bodyLine(
|
|
598
|
+
line: string,
|
|
599
|
+
theme: MutedTheme,
|
|
600
|
+
paint: (line: string) => string = (s) => s,
|
|
601
|
+
): string {
|
|
602
|
+
// ponytail: 3 = pi-tui tab width. Use visibleWidth if BODY_PAD stops being one tab.
|
|
603
|
+
return `${BODY_PAD}${sectionRule(line, theme, termW() - 3) ?? paint(line)}`;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
/** Muted `… N more lines` footer for a truncated tool-result body. */
|
|
607
|
+
export function moreLines(count: number, theme: MutedTheme): string {
|
|
608
|
+
return `${BODY_PAD}${theme.fg("muted", `… ${pluralize(count, "more line")}`)}`;
|
|
609
|
+
}
|
|
610
|
+
|
|
560
611
|
/** Decorate completed tool output with status-colored default chrome. */
|
|
561
612
|
export function frameToolResult<T extends FramableComponent & { setText(value: string): void }>(
|
|
562
613
|
component: T,
|