šŸ› fix(kavach): from another repository, the cd back passes, 0.7.15

Merged
AT
8d ago
+228-52

Slice: #349
Fixes #339

Under work item #43.

kavach's cd-out-of-worktree rule took the shell's current checkout as the session's. From a folder in another repository, it flagged the cd back to the session's worktree. Once a consumer sets the rule to refuse, that strands the session where the worktree guard refuses every write.

What changes:

  • The rule passes a cd when both of these hold:
    • the shell's checkout is one the worktree guard takes as no session's own (another repository, or a main checkout);
    • the target's checkout is one it takes as a session's own (a worktree under .claude/worktrees, or the worktree.ownCheckout clone).
  • Both guards share that test. owns_plain_checkout moves from worktree_guard.py to boundary.py, next to a new ownable_checkout. judge() gives the detectors the settings (Call.settings), so the rule can read worktree.ownCheckout.
  • Once the way back passes, a later cd in the same command is judged from the checkout it entered, as the session's. For example, cd <session> && cd <other> fires with the session's worktree named. This goes beyond the slice's table, and came from Cubic's review.
  • The rule asks about ownership only for a cd that leaves the checkout. A cd inside it costs no git starts, and an error in the lookup cannot refuse it.
  • From a checkout the guard takes as no session's own, the message calls no checkout "this session's". It no longer says to cd into the shell's checkout; it says that a cd into the session's own worktree brings the shell back.
  • kavach and sarathi move to 0.7.15, including sarathi's VERSION in cli.ts. pariksha stays at 0.7.14.

Deliberate, from the slice's table:

  • One warning is lost. A session started in a main checkout, with no worktree, can now cd into any managed worktree of that repository without the "another session may own" warning. From there, the rule cannot tell the session's worktree from another session's.
  • The plain-clone wording changed. The message now reads "takes as no session's own" from every checkout that is neither managed nor the ownCheckout clone. That includes the default-config case an exact-stderr test used to pin. That guard-level test now runs with an ownCheckout config, so it still checks the owned wording. The unit tests cover the wording without one.
  • Not here: a shell stuck in another session's managed worktree (#349, "Not here").

Tests:

  • pnpm check passes, including kavach's Python suite.
  • New unit tests in test_rules.py:
    • from another repository, or from a main checkout, the cd into a managed worktree passes, and so does the cd into the ownCheckout clone;
    • from another repository, a cd elsewhere names no checkout as the session's;
    • from a managed worktree, and from the ownCheckout clone, a cd into another repository's managed worktree still fires;
    • a cd inside the checkout never asks about ownership;
    • from a peer worktree, the cd back to the ownCheckout clone passes, while without that config it still names the peer.
  • A new subprocess test runs command_guard.py with the rule set to refuse and the cwd in another repository:
    • cd <managed worktree> exits 0;
    • cd <third repository> exits 2 with the neutral message.

Not checked yet: one event through veda's real sarathi.sh. The hook loads sarathi and kavach from the registry at the root pin, which is 0.7.14, so this code can reach it only after v0.7.15 and the pin bump. I'll run it on the pin-bump PR, with the worktree's .claude/kavach.json setting the rule to refuse (sarathi.sh passes it as KAVACH_CONFIG). Until then, the subprocess test through command_guard.py stands in for it.

Ships: v0.7.15. After that come a pin bump of @veda-hq/sarathi, then Alok's pull and pnpm install in the main checkout, both at once.

šŸ¤– Generated with Claude Code