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
+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 ""}