Carry the reload state as one JSON argument and exit naming a reload without a task

This commit is contained in:
2026-09-26 13:35:50 +02:00
parent 64a752c76b
commit a64461f2c1
4 changed files with 31 additions and 12 deletions
+17 -7
View File
@@ -10,8 +10,8 @@ interrupt: `claude --resume` on the terminal, every worktree first marked truste
An unfinished chunk resumes the same session next cycle; a finished one starts a fresh session.
Cycles continue until that interrupt or Ctrl-C. Words: ~/.claude/CLAUDE.md → "Vocabulary".
Exit 1: no task, not inside a checkout, no premises, claude leaves no transcript, or the worker or
the judge fails three times running. A worker fails when claude exits non-zero, is killed, or ends
Exit 1: no task, not inside a checkout, no premises, claude leaves no transcript, a reload handing
over no task, or the worker or the judge fails three times running. A worker fails when claude exits non-zero, is killed, or ends
without a result event; a judge when its verdict misses a field or quotes nothing in the transcript.
Exit 2: the human is needed and stdin or stdout is not a terminal, or the interrupt ended without
them typing anything. Rerunning resumes any open session.
@@ -373,19 +373,29 @@ def reload_if_edited(root, task, cycle_number, failures):
if trial.returncode != 0:
print(f"keeping the running script: {trial.stderr.strip() or f'exit {trial.returncode}'}", file=sys.stderr)
return
os.execv(sys.executable, [sys.executable, __file__, RELOAD_FLAG, str(cycle_number), str(failures), root, task])
state = {"cycle_number": cycle_number, "failures": failures, "root": root, "task": task}
os.execv(sys.executable, [sys.executable, __file__, RELOAD_FLAG, json.dumps(state)])
def reloaded_state(handed):
state = parse(handed[0]) if len(handed) == 1 else None
if not state or {"cycle_number", "failures", "root"} - state.keys() or not isinstance(state.get("task"), str) or not state["task"]:
sys.exit(f"the reload handed {handed}, not the loop's state with a task; rerun loop-claude <task>")
return state
def main():
argv = sys.argv[1:]
cycle_number, failures, root = 0, 0, ""
if argv[:1] == [RELOAD_FLAG]:
cycle_number, failures, root, argv = int(argv[1]), int(argv[2]), argv[3], argv[4:]
task = " ".join(argv)
state = reloaded_state(argv[1:])
else:
state = {"cycle_number": 0, "failures": 0, "root": "", "task": " ".join(argv)}
task = state["task"]
if task in ("", "-h", "--help"):
print(__doc__.strip())
sys.exit(0 if task else 1)
root = root or checkout_root()
root = state["root"] or checkout_root()
cycle_number, failures = state["cycle_number"], state["failures"]
while True:
reload_if_edited(root, task, cycle_number, failures)
cycle_number += 1