"""The rungs loop-claude hands a worker's claude in its environment, so rule-hook holds each review launch to them: docs/decisions.md → `routing:`.""" import typing from model_routing.ladder import LADDER, Rung PROJECT_RUNG = "LOOP_CLAUDE_PROJECT_RUNG" WORKER_RUNG = "LOOP_CLAUDE_WORKER_RUNG" def environment(project: Rung | None, worker: Rung) -> dict[str, str]: """The variables a worker's claude starts with; a project off the ladder has no rung to hand.""" return ({PROJECT_RUNG: encoded(project)} if project else {}) | {WORKER_RUNG: encoded(worker)} def handed(environ: typing.Mapping[str, str]) -> tuple[Rung | None, Rung | None]: """The project's and the worker's rungs, each None when unset or not on the ladder.""" return decoded(environ.get(PROJECT_RUNG)), decoded(environ.get(WORKER_RUNG)) def encoded(rung: Rung) -> str: return f"{rung.model} {rung.effort}" def decoded(value: str | None) -> Rung | None: model, _, effort = (value or "").partition(" ") rung = Rung(model, effort) return rung if rung in LADDER else None