Registry Mirror
Skip to content

Conversation

@bottercode

@bottercode bottercode commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem

When an agent changes an icon, screenshot, or other image, Hunk shows only "Binary file skipped", so reviewing the change means leaving the terminal. Follow-up to the Discord thread with screenshots of the prototype, and to #1178, which made binary files selectable again.

What this adds

  • Image preview: on a changed PNG, JPEG, GIF, or WebP, press i (or View → File presentation → Image preview) to draw the before and after images inline where "Binary file skipped" was, with a summary such as same size 180×180 · 1.4 KB → 2.2 KB (+822 B). Sides sit next to each other on wide terminals and stack on narrow ones. Added and deleted images show the one side that exists; undecodable bytes and Git LFS pointers get a caption instead of an image.
  • A byte reader in the extension API (version 33; main took 32 for ctx.selection.layout):
    • ExtensionFileViewInput.readBytes(side), lazy, deduplicated, and null-on-failure exactly like readDocument, but also served for binary files.
    • Optional ExtensionVcsPatchResult.readFileBytes, the byte counterpart of readFileSource. It takes the same request, and the boundary caches each side once. It is optional, so existing adapters (e.g. hunk-hg) keep working; their files simply keep the raw diff.
    • Git and Jujutsu implement it, sharing the read path their text readers already use. File comparisons (hunk diff a.png b.png, difftool) and untracked images read from disk.
  • Bundled file views: the bundled UI tier could register panes, commands, and highlighters but not file views. Bundled file views are now composed ahead of user ones, the same way, so the preview works under --no-extensions.

Why core

My first version was an extension, but it had to run git cat-file on the blob ids in the patch header, because file views had no way to get a binary file's bytes. That only works for Git and doesn't belong in an extension or in core. The general piece is the byte reader, which also enables PDF, font, or hex views as extensions. The image preview is then a small bundled view on top, with no VCS-specific code.

Decisions I'd like your call on

  1. i as the default key. i was unbound on the review surface. Bundled commands are composed before user extensions, though, so an extension that already binds i now loses it, with the existing chord-conflict warning. One test extension used i for exactly that, and I moved it to o. Happy to ship the command unbound instead (hunk.imagePreview.toggle).
  2. Default on or off. It's opt-in like every other file view. For images the raw view is only "Binary file skipped", so making the preview the default for images could be argued for. I didn't do that without asking.
  3. Bundled vs extension. If you'd rather keep the preview out of core, the byte-reader half stands on its own, and the preview can be an extension.

Visual evidence

Ghostty on macOS, hunk show a3321c82 --no-extensions (the logo commit), auto layout, default theme, 200×50, run from source:

Real pixels (Kitty graphics) also scroll cleanly. With the images partly scrolled under the pinned file header, the top rows are cut off, nothing draws over the header, and nothing stays behind.

Terminal multiplexers

Hunk doesn't pick the image protocol itself; OpenTUI's <image> does.

  • tmux: OpenTUI detects tmux and draws the images as colored block characters instead of Kitty graphics. That's plain text, so scrolling, splitting panes, and detaching can't leave stale images behind. Checked in tmux 3.6a: the only Kitty escape sent was OpenTUI's startup capability probe, which tmux discards, and no image data was sent. Setting OPENTUI_IMAGE_PROTOCOL=kitty with tmux's allow-passthrough forces Kitty graphics, at the usual passthrough risks.
  • herdr: herdr answers the Kitty capability probe and redraws pane images in the outer terminal itself, so the preview gets real pixels. herdr 0.9.5 inside Ghostty:

With terminal.kitty_graphics = false, herdr stops advertising image support, and the preview falls back to blocks as in tmux.

