@heyhuynhgiabuu/pi-pretty 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +47 -0
- package/README.md +3 -0
- package/dist/claude-style.d.ts +2 -0
- package/dist/claude-style.d.ts.map +1 -1
- package/dist/claude-style.js +164 -19
- package/dist/claude-style.js.map +1 -1
- package/dist/config.d.ts +8 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +11 -0
- package/dist/config.js.map +1 -1
- package/dist/fff.d.ts.map +1 -1
- package/dist/fff.js +6 -1
- package/dist/fff.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +9 -7
- package/dist/render.js.map +1 -1
- package/package.json +4 -4
- package/src/claude-style.ts +187 -17
- package/src/config.ts +17 -0
- package/src/fff.ts +7 -3
- package/src/index.ts +4 -0
- package/src/render.ts +9 -7
package/src/claude-style.ts
CHANGED
|
@@ -13,14 +13,40 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import { highlightCode, keyText } from "@earendil-works/pi-coding-agent";
|
|
16
|
-
import { Container, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
16
|
+
import { Container, Text, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
17
|
+
import { BG_BASE, BG_ERROR, resolveBaseBackground } from "./config.js";
|
|
17
18
|
import { ELAPSED_KEY, shortPath } from "./helpers.js";
|
|
19
|
+
import { fillToolBackground, preserveBoxBackground } from "./render.js";
|
|
18
20
|
import type { RenderCtxLike, ThemeLike } from "./types.js";
|
|
19
21
|
|
|
20
22
|
type AnyFn = (...args: any[]) => any;
|
|
21
23
|
type AnyComponent = { render(width: number): string[]; invalidate?(): void; [key: string]: any };
|
|
22
24
|
|
|
23
25
|
const ANSI_RE = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`, "g");
|
|
26
|
+
// Escape-sequence stripping, ported from the host's `utils/ansi.js` (via ansi-regex / strip-ansi,
|
|
27
|
+
// MIT). Not importable: that package exports only "." and "./rpc-entry". pi-tui's
|
|
28
|
+
// `stripTerminalSequences` is not a substitute — it scans to the first m/G/K/H/J, so on
|
|
29
|
+
// "keep ESC[?25l me" it eats the text between, and it misses C1 (\u009b) entirely. A private
|
|
30
|
+
// prefix (<, =, >) is accepted only right after a real CSI introducer, so ESC[<35;59;1M strips
|
|
31
|
+
// whole while ESC = does not swallow the digits that follow.
|
|
32
|
+
const ANSI_ST = `(?:${String.fromCharCode(7)}|\\u001B\\\\|\\u009C)`;
|
|
33
|
+
const ANSI_OSC_START = "\\u001B\\]";
|
|
34
|
+
const ANSI_CSI_START = "(?:(?:\\u001B\\[|\\u009B)[<=>]|[\\u001B\\u009B][[\\]()#;?]*)(?:\\d{1,4}(?:[;:]\\d{0,4})*)?";
|
|
35
|
+
const ANSI_CSI_FINAL = "[\\dA-PR-TZcf-nq-uy=><~]";
|
|
36
|
+
const ANSI_SEQUENCE_RE = new RegExp(
|
|
37
|
+
`(?:${ANSI_OSC_START}[\\s\\S]*?${ANSI_ST})|${ANSI_CSI_START}${ANSI_CSI_FINAL}`,
|
|
38
|
+
"g",
|
|
39
|
+
);
|
|
40
|
+
/** C0/C1 controls and the interlinear-annotation block, built from char codes because a literal
|
|
41
|
+
* control character in a regex is flagged by the linter. Tab and newline are absent: both are
|
|
42
|
+
* layout the host keeps, and `Text` turns each tab into three spaces. */
|
|
43
|
+
const CONTROL_CHARS_RE = new RegExp(
|
|
44
|
+
`[${String.fromCharCode(0)}-${String.fromCharCode(8)}${String.fromCharCode(11)}${String.fromCharCode(12)}` +
|
|
45
|
+
`${String.fromCharCode(14)}-${String.fromCharCode(31)}${String.fromCharCode(127)}-${String.fromCharCode(159)}` +
|
|
46
|
+
`${String.fromCharCode(0xfff9)}-${String.fromCharCode(0xfffb)}]`,
|
|
47
|
+
"g",
|
|
48
|
+
);
|
|
49
|
+
|
|
24
50
|
// Kitty (`ESC _G`) and iTerm2 (`ESC ]1337;File=`) inline-image payload lines.
|
|
25
51
|
const IMAGE_LINE_RE = new RegExp(`${String.fromCharCode(27)}(?:_G|\\]1337;File=)`);
|
|
26
52
|
const isImageLine = (line: string): boolean => IMAGE_LINE_RE.test(line);
|
|
@@ -171,6 +197,22 @@ function resultText(result: any): string {
|
|
|
171
197
|
.join("\n");
|
|
172
198
|
}
|
|
173
199
|
|
|
200
|
+
/** Sanitized body text for a tool with no renderer of its own.
|
|
201
|
+
*
|
|
202
|
+
* Per block, like the host: joining first lets an unterminated escape in one block swallow the
|
|
203
|
+
* text of the next. With blocks `["keep ESC]title", "visible BEL after"]` the join-first order
|
|
204
|
+
* loses "visible", because the unterminated OSC then runs on to the BEL. */
|
|
205
|
+
function sanitizedBodyText(result: any): string {
|
|
206
|
+
return ((result?.content ?? []) as Array<{ type?: string; text?: string }>)
|
|
207
|
+
.filter((block) => block.type === "text")
|
|
208
|
+
.map((block) =>
|
|
209
|
+
// Host order: strip ANSI, then binary controls, then CR. Removing CR first would let
|
|
210
|
+
// "a ESC CR [31m b" read as a complete SGR and lose "[31m" from the text.
|
|
211
|
+
(block.text ?? "").replace(ANSI_SEQUENCE_RE, "").replace(CONTROL_CHARS_RE, "").replace(/\r/g, ""),
|
|
212
|
+
)
|
|
213
|
+
.join("\n");
|
|
214
|
+
}
|
|
215
|
+
|
|
174
216
|
function countLines(text: string, skip?: RegExp): number {
|
|
175
217
|
return text.split("\n").filter((line) => line.trim() !== "" && !(skip && skip.test(line.trim()))).length;
|
|
176
218
|
}
|
|
@@ -319,6 +361,19 @@ function fitLine(line: string, width: number, theme: ThemeLike): string {
|
|
|
319
361
|
return visibleWidth(line) > width ? truncateToWidth(line, width, theme.fg("dim", "…")) : line;
|
|
320
362
|
}
|
|
321
363
|
|
|
364
|
+
/** Paint a delegated expanded body. The claudecode shell is "self", so the host draws no box: a
|
|
365
|
+
* tool whose original renderer emits plain or foreground-only rows would otherwise float on the
|
|
366
|
+
* terminal's own background. Tools that paint their own rows keep them untouched. */
|
|
367
|
+
function paintedBody(component: AnyComponent, bg: string): AnyComponent {
|
|
368
|
+
return {
|
|
369
|
+
render: (width: number) =>
|
|
370
|
+
(component.render(Math.max(1, width)) as string[]).map((line) =>
|
|
371
|
+
isImageLine(line) ? line : fillToolBackground(line, bg, width, ""),
|
|
372
|
+
),
|
|
373
|
+
invalidate: () => component.invalidate?.(),
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
|
|
322
377
|
function buildCallRow(
|
|
323
378
|
theme: ThemeLike,
|
|
324
379
|
ctx: RenderCtxLike,
|
|
@@ -328,14 +383,20 @@ function buildCallRow(
|
|
|
328
383
|
hint = "",
|
|
329
384
|
bodyLines: string[] = [],
|
|
330
385
|
): AnyComponent {
|
|
386
|
+
// Resolved once per render call, not per frame: it reads pi-pretty.json synchronously.
|
|
387
|
+
resolveBaseBackground(theme);
|
|
388
|
+
const bg = ctx.isError ? BG_ERROR : BG_BASE;
|
|
331
389
|
return rowComponent((width) => {
|
|
332
|
-
const head = `${indentOf(ctx)}${stateIcon(theme, state)} ${theme.bold(theme.fg("
|
|
390
|
+
const head = `${indentOf(ctx)}${stateIcon(theme, state)} ${theme.bold(theme.fg("toolTitle", label))}`;
|
|
333
391
|
const body = detail ? ` ${theme.fg("dim", "(")}${theme.fg("muted", detail)}${theme.fg("dim", ")")}` : "";
|
|
334
392
|
const indent = `${indentOf(ctx)} `;
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
393
|
+
const title = fitLine(`${head}${body}${hint}`, width, theme);
|
|
394
|
+
// Fill after truncating: truncateToWidth counts background sequences as visible width.
|
|
395
|
+
// An empty indent pads the row to the render width, so the colour reaches the edge.
|
|
396
|
+
// The body is painted too: this shell is "self", so the host draws no box and every row it
|
|
397
|
+
// leaves unpainted shows the terminal's own background (a codemode script reads as a hole).
|
|
398
|
+
const painted = (line: string): string => fillToolBackground(line, bg, width, "");
|
|
399
|
+
return [painted(title), ...bodyLines.map((line) => painted(fitLine(`${indent}${line}`, width, theme)))];
|
|
339
400
|
});
|
|
340
401
|
}
|
|
341
402
|
|
|
@@ -361,8 +422,14 @@ type CallBody = (args: Record<string, unknown>) => string[];
|
|
|
361
422
|
const codemodeSource: CallBody = (args) =>
|
|
362
423
|
highlightCode(firstString(args, ["code"]).replace(/\r/g, "").replace(/\t/g, " ").trimEnd(), "javascript");
|
|
363
424
|
|
|
364
|
-
/**
|
|
365
|
-
|
|
425
|
+
/** Tools whose expanded body already carries its own background, so painting it would replace
|
|
426
|
+
* colour that is the information: pi-diff's green/red hunks. */
|
|
427
|
+
const SELF_PAINTED_BODY_TOOLS = new Set(["write", "edit", "apply_patch"]);
|
|
428
|
+
|
|
429
|
+
/** Renderer pair for one tool; `original` is the result renderer shown when expanded.
|
|
430
|
+
* `external` marks the installer path whose shell is "self": the host draws no box there, so the
|
|
431
|
+
* expanded body must be painted here. pi-pretty's own tools paint their own bodies already. */
|
|
432
|
+
function claudeRenderers(name: string, label: string, original?: AnyFn, expandedCallBody?: CallBody, external = false) {
|
|
366
433
|
return {
|
|
367
434
|
renderCall(args: Record<string, unknown>, theme: ThemeLike, ctx: RenderCtxLike) {
|
|
368
435
|
const state: ToolState = ctx.isError
|
|
@@ -389,7 +456,32 @@ function claudeRenderers(name: string, label: string, original?: AnyFn, expanded
|
|
|
389
456
|
ctx: RenderCtxLike,
|
|
390
457
|
) {
|
|
391
458
|
if (options?.isPartial) return rowComponent(() => []);
|
|
392
|
-
|
|
459
|
+
// No renderer of its own (recall): the host would fall back to plain `toolOutput` text on
|
|
460
|
+
// this "self" shell, which has no box, so the body would float unpainted. Build it here.
|
|
461
|
+
if (ctx.expanded && !original && external) {
|
|
462
|
+
// The host fallback stripped ANSI and binary controls, dropped carriage returns, then
|
|
463
|
+
// rendered through a Text component. Skipping any of that would let a raw escape reach the
|
|
464
|
+
// terminal or misalign a tabbed row.
|
|
465
|
+
const text = sanitizedBodyText(result);
|
|
466
|
+
if (!text.trim()) return rowComponent(() => []);
|
|
467
|
+
resolveBaseBackground(theme);
|
|
468
|
+
const bg = ctx.isError ? BG_ERROR : BG_BASE;
|
|
469
|
+
// Drawn through the host's own Text: it wraps (so a long entry is not cut), turns tabs into
|
|
470
|
+
// three spaces, and pads each row to the render width before the background is applied.
|
|
471
|
+
const body = new Text(theme.fg("toolOutput", text), 0, 0, (line: string) =>
|
|
472
|
+
fillToolBackground(line, bg, undefined, ""),
|
|
473
|
+
);
|
|
474
|
+
return {
|
|
475
|
+
render: (width: number) => body.render(Math.max(1, width)),
|
|
476
|
+
invalidate: () => body.invalidate(),
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
if (ctx.expanded && original) {
|
|
480
|
+
const body = original(result, options, theme, ctx);
|
|
481
|
+
if (!external || !body || SELF_PAINTED_BODY_TOOLS.has(name)) return body;
|
|
482
|
+
resolveBaseBackground(theme);
|
|
483
|
+
return paintedBody(body, ctx.isError ? BG_ERROR : BG_BASE);
|
|
484
|
+
}
|
|
393
485
|
if (ctx.isError) {
|
|
394
486
|
const message = oneLine(
|
|
395
487
|
resultText(result)
|
|
@@ -487,9 +579,7 @@ export function installClaudeExternalToolRenderers(toolExecutionComponent: unkno
|
|
|
487
579
|
proto.getResultRenderer = function (this: any) {
|
|
488
580
|
const original = originals.getResultRenderer.call(this);
|
|
489
581
|
if (!isExternalTool(this)) return original;
|
|
490
|
-
|
|
491
|
-
if (!original && this.expanded) return undefined;
|
|
492
|
-
return claudeRenderers(this.toolName, labelOf(this), isolateDelegate(original)).renderResult;
|
|
582
|
+
return claudeRenderers(this.toolName, labelOf(this), isolateDelegate(original), undefined, true).renderResult;
|
|
493
583
|
};
|
|
494
584
|
// The shell is fixed when the component is built, and the style draws its own rows without a box.
|
|
495
585
|
proto.getRenderShell = function (this: any) {
|
|
@@ -513,6 +603,38 @@ export function withClaudeToolStyleApi<P extends { registerTool: AnyFn }>(pi: P)
|
|
|
513
603
|
// ---------------------------------------------------------------------------
|
|
514
604
|
|
|
515
605
|
const MIN_GROUPED_TOOLS = 2;
|
|
606
|
+
/**
|
|
607
|
+
* Tools whose expanded body stays inside the group instead of breaking it apart.
|
|
608
|
+
*
|
|
609
|
+
* A file-tool body is a diff: a few dozen lines at most, and the reason you expand the row is to
|
|
610
|
+
* read it next to the call it belongs to. `read`, `bash`, `codemode` and friends are the opposite —
|
|
611
|
+
* hundreds of lines, an async highlight pass, or an image payload that a tree row cannot carry — so
|
|
612
|
+
* they keep the old behaviour of leaving the group when expanded.
|
|
613
|
+
*/
|
|
614
|
+
const GROUP_INLINE_BODY_TOOLS = new Set(["write", "edit", "apply_patch"]);
|
|
615
|
+
|
|
616
|
+
/** `claudeStyle.expandFileTools`: open a file tool's diff by default instead of one `+N -N` row. */
|
|
617
|
+
let expandFileTools = false;
|
|
618
|
+
|
|
619
|
+
export function setClaudeStyleExpandFileTools(enabled: boolean): void {
|
|
620
|
+
expandFileTools = enabled;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/** `claudeStyle.groupInlineTools`: extra names added to `GROUP_INLINE_BODY_TOOLS`. */
|
|
624
|
+
let extraInlineTools = new Set<string>();
|
|
625
|
+
|
|
626
|
+
export function setClaudeStyleGroupInlineTools(names: readonly string[] | undefined): void {
|
|
627
|
+
extraInlineTools = new Set(names ?? []);
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
/** A tool result carrying an image block: the host renders those itself, outside a tree row. */
|
|
631
|
+
function hasImageBlock(result: any): boolean {
|
|
632
|
+
return (Array.isArray(result?.content) ? result.content : []).some((block: any) => block?.type === "image");
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/** Built-in inline body tools plus whatever the config adds. */
|
|
636
|
+
const inlinesBody = (toolName: string | undefined): boolean =>
|
|
637
|
+
GROUP_INLINE_BODY_TOOLS.has(toolName ?? "") || extraInlineTools.has(toolName ?? "");
|
|
516
638
|
|
|
517
639
|
const fg = (color: string, text: string): string => groupTheme.fg(color, text);
|
|
518
640
|
const bold = (text: string): string => groupTheme.bold(text);
|
|
@@ -555,6 +677,11 @@ let agentActive = false;
|
|
|
555
677
|
* transcript (same toolCallIds, fresh components) starts without stale marks. */
|
|
556
678
|
let interruptedTools = new WeakSet<object>();
|
|
557
679
|
|
|
680
|
+
/** File tools this session has already opened once on the user's behalf. Keyed by component, so a
|
|
681
|
+
* rebuilt transcript starts fresh. Opening only once is what keeps Ctrl+O and a click able to
|
|
682
|
+
* collapse a file tool afterwards: re-opening on every frame would silently undo them. */
|
|
683
|
+
let autoOpenedFileTools = new WeakSet<object>();
|
|
684
|
+
|
|
558
685
|
export function setClaudeStyleAgentActive(active: boolean): void {
|
|
559
686
|
agentActive = active;
|
|
560
687
|
}
|
|
@@ -564,6 +691,7 @@ export function setClaudeStyleAgentActive(active: boolean): void {
|
|
|
564
691
|
export function resetClaudeStyleSessionState(): void {
|
|
565
692
|
agentActive = false;
|
|
566
693
|
interruptedTools = new WeakSet<object>();
|
|
694
|
+
autoOpenedFileTools = new WeakSet<object>();
|
|
567
695
|
}
|
|
568
696
|
|
|
569
697
|
/** A call whose result will never arrive: marked while idle, or never resolved at all. */
|
|
@@ -599,11 +727,20 @@ function summaryRow(members: any[], width: number): string[] {
|
|
|
599
727
|
function treeRows(members: any[], width: number): { lines: string[]; owners: any[] } {
|
|
600
728
|
// Text-less assistant turns only contribute to the summary's thought count; their
|
|
601
729
|
// own rows (a hidden-thinking label) would read as noise between the tool rows.
|
|
730
|
+
/** A row that carries a diff line, which keeps its own background and blank spacing. */
|
|
731
|
+
const isBodyRow = (member: any, lineIndex: number): boolean =>
|
|
732
|
+
lineIndex > 0 &&
|
|
733
|
+
Boolean(member.expanded) &&
|
|
734
|
+
!member.result?.isError &&
|
|
735
|
+
GROUP_INLINE_BODY_TOOLS.has(member.toolName ?? "");
|
|
602
736
|
const blocks = members
|
|
603
737
|
.filter(isToolComponent)
|
|
604
738
|
.map((member) => ({
|
|
605
739
|
member,
|
|
606
|
-
rows
|
|
740
|
+
// Blank rows inside an inlined diff are hunks separated for readability, so they survive.
|
|
741
|
+
rows: (member.render(width) as string[]).filter(
|
|
742
|
+
(line, i) => !isImageLine(line) && (isBodyRow(member, i) || stripAnsi(line).trim() !== ""),
|
|
743
|
+
),
|
|
607
744
|
}))
|
|
608
745
|
.filter((block) => block.rows.length > 0);
|
|
609
746
|
const lines: string[] = [];
|
|
@@ -618,7 +755,13 @@ function treeRows(members: any[], width: number): { lines: string[]; owners: any
|
|
|
618
755
|
if (lineIndex === 0 && stripAnsi(line).trimStart().startsWith(ICON_SUCCESS))
|
|
619
756
|
content = line.replace(ICON_SUCCESS, "•");
|
|
620
757
|
if (lineIndex === 0 && isInterrupted(member)) content = markInterruptedRow(content);
|
|
621
|
-
|
|
758
|
+
// A group row is the tool's row inside a tree, so it drops the tool-row background: a bar
|
|
759
|
+
// starting at the guide column would stripe the whole group. A diff line is the exception —
|
|
760
|
+
// its green/red background IS the information, so an inlined body row keeps it.
|
|
761
|
+
const body = isBodyRow(member, lineIndex)
|
|
762
|
+
? content.replace(LEADING_SPACE_RE, "$1")
|
|
763
|
+
: preserveBoxBackground(content).replace(LEADING_SPACE_RE, "$1");
|
|
764
|
+
const row = ` ${fg("dim", guide)}${body}`;
|
|
622
765
|
lines.push(visibleWidth(row) > width ? truncateToWidth(row, width, "") : row);
|
|
623
766
|
owners.push(member);
|
|
624
767
|
});
|
|
@@ -741,11 +884,33 @@ function renderGrouped(container: any, width: number): string[] {
|
|
|
741
884
|
}
|
|
742
885
|
const members = children.slice(index, end);
|
|
743
886
|
const tools = members.filter(isToolComponent);
|
|
887
|
+
// A file tool opens by default, but only once: it needs a result to show, and re-opening it
|
|
888
|
+
// every frame would undo the collapse a click or Ctrl+O just asked for. `setExpanded` always
|
|
889
|
+
// rebuilds the component, so this stays out of the steady state.
|
|
890
|
+
// Deliberately the built-in file tools only: `expandFileTools` is about diffs, and opening
|
|
891
|
+
// every tool a config adds to `groupInlineTools` would surprise the user with a body they
|
|
892
|
+
// never asked to see.
|
|
893
|
+
if (expandFileTools) {
|
|
894
|
+
for (const tool of tools) {
|
|
895
|
+
if (autoOpenedFileTools.has(tool)) continue;
|
|
896
|
+
if (!tool.result || !GROUP_INLINE_BODY_TOOLS.has(tool.toolName ?? "")) continue;
|
|
897
|
+
autoOpenedFileTools.add(tool);
|
|
898
|
+
if (!tool.expanded) tool.setExpanded?.(true);
|
|
899
|
+
}
|
|
900
|
+
}
|
|
744
901
|
// While idle, any result-less styled tool is a restored dangling call — mark it once.
|
|
745
902
|
if (!agentActive) {
|
|
746
903
|
for (const tool of tools) if (!tool.result) interruptedTools.add(tool);
|
|
747
904
|
}
|
|
748
|
-
|
|
905
|
+
// An image-bearing result cannot ride a tree row: `treeRows` drops image payload lines, so
|
|
906
|
+
// keeping such a tool inline would hide the image behind its fallback note.
|
|
907
|
+
// Independently of expansion: the host adds its image components whenever a result carries an
|
|
908
|
+
// image, and `treeRows` filters image payload lines out, so a grouped image result — collapsed
|
|
909
|
+
// or expanded — shows the fallback note instead of the image.
|
|
910
|
+
const leavesGroup =
|
|
911
|
+
tools.some((tool) => hasImageBlock(tool.result)) ||
|
|
912
|
+
tools.some((tool) => tool.expanded && !inlinesBody(tool.toolName));
|
|
913
|
+
if (tools.length < MIN_GROUPED_TOOLS || leavesGroup) {
|
|
749
914
|
for (const member of members) {
|
|
750
915
|
const rendered = member.render(width);
|
|
751
916
|
// A group has no summary to say "interrupted", so the lone row says it itself.
|
|
@@ -759,8 +924,13 @@ function renderGrouped(container: any, width: number): string[] {
|
|
|
759
924
|
}
|
|
760
925
|
} else {
|
|
761
926
|
const running = tools.some((tool) => isRunning(tool));
|
|
927
|
+
// A delegated renderer can repaint after its first render — pi-diff starts a placeholder
|
|
928
|
+
// and calls invalidate when the async diff lands — and that repaint changes none of the
|
|
929
|
+
// cache's identity inputs. So a group holding an expanded member is never served from the
|
|
930
|
+
// cache; it re-renders each frame, like a running one.
|
|
931
|
+
const live = running || tools.some((tool) => Boolean(tool.expanded));
|
|
762
932
|
const key = groupCacheKey(members);
|
|
763
|
-
const cached =
|
|
933
|
+
const cached = live ? undefined : state.store.get(key);
|
|
764
934
|
if (cached && isSameGroup(cached, members, tools)) {
|
|
765
935
|
push(cached.component, cached.rendered);
|
|
766
936
|
} else {
|
|
@@ -770,7 +940,7 @@ function renderGrouped(container: any, width: number): string[] {
|
|
|
770
940
|
const component = groupComponent(owners);
|
|
771
941
|
const rendered = [...summary, ...tree.lines];
|
|
772
942
|
push(component, rendered);
|
|
773
|
-
if (!
|
|
943
|
+
if (!live && state.store.size < GROUP_RENDER_CACHE_MAX) {
|
|
774
944
|
state.store.set(key, {
|
|
775
945
|
component,
|
|
776
946
|
members: [...members],
|
package/src/config.ts
CHANGED
|
@@ -123,6 +123,14 @@ export interface PrettyConfig {
|
|
|
123
123
|
thinkingIndicator?: ThinkingIndicatorConfig;
|
|
124
124
|
/** "claudecode" renders collapsed tools as `✓ Name (args)` rows with grouping. */
|
|
125
125
|
toolStyle?: "default" | "claudecode";
|
|
126
|
+
/** `claudecode` only: show `write`/`edit`/`apply_patch` diffs by default instead of one
|
|
127
|
+
* collapsed `+N -N` row. Ctrl+O still toggles them with everything else. */
|
|
128
|
+
claudeStyle?: {
|
|
129
|
+
expandFileTools?: boolean;
|
|
130
|
+
/** Extra tools whose expanded body stays inside the group instead of breaking it apart,
|
|
131
|
+
* added to `write`/`edit`/`apply_patch`. Only sensible for tools with a short body. */
|
|
132
|
+
groupInlineTools?: string[];
|
|
133
|
+
};
|
|
126
134
|
fff?: FffConfig;
|
|
127
135
|
}
|
|
128
136
|
|
|
@@ -162,6 +170,15 @@ export function loadConfig(agentDir = getConfigDir()): PrettyConfig {
|
|
|
162
170
|
}
|
|
163
171
|
if (typeof parsed.theme === "string" && parsed.theme.trim() !== "") config.theme = parsed.theme;
|
|
164
172
|
if (parsed.toolStyle === "default" || parsed.toolStyle === "claudecode") config.toolStyle = parsed.toolStyle;
|
|
173
|
+
// Built member by member: assigning `config.claudeStyle` wholesale would make each key
|
|
174
|
+
// silently drop the others when a config sets more than one.
|
|
175
|
+
const expandFileTools = parsed.claudeStyle?.expandFileTools;
|
|
176
|
+
const groupInlineTools = normalizeToolList(parsed.claudeStyle?.groupInlineTools);
|
|
177
|
+
if (typeof expandFileTools === "boolean" || groupInlineTools.length) {
|
|
178
|
+
config.claudeStyle = {};
|
|
179
|
+
if (typeof expandFileTools === "boolean") config.claudeStyle.expandFileTools = expandFileTools;
|
|
180
|
+
if (groupInlineTools.length) config.claudeStyle.groupInlineTools = groupInlineTools;
|
|
181
|
+
}
|
|
165
182
|
if (typeof parsed.userRail === "string" && /^#[0-9a-fA-F]{6}$/.test(parsed.userRail))
|
|
166
183
|
config.userRail = parsed.userRail;
|
|
167
184
|
if (typeof parsed.icons === "string") config.icons = parsed.icons;
|
package/src/fff.ts
CHANGED
|
@@ -33,9 +33,13 @@ export class FffInitError extends Error {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export function isFffRestrictedBasePathError(error: unknown, options: FffInitOptions): boolean {
|
|
36
|
-
if (!(error instanceof
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
if (!(error instanceof Error) || error.name !== "FffInitError") return false;
|
|
37
|
+
// FffService persists across extension reloads on globalThis, so a reloaded module may
|
|
38
|
+
// receive an FffInitError constructed from another load's class object; instanceof would
|
|
39
|
+
// wrongly fail there. Check the structural name instead.
|
|
40
|
+
if ((error as FffInitError).kind !== "restricted-base-path") return false;
|
|
41
|
+
if ((error as FffInitError).restrictedScope === "home") return !options.enableHomeDirScanning;
|
|
42
|
+
if ((error as FffInitError).restrictedScope === "root") return !options.enableFsRootScanning;
|
|
39
43
|
return false;
|
|
40
44
|
}
|
|
41
45
|
|
package/src/index.ts
CHANGED
|
@@ -26,6 +26,8 @@ import {
|
|
|
26
26
|
installClaudeExternalToolRenderers,
|
|
27
27
|
resetClaudeStyleSessionState,
|
|
28
28
|
setClaudeStyleAgentActive,
|
|
29
|
+
setClaudeStyleExpandFileTools,
|
|
30
|
+
setClaudeStyleGroupInlineTools,
|
|
29
31
|
setClaudeStyleTheme,
|
|
30
32
|
withClaudeToolStyleApi,
|
|
31
33
|
} from "./claude-style.js";
|
|
@@ -87,6 +89,8 @@ export default async function piPrettyExtension(pi: ExtensionAPI, deps?: PiPrett
|
|
|
87
89
|
const config = loadConfig();
|
|
88
90
|
applyConfig(config);
|
|
89
91
|
const claudeStyle = config.toolStyle === "claudecode";
|
|
92
|
+
setClaudeStyleExpandFileTools(claudeStyle && Boolean(config.claudeStyle?.expandFileTools));
|
|
93
|
+
setClaudeStyleGroupInlineTools(claudeStyle ? config.claudeStyle?.groupInlineTools : undefined);
|
|
90
94
|
setClaudeThinkingLabels(claudeStyle);
|
|
91
95
|
// claudecode style keeps user messages plain; the default style prefixes them with a prompt icon.
|
|
92
96
|
if (!claudeStyle) {
|
package/src/render.ts
CHANGED
|
@@ -174,21 +174,23 @@ export function preserveBoxBackground(ansi: string): string {
|
|
|
174
174
|
while (i < parts.length) {
|
|
175
175
|
const code = Number(parts[i]);
|
|
176
176
|
if (code === 38) {
|
|
177
|
-
// Foreground extended — keep
|
|
178
|
-
|
|
177
|
+
// Foreground extended — keep the introducer and every argument that belongs to it.
|
|
178
|
+
// The palette index must travel with `38;5`: read on its own it can land in the
|
|
179
|
+
// 40-49/100-107 background range and be dropped, leaving a colour-less `38;5`.
|
|
179
180
|
if (parts[i + 1] === "5") {
|
|
180
|
-
kept.push(parts
|
|
181
|
-
i +=
|
|
181
|
+
kept.push(...parts.slice(i, i + 3));
|
|
182
|
+
i += 3;
|
|
182
183
|
} else if (parts[i + 1] === "2") {
|
|
183
|
-
kept.push(parts
|
|
184
|
+
kept.push(...parts.slice(i, i + 5));
|
|
184
185
|
i += 5;
|
|
185
186
|
} else {
|
|
187
|
+
kept.push(parts[i]);
|
|
186
188
|
i++;
|
|
187
189
|
}
|
|
188
190
|
} else if (code === 48) {
|
|
189
|
-
// Background extended — skip
|
|
191
|
+
// Background extended — skip it and its own arguments only (48;2 takes 4, not 5).
|
|
190
192
|
if (parts[i + 1] === "5") i += 3;
|
|
191
|
-
else if (parts[i + 1] === "2") i +=
|
|
193
|
+
else if (parts[i + 1] === "2") i += 5;
|
|
192
194
|
else i++;
|
|
193
195
|
} else if (code === 49 || (code >= 40 && code <= 47) || (code >= 100 && code <= 107)) {
|
|
194
196
|
i++;
|