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

20 lines
732 B
Python

from loop_claude.project.checkout import read_checkout_file
from files.markdown import sections
from loop_claude.stop import Stop
def read_premises(root: str) -> str | Stop:
text = read_checkout_file(root, "README.md", "no premises")
if isinstance(text, Stop):
return text
found = sections(text)
for name in ("Goals", "Audience"):
bodies = found.get(name, [])
if not bodies:
return Stop(1, f"README.md has no ## {name} heading - no premises.")
if len(bodies) > 1:
return Stop(1, f"README.md has ## {name} more than once - no premises.")
if not bodies[0]:
return Stop(1, f"README.md has nothing under ## {name} - no premises.")
return f"## Goals\n{found['Goals'][0]}\n\n## Audience\n{found['Audience'][0]}"