Skip to content

Commit f23e881

Browse files
authored
Merge pull request #127 from matt1398/fix/wsl-path-translation
fix: translate WSL mount paths to Windows drive-letter paths
2 parents ccdd34a + ad25f0f commit f23e881

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

src/main/utils/metadataExtraction.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import * as readline from 'readline';
99
import { LocalFileSystemProvider } from '../services/infrastructure/LocalFileSystemProvider';
1010
import { type ChatHistoryEntry, isTextContent, type UserEntry } from '../types';
1111

12+
import { translateWslMountPath } from './pathDecoder';
13+
1214
import type { FileSystemProvider } from '../services/infrastructure/FileSystemProvider';
1315

1416
const logger = createLogger('Util:metadataExtraction');
@@ -59,7 +61,7 @@ export async function extractCwd(
5961
if ('cwd' in entry && entry.cwd) {
6062
rl.close();
6163
fileStream.destroy();
62-
return normalizeDriveLetter(entry.cwd);
64+
return normalizeDriveLetter(translateWslMountPath(entry.cwd));
6365
}
6466
}
6567
} catch (error) {

src/main/utils/pathDecoder.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ export function decodePath(encodedName: string): string {
6969
}
7070

7171
// Ensure leading slash for POSIX-style absolute paths
72-
return decodedPath.startsWith('/') ? decodedPath : `/${decodedPath}`;
72+
const absolutePath = decodedPath.startsWith('/') ? decodedPath : `/${decodedPath}`;
73+
74+
// Translate WSL mount paths to Windows drive-letter paths on Windows
75+
return translateWslMountPath(absolutePath);
7376
}
7477

7578
/**
@@ -91,6 +94,23 @@ export function extractProjectName(encodedName: string, cwdHint?: string): strin
9194
return segments[segments.length - 1] || encodedName;
9295
}
9396

97+
/**
98+
* Translate WSL mount paths (/mnt/X/...) to Windows drive-letter paths (X:/...)
99+
* when running on Windows. No-op on other platforms.
100+
*/
101+
export function translateWslMountPath(posixPath: string): string {
102+
if (process.platform !== 'win32') {
103+
return posixPath;
104+
}
105+
const match = /^\/mnt\/([a-zA-Z])(\/.*)?$/.exec(posixPath);
106+
if (match) {
107+
const drive = match[1].toUpperCase();
108+
const rest = match[2] ?? '';
109+
return `${drive}:${rest}`;
110+
}
111+
return posixPath;
112+
}
113+
94114
// =============================================================================
95115
// Validation
96116
// =============================================================================

vitest.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export default defineConfig({
55
test: {
66
globals: true,
77
environment: 'happy-dom',
8+
testTimeout: 15000,
89
setupFiles: ['./test/setup.ts'],
910
include: ['test/**/*.test.ts'],
1011
coverage: {

0 commit comments

Comments
 (0)