# Version History & Rollback

Every file write is automatically tracked with an immutable version history. You can view, restore, and roll back files at any time - no manual snapshots needed.

## Tools

### file_versions
List the version history of any file. Shows version numbers, timestamps, sizes, and sources.

```
file_versions({ path: "src/index.html" })
```

### file_version_restore
Switch a file to any version - older or newer. No data is lost; it just changes which version is active.

```
file_version_restore({ path: "src/index.html", version: 2 })
```

### rollback
Restore files and folders under a path to their state at a given point in time. Supports scoping to a specific directory and recursive/non-recursive modes.

```
rollback({ datetime: "2026-04-08T14:30:00Z" })                          // entire project
rollback({ datetime: "2026-04-08T14:30:00Z", path: "src/components" })  // one folder, recursive
rollback({ datetime: "2026-04-08T14:30:00Z", path: "src", recursive: false })  // direct children only
rollback({ datetime: "latest" })                                                // undo previous rollback
```

## How It Works
- Every file write creates an immutable version with a timestamp
- `file_version_restore` switches which version is active - all versions are preserved
- `rollback` derives the project state at any point in time from the version history
- Rollback handles both files (version-based) and folders (timestamp-based)
- Files created after the target time are removed; files that existed are restored
- All operations are wrapped in a transaction - atomic and safe

## When to Use
- User says "undo that" → use `file_versions` + `file_version_restore` for one file
- User says "go back to before I changed everything" → use `rollback` with a datetime
- Something broke after a series of changes → `rollback` to before the changes
- Compare what changed → `file_versions` shows the full timeline per file
