diff --git a/bin/comprehension_history.py b/bin/comprehension_history.py index 29979259..122f1186 100644 --- a/bin/comprehension_history.py +++ b/bin/comprehension_history.py @@ -21,7 +21,7 @@ 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) -# A seat's label over its bullets: its name, then what the bullets are. +# A seat's label over its bullets: its name, then the listing's kind. LABEL = re.compile(rf"^(.+), ({DECIDED_BY}|{HARDEST_FIRST}|{RESTRUCTURE_FIRST}):$") SENIOR = "Maintainability senior" TITLE = "# Comprehension history\n" @@ -58,16 +58,16 @@ class Listing: class Entry: """One paired ruling, which names the commit it was against and its ruling, or one scoring run, which names neither. - `votes` and `scores` hold table rows, each the cells after the first, by the first, with the header left out. `scores` is the table with a Mean row, `votes` any other: a ruling's votes, whose one cell in a ruling before PR #232 is the overall vote. A ruling before PR #255 holds both tables, and scoring seats' listings too.""" + `score_rows` holds the rows of the table with a Mean row, and `vote_rows` those of any other table: each row's cells after the first, keyed by the first, without the header. `ruled_listings` holds the decided-by listings, and `scored_listings` the hardest-first and would-restructure-first ones.""" heading: str time: str commit: str against: str | None ruling: str | None - votes: dict[str, list[str]] - scores: dict[str, list[str]] - decided: list[Listing] - hardest: list[Listing] + vote_rows: dict[str, list[str]] + score_rows: dict[str, list[str]] + ruled_listings: list[Listing] + scored_listings: list[Listing] @property def paired(self) -> bool: @@ -75,16 +75,16 @@ class Entry: @property def scored(self) -> bool: - """Whether the entry counts as scoring the project: a scoring run, or a ruling from before PR #255 that holds scoring seats' places.""" + """Whether the entry scores the project: a scoring run, or a ruling that lists scoring seats' places, as a ruling from before PR #255 may, beside their table.""" return not self.paired or bool(self.scored_places) @property def ruled_places(self) -> list[Place]: - return [place for listing in self.decided for place in listing.places] + return [place for listing in self.ruled_listings for place in listing.places] @property def scored_places(self) -> list[Place]: - return [place for listing in self.hardest for place in listing.places] + return [place for listing in self.scored_listings for place in listing.places] @dataclasses.dataclass(frozen=True) @@ -135,10 +135,10 @@ def entries(history: str) -> list[Entry]: listed = listings(body) found.append(Entry( heading, named.group(1), named.group(3), named.group(4), ruling.group(1) if ruling else None, - votes={name: cells for table in tables if MEAN not in table for name, cells in table.items()}, - scores={name: cells for table in tables if MEAN in table for name, cells in table.items()}, - decided=[listing for listing in listed if listing.kind == DECIDED_BY], - hardest=[listing for listing in listed if listing.kind != DECIDED_BY], + vote_rows={name: cells for table in tables if MEAN not in table for name, cells in table.items()}, + score_rows={name: cells for table in tables if MEAN in table for name, cells in table.items()}, + ruled_listings=[listing for listing in listed if listing.kind == DECIDED_BY], + scored_listings=[listing for listing in listed if listing.kind != DECIDED_BY], )) return found @@ -146,18 +146,18 @@ def entries(history: str) -> list[Entry]: def latest_places(history: str) -> str | None: """The places seats found hard since the newest scored commit, under each entry's heading, oldest first; None when no place counts. - They start at the first of newest_scored's entries, so a rerun of one head adds to the run before it. Where no entry counts as scoring the project, they start at the oldest entry. From there, each entry gives every scoring seat's place, and each ruled place opening with a dimension its seat voted worse.""" + They start at the first entry that scores that commit, so a rerun of one head adds to the run before it. Where no entry scores the project, they start at the oldest entry. From there, each entry gives every scoring seat's place, and each ruled place opening with a dimension its seat voted worse.""" found = by_time(entries(history)) - newest = newest_scored(found) + newest = newest_commit_runs(found) start = found.index(newest[0]) if newest else 0 - parts = [placed(entry, worse_places(entry) + entry.hardest) for entry in found[start:]] + parts = [placed(entry, worse_places(entry) + entry.scored_listings) for entry in found[start:]] return "\n".join(part for part in parts if part) or None def latest_overall(history: str) -> decimal.Decimal | Failure | None: - """The mean of the overall means of newest_scored's entries, since a rerun of one head measures it again; None where no entry counts as scoring the project.""" + """The mean of the overall means of the entries that score the newest scored commit, since a rerun of one head measures it again; None where no entry scores the project.""" overalls = [] - for entry in newest_scored(by_time(entries(history))): + for entry in newest_commit_runs(by_time(entries(history))): overall = run_overall(entry) if isinstance(overall, Failure): return overall @@ -165,57 +165,56 @@ def latest_overall(history: str) -> decimal.Decimal | Failure | None: return sum(overalls, decimal.Decimal(0)) / len(overalls) if overalls else None -def newest_scored(found: list[Entry]) -> list[Entry]: - """In found's order, the entries that count as scoring the project on the newest scored commit, the commit of the last such entry; empty where none counts. A commit matches by prefix, since a heading may write it at any length from 7 characters.""" - scoring = [entry for entry in found if entry.scored] - return [entry for entry in scoring if entry.commit.startswith(scoring[-1].commit) or scoring[-1].commit.startswith(entry.commit)] if scoring else [] +def newest_commit_runs(found: list[Entry]) -> list[Entry]: + """The entries that score the commit of the last entry that scores the project, in found's order; empty where none does. Commits match by prefix, since a heading may write one at any length from 7 characters.""" + scored = [entry for entry in found if entry.scored] + if not scored: + return [] + newest = scored[-1].commit + return [entry for entry in scored if entry.commit.startswith(newest) or newest.startswith(entry.commit)] def run_overall(run: Entry) -> decimal.Decimal | Failure: - """The overall cell of the Mean row of an entry that counts as scoring the project.""" + """The overall cell of the Mean row of an entry that scores the project.""" try: - overall = decimal.Decimal(last_cells(run.scores).get(MEAN, "")) + overall = decimal.Decimal(last_cells(run.score_rows).get(MEAN, "")) except decimal.InvalidOperation: overall = None return overall if overall is not None and overall.is_finite() else Failure(f"{HISTORY}'s scoring run {run.heading} has no Mean row ending in its overall, which sets code health's weight") def last_cells(rows: dict[str, list[str]]) -> dict[str, str]: - """Each row's last non-empty cell, by its first cell: a seat's overall vote in an entry's `votes`, or its overall score, or the Mean row's, in its `scores`.""" + """Each row's last cell, by its first cell, leaving out a row whose last cell is empty: a seat's overall vote in an entry's `vote_rows`, or its overall score, or the Mean row's, in its `score_rows`.""" return {name: cells[-1] for name, cells in rows.items() if cells and cells[-1]} -def scoring_runs(found: list[Entry]) -> list[Entry]: - """The scoring runs among the entries, oldest first. Unlike Entry.scored, it leaves out a ruling from before PR #255 that holds scoring seats' places.""" - return [entry for entry in by_time(found) if not entry.paired] - - def by_time(found: list[Entry]) -> list[Entry]: return sorted(found, key=lambda entry: entry.time) def worse_places(entry: Entry) -> list[Listing]: - """Each of a ruling's decided-by listings, cut to the bullets that open with a dimension its seat's vote counted as worse; Overall counts as one.""" + """Each of a ruling's decided-by listings, cut to the bullets that open with a dimension its seat's vote counted as worse.""" cut = [] - for listing in entry.decided: - worse = worse_dimensions(entry.votes.get(listing.seat, [])) - cut.append(dataclasses.replace(listing, bullets=[bullet for bullet in listing.bullets if worse.intersection(place_dimensions(bullet.removeprefix("- ")))])) + for listing in entry.ruled_listings: + worse = worse_dimensions(entry.vote_rows.get(listing.seat, [])) + kept = [bullet for bullet in listing.bullets if worse.intersection(place_dimensions(bullet.removeprefix("- ")))] + cut.append(dataclasses.replace(listing, bullets=kept)) return cut def placed(entry: Entry, listed: list[Listing]) -> str: - """The entry's heading, then each listing with bullets, its label and its bullets; empty when no listing has any.""" + """The entry's heading, then the label and bullets of each listing that has bullets; empty when none has.""" text = "".join(f"\n{listing.label}\n\n" + "".join(f"{bullet}\n" for bullet in listing.bullets) for listing in listed if listing.bullets) return f"## {entry.heading}\n{text}" if text else "" def worse_dimensions(votes: list[str]) -> set[str]: - """The dimensions, Overall included, whose vote in a seat's row of the ruling's votes counted as worse; `same (voted worse, …)` counted as same. A row without one vote per dimension, as in the older table with a single `Vote`, has none.""" + """The dimensions, Overall included, that a seat's row of votes counted as worse; `same (voted worse, …)` counts as same. A row without one vote per dimension, such as the older single `Vote` table's, gives an empty set.""" return {dimension for dimension, vote in zip(DIMENSIONS, votes) if vote == "worse"} if len(votes) == len(DIMENSIONS) else set() def table_rows(body: str) -> list[dict[str, list[str]]]: - """Each table's rows after its header and separator, the cells after the first keyed by the first cell. A table starts at the row above a separator; `sections` has dropped the blank lines between tables.""" + """Each table's rows after its header and separator, the cells after the first keyed by the first cell. Tables may touch, so a table starts at the row above a separator.""" lines = [line for line in body.splitlines() if line.startswith("|")] separators = [index for index, line in enumerate(lines) if line.startswith("|-")] ends = [*(index - 1 for index in separators[1:]), len(lines)] @@ -223,7 +222,6 @@ def table_rows(body: str) -> list[dict[str, list[str]]]: def row_cells(line: str) -> tuple[str, list[str]]: - """A table row's first cell, then the cells after it.""" name, *cells = [cell.strip() for cell in line.strip("|").split("|")] return name, cells diff --git a/bin/larv_review/agreement.py b/bin/larv_review/agreement.py index a1a537db..1e3755be 100644 --- a/bin/larv_review/agreement.py +++ b/bin/larv_review/agreement.py @@ -1,6 +1,6 @@ import decimal -from comprehension_history import counted_vote, entries, Entry, last_cells, scoring_runs +from comprehension_history import by_time, counted_vote, entries, Entry, last_cells from larv_review.seats import FIRST_SEATS # Matches score-outcomes, which waits for 10 finished chunks before it shows a median. @@ -10,7 +10,7 @@ MIN_PAIRS = 10 def ruling_agreement(found: list[Entry]) -> list[bool]: """For each paired ruling that holds both of the first seats' overall votes, whether they counted alike.""" first, second = FIRST_SEATS - cells = [last_cells(entry.votes) for entry in found if entry.paired] + cells = [last_cells(entry.vote_rows) for entry in found if entry.paired] return [counted_vote(each[first]) == counted_vote(each[second]) for each in cells if first in each and second in each] @@ -18,9 +18,9 @@ def run_agreement(found: list[Entry]) -> list[bool]: """For each commit scored at least twice, whether the first two seats' overall scores moved the same way, up, down or not at all, from its first run to its second. Both runs read one tree, so the pair is the ruling those seats would make from absolute scores on code that did not change.""" first, second = FIRST_SEATS runs: dict[str, list[dict[str, decimal.Decimal]]] = {} - for entry in scoring_runs(found): - cells = last_cells(entry.scores) - if first in cells and second in cells: + for entry in by_time(found): + cells = last_cells(entry.score_rows) + if entry.scored and first in cells and second in cells: runs.setdefault(entry.commit, []).append({first: decimal.Decimal(cells[first]), second: decimal.Decimal(cells[second])}) pairs = [(each[0], each[1]) for each in runs.values() if len(each) >= 2] return [direction(before[first], after[first]) == direction(before[second], after[second]) for before, after in pairs] diff --git a/bin/larv_review/test_larv_review.py b/bin/larv_review/test_larv_review.py index c0f05247..c4e93907 100644 --- a/bin/larv_review/test_larv_review.py +++ b/bin/larv_review/test_larv_review.py @@ -162,13 +162,29 @@ class History(unittest.TestCase): fell = ruled.replace("2026-10-10T12:00:00Z", "2026-10-09T12:00:00Z") + "\n| Seat | Navigation | Locality | Shape | Self-sufficiency | Overall |\n|---|---|---|---|---|---|\n| Mid A | 7 | 6 | 7 | 7 | 7 |\n| Mean | 7 | 6 | 7 | 7 | 7 |\n\nJunior A, hardest first:\n\n- `bin/j.py:5` `s`: wide\n" self.assertEqual(latest_places(appended(appended("", scored), fell)), hard_since.replace("2026-10-10T12:00:00Z", "2026-10-09T12:00:00Z") + "\nJunior A, hardest first:\n\n- `bin/j.py:5` `s`: wide\n") - def test_takes_a_seats_vote_from_the_votes_table_whichever_table_comes_first(self): + def test_takes_a_seats_vote_from_the_votes_table_when_it_comes_first(self): + self.assert_votes_table_read(lambda votes, scores: votes + scores) + + def test_takes_a_seats_vote_from_the_votes_table_when_it_comes_second(self): + self.assert_votes_table_read(lambda votes, scores: scores + votes) + + def assert_votes_table_read(self, tables): votes = "| Seat | Navigation | Locality | Shape | Self-sufficiency | Overall |\n|---|---|---|---|---|---|\n| Mid A | same | worse | same | same | same |\n" scores = "| Seat | Navigation | Locality | Shape | Self-sufficiency | Overall |\n|---|---|---|---|---|---|\n| Mid A | 7 | 7 | 7 | 7 | 7 |\n| Mean | 7 | 7 | 7 | 7 | 7 |\n" places = "Mid A, decided by:\n\n- Locality: `bin/e.py:1` `n`: kept\n- Shape: `bin/f.py:2` `o`: dropped\n" kept = "## 2026-10-07T12:00:00Z, PR #2 at bbbbbbb, against aaaaaaa\n\nMid A, decided by:\n\n- Locality: `bin/e.py:1` `n`: kept\n" - for tables in (votes + scores, scores + votes): - self.assertEqual(latest_places(appended("", paired("2026-10-07T12:00:00Z", "worse") + tables + places)), kept) + self.assertEqual(latest_places(appended("", paired("2026-10-07T12:00:00Z", "worse") + tables(votes, scores) + places)), kept) + + def test_keeps_every_bullet_of_a_listing_that_opens_with_a_dimension_voted_worse(self): + votes = "\n| Seat | Navigation | Locality | Shape | Self-sufficiency | Overall |\n|---|---|---|---|---|---|\n| Mid A | same | worse | worse | same | same |\n" + places = "\nMid A, decided by:\n\n- Locality: `bin/e.py:1` `n`: deep\n- Shape: `bin/f.py:2` `o`: wide\n" + expected = "## 2026-10-07T12:00:00Z, PR #2 at bbbbbbb, against aaaaaaa\n\nMid A, decided by:\n\n- Locality: `bin/e.py:1` `n`: deep\n- Shape: `bin/f.py:2` `o`: wide\n" + self.assertEqual(latest_places(appended("", paired("2026-10-07T12:00:00Z", "worse") + votes + places)), expected) + + def test_drops_the_bullets_of_a_seat_with_no_row_in_the_votes_table(self): + votes = "\n| Seat | Navigation | Locality | Shape | Self-sufficiency | Overall |\n|---|---|---|---|---|---|\n| Mid A | same | worse | same | same | same |\n" + places = "\nJunior A, decided by:\n\n- Locality: `bin/e.py:1` `n`: deep\n" + self.assertIsNone(latest_places(appended("", paired("2026-10-07T12:00:00Z", "worse") + votes + places))) def test_names_the_places_of_every_run_on_the_newest_scored_commit(self): run = "## {time}, {pr} at {commit}\n\nJunior A, hardest first:\n\n- `bin/b.py:{line}` `h`: long\n" diff --git a/docs/decisions.md b/docs/decisions.md index 8fad991c..b8a89f63 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -468,7 +468,7 @@ Valid while the worker writes the tests that larv-review's reviewers hold to the 2026-10-16, lilleman, answering the review of PR #283. An item that restores a maintain goal the project breaks today is a defect: exempt as `defect`. Its Moves name that maintain goal and how much of it is broken, and the goal weighs as the heaviest achieve goal, since a broken maintain goal outranks any achieve goal. Every defect ranks by its score, so a trivial one waits behind valuable work. Only questions and then security findings rank first in their release: a question's answer may change other items, and a question waits for the human anyway, so ranking it first delays no chunk. An item names the most specific goal it moves, and a parent only for a move none of its sub-goals covers, so a sub-goal's move does not count twice; `rank_todo.py` refuses a goal named beside its own sub-goal. Each project reshapes its own `todo.md`; `CLAUDE.md` → "Working loop" makes the reshape the only work until done, as it makes writing missing premises. An item that makes this project easier to read moves code health, as the paragraph below says, and goal 1.4, since reading cost is measured in tokens per chunk. -2026-10-18, lilleman. Serves goal 1.1: every project shares one achieve goal, code health, which `CLAUDE.md` → "Shared goal" states once and which replaces each project's own readability goal. It ranks first among a project's achieve goals, since lilleman rates it very important while the comprehension panel's overall is under 7.0. While that overall is under 7.0, or no scoring run has measured the project, it weighs four times its weight at 7.0 or above, as `UNDER_FLOOR` sets. The overall is the mean of the overall means of every scoring run on the newest scored commit in `docs/comprehension-history.md`, as `newest_scored` finds them. Two runs of one head measure it twice, and the newest alone would let their noise flip the weight: 7.13 and 6.88 on one head of another project would have. The review of PR #324 raised this choice. Weighing code health four times as much leaves the other achieve goals' weights as they are. So crossing 7.0 changes only the scores of the items that move code health, and of the defects, since a broken maintain goal weighs as the heaviest achieve goal. `larv-review record-scoring` re-ranks `todo.md` after it appends a run. A project that opts out of the comprehension check voids the goal, as `review: a project decision may opt every chunk out …` records. A README voids the goal with `**Void:** code health, since .` under `## Goals`, and an item's Moves cell names it as in `code health by 6`. A panel of three readers seated as lilleman picked both 3-0: `code health` over `code`, `health`, `C` and `0`, and the bold `Void:` line over a sentence under `## Goals` or a line under `## Audience`. `score-outcomes` counts the counter-signal's misread findings per chunk, as `review: a reviewer under …` records. Valid while the comprehension panel's overall is how a project measures how hard it is to read. +2026-10-18, lilleman. Serves goal 1.1: every project shares one achieve goal, code health, which `CLAUDE.md` → "Shared goal" states once and which replaces each project's own readability goal. It ranks first among a project's achieve goals, since lilleman rates it very important while the comprehension panel's overall is under 7.0. While that overall is under 7.0, or no scoring run has measured the project, it weighs four times its weight at 7.0 or above, as `UNDER_FLOOR` sets. The overall is the mean of the overall means of every scoring run on the newest scored commit in `docs/comprehension-history.md`, as `newest_commit_runs` finds them. Two runs of one head measure it twice, and the newest alone would let their noise flip the weight: 7.13 and 6.88 on one head of another project would have. The review of PR #324 raised this choice. Weighing code health four times as much leaves the other achieve goals' weights as they are. So crossing 7.0 changes only the scores of the items that move code health, and of the defects, since a broken maintain goal weighs as the heaviest achieve goal. `larv-review record-scoring` re-ranks `todo.md` after it appends a run. A project that opts out of the comprehension check voids the goal, as `review: a project decision may opt every chunk out …` records. A README voids the goal with `**Void:** code health, since .` under `## Goals`, and an item's Moves cell names it as in `code health by 6`. A panel of three readers seated as lilleman picked both 3-0: `code health` over `code`, `health`, `C` and `0`, and the bold `Void:` line over a sentence under `## Goals` or a line under `## Audience`. `score-outcomes` counts the counter-signal's misread findings per chunk, as `review: a reviewer under …` records. Valid while the comprehension panel's overall is how a project measures how hard it is to read. 2026-10-15, lilleman. Serves goal 1.4: loop-claude routes a chunk's first cycle on the item the chunk takes (`routing: a chunk's worker runs on the rung its item's L picks`). An item lists the items that must be done before it starts in a Blocked by column, and `rank_todo.py` ranks each blocker above every item it blocks. The table's order is `todo.md`'s only order: `rank_todo.py` fails on text beside the table under `## Items`, since a prose order there, "Release 0.3.0 takes items 125, 114 and 124 first", contradicted the table and loop-claude could not read it. A decision that wants an order sets the scores instead. An item waits while it is marked `question` or a blocker of it is still in the table, whatever the rows' order, so a release's first row that does not wait is the item a chunk takes. A blocker the table no longer holds was finished or deleted, and is dropped, so the cell shows what still blocks. A panel of three readers seated as lilleman picked the spelling: two ranked "Blocked by" first, as the cell lists only what still blocks, and all three chose bare IDs such as `12, 14` in a column right after Release, read before the tagline and kept apart from the scores. `rank_todo.py` adds the column to a table without it. The tools read cells by column name, so a later column leaves a reader on an older release working; `rank_todo.py`, which writes every column, fails on one it does not know rather than drop it.