@xynogen/pix-display 0.1.1 → 0.1.3

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
@@ -6,7 +6,7 @@ Pi core extension — paste chip rendering and thinking block display.
6
6
 
7
7
  Two features, always on when installed:
8
8
 
9
- **Paste chips.** Replaces Pi's paste markers (`[paste #1 2232 chars]`) with styled icon chips (`text 2.2k chars` for text, `image #1` for images). 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.
9
+ **Paste chips.** Replaces Pi's paste markers (`[paste #1 2232 chars]`) with styled icon chips: `image #1` for image pastes (blue), `text +N lines` / `text Nk chars` for text pastes (green). 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.
10
10
 
11
11
  **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`).
12
12
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xynogen/pix-display",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Pi core extension — paste chip rendering and thinking block display",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -33,6 +33,12 @@ type EditorFactory = (
33
33
 
34
34
  // ─── Constants ────────────────────────────────────────────────────────────────
35
35
 
36
+ // Boundary wrapper injected around each expanded paste so the model sees an
37
+ // explicit start/end per blob instead of multiple pastes merged into one wall.
38
+ // Applies to text and image pastes alike.
39
+ const PASTE_OPEN = "<paste>";
40
+ const PASTE_CLOSE = "</paste>";
41
+
36
42
  const IMAGE_EXTS = new Set([
37
43
  ".png",
38
44
  ".jpg",
@@ -79,14 +85,55 @@ type EditorInternals = {
79
85
  pasteCounter: number;
80
86
  };
81
87
 
88
+ // expandPasteMarkers is TS-private on the base Editor but runtime-public JS.
89
+ // We reimplement its loop (rather than call super) so we can wrap each
90
+ // replacement, and to avoid depending on a non-exported private method.
91
+ type ExpandInternals = {
92
+ pastes: Map<number, string>;
93
+ };
94
+
95
+ type ExpandPasteHandler = { expandPasteMarkers(text: string): string };
96
+
97
+ // Mirror of the base Editor's paste-marker grammar, per-id at expand time.
98
+ function markerReFor(pasteId: number): RegExp {
99
+ return new RegExp(
100
+ `\\[paste #${pasteId}( (\\+\\d+ lines|\\d+ chars))?\\]`,
101
+ "g",
102
+ );
103
+ }
104
+
105
+ /**
106
+ * Expand every paste marker in `text` to its content wrapped in
107
+ * `<paste>…</paste>`. Mirrors the base Editor's expansion loop but adds a
108
+ * boundary per blob (text and image alike) so adjacent pastes can't merge
109
+ * into one indistinguishable wall in the model-facing text.
110
+ */
111
+ export function expandPasteMarkers(
112
+ text: string,
113
+ pastes: Map<number, string>,
114
+ ): string {
115
+ let result = text;
116
+ for (const [pasteId, pasteContent] of pastes) {
117
+ result = result.replace(
118
+ markerReFor(pasteId),
119
+ () => `${PASTE_OPEN}${pasteContent}${PASTE_CLOSE}`,
120
+ );
121
+ }
122
+ return result;
123
+ }
124
+
82
125
  // ─── Path → marker rewriter ──────────────────────────────────────────────────
83
126
 
84
127
  /**
85
128
  * Walk `text`, for each image path: allocate a new paste ID, register the
86
129
  * real path in editor.pastes, remember the ID as an image, and emit a
87
130
  * Pi-format marker so deletion is atomic.
131
+ *
132
+ * Exported for integration testing: composed with `expandPasteMarkers`, this
133
+ * reproduces the full clipboard-image round-trip (path insert → marker →
134
+ * boundary-wrapped expansion) without standing up a live TUI editor.
88
135
  */
89
- function replaceImagePaths(
136
+ export function replaceImagePaths(
90
137
  text: string,
91
138
  internals: EditorInternals,
92
139
  imageIds: Set<number>,
@@ -167,6 +214,7 @@ class ChipEditor extends CustomEditor {
167
214
  constructor(...args: ConstructorParameters<typeof CustomEditor>) {
168
215
  super(...args);
169
216
  this.patchHandlePaste();
217
+ this.patchExpandPasteMarkers();
170
218
  }
171
219
 
172
220
  override insertTextAtCursor(text: string): void {
@@ -179,6 +227,20 @@ class ChipEditor extends CustomEditor {
179
227
  );
180
228
  }
181
229
 
230
+ /**
231
+ * Patch `expandPasteMarkers` (TS-private on the base Editor, runtime-public
232
+ * JS) so every paste expands to its content wrapped in `<paste>…</paste>`,
233
+ * giving the model an explicit boundary per blob — text and image alike.
234
+ * The base inlines content raw, letting adjacent pastes merge into one
235
+ * indistinguishable wall. Patched per-instance, mirroring patchHandlePaste.
236
+ */
237
+ private patchExpandPasteMarkers(): void {
238
+ const internals = this as unknown as ExpandInternals;
239
+ const self = this as unknown as ExpandPasteHandler;
240
+ self.expandPasteMarkers = (text: string): string =>
241
+ expandPasteMarkers(text, internals.pastes);
242
+ }
243
+
182
244
  private patchHandlePaste(): void {
183
245
  const self = this as unknown as PasteHandler;
184
246
  const base = self.handlePaste.bind(self);