@devries-cameron20 / t3code Mirror · read-only / commits / 6fe782ca4a
Fork 0

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, 16:00 UTC

fix(server): Windows drive paths open under WSL (#26030)

Julius Marminge committed Nov 13, 2026 at 17:46 UTC 6fe782ca4a552acee1419dd5a92c600e5b9d1327
6 files changed +167 -4
apps/server/src/assets/AssetAccess.test.ts
+30
@@ -28,6 +28,7 @@ import { vi } from "vite-plus/test";
28 import * as AssetSigner from "./AssetSigner.ts";
29 import * as ServerSecretStore from "../auth/ServerSecretStore.ts";
30 import * as ServerConfig from "../config.ts";
31 +import { makeFakeWslHost } from "../testUtils/fakeWsl.ts";
32 import * as Orchestrator from "../orchestration-v2/Orchestrator.ts";
33 import * as ProjectFaviconResolver from "../project/ProjectFaviconResolver.ts";
34 import * as T3ProjectFileLoader from "../project/T3ProjectFileLoader.ts";
@@ -570,6 +571,35 @@ describe("AssetAccess", () => {
571 }).pipe(Effect.provide(layerTest)),
572 );
573
574 + it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")(
575 + "resolves a Windows drive media path under WSL to where wslpath mounts it",
576 + () =>
577 + Effect.gen(function* () {
578 + const fs = yield* FileSystem.FileSystem;
579 + const path = yield* Path.Path;
580 + const { mountRoot, underWsl } = yield* makeFakeWslHost;
581 + const workspaceRoot = yield* fs.makeTempDirectoryScoped({ prefix: "t3-media-wsl-root-" });
582 + const filePath = path.join(mountRoot, "c", "Users", "me", "Pictures", "shot.png");
583 + yield* fs.makeDirectory(path.dirname(filePath), { recursive: true });
584 + yield* fs.writeFile(filePath, screenshotPng);
585 + const canonicalFile = yield* fs.realPath(filePath);
586 + const drivePath = "C:\\Users\\me\\Pictures\\shot.png";
587 +
588 + for (const resource of [
589 + { _tag: "media-file", threadId: ThreadId.make("thread-1"), path: drivePath },
590 + { _tag: "draft-workspace-file", cwd: workspaceRoot, path: drivePath },
591 + ] as const) {
592 + const result = yield* underWsl(issueAssetUrl({ resource, workspaceRoot }));
593 + expect(result.imageDimensions).toEqual({ width: 390, height: 844 });
594 + const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
595 + const separator = suffix.indexOf("/");
596 + expect(
597 + yield* resolveAsset(suffix.slice(0, separator), suffix.slice(separator + 1)),
598 + ).toMatchObject({ kind: "file", path: canonicalFile, mimeType: "image/png" });
599 + }
600 + }).pipe(Effect.provide(layerTest)),
601 + );
602 +
603 // Resolving `file://attacker.test/share/cat.jpg` from an agent's markdown sent the
604 // Windows user's NTLM credentials to attacker.test.
605 it.effect("never resolves a network media path outside the thread's project", () =>
apps/server/src/assets/AssetAccess.ts
+6 -2
@@ -57,6 +57,7 @@ import { expandHomePath } from "@t3tools/provider-core/server/pathExpansion";
57 import * as ProjectFaviconResolver from "../project/ProjectFaviconResolver.ts";
58 import { isWithinRoot } from "../workspace/KnownWorkspaces.ts";
59 import * as WorkspacePaths from "../workspace/WorkspacePaths.ts";
60 +import { toWslDrivePath } from "../workspace/wslDrivePath.ts";
61 import * as NativeAppIconResolver from "./NativeAppIconResolver.ts";
62 import { sourceControlDefinitions } from "../sourceControl/sourceControlDefinitions.ts";
63 import { extractIcnsPng } from "./icns.ts";
@@ -548,7 +549,10 @@ export const issueAssetUrl = Effect.fn("AssetAccess.issueAssetUrl")(function* (i
549
550 switch (input.resource._tag) {
551 case "media-file": {
551 - let requestedPath = expandHomePath(input.resource.path, yield* HostProcess.HomeDirectory);
552 + let requestedPath = expandHomePath(
553 + yield* toWslDrivePath(input.resource.path),
554 + yield* HostProcess.HomeDirectory,
555 + );
556 if (!path.isAbsolute(requestedPath)) {
557 if (!input.workspaceRoot) {
558 return yield* new AssetWorkspaceContextNotFoundError({ resource: input.resource });
@@ -605,7 +609,7 @@ export const issueAssetUrl = Effect.fn("AssetAccess.issueAssetUrl")(function* (i
609 const draftWorkspaceRoot = input.workspaceRoot ?? input.resource.cwd;
610 const hostPath = input.resource.path.startsWith("~/")
611 ? expandHomePath(input.resource.path, yield* HostProcess.HomeDirectory)
608 - : input.resource.path;
612 + : yield* toWslDrivePath(input.resource.path);
613 if (path.isAbsolute(hostPath)) {
614 const finalized = yield* finalizeAbsoluteMediaFileAsset({
615 requestedPath: hostPath,
apps/server/src/testUtils/fakeWsl.ts new
+37
@@ -0,0 +1,37 @@
1 +import * as HostProcess from "@t3tools/shared/HostProcess";
2 +import * as Effect from "effect/Effect";
3 +import * as FileSystem from "effect/FileSystem";
4 +import * as Path from "effect/Path";
5 +
6 +// `wslpath` honours the distro's configurable automount root, so the fake maps drives under a temp dir.
7 +export const makeFakeWslHost = Effect.gen(function* () {
8 + const fileSystem = yield* FileSystem.FileSystem;
9 + const path = yield* Path.Path;
10 + const mountRoot = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3code-wsl-mnt-" });
11 + const binDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3code-wsl-bin-" });
12 + const wslpath = path.join(binDir, "wslpath");
13 + yield* fileSystem
14 + .writeFileString(
15 + wslpath,
16 + [
17 + "#!/bin/sh",
18 + '[ "$1" = "-u" ] || exit 1',
19 + "p=$(printf '%s' \"$2\" | tr '\\\\' '/')",
20 + "drive=$(printf '%s' \"$p\" | cut -c1 | tr 'A-Z' 'a-z')",
21 + `printf '%s/%s%s\\n' '${mountRoot}' "$drive" "\${p#?:}"`,
22 + "",
23 + ].join("\n"),
24 + )
25 + .pipe(Effect.orDie);
26 + yield* fileSystem.chmod(wslpath, 0o755).pipe(Effect.orDie);
27 + const environment = {
28 + ...HostProcess.Environment.defaultValue(),
29 + PATH: `${binDir}:${HostProcess.Environment.defaultValue().PATH ?? ""}`,
30 + };
31 + const underWsl = <A, E, R>(effect: Effect.Effect<A, E, R>) =>
32 + effect.pipe(
33 + Effect.provideService(HostProcess.Platform, "linux"),
34 + Effect.provideService(HostProcess.Environment, environment),
35 + );
36 + return { mountRoot, underWsl };
37 +});
apps/server/src/workspace/WorkspaceFileSystem.test.ts
+52
@@ -12,6 +12,7 @@ import * as Layer from "effect/Layer";
12 import * as Path from "effect/Path";
13
14 import * as ServerConfig from "../config.ts";
15 +import { makeFakeWslHost } from "../testUtils/fakeWsl.ts";
16 import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts";
17 import * as VcsProcess from "../vcs/VcsProcess.ts";
18 import * as KnownWorkspaces from "./KnownWorkspaces.ts";
@@ -96,6 +97,14 @@ const writeTextFile = Effect.fn("writeTextFile")(function* (
97 yield* fileSystem.writeFileString(absolutePath, contents).pipe(Effect.orDie);
98 });
99
100 +const makeWslHost = Effect.gen(function* () {
101 + const { mountRoot, underWsl } = yield* makeFakeWslHost;
102 + const service = yield* underWsl(
103 + WorkspaceFileSystem.make.pipe(Effect.provide(layerKnownWorkspacesTest)),
104 + );
105 + return { mountRoot, service, underWsl };
106 +});
107 +
108 it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (it) => {
109 describe("getMetadata", () => {
110 it.effect(
@@ -181,6 +190,31 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (i
190 expect(statted).toEqual([]);
191 }),
192 );
193 +
194 + it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")(
195 + "reports a Windows drive path under WSL as the file it maps to",
196 + () =>
197 + Effect.gen(function* () {
198 + const { mountRoot, service, underWsl } = yield* makeWslHost;
199 + yield* writeTextFile(mountRoot, "c/Users/me/Documents/notes.md", "# Notes\n");
200 +
201 + const { entries } = yield* underWsl(
202 + service.getMetadata({
203 + paths: [
204 + "C:\\Users\\me\\Documents\\notes.md",
205 + "C:/Users/me/Documents/notes.md",
206 + "C:/Users/me/Documents/notes\u0000.md",
207 + ],
208 + }),
209 + );
210 +
211 + expect(entries).toEqual([
212 + { kind: "file", byteLength: 8 },
213 + { kind: "file", byteLength: 8 },
214 + null,
215 + ]);
216 + }),
217 + );
218 });
219
220 describe("readFile", () => {
@@ -351,6 +385,24 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (i
385 }),
386 );
387
388 + it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")(
389 + "reads a Windows drive path under WSL from where wslpath mounts it",
390 + () =>
391 + Effect.gen(function* () {
392 + const { mountRoot, service, underWsl } = yield* makeWslHost;
393 + const cwd = yield* makeTempDir;
394 + yield* writeTextFile(mountRoot, "c/Users/me/Documents/notes.md", "# Notes\n");
395 +
396 + for (const relativePath of [
397 + "C:\\Users\\me\\Documents\\notes.md",
398 + "C:/Users/me/Documents/notes.md",
399 + ]) {
400 + const result = yield* underWsl(service.readFile({ cwd, relativePath }));
401 + expect(result).toMatchObject({ contents: "# Notes\n", truncated: false });
402 + }
403 + }),
404 + );
405 +
406 it.effect("refuses a network path outside the workspace", () =>
407 Effect.gen(function* () {
408 const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
apps/server/src/workspace/WorkspaceFileSystem.ts
+13 -2
@@ -19,6 +19,7 @@ import * as Effect from "effect/Effect";
19 import * as FileSystem from "effect/FileSystem";
20 import * as Layer from "effect/Layer";
21 import * as Path from "effect/Path";
22 +import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
23 import * as Schema from "effect/Schema";
24
25 import { makeIsServerInternalPath } from "../auth/serverInternalPaths.ts";
@@ -26,6 +27,7 @@ import * as KnownWorkspaces from "./KnownWorkspaces.ts";
27 import * as WorkspaceEntries from "./WorkspaceEntries.ts";
28 import * as WorkspacePaths from "./WorkspacePaths.ts";
29 import { fileHeaderMimeType } from "./fileHeaderMimeType.ts";
30 +import { toWslDrivePath } from "./wslDrivePath.ts";
31
32 const PROJECT_READ_FILE_MAX_BYTES = 1024 * 1024;
33
@@ -141,9 +143,18 @@ export const make = Effect.gen(function* () {
143 const knownWorkspaces = yield* KnownWorkspaces.KnownWorkspaces;
144 const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries;
145 const isServerInternalPath = yield* makeIsServerInternalPath;
146 + const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
147 +
148 + const toHostPath = (requestedPath: string) =>
149 + toWslDrivePath(requestedPath).pipe(
150 + Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
151 + );
152
153 const metadataForPath = Effect.fnUntraced(function* (requestedPath: string) {
146 - const expandedPath = expandHomePath(requestedPath, yield* HostProcess.HomeDirectory);
154 + const expandedPath = expandHomePath(
155 + yield* toHostPath(requestedPath),
156 + yield* HostProcess.HomeDirectory,
157 + );
158 // Chips ask as soon as an agent's message renders, and touching a network
159 // path makes Windows sign in to its host with the user's NTLM credentials.
160 if (!path.isAbsolute(expandedPath) || isNetworkPath(expandedPath)) return null;
@@ -230,7 +241,7 @@ export const make = Effect.gen(function* () {
241 const requestedPath = input.relativePath;
242 const hostPath = requestedPath.startsWith("~/")
243 ? expandHomePath(requestedPath, yield* HostProcess.HomeDirectory)
233 - : requestedPath;
244 + : yield* toHostPath(requestedPath);
245 if (
246 isNetworkPath(hostPath) &&
247 !KnownWorkspaces.isWithinRoot(path, path.resolve(hostPath), path.resolve(input.cwd))
apps/server/src/workspace/wslDrivePath.ts new
+29
@@ -0,0 +1,29 @@
1 +import * as HostProcess from "@t3tools/shared/HostProcess";
2 +import { isWindowsDrivePath } from "@t3tools/shared/path";
3 +import * as Effect from "effect/Effect";
4 +import * as ChildProcess from "effect/process/ChildProcess";
5 +import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
6 +
7 +// WSL mounts Windows drives under a configurable automount root, so only wslpath knows where.
8 +// No WSL env check: servers started by systemd lack WSL_DISTRO_NAME, and off WSL the spawn just fails.
9 +// Untraced: it runs for every chip path, and only drive paths on Linux do any work.
10 +export const toWslDrivePath = Effect.fnUntraced(function* (requestedPath: string) {
11 + // spawn throws on a NUL byte instead of failing.
12 + if (!isWindowsDrivePath(requestedPath) || requestedPath.includes("\0")) return requestedPath;
13 + if ((yield* HostProcess.Platform) !== "linux") return requestedPath;
14 + const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
15 + const output = yield* spawner
16 + .string(
17 + ChildProcess.make("wslpath", ["-u", requestedPath], {
18 + env: yield* HostProcess.Environment,
19 + stdin: "ignore",
20 + stderr: "ignore",
21 + }),
22 + )
23 + .pipe(
24 + Effect.timeout("1 second"),
25 + Effect.orElseSucceed(() => ""),
26 + );
27 + const linuxPath = output.endsWith("\n") ? output.slice(0, -1) : output;
28 + return linuxPath.startsWith("/") ? linuxPath : requestedPath;
29 +});