@devries-cameron20 / t3code Mirror · read-only / commits / 4e274aed25
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 22, 13:15 UTC

fix(shared): Open in Zed prefers zeditor over the ZFS zed on Linux (#23416)

Signed-off-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com> Co-authored-by: Pujitha Paladugu <10557236+pujitha24@users.noreply.github.com> Co-authored-by: maria-rcks <maria@kuuro.net>

Pujitha Paladugu committed Oct 29, 2026 at 11:02 UTC 4e274aed25fdb94d71320c4565a1c3c35ca17093
2 files changed +114 -3
apps/server/src/process/externalLauncher.test.ts
+103
@@ -10,11 +10,14 @@ import * as Fiber from "effect/Fiber";
10 import * as FileSystem from "effect/FileSystem";
11 import * as Layer from "effect/Layer";
12 import * as Path from "effect/Path";
13 +import * as Option from "effect/Option";
14 import * as PlatformError from "effect/PlatformError";
15 import * as Sink from "effect/Sink";
16 import * as Stream from "effect/Stream";
17 import { ChildProcess, ChildProcessSpawner } from "effect/process";
18
19 +import { EDITORS } from "@t3tools/contracts";
20 +import { resolveEditorCommand } from "@t3tools/shared/editor";
21 import * as HostProcess from "@t3tools/shared/HostProcess";
22 import { SpawnExecutableResolution } from "@t3tools/shared/shell";
23 import * as ExternalLauncher from "./externalLauncher.ts";
@@ -335,6 +338,106 @@ for (const cwd of ["/workspace with spaces/", "/workspace with spaces/file.ts:12
338 );
339 }
340
341 +for (const { layout, pathNames, fallbackNames, expected } of [
342 + { layout: "PATH", pathNames: ["zed", "zeditor"], fallbackNames: [], expected: "zeditor" },
343 + {
344 + layout: "mixed locations",
345 + pathNames: ["zed"],
346 + fallbackNames: ["zeditor"],
347 + expected: "fallback",
348 + },
349 + {
350 + layout: "fallback directory",
351 + pathNames: [],
352 + fallbackNames: ["zed", "zeditor"],
353 + expected: "fallback",
354 + },
355 +]) {
356 + it.effect.skipIf(windowsHost)(`prefers the Zed editor on Linux with ${layout}`, () =>
357 + Effect.gen(function* () {
358 + const fs = yield* FileSystem.FileSystem;
359 + const path = yield* Path.Path;
360 + const home = yield* fs.makeTempDirectoryScoped({ prefix: "t3-zed-linux-" });
361 + const binDir = path.join(home, "bin");
362 + const fallbackDir = path.join(home, ".local/bin");
363 + for (const [dir, names] of [
364 + [binDir, pathNames],
365 + [fallbackDir, fallbackNames],
366 + ] as const) {
367 + yield* fs.makeDirectory(dir, { recursive: true });
368 + for (const name of names) {
369 + yield* fs.writeFileString(path.join(dir, name), "#!/bin/sh\n");
370 + yield* fs.chmod(path.join(dir, name), 0o755);
371 + }
372 + }
373 +
374 + let spawned: ChildProcess.StandardCommand | undefined;
375 + yield* Effect.gen(function* () {
376 + const launcher = yield* ExternalLauncher.ExternalLauncher;
377 + assert.include(yield* launcher.resolveAvailableEditors(), "zed");
378 + yield* launcher.launchEditor({ editor: "zed", cwd: "/workspace" });
379 + }).pipe(
380 + Effect.provide(
381 + layerTest({
382 + platform: "linux",
383 + env: { HOME: home, PATH: binDir },
384 + onSpawn: (command) => {
385 + spawned = command;
386 + },
387 + }),
388 + ),
389 + );
390 + assert.ok(spawned);
391 + assert.equal(
392 + spawned.command,
393 + expected === "fallback" ? path.join(fallbackDir, "zeditor") : expected,
394 + );
395 + assert.deepEqual(spawned.args, ["/workspace"]);
396 + }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
397 + );
398 +}
399 +
400 +it.effect.skipIf(windowsHost)("prefers zeditor in a later Linux fallback directory", () =>
401 + Effect.gen(function* () {
402 + const fs = yield* FileSystem.FileSystem;
403 + const path = yield* Path.Path;
404 + const home = yield* fs.makeTempDirectoryScoped({ prefix: "t3-zed-fallback-" });
405 + const localBin = path.join(home, ".local/bin");
406 + const systemBin = path.join(home, "system-bin");
407 + for (const [dir, name] of [
408 + [localBin, "zed"],
409 + [systemBin, "zeditor"],
410 + ] as const) {
411 + yield* fs.makeDirectory(dir, { recursive: true });
412 + const executable = path.join(dir, name);
413 + yield* fs.writeFileString(executable, "#!/bin/sh\n");
414 + yield* fs.chmod(executable, 0o755);
415 + }
416 + const editor = EDITORS.find((editor) => editor.id === "zed")!;
417 + const resolve = resolveEditorCommand(editor, { HOME: home, PATH: "" }).pipe(
418 + Effect.provideService(HostProcess.Platform, "linux"),
419 + Effect.provideService(Path.Path, {
420 + ...path,
421 + join: (...parts) =>
422 + path.join(
423 + ...parts.map((part) =>
424 + ["/usr/local/bin", "/usr/bin", "/snap/bin"].includes(part) ? systemBin : part,
425 + ),
426 + ),
427 + }),
428 + );
429 + assert.deepEqual(
430 + yield* resolve,
431 + Option.some({ command: path.join(systemBin, "zeditor"), baseArgs: [] }),
432 + );
433 + yield* fs.remove(path.join(systemBin, "zeditor"));
434 + assert.deepEqual(
435 + yield* resolve,
436 + Option.some({ command: path.join(localBin, "zed"), baseArgs: [] }),
437 + );
438 + }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
439 +);
440 +
441 it.effect.each([
442 { editor: "webstorm", installPath: "Applications/WebStorm 2026.2.app/Contents/MacOS/webstorm" },
443 { editor: "idea", installPath: "Applications/IntelliJ IDEA 2026.1.4.app/Contents/MacOS/idea" },
packages/shared/src/editor.ts
+11 -3
@@ -34,7 +34,8 @@ export const resolveEditorCommand = Effect.fn("editor.resolveEditorCommand")(fun
34 const platform = yield* HostProcess.Platform;
35 // Prefer Zed's macOS bundle because OpenZFS also installs a zed executable.
36 const preferBundle = platform === "darwin" && editor.id === "zed";
37 - if (!preferBundle) {
37 + const preferZeditor = platform === "linux" && editor.id === "zed";
38 + if (!preferBundle && !preferZeditor) {
39 for (const command of editor.commands) {
40 if (yield* isCommandAvailable(command, { env })) return Option.some({ command, baseArgs });
41 }
@@ -129,8 +130,15 @@ export const resolveEditorCommand = Effect.fn("editor.resolveEditorCommand")(fun
130 const dataHome = env.XDG_DATA_HOME || (home ? path.join(home, ".local/share") : undefined);
131 if (dataHome) dirs.push(path.join(dataHome, "JetBrains/Toolbox/scripts"));
132 }
132 - for (const dir of dirs) {
133 - for (const name of editor.commands) candidates.push(path.join(dir, name));
133 + if (preferZeditor) {
134 + // Linux packages use zeditor because OpenZFS owns the zed command.
135 + for (const name of ["zeditor", "zed"]) {
136 + candidates.push(name, ...dirs.map((dir) => path.join(dir, name)));
137 + }
138 + } else {
139 + for (const dir of dirs) {
140 + for (const name of editor.commands) candidates.push(path.join(dir, name));
141 + }
142 }
143 }
144