Answer principles round 2: 0 🔴, 3 🟡; cite item 171 in the figures decision, check a handed route's levels as a value, carry the item and levels in ArchivedWorker

This commit is contained in:
2026-10-16 12:56:20 +02:00
parent 50fdd9e66d
commit 24549589ec
7 changed files with 31 additions and 20 deletions
+21 -10
View File
@@ -14,9 +14,10 @@ LEVELS_ROUTED = re.compile(r"L of (?P<likelihood>[0-9]+) and E \+ I of (?P<escap
class ArchivedWorker(typing.NamedTuple):
"""What an archived worker line names, whatever its route says: the worker's rung, and whether an item routed it."""
"""What an archived worker line names: the worker's rung, the item that routed it, 0 for none, and the text naming that item's levels, which an older loop-claude wrote as an R + C."""
rung: Rung
routed: bool
item: int
levels: str
def on_their_scales(likelihood: int, escape_and_impact: int) -> bool:
@@ -24,9 +25,14 @@ def on_their_scales(likelihood: int, escape_and_impact: int) -> bool:
return 1 <= likelihood <= LEVELS["L"] and 2 <= escape_and_impact <= LEVELS["E"] + LEVELS["I"]
def levels_fit(item: int, likelihood: int, escape_and_impact: int) -> bool:
"""Whether a route may hold these: an item with levels on their scales, or no item and no levels."""
return on_their_scales(likelihood, escape_and_impact) if item else not (likelihood or escape_and_impact)
@dataclasses.dataclass(frozen=True)
class Route:
"""A chunk's worker rung, and the plan item that picked it, 0 for none, with its L, which picked the worker's rung, and its E + I, which picks its reviewers'. A route with an item holds levels on their scales, and one without holds none, so no rung is picked from a level off its scale.
"""A chunk's worker rung, and the plan item that picked it, 0 for none, with its L, which picked the worker's rung, and its E + I, which picks its reviewers'. A route holds only levels that levels_fit, so no rung is picked from a level off its scale.
unfinished counts the unfinished verdicts towards the next one-rung step; a reload hands it over with the rung.
"""
@@ -39,9 +45,15 @@ class Route:
unfinished: int = 0
def __post_init__(self) -> None:
if (self.item and not on_their_scales(self.likelihood, self.escape_and_impact)) or (not self.item and (self.likelihood or self.escape_and_impact)):
# A guard against a programming error, which nothing catches: route_from and the reload decoder check fits before they build a route.
if not levels_fit(self.item, self.likelihood, self.escape_and_impact):
raise ValueError(f"a route by item {self.item} cannot hold an L of {self.likelihood} and an E + I of {self.escape_and_impact}")
@staticmethod
def fits(fields: typing.Mapping[str, typing.Any]) -> bool:
"""Whether a route may be built from these fields, as the reload decoder asks of a handed one."""
return levels_fit(fields.get("item", 0), fields.get("likelihood", 0), fields.get("escape_and_impact", 0))
def __str__(self) -> str:
"""What the archive records as each verdict's worker; ROUTED reads it back."""
return f"{self.rung}, routed by item {self.item}'s L of {self.likelihood} and E + I of {self.escape_and_impact}" if self.item else str(self.rung)
@@ -51,16 +63,15 @@ def archived_worker(worker: str) -> ArchivedWorker | None:
"""What an archived worker line names; None for a model run off the ladder."""
found = ROUTED.fullmatch(worker)
rung = Rung.parse(found["rung"]) if found else None
return ArchivedWorker(rung, bool(found["item"])) if found and rung else None
return ArchivedWorker(rung, int(found["item"] or 0), found["levels"] or "") if found and rung else None
def route_from(worker: str) -> Route | None:
"""The route an archived worker line names; None for a model run off the ladder, or a route by anything but levels on their scales."""
archived = archived_worker(worker)
if archived is None or not archived.routed:
if archived is None or not archived.item:
return Route(archived.rung) if archived else None
found = typing.cast(re.Match[str], ROUTED.fullmatch(worker))
levels = LEVELS_ROUTED.fullmatch(found["levels"])
if not levels or not on_their_scales(int(levels["likelihood"]), int(levels["escape_and_impact"])):
levels = LEVELS_ROUTED.fullmatch(archived.levels)
if not levels or not levels_fit(archived.item, int(levels["likelihood"]), int(levels["escape_and_impact"])):
return None
return Route(archived.rung, int(found["item"]), int(levels["likelihood"]), int(levels["escape_and_impact"]))
return Route(archived.rung, archived.item, int(levels["likelihood"]), int(levels["escape_and_impact"]))