The best way to control Claude Code, Codex and more from any computer or phone
fix(server): open stable Zed when a prerelease Zed is first on PATH (#24656)
Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Victor committed
Nov 14, 2026 at 02:23 UTC
86d49daf82b16f39047db5cc763c088b0aff230c
3 files changed
+145
-31
apps/server/src/process/externalLauncher.test.ts
+51
@@ -1183,6 +1183,57 @@ it.effect(
1183
},
1184
);
1185
1186
+it.effect.each(["Zed Nightly", "Zed Preview"])(
1187
+ "launches stable Zed on Windows when %s comes first on PATH",
1188
+ (channel) =>
1189
+ Effect.gen(function* () {
1190
+ const fs = yield* FileSystem.FileSystem;
1191
+ const path = yield* Path.Path;
1192
+ const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-zed-channels-" });
1193
+ // A user folder naming Zed and a channel does not mark either install.
1194
+ const programs = path.join(root, "Users", "zedpreview", "Programs");
1195
+ const prereleaseBin = path.join(programs, channel, "bin");
1196
+ const stableBin = path.join(programs, "Zed", "bin");
1197
+ for (const dir of [prereleaseBin, stableBin]) {
1198
+ yield* fs.makeDirectory(dir, { recursive: true });
1199
+ yield* fs.writeFileString(path.join(dir, "zed.EXE"), "");
1200
+ }
1201
+ const env = { PATH: `${prereleaseBin};${stableBin}`, PATHEXT: ".COM;.EXE;.BAT;.CMD" };
1202
+
1203
+ const launchZed = Effect.gen(function* () {
1204
+ let spawned: ChildProcess.StandardCommand | undefined;
1205
+ yield* Effect.gen(function* () {
1206
+ const launcher = yield* ExternalLauncher.ExternalLauncher;
1207
+ yield* launcher.launchEditor({ editor: "zed", cwd: "C:\\workspace" });
1208
+ }).pipe(
1209
+ Effect.provide(
1210
+ layerTest({
1211
+ platform: "win32",
1212
+ env,
1213
+ onSpawn: (command) => {
1214
+ spawned = command;
1215
+ },
1216
+ }),
1217
+ ),
1218
+ );
1219
+ assert.ok(spawned);
1220
+ return spawned;
1221
+ });
1222
+
1223
+ const stable = yield* launchZed;
1224
+ assert.equal(stable.command, path.join(stableBin, "zed.EXE"));
1225
+ assert.deepEqual(stable.args, ["C:\\workspace"]);
1226
+
1227
+ env.PATH = `${stableBin};${prereleaseBin}`;
1228
+ assert.equal((yield* launchZed).command, "zed");
1229
+
1230
+ env.PATH = `${prereleaseBin};${stableBin}`;
1231
+ // With only the prerelease install left, it still opens by name.
1232
+ yield* fs.remove(path.join(stableBin, "zed.EXE"));
1233
+ assert.equal((yield* launchZed).command, "zed");
1234
+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
1235
+);
1236
+
1237
const launchWindowsShimEditor = (cwd: string) =>
1238
Effect.gen(function* () {
1239
const fileSystem = yield* FileSystem.FileSystem;
packages/shared/src/editor.ts
+26
-2
@@ -7,10 +7,20 @@ import * as Stream from "effect/Stream";
7
import { ChildProcess, ChildProcessSpawner } from "effect/process";
8
9
import * as HostProcess from "./HostProcess.ts";
10
-import { isCommandAvailable, resolveCommandPath } from "./shell.ts";
10
+import { isCommandAvailable, resolveCommandPath, resolveCommandPaths } from "./shell.ts";
11
12
type Editor = (typeof EDITORS)[number];
13
14
+// The nearest Zed folder identifies the channel, even below a user named zedpreview.
15
+const isPrereleaseZedPath = (filePath: string) => {
16
+ const install = filePath
17
+ .split(/[\\/]/)
18
+ .slice(0, -1)
19
+ .findLast((folder) => folder.toLowerCase().includes("zed"))
20
+ ?.toLowerCase();
21
+ return install !== undefined && (install.includes("nightly") || install.includes("preview"));
22
+};
23
+
24
const installNames: Partial<Record<Editor["id"], ReadonlyArray<string>>> = {
25
vscode: ["Visual Studio Code"],
26
"vscode-insiders": ["Visual Studio Code - Insiders"],
@@ -59,7 +69,21 @@ export const resolveEditorCommand = Effect.fn("editor.resolveEditorCommand")(fun
69
// Prefer Zed's macOS bundle because OpenZFS also installs a zed executable.
70
const preferBundle = platform === "darwin" && editor.id === "zed";
71
const preferZeditor = platform === "linux" && editor.id === "zed";
62
- if (!preferBundle && !preferZeditor) {
72
+ if (platform === "win32" && editor.id === "zed") {
73
+ const isStable = (resolved: string) => !isPrereleaseZedPath(resolved);
74
+ let firstCommand: string | undefined;
75
+ for (const command of editor.commands) {
76
+ const matches = yield* resolveCommandPaths(command, { env, until: isStable });
77
+ const stable = matches.find(isStable);
78
+ // Bypass PATH only when stable is behind a prerelease install.
79
+ if (stable !== undefined) {
80
+ const isFirst = firstCommand === undefined && stable === matches[0];
81
+ return Option.some({ command: isFirst ? command : stable, baseArgs });
82
+ }
83
+ if (firstCommand === undefined && matches.length > 0) firstCommand = command;
84
+ }
85
+ if (firstCommand !== undefined) return Option.some({ command: firstCommand, baseArgs });
86
+ } else if (!preferBundle && !preferZeditor) {
87
for (const command of editor.commands) {
88
if (yield* isCommandAvailable(command, { env })) return Option.some({ command, baseArgs });
89
}
packages/shared/src/shell.ts
+68
-29
@@ -640,6 +640,47 @@ const isExecutableFile = Effect.fnUntraced(function* (
640
return canExecuteFile(filePath);
641
});
642
643
+// Called within the traced command resolvers.
644
+const findOnPath = Effect.fnUntraced(function* (
645
+ pathValue: string,
646
+ commandCandidates: ReadonlyArray<string>,
647
+ platform: NodeJS.Platform,
648
+ windowsPathExtensions: ReadonlyArray<string>,
649
+ isLast: (match: string) => boolean,
650
+): Effect.fn.Return<ReadonlyArray<string>, never, FileSystem.FileSystem | Path.Path> {
651
+ const path = yield* Path.Path;
652
+ // Keep case variants: Windows can make PATH directories case-sensitive.
653
+ const pathEntries: string[] = [];
654
+ const seenPathEntries = new Set<string>();
655
+ for (const entry of pathValue.split(pathDelimiterForPlatform(platform))) {
656
+ const pathEntry = stripWrappingQuotes(entry.trim());
657
+ if (pathEntry.length === 0 || seenPathEntries.has(pathEntry)) continue;
658
+
659
+ seenPathEntries.add(pathEntry);
660
+ pathEntries.push(pathEntry);
661
+ }
662
+
663
+ const listings = yield* PathDirectoryListings;
664
+ const matches: string[] = [];
665
+ for (const pathEntry of pathEntries) {
666
+ let listing = listings && (yield* Cache.get(listings, pathEntry));
667
+ if (listings && listing?.names && listing.modified !== (yield* directoryMtime(pathEntry))) {
668
+ yield* Cache.invalidate(listings, pathEntry);
669
+ listing = yield* Cache.get(listings, pathEntry);
670
+ }
671
+ for (const candidate of commandCandidates) {
672
+ if (listing?.names && !listing.names.has(candidate.toLowerCase())) continue;
673
+ const candidatePath = path.join(pathEntry, candidate);
674
+ if (yield* isExecutableFile(candidatePath, platform, windowsPathExtensions)) {
675
+ matches.push(candidatePath);
676
+ if (isLast(candidatePath)) return matches;
677
+ break;
678
+ }
679
+ }
680
+ }
681
+ return matches;
682
+});
683
+
684
const resolveCommandPathForPlatform = Effect.fn("shell.resolveCommandPathForPlatform")(function* (
685
command: string,
686
options: CommandAvailabilityOptions & { readonly platform: NodeJS.Platform },
@@ -679,35 +720,15 @@ const resolveCommandPathForPlatform = Effect.fn("shell.resolveCommandPathForPlat
720
return cached.resolvedPath;
721
}
722
682
- // Keep case variants: Windows can make PATH directories case-sensitive.
683
- const pathEntries: string[] = [];
684
- const seenPathEntries = new Set<string>();
685
- for (const entry of pathValue.split(pathDelimiterForPlatform(platform))) {
686
- const pathEntry = stripWrappingQuotes(entry.trim());
687
- if (pathEntry.length === 0 || seenPathEntries.has(pathEntry)) continue;
688
-
689
- seenPathEntries.add(pathEntry);
690
- pathEntries.push(pathEntry);
691
- }
692
-
693
- const listings = yield* PathDirectoryListings;
694
- for (const pathEntry of pathEntries) {
695
- let listing = listings && (yield* Cache.get(listings, pathEntry));
696
- if (listings && listing?.names && listing.modified !== (yield* directoryMtime(pathEntry))) {
697
- yield* Cache.invalidate(listings, pathEntry);
698
- listing = yield* Cache.get(listings, pathEntry);
699
- }
700
- for (const candidate of commandCandidates) {
701
- if (listing?.names && !listing.names.has(candidate.toLowerCase())) continue;
702
- const candidatePath = path.join(pathEntry, candidate);
703
- if (yield* isExecutableFile(candidatePath, platform, windowsPathExtensions)) {
704
- cacheCommandResolution(cache, cacheKey, candidatePath, nowNanos);
705
- return candidatePath;
706
- }
707
- }
708
- }
709
- cacheCommandResolution(cache, cacheKey, null, nowNanos);
710
- return null;
723
+ const [resolvedPath = null] = yield* findOnPath(
724
+ pathValue,
725
+ commandCandidates,
726
+ platform,
727
+ windowsPathExtensions,
728
+ () => true,
729
+ );
730
+ cacheCommandResolution(cache, cacheKey, resolvedPath, nowNanos);
731
+ return resolvedPath;
732
});
733
734
export const resolveCommandPath = Effect.fn("shell.resolveCommandPath")(function* (
@@ -720,6 +741,24 @@ export const resolveCommandPath = Effect.fn("shell.resolveCommandPath")(function
741
});
742
});
743
744
+// Matches for a bare command in PATH order, up to the first one `until` accepts; not cached.
745
+export const resolveCommandPaths = Effect.fn("shell.resolveCommandPaths")(function* (
746
+ command: string,
747
+ options: CommandAvailabilityOptions & { readonly until: (match: string) => boolean },
748
+) {
749
+ const path = yield* Path.Path;
750
+ const platform = yield* HostProcess.Platform;
751
+ const env = options.env ?? (yield* HostProcess.Environment);
752
+ const windowsPathExtensions = platform === "win32" ? resolveWindowsPathExtensions(env) : [];
753
+ return yield* findOnPath(
754
+ resolvePathEnvironmentVariable(env),
755
+ resolveCommandCandidates(command, platform, windowsPathExtensions, path.extname),
756
+ platform,
757
+ windowsPathExtensions,
758
+ options.until,
759
+ );
760
+});
761
+
762
// Git 2.56 x64 uses ucrt64; ARM64 uses clangarm64; older x64/32-bit builds use mingw64/mingw32.
763
const GIT_FOR_WINDOWS_BUILDS = ["ucrt64", "clangarm64", "mingw64", "mingw32"] as const;
764