From d7193f65da780cc0dd6a4bbcd97b597c9953df14 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 15 Oct 2026 16:28:11 +0200 Subject: [PATCH] =?UTF-8?q?Answer=20stability=20round=201:=201=20?= =?UTF-8?q?=F0=9F=94=B4,=206=20=F0=9F=9F=A1;=20keep=20the=20marker=20in=20?= =?UTF-8?q?model=5Frouting=20so=20routing=5Ffigures=20imports=20nothing=20?= =?UTF-8?q?of=20loop=5Fclaude,=20total=20escalations=20across=20every=20ch?= =?UTF-8?q?unk,=20fold=20CLAUDE.md's=20subagent=20rung=20rules=20into=20on?= =?UTF-8?q?e=20ordered=20rule?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CLAUDE.md | 10 ++++++-- bin/loop_claude/cycle/prompts.py | 16 ++++++------- bin/loop_claude/routing.py | 3 +-- bin/loop_claude/test_loop_claude.py | 3 ++- bin/model_routing/route.py | 2 ++ bin/routing_figures/measure.py | 26 ++++++++++++++------- bin/routing_figures/test_routing_figures.py | 4 +++- docs/decisions.md | 2 +- todo.md | 2 +- 9 files changed, 44 insertions(+), 24 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index f0fb5e33..5ee8cb6e 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -52,13 +52,19 @@ The rules only reviewers apply, for quality, comments, READMEs and prose, live i - Keep the project's main checkout (e.g. `~/code/log`, never a worktree) current: when it is behind `origin` โ€” a merge landed, or a fetch shows it โ€” run `git pull --ff-only` there instead of reporting the lag, never with `--autostash`: a dirty checkout is a finding to report, not to carry along. - Run a project's language runtime, package manager, and task runner through its container/tooling setup, never directly on the host unless a decision puts them there. Example: `docker compose run --rm app โ€ฆ`. - Tear down test containers after a run. -- Delegate a task to a subagent only when you need just its conclusion: a search or read across many files, or work independent enough to run in parallel. Keep edits, and whatever you must check line by line, in your own thread: you would read a delegated diff again to check it. Score the task's R and C as for a `todo.md` item. Launch the subagent with the model and effort that `~/.claude/bin/subagent-rung ` prints. `` is the project's model id, such as `claude-opus-5-5`: the one loop-claude's prompt names as the project's, or else your own. A reviewer, a comprehension seat or the security pass takes the model and effort loop-claude's prompt gives it; given none, launch it with no model or effort, so it runs on your model. A subagent that files or scores `todo.md` items takes the rung `~/.claude/bin/subagent-rung --plan ` prints, which is never below the project's. +- Delegate a task to a subagent only when you need just its conclusion: a search or read across many files, or work independent enough to run in parallel. Keep edits, and whatever you must check line by line, in your own thread: you would read a delegated diff again to check it. Launch the subagent with the model and effort of the first case that fits: + 1. A reviewer, a comprehension seat or the security pass: those loop-claude's prompt gives it. Given none, pass no model or effort, so it runs on your model. + 2. An escalated task, below: the rung loop-claude's prompt names for escalation. + 3. A subagent that files or scores `todo.md` items: what `~/.claude/bin/subagent-rung --plan ` prints, which is never below the project's rung. + 4. Any other: what `~/.claude/bin/subagent-rung ` prints. + + Score the task's R and C as for a `todo.md` item. `` is the project's model id, such as `claude-opus-5-5`: the one loop-claude's prompt names as the project's, or else your own. - Escalate a task that proves too hard for your rung. Three triggers say so: 1. A re-score of the item, made on the project's rung or above, picks a rung above yours. 2. The same failing test or finding survives two fix attempts. 3. A pass reports a ๐Ÿ”ด in round 2 or later. - When one fires, hand the hard part, edits included, to a subagent on the rung loop-claude's prompt names, one above yours. Cite the trigger and its evidence in the subagent's prompt, in the words loop-claude's prompt gives. Each later subagent on that task runs on that rung or higher, and each further trigger moves it one rung up, to at most the highest rung the prompt names. Ask the human before going higher, or when no prompt names a rung. + When one fires, hand the hard part, edits included, to a subagent on the rung loop-claude's prompt names, one above yours. Cite the trigger and its evidence in the subagent's prompt, in the words loop-claude's prompt gives. Each later subagent on that task runs on that rung or higher, and each further trigger moves it one rung up, to at most the highest rung the prompt names. Ask the human before going higher. Where loop-claude's prompt names no escalation, as on the ladder's top rung or off it, keep the task in your own thread. - Give a subagent only the access its job needs, and state the limits in its prompt. One that only reads, such as a prose review, gets no shell and no edits. One that probes a build tags the image as throwaway and removes it afterwards, writes only to the session scratchpad, and removes no image or file it did not create. - Check `README.md` first for build, test, install, and codegen commands, and fix one that misbehaves in the same change. Refresh `README.md` whenever you change what it describes, keeping it true, not longer. - Where `~/.claude/bin/rule-hook` does not check it, such as an image named in test code, a Kubernetes manifest, a `docker run` line or a file a Bash command writes, pin a container image to its full patch version and a GitHub Action to a semver tag. diff --git a/bin/loop_claude/cycle/prompts.py b/bin/loop_claude/cycle/prompts.py index 05cbbfff..718739bd 100644 --- a/bin/loop_claude/cycle/prompts.py +++ b/bin/loop_claude/cycle/prompts.py @@ -1,8 +1,8 @@ -from loop_claude.routing import ESCALATION_MARKER, escalation_rungs -from model_routing.ladder import highest, LADDER, Rung +from model_routing.ladder import climbed, highest, LADDER, 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 from markdown_text import quoted -from model_routing.route import Route def either(names: tuple[str, ...]) -> str: """The names as `a, b or c`.""" @@ -17,8 +17,8 @@ ANSWERS_RECORDED = f"every answer the human typed in it that a later chunk could def fresh(task: str, premises: str, route: Route, anchor: Rung | None) -> str: - # A chunk no item routed gets no route paragraph, but may still escalate. - routed = f"{routed_by(route, anchor)}\n\n" if route.item else "".join(f"{text.lstrip()}\n\n" for text in [escalation(route, anchor)] if text) + escalated = escalation(route, anchor).lstrip() + routed = f"{routed_by(route, anchor)}\n\n" if route.item else (f"{escalated}\n\n" if escalated else "") return f"{task}\n\nContinue any open draft PR or worktree for the chunk before creating a new one.\n\n{routed}The chunk's todo.md items, or else the task above, set its scope. The goals below choose between ways to deliver that scope, and never widen it.\n\nFrom README.md:\n{premises}" @@ -27,7 +27,7 @@ def routed_by(route: Route, anchor: Rung | None) -> str: def off_the_projects_rung(route: Route, anchor: Rung | None) -> str: - """Which subagents to launch on the project's rung, anchor, and below it which on the --plan rung; empty while the worker runs on anchor, as every chunk no item routed starts (routing.first_route).""" + """Which subagents to launch on the project's rung, anchor, and below it which on the --plan rung; empty while the worker runs on anchor, as every chunk no item routed does until it steps up.""" if anchor is None or route.rung == anchor: return "" # Below the project's rung, the reviewers stay on it to hold quality; above it, the seats score every chunk on one rung, and the security pass spends no more than the project chose. @@ -38,13 +38,13 @@ def off_the_projects_rung(route: Route, anchor: Rung | None) -> str: def escalation(route: Route, anchor: Rung | None) -> str: - """The rungs routing.escalation_rungs opens to the worker, and how to mark an escalated subagent's prompt; empty off the ladder or on its top rung.""" + """The rungs an escalation trigger opens to the worker, from one above its own up to two above the rung its chunk started on, and how to mark an escalated subagent's prompt; empty off the ladder or on its top rung.""" if anchor is None or route.rung not in LADDER[:-1]: return "" marked = f" Open the subagent's prompt with `{ESCALATION_MARKER} :`, n the trigger's number." rungs = [f"`{rung.agent_args()}`" for rung in escalation_rungs(anchor, route)] if not rungs: - return f" An escalation trigger in `~/.claude/CLAUDE.md` lets you hand a task to a subagent above your rung only once the human agrees.{marked}" + return f" An escalation trigger in `~/.claude/CLAUDE.md` lets you hand a task to a subagent with the Agent tool set to `{climbed(route.rung, 1).agent_args()}`, one rung above yours, only once the human agrees.{marked}" further = f", and on each further trigger one rung higher, up to {rungs[-1]}" if len(rungs) > 1 else "" return f" When an escalation trigger in `~/.claude/CLAUDE.md` fires, hand the task to a subagent with the Agent tool set to {rungs[0]}, one rung above yours{further}; above that, ask the human first.{marked}" diff --git a/bin/loop_claude/routing.py b/bin/loop_claude/routing.py index 4ee3d353..657511b2 100644 --- a/bin/loop_claude/routing.py +++ b/bin/loop_claude/routing.py @@ -7,9 +7,8 @@ from todo_table import Item, items from model_routing.route import Route UNFINISHED_PER_STEP = 2 -# How many rungs above item_rung the worker may escalate a task without the human's yes, and how it opens an escalated subagent's prompt: docs/decisions.md โ†’ `routing: a worker hands a task one rung up`. +# How many rungs above item_rung the worker may escalate a task without the human's yes: docs/decisions.md โ†’ `routing: a worker hands a task one rung up`. ESCALATION_CAP = 2 -ESCALATION_MARKER = "Escalation trigger" # The models `judge-replay` found returning, on their cheapest rung, every verdict the reference judge reproduced: docs/decisions.md โ†’ `routing: on a model judge-replay covered`. JUDGE_REPLAYED = ("claude-opus-5-5",) diff --git a/bin/loop_claude/test_loop_claude.py b/bin/loop_claude/test_loop_claude.py index 5c537a3e..5198155f 100644 --- a/bin/loop_claude/test_loop_claude.py +++ b/bin/loop_claude/test_loop_claude.py @@ -662,8 +662,9 @@ class WorkerArgs(unittest.TestCase): fresh = prompts.fresh("Do it.", "## Goals", Route(opus, 3, 9), opus) self.assertIn("whether or not it is item 3. When an escalation trigger in `~/.claude/CLAUDE.md` fires, hand the task to a subagent with the Agent tool set to `model opus, effort high`, one rung above yours, and on each further trigger one rung higher, up to `model opus, effort xhigh`; above that, ask the human first. Open the subagent's prompt with `Escalation trigger :`, n the trigger's number.\n\n", fresh) self.assertTrue(prompts.resumed("", Route(Rung("claude-opus-5-5", "high"), 3, 9), opus).endswith(" When an escalation trigger in `~/.claude/CLAUDE.md` fires, hand the task to a subagent with the Agent tool set to `model opus, effort xhigh`, one rung above yours; above that, ask the human first. Open the subagent's prompt with `Escalation trigger :`, n the trigger's number.")) - self.assertTrue(prompts.resumed("", Route(Rung("claude-opus-5-5", "xhigh"), 3, 9), opus).endswith(" An escalation trigger in `~/.claude/CLAUDE.md` lets you hand a task to a subagent above your rung only once the human agrees. Open the subagent's prompt with `Escalation trigger :`, n the trigger's number.")) + self.assertTrue(prompts.resumed("", Route(Rung("claude-opus-5-5", "xhigh"), 3, 9), opus).endswith(" An escalation trigger in `~/.claude/CLAUDE.md` lets you hand a task to a subagent with the Agent tool set to `model opus, effort max`, one rung above yours, only once the human agrees. Open the subagent's prompt with `Escalation trigger :`, n the trigger's number.")) self.assertNotIn("escalation", prompts.resumed("", Route(Rung("claude-fable-5-1", "max"), 3, 20), opus)) + self.assertIn("hand the task to a subagent with the Agent tool set to `model fable, effort max`, one rung above yours;", prompts.resumed("", Route(Rung("claude-opus-5-5", "max"), 3, 13), opus)) self.assertNotIn("escalation", prompts.resumed("", Route(Rung("m")), None)) self.assertNotIn("escalation", prompts.resumed("", Route(Rung("claude-opus-5-5", "low"), 3, 9), opus)) self.assertIn("before creating a new one.\n\nWhen an escalation trigger in `~/.claude/CLAUDE.md` fires, hand the task to a subagent with the Agent tool set to `model opus, effort high`, one rung above yours, and on each further trigger one rung higher, up to `model opus, effort xhigh`; above that, ask the human first. Open the subagent's prompt with `Escalation trigger :`, n the trigger's number.\n\nThe chunk's", prompts.fresh("Do it.", "## Goals", Route(opus), opus)) diff --git a/bin/model_routing/route.py b/bin/model_routing/route.py index a4677520..ad626fa7 100644 --- a/bin/model_routing/route.py +++ b/bin/model_routing/route.py @@ -4,6 +4,8 @@ import re 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" ROUTED = re.compile(r"(?P\S+) at (?P\S+) effort(?:, routed by item (?P[0-9]+)'s R \+ C of (?P[0-9]+))?") diff --git a/bin/routing_figures/measure.py b/bin/routing_figures/measure.py index 315a0673..233e5f04 100644 --- a/bin/routing_figures/measure.py +++ b/bin/routing_figures/measure.py @@ -7,10 +7,9 @@ import typing from claude_code.entries import assistant_parts, parts, tool_call, usage_count from git_command import commits -from loop_claude.routing import ESCALATION_MARKER +from model_routing.route import ESCALATION_MARKER, route_from from model_routing.ladder import position, Rung from round_titles import round_counts -from model_routing.route import route_from from shell_command import simple_commands from transcript_archive.outcomes import UNFINISHED_AT, workers @@ -66,11 +65,12 @@ class ChunkFigures: @dataclasses.dataclass(frozen=True) class Figures: - """skipped names each chunk folder the archive could not read whole.""" + """escalated counts every chunk's escalations by trigger, routed or not; skipped names each chunk folder the archive could not read whole.""" chunks: int tokens: dict[str, collections.Counter[str]] routed: dict[Rung, list[ChunkFigures]] reports: dict[str, Reports] + escalated: collections.Counter[int] skipped: tuple[str, ...] = () @@ -204,7 +204,7 @@ def totals(chunks: list[ChunkFigures], skipped: tuple[str, ...] = ()) -> Figures routed.setdefault(chunk.start, []).append(chunk) for kind, found in chunk.reports.items(): reports[kind] = reports.get(kind, Reports(0, 0, 0)) + found - return Figures(len(chunks), tokens, routed, reports, skipped) + return Figures(len(chunks), tokens, routed, reports, summed(chunks, lambda chunk: chunk.escalated), skipped) def calls(figures: Figures) -> list[str]: @@ -234,9 +234,10 @@ def render(figures: Figures, found: list[str], at: str, cycle: int, since: str) *[part for dimension in DIMENSIONS for part in (f"## Tokens by {dimension}", table((dimension.capitalize(), "Tokens"), [(label, str(tokens)) for label, tokens in figures.tokens[dimension].most_common()]))], "## Routed chunks by the rung they started on", table(("Rung", "Chunks", "Review rounds past each pass's first, mean", "Unfinished verdicts, mean", "Subagent rungs", "Escalations by trigger"), [ - (str(rung), str(len(chunks)), f"{mean(chunks, lambda chunk: chunk.rounds_past_first):.1f}", f"{mean(chunks, lambda chunk: chunk.unfinished):.1f}", ", ".join(f"{label} {times}" for label, times in sum((chunk.delegated for chunk in chunks), collections.Counter()).most_common()), escalated(chunks)) + (str(rung), str(len(chunks)), f"{mean(chunks, lambda chunk: chunk.rounds_past_first):.1f}", f"{mean(chunks, lambda chunk: chunk.unfinished):.1f}", subagent_rungs(chunks), triggers(summed(chunks, lambda chunk: chunk.escalated))) for rung, chunks in sorted(figures.routed.items(), key=lambda item: position(item[0])) ]), + f"Escalations by trigger across every chunk, routed or not: {triggers(figures.escalated) or 'none'}.", "## Subagent reports against the searches they ran, in characters", table(("Subagent type", "Subagents", "Reports", "Searches"), [(kind, str(found.subagents), str(found.report), str(found.searches)) for kind, found in sorted(figures.reports.items())]), *(["## Chunks skipped, unreadable", "".join(f"- {folder}\n" for folder in figures.skipped).rstrip("\n")] if figures.skipped else []), @@ -244,9 +245,18 @@ def render(figures: Figures, found: list[str], at: str, cycle: int, since: str) return "\n\n".join(sections) + "\n" -def escalated(chunks: list[ChunkFigures]) -> str: - """The chunks' escalations as `trigger 2: 3, trigger 3: 1`.""" - return ", ".join(f"trigger {trigger}: {times}" for trigger, times in sorted(sum((chunk.escalated for chunk in chunks), collections.Counter()).items())) +def summed(chunks: list[ChunkFigures], of: typing.Callable[[ChunkFigures], collections.Counter]) -> collections.Counter: + return sum(map(of, chunks), collections.Counter()) + + +def subagent_rungs(chunks: list[ChunkFigures]) -> str: + """The rungs the chunks' subagents ran on, most used first, as `claude-opus-5-5 at high effort 2, โ€ฆ`.""" + return ", ".join(f"{label} {times}" for label, times in summed(chunks, lambda chunk: chunk.delegated).most_common()) + + +def triggers(escalated: collections.Counter[int]) -> str: + """Escalations as `trigger 2: 3, trigger 3: 1`.""" + return ", ".join(f"trigger {trigger}: {times}" for trigger, times in sorted(escalated.items())) def table(header: tuple[str, ...], rows: list[tuple[str, ...]]) -> str: diff --git a/bin/routing_figures/test_routing_figures.py b/bin/routing_figures/test_routing_figures.py index 77a429ad..16e0a55a 100644 --- a/bin/routing_figures/test_routing_figures.py +++ b/bin/routing_figures/test_routing_figures.py @@ -155,7 +155,9 @@ class Calls(unittest.TestCase): two = ChunkFigures({}, HIGH, 0, 1, collections.Counter({str(HIGH): 2, str(LOW): 1}), {}, collections.Counter()) self.assertIn(f"| {LOW} | 1 | 1.0 | 0.0 | {HIGH} 2 | |\n| {HIGH} | 1 | 0.0 | 1.0 | {HIGH} 2, {LOW} 1 | |", render(totals([two, chunk]), [], "2026-10-15T00:00:00Z", 40, "")) self.assertIn("| Explore | 2 | 3 | 4 |", text) - self.assertIn(f"| {LOW} | 2 | 0.0 | 0.0 | | trigger 2: 3, trigger 10: 1 |", render(totals([figures(escalated={2: 2}), figures(escalated={2: 1, 10: 1})]), [], "2026-10-15T00:00:00Z", 40, "")) + escalated = render(totals([figures(escalated={2: 2}), figures(escalated={2: 1, 10: 1}), figures(start=None, escalated={3: 1})]), [], "2026-10-15T00:00:00Z", 40, "") + self.assertIn(f"| {LOW} | 2 | 0.0 | 0.0 | | trigger 2: 3, trigger 10: 1 |\n\nEscalations by trigger across every chunk, routed or not: trigger 2: 3, trigger 3: 1, trigger 10: 1.\n", escalated) + self.assertIn("Escalations by trigger across every chunk, routed or not: none.\n", text) self.assertIn("## Calls for a routing change\n\nNone.\n", render(totals([]), [], "2026-10-15T00:00:00Z", 20, "")) self.assertIn("from 0 finished chunks that finished after the reset of 2026-10-14T00:00:00Z.", render(totals([]), [], "2026-10-15T00:00:00Z", 20, "2026-10-14T00:00:00Z")) diff --git a/docs/decisions.md b/docs/decisions.md index ca84275f..32d8b7ab 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -200,7 +200,7 @@ Valid while the index ranks these models, and while no newer model joins the cat Three triggers in `CLAUDE.md` โ†’ "Working with the codebase" mark a task too hard: a re-score of the item on the project's rung or above picks a higher rung, the same failing test or finding survives two fix attempts, or a pass reports a ๐Ÿ”ด in round 2 or later. When one fires, the worker hands the hard part to a subagent one rung above its own, edits included, though the delegation rule keeps edits in the worker's thread: the escalation exists because the worker could not get them right. Each further trigger on that task climbs one more rung. Without lilleman's yes the climb stops two rungs above the rung the chunk's item picks, the rung the chunk started on, or the project's rung for a chunk no item routed. A step-up between cycles raises the worker but not that limit: lilleman set the limit from the rung the chunk started on, so a worker that has stepped up may need a yes for its first escalation. -loop-claude's prompt names the rungs a trigger opens, so the worker computes no rung positions, and tells the worker to open each escalated subagent's prompt with `Escalation trigger :`. `bin/loop_claude/routing.py` holds the limit and that marker. The archive keeps the raw transcript, which holds the marked prompt, and `bin/routing_figures/` counts the escalations by trigger for each rung routed chunks started on, in `routing-figures.md`. +loop-claude's prompt names the rungs a trigger opens, so the worker computes no rung positions, and tells the worker to open each escalated subagent's prompt with `Escalation trigger :`. `bin/loop_claude/routing.py` holds the limit, and `bin/model_routing/route.py` the marker, beside the other words the archive records, since both loop-claude and `bin/routing_figures/` read it. The archive keeps the raw transcript, which holds the marked prompt, and `bin/routing_figures/` counts the escalations by trigger for each rung routed chunks started on, in `routing-figures.md`. Valid while the ladder orders its rungs by competence. diff --git a/todo.md b/todo.md index 9b01fa40..dc670745 100644 --- a/todo.md +++ b/todo.md @@ -91,7 +91,7 @@ Release 0.2.0 takes items 125, 114 and 124 first, whatever their scores: Shape i The human asked for this on 2026-10-15, and for the worker to escalate too. A reviewer rules the work below standard when it reports an architect BLOCK or a finding against `skills/larv-review/standards/quality.md`. It may then ask for its pass to rerun one rung up, and that rerun counts toward no round cap. A comprehension seat rules it below standard when it votes "worse" in a paired ruling. It may then ask for the ruling to rerun with its seat one rung up. Either ruling becomes a fourth escalation trigger in `CLAUDE.md` โ†’ "Working with the codebase". No ruling raises the judge's own rung. -This revises `docs/decisions.md` โ†’ `routing: one ladder`, which launches the reviewers on the project's rung while the worker runs below it, and on the worker's rung otherwise. It also revises `review: a pass gets at most three rounds per chunk`. Which rung a subagent gets is spread over three rules in `CLAUDE.md` โ†’ "Working with the codebase" (delegation, planning subagents and reviewers, escalation) and `bin/loop_claude/cycle/prompts.py`'s `off_the_projects_rung` and `escalation`; fold the `CLAUDE.md` rules into one ordered rule as this item adds its trigger. The comprehension seats found larv-review ยง3's "Round cap" hard to read; word the exception so "Round cap" gets easier to read, or land it in item 120's table. +This revises `docs/decisions.md` โ†’ `routing: one ladder`, which launches the reviewers on the project's rung while the worker runs below it, and on the worker's rung otherwise. It also revises `review: a pass gets at most three rounds per chunk`. The comprehension seats found larv-review ยง3's "Round cap" hard to read; word the exception so "Round cap" gets easier to read, or land it in item 120's table. ### 145. Run the stability reviewer on the worker's rung while the worker runs below the project's rung, once a replay of past stability rounds on that rung finds the ๐Ÿ”ด and ๐ŸŸก findings on record.