diff --git a/bin/claude_home/home.py b/bin/claude_home/home.py index ed3ef26d..7d40388e 100644 --- a/bin/claude_home/home.py +++ b/bin/claude_home/home.py @@ -33,7 +33,7 @@ class Git(typing.Protocol): def unready(home: pathlib.Path, clone: pathlib.Path, reports: pathlib.Path, own: pathlib.Path, claude: Claude, git: Git) -> str | None: - """Builds the home from clone, or refreshes it where the clone's commit or the reports folder changed since. own is the person's own Claude home, whose instructions the home keeps out. Then why a claude cannot run in the home yet, said for the person to act on; None where one can.""" + """Builds the home from clone, or refreshes it where the clone's commit or the reports folder changed since; own is the person's own Claude home, whose instructions the home keeps out. Then says why a claude cannot run in the home yet, said for the person to act on; None where one can.""" try: built = refreshed(home, clone, reports, own, claude, git) if isinstance(built, Failure): @@ -71,6 +71,9 @@ def printed(done: subprocess.CompletedProcess[str]) -> str: def refreshed(home: pathlib.Path, clone: pathlib.Path, reports: pathlib.Path, own: pathlib.Path, claude: Claude, git: Git) -> Failure | None: + # The home links to the clone's rules/, and Claude Code applies the exclusion of own's files to a link's target too: a clone in own would run without its rules. + if clone.resolve().is_relative_to(own.resolve()): + return Failure(f"the release is cloned in your own Claude home, {own}, whose instructions the loop keeps out; clone it elsewhere, as README.md → Install says") commit = git("rev-parse", "HEAD", cwd=str(clone)) if isinstance(commit, Failure): return commit diff --git a/bin/claude_home/test_home.py b/bin/claude_home/test_home.py index d0a50d5a..78df21eb 100644 --- a/bin/claude_home/test_home.py +++ b/bin/claude_home/test_home.py @@ -77,6 +77,14 @@ class Home(unittest.TestCase): self.assertEqual(self.settings()["claudeMdExcludes"], [f"{self.own}/**"]) + def test_a_clone_in_the_persons_own_home_stops_since_the_exclusion_would_drop_the_setups_rules(self) -> None: + for own in (self.clone, self.clone.parent): + with self.subTest(own=own): + self.own = own + + self.assertEqual(self.unready(), f"could not build the loop's Claude home, {self.home}: the release is cloned in your own Claude home, {own}, whose instructions the loop keeps out; clone it elsewhere, as README.md → Install says") + self.assertFalse((self.home / "settings.json").exists()) + def test_a_moved_reports_folder_refreshes_the_home(self) -> None: self.unready() self.reports = self.temp / "elsewhere" / "build-release" / "larv-review" diff --git a/bin/loop_state/paths.py b/bin/loop_state/paths.py index d6be608e..6be910ba 100644 --- a/bin/loop_state/paths.py +++ b/bin/loop_state/paths.py @@ -10,7 +10,7 @@ RELEASE_ROOT = pathlib.Path(__file__).resolve().parents[2] # Each folder below is named relative to the person's home folder. -# The person's own Claude home. No claude the loop starts runs there, and neither entry point reads or writes it: its name is for prose and for rule-hook's rules that guard it. +# The person's own Claude home. No claude the loop starts runs there, and neither entry point reads or writes it: its name is for prose, for rule-hook's rules that guard it, and for the instructions the loop's home keeps out. CLAUDE_HOME = ".claude" # The name of the setup's own folder, in the config home and in the state home. SETUP = "build-release" diff --git a/first-chunk-e2e/first_chunk.py b/first-chunk-e2e/first_chunk.py index 74ffce0c..7b853e44 100644 --- a/first-chunk-e2e/first_chunk.py +++ b/first-chunk-e2e/first_chunk.py @@ -1,6 +1,6 @@ """Runs a first chunk as a newcomer would, and checks that the person's own Claude home is left as it was. -It runs in the container of the Dockerfile beside it, from a clone of this repo: `first-chunk-e2e/run` starts it. The machine holds a stock Claude Code with its own `~/.claude`, to which this adds a `CLAUDE.md`. build-release then runs a task in a small project, with claude calling the mock Messages API. The run passes where the chunk finished on the setup's instructions, no request held the person's own, and `~/.claude` and `~/.claude.json` hold what they held before. +It runs in the container of the Dockerfile beside it, from a clone of this repo: `first-chunk-e2e/run` starts it. The machine holds a stock Claude Code with its own `~/.claude`, to which this adds what a person keeps there: instructions, a rule, a skill, an agent, a command and a hook. build-release then runs a task in a small project, with claude calling the mock Messages API. The run passes where the chunk finished on the setup's instructions, no request held the person's own, and `~/.claude` and `~/.claude.json` hold what they held before. """ import hashlib import json @@ -14,26 +14,33 @@ import mock_messages_api CLONE = pathlib.Path(__file__).resolve().parent.parent HOME = pathlib.Path.home() -# The project's key is its path under ~/code: README.md → Install → "Set up a project". +# Under ~/code, so the project's key is `first-project`: bin/transcript_archive/project_key.py. PROJECT = HOME / "code" / "first-project" ARCHIVE = HOME / ".local/state/build-release/transcripts/first-project" CONFIG = HOME / ".config/build-release/first-project/config.toml" -# What the person's own `~/.claude` holds beside the stock install's files. Nothing in it loads in the loop's home, so no request may hold either instruction, and the hook never runs. +# What the person's own `~/.claude` holds beside the stock install's files. None of it loads in the loop's home, so no request may hold any of OWN_TEXTS, and the hook never runs. OWN_INSTRUCTION = "Sign every reply as the newcomer's own claude." OWN_RULE = "Open every reply with the newcomer's own greeting." +OWN_SKILL = "Folds the newcomer's own paper cranes." +OWN_AGENT = "Waters the newcomer's own ferns." +OWN_COMMAND = "Winds the newcomer's own clock." +OWN_TEXTS = (OWN_INSTRUCTION, OWN_RULE, OWN_SKILL, OWN_AGENT, OWN_COMMAND) OWN_HOOK_RAN = HOME / "own-hook-ran" OWN_FILES = { "CLAUDE.md": OWN_INSTRUCTION + "\n", - # In two parts, since bin/repo_checks/test_citations.py reads a rule file's path written whole as one of the setup's. + # In two parts: bin/repo_checks/test_citations.py takes a rule file's path written whole for a citation of the setup's rules, and fails where the setup has no such file. os.path.join("rules", "greeting.md"): OWN_RULE + "\n", + "skills/cranes/SKILL.md": f"---\nname: cranes\ndescription: {OWN_SKILL}\n---\n\nFold one.\n", + "agents/ferns.md": f"---\nname: ferns\ndescription: {OWN_AGENT}\n---\n\nWater one.\n", + "commands/clock.md": f"---\ndescription: {OWN_COMMAND}\n---\n\nWind it.\n", "settings.json": json.dumps({"hooks": {"SessionStart": [{"hooks": [{"type": "command", "command": f"touch {OWN_HOOK_RAN}"}]}]}}) + "\n", } # A heading of the setup's CLAUDE.md, which the worker's request holds where the loop's home loaded. SETUP_INSTRUCTION = "## Working loop" -# What build-release asks a project's first chunk, and the model the newcomer types: one on the shipped routing ladder. +# What build-release asks before a project's first chunk, and the model the newcomer types: one on the shipped routing ladder. MODEL_QUESTION = "name claude --model takes:" MODEL = "claude-opus-5-5" -# How long the chunk may take. One on the mock takes under a minute. +# How many seconds build-release may take to start the chunk, and the chunk to finish. PATIENCE = 300 README = """# first-project @@ -102,7 +109,7 @@ def chunk_finished() -> bool: def windows() -> str: - """What each tmux window of the loop shows, for a run that failed.""" + """What each tmux window of the loop shows.""" listed = subprocess.run(["tmux", "list-panes", "-a", "-F", "#{pane_id}"], capture_output=True, text=True).stdout.split() return "\n".join(subprocess.run(["tmux", "capture-pane", "-p", "-J", "-S", "-200", "-t", pane], capture_output=True, text=True).stdout.strip() for pane in listed) @@ -125,9 +132,9 @@ def failures(requests: mock_messages_api.Requests, before: dict[str, str]) -> li found.append(f"no chunk finished within {PATIENCE} s; the loop's tmux windows show:\n{windows()}") if not any(SETUP_INSTRUCTION in text for text in texts): found.append(f"none of claude's {len(texts)} requests held the setup's CLAUDE.md, so the loop's home did not load") - for instruction in (OWN_INSTRUCTION, OWN_RULE): - if any(instruction in text for text in texts): - found.append(f"a request held the person's own instruction `{instruction}`, so `~/.claude` loaded in the loop") + for own in OWN_TEXTS: + if any(own in text for text in texts): + found.append(f"a request held the person's own `{own}`, so `~/.claude` loaded in the loop") if OWN_HOOK_RAN.exists(): found.append("the hook of the person's own `~/.claude/settings.json` ran in the loop") after = snapshot(HOME / ".claude", HOME / ".claude.json") @@ -139,15 +146,15 @@ def failures(requests: mock_messages_api.Requests, before: dict[str, str]) -> li def main() -> int: for name, text in OWN_FILES.items(): - (HOME / ".claude" / name).parent.mkdir(exist_ok=True) + (HOME / ".claude" / name).parent.mkdir(parents=True, exist_ok=True) (HOME / ".claude" / name).write_text(text, encoding="utf-8") before = snapshot(HOME / ".claude", HOME / ".claude.json") project_made() requests = mock_messages_api.Requests() server = mock_messages_api.serve(requests) - # A made-up token, which grants access to nothing. It signs claude in, as docs/decisions.md → `Claude Code in a home of its own` found, and the mock doesn't check it. + # A made-up token, which doesn't grant access to anything. It signs claude in, as docs/decisions.md → `Claude Code in a home of its own` found, and the mock doesn't check it. env = {**os.environ, "ANTHROPIC_BASE_URL": f"http://127.0.0.1:{server.server_port}", "CLAUDE_CODE_OAUTH_TOKEN": "mock-token"} - started = subprocess.run([str(CLONE / "bin" / "build-release"), "Write a note of what the project is for."], cwd=PROJECT, env=env, stdin=subprocess.DEVNULL) + started = subprocess.run([str(CLONE / "bin" / "build-release"), "Write a note of what the project is for."], cwd=PROJECT, env=env, stdin=subprocess.DEVNULL, timeout=PATIENCE) if started.returncode: found = [f"build-release exited {started.returncode}"] else: