Answer principles round 1: 0 🔴, 4 🟡 (0 misread); drop typing.cast and subTest loops from new code, state the price list's two uses, record the subTest decision

This commit is contained in:
2026-11-12 20:18:54 +01:00
parent 95fb0d03cf
commit 7e29dc0014
12 changed files with 71 additions and 29 deletions
+1 -1
View File
@@ -134,7 +134,7 @@ Install puts only `loop-claude` and `loop-inbox` on `PATH`; call the others by t
- `loop_state/` holds the files loop-claude and loop-inbox share: the question files (`waiting/`), the files a running loop lists itself in (`running_loops.py`, `session_lock.py`), their paths, and `hand_over.py`, which opens claude for `/talk`. A change to any of them changes both tools.
- `machine_load/` takes the machine's heavy slots, its shared lock files, for `run_heavy`, and reads the memory share that loop-claude waits for. It also gives `mutate_changes` a slot's CPU count.
- `mattermost_dm/` sends the human a Mattermost DM, for `mattermost-dm` and for loop-claude through `loop_effects`.
- `model_routing/` holds the routing ladder, which loop-claude, `rule_hook`, both replay tools and `subagent-rung` read.
- `model_routing/` holds the routing ladder, which loop-claude, `rule_hook`, both replay tools and `subagent-rung` read, and the list prices, which `transcript_archive` and `routing_figures` read.
- `rank_todo.py`, `settings_filter.py` and `statusline.py` are tools of one file each, tested beside them.
- `records/` reads a Markdown file's `##` sections, quotes a passage and joins names into a list, stamps times in UTC, and replaces a file in one step, private where it is new.
- `release_plan/` reads `todo.md`'s items table and release versions, says which release is next and whether it is ready to cut (`release_standing.py`), and ranks the plan (`ranking.py`, with its score formula in `formula.py` and its blocker order in `blockers.py`). `plan_file.py` reads, ranks, checks and writes a `todo.md`, for `larv_review`, `rank_todo.py`, `rule_hook` and `todo_item`.
+29 -6
View File
@@ -176,12 +176,35 @@ class Command(typing.NamedTuple):
ids_from: int | None = None
ITEM_ID = re.compile(r"[0-9]+")
def no_arguments(given: list[str]) -> bool:
return not given
def are_ids(given: list[str]) -> bool:
return all(re.fullmatch(r"[0-9]+", id_) for id_ in given)
return all(ITEM_ID.fullmatch(id_) for id_ in given)
def run_needs_scoring_run(given: list[str]) -> Failure | None:
return with_default_branch(lambda default: needs_scoring_run(default, [int(id_) for id_ in given]), stale_ok=False)
def fits_prepare_scoring(given: list[str]) -> bool:
return not given or len(given) == 2 and given[0] == "--preloaded"
def run_record_scoring(given: list[str]) -> Failure | None:
return with_default_branch(lambda default: record_scoring(default, pathlib.Path(given[0]), [int(id_) for id_ in given[1:]]), stale_ok=False)
def fits_reviewer_header(given: list[str]) -> bool:
return bool(given) and given[0] in REVIEWERS and given[1:] in ([], ["--rerun"])
def run_reviewer_header(given: list[str]) -> Failure | None:
return with_default_branch(lambda default: reviewer_header(default, given[0], given[1:] == ["--rerun"]), stale_ok=True)
# One row per subcommand, in the order the usage line and the docstring above list them: main, USAGE and `--help` all read this table.
@@ -189,14 +212,14 @@ COMMANDS = {
"review-folder": Command("review-folder", no_arguments, lambda given: make_review_folder()),
"ruling-base": Command("ruling-base", no_arguments, lambda given: with_default_branch(show_ruling_base, stale_ok=False)),
"round-count": Command("round-count", no_arguments, lambda given: with_default_branch(round_count, stale_ok=True)),
"needs-scoring-run": Command("needs-scoring-run [<item ID>...]", are_ids, lambda given: with_default_branch(lambda default: needs_scoring_run(default, [int(id_) for id_ in given]), stale_ok=False), ids_from=0),
"needs-scoring-run": Command("needs-scoring-run [<item ID>...]", are_ids, run_needs_scoring_run, ids_from=0),
"scoring-run-owed": Command("scoring-run-owed", no_arguments, lambda given: with_default_branch(owed, stale_ok=False)),
"record-ruling": Command("record-ruling <votes file>", lambda given: len(given) == 1, lambda given: record_ruling(pathlib.Path(given[0]))),
"prepare-scoring": Command("prepare-scoring [--preloaded <text>]", lambda given: not given or len(given) == 2 and given[0] == "--preloaded", lambda given: prepared_scoring(given[1] if given else None)),
"record-scoring": Command("record-scoring <scores file> [<item ID>...]", lambda given: bool(given) and are_ids(given[1:]), lambda given: with_default_branch(lambda default: record_scoring(default, pathlib.Path(given[0]), [int(id_) for id_ in given[1:]]), stale_ok=False), ids_from=1),
"prepare-scoring": Command("prepare-scoring [--preloaded <text>]", fits_prepare_scoring, lambda given: prepared_scoring(given[1] if given else None)),
"record-scoring": Command("record-scoring <scores file> [<item ID>...]", lambda given: bool(given) and are_ids(given[1:]), run_record_scoring, ids_from=1),
"places": Command("places", no_arguments, lambda given: show_places()),
"agreement": Command("agreement", no_arguments, lambda given: show_agreement()),
"reviewer-header": Command("reviewer-header <pass> [--rerun]", lambda given: given[:1] != [] and given[0] in REVIEWERS and given[1:] in ([], ["--rerun"]), lambda given: with_default_branch(lambda default: reviewer_header(default, given[0], given[1:] == ["--rerun"]), stale_ok=True)),
"reviewer-header": Command("reviewer-header <pass> [--rerun]", fits_reviewer_header, run_reviewer_header),
"reviewer-context": Command("reviewer-context", no_arguments, lambda given: printed(hook_reply(sys.stdin.read(), pathlib.Path.home()))),
}
SHAPES = " | ".join(command.shape for command in COMMANDS.values())
@@ -214,7 +237,7 @@ def main(argv: list[str]) -> int:
command = COMMANDS.get(name)
if command and command.fits(given):
done = command.run(given)
elif command and command.ids_from is not None and (named := [id_ for id_ in given[command.ids_from:] if not re.fullmatch(r"[0-9]+", id_)]):
elif command and command.ids_from is not None and (named := [id_ for id_ in given[command.ids_from:] if not ITEM_ID.fullmatch(id_)]):
print(f"{name} takes item IDs, the numbers in todo.md's ID column, not {' '.join(named)}; {USAGE}", file=sys.stderr)
return 1
else:
+12 -7
View File
@@ -872,15 +872,20 @@ class LarvReviewTool(unittest.TestCase):
def test_review_folder_takes_no_arguments(self):
self.assertIn("unknown arguments", self.run_tool("review-folder", "x").stderr)
def test_names_the_arguments_that_are_not_item_ids(self):
for args, named in ((("needs-scoring-run", "3", "x"), "x"), (("record-scoring", "scores.md", "4", "y1"), "y1")):
with self.subTest(args=args):
ran = self.run_tool(*args)
self.assertEqual(ran.returncode, 1)
self.assertIn(f"takes item IDs, the numbers in todo.md's ID column, not {named};", ran.stderr)
def assert_names_the_non_id(self, named, *args):
ran = self.run_tool(*args)
self.assertEqual(ran.returncode, 1)
self.assertIn(f"takes item IDs, the numbers in todo.md's ID column, not {named};", ran.stderr)
def test_needs_scoring_run_names_the_argument_that_is_not_an_item_id(self):
self.assert_names_the_non_id("x", "needs-scoring-run", "3", "x")
def test_record_scoring_names_the_argument_after_its_file_that_is_not_an_item_id(self):
self.assert_names_the_non_id("y1", "record-scoring", "scores.md", "4", "y1")
def test_help_and_the_usage_line_list_the_same_commands(self):
listed = self.run_tool("--help").stdout.splitlines()[2].removeprefix("usage: larv-review ").split(" | ")
usage = next(line for line in self.run_tool("--help").stdout.splitlines() if line.startswith("usage: larv-review "))
listed = usage.removeprefix("usage: larv-review ").split(" | ")
self.assertEqual([shape.split()[0] for shape in listed], ["review-folder", "ruling-base", "round-count", "needs-scoring-run", "scoring-run-owed", "record-ruling", "prepare-scoring", "record-scoring", "places", "agreement", "reviewer-header", "reviewer-context"])
self.assertIn(f"usage: larv-review {' | '.join(listed)}", self.run_tool().stderr)
+5 -5
View File
@@ -32,11 +32,11 @@ class ScoreBullets(unittest.TestCase):
with_extra = skill.replace("## The score\n\n", "## The score\n\n- A bullet before the anchors.\n\n", 1)
self.assertEqual(score_bullets(with_extra), score_bullets(skill))
def test_fails_where_an_anchor_or_a_dimension_is_missing(self):
skill = SKILL.read_text()
for dropped in ("- **10 — Duress-proof.**", "- **Shape** —"):
with self.subTest(dropped=dropped):
self.assertIsInstance(score_bullets(skill.replace(dropped, "- Dropped:", 1)), Failure)
def test_fails_where_an_anchor_is_missing(self):
self.assertIsInstance(score_bullets(SKILL.read_text().replace("- **10 — Duress-proof.**", "- Dropped:", 1)), Failure)
def test_fails_where_a_dimension_is_missing(self):
self.assertIsInstance(score_bullets(SKILL.read_text().replace("- **Shape** —", "- Dropped:", 1)), Failure)
def test_fails_where_a_fifth_dimension_is_added(self):
skill = SKILL.read_text()
+1 -1
View File
@@ -46,7 +46,7 @@ def moment(stamp: str) -> datetime.datetime:
return datetime.datetime.fromisoformat(stamp)
# An outcome's stamp runs to the second, so a message written earlier in that second would count in both stretches. In practice none is, since the judge runs for seconds after the worker's last message.
# An outcome's stamp runs to the second, so a message written earlier in that second would count in both stretches. The worker writes none then, since the judge runs for seconds after its last message; a subagent or a /talk session still running may, which overcounts that message once.
def later(timestamp: str, start: datetime.datetime) -> bool:
"""Whether timestamp is after start; False where it is no time, or names no time zone to compare by."""
try:
-1
View File
@@ -26,7 +26,6 @@ from loop_claude.stop import Stop
from loop_claude.direct_message import tell
def main(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launcher: pathlib.Path, cwd: pathlib.Path, effects: Effects) -> int:
try:
stop = run_loop(argv, env, paths, launcher, cwd, effects)
+2 -2
View File
@@ -1,4 +1,4 @@
"""What a message costs at list prices: the weights that split a chunk's recorded cost between its messages."""
"""What a message costs at list prices. The weights that split a chunk's recorded cost between its messages, and the prices a Spent block records beside what a stretch spent, so a price wrong here stays wrong in every outcome written after it."""
import dataclasses
from claude_code.tokens import tokens_of
@@ -20,7 +20,7 @@ class Price:
return self.input * 2
# Anthropic's list prices as the claude-api skill lists them (cached 2026-10-06, and Fable 5.2's on 2026-11-03), with Opus 5.5's cache prices from `docs/decisions.md` → `loop-claude: the worker's claude compacts…`. Haiku 5.5's cache read is assumed at a tenth of its input, and its dearer prompts above 200k tokens are left out. Where a chunk records its cost, only the proportions between one model's messages matter, so these may be a little off.
# Anthropic's list prices as the claude-api skill lists them (cached 2026-10-06, and Fable 5.2's on 2026-11-03), with Opus 5.5's cache prices from `docs/decisions.md` → `loop-claude: the worker's claude compacts…`. Haiku 5.5's cache read is assumed at a tenth of its input, and its dearer prompts above 200k tokens are left out. Keep each price current with that list: the prices are archived as the ones in force.
PRICES = {
# Archived chunks that ran on Fable 5.1 are still priced from here.
"claude-fable-5-1": Price(10, 0.25, 50),
-2
View File
@@ -8,8 +8,6 @@ from reading_cost.shell_reads import Reads, shell_reads
from command_lines.shell_command import resolved, simple_commands
@dataclasses.dataclass(frozen=True)
class Reading:
"""What the worker and its subagents took in before the worker's first commit: tokens counts the new input tokens, and files counts how often each tracked file was opened or searched, by its path in the checkout."""
+2
View File
@@ -1,4 +1,6 @@
import pathlib
# Each module here checks a convention of the repo's files, as a linter does: import order, citations, CI, settings. So it reads source or Markdown, which technical-principles.md bans in a test of a unit's behaviour.
# The checkout root.
ROOT = pathlib.Path(__file__).resolve().parents[2]
+13 -3
View File
@@ -24,9 +24,19 @@ def compared(reviewed: str, project: Rung, chosen: list[Round], found_on: typing
return found
runs.append(found)
# A failed replay found nothing, which would lower the bar where it had CLAUDE.md and count as misses where it had none.
kept = [(one, *found) for one, *found in zip(chosen, *runs) if not any(isinstance(each, Failure) for each in found)]
first, second, third, without = ([typing.cast(set[int], found[run]) for _, *found in kept] for run in range(4))
return comparison(reviewed, project, [one for one, *_ in kept], (first, second, third), without, len(chosen) - len(kept))
kept = rounds_without_failure(chosen, runs)
first, second, third, without = ([found[run] for _, found in kept] for run in range(4))
return comparison(reviewed, project, [one for one, _ in kept], (first, second, third), without, len(chosen) - len(kept))
def rounds_without_failure(chosen: list[Round], runs: list[list[set[int] | Failure]]) -> list[tuple[Round, list[set[int]]]]:
"""Each round of chosen that no run failed on, with what each run found in it."""
kept = []
for one, *found in zip(chosen, *runs):
finds = [each for each in found if not isinstance(each, Failure)]
if len(finds) == len(found):
kept.append((one, finds))
return kept
def comparison(reviewed: str, reference: Rung, rounds: list[Round], with_it: tuple[list[set[int]], list[set[int]], list[set[int]]], without: list[set[int]], left_out: int) -> str:
+1 -1
View File
@@ -61,7 +61,7 @@ def annotation_lines(annotation: Annotation) -> str:
# Nothing reads a Spent block yet: the first tool that derives dollars from one adds its parser here, beside this writer.
def spent_block(since: str, found: dict[Spender, Tokens]) -> str:
"""The archive's block for what the stretch spent, then the list prices in force for each model in it; empty where nothing was spent."""
"""The archive's block for what the stretch spent, then the list prices in force for each model in it that has one; empty where nothing was spent."""
if not found:
return ""
spenders = [f"- {name}, {model}: {', '.join(map(str, (tokens.input, tokens.write_5m, tokens.write_1h, tokens.read, tokens.output)))}" for (name, model), tokens in found.items()]
+5
View File
@@ -12,6 +12,7 @@ Each project principle states one rule that the decisions below apply; their ent
# Decisions no project principle covers
- bin/: a test parametrizes its cases with `subTest`, since pytest's `parametrize` doesn't reach a unittest `TestCase`
- bin/: the tools run on the host's Python, with no container, and so do their tests outside CI
- bin/: the tools support only the latest stable Python, and the tests, written in plain unittest, run on it in four pytest-xdist workers
- deploy: this repo keeps no `AGENTS.md`, since `~/.claude` is its checkout; its principles and decision titles head `docs/decisions.md`, its working rules follow them there, and its `.claude/settings.json` excludes every `.claude/CLAUDE.md`, so a session in the clone loads only the clone's `CLAUDE.md`
@@ -49,6 +50,10 @@ Settling a call is the human's. The chunk that settles the calls cites, in `docs
# Decisions
## bin/: a test parametrizes its cases with `subTest`, since pytest's `parametrize` doesn't reach a unittest `TestCase`
2026-11-12, lilleman, from the release review of 0.9.0. Applies `principles/technical-principles.md` → "Most code should have automated tests", whose "parametrize the cases" asks for one reported result per case. The tests are plain unittest, run by pytest, and pytest's `parametrize` doesn't work on a `TestCase` method; `subTest` is the unittest mechanism that does: each case reports and fails on its own, with its parameters named. A test body that loops over its cases for another reason, or holds a branch, is still a breach. Valid while the tests stay in plain unittest.
## bin/: an outcome is an entry of a `.outcomes.md` file in loop-claude's archive, a record is a document tools or people keep entries in, and a place is what a comprehension seat names
2026-10-23, larv-review, through PR #367. Serves code health: a reader can trust that one word names one thing in every tool. Before, "record" and "outcome" each named different things in three modules, and "place" in two. Each word kept the meaning it already had where renaming costs most: