read_file: transcode UTF-16 text files to UTF-8 instead of refusing as binary (port from kimi-code) - #80717
Merged
Merged
Conversation
Contributor
૮ >ﻌ< ა ci reviewran on 8cfd852 — Port from MoonshotAI/kimi-code#2647: read UTF-16 text files
|
teknium1
force-pushed
the
kimi-code-port/utf16-read
branch
from
August 17, 2026 02:55
6c564a8 to
53a6a00
Compare
…oding to UTF-8 UTF-16 text files (Windows Notepad .txt, PowerShell > redirects) were refused as binary: the terminal env decodes stdout as UTF-8 with errors=replace, so their content arrived mangled with U+FFFD and tripped the binary guard. ShellFileOperations.read_file now probes the raw bytes via the backend's Python when the binary guard fires: a BOM or the zero-byte parity heuristic (derived from VS Code's encoding sniffer, tolerant of mixed Latin/CJK content) identifies UTF-16 LE/BE, and the file is transcoded to UTF-8 with CRLF normalized and the BOM stripped. Real binaries (zeros at both parities), binary extensions, files over 10 MiB, and legacy 8-bit encodings (GBK, Big5) still refuse — a wrong silent guess is worse than a clear refusal. Works on every shell backend (local/docker/ssh) since the probe runs via python3 -c. Tests run against a real LocalEnvironment (E2E, no mocks); sabotage run confirmed 6/9 fail without the fix.
teknium1
force-pushed
the
kimi-code-port/utf16-read
branch
from
August 17, 2026 03:30
53a6a00 to
8cfd852
Compare
teknium1
added a commit
that referenced
this pull request
Aug 17, 2026
…scout-slate wave Post-merge docs sweep for the Aug 16 scout slate. Two pages: - mcp.md: tool-result sanitization section — invisible Unicode TAG chars (U+E0000-E007F) stripped from results/resources/descriptions (#80689); vendor _meta surfaced to the model minus protocol-reserved modelcontextprotocol/mcp prefixes (#80712) - tools.md: tool result annotations section — signal-death exit notes (subprocess -signum definite, shell 128+signum hedged) (#78074); UTF-16 read_file transcoding with disclosure hint and 10MB cap (#80717) Security-policy docs (approvals/allowlist) intentionally untouched.
teknium1
added a commit
that referenced
this pull request
Aug 17, 2026
…scout-slate wave Post-merge docs sweep for the Aug 16 scout slate. Two pages: - mcp.md: tool-result sanitization section — invisible Unicode TAG chars (U+E0000-E007F) stripped from results/resources/descriptions (#80689); vendor _meta surfaced to the model minus protocol-reserved modelcontextprotocol/mcp prefixes (#80712) - tools.md: tool result annotations section — signal-death exit notes (subprocess -signum definite, shell 128+signum hedged) (#78074); UTF-16 read_file transcoding with disclosure hint and 10MB cap (#80717) Security-policy docs (approvals/allowlist) intentionally untouched.
lisajlau
pushed a commit
to lisajlau/hermes-agent
that referenced
this pull request
Aug 20, 2026
…scout-slate wave Post-merge docs sweep for the Aug 16 scout slate. Two pages: - mcp.md: tool-result sanitization section — invisible Unicode TAG chars (U+E0000-E007F) stripped from results/resources/descriptions (NousResearch#80689); vendor _meta surfaced to the model minus protocol-reserved modelcontextprotocol/mcp prefixes (NousResearch#80712) - tools.md: tool result annotations section — signal-death exit notes (subprocess -signum definite, shell 128+signum hedged) (NousResearch#78074); UTF-16 read_file transcoding with disclosure hint and 10MB cap (NousResearch#80717) Security-policy docs (approvals/allowlist) intentionally untouched.
prmartinow
pushed a commit
to prmartinow/hermes-agent
that referenced
this pull request
Aug 26, 2026
…scout-slate wave Post-merge docs sweep for the Aug 16 scout slate. Two pages: - mcp.md: tool-result sanitization section — invisible Unicode TAG chars (U+E0000-E007F) stripped from results/resources/descriptions (NousResearch#80689); vendor _meta surfaced to the model minus protocol-reserved modelcontextprotocol/mcp prefixes (NousResearch#80712) - tools.md: tool result annotations section — signal-death exit notes (subprocess -signum definite, shell 128+signum hedged) (NousResearch#78074); UTF-16 read_file transcoding with disclosure hint and 10MB cap (NousResearch#80717) Security-policy docs (approvals/allowlist) intentionally untouched.
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
read_filenow reads UTF-16 text files by transcoding them to UTF-8 instead of refusing them as binary. Windows Notepad.txtfiles and PowerShell>redirects are UTF-16 by default; the terminal env decodes stdout as UTF-8 witherrors="replace", so their content arrived as U+FFFD mojibake and tripped the binary guard.Ported from MoonshotAI/kimi-code#2647 (detection derived from VS Code's encoding sniffer), adapted to Hermes' shell-backend architecture: the probe runs via
python3 -cthrough the backend's own shell, so it works identically on local, docker, and ssh backends.Changes
tools/file_operations.py: newShellFileOperations._try_read_utf16()invoked when the binary guard fires — trusts a BOM first, then the zero-byte parity heuristic (zeros clustered at odd indices = UTF-16 LE, even = BE; placement-only so mixed Latin/CJK content still detects). Transcodes to UTF-8, strips BOM, normalizes CRLF, supports pagination, and appends a "Transcoded from UTF-16-LE" hint so edits re-encoding as UTF-8 aren't a surprise. Real binaries (zeros at both parities), binary extensions, >10 MiB files, and legacy 8-bit encodings (GBK/Big5) still refuse — a wrong silent guess is worse than a clear refusal.tests/tools/test_utf16_read.py: 9 E2E tests against a realLocalEnvironment(BOM LE/BE, BOM-less, mixed CJK, CRLF, pagination, real-binary refusal, binary-extension skip, UTF-8 untouched).Validation
Infographic