Answer architecture round 2: 2 🔴, 3 🟡; route from the ladder by rung, keep a stepped-up rung across reruns and reloads, test the judge's bundled range, and file item 136 for routing on the item taken

This commit is contained in:
2026-10-14 23:06:54 +02:00
parent c75e576773
commit d6e019444d
20 changed files with 305 additions and 148 deletions
+7 -5
View File
@@ -7,7 +7,7 @@ import types
import typing
from loop_claude.effects import Effects
from loop_claude.loop.routing import Route
from loop_claude.routing import Route
from loop_claude.stop import Stop
RELOAD_FLAG = "--reloaded"
@@ -32,21 +32,23 @@ def decode_handed(handed: str, kind: type[T]) -> T | None:
except ValueError:
return None
decoded = decoded_as(fields, kind)
return None if decoded is REJECTED else decoded
return None if decoded is REJECTED else typing.cast(T, decoded)
REJECTED = object()
def decoded_as(value: object, kind: typing.Any) -> typing.Any:
"""value as kind, or REJECTED: a dataclass from an object holding exactly its fields, a union's first member that fits, else a value of exactly kind."""
"""value as kind, or REJECTED: a dataclass from an object holding its fields, a union's first member that fits, else a value of exactly kind."""
if isinstance(kind, types.UnionType):
return next((found for option in typing.get_args(kind) if (found := decoded_as(value, option)) is not REJECTED), REJECTED)
if isinstance(kind, type) and dataclasses.is_dataclass(kind):
shape = typing.get_type_hints(kind)
if not isinstance(value, dict) or value.keys() != shape.keys():
# A field with a default may be missing, so a field added since the running script started does not stop the loop.
required = {field.name for field in dataclasses.fields(kind) if field.default is dataclasses.MISSING and field.default_factory is dataclasses.MISSING}
if not isinstance(value, dict) or not required <= value.keys() <= shape.keys():
return REJECTED
fields = {name: decoded_as(value[name], type_) for name, type_ in shape.items()}
fields = {name: decoded_as(field, shape[name]) for name, field in value.items()}
return REJECTED if any(field is REJECTED for field in fields.values()) else kind(**fields)
return value if type(value) is kind else REJECTED