28 lines
1.4 KiB
Python
28 lines
1.4 KiB
Python
import pathlib
|
|
|
|
from loop_claude.project.text_file import read_utf8
|
|
from loop_claude.stop import Stop
|
|
|
|
# The records the judge reads beside the README's premises: these project files, then the human's rules below.
|
|
RECORD_FILES = ("AGENTS.md", "docs/decisions.md")
|
|
# The human's rules for every project, under ~/.claude: CLAUDE.md, then each .md file in these folders, which a repo check keeps present.
|
|
HUMAN_RULES_FILE = "CLAUDE.md"
|
|
HUMAN_RULE_DIRS = ("rules", "skills/larv-review/standards")
|
|
HUMAN_RULE_NAMES = (f"~/.claude/{HUMAN_RULES_FILE}", *(f"~/.claude/{folder}/" for folder in HUMAN_RULE_DIRS))
|
|
|
|
|
|
def read_records(root: str, claude_dir: 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_dir / HUMAN_RULES_FILE] + [rule for folder in HUMAN_RULE_DIRS for rule in sorted((claude_dir / folder).glob("*.md"))]
|
|
sources = [(root, name, name) for name in RECORD_FILES]
|
|
sources += [(str(rule.parent), rule.name, f"~/.claude/{rule.relative_to(claude_dir)}") for rule in rules]
|
|
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)
|