35 lines
2.2 KiB
Python
35 lines
2.2 KiB
Python
"""The rungs and the E + I loop-claude hands a worker's claude in its environment, from which rule-hook works out the rung of each review launch: 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, ProjectRung, Rung
|
|
from model_routing.route import Route
|
|
|
|
PROJECT_RUNG = "LOOP_CLAUDE_PROJECT_RUNG"
|
|
WORKER_RUNG = "LOOP_CLAUDE_WORKER_RUNG"
|
|
# The E + I the chunk's reviews are routed on, from which review_rung works out each review's rung.
|
|
ESCAPE_AND_IMPACT = "LOOP_CLAUDE_ESCAPE_AND_IMPACT"
|
|
|
|
|
|
def environment(project: ProjectRung | None, route: Route) -> dict[str, str]:
|
|
"""The variables a worker's claude on route starts with. A project off the ladder gets an empty project rung, so none is inherited from the environment."""
|
|
return {PROJECT_RUNG: str(project.rung) if project else "", WORKER_RUNG: str(route.rung), ESCAPE_AND_IMPACT: str(route.reviewed_on())}
|
|
|
|
|
|
def hands_rungs(environ: typing.Mapping[str, str]) -> bool:
|
|
"""Whether the environment names a project's and a worker's rung, as loop-claude sets them for a project on its ladder. Where it names neither, no review launch is checked, so the caller skips reading the project's ladder."""
|
|
return bool(environ.get(PROJECT_RUNG) and environ.get(WORKER_RUNG))
|
|
|
|
|
|
def handed(environ: typing.Mapping[str, str], ladder: Ladder) -> tuple[ProjectRung | None, Rung | None, int]:
|
|
"""The project's rung and the worker's rung, each None when unset or not on ladder, and the reviews' E + I, 0 when unset or not a whole number. ladder is the project's. An older loop-claude hands no E + I, and 0 steps no review up."""
|
|
escape_and_impact = environ.get(ESCAPE_AND_IMPACT, "")
|
|
project = on_the_ladder(environ.get(PROJECT_RUNG), ladder)
|
|
return ProjectRung(ladder, project) if project else None, on_the_ladder(environ.get(WORKER_RUNG), ladder), int(escape_and_impact) if escape_and_impact.isdecimal() else 0
|
|
|
|
|
|
def on_the_ladder(value: str | None, ladder: Ladder) -> Rung | None:
|
|
rung = Rung.parse(value or "")
|
|
return rung if rung in ladder.rungs else None
|