@xynogen/pix-display 0.1.10 → 0.1.12

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
@@ -1,3 +1,5 @@
1
+ <!-- markdownlint-disable MD013 -->
2
+
1
3
  # pix-display
2
4
 
3
5
  Pi core extension — paste chips, thinking blocks, and polished code snippets.
@@ -12,7 +14,7 @@ Three features, always on when installed:
12
14
 
13
15
  **Code snippets.** Renders every fenced code block in assistant responses inside a themed, language-labeled frame—including Python, TypeScript, JSON, YAML, Rust, Go, SQL, shell, and arbitrary custom language tags. Untagged fences use a `code` label. Pi's native syntax highlighting remains intact for recognized languages, while long lines are safely clipped to the terminal width.
14
16
 
15
- The features are registered at session start. TUI-only display changes are no-ops in JSON/RPC/print modes.
17
+ The features are registered at session start. TUI-only display changes are no-ops in JSON/RPC/print modes. In-process non-TUI child sessions (such as background subagents) do not clear the parent TUI's renderer state.
16
18
 
17
19
  ## Install
18
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xynogen/pix-display",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "description": "Pi core extension \u2014 paste chips, thinking blocks, and framed code rendering",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -13,6 +13,7 @@ const OSC_RE = /\x1b\][^\x07]*(?:\x07|\x1b\\)/g;
13
13
  const PATCHED = Symbol.for("@xynogen/pix-display:code-block-renderer");
14
14
 
15
15
  type CodeFrameTheme = Pick<Theme, "bg" | "bold" | "fg" | "getBgAnsi">;
16
+ type RenderMode = "tui" | "rpc" | "json" | "print";
16
17
 
17
18
  type PatchablePrototype = {
18
19
  [PATCHED]?: boolean;
@@ -21,6 +22,20 @@ type PatchablePrototype = {
21
22
 
22
23
  let activeTheme: CodeFrameTheme | undefined;
23
24
 
25
+ /**
26
+ * Preserve the main TUI theme when an in-process non-TUI child session starts.
27
+ * Subagents share this module and the patched prototype with the parent; letting
28
+ * their print/RPC session clear the theme silently disables code frames in the
29
+ * still-running parent transcript.
30
+ */
31
+ export function themeAfterSessionStart(
32
+ current: CodeFrameTheme | undefined,
33
+ mode: RenderMode,
34
+ theme: CodeFrameTheme,
35
+ ): CodeFrameTheme | undefined {
36
+ return mode === "tui" ? theme : current;
37
+ }
38
+
24
39
  function plainText(line: string): string {
25
40
  return line.replace(OSC_RE, "").replace(ANSI_RE, "");
26
41
  }
@@ -149,6 +164,6 @@ function patchAssistantRenderer(): void {
149
164
  export default function codeBlocksExtension(pi: ExtensionAPI): void {
150
165
  patchAssistantRenderer();
151
166
  pi.on("session_start", (_event, ctx) => {
152
- activeTheme = ctx.mode === "tui" ? ctx.ui.theme : undefined;
167
+ activeTheme = themeAfterSessionStart(activeTheme, ctx.mode, ctx.ui.theme);
153
168
  });
154
169
  }
@@ -149,11 +149,20 @@ export function replaceImagePaths(
149
149
  *
150
150
  * Width-preserving is not required — Pi re-wraps each render call.
151
151
  */
152
+ // A `[...]` span that starts with `paste #` and may carry interleaved cursor
153
+ // SGR codes (e.g. `[paste #1 \x1b[7m5\x1b[0m8 chars]`). We strip ANSI from the
154
+ // matched span only, never the whole line, so the editor cursor's own
155
+ // inverse-video block outside any marker survives.
156
+ const MARKER_SPAN_RE =
157
+ /(?:\x1b\[[0-9;]*m)*\[(?:\x1b\[[0-9;]*m)*paste #(?:[^\]]|\x1b\[[0-9;]*m)*\]/g;
158
+
152
159
  export function restyleMarkers(line: string, imageIds: Set<number>): string {
153
- // Strip cursor inversion codes the TUI embeds when the cursor
154
- // intersects a marker — plain MARKER_RE handles the rest.
155
- const clean = line.includes("\x1b") ? line.replace(CURSOR_RE, "") : line;
156
- return clean.replace(MARKER_RE, (_full, idStr, _g2, _g3, linesStr, charsStr) => {
160
+ return line.replace(MARKER_SPAN_RE, (span) => {
161
+ const clean = span.includes("\x1b") ? span.replace(CURSOR_RE, "") : span;
162
+ MARKER_RE.lastIndex = 0;
163
+ const m = MARKER_RE.exec(clean);
164
+ if (!m?.[1]) return span;
165
+ const [, idStr, , , linesStr, charsStr] = m;
157
166
  const id = Number.parseInt(idStr, 10);
158
167
  if (imageIds.has(id)) {
159
168
  return chip(FG_BLUE, icon("paste.image"), "image", `#${id}`);
@@ -191,6 +200,18 @@ function compactNumber(raw: string): string {
191
200
  // per-instance, capturing the base implementation, so large text pastes get the
192
201
  // same trailing-space treatment as image chips.
193
202
  type PasteHandler = { handlePaste(text: string): void };
203
+ type SubmitHandler = { submitValue(): void };
204
+
205
+ /**
206
+ * Drop image classifications when Pi resets its paste IDs after a submit.
207
+ *
208
+ * The base editor clears `pastes` and resets `pasteCounter` to zero, so IDs are
209
+ * reused in the next prompt. Keeping the old IDs would make a later text paste
210
+ * with the same ID render as an image chip.
211
+ */
212
+ export function clearImageIdsAfterSubmit(imageIds: Set<number>): void {
213
+ imageIds.clear();
214
+ }
194
215
 
195
216
  class ChipEditor extends CustomEditor {
196
217
  private readonly imageIds = new Set<number>();
@@ -199,6 +220,7 @@ class ChipEditor extends CustomEditor {
199
220
  super(...args);
200
221
  this.patchHandlePaste();
201
222
  this.patchExpandPasteMarkers();
223
+ this.patchSubmitValue();
202
224
  }
203
225
 
204
226
  override insertTextAtCursor(text: string): void {
@@ -237,6 +259,17 @@ class ChipEditor extends CustomEditor {
237
259
  };
238
260
  }
239
261
 
262
+ private patchSubmitValue(): void {
263
+ const self = this as unknown as SubmitHandler;
264
+ const base = self.submitValue.bind(self);
265
+ self.submitValue = () => {
266
+ // Pi resets pasteCounter to zero in submitValue. Clear the parallel
267
+ // image-ID registry in the same operation before those IDs get reused.
268
+ clearImageIdsAfterSubmit(this.imageIds);
269
+ base();
270
+ };
271
+ }
272
+
240
273
  override render(width: number): string[] {
241
274
  const raw = super.render(width);
242
275
  return raw.map((line) => {