Skip to content

feat(terminal): support inline images - #11706

Closed
XRX193 wants to merge 7 commits into
stablyai:mainfrom
XRX193:fix/terminal-inline-images
Closed

XRX193 wants to merge 7 commits into
stablyai:mainfrom
XRX193:fix/terminal-inline-images

Conversation

@XRX193

@XRX193 XRX193 commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add the official xterm image addon to terminal panes so Orca can render Kitty graphics and iTerm2 inline-image sequences.
  • Enable cell/window size reports used by image-capable TUIs.
  • Bound untrusted terminal image payloads to 8 MB, decoded images to 4,194,304 pixels, and retained image storage to 16 MB per pane.
  • Dispose image storage with the pane and add focused creation/lifecycle regression coverage.

Fixes #11668.

Screenshots

Not included. This change renders protocol output inside the existing terminal surface; the Electron renderer bundle and addon lifecycle are covered below, but the current Pi/Kimi releases do not emit image sequences for TERM_PROGRAM=Orca yet (see Notes).

Testing

  • pnpm lint - code-quality, type-aware, reliability, and max-lines gates passed; the command stopped on pre-existing stale generated skill manifests.
  • pnpm typecheck
  • pnpm test - 36/36 focused tests passed. The full suite hit the 15-minute limit with unrelated environment failures (restricted Electron download/network access, unavailable WSL, and denied system-directory writes).
  • pnpm build - pnpm build:electron-vite passed; native/release targets were not run.
  • Added or updated high-quality tests that would catch regressions, or explained why tests were not needed

AI Review Report

Reviewed addon ownership, activation order, pane disposal, memory pressure, protocol scope, renderer bundling, and the capability negotiation used by Pi Code and Kimi Code. The review rejected globally spoofing Kitty/Ghostty environment variables because they could enable unrelated terminal-specific behavior. Instead, Orca keeps its existing TERM_PROGRAM=Orca identity and the client allowlists need a small compatibility follow-up.

Cross-platform review covered macOS, Linux, and Windows. This PR is renderer-only and adds no shortcut, label, path, shell, PTY-provider, or Electron platform branch. Local, SSH, WSL, and relay terminals all feed the same pane renderer, so protocol parsing is shared across execution hosts.

Security Audit

Terminal output is untrusted input. The addon is the official xterm implementation rather than a custom decoder, SIXEL is disabled because it is outside this issue, sequence payloads are capped at 8 MB, decoded images at roughly 4 million pixels, and retained storage at 16 MB per pane with FIFO eviction. Image storage is explicitly disposed when a pane closes.

No command execution, filesystem path handling, IPC, authentication, credentials, secrets, or network requests were added.

Notes

Orca keeps its existing TERM_PROGRAM=Orca identity and does not set KITTY_WINDOW_ID or impersonate another terminal. Client-side compatibility is tracked by verified follow-ups:

  • Kimi Code: MoonshotAI/kimi-code#2454 recognizes Orca as Kitty-graphics capable. Its pi-tui suite passes 716/716 tests and type-checks.
  • Pi: earendil-works/pi#7357 requests the required new-contributor approval. The implementation is already available at XRX193/pi@f23e2c3; the focused regression test and pi-tui build pass. A PR will be opened after the required maintainer lgtm.

@greptile-apps

greptile-apps Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR adds inline image support to Orca's terminal panes by integrating the official @xterm/addon-image package, enabling Kitty graphics protocol and iTerm2 inline image (IIP) sequences. All three PTY spawn paths (daemon subprocess, local provider, relay handler) are updated to export ORCA_IMAGE_PROTOCOL=kitty, and the renderer is updated to create, load, and dispose an ImageAddon per pane with explicit memory limits.

  • Addon lifecycle: ImageAddon is instantiated in createPaneDOM with configured safety bounds (8 MB per payload, 4 MP pixel limit, 16 MB storage per pane with FIFO eviction), loaded in openTerminal, and disposed in disposePane following the same try/catch pattern used by all other addons.
  • Environment advertisement: ORCA_IMAGE_PROTOCOL: 'kitty' is injected into the PTY environment in pty-subprocess.ts, local-pty-provider.ts, and pty-handler.ts, allowing image-capable TUIs to detect Kitty graphics support without impersonating KITTY_WINDOW_ID or another terminal.
  • Tests: New focused tests verify the addon options, load order, and disposal on pane close across pane-dom-creation.test.ts and pane-lifecycle.test.ts, plus env-var assertions in all three PTY provider test files.

