Skip to main content
Track file changes in a hidden git repo so agents can snapshot, diff, and restore workspace files without touching your real repository.
The user approves autonomous edits; shadow-git snapshots let the agent diff, undo, or redo workspace changes safely.

Quick Start

1

Simple Usage

Enable change tracking on an autonomous agent — full_auto turns on snapshots automatically:
2

With Configuration

Use AutonomyConfig for explicit control, or call FileSnapshot directly:
3

Re-root After a Workspace

Agent.__init__ roots change tracking at os.getcwd(). Attach a per-session directory later, then call set_snapshot_root() so undo() restores the right place:

Re-rooting Change Tracking

set_snapshot_root(project_path) re-roots undo/redo/diff at a directory known only after construction — the moment a bot, gateway, or custom wrapper attaches a per-chat Workspace. Returns boolTrue when a snapshot manager is rooted at the given path, False if construction failed (e.g. git unavailable).
Re-rooting clears the undo/redo stacks — they belong to the previous root. The old shadow repo is orphaned (still on disk under ~/.praisonai/snapshots/), and only future changes are tracked at the new root.

Bot / Gateway Workspaces

Bots and gateways call Agent.set_snapshot_root(workspace.root) from apply_bot_smart_defaults() immediately after attaching the per-chat Workspace. So /undo in a Slack, Discord, or Telegram chat reverts files in that chat’s workspace — never the gateway’s process cwd. Custom wrappers that attach a workspace after Agent.__init__ should do the same:
See Bot Gateway for how the gateway wires this automatically.

How It Works

Git must be available on PATH. If shadow-repo init fails, tracking is skipped silently and undo() returns False.

Restore Guarantees

restore() (and agent.undo()) rebuilds the project to exactly the target snapshot’s tree:
The ignored-file guarantee is what makes agent.undo() safe to call in projects that keep secrets in .env. Both _sync_files() and restore() build their exclusion set from _build_ignore_patterns(), so a file the snapshot never tracked can never be pruned by a restore.

Common Patterns

Selective restore

List recent snapshots


Best Practices

When using autonomy="full_auto", call agent.undo() rather than manual restore() — the agent maintains an undo/redo stack across iterations.
Call track(message=...) (or run the agent once) before bulk refactors so you have a named rollback point.
The shadow repo honours .gitignore patterns plus built-in defaults (.git, __pycache__, node_modules, venv, .venv, .pytest_cache, .mypy_cache). Ignored files are neither snapshotted nor pruned by restore(). A .env file that lives outside version control survives every undo() / restore().
Call snapshot.cleanup() to remove the shadow repository if you no longer need history for a project.
Agent.__init__ roots the snapshot at os.getcwd(). If you attach a Workspace (or any per-session root) later, call agent.set_snapshot_root(str(workspace.root)) immediately — otherwise agent.undo() restores files in the wrong directory. Re-rooting clears the undo/redo stacks; rooting at the current directory is a no-op.

File Editing

Safe find-and-replace tools agents use before snapshots capture the result

Autonomy Loop

Configure track_changes and autonomous file-editing levels