⨠feat(kavach): git writers and installs stop at an owned clone's fences, 0.6.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,rmandmvpass when every path they name misses every fence.., or no path with-p, counts as the whole checkout.applypasses when the paths from the guard's owngit apply --numstat -zmiss every fence. A branch switch (checkout <commit>,switch, and-fback toHEAD) passes whengit 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,gitwith 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, andconfigthat sets a value.
- Subcommands that never write the work tree pass:
- Package installs: only
pnpm install --frozen-lockfile --ignore-scripts --ignore-pnpmfilepasses, alone on its line. Every other pnpm, npm, yarn or bun install, update or removal is refused, and so arenpx,bunxandcorepack. veda'sprotectedPathsalso fencespnpm-workspace.yaml,.pnpmfile.cjs,.pnpmfile.mjsand.npmrc(.claude/kavach.json). The pinned kavach already readsprotectedPaths, so that part applies as soon as this merges. - Through another program:
xargs git ā¦,pnpm exec git ā¦,timeout 60 pnpm installand the like are refused. boundary.mutation_directoriescollects each mutating segment (words, cwd, prefix, whether it is alone on its line,sh -cincluded) 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,rebaseorstashin their clone; they commit a WIP instead of stashing. So a cloud session can no longer bringmaininto 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
mainwhose 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 (
--outputamong 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 gitandmise exec -- git; - 39 git shapes that still pass, plus one from a subfolder;
-fjudged againstHEAD, 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 -zreader and the program-running options.
- 57 refused git shapes (
- All 20
OwnCheckoutTesttests pass. The first fullpnpm checkfailed only on pariksha's doc-checks flake (ENOTEMPTYon 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 teststops 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, andmvwhen every path they name misses a fence,applywhen its own--numstatpaths do, and a branch switch whengit diffshows 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, plusnpx,bunx, andcorepack, 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.npmrcas 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.