from failure import Failure from loop_claude.project.text_file import read_utf8 from records.markdown_text import sections def read_premises(root: str) -> str | Failure: """README.md's ## Goals and ## Audience in root; a Failure where README.md cannot be read or lacks either, or holds one twice or empty.""" text = read_utf8(root, "README.md", "no premises") if isinstance(text, Failure): return text found = sections(text) for name in ("Goals", "Audience"): bodies = found.get(name, []) if not bodies: return Failure(f"README.md has no ## {name} heading - no premises.") if len(bodies) > 1: return Failure(f"README.md has ## {name} more than once - no premises.") if not bodies[0]: return Failure(f"README.md has nothing under ## {name} - no premises.") return f"## Goals\n{found['Goals'][0]}\n\n## Audience\n{found['Audience'][0]}"