Tests

  • Shared byte reads: bounded file and stream reads in @hunk/vcs/source.
  • Git: exact bytes from a commit, the index, and the working tree; size limits; missing objects.
  • Jujutsu: a real-repo byte read (runs in CI; jj isn't installed on my machine, so it skipped locally), plus a stubbed process checking non-UTF-8 bytes survive.
  • Boundary adapter: per-side caching, retry after a failed read, too-large, and malformed answers.
  • Loading: end-to-end in real Git repos (working tree, commit, untracked) and binary file pairs.
  • File-view input: readBytes deduplication and null resolution.
  • Preview: layout, captions, and registration.
  • PTY: i shows the preview with no extensions loaded, and pressing it again restores the raw diff.
  • Mutation checks: removing the loader wiring or the bundled registration fails the tests.
  • scripts/packaging: the doc-example and consumer checks now cover the new API.

Commands run (macOS, Bun 1.4.3):

bun run typecheck      # pass
bun run lint           # pass
bun run format:check   # pass
bun run deps:check     # pass
bun run check:docs     # pass
bun run build:npm && bun run check:pack   # pass, 40 doc examples
bun run test           # 9 failures, all of which also fail on clean main (88f8dbed) on this machine
bun run test:integration   # 265 pass, 1 fail, which also fails on clean main
bun run test:tty-smoke     # all 11 skip: macOS `script` lacks -c; runs on Linux CI

The bun run test failures on both this branch and clean main are the rewriteInstalledPackageSpecifiers group (4), "does not retain resolution misses across installs", "locates relative dependency files…", "selects import versus require conditions…", "suppresses lifecycle scripts in transitive Git dependencies…", and "status-owned reload configuration…". The integration failure on both is "enabled trusted launch extensions span real broker-mounted sibling reviews and shut down once". A terminal-color-watcher test failed once and passed on the rerun.

Limitations

  • Sapling has no source reader at all today, so it has no byte reader either; its images keep the raw diff. Same for hunk patch / stdin input.
  • SVG is text with hunks, so it stays on the raw diff.
  • Not tested on Linux or Windows locally; CI covers the unit and integration suites.

@greptile-apps

greptile-apps Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

PR author is not in the allowed authors list.

@vercel

vercel Bot commented Oct 20, 2026

Copy link
Copy Markdown

@bottercode is attempting to deploy a commit to the Modem Team on Vercel.

A member of the Team first needs to authorize it.

@bottercode

Copy link
Copy Markdown
Contributor Author

Before:
image

After:
image

@squad-joey squad-joey 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.

The opt-in image-view flow works in my scoped Linux PTY checks at d3d28805. With the same PNG inputs, base 88f8dbed stays on the raw binary view; head shows the before/after preview under --no-extensions and a second i restores the raw view.

I exercised file comparison and Git working-tree inputs, including an untracked added PNG and a deleted PNG. At 160 columns, both captions share a row; resizing to 62 columns stacks them, and widening restores the side-by-side layout. Corrupt replacement bytes and a Git LFS pointer produce the expected explanation while retaining the readable side. A text SVG stays in the raw diff on both revisions.

An additional live-session check kept the preview selected while changing the replacement PNG and running session reload: the dimensions updated from 32×20 to 12×24, with the old caption gone. Toggling back to raw still worked.

No actionable UI regression found in those checks. This is not verification of Kitty graphics, exact pixel output, JPEG/GIF/WebP, or the byte-reader/API contract.

Supporting checks and limits
  • Exact base 88f8dbedf5a879d8bf0fb051ee22f1280f4b5dd8 → head d3d2880596dcae36fbffbce1d0ba721a833b7f2d; Linux x86_64, Bun 1.4.2, frozen dependencies without lifecycle scripts, isolated HOME/config/temp paths and test sessions.
  • Independent seven-case PTY matrix on each revision, plus the head live-reload check. Existing file-view PTYs: base 14 pass, head 15 pass.
  • Head: 135 focused UI tests, 118 review-conformance tests and typecheck pass.
  • TTY smoke initially had the same two filename assertions fail on both revisions with my long isolated temp path: the displayed filename was truncated. Both revisions pass all 11 with an equally isolated shorter temp path; the long-path failure wasn't fixed by this PR.
  • No full default or full PTY suite, installed-binary, macOS or Windows verification. These checks cover the current opt-in behavior, not a decision about the proposed default key or whether previews should be enabled by default.

This comment was generated by Pi using GPT-6.1 Sol

@squad-robert squad-robert 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.

The byte-reader/backend slice works in my Linux checks, with one request-deduplication issue below to fix before relying on the new API’s “at most once per file and side” guarantee.

On 88f8dbed → d3d28805, the same real loader workloads go from no binary byte capability to exact old/new bytes for index/worktree, HEAD/index, HEAD/worktree, commit, rename, addition, deletion, untracked and file-pair inputs. The fixtures contain NUL and invalid UTF-8 bytes; binary files remain outside text-source consumers. Exact-limit/over-limit filesystem and Git reads, stream cancellation, and optional-reader/failure handling also checked out.

The overlapping-request regression fails on head and passes with a scratch-only pending-read cache. That experiment preserves failed-read retry behavior; head and experiment each pass the focused 125-test slice and typecheck.

This isn’t image-rendering certification: I didn’t verify Kitty pixels, UI layout, installed binaries or non-Linux behavior. Jujutsu isn’t installed here, so its real-repository byte test was skipped, not verified.

This comment was generated by Pi using GPT-6.1 Sol


let result: unknown;
try {
result = await read({

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.

[P2] Share in-flight reads across replacement file-view requests

The cache is populated only after await read(...). If another layout request asks for this side before that finishes, it starts another backend read instead of sharing the first one. I reproduced this with a real Git-loaded binary: start readBytes("old"), abort that input, then create a replacement createFileViewInput over the same DiffFile and read the old side. That launches two git show processes; two calls within a single input correctly launch only one.

This breaks the public reader’s “at most once per file and side” contract and duplicates I/O/buffer allocation when requests are replaced while bytes are loading. Please cache the pending per-side promise immediately and share it across requests, while still evicting rejected/malformed reads so later layouts can retry. A scratch-only pending cache makes the same real-Git regression pass without losing the existing retry behavior.

This comment was generated by Pi using GPT-6.1 Sol

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, fixed in 1afbd3c (was c42d5d2 before the rebase). The pending read is now cached per side as soon as it starts, so a replacement request shares the in-flight git show; rejected or malformed answers are evicted so later layouts can still retry. Added a test that issues two overlapping requests and asserts one adapter call; it fails on the previous implementation.

@squad-robert squad-robert 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.

My in-flight byte-read finding is addressed at c42d5d27.

The original real-Git reproduction now launches one git show read across an aborted file-view input and its replacement, versus two on d3d28805. The original byte-fidelity and side-selection checks still pass. I also checked overlapping rejected, malformed and too-large reads: callers share the pending read, transient failures remain retryable, and the other side stays independent.

The new regression test fails on the previous implementation and passes here; the focused slice is now 126 pass / 9 skip, and typecheck passes.

No remaining objection from that backend finding. This isn’t blanket image-feature approval; the previously stated rendering/platform limitations still apply.

This comment was generated by Pi using GPT-6.1 Sol

@squad-joey squad-joey 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.

Rechecked the UI slice at c42d5d279caed7a15b843d9f0cc00fcf561ae162 after the byte-cache change. The same seven PNG/SVG controls and the active-preview session-reload check pass, including narrow/wide reflow and toggling back to raw. No UI/layout code changed from the previously reviewed head.

Existing file-view PTYs (15), focused UI tests (135), review conformance (118), typecheck and short-path TTY smoke (11) also pass on this exact head.

This remains a Linux/Bun 1.4.2 source-level UI check—not verification of the deduplication/retry fix, exact Kitty pixels, other image formats, installed binaries or other platforms. The earlier review's full-suite and long-temp-path limits still apply.

This comment was generated by Pi using GPT-6.1 Sol

Changed PNG, JPEG, GIF, and WebP files show only "Binary file skipped".
Add a bundled "Image preview" file view (toggled with `i`, or View → File
presentation) that draws the before and after images inline with OpenTUI's
<image>, plus a summary of dimensions and size.

To keep the preview provider-neutral, extension API 32 adds:
- `ExtensionFileViewInput.readBytes(side)`, lazy and cached like
  `readDocument`, and served for binary files;
- optional `ExtensionVcsPatchResult.readFileBytes`, implemented by the Git
  and Jujutsu providers. File comparisons and untracked files read bytes
  from disk.

Bundled UI can now register file views, composed ahead of user views like
bundled commands and highlighters.
The byte fetcher cached a side only after its read finished, so a layout
request that replaced an aborted one while bytes were loading started a
second provider read. Cache the pending read immediately and evict it only
when it rejects or answers malformed, so later layouts can still retry.

@squad-joey squad-joey 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.

Rechecked the rebase/API-33 integration at 1afbd3c5a49b20135d6a260946f8558f6299e6ef (base 96619dbc). The earlier PNG UI checks still pass on this exact head: seven file-pair/Git/error/SVG-control cases plus actual session reload, including wide ↔ narrow layout and updated PNG dimensions with preview selected.

Existing file-view PTYs pass (15), as do focused file-view/host/selection tests (192), review conformance (118), typecheck, and TTY smoke (11). Linux source, Bun 1.4.2, isolated sessions, --no-extensions.

No actionable UI integration issue found. This does not independently verify the backend deduplication contract, Kitty image pixels, other image formats/platforms, or the full test suites.

This comment was generated by Pi using GPT-6.1 Sol

@est7

est7 commented Nov 4, 2026

Copy link
Copy Markdown

+1 from a user who'd really like to see this land. I review a lot of agent-generated changes to Android projects — drawables, launcher icons, screenshot fixtures — and right now every one of them is "Binary file skipped", so I have to leave Hunk to check the images. I tried the extension route first, but on API 32 a file view can't get a binary file's bytes, so it ends up shelling out to Git like the first prototype here did. The readBytes / readFileBytes half seems worth having even on its own.

On the open questions, as one user:

  1. i key: fine by me, and it reads naturally as "image".
  2. Default on/off: I'd prefer the preview to be the default for previewable images. The raw view for these files is only "Binary file skipped", so turning the preview on doesn't hide anything, and you can still press i to get the raw diff back.
  3. Bundled vs extension: bundled, so it also works under --no-extensions. If that's the sticking point, merging the byte reader first and shipping the preview as an extension would still unblock this.

It looks like the PR is only blocked on bookkeeping: squad-robert's earlier "changes requested" review is still active even though the follow-up review says it was addressed in c42d5d27, and the one red check (Windows compatibility) failed with a runner bash startup failure that the action says a re-run may fix. Is there anything else needed from the author's side to get it reviewed by a maintainer?

@benvinegar
benvinegar merged commit 348e707 into modem-dev:main Nov 5, 2026
21 of 23 checks passed
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.

5 participants