diff --git a/.gitignore b/.gitignore index a2ded1f1..ccdd1054 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ !agents/ !agents/*.md !bin/ +!bin/comprehension_history.py !bin/failure.py !bin/file_writes.py !bin/larv-review diff --git a/CHANGELOG.md b/CHANGELOG.md index 8268a089..ab7cc171 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,9 +3,9 @@ ## Unreleased - The stability reviewer keeps its scratch work in a directory it creates for the run, deletes that directory afterwards, and deletes nothing else. -- larv-review's mechanical rules run in the new, tested `bin/larv-review`: the paired ruling's base (`ruling-base`), each pass's round count (`round-count`), the scoring run's trigger (`needs-scoring-run ...`), and the vote count, means and history format (`record-ruling ` and `record-scoring ...`, which read a seats file and append to `docs/comprehension-history.md`; `record-scoring` prints `Floor:` when the means under the floor block the merge). The skill says when to run each and what its answer means. A seats file line the tool cannot read fails the run, so a mistyped vote never counts as same. The base search compares the history before and after each merged change, so it no longer depends on how a line is worded, and orders a change's rulings by their headings' times. A release whose last plan item moves to another release is due a scoring run too, once work has landed towards it. A seats file must name commits the checkout holds. Scores a `comprehension floor:` decision entry still holds move into the history through `record-scoring`, as a `Mean:` line. When origin cannot be fetched, the tool reads it as last fetched and says so. +- larv-review's mechanical rules run in the new, tested `bin/larv-review`: the paired ruling's base (`ruling-base`), each pass's round count (`round-count`), the scoring run's trigger (`needs-scoring-run ...`), and the vote count, means and history format (`record-ruling []` and `record-scoring `, which append to `docs/comprehension-history.md`; `record-scoring` prints `Floor:` naming each mean under the floor). The skill says when to run each and what its answer means. A seats file line the tool cannot read fails the run, so a mistyped vote never counts as same. The base search compares the history before and after each merged change, so it no longer depends on how a line is worded, and orders a change's rulings by their headings' times. A release whose last plan item moves to another release is due a scoring run too, once work has landed towards it. A seats file must name commits the checkout holds. When origin cannot be fetched, the tool reads it as last fetched and says so. - The new `bin/metric-bench` benches cheap static metrics of a project's Python against the places its comprehension history names as hardest: cognitive complexity, length, shared state and change spread, each scored by how well it ranks the named functions above the rest. No metric enters review yet. -- larv-review blocks a merge when simulated readers rule that the PR makes the project read worse than the last measured commit: the default branch's newest merged change whose last ruling in `docs/comprehension-history.md` is better, or that added a scoring run there while that ruling named no fall. A ruling of same leaves that commit in place, so a worse ruling may name places earlier chunks wrote. In each architecture pass Mid A and the inherited architect vote better, same or worse on each dimension and overall: `Navigation same, Locality worse, Shape same, Self-sufficiency same, Overall better`. When their overall votes differ, the maintainability senior and Junior A vote too. A ruling needs a lead of two or more votes, else it is same. Each place a seat names opens with the dimensions it moves, such as `Locality, Shape: `, or the run fails, and a vote that no place opens with counts as same. A dimension falls when its worse votes lead by two. A better or same ruling in which a dimension fell calls a scoring run, and counts as worse when that dimension's mean is under the floor; such a run leaves the ratchet's base in place unless the ruling is better. A worse ruling never ships: after three rounds larv-review asks you for another round, a no leaves the PR unmerged, and so does an unattended run. The four-seat scoring run checks the comprehension floor only when a chunk ships or removes a release's last plan item, or ships an item naming the floor; between those runs, a score under the floor blocks a merge only through a fallen dimension, and that block counts as a worse ruling. On those runs, a score under the floor blocks the merge until fixed or until you decide to ship; a decision in `docs/decisions.md` that lets every chunk ship under the floor counts as yours. +- larv-review blocks a merge when simulated readers rule that the PR makes the project read worse than the last measured commit: the default branch's newest merged change whose last ruling in `docs/comprehension-history.md` is better, or that added a scoring run there while that ruling named no fall. A ruling of same leaves that commit in place, so a worse ruling may name places earlier chunks wrote. In each architecture pass Mid A and the inherited architect vote better, same or worse on each dimension and overall: `Navigation same, Locality worse, Shape same, Self-sufficiency same, Overall better`. When their overall votes differ, the maintainability senior and Junior A vote too. A ruling needs a lead of two or more votes, else it is same. Each place a seat names opens with the dimensions it moves, such as `Locality, Shape: `, or the run fails, and a vote that no place opens with counts as same. A dimension falls when its worse votes lead by two. When a dimension falls in a better or same ruling, `record-ruling` asks for the four scoring seats and, given their scores file, counts the ruling as worse when that dimension's mean is under the floor. A worse ruling never ships: after three rounds larv-review asks you for another round, a no leaves the PR unmerged, and so does an unattended run. The four-seat scoring run checks the comprehension floor only when a chunk ships or removes a release's last plan item, or ships an item naming the floor; between those runs, a score under the floor blocks a merge only through a fallen dimension, and that block counts as a worse ruling. On those runs, a score under the floor blocks the merge until fixed or until you decide to ship; a decision in `docs/decisions.md` that lets every chunk ship under the floor counts as yours. - larv-review reruns fewer passes after a fix. A fix reruns the pass whose ๐Ÿ”ด or ๐ŸŸก it answers, plus stability when the fix changes behaviour, security when it opens an untrusted-input boundary or touches authn/authz, secrets or crypto, and architecture when it carries an architectural decision. A rerun reviews only what changed since that pass last reviewed. A fix for a ๐ŸŸข, a โ“ or any prose finding reruns no pass, and prose takes one round. - larv-review runs one security pass on each change: the full scan alone when it runs, else `/security-review`. - larv-review runs the new `bin/reading-cost`, which measures each chunk `loop-claude` finished from its archive: the new input tokens the worker and its subagents took in before the worker's first commit, and the files git tracks that they read most. It appends each figure the project's `docs/reading-cost.md` lacks. Once 10 chunks are measured, and the last 5 chunks' median is above the 5 before them, larv-review files one plan item naming the files read most, or refreshes it. The chunk that ships it runs `reading-cost --reset`, so the trend counts only chunks that finished after it. diff --git a/bin/larv_review/history.py b/bin/comprehension_history.py similarity index 54% rename from bin/larv_review/history.py rename to bin/comprehension_history.py index 1cac4902..62592a7b 100644 --- a/bin/larv_review/history.py +++ b/bin/comprehension_history.py @@ -2,25 +2,35 @@ import dataclasses import re import time -from larv_review.seats import ARCHITECT, DIMENSIONS, MEAN, Seat from failure import Failure from markdown_sections import sections -DATED = re.compile(r"^[0-9]{4}-[0-9]{2}-[0-9]{2}(?:T[0-9]{2}:[0-9]{2}:[0-9]{2}Z)?, ") +ARCHITECT = "Inherited architect" DECIDED_BY = "decided by" -FELL = re.compile(r"^Fell: (.+)$", re.M) -RATCHET = re.compile(r"^Ratchet: .+$", re.M) +DIMENSIONS = ("Navigation", "Locality", "Shape", "Self-sufficiency", "Overall") HARDEST_FIRST = "hardest first" HEADING = re.compile(r"^([^,]+), (.+) at ([0-9a-f]{7,40})(?:, against ([0-9a-f]{7,40}))?$") +HISTORY = "docs/comprehension-history.md" +JUNIOR = "Junior A" +MEAN = "Mean" +MID = "Mid A" # `path:line` or `:line`, then the unit's name where one follows. PLACE = re.compile(r"`([^`\s]*):\d+`(?: `(\w+)`)?") RESTRUCTURE_FIRST = "would restructure first" RULING = re.compile(r"^Ruling: (better|same|worse)$", re.M) SEAT_PLACES = re.compile(rf"^.+, ({DECIDED_BY}|{HARDEST_FIRST}|{RESTRUCTURE_FIRST}):$") +SENIOR = "Maintainability senior" STAMP = "%Y-%m-%dT%H:%M:%SZ" TITLE = "# Comprehension history\n" +@dataclasses.dataclass(frozen=True) +class Seat: + name: str + said: str + places: list[str] + + @dataclasses.dataclass(frozen=True) class Place: path: str @@ -29,14 +39,12 @@ class Place: @dataclasses.dataclass(frozen=True) class Entry: - """One paired ruling, which names the commit it was against, its ruling and the dimensions that fell unless it is worse, or one scoring run, which names none of them and may hold a `Ratchet:` line.""" + """One paired ruling, which names the commit it was against and its ruling, or one scoring run, which names neither.""" heading: str time: str commit: str against: str | None ruling: str | None - fell: list[str] - ratchet: str | None places: list[Place] @property @@ -52,11 +60,11 @@ class Heading: @dataclasses.dataclass(frozen=True) -class HistoryChange: - """A merged change on the default branch that touched the history, and the history before and after it.""" - commit: str - before: str - after: str +class Scoring: + """The four scoring seats' lines, their scores as written and the means, in DIMENSIONS' order.""" + seats: list[Seat] + scores: dict[str, list[str]] + means: list[str] def entries(history: str) -> list[Entry]: @@ -66,9 +74,7 @@ def entries(history: str) -> list[Entry]: if named := HEADING.match(heading): body = "\n".join(bodies) ruling = RULING.search(body) - fell = FELL.search(body) - ratchet = RATCHET.search(body) - found.append(Entry(heading, named.group(1), named.group(3), named.group(4), ruling.group(1) if ruling else None, [name.strip() for name in fell.group(1).split(",")] if fell else [], ratchet.group(0) if ratchet else None, seat_places(body))) + found.append(Entry(heading, named.group(1), named.group(3), named.group(4), ruling.group(1) if ruling else None, seat_places(body))) return found @@ -96,13 +102,9 @@ def bullet_places(bullet: str) -> list[Place]: return places -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}") - if DATED.match(read) and not moved: - 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}" +def heading(at: float, read: str, paired: bool) -> Heading | Failure: + """An entry's heading, matched by HEADING: when the seats finished, in UTC, and what they read.""" + title = f"{time.strftime(STAMP, time.gmtime(at))}, {read}" if (named := HEADING.match(title)) and bool(named.group(4)) == paired: return Heading(title, named.group(3), named.group(4)) return Failure(f"the seats file's first line is not ` at {', against ' if paired else ''}`: {read}") @@ -114,11 +116,12 @@ def appended(history: str, entry: str) -> str: return f"{text}\n{entry}" -def ruling_entry(title: str, seats: list[Seat], said: dict[str, list[str]], counted: dict[str, list[str]], ruled: str, fell: list[str]) -> str: - """A paired ruling's entry; a seat's vote that counted as same for want of a place says so.""" +def ruling_entry(title: str, seats: list[Seat], said: dict[str, list[str]], counted: dict[str, list[str]], lines: list[str], scoring: Scoring | None) -> str: + """A paired ruling's entry, with the scoring run that decided a fall; a seat's vote that counted as same for want of a place says so.""" votes = [[seat.name, *map(vote_text, DIMENSIONS, said[seat.name], counted[seat.name])] for seat in seats] - lines = [f"Ruling: {ruled}"] + ([f"Fell: {', '.join(fell)}"] if fell else []) - return entry_text(title, lines, [["Seat", *DIMENSIONS], *votes], [(f"{seat.name}, {DECIDED_BY}:", seat.places) for seat in seats]) + tables = [[["Seat", *DIMENSIONS], *votes]] + ([scores_table(scoring)] if scoring else []) + labels = [(f"{seat.name}, {DECIDED_BY}:", seat.places) for seat in seats] + (scoring_labels(scoring.seats) if scoring else []) + return entry_text(title, lines, tables, labels) def vote_text(dimension: str, said: str, counted: str) -> str: @@ -127,17 +130,21 @@ def vote_text(dimension: str, said: str, counted: str) -> str: return f"same (voted {said}, naming no place)" if dimension == DIMENSIONS[-1] else f"same (voted {said}, no place naming {dimension})" -def scoring_entry(title: str, seats: list[Seat], scores: dict[str, list[str]], means: list[str], lines: list[str]) -> str: - """A scoring run's entry, with any lines such as a `Ratchet:` line; 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, lines, [["Seat", *DIMENSIONS], *rows], labels) +def scoring_entry(title: str, lines: list[str], scoring: Scoring) -> str: + return entry_text(title, lines, [scores_table(scoring)], scoring_labels(scoring.seats)) -def entry_text(title: str, lines: list[str], table: list[list[str]], seats: list[tuple[str, list[str]]]) -> str: - """The heading, any lines such as `Ruling: same`, a table whose first row is its header, and under each seat's label its places, one bullet each.""" - header, *rows = table - parts = [f"## {title}", *lines, "\n".join([row_text(header), "|" + "---|" * len(header), *map(row_text, rows)])] +def scores_table(scoring: Scoring) -> list[list[str]]: + return [["Seat", *DIMENSIONS], *([seat, *values] for seat, values in scoring.scores.items()), [MEAN, *scoring.means]] + + +def scoring_labels(seats: list[Seat]) -> list[tuple[str, list[str]]]: + return [(f"{seat.name}, {RESTRUCTURE_FIRST if seat.name == ARCHITECT else HARDEST_FIRST}:", seat.places) for seat in seats] + + +def entry_text(title: str, lines: list[str], tables: list[list[list[str]]], seats: list[tuple[str, list[str]]]) -> str: + """The heading, any lines such as `Ruling: same`, each table, whose first row is its header, and under each seat's label its places, one bullet each.""" + parts = [f"## {title}", *lines, *("\n".join([row_text(header), "|" + "---|" * len(header), *map(row_text, rows)]) for header, *rows in tables)] parts += [f"{label}\n\n" + "\n".join(f"- {place}" for place in places) for label, places in seats if places] return "\n\n".join(parts) + "\n" diff --git a/bin/larv_review/base.py b/bin/larv_review/base.py index 200c9fdb..538d90cf 100644 --- a/bin/larv_review/base.py +++ b/bin/larv_review/base.py @@ -1,16 +1,15 @@ -from larv_review.history import entries, Entry, HistoryChange +from comprehension_history import entries, Entry +from larv_review.git import HistoryChange def measured_commit(changes: list[HistoryChange]) -> str | None: - """The newest change, of changes given newest first, whose last added paired ruling is better, or that adds a scoring run and whose last added paired ruling names no fall.""" + """The newest change, of changes given newest first, that adds a scoring run to the history, or whose last added paired ruling is better.""" for change in changes: held = {entry.heading for entry in entries(change.before)} added = [entry for entry in entries(change.after) if entry.heading not in held] rulings = sorted((entry for entry in added if entry.paired), key=lambda entry: entry.time) - last = rulings[-1] if rulings else None - ruled_better = last is not None and last.ruling == "better" - scored_without_fall = any(not entry.paired for entry in added) and not (last and last.fell) - if ruled_better or scored_without_fall: + ruled_better = bool(rulings) and rulings[-1].ruling == "better" + if ruled_better or any(not entry.paired for entry in added): return change.commit return None diff --git a/bin/larv_review/git.py b/bin/larv_review/git.py index 5c4d0bb5..fca2c324 100644 --- a/bin/larv_review/git.py +++ b/bin/larv_review/git.py @@ -1,10 +1,17 @@ +import dataclasses import re import subprocess from failure import Failure -from larv_review.history import HistoryChange +from comprehension_history import HISTORY -HISTORY = "docs/comprehension-history.md" + +@dataclasses.dataclass(frozen=True) +class HistoryChange: + """A merged change on the default branch that touched the history, and the history before and after it.""" + commit: str + before: str + after: str def git(*args: str) -> str | Failure: diff --git a/bin/larv_review/main.py b/bin/larv_review/main.py index 12b8ee57..ebccd8ec 100644 --- a/bin/larv_review/main.py +++ b/bin/larv_review/main.py @@ -1,38 +1,35 @@ """Hold larv-review's mechanical rules: the paired ruling's base and vote count, each pass's rounds, the scoring run's trigger, and the comprehension history's format. -usage: larv-review ruling-base | round-count | needs-scoring-run [...] | record-ruling | record-scoring [...] +usage: larv-review ruling-base | round-count | needs-scoring-run [...] | record-ruling [] | record-scoring -Run it inside a project checkout or one of its worktrees. Each command but record-ruling first -fetches origin, when the checkout has that remote, and takes origin's default branch, or else the -local main or master, as the default branch. When the fetch fails, round-count and record-scoring -read origin as last fetched and say so on stderr; the other two exit 1. The history is +Run it inside a project checkout or one of its worktrees. ruling-base, round-count and +needs-scoring-run first fetch origin, when the checkout has that remote, and take origin's default +branch, or else the local main or master, as the default branch. When the fetch fails, round-count +reads origin as last fetched and says so on stderr; the other two exit 1. The history is docs/comprehension-history.md in the checkout. ruling-base prints the commit a paired ruling reads against, then which of these found it. The last -measured commit is the default branch's newest merged change whose last added paired ruling, by -heading time, is better, or that adds a scoring run to the history while that ruling names no fall; -a merge commit counts as one change against its first parent. With none, the base is the one the -history's first paired ruling names; with no ruling either, it is the merge base of HEAD and the -default branch. +measured commit is the default branch's newest merged change that adds a scoring run to the +history, or whose last added paired ruling, by heading time, is better; a merge commit counts as +one change against its first parent. With none, the base is the one the history's first paired +ruling names; with no ruling either, it is the merge base of HEAD and the default branch. round-count prints each pass's count: the highest among the titles opening `Answer round :` of commits the default branch does not hold. It marks each pass at the cap of {cap} rounds, and each name in such a title that is not a pass. needs-scoring-run takes the IDs of the todo.md items the chunk ships, none when it ships none, and -prints why the chunk is due a scoring run, or `No scoring run due.` The chunk's entries are those -the checkout's history holds and the default branch's lacks. It is due when the chunk ships an item -whose tagline names the comprehension floor, when it leaves a release with no item in the -checkout's todo.md, less the shipped items, and work has landed towards that release, or when the -chunk's newest entry is a paired ruling with a `Fell:` line. Work has landed when the chunk ships -one of the release's items, or when the release is the earliest the default branch's todo.md names -and the default branch has a commit after its newest v* tag, or has no v* tag. +prints why the chunk is due a scoring run, or `No scoring run due.` It is due when the chunk ships +an item whose tagline names the comprehension floor, or when it leaves a release with no item in +the checkout's todo.md, less the shipped items, and work has landed towards that release. Work has +landed when the chunk ships one of the release's items, or when the release is the earliest the +default branch's todo.md names and the default branch has a commit after its newest v* tag, or has +no v* tag. -record-ruling and record-scoring read a seats file: a first line naming what the seats read, ` at `, ending `, against ` for a paired ruling, then each seat's line, each -followed by its places, one `- ` bullet each, as the history writes them. A seat's line opens with -its label, written exactly: `Junior A:`, `Mid A:`, `Maintainability senior:` or `Inherited -architect:`. +A seats file's first line names what the seats read, ` at `, ending +`, against ` in a votes file. Each seat's line follows, opening with its label written +exactly: `Junior A:`, `Mid A:`, `Maintainability senior:` or `Inherited architect:`. Its places +follow it, one `- ` bullet each, as the history writes them. A votes file: PR #231 at abc1234, against def5678 @@ -46,35 +43,30 @@ architect:`. - Navigation: `README.md:40` "Tools": ... - Locality: `bin/x.py:12` `run`: ... +A scores file holds Junior A's, Mid A's, the maintainability senior's and the inherited architect's +lines in that order, each `Navigation , Locality , Shape , Self-sufficiency , Overall +`: each score from 1 to 10, and the overall at most 1 above the line's lowest dimension. + record-ruling takes Mid A's and the inherited architect's votes on each dimension and overall, each better, same or worse. Each place opens with the names from the seat's line that it moves, joined by `, ` and followed by `: `. A dimension's vote counts as same unless one of the seat's places opens with that dimension and holds a `path:line` in backticks; the overall vote counts as same unless any place holds one. The printed votes say so. When the two counted overall votes differ, it appends nothing and prints `Split:`, saying to add the maintainability senior's and Junior A's lines. -Otherwise the ruling is the overall vote that leads each other vote by two or more, else same; it -prints `Ruling:` and appends the ruling. A dimension falls when its worse votes lead each other vote -by two or more. Unless the ruling is worse, it prints and records a `Fell:` line naming each. +Otherwise the ruling is the overall vote that leads each other vote by two or more, else same. A +dimension falls when its worse votes lead each other vote by two or more. When a better or same +ruling has a fallen dimension, it appends nothing and prints `Fell:`, saying to run the four +scoring seats on the same commit and run it again with their scores file. With that file, the +ruling counts as worse when a fallen dimension's mean is under the floor of {floor}, and stands +otherwise. It prints `Ruling:` and appends the ruling, with the scores where a fall called them. -record-scoring takes a seats file and the IDs of the items the chunk ships, as needs-scoring-run -does. The file holds Junior A's, Mid A's, the maintainability senior's and the inherited architect's -lines in that order, or a `Mean:` line alone for a run moved from a decision entry. Each line is -`Navigation , Locality , Shape , Self-sufficiency , Overall `, each score from 1 to -10 and the overall at most 1 above the line's lowest dimension. Its first line names no `, against`. -It appends the seats' scores and their means, rounded half up to two decimals, and prints the means, -the item IDs it read, and each mean under the floor of {floor}. It exits 1 on a run with seats that -no plan item, release or fall calls. A line opening `Floor:` says the means under the floor block -the merge, as they do when needs-scoring-run would give a reason besides a fall. It reads the -chunk's entries as needs-scoring-run does. When a fall is pending, it says whether the paired ruling -stands. When a fallen dimension's mean is under the floor, the ruling counts as worse, and it prints -and records a `Ratchet:` line. needs-scoring-run repeats that line, prefixed with `Still standing:`, -until a paired ruling follows it. Once a scoring run follows a fall, the fall calls no other. A file -holding a `Mean:` line alone prints only its means. +record-scoring takes the scores file of a run needs-scoring-run called, whose first line names no +`, against`. It appends the seats' scores and their means, rounded half up to two decimals, prints +the means, and prints a line opening `Floor:` that names each mean under the floor of {floor}. Each record is appended to the history, created when missing, under a heading of the current UTC -time and the seats file's first line. A file holding a `Mean:` line alone opens with the date or -time its decision entry gives, and that line alone is the heading. Each commit the line names must -be in the checkout. Each run appends, so record a ruling or a run once. +time and the seats file's first line. Each commit that line names must be in the checkout. Each run +appends, so record a ruling or a run once. Exit 1, saying why, on unknown arguments, an unknown item ID, a seats file it cannot read or that breaks the shape above, or when git cannot start, finds no checkout or no default branch, cannot @@ -87,18 +79,18 @@ import sys import time import typing -from larv_review.history import appended, heading, ruling_entry, scoring_entry, vote_text +from comprehension_history import appended, DIMENSIONS, heading, HISTORY, ruling_entry, Scoring, scoring_entry, vote_text from larv_review.base import base from larv_review.rounds import CAP, PASSES, round_counts -from larv_review.scoring import chunk_entries, fall, Fall, fall_outcome, fall_reasons, FLOOR, floor_verdict, means, plan_items, scoring_run_due, uncalled, under_floor -from larv_review.git import commit_exists, default_branch, file_at, git, HISTORY, history_changes, landed_since_release, top +from larv_review.git import commit_exists, default_branch, file_at, git, history_changes, landed_since_release, top from larv_review.ruling import counted, fallen, ruling, votes -from larv_review.seats import DIMENSIONS, MEAN, Report, report, score_line, scores from failure import Failure +from larv_review.scoring import fall_ruling, FLOOR, means, plan_items, scoring_run_due, under_floor from rank_todo import ITEMS_HEADER from file_writes import replace_file +from larv_review.seats import scores, seats_file, SeatsFile -USAGE = "usage: larv-review ruling-base | round-count | needs-scoring-run [...] | record-ruling | record-scoring [...]" +USAGE = "usage: larv-review ruling-base | round-count | needs-scoring-run [...] | record-ruling [] | record-scoring " def main(argv: list[str]) -> int: @@ -112,13 +104,12 @@ def main(argv: list[str]) -> int: done = with_default_branch(round_count, stale_ok=True) elif command == "needs-scoring-run" and all(re.fullmatch(r"[0-9]+", id_) for id_ in given): done = with_default_branch(lambda default: needs_scoring_run(default, [int(id_) for id_ in given]), stale_ok=False) - elif command == "record-ruling" and len(given) == 1: - done = record_ruling(pathlib.Path(given[0])) - elif command == "record-scoring" and given and all(re.fullmatch(r"[0-9]+", id_) for id_ in given[1:]): - done = with_default_branch(lambda default: record_scoring(default, pathlib.Path(given[0]), [int(id_) for id_ in given[1:]]), stale_ok=True) - elif command in ("needs-scoring-run", "record-scoring") and given: - named = given[1:] if command == "record-scoring" else given - print(f"{command} takes item IDs, the numbers in todo.md's ID column, not {' '.join(id_ for id_ in named if not re.fullmatch(r'[0-9]+', id_))}; {USAGE}", file=sys.stderr) + elif command == "record-ruling" and len(given) in (1, 2): + done = record_ruling(*map(pathlib.Path, given)) + elif command == "record-scoring" and len(given) == 1: + done = record_scoring(pathlib.Path(given[0])) + elif command == "needs-scoring-run": + print(f"needs-scoring-run takes item IDs, the numbers in todo.md's ID column, not {' '.join(id_ for id_ in given if not re.fullmatch(r'[0-9]+', id_))}", file=sys.stderr) return 1 elif not argv: print(USAGE, file=sys.stderr) @@ -169,21 +160,6 @@ def round_count(default: str) -> Failure | None: def needs_scoring_run(default: str, ids: list[int]) -> Failure | None: - state = chunk_fall(default) - if isinstance(state, Failure): - return state - planned = plan_reasons(default, ids) - if isinstance(planned, Failure): - return planned - reasons = planned + fall_reasons(state) - print(f"Scoring run due: the chunk {' and '.join(reasons)}." if reasons else "No scoring run due.") - if state.ratchet: - print(f"Still standing: {state.ratchet} Fix it and rule again.") - return None - - -def plan_reasons(default: str, ids: list[int]) -> list[str] | Failure: - """Why the plan calls a scoring run, from the default branch's todo.md and the checkout's.""" checkout = top() if isinstance(checkout, Failure): return checkout @@ -204,22 +180,15 @@ def plan_reasons(default: str, ids: list[int]) -> list[str] | Failure: landed = landed_since_release(default) if isinstance(landed, Failure): return landed - return scoring_run_due(planned, chunk, ids, landed) + reasons = scoring_run_due(planned, chunk, ids, landed) + if isinstance(reasons, Failure): + return reasons + print(f"Scoring run due: the chunk {' and '.join(reasons)}." if reasons else "No scoring run due.") + return None -def chunk_fall(default: str) -> Fall | Failure: - """Where the chunk stands in the fall sequence, from the entries the checkout's history holds and the default branch's lacks.""" - held = file_at(default, HISTORY) - if isinstance(held, Failure): - return held - read = history_text() - if isinstance(read, Failure): - return read - return fall(chunk_entries(held, read[1])) - - -def record_ruling(seats_file: pathlib.Path) -> Failure | None: - read = read_seats(seats_file, paired=True) +def record_ruling(votes_file: pathlib.Path, scores_file: pathlib.Path | None = None) -> Failure | None: + read = read_seats(votes_file, paired=True) if isinstance(read, Failure): return read title, given = read @@ -230,65 +199,71 @@ def record_ruling(seats_file: pathlib.Path) -> Failure | None: tally = ", ".join(f"{seat.name} {vote_text(DIMENSIONS[-1], said[seat.name][-1], count[seat.name][-1])}" for seat in given.seats) ruled = ruling([each[-1] for each in count.values()]) if ruled is None: - print(f"Split: {tally}. Launch the maintainability senior and Junior A together, add their lines to the seats file, and run this again.") + print(f"Split: {tally}. Launch the maintainability senior and Junior A together, add their lines to the votes file, and run this again.") return None fell = fallen(count) if ruled != "worse" else [] - print(f"Ruling: {ruled}. Overall votes as counted: {tally}.") - if fell: - print(f"Fell: {', '.join(fell)}. A scoring run is due; the ruling counts as worse if that run scores {' or '.join(fell)} under the floor of {FLOOR}.") - return append(ruling_entry(title, given.seats, said, count, ruled, fell)) + if fell and scores_file is None: + print(f"Fell: {', '.join(fell)}, in a {ruled} ruling. Launch the four scoring seats on {given.read.partition(', against')[0]}, write their lines to a scores file, and run this again with both files.") + return None + if scores_file and not fell: + return Failure(f"no dimension fell in this {ruled} ruling, so it takes no scores file") + lines = [f"Ruling: {ruled}"] + scoring = None + if scores_file: + scored = read_scoring(scores_file, given.read.partition(", against")[0]) + if isinstance(scored, Failure): + return scored + scoring = scored + ruled, why = fall_ruling(ruled, fell, [decimal.Decimal(value) for value in scoring.means]) + lines = [f"Ruling: {ruled}", why] + print(f"{lines[0]}. {' '.join(lines[1:] + [f'Overall votes as counted: {tally}.'])}") + return append(ruling_entry(title, given.seats, said, count, lines, scoring)) -def record_scoring(default: str, seats_file: pathlib.Path, ids: list[int]) -> Failure | None: - read = read_seats(seats_file, paired=False) +def record_scoring(scores_file: pathlib.Path) -> Failure | None: + read = read_seats(scores_file, paired=False) if isinstance(read, Failure): return read title, given = read - if given.moved_mean is not None: - return record_moved_mean(title, given.moved_mean) + scoring = scored_seats(given) + if isinstance(scoring, Failure): + return scoring + found = [decimal.Decimal(value) for value in scoring.means] + print(f"Means: {', '.join(f'{name} {value}' for name, value in zip(DIMENSIONS, found))}.") + if under := under_floor(found): + print(f"Floor: {', '.join(under)} under the floor of {FLOOR} block the merge.") + return append(scoring_entry(title, [], scoring)) + + +def read_scoring(scores_file: pathlib.Path, read: str) -> Scoring | Failure: + """The scores a fall called, once their file names what the votes file read.""" + try: + given = seats_file(scores_file.read_text(encoding="utf-8")) + except (OSError, UnicodeDecodeError) as failure: + return Failure(f"could not read {scores_file}: {failure}") + if isinstance(given, Failure): + return given + if given.read != read: + return Failure(f"the scores file's first line is not `{read}`, as the votes file reads: {given.read}") + return scored_seats(given) + + +def scored_seats(given: SeatsFile) -> Scoring | Failure: found = scores(given.seats) if isinstance(found, Failure): return found - mean = means(list(found.values())) - state = chunk_fall(default) - if isinstance(state, Failure): - return state - planned = plan_reasons(default, ids) - if isinstance(planned, Failure): - return planned - if not (planned or state.pending): - return Failure(uncalled(state)) - print(f"Means: {means_text(mean)}.") - print(f"Item IDs read: {', '.join(map(str, ids)) or 'none'}.") - print(floor_verdict(under_floor(mean), planned)) - outcome = fall_outcome(state.pending, mean) - if outcome: - print(outcome[0]) - return append(scoring_entry(title, given.seats, found, [str(value) for value in mean], outcome[1] if outcome else [])) + return Scoring(given.seats, found, [str(value) for value in means(list(found.values()))]) -def record_moved_mean(title: str, line: str) -> Failure | None: - moved = score_line(MEAN, line) - if isinstance(moved, Failure): - return moved - mean = means([moved]) - print(f"Means: {means_text(mean)}.") - return append(scoring_entry(title, [], {}, [str(value) for value in mean], [])) - - -def means_text(mean: list[decimal.Decimal]) -> str: - return ", ".join(f"{name} {value}" for name, value in zip(DIMENSIONS, mean)) - - -def read_seats(seats_file: pathlib.Path, paired: bool) -> tuple[str, Report] | Failure: +def read_seats(path: pathlib.Path, paired: bool) -> tuple[str, SeatsFile] | Failure: """The seats file, and the heading its record goes under, once each commit it names is in the checkout.""" try: - given = report(seats_file.read_text(encoding="utf-8")) + given = seats_file(path.read_text(encoding="utf-8")) except (OSError, UnicodeDecodeError) as failure: - return Failure(f"could not read {seats_file}: {failure}") + return Failure(f"could not read {path}: {failure}") if isinstance(given, Failure): return given - named = heading(time.time(), given.read, paired, given.moved_mean is not None) + named = heading(time.time(), given.read, paired) if isinstance(named, Failure): return named if unknown := [commit for commit in (named.commit, named.against) if commit and not commit_exists(commit)]: @@ -296,27 +271,16 @@ def read_seats(seats_file: pathlib.Path, paired: bool) -> tuple[str, Report] | F return named.title, given -def history_text() -> tuple[pathlib.Path, str] | Failure: - """The checkout's history and its text, empty when the file is missing.""" +def append(entry: str) -> Failure | None: checkout = top() if isinstance(checkout, Failure): return checkout history = pathlib.Path(checkout, HISTORY) try: - return history, history.read_text(encoding="utf-8") if history.exists() else "" + text = history.read_text(encoding="utf-8") if history.exists() else "" + history.parent.mkdir(parents=True, exist_ok=True) except (OSError, UnicodeDecodeError) as failure: return Failure(f"could not read {history}: {failure}") - - -def append(entry: str) -> Failure | None: - read = history_text() - if isinstance(read, Failure): - return read - history, text = read - try: - history.parent.mkdir(parents=True, exist_ok=True) - except OSError as failure: - return Failure(f"could not create {history.parent}: {failure}") if unwritten := replace_file(history, appended(text, entry).encode()): return Failure(f"could not write {history}: {unwritten.reason}") print(f"Appended to {history}.") diff --git a/bin/larv_review/ruling.py b/bin/larv_review/ruling.py index 9dfc2bd4..4b8e608b 100644 --- a/bin/larv_review/ruling.py +++ b/bin/larv_review/ruling.py @@ -1,6 +1,6 @@ -from larv_review.seats import DIMENSIONS, FIRST_SEATS, Seat, SPLIT_SEATS, vote_line +from comprehension_history import DIMENSIONS, PLACE, Seat from failure import Failure -from larv_review.history import PLACE +from larv_review.seats import FIRST_SEATS, SPLIT_SEATS, vote_line VOTES = ("better", "same", "worse") diff --git a/bin/larv_review/scoring.py b/bin/larv_review/scoring.py index f5ccaa17..021a3593 100644 --- a/bin/larv_review/scoring.py +++ b/bin/larv_review/scoring.py @@ -1,64 +1,18 @@ -import dataclasses import decimal -import itertools -from larv_review.seats import DIMENSIONS -from larv_review.history import entries, Entry +from comprehension_history import DIMENSIONS from failure import Failure from rank_todo import Item, ITEMS_HEADER, parse_row, table_rows FLOOR = decimal.Decimal("7.0") -def chunk_entries(default_history: str, history: str) -> list[Entry]: - """The checkout's entries whose headings the default branch's history lacks, oldest first; entries sharing a time keep their file order.""" - held = {entry.heading for entry in entries(default_history)} - return sorted((entry for entry in entries(history) if entry.heading not in held), key=lambda entry: entry.time) - - -@dataclasses.dataclass(frozen=True) -class Fall: - """Where the chunk stands in the fall sequence: a paired ruling with a `Fell:` line leaves its dimensions pending until a scoring run follows; that run records a `Ratchet:` line when a fallen dimension is under the floor, and the ratchet stands until the next paired ruling.""" - pending: list[str] - ratchet: str | None - scored_last: bool - - -def fall(chunk: list[Entry]) -> Fall: - newest = chunk[-1] if chunk else None - since_ruling = list(itertools.takewhile(lambda entry: not entry.paired, reversed(chunk))) - ratchet = next((entry.ratchet for entry in since_ruling if entry.ratchet), None) - return Fall(newest.fell if newest and newest.paired else [], ratchet, newest is not None and not newest.paired) - - -def fall_reasons(state: Fall) -> list[str]: - return [f"has a paired ruling in which {' and '.join(state.pending)} fell"] if state.pending else [] - - -def uncalled(state: Fall) -> str: - """Why a scoring run nothing calls fails, and what to do instead.""" - if state.scored_last: - return "the chunk's newest entry is already a scoring run; record a paired ruling first, or name the item IDs the chunk ships" - return "no plan item, release or fall calls this scoring run; name the item IDs the chunk ships, as needs-scoring-run took them" - - -def floor_verdict(under: list[str], reasons: list[str]) -> str: - """Whether the means under the floor block the merge: they do on a run the plan calls, its reasons given.""" - if not under: - return f"None under the floor of {FLOOR}." - if reasons: - return f"Floor: {', '.join(under)} under the floor of {FLOOR} block the merge, as the chunk {' and '.join(reasons)}." - return f"Under the floor of {FLOOR}, blocking nothing, as only a fall called this run: {', '.join(under)}." - - -def fall_outcome(fell: list[str], found: list[decimal.Decimal]) -> tuple[str, list[str]] | None: - """What a scoring run says of a pending fall, and the lines it records: a `Ratchet:` line when a fallen dimension's mean is under the floor.""" - if not fell: - return None - if dropped := [f"{name} is {value}" for name, value in zip(DIMENSIONS, found) if name in fell and value < FLOOR]: - line = f"Ratchet: the paired ruling counts as worse, as {' and '.join(fell)} fell and {', '.join(dropped)}, under the floor of {FLOOR}." - return line, [line] - return f"The paired ruling stands: {' and '.join(fell)} fell and each stays at or above the floor of {FLOOR}.", [] +def fall_ruling(ruled: str, fell: list[str], found: list[decimal.Decimal]) -> tuple[str, str]: + """The ruling once the scoring run has scored the dimensions that fell, and the line that says why: worse when one of their means is under the floor.""" + under = [f"{name} {value}" for name, value in zip(DIMENSIONS, found) if name in fell and value < FLOOR] + if under: + return "worse", f"Fell: {', '.join(fell)}, under the floor of {FLOOR} at {', '.join(under)}, so the {ruled} ruling counts as worse." + return ruled, f"Fell: {', '.join(fell)}, each at or above the floor of {FLOOR}, so the {ruled} ruling stands." def means(lines: list[list[str]]) -> list[decimal.Decimal]: diff --git a/bin/larv_review/seats.py b/bin/larv_review/seats.py index 0c0791a1..2fe9fb58 100644 --- a/bin/larv_review/seats.py +++ b/bin/larv_review/seats.py @@ -2,16 +2,10 @@ import dataclasses import decimal import re +from comprehension_history import ARCHITECT, DIMENSIONS, JUNIOR, MID, Seat, SENIOR from failure import Failure -ARCHITECT = "Inherited architect" -DIMENSIONS = ("Navigation", "Locality", "Shape", "Self-sufficiency", "Overall") -JUNIOR = "Junior A" -# A scoring run moved from a `comprehension floor:` decision entry kept only the seats' means. -MEAN = "Mean" -MID = "Mid A" SCORES = re.compile(", ".join(rf"{name} ([0-9]+(?:\.[0-9]+)?)" for name in DIMENSIONS)) -SENIOR = "Maintainability senior" FIRST_SEATS = (MID, ARCHITECT) SCORING_SEATS = (JUNIOR, MID, SENIOR, ARCHITECT) @@ -21,32 +15,19 @@ VOTE_LINE = re.compile(", ".join(rf"{name} (better|same|worse)" for name in DIME @dataclasses.dataclass(frozen=True) -class Seat: - name: str - said: str - places: list[str] - - -@dataclasses.dataclass(frozen=True) -class Report: - """A seats file: what the seats read, ` at `, with `, against ` for a paired ruling, then each seat's line and its places, or, for a run moved from a decision entry, its Mean line alone.""" +class SeatsFile: + """What the seats read, ` at `, with `, against ` for a paired ruling, then each seat's line and its places.""" read: str seats: list[Seat] - moved_mean: str | None -def report(text: str) -> Report | Failure: +def seats_file(text: str) -> SeatsFile | Failure: lines = [line for line in text.splitlines() if line.strip()] if not lines: return Failure("the seats file is empty; its first line names what the seats read: at ") seats: list[Seat] = [] - moved_mean = None for line in lines[1:]: - if line.startswith(f"{MEAN}: ") and not seats and moved_mean is None: - moved_mean = line[len(MEAN) + 2:].strip() - elif moved_mean is not None: - return Failure(f"a {MEAN} line stands alone in its seats file: {line}") - elif seat := SEAT_LINE.match(line): + if seat := SEAT_LINE.match(line): if seat.group(1) in [known.name for known in seats]: return Failure(f"{seat.group(1)} appears twice in the seats file") seats.append(Seat(seat.group(1), seat.group(2).strip(), [])) @@ -56,13 +37,13 @@ def report(text: str) -> Report | Failure: seats[-1].places[-1] += " " + line.strip() else: return Failure(f"the seats file has a line that is neither a seat's line, opening with one of {', '.join(SCORING_SEATS)} and a colon, nor one of its places: {line}") - return Report(lines[0].strip(), seats, moved_mean) + return SeatsFile(lines[0].strip(), seats) def scores(seats: list[Seat]) -> dict[str, list[str]] | Failure: """Each seat's five scores as written, in DIMENSIONS' order.""" if [seat.name for seat in seats] != list(SCORING_SEATS): - return Failure(f"a scoring run's seats are {', '.join(SCORING_SEATS)}, in that order, or a {MEAN} line alone; the file has {', '.join(seat.name for seat in seats) or 'none'}") + return Failure(f"a scoring run's seats are {', '.join(SCORING_SEATS)}, in that order; the file has {', '.join(seat.name for seat in seats) or 'none'}") found = {} for seat in seats: values = score_line(seat.name, seat.said) diff --git a/bin/metric_bench/bench.py b/bin/metric_bench/bench.py index 4beda4a5..3f5b640b 100644 --- a/bin/metric_bench/bench.py +++ b/bin/metric_bench/bench.py @@ -4,7 +4,7 @@ import dataclasses import os import statistics -from larv_review.history import Place +from comprehension_history import Place from metric_bench.python_units import Unit METRICS: dict[str, Callable[[Unit, dict[str, int]], int]] = { diff --git a/bin/metric_bench/main.py b/bin/metric_bench/main.py index 6b071534..ed71e097 100644 --- a/bin/metric_bench/main.py +++ b/bin/metric_bench/main.py @@ -35,7 +35,7 @@ import subprocess import sys from metric_bench.bench import bench, co_changed, medians, METRICS, resolved, RunScores, Score -from larv_review.history import entries, Entry +from comprehension_history import entries, Entry from failure import Failure from metric_bench.python_units import measured, python_units, Unit diff --git a/bin/test_larv_review.py b/bin/test_larv_review.py index 12bb6300..1559736d 100644 --- a/bin/test_larv_review.py +++ b/bin/test_larv_review.py @@ -9,15 +9,16 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) -from larv_review.history import appended, entries, HistoryChange, Place, ruling_entry +from comprehension_history import appended, entries, Place, ruling_entry, Scoring, Seat from larv_review.base import base, first_ruling, measured_commit -from larv_review.scoring import chunk_entries, fall, fall_outcome, fall_reasons, means, plan_items, scoring_run_due, under_floor from larv_review.ruling import counted, fallen, ruling, votes from failure import Failure +from larv_review.scoring import fall_ruling, means, plan_items, scoring_run_due, under_floor +from larv_review.git import HistoryChange from test_loop_claude_black_box import host_env from rank_todo import Item -from larv_review.seats import report, score_line, scores, Seat from larv_review.rounds import round_counts +from larv_review.seats import score_line, scores, seats_file TOOL = pathlib.Path(__file__).resolve().parent / "larv-review" SCORING = "## 2026-10-08T12:00:00Z, PR #1 at aaaaaaa\n\n| Seat | Overall |\n|---|---|\n| Mean | 7.00 |\n" @@ -41,14 +42,14 @@ def todo(*rows: str) -> str: class Seats(unittest.TestCase): def test_reads_each_seats_line_and_places_and_joins_a_wrapped_place(self): - given = report(f"PR #2 at abc1234, against def5678\n\nMid A: {said('worse')}\n\n- `a.py:1` `f`: hard\n to read\n\nInherited architect: {said('same')}\n") + given = seats_file(f"PR #2 at abc1234, against def5678\n\nMid A: {said('worse')}\n\n- `a.py:1` `f`: hard\n to read\n\nInherited architect: {said('same')}\n") self.assertEqual(given.read, "PR #2 at abc1234, against def5678") self.assertEqual(given.seats, [Seat("Mid A", said("worse"), ["`a.py:1` `f`: hard to read"]), Seat("Inherited architect", said("same"), [])]) def test_refuses_a_line_that_is_neither_a_seat_nor_a_place_and_a_seat_twice(self): - self.assertIsInstance(report("PR #2 at abc1234\n\nMid A worse\n"), Failure) - self.assertIsInstance(report("PR #2 at abc1234\n\nMid A: worse\n\nMid A: same\n"), Failure) - self.assertIsInstance(report(""), Failure) + self.assertIsInstance(seats_file("PR #2 at abc1234\n\nMid A worse\n"), Failure) + self.assertIsInstance(seats_file("PR #2 at abc1234\n\nMid A: worse\n\nMid A: same\n"), Failure) + self.assertIsInstance(seats_file(""), Failure) def test_counts_each_vote_of_a_seat_naming_no_place_as_same(self): seats = [Seat("Mid A", said("worse", "worse"), ["Locality: the whole skill"]), Seat("Inherited architect", said("better"), ["Overall: `a.py:3` `f`: shorter"])] @@ -80,11 +81,6 @@ class Seats(unittest.TestCase): four = {name: ["same", vote, "same", "same", "better"] for name, vote in (("Mid A", "worse"), ("Inherited architect", "same"), ("Maintainability senior", "worse"), ("Junior A", "worse"))} self.assertEqual(fallen(four), ["Locality"]) self.assertEqual(fallen({**four, "Junior A": ["same", "better", "same", "same", "better"]}), []) - found = [decimal.Decimal(score) for score in ("6", "6.5", "7", "6", "6")] - ratchet = "Ratchet: the paired ruling counts as worse, as Locality and Shape fell and Locality is 6.5, under the floor of 7.0." - self.assertEqual(fall_outcome(["Locality", "Shape"], found), (ratchet, [ratchet])) - self.assertEqual(fall_outcome(["Shape"], found), ("The paired ruling stands: Shape fell and each stays at or above the floor of 7.0.", [])) - self.assertIsNone(fall_outcome([], found)) def test_rules_by_a_lead_of_two_and_splits_two_seats_that_differ(self): cases = [ @@ -120,39 +116,24 @@ class History(unittest.TestCase): def test_reads_back_what_it_writes(self): seats = [Seat("Mid A", said("better", "worse"), ["`bin/a.py:3` `f`: hard, with `:9` `g`"]), Seat("Inherited architect", said("worse", "worse"), [])] written = {"Mid A": ["same", "worse", "same", "same", "better"], "Inherited architect": ["same", "worse", "same", "same", "worse"]} - ruled = ruling_entry("2026-10-08T18:37:21Z, PR #2 at bbbbbbb, against aaaaaaa", seats, written, {**written, "Inherited architect": ["same"] * 5}, "better", ["Locality"]) + scoring = Scoring([Seat("Junior A", "", ["`bin/b.py:4` `h`: long"])], {"Junior A": ["7", "6.5", "7", "7", "7"]}, ["7.00", "6.50", "7.00", "7.00", "7.00"]) + ruled = ruling_entry("2026-10-08T18:37:21Z, PR #2 at bbbbbbb, against aaaaaaa", seats, written, {**written, "Inherited architect": ["same"] * 5}, ["Ruling: worse", "Fell: Locality, under the floor."], scoring) history = appended(appended("", SCORING), ruled) self.assertTrue(history.startswith("# Comprehension history\n\n## 2026-10-08T12:00:00Z")) self.assertNotIn("Inherited architect, decided by:", history) self.assertIn("| Inherited architect | same | same (voted worse, no place naming Locality) | same | same | same (voted worse, naming no place) |", history) found = entries(history) - self.assertEqual([(entry.commit, entry.against, entry.ruling, entry.fell) for entry in found], [("aaaaaaa", None, None, []), ("bbbbbbb", "aaaaaaa", "better", ["Locality"])]) - self.assertEqual(found[1].places, [Place("bin/a.py", "f"), Place("bin/a.py", "g")]) + self.assertEqual([(entry.commit, entry.against, entry.ruling) for entry in found], [("aaaaaaa", None, None), ("bbbbbbb", "aaaaaaa", "worse")]) + self.assertEqual(found[1].places, [Place("bin/a.py", "f"), Place("bin/a.py", "g"), Place("bin/b.py", "h")]) + self.assertIn("| Mean | 7.00 | 6.50 | 7.00 | 7.00 | 7.00 |\n\nMid A, decided by:", history) self.assertEqual([entry.paired for entry in found], [False, True]) -class FallState(unittest.TestCase): - def test_gives_the_fall_its_own_reason_outside_the_plans(self): - plan = [item(1, (0, 1, 0)), item(2, (0, 1, 0))] - self.assertEqual(scoring_run_due(plan, plan, [], True), []) - self.assertEqual(fall_reasons(fall(chunk_entries("", paired("2026-10-08T13:00:00Z", "same\n\nFell: Locality")))), ["has a paired ruling in which Locality fell"]) - - def test_finds_a_fall_in_the_newest_entry_when_it_is_a_better_ruling(self): - fell = paired("2026-10-08T13:00:00Z", "better\n\nFell: Locality,Shape") - self.assertEqual(fall(chunk_entries("", SCORING + fell)).pending, ["Locality", "Shape"]) - later = SCORING.replace("12:00:00Z", "14:00:00Z").replace("| Mean | 7.00 |", "Ratchet: worse.\n\n| Mean | 7.00 |") - self.assertEqual(fall(chunk_entries("", fell + later)).pending, []) - self.assertEqual(fall(chunk_entries("", fell + later)).ratchet, "Ratchet: worse.") - self.assertEqual(fall(chunk_entries("", SCORING + paired("2026-10-08T13:00:00Z", "same\n\nFell: Locality"))).pending, ["Locality"]) - self.assertEqual(fall(chunk_entries("", "")).pending, []) - rescored = SCORING.replace("12:00:00Z", "15:00:00Z") - self.assertEqual(fall(chunk_entries("", fell + later + rescored)).ratchet, "Ratchet: worse.") - self.assertIsNone(fall(chunk_entries("", fell + later + paired("2026-10-08T16:00:00Z", "same"))).ratchet) - - def test_reads_only_the_entries_the_default_branch_lacks(self): - fell = paired("2026-10-08T13:00:00Z", "better\n\nFell: Locality") - merged = SCORING.replace("12:00:00Z", "14:00:00Z").replace("PR #1", "PR #9") - self.assertEqual(fall(chunk_entries(merged, fell + merged)).pending, ["Locality"]) +class FallRuling(unittest.TestCase): + def test_counts_a_ruling_worse_when_a_fallen_dimensions_mean_is_under_the_floor(self): + found = [decimal.Decimal(score) for score in ("6", "6.5", "7", "6", "6")] + self.assertEqual(fall_ruling("better", ["Locality", "Shape"], found), ("worse", "Fell: Locality, Shape, under the floor of 7.0 at Locality 6.5, so the better ruling counts as worse.")) + self.assertEqual(fall_ruling("same", ["Shape"], found), ("same", "Fell: Shape, each at or above the floor of 7.0, so the same ruling stands.")) class Base(unittest.TestCase): @@ -166,11 +147,6 @@ class Base(unittest.TestCase): worse_last = HistoryChange("worse", SCORING, SCORING + paired("2026-10-08T13:00:00Z", "better") + paired("2026-10-08T14:00:00Z", "worse")) self.assertEqual(measured_commit([worse_last, older]), "old") self.assertIsNone(measured_commit([same])) - run = SCORING.replace("12:00:00Z", "14:00:00Z").replace("PR #1", "PR #2") - same_fell = HistoryChange("same fell", SCORING, SCORING + paired("2026-10-08T13:00:00Z", "same\n\nFell: Locality") + run) - self.assertEqual(measured_commit([same_fell, older]), "old") - better_fell = HistoryChange("better fell", SCORING, SCORING + paired("2026-10-08T13:00:00Z", "better\n\nFell: Locality") + run) - self.assertEqual(measured_commit([better_fell, older]), "better fell") def test_falls_back_to_the_first_rulings_base_then_to_none(self): ruled = paired("2026-10-08T13:00:00Z", "worse") @@ -249,8 +225,8 @@ class LarvReviewTool(unittest.TestCase): def run_tool(self, *args): return subprocess.run([sys.executable, str(TOOL), *args], capture_output=True, cwd=self.checkout, env=self.env, text=True) - def seats_file(self, text): - path = self.checkout.parent / "seats.md" + def seats_file(self, text, name="seats.md"): + path = self.checkout.parent / name path.write_text(textwrap.dedent(text)) return str(path) @@ -309,45 +285,41 @@ class LarvReviewTool(unittest.TestCase): self.assertEqual(recorded[0].places, [Place("bin/a.py", "f")] * 2) self.assertIn("| Junior A | same | same | same | same | same (voted worse, naming no place) |", history.read_text()) - def test_holds_a_better_ruling_that_hides_a_fall_until_a_scoring_run_decides_it(self): + def test_asks_for_the_scoring_seats_when_a_dimension_falls_and_rules_with_their_scores(self): place = "\n\n- Locality, Overall: `bin/a.py:3` `f`: shorter\n\n" - ran = self.run_tool("record-ruling", self.seats_file(f"PR #2 at {self.start}, against {self.start}\n\nMid A: {said('better', 'worse')}{place}Inherited architect: {said('better', 'worse')}{place}")) - self.assertEqual(ran.returncode, 0, ran.stderr) - self.assertIn("Fell: Locality. A scoring run is due", ran.stdout) - self.assertEqual(self.run_tool("needs-scoring-run", "2").stdout, "Scoring run due: the chunk has a paired ruling in which Locality fell.\n") + votes_file = self.seats_file(f"PR #2 at {self.start}, against {self.start}\n\nMid A: {said('better', 'worse')}{place}Inherited architect: {said('better', 'worse')}{place}", "votes.md") + asked = self.run_tool("record-ruling", votes_file) + self.assertEqual(asked.returncode, 0, asked.stderr) + self.assertTrue(asked.stdout.startswith(f"Fell: Locality, in a better ruling. Launch the four scoring seats on PR #2 at {self.start},")) + history = self.checkout / "docs" / "comprehension-history.md" + self.assertFalse(history.exists()) line = "Navigation 7, Locality 6.5, Shape 7, Self-sufficiency 7, Overall 7" - seats = "".join(f"\n{seat}: {line}\n" for seat in ("Junior A", "Mid A", "Maintainability senior", "Inherited architect")) - scored = self.run_tool("record-scoring", self.seats_file(f"PR #2 at {self.start}\n" + seats)) - self.assertIn("Ratchet: the paired ruling counts as worse, as Locality fell and Locality is 6.50, under the floor of 7.0.", scored.stdout) - self.assertIn("blocking nothing, as only a fall called this run: Locality 6.50.", scored.stdout) + scores_text = f"PR #2 at {self.start}\n" + "".join(f"\n{seat}: {line}\n\n- `bin/b.py:4` `h`: long\n" for seat in ("Junior A", "Mid A", "Maintainability senior", "Inherited architect")) + ruled = self.run_tool("record-ruling", votes_file, self.seats_file(scores_text, "scores.md")) + self.assertEqual(ruled.returncode, 0, ruled.stderr) + self.assertTrue(ruled.stdout.startswith("Ruling: worse. Fell: Locality, under the floor of 7.0 at Locality 6.50, so the better ruling counts as worse.")) + recorded = entries(history.read_text()) + self.assertEqual([entry.ruling for entry in recorded], ["worse"]) + self.assertIn("| Mean | 7.00 | 6.50 | 7.00 | 7.00 | 7.00 |", history.read_text()) + stands = self.run_tool("record-ruling", votes_file, self.seats_file(scores_text.replace("Locality 6.5", "Locality 7"), "scores.md")) + self.assertTrue(stands.stdout.startswith("Ruling: better. Fell: Locality, each at or above the floor of 7.0, so the better ruling stands."), stands.stderr) + other = self.run_tool("record-ruling", votes_file, self.seats_file(scores_text.replace("PR #2", "PR #3"), "scores.md")) + self.assertIn("the scores file's first line is not", other.stderr) - self.assertIn("\n\nRatchet: the paired ruling counts as worse", (self.checkout / "docs" / "comprehension-history.md").read_text()) - self.assertTrue(self.run_tool("needs-scoring-run", "2").stdout.startswith("No scoring run due.\nStill standing: Ratchet:")) - again = self.run_tool("record-scoring", self.seats_file(f"PR #2 at {self.start}\n" + seats)) - self.assertIn("already a scoring run; record a paired ruling first", again.stderr) - same = self.run_tool("record-ruling", self.seats_file(f"PR #3 at {self.start}, against {self.start}\n\nMid A: {said('same', 'worse')}{place}Inherited architect: {said('same', 'worse')}{place}")) - self.assertIn("Fell: Locality.", same.stdout, same.stderr) - stands = self.run_tool("record-scoring", self.seats_file(f"PR #2 at {self.start}\n" + seats.replace("Locality 6.5", "Locality 7"))) - self.assertIn("The paired ruling stands: Locality fell and each stays at or above the floor of 7.0.", stands.stdout) - - def test_names_no_fall_on_a_worse_ruling(self): + def test_names_no_fall_on_a_worse_ruling_and_takes_no_scores_file_without_one(self): place = "\n\n- Locality, Overall: `bin/a.py:3` `f`: longer\n\n" ran = self.run_tool("record-ruling", self.seats_file(f"PR #2 at {self.start}, against {self.start}\n\nMid A: {said('worse', 'worse')}{place}Inherited architect: {said('worse', 'worse')}{place}")) self.assertEqual(ran.returncode, 0, ran.stderr) self.assertNotIn("Fell:", ran.stdout + (self.checkout / "docs" / "comprehension-history.md").read_text()) + extra = self.run_tool("record-ruling", self.seats_file(f"PR #2 at {self.start}, against {self.start}\n\nMid A: {said('worse')}{place}Inherited architect: {said('worse')}{place}"), self.seats_file("PR #2", "scores.md")) + self.assertIn("takes no scores file", extra.stderr) def test_records_a_scoring_run_with_its_means(self): line = "Navigation 7, Locality 6.5, Shape 7, Self-sufficiency 6.5, Overall 7" seats = "".join(f"\n{seat}: {line}\n\n- `bin/a.py:3` `f`: long\n" for seat in ("Junior A", "Mid A", "Maintainability senior", "Inherited architect")) - uncalled = self.run_tool("record-scoring", self.seats_file(f"PR #2 at {self.start}\n" + seats)) - self.assertEqual(uncalled.returncode, 1) - self.assertIn("name the item IDs the chunk ships", uncalled.stderr) - due = self.run_tool("record-scoring", self.seats_file(f"PR #3 at {self.start}\n" + seats), "1") - self.assertEqual(due.returncode, 0, due.stderr) - self.assertIn("\nItem IDs read: 1.\nFloor: Locality 6.50, Self-sufficiency 6.50 under the floor of 7.0 block the merge, as the chunk leaves release 0.1.0 with no plan item.\n", due.stdout) - swapped = self.run_tool("record-scoring", "1", self.seats_file(f"PR #3 at {self.start}\n" + seats)) - self.assertEqual(swapped.returncode, 1) - self.assertIn("not /", swapped.stderr) + ran = self.run_tool("record-scoring", self.seats_file(f"PR #2 at {self.start}\n" + seats)) + self.assertEqual(ran.returncode, 0, ran.stderr) + self.assertIn("\nFloor: Locality 6.50, Self-sufficiency 6.50 under the floor of 7.0 block the merge.\n", ran.stdout) text = (self.checkout / "docs" / "comprehension-history.md").read_text() self.assertIn("| Mean | 7.00 | 6.50 | 7.00 | 6.50 | 7.00 |", text) self.assertIn("Inherited architect, would restructure first:", text) @@ -361,13 +333,6 @@ class LarvReviewTool(unittest.TestCase): self.assertEqual(lacking.returncode, 1) self.assertIn("abcdef1, which is no commit", lacking.stderr) - def test_moves_a_dated_mean_from_a_decision_entry_as_a_scoring_run(self): - mean = "Mean: Navigation 7.38, Locality 6.63, Shape 7.0, Self-sufficiency 6.88, Overall 6.88\n" - ran = self.run_tool("record-scoring", self.seats_file(f"2026-10-04, PR #1 merged at {self.start}\n\n{mean}")) - self.assertEqual(ran.returncode, 0, ran.stderr) - text = (self.checkout / "docs" / "comprehension-history.md").read_text() - self.assertIn(f"## 2026-10-04, PR #1 merged at {self.start}\n\n| Seat | Navigation | Locality | Shape | Self-sufficiency | Overall |\n|---|---|---|---|---|---|\n| Mean | 7.38 | 6.63 | 7.00 | 6.88 | 6.88 |\n", text) - def test_states_its_rules_and_finds_origins_default_branch_where_the_clone_recorded_none(self): helped = self.run_tool("--help") self.assertEqual(helped.returncode, 0, helped.stderr) @@ -375,13 +340,6 @@ class LarvReviewTool(unittest.TestCase): self.git("remote", "set-head", "origin", "--delete") self.assertEqual(self.run_tool("needs-scoring-run", "2").stdout, "No scoring run due.\n") - def test_refuses_a_dated_first_line_except_for_a_mean_alone_and_a_mean_without_one(self): - mean = "Mean: Navigation 7, Locality 7, Shape 7, Self-sufficiency 7, Overall 7\n" - self.assertEqual(self.run_tool("record-scoring", self.seats_file(f"PR #1 at {self.start}\n\n{mean}")).returncode, 1) - ruled = self.run_tool("record-ruling", self.seats_file(f"2026-10-08, PR #2 at {self.start}, against {self.start}\n\nMid A: {said('same')}\n\nInherited architect: {said('same')}\n")) - self.assertEqual(ruled.returncode, 1) - self.assertIn("only a seats file holding a Mean line alone", ruled.stderr) - def test_takes_a_local_main_without_origin_and_reads_origin_as_last_fetched_when_the_fetch_fails(self): self.commit("Answer prose round 1: a") self.git("remote", "set-url", "origin", str(self.checkout.parent / "gone.git")) diff --git a/bin/test_metric_bench.py b/bin/test_metric_bench.py index b302342b..318a101e 100644 --- a/bin/test_metric_bench.py +++ b/bin/test_metric_bench.py @@ -11,7 +11,7 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) from metric_bench.bench import auc, bench, co_changed, resolved, top_k from metric_bench.python_units import cognitive, measured, python_units, Unit -from larv_review.history import entries, Place +from comprehension_history import entries, Place from failure import Failure from test_loop_claude_black_box import host_env diff --git a/bin/test_types.py b/bin/test_types.py index 1a6b2c80..6a3d9129 100644 --- a/bin/test_types.py +++ b/bin/test_types.py @@ -11,5 +11,5 @@ class Types(unittest.TestCase): self.assertIsNotNone(floor, "README.md's Install names `Python 3.N or newer`") if shutil.which("uv") is None: self.fail("uv on PATH fetches mypy; see README.md's Test line") - ran = subprocess.run(["uv", "tool", "run", "--python", "%d.%d" % floor, "mypy==2.3.1", "--cache-dir=/dev/null", "--check-untyped-defs", "--disallow-untyped-defs", "-p", "larv_review", "-p", "loop_claude", "-p", "metric_bench", "-m", "rank_todo", "-p", "reading_cost", "-m", "statusline"], capture_output=True, cwd=ROOT / "bin", text=True) + ran = subprocess.run(["uv", "tool", "run", "--python", "%d.%d" % floor, "mypy==2.3.1", "--cache-dir=/dev/null", "--check-untyped-defs", "--disallow-untyped-defs", "-m", "comprehension_history", "-p", "larv_review", "-p", "loop_claude", "-p", "metric_bench", "-m", "rank_todo", "-p", "reading_cost", "-m", "statusline"], capture_output=True, cwd=ROOT / "bin", text=True) self.assertEqual(ran.returncode, 0, ran.stdout + ran.stderr) diff --git a/docs/decisions.md b/docs/decisions.md index 810eee11..6bf3cb33 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -69,7 +69,7 @@ lilleman decided to ship each of these under the floor on the day listed. Each l 2026-10-08, lilleman. Serves goals 1.1 and 1.4. Two independent four-seat runs moved up to 0.4 on near-identical code, so a fall within that noise forced rounds that changed nothing (PR #224). A seat reading both versions judges the difference on the same material, so the noise the versions share cancels. No conventional significance level lets a sign test settle with four votes, so the human chose a lead of two votes over every other ruling, same included. Two seats that agree settle it, so a PR that leaves the reading as it was costs two seats. A third seat alone can never settle it, so the third and fourth launch together. The base is the default branch's newest merged change whose last added paired ruling is better, or that adds a scoring run to the history while that ruling names no fall. The human chose the last measured commit on the architect's finding that with a merge base as the base, chunks without an architecture pass, and a suspended restructure's steps, could each lower comprehension unseen. A ruling of same leaves the base where it was, or a run of small falls each ruled same would add up unseen. A scoring run moves it too: otherwise a project never ruled better would compare against its first ruling forever, and a release's floor check is where the human sees the absolute level. Reading the default branch one merged change at a time keeps the rule working for merge commits and squash merges alike: a branch's own early ruling of better never counts, only the merged change's last ruling. The scoring run also runs on a chunk shipping an item that names the floor, so the chunk that lifts a project to the floor can prove it. A chunk that removes a release's last item without shipping it runs it too, so no release ends unmeasured. Valid while seats reading both versions agree more often than two absolute runs do. -2026-10-09, lilleman: each seat also rules each dimension, and a dimension falls by the same lead of two. A better or same ruling naming a fallen dimension calls the scoring run, and counts as worse when that dimension's mean is under the floor, so between releases a project cannot trade one dimension below the floor for gains in the other three. Such a run blocks on the fallen dimensions alone: the floor's own block stays with a release's end and an item naming the floor. Nor does it move the base, unless the ruling is better: a run of falls each ruled same must not add up unseen. A dimension's vote counts only where one of the seat's places opens with that dimension, so a fall rests on places the seats name. +2026-10-09, lilleman: each seat also rules each dimension, and a dimension falls by the same lead of two. A better or same ruling naming a fallen dimension calls the scoring run, and counts as worse when that dimension's mean is under the floor, so between releases a project cannot trade one dimension below the floor for gains in the other three. The four scoring seats' scores go into the ruling itself, which `record-ruling` decides in one call, so no command reads a fall another command recorded. Those scores block on the fallen dimensions alone, the floor's own block staying with a release's end and an item naming the floor, and they leave the base where the ruling leaves it: a run of falls each ruled same must not add up unseen. A dimension's vote counts only where one of the seat's places opens with that dimension, so a fall rests on places the seats name. ## review: a project decision may suspend the comprehension check for the plan items it names diff --git a/skills/larv-review/SKILL.md b/skills/larv-review/SKILL.md index 57b65dc5..84b3f07d 100644 --- a/skills/larv-review/SKILL.md +++ b/skills/larv-review/SKILL.md @@ -94,27 +94,25 @@ Then the comprehension check: simulated readers, launched per `~/.claude/skills/ - **Base.** The last measured commit, which `~/.claude/bin/larv-review ruling-base` prints. - **Head.** Before each ruling, merge `origin/` into this branch unless the head already holds it, so the seats see only this branch's change on top of the base. -- **Seats.** Mid A and the inherited architect. Write what they read and their replies into a seats file in your scratchpad, in the shape `~/.claude/bin/larv-review --help` shows, and run `~/.claude/bin/larv-review record-ruling `. On `Split:`, launch the maintainability senior and Junior A together, add their lines, and run it again. -- **Ruling.** The `Ruling:` line `record-ruling` prints and appends to the history. A better or same ruling may carry a `Fell:` line naming dimensions the seats ruled worse; a scoring run then decides whether it stands. +- **Seats.** Mid A and the inherited architect. Write what they read and their replies into a votes file in your scratchpad, in the shape `~/.claude/bin/larv-review --help` shows, and run `~/.claude/bin/larv-review record-ruling `. On `Split:`, launch the maintainability senior and Junior A together, add their lines, and run it again. On `Fell:`, launch the four scoring seats, below, on the same commit, write their lines into a scores file, and run `record-ruling `. +- **Ruling.** The `Ruling:` line `record-ruling` prints and appends to the history. -**Scoring run**, when `~/.claude/bin/larv-review needs-scoring-run ` prints `Scoring run due:`. Run `needs-scoring-run` after the paired ruling and before removing the chunk's items from `todo.md`. Junior A, Mid A, the maintainability senior and the inherited architect each score the project at the head from 1 to 10 overall and on four dimensions: Navigation, Locality, Shape and Self-sufficiency. Write their lines into a seats file and run `~/.claude/bin/larv-review record-scoring `, which appends the run to the history and prints the four seats' means. +**Scoring run**, when `~/.claude/bin/larv-review needs-scoring-run ` prints `Scoring run due:`. Run `needs-scoring-run` before removing the chunk's items from `todo.md`. Junior A, Mid A, the maintainability senior and the inherited architect each score the project at the head from 1 to 10 overall and on four dimensions: Navigation, Locality, Shape and Self-sufficiency. Write their lines into a scores file and run `~/.claude/bin/larv-review record-scoring `, which appends the run to the history and prints the four seats' means. The chunk does not merge while either holds: -- **Ratchet.** The paired ruling is worse, or `record-scoring` prints `Ratchet:`, because a dimension that fell is under the floor. `needs-scoring-run` repeats that line, prefixed with `Still standing:`, until a paired ruling follows it. +- **Ratchet.** The paired ruling is worse. - **Floor.** `record-scoring` prints `Floor:`, naming means under the floor of 7.0. Each is a ๐Ÿ”ด of the comprehension check. It is never filed, and stands until a later run clears it or, for the floor, a decision to ship answers it. -Fix a worse ruling at the places the seats voting worse name, a fallen dimension at the places that open with it, and the floor at the places the seats name under the lowest dimension. When only the Floor bullet holds, the user may decide to ship instead. A decision that lets every chunk ship under the floor, held in the project's `docs/decisions.md` before the chunk began, counts as theirs while it stands. A decision to ship listed in the `comprehension floor:` entry covers only the chunk it names. No user reachable โ†’ fix. A worse ruling never ships: after three rounds, "Round cap" โ†’ "Cap" asks the user for another round. +Fix a worse ruling at the places the seats voting worse name, or, where a fallen dimension made it worse, at the places that open with that dimension, and the floor at the places the seats name under the lowest dimension. When only the Floor bullet holds, the user may decide to ship instead. A decision that lets every chunk ship under the floor, held in the project's `docs/decisions.md` before the chunk began, counts as theirs while it stands. A decision to ship listed in the `comprehension floor:` entry covers only the chunk it names. No user reachable โ†’ fix. A worse ruling never ships: after three rounds, "Round cap" โ†’ "Cap" asks the user for another round. Two files of the project keep the records: - **History.** `docs/comprehension-history.md` keeps every paired ruling and scoring run, which `larv-review` appends; never edit one. Appending re-enters no pass. Resolve a merge conflict in the file by putting the default branch's entries first. - **Entry.** `docs/decisions.md` keeps one entry whose title opens `comprehension floor:`. It holds each decision to ship under the floor, with its scores. -A `comprehension floor:` entry written before the history may still hold a scoring run's five scores. The next scoring run moves them, and only them, into the history as its first run. Write a seats file of two lines and run `~/.claude/bin/larv-review record-scoring` on it. The first line is `, at `, the commit being the one the entry names, or else the one that wrote those scores into it. The second is `Mean:` and the five scores, in the shape `--help` shows. The rest of the entry stays. - Put each ruling with its base and votes, and each run's five scores, in the summary. List in the entry each decision to ship under the floor, and file its places in `todo.md` per `~/.claude/CLAUDE.md` โ†’ "Todo items". A project without the entry gets it at its first scoring run, titled `comprehension floor: every dimension and the overall at 7.0 or above` and applying KISS (`~/.claude/principles/technical-principles.md`). **Fresh.** Where the chunk ran a comprehension check, the architecture pass is done only once its last paired ruling, and its last scoring run where one is due, read the commit to merge. They may predate commits that change only `docs/decisions.md`, `docs/comprehension-history.md`, `docs/reading-cost.md`, `todo.md` or `CHANGELOG.md`. Any other commit after them, a prose fix included, because the seats read the docs, calls for a rescore: the comprehension check again, once every other pass is done, the auto-reviewer included. A rescore reporting a ๐Ÿ”ด that no decision to ship answers is an architecture round. Any other rescore is not a round: append only its results to the history, in a commit titled `Rescore: โ€ฆ`. A `Rescore:` commit re-enters no pass: push it and wait for the forge's checks (ยง4 step 3), not for an auto-review. diff --git a/todo.md b/todo.md index 47261aa8..b80efa2e 100644 --- a/todo.md +++ b/todo.md @@ -66,6 +66,9 @@ Raised by the principles audit of PR #215 against KISS, in `principles/technical PR #225's last run, at 8c9bf09, put Locality at 6.75 and Self-sufficiency and the overall at 6.88. Its seats named: the judge's policy spread over `loop/main.py`'s docstring, `cycle/judge_reply.py`'s `JUDGE_RULES`, `cycle/judge.py`'s `judge_prompt` and `cycle/worker.py`'s `worker_args`; `loop_claude/claude_code/` and the read side of `transcript_archive.py`, which `bin/reading_cost/` also imports; two meanings of a checkout's root in `project/checkout.py`'s `checkout_root` and `reading_cost/main.py`'s `located`; and `skills/larv-review/SKILL.md` ยง3's round count, which only prose enforces. + +2026-10-09, from the same studies: give the judge's contract one home. `cycle/judge.py` takes `judge_reply.py`'s rules, schema and `verdict_from`; `QUOTE_SOURCES`, `ANSWER_DESTINATIONS` and `ANSWERS_RECORDED` move to `project/records.py`, so `worker.py` imports the records, not the judge; `states.py`'s two `Judging` cases get exclusive guards, so their order carries no meaning. PR #232's scoring run at 324d650 put Locality at 6.50. + ### 21. Give `settings.json`'s model one writer, and sort its keys. Claude Code rewrites `"model"` in this tracked file whenever a model is picked, so one `/model` dirties the checkout and overrides the synced choice. @@ -92,6 +95,9 @@ Raised by the principles audit of PR #224. The `settings.json` decision is valid Raised by the architect on PR #225 and by the inherited architect of PR #224's scoring run: `bin/` is one flat folder of tools, the modules they share and the repo's checks, with `loop_claude`'s tests beside them instead of beside the package. `loop_claude/claude_code/` parses Claude Code's own formats and `bin/reading_cost/measure.py` imports it too, so it is a package of its own. + +2026-10-09, from two architecture studies on PR #232: lift `loop_claude/claude_code/` and the archive's layout out of `loop_claude/` into packages of their own, `claude_code/` and `transcript_archive/`, so `reading_cost` imports no tool. `transcript_archive` takes the write side (`archive`), the read side (`finished_chunks`, `FinishedChunk`, the stamps) and one `project_archive(checkout_root, home, env)` that both tools call, which derives the archive key one way, as item 5 asks. Move each tool's tests beside its package, and `test_loop_claude_black_box.host_env`, which three other tools' tests import, into a test helper of its own. + ### 5. Key a project on its checkout's full path, and refuse to start while another session uses that key. The key names the project's session, archive folder and models entry. `project_key` drops the leading `/`, so `~/code/a` and `/a` share all three, and one loop can resume or delete the other's session.