Answer architecture round 1: 0 🔴, 8 🟡; read old routes' rungs, write R in rank_todo, route reviews through review_rungs, file item 168

This commit is contained in:
2026-10-16 12:11:25 +02:00
parent 149108e8d8
commit 12909f233d
20 changed files with 141 additions and 94 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ It first replays every verdict on the reference judge: the model at xhigh effort
judge ran on before loop-claude routed it. A verdict the reference judge returns another kind on
may rest on records or judge rules that have changed since; either way no rung is held to it. It
then replays the rest on each candidate rung, highest first: from the model's cheapest rung down
to the rung the lowest L picks for a worker. It stops at the first rung that misses one. It prints each
to the ladder's bottom rung. It stops at the first rung that misses one. It prints each
verdict the reference judge did not reproduce, each verdict a rung missed, and the lowest rung
that, like each rung above it, missed none. A rung it names is the evidence to add the model to
JUDGE_REPLAYED in bin/loop_claude/routing.py, which routes that model's judge, and to record the
+25 -15
View File
@@ -1,4 +1,4 @@
from model_routing.ladder import climbed, LADDER, position, review_rung, reviewers_rung, ReviewKind, Rung
from model_routing.ladder import climbed, LADDER, position, review_rungs, ReviewKind, Rung
from model_routing.route import ESCALATION_MARKER, Route
from loop_claude.routing import escalation_rungs
from loop_claude.project.records import HUMAN_RULE_NAMES, RECORD_FILES
@@ -14,6 +14,8 @@ QUOTE_SOURCES = either(("README.md's Goals and Audience", *RECORD_FILES, *HUMAN_
# Where the worker may write an answer the human typed, so it counts as recorded.
ANSWER_DESTINATIONS = "README.md's Goals or Audience, " + ", ".join(RECORD_FILES) + ", todo.md or a comment"
ANSWERS_RECORDED = f"every answer the human typed in it that a later chunk could need is recorded in {ANSWER_DESTINATIONS} at the one place it governs"
# Each kind of review, as review_launches names those it launches.
REVIEWS: tuple[tuple[str, ReviewKind], ...] = (("each reviewer", "reviewer"), ("each comprehension seat", "seat"), ("the security pass's subagent", "security"))
def fresh(task: str, premises: str, route: Route, anchor: Rung | None) -> str:
@@ -27,24 +29,33 @@ def routed_by(route: Route, anchor: Rung | None) -> str:
def review_launches(route: Route, anchor: Rung | None) -> str:
"""Which reviews to launch on a rung other than the worker's, and on which; below the project's rung, anchor, also where to launch a subagent that plans. Empty off the ladder, and where every review runs on the worker's rung."""
"""Which reviews to launch on a rung other than the worker's, and on which; below the project's rung, anchor, also where to launch a subagent that plans. Empty off the ladder, and where every review runs on the worker's rung.
For a worker on Sonnet 5.5 at high, on an Opus 5.5 project, routed by item 3 of E + I 5, it opens: ` Launch each reviewer with the Agent tool set to model opus, effort high, the rung item 3's E + I of 5 picks. Launch each comprehension seat and the security pass's subagent with the Agent tool set to model opus, effort medium, the project's rung.`
"""
if anchor is None:
return ""
reviewers = reviewers_rung(anchor, route.rung, route.escape_and_impact)
# The seats score every chunk on one rung, and the security pass spends no more than the project chose. Where the reviewers' rung is anchor too, anchor's name wins.
named = {reviewers: f"the rung item {route.item}'s E + I of {route.escape_and_impact} picks", anchor: "the project's rung"}
rungs = review_rungs(anchor, route.rung, route.escape_and_impact)
launched: dict[Rung, list[str]] = {}
kinds: tuple[tuple[str, ReviewKind], ...] = (("each reviewer", "reviewer"), ("each comprehension seat and the security pass's subagent", "seat"))
for reviews, kind in kinds:
rung = review_rung(kind, anchor, reviewers)
if rung != route.rung:
launched.setdefault(rung, []).append(reviews)
launches = "".join(f" Launch {', '.join(reviews)} with the Agent tool set to {rung.agent_args()}, {named[rung]}." for rung, reviews in launched.items())
scan = " Run a full scan only from such a subagent, since the scan's agents run on the model that starts them." if anchor != route.rung else ""
for reviews, kind in REVIEWS:
if rungs[kind] != route.rung:
launched.setdefault(rungs[kind], []).append(reviews)
launches = "".join(f" Launch {listed(reviews)} with the Agent tool set to {rung.agent_args()}, {rung_named(rung, route, anchor)}." for rung, reviews in launched.items())
scan = " Run a full scan only from such a subagent, since the scan's agents run on the model that starts them." if rungs["security"] != route.rung else ""
planning = f" Your rung is below the project's: launch each subagent that files or scores todo.md items on the rung `~/.claude/bin/subagent-rung --plan {anchor.model} <L>` prints." if position(route.rung) < position(anchor) else ""
return f"{launches}{scan}{planning}"
def listed(names: list[str]) -> str:
"""The names as `a, b and c`."""
return names[0] if len(names) == 1 else f"{', '.join(names[:-1])} and {names[-1]}"
def rung_named(rung: Rung, route: Route, anchor: Rung) -> str:
"""Why a review runs on rung: it is the project's, anchor, or the one the route's item's E + I picks."""
return "the project's rung" if rung == anchor else f"the rung item {route.item}'s E + I of {route.escape_and_impact} picks"
def escalation(route: Route, anchor: Rung | None) -> str:
"""The prompt's escalation sentences, the marker's among them. Empty off the ladder or on its top rung. Where escalation_rungs opens none, the worker escalates only with the human's yes.
Else they name the rungs escalation_rungs opens to a subagent, and offer to resume the worker one rung up for the rest of the chunk, up to the highest of those rungs."""
@@ -63,9 +74,8 @@ def reruns(route: Route, anchor: Rung | None) -> str:
"""The prompt's sentence naming the rung one above a reviewer's and a seat's, on which each reruns when it asks; empty off the ladder, and leaving out one already on the top rung."""
if anchor is None or route.rung not in LADDER:
return ""
# The rungs review_launches launches them on.
reviewers = reviewers_rung(anchor, route.rung, route.escape_and_impact)
launched = (("reviewer", review_rung("reviewer", anchor, reviewers)), ("comprehension seat", review_rung("seat", anchor, reviewers)))
rungs = review_rungs(anchor, route.rung, route.escape_and_impact)
launched = (("reviewer", rungs["reviewer"]), ("comprehension seat", rungs["seat"]))
rerun = {name: climbed(rung, 1) for name, rung in launched if rung != LADDER[-1]}
if not rerun:
return ""
+5 -5
View File
@@ -45,10 +45,10 @@ Where that model is on the routing ladder (bin/model_routing/ladder.py), the wor
interrupt run on one of the ladder's rungs: a model at an effort. As a chunk starts, todo.md's top
item in the next release that does not wait routes it: an item waits while it is marked question,
or while an item that blocks it is still in the table. The item's L picks the worker's rung,
counted from the model's cheapest rung, and an L of 2 or less picks a rung below it; without such
an item, or with no L, the chunk runs on the model's cheapest rung. The item's E + I picks the
reviewers' rung, never below the worker's or the cheapest rung, and an E + I of 5 or more picks a
rung above the cheapest. The worker's first prompt names the rung and the item, and asks the worker to
stepping from the model's cheapest rung by WORKER_STEPS in bin/model_routing/ladder.py, below it
for a low L; without such an item, or with no L, the chunk runs on the model's cheapest rung. The
item's E + I picks the reviewers' rung, stepping up from the cheapest rung by REVIEW_STEPS there,
never below the worker's rung. The worker's first prompt names the rung and the item, and asks the worker to
name each item the chunk takes, with its L and E + I. The prompt has the worker launch each review
that runs on a rung other than its own on that rung: the reviewers on theirs, and each
comprehension seat and the security pass on the cheapest rung. Below the cheapest rung, it has the
@@ -115,7 +115,7 @@ Exit 1, saying why, when:
worker fails when claude cannot start, exits non-zero, is killed, or ends without a result event;
a judge when claude cannot start, exits non-zero or prints no json reply, or its reply misses or
mistypes a field, interrupts or quotes an answer without a question, gives an unfinished verdict
an L outside 0 to 4, or quotes a passage the transcript does not hold; it holds an elided
an L off its scale, or quotes a passage the transcript does not hold; it holds an elided
passage when each fragment appears in order.
A usage limit is not a failure, and restarts the count of three: the worker or the judge is
retried 2 minutes after the limit resets, or every 10 minutes when the reset time is unknown or
+1 -1
View File
@@ -62,7 +62,7 @@ def escalation_cap(anchor: Rung, route: Route) -> Rung:
def stepped(anchor: Rung, route: Route, bundled: int, escalated: bool) -> Route:
"""The route after one more unfinished verdict, never on a lower rung.
"""The route after one more unfinished verdict. Its rules, in order: the rung never falls below kept_rung; a bundled item lifts it to the rung that item's L picks; every second unfinished verdict steps it up one rung; so does an escalation the judge found, up to escalation_cap, two rungs above item_rung; and both steps on one verdict make one step.
bundled and escalated are the verdict's fields, not the verdict, since loop_claude.cycle.judge imports this module through prompts.
"""
+1 -1
View File
@@ -979,7 +979,7 @@ class JudgeFailures(unittest.TestCase):
("verdict_from", 'f"the judge\'s reply has no {name}', field),
("verdict_from", "'the judge interrupted without a question'", unasked),
("verdict_from", "'the judge quoted an answer without a question'", unasked),
("verdict_from", 'f"the judge\'s bundled L', "gives an unfinished verdict an L outside 0 to 4"),
("verdict_from", 'f"the judge\'s bundled L', "gives an unfinished verdict an L off its scale"),
("run_judge", "f'{verdict.reason}; it replied:", field),
("run_judge", "f'the judge quoted {verdict.evidence!r}, which is not in the transcript", "quotes a passage the transcript does not hold"),
("claude_reply", "f'could not start claude:", started),
+14 -13
View File
@@ -70,19 +70,19 @@ def project_rung(model: str) -> Rung | None:
return next((rung for rung in LADDER if rung.model == model), None)
def worker_rung(anchor: Rung, likelihood: int) -> Rung:
"""The rung a task's L picks for its worker from anchor, the project's rung, stopping at either end of the ladder."""
return climbed(anchor, WORKER_STEPS[likelihood])
def worker_rung(project: Rung, likelihood: int) -> Rung:
"""The rung a task's L picks for its worker, counted from the project's rung, stopping at either end of the ladder."""
return climbed(project, WORKER_STEPS[likelihood])
def floored(anchor: Rung, likelihood: int) -> Rung:
"""The rung a task's L picks from anchor, the project's rung, never below anchor."""
return highest(anchor, worker_rung(anchor, likelihood))
def planning_rung(project: Rung, likelihood: int) -> Rung:
"""The rung of a task that files or scores todo.md items: the one its L picks, never below the project's rung."""
return highest(project, worker_rung(project, likelihood))
def review_floor(anchor: Rung, escape_and_impact: int) -> Rung:
"""The rung a task's E + I picks for a review from anchor, the project's rung, never below anchor. An E + I of 0, for no task, picks anchor."""
return climbed(anchor, REVIEW_STEPS.get(escape_and_impact, 0))
def review_floor(project: Rung, escape_and_impact: int) -> Rung:
"""The rung a task's E + I picks for a review, counted up from the project's rung. An E + I of 0, for no task, picks the project's rung."""
return climbed(project, REVIEW_STEPS.get(escape_and_impact, 0))
def stepped_up(rung: Rung) -> Rung:
@@ -90,13 +90,14 @@ def stepped_up(rung: Rung) -> Rung:
return climbed(rung, 1)
def reviewers_rung(project: Rung, worker: Rung, escape_and_impact: int) -> Rung:
"""The rung a chunk's reviewers run on: the higher of the worker's rung and the one its item's E + I picks, which is never below the project's."""
return highest(worker, review_floor(project, escape_and_impact))
def review_rungs(project: Rung, worker: Rung, escape_and_impact: int) -> dict[ReviewKind, Rung]:
"""The rung each kind of review in a chunk runs on, where its worker runs on worker and its item has that E + I. The reviewers run on the higher of the worker's rung and review_floor's."""
reviewers = highest(worker, review_floor(project, escape_and_impact))
return {kind: review_rung(kind, project, reviewers) for kind in typing.get_args(ReviewKind)}
def review_rung(kind: ReviewKind, project: Rung, reviewers: Rung) -> Rung:
"""The rung a review runs on: a reviewer on reviewers, which reviewers_rung picks; a seat or the security pass on the project's."""
"""The rung a review of kind runs on: a reviewer on the reviewers' rung; a seat or the security pass on the project's, so the seats score every chunk on one rung, and the security pass spends no more than the project chose."""
return reviewers if kind == "reviewer" else project
+17 -6
View File
@@ -3,12 +3,13 @@ import dataclasses
import re
from todo_table import LEVELS
from model_routing.ladder import Rung, WORKER_STEPS
from model_routing.ladder import Rung
# How a worker opens the prompt of a subagent it escalates a task to, `Escalation trigger 2: …`: docs/decisions.md → `routing: a worker hands a task one rung up`.
ESCALATION_MARKER = "Escalation trigger"
# A line an older loop-claude wrote, naming an R + C, reads as no route, so its chunk routes afresh.
ROUTED = re.compile(r"(?P<rung>.+?)(?:, routed by item (?P<item>[0-9]+)'s L of (?P<likelihood>[0-9]+) and E \+ I of (?P<escape_and_impact>[0-9]+))?")
# An archived worker line: the rung, then the item and the levels that routed it, if any. resume reads only LEVELS_ROUTED's levels, so a line an older loop-claude wrote, naming an R + C, routes its chunk afresh; the figures still read its rung.
ROUTED = re.compile(r"(?P<rung>.+?)(?:, routed by item (?P<item>[0-9]+)'s (?P<levels>.+))?")
LEVELS_ROUTED = re.compile(r"L of (?P<likelihood>[0-9]+) and E \+ I of (?P<escape_and_impact>[0-9]+)")
@dataclasses.dataclass(frozen=True)
@@ -29,14 +30,24 @@ class Route:
def route_from(worker: str) -> Route | None:
"""The route an archived worker line names; None for a model run off the ladder, or levels off their scales."""
"""The route an archived worker line names; None for a model run off the ladder, or a route by anything but levels on their scales."""
found = ROUTED.fullmatch(worker)
rung = Rung.parse(found["rung"]) if found else None
if not found or not rung:
return None
if not found["item"]:
return Route(rung)
likelihood, escape_and_impact = int(found["likelihood"]), int(found["escape_and_impact"])
if likelihood not in WORKER_STEPS or not 2 <= escape_and_impact <= LEVELS["E"] + LEVELS["I"]:
levels = LEVELS_ROUTED.fullmatch(found["levels"])
if not levels:
return None
likelihood, escape_and_impact = int(levels["likelihood"]), int(levels["escape_and_impact"])
if not 1 <= likelihood <= LEVELS["L"] or not 2 <= escape_and_impact <= LEVELS["E"] + LEVELS["I"]:
return None
return Route(rung, int(found["item"]), likelihood, escape_and_impact)
def archived_rung(worker: str) -> tuple[Rung, bool] | None:
"""The rung an archived worker line names, and whether an item routed it, whatever the route names after the rung; None for a model run off the ladder."""
found = ROUTED.fullmatch(worker)
rung = Rung.parse(found["rung"]) if found else None
return (rung, bool(found["item"])) if found and rung else None
+15 -8
View File
@@ -4,7 +4,8 @@ import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from model_routing.ladder import floored, highest, LADDER, project_rung, review_floor, review_rung, reviewers_rung, Rung, stepped_up, worker_rung
from model_routing.ladder import highest, LADDER, planning_rung, project_rung, review_floor, review_rung, review_rungs, Rung, stepped_up, worker_rung, WORKER_STEPS
from todo_table import LEVELS
OPUS = Rung("claude-opus-5-5", "medium")
@@ -38,9 +39,12 @@ class Ladder(unittest.TestCase):
self.assertEqual(stepped_up(LADDER[-1]), LADDER[-1])
self.assertEqual(stepped_up(OPUS), Rung("claude-opus-5-5", "high"))
def test_floors_the_workers_picked_rung_at_the_projects_rung(self):
self.assertEqual(floored(OPUS, 1), OPUS)
self.assertEqual(floored(OPUS, 4), Rung("claude-opus-5-5", "high"))
def test_steps_a_worker_for_every_level_on_ls_scale(self):
self.assertEqual(set(WORKER_STEPS), set(range(1, LEVELS["L"] + 1)))
def test_plans_on_the_rung_l_picks_but_never_below_the_projects(self):
self.assertEqual(planning_rung(OPUS, 1), OPUS)
self.assertEqual(planning_rung(OPUS, 4), Rung("claude-opus-5-5", "high"))
def test_names_each_rung_by_a_family_the_agent_tool_takes(self):
self.assertEqual({rung.agent_args().split(",")[0] for rung in LADDER}, {"model haiku", "model sonnet", "model opus", "model fable"})
@@ -87,10 +91,13 @@ class Ladder(unittest.TestCase):
def test_puts_reviewers_on_the_highest_of_the_projects_rung_the_workers_and_the_one_e_plus_i_picks(self):
haiku, fable = LADDER[4], LADDER[-1]
self.assertEqual(reviewers_rung(OPUS, haiku, 4), OPUS)
self.assertEqual(reviewers_rung(OPUS, haiku, 5), Rung("claude-opus-5-5", "high"))
self.assertEqual(reviewers_rung(OPUS, fable, 5), fable)
self.assertEqual(reviewers_rung(OPUS, Rung("claude-opus-5-5", "high"), 7), Rung("claude-opus-5-5", "max"))
self.assertEqual(review_rungs(OPUS, haiku, 4)["reviewer"], OPUS)
self.assertEqual(review_rungs(OPUS, haiku, 5)["reviewer"], Rung("claude-opus-5-5", "high"))
self.assertEqual(review_rungs(OPUS, fable, 5)["reviewer"], fable)
self.assertEqual(review_rungs(OPUS, Rung("claude-opus-5-5", "high"), 7)["reviewer"], Rung("claude-opus-5-5", "max"))
def test_keeps_the_seats_and_the_security_pass_on_the_projects_rung_whatever_the_worker_or_e_plus_i(self):
self.assertEqual(review_rungs(OPUS, LADDER[-1], 8), {"reviewer": LADDER[-1], "seat": OPUS, "security": OPUS})
def test_holds_a_reviewer_to_the_reviewers_rung_and_anything_else_to_the_projects(self):
fable = LADDER[-1]
+2 -2
View File
@@ -3,7 +3,7 @@
loop-claude sets these variables for its worker and for the claude an interrupt resumes; a human's shell does not, and rule-hook then checks no review launch."""
import typing
from model_routing.ladder import LADDER, reviewers_rung, Rung
from model_routing.ladder import LADDER, review_rungs, Rung
from model_routing.route import Route
PROJECT_RUNG = "LOOP_CLAUDE_PROJECT_RUNG"
@@ -13,7 +13,7 @@ REVIEWER_RUNG = "LOOP_CLAUDE_REVIEWER_RUNG"
def environment(project: Rung | None, route: Route) -> dict[str, str]:
"""The variables a worker's claude on route starts with. A project off the ladder gets empty project and reviewer rungs, so none is inherited from the environment."""
reviewers = reviewers_rung(project, route.rung, route.escape_and_impact) if project else None
reviewers = review_rungs(project, route.rung, route.escape_and_impact)["reviewer"] if project else None
return {PROJECT_RUNG: str(project) if project else "", WORKER_RUNG: str(route.rung), REVIEWER_RUNG: str(reviewers) if reviewers else ""}
+15 -16
View File
@@ -76,7 +76,7 @@ import re
import sys
import typing
from todo_table import BLOCKED_BY, cells, HEADER_START, Item, items_table, MOVES, OLD_SHAPE, parse_row, Shape, SHAPE, shape_of, Table, table_rows
from todo_table import BLOCKED_BY, cells, HEADER_START, Item, items_table, MOVES, OLD_SHAPE, parse_row, risk, Shape, SHAPE, shape_of, Table, table_rows
from failure import Failure
from markdown_text import FENCE, sections
from file_writes import replace_file
@@ -290,31 +290,29 @@ def read_table(lines: list[str]) -> Table | Failure:
return Failure(f"## Items holds no table whose header opens {HEADER_START}; rank_todo.py --help shows a valid one")
if isinstance(table, Failure):
return table
# A table without its shape's risk scores fails, so no chunk starts on an unscored item.
if shape_of(table.columns) is OLD_SHAPE and "C" not in table.columns:
return Failure("todo.md's items table has no C column; add one after S, and score each item's C from 1 to 10 per rank_todo.py --help")
if shape_of(table.columns) is SHAPE and not {"L", "E", "I"} <= set(table.columns):
old = older_columns(table)
shape = shape_of(table.columns)
if missing := [column for column in shape.risk_columns if column not in table.columns]:
old = older_columns(table, shape)
dropped = f", and drop {joined(old)}" if old else ""
return Failure(f"todo.md's items table has no L, E and I columns; add them before R, score each item's L, E and I as rank_todo.py --help shows{dropped}")
return unknown_columns(table) or outside_items(lines, table) or table
columns = f"{joined(missing)} column; add it" if len(missing) == 1 else f"{joined(missing)} columns; add them"
return Failure(f"todo.md's items table has no {columns}, scoring each item's {joined(list(shape.risk_columns))} as rank_todo.py --help shows{dropped}")
return unknown_columns(table, shape) or outside_items(lines, table) or table
def unknown_columns(table: Table) -> Failure | None:
def unknown_columns(table: Table, shape: Shape) -> Failure | None:
"""Why ranking, which writes only the columns of the table's shape, would drop one of the table's columns; None when it would drop none."""
known = shape_of(table.columns).columns
unknown = [column for column in table.columns if column not in known]
if old := older_columns(table):
unknown = [column for column in table.columns if column not in shape.columns]
if old := older_columns(table, shape):
kind = "a column of an older shape; drop it" if len(old) == 1 else "columns of an older shape; drop them"
return Failure(f"todo.md's items table has {joined(old)}, {kind}, as rank_todo.py --help shows")
if unknown:
return Failure(f"todo.md's items table has the column {', '.join(unknown)}, which this rank_todo.py does not know; the columns it knows are {', '.join(known)}. Rename it, or move this machine to the release that added it")
return Failure(f"todo.md's items table has the column {', '.join(unknown)}, which this rank_todo.py does not know; the columns it knows are {', '.join(shape.columns)}. Rename it, or move this machine to the release that added it")
return None
def older_columns(table: Table) -> list[str]:
def older_columns(table: Table, shape: Shape) -> list[str]:
"""The table's columns that only OLD_SHAPE knows, where the table is in SHAPE."""
return [column for column in table.columns if column not in SHAPE.columns and column in OLD_SHAPE.columns] if shape_of(table.columns) is SHAPE else []
return [column for column in table.columns if column not in SHAPE.columns and column in OLD_SHAPE.columns] if shape is SHAPE else []
def joined(names: list[str]) -> str:
@@ -569,7 +567,8 @@ def parse_item(row: str, scoring: Scoring, table: Table) -> Item | Failure:
return Failure(f"item {item.id} cites goal {goal}, which README.md's ## Goals does not number")
if scoring.goals[goal] == "Maintain" and item.exempt != "defect":
return Failure(f"item {item.id} cites goal {goal}, a maintain goal, which only a defect that restores it may name; name the achieve goals the item moves")
return item
# R is written here, as the Score is, so --check finds a stale one, and a reader keeps the R the table stored.
return dataclasses.replace(item, scores=item.scores | {"R": risk(item.scores["L"], item.scores["E"], item.scores["I"])})
def render_item(item: Item, value: float, shape: Shape) -> str:
+5 -5
View File
@@ -5,9 +5,9 @@ import re
import statistics
import typing
from model_routing.route import archived_rung, ESCALATION_MARKER
from claude_code.entries import assistant_parts, parts, tool_call, usage_count
from git_command import commits
from model_routing.route import ESCALATION_MARKER, route_from
from model_routing.ladder import position, Rung
from round_titles import round_counts
from shell_command import simple_commands
@@ -91,10 +91,10 @@ def measured(chunk: Chunk, home: str) -> ChunkFigures:
reports[kind] = reports.get(kind, Reports(0, 0, 0)) + Reports(1, len(reported.get(subagent.launched_by, "")), sum(map(len, results(subagent.entries).values())))
for _, tools, spent in spend(subagent.entries):
add(tokens, chunk.project, kind, rung, tools, spent)
start = route_from(cycles[0][1]) if cycles else None
start = archived_rung(cycles[0][1]) if cycles else None
return ChunkFigures(
tokens=tokens,
start=start.rung if start and start.item else None,
start=start[0] if start and start[1] else None,
rounds_past_first=rounds_past_first(chunk.worker, home),
unfinished=sum(len(UNFINISHED_AT.findall(kept)) for kept in chunk.outcomes),
delegated=delegated,
@@ -133,8 +133,8 @@ def rung_at(cycles: list[tuple[str, str]], timestamp: str) -> Rung | str:
"""The rung of the cycle running at timestamp: the worker named by the first outcome stamped at or after it, or else by the last outcome. A worker off the ladder is returned as its text."""
second = timestamp[:19] + "Z"
found = next((rung for stamp, rung in cycles if stamp >= second), cycles[-1][1] if cycles else "unrouted")
route = route_from(found)
return route.rung if route else found
route = archived_rung(found)
return route[0] if route else found
def subagent_rung(entries: list[dict], arguments: dict, worker: Rung | str) -> Rung:
@@ -84,6 +84,13 @@ class Measured(unittest.TestCase):
worker = [commit("m1", "Answer stability round 1: 1 🔴, 0 🟡"), commit("m2", "Answer stability round 2: 0 🔴, 0 🟡"), commit("m3", "Answer stability round 2: 0 🔴, 0 🟡"), commit("m4", "Answer prose round 1: 0 🔴, 1 🟡")]
self.assertEqual(measured(Chunk("log", [], worker, []), "/h").rounds_past_first, 1)
def test_reads_the_rung_of_a_route_an_older_loop_claude_archived_by_r_plus_c(self):
older = f"{LOW}, routed by item 7's R + C of 9"
kept = stamped("2026-10-14T10:00:00Z", outcomes.finished(older, "m", "j"))
found = measured(Chunk("log", [kept], [message("m1", "2026-10-14T09:00:00Z")], []), "/h")
self.assertEqual(found.start, LOW)
self.assertEqual(found.tokens["rung"], {str(LOW): 111})
def test_starts_no_route_for_a_chunk_no_item_routed(self):
kept = stamped("2026-10-14T10:00:00Z", outcomes.finished(str(LOW), "m", "j"))
found = measured(Chunk("log", [kept], [message("m1", "2026-10-14T09:00:00Z")], []), "/h")
+3 -3
View File
@@ -3,7 +3,7 @@ import pathlib
import sys
from failure import Failure
from model_routing.ladder import LADDER, position, project_rung, Rung, worker_rung
from model_routing.ladder import LADDER, position, project_rung, Rung
from claude_code.reply import Limited
from loop_claude.project.model_choice import read_models_file
from loop_claude.stop import Stop
@@ -28,8 +28,8 @@ def projects_on(model: str, home: pathlib.Path) -> list[str] | Failure:
def down_from(top: Rung) -> list[Rung]:
"""top and each rung below it, down to the rung the lowest L picks for a worker from top, highest first."""
return list(LADDER[position(worker_rung(top, 1)):position(top) + 1])[::-1]
"""top and each rung below it, down to the ladder's bottom, highest first. A replay stops at the first rung that misses, so a low rung is replayed only where every rung above it passed."""
return list(LADDER[:position(top) + 1])[::-1]
def limited_exit(tool: str, limited: Limited) -> int:
+3 -2
View File
@@ -63,8 +63,9 @@ class FirstReply(unittest.TestCase):
class DownFrom(unittest.TestCase):
def test_runs_from_the_projects_rung_down_to_the_rung_the_lowest_l_picks(self):
self.assertEqual(down_from(REFERENCE), [REFERENCE, MIDDLE, CHEAP])
def test_runs_from_the_projects_rung_down_to_the_ladders_bottom(self):
self.assertEqual(down_from(REFERENCE)[:4], [REFERENCE, MIDDLE, CHEAP, LOWER])
self.assertEqual(down_from(REFERENCE)[-1], Rung("claude-haiku-5-5", "low"))
if __name__ == "__main__":
+2 -2
View File
@@ -9,8 +9,8 @@ reads origin as last fetched and says so on stderr.
Git history is the record. A chunk is a merge commit on the default branch's first-parent line
whose change removed items from todo.md, and changed more than todo.md and the records below; it
shipped those items. Each item's guess is its scores in the todo.md the merge's first parent held:
L, E, I, R and S, or before L, E and I replaced C, its R, S and C where it scored them. The chunk
measures:
L, E, I, R and S, or, before L, E and I replaced C, its R and S, and its C where a table with A, G
and Goals scored one. The chunk measures:
- lines changed: lines added plus lines deleted against the first parent, leaving out todo.md and
the records tools append to, docs/comprehension-history.md and docs/reading-cost.md;
+1 -1
View File
@@ -15,7 +15,7 @@ names it and why.
It first replays every round on the project's rung, the reference reviewer. Findings on record
that the reference reviewer does not raise again may rest on code or rules that have changed
since; no rung is held to them. It then replays the rounds where the reference raised any, on each
rung below, highest first, down to the rung the lowest L picks for a worker, and stops at the first rung
rung below, highest first, down to the ladder's bottom rung, and stops at the first rung
that misses one. For each replay, claude on the project's rung matches the report to the findings
on record, and counts a finding only where the report raises it as 🔴 or 🟡. The tool prints each
finding a rung missed and the lowest rung that, like each rung above it, missed none. That rung is
+5 -4
View File
@@ -15,9 +15,10 @@ Exit 1, saying why, on bad arguments.
import re
import sys
from model_routing.ladder import floored, project_rung, worker_rung
from todo_table import LEVELS
from model_routing.ladder import planning_rung, project_rung, worker_rung
USAGE = "usage: subagent-rung [--plan] <model> <L>, L a level from 1 to 4"
USAGE = f"usage: subagent-rung [--plan] <model> <L>, L a level from 1 to {LEVELS['L']}"
def agent_args(model: str, likelihood: int, planning: bool = False) -> str | None:
@@ -25,7 +26,7 @@ def agent_args(model: str, likelihood: int, planning: bool = False) -> str | Non
anchor = project_rung(model)
if anchor is None:
return None
return (floored if planning else worker_rung)(anchor, likelihood).agent_args()
return (planning_rung if planning else worker_rung)(anchor, likelihood).agent_args()
def main(argv: list[str]) -> int:
@@ -34,7 +35,7 @@ def main(argv: list[str]) -> int:
return 0
planning = argv[:1] == ["--plan"]
operands = argv[1:] if planning else argv
if len(operands) != 2 or not re.fullmatch(r"[1-4]", operands[1]):
if len(operands) != 2 or not re.fullmatch(r"[1-9][0-9]*", operands[1]) or int(operands[1]) > LEVELS["L"]:
print(f"subagent-rung: cannot read the arguments{' ' + ' '.join(argv) if argv else ''}; {USAGE}", file=sys.stderr)
return 1
model, likelihood = operands
+8 -3
View File
@@ -241,6 +241,11 @@ class Risk(unittest.TestCase):
without_r = re.sub(r"(\*\* \| \d+ \| \d+ \| \d+) \| \d+ \|", r"\1 |", without_r)
self.assertEqual(self.ranked(without_r).text, ranked)
def test_leaves_a_stale_r_to_ranking_so_a_reader_keeps_the_r_the_table_stored(self):
stale = TODO.replace("| 2 | 1 | 2 | 3 | 8 |", "| 2 | 1 | 2 | 10 | 8 |")
self.assertEqual(next(item for item in todo_table.items(stale) if item.id == 3).scores["R"], 10)
self.assertNotEqual(self.ranked(stale).text, stale)
def test_holds_r_at_7_when_i_is_5_and_at_5_when_i_is_4(self):
cases = {"| 1 | 1 | 5 |": 7, "| 1 | 1 | 4 |": 5, "| 2 | 2 | 4 |": 6, "| 4 | 3 | 5 |": 10, "| 3 | 3 | 3 |": 7}
for levels, risk in cases.items():
@@ -255,7 +260,7 @@ class Risk(unittest.TestCase):
def test_asks_a_table_from_before_l_e_and_i_for_them_yet_reads_its_rows(self):
before = TODO.replace("| L | E | I | R | S | Moves |", "| R | S | C | Moves |").replace("|---|---|---|---|---|---|---|---|---|---|---|---|", "|---|---|---|---|---|---|---|---|---|---|")
before = re.sub(r"(\*\* \|) \d+ \| \d+ \| \d+ \| (\d+) \| (\d+) \|", r"\1 \2 | \3 | 3 |", before)
self.assertEqual(self.ranked(before), Failure("todo.md's items table has no L, E and I columns; add them before R, score each item's L, E and I as rank_todo.py --help shows, and drop C"))
self.assertEqual(self.ranked(before), Failure("todo.md's items table has no L, E and I columns; add them, scoring each item's L, E and I as rank_todo.py --help shows, and drop C"))
items = todo_table.items(before)
self.assertEqual([(item.scores, item.likelihood, item.escape_and_impact) for item in items][1], ({"R": 2, "S": 4}, 0, 0))
@@ -290,11 +295,11 @@ class OldShape(unittest.TestCase):
def test_asks_for_a_c_column_in_a_table_without_one(self):
legacy = OLD_SHAPE.split("## Items")[0] + "## Items\n\n| ID | Release | Exempt | Item | R | S | A | G | Goals | Score |\n|---|---|---|---|---|---|---|---|---|---|\n| 2 | 0.1.0 | | **Tighten the tests.** | 2 | 4 | 5 | 5 | 2.1 | 0 |\n"
self.assertEqual(rank_todo.rank(legacy, README, "").reason, "todo.md's items table has no C column; add one after S, and score each item's C from 1 to 10 per rank_todo.py --help")
self.assertEqual(rank_todo.rank(legacy, README, "").reason, "todo.md's items table has no C column; add it, scoring each item's C as rank_todo.py --help shows")
def test_refuses_a_table_with_both_moves_and_goals(self):
both = OLD_SHAPE.replace("| Goals | Score |\n|---|", "| Goals | Moves | Score |\n|---|---|").replace(" | 0 |\n", " | 1 by 1 | 0 |\n")
self.assertEqual(self.ranked(both), Failure("todo.md's items table has no L, E and I columns; add them before R, score each item's L, E and I as rank_todo.py --help shows, and drop C, A, G and Goals"))
self.assertEqual(self.ranked(both), Failure("todo.md's items table has no L, E and I columns; add them, scoring each item's L, E and I as rank_todo.py --help shows, and drop C, A, G and Goals"))
one = TODO.replace("| Moves | Score |\n|---|", "| Moves | G | Score |\n|---|---|").replace(" | 0 |\n", " | 1 | 0 |\n")
self.assertEqual(self.ranked(one), Failure("todo.md's items table has G, a column of an older shape; drop it, as rank_todo.py --help shows"))
+5 -5
View File
@@ -27,6 +27,8 @@ class Shape:
score_columns: tuple[str, ...]
# The columns a reader does without: a missing BLOCKED_BY reads as blocked by nothing, a missing score as no score, and a missing Score as no score yet.
optional: tuple[str, ...]
# The columns rank_todo.py needs to rank a row, so no chunk starts on an item whose risk is unscored.
risk_columns: tuple[str, ...]
# The column naming the goals an item serves; read_goals reads it, given the item's ID to name in a failure, and write_goals writes it back.
goals_column: str
read_goals: typing.Callable[[str, str], Moves | Failure]
@@ -70,10 +72,10 @@ def write_cited(moves: Moves) -> str:
return ", ".join(goal for goal, _ in moves)
# L, E and I are optional, since score_outcomes reads tables from before they replaced C out of history; R too, since parse_row works it out from them.
SHAPE = Shape(("L", "E", "I", "R", "S"), (BLOCKED_BY, "L", "E", "I", "R", "Score"), MOVES, parse_moves, write_moves)
# L, E and I are optional, since score_outcomes reads tables from before they replaced C out of history; R too, since rank_todo.py writes it from them.
SHAPE = Shape(("L", "E", "I", "R", "S"), (BLOCKED_BY, "L", "E", "I", "R", "Score"), ("L", "E", "I"), MOVES, parse_moves, write_moves)
# The shape from before MOVES replaced A, G and Goals, and L, E and I replaced C, which older todo.md files hold; one from before C joined lacks it.
OLD_SHAPE = Shape(("R", "S", "C", "A", "G"), (BLOCKED_BY, "C", "Score"), "Goals", parse_cited, write_cited)
OLD_SHAPE = Shape(("R", "S", "C", "A", "G"), (BLOCKED_BY, "C", "Score"), ("C",), "Goals", parse_cited, write_cited)
@dataclasses.dataclass(frozen=True)
@@ -189,8 +191,6 @@ def parse_row(row: str, table: Table) -> Item | Failure:
scores = parse_scores(named["ID"], named, shape.score_columns)
if isinstance(scores, Failure):
return scores
if {"L", "E", "I"} <= scores.keys():
scores["R"] = risk(scores["L"], scores["E"], scores["I"])
blocked_by = parse_blockers(named["ID"], named.get(BLOCKED_BY, ""))
if isinstance(blocked_by, Failure):
return blocked_by
+6 -1
View File
@@ -6,7 +6,7 @@
`Bar = 0.1`
`Next ID = 168`
`Next ID = 169`
## Items
@@ -39,6 +39,7 @@
| 157 | 0.3.0 | | | **Split `docs/decisions.md` → `todo.md: one table of items …`'s 2026-10-02 paragraph into one paragraph per choice.** | 1 | 2 | 1 | 2 | 2 | 1.1 by 4, 1.4 by 4 | 10.9 |
| 106 | 0.3.0 | | | **Make larv-review's "Do not over-read a clean result" cite a rule that says Renovate or Dependabot owns dependency CVEs, or drop the citation.** | 1 | 2 | 1 | 2 | 1 | 1.1 by 5 | 10.9 |
| 167 | 0.3.0 | | | **Refuse a `/security-review` or `/claude-security` Skill call below the project's rung, as rule-hook refuses such an Agent call.** | 3 | 2 | 3 | 6 | 2 | 1.1 by 4 | 7.3 |
| 168 | 0.3.0 | | | **Name the project's rung `project` across `bin/loop_claude`, in place of `anchor`, as `bin/model_routing/ladder.py` names it.** | 2 | 1 | 3 | 4 | 3 | 1.1 by 3, 1.4 by 3 | 6.2 |
| 82 | 0.3.0 | | principle | **Sort `AGENTS.md`'s decision titles and `docs/decisions.md`'s entries by title.** | 2 | 2 | 1 | 3 | 4 | 1.1 by 4, 1.4 by 4 | 5.5 |
| 162 | 0.3.0 | | owner | **Script each step that 0.2.0's chunks repeated by hand and a program can compute, filing one item per step, and file this audit again for the next release.** | 2 | 2 | 1 | 3 | 3 | 1.4 by 4, 1.5 by 4 | 4.9 |
| 165 | 0.3.0 | | | **Make this repo's tests assert the facts a prompt or help text carries in place of its sentences, and drop the tests that scan source or assert a constant.** | 3 | 2 | 1 | 4 | 5 | 1.1 by 4, 1.4 by 3 | 3.0 |
@@ -213,6 +214,10 @@ Found by the goals audit of PR #245. `skills/larv-review/SKILL.md` §3 → "Secu
rule-hook checks Agent calls (item 163) but no Skill calls. A worker that invokes `/security-review` in its own context, instead of in a subagent, runs the pass on its own rung, and nothing blocks it. Check Skill calls too: `breaches_of` in bin/rule_hook/main.py takes a Skill call whose skill is `security-review` or `claude-security` as a review launch, and settings.json's PreToolUse matcher gains Skill. Found by the systems-architect's review of PR #295.
### 168. Name the project's rung `project` across `bin/loop_claude`, in place of `anchor`, as `bin/model_routing/ladder.py` names it.
The architecture pass of PR #296 found one rung under two names: `bin/model_routing/ladder.py` calls it `project`, while `bin/loop_claude/routing.py`, `cycle/prompts.py`, `cycle/run.py`'s `Cycle.anchor` and `loop/main.py` call it `anchor`, and gloss it as "anchor, the project's rung" in docstring after docstring. A reader works out that the two are one rung each time. Make `bin/loop_claude/routing.py`'s `first_route` easier to read.
### 82. Sort `AGENTS.md`'s decision titles and `docs/decisions.md`'s entries by title.
"Deterministic order", in `principles/technical-principles.md`, raised by the principles audit of PR #224: their order carries no meaning, so two chunks adding a decision conflict at the end, and a reader cannot find a title by scanning.