Generalise stability-replay to review-replay of any pass, and route each pass on its own rung so a replay may lower one pass alone
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from model_routing.ladder import climbed, LADDER, position, review_rungs, ReviewKind, Rung
|
||||
from model_routing.ladder import climbed, LADDER, position, review_rungs, REVIEWERS, ReviewKind, Rung
|
||||
from model_routing.route import ESCALATION_MARKER, HIGHEST_ESCAPE_AND_IMPACT, Route
|
||||
from loop_claude.routing import escalation_rungs
|
||||
from loop_claude.project.records import HUMAN_RULE_NAMES, RECORD_FILES
|
||||
@@ -10,8 +10,8 @@ QUOTE_SOURCES = listed(("README.md's Goals and Audience", *RECORD_FILES, *HUMAN_
|
||||
# Where the worker may write an answer the human typed, so it counts as recorded.
|
||||
ANSWER_DESTINATIONS = "README.md's Goals or Audience, " + ", ".join(RECORD_FILES) + ", todo.md or a comment"
|
||||
ANSWERS_RECORDED = f"every answer the human typed in it that a later chunk could need is recorded in {ANSWER_DESTINATIONS} at the one place it governs"
|
||||
# Each kind of review, as review_launches names those it launches.
|
||||
REVIEWS: tuple[tuple[str, ReviewKind], ...] = (("each reviewer", "reviewer"), ("each comprehension seat", "seat"), ("the security pass's subagent", "security"))
|
||||
# Each kind of review, as review_launches names those it launches: a row per pass, since a replay may lower one pass alone.
|
||||
REVIEWS: tuple[tuple[str, ReviewKind], ...] = (*((f"each {agent}", kind) for kind, agent in REVIEWERS.items()), ("each comprehension seat", "seat"), ("the security pass's subagent", "security"))
|
||||
|
||||
|
||||
def fresh(task: str, premises: str, route: Route, anchor: Rung | None, facts: str) -> str:
|
||||
@@ -48,11 +48,11 @@ def review_launches(route: Route, anchor: Rung | None) -> str:
|
||||
if anchor is None:
|
||||
return ""
|
||||
rungs = review_rungs(anchor, route.rung, route.reviewed_on())
|
||||
launched: dict[Rung, list[str]] = {}
|
||||
for reviews, kind in REVIEWS:
|
||||
launched: dict[Rung, list[ReviewKind]] = {}
|
||||
for _, kind in REVIEWS:
|
||||
if rungs[kind] != route.rung:
|
||||
launched.setdefault(rungs[kind], []).append(reviews)
|
||||
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())
|
||||
launched.setdefault(rungs[kind], []).append(kind)
|
||||
launches = "".join(f" Launch {listed(named(kinds), 'and')} with the Agent tool set to {rung.agent_args()}, {rung_named(rung, route, anchor)}." for rung, kinds in launched.items())
|
||||
scan = " Run a full scan only from such a subagent, since the scan's agents run on the model that starts them." if rungs["security"] != route.rung else ""
|
||||
planning = f" Your rung is below the project's: launch each subagent that files or scores todo.md items on the rung `~/.claude/bin/subagent-rung --plan {anchor.model} <L>` prints." if position(route.rung) < position(anchor) else ""
|
||||
return f"{launches}{scan}{planning}{taken_in_launches(route, anchor)}"
|
||||
@@ -63,11 +63,12 @@ def taken_in_launches(route: Route, anchor: Rung) -> str:
|
||||
|
||||
For a worker on Opus 5.5 at medium, routed by an item of E + I 6, it reads: ` Where an item you take into the chunk has an E + I of 7 or more, launch each reviewer with the Agent tool set to `model opus, effort max` from 7 and `model fable, effort max` from 8.`
|
||||
"""
|
||||
reviewers = review_rungs(anchor, route.rung, route.reviewed_on())["reviewer"]
|
||||
lowest = min(position(review_rungs(anchor, route.rung, route.reviewed_on())[kind]) for kind in REVIEWERS)
|
||||
higher: dict[Rung, int] = {}
|
||||
for escape_and_impact in range(route.reviewed_on() + 1, HIGHEST_ESCAPE_AND_IMPACT + 1):
|
||||
rung = review_rungs(anchor, route.rung, escape_and_impact)["reviewer"]
|
||||
if position(rung) > position(reviewers):
|
||||
# An E + I that steps reviews up puts every pass on one rung; one that does not leaves each pass where it is.
|
||||
rungs = {review_rungs(anchor, route.rung, escape_and_impact)[kind] for kind in REVIEWERS}
|
||||
if len(rungs) == 1 and position(rung := rungs.pop()) > lowest:
|
||||
higher.setdefault(rung, escape_and_impact)
|
||||
if not higher:
|
||||
return ""
|
||||
@@ -75,10 +76,18 @@ def taken_in_launches(route: Route, anchor: Rung) -> str:
|
||||
return f" Where an item you take into the chunk has an E + I of {min(higher.values())} or more, launch each reviewer with the Agent tool set to {listed(picks, 'and')}."
|
||||
|
||||
|
||||
def named(kinds: list[ReviewKind]) -> list[str]:
|
||||
"""How review_launches names kinds: by their rows in REVIEWS, with "each reviewer" for every pass where all are among them."""
|
||||
every = all(kind in kinds for kind in REVIEWERS)
|
||||
return [*(["each reviewer"] if every else []), *(name for name, kind in REVIEWS if kind in kinds and not (every and kind in REVIEWERS))]
|
||||
|
||||
|
||||
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 reviewed_on E + I picks, the item's or one taken in."""
|
||||
"""Why a review runs on rung: it is the project's, anchor, the one a pass's replay chose, which alone lies below anchor, or the one the route's reviewed_on E + I picks, the item's or one taken in."""
|
||||
if rung == anchor:
|
||||
return "the project's rung"
|
||||
if position(rung) < position(anchor):
|
||||
return "the rung the replay of its pass chose"
|
||||
if route.escape_and_impact_taken_in:
|
||||
return f"the rung picked by an item of E + I {route.escape_and_impact_taken_in} taken into the chunk"
|
||||
return f"the rung item {route.item}'s E + I of {route.escape_and_impact} picks"
|
||||
@@ -112,13 +121,21 @@ def reruns(route: Route, anchor: Rung | None) -> str:
|
||||
if anchor is None or route.rung not in LADDER:
|
||||
return ""
|
||||
rungs = review_rungs(anchor, route.rung, route.reviewed_on())
|
||||
launched = (("reviewer", rungs["reviewer"]), ("comprehension seat", rungs["seat"]))
|
||||
rerun = {name: climbed(rung, 1) for name, rung in launched if rung != LADDER[-1]}
|
||||
rerun: dict[Rung, list[ReviewKind]] = {}
|
||||
for _, kind in REVIEWS:
|
||||
if kind != "security" and rungs[kind] != LADDER[-1]:
|
||||
rerun.setdefault(climbed(rungs[kind], 1), []).append(kind)
|
||||
if not rerun:
|
||||
return ""
|
||||
if len(set(rerun.values())) == 1:
|
||||
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()}`."
|
||||
(first, kinds), *others = rerun.items()
|
||||
withs = [f"a {listed(nouns(more), 'or')} with `{rung.agent_args()}`" for rung, more in others]
|
||||
rest = f", {'and ' if len(withs) == 1 else ''}{listed(withs, 'and')}" if withs else ""
|
||||
return f" A {listed(nouns(kinds), 'or')} that asks for a rerun one rung up reruns with the Agent tool set to `{first.agent_args()}`{rest}."
|
||||
|
||||
|
||||
def nouns(kinds: list[ReviewKind]) -> list[str]:
|
||||
"""named's names without their "each"."""
|
||||
return [name.removeprefix("each ") for name in named(kinds)]
|
||||
|
||||
|
||||
def resumed(unfinished_evidence: str, route: Route, anchor: Rung | None) -> str:
|
||||
|
||||
Reference in New Issue
Block a user