From 3dcc4be311bd4fe50035921b1fd6fbab34943375 Mon Sep 17 00:00:00 2001 From: evilweasel <38261180+EvilWeasel@users.noreply.github.com> Date: Thu, 22 Oct 2026 17:28:46 +0200 Subject: [PATCH 1/2] fix(editor): open secondary WSL projects in Windows Zed Signed-off-by: evilweasel <38261180+EvilWeasel@users.noreply.github.com> --- .../src/process/externalLauncher.test.ts | 74 +++++++++++++++++++ apps/server/src/process/externalLauncher.ts | 1 + apps/web/src/components/ChatView.tsx | 6 +- .../src/components/chat/OpenInPicker.logic.ts | 10 +-- .../src/components/chat/OpenInPicker.test.ts | 63 ++++++++++++++++ packages/shared/src/editor.ts | 14 ++++ 6 files changed, 159 insertions(+), 9 deletions(-) create mode 100644 apps/web/src/components/chat/OpenInPicker.test.ts diff --git a/apps/server/src/process/externalLauncher.test.ts b/apps/server/src/process/externalLauncher.test.ts index 787a729f86b40..327f0a42311af 100644 --- a/apps/server/src/process/externalLauncher.test.ts +++ b/apps/server/src/process/externalLauncher.test.ts @@ -94,6 +94,80 @@ const layerTest = (input: { ); }; +it.effect.skipIf(windowsHost)("discovers and launches Windows Zed in the selected WSL distro", () => + Effect.gen(function* () { + const fs = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const binDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-wsl-zed-" }); + const executable = path.join(binDir, "zed.exe"); + yield* fs.writeFileString(executable, "#!/bin/sh\n"); + yield* fs.chmod(executable, 0o755); + let spawned: ChildProcess.StandardCommand | undefined; + yield* Effect.gen(function* () { + const launcher = yield* ExternalLauncher.ExternalLauncher; + assert.include(yield* launcher.resolveAvailableEditors(), "zed"); + yield* launcher.launchEditor({ + editor: "zed", + cwd: "/home/tobi/projects/linux-server@blain", + }); + }).pipe( + Effect.provide( + layerTest({ + platform: "linux", + env: { PATH: binDir, WSL_DISTRO_NAME: "Ubuntu", USER: "tobi" }, + onSpawn: (command) => { + spawned = command; + }, + }), + ), + ); + assert.ok(spawned); + assert.equal(spawned.command, "zed.exe"); + assert.deepEqual(spawned.args, [ + "--wsl", + "tobi@Ubuntu", + "/home/tobi/projects/linux-server@blain", + ]); + }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), +); + +it.effect.skipIf(windowsHost)("keeps native Linux and SSH Zed launches unchanged", () => + Effect.gen(function* () { + const fs = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const binDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-native-zed-" }); + for (const name of ["zed", "zed.exe"]) { + const executable = path.join(binDir, name); + yield* fs.writeFileString(executable, "#!/bin/sh\n"); + yield* fs.chmod(executable, 0o755); + } + const cases: ReadonlyArray> = [ + {}, + { WSL_DISTRO_NAME: "Ubuntu", SSH_CONNECTION: "client server" }, + ]; + for (const extraEnv of cases) { + let spawned: ChildProcess.StandardCommand | undefined; + yield* Effect.gen(function* () { + const launcher = yield* ExternalLauncher.ExternalLauncher; + yield* launcher.launchEditor({ editor: "zed", cwd: "/workspace/project" }); + }).pipe( + Effect.provide( + layerTest({ + platform: "linux", + env: { PATH: binDir, ...extraEnv }, + onSpawn: (command) => { + spawned = command; + }, + }), + ), + ); + assert.ok(spawned); + assert.equal(spawned.command, "zed"); + assert.deepEqual(spawned.args, ["/workspace/project"]); + } + }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), +); + it.effect.skipIf(windowsHost)( "launched browsers and editors do not inherit ELECTRON_RUN_AS_NODE", () => diff --git a/apps/server/src/process/externalLauncher.ts b/apps/server/src/process/externalLauncher.ts index 2c24857555bb6..c481c7342f070 100644 --- a/apps/server/src/process/externalLauncher.ts +++ b/apps/server/src/process/externalLauncher.ts @@ -123,6 +123,7 @@ const CommandLookupEnvConfig = Config.all({ path: Config.String("path").pipe(Config.option), PATHEXT: Config.String("PATHEXT").pipe(Config.option), HOME: Config.String("HOME").pipe(Config.option), + USER: Config.String("USER").pipe(Config.option), LOCALAPPDATA: Config.String("LOCALAPPDATA").pipe(Config.option), ProgramFiles: Config.String("ProgramFiles").pipe(Config.option), ProgramW6432: Config.String("ProgramW6432").pipe(Config.option), diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index ef3ac29db5693..988976d883af4 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -381,7 +381,6 @@ import { useEnvironmentQuery } from "../state/query"; import { useEnvironmentScope } from "~/state/session"; import { environmentServerConfigsAtom, - primaryServerAvailableEditorsAtom, primaryServerKeybindingsAtom, serverEnvironment, } from "../state/server"; @@ -587,6 +586,7 @@ import { recallableComposerPrompt } from "./chat/composerPromptHistory"; import { observeResize } from "~/lib/observeResize"; const EMPTY_PROVIDERS: ServerProvider[] = []; +const EMPTY_AVAILABLE_EDITORS: readonly never[] = []; const EMPTY_PROVIDER_MODELS: ServerProvider["models"] = []; const EMPTY_USAGE_LIMIT_SOURCES: UsageLimitSourceSnapshots = []; import type { CodexArtifactTemplate } from "@t3tools/shared/codexArtifactTemplates"; @@ -3088,7 +3088,9 @@ export default function ChatView(props: ChatViewProps) { const scriptKeybindings = useAtomValue(serverEnvironment.configValueAtom(environmentId))?.keybindings ?? DEFAULT_RESOLVED_KEYBINDINGS; - const availableEditors = useAtomValue(primaryServerAvailableEditorsAtom); + const availableEditors = + useAtomValue(serverEnvironment.configValueAtom(activeThread?.environmentId ?? environmentId)) + ?.availableEditors ?? EMPTY_AVAILABLE_EDITORS; const remoteOpenState = useRemoteOpenState(activeThread?.environmentId ?? environmentId); const showOpenInPicker = shouldShowOpenInPicker({ activeProjectName: activeProject?.title, diff --git a/apps/web/src/components/chat/OpenInPicker.logic.ts b/apps/web/src/components/chat/OpenInPicker.logic.ts index f5c9e17c392c5..970766c51940b 100644 --- a/apps/web/src/components/chat/OpenInPicker.logic.ts +++ b/apps/web/src/components/chat/OpenInPicker.logic.ts @@ -9,11 +9,7 @@ export function shouldShowOpenInPicker(input: { readonly remoteOpenMode: RemoteOpenMode; }): boolean { if (!input.activeProjectName) return false; - if ( - input.primaryEnvironmentId !== null && - input.activeThreadEnvironmentId === input.primaryEnvironmentId - ) { - return true; - } - return input.remoteOpenMode !== "local-exec"; + // Local execution targets the selected environment, including secondary WSL + // backends. The picker handles missing editors and unavailable SSH routes. + return true; } diff --git a/apps/web/src/components/chat/OpenInPicker.test.ts b/apps/web/src/components/chat/OpenInPicker.test.ts new file mode 100644 index 0000000000000..1f16c32fbc4ec --- /dev/null +++ b/apps/web/src/components/chat/OpenInPicker.test.ts @@ -0,0 +1,63 @@ +import { EnvironmentId } from "@t3tools/contracts"; +import { describe, expect, it } from "vite-plus/test"; + +import { shouldShowOpenInPicker } from "./OpenInPicker.logic"; + +describe("shouldShowOpenInPicker", () => { + const primaryEnvironmentId = EnvironmentId.make("environment-primary"); + + it("shows the picker for projects in the primary environment", () => { + expect( + shouldShowOpenInPicker({ + activeProjectName: "codething-mvp", + activeThreadEnvironmentId: primaryEnvironmentId, + primaryEnvironmentId, + remoteOpenMode: "local-exec", + }), + ).toBe(true); + }); + + it("shows the picker for remote environments in deep-link mode", () => { + expect( + shouldShowOpenInPicker({ + activeProjectName: "codething-mvp", + activeThreadEnvironmentId: EnvironmentId.make("environment-remote"), + primaryEnvironmentId, + remoteOpenMode: "remote-links", + }), + ).toBe(true); + }); + + it("shows the picker's unavailable state for remote environments without an SSH route", () => { + expect( + shouldShowOpenInPicker({ + activeProjectName: "codething-mvp", + activeThreadEnvironmentId: EnvironmentId.make("environment-remote"), + primaryEnvironmentId: null, + remoteOpenMode: "remote-unavailable", + }), + ).toBe(true); + }); + + it("shows the picker for non-primary local backends such as WSL", () => { + expect( + shouldShowOpenInPicker({ + activeProjectName: "codething-mvp", + activeThreadEnvironmentId: EnvironmentId.make("environment-remote"), + primaryEnvironmentId, + remoteOpenMode: "local-exec", + }), + ).toBe(true); + }); + + it("hides the picker when there is no active project", () => { + expect( + shouldShowOpenInPicker({ + activeProjectName: undefined, + activeThreadEnvironmentId: primaryEnvironmentId, + primaryEnvironmentId, + remoteOpenMode: "remote-links", + }), + ).toBe(false); + }); +}); diff --git a/packages/shared/src/editor.ts b/packages/shared/src/editor.ts index 4a263d0b10e89..f23290bb47ca9 100644 --- a/packages/shared/src/editor.ts +++ b/packages/shared/src/editor.ts @@ -34,6 +34,20 @@ export const resolveEditorCommand = Effect.fn("editor.resolveEditorCommand")(fun if (editor.commands === null) return Option.none(); const baseArgs = "baseArgs" in editor ? editor.baseArgs : []; const platform = yield* HostProcess.Platform; + // The Windows CLI needs an explicit distro when invoked without Zed's + // bundled WSL shell wrapper. Prefer it over a Linux `zed` (possibly ZFS). + if ( + platform === "linux" && + editor.id === "zed" && + env.WSL_DISTRO_NAME?.trim() && + env.SSH_CONNECTION === undefined && + env.SSH_TTY === undefined && + env.container === undefined && + (yield* isCommandAvailable("zed.exe", { env })) + ) { + const distro = env.USER ? `${env.USER}@${env.WSL_DISTRO_NAME}` : env.WSL_DISTRO_NAME; + return Option.some({ command: "zed.exe", baseArgs: ["--wsl", distro] }); + } // OpenZFS also installs a `zed` executable. Prefer the macOS editor bundle // so a PATH entry for the ZFS Event Daemon cannot take over editor opens. const preferBundle = platform === "darwin" && editor.id === "zed"; From 47571c78d3e8e87e2795c7b98cac78499d7e8f23 Mon Sep 17 00:00:00 2001 From: evilweasel <38261180+EvilWeasel@users.noreply.github.com> Date: Thu, 22 Oct 2026 17:34:13 +0200 Subject: [PATCH 2/2] fix(editor): preserve readonly command argument types Signed-off-by: evilweasel <38261180+EvilWeasel@users.noreply.github.com> --- packages/shared/src/editor.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/shared/src/editor.ts b/packages/shared/src/editor.ts index f23290bb47ca9..9fbd1c5f2f6f2 100644 --- a/packages/shared/src/editor.ts +++ b/packages/shared/src/editor.ts @@ -46,7 +46,8 @@ export const resolveEditorCommand = Effect.fn("editor.resolveEditorCommand")(fun (yield* isCommandAvailable("zed.exe", { env })) ) { const distro = env.USER ? `${env.USER}@${env.WSL_DISTRO_NAME}` : env.WSL_DISTRO_NAME; - return Option.some({ command: "zed.exe", baseArgs: ["--wsl", distro] }); + const wslArgs: ReadonlyArray = ["--wsl", distro]; + return Option.some({ command: "zed.exe", baseArgs: wslArgs }); } // OpenZFS also installs a `zed` executable. Prefer the macOS editor bundle // so a PATH entry for the ZFS Event Daemon cannot take over editor opens.