fix: PowerShell commands produce garbled output for non-ASCII characters on Windows
Description
On Windows, when MiMo-Code executes bash/shell commands via PowerShell, any output containing non-ASCII characters (Chinese, Japanese, Korean, emojis, etc.) appears garbled or corrupted.
This happens because PowerShell defaults to the system legacy encoding (e.g., CP936/GBK on Chinese Windows, CP1252 on English Windows) instead of UTF-8. Commands like echo "测试中文" or any tool outputting Unicode text will produce mojibake.
Root Cause
In packages/opencode/src/tool/bash.ts, the cmd() function invokes PowerShell with the -Command flag, which passes the command as a string interpreted through the system's default encoding.
Proposed Fix
Switch from -Command to -EncodedCommand with a UTF-8 preamble injected before encoding. This uses PowerShell's native base64-encoded command mechanism which properly handles Unicode:
- Add
encodePowerShellCommand()— encodes command string to base64 UTF-16LE (required by-EncodedCommand) - Add
withPowerShellUtf8Preamble()— prepends console encoding setup to force UTF-8 without BOM - Modify the
cmd()function to use these helpers
Steps to Reproduce
- Run MiMo-Code on Windows with a non-English system locale
- Use the bash tool to run a command that outputs non-ASCII text, e.g.,
echo "测试中文" - Observe garbled output
Environment
- OS: Windows 11
- MiMo-Code version: 0.1.0
- Terminal: Windows Terminal (PowerShell 7+)
Fixed by #1418 (merged in aae0243).
The bash tool's cmd() in packages/opencode/src/tool/bash.ts now prepends a UTF-8 encoding setup before the user command on Windows — $OutputEncoding = [Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false); for PowerShell/pwsh, and chcp 65001 >nul 2>nul & for cmd. The interactive TUI shell-mode path (session/prompt.ts) got the same treatment, and PYTHONIOENCODING=utf-8 is injected for piped Python output. This will ship in the next release.
中文:已由 #1418 修复(合并于 aae0243)。
bash.ts的cmd()现在在 Windows 上会在用户命令前注入 UTF-8 编码设置(PowerShell/pwsh 用$OutputEncoding/[Console]::OutputEncoding,cmd 用chcp 65001),TUI shell 模式同样处理,并为管道里的 Python 注入PYTHONIOENCODING=utf-8。将随下个版本发布。