diff --git a/.gitignore b/.gitignore index 85433283..62de3f31 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ !bin/failure.py !bin/file_writes.py !bin/git_command.py +!bin/git_repo.py !bin/larv-review !bin/larv_review/ !bin/larv_review/*.py @@ -41,9 +42,13 @@ !bin/reading_cost/*.py !bin/repo_checks/ !bin/repo_checks/*.py +!bin/round_titles.py !bin/rule-hook !bin/rule_hook/ !bin/rule_hook/*.py +!bin/score-outcomes +!bin/score_outcomes/ +!bin/score_outcomes/*.py !bin/shell_command.py !bin/statusline.py !bin/test_*.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 385ee686..19ac6e31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +- Every `todo.md` item carries a C score, how hard the change is to get right, from 1 to 10, in a column after S. C stays out of the score. `rank_todo.py` fails on an items table without the column, and the rule hook then blocks committing that `todo.md`. Before the next commit that changes a project's `todo.md`, add the column and score every item's C, as `rank_todo.py --help` shows. +- The new `bin/score-outcomes` shows what finished chunks measured beside the R, S and C their items were guessed at: lines and files changed, review rounds, and πŸ”΄ and 🟑 findings. It reads them from the default branch's merge commits, so a project that merges by squash or fast-forward shows none. Given a guess, it lists the 5 finished items guessed nearest. It always reports, for each score, the median outcome at each guessed value, once 10 chunks that each shipped one item record it: R against πŸ”΄ findings, S against lines changed, C against review rounds past each pass's first. A session filing or editing an item runs it and scores R, S and C from what it shows. +- larv-review round commits now carry the round's πŸ”΄ and 🟑 counts, `Answer stability round 1: 1 πŸ”΄, 2 🟑; …`, and the rule hook's new `round-title-counts` rule blocks a round title without them. - The stability reviewer mutation-tests the lines each change adds or modifies: it makes small changes to that code, such as flipping a comparison. For each test to add or strengthen, it reports one 🟑 naming the changes that test would catch. It uses the project's documented mutation command, or else cargo-mutants, Infection, mutmut or Stryker. The technical principles replace "Test coverage should not decline" with "Every mutant of a changed line fails a test, unless the mutant leaves behaviour unchanged", and say what a valuable test is: it checks behaviour through the unit's interface, and fails when that behaviour breaks. README β†’ "Tools" gives the mutmut command for `bin/`. Expect longer stability passes and more 🟑s about tests. In a project whose README documents no mutation command, the reviewer picks and installs a tool on each run; document one there to make the runs consistent. - Each new `loop-claude` worker session's prompt now quotes the README's Goals and Audience. A line above them says that the chunk's `todo.md` items, or else the task, set its scope, and that the goals only choose how to deliver it. A session outside the loop reads Goals and Audience before starting a chunk, as `CLAUDE.md` now says. - A session no longer reads the technical principles before writing code. It writes the simplest change that solves its item, test first wherever a test can check the change, and reads a principle only when the item changes it, a finding names it, or a decision or `todo.md` item it writes cites it. larv-review's reviewers hold the change to the principles, and a finding against one names it. Expect more findings from the prose and stability reviewers, since sessions no longer load the rules for comments and READMEs. diff --git a/README.md b/README.md index 050603b6..934ccdf6 100644 --- a/README.md +++ b/README.md @@ -73,24 +73,25 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a - `rank_todo.py [--check] [todo.md]` scores and ranks a project's `todo.md`; `rank_todo.py --help` states the format. - `reading-cost [--reset] [record]` appends a figure for each chunk `loop-claude` finished to a project's `docs/reading-cost.md`, and says whether the figures rise; `reading-cost --help` states the measure. - `rule-hook [overrides]` blocks a tool call that breaks a rule a program can check, unless the call overrides the rule; `settings.json` β†’ `hooks` runs it before each Bash, Edit, MultiEdit and Write call, and `rule-hook --help` states the rules and the override. +- `score-outcomes [R S C]` lists the finished items whose guessed R, S and C sit nearest the given scores, with what their chunks measured, and each score's median outcome; `score-outcomes --help` states the measures. - `statusline.py` renders Claude Code's status line; `settings.json` β†’ `statusLine` runs it. Test on the host, with `uv` on `PATH` to fetch mypy and the Python version Install names (`docs/decisions.md` β†’ `bin/`): `python3 -m unittest discover -s bin -p 'test_*.py'` -To mutation-test a changed module, copy `bin/` to a scratch directory (`cp -r bin "$scratch"`): mutmut writes files beside its config. In the copy, name the module and its tests in a `setup.cfg`, as below for `larv_review/rounds.py`. Leave out each test class that starts a tool's launcher through `subprocess`: a mutated module fails to load in a process mutmut did not start. +To mutation-test a changed module, copy `bin/` to a scratch directory (`cp -r bin "$scratch"`): mutmut writes files beside its config. In the copy, name the module and its tests in a `setup.cfg`, as below for `score_outcomes/outcomes.py`. Leave out each test class that starts a tool's launcher through `subprocess`: a mutated module fails to load in a process mutmut did not start. ```ini [mutmut] -source_paths=larv_review/rounds.py +source_paths=score_outcomes/outcomes.py also_copy=. -pytest_add_cli_args_test_selection=larv_review/ +pytest_add_cli_args_test_selection=score_outcomes/ pytest_add_cli_args=-k - not LarvReviewTool + not ScoreOutcomesTool ``` Then, in the copy: `uvx --with pytest 'mutmut>=3,<4' run && uvx --with pytest 'mutmut>=3,<4' results`, and `uvx --with pytest 'mutmut>=3,<4' show ` to see a mutant's change. The config keys are mutmut 3's. -`bin/` is the import root: each launcher puts it on `sys.path`, so a module imports another by its path under `bin/`, such as `from claude_code.entries import parse_entry`. Each tool's package holds its tests; `rank_todo.py` and `statusline.py` are tools of one file each, tested beside them, and `rule_hook` imports `rank_todo.py`'s check. The other non-test modules at `bin/`'s root, `claude_code/` and `transcript_archive/` serve more than one tool. `test_env.py` serves the tests, and `repo_checks/` tests the repo itself. +`bin/` is the import root: each launcher puts it on `sys.path`, so a module imports another by its path under `bin/`, such as `from claude_code.entries import parse_entry`. Each tool's package holds its tests; `rank_todo.py` and `statusline.py` are tools of one file each, tested beside them, `rule_hook` imports `rank_todo.py`'s check, and `score_outcomes` imports `reading_cost`'s record path. The other non-test modules at `bin/`'s root, `claude_code/` and `transcript_archive/` serve more than one tool. `test_env.py` serves the tests, and `repo_checks/` tests the repo itself. ## Tracking a new file diff --git a/bin/git_repo.py b/bin/git_repo.py new file mode 100644 index 00000000..7f36bd03 --- /dev/null +++ b/bin/git_repo.py @@ -0,0 +1,69 @@ +"""Run git in the current directory, and read the checkout, its default branch and its files.""" +import re +import subprocess + +from failure import Failure + + +def git(*args: str) -> str | Failure: + try: + ran = subprocess.run(["git", *args], capture_output=True, text=True) + except (OSError, ValueError) as failure: + return Failure(f"git could not start: {failure}") + return ran.stdout if ran.returncode == 0 else Failure(f"git {' '.join(args)}: {ran.stderr.strip()}") + + +def top() -> str | Failure: + found = git("rev-parse", "--show-toplevel") + return found if isinstance(found, Failure) else found.strip() + + +def default_branch(stale_ok: bool) -> tuple[str, str | None] | Failure: + """The default branch's ref, `origin/` after a fetch with that remote, else the local main or master, and a note for stderr. With stale_ok, a failed fetch reads origin as last fetched, and the note says so.""" + remotes = git("remote") + if isinstance(remotes, Failure): + return remotes + if "origin" in remotes.split(): + fetch = git("fetch", "--quiet", "origin") + if isinstance(fetch, Failure) and not stale_ok: + return fetch + note = f"reading origin as last fetched: {fetch.reason}" if isinstance(fetch, Failure) else None + default = git("symbolic-ref", "--short", "refs/remotes/origin/HEAD") + named = default.strip() if not isinstance(default, Failure) else origin_head() + return named if isinstance(named, Failure) else (named, note) + for branch in ("main", "master"): + if not isinstance(git("rev-parse", "--quiet", "--verify", f"refs/heads/{branch}"), Failure): + return branch, None + 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; set it with `git remote set-head origin --auto`") + + +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 not commit_exists(revision): + return "" + listed = git("ls-tree", "--name-only", revision, "--", path) + if isinstance(listed, Failure): + return listed + return git("show", f"{revision}:{path}") if listed.strip() else "" + + +def full_history() -> Failure | None: + """Why the checkout lacks the history a tool reads, None when it holds it all.""" + shallow = git("rev-parse", "--is-shallow-repository") + if isinstance(shallow, Failure): + return shallow + return Failure("a shallow clone lacks the full history; run `git fetch --unshallow origin`") if shallow.strip() == "true" else None diff --git a/bin/larv_review/git.py b/bin/larv_review/git.py index ef16ce64..f0ca946b 100644 --- a/bin/larv_review/git.py +++ b/bin/larv_review/git.py @@ -1,73 +1,12 @@ -import re -import subprocess - from failure import Failure +from git_repo import file_at, full_history, git from comprehension_history import HISTORY, HistoryChange -def git(*args: str) -> str | Failure: - try: - ran = subprocess.run(["git", *args], capture_output=True, text=True) - except (OSError, ValueError) as failure: - return Failure(f"git could not start: {failure}") - return ran.stdout if ran.returncode == 0 else Failure(f"git {' '.join(args)}: {ran.stderr.strip()}") - - -def top() -> str | Failure: - found = git("rev-parse", "--show-toplevel") - return found if isinstance(found, Failure) else found.strip() - - -def default_branch(stale_ok: bool) -> tuple[str, str | None] | Failure: - """The default branch's ref, `origin/` after a fetch with that remote, else the local main or master, and a note for stderr. With stale_ok, a failed fetch reads origin as last fetched, and the note says so.""" - remotes = git("remote") - if isinstance(remotes, Failure): - return remotes - if "origin" in remotes.split(): - fetch = git("fetch", "--quiet", "origin") - if isinstance(fetch, Failure) and not stale_ok: - return fetch - note = f"reading origin as last fetched: {fetch.reason}" if isinstance(fetch, Failure) else None - default = git("symbolic-ref", "--short", "refs/remotes/origin/HEAD") - named = default.strip() if not isinstance(default, Failure) else origin_head() - return named if isinstance(named, Failure) else (named, note) - for branch in ("main", "master"): - if not isinstance(git("rev-parse", "--quiet", "--verify", f"refs/heads/{branch}"), Failure): - return branch, None - 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; set it with `git remote set-head origin --auto`") - - -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 not commit_exists(revision): - return "" - listed = git("ls-tree", "--name-only", revision, "--", path) - if isinstance(listed, Failure): - return listed - return git("show", f"{revision}:{path}") if listed.strip() else "" - - def history_changes(default: str) -> list[HistoryChange] | Failure: """Each merged change on the default branch that touched the history, newest first; a merge commit counts as one change against its first parent.""" - shallow = git("rev-parse", "--is-shallow-repository") - if isinstance(shallow, Failure): - return shallow - if shallow.strip() == "true": - return Failure("a shallow clone lacks the commits the base search reads; run `git fetch --unshallow origin`") + if partial := full_history(): + return partial commits = git("log", "--first-parent", "--format=%H", default, "--", HISTORY) if isinstance(commits, Failure): return commits diff --git a/bin/larv_review/main.py b/bin/larv_review/main.py index c15a2346..c9b8218c 100644 --- a/bin/larv_review/main.py +++ b/bin/larv_review/main.py @@ -88,11 +88,12 @@ import sys import typing from larv_review.ruling_base import base -from larv_review.rounds import CAP, PASSES, round_counts -from larv_review.git import default_branch, file_at, git, history_changes +from round_titles import CAP, PASSES, round_counts +from git_repo import default_branch, file_at, git from failure import Failure from larv_review.scoring import FLOOR from comprehension_history import HISTORY +from larv_review.git import history_changes from larv_review.plan import plan_reasons from larv_review.record import record_ruling, record_scoring diff --git a/bin/larv_review/plan.py b/bin/larv_review/plan.py index 90536e0c..1efcd418 100644 --- a/bin/larv_review/plan.py +++ b/bin/larv_review/plan.py @@ -1,8 +1,9 @@ import pathlib from failure import Failure -from larv_review.git import file_at, landed_since_release, top -from todo_table import Item, items, ITEMS_HEADER +from git_repo import file_at, top +from todo_table import Item, items +from larv_review.git import landed_since_release def scoring_run_due(before: list[Item], after: list[Item], ships: list[int], landed: bool) -> list[str] | Failure: @@ -42,10 +43,12 @@ def plan_reasons(default: str, ids: list[int]) -> list[str] | Failure: except (OSError, UnicodeDecodeError) as failure: return Failure(f"could not read todo.md: {failure}") # While a chunk reshapes todo.md into one table, the default branch's todo.md has no items table. - planned = items(before) if ITEMS_HEADER in before.splitlines() else [] + planned = items(before) or [] if isinstance(planned, Failure): return Failure(f"{default}'s todo.md: {planned.reason}") chunk = items(after) + if chunk is None: + return Failure("the checkout's todo.md has no items table; rank_todo.py --help shows one") if isinstance(chunk, Failure): return Failure(f"the checkout's todo.md: {chunk.reason}") landed = landed_since_release(default) diff --git a/bin/larv_review/record.py b/bin/larv_review/record.py index b53e8918..031c7efe 100644 --- a/bin/larv_review/record.py +++ b/bin/larv_review/record.py @@ -2,7 +2,7 @@ import pathlib import time from comprehension_history import appended, DIMENSIONS, heading, Heading, HISTORY, recorded, ruling_entry, scoring_entry, ScoringRun, vote_text -from larv_review.git import commit_exists, top +from git_repo import commit_exists, top from larv_review.ruling import counted, fallen, overall, ruling, split, votes from failure import Failure from larv_review.scoring import fall_ruling, FLOOR, means, under_floor diff --git a/bin/larv_review/rounds.py b/bin/larv_review/rounds.py deleted file mode 100644 index 732e566e..00000000 --- a/bin/larv_review/rounds.py +++ /dev/null @@ -1,17 +0,0 @@ -import re - -CAP = 3 -PASSES = ("architecture", "full scan", "security", "overrides", "stability", "product-owner", "prose") -ROUND = re.compile(r"^Answer (.+?) round ([0-9]+):", re.IGNORECASE) - - -def round_counts(titles: list[str]) -> dict[str, int]: - """Each pass's round count among the branch's `Answer round :` commit titles: the highest , or the number of such commits where that is more, so a repeated number still counts. A pass with none has 0, and a title naming no known pass adds its name. Case is ignored.""" - highest: dict[str, int] = dict.fromkeys(PASSES, 0) - commits: dict[str, int] = dict.fromkeys(PASSES, 0) - for title in titles: - if named := ROUND.match(title): - name = named.group(1).lower() - highest[name] = max(highest.get(name, 0), int(named.group(2))) - commits[name] = commits.get(name, 0) + 1 - return {name: max(highest[name], commits[name]) for name in highest} diff --git a/bin/larv_review/test_larv_review.py b/bin/larv_review/test_larv_review.py index 4d44dccc..ec2a9378 100644 --- a/bin/larv_review/test_larv_review.py +++ b/bin/larv_review/test_larv_review.py @@ -18,7 +18,6 @@ from failure import Failure from larv_review.scoring import fall_ruling, means, under_floor from test_env import isolated_env from todo_table import Item, items -from larv_review.rounds import round_counts from larv_review.seats import score_line, scores, seats_file from larv_review.plan import scoring_run_due @@ -35,11 +34,11 @@ def said(overall: str, locality: str = "same") -> str: 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",)) + return Item(id_, release, "", tagline, {"R": 1, "S": 1, "C": 3, "A": 1, "G": 1}, ("1",)) def todo(*rows: str) -> str: - return "## Items\n\n| ID | Release | Exempt | Item | R | S | A | G | Goals | Score |\n|---|---|---|---|---|---|---|---|---|---|\n" + "".join(f"{row}\n" for row in rows) + return "## Items\n\n| ID | Release | Exempt | Item | R | S | C | A | G | Goals | Score |\n|---|---|---|---|---|---|---|---|---|---|---|\n" + "".join(f"{row}\n" for row in rows) class Seats(unittest.TestCase): @@ -174,23 +173,11 @@ class Base(unittest.TestCase): self.assertIsNone(first_ruling(SCORING)) -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", "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)) - - def test_counts_a_mis_cased_title_under_its_pass(self): - self.assertEqual(round_counts(["Answer Architecture round 4: x", "Answer architecture round 3: y"])["architecture"], 4) - - def test_counts_a_repeated_round_number_as_a_round_of_its_own(self): - self.assertEqual(round_counts(["Answer stability round 3: x", "Answer stability round 3: y", "Answer stability round 2: z", "Answer stability round 1: w"])["stability"], 4) - - class ScoringRunDue(unittest.TestCase): def test_reads_each_rows_id_release_and_tagline(self): - self.assertEqual(items(todo("| 3 | 0.1.0 | | **Do it.** | 1 | 1 | 1 | 1 | 1 | 9.0 |")), [item(3, (0, 1, 0))]) - self.assertIsInstance(items("# todo\n"), Failure) - self.assertIsInstance(items(todo("| 0 | 0.1.0 | | **Do it.** | 1 | 1 | 1 | 1 | 1 | 9.0 |")), Failure) + self.assertEqual(items(todo("| 3 | 0.1.0 | | **Do it.** | 1 | 1 | 3 | 1 | 1 | 1 | 9.0 |")), [item(3, (0, 1, 0))]) + self.assertIsNone(items("# todo\n")) + self.assertIsInstance(items(todo("| 0 | 0.1.0 | | **Do it.** | 1 | 1 | 3 | 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))] @@ -226,7 +213,7 @@ class LarvReviewTool(unittest.TestCase): self.checkout = root / "proj" subprocess.run(["git", "init", "-q", "--bare", "-b", "main", str(root / "origin.git")], check=True, env=self.env) subprocess.run(["git", "clone", "-q", str(root / "origin.git"), str(self.checkout)], check=True, env=self.env, capture_output=True) - self.commit("start", {"todo.md": todo("| 1 | 0.1.0 | | **Do it.** | 1 | 1 | 1 | 1 | 1 | 9.0 |", "| 2 | 0.2.0 | | **Then this.** | 1 | 1 | 1 | 1 | 1 | 9.0 |", "| 3 | 0.2.0 | | **And this.** | 1 | 1 | 1 | 1 | 1 | 9.0 |")}) + self.commit("start", {"todo.md": todo("| 1 | 0.1.0 | | **Do it.** | 1 | 1 | 3 | 1 | 1 | 1 | 9.0 |", "| 2 | 0.2.0 | | **Then this.** | 1 | 1 | 3 | 1 | 1 | 1 | 9.0 |", "| 3 | 0.2.0 | | **And this.** | 1 | 1 | 3 | 1 | 1 | 1 | 9.0 |")}) self.git("push", "-q", "origin", "HEAD:main") self.git("remote", "set-head", "origin", "main") self.git("switch", "-q", "-c", "chunk") @@ -283,6 +270,17 @@ class LarvReviewTool(unittest.TestCase): self.assertEqual(self.run_tool("needs-scoring-run").stdout, "No scoring run due.\n") self.assertIn("todo.md's ID column", self.run_tool("needs-scoring-run", "item-85").stderr) + def test_reads_a_default_branch_plan_without_a_table_as_empty_and_refuses_a_checkout_without_one(self): + self.git("switch", "-q", "-c", "reshape", "main") + self.commit("Plan as a list", {"todo.md": "# todo\n\n- [ ] Do it.\n"}) + self.git("push", "-q", "origin", "HEAD:main") + self.git("switch", "-q", "chunk") + self.assertEqual(self.run_tool("needs-scoring-run", "2").returncode, 0) + (self.checkout / "todo.md").write_text("# todo\n") + ran = self.run_tool("needs-scoring-run", "2") + self.assertEqual(ran.returncode, 1) + self.assertIn("the checkout's todo.md has no items table", ran.stderr) + def test_records_a_ruling_once_four_seats_settle_a_split(self): lines = """\ PR #2 at {start}, against {start} diff --git a/bin/rank_todo.py b/bin/rank_todo.py index 6aea06d8..23698a74 100755 --- a/bin/rank_todo.py +++ b/bin/rank_todo.py @@ -26,9 +26,9 @@ A valid todo.md; ## Details and each item's detail are optional: ## Items - | ID | Release | Exempt | Item | R | S | A | G | Goals | Score | - |---|---|---|---|---|---|---|---|---|---| - | 1 | 0.1.0 | | **Make the first thing work.** | 2 | 3 | 8 | 9 | 1 | 0 | + | ID | Release | Exempt | Item | R | S | C | A | G | Goals | Score | + |---|---|---|---|---|---|---|---|---|---|---| + | 1 | 0.1.0 | | **Make the first thing work.** | 2 | 3 | 4 | 8 | 9 | 1 | 0 | ## Details @@ -40,7 +40,8 @@ A valid todo.md; ## Details and each item's detail are optional: - The bar is judged on the Score as shown, to one decimal. - A new item takes Next ID, and Next ID then goes up by one; every ID stays below it. - The goal weights list README.md's numbered goals in order, a sub-goal such as 1.1 included. -- An item's R, S, A and G are whole numbers from 1 to 10; Goals lists goal numbers, comma separated. +- An item's R, S, C, A and G are whole numbers from 1 to 10; Goals lists goal numbers, comma separated. + C, how hard the change is to get right, stays out of the formula. - An item's Exempt cell is empty, or names why the bar does not apply: decision, defect, principle, question or security. An item docs/decisions.md cites as "`todo.md` item N" must be exempt, and a row marked decision must be cited there. @@ -57,7 +58,7 @@ import pathlib import re import sys -from todo_table import cells, Item, ITEMS_HEADER, parse_row, table_rows +from todo_table import cells, Item, ITEMS_HEADER, parse_row, table_rows, WITHOUT_C from failure import Failure from markdown_text import FENCE, sections from file_writes import replace_file @@ -186,6 +187,9 @@ def rank(text: str, readme: str, decisions: str) -> Ranked | Failure: def read_scoring(text: str, lines: list[str], readme: str) -> Scoring | Failure: if ITEMS_HEADER not in lines and "## Items" not in lines: return Failure("todo.md is not in the scored-table format; rank_todo.py --help shows a valid one") + # A table without C fails, so no chunk starts on an unscored item. + if WITHOUT_C in lines: + return Failure("todo.md's items table has no C column; add one after S, and score each item's C from 1 to 10 per rank_todo.py --help") goals = readme_goals(readme) if isinstance(goals, Failure): return goals @@ -367,7 +371,7 @@ def parse_item(row: str, weights: dict[str, float]) -> Item | Failure: def render_item(item: Item, value: float) -> str: release = ".".join(str(part) for part in item.release) - scores = " | ".join(str(item.scores[name]) for name in "RSAG") + scores = " | ".join(str(item.scores[name]) for name in "RSCAG") return f"| {item.id} | {release} | {item.exempt} | {item.tagline} | {scores} | {', '.join(item.goals)} | {value:.1f} |" diff --git a/bin/reading_cost/figures.py b/bin/reading_cost/figures.py index 1fc330e1..03f17065 100644 --- a/bin/reading_cost/figures.py +++ b/bin/reading_cost/figures.py @@ -11,6 +11,7 @@ from utc_stamp import STAMPED FIGURE = re.compile(rf"^Reading cost, chunk (\w+), finished ({STAMPED})$") FIGURE_PLACE = re.compile(r"^- `(.+)` (\d+)$") PLACES_KEPT = 10 +RECORD = "docs/reading-cost.md" RESET = "Reading cost reset, " RESET_AT = re.compile(rf"^{RESET}({STAMPED})$") TOKENS = re.compile(r"^(\d+) new input tokens before the first commit\.$") diff --git a/bin/reading_cost/main.py b/bin/reading_cost/main.py index 2dbfc044..aaceb43c 100644 --- a/bin/reading_cost/main.py +++ b/bin/reading_cost/main.py @@ -31,7 +31,7 @@ import time from reading_cost.measure import Checkout, measure, Reading from failure import Failure -from reading_cost.figures import figure, merged, readings_of, RESET, trend, unheld +from reading_cost.figures import figure, merged, readings_of, RECORD, RESET, trend, unheld from transcript_archive.read import finished_chunks, read_threads from transcript_archive.location import project_archive from file_writes import replace_file @@ -57,7 +57,7 @@ def main(argv: list[str]) -> int: return failed(checkout) home = pathlib.Path.home() archive = project_archive(checkout.main_root, home, os.environ) - record = pathlib.Path(given[0]) if given else pathlib.Path(checkout.current_root, "docs", "reading-cost.md") + record = pathlib.Path(given[0]) if given else pathlib.Path(checkout.current_root, RECORD) updated = update(record, archive, checkout, str(home), utc(time.time()) if reset else None) if isinstance(updated, Failure): return failed(updated) diff --git a/bin/repo_checks/test_types.py b/bin/repo_checks/test_types.py index fcd2952c..7a4da3a6 100644 --- a/bin/repo_checks/test_types.py +++ b/bin/repo_checks/test_types.py @@ -15,5 +15,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", "--exclude", "/test_", "-p", "claude_code", "-m", "comprehension_history", "-p", "larv_review", "-p", "loop_claude", "-m", "markdown_text", "-p", "metric_bench", "-m", "project_key", "-m", "rank_todo", "-p", "reading_cost", "-p", "rule_hook", "-m", "shell_command", "-m", "statusline", "-m", "todo_table", "-p", "transcript_archive", "-m", "utc_stamp"], 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", "--exclude", "/test_", "-p", "claude_code", "-m", "comprehension_history", "-m", "git_repo", "-p", "larv_review", "-p", "loop_claude", "-m", "markdown_text", "-p", "metric_bench", "-m", "project_key", "-m", "rank_todo", "-m", "round_titles", "-p", "reading_cost", "-p", "rule_hook", "-p", "score_outcomes", "-m", "shell_command", "-m", "statusline", "-m", "todo_table", "-p", "transcript_archive", "-m", "utc_stamp"], capture_output=True, cwd=ROOT / "bin", text=True) self.assertEqual(ran.returncode, 0, ran.stdout + ran.stderr) diff --git a/bin/round_titles.py b/bin/round_titles.py new file mode 100644 index 00000000..ec7a452c --- /dev/null +++ b/bin/round_titles.py @@ -0,0 +1,38 @@ +"""The titles of larv-review's round commits, `Answer round : πŸ”΄, 🟑; `: each pass's round count, and the findings the rounds reported.""" +import re + +CAP = 3 +PASSES = ("architecture", "full scan", "security", "overrides", "stability", "product-owner", "prose") +ROUND = re.compile(r"^Answer (.+?) round ([0-9]+):", re.IGNORECASE) +# What follows a round title's colon: the round's πŸ”΄ and 🟑 counts, then `;` and its summary, if any. +FINDINGS = re.compile(r" ([0-9]+) πŸ”΄, ([0-9]+) 🟑(?:;|$)") + + +def round_counts(titles: list[str]) -> dict[str, int]: + """Each pass's round count among the branch's `Answer round :` commit titles: the highest , or the number of such commits where that is more, so a repeated number still counts. A pass with none has 0, and a title naming no known pass adds its name. Case is ignored.""" + highest: dict[str, int] = dict.fromkeys(PASSES, 0) + commits: dict[str, int] = dict.fromkeys(PASSES, 0) + for title in titles: + if named := ROUND.match(title): + name = named.group(1).lower() + highest[name] = max(highest.get(name, 0), int(named.group(2))) + commits[name] = commits.get(name, 0) + 1 + return {name: max(highest[name], commits[name]) for name in highest} + + +def lacks_counts(title: str) -> bool: + """Whether title is a round title without the counts after its colon.""" + named = ROUND.match(title) + return named is not None and not FINDINGS.match(title, named.end()) + + +def round_findings(titles: list[str]) -> tuple[int, int] | None: + """The πŸ”΄ and 🟑 counts summed over the round titles among titles; None where a round title lacks them, or no title is a round.""" + counts = [] + for title in titles: + if named := ROUND.match(title): + found = FINDINGS.match(title, named.end()) + if not found: + return None + counts.append((int(found.group(1)), int(found.group(2)))) + return (sum(red for red, _ in counts), sum(yellow for _, yellow in counts)) if counts else None diff --git a/bin/rule_hook/override_log.py b/bin/rule_hook/override_log.py index d57ed0a2..2bc94655 100644 --- a/bin/rule_hook/override_log.py +++ b/bin/rule_hook/override_log.py @@ -96,7 +96,7 @@ def print_overrides(directory: str) -> int: if unread: print(f"rule-hook overrides cannot read the branch's reflog, so it cannot tell which overrides are this chunk's: {unread.reason}", file=sys.stderr) return 1 - default = default_branch(directory) + default = local_default_branch(directory) log = pathlib.Path(common) / LOG entries = [parsed_entry(line) for line in log.read_text(encoding="utf-8").splitlines()] if log.is_file() else [] on_default = (lambda commit: holds(directory, default, commit)) if default else (lambda commit: False) @@ -115,7 +115,7 @@ def unread_reflog(reflog: str | Failure, head: str | Failure) -> Failure | None: return None if head in reflog.split() else Failure("it does not hold HEAD") -def default_branch(directory: str) -> str | None: +def local_default_branch(directory: str) -> str | None: return next((name for name in ("origin/HEAD", "main", "master") if not isinstance(git(directory, "rev-parse", "--verify", "--quiet", name), Failure)), None) diff --git a/bin/rule_hook/rules.py b/bin/rule_hook/rules.py index 6f93a8de..5fd852c4 100644 --- a/bin/rule_hook/rules.py +++ b/bin/rule_hook/rules.py @@ -4,9 +4,10 @@ import re import typing from git_command import commits +from round_titles import lacks_counts from shell_command import Simple -RuleName = typing.Literal["action-pin", "commit-one-line", "ignorefile-sorted", "image-pin", "no-ai-attribution", "todo-rank-check"] +RuleName = typing.Literal["action-pin", "commit-one-line", "ignorefile-sorted", "image-pin", "no-ai-attribution", "round-title-counts", "todo-rank-check"] @dataclasses.dataclass(frozen=True) @@ -36,6 +37,10 @@ RULES: dict[RuleName, Rule] = { "no commit, PR, issue comment or file carries a Claude or Anthropic attribution, such as a co-author trailer or a generated-with line", "a git, gh or tea command, and any file written", ), + "round-title-counts": Rule( + "a larv-review round's commit title gives the counts of πŸ”΄ and 🟑 findings the round reported, such as `Answer stability round 1: 1 πŸ”΄, 2 🟑; flag a deleted test`, since score-outcomes counts them", + "a git commit whose message opens `Answer round :`", + ), "todo-rank-check": Rule( "while todo.md has changes, staged or not, a git commit waits until ~/.claude/bin/rank_todo.py --check passes on it", "a git commit in a checkout whose todo.md has changes", @@ -99,6 +104,8 @@ def command_breaches(command: str, simples: list[Simple], home: str) -> list[Bre breaches.append(Breach("commit-one-line", "pass the message as one -m '', not from a file", commit.directory)) elif len(commit.messages) > 1 or any("\n" in message.strip() for message in commit.messages): breaches.append(Breach("commit-one-line", "pass the message as one -m '', with no heredoc, second -m or newline", commit.directory)) + if any(lacks_counts(message) for message in commit.messages): + breaches.append(Breach("round-title-counts", "open the summary after the round's colon with ` πŸ”΄, 🟑;`", commit.directory)) return breaches diff --git a/bin/rule_hook/test_rule_hook.py b/bin/rule_hook/test_rule_hook.py index 23e99a61..e4e1be30 100644 --- a/bin/rule_hook/test_rule_hook.py +++ b/bin/rule_hook/test_rule_hook.py @@ -78,6 +78,12 @@ class CommandBreaches(unittest.TestCase): with self.subTest(command): self.assertEqual(checked(command), ["commit-one-line"]) + def test_a_round_title_without_its_counts_breaks_round_title_counts(self): + self.assertEqual(checked("git commit -m 'Answer stability round 1: fix the parser'"), ["round-title-counts"]) + self.assertEqual(checked("git commit --allow-empty -m 'Answer prose round 2: 0 πŸ”΄, 0 🟑'"), []) + self.assertEqual(checked("git commit -m 'Answer stability round 1: 1 πŸ”΄, 2 🟑; fix the parser'"), []) + self.assertEqual(checked("git commit -m 'Answer the question in the README'"), []) + def test_an_attribution_breaks_only_in_a_git_gh_or_tea_command(self): self.assertEqual(checked(f"tea pr create --description '{TRAILER}'"), ["no-ai-attribution"]) self.assertEqual(checked(f"grep -rn '{TRAILER}' ."), []) @@ -275,5 +281,5 @@ class Hook(unittest.TestCase): def test_help_lists_every_rule(self): helped = subprocess.run([str(HOOK), "--help"], capture_output=True, check=True, env=isolated_env(), text=True).stdout - for rule in ["action-pin", "commit-one-line", "ignorefile-sorted", "image-pin", "no-ai-attribution", "todo-rank-check"]: + for rule in ["action-pin", "commit-one-line", "ignorefile-sorted", "image-pin", "no-ai-attribution", "round-title-counts", "todo-rank-check"]: self.assertIn(f" {rule}\n The rule: ", helped) diff --git a/bin/score-outcomes b/bin/score-outcomes new file mode 100755 index 00000000..b28b6bdd --- /dev/null +++ b/bin/score-outcomes @@ -0,0 +1,9 @@ +#!/usr/bin/env python3 +import pathlib +import sys + +sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) + +from score_outcomes import main + +sys.exit(main.main(sys.argv[1:])) diff --git a/bin/score_outcomes/__init__.py b/bin/score_outcomes/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/bin/score_outcomes/main.py b/bin/score_outcomes/main.py new file mode 100644 index 00000000..80362015 --- /dev/null +++ b/bin/score_outcomes/main.py @@ -0,0 +1,110 @@ +"""Show what finished chunks measured beside the scores their items were guessed at, to score a new item by. + +usage: score-outcomes [R S C] + +Run it inside a project checkout or one of its worktrees. It fetches origin, when the checkout has +that remote, and reads origin's default branch, or else the local main or master; a failed fetch +reads origin as last fetched and says so on stderr. + +Git history is the record. A chunk is a merge commit on the default branch's first-parent line +whose change removed items from todo.md, and changed more than todo.md and the records below; it +shipped those items. Each item's guess is its R, S and C in the todo.md the merge's first parent +held; C only where that todo.md scored one. The chunk measures: + +- lines changed: lines added plus lines deleted against the first parent, leaving out todo.md and + the records tools append to, docs/comprehension-history.md and docs/reading-cost.md; +- files: the files those lines are in; +- review rounds past each pass's first: among the branch's `Answer round :` commit + titles, each pass's rounds as `larv-review round-count` counts them, less one, summed; +- πŸ”΄ and 🟑 findings: summed over those titles, each opening ` πŸ”΄, 🟑` after the colon, + such as `Answer stability round 1: 1 πŸ”΄, 2 🟑; flag a deleted test`. Unknown where a round title + lacks the counts, or the branch has no round. + +A project that merges without merge commits, by fast-forward or squash, has no chunk to measure. + +Given R, S and C, it lists the 5 finished items whose guesses sit closest, closest first: the +least mean squared difference over the scores both hold, C only where the item had one, the newest +first among equals. Each line gives what the item's chunk measured, which items shipped with it, and its tagline. + +Then, for each score, the median of the outcome it predicts at each value it was guessed at: R +against πŸ”΄ findings, S against lines changed, C against review rounds past each pass's first. It counts only chunks that +shipped one item, since a chunk measures all its items at once, and reports a score only once 10 +such chunks hold it and its outcome. + +Exit 1, saying why, on bad arguments, when git cannot start, finds no checkout or reads a shallow +clone, or the default branch cannot be read. +""" +import re +import sys + +from git_repo import default_branch, file_at, full_history, git +from failure import Failure +from score_outcomes.outcomes import nearest, Outcome, outcomes_of, render, report, shipped +from utc_stamp import utc + + +def main(argv: list[str]) -> int: + if argv[:1] in (["-h"], ["--help"]): + print(__doc__.strip()) + return 0 + if argv and (len(argv) != 3 or not all(re.fullmatch(r"[1-9]|10", arg) for arg in argv)): + print(f"score-outcomes: cannot read the arguments {' '.join(argv)}; usage: score-outcomes [R S C], each a whole number from 1 to 10", file=sys.stderr) + return 1 + found = default_branch(stale_ok=True) + if isinstance(found, Failure): + return failed(found) + default, note = found + if note: + print(f"score-outcomes: {note}", file=sys.stderr) + outcomes = read_outcomes(default) + if isinstance(outcomes, Failure): + return failed(outcomes) + if argv: + given = dict(zip("RSC", map(int, argv))) + print(f"Finished items nearest R {given['R']}, S {given['S']}, C {given['C']}, closest first:\n") + print("\n".join(render(outcome) for outcome in nearest(outcomes, given)) or "- None: no merge commit on the default branch shipped an item from todo.md. A project that merges by squash or fast-forward has none.") + print() + print("Median outcome at each guessed score, among chunks that shipped one item:\n") + print("\n".join(report(outcomes))) + return 0 + + +def failed(failure: Failure) -> int: + print(f"score-outcomes: {failure.reason}", file=sys.stderr) + return 1 + + +def read_outcomes(default: str) -> list[Outcome] | Failure: + if partial := full_history(): + return partial + merges = git("log", "--first-parent", "--merges", "--format=%H %h %ct", default, "--", "todo.md") + if isinstance(merges, Failure): + return merges + outcomes: list[Outcome] = [] + for line in merges.splitlines(): + merge, short, time = line.split() + measured = measure(merge, short, utc(int(time))) + if isinstance(measured, Failure): + return measured + outcomes += measured + return outcomes + + +def measure(merge: str, short: str, merged: str) -> list[Outcome] | Failure: + """What one merge measured for each item it shipped.""" + before = file_at(f"{merge}^1", "todo.md") + if isinstance(before, Failure): + return before + after = file_at(merge, "todo.md") + if isinstance(after, Failure): + return after + items = shipped(before, after) + if not items: + return [] + numstat = git("diff", "--numstat", f"{merge}^1", merge) + if isinstance(numstat, Failure): + return numstat + titles = git("log", "--format=%s", f"{merge}^1..{merge}^2") + if isinstance(titles, Failure): + return titles + return outcomes_of(items, short, merged, numstat, titles.splitlines()) diff --git a/bin/score_outcomes/outcomes.py b/bin/score_outcomes/outcomes.py new file mode 100644 index 00000000..e032bfb6 --- /dev/null +++ b/bin/score_outcomes/outcomes.py @@ -0,0 +1,92 @@ +import dataclasses +import statistics +import typing + +from comprehension_history import HISTORY +from todo_table import Item, items +from reading_cost.figures import RECORD +from round_titles import round_counts, round_findings + +# Fewest single-item chunks a score needs before its medians print: the 10 figures the reading-cost trend waits for; no published standard sets either. +ENOUGH = 10 +# The plan, and the records tools append to: none of their lines are the chunk's work. +NOT_WORK = ("todo.md", HISTORY, RECORD) + + +@dataclasses.dataclass(frozen=True) +class Outcome: + """What the merge that shipped an item measured. findings holds the πŸ”΄ and 🟑 counts, None where a round title lacks them or the branch has no round.""" + item: Item + merge: str + merged: str + shipped_with: tuple[int, ...] + lines: int + files: int + rounds_past_first: int + findings: tuple[int, int] | None + + +# Each pass takes a first round whatever the change, so only the rounds after it measure how hard the change was to get right. +MEASURES: dict[str, tuple[str, typing.Callable[[Outcome], int | None]]] = { + "R": ("πŸ”΄ findings", lambda outcome: outcome.findings[0] if outcome.findings else None), + "S": ("lines changed", lambda outcome: outcome.lines), + "C": ("review rounds past each pass's first", lambda outcome: outcome.rounds_past_first), +} + + +def shipped(before: str, after: str) -> list[Item]: + """Each item the todo.md before a change holds and the todo.md after it does not, as scored before; none where either holds no items table it can read.""" + planned, left = items(before), items(after) + if not isinstance(planned, list) or not isinstance(left, list): + return [] + kept = {item.id for item in left} + return sorted((item for item in planned if item.id not in kept), key=lambda item: item.id) + + +def outcomes_of(shipped: list[Item], merge: str, merged: str, numstat: str, titles: list[str]) -> list[Outcome]: + """What one merge measured for each item it shipped, from `git diff --numstat` against its first parent and its branch's commit titles; none where it changed nothing but the plan and the records.""" + changed = [row.split("\t", 2) for row in numstat.splitlines()] + work = [row for row in changed if len(row) == 3 and row[2] not in NOT_WORK] + if not work: + return [] + # Git counts a binary file's lines as "-". + lines = sum(int(count) for row in work for count in row[:2] if count.isdigit()) + past_first = sum(max(0, count - 1) for count in round_counts(titles).values()) + ids = [item.id for item in shipped] + return [Outcome(item, merge, merged, tuple(id_ for id_ in ids if id_ != item.id), lines, len(work), past_first, round_findings(titles)) for item in shipped] + + +def nearest(outcomes: list[Outcome], given: dict[str, int], count: int = 5) -> list[Outcome]: + """The outcomes whose guesses sit closest to the given scores: the least mean squared difference over the scores both hold, the newest first among equals.""" + def distance(outcome: Outcome) -> float: + shared = [name for name in given if name in outcome.item.scores] + return sum((given[name] - outcome.item.scores[name]) ** 2 for name in shared) / len(shared) + newest_first = sorted(outcomes, key=lambda outcome: outcome.merged, reverse=True) + return sorted(newest_first, key=distance)[:count] + + +def report(outcomes: list[Outcome]) -> list[str]: + """For each score, the median outcome at each value it was guessed at, among chunks that shipped one item: a chunk measures all its items at once.""" + single = [outcome for outcome in outcomes if not outcome.shipped_with] + lines = [] + for name, (what, measure) in MEASURES.items(): + held = [(outcome.item.scores[name], value) for outcome in single if name in outcome.item.scores and (value := measure(outcome)) is not None] + if len(held) < ENOUGH: + chunks = "chunk that shipped one item records" if len(held) == 1 else "chunks that shipped one item record" + lines.append(f"- {name}, {what}: {len(held)} {chunks} {name} and its outcome; the report needs {ENOUGH}.") + continue + medians = [(guess, [value for at, value in held if at == guess]) for guess in sorted({guess for guess, _ in held})] + lines.append(f"- {name}, {what}: " + ", ".join(f"{guess} β†’ {statistics.median(found):g} ({plural(len(found), 'chunk')})" for guess, found in medians)) + return lines + + +def render(outcome: Outcome) -> str: + scores = ", ".join(f"{name} {outcome.item.scores[name]}" for name in MEASURES if name in outcome.item.scores) + findings = f"{outcome.findings[0]} πŸ”΄, {outcome.findings[1]} 🟑" if outcome.findings else "findings unknown" + others = outcome.shipped_with + together = f", with item{'s' if len(others) > 1 else ''} {', '.join(map(str, others))}" if others else "" + return f"- Item {outcome.item.id}, {scores}: {plural(outcome.lines, 'line')} in {plural(outcome.files, 'file')}, {plural(outcome.rounds_past_first, 'round')} past each pass's first, {findings}; merged {outcome.merged} in {outcome.merge}{together}. {outcome.item.tagline}" + + +def plural(count: int, noun: str) -> str: + return f"{count} {noun}{'' if count == 1 else 's'}" diff --git a/bin/score_outcomes/test_score_outcomes.py b/bin/score_outcomes/test_score_outcomes.py new file mode 100644 index 00000000..b4be6d41 --- /dev/null +++ b/bin/score_outcomes/test_score_outcomes.py @@ -0,0 +1,138 @@ +import os +import pathlib +import subprocess +import sys +import tempfile +import unittest + +sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) + +from test_env import isolated_env +from todo_table import Item +from score_outcomes.outcomes import nearest, Outcome, outcomes_of, render, report, shipped + +TOOL = pathlib.Path(__file__).resolve().parents[1] / "score-outcomes" +HEADER = "| ID | Release | Exempt | Item | R | S | C | A | G | Goals | Score |\n|---|---|---|---|---|---|---|---|---|---|---|\n" +WITHOUT_C = "| ID | Release | Exempt | Item | R | S | A | G | Goals | Score |\n|---|---|---|---|---|---|---|---|---|---|\n" +FIRST = "| 4 | 0.1.0 | | **Do it.** | 2 | 3 | 10 | 6 | 7 | 1 | 9.0 |" +SECOND = "| 5 | 0.1.0 | | **Then this.** | 4 | 6 | 8 | 6 | 7 | 1 | 9.0 |" + + +def todo(*rows: str, header: str = HEADER) -> str: + return "# todo\n\n## Items\n\n" + header + "".join(f"{row}\n" for row in rows) + + +def item(id_: int, scores: dict[str, int]) -> Item: + return Item(id_, (0, 1, 0), "", f"**Item {id_}.**", scores, ("1",)) + + +def outcome(id_: int, r: int, s: int, c: int | None, lines: int = 10, rounds: int = 1, findings: tuple[int, int] | None = (0, 0), merged: str = "2026-10-13T10:00:00Z", shipped_with: tuple[int, ...] = ()) -> Outcome: + return Outcome(item(id_, {"R": r, "S": s} | ({"C": c} if c else {})), "aaaaaaa", merged, shipped_with, lines, 1, rounds, findings) + + +class Shipped(unittest.TestCase): + def test_ships_each_item_the_change_removed_with_the_scores_it_had_before(self): + self.assertEqual([found.id for found in shipped(todo(FIRST, SECOND), todo(SECOND))], [4]) + self.assertEqual(shipped(todo(FIRST, SECOND), todo(SECOND))[0].scores, {"R": 2, "S": 3, "C": 10, "A": 6, "G": 7}) + + def test_lists_the_shipped_items_by_id(self): + self.assertEqual([found.id for found in shipped(todo(SECOND, FIRST), todo())], [4, 5]) + + def test_reads_a_table_from_before_c_joined_it(self): + older = "| 4 | 0.1.0 | | **A \\| B.** | 2 | 3 | 6 | 7 | 1 | 9.0 |" + self.assertEqual(shipped(todo(older, header=WITHOUT_C), todo(header=WITHOUT_C))[0].scores, {"R": 2, "S": 3, "A": 6, "G": 7}) + + def test_ships_nothing_where_either_plan_has_no_table_it_can_read(self): + self.assertEqual(shipped(todo(FIRST), "# todo\n\n- [ ] Do it.\n"), []) + self.assertEqual(shipped(todo(FIRST, "| x | 0.1.0 | | **Bad.** | 2 | 3 | 5 | 6 | 7 | 1 | 9.0 |"), todo()), []) + + +class OutcomesOf(unittest.TestCase): + def test_measures_the_change_less_the_plan_and_the_tool_records_and_counts_binary_files(self): + numstat = "3\t1\ta.py\n-\t-\tlogo.png\n0\t1\t2026\n5\t0\ttodo.md\n9\t0\tdocs/reading-cost.md\n4\t0\tdocs/comprehension-history.md\n" + titles = ["Answer stability round 1: 1 πŸ”΄, 2 🟑; fix", "Answer stability round 2: 0 πŸ”΄, 1 🟑; fix", "Answer prose round 1: 0 πŸ”΄, 3 🟑", "Do it"] + found = outcomes_of([item(4, {"R": 2}), item(5, {"R": 3})], "abc1234", "2026-10-13T10:00:00Z", numstat, titles) + self.assertEqual(found[0], Outcome(item(4, {"R": 2}), "abc1234", "2026-10-13T10:00:00Z", (5,), 5, 3, 1, (1, 6))) + self.assertEqual(found[1].shipped_with, (4,)) + + def test_measures_no_chunk_that_changed_only_the_plan(self): + self.assertEqual(outcomes_of([item(4, {"R": 2})], "abc1234", "2026-10-13T10:00:00Z", "0\t5\ttodo.md\n", []), []) + + +class Nearest(unittest.TestCase): + def test_lists_the_closest_guesses_first_by_the_mean_over_the_scores_both_hold(self): + found = [outcome(1, 9, 9, 9), outcome(2, 3, 5, None), outcome(3, 3, 4, 6), outcome(4, 3, 4, 9)] + self.assertEqual([each.item.id for each in nearest(found, {"R": 3, "S": 4, "C": 5}, 3)], [3, 2, 4]) + + def test_lists_five_by_default(self): + self.assertEqual(len(nearest([outcome(id_, 3, 4, 5) for id_ in range(6)], {"R": 3, "S": 4, "C": 5})), 5) + + def test_lists_the_newest_first_among_equals(self): + found = [outcome(1, 3, 4, 5, merged="2026-10-12T10:00:00Z"), outcome(2, 3, 4, 5, merged="2026-10-13T09:00:00Z")] + self.assertEqual([each.item.id for each in nearest(found, {"R": 3, "S": 4, "C": 5})], [2, 1]) + + +class Report(unittest.TestCase): + def test_gives_each_guessed_values_median_outcome_once_ten_single_item_chunks_hold_it(self): + found = [outcome(id_, 2, 1 + id_ % 2, 4, lines=10 * id_, rounds=id_) for id_ in range(1, 11)] + lines = report(found + [outcome(11, 2, 2, None, lines=1000, findings=None, shipped_with=(12,))]) + self.assertIn("- R, πŸ”΄ findings: 2 β†’ 0 (10 chunks)", lines) + self.assertIn("- S, lines changed: 1 β†’ 60 (5 chunks), 2 β†’ 50 (5 chunks)", lines) + self.assertIn("- C, review rounds past each pass's first: 4 β†’ 5.5 (10 chunks)", lines) + + def test_says_how_many_chunks_it_has_under_ten(self): + self.assertIn("- C, review rounds past each pass's first: 1 chunk that shipped one item records C and its outcome; the report needs 10.", report([outcome(1, 2, 2, 4), outcome(2, 2, 2, None)])) + + +class Render(unittest.TestCase): + def test_names_the_items_shipped_together_and_unknown_findings(self): + self.assertEqual(render(outcome(4, 2, 3, None, lines=1, rounds=2, findings=None, shipped_with=(5, 6))), "- Item 4, R 2, S 3: 1 line in 1 file, 2 rounds past each pass's first, findings unknown; merged 2026-10-13T10:00:00Z in aaaaaaa, with items 5, 6. **Item 4.**") + self.assertEqual(render(outcome(4, 2, 3, 4, findings=(1, 2))), "- Item 4, R 2, S 3, C 4: 10 lines in 1 file, 1 round past each pass's first, 1 πŸ”΄, 2 🟑; merged 2026-10-13T10:00:00Z in aaaaaaa. **Item 4.**") + self.assertIn("1 round past each pass's first, 0 πŸ”΄, 0 🟑; merged 2026-10-13T10:00:00Z in aaaaaaa, with item 5. ", render(outcome(4, 2, 3, 4, rounds=1, shipped_with=(5,)))) + + +class ScoreOutcomesTool(unittest.TestCase): + def setUp(self): + temp = tempfile.TemporaryDirectory() + self.addCleanup(temp.cleanup) + root = pathlib.Path(os.path.realpath(temp.name)) + self.env = {**isolated_env(), "GIT_CONFIG_GLOBAL": os.devnull, "HOME": str(root)} + self.checkout = root / "proj" + self.checkout.mkdir() + self.git("init", "-q", "-b", "main") + self.commit("start", {"todo.md": todo(FIRST, SECOND)}) + + 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 + + def commit(self, title, files): + for name, text in files.items(): + (self.checkout / name).parent.mkdir(parents=True, exist_ok=True) + (self.checkout / name).write_text(text) + self.git("add", name) + self.git("commit", "-q", "-m", title) + + 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 test_measures_each_merged_chunk_that_removed_an_item(self): + self.git("switch", "-q", "-c", "chunk") + self.commit("Do it", {"a.py": "1\n2\n3\n", "todo.md": todo(SECOND)}) + self.commit("Answer stability round 1: 1 πŸ”΄, 2 🟑; fix", {"a.py": "1\n2\n4\n"}) + self.git("switch", "-q", "main") + self.git("merge", "-q", "--no-ff", "-m", "Merge chunk", "chunk") + ran = self.run_tool("2", "3", "10") + self.assertEqual(ran.returncode, 0, ran.stderr) + self.assertIn("- Item 4, R 2, S 3, C 10: 3 lines in 1 file, 0 rounds past each pass's first, 1 πŸ”΄, 2 🟑; merged ", ran.stdout) + self.assertNotIn("Item 5", ran.stdout) + + def test_refuses_a_score_outside_one_to_ten_or_a_missing_score(self): + for args in (("2", "11", "5"), ("0", "3", "5"), ("2", "3")): + with self.subTest(args): + ran = self.run_tool(*args) + self.assertEqual(ran.returncode, 1) + self.assertIn("usage: score-outcomes [R S C]", ran.stderr) + + +if __name__ == "__main__": + unittest.main() diff --git a/bin/test_rank_todo.py b/bin/test_rank_todo.py index 3a6f50d1..56f5a633 100644 --- a/bin/test_rank_todo.py +++ b/bin/test_rank_todo.py @@ -33,13 +33,13 @@ TODO = """# todo ## Items -| ID | Release | Exempt | Item | R | S | A | G | Goals | Score | -|---|---|---|---|---|---|---|---|---|---| -| 1 | 0.2.0 | | **Ship the later thing.** | 1 | 1 | 9 | 9 | 1 | 0 | -| 2 | 0.1.0 | | **Tighten the tests.** | 2 | 4 | 5 | 5 | 2.1 | 0 | -| 3 | 0.1.0 | | **Make it fast, `a \\| b`.** | 3 | 8 | 6 | 8 | 2.1, 1 | 0 | -| 4 | 0.1.0 | security | **Rotate the leaked key.** | 9 | 2 | 1 | 1 | 2.1 | 0 | -| 5 | 0.1.0 | decision | **Move the writes out.** | 5 | 5 | 4 | 5 | 2.1 | 0 | +| ID | Release | Exempt | Item | R | S | C | A | G | Goals | Score | +|---|---|---|---|---|---|---|---|---|---|---| +| 1 | 0.2.0 | | **Ship the later thing.** | 1 | 1 | 3 | 9 | 9 | 1 | 0 | +| 2 | 0.1.0 | | **Tighten the tests.** | 2 | 4 | 3 | 5 | 5 | 2.1 | 0 | +| 3 | 0.1.0 | | **Make it fast, `a \\| b`.** | 3 | 8 | 3 | 6 | 8 | 2.1, 1 | 0 | +| 4 | 0.1.0 | security | **Rotate the leaked key.** | 9 | 2 | 3 | 1 | 1 | 2.1 | 0 | +| 5 | 0.1.0 | decision | **Move the writes out.** | 5 | 5 | 3 | 4 | 5 | 2.1 | 0 | ## Details @@ -63,11 +63,11 @@ class Rank(unittest.TestCase): def test_scores_and_sorts_by_release_then_security_then_score_and_orders_the_details_to_match(self): ranked = self.ranked() - self.assertIn("""| 4 | 0.1.0 | security | **Rotate the leaked key.** | 9 | 2 | 1 | 1 | 2.1 | -6.8 | -| 3 | 0.1.0 | | **Make it fast, `a \\| b`.** | 3 | 8 | 6 | 8 | 2.1, 1 | 23.0 | -| 2 | 0.1.0 | | **Tighten the tests.** | 2 | 4 | 5 | 5 | 2.1 | 10.3 | -| 5 | 0.1.0 | decision | **Move the writes out.** | 5 | 5 | 4 | 5 | 2.1 | 5.1 | -| 1 | 0.2.0 | | **Ship the later thing.** | 1 | 1 | 9 | 9 | 1 | 34.8 | + self.assertIn("""| 4 | 0.1.0 | security | **Rotate the leaked key.** | 9 | 2 | 3 | 1 | 1 | 2.1 | -6.8 | +| 3 | 0.1.0 | | **Make it fast, `a \\| b`.** | 3 | 8 | 3 | 6 | 8 | 2.1, 1 | 23.0 | +| 2 | 0.1.0 | | **Tighten the tests.** | 2 | 4 | 3 | 5 | 5 | 2.1 | 10.3 | +| 5 | 0.1.0 | decision | **Move the writes out.** | 5 | 5 | 3 | 4 | 5 | 2.1 | 5.1 | +| 1 | 0.2.0 | | **Ship the later thing.** | 1 | 1 | 3 | 9 | 9 | 1 | 34.8 | """, ranked.text) self.assertTrue(ranked.text.endswith("## Details\n\n### 3. Make it fast, `a | b`.\n\nFast detail.\n\n### 1. Ship the later thing.\n\nLater detail.\n\n## Notes\n\nKept as written.\n")) self.assertEqual(ranked.under_bar, []) @@ -75,7 +75,7 @@ class Rank(unittest.TestCase): def test_holds_each_item_a_decision_cites_and_says_how_to_settle_a_finished_one(self): self.assertIsInstance(self.ranked(decisions=DECISIONS + "Until `todo.md` item 4 lands.\n"), rank_todo.Ranked) - gone = self.ranked(TODO.replace("| 5 | 0.1.0 | decision | **Move the writes out.** | 5 | 5 | 4 | 5 | 2.1 | 0 |\n", "")) + gone = self.ranked(TODO.replace("| 5 | 0.1.0 | decision | **Move the writes out.** | 5 | 5 | 3 | 4 | 5 | 2.1 | 0 |\n", "")) self.assertEqual(gone.reason, "docs/decisions.md cites \"`todo.md` item 5\", which todo.md no longer holds; revise that decision to say what holds now") def test_names_each_item_under_the_bar_that_is_not_exempt(self): @@ -94,16 +94,21 @@ class Rank(unittest.TestCase): self.assertIn("| 1 | 1.00 |\n| 2 | 0.75 |\n| 2.1 | 0.50 |\n| 3 | 0.25 |", failure.reason) def test_refuses_a_formula_that_is_more_than_arithmetic_over_the_scores(self): - for formula in ("__import__('os')", "R.real", "X + 1", "R ** 2", "R +", "R / (S - 2)", "R\x00", "1" * 400, " + ".join(["R"] * 300), "-" * 100000 + "R"): + for formula in ("__import__('os')", "R.real", "X + 1", "C + 1", "R ** 2", "R +", "R / (S - 2)", "R\x00", "1" * 400, " + ".join(["R"] * 300), "-" * 100000 + "R"): with self.subTest(formula=formula): self.assertIsInstance(self.ranked(TODO.replace("-R - S/4 + 2*A + 2*G*W", formula)), Failure) + def test_asks_for_a_c_column_in_a_table_without_one(self): + legacy = TODO.split("## Items")[0] + "## Items\n\n| ID | Release | Exempt | Item | R | S | A | G | Goals | Score |\n|---|---|---|---|---|---|---|---|---|---|\n| 2 | 0.1.0 | | **Tighten the tests.** | 2 | 4 | 5 | 5 | 2.1 | 0 |\n" + self.assertEqual(self.ranked(legacy, decisions="").reason, "todo.md's items table has no C column; add one after S, and score each item's C from 1 to 10 per rank_todo.py --help") + def test_refuses_a_file_off_the_format(self): - row = "| 2 | 0.1.0 | | **Tighten the tests.** | 2 | 4 | 5 | 5 | 2.1 | 0 |" + row = "| 2 | 0.1.0 | | **Tighten the tests.** | 2 | 4 | 3 | 5 | 5 | 2.1 | 0 |" broken = { row: row.replace("0.1.0", "0.1"), + "| 2 | 4 | 3 | 5 | 5 |": "| 2 | 4 | 11 | 5 | 5 |", row + "\n": row.replace("5 | 5", "5 | Β²") + "\n", - "| 2.1 | 0 |\n\n## Details": "| 2.1 | 0 |\n\n| 9 | 0.1.0 | | **Stray.** | 1 | 1 | 1 | 1 | 1 | 0 |\n\n## Details", + "| 2.1 | 0 |\n\n## Details": "| 2.1 | 0 |\n\n| 9 | 0.1.0 | | **Stray.** | 1 | 1 | 3 | 1 | 1 | 1 | 0 |\n\n## Details", "| 4 | 0.1.0 | security |": "| 4 | 0.1.0 | later |", "| 5 | 0.1.0 | decision |": "| 5 | 0.1.0 | |", "`Next ID = 6`": "`Next ID = 5`", diff --git a/bin/test_round_titles.py b/bin/test_round_titles.py new file mode 100644 index 00000000..1cb56861 --- /dev/null +++ b/bin/test_round_titles.py @@ -0,0 +1,39 @@ +import pathlib +import sys +import unittest + +sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) + +from round_titles import lacks_counts, round_counts, round_findings + + +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", "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)) + + def test_counts_a_mis_cased_title_under_its_pass(self): + self.assertEqual(round_counts(["Answer Architecture round 4: x", "Answer architecture round 3: y"])["architecture"], 4) + + def test_counts_a_repeated_round_number_as_a_round_of_its_own(self): + self.assertEqual(round_counts(["Answer stability round 3: x", "Answer stability round 3: y", "Answer stability round 2: z", "Answer stability round 1: w"])["stability"], 4) + + +class RoundFindings(unittest.TestCase): + def test_sums_the_counts_each_round_title_opens_with(self): + self.assertEqual(round_findings(["Answer stability round 1: 1 πŸ”΄, 2 🟑; flag a deleted test", "Answer prose round 1: 0 πŸ”΄, 3 🟑", "Merge origin/main"]), (1, 5)) + + def test_knows_no_count_when_a_round_title_or_every_round_lacks_one(self): + self.assertIsNone(round_findings(["Answer stability round 1: 1 πŸ”΄, 2 🟑; fix", "Answer prose round 1: fix the README"])) + self.assertIsNone(round_findings(["Answer stability round 1: 1 πŸ”΄, 2 🟑 fix"])) + self.assertIsNone(round_findings(["Do the work"])) + + + def test_finds_a_round_title_without_counts(self): + self.assertTrue(lacks_counts("Answer stability round 1: fix")) + self.assertFalse(lacks_counts("Answer stability round 1: 0 πŸ”΄, 1 🟑; fix")) + self.assertFalse(lacks_counts("Answer the question")) + + +if __name__ == "__main__": + unittest.main() diff --git a/bin/todo_table.py b/bin/todo_table.py index ba6e3b0c..25b5b872 100644 --- a/bin/todo_table.py +++ b/bin/todo_table.py @@ -4,7 +4,10 @@ import re from failure import Failure EXEMPTIONS = ("", "decision", "defect", "principle", "question", "security") -ITEMS_HEADER = "| ID | Release | Exempt | Item | R | S | A | G | Goals | Score |" +COLUMNS = ("ID", "Release", "Exempt", "Item", "R", "S", "C", "A", "G", "Goals", "Score") +ITEMS_HEADER = "| " + " | ".join(COLUMNS) + " |" +# Tables in git history from before C joined lack it; items() still parses them, though rank_todo refuses one in a checkout. +WITHOUT_C = "| " + " | ".join(column for column in COLUMNS if column != "C") + " |" @dataclasses.dataclass(frozen=True) @@ -24,18 +27,22 @@ class Table: rows: list[str] -def items(todo: str) -> list[Item] | Failure: - """Each row of a todo.md's items table.""" - table = table_rows(todo.splitlines(), ITEMS_HEADER) +def items(todo: str) -> list[Item] | None | Failure: + """Each row of a todo.md's items table, with C or without it; None where todo.md holds no items table.""" + lines = todo.splitlines() + headers = [header for header in (ITEMS_HEADER, WITHOUT_C) if header in lines] + if not headers: + return None + table = table_rows(lines, headers[0]) if isinstance(table, Failure): return table - items = [] + found = [] for row in table.rows: - item = parse_row(row) + item = parse_row(row, headers[0]) if isinstance(item, Failure): return item - items.append(item) - return items + found.append(item) + return found def table_rows(lines: list[str], header: str) -> Table | Failure: @@ -55,12 +62,14 @@ def cells(row: str, count: int) -> list[str] | Failure: return found if len(found) == count else Failure(f"this row needs {count} cells: {row}") -def parse_row(row: str) -> Item | Failure: - """An item row, every cell checked but the goals it cites.""" - found = cells(row, 10) +def parse_row(row: str, header: str = ITEMS_HEADER) -> Item | Failure: + """An item row under header, every cell checked but the goals it cites.""" + names = header.strip("| ").split(" | ") + found = cells(row, len(names)) if isinstance(found, Failure): return found - id_, release, exempt, tagline, r, s, a, g, goals, _ = found + named = dict(zip(names, found)) + id_, release, exempt, tagline = named["ID"], named["Release"], named["Exempt"], named["Item"] if not re.fullmatch(r"[0-9]+", id_) or int(id_) < 1: return Failure(f"the ID {id_!r} is not a positive whole number: {row}") if not re.fullmatch(r"[0-9]+\.[0-9]+\.[0-9]+", release): @@ -69,11 +78,13 @@ def parse_row(row: str) -> Item | Failure: return Failure(f"item {id_}'s Exempt {exempt!r} is not empty or one of {', '.join(EXEMPTIONS[1:])}") if not re.fullmatch(r"\*\*[^*].*[^*]\*\*", tagline): return Failure(f"item {id_}'s Item cell is not one bold tagline: {tagline}") - scores = {} - for name, value in zip("RSAG", (r, s, a, g)): - if not re.fullmatch(r"[0-9]+", value) or not 1 <= int(value) <= 10: - return Failure(f"item {id_}'s {name} {value!r} is not a whole number from 1 to 10") - scores[name] = int(value) - cited = tuple(goal.strip() for goal in goals.split(",")) + scores: dict[str, int] = {} + for name in ("R", "S", "C", "A", "G"): + if name not in named: + continue + if not re.fullmatch(r"[0-9]+", named[name]) or not 1 <= int(named[name]) <= 10: + return Failure(f"item {id_}'s {name} {named[name]!r} is not a whole number from 1 to 10") + scores[name] = int(named[name]) + cited = tuple(goal.strip() for goal in named["Goals"].split(",")) major, minor, patch = (int(part) for part in release.split(".")) return Item(int(id_), (major, minor, patch), exempt, tagline, scores, cited) diff --git a/docs/comprehension-history.md b/docs/comprehension-history.md index e33b562e..ea51b828 100644 --- a/docs/comprehension-history.md +++ b/docs/comprehension-history.md @@ -1436,3 +1436,77 @@ Inherited architect, decided by: - Locality: `bin/rule_hook/override_log.py:36` `this_chunks`: reflog, default branch and logged branch held at once - Shape: `bin/reading_cost/measure.py:43` `commit_time`: reading-cost and rule-hook share one parser, one concept with one implementation - Shape: `bin/rank_todo.py:114` `check_failures`: --check pulled out so rule-hook reuses it + +## 2026-10-13T09:29:12Z, PR #254 at 2284780, against 4cc9953 + +Ruling: worse + +Fell: Locality. Under the floor of 7.0: Locality 6.50, so the same ruling counts as worse. + +| Seat | Navigation | Locality | Shape | Self-sufficiency | Overall | +|---|---|---|---|---|---| +| Mid A | same | worse | same | same | same | +| Inherited architect | same | worse | same | same | same | + +| Seat | Navigation | Locality | Shape | Self-sufficiency | Overall | +|---|---|---|---|---|---| +| Junior A | 7 | 6.5 | 6.5 | 6.5 | 6.5 | +| Mid A | 7.5 | 7 | 7 | 6.5 | 7 | +| Maintainability senior | 7.5 | 6.5 | 6.5 | 7 | 7 | +| Inherited architect | 7 | 6 | 6 | 6.5 | 6.5 | +| Mean | 7.25 | 6.50 | 6.50 | 6.63 | 6.75 | + +Mid A, decided by: + +- Locality: `bin/todo_table.py:62` `parse_row`: a C-less row gets a blank cell spliced in by position, and whether a table without C is valid is decided in three files that disagree on purpose +- Locality: `bin/loop_claude/project/records.py:9` `HUMAN_RULE_DIRS`: the judge's rule-file text is now built from tuples across three modules and an unnamed repo check +- Locality: `bin/rule_hook/override_log.py:118` `default_branch`: reuses the name of `larv_review/git.py`'s `default_branch` with a different contract + +Inherited architect, decided by: + +- Locality: `bin/score_outcomes/outcomes.py:6` `round_findings`: the round-commit title is a contract held in SKILL.md prose, `ROUND` and `FINDINGS`; a slightly different title silently reads as findings unknown +- Locality: `bin/todo_table.py:62` `parse_row`: the rule for the pre-C table is spread over todo_table, rank_todo and larv_review/plan, which disagree on purpose +- Locality: `bin/rule_hook/override_log.py:36` `this_chunks`: which overrides belong to the chunk depends on reflog and ancestry state the code does not hold +- Locality, Shape: `bin/score_outcomes/main.py:41` imports: one tool reaches into another tool's package for its git helpers + +Junior A, hardest first: + +- `bin/score_outcomes/outcomes.py:42` `guesses`: a second todo-table parser beside `todo_table.items` +- `bin/larv_review/git.py:8` `git`: one of four look-alike git wrappers with different contracts + +Mid A, hardest first: + +- `bin/score_outcomes/outcomes.py:9` `FINDINGS`: round titles parsed in `rounds.py`, here and prose in SKILL.md +- `bin/score_outcomes/outcomes.py:21` `Outcome`: one of three unrelated `Outcome`s + +Maintainability senior, hardest first: + +- `bin/score_outcomes/outcomes.py:42` `guesses`: a third items-table parser with its own cell splitter +- `bin/score_outcomes/main.py:93` `measure`: decisions threaded between git calls + +Inherited architect, would restructure first: + +- `bin/score_outcomes/outcomes.py:9` `FINDINGS`: the round-title grammar lives in SKILL.md, `ROUND` and here +- `bin/larv_review/git.py:21` `default_branch`: one of two `default_branch`s and five git runners + +## 2026-10-13T10:03:42Z, PR #254 at 5b6c497, against 4cc9953 + +Ruling: same + +| Seat | Navigation | Locality | Shape | Self-sufficiency | Overall | +|---|---|---|---|---|---| +| Mid A | same | same | worse | same | same | +| Inherited architect | same | worse | same | same | same | + +Mid A, decided by: + +- Shape: `bin/git_repo.py:8` `git`: four modules carry "git" in their path, and two define a `git` with different signatures +- Shape: `bin/todo_table.py:30` `items`: one name now covers three outcomes and two header shapes, each caller reading None differently + +Inherited architect, decided by: + +- Locality: `bin/todo_table.py:30` `items`: accepts a table without C that `rank_todo.py` `read_scoring` rejects, and `render_item` relies on that rejection having run first +- Locality: `bin/larv_review/plan.py:46` `plan_reasons`: `items(before) or []` turns None into an empty list and relies on a Failure being truthy +- Locality: `bin/loop_claude/project/records.py:10` `HUMAN_RULE_DIRS`: the judge reads every file in two folders, shrinking the transcript it sees +- Locality: `bin/loop_claude/cycle/judge.py:41` `JUDGE_RULES`: the judge's rule text is built across three files +- Locality: `bin/rule_hook/override_log.py:36` `this_chunks`: which overrides list depends on reflog, branch name and default-branch state diff --git a/docs/reading-cost.md b/docs/reading-cost.md index c3d6797d..70ac4f38 100644 --- a/docs/reading-cost.md +++ b/docs/reading-cost.md @@ -178,3 +178,20 @@ Read most (opens and searches): - `bin/loop_claude/loop/main.py` 1 - `bin/loop_claude/test_loop_claude.py` 1 - `docs/decisions.md` 1 + +## Reading cost, chunk 50e484d03614, finished 2026-10-13T09:11:18Z + +61233 new input tokens before the first commit. + +Read most (opens and searches): + +- `agents/stability-reviewer.md` 2 +- `docs/decisions.md` 2 +- `principles/technical-principles.md` 2 +- `skills/larv-review/SKILL.md` 2 +- `todo.md` 2 +- `.gitignore` 1 +- `CHANGELOG.md` 1 +- `README.md` 1 +- `rules/decisions.md` 1 +- `rules/todo-items.md` 1 diff --git a/rules/todo-items.md b/rules/todo-items.md index 3ac3a140..7d890e4e 100644 --- a/rules/todo-items.md +++ b/rules/todo-items.md @@ -7,11 +7,13 @@ paths: - **`todo.md` is mandatory in every project, in one shape**, which `~/.claude/bin/rank_todo.py` checks and ranks; its `--help` shows a valid file. `## Scoring` holds the formula, the bar and the goal weights; `## Items` is one table of every item; `## Details` holds each item's detail under its ID. Cite an item by its ID. The formula, bar and weights are the project's own to tune. - **An item's release allows the bump that semver read strictly asks for.** An item that changes what exists needs a major, or before 1.0.0 a minor. One that only adds needs a minor, and a fix a patch. -- **Score an item when it is filed or edited.** Each of R, S, A and G is a whole number from 1 to 10: +- **Score an item when it is filed or edited.** Each of R, S, C, A and G is a whole number from 1 to 10: - **R** β€” the risk that the change creates serious bugs or issues. - **S** β€” the size of the change. + - **C** β€” how hard the change is to get right: novel design, subtle invariants, many interacting parts. A huge rename is low C; a ten-line lock fix can be high. C stays out of the score. - **A** β€” its value to the audience in `README.md` β†’ `## Audience`. - **G** β€” its value to the goals it cites in the Goals column; W is the weight of the heaviest of them. +- **Check R, S and C against finished chunks.** Guess them, then run `~/.claude/bin/score-outcomes ` in the project. It lists the finished items guessed nearest, what their chunks measured, and the median outcome at each guessed value. Set each score to the value guessed for the finished items whose outcome matches what you expect of this one. Keep your guess when no listed item resembles the one you are scoring. - **An item scoring under the bar is deleted, with every item that needs it, and a finding under the bar is not filed.** The chunk's summary names each, with its score. - **The Exempt cell keeps an item whatever its score:** `security` for a security finding, `defect` for a πŸ”΄ finding, `question` for a question only the human can answer, `decision` for an item `docs/decisions.md` cites, and, where no other reason fits, `principle` for a 🟑 finding against a file under `~/.claude/principles/`, whose item's detail names that principle. Every item `docs/decisions.md` cites carries one of these reasons. - **Unless the project has a reason to differ, weigh goals by position, the first heaviest.** When the weights stop listing the README's goals, `rank_todo.py` fails and prints those weights. diff --git a/skills/larv-review/SKILL.md b/skills/larv-review/SKILL.md index f0c5d219..fbbc1e12 100644 --- a/skills/larv-review/SKILL.md +++ b/skills/larv-review/SKILL.md @@ -66,7 +66,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 "Opt-out" or "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. `~/.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. +- **Count.** Close each round with one commit that holds the round's fixes. Title it `Answer round : πŸ”΄, 🟑; …`: `` is the pass's name in lower case, such as `full scan`, and `` and `` are the πŸ”΄ and 🟑 findings all the round's reviewers reported. Example: `Answer stability round 1: 1 πŸ”΄, 2 🟑; flag a deleted test`. 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. diff --git a/todo.md b/todo.md index 859239aa..466ab462 100644 --- a/todo.md +++ b/todo.md @@ -6,7 +6,7 @@ `Bar = 9` -`Next ID = 110` +`Next ID = 118` | Goal | W | |---|---| @@ -22,64 +22,62 @@ ## Items -| ID | Release | Exempt | Item | R | S | A | G | Goals | Score | -|---|---|---|---|---|---|---|---|---|---| -| 98 | 0.1.0 | | **Score R and S from a measurement wherever one exists, and calibrate each guessed score against the finished chunk's measured outcome.** | 2 | 5 | 6 | 7 | 1.1, 1.4 | 22.6 | -| 99 | 0.1.0 | | **Drop the comprehension panel as a merge gate, and keep recording its scores and the places in the code its seats found hard, for later measurement and for other reviewers and agents to improve.** | 4 | 5 | 7 | 7 | 1.1, 1.4, 1.5 | 22.6 | -| 87 | 0.1.0 | | **Score every `todo.md` item's complexity C from 1 to 10, and have `rank_todo.py` fail on an item without one.** | 3 | 4 | 6 | 7 | 1.1, 1.4 | 21.9 | -| 97 | 0.1.0 | | **Narrow each review pass to the findings worth a fix, so a pass converges in its second round.** | 5 | 4 | 7 | 7 | 1.1, 1.4, 1.5 | 21.9 | -| 109 | 0.1.0 | | **Lower the reading cost of the files a chunk reads most before its first commit.** | 2 | 4 | 5 | 6 | 1.4 | 18.5 | -| 93 | 0.2.0 | | **Let a chunk's worker start below the project's model, once the archive shows chunks on a lower rung took no more review rounds than chunks on the project's model.** | 3 | 2 | 6 | 7 | 1.1, 1.4 | 22.4 | -| 94 | 0.2.0 | | **Every 20th cycle, have loop-claude measure token spend and routing outcomes, file them here, and interrupt the human only when they call for a routing change.** | 3 | 5 | 6 | 7 | 1.1, 1.4 | 21.6 | -| 88 | 0.2.0 | | **Define one routing ladder of (model, effort) rungs ordered by a published ranking of their competence, and map a task's R + C to a rung relative to the project's model.** | 3 | 4 | 6 | 7 | 1.4 | 21.4 | -| 90 | 0.2.0 | | **Route each reviewer by the chunk's R + C, once a replay of past chunks shows the routed reviewer finds the πŸ”΄ and 🟑 findings on record.** | 4 | 5 | 6 | 7 | 1.4 | 20.2 | -| 91 | 0.2.0 | | **Start each chunk's worker on the rung its item's R + C picks, never below the project's model, and step it one rung up after two unfinished verdicts on one chunk.** | 4 | 5 | 6 | 7 | 1.4 | 20.2 | -| 105 | 0.2.0 | decision | **Compare review rounds per pass and reading cost for the five chunks before and after the `worker:` decision moved the principles out of the worker's context, and file an item if either rose.** | 1 | 2 | 5 | 6 | 1.4 | 20.0 | -| 92 | 0.2.0 | | **Have the worker route each subagent by its task's R + C, and delegate a task only when the worker needs just its conclusion.** | 2 | 2 | 5 | 6 | 1.4 | 19.0 | -| 89 | 0.2.0 | | **Run the judge on the rung its chunk's R + C picks, once a replay of archived transcripts shows it returns the verdicts on record.** | 3 | 4 | 5 | 6 | 1.4 | 17.5 | -| 1 | 0.3.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.3.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.3.0 | | **Give `settings.json`'s model one writer, and sort its keys.** | 3 | 3 | 6 | 7 | 1.3 | 21.8 | -| 49 | 0.3.0 | principle | **Check that `AGENTS.md` lists exactly the titles of `docs/decisions.md`.** | 1 | 2 | 5 | 6 | 1.3 | 20.1 | -| 59 | 0.3.0 | | **Bound a run of unfinished verdicts on one chunk, so a worker and judge that disagree cannot cycle unattended without end.** | 3 | 3 | 6 | 6 | 1.4 | 19.8 | -| 12 | 0.3.0 | | **Run the test suite in CI on every PR, or record in `docs/decisions.md` why the local run is enough.** | 2 | 4 | 4 | 6 | 1.1 | 16.9 | -| 80 | 0.3.0 | | **State in README β†’ Install that every machine taking this checkout must be a sandbox, as `settings.json`'s auto mode assumes.** | 1 | 1 | 5 | 5 | 4 | 16.8 | -| 5 | 0.3.0 | decision | **Key a project on its checkout's full path, and refuse to start while another session uses that key.** | 5 | 5 | 5 | 6 | 1.1 | 15.6 | -| 84 | 0.3.0 | | **Check, at each release's scoring run, that seats in a paired ruling agree more often than two scoring runs on near-identical code do, as the paired-ruling decision assumes.** | 2 | 2 | 4 | 5 | 1.4 | 15.1 | -| 67 | 0.3.0 | principle | **Point stability-reviewer at the technical principles in place of its own restatement of them.** | 2 | 3 | 4 | 5 | 1.3 | 14.9 | -| 106 | 0.3.0 | | **Make larv-review's "Do not over-read a clean result" cite a rule that says Renovate or Dependabot owns dependency CVEs, or drop the citation.** | 1 | 1 | 3 | 5 | 1.1 | 14.7 | -| 66 | 0.3.0 | principle | **Hold systems-architect's method thresholds only while the comprehension panel finds the flagged code hard.** | 3 | 3 | 4 | 5 | 1.1 | 14.2 | -| 101 | 0.3.0 | principle | **Have `larv_review/record.py`'s `read_seats` take the time, the commit check and the history as inputs, so it parses and decides without effects.** | 3 | 3 | 4 | 5 | 1.1 | 14.2 | -| 29 | 0.3.0 | | **Make the contributor a standing member of every project's audience, unless its `## Audience` says maintainability does not matter.** | 2 | 2 | 3 | 5 | 1.1, 1.4 | 13.4 | -| 68 | 0.3.0 | principle | **Test `workflow-bench/compare.py`'s blinding and `bench.py`'s run plan.** | 2 | 4 | 3 | 5 | 1.1 | 12.9 | -| 65 | 0.3.0 | | **Archive each judge reply the loop rejects.** | 3 | 4 | 4 | 5 | 3 | 12.5 | -| 82 | 0.3.0 | principle | **Sort `AGENTS.md`'s decision titles and `docs/decisions.md`'s entries by title.** | 1 | 2 | 3 | 4 | 1.3 | 12.3 | -| 73 | 0.3.0 | | **Have each reviewer write its full report to a file and return the worker only its findings' one-line summaries.** | 3 | 4 | 4 | 4 | 1.4 | 11.7 | -| 6 | 0.3.0 | decision | **Move what `loop-claude` writes out of `~/.claude.json`, and ask the human about each write that must stay.** | 5 | 5 | 4 | 5 | 1.1 | 11.7 | -| 51 | 0.3.0 | principle | **Hand loop-claude's terminal output to an injected effect, so no storage or retry function prints.** | 3 | 5 | 3 | 5 | 1.1 | 11.7 | -| 102 | 0.3.0 | | **Give loop-claude's retry delay an environment override, so the black-box test stops replacing `time.sleep` through `sitecustomize`.** | 2 | 2 | 3 | 4 | 1.1 | 11.4 | -| 50 | 0.3.0 | principle | **Grant the bench's runs only the tools a review needs, in place of skipping every permission.** | 2 | 2 | 3 | 4 | 4 | 9.9 | -| 81 | 0.3.0 | principle | **Have `workflow-bench/bench.py` return each run's failure as a value, so one failed clone does not hide the later runs' results.** | 2 | 2 | 3 | 4 | 4 | 9.9 | -| 4 | 0.3.0 | | **Name each chunk's archive folder by the chunk's start time, so `/` lists chunks in the order they ran.** | 3 | 2 | 4 | 3 | 3 | 9.6 | -| 52 | 0.3.0 | principle | **Record why this checkout lives in Claude Code's own directory, or move it out and link it in.** | 6 | 6 | 3 | 5 | 2 | 7.5 | -| 77 | 0.4.0 | | **Teach `bin/metric-bench` Go and TypeScript, rerun it once two projects' comprehension histories name places, and bring into review only a metric that tracks the panel.** | 3 | 6 | 6 | 7 | 1.1, 1.4 | 21.4 | +| ID | Release | Exempt | Item | R | S | C | A | G | Goals | Score | +|---|---|---|---|---|---|---|---|---|---|---| +| 99 | 0.1.0 | | **Drop the comprehension panel as a merge gate, and keep recording its scores and the places in the code its seats found hard, for later measurement and for other reviewers and agents to improve.** | 4 | 5 | 4 | 7 | 7 | 1.1, 1.4, 1.5 | 22.6 | +| 97 | 0.1.0 | | **Narrow each review pass to the findings worth a fix, so a pass converges in its second round.** | 5 | 4 | 6 | 7 | 7 | 1.1, 1.4, 1.5 | 21.9 | +| 109 | 0.1.0 | | **Lower the reading cost of the files a chunk reads most before its first commit.** | 2 | 4 | 4 | 5 | 6 | 1.4 | 18.5 | +| 93 | 0.2.0 | | **Let a chunk's worker start below the project's model, once the archive shows chunks on a lower rung took no more review rounds than chunks on the project's model.** | 3 | 2 | 6 | 6 | 7 | 1.1, 1.4 | 22.4 | +| 94 | 0.2.0 | | **Every 20th cycle, have loop-claude measure token spend and routing outcomes, file them here, and interrupt the human only when they call for a routing change.** | 3 | 5 | 6 | 6 | 7 | 1.1, 1.4 | 21.6 | +| 88 | 0.2.0 | | **Define one routing ladder of (model, effort) rungs ordered by a published ranking of their competence, and map a task's R + C to a rung relative to the project's model.** | 3 | 4 | 5 | 6 | 7 | 1.4 | 21.4 | +| 90 | 0.2.0 | | **Route each reviewer by the chunk's R + C, once a replay of past chunks shows the routed reviewer finds the πŸ”΄ and 🟑 findings on record.** | 4 | 5 | 8 | 6 | 7 | 1.4 | 20.2 | +| 91 | 0.2.0 | | **Start each chunk's worker on the rung its item's R + C picks, never below the project's model, and step it one rung up after two unfinished verdicts on one chunk.** | 4 | 5 | 6 | 6 | 7 | 1.4 | 20.2 | +| 105 | 0.2.0 | decision | **Compare review rounds per pass and reading cost for the five chunks before and after the `worker:` decision moved the principles out of the worker's context, and file an item if either rose.** | 1 | 2 | 3 | 5 | 6 | 1.4 | 20.0 | +| 112 | 0.2.0 | | **Count an item as shipped only where its chunk built it, so an item a chunk dropped from the plan gets no outcome.** | 2 | 3 | 5 | 5 | 6 | 1.1 | 19.1 | +| 92 | 0.2.0 | | **Have the worker route each subagent by its task's R + C, and delegate a task only when the worker needs just its conclusion.** | 2 | 2 | 5 | 5 | 6 | 1.4 | 19.0 | +| 110 | 0.2.0 | | **Count, for each finished chunk, the later changes that fixed code it wrote, and show them beside its guessed R.** | 2 | 4 | 6 | 5 | 6 | 1.1, 1.4 | 18.9 | +| 89 | 0.2.0 | | **Run the judge on the rung its chunk's R + C picks, once a replay of archived transcripts shows it returns the verdicts on record.** | 3 | 4 | 7 | 5 | 6 | 1.4 | 17.5 | +| 115 | 0.2.0 | question | **Confirm or set how many finished chunks that each shipped one item `score-outcomes` waits for before it shows a score's medians, today 10.** | 1 | 1 | 2 | 4 | 5 | 1.2 | 16.6 | +| 116 | 0.2.0 | | **Report R by the share of chunks with a πŸ”΄, once 10 chunks that each shipped one item record finding counts and most record no πŸ”΄.** | 1 | 2 | 2 | 4 | 5 | 1.1 | 16.4 | +| 111 | 0.2.0 | | **Measure the chunks of a project that merges by squash or fast-forward, which `score-outcomes` skips today.** | 3 | 3 | 5 | 4 | 5 | 1.3 | 13.9 | +| 113 | 0.2.0 | | **Compute an item's S from the code it names, where it names any, and show it beside the finished items `score-outcomes` lists.** | 3 | 4 | 6 | 4 | 5 | 1.1, 1.4 | 13.9 | +| 1 | 0.3.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 | 2 | 8 | 9 | 3, 4 | 27.0 | +| 62 | 0.3.0 | defect | **Lift Locality, Self-sufficiency and the overall to the comprehension floor, at the places the seats name.** | 4 | 6 | 6 | 6 | 8 | 1.1 | 22.3 | +| 21 | 0.3.0 | | **Give `settings.json`'s model one writer, and sort its keys.** | 3 | 3 | 4 | 6 | 7 | 1.3 | 21.8 | +| 49 | 0.3.0 | principle | **Check that `AGENTS.md` lists exactly the titles of `docs/decisions.md`.** | 1 | 2 | 2 | 5 | 6 | 1.3 | 20.1 | +| 59 | 0.3.0 | | **Bound a run of unfinished verdicts on one chunk, so a worker and judge that disagree cannot cycle unattended without end.** | 3 | 3 | 5 | 6 | 6 | 1.4 | 19.8 | +| 12 | 0.3.0 | | **Run the test suite in CI on every PR, or record in `docs/decisions.md` why the local run is enough.** | 2 | 4 | 3 | 4 | 6 | 1.1 | 16.9 | +| 80 | 0.3.0 | | **State in README β†’ Install that every machine taking this checkout must be a sandbox, as `settings.json`'s auto mode assumes.** | 1 | 1 | 1 | 5 | 5 | 4 | 16.8 | +| 5 | 0.3.0 | decision | **Key a project on its checkout's full path, and refuse to start while another session uses that key.** | 5 | 5 | 7 | 5 | 6 | 1.1 | 15.6 | +| 84 | 0.3.0 | | **Check, at each release's scoring run, that seats in a paired ruling agree more often than two scoring runs on near-identical code do, as the paired-ruling decision assumes.** | 2 | 2 | 5 | 4 | 5 | 1.4 | 15.1 | +| 67 | 0.3.0 | principle | **Point stability-reviewer at the technical principles in place of its own restatement of them.** | 2 | 3 | 2 | 4 | 5 | 1.3 | 14.9 | +| 106 | 0.3.0 | | **Make larv-review's "Do not over-read a clean result" cite a rule that says Renovate or Dependabot owns dependency CVEs, or drop the citation.** | 1 | 1 | 1 | 3 | 5 | 1.1 | 14.7 | +| 66 | 0.3.0 | principle | **Hold systems-architect's method thresholds only while the comprehension panel finds the flagged code hard.** | 3 | 3 | 4 | 4 | 5 | 1.1 | 14.2 | +| 101 | 0.3.0 | principle | **Have `larv_review/record.py`'s `read_seats` take the time, the commit check and the history as inputs, so it parses and decides without effects.** | 3 | 3 | 3 | 4 | 5 | 1.1 | 14.2 | +| 29 | 0.3.0 | | **Make the contributor a standing member of every project's audience, unless its `## Audience` says maintainability does not matter.** | 2 | 2 | 3 | 3 | 5 | 1.1, 1.4 | 13.4 | +| 68 | 0.3.0 | principle | **Test `workflow-bench/compare.py`'s blinding and `bench.py`'s run plan.** | 2 | 4 | 4 | 3 | 5 | 1.1 | 12.9 | +| 65 | 0.3.0 | | **Archive each judge reply the loop rejects.** | 3 | 4 | 3 | 4 | 5 | 3 | 12.5 | +| 82 | 0.3.0 | principle | **Sort `AGENTS.md`'s decision titles and `docs/decisions.md`'s entries by title.** | 1 | 2 | 2 | 3 | 4 | 1.3 | 12.3 | +| 114 | 0.3.0 | | **Run git through `git_repo.py` in `rule_hook`, `metric_bench`, `reading_cost` and `loop_claude`, keeping rule-hook's guards as an option, so one module owns how a tool runs git.** | 3 | 4 | 4 | 3 | 5 | 1.1 | 11.9 | +| 73 | 0.3.0 | | **Have each reviewer write its full report to a file and return the worker only its findings' one-line summaries.** | 3 | 4 | 4 | 4 | 4 | 1.4 | 11.7 | +| 6 | 0.3.0 | decision | **Move what `loop-claude` writes out of `~/.claude.json`, and ask the human about each write that must stay.** | 5 | 5 | 6 | 4 | 5 | 1.1 | 11.7 | +| 51 | 0.3.0 | principle | **Hand loop-claude's terminal output to an injected effect, so no storage or retry function prints.** | 3 | 5 | 5 | 3 | 5 | 1.1 | 11.7 | +| 102 | 0.3.0 | | **Give loop-claude's retry delay an environment override, so the black-box test stops replacing `time.sleep` through `sitecustomize`.** | 2 | 2 | 2 | 3 | 4 | 1.1 | 11.4 | +| 117 | 0.3.0 | | **Give `todo_table.items` one way to say a plan has no items table, so no caller tells it from an empty plan by truthiness.** | 2 | 2 | 3 | 3 | 4 | 1.1 | 11.4 | +| 50 | 0.3.0 | principle | **Grant the bench's runs only the tools a review needs, in place of skipping every permission.** | 2 | 2 | 3 | 3 | 4 | 4 | 9.9 | +| 81 | 0.3.0 | principle | **Have `workflow-bench/bench.py` return each run's failure as a value, so one failed clone does not hide the later runs' results.** | 2 | 2 | 3 | 3 | 4 | 4 | 9.9 | +| 4 | 0.3.0 | | **Name each chunk's archive folder by the chunk's start time, so `/` lists chunks in the order they ran.** | 3 | 2 | 3 | 4 | 3 | 3 | 9.6 | +| 52 | 0.3.0 | principle | **Record why this checkout lives in Claude Code's own directory, or move it out and link it in.** | 6 | 6 | 4 | 3 | 5 | 2 | 7.5 | +| 77 | 0.4.0 | | **Teach `bin/metric-bench` Go and TypeScript, rerun it once two projects' comprehension histories name places, and bring into review only a metric that tracks the panel.** | 3 | 6 | 6 | 6 | 7 | 1.1, 1.4 | 21.4 | ## Details -### 98. Score R and S from a measurement wherever one exists, and calibrate each guessed score against the finished chunk's measured outcome. - -A score that can be computed from the code it touches, such as the files an item names, comes from that computation. Otherwise size and risk are estimated from finished work, the way reference-class forecasting estimates a project from earlier projects like it. When a chunk merges, record its measured outcome beside the item's guessed R and S: lines and files changed, review rounds, πŸ”΄ and 🟑 findings, and fixes the code needed later. Show the scorer, when it files an item, the finished items whose guessed scores sat nearest and what they measured. Once enough chunks are recorded, report how far each guess was from its outcome, so a scorer whose S runs high can be corrected. Item 87's C is scored and calibrated the same way. - ### 99. Drop the comprehension panel as a merge gate, and keep recording its scores and the places in the code its seats found hard, for later measurement and for other reviewers and agents to improve. No published study validates simulated reader panels as a measure of how easy code is to understand, and item 84's test of whether the panel's signal beats its noise has not run. Keep running the panel where it runs, and keep `docs/comprehension-history.md`: each run's scores, and each place a seat named with what it found hard there. No paired ruling, floor or ratchet blocks a merge. The architecture pass and the stability reviewer read the latest places named, and each chunk that touches one of them improves it or says in its PR summary why not. A worker filing items reads them too. This revises the `comprehension floor:` decision and the `review:` decisions on the paired ruling, the scoring run, suspending and opting out of the comprehension check, and it turns item 62 from a defect into an ordinary item scored by its value. A project's own gate rule, such as the one in fejkdata's `AGENTS.md`, is that project's to change. -### 87. Score every `todo.md` item's complexity C from 1 to 10, and have `rank_todo.py` fail on an item without one. - -C is how hard the change is to get right: novel design, subtle invariants, many interacting parts. It differs from R, the chance the change creates serious bugs, and from S, its size: a huge rename is low C, a ten-line lock fix can be high C. C routes work (items 88–92) and stays out of the Score formula. Add the column to `rank_todo.py`'s valid shape and its `--help`, backfill every item in this repo, and state in `~/.claude/rules/todo-items.md` that C is scored when an item is filed, like R, S, A and G, so no chunk starts on an unscored item. - ### 97. Narrow each review pass to the findings worth a fix, so a pass converges in its second round. Anthropic's best-practices page: "A reviewer prompted to find gaps will usually report some, even when the work is sound… Chasing every finding leads to over-engineering." 320 of this repo's 876 commits answer a review round. @@ -90,7 +88,7 @@ From its second round on, a pass reviews only how the chunk answered the round b ### 109. Lower the reading cost of the files a chunk reads most before its first commit. -`bin/reading-cost` found a rise: the last 5 chunks' median is 106562 new input tokens before their first commit, the 5 before them 56802. Files read most in those 5 chunks (opens and searches): `CLAUDE.md` 17, `todo.md` 16, `docs/decisions.md` 12, `README.md` 10, `bin/loop_claude/loop/main.py` 9, `CHANGELOG.md` 8, `skills/larv-review/SKILL.md` 8, `.gitignore` 5, `bin/loop_claude/test_loop_claude.py` 5, `AGENTS.md` 4. The chunk that ships this item runs `reading-cost --reset`. +`bin/reading-cost` found a rise: the last 5 chunks' median is 106562 new input tokens before their first commit, the 5 before them 50762. Files read most in those 5 chunks (opens and searches): `CLAUDE.md` 17, `todo.md` 17, `docs/decisions.md` 11, `README.md` 10, `bin/loop_claude/loop/main.py` 9, `skills/larv-review/SKILL.md` 9, `CHANGELOG.md` 8, `.gitignore` 5, `agents/stability-reviewer.md` 5, `bin/loop_claude/test_loop_claude.py` 5. The chunk that ships this item runs `reading-cost --reset`. ### 93. Let a chunk's worker start below the project's model, once the archive shows chunks on a lower rung took no more review rounds than chunks on the project's model. @@ -108,8 +106,6 @@ Needs 88, 91, 92. One ladder, the same in every project (goal 1.3), read by loop-claude, larv-review and the worker. A rung is a model and an effort; the rungs run from Haiku at low effort to the strongest model at max effort. Order the rungs by a published source, cited in the decision recording the ladder; where no source orders two rungs, such as Sonnet at xhigh against Opus at medium, ask the human. R + C moves a task up or down from the rung holding the project's model at its default effort: a low sum steps down, a high sum steps up, the thresholds set in the decision. S never moves a rung: a huge task with low R and C runs cheap. Leave out the comprehension panel and the security pass, which stay on the project model. Record each route in loop-claude's archive, so the outcomes can tune the thresholds. -Needs 87. - ### 90. Route each reviewer by the chunk's R + C, once a replay of past chunks shows the routed reviewer finds the πŸ”΄ and 🟑 findings on record. larv-review passes the rung through the Agent tool's `model` and `effort`. A reviewer never steps down when the worker has stepped down on the same chunk, so a cheap worker always meets a reviewer on the project model or above. @@ -126,18 +122,42 @@ Needs 88. The `worker:` decision is valid while review rounds per pass do not rise. Count the rounds from each PR's `Answer round :` commits, and take reading cost from `docs/reading-cost.md`. Run it once five chunks have merged after the one that recorded the decision. +### 112. Count an item as shipped only where its chunk built it, so an item a chunk dropped from the plan gets no outcome. + +`score-outcomes` counts every item a merge removed from `todo.md` as shipped. A merge that changed only the plan ships nothing, but one that built an item and also dropped another gives the dropped item the built one's outcome, as PR #253 did with item 69. Mark a dropped item in the change that drops it, such as by the commit or merge title, and leave it out. + ### 92. Have the worker route each subagent by its task's R + C, and delegate a task only when the worker needs just its conclusion. State in `CLAUDE.md` when the worker delegates: a search or read that spans many files whose conclusion is all it needs, and work independent enough to run in parallel. Edits and anything the worker must verify line by line stay in the main thread, since a delegated diff is read again to check it. The worker scores R and C for each delegated task as it would for an item, and passes the rung's model and effort. In item 73's measurement, reports cost a median 8% of the worker's peak context, and `sed -n` and `grep` output made up 41% of its Bash results, so delegating searches saves the most context. The Agent tool sets a subagent's effort only when instructions ask, so the rule names both model and effort. Needs 88. +### 110. Count, for each finished chunk, the later changes that fixed code it wrote, and show them beside its guessed R. + +`score-outcomes` measures R only by the πŸ”΄ findings review caught. A serious bug review missed shows later, as a change that fixes code the chunk wrote. + ### 89. Run the judge on the rung its chunk's R + C picks, once a replay of archived transcripts shows it returns the verdicts on record. loop-claude starts the judge itself (`bin/loop_claude/cycle/judge.py`), so it routes without any skill change. Replay the judge on archived cycles at the candidate rung, and switch only when its interrupts and verdicts match those on record. Needs 88. +### 115. Confirm or set how many finished chunks that each shipped one item `score-outcomes` waits for before it shows a score's medians, today 10. + +`ENOUGH` in `bin/score_outcomes/outcomes.py` matches the 10 figures the reading-cost trend waits for. No published standard sets either, and `CLAUDE.md` β†’ "Web research" asks the human for a threshold a consumer relies on. + +### 116. Report R by the share of chunks with a πŸ”΄, once 10 chunks that each shipped one item record finding counts and most record no πŸ”΄. + +`score-outcomes` reports R as the median πŸ”΄ count at each guessed R. Where most chunks have no πŸ”΄, every median reads 0 and tells a scorer nothing. No round title held counts before PR #254, so how often a chunk has a πŸ”΄ is not yet known. + +### 111. Measure the chunks of a project that merges by squash or fast-forward, which `score-outcomes` skips today. + +`score-outcomes` reads a chunk from a merge commit: its branch's round titles, and its change against the first parent. Two of the projects under `~/code` merge without merge commits, so their scorers see no finished item. + +### 113. Compute an item's S from the code it names, where it names any, and show it beside the finished items `score-outcomes` lists. + +`score-outcomes` grounds R, S and C in finished chunks only. Where an item names files or units, their size bounds what the change can touch. + ### 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. @@ -150,7 +170,7 @@ The README line covers the bench's transcripts in `workflow-bench/logs/` too (go Raised by the principles audit of PR #215 against KISS, in `principles/technical-principles.md`, and goal 1.1. The `comprehension floor:` entry in `docs/decisions.md` lists each decision to ship under it. -PR #234's last scoring run, at b2a277b, put Locality and Self-sufficiency at 6.50 and the overall at 6.75. Every seat named larv-review's rules, which cannot be followed without `skills/larv-review/SKILL.md` Β§3 open beside the code: "Round cap", "Re-entry", "Fresh" and "Suspended" point at each other; `bin/larv_review/record.py` `record_ruling` branches on split, worse, fell and a scores file, with its terms defined only in `larv-review --help` and the skill; the pass list lives in both `bin/larv_review/rounds.py` `PASSES` and the skill's table, which also counts the auto-reviewer; `bin/comprehension_history.py` is reader, writer and seat registry in one, and parses the history by regex for two tools. Also named: the judge's prompt assembled from `cycle/judge.py`, `cycle/prompts.py` and `project/records.py`; git run four ways, in `bin/larv_review/git.py`, `bin/metric_bench/main.py`, `bin/reading_cost/main.py` and `bin/loop_claude/effects.py`; `SeatsFile.read`, a field named like a method. +PR #234's last scoring run, at b2a277b, put Locality and Self-sufficiency at 6.50 and the overall at 6.75. Every seat named larv-review's rules, which cannot be followed without `skills/larv-review/SKILL.md` Β§3 open beside the code: "Round cap", "Re-entry", "Fresh" and "Suspended" point at each other; `bin/larv_review/record.py` `record_ruling` branches on split, worse, fell and a scores file, with its terms defined only in `larv-review --help` and the skill; the pass list lives in both `bin/round_titles.py` `PASSES` and the skill's table, which also counts the auto-reviewer; `bin/comprehension_history.py` is reader, writer and seat registry in one, and parses the history by regex for two tools. Also named: the judge's prompt assembled from `cycle/judge.py`, `cycle/prompts.py` and `project/records.py`; git run four ways, in `bin/larv_review/git.py`, `bin/metric_bench/main.py`, `bin/reading_cost/main.py` and `bin/loop_claude/effects.py`; `SeatsFile.read`, a field named like a method. ### 21. Give `settings.json`'s model one writer, and sort its keys. @@ -218,6 +238,10 @@ Goal 3, raised by the principles audit of PR #215: the judge runs with `--no-ses "Deterministic order", in `principles/technical-principles.md`, raised by the principles audit of PR #224: their order carries no meaning, so two chunks adding a decision conflict at the end, and a reader cannot find a title by scanning. +### 114. Run git through `git_repo.py` in `rule_hook`, `metric_bench`, `reading_cost` and `loop_claude`, keeping rule-hook's guards as an option, so one module owns how a tool runs git. + +The comprehension seats on PR #254 found five git runners with different contracts: `git_repo.git`, `rule_hook/git.py`'s guarded one, `metric_bench/main.py`'s, `reading_cost/main.py`'s `located` and `loop_claude/effects.py`'s. + ### 73. Have each reviewer write its full report to a file and return the worker only its findings' one-line summaries. 2026-10-08, lilleman: rescored from A10/G8 to A4/G4 on the measurement below, so other items that lower token use go first. @@ -243,6 +267,10 @@ Claude Code owns that file and writes it. `trust` reads it, changes it and write Found by the principles audit of PR #242. `bin/loop_claude/test_black_box.py:113-114` swaps the global `time.sleep`, the shape "Functional core, imperative shell" bans. An override of the delay lets the test run the code as production runs it. +### 117. Give `todo_table.items` one way to say a plan has no items table, so no caller tells it from an empty plan by truthiness. + +The comprehension seats on PR #254 found `items` returning a list, None or a Failure, and `larv_review/plan.py` `plan_reasons` reading None through `items(before) or []`, which works only because a Failure is truthy. + ### 50. Grant the bench's runs only the tools a review needs, in place of skipping every permission. "Always grant explicit access to data", in `principles/technical-principles.md`: `workflow-bench/bench.py` starts claude with `--dangerously-skip-permissions`, and no rule confines it to a sandbox, so a run on the host reaches the host's credentials and other checkouts.