fix(shell): use EncodedCommand for PowerShell to fix Windows encoding issues - #11148
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR centralizes PowerShell command invocation and switches PowerShell execution to use -EncodedCommand (with a UTF-8 wrapper) instead of passing raw -Command strings.
Changes:
- Added a core
powershell.tshelper to generate PowerShell CLI args using-EncodedCommand. - Updated shell argument selection to delegate PowerShell arg construction to the new helper.
- Updated Windows PowerShell process creation to reuse
Shell.args(...)rather than hardcoding flags.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| packages/opencode/src/tool/shell.ts | Uses Shell.args(...) for Windows PowerShell process creation instead of inline PowerShell flags. |
| packages/opencode/src/shell/shell.ts | Routes PowerShell argument generation through @opencode-ai/core/shell/powershell. |
| packages/core/src/shell/powershell.ts | Introduces PowerShell arg builder that encodes commands and enforces UTF-8 I/O settings. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Code Review SummaryStatus: 1 Observation (no blocking issues) | Recommendation: Merge Overview
Previously Flagged Issues — All ResolvedAll issues from prior reviews have been addressed:
Remaining Observation (not in diff)Changeset missing: This PR fixes a real user-facing bug (garbled output on non-English Windows locales) and still has no Files Reviewed (3 files)
Reviewed by claude-4.6-sonnet-20260217 · 676,910 tokens Review guidance: REVIEW.md from base branch |
… issues On Windows, PowerShell commands with non-ASCII characters (e.g., Chinese, Japanese, Cyrillic) produce garbled output (mojibake) because the console encoding defaults to the system OEM code page rather than UTF-8. Switch from `-Command` to `-EncodedCommand` with a Base64-encoded UTF-16LE payload that explicitly sets `[Console]::InputEncoding`, `[Console]::OutputEncoding`, and `$OutputEncoding` to UTF-8 before executing the original command. This ensures both input and output are properly encoded as UTF-8 regardless of the system locale. Fixes #4138 Fixes #2422 Fixes #2939
cf890dd to
6e0639b
Compare
|
Hey @senguangd, could you please link your GitHub account to the Kilo account? This way, we can grant you credits for the merged PRs. |
fix(shell): use EncodedCommand for PowerShell to fix Windows encoding issues
Issue
Fixes #4138
Fixes #2422
Fixes #2939
Also related to #9440, #8616
Context
On Windows, PowerShell commands containing or producing non-ASCII characters (Chinese, Japanese, Cyrillic, etc.) result in garbled output (mojibake). This happens because the console encoding defaults to the system OEM code page (e.g., CP936 for zh-CN) rather than UTF-8.
Multiple users have reported this issue:
-Commandargument not recognized properly by pwsh.exeAll three issues were closed as stale/not-planned without a code fix. The underlying encoding problem remains.
Implementation
Switch PowerShell invocation from
-Commandto-EncodedCommandwith a Base64-encoded UTF-16LE payload. The encoded payload explicitly sets[Console]::InputEncoding,[Console]::OutputEncoding, and$OutputEncodingto UTF-8 before executing the original command. This ensures both input and output are properly encoded as UTF-8 regardless of the system locale.New file:
packages/core/src/shell/powershell.tsargs(command)— returns PowerShell arguments using-EncodedCommandencoded(command)— wraps the command in a UTF-8 console setup preamble and encodes as Base64 (UTF-16LE)Modified:
packages/opencode/src/shell/shell.ts["-NoProfile", "-Command", command]withPowerShell.args(command)Modified:
packages/opencode/src/tool/shell.ts["-NoLogo", "-NoProfile", "-NonInteractive", "-Command", command]withShell.args(shell, command, cwd), reusing the same encoding logicThis approach is inspired by how VS Code's own shell execution handles PowerShell encoding (using
-EncodedCommandto avoid encoding mismatches).Screenshots
N/A, non-visual change. The fix affects command output encoding in the shell execution layer.
How to Test
Manual/local verification
Reviewer test steps
Checklist
// kilocode_changemarkers added for changes inpackages/opencode/