"""Print the Agent tool's model and effort for a subagent's task: docs/decisions.md → `routing:`. usage: subagent-rung [--plan] is the project's model, such as claude-opus-5-5, and 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 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 prints nothing on stdout, says so on stderr and exits 0; launch the subagent with no model or effort. Exit 1, saying why, on bad arguments. """ import re import sys from todo_table import LEVELS from model_routing.ladder import planning_rung, project_rung, worker_rung USAGE = f"usage: subagent-rung [--plan] , 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.""" anchor = project_rung(model) if anchor is None: return None return (planning_rung if planning else worker_rung)(anchor, likelihood).agent_args() def main(argv: list[str]) -> 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 args = agent_args(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