List every running loop in loop-inbox, with the ID and tagline of each item its chunk takes

This commit is contained in:
2026-10-29 19:57:11 +01:00
parent 8bddfdc282
commit 9bcfaebb83
16 changed files with 389 additions and 50 deletions
+28 -3
View File
@@ -3,12 +3,15 @@
How it shows the loops and a question was picked on 2026-10-28 by a bench of three readers seated as the README's
audience, as ~/.claude/CLAUDE.md → "Working loop" → "Bench a syntax with the people who write it." has it: a block per
loop with its checkout's path and how long it has waited, and an answer prompt saying that Enter alone doesn't stop the loop.
A second bench, on 2026-10-29, picked the running loops' section: below the waiting loops, a line per loop with its
checkout and the number it waits as, then a line per item its chunk takes, with its ID and tagline.
"""
import dataclasses
import textwrap
import typing
from loop_claude.waiting import Ask, Asking, OpenInInbox, OpenOnTerminal, TALK
from loop_claude.running_loops import RunningLoop, Taken
ENTER = "enter"
BACKSPACE = "backspace"
@@ -24,10 +27,11 @@ NARROWEST = 20
@dataclasses.dataclass(frozen=True)
class Listing:
"""The waiting loops as they were when the human began typing a number, so a loop's number doesn't change while they type it."""
"""The waiting loops as they were when the human began typing a number, so a loop's number doesn't change while they type it, and the running loops."""
shown: tuple[Ask, ...] = ()
typed: str = ""
note: str = ""
running: tuple[RunningLoop, ...] = ()
@dataclasses.dataclass(frozen=True)
@@ -65,9 +69,9 @@ def pressed(screen: Screen, key: str) -> Screen | Send | Open | Quit:
if key == ENTER:
return picked(shown, typed)
if key == BACKSPACE:
return Listing(shown, typed[:-1])
return dataclasses.replace(screen, typed=typed[:-1])
# isdigit would also take "²", which int() rejects.
return Listing(shown, typed + key) if key.isdecimal() else screen
return dataclasses.replace(screen, typed=typed + key) if key.isdecimal() else screen
case Answering(ask, typed):
if key == ESCAPE or (key == ENTER and not typed.strip()):
return Listing()
@@ -106,10 +110,31 @@ def listing_lines(screen: Listing, now: float, local_time: typing.Callable[[floa
lines += wrapped(f"[{number}] {ask.root}, waiting since {local_time(ask.asked)} ({waited(now - ask.asked)}){state}", width)
lines += cut(wrapped(ask.question, width - len(INDENT) - len(ELLIPSIS)), SHOWN_LINES)
lines.append("")
lines += running_lines(screen.running, screen.shown, width)
ask_for = "Type a number and Enter to answer that loop; " if count else ""
return lines, [*wrapped(screen.note, width), *wrapped(f"{ask_for}{QUIT} quits loop-inbox, and the loops keep waiting.", width), *typed_after(">", screen.typed, width)]
def running_lines(running: tuple[RunningLoop, ...], shown: tuple[Ask, ...], width: int) -> list[str]:
"""Each running loop's checkout, with the number it waits as, and a line per item its chunk takes."""
if not running:
return ["No loop runs."]
numbers = {ask.session: number for number, ask in enumerate(shown, 1)}
lines = wrapped(f"Running: {len(running)} loop{'s' if len(running) > 1 else ''}", width)
for loop in running:
waits_as = f", waiting as [{numbers[loop.session]}]" if loop.session in numbers else ""
lines += wrapped(f"- {loop.root}{waits_as}", width)
for item in loop.items or (None,):
lines += cut(wrapped(item_line(item), width - len(INDENT) - len(ELLIPSIS)), 1)
return lines
def item_line(item: Taken | None) -> str:
if item is None:
return "no todo.md item yet"
return f"item {item.id}: {item.tagline}" if item.tagline else f"item {item.id}"
def answering_lines(screen: Answering, now: float, local_time: typing.Callable[[float], str], width: int) -> tuple[list[str], list[str]]:
"""The question, in lines of at most width characters, and its foot, the prompt for the answer."""
ask = screen.ask