Skip to content

fix(shell): report PowerShell on Windows when no profile is configured (#82)#239

Open
proyectoauraorg wants to merge 1 commit into
Zoo-Code-Org:mainfrom
proyectoauraorg:fix/82-shell-detection
Open

fix(shell): report PowerShell on Windows when no profile is configured (#82)#239
proyectoauraorg wants to merge 1 commit into
Zoo-Code-Org:mainfrom
proyectoauraorg:fix/82-shell-detection

Conversation

@proyectoauraorg
Copy link
Copy Markdown
Contributor

@proyectoauraorg proyectoauraorg commented May 21, 2026

Summary

Fixes #82. On Windows the system prompt told the model the shell was cmd.exe, but the integrated terminal actually runs PowerShell — VS Code's default on modern Windows. The two shell-detection paths disagreed.

getShell() (used by the system prompt in system-info.ts and shell-specific rules.ts) called getWindowsShellFromVSCode(), which returned null when no explicit terminal.integrated.defaultProfile.windows was set. getShell() then fell through to COMSPEC (cmd.exe), which is not what VS Code launches.

Fix

When no Windows terminal profile is configured, getWindowsShellFromVSCode() now returns Windows PowerShell (VS Code's built-in default) instead of null. Windows PowerShell is always present and allowlisted, so it's a safe default.

Explicitly configured profiles are unchanged: PowerShell 7 / legacy / WSL / custom paths and an explicit Command Prompt profile all still resolve as before.

Testing

vitest run utils/__tests__/shell.spec.ts core/prompts/sections/__tests__/system-info.spec.ts
# Test Files 2 passed (2) · Tests 40 passed (40)

Updated the no-profile Windows tests to assert PowerShell, kept allowlist-safety coverage (non-allowlisted profile path → safe fallback), and added a test confirming an explicit Command Prompt profile still yields cmd.exe.

Summary by CodeRabbit

  • Bug Fixes
    • Updated Windows terminal shell detection to default to Windows PowerShell when no VS Code profile is configured.
    • Improved fallback behavior to use Command Prompt when configured shell paths are not allowlisted.

Review Change Stack

… is set (Zoo-Code-Org#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 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 21, 2026

📝 Walkthrough

Walkthrough

Windows shell detection behavior is updated so that getWindowsShellFromVSCode() returns the legacy PowerShell path when VS Code has no explicit terminal profile configured, instead of null. Tests validate the default PowerShell behavior, non-allowlisted profile fallback, and explicit Command Prompt configuration.

Changes

Windows Shell Detection Default

Layer / File(s) Summary
Windows shell detection implementation
src/utils/shell.ts
getWindowsShellFromVSCode() returns SHELL_PATHS.POWERSHELL_LEGACY instead of null when no VS Code terminal default profile is configured, preventing fallback to cmd.exe and aligning with VS Code's built-in PowerShell default.
Windows shell detection test coverage
src/utils/__tests__/shell.spec.ts
Three test cases validate the updated behavior: default to legacy PowerShell when no profile is set, fall back to cmd.exe for non-allowlisted profiles, and use cmd.exe when Command Prompt profile is explicitly configured.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A rabbit hops through Windows shells,
Once lost in null and fallback spells,
Now PowerShell rings out with grace,
No more cmd.exe in the wrong place! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing shell detection to report PowerShell on Windows when no profile is configured, directly addressing issue #82.
Description check ✅ Passed The description covers the core issue, implementation details, and testing results. However, the PR description lacks explicit reference to linked issue (#82 only mentioned in Fixes, not fully elaborated) and Pre-Submission Checklist is missing from the description.
Linked Issues check ✅ Passed The PR directly fixes the root cause identified in issue #82: getWindowsShellFromVSCode() now returns Windows PowerShell instead of null when no profile is configured, ensuring the system prompt reports the shell that actually executes commands.
Out of Scope Changes check ✅ Passed All changes are scoped to shell detection logic in src/utils/shell.ts and corresponding tests in shell.spec.ts. No unrelated modifications detected; changes directly address the linked issue's requirements.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/utils/shell.ts (1)

188-198: 💤 Low value

Consider narrowing the return type to string.

With this change, every branch of getWindowsShellFromVSCode() now returns a non-null string (the early-return defaults to POWERSHELL_LEGACY, and the remaining branches all return concrete SHELL_PATHS.* values or normalizedPath from a profile). The declared string | null return type is therefore misleading and may push callers to add unreachable null checks. The peer macOS/Linux helpers still legitimately return null, so this divergence is also worth documenting if you keep the union.

♻️ Optional narrowing
-function getWindowsShellFromVSCode(): string | null {
+function getWindowsShellFromVSCode(): string {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/utils/shell.ts` around lines 188 - 198, The function
getWindowsShellFromVSCode currently declares a return type of string | null but
all execution paths return a concrete string (the early exit returns
SHELL_PATHS.POWERSHELL_LEGACY, and the other branches return specific
SHELL_PATHS.* values or the profile's normalizedPath), so update the function
signature to return string (not string | null) and adjust any callers if they
were guarding against null; keep references to defaultProfileName, profiles,
normalizedPath and SHELL_PATHS.* when locating the logic to change and, if
desired, add a short comment noting that unlike the macOS/Linux helpers this
helper never returns null.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/utils/shell.ts`:
- Around line 188-198: The function getWindowsShellFromVSCode currently declares
a return type of string | null but all execution paths return a concrete string
(the early exit returns SHELL_PATHS.POWERSHELL_LEGACY, and the other branches
return specific SHELL_PATHS.* values or the profile's normalizedPath), so update
the function signature to return string (not string | null) and adjust any
callers if they were guarding against null; keep references to
defaultProfileName, profiles, normalizedPath and SHELL_PATHS.* when locating the
logic to change and, if desired, add a short comment noting that unlike the
macOS/Linux helpers this helper never returns null.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2ccac09b-b670-490b-b222-1b427d4a60c0

📥 Commits

Reviewing files that changed from the base of the PR and between 166bc3f and 3a2181c.

📒 Files selected for processing (2)
  • src/utils/__tests__/shell.spec.ts
  • src/utils/shell.ts

@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Comment thread src/utils/shell.ts
Comment on lines +191 to +197
// 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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

On a machine with PowerShell 7 installed, VS Code's auto-detection will typically select PS7 as the default terminal — not legacy 5.1. Commit 1a2c45cb fixed the analogous case (profile name includes "powershell" but no path/source) by switching from POWERSHELL_LEGACYPOWERSHELL_7 for exactly this reason (UTF-8 mojibake). Should this path apply the same heuristic — e.g. probe for PS7 at its known path before falling back to legacy?

// 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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this mock still needed? With the early return at shell.ts:197, getShellFromUserInfo() is never called in this code path — so this mock value is never read. Removing it would make the test clearer about what's actually being exercised.

Suggested change
vi.mocked(userInfo).mockReturnValue({ shell: "C:\\Program Files\\PowerShell\\7\\pwsh.exe" } as any)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] System prompt on windows says shell is cmd.exe but if powershell is used via VS Code terminal provider when inline terminal is off

2 participants