Introduction¶
The native file tools in DeepSeek Harness (DSH) (read / write / edit) accept only UTF-8. When handling files in Chinese GBK, Japanese Shift-JIS, Korean EUC-KR, or files with a BOM, the AI often fails outright with a read error, or corrupts the file encoding and loses the BOM after modifying the file. This plugin takes over these tools and reads or writes files in their original encoding, while preserving existing mechanisms such as sandbox guardrails and read-before-write protection. It resolves the silent corruption issue when the AI reads or writes multi-byte encoded files.
What Is This¶
This is mrweicodes/dsh-fs-encoding, a DSH plugin maintained by MrWeiCodes and categorized as a model inference tool.
Its core value is to prevent the AI from corrupting encoding when reading or writing non-UTF-8 files such as GBK, or files with a BOM. The plugin uses byte-level fidelity, BOM fidelity, and line-ending fidelity to ensure that files retain their original encoding characteristics during read and write operations.
Core Features¶
- Byte-level fidelity: Reads and writes files in their original encoding without converting to UTF-8.
- BOM fidelity: Precisely restores an existing BOM or never adds one.
- Line-ending fidelity: Recognizes and restores CRLF / LF / CR.
- No silent corruption: Rejects writes for characters that cannot be represented.
- Smart detection: If a file cannot be read, it lists candidate encodings for selection instead of simply failing with an error.
- Broad support: Supports 19 encodings, including GBK, Big5, Shift-JIS, EUC-KR, and Windows-125x.
- Zero learning curve: Directly replaces the native
read/write/edittools, with parameters and return formats identical to the originals. - Create with specified encoding:
writesupports anencodingparameter for creating new files with a specified encoding. - Additional tools: Provides three extra tools:
insert,undo_last_edit, andstr_replace_editor.
Installation and Activation¶
Use the officially provided install command to activate it:
dsh plugin --profile web add dsh-fs-encoding
After installation, the plugin automatically overrides the native tools, with no additional configuration required.
Typical Usage¶
The plugin takes over the native tools. The invocation method is basically the same as the originals, with the main difference being explicit encoding specification.
Reading Non-UTF-8 Files¶
For non-UTF-8 files such as GBK, you need to explicitly pass the encoding parameter:
read({ file_path: "legacy.txt", encoding: "gbk" })
Writing a File with a Specified Encoding¶
When creating a new file, use the encoding parameter to specify the encoding (for example, GBK):
write({ file_path: "run.bat", content: "echo 中文\r\n", encoding: "gbk" })
Additional Tools¶
The plugin provides three additional tools:
insert: Inserts a string at a specified line number (not supported natively).
insert({ file_path: "config.ini", insert_line: 0, new_string: "[core]" })
undo_last_edit: Undoes the last edit, restoring both content and encoding.
undo_last_edit({ file_path: "config.ini" })
str_replace_editor: A compatibility layer tool that supports subcommands such asview,create,str_replace,insert, andundo_edit.
Notes¶
- Tool conflicts: It is mutually exclusive with plugins that register tools with the same names at the same level (such as
read/write/edit/insert/str_replace_editor/undo_last_edit). encodingparameter limitation: Theencodingparameter is only valid for new files. If the file already exists, passingencodingdirectly will cause an error. The plugin does not convert the encoding of existing files.- Windows cross-drive issue: On Windows, installation fails if the plugin directory and profile are not on the same drive.
- Undo limitation:
undo_last_editretains only the most recent edit and does not write it to disk, so it cannot be undone after DSH restarts. - License: MIT License.
Summary¶
dsh-fs-encoding addresses the pain points of DSH when handling multi-byte encoded files by precisely controlling the file read and write process. It is suitable for scenarios that require maintaining legacy systems, handling internationalized files, or ensuring codebase encoding consistency.