28 lines
1.5 KiB
Python
28 lines
1.5 KiB
Python
"""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:`.
|
|
|
|
loop-claude sets these variables for its worker and for the claude an interrupt resumes; a human's shell does not, and rule-hook then checks no review launch."""
|
|
import typing
|
|
|
|
from model_routing.ladder import LADDER, review_rungs, Rung
|
|
from model_routing.route import Route
|
|
|
|
PROJECT_RUNG = "LOOP_CLAUDE_PROJECT_RUNG"
|
|
WORKER_RUNG = "LOOP_CLAUDE_WORKER_RUNG"
|
|
REVIEWER_RUNG = "LOOP_CLAUDE_REVIEWER_RUNG"
|
|
|
|
|
|
def environment(project: Rung | None, route: Route) -> dict[str, str]:
|
|
"""The variables a worker's claude on route starts with. A project off the ladder gets empty project and reviewer rungs, so none is inherited from the environment."""
|
|
reviewers = review_rungs(project, route.rung, route.reviewed_on())["reviewer"] if project else None
|
|
return {PROJECT_RUNG: str(project) if project else "", WORKER_RUNG: str(route.rung), REVIEWER_RUNG: str(reviewers) if reviewers else ""}
|
|
|
|
|
|
def handed(environ: typing.Mapping[str, str]) -> tuple[Rung | None, Rung | None, Rung | None]:
|
|
"""The project's, the worker's and the reviewers' rungs, each None when unset or not on the ladder."""
|
|
return on_the_ladder(environ.get(PROJECT_RUNG)), on_the_ladder(environ.get(WORKER_RUNG)), on_the_ladder(environ.get(REVIEWER_RUNG))
|
|
|
|
|
|
def on_the_ladder(value: str | None) -> Rung | None:
|
|
rung = Rung.parse(value or "")
|
|
return rung if rung in LADDER else None
|