Give failure one spelling
This commit is contained in:
@@ -5,7 +5,7 @@ from loop_claude.checkout import project_name
|
||||
from loop_claude.file_writes import make_private, replace_file
|
||||
from loop_claude.interrupt import interrupt
|
||||
from loop_claude.judge import judge
|
||||
from loop_claude.outcome import Continue, Failure, Retry, Stop
|
||||
from loop_claude.outcome import Continue, Failure, Stop
|
||||
from loop_claude.session import delete_session, session_for, transcript_file
|
||||
from loop_claude.transcript import read, render
|
||||
from loop_claude.worker import run_worker, worker_args
|
||||
@@ -15,7 +15,7 @@ def run_cycle(root, task, premises, models, paths):
|
||||
session = session_for(root, paths)
|
||||
resuming = bool(transcript_file(session))
|
||||
if failure := run_worker(root, worker_args(task, session, models.worker, resuming)):
|
||||
return Retry(failure.reason)
|
||||
return failure
|
||||
path = transcript_file(session)
|
||||
if not path:
|
||||
return Stop(1, f"claude left no transcript for session {session.id}")
|
||||
@@ -57,6 +57,6 @@ def archive(root, path, note, paths):
|
||||
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.strerror}")
|
||||
return Failure(f"could not archive the transcript: {dest}: {failure.reason}")
|
||||
print(f"transcript: {copy}", file=sys.stderr)
|
||||
return None
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
from loop_claude.outcome import Failure
|
||||
|
||||
|
||||
def make_private(folder):
|
||||
mask = os.umask(0o077)
|
||||
@@ -25,5 +27,5 @@ def replace_file(path, data):
|
||||
except OSError as failure:
|
||||
if os.path.exists(staged):
|
||||
os.remove(staged)
|
||||
return failure
|
||||
return Failure(failure.strerror)
|
||||
return None
|
||||
|
||||
@@ -39,7 +39,7 @@ import sys
|
||||
from loop_claude.checkout import checkout_root
|
||||
from loop_claude.cycle import run_cycle
|
||||
from loop_claude.models import project_models
|
||||
from loop_claude.outcome import Continue, Retry, Stop
|
||||
from loop_claude.outcome import Continue, Failure, Stop
|
||||
from loop_claude.premises import read_premises
|
||||
from loop_claude.reload import RELOAD_FLAG, decode_state, exec_if_edited, fingerprint
|
||||
from loop_claude.retry import stop_or_sleep_a_minute
|
||||
@@ -81,9 +81,9 @@ def run_loop(argv, env, paths, launcher, cwd):
|
||||
match run_cycle(state.root, state.task, premises, models, paths):
|
||||
case Stop() as stop:
|
||||
return stop
|
||||
case Retry(failure):
|
||||
case Failure(reason):
|
||||
state = dataclasses.replace(state, failures=state.failures + 1)
|
||||
if stop := stop_or_sleep_a_minute("worker", state.failures, failure):
|
||||
if stop := stop_or_sleep_a_minute("worker", state.failures, reason):
|
||||
return stop
|
||||
case Continue():
|
||||
state = dataclasses.replace(state, failures=0)
|
||||
|
||||
@@ -40,7 +40,7 @@ def project_model(name, paths):
|
||||
if isinstance(models, Stop):
|
||||
return models
|
||||
if failure := replace_json(saved, {**models, name: chosen}, indent="\t", sort_keys=True):
|
||||
return Stop(1, f"could not save the model in {saved}: {failure.strerror}")
|
||||
return Stop(1, f"could not save the model in {saved}: {failure.reason}")
|
||||
print(f"{name} runs on {chosen}", file=sys.stderr)
|
||||
return chosen
|
||||
|
||||
|
||||
@@ -11,11 +11,6 @@ class Failure:
|
||||
reason: str
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Retry:
|
||||
failure: str
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Stop:
|
||||
code: int
|
||||
|
||||
@@ -19,13 +19,13 @@ def human_turns(entries):
|
||||
def render(entries):
|
||||
lines = []
|
||||
for entry in entries:
|
||||
lines += [line for part in assistant_parts(entry) if (line := said(part))]
|
||||
lines += [line for part in assistant_parts(entry) if (line := part_line(part))]
|
||||
if (text := human_text(entry)) is not None:
|
||||
lines.append("[human] " + text)
|
||||
return "\n\n".join(lines)
|
||||
|
||||
|
||||
def said(part, limit=400):
|
||||
def part_line(part, limit=400):
|
||||
if (text := part_text(part)) and text.strip():
|
||||
return text
|
||||
if call := tool_call(part):
|
||||
|
||||
@@ -21,6 +21,6 @@ def trust(config, roots):
|
||||
if not untrusted:
|
||||
return
|
||||
if failure := replace_json(config, data, indent=2):
|
||||
print(f"could not write {config}: {failure.strerror}", file=sys.stderr)
|
||||
print(f"could not write {config}: {failure.reason}", file=sys.stderr)
|
||||
return
|
||||
print("trusted for the interrupt: " + ", ".join(untrusted), file=sys.stderr)
|
||||
|
||||
@@ -2,7 +2,7 @@ import subprocess
|
||||
|
||||
from loop_claude.claude_code import assistant_parts, ends_stream, parse
|
||||
from loop_claude.outcome import Failure
|
||||
from loop_claude.transcript import said
|
||||
from loop_claude.transcript import part_line
|
||||
|
||||
|
||||
def run_worker(root, args):
|
||||
@@ -16,7 +16,7 @@ def run_worker(root, args):
|
||||
event = parse(raw) or {}
|
||||
done = done or ends_stream(event)
|
||||
for part in assistant_parts(event):
|
||||
if line := said(part, 160):
|
||||
if line := part_line(part, 160):
|
||||
print(line, flush=True)
|
||||
code = proc.wait()
|
||||
if code < 0:
|
||||
|
||||
Reference in New Issue
Block a user