diff --git a/core/tools/implementations/runTerminalCommand.ts b/core/tools/implementations/runTerminalCommand.ts index bed8aceb8..e3bb9374d 100644 --- a/core/tools/implementations/runTerminalCommand.ts +++ b/core/tools/implementations/runTerminalCommand.ts @@ -114,7 +114,16 @@ export const runTerminalCommandImpl: ToolImpl = async (args, extras) => { const ideInfo = await extras.ide.getIdeInfo(); const toolCallId = extras.toolCallId || ""; - if (ENABLED_FOR_REMOTES.includes(ideInfo.remoteName)) { + // When extension host runs on Windows but connects to WSL, we can't spawn + // shells directly - the platform is "win32" but commands should run in Linux. + // Use ide.runCommand() instead to let VS Code handle the remote execution. + const isWindowsHostWithWslRemote = + process.platform === "win32" && ideInfo.remoteName === "wsl"; + + if ( + ENABLED_FOR_REMOTES.includes(ideInfo.remoteName) && + !isWindowsHostWithWslRemote + ) { // For streaming output if (extras.onPartialOutput) { try { diff --git a/core/tools/implementations/runTerminalCommand.vitest.ts b/core/tools/implementations/runTerminalCommand.vitest.ts index 089c85502..ea502f7c0 100644 --- a/core/tools/implementations/runTerminalCommand.vitest.ts +++ b/core/tools/implementations/runTerminalCommand.vitest.ts @@ -644,6 +644,30 @@ describe("runTerminalCommandImpl", () => { ).resolves.toBeDefined(); }); + it("should use ide.runCommand when Windows host connects to WSL", async () => { + // When extension runs on Windows but connects to WSL, we can't spawn + // shells directly - must use ide.runCommand instead + const originalPlatform = process.platform; + Object.defineProperty(process, "platform", { value: "win32" }); + + try { + const extras = createMockExtras({ remoteName: "wsl" }); + + const result = await runTerminalCommandImpl( + { command: "echo test" }, + extras, + ); + + // Should fall back to ide.runCommand, not try to spawn powershell.exe + expect(mockRunCommand).toHaveBeenCalledWith("echo test"); + expect(result[0].content).toContain("Terminal output not available"); + } finally { + Object.defineProperty(process, "platform", { + value: originalPlatform, + }); + } + }); + it("should handle dev-container environment", async () => { mockGetWorkspaceDirs.mockResolvedValue(["file:///workspace"]);