Harness Intelligence Wiki
Domains

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 init or hi update installs the commit-gate Registry Item for a supported JavaScript consumer. ensure exists only as hi tools ensure, which installs tools and does not touch the Commit Gate.
  • CLI: hi init writes the policy; hi init and hi update compile the Quality Command Contract, install the gate files, run Hook Activation or the Commit Gate Opt-Out, and report the result. hi commit-gate verify observes the live gate and writes nothing.
  • Git and Lefthook: Git runs the Managed Hook Script, which runs the checkout's own Lefthook pre-commit event.

Flow

  1. hi init writes commitGate: "enabled" | "disabled" to .devpunks/settings.json. An absent value means enabled. Writing the policy changes no hook state.

  2. Context compilation checks consumer eligibility and requires both lint and read-only format-check commands. An incomplete applicable contract fails with IncompleteQualityCommandContract before desired actions are exposed.

  3. hi init and hi update install the item:

    • the root lefthook@2.2.2 devDependency;
    • a YAML merge into lefthook.yml that keeps consumer entries and adds HI-owned pre-commit.commands.lint, no_auto_install: true, lefthook: node_modules/.bin/lefthook and assert_lefthook_installed: true;
    • the Managed Hook Script .githooks/pre-commit and the Hook Activation script .agents/scripts/activate-git-hooks.mjs (both Copied).
  4. Hook Activation: when the project has no root scripts.prepare, hi init and hi update add node .agents/scripts/activate-git-hooks.mjs; an existing prepare is kept and the report names the command to append. They then run the script once. The script sets core.hooksPath to .githooks only when it is unset and installed Lefthook is 2.1.14 or later. It never overrides another core.hooksPath: that project gets a Hook Migration Proposal.

  5. hi commit-gate verify observes the live gate and writes no file. It passes only when all of these are true:

    • the hook state is managed: core.hooksPath is .githooks and the sha256 of .githooks/pre-commit matches the shipped Managed Hook Script;
    • the project-local Lefthook dependency, lockfile and executable are 2.2.2;
    • the HI-owned lint entry is active;
    • the hook is executable.

    When core.hooksPath is unset, the state is inactive and verify names node .agents/scripts/activate-git-hooks.mjs. Another core.hooksPath (for example .husky) or an edited script is other: another hook manager owns the hook.

  6. Normal git commit runs the Managed Hook Script in every worktree, because worktrees share .git/config. The script fails closed when node_modules/.bin/lefthook is 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.

  7. Migration: a bun install before Hook Activation lets Lefthook write its own .git/hooks/pre-commit. Once core.hooksPath is set, Git ignores that file. Verify reports it as inert and HI never deletes it.

  8. Commit Gate Opt-Out: when settings say commitGate: "disabled", hi update plans no Managed Hook Script and runs no Hook Activation. It removes .githooks/pre-commit only when its digest matches, and unsets core.hooksPath only 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 verify passes.
  • Inactive: core.hooksPath is unset; run node .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=0 or --no-verify can 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.

Sources

On this page