✨ feat(kavach): reviewed CLIs run with free-text arguments
Slice: #67
kavach gains worktree.reviewedCLIs: a CLI whose writes the consumer reviewed runs from the owned worktree with free-text arguments. That covers niyam review-thread PRRT_… --reply "<text>" and the niyam lines athya_mono needs for W-56 (athya-hq/athya_mono#3617). The decision is Alok's on #67: "Decision: build #67 (W-56 choice 1A)".
What the setting does
-
The entry. An entry names a
program, itssubcommandsand areason. Eachsubcommandskey is the subcommand's leading words ("keep-going --stop"is two). Its value can declarepathOptions(--opt v/--opt=v) andpathOperands. -
Where it runs. A matching line runs only from the owned worktree's root, after the ownership check. While a push runs it waits, as a trusted command does.
-
Paths and data. Each declared path is resolved, symlinks followed, and confined like any other destination, so the refusal is the standard "outside this session's Claude worktree". Every other word is data, quoted free text included.
-
The words. The line is matched by its own lexer (
reviewed_cli_words), not by the shell parser:- words are bare
[A-Za-z0-9._/=:,@+%-], single-quoted text, or double-quoted text with no$, backtick or backslash; - a bare word may not start with
=(zsh expands=lsto/bin/ls); - so a redirection, pipe, chain, newline, comment, glob,
~,$(…), backticks or an env prefix is never a reviewed CLI's line.
This holds in both
command.shellExpansionmodes; the tests run every refused line underwarnandrefuse. - words are bare
-
A line that names a reviewed CLI but doesn't fit is refused, and the refusal says why and lists the subcommands. Nothing else falls through to the general parser.
-
Programs kavach judges itself are never reviewed. That means git, rm, pnpm, shells, interpreters and wrappers (
judged_here).
Evidence
-
Local
pnpm check. Every package's check passes:- kavach: 637 Python tests OK, 753 node tests pass, coverage 99.91% lines and 97.70% branches;
pnpm lintandpnpm guardspass.
Four
scripts/version-rule.test.mjstests fail on this machine only. The shell setstag.gpgSign=truethroughGIT_CONFIG_*, so the test's lightweightgit tagasks for a message ("fatal: no tag message?"). CI runs the full check. -
New Python tests:
test_config.py(test_reviewed_clis),test_worktree_guard.py(ReviewedCLITest,ReviewedCLIWordsTest) andtest_push_in_progress.py(test_a_reviewed_cli_waits_too). -
Operand paths. With
pathOperands, a word that starts with-is confined too, soniyam brief -x/../../../../r.mdis refused. -
Corpus: 21 new
rv-*rows, run in real bash against aniyamstand-in (fixture.tsNIYAM_STANDIN). The stand-in writes under its toplevel and touches each declared path.- Allowed (near-miss, nothing written outside):
handoff --record … --reason "text with spaces"review-thread PRRT_x --reply "text"review-thread PRRT_x --body-file .tmp/r.mdbrief .tmp/d.mdkeep-going --stop "why"pr-signals 12
- Refused (attack, the outside write really happens in bash):
- a redirect;
- a chain that
cds to the main checkout; $(…)and backticks in--reply;--body-fileandbriefoutside the worktree;- the unlisted
pr-autocreate watch --root <main>; - a
GIT_DIR=/GIT_WORK_TREE=prefix; - all six allowed lines from the main checkout.
corpus.test.tsandfixture.test.ts: 76/76 pass.
- Allowed (near-miss, nothing written outside):
The niyam audit (v0.6.17, tag v0.6.17, 4665020)
I traced each command by call path, not by import graph. niyam writes only through Sys (write, append, mkdir, remove, replace, claim, detach, tempDir).
| Command | Local writes | Notes |
|---|---|---|
handoff --record / --assert-fresh | <toplevel>/.tmp/push/handoff-log.jsonl (handoff.ts:398-399) | The toplevel comes from git rev-parse --show-toplevel. --base reaches git only after rev-parse --symbolic-full-name shows a refs/remotes/ ref. --open-brief is read only, and draftAt refuses a draft outside the repository; the brief goes to GitHub. |
brief [--lint] <draft> | none | Reads the draft (draftAt), opens a GitHub issue. |
review-thread | none | --body-file is read from any path (resolvePath(sys.cwd, …), review-thread.ts:223) and posted to GitHub, so kavach must confine it, and does. |
pr-signals | none | Reads signals.findings, whose settings refuse / and ... Runs git log -p. |
keep-going --stop | <toplevel>/.tmp/keep-going/stop-note.json (keep-going.ts:269-270) | Runs git reads, ps and lsof. The bare Stop-hook form (<session>.json) is not listed. |
cubic-dismiss | the ledger <toplevel>/<settings.file>, then git add and git commit --only of it | --from must be inside the repository. |
Shared modules on these paths write nothing locally: agent.ts, work.ts sessionToken, as-agent.ts agentEnv, pages.ts and host.ts. The keychain and $HOME are read only. The writers that are reached only by unlisted commands (lockout, machine, onboard, owner-login, pr-autocreate, session-start) stay out of the entry.
Can cubic-dismiss's ledger leave the repository? The regex (cubic-dismiss.ts:58) bars an absolute path and any . or .. segment, so the path stays inside the toplevel as written. A symlink can still take it out. I tried a committed symlink at .cubic-dismiss, a ledger under a committed symlinked directory, and one under an untracked symlinked directory. In all three, the git status --porcelain -- <file> pre-check (line 231) exits 0 with no output. Node's writeFileSync then follows the link, so the write lands outside. The undo() after the failed git add/commit restores the old text, so the outside write is transient unless the process dies in between.
The same holds for .tmp/push and .tmp/keep-going. I ran this guard on ln -s <outside> .tmp/push, mkdir -p .tmp && ln -s <outside> .tmp/push and ln -s <outside> link from an owned worktree, and it allowed all three (exit 0): ln's destination is inside the worktree. This is the known limit of every reviewed runner (pnpm test runs code kavach can't see). The README says so. The fix belongs in niyam: compare the realpath of the write target with the realpath of the toplevel before writing.
Scope notes
onboard … --dry-run(veda#54) is not in the sample entry. A prefix keyonboardwould also admitonboard --yes, which writes workflows, hooks and settings, and pushes. It stays inreadOnlyCommands, where veda's own.claude/kavach.jsonalready has it.--versionandproposefit as prefixes.- No version bump here. The release PR (kavach and sarathi) follows the merge.
🤖 Generated with Claude Code
Summary by cubic
Adds worktree.reviewedCLIs to kavach: consumers can now list a CLI whose writes they reviewed, and its subcommands run from the owned worktree's root with free-text arguments. Before, commands with free-text arguments had no allowed form, since readOnlyCommands only matches exact patterns. The sample niyam entry covers the lines W-56 needs (decision on #67).
How the setting works
- An entry names a
program, the leading words of eachsubcommand,pathOptions/pathOperandsfor the options and operands that are paths, and areason. Declared paths are resolved, symlinks followed, and confined to the worktree like any other destination. - The line must be one command of literal words run from the worktree root: bare
[A-Za-z0-9._/=:,@+%-]or single/double-quoted text with no$, backtick, or backslash. Redirections, pipes, chains, globs,~,$(...), backticks, and env prefixes are refused in bothshellExpansionmodes, and the refusal names the listed subcommands. - Runs wait while a push is in progress, like trusted commands.
- Programs kavach judges itself (
git,rm,pnpm, shells, interpreters, wrappers) can never be listed.