pi-image-preview 0.1.2 → 0.1.5

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/index.ts CHANGED
@@ -18,7 +18,7 @@ async function loadPiImageResizer(): Promise<ImageResizer | null> {
18
18
  cachedResizerPromise = (async () => {
19
19
  try {
20
20
  const require = createRequire(import.meta.url);
21
- const piEntry = require.resolve("@mariozechner/pi-coding-agent");
21
+ const piEntry = require.resolve("@earendil-works/pi-coding-agent");
22
22
  const distDir = path.dirname(piEntry);
23
23
  const moduleUrl = pathToFileURL(
24
24
  path.join(distDir, "utils", "image-resize.js"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-image-preview",
3
- "version": "0.1.2",
3
+ "version": "0.1.5",
4
4
  "description": "Image preview extension for pi coding agent — renders inline image thumbnails above the editor using kitty graphics protocol with tmux support",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -228,6 +228,12 @@ export function registerImagePreviewExtension(
228
228
  debugLog("Error during editor text scan", err);
229
229
  });
230
230
  }, POLL_INTERVAL_MS);
231
+ // Don't let the poll timer keep the Node event loop alive.
232
+ // In non-interactive modes (e.g. `pi --print`), the process must be
233
+ // able to exit once work is done — an active interval would block exit.
234
+ if (typeof pollTimer.unref === "function") {
235
+ pollTimer.unref();
236
+ }
231
237
  }
232
238
 
233
239
  function stopPolling(): void {
@@ -1,10 +1,36 @@
1
1
  import {
2
2
  type Component,
3
3
  getCapabilities,
4
+ type ImageProtocol,
4
5
  getImageDimensions,
5
6
  calculateImageRows,
6
7
  getCellDimensions,
7
- } from "@mariozechner/pi-tui";
8
+ } from "@earendil-works/pi-tui";
9
+
10
+ /**
11
+ * Detect image protocol support, working around pi-tui ≥0.67.6 which
12
+ * hardcodes `images: null` inside tmux/screen for safety. Our extension
13
+ * uses the Unicode placeholder protocol which is specifically designed
14
+ * to work inside tmux, so we can safely detect kitty-in-tmux ourselves.
15
+ */
16
+ function detectImageProtocol(): ImageProtocol | null {
17
+ const caps = getCapabilities();
18
+ if (caps.images) return caps.images;
19
+
20
+ // pi-tui returns null inside tmux — check if the outer terminal is kitty
21
+ const inTmux = !!process.env.TMUX || (process.env.TERM?.toLowerCase() || "").startsWith("tmux");
22
+ if (inTmux) {
23
+ if (process.env.KITTY_WINDOW_ID || (process.env.TERM_PROGRAM?.toLowerCase() || "") === "kitty") {
24
+ return "kitty";
25
+ }
26
+ // ghostty and wezterm also support kitty graphics in tmux
27
+ const termProgram = process.env.TERM_PROGRAM?.toLowerCase() || "";
28
+ if (termProgram === "ghostty" || process.env.GHOSTTY_RESOURCES_DIR) return "kitty";
29
+ if (termProgram === "wezterm" || process.env.WEZTERM_PANE) return "kitty";
30
+ }
31
+
32
+ return null;
33
+ }
8
34
 
9
35
  export interface GalleryTheme {
10
36
  accent: (s: string) => string;
@@ -20,6 +46,7 @@ export interface GalleryImage {
20
46
  }
21
47
 
22
48
  const THUMB_MAX_WIDTH = 25;
49
+ const THUMB_MAX_ROWS = 15; // cap height so tall images don't overflow the terminal
23
50
  const GAP = 2; // columns between images
24
51
 
25
52
  // Monotonic counter for kitty image IDs — avoids birthday-paradox collisions
@@ -229,7 +256,7 @@ export class ImageGallery implements Component {
229
256
  }
230
257
 
231
258
  const lines: string[] = [];
232
- const caps = getCapabilities();
259
+ const imageProtocol = detectImageProtocol();
233
260
 
234
261
  // Header
235
262
  const count = this.images.length;
@@ -239,7 +266,7 @@ export class ImageGallery implements Component {
239
266
  : ` 📎 ${count} images attached`;
240
267
  lines.push(this.theme.accent(headerText));
241
268
 
242
- if (caps.images === "kitty") {
269
+ if (imageProtocol === "kitty") {
243
270
  this.renderKittyHorizontal(lines, width);
244
271
  } else {
245
272
  this.renderTextFallback(lines);
@@ -276,7 +303,10 @@ export class ImageGallery implements Component {
276
303
  heightPx: 600,
277
304
  };
278
305
 
279
- const rows = calculateImageRows(dims, thumbWidth, getCellDimensions());
306
+ const rows = Math.min(
307
+ calculateImageRows(dims, thumbWidth, getCellDimensions()),
308
+ THUMB_MAX_ROWS,
309
+ );
280
310
  const imageId = allocateImageId();
281
311
  this.activeImageIds.push(imageId);
282
312