From 886c864521f579e1aac3cb8c1b7e35e89d54f280 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 12:49:32 +0200 Subject: [PATCH] =?UTF-8?q?Answer=20principles=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=209=20=F0=9F=9F=A1;=20drop=20a=20route=20handed?= =?UTF-8?q?=20under=20R=20+=20C,=20validate=20Route,=20rank=20old=20tables?= =?UTF-8?q?=20without=20C,=20settle=20item=20166,=20file=20items=20170=20a?= =?UTF-8?q?nd=20171?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AGENTS.md | 2 +- CHANGELOG.md | 2 +- bin/loop_claude/cycle/judge.py | 6 ++-- bin/loop_claude/cycle/prompts.py | 2 +- bin/loop_claude/loop/main.py | 8 ++--- bin/loop_claude/loop/reload.py | 25 ++++++++++--- bin/loop_claude/loop/routing_check.py | 2 +- bin/loop_claude/routing.py | 4 +-- bin/loop_claude/test_black_box.py | 2 +- bin/loop_claude/test_loop_claude.py | 25 +++++++++---- bin/model_routing/route.py | 51 +++++++++++++++++---------- bin/model_routing/test_ladder.py | 2 +- bin/rank_todo.py | 18 ++++++---- bin/routing_figures/measure.py | 10 +++--- bin/rule_hook/reviewer_rung.py | 7 ++-- bin/rule_hook/rules.py | 2 +- bin/rule_hook/test_rule_hook.py | 7 ++-- bin/score_outcomes/main.py | 4 ++- bin/score_outcomes/outcomes.py | 28 +++++++-------- bin/test_rank_todo.py | 4 +-- bin/todo_table.py | 2 +- docs/decisions.md | 12 +++---- todo.md | 17 +++++---- 23 files changed, 147 insertions(+), 95 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 8ec6c133..baca00a4 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -50,7 +50,7 @@ Decisions live in `docs/decisions.md`: ## Working rules -- `routing-calls-raised.md` sits at the root of loop-claude's archive (`$LOOP_CLAUDE_TRANSCRIPTS`, default `~/.claude/loop-claude-transcripts`). Each of its lines is a call or a `Reset`, with a stamp. A call is new when it is stamped after the latest `Reset` and after the latest stamp that `todo.md` or `docs/decisions.md` → `routing:` cites. When there are new calls, file one `todo.md` item to settle them, or refresh the item already filed. Its detail quotes those calls with their stamps, and the routed-chunks table of `routing-figures.md` beside it, never the project names its other tables hold. A change to the ladder, its bands or the delegation rule is the human's. The chunk that settles the calls cites the latest stamp it settled in `docs/decisions.md` → `routing:`, whatever the human decided, so they are not filed again. Once a chunk that changes the ladder, its bands or the delegation rule has merged, append `- Reset` to `routing-calls-raised.md`: the figures then count only chunks finished after it, and its calls may be raised again. +- `routing-calls-raised.md` sits at the root of loop-claude's archive (`$LOOP_CLAUDE_TRANSCRIPTS`, default `~/.claude/loop-claude-transcripts`). Each of its lines is a call or a `Reset`, with a stamp. A call is new when it is stamped after the latest `Reset` and after the latest stamp that `todo.md` or `docs/decisions.md` → `routing:` cites. When there are new calls, file one `todo.md` item to settle them, or refresh the item already filed. Its detail quotes those calls with their stamps, and the routed-chunks table of `routing-figures.md` beside it, never the project names its other tables hold. A change to the ladder, its steps or the delegation rule is the human's. The chunk that settles the calls cites the latest stamp it settled in `docs/decisions.md` → `routing:`, whatever the human decided, so they are not filed again. Once a chunk that changes the ladder, its steps or the delegation rule has merged, append `- Reset` to `routing-calls-raised.md`: the figures then count only chunks finished after it, and its calls may be raised again. - When `~/.claude/settings.json` has uncommitted changes, commit them on a branch of their own and merge them through a PR: Claude Code writes that file from any session. Read their diff first. When it holds a credential, such as a token in `env` or `mcpServers`, ask the human to move it out of the file, and commit only once it is gone. A token in `env` moves to the shell profile; a server in `mcpServers` moves to `~/.claude.json` with `claude mcp add --scope user`. ## Scoring run diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d980662..2768417f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ - An item that restores a maintain goal the project breaks today is exempt as `defect`, and its Moves may name that maintain goal, weighed as the heaviest achieve goal. A defect ranks by its score like any item. Only two kinds rank ahead of the rest of their release: questions first, since an answer may change other items, then security items. - The stability reviewer applies `principles/technical-principles.md` as written, in place of its own copies of it. Its test-data check now asks for UUID v7, where it asked for randomised UUIDs. - larv-review's principles audit is a pass of its own, and runs on every chunk that changes code, config or tests, not only on one with an architectural decision. A chunk of prose or planning alone skips it. -- `rule-hook` refuses an Agent call that launches a reviewer, a comprehension seat or the security pass on a rung below the one `loop-claude` names for it, and takes no override: pass the model and effort the refusal names. A reviewer is held to the higher of the worker's rung and the project's; a seat or the security pass to the project's. +- `rule-hook` refuses an Agent call that launches a reviewer, a comprehension seat or the security pass on a rung below the one `loop-claude` names for it, and takes no override: pass the model and effort the refusal names. A seat or the security pass is held to the project's rung, and a reviewer to the reviewers' rung below. ## 0.1.0 diff --git a/bin/loop_claude/cycle/judge.py b/bin/loop_claude/cycle/judge.py index ecfcde51..48eaa97d 100644 --- a/bin/loop_claude/cycle/judge.py +++ b/bin/loop_claude/cycle/judge.py @@ -122,9 +122,9 @@ def verdict_from(output: object) -> Verdict | Failure: return QuotedAnswer(output["evidence"], output["question"], output["answer"]) if output["finished"]: return Finished(output["evidence"]) - if not 0 <= output["bundled"] <= HIGHEST_L: - return Failure(f"the judge's bundled L {output['bundled']} is not from 0 to {HIGHEST_L}") - return Unfinished(output["evidence"], output["bundled"], output["escalation"]) + # A bundled L off its scale counts as none: holding the rung is safe, and three failures would stop an unattended loop. + bundled = output["bundled"] if 0 <= output["bundled"] <= HIGHEST_L else 0 + return Unfinished(output["evidence"], bundled, output["escalation"]) def judge(root: str, task: str, premises: str, records: str, rendered_transcript: str, rung: Rung, effects: Effects) -> Verdict | Stop: diff --git a/bin/loop_claude/cycle/prompts.py b/bin/loop_claude/cycle/prompts.py index 822d1bbf..da9eb43c 100644 --- a/bin/loop_claude/cycle/prompts.py +++ b/bin/loop_claude/cycle/prompts.py @@ -70,7 +70,7 @@ def reruns(route: Route, anchor: Rung | None) -> str: if not rerun: return "" if len(set(rerun.values())) == 1: - return f" A {' or '.join(rerun)} that asks for a rerun one rung up reruns with the Agent tool set to `{next(iter(rerun.values())).agent_args()}`." + return f" A {listed(list(rerun), 'or')} that asks for a rerun one rung up reruns with the Agent tool set to `{next(iter(rerun.values())).agent_args()}`." return f" A reviewer that asks for a rerun one rung up reruns with the Agent tool set to `{rerun['reviewer'].agent_args()}`, and a comprehension seat with `{rerun['comprehension seat'].agent_args()}`." diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index 82b68dea..f441d95d 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -58,7 +58,8 @@ seat that rules the work below standard may ask to rerun one rung up; each promp loop-claude hands the worker's claude its own rung, the project's and the reviewers', in LOOP_CLAUDE_WORKER_RUNG, LOOP_CLAUDE_PROJECT_RUNG and LOOP_CLAUDE_REVIEWER_RUNG, and rule-hook refuses a review launched below the rung named for it. The judge reports the highest L the worker -states, and the next cycle steps up to the rung that L picks, never down. Every second unfinished +states, and the next cycle steps up to the rung that L picks, never down; an L off its scale counts +as none. Every second unfinished verdict on a chunk steps it up one rung. So does an unfinished verdict on a worker that ended its run asking for a higher rung, once the judge quotes the transcript showing that the escalation trigger it named fired (~/.claude/CLAUDE.md → "Working with the codebase" lists them). That step @@ -114,9 +115,8 @@ Exit 1, saying why, when: - the worker or the judge fails three times running, retried a minute apart within the cycle. A 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 off its scale, or quotes a passage the transcript does not hold; it holds an elided - passage when each fragment appears in order. + mistypes a field, interrupts or quotes an answer without a question, 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 more than 2 minutes past. The judge's reply gives its reset time only as text, so the judge is diff --git a/bin/loop_claude/loop/reload.py b/bin/loop_claude/loop/reload.py index 5483dccb..d8105ffa 100644 --- a/bin/loop_claude/loop/reload.py +++ b/bin/loop_claude/loop/reload.py @@ -32,24 +32,39 @@ def decode_handed(handed: str, kind: type[T]) -> T | None: except ValueError: return None decoded = decoded_as(fields, kind) - return None if decoded is REJECTED else typing.cast(T, decoded) + return None if decoded in (REJECTED, RETIRED) else typing.cast(T, decoded) REJECTED = object() +# A dataclass handed with a field its RETIRED names: where None may stand in for it, it decodes as None. +RETIRED = object() def decoded_as(value: object, kind: typing.Any) -> typing.Any: - """value as kind, or REJECTED: a dataclass from an object holding its fields, a union's first member that fits, else a value of exactly kind.""" + """value as kind, REJECTED or RETIRED: a dataclass from an object holding its fields, a union's first member that fits, else a value of exactly kind.""" if isinstance(kind, types.UnionType): - return next((found for option in typing.get_args(kind) if (found := decoded_as(value, option)) is not REJECTED), REJECTED) + found = [decoded_as(value, option) for option in typing.get_args(kind)] + fits = [each for each in found if each is not REJECTED and each is not RETIRED] + if fits: + return fits[0] + return None if RETIRED in found and type(None) in typing.get_args(kind) else REJECTED if isinstance(kind, type) and dataclasses.is_dataclass(kind): - shape = typing.get_type_hints(kind) + if isinstance(value, dict) and value.keys() & getattr(kind, "RETIRED", frozenset()): + return RETIRED + hints = typing.get_type_hints(kind) + shape = {field.name: hints[field.name] for field in dataclasses.fields(kind)} # A field with a default may be missing, so a field added since the running script started does not stop the loop. required = {field.name for field in dataclasses.fields(kind) if field.default is dataclasses.MISSING and field.default_factory is dataclasses.MISSING} if not isinstance(value, dict) or not required <= value.keys() <= shape.keys(): return REJECTED fields = {name: decoded_as(field, shape[name]) for name, field in value.items()} - return REJECTED if any(field is REJECTED for field in fields.values()) else kind(**fields) + if any(field in (REJECTED, RETIRED) for field in fields.values()): + return REJECTED + try: + return kind(**fields) + except ValueError: + # A dataclass that checks its fields, as Route does, refuses a handed state that breaks them. + return REJECTED return value if type(value) is kind else REJECTED diff --git a/bin/loop_claude/loop/routing_check.py b/bin/loop_claude/loop/routing_check.py index 6b1ad65c..3b6344b5 100644 --- a/bin/loop_claude/loop/routing_check.py +++ b/bin/loop_claude/loop/routing_check.py @@ -50,7 +50,7 @@ def raise_calls(root: pathlib.Path, new: list[str], rung: Rung, paths: Paths, ef if not effects.on_terminal(): print("Not on a terminal: the calls are raised again at the next measurement.", file=sys.stderr) return None - prompt = f"Put these calls for a routing change from loop-claude's figures to the human, and change nothing until they answer:\n{listed}The figures are in {root / archive.FIGURES}. The ladder, its bands and the delegation rule are docs/decisions.md → `routing:`, and a change to them is the human's. Record what they decide as ~/.claude/CLAUDE.md says; the next chunk of this repo files the plan item for these calls." + prompt = f"Put these calls for a routing change from loop-claude's figures to the human, and change nothing until they answer:\n{listed}The figures are in {root / archive.FIGURES}. The ladder, its steps and the delegation rule are docs/decisions.md → `routing:`, and a change to them is the human's. Record what they decide as ~/.claude/CLAUDE.md says; the next chunk of this repo files the plan item for these calls." if unstarted := hand_over(rung, [prompt], str(paths.claude_dir), paths, {}, effects): return Stop(1, f"could not start claude for the routing calls: {unstarted.reason}") # Raised once the human has seen them, answered or not: an unanswered call reaches the plan through AGENTS.md, so it is not asked twice. diff --git a/bin/loop_claude/routing.py b/bin/loop_claude/routing.py index bbf22900..9fc4fc12 100644 --- a/bin/loop_claude/routing.py +++ b/bin/loop_claude/routing.py @@ -14,14 +14,14 @@ JUDGE_REPLAYED = ("claude-opus-5-5",) def routed_item(todo: str) -> Item | Failure | None: - """The next release's first row that does not wait, as todo_table.waiting says, in the table's order; None when there is none, or it has no L.""" + """The next release's first row that does not wait, as todo_table.waiting says, in the table's order; None when there is none, or it lacks L, E or I.""" found = items(todo) if isinstance(found, Failure) or not found: return found if isinstance(found, Failure) else None next_release = min(item.release for item in found) waits = waiting(found) takes = next((item for item in found if item.release == next_release and item.id not in waits), None) - return takes if takes and takes.likelihood else None + return takes if takes and takes.likelihood and takes.escape_and_impact else None def first_route(anchor: Rung, item: Item | None) -> Route: diff --git a/bin/loop_claude/test_black_box.py b/bin/loop_claude/test_black_box.py index 2ec48fa9..28c62f32 100644 --- a/bin/loop_claude/test_black_box.py +++ b/bin/loop_claude/test_black_box.py @@ -118,7 +118,7 @@ PREMISES = "# Project\n\n## Goals\n\n1. Work.\n\n## Audience\n\nMe.\n" # Item 4's L of 4 steps one rung up from the project's. TODO = "## Items\n\n| ID | Release | Exempt | Item | L | E | I | R | S | Moves | Score |\n|---|---|---|---|---|---|---|---|---|---|---|\n| 4 | 0.1.0 | | **Do it.** | 4 | 2 | 3 | 7 | 2 | 1 by 9 | 25 |\n" # Item 4's L of 2 steps one rung down. -CHEAP = TODO.replace("| 4 | 2 | 3 |", "| 2 | 1 | 2 |") +CHEAP = TODO.replace("| 4 | 2 | 3 | 7 |", "| 2 | 1 | 2 | 3 |") def worker(**step): diff --git a/bin/loop_claude/test_loop_claude.py b/bin/loop_claude/test_loop_claude.py index bea23068..790ccff6 100644 --- a/bin/loop_claude/test_loop_claude.py +++ b/bin/loop_claude/test_loop_claude.py @@ -598,6 +598,16 @@ class Routing(unittest.TestCase): self.assertEqual(routing.judge_rung("judge-model", Route(self.HIGH, 3, 4, 5)), Rung("judge-model")) self.assertEqual(routing.judge_rung("claude-sonnet-5-5", Route(self.HIGH, 3, 4, 5)), Rung("claude-sonnet-5-5")) + def test_refuses_a_route_whose_item_has_levels_off_their_scales_or_levels_without_an_item(self): + for item, likelihood, escape_and_impact in ((3, 0, 5), (3, 5, 5), (3, 4, 1), (3, 4, 9), (0, 4, 5)): + with self.subTest(item=item, likelihood=likelihood, escape_and_impact=escape_and_impact): + with self.assertRaises(ValueError): + Route(self.HIGH, item, likelihood, escape_and_impact) + + def test_routes_nothing_on_an_item_without_e_or_i(self): + without_i = TODO.replace("| E | I | R |", "| E | R |").replace("|---|---|---|---|---|---|---|---|---|---|---|", "|---|---|---|---|---|---|---|---|---|---|").replace("| 4 | 3 | 5 | 10 |", "| 4 | 3 | 10 |").replace("| 4 | 2 | 3 | 7 |", "| 4 | 2 | 7 |").replace("| 1 | 1 | 1 | 1 |", "| 1 | 1 | 1 |") + self.assertIsNone(routing.routed_item(without_i)) + def test_archives_the_route_in_a_line_it_reads_back(self): route = Route(self.HIGH, 3, 4, 5) self.assertEqual(str(route), "claude-opus-5-5 at high effort, routed by item 3's L of 4 and E + I of 5") @@ -607,7 +617,7 @@ class Routing(unittest.TestCase): self.assertIsNone(route_from("worker-model")) def test_reads_no_route_from_a_line_whose_levels_are_off_their_scales_or_an_r_plus_c_route_wrote(self): - for line in ("claude-opus-5-5 at high effort, routed by item 3's L of 5 and E + I of 5", "claude-opus-5-5 at high effort, routed by item 3's L of 0 and E + I of 5", "claude-opus-5-5 at high effort, routed by item 3's L of 4 and E + I of 9", "claude-opus-5-5 at high effort, routed by item 3's R + C of 11"): + for line in ("claude-opus-5-5 at high effort, routed by item 3's L of 5 and E + I of 5", "claude-opus-5-5 at high effort, routed by item 3's L of 0 and E + I of 5", "claude-opus-5-5 at high effort, routed by item 3's L of 4 and E + I of 9", "claude-opus-5-5 at high effort, routed by item 3's L of 4 and E + I of 1", "claude-opus-5-5 at high effort, routed by item 3's R + C of 11"): with self.subTest(line=line): self.assertIsNone(route_from(line)) @@ -858,13 +868,13 @@ class Verdict(unittest.TestCase): self.assertEqual(verdict_from({"bundled": 0, "escalation": "", "answer": "", "interrupt": True, "evidence": "x", "finished": False, "question": " "}), Failure("the judge interrupted without a question")) self.assertEqual(verdict_from(None), Failure("the judge returned no reply")) - def test_takes_a_bundled_l_from_0_to_4_on_an_unfinished_verdict(self): + def test_takes_a_bundled_l_on_its_scale_and_counts_any_other_as_none(self): reply = {"answer": "", "escalation": "", "interrupt": False, "evidence": "e", "finished": False, "question": ""} self.assertEqual(verdict_from({**reply, "bundled": 4}), Unfinished("e", 4)) self.assertEqual(verdict_from({**reply, "bundled": True}), Failure("the judge's reply has no bundled of type integer")) - for bundled in (5, -1): + for bundled in (5, 13, -1): with self.subTest(bundled=bundled): - self.assertEqual(verdict_from({**reply, "bundled": bundled}), Failure(f"the judge's bundled L {bundled} is not from 0 to 4")) + self.assertEqual(verdict_from({**reply, "bundled": bundled}), Unfinished("e", 0)) def test_takes_an_escalation_quote_on_an_unfinished_verdict(self): @@ -889,7 +899,7 @@ class LoopRuns(unittest.TestCase): self.assertIsNone(reload.decode_handed('{"count": "1", "name": "n"}', Stringly)) def test_decodes_a_route_inside_the_state_or_none(self): - state = main.LoopRun(cycle_number=1, root="/r", task="do it", unfinished_evidence="", route=Route(Rung("claude-opus-5-5", "high"), 3, 11, 1)) + state = main.LoopRun(cycle_number=1, root="/r", task="do it", unfinished_evidence="", route=Route(Rung("claude-opus-5-5", "high"), 3, 4, 5, 1)) self.assertEqual(reload.decode_handed(json.dumps(dataclasses.asdict(state)), main.LoopRun), state) unrouted = dataclasses.replace(state, route=None) self.assertEqual(reload.decode_handed(json.dumps(dataclasses.asdict(unrouted)), main.LoopRun), unrouted) @@ -899,6 +909,10 @@ class LoopRuns(unittest.TestCase): del handed["route"]["rung"] self.assertIsNone(reload.decode_handed(json.dumps(handed), main.LoopRun)) + def test_drops_a_route_an_older_loop_claude_handed_under_r_plus_c_so_the_chunk_routes_afresh(self): + older = {"cycle_number": 3, "root": "/r", "task": "do it", "unfinished_evidence": "", "route": {"rung": {"model": "claude-opus-5-5", "effort": "high"}, "item": 3, "risk_and_complexity": 11, "unfinished": 1}} + self.assertEqual(reload.decode_handed(json.dumps(older), main.LoopRun), main.LoopRun(3, "/r", "do it", "")) + def test_decodes_a_state_from_before_a_field_with_a_default_joined_it(self): self.assertEqual(reload.decode_handed(json.dumps({"cycle_number": 3, "root": "/r", "task": "do it", "unfinished_evidence": ""}), main.LoopRun), main.LoopRun(3, "/r", "do it", "")) @@ -979,7 +993,6 @@ 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 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), diff --git a/bin/model_routing/route.py b/bin/model_routing/route.py index b33286f8..f64cb98c 100644 --- a/bin/model_routing/route.py +++ b/bin/model_routing/route.py @@ -1,6 +1,7 @@ """A chunk's route: its worker's rung and the plan item that picked it, in the words the archive records each verdict's worker in.""" import dataclasses import re +import typing from todo_table import LEVELS from model_routing.ladder import Rung @@ -12,42 +13,54 @@ ROUTED = re.compile(r"(?P.+?)(?:, routed by item (?P[0-9]+)'s (?P[0-9]+) and E \+ I of (?P[0-9]+)") +class ArchivedWorker(typing.NamedTuple): + """What an archived worker line names, whatever its route says: the worker's rung, and whether an item routed it.""" + rung: Rung + routed: bool + + +def on_their_scales(likelihood: int, escape_and_impact: int) -> bool: + """Whether L and E + I are levels on the scales todo_table.LEVELS gives; E and I each start at 1.""" + return 1 <= likelihood <= LEVELS["L"] and 2 <= escape_and_impact <= LEVELS["E"] + LEVELS["I"] + + @dataclasses.dataclass(frozen=True) class Route: - """A chunk's worker rung, and the plan item that picked it, 0 for none, with its L, which picked the worker's rung, and its E + I, which picks its reviewers'. + """A chunk's worker rung, and the plan item that picked it, 0 for none, with its L, which picked the worker's rung, and its E + I, which picks its reviewers'. A route with an item holds levels on their scales, and one without holds none, so no rung is picked from a level off its scale. unfinished counts the unfinished verdicts towards the next one-rung step; a reload hands it over with the rung. """ + # The fields a loop-claude from before L and E + I replaced R + C hands on reload; the reloaded script drops such a route, and the chunk routes afresh. + RETIRED: typing.ClassVar[frozenset[str]] = frozenset({"risk_and_complexity"}) rung: Rung item: int = 0 likelihood: int = 0 escape_and_impact: int = 0 unfinished: int = 0 + def __post_init__(self) -> None: + if (self.item and not on_their_scales(self.likelihood, self.escape_and_impact)) or (not self.item and (self.likelihood or self.escape_and_impact)): + raise ValueError(f"a route by item {self.item} cannot hold an L of {self.likelihood} and an E + I of {self.escape_and_impact}") + def __str__(self) -> str: """What the archive records as each verdict's worker; ROUTED reads it back.""" return f"{self.rung}, routed by item {self.item}'s L of {self.likelihood} and E + I of {self.escape_and_impact}" if self.item else str(self.rung) +def archived_worker(worker: str) -> ArchivedWorker | None: + """What an archived worker line names; None for a model run off the ladder.""" + found = ROUTED.fullmatch(worker) + rung = Rung.parse(found["rung"]) if found else None + return ArchivedWorker(rung, bool(found["item"])) if found and rung else None + + def route_from(worker: str) -> Route | None: """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) + archived = archived_worker(worker) + if archived is None or not archived.routed: + return Route(archived.rung) if archived else None + found = typing.cast(re.Match[str], ROUTED.fullmatch(worker)) levels = LEVELS_ROUTED.fullmatch(found["levels"]) - if not levels: + if not levels or not on_their_scales(int(levels["likelihood"]), int(levels["escape_and_impact"])): 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 + return Route(archived.rung, int(found["item"]), int(levels["likelihood"]), int(levels["escape_and_impact"])) diff --git a/bin/model_routing/test_ladder.py b/bin/model_routing/test_ladder.py index 84d82327..2913f52e 100644 --- a/bin/model_routing/test_ladder.py +++ b/bin/model_routing/test_ladder.py @@ -43,7 +43,7 @@ class Ladder(unittest.TestCase): self.assertEqual(set(WORKER_STEPS), set(range(1, LEVELS["L"] + 1))) def test_names_the_lowest_rung_any_l_routes_a_worker_to(self): - self.assertEqual(lowest_worker_rung(OPUS), min((worker_rung(OPUS, likelihood) for likelihood in WORKER_STEPS), key=LADDER.index)) + self.assertEqual(lowest_worker_rung(OPUS), Rung("claude-haiku-5-5", "max")) def test_plans_on_the_rung_l_picks_but_never_below_the_projects(self): self.assertEqual(planning_rung(OPUS, 1), OPUS) diff --git a/bin/rank_todo.py b/bin/rank_todo.py index 1c31ebd4..e823f376 100755 --- a/bin/rank_todo.py +++ b/bin/rank_todo.py @@ -210,11 +210,15 @@ def rank(text: str, readme: str, decisions: str) -> Ranked | Failure: return Ranked(ranked, under_bar, notes(items, scoring)) +# The columns ranking fills itself, so a table without one gains it. +WRITTEN = (BLOCKED_BY, "R", "Score") + + def rewrite_table(lines: list[str], table: Table, shape: Shape, scored: list[tuple[Item, float]]) -> str: - """lines with the table's rows in scored's order, under a header naming every column of shape, so a table from before BLOCKED_BY joined gains the column.""" - columns = shape.columns + """lines with the table's rows in scored's order, under a header naming, in shape's order, each column the table holds and each of WRITTEN.""" + columns = tuple(column for column in shape.columns if column in table.columns or column in WRITTEN) header = ["| " + " | ".join(columns) + " |", "|" + "---|" * len(columns)] - rows = [render_item(item, value, shape) for item, value in scored] + rows = [render_item(item, value, shape, columns) for item, value in scored] return "\n".join(lines[:table.header] + header + rows + lines[table.start + len(table.rows):]) @@ -566,10 +570,10 @@ def parse_item(row: str, scoring: Scoring, table: Table) -> Item | Failure: 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: - """The item's row, each cell under its column of shape.""" - written = {"ID": str(item.id), "Release": release_name(item), BLOCKED_BY: ", ".join(map(str, item.blocked_by)), "Exempt": item.exempt, "Item": item.tagline, **{name: str(item.scores[name]) for name in shape.score_columns}, shape.goals_column: shape.write_goals(item.moves), "Score": f"{value:.1f}"} - return "| " + " | ".join(written[column] for column in shape.columns) + " |" +def render_item(item: Item, value: float, shape: Shape, columns: tuple[str, ...]) -> str: + """The item's row, each cell under its column.""" + written = {"ID": str(item.id), "Release": release_name(item), BLOCKED_BY: ", ".join(map(str, item.blocked_by)), "Exempt": item.exempt, "Item": item.tagline, **{name: str(score) for name, score in item.scores.items()}, shape.goals_column: shape.write_goals(item.moves), "Score": f"{value:.1f}"} + return "| " + " | ".join(written[column] for column in columns) + " |" def rank_details(text: str, items: list[Item]) -> str | Failure: diff --git a/bin/routing_figures/measure.py b/bin/routing_figures/measure.py index 65a1e4ff..ee11c017 100644 --- a/bin/routing_figures/measure.py +++ b/bin/routing_figures/measure.py @@ -5,7 +5,7 @@ import re import statistics import typing -from model_routing.route import archived_rung, ESCALATION_MARKER +from model_routing.route import archived_worker, ESCALATION_MARKER from claude_code.entries import assistant_parts, parts, tool_call, usage_count from git_command import commits from model_routing.ladder import position, Rung @@ -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 = archived_rung(cycles[0][1]) if cycles else None + start = archived_worker(cycles[0][1]) if cycles else None return ChunkFigures( tokens=tokens, - start=start[0] if start and start[1] else None, + start=start.rung if start and start.routed 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 = archived_rung(found) - return route[0] if route else found + archived = archived_worker(found) + return archived.rung if archived else found def subagent_rung(entries: list[dict], arguments: dict, worker: Rung | str) -> Rung: diff --git a/bin/rule_hook/reviewer_rung.py b/bin/rule_hook/reviewer_rung.py index e68a7bc7..3bd28158 100644 --- a/bin/rule_hook/reviewer_rung.py +++ b/bin/rule_hook/reviewer_rung.py @@ -5,7 +5,7 @@ import typing from rule_hook.rules import Breach from rule_hook.call import Call, text from model_routing.worker_rungs import handed -from model_routing.ladder import position, review_rung, ReviewKind, Rung +from model_routing.ladder import highest, position, review_rung, ReviewKind, Rung # A reviewer is an agent under agents/, as CLAUDE.md → "Vocabulary" defines it. REVIEWERS = frozenset(path.stem for path in (pathlib.Path(__file__).resolve().parents[2] / "agents").glob("*.md")) @@ -20,9 +20,10 @@ def reviewer_breaches(call: Call, environ: typing.Mapping[str, str]) -> list[Bre """The breach of an Agent call that launches a review below its rung; none where loop-claude handed no rungs.""" project, worker, reviewers = handed(environ) kind = review_kind(call.given) - if kind is None or project is None or worker is None or reviewers is None: + if kind is None or project is None or worker is None: return [] - required = review_rung(kind, project, reviewers) + # A worker an older loop-claude started was handed no reviewers' rung; its reviewers are held to the rung that loop-claude gave them. + required = review_rung(kind, project, reviewers or highest(project, worker)) named = named_rung(call.given, worker) if position(named) >= position(required): return [] diff --git a/bin/rule_hook/rules.py b/bin/rule_hook/rules.py index 75a17154..d3a5d844 100644 --- a/bin/rule_hook/rules.py +++ b/bin/rule_hook/rules.py @@ -41,7 +41,7 @@ RULES: dict[RuleName, Rule] = { ), # A rung is not a judgment call, and the refusal names the arguments to pass, so no marker waives it. "reviewer-rung": Rule( - "a reviewer, a comprehension seat or the security pass's subagent runs on the rung loop-claude names for it: the project's rung, or for a reviewer the worker's rung where that is higher, so a worker below the project's rung cannot hand a review to its own cheaper model", + "a reviewer, a comprehension seat or the security pass's subagent runs on the rung loop-claude names for it: for a seat or the security pass the project's rung, and for a reviewer the highest of the project's rung, the worker's and the one its item's E + I picks, so a worker below the project's rung cannot hand a review to its own cheaper model", "an Agent call, in a claude loop-claude started, whose subagent type is an agent under agents/, or whose prompt opens with seat-prompts.md's opening sentence or the one larv-review's Security section sets", overridable=False, ), diff --git a/bin/rule_hook/test_rule_hook.py b/bin/rule_hook/test_rule_hook.py index df0ea2cb..42eacb10 100644 --- a/bin/rule_hook/test_rule_hook.py +++ b/bin/rule_hook/test_rule_hook.py @@ -207,9 +207,10 @@ class ReviewerRung(unittest.TestCase): self.assertEqual(self.refused({"subagent_type": "stability-reviewer", "model": "opus", "effort": "medium"}, lifted), ["reviewer-rung"]) self.assertEqual(self.refused({"prompt": "You are one seat of a comprehension panel.", "model": "opus", "effort": "medium"}, lifted), []) - def test_checks_nothing_where_loop_claude_handed_no_reviewers_rung(self): - without = {name: rung for name, rung in self.ENVIRON.items() if name != "LOOP_CLAUDE_REVIEWER_RUNG"} - self.assertEqual(self.refused({"subagent_type": "stability-reviewer", "model": "sonnet", "effort": "high"}, without), []) + def test_holds_a_reviewer_to_the_higher_of_the_workers_and_the_projects_rung_where_loop_claude_handed_no_reviewers_rung(self): + without = {name: rung for name, rung in self.ABOVE.items() if name != "LOOP_CLAUDE_REVIEWER_RUNG"} + self.assertEqual(self.refused({"subagent_type": "stability-reviewer", "model": "opus", "effort": "medium"}, without), ["reviewer-rung"]) + self.assertEqual(self.refused({"prompt": "You are one seat of a comprehension panel.", "model": "sonnet", "effort": "high"}, without), ["reviewer-rung"]) def test_a_seat_or_a_security_launch_is_held_to_the_project_rung_alone(self): seat = {"prompt": "You are one seat of a comprehension panel. Tools: Read, Grep, Glob.", "model": "opus", "effort": "medium"} diff --git a/bin/score_outcomes/main.py b/bin/score_outcomes/main.py index 84b67d57..720e6b51 100644 --- a/bin/score_outcomes/main.py +++ b/bin/score_outcomes/main.py @@ -45,6 +45,7 @@ import sys from git_repo import default_branch, file_at, full_history, git from failure import Failure from todo_table import LEVELS, risk, TOP_SCORE +from markdown_text import listed from score_outcomes.outcomes import nearest, Outcome, outcomes_of, render, report, shipped from utc_stamp import utc @@ -57,7 +58,8 @@ def main(argv: list[str]) -> int: print(__doc__.strip()) return 0 if argv and (len(argv) != len(GIVEN) or not all(re.fullmatch(r"[1-9][0-9]?", arg) and int(arg) <= LEVELS.get(name, TOP_SCORE) for name, arg in zip(GIVEN, argv))): - print(f"score-outcomes: cannot read the arguments {' '.join(argv)}; usage: score-outcomes [L E I S], L from 1 to 4, E from 1 to 3, I from 1 to 5 and S from 1 to 10", file=sys.stderr) + scales = listed([f"{name} from 1 to {LEVELS.get(name, TOP_SCORE)}" for name in GIVEN], "and") + print(f"score-outcomes: cannot read the arguments {' '.join(argv)}; usage: score-outcomes [L E I S], {scales}", file=sys.stderr) return 1 found = default_branch(stale_ok=True) if isinstance(found, Failure): diff --git a/bin/score_outcomes/outcomes.py b/bin/score_outcomes/outcomes.py index 66ebbf15..eb5d9077 100644 --- a/bin/score_outcomes/outcomes.py +++ b/bin/score_outcomes/outcomes.py @@ -4,6 +4,7 @@ import typing from comprehension_history import HISTORY from todo_table import Item, items +from markdown_text import listed from reading_cost.figures import RECORD from round_titles import round_counts, round_findings @@ -28,11 +29,8 @@ class Outcome: # An outcome's name and how to read it from an Outcome, None where the chunk did not record it. Measure = tuple[str, typing.Callable[[Outcome], int | None]] -# Each pass takes a first round whatever the change, so only the rounds after it measure how hard the change was to get right. -ROUNDS: Measure = ("review rounds past each pass's first", lambda outcome: outcome.rounds_past_first) -RED: Measure = ("🔴 findings", lambda outcome: outcome.findings[0] if outcome.findings else None) # The scores whose median outcome the report gives at each guessed value. -MEDIANS: dict[str, Measure] = {"R": RED, "S": ("lines changed", lambda outcome: outcome.lines)} +MEDIANS: dict[str, Measure] = {"R": ("🔴 findings", lambda outcome: outcome.findings[0] if outcome.findings else None), "S": ("lines changed", lambda outcome: outcome.lines)} # The levels R is built from, for each of which the report gives how well it orders chunks by both outcomes. ORDERED = ("L", "E", "I") # The scores render shows, in this order; C only on an item scored before L, E and I replaced it. @@ -82,15 +80,16 @@ def report(outcomes: list[Outcome]) -> list[str]: medians = [(guess, [value for at, value in held if at == guess]) for guess in sorted({guess for guess, _ in held})] lines.append(f"- {name}, {what}: " + ", ".join(f"{guess} → {statistics.median(found):g} ({plural(len(found), 'chunk')})" for guess, found in medians)) for name in ORDERED: - held_both = [outcome for outcome in single if name in outcome.item.scores and outcome.findings] - opening = f"- {name}, by {ROUNDS[0]} and {RED[0]}: " - if len(held_both) < ENOUGH: - lines.append(opening + too_few(len(held_both), name, "both outcomes")) + # Each pass takes a first round whatever the change, so only the rounds after it measure how hard the change was to get right. + rows = [(outcome.item.scores[name], outcome.rounds_past_first, outcome.findings[0]) for outcome in single if name in outcome.item.scores and outcome.findings is not None] + opening = f"- {name}, by review rounds past each pass's first and 🔴 findings: " + if len(rows) < ENOUGH: + lines.append(opening + too_few(len(rows), name, "both outcomes")) continue - guesses = [outcome.item.scores[name] for outcome in held_both] - found = [rank_correlation(guesses, [typing.cast(int, measure(outcome)) for outcome in held_both]) for _, measure in (ROUNDS, RED)] + guesses, rounds, red = ([row[column] for row in rows] for column in range(3)) + found = [rank_correlation(guesses, rounds), rank_correlation(guesses, red)] undefined = ", since every chunk held one value" if None in found else "" - lines.append(opening + f"rank correlation {' and '.join('none' if value is None else f'{value:+.2f}' for value in found)}{undefined} ({plural(len(held_both), 'chunk')})") + lines.append(opening + f"rank correlation {listed(['none' if value is None else f'{value:+.2f}' for value in found], 'and')}{undefined} ({plural(len(rows), 'chunk')})") return lines @@ -100,11 +99,10 @@ def too_few(held: int, name: str, what: str) -> str: def rank_correlation(guesses: list[int], outcomes: list[int]) -> float | None: - """Spearman's rank correlation, tied values sharing their mean rank; None where either side holds one value.""" - try: - return statistics.correlation(ranks(guesses), ranks(outcomes)) - except statistics.StatisticsError: + """Spearman's rank correlation, tied values sharing their mean rank; None where either side holds one value, which no order can rank.""" + if len(set(guesses)) < 2 or len(set(outcomes)) < 2: return None + return statistics.correlation(ranks(guesses), ranks(outcomes)) def ranks(values: list[int]) -> list[float]: diff --git a/bin/test_rank_todo.py b/bin/test_rank_todo.py index bb5a609b..f95db2fc 100644 --- a/bin/test_rank_todo.py +++ b/bin/test_rank_todo.py @@ -293,9 +293,9 @@ class OldShape(unittest.TestCase): def test_refuses_a_formula_over_v(self): self.assertEqual(self.ranked(OLD_SHAPE.replace("-R - S/4 + 2*A + 2*G*W", "V")), Failure("the formula 'V' may hold only numbers, A, G, R, S, W, + - * / ** and parentheses")) - def test_asks_for_a_c_column_in_a_table_without_one(self): + def test_ranks_a_table_from_before_c_joined_and_says_to_reshape_it(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 it, scoring each item's C as rank_todo.py --help shows") + self.assertEqual(rank_todo.rank(legacy, README, "").notes, [rank_todo.RESHAPE]) 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") diff --git a/bin/todo_table.py b/bin/todo_table.py index f8ea595c..dc232202 100644 --- a/bin/todo_table.py +++ b/bin/todo_table.py @@ -75,7 +75,7 @@ def write_cited(moves: Moves) -> str: # 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"), ("C",), "Goals", parse_cited, write_cited) +OLD_SHAPE = Shape(("R", "S", "C", "A", "G"), (BLOCKED_BY, "C", "Score"), (), "Goals", parse_cited, write_cited) @dataclasses.dataclass(frozen=True) diff --git a/docs/decisions.md b/docs/decisions.md index 9398c3d1..f59da4e4 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -62,7 +62,7 @@ 2026-10-15, lilleman asked for it through todo item 144, implemented by claude. Serves goal 1.1: a cheap reviewer that finds the work below standard can have a more capable one check that ruling, and work below standard gets a more capable rung to fix it. -The work is below standard where systems-architect returns BLOCK, a reviewer reports a finding against larv-review's `standards/quality.md`, or `record-ruling` counts a comprehension seat's vote in a paired ruling as worse. That reviewer or seat may ask, and the worker then relaunches it on the rung loop-claude's prompt names, one above the rung it ran on. `bin/loop_claude/cycle/prompts.py`'s `reruns` names it: the seats run on the project's rung, and the reviewers too while the worker runs below it. Off the ladder, or for a reviewer or seat already on the top rung, the prompt names none, and its report stands. +The work is below standard where systems-architect returns BLOCK, a reviewer reports a finding against larv-review's `standards/quality.md`, or `record-ruling` counts a comprehension seat's vote in a paired ruling as worse. That reviewer or seat may ask, and the worker then relaunches it on the rung loop-claude's prompt names, one above the rung it ran on. `bin/loop_claude/cycle/prompts.py`'s `reruns` names it: the seats run on the project's rung, and the reviewers on the rung `review_rungs` in `bin/model_routing/ladder.py` gives them. Off the ladder, or for a reviewer or seat already on the top rung, the prompt names none, and its report stands. A reviewer's relaunch gets the report that asked and confirms or dismisses each of its findings with a reason, so no finding goes unanswered; a seat's relaunch reads afresh, since a seat reports no findings. The relaunch's report stands in place of the one that asked, in the same round, so it adds no round, and a relaunch cannot ask again. So the round cap still bounds a pass, and one round launches a reviewer at most twice. The ruling that stands is the fourth escalation trigger in `CLAUDE.md`. lilleman ruled that no ruling raises the judge's rung, which `routing: on a model judge-replay covered` sets. @@ -138,7 +138,7 @@ Valid while the ladder orders its rungs by competence. 2026-10-16, lilleman, ruling on the plan in PR #283: release 0.2.0 takes plan items 146, 152, 73, 50, 65, 84, 153 and 67, the split of `routing: one ladder`, and the question of how many chunks `score-outcomes` and the reading-cost trend wait for, ahead of their scores, to put budget and efficiency in the other projects first. A standing goal cannot capture that priority for now, so it is a one-time ruling: the later releases, and every release after 0.2.0, fill from the score again. -2026-10-15, lilleman. Serves goal 1.4: loop-claude routes a chunk's first cycle on the item the chunk takes (`routing: a chunk's worker runs on the rung its item picks`). An item lists the items that must be done before it starts in a Blocked by column, and `rank_todo.py` ranks each blocker above every item it blocks. The table's order is `todo.md`'s only order: `rank_todo.py` fails on text beside the table under `## Items`, since a prose order there, "Release 0.3.0 takes items 125, 114 and 124 first", contradicted the table and loop-claude could not read it. A decision that wants an order sets the scores instead. An item waits while it is marked `question` or a blocker of it is still in the table, whatever the rows' order, so a release's first row that does not wait is the item a chunk takes. A blocker the table no longer holds was finished or deleted, and is dropped, so the cell shows what still blocks. A panel of three readers seated as lilleman picked the spelling: two ranked "Blocked by" first, as the cell lists only what still blocks, and all three chose bare IDs such as `12, 14` in a column right after Release, read before the tagline and kept apart from the scores. `rank_todo.py` adds the column to a table without it. The tools read cells by column name, so a later column leaves a reader on an older release working; `rank_todo.py`, which writes every column, fails on one it does not know rather than drop it. +2026-10-15, lilleman. Serves goal 1.4: loop-claude routes a chunk's first cycle on the item the chunk takes (`routing: a chunk's worker runs on the rung its item's L picks`). An item lists the items that must be done before it starts in a Blocked by column, and `rank_todo.py` ranks each blocker above every item it blocks. The table's order is `todo.md`'s only order: `rank_todo.py` fails on text beside the table under `## Items`, since a prose order there, "Release 0.3.0 takes items 125, 114 and 124 first", contradicted the table and loop-claude could not read it. A decision that wants an order sets the scores instead. An item waits while it is marked `question` or a blocker of it is still in the table, whatever the rows' order, so a release's first row that does not wait is the item a chunk takes. A blocker the table no longer holds was finished or deleted, and is dropped, so the cell shows what still blocks. A panel of three readers seated as lilleman picked the spelling: two ranked "Blocked by" first, as the cell lists only what still blocks, and all three chose bare IDs such as `12, 14` in a column right after Release, read before the tagline and kept apart from the scores. `rank_todo.py` adds the column to a table without it. The tools read cells by column name, so a later column leaves a reader on an older release working; `rank_todo.py`, which writes every column, fails on one it does not know rather than drop it. ## todo.md: only a session or subagent on the project's rung or above scores or reshapes the plan; one below it drafts new items and changes to filed ones for a subagent at or above that rung to apply and score, and removes finished ones @@ -172,7 +172,7 @@ Valid while no published standard sets either number, the reading-cost window st ## rule-hook: a PreToolUse hook enforces each rule a program can check, a `# rule-override : ` marker overrides one, and larv-review's overrides pass rules on each override before merge -2026-10-12, lilleman. Serves goals 1.2 and 1.3. Anthropic's best-practices page calls `CLAUDE.md` advisory and hooks deterministic, so a rule that must hold every time moves into `bin/rule-hook`, and `CLAUDE.md` keeps it only where the hook cannot check it. A Claude Code hook ties the check to one vendor ("Prefer the vendor-neutral option", `principles/technical-principles.md`), which is the target itself here: this repo configures Claude Code. What the tie buys: the hook blocks before a write lands, Edit and Write calls included, in every project with no per-repo install; a git `commit-msg` hook sees only commits, and CI sees them only after the push. The hook checks each write, so the agent fixes the line it just wrote; checking the staged diff at commit time would also cover files a Bash command writes, at the cost of later feedback. The marker's spelling was picked by a panel of three fresh readers, two to one. Each override is logged in the checkout's git directory, which is never pushed (goal 4). The plan had loop-claude's judge to rule on overrides inside a loop; lilleman approved larv-review's overrides pass in every run, because it rules before merge and an outrageous override still reaches the human through its ask. Valid while a PreToolUse hook that exits 2 blocks the call and hands its stderr to the model, and while an agent commits through Claude Code's Bash tool. +2026-10-12, lilleman. Serves goals 1.2 and 1.3. Anthropic's best-practices page calls `CLAUDE.md` advisory and hooks deterministic, so a rule that must hold every time moves into `bin/rule-hook`, and `CLAUDE.md` keeps it only where the hook cannot check it. A Claude Code hook ties the check to one vendor ("Prefer the vendor-neutral option", `principles/technical-principles.md`), which is the target itself here: this repo configures Claude Code. What the tie buys: the hook blocks before a write lands, Edit and Write calls included, in every project with no per-repo install; a git `commit-msg` hook sees only commits, and CI sees them only after the push. The hook checks each write, so the agent fixes the line it just wrote; checking the staged diff at commit time would also cover files a Bash command writes, at the cost of later feedback. The marker's spelling was picked by a panel of three fresh readers, two to one. Each override is logged in the checkout's git directory, which is never pushed (goal 4). The plan had loop-claude's judge to rule on overrides inside a loop; lilleman approved larv-review's overrides pass in every run, because it rules before merge and an outrageous override still reaches the human through its ask. 2026-10-16, lilleman, answering the question plan item 166 asked: `reviewer-rung` takes no marker, since a rung is no judgment call and the refusal names the arguments to pass, as the comment above it in `bin/rule_hook/rules.py` says; `routing: a chunk's worker runs on the rung its item's L picks` names the rungs it holds a launch to. Valid while a PreToolUse hook that exits 2 blocks the call and hands its stderr to the model, and while an agent commits through Claude Code's Bash tool. ## rules/: `CLAUDE.md` holds the worker's rules that no file path can scope, and each topic's rules for the worker live in a `rules/` file that Claude Code loads by its `paths:` frontmatter @@ -232,7 +232,7 @@ Valid while a mutation run on a chunk's changed lines stays cheap beside the rev The rungs, least competent first: Haiku 5.5 at low, medium, high, xhigh and max; Sonnet 5.5 at high; Opus 5.5 at medium, high, xhigh and max; Fable 5.1 at max. The order and the cut come from the Artificial Analysis Intelligence Index (https://artificialanalysis.ai/leaderboards/models, read 2026-10-14), which scores each model at each effort and gives a cost per task. A rung stays only where no cheaper rung scores as high, so a step up always buys more score (goal 1.4). That cut drops Sonnet 5.5 at low, medium, xhigh and max, Opus 5.5 at low, and every Fable 5.1 rung, and every tie in the index falls among the dropped rungs. lilleman put Fable 5.1 at max back on top: the index scores it under Opus 5.5 at high, but Anthropic's model catalog names Fable the most capable model, and for the hardest tasks lilleman wants the highest quality at any price. -A project's rung is its model's cheapest rung, which for Opus 5.5 is its default effort, medium. A model off the ladder routes nothing: claude runs it at the effort its settings give. A task's L steps its worker from the project's rung: 1 two rungs down, 2 one down, 3 none, 4 one up. Its E + I steps its reviewers up from the project's rung: 4 or less none, 5 one up, 6 two up, 7 three up, 8 four up. A step past either end stops there. A worker errs more the more it changes and the newer that is, which L scores; review must look harder the further a defect would escape and the more it would break, which E + I scores (goals 1.1 and 1.4). Size sets L, so a large change runs its worker higher. The steps spread the values this repo's plan held when rescored on 2026-10-16, L 1 to 4 and E + I 2 to 7, so a worker on most items runs at or below the project's rung, and a review climbs only where a defect would escape far or break much. Until then, from 2026-10-14, one band of R + C picked the worker's rung. lilleman approved these steps on 2026-10-16 as a first guess: `score-outcomes` reports how well L, E and I each order finished chunks by review rounds and 🔴 findings, and the steps are re-tuned once 10 chunks have shipped under them. A change to the ladder or the steps is lilleman's. +A project's rung is its model's cheapest rung, which for Opus 5.5 is its default effort, medium. A model off the ladder routes nothing: claude runs it at the effort its settings give. A task's L steps its worker from the project's rung: 1 two rungs down, 2 one down, 3 none, 4 one up. Its E + I steps its reviewers up from the project's rung: 4 or less none, 5 one up, 6 two up, 7 three up, 8 four up. A step past either end stops there. A worker errs more the more it changes and the newer that is, which L scores; review must look harder the further a defect would escape and the more it would break, which E + I scores (goals 1.1 and 1.4). Size sets L, so a large change runs its worker higher. The steps spread the values this repo's plan held when rescored on 2026-10-16, L 1 to 4 and E + I 2 to 7, so a worker on most items runs at or below the project's rung, and a review climbs only where a defect would escape far or break much. Until then, from 2026-10-14, one band of R + C picked the worker's rung. lilleman approved these steps on 2026-10-16 as a first guess: `score-outcomes` reports how well L, E and I each order finished chunks by review rounds and 🔴 findings, and `todo.md` item 170 re-tunes the steps once 10 chunks have shipped under them. A change to the ladder or the steps is lilleman's. Valid while the index ranks these models, and while no newer model joins the catalog. @@ -294,7 +294,7 @@ Valid while the worker reports in its transcript the triggers that fired. ## routing: on a model judge-replay covered, the judge runs on the rung its chunk's item's E + I picks for a review, never below the project's rung -2026-10-15, lilleman's plan, settled by the replay below. Serves goals 1.2 and 1.4, under the ladder and bands of `routing: one ladder`. +2026-10-15, lilleman's plan, settled by the replay below. Serves goals 1.2 and 1.4, under the ladder and steps of `routing: one ladder`. On a model listed in `JUDGE_REPLAYED` in `bin/loop_claude/routing.py`, the judge runs on the rung its chunk's item's E + I picks for a review, never below the project's rung, and keeps that rung when the worker steps up. Without an item, it runs on the project's rung. Each archived verdict names the judge's rung on a `Judge:` line. @@ -310,6 +310,6 @@ Valid while the archived verdicts show what a judge should return, and until a n `bin/stability-replay ` replays archived stability rounds on the code each reviewed, first on the project's rung, then on each rung below it, highest first, and stops at the first that misses a finding the project's rung found again. A rung qualifies only where it finds every such 🔴 and 🟡. -On 2026-10-15, `bin/stability-replay claude-opus-5-5` replayed the latest 10 rounds holding a 🔴 or 🟡, 40 findings in all, 8 of the rounds from this repo. Opus 5.5 at medium, the project's rung, found 29 of them again. Sonnet 5.5 at high missed 13 of those 29, 2 of them 🔴, so no rung below the project's rung qualifies, and Haiku 5.5, below Sonnet on the ladder, was not tried. So the stability reviewer runs where `routing: a chunk's worker runs on the rung its item picks` puts every reviewer: on the project's rung while the worker runs below it. +On 2026-10-15, `bin/stability-replay claude-opus-5-5` replayed the latest 10 rounds holding a 🔴 or 🟡, 40 findings in all, 8 of the rounds from this repo. Opus 5.5 at medium, the project's rung, found 29 of them again. Sonnet 5.5 at high missed 13 of those 29, 2 of them 🔴, so no rung below the project's rung qualifies, and Haiku 5.5, below Sonnet on the ladder, was not tried. So the stability reviewer runs where `routing: a chunk's worker runs on the rung its item's L picks` puts every reviewer: never below the project's rung while the worker runs below it. Valid until a new model joins the ladder, or the archive holds rounds a new reviewer prompt produced: replay then. diff --git a/todo.md b/todo.md index 2252639c..9531bdb8 100644 --- a/todo.md +++ b/todo.md @@ -6,13 +6,12 @@ `Bar = 0.1` -`Next ID = 170` +`Next ID = 172` ## Items | ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score | |---|---|---|---|---|---|---|---|---|---|---|---| -| 166 | 0.2.0 | | question | **Decide whether `docs/decisions.md` names rule-hook's refusal of a review launched below its rung, in `routing:` and in `rule-hook:`.** | 1 | 2 | 1 | 2 | 1 | 1.2 by 3 | 4.4 | | 152 | 0.2.0 | | decision | **Anchor each score level in `rules/todo-items.md` with words, and each project's with two or three items it shipped, and have a scorer compare a new item against them.** | 3 | 2 | 3 | 6 | 4 | 1.1 by 7 | 6.4 | | 50 | 0.2.0 | | principle | **Grant the bench's runs only the tools a review needs, in place of skipping every permission.** | 2 | 2 | 1 | 3 | 2 | 1.1 by 3 | 5.5 | | 65 | 0.2.0 | | defect | **Archive each judge reply the loop rejects.** | 2 | 1 | 3 | 4 | 4 | 3 by 3 | 5.5 | @@ -42,10 +41,12 @@ | 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 | +| 171 | 0.3.0 | | | **Group the routing figures' review rounds by the reviewers' rung as well as the worker's, so a call blames a rung only for rounds its own reviews raised.** | 3 | 2 | 2 | 5 | 4 | 1.2 by 3, 1.4 by 3 | 3.2 | | 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 | | 169 | 0.3.0 | | | **Have rule-hook's `todo-rank-check` catch a `todo.md` that the same Bash call edits and then commits.** | 3 | 1 | 3 | 5 | 3 | 1.1 by 2 | 2.7 | | 122 | 0.4.0 | | | **Assemble the judge's prompt in `bin/loop_claude/cycle/judge.py`, importing only wording the worker also sees, and call the worker "the worker" in it.** | 2 | 2 | 3 | 5 | 3 | 1.1 by 5, 1.4 by 5 | 10.3 | | 158 | 0.4.0 | | decision | **Measure the fixed cost of a chunk from loop-claude's archive, in tokens and hours against its items' S, and set F in `Score = 100 * V / (2**S + F)` to it.** | 2 | 2 | 1 | 3 | 3 | 1.1 by 5, 1.4 by 5 | 10.3 | +| 170 | 0.4.0 | | decision | **Re-tune `WORKER_STEPS` and `REVIEW_STEPS` once 10 chunks have shipped under them, from how well L and E + I order their review rounds and 🔴 findings.** | 2 | 2 | 3 | 5 | 2 | 1.1 by 3, 1.4 by 5 | 10.0 | | 116 | 0.4.0 | | | **Report L by the share of chunks with a 🔴, once 10 chunks that each shipped one item record finding counts and most record no 🔴.** | 1 | 1 | 2 | 2 | 2 | 1.1 by 5 | 9.1 | | 121 | 0.4.0 | | | **Check that `bin/round_titles.py`'s `PASSES` lists exactly the passes of larv-review §3's table.** | 1 | 1 | 1 | 1 | 2 | 1.1 by 5 | 9.1 | | 112 | 0.4.0 | | | **Count an item as shipped only where its chunk built it, so an item a chunk dropped from the plan gets no outcome.** | 3 | 2 | 2 | 5 | 3 | 1.1 by 6 | 8.2 | @@ -82,10 +83,6 @@ ## Details -### 166. Decide whether `docs/decisions.md` names rule-hook's refusal of a review launched below its rung, in `routing:` and in `rule-hook:`. - -Item 163 (PR #295) has rule-hook refuse a review launch below the rung loop-claude gives its worker. The routing decision still says loop-claude's prompt has the worker launch reviewers, comprehension seats and the security pass on the project's rung, and does not name the hook. Recommendation: amend that paragraph to say rule-hook refuses a launch below the rung too. The decision was held before the chunk began, so the human decides. The `rule-hook:` entry's title says a marker overrides one rule, and `reviewer-rung` takes none. The amendment need not give the reason no marker waives the rule: the comment above `reviewer-rung` in bin/rule_hook/rules.py records it. - ### 152. Anchor each score level in `rules/todo-items.md` with words, and each project's with two or three items it shipped, and have a scorer compare a new item against them. LLM ratings drift to the middle of an unanchored scale, and worked examples cut estimation error. A project's anchors are shipped items, cited by ID and commit, chosen from what `score-outcomes` measured for them. @@ -229,6 +226,10 @@ lilleman asked, on 2026-10-16, for a standing audit each release, so the loop ke The chunk that ships this item files a copy of it in the release after the one it audits, rewording "0.2.0" to the release that copy audits, and marks the copy `owner`, so the audit recurs each release until lilleman drops it. +### 171. Group the routing figures' review rounds by the reviewers' rung as well as the worker's, so a call blames a rung only for rounds its own reviews raised. + +Raised by the goals audit of PR #296. `bin/routing_figures/measure.py` groups a chunk's review rounds by the rung its worker started on, and calls for a routing change when a lower rung took more of them. Since PR #296 the reviewers run on the rung their item's E + I picks, apart from the worker's, and the archive does not record it. A cheap worker on an item of high E + I gets stronger reviewers, who may raise more rounds, and a call could then blame the worker's rung for them: an interrupt of lilleman that settles nothing (goal 1.2). + ### 165. 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. A test audit across lilleman's projects on 2026-10-16 found 10 of 33 sampled tests in this repo pinning wording that is not the contract. Examples of these and other weak tests: `bin/loop_claude/test_loop_claude.py:165`, `:271` and most asserts in `:664` to `:687` pin whole sentences of the question, archive or prompt text, up to about 750 characters, and `:864` asserts help-text wording. `:906` and `:936` parse the source with `ast` and list each `Stop(...)` and `Failure(...)` call by function name. `bin/model_routing/test_ladder.py:16` asserts `len(LADDER) == 11`. Rewrite each to the technical principles' test bullet: assert the facts the text must carry, such as an item ID, a rung or a model argument, and delete a test no real bug could fail. Before and after rewriting a test, run the mutation tool on the code it covers: every mutant the old test killed, the new one kills. @@ -245,6 +246,10 @@ All four seats of PR #257's scoring run named `bin/loop_claude/cycle/judge.py:16 F is 8 until then, about one S 3 change, lilleman's call in PR #283. A chunk costs more than its size: the worker reads about 130k tokens before its first commit whatever the item, and every chunk takes its review passes. Fit cost against 2**S from the finished chunks `score-outcomes` measures, in the same units `2**S` counts, and say in `docs/decisions.md` → `todo.md: …` how far the fit holds. A chunk bundling tiny items shares F between them. +### 170. Re-tune `WORKER_STEPS` and `REVIEW_STEPS` once 10 chunks have shipped under them, from how well L and E + I order their review rounds and 🔴 findings. + +`docs/decisions.md` → `routing: one ladder…` calls the steps lilleman approved on 2026-10-16 a first guess. Once 10 chunks that each shipped one item scored with L, E and I have merged, read `score-outcomes`' rank correlations for L, E and I and the routed-chunks table of `routing-figures.md`, and propose new steps to lilleman, whose call they are. A change to the steps appends a `Reset` to `routing-calls-raised.md` once merged, as `AGENTS.md` says. + ### 116. Report L by the share of chunks with a 🔴, once 10 chunks that each shipped one item record finding counts and most record no 🔴. `score-outcomes` reports the median 🔴 count at each guessed R, and how well L orders chunks by 🔴 findings; the part of R a 🔴 tests is L. Where most chunks have no 🔴, every median reads 0 and the rank correlation reads none, which tells a scorer nothing. No round title held counts before PR #254, so how often a chunk has a 🔴 is not yet known.