Repository navigation
fix(ade-code): make clipboard image paste work on remote runtimes #583
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.
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -85,6 +85,7 @@ import { | |
| resizeTerminal, | ||
| reloadClaudePlugins, | ||
| respondToInput, | ||
| saveRuntimeTempAttachment, | ||
| sendChatMessage, | ||
| sendToTerminalSession, | ||
| signalTerminal, | ||
|
|
@@ -164,7 +165,7 @@ import { chatSelectionCopyText, resolveDrawerChatSelection } from "./drawerSelec | |
| import { sortLanesForStackGraph } from "./laneTree"; | ||
| import { latestExpandableFailureId, renderObject, summarizeDiffChanges } from "./format"; | ||
| import { startTuiHeartbeat, type TuiHeartbeat } from "./heartbeat"; | ||
| import { isImageFilePath, latestOpenableImageTarget, readClipboardImageAttachment, readImageDimensions } from "./imageTargets"; | ||
| import { clipboardScratchDir, isImageFilePath, latestOpenableImageTarget, readClipboardImageAttachment, readImageDimensions } from "./imageTargets"; | ||
| import { appendReservedTuiEvent, dedupeTuiEvents, reserveTuiEventDedupKey, syncTuiEventDedupKeys } from "./eventDedup"; | ||
| import { advanceOlderHistoryCursor, prependOlderTuiHistory, splitSnapshotForDisplay, takeNewestChunk, TUI_LOADED_EVENT_CAP } from "./olderHistory"; | ||
| import { coalesceTextDeltaEnvelopes } from "./assistantTextIdentity"; | ||
|
|
@@ -9651,30 +9652,75 @@ export function AdeCodeApp({ project, forceEmbedded, requireSocket, socketPath, | |
| setPaneFocus("details"); | ||
| }, [setPaneFocus]); | ||
|
|
||
| const attachClipboardImage = useCallback((): boolean => { | ||
| const attachment = readClipboardImageAttachment(project.workspaceRoot); | ||
| if (!attachment) { | ||
| addNotice("No clipboard image was found. On macOS, copy an image or image file path; ADE Code checks pngpaste and pbpaste.", "error"); | ||
| return true; | ||
| } | ||
| if (activePaneRef.current !== "chat") { | ||
| focusChat(); | ||
| } | ||
| const insertText = `@${path.basename(attachment.path)}`; | ||
| const addImageMention = useCallback((filePath: string): void => { | ||
| const insertText = `@${path.basename(filePath)}`; | ||
| setSelectedMentions((prev) => { | ||
| if (prev.some((entry) => entry.filePath === attachment.path)) return prev; | ||
| if (prev.some((entry) => entry.filePath === filePath)) return prev; | ||
| return [...prev, { | ||
| kind: "file" as const, | ||
| label: path.basename(attachment.path), | ||
| label: path.basename(filePath), | ||
| insertText, | ||
| detail: attachment.path, | ||
| filePath: attachment.path, | ||
| detail: filePath, | ||
| filePath, | ||
| attachment: true, | ||
| }].slice(-12); | ||
| }); | ||
| addNotice("Attached clipboard image.", "success"); | ||
| }, [addNotice]); | ||
|
|
||
| const attachClipboardImage = useCallback((): boolean => { | ||
| // The clipboard always lives on the machine running the TUI. When the | ||
| // runtime is remote, `project.workspaceRoot` points at a path on the other | ||
| // machine — writing there locally fails (and would be unreadable by the | ||
| // agent anyway), so materialize into a local scratch dir and upload the | ||
| // bytes to the runtime, mirroring the desktop composer. | ||
| const cacheRoot = remoteLaunch ? os.tmpdir() : project.workspaceRoot; | ||
| let attachment: AgentChatFileRef | null = null; | ||
| try { | ||
| attachment = readClipboardImageAttachment(cacheRoot); | ||
| } catch (err) { | ||
| addNotice(`Could not read the clipboard image: ${err instanceof Error ? err.message : String(err)}`, "error"); | ||
| return true; | ||
| } | ||
| if (!attachment) { | ||
| addNotice("No clipboard image was found. On macOS, copy an image or image file path; ADE Code checks pngpaste and pbpaste.", "error"); | ||
| return true; | ||
| } | ||
| if (activePaneRef.current !== "chat") { | ||
| focusChat(); | ||
| } | ||
|
|
||
| if (!remoteLaunch) { | ||
| addImageMention(attachment.path); | ||
| return true; | ||
| } | ||
|
|
||
| const conn = connectionRef.current; | ||
| if (!conn) { | ||
| addNotice("Not connected to the remote runtime — can't attach the image yet.", "error"); | ||
| return true; | ||
|
greptile-apps[bot] marked this conversation as resolved.
Resolved
|
||
| } | ||
| const localPath = attachment.path; | ||
| // Only the temp files ADE materialized under the scratch dir are ours to | ||
| // delete. The clipboard may instead reference a pre-existing user file | ||
| // (copied image file / file path) — upload its bytes, but never delete it. | ||
| const isScratchTemp = localPath.startsWith(`${clipboardScratchDir(cacheRoot)}${path.sep}`); | ||
| void (async () => { | ||
| try { | ||
| const data = await fs.promises.readFile(localPath); | ||
| const { path: remotePath } = await saveRuntimeTempAttachment(conn, { | ||
| data: data.toString("base64"), | ||
| filename: path.basename(localPath), | ||
| }); | ||
| addImageMention(remotePath); | ||
| } catch (err) { | ||
| addNotice(`Could not upload the clipboard image to the remote runtime: ${err instanceof Error ? err.message : String(err)}`, "error"); | ||
| } finally { | ||
| if (isScratchTemp) await fs.promises.rm(localPath, { force: true }).catch(() => {}); | ||
| } | ||
| })(); | ||
|
Comment on lines
+9723
to
+9740
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don’t let remote uploads complete out-of-band from submit. This fire-and-forget upload adds the mention only after the RPC resolves. A quick Ctrl+V→Enter can send without the image, and switching chats before completion can attach the uploaded chip to the wrong context. Track pending uploads and make submit await/drain them, or block submit until the upload is resolved and discard completion if the active lane/session changed. 🤖 Prompt for AI Agents |
||
| return true; | ||
|
greptile-apps[bot] marked this conversation as resolved.
Resolved
|
||
| }, [addNotice, focusChat, project.workspaceRoot]); | ||
| }, [addImageMention, addNotice, focusChat, project.workspaceRoot, remoteLaunch]); | ||
|
|
||
| // Resolve the deeplink target for the row/pane currently focused in the | ||
| // lanes-picker or PR-picker contexts. Returns `null` when the focus is on | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.