The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 12:15 UTC
fix(server): open WSL-mounted Windows drives directly in File Explorer (#31816)
Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>
spoon committed
Nov 15, 2026 at 14:44 UTC
bdf6c6ec890114373079a164e3f5f5aa4347cb21
2 files changed
+73
-5
apps/server/src/process/externalLauncher.test.ts
+33
@@ -354,6 +354,39 @@ it.effect("launches an installed editor with platform-safe arguments", () =>
354
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
355
);
356
357
+const wslpathSpawner = (out: string | undefined) =>
358
+ Layer.succeed(
359
+ ChildProcessSpawner.ChildProcessSpawner,
360
+ ChildProcessSpawner.make((command) =>
361
+ Effect.sync(() => {
362
+ if (!ChildProcess.isStandardCommand(command)) {
363
+ throw new Error("Expected a standard command");
364
+ }
365
+ assert.equal(command.command, "wslpath");
366
+ return makeMockDetachedHandle(
367
+ out === undefined ? { exitCode: 1 } : { exitCode: 0, stdout: `${out}\n` },
368
+ );
369
+ }),
370
+ ),
371
+ );
372
+
373
+it.effect.each([
374
+ // wslpath is mount-aware: a drive remapped in /etc/wsl.conf keeps its real letter.
375
+ { target: "/mnt/d/project", wslpath: "E:\\project", expected: "E:\\project" },
376
+ // wslpath missing or failing falls back to the hand-built UNC path.
377
+ {
378
+ target: "/home/user/repo",
379
+ wslpath: undefined,
380
+ expected: "\\\\wsl.localhost\\Ubuntu-24.04\\home\\user\\repo",
381
+ },
382
+ { target: "/", wslpath: undefined, expected: "\\\\wsl.localhost\\Ubuntu-24.04" },
383
+])("resolveWslFileManagerPath resolves $target to $expected", ({ target, wslpath, expected }) =>
384
+ Effect.gen(function* () {
385
+ const result = yield* ExternalLauncher.resolveWslFileManagerPath(target, "Ubuntu-24.04");
386
+ assert.equal(result, expected);
387
+ }).pipe(Effect.provide(wslpathSpawner(wslpath))),
388
+);
389
+
390
it.live.skipIf(!windowsHost)("opens Windows folders through the default shell handler", () =>
391
Effect.gen(function* () {
392
let spawned: ChildProcess.StandardCommand | undefined;
apps/server/src/process/externalLauncher.ts
+40
-5
@@ -371,11 +371,41 @@ const fileManagerRevealKindForPlatform = Effect.fn(
371
return hasGraphicalLinuxSession(env) ? "files" : undefined;
372
});
373
374
-function resolveWslFileManagerPath(target: string, distroName: string): string {
374
+function wslUncFallbackPath(target: string, distroName: string): string {
375
const relativePath = target.replace(/^\/+/, "").replaceAll("/", "\\");
376
return `\\\\wsl.localhost\\${distroName}${relativePath.length > 0 ? `\\${relativePath}` : ""}`;
377
}
378
379
+// wslpath -w is mount-aware, so a drive remapped in /etc/wsl.conf resolves to the
380
+// real letter and a Linux path resolves to the \\wsl.localhost UNC path. Fall back
381
+// to the UNC form by hand when wslpath is missing or fails.
382
+export const resolveWslFileManagerPath = Effect.fn("externalLauncher.resolveWslFileManagerPath")(
383
+ function* (
384
+ target: string,
385
+ distroName: string,
386
+ ): Effect.fn.Return<string, never, ChildProcessSpawner.ChildProcessSpawner> {
387
+ const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
388
+ return yield* spawner
389
+ .spawn(ChildProcess.make("wslpath", ["-w", target], { stdin: "ignore", stderr: "ignore" }))
390
+ .pipe(
391
+ Effect.flatMap((handle) =>
392
+ Effect.all([handle.stdout.pipe(Stream.decodeText(), Stream.mkString), handle.exitCode], {
393
+ concurrency: "unbounded",
394
+ }),
395
+ ),
396
+ Effect.map(([stdout, exitCode]) => {
397
+ const translated = stdout.trim();
398
+ return exitCode === 0 && translated.length > 0
399
+ ? translated
400
+ : wslUncFallbackPath(target, distroName);
401
+ }),
402
+ Effect.scoped,
403
+ Effect.timeout("2 seconds"),
404
+ Effect.orElseSucceed(() => wslUncFallbackPath(target, distroName)),
405
+ );
406
+ },
407
+);
408
+
409
function buildBrowserLaunch(
410
target: string,
411
platform: NodeJS.Platform,
@@ -547,7 +577,7 @@ const resolveEditorLaunch = Effect.fn("resolveEditorLaunch")(function* (
577
command,
578
args:
579
command === "explorer.exe" && env.WSL_DISTRO_NAME !== undefined
550
- ? [resolveWslFileManagerPath(target, env.WSL_DISTRO_NAME)]
580
+ ? [yield* resolveWslFileManagerPath(target, env.WSL_DISTRO_NAME)]
581
: [target],
582
};
583
});
@@ -611,13 +641,18 @@ const resolveFileManagerRevealLaunch = Effect.fn("resolveFileManagerRevealLaunch
641
shouldUseWindowsHostFromWsl(platform, env) &&
642
env.WSL_DISTRO_NAME !== undefined
643
) {
614
- const explorerTarget = resolveWslFileManagerPath(target, env.WSL_DISTRO_NAME);
644
if (yield* isCommandAvailable(WSL_POWERSHELL_COMMAND, { env })) {
645
// WSL names may contain quotes that Explorer's /select cannot encode.
646
// Open the parent through the shell so replacement managers still apply.
647
const path = yield* Path.Path;
648
// .NET path parsing rejects characters that are legal in WSL filenames.
620
- const parent = resolveWslFileManagerPath(path.dirname(target), env.WSL_DISTRO_NAME);
649
+ const [explorerTarget, parent] = yield* Effect.all(
650
+ [
651
+ resolveWslFileManagerPath(target, env.WSL_DISTRO_NAME),
652
+ resolveWslFileManagerPath(path.dirname(target), env.WSL_DISTRO_NAME),
653
+ ],
654
+ { concurrency: "unbounded" },
655
+ );
656
const source = explorerTarget.includes('"')
657
? `Invoke-Item -LiteralPath ${escapePowerShellStringLiteral(parent)}`
658
: buildFileManagerRevealPowerShellSource(explorerTarget, parent);
@@ -632,7 +667,7 @@ const resolveFileManagerRevealLaunch = Effect.fn("resolveFileManagerRevealLaunch
667
editor: "file-manager",
668
target,
669
command: "explorer.exe",
635
- args: [resolveWslFileManagerPath(path.dirname(target), env.WSL_DISTRO_NAME)],
670
+ args: [yield* resolveWslFileManagerPath(path.dirname(target), env.WSL_DISTRO_NAME)],
671
};
672
}
673