Name the project once in main, and give the archive its own module
This commit is contained in:
+10
-31
@@ -1,35 +1,31 @@
|
||||
import hashlib
|
||||
import sys
|
||||
|
||||
from loop_claude.project.checkout import project_name
|
||||
from loop_claude.file_writes import make_private, replace_file
|
||||
from loop_claude.claude_runs.interrupt import interrupt
|
||||
from loop_claude.claude_runs.judge import judge
|
||||
from loop_claude.outcome import Continue, Failure, Stop
|
||||
from loop_claude.archive import archive
|
||||
from loop_claude.claude_code.session import delete_session, session_for, 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 Continue, Failure, Stop
|
||||
|
||||
|
||||
def run_cycle(root, task, premises, models, paths):
|
||||
session = session_for(root, paths)
|
||||
def run_cycle(root, project, task, premises, models, paths):
|
||||
session = session_for(project, paths)
|
||||
resuming = bool(transcript_file(session))
|
||||
if failure := run_worker(root, worker_args(task, session, models.worker, resuming)):
|
||||
return failure
|
||||
path = transcript_file(session)
|
||||
if not path:
|
||||
return Stop(1, f"claude left no transcript for session {session.id}")
|
||||
verdict = judge_through_interrupts(root, task, premises, models, session, path, paths)
|
||||
verdict = judge_through_interrupts(root, project, task, premises, models, session, path, paths)
|
||||
if isinstance(verdict, Stop):
|
||||
return verdict
|
||||
if verdict["finished"]:
|
||||
if failure := archive(root, path, f"Task: {task}\n\nVerdict: finished", paths):
|
||||
if failure := archive(project, path, f"Task: {task}\n\nVerdict: finished", paths):
|
||||
return Stop(1, failure.reason)
|
||||
delete_session(session)
|
||||
return Continue()
|
||||
|
||||
|
||||
def judge_through_interrupts(root, task, premises, models, session, path, paths):
|
||||
def judge_through_interrupts(root, project, task, premises, models, session, path, paths):
|
||||
# The interrupt appends to this transcript, so each pass judges and archives it anew.
|
||||
while True:
|
||||
entries = read(path)
|
||||
@@ -38,25 +34,8 @@ def judge_through_interrupts(root, task, premises, models, session, path, paths)
|
||||
verdict = judge(root, task, premises, render(entries), models.judge)
|
||||
if isinstance(verdict, Stop) or not verdict["interrupt"]:
|
||||
return verdict
|
||||
if failure := archive(root, path, f"Task: {task}\n\nVerdict: interrupt\n\n{verdict['question']}", paths):
|
||||
if failure := archive(project, path, f"Task: {task}\n\nVerdict: interrupt\n\n{verdict['question']}", paths):
|
||||
return Stop(1, failure.reason)
|
||||
if stop := interrupt(root, session.id, models.worker, path, verdict["question"], paths):
|
||||
return stop
|
||||
|
||||
|
||||
def archive(root, path, note, paths):
|
||||
folder = paths.archive / project_name(root, paths.code)
|
||||
try:
|
||||
with open(path, "rb") as handle:
|
||||
raw = handle.read()
|
||||
make_private(folder)
|
||||
except OSError as failure:
|
||||
return Failure(f"could not archive the transcript: {failure.filename}: {failure.strerror}")
|
||||
copy = folder / f"{hashlib.sha256(raw).hexdigest()}.jsonl"
|
||||
# The copy lands last, so a copy on disk always has its verdict beside it.
|
||||
if not copy.exists():
|
||||
for dest, data in ((copy.with_suffix(".verdict.md"), f"{note}\n".encode()), (copy, raw)):
|
||||
if failure := replace_file(dest, data):
|
||||
return Failure(f"could not archive the transcript: {dest}: {failure.reason}")
|
||||
print(f"transcript: {copy}", file=sys.stderr)
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user