✨ feat(kavach): keep agents off the files a repository's git hooks run, 0.7.6

Merged
AT
12d ago
+725-38

Slice: #235

Option A, Alok's choice; approved on the proposal. Plan and limits: https://claude.ai/artifact/V1xgxQaWqvzD9Kkww5vxgZ

veda's hooks run from the tracked .githooks/, so each worktree runs its own copy, and an agent could edit it to skip the checks on its own pushes. This adds a kavach setting that keeps agent sessions off those files, and readies veda to use it.

kavach (0.7.6)

  • worktree.protectedPaths and worktree.protectedPathsReason: paths that stay refused in every checkout a session owns, its Claude-managed worktree included. An owned clone adds them to ownCheckout.protectedPaths. Each refusal quotes the reason.
  • Refused: an Edit, Write or NotebookEdit of a listed path, and Bash targets in or holding one (sed -i, cp, rm, chmod, ln, through sh -c or pnpm exec too), compared by file identity.
  • Also refused: a command that names the checkout's root as what it writes (rm -rf ., chmod -R a-x ., find . -delete, cp file .). This holds in an owned clone too.
  • In a worktree, git's checkout [<ref>] -- <path>, checkout <path>, restore, rm, mv and apply are judged by the paths they name.
  • Left open: merges, rebases, stash, reset --hard, branch switches, index plumbing, pnpm install and package scripts. The README names that limit.
  • Tests:
    • refused: an Edit, a Write, a NotebookEdit, a MultiEdit and Bash writes to .githooks/pre-push, git's path writers, the named root, and a pnpm-linked package on both spellings;
    • allowed: reads of the hook (cat, git diff, git show) and normal worktree work;
    • an owned clone, and the settings' validation.
  • Plainest open gap: git runs no hook that is absent, so git switch --detach <a commit without .githooks/>, then a push, skips every local check. Branch switches stay open by design; the README says so. Main's required checks still bind merges.
  • No corpus rows: the corpus runs every row under corpus/kavach.config.json in one fixture, and the setting would change that fixture for all of them. The adapter tests above cover the refusals end to end, as the hook runs them.
  • 0.7.6: v0.7.5 was tagged from #242 while this was open, so this is the next legal version.

veda

  • scripts/guards.sh now holds the guards line. pre-push runs it directly, and pnpm guards is bash scripts/guards.sh. The hook reads none of package.json's scripts, so package.json (pins, dependencies) stays agent-editable and is not on the list.
  • CLAUDE.md ("Git hooks") and docs/lessons/git-github.md say what is protected and how a hook change happens: Alok makes it, or allows one session by taking the path off the main checkout's list.

Not in this PR, on purpose

.claude/kavach.json gets veda's list in the pin-bump PR. Sessions load the main checkout's copy, and the pinned kavach (0.7.4, or 0.7.5) refuses every call on a key it does not know. The entry:

"protectedPaths": [".githooks/", "scripts/guards.sh", "scripts/released-pins.mjs", ".dvara.json", ".veda/records-baseline.json", ".veda/required-settings.json", ".github/niyam.json", "node_modules/"],
"protectedPathsReason": "veda's git hooks run them on every commit and push, from each worktree's own copy (veda#235); Alok changes them, or allows one session by taking the path off this list in the main checkout (CLAUDE.md, Git hooks)"

Steps

#StepWho
1This PR merges (auto-merge; no code-owner path)agent
2Tag v0.7.6 on main and push itAlok
3PR: sarathi pin → 0.7.6, plus the kavach.json entry aboveagent
4Pull main in the main checkout, pnpm install there (a session start also installs a pin that is behind)Alok

🤖 Generated with Claude Code