Documentation
¶
Index ¶
- func FindRoot(start string) (string, error)
- func IsFullCommitHash(s string) bool
- func ProviderFromRemoteURL(remoteURL string) string
- func SemanticaHookMarker() string
- type Commit
- type FileStat
- type HookInstallOptions
- type Repo
- func (r *Repo) ChangedFilesForCommit(ctx context.Context, hash string) ([]string, error)
- func (r *Repo) ChangedPathsBetween(ctx context.Context, fromCommit, toCommit string) ([]string, error)
- func (r *Repo) ChangedPathsFromCommitToWorktree(ctx context.Context, commit string) ([]string, error)
- func (r *Repo) CommitFormat(ctx context.Context, commitHash, format string) (string, error)
- func (r *Repo) CommitSubject(ctx context.Context, commitHash string) (string, error)
- func (r *Repo) CommitSubjects(ctx context.Context, commitHashes []string) (map[string]string, error)
- func (r *Repo) CommitSubjectsBetween(ctx context.Context, base, head string, limit int) ([]string, error)
- func (r *Repo) CountCommitsBetween(ctx context.Context, base, head string) (int, error)
- func (r *Repo) CurrentBranch(ctx context.Context) (string, error)
- func (r *Repo) DefaultBaseRef(ctx context.Context) (string, error)
- func (r *Repo) DiffAll(ctx context.Context) ([]byte, error)
- func (r *Repo) DiffBetween(ctx context.Context, base, head string) ([]byte, error)
- func (r *Repo) DiffCached(ctx context.Context) ([]byte, error)
- func (r *Repo) DiffForCommit(ctx context.Context, hash string) ([]byte, error)
- func (r *Repo) DiffStatForCommit(ctx context.Context, hash string) ([]FileStat, error)
- func (r *Repo) DiffWorkingTree(ctx context.Context) ([]byte, error)
- func (r *Repo) HeadCommitHash(ctx context.Context) (string, error)
- func (r *Repo) HooksDir(ctx context.Context) (string, error)
- func (r *Repo) InstallSemanticaHook(ctx context.Context, opts HookInstallOptions) error
- func (r *Repo) IsDirty(ctx context.Context) (bool, error)
- func (r *Repo) ListFilesFromGit(ctx context.Context) ([]string, error)
- func (r *Repo) LogSince(ctx context.Context, since time.Time, limit int) ([]Commit, error)
- func (r *Repo) MergeBase(ctx context.Context, a, b string) (string, error)
- func (r *Repo) OrdinaryTrackedFiles(ctx context.Context) ([]string, error)
- func (r *Repo) ReadFile(relPath string) ([]byte, error)
- func (r *Repo) RemoteURL(ctx context.Context) (string, error)
- func (r *Repo) RemoveFile(relPath string) error
- func (r *Repo) ResolveRef(ctx context.Context, ref string) (string, error)
- func (r *Repo) RestoreFile(relPath string, content []byte, mode os.FileMode, isSymlink bool, ...) error
- func (r *Repo) Root() string
- func (r *Repo) StatusShort(ctx context.Context) (string, error)
- func (r *Repo) TrackedFilesAtCommit(ctx context.Context, commit string) ([]string, error)
- func (r *Repo) WriteFile(relPath string, b []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FindRoot ¶ added in v0.5.0
FindRoot resolves the given path to the enclosing git repository root, returning the canonical (symlink-resolved) path. Worktrees backed by a .git file are accepted. Returns an error if no .git is found up to the filesystem root.
Callers that need a full *Repo handle should use OpenRepo. FindRoot is the lightweight option for code that only cares about whether a path belongs to a repository and which one.
func IsFullCommitHash ¶ added in v0.6.0
IsFullCommitHash reports whether s is a full lowercase SHA-1 or SHA-256 object ID.
func ProviderFromRemoteURL ¶
ProviderFromRemoteURL returns the hosting provider based on the remote URL hostname. Returns "github", "gitlab", or "unknown".
func SemanticaHookMarker ¶ added in v0.3.9
func SemanticaHookMarker() string
SemanticaHookMarker returns the marker written into Semantica-owned git hooks.
Types ¶
type Commit ¶ added in v0.4.0
type Commit struct {
// ShortHash is git's abbreviated hash (typically 7 chars).
ShortHash string
// Subject is the first line of the commit message.
Subject string
// Body is the trimmed remainder of the commit message; empty
// when the commit has no body. Already newline-normalized.
Body string
}
Commit is one entry in the result of LogSince. Used by the handoff bundle to render each commit's subject and (when non-empty) body separately, so a session-summary commit with substantive details doesn't get truncated to its first line.
type HookInstallOptions ¶
type Repo ¶
type Repo struct {
// contains filtered or unexported fields
}
func (*Repo) ChangedFilesForCommit ¶
ChangedFilesForCommit returns the repo-relative paths (forward slashes) of files changed by the given commit. Uses git diff-tree, the canonical plumbing command for listing files touched by a commit.
func (*Repo) ChangedPathsBetween ¶ added in v0.6.0
func (r *Repo) ChangedPathsBetween(ctx context.Context, fromCommit, toCommit string) ([]string, error)
ChangedPathsBetween returns paths that differ between two commit trees. Renames are reported as a deletion and an addition.
func (*Repo) ChangedPathsFromCommitToWorktree ¶ added in v0.6.0
func (r *Repo) ChangedPathsFromCommitToWorktree(ctx context.Context, commit string) ([]string, error)
ChangedPathsFromCommitToWorktree returns staged, unstaged, and deleted paths relative to commit. It overrides Git settings that weaken stat validation. On Unix, ctime and inode changes expose same-size rewrites with restored mtimes. Windows has no equivalent signal, so callers that require this guarantee must disable reuse there. Git still skips assume-unchanged and skip-worktree entries; use OrdinaryTrackedFiles to exclude them.
func (*Repo) CommitFormat ¶ added in v0.4.0
CommitFormat runs `git show -s --format=<format> <commitHash>` and returns the trimmed output. Callers compose multi-field formats (e.g. "%H%n%an%n%ai%n%s") and parse the result by line. This is the single git-show entry point for callers that need more than just the subject.
func (*Repo) CommitSubject ¶
func (*Repo) CommitSubjects ¶ added in v0.6.0
func (r *Repo) CommitSubjects(ctx context.Context, commitHashes []string) (map[string]string, error)
CommitSubjects resolves subjects for many commits in a single git invocation. This keeps large lineage-record listings from spawning one git process per row.
Keys of the returned map are the full commit hashes as git prints them (%H); callers that look up by input should pass full hashes. Unknown or pruned hashes are skipped (--ignore-missing), not errors.
func (*Repo) CommitSubjectsBetween ¶
func (r *Repo) CommitSubjectsBetween(ctx context.Context, base, head string, limit int) ([]string, error)
CommitSubjectsBetween returns commit subject lines (no hashes) for commits reachable from head but not from base, newest first, capped at limit.
func (*Repo) CountCommitsBetween ¶ added in v0.5.4
CountCommitsBetween returns the exact number of commits reachable from head but not from base. Used by callers that need an honest "dropped N commits" report when truncating: a limit-clamped log query cannot reveal the real total.
func (*Repo) CurrentBranch ¶
CurrentBranch returns the current branch name (e.g. "main", "feature-x"). Returns "HEAD" for detached HEAD state.
func (*Repo) DefaultBaseRef ¶
DefaultBaseRef returns the best-guess default branch ref for the repository. Resolution order: refs/remotes/origin/HEAD, origin/main, origin/master, main, master.
func (*Repo) DiffAll ¶
DiffAll returns a unified diff of all uncommitted changes: staged, unstaged, and untracked files. Untracked files are represented as new-file diffs so the LLM sees their full content.
func (*Repo) DiffBetween ¶
DiffBetween returns the unified diff between two refs (three-dot: from merge-base of a and b to b). This shows only changes introduced on the feature branch, not upstream drift.
func (*Repo) DiffCached ¶
DiffCached returns the unified diff of staged changes against HEAD. Used by the commit-msg hook to compute AI attribution before the commit is finalized (the commit hash doesn't exist yet at that point).
func (*Repo) DiffForCommit ¶
func (*Repo) DiffStatForCommit ¶
DiffStatForCommit returns per-file added/deleted line counts for the given commit using git diff --numstat. Binary files are included with 0/0 counts.
func (*Repo) DiffWorkingTree ¶ added in v0.4.0
DiffWorkingTree returns the combined unstaged + staged diff against HEAD. Used by the handoff bundle to surface uncommitted changes; callers redact the result before including it in any agent-visible payload.
func (*Repo) InstallSemanticaHook ¶
func (r *Repo) InstallSemanticaHook(ctx context.Context, opts HookInstallOptions) error
func (*Repo) IsDirty ¶
IsDirty returns true if the working tree has any changes: -modified, staged, deleted, untracked
func (*Repo) ListFilesFromGit ¶
func (*Repo) LogSince ¶ added in v0.4.0
LogSince returns commits whose author-date is at or after the given time, capped at limit entries (default 20 when limit<=0). Each Commit carries the short hash, subject, and body so the handoff bundle can render them with their full context rather than collapsing each commit to a single line.
func (*Repo) OrdinaryTrackedFiles ¶ added in v0.6.0
OrdinaryTrackedFiles returns index paths tagged "H" by git ls-files -v. It excludes entries whose working-tree content Git does not verify, including assume-unchanged, skip-worktree, unmerged, and removed entries.
func (*Repo) RemoveFile ¶
func (*Repo) ResolveRef ¶
ResolveRef resolves a git ref (HEAD, branch name, tag, commit prefix) to a full commit hash. Returns an error if the ref is not valid.
func (*Repo) RestoreFile ¶
func (r *Repo) RestoreFile(relPath string, content []byte, mode os.FileMode, isSymlink bool, linkTarget string) error
RestoreFile restores a file from a checkpoint manifest. It handles both regular files (with correct mode bits) and symlinks. For backward compatibility, if mode is 0 it defaults to 0644.
func (*Repo) StatusShort ¶ added in v0.4.0
StatusShort returns `git status --short` output (one line per file, e.g. " M path/to/file"). Used by the handoff bundle to summarize uncommitted changes a fresh agent session needs to know about.
func (*Repo) TrackedFilesAtCommit ¶ added in v0.6.0
TrackedFilesAtCommit returns the paths tracked in the given commit's tree. The id must be a full commit hash.