@xynogen/pix-pretty 1.27.0 → 1.30.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/README.md CHANGED
@@ -54,15 +54,15 @@ problem on terminals without a Nerd Font, becomes a one-file edit here.
54
54
  tree with a default dot, connection status, and expandable shell variables
55
55
  with set state and an export example.
56
56
 
57
- UI features that used to live here have moved to [`pix-display`](packages/pix-display):
58
- paste chip rendering and reasoning-tag (`<think>`/`<thinking>`) → native
59
- `thinking` content blocks.
57
+ ### Inline chips (`./chips`)
60
58
 
61
- ## Install
59
+ The one source of truth for inline chip tags. Producers build tags with `chipTag`:
60
+ `chipTag.path(p)` (`@` picker), `chipTag.skill(ref)` (`$` picker), `chipTag.prompt(name, body)` (`/plan`).
61
+ The model receives each tag verbatim. `registerChips(pi)` shows them as chips in the prompt
62
+ editor and in sent user messages. `pix-display` calls it. Add a new chip kind here, not in a feature package.
62
63
 
63
- ```bash
64
- pi install npm:@xynogen/pix-pretty
65
- ```
64
+ UI features that moved to [`pix-display`](packages/pix-display): reasoning-tag (`<think>`/`<thinking>`) → native
65
+ `thinking` content blocks.
66
66
 
67
67
  ## Configuration
68
68
 
@@ -130,18 +130,32 @@ The package exposes its sub-modules via `exports`:
130
130
  @xynogen/pix-pretty/gate-overlay
131
131
  @xynogen/pix-pretty/modal-frame
132
132
  @xynogen/pix-pretty/provider-picker
133
+ @xynogen/pix-pretty/shell-tool (shared bash/powershell tool registrar + renderer)
134
+ @xynogen/pix-pretty/chips (inline chip tags + editor/history chip renderer)
133
135
  ```
134
136
 
135
- ## Full distro
137
+ ## Install
136
138
 
137
- Source: [github.com/xynogen/pix-mono](https://github.com/xynogen/pix-mono)
139
+ ```bash
140
+ pi install npm:@xynogen/pix-pretty
141
+ ```
142
+
143
+ > Foundation library. Feature packages install it as a dependency. Install it directly only when you build your own extension on it.
138
144
 
139
- To install the complete pix suite (all packages + Pi itself):
145
+ ## Full distro
146
+
147
+ This package is part of [Pix](https://github.com/xynogen/pix-mono). The installer sets up Pi and the full distro. See [Install](https://github.com/xynogen/pix-mono#install) for the notes for each OS.
140
148
 
141
149
  ```bash
150
+ # Linux / macOS
142
151
  curl -fsSL https://raw.githubusercontent.com/xynogen/pix-mono/main/scripts/install.sh | sh
