Answer principles round 1: 0 🔴, 3 🟡 (0 misread); return withdraw's failure as a warning, check every field read_ask reads, test loop-inbox's /talk end, move TALK to waiting.py
This commit is contained in:
+21
-11
@@ -23,6 +23,7 @@ bin/loop_claude/waiting.py describes.
|
||||
|
||||
Exit 2 when stdin or stdout is not a terminal, or on an unknown argument.
|
||||
"""
|
||||
import contextlib
|
||||
import curses
|
||||
import pathlib
|
||||
import sys
|
||||
@@ -75,7 +76,7 @@ def run(window: curses.window, paths: Paths, effects: Effects) -> None:
|
||||
case Send(ask, text):
|
||||
screen = Listing(note=sent(folder, ask, text))
|
||||
case Open(ask):
|
||||
screen = Listing(note=opened(window, paths, ask, effects))
|
||||
screen = Listing(note=opened(lambda: off_screen(window), paths, ask, effects))
|
||||
case Listing() | Answering() as next_screen:
|
||||
screen = next_screen
|
||||
|
||||
@@ -125,8 +126,8 @@ def sent(folder: pathlib.Path, ask: Ask, text: str) -> str:
|
||||
return f"Sent to {ask.root}."
|
||||
|
||||
|
||||
def opened(window: curses.window, paths: Paths, ask: Ask, effects: Effects) -> str:
|
||||
"""Opens the worker's claude session on this terminal once the loop has made way for it, and says what came of it."""
|
||||
def opened(screen_off: typing.Callable[[], typing.ContextManager[None]], paths: Paths, ask: Ask, effects: Effects) -> str:
|
||||
"""Opens the worker's claude session on this terminal, inside screen_off, once the loop has made way for it, and says what came of it."""
|
||||
folder = paths.waiting
|
||||
if not (isinstance(ask.state, Asking) and still_waits(folder, ask)):
|
||||
return no_longer_waits(ask)
|
||||
@@ -135,14 +136,23 @@ def opened(window: curses.window, paths: Paths, ask: Ask, effects: Effects) -> s
|
||||
return f"Could not open claude for {ask.root}: {claimed.reason}"
|
||||
if not claimed:
|
||||
return f"{ask.root} did not make way for claude within {MAKE_WAY_SECONDS:g} s; it was answered on its terminal, or stopped."
|
||||
curses.def_prog_mode()
|
||||
curses.endwin()
|
||||
try:
|
||||
unstarted = hand_over(ask.state.talk, paths, effects)
|
||||
finally:
|
||||
unsent = send(folder, ask, ClaudeEnded())
|
||||
curses.reset_prog_mode()
|
||||
window.refresh()
|
||||
with screen_off():
|
||||
try:
|
||||
unstarted = hand_over(ask.state.talk, paths, effects)
|
||||
finally:
|
||||
unsent = send(folder, ask, ClaudeEnded())
|
||||
said = f"Could not start claude for {ask.root}: {unstarted.reason}" if unstarted else f"claude for {ask.root} has ended; the loop goes on."
|
||||
# Without ClaudeEnded, the loop goes on only once loop-inbox quits.
|
||||
return f"{said} Could not tell the loop: {unsent.reason}; quit loop-inbox to let it go on." if unsent else said
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def off_screen(window: curses.window) -> typing.Iterator[None]:
|
||||
"""Hands the terminal to another program, and draws loop-inbox again once it ends."""
|
||||
curses.def_prog_mode()
|
||||
curses.endwin()
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
curses.reset_prog_mode()
|
||||
window.refresh()
|
||||
|
||||
Reference in New Issue
Block a user