26 lines
1.1 KiB
Python
26 lines
1.1 KiB
Python
import pathlib
|
|
|
|
from loop_claude.project.text_file import read_utf8
|
|
from loop_claude.stop import Stop
|
|
|
|
# The records: these project files and the human's rules; the judge reads them beside the README's premises.
|
|
RECORD_FILES = ("AGENTS.md", "docs/decisions.md")
|
|
HUMAN_RULES = "~/.claude/CLAUDE.md"
|
|
HUMAN_RULES_DIR = "~/.claude/rules/"
|
|
|
|
|
|
def read_records(root: str, claude_md: pathlib.Path) -> str | Stop:
|
|
"""The project's record files, then the human's rules for every project, CLAUDE.md first, each headed by its name; a file that does not exist is left out."""
|
|
rules = claude_md.parent / "rules"
|
|
sources = [(root, name, name) for name in RECORD_FILES] + [(str(claude_md.parent), claude_md.name, HUMAN_RULES)]
|
|
sources += [(str(rules), rule.name, HUMAN_RULES_DIR + rule.name) for rule in sorted(rules.glob("*.md"))]
|
|
records = []
|
|
for folder, name, heading in sources:
|
|
if not pathlib.Path(folder, name).exists():
|
|
continue
|
|
text = read_utf8(folder, name, "the judge cannot read the records")
|
|
if isinstance(text, Stop):
|
|
return text
|
|
records.append(f"From {heading}:\n{text.strip()}")
|
|
return "\n\n".join(records)
|