diff --git a/CHANGELOG.md b/CHANGELOG.md index 6be4974c..9e28d2a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- 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 left with no plan item is due a scoring run however its items left, moved to another release included. +- 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 left with no plan item is due a scoring run however its items left, moved to another release included. 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 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/git.py b/bin/larv_review/git.py index 960072b5..841bf793 100644 --- a/bin/larv_review/git.py +++ b/bin/larv_review/git.py @@ -1,7 +1,9 @@ +import re import subprocess +import sys from failure import Failure -from larv_review.rules import HistoryChange +from larv_review.history import HistoryChange HISTORY = "docs/comprehension-history.md" @@ -26,20 +28,32 @@ def default_branch() -> str | Failure: return remotes if "origin" in remotes.split(): if isinstance(fetched := git("fetch", "--quiet", "origin"), Failure): - return fetched + print(f"reading origin as last fetched: {fetched.reason}", file=sys.stderr) default = git("symbolic-ref", "--short", "refs/remotes/origin/HEAD") - if isinstance(default, Failure): - return Failure(f"origin names no default branch; set it with `git remote set-head origin --auto`: {default.reason}") - return default.strip() + return default.strip() if not isinstance(default, Failure) else origin_head() for branch in ("main", "master"): if not isinstance(git("rev-parse", "--quiet", "--verify", f"refs/heads/{branch}"), Failure): return branch return Failure("no origin remote, and no main or master branch to take as the default branch") +def origin_head() -> str | Failure: + """The default branch origin names, for a clone made by `git init` and `git remote add`, which records none.""" + listed = git("ls-remote", "--symref", "origin", "HEAD") + if isinstance(listed, Failure): + return listed + if named := re.match(r"ref: refs/heads/(\S+)\tHEAD", listed): + return f"origin/{named.group(1)}" + return Failure("origin names no default branch") + + +def commit_exists(commit: str) -> bool: + return not isinstance(git("rev-parse", "--quiet", "--verify", f"{commit}^{{commit}}"), Failure) + + def file_at(revision: str, path: str) -> str | Failure: """A file's text at a revision, empty where the revision is not a commit, such as a root commit's parent, or holds no such file.""" - if isinstance(git("rev-parse", "--quiet", "--verify", f"{revision}^{{commit}}"), Failure): + if not commit_exists(revision): return "" listed = git("ls-tree", "--name-only", revision, "--", path) if isinstance(listed, Failure): diff --git a/bin/larv_review/history.py b/bin/larv_review/history.py index 92ae74a5..af9cdf8d 100644 --- a/bin/larv_review/history.py +++ b/bin/larv_review/history.py @@ -3,17 +3,19 @@ import os import re import time -from larv_review.seats import DIMENSIONS, Seat +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}[^,]*, ") DECIDED_BY = "decided by" HARDEST_FIRST = "hardest first" -WOULD_RESTRUCTURE_FIRST = "would restructure first" HEADING = re.compile(r"^([^,]+), (.+) at ([0-9a-f]{7,40})(?:, against ([0-9a-f]{7,40}))?$") -RULING = re.compile(r"^Ruling: (better|same|worse)$", re.M) -SEAT_PLACES = re.compile(rf"^.+, ({DECIDED_BY}|{HARDEST_FIRST}|{WOULD_RESTRUCTURE_FIRST}):$") # `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}):$") STAMP = "%Y-%m-%dT%H:%M:%SZ" TITLE = "# Comprehension history\n" @@ -35,6 +37,14 @@ class Entry: places: list[Place] +@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 + + @dataclasses.dataclass(frozen=True) class ScoringRun: heading: str @@ -98,9 +108,12 @@ def resolved(places: list[Place], tracked: list[str]) -> tuple[list[Place], list return found, dropped -def heading(at: float, read: str) -> str: - """An entry's heading: when the seats finished, in UTC, and what they read.""" - return f"{time.strftime(STAMP, time.gmtime(at))}, {read}" +def heading(at: float, read: str, paired: bool) -> re.Match[str] | Failure: + """An entry's heading, matched by HEADING: when the seats finished, in UTC, and what they read; a read that opens with its own date, as a run moved from a decision entry does, keeps it.""" + title = read if DATED.match(read) else f"{time.strftime(STAMP, time.gmtime(at))}, {read}" + if (named := HEADING.match(title)) and bool(named.group(4)) == paired: + return named + return Failure(f"the seats file's first line is not ` at {', against ' if paired else ''}`: {read}") def appended(history: str, entry: str) -> str: @@ -116,8 +129,8 @@ def ruling_entry(title: str, seats: list[Seat], counted: dict[str, str], ruled: def scoring_entry(title: str, seats: list[Seat], scores: dict[str, list[str]], means: list[str]) -> str: - rows = [[seat, *values] for seat, values in scores.items()] + [["Mean", *means]] - labels = [(f"{seat.name}, {WOULD_RESTRUCTURE_FIRST if seat.name == 'Inherited architect' else HARDEST_FIRST}:", seat.places) for seat in seats] + rows = [[seat, *values] for seat, values in scores.items() if seat != MEAN] + [[MEAN, *means]] + labels = [(f"{seat.name}, {RESTRUCTURE_FIRST if seat.name == ARCHITECT else HARDEST_FIRST}:", seat.places) for seat in seats if seat.name != MEAN] return entry_text(title, [], [["Seat", *DIMENSIONS], *rows], labels) diff --git a/bin/larv_review/main.py b/bin/larv_review/main.py index 285e5102..29a13446 100644 --- a/bin/larv_review/main.py +++ b/bin/larv_review/main.py @@ -15,7 +15,7 @@ of HEAD and the default branch. round-count prints, for each pass, the highest among this branch's commit titles opening `Answer round :`, counting commits the default branch does not hold, and marks a pass at -the cap of 3 rounds, and a name in such a title that is no pass. +the cap of {cap} rounds, and a name in such a title that is no pass. needs-scoring-run prints why the chunk shipping the given todo.md item IDs takes a scoring run, or `No scoring run due.` It is due when the chunk ships an item whose tagline names the comprehension @@ -43,13 +43,14 @@ appends nothing and says to add the maintainability senior's and Junior A's line ruling is the vote that leads each other vote by two or more, else same, and it appends the ruling. record-scoring takes 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 seat's lowest -dimension. A 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 7.0. +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. A 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}. 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. +time and the seats file's first line, or of that line alone when it opens with a date. Each commit +the line names must be in the checkout. 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, or the @@ -60,9 +61,9 @@ import sys import time import typing -from larv_review.history import appended, HEADING, heading, ruling_entry, scoring_entry -from larv_review.rules import CAP, first_ruling, means, measured_commit, PASSES, plan_items, round_counts, ruling, scoring_run_due, under_floor, votes -from larv_review.git import default_branch, file_at, git, HISTORY, history_changes, landed_since_release, top +from larv_review.history import appended, heading, ruling_entry, scoring_entry +from larv_review.rules import base, CAP, FLOOR, means, PASSES, 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, report, scores from failure import Failure from file_writes import replace_file @@ -72,7 +73,7 @@ USAGE = "usage: larv-review ruling-base | round-count | needs-scoring-run int: if argv in (["-h"], ["--help"]): - print(__doc__.strip()) + print(__doc__.strip().format(cap=CAP, floor=FLOOR)) return 0 command, *given = argv or [""] if command in ("ruling-base", "round-count") and not given: @@ -99,19 +100,13 @@ def ruling_base(default: str) -> Failure | None: changes = history_changes(default) if isinstance(changes, Failure): return changes - if found := measured_commit(changes): - print(f"{found}\nThe newest merged change on {default} that adds a scoring run to {HISTORY}, or whose last added paired ruling is better.") - return None history = file_at(default, HISTORY) if isinstance(history, Failure): return history - if (first := first_ruling(history)) and first.against: - print(f"{first.against}\nNo merged change on {default} adds a scoring run or a better ruling; the base its first paired ruling names.") - return None merge_base = git("merge-base", "HEAD", default) if isinstance(merge_base, Failure): return merge_base - print(f"{merge_base.strip()}\nNo merged change on {default} adds a scoring run or a paired ruling; the merge base of HEAD and {default}.") + print("\n".join(base(changes, history, merge_base.strip(), default))) return None @@ -133,22 +128,20 @@ def needs_scoring_run(default: str, ids: list[int]) -> Failure | None: return before try: after = pathlib.Path(checkout, "todo.md").read_text(encoding="utf-8") - except FileNotFoundError: - after = "" except (OSError, UnicodeDecodeError) as failure: return Failure(f"could not read todo.md: {failure}") planned = plan_items(before) if isinstance(planned, Failure): - return planned + return Failure(f"{default}'s todo.md: {planned.reason}") chunk = plan_items(after) if isinstance(chunk, Failure): - return chunk - if unknown := sorted(set(ids) - {item.id for item in planned + chunk}): - return Failure(f"neither {default}'s todo.md nor the checkout's holds item {', '.join(map(str, unknown))}") + return Failure(f"the checkout's todo.md: {chunk.reason}") 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 @@ -160,9 +153,12 @@ def record(seats_file: pathlib.Path, paired: bool) -> Failure | None: return Failure(f"could not read {seats_file}: {failure}") if isinstance(given, Failure): return given - title = heading(time.time(), given.read) - if not (named := HEADING.match(title)) or bool(named.group(4)) != paired: - return Failure(f"the seats file's first line is not ` at {', against ' if paired else ''}`: {given.read}") + named = heading(time.time(), given.read, paired) + if isinstance(named, Failure): + return named + title = named.group(0) + if unknown := [commit for commit in named.group(3, 4) if commit and not commit_exists(commit)]: + return Failure(f"the seats file names {', '.join(unknown)}, which is no commit in this checkout") if paired: counted = votes(given.seats) if isinstance(counted, Failure): @@ -179,7 +175,7 @@ def record(seats_file: pathlib.Path, paired: bool) -> Failure | None: return found mean = means(found) under = under_floor(mean) - print(f"Means: {', '.join(f'{name} {value}' for name, value in zip(DIMENSIONS, mean))}. {'Under the floor of 7.0: ' + ', '.join(under) if under else 'None under the floor of 7.0'}.") + 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])) diff --git a/bin/larv_review/rules.py b/bin/larv_review/rules.py index e80e4fcd..04fd2bc9 100644 --- a/bin/larv_review/rules.py +++ b/bin/larv_review/rules.py @@ -1,29 +1,18 @@ -import dataclasses import decimal import re -from larv_review.seats import DIMENSIONS, Seat -from larv_review.history import entries, Entry, PLACE +from larv_review.seats import DIMENSIONS, FIRST_SEATS, Seat, SPLIT_SEATS +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 -FIRST_SEATS = ("Mid A", "Inherited architect") FLOOR = decimal.Decimal("7.0") PASSES = ("architecture", "full scan", "security", "stability", "product-owner", "prose") -ROUND = re.compile(r"^Answer (.+) round ([0-9]+):") -SPLIT_SEATS = ("Maintainability senior", "Junior A") +ROUND = re.compile(r"^Answer (.+?) round ([0-9]+):") VOTES = ("better", "same", "worse") -@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 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.""" names = [seat.name for seat in seats] @@ -86,12 +75,18 @@ def first_ruling(history: str) -> Entry | None: return rulings[0] if rulings else None +def base(changes: list[HistoryChange], history: str, merge_base: str, default: str) -> tuple[str, str]: + """The commit a paired ruling reads against, and how it was found: the last measured commit, else the base the history's first paired ruling names, else the merge base of HEAD and the default branch. history is the default branch's.""" + if found := measured_commit(changes): + return found, f"The newest merged change on {default} that adds a scoring run to the history, or whose last added paired ruling is better." + if (first := first_ruling(history)) and first.against: + return first.against, f"No merged change on {default} adds a scoring run or a better ruling; the base its first paired ruling names." + return merge_base, f"No merged change on {default} adds a scoring run or a paired ruling; the merge base of HEAD and {default}." + + def plan_items(todo: str) -> list[Item] | Failure: - """Each row of a todo.md's items table, read as `rank_todo.py` reads it; a plan with no table has no items.""" - lines = todo.splitlines() - if ITEMS_HEADER not in lines: - return [] - table = table_rows(lines, ITEMS_HEADER) + """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 = [] @@ -103,9 +98,11 @@ 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]: +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 the newest release tag. A release has work landed towards it when the chunk ships one of its items, or when it is the earliest release 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()] left = {item.release for item in after if item.id not in ships} diff --git a/bin/larv_review/seats.py b/bin/larv_review/seats.py index c7c4194d..a1db8990 100644 --- a/bin/larv_review/seats.py +++ b/bin/larv_review/seats.py @@ -3,10 +3,15 @@ import re from failure import Failure +ARCHITECT = "Inherited architect" DIMENSIONS = ("Navigation", "Locality", "Shape", "Self-sufficiency", "Overall") -SCORING_SEATS = ("Junior A", "Mid A", "Maintainability senior", "Inherited architect") -SEAT_LINE = re.compile(r"^(Junior A|Mid A|Maintainability senior|Inherited architect): (.+)$") +FIRST_SEATS = ("Mid A", ARCHITECT) +# A scoring run moved from a `comprehension floor:` decision entry kept only the seats' means. +MEAN = "Mean" SCORES = re.compile(", ".join(rf"{name} ([0-9]+(?:\.[0-9]+)?)" for name in DIMENSIONS)) +SCORING_SEATS = ("Junior A", "Mid A", "Maintainability senior", ARCHITECT) +SEAT_LINE = re.compile(rf"^({'|'.join((*SCORING_SEATS, MEAN))}): (.+)$") +SPLIT_SEATS = ("Maintainability senior", "Junior A") @dataclasses.dataclass(frozen=True) @@ -43,9 +48,9 @@ def report(text: str) -> Report | Failure: 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; the file has {', '.join(seat.name for seat in seats) or 'none'}") + """Each seat's five scores as written, in DIMENSIONS' order: the four seats', or the Mean line's alone.""" + if [seat.name for seat in seats] not in (list(SCORING_SEATS), [MEAN]): + 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'}") found = {} for seat in seats: if not (written := SCORES.fullmatch(seat.said)): diff --git a/bin/test_larv_review.py b/bin/test_larv_review.py index 07c31733..19d7c98d 100644 --- a/bin/test_larv_review.py +++ b/bin/test_larv_review.py @@ -9,9 +9,9 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) -from larv_review.history import appended, entries, Place, ruling_entry, scoring_runs +from larv_review.history import appended, entries, HistoryChange, Place, ruling_entry, scoring_runs +from larv_review.rules import base, first_ruling, means, measured_commit, plan_items, round_counts, ruling, scoring_run_due, under_floor, votes from failure import Failure -from larv_review.rules import first_ruling, HistoryChange, means, measured_commit, plan_items, round_counts, ruling, scoring_run_due, under_floor, votes from test_loop_claude_black_box import host_env from rank_todo import Item from larv_review.seats import report, scores, Seat @@ -108,6 +108,12 @@ class Base(unittest.TestCase): self.assertEqual(measured_commit([worse_last, older]), "old") self.assertIsNone(measured_commit([same])) + def test_falls_back_to_the_first_rulings_base_then_to_the_merge_base(self): + ruled = paired("2026-10-08T13:00:00Z", "worse") + self.assertEqual(base([HistoryChange("c", "", ruled)], ruled, "m", "main")[0], "aaaaaaa") + self.assertEqual(base([], "", "m", "main")[0], "m") + self.assertEqual(base([HistoryChange("c", "", SCORING)], SCORING, "m", "main")[0], "c") + def test_finds_the_earliest_ruling_by_its_time(self): ruled = first_ruling(paired("2026-10-08T14:00:00Z", "same", "ccccccc") + paired("2026-10-08T13:00:00Z", "worse")) self.assertEqual(ruled and ruled.commit, "bbbbbbb") @@ -116,19 +122,20 @@ class Base(unittest.TestCase): class Rounds(unittest.TestCase): def test_counts_each_passs_highest_round(self): - counts = round_counts(["Answer prose round 1: x", "Answer full scan round 2: y", "Answer full scan round 1: z", "Answer stability: no round", "Answer stabilty round 1: typo", "Rescore: w"]) - self.assertEqual((counts["prose"], counts["full scan"], counts["stability"], counts["architecture"], counts["stabilty"]), (1, 2, 0, 0, 1)) + counts = round_counts(["Answer prose round 1: x", "Answer full scan round 2: y", "Answer full scan round 1: z", "Answer stability: no round", "Answer stabilty round 1: typo", "Answer security round 1: rename round 2: x", "Rescore: w"]) + self.assertEqual((counts["prose"], counts["full scan"], counts["stability"], counts["architecture"], counts["stabilty"], counts["security"]), (1, 2, 0, 0, 1, 1)) class ScoringRunDue(unittest.TestCase): def test_reads_each_rows_id_release_and_tagline(self): self.assertEqual(plan_items(todo("| 3 | 0.1.0 | | **Do it.** | 1 | 1 | 1 | 1 | 1 | 9.0 |")), [item(3, (0, 1, 0))]) - self.assertEqual(plan_items("# todo\n"), []) + self.assertIsInstance(plan_items("# todo\n"), Failure) self.assertIsInstance(plan_items(todo("| 0 | 0.1.0 | | **Do it.** | 1 | 1 | 1 | 1 | 1 | 9.0 |")), Failure) 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) def test_is_due_when_the_chunk_ships_a_releases_last_item(self): plan = [item(1, (0, 1, 0)), item(2, (0, 2, 0))] @@ -163,6 +170,7 @@ class LarvReviewTool(unittest.TestCase): self.git("push", "-q", "origin", "HEAD:main") self.git("remote", "set-head", "origin", "main") self.git("switch", "-q", "-c", "chunk") + self.start = self.git("rev-parse", "--short", "HEAD").strip() def git(self, *args): return subprocess.run(["git", "-c", "user.name=t", "-c", "user.email=t@t", *args], cwd=self.checkout, check=True, env=self.env, capture_output=True, text=True).stdout @@ -213,7 +221,7 @@ class LarvReviewTool(unittest.TestCase): def test_records_a_ruling_once_four_seats_settle_a_split(self): lines = """\ - PR #2 at abc1234, against def5678 + PR #2 at {start}, against {start} Mid A: worse @@ -221,6 +229,7 @@ class LarvReviewTool(unittest.TestCase): Inherited architect: same """ + lines = lines.replace("{start}", self.start) 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.")) @@ -230,14 +239,14 @@ class LarvReviewTool(unittest.TestCase): 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.") recorded = entries(history.read_text()) - self.assertEqual([(entry.commit, entry.against, entry.ruling) for entry in recorded], [("abc1234", "def5678", "same")]) + 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()) 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("PR #2 at abc1234\n" + seats)) + 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) text = (self.checkout / "docs" / "comprehension-history.md").read_text() @@ -245,10 +254,30 @@ class LarvReviewTool(unittest.TestCase): self.assertIn("Inherited architect, would restructure first:", text) self.assertEqual([run.places for run in scoring_runs(text)], [[Place("bin/a.py", "f")] * 4]) - def test_refuses_a_ruling_file_that_names_no_base(self): - ran = self.run_tool("record-ruling", self.seats_file("PR #2 at abc1234\n\nMid A: same\n\nInherited architect: same\n")) + 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")) 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")) + 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_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")) + offline = self.run_tool("round-count") + self.assertEqual(offline.returncode, 0, offline.stderr) + self.assertIn("reading origin as last fetched", offline.stderr) + self.assertIn("prose: 1\n", offline.stdout) + self.git("remote", "remove", "origin") + self.assertIn("prose: 1\n", self.run_tool("round-count").stdout) if __name__ == "__main__": diff --git a/docs/comprehension-history.md b/docs/comprehension-history.md index ee87e816..0fd6b682 100644 --- a/docs/comprehension-history.md +++ b/docs/comprehension-history.md @@ -422,3 +422,33 @@ Inherited architect, decided by: - `bin/metric_bench/places.py:7` `RUN`, `SEAT_PLACES`, `PLACE` and `:60` `resolved`: a regex reader of a prose format, and a historical quirk to know first - `AGENTS.md:35` "Scoring run": the section's name no longer covers its use by paired rulings - `skills/larv-review/SKILL.md:64` "Re-entry", better: which passes a fix reruns is explicit + +## 2026-10-08T23:12:17Z, PR #231 at 53ed515, against 12d6d75 + +Ruling: better + +| Seat | Vote | +|---|---| +| Mid A | better | +| Inherited architect | better | + +Mid A, decided by: + +- `bin/larv_review/rules.py:64` `round_counts`, with `:10` `CAP` and `bin/larv_review/main.py:118` `round_count`, better: a fourth round leads cold to one named function, where the base had only `skills/larv-review/SKILL.md:58` "Count" to carry out by hand +- `bin/larv_review/main.py:1` the module docstring, better: the base, round count, trigger, vote rule and seats file are written beside the code that carries them out +- `bin/larv_review/rules.py:41` `ruling` and `:27` `votes`, better: the vote rule is a short pure function, changeable without the skill text in mind +- `bin/larv_review/git.py:4` the import of `HistoryChange` from rules, with `:50` `history_changes`: the git layer takes its result type from the rules module, so the direction among the three modules is not obvious +- `bin/larv_review/history.py:85` `resolved` and `:56` `scoring_runs`: they serve only metric-bench, so old-history path logic sits in the review tool's module +- `bin/metric_bench/main.py:143` `git` against `bin/larv_review/git.py:9` `git`: two private git runners with different error handling +- `bin/larv_review/rules.py:106` `scoring_run_due`: the densest new unit, two plans, shipped IDs and a flag held at once +- `skills/larv-review/SKILL.md:93` "Paired ruling" and `:100` "Scoring run": more vocabulary, though each mechanical step now names a subcommand + +Inherited architect, decided by: + +- `bin/larv_review/rules.py:64` `round_counts`, with `bin/larv_review/main.py:118` `round_count`, better: the 3am question leads to `round-count` and one pure function, where the base's `skills/larv-review/SKILL.md:58` "Count" was prose to carry out against `git log` +- `bin/larv_review/rules.py:106` `scoring_run_due`, better: the trigger is a checkable function that prints its reason, though dense in its `and`/`or` binding and set arithmetic +- `bin/larv_review/main.py:1` the module docstring, better: the history format and ratchet have one tested home; `skills/larv-review/SKILL.md:42` now points at `--help` for the rules +- `bin/larv_review/history.py:85` `resolved`, `:56` `scoring_runs` and `:61` `seat_places`: a parser only metric-bench uses, under the review tool's name; where it rots first +- `bin/larv_review/git.py:4` the import of `HistoryChange` from rules, and `bin/metric_bench/main.py:143` `git`: a reversed dependency and two git runners +- `bin/larv_review/seats.py:7` `SCORING_SEATS` and `SEAT_LINE`, with `bin/larv_review/rules.py:11` `FIRST_SEATS`: seat names spelled in four places +- `bin/larv_review/main.py:164` `record` and `bin/larv_review/history.py:52` `entries`: positional regex groups that need `HEADING` open beside them diff --git a/skills/larv-review/SKILL.md b/skills/larv-review/SKILL.md index 09d565c1..e0c081a7 100644 --- a/skills/larv-review/SKILL.md +++ b/skills/larv-review/SKILL.md @@ -39,7 +39,7 @@ A pass is one kind of review, a row of the table, named by its first column. Its | Product-owner | product-owner-reviewer | changes an external surface: API, CLI, UI, error or deprecation text a consumer reads, README and docs an outside reader lands on | | Prose | prose-reviewer | every chunk, one round | -`~/.claude/bin/larv-review` holds this section's mechanical rules: the round count, the paired ruling's base and vote count, the scoring run's trigger and the history's format. Run it in the chunk's worktree; `larv-review --help` states each rule. On exit 1, repair what its message names and run it again. +`~/.claude/bin/larv-review` holds this section's mechanical rules: the round count, the paired ruling's base and vote count, the scoring run's trigger and the history's format. Run it in the chunk's worktree; `~/.claude/bin/larv-review --help` states each rule. On exit 1, repair what its message names and run it again. A comment is prose, not code. Passes run in this order: line-level polish on code the architect wants restructured, or on a call the security pass will rewrite, is wasted work. @@ -57,7 +57,7 @@ Give a reviewer without Bash the branch diff and `git ls-files`'s output in its - **Round.** A round is one launch of a pass's reviewer: the first, each re-entry, and the rerun after the architect returns Stage 0 questions ("Architecture" below). A rescore is a round only as "Architecture" โ†’ "Fresh" says. - **Architecture round.** The architecture pass's first round is the architect (unless skipped), the principles audit and the comprehension check, which "Architecture" โ†’ "Suspended" may skip. A later round relaunches each reviewer whose ๐Ÿ”ด or ๐ŸŸก the previous round's fixes answer, the comprehension check only as "Architecture" โ†’ "Fresh" says. Where those fixes carry an architectural decision, the architect and the principles audit run again. - **Auto-reviewer.** The external auto-reviewer (ยง4) is a pass of its own, each review it posts a round. -- **Count.** Close each round with one commit that holds the round's fixes and is titled `Answer round : โ€ฆ`, `` being the pass's name in lower case, such as `full scan`. A round that changed nothing gets an empty commit (`git commit --allow-empty`). Push the commits when ยง4 runs next, where there is a remote. `larv-review round-count` prints each pass's count and marks a pass at the cap. The auto-reviewer's count is the number of its reviews on the PR, less its reviews of a `Rescore:` commit. +- **Count.** Close each round with one commit that holds the round's fixes and is titled `Answer round : โ€ฆ`, `` being the pass's name in lower case, such as `full scan`. A round that changed nothing gets an empty commit (`git commit --allow-empty`). Push the commits when ยง4 runs next, where there is a remote. `~/.claude/bin/larv-review round-count` prints each pass's count and marks a pass at the cap. The auto-reviewer's count is the number of its reviews on the PR, less its reviews of a `Rescore:` commit. - **Later rounds.** A rerun pass reviews only what changed since it last reviewed: `git diff HEAD`, since the fixes may be unpushed. The comprehension check's seats still read the whole project. From round 2, prompt an agent under `~/.claude/agents/` with its own last round's findings verbatim too. - **Done.** A pass is done when its latest round leaves no ๐Ÿ”ด or ๐ŸŸก standing: none was reported, or each was shown factually wrong, declined, filed, or named under the bar per "Findings", or, for the prose pass, fixed. Resolve that round's ๐ŸŸขs and โ“s per "Findings" too. - **Cap.** A pass takes at most three rounds per chunk. Instead of a fourth, list what is open and ask the user. For the auto-reviewer, ask before the push that would summon its fourth, and hold the fixes unpushed until the answer. @@ -92,12 +92,12 @@ Then the comprehension check: simulated readers, launched per `~/.claude/skills/ **Paired ruling**, in every architecture pass. Each seat votes whether the project reads better, the same or worse at this branch's head than at the base. -- **Base.** The last measured commit, which `larv-review ruling-base` prints. +- **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 `larv-review --help` shows, and run `larv-review record-ruling `. On `Split:`, launch the maintainability senior and Junior A together, add their lines, and run it again. +- **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 it prints, which it appends to the history. -**Scoring run**, when `larv-review needs-scoring-run ` prints `Scoring run due:`. Run it 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 `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 it 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: @@ -113,7 +113,7 @@ Two files of the project keep the records: - **History.** `docs/comprehension-history.md` keeps every paired ruling and scoring run, which `larv-review` appends; nothing edits them. 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: a heading of the date or time the entry gives and whatever it names the run by, its commit included where named, and a table with the mean alone. The rest of the entry stays. +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: run `~/.claude/bin/larv-review record-scoring` on a seats file whose first line is the date or time the entry gives, then what it names the run by and the commit, the one it names or else the one that wrote those scores into the entry, and whose one seat line is `Mean:` followed by the five scores. 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`). diff --git a/todo.md b/todo.md index f037aeb5..47261aa8 100644 --- a/todo.md +++ b/todo.md @@ -24,7 +24,6 @@ | ID | Release | Exempt | Item | R | S | A | G | Goals | Score | |---|---|---|---|---|---|---|---|---|---| -| 85 | 0.1.0 | | **Move larv-review's mechanical rules โ€” the paired ruling's base and vote count, each pass's round count, the scoring run's trigger and the comprehension history's format โ€” into one tested tool under `bin/`, so the skill says only when to run it and what each answer means.** | 4 | 7 | 8 | 9 | 1.1 | 28.1 | | 1 | 0.1.0 | question | **Say in README โ†’ Install how the transcript archive is backed up, once bender-infra backs up ai-sandbox's data volume.** | 3 | 5 | 8 | 9 | 3, 4 | 27.0 | | 62 | 0.1.0 | defect | **Lift Locality, Self-sufficiency and the overall to the comprehension floor, at the places the seats name.** | 4 | 6 | 6 | 8 | 1.1 | 22.3 | | 21 | 0.1.0 | | **Give `settings.json`'s model one writer, and sort its keys.** | 3 | 3 | 6 | 7 | 1.3 | 21.8 | @@ -53,10 +52,6 @@ ## Details -### 85. Move larv-review's mechanical rules โ€” the paired ruling's base and vote count, each pass's round count, the scoring run's trigger and the comprehension history's format โ€” into one tested tool under `bin/`, so the skill says only when to run it and what each answer means. - -2026-10-08, lilleman: Every comprehension run since PR #224 named `skills/larv-review/SKILL.md` ยง3 "Architecture" the hardest place, and PR #228's paired ruling ruled worse on rules a program should hold: the base's `git log` search and fallbacks, the vote arithmetic, a trigger written out three times, and the round count PR #225's seats said only prose enforces. PR #228's reviewers found about twenty edge cases in that text, among them squash against merge commits, entry order, a vote with no place, and a trigger judged before items are removed; tests can hold each, prose could not. Keep the skill's judgement calls in prose, and give the tool the history's format, so the base search does not hang on the wording of a line. The history's reader in `bin/metric_bench/places.py` moves into that tool, so the format has one reader. - ### 1. Say in README โ†’ Install how the transcript archive is backed up, once bender-infra backs up ai-sandbox's data volume. It lives under `~/.claude`, which `.gitignore` keeps from the remote, so a lost disk loses every unattended run's record. Back it up only to a destination private to me and encrypted at rest: the worker runs with permissions bypassed, so the archived tool results can hold credentials it read.