Skip to main content

Module git

Module git 

Source
Expand description

Git-based reconciliation for session close.

Backstop layer of the trust-fabric file-capture stack:

  1. (highest trust) specialized event types (agent.wrote_file)
  2. (medium) promoted from generic agent.called_tool
  3. (this module) shell out to git at session close and pick up anything an agent edited outside any captured tool channel

Why this matters: the trust-fabric bar is “if a file changed, it must appear in the receipt.” Hooks and MCP cover most paths but not all – an agent that ran sed -i inside a Bash command, a build tool that modified files, or any other untracked side effect would otherwise vanish silently. Running git diff and git ls-files --others at close catches the rest.

Fail-open by design: if the working dir isn’t a git repo, if the git binary is missing, or if any git command errors, returns an empty list. The receipt is still produced; reconciliation is a best-effort enhancement, never a gate.

Structs§

GitChange
One file change observed via git that wasn’t already captured by a tool channel. Mapped 1:1 into a synthetic AgentWroteFile event at session close so it flows through the normal aggregator and receipt composition path.

Functions§

current_head_sha
Capture the current HEAD commit SHA so it can be stored in the session manifest at session start. The session close pass uses it as the diff base for committed-during-session changes. Returns None when not in a git repo or no commits exist yet.
reconcile_changes
Collect every file change in repo_dir worth surfacing in a session receipt: working-tree modifications (staged or not), committed-since-since_sha changes (when provided), and untracked files.