Files
continue/core/util/shellPath.ts
shanevcantwell 939b44b39f fix: detect WSL remote for shell PATH resolution
When Windows host connects to WSL remote, getEnvPathFromUserShell() was
returning undefined because it checked only process.platform === "win32".

Add remoteName parameter to getEnvPathFromUserShell() and use the
isWindowsHostWithWslRemote pattern (consistent with resolveCommandForPlatform)
to allow shell PATH detection for WSL remotes.

Fixes #9737

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-26 18:51:11 -07:00

31 lines
862 B
TypeScript

import { exec } from "child_process";
import { promisify } from "util";
const execAsync = promisify(exec);
export async function getEnvPathFromUserShell(
remoteName?: string,
): Promise<string | undefined> {
const isWindowsHostWithWslRemote =
process.platform === "win32" && remoteName === "wsl";
if (process.platform === "win32" && !isWindowsHostWithWslRemote) {
return undefined;
}
if (!process.env.SHELL) {
return undefined;
}
try {
// Source common profile files
const command = `${process.env.SHELL} -l -c 'for f in ~/.zprofile ~/.zshrc ~/.bash_profile ~/.bashrc; do [ -f "$f" ] && source "$f" 2>/dev/null; done; echo $PATH'`;
const { stdout } = await execAsync(command, {
encoding: "utf8",
});
return stdout.trim();
} catch (error) {
return process.env.PATH; // Fallback to current PATH
}
}