Documentation
¶
Overview ¶
Package gitx is the small amount of git this server needs to answer two questions about a delegated task: what did the worker change, and can it be given a working directory of its own.
It shells out to git rather than linking a library. The worker is already driving the same repository through the same binary, and matching its view exactly matters more here than avoiding a process — a library reading the index differently from the git the agent just ran would report changes that are not there.
Every function is read-only unless its name says otherwise, and every one of them degrades to a clear error rather than guessing when the directory is not a repository.
Index ¶
- func AddWorktree(ctx context.Context, repo, path, branch string) error
- func Available() (string, bool)
- func Branch(ctx context.Context, dir string) string
- func Head(ctx context.Context, dir string) (string, error)
- func RemoveWorktree(ctx context.Context, repo, path, branch string, force bool) error
- func Root(ctx context.Context, dir string) (string, error)
- type FileChange
- type Report
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddWorktree ¶
AddWorktree checks out a new branch at path, sharing the repository's history but with a working directory of its own.
This is what lets several workers run at once without fighting: agents edit files, and two of them in the same checkout will overwrite each other's work and produce a diff neither of them intended. A worktree gives each one an isolated tree while keeping one git history, so the result can still be reviewed and merged normally.
func Head ¶
Head returns the commit dir is currently on. It returns "" with no error in a repository that has no commits yet, which is a legitimate state rather than a failure — a task can still be started there.
func RemoveWorktree ¶
RemoveWorktree deletes a worktree and its branch. Without force it refuses when the tree still holds uncommitted work, which is the whole reason the worktree existed.
Types ¶
type FileChange ¶
type FileChange struct {
Path string `json:"path"`
Status string `json:"status"` // human-readable: modified, added, deleted, renamed, untracked
Added int `json:"added,omitempty"`
Deleted int `json:"deleted,omitempty"`
}
FileChange is one path the worker touched.
type Report ¶
type Report struct {
Repo bool `json:"repo"`
Root string `json:"root,omitempty"`
Branch string `json:"branch,omitempty"`
BaseCommit string `json:"base_commit,omitempty"`
HeadCommit string `json:"head_commit,omitempty"`
Commits []string `json:"commits,omitempty"` // made since base, newest first
Files []FileChange `json:"files,omitempty"`
Added int `json:"lines_added"`
Deleted int `json:"lines_deleted"`
Patch string `json:"patch,omitempty"`
Truncated bool `json:"patch_truncated,omitempty"`
Dirty bool `json:"dirty"` // uncommitted changes are present
}
Report is everything that changed in a working directory since a base commit.
func Summarize ¶
func Summarize(ctx context.Context, dir, base string, patch bool, maxPatchBytes int) (Report, error)
Summarize reports what changed in dir since base.
base is the commit the task started from. Comparing against it — rather than against HEAD — is what makes the answer useful when the worker committed its own work: a diff against HEAD would show nothing at all and read as "the agent changed no files", which is the opposite of the truth.
An empty base falls back to comparing the working tree against HEAD, which is all that can be known when the starting point was never recorded.