Introduction

During the development and debugging of DeepSeek Harness (DSH), locating file lines by line numbers or raw text is common, but changes in text formatting or line-number shifts can easily cause location to fail. dsh-hash-edit aims to solve line-location and rollback issues in file editing by generating stable hash anchors for each line of a file, ensuring that edits are based on content rather than position.

Plugin Scope

This is a client-side plugin for DeepSeek Harness (DSH) that provides hash-anchored read, replace, and undo capabilities. It intercepts writes and masks built-in tools to perform high-precision operations on file lines. The plugin is released under the MIT license and maintained by developer ddv12138.

Core Features

The plugin primarily implements the following behaviors:

  1. Hash Anchor Mechanism: Uses the xxHash32 algorithm to generate stable 3-character base-62 anchors for each line. Anchors resolve conflicts through coprime bitmap probing and are guaranteed unique by construction.
  2. Edit Takeover: After the plugin is loaded, it masks the built-in edit tool and intercepts write operations, automatically appending an anchor block to keep the file fresh.
  3. Rejection Rules: The plugin rejects stale anchors, ambiguous anchors, and invalid references, and never performs fuzzy matching.
  4. Persistent Undo: Supports undo_last_replace; undo records persist across restarts and restore content at byte-level precision.

Installation and Enablement

This is a DSH bundle (plugin package); users must install it into a specific profile.

# 从 GitHub 安装
dsh plugin --profile demo add github:ddv12138/dsh-hash-edit

# 从本地安装
dsh plugin --profile demo add ./dsh-hash-edit

# 从 npm 安装
dsh plugin --profile demo add @ddv12138/dsh-hash-edit

After loading this bundle’s patch into a profile, a plugin line is inserted to take over editing behavior. Since it is installed per profile, it can work under any preset / profile.

Usage Notes

When using this plugin, adhere to the following rules:

  • Single Edit: Each file allows only one edit per message.
  • Clean Hashes: When operating, copy only the clean 3-character hash, without line numbers or context.

Tool Invocation

The plugin provides the following tools:

  • read (hashline): Converts lines into HASH│content format, supports pagination, and records displayed ranges.
  • replace: Use remove_from / remove_to (clean 3-character hashes) to specify the range to remove, followed by replacement_text for replacement. One call supports only one modification.
  • undo_last_replace: Undoes the most recent replacement, restoring content to byte-level precision.

Rejection Codes

If file state mismatches or parameter errors occur during operation, the following rejection codes are returned:

  • [E_STALE_ANCHOR]: The anchor does not exist in the current file.
  • [E_AMBIGUOUS_ANCHOR]: The anchor matches multiple lines.
  • [E_RANGE_STALE]: The file has changed, or the range has never been displayed.
  • [E_BAD_REF]: The reference is not a clean 3-character hash.
  • [E_UNDO_STALE]: The file was modified after the last replacement.
  • [E_FILE_TOO_LARGE]: The file exceeds 238,328 lines or 100 MB.

Technical Details and Limitations

  • Algorithm: The anchoring algorithm is xxHash32(canon, seed 0) >>> 14 % 238328; generated anchors use a base-62 character set.
  • Storage: Undo records and snapshots are stored in .dsh-hash-edit/store.json in the project workspace (gitignored).
  • File Limits: The plugin only supports files with ≤ 238,328 lines and size ≤ 100 MB.

Conclusion

dsh-hash-edit provides a robust, content-hash-based approach to file editing, suitable for scenarios requiring precise control over line-level changes and frequent undo. For more details, see the GitHub repository or the community catalog.