Confidence Score: 5/5

Safe to merge. Changes are renderer-only and additive: a new xterm addon is instantiated per pane with explicit memory bounds and disposed on pane close, and an environment variable is injected into all three PTY spawn paths to advertise capability to TUIs.

All three PTY spawn paths are consistently updated. The ImageAddon follows the same creation/load/dispose lifecycle pattern as every other addon in the codebase. Memory is bounded at multiple layers (per-image payload cap, pixel limit, per-pane FIFO storage cap). SIXEL is explicitly disabled. Test coverage verifies the constructor options, load order, and disposal. No IPC, authentication, filesystem, or network code was touched.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
src/renderer/src/lib/pane-manager/pane-dom-creation.ts Adds ImageAddon instantiation with bounded options (8 MB payload cap, 4 MP pixels, 16 MB storage, FIFO eviction). SIXEL is explicitly disabled. The addon is always created and assigned to the pane object.
src/renderer/src/lib/pane-manager/pane-lifecycle.ts Loads imageAddon after terminal.open() and before WebGL attachment (consistent with other addon ordering). Disposes it in disposePane() using the same try/catch pattern as all other addons.
src/renderer/src/lib/pane-manager/pane-manager-types.ts Adds optional imageAddon?: ImageAddon to ManagedPaneInternal. Not surfaced on the public ManagedPane type, consistent with webglAddon and ligaturesAddon.
src/main/providers/local-pty-provider.ts Adds ORCA_IMAGE_PROTOCOL: 'kitty' to the PTY spawn environment. Consistent with the other two spawn paths.
src/main/daemon/pty-subprocess.ts Adds ORCA_IMAGE_PROTOCOL: 'kitty' to the daemon subprocess environment, advertising Kitty graphics capability to TUIs running under the daemon path.
src/relay/pty-handler.ts Adds ORCA_IMAGE_PROTOCOL: 'kitty' to the relay PTY spawn environment, completing the three-path coverage for the environment variable advertisement.
src/renderer/src/lib/pane-manager/pane-lifecycle.test.ts New test verifies loadAddon:image is called during openTerminal and that imageAddon.dispose() is called exactly once on pane disposal.
src/renderer/src/lib/pane-manager/pane-dom-creation.test.ts New test verifies that all ImageAddon constructor options match the intended bounds (pixelLimit, storageLimit, size caps, sixelSupport: false, iipSupport: true, kittySupport: true).

Sequence Diagram

sequenceDiagram
    participant Shell as Shell / TUI
    participant PTY as PTY Provider
    participant Renderer as Renderer createPaneDOM
    participant xterm as xterm.js Terminal
    participant ImageAddon as ImageAddon

    PTY->>Shell: "spawn(env: {ORCA_IMAGE_PROTOCOL: 'kitty', ...})"
    Note over Shell: TUI detects Kitty graphics support

    Renderer->>ImageAddon: "new ImageAddon({pixelLimit, storageLimit, kittySizeLimit, iipSizeLimit, ...})"
    Renderer->>xterm: new Terminal(opts)

    Renderer->>xterm: terminal.open(xtermContainer)
    Renderer->>xterm: loadAddon(fitAddon)
    Renderer->>xterm: loadAddon(imageAddon)
    Renderer->>xterm: loadAddon(searchAddon, ...)
    Renderer->>xterm: attachWebgl(pane)

    Shell-->>xterm: Kitty / iTerm2 image escape sequences
    xterm->>ImageAddon: decode and render (RGBA canvas overlay)
    Note over ImageAddon: Bounded: 8MB payload, 4MP pixels, 16MB/pane FIFO

    Note over Renderer: On pane close
    Renderer->>ImageAddon: imageAddon.dispose()
    Renderer->>xterm: terminal.dispose()
Loading

Reviews (2): Last reviewed commit: "fix(terminal): advertise inline image ca..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 64514f8e-38ca-4ed4-bac1-3cb5ca1fa0f5

