Verify passes in a checkout that holds other worktrees

Merged
DO
1mo ago
+187-17

Why. The Maintainer's sessions put git worktrees under .claude/worktrees/ in the main checkout, each a whole copy of the repo with a .git file. tools/check_context.py and tools/check_repo.py walked the whole tree, so make verify in that checkout read every nested copy's AGENTS.md, CLAUDE.md and tests as this repo's own. Verify passed only in a worktree or a fresh clone.

What.

  • tools/walk.py lists this working tree's files and top-level folders, and copies the tree. It skips any directory below the root that holds a .git entry, file or directory. At the root it skips the tree's own .git and the corpus/ that make_corpus.py writes; .gitignore now anchors that to /corpus/. __pycache__ is skipped at any depth. A skipped name drops a directory, never a file of that name. A link is listed and never followed. A link to nothing is reported by check_repo in a sentence. It needs no git, so it also works in an export that has no .git.
  • check_context, check_repo and check_purity walk through it. check_purity walks kernel/ from the repo root, so kernel/corpus/ is checked like any other code. clone() in tests/test_tools.py and the copy in tools/mutants.py copy through it, links as links, so all of them skip the same things. Only the tree-copy code in mutants.py changed; the list of mutants did not.
  • tools/AGENTS.md gains the rule: the tree is walked or copied only by walk.py.

Safe for CI. Skipping a directory that holds .git cannot hide committed content from the required check. Git refuses to check out a path named .git, so no commit can plant one, and in CI every such directory is one a person made locally.

Tests, written first.

  • test_another_working_tree_inside_this_one_is_not_read plants nested worktrees full of faults in a clone, with .git files and a .git directory, and runs every check that reads the tree. Before the change it failed for purity, repo and context.
  • test_only_the_corpus_at_the_root_is_skipped_and_only_a_directory plants kernel/corpus/x.py with import time, sim/corpus/test_hidden.py, a credential-shaped token under sim/corpus/, and a corpus file, and asserts each is caught.
  • test_a_copy_of_the_repo_leaves_out_another_working_tree and test_a_link_is_not_followed_and_a_link_to_nothing_is_reported hold the walk and the copy to the same rules.
  • test_only_the_walk_walks_the_tree reads the syntax of every file under tools/, tests/ and sim/, and fails if anything but walk.py walks or copies a tree. test_a_walk_written_another_way_is_still_a_walk feeds it Path.walk(), os.fwalk, os.walk (, from os import walk, an aliased copytree, glob(..., recursive=True) and glob("x/**/*.py").

Verified. make verify and python3 -m tools.mutants pass (26 of 26 killed, after rebasing onto main). make verify also passes in a clone that holds a real git worktree under .claude/worktrees/.

Not here. A committed link in kernel/ that points at a directory outside it, such as kernel/ext -> ../docs/x, hides that code from check_purity. That was already true before this change, and it is its own story: "A link in kernel/ cannot hide code from the purity check".

Order. "Session hooks that check: the fast checks after an edit, verify before a stop, the Maintainer's identity" should merge after this. Without it, a session in the main checkout is sent back at every stop.

Closes #64

šŸ¤– Generated with Claude Code