@xynogen/pix-display 0.2.1 → 0.3.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/LICENSE +21 -0
- package/README.md +9 -9
- package/package.json +3 -3
- package/src/index.ts +5 -5
- package/src/inline-chips.ts +0 -205
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
CHANGED
|
@@ -8,7 +8,7 @@ Pi core extension — inline chips, thinking blocks, and polished code snippets.
|
|
|
8
8
|
|
|
9
9
|
Three features, always on when installed:
|
|
10
10
|
|
|
11
|
-
**Inline chips.** Renders `<path>…</path>` spans (written by e.g. `pix-search`) as `@name` chips, and replaces Pi's paste markers (`[paste #1 2232 chars]`) with styled icon chips: `image #1` for image pastes (blue), `text
|
|
11
|
+
**Inline chips.** Renders `<path>…</path>` spans (written by e.g. `pix-search`) as `@name` chips, `<skill>…</skill>` spans (written by the `pix-skills` `$` picker) as `$name` chips with the skills.sh `owner/repo` in dim, and replaces Pi's paste markers (`[paste #1 2232 chars]`) with styled icon chips: `image #1` for image pastes (blue), `text N chars` / `text Nk chars` for text pastes over 100 characters (green). A shorter paste stays inline, even with many lines. Collapses pasted image paths into markers in the buffer while showing human-readable labels on screen. The display rewrite is purely visual — the buffer keeps the real path for the model. Expansion wraps each paste in `<paste>…</paste>` so adjacent pastes don't merge into one wall in the model-facing text. Sent user messages get the same treatment in the transcript (display-only, via Pi's Markdown transformer hook, Pi ≥ 0.85): `<paste>`/`<path>`/`<skill>` spans collapse to inline chips, text pastes keep a head…tail glimpse. The chip code lives in `@xynogen/pix-pretty/chips`. pix-display only calls `registerChips(pi)`.
|
|
12
12
|
|
|
13
13
|
**Thinking blocks.** Converts leaked reasoning tags (`<think>`/`<thinking>`) from some providers into native Pi `thinking` content blocks, which render dim + italic via the `thinkingText` theme token. No ANSI injection, no markdown blockquote shim. Applies during streaming (`message_update`) and finalization (`message_end`).
|
|
14
14
|
|
|
@@ -22,22 +22,22 @@ The features are registered at session start. TUI-only display changes are no-op
|
|
|
22
22
|
pi install npm:@xynogen/pix-display
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
>
|
|
26
|
-
>
|
|
27
|
-
> ```bash
|
|
28
|
-
> pi install npm:@xynogen/pix-core
|
|
29
|
-
> ```
|
|
25
|
+
> Bundled in [`@xynogen/pix-core`](https://www.npmjs.com/package/@xynogen/pix-core). Install it alone only if you do not use pix-core.
|
|
30
26
|
|
|
31
27
|
## Full distro
|
|
32
28
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
To install the complete pix suite (all packages + Pi itself):
|
|
29
|
+
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.
|
|
36
30
|
|
|
37
31
|
```bash
|
|
32
|
+
# Linux / macOS
|
|
38
33
|
curl -fsSL https://raw.githubusercontent.com/xynogen/pix-mono/main/scripts/install.sh | sh
|
|
39
34
|
```
|
|
40
35
|
|
|
36
|
+
```powershell
|
|
37
|
+
# Windows
|
|
38
|
+
irm https://raw.githubusercontent.com/xynogen/pix-mono/main/scripts/install.ps1 | iex
|
|
39
|
+
```
|
|
40
|
+
|
|
41
41
|
## License
|
|
42
42
|
|
|
43
43
|
MIT
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xynogen/pix-display",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Pi core extension
|
|
3
|
+
"version": "0.3.1",
|
|
4
|
+
"description": "Pi core extension \u2014 inline chips, thinking blocks, and framed code rendering",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"scripts": {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@xynogen/pix-pretty": "^1.
|
|
42
|
+
"@xynogen/pix-pretty": "^1.30.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"@earendil-works/pi-coding-agent": "*",
|
package/src/index.ts
CHANGED
|
@@ -5,19 +5,19 @@
|
|
|
5
5
|
* Terminal-only rendering behavior stays inactive outside TUI mode.
|
|
6
6
|
*
|
|
7
7
|
* Modules:
|
|
8
|
-
*
|
|
8
|
+
* @xynogen/pix-pretty/chips Inline chips (tag format, editor, sent messages)
|
|
9
9
|
* thinking.ts Leaked reasoning tag → native thinking content blocks
|
|
10
10
|
* code-blocks.ts Framed, syntax-highlighted code fences in LLM output
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
14
|
+
import { registerChips } from "@xynogen/pix-pretty/chips";
|
|
14
15
|
|
|
15
|
-
import codeBlocksExtension from "./code-blocks.
|
|
16
|
-
import
|
|
17
|
-
import thinkingExtension from "./thinking.js";
|
|
16
|
+
import codeBlocksExtension from "./code-blocks.ts";
|
|
17
|
+
import thinkingExtension from "./thinking.ts";
|
|
18
18
|
|
|
19
19
|
export default function pixDisplayExtension(pi: ExtensionAPI): void {
|
|
20
|
-
|
|
20
|
+
registerChips(pi);
|
|
21
21
|
thinkingExtension(pi);
|
|
22
22
|
codeBlocksExtension(pi);
|
|
23
23
|
}
|
package/src/inline-chips.ts
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* inline-chips — render inline tokens in the prompt editor as compact chips.
|
|
3
|
-
*
|
|
4
|
-
* long pasted text → buffer: [paste #1 +42 lines] display: text 42 lines
|
|
5
|
-
* /tmp/shot.png → buffer: [paste #2 13 chars] display: image #2
|
|
6
|
-
* <path>src/a.ts</path> → buffer: [paste #3 8 chars] display: @a.ts
|
|
7
|
-
*
|
|
8
|
-
* `<path>…</path>` from pix-search and Pi's `<paste>…</paste>` payloads are
|
|
9
|
-
* promoted to atomic paste markers (one backspace deletes the whole chip) and
|
|
10
|
-
* expanded back verbatim for the model.
|
|
11
|
-
*/
|
|
12
|
-
import { basename } from "node:path";
|
|
13
|
-
import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
14
|
-
import { CustomEditor } from "@earendil-works/pi-coding-agent";
|
|
15
|
-
import { CURSOR_MARKER, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
16
|
-
import { BOLD, FG_BLUE, FG_DIM, FG_GREEN, RST } from "@xynogen/pix-pretty/ansi";
|
|
17
|
-
import { icon } from "@xynogen/pix-pretty/icon-catalog";
|
|
18
|
-
import { dirIcon, fileIcon } from "@xynogen/pix-pretty/icons";
|
|
19
|
-
|
|
20
|
-
// ponytail: Pi only exposes atomic paste tokens today. Keep its private registry
|
|
21
|
-
// adapter here; replace this adapter when Pi provides a public inline-token API.
|
|
22
|
-
type Chip = { kind: "image" | "path"; path: string };
|
|
23
|
-
type Registry = Map<number, string | Chip>;
|
|
24
|
-
type PiEditor = {
|
|
25
|
-
pastes: Registry;
|
|
26
|
-
pasteCounter: number;
|
|
27
|
-
expandPasteMarkers(text: string): string;
|
|
28
|
-
handlePaste(text: string): void;
|
|
29
|
-
insertTextAtCursorInternal(text: string): void;
|
|
30
|
-
};
|
|
31
|
-
const MARKER = /\[paste #(\d+)( (\+\d+ lines|\d+ chars))?\]/g;
|
|
32
|
-
const SGR = "(?:\\x1b\\[[0-9;]*m|\\x1b_pi:c\\x07)*";
|
|
33
|
-
const PASTE_SPAN = new RegExp(`${SGR}\\[${SGR}paste #(?:[^\\]]|${SGR})*\\]`, "g");
|
|
34
|
-
const PATH_TAG = /<path>([^<]+)<\/path>/g;
|
|
35
|
-
const PASTE_TAG = /<paste>([\s\S]*?)<\/paste>/g;
|
|
36
|
-
const CODES = /\x1b\[[0-9;]*m|\x1b_pi:c\x07/g;
|
|
37
|
-
const IMAGE_PATH =
|
|
38
|
-
/(^|[^\w/@])((?:~|\/)[^\s,;'"(){}[\]]+\.(?:png|jpe?g|gif|webp|bmp|tiff?|heic|heif))(?=$|[\s,;'"(){}[\]])/gi;
|
|
39
|
-
|
|
40
|
-
/** Expand once: token-looking text inside a paste is literal user content. */
|
|
41
|
-
export function expandChips(text: string, registry: Registry): string {
|
|
42
|
-
return text.replace(MARKER, (marker, id: string) => {
|
|
43
|
-
const value = registry.get(Number(id));
|
|
44
|
-
if (value === undefined) return marker;
|
|
45
|
-
if (typeof value === "string") return `<paste>${value}</paste>`;
|
|
46
|
-
return value.kind === "path" ? `<path>${value.path}</path>` : `<paste>${value.path}</paste>`;
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/** Re-emit the cursor (inverse video + TUI marker) that a chip swallowed. */
|
|
51
|
-
function keepCursor(span: string, label: string): string {
|
|
52
|
-
const marker = span.includes(CURSOR_MARKER) ? CURSOR_MARKER : "";
|
|
53
|
-
return span.includes("\x1b[7m")
|
|
54
|
-
? `${marker}\x1b[7m${label.replaceAll(RST, `${RST}\x1b[7m`)}\x1b[27m`
|
|
55
|
-
: marker + label;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** Plain chip text: `head` is the identity, `meta` the dim size/id suffix. */
|
|
59
|
-
function chipLabel(
|
|
60
|
-
value: string | Chip,
|
|
61
|
-
id?: number,
|
|
62
|
-
): { head: string; meta: string; color: string } {
|
|
63
|
-
if (typeof value === "string") {
|
|
64
|
-
const lines = value.split("\n").length;
|
|
65
|
-
const count =
|
|
66
|
-
value.length < 1000 ? `${value.length}` : `${Number((value.length / 1000).toFixed(1))}k`;
|
|
67
|
-
return {
|
|
68
|
-
head: `${icon("paste.text")} text`,
|
|
69
|
-
meta: lines > 10 ? `${lines} lines` : `${count} chars`,
|
|
70
|
-
color: FG_GREEN,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
if (value.kind === "path") {
|
|
74
|
-
const dir = value.path.endsWith("/");
|
|
75
|
-
const name = basename(value.path) || value.path;
|
|
76
|
-
// Same file-type glyphs the picker shows (trailing space is part of the icon).
|
|
77
|
-
return {
|
|
78
|
-
head: `${dir ? dirIcon() : fileIcon(value.path)}@${name}${dir && name !== "/" ? "/" : ""}`,
|
|
79
|
-
meta: "",
|
|
80
|
-
color: FG_BLUE,
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
return {
|
|
84
|
-
head: `${icon("paste.image")} image`,
|
|
85
|
-
meta: id === undefined ? "" : `#${id}`,
|
|
86
|
-
color: FG_BLUE,
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export function renderChips(line: string, registry: Registry): string {
|
|
91
|
-
return line.replace(PASTE_SPAN, (span) => {
|
|
92
|
-
const id = Number(/\[paste #(\d+)/.exec(span.replace(CODES, ""))?.[1]);
|
|
93
|
-
const value = registry.get(id);
|
|
94
|
-
if (value === undefined) return span;
|
|
95
|
-
const { head, meta, color } = chipLabel(value, id);
|
|
96
|
-
const label = `${color}${BOLD}${head}${RST}${meta ? `${FG_DIM} ${meta}${RST}` : ""}`;
|
|
97
|
-
// Tight, no padding: Pi locates the cursor by its marker, so a shorter chip
|
|
98
|
-
// just shifts following text left. render() clamps overflow.
|
|
99
|
-
return keepCursor(span, label);
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const HISTORY_TAG = /<(paste|path)>([\s\S]*?)<\/\1>/g;
|
|
104
|
-
const IMAGE_FILE = /^(?:~|\/)\S+\.(?:png|jpe?g|gif|webp|bmp|tiff?|heic|heif)$/i;
|
|
105
|
-
const PREVIEW_CHARS = 40;
|
|
106
|
-
|
|
107
|
-
/** Head…tail glimpse of a paste (whitespace collapsed, backticks dropped for inline code). */
|
|
108
|
-
function snippet(text: string): string {
|
|
109
|
-
const flat = text.replace(/`/g, "").replace(/\s+/g, " ").trim();
|
|
110
|
-
if (flat.length <= PREVIEW_CHARS) return flat;
|
|
111
|
-
const tail = Math.floor(PREVIEW_CHARS / 3);
|
|
112
|
-
return `${flat.slice(0, PREVIEW_CHARS - tail).trimEnd()}…${flat.slice(-tail).trimStart()}`;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Display-only: collapse `<paste>…</paste>` / `<path>…</path>` in a sent user
|
|
117
|
-
* message into the same chips the editor showed. Session and model context
|
|
118
|
-
* keep the full text; images take the paste chip since the file path is the
|
|
119
|
-
* whole payload.
|
|
120
|
-
*/
|
|
121
|
-
export function renderHistoryChips(markdown: string): string {
|
|
122
|
-
return markdown.replace(HISTORY_TAG, (_match, tag: string, body: string) => {
|
|
123
|
-
let value: string | Chip = body;
|
|
124
|
-
if (tag === "path") value = { kind: "path", path: body };
|
|
125
|
-
else if (IMAGE_FILE.test(body)) value = { kind: "image", path: body };
|
|
126
|
-
const { head, meta } = chipLabel(value);
|
|
127
|
-
// Text pastes keep a short glimpse so history stays scannable.
|
|
128
|
-
const preview = typeof value === "string" ? snippet(value) : "";
|
|
129
|
-
return `\`${head}${meta ? ` ${meta}` : ""}${preview ? ` · ${preview}` : ""}\``;
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/** Patch one editor instance; order-independent with other instance patchers (pix-search). */
|
|
134
|
-
export function installChips(editor: CustomEditor): void {
|
|
135
|
-
// SAFETY: Pi's TS-private members remain runtime properties on CustomEditor.
|
|
136
|
-
const pi = editor as unknown as PiEditor;
|
|
137
|
-
pi.expandPasteMarkers = (text) => expandChips(text, pi.pastes);
|
|
138
|
-
const handlePaste = pi.handlePaste.bind(editor);
|
|
139
|
-
pi.handlePaste = (text) => {
|
|
140
|
-
if (IMAGE_FILE.test(text)) {
|
|
141
|
-
editor.insertTextAtCursor(`<paste>${text}</paste>`);
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
const before = pi.pasteCounter;
|
|
145
|
-
handlePaste(text);
|
|
146
|
-
// Land the cursor after the chip, not glued to it.
|
|
147
|
-
if (pi.pasteCounter > before) pi.insertTextAtCursorInternal(" ");
|
|
148
|
-
};
|
|
149
|
-
const insertTextAtCursor = editor.insertTextAtCursor.bind(editor);
|
|
150
|
-
editor.insertTextAtCursor = (text: string) => {
|
|
151
|
-
if (!text) return;
|
|
152
|
-
// SAFETY: Pi snapshots and renumbers registry values without interpreting them.
|
|
153
|
-
const chip = (value: string | Chip, length: number) => {
|
|
154
|
-
const id = ++pi.pasteCounter;
|
|
155
|
-
pi.pastes.set(id, value);
|
|
156
|
-
return `[paste #${id} ${length} chars]`;
|
|
157
|
-
};
|
|
158
|
-
const replaced = text
|
|
159
|
-
.replace(PATH_TAG, (_match, path: string) => chip({ kind: "path", path }, path.length))
|
|
160
|
-
.replace(PASTE_TAG, (_match, body: string) =>
|
|
161
|
-
chip(IMAGE_FILE.test(body) ? { kind: "image", path: body } : body, body.length),
|
|
162
|
-
)
|
|
163
|
-
.replace(
|
|
164
|
-
IMAGE_PATH,
|
|
165
|
-
(_match, prefix: string, path: string) =>
|
|
166
|
-
prefix + chip({ kind: "image", path }, path.length),
|
|
167
|
-
);
|
|
168
|
-
insertTextAtCursor(/\[paste #\d+[^\]]*\]$/.test(replaced) ? `${replaced} ` : replaced);
|
|
169
|
-
};
|
|
170
|
-
const render = editor.render.bind(editor);
|
|
171
|
-
editor.render = (width: number) =>
|
|
172
|
-
render(width).map((line) => {
|
|
173
|
-
// SAFETY: Pi owns the current registry, including its replacement during undo.
|
|
174
|
-
const styled = renderChips(line, pi.pastes);
|
|
175
|
-
// Restyling may widen a line (e.g. "#1" → "text"); clamp only on overflow.
|
|
176
|
-
return visibleWidth(styled) > width ? truncateToWidth(styled, width, "") : styled;
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export default function (pi: ExtensionAPI): void {
|
|
181
|
-
// ponytail: local Pi 0.82 types predate the runtime Markdown transformer hook.
|
|
182
|
-
const markdownPi = pi as ExtensionAPI & {
|
|
183
|
-
registerMarkdownTransformer?: (
|
|
184
|
-
transformer: (markdown: string, context: { messageType: string }) => string,
|
|
185
|
-
) => void;
|
|
186
|
-
};
|
|
187
|
-
markdownPi.registerMarkdownTransformer?.((markdown, { messageType }) =>
|
|
188
|
-
messageType === "user" ? renderHistoryChips(markdown) : markdown,
|
|
189
|
-
);
|
|
190
|
-
|
|
191
|
-
pi.on("session_start", (_event, ctx) => {
|
|
192
|
-
if (ctx.mode !== "tui") return;
|
|
193
|
-
const previous = ctx.ui.getEditorComponent();
|
|
194
|
-
ctx.ui.setEditorComponent((tui, theme, kb) => {
|
|
195
|
-
const editor = previous?.(tui, theme, kb) ?? new CustomEditor(tui, theme, kb);
|
|
196
|
-
// ponytail: chips need CustomEditor internals; a foreign editor is kept unchipped.
|
|
197
|
-
if (editor instanceof CustomEditor) installChips(editor);
|
|
198
|
-
return editor;
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
pi.on("session_shutdown", (_event, ctx) => {
|
|
203
|
-
if (ctx.mode === "tui") ctx.ui.setEditorComponent(undefined);
|
|
204
|
-
});
|
|
205
|
-
}
|