📥 Commits

Reviewing files that changed from the base of the PR and between 4221f8d and 9421530.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (12)
  • package.json
  • src/main/daemon/pty-subprocess.test.ts
  • src/main/daemon/pty-subprocess.ts
  • src/main/providers/local-pty-provider.test.ts
  • src/main/providers/local-pty-provider.ts
  • src/relay/pty-handler.test.ts
  • src/relay/pty-handler.ts
  • src/renderer/src/lib/pane-manager/pane-dom-creation.test.ts
  • src/renderer/src/lib/pane-manager/pane-dom-creation.ts
  • src/renderer/src/lib/pane-manager/pane-lifecycle.test.ts
  • src/renderer/src/lib/pane-manager/pane-lifecycle.ts
  • src/renderer/src/lib/pane-manager/pane-manager-types.ts
🚧 Files skipped from review as they are similar to previous changes (12)
  • package.json
  • src/relay/pty-handler.ts
  • src/relay/pty-handler.test.ts
  • src/main/daemon/pty-subprocess.ts
  • src/renderer/src/lib/pane-manager/pane-dom-creation.test.ts
  • src/renderer/src/lib/pane-manager/pane-lifecycle.ts
  • src/renderer/src/lib/pane-manager/pane-lifecycle.test.ts
  • src/renderer/src/lib/pane-manager/pane-dom-creation.ts
  • src/main/providers/local-pty-provider.ts
  • src/main/daemon/pty-subprocess.test.ts
  • src/renderer/src/lib/pane-manager/pane-manager-types.ts
  • src/main/providers/local-pty-provider.test.ts

📝 Walkthrough

Walkthrough

Adds @xterm/addon-image and stores a configured image addon on each managed pane. The addon enables bounded Kitty and iTerm2 image support, placeholders, and configured pixel and storage limits while disabling Sixel support. openTerminal loads the addon when present. disposePane disposes the addon and ignores disposal errors. PTY environments now set ORCA_IMAGE_PROTOCOL=kitty. Tests cover addon configuration, lifecycle handling, and PTY environment values.

Merge Risk: ⚪ Minimal · up to 94215

This change adds inline image support with bounded payloads, decoded image sizes, retained storage, and pane cleanup; no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding inline image support to the terminal.
Description check ✅ Passed The description explains the change, rationale, linked issue, testing, security, compatibility, and review considerations; only minor template sections are absent.
Linked Issues check ✅ Passed The changes address issue #11668 by adding Kitty and iTerm2 image rendering, protocol configuration, resource limits, pane cleanup, and regression tests.
Out of Scope Changes check ✅ Passed All reviewed changes support inline image rendering, protocol setup, resource management, or focused regression coverage.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Checkov (3.3.9)
package.json

Checkov timed out on this file


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@AmethystLiang

Copy link
Copy Markdown
Contributor

thanks for the PR. will review it. since it touches terminal, it will have a longer review time as we ensure it doesn't cause any functionality or performance regression for the terminal

@XRX193

XRX193 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

The linked-issue compatibility warning now has verified client follow-ups: MoonshotAI/kimi-code#2454 is open with 716/716 pi-tui tests passing, and earendil-works/pi#7357 links the tested Pi implementation while its required contributor approval is pending. Both preserve TERM_PROGRAM=Orca and enable Kitty image output client-side.

@coderabbitai

coderabbitai Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

@XRX193 I will review the current changes, including the terminal image addon lifecycle and the stated client compatibility follow-ups.

✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderredlab

Copy link
Copy Markdown

Thanks for working on this. This PR would directly unblock an important part of my Orca workflow. I use Orca on both Windows and macOS for coding-agent sessions, where screenshots, generated assets, and UI/debugging output need to be reviewed inline.

I’d be happy to test a build of this branch on both platforms, including image sizing, scrolling, repeated image output, and pane lifecycle behavior, if that would help move the review forward.

@mmarabel mmarabel mentioned this pull request Aug 6, 2026
4 of 5 tasks
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/providers/local-pty-provider.ts (1)

671-681: 🗄️ Data Integrity & Integration | 🟠 Major

Preserve the Kitty image protocol contract across PTY builders.

ORCA_IMAGE_PROTOCOL=kitty is not immutable in the current builders: caller/env hook values can replace it. Local, relay, and daemon PTYs should either reapply this marker after every environment hook or reject overrides for this key.
[low_effort_andhigh_reward]


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4a7a4031-5ae8-49e0-a308-0a8d83c1a584

📥 Commits

Reviewing files that changed from the base of the PR and between 7e60b33 and fafd8c1.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (12)
  • package.json
  • src/main/daemon/pty-subprocess.test.ts
  • src/main/daemon/pty-subprocess.ts
  • src/main/providers/local-pty-provider.test.ts
  • src/main/providers/local-pty-provider.ts
  • src/relay/pty-handler.test.ts
  • src/relay/pty-handler.ts
  • src/renderer/src/lib/pane-manager/pane-dom-creation.test.ts
  • src/renderer/src/lib/pane-manager/pane-dom-creation.ts
  • src/renderer/src/lib/pane-manager/pane-lifecycle.test.ts
  • src/renderer/src/lib/pane-manager/pane-lifecycle.ts
  • src/renderer/src/lib/pane-manager/pane-manager-types.ts
🚧 Files skipped from review as they are similar to previous changes (6)
  • src/renderer/src/lib/pane-manager/pane-dom-creation.ts
  • src/renderer/src/lib/pane-manager/pane-lifecycle.test.ts
  • package.json
  • src/renderer/src/lib/pane-manager/pane-manager-types.ts
  • src/renderer/src/lib/pane-manager/pane-dom-creation.test.ts
  • src/renderer/src/lib/pane-manager/pane-lifecycle.ts

Comment thread src/main/daemon/pty-subprocess.ts Resolved
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@nwparker nwparker removed the P2 label Aug 19, 2026
nwparker pushed a commit that referenced this pull request Sep 8, 2026
Add opt-in inline terminal images (SIXEL, iTerm2 IIP, Kitty graphics)
through @xterm/addon-image, designed to keep idle terminals unaffected.

Performance:
- The addon (base64-inlined wasm decoders + protocol handlers) loads off
  the boot critical path via a deferred loader that mirrors the WebGL
  addon: primed after first paint only when the setting is on, read back
  synchronously at attach, with a 3-attempt cap so a transient failure
  never disables images for the session and a missing chunk never
  refetches per pane. renderer-boot-graph guards against eager import.
- enableSizeReports:false so the addon never sets windowOptions and
  double-answers Orca's own CSI 14t/16t responder.
- Perf-tuned decode/storage limits (storageLimit, sixel/iip/kitty size
  caps) in one place.

Correctness:
- Orca's DA1 handler wins over the addon's (last-registered-first), and
  the default DA1 response never advertised Sixel (;4), so DA1-detecting
  tools (chafa, img2sixel, viu, timg) never emitted it. The winning
  handler now appends ;4 while the setting is on, resolved per query so a
  live toggle changes the next DA1; idempotent against the ConPTY
  response that already lists it.
- ORCA_IMAGE_PROTOCOL=kitty is exported to spawned shells (local, daemon,
  relay/SSH) and forwarded across the WSL boundary, so image-capable
  agents can pick an encoder. Unknown image sequences are swallowed by
  xterm when the addon is detached, so this never garbles output.
- Settings toggle (default on) gates rendering and DA1 advertisement.

Cross-checked against community PRs #7775, #11706, and #19201 at the end;
credited below.

Co-authored-by: s546126 <s546126@users.noreply.github.com>
Co-authored-by: XRX193 <XRX193@users.noreply.github.com>
Co-authored-by: lmsh7 <lmsh7@users.noreply.github.com>
nwparker pushed a commit that referenced this pull request Sep 8, 2026
Add opt-in inline terminal images (SIXEL, iTerm2 IIP, Kitty graphics)
through @xterm/addon-image, designed to keep idle terminals unaffected.

Performance:
- The addon (base64-inlined wasm decoders + protocol handlers) loads off
  the boot critical path via a deferred loader that mirrors the WebGL
  addon: primed after first paint only when the setting is on, read back
  synchronously at attach, with a 3-attempt cap so a transient failure
  never disables images for the session and a missing chunk never
  refetches per pane. renderer-boot-graph guards against eager import.
