Preface¶
In DSH, enabling models to modify code often relies on the write and edit tools writing directly to disk. Across consecutive rounds of changes, relying solely on Git or manually comparing chats makes it hard to quickly answer “Which files were changed in this round, and would stepping back overwrite edits I made manually afterward?” The community plugin dsh-file-undo (maintainer: QinLuza, category: Memory) targets exactly this class of problems: it captures full‑text snapshots before every file write/edit, provides a side‑panel red/green diff for item‑by‑item review, and supports /undo with two‑stage confirmation. Current version 0.2.0, licensed under MIT.
What is this¶
dsh-file-undo is a DSH plugin designed to undo agent-performed write / edit operations on files. Rather than storing reverse patches, it saves the full “before” content before writing to disk and, when undoing, writes the entire file back; diffs are computed on‑the‑fly, decoupled from storage. Beyond chat commands, it provides a Web side‑panel “Undo” view (with an un‑undone count badge) and can switch sessions within the same project tree, auto‑following the currently viewed session.
Core Features¶
Visual Review Panel¶
After opening the review panel at the bottom of the side panel, it includes:
- History list: time, tool type (write / edit / create), file name, lines restored/removed, model turn; failed calls are also logged.
- Undo-perspective diff: green lines show content that will be restored on undo, red lines show current content that will be removed; very long content is truncated by default, with a “Show all” option after roughly 800 lines.
- Automatic pre‑check: opening an entry determines whether it can be safely undone and provides categorized reasons (see the safety model below).
- Two‑stage confirmation: the first click arms the action (auto‑disarms in about 3 seconds); the second click executes.
- Session switcher: lists sessions under the current directory and its parent/child directories, defaulting to follow the currently viewed session; can silently degrade in headless or similar environments.
Safety Model¶
The Host decides whether a file can be changed; the UI only displays the result. Pre‑check (preview) is a read‑only classification. Common reasons include: file_creation (undoing a creation will delete the file; requires both content and hash gates plus confirmation), external_modified (the file was manually changed after the snapshot; avoids swallowing human edits), superseded_by_later_ops (later edits exist on the same file; guides “RewindTo this state”), already_reverted, file_missing, stale, and others. Apply (commit) carries an expectedCurrentHash optimistic lock; if the file changes after preview, the apply is rejected. It also supports RewindTo (atomically writes back a selected historical entry and clearly indicates the number of subsequent steps that will be discarded) and cascading restore/redo, with state transitioning in a closed loop through recorded → reverted → reapplied. The /undo command in chat does not block on external_modified, preserving a forced‑undo semantics.
Commands¶
| Command | Effect |
|---|---|
/undo |
Undo the most recent file write/edit |
/undo list |
View the recorded operation history for the current session |
/undo <n> |
Undo the operation at the specified index |
/undo sessions |
List sessions in the same project tree (uses the same API as the panel switcher) |
/undo prune [days] |
Prune snapshots older than N days (default 7); only reduces rewind depth and does not touch current files |
/undo git [n] |
Restore the n‑th snapshot from the git archive (0 = latest) |
/undo git-status |
Show git archive health status |
Snapshot Storage and Archive¶
Snapshot directory structure (under the user’s home directory):
~/.dsh/file-undo/
<workspace-key>/ # Derived from a normalized session cwd
<chat-key>/ # Session id
snapshots.jsonl # Append-only
git-archive/ # One commit per snapshot; can silently degrade
On plugin load, a lazy 7‑day cleanup is performed; you can also run /undo prune manually. When paths differ but point to the same directory, they are normalized to the same workspace key.
Installation and Activation¶
The plugin runs with the permissions of the current DSH process; before installing, it’s recommended to read the GitHub repository source and the MIT license. Community directory page: skillhub plugin page (an independent site with no official affiliation with DeepSeek / High‑Flyer).
Option 1: Local build (link) — Run pnpm install && pnpm build in the repository directory, add a link: dependency to the profile’s package.json, then run pnpm install in the profile directory and restart DSH. The full steps in the README include git clone to obtain the source; see the official documentation.
Option 2: npm (once published):
dsh plugin --profile web add dsh-file-undo
For pure client‑side changes under link mode, a browser hard refresh is usually sufficient; Host‑side changes require restarting DSH.
Typical Usage¶
- Install and restart DSH (or configure your profile via the link method).
- In the Web UI, have the agent modify files via
write/edit; before each disk write, entries automatically enter the timeline. - Open the “Undo” icon at the bottom of the side panel, select an entry in the history list, review the pre‑check result and the red/green diff, and perform a two‑stage confirmation to undo; or use chat commands such as
/undo,/undo list,/undo 2. - If the pre‑check reports
superseded_by_later_ops, follow the panel’s guidance to use “RewindTo this state,” confirming the number of subsequent steps that will be discarded. - Periodically or as needed, run
/undo prune 7to clean up old snapshots; use/undo git-statusand/undo git [n]to inspect or restore from the git archive.
Use Cases and Limitations¶
Suitable for: scenarios where you frequently let agents modify the same repository, need to review diffs per round, want to quickly roll back entire files after an erroneous change, and the main modifications come from DSH’s write / edit.
Notes:
- Only covers
write/edit; direct file changes in the shell (redirects,Set-Content, etc.) do not enter the timeline. - “RewindTo this state” discards changes made afterward and does not replay against older baselines.
- The panel and session following depend on the Web UI; in headless environments, chat commands remain available.
- The HTTP API endpoints are
POST /file-undo/api/*, with Host header and Origin trust fences, intended for local/trusted environments only.
Conclusion¶
dsh-file-undo turns agent file changes into a reviewable timeline: full‑text snapshots, side‑panel diffs, pre‑checks with optimistic‑lock commits, plus /undo and rewind/redo loops. To try it or contribute code, start from the directory page and the repository:
- Directory page: https://www.skillhub.cn/plugins/QinLuza/dsh-file-undo
- GitHub: https://github.com/QinLuza/dsh-file-undo