"""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 the setup's 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, naming the ladder's file, and exits 0; launch the subagent with no model or effort. It reads the routing ladder of the project whose checkout it runs in: routing-ladder.json in the folder of the project's config, ~/.config/build-release//, or else the one this setup ships, as in a checkout no config names. build-release --help shows the file's shape. Exit 1, saying why, on bad arguments, or where the project's config or its routing ladder is faulty or cannot be read. Where XDG_CONFIG_HOME holds an absolute path, read ~/.config in this help as that path. """ from collections.abc import Mapping import pathlib import re import sys from failure import Failure from model_routing.ladder import Ladder from plan.todo_table import LEVELS from model_routing.ladder_file import project_ladder_file, read_ladder USAGE = f"usage: subagent-rung [--plan] , 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 (project.planning_rung if planning else project.worker_rung)(likelihood).agent_args() def main(argv: list[str], home: pathlib.Path, env: Mapping[str, 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 file = project_ladder_file(None, home, env) ladder = file if isinstance(file, Failure) else read_ladder(file) 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 {file}; pass the Agent tool no model or effort", file=sys.stderr) else: print(args) return 0