git-tools
v0.6.0Git tools for coding agents: state, commits, rewrites and stacked branches, worktrees and pushing.
These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.
git_repo_read Read the git repository
Read the git repository. method "status": the state of the working tree: the branch, its upstream and ahead/behind counts, the remote default branch as recorded locally with the merge-base and the branch's own commits, staged, unstaged, untracked and conflicted files, an operation in progress (rebase, am, merge, cherry-pick, revert, bisect), stashes, worktrees, and when origin was last fetched. It reads only local refs, so fetch first for fresh remote state. Lists stop at 50 with truncated. method "conflicts": the conflicts a merge, rebase, cherry-pick or revert left: the operation, what ours…
| Parameter | Type | Description |
|---|---|---|
method * | string | "status" reads the working tree state: branch, upstream, base, staged, unstaged, untracked and conflicted files, an operation in progress, stashes, worktrees, and last fetch. "conflicts" reads the ope… |
file | string | origin: with lines, the file to blame; with token or regex, limits the search to it; relative to the working tree root. |
limit | integer | conventions: how many recent non-merge commits to sample (default 30). |
lines | string | origin: "10,20" or "10,+5": the range to blame (its first line's commit is returned). |
paths | array | conflicts: only these conflicted files, as paths relative to the working tree root (default all). |
regex | string | origin: find the commit that introduced a match of this regular expression (git log -G). |
sha | string | origin: the commit to read. |
token | string | origin: find the commit that introduced this exact string (git log -S). |
git_commit_read Read the checks before a commit
Read the checks that apply before a commit. method "lint": check a candidate commit message: the subject's hard limit and its target from the repository's history, the blank line after the subject, body wrapping, whitespace and a trailing period, and the conventional type(scope) shape where the history uses it; also the repository's commitlint when it is installed, and a commit-msg hook that needs a missing commitlint is an error. Lint the exact text that will be committed, because rewrapping it afterwards defeats the check. method "secrets": scan the added lines of the staged changes, the uns…
| Parameter | Type | Description |
|---|---|---|
method * | string | "lint" checks a candidate commit message against the built-in rules and the repository's commitlint. "secrets" scans a diff for credentials. "hunks" lists the unstaged hunks to stage. "amend" says how… |
body_wrap | integer | lint: the body width in columns that draws a warning (default 72). |
message | string | lint: the full candidate commit message, subject, blank line, body, exactly as it will be committed. |
paths | array | secrets, hunks: only these files or directories, relative to the working tree root (default all). |
range | string | secrets: the commit range for target "range", such as "main..HEAD". |
sha | string | amend: the commit to correct (default HEAD). |
subject_max | integer | lint: the subject's hard limit in columns (default 72). |
target | string | secrets: what to scan: "staged" (the default) is the index against HEAD, "worktree" the unstaged changes, "range" a commit range. |
git_commit_stage Stage chosen hunks
Stage exactly the named hunks of a git_commit_read hunks listing into the index. Pass the listing's digest with the ids and the same paths: the call recomputes the diff and stages nothing when it differs from the listing, so a stale listing never stages other hunks. The working tree is untouched. Ids are positions in one listing, so list again after staging. A binary file cannot be staged by hunk; stage it whole with git add.
| Parameter | Type | Description |
|---|---|---|
digest * | string | The digest of the git_commit_read hunks listing the ids come from. |
hunks * | array | The ids of the hunks to stage, from that listing; a repeated id is staged once. |
paths | array | The same files or directories the listing was made with, relative to the working tree root. |
git_commit_create Commit the staged changes
Commit exactly what is staged, with the message it was given; nothing that is not staged goes in. The message is linted first, as git_commit_read lint does (the built-in rules and the repository's commitlint), and the staged diff is scanned for credentials, as git_commit_read secrets does. The message is then normalized once the way git would clean it and committed byte for byte, so the repository's hooks see the text that was checked. Hooks run as the repository configures them and are never skipped. Findings named by fingerprint in accept_findings are let through; read each one first. A chec…
| Parameter | Type | Description |
|---|---|---|
accept_findings | array | The fingerprints (file:line:rule) of secret findings you read and judged false positives; they no longer stop the commit. |
body_wrap | integer | The body width in columns that draws a warning (default 72). |
fixup | string | Commit the staged changes as a fixup of this earlier commit of the branch (a sha or a ref; on a stack, commit it on the top branch, where a commit of a lower layer is a valid target); the message is t… |
message | string | The full commit message, subject, blank line, body, exactly as it should land in the history. Pass it or fixup, not both. |
subject_max | integer | The subject's hard limit in columns (default 72). |
git_commit_amend Amend the last commit
Replace HEAD with a commit holding the staged changes and the message given, or HEAD's own message when none is given; with nothing staged it rewords. The message is checked, the staged diff scanned, and the repository's hooks run exactly as git_commit_create does, with the same check_failed details. The rewrite follows the rule for rewriting commits: a branch's own commit may be amended even once pushed, and needs_force_push then says the push needs a force push; the default branch, a commit already on it, and a commit another remote branch holds are never amended, nor is a commit that branch…
| Parameter | Type | Description |
|---|---|---|
accept_findings | array | The fingerprints (file:line:rule) of secret findings you read and judged false positives; they no longer stop the commit. |
body_wrap | integer | The body width in columns that draws a warning (default 72). |
message | string | The new full commit message, exactly as it should land in the history; HEAD's own message when omitted. |
subject_max | integer | The subject's hard limit in columns (default 72). |
git_commit_verify Check each commit of the branch
Check that every commit after base passes on its own: each one is checked out, oldest first, in a throwaway worktree (its checkout hooks off) and command is run there, after an optional one-time setup. It stops at the first failing commit unless keep_going is set, and checks at most 30 commits; pass a nearer base for a longer branch. A failing command is a result, not an error: the result lists each commit's outcome with its duration and the tail of a failure's output. The caller's checkout, index and stashes are untouched, and the worktree is removed afterwards. The command gets only the allo…
| Parameter | Type | Description |
|---|---|---|
command * | string | The check to run at each commit with `sh -c`, e.g. `pnpm run typecheck && pnpm test`. |
base | string | Commits after this ref are checked; by default the merge-base of HEAD and the remote default branch. |
dir | string | The directory inside the repository to run setup and command in, relative to the working tree root; the root by default. |
keep_going | boolean | Check every commit even after a failure (default false). |
setup | string | Run once in the throwaway worktree before the first check, e.g. installing dependencies. |
timeout_sec | integer | The limit in seconds for each run of command, and for setup (default 600). |
git_rebase_read Read the stack of the branch
Read the stack of the checked-out branch. method "stack": a stack is the local branches on the current branch's line between the remote default branch and the top, read from ancestry; nothing is recorded, so a stack made by any tool or by hand reads the same. It returns the base (the remote default branch and the merge base), the current branch and the top, and per layer, bottom to top: its branches, tip, the commits it adds (at most 30, oldest first, with how many there are and how many are fixup!, squash! or amend! commits), how each branch stands to its own remote branches (same, ahead: a p…
| Parameter | Type | Description |
|---|---|---|
method * | string | "stack" reads the stack of the checked-out branch: its layers, their commits, how each stands to its remote branches, and whether the whole stack may be rewritten. |
top | string | stack: the branch the stack ends at, when the branches above this one fork. |
git_rebase_start Rebase the stack
Rebase the whole stack of the checked-out branch without an editor, folding fixup!, squash! and amend! commits in (autosquash). Every layer branch moves with it, each staying on the one below, and HEAD ends on the branch it started on. By default it fetches the remote default branch and replays the stack on its latest state, dropping a commit whose change the base already has. keep_base only folds the fixups on the current base, with no fetch: a fix for a lower layer is committed on the top as a fixup (git_commit_create with fixup), then folded here. after names a layer branch below the top wh…
| Parameter | Type | Description |
|---|---|---|
after | string | A layer branch below the top whose layers already landed (squash-merged, say): only the layers above it are replayed, and it and the layers below it are not moved. |
keep_base | boolean | Fold the fixups only: replay on the current base, with no fetch. Not with onto or after. |
onto | string | The commit or ref to rebase onto; by default the remote default branch, fetched first. Not with keep_base. |
top | string | The branch the stack ends at, when the branches above the current one fork. |
git_rebase_resume Resume the stopped rebase
Continue, skip or abort the rebase that git_rebase_start left stopped on conflicts, an empty commit or a failing hook. action "continue" first stages every conflicted file whose working copy holds no conflict markers (a deleted file counts as resolved), so resolve the files by editing them, with no git add; when a file still holds markers it runs nothing and returns paused with unresolved naming the files. Then it continues the rebase. action "skip" drops the commit being replayed (what to do for a commit that became empty). action "abort" ends the rebase and puts every layer branch back where…
| Parameter | Type | Description |
|---|---|---|
action * | string | "continue" stages the conflicted files you resolved (no conflict markers left) and goes on; "skip" drops the commit being replayed; "abort" gives up and puts every branch back where it was. |
git_rebase_split Cut the branch into layers
Cut the checked-out branch into stacked layers. at lists the last commit of each new lower layer, bottom up, and names the new branch for each: a branch is created at that commit, and the current branch stays the top of what it held. Nothing is rewritten and nothing is checked out; the new layers are plain local branches, each on the one below. add starts a new empty layer on top of the current branch: a new branch at the same commit, checked out, so uncommitted changes stay and the next commit lands on the new layer. It works from the top of the stack only. at and add can be given together. I…
| Parameter | Type | Description |
|---|---|---|
add | string | The name of a new empty layer to start on top of the current branch and check out. |
at | array | The last commit of each new lower layer, bottom up: commits of the current layer, never its tip. Each gets a new branch (see names). |
names | array | The new layer branches' names, one per at entry, in the same order. |