Answer architecture round 5: return the heading as a dataclass, read the Mean line as its own field, mark an entry paired explicitly, move metric-bench's path resolution back to metric_bench, and split the scoring trigger into named steps

This commit is contained in:
2026-10-09 01:44:53 +02:00
parent efed78bf5e
commit c1133edf39
9 changed files with 143 additions and 92 deletions
+16 -33
View File
@@ -1,5 +1,4 @@
import dataclasses
import os
import re
import time
@@ -36,6 +35,17 @@ class Entry:
ruling: str | None
places: list[Place]
@property
def paired(self) -> bool:
return self.against is not None
@dataclasses.dataclass(frozen=True)
class Heading:
title: str
commit: str
against: str | None
@dataclasses.dataclass(frozen=True)
class HistoryChange:
@@ -45,13 +55,6 @@ class HistoryChange:
after: str
@dataclasses.dataclass(frozen=True)
class ScoringRun:
heading: str
commit: str
places: list[Place]
def entries(history: str) -> list[Entry]:
"""Each paired ruling and scoring run in a comprehension history, in the order the file holds them; a section whose heading names no commit is left out."""
found = []
@@ -63,11 +66,6 @@ def entries(history: str) -> list[Entry]:
return found
def scoring_runs(history: str) -> list[ScoringRun]:
"""Each scoring run, with the places its seats named, as they wrote them; paired rulings name what changed, not what is hard, and are left out."""
return [ScoringRun(entry.heading, entry.commit, entry.places) for entry in entries(history) if entry.against is None]
def seat_places(body: str) -> list[Place]:
places = []
listing = False
@@ -92,23 +90,7 @@ def bullet_places(bullet: str) -> list[Place]:
return places
def resolved(places: list[Place], tracked: list[str]) -> tuple[list[Place], list[Place]]:
"""Entries written before paths were written from the repository's root shorten a path once they have named its folder: `cycle/run.py` after `bin/loop_claude/cycle/states.py`. Each place resolves to the one tracked file it names, or, where several match, the one in the folder of the place resolved before it; a place naming no file, or several, is dropped. Returns the resolved places and the dropped ones."""
found = []
dropped = []
before = ""
for place in places:
candidates = [place.path] if place.path in tracked else [path for path in tracked if path.endswith("/" + place.path)]
nearest = [path for path in candidates if path.startswith(os.path.dirname(before) + "/")] if len(candidates) > 1 else candidates
if len(nearest) == 1:
before = nearest[0]
found.append(Place(before, place.name))
else:
dropped.append(place)
return found, dropped
def heading(at: float, read: str, paired: bool, moved: bool) -> re.Match[str] | Failure:
def heading(at: float, read: str, paired: bool, moved: bool) -> Heading | Failure:
"""An entry's heading, matched by HEADING: when the seats finished, in UTC, and what they read. A run moved from a decision entry opens instead with the date or time that entry gives."""
if moved and not DATED.match(read):
return Failure(f"a seats file holding a {MEAN} line alone opens with YYYY-MM-DD or YYYY-MM-DDTHH:MM:SSZ, then `, `: {read}")
@@ -116,7 +98,7 @@ def heading(at: float, read: str, paired: bool, moved: bool) -> re.Match[str] |
return Failure(f"only a seats file holding a {MEAN} line alone opens with a date: {read}")
title = read if moved else f"{time.strftime(STAMP, time.gmtime(at))}, {read}"
if (named := HEADING.match(title)) and bool(named.group(4)) == paired:
return named
return Heading(title, named.group(3), named.group(4))
return Failure(f"the seats file's first line is not `<PR or branch> at <commit>{', against <base>' if paired else ''}`: {read}")
@@ -137,8 +119,9 @@ def vote_text(seat: Seat, counted: str) -> str:
def scoring_entry(title: str, seats: list[Seat], scores: dict[str, list[str]], means: list[str]) -> str:
rows = [[seat, *values] for seat, values in scores.items() if seat != MEAN] + [[MEAN, *means]]
labels = [(f"{seat.name}, {RESTRUCTURE_FIRST if seat.name == ARCHITECT else HARDEST_FIRST}:", seat.places) for seat in seats if seat.name != MEAN]
"""A scoring run's entry; a run moved from a decision entry has its means alone."""
rows = [[seat, *values] for seat, values in scores.items()] + [[MEAN, *means]]
labels = [(f"{seat.name}, {RESTRUCTURE_FIRST if seat.name == ARCHITECT else HARDEST_FIRST}:", seat.places) for seat in seats]
return entry_text(title, [], [["Seat", *DIMENSIONS], *rows], labels)