Skip to content

A self-improving RLM agent for coding workflows and long-running autonomous tasks.

Rust

fix(tui): show compact fullscreen image fallbacks (#437)

Sebastian Müllere751ad727dec
diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md
index b36ed19c68..5c347973ee 100644
--- a/packages/coding-agent/CHANGELOG.md
+++ b/packages/coding-agent/CHANGELOG.md
@@ -4,6 +4,7 @@
- Fixed daemon backpressure triggering redundant catch-up snapshots for events already queued by the socket.
- Fixed incompatible daemon builds crashing startup or respawning after shutdown, with capability negotiation, verified provenance, and convergent force shutdown ([ENG-4687](https://linear.app/primeintellect/issue/ENG-4687/make-daemon-version-mismatches-self-healing)).
+- Changed tool-result and announcement images to show compact metadata instead of terminal graphics ([#437](https://github.com/PrimeIntellect-ai/prime-agent/pull/437) by [@snimu](https://github.com/snimu)).
- Changed top-level CLI help to show concise common options and commands without loading runtime resources ([ENG-4688](https://linear.app/primeintellect/issue/ENG-4688/help-command-is-obscenely-verbose)).
- Fixed completed subagents cancelling their RLM heartbeats before the first run ([ENG-4652](https://linear.app/primeintellect/issue/ENG-4652/subagent-heartbeats-dont-work)).
- Changed the fullscreen follow shortcut from `Alt+Down` to `Ctrl+Shift+Down` for more reliable terminal input ([ENG-4684](https://linear.app/primeintellect/issue/ENG-4684/altdown-doesnt-work)).
diff --git a/packages/coding-agent/docs/settings.md b/packages/coding-agent/docs/settings.md
index 1723d38aa1..652db88046 100644
--- a/packages/coding-agent/docs/settings.md
+++ b/packages/coding-agent/docs/settings.md
@@ -143,8 +143,7 @@ When a provider requests a retry delay longer than `retry.provider.maxRetryDelay
| Setting | Type | Default | Description |
|---------|------|---------|-------------|
-| `terminal.showImages` | boolean | `true` | Show images in terminal (if supported) |
-| `terminal.imageWidthCells` | number | `60` | Preferred inline image width in terminal cells |
+| `terminal.showImages` | boolean | `true` | Show image type and dimensions in terminal |
| `terminal.clearOnShrink` | boolean | `false` | Clear empty rows when content shrinks (can cause flicker) |
| `images.autoResize` | boolean | `true` | Resize images to 2000x2000 max |
| `images.blockImages` | boolean | `false` | Block all images from being sent to LLM |
diff --git a/packages/coding-agent/docs/tui.md b/packages/coding-agent/docs/tui.md
index b51fa19f54..2872ac4b74 100644
--- a/packages/coding-agent/docs/tui.md
+++ b/packages/coding-agent/docs/tui.md
@@ -248,14 +248,14 @@ md.setText("Updated markdown");
### Image
-Renders images in supported terminals (Kitty, iTerm2, Ghostty, WezTerm).
+Prime Agent shows compact image metadata and does not emit terminal graphics for images.
```typescript
const image = new Image(
base64Data, // base64-encoded image
"image/png", // MIME type
theme, // ImageTheme
- { maxWidthCells: 80, maxHeightCells: 24 }
+ { filename: "result.png", fallbackOnly: true }
);
```
diff --git a/packages/coding-agent/src/core/extensions/types.ts b/packages/coding-agent/src/core/extensions/types.ts
index 6863256cda..b0dfecb1f7 100644
--- a/packages/coding-agent/src/core/extensions/types.ts
+++ b/packages/coding-agent/src/core/extensions/types.ts
@@ -409,7 +409,7 @@ export interface ToolRenderContext<TState = any, TArgs = any> {
expanded: boolean;
/** Whether this row should show the global tool expansion shortcut. */
showExpandHint?: boolean;
- /** Whether inline images are currently shown in the TUI. */
+ /** Whether image metadata is currently shown in the TUI. */
showImages: boolean;
/** Whether image fallback labels may parse dimensions from base64 data. */
includeImageDimensions: boolean;
diff --git a/packages/coding-agent/src/core/settings-manager.ts b/packages/coding-agent/src/core/settings-manager.ts
index 33241f690c..5230b109c1 100644
--- a/packages/coding-agent/src/core/settings-manager.ts
+++ b/packages/coding-agent/src/core/settings-manager.ts
@@ -40,8 +40,7 @@ export interface RetrySettings {
}
export interface TerminalSettings {
- showImages?: boolean; // default: true (only relevant if terminal supports images)
- imageWidthCells?: number; // default: 60 (preferred inline image width in terminal cells)
+ showImages?: boolean; // default: true (show image type and dimensions)
clearOnShrink?: boolean; // default: false (clear empty rows when content shrinks)
showTerminalProgress?: boolean; // default: false (OSC 9;4 terminal progress indicators)
fullscreen?: boolean; // default: true (alternate-screen rendering with scrollable transcript)
@@ -1027,23 +1026,6 @@ export class SettingsManager {
this.save();
}
- getImageWidthCells(): number {
- const width = this.settings.terminal?.imageWidthCells;
- if (typeof width !== "number" || !Number.isFinite(width)) {
- return 60;
- }
- return Math.max(1, Math.floor(width));
- }
-
- setImageWidthCells(width: number): void {
- if (!this.globalSettings.terminal) {
- this.globalSettings.terminal = {};
- }
- this.globalSettings.terminal.imageWidthCells = Math.max(1, Math.floor(width));
- this.markModified("terminal", "imageWidthCells");
- this.save();
- }
-
getClearOnShrink(): boolean {
// Settings takes precedence, then env var, then default false
if (this.settings.terminal?.clearOnShrink !== undefined) {
diff --git a/packages/coding-agent/src/core/tools/render-utils.ts b/packages/coding-agent/src/core/tools/render-utils.ts
index 5307527fe3..81d057583a 100644
--- a/packages/coding-agent/src/core/tools/render-utils.ts
+++ b/packages/coding-agent/src/core/tools/render-utils.ts
@@ -1,6 +1,6 @@
import * as os from "node:os";
import type { ImageContent, TextContent } from "@earendil-works/pi-ai";
-import { getCapabilities, getImageDimensions, imageFallback } from "@earendil-works/pi-tui";
+import { getImageDimensions, imageFallback } from "@earendil-works/pi-tui";
import stripAnsi from "strip-ansi";
import { sanitizeBinaryOutput } from "../../utils/shell.js";
@@ -44,9 +44,8 @@ export function getTextOutput(
let output = textBlocks.map((c) => sanitizeBinaryOutput(stripAnsi(c.text || "")).replace(/\r/g, "")).join("\n");
- const caps = getCapabilities();
const includeImageDimensions = options.includeImageDimensions ?? true;
- if (imageBlocks.length > 0 && (!caps.images || !showImages)) {
+ if (imageBlocks.length > 0 && !showImages) {
const imageIndicators = imageBlocks
.map((img) => {
const mimeType = img.mimeType ?? "image/unknown";
diff --git a/packages/coding-agent/src/modes/interactive/components/conversation-components.ts b/packages/coding-agent/src/modes/interactive/components/conversation-components.ts
index ad84f3275c..de40150a38 100644
--- a/packages/coding-agent/src/modes/interactive/components/conversation-components.ts
+++ b/packages/coding-agent/src/modes/interactive/components/conversation-components.ts
@@ -63,8 +63,7 @@ export function buildConversationComponents(
content.name,
content.id,
content.arguments,
- // Replayed history rebuilds on every event; don't re-emit inline images.
- { ...options.toolOptions, allowInlineImages: false },
+ { ...options.toolOptions, includeImageDimensions: false },
options.getToolDefinition(content.name),
options.ui,
options.cwd,
diff --git a/packages/coding-agent/src/modes/interactive/components/earendil-announcement.ts b/packages/coding-agent/src/modes/interactive/components/earendil-announcement.ts
index 59ec78f796..6f5a0bde5c 100644
--- a/packages/coding-agent/src/modes/interactive/components/earendil-announcement.ts
+++ b/packages/coding-agent/src/modes/interactive/components/earendil-announcement.ts
@@ -42,7 +42,7 @@ export class EarendilAnnouncementComponent extends Container {
imageBase64,
"image/png",
{ fallbackColor: (text) => theme.fg("muted", text) },
- { maxWidthCells: 56, filename: IMAGE_FILENAME },
+ { maxWidthCells: 56, filename: IMAGE_FILENAME, fallbackOnly: true },
),
);
this.addChild(new Spacer(1));
diff --git a/packages/coding-agent/src/modes/interactive/components/settings-selector.ts b/packages/coding-agent/src/modes/interactive/components/settings-selector.ts
index a06472b4f6..90f7098be0 100644
--- a/packages/coding-agent/src/modes/interactive/components/settings-selector.ts
+++ b/packages/coding-agent/src/modes/interactive/components/settings-selector.ts
@@ -2,7 +2,6 @@ import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
import type { Transport } from "@earendil-works/pi-ai";
import {
Container,
- getCapabilities,
type SelectItem,
SelectList,
type SelectListLayoutOptions,
@@ -33,7 +32,6 @@ const THINKING_DESCRIPTIONS: Record<ThinkingLevel, string> = {
export interface SettingsConfig {
autoCompact: boolean;
showImages: boolean;
- imageWidthCells: number;
autoResizeImages: boolean;
blockImages: boolean;
enableSkillCommands: boolean;
@@ -60,7 +58,6 @@ export interface SettingsConfig {
export interface SettingsCallbacks {
onAutoCompactChange: (enabled: boolean) => void;
onShowImagesChange: (enabled: boolean) => void;
- onImageWidthCellsChange: (width: number) => void;
onAutoResizeImagesChange: (enabled: boolean) => void;
onBlockImagesChange: (blocked: boolean) => void;
onEnableSkillCommandsChange: (enabled: boolean) => void;
@@ -202,7 +199,6 @@ export class SettingsSelectorComponent extends Container {
constructor(config: SettingsConfig, callbacks: SettingsCallbacks) {
super();
- const supportsImages = getCapabilities().images;
let currentWarnings = { ...config.warnings };
const items: SettingItem[] = [
@@ -325,27 +321,16 @@ export class SettingsSelectorComponent extends Container {
},
];
- // Only show image toggle if terminal supports it
- if (supportsImages) {
- // Insert after autocompact
- items.splice(1, 0, {
- id: "show-images",
- label: "Show images",
- description: "Render images inline in terminal",
- currentValue: config.showImages ? "true" : "false",
- values: ["true", "false"],
- });
- items.splice(2, 0, {
- id: "image-width-cells",
- label: "Image width",
- description: "Preferred inline image width in terminal cells",
- currentValue: String(config.imageWidthCells),
- values: ["60", "80", "120"],
- });
- }
+ items.splice(1, 0, {
+ id: "show-images",
+ label: "Show image metadata",
+ description: "Show image type and dimensions in terminal",
+ currentValue: config.showImages ? "true" : "false",
+ values: ["true", "false"],
+ });
// Image auto-resize toggle (always available, affects both attached and read images)
- items.splice(supportsImages ? 3 : 1, 0, {
+ items.splice(2, 0, {
id: "auto-resize-images",
label: "Auto-resize images",
description: "Resize large images to 2000x2000 max for better model compatibility",
@@ -458,9 +443,6 @@ export class SettingsSelectorComponent extends Container {
case "show-images":
callbacks.onShowImagesChange(newValue === "true");
break;
- case "image-width-cells":
- callbacks.onImageWidthCellsChange(parseInt(newValue, 10));
- break;
case "auto-resize-images":
callbacks.onAutoResizeImagesChange(newValue === "true");
break;
diff --git a/packages/coding-agent/src/modes/interactive/components/show-images-selector.ts b/packages/coding-agent/src/modes/interactive/components/show-images-selector.ts
index c0c7bc153b..7e37cb7124 100644
--- a/packages/coding-agent/src/modes/interactive/components/show-images-selector.ts
+++ b/packages/coding-agent/src/modes/interactive/components/show-images-selector.ts
@@ -17,7 +17,7 @@ export class ShowImagesSelectorComponent extends Container {
super();
const items: SelectItem[] = [
- { value: "yes", label: "Yes", description: "Show images inline in terminal" },
+ { value: "yes", label: "Yes", description: "Show image type and dimensions" },
{ value: "no", label: "No", description: "Show text placeholder instead" },
];
diff --git a/packages/coding-agent/src/modes/interactive/components/tool-execution.ts b/packages/coding-agent/src/modes/interactive/components/tool-execution.ts
index 6579d43016..62e80c8197 100644
--- a/packages/coding-agent/src/modes/interactive/components/tool-execution.ts
+++ b/packages/coding-agent/src/modes/interactive/components/tool-execution.ts
@@ -1,12 +1,11 @@
import type { AgentToolResult } from "@earendil-works/pi-agent-core";
-import { type Component, Container, getCapabilities, Image, Spacer, Text, type TUI } from "@earendil-works/pi-tui";
+import { type Component, Container, Image, Text, type TUI } from "@earendil-works/pi-tui";
import type { ToolDefinition, ToolRenderContext, ToolRenderResultOptions } from "../../../core/extensions/types.js";
import type { KernelSentAgentMessage } from "../../../core/kernel/index.js";
import { createBashToolDefinition } from "../../../core/tools/bash.js";
import { createEditToolDefinition } from "../../../core/tools/edit.js";
import { createAllToolDefinitions } from "../../../core/tools/index.js";
import { getTextOutput as getRenderedTextOutput } from "../../../core/tools/render-utils.js";
-import { convertToPng } from "../../../utils/image-convert.js";
import type { AgentConnectionToolDefinition } from "../../agent-connection/index.js";
import { type Theme, theme } from "../theme/theme.js";
import { getWorkingPulseFrame, workingIconFrame } from "../theme/working-icon.js";
@@ -15,13 +14,8 @@ import { ToolPanel } from "./tool-panel.js";
export interface ToolExecutionOptions {
showImages?: boolean;
- imageWidthCells?: number;
- /**
- * Whether this component may emit inline terminal image escape sequences.
- * Historical session replay disables this so loading image-heavy sessions does
- * not re-send every image in the scrollback.
- */
- allowInlineImages?: boolean;
+ /** Whether image metadata may parse dimensions from base64 data. */
+ includeImageDimensions?: boolean;
}
export interface ToolExecutionRendererDefinition {
@@ -80,15 +74,13 @@ export class ToolExecutionComponent extends Container {
private ipythonCellComponent?: IPythonCellComponent;
private rendererState: any = {};
private imageComponents: Image[] = [];
- private imageSpacers: Spacer[] = [];
private toolName: string;
private toolCallId: string;
private args: any;
private expanded = false;
private showExpandHint = true;
private showImages: boolean;
- private allowInlineImages: boolean;
- private imageWidthCells: number;
+ private includeImageDimensions: boolean;
private isPartial = true;
private toolDefinition?: ToolExecutionDefinition;
private builtInToolDefinition?: ToolDefinition<any, any>;
@@ -102,7 +94,6 @@ export class ToolExecutionComponent extends Container {
isError: boolean;
details?: any;
};
- private convertedImages: Map<number, { data: string; mimeType: string }> = new Map();
private hideComponent = false;
constructor(
@@ -121,8 +112,7 @@ export class ToolExecutionComponent extends Container {
this.toolDefinition = toolDefinition;
this.builtInToolDefinition = createReplayBuiltInToolDefinition(toolName, cwd, toolDefinition);
this.showImages = options.showImages ?? true;
- this.allowInlineImages = options.allowInlineImages ?? true;
- this.imageWidthCells = options.imageWidthCells ?? 60;
+ this.includeImageDimensions = options.includeImageDimensions ?? true;
this.ui = ui;
this.cwd = cwd;
@@ -183,12 +173,7 @@ export class ToolExecutionComponent extends Container {
return this.toolName === "ipython" && !this.toolDefinition?.renderCall && !this.toolDefinition?.renderResult;
}
- private shouldRenderInlineImages(): boolean {
- return this.showImages && this.allowInlineImages;
- }
-
private getRenderContext(lastComponent: Component | undefined): ToolRenderContext {
- const renderInlineImages = this.shouldRenderInlineImages();
return {
args: this.args,
toolCallId: this.toolCallId,
@@ -204,8 +189,8 @@ export class ToolExecutionComponent extends Container {
isPartial: this.isPartial,
expanded: this.expanded,
showExpandHint: this.showExpandHint,
- showImages: renderInlineImages,
- includeImageDimensions: this.allowInlineImages,
+ showImages: this.showImages,
+ includeImageDimensions: this.includeImageDimensions,
isError: this.result?.isError ?? false,
};
}
@@ -264,7 +249,6 @@ export class ToolExecutionComponent extends Container {
this.result = sentAgentMessages.length > 0 ? { ...result, details: { ...details, sentAgentMessages } } : result;
this.isPartial = isPartial;
this.updateDisplay();
- this.maybeConvertImagesForKitty();
}
appendSentAgentMessage(message: KernelSentAgentMessage): void {
@@ -277,30 +261,6 @@ export class ToolExecutionComponent extends Container {
}
}
- private maybeConvertImagesForKitty(): void {
- if (!this.allowInlineImages) return;
- const caps = getCapabilities();
- if (caps.images !== "kitty") return;
- if (!this.result) return;
-
- const imageBlocks = this.result.content.filter((c) => c.type === "image");
- for (let i = 0; i < imageBlocks.length; i++) {
- const img = imageBlocks[i];
- if (!img.data || !img.mimeType) continue;
- if (img.mimeType === "image/png") continue;
- if (this.convertedImages.has(i)) continue;
-
- const index = i;
- convertToPng(img.data, img.mimeType).then((converted) => {
- if (converted) {
- this.convertedImages.set(index, converted);
- this.updateDisplay();
- this.ui.requestRender();
- }
- });
- }
- }
-
setExpanded(expanded: boolean): void {
this.expanded = expanded;
this.updateDisplay();
@@ -316,22 +276,11 @@ export class ToolExecutionComponent extends Container {
setShowImages(show: boolean): void {
this.showImages = show;
- if (show) {
- this.maybeConvertImagesForKitty();
- }
- this.updateDisplay();
- }
-
- setAllowInlineImages(allow: boolean): void {
- this.allowInlineImages = allow;
- if (allow) {
- this.maybeConvertImagesForKitty();
- }
this.updateDisplay();
}
- setImageWidthCells(width: number): void {
- this.imageWidthCells = Math.max(1, Math.floor(width));
+ setIncludeImageDimensions(include: boolean): void {
+ this.includeImageDimensions = include;
this.updateDisplay();
}
@@ -368,7 +317,6 @@ export class ToolExecutionComponent extends Container {
}
private updateDisplay(): void {
- const renderInlineImages = this.shouldRenderInlineImages();
let hasContent = false;
this.hideComponent = false;
if (this.hasRendererDefinition() && this.getRenderShell() === "self") {
@@ -385,7 +333,7 @@ export class ToolExecutionComponent extends Container {
executionStarted: this.executionStarted,
argsComplete: this.argsComplete,
showExpandHint: this.showExpandHint,
- showImages: renderInlineImages,
+ showImages: this.showImages,
cwd: this.cwd,
};
if (!this.ipythonCellComponent) {
@@ -418,34 +366,24 @@ export class ToolExecutionComponent extends Container {
this.removeChild(img);
}
this.imageComponents = [];
- for (const spacer of this.imageSpacers) {
- this.removeChild(spacer);
- }
- this.imageSpacers = [];
if (this.result) {
const imageBlocks = this.result.content.filter((c) => c.type === "image");
- const caps = getCapabilities();
for (let i = 0; i < imageBlocks.length; i++) {
const img = imageBlocks[i];
- if (caps.images && renderInlineImages && img.data && img.mimeType) {
- const converted = this.convertedImages.get(i);
- const imageData = converted?.data ?? img.data;
- const imageMimeType = converted?.mimeType ?? img.mimeType;
- if (caps.images === "kitty" && imageMimeType !== "image/png") continue;
-
- const spacer = new Spacer(1);
- this.addChild(spacer);
- this.imageSpacers.push(spacer);
- const imageComponent = new Image(
- imageData,
- imageMimeType,
- { fallbackColor: (s: string) => theme.fg("toolOutput", s) },
- { maxWidthCells: this.imageWidthCells },
- );
- this.imageComponents.push(imageComponent);
- this.addChild(imageComponent);
- }
+ if (!this.showImages || !img.data || !img.mimeType) continue;
+
+ const imageComponent = new Image(
+ img.data,
+ img.mimeType,
+ { fallbackColor: (s: string) => theme.fg("toolOutput", s) },
+ {
+ fallbackOnly: true,
+ fallbackPrefix: " ╰─ ",
+ },
+ );
+ this.imageComponents.push(imageComponent);
+ this.addChild(imageComponent);
}
}
@@ -535,8 +473,8 @@ export class ToolExecutionComponent extends Container {
}
private getTextOutput(): string {
- return getRenderedTextOutput(this.result, this.shouldRenderInlineImages(), {
- includeImageDimensions: this.allowInlineImages,
+ return getRenderedTextOutput(this.result, this.showImages, {
+ includeImageDimensions: this.includeImageDimensions,
});
}
diff --git a/packages/coding-agent/src/modes/interactive/interactive-mode.ts b/packages/coding-agent/src/modes/interactive/interactive-mode.ts
index ff3696d0cc..e98c2e3a61 100644
--- a/packages/coding-agent/src/modes/interactive/interactive-mode.ts
+++ b/packages/coding-agent/src/modes/interactive/interactive-mode.ts
@@ -2746,7 +2746,6 @@ export class InteractiveMode {
latestToolCall.arguments,
{
showImages: this.settingsManager.getShowImages(),
- imageWidthCells: this.settingsManager.getImageWidthCells(),
},
toolDefinition,
this.ui,
@@ -5606,7 +5605,6 @@ export class InteractiveMode {
cwd: this.getCurrentCwd(),
toolOptions: {
showImages: this.settingsManager.getShowImages(),
- imageWidthCells: this.settingsManager.getImageWidthCells(),
},
getToolDefinition: (name) => definitions.get(name),
markdownTheme: this.getMarkdownThemeWithSettings(),
@@ -5970,9 +5968,7 @@ export class InteractiveMode {
content.arguments,
{
showImages: this.settingsManager.getShowImages(),
- imageWidthCells: this.settingsManager.getImageWidthCells(),
- // Do not replay historical inline image payloads on session load/rebuild.
- allowInlineImages: false,
+ includeImageDimensions: false,
},
this.getCachedToolDefinition(content.name),
this.ui,
@@ -6016,8 +6012,7 @@ export class InteractiveMode {
}
for (const [toolCallId, component] of renderedPendingTools) {
- // These tool calls have no historical result yet, so future updates are live output.
- component.setAllowInlineImages(true);
+ component.setIncludeImageDimensions(true);
this.pendingTools.set(toolCallId, component);
}
this.ui.requestRender();
@@ -6873,7 +6868,6 @@ export class InteractiveMode {
{
autoCompact: state.autoCompactionEnabled,
showImages: this.settingsManager.getShowImages(),
- imageWidthCells: this.settingsManager.getImageWidthCells(),
autoResizeImages: this.settingsManager.getImageAutoResize(),
blockImages: this.settingsManager.getBlockImages(),
enableSkillCommands: this.settingsManager.getEnableSkillCommands(),
@@ -6912,14 +6906,6 @@ export class InteractiveMode {
}
}
},
- onImageWidthCellsChange: (width) => {
- this.settingsManager.setImageWidthCells(width);
- for (const child of this.chatContainer.children) {
- if (child instanceof ToolExecutionComponent) {
- child.setImageWidthCells(width);
- }
- }
- },
onAutoResizeImagesChange: (enabled) => {
this.settingsManager.setImageAutoResize(enabled);
},
diff --git a/packages/coding-agent/test/interactive-mode-status.test.ts b/packages/coding-agent/test/interactive-mode-status.test.ts
index 045781f82f..b823bd4bd8 100644
--- a/packages/coding-agent/test/interactive-mode-status.test.ts
+++ b/packages/coding-agent/test/interactive-mode-status.test.ts
@@ -261,7 +261,7 @@ describe("InteractiveMode.renderSessionContext", () => {
initTheme("dark");
});
- test("renders historical tool result images as fallbacks instead of replaying inline payloads", async () => {
+ test("does not replay historical tool result image payloads", async () => {
setCapabilities({ images: "kitty", trueColor: true, hyperlinks: true });
try {
const chatContainer = new Container();
@@ -279,7 +279,6 @@ describe("InteractiveMode.renderSessionContext", () => {
preloadToolDefinitions: vi.fn(async () => {}),
settingsManager: {
getShowImages: () => true,
- getImageWidthCells: () => 60,
},
getCachedToolDefinition: () => undefined,
getCurrentCwd: () => process.cwd(),
@@ -310,7 +309,6 @@ describe("InteractiveMode.renderSessionContext", () => {
const rendered = renderAll(chatContainer);
expect(rendered).not.toContain("\x1b_G");
- expect(normalizeRenderedOutput(chatContainer)).toContain("[Image: [image/png]]");
expect(ipythonToolComponents.size).toBe(0);
expect(lateIpythonSentAgentMessages.size).toBe(0);
} finally {
@@ -318,7 +316,7 @@ describe("InteractiveMode.renderSessionContext", () => {
}
});
- test("keeps pending history tool calls eligible for live inline image updates", async () => {
+ test("keeps pending history tool calls metadata-only when live results arrive", async () => {
setCapabilities({ images: "kitty", trueColor: true, hyperlinks: true });
try {
const chatContainer = new Container();
@@ -335,7 +333,6 @@ describe("InteractiveMode.renderSessionContext", () => {
preloadToolDefinitions: vi.fn(async () => {}),
settingsManager: {
getShowImages: () => true,
- getImageWidthCells: () => 60,
},
getCachedToolDefinition: () => undefined,
getCurrentCwd: () => process.cwd(),
@@ -362,7 +359,9 @@ describe("InteractiveMode.renderSessionContext", () => {
expect(component).toBeDefined();
component!.updateResult({ content: [{ type: "image", data: "AAAA", mimeType: "image/png" }], isError: false });
- expect(component!.render(120).join("\n")).toContain("\x1b_G");
+ const rendered = normalizeRenderedOutput(chatContainer);
+ expect(rendered).not.toContain("\x1b_G");
+ expect(rendered).toContain("╰─ [image/png · 800×600]");
} finally {
resetCapabilitiesCache();
}
@@ -1090,7 +1089,6 @@ describe("InteractiveMode tool event rendering", () => {
uiServices: {
settingsManager: {
getShowImages: () => true,
- getImageWidthCells: () => 60,
},
},
toolOutputExpanded: false,
diff --git a/packages/coding-agent/test/settings-selector.test.ts b/packages/coding-agent/test/settings-selector.test.ts
new file mode 100644
index 0000000000..3c01b00c00
--- /dev/null
+++ b/packages/coding-agent/test/settings-selector.test.ts
@@ -0,0 +1,79 @@
+import { resetCapabilitiesCache, setCapabilities } from "@earendil-works/pi-tui";
+import stripAnsi from "strip-ansi";
+import { beforeAll, describe, expect, test } from "vitest";
+import {
+ type SettingsCallbacks,
+ type SettingsConfig,
+ SettingsSelectorComponent,
+} from "../src/modes/interactive/components/settings-selector.js";
+import { initTheme } from "../src/modes/interactive/theme/theme.js";
+
+const config: SettingsConfig = {
+ autoCompact: true,
+ showImages: true,
+ autoResizeImages: true,
+ blockImages: false,
+ enableSkillCommands: true,
+ enableBuiltinSkills: true,
+ steeringMode: "one-at-a-time",
+ followUpMode: "one-at-a-time",
+ transport: "sse",
+ thinkingLevel: "off",
+ availableThinkingLevels: ["off"],
+ currentTheme: "dark",
+ availableThemes: ["dark"],
+ hideThinkingBlock: false,
+ treeFilterMode: "user-only",
+ showHardwareCursor: false,
+ editorPaddingX: 0,
+ autocompleteMaxVisible: 5,
+ quietStartup: false,
+ clearOnShrink: false,
+ showTerminalProgress: false,
+ fullscreen: true,
+ warnings: {},
+};
+
+const callbacks: SettingsCallbacks = {
+ onAutoCompactChange: () => {},
+ onShowImagesChange: () => {},
+ onAutoResizeImagesChange: () => {},
+ onBlockImagesChange: () => {},
+ onEnableSkillCommandsChange: () => {},
+ onEnableBuiltinSkillsChange: () => {},
+ onSteeringModeChange: () => {},
+ onFollowUpModeChange: () => {},
+ onTransportChange: () => {},
+ onThinkingLevelChange: () => {},
+ onThemeChange: () => {},
+ onHideThinkingBlockChange: () => {},
+ onTreeFilterModeChange: () => {},
+ onShowHardwareCursorChange: () => {},
+ onEditorPaddingXChange: () => {},
+ onAutocompleteMaxVisibleChange: () => {},
+ onQuietStartupChange: () => {},
+ onClearOnShrinkChange: () => {},
+ onShowTerminalProgressChange: () => {},
+ onFullscreenChange: () => {},
+ onWarningsChange: () => {},
+ onCancel: () => {},
+};
+
+describe("SettingsSelectorComponent", () => {
+ beforeAll(() => {
+ initTheme("dark");
+ });
+
+ test("shows the image metadata toggle without a terminal graphics protocol", () => {
+ setCapabilities({ images: null, trueColor: true, hyperlinks: true });
+ try {
+ const component = new SettingsSelectorComponent(config, callbacks);
+ const rendered = stripAnsi(component.render(120).join("\n"));
+
+ expect(rendered).toContain("Show image metadata");
+ expect(rendered).toContain("Auto-resize images");
+ } finally {
+ resetCapabilitiesCache();
+ }
+ });
+});
diff --git a/packages/coding-agent/test/suite/regressions/4167-thinking-toggle-pending-tool-render.test.ts b/packages/coding-agent/test/suite/regressions/4167-thinking-toggle-pending-tool-render.test.ts
index 62b4a55667..edf99f85f7 100644
--- a/packages/coding-agent/test/suite/regressions/4167-thinking-toggle-pending-tool-render.test.ts
+++ b/packages/coding-agent/test/suite/regressions/4167-thinking-toggle-pending-tool-render.test.ts
@@ -42,7 +42,6 @@ type RenderSessionContextThis = {
ui: TUI;
settingsManager: {
getShowImages(): boolean;
- getImageWidthCells(): number;
};
toolOutputExpanded: boolean;
isInitialized: boolean;
@@ -86,7 +85,6 @@ function createFakeInteractiveModeThis(): RenderSessionContextThis {
ui: { requestRender: vi.fn() } as unknown as TUI,
settingsManager: {
getShowImages: () => false,
- getImageWidthCells: () => 60,
},
toolOutputExpanded: false,
isInitialized: true,
diff --git a/packages/coding-agent/test/suite/regressions/4529-leading-newline-bash-cell.test.ts b/packages/coding-agent/test/suite/regressions/4529-leading-newline-bash-cell.test.ts
index 529ab7925b..f13fa907d3 100644
--- a/packages/coding-agent/test/suite/regressions/4529-leading-newline-bash-cell.test.ts
+++ b/packages/coding-agent/test/suite/regressions/4529-leading-newline-bash-cell.test.ts
@@ -63,7 +63,7 @@ describe("ENG-4529 leading newline before %%bash", () => {
start.toolName,
start.toolCallId,
start.args,
- { allowInlineImages: false },
+ {},
undefined,
{ requestRender: vi.fn() } as unknown as TUI,
harness.tempDir,
diff --git a/packages/coding-agent/test/suite/regressions/4583-latest-tool-expand-hint.test.ts b/packages/coding-agent/test/suite/regressions/4583-latest-tool-expand-hint.test.ts
index 0a0bd43c63..f4da578caf 100644
--- a/packages/coding-agent/test/suite/regressions/4583-latest-tool-expand-hint.test.ts
+++ b/packages/coding-agent/test/suite/regressions/4583-latest-tool-expand-hint.test.ts
@@ -53,7 +53,7 @@ describe("ENG-4583 latest tool expand hint", () => {
const components = buildConversationComponents(harness.session.messages, {
ui: { requestRender: vi.fn() } as unknown as TUI,
cwd: harness.tempDir,
- toolOptions: { allowInlineImages: false },
+ toolOptions: {},
getToolDefinition: () => undefined,
});
const tools = components.filter(
diff --git a/packages/coding-agent/test/tool-execution-component.test.ts b/packages/coding-agent/test/tool-execution-component.test.ts
index 620e40369a..92ee08403a 100644
--- a/packages/coding-agent/test/tool-execution-component.test.ts
+++ b/packages/coding-agent/test/tool-execution-component.test.ts
@@ -1,7 +1,8 @@
-import { resetCapabilitiesCache, setCapabilities, Text, type TUI } from "@earendil-works/pi-tui";
+import { Container, resetCapabilitiesCache, setCapabilities, Text, TUI } from "@earendil-works/pi-tui";
import stripAnsi from "strip-ansi";
import { Type } from "typebox";
import { beforeAll, describe, expect, test } from "vitest";
+import { VirtualTerminal } from "../../tui/test/virtual-terminal.js";
import type { ToolDefinition } from "../src/core/extensions/types.js";
import { type BashOperations, createBashTool, createBashToolDefinition } from "../src/core/tools/bash.js";
import { createEditToolDefinition } from "../src/core/tools/edit.js";
@@ -37,14 +38,6 @@ function createMetadataOnlyToolDefinition(definition: ToolDefinition<any, any>)
return metadata;
}
-async function waitForCondition(condition: () => boolean): Promise<void> {
- for (let i = 0; i < 50; i++) {
- if (condition()) return;
- await new Promise((resolve) => setTimeout(resolve, 10));
- }
- throw new Error("condition was not met");
-}
-
describe("ToolExecutionComponent parity", () => {
beforeAll(() => {
initTheme("dark");
@@ -82,7 +75,151 @@ describe("ToolExecutionComponent parity", () => {
expect(rendered).toContain("custom result");
});
- test("suppressed history image fallbacks skip dimension parsing", () => {
+ test.each(["kitty", null] as const)("renders one compact image metadata row for %s capability", (protocol) => {
+ setCapabilities({ images: protocol, trueColor: true, hyperlinks: true });
+ try {
+ const component = new ToolExecutionComponent(
+ "custom_tool",
+ "tool-image-default",
+ {},
+ { showImages: true },
+ undefined,
+ createFakeTui(),
+ process.cwd(),
+ );
+ component.updateResult({ content: [{ type: "image", data: "AAAA", mimeType: "image/png" }], isError: false });
+
+ const rendered = stripAnsi(component.render(120).join("\n"));
+ expect(rendered).not.toContain("\x1b_G");
+ expect(rendered).toContain(" ╰─ [image/png · 800×600]");
+ expect(rendered.match(/image\/png/g)).toHaveLength(1);
+ } finally {
+ resetCapabilitiesCache();
+ }
+ });
+
+ test("keeps image metadata escape-free across visibility toggles", () => {
+ setCapabilities({ images: "kitty", trueColor: true, hyperlinks: true });
+ try {
+ const component = new ToolExecutionComponent(
+ "custom_tool",
+ "tool-image-history",
+ {},
+ { showImages: true, includeImageDimensions: false },
+ undefined,
+ createFakeTui(),
+ process.cwd(),
+ );
+ component.updateResult({ content: [{ type: "image", data: "AAAA", mimeType: "image/png" }], isError: false });
+
+ let rendered = component.render(120).join("\n");
+ expect(rendered).not.toContain("\x1b_G");
+ const fallbackLines = stripAnsi(rendered).split("\n");
+ const fallbackIndex = fallbackLines.findIndex((line) => line.includes("[image/png"));
+ expect(fallbackIndex).toBeGreaterThan(0);
+ expect(fallbackLines[fallbackIndex - 1]?.trim()).not.toBe("");
+
+ component.setShowImages(false);
+ component.setShowImages(true);
+ rendered = component.render(120).join("\n");
+ expect(rendered).not.toContain("\x1b_G");
+ } finally {
+ resetCapabilitiesCache();
+ }
+ });
+ test("does not duplicate replayed image fallbacks through built-in renderers", () => {
+ setCapabilities({ images: "kitty", trueColor: true, hyperlinks: true });
+ try {
+ const component = new ToolExecutionComponent(
+ "bash",
+ "tool-bash-image-history",
+ { command: "generate-image" },
+ { showImages: true, includeImageDimensions: false },
+ undefined,
+ createFakeTui(),
+ process.cwd(),
+ );
+ component.updateResult({ content: [{ type: "image", data: "AAAA", mimeType: "image/png" }], isError: false });
+
+ const rendered = stripAnsi(component.render(120).join("\n"));
+ expect(rendered.match(/image\/png/g)).toHaveLength(1);
+ } finally {
+ resetCapabilitiesCache();
+ }
+ });
+
+ test.each(["kitty", "iterm2", null] as const)(
+ "keeps one visible IPython image row without emitting terminal graphics for %s capability",
+ (protocol) => {
+ setCapabilities({ images: protocol, trueColor: true, hyperlinks: true });
+ try {
+ const component = new ToolExecutionComponent(
+ "ipython",
+ `tool-ipython-image-${protocol}`,
+ { code: "display(image)" },
+ { showImages: true, includeImageDimensions: false },
+ undefined,
+ createFakeTui(),
+ process.cwd(),
+ );
+ component.setExpanded(true);
+ component.updateResult(
+ {
+ content: [{ type: "image", data: "AAAA", mimeType: "image/png" }],
+ isError: false,
+ },
+ false,
+ );
+
+ const rendered = component.render(120).join("\n");
+ expect(rendered).not.toContain("\x1b_G");
+ expect(rendered).not.toContain("\x1b]1337;File=");
+ const lines = stripAnsi(rendered).split("\n");
+ expect(lines.filter((line) => line.includes("╰─ [image/png")).length).toBe(1);
+ } finally {
+ resetCapabilitiesCache();
+ }
+ },
+ );
+
+ test("uses the compact fallback for a live IPython image in fullscreen", async () => {
+ setCapabilities({ images: "kitty", trueColor: true, hyperlinks: true });
+ const terminal = new VirtualTerminal(120, 12);
+ const tui = new TUI(terminal);
+ try {
+ const transcript = new Container();
+ const dock = new Text("> prompt", 0, 0);
+ const component = new ToolExecutionComponent(
+ "ipython",
+ "tool-ipython-image-fullscreen",
+ { code: "display(image)" },
+ { showImages: true },
+ undefined,
+ tui,
+ process.cwd(),
+ );
+ component.setExpanded(true);
+ component.updateResult(
+ { content: [{ type: "image", data: "AAAA", mimeType: "image/png" }], isError: false },
+ false,
+ );
+ transcript.addChild(component);
+ tui.addChild(transcript);
+ tui.addChild(dock);
+ tui.start();
+ tui.enterFullscreen({ scroll: [transcript], dock });
+ await terminal.waitForRender();
+
+ const viewport = terminal.getViewport();
+ expect(viewport.filter((line) => line.includes(" ╰─ [image/png · 800×600]")).length).toBe(1);
+ expect(viewport.join("\n")).not.toContain("\x1b_G");
+ } finally {
+ tui.stop();
+ resetCapabilitiesCache();
+ }
+ });
+
+ test("historical image fallbacks include dimensions", () => {
setCapabilities({ images: "kitty", trueColor: true, hyperlinks: true });
try {
const onePixelPng =
@@ -91,7 +228,7 @@ describe("ToolExecutionComponent parity", () => {
"custom_tool",
"tool-image-history-dims",
{},
- { showImages: true, allowInlineImages: false },
+ { showImages: true, includeImageDimensions: false },
undefined,
createFakeTui(),
process.cwd(),
@@ -102,14 +239,38 @@ describe("ToolExecutionComponent parity", () => {
});
const rendered = stripAnsi(component.render(120).join("\n"));
- expect(rendered).toContain("[Image: [image/png]]");
- expect(rendered).not.toContain("1x1");
+ expect(rendered).toContain(" ╰─ [image/png · 1×1]");
} finally {
resetCapabilitiesCache();
}
});
- test("converts kitty images even if image display is toggled off when the result arrives", async () => {
+ test("pending history components remain metadata-only when restored to live output", () => {
+ setCapabilities({ images: "kitty", trueColor: true, hyperlinks: true });
+ try {
+ const component = new ToolExecutionComponent(
+ "custom_tool",
+ "tool-image-pending-history",
+ {},
+ { showImages: true, includeImageDimensions: false },
+ undefined,
+ createFakeTui(),
+ process.cwd(),
+ );
+ component.updateResult({ content: [{ type: "image", data: "AAAA", mimeType: "image/png" }], isError: false });
+ expect(component.render(120).join("\n")).not.toContain("\x1b_G");
+
+ component.setIncludeImageDimensions(true);
+
+ const rendered = stripAnsi(component.render(120).join("\n"));
+ expect(rendered).not.toContain("\x1b_G");
+ expect(rendered).toContain(" ╰─ [image/png · 800×600]");
+ } finally {
+ resetCapabilitiesCache();
+ }
+ });
+
+ test("preserves original image metadata when display is toggled back on", () => {
setCapabilities({ images: "kitty", trueColor: true, hyperlinks: true });
try {
const tinyJpeg =
@@ -128,10 +289,11 @@ describe("ToolExecutionComponent parity", () => {
isError: false,
});
- await waitForCondition(() => (component as any).convertedImages.size === 1);
component.setShowImages(true);
- expect(component.render(120).join("\n")).toContain("\x1b_G");
+ const rendered = stripAnsi(component.render(120).join("\n"));
+ expect(rendered).not.toContain("\x1b_G");
+ expect(rendered).toContain(" ╰─ [image/jpeg · 2×2]");
} finally {
resetCapabilitiesCache();
}
diff --git a/packages/tui/CHANGELOG.md b/packages/tui/CHANGELOG.md
index 997b4e5cdc..4a22352815 100644
--- a/packages/tui/CHANGELOG.md
+++ b/packages/tui/CHANGELOG.md
@@ -2,6 +2,7 @@
## [Unreleased]
+- Removed the fullscreen image fallback instruction and kept fullscreen overlays from emitting terminal graphics ([#437](https://github.com/PrimeIntellect-ai/prime-agent/pull/437) by [@snimu](https://github.com/snimu)).
- Changed the fullscreen follow shortcut from `Alt+Down` to `Ctrl+Shift+Down` for more reliable terminal input ([ENG-4684](https://linear.app/primeintellect/issue/ENG-4684/altdown-doesnt-work)).
- Fixed autocomplete popups overlapping the prompt's top edge.
diff --git a/packages/tui/README.md b/packages/tui/README.md
index f57f24cd57..c28647549b 100644
--- a/packages/tui/README.md
+++ b/packages/tui/README.md
@@ -25,7 +25,7 @@ Minimal terminal UI framework with differential rendering and synchronized outpu
- **Component-based**: Simple Component interface with render() method
- **Theme Support**: Components accept theme interfaces for customizable styling
- **Built-in Components**: Text, TruncatedText, Input, Editor, Markdown, Loader, SelectList, SettingsList, Spacer, Image, Box, Container
-- **Inline Images**: Renders images in terminals that support Kitty or iTerm2 graphics protocols
+- **Image Support**: Renders terminal graphics or compact image metadata
- **Autocomplete Support**: File paths and slash commands
## Quick Start
@@ -514,7 +514,7 @@ const spacer = new Spacer(2); // 2 empty lines (default: 1)
### Image
-Renders images inline for terminals that support the Kitty graphics protocol (Kitty, Ghostty, WezTerm) or iTerm2 inline images. Falls back to a text placeholder on unsupported terminals.
+Renders Kitty or iTerm2 terminal graphics when supported. Set `fallbackOnly: true` to show compact image metadata instead; Prime Agent uses this metadata-only mode.
```typescript
interface ImageTheme {
@@ -525,6 +525,7 @@ interface ImageOptions {
maxWidthCells?: number;
maxHeightCells?: number;
filename?: string;
+ fallbackOnly?: boolean;
}
const image = new Image(
diff --git a/packages/tui/src/components/image.ts b/packages/tui/src/components/image.ts
index 74992b342e..8678cc211c 100644
--- a/packages/tui/src/components/image.ts
+++ b/packages/tui/src/components/image.ts
@@ -8,6 +8,18 @@ import {
} from "../terminal-image.js";
import type { Component } from "../tui.js";
+let fullscreenFallback = false;
+
+export function withFullscreenImageFallback<T>(render: () => T): T {
+ const previous = fullscreenFallback;
+ fullscreenFallback = true;
+ try {
+ return render();
+ } finally {
+ fullscreenFallback = previous;
+ }
+}
+
export interface ImageTheme {
fallbackColor: (str: string) => string;
}
@@ -16,6 +28,9 @@ export interface ImageOptions {
maxWidthCells?: number;
maxHeightCells?: number;
filename?: string;
+ /** Render metadata instead of terminal graphics. */
+ fallbackOnly?: boolean;
+ fallbackPrefix?: string;
/** Kitty image ID. If provided, reuses this ID (for animations/updates). */
imageId?: number;
}
@@ -30,6 +45,7 @@ export class Image implements Component {
private cachedLines?: string[];
private cachedWidth?: number;
+ private cachedFullscreenFallback?: boolean;
constructor(
base64Data: string,
@@ -54,10 +70,11 @@ export class Image implements Component {
invalidate(): void {
this.cachedLines = undefined;
this.cachedWidth = undefined;
+ this.cachedFullscreenFallback = undefined;
}
render(width: number): string[] {
- if (this.cachedLines && this.cachedWidth === width) {
+ if (this.cachedLines && this.cachedWidth === width && this.cachedFullscreenFallback === fullscreenFallback) {
return this.cachedLines;
}
@@ -66,7 +83,12 @@ export class Image implements Component {
const caps = getCapabilities();
let lines: string[];
- if (caps.images) {
+ if (fullscreenFallback || this.options.fallbackOnly === true) {
+ const parts = [this.mimeType];
+ parts.push(`${this.dimensions.widthPx}×${this.dimensions.heightPx}`);
+ if (this.options.filename) parts.unshift(this.options.filename);
+ lines = [this.theme.fallbackColor(`${this.options.fallbackPrefix ?? ""}[${parts.join(" · ")}]`)];
+ } else if (caps.images) {
if (caps.images === "kitty" && this.imageId === undefined) {
this.imageId = allocateImageId();
}
@@ -106,6 +128,7 @@ export class Image implements Component {
this.cachedLines = lines;
this.cachedWidth = width;
+ this.cachedFullscreenFallback = fullscreenFallback;
return lines;
}
diff --git a/packages/tui/src/tui.ts b/packages/tui/src/tui.ts
index 103edbb916..32655a68bc 100644
--- a/packages/tui/src/tui.ts
+++ b/packages/tui/src/tui.ts
@@ -6,6 +6,7 @@ import * as fs from "node:fs";
import * as os from "node:os";
import * as path from "node:path";
import { performance } from "node:perf_hooks";
+import { withFullscreenImageFallback } from "./components/image.js";
import { FullscreenViewport, type ScrollInfo, type SelectionScrollDirection } from "./fullscreen.js";
import { getKeybindings } from "./keybindings.js";
import { isKeyRelease, matchesKey } from "./keys.js";
@@ -1424,22 +1425,22 @@ export class TUI extends Container {
const transcript: string[] = [];
const selectionRegions: TableCellSelectionRegion[] = [];
- for (const component of fullscreen.scroll) {
- const lineOffset = transcript.length;
- const componentLines = component.render(width);
- for (const region of component.getSelectionRegions?.() ?? []) {
- selectionRegions.push({
- ...region,
- line: region.line + lineOffset,
- tableTop: region.tableTop + lineOffset,
- tableBottom: region.tableBottom + lineOffset,
- });
- }
- for (const line of componentLines) {
- transcript.push(line);
+ const dock = withFullscreenImageFallback(() => {
+ for (const component of fullscreen.scroll) {
+ const lineOffset = transcript.length;
+ const componentLines = component.render(width);
+ for (const region of component.getSelectionRegions?.() ?? []) {
+ selectionRegions.push({
+ ...region,
+ line: region.line + lineOffset,
+ tableTop: region.tableTop + lineOffset,
+ tableBottom: region.tableBottom + lineOffset,
+ });
+ }
+ transcript.push(...componentLines);
}
- }
- const dock = fullscreen.dock.render(width);
+ return fullscreen.dock.render(width);
+ });
let frame = fullscreen.viewport.composeFrame(transcript, dock, height, selectionRegions);
this.overlaySelectionRegions.push(
@@ -1459,7 +1460,7 @@ export class TUI extends Container {
}
}
if (this.overlayStack.length > 0) {
- frame = this.compositeOverlays(frame, width, height);
+ frame = withFullscreenImageFallback(() => this.compositeOverlays(frame, width, height));
}
const cursorPos = this.extractCursorPosition(frame, height);
fullscreen.viewport.applyFrameSelection(frame, height, this.overlaySelectionRegions);
diff --git a/packages/tui/test/fullscreen.test.ts b/packages/tui/test/fullscreen.test.ts
index a04609f930..6b738cbd9b 100644
--- a/packages/tui/test/fullscreen.test.ts
+++ b/packages/tui/test/fullscreen.test.ts
@@ -1,8 +1,10 @@
import assert from "node:assert";
import { describe, it } from "node:test";
import { Box } from "../src/components/box.js";
+import { Image } from "../src/components/image.js";
import { Markdown } from "../src/components/markdown.js";
import type { TerminalStopOptions } from "../src/terminal.js";
+import { resetCapabilitiesCache, setCapabilities, setCellDimensions } from "../src/terminal-image.js";
import { type Component, Container, TUI } from "../src/tui.js";
import { defaultMarkdownTheme } from "./test-themes.js";
import { VirtualTerminal } from "./virtual-terminal.js";
@@ -122,6 +124,95 @@ describe("TUI fullscreen mode", () => {
tui.stop();
});
+ it("renders terminal images as compact metadata fallbacks", async () => {
+ setCapabilities({ images: "kitty", trueColor: true, hyperlinks: true });
+ setCellDimensions({ widthPx: 10, heightPx: 10 });
+ try {
+ const { terminal, tui, chat, dock } = setup(["before"], 80);
+ const image = new Image(
+ "AAAA",
+ "image/png",
+ { fallbackColor: (value) => value },
+ {},
+ { widthPx: 120, heightPx: 80 },
+ );
+ tui.enterFullscreen({ scroll: [chat, image], dock });
+ await terminal.waitForRender();
+
+ const viewport = terminal.getViewport();
+ const imageRow = viewport.indexOf("[image/png · 120×80]");
+ assert.strictEqual(viewport.indexOf("before") + 1, imageRow);
+ assert.strictEqual(viewport.filter((line) => line.includes("/fullscreen off to view")).length, 0);
+ assert.ok(!terminal.getWrites().includes("\x1b_G"));
+
+ tui.stop();
+ } finally {
+ resetCapabilitiesCache();
+ setCellDimensions({ widthPx: 9, heightPx: 18 });
+ }
+ });
+
+ it("restores inline rendering after leaving fullscreen", async () => {
+ setCapabilities({ images: "kitty", trueColor: true, hyperlinks: true });
+ setCellDimensions({ widthPx: 10, heightPx: 10 });
+ try {
+ const terminal = new LoggingVirtualTerminal(80, 10);
+ const tui = new TUI(terminal);
+ const image = new Image(
+ "AAAA",
+ "image/png",
+ { fallbackColor: (value) => value },
+ { maxWidthCells: 2, fallbackOnly: false },
+ { widthPx: 20, heightPx: 20 },
+ );
+ const dock = new TestComponent();
+ dock.lines = ["> prompt"];
+ tui.addChild(image);
+ tui.start();
+ await terminal.waitForRender();
+ assert.ok(terminal.getWrites().includes("\x1b_G"));
+
+ tui.enterFullscreen({ scroll: [image], dock });
+ await terminal.waitForRender();
+ assert.ok(terminal.getViewport().includes("[image/png · 20×20]"));
+
+ tui.exitFullscreen({ flush: false });
+ assert.strictEqual(image.render(80).length, 2);
+ assert.ok(image.render(80).some((line) => line.includes("\x1b_G")));
+
+ tui.stop();
+ } finally {
+ resetCapabilitiesCache();
+ setCellDimensions({ widthPx: 9, heightPx: 18 });
+ }
+ });
+
+ it("uses compact metadata for images in fullscreen overlays", async () => {
+ setCapabilities({ images: "kitty", trueColor: true, hyperlinks: true });
+ try {
+ const { terminal, tui, chat, dock } = setup(["history"], 80);
+ tui.enterFullscreen({ scroll: [chat], dock });
+ tui.showOverlay(
+ new Image(
+ "AAAA",
+ "image/png",
+ { fallbackColor: (value) => value },
+ { fallbackOnly: false },
+ { widthPx: 20, heightPx: 20 },
+ ),
+ { width: 30 },
+ );
+ await terminal.waitForRender();
+
+ assert.ok(!terminal.getWrites().includes("\x1b_G"));
+ assert.ok(terminal.getViewport().some((line) => line.includes("[image/png · 20×20]")));
+
+ tui.stop();
+ } finally {
+ resetCapabilitiesCache();
+ }
+ });
+
it("keeps the window pinned to the bottom while following", async () => {
const { terminal, tui, chat, dock } = setup(lines(20));
tui.enterFullscreen({ scroll: [chat], dock });
diff --git a/packages/tui/test/terminal-image.test.ts b/packages/tui/test/terminal-image.test.ts
index 58e018d25a..137deec33e 100644
--- a/packages/tui/test/terminal-image.test.ts
+++ b/packages/tui/test/terminal-image.test.ts
@@ -336,6 +336,23 @@ describe("Kitty image cursor movement", () => {
setCellDimensions({ widthPx: 9, heightPx: 18 });
}
});
+
+ it("keeps compact metadata and its prefix when terminal graphics are unavailable", () => {
+ setCapabilities({ images: null, trueColor: true, hyperlinks: true });
+ try {
+ const image = new Image(
+ "AAAA",
+ "image/png",
+ { fallbackColor: (value) => value },
+ { filename: "result.png", fallbackOnly: true, fallbackPrefix: " ╰─ " },
+ { widthPx: 20, heightPx: 10 },
+ );
+
+ assert.deepStrictEqual(image.render(80), [" ╰─ [result.png · image/png · 20×10]"]);
+ } finally {
+ resetCapabilitiesCache();
+ }
+ });
});
describe("hyperlink", () => {