From 3d51ebc5df419fcb6f1d5bd41fd479abc022ab91 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Wed, 21 Oct 2026 16:47:51 +0200 Subject: [PATCH] Measure each chunk by one rule: a merge commit, or a run of commits sharing one commit time --- CHANGELOG.md | 2 +- bin/score_outcomes/anchors.py | 2 +- bin/score_outcomes/main.py | 72 +++++++++++------------ bin/score_outcomes/test_score_outcomes.py | 53 +++++++++++++++-- todo.md | 7 +-- 5 files changed, 84 insertions(+), 52 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70a92505..bcf50e99 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- `score-outcomes` now measures chunks in a project that merges by rebase. After the default branch's newest merge commit, a chunk is a run of commits sharing one commit time, which a rebase merge gives the commits it replays. Such a chunk's rounds and findings read `at least`, since rebase drops a round's empty commit; a run never replayed reads `never replayed, so perhaps part of a pull request`; and the report ends saying how it reads these chunks. Such projects can now add `docs/score-anchors.md`. +- `score-outcomes` measures each chunk on the default branch's first-parent line: a merge commit is a chunk of its own, and any other commit joins the commit above it when both share a commit time, else starts a chunk. - Every project now shares one achieve goal, code health: the code is easy to understand and change safely. `CLAUDE.md` → "Shared goal" states it, with its signal and counter-signal. `rank_todo.py` ranks it first among a project's achieve goals. A project's overall is the overall mean of the newest scoring run in `docs/comprehension-history.md`, averaged with every other run on its commit. While that overall is under 7.0, or no run has measured the project, code health weighs four times as much as it does at 7.0 or above. An item's Moves cell names it as in `code health by 6`. A README voids it with `**Void:** code health, since .` under `## Goals`, and `rank_todo.py` then refuses an item that names it. `larv-review record-scoring` re-ranks `todo.md` after it appends a run, and exits 1 where `rank_todo.py` would, keeping the run. Expect items that make code easier to read to rank higher in every project. On upgrade: 1. Move every machine to this release before any of them ranks a plan another machine shares: an older `rank_todo.py` scores it without code health and rejects a `code health` cell. 2. Void code health in each project that opts out of the comprehension check, or `rank_todo.py` refuses its plan. diff --git a/bin/score_outcomes/anchors.py b/bin/score_outcomes/anchors.py index c9443766..92be7cac 100644 --- a/bin/score_outcomes/anchors.py +++ b/bin/score_outcomes/anchors.py @@ -39,5 +39,5 @@ def anchor_lines(found: Anchors | Failure, outcomes: list[Outcome]) -> list[str] lines = [] for level, ids in found: lines.append(f"{level}:") - lines += [render(by_id[id_]) if id_ in by_id else f"- Item {id_}: no merge commit on the default branch shipped it." for id_ in ids] + lines += [render(by_id[id_]) if id_ in by_id else f"- Item {id_}: no chunk shipped it." for id_ in ids] return lines diff --git a/bin/score_outcomes/main.py b/bin/score_outcomes/main.py index 39331412..2407b9f8 100644 --- a/bin/score_outcomes/main.py +++ b/bin/score_outcomes/main.py @@ -6,11 +6,12 @@ Run it inside a project checkout or one of its worktrees. It fetches origin, whe 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 the scores it held in the todo.md of the merge's first -parent: L, E, I, R and S. An item scored before L, E and I replaced C holds R and S, and C too where -its table also had A, G and Goals. The chunk measures: +Git history is the record. The default branch's first-parent line is cut into chunks by one rule: a +merge commit is a chunk of its own, and any other commit joins the commit above it when both share a +commit time, else starts a chunk. A chunk whose change removed items from todo.md, and changed more +than todo.md and the records below, shipped those items. Each item's guess is the scores it held in +the todo.md the chunk started from: L, E, I, R and S. An item scored before L, E and I replaced C +holds R and S, and C too where its table also had A, G and Goals. 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; @@ -21,14 +22,12 @@ its table also had A, G and Goals. The chunk measures: 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. -After the first-parent line's newest merge commit, where a project merges by rebase or squash, a -chunk is instead a run of commits on that line sharing one commit time, as a rebase merge replays a -pull request's commits at once; it measures against the commit before its first, whose todo.md -holds the guesses, and its titles are its commits'. It is marked `by rebase` where a commit time -differs from its author time, and `never replayed` where none does, since a pushed or -fast-forwarded commit may be part of a pull request. Two pull requests merged in the same second -read as one chunk. Rebase drops a round's commit that changed no file, so such a chunk gives its -rounds and findings as lower bounds, `at least`, and the report ends saying all this. +A chunk is marked `by rebase` where a commit in it has a committer time apart from its author time, +since a rebase replays a pull request's commits at once, and `never replayed` where none does, since +a pushed or fast-forwarded commit may be part of a pull request. A merge's titles are its branch's +commits'; any other chunk's are its own. Two pull requests merged in the same second read as one +chunk. Rebase drops a round's commit that changed no file, so such a chunk gives its rounds and +findings as lower bounds, `at least`, and the report ends saying all this. Given L, E and I, on the levels ~/.claude/rules/todo-items.md defines, and S, it works out R from L, E and I, as rank_todo.py does, and lists the 5 finished items whose guesses sit closest, closest @@ -37,7 +36,7 @@ scored before L, E and I, the newest first among equals. Each line gives what th measured, which items shipped with it, and its tagline. Then the project's anchors, the shipped items its docs/score-anchors.md names for each level of L, -E and I, read from the checkout's working tree, each line as above, or that no merge shipped it. A +E and I, read from the checkout's working tree, each line as above, or that no chunk shipped it. A file that cannot be read, a row that does not hold a level on its scale and a list of IDs, or a level named twice leaves the anchors out, saying why. @@ -132,47 +131,42 @@ def read_anchors() -> Anchors | Failure: def read_outcomes(default: str) -> list[Outcome] | Failure: - """What each chunk measured: each merge commit on the default branch's first-parent line, and each run of commits after the newest that share one commit time.""" + """What each chunk on the default branch's first-parent line measured.""" 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 + chunks = read_chunks(default) + if isinstance(chunks, Failure): + return chunks outcomes: list[Outcome] = [] - for line in merges.splitlines(): - merge, short, time = line.split() - measured = measure(f"{merge}^1", merge, short, utc(int(time)), f"{merge}^1..{merge}^2", "merge") - if isinstance(measured, Failure): - return measured - outcomes += measured - replays = read_replays(default) - if isinstance(replays, Failure): - return replays - for first, last, committed, landed in replays: - label = f"{first}^..{last}" if first != last else first - measured = measure(f"{first}^1", last, label, utc(committed), f"{first}^1..{last}", landed) + for first, last, committed, landed in chunks: + label = first if first == last else f"{first}^..{last}" + titled = f"{first}^1..{first}^2" if landed == "merge" else f"{first}^1..{last}" + measured = measure(f"{first}^1", last, label, utc(committed), titled, landed) if isinstance(measured, Failure): return measured outcomes += measured return outcomes -def read_replays(default: str) -> list[tuple[str, str, int, Landing]] | Failure: - """Each run of commits on the default branch's first-parent line after its newest merge commit that share one commit time: its first and last commit, as short hashes, that time, and whether a rebase replayed it, which leaves a commit time apart from its author time.""" +def read_chunks(default: str) -> list[tuple[str, str, int, Landing]] | Failure: + """Each chunk on the default branch's first-parent line, newest first: its first and last commit as short hashes, its commit time, and how it reached the branch. A merge commit is a chunk of its own; any other commit joins the commit above it when both share a commit time.""" log = git("log", "--first-parent", "--format=%h %ct %at %p", default) if isinstance(log, Failure): return log - runs: list[tuple[str, str, int, Landing]] = [] + chunks: list[tuple[str, str, int, Landing]] = [] + joinable = False for line in log.splitlines(): short, committed, authored, *parents = line.split() if len(parents) > 1: - break - replayed = committed != authored - if runs and runs[-1][2] == int(committed): - runs[-1] = (short, runs[-1][1], int(committed), "rebase" if replayed or runs[-1][3] == "rebase" else "push") + chunks.append((short, short, int(committed), "merge")) + joinable = False + elif joinable and chunks[-1][2] == int(committed): + _, newest, time, landed = chunks[-1] + chunks[-1] = (short, newest, time, "rebase" if landed == "rebase" or committed != authored else "push") else: - runs.append((short, short, int(committed), "rebase" if replayed else "push")) - return runs + chunks.append((short, short, int(committed), "rebase" if committed != authored else "push")) + joinable = True + return chunks def measure(before: str, tip: str, label: str, merged: str, titled: str, landed: Landing) -> list[Outcome] | Failure: diff --git a/bin/score_outcomes/test_score_outcomes.py b/bin/score_outcomes/test_score_outcomes.py index 9d47b8eb..3678cd93 100644 --- a/bin/score_outcomes/test_score_outcomes.py +++ b/bin/score_outcomes/test_score_outcomes.py @@ -152,7 +152,7 @@ class Anchors(unittest.TestCase): def test_lists_each_anchor_with_what_its_chunk_measured_and_says_which_it_cannot_find(self): lines = anchor_lines([("L 1", (4, 9))], [outcome(4, 2, 3, None, findings=(1, 2))]) - self.assertEqual(lines, ["L 1:", "- Item 4, R 2, S 3: 10 lines in 1 file, 1 round past each pass's first, 1 🔴, 2 🟡; merged 2026-10-13T10:00:00Z in aaaaaaa. **Item 4.**", "- Item 9: no merge commit on the default branch shipped it."]) + self.assertEqual(lines, ["L 1:", "- Item 4, R 2, S 3: 10 lines in 1 file, 1 round past each pass's first, 1 🔴, 2 🟡; merged 2026-10-13T10:00:00Z in aaaaaaa. **Item 4.**", "- Item 9: no chunk shipped it."]) def test_points_to_the_rules_where_the_project_names_no_anchors(self): self.assertIn("docs/score-anchors.md", anchor_lines([], [])[0]) @@ -222,6 +222,13 @@ class ScoreOutcomesTool(unittest.TestCase): self.env.pop(name, None) return self.git("rev-parse", "--short", "HEAD").strip() + def merge_branch(self, branch, at): + self.env.update({"GIT_COMMITTER_DATE": at, "GIT_AUTHOR_DATE": at}) + self.git("merge", "-q", "--no-ff", "-m", f"Merge {branch}", branch) + for name in ("GIT_COMMITTER_DATE", "GIT_AUTHOR_DATE"): + self.env.pop(name, None) + return self.git("rev-parse", "--short", "HEAD").strip() + def run_tool(self, *args): return subprocess.run([sys.executable, str(TOOL), *args], capture_output=True, cwd=self.checkout, env=self.env, text=True) @@ -251,8 +258,8 @@ class ScoreOutcomesTool(unittest.TestCase): self.assertIn(f"- Item 5, R 4, S 6, C 8: 1 line in 1 file, at least 0 rounds past each pass's first, findings unknown; committed 2026-10-13T11:00:00Z in {pushed}, never replayed, so perhaps part of a pull request. **Then this.**", ran.stdout) self.assertIn("Chunks that left no merge commit:", ran.stdout) - def test_measures_merge_commits_as_before_and_reads_no_rebase_chunk_behind_the_newest(self): - self.commit("Drop item 5 on main", {"b.py": "1\n", "todo.md": todo(FIRST)}, at="2026-10-12T09:00:00Z") + def test_counts_a_direct_commit_behind_the_newest_merge_as_a_push_chunk(self): + drop = self.commit("Drop item 5 on main", {"b.py": "1\n", "todo.md": todo(FIRST)}, at="2026-10-12T09:00:00Z", authored="2026-10-12T09:00:00Z") self.git("switch", "-q", "-c", "chunk") self.commit("Do it", {"a.py": "1\n", "todo.md": todo()}) self.git("switch", "-q", "main") @@ -260,9 +267,45 @@ class ScoreOutcomesTool(unittest.TestCase): ran = self.run_tool("1", "2", "1", "3") self.assertEqual(ran.returncode, 0, ran.stderr) self.assertRegex(ran.stdout, r"- Item 4, R 2, S 3, C 10: 1 line in 1 file, 0 rounds past each pass's first, findings unknown; merged \S+ in [0-9a-f]{7,}\. ") - self.assertNotIn("Item 5", ran.stdout) + self.assertIn(f"- Item 5, R 4, S 6, C 8: 1 line in 1 file, at least 0 rounds past each pass's first, findings unknown; committed 2026-10-12T09:00:00Z in {drop}, never replayed, so perhaps part of a pull request. **Then this.**", ran.stdout) self.assertNotIn("by rebase", ran.stdout) + def test_labels_a_merge_merge_even_when_its_author_and_commit_times_are_equal(self): + self.git("switch", "-q", "-c", "chunk") + self.commit("Do it", {"a.py": "1\n", "todo.md": todo(SECOND)}, at="2026-10-13T09:00:00Z", authored="2026-10-13T09:00:00Z") + self.git("switch", "-q", "main") + merged = self.merge_branch("chunk", "2026-10-13T10:00:00Z") + ran = self.run_tool("1", "2", "1", "3") + self.assertEqual(ran.returncode, 0, ran.stderr) + self.assertIn(f"merged 2026-10-13T10:00:00Z in {merged}. **Do it.**", ran.stdout) + self.assertNotIn("by rebase", ran.stdout) + self.assertNotIn("never replayed", ran.stdout) + + def test_counts_each_merge_at_one_commit_time_as_its_own_chunk(self): + self.git("switch", "-q", "-c", "one") + self.commit("Do four", {"a.py": "1\n", "todo.md": todo(SECOND)}, at="2026-10-13T10:00:00Z", authored="2026-10-13T10:00:00Z") + self.git("switch", "-q", "main") + first = self.merge_branch("one", "2026-10-13T10:00:00Z") + self.git("switch", "-q", "-c", "two") + self.commit("Do five", {"b.py": "1\n", "todo.md": todo()}, at="2026-10-13T10:00:00Z", authored="2026-10-13T10:00:00Z") + self.git("switch", "-q", "main") + second = self.merge_branch("two", "2026-10-13T10:00:00Z") + ran = self.run_tool("1", "2", "1", "3") + self.assertEqual(ran.returncode, 0, ran.stderr) + self.assertIn(f"merged 2026-10-13T10:00:00Z in {first}. **Do it.**", ran.stdout) + self.assertIn(f"merged 2026-10-13T10:00:00Z in {second}. **Then this.**", ran.stdout) + + def test_counts_a_rebase_run_behind_a_merge_as_one_chunk_labelled_rebase(self): + self.git("switch", "-q", "-c", "other") + self.commit("Other work", {"z.py": "1\n"}) + self.git("switch", "-q", "main") + first = self.commit("Do it", {"a.py": "1\n2\n3\n", "todo.md": todo(SECOND)}, at="2026-10-13T09:00:00Z", authored="2026-10-13T08:00:00Z") + last = self.commit("Answer stability round 1: 1 🔴, 2 🟡; fix", {"a.py": "1\n2\n4\n"}, at="2026-10-13T09:00:00Z", authored="2026-10-13T08:00:00Z") + self.merge_branch("other", "2026-10-13T10:00:00Z") + ran = self.run_tool("1", "2", "1", "3") + self.assertEqual(ran.returncode, 0, ran.stderr) + self.assertIn(f"- Item 4, R 2, S 3, C 10: 3 lines in 1 file, at least 0 rounds past each pass's first, at least 1 🔴, 2 🟡; merged 2026-10-13T09:00:00Z by rebase in {first}^..{last}. **Do it.**", ran.stdout) + def test_lists_the_projects_anchors_with_what_their_chunks_measured(self): self.git("switch", "-q", "-c", "chunk") self.commit("Do it", {"a.py": "1\n", "todo.md": todo(SECOND)}) @@ -273,7 +316,7 @@ class ScoreOutcomesTool(unittest.TestCase): ran = self.run_tool("1", "2", "1", "3") self.assertEqual(ran.returncode, 0, ran.stderr) self.assertIn("Anchors in docs/score-anchors.md, each level's shipped items:\n\nL 1:\n- Item 4, R 2, S 3, C 10: 1 line in 1 file", ran.stdout) - self.assertIn("I 3:\n- Item 5: no merge commit on the default branch shipped it.", ran.stdout) + self.assertIn("I 3:\n- Item 5: no chunk shipped it.", ran.stdout) def test_refuses_anchors_it_cannot_read(self): (self.checkout / "docs").mkdir() diff --git a/todo.md b/todo.md index 42cbd391..517f95cc 100644 --- a/todo.md +++ b/todo.md @@ -71,7 +71,6 @@ | 101 | 0.4.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.** | 2 | 1 | 2 | 3 | 3 | 1.1 by 5 | 5.3 | | 111 | 0.4.0 | | | **Measure the chunks of a project that merges by squash or fast-forward, which `score-outcomes` skips today.** | 3 | 2 | 2 | 5 | 3 | 1.1 by 5 | 5.3 | | 110 | 0.4.0 | | | **Count, for each finished chunk, the later changes that fixed code it wrote, and show them beside its guessed E.** | 3 | 2 | 2 | 5 | 5 | 1.1 by 6, 1.4 by 6 | 4.9 | -| 200 | 0.4.0 | | | **Make `score-outcomes` measure the chunks of a project that merges by rebase.** | 2 | 2 | 1 | 3 | 3 | 1.1 by 4 | 4.2 | | 149 | 0.4.0 | | decision | **Fill each release by priority up to a capacity it states, in place of the bar, and move what does not fit to a later release.** | 4 | 2 | 3 | 7 | 5 | 1.1 by 7 | 3.0 | | 123 | 0.5.0 | | | **Have `bin/comprehension_history.py` parse each history entry once into seats, votes and places, so `latest_places`, `worse_places` and `worse_votes` neither depend on table order nor split a label to find a seat.** | 2 | 1 | 2 | 3 | 5 | code health by 5, 1.4 by 5 | 11.0 | | 124 | 0.5.0 | | decision | **Group the shared modules at `bin/`'s root into packages named by purpose, so the root holds only launchers and stand-alone tools.** | 4 | 1 | 3 | 6 | 6 | code health by 9, 1.4 by 9 | 11.0 | @@ -331,16 +330,12 @@ Found by the principles audit of PR #242, against "Functional core, imperative s ### 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. A project that merges by squash or fast-forward has no merge commit, so its scorer sees no finished item. Rebase merges are item 200. +`score-outcomes` reads a chunk from a merge commit: its branch's round titles, and its change against the first parent. A project that merges by squash or fast-forward has no merge commit, so its scorer sees no finished item. ### 110. Count, for each finished chunk, the later changes that fixed code it wrote, and show them beside its guessed E. `score-outcomes` measures risk only by the 🔴 findings review caught. A serious bug review missed shows later, as a change that fixes code the chunk wrote: the defect that escaped, which E guesses. -### 200. Make `score-outcomes` measure the chunks of a project that merges by rebase. - -A rebase merge replays a pull request's commits at once, so they share one commit time. `score-outcomes` should read each such run as one chunk, under the same rule that reads a merge commit as one chunk. Squash and fast-forward merges stay with item 111. - ### 149. Fill each release by priority up to a capacity it states, in place of the bar, and move what does not fit to a later release. A release's capacity is a sum of its items' cost, as the formula counts it. Each project states its own; the human sets the first value per project. Nothing is deleted by score.