@xynogen/pix-pretty 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 xynogen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,68 @@
1
+ # pix-pretty
2
+
3
+ Complete rendering and formatting solution for Pi Coding Agent with syntax highlighting, file icons, tree views, FFF search, paste chip formatting, and reasoning tag cleanup.
4
+
5
+ ## Features
6
+
7
+ ### Tool Output Rendering
8
+ - **Syntax highlighting** - Uses `cli-highlight` (highlight.js-backed) for code blocks
9
+ - **File icons** - Visual file type indicators in ls/find output
10
+ - **Tree views** - Hierarchical directory display
11
+ - **FFF search** - Fast full-text search integration with `@ff-labs/fff-node`
12
+ - **Diff rendering** - Enhanced git diff and edit/write tool output
13
+ - **Image metadata** - Display image dimensions and format info
14
+ - **Bash exit summary** - Command status and timing info
15
+
16
+ ### Paste Chip Formatting
17
+ - **Image path collapsing** - Converts `/tmp/pi-clipboard-abc.png` → `[paste image #1]`
18
+ - **Text paste markers** - Long pasted text → `[paste text +42 lines]`
19
+ - **Atomic deletion** - Delete entire paste markers as single units
20
+ - **Type-aware labels** - Visual distinction between image and text pastes
21
+
22
+ ### Reasoning Tag Rendering
23
+ - **Collapsible display** - Renders leaked `<think>`/`<thinking>` tags as collapsible HTML details blocks
24
+ - **Visual distinction** - Uses ⚙ icon to clearly mark reasoning content
25
+ - **Non-intrusive** - Only processes finalized messages, no live mutation
26
+ - **Context-efficient** - Collapsible format minimizes visual clutter (toggle with ctrl+o in Pi agent)
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ pi install git:github.com/xynogen/pix-pretty
32
+ ```
33
+
34
+ ## Configuration
35
+
36
+ ### Environment Variables
37
+
38
+ **Tool rendering:**
39
+ - `PRETTY_THEME` - Color theme for syntax highlighting
40
+ - `PRETTY_MAX_HL_CHARS` - Max characters to highlight (default: 50000)
41
+ - `PRETTY_MAX_PREVIEW_LINES` - Max lines in preview output
42
+ - `PRETTY_CACHE_LIMIT` - FFF cache size limit
43
+ - `PRETTY_ICONS` - Enable/disable file icons
44
+ - `PRETTY_DISABLE_TOOLS` - Comma-separated list of tools to skip rendering
45
+ - `PRETTY_IMAGE_PROTOCOL` - Protocol for image display (tmux passthrough)
46
+ - `PRETTY_FFF_DIR` - Override FFF state dir (default: `~/.cache/pi/fff`)
47
+
48
+ ## Architecture
49
+
50
+ This package combines two rendering systems:
51
+
52
+ 1. **Tool output rendering** (`src/index.ts`) - Intercepts read/bash/ls/find/grep/multi_grep tools
53
+ 2. **Paste chip formatting** (`src/paste-chips.ts`) - Custom editor component for paste markers
54
+
55
+ Both work independently but complement each other for a cohesive visual experience.
56
+
57
+ ## Origin
58
+
59
+ Tool rendering is a vendored fork of [`@heyhuynhgiabuu/pi-pretty`](https://github.com/buddingnewinsights/pi-pretty) with two key changes:
60
+
61
+ 1. **Highlight engine: shiki → cli-highlight** - Simpler, synchronous, no WASM
62
+ 2. **FFF state dir: `~/.pi/agent/pi-pretty/fff` → `~/.cache/pi/fff`** - Standard XDG cache location
63
+
64
+ Paste chip formatting is custom logic for Pi's paste marker system.
65
+
66
+ ## License
67
+
68
+ MIT - See LICENSE file
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@xynogen/pix-pretty",
3
+ "version": "1.0.0",
4
+ "description": "Enhanced tool output rendering with syntax highlighting, file icons, tree views, FFF search, and paste chip formatting",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "scripts": {
8
+ "test": "bun test"
9
+ },
10
+ "files": [
11
+ "src",
12
+ "README.md",
13
+ "LICENSE"
14
+ ],
15
+ "pi": {
16
+ "extensions": [
17
+ "./src/index.ts",
18
+ "./src/paste-chips.ts",
19
+ "./src/thinking.ts"
20
+ ]
21
+ },
22
+ "keywords": [
23
+ "pi",
24
+ "pi-package",
25
+ "pi-extension",
26
+ "syntax-highlighting",
27
+ "fff",
28
+ "paste-chips",
29
+ "tool-rendering"
30
+ ],
31
+ "author": "xynogen",
32
+ "license": "MIT",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/xynogen/pix-mono.git",
36
+ "directory": "packages/pix-pretty"
37
+ },
38
+ "homepage": "https://github.com/xynogen/pix-mono/tree/main/packages/pix-pretty#readme",
39
+ "bugs": {
40
+ "url": "https://github.com/xynogen/pix-mono/issues"
41
+ },
42
+ "publishConfig": {
43
+ "access": "public"
44
+ },
45
+ "dependencies": {
46
+ "cli-highlight": "^2.1.11",
47
+ "@ff-labs/fff-node": "^0.5.2",
48
+ "diff": "^7.0.0"
49
+ },
50
+ "peerDependencies": {
51
+ "@earendil-works/pi-coding-agent": "*",
52
+ "@earendil-works/pi-tui": "*"
53
+ }
54
+ }
package/src/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # pretty (vendored)
2
+
3
+ Local fork of [`@heyhuynhgiabuu/pi-pretty`](https://github.com/buddingnewinsights/pi-pretty)
4
+ (v0.5.1). Enhances built-in `read` / `bash` / `ls` / `find` / `grep` /
5
+ `multi_grep` tool output with syntax highlighting, file icons, tree views, and
6
+ FFF-backed search.
7
+
8
+ ## Why vendored
9
+
10
+ We need two behavioral changes the upstream package does not expose as config,
11
+ so the source is copied here 1:1 and patched:
12
+
13
+ 1. **Highlight engine: shiki → cli-highlight.**
14
+ Upstream uses `@shikijs/cli` (`codeToANSI`, TextMate grammars + WASM).
15
+ This fork uses [`cli-highlight`](https://www.npmjs.com/package/cli-highlight)
16
+ (highlight.js-backed, synchronous). The `hlBlock` interface, language table,
17
+ line-number layout, and low-contrast normalization are unchanged.
18
+
19
+ 2. **FFF state dir: `~/.pi/agent/pi-pretty/fff` → `~/.cache/pi/fff`.**
20
+ `getPiPrettyFffDir()` now resolves to `$XDG_CACHE_HOME/pi/fff`
21
+ (default `~/.cache/pi/fff`), overridable with `PRETTY_FFF_DIR`.
22
+
23
+ Everything else (bash exit summary, ls tree, find grouping, grep highlighting,
24
+ image metadata, tmux passthrough, `/fff-health`, `/fff-rescan`, multi_grep
25
+ ripgrep fallback) is byte-for-byte upstream.
26
+
27
+ ## Diff vs upstream
28
+
29
+ - `index.ts`
30
+ - imports: `@shikijs/cli` + `shiki` types → `cli-highlight` (lazy `require`)
31
+ with local `BundledLanguage`/`BundledTheme = string` aliases.
32
+ - `FORCE_COLOR=3` default before chalk init (shiki always emitted truecolor;
33
+ chalk decides level once at load). Respects an explicit `FORCE_COLOR` /
34
+ `NO_COLOR`.
35
+ - `HLJS_LANG_ALIAS` maps shiki-style ids (`tsx`, `jsx`, `jsonc`, `mdx`,
36
+ `make`, `svelte`, `vue`) onto highlight.js-supported ids.
37
+ - `hlBlock()` calls `highlight(code, { language, ignoreIllegals: true })`
38
+ instead of `await codeToANSI(...)`. Still async-typed so call sites match.
39
+ - `getPiPrettyFffDir()` → `~/.cache/pi/fff`.
40
+ - `fff-helpers.ts`, `multi-grep-fallback.ts` — unchanged.
41
+
42
+ ## Runtime deps & module resolution
43
+
44
+ `cli-highlight` and `@ff-labs/fff-node` are installed into pi's npm root
45
+ (`~/.pi/agent/npm/node_modules`) by `setup.sh`. Because the extensions dir is a
46
+ symlink into dotfiles and Node dereferences symlinks before resolving bare
47
+ imports, `setup.sh` also creates a git-ignored
48
+ `extensions/node_modules` → `~/.pi/agent/npm/node_modules` bridge next to the
49
+ real source so `require("cli-highlight")` / `import("@ff-labs/fff-node")`
50
+ resolve.
51
+
52
+ The upstream `npm:@heyhuynhgiabuu/pi-pretty` package is uninstalled by
53
+ `setup.sh` — both register the same tool names and pi does not share tool-name
54
+ ownership across extensions.
55
+
56
+ ## Env vars
57
+
58
+ Same as upstream (`PRETTY_THEME`, `PRETTY_MAX_HL_CHARS`,
59
+ `PRETTY_MAX_PREVIEW_LINES`, `PRETTY_CACHE_LIMIT`, `PRETTY_ICONS`,
60
+ `PRETTY_DISABLE_TOOLS`, `PRETTY_IMAGE_PROTOCOL`) plus:
61
+
62
+ - `PRETTY_FFF_DIR` — override the FFF state dir (default `~/.cache/pi/fff`).
63
+
64
+ ## License
65
+
66
+ MIT — upstream by huynhgiabuu. See upstream repo.
package/src/ansi.ts ADDED
@@ -0,0 +1,89 @@
1
+ import type { BgTheme } from "./types.js";
2
+
3
+ export let RST = "\x1b[0m";
4
+
5
+ export const BOLD = "\x1b[1m";
6
+
7
+ export const FG_LNUM = "\x1b[38;2;100;100;100m";
8
+
9
+ export const FG_DIM = "\x1b[38;2;80;80;80m";
10
+
11
+ export const FG_RULE = "\x1b[38;2;50;50;50m";
12
+
13
+ export const FG_GREEN = "\x1b[38;2;100;180;120m";
14
+
15
+ export const FG_RED = "\x1b[38;2;200;100;100m";
16
+
17
+ export const FG_YELLOW = "\x1b[38;2;220;180;80m";
18
+
19
+ export const FG_BLUE = "\x1b[38;2;100;140;220m";
20
+
21
+ const FG_MUTED = "\x1b[38;2;139;148;158m";
22
+
23
+ const BG_DEFAULT = "\x1b[49m";
24
+
25
+ export let BG_BASE = BG_DEFAULT; // tool box success/base bg — updated from theme's toolSuccessBg
26
+
27
+ export let BG_ERROR = BG_DEFAULT; // tool box error bg — updated from theme's toolErrorBg
28
+
29
+ /** Parse an ANSI 24-bit color escape into { r, g, b }. Handles both fg (38;2) and bg (48;2). */
30
+ function parseAnsiRgb(
31
+ ansi: string,
32
+ ): { r: number; g: number; b: number } | null {
33
+ const m = ansi.match(
34
+ new RegExp(`${ESC_RE}\\[(?:38|48);2;(\\d+);(\\d+);(\\d+)m`),
35
+ );
36
+ return m ? { r: +m[1], g: +m[2], b: +m[3] } : null;
37
+ }
38
+
39
+ function getThemeBgAnsi(theme: BgTheme, key: string): string | null {
40
+ try {
41
+ const bgAnsi = theme.getBgAnsi?.(key);
42
+ return bgAnsi && parseAnsiRgb(bgAnsi) ? bgAnsi : null;
43
+ } catch {
44
+ return null;
45
+ }
46
+ }
47
+
48
+ /** Read themed tool backgrounds and update BG_BASE / BG_ERROR + RST.
49
+ * Recompute on each render so runtime theme changes are respected. */
50
+ export function resolveBaseBackground(theme: BgTheme | null | undefined): void {
51
+ if (!theme?.getBgAnsi) return;
52
+
53
+ BG_BASE =
54
+ getThemeBgAnsi(theme, "toolBg") ??
55
+ getThemeBgAnsi(theme, "background") ??
56
+ BG_DEFAULT;
57
+ BG_ERROR = getThemeBgAnsi(theme, "toolErrorBg") ?? BG_BASE;
58
+ RST = `\x1b[0m${BG_BASE}`;
59
+ }
60
+
61
+ const ESC_RE = "\u001b";
62
+
63
+ export const ANSI_CAPTURE_RE = new RegExp(`${ESC_RE}\\[([0-9;]*)m`, "g");
64
+
65
+ // ---------------------------------------------------------------------------
66
+ // Low-contrast fix (same as pi-diff)
67
+ // ---------------------------------------------------------------------------
68
+
69
+ function isLowContrastShikiFg(params: string): boolean {
70
+ if (params === "30" || params === "90") return true;
71
+ if (params === "38;5;0" || params === "38;5;8") return true;
72
+ if (!params.startsWith("38;2;")) return false;
73
+ const parts = params.split(";").map(Number);
74
+ if (parts.length !== 5 || parts.some((n) => !Number.isFinite(n)))
75
+ return false;
76
+ const [, , r, g, b] = parts;
77
+ const luminance = 0.2126 * r + 0.7152 * g + 0.0722 * b;
78
+ return luminance < 72;
79
+ }
80
+
81
+ export function normalizeShikiContrast(ansi: string): string {
82
+ return ansi.replace(ANSI_CAPTURE_RE, (seq, params: string) =>
83
+ isLowContrastShikiFg(params) ? FG_MUTED : seq,
84
+ );
85
+ }
86
+
87
+ // ---------------------------------------------------------------------------
88
+ // Utilities
89
+ // ---------------------------------------------------------------------------
package/src/config.ts ADDED
@@ -0,0 +1,66 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+
4
+ import type { BundledTheme } from "./types.js";
5
+
6
+ const DEFAULT_THEME: BundledTheme = "github-dark";
7
+
8
+ export function getDefaultAgentDir(): string | undefined {
9
+ const home = process.env.HOME ?? "";
10
+ return home ? join(home, ".pi/agent") : undefined;
11
+ }
12
+
13
+ function readThemeFromSettings(agentDir?: string): BundledTheme | undefined {
14
+ const resolvedAgentDir = agentDir ?? getDefaultAgentDir();
15
+ if (!resolvedAgentDir) return undefined;
16
+
17
+ try {
18
+ const settings = JSON.parse(
19
+ readFileSync(join(resolvedAgentDir, "settings.json"), "utf8"),
20
+ ) as {
21
+ theme?: unknown;
22
+ };
23
+ return typeof settings.theme === "string"
24
+ ? (settings.theme as BundledTheme)
25
+ : undefined;
26
+ } catch {
27
+ return undefined;
28
+ }
29
+ }
30
+
31
+ function resolvePrettyTheme(agentDir?: string): BundledTheme {
32
+ return (
33
+ (process.env.PRETTY_THEME as BundledTheme | undefined) ??
34
+ readThemeFromSettings(agentDir) ??
35
+ DEFAULT_THEME
36
+ );
37
+ }
38
+
39
+ export let THEME: BundledTheme = resolvePrettyTheme();
40
+
41
+ export function setPrettyTheme(agentDir?: string): void {
42
+ const resolvedTheme = resolvePrettyTheme(agentDir);
43
+ if (resolvedTheme === THEME) return;
44
+ THEME = resolvedTheme;
45
+ }
46
+
47
+ export function envInt(name: string, fallback: number): number {
48
+ const v = Number.parseInt(process.env[name] ?? "", 10);
49
+ return Number.isFinite(v) && v > 0 ? v : fallback;
50
+ }
51
+
52
+ export const MAX_HL_CHARS = envInt("PRETTY_MAX_HL_CHARS", 80_000);
53
+
54
+ export const MAX_PREVIEW_LINES = envInt("PRETTY_MAX_PREVIEW_LINES", 80);
55
+
56
+ export const CACHE_LIMIT = envInt("PRETTY_CACHE_LIMIT", 128);
57
+
58
+ // --- Diff rendering limits (edit/write tools) ---
59
+ export const MAX_RENDER_LINES = envInt("PRETTY_MAX_RENDER_LINES", 150);
60
+
61
+ // Word-level emphasis only when paired del/add lines are at least this similar.
62
+ export const WORD_DIFF_MIN_SIM = 0.15;
63
+
64
+ // ---------------------------------------------------------------------------
65
+ // ANSI
66
+ // ---------------------------------------------------------------------------