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+)
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, thecmd()function invokes PowerShell with the-Commandflag, which passes the command as a string interpreted through the system's default encoding.Proposed Fix
Switch from
-Commandto-EncodedCommandwith a UTF-8 preamble injected before encoding. This uses PowerShell's native base64-encoded command mechanism which properly handles Unicode:encodePowerShellCommand()— encodes command string to base64 UTF-16LE (required by-EncodedCommand)withPowerShellUtf8Preamble()— prepends console encoding setup to force UTF-8 without BOMcmd()function to use these helpersSteps to Reproduce
echo "测试中文"Environment