Answer principles round 1: 1 🔴, 7 🟡 (0 misread); every effect is handed in as an argument, no test patches a global, and the traces principle scopes tools that run on their user's machine
CI / tests (pull_request) Successful in 3m43s

This commit is contained in:
2026-11-19 12:42:03 +01:00
parent 8ca612b7a4
commit cb3135bc8c
124 changed files with 1437 additions and 793 deletions
+24 -7
View File
@@ -1,12 +1,13 @@
"""How entry points claim a checkout before they start a chunk in it, so that two never start the same chunk and do-epic never starts one where loop-claude runs.
An entry point holds `starting` on `project_lock` while it lists the windows of the checkout's chunks and starts new ones. It starts each chunk in a tmux window with CHUNK_FLAG, and hands that window the variables named with HANDED.
An entry point holds `starting` on `project_lock` while it lists the windows of the checkout's chunks and starts new ones. Where the lock cannot be taken, `starting` yields a Failure, and the entry point doesn't start any chunk. It starts each chunk in a tmux window with CHUNK_FLAG, and hands that window the variables named with HANDED.
"""
import contextlib
import fcntl
import pathlib
import typing
from failure import Failure
from transcript_archive.project_key import project_key
from agent_cycle import tmux
@@ -21,12 +22,28 @@ HANDED = "LOOP_CLAUDE_"
@contextlib.contextmanager
def starting(folder: pathlib.Path) -> typing.Iterator[None]:
"""Holds the LOCK in folder: project_lock's for a project, or do-epic's for an epic. Raises OSError where the file cannot be opened or locked."""
folder.mkdir(parents=True, exist_ok=True)
with open(folder / LOCK, "a") as lock:
fcntl.flock(lock, fcntl.LOCK_EX)
yield
def starting(folder: pathlib.Path) -> typing.Iterator[Failure | None]:
"""Holds the LOCK in folder: project_lock's for a project, or do-epic's for an epic. It yields a Failure, and doesn't hold any lock, where the file cannot be opened or locked."""
with locked(folder / LOCK) as failure:
yield failure
@contextlib.contextmanager
def locked(file: pathlib.Path) -> typing.Iterator[Failure | None]:
"""Holds a flock on file, which it makes with its folder. It yields a Failure, and doesn't hold any lock, where the file cannot be opened or locked."""
try:
file.parent.mkdir(parents=True, exist_ok=True)
lock = open(file, "a")
except OSError as failure:
yield Failure(f"cannot lock {failure.filename or file}: {failure.strerror}")
return
with lock:
try:
fcntl.flock(lock, fcntl.LOCK_EX)
except OSError as failure:
yield Failure(f"cannot lock {file}: {failure.strerror}")
return
yield None
def project_lock(root: str, home: pathlib.Path) -> pathlib.Path: