š fix(kavach): the cd back to the session's recorded worktree passes, 0.7.18
Under work item #43.
From another session's managed worktree, kavach's cd-out-of-worktree took that worktree as the session's, since it is ownable. It flagged the cd back to the session's own worktree and named the wrong one. Once a consumer sets the rule to refuse, that strands the session.
What changes:
-
boundary.pygets the desktop app's session-record reader, moved fromworktree_guard.py, which keeps using it under the same names:session_record,claude_app_root,SESSION_ID,HOST_SESSIONandRECORD_LIMIT. -
A new
boundary.session_worktree(session_id, own, environ)returns the record'sworktreePath, else itscwd, only when all of these hold:- the hook's
CLAUDE_CODE_HOST_SESSION_IDnames the record; - the record's
cliSessionIdis the payload'ssession_id; - the path is absolute, a real directory, and the root of a checkout a session can own (
ownable_checkout).
It never raises. Anything else is
None. - the hook's
-
rules.py:Callcarries the payload'ssession_id.cd_out_of_worktreereads the record at most once per call, and only for acdthat leaves the shell's checkout and that #350's pass did not already let through.- A
cdinto the recorded worktree passes, and a latercdin the same command is judged from it. - When the shell is elsewhere, a finding reads "(the shell is in X; Y is this session's)" and says
cd Ybrings it back.
-
With no record that fits, the rule judges exactly as in 0.7.15. Nothing fires that did not fire before.
-
One message changes with a matching record. From a checkout no session owns, a
cdthat still fires now reads "(the shell is in X; Y is this session's)". It replaces #350's "takes as no session's own" wording. The tests check this wording only from another session's worktree. -
kavach and sarathi move to 0.7.18.
v0.7.17released #365's sarathi while this was open, and main is merged in for that version clash. sarathi'sVERSIONincli.tschanges too. Slice #364 and its page say 0.7.17, written before that tag.
Why the record: the hook payload does not say which worktree is the session's. The app's record does. kavach already trusts it, under the same two checks, for the side-session notes folders a session was granted. I surveyed the records on this machine:
- Records for worktree sessions have
worktreePath. - The rest have
cwdset to the folder the session started in. cwddoes not follow the shell;shellFoldersdoes. In 36 of the 110 records withshellFolders, a shell folder lies outsidecwd, whilecwdstayed at the worktree the session started in.- No record's
worktreePathdiffers from itscwd.
Tests, a new RecordedWorktree class in test_rules.py with the app folder faked under a test HOME:
- From another session's worktree,
cd <recorded>,cd <recorded> && pwdandpushd <recorded>/subpass.judge()underrefuserefuses nothing. - The same
cdstill fires with no host variable, a malformed host id, nosession_id, or a wrongcliSessionId. - A recorded path that is no ownable root names nothing:
/, a worktree's subfolder, the main checkout, a relative path, or a missing folder. - A record with only
cwdcounts. - A
cdelsewhere names the recorded worktree, including the refusal for a folder in no repository. From the recorded worktree itself, the finding reads as before. - A later
cdis judged from the recorded worktree. - A
cdinside the checkout reads no record. - Through
command_guard.py, underrefuse, thecdback exits 0 withsession_idand 2 without it.
pnpm check passes.
Not checked yet: one event through veda's real sarathi.sh. The hook runs the root pin, 0.7.15, so that check waits for the pin bump after v0.7.18. On it, this session's session_id and a cwd in another veda worktree should let cd <this worktree> exit 0, and the same event without session_id should exit 2.
Not here: #363, where the worktree guard admits writes in any managed worktree. CLI sessions with no desktop app keep today's behaviour.
š¤ Generated with Claude Code