- enableSizeReports:false so the addon never sets windowOptions and
  double-answers Orca's own CSI 14t/16t responder.
- Perf-tuned decode/storage limits (storageLimit, sixel/iip/kitty size
  caps) in one place.

Correctness:
- Orca's DA1 handler wins over the addon's (last-registered-first), and
  the default DA1 response never advertised Sixel (;4), so DA1-detecting
  tools (chafa, img2sixel, viu, timg) never emitted it. The winning
  handler now appends ;4 while the setting is on, resolved per query so a
  live toggle changes the next DA1; idempotent against the ConPTY
  response that already lists it.
- ORCA_IMAGE_PROTOCOL=kitty is exported to spawned shells (local, daemon,
  relay/SSH) and forwarded across the WSL boundary, so image-capable
  agents can pick an encoder. Unknown image sequences are swallowed by
  xterm when the addon is detached, so this never garbles output.
- Settings toggle (default on) gates rendering and DA1 advertisement.

Cross-checked against community PRs #7775, #11706, and #19201 at the end;
credited below.

Co-authored-by: s546126 <s546126@users.noreply.github.com>
Co-authored-by: XRX193 <XRX193@users.noreply.github.com>
Co-authored-by: lmsh7 <lmsh7@users.noreply.github.com>
nwparker pushed a commit that referenced this pull request Sep 18, 2026
Add opt-in inline terminal images (SIXEL, iTerm2 IIP, Kitty graphics)
through @xterm/addon-image, designed to keep idle terminals unaffected.

Performance:
- The addon (base64-inlined wasm decoders + protocol handlers) loads off
  the boot critical path via a deferred loader that mirrors the WebGL
  addon: primed after first paint only when the setting is on, read back
  synchronously at attach, with a 3-attempt cap so a transient failure
  never disables images for the session and a missing chunk never
  refetches per pane. renderer-boot-graph guards against eager import.
- enableSizeReports:false so the addon never sets windowOptions and
  double-answers Orca's own CSI 14t/16t responder.
- Perf-tuned decode/storage limits (storageLimit, sixel/iip/kitty size
  caps) in one place.

Correctness:
- Orca's DA1 handler wins over the addon's (last-registered-first), and
  the default DA1 response never advertised Sixel (;4), so DA1-detecting
  tools (chafa, img2sixel, viu, timg) never emitted it. The winning
  handler now appends ;4 while the setting is on, resolved per query so a
  live toggle changes the next DA1; idempotent against the ConPTY
  response that already lists it.
- ORCA_IMAGE_PROTOCOL=kitty is exported to spawned shells (local, daemon,
  relay/SSH) and forwarded across the WSL boundary, so image-capable
  agents can pick an encoder. Unknown image sequences are swallowed by
  xterm when the addon is detached, so this never garbles output.
- Settings toggle (default on) gates rendering and DA1 advertisement.

Cross-checked against community PRs #7775, #11706, and #19201 at the end;
credited below.

Co-authored-by: s546126 <s546126@users.noreply.github.com>
Co-authored-by: XRX193 <XRX193@users.noreply.github.com>
Co-authored-by: lmsh7 <lmsh7@users.noreply.github.com>
nwparker pushed a commit that referenced this pull request Sep 18, 2026
Add opt-in inline terminal images (SIXEL, iTerm2 IIP, Kitty graphics)
through @xterm/addon-image, designed to keep idle terminals unaffected.

Performance:
- The addon (base64-inlined wasm decoders + protocol handlers) loads off
  the boot critical path via a deferred loader that mirrors the WebGL
  addon: primed after first paint only when the setting is on, read back
  synchronously at attach, with a 3-attempt cap so a transient failure
  never disables images for the session and a missing chunk never
  refetches per pane. renderer-boot-graph guards against eager import.
- enableSizeReports:false so the addon never sets windowOptions and
  double-answers Orca's own CSI 14t/16t responder.
- Perf-tuned decode/storage limits (storageLimit, sixel/iip/kitty size
  caps) in one place.

Correctness:
- Orca's DA1 handler wins over the addon's (last-registered-first), and
  the default DA1 response never advertised Sixel (;4), so DA1-detecting
  tools (chafa, img2sixel, viu, timg) never emitted it. The winning
  handler now appends ;4 while the setting is on, resolved per query so a
  live toggle changes the next DA1; idempotent against the ConPTY
  response that already lists it.
