Skip to main content

Module git_hooks

Module git_hooks 

Source
Expand description

Git-hook managed-block writer + conflict detection for CodexSurface.

Codex has no programmatic gate equivalent (see [docs/design.md] §1), so enforcement runs through real .git/hooks/pre-commit and .git/hooks/pre-push scripts. This module is the analogue of crate::agents_md for those shell files. The block is anchored by the MANAGED_START / MANAGED_END marker pair so re-installing never disturbs sibling content. detect_conflict sniffs each hook for husky / lefthook / pre-commit-framework fingerprints; on a match, callers must skip writing and surface a HookConflict in their report (never fail, never clobber). The idempotency contract matches crate::agents_md: round-trip canonicalises trailing-newline state to a single \n; bytes outside the block are byte-for-byte preserved.

Enums§

HookConflict
A foreign hook manager klasp recognises and refuses to overwrite.
HookError
HookKind
Which git-hook this block targets. Drives the --trigger arg passed through to klasp gate, and the on-disk filename (.git/hooks/pre-commit vs .git/hooks/pre-push).
HookWarning
Structured warning surfaced by CodexSurface::install_detailed when the hook write was skipped (or otherwise non-fatally adjusted). Never raised as an error — the install completes; the warning rides alongside the report.

Constants§

MANAGED_END
Closing marker for klasp’s managed block in a git-hook file.
MANAGED_START
Opening marker for klasp’s managed block in a git-hook file. Stable across schema bumps; install_block greps for this exact substring to decide whether the file already has a klasp section.
SHEBANG
Shebang klasp uses when it has to fresh-create a hook. We pick the portable /usr/bin/env sh form — git itself ships hook samples with the same shebang, so users running this on minimal Alpine / BSD images get a working interpreter without a hard-coded /bin/bash dependency.

Functions§

contains_block
true when existing already contains a (well-formed) klasp managed block — used by callers to decide whether install is a no-op.
detect_conflict
Inspect a hook file’s contents for a recognised foreign hook manager.
install_block
Splice klasp’s managed block into existing, returning the new file body.
render_managed_block
Render the full managed block (markers + body) for the given hook.
render_managed_body
Render the inner body of klasp’s managed block for the given hook kind. Pure: no env, no IO. The result is the lines between the markers — render_managed_block adds the markers themselves.
uninstall_block
Inverse of install_block: remove klasp’s managed block and the blank-line separator install inserted around it.