import pathlib from loop_claude.stop import Stop 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: 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.") records.append(f"From {name}:\n{text.strip()}") return "\n\n".join(records)