AI agents can make destructive changes to working directories during development. git checkout . cannot handle uncommitted changes or non-repository directories, which is exactly the time window most frequently encountered in agent operations. dsh-rewind provides “time travel” capability for arbitrary directories through content-addressed snapshots and revocable undo commands.

What Is This

dsh-rewind is a DSH plugin maintained by liyixuan201211. It does not depend on git and can capture the state of uncommitted changes, never-tracked files, and non-repository directories, providing one-click rollback and a revocable undo mechanism.

Installation and Enablement

Install the plugin in a DSH environment:

dsh plugin --profile web add github:liyixuan201211/dsh-rewind

After installation, the rewind command can be used in any directory.

Core Features

  1. Content-Addressed Snapshots: Snapshot any folder; file content is addressed by SHA256 hash, supporting files up to 8 MiB.
  2. Revocable Undo: The undo command saves the current state before execution, so the undo operation itself can be undone again.
  3. General Directory Support: Supports both git and non-git directories.
  4. Command Wrapper: rewind exec wraps batch file modification commands and automatically takes snapshots before and after.
  5. Watch Mode: rewind watch provides protection through debouncing and content verification, suitable for long sessions.
  6. Safety Properties: Ensures atomic writes, pre-write content validation, non-recursive deletion, and append-only logs.

Typical Usage

Create a Snapshot

Before performing potentially destructive operations, create a marker:

rewind snap --label "before the refactor"

Undo Operations

The undo command is in “plan mode” by default. It does not directly modify files and only prints the operation plan:

rewind undo

To execute the undo, you must explicitly specify --yes:

rewind undo --yes

Batch Modifications and Rollback

Use rewind exec to wrap code transformation or build commands:

rewind exec -- npx jscodeshift -t transform.js src/

Long Session Protection

Start watch mode with a 2-second debounce:

rewind watch --debounce 2000

Storage Location and Exclusions

Snapshot data is stored under <root>/.rewind/ in the project root directory, including metadata, logs, and object files. Paths such as .git, node_modules, .venv, __pycache__, dist, build, and target are excluded by default. If a path has not been captured, the plugin rejects deletion of that path to ensure the safety of undo.

Exit Code Contract

The plugin defines operation status through exit codes:

Code Meaning
0 Operation succeeded
1 Error occurred while applying; some paths may not have been restored
2 Usage error
3 status: tree differs from the previous snapshot
4 undo: plan generated, but not executed (--yes not specified)
5 Rejected: unsafe path or uncaught content encountered
6 No-op (--yes not specified and no changes present)

Conclusion

dsh-rewind provides a reliable “regret pill” for agent development. Through content addressing and strict safety properties, it ensures the reversibility of directory state. For more details, refer to the plugin catalog page or the GitHub repository.