diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cc3e74a..e75766d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- larv-review runs the new `bin/reading_cost.py`, which measures each chunk `loop-claude` finished from its archive: the tokens the worker and its subagents took in before the worker's first commit, and the files git tracks that they read most. It appends each figure the project's `docs/comprehension-history.md` lacks. When the last 5 chunks' median is above the 5 before them, larv-review files one plan item naming the files read most, or refreshes it; only its own chunk or you remove it. The chunk that ships it runs `reading_cost.py --reset`, so the trend counts only chunks that finished after it. +- larv-review runs the new `bin/reading_cost.py`, which measures each chunk `loop-claude` finished from its archive: the new input tokens the worker and its subagents took in before the worker's first commit, and the files git tracks that they read most. It appends each figure the project's `docs/comprehension-history.md` lacks. Once 10 chunks are measured, and the last 5 chunks' median is above the 5 before them, larv-review files one plan item naming the files read most, or refreshes it; only its own chunk or you remove it. The chunk that ships it runs `reading_cost.py --reset`, so the trend counts only chunks that finished after it. - larv-review appends every scoring run to the project's `docs/comprehension-history.md`: the commit the seats read, each seat's five scores and the seats' mean, and the places each seat named. The ratchet compares a run with the history's last run on the default branch. The `comprehension floor:` entry in `docs/decisions.md` keeps only the decisions to ship under the floor; a project's next scoring run moves the last scores the entry still holds into the history. The seats do not read the history. - The README's goals put quality with the fewest interrupts first, as goal 1; sharing the setup, backups and leaking nothing follow as goals 2–4. - larv-review reruns the comprehension scoring run before merge when any commit since the last run changes more than `docs/decisions.md`, `docs/comprehension-history.md`, `todo.md` or `CHANGELOG.md`, so the recorded scores are the merged commit's. A score under the floor, or below the default branch's recorded scores, blocks the merge and is never filed in `todo.md`. A fix lifts either; your decision to ship under the floor lifts only a score under the floor. A rerun counts toward the three-round cap only when it reports a blocking score that no decision of yours covers. diff --git a/README.md b/README.md index 5f542e3d..ad898b4e 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ Rename `## Unreleased` in `CHANGELOG.md` to the version, commit, tag that commit - `loop-claude ` runs a project's next chunk cycle after cycle; `loop-claude --help` states its contract. - `rank_todo.py [--check] [todo.md]` scores and ranks a project's `todo.md`; `rank_todo.py --help` states the format. -- `reading_cost.py [--reset] [history]` measures the chunks `loop-claude` finished into a project's comprehension history and says whether the figures rise; `reading_cost.py --help` states the measure. +- `reading_cost.py [--reset] [history]` appends a figure for each chunk `loop-claude` finished to a project's comprehension history, and says whether the figures rise; `reading_cost.py --help` states the measure. - `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'` diff --git a/bin/reading_cost.py b/bin/reading_cost.py index 815e81b9..fc205697 100644 --- a/bin/reading_cost.py +++ b/bin/reading_cost.py @@ -3,14 +3,14 @@ usage: reading_cost.py [--reset] [history] -Run it inside a project checkout or one of its worktrees. history defaults to -docs/comprehension-history.md there, created when missing. It reads loop-claude's archive of the -project, $LOOP_CLAUDE_TRANSCRIPTS/ (default ~/.claude/loop-claude-transcripts), being -the checkout's path relative to ~/code, or to / outside it. For each chunk the judge ruled -finished, under a UTC time, that history does not hold, it measures what the worker and its subagents read before -the worker's first commit: the tokens they took in, and how often they opened or searched each -file git tracks in the checkout. A chunk whose worker never committed is not measured. Each -figure is appended under a "## Reading cost, chunk , finished " heading, in the +Run it inside a project checkout or one of its worktrees. history defaults to docs/comprehension- +history.md there, created when missing. It reads loop-claude's archive of the project, +$LOOP_CLAUDE_TRANSCRIPTS/ (default ~/.claude/loop-claude-transcripts), being the +checkout's path relative to ~/code, or to / outside it. For each finished chunk the history does not +yet hold, it measures what the worker and its subagents read before the worker's first commit: their +new input tokens (uncached and cache-written; cache reads excluded), and how often they opened or +searched each file git tracks in the checkout. A chunk whose worker never committed is not measured. +Each figure is appended under a "## Reading cost, chunk , finished " heading, in the order the chunks finished. --reset also appends a "## Reading cost reset, " heading: the trend then counts only @@ -49,7 +49,7 @@ HEADING = "Reading cost, chunk " PLACE = re.compile(r"^- `(.+)` (\d+)$") PLACES_KEPT = 10 RESET = "Reading cost reset, " -TOKENS = re.compile(r"^(\d+) tokens read before the first commit\.$") +TOKENS = re.compile(r"^(\d+) new input tokens before the first commit\.$") WINDOW = 5 @@ -70,10 +70,12 @@ class Checkout: def main(argv: list[str]) -> int: reset = argv[:1] == ["--reset"] given = argv[1:] if reset else argv - if given[:1] in (["-h"], ["--help"]) or len(given) > 1 or given[:1] and given[0].startswith("-"): - helped = given[:1] in (["-h"], ["--help"]) and len(given) == 1 - print(__doc__.strip(), file=sys.stdout if helped else sys.stderr) - return 0 if helped else 1 + if given in (["-h"], ["--help"]): + print(__doc__.strip()) + return 0 + if len(given) > 1 or given[:1] and given[0].startswith("-"): + print(f"unknown arguments {' '.join(given)}; usage: reading_cost.py [--reset] [history]", file=sys.stderr) + return 1 checkout = located() if isinstance(checkout, Failure): return failed(checkout) @@ -85,7 +87,7 @@ def main(argv: list[str]) -> int: if isinstance(updated, Failure): return failed(updated) appended, readings = updated - print(f"Appended {appended} reading-cost figures from {archive}{' and a reset' if reset else ''} to {history}.") + print(f"Appended {appended} reading-cost figure{'' if appended == 1 else 's'} from {archive}{' and a reset' if reset else ''} to {history}.") print(trend(readings)) return 0 @@ -233,7 +235,7 @@ def relative(path: str, roots: list[str]) -> str | None: def figure(chunk: FinishedChunk, reading: Reading) -> str: places = "".join(f"- `{path}` {times}\n" for path, times in ranked(reading.places)) - return f"## {HEADING}{chunk_id(chunk)}, finished {chunk.finished}\n\n{reading.tokens} tokens read before the first commit.\n" + (f"\nRead most:\n\n{places}" if places else "") + return f"## {HEADING}{chunk_id(chunk)}, finished {chunk.finished}\n\n{reading.tokens} new input tokens before the first commit.\n" + (f"\nRead most (opens and searches):\n\n{places}" if places else "") # The figures after the last reset, in the order their chunks finished: each machine appends its own archive's chunks. @@ -260,16 +262,15 @@ def merged(history: str, figures: list[str]) -> str: return history.rstrip("\n") + "\n\n" + "\n".join(figures) -# Medians, so one chunk that ran a panel of readers or waited out a usage limit does not decide the trend alone. def trend(readings: list[Reading]) -> str: if len(readings) < 2 * WINDOW: return f"{len(readings)} chunks measured; the trend needs {2 * WINDOW}." last, earlier = middle(readings[-WINDOW:]), middle(readings[-2 * WINDOW:-WINDOW]) - medians = f"the last {WINDOW} chunks' median is {last} tokens read before their first commit, the {WINDOW} before them {earlier}." + medians = f"the last {WINDOW} chunks' median is {last} new input tokens before their first commit, the {WINDOW} before them {earlier}." if last <= earlier: return f"Not rising: {medians}" read_most = "".join(f"\n- `{path}` {times}" for path, times in ranked(sum((reading.places for reading in readings[-WINDOW:]), collections.Counter()))) - return f"Rising: {medians}\n\nRead most over the last {WINDOW}:\n{read_most}" + return f"Rising: {medians}\n\nRead most over the last {WINDOW} (opens and searches):\n{read_most}" def middle(readings: list[Reading]) -> int: diff --git a/bin/test_reading_cost.py b/bin/test_reading_cost.py index a1008d68..21c673f0 100644 --- a/bin/test_reading_cost.py +++ b/bin/test_reading_cost.py @@ -73,16 +73,16 @@ class Figures(unittest.TestCase): def test_rises_only_above_the_five_before_and_needs_ten(self): flat = [Reading(100, collections.Counter({"a.py": 1}))] * 10 self.assertEqual(reading_cost.trend(flat[:9]), "9 chunks measured; the trend needs 10.") - self.assertTrue(reading_cost.trend(flat).startswith("Not rising: the last 5 chunks' median is 100 tokens")) + self.assertTrue(reading_cost.trend(flat).startswith("Not rising: the last 5 chunks' median is 100 new input tokens")) self.assertTrue(reading_cost.trend(flat[:9] + [Reading(3000000, collections.Counter())]).startswith("Not rising:")) - self.assertEqual(reading_cost.trend(flat[:5] + [Reading(101, collections.Counter({"b.py": 2}))] * 5), "Rising: the last 5 chunks' median is 101 tokens read before their first commit, the 5 before them 100.\n\nRead most over the last 5:\n\n- `b.py` 10") + self.assertEqual(reading_cost.trend(flat[:5] + [Reading(101, collections.Counter({"b.py": 2}))] * 5), "Rising: the last 5 chunks' median is 101 new input tokens before their first commit, the 5 before them 100.\n\nRead most over the last 5 (opens and searches):\n\n- `b.py` 10") def test_a_figure_reads_back_as_the_reading_it_was_written_from_and_a_damaged_one_fails(self): reading = Reading(7, collections.Counter({"b.py": 1, "a.py": 3})) written = reading_cost.figure(FinishedChunk("abcdef0123456789", "t", pathlib.Path(), []), reading) - self.assertEqual(written, "## Reading cost, chunk abcdef012345, finished t\n\n7 tokens read before the first commit.\n\nRead most:\n\n- `a.py` 3\n- `b.py` 1\n") + self.assertEqual(written, "## Reading cost, chunk abcdef012345, finished t\n\n7 new input tokens before the first commit.\n\nRead most (opens and searches):\n\n- `a.py` 3\n- `b.py` 1\n") self.assertEqual(reading_cost.readings_of(written), [reading]) - self.assertEqual(reading_cost.readings_of(written.replace("7 tokens", "seven tokens")), Failure('the figure under "## Reading cost, chunk abcdef012345, finished t" holds no single tokens line; restore it from git history')) + self.assertEqual(reading_cost.readings_of(written.replace("7 new", "seven new")), Failure('the figure under "## Reading cost, chunk abcdef012345, finished t" holds no single tokens line; restore it from git history')) def test_counts_only_figures_finished_after_the_last_reset_in_the_order_they_finished(self): @@ -136,7 +136,7 @@ class ReadingCostTool(unittest.TestCase): self.assertEqual(ran.returncode, 0, ran.stderr) history = worktree / "docs" / "comprehension-history.md" self.assertEqual(ran.stdout, f"Appended 2 reading-cost figures from {self.home / '.claude' / 'loop-claude-transcripts' / 'proj'} to {history}.\n2 chunks measured; the trend needs 10.\n") - figure = "## Reading cost, chunk {}, finished {}\n\n33 tokens read before the first commit.\n\nRead most:\n\n- `a.py` 1\n" + figure = "## Reading cost, chunk {}, finished {}\n\n33 new input tokens before the first commit.\n\nRead most (opens and searches):\n\n- `a.py` 1\n" self.assertEqual(history.read_text(), "# Comprehension history\n\n" + "\n".join(figure.format(chunk.folder[:12], chunk.finished) for chunk in chunks)) self.assertTrue(self.run_tool(worktree).stdout.startswith(f"Appended 0 reading-cost figures from")) self.assertEqual(history.read_text().count("## Reading cost"), 2) @@ -147,7 +147,6 @@ class ReadingCostTool(unittest.TestCase): def test_refuses_an_option_it_does_not_know(self): ran = self.run_tool(self.checkout, "--rest") self.assertEqual((ran.returncode, ran.stdout), (1, "")) - self.assertFalse((self.checkout / "--rest").exists()) def test_exits_1_outside_a_checkout(self): ran = self.run_tool(self.home) diff --git a/docs/decisions.md b/docs/decisions.md index e782646f..525780a1 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -112,7 +112,7 @@ lilleman decided to ship each of these under the floor on the day listed. Each l ## reading cost: larv-review measures each finished chunk from loop-claude's archive and appends the figure to `docs/comprehension-history.md` in the next chunk's PR -2026-10-08, lilleman. Serves goal 1.1: comprehension measured from real work, at no model cost (goal 1.4). loop-claude archives from the main checkout, outside any PR, so a tracked file it wrote there would dirty that checkout; `bin/reading_cost.py` instead measures each finished chunk the history lacks from the archive, in the next chunk's worktree, so a PR that never merges loses no figure and loop-claude needs no change. Serves goal 4 by naming only files git tracks, and token counts. Rejected: loop-claude opening a PR of its own, one more PR per chunk and a tie to the forge; the worker measuring its own transcript before merging, which misses the chunk's tail. The figure counts tokens taken in, because workers read mostly through Bash and subagents, where parsed paths alone miss what they read. Valid while loop-claude archives every finished chunk with its subagents' transcripts. +2026-10-08, lilleman. Serves goal 1.1: comprehension measured from real work, at no model cost (goal 1.4). loop-claude archives from the main checkout, outside any PR, so a tracked file it wrote there would dirty that checkout; `bin/reading_cost.py` instead measures each finished chunk the history lacks from the archive, in the next chunk's worktree, so a PR that never merges loses no figure and loop-claude needs no change. Serves goal 4 by naming only files git tracks, and token counts. Rejected: loop-claude opening a PR of its own, one more PR per chunk and a tie to the forge; the worker measuring its own transcript before merging, which misses the chunk's tail. The figure counts new input tokens, uncached and cache-written, because workers read mostly through Bash and subagents, where parsed paths alone miss what they read. Valid while loop-claude archives every finished chunk with its subagents' transcripts. ## reading cost: a rise is the last 5 chunks' median above the 5 before them, and files or refreshes one plan item that only its own chunk or the human removes diff --git a/skills/larv-review/SKILL.md b/skills/larv-review/SKILL.md index 0fb97ba3..a7fa4ab7 100644 --- a/skills/larv-review/SKILL.md +++ b/skills/larv-review/SKILL.md @@ -24,7 +24,7 @@ Words: `~/.claude/CLAUDE.md` → "Vocabulary". What a reviewer reports: ~/.claud Follow `~/.claude/CLAUDE.md` → "Git, commits, and PRs". Never commit to the default branch. Commit, push with upstream set, and open a **draft** PR so CI cycles while the review runs. No remote → review locally and say so in the summary. -**Reading cost.** Run `~/.claude/bin/reading_cost.py` in the chunk's worktree and commit what it appends to `docs/comprehension-history.md`; the commit re-enters no pass. On `Rising:`, file a plan item titled `**Lower the reading cost of the files chunks read most before their first commit.**` under the next release, with no Exempt reason and the tool's medians and files as its detail; where the plan already holds it, refresh its detail instead. On exit 1, repair what its message names and run it again; ask the human when the message names no repair. Leave the plan as it is on any other output. The chunk that ships that item runs the tool with `--reset` instead, so the next rise is measured on chunks that finished after it. +**Reading cost.** Run `~/.claude/bin/reading_cost.py` in the chunk's worktree and commit what it appends to `docs/comprehension-history.md`; the commit re-enters no pass. On `Rising:`, file a plan item titled `**Lower the reading cost of the files chunks read most before their first commit.**`, scored per `~/.claude/CLAUDE.md` → "Todo items" with the tool's medians and files as its detail; where the plan already holds it, refresh its detail instead. It names the next release, or the one after when this chunk ships the next release's last item. On exit 1, repair what its message names and run it again; when the message names no repair, file it as a `question` item and go on. Leave the plan as it is on any other output. The chunk that ships that item runs the tool with `--reset` instead, so the next rise is measured on chunks that finished after it. ## 3. Passes