143
152
  ```
144
153
 
154
+ ```powershell
155
+ # Windows
156
+ irm https://raw.githubusercontent.com/xynogen/pix-mono/main/scripts/install.ps1 | iex
157
+ ```
158
+
145
159
  ## License
146
160
 
147
- MIT
161
+ MIT. See [LICENSE](LICENSE).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xynogen/pix-pretty",
3
- "version": "1.27.0",
3
+ "version": "1.30.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",
@@ -28,8 +28,12 @@
28
28
  "./gate-overlay": "./src/gate-overlay.ts",
29
29
  "./modal-frame": "./src/modal-frame.ts",
30
30
  "./provider-picker": "./src/provider-picker.ts",
31
+ "./shell-tool": "./src/shell-tool.ts",
32
+ "./command-preview": "./src/command-preview.ts",
33
+ "./tool-status": "./src/tool-status.ts",
31
34
  "./test-utils": "./src/test-utils.ts",
32
- "./transient-error": "./src/transient-error.ts"
35
+ "./transient-error": "./src/transient-error.ts",
36
+ "./chips": "./src/chips.ts"
33
37
  },
34
38
  "scripts": {
35
39
  "test": "bun test"
@@ -64,7 +68,7 @@
64
68
  "access": "public"
65
69
  },
66
70
  "dependencies": {
67
- "@xynogen/pix-runtime": "^0.10.0",
71
+ "@xynogen/pix-runtime": "^0.13.0",
68
72
  "chalk": "^4.1.2",
69
73
  "cli-highlight": "^2.1.11",
70
74
  "@ff-labs/fff-node": "^0.10.6",
package/src/chips.ts ADDED
@@ -0,0 +1,307 @@
1
+ /**
2
+ * chips — the one source of truth for inline chip tags: their text format
3
+ * (`chipTag`), editor chips, and sent-message chips. Producers (pix-search `@`,
4
+ * pix-skills `$`, pix-core `/plan`) build tags with `chipTag`. pix-display
5
+ * activates the renderer with `registerChips(pi)`.
6
+ *
7
+ * long pasted text → buffer: [paste #1 +42 lines] display: 󰉿 text 42 lines
8
+ * /tmp/shot.png → buffer: [paste #2 13 chars] display: 󰋩 image #2
9
+ * <path>src/a.ts</path> → buffer: [paste #3 8 chars] display: 󰉿 @a.ts
10
+ * <prompt name="plan">… → buffer: [paste #4 900 chars] display: prompt
11
+ * <prompt name="plan-edit">… → … display: edit prompt
12
+ * <skill>a/b@tdd</skill> → buffer: [paste #5 7 chars] display: 󱁤 $tdd a/b
13
+ *
14
+ * Tags and Pi's `<paste>…</paste>` payloads are promoted to atomic paste markers (one backspace deletes the whole chip) and
15
+ * expanded back verbatim for the model.
16
+ */
17
+ import { basename } from "node:path";
18
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
19
+ import { CustomEditor } from "@earendil-works/pi-coding-agent";
20
+ import { CURSOR_MARKER, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
21
+ import { BOLD, FG_BLUE, FG_DIM, FG_GREEN, FG_YELLOW, RST } from "./ansi.ts";
22
+ import { icon } from "./icon-catalog.ts";
23
+ import { dirIcon, fileIcon } from "./icons.ts";
24
+
25
+ /** Build a chip tag. The model receives the tag verbatim. The UI shows a chip. */
26
+ export const chipTag = {
27
+ /** `@` file or folder mention. A folder keeps its trailing `/`. */
28
+ path: (path: string) => `<path>${path}</path>`,
29
+ /** `$` skill: `name` (local) or `owner/repo@name` (skills.sh). */
30
+ skill: (ref: string) => `<skill>${ref}</skill>`,
31
+ /** Injected prompt, e.g. `/plan`. `name` must match `[\w-]+`. */
32
+ prompt: (name: string, body: string) => `<prompt name="${name}">${body}</prompt>`,
33
+ };
34
+
35
+ // ponytail: Pi only exposes atomic paste tokens today. Keep its private registry
36
+ // adapter here; replace this adapter when Pi provides a public inline-token API.
37
+ type Chip =
38
+ | { kind: "image" | "path"; path: string }
39
+ | { kind: "skill"; ref: string }
40
+ | { kind: "prompt"; name: string; body: string };
41
+ type Registry = Map<number, string | Chip>;
42
+ type PiEditor = {
43
+ pastes: Registry;
44
+ pasteCounter: number;
45
+ state: { lines: string[]; cursorLine: number; cursorCol: number };
46
+ setCursorCol(col: number): void;
47
+ expandPasteMarkers(text: string): string;
48
+ handlePaste(text: string): void;
49
+ insertTextAtCursorInternal(text: string): void;
50
+ };
51
+ /** A text paste becomes a chip only above this many characters (Pi's own limit is 1000). */
52
+ const PASTE_MAX_CHARS = 100;
53
+ const MARKER = /\[paste #(\d+)( (\+\d+ lines|\d+ chars))?\]/g;
54
+ const SGR = "(?:\\x1b\\[[0-9;]*m|\\x1b_pi:c\\x07)*";
55
+ const PASTE_SPAN = new RegExp(`${SGR}\\[${SGR}paste #(?:[^\\]]|${SGR})*\\]`, "g");
56
+ const PATH_TAG = /<path>([^<]+)<\/path>/g;
57
+ /** Matches `chipTag.skill` output. Group 1 is the ref. */
58
+ export const SKILL_TAG = /<skill>([^<]+)<\/skill>/g;
59
+ const PASTE_TAG = /<paste>([\s\S]*?)<\/paste>/g;
60
+ // Injected prompt from another extension (e.g. /plan). Kept as a tag for the model.
61
+ const PROMPT_TAG = /<prompt name="([\w-]+)">([\s\S]*?)<\/prompt>/g;
62
+ const PROMPT_ONLY = /^<prompt name="[\w-]+">[\s\S]*<\/prompt>\s*$/;
63
+ const CODES = /\x1b\[[0-9;]*m|\x1b_pi:c\x07/g;
64
+ const IMAGE_PATH =
65
+ /(^|[^\w/@])((?:~|[a-zA-Z]:[/\\]|\/|\\\\)[^\s,;'"(){}[\]]+\.(?:png|jpe?g|gif|webp|bmp|tiff?|heic|heif))(?=$|[\s,;'"(){}[\]])/gi;
66
+
67
+ /** Expand once: token-looking text inside a paste is literal user content. */
68
+ export function expandChips(text: string, registry: Registry): string {
69
+ return text.replace(MARKER, (marker, id: string) => {
70
+ const value = registry.get(Number(id));
71
+ if (value === undefined) return marker;
72
+ if (typeof value === "string") return `<paste>${value}</paste>`;
73
+ if (value.kind === "prompt") return chipTag.prompt(value.name, value.body);
74
+ if (value.kind === "skill") return chipTag.skill(value.ref);
75
+ return value.kind === "path" ? chipTag.path(value.path) : `<paste>${value.path}</paste>`;
76
+ });
77
+ }
78
+
79
+ /** Re-emit the cursor (inverse video + TUI marker) that a chip swallowed. */
80
+ function keepCursor(span: string, label: string): string {
81
+ const marker = span.includes(CURSOR_MARKER) ? CURSOR_MARKER : "";
82
+ return span.includes("\x1b[7m")
83
+ ? `${marker}\x1b[7m${label.replaceAll(RST, `${RST}\x1b[7m`)}\x1b[27m`
84
+ : marker + label;
85
+ }
86
+
87
+ /** Plain chip text: `head` is the identity, `meta` the dim size/id suffix. */
88
+ function chipLabel(
89
+ value: string | Chip,
90
+ id?: number,
91
+ ): { head: string; meta: string; color: string } {
92
+ if (typeof value === "string") {
93
+ const count =
94
+ value.length < 1000 ? `${value.length}` : `${Number((value.length / 1000).toFixed(1))}k`;
95
+ return {
96
+ head: `${icon("paste.text")} text`,
97
+ meta: `${count} chars`,
98
+ color: FG_GREEN,
99
+ };
100
+ }
101
+ if (value.kind === "prompt") {
102
+ // The first name segment is the producer namespace (`plan`). The icon already shows it.
103
+ const sub = value.name.split("-").slice(1).join("-");
104
+ return {
105
+ head: `${icon("paste.prompt")}${sub ? ` ${sub}` : ""}`,
106
+ meta: "prompt",
107
+ color: FG_YELLOW,
108
+ };
109
+ }
110
+ if (value.kind === "skill") {
111
+ // `owner/repo@name` (skills.sh) or bare `name` (local).
112
+ const at = value.ref.lastIndexOf("@");
113
+ // ponytail: reuses the `tools` icon. Add a `skill` catalog key in pix-runtime if it needs its own glyph.
114
+ return {
115
+ head: `${icon("tools")} $${value.ref.slice(at + 1)}`,
116
+ meta: at < 0 ? "" : value.ref.slice(0, at),
117
+ color: FG_YELLOW,
118
+ };
119
+ }
120
+ if (value.kind === "path") {
121
+ const dir = value.path.endsWith("/");
122
+ const name = basename(value.path) || value.path;
123
+ // Same file-type glyphs the picker shows (trailing space is part of the icon).
124
+ return {
125
+ head: `${dir ? dirIcon() : fileIcon(value.path)}@${name}${dir && name !== "/" ? "/" : ""}`,
126
+ meta: "",
127
+ color: FG_BLUE,
128
+ };
129
+ }
130
+ return {
131
+ head: `${icon("paste.image")} image`,
132
+ meta: id === undefined ? "" : `#${id}`,
133
+ color: FG_BLUE,
134
+ };
135
+ }
136
+
137
+ export function renderChips(line: string, registry: Registry): string {
138
+ return line.replace(PASTE_SPAN, (span) => {
139
+ const id = Number(/\[paste #(\d+)/.exec(span.replace(CODES, ""))?.[1]);
140
+ const value = registry.get(id);
141
+ if (value === undefined) return span;
142
+ const { head, meta, color } = chipLabel(value, id);
143
+ const label = `${color}${BOLD}${head}${RST}${meta ? `${FG_DIM} ${meta}${RST}` : ""}`;
144
+ // Tight, no padding: Pi locates the cursor by its marker, so a shorter chip
145
+ // just shifts following text left. render() clamps overflow.
146
+ return keepCursor(span, label);
147
+ });
148
+ }
149
+
150
+ const HISTORY_TAG =
151
+ /<(paste|path|skill)>([\s\S]*?)<\/\1>|<prompt name="([\w-]+)">([\s\S]*?)<\/prompt>/g;
152
+ const IMAGE_FILE =
153
+ /^(?:~|[a-zA-Z]:[/\\]|\/|\\\\)[^\r\n]+\.(?:png|jpe?g|gif|webp|bmp|tiff?|heic|heif)$/i;
154
+ const PREVIEW_CHARS = 40;
155
+
156
+ /** Head…tail glimpse of a paste (whitespace collapsed, backticks dropped for inline code). */
157
+ function snippet(text: string): string {
158
+ const flat = text.replace(/`/g, "").replace(/\s+/g, " ").trim();
159
+ if (flat.length <= PREVIEW_CHARS) return flat;
160
+ const tail = Math.floor(PREVIEW_CHARS / 3);
161
+ return `${flat.slice(0, PREVIEW_CHARS - tail).trimEnd()}…${flat.slice(-tail).trimStart()}`;
162
+ }
163
+
164
+ /**
165
+ * Display-only: collapse `<paste>…</paste>` / `<path>…</path>` in a sent user
166
+ * message into the same chips the editor showed. Session and model context
167
+ * keep the full text; images take the paste chip since the file path is the
168
+ * whole payload.
169
+ */
170
+ export function renderHistoryChips(markdown: string): string {
171
+ return markdown.replace(
172
+ HISTORY_TAG,
173
+ (_match, tag?: string, text?: string, name?: string, prompt?: string) => {
174
+ if (name !== undefined) {
175
+ const { head, meta } = chipLabel({ kind: "prompt", name, body: prompt ?? "" });
176
+ return `\`${head} ${meta}\``;
177
+ }
178
+ const body = text ?? "";
179
+ let value: string | Chip = body;
180
+ if (tag === "path") value = { kind: "path", path: body };
181
+ else if (tag === "skill") value = { kind: "skill", ref: body };
182
+ else if (IMAGE_FILE.test(body)) value = { kind: "image", path: body };
183
+ const { head, meta } = chipLabel(value);
184
+ // Text pastes keep a short glimpse so history stays scannable.
185
+ const preview = typeof value === "string" ? snippet(value) : "";
186
+ return `\`${head}${meta ? ` ${meta}` : ""}${preview ? ` · ${preview}` : ""}\``;
187
+ },
188
+ );
189
+ }
190
+
191
+ /** Patch one editor instance; order-independent with other instance patchers (pix-search). */
192
+ export function installChips(editor: CustomEditor): void {
193
+ // SAFETY: Pi's TS-private members remain runtime properties on CustomEditor.
194
+ const pi = editor as unknown as PiEditor;
195
+ pi.expandPasteMarkers = (text) => expandChips(text, pi.pastes);
196
+ const handlePaste = pi.handlePaste.bind(editor);
197
+ pi.handlePaste = (text) => {
198
+ if (IMAGE_FILE.test(text) || PROMPT_ONLY.test(text)) {
199
+ editor.insertTextAtCursor(IMAGE_FILE.test(text) ? `<paste>${text}</paste>` : text.trim());
200
+ return;
201
+ }
202
+ // Pi cleans the text, takes the undo snapshot and picks inline vs chip by its own
203
+ // rule (>10 lines or >1000 chars). Size alone decides here, so fix Pi's pick after it.
204
+ const { cursorLine: l0, cursorCol: c0 } = pi.state;
205
+ const before = pi.pasteCounter;
206
+ handlePaste(text);
207
+ const chipped = pi.pasteCounter > before ? pi.pastes.get(pi.pasteCounter) : undefined;
208
+ if (chipped !== undefined && typeof chipped !== "string") return;
209
+ // Pi inserted its text or marker from (l0, c0) to the cursor.
210
+ const { lines, cursorLine: l1, cursorCol: c1 } = pi.state;
211
+ const first = lines[l0] ?? "";
212
+ const last = lines[l1] ?? "";
213
+ const value =
214
+ chipped ??
215
+ (l0 === l1
216
+ ? first.slice(c0, c1)
217
+ : [first.slice(c0), ...lines.slice(l0 + 1, l1), last.slice(0, c1)].join("\n"));
218
+ const wantChip = value.length > PASTE_MAX_CHARS;
219
+ if (wantChip !== (chipped !== undefined)) {
220
+ pi.state.lines = [
221
+ ...lines.slice(0, l0),
222
+ first.slice(0, c0) + last.slice(c1),
223
+ ...lines.slice(l1 + 1),
224
+ ];
225
+ pi.state.cursorLine = l0;
226
+ pi.setCursorCol(c0);
227
+ if (wantChip) {
228
+ const id = ++pi.pasteCounter;
229
+ pi.pastes.set(id, value);
230
+ pi.insertTextAtCursorInternal(`[paste #${id} ${value.length} chars]`);
231
+ } else {
232
+ pi.pastes.delete(pi.pasteCounter);
233
+ pi.pasteCounter = before;
234
+ pi.insertTextAtCursorInternal(value);
235
+ }
236
+ }
237
+ // Land the cursor after the chip, not glued to it.
238
+ if (wantChip) pi.insertTextAtCursorInternal(" ");
239
+ };
240
+ const insertTextAtCursor = editor.insertTextAtCursor.bind(editor);
241
+ editor.insertTextAtCursor = (text: string) => {
242
+ if (!text) return;
243
+ // SAFETY: Pi snapshots and renumbers registry values without interpreting them.
244
+ const chip = (value: string | Chip, length: number) => {
245
+ const id = ++pi.pasteCounter;
246
+ pi.pastes.set(id, value);
247
+ return `[paste #${id} ${length} chars]`;
248
+ };
249
+ if (IMAGE_FILE.test(text.trim())) {
250
+ const trimmed = text.trim();
251
+ const replaced = chip({ kind: "image", path: trimmed }, trimmed.length);
252
+ insertTextAtCursor(`${replaced} `);
253
+ return;
254
+ }
255
+ const replaced = text
256
+ .replace(PROMPT_TAG, (_match, name: string, body: string) =>
257
+ chip({ kind: "prompt", name, body }, body.length),
258
+ )
259
+ .replace(PATH_TAG, (_match, path: string) => chip({ kind: "path", path }, path.length))
260
+ .replace(SKILL_TAG, (_match, ref: string) => chip({ kind: "skill", ref }, ref.length))
261
+ .replace(PASTE_TAG, (_match, body: string) =>
262
+ chip(IMAGE_FILE.test(body) ? { kind: "image", path: body } : body, body.length),
263
+ )
264
+ .replace(
265
+ IMAGE_PATH,
266
+ (_match, prefix: string, path: string) =>
267
+ prefix + chip({ kind: "image", path }, path.length),
268
+ );
269
+ insertTextAtCursor(/\[paste #\d+[^\]]*\]$/.test(replaced) ? `${replaced} ` : replaced);
270
+ };
271
+ const render = editor.render.bind(editor);
272
+ editor.render = (width: number) =>
273
+ render(width).map((line) => {
274
+ // SAFETY: Pi owns the current registry, including its replacement during undo.
275
+ const styled = renderChips(line, pi.pastes);
276
+ // Restyling may widen a line (e.g. "#1" → "text"); clamp only on overflow.
277
+ return visibleWidth(styled) > width ? truncateToWidth(styled, width, "") : styled;
278
+ });
279
+ }
280
+
281
+ /** Activate chips: sent-message transformer + editor patch. pix-display calls this. */
282
+ export function registerChips(pi: ExtensionAPI): void {
283
+ // ponytail: local Pi 0.82 types predate the runtime Markdown transformer hook.
284
+ const markdownPi = pi as ExtensionAPI & {
285
+ registerMarkdownTransformer?: (
286
+ transformer: (markdown: string, context: { messageType: string }) => string,
287
+ ) => void;
288
+ };
289
+ markdownPi.registerMarkdownTransformer?.((markdown, { messageType }) =>
290
+ messageType === "user" ? renderHistoryChips(markdown) : markdown,
291
+ );
292
+
293
+ pi.on("session_start", (_event, ctx) => {
294
+ if (ctx.mode !== "tui") return;
295
+ const previous = ctx.ui.getEditorComponent();
296
+ ctx.ui.setEditorComponent((tui, theme, kb) => {
297
+ const editor = previous?.(tui, theme, kb) ?? new CustomEditor(tui, theme, kb);
298
+ // ponytail: chips need CustomEditor internals; a foreign editor is kept unchipped.
299
+ if (editor instanceof CustomEditor) installChips(editor);
300
+ return editor;
301
+ });
302
+ });
303
+
304
+ pi.on("session_shutdown", (_event, ctx) => {
305
+ if (ctx.mode === "tui") ctx.ui.setEditorComponent(undefined);
306
+ });
307
+ }
@@ -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
+ }
@@ -1,5 +1,5 @@
1
- import type { FffState } from "../fff.js";
2
- import type { CommandContextLike, PiPrettyApi } from "../types.js";
1
+ import type { FffState } from "../fff.ts";
2
+ import type { CommandContextLike, PiPrettyApi } from "../types.ts";
3
3
 
4
4
  // ── FFF slash commands ─────────────────────────────────────────────────
5
5
 
package/src/confirm.ts CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  modalWidth,
15
15
  selectListTheme,
16
16
  terminalModalHeight,
17
- } from "./modal-frame.js";
17
+ } from "./modal-frame.ts";
18
18
 
19
19
  // Minimal structural type for the `ctx.ui.custom` host call.
20
20
  interface CustomTheme {
@@ -9,12 +9,12 @@
9
9
  import { config } from "@xynogen/pix-runtime/config";
10
10
  import { prettySection } from "@xynogen/pix-runtime/sections";
11
11
  import * as Diff from "diff";
12
- import { BG_BASE, BOLD, FG_DIM, FG_GREEN, FG_LNUM, FG_RED, FG_RULE, RST } from "./ansi.js";
13
- import { MAX_HL_CHARS, MAX_RENDER_LINES, WORD_DIFF_MIN_SIM } from "./config.js";
14
- import type { DiffLine, ParsedDiff } from "./diff.js";
15
- import { hlBlock } from "./highlight.js";
16
- import type { BundledLanguage, FgTheme } from "./types.js";
17
- import { termW as utilsTermW } from "./utils.js";
12
+ import { BG_BASE, BOLD, FG_DIM, FG_GREEN, FG_LNUM, FG_RED, FG_RULE, RST } from "./ansi.ts";
13
+ import { MAX_HL_CHARS, MAX_RENDER_LINES, WORD_DIFF_MIN_SIM } from "./config.ts";
14
+ import type { DiffLine, ParsedDiff } from "./diff.ts";
15
+ import { hlBlock } from "./highlight.ts";
16
+ import type { BundledLanguage, FgTheme } from "./types.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)
@@ -102,8 +102,31 @@ export const DEFAULT_DIFF_COLORS: DiffColors = {
102
102
  type DiffTheme = {
103
103
  fg?: FgTheme["fg"];
104
104
  getFgAnsi?: (key: string) => string;
105
+ getBgAnsi?: (key: string) => string;
105
106
  };
106
107
 
108
+ function themeBg(theme: DiffTheme, key: string): string | undefined {
109
+ try {
110
+ return theme.getBgAnsi?.(key) || undefined;
111
+ } catch {
112
+ return undefined;
113
+ }
114
+ }
115
+
116
+ const RGB_RE = /^\x1b\[[34]8;2;(\d+);(\d+);(\d+)m$/;
117
+
118
+ /**
119
+ * Word-diff emphasis: the row tint moved 25% toward the diff foreground.
120
+ * Undefined when either color is not truecolor (256-color themes keep the default).
121
+ */
122
+ function strongerBg(bg: string, fg: string): string | undefined {
123
+ const b = RGB_RE.exec(bg);
124
+ const f = RGB_RE.exec(fg);
125
+ if (!b || !f) return undefined;
126
+ const mix = [1, 2, 3].map((i) => Math.round(Number(b[i]) * 0.75 + Number(f[i]) * 0.25));
127
+ return `\x1b[48;2;${mix.join(";")}m`;
128
+ }
129
+
107
130
  function themeFg(theme: DiffTheme, key: string, fallback: string): string {
108
131
  try {
109
132
  return theme.getFgAnsi?.(key) || fallback;
@@ -114,17 +137,25 @@ function themeFg(theme: DiffTheme, key: string, fallback: string): string {
114
137
 
115
138
  export function resolveDiffColors(theme?: DiffTheme): DiffColors {
116
139
  if (!theme) return DEFAULT_DIFF_COLORS;
140
+ const fgAdd = themeFg(theme, "toolDiffAdded", FG_ADD);
141
+ const fgDel = themeFg(theme, "toolDiffRemoved", FG_DEL);
142
+ // Row tints follow the theme's tool success/error backgrounds, so a light
143
+ // theme gets light bands. Themes without them keep the dark defaults.
144
+ const themedAdd = themeBg(theme, "toolSuccessBg");
145
+ const themedDel = themeBg(theme, "toolErrorBg");
146
+ const bgAdd = themedAdd ?? BG_ADD_FAINT;
147
+ const bgDel = themedDel ?? BG_DEL_FAINT;
117
148
  return {
118
- fgAdd: themeFg(theme, "toolDiffAdded", FG_ADD),
119
- fgDel: themeFg(theme, "toolDiffRemoved", FG_DEL),
149
+ fgAdd,
150
+ fgDel,
120
151
  fgCtx: themeFg(theme, "toolDiffContext", FG_DIM),
121
152
  theme: typeof theme.fg === "function" ? (theme as FgTheme) : undefined,
122
- bgAdd: BG_ADD_FAINT,
123
- bgDel: BG_DEL_FAINT,
124
- bgAddHighlight: BG_ADD_STRONG,
125
- bgDelHighlight: BG_DEL_STRONG,
126
- bgGutterAdd: BG_ADD_FAINT,
127
- bgGutterDel: BG_DEL_FAINT,
153
+ bgAdd,
154
+ bgDel,
155
+ bgAddHighlight: (themedAdd && strongerBg(themedAdd, fgAdd)) ?? BG_ADD_STRONG,
156
+ bgDelHighlight: (themedDel && strongerBg(themedDel, fgDel)) ?? BG_DEL_STRONG,
157
+ bgGutterAdd: bgAdd,
158
+ bgGutterDel: bgDel,
128
159
  };
129
160
  }
130
161
 
@@ -637,7 +668,7 @@ export async function renderUnified(
637
668
 
638
669
  out.push(rule(tw));
639
670
  if (diff.lines.length > vis.length) {
640
- out.push(`${BG_BASE}${FG_DIM} … ${diff.lines.length - vis.length} more lines${RST}`);
671
+ out.push(`${BG_BASE}${FG_DIM}${BODY_PAD}… ${diff.lines.length - vis.length} more lines${RST}`);
641
672
  }
642
673
  return out.join("\n");
643
674
  }
@@ -819,7 +850,7 @@ export async function renderSplit(
819
850
 
820
851
  out.push(`${rule(half)}${FG_RULE}┊${RST}${rule(half)}`);
821
852
  if (rows.length > vis.length) {
822
- out.push(`${BG_BASE}${FG_DIM} … ${rows.length - vis.length} more lines${RST}`);
853
+ out.push(`${BG_BASE}${FG_DIM}${BODY_PAD}… ${rows.length - vis.length} more lines${RST}`);
823
854
  }
824
855
  return out.join("\n");
825
856
  }
package/src/fff.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { join } from "node:path";
2
-
3
2
  import type { GrepCursor, GrepMatch } from "@ff-labs/fff-node";
3
+ import { cacheDir } from "@xynogen/pix-runtime/paths";
4
4
 
5
- import type { FffBackedFinder, OptionalFffModule } from "./types.js";
5
+ import type { FffBackedFinder, OptionalFffModule } from "./types.ts";
6
6
 
7
7
  export interface FffState {
8
8
  module: OptionalFffModule | null;
@@ -20,15 +20,17 @@ export const fffState: FffState = {
20
20
 
21
21
  export const FFF_SCAN_TIMEOUT = 15_000;
22
22
 
23
- export function getPiPrettyFffDir(_agentDir: string): string {
24
- // FFF state lives under the XDG cache dir, not the agent dir.
25
- // Override with PRETTY_FFF_DIR; otherwise ~/.cache/pi/fff
26
- // ($XDG_CACHE_HOME/pi/fff when XDG_CACHE_HOME is set).
23
+ /**
24
+ * FFF state lives under the Pi cache dir, not the agent dir. Override with
25
+ * PRETTY_FFF_DIR; otherwise `cacheDir()/fff` (~/.cache/pi/fff, or
26
+ * $XDG_CACHE_HOME/pi/fff). Uses `os.homedir()` semantics — `HOME` is unset in
27
+ * a Windows Pi process, which used to put the index inside the project.
28
+ * The argument is ignored and kept for API compatibility.
29
+ */
30
+ export function getPiPrettyFffDir(_agentDir?: string): string {
27
31
  const override = process.env.PRETTY_FFF_DIR?.trim();
28
32
  if (override) return override;
29
- const home = process.env.HOME ?? "";
30
- const cacheHome = process.env.XDG_CACHE_HOME?.trim() || join(home, ".cache");
31
- return join(cacheHome, "pi", "fff");
33
+ return join(cacheDir(), "fff");
32
34
  }
33
35
 
34
36
  export async function fffEnsureFinder(cwd: string): Promise<FffBackedFinder | null> {
@@ -26,7 +26,7 @@ import {
26
26
  modalWidth,
27
27
  selectListTheme,
28
28
  terminalModalHeight,
29
- } from "./modal-frame.js";
29
+ } from "./modal-frame.ts";
30
30
 
31
31
  // ── Types ─────────────────────────────────────────────────────────────────────
32
32
 
package/src/highlight.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { normalizeShikiContrast } from "./ansi.js";
2
- import { CACHE_LIMIT, MAX_HL_CHARS, MAX_HL_LINE_CHARS } from "./config.js";
3
- import type { BundledLanguage, FgTheme } from "./types.js";
1
+ import { normalizeShikiContrast } from "./ansi.ts";
2
+ import { CACHE_LIMIT, MAX_HL_CHARS, MAX_HL_LINE_CHARS } from "./config.ts";
3
+ import type { BundledLanguage, FgTheme } from "./types.ts";
4
4
 
5
5
  // Engine: cli-highlight (highlight.js-backed, synchronous ANSI output).
6
6
  //