@xynogen/pix-pretty 3.4.0 → 3.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xynogen/pix-pretty",
3
- "version": "3.4.0",
3
+ "version": "3.5.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",
@@ -42,6 +42,7 @@
42
42
  "./test-utils": "./src/test-utils.ts",
43
43
  "./transient-error": "./src/transient-error.ts",
44
44
  "./chips": "./src/chips.ts",
45
+ "./command-card": "./src/command-card.ts",
45
46
  "./grammar-consent": "./src/grammar-consent.ts",
46
47
  "./tui": "./src/tui.ts"
47
48
  },
@@ -0,0 +1,68 @@
1
+ /**
2
+ * command-card.ts — the card frame for a slash command's result (/agent, /btw).
3
+ *
4
+ * Layout: status glyph, bold TITLE and muted `· meta`; an accent `▐` prompt row;
5
+ * a blank row; then the body the caller adds. selectedBg keeps it apart from the
6
+ * main thread. Each package owns its entry type and renderer; this owns the look.
7
+ */
8
+
9
+ import type { Theme } from "@earendil-works/pi-coding-agent";
10
+ import { Box, type Component, Markdown, Spacer, Text } from "@earendil-works/pi-tui";
11
+ import { solidBackground } from "./ansi.ts";
12
+ import { icon } from "./icon-catalog.ts";
13
+ import { transformMarkdown } from "./markdown-transform.ts";
14
+ import { dotJoin } from "./render-row.ts";
15
+ import { getMarkdownTheme } from "./tui.ts";
16
+
17
+ export type CommandCardStatus = "success" | "warning" | "error";
18
+
19
+ export interface CommandCardHeader {
20
+ status: CommandCardStatus;
21
+ /** Shown bold, e.g. "AGENT". */
22
+ title: string;
23
+ /** Joined with ` · `; falsy parts are dropped. */
24
+ meta?: ReadonlyArray<string | false | null | undefined>;
25
+ /** What the user asked; shown dim behind an accent bar. */
26
+ prompt?: string;
27
+ }
28
+
29
+ type CardTheme = Pick<Theme, "fg" | "bg" | "bold">;
30
+
31
+ const GLYPH = { success: "status.ok", warning: "status.warn", error: "status.error" } as const;
32
+
33
+ /** The card frame with its header rows. Callers add the body children. */
34
+ export function commandCard(theme: CardTheme, header: CommandCardHeader): Box {
35
+ // Directive output ends styles with a full reset; keep the card color behind it.
36
+ // Children pad themselves, not the Box: Markdown leaves image rows unpadded, and
37
+ // framed images (math, Mermaid) indent that row to match, as in the transcript.
38
+ const card = new Box(
39
+ 0,
40
+ 1,
41
+ solidBackground((text) => theme.bg("selectedBg", text)),
42
+ );
43
+ const meta = dotJoin(header.meta ?? []);
44
+ const glyph = theme.fg(header.status, icon(GLYPH[header.status]));
45
+ const tail = meta ? ` ${theme.fg("muted", `· ${meta}`)}` : "";
46
+ card.addChild(new Text(`${glyph} ${theme.bold(header.title)}${tail}`, 1, 0));
47
+ if (header.prompt) {
48
+ card.addChild(new Text(`${theme.fg("accent", "▐")} ${theme.fg("dim", header.prompt)}`, 1, 0));
49
+ }
50
+ card.addChild(new Spacer(1));
51
+ return card;
52
+ }
53
+
54
+ /** Card body as Markdown, through the same display pipeline as main replies. */
55
+ export function cardMarkdown(text: string, theme: Pick<Theme, "fg">): Component {
56
+ try {
57
+ return new Markdown(
58
+ text,
59
+ 1,
60
+ 0,
61
+ getMarkdownTheme(),
62
+ { color: (value) => theme.fg("customMessageText", value) },
63
+ { transform: transformMarkdown },
64
+ );
65
+ } catch {
66
+ return new Text(theme.fg("customMessageText", text), 1, 0);
67
+ }
68
+ }
@@ -12,7 +12,7 @@ import * as Diff from "diff";
12
12
  import { BG_BASE, BOLD, FG_DIM, FG_GREEN, FG_LNUM, FG_RED, FG_RULE, RST } from "./ansi.ts";
13
13
  import { MAX_HL_CHARS, MAX_RENDER_LINES, WORD_DIFF_MIN_SIM } from "./config.ts";
14
14
  import type { DiffLine, ParsedDiff } from "./diff.ts";
15
- import { bodyLine } from "./frame.ts";
15
+ import { BODY_PAD, bodyLine } from "./frame.ts";
16
16
  import { hlBlock } from "./highlight.ts";
17
17
  import type { BundledLanguage, FgTheme } from "./types.ts";
18
18
  import { terminalWidth } from "./utils.ts";
@@ -189,7 +189,13 @@ function diffWidth(): number {
189
189
  // Single source of truth: utils.terminalWidth caches, falls back to tty ioctl, and
190
190
  // invalidates on resize. Diff layout needs a hard floor of 80 cols for the
191
191
  // split-view column math (no ceiling — fill the true width on ultrawide).
192
- return Math.max(80, terminalWidth());
192
+ // The diff sits in the tool-result body column, so the indent comes out of that width.
193
+ return Math.max(80, terminalWidth()) - BODY_PAD.length;
194
+ }
195
+
196
+ /** Rows indented into the body column, like every other tool-result body. */
197
+ function inBodyColumn(rows: readonly string[]): string[] {
198
+ return rows.map((row) => BODY_PAD + row);
193
199
  }
194
200
 
195
201
  /** Pad/truncate `s` to exactly `w` visible chars. ANSI-aware. */
@@ -489,7 +495,8 @@ function at<T>(arr: T[], i: number): T {
489
495
 
490
496
  function shouldUseSplit(diff: ParsedDiff, tw: number, maxRows = MAX_PREVIEW_LINES): boolean {
491
497
  if (!diff.lines.length) return false;
492
- if (tw < SPLIT_MIN_WIDTH) return false;
498
+ // The configured threshold is a terminal width; `tw` is the body column inside it.
499
+ if (tw + BODY_PAD.length < SPLIT_MIN_WIDTH) return false;
493
500
 
494
501
  const nw = Math.max(
495
502
  2,
@@ -668,12 +675,13 @@ export async function renderUnified(
668
675
  }
669
676
 
670
677
  out.push(rule(tw));
678
+ const rows = inBodyColumn(out);
671
679
  if (diff.lines.length > vis.length) {
672
- out.push(
680
+ rows.push(
673
681
  `${BG_BASE}${bodyLine(`${FG_DIM}… ${diff.lines.length - vis.length} more lines${RST}`)}`,
674
682
  );
675
683
  }
676
- return out.join("\n");
684
+ return rows.join("\n");
677
685
  }
678
686
 
679
687
  // ---------------------------------------------------------------------------
@@ -852,8 +860,9 @@ export async function renderSplit(
852
860
  }
853
861
 
854
862
  out.push(`${rule(half)}${FG_RULE}┊${RST}${rule(half)}`);
863
+ const framed = inBodyColumn(out);
855
864
  if (rows.length > vis.length) {
856
- out.push(`${BG_BASE}${bodyLine(`${FG_DIM}… ${rows.length - vis.length} more lines${RST}`)}`);
865
+ framed.push(`${BG_BASE}${bodyLine(`${FG_DIM}… ${rows.length - vis.length} more lines${RST}`)}`);
857
866
  }
858
- return out.join("\n");
867
+ return framed.join("\n");
859
868
  }
package/src/frame.ts CHANGED
@@ -217,6 +217,18 @@ export function bodyRows(
217
217
  };
218
218
  }
219
219
 
220
+ /**
221
+ * A call title that may wrap: `renderTitle` output plus its arguments. Rows after the first
222
+ * hang in the body column under the tool name, not at column 0.
223
+ */
224
+ export function titleBlock(title: string, rest = ""): BodyComponent {
225
+ const text = rest ? `${title} ${rest}` : title;
226
+ return {
227
+ render: (width) => wrapUnderIndent(text, width, BODY_PAD.length),
228
+ invalidate() {},
229
+ };
230
+ }
231
+
220
232
  /** Content that already sits in the body column, so `bodyRows` keeps it as is. */
221
233
  export type Body = { readonly text: string };
222
234
 
package/src/render-row.ts CHANGED
@@ -80,7 +80,7 @@ export function widgetTitle(
80
80
  * Pass `paint` (e.g. `(s) => theme.fg("dim", s)`) to tint the separator to theme.
81
81
  */
82
82
  export function dotJoin(
83
- parts: Array<string | false | null | undefined>,
83
+ parts: ReadonlyArray<string | false | null | undefined>,
84
84
  paint?: RulePaint,
85
85
  ): string {
86
86
  const sep = paint ? paint(" · ") : " · ";
package/src/renderers.ts CHANGED
@@ -4,7 +4,7 @@ import { prettySection } from "@xynogen/pix-runtime/sections";
4
4
 
5
5
  import { FG_DIM, FG_RULE, RST } from "./ansi.ts";
6
6
  import { MAX_PREVIEW_LINES } from "./config.ts";
7
- import { bodyLine, bodyWidth, type ExpandHintCtx, expandHint, rule } from "./frame.ts";
7
+ import { BODY_PAD, bodyLine, bodyWidth, type ExpandHintCtx, expandHint, rule } from "./frame.ts";
8
8
  import { hlBlock } from "./highlight.ts";
9
9
  import { dirIcon, fileColor, fileIcon } from "./icons.ts";
10
10
  import { lang } from "./lang.ts";
@@ -45,7 +45,8 @@ export async function renderFileContent(
45
45
  const codeRows = show.map((line, i) => hl[i] ?? line);
46
46
  const body = theme && total > maxLines ? fadeTail(codeRows, theme) : codeRows;
47
47
 
48
- const tw = options.width ?? terminalWidth();
48
+ // The frame sits in the tool-result body column, under the title, not at column 0.
49
+ const tw = Math.max(1, (options.width ?? terminalWidth()) - BODY_PAD.length);
49
50
  const startLine = offset;
50
51
  const endLine = startLine + show.length - 1;
51
52
  const nw = Math.max(3, String(endLine).length);
@@ -53,7 +54,7 @@ export async function renderFileContent(
53
54
  const cw = Math.max(1, tw - gw);
54
55
 
55
56
  const out: string[] = [];
56
- out.push(rule(tw));
57
+ out.push(BODY_PAD + rule(tw));
57
58
 
58
59
  for (let i = 0; i < body.length; i++) {
59
60
  const ln = startLine + i;
@@ -63,15 +64,15 @@ export async function renderFileContent(
63
64
  // continuation rows indent under the gutter so the code column aligns.
64
65
  const rows = wrapTextWithAnsi(code, cw);
65
66
  rows.forEach((rowText, r) => {
66
- out.push(`${lineGutter(r === 0 ? ln : "", nw)}${rowText}${RST}`);
67
+ out.push(`${BODY_PAD}${lineGutter(r === 0 ? ln : "", nw)}${rowText}${RST}`);
67
68
  });
68
69
  continue;
69
70
  }
70
71
  const display = truncateToWidth(code, cw, `${FG_DIM}›`);
71
- out.push(`${lineGutter(ln, nw)}${display}${RST}`);
72
+ out.push(`${BODY_PAD}${lineGutter(ln, nw)}${display}${RST}`);
72
73
  }
73
74
 
74
- out.push(rule(tw));
75
+ out.push(BODY_PAD + rule(tw));
75
76
  if (total > maxLines) {
76
77
  const more = `… ${pluralize(total - maxLines, "more line")} (${total} total) `;
77
78
  out.push(
package/src/shell-tool.ts CHANGED
@@ -280,7 +280,7 @@ export function gatedCancellation(action: string): {
280
280
  return {
281
281
  outcome: "timed-out",
282
282
  cancellationKind: "timeout",
283
- text: "Cancelled — Timed out — auto-denied.",
283
+ text: "Cancelled — Timed out — auto-denied. Often the user is away (AFK): rerun this call when they return.",
284
284
  };
285
285
  if (action === "denied")
286
286
  return { outcome: "denied", cancellationKind: "denied", text: "Cancelled — Denied by user." };
package/src/tui.ts CHANGED
@@ -30,6 +30,7 @@ export {
30
30
  Box,
31
31
  Container,
32
32
  decodeKittyPrintable,
33
+ deleteAllKittyImages,
33
34
  Editor,
34
35
  fuzzyFilter,
35
36
  getCapabilities,