Give the own home a rule and a hook
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
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.
|
||||
"""
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
import subprocess
|
||||
@@ -17,8 +18,15 @@ HOME = pathlib.Path.home()
|
||||
PROJECT = HOME / "code" / "first-project"
|
||||
ARCHIVE = HOME / ".local/state/build-release/transcripts/first-project"
|
||||
CONFIG = HOME / ".config/build-release/first-project/config.toml"
|
||||
# The line the person's own CLAUDE.md holds. No request may hold it: nothing in `~/.claude` loads in the loop's home.
|
||||
# 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.
|
||||
OWN_INSTRUCTION = "Sign every reply as the newcomer's own claude."
|
||||
OWN_RULE = "Open every reply with the newcomer's own greeting."
|
||||
OWN_HOOK_RAN = HOME / "own-hook-ran"
|
||||
OWN_FILES = {
|
||||
"CLAUDE.md": OWN_INSTRUCTION + "\n",
|
||||
"rules/greeting.md": OWN_RULE + "\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.
|
||||
@@ -113,12 +121,11 @@ 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 n, text in enumerate(texts):
|
||||
if OWN_INSTRUCTION in text:
|
||||
i = text.index(OWN_INSTRUCTION)
|
||||
print("DEBUG", n, len(texts), text[max(0, i - 700):i + 100], "\nSTART", text[:600], file=sys.stderr)
|
||||
if any(OWN_INSTRUCTION in text for text in texts):
|
||||
found.append("a request held the person's own CLAUDE.md, so `~/.claude` loaded in the loop")
|
||||
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")
|
||||
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")
|
||||
for path in sorted(before.keys() | after.keys()):
|
||||
if before.get(path) != after.get(path):
|
||||
@@ -127,7 +134,9 @@ def failures(requests: mock_messages_api.Requests, before: dict[str, str]) -> li
|
||||
|
||||
|
||||
def main() -> int:
|
||||
(HOME / ".claude" / "CLAUDE.md").write_text(OWN_INSTRUCTION + "\n", encoding="utf-8")
|
||||
for name, text in OWN_FILES.items():
|
||||
(HOME / ".claude" / name).parent.mkdir(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()
|
||||
|
||||
Reference in New Issue
Block a user