Files
claude-config/bin/loop_claude/project/records.py
T

24 lines
918 B
Python

import pathlib
from loop_claude.stop import Stop
def read_records(root: str) -> str | Stop:
"""AGENTS.md and the decision log, each headed by its path; a file the project lacks is left out."""
project = pathlib.Path(root)
paths = [project / "AGENTS.md", project / "docs" / "decisions.md", *sorted(project.glob("docs/decisions/*.md"))]
records = []
for path in paths:
name = path.relative_to(project)
try:
text = path.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)