From 2c6e0633cf431db867989cc1cf7b9a0b756d11a1 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 9 Oct 2026 10:51:09 +0200 Subject: [PATCH 01/22] Rule each dimension in the paired ruling, and count a better ruling as worse when a dimension it rules fallen is under the floor --- AGENTS.md | 2 +- CHANGELOG.md | 1 + bin/larv_review/history.py | 26 ++--- bin/larv_review/main.py | 74 +++++++++----- bin/larv_review/rules.py | 49 ++++++--- bin/larv_review/seats.py | 8 ++ bin/test_larv_review.py | 109 ++++++++++++++------- docs/decisions.md | 4 +- skills/comprehension-panel/seat-prompts.md | 6 +- skills/larv-review/SKILL.md | 6 +- 10 files changed, 197 insertions(+), 88 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 0b47735c..4072baca 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -12,7 +12,7 @@ Decisions live in `docs/decisions.md`: - loop-claude: each project's model lives in `~/.claude/loop-claude-models.json`, which only loop-claude writes - review: a pass gets at most three rounds per chunk; instead of a fourth, the run asks the human - review: a fix for a ๐Ÿ”ด or ๐ŸŸก reruns the pass that found it and each pass whose trigger names fixes like it; a fix for a ๐ŸŸข, a โ“ or a prose finding reruns none -- review: a paired ruling against the last measured commit decides the ratchet; the four-seat scoring run checks the floor when a release's items run out or an item names the floor +- review: a paired ruling against the last measured commit decides the ratchet, and counts as worse when a dimension it rules fallen is under the floor; the four-seat scoring run checks the floor when a release's items run out, an item names the floor or a better ruling names a fallen dimension - review: a project decision may suspend the comprehension check for the plan items it names - review: a pass skips only on a precedent: a decision, or a plan item crediting the pass, that the repo held before the chunk began - loop-claude: the archive keeps the raw transcript, and a failed archive stops the loop diff --git a/CHANGELOG.md b/CHANGELOG.md index db6d64d4..8ef8f130 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- larv-review's paired ruling takes each seat's vote on each dimension too: `Navigation same, Locality worse, Shape same, Self-sufficiency same, Overall better`. A better ruling in which a dimension fell calls a scoring run, and counts as worse, blocking the merge, when that dimension's mean is under the floor. - 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`). 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. - 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 that added a scoring run to `docs/comprehension-history.md`, or whose last ruling there is better. 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; when they disagree, the maintainability senior and Junior A vote too. A ruling needs a lead of two or more votes, else it is same, and a vote that names no place counts as same. 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 the floor blocks nothing. 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. diff --git a/bin/larv_review/history.py b/bin/larv_review/history.py index 3e497d38..f5258f77 100644 --- a/bin/larv_review/history.py +++ b/bin/larv_review/history.py @@ -8,6 +8,7 @@ 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)?, ") DECIDED_BY = "decided by" +FELL = re.compile(r"^Fell: (.+)$", re.M) HARDEST_FIRST = "hardest first" HEADING = re.compile(r"^([^,]+), (.+) at ([0-9a-f]{7,40})(?:, against ([0-9a-f]{7,40}))?$") # `path:line` or `:line`, then the unit's name where one follows. @@ -27,12 +28,13 @@ class Place: @dataclasses.dataclass(frozen=True) class Entry: - """One paired ruling, which names the commit it was against and its ruling, or one scoring run, which names neither.""" + """One paired ruling, which names the commit it was against, its ruling and the dimensions that fell when it is better, or one scoring run, which names none of them.""" heading: str time: str commit: str against: str | None ruling: str | None + fell: list[str] places: list[Place] @property @@ -62,7 +64,8 @@ def entries(history: str) -> list[Entry]: if named := HEADING.match(heading): body = "\n".join(bodies) ruling = RULING.search(body) - found.append(Entry(heading, named.group(1), named.group(3), named.group(4), ruling.group(1) if ruling else None, seat_places(body))) + fell = FELL.search(body) + found.append(Entry(heading, named.group(1), named.group(3), named.group(4), ruling.group(1) if ruling else None, fell.group(1).split(", ") if fell else [], seat_places(body))) return found @@ -108,21 +111,22 @@ def appended(history: str, entry: str) -> str: return f"{text}\n{entry}" -def ruling_entry(title: str, seats: list[Seat], counted: dict[str, str], ruled: str) -> str: - """A paired ruling's entry; a seat's vote that counted as same for naming no place says so.""" - votes = [[seat.name, vote_text(seat, counted[seat.name])] for seat in seats] - return entry_text(title, [f"Ruling: {ruled}"], [["Seat", "Vote"], *votes], [(f"{seat.name}, {DECIDED_BY}:", seat.places) for seat in seats]) +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, with a `Fell:` line when it is better and fell names dimensions; a seat's vote that counted as same for naming no place says so.""" + votes = [[seat.name, *map(vote_text, said[seat.name], counted[seat.name])] for seat in seats] + lines = [f"Ruling: {ruled}"] + ([f"Fell: {', '.join(fell)}"] if ruled == "better" and fell else []) + return entry_text(title, lines, [["Seat", *DIMENSIONS], *votes], [(f"{seat.name}, {DECIDED_BY}:", seat.places) for seat in seats]) -def vote_text(seat: Seat, counted: str) -> str: - return counted if counted == seat.said else f"same (voted {seat.said}, naming no place)" +def vote_text(said: str, counted: str) -> str: + return counted if counted == said else f"same (voted {said}, naming no place)" -def scoring_entry(title: str, seats: list[Seat], scores: dict[str, list[str]], means: list[str]) -> str: - """A scoring run's entry; a run moved from a decision entry has its means alone.""" +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, [], [["Seat", *DIMENSIONS], *rows], labels) + return entry_text(title, lines, [["Seat", *DIMENSIONS], *rows], labels) def entry_text(title: str, lines: list[str], table: list[list[str]], seats: list[tuple[str, list[str]]]) -> str: diff --git a/bin/larv_review/main.py b/bin/larv_review/main.py index bd6dc2da..970832fa 100644 --- a/bin/larv_review/main.py +++ b/bin/larv_review/main.py @@ -20,7 +20,8 @@ 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.` 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 +an item whose tagline names the comprehension floor, when the checkout's history ends on a better +paired ruling with a `Fell:` line, 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 @@ -34,26 +35,30 @@ opens with its label, written exactly: `Junior A:`, `Mid A:`, `Maintainability s PR #231 at abc1234, against def5678 - Mid A: worse + Mid A: Navigation same, Locality worse, Shape same, Self-sufficiency same, Overall worse - `bin/x.py:12` `run`: three branches to hold at once - Inherited architect: worse + Inherited architect: Navigation same, Locality worse, Shape same, Self-sufficiency same, Overall worse - `bin/x.py:12` `run`: ... -record-ruling takes Mid A's and the inherited architect's votes, better, same or worse; a better or -worse vote naming no place in backticks, `path:line`, counts as same, and the printed votes say so. -When the two counted 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 vote that leads each -other vote by two or more, else same; it prints `Ruling:` and appends the ruling. +record-ruling takes Mid A's and the inherited architect's votes on each dimension and overall, +each better, same or worse. Each vote of a seat naming no place in backticks, `path:line`, counts +as same, and 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. On a better ruling, it prints and records a `Fell:` line naming each. record-scoring takes 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 and each one under the floor of {floor}. +decimals, and prints the means and each one under the floor of {floor}. When the history ends on a +better paired ruling with a `Fell:` line, it says whether the ruling stands; when a dimension that +fell is under the floor, the ruling counts as worse, and it prints and records a `Ratchet:` line. 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 @@ -71,7 +76,7 @@ import time import typing from larv_review.history import appended, heading, ruling_entry, scoring_entry, vote_text -from larv_review.rules import base, CAP, FLOOR, means, PASSES, plan_items, round_counts, ruling, scoring_run_due, under_floor, votes +from larv_review.rules import base, CAP, counted, fallen, fell_under_floor, FLOOR, means, PASSES, pending_fall, plan_items, round_counts, ruling, scoring_run_due, under_floor, votes from larv_review.git import commit_exists, default_branch, file_at, git, HISTORY, history_changes, landed_since_release, top from larv_review.seats import DIMENSIONS, MEAN, Report, report, score_line, scores from failure import Failure @@ -168,7 +173,10 @@ def needs_scoring_run(default: str, ids: list[int]) -> Failure | None: landed = landed_since_release(default) if isinstance(landed, Failure): return landed - reasons = scoring_run_due(planned, chunk, ids, landed) + history = history_text() + if isinstance(history, Failure): + return history + reasons = scoring_run_due(planned, chunk, ids, landed, pending_fall(history[1])) if isinstance(reasons, Failure): return reasons print(f"Scoring run due: the chunk {' and '.join(reasons)}." if reasons else "No scoring run due.") @@ -180,16 +188,20 @@ def record_ruling(seats_file: pathlib.Path) -> Failure | None: if isinstance(read, Failure): return read title, given = read - counted = votes(given.seats) - if isinstance(counted, Failure): - return counted - tally = ", ".join(f"{seat.name} {vote_text(seat, counted[seat.name])}" for seat in given.seats) - ruled = ruling(list(counted.values())) + said = votes(given.seats) + if isinstance(said, Failure): + return said + count = counted(given.seats, said) + tally = ", ".join(f"{seat.name} {vote_text(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.") return None - print(f"Ruling: {ruled}. Votes as counted: {tally}.") - return append(ruling_entry(title, given.seats, counted, ruled)) + fell = fallen(count) + print(f"Ruling: {ruled}. Overall votes as counted: {tally}.") + if ruled == "better" and fell: + print(f"Fell: {', '.join(fell)}. A scoring run is due; the ruling counts as worse if it puts {' or '.join(fell)} under the floor of {FLOOR}.") + return append(ruling_entry(title, given.seats, said, count, ruled, fell)) def record_scoring(seats_file: pathlib.Path) -> Failure | None: @@ -206,7 +218,14 @@ def record_scoring(seats_file: pathlib.Path) -> Failure | None: mean = means(list(found.values()) or [moved]) under = under_floor(mean) print(f"Means: {', '.join(f'{name} {value}' for name, value in zip(DIMENSIONS, mean))}. {f'Under the floor of {FLOOR}: ' + ', '.join(under) if under else f'None under the floor of {FLOOR}'}.") - return append(scoring_entry(title, given.seats, found, [str(value) for value in mean])) + history = history_text() + if isinstance(history, Failure): + return history + fell = [] if given.moved_mean else pending_fall(history[1]) + ratchet = [f"Ratchet: the paired ruling counts as worse, as {', '.join(dropped)} fell under the floor of {FLOOR}."] if (dropped := fell_under_floor(fell, mean)) else [] + if fell: + print(ratchet[0] if ratchet else f"The better paired ruling stands: {', '.join(fell)} fell and stays at or above the floor of {FLOOR}.") + return append(scoring_entry(title, given.seats, found, [str(value) for value in mean], ratchet)) def read_seats(seats_file: pathlib.Path, paired: bool) -> tuple[str, Report] | Failure: @@ -225,16 +244,27 @@ def read_seats(seats_file: pathlib.Path, paired: bool) -> tuple[str, Report] | F return named.title, given -def append(entry: str) -> Failure | None: +def history_text() -> tuple[pathlib.Path, str] | Failure: + """The checkout's history and its text, empty when the file is missing.""" checkout = top() if isinstance(checkout, Failure): return checkout history = pathlib.Path(checkout, HISTORY) try: - text = history.read_text(encoding="utf-8") if history.exists() else "" - history.parent.mkdir(parents=True, exist_ok=True) + return history, history.read_text(encoding="utf-8") if history.exists() else "" 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/rules.py b/bin/larv_review/rules.py index bce9be1f..d02bf4e7 100644 --- a/bin/larv_review/rules.py +++ b/bin/larv_review/rules.py @@ -1,7 +1,7 @@ import decimal import re -from larv_review.seats import DIMENSIONS, FIRST_SEATS, Seat, SPLIT_SEATS +from larv_review.seats import DIMENSIONS, FIRST_SEATS, Seat, SPLIT_SEATS, vote_line from larv_review.history import entries, Entry, HistoryChange, PLACE from failure import Failure from rank_todo import Item, ITEMS_HEADER, parse_row, table_rows @@ -13,18 +13,26 @@ ROUND = re.compile(r"^Answer (.+?) round ([0-9]+):") VOTES = ("better", "same", "worse") -def votes(seats: list[Seat]) -> dict[str, str] | Failure: - """Each seat's vote as it counts: a better or worse vote naming no `path:line` place counts as same.""" +def votes(seats: list[Seat]) -> dict[str, list[str]] | Failure: + """Each seat's five votes as written, in DIMENSIONS' order.""" names = [seat.name for seat in seats] if names[:2] != list(FIRST_SEATS) or names[2:] not in ([], list(SPLIT_SEATS)): - return Failure(f"a paired ruling's seats are {' and '.join(FIRST_SEATS)}, then, when their votes differ, {' and '.join(SPLIT_SEATS)}, in that order; the file has {', '.join(names) or 'none'}") - if unknown := [seat for seat in seats if seat.said not in VOTES]: - return Failure(f"{unknown[0].name}'s vote {unknown[0].said!r} is not better, same or worse") - counted = {seat.name: seat.said if names_a_place(seat) else "same" for seat in seats} - first, second, *more = counted.values() + return Failure(f"a paired ruling's seats are {' and '.join(FIRST_SEATS)}, then, when their overall votes differ, {' and '.join(SPLIT_SEATS)}, in that order; the file has {', '.join(names) or 'none'}") + said = {} + for seat in seats: + line = vote_line(seat.name, seat.said) + if isinstance(line, Failure): + return line + said[seat.name] = line + first, second, *more = (each[-1] for each in counted(seats, said).values()) if more and first == second: - return Failure(f"{' and '.join(FIRST_SEATS)} both count as {first}, which settles the ruling; drop the other seats' lines") - return counted + return Failure(f"{' and '.join(FIRST_SEATS)} both count as {first} overall, which settles the ruling; drop the other seats' lines") + return said + + +def counted(seats: list[Seat], said: dict[str, list[str]]) -> dict[str, list[str]]: + """Each seat's votes as they count: a seat naming no `path:line` place counts as same on each.""" + return {seat.name: said[seat.name] if names_a_place(seat) else ["same"] * len(DIMENSIONS) for seat in seats} def names_a_place(seat: Seat) -> bool: @@ -41,6 +49,21 @@ def ruling(counted: list[str]) -> str | None: return "same" +def fallen(counted: dict[str, list[str]]) -> list[str]: + """Each dimension, Overall aside, that the seats rule worse by a lead of two.""" + return [name for name, column in zip(DIMENSIONS[:-1], zip(*counted.values())) if ruling(list(column)) == "worse"] + + +def pending_fall(history: str) -> list[str]: + """The dimensions that fell in the history's newest entry, when it is a better paired ruling, so no scoring run has followed it. Of entries with one time, the later in the file is newer.""" + newest = max(enumerate(entries(history)), key=lambda indexed: (indexed[1].time, indexed[0]), default=None) + return newest[1].fell if newest and newest[1].ruling == "better" else [] + + +def fell_under_floor(fell: list[str], found: list[decimal.Decimal]) -> list[str]: + return [f"{name} {value}" for name, value in zip(DIMENSIONS, found) if name in fell and value < FLOOR] + + def means(lines: list[list[str]]) -> list[decimal.Decimal]: """The mean of each score across the lines, in DIMENSIONS' order, rounded half up to two decimals.""" return [mean([decimal.Decimal(score) for score in column]) for column in zip(*lines)] @@ -102,13 +125,15 @@ def plan_items(todo: str) -> list[Item] | Failure: return items -def scoring_run_due(before: list[Item], after: list[Item], ships: list[int], landed: bool) -> list[str] | Failure: - """Why the chunk takes a scoring run, empty when it does not. before is the default branch's plan, after the chunk's, ships the IDs it ships, and landed whether the default branch holds a commit after its newest release tag. Work has landed towards an emptied release when the chunk ships one of its items, or when it is the next release, the earliest before names, and landed holds.""" +def scoring_run_due(before: list[Item], after: list[Item], ships: list[int], landed: bool, fell: list[str]) -> list[str] | Failure: + """Why the chunk takes a scoring run, empty when it does not. before is the default branch's plan, after the chunk's, ships the IDs it ships, landed whether the default branch holds a commit after its newest release tag, and fell what pending_fall finds in the chunk's history. Work has landed towards an emptied release when the chunk ships one of its items, or when it is the next release, the earliest before names, and landed holds.""" plan = {item.id: item for item in before + after} if unknown := sorted(set(ships) - set(plan)): return Failure(f"neither plan holds item {', '.join(map(str, unknown))}") shipped = [plan[id_] for id_ in ships] reasons = [f"ships item {item.id}, which names the comprehension floor" for item in shipped if "comprehension floor" in item.tagline.lower()] + if fell: + reasons.append(f"has a better paired ruling in which {' and '.join(fell)} fell") next_release = min((item.release for item in before), default=None) for release in emptied(before, after, shipped): if any(item.release == release for item in shipped) or (release == next_release and landed): diff --git a/bin/larv_review/seats.py b/bin/larv_review/seats.py index 0f404dad..0c0791a1 100644 --- a/bin/larv_review/seats.py +++ b/bin/larv_review/seats.py @@ -17,6 +17,7 @@ FIRST_SEATS = (MID, ARCHITECT) SCORING_SEATS = (JUNIOR, MID, SENIOR, ARCHITECT) SEAT_LINE = re.compile(rf"^({'|'.join(SCORING_SEATS)}): (.+)$") SPLIT_SEATS = (SENIOR, JUNIOR) +VOTE_LINE = re.compile(", ".join(rf"{name} (better|same|worse)" for name in DIMENSIONS)) @dataclasses.dataclass(frozen=True) @@ -81,3 +82,10 @@ def score_line(name: str, said: str) -> list[str] | Failure: if values[-1] > min(values[:-1]) + 1: return Failure(f"{name}'s overall exceeds the lowest dimension by more than 1; ask the seat to rescore: {said}") return list(written.groups()) + + +def vote_line(name: str, said: str) -> list[str] | Failure: + """A paired seat's five votes, in DIMENSIONS' order.""" + if not (written := VOTE_LINE.fullmatch(said)): + return Failure(f"{name}'s line is not {', '.join(vote + ' ' for vote in DIMENSIONS)}: {said}") + return list(written.groups()) diff --git a/bin/test_larv_review.py b/bin/test_larv_review.py index 48dc243c..83bad3b2 100644 --- a/bin/test_larv_review.py +++ b/bin/test_larv_review.py @@ -10,7 +10,7 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) from larv_review.history import appended, entries, HistoryChange, Place, ruling_entry -from larv_review.rules import base, first_ruling, means, measured_commit, plan_items, round_counts, ruling, scoring_run_due, under_floor, votes +from larv_review.rules import base, counted, fallen, fell_under_floor, first_ruling, means, measured_commit, pending_fall, plan_items, round_counts, ruling, scoring_run_due, under_floor, votes from failure import Failure from test_loop_claude_black_box import host_env from rank_todo import Item @@ -24,6 +24,10 @@ def paired(time: str, verdict: str, commit: str = "bbbbbbb") -> str: return f"## {time}, PR #2 at {commit}, against aaaaaaa\n\nRuling: {verdict}\n" +def said(overall: str, locality: str = "same") -> str: + return f"Navigation same, Locality {locality}, Shape same, Self-sufficiency same, Overall {overall}" + + def item(id_: int, release: tuple[int, int, int], tagline: str = "**Do it.**") -> Item: return Item(id_, release, "", tagline, {"R": 1, "S": 1, "A": 1, "G": 1}, ("1",)) @@ -34,28 +38,38 @@ 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("PR #2 at abc1234, against def5678\n\nMid A: worse\n\n- `a.py:1` `f`: hard\n to read\n\nInherited architect: same\n") + 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") self.assertEqual(given.read, "PR #2 at abc1234, against def5678") - self.assertEqual(given.seats, [Seat("Mid A", "worse", ["`a.py:1` `f`: hard to read"]), Seat("Inherited architect", "same", [])]) + 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) - def test_counts_a_vote_naming_no_place_as_same(self): - seats = [Seat("Mid A", "worse", ["the whole skill"]), Seat("Inherited architect", "better", ["`a.py:3` `f`: shorter"])] - self.assertEqual(votes(seats), {"Mid A": "same", "Inherited architect": "better"}) + def test_counts_each_vote_of_a_seat_naming_no_place_as_same(self): + seats = [Seat("Mid A", said("worse", "worse"), ["the whole skill"]), Seat("Inherited architect", said("better"), ["`a.py:3` `f`: shorter"])] + written = votes(seats) + self.assertEqual(written, {"Mid A": ["same", "worse", "same", "same", "worse"], "Inherited architect": ["same", "same", "same", "same", "better"]}) + self.assertEqual(counted(seats, written)["Mid A"], ["same"] * 5) - def test_refuses_two_more_seats_once_the_first_two_agree(self): - seats = [Seat(name, vote, ["`f.py:1` `f`: x"]) for name, vote in (("Mid A", "worse"), ("Inherited architect", "worse"), ("Maintainability senior", "better"), ("Junior A", "better"))] + def test_refuses_two_more_seats_once_the_first_two_agree_overall(self): + seats = [Seat(name, said(vote), ["`f.py:1` `f`: x"]) for name, vote in (("Mid A", "worse"), ("Inherited architect", "worse"), ("Maintainability senior", "better"), ("Junior A", "better"))] self.assertIsInstance(votes(seats), Failure) - def test_takes_the_first_two_seats_then_the_other_two_in_order(self): - first = [Seat("Mid A", "same", []), Seat("Inherited architect", "same", [])] + def test_takes_the_first_two_seats_then_the_other_two_in_order_and_each_dimensions_vote(self): + first = [Seat("Mid A", said("same"), []), Seat("Inherited architect", said("same"), [])] self.assertIsInstance(votes(first[::-1]), Failure) - self.assertIsInstance(votes(first + [Seat("Junior A", "same", [])]), Failure) - self.assertIsInstance(votes([first[0], Seat("Inherited architect", "worst", [])]), Failure) + self.assertIsInstance(votes(first + [Seat("Junior A", said("same"), [])]), Failure) + self.assertIsInstance(votes([first[0], Seat("Inherited architect", said("worst"), [])]), Failure) + self.assertIsInstance(votes([first[0], Seat("Inherited architect", "same", [])]), Failure) + + def test_finds_each_dimension_ruled_worse_by_a_lead_of_two(self): + self.assertEqual(fallen({"Mid A": ["same", "worse", "worse", "same", "better"], "Inherited architect": ["same", "worse", "same", "same", "better"]}), ["Locality"]) + 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"]}), []) + self.assertEqual(fell_under_floor(["Locality", "Shape"], [decimal.Decimal(score) for score in ("6", "6.5", "7", "6", "6")]), ["Locality 6.5"]) def test_rules_by_a_lead_of_two_and_splits_two_seats_that_differ(self): cases = [ @@ -90,17 +104,27 @@ class Seats(unittest.TestCase): class History(unittest.TestCase): def test_reads_back_what_it_writes(self): seats = [Seat("Mid A", "worse", ["`bin/a.py:3` `f`: hard, with `:9` `g`"]), Seat("Inherited architect", "worse", [])] - ruled = ruling_entry("2026-10-08T18:37:21Z, PR #2 at bbbbbbb, against aaaaaaa", seats, {"Mid A": "worse", "Inherited architect": "same"}, "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"]) 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 (voted worse, naming no place) |", history) + self.assertIn("| Inherited architect | same | same (voted worse, naming no place) | same | same | same (voted worse, naming no place) |", history) found = entries(history) - self.assertEqual([(entry.commit, entry.against, entry.ruling) for entry in found], [("aaaaaaa", None, None), ("bbbbbbb", "aaaaaaa", "worse")]) + 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.paired for entry in found], [False, True]) +class PendingFall(unittest.TestCase): + 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(pending_fall(SCORING + fell), ["Locality", "Shape"]) + self.assertEqual(pending_fall(fell + SCORING.replace("12:00:00Z", "14:00:00Z")), []) + self.assertEqual(pending_fall(SCORING + paired("2026-10-08T13:00:00Z", "better")), []) + self.assertEqual(pending_fall(""), []) + + class Base(unittest.TestCase): def test_takes_the_newest_change_adding_a_scoring_run_or_ending_on_a_better_ruling(self): older = HistoryChange("old", "", SCORING) @@ -139,27 +163,31 @@ class ScoringRunDue(unittest.TestCase): def test_is_due_for_an_item_naming_the_floor(self): plan = [item(1, (0, 1, 0), "**Lift the project to the Comprehension floor.**"), item(2, (0, 1, 0))] - self.assertEqual(scoring_run_due(plan, plan, [1], True), ["ships item 1, which names the comprehension floor"]) - self.assertIsInstance(scoring_run_due(plan, plan, [9], True), Failure) + self.assertEqual(scoring_run_due(plan, plan, [1], True, []), ["ships item 1, which names the comprehension floor"]) + self.assertIsInstance(scoring_run_due(plan, plan, [9], True, []), Failure) def test_is_due_when_the_chunk_ships_a_releases_last_item(self): plan = [item(1, (0, 1, 0)), item(2, (0, 2, 0))] - self.assertEqual(scoring_run_due(plan, plan, [1], False), ["leaves release 0.1.0 with no plan item"]) - self.assertEqual(scoring_run_due(plan, plan + [item(3, (0, 1, 0))], [1], True), []) + self.assertEqual(scoring_run_due(plan, plan, [1], False, []), ["leaves release 0.1.0 with no plan item"]) + self.assertEqual(scoring_run_due(plan, plan + [item(3, (0, 1, 0))], [1], True, []), []) def test_is_due_when_the_chunk_removes_the_next_releases_last_item_after_work_landed(self): before = [item(1, (0, 1, 0)), item(2, (0, 1, 0)), item(3, (0, 2, 0))] after = [item(2, (0, 1, 0)), item(3, (0, 2, 0))] - self.assertEqual(scoring_run_due(before, after, [2], True), ["leaves release 0.1.0 with no plan item"]) - self.assertEqual(scoring_run_due(before, after, [], True), []) + self.assertEqual(scoring_run_due(before, after, [2], True, []), ["leaves release 0.1.0 with no plan item"]) + self.assertEqual(scoring_run_due(before, after, [], True, []), []) emptied = [item(3, (0, 2, 0))] - self.assertEqual(scoring_run_due(before, emptied, [2], False), ["leaves release 0.1.0 with no plan item"]) - self.assertEqual(scoring_run_due(before, emptied, [], True), ["leaves release 0.1.0 with no plan item"]) - self.assertEqual(scoring_run_due(before, emptied, [], False), []) + self.assertEqual(scoring_run_due(before, emptied, [2], False, []), ["leaves release 0.1.0 with no plan item"]) + self.assertEqual(scoring_run_due(before, emptied, [], True, []), ["leaves release 0.1.0 with no plan item"]) + self.assertEqual(scoring_run_due(before, emptied, [], False, []), []) + + def test_is_due_when_a_better_ruling_hides_a_fall(self): + plan = [item(1, (0, 1, 0)), item(2, (0, 1, 0))] + self.assertEqual(scoring_run_due(plan, plan, [], True, ["Locality"]), ["has a better paired ruling in which Locality fell"]) def test_is_not_due_when_a_later_release_loses_its_last_item_unshipped(self): before = [item(1, (0, 1, 0)), item(3, (0, 2, 0))] - self.assertEqual(scoring_run_due(before, before[:1], [], True), []) + self.assertEqual(scoring_run_due(before, before[:1], [], True, []), []) class LarvReviewTool(unittest.TestCase): @@ -230,25 +258,38 @@ class LarvReviewTool(unittest.TestCase): lines = """\ PR #2 at {start}, against {start} - Mid A: worse + Mid A: {worse} - `bin/a.py:3` `f`: three branches - Inherited architect: same + Inherited architect: {same} """ - lines = lines.replace("{start}", self.start) + lines = lines.replace("{start}", self.start).replace("{worse}", said("worse")).replace("{same}", said("same")) split = self.run_tool("record-ruling", self.seats_file(lines)) self.assertEqual(split.returncode, 0, split.stderr) self.assertTrue(split.stdout.startswith("Split: Mid A worse, Inherited architect same.")) history = self.checkout / "docs" / "comprehension-history.md" self.assertFalse(history.exists()) - lines += "\n\t\t\tMaintainability senior: worse\n\n\t\t\t- `bin/a.py:3` `f`: hard\n\n\t\t\tJunior A: worse\n" + lines += f"\n\t\t\tMaintainability senior: {said('worse')}\n\n\t\t\t- `bin/a.py:3` `f`: hard\n\n\t\t\tJunior A: {said('worse')}\n" ran = self.run_tool("record-ruling", self.seats_file(lines)) - self.assertEqual(ran.stdout.splitlines()[0], "Ruling: same. Votes as counted: Mid A worse, Inherited architect same, Maintainability senior worse, Junior A same (voted worse, naming no place).") + self.assertEqual(ran.stdout.splitlines()[0], "Ruling: same. Overall votes as counted: Mid A worse, Inherited architect same, Maintainability senior worse, Junior A same (voted worse, naming no place).") recorded = entries(history.read_text()) self.assertEqual([(entry.commit, entry.against, entry.ruling) for entry in recorded], [(self.start, self.start, "same")]) self.assertEqual(recorded[0].places, [Place("bin/a.py", "f")] * 2) - self.assertIn("| Junior A | same (voted worse, naming no place) |", history.read_text()) + 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): + place = "\n\n- `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 better paired ruling in which Locality fell.\n") + 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 6.50 fell under the floor of 7.0.", scored.stdout) + self.assertIn("\n\nRatchet: the paired ruling counts as worse", (self.checkout / "docs" / "comprehension-history.md").read_text()) + self.assertEqual(self.run_tool("needs-scoring-run", "2").stdout, "No scoring run due.\n") def test_records_a_scoring_run_with_its_means(self): line = "Navigation 7, Locality 6.5, Shape 7, Self-sufficiency 6.5, Overall 7" @@ -262,10 +303,10 @@ class LarvReviewTool(unittest.TestCase): self.assertEqual([entry.places for entry in entries(text)], [[Place("bin/a.py", "f")] * 4]) def test_refuses_a_ruling_file_that_names_no_base_or_a_commit_the_checkout_lacks(self): - ran = self.run_tool("record-ruling", self.seats_file(f"PR #2 at {self.start}\n\nMid A: same\n\nInherited architect: same\n")) + ran = self.run_tool("record-ruling", self.seats_file(f"PR #2 at {self.start}\n\nMid A: {said('same')}\n\nInherited architect: {said('same')}\n")) self.assertEqual(ran.returncode, 1) self.assertIn("against ", ran.stderr) - lacking = self.run_tool("record-ruling", self.seats_file(f"PR #2 at {self.start}, against abcdef1\n\nMid A: same\n\nInherited architect: same\n")) + lacking = self.run_tool("record-ruling", self.seats_file(f"PR #2 at {self.start}, against abcdef1\n\nMid A: {said('same')}\n\nInherited architect: {said('same')}\n")) self.assertEqual(lacking.returncode, 1) self.assertIn("abcdef1, which is no commit", lacking.stderr) @@ -286,7 +327,7 @@ class LarvReviewTool(unittest.TestCase): 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: same\n\nInherited architect: same\n")) + 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) diff --git a/docs/decisions.md b/docs/decisions.md index 477b7ee8..15d88834 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -65,9 +65,9 @@ lilleman decided to ship each of these under the floor on the day listed. Each l 2026-10-08, lilleman, replacing the 2026-09-30 rule that every fix, a nit's included, re-enters review. Serves goal 1.4. An audit of the four costliest archived chunks (2026-10-08) found nearly every finding that mattered in a pass's first round; later rounds mostly re-checked the last fix, reworded what an earlier round wrote, or contradicted another round on the same line. A round 2 caught real bugs only where a fix changed behaviour, so stability still reruns on every fix that does, and security on every fix that opens an untrusted-input boundary or touches authn/authz, secrets or crypto. Valid while round-2 reviews of nit and prose fixes keep changing nothing a user would notice. -## review: a paired ruling against the last measured commit decides the ratchet; the four-seat scoring run checks the floor when a release's items run out or an item names the floor +## review: a paired ruling against the last measured commit decides the ratchet, and counts as worse when a dimension it rules fallen is under the floor; the four-seat scoring run checks the floor when a release's items run out, an item names the floor or a better ruling names a fallen dimension -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 that adds a scoring run to the history, or whose last added paired ruling is better. 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-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 that adds a scoring run to the history, or whose last added paired ruling is better. 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. 2026-10-09, lilleman: each seat also rules each dimension, and a dimension falls by the same lead of two. A better 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. Valid while seats reading both versions agree more often than two absolute runs do. ## review: a project decision may suspend the comprehension check for the plan items it names diff --git a/skills/comprehension-panel/seat-prompts.md b/skills/comprehension-panel/seat-prompts.md index 45b9d64c..5e0cb2cc 100644 --- a/skills/comprehension-panel/seat-prompts.md +++ b/skills/comprehension-panel/seat-prompts.md @@ -84,11 +84,11 @@ Your harness pre-loads these files into your context before your first tool call No running anything, no builds, no tests, no edits of any kind. -Rule whether the project as a whole reads better, the same or worse at {head} than at {base}, judged on these four dimensions: +Rule whether the project reads better, the same or worse at {head} than at {base} on each of these four dimensions, and as a whole: {dimensions} Same means a reader of either version would find it as easy to understand and change. Do not manufacture a difference. Report, in this shape: -1. Your ruling: better, same or worse. -2. The places that decided it, most decisive first. Each: path:line and the unit's name, in the version the place is in, and one or two sentences on what reads easier or harder there than in the other version. A better or worse ruling with no named place is discarded. +1. Your rulings, each better, same or worse, in this shape: Navigation , Locality , Shape , Self-sufficiency , Overall +2. The places that decided them, most decisive first. Each: path:line and the unit's name, in the version the place is in, the dimension it moves, and one or two sentences on what reads easier or harder there than in the other version. Rulings with no named place are discarded. ``` diff --git a/skills/larv-review/SKILL.md b/skills/larv-review/SKILL.md index 97664cd5..8435329a 100644 --- a/skills/larv-review/SKILL.md +++ b/skills/larv-review/SKILL.md @@ -95,18 +95,18 @@ 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. +- **Ruling.** The `Ruling:` line `record-ruling` prints and appends to the history. A better ruling may carry a `Fell:` line naming dimensions the seats ruled worse; a scoring run then decides whether it stands. **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 seats 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. +- **Ratchet.** The paired ruling is worse, or `record-scoring` prints `Ratchet:` because a dimension that fell is under the floor. - **Floor.** `record-scoring` names a mean 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, and the floor at the places the seats name under the lowest dimension. Under the floor alone, 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, a fallen dimension at the places they name under it, and the floor at the places the seats name under the lowest dimension. Under the floor alone, 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: -- 2.52.0 From 75b0e463266edf104736860840006a28a5961c28 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 9 Oct 2026 10:58:59 +0200 Subject: [PATCH 02/22] Answer architecture round 1: count a dimension's vote only where a place names it, take a fall on a same ruling too, block a fall-called run only on the fallen dimensions, read the chunk's own entries, and repeat a standing ratchet --- AGENTS.md | 2 +- CHANGELOG.md | 4 +- bin/larv_review/history.py | 11 ++++-- bin/larv_review/main.py | 71 +++++++++++++++++++++-------------- bin/larv_review/rules.py | 38 +++++++++++++------ bin/test_larv_review.py | 47 ++++++++++++++++------- docs/comprehension-history.md | 33 ++++++++++++++++ docs/decisions.md | 4 +- skills/larv-review/SKILL.md | 10 ++--- 9 files changed, 154 insertions(+), 66 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 4072baca..041b9c52 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -12,7 +12,7 @@ Decisions live in `docs/decisions.md`: - loop-claude: each project's model lives in `~/.claude/loop-claude-models.json`, which only loop-claude writes - review: a pass gets at most three rounds per chunk; instead of a fourth, the run asks the human - review: a fix for a ๐Ÿ”ด or ๐ŸŸก reruns the pass that found it and each pass whose trigger names fixes like it; a fix for a ๐ŸŸข, a โ“ or a prose finding reruns none -- review: a paired ruling against the last measured commit decides the ratchet, and counts as worse when a dimension it rules fallen is under the floor; the four-seat scoring run checks the floor when a release's items run out, an item names the floor or a better ruling names a fallen dimension +- review: a paired ruling against the last measured commit decides the ratchet, and counts as worse when a dimension it rules fallen is under the floor; the four-seat scoring run checks the floor when a release's items run out, an item names the floor or a ruling names a fallen dimension - review: a project decision may suspend the comprehension check for the plan items it names - review: a pass skips only on a precedent: a decision, or a plan item crediting the pass, that the repo held before the chunk began - loop-claude: the archive keeps the raw transcript, and a failed archive stops the loop diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ef8f130..39b0d0c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,10 @@ ## Unreleased -- larv-review's paired ruling takes each seat's vote on each dimension too: `Navigation same, Locality worse, Shape same, Self-sufficiency same, Overall better`. A better ruling in which a dimension fell calls a scoring run, and counts as worse, blocking the merge, when that dimension's mean is under the floor. +- larv-review's paired ruling takes each seat's vote on each dimension too: `Navigation same, Locality worse, Shape same, Self-sufficiency same, Overall better`. A better or same ruling in which a dimension fell calls a scoring run, and counts as worse, blocking the merge, when that dimension's mean is under the floor. A dimension's vote counts only where the seat names a place under that dimension. - 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`). 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. - 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 that added a scoring run to `docs/comprehension-history.md`, or whose last ruling there is better. 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; when they disagree, the maintainability senior and Junior A vote too. A ruling needs a lead of two or more votes, else it is same, and a vote that names no place counts as same. 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 the floor blocks nothing. 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 that added a scoring run to `docs/comprehension-history.md`, or whose last ruling there is better. 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; when they disagree, the maintainability senior and Junior A vote too. A ruling needs a lead of two or more votes, else it is same, and a vote that names no place counts as same. 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 the floor blocks only a dimension a paired ruling finds fallen. 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/larv_review/history.py index f5258f77..b3ac3c47 100644 --- a/bin/larv_review/history.py +++ b/bin/larv_review/history.py @@ -9,6 +9,7 @@ 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)?, ") DECIDED_BY = "decided by" FELL = re.compile(r"^Fell: (.+)$", re.M) +RATCHET = re.compile(r"^Ratchet: .+$", re.M) HARDEST_FIRST = "hardest first" HEADING = re.compile(r"^([^,]+), (.+) at ([0-9a-f]{7,40})(?:, against ([0-9a-f]{7,40}))?$") # `path:line` or `:line`, then the unit's name where one follows. @@ -28,13 +29,14 @@ 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 when it is better, or one scoring run, which names none of them.""" + """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.""" heading: str time: str commit: str against: str | None ruling: str | None fell: list[str] + ratchet: str | None places: list[Place] @property @@ -65,7 +67,8 @@ def entries(history: str) -> list[Entry]: body = "\n".join(bodies) ruling = RULING.search(body) fell = FELL.search(body) - found.append(Entry(heading, named.group(1), named.group(3), named.group(4), ruling.group(1) if ruling else None, fell.group(1).split(", ") if fell else [], seat_places(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))) return found @@ -112,9 +115,9 @@ def appended(history: str, entry: str) -> str: 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, with a `Fell:` line when it is better and fell names dimensions; a seat's vote that counted as same for naming no place says so.""" + """A paired ruling's entry, with a `Fell:` line when it is better or same and fell names dimensions; a seat's vote that counted as same for naming no place says so.""" votes = [[seat.name, *map(vote_text, said[seat.name], counted[seat.name])] for seat in seats] - lines = [f"Ruling: {ruled}"] + ([f"Fell: {', '.join(fell)}"] if ruled == "better" and fell else []) + lines = [f"Ruling: {ruled}"] + ([f"Fell: {', '.join(fell)}"] if ruled != "worse" and fell else []) return entry_text(title, lines, [["Seat", *DIMENSIONS], *votes], [(f"{seat.name}, {DECIDED_BY}:", seat.places) for seat in seats]) diff --git a/bin/larv_review/main.py b/bin/larv_review/main.py index 970832fa..f6822e06 100644 --- a/bin/larv_review/main.py +++ b/bin/larv_review/main.py @@ -2,10 +2,10 @@ 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. 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 +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 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 @@ -20,8 +20,8 @@ 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.` It is due when the chunk ships -an item whose tagline names the comprehension floor, when the checkout's history ends on a better -paired ruling with a `Fell:` line, or when it leaves a release with no item in +an item whose tagline names the comprehension floor, when the checkout's history ends on a paired +ruling with a `Fell:` line, 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 @@ -44,12 +44,13 @@ opens with its label, written exactly: `Junior A:`, `Mid A:`, `Maintainability s - `bin/x.py:12` `run`: ... record-ruling takes Mid A's and the inherited architect's votes on each dimension and overall, -each better, same or worse. Each vote of a seat naming no place in backticks, `path:line`, counts -as same, and the printed votes say so. When the two counted overall votes differ, it appends +each better, same or worse. A dimension's vote counts as same unless one of the seat's places in +backticks, `path:line`, names that dimension; the overall vote counts as same unless the seat names +any place. 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. On a better ruling, it prints and records a `Fell:` line naming each. +vote by two or more. Unless the ruling is worse, it prints and records a `Fell:` line naming each. record-scoring takes 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. @@ -57,8 +58,10 @@ Each line is `Navigation , Locality , Shape , Self-sufficiency , Ove 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 and each one under the floor of {floor}. When the history ends on a -better paired ruling with a `Fell:` line, it says whether the ruling stands; when a dimension that -fell is under the floor, the ruling counts as worse, and it prints and records a `Ratchet:` line. +paired ruling with a `Fell:` line, it says whether the ruling stands; when a dimension that fell is +under the floor, the ruling counts as worse, and it prints and records a `Ratchet:` line, which +needs-scoring-run repeats until a paired ruling follows it. Both read only the entries the default +branch's history lacks. 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 @@ -75,8 +78,8 @@ import sys import time import typing -from larv_review.history import appended, heading, ruling_entry, scoring_entry, vote_text -from larv_review.rules import base, CAP, counted, fallen, fell_under_floor, FLOOR, means, PASSES, pending_fall, plan_items, round_counts, ruling, scoring_run_due, under_floor, votes +from larv_review.history import appended, Entry, heading, ruling_entry, scoring_entry, vote_text +from larv_review.rules import base, CAP, chunk_entries, counted, fall_outcome, fallen, FLOOR, means, PASSES, pending_fall, plan_items, round_counts, ruling, scoring_run_due, standing_ratchet, under_floor, votes from larv_review.git import commit_exists, default_branch, file_at, git, HISTORY, history_changes, landed_since_release, top from larv_review.seats import DIMENSIONS, MEAN, Report, report, score_line, scores from failure import Failure @@ -100,7 +103,7 @@ def main(argv: list[str]) -> int: elif command == "record-ruling" and len(given) == 1: done = record_ruling(pathlib.Path(given[0])) elif command == "record-scoring" and len(given) == 1: - done = record_scoring(pathlib.Path(given[0])) + done = with_default_branch(lambda default: record_scoring(default, pathlib.Path(given[0])), stale_ok=True) elif command == "needs-scoring-run": print(f"needs-scoring-run takes item IDs, the numbers in todo.md's ID column: {' '.join(given)}", file=sys.stderr) return 1 @@ -173,16 +176,29 @@ def needs_scoring_run(default: str, ids: list[int]) -> Failure | None: landed = landed_since_release(default) if isinstance(landed, Failure): return landed - history = history_text() - if isinstance(history, Failure): - return history - reasons = scoring_run_due(planned, chunk, ids, landed, pending_fall(history[1])) + recorded = chunk_history(default) + if isinstance(recorded, Failure): + return recorded + reasons = scoring_run_due(planned, chunk, ids, landed, pending_fall(recorded)) if isinstance(reasons, Failure): return reasons print(f"Scoring run due: the chunk {' and '.join(reasons)}." if reasons else "No scoring run due.") + if ratchet := standing_ratchet(recorded): + print(f"Still standing: {ratchet} Fix it and rule again.") return None +def chunk_history(default: str) -> list[Entry] | Failure: + """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 chunk_entries(held, read[1]) + + def record_ruling(seats_file: pathlib.Path) -> Failure | None: read = read_seats(seats_file, paired=True) if isinstance(read, Failure): @@ -199,12 +215,12 @@ def record_ruling(seats_file: pathlib.Path) -> Failure | None: return None fell = fallen(count) print(f"Ruling: {ruled}. Overall votes as counted: {tally}.") - if ruled == "better" and fell: + if ruled != "worse" and fell: print(f"Fell: {', '.join(fell)}. A scoring run is due; the ruling counts as worse if it puts {' or '.join(fell)} under the floor of {FLOOR}.") return append(ruling_entry(title, given.seats, said, count, ruled, fell)) -def record_scoring(seats_file: pathlib.Path) -> Failure | None: +def record_scoring(default: str, seats_file: pathlib.Path) -> Failure | None: read = read_seats(seats_file, paired=False) if isinstance(read, Failure): return read @@ -218,14 +234,13 @@ def record_scoring(seats_file: pathlib.Path) -> Failure | None: mean = means(list(found.values()) or [moved]) under = under_floor(mean) print(f"Means: {', '.join(f'{name} {value}' for name, value in zip(DIMENSIONS, mean))}. {f'Under the floor of {FLOOR}: ' + ', '.join(under) if under else f'None under the floor of {FLOOR}'}.") - history = history_text() - if isinstance(history, Failure): - return history - fell = [] if given.moved_mean else pending_fall(history[1]) - ratchet = [f"Ratchet: the paired ruling counts as worse, as {', '.join(dropped)} fell under the floor of {FLOOR}."] if (dropped := fell_under_floor(fell, mean)) else [] - if fell: - print(ratchet[0] if ratchet else f"The better paired ruling stands: {', '.join(fell)} fell and stays at or above the floor of {FLOOR}.") - return append(scoring_entry(title, given.seats, found, [str(value) for value in mean], ratchet)) + recorded = chunk_history(default) + if isinstance(recorded, Failure): + return recorded + outcome = fall_outcome([] if given.moved_mean else pending_fall(recorded), 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 [])) def read_seats(seats_file: pathlib.Path, paired: bool) -> tuple[str, Report] | Failure: diff --git a/bin/larv_review/rules.py b/bin/larv_review/rules.py index d02bf4e7..cefcb28a 100644 --- a/bin/larv_review/rules.py +++ b/bin/larv_review/rules.py @@ -31,12 +31,12 @@ def votes(seats: list[Seat]) -> dict[str, list[str]] | Failure: def counted(seats: list[Seat], said: dict[str, list[str]]) -> dict[str, list[str]]: - """Each seat's votes as they count: a seat naming no `path:line` place counts as same on each.""" - return {seat.name: said[seat.name] if names_a_place(seat) else ["same"] * len(DIMENSIONS) for seat in seats} + """Each seat's votes as they count: a dimension's vote counts as same unless one of the seat's `path:line` places names that dimension, and the overall vote unless the seat names any place.""" + return {seat.name: [vote if names_a_place(seat, name) else "same" for name, vote in zip(DIMENSIONS, said[seat.name])] for seat in seats} -def names_a_place(seat: Seat) -> bool: - return any(PLACE.search(place) for place in seat.places) +def names_a_place(seat: Seat, dimension: str) -> bool: + return any(PLACE.search(place) and (dimension == DIMENSIONS[-1] or dimension.lower() in place.lower()) for place in seat.places) def ruling(counted: list[str]) -> str | None: @@ -54,14 +54,30 @@ def fallen(counted: dict[str, list[str]]) -> list[str]: return [name for name, column in zip(DIMENSIONS[:-1], zip(*counted.values())) if ruling(list(column)) == "worse"] -def pending_fall(history: str) -> list[str]: - """The dimensions that fell in the history's newest entry, when it is a better paired ruling, so no scoring run has followed it. Of entries with one time, the later in the file is newer.""" - newest = max(enumerate(entries(history)), key=lambda indexed: (indexed[1].time, indexed[0]), default=None) - return newest[1].fell if newest and newest[1].ruling == "better" else [] +def chunk_entries(default_history: str, history: str) -> list[Entry]: + """The checkout's entries whose headings the default branch's history lacks, oldest first; of entries with one time, the later in the file is newer.""" + 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) -def fell_under_floor(fell: list[str], found: list[decimal.Decimal]) -> list[str]: - return [f"{name} {value}" for name, value in zip(DIMENSIONS, found) if name in fell and value < FLOOR] +def pending_fall(chunk: list[Entry]) -> list[str]: + """The dimensions that fell in the chunk's newest entry: a paired ruling no scoring run has followed yet.""" + return chunk[-1].fell if chunk else [] + + +def standing_ratchet(chunk: list[Entry]) -> str | None: + """The `Ratchet:` line of the chunk's newest entry, which no paired ruling has followed yet.""" + return chunk[-1].ratchet if chunk else None + + +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 stays at or above the floor of {FLOOR}.", [] def means(lines: list[list[str]]) -> list[decimal.Decimal]: @@ -133,7 +149,7 @@ def scoring_run_due(before: list[Item], after: list[Item], ships: list[int], lan shipped = [plan[id_] for id_ in ships] reasons = [f"ships item {item.id}, which names the comprehension floor" for item in shipped if "comprehension floor" in item.tagline.lower()] if fell: - reasons.append(f"has a better paired ruling in which {' and '.join(fell)} fell") + reasons.append(f"has a paired ruling in which {' and '.join(fell)} fell") next_release = min((item.release for item in before), default=None) for release in emptied(before, after, shipped): if any(item.release == release for item in shipped) or (release == next_release and landed): diff --git a/bin/test_larv_review.py b/bin/test_larv_review.py index 83bad3b2..b62e64b6 100644 --- a/bin/test_larv_review.py +++ b/bin/test_larv_review.py @@ -10,7 +10,7 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) from larv_review.history import appended, entries, HistoryChange, Place, ruling_entry -from larv_review.rules import base, counted, fallen, fell_under_floor, first_ruling, means, measured_commit, pending_fall, plan_items, round_counts, ruling, scoring_run_due, under_floor, votes +from larv_review.rules import base, chunk_entries, counted, fall_outcome, fallen, first_ruling, means, measured_commit, pending_fall, plan_items, round_counts, ruling, scoring_run_due, standing_ratchet, under_floor, votes from failure import Failure from test_loop_claude_black_box import host_env from rank_todo import Item @@ -53,6 +53,10 @@ class Seats(unittest.TestCase): self.assertEqual(written, {"Mid A": ["same", "worse", "same", "same", "worse"], "Inherited architect": ["same", "same", "same", "same", "better"]}) self.assertEqual(counted(seats, written)["Mid A"], ["same"] * 5) + def test_counts_a_dimensions_vote_only_where_a_place_names_that_dimension(self): + seats = [Seat("Mid A", said("better", "worse"), ["`a.py:3` `f`: shorter"]), Seat("Inherited architect", said("better", "worse"), ["`a.py:3` `f`: locality, held at once"])] + self.assertEqual([votes[1:] for votes in counted(seats, {seat.name: [*said("better", "worse").replace(",", "").split()[1::2]] for seat in seats}).values()], [["same", "same", "same", "better"], ["worse", "same", "same", "better"]]) + def test_refuses_two_more_seats_once_the_first_two_agree_overall(self): seats = [Seat(name, said(vote), ["`f.py:1` `f`: x"]) for name, vote in (("Mid A", "worse"), ("Inherited architect", "worse"), ("Maintainability senior", "better"), ("Junior A", "better"))] self.assertIsInstance(votes(seats), Failure) @@ -69,7 +73,11 @@ 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"]}), []) - self.assertEqual(fell_under_floor(["Locality", "Shape"], [decimal.Decimal(score) for score in ("6", "6.5", "7", "6", "6")]), ["Locality 6.5"]) + 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 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 = [ @@ -103,7 +111,7 @@ class Seats(unittest.TestCase): class History(unittest.TestCase): def test_reads_back_what_it_writes(self): - seats = [Seat("Mid A", "worse", ["`bin/a.py:3` `f`: hard, with `:9` `g`"]), Seat("Inherited architect", "worse", [])] + 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"]) history = appended(appended("", SCORING), ruled) @@ -114,15 +122,23 @@ class History(unittest.TestCase): 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.paired for entry in found], [False, True]) + self.assertNotIn("Fell:", ruling_entry("2026-10-08T18:37:21Z, PR #2 at bbbbbbb, against aaaaaaa", seats, written, written, "worse", ["Locality"])) class PendingFall(unittest.TestCase): 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(pending_fall(SCORING + fell), ["Locality", "Shape"]) - self.assertEqual(pending_fall(fell + SCORING.replace("12:00:00Z", "14:00:00Z")), []) - self.assertEqual(pending_fall(SCORING + paired("2026-10-08T13:00:00Z", "better")), []) - self.assertEqual(pending_fall(""), []) + fell = paired("2026-10-08T13:00:00Z", "better\n\nFell: Locality,Shape") + self.assertEqual(pending_fall(chunk_entries("", SCORING + fell)), ["Locality", "Shape"]) + later = SCORING.replace("12:00:00Z", "14:00:00Z").replace("| Mean | 7.00 |", "Ratchet: worse.\n\n| Mean | 7.00 |") + self.assertEqual(pending_fall(chunk_entries("", fell + later)), []) + self.assertEqual(standing_ratchet(chunk_entries("", fell + later)), "Ratchet: worse.") + self.assertEqual(pending_fall(chunk_entries("", SCORING + paired("2026-10-08T13:00:00Z", "same\n\nFell: Locality"))), ["Locality"]) + self.assertEqual(pending_fall(chunk_entries("", "")), []) + + 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(pending_fall(chunk_entries(merged, fell + merged)), ["Locality"]) class Base(unittest.TestCase): @@ -183,7 +199,7 @@ class ScoringRunDue(unittest.TestCase): def test_is_due_when_a_better_ruling_hides_a_fall(self): plan = [item(1, (0, 1, 0)), item(2, (0, 1, 0))] - self.assertEqual(scoring_run_due(plan, plan, [], True, ["Locality"]), ["has a better paired ruling in which Locality fell"]) + self.assertEqual(scoring_run_due(plan, plan, [], True, ["Locality"]), ["has a paired ruling in which Locality fell"]) def test_is_not_due_when_a_later_release_loses_its_last_item_unshipped(self): before = [item(1, (0, 1, 0)), item(3, (0, 2, 0))] @@ -279,17 +295,22 @@ class LarvReviewTool(unittest.TestCase): 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): - place = "\n\n- `bin/a.py:3` `f`: shorter\n\n" + place = "\n\n- `bin/a.py:3` `f`: Locality, 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 better paired ruling in which Locality fell.\n") + self.assertEqual(self.run_tool("needs-scoring-run", "2").stdout, "Scoring run due: the chunk has a paired ruling in which Locality fell.\n") 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 6.50 fell under the floor of 7.0.", scored.stdout) + 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("\n\nRatchet: the paired ruling counts as worse", (self.checkout / "docs" / "comprehension-history.md").read_text()) - self.assertEqual(self.run_tool("needs-scoring-run", "2").stdout, "No scoring run due.\n") + self.assertTrue(self.run_tool("needs-scoring-run", "2").stdout.startswith("No scoring run due.\nStill standing: Ratchet:")) + 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 stays at or above the floor of 7.0.", stands.stdout) def test_records_a_scoring_run_with_its_means(self): line = "Navigation 7, Locality 6.5, Shape 7, Self-sufficiency 6.5, Overall 7" diff --git a/docs/comprehension-history.md b/docs/comprehension-history.md index 16424e25..c74868ce 100644 --- a/docs/comprehension-history.md +++ b/docs/comprehension-history.md @@ -528,3 +528,36 @@ Junior A, decided by: - `bin/larv_review/git.py:5` and `bin/metric_bench/main.py:38`: the git layer depends on the history type, and metric-bench on larv-review's package - `bin/larv_review/main.py:1` the module docstring: one home, but a wall of rules leaning on terms defined elsewhere - `bin/larv_review/rules.py:16` `votes`: a seat protocol reconstructed only from `skills/larv-review/SKILL.md:97` + +## 2026-10-09T08:54:36Z, PR #232 at 2c6e063, against 12d6d75 + +Ruling: better + +| Seat | Navigation | Locality | Shape | Self-sufficiency | Overall | +|---|---|---|---|---|---| +| Mid A | better | same | same | better | better | +| Inherited architect | better | worse | same | better | better | + +Mid A, decided by: + +- `bin/larv_review/main.py:146` `round_count`: Navigation, better: the fourth-round symptom leads to a named unit, where the base had only `skills/larv-review/SKILL.md:58` "Count" +- `bin/larv_review/rules.py:42` `ruling`, `:52` `fallen` and `:128` `scoring_run_due`: Self-sufficiency, better: vote arithmetic and the scoring trigger are pure functions with docstrings, where the base had prose alone +- `README.md:68` "Tools": Navigation, better: the README names larv-review and metric-bench +- `bin/larv_review/main.py:1` the module docstring: Self-sufficiency, better, with a cost: Split, Fell, Ratchet and the moved Mean line arrive in long sentences +- `bin/larv_review/history.py:96` `heading`: Locality, against: two flags with DATED and HEADING, traced through `bin/larv_review/seats.py:38` `report` and `bin/larv_review/main.py:207` `record_scoring` +- `bin/larv_review/history.py:18` `SEAT_PLACES`, `:114` `ruling_entry` and `:125` `scoring_entry`: Locality, against: writers and parser must agree on label strings +- `bin/larv_review/rules.py:1` the module: Shape, against: one vague name over five concerns +- `bin/metric_bench/bench.py:87` `resolved` and `bin/metric_bench/main.py:38`: Shape and Locality, against: metric-bench depends on larv-review's history parser + +Inherited architect, decided by: + +- `bin/larv_review/main.py:146` `round_count`: Navigation: the 3am question lands on a function, where the base had `skills/larv-review/SKILL.md:58` "Count" +- `bin/larv_review/rules.py:89` `measured_commit` and `:105` `base`: Self-sufficiency: the ratchet's base is executable, where the base had `skills/larv-review/SKILL.md:100` +- `bin/larv_review/history.py:60` `entries`, `:114` `ruling_entry` and `:125` `scoring_entry`: Self-sufficiency and Navigation: the history's format is a regex plus writers, where the base had `skills/larv-review/SKILL.md:92` +- `bin/larv_review/main.py:207` `record_scoring`, with `bin/larv_review/seats.py:45` `report` and `bin/larv_review/history.py:96` `heading`: Locality: the moved Mean case threads through three modules +- `bin/larv_review/rules.py:57` `pending_fall`, called from `bin/larv_review/main.py:179` and `:224`: Locality: commands depend on state an earlier command appended to the history; `history[1]` hides it at the call site +- `bin/metric_bench/main.py:38` and `bin/metric_bench/bench.py:7`: Locality: metric-bench parses the history with larv-review's `entries`, and keeps its own `git()` at `bin/metric_bench/main.py:143` +- `bin/larv_review/rules.py:1` the module: Shape: a grab-bag name +- `bin/larv_review/git.py:56` `file_at` and `bin/larv_review/main.py:247` `history_text`: Locality: two histories, the default branch's and the checkout's +- `skills/larv-review/SKILL.md:97` "Seats": Self-sufficiency, against the skill: it needs the tool's help open beside it +- `bin/rank_todo.py:386` `parse_row`: Shape, a small gain diff --git a/docs/decisions.md b/docs/decisions.md index 15d88834..70a6ae1b 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -65,9 +65,9 @@ lilleman decided to ship each of these under the floor on the day listed. Each l 2026-10-08, lilleman, replacing the 2026-09-30 rule that every fix, a nit's included, re-enters review. Serves goal 1.4. An audit of the four costliest archived chunks (2026-10-08) found nearly every finding that mattered in a pass's first round; later rounds mostly re-checked the last fix, reworded what an earlier round wrote, or contradicted another round on the same line. A round 2 caught real bugs only where a fix changed behaviour, so stability still reruns on every fix that does, and security on every fix that opens an untrusted-input boundary or touches authn/authz, secrets or crypto. Valid while round-2 reviews of nit and prose fixes keep changing nothing a user would notice. -## review: a paired ruling against the last measured commit decides the ratchet, and counts as worse when a dimension it rules fallen is under the floor; the four-seat scoring run checks the floor when a release's items run out, an item names the floor or a better ruling names a fallen dimension +## review: a paired ruling against the last measured commit decides the ratchet, and counts as worse when a dimension it rules fallen is under the floor; the four-seat scoring run checks the floor when a release's items run out, an item names the floor or a ruling names a fallen dimension -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 that adds a scoring run to the history, or whose last added paired ruling is better. 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. 2026-10-09, lilleman: each seat also rules each dimension, and a dimension falls by the same lead of two. A better 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. Valid while seats reading both versions agree more often than two absolute runs do. +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 that adds a scoring run to the history, or whose last added paired ruling is better. 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. 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. A dimension's vote counts only where one of the seat's places names that dimension. Valid while seats reading both versions agree more often than two absolute runs do. ## 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 8435329a..52e9d721 100644 --- a/skills/larv-review/SKILL.md +++ b/skills/larv-review/SKILL.md @@ -95,14 +95,14 @@ 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 ruling may carry a `Fell:` line naming dimensions the seats ruled worse; a scoring run then decides whether it stands. +- **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. -**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 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` 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. 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. -- **Floor.** `record-scoring` names a mean under the floor of 7.0. +- **Ratchet.** The paired ruling is worse, or `record-scoring` prints `Ratchet:` because a dimension that fell is under the floor, which `needs-scoring-run` repeats as `Still standing:` until a paired ruling follows it. +- **Floor.** `record-scoring` names a mean under the floor of 7.0, on a run `needs-scoring-run` called for a reason besides a fall. 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. @@ -117,7 +117,7 @@ A `comprehension floor:` entry written before the history may still hold a scori 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 it ran one, 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. +**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. **Suspended.** A decision in the project's `docs/decisions.md`, held before the chunk began, may name plan items to ship without a comprehension check. A named item counts as `todo.md` worded it before the chunk began. The decision must name the later plan item whose chunk ends the suspension with a comprehension check. A chunk may ship named items only with each other. Such a chunk skips the comprehension check, so neither the ratchet nor the floor can block it, and its summary cites the decision. A chunk due a scoring run runs it, even when every item it ships is named. -- 2.52.0 From 9de87e04cf55acd769fa42c05e210b5a585105db Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 9 Oct 2026 11:04:01 +0200 Subject: [PATCH 03/22] Answer architecture round 2: fail a place naming no dimension, keep a ratchet until a ruling follows, leave the base on a fall-called run, let record-scoring say whether the floor blocks, and name the missing dimension in a discounted vote --- CHANGELOG.md | 2 +- bin/larv_review/history.py | 12 ++-- bin/larv_review/main.py | 73 +++++++++++++--------- bin/larv_review/rules.py | 29 +++++++-- bin/test_larv_review.py | 27 +++++--- docs/decisions.md | 2 +- skills/comprehension-panel/seat-prompts.md | 2 +- skills/larv-review/SKILL.md | 4 +- 8 files changed, 95 insertions(+), 56 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39b0d0c4..ce21dcc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- larv-review's paired ruling takes each seat's vote on each dimension too: `Navigation same, Locality worse, Shape same, Self-sufficiency same, Overall better`. A better or same ruling in which a dimension fell calls a scoring run, and counts as worse, blocking the merge, when that dimension's mean is under the floor. A dimension's vote counts only where the seat names a place under that dimension. +- larv-review's paired ruling takes each seat's vote on each dimension too: `Navigation same, Locality worse, Shape same, Self-sufficiency same, Overall better`. A better or same ruling in which a dimension fell calls a scoring run, and counts as worse, blocking the merge, when that dimension's mean is under the floor. Such a run blocks on the fallen dimensions alone and leaves the ratchet's base in place unless the ruling is better. Each place a seat names must name the dimensions it moves, spelled as in the seat's line, or the run fails; a dimension's vote counts only where one of the seat's places names it. `record-scoring` takes the shipped item IDs too and prints `Floor:` when the means under the floor block the merge. - 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`). 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. - 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 that added a scoring run to `docs/comprehension-history.md`, or whose last ruling there is better. 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; when they disagree, the maintainability senior and Junior A vote too. A ruling needs a lead of two or more votes, else it is same, and a vote that names no place counts as same. 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 the floor blocks only a dimension a paired ruling finds fallen. 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. diff --git a/bin/larv_review/history.py b/bin/larv_review/history.py index b3ac3c47..bfb2530d 100644 --- a/bin/larv_review/history.py +++ b/bin/larv_review/history.py @@ -115,14 +115,16 @@ def appended(history: str, entry: str) -> str: 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, with a `Fell:` line when it is better or same and fell names dimensions; a seat's vote that counted as same for naming no place says so.""" - votes = [[seat.name, *map(vote_text, said[seat.name], counted[seat.name])] for seat in seats] - lines = [f"Ruling: {ruled}"] + ([f"Fell: {', '.join(fell)}"] if ruled != "worse" and fell else []) + """A paired ruling's entry, with a `Fell:` line when fell names dimensions; 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]) -def vote_text(said: str, counted: str) -> str: - return counted if counted == said else f"same (voted {said}, naming no place)" +def vote_text(dimension: str, said: str, counted: str) -> str: + if counted == said: + return counted + 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: diff --git a/bin/larv_review/main.py b/bin/larv_review/main.py index f6822e06..8600bf44 100644 --- a/bin/larv_review/main.py +++ b/bin/larv_review/main.py @@ -9,8 +9,8 @@ read origin as last fetched and say so on stderr; the other two exit 1. The hist 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 that adds a scoring run to the -history, or whose last added paired ruling, by heading time, is better; a merge commit counts as +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. @@ -37,30 +37,34 @@ opens with its label, written exactly: `Junior A:`, `Mid A:`, `Maintainability s Mid A: Navigation same, Locality worse, Shape same, Self-sufficiency same, Overall worse - - `bin/x.py:12` `run`: three branches to hold at once + - `bin/x.py:12` `run`: Locality: three branches to hold at once Inherited architect: Navigation same, Locality worse, Shape same, Self-sufficiency same, Overall worse - - `bin/x.py:12` `run`: ... + - `bin/x.py:12` `run`: Locality: ... record-ruling takes Mid A's and the inherited architect's votes on each dimension and overall, -each better, same or worse. A dimension's vote counts as same unless one of the seat's places in +each better, same or worse. Each place names the dimensions it moves, or Overall, spelled as the +seat's line spells them. A dimension's vote counts as same unless one of the seat's places in backticks, `path:line`, names that dimension; the overall vote counts as same unless the seat names -any place. The printed votes say so. When the two counted overall votes differ, it appends +any such place. 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. -record-scoring takes Junior A's, Mid A's, the maintainability senior's and the inherited +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 and each one under the floor of {floor}. When the history ends on a +decimals, and prints the means and each one under the floor of {floor}. A `Floor:` line says the +means under the floor block the merge, as they do when needs-scoring-run would give a reason +besides a fall. When the history ends on a paired ruling with a `Fell:` line, it says whether the ruling stands; when a dimension that fell is under the floor, the ruling counts as worse, and it prints and records a `Ratchet:` line, which -needs-scoring-run repeats until a paired ruling follows it. Both read only the entries the default +needs-scoring-run repeats as `Still standing:` until a paired ruling follows it. Both read only the entries the default branch's history lacks. Each record is appended to the history, created when missing, under a heading of the current UTC @@ -79,14 +83,14 @@ import time import typing from larv_review.history import appended, Entry, heading, ruling_entry, scoring_entry, vote_text -from larv_review.rules import base, CAP, chunk_entries, counted, fall_outcome, fallen, FLOOR, means, PASSES, pending_fall, plan_items, round_counts, ruling, scoring_run_due, standing_ratchet, under_floor, votes +from larv_review.rules import base, CAP, chunk_entries, counted, fall_outcome, fallen, FLOOR, floor_verdict, means, PASSES, pending_fall, plan_items, round_counts, ruling, scoring_run_due, standing_ratchet, under_floor, votes from larv_review.git import commit_exists, default_branch, file_at, git, HISTORY, history_changes, landed_since_release, top from larv_review.seats import DIMENSIONS, MEAN, Report, report, score_line, scores from failure import Failure from rank_todo import ITEMS_HEADER from file_writes import replace_file -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: @@ -102,10 +106,10 @@ def main(argv: list[str]) -> int: 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 len(given) == 1: - done = with_default_branch(lambda default: record_scoring(default, pathlib.Path(given[0])), stale_ok=True) - elif command == "needs-scoring-run": - print(f"needs-scoring-run takes item IDs, the numbers in todo.md's ID column: {' '.join(given)}", file=sys.stderr) + 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: + print(f"{command} takes item IDs, the numbers in todo.md's ID column: {' '.join(given)}", file=sys.stderr) return 1 elif not argv: print(USAGE, file=sys.stderr) @@ -156,6 +160,20 @@ def round_count(default: str) -> Failure | None: def needs_scoring_run(default: str, ids: list[int]) -> Failure | None: + recorded = chunk_history(default) + if isinstance(recorded, Failure): + return recorded + reasons = due_reasons(default, ids, pending_fall(recorded)) + if isinstance(reasons, Failure): + return reasons + print(f"Scoring run due: the chunk {' and '.join(reasons)}." if reasons else "No scoring run due.") + if ratchet := standing_ratchet(recorded): + print(f"Still standing: {ratchet} Fix it and rule again.") + return None + + +def due_reasons(default: str, ids: list[int], fell: list[str]) -> list[str] | Failure: + """Why the chunk is due a scoring run, from the default branch's plan and the checkout's.""" checkout = top() if isinstance(checkout, Failure): return checkout @@ -176,16 +194,7 @@ def needs_scoring_run(default: str, ids: list[int]) -> Failure | None: landed = landed_since_release(default) if isinstance(landed, Failure): return landed - recorded = chunk_history(default) - if isinstance(recorded, Failure): - return recorded - reasons = scoring_run_due(planned, chunk, ids, landed, pending_fall(recorded)) - if isinstance(reasons, Failure): - return reasons - print(f"Scoring run due: the chunk {' and '.join(reasons)}." if reasons else "No scoring run due.") - if ratchet := standing_ratchet(recorded): - print(f"Still standing: {ratchet} Fix it and rule again.") - return None + return scoring_run_due(planned, chunk, ids, landed, fell) def chunk_history(default: str) -> list[Entry] | Failure: @@ -208,19 +217,19 @@ def record_ruling(seats_file: pathlib.Path) -> Failure | None: if isinstance(said, Failure): return said count = counted(given.seats, said) - tally = ", ".join(f"{seat.name} {vote_text(said[seat.name][-1], count[seat.name][-1])}" for seat in given.seats) + 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.") return None - fell = fallen(count) + fell = fallen(count) if ruled != "worse" else [] print(f"Ruling: {ruled}. Overall votes as counted: {tally}.") - if ruled != "worse" and fell: + if fell: print(f"Fell: {', '.join(fell)}. A scoring run is due; the ruling counts as worse if it puts {' or '.join(fell)} under the floor of {FLOOR}.") return append(ruling_entry(title, given.seats, said, count, ruled, fell)) -def record_scoring(default: str, seats_file: pathlib.Path) -> Failure | None: +def record_scoring(default: str, seats_file: pathlib.Path, ids: list[int]) -> Failure | None: read = read_seats(seats_file, paired=False) if isinstance(read, Failure): return read @@ -232,11 +241,13 @@ def record_scoring(default: str, seats_file: pathlib.Path) -> Failure | None: if isinstance(moved, Failure): return moved mean = means(list(found.values()) or [moved]) - under = under_floor(mean) - print(f"Means: {', '.join(f'{name} {value}' for name, value in zip(DIMENSIONS, mean))}. {f'Under the floor of {FLOOR}: ' + ', '.join(under) if under else f'None under the floor of {FLOOR}'}.") recorded = chunk_history(default) if isinstance(recorded, Failure): return recorded + blocking = due_reasons(default, ids, []) + if isinstance(blocking, Failure): + return blocking + print(f"Means: {', '.join(f'{name} {value}' for name, value in zip(DIMENSIONS, mean))}. {floor_verdict(under_floor(mean), blocking)}") outcome = fall_outcome([] if given.moved_mean else pending_fall(recorded), mean) if outcome: print(outcome[0]) diff --git a/bin/larv_review/rules.py b/bin/larv_review/rules.py index cefcb28a..413d464c 100644 --- a/bin/larv_review/rules.py +++ b/bin/larv_review/rules.py @@ -23,6 +23,8 @@ def votes(seats: list[Seat]) -> dict[str, list[str]] | Failure: line = vote_line(seat.name, seat.said) if isinstance(line, Failure): return line + if unnamed := [place for place in seat.places if not any(re.search(rf"\b{name}\b", place) for name in DIMENSIONS)]: + return Failure(f"{seat.name}'s place names none of {', '.join(DIMENSIONS)}, spelled so: {unnamed[0]}") said[seat.name] = line first, second, *more = (each[-1] for each in counted(seats, said).values()) if more and first == second: @@ -31,12 +33,12 @@ def votes(seats: list[Seat]) -> dict[str, list[str]] | Failure: def counted(seats: list[Seat], said: dict[str, list[str]]) -> dict[str, list[str]]: - """Each seat's votes as they count: a dimension's vote counts as same unless one of the seat's `path:line` places names that dimension, and the overall vote unless the seat names any place.""" + """Each seat's votes as they count: a dimension's vote counts as same unless one of the seat's `path:line` places names that dimension, and the overall vote unless the seat names any such place.""" return {seat.name: [vote if names_a_place(seat, name) else "same" for name, vote in zip(DIMENSIONS, said[seat.name])] for seat in seats} def names_a_place(seat: Seat, dimension: str) -> bool: - return any(PLACE.search(place) and (dimension == DIMENSIONS[-1] or dimension.lower() in place.lower()) for place in seat.places) + return any(PLACE.search(place) and (dimension == DIMENSIONS[-1] or re.search(rf"\b{dimension}\b", place)) for place in seat.places) def ruling(counted: list[str]) -> str | None: @@ -66,8 +68,22 @@ def pending_fall(chunk: list[Entry]) -> list[str]: def standing_ratchet(chunk: list[Entry]) -> str | None: - """The `Ratchet:` line of the chunk's newest entry, which no paired ruling has followed yet.""" - return chunk[-1].ratchet if chunk else None + """The chunk's newest `Ratchet:` line, unless a paired ruling has followed it.""" + for entry in reversed(chunk): + if entry.paired: + return None + if entry.ratchet: + return entry.ratchet + return None + + +def floor_verdict(under: list[str], reasons: list[str]) -> str: + """Whether the means under the floor block the merge: they do on a run due for a reason besides a fall.""" + 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 on a run due for no reason besides a fall: {', '.join(under)}." def fall_outcome(fell: list[str], found: list[decimal.Decimal]) -> tuple[str, list[str]] | None: @@ -103,12 +119,13 @@ def round_counts(titles: list[str]) -> dict[str, int]: def measured_commit(changes: list[HistoryChange]) -> str | None: - """The newest change, of changes given newest first, that adds a scoring run to the history, or whose last added paired ruling is better.""" + """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.""" 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) - if any(not entry.paired for entry in added) or rulings and rulings[-1].ruling == "better": + last = rulings[-1] if rulings else None + if last and last.ruling == "better" or any(not entry.paired for entry in added) and not (last and last.fell): return change.commit return None diff --git a/bin/test_larv_review.py b/bin/test_larv_review.py index b62e64b6..d7626615 100644 --- a/bin/test_larv_review.py +++ b/bin/test_larv_review.py @@ -48,14 +48,16 @@ class Seats(unittest.TestCase): self.assertIsInstance(report(""), Failure) def test_counts_each_vote_of_a_seat_naming_no_place_as_same(self): - seats = [Seat("Mid A", said("worse", "worse"), ["the whole skill"]), Seat("Inherited architect", said("better"), ["`a.py:3` `f`: shorter"])] + seats = [Seat("Mid A", said("worse", "worse"), ["Locality: the whole skill"]), Seat("Inherited architect", said("better"), ["`a.py:3` `f`: Overall: shorter"])] written = votes(seats) self.assertEqual(written, {"Mid A": ["same", "worse", "same", "same", "worse"], "Inherited architect": ["same", "same", "same", "same", "better"]}) self.assertEqual(counted(seats, written)["Mid A"], ["same"] * 5) def test_counts_a_dimensions_vote_only_where_a_place_names_that_dimension(self): - seats = [Seat("Mid A", said("better", "worse"), ["`a.py:3` `f`: shorter"]), Seat("Inherited architect", said("better", "worse"), ["`a.py:3` `f`: locality, held at once"])] - self.assertEqual([votes[1:] for votes in counted(seats, {seat.name: [*said("better", "worse").replace(",", "").split()[1::2]] for seat in seats}).values()], [["same", "same", "same", "better"], ["worse", "same", "same", "better"]]) + seats = [Seat("Mid A", said("better", "worse"), ["`a.py:3` `f`: Shape, reshaped"]), Seat("Inherited architect", said("better", "worse"), ["`a.py:3` `f`: Locality, held at once"])] + written = {seat.name: ["same", "worse", "same", "same", "better"] for seat in seats} + self.assertEqual(counted(seats, written), {"Mid A": ["same", "same", "same", "same", "better"], "Inherited architect": written["Inherited architect"]}) + self.assertIsInstance(votes([Seat("Mid A", said("better"), ["`a.py:3` `f`: self sufficiency"]), seats[1]]), Failure) def test_refuses_two_more_seats_once_the_first_two_agree_overall(self): seats = [Seat(name, said(vote), ["`f.py:1` `f`: x"]) for name, vote in (("Mid A", "worse"), ("Inherited architect", "worse"), ("Maintainability senior", "better"), ("Junior A", "better"))] @@ -117,12 +119,11 @@ class History(unittest.TestCase): 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, naming no place) | same | same | same (voted worse, naming no place) |", 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.paired for entry in found], [False, True]) - self.assertNotIn("Fell:", ruling_entry("2026-10-08T18:37:21Z, PR #2 at bbbbbbb, against aaaaaaa", seats, written, written, "worse", ["Locality"])) class PendingFall(unittest.TestCase): @@ -276,7 +277,7 @@ class LarvReviewTool(unittest.TestCase): Mid A: {worse} - - `bin/a.py:3` `f`: three branches + - `bin/a.py:3` `f`: Overall: three branches Inherited architect: {same} """ @@ -286,7 +287,7 @@ class LarvReviewTool(unittest.TestCase): self.assertTrue(split.stdout.startswith("Split: Mid A worse, Inherited architect same.")) history = self.checkout / "docs" / "comprehension-history.md" self.assertFalse(history.exists()) - lines += f"\n\t\t\tMaintainability senior: {said('worse')}\n\n\t\t\t- `bin/a.py:3` `f`: hard\n\n\t\t\tJunior A: {said('worse')}\n" + lines += f"\n\t\t\tMaintainability senior: {said('worse')}\n\n\t\t\t- `bin/a.py:3` `f`: Overall: hard\n\n\t\t\tJunior A: {said('worse')}\n" ran = self.run_tool("record-ruling", self.seats_file(lines)) self.assertEqual(ran.stdout.splitlines()[0], "Ruling: same. Overall votes as counted: Mid A worse, Inherited architect same, Maintainability senior worse, Junior A same (voted worse, naming no place).") recorded = entries(history.read_text()) @@ -312,16 +313,24 @@ class LarvReviewTool(unittest.TestCase): 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 stays at or above the floor of 7.0.", stands.stdout) + def test_names_no_fall_on_a_worse_ruling(self): + place = "\n\n- `bin/a.py:3` `f`: Locality, 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()) + 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")) 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("Under the floor of 7.0: Locality 6.50, Self-sufficiency 6.50.", ran.stdout) + self.assertIn("Under the floor of 7.0, blocking nothing on a run due for no reason besides a fall: Locality 6.50, Self-sufficiency 6.50.", ran.stdout) + due = self.run_tool("record-scoring", self.seats_file(f"PR #3 at {self.start}\n" + seats), "1") + self.assertIn("Floor: 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.", due.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) - self.assertEqual([entry.places for entry in entries(text)], [[Place("bin/a.py", "f")] * 4]) + self.assertEqual(entries(text)[0].places, [Place("bin/a.py", "f")] * 4) def test_refuses_a_ruling_file_that_names_no_base_or_a_commit_the_checkout_lacks(self): ran = self.run_tool("record-ruling", self.seats_file(f"PR #2 at {self.start}\n\nMid A: {said('same')}\n\nInherited architect: {said('same')}\n")) diff --git a/docs/decisions.md b/docs/decisions.md index 70a6ae1b..097b9a5c 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -67,7 +67,7 @@ lilleman decided to ship each of these under the floor on the day listed. Each l ## review: a paired ruling against the last measured commit decides the ratchet, and counts as worse when a dimension it rules fallen is under the floor; the four-seat scoring run checks the floor when a release's items run out, an item names the floor or a ruling names a fallen dimension -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 that adds a scoring run to the history, or whose last added paired ruling is better. 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. 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. A dimension's vote counts only where one of the seat's places names that dimension. Valid while seats reading both versions agree more often than two absolute runs do. +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 that adds a scoring run to the history, or whose last added paired ruling is better. 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. 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 names that dimension. Valid while seats reading both versions agree more often than two absolute runs do. ## review: a project decision may suspend the comprehension check for the plan items it names diff --git a/skills/comprehension-panel/seat-prompts.md b/skills/comprehension-panel/seat-prompts.md index 5e0cb2cc..254fe5cf 100644 --- a/skills/comprehension-panel/seat-prompts.md +++ b/skills/comprehension-panel/seat-prompts.md @@ -90,5 +90,5 @@ Same means a reader of either version would find it as easy to understand and ch Report, in this shape: 1. Your rulings, each better, same or worse, in this shape: Navigation , Locality , Shape , Self-sufficiency , Overall -2. The places that decided them, most decisive first. Each: path:line and the unit's name, in the version the place is in, the dimension it moves, and one or two sentences on what reads easier or harder there than in the other version. Rulings with no named place are discarded. +2. The places that decided them, most decisive first. Each: path:line and the unit's name, in the version the place is in, the dimensions it moves, each spelled as in your rulings line, or Overall, and one or two sentences on what reads easier or harder there than in the other version. Rulings with no named place are discarded. ``` diff --git a/skills/larv-review/SKILL.md b/skills/larv-review/SKILL.md index 52e9d721..5ce944b3 100644 --- a/skills/larv-review/SKILL.md +++ b/skills/larv-review/SKILL.md @@ -97,12 +97,12 @@ Then the comprehension check: simulated readers, launched per `~/.claude/skills/ - **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. -**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` 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. 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, which `needs-scoring-run` repeats as `Still standing:` until a paired ruling follows it. -- **Floor.** `record-scoring` names a mean under the floor of 7.0, on a run `needs-scoring-run` called for a reason besides a fall. +- **Floor.** `record-scoring` prints `Floor:`, naming means under the floor of 7.0 on a run due for a reason besides a fall. 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. -- 2.52.0 From 030e29a52d99b1596c58b4103fb4cbf9b7fc610d Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 9 Oct 2026 11:07:12 +0200 Subject: [PATCH 04/22] Answer architecture round 3: open each place with the dimensions it moves, fail a scoring run nothing calls, test the base rule and a standing ratchet, and state the base rule whole --- CHANGELOG.md | 4 +-- bin/larv_review/main.py | 13 +++++---- bin/larv_review/rules.py | 12 ++++++-- bin/test_larv_review.py | 33 ++++++++++++++-------- docs/decisions.md | 2 +- skills/comprehension-panel/seat-prompts.md | 2 +- 6 files changed, 43 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce21dcc4..ca36e7bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,10 @@ ## Unreleased -- larv-review's paired ruling takes each seat's vote on each dimension too: `Navigation same, Locality worse, Shape same, Self-sufficiency same, Overall better`. A better or same ruling in which a dimension fell calls a scoring run, and counts as worse, blocking the merge, when that dimension's mean is under the floor. Such a run blocks on the fallen dimensions alone and leaves the ratchet's base in place unless the ruling is better. Each place a seat names must name the dimensions it moves, spelled as in the seat's line, or the run fails; a dimension's vote counts only where one of the seat's places names it. `record-scoring` takes the shipped item IDs too and prints `Floor:` when the means under the floor block the merge. +- larv-review's paired ruling takes each seat's vote on each dimension too: `Navigation same, Locality worse, Shape same, Self-sufficiency same, Overall better`. A better or same ruling in which a dimension fell calls a scoring run, and counts as worse, blocking the merge, when that dimension's mean is under the floor. Such a run blocks on the fallen dimensions alone and leaves the ratchet's base in place unless the ruling is better. Each place a seat names opens with the dimensions it moves, spelled as in the seat's line, such as `Locality, Shape: `, or the run fails; a dimension's vote counts only where one of the seat's places opens with it. `record-scoring` takes the shipped item IDs too and prints `Floor:` when the means under the floor block the merge. - 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`). 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. - 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 that added a scoring run to `docs/comprehension-history.md`, or whose last ruling there is better. 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; when they disagree, the maintainability senior and Junior A vote too. A ruling needs a lead of two or more votes, else it is same, and a vote that names no place counts as same. 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 the floor blocks only a dimension a paired ruling finds fallen. 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; when they disagree, the maintainability senior and Junior A vote too. A ruling needs a lead of two or more votes, else it is same, and a vote that names no place counts as same. 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 the floor blocks only a dimension a paired ruling finds fallen. 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/main.py b/bin/larv_review/main.py index 8600bf44..406168ea 100644 --- a/bin/larv_review/main.py +++ b/bin/larv_review/main.py @@ -37,15 +37,15 @@ opens with its label, written exactly: `Junior A:`, `Mid A:`, `Maintainability s Mid A: Navigation same, Locality worse, Shape same, Self-sufficiency same, Overall worse - - `bin/x.py:12` `run`: Locality: three branches to hold at once + - Locality: `bin/x.py:12` `run`: three branches to hold at once Inherited architect: Navigation same, Locality worse, Shape same, Self-sufficiency same, Overall worse - - `bin/x.py:12` `run`: Locality: ... + - Locality: `bin/x.py:12` `run`: ... record-ruling takes Mid A's and the inherited architect's votes on each dimension and overall, -each better, same or worse. Each place names the dimensions it moves, or Overall, spelled as the -seat's line spells them. A dimension's vote counts as same unless one of the seat's places in +each better, same or worse. Each place opens with the dimensions it moves, or Overall, spelled as +the seat's line spells them and joined by `, `, then `: `. A dimension's vote counts as same unless one of the seat's places in backticks, `path:line`, names that dimension; the overall vote counts as same unless the seat names any such place. 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. @@ -59,7 +59,8 @@ architect's lines in that order, or a `Mean:` line alone for a run moved from a 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 and each one under the floor of {floor}. A `Floor:` line says the +decimals, and prints the means and each one under the floor of {floor}. It exits 1 on a run with +seats that no plan item, release or fall calls. A `Floor:` line says the means under the floor block the merge, as they do when needs-scoring-run would give a reason besides a fall. When the history ends on a paired ruling with a `Fell:` line, it says whether the ruling stands; when a dimension that fell is @@ -247,6 +248,8 @@ def record_scoring(default: str, seats_file: pathlib.Path, ids: list[int]) -> Fa blocking = due_reasons(default, ids, []) if isinstance(blocking, Failure): return blocking + if not (blocking or given.moved_mean or pending_fall(recorded)): + return Failure("no plan item, release or fall calls this scoring run; name the item IDs the chunk ships, as needs-scoring-run took them") print(f"Means: {', '.join(f'{name} {value}' for name, value in zip(DIMENSIONS, mean))}. {floor_verdict(under_floor(mean), blocking)}") outcome = fall_outcome([] if given.moved_mean else pending_fall(recorded), mean) if outcome: diff --git a/bin/larv_review/rules.py b/bin/larv_review/rules.py index 413d464c..db86ef6d 100644 --- a/bin/larv_review/rules.py +++ b/bin/larv_review/rules.py @@ -23,8 +23,8 @@ def votes(seats: list[Seat]) -> dict[str, list[str]] | Failure: line = vote_line(seat.name, seat.said) if isinstance(line, Failure): return line - if unnamed := [place for place in seat.places if not any(re.search(rf"\b{name}\b", place) for name in DIMENSIONS)]: - return Failure(f"{seat.name}'s place names none of {', '.join(DIMENSIONS)}, spelled so: {unnamed[0]}") + if unnamed := [place for place in seat.places if not place_dimensions(place)]: + return Failure(f"{seat.name}'s place does not open with the dimensions it moves, each one of {', '.join(DIMENSIONS)}, then `: `: {unnamed[0]}") said[seat.name] = line first, second, *more = (each[-1] for each in counted(seats, said).values()) if more and first == second: @@ -38,7 +38,13 @@ def counted(seats: list[Seat], said: dict[str, list[str]]) -> dict[str, list[str def names_a_place(seat: Seat, dimension: str) -> bool: - return any(PLACE.search(place) and (dimension == DIMENSIONS[-1] or re.search(rf"\b{dimension}\b", place)) for place in seat.places) + return any(PLACE.search(place) and (dimension == DIMENSIONS[-1] or dimension in place_dimensions(place)) for place in seat.places) + + +def place_dimensions(place: str) -> list[str]: + """The dimensions a place opens with, as in `Locality, Shape: `path:line` ...`; empty when any name before the first `: ` is no dimension.""" + named = place.partition(": ")[0].split(", ") + return named if all(name in DIMENSIONS for name in named) else [] def ruling(counted: list[str]) -> str | None: diff --git a/bin/test_larv_review.py b/bin/test_larv_review.py index d7626615..f121841a 100644 --- a/bin/test_larv_review.py +++ b/bin/test_larv_review.py @@ -48,19 +48,21 @@ class Seats(unittest.TestCase): self.assertIsInstance(report(""), 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"), ["`a.py:3` `f`: Overall: shorter"])] + seats = [Seat("Mid A", said("worse", "worse"), ["Locality: the whole skill"]), Seat("Inherited architect", said("better"), ["Overall: `a.py:3` `f`: shorter"])] written = votes(seats) self.assertEqual(written, {"Mid A": ["same", "worse", "same", "same", "worse"], "Inherited architect": ["same", "same", "same", "same", "better"]}) self.assertEqual(counted(seats, written)["Mid A"], ["same"] * 5) def test_counts_a_dimensions_vote_only_where_a_place_names_that_dimension(self): - seats = [Seat("Mid A", said("better", "worse"), ["`a.py:3` `f`: Shape, reshaped"]), Seat("Inherited architect", said("better", "worse"), ["`a.py:3` `f`: Locality, held at once"])] + seats = [Seat("Mid A", said("better", "worse"), ["Shape: `a.py:3` `f`: the Locality of it, reshaped"]), Seat("Inherited architect", said("better", "worse"), ["Locality, Shape: `a.py:3` `f`: held at once"])] written = {seat.name: ["same", "worse", "same", "same", "better"] for seat in seats} self.assertEqual(counted(seats, written), {"Mid A": ["same", "same", "same", "same", "better"], "Inherited architect": written["Inherited architect"]}) - self.assertIsInstance(votes([Seat("Mid A", said("better"), ["`a.py:3` `f`: self sufficiency"]), seats[1]]), Failure) + self.assertIsInstance(votes([Seat("Mid A", said("better"), ["Locality, self sufficiency: `a.py:3` `f`: x"]), seats[1]]), Failure) + self.assertIsInstance(votes([Seat("Mid A", said("better"), ["`a.py:3` `f`: Locality: x"]), seats[1]]), Failure) + self.assertEqual(votes(seats), {seat.name: written[seat.name] for seat in seats}) def test_refuses_two_more_seats_once_the_first_two_agree_overall(self): - seats = [Seat(name, said(vote), ["`f.py:1` `f`: x"]) for name, vote in (("Mid A", "worse"), ("Inherited architect", "worse"), ("Maintainability senior", "better"), ("Junior A", "better"))] + seats = [Seat(name, said(vote), ["Overall: `f.py:1` `f`: x"]) for name, vote in (("Mid A", "worse"), ("Inherited architect", "worse"), ("Maintainability senior", "better"), ("Junior A", "better"))] self.assertIsInstance(votes(seats), Failure) def test_takes_the_first_two_seats_then_the_other_two_in_order_and_each_dimensions_vote(self): @@ -135,6 +137,9 @@ class PendingFall(unittest.TestCase): self.assertEqual(standing_ratchet(chunk_entries("", fell + later)), "Ratchet: worse.") self.assertEqual(pending_fall(chunk_entries("", SCORING + paired("2026-10-08T13:00:00Z", "same\n\nFell: Locality"))), ["Locality"]) self.assertEqual(pending_fall(chunk_entries("", "")), []) + rescored = SCORING.replace("12:00:00Z", "15:00:00Z") + self.assertEqual(standing_ratchet(chunk_entries("", fell + later + rescored)), "Ratchet: worse.") + self.assertIsNone(standing_ratchet(chunk_entries("", fell + later + paired("2026-10-08T16:00:00Z", "same")))) def test_reads_only_the_entries_the_default_branch_lacks(self): fell = paired("2026-10-08T13:00:00Z", "better\n\nFell: Locality") @@ -153,6 +158,11 @@ 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") @@ -277,7 +287,7 @@ class LarvReviewTool(unittest.TestCase): Mid A: {worse} - - `bin/a.py:3` `f`: Overall: three branches + - Overall: `bin/a.py:3` `f`: three branches Inherited architect: {same} """ @@ -287,7 +297,7 @@ class LarvReviewTool(unittest.TestCase): self.assertTrue(split.stdout.startswith("Split: Mid A worse, Inherited architect same.")) history = self.checkout / "docs" / "comprehension-history.md" self.assertFalse(history.exists()) - lines += f"\n\t\t\tMaintainability senior: {said('worse')}\n\n\t\t\t- `bin/a.py:3` `f`: Overall: hard\n\n\t\t\tJunior A: {said('worse')}\n" + lines += f"\n\t\t\tMaintainability senior: {said('worse')}\n\n\t\t\t- Overall: `bin/a.py:3` `f`: hard\n\n\t\t\tJunior A: {said('worse')}\n" ran = self.run_tool("record-ruling", self.seats_file(lines)) self.assertEqual(ran.stdout.splitlines()[0], "Ruling: same. Overall votes as counted: Mid A worse, Inherited architect same, Maintainability senior worse, Junior A same (voted worse, naming no place).") recorded = entries(history.read_text()) @@ -296,7 +306,7 @@ class LarvReviewTool(unittest.TestCase): 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): - place = "\n\n- `bin/a.py:3` `f`: Locality, shorter\n\n" + 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) @@ -314,7 +324,7 @@ class LarvReviewTool(unittest.TestCase): self.assertIn("The paired ruling stands: Locality fell and stays at or above the floor of 7.0.", stands.stdout) def test_names_no_fall_on_a_worse_ruling(self): - place = "\n\n- `bin/a.py:3` `f`: Locality, longer\n\n" + 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()) @@ -322,10 +332,11 @@ class LarvReviewTool(unittest.TestCase): 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")) - 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("Under the floor of 7.0, blocking nothing on a run due for no reason besides a fall: Locality 6.50, Self-sufficiency 6.50.", ran.stdout) + 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("Floor: 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.", due.stdout) text = (self.checkout / "docs" / "comprehension-history.md").read_text() self.assertIn("| Mean | 7.00 | 6.50 | 7.00 | 6.50 | 7.00 |", text) diff --git a/docs/decisions.md b/docs/decisions.md index 097b9a5c..8fdd3ac0 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -67,7 +67,7 @@ lilleman decided to ship each of these under the floor on the day listed. Each l ## review: a paired ruling against the last measured commit decides the ratchet, and counts as worse when a dimension it rules fallen is under the floor; the four-seat scoring run checks the floor when a release's items run out, an item names the floor or a ruling names a fallen dimension -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 that adds a scoring run to the history, or whose last added paired ruling is better. 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. 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 names that dimension. Valid while seats reading both versions agree more often than two absolute runs do. +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. 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 names that dimension. Valid while seats reading both versions agree more often than two absolute runs do. ## review: a project decision may suspend the comprehension check for the plan items it names diff --git a/skills/comprehension-panel/seat-prompts.md b/skills/comprehension-panel/seat-prompts.md index 254fe5cf..9e72c368 100644 --- a/skills/comprehension-panel/seat-prompts.md +++ b/skills/comprehension-panel/seat-prompts.md @@ -90,5 +90,5 @@ Same means a reader of either version would find it as easy to understand and ch Report, in this shape: 1. Your rulings, each better, same or worse, in this shape: Navigation , Locality , Shape , Self-sufficiency , Overall -2. The places that decided them, most decisive first. Each: path:line and the unit's name, in the version the place is in, the dimensions it moves, each spelled as in your rulings line, or Overall, and one or two sentences on what reads easier or harder there than in the other version. Rulings with no named place are discarded. +2. The places that decided them, most decisive first. Each opens with the dimensions it moves, spelled as in your rulings line, or Overall, joined by ", " and followed by ": ". Then path:line and the unit's name, in the version the place is in, and one or two sentences on what reads easier or harder there than in the other version. Rulings with no named place are discarded. ``` -- 2.52.0 From 60a00ce54fc295c9eb8af66e9ef8a591a66204af Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 9 Oct 2026 11:27:20 +0200 Subject: [PATCH 05/22] Answer stability round 1: name the base rule's two conditions, skip the plan for a moved Mean run, and test the floor that blocks nothing --- bin/larv_review/main.py | 2 +- bin/larv_review/rules.py | 4 +++- bin/test_larv_review.py | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/bin/larv_review/main.py b/bin/larv_review/main.py index 406168ea..8b10c5fc 100644 --- a/bin/larv_review/main.py +++ b/bin/larv_review/main.py @@ -245,7 +245,7 @@ def record_scoring(default: str, seats_file: pathlib.Path, ids: list[int]) -> Fa recorded = chunk_history(default) if isinstance(recorded, Failure): return recorded - blocking = due_reasons(default, ids, []) + blocking = [] if given.moved_mean else due_reasons(default, ids, []) if isinstance(blocking, Failure): return blocking if not (blocking or given.moved_mean or pending_fall(recorded)): diff --git a/bin/larv_review/rules.py b/bin/larv_review/rules.py index db86ef6d..8c3d9ff3 100644 --- a/bin/larv_review/rules.py +++ b/bin/larv_review/rules.py @@ -131,7 +131,9 @@ def measured_commit(changes: list[HistoryChange]) -> str | None: 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 - if last and last.ruling == "better" or any(not entry.paired for entry in added) and not (last and last.fell): + 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: return change.commit return None diff --git a/bin/test_larv_review.py b/bin/test_larv_review.py index f121841a..3f1bd9de 100644 --- a/bin/test_larv_review.py +++ b/bin/test_larv_review.py @@ -315,6 +315,7 @@ class LarvReviewTool(unittest.TestCase): 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 on a run due for no reason besides a fall: Locality 6.50.", scored.stdout) 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:")) -- 2.52.0 From c386163a5fc81b475b7fb5ef8387b5f1940384a7 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 9 Oct 2026 11:31:17 +0200 Subject: [PATCH 06/22] =?UTF-8?q?Answer=20architecture=20round=204:=20no?= =?UTF-8?q?=20=F0=9F=94=B4=20or=20=F0=9F=9F=A1;=20its=20two=20=F0=9F=9F=A2?= =?UTF-8?q?=20fixes,=20the=20usage=20line=20and=20"opens=20with",=20land?= =?UTF-8?q?=20in=20the=20prose=20round's=20commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From 6a8bbcfff94e9ea452af9bea09fff7a3ba0ab15e Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 9 Oct 2026 11:31:17 +0200 Subject: [PATCH 07/22] Answer prose round 1: split the record-scoring help into one idea per sentence, name the chunk's entries once, fold the changelog bullet into the bullets it changes, and give the decision's amendment its own paragraph --- AGENTS.md | 2 +- CHANGELOG.md | 5 ++- bin/larv_review/history.py | 2 +- bin/larv_review/main.py | 37 +++++++++++----------- bin/larv_review/rules.py | 10 +++--- bin/test_larv_review.py | 6 ++-- docs/decisions.md | 6 ++-- skills/comprehension-panel/seat-prompts.md | 2 +- skills/larv-review/SKILL.md | 6 ++-- 9 files changed, 39 insertions(+), 37 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 041b9c52..91431112 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -12,7 +12,7 @@ Decisions live in `docs/decisions.md`: - loop-claude: each project's model lives in `~/.claude/loop-claude-models.json`, which only loop-claude writes - review: a pass gets at most three rounds per chunk; instead of a fourth, the run asks the human - review: a fix for a ๐Ÿ”ด or ๐ŸŸก reruns the pass that found it and each pass whose trigger names fixes like it; a fix for a ๐ŸŸข, a โ“ or a prose finding reruns none -- review: a paired ruling against the last measured commit decides the ratchet, and counts as worse when a dimension it rules fallen is under the floor; the four-seat scoring run checks the floor when a release's items run out, an item names the floor or a ruling names a fallen dimension +- review: a paired ruling against the last measured commit decides the ratchet, and counts as worse when a dimension it rules fallen is under the floor; the four-seat scoring run checks the floor when a release's items run out or an item names the floor, and also runs when a ruling names a fallen dimension - review: a project decision may suspend the comprehension check for the plan items it names - review: a pass skips only on a precedent: a decision, or a plan item crediting the pass, that the repo held before the chunk began - loop-claude: the archive keeps the raw transcript, and a failed archive stops the loop diff --git a/CHANGELOG.md b/CHANGELOG.md index ca36e7bf..9a875558 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,9 @@ ## Unreleased -- larv-review's paired ruling takes each seat's vote on each dimension too: `Navigation same, Locality worse, Shape same, Self-sufficiency same, Overall better`. A better or same ruling in which a dimension fell calls a scoring run, and counts as worse, blocking the merge, when that dimension's mean is under the floor. Such a run blocks on the fallen dimensions alone and leaves the ratchet's base in place unless the ruling is better. Each place a seat names opens with the dimensions it moves, spelled as in the seat's line, such as `Locality, Shape: `, or the run fails; a dimension's vote counts only where one of the seat's places opens with it. `record-scoring` takes the shipped item IDs too and prints `Floor:` when the means under the floor block the merge. -- 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`). 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 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. - 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; when they disagree, the maintainability senior and Junior A vote too. A ruling needs a lead of two or more votes, else it is same, and a vote that names no place counts as same. 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 the floor blocks only a dimension a paired ruling finds fallen. 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. 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 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/larv_review/history.py index bfb2530d..1cac4902 100644 --- a/bin/larv_review/history.py +++ b/bin/larv_review/history.py @@ -115,7 +115,7 @@ def appended(history: str, entry: str) -> str: 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, with a `Fell:` line when fell names dimensions; a seat's vote that counted as same for want of a place says so.""" + """A paired ruling's entry; 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]) diff --git a/bin/larv_review/main.py b/bin/larv_review/main.py index 8b10c5fc..0cbe9280 100644 --- a/bin/larv_review/main.py +++ b/bin/larv_review/main.py @@ -1,6 +1,6 @@ """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 @@ -19,10 +19,11 @@ round-count prints each pass's count: the highest among the titles opening 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.` It is due when the chunk ships -an item whose tagline names the comprehension floor, when the checkout's history ends on a paired -ruling with a `Fell:` line, 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 +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 the chunk's newest entry is a paired ruling +with a `Fell:` line, 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. @@ -44,11 +45,12 @@ opens with its label, written exactly: `Junior A:`, `Mid A:`, `Maintainability s - Locality: `bin/x.py:12` `run`: ... 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 dimensions it moves, or Overall, spelled as -the seat's line spells them and joined by `, `, then `: `. A dimension's vote counts as same unless one of the seat's places in -backticks, `path:line`, names that dimension; the overall vote counts as same unless the seat names -any such place. 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. +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. @@ -60,13 +62,12 @@ Each line is `Navigation , Locality , Shape , Self-sufficiency , Ove 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 and each one under the floor of {floor}. It exits 1 on a run with -seats that no plan item, release or fall calls. A `Floor:` line says the -means under the floor block the merge, as they do when needs-scoring-run would give a reason -besides a fall. When the history ends on a -paired ruling with a `Fell:` line, it says whether the ruling stands; when a dimension that fell is -under the floor, the ruling counts as worse, and it prints and records a `Ratchet:` line, which -needs-scoring-run repeats as `Still standing:` until a paired ruling follows it. Both read only the entries the default -branch's history lacks. +seats that no plan item, release or fall calls. A `Floor:` line 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 as `Still standing:` +until a paired ruling follows it. 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 @@ -226,7 +227,7 @@ def record_ruling(seats_file: pathlib.Path) -> Failure | 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 it puts {' or '.join(fell)} under the floor of {FLOOR}.") + 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)) diff --git a/bin/larv_review/rules.py b/bin/larv_review/rules.py index 8c3d9ff3..d9639f19 100644 --- a/bin/larv_review/rules.py +++ b/bin/larv_review/rules.py @@ -33,7 +33,7 @@ def votes(seats: list[Seat]) -> dict[str, list[str]] | Failure: def counted(seats: list[Seat], said: dict[str, list[str]]) -> dict[str, list[str]]: - """Each seat's votes as they count: a dimension's vote counts as same unless one of the seat's `path:line` places names that dimension, and the overall vote unless the seat names any such place.""" + """Each seat's votes as they count: a dimension's vote counts as same unless one of the seat's `path:line` places opens with that dimension, and the overall vote unless the seat names any such place.""" return {seat.name: [vote if names_a_place(seat, name) else "same" for name, vote in zip(DIMENSIONS, said[seat.name])] for seat in seats} @@ -63,13 +63,13 @@ def fallen(counted: dict[str, list[str]]) -> list[str]: def chunk_entries(default_history: str, history: str) -> list[Entry]: - """The checkout's entries whose headings the default branch's history lacks, oldest first; of entries with one time, the later in the file is newer.""" + """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) def pending_fall(chunk: list[Entry]) -> list[str]: - """The dimensions that fell in the chunk's newest entry: a paired ruling no scoring run has followed yet.""" + """The dimensions that fell in the chunk's newest entry, empty unless that entry is a paired ruling.""" return chunk[-1].fell if chunk else [] @@ -89,7 +89,7 @@ def floor_verdict(under: list[str], reasons: list[str]) -> str: 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 on a run due for no reason besides a fall: {', '.join(under)}." + 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: @@ -99,7 +99,7 @@ def fall_outcome(fell: list[str], found: list[decimal.Decimal]) -> tuple[str, li 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 stays at or above the floor of {FLOOR}.", [] + return f"The paired ruling stands: {' and '.join(fell)} fell and each stays at or above the floor of {FLOOR}.", [] def means(lines: list[list[str]]) -> list[decimal.Decimal]: diff --git a/bin/test_larv_review.py b/bin/test_larv_review.py index 3f1bd9de..e9783b0b 100644 --- a/bin/test_larv_review.py +++ b/bin/test_larv_review.py @@ -80,7 +80,7 @@ class Seats(unittest.TestCase): 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 stays at or above the floor of 7.0.", [])) + 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): @@ -315,14 +315,14 @@ class LarvReviewTool(unittest.TestCase): 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 on a run due for no reason besides a fall: Locality 6.50.", scored.stdout) + self.assertIn("blocking nothing, as only a fall called this run: Locality 6.50.", scored.stdout) 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:")) 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 stays at or above the floor of 7.0.", stands.stdout) + 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): place = "\n\n- Locality, Overall: `bin/a.py:3` `f`: longer\n\n" diff --git a/docs/decisions.md b/docs/decisions.md index 8fdd3ac0..810eee11 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -65,9 +65,11 @@ lilleman decided to ship each of these under the floor on the day listed. Each l 2026-10-08, lilleman, replacing the 2026-09-30 rule that every fix, a nit's included, re-enters review. Serves goal 1.4. An audit of the four costliest archived chunks (2026-10-08) found nearly every finding that mattered in a pass's first round; later rounds mostly re-checked the last fix, reworded what an earlier round wrote, or contradicted another round on the same line. A round 2 caught real bugs only where a fix changed behaviour, so stability still reruns on every fix that does, and security on every fix that opens an untrusted-input boundary or touches authn/authz, secrets or crypto. Valid while round-2 reviews of nit and prose fixes keep changing nothing a user would notice. -## review: a paired ruling against the last measured commit decides the ratchet, and counts as worse when a dimension it rules fallen is under the floor; the four-seat scoring run checks the floor when a release's items run out, an item names the floor or a ruling names a fallen dimension +## review: a paired ruling against the last measured commit decides the ratchet, and counts as worse when a dimension it rules fallen is under the floor; the four-seat scoring run checks the floor when a release's items run out or an item names the floor, and also runs when a ruling names a fallen dimension -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. 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 names that dimension. Valid while seats reading both versions agree more often than two absolute runs do. +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. ## review: a project decision may suspend the comprehension check for the plan items it names diff --git a/skills/comprehension-panel/seat-prompts.md b/skills/comprehension-panel/seat-prompts.md index 9e72c368..602178c7 100644 --- a/skills/comprehension-panel/seat-prompts.md +++ b/skills/comprehension-panel/seat-prompts.md @@ -90,5 +90,5 @@ Same means a reader of either version would find it as easy to understand and ch Report, in this shape: 1. Your rulings, each better, same or worse, in this shape: Navigation , Locality , Shape , Self-sufficiency , Overall -2. The places that decided them, most decisive first. Each opens with the dimensions it moves, spelled as in your rulings line, or Overall, joined by ", " and followed by ": ". Then path:line and the unit's name, in the version the place is in, and one or two sentences on what reads easier or harder there than in the other version. Rulings with no named place are discarded. +2. The places that decided them, most decisive first. Each opens with the names from your rulings line that it moves, joined by ", " and followed by ": ", such as `Locality, Shape: `. Then `path:line` and the unit's name, each in backticks, in the version the place is in, and one or two sentences on what reads easier or harder there than in the other version. A ruling that no place opens with counts as same. ``` diff --git a/skills/larv-review/SKILL.md b/skills/larv-review/SKILL.md index 5ce944b3..59492a69 100644 --- a/skills/larv-review/SKILL.md +++ b/skills/larv-review/SKILL.md @@ -101,12 +101,12 @@ Then the comprehension check: simulated readers, launched per `~/.claude/skills/ 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, which `needs-scoring-run` repeats as `Still standing:` until a paired ruling follows it. -- **Floor.** `record-scoring` prints `Floor:`, naming means under the floor of 7.0 on a run due for a reason besides a fall. +- **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 as `Still standing:` until a paired ruling follows it. +- **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 they name under it, and the floor at the places the seats name under the lowest dimension. Under the floor alone, 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, 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. Two files of the project keep the records: -- 2.52.0 From 885396370a040709955a8e33a66e4416387db91d Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 9 Oct 2026 11:40:13 +0200 Subject: [PATCH 08/22] Answer architecture round 5: give record_scoring's moved Mean its own path, and take pending_fall from a paired entry alone --- bin/larv_review/main.py | 73 ++++++++++++++-------- bin/larv_review/rules.py | 9 ++- bin/test_larv_review.py | 7 ++- docs/comprehension-history.md | 59 +++++++++++++++++ skills/comprehension-panel/seat-prompts.md | 2 +- skills/larv-review/SKILL.md | 2 +- 6 files changed, 121 insertions(+), 31 deletions(-) diff --git a/bin/larv_review/main.py b/bin/larv_review/main.py index 0cbe9280..688a5b7f 100644 --- a/bin/larv_review/main.py +++ b/bin/larv_review/main.py @@ -10,8 +10,8 @@ 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 +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. round-count prints each pass's count: the highest among the titles opening @@ -23,8 +23,8 @@ prints why the chunk is due a scoring run, or `No scoring run due.` The chunk's 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 the chunk's newest entry is a paired ruling with a `Fell:` line, 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 +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. @@ -36,12 +36,14 @@ opens with its label, written exactly: `Junior A:`, `Mid A:`, `Maintainability s PR #231 at abc1234, against def5678 - Mid A: Navigation same, Locality worse, Shape same, Self-sufficiency same, Overall worse + Mid A: Navigation better, Locality worse, Shape same, Self-sufficiency same, Overall better + - Navigation, Overall: `README.md:40` "Tools": names the tool a symptom leads to - Locality: `bin/x.py:12` `run`: three branches to hold at once - Inherited architect: Navigation same, Locality worse, Shape same, Self-sufficiency same, Overall worse + Inherited architect: Navigation better, Locality worse, Shape same, Self-sufficiency same, Overall better + - Navigation: `README.md:40` "Tools": ... - Locality: `bin/x.py:12` `run`: ... record-ruling takes Mid A's and the inherited architect's votes on each dimension and overall, @@ -50,8 +52,7 @@ joined by `, ` and followed by `: `. A dimension's vote counts as same unless on 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 +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. @@ -61,13 +62,14 @@ architect's lines in that order, or a `Mean:` line alone for a run moved from a 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 and each one under the floor of {floor}. It exits 1 on a run with -seats that no plan item, release or fall calls. A `Floor:` line 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 as `Still standing:` -until a paired ruling follows it. +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. 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 @@ -78,6 +80,7 @@ Exit 1, saying why, on unknown arguments, an unknown item ID, a seats file it ca breaks the shape above, or when git cannot start, finds no checkout or no default branch, cannot fetch origin for ruling-base or needs-scoring-run, or cannot read or write the history or todo.md. """ +import decimal import pathlib import re import sys @@ -85,7 +88,7 @@ import time import typing from larv_review.history import appended, Entry, heading, ruling_entry, scoring_entry, vote_text -from larv_review.rules import base, CAP, chunk_entries, counted, fall_outcome, fallen, FLOOR, floor_verdict, means, PASSES, pending_fall, plan_items, round_counts, ruling, scoring_run_due, standing_ratchet, under_floor, votes +from larv_review.rules import base, CAP, chunk_entries, counted, fall_outcome, fallen, FLOOR, floor_verdict, means, PASSES, pending_fall, plan_items, round_counts, ruling, scoring_run_due, standing_ratchet, uncalled, under_floor, votes from larv_review.git import commit_exists, default_branch, file_at, git, HISTORY, history_changes, landed_since_release, top from larv_review.seats import DIMENSIONS, MEAN, Report, report, score_line, scores from failure import Failure @@ -111,7 +114,8 @@ def main(argv: list[str]) -> int: 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: - print(f"{command} takes item IDs, the numbers in todo.md's ID column: {' '.join(given)}", file=sys.stderr) + 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) return 1 elif not argv: print(USAGE, file=sys.stderr) @@ -236,28 +240,43 @@ def record_scoring(default: str, seats_file: pathlib.Path, ids: list[int]) -> Fa if isinstance(read, Failure): return read title, given = read - found = scores(given.seats) if given.moved_mean is None else {} + if given.moved_mean is not None: + return record_moved_mean(title, given.moved_mean) + found = scores(given.seats) if isinstance(found, Failure): return found - moved = [] if given.moved_mean is None else score_line(MEAN, given.moved_mean) - if isinstance(moved, Failure): - return moved - mean = means(list(found.values()) or [moved]) + mean = means(list(found.values())) recorded = chunk_history(default) if isinstance(recorded, Failure): return recorded - blocking = [] if given.moved_mean else due_reasons(default, ids, []) + blocking = due_reasons(default, ids, []) if isinstance(blocking, Failure): return blocking - if not (blocking or given.moved_mean or pending_fall(recorded)): - return Failure("no plan item, release or fall calls this scoring run; name the item IDs the chunk ships, as needs-scoring-run took them") - print(f"Means: {', '.join(f'{name} {value}' for name, value in zip(DIMENSIONS, mean))}. {floor_verdict(under_floor(mean), blocking)}") - outcome = fall_outcome([] if given.moved_mean else pending_fall(recorded), mean) + fell = pending_fall(recorded) + if not (blocking or fell): + return Failure(uncalled(recorded)) + print(f"Means: {means_text(mean)}.") + print(f"Item IDs read: {', '.join(map(str, ids)) or 'none'}.") + print(floor_verdict(under_floor(mean), blocking)) + outcome = fall_outcome(fell, 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 [])) +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: """The seats file, and the heading its record goes under, once each commit it names is in the checkout.""" try: diff --git a/bin/larv_review/rules.py b/bin/larv_review/rules.py index d9639f19..c4a330f9 100644 --- a/bin/larv_review/rules.py +++ b/bin/larv_review/rules.py @@ -70,7 +70,14 @@ def chunk_entries(default_history: str, history: str) -> list[Entry]: def pending_fall(chunk: list[Entry]) -> list[str]: """The dimensions that fell in the chunk's newest entry, empty unless that entry is a paired ruling.""" - return chunk[-1].fell if chunk else [] + return chunk[-1].fell if chunk and chunk[-1].paired else [] + + +def uncalled(chunk: list[Entry]) -> str: + """Why a scoring run nothing calls fails, and what to do instead.""" + if chunk and not chunk[-1].paired: + 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 standing_ratchet(chunk: list[Entry]) -> str | None: diff --git a/bin/test_larv_review.py b/bin/test_larv_review.py index e9783b0b..76dd868f 100644 --- a/bin/test_larv_review.py +++ b/bin/test_larv_review.py @@ -319,6 +319,8 @@ class LarvReviewTool(unittest.TestCase): 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"))) @@ -338,7 +340,10 @@ class LarvReviewTool(unittest.TestCase): 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("Floor: 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.", due.stdout) + 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) 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) diff --git a/docs/comprehension-history.md b/docs/comprehension-history.md index c74868ce..7521e6cb 100644 --- a/docs/comprehension-history.md +++ b/docs/comprehension-history.md @@ -561,3 +561,62 @@ Inherited architect, decided by: - `bin/larv_review/git.py:56` `file_at` and `bin/larv_review/main.py:247` `history_text`: Locality: two histories, the default branch's and the checkout's - `skills/larv-review/SKILL.md:97` "Seats": Self-sufficiency, against the skill: it needs the tool's help open beside it - `bin/rank_todo.py:386` `parse_row`: Shape, a small gain + +## 2026-10-09T09:35:29Z, PR #232 at 6a8bbcf, against 12d6d75 + +Ruling: same + +Fell: Locality, Shape + +| Seat | Navigation | Locality | Shape | Self-sufficiency | Overall | +|---|---|---|---|---|---| +| Mid A | better | worse | same | better | better | +| Inherited architect | better | worse | worse | same | worse | +| Maintainability senior | better | worse | worse | better | same | +| Junior A | better | worse | worse | better | worse | + +Mid A, decided by: + +- Navigation, Self-sufficiency, Overall: `bin/larv_review/rules.py:118` `round_counts`, with `bin/larv_review/main.py:155` `round_count`: the fourth-round symptom leads from the README's Tools list to a named, tested function, where the base had `skills/larv-review/SKILL.md:58` "Count" +- Self-sufficiency, Overall: `bin/larv_review/history.py:117` `ruling_entry` and `:130` `scoring_entry`: the history format is produced by code and checked by a regex, where the base had `skills/larv-review/SKILL.md:92` "History" +- Locality: `bin/larv_review/main.py:234` `record_scoring`: five conditionals on `given.moved_mean` weave a one-off migration into the main scoring path +- Locality: `bin/metric_bench/main.py:38` and `bin/larv_review/history.py:31` `Entry`: places are parsed in larv_review but used only by metric_bench; `bin/metric_bench/bench.py:87` `resolved` copes with old paths +- Locality: `bin/larv_review/main.py:1` the module docstring: rules compressed into one dense block; the fall, Ratchet and Still standing chain reaches across `bin/larv_review/rules.py:95` `fall_outcome`, `:76` `standing_ratchet` and `bin/larv_review/main.py:164` `needs_scoring_run` +- Navigation: `README.md:66` "Tools": lists larv-review and metric-bench; `skills/larv-review/SKILL.md:46` points at `--help` +- Shape: `bin/larv_review/rules.py:155` `plan_items` and `:169` `scoring_run_due`: a catch-all module, offset by the clean package split and the truthful `skills/comprehension-panel/seat-prompts.md:1` name + +Inherited architect, decided by: + +- Locality: `bin/larv_review/main.py:234` `record_scoring`: whether a run is allowed and whether the floor blocks depend on the plan diff, a pending fall read from the history, and `moved_mean`, checked five times in 25 lines +- Locality: `bin/larv_review/rules.py:71` `pending_fall` and `:76` `standing_ratchet`: commands talk only through the history file, so the outcome depends on the order they ran in +- Locality, Shape: `bin/larv_review/rules.py:127` `measured_commit`: re-parses the history around every merged change and applies a two-clause rule; where it rots first +- Shape: `bin/larv_review/rules.py:1` the module: vote counting, round counting, base search, plan parsing and release emptying under a name that says as little as utils; `HistoryChange` defined in history but built in `bin/larv_review/git.py:66` `history_changes` +- Shape: `bin/metric_bench/main.py:38`: a second tool no review runs, depending on larv_review's history parser; `bin/` gains two packages +- Shape: `bin/metric_bench/bench.py:87` `resolved`: a shim for old path formats +- Navigation: `bin/larv_review/rules.py:118` `round_counts` and `bin/larv_review/main.py:155` `round_count`: the 3am symptom lands on a named command, where the base had `skills/larv-review/SKILL.md:58` "Count" +- Navigation: `README.md:66` "Tools": lists every tool +- Navigation: `skills/comprehension-panel/seat-prompts.md:1`: a truthful name +- Self-sufficiency: `bin/larv_review/main.py:1` the module docstring and `skills/larv-review/SKILL.md:93` "Paired ruling": the code explains itself, but the skill's ratchet text needs the docstring open beside it; ruled same + +Maintainability senior, decided by: + +- Locality: `bin/larv_review/main.py:234` `record_scoring`: tests `given.moved_mean` five times, each branch tied to `chunk_history`, `due_reasons` and `pending_fall` +- Locality: `bin/larv_review/rules.py:71` `pending_fall`: its docstring holds only because `bin/larv_review/history.py:62` `entries` gives scoring runs an empty `fell`; the Fell, Ratchet and Still standing chain spans four files +- Locality, Shape: `bin/metric_bench/main.py:38` `main`: metric-bench imports larv_review's history internals; `bin/metric_bench/main.py:143` `git` repeats `bin/larv_review/git.py:10` `git` +- Shape: `bin/larv_review/rules.py:35` `counted`: a function and a parameter share the name; the module name says nothing of its contents +- Shape: `bin/larv_review/main.py:177` `due_reasons`: main holds commands plus I/O helpers, and the vocabulary grew to seven concepts +- Navigation: `README.md:66` "Tools": every tool listed with its `--help` +- Self-sufficiency, Navigation: `bin/larv_review/rules.py:118` `round_counts`: the round count, vote count and trigger state their rules in code, where the base had `skills/larv-review/SKILL.md:58` "Count" +- Self-sufficiency: `bin/larv_review/main.py:1` the module docstring: an 80-line block of every rule at once, partly cancelling the gain + +Junior A, decided by: + +- Locality, Overall: `bin/larv_review/main.py:234` `record_scoring`: the moved-Mean case is checked five times and decides four things +- Locality, Overall: `bin/larv_review/rules.py:76` `standing_ratchet` and `:71` `pending_fall`: a merge block depends on state earlier commands wrote into the history +- Locality, Shape: `bin/larv_review/rules.py:127` `measured_commit`: walks every merged change's history; restated at `bin/larv_review/main.py:11`, the hardest sentence in the repo +- Shape: `bin/larv_review/rules.py:1` the module: a grab-bag name beside truthfully named siblings +- Shape: `bin/larv_review/seats.py:31` `Report`: the field `read` looks like a verb; `said`, `counted`, `given` and `found` at `bin/larv_review/main.py:217` `record_ruling` need tracing +- Shape: `bin/metric_bench/main.py:38`: the history format is a contract between two tool packages +- Navigation, Self-sufficiency: `bin/larv_review/rules.py:118` `round_counts`: the 3am question lands on one named function, where the base had `skills/larv-review/SKILL.md:58` "Count" +- Navigation: `README.md:66` "Tools": the README lists larv-review and metric-bench +- Self-sufficiency: `bin/larv_review/history.py:62` `entries` and `:117` `ruling_entry`: the history format is enforced in code; the skill needs `--help` open beside it diff --git a/skills/comprehension-panel/seat-prompts.md b/skills/comprehension-panel/seat-prompts.md index 602178c7..f53b8df5 100644 --- a/skills/comprehension-panel/seat-prompts.md +++ b/skills/comprehension-panel/seat-prompts.md @@ -90,5 +90,5 @@ Same means a reader of either version would find it as easy to understand and ch Report, in this shape: 1. Your rulings, each better, same or worse, in this shape: Navigation , Locality , Shape , Self-sufficiency , Overall -2. The places that decided them, most decisive first. Each opens with the names from your rulings line that it moves, joined by ", " and followed by ": ", such as `Locality, Shape: `. Then `path:line` and the unit's name, each in backticks, in the version the place is in, and one or two sentences on what reads easier or harder there than in the other version. A ruling that no place opens with counts as same. +2. The places that decided them, most decisive first. Each opens with the names from your rulings line that it moves, joined by ", " and followed by ": ", such as `Locality, Shape: `. Then `path:line` and the unit's name, each in backticks, in the version the place is in, and one or two sentences on what reads easier or harder there than in the other version. A dimension's ruling that no place opens with counts as same, and the overall ruling does unless you name a place. ``` diff --git a/skills/larv-review/SKILL.md b/skills/larv-review/SKILL.md index 59492a69..84b7a578 100644 --- a/skills/larv-review/SKILL.md +++ b/skills/larv-review/SKILL.md @@ -101,7 +101,7 @@ Then the comprehension check: simulated readers, launched per `~/.claude/skills/ 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 as `Still standing:` until a paired ruling follows it. +- **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. - **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. -- 2.52.0 From 4e728df7cc6be6e0799c2324213e21ff16a40bd2 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 9 Oct 2026 11:40:20 +0200 Subject: [PATCH 09/22] Answer product-owner round 1: print Floor and the item IDs read on lines of their own, say when a scoring run already answered the fall, and show a fall in the help's example (the fixes land in the architecture round 5 commit) -- 2.52.0 From e2e3569e1f18ba3ecaf3ac38dea4e4b5ee1b86c2 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 9 Oct 2026 11:42:32 +0200 Subject: [PATCH 10/22] Answer product-owner round 2: rewrap the help to 100 columns, and say a moved Mean run prints only its means --- bin/larv_review/main.py | 84 ++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/bin/larv_review/main.py b/bin/larv_review/main.py index 688a5b7f..3bea3836 100644 --- a/bin/larv_review/main.py +++ b/bin/larv_review/main.py @@ -10,29 +10,29 @@ 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. +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. -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. +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 the chunk's newest entry is a paired ruling -with a `Fell:` line, 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. +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 the chunk's newest entry is a paired ruling with a +`Fell:` line, 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:`. +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:`. PR #231 at abc1234, against def5678 @@ -46,35 +46,35 @@ opens with its label, written exactly: `Junior A:`, `Mid A:`, `Maintainability s - Navigation: `README.md:40` "Tools": ... - Locality: `bin/x.py:12` `run`: ... -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. +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. 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. +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. 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 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. 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 -- 2.52.0 From 324d65007faee6f3aa6bfc94d9e5d8b614c83acb Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 9 Oct 2026 11:42:32 +0200 Subject: [PATCH 11/22] =?UTF-8?q?Answer=20stability=20round=202:=20no=20?= =?UTF-8?q?=F0=9F=94=B4=20or=20=F0=9F=9F=A1;=20its=20=F0=9F=9F=A2,=20the?= =?UTF-8?q?=20moved=20Mean's=20output,=20lands=20in=20the=20product-owner?= =?UTF-8?q?=20round=202=20commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.52.0 From 9ca791435f7527f537999fc47bb20588c2b8a51c Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 9 Oct 2026 11:47:36 +0200 Subject: [PATCH 12/22] Record the rescore at 324d650: a same ruling in which Locality fell, and a scoring run that puts Locality at 6.50, so the ratchet stands --- docs/comprehension-history.md | 112 ++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/docs/comprehension-history.md b/docs/comprehension-history.md index 7521e6cb..c460ba54 100644 --- a/docs/comprehension-history.md +++ b/docs/comprehension-history.md @@ -620,3 +620,115 @@ Junior A, decided by: - Navigation, Self-sufficiency: `bin/larv_review/rules.py:118` `round_counts`: the 3am question lands on one named function, where the base had `skills/larv-review/SKILL.md:58` "Count" - Navigation: `README.md:66` "Tools": the README lists larv-review and metric-bench - Self-sufficiency: `bin/larv_review/history.py:62` `entries` and `:117` `ruling_entry`: the history format is enforced in code; the skill needs `--help` open beside it + +## 2026-10-09T09:46:21Z, PR #232 at 324d650, against 12d6d75 + +Ruling: same + +Fell: Locality + +| Seat | Navigation | Locality | Shape | Self-sufficiency | Overall | +|---|---|---|---|---|---| +| Mid A | better | worse | worse | better | same | +| Inherited architect | better | worse | worse | better | better | +| Maintainability senior | better | worse | same | better | better | +| Junior A | better | worse | same | same | same | + +Mid A, decided by: + +- Navigation, Self-sufficiency: `bin/larv_review/rules.py:125` `round_counts`: the fourth-round symptom leads to a named function and `CAP`, where the base had prose at `skills/larv-review/SKILL.md:58` "Count" +- Navigation: `README.md:70` "Tools": names larv-review and metric-bench and the rules each holds +- Locality: `bin/larv_review/main.py:238` `record_scoring`: its result depends on which entry is newest in the history; the whole fall, scoring run, Ratchet, Still standing sequence must be held +- Locality: `bin/larv_review/rules.py:71` `pending_fall` and `:83` `standing_ratchet`: the verdict depends on entry order in a file no single function shows +- Locality, Shape: `bin/metric_bench/bench.py:7` and `bin/metric_bench/main.py:38`: metric-bench depends on larv-review's history parser and keeps its own `git` at `bin/metric_bench/main.py:143` +- Shape: `bin/larv_review/rules.py:16` `votes` through `:176` `scoring_run_due`: one module named rules holds four concepts +- Shape: `bin/larv_review/rules.py:35` `counted` and `bin/larv_review/history.py:68` `entries`: one name over two things +- Self-sufficiency: `bin/larv_review/seats.py:38` `report` and `bin/larv_review/history.py:99` `heading`: the seats file and history entry shapes are enforced in code + +Inherited architect, decided by: + +- Navigation, Self-sufficiency, Overall: `bin/larv_review/rules.py:125` `round_counts`, with `bin/larv_review/main.py:159` `round_count`: the 3am question leads to one tested function, where the base had `skills/larv-review/SKILL.md:58` "Count" +- Navigation, Overall: `README.md:70` "Tools": one hop from a symptom to a file +- Locality: `bin/larv_review/main.py:238` `record_scoring`: four helpers over four sources; why `fell` is empty here and not at `bin/larv_review/main.py:168` is stated nowhere at the call +- Locality: `bin/larv_review/rules.py:83` `standing_ratchet` with `bin/larv_review/history.py:12` `RATCHET`: state passes between commands through a markdown file's wording +- Locality, Shape: `bin/larv_review/rules.py:176` `scoring_run_due` and `:192` `emptied`: the due rule packs five conditions +- Shape: `bin/larv_review/rules.py:1` the module: one name over many concepts +- Shape: `bin/metric_bench/main.py:38` and `bin/metric_bench/bench.py:7`: the history format has no home of its own; `bin/larv_review/git.py:7` `HISTORY` sits in a module named for git +- Self-sufficiency: `bin/larv_review/main.py:1` the module docstring: dense, but it ships with the code and states every rule + +Maintainability senior, decided by: + +- Navigation, Self-sufficiency, Overall: `bin/larv_review/rules.py:125` `round_counts`, with `bin/larv_review/main.py:159` `round_count`: the rule is one small tested function, where the base had `skills/larv-review/SKILL.md:58` "Count" +- Navigation: `README.md:66` "Tools": lists both tools with a pointer to each `--help` +- Self-sufficiency: `bin/larv_review/rules.py:35` `counted`, `:50` `ruling` and `:60` `fallen`: each rule stated in a docstring and enforced beside it, where the base had `skills/larv-review/SKILL.md:100` "Ratchet" +- Locality: `bin/larv_review/main.py:238` `record_scoring`: `due_reasons` with an empty fall, then `pending_fall` separately; four places to hold +- Locality: `bin/larv_review/rules.py:71` `pending_fall` and `:83` `standing_ratchet`: order dependence between commands through a file +- Locality, Shape: `bin/larv_review/seats.py:38` `report`, `bin/larv_review/history.py:99` `heading` and `bin/larv_review/main.py:267` `record_moved_mean`: a one-time migration threaded through three modules +- Shape: `bin/metric_bench/main.py:38` and `bin/metric_bench/bench.py:7`: a second tool depends on the first one's parser; `Entry.places` at `bin/larv_review/history.py:40` exists only for it +- Shape: `bin/larv_review/rules.py:176` `scoring_run_due`: a grab-bag module, offset by the truer `skills/comprehension-panel/seat-prompts.md:1` name +- Self-sufficiency: `bin/larv_review/main.py:11` the `ruling-base` paragraph: took three reads, resolved only by `bin/larv_review/rules.py:134` `measured_commit` + +Junior A, decided by: + +- Navigation: `bin/larv_review/rules.py:125` `round_counts`: the symptom leads to the `round-count` command, where the base had `skills/larv-review/SKILL.md:58` "Count" +- Navigation: `README.md:68` "Tools": names both tools; `skills/larv-review/SKILL.md:46` points at the same tool +- Locality: `bin/larv_review/main.py:238` `record_scoring`: whether the run blocks, ratchets or fails depends on three outside sources +- Locality: `bin/larv_review/rules.py:134` `measured_commit`: the base depends on what each past merged change added, by heading time +- Locality: `bin/metric_bench/main.py:38` `entries, Entry`: a second tool parses the history through larv-review's internals +- Shape: `bin/larv_review/rules.py:176` `scoring_run_due`: a catch-all module, offset by the clean split and the truer `skills/comprehension-panel/seat-prompts.md:1` +- Self-sufficiency: `skills/larv-review/SKILL.md:98` "Ruling": the skill needs `bin/larv_review/main.py:1` open beside it, offset by rules now in code + +## 2026-10-09T09:47:25Z, PR #232 at 324d650 + +Ratchet: the paired ruling counts as worse, as Locality fell and Locality is 6.50, under the floor of 7.0. + +| Seat | Navigation | Locality | Shape | Self-sufficiency | Overall | +|---|---|---|---|---|---| +| Junior A | 7 | 6 | 6.5 | 6 | 6.5 | +| Mid A | 7 | 7 | 6.5 | 6.5 | 7 | +| Maintainability senior | 7.5 | 6.5 | 7 | 7 | 7 | +| Inherited architect | 7 | 6.5 | 6.5 | 7 | 7 | +| Mean | 7.13 | 6.50 | 6.63 | 6.63 | 6.88 | + +Junior A, hardest first: + +- `bin/larv_review/main.py:238` `record_scoring`: `due_reasons` with an empty fall means "reasons besides a fall", stated only at `bin/larv_review/rules.py:93` `floor_verdict` +- `bin/larv_review/main.py:1` the module docstring: 80 lines of interlocking rules that never say why +- `bin/larv_review/rules.py:134` `measured_commit`: `not (last and last.fell)` is true with no ruling at all +- `bin/larv_review/rules.py:16` `votes`, with `:35` `counted` and `:40` `names_a_place`: the counting rule spans three files +- `bin/larv_review/history.py:62` `entries` and `:75` `seat_places`: the parser and writer share a format by eye +- `bin/loop_claude/cycle/judge.py:31` `run_judge`: five outcomes, the spec a prompt string +- `bin/loop_claude/transcript_archive.py:30` `archive`: reading-cost parses its outcome text +- `bin/metric_bench/bench.py:87` `resolved`: order-dependent legacy shim + +Mid A, hardest first: + +- `bin/larv_review/main.py:238` `record_scoring`: six exits; `due_reasons` with an empty fall list on purpose +- `bin/larv_review/rules.py:134` `measured_commit`: states what, never why +- `bin/larv_review/rules.py:176` `scoring_run_due`: five inputs in one dense sentence +- `bin/loop_claude/cycle/judge.py:31` `run_judge`: two text checks against two texts +- `bin/loop_claude/transcript_archive.py:30` `archive`: a prose format that is a contract with another tool +- `bin/loop_claude/cycle/states.py:69` `transition`: case order decides behaviour +- `bin/larv_review/rules.py:16` `votes`: parse also enforces the ruling protocol; `counted` shadowed +- `bin/loop_claude/claude_code/entries.py:45` `string_by_human`: heuristics on who wrote an entry + +Maintainability senior, hardest first: + +- `bin/larv_review/main.py:238` `record_scoring`: ten lines, six ideas; `due_reasons`'s third argument means different things to its two callers +- `bin/larv_review/rules.py:134` `measured_commit`: the no-ruling case deduced only from the help +- `bin/larv_review/rules.py:176` `scoring_run_due`: a 70-word docstring and a second document open +- `bin/larv_review/rules.py:16` `votes`: Overall's rule hidden in `DIMENSIONS[-1]`; `None` means split +- `bin/larv_review/history.py:62` `entries`: eight positional arguments counted against a regex +- `bin/larv_review/history.py:99` `heading`: a one-off migration threaded through three files +- `bin/metric_bench/bench.py:87` `resolved`: depends on earlier bullets' order +- `bin/loop_claude/cycle/states.py:69` `transition`: case order, resolved by comments + +Inherited architect, would restructure first: + +- `bin/loop_claude/transcript_archive.py:111` `finished_chunks`, `bin/reading_cost/archive.py:10` `project_archive` and `bin/loop_claude/claude_code/entries.py:5` `parse_entry`: lift the shared formats out of loop_claude +- `bin/larv_review/rules.py:125` `round_counts` and `:176` `scoring_run_due`: split rules into rounds, ruling, base and scoring +- `bin/loop_claude/cycle/judge_reply.py:12` `JUDGE_RULES` and `bin/loop_claude/cycle/worker.py:41` `worker_args`: give the prompt text one home +- `bin/failure.py:5` `Failure`, `bin/file_writes.py:21` `replace_file` and `bin/markdown_sections.py:6` `sections`: tidy the bin root +- `bin/larv_review/git.py:10` `git`, `bin/metric_bench/main.py:143` `git` and `bin/reading_cost/main.py:113` `located`: one git runner +- `bin/loop_claude/project/checkout.py:32` `read_utf8`: a generic reader under a lying name +- `bin/larv_review/main.py:101` `main`: an if/elif dispatch where the next command lands -- 2.52.0 From 4cda8551b41781f6ce649e98ec849501024d1a56 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 9 Oct 2026 11:53:08 +0200 Subject: [PATCH 13/22] Answer architecture round 6: split rules into ruling, rounds, base and scoring modules, read the fall sequence as one Fall state, and give the plan's reasons and the fall's their own functions --- bin/larv_review/base.py | 29 ++++++ bin/larv_review/main.py | 57 ++++++----- bin/larv_review/rounds.py | 14 +++ bin/larv_review/rules.py | 196 ------------------------------------- bin/larv_review/ruling.py | 54 ++++++++++ bin/larv_review/scoring.py | 109 +++++++++++++++++++++ bin/test_larv_review.py | 44 +++++---- 7 files changed, 260 insertions(+), 243 deletions(-) create mode 100644 bin/larv_review/base.py create mode 100644 bin/larv_review/rounds.py delete mode 100644 bin/larv_review/rules.py create mode 100644 bin/larv_review/ruling.py create mode 100644 bin/larv_review/scoring.py diff --git a/bin/larv_review/base.py b/bin/larv_review/base.py new file mode 100644 index 00000000..200c9fdb --- /dev/null +++ b/bin/larv_review/base.py @@ -0,0 +1,29 @@ +from larv_review.history import entries, Entry, 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.""" + 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: + return change.commit + return None + + +def first_ruling(history: str) -> Entry | None: + rulings = sorted((entry for entry in entries(history) if entry.paired), key=lambda entry: entry.time) + return rulings[0] if rulings else None + + +def base(changes: list[HistoryChange], history: str) -> tuple[str, str] | None: + """The commit a paired ruling reads against, and which fallback found it; None leaves the merge base of HEAD and the default branch. history is the default branch's.""" + if found := measured_commit(changes): + return found, "the last measured commit" + if (first := first_ruling(history)) and first.against: + return first.against, "the base the history's first paired ruling names" + return None diff --git a/bin/larv_review/main.py b/bin/larv_review/main.py index 3bea3836..cdabb391 100644 --- a/bin/larv_review/main.py +++ b/bin/larv_review/main.py @@ -87,9 +87,12 @@ import sys import time import typing -from larv_review.history import appended, Entry, heading, ruling_entry, scoring_entry, vote_text -from larv_review.rules import base, CAP, chunk_entries, counted, fall_outcome, fallen, FLOOR, floor_verdict, means, PASSES, pending_fall, plan_items, round_counts, ruling, scoring_run_due, standing_ratchet, uncalled, under_floor, votes +from larv_review.history import appended, heading, ruling_entry, 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.ruling import counted, fallen, ruling, votes from larv_review.seats import DIMENSIONS, MEAN, Report, report, score_line, scores from failure import Failure from rank_todo import ITEMS_HEADER @@ -166,20 +169,21 @@ def round_count(default: str) -> Failure | None: def needs_scoring_run(default: str, ids: list[int]) -> Failure | None: - recorded = chunk_history(default) - if isinstance(recorded, Failure): - return recorded - reasons = due_reasons(default, ids, pending_fall(recorded)) - if isinstance(reasons, Failure): - return reasons + 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 ratchet := standing_ratchet(recorded): - print(f"Still standing: {ratchet} Fix it and rule again.") + if state.ratchet: + print(f"Still standing: {state.ratchet} Fix it and rule again.") return None -def due_reasons(default: str, ids: list[int], fell: list[str]) -> list[str] | Failure: - """Why the chunk is due a scoring run, from the default branch's plan and the checkout's.""" +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 @@ -200,18 +204,18 @@ def due_reasons(default: str, ids: list[int], fell: list[str]) -> list[str] | Fa landed = landed_since_release(default) if isinstance(landed, Failure): return landed - return scoring_run_due(planned, chunk, ids, landed, fell) + return scoring_run_due(planned, chunk, ids, landed) -def chunk_history(default: str) -> list[Entry] | Failure: - """The entries the checkout's history holds and the default branch's lacks.""" +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 chunk_entries(held, read[1]) + return fall(chunk_entries(held, read[1])) def record_ruling(seats_file: pathlib.Path) -> Failure | None: @@ -246,19 +250,18 @@ def record_scoring(default: str, seats_file: pathlib.Path, ids: list[int]) -> Fa if isinstance(found, Failure): return found mean = means(list(found.values())) - recorded = chunk_history(default) - if isinstance(recorded, Failure): - return recorded - blocking = due_reasons(default, ids, []) - if isinstance(blocking, Failure): - return blocking - fell = pending_fall(recorded) - if not (blocking or fell): - return Failure(uncalled(recorded)) + 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), blocking)) - outcome = fall_outcome(fell, mean) + 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 [])) diff --git a/bin/larv_review/rounds.py b/bin/larv_review/rounds.py new file mode 100644 index 00000000..c6d19393 --- /dev/null +++ b/bin/larv_review/rounds.py @@ -0,0 +1,14 @@ +import re + +CAP = 3 +PASSES = ("architecture", "full scan", "security", "stability", "product-owner", "prose") +ROUND = re.compile(r"^Answer (.+?) round ([0-9]+):") + + +def round_counts(titles: list[str]) -> dict[str, int]: + """Each pass's highest round among the branch's `Answer round :` commit titles; a pass with none has 0, and a title naming no known pass adds its name.""" + counts = dict.fromkeys(PASSES, 0) + for title in titles: + if named := ROUND.match(title): + counts[named.group(1)] = max(counts.get(named.group(1), 0), int(named.group(2))) + return counts diff --git a/bin/larv_review/rules.py b/bin/larv_review/rules.py deleted file mode 100644 index c4a330f9..00000000 --- a/bin/larv_review/rules.py +++ /dev/null @@ -1,196 +0,0 @@ -import decimal -import re - -from larv_review.seats import DIMENSIONS, FIRST_SEATS, Seat, SPLIT_SEATS, vote_line -from larv_review.history import entries, Entry, HistoryChange, PLACE -from failure import Failure -from rank_todo import Item, ITEMS_HEADER, parse_row, table_rows - -CAP = 3 -FLOOR = decimal.Decimal("7.0") -PASSES = ("architecture", "full scan", "security", "stability", "product-owner", "prose") -ROUND = re.compile(r"^Answer (.+?) round ([0-9]+):") -VOTES = ("better", "same", "worse") - - -def votes(seats: list[Seat]) -> dict[str, list[str]] | Failure: - """Each seat's five votes as written, in DIMENSIONS' order.""" - names = [seat.name for seat in seats] - if names[:2] != list(FIRST_SEATS) or names[2:] not in ([], list(SPLIT_SEATS)): - return Failure(f"a paired ruling's seats are {' and '.join(FIRST_SEATS)}, then, when their overall votes differ, {' and '.join(SPLIT_SEATS)}, in that order; the file has {', '.join(names) or 'none'}") - said = {} - for seat in seats: - line = vote_line(seat.name, seat.said) - if isinstance(line, Failure): - return line - if unnamed := [place for place in seat.places if not place_dimensions(place)]: - return Failure(f"{seat.name}'s place does not open with the dimensions it moves, each one of {', '.join(DIMENSIONS)}, then `: `: {unnamed[0]}") - said[seat.name] = line - first, second, *more = (each[-1] for each in counted(seats, said).values()) - if more and first == second: - return Failure(f"{' and '.join(FIRST_SEATS)} both count as {first} overall, which settles the ruling; drop the other seats' lines") - return said - - -def counted(seats: list[Seat], said: dict[str, list[str]]) -> dict[str, list[str]]: - """Each seat's votes as they count: a dimension's vote counts as same unless one of the seat's `path:line` places opens with that dimension, and the overall vote unless the seat names any such place.""" - return {seat.name: [vote if names_a_place(seat, name) else "same" for name, vote in zip(DIMENSIONS, said[seat.name])] for seat in seats} - - -def names_a_place(seat: Seat, dimension: str) -> bool: - return any(PLACE.search(place) and (dimension == DIMENSIONS[-1] or dimension in place_dimensions(place)) for place in seat.places) - - -def place_dimensions(place: str) -> list[str]: - """The dimensions a place opens with, as in `Locality, Shape: `path:line` ...`; empty when any name before the first `: ` is no dimension.""" - named = place.partition(": ")[0].split(", ") - return named if all(name in DIMENSIONS for name in named) else [] - - -def ruling(counted: list[str]) -> str | None: - """The vote that leads each other vote by two or more, else same; None when only the first two seats voted and they differ, so two more must vote.""" - if len(counted) == 2 and counted[0] != counted[1]: - return None - for vote in VOTES: - if all(counted.count(vote) >= counted.count(other) + 2 for other in VOTES if other != vote): - return vote - return "same" - - -def fallen(counted: dict[str, list[str]]) -> list[str]: - """Each dimension, Overall aside, that the seats rule worse by a lead of two.""" - return [name for name, column in zip(DIMENSIONS[:-1], zip(*counted.values())) if ruling(list(column)) == "worse"] - - -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) - - -def pending_fall(chunk: list[Entry]) -> list[str]: - """The dimensions that fell in the chunk's newest entry, empty unless that entry is a paired ruling.""" - return chunk[-1].fell if chunk and chunk[-1].paired else [] - - -def uncalled(chunk: list[Entry]) -> str: - """Why a scoring run nothing calls fails, and what to do instead.""" - if chunk and not chunk[-1].paired: - 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 standing_ratchet(chunk: list[Entry]) -> str | None: - """The chunk's newest `Ratchet:` line, unless a paired ruling has followed it.""" - for entry in reversed(chunk): - if entry.paired: - return None - if entry.ratchet: - return entry.ratchet - return None - - -def floor_verdict(under: list[str], reasons: list[str]) -> str: - """Whether the means under the floor block the merge: they do on a run due for a reason besides a fall.""" - 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 means(lines: list[list[str]]) -> list[decimal.Decimal]: - """The mean of each score across the lines, in DIMENSIONS' order, rounded half up to two decimals.""" - return [mean([decimal.Decimal(score) for score in column]) for column in zip(*lines)] - - -def mean(values: list[decimal.Decimal]) -> decimal.Decimal: - return (sum(values, decimal.Decimal(0)) / len(values)).quantize(decimal.Decimal("0.01"), decimal.ROUND_HALF_UP) - - -def under_floor(found: list[decimal.Decimal]) -> list[str]: - return [f"{name} {value}" for name, value in zip(DIMENSIONS, found) if value < FLOOR] - - -def round_counts(titles: list[str]) -> dict[str, int]: - """Each pass's highest round among the branch's `Answer round :` commit titles; a pass with none has 0, and a title naming no known pass adds its name.""" - counts = dict.fromkeys(PASSES, 0) - for title in titles: - if named := ROUND.match(title): - counts[named.group(1)] = max(counts.get(named.group(1), 0), int(named.group(2))) - return counts - - -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.""" - 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: - return change.commit - return None - - -def first_ruling(history: str) -> Entry | None: - rulings = sorted((entry for entry in entries(history) if entry.paired), key=lambda entry: entry.time) - return rulings[0] if rulings else None - - -def base(changes: list[HistoryChange], history: str) -> tuple[str, str] | None: - """The commit a paired ruling reads against, and which fallback found it; None leaves the merge base of HEAD and the default branch. history is the default branch's.""" - if found := measured_commit(changes): - return found, "the last measured commit" - if (first := first_ruling(history)) and first.against: - return first.against, "the base the history's first paired ruling names" - return None - - -def plan_items(todo: str) -> list[Item] | Failure: - """Each row of a todo.md's items table, read as `rank_todo.py` reads it.""" - table = table_rows(todo.splitlines(), ITEMS_HEADER) - if isinstance(table, Failure): - return table - items = [] - for row in table.rows: - item = parse_row(row) - if isinstance(item, Failure): - return item - items.append(item) - return items - - -def scoring_run_due(before: list[Item], after: list[Item], ships: list[int], landed: bool, fell: list[str]) -> list[str] | Failure: - """Why the chunk takes a scoring run, empty when it does not. before is the default branch's plan, after the chunk's, ships the IDs it ships, landed whether the default branch holds a commit after its newest release tag, and fell what pending_fall finds in the chunk's history. Work has landed towards an emptied release when the chunk ships one of its items, or when it is the next release, the earliest before names, and landed holds.""" - plan = {item.id: item for item in before + after} - if unknown := sorted(set(ships) - set(plan)): - return Failure(f"neither plan holds item {', '.join(map(str, unknown))}") - shipped = [plan[id_] for id_ in ships] - reasons = [f"ships item {item.id}, which names the comprehension floor" for item in shipped if "comprehension floor" in item.tagline.lower()] - if fell: - reasons.append(f"has a paired ruling in which {' and '.join(fell)} fell") - next_release = min((item.release for item in before), default=None) - for release in emptied(before, after, shipped): - if any(item.release == release for item in shipped) or (release == next_release and landed): - reasons.append(f"leaves release {'.'.join(map(str, release))} with no plan item") - return reasons - - -def emptied(before: list[Item], after: list[Item], shipped: list[Item]) -> list[tuple[int, int, int]]: - """Each release the default branch's plan or a shipped item names that the chunk's plan, less the shipped items, names no longer.""" - named = {item.release for item in before + shipped} - left = {item.release for item in after if item.id not in {ship.id for ship in shipped}} - return sorted(named - left) diff --git a/bin/larv_review/ruling.py b/bin/larv_review/ruling.py new file mode 100644 index 00000000..9dfc2bd4 --- /dev/null +++ b/bin/larv_review/ruling.py @@ -0,0 +1,54 @@ +from larv_review.seats import DIMENSIONS, FIRST_SEATS, Seat, SPLIT_SEATS, vote_line +from failure import Failure +from larv_review.history import PLACE + +VOTES = ("better", "same", "worse") + + +def votes(seats: list[Seat]) -> dict[str, list[str]] | Failure: + """Each seat's five votes as written, in DIMENSIONS' order.""" + names = [seat.name for seat in seats] + if names[:2] != list(FIRST_SEATS) or names[2:] not in ([], list(SPLIT_SEATS)): + return Failure(f"a paired ruling's seats are {' and '.join(FIRST_SEATS)}, then, when their overall votes differ, {' and '.join(SPLIT_SEATS)}, in that order; the file has {', '.join(names) or 'none'}") + said = {} + for seat in seats: + line = vote_line(seat.name, seat.said) + if isinstance(line, Failure): + return line + if unnamed := [place for place in seat.places if not place_dimensions(place)]: + return Failure(f"{seat.name}'s place does not open with the dimensions it moves, each one of {', '.join(DIMENSIONS)}, then `: `: {unnamed[0]}") + said[seat.name] = line + first, second, *more = (each[-1] for each in counted(seats, said).values()) + if more and first == second: + return Failure(f"{' and '.join(FIRST_SEATS)} both count as {first} overall, which settles the ruling; drop the other seats' lines") + return said + + +def counted(seats: list[Seat], said: dict[str, list[str]]) -> dict[str, list[str]]: + """Each seat's votes as they count: a dimension's vote counts as same unless one of the seat's `path:line` places opens with that dimension, and the overall vote unless the seat names any such place.""" + return {seat.name: [vote if names_a_place(seat, name) else "same" for name, vote in zip(DIMENSIONS, said[seat.name])] for seat in seats} + + +def names_a_place(seat: Seat, dimension: str) -> bool: + return any(PLACE.search(place) and (dimension == DIMENSIONS[-1] or dimension in place_dimensions(place)) for place in seat.places) + + +def place_dimensions(place: str) -> list[str]: + """The dimensions a place opens with, as in `Locality, Shape: `path:line` ...`; empty when any name before the first `: ` is no dimension.""" + named = place.partition(": ")[0].split(", ") + return named if all(name in DIMENSIONS for name in named) else [] + + +def ruling(counted: list[str]) -> str | None: + """The vote that leads each other vote by two or more, else same; None when only the first two seats voted and they differ, so two more must vote.""" + if len(counted) == 2 and counted[0] != counted[1]: + return None + for vote in VOTES: + if all(counted.count(vote) >= counted.count(other) + 2 for other in VOTES if other != vote): + return vote + return "same" + + +def fallen(counted: dict[str, list[str]]) -> list[str]: + """Each dimension, Overall aside, that the seats rule worse by a lead of two.""" + return [name for name, column in zip(DIMENSIONS[:-1], zip(*counted.values())) if ruling(list(column)) == "worse"] diff --git a/bin/larv_review/scoring.py b/bin/larv_review/scoring.py new file mode 100644 index 00000000..f5ccaa17 --- /dev/null +++ b/bin/larv_review/scoring.py @@ -0,0 +1,109 @@ +import dataclasses +import decimal +import itertools + +from larv_review.seats import DIMENSIONS +from larv_review.history import entries, Entry +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 means(lines: list[list[str]]) -> list[decimal.Decimal]: + """The mean of each score across the lines, in DIMENSIONS' order, rounded half up to two decimals.""" + return [mean([decimal.Decimal(score) for score in column]) for column in zip(*lines)] + + +def mean(values: list[decimal.Decimal]) -> decimal.Decimal: + return (sum(values, decimal.Decimal(0)) / len(values)).quantize(decimal.Decimal("0.01"), decimal.ROUND_HALF_UP) + + +def under_floor(found: list[decimal.Decimal]) -> list[str]: + return [f"{name} {value}" for name, value in zip(DIMENSIONS, found) if value < FLOOR] + + +def plan_items(todo: str) -> list[Item] | Failure: + """Each row of a todo.md's items table, read as `rank_todo.py` reads it.""" + table = table_rows(todo.splitlines(), ITEMS_HEADER) + if isinstance(table, Failure): + return table + items = [] + for row in table.rows: + item = parse_row(row) + if isinstance(item, Failure): + return item + items.append(item) + return items + + +def scoring_run_due(before: list[Item], after: list[Item], ships: list[int], landed: bool) -> list[str] | Failure: + """Why the plan calls a scoring run, empty when it does not. before is the default branch's plan, after the chunk's, ships the IDs it ships, and landed whether the default branch holds a commit after its newest release tag. Work has landed towards an emptied release when the chunk ships one of its items, or when it is the next release, the earliest before names, and landed holds.""" + plan = {item.id: item for item in before + after} + if unknown := sorted(set(ships) - set(plan)): + return Failure(f"neither plan holds item {', '.join(map(str, unknown))}") + shipped = [plan[id_] for id_ in ships] + reasons = [f"ships item {item.id}, which names the comprehension floor" for item in shipped if "comprehension floor" in item.tagline.lower()] + next_release = min((item.release for item in before), default=None) + for release in emptied(before, after, shipped): + if any(item.release == release for item in shipped) or (release == next_release and landed): + reasons.append(f"leaves release {'.'.join(map(str, release))} with no plan item") + return reasons + + +def emptied(before: list[Item], after: list[Item], shipped: list[Item]) -> list[tuple[int, int, int]]: + """Each release the default branch's plan or a shipped item names that the chunk's plan, less the shipped items, names no longer.""" + named = {item.release for item in before + shipped} + left = {item.release for item in after if item.id not in {ship.id for ship in shipped}} + return sorted(named - left) diff --git a/bin/test_larv_review.py b/bin/test_larv_review.py index 76dd868f..dc4aa1f4 100644 --- a/bin/test_larv_review.py +++ b/bin/test_larv_review.py @@ -10,11 +10,14 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) from larv_review.history import appended, entries, HistoryChange, Place, ruling_entry -from larv_review.rules import base, chunk_entries, counted, fall_outcome, fallen, first_ruling, means, measured_commit, pending_fall, plan_items, round_counts, ruling, scoring_run_due, standing_ratchet, under_floor, votes +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 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 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" @@ -131,20 +134,20 @@ class History(unittest.TestCase): class PendingFall(unittest.TestCase): 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(pending_fall(chunk_entries("", SCORING + fell)), ["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(pending_fall(chunk_entries("", fell + later)), []) - self.assertEqual(standing_ratchet(chunk_entries("", fell + later)), "Ratchet: worse.") - self.assertEqual(pending_fall(chunk_entries("", SCORING + paired("2026-10-08T13:00:00Z", "same\n\nFell: Locality"))), ["Locality"]) - self.assertEqual(pending_fall(chunk_entries("", "")), []) + 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(standing_ratchet(chunk_entries("", fell + later + rescored)), "Ratchet: worse.") - self.assertIsNone(standing_ratchet(chunk_entries("", fell + later + paired("2026-10-08T16:00:00Z", "same")))) + 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(pending_fall(chunk_entries(merged, fell + merged)), ["Locality"]) + self.assertEqual(fall(chunk_entries(merged, fell + merged)).pending, ["Locality"]) class Base(unittest.TestCase): @@ -190,31 +193,32 @@ class ScoringRunDue(unittest.TestCase): def test_is_due_for_an_item_naming_the_floor(self): plan = [item(1, (0, 1, 0), "**Lift the project to the Comprehension floor.**"), item(2, (0, 1, 0))] - self.assertEqual(scoring_run_due(plan, plan, [1], True, []), ["ships item 1, which names the comprehension floor"]) - self.assertIsInstance(scoring_run_due(plan, plan, [9], True, []), Failure) + self.assertEqual(scoring_run_due(plan, plan, [1], True), ["ships item 1, which names the comprehension floor"]) + self.assertIsInstance(scoring_run_due(plan, plan, [9], True), Failure) def test_is_due_when_the_chunk_ships_a_releases_last_item(self): plan = [item(1, (0, 1, 0)), item(2, (0, 2, 0))] - self.assertEqual(scoring_run_due(plan, plan, [1], False, []), ["leaves release 0.1.0 with no plan item"]) - self.assertEqual(scoring_run_due(plan, plan + [item(3, (0, 1, 0))], [1], True, []), []) + self.assertEqual(scoring_run_due(plan, plan, [1], False), ["leaves release 0.1.0 with no plan item"]) + self.assertEqual(scoring_run_due(plan, plan + [item(3, (0, 1, 0))], [1], True), []) def test_is_due_when_the_chunk_removes_the_next_releases_last_item_after_work_landed(self): before = [item(1, (0, 1, 0)), item(2, (0, 1, 0)), item(3, (0, 2, 0))] after = [item(2, (0, 1, 0)), item(3, (0, 2, 0))] - self.assertEqual(scoring_run_due(before, after, [2], True, []), ["leaves release 0.1.0 with no plan item"]) - self.assertEqual(scoring_run_due(before, after, [], True, []), []) + self.assertEqual(scoring_run_due(before, after, [2], True), ["leaves release 0.1.0 with no plan item"]) + self.assertEqual(scoring_run_due(before, after, [], True), []) emptied = [item(3, (0, 2, 0))] - self.assertEqual(scoring_run_due(before, emptied, [2], False, []), ["leaves release 0.1.0 with no plan item"]) - self.assertEqual(scoring_run_due(before, emptied, [], True, []), ["leaves release 0.1.0 with no plan item"]) - self.assertEqual(scoring_run_due(before, emptied, [], False, []), []) + self.assertEqual(scoring_run_due(before, emptied, [2], False), ["leaves release 0.1.0 with no plan item"]) + self.assertEqual(scoring_run_due(before, emptied, [], True), ["leaves release 0.1.0 with no plan item"]) + self.assertEqual(scoring_run_due(before, emptied, [], False), []) def test_is_due_when_a_better_ruling_hides_a_fall(self): plan = [item(1, (0, 1, 0)), item(2, (0, 1, 0))] - self.assertEqual(scoring_run_due(plan, plan, [], True, ["Locality"]), ["has a paired ruling in which Locality fell"]) + 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_is_not_due_when_a_later_release_loses_its_last_item_unshipped(self): before = [item(1, (0, 1, 0)), item(3, (0, 2, 0))] - self.assertEqual(scoring_run_due(before, before[:1], [], True, []), []) + self.assertEqual(scoring_run_due(before, before[:1], [], True), []) class LarvReviewTool(unittest.TestCase): -- 2.52.0 From a83003980c46a80656b8755585588d579ba344ee Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 9 Oct 2026 11:55:06 +0200 Subject: [PATCH 14/22] Fix the auditors' round-6 nits: list the fall's reason last in the help, as it prints, and name the fall tests for the Fall state --- bin/larv_review/main.py | 10 +++++----- bin/test_larv_review.py | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/bin/larv_review/main.py b/bin/larv_review/main.py index cdabb391..12b8ee57 100644 --- a/bin/larv_review/main.py +++ b/bin/larv_review/main.py @@ -22,11 +22,11 @@ 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 the chunk's newest entry is a paired ruling with a -`Fell:` line, 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. +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. 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 diff --git a/bin/test_larv_review.py b/bin/test_larv_review.py index dc4aa1f4..12bb6300 100644 --- a/bin/test_larv_review.py +++ b/bin/test_larv_review.py @@ -131,7 +131,12 @@ class History(unittest.TestCase): self.assertEqual([entry.paired for entry in found], [False, True]) -class PendingFall(unittest.TestCase): +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"]) @@ -211,11 +216,6 @@ class ScoringRunDue(unittest.TestCase): self.assertEqual(scoring_run_due(before, emptied, [], True), ["leaves release 0.1.0 with no plan item"]) self.assertEqual(scoring_run_due(before, emptied, [], False), []) - def test_is_due_when_a_better_ruling_hides_a_fall(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_is_not_due_when_a_later_release_loses_its_last_item_unshipped(self): before = [item(1, (0, 1, 0)), item(3, (0, 2, 0))] self.assertEqual(scoring_run_due(before, before[:1], [], True), []) -- 2.52.0 From e694e4154e697fe16125def09c60f1aaab39147f Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 9 Oct 2026 12:22:13 +0200 Subject: [PATCH 15/22] Answer architecture round 7: decide a fall inside record-ruling with the scoring seats' scores, give the history format one owner in comprehension_history, drop the moved Mean path, and plan the archive and judge restructures in items 83 and 62 --- .gitignore | 1 + CHANGELOG.md | 4 +- .../history.py => comprehension_history.py} | 77 +++--- bin/larv_review/base.py | 11 +- bin/larv_review/git.py | 11 +- bin/larv_review/main.py | 242 ++++++++---------- bin/larv_review/ruling.py | 4 +- bin/larv_review/scoring.py | 60 +---- bin/larv_review/seats.py | 33 +-- bin/metric_bench/bench.py | 2 +- bin/metric_bench/main.py | 2 +- bin/test_larv_review.py | 130 ++++------ bin/test_metric_bench.py | 2 +- bin/test_types.py | 2 +- docs/decisions.md | 2 +- skills/larv-review/SKILL.md | 12 +- todo.md | 6 + 17 files changed, 238 insertions(+), 363 deletions(-) rename bin/{larv_review/history.py => comprehension_history.py} (54%) 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. -- 2.52.0 From 2630291af225bda732fe4d091d3a5fd2d294514c Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 9 Oct 2026 12:29:37 +0200 Subject: [PATCH 16/22] Answer architecture round 8: refuse a scoring run the plan does not call and a second entry on one read, keep a fall's scoring places apart for metric-bench, let the history format write the Ruling line, decide the fall step in a pure function, and state the base rule as the code holds it --- CHANGELOG.md | 4 +- bin/comprehension_history.py | 38 +++++++---- bin/larv_review/base.py | 11 ++- bin/larv_review/git.py | 10 +-- bin/larv_review/main.py | 127 ++++++++++++++++++++--------------- bin/larv_review/scoring.py | 14 +++- bin/metric_bench/main.py | 11 +-- bin/test_larv_review.py | 44 +++++++----- bin/test_metric_bench.py | 2 +- docs/decisions.md | 4 +- skills/larv-review/SKILL.md | 2 +- todo.md | 4 +- 12 files changed, 160 insertions(+), 111 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab7cc171..0b635c77 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 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. +- 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` and refuse a second entry on the same commit; `record-scoring` refuses a run the plan does not call, and 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. 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 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 that added a scoring run to `docs/comprehension-history.md`, or whose last ruling there is better. 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/comprehension_history.py b/bin/comprehension_history.py index 62592a7b..c768335a 100644 --- a/bin/comprehension_history.py +++ b/bin/comprehension_history.py @@ -1,4 +1,5 @@ import dataclasses +import decimal import re import time @@ -18,7 +19,8 @@ MID = "Mid A" 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}):$") +RULED_PLACES = re.compile(rf"^.+, {DECIDED_BY}:$") +SCORED_PLACES = re.compile(rf"^.+, ({HARDEST_FIRST}|{RESTRUCTURE_FIRST}):$") SENIOR = "Maintainability senior" STAMP = "%Y-%m-%dT%H:%M:%SZ" TITLE = "# Comprehension history\n" @@ -39,13 +41,14 @@ class Place: @dataclasses.dataclass(frozen=True) class Entry: - """One paired ruling, which names the commit it was against and its ruling, or one scoring run, which names neither.""" + """One paired ruling, which names the commit it was against and its ruling, or one scoring run, which names neither. A scoring run's places, or those of the scores a fall called into a ruling, are scored_places.""" heading: str time: str commit: str against: str | None ruling: str | None - places: list[Place] + ruled_places: list[Place] + scored_places: list[Place] @property def paired(self) -> bool: @@ -55,6 +58,7 @@ class Entry: @dataclasses.dataclass(frozen=True) class Heading: title: str + label: str commit: str against: str | None @@ -64,7 +68,7 @@ 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] + means: list[decimal.Decimal] def entries(history: str) -> list[Entry]: @@ -74,15 +78,21 @@ def entries(history: str) -> list[Entry]: if named := HEADING.match(heading): body = "\n".join(bodies) ruling = RULING.search(body) - found.append(Entry(heading, named.group(1), named.group(3), named.group(4), ruling.group(1) if ruling 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, RULED_PLACES), seat_places(body, SCORED_PLACES))) return found -def seat_places(body: str) -> list[Place]: +def recorded(history: str, read: str) -> bool: + """Whether the history holds an entry on what a seats file's first line says the seats read.""" + return any(entry.heading.partition(", ")[2] == read for entry in entries(history)) + + +def seat_places(body: str, labels: re.Pattern[str]) -> list[Place]: + """The places under each seat label labels matches.""" places = [] listing = False for line in body.splitlines(): - if SEAT_PLACES.match(line): + if labels.match(line): listing = True elif listing and line.startswith("- "): places += bullet_places(line) @@ -106,7 +116,7 @@ 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 Heading(title, named.group(2), named.group(3), named.group(4)) return Failure(f"the seats file's first line is not ` at {', against ' if paired else ''}`: {read}") @@ -116,12 +126,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]], 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.""" +def ruling_entry(title: str, seats: list[Seat], said: dict[str, list[str]], counted: dict[str, list[str]], ruled: str, notes: list[str], scoring: Scoring | None) -> str: + """A paired ruling's entry, with any notes, such as why a fall decided it, and the scores 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] 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) + return entry_text(title, [f"Ruling: {ruled}", *notes], tables, labels) def vote_text(dimension: str, said: str, counted: str) -> str: @@ -130,12 +140,12 @@ 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, lines: list[str], scoring: Scoring) -> str: - return entry_text(title, lines, [scores_table(scoring)], scoring_labels(scoring.seats)) +def scoring_entry(title: str, scoring: Scoring) -> str: + return entry_text(title, [], [scores_table(scoring)], scoring_labels(scoring.seats)) def scores_table(scoring: Scoring) -> list[list[str]]: - return [["Seat", *DIMENSIONS], *([seat, *values] for seat, values in scoring.scores.items()), [MEAN, *scoring.means]] + return [["Seat", *DIMENSIONS], *([seat, *values] for seat, values in scoring.scores.items()), [MEAN, *map(str, scoring.means)]] def scoring_labels(seats: list[Seat]) -> list[tuple[str, list[str]]]: diff --git a/bin/larv_review/base.py b/bin/larv_review/base.py index 538d90cf..56af7922 100644 --- a/bin/larv_review/base.py +++ b/bin/larv_review/base.py @@ -1,5 +1,14 @@ +import dataclasses + from comprehension_history import entries, Entry -from larv_review.git import HistoryChange + + +@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 measured_commit(changes: list[HistoryChange]) -> str | None: diff --git a/bin/larv_review/git.py b/bin/larv_review/git.py index fca2c324..b574a14e 100644 --- a/bin/larv_review/git.py +++ b/bin/larv_review/git.py @@ -1,17 +1,9 @@ -import dataclasses import re import subprocess from failure import Failure from comprehension_history import HISTORY - - -@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 +from larv_review.base import HistoryChange def git(*args: str) -> str | Failure: diff --git a/bin/larv_review/main.py b/bin/larv_review/main.py index ebccd8ec..391e203c 100644 --- a/bin/larv_review/main.py +++ b/bin/larv_review/main.py @@ -1,11 +1,11 @@ """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. 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 +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 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 @@ -60,13 +60,15 @@ scoring seats on the same commit and run it again with their scores file. With t 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 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}. +record-scoring takes the scores file of a run needs-scoring-run calls, whose first line names no +`, against`, and the same item IDs, and exits 1 when they call no run: each scoring run moves the +ratchet's base. It appends the seats' scores and their means, rounded half up to two decimals, +prints the means and, when a mean is under the floor of {floor}, a line opening `Floor:` naming +each one, which blocks the merge. 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. Each commit that 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. It exits 1 +when the history already holds an entry on what that line reads. 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 @@ -79,18 +81,18 @@ import sys import time import typing -from comprehension_history import appended, DIMENSIONS, heading, HISTORY, ruling_entry, Scoring, scoring_entry, vote_text +from comprehension_history import appended, DIMENSIONS, heading, Heading, HISTORY, recorded, 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.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 failure import Failure -from larv_review.scoring import fall_ruling, FLOOR, means, plan_items, scoring_run_due, under_floor +from larv_review.scoring import fall_ruling, fall_step, 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: @@ -106,10 +108,11 @@ def main(argv: list[str]) -> int: 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) 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) + 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) return 1 elif not argv: print(USAGE, file=sys.stderr) @@ -160,6 +163,15 @@ def round_count(default: str) -> Failure | None: def needs_scoring_run(default: str, ids: list[int]) -> Failure | None: + reasons = plan_reasons(default, ids) + 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 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 @@ -180,18 +192,14 @@ def needs_scoring_run(default: str, ids: list[int]) -> Failure | None: landed = landed_since_release(default) if isinstance(landed, Failure): return 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 + return scoring_run_due(planned, chunk, ids, landed) 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 + named, given = read said = votes(given.seats) if isinstance(said, Failure): return said @@ -202,49 +210,52 @@ def record_ruling(votes_file: pathlib.Path, scores_file: pathlib.Path | None = N 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 [] - 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 + notes = [] + match fall_step(fell, scores_file is not None): + case "ask": + print(f"Fell: {', '.join(fell)}, in a {ruled} ruling. Launch the four scoring seats on {named.label} at {named.commit}, write their lines to a scores file, and run this again with both files.") + return None + case "refuse": + return Failure(f"no dimension fell in this {ruled} ruling, so it takes no scores file") if scores_file: - scored = read_scoring(scores_file, given.read.partition(", against")[0]) + scored = read_scoring(scores_file, named) 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)) + ruled, why = fall_ruling(ruled, fell, scoring.means) + notes = [why] + print(f"Ruling: {ruled}. {' '.join(notes + [f'Overall votes as counted: {tally}.'])}") + return append(given.read, ruling_entry(named.title, given.seats, said, count, ruled, notes, scoring)) -def record_scoring(scores_file: pathlib.Path) -> Failure | None: +def record_scoring(default: str, scores_file: pathlib.Path, ids: list[int]) -> Failure | None: read = read_seats(scores_file, paired=False) if isinstance(read, Failure): return read - title, given = read + named, given = read 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)) + reasons = plan_reasons(default, ids) + if isinstance(reasons, Failure): + return reasons + if not reasons: + return Failure("no plan item or release calls this scoring run; name the item IDs the chunk ships, as needs-scoring-run took them, or record a fall's scores with record-ruling") + print(f"Means: {', '.join(f'{name} {value}' for name, value in zip(DIMENSIONS, scoring.means))}.") + if under := under_floor(scoring.means): + print(f"Floor: {', '.join(under)} under the floor of {FLOOR} block the merge, as the chunk {' and '.join(reasons)}.") + return append(given.read, scoring_entry(named.title, scoring)) -def read_scoring(scores_file: pathlib.Path, read: str) -> Scoring | Failure: +def read_scoring(scores_file: pathlib.Path, votes: Heading) -> 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}") + read = read_seats(scores_file, paired=False) + if isinstance(read, Failure): + return read + named, given = read + if (named.label, named.commit) != (votes.label, votes.commit): + return Failure(f"the scores file's first line is not `{votes.label} at {votes.commit}`, as the votes file reads: {given.read}") return scored_seats(given) @@ -252,10 +263,10 @@ def scored_seats(given: SeatsFile) -> Scoring | Failure: found = scores(given.seats) if isinstance(found, Failure): return found - return Scoring(given.seats, found, [str(value) for value in means(list(found.values()))]) + return Scoring(given.seats, found, means(list(found.values()))) -def read_seats(path: pathlib.Path, paired: bool) -> tuple[str, SeatsFile] | Failure: +def read_seats(path: pathlib.Path, paired: bool) -> tuple[Heading, SeatsFile] | Failure: """The seats file, and the heading its record goes under, once each commit it names is in the checkout.""" try: given = seats_file(path.read_text(encoding="utf-8")) @@ -268,19 +279,25 @@ def read_seats(path: pathlib.Path, paired: bool) -> tuple[str, SeatsFile] | Fail return named if unknown := [commit for commit in (named.commit, named.against) if commit and not commit_exists(commit)]: return Failure(f"the seats file names {', '.join(unknown)}, which is no commit in this checkout") - return named.title, given + return named, given -def append(entry: str) -> Failure | None: +def append(read: str, entry: str) -> Failure | None: + """Append entry unless the history already holds one on what the seats read.""" checkout = top() if isinstance(checkout, Failure): return checkout history = pathlib.Path(checkout, HISTORY) try: 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}") + if recorded(text, read): + return Failure(f"{history} already holds an entry on {read}; record each ruling or run once") + 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/scoring.py b/bin/larv_review/scoring.py index 021a3593..f0f11552 100644 --- a/bin/larv_review/scoring.py +++ b/bin/larv_review/scoring.py @@ -7,11 +7,19 @@ from rank_todo import Item, ITEMS_HEADER, parse_row, table_rows FLOOR = decimal.Decimal("7.0") +def fall_step(fell: list[str], scored: bool) -> str: + """What record-ruling does next: ask for the scoring seats when a dimension fell and no scores file came, refuse a scores file no fall calls, or rule.""" + if fell and not scored: + return "ask" + if scored and not fell: + return "refuse" + return "rule" + + 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." + if under := [f"{name} {value}" for name, value in zip(DIMENSIONS, found) if name in fell and value < FLOOR]: + return "worse", f"Fell: {', '.join(fell)}. Under the floor of {FLOOR}: {', '.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." diff --git a/bin/metric_bench/main.py b/bin/metric_bench/main.py index ed71e097..7b6b33a9 100644 --- a/bin/metric_bench/main.py +++ b/bin/metric_bench/main.py @@ -3,9 +3,10 @@ usage: metric-bench [history] history defaults to docs/comprehension-history.md in the checkout it runs in, and the bench reads -the checkout that holds the history. For each scoring run in it, at the commit the panel read, it -measures each module-level function and each method of a module-level class in the Python files git -tracks, leaving out test_*.py, *_test.py and anything under a tests/ folder: +the checkout that holds the history. For each scoring run in it, those a fall called inside a paired +ruling included, at the commit the panel read, it measures each module-level function and each +method of a module-level class in the Python files git tracks, leaving out test_*.py, *_test.py and +anything under a tests/ folder: - cognitive complexity: SonarSource's white paper, read for Python; - length: lines; @@ -81,7 +82,7 @@ def bench_runs(text: str, top: str) -> tuple[list[tuple[str, RunScores]], list[s """Each scored run's heading and scores, and a note for each run skipped or not scored and each file left out.""" rows = [] notes = [] - for run in [entry for entry in entries(text) if not entry.paired]: + for run in [entry for entry in entries(text) if entry.scored_places or not entry.paired]: if isinstance(missing := git(["cat-file", "-e", f"{run.commit}^{{commit}}"], top), Failure): notes.append(f"Skipped, its commit is not in {top}: {run.heading} ({missing.reason})") continue @@ -121,7 +122,7 @@ def run_scores(run: Entry, top: str) -> tuple[RunScores | None, list[str]] | Fai log = git(["-c", "core.quotePath=false", "log", "--no-merges", "--format=tformat:@@", "--name-only", run.commit], top) if isinstance(log, Failure): return log - places, dropped = resolved(run.places, tracked) + places, dropped = resolved(run.scored_places, tracked) return bench(units, places, len(set(dropped)), co_changed(log)), unparsed diff --git a/bin/test_larv_review.py b/bin/test_larv_review.py index 1559736d..b793a540 100644 --- a/bin/test_larv_review.py +++ b/bin/test_larv_review.py @@ -9,12 +9,11 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) -from comprehension_history import appended, entries, Place, ruling_entry, Scoring, Seat -from larv_review.base import base, first_ruling, measured_commit +from comprehension_history import appended, entries, Place, recorded, ruling_entry, Scoring, Seat +from larv_review.base import base, first_ruling, HistoryChange, measured_commit 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 larv_review.scoring import fall_ruling, fall_step, means, plan_items, scoring_run_due, under_floor from test_loop_claude_black_box import host_env from rank_todo import Item from larv_review.rounds import round_counts @@ -116,15 +115,17 @@ 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"]} - 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) + scoring = Scoring([Seat("Junior A", "", ["`bin/b.py:4` `h`: long"])], {"Junior A": ["7", "6.5", "7", "7", "7"]}, [decimal.Decimal(mean) for mean in ("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}, "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) 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.assertEqual((found[1].ruled_places, found[1].scored_places), ([Place("bin/a.py", "f"), Place("bin/a.py", "g")], [Place("bin/b.py", "h")])) + self.assertTrue(recorded(history, "PR #2 at bbbbbbb, against aaaaaaa")) + self.assertFalse(recorded(history, "PR #2 at bbbbbbb")) 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]) @@ -132,9 +133,12 @@ class History(unittest.TestCase): 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("better", ["Locality", "Shape"], found), ("worse", "Fell: Locality, Shape. Under the floor of 7.0: 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.")) + def test_asks_for_scores_on_a_fall_refuses_them_without_one_and_rules_otherwise(self): + self.assertEqual([fall_step(["Locality"], False), fall_step([], True), fall_step(["Locality"], True), fall_step([], False)], ["ask", "refuse", "rule", "rule"]) + class Base(unittest.TestCase): def test_takes_the_newest_change_adding_a_scoring_run_or_ending_on_a_better_ruling(self): @@ -147,6 +151,8 @@ 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])) + scored_fall = HistoryChange("same fell", SCORING, SCORING + paired("2026-10-08T13:00:00Z", "same\n\nFell: Locality, each at or above the floor.\n\n| Seat | Overall |\n|---|---|\n| Mean | 7.00 |")) + self.assertEqual(measured_commit([scored_fall, older]), "old") def test_falls_back_to_the_first_rulings_base_then_to_none(self): ruled = paired("2026-10-08T13:00:00Z", "worse") @@ -282,7 +288,7 @@ class LarvReviewTool(unittest.TestCase): self.assertEqual(ran.stdout.splitlines()[0], "Ruling: same. Overall votes as counted: Mid A worse, Inherited architect same, Maintainability senior worse, Junior A same (voted worse, naming no place).") recorded = entries(history.read_text()) self.assertEqual([(entry.commit, entry.against, entry.ruling) for entry in recorded], [(self.start, self.start, "same")]) - self.assertEqual(recorded[0].places, [Place("bin/a.py", "f")] * 2) + self.assertEqual(recorded[0].ruled_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_asks_for_the_scoring_seats_when_a_dimension_falls_and_rules_with_their_scores(self): @@ -297,13 +303,17 @@ class LarvReviewTool(unittest.TestCase): 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.")) + self.assertTrue(ruled.stdout.startswith("Ruling: worse. Fell: Locality. Under the floor of 7.0: Locality 6.50, so the better ruling counts as worse.")) + again = self.run_tool("record-ruling", votes_file, self.seats_file(scores_text, "scores.md")) + self.assertIn("already holds an entry on", again.stderr) 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()) + votes_file = self.seats_file(pathlib.Path(votes_file).read_text().replace("PR #2", "PR #3"), "votes.md") + scores_text = scores_text.replace("PR #2", "PR #3") 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")) + other = self.run_tool("record-ruling", votes_file, self.seats_file(scores_text.replace("PR #3", "PR #4"), "scores.md")) self.assertIn("the scores file's first line is not", other.stderr) def test_names_no_fall_on_a_worse_ruling_and_takes_no_scores_file_without_one(self): @@ -311,19 +321,23 @@ class LarvReviewTool(unittest.TestCase): 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")) + extra = self.run_tool("record-ruling", self.seats_file(f"PR #3 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")) - ran = self.run_tool("record-scoring", self.seats_file(f"PR #2 at {self.start}\n" + seats)) + uncalled = self.run_tool("record-scoring", self.seats_file(f"PR #2 at {self.start}\n" + seats)) + self.assertEqual(uncalled.returncode, 1) + self.assertIn("no plan item or release calls this scoring run", uncalled.stderr) + ran = self.run_tool("record-scoring", self.seats_file(f"PR #2 at {self.start}\n" + seats), "1") 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) + self.assertIn("\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", ran.stdout) + self.assertIn("not /", self.run_tool("record-scoring", "1", self.seats_file(f"PR #2 at {self.start}\n" + seats)).stderr) 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) - self.assertEqual(entries(text)[0].places, [Place("bin/a.py", "f")] * 4) + self.assertEqual(entries(text)[0].scored_places, [Place("bin/a.py", "f")] * 4) def test_refuses_a_ruling_file_that_names_no_base_or_a_commit_the_checkout_lacks(self): ran = self.run_tool("record-ruling", self.seats_file(f"PR #2 at {self.start}\n\nMid A: {said('same')}\n\nInherited architect: {said('same')}\n")) diff --git a/bin/test_metric_bench.py b/bin/test_metric_bench.py index 318a101e..5df23802 100644 --- a/bin/test_metric_bench.py +++ b/bin/test_metric_bench.py @@ -144,7 +144,7 @@ class Places(unittest.TestCase): def test_reads_each_scoring_runs_places_and_leaves_paired_rulings_out(self): runs = [entry for entry in entries(self.HISTORY) if not entry.paired] self.assertEqual([(run.heading, run.commit) for run in runs], [("2026-10-08T12:50:49Z, PR #224 at a58a0a8", "a58a0a8")]) - self.assertEqual(runs[0].places, [Place("skills/x/SKILL.md", None), Place("bin/tool/cycle/states.py", "transition"), Place("cycle/run.py", "step"), Place("cycle/run.py", "close"), Place("bin/tool/cycle/judge.py", "run_judge")]) + self.assertEqual(runs[0].scored_places, [Place("skills/x/SKILL.md", None), Place("bin/tool/cycle/states.py", "transition"), Place("cycle/run.py", "step"), Place("cycle/run.py", "close"), Place("bin/tool/cycle/judge.py", "run_judge")]) def test_resolves_a_shortened_path_to_the_file_nearest_the_one_before_it(self): tracked = ["bin/tool/cycle/states.py", "bin/tool/cycle/run.py", "bin/other/cycle/run.py"] diff --git a/docs/decisions.md b/docs/decisions.md index 6bf3cb33..46bc54c8 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -67,9 +67,9 @@ lilleman decided to ship each of these under the floor on the day listed. Each l ## review: a paired ruling against the last measured commit decides the ratchet, and counts as worse when a dimension it rules fallen is under the floor; the four-seat scoring run checks the floor when a release's items run out or an item names the floor, and also runs when a ruling names a fallen dimension -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-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 that adds a scoring run to the history, or whose last added paired ruling is better. 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. 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. +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. PR #232's own history holds one fall-called scoring run recorded on its own, before this rule; it moves the base like any scoring run, which is safe under it, since a later fall of a dimension under the floor is always caught. 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 84b3f07d..3f7780c9 100644 --- a/skills/larv-review/SKILL.md +++ b/skills/larv-review/SKILL.md @@ -97,7 +97,7 @@ Then the comprehension check: simulated readers, launched per `~/.claude/skills/ - **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` 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. +**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. Where a fall's scores file already read the head, run `record-scoring` on that file. The chunk does not merge while either holds: diff --git a/todo.md b/todo.md index b80efa2e..e8bfcff5 100644 --- a/todo.md +++ b/todo.md @@ -66,8 +66,7 @@ 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. +2026-10-09, from two architecture studies on PR #232: 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. @@ -95,7 +94,6 @@ 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. -- 2.52.0 From d18441ba898252f4b61571cb635b4a581a06626c Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 9 Oct 2026 12:29:37 +0200 Subject: [PATCH 17/22] Answer stability round 3: its two findings, the legacy entry and the stale base rule, land in the architecture round 8 commit -- 2.52.0 From 745818826a886dac75c9f7700022f9a1a12ebeca Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 9 Oct 2026 12:29:37 +0200 Subject: [PATCH 18/22] Answer product-owner round 3: the base rule, the Floor line, the fall's wording and reusing a fall's scores file land in the architecture round 8 commit -- 2.52.0 From 8cee26b1d64cacb88701bd83be014c7d67b6a5a3 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 9 Oct 2026 12:59:45 +0200 Subject: [PATCH 19/22] Answer architecture round 9: refuse a repeat record before any output, count a fall's scores once in metric-bench, fetch origin for record-scoring as for needs-scoring-run, type fall_step's outcomes, and state the duplicate rule as the code holds it --- CHANGELOG.md | 2 +- bin/larv_review/main.py | 32 +++++++++++++++++++++++--------- bin/larv_review/scoring.py | 3 ++- bin/metric_bench/main.py | 8 +++++++- bin/test_larv_review.py | 4 +++- bin/test_metric_bench.py | 8 ++++++-- 6 files changed, 42 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b635c77..6e815ad5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## 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 append to `docs/comprehension-history.md` and refuse a second entry on the same commit; `record-scoring` refuses a run the plan does not call, and 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. +- 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` and refuse a second entry on what a seats file's first line reads; `record-scoring` refuses a run the plan does not call, and 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 that added a scoring run to `docs/comprehension-history.md`, or whose last ruling there is better. 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. diff --git a/bin/larv_review/main.py b/bin/larv_review/main.py index 391e203c..64a01cf6 100644 --- a/bin/larv_review/main.py +++ b/bin/larv_review/main.py @@ -4,8 +4,8 @@ usage: larv-review ruling-base | round-count | needs-scoring-run [...] 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 +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 three 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 @@ -109,7 +109,7 @@ def main(argv: list[str]) -> int: elif command == "record-ruling" and len(given) in (1, 2): done = record_ruling(*map(pathlib.Path, given)) 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) + done = with_default_branch(lambda default: record_scoring(default, pathlib.Path(given[0]), [int(id_) for id_ in given[1:]]), stale_ok=False) 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) @@ -250,7 +250,7 @@ def record_scoring(default: str, scores_file: pathlib.Path, ids: list[int]) -> F def read_scoring(scores_file: pathlib.Path, votes: Heading) -> Scoring | Failure: """The scores a fall called, once their file names what the votes file read.""" - read = read_seats(scores_file, paired=False) + read = read_seats(scores_file, paired=False, fresh=False) if isinstance(read, Failure): return read named, given = read @@ -266,8 +266,8 @@ def scored_seats(given: SeatsFile) -> Scoring | Failure: return Scoring(given.seats, found, means(list(found.values()))) -def read_seats(path: pathlib.Path, paired: bool) -> tuple[Heading, SeatsFile] | Failure: - """The seats file, and the heading its record goes under, once each commit it names is in the checkout.""" +def read_seats(path: pathlib.Path, paired: bool, fresh: bool = True) -> tuple[Heading, SeatsFile] | Failure: + """The seats file, and the heading its record goes under, once each commit it names is in the checkout and, when fresh, before anything is printed, once the history holds no entry on what it reads.""" try: given = seats_file(path.read_text(encoding="utf-8")) except (OSError, UnicodeDecodeError) as failure: @@ -279,19 +279,33 @@ def read_seats(path: pathlib.Path, paired: bool) -> tuple[Heading, SeatsFile] | return named if unknown := [commit for commit in (named.commit, named.against) if commit and not commit_exists(commit)]: return Failure(f"the seats file names {', '.join(unknown)}, which is no commit in this checkout") + if fresh: + history = history_file() + if isinstance(history, Failure): + return history + if recorded(history[1], given.read): + return Failure(f"{history[0]} already holds an entry on {given.read}; record each ruling or run once") return named, given -def append(read: str, entry: str) -> Failure | None: - """Append entry unless the history already holds one on what the seats read.""" +def history_file() -> tuple[pathlib.Path, str] | Failure: + """The checkout's history and its text, empty when the file is missing.""" checkout = top() if isinstance(checkout, Failure): return checkout history = pathlib.Path(checkout, HISTORY) try: - text = history.read_text(encoding="utf-8") if history.exists() else "" + return history, history.read_text(encoding="utf-8") if history.exists() else "" except (OSError, UnicodeDecodeError) as failure: return Failure(f"could not read {history}: {failure}") + + +def append(read: str, entry: str) -> Failure | None: + """Append entry unless the history already holds one on what the seats read.""" + read_history = history_file() + if isinstance(read_history, Failure): + return read_history + history, text = read_history if recorded(text, read): return Failure(f"{history} already holds an entry on {read}; record each ruling or run once") try: diff --git a/bin/larv_review/scoring.py b/bin/larv_review/scoring.py index f0f11552..891d0f9f 100644 --- a/bin/larv_review/scoring.py +++ b/bin/larv_review/scoring.py @@ -1,4 +1,5 @@ import decimal +import typing from comprehension_history import DIMENSIONS from failure import Failure @@ -7,7 +8,7 @@ from rank_todo import Item, ITEMS_HEADER, parse_row, table_rows FLOOR = decimal.Decimal("7.0") -def fall_step(fell: list[str], scored: bool) -> str: +def fall_step(fell: list[str], scored: bool) -> typing.Literal["ask", "refuse", "rule"]: """What record-ruling does next: ask for the scoring seats when a dimension fell and no scores file came, refuse a scores file no fall calls, or rule.""" if fell and not scored: return "ask" diff --git a/bin/metric_bench/main.py b/bin/metric_bench/main.py index 7b6b33a9..84cccd3a 100644 --- a/bin/metric_bench/main.py +++ b/bin/metric_bench/main.py @@ -78,11 +78,17 @@ def read_history(given: pathlib.Path | None) -> tuple[str, pathlib.Path, str] | return Failure(f"could not read {history}: {failure}") +def scored_runs(found: list[Entry]) -> list[Entry]: + """Each scoring run, and each paired ruling holding the scores a fall called unless a scoring run on its commit records them too.""" + runs = {entry.commit for entry in found if not entry.paired} + return [entry for entry in found if not entry.paired or entry.scored_places and entry.commit not in runs] + + def bench_runs(text: str, top: str) -> tuple[list[tuple[str, RunScores]], list[str]] | Failure: """Each scored run's heading and scores, and a note for each run skipped or not scored and each file left out.""" rows = [] notes = [] - for run in [entry for entry in entries(text) if entry.scored_places or not entry.paired]: + for run in scored_runs(entries(text)): if isinstance(missing := git(["cat-file", "-e", f"{run.commit}^{{commit}}"], top), Failure): notes.append(f"Skipped, its commit is not in {top}: {run.heading} ({missing.reason})") continue diff --git a/bin/test_larv_review.py b/bin/test_larv_review.py index b793a540..2e306b81 100644 --- a/bin/test_larv_review.py +++ b/bin/test_larv_review.py @@ -306,6 +306,7 @@ class LarvReviewTool(unittest.TestCase): self.assertTrue(ruled.stdout.startswith("Ruling: worse. Fell: Locality. Under the floor of 7.0: Locality 6.50, so the better ruling counts as worse.")) again = self.run_tool("record-ruling", votes_file, self.seats_file(scores_text, "scores.md")) self.assertIn("already holds an entry on", again.stderr) + self.assertEqual(self.run_tool("record-ruling", votes_file).stdout, "") 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()) @@ -313,7 +314,8 @@ class LarvReviewTool(unittest.TestCase): scores_text = scores_text.replace("PR #2", "PR #3") 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 #3", "PR #4"), "scores.md")) + votes_file = self.seats_file(pathlib.Path(votes_file).read_text().replace("PR #3", "PR #4"), "votes.md") + other = self.run_tool("record-ruling", votes_file, self.seats_file(scores_text.replace("PR #3", "PR #5"), "scores.md")) self.assertIn("the scores file's first line is not", other.stderr) def test_names_no_fall_on_a_worse_ruling_and_takes_no_scores_file_without_one(self): diff --git a/bin/test_metric_bench.py b/bin/test_metric_bench.py index 5df23802..b05ab545 100644 --- a/bin/test_metric_bench.py +++ b/bin/test_metric_bench.py @@ -14,6 +14,7 @@ from metric_bench.python_units import cognitive, measured, python_units, Unit from comprehension_history import entries, Place from failure import Failure from test_loop_claude_black_box import host_env +from metric_bench.main import scored_runs TOOL = pathlib.Path(__file__).resolve().parent / "metric-bench" @@ -141,9 +142,12 @@ class Places(unittest.TestCase): - `bin/tool/cycle/run.py:1` `step` """) - def test_reads_each_scoring_runs_places_and_leaves_paired_rulings_out(self): - runs = [entry for entry in entries(self.HISTORY) if not entry.paired] + def test_reads_each_scoring_runs_places_and_leaves_rulings_out_unless_they_hold_a_falls_scores(self): + runs = scored_runs(entries(self.HISTORY)) self.assertEqual([(run.heading, run.commit) for run in runs], [("2026-10-08T12:50:49Z, PR #224 at a58a0a8", "a58a0a8")]) + fall = "\n## 2026-10-09T09:00:00Z, PR #232 at {commit}, against 12d6d75\n\nRuling: worse\n\nJunior A, hardest first:\n\n- `bin/a.py:3` `f`\n" + self.assertEqual([run.commit for run in scored_runs(entries(self.HISTORY + fall.format(commit="bbbbbbb")))], ["a58a0a8", "bbbbbbb"]) + self.assertEqual([run.commit for run in scored_runs(entries(self.HISTORY + fall.format(commit="a58a0a8")))], ["a58a0a8"]) self.assertEqual(runs[0].scored_places, [Place("skills/x/SKILL.md", None), Place("bin/tool/cycle/states.py", "transition"), Place("cycle/run.py", "step"), Place("cycle/run.py", "close"), Place("bin/tool/cycle/judge.py", "run_judge")]) def test_resolves_a_shortened_path_to_the_file_nearest_the_one_before_it(self): -- 2.52.0 From bc2cc2c68eb6cfd3239327c694c413d15c8444a8 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 9 Oct 2026 12:59:45 +0200 Subject: [PATCH 20/22] Answer stability round 4: its findings land in the architecture round 9 commit -- 2.52.0 From 53014f849c570a49bd272f773227deddac3d69e1 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 9 Oct 2026 12:59:45 +0200 Subject: [PATCH 21/22] Answer product-owner round 4: its findings land in the architecture round 9 commit -- 2.52.0 From 97e76dd1ceeb6a745785d450637c3573da4d2279 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 9 Oct 2026 13:15:58 +0200 Subject: [PATCH 22/22] Ship PR #232 below the ratchet, as lilleman decided, and drop main.py's unused decimal import --- bin/larv_review/main.py | 1 - docs/decisions.md | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/larv_review/main.py b/bin/larv_review/main.py index 64a01cf6..67a4ea68 100644 --- a/bin/larv_review/main.py +++ b/bin/larv_review/main.py @@ -74,7 +74,6 @@ Exit 1, saying why, on unknown arguments, an unknown item ID, a seats file it ca breaks the shape above, or when git cannot start, finds no checkout or no default branch, cannot fetch origin for ruling-base or needs-scoring-run, or cannot read or write the history or todo.md. """ -import decimal import pathlib import re import sys diff --git a/docs/decisions.md b/docs/decisions.md index 46bc54c8..1cffe397 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -52,6 +52,7 @@ lilleman decided to ship each of these under the floor on the day listed. Each l - 2026-10-08, PR #225: 7.25, 6.75, 7.00, 6.88, 6.88. Above PR #224's run on every score but Shape, which held. - 2026-10-08, PR #228: no scoring run; its last paired ruling, against 12d6d75, was worse, 2 votes to 0. lilleman shipped it below the ratchet: the seats blamed the new ratchet's own rules, since moved into the tested `bin/larv-review`. - 2026-10-08, PR #229: no scoring run; its last paired ruling, against 12d6d75, was worse, 2 votes to 0. lilleman shipped it below the ratchet for PR #228's reason: the seats' decisive places were still PR #228's rules, since moved into `bin/larv-review`. +- 2026-10-09, PR #232: 7.13, 6.50, 6.63, 6.63, 6.88, at 324d650, whose ruling the fall made worse. Its last paired ruling, at 53014f8 against 12d6d75, split: Mid A better, the inherited architect worse, both with Locality worse. lilleman shipped it below the ratchet: after a restructure the seats still weigh PRs #229 to #231's code against the base, and their Locality places are filed under items 62 and 83. ## loop-claude: each project's model lives in `~/.claude/loop-claude-models.json`, which only loop-claude writes -- 2.52.0