import subprocess import sys from loop_claude import human from loop_claude.checkout import checkouts from loop_claude.outcome import Failure, Stop from loop_claude.transcript import human_turns, read from loop_claude.trust import trust TO = "answer the question above" def interrupt(root, session_id, model, path, question, paths): print(f"\n{question}", file=sys.stderr) if stop := human.off_terminal(TO): return stop trust(paths.claude_json, checkouts(root)) entries = read(path) if isinstance(entries, Failure): return Stop(1, entries.reason) before = human_turns(entries) try: subprocess.run(["claude", "--model", model, "--permission-mode", "bypassPermissions", "--resume", str(session_id)], cwd=root) except OSError as failure: return Stop(1, f"could not start claude for the interrupt: {failure.strerror}") 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 human.needed(TO, "the interrupt ended with nothing typed") return None