Write the review folder under the state folder into the generated settings.json
CI / tests (pull_request) Failing after 4m58s

This commit is contained in:
2026-12-04 04:06:38 +01:00
parent 138a091f73
commit 9d2f5b9253
6 changed files with 56 additions and 19 deletions
+16 -12
View File
@@ -17,6 +17,8 @@ from text_files.file_writes import replace_file
LINKED = ("CLAUDE.md", "agents", "rules", "skills")
# Stands for the clone's folder in the clone's settings.json. Every value that holds it is a shell command, such as a hook's.
CLONE = "{clone}"
# Stands for the review folder, the one under the state folder where each reviewer writes its report, which a session may write.
REVIEWS = "{reviews}"
# The file in the home that names the clone and the commit the home was built from.
BUILT_FROM = "built-from"
@@ -28,10 +30,10 @@ class Git(typing.Protocol):
def __call__(self, *args: str, cwd: str | None = None) -> str | Failure: ...
def unready(home: pathlib.Path, clone: pathlib.Path, claude: Claude, git: Git) -> str | None:
def unready(home: pathlib.Path, clone: pathlib.Path, reviews: pathlib.Path, claude: Claude, git: Git) -> str | None:
"""Builds the home from clone, or refreshes it where the clone's commit changed since. Then 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, claude, git)
built = refreshed(home, clone, reviews, claude, git)
if isinstance(built, Failure):
return f"could not build the loop's Claude home, {home}: {built.reason}"
status = claude(["auth", "status"])
@@ -61,11 +63,11 @@ def printed(done: subprocess.CompletedProcess[str]) -> str:
return " ".join((done.stderr or done.stdout).split()) or f"it printed nothing and exited {done.returncode}"
def refreshed(home: pathlib.Path, clone: pathlib.Path, claude: Claude, git: Git) -> Failure | None:
def refreshed(home: pathlib.Path, clone: pathlib.Path, reviews: pathlib.Path, claude: Claude, git: Git) -> Failure | None:
commit = git("rev-parse", "HEAD", cwd=str(clone))
if isinstance(commit, Failure):
return commit
built_from = f"{clone} at {commit.strip()}\n"
built_from = f"{clone} at {commit.strip()}, reviews in {reviews}\n"
home.mkdir(parents=True, exist_ok=True)
# Several loops start at once after an update: one refreshes the home, and the others wait and find it done.
with open(home / ".refresh-lock", "w", encoding="utf-8") as lock:
@@ -74,7 +76,7 @@ def refreshed(home: pathlib.Path, clone: pathlib.Path, claude: Claude, git: Git)
if stamp.is_file() and stamp.read_text(encoding="utf-8") == built_from:
return None
# The stamp is written last, so a refresh that failed halfway runs again.
return linked(home, clone) or settings_written(home, clone) or plugins_installed(clone, claude) or replace_file(stamp, built_from.encode())
return linked(home, clone) or settings_written(home, clone, reviews) or plugins_installed(clone, claude) or replace_file(stamp, built_from.encode())
def linked(home: pathlib.Path, clone: pathlib.Path) -> Failure | None:
@@ -87,9 +89,9 @@ def linked(home: pathlib.Path, clone: pathlib.Path) -> Failure | None:
return None
def settings_written(home: pathlib.Path, clone: pathlib.Path) -> Failure | None:
"""Writes the home's settings.json: the clone's, with the clone's folder in place of CLONE, and the model the home's file holds."""
settings = placed(json.loads((clone / "settings.json").read_text(encoding="utf-8")), shlex.quote(str(clone)))
def settings_written(home: pathlib.Path, clone: pathlib.Path, reviews: pathlib.Path) -> Failure | None:
"""Writes the home's settings.json: the clone's, with the clone's folder in place of CLONE and the review folder in place of REVIEWS, and the model the home's file holds."""
settings = placed(json.loads((clone / "settings.json").read_text(encoding="utf-8")), {CLONE: shlex.quote(str(clone)), REVIEWS: str(reviews)})
generated = home / "settings.json"
try:
old = json.loads(generated.read_text(encoding="utf-8")) if generated.is_file() else {}
@@ -103,13 +105,15 @@ def settings_written(home: pathlib.Path, clone: pathlib.Path) -> Failure | None:
return replace_file(generated, (json.dumps(settings, indent=2, sort_keys=True) + "\n").encode())
def placed(value: typing.Any, clone: str) -> typing.Any:
def placed(value: typing.Any, stand_for: dict[str, str]) -> typing.Any:
if isinstance(value, str):
return value.replace(CLONE, clone)
for name, replacement in stand_for.items():
value = value.replace(name, replacement)
return value
if isinstance(value, list):
return [placed(each, clone) for each in value]
return [placed(each, stand_for) for each in value]
if isinstance(value, dict):
return {key: placed(each, clone) for key, each in value.items()}
return {key: placed(each, stand_for) for key, each in value.items()}
return value