"""The routing ladder, and the step an R + C moves a task from the project's rung: docs/decisions.md → `routing:`.""" import dataclasses @dataclasses.dataclass(frozen=True) class Rung: model: str # Empty leaves the effort to claude's default for the model, as for a model off the ladder. effort: str = "" def flags(self) -> list[str]: return ["--model", self.model, *(["--effort", self.effort] if self.effort else [])] def __str__(self) -> str: return f"{self.model} at {self.effort} effort" if self.effort else self.model # Least competent first. The Artificial Analysis Intelligence Index orders every rung but the top one, keeping a rung only # where no cheaper rung scores as high; Fable 5.1 tops the ladder as Anthropic's most capable model, which the index does not show. LADDER = ( Rung("claude-haiku-5-5", "low"), Rung("claude-haiku-5-5", "medium"), Rung("claude-haiku-5-5", "high"), Rung("claude-haiku-5-5", "xhigh"), Rung("claude-haiku-5-5", "max"), Rung("claude-sonnet-5-5", "high"), Rung("claude-opus-5-5", "medium"), Rung("claude-opus-5-5", "high"), Rung("claude-opus-5-5", "xhigh"), Rung("claude-opus-5-5", "max"), Rung("claude-fable-5-1", "max"), ) # (highest R + C in the band, rungs it steps from the project's rung); a higher R + C steps ABOVE_THE_BANDS. BANDS = ((4, -3), (6, -2), (8, -1), (10, 0), (12, 1), (14, 2), (16, 3)) ABOVE_THE_BANDS = 4 def project_rung(model: str) -> int | None: """The index of the model's cheapest rung, which for Opus 5.5 is its default effort; None for a model off the ladder.""" return next((index for index, rung in enumerate(LADDER) if rung.model == model), None) def steps(risk_and_complexity: int) -> int: return next((step for highest, step in BANDS if risk_and_complexity <= highest), ABOVE_THE_BANDS) def climbed(index: int, by: int) -> int: """The rung by steps from index, stopping at either end of the ladder.""" return max(0, min(len(LADDER) - 1, index + by)) def picked(anchor: int, risk_and_complexity: int) -> int: """The rung a task's R + C picks from anchor, the project's rung.""" return climbed(anchor, steps(risk_and_complexity)) def index_of(rung: Rung) -> int | None: return LADDER.index(rung) if rung in LADDER else None