Answer principles round 1: 0 🔴, 6 🟡; average the overall over the newest scored commit's runs, re-rank through rank_todo's functions and say not to record again, tie the help to UNDER_FLOOR and FLOOR, add code health to the working loop's premises, loop-claude's first prompt and two more agents, and fix items 114, 124 and 125's details

This commit is contained in:
2026-10-18 20:29:19 +02:00
parent 3081d50f0f
commit 390d1f1f83
15 changed files with 93 additions and 42 deletions
+15 -4
View File
@@ -117,15 +117,26 @@ def latest_places(history: str) -> str | None:
def latest_overall(history: str) -> decimal.Decimal | Failure | None:
"""The overall mean of the newest scoring run, by time; None when the history holds none."""
"""The mean of the overall means of the scoring runs on the newest run's commit, since a rerun of one head measures it again; None when the history holds no run."""
runs = scoring_runs(entries(history))
if not runs:
return None
overalls = []
for run in (run for run in runs if run.commit == runs[-1].commit):
overall = run_overall(run)
if isinstance(overall, Failure):
return overall
overalls.append(overall)
return sum(overalls, decimal.Decimal(0)) / len(overalls)
def run_overall(run: Entry) -> decimal.Decimal | Failure:
"""The overall cell of a scoring run's Mean row."""
try:
overall = decimal.Decimal(overall_cells(runs[-1]).get(MEAN, ""))
overall = decimal.Decimal(overall_cells(run).get(MEAN, ""))
except decimal.InvalidOperation:
overall = None
return overall if overall is not None and overall.is_finite() else Failure(f"{HISTORY}'s newest scoring run, {runs[-1].heading}, has no Mean row ending in its overall")
return overall if overall is not None and overall.is_finite() else Failure(f"{HISTORY}'s scoring run {run.heading} has no Mean row ending in its overall")
def overall_cells(entry: Entry) -> dict[str, str]:
@@ -134,7 +145,7 @@ def overall_cells(entry: Entry) -> dict[str, str]:
def scoring_runs(found: list[Entry]) -> list[Entry]:
"""The scoring runs among the entries, oldest first."""
"""The scoring runs among the entries, oldest first. Unlike scored, it leaves out a ruling from before PR #255 that holds scoring seats' places, since such a ruling has no Mean row."""
return [entry for entry in by_time(found) if not entry.paired]
+15 -3
View File
@@ -54,16 +54,28 @@ def record_scoring(default: str, scores_file: pathlib.Path, ids: list[int]) -> F
def rerank() -> Failure | None:
"""Rank the checkout's todo.md again, since the overall sets code health's weight."""
"""Rank the checkout's todo.md again, since the overall sets code health's weight. The run stays recorded whatever happens, so a failure says to rank todo.md, not to record the run again."""
checkout = top()
if isinstance(checkout, Failure):
return checkout
todo = pathlib.Path(checkout, "todo.md")
if rank_todo.main([str(todo)]):
return Failure(f"recorded the run, but rank_todo.py exited 1 on {todo}, saying why above; settle that before committing the run")
texts = rank_todo.read_all(todo)
if isinstance(texts, Failure):
return unranked(todo, texts)
ranked = rank_todo.rank(*texts)
if isinstance(ranked, Failure):
return unranked(todo, ranked)
if ranked.text != texts[0] and (unwritten := rank_todo.write(todo, ranked.text)):
return Failure(f"recorded the run, but {unwritten.reason}; run rank_todo.py on {todo}")
for line in ranked.notes + ranked.under_bar:
print(f"{todo}: {line}")
return None
def unranked(todo: pathlib.Path, why: Failure) -> Failure:
return Failure(f"recorded the run, but rank_todo.py cannot rank {todo}: {why.reason}. Repair it and run rank_todo.py on it, not record-scoring again")
def scored_seats(given: SeatsFile) -> ScoringRun | Failure:
found = scores(given.seats)
if isinstance(found, Failure):
+17 -4
View File
@@ -438,10 +438,9 @@ class LarvReviewTool(unittest.TestCase):
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)
self.plan()
ran = self.run_tool("record-scoring", self.seats_file(f"PR #2 at {self.start}\n" + seats), "1")
# This checkout's todo.md, beside no README.md, does not rank, so the run is recorded and the re-rank fails.
self.assertEqual(ran.returncode, 1)
self.assertIn(f"recorded the run, but rank_todo.py exited 1 on {self.checkout / 'todo.md'}", ran.stderr)
self.assertEqual(ran.returncode, 0, ran.stderr)
self.assertIn("\nFloor: Locality 6.50, Self-sufficiency 6.50 under the floor of 7.0.\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()
@@ -449,12 +448,26 @@ class LarvReviewTool(unittest.TestCase):
self.assertIn("Inherited architect, would restructure first:", text)
self.assertEqual(entries(text)[0].scored_places, [Place("bin/a.py", "f")] * 4)
def test_reranks_todo_md_by_the_overall_it_records(self):
def plan(self):
"""Commit and push a README.md and a todo.md that rank, item 1 alone in release 0.1.0, as ranked before any scoring run."""
header = "| ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score |\n|---|---|---|---|---|---|---|---|---|---|---|---|\n"
# Before any scoring run code health weighs four times its weight at an overall of 7.0: 4 / 1.97 against goal 1's 0.97 / 1.97.
rows = "| 1 | 0.1.0 | | | **Read easier.** | 1 | 1 | 1 | 1 | 1 | code health by 1 | 101.5 |\n| 2 | 0.2.0 | | | **Do A.** | 1 | 1 | 1 | 1 | 1 | 1 by 1 | 24.6 |\n"
self.commit("Plan", {"README.md": "# P\n\n## Goals\n\n1. **Achieve:** A.\n", "todo.md": "# todo\n\n## Scoring\n\n`Score = 100 * V / 2**S`\n\n`Bar = 0.1`\n\n`Next ID = 3`\n\n## Items\n\n" + header + rows})
self.git("push", "-q", "origin", "HEAD:main")
def test_reports_a_plan_it_cannot_rank_yet_keeps_the_run(self):
line = "Navigation 7, Locality 7, Shape 7, Self-sufficiency 7, Overall 7"
seats = "".join(f"\n{seat}: {line}\n" for seat in ("Junior A", "Mid A", "Maintainability senior", "Inherited architect"))
# This checkout's todo.md, beside no README.md, does not rank.
ran = self.run_tool("record-scoring", self.seats_file(f"PR #2 at {self.start}\n" + seats), "1")
self.assertEqual(ran.returncode, 1)
self.assertIn(f"recorded the run, but rank_todo.py cannot rank {self.checkout / 'todo.md'}: {self.checkout / 'README.md'}: not found", ran.stderr)
self.assertIn("not record-scoring again", ran.stderr)
self.assertEqual(len(entries((self.checkout / "docs" / "comprehension-history.md").read_text())), 1)
def test_reranks_todo_md_by_the_overall_it_records(self):
self.plan()
line = "Navigation 7, Locality 7, Shape 7, Self-sufficiency 7, Overall 7"
seats = "".join(f"\n{seat}: {line}\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), "1")
+5 -1
View File
@@ -14,11 +14,15 @@ ANSWERS_RECORDED = f"every answer the human typed in it that a later chunk could
REVIEWS: tuple[tuple[str, ReviewKind], ...] = (*((f"each {agent}", kind) for kind, agent in REVIEWERS.items()), ("each comprehension seat", "seat"), ("the security pass's subagent", "security"))
# The premises rank code health, the goal every project shares, first among the goals the first prompt quotes.
AFTER_CODE_HEALTH = 'after code health (~/.claude/CLAUDE.md → "Shared goal") unless README.md voids it'
def fresh(task: str, premises: str, route: Route, anchor: Rung | None, facts: str) -> str:
"""A chunk's first prompt; facts is preflight_facts' or preflight_failed's text."""
escalated = f"{escalation(route, anchor)}{reruns(route, anchor)}".lstrip()
routed = f"{routed_by(route, anchor)}{recount(route)}\n\n" if route.item else (f"{escalated}\n\n" if escalated else "")
return f"{task}\n\nContinue any open draft PR or worktree for the chunk before creating a new one.\n\n{routed}{facts}\n\nThe chunk's todo.md items, or else the task above, set its scope. The goals below choose between ways to deliver that scope, and never widen it.\n\nFrom README.md:\n{premises}"
return f"{task}\n\nContinue any open draft PR or worktree for the chunk before creating a new one.\n\n{routed}{facts}\n\nThe chunk's todo.md items, or else the task above, set its scope. The goals below, {AFTER_CODE_HEALTH}, choose between ways to deliver that scope, and never widen it.\n\nFrom README.md:\n{premises}"
def routed_by(route: Route, anchor: Rung | None) -> str:
+4 -3
View File
@@ -3,9 +3,10 @@
usage: loop-claude <task>
Run it anywhere inside a project checkout whose README.md has ## Goals and ## Audience, the
premises; the task runs at the checkout root. Each cycle a worker runs the task. A chunk's first
worker prompt also quotes the premises, which choose between ways to deliver the chunk's todo.md
items, or else the task, and never widen them. A judge then reads the transcript's end, the
premises, which rank code health (~/.claude/CLAUDE.md → "Shared goal") first among the goals unless
README.md voids it; the task runs at the checkout root. Each cycle a worker runs the task. A chunk's
first worker prompt also quotes the premises, which choose between ways to deliver the chunk's
todo.md items, or else the task, and never widen them. A judge then reads the transcript's end, the
premises, and the records: the project's AGENTS.md and docs/decisions.md, and the human's
~/.claude/CLAUDE.md, ~/.claude/rules/*.md and
~/.claude/skills/larv-review/standards/*.md, where they exist. It rules whether the chunk, the work
+1 -1
View File
@@ -371,7 +371,7 @@ class Cycles(unittest.TestCase):
self.assertIsNone(argument(workers[1], "--name"))
self.assertEqual(argument(workers[2], "--session-id"), session)
self.assertTrue(argument(workers[0], "-p").startswith(f"{TASK}\n\nContinue any open draft PR"))
self.assertTrue(argument(workers[0], "-p").endswith("The chunk's todo.md items, or else the task above, set its scope. The goals below choose between ways to deliver that scope, and never widen it.\n\nFrom README.md:\n## Goals\n1. Work.\n\n## Audience\nMe."))
self.assertTrue(argument(workers[0], "-p").endswith("The chunk's todo.md items, or else the task above, set its scope. The goals below, " 'after code health (~/.claude/CLAUDE.md → "Shared goal") unless README.md voids it' ", choose between ways to deliver that scope, and never widen it.\n\nFrom README.md:\n## Goals\n1. Work.\n\n## Audience\nMe."))
self.assertIn("main or master", argument(workers[0], "-p"))
self.assertNotIn(TASK, argument(workers[1], "-p"))
self.assertIn("Even then, it is finished only once every answer the human typed in it", argument(workers[1], "-p"))
+14 -13
View File
@@ -4,12 +4,12 @@
usage: rank_todo.py [--check] [todo.md]
Reads todo.md (default: ./todo.md), the README.md beside it, and docs/decisions.md and
docs/comprehension-history.md when there are. Rewrites each item's Score from the formula and sorts the items by release; within a release,
question rows come first, then security rows, then the rest, each group by score from highest, then
by ID. Then it moves each blocker, an item another's Blocked by cell names, that ranks below an item
it blocks to just above the first such item. Orders the details to match. Writes each item's R, and
adds the Blocked by and R columns to a table without them. --check writes nothing and fails when the
file is not ranked as it would be.
docs/comprehension-history.md where they exist. Rewrites each item's Score from the formula and
sorts the items by release; within a release, question rows come first, then security rows, then
the rest, each group by score from highest, then by ID. Then it moves each blocker, an item
another's Blocked by cell names, that ranks below an item it blocks to just above the first such
item. Orders the details to match. Writes each item's R, and adds the Blocked by and R columns to a
table without them. --check writes nothing and fails when the file is not ranked as it would be.
A valid todo.md; ## Details and each item's detail are optional:
@@ -38,15 +38,16 @@ A valid todo.md; ## Details and each item's detail are optional:
- The formula holds numbers, + - * / ** and parentheses over L, E, I, R, S and V.
- V sums, over the goals in an item's Moves cell, each goal's weight times how far the item moves it.
README.md marks each goal **Maintain:** or **Achieve:**. The achieve goals rank code health first,
the goal every project shares, which a Moves cell names as `code health by 4`. README.md's achieve
the goal every project shares, which a Moves cell names as `code health by 6`. README.md's achieve
goals follow in reading order, a sub-goal such as 1.1 included. Each weighs 0.97 times the one
before, and the weights sum to 1. With 5 achieve goals the first weighs 0.212 and the last 0.188.
With 15 they weigh 0.082 and 0.053. Code health then weighs 4 times that while the overall of
docs/comprehension-history.md's newest scoring run is under 7.0, or there is none. A line
With 15 they weigh 0.082 and 0.053. Code health then weighs 4 times that while the overall is
under 7.0, and while docs/comprehension-history.md holds no scoring run. The overall is the mean
of the overall means of every run on the newest run's commit. A line
`**Void:** code health, since <reason>.` in README.md's ## Goals drops code health, and an item
may not name it. A project whose docs/decisions.md has a `## review opt-out:` title naming the
comprehension check must void it. Only an item marked defect may name a maintain goal, the one it restores, which
weighs as the heaviest achieve goal.
may not name it. A project must void it where its docs/decisions.md has a `## review opt-out:`
title naming the comprehension check. Only an item marked defect may name a maintain goal, the
one it restores, which weighs as the heaviest achieve goal.
- The bar is judged on the Score as shown, to one decimal.
- A new item takes Next ID, and Next ID then goes up by one; every ID stays below it.
- An item's L, E and I are levels that ~/.claude/rules/todo-items.md defines: L from 1 to 4, E from 1
@@ -320,7 +321,7 @@ def ranked_goals(readme: str, decisions: str) -> list[tuple[str, Mark]] | Failur
def weigh(lines: list[str], history: str, goals: list[tuple[str, Mark]], shape: Shape) -> dict[str, float] | Failure:
"""Each goal's weight. In OLD_SHAPE, README.md's goals weigh what todo.md states, and code health nothing. Otherwise goal_weights gives each its weight, at the overall of the history's newest scoring run where the goals hold code health."""
"""Each goal's weight. In OLD_SHAPE, README.md's goals weigh what todo.md states, and code health nothing. Otherwise goal_weights gives each its weight, at the overall latest_overall reads where the goals hold code health."""
if shape is OLD_SHAPE:
return parse_weights(lines, [number for number, _ in goals if number != CODE_HEALTH])
if WEIGHTS_HEADER in lines:
+12 -3
View File
@@ -130,6 +130,7 @@ class Rank(unittest.TestCase):
self.assertEqual((round(weights[0], 3), round(weights[-1], 3), round(sum(weights), 6)), (first, last, 1))
for figure in (rank_todo.GOAL_STEP, first, last):
self.assertIn(str(figure), rank_todo.__doc__)
self.assertIn(f"Code health then weighs {rank_todo.UNDER_FLOOR} times that while the overall is\n under {rank_todo.FLOOR},", rank_todo.__doc__)
def test_scores_an_item_by_the_weights_of_the_goals_it_moves(self):
readme = "## Goals\n\n" + VOID + "1. **Achieve:** A.\n 1. **Maintain:** B.\n 2. **Achieve:** C.\n2. **Achieve:** D.\n"
@@ -264,15 +265,23 @@ class CodeHealth(unittest.TestCase):
with self.subTest(history=history):
self.assertEqual(self.scores(history), {"| 1": "101.5", "| 2": "24.6"})
def test_weighs_by_the_newest_scoring_run_wherever_the_file_holds_it(self):
def test_weighs_by_the_newest_scored_commit_wherever_the_file_holds_it(self):
older = SCORED.format(overall="6.50").removeprefix("# Comprehension history\n\n")
newer = SCORED.format(overall="7.25").removeprefix("# Comprehension history\n\n").replace("2026-10-08", "2026-10-10")
newer = SCORED.format(overall="7.25").removeprefix("# Comprehension history\n\n").replace("2026-10-08", "2026-10-10").replace("aaaaaaa", "bbbbbbb")
for history in (f"{older}\n{newer}", f"{newer}\n{older}"):
with self.subTest(history=history):
self.assertEqual(self.scores(history)["| 1"], "25.4")
def test_weighs_by_the_mean_overall_of_every_run_on_the_newest_scored_commit(self):
first = SCORED.format(overall="7.13").removeprefix("# Comprehension history\n\n")
rerun = SCORED.format(overall="6.88").removeprefix("# Comprehension history\n\n").replace("2026-10-08T12", "2026-10-08T13").replace("PR #1 at", "PR #1 rerun at")
# 7.13 and 6.88 average 7.005, at the floor or above.
self.assertEqual(self.scores(f"{first}\n{rerun}")["| 1"], "25.4")
later = SCORED.format(overall="6.50").removeprefix("# Comprehension history\n\n").replace("2026-10-08", "2026-10-09").replace("aaaaaaa", "bbbbbbb")
self.assertEqual(self.scores(f"{first}\n{rerun}\n{later}")["| 1"], "101.5")
def test_refuses_a_newest_scoring_run_with_no_overall_mean(self):
self.assertEqual(self.scores(SCORED.format(overall="high")), Failure("docs/comprehension-history.md's newest scoring run, 2026-10-08T12:00:00Z, PR #1 at aaaaaaa, has no Mean row ending in its overall"))
self.assertEqual(self.scores(SCORED.format(overall="high")), Failure("docs/comprehension-history.md's scoring run 2026-10-08T12:00:00Z, PR #1 at aaaaaaa has no Mean row ending in its overall"))
def test_drops_code_health_where_readme_voids_it(self):
voided = "## Goals\n\n**Void:** code health, since it is a one-off script.\n\n1. **Achieve:** A.\n"