Name loop_claude's modules and words by what each holds, explain the reload, and tie each exit-1 clause of --help to its Stop

This commit is contained in:
2026-10-02 08:42:29 +02:00
parent dc844030fa
commit 211524196b
27 changed files with 212 additions and 165 deletions
+25 -16
View File
@@ -10,13 +10,22 @@ on the terminal, every worktree first marked trusted in ~/.claude.json. An unfin
its session next cycle; the next chunk starts a fresh session.
Cycles continue until an exit below or Ctrl-C. Words: ~/.claude/CLAUDE.md → "Vocabulary".
Exit 1: no task, git cannot start or finds no checkout, no premises, a models file it cannot read or
write, claude leaves no transcript or one it cannot read or archive, a finished chunk's session it
cannot delete, claude cannot start for an interrupt, python cannot start for a reload, a reload whose
loop run it cannot read, or the worker or the judge fails three times running, retried a minute apart
within the cycle. A worker fails when claude cannot start, exits non-zero, is killed, or ends without
a result event; a judge when claude cannot start or exits non-zero, or its verdict misses or mistypes
a field, interrupts without a question, or quotes nothing in the transcript.
Exit 1, saying why, when:
- no task is given
- git cannot start or finds no checkout
- README.md holds no premises
- the models file cannot be read or written
- claude leaves no transcript
- a transcript cannot be read or archived
- a finished chunk's session cannot be deleted
- claude cannot start for an interrupt
- python cannot start for a reload
- a reload cannot read the cycle number, checkout root and task the edited script was handed, as
when the edit changed what one script hands the next
- the worker or the judge fails three times running, retried a minute apart within the cycle. A
worker fails when claude cannot start, exits non-zero, is killed, or ends without a result event;
a judge when claude cannot start or exits non-zero, or its reply misses or mistypes a field,
interrupts without a question, or quotes nothing in the transcript.
Exit 2: the human is needed, to pick the model or answer an interrupt, and stdin or stdout is not a
terminal, the input ends, or the interrupt ended with nothing typed. Rerunning resumes any
open session.
@@ -40,14 +49,14 @@ import sys
import typing
from loop_claude.claude_code.session import session_for
from loop_claude.cycle.steps import Cycle, run_cycle
from loop_claude.cycle.run import Cycle, run_cycle
from loop_claude.effects import Effects
from loop_claude.loop.reload import RELOAD_FLAG, LoopRun, decode_handed, exec_if_edited, fingerprint
from loop_claude.outcome import Stop
from loop_claude.paths import Paths
from loop_claude.project.checkout import checkout_root, project_name
from loop_claude.project.models import project_models
from loop_claude.project.checkout import checkout_root, project_key
from loop_claude.project.models import models_for
from loop_claude.project.premises import read_premises
from loop_claude.stop import Stop
def main(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launcher: pathlib.Path, cwd: pathlib.Path, effects: Effects) -> int:
@@ -65,8 +74,8 @@ def run_loop(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launc
if isinstance(loop_run, Stop):
return loop_run
baseline = fingerprint(launcher)
project = project_name(loop_run.root, paths.code)
session = session_for(project, paths)
key = project_key(loop_run.root, paths.code)
session = session_for(key, paths)
while True:
if stop := exec_if_edited(launcher, baseline, loop_run, effects):
return stop
@@ -74,11 +83,11 @@ def run_loop(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launc
premises = read_premises(loop_run.root)
if isinstance(premises, Stop):
return premises
models = project_models(project, paths, env, effects)
models = models_for(key, paths, env, effects)
if isinstance(models, Stop):
return models
print(f"\n=== cycle {loop_run.cycle_number} ===", flush=True)
if stop := run_cycle(Cycle(effects=effects, models=models, paths=paths, premises=premises, project=project, root=loop_run.root, session=session, task=loop_run.task)):
if stop := run_cycle(Cycle(effects=effects, models=models, paths=paths, premises=premises, project_key=key, root=loop_run.root, session=session, task=loop_run.task)):
return stop
@@ -91,5 +100,5 @@ def loop_run_from(argv: list[str], cwd: pathlib.Path, effects: Effects) -> LoopR
return root if isinstance(root, Stop) else LoopRun(0, root, task)
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):
return Stop(1, f"the reload cannot read the loop run from {argv[1:]}; rerun loop-claude <task>")
return Stop(1, f"the reload cannot read the cycle number, checkout root and task the edited script was handed in {argv[1:]}, as when the edit changed what one script hands the next; rerun loop-claude <task>")
return loop_run