From e7b0479092f53a21c6c4da502db0a0423b829ccb Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Tue, 29 Sep 2026 11:33:49 +0200 Subject: [PATCH] Hand run_cycle and judge_through_interrupts one cycle context --- bin/loop_claude/cycle.py | 40 +++++++++++++++++++++++++++------------- bin/loop_claude/main.py | 6 ++++-- todo.md | 1 - 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/bin/loop_claude/cycle.py b/bin/loop_claude/cycle.py index 8429b417..997f0e65 100644 --- a/bin/loop_claude/cycle.py +++ b/bin/loop_claude/cycle.py @@ -1,40 +1,54 @@ +import dataclasses + from loop_claude.archive import archive -from loop_claude.claude_code.session import delete_session, session_for, transcript_file +from loop_claude.claude_code.session import Session, delete_session, transcript_file from loop_claude.claude_code.transcript import read, render from loop_claude.claude_runs.interrupt import interrupt from loop_claude.claude_runs.judge import judge from loop_claude.claude_runs.worker import run_worker, worker_args from loop_claude.outcome import Failure, Stop +from loop_claude.paths import Paths +from loop_claude.project.models import Models from loop_claude.retry import retried -def run_cycle(root, project, task, premises, models, paths): - session = session_for(project, paths) - if stop := retried("worker", lambda: run_worker(root, worker_args(task, session, models.worker, bool(transcript_file(session))))): +@dataclasses.dataclass(frozen=True) +class Cycle: + models: Models + paths: Paths + premises: str + project: str + root: str + session: Session + task: str + + +def run_cycle(cycle): + if stop := retried("worker", lambda: run_worker(cycle.root, worker_args(cycle.task, cycle.session, cycle.models.worker, bool(transcript_file(cycle.session))))): return stop - path = transcript_file(session) + path = transcript_file(cycle.session) if not path: - return Stop(1, f"claude left no transcript for session {session.id}") - verdict = judge_through_interrupts(root, project, task, premises, models, session, path, paths) + return Stop(1, f"claude left no transcript for session {cycle.session.id}") + verdict = judge_through_interrupts(cycle, path) if isinstance(verdict, Stop): return verdict if verdict.finished: - if failure := archive(project, path, f"Task: {task}\n\nVerdict: finished", paths): + if failure := archive(cycle.project, path, f"Task: {cycle.task}\n\nVerdict: finished", cycle.paths): return Stop(1, failure.reason) - delete_session(session) + delete_session(cycle.session) -def judge_through_interrupts(root, project, task, premises, models, session, path, paths): +def judge_through_interrupts(cycle, path): # The interrupt appends to this transcript, so each pass judges and archives it anew. while True: entries = read(path) if isinstance(entries, Failure): return Stop(1, entries.reason) - verdict = judge(root, task, premises, render(entries), models.judge) + verdict = judge(cycle.root, cycle.task, cycle.premises, render(entries), cycle.models.judge) if isinstance(verdict, Stop) or not verdict.interrupt: return verdict - if failure := archive(project, path, f"Task: {task}\n\nVerdict: interrupt\n\n{verdict.question}", paths): + if failure := archive(cycle.project, path, f"Task: {cycle.task}\n\nVerdict: interrupt\n\n{verdict.question}", cycle.paths): return Stop(1, failure.reason) - if stop := interrupt(root, session.id, models.worker, path, verdict.question, paths): + if stop := interrupt(cycle.root, cycle.session.id, cycle.models.worker, path, verdict.question, cycle.paths): return stop diff --git a/bin/loop_claude/main.py b/bin/loop_claude/main.py index 5b77cbc4..e791e300 100644 --- a/bin/loop_claude/main.py +++ b/bin/loop_claude/main.py @@ -36,7 +36,8 @@ loop-claude --help succeeds. import dataclasses import sys -from loop_claude.cycle import run_cycle +from loop_claude.claude_code.session import session_for +from loop_claude.cycle import Cycle, run_cycle from loop_claude.outcome import Stop from loop_claude.project.checkout import checkout_root, project_name from loop_claude.project.models import project_models @@ -60,6 +61,7 @@ def run_loop(argv, env, paths, launcher, cwd): return state baseline = fingerprint(launcher) project = project_name(state.root, paths.code) + session = session_for(project, paths) while True: exec_if_edited(launcher, baseline, state) state = dataclasses.replace(state, cycle_number=state.cycle_number + 1) @@ -70,7 +72,7 @@ def run_loop(argv, env, paths, launcher, cwd): if isinstance(models, Stop): return models print(f"\n=== cycle {state.cycle_number} ===", flush=True) - if stop := run_cycle(state.root, project, state.task, premises, models, paths): + if stop := run_cycle(Cycle(models=models, paths=paths, premises=premises, project=project, root=state.root, session=session, task=state.task)): return stop diff --git a/todo.md b/todo.md index adcd7274..f26afe02 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 2f9ab2f named (`docs/decisions.md`), capping dimension first: -- **Hand `run_cycle` and `judge_through_interrupts` one cycle context.** Two seats: eight positional arguments. - **Build `premises.sections` without filling `found` through an alias.** Two seats traced `current` by hand. - **Route a fix through larv-review's Re-entry in one read.** All four seats reread "Re-entry" and "Round cap" against the pass table, reaching a round through `CLAUDE.md` → "Vocabulary" and `review-findings.md` → "Rounds". - **Keep in `UserEntryKind` only the kinds a caller tells apart.** Three seats: `human_text` compares only `HUMAN`, and they hunted for the caller of the other six. -- 2.52.0