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§
- Hook
Conflict - A foreign hook manager klasp recognises and refuses to overwrite.
- Hook
Error - Hook
Kind - Which git-hook this block targets. Drives the
--triggerarg passed through toklasp gate, and the on-disk filename (.git/hooks/pre-commitvs.git/hooks/pre-push). - Hook
Warning - Structured warning surfaced by
CodexSurface::install_detailedwhen 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_blockgreps 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 shform — 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/bashdependency.
Functions§
- contains_
block truewhenexistingalready 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_blockadds the markers themselves. - uninstall_
block - Inverse of
install_block: remove klasp’s managed block and the blank-line separator install inserted around it.