Hand run_cycle and judge_through_interrupts one cycle context #131
+27
-13
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user