Preface¶
When running an agent in DeepSeek Harness (DSH), the model modifies workspace files via tools like write / edit. When changes are wrong, excessive, or when you want to preview before deciding whether to keep them, you need an actionable way to roll back. The community already has “conversation rewind”-style plugins that switch both conversation context and files back, suitable for “returning to before a certain message”; but if you only want to revert files to the state before a certain turn of conversation, want the model to be able to trigger it itself, need it to work in headless environments, and don’t want to depend on git, then you need a plugin dedicated to file-layer snapshotting and rollback. Below is an introduction to maintainer ruaibeite’s dsh-undo (category: admin-security), which snapshots before each write in the current turn lands on disk, and supports three entry points: a tool, the /undo command, and a Web GUI button.
What is this¶
dsh-undo is a host-side plugin for DSH: it saves a snapshot of the original content before each file write or edit lands on disk. The model can call the undo tool, or you can type /undo in the input box, or click ↶ Undo this turn in the assistant message action row, to revert all files modified during an entire conversation turn in one go (fine-grained single-file rollback by snapshot id is also supported). It does not fork shells, does not read credentials, makes no network requests, and does not touch git repositories; snapshots and the index are written under $DSH_HOME/undo/. If you need to roll back “conversation + files” together, you should choose conversation-rewind-style plugins such as dsh-rewind-plugin or dsh-recall-plugin; this plugin only operates at the file layer and is deliberately kept lightweight.
Differences from conversation-rewind-style plugins¶
| dsh-undo | Conversation-rewind-style (e.g., dsh-rewind-plugin, dsh-recall-plugin) | |
|---|---|---|
| Rollback target | Files (all files modified in this turn) | Conversation context + files |
| Who triggers | Model calls the undo tool; humans can type /undo; Web GUI has a button |
Mostly clicking a button in Web GUI or typing a command |
| Runtime environment | Host-side; works in headless and Web-UI-less profiles too | Primarily in Web GUI |
| Dependencies | None (no git dependency) | Most depend on git or session forking |
| Sandbox | Snapshots are written in-process via Node fs; no extra permission relaxation needed under workspace-write |
Writing to storage outside the workspace via shell may be denied by the sandbox |
Core functionality¶
Capture and turns¶
Two complementary paths only perform side-channel recording and do not change write semantics:
- Intent hooks (primary): hooked into the
fs/write-intent/fs/edit-intentwaterfall, able to obtain tool execution information such ascallIdandagent;prepend: trueis required, otherwise it may be truncated by the built-in observation policy. - fs service wrapping (fallback): wraps the prototype owning
writeText/editText; if no intent events are received, snapshots are still created.
The same write may hit both paths; the plugin deduplicates across mechanisms (same path, same event, within 250 ms, different mechanisms record only one entry).
Turn boundaries come from the seq of the most recent user/message event in the session log (by default, scanning the last sessionScanEvents entries); writes where the session cannot be read are assigned to the current in-progress turn.
The undo tool¶
The model can call undo:
| Parameter | Description |
|---|---|
action |
list: list snapshots by turn; restore: roll back |
id |
Roll back a single snapshot; takes priority over turn when provided |
turn |
Which turn to roll back: last (default), 1/2/… (newest to oldest), or a turn key shown by list |
limit |
How many turns to return when listing, default 10 |
dryRun |
When restoring, only report what each file would become, without writing to disk |
Rollback semantics highlights: when the same file is modified multiple times within one turn, restore the content corresponding to the earliest snapshot before the start of that turn; files newly created in this turn are deleted upon rollback; the rollback action itself is also snapshotted, so it can be undone again (equivalent to redo); a single file failure does not abort the whole turn, and results are reported item by item.
Manual entry: /undo command¶
| Command | Effect |
|---|---|
/undo or /undo list |
List recent turns |
/undo restore [turn] |
Roll back that turn; omitting the turn = the most recent turn |
/undo dry [turn] |
Preview, without writing to disk |
/undo id <snapshot-id> |
Fine-grained single-file rollback |
The command and the undo tool share the same execution logic. If the profile has no command registry, only the manual entry is missing; if /undo is already taken, it will automatically register as /undo-turn.
Web GUI: assistant message action row¶
On finalized assistant messages, the action row (next to copy, branch) will show ↶ Undo this turn; clicking it rolls back the most recent turn. The button executes the host command /undo 1, consistent with the tool and command behavior. Preview is available via /undo dry.
Installation and enabling¶
Install from GitHub (recommended by the README; dsh.bundle in package.json allows dsh to mount it automatically):
dsh plugin --profile web add github:ruaibeite/dsh-undo
Alternatively, after cloning the repository, use the bundled script (it will automatically switch to the desktop CLI):
./install.sh
PROFILE_NAME=headless ./install.sh
Restart dsh after installation for it to take effect. The plugin runs with the permissions of the current dsh process; please review the GitHub source and MIT license yourself before installing. Node >=20 is required (see engines in package.json).
Storage and configuration¶
$DSH_HOME/undo/
├── index.json # Snapshot index (id/time/path/existed/bytes/turn/sessionId)
└── files/<snapshot-id> # Snapshot contents
Writes inside $DSH_HOME are excluded. Corresponding entries in cordis.patch.yml can be configured:
| Key | Default | Description |
|---|---|---|
maxSnapshots |
300 | Maximum number of snapshots; oldest ones are evicted when exceeded |
maxFileBytes |
4194304 | Files larger than this are not snapshotted |
onlyToolWrites |
false | When true, only snapshot writes with a tool actor |
sessionScanEvents |
400 | Number of tail events scanned in the session log when locating turn boundaries |
listFilesPerTurn |
10 | Maximum number of files listed per turn when listing; the rest are summarized as omitted |
debug |
false | When true, events are written to $DSH_HOME/undo/debug.log |
Typical usage¶
- After installing and restarting dsh, let the agent modify several files within one conversation turn.
- Run
/undo listin the input box to view recent turns and file summaries. - Confirm which turn to revert: run
/undo dry 1to preview (1means the newest turn), or let the model callundo, e.g.,action: "restore", turn: "last", dryRun: true. - Run
/undo restore 1or have the modelaction: "restore"to complete the rollback; if only one file needs to be changed, use/undo id <snapshot-id>or the tool’sidparameter.
In the Web GUI, you can also directly click ↶ Undo this turn next to an assistant message; clicking again can undo the rollback just performed (because the rollback itself is snapshotted).
Use cases and notes¶
Suitable for: needing to batch-undo file changes by “conversation turn” in DSH; needing snapshots to still work under restricted sessions like headless / workspace-write (in-process fs, not relying on shell writes outside the workspace); not wanting to maintain a separate git shadow repository just for rollback; wanting the model to call undo itself when it mess up the code.
Limitations (verbatim from the README):
- Only rolls back files, not conversation.
- Only records writes via
ctx.fs; changes written directly to disk via shell or bypassing fs do not produce snapshots (if such a file is later written by a tool again, it will be snapshotted based on its then-existing state). - Single files larger than
maxFileBytesare not snapshotted. - Turn grouping depends on
user/messagein the session log; when unavailable, it degrades to grouping by tool calls. - Rolling back existing files goes through
ctx.fs.writeText, subject to file policy constraints (read-only sessions will be rejected); deleting files newly created in this turn usesfs.unlinkSync, the only write operation not going through the policy, used to restore “newly created” back to “non-existent”.
The DSH ecosystem is “everything is a plugin”; the community directory SkillHub plugin page is an independent site and has no official affiliation with DeepSeek / High-Flyer.
Conclusion¶
dsh-undo turns “per-turn file undo” into a lightweight host-side capability: dual-path snapshotting, the undo tool and /undo, and the GUI button share one set of logic, and recording works even under restricted sandboxes. If your need is conversation-layer rollback, choose a suitable rewind/recall-style plugin; if your main need is reversible operations after the agent modifies files, install it via the commands above and restart dsh.
- Directory page: https://www.skillhub.cn/plugins/ruaibeite/dsh-undo
- GitHub: https://github.com/ruaibeite/dsh-undo