Name each entry shape written_by_human checks, and annotate every parameter in loop_claude

This commit is contained in:
2026-10-01 23:47:03 +02:00
parent 70ad9a9caa
commit 39acf6dff0
24 changed files with 113 additions and 84 deletions
+7 -7
View File
@@ -27,7 +27,7 @@ class Cycle:
task: str
def run_cycle(cycle) -> Stop | None:
def run_cycle(cycle: Cycle) -> Stop | None:
state: State = Working()
while not isinstance(state, Ended):
event = step(cycle, state)
@@ -37,7 +37,7 @@ def run_cycle(cycle) -> Stop | None:
return None
def step(cycle, state: Active) -> Event | Stop:
def step(cycle: Cycle, state: Active) -> Event | Stop:
match state:
case Working():
return work(cycle)
@@ -51,7 +51,7 @@ def step(cycle, state: Active) -> Event | Stop:
typing.assert_never(state)
def work(cycle) -> WorkerRan | Stop:
def work(cycle: Cycle) -> WorkerRan | Stop:
# session_open runs inside the lambda: a failed attempt may have opened the session.
if stop := retried("worker", lambda: run_worker(cycle.root, worker_args(cycle.task, cycle.session, cycle.models.worker, session_open(cycle.session)), cycle.effects), cycle.effects):
return stop
@@ -59,7 +59,7 @@ def work(cycle) -> WorkerRan | Stop:
return WorkerRan(path) if path else Stop(1, f"claude left no transcript for session {cycle.session.id}")
def rule(cycle, transcript_path) -> Ruled | Stop:
def rule(cycle: Cycle, transcript_path: str) -> Ruled | Stop:
entries = read(transcript_path)
if isinstance(entries, Failure):
return Stop(1, entries.reason)
@@ -67,19 +67,19 @@ def rule(cycle, transcript_path) -> Ruled | Stop:
return verdict if isinstance(verdict, Stop) else Ruled(verdict)
def ask(cycle, transcript_path, question) -> Answered | Stop:
def ask(cycle: Cycle, transcript_path: str, question: str) -> Answered | Stop:
# The interrupt appends to this transcript, so it is archived at each question.
if failure := archive(cycle.project, transcript_path, f"Task: {cycle.task}\n\nVerdict: interrupt\n\n{question}", cycle.paths):
return Stop(1, failure.reason)
return interrupt(cycle.root, cycle.session.id, cycle.models.worker, transcript_path, question, cycle.paths, cycle.effects) or Answered()
def close(cycle, transcript_path) -> Archived | Stop:
def close(cycle: Cycle, transcript_path: str) -> Archived | Stop:
if failure := archive(cycle.project, transcript_path, f"Task: {cycle.task}\n\nVerdict: finished", cycle.paths):
return Stop(1, failure.reason)
delete_session(cycle.session)
return Archived()
def session_open(session) -> bool:
def session_open(session: Session) -> bool:
return bool(transcript_file(session))