Documentation
¶
Overview ¶
Package checkpoint — git commit + safety net for clawtool.
Per ADR-022 (drafting): the operator's "checkpoint" umbrella covers Commit (this file), autocommit, doc-sync rules, snapshot/ restore, and dirty-tree guard. v1 ships only the Commit primitive — Conventional Commits validation, hard Co-Authored-By block, and a pre-commit rules.Verdict gate. The richer pieces (autocommit, snapshot, guard) layer on top in subsequent commits.
Lives in internal/checkpoint, NOT internal/agents/biam — Codex's architectural review (BIAM task a3ef5af9) was explicit: "Do not reuse BIAM for checkpoint state. The overlap is 'SQLite exists,' not semantics." Checkpoint state is per-repo + per-session, not per-agent-task.
Index ¶
- func CurrentBranch(cwd string) string
- func IsClean(cwd string) (bool, error)
- func IsGitRepo(cwd string) bool
- func Stage(cwd string, paths []string, autoAll bool) error
- func StagedFiles(cwd string) ([]string, error)
- func ValidateMessage(msg string, opts CommitOptions) error
- type CommitOptions
- type CommitResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CurrentBranch ¶
CurrentBranch returns the symbolic branch name (or empty when detached). Used in CommitResult for the operator's render.
func IsClean ¶
IsClean reports whether the working tree has no unstaged or untracked changes (git status --porcelain returns empty). When AllowDirty is false, the Commit caller refuses to proceed if this returns false AFTER staging.
func IsGitRepo ¶
IsGitRepo reports whether cwd is inside a Git working tree. We shell out to `git rev-parse --is-inside-work-tree` rather than walking up looking for `.git` because submodules and worktrees both make the directory layout non-trivial; let Git answer the question.
func Stage ¶
Stage runs `git add` for each path. When paths is empty the caller may have set AutoStageAll, which is handled here too.
func StagedFiles ¶ added in v0.21.4
StagedFiles returns the list of staged paths (relative to cwd, forward-slash). Empty when the index is clean. Used by the Commit tool to populate rules.Context.ChangedPaths so `changed(glob)` predicates see what's actually about to land.
func ValidateMessage ¶
func ValidateMessage(msg string, opts CommitOptions) error
ValidateMessage runs every message-level check the operator configured. Returns nil when the message passes; otherwise an error naming the failed check first so a caller's error display reads cleanly.
Types ¶
type CommitOptions ¶
type CommitOptions struct {
// Message is the proposed commit message body. Validated
// against Conventional Commits unless RequireConventional
// is false.
Message string
// Cwd is the repo root. Defaults to current directory.
Cwd string
// Files lists paths to stage before committing. When empty,
// the existing index is used (operator stages manually or
// via AutoStageAll=true).
Files []string
// AutoStageAll runs `git add -A` before commit. Default
// false to avoid accidentally committing the world.
AutoStageAll bool
// AllowEmpty maps onto `git commit --allow-empty`. Default
// false — empty commits are usually a bug.
AllowEmpty bool
// AllowDirty bypasses the working-tree dirtiness guard.
// Default false — dirty trees during a commit usually mean
// "you forgot to stage something or autocommit raced you".
AllowDirty bool
// RequireConventional enforces the Conventional Commits
// shape. Default true (operator's policy); flip to false
// for prototype repos that don't bother.
RequireConventional bool
// Default true (operator memory feedback — never attribute
// to AI). The flag exists so other operators using
// clawtool can opt out; Bahadır's profile keeps it on.
ForbidCoauthor bool
// Push runs `git push` after the commit. Default false —
// auto-push is loud and should be opt-in per call.
Push bool
// Sign maps onto `git commit -S`. When true, fails fast
// if `git config commit.gpgsign` isn't already configured —
// no silent fall-through to unsigned commits.
Sign bool
}
CommitOptions captures every input the Commit primitive accepts. The MCP tool layer (internal/tools/core/commit_tool.go) maps JSON args onto this struct so Validate / Run / Push stay pure and testable in isolation.
type CommitResult ¶
type CommitResult struct {
Sha string `json:"sha"`
ShortSha string `json:"short_sha"`
Branch string `json:"branch,omitempty"`
Subject string `json:"subject"`
Files []string `json:"files,omitempty"`
Pushed bool `json:"pushed"`
CommittedAt time.Time `json:"committed_at"`
}
CommitResult is the structured return shape.
func Run ¶
func Run(ctx context.Context, opts CommitOptions) (CommitResult, error)
Run executes the actual `git commit -m <msg>` and returns the new SHA + branch + subject. ValidateMessage MUST have run before this point.