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):