fix(cli,hooks): UTF-8 robustness on Windows (GBK) locales - #210
Open
raymondginger2018-sudo wants to merge 2 commits into
Open
fix(cli,hooks): UTF-8 robustness on Windows (GBK) locales#210raymondginger2018-sudo wants to merge 2 commits into
raymondginger2018-sudo wants to merge 2 commits into
Conversation
Windows consoles default to GBK/cp936, so rich rendering or model output that emits non-GBK text crashes with UnicodeEncodeError. Reconfigure stdio to UTF-8 before the parser/Console are set up. No behavior change on UTF-8-locale systems (the reconfigure is a no-op there); copied verbatim from the working tree (e1e00cc5, cli hunk only).
hooks.json / .claude settings.json are written as UTF-8 JSON, but Path.read_text() defaults to the locale encoding, so on a GBK/cp936 Windows console a config containing non-GBK bytes is mis-decoded (or raises) before parsing. Read explicitly as UTF-8; no behavior change on UTF-8 locales.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Windows defaults the console to GBK/cp936. Two small fixes make the CLI robust to non-UTF-8 locales; each is a no-op where the locale is already UTF-8.
Changes
deepcode loopnow callscore.platform_compat.configure_utf8_stdio()before the parser/Console are set up. FixesUnicodeEncodeErrorwhen rich or model output renders non-GBK text (the recentdshheadless runs crashed on Windows otherwise).hooks.json/.claude/settings.jsonexplicitly as UTF-8 instead of the locale default, so a GBK-locale console does not mis-decode (or raise on) non-GBK bytes in a UTF-8 hooks config.Tests
ruff check+ruff format --checkpass under the repo-pinned ruff (pre-commit rev v0.15.21).Notes
Two independent commits, one logical concern (UTF-8 robustness). The CLI hunk is taken verbatim from our local working tree fix for the same crash.