✨ feat(kavach): git writers and installs stop at an owned clone's fences, 0.6.16

Merged
AT
15d ago
+1087-16

Slice: #142

What

Closes the gap #136 describes, with options B and C, which Alok picked in chat on 2026-11-16 ("go with B plus C, build it"). Inside a Claude cloud session's own clone (worktree.ownCheckout), kavach now judges git commands and package installs by what they can write, not only by the folder they run in:

  • git (new packages/kavach/python/kavach/clone_writers.py):
    • Subcommands that never write the work tree pass: add, commit, push, fetch, branch, tag, the reads, and plumbing that writes only the git folder. They are refused with an option that runs a program (--upload-pack, --receive-pack, --exec, grep -O).
    • checkout -- <path>, restore, rm and mv pass when every path they name misses every fence. ., or no path with -p, counts as the whole checkout.
    • apply passes when the paths from the guard's own git apply --numstat -z miss every fence. A branch switch (checkout <commit>, switch, and -f back to HEAD) passes when git diff --name-only <sha> -- <fences> is empty. These three run only as a command of their own, so an earlier command on the line can't change what they read.
    • Exact option tables per subcommand. An unknown option, a git abbreviation (--har), --pathspec-from-file, a pathspec with magic or a glob, an alias, git with anything before it, and every other subcommand are refused: merge, pull, rebase, cherry-pick, revert, am, stash, clean, sparse-checkout, read-tree -u, switch --orphan, clone, and config that sets a value.
  • Package installs: only pnpm install --frozen-lockfile --ignore-scripts --ignore-pnpmfile passes, alone on its line. Every other pnpm, npm, yarn or bun install, update or removal is refused, and so are npx, bunx and corepack. veda's protectedPaths also fences pnpm-workspace.yaml, .pnpmfile.cjs, .pnpmfile.mjs and .npmrc (.claude/kavach.json). The pinned kavach already reads protectedPaths, so that part applies as soon as this merges.
  • Through another program: xargs git …, pnpm exec git …, timeout 60 pnpm install and the like are refused.
  • boundary.mutation_directories collects each mutating segment (words, cwd, prefix, whether it is alone on its line, sh -c included) for this check. Desktop worktree sessions are unchanged.

kavach and sarathi go to 0.6.16.

Still open (README, ownCheckout, "The limit:")

Repository code that a command runs. A session can edit scripts/*.mjs and run pnpm check, or write .tmp/x.ts and run pnpm exec tsx .tmp/x.ts, and reach every fence that way. A trustedCommands script also runs before these checks. #136 left this class out on purpose. Closing it is a separate decision: for example, whether a cloud session's guards must run from a node_modules/ it can't have touched.

What this costs cloud sessions

  • No pull, merge, rebase or stash in their clone; they commit a WIP instead of stashing. So a cloud session can no longer bring main into its branch or resolve a merge conflict there. A pull request that falls behind or conflicts is finished from a desktop session or a fresh clone.
  • No switch to a main whose fenced files differ from theirs, which means every pin bump.
  • No installing a new dependency or a new workspace package.

Evidence

  • OwnCheckoutTest: the four gap rows flip from exit 0 to exit 2. New rows cover:
    • 57 refused git shapes (--output among them), plus three from a subfolder or through -C;
    • the alone-on-its-line rule;
    • git and pnpm run through another program, with the reason checked for pnpm exec git and mise exec -- git;
    • 39 git shapes that still pass, plus one from a subfolder;
    • -f judged against HEAD, and a name that is both a tag and a branch judged both ways;
    • git config exported on the line;
    • only the frozen install running;
    • a worktree session judged as before;
    • unit rows for the --numstat -z reader and the program-running options.
  • All 20 OwnCheckoutTest tests pass. The first full pnpm check failed only on pariksha's doc-checks flake (ENOTEMPTY on a temp folder; see #132), and every part then passed separately: kavach, pariksha, sarathi, provenance, script tests, lint, guards. A second full run, after the last fixes, failed only on dvara's wall-clock test stops waiting on output a leftover process holds open (Date.now() - started < 2500; dvara is untouched here), with the machine at a load average of about 88. That test also failed alone under that load. CI is the clean run.

After merge

Tag v0.6.16, bump the root pin to sarathi 0.6.16, then Alok runs pnpm install in the main checkout. Until then, sessions run 0.6.13.

šŸ¤– Generated with Claude Code


Summary by cubic

Closes the gap where git and package commands could rewrite fenced files inside a cloud session's own clone by writing files their command lines do not name. In owned clones, kavach now judges these commands by what they can write, not just the folder they run in. Desktop worktree sessions are unchanged.

  • Git runs only subcommands that never write the work tree, plus checkout --, restore, rm, and mv when every path they name misses a fence, apply when its own --numstat paths do, and a branch switch when git diff shows the fenced paths match. Everything else — merge, pull, rebase, stash, clean, aliases, abbreviations, unknown options — is refused.
  • Only pnpm install --frozen-lockfile --ignore-scripts --ignore-pnpmfile, alone on its line, passes. Every other pnpm, npm, yarn, or bun install, update, or removal, plus npx, bunx, and corepack, is refused.
  • Git or a package manager run through another program (xargs git, pnpm exec git, timeout 60 pnpm install) is refused.
  • veda fences pnpm-workspace.yaml, .pnpmfile.cjs, .pnpmfile.mjs, and .npmrc as well.

What cloud sessions lose

pull, merge, rebase, and stash no longer run in their clone, switching to a branch whose fenced files differ is refused, and new packages or dependencies cannot be installed.

The limit

A package script or other repository code a command runs can still reach fences — editing scripts/*.mjs and running pnpm check, or writing .tmp/x.ts and running pnpm exec tsx .tmp/x.ts. Closing that is a separate decision, and issue #136 left it out on purpose. Kavach and sarathi bump to 0.6.16.