29 lines
1.6 KiB
Python
29 lines
1.6 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, 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_rungs works out each review's rung.
|
|
ESCAPE_AND_IMPACT = "LOOP_CLAUDE_ESCAPE_AND_IMPACT"
|
|
|
|
|
|
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 an empty project rung, so none is inherited from the environment."""
|
|
return {PROJECT_RUNG: str(project) if project else "", WORKER_RUNG: str(route.rung), ESCAPE_AND_IMPACT: str(route.reviewed_on())}
|
|
|
|
|
|
def handed(environ: typing.Mapping[str, str]) -> tuple[Rung | None, Rung | None, int]:
|
|
"""The project's and the worker's rungs, each None when unset or not on the ladder, and the reviews' E + I, 0 when unset or not a whole number. An older loop-claude hands no E + I, and 0 steps no review up."""
|
|
escape_and_impact = environ.get(ESCAPE_AND_IMPACT, "")
|
|
return on_the_ladder(environ.get(PROJECT_RUNG)), on_the_ladder(environ.get(WORKER_RUNG)), int(escape_and_impact) if escape_and_impact.isdecimal() else 0
|
|
|
|
|
|
def on_the_ladder(value: str | None) -> Rung | None:
|
|
rung = Rung.parse(value or "")
|
|
return rung if rung in LADDER else None
|