Skip to content

fix(windows): decode Windows bash output encodings - #90

Open
yuczzzzz wants to merge 1 commit into
rebel0789:mainfrom
yuczzzzz:codex/windows-bash-output-encoding
Open

fix(windows): decode Windows bash output encodings#90
yuczzzzz wants to merge 1 commit into
rebel0789:mainfrom
yuczzzzz:codex/windows-bash-output-encoding

Conversation

@yuczzzzz

Copy link
Copy Markdown

Why

On Windows, some bash commands produce output bytes in a non-UTF-8 encoding. Decoding those bytes as UTF-8 produces garbled text, making command output difficult to read and use.

Goal

Ensure bash output on Windows is correctly decoded as Unicode text when it uses a supported non-UTF-8 encoding, while preserving existing UTF-8 behavior and non-Windows behavior.

Summary

  • Preserve raw byte chunks from bash stdout and stderr, then decode each stream independently after the process exits.
  • On Windows, validate UTF-8 strictly before attempting encoding detection. For invalid UTF-8, accept only chardet's first candidate when confidence is at least 80 and iconv-lite supports it.
  • Fall back to tolerant UTF-8 decoding when detection is absent, low-confidence, unsupported, or throws.
  • Keep the existing combined raw-byte output limit, timeout handling, redaction, UTF-8 truncation, and external bash tool interface.
  • Add direct runtime dependencies for chardet and iconv-lite.
  • Add encoding smoke coverage for UTF-8, GBK, GB18030, fallback paths, split multi-byte output, truncated UTF-8, and Windows mixed stdout/stderr encoding.

Security Impact

This change affects shell-output decoding only. It does not change bash command permissions, execution modes, MCP parameters, environment variables, or result fields. Output retention remains bounded by the existing raw-byte limit. Low-confidence or unsupported encoding detection falls back to the existing UTF-8 behavior.

Validation

  • npm run build
  • npm run smoke
  • npm run stress
  • Update README.md or CHANGELOG.md for this behavior change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant