Answer architecture round 1: 2 🔴, 4 🟡 (0 misread); one branch_chunks reader with a pure fix rule, routed chunks matched by item

This commit is contained in:
2026-10-28 21:22:25 +01:00
parent 1a81b55925
commit a16f0e4625
22 changed files with 639 additions and 595 deletions
+21 -53
View File
@@ -35,10 +35,10 @@ holds R and S, and C too where its table also had A, G and Goals. The chunk meas
A chunk is marked `by rebase` where a commit in it has a committer time apart from its author time,
since a rebase replays a pull request's commits at once, and `never replayed` where none does, since
a pushed or fast-forwarded commit may be part of a pull request. A merge's titles are its branch's
commits'; any other chunk's are its own. Two pull requests merged in the same second read as one
chunk. Rebase drops a round's commit that changed no file, so a rebase or push chunk gives its
rounds and findings as lower bounds, `at least`, and the report ends saying all this.
a pushed or fast-forwarded commit may be part of a pull request. A merge's titles are its own and
its branch's commits'; any other chunk's are its own. Two pull requests merged in the same second
read as one chunk. Rebase drops a round's commit that changed no file, so a rebase or push chunk
gives its rounds and findings as lower bounds, `at least`, and the report ends saying all this.
Given L, E and I, on the levels ~/.claude/rules/todo-items.md defines, and S, it works out R from
L, E and I, as rank_todo.py does, and lists the 5 finished items whose guesses sit closest, closest
@@ -71,18 +71,18 @@ Exit 1, saying why, on bad arguments, when git cannot start, finds no checkout o
clone, or the default branch cannot be read; or, after the rest of the report, when the anchors are
left out.
"""
import functools
import pathlib
import re
import sys
from score_outcomes.anchors import anchor_lines, Anchors, ANCHORS_PATH, parse_anchors
from score_outcomes.results import chunk_log, fixed_later, label, Landing, misreads, nearest, render, report, Result, results_of, shipped
from git_repo import default_branch, file_at, full_history, git, top
from branch_chunks.read import branch_chunks
from git_repo import default_branch, full_history, git, top
from failure import Failure
from score_outcomes.later_fixes import later_fixes
from score_outcomes.results import fixed_later, misreads, nearest, render, report, Result, results_of
from todo_table import LEVELS, risk, TOP_SCORE
from markdown_text import listed
from utc_stamp import utc
# The scores score-outcomes takes, in order.
GIVEN = ("L", "E", "I", "S")
@@ -157,51 +157,19 @@ def read_results(default: str) -> list[Result] | Failure:
"""What each chunk on the default branch's first-parent line measured."""
if partial := full_history():
return partial
# Both logs read one commit, so a fetch that moves the branch between them cannot cut chunks two ways.
tip = git("rev-parse", "--verify", f"{default}^{{commit}}")
if isinstance(tip, Failure):
return tip
log = git("log", "--first-parent", "--format=%x1e%h %ct %at %p", "--name-only", tip.strip())
if isinstance(log, Failure):
return log
fixes = later_fixes(tip.strip())
if isinstance(fixes, Failure):
return fixes
fixed_by = {landed.label: landed.fixed_by for landed in fixes}
# Each commit's part of the log is its line, then the files it changed against its first parent.
commits = [part.splitlines() for part in log.split("\x1e")[1:]]
headers = [commit[0] for commit in commits]
hashes = [header.split()[0] for header in headers]
plan = {short for short, commit in zip(hashes, commits) if "todo.md" in commit}
root = top()
if isinstance(root, Failure):
return root
run = functools.partial(git, cwd=root)
chunks = branch_chunks(default, run)
if isinstance(chunks, Failure):
return chunks
results: list[Result] = []
for first, last, committed, landed in chunk_log(headers):
# Only a chunk that changed todo.md can ship an item, so the others skip measure's git calls.
if not any(short in plan for short in hashes[hashes.index(last):hashes.index(first) + 1]):
for chunk in chunks:
if chunk.before is None or not chunk.shipped:
continue
titled = f"{first}^1..{first}^2" if landed == "merge" else f"{first}^1..{last}"
named = label(first, last)
measured = measure(f"{first}^1", last, named, utc(committed), titled, landed, fixed_by[named])
if isinstance(measured, Failure):
return measured
results += measured
numstat = run("diff", "--numstat", chunk.before, chunk.tip)
if isinstance(numstat, Failure):
return numstat
results += results_of(chunk, numstat)
return results
def measure(before: str, tip: str, named: str, merged: str, titled: str, landed: Landing, fixed_by: tuple[str, ...]) -> list[Result] | Failure:
"""What one chunk measured for each item it shipped: its change from the commit before it to its tip, and the titles of the commits in the range titled."""
planned = file_at(before, "todo.md")
if isinstance(planned, Failure):
return planned
after = file_at(tip, "todo.md")
if isinstance(after, Failure):
return after
items = shipped(planned, after)
if not items:
return []
numstat = git("diff", "--numstat", before, tip)
if isinstance(numstat, Failure):
return numstat
titles = git("log", "--format=%s", titled)
if isinstance(titles, Failure):
return titles
return results_of(items, named, merged, numstat, titles.splitlines(), landed, fixed_by)