@xynogen/pix-pretty 1.5.1 → 1.6.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/README.md +23 -10
- package/package.json +17 -1
- package/src/diff-render.ts +7 -7
- package/src/index.ts +20 -216
- package/src/resize.ts +18 -0
- package/src/types-diff.d.ts +3 -4
- package/src/image.ts +0 -163
- package/src/tools/bash.test.ts +0 -81
- package/src/tools/bash.ts +0 -173
- package/src/tools/edit.ts +0 -291
- package/src/tools/find.ts +0 -143
- package/src/tools/grep.ts +0 -179
- package/src/tools/ls.ts +0 -106
- package/src/tools/read.ts +0 -180
- package/src/tools/write.ts +0 -232
- package/src/types-fff.d.ts +0 -80
package/README.md
CHANGED
|
@@ -5,6 +5,7 @@ Complete rendering and formatting solution for Pi Coding Agent with syntax highl
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
7
|
### Tool Output Rendering
|
|
8
|
+
|
|
8
9
|
- **Syntax highlighting** - Uses `cli-highlight` (highlight.js-backed) for code blocks
|
|
9
10
|
- **File icons** - Visual file type indicators in ls/find output
|
|
10
11
|
- **Tree views** - Hierarchical directory display
|
|
@@ -14,21 +15,23 @@ Complete rendering and formatting solution for Pi Coding Agent with syntax highl
|
|
|
14
15
|
- **Bash exit summary** - Command status and timing info
|
|
15
16
|
|
|
16
17
|
### Paste Chip Formatting
|
|
18
|
+
|
|
17
19
|
- **Image path collapsing** - Converts `/tmp/pi-clipboard-abc.png` → `[paste image #1]`
|
|
18
20
|
- **Text paste markers** - Long pasted text → `[paste text +42 lines]`
|
|
19
21
|
- **Atomic deletion** - Delete entire paste markers as single units
|
|
20
22
|
- **Type-aware labels** - Visual distinction between image and text pastes
|
|
21
23
|
|
|
22
24
|
### Reasoning Tag Rendering
|
|
23
|
-
|
|
24
|
-
- **
|
|
25
|
-
- **
|
|
26
|
-
- **
|
|
25
|
+
|
|
26
|
+
- **Live streaming** - Splits `<think>`/`<thinking>` regions into native Pi `thinking` content blocks token-by-token during streaming
|
|
27
|
+
- **Finalized cleanup** - On `message_end`, re-splits every affected text block for persistence (the finalized message bypasses the live rebuild)
|
|
28
|
+
- **Partial-tag safety** - Strips trailing half-streamed tags (e.g. `<thin`) so they never flash as literal text
|
|
29
|
+
- **Visual distinction** - Uses Pi's native `thinking` block rendering (dim + italic via `thinkingText` theme token) — no ANSI injection, no markdown blockquote shim
|
|
27
30
|
|
|
28
31
|
## Installation
|
|
29
32
|
|
|
30
33
|
```bash
|
|
31
|
-
pi install
|
|
34
|
+
pi install npm:@xynogen/pix-pretty
|
|
32
35
|
```
|
|
33
36
|
|
|
34
37
|
## Configuration
|
|
@@ -36,8 +39,9 @@ pi install git:github.com/xynogen/pix-pretty
|
|
|
36
39
|
### Environment Variables
|
|
37
40
|
|
|
38
41
|
**Tool rendering:**
|
|
42
|
+
|
|
39
43
|
- `PRETTY_THEME` - Color theme for syntax highlighting
|
|
40
|
-
- `PRETTY_MAX_HL_CHARS` - Max characters to highlight (default:
|
|
44
|
+
- `PRETTY_MAX_HL_CHARS` - Max characters to highlight (default: 80000)
|
|
41
45
|
- `PRETTY_MAX_PREVIEW_LINES` - Max lines in preview output
|
|
42
46
|
- `PRETTY_CACHE_LIMIT` - FFF cache size limit
|
|
43
47
|
- `PRETTY_ICONS` - Enable/disable file icons
|
|
@@ -49,8 +53,9 @@ pi install git:github.com/xynogen/pix-pretty
|
|
|
49
53
|
|
|
50
54
|
This package combines two rendering systems:
|
|
51
55
|
|
|
52
|
-
1. **
|
|
53
|
-
2. **Paste chip formatting** (`src/paste-chips.ts`) - Custom editor component for paste markers
|
|
56
|
+
1. **Theme + FFF commands** (`src/index.ts`) - Initialises syntax-highlight theme from Pi settings, clears highlight cache, and registers FFF slash commands. Tool renderers live in the standalone `pix-{read,bash,ls,find,grep,edit,write}` packages — each self-registers via its own Pi extension entry point.
|
|
57
|
+
2. **Paste chip formatting** (`src/paste-chips.ts`) - Custom editor component for paste markers.
|
|
58
|
+
3. **Reasoning tag rendering** (`src/thinking.ts`) - Converts leaked `<think>`/`<thinking>` tags into native Pi `thinking` content blocks (dim + italic via `thinkingText` theme token).
|
|
54
59
|
|
|
55
60
|
Both work independently but complement each other for a cohesive visual experience.
|
|
56
61
|
|
|
@@ -64,10 +69,18 @@ Key divergences from upstream:
|
|
|
64
69
|
2. **FFF state dir** - `~/.pi/agent/pi-pretty/fff` → `~/.cache/pi/fff` (XDG cache)
|
|
65
70
|
3. **Split diff view for edit/write tools** - Full side-by-side diff with gutter, line numbers, syntax highlighting
|
|
66
71
|
4. **Paste chip formatting** - Custom editor component for Pi's paste marker system (not in upstream)
|
|
67
|
-
5. **Reasoning tag rendering** -
|
|
72
|
+
5. **Reasoning tag rendering** - Converts leaked `<think>`/`<thinking>` tags into native Pi `thinking` content blocks (not in upstream)
|
|
68
73
|
|
|
69
74
|
Paste chip formatting and reasoning tag rendering are original additions with no upstream equivalent.
|
|
70
75
|
|
|
76
|
+
## Full distro
|
|
77
|
+
|
|
78
|
+
To install the complete pix suite (all packages + Pi itself):
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
curl -fsSL https://raw.githubusercontent.com/xynogen/pix-mono/main/scripts/install.sh | sh
|
|
82
|
+
```
|
|
83
|
+
|
|
71
84
|
## License
|
|
72
85
|
|
|
73
|
-
MIT
|
|
86
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,9 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xynogen/pix-pretty",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "Enhanced tool output rendering with syntax highlighting, file icons, tree views, FFF search, and paste chip formatting",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/index.ts",
|
|
9
|
+
"./ansi": "./src/ansi.ts",
|
|
10
|
+
"./config": "./src/config.ts",
|
|
11
|
+
"./diff": "./src/diff.ts",
|
|
12
|
+
"./diff-render": "./src/diff-render.ts",
|
|
13
|
+
"./highlight": "./src/highlight.ts",
|
|
14
|
+
"./lang": "./src/lang.ts",
|
|
15
|
+
"./icons": "./src/icons.ts",
|
|
16
|
+
"./renderers": "./src/renderers.ts",
|
|
17
|
+
"./fff": "./src/fff.ts",
|
|
18
|
+
"./types": "./src/types.ts",
|
|
19
|
+
"./utils": "./src/utils.ts",
|
|
20
|
+
"./resize": "./src/resize.ts",
|
|
21
|
+
"./context": "./src/tools/context.ts"
|
|
22
|
+
},
|
|
7
23
|
"scripts": {
|
|
8
24
|
"test": "bun test"
|
|
9
25
|
},
|
package/src/diff-render.ts
CHANGED
|
@@ -808,7 +808,7 @@ export async function renderSplit(
|
|
|
808
808
|
|
|
809
809
|
type HalfResult = { gutter: string; contGutter: string; bodyRows: string[] };
|
|
810
810
|
|
|
811
|
-
function
|
|
811
|
+
function halfBuild(
|
|
812
812
|
line: DiffLine | null,
|
|
813
813
|
hl: string,
|
|
814
814
|
ranges: Array<[number, number]> | null,
|
|
@@ -890,14 +890,14 @@ export async function renderSplit(
|
|
|
890
890
|
if (paired && wd && wd.similarity >= WORD_DIFF_MIN_SIM && canHL) {
|
|
891
891
|
const lhl = leftHL[lI++] ?? leftLine.content;
|
|
892
892
|
const rhl = rightHL[rI++] ?? rightLine.content;
|
|
893
|
-
lResult =
|
|
894
|
-
rResult =
|
|
893
|
+
lResult = halfBuild(leftLine, lhl, wd.oldRanges, "left");
|
|
894
|
+
rResult = halfBuild(rightLine, rhl, wd.newRanges, "right");
|
|
895
895
|
} else if (paired && wd && wd.similarity >= WORD_DIFF_MIN_SIM && !canHL) {
|
|
896
896
|
const pwd = plainWordDiff(leftLine.content, rightLine.content);
|
|
897
897
|
lI++;
|
|
898
898
|
rI++;
|
|
899
|
-
lResult =
|
|
900
|
-
rResult =
|
|
899
|
+
lResult = halfBuild(leftLine, pwd.old, null, "left");
|
|
900
|
+
rResult = halfBuild(rightLine, pwd.new, null, "right");
|
|
901
901
|
} else {
|
|
902
902
|
const lhl =
|
|
903
903
|
leftLine && leftLine.type !== "sep"
|
|
@@ -907,8 +907,8 @@ export async function renderSplit(
|
|
|
907
907
|
rightLine && rightLine.type !== "sep"
|
|
908
908
|
? (rightHL[rI++] ?? rightLine?.content ?? "")
|
|
909
909
|
: "";
|
|
910
|
-
lResult =
|
|
911
|
-
rResult =
|
|
910
|
+
lResult = halfBuild(leftLine, lhl, null, "left");
|
|
911
|
+
rResult = halfBuild(rightLine, rhl, null, "right");
|
|
912
912
|
}
|
|
913
913
|
|
|
914
914
|
const maxRowsN = Math.max(lResult.bodyRows.length, rResult.bodyRows.length);
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* pi-pretty — Pretty terminal output for pi built-in tools.
|
|
3
3
|
*
|
|
4
|
-
* Entry point:
|
|
4
|
+
* Entry point: initialises theme + highlight cache, registers FFF slash
|
|
5
|
+
* commands (/fff-rescan etc.). Individual tool renderers live in the
|
|
6
|
+
* standalone pix-{read,bash,ls,find,grep,edit,write} packages — each
|
|
7
|
+
* self-registers via its own pi extension entry point.
|
|
5
8
|
*
|
|
6
9
|
* Modules:
|
|
7
10
|
* types.ts shared interfaces/types
|
|
@@ -9,141 +12,32 @@
|
|
|
9
12
|
* ansi.ts ANSI codes, low-contrast fix
|
|
10
13
|
* utils.ts helpers + renderToolError
|
|
11
14
|
* lang.ts language detection
|
|
12
|
-
* image.ts terminal image protocols
|
|
13
15
|
* icons.ts Nerd Font file-type icons
|
|
14
16
|
* highlight.ts cli-highlight engine + ANSI cache
|
|
15
17
|
* renderers.ts renderFileContent/Bash/Tree/Find/Grep
|
|
16
|
-
* fff.ts Fast File Finder + cursor store +
|
|
18
|
+
* fff.ts Fast File Finder + cursor store + module singleton
|
|
17
19
|
* diff.ts unified diff parser
|
|
18
20
|
* diff-render.ts split/word-level diff renderer
|
|
19
|
-
*
|
|
21
|
+
* resize.ts terminal resize invalidation registry
|
|
22
|
+
* tools/ per-tool registrar helpers (context type)
|
|
20
23
|
* commands/ slash command registrars (fff)
|
|
21
24
|
*/
|
|
22
25
|
|
|
23
|
-
import { mkdirSync } from "node:fs";
|
|
24
|
-
import { join } from "node:path";
|
|
25
|
-
import type {
|
|
26
|
-
BashToolInput,
|
|
27
|
-
EditToolInput,
|
|
28
|
-
ExtensionContext,
|
|
29
|
-
FindToolInput,
|
|
30
|
-
GrepToolInput,
|
|
31
|
-
LsToolInput,
|
|
32
|
-
ReadToolInput,
|
|
33
|
-
WriteToolInput,
|
|
34
|
-
} from "@earendil-works/pi-coding-agent";
|
|
35
26
|
import { registerFffCommands } from "./commands/fff.js";
|
|
36
27
|
import { getDefaultAgentDir, setPrettyTheme } from "./config.js";
|
|
37
|
-
import {
|
|
38
|
-
CursorStore,
|
|
39
|
-
fffDestroy,
|
|
40
|
-
fffEnsureFinder,
|
|
41
|
-
fffState,
|
|
42
|
-
getPiPrettyFffDir,
|
|
43
|
-
} from "./fff.js";
|
|
28
|
+
import { fffState } from "./fff.js";
|
|
44
29
|
import { clearHighlightCache } from "./highlight.js";
|
|
45
|
-
import {
|
|
46
|
-
import type { ToolContext } from "./tools/context.js";
|
|
47
|
-
import { registerEditTool } from "./tools/edit.js";
|
|
48
|
-
import { registerFindTool } from "./tools/find.js";
|
|
49
|
-
import { registerGrepTool } from "./tools/grep.js";
|
|
50
|
-
import { registerLsTool } from "./tools/ls.js";
|
|
51
|
-
import { registerReadTool } from "./tools/read.js";
|
|
52
|
-
import { registerWriteTool } from "./tools/write.js";
|
|
53
|
-
import type {
|
|
54
|
-
PiPrettyApi,
|
|
55
|
-
PiPrettyDeps,
|
|
56
|
-
PiPrettySdk,
|
|
57
|
-
TextComponentCtor,
|
|
58
|
-
ToolFactory,
|
|
59
|
-
} from "./types.js";
|
|
60
|
-
import { getErrorMessage, shortPath } from "./utils.js";
|
|
30
|
+
import type { PiPrettyApi } from "./types.js";
|
|
61
31
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
function attachResizeListener(): void {
|
|
70
|
-
if (_resizeListenerAttached) return;
|
|
71
|
-
_resizeListenerAttached = true;
|
|
72
|
-
process.stdout.on("resize", () => {
|
|
73
|
-
for (const inv of _resizeInvalidators.values()) inv();
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function trackInvalidator(toolCallId: string, inv: () => void): void {
|
|
78
|
-
_resizeInvalidators.set(toolCallId, inv);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// ── Extension entry point ──────────────────────────────────────────────
|
|
82
|
-
|
|
83
|
-
export default function piPrettyExtension(
|
|
84
|
-
pi: PiPrettyApi,
|
|
85
|
-
deps?: PiPrettyDeps,
|
|
86
|
-
): void {
|
|
87
|
-
attachResizeListener();
|
|
88
|
-
|
|
89
|
-
let createReadTool: ToolFactory<ReadToolInput> | undefined;
|
|
90
|
-
let createBashTool: ToolFactory<BashToolInput> | undefined;
|
|
91
|
-
let createLsTool: ToolFactory<LsToolInput> | undefined;
|
|
92
|
-
let createFindTool: ToolFactory<FindToolInput> | undefined;
|
|
93
|
-
let createGrepTool: ToolFactory<GrepToolInput> | undefined;
|
|
94
|
-
let createEditTool: ToolFactory<EditToolInput> | undefined;
|
|
95
|
-
let createWriteTool: ToolFactory<WriteToolInput> | undefined;
|
|
96
|
-
let TextComponent: TextComponentCtor;
|
|
97
|
-
let sdk: PiPrettySdk;
|
|
98
|
-
|
|
99
|
-
const cursorStore = new CursorStore();
|
|
100
|
-
|
|
101
|
-
if (deps) {
|
|
102
|
-
sdk = deps.sdk;
|
|
103
|
-
createReadTool = sdk.createReadToolDefinition ?? sdk.createReadTool;
|
|
104
|
-
createBashTool = sdk.createBashToolDefinition ?? sdk.createBashTool;
|
|
105
|
-
createLsTool = sdk.createLsToolDefinition ?? sdk.createLsTool;
|
|
106
|
-
createFindTool = sdk.createFindToolDefinition ?? sdk.createFindTool;
|
|
107
|
-
createGrepTool = sdk.createGrepToolDefinition ?? sdk.createGrepTool;
|
|
108
|
-
createEditTool = sdk.createEditToolDefinition ?? sdk.createEditTool;
|
|
109
|
-
createWriteTool = sdk.createWriteToolDefinition ?? sdk.createWriteTool;
|
|
110
|
-
TextComponent = deps.TextComponent;
|
|
111
|
-
fffState.module = deps.fffModule ?? null;
|
|
112
|
-
fffState.finder = null;
|
|
113
|
-
fffState.partialIndex = false;
|
|
114
|
-
fffState.dbDir = null;
|
|
115
|
-
} else {
|
|
116
|
-
try {
|
|
117
|
-
sdk = require("@earendil-works/pi-coding-agent");
|
|
118
|
-
createReadTool = sdk.createReadToolDefinition ?? sdk.createReadTool;
|
|
119
|
-
createBashTool = sdk.createBashToolDefinition ?? sdk.createBashTool;
|
|
120
|
-
createLsTool = sdk.createLsToolDefinition ?? sdk.createLsTool;
|
|
121
|
-
createFindTool = sdk.createFindToolDefinition ?? sdk.createFindTool;
|
|
122
|
-
createGrepTool = sdk.createGrepToolDefinition ?? sdk.createGrepTool;
|
|
123
|
-
createEditTool = sdk.createEditToolDefinition ?? sdk.createEditTool;
|
|
124
|
-
createWriteTool = sdk.createWriteToolDefinition ?? sdk.createWriteTool;
|
|
125
|
-
TextComponent = require("@earendil-works/pi-tui").Text;
|
|
126
|
-
} catch {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
32
|
+
export default function piPrettyExtension(pi: PiPrettyApi): void {
|
|
33
|
+
let sdk: { getAgentDir?: () => string };
|
|
34
|
+
try {
|
|
35
|
+
sdk = require("@earendil-works/pi-coding-agent");
|
|
36
|
+
} catch {
|
|
37
|
+
return;
|
|
129
38
|
}
|
|
130
|
-
if (!createReadTool || !TextComponent!) return;
|
|
131
|
-
|
|
132
|
-
const cwd = process.cwd();
|
|
133
|
-
const home = process.env.HOME ?? "";
|
|
134
|
-
const sp = (p: string) => shortPath(cwd, home, p);
|
|
135
|
-
// Respect PRETTY_DISABLE_TOOLS env var
|
|
136
|
-
const disabledTools = new Set(
|
|
137
|
-
(process.env.PRETTY_DISABLE_TOOLS ?? "")
|
|
138
|
-
.split(",")
|
|
139
|
-
.map((s) => s.trim().toLowerCase())
|
|
140
|
-
.filter(Boolean),
|
|
141
|
-
);
|
|
142
|
-
const isToolEnabled = (name: string) =>
|
|
143
|
-
!disabledTools.has(name.toLowerCase());
|
|
144
|
-
|
|
145
|
-
// ── Theme + FFF init ────────────────────────────────────────────────
|
|
146
39
|
|
|
40
|
+
// ── Theme init ──────────────────────────────────────────────────────
|
|
147
41
|
const getAgentDir = sdk.getAgentDir;
|
|
148
42
|
setPrettyTheme(
|
|
149
43
|
(() => {
|
|
@@ -156,98 +50,8 @@ export default function piPrettyExtension(
|
|
|
156
50
|
);
|
|
157
51
|
clearHighlightCache();
|
|
158
52
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
fffState.dbDir = getPiPrettyFffDir(getAgentDir());
|
|
164
|
-
try {
|
|
165
|
-
mkdirSync(fffState.dbDir, { recursive: true });
|
|
166
|
-
} catch {}
|
|
167
|
-
}
|
|
168
|
-
} catch {
|
|
169
|
-
/* FFF not installed — SDK tools will be used */
|
|
170
|
-
}
|
|
171
|
-
} else if (fffState.module && getAgentDir) {
|
|
172
|
-
fffState.dbDir = getPiPrettyFffDir(getAgentDir());
|
|
173
|
-
try {
|
|
174
|
-
mkdirSync(fffState.dbDir, { recursive: true });
|
|
175
|
-
} catch {}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
pi.on("session_start", async (_event, ctx: ExtensionContext) => {
|
|
179
|
-
if (!fffState.module) {
|
|
180
|
-
try {
|
|
181
|
-
const imported = await import("@ff-labs/fff-node");
|
|
182
|
-
fffState.module = { FileFinder: imported.FileFinder };
|
|
183
|
-
} catch {}
|
|
184
|
-
}
|
|
185
|
-
if (!fffState.module) return;
|
|
186
|
-
|
|
187
|
-
if (!fffState.dbDir) {
|
|
188
|
-
const agentDir = getAgentDir?.() ?? join(home, ".pi/agent");
|
|
189
|
-
fffState.dbDir = getPiPrettyFffDir(agentDir);
|
|
190
|
-
try {
|
|
191
|
-
mkdirSync(fffState.dbDir, { recursive: true });
|
|
192
|
-
} catch {}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
try {
|
|
196
|
-
await fffEnsureFinder(ctx.cwd);
|
|
197
|
-
if (fffState.partialIndex) {
|
|
198
|
-
ctx.ui?.notify?.(
|
|
199
|
-
"FFF: scan timed out — using partial index. Run /fff-rescan when ready.",
|
|
200
|
-
"warning",
|
|
201
|
-
);
|
|
202
|
-
} else {
|
|
203
|
-
ctx.ui?.notify?.("FFF indexed", "info");
|
|
204
|
-
}
|
|
205
|
-
} catch (error: unknown) {
|
|
206
|
-
ctx.ui?.notify?.(`FFF init failed: ${getErrorMessage(error)}`, "error");
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
pi.on("session_shutdown", async () => {
|
|
211
|
-
fffDestroy();
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
// ── Build shared tool context ───────────────────────────────────────
|
|
215
|
-
|
|
216
|
-
const toolCtx: ToolContext = {
|
|
217
|
-
cwd,
|
|
218
|
-
sp,
|
|
219
|
-
TextComponent: TextComponent!,
|
|
220
|
-
fffState,
|
|
221
|
-
cursorStore,
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
// ── Register tools ──────────────────────────────────────────────────
|
|
225
|
-
|
|
226
|
-
if (isToolEnabled("read") && createReadTool) {
|
|
227
|
-
registerReadTool(pi, createReadTool, toolCtx);
|
|
228
|
-
}
|
|
229
|
-
if (isToolEnabled("bash") && createBashTool) {
|
|
230
|
-
registerBashTool(pi, createBashTool, toolCtx);
|
|
231
|
-
}
|
|
232
|
-
if (isToolEnabled("ls") && createLsTool) {
|
|
233
|
-
registerLsTool(pi, createLsTool, toolCtx);
|
|
234
|
-
}
|
|
235
|
-
if (isToolEnabled("find") && createFindTool) {
|
|
236
|
-
registerFindTool(pi, createFindTool, toolCtx);
|
|
237
|
-
}
|
|
238
|
-
if (isToolEnabled("grep") && createGrepTool) {
|
|
239
|
-
registerGrepTool(pi, createGrepTool, toolCtx);
|
|
240
|
-
}
|
|
241
|
-
if (isToolEnabled("edit") && createEditTool) {
|
|
242
|
-
registerEditTool(pi, createEditTool, toolCtx, trackInvalidator);
|
|
243
|
-
}
|
|
244
|
-
if (isToolEnabled("write") && createWriteTool) {
|
|
245
|
-
registerWriteTool(pi, createWriteTool, toolCtx, trackInvalidator);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
// ── Register FFF commands ───────────────────────────────────────────
|
|
249
|
-
|
|
250
|
-
if (fffState.module) {
|
|
251
|
-
registerFffCommands(pi, fffState);
|
|
252
|
-
}
|
|
53
|
+
// ── FFF slash commands ──────────────────────────────────────────────
|
|
54
|
+
// fffState is a module-level singleton shared with pix-grep/pix-find.
|
|
55
|
+
// Commands become available once pix-grep initialises the finder.
|
|
56
|
+
registerFffCommands(pi, fffState);
|
|
253
57
|
}
|
package/src/resize.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// ── Resize invalidation registry ───────────────────────────────────────
|
|
2
|
+
// Diff renderers (edit/write) register their ctx.invalidate keyed by
|
|
3
|
+
// toolCallId so a terminal resize triggers re-render at the new width.
|
|
4
|
+
|
|
5
|
+
const _invalidators = new Map<string, () => void>();
|
|
6
|
+
let _attached = false;
|
|
7
|
+
|
|
8
|
+
export function attachResizeListener(): void {
|
|
9
|
+
if (_attached) return;
|
|
10
|
+
_attached = true;
|
|
11
|
+
process.stdout.on("resize", () => {
|
|
12
|
+
for (const inv of _invalidators.values()) inv();
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function trackInvalidator(toolCallId: string, inv: () => void): void {
|
|
17
|
+
_invalidators.set(toolCallId, inv);
|
|
18
|
+
}
|
package/src/types-diff.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
// Minimal ambient shim for the `diff` npm package (v7) — only the surface
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
// editor/LSP quiet without vendoring node_modules in-repo.
|
|
1
|
+
// Minimal ambient shim for the `diff` npm package (v7) — only the surface used
|
|
2
|
+
// by diff.ts and diff-render.ts. diff@7 ships no bundled types and @types/diff
|
|
3
|
+
// is not installed into pi's npm root; this keeps tsc quiet without vendoring.
|
|
5
4
|
|
|
6
5
|
declare module "diff" {
|
|
7
6
|
export interface StructuredPatchHunk {
|
package/src/image.ts
DELETED
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import * as childProcess from "node:child_process";
|
|
2
|
-
|
|
3
|
-
import type { ImageProtocol } from "./types.js";
|
|
4
|
-
|
|
5
|
-
let _tmuxClientTermCache: string | null | undefined;
|
|
6
|
-
let _tmuxAllowPassthroughCache: boolean | null | undefined;
|
|
7
|
-
let _tmuxClientTermOverrideForTests: string | null | undefined;
|
|
8
|
-
let _tmuxAllowPassthroughOverrideForTests: boolean | null | undefined;
|
|
9
|
-
|
|
10
|
-
function isTmuxSession(): boolean {
|
|
11
|
-
return !!process.env.TMUX || /^(tmux|screen)/.test(process.env.TERM ?? "");
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function normalizeTerminalName(term: string): string {
|
|
15
|
-
const t = term.toLowerCase();
|
|
16
|
-
if (t.includes("kitty")) return "kitty";
|
|
17
|
-
if (t.includes("ghostty")) return "ghostty";
|
|
18
|
-
if (t.includes("wezterm")) return "WezTerm";
|
|
19
|
-
if (t.includes("iterm")) return "iTerm.app";
|
|
20
|
-
if (t.includes("mintty")) return "mintty";
|
|
21
|
-
return term;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function readTmuxClientTerm(): string | null {
|
|
25
|
-
if (_tmuxClientTermOverrideForTests !== undefined) {
|
|
26
|
-
return _tmuxClientTermOverrideForTests
|
|
27
|
-
? normalizeTerminalName(_tmuxClientTermOverrideForTests)
|
|
28
|
-
: null;
|
|
29
|
-
}
|
|
30
|
-
if (!isTmuxSession()) return null;
|
|
31
|
-
if (_tmuxClientTermCache !== undefined) return _tmuxClientTermCache;
|
|
32
|
-
try {
|
|
33
|
-
const term = childProcess
|
|
34
|
-
.execFileSync("tmux", ["display-message", "-p", "#{client_termname}"], {
|
|
35
|
-
encoding: "utf8",
|
|
36
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
37
|
-
timeout: 200,
|
|
38
|
-
})
|
|
39
|
-
.trim();
|
|
40
|
-
_tmuxClientTermCache = term ? normalizeTerminalName(term) : null;
|
|
41
|
-
} catch {
|
|
42
|
-
_tmuxClientTermCache = null;
|
|
43
|
-
}
|
|
44
|
-
return _tmuxClientTermCache;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Detect the outer terminal when running inside tmux.
|
|
49
|
-
* tmux sets TERM_PROGRAM=tmux, but the real terminal is often in
|
|
50
|
-
* the environment of the tmux server or can be inferred.
|
|
51
|
-
|
|
52
|
-
*/
|
|
53
|
-
function getOuterTerminal(): string {
|
|
54
|
-
// Environment hints that often survive inside tmux
|
|
55
|
-
if (process.env.LC_TERMINAL === "iTerm2") return "iTerm.app";
|
|
56
|
-
if (process.env.GHOSTTY_RESOURCES_DIR) return "ghostty";
|
|
57
|
-
if (process.env.KITTY_WINDOW_ID || process.env.KITTY_PID) return "kitty";
|
|
58
|
-
if (
|
|
59
|
-
process.env.WEZTERM_EXECUTABLE ||
|
|
60
|
-
process.env.WEZTERM_CONFIG_DIR ||
|
|
61
|
-
process.env.WEZTERM_CONFIG_FILE
|
|
62
|
-
) {
|
|
63
|
-
return "WezTerm";
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const termProgram = process.env.TERM_PROGRAM ?? "";
|
|
67
|
-
if (termProgram && termProgram !== "tmux" && termProgram !== "screen") {
|
|
68
|
-
return normalizeTerminalName(termProgram);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const tmuxClientTerm = readTmuxClientTerm();
|
|
72
|
-
if (tmuxClientTerm) return tmuxClientTerm;
|
|
73
|
-
|
|
74
|
-
const term = process.env.TERM ?? "";
|
|
75
|
-
if (term) return normalizeTerminalName(term);
|
|
76
|
-
if (
|
|
77
|
-
process.env.COLORTERM === "truecolor" ||
|
|
78
|
-
process.env.COLORTERM === "24bit"
|
|
79
|
-
)
|
|
80
|
-
return "unknown-modern";
|
|
81
|
-
return termProgram;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function detectImageProtocol(): ImageProtocol {
|
|
85
|
-
const forced = (process.env.PRETTY_IMAGE_PROTOCOL ?? "").toLowerCase();
|
|
86
|
-
if (forced === "kitty" || forced === "iterm2" || forced === "none") {
|
|
87
|
-
return forced;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const term = getOuterTerminal();
|
|
91
|
-
// Ghostty and Kitty use the Kitty graphics protocol
|
|
92
|
-
if (term === "ghostty" || term === "kitty") return "kitty";
|
|
93
|
-
// iTerm2, WezTerm, Mintty support the iTerm2 protocol
|
|
94
|
-
if (["iTerm.app", "WezTerm", "mintty"].includes(term)) return "iterm2";
|
|
95
|
-
if (process.env.LC_TERMINAL === "iTerm2") return "iterm2";
|
|
96
|
-
return "none";
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function tmuxAllowsPassthrough(): boolean | null {
|
|
100
|
-
if (_tmuxAllowPassthroughOverrideForTests !== undefined)
|
|
101
|
-
return _tmuxAllowPassthroughOverrideForTests;
|
|
102
|
-
if (!isTmuxSession()) return null;
|
|
103
|
-
if (_tmuxAllowPassthroughCache !== undefined)
|
|
104
|
-
return _tmuxAllowPassthroughCache;
|
|
105
|
-
try {
|
|
106
|
-
const value = childProcess
|
|
107
|
-
.execFileSync("tmux", ["show-options", "-gv", "allow-passthrough"], {
|
|
108
|
-
encoding: "utf8",
|
|
109
|
-
stdio: ["ignore", "pipe", "ignore"],
|
|
110
|
-
timeout: 200,
|
|
111
|
-
})
|
|
112
|
-
.trim()
|
|
113
|
-
.toLowerCase();
|
|
114
|
-
_tmuxAllowPassthroughCache = value === "on" || value === "all";
|
|
115
|
-
} catch {
|
|
116
|
-
_tmuxAllowPassthroughCache = null;
|
|
117
|
-
}
|
|
118
|
-
return _tmuxAllowPassthroughCache;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function getTmuxPassthroughWarning(protocol: ImageProtocol): string | null {
|
|
122
|
-
if (!isTmuxSession() || protocol === "none") return null;
|
|
123
|
-
if (tmuxAllowsPassthrough() === false) {
|
|
124
|
-
return "tmux allow-passthrough is off. Run: tmux set -g allow-passthrough on";
|
|
125
|
-
}
|
|
126
|
-
return null;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Wrap escape sequence for tmux passthrough.
|
|
131
|
-
* tmux requires: ESC Ptmux; <escaped-sequence> ESC \
|
|
132
|
-
* Inner ESC chars must be doubled.
|
|
133
|
-
|
|
134
|
-
*/
|
|
135
|
-
function tmuxWrap(seq: string): string {
|
|
136
|
-
if (!isTmuxSession()) return seq;
|
|
137
|
-
// Double all ESC chars inside the sequence
|
|
138
|
-
const escaped = seq.split("\x1b").join("\x1b\x1b");
|
|
139
|
-
return `\x1bPtmux;${escaped}\x1b\\`;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export const __imageInternals = {
|
|
143
|
-
isTmuxSession,
|
|
144
|
-
getOuterTerminal,
|
|
145
|
-
detectImageProtocol,
|
|
146
|
-
tmuxWrap,
|
|
147
|
-
tmuxAllowsPassthrough,
|
|
148
|
-
getTmuxPassthroughWarning,
|
|
149
|
-
setTmuxClientTermOverrideForTests: (value: string | null | undefined) => {
|
|
150
|
-
_tmuxClientTermOverrideForTests = value;
|
|
151
|
-
},
|
|
152
|
-
setTmuxAllowPassthroughOverrideForTests: (
|
|
153
|
-
value: boolean | null | undefined,
|
|
154
|
-
) => {
|
|
155
|
-
_tmuxAllowPassthroughOverrideForTests = value;
|
|
156
|
-
},
|
|
157
|
-
resetCachesForTests: () => {
|
|
158
|
-
_tmuxClientTermCache = undefined;
|
|
159
|
-
_tmuxAllowPassthroughCache = undefined;
|
|
160
|
-
_tmuxClientTermOverrideForTests = undefined;
|
|
161
|
-
_tmuxAllowPassthroughOverrideForTests = undefined;
|
|
162
|
-
},
|
|
163
|
-
};
|