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

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: these project files and the human's rules; the judge reads them beside the README's premises.
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.
HUMAN_RULES = "CLAUDE.md"
HUMAN_RULE_DIRS = ("rules", "skills/larv-review/standards")
HUMAN_RULE_NAMES = tuple(f"~/.claude/{name}" for name in (HUMAN_RULES, *(f"{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] + [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)