Files
claude-config/bin/subagent_rung/main.py
T

58 lines
2.7 KiB
Python

"""Print the Agent tool's model and effort for a subagent's task: docs/decisions.md → `routing:`.
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`. 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, 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_file import project_ladder
USAGE = f"usage: subagent-rung [--plan] <model> <L>, L a level from 1 to {LEVELS['L']}"
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 (ladder.planning_rung if planning else ladder.worker_rung)(project, likelihood).agent_args()
def main(argv: list[str], home: pathlib.Path) -> int:
if argv[:1] in (["-h"], ["--help"]):
print(__doc__.strip())
return 0
planning = argv[:1] == ["--plan"]
operands = argv[1:] if planning else argv
if len(operands) != 2 or not re.fullmatch(r"[1-9][0-9]*", operands[1]) or int(operands[1]) > LEVELS["L"]:
print(f"subagent-rung: cannot read the arguments{' ' + ' '.join(argv) if argv else ''}; {USAGE}", file=sys.stderr)
return 1
model, likelihood = operands
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:
print(args)
return 0