|
|
@@ -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.
|
|
|
|
"""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 hashlib
|
|
|
|
import json
|
|
|
|
import json
|
|
|
@@ -14,26 +14,33 @@ import mock_messages_api
|
|
|
|
|
|
|
|
|
|
|
|
CLONE = pathlib.Path(__file__).resolve().parent.parent
|
|
|
|
CLONE = pathlib.Path(__file__).resolve().parent.parent
|
|
|
|
HOME = pathlib.Path.home()
|
|
|
|
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"
|
|
|
|
PROJECT = HOME / "code" / "first-project"
|
|
|
|
ARCHIVE = HOME / ".local/state/build-release/transcripts/first-project"
|
|
|
|
ARCHIVE = HOME / ".local/state/build-release/transcripts/first-project"
|
|
|
|
CONFIG = HOME / ".config/build-release/first-project/config.toml"
|
|
|
|
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_INSTRUCTION = "Sign every reply as the newcomer's own claude."
|
|
|
|
OWN_RULE = "Open every reply with the newcomer's own greeting."
|
|
|
|
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_HOOK_RAN = HOME / "own-hook-ran"
|
|
|
|
OWN_FILES = {
|
|
|
|
OWN_FILES = {
|
|
|
|
"CLAUDE.md": OWN_INSTRUCTION + "\n",
|
|
|
|
"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",
|
|
|
|
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",
|
|
|
|
"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.
|
|
|
|
# A heading of the setup's CLAUDE.md, which the worker's request holds where the loop's home loaded.
|
|
|
|
SETUP_INSTRUCTION = "## Working loop"
|
|
|
|
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_QUESTION = "name claude --model takes:"
|
|
|
|
MODEL = "claude-opus-5-5"
|
|
|
|
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
|
|
|
|
PATIENCE = 300
|
|
|
|
README = """# first-project
|
|
|
|
README = """# first-project
|
|
|
|
|
|
|
|
|
|
|
@@ -102,7 +109,7 @@ def chunk_finished() -> bool:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def windows() -> str:
|
|
|
|
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()
|
|
|
|
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)
|
|
|
|
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()}")
|
|
|
|
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):
|
|
|
|
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")
|
|
|
|
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):
|
|
|
|
for own in OWN_TEXTS:
|
|
|
|
if any(instruction in text for text in texts):
|
|
|
|
if any(own in text for text in texts):
|
|
|
|
found.append(f"a request held the person's own instruction `{instruction}`, so `~/.claude` loaded in the loop")
|
|
|
|
found.append(f"a request held the person's own `{own}`, so `~/.claude` loaded in the loop")
|
|
|
|
if OWN_HOOK_RAN.exists():
|
|
|
|
if OWN_HOOK_RAN.exists():
|
|
|
|
found.append("the hook of the person's own `~/.claude/settings.json` ran in the loop")
|
|
|
|
found.append("the hook of the person's own `~/.claude/settings.json` ran in the loop")
|
|
|
|
after = snapshot(HOME / ".claude", HOME / ".claude.json")
|
|
|
|
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:
|
|
|
|
def main() -> int:
|
|
|
|
for name, text in OWN_FILES.items():
|
|
|
|
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")
|
|
|
|
(HOME / ".claude" / name).write_text(text, encoding="utf-8")
|
|
|
|
before = snapshot(HOME / ".claude", HOME / ".claude.json")
|
|
|
|
before = snapshot(HOME / ".claude", HOME / ".claude.json")
|
|
|
|
project_made()
|
|
|
|
project_made()
|
|
|
|
requests = mock_messages_api.Requests()
|
|
|
|
requests = mock_messages_api.Requests()
|
|
|
|
server = mock_messages_api.serve(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"}
|
|
|
|
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:
|
|
|
|
if started.returncode:
|
|
|
|
found = [f"build-release exited {started.returncode}"]
|
|
|
|
found = [f"build-release exited {started.returncode}"]
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|