Read the routing ladder from routing-ladder.json, which a project replaces with a file of its own in its config's folder
CI / tests (pull_request) Successful in 2m37s

This commit is contained in:
2026-11-15 18:51:59 +01:00
parent 9d0e2ad853
commit 0a20b6d4f6
42 changed files with 848 additions and 453 deletions
+19 -9
View File
@@ -5,31 +5,37 @@ usage: subagent-rung [--plan] <model> <L>
<model> is the project's model, such as claude-opus-5-5, and <L> the task's L, the chance it holds
a defect, a level from 1 to 4 scored as for a todo.md item. It prints the rung that L picks from
the model's cheapest rung, the project's rung, in the Agent tool's words, such as `model sonnet,
effort high`. --plan, for a task that files or scores todo.md items, prints the project's rung where
effort high`. It reads the routing ladder of the project whose checkout it runs in:
routing-ladder.json in the folder of the project's config, ~/.claude-projects/<key>/, or else
the one this setup ships. loop-claude --help says how to write one. --plan, for a task that files or scores todo.md items, prints the project's rung where
that L picks a lower one, as ~/.claude/rules/todo-items.md lets only the project's rung or above
plan. For a model off the routing ladder, the tool doesn't print anything on stdout, says so on stderr and
exits 0; launch the subagent with no model or effort.
Exit 1, saying why, on bad arguments.
Exit 1, saying why, on bad arguments, or where the project's config or its routing ladder is faulty
or cannot be read.
"""
import pathlib
import re
import sys
from failure import Failure
from model_routing.ladder import Ladder
from release_plan.todo_table import LEVELS
from model_routing.ladder import planning_rung, project_rung, worker_rung
from model_routing.ladder_file import project_ladder
USAGE = f"usage: subagent-rung [--plan] <model> <L>, L a level from 1 to {LEVELS['L']}"
def agent_args(model: str, likelihood: int, planning: bool = False) -> str | None:
"""The Agent tool's model and effort for the rung likelihood picks from model's cheapest rung, never below it when planning; None for a model off the ladder."""
project = project_rung(model)
def agent_args(ladder: Ladder, model: str, likelihood: int, planning: bool = False) -> str | None:
"""The Agent tool's model and effort for the rung likelihood picks on ladder from model's cheapest rung, never below it when planning; None for a model off the ladder."""
project = ladder.project_rung(model)
if project is None:
return None
return (planning_rung if planning else worker_rung)(project, likelihood).agent_args()
return (ladder.planning_rung if planning else ladder.worker_rung)(project, likelihood).agent_args()
def main(argv: list[str]) -> int:
def main(argv: list[str], home: pathlib.Path) -> int:
if argv[:1] in (["-h"], ["--help"]):
print(__doc__.strip())
return 0
@@ -39,7 +45,11 @@ def main(argv: list[str]) -> int:
print(f"subagent-rung: cannot read the arguments{' ' + ' '.join(argv) if argv else ''}; {USAGE}", file=sys.stderr)
return 1
model, likelihood = operands
args = agent_args(model, int(likelihood), planning)
ladder = project_ladder(None, home)
if isinstance(ladder, Failure):
print(f"subagent-rung: {ladder.reason}", file=sys.stderr)
return 1
args = agent_args(ladder, model, int(likelihood), planning)
if args is None:
print(f"subagent-rung: {model} is not on the routing ladder; pass the Agent tool no model or effort", file=sys.stderr)
else: