Documentation
¶
Overview ¶
Package gitdiff captures the full workspace diff after an agent run: staged + unstaged changes plus non-ignored untracked files. Ignored files are outside this evidence contract unless they are already tracked.
Index ¶
- Variables
- func FilePatch(ctx context.Context, path string, before, after FileVersion) (string, error)
- func HeadCommit(ctx context.Context, dir string) (string, error)
- func WorkspaceDiff(ctx context.Context, dir, destPath string, excludes ...string) (wrote bool, err error)
- func WorkspaceDiffWithLimit(ctx context.Context, dir, destPath string, maxBytes int64, excludes ...string) (wrote bool, err error)
- func WorkspaceFiles(ctx context.Context, dir string) ([]string, error)
- type FileVersion
- type Info
Constants ¶
This section is empty.
Variables ¶
var ErrWorkspaceDiffLimit = errors.New("workspace diff byte limit exceeded")
Functions ¶
func FilePatch ¶
FilePatch builds a git-compatible unified patch for one repository-relative path without touching the caller's worktree or index.
func HeadCommit ¶
HeadCommit returns dir's HEAD commit SHA at call time. A non-git dir or a repository with no commits yet yields ("", nil); any other failure is an error, so a failed capture is never recorded as "no commits were made".
func WorkspaceDiff ¶
func WorkspaceDiff(ctx context.Context, dir, destPath string, excludes ...string) (wrote bool, err error)
WorkspaceDiff streams the combined staged+unstaged+untracked diff for dir into destPath and reports whether anything was written. An empty diff leaves no file. A non-git dir is a no-op (false, nil) — not every workspace is a repo. excludes are workspace-relative paths (forward-slashed) kept out of the diff, e.g. the run bundle dir so a run never captures itself.
Untracked staging uses a private snapshot of the repository index. The caller's real index is never modified, even transiently, so an interrupted capture cannot leave intent-to-add entries behind or race an unrelated Git operation. `git add --pathspec-from-file` requires git >=2.25.
func WorkspaceDiffWithLimit ¶
func WorkspaceDiffWithLimit(ctx context.Context, dir, destPath string, maxBytes int64, excludes ...string) (wrote bool, err error)
WorkspaceDiffWithLimit is WorkspaceDiff with an explicit maximum artifact size. Zero means unlimited. A limit failure aborts the secure temporary file, so callers never observe a partial workspace.diff.
func WorkspaceFiles ¶
WorkspaceFiles returns the tracked and untracked, non-ignored files in dir. It uses the same bounded context and scrubbed Git environment as the other evidence-capture helpers, so inherited repository overrides cannot redirect the listing away from dir.
Types ¶
type FileVersion ¶
type FileVersion struct {
Exists bool
Content []byte
// Mode is the source file's os.FileMode. Git records only the executable
// bit for ordinary files; a zero mode preserves the historical 100644
// default for callers that do not yet provide mode evidence.
Mode os.FileMode
}
FileVersion is one side of a captured file edit. Exists distinguishes an added/deleted file from an existing empty file.
type Info ¶
Info is the workspace git context recorded as run evidence: whether the workspace is a git repository, the commit the run started from (empty until the first commit exists), its branch (empty when detached), and whether the workspace already had uncommitted or untracked changes.
func WorkspaceInfo ¶
WorkspaceInfo reports dir's git context from a single `git status` call, so there is exactly one failure mode: a non-git dir is a no-op (zero Info, nil error) and any other git failure is returned rather than recording a possibly-wrong context as evidence. excludes follow WorkspaceDiff's contract — workspace-relative paths kept out of the dirty check. Nothing is implicitly excluded: callers must name the exact generated/control paths so legitimate tracked files under similarly named directories remain evidence.