From 3a2181c15a2eca9aa1304ccfbcba4375f0dbeab7 Mon Sep 17 00:00:00 2001 From: "Dr. Armando Vaquera (proyectoauraorg)" Date: Thu, 21 May 2026 09:26:29 -0600 Subject: [PATCH] fix(shell): default to PowerShell on Windows when no terminal profile is set (#82) getShell() fell through to COMSPEC (cmd.exe) when VS Code had no explicit Windows terminal profile, so the system prompt advertised cmd.exe even though the integrated terminal actually launches PowerShell (VS Code's modern default). Return Windows PowerShell from getWindowsShellFromVSCode() in that case so the prompt and rules match the real shell. Explicitly configured cmd/WSL/custom profiles are unaffected. Co-Authored-By: Claude Opus 4.7 --- src/utils/__tests__/shell.spec.ts | 20 ++++++++++++-------- src/utils/shell.ts | 8 +++++++- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/utils/__tests__/shell.spec.ts b/src/utils/__tests__/shell.spec.ts index 8f370e4d7f..828e7b62a2 100644 --- a/src/utils/__tests__/shell.spec.ts +++ b/src/utils/__tests__/shell.spec.ts @@ -173,23 +173,27 @@ describe("Shell Detection Tests", () => { expect(getShell()).toBe("C:\\Windows\\System32\\cmd.exe") }) - it("respects userInfo() if no VS Code config is available and shell is allowed", () => { + it("defaults to Windows PowerShell when VS Code has no configured profile", () => { + // Modern VS Code launches PowerShell by default on Windows (issue #82), so + // getShell() should report PowerShell rather than falling through to cmd.exe. vscode.workspace.getConfiguration = () => ({ get: () => undefined }) as any vi.mocked(userInfo).mockReturnValue({ shell: "C:\\Program Files\\PowerShell\\7\\pwsh.exe" } as any) - expect(getShell()).toBe("C:\\Program Files\\PowerShell\\7\\pwsh.exe") + expect(getShell()).toBe("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe") }) - it("falls back to safe shell when userInfo() returns non-allowlisted shell", () => { - vscode.workspace.getConfiguration = () => ({ get: () => undefined }) as any - vi.mocked(userInfo).mockReturnValue({ shell: "C:\\Custom\\PowerShell.exe" } as any) + it("falls back to safe shell when the configured profile path is non-allowlisted", () => { + mockVsCodeConfig("windows", "Custom", { + Custom: { path: "C:\\Custom\\evil.exe" }, + }) expect(getShell()).toBe("C:\\Windows\\System32\\cmd.exe") }) - it("falls back to safe shell when COMSPEC is non-allowlisted", () => { - vscode.workspace.getConfiguration = () => ({ get: () => undefined }) as any - process.env.COMSPEC = "D:\\CustomCmd\\cmd.exe" + it("uses cmd.exe when a Command Prompt profile is explicitly configured", () => { + mockVsCodeConfig("windows", "Command Prompt", { + "Command Prompt": { path: "C:\\Windows\\System32\\cmd.exe" }, + }) expect(getShell()).toBe("C:\\Windows\\System32\\cmd.exe") }) diff --git a/src/utils/shell.ts b/src/utils/shell.ts index 45253c31b0..d39395ade3 100644 --- a/src/utils/shell.ts +++ b/src/utils/shell.ts @@ -188,7 +188,13 @@ function normalizeShellPath(path: string | string[] | undefined): string | null function getWindowsShellFromVSCode(): string | null { const { defaultProfileName, profiles } = getWindowsTerminalConfig() if (!defaultProfileName) { - return null + // No explicit Windows terminal profile is configured. VS Code's built-in + // default on modern Windows is PowerShell (not cmd.exe), and that is the + // shell the integrated terminal actually launches. Mirror it here so the + // system prompt advertises the real shell instead of falling through to + // COMSPEC (cmd.exe). Windows PowerShell is always present, so it is a safe + // allowlisted default. See issue #82. + return SHELL_PATHS.POWERSHELL_LEGACY } const profile = profiles[defaultProfileName]