@xynogen/pix-pretty 1.30.1 → 1.32.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.30.1",
3
+ "version": "1.32.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",
@@ -33,7 +33,8 @@
33
33
  "./tool-status": "./src/tool-status.ts",
34
34
  "./test-utils": "./src/test-utils.ts",
35
35
  "./transient-error": "./src/transient-error.ts",
36
- "./chips": "./src/chips.ts"
36
+ "./chips": "./src/chips.ts",
37
+ "./grammar-consent": "./src/grammar-consent.ts"
37
38
  },
38
39
  "scripts": {
39
40
  "test": "bun test"
@@ -68,7 +69,7 @@
68
69
  "access": "public"
69
70
  },
70
71
  "dependencies": {
71
- "@xynogen/pix-runtime": "^0.13.0",
72
+ "@xynogen/pix-runtime": "^0.14.0",
72
73
  "chalk": "^4.1.2",
73
74
  "cli-highlight": "^2.1.11",
74
75
  "@ff-labs/fff-node": "^0.10.6",
package/src/chips.ts CHANGED
@@ -51,7 +51,9 @@ type PiEditor = {
51
51
  /** A text paste becomes a chip only above this many characters (Pi's own limit is 1000). */
52
52
  const PASTE_MAX_CHARS = 100;
53
53
  const MARKER = /\[paste #(\d+)( (\+\d+ lines|\d+ chars))?\]/g;
54
- const SGR = "(?:\\x1b\\[[0-9;]*m|\\x1b_pi:c\\x07)*";
54
+ // Zero-width codes the editor may put inside a marker: SGR, the cursor marker, and
55
+ // pi-tui 1.4's fake-cursor APC pair (`\x1b_pi:fc\x07` … `\x1b_pi:/fc\x07`).
56
+ const SGR = "(?:\\x1b\\[[0-9;]*m|\\x1b_pi:(?:c|/?fc)\\x07)*";
55
57
  const PASTE_SPAN = new RegExp(`${SGR}\\[${SGR}paste #(?:[^\\]]|${SGR})*\\]`, "g");
56
58
  const PATH_TAG = /<path>([^<]+)<\/path>/g;
57
59
  /** Matches `chipTag.skill` output. Group 1 is the ref. */
@@ -60,7 +62,7 @@ const PASTE_TAG = /<paste>([\s\S]*?)<\/paste>/g;
60
62
  // Injected prompt from another extension (e.g. /plan). Kept as a tag for the model.
61
63
  const PROMPT_TAG = /<prompt name="([\w-]+)">([\s\S]*?)<\/prompt>/g;
62
64
  const PROMPT_ONLY = /^<prompt name="[\w-]+">[\s\S]*<\/prompt>\s*$/;
63
- const CODES = /\x1b\[[0-9;]*m|\x1b_pi:c\x07/g;
65
+ const CODES = /\x1b\[[0-9;]*m|\x1b_pi:(?:c|\/?fc)\x07/g;
64
66
  const IMAGE_PATH =
65
67
  /(^|[^\w/@])((?:~|[a-zA-Z]:[/\\]|\/|\\\\)[^\s,;'"(){}[\]]+\.(?:png|jpe?g|gif|webp|bmp|tiff?|heic|heif))(?=$|[\s,;'"(){}[\]])/gi;
66
68
 
@@ -79,7 +81,8 @@ export function expandChips(text: string, registry: Registry): string {
79
81
  /** Re-emit the cursor (inverse video + TUI marker) that a chip swallowed. */
80
82
  function keepCursor(span: string, label: string): string {
81
83
  const marker = span.includes(CURSOR_MARKER) ? CURSOR_MARKER : "";
82
- return span.includes("\x1b[7m")
84
+ // pi-tui <1.4 drew the cursor as inverse video; 1.4 wraps it in fake-cursor APC markers.
85
+ return span.includes("\x1b[7m") || span.includes("\x1b_pi:fc\x07")
83
86
  ? `${marker}\x1b[7m${label.replaceAll(RST, `${RST}\x1b[7m`)}\x1b[27m`
84
87
  : marker + label;
85
88
  }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * pix-pretty/grammar-consent — one-time user consent to install an ast-grep grammar.
3
+ *
4
+ * A tool's `execute` receives a Pi UI context. This turns it into a `ConsentFn`
5
+ * for `parseWithGrammar` (`@xynogen/pix-runtime/ast`): it shows a confirm overlay once per package. Without
6
+ * a UI (non-interactive session), it defers — the package installs nothing
7
+ * without a person saying yes.
8
+ */
9
+
10
+ import { type ConsentFn, grammarCacheDir } from "@xynogen/pix-runtime/ast";
11
+ import { showOverlay } from "./gate-overlay.ts";
12
+
13
+ // Minimal shape of the execute `ctx` we need. No hard dep on the host type.
14
+ export interface ExecuteCtx {
15
+ hasUI?: boolean;
16
+ ui: Parameters<typeof showOverlay>[0];
17
+ }
18
+
19
+ const INSTALL_TIMEOUT_MS = 60_000;
20
+
21
+ /** Build a consent function that asks once per grammar package. */
22
+ export function grammarConsent(ctx?: ExecuteCtx): ConsentFn | undefined {
23
+ if (!ctx?.hasUI) return undefined;
24
+ return async (pkg: string): Promise<boolean> => {
25
+ const result = await showOverlay(ctx.ui, {
26
+ mode: "confirm",
27
+ title: "Install ast-grep grammar",
28
+ body: [
29
+ `This language needs the grammar package:`,
30
+ ` ${pkg}`,
31
+ ``,
32
+ `Install it into the pix cache (${grammarCacheDir()})?`,
33
+ `If another grammar is already active, restart the agent after installation.`,
34
+ ],
35
+ accent: "accent",
36
+ timeoutMs: INSTALL_TIMEOUT_MS,
37
+ choices: [
38
+ { value: "yes", label: "Install", description: "Download and use this grammar" },
39
+ { value: "no", label: "Skip", description: "Do not install; skip this language" },
40
+ ],
41
+ });
42
+ return result.action === "approved";
43
+ };
44
+ }
package/src/shell-tool.ts CHANGED
@@ -189,7 +189,8 @@ export function registerShellTool(
189
189
  if (d?._type === "bashResult") {
190
190
  const normalizedText = normalizeShellText(d.text as string);
191
191
  const lc = normalizedText ? normalizedText.split("\n").length : 0;
192
- const durationMs = Number(d.durationMs ?? 0);
192
+ // Host time (monotonic, persisted) wins; details keep old hosts and sessions working.
193
+ const durationMs = Number(renderCtx.durationMs ?? d.durationMs ?? 0);
193
194
  const exitCode = d.exitCode as number | null;
194
195
  const status = exitCode === null ? "warning" : exitCode === 0 ? "success" : "error";
195
196
  const meta = dotJoin([
package/src/types.ts CHANGED
@@ -72,6 +72,8 @@ export type RenderContextLike<
72
72
  invalidate: () => void;
73
73
  /** Stable id for this tool execution — used to key resize invalidators. */
74
74
  toolCallId?: string;
75
+ /** Host-recorded execution time of the final result (Pi >= 1.1). Undefined while partial. */
76
+ durationMs?: number;
75
77
  };
76
78
 
77
79
  type SessionContextLike = ExtensionContext;
package/src/utils.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { isAbsolute, relative } from "node:path";
2
- import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
1
+ import { isAbsolute, relative, resolve } from "node:path";
2
+ import { pathToFileURL } from "node:url";
3
+ import { getCapabilities, hyperlink, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
3
4
 
4
5
  import {
5
6
  ANSI_CAPTURE_RE,
@@ -546,6 +547,17 @@ export function shortPath(cwd: string, home: string, p: string): string {
546
547
  return home && p.startsWith(home) ? `~${p.slice(home.length)}` : p;
547
548
  }
548
549
 
550
+ /**
551
+ * shortPath() wrapped in an OSC 8 `file://` link when the terminal supports it
552
+ * (pi-tui detects support, including tmux/screen). Width math and truncation in
553
+ * pi-tui skip OSC 8, and terminals without it get plain text.
554
+ */
555
+ export function linkedShortPath(cwd: string, home: string, p: string): string {
556
+ const text = shortPath(cwd, home, p);
557
+ if (!text || !getCapabilities().hyperlinks) return text;
558
+ return hyperlink(text, pathToFileURL(resolve(cwd, p)).href);
559
+ }
560
+
549
561
  /** Paints a rule line. Callers pass `(s) => theme.fg(status, s)` so the frame
550
562
  * tint follows the active theme (success/error/warning). Default = neutral FG_RULE. */
551
563
  export type RulePaint = (glyphs: string) => string;