- ORCA_IMAGE_PROTOCOL=kitty is exported to spawned shells (local, daemon,
  relay/SSH) and forwarded across the WSL boundary, so image-capable
  agents can pick an encoder. Unknown image sequences are swallowed by
  xterm when the addon is detached, so this never garbles output.
- Settings toggle (default on) gates rendering and DA1 advertisement.

Cross-checked against community PRs #7775, #11706, and #19201 at the end;
credited below.

Co-authored-by: s546126 <s546126@users.noreply.github.com>
Co-authored-by: XRX193 <XRX193@users.noreply.github.com>
Co-authored-by: lmsh7 <lmsh7@users.noreply.github.com>
nwparker added a commit that referenced this pull request Sep 18, 2026
…9512)

* feat(terminal): inline images via @xterm/addon-image, perf-first

Add opt-in inline terminal images (SIXEL, iTerm2 IIP, Kitty graphics)
through @xterm/addon-image, designed to keep idle terminals unaffected.

Performance:
- The addon (base64-inlined wasm decoders + protocol handlers) loads off
  the boot critical path via a deferred loader that mirrors the WebGL
  addon: primed after first paint only when the setting is on, read back
  synchronously at attach, with a 3-attempt cap so a transient failure
  never disables images for the session and a missing chunk never
  refetches per pane. renderer-boot-graph guards against eager import.
- enableSizeReports:false so the addon never sets windowOptions and
  double-answers Orca's own CSI 14t/16t responder.
- Perf-tuned decode/storage limits (storageLimit, sixel/iip/kitty size
  caps) in one place.

Correctness:
- Orca's DA1 handler wins over the addon's (last-registered-first), and
  the default DA1 response never advertised Sixel (;4), so DA1-detecting
  tools (chafa, img2sixel, viu, timg) never emitted it. The winning
  handler now appends ;4 while the setting is on, resolved per query so a
  live toggle changes the next DA1; idempotent against the ConPTY
  response that already lists it.
- ORCA_IMAGE_PROTOCOL=kitty is exported to spawned shells (local, daemon,
  relay/SSH) and forwarded across the WSL boundary, so image-capable
  agents can pick an encoder. Unknown image sequences are swallowed by
  xterm when the addon is detached, so this never garbles output.
- Settings toggle (default on) gates rendering and DA1 advertisement.

Cross-checked against community PRs #7775, #11706, and #19201 at the end;
credited below.

Co-authored-by: s546126 <s546126@users.noreply.github.com>
Co-authored-by: XRX193 <XRX193@users.noreply.github.com>
Co-authored-by: lmsh7 <lmsh7@users.noreply.github.com>

* fix(terminal): bound inline image memory and classify Kitty replies

* fix(terminal): bound image decode and release image resources on cleanup

* fix(terminal): address image addon review feedback

* test(terminal): stub setPaneInlineImagesEnabled in appearance manager fakes

* fix(terminal): evict unplaced kitty payloads before displayed images

Byte-budget eviction dropped the oldest transmitted blob regardless of
placement, so a new upload could erase a visible image while abandoned
blobs still held budget. Unplaced payloads now go first and displayed
ones only when that is not enough. The incoming image is always stored,
so an oversized one overshoots the cap by one payload instead of being
dropped after the protocol already acked OK.

* fix(terminal): gate DA1 Sixel on real addon attachment; claim SSH image spec in CI

- DA1 advertised Sixel from the setting alone, so a pane whose lazy addon
  chunk was still loading (or had failed all three attempts) told
  feature-detecting tools to emit DCS that nothing could render. Track the
  attached decoder per terminal and require it before setting the ;4 bit.
- tests/e2e/terminal-inline-images-ssh.spec.ts was Docker-gated but claimed
  by no lane runner, so pr-e2e-gate-contract failed and the spec would have
  self-skipped green forever.
- Reject non-positive PNG IHDR dimensions before decode: they are parsed with
  signed shifts, so a dimension >= 0x80000000 came back negative and slipped
  past the pixel-limit comparison.
- One resolveTerminalInlineImagesEnabled() for the default-on setting; the
  four call sites mixed '?? true' with '!== false', which disagree on null.
- One readInlineImageResources() walk of the addon internals instead of two
  copies that could drift against the patched dependency.
- Isolate the deferred-attach drain per pane; make the zoom-invariance and
  backing-storage e2e assertions fail when the feature is dead.

* refactor(terminal): one lazy xterm addon loader for webgl and image

terminal-image-addon-loader was a structural clone of the webgl one — same
memo, attempt cap, and .then(ok,err)-clears-memo recovery. Both now wrap
createLazyXtermAddonLoader; each keeps its literal import() specifier so the
bundler still splits the chunk (verified against a fresh build: addon-image
stays out of the boot graph).

* refactor(terminal): name openTerminal's addon flags; pin image addon limits

Two adjacent optional booleans could be swapped without a type error once
inline images added the second one.

* docs(terminal): state the real per-pane image ceiling; drop test ordering dependency

storageLimit:32 reads like the pane's budget but keys three pools — decoded
pixels, retained encoded Kitty blobs, and pending WASM decoders — so the worst
case is ~98 MB per pane with no cross-pane governor. Say so at the constant.

pane-inline-images.test.ts's deferred case needed to run first; it now takes a
fresh module instead, and the rest prime in beforeAll. Verified by running the
file with that test moved last.

* fix(terminal): satisfy rebased static analysis gate

* fix(terminal): complete casting gate cleanup

* fix(terminal): recover failed image addon loads

* fix(terminal): bound image decoder allocations

---------

Co-authored-by: m4air <m4air@m4airs-MacBook-Air.local>
Co-authored-by: s546126 <s546126@users.noreply.github.com>
Co-authored-by: XRX193 <XRX193@users.noreply.github.com>
Co-authored-by: lmsh7 <lmsh7@users.noreply.github.com>
Co-authored-by: Neil <4138956+nwparker@users.noreply.github.com>
Co-authored-by: Neil <neil@stably.ai>
@nwparker

Copy link
Copy Markdown
Contributor

Closing as superseded by merged PR #19512, which incorporates the inline image support and environment signaling from this work with broader protocol and lifecycle coverage.

@nwparker nwparker closed this Sep 19, 2026
petrroll pushed a commit to earendil-works/pi that referenced this pull request Oct 29, 2026
## Summary

Treat `TERM_PROGRAM=Orca` as Kitty-image capable in `pi-tui`'s terminal
capability detection, so image components render inline instead of
falling back to text when running inside Orca.

- Recognize Orca as supporting Kitty inline images, true color, and OSC
8 hyperlinks.
- Preserve the existing tmux and screen precedence guards.
- Gate images on Orca's capability advertisement: require both
`TERM_PROGRAM=Orca` and Orca's `ORCA_IMAGE_PROTOCOL=kitty` signal before
enabling Kitty output, so existing Orca releases that do not yet
advertise image support safely keep the text fallback.
- Add a regression test and the package/CLI changesets.

## Related

