dsh-hashline-edit-pro: Edit Files with Content Hash Anchors, Line Number Independent

Preface

The common approach for letting models modify local files in DSH is to locate content by line number or full-text string matching. Once a file is changed externally, or a snippet referenced by the model appears elsewhere, the wrong line can easily be modified—and sometimes this isn’t caught before the write. dsh-hashline-edit-pro is a dynamic DSH plugin that assigns each line of text a unique 3-character content hash as its “address.” Reads, replacements, and rollbacks all operate around hash anchors. If an anchor is stale, the plugin throws an error before writing and returns new anchors from the current context, rather than silently corrupting the file. This plugin is maintained by sleepinginsummer and ported from the Pi Coding Agent ecosystem’s pi-hashline-edit-pro. It is categorized as a client plugin in the SkillHub plugin directory.

What This Is

dsh-hashline-edit-pro (same name as the npm package, current version 0.1.0, MIT license) registers three tools with DSH: hashline_read, replace, and undo_last_replace. The core idea is: the edit target is always a hash, never a line number or raw string match.

The differences from the original Pi version are deliberate: the DSH side adds the three tools above while retaining the built-in read / edit / write to avoid breaking sandbox observation policies; the hash implementation is switched to pure-JS xxh32, with state persisted to ~workspace/.dsh-hashline-state.json in the workspace; image reads are rejected with guidance to use the built-in read_image.

Core Features

hashline_read

Reads files in the form HASH│content: each line is prefixed with a 3-character alphanumeric hash, without line numbers. Supports offset / limit pagination; with raw: true it can return normal content with line numbers. Empty files output a single line HASH│ as an anchor. Images, binaries, and UTF-16 are rejected with guidance.

replace

Uses remove_from / remove_to (raw 3-character hashes) to specify the line range to replace, and writes new content via replacement_text (pass "" to delete that range). Anchor validation failures throw errors such as [E_STALE_ANCHOR], [E_AMBIGUOUS_ANCHOR], [E_RANGE_STALE], etc., along with the new anchor context from the current file; reversed ranges are automatically corrected. If pasted content includes HASH│ prefixes, they are automatically stripped with a warning. The returned result includes a diff with HASH│ (the + lines are the new anchors), facilitating chained consecutive edits.

Unchanged lines keep their original anchors (content-derived base + bitmap probing + stable hash mapping), so chained edits typically don’t require re-running hashline_read every time. There is also a served-state guard: only hashes the model has “seen” in reads or diffs can be replaced, reducing the risk of fabricating anchors out of thin air.

undo_last_replace

Rolls back the last replace on a specified file; undo records are persisted and can still be rolled back after restarting DSH. If the file was modified externally after the replace, the rollback is refused with [E_UNDO_STALE].

File and Security Boundaries

Preserves BOM and line endings (LF / CRLF / CR); UTF-8 decoding anomalies produce warnings. Single file limit is approximately 100MB / 238,328 lines; writes go through DSH’s fs service using atomic writes. In sandbox-restricted environments this maps to standard [sandbox: ...] markers with a prompt to upgrade using the built-in write. If undo persistence fails, the edit still executes but with an [E_UNDO_UNAVAILABLE] warning.

Installation and Activation

The installation command follows the README verbatim:

dsh plugin --profile <name> add dsh-hashline-edit-pro

Replace <name> with your DSH profile name. Restart DSH after installation; hashline_read, replace, and undo_last_replace will then be available to all sessions.

The plugin runs with the current DSH process’s permissions; before installing, it is recommended to review the source code and MIT license in the GitHub repository to confirm it meets your environment policies. SkillHub is a community directory site with no official affiliation with DeepSeek or High-Flyer.

Typical Usage (Workflow)

Below is a reproducible mental model; refer to the tool schema for specific parameters.

  1. Read first: call hashline_read on the target path to get text like abc│first line content; note the 3-character hashes of the start and end lines of the range you want to change (e.g., remove_from, remove_to).
  2. Then edit: call replace, filling in the hash range and replacement_text; if a stale-class error is returned, re-specify the range based on the new anchors in the response and do not force the write.
  3. Chain edits: use the new anchors from the + lines in the returned diff to perform consecutive replace calls; anchors of untouched lines remain unchanged.
  4. Undo: call undo_last_replace on the same file to undo the last replacement (provided the file hasn’t been further modified externally).

For a normal view with line numbers, use raw: true in hashline_read; for images, use the built-in read_image—do not use this plugin to read images.

Use Cases and Caveats

Suitable for: letting the model perform precise, verifiable local text edits in DSH; multi-step patch-style modifications; replace operations requiring persistent undo.

Notes:

  • Anchors and served state depend on the plugin state file and workspace paths; there is a cap on the number of paths (documented as a 256-path limit).
  • Compared with the original Pi version, the DSH version does not override built-in read/edit, so built-in tools may still be mixed in daily use; don’t mix hash editing and line-number editing in the same logic while assuming line numbers remain valid.
  • On the development side: npm test runs 32 test cases (node –test), covering xxh32, anchor uniqueness, stale/range validation, EOL/BOM, etc.; the main logic lives in the pure core section //PURE-CORE-START..END of the single file src/host.js.

Closing

dsh-hashline-edit-pro brings the workflow of “locate lines by content hash, validate anchors before writing, diffs with new anchors, persistent undo” into DSH, and makes porting trade-offs for coexistence with sandboxing and built-in tools. For further information, visit the SkillHub directory page and the GitHub repository.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye