Skip to content

Verification and commit gate

Terminal window
har env verify 1
har env verify 1 --full
har env verify 1 --full --json # structured result only

Quick verification should be fast enough for iteration. Full verification is the repository’s completion contract. The exact commands are adapted in .har/stages.json; typical full checks include unit tests, lint, readiness, browser E2E, and project-specific stages.

har env verify streams progress to stderr. It does not dump the per-step JSON contract afterward — that duplicated CI logs and agent context. Scripts that need the object can pass --json. Passing steps omit output; failed steps include a truncated excerpt.

HAR records CLI and MCP verification as run JSON and records the exact Git tree state for full verification. A later source edit invalidates that validation.

Every har env verify is a new factory run: its own run id, its own stage logs in .har/artifacts/<factory-run-id>/ and its own verification trace, even when the tree was verified before. A failed verify followed by a passing one of the same tree (for example after a factory line gate) is two runs, and both reach Mission Control and every other receiver. The validation record of a tree points at its latest run: that is the verify the commit gate checks, and the run a commit of that tree binds to, in its proof and trailers.

Init and maintain now offer to install the gate according to the user’s onboarding preferences. Configure that default once:

Terminal window
har preferences configure

Install or inspect it directly at any time:

Terminal window
har hooks install
har hooks status

HAR installs repository-level pre-commit and post-commit hooks that cover its worktrees:

  • pre-commit hashes the staged change batch and compares it with successful full validation;
  • post-commit associates the new commit SHA with that validation.

The gate is intentionally based on content, not timestamps or branch names.

Husky and other managed hooks (core.hooksPath)

Section titled “Husky and other managed hooks (core.hooksPath)”

When core.hooksPath is set, git runs hooks only from that directory, not .git/hooks. Husky sets it: v9 to .husky/_, a relative path that each worktree resolves against its own root and that husky generates on install, so it may not exist yet. HAR does not write into such a directory unless you ask it to.

har hooks install always installs the workers (har-pre-commit, har-post-commit and, for notes+trailers, har-commit-msg) in <git-common-dir>/hooks, which every worktree shares, and always runs the Factory Commits proof setup. Under a managed core.hooksPath it then reports which hooks are not active and prints the block for each one; it does not fail.

With husky, let HAR add the blocks to husky’s tracked hooks:

Terminal window
har hooks install --managed # appends a HAR block to .husky/pre-commit, post-commit (and commit-msg)
git add .husky && git commit -m "chore: run the har commit gate from husky"

Each block calls "$(git rev-parse --git-common-dir)/hooks/har-<hook>" only when that worker exists, so the same tracked files work in every worktree and do nothing in a clone without HAR. Re-running is idempotent; har hooks uninstall removes the blocks (commit that change too). har hooks status names the file each hook runs from, and says when core.hooksPath keeps the gate from running.

For another hook manager, add the printed blocks to its pre-commit, post-commit and, with notes+trailers, commit-msg hooks. --force writes into the core.hooksPath directory itself, which a manager like husky regenerates.

The workers re-enter the har that installed them and fall back to har on PATH, then node_modules/.bin/har, when that one is gone (for example after a Node version manager moves it). If none is found they skip with a notice and never block the commit.

In .har/stages.json:

{
"commitGate": {
"enabled": true,
"mode": "block",
"scope": "worktrees"
}
}

mode can be block or warn. scope can be worktrees or all; the default worktree scope enforces agent sessions while warning in ordinary checkouts. "enabled": false turns the gate off.

har onboard and har env maintain ask for the gate (off, warn or block) when nobody chose it yet, and record the answer with "recordedBy": "onboard" or "maintain". From then on har env maintain never changes the gate, and never reinstalls hooks you removed, unless you pass --commit-gate off|warn|block. A gate set to "enabled": false by hand counts as chosen too.

Terminal window
har env verify 1 --full
git add -A
git commit -m "fix: explain the validated change"

Stage everything that was verified. A partially staged tree is a different batch and should not pass the gate. Never bypass hooks to force an agent commit; run the required validation against the intended state.

Setup, levels, pushing notes and squash merges are covered in Record Factory Commits proofs. In short:

HAR can record its validations as Factory Commits proofs in git. HAR builds a factory-run predicate from each full validation. The git-factory executable (HAR_FACTORY_PROOF_BIN, else the copy HAR installs in ~/.har/factory-proof, else PATH) builds the statement and writes notes, trailers and verification. The mode is set per repository in the main checkout’s .har/harness.env (slot worktrees use it too):

Terminal window
HAR_FACTORY_PROOF=notes # off | notes | notes+trailers (unset: off)
  • Unset (the default) or off: no proofs. Nothing is attested, noted or installed, even when a git-factory is on the machine. har hooks install removes the proof setup an earlier mode added (fetch refspec, notes.rewriteRef, the trailer commit-msg hook) and keeps the notes; har proof disable sets off and does the same.
  • notes:
    • every har env verify --full attests the validated tree, stored next to the validation record;
    • post-commit adds that attestation to refs/notes/factory on the new commit; when HEAD already has the verified tree (re-verify after a rebase or amend), verify adds it to HEAD’s note itself;
    • har hooks install runs git factory setup (a fetch refspec into the tracking ref refs/notes/remotes/<remote>/factory, notes.rewriteRef), and har hooks uninstall undoes it. Publish notes with har proof sync.
  • notes+trailers: everything in notes, plus a managed commit-msg hook that adds Factory-Run and Factory-Attestation trailers for a verified tree, and a Work-Unit trailer when the slot was bound to a work unit (--work-id at launch, or har env work-bind). Re-run har hooks install after changing the mode.

A proof names a work unit and an attempt only when the slot is bound to one. A full verify that writes a proof with no work unit says so in one line; see Bind a work unit.

Proofs never block verify or a commit. When git-factory fails, or is missing under an explicit mode, HAR prints one line and carries on. Predicates never contain absolute paths, prompts, or work-unit titles or URLs.

Under notes or notes+trailers, HAR installs factory-proof 0.4.0 in ~/.har/factory-proof on har env launch and har hooks install, needs 0.2.0 or newer, and treats an older git-factory as missing; har hooks status shows what it found. Every HAR proof has environment.trust: self-reported, in CI too: the agent runs as the developer, so a proof records what this checkout reports, not an independent attestation. See Trust.

Inspect and verify proofs with har proof show [rev] and har proof verify [rev|A..B] [--min-level L0|L1|L2|L3] [--allowed-signers <file>] [--json]. MCP agents use har_proof_show and har_proof_verify. Both pass git factory output and exit codes through. The minimum level defaults to L1 for one commit and for a range.

har env complete 1 reuses the last passing full validation whose tree hash matches the current worktree, then tears the slot down and keeps the session branch. Verify-before-done already recorded that proof — complete does not re-run the suite by default.

If the tree changed after that verify (or there is no matching passing full validation), complete refuses and tells you to re-run:

Terminal window
har env complete 1 --verify

--verify is the previous default: full verification, record validation, then teardown. Use har env teardown 1 for cleanup without claiming completion. --skip-verify is a deprecated no-op; skip is already the default.