Name the loop's states with one transition function, and inject its side effects

This commit is contained in:
2026-10-01 23:12:37 +02:00
parent d0ce3b2690
commit f385b563f0
16 changed files with 469 additions and 126 deletions
+4 -5
View File
@@ -1,11 +1,10 @@
import dataclasses
import hashlib
import json
import os
import subprocess
import sys
import typing
from loop_claude.effects import Effects
from loop_claude.outcome import Stop
RELOAD_FLAG = "--reloaded"
@@ -44,15 +43,15 @@ def fingerprint(launcher) -> str:
return digest.hexdigest()
def exec_if_edited(launcher, baseline, state) -> Stop | None:
def exec_if_edited(launcher, baseline, state, effects: Effects) -> Stop | None:
if fingerprint(launcher) == baseline:
return None
try:
trial = subprocess.run([sys.executable, launcher, "--help"], capture_output=True, text=True)
trial = effects.run([sys.executable, launcher, "--help"], capture_output=True, text=True)
if trial.returncode != 0:
print(f"keeping the running script: {trial.stderr.strip() or f'exit {trial.returncode}'}", file=sys.stderr)
return None
os.execv(sys.executable, [sys.executable, str(launcher), RELOAD_FLAG, json.dumps(dataclasses.asdict(state))])
effects.execv(sys.executable, [sys.executable, str(launcher), RELOAD_FLAG, json.dumps(dataclasses.asdict(state))])
except OSError as failure:
return Stop(1, f"could not reload loop-claude: {failure.strerror}; rerun loop-claude <task>")
return None