Skip to content
22 changes: 21 additions & 1 deletion core/tools/implementations/runTerminalCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,32 @@ import { getBooleanArg, getStringArg } from "../parseArgs";
* Falls back to home directory or temp directory if no workspace is available.
*/
function resolveWorkingDirectory(workspaceDirs: string[]): string {
// Handle vscode-remote://wsl+distro/path URIs (WSL2 remote workspaces)
const wslWorkspaceDir = workspaceDirs.find((dir) =>
dir.startsWith("vscode-remote://wsl"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way we could write this that isn't so specific to vscode-remote://wsl? I suppose the same issue applies to any non-file URIs? If not obvious this is fine for now but it feels a bit specific

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, that was overly narrow. I'll re-submit with it more widely applicable.

);
if (wslWorkspaceDir) {
try {
const url = new URL(wslWorkspaceDir);
return url.pathname; // e.g., "/home/user/project"
} catch {
// Fall through to other handlers
}
}

// Handle file:// URIs (local workspaces)
const fileWorkspaceDir = workspaceDirs.find((dir) =>
dir.startsWith("file:/"),
);
if (fileWorkspaceDir) {
return fileURLToPath(fileWorkspaceDir);
try {
return fileURLToPath(fileWorkspaceDir);
} catch {
// fileURLToPath can fail on malformed URIs or in some remote environments
// Fall through to default handling
}
}

// Default to user's home directory with fallbacks
try {
return process.env.HOME || process.env.USERPROFILE || process.cwd();
Expand Down
Loading