Answer architecture round 8: refuse a scoring run the plan does not call and a second entry on one read, keep a fall's scoring places apart for metric-bench, let the history format write the Ruling line, decide the fall step in a pure function, and state the base rule as the code holds it

This commit is contained in:
2026-10-09 12:29:37 +02:00
parent e694e4154e
commit 2630291af2
12 changed files with 160 additions and 111 deletions
+2 -2
View File
@@ -3,9 +3,9 @@
## Unreleased
- The stability reviewer keeps its scratch work in a directory it creates for the run, deletes that directory afterwards, and deletes nothing else.
- larv-review's mechanical rules run in the new, tested `bin/larv-review`: the paired ruling's base (`ruling-base`), each pass's round count (`round-count`), the scoring run's trigger (`needs-scoring-run <item ID>...`), and the vote count, means and history format (`record-ruling <votes file> [<scores file>]` and `record-scoring <scores file>`, which append to `docs/comprehension-history.md`; `record-scoring` prints `Floor:` naming each mean under the floor). The skill says when to run each and what its answer means. A seats file line the tool cannot read fails the run, so a mistyped vote never counts as same. The base search compares the history before and after each merged change, so it no longer depends on how a line is worded, and orders a change's rulings by their headings' times. A release whose last plan item moves to another release is due a scoring run too, once work has landed towards it. A seats file must name commits the checkout holds. When origin cannot be fetched, the tool reads it as last fetched and says so.
- larv-review's mechanical rules run in the new, tested `bin/larv-review`: the paired ruling's base (`ruling-base`), each pass's round count (`round-count`), the scoring run's trigger (`needs-scoring-run <item ID>...`), and the vote count, means and history format (`record-ruling <votes file> [<scores file>]` and `record-scoring <scores file> <item ID>...`, which append to `docs/comprehension-history.md` and refuse a second entry on the same commit; `record-scoring` refuses a run the plan does not call, and prints `Floor:` naming each mean under the floor). The skill says when to run each and what its answer means. A seats file line the tool cannot read fails the run, so a mistyped vote never counts as same. The base search compares the history before and after each merged change, so it no longer depends on how a line is worded, and orders a change's rulings by their headings' times. A release whose last plan item moves to another release is due a scoring run too, once work has landed towards it. A seats file must name commits the checkout holds. When origin cannot be fetched, the tool reads it as last fetched and says so.
- The new `bin/metric-bench` benches cheap static metrics of a project's Python against the places its comprehension history names as hardest: cognitive complexity, length, shared state and change spread, each scored by how well it ranks the named functions above the rest. No metric enters review yet.
- larv-review blocks a merge when simulated readers rule that the PR makes the project read worse than the last measured commit: the default branch's newest merged change whose last ruling in `docs/comprehension-history.md` is better, or that added a scoring run there while that ruling named no fall. A ruling of same leaves that commit in place, so a worse ruling may name places earlier chunks wrote. In each architecture pass Mid A and the inherited architect vote better, same or worse on each dimension and overall: `Navigation same, Locality worse, Shape same, Self-sufficiency same, Overall better`. When their overall votes differ, the maintainability senior and Junior A vote too. A ruling needs a lead of two or more votes, else it is same. Each place a seat names opens with the dimensions it moves, such as `Locality, Shape: `, or the run fails, and a vote that no place opens with counts as same. A dimension falls when its worse votes lead by two. When a dimension falls in a better or same ruling, `record-ruling` asks for the four scoring seats and, given their scores file, counts the ruling as worse when that dimension's mean is under the floor. A worse ruling never ships: after three rounds larv-review asks you for another round, a no leaves the PR unmerged, and so does an unattended run. The four-seat scoring run checks the comprehension floor only when a chunk ships or removes a release's last plan item, or ships an item naming the floor; between those runs, a score under the floor blocks a merge only through a fallen dimension, and that block counts as a worse ruling. On those runs, a score under the floor blocks the merge until fixed or until you decide to ship; a decision in `docs/decisions.md` that lets every chunk ship under the floor counts as yours.
- larv-review blocks a merge when simulated readers rule that the PR makes the project read worse than the last measured commit: the default branch's newest merged change that added a scoring run to `docs/comprehension-history.md`, or whose last ruling there is better. A ruling of same leaves that commit in place, so a worse ruling may name places earlier chunks wrote. In each architecture pass Mid A and the inherited architect vote better, same or worse on each dimension and overall: `Navigation same, Locality worse, Shape same, Self-sufficiency same, Overall better`. When their overall votes differ, the maintainability senior and Junior A vote too. A ruling needs a lead of two or more votes, else it is same. Each place a seat names opens with the dimensions it moves, such as `Locality, Shape: `, or the run fails, and a vote that no place opens with counts as same. A dimension falls when its worse votes lead by two. When a dimension falls in a better or same ruling, `record-ruling` asks for the four scoring seats and, given their scores file, counts the ruling as worse when that dimension's mean is under the floor. A worse ruling never ships: after three rounds larv-review asks you for another round, a no leaves the PR unmerged, and so does an unattended run. The four-seat scoring run checks the comprehension floor only when a chunk ships or removes a release's last plan item, or ships an item naming the floor; between those runs, a score under the floor blocks a merge only through a fallen dimension, and that block counts as a worse ruling. On those runs, a score under the floor blocks the merge until fixed or until you decide to ship; a decision in `docs/decisions.md` that lets every chunk ship under the floor counts as yours.
- larv-review reruns fewer passes after a fix. A fix reruns the pass whose 🔴 or 🟡 it answers, plus stability when the fix changes behaviour, security when it opens an untrusted-input boundary or touches authn/authz, secrets or crypto, and architecture when it carries an architectural decision. A rerun reviews only what changed since that pass last reviewed. A fix for a 🟢, a ❓ or any prose finding reruns no pass, and prose takes one round.
- larv-review runs one security pass on each change: the full scan alone when it runs, else `/security-review`.
- larv-review runs the new `bin/reading-cost`, 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/reading-cost.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. The chunk that ships it runs `reading-cost --reset`, so the trend counts only chunks that finished after it.
+24 -14
View File
@@ -1,4 +1,5 @@
import dataclasses
import decimal
import re
import time
@@ -18,7 +19,8 @@ MID = "Mid A"
PLACE = re.compile(r"`([^`\s]*):\d+`(?: `(\w+)`)?")
RESTRUCTURE_FIRST = "would restructure first"
RULING = re.compile(r"^Ruling: (better|same|worse)$", re.M)
SEAT_PLACES = re.compile(rf"^.+, ({DECIDED_BY}|{HARDEST_FIRST}|{RESTRUCTURE_FIRST}):$")
RULED_PLACES = re.compile(rf"^.+, {DECIDED_BY}:$")
SCORED_PLACES = re.compile(rf"^.+, ({HARDEST_FIRST}|{RESTRUCTURE_FIRST}):$")
SENIOR = "Maintainability senior"
STAMP = "%Y-%m-%dT%H:%M:%SZ"
TITLE = "# Comprehension history\n"
@@ -39,13 +41,14 @@ class Place:
@dataclasses.dataclass(frozen=True)
class Entry:
"""One paired ruling, which names the commit it was against and its ruling, or one scoring run, which names neither."""
"""One paired ruling, which names the commit it was against and its ruling, or one scoring run, which names neither. A scoring run's places, or those of the scores a fall called into a ruling, are scored_places."""
heading: str
time: str
commit: str
against: str | None
ruling: str | None
places: list[Place]
ruled_places: list[Place]
scored_places: list[Place]
@property
def paired(self) -> bool:
@@ -55,6 +58,7 @@ class Entry:
@dataclasses.dataclass(frozen=True)
class Heading:
title: str
label: str
commit: str
against: str | None
@@ -64,7 +68,7 @@ class Scoring:
"""The four scoring seats' lines, their scores as written and the means, in DIMENSIONS' order."""
seats: list[Seat]
scores: dict[str, list[str]]
means: list[str]
means: list[decimal.Decimal]
def entries(history: str) -> list[Entry]:
@@ -74,15 +78,21 @@ def entries(history: str) -> list[Entry]:
if named := HEADING.match(heading):
body = "\n".join(bodies)
ruling = RULING.search(body)
found.append(Entry(heading, named.group(1), named.group(3), named.group(4), ruling.group(1) if ruling else None, seat_places(body)))
found.append(Entry(heading, named.group(1), named.group(3), named.group(4), ruling.group(1) if ruling else None, seat_places(body, RULED_PLACES), seat_places(body, SCORED_PLACES)))
return found
def seat_places(body: str) -> list[Place]:
def recorded(history: str, read: str) -> bool:
"""Whether the history holds an entry on what a seats file's first line says the seats read."""
return any(entry.heading.partition(", ")[2] == read for entry in entries(history))
def seat_places(body: str, labels: re.Pattern[str]) -> list[Place]:
"""The places under each seat label labels matches."""
places = []
listing = False
for line in body.splitlines():
if SEAT_PLACES.match(line):
if labels.match(line):
listing = True
elif listing and line.startswith("- "):
places += bullet_places(line)
@@ -106,7 +116,7 @@ def heading(at: float, read: str, paired: bool) -> Heading | Failure:
"""An entry's heading, matched by HEADING: when the seats finished, in UTC, and what they read."""
title = f"{time.strftime(STAMP, time.gmtime(at))}, {read}"
if (named := HEADING.match(title)) and bool(named.group(4)) == paired:
return Heading(title, named.group(3), named.group(4))
return Heading(title, named.group(2), named.group(3), named.group(4))
return Failure(f"the seats file's first line is not `<PR or branch> at <commit>{', against <base>' if paired else ''}`: {read}")
@@ -116,12 +126,12 @@ def appended(history: str, entry: str) -> str:
return f"{text}\n{entry}"
def ruling_entry(title: str, seats: list[Seat], said: dict[str, list[str]], counted: dict[str, list[str]], lines: list[str], scoring: Scoring | None) -> str:
"""A paired ruling's entry, with the scoring run that decided a fall; a seat's vote that counted as same for want of a place says so."""
def ruling_entry(title: str, seats: list[Seat], said: dict[str, list[str]], counted: dict[str, list[str]], ruled: str, notes: list[str], scoring: Scoring | None) -> str:
"""A paired ruling's entry, with any notes, such as why a fall decided it, and the scores that decided a fall; a seat's vote that counted as same for want of a place says so."""
votes = [[seat.name, *map(vote_text, DIMENSIONS, said[seat.name], counted[seat.name])] for seat in seats]
tables = [[["Seat", *DIMENSIONS], *votes]] + ([scores_table(scoring)] if scoring else [])
labels = [(f"{seat.name}, {DECIDED_BY}:", seat.places) for seat in seats] + (scoring_labels(scoring.seats) if scoring else [])
return entry_text(title, lines, tables, labels)
return entry_text(title, [f"Ruling: {ruled}", *notes], tables, labels)
def vote_text(dimension: str, said: str, counted: str) -> str:
@@ -130,12 +140,12 @@ def vote_text(dimension: str, said: str, counted: str) -> str:
return f"same (voted {said}, naming no place)" if dimension == DIMENSIONS[-1] else f"same (voted {said}, no place naming {dimension})"
def scoring_entry(title: str, lines: list[str], scoring: Scoring) -> str:
return entry_text(title, lines, [scores_table(scoring)], scoring_labels(scoring.seats))
def scoring_entry(title: str, scoring: Scoring) -> str:
return entry_text(title, [], [scores_table(scoring)], scoring_labels(scoring.seats))
def scores_table(scoring: Scoring) -> list[list[str]]:
return [["Seat", *DIMENSIONS], *([seat, *values] for seat, values in scoring.scores.items()), [MEAN, *scoring.means]]
return [["Seat", *DIMENSIONS], *([seat, *values] for seat, values in scoring.scores.items()), [MEAN, *map(str, scoring.means)]]
def scoring_labels(seats: list[Seat]) -> list[tuple[str, list[str]]]:
+10 -1
View File
@@ -1,5 +1,14 @@
import dataclasses
from comprehension_history import entries, Entry
from larv_review.git import HistoryChange
@dataclasses.dataclass(frozen=True)
class HistoryChange:
"""A merged change on the default branch that touched the history, and the history before and after it."""
commit: str
before: str
after: str
def measured_commit(changes: list[HistoryChange]) -> str | None:
+1 -9
View File
@@ -1,17 +1,9 @@
import dataclasses
import re
import subprocess
from failure import Failure
from comprehension_history import HISTORY
@dataclasses.dataclass(frozen=True)
class HistoryChange:
"""A merged change on the default branch that touched the history, and the history before and after it."""
commit: str
before: str
after: str
from larv_review.base import HistoryChange
def git(*args: str) -> str | Failure:
+72 -55
View File
@@ -1,11 +1,11 @@
"""Hold larv-review's mechanical rules: the paired ruling's base and vote count, each pass's rounds, the scoring run's trigger, and the comprehension history's format.
usage: larv-review ruling-base | round-count | needs-scoring-run [<item ID>...] | record-ruling <votes file> [<scores file>] | record-scoring <scores file>
usage: larv-review ruling-base | round-count | needs-scoring-run [<item ID>...] | record-ruling <votes file> [<scores file>] | record-scoring <scores file> [<item ID>...]
Run it inside a project checkout or one of its worktrees. ruling-base, round-count and
needs-scoring-run first fetch origin, when the checkout has that remote, and take origin's default
branch, or else the local main or master, as the default branch. When the fetch fails, round-count
reads origin as last fetched and says so on stderr; the other two exit 1. The history is
Run it inside a project checkout or one of its worktrees. Each command but record-ruling first
fetches origin, when the checkout has that remote, and takes origin's default branch, or else the
local main or master, as the default branch. When the fetch fails, round-count and record-scoring
read origin as last fetched and say so on stderr; the other two exit 1. The history is
docs/comprehension-history.md in the checkout.
ruling-base prints the commit a paired ruling reads against, then which of these found it. The last
@@ -60,13 +60,15 @@ scoring seats on the same commit and run it again with their scores file. With t
ruling counts as worse when a fallen dimension's mean is under the floor of {floor}, and stands
otherwise. It prints `Ruling:` and appends the ruling, with the scores where a fall called them.
record-scoring takes the scores file of a run needs-scoring-run called, whose first line names no
`, against`. It appends the seats' scores and their means, rounded half up to two decimals, prints
the means, and prints a line opening `Floor:` that names each mean under the floor of {floor}.
record-scoring takes the scores file of a run needs-scoring-run calls, whose first line names no
`, against`, and the same item IDs, and exits 1 when they call no run: each scoring run moves the
ratchet's base. It appends the seats' scores and their means, rounded half up to two decimals,
prints the means and, when a mean is under the floor of {floor}, a line opening `Floor:` naming
each one, which blocks the merge.
Each record is appended to the history, created when missing, under a heading of the current UTC
time and the seats file's first line. Each commit that line names must be in the checkout. Each run
appends, so record a ruling or a run once.
time and the seats file's first line. Each commit that line names must be in the checkout. It exits 1
when the history already holds an entry on what that line reads.
Exit 1, saying why, on unknown arguments, an unknown item ID, a seats file it cannot read or that
breaks the shape above, or when git cannot start, finds no checkout or no default branch, cannot
@@ -79,18 +81,18 @@ import sys
import time
import typing
from comprehension_history import appended, DIMENSIONS, heading, HISTORY, ruling_entry, Scoring, scoring_entry, vote_text
from comprehension_history import appended, DIMENSIONS, heading, Heading, HISTORY, recorded, ruling_entry, Scoring, scoring_entry, vote_text
from larv_review.base import base
from larv_review.rounds import CAP, PASSES, round_counts
from larv_review.git import commit_exists, default_branch, file_at, git, history_changes, landed_since_release, top
from larv_review.ruling import counted, fallen, ruling, votes
from failure import Failure
from larv_review.scoring import fall_ruling, FLOOR, means, plan_items, scoring_run_due, under_floor
from larv_review.scoring import fall_ruling, fall_step, FLOOR, means, plan_items, scoring_run_due, under_floor
from rank_todo import ITEMS_HEADER
from file_writes import replace_file
from larv_review.seats import scores, seats_file, SeatsFile
USAGE = "usage: larv-review ruling-base | round-count | needs-scoring-run [<item ID>...] | record-ruling <votes file> [<scores file>] | record-scoring <scores file>"
USAGE = "usage: larv-review ruling-base | round-count | needs-scoring-run [<item ID>...] | record-ruling <votes file> [<scores file>] | record-scoring <scores file> [<item ID>...]"
def main(argv: list[str]) -> int:
@@ -106,10 +108,11 @@ def main(argv: list[str]) -> int:
done = with_default_branch(lambda default: needs_scoring_run(default, [int(id_) for id_ in given]), stale_ok=False)
elif command == "record-ruling" and len(given) in (1, 2):
done = record_ruling(*map(pathlib.Path, given))
elif command == "record-scoring" and len(given) == 1:
done = record_scoring(pathlib.Path(given[0]))
elif command == "needs-scoring-run":
print(f"needs-scoring-run takes item IDs, the numbers in todo.md's ID column, not {' '.join(id_ for id_ in given if not re.fullmatch(r'[0-9]+', id_))}", file=sys.stderr)
elif command == "record-scoring" and given and all(re.fullmatch(r"[0-9]+", id_) for id_ in given[1:]):
done = with_default_branch(lambda default: record_scoring(default, pathlib.Path(given[0]), [int(id_) for id_ in given[1:]]), stale_ok=True)
elif command in ("needs-scoring-run", "record-scoring") and given:
named = given[1:] if command == "record-scoring" else given
print(f"{command} takes item IDs, the numbers in todo.md's ID column, not {' '.join(id_ for id_ in named if not re.fullmatch(r'[0-9]+', id_))}; {USAGE}", file=sys.stderr)
return 1
elif not argv:
print(USAGE, file=sys.stderr)
@@ -160,6 +163,15 @@ def round_count(default: str) -> Failure | None:
def needs_scoring_run(default: str, ids: list[int]) -> Failure | None:
reasons = plan_reasons(default, ids)
if isinstance(reasons, Failure):
return reasons
print(f"Scoring run due: the chunk {' and '.join(reasons)}." if reasons else "No scoring run due.")
return None
def plan_reasons(default: str, ids: list[int]) -> list[str] | Failure:
"""Why the plan calls a scoring run, from the default branch's todo.md and the checkout's."""
checkout = top()
if isinstance(checkout, Failure):
return checkout
@@ -180,18 +192,14 @@ def needs_scoring_run(default: str, ids: list[int]) -> Failure | None:
landed = landed_since_release(default)
if isinstance(landed, Failure):
return landed
reasons = scoring_run_due(planned, chunk, ids, landed)
if isinstance(reasons, Failure):
return reasons
print(f"Scoring run due: the chunk {' and '.join(reasons)}." if reasons else "No scoring run due.")
return None
return scoring_run_due(planned, chunk, ids, landed)
def record_ruling(votes_file: pathlib.Path, scores_file: pathlib.Path | None = None) -> Failure | None:
read = read_seats(votes_file, paired=True)
if isinstance(read, Failure):
return read
title, given = read
named, given = read
said = votes(given.seats)
if isinstance(said, Failure):
return said
@@ -202,49 +210,52 @@ def record_ruling(votes_file: pathlib.Path, scores_file: pathlib.Path | None = N
print(f"Split: {tally}. Launch the maintainability senior and Junior A together, add their lines to the votes file, and run this again.")
return None
fell = fallen(count) if ruled != "worse" else []
if fell and scores_file is None:
print(f"Fell: {', '.join(fell)}, in a {ruled} ruling. Launch the four scoring seats on {given.read.partition(', against')[0]}, write their lines to a scores file, and run this again with both files.")
return None
if scores_file and not fell:
return Failure(f"no dimension fell in this {ruled} ruling, so it takes no scores file")
lines = [f"Ruling: {ruled}"]
scoring = None
notes = []
match fall_step(fell, scores_file is not None):
case "ask":
print(f"Fell: {', '.join(fell)}, in a {ruled} ruling. Launch the four scoring seats on {named.label} at {named.commit}, write their lines to a scores file, and run this again with both files.")
return None
case "refuse":
return Failure(f"no dimension fell in this {ruled} ruling, so it takes no scores file")
if scores_file:
scored = read_scoring(scores_file, given.read.partition(", against")[0])
scored = read_scoring(scores_file, named)
if isinstance(scored, Failure):
return scored
scoring = scored
ruled, why = fall_ruling(ruled, fell, [decimal.Decimal(value) for value in scoring.means])
lines = [f"Ruling: {ruled}", why]
print(f"{lines[0]}. {' '.join(lines[1:] + [f'Overall votes as counted: {tally}.'])}")
return append(ruling_entry(title, given.seats, said, count, lines, scoring))
ruled, why = fall_ruling(ruled, fell, scoring.means)
notes = [why]
print(f"Ruling: {ruled}. {' '.join(notes + [f'Overall votes as counted: {tally}.'])}")
return append(given.read, ruling_entry(named.title, given.seats, said, count, ruled, notes, scoring))
def record_scoring(scores_file: pathlib.Path) -> Failure | None:
def record_scoring(default: str, scores_file: pathlib.Path, ids: list[int]) -> Failure | None:
read = read_seats(scores_file, paired=False)
if isinstance(read, Failure):
return read
title, given = read
named, given = read
scoring = scored_seats(given)
if isinstance(scoring, Failure):
return scoring
found = [decimal.Decimal(value) for value in scoring.means]
print(f"Means: {', '.join(f'{name} {value}' for name, value in zip(DIMENSIONS, found))}.")
if under := under_floor(found):
print(f"Floor: {', '.join(under)} under the floor of {FLOOR} block the merge.")
return append(scoring_entry(title, [], scoring))
reasons = plan_reasons(default, ids)
if isinstance(reasons, Failure):
return reasons
if not reasons:
return Failure("no plan item or release calls this scoring run; name the item IDs the chunk ships, as needs-scoring-run took them, or record a fall's scores with record-ruling")
print(f"Means: {', '.join(f'{name} {value}' for name, value in zip(DIMENSIONS, scoring.means))}.")
if under := under_floor(scoring.means):
print(f"Floor: {', '.join(under)} under the floor of {FLOOR} block the merge, as the chunk {' and '.join(reasons)}.")
return append(given.read, scoring_entry(named.title, scoring))
def read_scoring(scores_file: pathlib.Path, read: str) -> Scoring | Failure:
def read_scoring(scores_file: pathlib.Path, votes: Heading) -> Scoring | Failure:
"""The scores a fall called, once their file names what the votes file read."""
try:
given = seats_file(scores_file.read_text(encoding="utf-8"))
except (OSError, UnicodeDecodeError) as failure:
return Failure(f"could not read {scores_file}: {failure}")
if isinstance(given, Failure):
return given
if given.read != read:
return Failure(f"the scores file's first line is not `{read}`, as the votes file reads: {given.read}")
read = read_seats(scores_file, paired=False)
if isinstance(read, Failure):
return read
named, given = read
if (named.label, named.commit) != (votes.label, votes.commit):
return Failure(f"the scores file's first line is not `{votes.label} at {votes.commit}`, as the votes file reads: {given.read}")
return scored_seats(given)
@@ -252,10 +263,10 @@ def scored_seats(given: SeatsFile) -> Scoring | Failure:
found = scores(given.seats)
if isinstance(found, Failure):
return found
return Scoring(given.seats, found, [str(value) for value in means(list(found.values()))])
return Scoring(given.seats, found, means(list(found.values())))
def read_seats(path: pathlib.Path, paired: bool) -> tuple[str, SeatsFile] | Failure:
def read_seats(path: pathlib.Path, paired: bool) -> tuple[Heading, SeatsFile] | Failure:
"""The seats file, and the heading its record goes under, once each commit it names is in the checkout."""
try:
given = seats_file(path.read_text(encoding="utf-8"))
@@ -268,19 +279,25 @@ def read_seats(path: pathlib.Path, paired: bool) -> tuple[str, SeatsFile] | Fail
return named
if unknown := [commit for commit in (named.commit, named.against) if commit and not commit_exists(commit)]:
return Failure(f"the seats file names {', '.join(unknown)}, which is no commit in this checkout")
return named.title, given
return named, given
def append(entry: str) -> Failure | None:
def append(read: str, entry: str) -> Failure | None:
"""Append entry unless the history already holds one on what the seats read."""
checkout = top()
if isinstance(checkout, Failure):
return checkout
history = pathlib.Path(checkout, HISTORY)
try:
text = history.read_text(encoding="utf-8") if history.exists() else ""
history.parent.mkdir(parents=True, exist_ok=True)
except (OSError, UnicodeDecodeError) as failure:
return Failure(f"could not read {history}: {failure}")
if recorded(text, read):
return Failure(f"{history} already holds an entry on {read}; record each ruling or run once")
try:
history.parent.mkdir(parents=True, exist_ok=True)
except OSError as failure:
return Failure(f"could not create {history.parent}: {failure}")
if unwritten := replace_file(history, appended(text, entry).encode()):
return Failure(f"could not write {history}: {unwritten.reason}")
print(f"Appended to {history}.")
+11 -3
View File
@@ -7,11 +7,19 @@ from rank_todo import Item, ITEMS_HEADER, parse_row, table_rows
FLOOR = decimal.Decimal("7.0")
def fall_step(fell: list[str], scored: bool) -> str:
"""What record-ruling does next: ask for the scoring seats when a dimension fell and no scores file came, refuse a scores file no fall calls, or rule."""
if fell and not scored:
return "ask"
if scored and not fell:
return "refuse"
return "rule"
def fall_ruling(ruled: str, fell: list[str], found: list[decimal.Decimal]) -> tuple[str, str]:
"""The ruling once the scoring run has scored the dimensions that fell, and the line that says why: worse when one of their means is under the floor."""
under = [f"{name} {value}" for name, value in zip(DIMENSIONS, found) if name in fell and value < FLOOR]
if under:
return "worse", f"Fell: {', '.join(fell)}, under the floor of {FLOOR} at {', '.join(under)}, so the {ruled} ruling counts as worse."
if under := [f"{name} {value}" for name, value in zip(DIMENSIONS, found) if name in fell and value < FLOOR]:
return "worse", f"Fell: {', '.join(fell)}. Under the floor of {FLOOR}: {', '.join(under)}, so the {ruled} ruling counts as worse."
return ruled, f"Fell: {', '.join(fell)}, each at or above the floor of {FLOOR}, so the {ruled} ruling stands."
+6 -5
View File
@@ -3,9 +3,10 @@
usage: metric-bench [history]
history defaults to docs/comprehension-history.md in the checkout it runs in, and the bench reads
the checkout that holds the history. For each scoring run in it, at the commit the panel read, it
measures each module-level function and each method of a module-level class in the Python files git
tracks, leaving out test_*.py, *_test.py and anything under a tests/ folder:
the checkout that holds the history. For each scoring run in it, those a fall called inside a paired
ruling included, at the commit the panel read, it measures each module-level function and each
method of a module-level class in the Python files git tracks, leaving out test_*.py, *_test.py and
anything under a tests/ folder:
- cognitive complexity: SonarSource's white paper, read for Python;
- length: lines;
@@ -81,7 +82,7 @@ def bench_runs(text: str, top: str) -> tuple[list[tuple[str, RunScores]], list[s
"""Each scored run's heading and scores, and a note for each run skipped or not scored and each file left out."""
rows = []
notes = []
for run in [entry for entry in entries(text) if not entry.paired]:
for run in [entry for entry in entries(text) if entry.scored_places or not entry.paired]:
if isinstance(missing := git(["cat-file", "-e", f"{run.commit}^{{commit}}"], top), Failure):
notes.append(f"Skipped, its commit is not in {top}: {run.heading} ({missing.reason})")
continue
@@ -121,7 +122,7 @@ def run_scores(run: Entry, top: str) -> tuple[RunScores | None, list[str]] | Fai
log = git(["-c", "core.quotePath=false", "log", "--no-merges", "--format=tformat:@@", "--name-only", run.commit], top)
if isinstance(log, Failure):
return log
places, dropped = resolved(run.places, tracked)
places, dropped = resolved(run.scored_places, tracked)
return bench(units, places, len(set(dropped)), co_changed(log)), unparsed
+29 -15
View File
@@ -9,12 +9,11 @@ import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
from comprehension_history import appended, entries, Place, ruling_entry, Scoring, Seat
from larv_review.base import base, first_ruling, measured_commit
from comprehension_history import appended, entries, Place, recorded, ruling_entry, Scoring, Seat
from larv_review.base import base, first_ruling, HistoryChange, measured_commit
from larv_review.ruling import counted, fallen, ruling, votes
from failure import Failure
from larv_review.scoring import fall_ruling, means, plan_items, scoring_run_due, under_floor
from larv_review.git import HistoryChange
from larv_review.scoring import fall_ruling, fall_step, means, plan_items, scoring_run_due, under_floor
from test_loop_claude_black_box import host_env
from rank_todo import Item
from larv_review.rounds import round_counts
@@ -116,15 +115,17 @@ class History(unittest.TestCase):
def test_reads_back_what_it_writes(self):
seats = [Seat("Mid A", said("better", "worse"), ["`bin/a.py:3` `f`: hard, with `:9` `g`"]), Seat("Inherited architect", said("worse", "worse"), [])]
written = {"Mid A": ["same", "worse", "same", "same", "better"], "Inherited architect": ["same", "worse", "same", "same", "worse"]}
scoring = Scoring([Seat("Junior A", "", ["`bin/b.py:4` `h`: long"])], {"Junior A": ["7", "6.5", "7", "7", "7"]}, ["7.00", "6.50", "7.00", "7.00", "7.00"])
ruled = ruling_entry("2026-10-08T18:37:21Z, PR #2 at bbbbbbb, against aaaaaaa", seats, written, {**written, "Inherited architect": ["same"] * 5}, ["Ruling: worse", "Fell: Locality, under the floor."], scoring)
scoring = Scoring([Seat("Junior A", "", ["`bin/b.py:4` `h`: long"])], {"Junior A": ["7", "6.5", "7", "7", "7"]}, [decimal.Decimal(mean) for mean in ("7.00", "6.50", "7.00", "7.00", "7.00")])
ruled = ruling_entry("2026-10-08T18:37:21Z, PR #2 at bbbbbbb, against aaaaaaa", seats, written, {**written, "Inherited architect": ["same"] * 5}, "worse", ["Fell: Locality, under the floor."], scoring)
history = appended(appended("", SCORING), ruled)
self.assertTrue(history.startswith("# Comprehension history\n\n## 2026-10-08T12:00:00Z"))
self.assertNotIn("Inherited architect, decided by:", history)
self.assertIn("| Inherited architect | same | same (voted worse, no place naming Locality) | same | same | same (voted worse, naming no place) |", history)
found = entries(history)
self.assertEqual([(entry.commit, entry.against, entry.ruling) for entry in found], [("aaaaaaa", None, None), ("bbbbbbb", "aaaaaaa", "worse")])
self.assertEqual(found[1].places, [Place("bin/a.py", "f"), Place("bin/a.py", "g"), Place("bin/b.py", "h")])
self.assertEqual((found[1].ruled_places, found[1].scored_places), ([Place("bin/a.py", "f"), Place("bin/a.py", "g")], [Place("bin/b.py", "h")]))
self.assertTrue(recorded(history, "PR #2 at bbbbbbb, against aaaaaaa"))
self.assertFalse(recorded(history, "PR #2 at bbbbbbb"))
self.assertIn("| Mean | 7.00 | 6.50 | 7.00 | 7.00 | 7.00 |\n\nMid A, decided by:", history)
self.assertEqual([entry.paired for entry in found], [False, True])
@@ -132,9 +133,12 @@ class History(unittest.TestCase):
class FallRuling(unittest.TestCase):
def test_counts_a_ruling_worse_when_a_fallen_dimensions_mean_is_under_the_floor(self):
found = [decimal.Decimal(score) for score in ("6", "6.5", "7", "6", "6")]
self.assertEqual(fall_ruling("better", ["Locality", "Shape"], found), ("worse", "Fell: Locality, Shape, under the floor of 7.0 at Locality 6.5, so the better ruling counts as worse."))
self.assertEqual(fall_ruling("better", ["Locality", "Shape"], found), ("worse", "Fell: Locality, Shape. Under the floor of 7.0: Locality 6.5, so the better ruling counts as worse."))
self.assertEqual(fall_ruling("same", ["Shape"], found), ("same", "Fell: Shape, each at or above the floor of 7.0, so the same ruling stands."))
def test_asks_for_scores_on_a_fall_refuses_them_without_one_and_rules_otherwise(self):
self.assertEqual([fall_step(["Locality"], False), fall_step([], True), fall_step(["Locality"], True), fall_step([], False)], ["ask", "refuse", "rule", "rule"])
class Base(unittest.TestCase):
def test_takes_the_newest_change_adding_a_scoring_run_or_ending_on_a_better_ruling(self):
@@ -147,6 +151,8 @@ class Base(unittest.TestCase):
worse_last = HistoryChange("worse", SCORING, SCORING + paired("2026-10-08T13:00:00Z", "better") + paired("2026-10-08T14:00:00Z", "worse"))
self.assertEqual(measured_commit([worse_last, older]), "old")
self.assertIsNone(measured_commit([same]))
scored_fall = HistoryChange("same fell", SCORING, SCORING + paired("2026-10-08T13:00:00Z", "same\n\nFell: Locality, each at or above the floor.\n\n| Seat | Overall |\n|---|---|\n| Mean | 7.00 |"))
self.assertEqual(measured_commit([scored_fall, older]), "old")
def test_falls_back_to_the_first_rulings_base_then_to_none(self):
ruled = paired("2026-10-08T13:00:00Z", "worse")
@@ -282,7 +288,7 @@ class LarvReviewTool(unittest.TestCase):
self.assertEqual(ran.stdout.splitlines()[0], "Ruling: same. Overall votes as counted: Mid A worse, Inherited architect same, Maintainability senior worse, Junior A same (voted worse, naming no place).")
recorded = entries(history.read_text())
self.assertEqual([(entry.commit, entry.against, entry.ruling) for entry in recorded], [(self.start, self.start, "same")])
self.assertEqual(recorded[0].places, [Place("bin/a.py", "f")] * 2)
self.assertEqual(recorded[0].ruled_places, [Place("bin/a.py", "f")] * 2)
self.assertIn("| Junior A | same | same | same | same | same (voted worse, naming no place) |", history.read_text())
def test_asks_for_the_scoring_seats_when_a_dimension_falls_and_rules_with_their_scores(self):
@@ -297,13 +303,17 @@ class LarvReviewTool(unittest.TestCase):
scores_text = f"PR #2 at {self.start}\n" + "".join(f"\n{seat}: {line}\n\n- `bin/b.py:4` `h`: long\n" for seat in ("Junior A", "Mid A", "Maintainability senior", "Inherited architect"))
ruled = self.run_tool("record-ruling", votes_file, self.seats_file(scores_text, "scores.md"))
self.assertEqual(ruled.returncode, 0, ruled.stderr)
self.assertTrue(ruled.stdout.startswith("Ruling: worse. Fell: Locality, under the floor of 7.0 at Locality 6.50, so the better ruling counts as worse."))
self.assertTrue(ruled.stdout.startswith("Ruling: worse. Fell: Locality. Under the floor of 7.0: Locality 6.50, so the better ruling counts as worse."))
again = self.run_tool("record-ruling", votes_file, self.seats_file(scores_text, "scores.md"))
self.assertIn("already holds an entry on", again.stderr)
recorded = entries(history.read_text())
self.assertEqual([entry.ruling for entry in recorded], ["worse"])
self.assertIn("| Mean | 7.00 | 6.50 | 7.00 | 7.00 | 7.00 |", history.read_text())
votes_file = self.seats_file(pathlib.Path(votes_file).read_text().replace("PR #2", "PR #3"), "votes.md")
scores_text = scores_text.replace("PR #2", "PR #3")
stands = self.run_tool("record-ruling", votes_file, self.seats_file(scores_text.replace("Locality 6.5", "Locality 7"), "scores.md"))
self.assertTrue(stands.stdout.startswith("Ruling: better. Fell: Locality, each at or above the floor of 7.0, so the better ruling stands."), stands.stderr)
other = self.run_tool("record-ruling", votes_file, self.seats_file(scores_text.replace("PR #2", "PR #3"), "scores.md"))
other = self.run_tool("record-ruling", votes_file, self.seats_file(scores_text.replace("PR #3", "PR #4"), "scores.md"))
self.assertIn("the scores file's first line is not", other.stderr)
def test_names_no_fall_on_a_worse_ruling_and_takes_no_scores_file_without_one(self):
@@ -311,19 +321,23 @@ class LarvReviewTool(unittest.TestCase):
ran = self.run_tool("record-ruling", self.seats_file(f"PR #2 at {self.start}, against {self.start}\n\nMid A: {said('worse', 'worse')}{place}Inherited architect: {said('worse', 'worse')}{place}"))
self.assertEqual(ran.returncode, 0, ran.stderr)
self.assertNotIn("Fell:", ran.stdout + (self.checkout / "docs" / "comprehension-history.md").read_text())
extra = self.run_tool("record-ruling", self.seats_file(f"PR #2 at {self.start}, against {self.start}\n\nMid A: {said('worse')}{place}Inherited architect: {said('worse')}{place}"), self.seats_file("PR #2", "scores.md"))
extra = self.run_tool("record-ruling", self.seats_file(f"PR #3 at {self.start}, against {self.start}\n\nMid A: {said('worse')}{place}Inherited architect: {said('worse')}{place}"), self.seats_file("PR #2", "scores.md"))
self.assertIn("takes no scores file", extra.stderr)
def test_records_a_scoring_run_with_its_means(self):
line = "Navigation 7, Locality 6.5, Shape 7, Self-sufficiency 6.5, Overall 7"
seats = "".join(f"\n{seat}: {line}\n\n- `bin/a.py:3` `f`: long\n" for seat in ("Junior A", "Mid A", "Maintainability senior", "Inherited architect"))
ran = self.run_tool("record-scoring", self.seats_file(f"PR #2 at {self.start}\n" + seats))
uncalled = self.run_tool("record-scoring", self.seats_file(f"PR #2 at {self.start}\n" + seats))
self.assertEqual(uncalled.returncode, 1)
self.assertIn("no plan item or release calls this scoring run", uncalled.stderr)
ran = self.run_tool("record-scoring", self.seats_file(f"PR #2 at {self.start}\n" + seats), "1")
self.assertEqual(ran.returncode, 0, ran.stderr)
self.assertIn("\nFloor: Locality 6.50, Self-sufficiency 6.50 under the floor of 7.0 block the merge.\n", ran.stdout)
self.assertIn("\nFloor: Locality 6.50, Self-sufficiency 6.50 under the floor of 7.0 block the merge, as the chunk leaves release 0.1.0 with no plan item.\n", ran.stdout)
self.assertIn("not /", self.run_tool("record-scoring", "1", self.seats_file(f"PR #2 at {self.start}\n" + seats)).stderr)
text = (self.checkout / "docs" / "comprehension-history.md").read_text()
self.assertIn("| Mean | 7.00 | 6.50 | 7.00 | 6.50 | 7.00 |", text)
self.assertIn("Inherited architect, would restructure first:", text)
self.assertEqual(entries(text)[0].places, [Place("bin/a.py", "f")] * 4)
self.assertEqual(entries(text)[0].scored_places, [Place("bin/a.py", "f")] * 4)
def test_refuses_a_ruling_file_that_names_no_base_or_a_commit_the_checkout_lacks(self):
ran = self.run_tool("record-ruling", self.seats_file(f"PR #2 at {self.start}\n\nMid A: {said('same')}\n\nInherited architect: {said('same')}\n"))
+1 -1
View File
@@ -144,7 +144,7 @@ class Places(unittest.TestCase):
def test_reads_each_scoring_runs_places_and_leaves_paired_rulings_out(self):
runs = [entry for entry in entries(self.HISTORY) if not entry.paired]
self.assertEqual([(run.heading, run.commit) for run in runs], [("2026-10-08T12:50:49Z, PR #224 at a58a0a8", "a58a0a8")])
self.assertEqual(runs[0].places, [Place("skills/x/SKILL.md", None), Place("bin/tool/cycle/states.py", "transition"), Place("cycle/run.py", "step"), Place("cycle/run.py", "close"), Place("bin/tool/cycle/judge.py", "run_judge")])
self.assertEqual(runs[0].scored_places, [Place("skills/x/SKILL.md", None), Place("bin/tool/cycle/states.py", "transition"), Place("cycle/run.py", "step"), Place("cycle/run.py", "close"), Place("bin/tool/cycle/judge.py", "run_judge")])
def test_resolves_a_shortened_path_to_the_file_nearest_the_one_before_it(self):
tracked = ["bin/tool/cycle/states.py", "bin/tool/cycle/run.py", "bin/other/cycle/run.py"]
+2 -2
View File
@@ -67,9 +67,9 @@ lilleman decided to ship each of these under the floor on the day listed. Each l
## review: a paired ruling against the last measured commit decides the ratchet, and counts as worse when a dimension it rules fallen is under the floor; the four-seat scoring run checks the floor when a release's items run out or an item names the floor, and also runs when a ruling names a fallen dimension
2026-10-08, lilleman. Serves goals 1.1 and 1.4. Two independent four-seat runs moved up to 0.4 on near-identical code, so a fall within that noise forced rounds that changed nothing (PR #224). A seat reading both versions judges the difference on the same material, so the noise the versions share cancels. No conventional significance level lets a sign test settle with four votes, so the human chose a lead of two votes over every other ruling, same included. Two seats that agree settle it, so a PR that leaves the reading as it was costs two seats. A third seat alone can never settle it, so the third and fourth launch together. The base is the default branch's newest merged change whose last added paired ruling is better, or that adds a scoring run to the history while that ruling names no fall. The human chose the last measured commit on the architect's finding that with a merge base as the base, chunks without an architecture pass, and a suspended restructure's steps, could each lower comprehension unseen. A ruling of same leaves the base where it was, or a run of small falls each ruled same would add up unseen. A scoring run moves it too: otherwise a project never ruled better would compare against its first ruling forever, and a release's floor check is where the human sees the absolute level. Reading the default branch one merged change at a time keeps the rule working for merge commits and squash merges alike: a branch's own early ruling of better never counts, only the merged change's last ruling. The scoring run also runs on a chunk shipping an item that names the floor, so the chunk that lifts a project to the floor can prove it. A chunk that removes a release's last item without shipping it runs it too, so no release ends unmeasured. Valid while seats reading both versions agree more often than two absolute runs do.
2026-10-08, lilleman. Serves goals 1.1 and 1.4. Two independent four-seat runs moved up to 0.4 on near-identical code, so a fall within that noise forced rounds that changed nothing (PR #224). A seat reading both versions judges the difference on the same material, so the noise the versions share cancels. No conventional significance level lets a sign test settle with four votes, so the human chose a lead of two votes over every other ruling, same included. Two seats that agree settle it, so a PR that leaves the reading as it was costs two seats. A third seat alone can never settle it, so the third and fourth launch together. The base is the default branch's newest merged change that adds a scoring run to the history, or whose last added paired ruling is better. The human chose the last measured commit on the architect's finding that with a merge base as the base, chunks without an architecture pass, and a suspended restructure's steps, could each lower comprehension unseen. A ruling of same leaves the base where it was, or a run of small falls each ruled same would add up unseen. A scoring run moves it too: otherwise a project never ruled better would compare against its first ruling forever, and a release's floor check is where the human sees the absolute level. Reading the default branch one merged change at a time keeps the rule working for merge commits and squash merges alike: a branch's own early ruling of better never counts, only the merged change's last ruling. The scoring run also runs on a chunk shipping an item that names the floor, so the chunk that lifts a project to the floor can prove it. A chunk that removes a release's last item without shipping it runs it too, so no release ends unmeasured. Valid while seats reading both versions agree more often than two absolute runs do.
2026-10-09, lilleman: each seat also rules each dimension, and a dimension falls by the same lead of two. A better or same ruling naming a fallen dimension calls the scoring run, and counts as worse when that dimension's mean is under the floor, so between releases a project cannot trade one dimension below the floor for gains in the other three. The four scoring seats' scores go into the ruling itself, which `record-ruling` decides in one call, so no command reads a fall another command recorded. Those scores block on the fallen dimensions alone, the floor's own block staying with a release's end and an item naming the floor, and they leave the base where the ruling leaves it: a run of falls each ruled same must not add up unseen. A dimension's vote counts only where one of the seat's places opens with that dimension, so a fall rests on places the seats name.
2026-10-09, lilleman: each seat also rules each dimension, and a dimension falls by the same lead of two. A better or same ruling naming a fallen dimension calls the scoring run, and counts as worse when that dimension's mean is under the floor, so between releases a project cannot trade one dimension below the floor for gains in the other three. The four scoring seats' scores go into the ruling itself, which `record-ruling` decides in one call, so no command reads a fall another command recorded. Those scores block on the fallen dimensions alone, the floor's own block staying with a release's end and an item naming the floor, and they leave the base where the ruling leaves it: a run of falls each ruled same must not add up unseen. PR #232's own history holds one fall-called scoring run recorded on its own, before this rule; it moves the base like any scoring run, which is safe under it, since a later fall of a dimension under the floor is always caught. A dimension's vote counts only where one of the seat's places opens with that dimension, so a fall rests on places the seats name.
## review: a project decision may suspend the comprehension check for the plan items it names
+1 -1
View File
@@ -97,7 +97,7 @@ Then the comprehension check: simulated readers, launched per `~/.claude/skills/
- **Seats.** Mid A and the inherited architect. Write what they read and their replies into a votes file in your scratchpad, in the shape `~/.claude/bin/larv-review --help` shows, and run `~/.claude/bin/larv-review record-ruling <votes file>`. On `Split:`, launch the maintainability senior and Junior A together, add their lines, and run it again. On `Fell:`, launch the four scoring seats, below, on the same commit, write their lines into a scores file, and run `record-ruling <votes file> <scores file>`.
- **Ruling.** The `Ruling:` line `record-ruling` prints and appends to the history.
**Scoring run**, when `~/.claude/bin/larv-review needs-scoring-run <the IDs of the items the chunk ships, if any>` prints `Scoring run due:`. Run `needs-scoring-run` before removing the chunk's items from `todo.md`. Junior A, Mid A, the maintainability senior and the inherited architect each score the project at the head from 1 to 10 overall and on four dimensions: Navigation, Locality, Shape and Self-sufficiency. Write their lines into a scores file and run `~/.claude/bin/larv-review record-scoring <scores file>`, which appends the run to the history and prints the four seats' means.
**Scoring run**, when `~/.claude/bin/larv-review needs-scoring-run <the IDs of the items the chunk ships, if any>` prints `Scoring run due:`. Run `needs-scoring-run` before removing the chunk's items from `todo.md`. Junior A, Mid A, the maintainability senior and the inherited architect each score the project at the head from 1 to 10 overall and on four dimensions: Navigation, Locality, Shape and Self-sufficiency. Write their lines into a scores file and run `~/.claude/bin/larv-review record-scoring <scores file> <the same item IDs>`, which appends the run to the history and prints the four seats' means. Where a fall's scores file already read the head, run `record-scoring` on that file.
The chunk does not merge while either holds:
+1 -3
View File
@@ -66,8 +66,7 @@ Raised by the principles audit of PR #215 against KISS, in `principles/technical
PR #225's last run, at 8c9bf09, put Locality at 6.75 and Self-sufficiency and the overall at 6.88. Its seats named: the judge's policy spread over `loop/main.py`'s docstring, `cycle/judge_reply.py`'s `JUDGE_RULES`, `cycle/judge.py`'s `judge_prompt` and `cycle/worker.py`'s `worker_args`; `loop_claude/claude_code/` and the read side of `transcript_archive.py`, which `bin/reading_cost/` also imports; two meanings of a checkout's root in `project/checkout.py`'s `checkout_root` and `reading_cost/main.py`'s `located`; and `skills/larv-review/SKILL.md` §3's round count, which only prose enforces.
2026-10-09, from the same studies: give the judge's contract one home. `cycle/judge.py` takes `judge_reply.py`'s rules, schema and `verdict_from`; `QUOTE_SOURCES`, `ANSWER_DESTINATIONS` and `ANSWERS_RECORDED` move to `project/records.py`, so `worker.py` imports the records, not the judge; `states.py`'s two `Judging` cases get exclusive guards, so their order carries no meaning. PR #232's scoring run at 324d650 put Locality at 6.50.
2026-10-09, from two architecture studies on PR #232: give the judge's contract one home. `cycle/judge.py` takes `judge_reply.py`'s rules, schema and `verdict_from`; `QUOTE_SOURCES`, `ANSWER_DESTINATIONS` and `ANSWERS_RECORDED` move to `project/records.py`, so `worker.py` imports the records, not the judge; `states.py`'s two `Judging` cases get exclusive guards, so their order carries no meaning. PR #232's scoring run at 324d650 put Locality at 6.50.
### 21. Give `settings.json`'s model one writer, and sort its keys.
@@ -95,7 +94,6 @@ Raised by the principles audit of PR #224. The `settings.json` decision is valid
Raised by the architect on PR #225 and by the inherited architect of PR #224's scoring run: `bin/` is one flat folder of tools, the modules they share and the repo's checks, with `loop_claude`'s tests beside them instead of beside the package. `loop_claude/claude_code/` parses Claude Code's own formats and `bin/reading_cost/measure.py` imports it too, so it is a package of its own.
2026-10-09, from two architecture studies on PR #232: lift `loop_claude/claude_code/` and the archive's layout out of `loop_claude/` into packages of their own, `claude_code/` and `transcript_archive/`, so `reading_cost` imports no tool. `transcript_archive` takes the write side (`archive`), the read side (`finished_chunks`, `FinishedChunk`, the stamps) and one `project_archive(checkout_root, home, env)` that both tools call, which derives the archive key one way, as item 5 asks. Move each tool's tests beside its package, and `test_loop_claude_black_box.host_env`, which three other tools' tests import, into a test helper of its own.
### 5. Key a project on its checkout's full path, and refuse to start while another session uses that key.