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

  1. Byte-level fidelity: Reads and writes files in their original encoding without converting to UTF-8.
  2. BOM fidelity: Precisely restores an existing BOM or never adds one.
  3. Line-ending fidelity: Recognizes and restores CRLF / LF / CR.
  4. No silent corruption: Rejects writes for characters that cannot be represented.
  5. Smart detection: If a file cannot be read, it lists candidate encodings for selection instead of simply failing with an error.
  6. Broad support: Supports 19 encodings, including GBK, Big5, Shift-JIS, EUC-KR, and Windows-125x.
  7. Zero learning curve: Directly replaces the native read / write / edit tools, with parameters and return formats identical to the originals.
  8. Create with specified encoding: write supports an encoding parameter for creating new files with a specified encoding.
  9. Additional tools: Provides three extra tools: insert, undo_last_edit, and str_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:

  1. insert: Inserts a string at a specified line number (not supported natively).
    insert({ file_path: "config.ini", insert_line: 0, new_string: "[core]" })
  1. undo_last_edit: Undoes the last edit, restoring both content and encoding.
    undo_last_edit({ file_path: "config.ini" })
  1. str_replace_editor: A compatibility layer tool that supports subcommands such as view, create, str_replace, insert, and undo_edit.

Notes

  1. 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).
  2. encoding parameter limitation: The encoding parameter is only valid for new files. If the file already exists, passing encoding directly will cause an error. The plugin does not convert the encoding of existing files.
  3. Windows cross-drive issue: On Windows, installation fails if the plugin directory and profile are not on the same drive.
  4. Undo limitation: undo_last_edit retains only the most recent edit and does not write it to disk, so it cannot be undone after DSH restarts.
  5. 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.