fix(dev-mcp): pin UTF-8 for PowerShell shell commands - #7096
Open
PresentJay wants to merge 1 commit into
Open
Conversation
Windows PowerShell 5.1 encodes what it writes to a native process with the legacy console codepage and substitutes `?` for every character that codepage cannot represent. Prose piped into `buzz messages send --content -` loses its em dashes, curly quotes, and non-Latin text before the event is built and signed, and the command still reports success — so the corruption is silent and permanent in message history. Prepend the UTF-8 pin to the command string when the resolved shell is powershell or pwsh, so it holds for every session rather than depending on each caller setting `$OutputEncoding` first. Other shells are handed the command unchanged. Fixes block#6527 Signed-off-by: Hyeonjae.Jeong <presentj94@gmail.com>
🔐 Codex Security Review
|
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.
Windows PowerShell 5.1 encodes what it writes to a native process with the legacy console codepage and substitutes
?for every character that codepage cannot represent. Prose piped intobuzz messages send --content -loses its em dashes, curly quotes, and non-Latin text before the event is built and signed — and the command still exits 0, so the corruption is silent and permanent in message history.buzz-dev-mcpspawns that shell for everydev__shellcall, which is the path managed agents use to reach the CLI. This pins BOM-less UTF-8 on the session before the caller's command runs:That is the workaround from the issue, moved from the caller into the spawn so it holds for every session. A prompt-level instruction cannot: each channel is an independent, long-running agent session, so one can comply while another keeps using the legacy encoding.
Dispatch is on the resolved shell (
powershell/pwsh), not the host OS, matching howshell_flagright above it already picks the command flag. Every other shell is handed the command unchanged.Fixes #6527
Test
Two cases in
crates/buzz-dev-mcp/src/shell.rs, over the command string that is actually handed to the shell:powershell_command_pins_utf8_before_the_callers_command— asserts the preamble comes first and the caller's command (em dash — café 測試 🐝) survives intact, forpowershell.exe,pwsh.exe, andpwsh. Before the change it fails with the command returned bare.other_shells_receive_the_command_unchanged—bash,/bin/zsh,sh, andcmd.exeare untouched.Scope note: this covers how the command is constructed. The end-to-end Windows assertion the issue asks for — sending through a live harness and reading the accepted event's code points back — is not included here; it needs a Windows runner this change cannot provide.