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 23, 00:30 UTC
fix(server): select linked files when revealing on Linux (#14044)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Akshar Patel committed
Oct 19, 2026 at 20:28 UTC
a3de2ae057b93c9097cf5abef0e581b4302bc0b7
2 files changed
+201
-7
apps/server/src/process/externalLauncher.test.ts
+139
-2
@@ -11,8 +11,10 @@ import * as Effect from "effect/Effect";
11
import * as Exit from "effect/Exit";
12
import * as Fiber from "effect/Fiber";
13
import * as FileSystem from "effect/FileSystem";
14
+import * as Latch from "effect/Latch";
15
import * as Layer from "effect/Layer";
16
import * as Path from "effect/Path";
17
+import * as PlatformError from "effect/PlatformError";
18
import * as Sink from "effect/Sink";
19
import * as Stream from "effect/Stream";
20
import * as TestClock from "effect/testing/TestClock";
@@ -29,6 +31,7 @@ import * as ExternalLauncher from "./externalLauncher.ts";
31
const windowsHost = HostProcess.Platform.defaultValue() === "win32";
32
33
interface MockSpawnResult {
34
+ readonly spawnError?: PlatformError.PlatformError;
35
readonly exitCode?: number;
36
readonly stdout?: string;
37
readonly stall?: boolean;
@@ -69,15 +72,17 @@ const layerTest = (input: {
72
const layerSpawner = Layer.succeed(
73
ChildProcessSpawner.ChildProcessSpawner,
74
ChildProcessSpawner.make((command) =>
72
- Effect.sync(() => {
75
+ Effect.gen(function* () {
76
assert.equal(ChildProcess.isStandardCommand(command), true);
77
if (!ChildProcess.isStandardCommand(command)) {
78
throw new Error("Expected a standard command");
79
}
80
input.onSpawn?.(command);
81
+ const result = input.spawnResult?.(command);
82
+ if (result?.spawnError) return yield* result.spawnError;
83
return makeMockDetachedHandle({
84
...(input.onUnref === undefined ? {} : { onUnref: input.onUnref }),
80
- ...input.spawnResult?.(command),
85
+ ...result,
86
});
87
}),
88
),
@@ -857,6 +862,138 @@ it.effect.skipIf(windowsHost)("reveals by opening the containing directory on Li
862
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
863
);
864
865
+for (const wsl of [false, true]) {
866
+ it.effect.skipIf(windowsHost)(
867
+ "selects a file over D-Bus on " + (wsl ? "WSLg without interop PowerShell" : "Linux"),
868
+ () =>
869
+ Effect.gen(function* () {
870
+ const fileSystem = yield* FileSystem.FileSystem;
871
+ const path = yield* Path.Path;
872
+ const binDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-editors-" });
873
+ for (const name of ["xdg-open", "xdg-mime", "gdbus", ...(wsl ? ["explorer.exe"] : [])]) {
874
+ const filePath = path.join(binDir, name);
875
+ yield* fileSystem.writeFileString(filePath, "#!/bin/sh\n");
876
+ yield* fileSystem.chmod(filePath, 0o755);
877
+ }
878
+ const target = "/workspace/media/a 'quoted' \"clip\" #100% ? é\\name.mp4";
879
+ const spawnedCommands: ChildProcess.StandardCommand[] = [];
880
+ yield* Effect.gen(function* () {
881
+ const launcher = yield* ExternalLauncher.ExternalLauncher;
882
+ yield* launcher.launchEditor({ editor: "file-manager", cwd: target, reveal: true });
883
+ }).pipe(
884
+ Effect.provide(
885
+ layerTest({
886
+ platform: "linux",
887
+ env: {
888
+ PATH: binDir,
889
+ WAYLAND_DISPLAY: "wayland-1",
890
+ ...(wsl
891
+ ? { WSL_DISTRO_NAME: "Ubuntu-24.04", WSL_INTEROP: "/run/WSL/1_interop" }
892
+ : {}),
893
+ },
894
+ onSpawn: (command) => spawnedCommands.push(command),
895
+ spawnResult: (command) =>
896
+ command.command === "xdg-mime"
897
+ ? { stdout: "com.thisisgm.flea.desktop\n" }
898
+ : undefined,
899
+ }),
900
+ ),
901
+ );
902
+
903
+ const reveal = spawnedCommands.find((command) => command.command === "gdbus");
904
+ assert.ok(reveal);
905
+ assert.deepEqual(reveal.args, [
906
+ "call",
907
+ "--session",
908
+ "--dest",
909
+ "org.freedesktop.FileManager1",
910
+ "--object-path",
911
+ "/org/freedesktop/FileManager1",
912
+ "--method",
913
+ "org.freedesktop.FileManager1.ShowItems",
914
+ "[\"file:///workspace/media/a%20'quoted'%20%22clip%22%20%23100%25%20%3F%20%C3%A9%5Cname.mp4\"]",
915
+ "",
916
+ ]);
917
+ assert.deepEqual(
918
+ spawnedCommands.filter((command) => command.command !== "xdg-mime"),
919
+ [reveal],
920
+ );
921
+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
922
+ );
923
+}
924
+
925
+for (const scenario of ["rejected", "spawn-error", "stalled"] as const) {
926
+ it.effect.skipIf(windowsHost)("opens the containing directory when D-Bus is " + scenario, () =>
927
+ Effect.gen(function* () {
928
+ const fileSystem = yield* FileSystem.FileSystem;
929
+ const path = yield* Path.Path;
930
+ const binDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-editors-" });
931
+ for (const name of ["xdg-open", "xdg-mime", "gdbus"]) {
932
+ const filePath = path.join(binDir, name);
933
+ yield* fileSystem.writeFileString(filePath, "#!/bin/sh\n");
934
+ yield* fileSystem.chmod(filePath, 0o755);
935
+ }
936
+
937
+ const spawnedCommands: ChildProcess.StandardCommand[] = [];
938
+ const started = yield* Latch.make();
939
+ const launch = Effect.gen(function* () {
940
+ const launcher = yield* ExternalLauncher.ExternalLauncher;
941
+ yield* launcher.launchEditor({
942
+ editor: "file-manager",
943
+ cwd: "/workspace/media/linux-mini-v2.mp4",
944
+ reveal: true,
945
+ });
946
+ }).pipe(
947
+ Effect.provide(
948
+ layerTest({
949
+ platform: "linux",
950
+ env: { PATH: binDir, DISPLAY: ":0" },
951
+ onSpawn: (command) => {
952
+ spawnedCommands.push(command);
953
+ if (command.command === "gdbus") started.openUnsafe();
954
+ },
955
+ spawnResult: (command) => {
956
+ if (command.command === "xdg-mime") return { stdout: "org.gnome.Nautilus.desktop\n" };
957
+ if (command.command !== "gdbus") return undefined;
958
+ if (scenario === "spawn-error") {
959
+ return {
960
+ spawnError: new PlatformError.PlatformError(
961
+ new PlatformError.SystemError({
962
+ _tag: "NotFound",
963
+ module: "ChildProcess",
964
+ method: "spawn",
965
+ pathOrDescriptor: "gdbus",
966
+ }),
967
+ ),
968
+ };
969
+ }
970
+ return { exitCode: 1, stall: scenario === "stalled" };
971
+ },
972
+ }),
973
+ ),
974
+ );
975
+ if (scenario === "stalled") {
976
+ const fiber = yield* launch.pipe(Effect.forkChild);
977
+ yield* started.await;
978
+ yield* TestClock.adjust("1999 millis");
979
+ assert.isUndefined(spawnedCommands.find((command) => command.command === "xdg-open"));
980
+ yield* TestClock.adjust("1 millis");
981
+ yield* Fiber.join(fiber);
982
+ } else {
983
+ yield* launch;
984
+ }
985
+
986
+ assert.deepEqual(
987
+ spawnedCommands
988
+ .filter((command) => command.command !== "xdg-mime")
989
+ .map((command) => command.command),
990
+ ["gdbus", "xdg-open"],
991
+ );
992
+ assert.deepEqual(spawnedCommands.at(-1)?.args, ["/workspace/media"]);
993
+ }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
994
+ );
995
+}
996
+
997
it.effect.skipIf(windowsHost)(
998
"does not advertise a Linux file manager without a graphical session",
999
() =>
apps/server/src/process/externalLauncher.ts
+62
-5
@@ -652,12 +652,69 @@ const resolveFileManagerRevealLaunch = Effect.fn("resolveFileManagerRevealLaunch
652
};
653
}
654
655
- // Linux file managers have no portable "select this file" flag, so open
656
- // the containing directory instead.
655
const path = yield* Path.Path;
656
return { editor: "file-manager", target, command, args: [path.dirname(target)] };
657
});
658
659
+const tryRevealLinuxItem = Effect.fn("externalLauncher.tryRevealLinuxItem")(
660
+ function* (target: string) {
661
+ const env = yield* readCommandLookupEnv;
662
+ if (!(yield* isCommandAvailable("gdbus", { env }))) return false;
663
+
664
+ const path = yield* Path.Path;
665
+ const uri = yield* path.toFileUrl(target);
666
+ const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
667
+ const exitCode = yield* spawner.exitCode(
668
+ ChildProcess.make(
669
+ "gdbus",
670
+ [
671
+ "call",
672
+ "--session",
673
+ "--dest",
674
+ "org.freedesktop.FileManager1",
675
+ "--object-path",
676
+ "/org/freedesktop/FileManager1",
677
+ "--method",
678
+ "org.freedesktop.FileManager1.ShowItems",
679
+ // File URLs percent-encode the double quotes and backslashes GVariant would interpret.
680
+ `["${uri.href}"]`,
681
+ "",
682
+ ],
683
+ {
684
+ stdin: "ignore",
685
+ stdout: "ignore",
686
+ stderr: "ignore",
687
+ // Timeout waits for scoped cleanup, even if the helper ignores SIGTERM.
688
+ forceKillAfter: "1 second",
689
+ },
690
+ ),
691
+ );
692
+ return exitCode === 0;
693
+ },
694
+ Effect.timeout("2 seconds"),
695
+ Effect.catchTags({
696
+ BadArgument: () => Effect.succeed(false),
697
+ PlatformError: () => Effect.succeed(false),
698
+ TimeoutError: () => Effect.succeed(false),
699
+ }),
700
+);
701
+
702
+const launchEditor = Effect.fn("externalLauncher.launchEditor")(function* (
703
+ input: LaunchEditorInput,
704
+) {
705
+ const launch = yield* resolveEditorLaunch(input);
706
+ if (
707
+ input.editor === "file-manager" &&
708
+ input.reveal === true &&
709
+ launch.command === "xdg-open" &&
710
+ (yield* HostProcess.Platform) === "linux" &&
711
+ (yield* tryRevealLinuxItem(launch.target))
712
+ ) {
713
+ return;
714
+ }
715
+ yield* launchEditorProcess(launch);
716
+});
717
+
718
const launchAndUnref = Effect.fn("externalLauncher.launchAndUnref")(function* (
719
launch: ProcessLaunch,
720
onError: (cause: unknown) => ExternalLauncherError,
@@ -817,9 +874,9 @@ export const make = Effect.gen(function* () {
874
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
875
),
876
launchEditor: (input) =>
820
- provideCommandResolutionServices(
821
- Effect.flatMap(resolveEditorLaunch(input), launchEditorProcess),
822
- ).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner)),
877
+ provideCommandResolutionServices(launchEditor(input)).pipe(
878
+ Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
879
+ ),
880
});
881
});
882