Name the session invariant run_cycle resumes on, and say which outcome ended an interrupt
This commit is contained in:
+10
-4
@@ -133,6 +133,11 @@ def end_session(path):
|
||||
print(f"could not remove {sibling}: {failure}", file=sys.stderr)
|
||||
|
||||
|
||||
def session_open(session_id):
|
||||
"""The transcript outlives its cycle until end_session removes it: present means the chunk is unfinished."""
|
||||
return bool(session_file(session_id))
|
||||
|
||||
|
||||
def parse(raw):
|
||||
try:
|
||||
entry = json.loads(raw)
|
||||
@@ -306,15 +311,15 @@ def judge(task, premises, transcript):
|
||||
def interrupt(session_id, path, question):
|
||||
print(f"\n{question}", file=sys.stderr)
|
||||
if not (sys.stdin.isatty() and sys.stdout.isatty()):
|
||||
return False
|
||||
return "the human is needed and no terminal is attached"
|
||||
trust(checkouts())
|
||||
before = human_turns(entries(path))
|
||||
subprocess.run(["claude", "--permission-mode", "bypassPermissions", "--resume", str(session_id)])
|
||||
return human_turns(entries(path)) > before
|
||||
return "" if human_turns(entries(path)) > before else "the interrupt ended without the human typing anything"
|
||||
|
||||
|
||||
def run_cycle(task, premises, name, session_id):
|
||||
worked = run_worker(worker_args(task, name, session_id, resuming=bool(session_file(session_id))))
|
||||
worked = run_worker(worker_args(task, name, session_id, resuming=session_open(session_id)))
|
||||
if not worked:
|
||||
return False
|
||||
path = session_file(session_id)
|
||||
@@ -323,7 +328,8 @@ def run_cycle(task, premises, name, session_id):
|
||||
verdict = judge(task, premises, render(entries(path)))
|
||||
while verdict["ask"]:
|
||||
archive(path, f"Task: {task}\n\nVerdict: needs input\n\n{verdict['question']}")
|
||||
if not interrupt(session_id, path, verdict["question"]):
|
||||
if failure := interrupt(session_id, path, verdict["question"]):
|
||||
print(failure, file=sys.stderr)
|
||||
sys.exit(2)
|
||||
verdict = judge(task, premises, render(entries(path)))
|
||||
if verdict["finished"]:
|
||||
|
||||
Reference in New Issue
Block a user