Answer the architect: fail a judge that answers without interrupting, read every checkout file through one function

This commit is contained in:
2026-10-03 00:39:20 +02:00
parent 6340e5a993
commit 160b1dae5f
6 changed files with 32 additions and 26 deletions
+10
View File
@@ -27,3 +27,13 @@ def worktrees(root: str, effects: Effects) -> list[str]:
def project_key(root: str, code: pathlib.Path) -> str:
return root.removeprefix(f"{code}/").lstrip("/")
def read_checkout_file(root: str, name: str, consequence: str) -> str | Stop:
try:
return pathlib.Path(root, name).read_text(encoding="utf-8")
except OSError as failure:
return Stop(1, f"{name} in {root}: {failure.strerror} - {consequence}.")
except UnicodeDecodeError as failure:
line = failure.object.count(b"\n", 0, failure.start) + 1
return Stop(1, f"{name} is not UTF-8 on line {line} - {consequence}.")
+5 -8
View File
@@ -1,19 +1,16 @@
import pathlib
import re
from loop_claude.project.checkout import read_checkout_file
from loop_claude.stop import Stop
FENCE = re.compile(r"^ {0,3}(`{3,}|~{3,})", re.M)
def read_premises(root: str) -> str | Stop:
try:
found = sections(pathlib.Path(root, "README.md").read_text(encoding="utf-8"))
except OSError as failure:
return Stop(1, f"README.md in {root}: {failure.strerror} - no premises.")
except UnicodeDecodeError as failure:
line = failure.object.count(b"\n", 0, failure.start) + 1
return Stop(1, f"README.md is not UTF-8 on line {line} - no premises.")
text = read_checkout_file(root, "README.md", "no premises")
if isinstance(text, Stop):
return text
found = sections(text)
for name in ("Goals", "Audience"):
bodies = found.get(name, [])
if not bodies:
+5 -8
View File
@@ -1,5 +1,6 @@
import pathlib
from loop_claude.project.checkout import read_checkout_file
from loop_claude.stop import Stop
@@ -7,14 +8,10 @@ def read_records(root: str) -> str | Stop:
"""AGENTS.md and docs/decisions.md, each headed by its path; a file the project lacks is left out."""
records = []
for name in ("AGENTS.md", "docs/decisions.md"):
try:
text = pathlib.Path(root, name).read_text(encoding="utf-8")
except FileNotFoundError:
if not pathlib.Path(root, name).exists():
continue
except OSError as failure:
return Stop(1, f"{name} in {root}: {failure.strerror} - the judge cannot read the project's records.")
except UnicodeDecodeError as failure:
line = failure.object.count(b"\n", 0, failure.start) + 1
return Stop(1, f"{name} is not UTF-8 on line {line} - the judge cannot read the project's records.")
text = read_checkout_file(root, name, "the judge cannot read the project's records")
if isinstance(text, Stop):
return text
records.append(f"From {name}:\n{text.strip()}")
return "\n\n".join(records)