MiMo-Code icon indicating copy to clipboard operation
MiMo-Code copied to clipboard

fix: PowerShell commands produce garbled output for non-ASCII characters on Windows

Open senguangd opened this issue 5 months ago • 1 comments

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:

  1. Add encodePowerShellCommand() — encodes command string to base64 UTF-16LE (required by -EncodedCommand)
  2. Add withPowerShellUtf8Preamble() — prepends console encoding setup to force UTF-8 without BOM
  3. Modify the cmd() function to use these helpers

Steps to Reproduce

  1. Run MiMo-Code on Windows with a non-English system locale
  2. Use the bash tool to run a command that outputs non-ASCII text, e.g., echo "测试中文"
  3. Observe garbled output

Environment

  • OS: Windows 11
  • MiMo-Code version: 0.1.0
  • Terminal: Windows Terminal (PowerShell 7+)

senguangd avatar Jun 11 '26 14:06 senguangd

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。将随下个版本发布。

yanyihan-xiaomi avatar Jun 28 '26 07:06 yanyihan-xiaomi