The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
feat(desktop): skip staging for local OS drops; keep inline @file refs
Brooklyn Nicholson26472756f1d8
diff --git a/apps/desktop/src/app/chat/composer/hooks/use-composer-drop.ts b/apps/desktop/src/app/chat/composer/hooks/use-composer-drop.tsindex 35949c2ed17..66f089ea202 100644--- a/apps/desktop/src/app/chat/composer/hooks/use-composer-drop.ts+++ b/apps/desktop/src/app/chat/composer/hooks/use-composer-drop.ts@@ -1,8 +1,10 @@import { type DragEvent as ReactDragEvent, useRef, useState } from 'react'import { triggerHaptic } from '@/lib/haptics'+import { $terminalBackend } from '@/store/session'+import { isSessionRemote } from '@/store/session-states'-import { extractDroppedFiles, HERMES_PATHS_MIME, partitionDroppedFiles } from '../../hooks/use-composer-actions'+import { extractDroppedFiles, HERMES_PATHS_MIME, type OsDropStagingContext, partitionDroppedFiles } from '../../hooks/use-composer-actions'import { dragHasAttachments, droppedFileInlineRefs, type InlineRefInput } from '../inline-refs'import type { ChatBarProps } from '../types'@@ -12,6 +14,7 @@ interface UseComposerDropArgs {onAttachDroppedItems: ChatBarProps['onAttachDroppedItems']recordUndoPoint: () => voidrequestMainFocus: () => void+ sessionId?: string | null}/**@@ -26,7 +29,8 @@ export function useComposerDrop({insertInlineRefs,onAttachDroppedItems,recordUndoPoint,- requestMainFocus+ requestMainFocus,+ sessionId}: UseComposerDropArgs) {const [dragActive, setDragActive] = useState(false)const dragDepthRef = useRef(0)@@ -36,6 +40,16 @@ export function useComposerDrop({setDragActive(false)}+ // Staging inputs for OS drops, read at drop time (#52427): a local+ // connection on a shared filesystem keeps non-image OS drops as+ // original-path inline refs; remote / container / cross-filesystem+ // backends still stage. Mirrors uploadComposerAttachment's byte decision.+ const osDropStaging = (): OsDropStagingContext => ({+ backendCwd: cwd,+ remote: isSessionRemote(sessionId),+ terminalBackend: $terminalBackend.get()+ })+const handleDragEnter = (event: ReactDragEvent<HTMLFormElement>) => {if (!onAttachDroppedItems || !dragHasAttachments(event.dataTransfer, HERMES_PATHS_MIME)) {return@@ -88,8 +102,9 @@ export function useComposerDrop({// In-app drags (project tree / gutter) are workspace-relative paths the// gateway resolves directly, so they stay inline @file:/@line: refs. OS// drops are absolute local paths a remote gateway can't read (and images- // need byte upload for vision), so route them through the upload pipeline.- const { inAppRefs, osDrops } = partitionDroppedFiles(candidates)+ // need byte upload for vision), so route them through the upload pipeline+ // — unless the backend resolves this machine's paths as-is (#52427).+ const { inAppRefs, osDrops } = partitionDroppedFiles(candidates, osDropStaging())const refs = droppedFileInlineRefs(inAppRefs, cwd)if (refs.length && insertInlineRefs(refs)) {@@ -142,7 +157,7 @@ export function useComposerDrop({// in-app drags stay inline refs; OS drops go through the upload pipeline.// (When no upload handler is wired, fall back to inline refs for all.)const attach = onAttachDroppedItems- const { inAppRefs, osDrops } = partitionDroppedFiles(candidates)+ const { inAppRefs, osDrops } = partitionDroppedFiles(candidates, osDropStaging())const refs = droppedFileInlineRefs(attach ? inAppRefs : candidates, cwd)if (refs.length && insertInlineRefs(refs)) {diff --git a/apps/desktop/src/app/chat/composer/index.tsx b/apps/desktop/src/app/chat/composer/index.tsxindex bcc5685ed12..ad18f5058fd 100644--- a/apps/desktop/src/app/chat/composer/index.tsx+++ b/apps/desktop/src/app/chat/composer/index.tsx@@ -1071,7 +1071,7 @@ export function ChatBar({handleDrop,handleInputDragOver,handleInputDrop- } = useComposerDrop({ cwd, insertInlineRefs, onAttachDroppedItems, recordUndoPoint, requestMainFocus })+ } = useComposerDrop({ cwd, insertInlineRefs, onAttachDroppedItems, recordUndoPoint, requestMainFocus, sessionId })// A bot chat is a companion conversation, not a working session, so it has no// repo to speak of — see the blank repoPath handed to CodingStatusRow below.diff --git a/apps/desktop/src/app/chat/hooks/use-composer-actions.test.ts b/apps/desktop/src/app/chat/hooks/use-composer-actions.test.tsindex 0a44c6a4452..02ac9961e3a 100644--- a/apps/desktop/src/app/chat/hooks/use-composer-actions.test.ts+++ b/apps/desktop/src/app/chat/hooks/use-composer-actions.test.ts@@ -80,6 +80,57 @@ describe('partitionDroppedFiles', () => {it('returns empty groups for an empty drop', () => {expect(partitionDroppedFiles([])).toEqual({ inAppRefs: [], osDrops: [] })})++ it('routes a local non-image OS drop to inline refs; keeps images, remote, and cross-filesystem drops staged', () => {+ // #52427: when the gateway shares this machine's filesystem, an OS drop's+ // original path resolves on the backend as-is, so it stays an inline+ // @file: ref — no staged copy, no lost path semantics. Only drops the+ // backend cannot resolve keep the upload pipeline.+ const finderPdf = osDrop('/Users/mahmoud/Downloads/DEVIS_signed.pdf')+ const screenshot = osDrop('/var/folders/shot.png')+ const pathless = { file: new File(['x'], 'notes.txt'), path: '' }++ const local = partitionDroppedFiles([finderPdf, screenshot, pathless], {+ backendCwd: '/Users/mahmoud/projects/app',+ remote: false,+ terminalBackend: 'local'+ })++ expect(local.inAppRefs).toEqual([finderPdf])+ expect(local.osDrops).toEqual([screenshot, pathless])++ // Remote gateway: this machine's paths never resolve there.+ const remote = partitionDroppedFiles([finderPdf], {+ backendCwd: '/home/gateway/app',+ remote: true,+ terminalBackend: 'local'+ })++ expect(remote).toEqual({ inAppRefs: [], osDrops: [finderPdf] })++ // Local connection but a container backend: the host path would dangle+ // inside the sandbox (#76577).+ const docker = partitionDroppedFiles([finderPdf], {+ backendCwd: '/workspace',+ remote: false,+ terminalBackend: 'docker'+ })++ expect(docker.osDrops).toEqual([finderPdf])++ // Local connection, POSIX backend cwd, Windows host path (#15317).+ const wsl = partitionDroppedFiles([osDrop('C:\\Users\\al\\Downloads\\report.txt')], {+ backendCwd: '/home/gateway/app',+ remote: false,+ terminalBackend: 'local'+ })++ expect(wsl.osDrops).toHaveLength(1)+ })++ it('stages every OS drop when no staging context is given', () => {+ expect(partitionDroppedFiles([osDrop('/abs/a.pdf')]).osDrops).toHaveLength(1)+ })})// Minimal DataTransfer stand-in. A real OS drop populates BOTH `items` (whichdiff --git a/apps/desktop/src/app/chat/hooks/use-composer-actions.ts b/apps/desktop/src/app/chat/hooks/use-composer-actions.tsindex cc8b9427191..74d57f04612 100644--- a/apps/desktop/src/app/chat/hooks/use-composer-actions.ts+++ b/apps/desktop/src/app/chat/hooks/use-composer-actions.ts@@ -5,6 +5,7 @@ import { droppedFileInlineRef } from '@/app/chat/composer/inline-refs'import { LARGE_PASTE_TITLE_PREVIEW_CHARS, pasteSizeLabel } from '@/app/chat/composer/large-paste'import { formatRefValue } from '@/components/assistant-ui/directive-text'import { useI18n } from '@/i18n'+import { attachmentPathNeedsUpload } from '@/lib/attachment-upload-policy'import { attachmentId, contextPath, pathLabel } from '@/lib/chat-runtime'import { readDesktopFileDataUrlLocalFirst, selectDesktopPaths } from '@/lib/desktop-fs'import { downscaleDataUrlForPreview } from '@/lib/image-resize'@@ -310,8 +311,54 @@ function droppedLinkUrls(transfer: DataTransfer): string[] {* in remote mode, and an image needs its bytes uploaded to get vision either* way. So OS drops must go through the attachment/upload pipeline rather than* leaking a local path into the prompt text.+ *+ * `staging` narrows that: when the session's backend resolves this machine's+ * paths as-is (a local connection on a shared filesystem — #52427), a+ * non-image OS drop keeps its original-path inline `@file:` ref instead of+ * being copied into the gateway's staging dir. Without it (legacy callers)+ * every OS drop is staged, as before.*/-export function partitionDroppedFiles(candidates: DroppedFile[]): {+export interface OsDropStagingContext {+ /** The session's backend cwd — cross-filesystem detection (Windows host → POSIX backend). */+ backendCwd?: null | string+ /** Whether the connection owning the session is a remote gateway. */+ remote?: boolean+ /** Terminal backend name from session.info (local | docker | ssh | ...). */+ terminalBackend?: null | string+}++function osDropNeedsStaging(candidate: DroppedFile, staging?: OsDropStagingContext): boolean {+ if (!staging) {+ return true+ }++ // No path -> no inline ref is possible; keep it on the upload pipeline so+ // the failure surfaces ("Could not attach") instead of the drop vanishing.+ if (!candidate.path) {+ return true+ }++ // Images keep the attach pipeline everywhere: vision needs the bytes queued+ // gateway-side even when the path itself resolves.+ const file = candidate.file++ if (file && (file.type.startsWith('image/') || isImagePath(file.name))) {+ return true+ }++ if (isImagePath(candidate.path)) {+ return true+ }++ return (+ Boolean(staging.remote) || attachmentPathNeedsUpload(candidate.path, staging.backendCwd, staging.terminalBackend)+ )+}++export function partitionDroppedFiles(+ candidates: DroppedFile[],+ staging?: OsDropStagingContext+): {osDrops: DroppedFile[]inAppRefs: DroppedFile[]} {@@ -319,7 +366,7 @@ export function partitionDroppedFiles(candidates: DroppedFile[]): {const inAppRefs: DroppedFile[] = []for (const candidate of candidates) {- if (candidate.file) {+ if (candidate.file && osDropNeedsStaging(candidate, staging)) {osDrops.push(candidate)} else {inAppRefs.push(candidate)diff --git a/apps/desktop/src/components/assistant-ui/thread/user-edit-composer.tsx b/apps/desktop/src/components/assistant-ui/thread/user-edit-composer.tsxindex fcc665a7a8b..c534b27b930 100644--- a/apps/desktop/src/components/assistant-ui/thread/user-edit-composer.tsx+++ b/apps/desktop/src/components/assistant-ui/thread/user-edit-composer.tsx@@ -556,8 +556,14 @@ export const UserEditComposer: FC<UserEditComposerProps> = ({ cwd, gateway, sess// In-app drags (project tree / gutter) are workspace-relative paths that// resolve on the gateway as-is, so they stay inline refs. OS drops need to- // be staged + uploaded first, then their gateway-side ref is inserted.- const { inAppRefs, osDrops } = partitionDroppedFiles(candidates)+ // be staged + uploaded first, then their gateway-side ref is inserted —+ // unless the backend resolves this machine's paths as-is, in which case+ // the drop keeps its original-path inline ref too (#52427).+ const { inAppRefs, osDrops } = partitionDroppedFiles(candidates, {+ backendCwd: cwd,+ remote: isSessionRemote(sessionId),+ terminalBackend: $terminalBackend.get()+ })if (insertDroppedRefs(inAppRefs)) {triggerHaptic('selection')