The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(desktop): extract attachmentPathNeedsUpload into lib
Brooklyn Nicholsond29475093294
diff --git a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.ts b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.tsindex 02e4137e511..e0dc5e30968 100644--- a/apps/desktop/src/app/session/hooks/use-prompt-actions/index.ts+++ b/apps/desktop/src/app/session/hooks/use-prompt-actions/index.ts@@ -7,12 +7,12 @@ import { type MutableRefObject, useCallback, useEffect, useRef } from 'react'import { transcribeAudio } from '@/hermes'import { useI18n } from '@/i18n'+import { attachmentPathNeedsUpload } from '@/lib/attachment-upload-policy'import { type ChatMessage, textPart } from '@/lib/chat-messages'import { pathLabel } from '@/lib/chat-runtime'import { sanitizeComposerInput } from '@/lib/composer-input-sanitize'import { triggerHaptic } from '@/lib/haptics'import { setMutableRef } from '@/lib/mutable-ref'-import { isWindowsAbsolutePath } from '@/lib/path-compare'import { normalize } from '@/lib/text'import { transcribeAudioClientDirect } from '@/lib/voice-client-direct'import { clearClarifyRequest } from '@/store/clarify'@@ -91,28 +91,6 @@ interface HandoffResult {error?: string}-const POSIX_ABSOLUTE_PATH_RE = /^\/(?!\/)/--// Terminal backends whose execution environment has its own filesystem-// (docker/ssh/singularity/modal/...) cannot see the desktop's host paths —-// they must be crossed as bytes, like remote attachments. Mirrors the-// container_backend set in tools/terminal_tool.py::_get_env_config.-const CONTAINER_TERMINAL_BACKENDS = new Set(['docker', 'ssh', 'singularity', 'modal', 'daytona', 'vercel_sandbox'])--// `mode: local` means the gateway was launched locally, not necessarily that-// Electron and the gateway share a filesystem. Windows Desktop can front a-// WSL/Docker backend whose cwd is POSIX, so a Windows host path must cross the-// boundary as bytes just like a remote attachment. Container terminal backends-// (docker, ssh, ...) always need bytes: the sandbox has its own filesystem and-// the host path would dangle inside it (#76577).-function attachmentPathNeedsUpload(path: string, backendCwd?: null | string, terminalBackend?: string): boolean {- if (CONTAINER_TERMINAL_BACKENDS.has((terminalBackend || '').trim().toLowerCase())) {- return true- }-- return isWindowsAbsolutePath(path.trim()) && POSIX_ABSOLUTE_PATH_RE.test(backendCwd?.trim() || '')-}-/*** Stage one file/image attachment into the session workspace and return the* attachment rewritten with the gateway-side ref. Attachments upload theirdiff --git a/apps/desktop/src/lib/attachment-upload-policy.ts b/apps/desktop/src/lib/attachment-upload-policy.tsnew file mode 100644index 00000000000..f797fcba8e9--- /dev/null+++ b/apps/desktop/src/lib/attachment-upload-policy.ts@@ -0,0 +1,41 @@+/** When a composer attachment must cross as BYTES rather than ride its path.+ *+ * Shared by the submit-time upload pipeline (`uploadComposerAttachment`) and+ * the drop-time routing decision (`partitionDroppedFiles`) so the two never+ * drift apart. Pure: takes the path and backend facts as arguments.+ */++import { isWindowsAbsolutePath } from '@/lib/path-compare'++const POSIX_ABSOLUTE_PATH_RE = /^\/(?!\/)/++// Terminal backends whose execution environment has its own filesystem+// (docker/ssh/singularity/modal/...) cannot see the desktop's host paths —+// they must be crossed as bytes, like remote attachments. Mirrors the+// container_backend set in tools/terminal_tool.py::_get_env_config.+export const CONTAINER_TERMINAL_BACKENDS = new Set([+ 'docker',+ 'ssh',+ 'singularity',+ 'modal',+ 'daytona',+ 'vercel_sandbox'+])++// `mode: local` means the gateway was launched locally, not necessarily that+// Electron and the gateway share a filesystem. Windows Desktop can front a+// WSL/Docker backend whose cwd is POSIX, so a Windows host path must cross the+// boundary as bytes just like a remote attachment. Container terminal backends+// (docker, ssh, ...) always need bytes: the sandbox has its own filesystem and+// the host path would dangle inside it (#76577).+export function attachmentPathNeedsUpload(+ path: string,+ backendCwd?: null | string,+ terminalBackend?: null | string+): boolean {+ if (CONTAINER_TERMINAL_BACKENDS.has((terminalBackend || '').trim().toLowerCase())) {+ return true+ }++ return isWindowsAbsolutePath(path.trim()) && POSIX_ABSOLUTE_PATH_RE.test(backendCwd?.trim() || '')+}