Answer architecture round 1: 1 🔴, 1 🟡; build the report text in a pure function, and parse anchor rows and IDs with todo_table's parsers

This commit is contained in:
2026-10-16 19:41:53 +02:00
parent c0dce6c887
commit 0f3434f2c5
4 changed files with 52 additions and 44 deletions
+17 -14
View File
@@ -48,7 +48,7 @@ import pathlib
import re
import sys
from score_outcomes.anchors import anchor_lines, ANCHORS, anchors
from score_outcomes.anchors import anchor_lines, ANCHORS_PATH, parse_anchors
from git_repo import default_branch, file_at, full_history, git, top
from failure import Failure
from todo_table import LEVELS, risk, TOP_SCORE
@@ -80,20 +80,23 @@ def main(argv: list[str]) -> int:
anchored = read_anchors()
if isinstance(anchored, Failure):
return failed(anchored)
if argv:
given = dict(zip(GIVEN, map(int, argv)))
given["R"] = risk(given["L"], given["E"], given["I"])
print(f"Finished items nearest L {given['L']}, E {given['E']}, I {given['I']}, so R {given['R']}, and S {given['S']}, closest first:\n")
print("\n".join(render(outcome) for outcome in nearest(outcomes, given)) or "- None: no merge commit on the default branch shipped an item from todo.md. A project that merges by squash or fast-forward has none.")
print()
print(f"Anchors in {ANCHORS}, each level's shipped items:\n")
print("\n".join(anchor_lines(anchored, outcomes)) or f"- None: the project's {ANCHORS} names no level; ~/.claude/rules/todo-items.md says how to choose them.")
print()
print("Median outcome at each guessed score, among chunks that shipped one item:\n")
print("\n".join(report(outcomes)))
given = dict(zip(GIVEN, map(int, argv)))
print(report_text(outcomes, anchored, given))
return 0
def report_text(outcomes: list[Outcome], anchored: list[tuple[str, tuple[int, ...]]], given: dict[str, int]) -> str:
"""The report: the finished items nearest the given scores, where any are given, then the anchors, then the medians."""
sections = []
if given:
r = risk(given["L"], given["E"], given["I"])
near = [render(outcome) for outcome in nearest(outcomes, given | {"R": r})] or ["- None: no merge commit on the default branch shipped an item from todo.md. A project that merges by squash or fast-forward has none."]
sections.append([f"Finished items nearest L {given['L']}, E {given['E']}, I {given['I']}, so R {r}, and S {given['S']}, closest first:", "", *near])
sections.append([f"Anchors in {ANCHORS_PATH}, each level's shipped items:", "", *anchor_lines(anchored, outcomes)])
sections.append(["Median outcome at each guessed score, among chunks that shipped one item:", "", *report(outcomes)])
return "\n\n".join("\n".join(section) for section in sections)
def failed(failure: Failure) -> int:
print(f"score-outcomes: {failure.reason}", file=sys.stderr)
return 1
@@ -105,11 +108,11 @@ def read_anchors() -> list[tuple[str, tuple[int, ...]]] | Failure:
if isinstance(root, Failure):
return root
try:
return anchors((pathlib.Path(root) / ANCHORS).read_text())
return parse_anchors((pathlib.Path(root) / ANCHORS_PATH).read_text())
except FileNotFoundError:
return []
except (OSError, UnicodeDecodeError) as failure:
return Failure(f"cannot read {ANCHORS}: {failure}")
return Failure(f"cannot read {ANCHORS_PATH}: {failure}")
def read_outcomes(default: str) -> list[Outcome] | Failure: