GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(tui): embed pasted images and carry path in description by K0nigsberg · Pull Request #55412 · anomalyco/opencode

fix(tui): embed pasted images and carry path in description #55412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
K0nigsberg wants to merge 2 commits into anomalyco:dev from K0nigsberg:image-path-context

Uh oh!

There was an error while loading. Please reload this page.

Closed

fix(tui): embed pasted images and carry path in description #55412

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit Hold shift + click to select a range
9296e12
fix(tui): paste local images as file:// attachments
Oct 15, 2026
79ef593
fix(tui): embed pasted images and carry path in description
Oct 15, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Next Next commit
fix(tui): paste local images as file:// attachments
Keep the short basename in FileAttachment.name for display and provider
filename metadata. Send the filesystem path as a file:// URI so admission
retains source.uri and existing toLLMMessages location text can surface it.

Clipboard bitmaps stay data: URIs named "clipboard" and do not get a fake
Attached file path note.

Fixes #41454
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

yida
yida committed Oct 15, 2026
commit 9296e12a20ecddfdece5294e5875a8b3961a79fd

There are no files selected for viewing

3 changes: 2 additions & 1 deletion 3 packages/tui/src/component/prompt/index.tsx
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import { Slot } from "../../plugin/render"
import type { SessionInbox } from "@opencode/schema/session-inbox"
import {
deduplicatePromptImages,
isPromptImageUri,
preserveMentionlessPromptAttachments,
promptAttachmentLabel,
} from "../../prompt/attachment"
Expand Down Expand Up @@ -392,7 +393,7 @@ export function Prompt(props: PromptProps) {
}

const imageAttachments = createMemo(() =>
(deduplicatePromptImages(store.prompt.files) ?? []).filter((file) => file.uri.startsWith("data:image/")),
(deduplicatePromptImages(store.prompt.files) ?? []).filter((file) => isPromptImageUri(file.uri)),
)
const imagePreviewHeight = createMemo(() => Math.max(4, Math.min(8, Math.floor(dimensions().height / 4))))
const imagePreviewWidth = createMemo(() => imagePreviewHeight() * 2)
Expand Down
5 changes: 4 additions & 1 deletion 5 packages/tui/src/component/prompt/local-attachment.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import path from "node:path"
import { pathToFileURL } from "node:url"

