List a loop's question in loop-inbox only while the loop holds the session's lock, so a killed loop's question stays gone whatever its pid now names

This commit is contained in:
2026-10-29 18:14:44 +01:00
parent 93d413f5f3
commit 5df105033c
10 changed files with 157 additions and 66 deletions
+6 -6
View File
@@ -33,7 +33,7 @@ import sys
import typing
from loop_inbox.inbox import Answering, answering_lines, BACKSPACE, ENTER, ESCAPE, fitted, Listing, listing_lines, Open, pressed, Quit, Screen, Send
from loop_claude.waiting import Ask, ask_file, Asking, claim_talk, ClaudeEnded, MAKE_WAY_SECONDS, read_ask, send, Typed, waiting
from loop_claude.waiting import Ask, ask_file, Asking, claim_talk, ClaudeEnded, MAKE_WAY_SECONDS, read_ask, running, send, Typed, waiting
from loop_claude.effects import Effects, system_effects
from failure import Failure
from loop_claude.hand_over import hand_over
@@ -69,7 +69,7 @@ def run(window: curses.window, screen_off: typing.Callable[[], typing.ContextMan
window.timeout(REFRESH_MS)
screen: Screen = Listing()
while True:
screen = entered(screen, refreshed(screen, folder, effects.alive), effects)
screen = entered(screen, refreshed(screen, folder), effects)
draw(window, screen, effects)
try:
key = window.get_wch()
@@ -100,11 +100,11 @@ def key_name(key: str | int) -> str:
return KEYS.get(key, key if isinstance(key, str) else "")
def refreshed(screen: Screen, folder: pathlib.Path, alive: typing.Callable[[int], bool]) -> Screen:
def refreshed(screen: Screen, folder: pathlib.Path) -> Screen:
"""screen with the loops as they wait now, unless the human is typing a number; a question that no longer waits leaves the answer screen."""
match screen:
case Listing(_, "", note):
return Listing(tuple(waiting(folder, alive)), "", note)
return Listing(tuple(waiting(folder)), "", note)
case Answering(ask) if not still_waits(folder, ask):
return Listing(note=no_longer_waits(ask))
return screen
@@ -125,9 +125,9 @@ def draw(window: curses.window, screen: Screen, effects: Effects) -> None:
def still_waits(folder: pathlib.Path, ask: Ask) -> bool:
"""Whether ask still waits for an answer from loop-inbox."""
"""Whether ask still waits for an answer from loop-inbox, from a loop that still runs."""
now = read_ask(ask_file(folder, ask.session))
return now is not None and now.id == ask.id and isinstance(now.state, Asking)
return now is not None and now.id == ask.id and isinstance(now.state, Asking) and running(folder, ask.session)
def no_longer_waits(ask: Ask) -> str: