Skip to content

fix: prefer PowerShell 7 over legacy Windows PowerShell 5.1 - #13365

Merged
marius-kilocode merged 4 commits into
mainfrom
support-configurable-powershell-shell
Aug 24, 2026
Merged

fix: prefer PowerShell 7 over legacy Windows PowerShell 5.1#13365
marius-kilocode merged 4 commits into
mainfrom
support-configurable-powershell-shell

Conversation

@marius-kilocode

Copy link
Copy Markdown
Collaborator

Kilo Code on Windows keeps selecting Windows PowerShell 5.1 for agent command execution even when PowerShell 7 is installed (#13324). PS 5.1 writes UTF-16LE with a BOM for Out-File/> redirection and has other encoding differences, so agent-driven commands can corrupt files that pwsh would leave intact.

Root cause, from the current selection logic:

  • Shell.preferred()/Shell.acceptable() in packages/core/src/shell.ts resolve pwsh only via PATH lookup. When the kilo serve process inherits a PATH without the pwsh directory (common with Store installs whose alias lives under %LOCALAPPDATA%\Microsoft\WindowsApps), detection silently degrades to System32\WindowsPowerShell\v1.0\powershell.exe.
  • The extension reads vscode.env.shell but only forwards it to the webview for display; the CLI shell selection never sees it.
  • Several execution paths bypass core selection entirely and hardcode legacy PowerShell: Agent Manager setup/run script launchers and the background-process Win32 probes in the CLI.

Plan on this branch:

  1. Regression tests (this commit): win32-gated tests in packages/core/test/kilocode/powershell.test.ts assert that with pwsh stripped from PATH, an installed PowerShell 7 still wins over legacy 5.1. They are expected to fail on the Windows CI shard until the fix commit lands.
  2. Fix: probe well-known pwsh install locations (%ProgramFiles%\PowerShell\7, %ProgramFiles(x86)%\PowerShell\7, %LOCALAPPDATA%\Microsoft\WindowsApps) after PATH lookup fails, keep explicit shell config as the highest-priority override, and switch the hardcoded call sites to prefer pwsh when present.

Refs #13324

@marius-kilocode
marius-kilocode marked this pull request as ready for review August 24, 2026 13:16
@kilo-code-bot

kilo-code-bot Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/kilo-vscode/src/util/powershell.ts 23 locations() returns full pwsh.exe paths, but pwshPath() treats them as directories and joins pwsh.exe again, so off-PATH installs are never found
Files Reviewed (12 files)
  • .changeset/prefer-powershell-7-on-windows.md - 0 issues
  • packages/core/src/kilocode/powershell.ts - 0 issues
  • packages/core/src/shell.ts - 0 issues
  • packages/core/test/kilocode/powershell.test.ts - 0 issues
  • packages/kilo-vscode/src/agent-manager/SetupScriptRunner.ts - 0 issues
  • packages/kilo-vscode/src/agent-manager/run/service.ts - 0 issues
  • packages/kilo-vscode/src/util/powershell.ts - 1 issue
  • packages/kilo-vscode/tests/unit/powershell.test.ts - 0 issues
  • packages/kilo-vscode/tests/unit/run-script-service.test.ts - 0 issues
  • packages/opencode/src/kilocode/background-process/index.ts - 0 issues
  • packages/opencode/src/kilocode/background-process/runner.ts - 0 issues
  • packages/opencode/src/kilocode/shell/shell.ts - 0 issues

Fix these issues in Kilo Cloud


Reviewed by grok-4.6 · Input: 148.5K · Output: 17.7K · Cached: 542.6K

Review guidance: REVIEW.md from base branch main

export const probe = (env: NodeJS.ProcessEnv = process.env) =>
locations(env).filter((file) => statSync(file, { throwIfNoEntry: false })?.isFile())

export const pwsh = (env: NodeJS.ProcessEnv = process.env) => which("pwsh", env) ?? probe(env)[0]

@WebReflection WebReflection Aug 24, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

not a big deal, neither a blocker, rather a FYI, nowadays it'd be probe(env).at(0) to avoid "messing" with arrays (because if the length is 0 it would access an undefined index)

@marius-kilocode
marius-kilocode merged commit 2242457 into main Aug 24, 2026
34 checks passed
@marius-kilocode
marius-kilocode deleted the support-configurable-powershell-shell branch August 24, 2026 13:53
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.

2 participants