Lefthook Commit Gate Lifecycle
How HI plans, materializes, verifies, and checks a consumer Commit Gate.
Lefthook Commit Gate Lifecycle
The lifecycle starts when hi init or hi update finds a Commit Gate Consumer. It ends when hi commit-gate verify passes against live repository facts; verify observes that state without repairing it.
Trigger and actors
- Trigger:
hi initorhi updateinstalls thecommit-gateRegistry Item for a supported JavaScript consumer.ensureexists only ashi tools ensure, which installs tools and does not touch the Commit Gate. - CLI:
hi initwrites the policy;hi initandhi updatecompile the Quality Command Contract, install the gate files, run Hook Activation or the Commit Gate Opt-Out, and report the result.hi commit-gate verifyobserves the live gate and writes nothing. - Git and Lefthook: Git runs the Managed Hook Script, which runs the checkout's own Lefthook
pre-commitevent.
Flow
-
hi initwritescommitGate: "enabled" | "disabled"to.devpunks/settings.json. An absent value means enabled. Writing the policy changes no hook state. -
Context compilation checks consumer eligibility and requires both lint and read-only format-check commands. An incomplete applicable contract fails with
IncompleteQualityCommandContractbefore desired actions are exposed. -
hi initandhi updateinstall the item:- the root
lefthook@2.2.2devDependency; - a YAML merge into
lefthook.ymlthat keeps consumer entries and adds HI-ownedpre-commit.commands.lint,no_auto_install: true,lefthook: node_modules/.bin/lefthookandassert_lefthook_installed: true; - the Managed Hook Script
.githooks/pre-commitand the Hook Activation script.agents/scripts/activate-git-hooks.mjs(both Copied).
- the root
-
Hook Activation: when the project has no root
scripts.prepare,hi initandhi updateaddnode .agents/scripts/activate-git-hooks.mjs; an existingprepareis kept and the report names the command to append. They then run the script once. The script setscore.hooksPathto.githooksonly when it is unset and installed Lefthook is 2.1.14 or later. It never overrides anothercore.hooksPath: that project gets a Hook Migration Proposal. -
hi commit-gate verifyobserves the live gate and writes no file. It passes only when all of these are true:- the hook state is
managed:core.hooksPathis.githooksand the sha256 of.githooks/pre-commitmatches the shipped Managed Hook Script; - the project-local Lefthook dependency, lockfile and executable are 2.2.2;
- the HI-owned
lintentry is active; - the hook is executable.
When
core.hooksPathis unset, the state isinactiveand verify namesnode .agents/scripts/activate-git-hooks.mjs. Anothercore.hooksPath(for example.husky) or an edited script isother: another hook manager owns the hook. - the hook state is
-
Normal
git commitruns the Managed Hook Script in every worktree, because worktrees share.git/config. The script fails closed whennode_modules/.bin/lefthookis missing. Lefthook invokes the runner: applicable staged owners each run once, lint and format-check run concurrently, and every failure is reported. Empty or non-applicable scope starts no quality process. -
Migration: a
bun installbefore Hook Activation lets Lefthook write its own.git/hooks/pre-commit. Oncecore.hooksPathis set, Git ignores that file. Verify reports it as inert and HI never deletes it. -
Commit Gate Opt-Out: when settings say
commitGate: "disabled",hi updateplans no Managed Hook Script and runs no Hook Activation. It removes.githooks/pre-commitonly when its digest matches, and unsetscore.hooksPathonly when it is.githooks. It reports both, and it reports a kept.git/hooks/pre-commit, which Git runs again after the unset. The runner also passes every commit while the policy is disabled.
Terminal outcomes
- Healthy:
hi commit-gate verifypasses. - Inactive:
core.hooksPathis unset; runnode .agents/scripts/activate-git-hooks.mjs. - Other manager: another hook path or script owns
pre-commit; HI does not override it. - Disabled: the Opt-Out removed only HI-owned hook state.
- Deliberately bypassed:
LEFTHOOK=0or--no-verifycan bypass the local gate. HI does not claim historical bypass detection; CI remains merge authority.
Validation signal
Focused CLI tests prove each verify state, the inert old hook, and the Opt-Out on real Git checkouts (commit-gate-capabilities.test.ts, commit-gate-command.test.ts, pipeline.test.ts). The baseline video, retro and plan move spec (AC-026 to AC-032) owns the Managed Hook Script decisions. The original Lefthook 2.1.10 evidence stays in the retained implementation notes.