š fix: writers refuse a symlink that leads out of the git toplevel
Slice: #360
Closes #360.
niyam's writers no longer follow a symlink out of the git toplevel. kavach 0.6.9 (veda-hq/veda#95) lets these commands run from an owned worktree on the claim that niyam writes only under the toplevel, and a link broke that claim.
Sys.confine(root, path)is the one helper. It finds the nearest part ofpaththat is there, bylstat, so a link that leads nowhere counts. It follows that part's links and throws unless the real path is the toplevel's real path or lies under it, compared by whole segments. The error names the path, where it leads and the toplevel.cubic-dismisschecks its ledger before reading or writing it, and refuses with exit 1.handoff --record/--assert-freshcheck the run log before judging a push or opening a--open-briefissue, and again at the append.keep-going --stopsays no stop note was written. The Stop hook checks its counter and the stop note before either is read. It still fails open, but says why.
Tests use real symlinks: a linked file, a linked folder (committed and untracked), a linked .tmp/push, a linked .tmp and a dangling link. Each one refuses, and the outside folder stays empty or unchanged. With confine made a no-op, the cubic-dismiss, handoff and keep-going tests fail, and handoff and keep-going write outside.
docs/decisions.md records this as P-67. Left for its own slice: pr-autocreate has the same gap under .tmp/pr-autocreate, but kavach 0.6.9 does not let it run from a worktree.
Guards: none. Only src/ and docs/decisions.md change.
Checked: pnpm check passes.
š¤ Generated with Claude Code
Summary by cubic
Writers that could follow a symlink out of the git toplevel now refuse, closing the gap kavach 0.6.9 opened by allowing these commands to run from an owned worktree.
- Adds
Sys.confine(root, path): it finds the nearest existing part ofpathbylstat, follows its links, and throws unless the real path stays underroot; a dangling link refuses too, and the error names the path, its target, and the toplevel. cubic-dismisschecks its ledger,handoff --record/--assert-freshcheck the run log, andkeep-going --stopchecks the stop note and counter ā before any read or write.keep-going --stopexits 1 with "No stop note written" on refusal;pr-autocreatehas the same gap but is left for its own slice.