Decode the worker's stream leniently, name UserEntryKind's members only, and restore the section-headers decision's citation

This commit is contained in:
2026-09-28 16:28:43 +02:00
parent 72d04227f9
commit 9659f70efd
6 changed files with 24 additions and 20 deletions
+9 -8
View File
@@ -67,7 +67,7 @@ def run_cycle(root, task, premises, chosen, paths, env):
return stop
if verdict["finished"]:
archive(root, path, f"Task: {task}\n\nVerdict: finished", paths)
delete_session(path)
delete_session(session)
return Continue()
@@ -254,14 +254,15 @@ def interrupt(root, session_id, chosen, path, question, paths, env):
if not (sys.stdin.isatty() and sys.stdout.isatty()):
return Stop(2, "stdin or stdout is not a terminal")
trust(paths.claude_json, checkouts(root))
before = read(path)
if isinstance(before, Failure):
return Stop(1, before.reason)
entries = read(path)
if isinstance(entries, Failure):
return Stop(1, entries.reason)
before = human_turns(entries)
subprocess.run(["claude", "--model", model_for(env, "LOOP_CLAUDE_WORKER_MODEL", chosen), "--permission-mode", "bypassPermissions", "--resume", str(session_id)], cwd=root)
after = read(path)
if isinstance(after, Failure):
return Stop(1, f"could not tell whether you typed anything: {after.reason}")
if human_turns(after) <= human_turns(before):
entries = read(path)
if isinstance(entries, Failure):
return Stop(1, f"could not tell whether you typed anything: {entries.reason}")
if human_turns(entries) <= before:
return Stop(2, "the interrupt ended without the human typing anything")
return None
+4 -1
View File
@@ -31,7 +31,10 @@ def transcript_file(session):
return hit[0] if hit else ""
def delete_session(path):
def delete_session(session):
path = transcript_file(session)
if not path:
return
for sibling in glob.glob(glob.escape(path.removesuffix(".jsonl")) + "*"):
try:
shutil.rmtree(sibling) if os.path.isdir(sibling) else os.remove(sibling)
+8 -8
View File
@@ -5,15 +5,15 @@ from loop_claude.outcome import Failure
class UserEntryKind(enum.Enum):
"""Who wrote a "user" entry: the human wrote HUMAN, Claude Code every other kind; the value is the tell."""
"""Who wrote a "user" entry: the human wrote HUMAN, Claude Code every other kind."""
COMMAND = "string content starting with <"
CTRL_C = "a text part starting with [Request interrupted"
EMPTY = "no content"
HUMAN = "typed by the human"
META = "isMeta"
NON_TEXT = "a part that is not text, such as a tool result"
SDK_PROMPT = "promptSource sdk: the claude -p prompt"
COMMAND = enum.auto()
CTRL_C = enum.auto()
EMPTY = enum.auto()
HUMAN = enum.auto()
META = enum.auto()
NON_TEXT = enum.auto()
SDK_PROMPT = enum.auto()
def read(path):
+1 -1
View File
@@ -6,7 +6,7 @@ from loop_claude.transcript import parse, parts, said
def run_worker(root, args):
try:
proc = subprocess.Popen(["claude", *args], cwd=root, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, text=True)
proc = subprocess.Popen(["claude", *args], cwd=root, encoding="utf-8", errors="replace", stdin=subprocess.DEVNULL, stdout=subprocess.PIPE)
except OSError as failure:
return Failure(f"could not start claude: {failure.strerror}")
with proc: