Expand description
Shared plumbing for the linter-orchestration hooks.
Nine of them do the same four things: collect staged files of some kind, bail out if there are none, resolve a tool, run it. In shell that was ~65 lines apiece, mostly duplicated; here it is a handful of helpers and each hook keeps only what is actually specific to it.
Structs§
- Activity
- What a spawned command has been doing, shared between the reader threads
that see its bytes, the CPU sampler, the wait loop that judges it, and the
progress displays. Every field is an atomic offset from
base, so the 80 ms repaint and the 25 ms wait loop read it without a lock. - Clocks
- The budgets one wait is judged under — the inputs to
judgethat do not move while the command runs. - Commit
Index - The index
git commitis sealing, and the repository it belongs to. - Killed
- A command killed by a clock — what happened, said with enough to tell “slow” from “stuck”, which is the whole reason there are two clocks.
Enums§
- CpuGate
- What the kill decision may rest on from the CPU side (ADR-0009). Not
sampled at all: the silence-only rule, as ever. Measured: the silence
budget, because “silent and idle” was actually observed. Unmeasured —
sampling is on but the last sample was late, partial, or has not come
yet: the EXTENDED budget,
greengate.idleTimeout × greengate.idleLoadScale, which is bounded even when the ceiling is off, and never the bare silence budget, because that would kill on a measurement nobody made. - CpuState
- What the CPU side of
Activityknows. Stored as au8. - CpuVerdict
- What the CPU sampler could say when a command was killed.
- Index
Lookup Error - Why
commit_indexcould not locate the index. - Lock
Wait - The budget for a declared wait, as
lock_waitreads it. - Ran
- What became of a command run under the deadline.
- Restaged
- What a re-stage actually did. THREE answers, because the old
boolconflated two of them and the conflation shipped unformatted code. - Retry
- Whether a check’s tool may be run once more after a kill (ADR-0009).
- Why
- Which clock killed a command.
Constants§
- BUSY_
MILLI_ CORES - A work window of at least this many thousandths of one core counts as the tree doing something (ADR-0008): 0.1 core. A hang — a prompt, a lock, a dead network — sits near zero; a test suite runs at whole cores.
- INDEX_
ENV - The variable a pre-commit command is told the index being committed in:
see
commit_index. - INDEX_
GIT_ DIR_ ENV - The absolute git dir of the repository that index belongs to: a consumer
honours
INDEX_ENVonly where its owngit rev-parse --absolute-git-diris this, so a suite’s fixture repository never reads the outer index. - LAST_
LINE_ CHARS - How much of a tool’s last stderr line a message may quote.
Functions§
- bounded_
success status_within, collapsed to “did it exit 0” — the shape the one-shot tool spawns want. A timeout says so, nameswhat, and reads as failure.- capture_
within - Run to completion under the
greengate.timeoutdeadline with stdout and stderr CAPTURED into a string the caller can parse — what the audit checks need: their verdict lives in the tool’s output, not its exit code alone. Arrival-ordered merge of both streams, likestatus_streamed’s blocks.Nonewhen the child cannot be spawned. - check_
timeout - The wall-clock CEILING for one check’s spawned command, in seconds.
- commit_
index - The index
git commitis sealing, as an absolute path: git’s ownGIT_INDEX_FILEwhen it handed the hook one (the temporary index ofcommit -aorcommit <paths>), else the repository’s index. Relative paths are resolved against this process’s directory, where git ran the hook. Paths are kept as bytes, so a non-UTF-8 one survives. The error names the step that failed, with git’s own reason. - cores
millithousandths of a core as people read it:~3.9 cores.- fail
- first_
existing - The first of
namesthat exists at the repo root — how these hooks decide a repo has opted into a tool. - fixing_
enabled - Whether the user asked for checks to repair what they find.
- fixing_
requested - What the CONFIG says, ignoring whether the current run may act on it.
- hl
- Orange, for the fragments these hooks highlight.
- human_
secs secsas people read it:12s,8m12s,1h02m.- idle_
cpu_ credit - Whether a silent check that is measurably working on CPU is kept alive
past the silence budget —
greengate.idleCpuCredit, default true (ADR-0008,hooks.liveness).falserestores the silence-only rule everywhere. Read once perSettings, like the two clocks. - idle_
load_ scale greengate.idleLoadScale: how far the silence budget may stretch, as a factor — under load (ADR-0009, the load-scaled budget) and whenever the CPU could not be measured (the extended budget,idleTimeout × this). Default 4,1disables the stretch, range 1..=16. A HOST key: read from global or system config only, never from a repository, because it describes the machine and two repositories must not disagree about it.- idle_
timeout - The SILENCE budget: how long a spawned command may go without writing a byte before it is judged stuck, in seconds.
- judge
- Which clock, if any, has fired — the decision, with no process or clock of its own so it can be tested to the second.
- lock_
wait - How long a command may sit in a DECLARED wait — a line that says it is
blocked on a lock (
crate::hooks::wait::marker) — before it is killed, in seconds.greengate.lockWait, default 600;0means until the ceiling. The silence clock does not run during such a wait: the tool has said what it is doing, and a lock held by another cargo for a minute on a loaded machine is not a hang (ADR-0009). Read once perSettings. - network_
probe_ budget - The deadline for a network PROBE — an
ls-remoteasked before the real work, not the work itself. Capped at 30s belowcheck_timeout: a probe answers in a second or two when the network is there at all, and a healthygreengate.timeoutof ten minutes is sized for a test suite, not for deciding whether the remote is reachable. Shrinkinggreengate.timeoutbelow the cap shrinks this too, and0keeps meaning no deadline — somebody who disabled the clock disabled all of it. - not_
the_ index - Whether the file set every check sees is something other than the index.
- ok
- A check passed. THE funnel for every success line, which is what lets
greengate.quietswallow them in one place — seecrate::live::quiet. - override_
file_ set - Make every subsequent
staged_filesanswer fromfilesinstead of the index. Only the first call counts. - program
- Resolve a tool name to a full path for spawning.
- repo_
root - Repo root, or “.” when git cannot say.
- repo_
root_ checked - Repo root, or an error naming the problem.
- restage
- Re-stage exactly the paths a fixer rewrote, and say what happened.
- retry_
budget - Whether a kill earns the one retry, and with how much ceiling left
(
Some(None): the ceiling is off). Only after a SILENCE kill whose last line reads like a wait — never after a declared wait outlived its own budget, nor at the ceiling — and only while the ceiling has at least one silence budget left. Pure. - run
- Run
argvfromroot, inheriting stdio. True when it exits 0. - run_
quiet - As
run, but with the tool’s own output discarded. - sampling_
schedule - When sampling starts and how often it repeats, from the silence budget:
quiet for
max(250 ms, min(30 s, budget/3)), then everyclamp(budget/4, 250 ms, 10 s)— so even a one-second budget is sampled several times before it runs out. - say
- A line with no sign of its own — what a check’s direct
println!becomes, so it lands in the check’s block instead of interleaving. Seelive::say. - say_
timed_ out - Say a command was killed, by which clock, and what that tells you.
- staged_
docs_ only - Whether the staged change is ONLY edits to existing documentation: every
path a modification (an added, deleted or renamed file can break a citation
in either direction, so it is never skipped) with a documentation
extension, outside the decision registry’s
adr/, whose records the decision graph is built from. False when the file set is not the index, when git would not say, and for an empty change. - staged_
files - An empty
extsreturns them all. - status_
streamed status_within, with the child’s stdout and stderr CAPTURED into the calling check’s slot instead of inherited — the other half of one-check- one-block: a linter’s twelve lines used to land on the shared terminal between two other checks’ lines. Falls back to plainstatus_withinwhen no slot is installed on this thread (greengate.progress false, or a spawn outside a stage), which is byte-for-byte the old behaviour.- status_
within cmd.status(), bounded bycheck_timeout.- status_
within_ secs status_withinwith an explicit ceiling — the testable seam. The output is inherited, so nobody sees the bytes and the silence budget cannot apply; the ceiling is the only clock.- strip_
git_ env - Strip git’s own environment before handing a Command to another tool.
- tracked_
files - Every path the index holds — what the repository CARRIES, as opposed to what the current change touches.
- warn
- which
- First match for
toolon PATH. - which_
on whichagainst an EXPLICIT path list — the seam its own test needs.