- Requested by maintainer approval in
[#7357](#7357)
(lgtm).
- Depends on the Orca-side capability advertisement, which has landed:
[stablyai/orca#19512](stablyai/orca#19512)
(merged 2026-09-18, `09073086a8`) exports `ORCA_IMAGE_PROTOCOL=kitty` on
the daemon, local, and relay PTY paths, and forwards it across the WSL
boundary. Supersedes
[stablyai/orca#11706](stablyai/orca#11706),
which was closed in favor of #19512.

## Testing

- `pnpm --filter @moonshot-ai/pi-tui test` — focused regression suite
passes.
- `pnpm --filter @moonshot-ai/pi-tui typecheck` — passes.
subimpact pushed a commit to subimpact/e that referenced this pull request Oct 31, 2026
…s#9329)

## Summary

Treat `TERM_PROGRAM=Orca` as Kitty-image capable in `pi-tui`'s terminal
capability detection, so image components render inline instead of
falling back to text when running inside Orca.

- Recognize Orca as supporting Kitty inline images, true color, and OSC
8 hyperlinks.
- Preserve the existing tmux and screen precedence guards.
- Gate images on Orca's capability advertisement: require both
`TERM_PROGRAM=Orca` and Orca's `ORCA_IMAGE_PROTOCOL=kitty` signal before
enabling Kitty output, so existing Orca releases that do not yet
advertise image support safely keep the text fallback.
- Add a regression test and the package/CLI changesets.

## Related

- Requested by maintainer approval in
[earendil-works#7357](earendil-works#7357)
(lgtm).
- Depends on the Orca-side capability advertisement, which has landed:
[stablyai/orca#19512](stablyai/orca#19512)
(merged 2026-09-18, `09073086a8`) exports `ORCA_IMAGE_PROTOCOL=kitty` on
the daemon, local, and relay PTY paths, and forwards it across the WSL
boundary. Supersedes
[stablyai/orca#11706](stablyai/orca#11706),
which was closed in favor of #19512.

## Testing

- `pnpm --filter @moonshot-ai/pi-tui test` — focused regression suite
passes.
- `pnpm --filter @moonshot-ai/pi-tui typecheck` — passes.

(cherry picked from commit f09d01b)
oskarfreye pushed a commit to draht-dev/draht that referenced this pull request Nov 4, 2026
…endil-works/pi#9329)

## Summary

Treat `TERM_PROGRAM=Orca` as Kitty-image capable in `pi-tui`'s terminal
capability detection, so image components render inline instead of
falling back to text when running inside Orca.

- Recognize Orca as supporting Kitty inline images, true color, and OSC
8 hyperlinks.
- Preserve the existing tmux and screen precedence guards.
- Gate images on Orca's capability advertisement: require both
`TERM_PROGRAM=Orca` and Orca's `ORCA_IMAGE_PROTOCOL=kitty` signal before
enabling Kitty output, so existing Orca releases that do not yet
advertise image support safely keep the text fallback.
- Add a regression test and the package/CLI changesets.

## Related

- Requested by maintainer approval in
[earendil-works/pi#7357](earendil-works/pi#7357)
(lgtm).
- Depends on the Orca-side capability advertisement, which has landed:
[stablyai/orca#19512](stablyai/orca#19512)
(merged 2026-09-18, `09073086a8`) exports `ORCA_IMAGE_PROTOCOL=kitty` on
the daemon, local, and relay PTY paths, and forwards it across the WSL
boundary. Supersedes
[stablyai/orca#11706](stablyai/orca#11706),
which was closed in favor of badlogic/pi-mono#19512.

## Testing

- `pnpm --filter @moonshot-ai/pi-tui test` — focused regression suite
passes.
- `pnpm --filter @moonshot-ai/pi-tui typecheck` — passes.

(cherry picked from commit f09d01b85e0384647fcab6779d35ab9dabe04be3)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sherocktong pushed a commit to pi-plus-org/pi-plus that referenced this pull request Nov 12, 2026
…s#9329)

## Summary

Treat `TERM_PROGRAM=Orca` as Kitty-image capable in `pi-tui`'s terminal
capability detection, so image components render inline instead of
falling back to text when running inside Orca.

- Recognize Orca as supporting Kitty inline images, true color, and OSC
8 hyperlinks.
- Preserve the existing tmux and screen precedence guards.
- Gate images on Orca's capability advertisement: require both
`TERM_PROGRAM=Orca` and Orca's `ORCA_IMAGE_PROTOCOL=kitty` signal before
enabling Kitty output, so existing Orca releases that do not yet
advertise image support safely keep the text fallback.
- Add a regression test and the package/CLI changesets.

## Related

- Requested by maintainer approval in
[earendil-works#7357](earendil-works#7357)
(lgtm).
- Depends on the Orca-side capability advertisement, which has landed:
[stablyai/orca#19512](stablyai/orca#19512)
(merged 2026-09-18, `09073086a8`) exports `ORCA_IMAGE_PROTOCOL=kitty` on
the daemon, local, and relay PTY paths, and forwards it across the WSL
boundary. Supersedes
[stablyai/orca#11706](stablyai/orca#11706),
which was closed in favor of #19512.

## Testing

- `pnpm --filter @moonshot-ai/pi-tui test` — focused regression suite
passes.
- `pnpm --filter @moonshot-ai/pi-tui typecheck` — passes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Inline image display

5 participants