Repository navigation
Conversation
On non-UTF-8 Windows locales (e.g. zh-CN ACP 936/GBK), shell subprocesses emit output in the legacy code page which we decode as UTF-8, producing mojibake for CJK filenames/output. Fix both execution paths: - bash tool (src/tool/bash.ts): prepend an $OutputEncoding/[Console]:: OutputEncoding UTF-8 statement for PowerShell, chcp 65001 for cmd. - TUI shell mode (src/session/prompt.ts shellImpl): same prefixes for powershell/pwsh/cmd invocations. - Add PYTHONIOENCODING=utf-8 to the shell env on Windows so piped Python output is UTF-8 (Python ignores the code page when stdout is a pipe). Based on upstream anomalyco/opencode#31658.
…1418) * fix: force UTF-8 for Windows shell subprocesses to fix CJK mojibake On non-UTF-8 Windows locales (e.g. zh-CN ACP 936/GBK), shell subprocesses emit output in the legacy code page which we decode as UTF-8, producing mojibake for CJK filenames/output. Fix both execution paths: - bash tool (src/tool/bash.ts): prepend an $OutputEncoding/[Console]:: OutputEncoding UTF-8 statement for PowerShell, chcp 65001 for cmd. - TUI shell mode (src/session/prompt.ts shellImpl): same prefixes for powershell/pwsh/cmd invocations. - Add PYTHONIOENCODING=utf-8 to the shell env on Windows so piped Python output is UTF-8 (Python ignores the code page when stdout is a pipe). Based on upstream anomalyco/opencode#31658. * docs: add Windows CJK mojibake workaround to README Document the system-wide UTF-8 (Beta) toggle as a workaround for garbled CJK shell output on non-UTF-8 Windows locales, for users on older versions or tools not yet special-cased. Added to both English and Chinese README. * docs: clarify MiMoCode version and tone in Windows CJK note * docs: refine wording of Windows CJK note * refactor: extract shared Windows UTF-8 shell prefixes; redirect chcp stderr Address PR review: extract POWERSHELL_UTF8_PREFIX and CMD_UTF8_PREFIX into src/shell/shell.ts so the bash tool and TUI shell-mode paths can't drift, and redirect both stdout and stderr (>nul 2>nul) so a chcp failure in a restricted shell never pollutes command output.
…iaomiMiMo#1418) * fix: force UTF-8 for Windows shell subprocesses to fix CJK mojibake On non-UTF-8 Windows locales (e.g. zh-CN ACP 936/GBK), shell subprocesses emit output in the legacy code page which we decode as UTF-8, producing mojibake for CJK filenames/output. Fix both execution paths: - bash tool (src/tool/bash.ts): prepend an $OutputEncoding/[Console]:: OutputEncoding UTF-8 statement for PowerShell, chcp 65001 for cmd. - TUI shell mode (src/session/prompt.ts shellImpl): same prefixes for powershell/pwsh/cmd invocations. - Add PYTHONIOENCODING=utf-8 to the shell env on Windows so piped Python output is UTF-8 (Python ignores the code page when stdout is a pipe). Based on upstream anomalyco/opencode#31658. * docs: add Windows CJK mojibake workaround to README Document the system-wide UTF-8 (Beta) toggle as a workaround for garbled CJK shell output on non-UTF-8 Windows locales, for users on older versions or tools not yet special-cased. Added to both English and Chinese README. * docs: clarify MiMoCode version and tone in Windows CJK note * docs: refine wording of Windows CJK note * refactor: extract shared Windows UTF-8 shell prefixes; redirect chcp stderr Address PR review: extract POWERSHELL_UTF8_PREFIX and CMD_UTF8_PREFIX into src/shell/shell.ts so the bash tool and TUI shell-mode paths can't drift, and redirect both stdout and stderr (>nul 2>nul) so a chcp failure in a restricted shell never pollutes command output.
…1418) * fix: force UTF-8 for Windows shell subprocesses to fix CJK mojibake On non-UTF-8 Windows locales (e.g. zh-CN ACP 936/GBK), shell subprocesses emit output in the legacy code page which we decode as UTF-8, producing mojibake for CJK filenames/output. Fix both execution paths: - bash tool (src/tool/bash.ts): prepend an $OutputEncoding/[Console]:: OutputEncoding UTF-8 statement for PowerShell, chcp 65001 for cmd. - TUI shell mode (src/session/prompt.ts shellImpl): same prefixes for powershell/pwsh/cmd invocations. - Add PYTHONIOENCODING=utf-8 to the shell env on Windows so piped Python output is UTF-8 (Python ignores the code page when stdout is a pipe). Based on upstream anomalyco/opencode#31658. * docs: add Windows CJK mojibake workaround to README Document the system-wide UTF-8 (Beta) toggle as a workaround for garbled CJK shell output on non-UTF-8 Windows locales, for users on older versions or tools not yet special-cased. Added to both English and Chinese README. * docs: clarify MiMoCode version and tone in Windows CJK note * docs: refine wording of Windows CJK note * refactor: extract shared Windows UTF-8 shell prefixes; redirect chcp stderr Address PR review: extract POWERSHELL_UTF8_PREFIX and CMD_UTF8_PREFIX into src/shell/shell.ts so the bash tool and TUI shell-mode paths can't drift, and redirect both stdout and stderr (>nul 2>nul) so a chcp failure in a restricted shell never pollutes command output.
|
为什么还没被合并。。。。非常需要这个 |
|
Still broken on v2.0.18 (windows-x64) — verified today. Two notes for the rebase:
The three-layer fix in the description is correct — all of Written with opencode v2.0.18; all numbers measured on my own machine. |
|
Still reproduces on v2.0.22 (windows-x64) — independently verified today. Environment
Repro / measurement (as seen by the spawned child with piped stdout) Two notes for the rebase:
Confirmed the three-layer prefix works ( As a data point that the mechanism is viable on v2.0.22 without a core patch: the V2 plugin Hoping this gets merged — the duplicate issues keep multiplying. |
|
This branch has been upgraded to V2. We're no longer taking PRs for V1. If you think this is still relevant, please port it over and open it for V2. — from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊 |
Issue for this PR
Closes #23636
Closes #31187
Closes #30205
Closes #31830
Closes #26882
Type of change
What does this PR do?
On zh-CN Windows systems, the default active code page (ACP) is 936 (GBK). New subprocesses spawned by OpenCode inherit this encoding. Garbled characters occur when tools output non-ASCII characters such as CJK characters.
This PR fixes the garbled text bug by prepending the command
$OutputEncoding = [Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false);before the executed command to set the character encoding to UTF-8; this fix targets PowerShell. When the spawned subprocess is CMD,chcp 65001 >nulis prepended to the command to switch the code page.When running the python command in Windows Terminal, if stdout is a pipe (rather than the console), Python ignores the code page set via chcp and falls back to the system ANSI code page (GBK on Chinese-language Windows systems). The fix is to append the environment variable
PYTHONIOENCODING=utf-8in the shell environment.How did you verify your code works?
I ran OpenCode locally with
bun dev. In shell mode, I ran thelscommand to list a directory containing files with Chinese filenames, and the output displayed correctly. I also executedWrite-Output "中文输出"to inspect console output, which rendered properly as well.I have completed local tests with both PowerShell and CMD set as the default shells. The results meet expectations with no garbled characters present.
Screenshots / recordings
before


after


Checklist