32 lines
1.3 KiB
Python
32 lines
1.3 KiB
Python
import sys
|
|
import uuid
|
|
|
|
from loop_claude.effects import Effects
|
|
from failure import Failure
|
|
from loop_claude.claude_code.transcript import human_turns, read_transcript
|
|
from loop_claude.stop import needs_human, needs_terminal, Stop
|
|
from loop_claude.paths import Paths
|
|
from loop_claude.claude_code.trust import trust
|
|
from loop_claude.project.checkout import worktrees
|
|
|
|
ANSWER_QUESTION = "answer the question above"
|
|
|
|
|
|
def interrupt(root: str, session_id: uuid.UUID, model: str, path: str, question: str, paths: Paths, effects: Effects) -> Stop | None:
|
|
print(f"\n{question}", file=sys.stderr)
|
|
if stop := needs_terminal(ANSWER_QUESTION, effects.on_terminal()):
|
|
return stop
|
|
trust(paths.claude_json, worktrees(root, effects))
|
|
entries = read_transcript(path)
|
|
if isinstance(entries, Failure):
|
|
return Stop(1, entries.reason)
|
|
before = human_turns(entries)
|
|
try:
|
|
effects.claude_on_terminal(["--model", model, "--permission-mode", "bypassPermissions", "--resume", str(session_id)], root)
|
|
except OSError as failure:
|
|
return Stop(1, f"could not start claude for the interrupt: {failure.strerror}")
|
|
entries = read_transcript(path)
|
|
if isinstance(entries, Failure):
|
|
return Stop(1, f"could not tell whether you typed anything: {entries.reason}")
|
|
return None if human_turns(entries) > before else needs_human(ANSWER_QUESTION, "the interrupt ended with nothing typed")
|