// Bound filesystem work per terminal paste; the byte budget also bounds staged data.
const MAX_PASTED_FILEPATHS = 32
Expand Down Expand Up @@ -50,9 +51,11 @@ export async function resolvePastedAttachments(text: string, platform: string) {
if (item.attachment.type === "text") {
return { type: "text" as const, content: item.attachment.content, filename }
}
// Keep the short display name, and pass the path as a file:// URI so
// admission retains source.uri and toLLMMessages can expose the location.
return {
type: "file" as const,
uri: `data:${item.attachment.mime};base64,${Buffer.from(item.attachment.content).toString("base64")}`,
uri: pathToFileURL(item.filepath).href,
Comment thread Outdated

@opencode-agent opencode-agent Bot Oct 15, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This changes when the file is read: before, the TUI embedded the file's contents at paste time; now the server opens the path when the prompt is submitted. Two cases that work today will break:

  • Remote server (--server <url>): the path is on the user's machine, so the server's readFileAttachment can't open it and the prompt fails.
  • Files that disappear before submit, such as a macOS screenshot dragged from its thumbnail or other temporary files. [FEATURE]: TUI should capture dropped/pasted files at drop time when the source path is ephemeral #46664 asks for the opposite: capture the contents at paste time.

Also, the TUI still reads up to 20 MB of the file above (readLocalAttachment) and then throws the contents away.

Could you keep the embedded data: contents and send the path alongside them? Or send file:// only when the server is local, and fall back to data: otherwise?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@K0nigsberg K0nigsberg Oct 15, 2026

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Good catch — switched back to embedding data: at paste time.

The absolute path now rides in FileAttachment.description (basename stays in name). toLLMMessages only emits Attached file: <path> when that description is an absolute filesystem path, so clipboard / free-form descriptions stay out of the path note.

That keeps remote --server and ephemeral paths working while still giving the model a real location when one exists.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
filename,
}
})
Expand Down
4 changes: 2 additions & 2 deletions 4 packages/tui/src/mini/footer.prompt.tsx
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from "@opentui/core"
import { useRenderer, useTerminalDimensions } from "@opentui/solid"
import { normalizePromptContent } from "../prompt/content"
import { deduplicatePromptImages, promptAttachmentLabel } from "../prompt/attachment"
import { deduplicatePromptImages, isPromptImageUri, promptAttachmentLabel } from "../prompt/attachment"
import { resolvePastedAttachments } from "../component/prompt/local-attachment"
import { createTuiClipboard, type OwnedClipboardService } from "../clipboard"
import type { ClipboardService } from "../context/clipboard"
Expand Down Expand Up @@ -393,7 +393,7 @@ export function createPromptState(input: PromptInput): PromptState {
),
)
const images = createMemo(() =>
(deduplicatePromptImages(attachments()) ?? []).filter((file) => file.uri.startsWith("data:image/")),
(deduplicatePromptImages(attachments()) ?? []).filter((file) => isPromptImageUri(file.uri)),
)
let clipboard: OwnedClipboardService | undefined
let pasteQueue: Promise<void> | undefined
Expand Down
9 changes: 9 additions & 0 deletions 9 packages/tui/src/prompt/attachment.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,18 @@ type ProjectedFile = Readonly<{
function attachmentKind(uri: string) {
if (uri.startsWith("data:image/")) return "Image"
if (uri.startsWith("data:application/pdf;")) return "PDF"
if (uri.startsWith("file:")) {
Comment thread

@opencode-agent opencode-agent Bot Oct 15, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This is left over from the file:// approach. Pastes no longer create file: links, but @-mentions of image files do (autocomplete.tsx uses pathToFileURL). With isPromptImageUri, @-mentioned images now show up in the prompt's image previews and preview dialog. The TUI also tries to load them from a path that may only exist on the server when using --server. Since this fix doesn't need it, please drop the file: branch and isPromptImageUri (and their uses in prompt/index.tsx and mini/footer.prompt.tsx), along with the file:// label test in attachment.test.ts.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
const pathname = URL.parse(uri)?.pathname ?? uri
if (/\.(avif|gif|jpe?g|png|webp)$/i.test(pathname)) return "Image"
if (/\.pdf$/i.test(pathname)) return "PDF"
}
return undefined
}

export function isPromptImageUri(uri: string) {
return attachmentKind(uri) === "Image"
}

function attachmentMetadata(file: PromptFileIdentity) {
return JSON.stringify([file.name ?? null, file.description ?? null])
}
Expand Down
5 changes: 5 additions & 0 deletions 5 packages/tui/test/prompt/attachment.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ describe("prompt attachments", () => {
expect(promptAttachmentLabel(files, { uri: "data:application/pdf;base64,BBB" })).toBe("[PDF 1]")
})

test("labels local file:// image and PDF attachments", () => {
expect(promptAttachmentLabel([], { uri: "file:///tmp/photo.png", name: "photo.png" })).toBe("[Image 1]")
expect(promptAttachmentLabel([], { uri: "file:///tmp/doc.pdf", name: "doc.pdf" })).toBe("[PDF 1]")
})

test("does not reuse a label when attachment metadata differs", () => {
const uri = "data:image/png;base64,AAA"
const files = [{ uri, name: "one.png", mention: { start: 0, end: 9, text: "[Image 1]" } }]
Expand Down
8 changes: 4 additions & 4 deletions 8 packages/tui/test/prompt/local-attachment.test.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ describe("prompt local attachments", () => {

for (const input of [file, `'${file}'`, pathToFileURL(file).href]) {
expect(await resolvePastedAttachments(input, process.platform)).toEqual([
{ type: "file", uri: "data:image/png;base64,AQID", filename: "one image.png" },
{ type: "file", uri: pathToFileURL(file).href, filename: "one image.png" },
])
}
})
Expand All @@ -113,8 +113,8 @@ describe("prompt local attachments", () => {
`# dropped files\r\n${pathToFileURL(image).href}\r\n${pathToFileURL(pdf).href}`,
]) {
expect(await resolvePastedAttachments(input, process.platform)).toEqual([
{ type: "file", uri: "data:image/png;base64,AQID", filename: "one image.png" },
{ type: "file", uri: "data:application/pdf;base64,BAUG", filename: "two file.pdf" },
{ type: "file", uri: pathToFileURL(image).href, filename: "one image.png" },
{ type: "file", uri: pathToFileURL(pdf).href, filename: "two file.pdf" },
])
}
})
Expand Down Expand Up @@ -159,7 +159,7 @@ describe("prompt local attachments", () => {
])

expect(await resolvePastedAttachments(`${image} ${svg}`, process.platform)).toMatchObject([
{ type: "file", filename: "image.png" },
{ type: "file", uri: pathToFileURL(image).href, filename: "image.png" },
{ type: "text", content, filename: "image.svg" },
])
await Bun.write(svg, content + " ")
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.