From abf4f67ca86189c7f7342e3d78f3f4891daea67c Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 29 Oct 2026 00:28:14 +0100 Subject: [PATCH] Count a file read in chunk-preflight's worktree in reading-cost's most-read list --- CHANGELOG.md | 1 + bin/reading_cost/measure.py | 8 +++++++- bin/reading_cost/test_reading_cost.py | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6de37e6b..c9e6be58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- `reading-cost` now lists the files a chunk read in the worktree `chunk-preflight` made, `-item-`. It listed none, since no transcript command names that worktree. - `larv-review ruling-base` now finds the last measured commit when run in a subfolder of a checkout. Before, it found no change to the comprehension history there and fell back to the merge base. - `score-outcomes` now counts each finished chunk's later fixes: the later chunks on the default branch that fixed code it shipped, each a defect that review let through. A later chunk counts where a change of it rewrites or removes lines that `git blame` traces to the earlier chunk: its whole change where it ships a `todo.md` item marked `defect` or `security`, or one of its round commits whose title counts both a 🔴 and a finding a reviewer marked `[misread]`. Each finished item shows the count beside its guessed scores, and a new list, after the misread findings, names the chunks that fixed each one, newest first. `routing-figures.md` shows the mean per rung, over the chunks whose later fixes are known, in a new column of the routed-chunks table. To find them, loop-claude now reads each archived project's checkout, and the figures name each project whose default branch it could not read. - `loop-claude` now opens every message it prints with the machine's local time, as in `2026-10-28 11:46:01`, so you can see when each happened, such as how long a question has waited. A message of several lines, such as a question, carries the time on its first line only. The `retrying at …` time of a usage-limit wait now also shows seconds, and no longer names the zone. diff --git a/bin/reading_cost/measure.py b/bin/reading_cost/measure.py index a5d35ce0..0b671703 100644 --- a/bin/reading_cost/measure.py +++ b/bin/reading_cost/measure.py @@ -1,5 +1,6 @@ import collections import dataclasses +import re from claude_code.entries import assistant_parts, parse_entry, tool_call, usage_count from git_command import commits @@ -32,7 +33,7 @@ def measure(threads: list[bytes], checkout: Checkout, home: str) -> Reading | No before = [[entry for entry in thread if entry.get("type") == "assistant" and str(entry.get("timestamp", "")) < commit] for thread in (worker, *subagents)] reads = [reads_of(part, str(entry.get("cwd") or "/"), home) for thread in before for entry in thread for part in assistant_parts(entry)] roots = [checkout.main_root, *(added for found in reads for added in found.added)] - files = collections.Counter(file for found in reads for path in found.read if (file := relative(path, roots)) in checkout.tracked) + files = collections.Counter(file for found in reads for path in found.read if (file := relative(in_main_checkout(path, checkout.main_root), roots)) in checkout.tracked) return Reading(sum(map(tokens_in, before)), files) @@ -68,6 +69,11 @@ def reads_of(part: object, cwd: str, home: str) -> Reads: return shell_reads(str(arguments.get("command", "")), cwd, home) if name == "Bash" else Reads([], []) +# chunk-preflight adds each item's worktree beside the checkout as -item-, which no transcript command names. +def in_main_checkout(path: str, main_root: str) -> str: + return re.sub("^" + re.escape(main_root.rstrip("/")) + r"-item-\d+(?=/)", main_root.rstrip("/"), path, count=1) + + # Relative to the deepest root holding it, so the checkout and each worktree name a file alike. def relative(path: str, roots: list[str]) -> str | None: holding = [root for root in roots if path.startswith(root.rstrip("/") + "/")] diff --git a/bin/reading_cost/test_reading_cost.py b/bin/reading_cost/test_reading_cost.py index e86154ed..c9b79278 100644 --- a/bin/reading_cost/test_reading_cost.py +++ b/bin/reading_cost/test_reading_cost.py @@ -64,6 +64,11 @@ class Measure(unittest.TestCase): checkout = Checkout("/c/w", "/c/p", frozenset({"README.md", "late.py", "src/a.py", "src/b.py", "x.py"})) self.assertEqual(measure.measure([jsonl(worker), jsonl(subagent)], checkout, "/h"), Reading(33, collections.Counter({"src/a.py": 2, "README.md": 1, "src/b.py": 1}))) + def test_counts_a_file_read_in_the_worktree_chunk_preflight_made_as_the_checkout_s(self): + worker = [said("1", "m1", tokens=10, name="Read", input={"file_path": "/c/p-item-7/README.md"}), said("2", "m2", command="git commit -m x")] + checkout = Checkout("/c/p-item-7", "/c/p", frozenset({"README.md"})) + self.assertEqual(measure.measure([jsonl(worker)], checkout, "/h").files, collections.Counter({"README.md": 1})) + def test_measures_nothing_for_a_worker_that_never_committed(self): self.assertIsNone(measure.measure([jsonl([said("1", "m1", command="git log --grep commit")])], Checkout("/c/p", "/c/p", frozenset()), "/h")) self.assertIsNone(measure.measure([jsonl([said("1", "m1", command="echo git commit")])], Checkout("/c/p", "/c/p", frozenset()), "/h"))