Shadow Git¶
Invisible change tracking for working directories. Uses GIT_DIR + GIT_WORK_TREE to maintain a bare git repo that the agent never sees.
shadow_git
¶
Shadow git: invisible change tracking for the working directory.
Uses GIT_DIR + GIT_WORK_TREE to maintain a bare git repo in the run output directory. The agent never sees this repo — it's purely harness bookkeeping for capturing diffs and enabling replay via reset.
ShadowGit(work_dir, git_dir)
¶
Invisible git repo that tracks all changes in a working directory.
init()
¶
Initialize the shadow git repo.
commit_baseline(message='baseline')
¶
Stage everything and commit as the baseline snapshot.
commit_snapshot(tag, message=None)
¶
Stage all changes and commit with a tag.
diff_from_ref(ref='baseline')
¶
Get unified diff of all changes since a ref.
diff_working()
¶
Get unified diff of uncommitted changes (against HEAD).
diff_working_names()
¶
Get list of changed files in working tree (uncommitted).
show_file(ref, path)
¶
Get file content at a specific ref. Returns None if not found.
status()
¶
Get short status output.
hard_reset_to(ref='baseline')
¶
Reset working directory to a specific ref. Destructive.
add_worktree(dest, ref)
¶
Create a git worktree checked out at ref in detached HEAD mode.
Uses GIT_DIR only (not GIT_WORK_TREE) since worktree commands operate on the bare repo directly.
Returns the resolved destination path.
remove_worktree(dest)
¶
Remove a git worktree. Uses --force to handle dirty trees.
tag(name)
¶
Create or update a tag at HEAD.
begin_session(session_index, mode, fork_from=None, needs_reset=False)
¶
Prepare the working directory for a session based on mode.
Only resets the working directory when needs_reset is True, which is used for forked sessions when a sibling has already run and modified the working directory since the fork point.
end_session(session_index, replicate=None)
¶
Commit and tag all changes after a session completes.
get_session_diff(session_index, mode, fork_from=None)
¶
Get the diff for what this session changed relative to its starting point.