Answer stability round 1: 1 🔴, 11 🟡 (0 misread); drop keys typed ahead on leaving an answer, wrap every line to the drawn width, list the routing calls, test the paths mutants survived

This commit is contained in:
2026-10-29 01:27:23 +01:00
parent 192b36fada
commit e3cd8ae0cf
15 changed files with 413 additions and 151 deletions
+44 -26
View File
@@ -1,21 +1,23 @@
"""Show every loop-claude on this machine that waits for you, oldest first, and answer each one here.
"""Show the interrupts of every loop-claude on this machine, oldest first, and answer each one here.
usage: loop-inbox
Each loop-claude that asks you a question lists it here, as well as on its own terminal, until it is
answered or the loop stops. The list shows each loop's checkout, when it asked and how long it has
waited, and the question's first lines; it refreshes every second. Type a loop's number and Enter
to see its whole question, then answer as on the loop's terminal:
Each loop-claude lists its interrupt here, as well as on its own terminal, until it is answered or
the loop stops. The list shows each loop's checkout, when it asked and how long it has waited, and
the question's first lines; it refreshes every second. Type a loop's number and Enter to see as much
of its question as fits; the loop's terminal shows it whole. Answer as on the loop's terminal:
- A line and Enter sends it to that loop, which goes on with it.
- A line and Enter sends it to that loop, which goes on with it. Of a pasted answer, only the first
line is sent, and the rest is dropped; a longer answer goes through /talk.
- /talk opens the worker's claude session here, with `claude --resume`, as /talk does on the loop's
terminal. Once that claude ends, the loop goes on, and the judge rules on what was typed there; a
loop whose claude ends with nothing typed stops.
terminal. Once that claude ends, the loop goes on if you typed there, and the judge rules on what
you typed; if you typed nothing, the loop stops.
- Enter alone, or Esc, goes back to the list; unlike on the loop's terminal, it doesn't stop the loop.
The loop takes whichever answer comes first, here or on its terminal, so it keeps working with no
loop-inbox running. A loop whose release is ready to cut, or whose /talk is open, shows that claude
is open, and is answered there. A loop whose process is gone drops off the list. q quits
loop-inbox running. A loop with claude open, for a release ready to cut, the routing calls or a
/talk, says where, and is answered there. A loop whose process is gone drops off the list. A loop
asking for its project's model, as on a project's first run, asks on its own terminal only. q quits
loop-inbox; the loops keep waiting.
The loops' questions are files in ~/.local/state/loop-claude, read and written as
@@ -25,6 +27,7 @@ Exit 2 when stdin or stdout is not a terminal, or on an unknown argument.
"""
import contextlib
import curses
import dataclasses
import pathlib
import sys
import typing
@@ -52,33 +55,44 @@ def main(argv: list[str], home: pathlib.Path) -> int:
if not (sys.stdin.isatty() and sys.stdout.isatty()):
print("loop-inbox: stdin or stdout is not a terminal; run it on one", file=sys.stderr)
return 2
# curses may hold keys it has read ahead, which only flushinp drops.
effects = dataclasses.replace(system_effects(), discard_typed=curses.flushinp)
try:
curses.wrapper(lambda window: run(window, paths_from(home), system_effects()))
curses.wrapper(lambda window: run(window, lambda: off_screen(window), paths_from(home), effects))
except KeyboardInterrupt:
pass
return 0
def run(window: curses.window, paths: Paths, effects: Effects) -> None:
def run(window: curses.window, screen_off: typing.Callable[[], typing.ContextManager[None]], paths: Paths, effects: Effects) -> None:
folder = paths.waiting
window.timeout(REFRESH_MS)
screen: Screen = Listing()
while True:
screen = refreshed(screen, folder, effects.alive)
screen = entered(screen, refreshed(screen, folder, effects.alive), effects)
draw(window, screen, effects)
try:
key = window.get_wch()
except curses.error:
continue # No key within REFRESH_MS.
after: Screen
match pressed(screen, key_name(key)):
case Quit():
return
case Send(ask, text):
screen = Listing(note=sent(folder, ask, text))
after = Listing(note=sent(folder, ask, text))
case Open(ask):
screen = Listing(note=opened(lambda: off_screen(window), paths, ask, effects))
after = Listing(note=opened(screen_off, paths, ask, effects))
case Listing() | Answering() as next_screen:
screen = next_screen
after = next_screen
screen = entered(screen, after, effects)
def entered(before: Screen, after: Screen, effects: Effects) -> Screen:
"""after, the screen that follows before. Leaving the answer screen drops the keys typed ahead, since on the list the rest of a pasted answer would pick a loop and answer it."""
if isinstance(before, Answering) and isinstance(after, Listing):
effects.discard_typed()
return after
def key_name(key: str | int) -> str:
@@ -97,13 +111,16 @@ def refreshed(screen: Screen, folder: pathlib.Path, alive: typing.Callable[[int]
def draw(window: curses.window, screen: Screen, effects: Effects) -> None:
height, width = window.getmaxyx()
height, columns = window.getmaxyx()
# The screen's last cell cannot be written without an error, so lines leave the last column empty.
width = columns - 1
now = effects.now()
lines = listing_lines(screen, now, effects.local_time, width) if isinstance(screen, Listing) else answering_lines(screen, now, effects.local_time, width)
lines, foot = listing_lines(screen, now, effects.local_time, width) if isinstance(screen, Listing) else answering_lines(screen, now, effects.local_time, width)
window.erase()
for row, line in enumerate(fitted(lines, height)):
# The last cell of the screen cannot be written without an error, so each line stops one short of it.
window.addnstr(row, 0, line, width - 1)
for row, line in enumerate(fitted(lines, foot, height)):
# addnstr counts characters, not cells, so a line of wide characters, such as emoji, can still run into the last cell.
with contextlib.suppress(curses.error):
window.addnstr(row, 0, line, width)
window.refresh()
@@ -114,7 +131,7 @@ def still_waits(folder: pathlib.Path, ask: Ask) -> bool:
def no_longer_waits(ask: Ask) -> str:
return f"{ask.root} no longer waits for that answer: it was answered on its terminal, or stopped."
return f"{ask.root} no longer waits for that answer: it was answered elsewhere, or stopped."
def sent(folder: pathlib.Path, ask: Ask, text: str) -> str:
@@ -135,15 +152,16 @@ def opened(screen_off: typing.Callable[[], typing.ContextManager[None]], paths:
if isinstance(claimed, Failure):
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."
return f"Could not open claude for {ask.root}: the loop was answered elsewhere or stopped, or didn't respond within {MAKE_WAY_SECONDS:g} s. If it is still listed, pick it again."
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
# The loop goes on only where the human typed in the worker's session, as interrupt.human_typed checks.
said = f"Could not start claude for {ask.root}: {unstarted.reason}. The loop stops." if unstarted else f"claude for {ask.root} has ended; the loop goes on if you typed there, and stops if you didn't."
# The loop also stops waiting for claude once loop-inbox's process ends.
return f"{said} Could not tell the loop that claude ended: {unsent.reason}; it waits until you quit loop-inbox." if unsent else said
@contextlib.contextmanager