@xynogen/pix-pretty 1.34.0 → 1.35.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xynogen/pix-pretty",
3
- "version": "1.34.0",
3
+ "version": "1.35.0",
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",
@@ -22,6 +22,7 @@
22
22
  "./fff": "./src/fff.ts",
23
23
  "./types": "./src/types.ts",
24
24
  "./utils": "./src/utils.ts",
25
+ "./text": "./src/text.ts",
25
26
  "./widget-format": "./src/widget-format.ts",
26
27
  "./resize": "./src/resize.ts",
27
28
  "./context": "./src/tools/context.ts",
@@ -69,7 +70,7 @@
69
70
  "access": "public"
70
71
  },
71
72
  "dependencies": {
72
- "@xynogen/pix-runtime": "^0.15.0",
73
+ "@xynogen/pix-runtime": "^0.16.0",
73
74
  "chalk": "^4.1.2",
74
75
  "cli-highlight": "^2.1.11",
75
76
  "@ff-labs/fff-node": "^0.10.6",
@@ -1,6 +1,14 @@
1
- import { Text, truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
1
+ import {
2
+ mixColors,
3
+ Text,
4
+ truncateToWidth,
5
+ visibleWidth,
6
+ wrapTextWithAnsi,
7
+ } from "@earendil-works/pi-tui";
2
8
  import { hlBlock } from "./highlight.ts";
9
+ import { fadeText } from "./text.ts";
3
10
  import type { ThemeLike } from "./types.ts";
11
+ import type { formatCollapsedToolRow } from "./utils.ts";
4
12
 
5
13
  export function commandPreview(
6
14
  header: string,
@@ -60,8 +68,15 @@ export function commandPreview(
60
68
  };
61
69
  }
62
70
 
63
- export function collapsedCommandRow(header: string, command: string, theme: Pick<ThemeLike, "fg">) {
64
- let text = `${header}${theme.fg("muted", " · ")}${theme.fg("dim", command.replace(/\s+/g, " ").trim())}`;
71
+ export function collapsedCommandRow(
72
+ header: string,
73
+ command: string,
74
+ theme: Pick<ThemeLike, "fg"> &
75
+ Pick<Parameters<typeof formatCollapsedToolRow>[0], "colors" | "style">,
76
+ ) {
77
+ const plain = command.replace(/\s+/g, " ").trim();
78
+ const prefix = `${header}${theme.fg("muted", " · ")}`;
79
+ let text = `${prefix}${theme.fg("dim", plain)}`;
65
80
  let replaced = false;
66
81
  return {
67
82
  setText(value: string) {
@@ -72,7 +87,20 @@ export function collapsedCommandRow(header: string, command: string, theme: Pick
72
87
  invalidate() {},
73
88
  render(width: number): string[] {
74
89
  if (replaced) return text ? new Text(text, 0, 0).render(width) : [];
75
- return [truncateToWidth(text, width, "…")];
90
+ const room = width - visibleWidth(prefix);
91
+ return [
92
+ room > 0
93
+ ? `${prefix}${fadeText(plain, room, (text, fade) =>
94
+ fade === 0
95
+ ? theme.fg("dim", text)
96
+ : theme.colors && theme.style
97
+ ? theme.style(text, {
98
+ fg: mixColors(theme.colors.dim, theme.colors.customMessageBg, fade),
99
+ })
100
+ : theme.fg("muted", text),
101
+ )}`
102
+ : truncateToWidth(prefix, width, "…"),
103
+ ];
76
104
  },
77
105
  };
78
106
  }
package/src/index.ts CHANGED
@@ -9,13 +9,25 @@
9
9
  */
10
10
 
11
11
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
12
+ import { once } from "@xynogen/pix-runtime/once";
12
13
  import { registerFffCommands } from "./commands/fff.ts";
13
14
  import { fffState } from "./fff.ts";
14
15
  import { clearHighlightCache } from "./highlight.ts";
15
16
  import { initIconMode } from "./icon-persist.ts";
17
+ import { installOrderedWidgets } from "./ordered-widgets.ts";
16
18
  import type { PiPrettyApi } from "./types.ts";
17
19
 
18
20
  export default function piPrettyExtension(pi: ExtensionAPI): void {
21
+ once(pi, "pix-pretty-widgets", () => {
22
+ let restore: (() => void) | undefined;
23
+ pi.on("session_start", (_event, ctx) => {
24
+ if (ctx.mode === "tui") restore = installOrderedWidgets(ctx.ui);
25
+ });
26
+ pi.on("session_shutdown", () => {
27
+ restore?.();
28
+ restore = undefined;
29
+ });
30
+ });
19
31
  const prettyPi = pi as unknown as PiPrettyApi;
20
32
  clearHighlightCache();
21
33
 
@@ -0,0 +1,90 @@
1
+ import type { ExtensionUIContext, Theme } from "@earendil-works/pi-coding-agent";
2
+ import { type Component, Container, Text, type TUI } from "@earendil-works/pi-tui";
3
+
4
+ type Widget = Component & { dispose?(): void };
5
+ type Content = string[] | ((tui: TUI, theme: Theme) => Widget) | undefined;
6
+ type Options = { placement?: "aboveEditor" | "belowEditor" };
7
+
8
+ const ORDER = [
9
+ "pix-transient-error",
10
+ "welcome",
11
+ "pi-lens-lsp",
12
+ "pix-proc:procs",
13
+ "pix-aria2:progress",
14
+ "agents",
15
+ "pix-btw-live",
16
+ "voice-stt",
17
+ ];
18
+ const GROUP = "pix-ordered-widgets";
19
+
20
+ /** Keep Pix widgets in one host slot; Pi moves individually updated slots to the end. */
21
+ export function installOrderedWidgets(ui: Pick<ExtensionUIContext, "setWidget">): () => void {
22
+ const original = ui.setWidget as (key: string, content: Content, options?: Options) => void;
23
+ const below = new Set<string>();
24
+ const widgets = new Map<string, Widget>();
25
+ let environment: { tui: TUI; theme: Theme } | undefined;
26
+
27
+ const clear = () => {
28
+ const children = [...widgets.values()];
29
+ widgets.clear();
30
+ environment = undefined;
31
+ for (const child of children) child.dispose?.();
32
+ };
33
+ const setWidget = (key: string, content: Content, options?: Options) => {
34
+ if (!ORDER.includes(key)) {
35
+ original.call(ui, key, content, options);
36
+ return;
37
+ }
38
+ const previous = widgets.get(key);
39
+ widgets.delete(key);
40
+ previous?.dispose?.();
41
+ if (below.delete(key)) original.call(ui, key, undefined);
42
+
43
+ if (content !== undefined && options?.placement !== "belowEditor") {
44
+ if (!environment) {
45
+ original.call(
46
+ ui,
47
+ GROUP,
48
+ (tui: TUI, theme: Theme) => {
49
+ environment = { tui, theme };
50
+ return {
51
+ render: (width: number) =>
52
+ ORDER.flatMap((name) => widgets.get(name)?.render(width) ?? []),
53
+ invalidate: () => {
54
+ for (const widget of widgets.values()) widget.invalidate();
55
+ },
56
+ dispose: clear,
57
+ };
58
+ },
59
+ { placement: "aboveEditor" },
60
+ );
61
+ }
62
+ if (environment) {
63
+ let widget: Widget;
64
+ if (Array.isArray(content)) {
65
+ const container = new Container();
66
+ for (const line of content.slice(0, 10)) container.addChild(new Text(line, 1, 0));
67
+ if (content.length > 10) {
68
+ container.addChild(
69
+ new Text(environment.theme.fg("muted", "... (widget truncated)"), 1, 0),
70
+ );
71
+ }
72
+ widget = container;
73
+ } else {
74
+ widget = content(environment.tui, environment.theme);
75
+ }
76
+ widgets.set(key, widget);
77
+ }
78
+ } else if (options?.placement === "belowEditor") {
79
+ original.call(ui, key, content, options);
80
+ if (content !== undefined) below.add(key);
81
+ }
82
+ if (widgets.size === 0 && environment) original.call(ui, GROUP, undefined);
83
+ environment?.tui.requestRender();
84
+ };
85
+ ui.setWidget = setWidget;
86
+ return () => {
87
+ if (ui.setWidget === setWidget) ui.setWidget = original;
88
+ if (environment) original.call(ui, GROUP, undefined);
89
+ };
90
+ }
package/src/text.ts ADDED
@@ -0,0 +1,39 @@
1
+ import { sliceByColumn, stripTerminalSequences, visibleWidth } from "@earendil-works/pi-tui";
2
+
3
+ const graphemes = new Intl.Segmenter(undefined, { granularity: "grapheme" });
4
+
5
+ /**
6
+ * Fit one line to terminal columns, fading only overflow. Input styling/controls are
7
+ * stripped; paint owns styling (0 = normal, 1 = background). It must not change width.
8
+ */
9
+ export function fadeText(
10
+ text: string,
11
+ width: number,
12
+ paint: (text: string, fade: number) => string,
13
+ fadeColumns = 8,
14
+ ): string {
15
+ if (!Number.isFinite(width) || width < 1) return "";
16
+ const columns = Math.floor(width);
17
+ const plain = stripTerminalSequences(text).replace(/[\x00-\x1f\x7f-\x9f]/g, " ");
18
+ if (visibleWidth(plain) <= columns) return paint(plain, 0);
19
+ const clipped = sliceByColumn(plain, 0, columns, true);
20
+ const end = visibleWidth(clipped);
21
+ const fadeWidth = Number.isFinite(fadeColumns) ? Math.max(0, Math.floor(fadeColumns)) : 8;
22
+ if (!fadeWidth) return paint(clipped, 0);
23
+ const start = Math.max(0, end - fadeWidth);
24
+ let column = 0;
25
+ let head = "";
26
+ let output = "";
27
+ for (const { segment } of graphemes.segment(clipped)) {
28
+ column += visibleWidth(segment);
29
+ if (column <= start) head += segment;
30
+ else {
31
+ if (head) {
32
+ output += paint(head, 0);
33
+ head = "";
34
+ }
35
+ output += paint(segment, (column - start) / (end - start));
36
+ }
37
+ }
38
+ return output;
39
+ }
@@ -1,12 +1,27 @@
1
- import { Text, truncateToWidth } from "@earendil-works/pi-tui";
2
- import { rule } from "./utils.ts";
1
+ import type { Theme } from "@earendil-works/pi-coding-agent";
2
+ import { stripTerminalSequences } from "@earendil-works/pi-tui";
3
+ import { icon } from "./icon-catalog.ts";
4
+ import { rule, widgetActivityRow, widgetTitle } from "./utils.ts";
3
5
 
4
6
  export const TRANSIENT_ERROR_TTL_MS = 30_000;
5
7
  const WIDGET_KEY = "pix-transient-error";
6
8
  const timers = new WeakMap<object, ReturnType<typeof setTimeout>>();
7
9
 
8
10
  type TransientMessageTheme = {
9
- fg(color: "error" | "warning" | "accent" | "muted" | "borderMuted", text: string): string;
11
+ fg(
12
+ color:
13
+ | "error"
14
+ | "warning"
15
+ | "accent"
16
+ | "success"
17
+ | "toolTitle"
18
+ | "dim"
19
+ | "muted"
20
+ | "borderMuted",
21
+ text: string,
22
+ ): string;
23
+ colors?: Pick<Theme["colors"], "dim" | "muted">;
24
+ style?: Theme["style"];
10
25
  };
11
26
 
12
27
  export type TransientMessageLevel = "error" | "warning" | "info";
@@ -36,18 +51,33 @@ export function showTransientMessage(
36
51
  ui.setWidget(
37
52
  WIDGET_KEY,
38
53
  (_tui, theme) => {
39
- const text = new Text("", 0, 0);
54
+ const detail = stripTerminalSequences(message)
55
+ .replace(/[\x00-\x1f\x7f-\x9f]/g, " ")
56
+ .replace(/\s+/g, " ")
57
+ .trim();
58
+ const fadeTheme = {
59
+ fg: theme.fg.bind(theme),
60
+ style: theme.style?.bind(theme),
61
+ colors: theme.colors && { dim: theme.colors.dim, customMessageBg: theme.colors.muted },
62
+ };
40
63
  return {
41
64
  render(width: number) {
65
+ if (width < 1) return [];
42
66
  const color = level === "info" ? "accent" : level;
43
- const prefix = theme.fg(color, `${level} `);
44
- text.setText(prefix + theme.fg("muted", message.replace(/\s+/g, " ").trim()));
67
+ const glyph = icon(
68
+ level === "error"
69
+ ? "status.error"
70
+ : level === "warning"
71
+ ? "status.warn"
72
+ : "status.active",
73
+ );
74
+ const prefix = widgetTitle(theme, glyph, "Runtime") + theme.fg(color, level);
45
75
  return [
46
76
  rule(width, (glyphs) => theme.fg("borderMuted", glyphs)),
47
- truncateToWidth(text.render(width)[0] ?? "", width),
77
+ widgetActivityRow(fadeTheme, prefix, detail, width),
48
78
  ];
49
79
  },
50
- invalidate: () => text.invalidate(),
80
+ invalidate() {},
51
81
  };
52
82
  },
53
83
  { placement: "aboveEditor" },
package/src/utils.ts CHANGED
@@ -5,6 +5,7 @@ import {
5
5
  getCapabilities,
6
6
  hyperlink,
7
7
  MouseRegion,
8
+ mixColors,
8
9
  truncateToWidth,
9
10
  visibleWidth,
10
11
  } from "@earendil-works/pi-tui";
@@ -22,6 +23,7 @@ import {
22
23
  } from "./ansi.ts";
23
24
  import { MAX_PREVIEW_LINES } from "./config.ts";
24
25
  import { icon } from "./icon-catalog.ts";
26
+ import { fadeText } from "./text.ts";
25
27
  import type {
26
28
  FgTheme,
27
29
  TextComponentCtor,
@@ -268,9 +270,15 @@ export type CollapsedToolStatus = "success" | "error" | "warning";
268
270
  * (`⚡` is reserved for strength / model-score badges, not warnings.)
269
271
  */
270
272
  export const COLLAPSED_TOOL_GLYPH: Record<CollapsedToolStatus, string> = {
271
- success: "✓",
272
- warning: "⚠",
273
- error: "✗",
273
+ get success() {
274
+ return icon("status.ok");
275
+ },
276
+ get warning() {
277
+ return icon("status.warn");
278
+ },
279
+ get error() {
280
+ return icon("status.error");
281
+ },
274
282
  };
275
283
 
276
284
  /**
@@ -292,6 +300,15 @@ export function padIcon(glyph: string, width = 2): string {
292
300
  return pad > 0 ? glyph + " ".repeat(pad) : glyph;
293
301
  }
294
302
 
303
+ /** Fixed icon/name columns align the divider across compact activity widgets. */
304
+ export function widgetTitle(
305
+ theme: { fg: (role: "toolTitle" | "muted", text: string) => string },
306
+ glyph: string,
307
+ name: string,
308
+ ): string {
309
+ return theme.fg("toolTitle", `${padIcon(glyph, 3)} ${name.padEnd(8)}`) + theme.fg("muted", " │ ");
310
+ }
311
+
295
312
  /**
296
313
  * Join non-empty parts with a middot separator: `dotJoin(["a", "", "b"])` → `"a · b"`.
297
314
  * Empty/nullish parts are dropped so callers can pass conditional pieces inline.
@@ -311,8 +328,45 @@ type CollapsedToolTheme = {
311
328
  text: string,
312
329
  ) => string;
313
330
  bold: (text: string) => string;
331
+ colors?: {
332
+ dim: Parameters<typeof mixColors>[0];
333
+ customMessageBg: Parameters<typeof mixColors>[1];
334
+ };
335
+ style?: (text: string, style: { fg: ReturnType<typeof mixColors> }) => string;
314
336
  };
315
337
 
338
+ /** Keep identity/stats fixed; only the trailing activity consumes spare columns. */
339
+ export function widgetActivityRow(
340
+ theme: Pick<CollapsedToolTheme, "fg" | "colors" | "style">,
341
+ prefix: string,
342
+ activity: string,
343
+ width: number,
344
+ stats = "",
345
+ ): string {
346
+ if (stats) {
347
+ const room = width - visibleWidth(stats) - 2;
348
+ if (room < visibleWidth(prefix)) return truncateToWidth(`${prefix} ${stats}`, width, "…");
349
+ const body = widgetActivityRow(theme, prefix, activity, room);
350
+ return body + " ".repeat(width - visibleWidth(body) - visibleWidth(stats)) + stats;
351
+ }
352
+ const separator = theme.fg("muted", " · ");
353
+ const room = width - visibleWidth(prefix) - 3;
354
+ if (!activity || room < 1) return truncateToWidth(prefix, width, "…");
355
+ return (
356
+ prefix +
357
+ separator +
358
+ fadeText(activity, room, (text, fade) =>
359
+ fade === 0
360
+ ? theme.fg("dim", text)
361
+ : theme.colors && theme.style
362
+ ? theme.style(text, {
363
+ fg: mixColors(theme.colors.dim, theme.colors.customMessageBg, fade),
364
+ })
365
+ : theme.fg("muted", text),
366
+ )
367
+ );
368
+ }
369
+
316
370
  /** Use the host lifecycle fields so every call has the same status marker. */
317
371
  export function formatToolCallTitle(
318
372
  theme: {
@@ -347,16 +401,28 @@ export function formatCollapsedToolRow(
347
401
  target: string,
348
402
  meta = "",
349
403
  status: CollapsedToolStatus = "success",
404
+ width?: number,
350
405
  ): string {
351
406
  const marker = padIcon(
352
407
  icon(status === "success" ? "status.ok" : status === "error" ? "status.error" : "status.warn"),
353
408
  );
354
- const parts = [
355
- `${theme.fg(status, marker)} ${theme.fg("toolTitle", theme.bold(tool))}`,
356
- target ? theme.fg("dim", target) : "",
357
- meta ? `${theme.fg("muted", "·")} ${theme.fg("muted", meta)}` : "",
358
- ].filter(Boolean);
359
- return parts.join(" ");
409
+ const title = `${theme.fg(status, marker)} ${theme.fg("toolTitle", theme.bold(tool))}`;
410
+ const metadata = meta ? ` ${theme.fg("muted", "·")} ${theme.fg("muted", meta)}` : "";
411
+ if (width === undefined)
412
+ return `${title}${target ? ` ${theme.fg("dim", target)}` : ""}${metadata}`;
413
+ const room = width - visibleWidth(title) - visibleWidth(metadata) - 1;
414
+ const fitted =
415
+ target && room > 0
416
+ ? fadeText(target, room, (text, fade) => {
417
+ if (fade === 0) return theme.fg("dim", text);
418
+ return theme.colors && theme.style
419
+ ? theme.style(text, {
420
+ fg: mixColors(theme.colors.dim, theme.colors.customMessageBg, fade),
421
+ })
422
+ : theme.fg("muted", text);
423
+ })
424
+ : "";
425
+ return truncateToWidth(`${title}${fitted ? ` ${fitted}` : ""}${metadata}`, width, "…");
360
426
  }
361
427
 
362
428
  /** Render shared one-row content for tools using the self-rendered shell. */
@@ -369,7 +435,7 @@ export function renderCollapsedToolRow(
369
435
  width?: number,
370
436
  ): string {
371
437
  return fillToolBackground(
372
- formatCollapsedToolRow(theme, tool, target, meta, status),
438
+ formatCollapsedToolRow(theme, tool, target, meta, status, width ?? termW()),
373
439
  BG_BASE,
374
440
  width,
375
441
  );