Answer the architect's second round
This commit is contained in:
@@ -40,7 +40,7 @@ import sys
|
|||||||
from loop_claude.claude_code.session import session_for
|
from loop_claude.claude_code.session import session_for
|
||||||
from loop_claude.cycle.steps import Cycle, run_cycle
|
from loop_claude.cycle.steps import Cycle, run_cycle
|
||||||
from loop_claude.effects import Effects
|
from loop_claude.effects import Effects
|
||||||
from loop_claude.loop.reload import RELOAD_FLAG, LoopRun, decode_state, exec_if_edited, fingerprint
|
from loop_claude.loop.reload import RELOAD_FLAG, LoopRun, decode_handed, exec_if_edited, fingerprint
|
||||||
from loop_claude.outcome import Stop
|
from loop_claude.outcome import Stop
|
||||||
from loop_claude.project.checkout import checkout_root, project_name
|
from loop_claude.project.checkout import checkout_root, project_name
|
||||||
from loop_claude.project.models import project_models
|
from loop_claude.project.models import project_models
|
||||||
@@ -86,7 +86,7 @@ def loop_run_from(argv, cwd, effects: Effects) -> LoopRun | Stop:
|
|||||||
return Stop(0 if task else 1, __doc__.strip())
|
return Stop(0 if task else 1, __doc__.strip())
|
||||||
root = checkout_root(cwd, effects)
|
root = checkout_root(cwd, effects)
|
||||||
return root if isinstance(root, Stop) else LoopRun(0, root, task)
|
return root if isinstance(root, Stop) else LoopRun(0, root, task)
|
||||||
loop_run = decode_state(argv[1], LoopRun) if len(argv) == 2 else None
|
loop_run = decode_handed(argv[1], LoopRun) if len(argv) == 2 else None
|
||||||
if not (loop_run and loop_run.root and loop_run.task):
|
if not (loop_run and loop_run.root and loop_run.task):
|
||||||
return Stop(1, f"the reload cannot read the loop's state from {argv[1:]}; rerun loop-claude <task>")
|
return Stop(1, f"the reload cannot read the loop run from {argv[1:]}; rerun loop-claude <task>")
|
||||||
return loop_run
|
return loop_run
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class LoopRun:
|
|||||||
task: str
|
task: str
|
||||||
|
|
||||||
|
|
||||||
def decode_state(handed, kind: type[T]) -> T | None:
|
def decode_handed(handed, kind: type[T]) -> T | None:
|
||||||
try:
|
try:
|
||||||
fields = json.loads(handed)
|
fields = json.loads(handed)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|||||||
@@ -317,15 +317,15 @@ class LoopRuns(unittest.TestCase):
|
|||||||
def test_stops_naming_the_reload_when_it_hands_over_anything_but_the_state_with_a_task(self):
|
def test_stops_naming_the_reload_when_it_hands_over_anything_but_the_state_with_a_task(self):
|
||||||
for handed in (["3", "2", "/r", "do it"], ["3"], ["[1]"], [json.dumps({"cycle_number": 3, "root": "/r"})], [json.dumps({"cycle_number": 3, "root": "/r", "task": ""})], [json.dumps({"cycle_number": "3", "root": "/r", "task": "do it"})], [json.dumps({"cycle_number": 3, "root": "", "task": "do it"})], [json.dumps({"cycle_number": 3, "root": "/r", "task": "do it", "turns": 1})], [json.dumps({"cycle_number": 3, "failures": 0, "root": "/r", "task": "do it"})]):
|
for handed in (["3", "2", "/r", "do it"], ["3"], ["[1]"], [json.dumps({"cycle_number": 3, "root": "/r"})], [json.dumps({"cycle_number": 3, "root": "/r", "task": ""})], [json.dumps({"cycle_number": "3", "root": "/r", "task": "do it"})], [json.dumps({"cycle_number": 3, "root": "", "task": "do it"})], [json.dumps({"cycle_number": 3, "root": "/r", "task": "do it", "turns": 1})], [json.dumps({"cycle_number": 3, "failures": 0, "root": "/r", "task": "do it"})]):
|
||||||
with self.subTest(handed=handed):
|
with self.subTest(handed=handed):
|
||||||
self.assertEqual(main.loop_run_from([main.RELOAD_FLAG, *handed], CWD, FakeEffects().effects()), Stop(1, f"the reload cannot read the loop's state from {handed}; rerun loop-claude <task>"))
|
self.assertEqual(main.loop_run_from([main.RELOAD_FLAG, *handed], CWD, FakeEffects().effects()), Stop(1, f"the reload cannot read the loop run from {handed}; rerun loop-claude <task>"))
|
||||||
|
|
||||||
def test_decodes_a_state_whose_annotations_are_strings(self):
|
def test_decodes_a_state_whose_annotations_are_strings(self):
|
||||||
@dataclasses.dataclass(frozen=True)
|
@dataclasses.dataclass(frozen=True)
|
||||||
class Stringly:
|
class Stringly:
|
||||||
count: "int"
|
count: "int"
|
||||||
name: "str"
|
name: "str"
|
||||||
self.assertEqual(reload.decode_state('{"count": 1, "name": "n"}', Stringly), Stringly(1, "n"))
|
self.assertEqual(reload.decode_handed('{"count": 1, "name": "n"}', Stringly), Stringly(1, "n"))
|
||||||
self.assertIsNone(reload.decode_state('{"count": "1", "name": "n"}', Stringly))
|
self.assertIsNone(reload.decode_handed('{"count": "1", "name": "n"}', Stringly))
|
||||||
|
|
||||||
def test_stops_when_the_reload_cannot_start_python(self):
|
def test_stops_when_the_reload_cannot_start_python(self):
|
||||||
with tempfile.TemporaryDirectory() as root:
|
with tempfile.TemporaryDirectory() as root:
|
||||||
|
|||||||
+1
-1
@@ -106,4 +106,4 @@
|
|||||||
|
|
||||||
## loop-claude: a cycle's state machine holds the paths that move it on, and a `Stop` leaves it
|
## loop-claude: a cycle's state machine holds the paths that move it on, and a `Stop` leaves it
|
||||||
|
|
||||||
2026-10-02, larv-review. Applies "Always use explicit state machines". A `Stop` ends the process, so no later state could act on it; a `Stopped` state would add a case every step must pass through and nothing would read. Valid while every failure of a cycle ends the loop.
|
2026-10-01, larv-review. Applies "Always use explicit state machines". A `Stop` ends the process, so no later state could act on it; a `Stopped` state would add a case every step must pass through and nothing would read. Valid while every failure of a cycle ends the loop.
|
||||||
|
|||||||
Reference in New Issue
Block a user