pi-image-preview 0.1.1 → 0.1.4

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,6 +1,6 @@
1
1
  # pi-image-preview
2
2
 
3
- Image preview extension for [pi coding agent](https://github.com/mariozechner/pi-coding-agent) — renders inline image thumbnails above the editor using the kitty graphics protocol with full tmux support.
3
+ Image preview extension for [pi coding agent](https://github.com/badlogic/pi-mono) — renders inline image thumbnails above the editor using the kitty graphics protocol with full tmux support.
4
4
 
5
5
  ![Screenshot](screenshot.png)
6
6
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pi-image-preview",
3
- "version": "0.1.1",
4
- "description": "Image preview extension for pi coding agent — renders inline image thumbnails above the editor using kitty graphics protocol with tmux support",
3
+ "version": "0.1.4",
4
+ "description": "Image preview extension for pi coding agent \u2014 renders inline image thumbnails above the editor using kitty graphics protocol with tmux support",
5
5
  "keywords": [
6
6
  "pi-package",
7
7
  "kitty",
@@ -1,7 +1,6 @@
1
1
  import path from "node:path";
2
2
  import type { ImageContent, ContentBlock } from "./content.ts";
3
3
  import { ImageGallery, type GalleryImage } from "./image-gallery.ts";
4
- import { PREFER_INLINE_SCREENSHOT_PROMPT } from "./prompt.ts";
5
4
  import { upgradeScreenshotToolResult } from "./tool-result-upgrader.ts";
6
5
  import { debugLog } from "./debug.ts";
7
6
 
@@ -240,10 +239,6 @@ export function registerImagePreviewExtension(
240
239
 
241
240
  // ── Event handlers ─────────────────────────────────────
242
241
 
243
- pi.on("before_agent_start", () => {
244
- return { systemPrompt: PREFER_INLINE_SCREENSHOT_PROMPT };
245
- });
246
-
247
242
  // Clean up resources when the process exits
248
243
  const cleanup = (): void => {
249
244
  stopPolling();
@@ -1,11 +1,37 @@
1
1
  import {
2
2
  type Component,
3
3
  getCapabilities,
4
+ type ImageProtocol,
4
5
  getImageDimensions,
5
6
  calculateImageRows,
6
7
  getCellDimensions,
7
8
  } from "@mariozechner/pi-tui";
8
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
+ }
34
+
9
35
  export interface GalleryTheme {
10
36
  accent: (s: string) => string;
11
37
  muted: (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
 
package/src/prompt.ts DELETED
@@ -1,2 +0,0 @@
1
- export const PREFER_INLINE_SCREENSHOT_PROMPT =
2
- "When you need to inspect a screenshot yourself, prefer screenshot tool calls that return the image inline. Avoid passing filePath to screenshot tools unless the user explicitly asked you to save a file or you do not need to inspect the image content yourself.";