Improve shell PATH hydration and fallback detection #1799
Mergedjuliusmarmingemerged 4 commits into
main fromrefs/pull/1799/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
- apps/desktop/src/syncShellEnvironment.ts lines 52 to 56Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -21,7 +40,15 @@21- const shellEnvironment = (options.readEnvironment ?? readEnvironmentFromLoginShell)(shell, [22- "PATH",23- "SSH_AUTH_SOCK",24- ]);40+ try {41+ for (const shell of listLoginShellCandidates(platform, env.SHELL, options.userShell)) {42+ try {43+ Object.assign(shellEnvironment, readEnvironment(shell, LOGIN_SHELL_ENV_NAMES));44+ if (shellEnvironment.PATH) {45+ break;46+ }47+ } catch (error) {48+ logWarning(`Failed to read login shell environment from ${shell}.`, error);49+ }50+ }255126- if (shellEnvironment.PATH) {27- env.PATH = shellEnvironment.PATH;52+ const launchctlPath =53+ platform === "darwin" ? (options.readLaunchctlPath ?? readPathFromLaunchctl)() : undefined;54+ const mergedPath = mergePathEntries(shellEnvironment.PATH ?? launchctlPath, env.PATH, platform);
- apps/desktop/src/syncShellEnvironment.ts line 53OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -20,8 +39,15 @@203921- const shellEnvironment = (options.readEnvironment ?? readEnvironmentFromLoginShell)(shell, [22- "PATH",23- "SSH_AUTH_SOCK",24- ]);40+ try {41+ for (const shell of listLoginShellCandidates(platform, env.SHELL, options.userShell)) {42+ try {43+ Object.assign(shellEnvironment, readEnvironment(shell, LOGIN_SHELL_ENV_NAMES));44+ if (shellEnvironment.PATH) {45+ break;46+ }47+ } catch (error) {48+ logWarning(`Failed to read login shell environment from ${shell}.`, error);49+ }50+ }255126- if (shellEnvironment.PATH) {27- env.PATH = shellEnvironment.PATH;52+ const launchctlPath =53+ platform === "darwin" ? (options.readLaunchctlPath ?? readPathFromLaunchctl)() : undefined;packages/shared/src/shell.ts line 53OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -28,3 +34,20 @@34+ const seen = new Set<string>();35+ const candidates: string[] = [];36+37+ for (const candidate of [trimNonEmpty(shell), trimNonEmpty(userShell), fallbackShell]) {38+ if (!candidate || seen.has(candidate)) {39+ continue;40+ }41+ seen.add(candidate);42+ candidates.push(candidate);2843 }294430- return undefined;45+ return candidates;46+}47+48+export function resolveLoginShell(49+ platform: NodeJS.Platform,50+ shell: string | undefined,51+ userShell = readUserLoginShell(),52+): string | undefined {53+ return listLoginShellCandidates(platform, shell, userShell)[0];apps/desktop/src/syncShellEnvironment.ts line 75OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -28,7 +56,20 @@56+ env.PATH = mergedPath;2857 }29583059 if (!env.SSH_AUTH_SOCK && shellEnvironment.SSH_AUTH_SOCK) {3160 env.SSH_AUTH_SOCK = shellEnvironment.SSH_AUTH_SOCK;3261 }62+63+ for (const name of [64+ "HOMEBREW_PREFIX",65+ "HOMEBREW_CELLAR",66+ "HOMEBREW_REPOSITORY",67+ "XDG_CONFIG_HOME",68+ "XDG_DATA_HOME",69+ ] as const) {70+ if (!env[name] && shellEnvironment[name]) {71+ env[name] = shellEnvironment[name];72+ }73+ }3374 } catch {34- // Keep inherited environment if shell lookup fails.75+ logWarning("Failed to synchronize the desktop shell environment.");
juliusmarminge merged this2e42f3f
juliusmarminge closed this
Sign in to join this conversation.



macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed