Answer stability round 1: 0 🔴, 5 🟡 (0 misread); lock an epic's decisions while one is appended, and test the epic's key, the approval and the quote sources

This commit is contained in:
2026-11-18 23:40:28 +01:00
parent 7d245dcdce
commit 24cb6b2af0
10 changed files with 159 additions and 53 deletions
+32 -10
View File
@@ -89,6 +89,19 @@ def with_language(text: str, language: str) -> str | Failure:
return line + "\n" + "\n" * bool(text.strip()) + text
def decision_titled(decisions: str, title: str) -> str | None:
"""The entry under the ### title heading of decisions, a ## Decisions section's body; None where it has no such heading."""
found: list[str] | None = None
for line, fenced in fenced_lines(decisions):
if not fenced and line.startswith("### "):
if found is not None:
break
found = [] if line[4:].strip() == title else None
elif found is not None:
found.append(line)
return None if found is None else "\n".join(found).strip()
@dataclasses.dataclass(frozen=True)
class EpicRecord:
"""One epic's record, kept in its description."""
@@ -110,18 +123,27 @@ class EpicRecord:
"""Writes body as the ## name section. approved says the human approved the change in an interrupt, which Goals and Audience need."""
return self.written(lambda text: with_section(text, name, body), frozenset({name}) if approved else frozenset())
def append_decision(self, title: str, entry: str) -> Held | Failure:
"""Adds entry under a ### title heading at the end of ## Decisions, leaving the decisions before it as they are."""
if not title.strip() or "\n" in title:
def append_decision(self, title: str, entry: str) -> bool | Failure:
"""Adds entry under a ### title heading at the end of ## Decisions, leaving the decisions before it as they are. False where the section already holds that entry under that title, so recording a decision twice keeps one; a Failure where it holds another entry under it, so one title names one decision."""
title, entry = title.strip(), entry.strip()
if not title or "\n" in title:
return Failure("the title must be one line of text")
if not entry.strip():
if not entry:
return Failure("pipe the decision's text in")
def appended(text: str) -> str | Failure:
before = read_section(text, "Decisions")
return before if isinstance(before, Failure) else with_section(text, "Decisions", f"{before}\n\n### {title.strip()}\n\n{entry.strip()}".strip())
return self.written(appended, frozenset())
held = self.description.held()
if isinstance(held, Failure):
return held
before = read_section(held.text, "Decisions")
if isinstance(before, Failure):
return before
same = decision_titled(before, title)
if same is not None:
return False if same == entry else Failure(f"## Decisions already holds another decision titled {title!r}: give this one a title of its own")
text = with_section(held.text, "Decisions", f"{before}\n\n### {title}\n\n{entry}".strip())
if isinstance(text, Failure):
return text
wrote = dataclasses.replace(self.description, approved=frozenset()).write(text, held.version)
return wrote if isinstance(wrote, Failure) else True
def write_language(self, language: str) -> Held | Failure:
return self.written(lambda text: with_language(text, language), frozenset())