Skip to content

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

Description

@senguangd

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+)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions