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, 13:30 UTC
fix(shared): preserve whitespace in POSIX PATH directories (#33840)
Co-authored-by: Simone <185146821+Lucenx9@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Simone committed
Nov 14, 2026 at 18:17 UTC
ccf7ead6a4a1c1ffd94133f0edd843de4e22b934
4 files changed
+54
-41
apps/desktop/src/shell/DesktopShellEnvironment.test.ts
+3
-3
@@ -486,7 +486,7 @@ describe("DesktopShellEnvironment", () => {
486
Effect.gen(function* () {
487
const env: NodeJS.ProcessEnv = {
488
SHELL: "/bin/zsh",
489
- PATH: "/Users/test/.local/bin:/usr/bin",
489
+ PATH: " /Users/test/.local/bin:/usr/bin",
490
};
491
const commands: ChildProcess.Command[] = [];
492
@@ -496,7 +496,7 @@ describe("DesktopShellEnvironment", () => {
496
handler: (command) => {
497
commands.push(command);
498
return envOutput({
499
- PATH: "/opt/homebrew/bin:/usr/bin",
499
+ PATH: "/opt/homebrew/bin:/usr/bin:/opt/bin ",
500
SSH_AUTH_SOCK: "/tmp/secretive.sock",
501
HOMEBREW_PREFIX: "/opt/homebrew",
502
});
@@ -505,7 +505,7 @@ describe("DesktopShellEnvironment", () => {
505
506
assert.equal(commands.length, 1);
507
assert.equal(commands[0]?._tag === "StandardCommand" ? commands[0].command : "", "/bin/zsh");
508
- assert.equal(env.PATH, "/opt/homebrew/bin:/usr/bin:/Users/test/.local/bin");
508
+ assert.equal(env.PATH, "/opt/homebrew/bin:/usr/bin:/opt/bin : /Users/test/.local/bin");
509
assert.equal(env.SSH_AUTH_SOCK, "/tmp/secretive.sock");
510
assert.equal(env.HOMEBREW_PREFIX, "/opt/homebrew");
511
assert.isTrue(prepared);
apps/desktop/src/shell/DesktopShellEnvironment.ts
+13
-33
@@ -3,6 +3,7 @@ import {
3
applyShellEnvironment,
4
buildEnvironmentCaptureCommand,
5
listLoginShellCandidates,
6
+ mergePathValues,
7
readUserLoginShell,
8
setWindowsPath,
9
} from "@t3tools/shared/shell";
@@ -131,10 +132,12 @@ const trimNonEmpty = (value: string | null | undefined): Option.Option<string> =
132
Option.filter((entry) => entry.length > 0),
133
);
134
134
-const pathDelimiter = (platform: NodeJS.Platform) => (platform === "win32" ? ";" : ":");
135
+// POSIX directory names may begin or end with whitespace; mergePathValues trims only on Windows.
136
+const nonEmptyPath = (value: string | null | undefined): Option.Option<string> =>
137
+ Option.fromNullishOr(value).pipe(Option.filter((entry) => entry.length > 0));
138
139
const readEnvPath = (env: NodeJS.ProcessEnv): Option.Option<string> =>
137
- trimNonEmpty(env.PATH ?? env.Path ?? env.path);
140
+ nonEmptyPath(env.PATH ?? env.Path ?? env.path);
141
142
const normalizeRuntimeDir = (value: string): string => value.replace(/\/+$/u, "");
143
@@ -153,39 +156,16 @@ const linuxRuntimeDirCandidates = (
156
return candidates.filter((candidate) => candidate.length > 0);
157
};
158
156
-const pathComparisonKey = (entry: string, platform: NodeJS.Platform) => {
157
- const normalized = entry.trim().replace(/^"+|"+$/g, "");
158
- return platform === "win32" ? normalized.toLowerCase() : normalized;
159
-};
160
-
161
-const sanitizePathEntry = (entry: string, platform: NodeJS.Platform) =>
162
- platform === "win32" ? entry.replaceAll('"', "") : entry;
163
-
159
const mergePaths = (
160
platform: NodeJS.Platform,
161
values: ReadonlyArray<Option.Option<string>>,
167
-): Option.Option<string> => {
168
- const delimiter = pathDelimiter(platform);
169
- const entries: string[] = [];
170
- const seen = new Set<string>();
171
-
172
- for (const value of values) {
173
- if (Option.isNone(value)) continue;
174
-
175
- for (const entry of value.value.split(delimiter)) {
176
- const sanitized = sanitizePathEntry(entry.trim(), platform);
177
- if (sanitized.length === 0) continue;
178
-
179
- const key = pathComparisonKey(sanitized, platform);
180
- if (key.length === 0 || seen.has(key)) continue;
181
-
182
- seen.add(key);
183
- entries.push(sanitized);
184
- }
185
- }
186
-
187
- return entries.length > 0 ? Option.some(entries.join(delimiter)) : Option.none();
188
-};
162
+): Option.Option<string> =>
163
+ Option.fromNullishOr(
164
+ values.reduce<string | undefined>(
165
+ (merged, value) => mergePathValues(merged, Option.getOrUndefined(value), platform),
166
+ undefined,
167
+ ),
168
+ );
169
170
const knownWindowsCliDirs = (env: NodeJS.ProcessEnv): ReadonlyArray<string> => [
171
...trimNonEmpty(env.APPDATA).pipe(
@@ -484,7 +464,7 @@ const installPosixEnvironment = Effect.fn("desktop.shellEnvironment.installPosix
464
? yield* readLaunchctlPath(config.env)
465
: Option.none<string>();
466
const mergedPath = mergePaths(config.platform, [
487
- trimNonEmpty(shellEnvironment.PATH).pipe(Option.orElse(() => launchctlPath)),
467
+ nonEmptyPath(shellEnvironment.PATH).pipe(Option.orElse(() => launchctlPath)),
468
readEnvPath(config.env),
469
]);
470
packages/shared/src/shell.test.ts
+29
@@ -251,6 +251,9 @@ describe("mergePathEntries", () => {
251
expect(
252
mergePathEntries("/opt/homebrew/bin:/usr/bin", "/Users/test/.local/bin:/usr/bin", "darwin"),
253
).toBe("/opt/homebrew/bin:/usr/bin:/Users/test/.local/bin");
254
+ expect(mergePathEntries("/opt/bin :/opt/bin", "/opt/bin :/usr/bin", "linux")).toBe(
255
+ "/opt/bin :/opt/bin:/usr/bin",
256
+ );
257
});
258
});
259
@@ -511,10 +514,36 @@ describe("mergePathValues", () => {
514
expect(mergePathValues("/usr/local/bin:/usr/bin", "/usr/bin:/USR/BIN", "linux")).toBe(
515
"/usr/local/bin:/usr/bin:/USR/BIN",
516
);
517
+ expect(mergePathValues("/opt/bin :/opt/bin", "/opt/bin :/usr/bin", "linux")).toBe(
518
+ "/opt/bin :/opt/bin:/usr/bin",
519
+ );
520
});
521
});
522
523
effectIt.layer(NodeServices.layer)("resolveCommandPath", (it) => {
524
+ it.effect("finds executables in a POSIX PATH directory ending in whitespace", () =>
525
+ Effect.gen(function* () {
526
+ const fs = yield* FileSystem.FileSystem;
527
+ const path = yield* Path.Path;
528
+ const cwd = yield* fs.makeTempDirectoryScoped({ directory: ".", prefix: "t3-path-" });
529
+ const directory = `${cwd}/bin \u00a0`;
530
+ yield* fs.makeDirectory(directory);
531
+ const executable = `${directory}/audit-command`;
532
+ yield* fs.writeFileString(executable, "#!/bin/sh\n");
533
+ yield* fs.chmod(executable, 0o755);
534
+ const env = { PATH: directory };
535
+
536
+ expect(
537
+ yield* resolveCommandPath("audit-command", { env }).pipe(
538
+ Effect.provideService(HostProcess.Platform, "linux"),
539
+ Effect.provideService(CommandResolutionCache, new Map()),
540
+ ),
541
+ ).toBe(path.join(directory, "audit-command"));
542
+ const resolveExecutable = yield* SpawnExecutableResolution;
543
+ expect(resolveExecutable("audit-command", "linux", env)).toBe(executable);
544
+ }),
545
+ );
546
+
547
const recordProbes = (env: NodeJS.ProcessEnv) =>
548
Effect.gen(function* () {
549
const probed: Array<string> = [];
packages/shared/src/shell.ts
+9
-5
@@ -106,7 +106,7 @@ function resolveSpawnExecutableWithNode(
106
}
107
108
for (const pathEntry of (readEnvPath(env) ?? "").split(pathDelimiterForPlatform(platform))) {
109
- const normalizedPathEntry = stripWrappingQuotes(pathEntry.trim());
109
+ const normalizedPathEntry = stripWrappingQuotes(trimPathEntry(pathEntry, platform));
110
if (normalizedPathEntry.length === 0) continue;
111
for (const candidate of candidates) {
112
const candidatePath = path.join(normalizedPathEntry, candidate);
@@ -188,7 +188,7 @@ export function mergePathEntries(
188
for (const pathValue of [preferredPath, inheritedPath]) {
189
if (!pathValue) continue;
190
for (const entry of pathValue.split(delimiter)) {
191
- const trimmedEntry = entry.trim();
191
+ const trimmedEntry = trimPathEntry(entry, platform);
192
if (!trimmedEntry || seen.has(trimmedEntry)) {
193
continue;
194
}
@@ -443,12 +443,16 @@ function stripWrappingQuotes(value: string): string {
443
return value.replace(/^"+|"+$/g, "");
444
}
445
446
+function trimPathEntry(entry: string, platform: NodeJS.Platform): string {
447
+ return platform === "win32" ? entry.trim() : entry;
448
+}
449
+
450
function pathDelimiterForPlatform(platform: NodeJS.Platform): string {
451
return platform === "win32" ? WINDOWS_PATH_DELIMITER : POSIX_PATH_DELIMITER;
452
}
453
454
function normalizePathEntryForComparison(entry: string, platform: NodeJS.Platform): string {
451
- const normalized = stripWrappingQuotes(entry.trim());
455
+ const normalized = stripWrappingQuotes(trimPathEntry(entry, platform));
456
return platform === "win32" ? normalized.toLowerCase() : normalized;
457
}
458
@@ -469,7 +473,7 @@ export function mergePathValues(
473
if (!rawValue) continue;
474
475
for (const entry of rawValue.split(delimiter)) {
472
- const sanitized = sanitizePathEntry(entry.trim(), platform);
476
+ const sanitized = sanitizePathEntry(trimPathEntry(entry, platform), platform);
477
if (sanitized.length === 0) continue;
478
479
const normalized = normalizePathEntryForComparison(sanitized, platform);
@@ -657,7 +661,7 @@ const findOnPath = Effect.fnUntraced(function* (
661
const pathEntries: string[] = [];
662
const seenPathEntries = new Set<string>();
663
for (const entry of pathValue.split(pathDelimiterForPlatform(platform))) {
660
- const pathEntry = stripWrappingQuotes(entry.trim());
664
+ const pathEntry = stripWrappingQuotes(trimPathEntry(entry, platform));
665
if (pathEntry.length === 0 || seenPathEntries.has(pathEntry)) continue;
666
667
seenPathEntries.add(pathEntry);