Skip to main content

Module git

Module git 

Source
Expand description

The git half of an agent’s work facts: repository, branch and uncommitted files in its working folder.

git never runs on a request: a background loop probes each agent’s folder and the request reads the cache. An entry is re-probed once it is REFRESH_AFTER_MS old or the agent’s folder changed. Distinct folders are probed concurrently (MAX_CONCURRENT_PROBES at a time) and a probe is abandoned after PROBE_TIMEOUT, so with a handful of folders an entry is under ~30 s old; many slow repositories can make it older, which is why every answer carries git_checked_ms. Every git run goes through fs_ops::git’s safe runner (the repository’s own fsmonitor and filters are off, nothing prompts, the index isn’t written, a slow run is killed after a few seconds).

Structs§

Entry 🔒
GitCache
Probe results per block id, with the folder each was taken in.
GitFacts
What git says about one working folder.

Constants§

MAX_CONCURRENT_PROBES 🔒
Most probes running at once: each is a few git processes.
MAX_DIRTY_FILES 🔒
Most uncommitted paths kept per agent; GitFacts::dirty_count is the real total.
PROBE_TIMEOUT 🔒
A probe (several git runs, each with its own 4 s limit) is abandoned after this and the folder reads as having no git facts until the next.
REFRESH_AFTER_MS
An entry this old is probed again on the next tick.
TICK 🔒
How often the loop looks for entries to refresh.

Functions§

branch_files
The files a PR from head into base changes in root: git diff --name-only base...head, the base being origin/<base> (or a local <base>), else the default branch (origin/HEAD, origin/main, origin/master), and the head a local branch, else origin/<head>. Empty when either can’t be found, on the base itself, or when git can’t say in PROBE_TIMEOUT. A diff of two commits: no working-tree filter runs.
cache 🔒
cached
The cached facts for block in dir (see GitCache::get).
first_ref 🔒
The first of candidates that names a commit in root.
merge_base_setting
The branch’s gh-merge-base setting (gh’s base for a PR from it), if set.
plain_branch 🔒
A branch name taken from a command, safe to hand git: no option, range or whitespace.
probe
Probe dir: None when it isn’t inside a git repository (or git is missing or too slow).
refresh_once
One refresh pass: probe each due (block, folder) in folders, every distinct folder once and at most MAX_CONCURRENT_PROBES at a time, each abandoned after timeout, and store the results stamped now_ms.
run_git_refresh_loop
Keep every registered agent’s git facts fresh. Never returns.