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:
+17
-14
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user