The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): keep single-letter WSL dirs on the bridge, test drive aliases on every OS
Teknium8211bb96eddb
diff --git a/apps/desktop/electron/wsl-path-bridge.test.ts b/apps/desktop/electron/wsl-path-bridge.test.tsindex 9013e6c29c8..9f6dd3be129 100644--- a/apps/desktop/electron/wsl-path-bridge.test.ts+++ b/apps/desktop/electron/wsl-path-bridge.test.ts@@ -8,6 +8,7 @@ import {resolveLocalReadPath,resolvePickerDefaultPath,setWslBridgeActive,+ shellDriveToNativePath,wslPosixToWindowsAccessible} from './wsl-path-bridge'@@ -87,17 +88,15 @@ test('setWslBridgeActive(false) → resolvePickerDefaultPath passes raw path thrassert.equal(resolvePickerDefaultPath(undefined), undefined)})-test('setWslBridgeActive(false) → local reads normalize drive aliases without WSL bridging', () => {+test('setWslBridgeActive(false) → resolveLocalReadPath passes raw path through without bridging', () => {setWslBridgeActive(false)// resolveLocalReadPath is used by fs-read-dir to make WSL paths readable// on the Windows host. When the bridge is inactive (remote gateway), the- // non-drive POSIX path must be returned as-is — no UNC rewriting or- // distro resolution. Windows drive aliases still identify native files.+ // raw POSIX path must be returned as-is — no UNC rewriting, no distro+ // resolution. The downstream fs call will fail gracefully on non-WSL+ // hosts, which is the desired behaviour.assert.equal(resolveLocalReadPath('/home/alex/proj'), '/home/alex/proj')- assert.equal(- resolveLocalReadPath('/mnt/c/Users/alex'),- process.platform === 'win32' ? 'C:/Users/alex' : '/mnt/c/Users/alex'- )+ assert.equal(resolveLocalReadPath('/mnt/c/Users/alex'), '/mnt/c/Users/alex')// Non-POSIX paths are never bridged regardless of state.assert.equal(resolveLocalReadPath('C:\\Users\\alex'), 'C:\\Users\\alex')assert.equal(resolveLocalReadPath(''), '')@@ -109,8 +108,21 @@ test('setWslBridgeActive(true) restores picker bridging', () => {setWslBridgeActive(true)assert.equal(resolvePickerDefaultPath('/home/alex', 'Ubuntu'), '\\\\wsl.localhost\\Ubuntu\\home\\alex')- assert.equal(- resolveLocalReadPath('/c/Users/alex', 'Ubuntu'),- process.platform === 'win32' ? 'C:/Users/alex' : '/c/Users/alex'- )+})++test('shellDriveToNativePath maps Git Bash/Cygwin/drvfs drive paths only when the native file exists', () => {+ const existing = new Set(['C:/Users/alex/notes.txt', 'D:/x', 'C:/'])+ const exists = (path: string) => existing.has(path)++ assert.equal(shellDriveToNativePath('/c/Users/alex/notes.txt', exists), 'C:/Users/alex/notes.txt')+ assert.equal(shellDriveToNativePath('/C/Users/alex/notes.txt', exists), 'C:/Users/alex/notes.txt')+ assert.equal(shellDriveToNativePath('/cygdrive/d/x', exists), 'D:/x')+ assert.equal(shellDriveToNativePath('/mnt/c/Users/alex/notes.txt', exists), 'C:/Users/alex/notes.txt')+ assert.equal(shellDriveToNativePath('/c', exists), 'C:/')+ // A real single-letter WSL directory with no native twin stays on the WSL bridge.+ assert.equal(shellDriveToNativePath('/e/projects', exists), null)+ // Not drive spellings at all.+ assert.equal(shellDriveToNativePath('/home/alex/proj', exists), null)+ assert.equal(shellDriveToNativePath('/mnt/data/x', exists), null)+ assert.equal(shellDriveToNativePath('C:\\Users\\alex', exists), null)})diff --git a/apps/desktop/electron/wsl-path-bridge.ts b/apps/desktop/electron/wsl-path-bridge.tsindex c818b4b9b9c..ee1c1b0447c 100644--- a/apps/desktop/electron/wsl-path-bridge.ts+++ b/apps/desktop/electron/wsl-path-bridge.ts@@ -13,6 +13,9 @@ const WIN_DRIVE_RE = /^([A-Za-z]):[\\/]/// `/mnt/c` and `/mnt/c/...` (drvfs default automount root).const WSL_MOUNT_RE = /^\/mnt\/([a-z])(?:\/(.*))?$/i+// `/c/...`, `/cygdrive/c/...`, `/mnt/c/...` (Git Bash, Cygwin, drvfs).+const SHELL_DRIVE_RE = /^\/(?:cygdrive\/|mnt\/)?([a-z])(?:\/|$)/i+let cachedDistro: null | string = nulllet cachedUncBase: null | string = null@@ -180,17 +183,34 @@ export function resolvePickerDefaultPath(return value.startsWith('/') && !WIN_DRIVE_RE.test(value) ? wslPosixToWindowsAccessible(value, distro) : defaultPath}+/**+ * Git Bash / Cygwin / drvfs drive spelling (`/c/...`, `/cygdrive/c/...`,+ * `/mnt/c/...`) → the native `C:/...` path, but only when that native file+ * exists. Native attachments use this spelling even while a local backend has+ * WSL bridging on, and the WSL fallback would look for them under+ * `\\wsl.localhost\<distro>\c\...`. The existence check keeps a real+ * single-letter WSL directory (`/e/projects`) on the WSL bridge.+ */+export function shellDriveToNativePath(value: string, exists: (path: string) => boolean = fs.existsSync): null | string {+ const drive = value.match(SHELL_DRIVE_RE)++ if (!drive) {+ return null+ }++ const nativePath = `${drive[1].toUpperCase()}:/${value.slice(drive[0].length)}`++ return exists(nativePath) ? nativePath : null+}+/** fs read path: on Windows, make a WSL cwd readable via its UNC / drive form. */export function resolveLocalReadPath(dirPath: string, distro?: string, profile?: null | string): string {const value = String(dirPath || '').trim()- // Native attachments can use Git Bash/Cygwin drive spelling even while the- // local backend has WSL bridging enabled. Translate before the WSL fallback- // turns /c/... into a nonexistent \\wsl.localhost\Ubuntu\c\... share.- const shellDrive = IS_WINDOWS && value.match(/^\/(?:cygdrive\/|mnt\/)?([a-z])(?:\/|$)/i)+ const nativeDrivePath = IS_WINDOWS ? shellDriveToNativePath(value) : null- if (shellDrive) {- return `${shellDrive[1].toUpperCase()}:/${value.slice(shellDrive[0].length)}`+ if (nativeDrivePath) {+ return nativeDrivePath}// In remote-gateway mode the POSIX paths belong to a host the Windows