Repository navigation
Conversation
There was a problem hiding this comment.
Works as described. I ran the TUI from source with the simulated model replying with an absolute-path PNG between two paragraphs. On the base it shows only the alt text as a link. With this PR the image draws fitted and left-aligned between the paragraphs (screenshots below). The new and moved tests and the plugin-markdown tests pass, and typecheck is clean in tui, util, session-ui and app.
Public API: unchanged. session.image_preview gets only a new description, and localImagePath/imageReadRequest move into the internal @opencode/util package.
One point worth fixing, inline: the per-session read cache never invalidates, so failed and stale reads stick for as long as the session view is open. Small thing: routes/session/index.tsx also includes three formatting-only hunks (BlockTool, ShellDisplay, Read) that aren't part of this feature.
Related: #52492
| const cached = files.get(key) | ||
| if (cached) return { key, bytes: cached } | ||
| const bytes = input.read(imageReadRequest(directory, path), { signal: controller.signal }) | ||
| // Failed reads stay cached so a streaming paragraph does not retry them on every update. |
There was a problem hiding this comment.
The read is cached permanently per directory + path, including failures. That breaks two common cases:
- The model often writes the image reference before the tool call that creates the file ("I'll render it to
chart.png:
", then a write or bash call). The first render caches the rejected read, so the alt text stays until the session view is remounted. - When an agent regenerates
chart.pngat the same path, the transcript keeps showing the old bytes.
Could failed reads be dropped from files once the stream settles, or the cache be keyed on something that changes when the message completes? That would let a later render retry. The map also holds every image's bytes for the life of the session view with no eviction.
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |


Issue for this PR
Closes #
Type of change
What does this PR do?
The desktop app already shows
images in assistant Markdown. The TUI only showed the alt text as a link. This PR makes the TUI show local images too, using the same path rules as desktop.localImagePathmoves from session-ui to@opencode/util/markdown-image. A newimageReadRequestbuilds the file read the desktop already did: relative paths read from the session directory, absolute paths from their own parent folder. Desktop now calls both shared functions, with no behavior change.client.api.file.read, so it also works with a remote server. Reads are cached per directory and path, so streaming rebuilds don't fetch again.renderNodeis wrapped for assistant text and compaction summaries:session.image_previewis on and Markdown is in rendered mode.http(s)images, linked images, mini mode and the btw panel are not changed.Paragraphs without images, and code-block plugin renderers, go through the same paths as before. The TUI already uses
internalBlockMode="top-level", so a renderer that isn't code-block-only doesn't change how blocks are grouped.How did you verify your code works?
bun run checkpassed.packages/tui/test/markdown-image.test.tsxcovers four cases:packages/util/src/markdown-image.test.ts, with new cases forimageReadRequest.Screenshots / recordings
Block-character fallback in the test renderer, at 60 and 14 columns:
Checklist
Added by the opencode bot (AI-generated).
Related: #52492