From d9058d2d7ed5f9e718b79e80237c8ed922b3ecd2 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 29 Sep 2026 10:29:08 +0200 Subject: [PATCH] Resolve decode_state's field types from string annotations too --- bin/loop_claude/reload.py | 3 ++- bin/test_loop_claude.py | 11 ++++++++++- todo.md | 1 - 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/bin/loop_claude/reload.py b/bin/loop_claude/reload.py index ba23f9b5..9419dd07 100644 --- a/bin/loop_claude/reload.py +++ b/bin/loop_claude/reload.py @@ -4,6 +4,7 @@ import json import os import subprocess import sys +import typing RELOAD_FLAG = "--reloaded" @@ -13,7 +14,7 @@ def decode_state(handed, kind): fields = json.loads(handed) except ValueError: return None - shape = {field.name: field.type for field in dataclasses.fields(kind)} + shape = typing.get_type_hints(kind) if not isinstance(fields, dict) or fields.keys() != shape.keys(): return None if any(type(fields[name]) is not type_ for name, type_ in shape.items()): diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index 6aeca665..8da269af 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -1,3 +1,4 @@ +import dataclasses import json import os import pathlib @@ -7,7 +8,7 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) -from loop_claude import file_writes, main +from loop_claude import file_writes, main, reload from loop_claude.claude_code import formats, transcript from loop_claude.claude_runs import judge from loop_claude.outcome import Failure, Stop @@ -119,6 +120,14 @@ class LoopState(unittest.TestCase): with self.subTest(handed=handed): self.assertEqual(main.loop_state([main.RELOAD_FLAG, *handed], CWD), Stop(1, f"the reload cannot read the loop's state from {handed}; rerun loop-claude ")) + def test_decodes_a_state_whose_annotations_are_strings(self): + @dataclasses.dataclass(frozen=True) + class Stringly: + count: "int" + name: "str" + self.assertEqual(reload.decode_state('{"count": 1, "name": "n"}', Stringly), Stringly(1, "n")) + self.assertIsNone(reload.decode_state('{"count": "1", "name": "n"}', Stringly)) + class ReplaceFile(unittest.TestCase): diff --git a/todo.md b/todo.md index b7418871..d76d7369 100644 --- a/todo.md +++ b/todo.md @@ -8,7 +8,6 @@ The rebuild lifts every dimension, one chunk per item, until the last item opens The places the panel on `rebuild` at 7f9de5c named (`docs/decisions.md`), capping dimension first: -- **Make `decode_state` check the fields' types without relying on the annotations being runtime types.** Two seats: `from __future__ import annotations` in `main.py` would fail every reload. - **State once, in `outcome.py`, that a `Failure` is retried and a `Stop` exits.** Three seats inferred it from `run_loop`. - **Define a round once, in larv-review's "Round cap", and link it from `review-findings.md` → "Rounds", the Vocabulary and the auto-reviewer's step.** All four seats held §3, "Rounds" and the Vocabulary open together to settle whether a launch counts. - **Give `project` one meaning: rename `Paths.projects` and `Session.projects` for Claude Code's transcript directory.** Two seats: it also names the package, the key and `~/.claude.json`'s object.