Merge remote-tracking branch 'origin/main' into item-420

# Conflicts:
#	bin/loop_claude/test_loop_claude.py
#	bin/loop_effects/test_effects.py
This commit is contained in:
2026-11-19 07:46:23 +01:00
162 changed files with 8606 additions and 1433 deletions
+20 -3
View File
@@ -10,6 +10,7 @@ import signal
import subprocess
import sys
import termios
import threading
import time
import typing
@@ -48,8 +49,8 @@ class Effects:
claude_on_terminal: typing.Callable[[list[str], str, dict[str, str]], int]
# Drops what was typed on the terminal and not yet read.
discard_typed: typing.Callable[[], None]
# Sends the human a direct message through the notifier the project's config names, as `notify` does, for the project whose checkout holds the current directory; a Failure where it could not.
dm: typing.Callable[[str], Failure | None]
# Sends the human a direct message through the notifier the project's config names, as `notify` does, for the project whose checkout holds the given directory, else the current directory; a Failure where it could not.
dm: typing.Callable[[str, str | None], Failure | None]
execv: typing.Callable[[str, list[str]], None]
git: git_repo.Git
input: typing.Callable[[str], str]
@@ -63,6 +64,8 @@ class Effects:
python: typing.Callable[[list[str], str], subprocess.CompletedProcess[str]]
sleep: typing.Callable[[float], None]
stream_claude: typing.Callable[[list[str], str, dict[str, str]], Streaming]
# Starts a timer, as start_timer does.
timer: typing.Callable[[float, typing.Callable[[], None]], typing.Callable[[], None]]
# Runs tmux with these arguments, as run_tmux does.
tmux: typing.Callable[[list[str]], subprocess.CompletedProcess[str]]
# Runs tmux on the terminal, as to attach a session, and returns its exit code once the human detaches.
@@ -108,7 +111,7 @@ def system_effects(backends: typing.Mapping[Notifier, Backend[typing.Any]] = BAC
claude=lambda args, cwd, stdin: subprocess.run(["claude", *args], capture_output=True, cwd=cwd, input=stdin, text=True),
claude_on_terminal=claude_on_terminal,
discard_typed=lambda: termios.tcflush(sys.stdin, termios.TCIFLUSH),
dm=lambda text: notify(text, None, pathlib.Path.home(), backends),
dm=lambda text, directory: notify(text, directory, pathlib.Path.home(), backends),
execv=os.execv,
git=git_repo.git,
input=input,
@@ -119,6 +122,7 @@ def system_effects(backends: typing.Mapping[Notifier, Backend[typing.Any]] = BAC
python=lambda args, cwd: run_python(args, cwd, PYTHON_TIMEOUT),
sleep=time.sleep,
stream_claude=StreamingClaude,
timer=start_timer,
tmux=run_tmux,
tmux_on_terminal=lambda args: subprocess.run(["tmux", *args]).returncode,
)
@@ -145,6 +149,19 @@ def run_python(args: list[str], cwd: str, timeout: float) -> subprocess.Complete
return subprocess.CompletedProcess(command, 1, "", f"stopped after {timeout} s")
def start_timer(delay: float, action: typing.Callable[[], None]) -> typing.Callable[[], None]:
"""Runs action on a thread of its own once delay seconds have passed, and returns what stops the timer: it cancels an action not yet started, and waits for one that has started to end."""
timer = threading.Timer(delay, action)
# A timer still running doesn't keep the process alive once the loop exits.
timer.daemon = True
timer.start()
def stop() -> None:
timer.cancel()
timer.join()
return stop
def run_tmux(args: list[str]) -> subprocess.CompletedProcess[str]:
"""Runs tmux and returns what it printed. A tmux that cannot start, as where none is installed, reads as exit 127, saying why on stderr."""
command = ["tmux", *args]