From f319a96e7e4669fc35892373dea1f715dce5047b Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 16 Oct 2026 12:18:03 +0200 Subject: [PATCH] =?UTF-8?q?Answer=20architecture=20round=202:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1;=20join=20prose=20lists=20with?= =?UTF-8?q?=20one=20markdown=5Ftext.listed,=20and=20floor=20the=20replays?= =?UTF-8?q?=20at=20lowest=5Fworker=5Frung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/judge_replay/main.py | 2 +- bin/loop_claude/cycle/judge.py | 5 +++-- bin/loop_claude/cycle/prompts.py | 16 +++------------- bin/markdown_text.py | 6 ++++++ bin/model_routing/ladder.py | 5 +++++ bin/model_routing/test_ladder.py | 5 ++++- bin/rank_todo.py | 15 +++++---------- bin/rung_replay/command.py | 6 +++--- bin/rung_replay/test_rung_replay.py | 5 ++--- bin/stability_replay/main.py | 2 +- bin/test_markdown_text.py | 7 +++++++ 11 files changed, 40 insertions(+), 34 deletions(-) diff --git a/bin/judge_replay/main.py b/bin/judge_replay/main.py index a121a8b2..3c406497 100644 --- a/bin/judge_replay/main.py +++ b/bin/judge_replay/main.py @@ -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 ladder's bottom rung. It stops at the first rung that misses one. It prints each +to the lowest rung a worker routes to. 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 diff --git a/bin/loop_claude/cycle/judge.py b/bin/loop_claude/cycle/judge.py index e8d7bfa2..ecfcde51 100644 --- a/bin/loop_claude/cycle/judge.py +++ b/bin/loop_claude/cycle/judge.py @@ -3,12 +3,13 @@ import json import re import typing -from loop_claude.cycle.prompts import ANSWER_DESTINATIONS, ANSWERS_RECORDED, either +from loop_claude.cycle.prompts import ANSWER_DESTINATIONS, ANSWERS_RECORDED from claude_code.reply import claude_reply, Limited from loop_claude.effects import Effects from failure import Failure from loop_claude.project.records import HUMAN_RULE_NAMES from todo_table import LEVELS +from markdown_text import listed from loop_claude.cycle.retry import retried from model_routing.ladder import Rung from loop_claude.stop import Stop @@ -45,7 +46,7 @@ JUDGE_RULES = ( f"its own. Even then, it is finished only once {ANSWERS_RECORDED}. An answer counts as recorded " f"where README.md or the records above hold it, {', '.join(HUMAN_RULE_NAMES)} included. It also counts where " f"the transcript shows the agent writing it into {ANSWER_DESTINATIONS}; writing it into " - f"{either(HUMAN_RULE_NAMES)} does not count. finished=false when work remains that a further run can " + f"{listed(HUMAN_RULE_NAMES, 'or')} does not count. finished=false when work remains that a further run can " "continue: an open PR, a review not yet run, CI not yet reported, an answer not yet recorded." ) diff --git a/bin/loop_claude/cycle/prompts.py b/bin/loop_claude/cycle/prompts.py index f88500fb..822d1bbf 100644 --- a/bin/loop_claude/cycle/prompts.py +++ b/bin/loop_claude/cycle/prompts.py @@ -2,15 +2,10 @@ from model_routing.ladder import climbed, LADDER, position, review_rungs, Review 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 -from markdown_text import quoted - -def either(names: tuple[str, ...]) -> str: - """The names as `a, b or c`.""" - return f"{', '.join(names[:-1])} or {names[-1]}" - +from markdown_text import listed, quoted # Where the judge may quote an answer from, named as the human and the worker see them; of README.md the judge sees only the premises. -QUOTE_SOURCES = either(("README.md's Goals and Audience", *RECORD_FILES, *HUMAN_RULE_NAMES)) +QUOTE_SOURCES = listed(("README.md's Goals and Audience", *RECORD_FILES, *HUMAN_RULE_NAMES), "or") # 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" @@ -40,17 +35,12 @@ def review_launches(route: Route, anchor: Rung | None) -> str: 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()) + launches = "".join(f" Launch {listed(reviews, 'and')} 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} ` 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" diff --git a/bin/markdown_text.py b/bin/markdown_text.py index fa01e7e7..3d908d5e 100644 --- a/bin/markdown_text.py +++ b/bin/markdown_text.py @@ -1,4 +1,5 @@ import re +import typing FENCE = re.compile(r"^ {0,3}(`{3,}|~{3,})", re.M) @@ -30,3 +31,8 @@ def sections(text: str) -> dict[str, list[str]]: # Blockquoted, so a passage holding blank lines still ends visibly where the text after it starts. def quoted(passage: str) -> str: return "\n".join(f"> {line}" for line in passage.splitlines()) + + +def listed(names: typing.Sequence[str], conjunction: str) -> str: + """The names as `a, b and c`, with conjunction, such as and or or, before the last.""" + return names[0] if len(names) == 1 else f"{', '.join(names[:-1])} {conjunction} {names[-1]}" diff --git a/bin/model_routing/ladder.py b/bin/model_routing/ladder.py index d95ea13b..23f49f3e 100644 --- a/bin/model_routing/ladder.py +++ b/bin/model_routing/ladder.py @@ -75,6 +75,11 @@ def worker_rung(project: Rung, likelihood: int) -> Rung: return climbed(project, WORKER_STEPS[likelihood]) +def lowest_worker_rung(project: Rung) -> Rung: + """The lowest rung any L routes a worker to, counted from the project's rung.""" + return climbed(project, min(WORKER_STEPS.values())) + + 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)) diff --git a/bin/model_routing/test_ladder.py b/bin/model_routing/test_ladder.py index 293ec1f9..84d82327 100644 --- a/bin/model_routing/test_ladder.py +++ b/bin/model_routing/test_ladder.py @@ -4,7 +4,7 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) -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 model_routing.ladder import highest, LADDER, lowest_worker_rung, 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") @@ -42,6 +42,9 @@ class Ladder(unittest.TestCase): 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_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)) + 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")) diff --git a/bin/rank_todo.py b/bin/rank_todo.py index f7125052..1c31ebd4 100755 --- a/bin/rank_todo.py +++ b/bin/rank_todo.py @@ -78,7 +78,7 @@ import typing 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 markdown_text import FENCE, listed, sections from file_writes import replace_file LARGEST_FORMULA = 200 @@ -293,9 +293,9 @@ def read_table(lines: list[str]) -> Table | Failure: 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 "" - 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}") + dropped = f", and drop {listed(old, 'and')}" if old else "" + columns = f"{listed(missing, 'and')} column; add it" if len(missing) == 1 else f"{listed(missing, 'and')} columns; add them" + return Failure(f"todo.md's items table has no {columns}, scoring each item's {listed(shape.risk_columns, 'and')} as rank_todo.py --help shows{dropped}") return unknown_columns(table, shape) or outside_items(lines, table) or table @@ -304,7 +304,7 @@ def unknown_columns(table: Table, shape: Shape) -> Failure | None: 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") + return Failure(f"todo.md's items table has {listed(old, 'and')}, {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(shape.columns)}. Rename it, or move this machine to the release that added it") return None @@ -315,11 +315,6 @@ def older_columns(table: Table, shape: Shape) -> list[str]: 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: - """The names as `a, b and c`.""" - return names[0] if len(names) == 1 else f"{', '.join(names[:-1])} and {names[-1]}" - - def read_items(table: Table, scoring: Scoring) -> list[Item] | Failure: items = [] for row in table.rows: diff --git a/bin/rung_replay/command.py b/bin/rung_replay/command.py index 45f8e49a..792b6c7c 100644 --- a/bin/rung_replay/command.py +++ b/bin/rung_replay/command.py @@ -3,7 +3,7 @@ import pathlib import sys from failure import Failure -from model_routing.ladder import LADDER, position, project_rung, Rung +from model_routing.ladder import LADDER, lowest_worker_rung, 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 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] + """top, the project's rung, and each rung below it, highest first, down to the lowest rung a worker routes to: no route uses a rung below it, so a replay there could change no routing.""" + return list(LADDER[position(lowest_worker_rung(top)):position(top) + 1])[::-1] def limited_exit(tool: str, limited: Limited) -> int: diff --git a/bin/rung_replay/test_rung_replay.py b/bin/rung_replay/test_rung_replay.py index 19f147d1..214d2283 100644 --- a/bin/rung_replay/test_rung_replay.py +++ b/bin/rung_replay/test_rung_replay.py @@ -63,9 +63,8 @@ class FirstReply(unittest.TestCase): class DownFrom(unittest.TestCase): - 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")) + def test_runs_from_the_projects_rung_down_to_the_lowest_rung_a_worker_routes_to(self): + self.assertEqual(down_from(REFERENCE), [REFERENCE, MIDDLE, CHEAP]) if __name__ == "__main__": diff --git a/bin/stability_replay/main.py b/bin/stability_replay/main.py index 6d03cb16..ade70ae4 100644 --- a/bin/stability_replay/main.py +++ b/bin/stability_replay/main.py @@ -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 ladder's bottom rung, and stops at the first rung +rung below, highest first, down to the lowest rung a worker routes to, 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 diff --git a/bin/test_markdown_text.py b/bin/test_markdown_text.py index f069da32..8b4dea08 100644 --- a/bin/test_markdown_text.py +++ b/bin/test_markdown_text.py @@ -21,5 +21,12 @@ class Sections(unittest.TestCase): self.assertEqual(markdown_text.quoted("merged\n\nPR #1"), "> merged\n> \n> PR #1") +class Listed(unittest.TestCase): + def test_joins_names_with_commas_and_the_conjunction_before_the_last(self): + self.assertEqual(markdown_text.listed(["a"], "and"), "a") + self.assertEqual(markdown_text.listed(["a", "b"], "and"), "a and b") + self.assertEqual(markdown_text.listed(("a", "b", "c"), "or"), "a, b or c") + + if __name__ == "__main__": unittest.main()