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
+9 -8
View File
@@ -5,10 +5,11 @@ import json
import pathlib
import re
import subprocess
import sys
import time
import typing
from loop_effects.effects import Effects
from failure import Failure
# The type of the first line of a run's file, which holds what the stream lacks: claude's arguments, working directory, prompt, exit code and stderr. No event claude writes has this type.
HEADER = "replay_run"
@@ -21,8 +22,8 @@ def replay_folder(root: pathlib.Path, tool: str, argv: list[str], now: float) ->
return root / "replays" / re.sub(r"[^A-Za-z0-9._-]", "_", name)
def archiving(effects: Effects, folder: pathlib.Path) -> Effects:
"""effects whose claude also writes each run into folder: a header line, then the stream claude printed. A run is kept whether it failed or not, and a run that repeats another word for word is kept once. A folder that can't be written is reported on stderr, and the replay goes on."""
def archiving(effects: Effects, folder: pathlib.Path, say: typing.Callable[[str], None]) -> Effects:
"""effects whose claude also writes each run into folder: a header line, then the stream claude printed. A run is kept whether it failed or not, and a run that repeats another word for word is kept once. A folder that can't be written is reported to say, and the replay goes on."""
claude = effects.claude
def run(args: list[str], cwd: str, prompt: str) -> subprocess.CompletedProcess[str]:
@@ -32,17 +33,17 @@ def archiving(effects: Effects, folder: pathlib.Path) -> Effects:
folder.mkdir(mode=0o700, parents=True, exist_ok=True)
(folder / f"{hashlib.sha256(content.encode()).hexdigest()}.jsonl").write_text(content, encoding="utf-8")
except OSError as failure:
print(f"could not keep the run in {folder}: {failure}", file=sys.stderr, flush=True)
say(f"could not keep the run in {folder}: {failure}")
return proc
return dataclasses.replace(effects, claude=run)
def print_report(folder: pathlib.Path, report: str) -> None:
"""Prints the report a replay ends with, and keeps it in folder, beside the runs."""
print(report)
def kept_report(folder: pathlib.Path, report: str) -> Failure | None:
"""Keeps the report a replay ends with in folder, beside the runs; the Failure where it can't."""
try:
folder.mkdir(mode=0o700, parents=True, exist_ok=True)
(folder / RESULT).write_text(report + "\n", encoding="utf-8")
except OSError as failure:
print(f"could not keep the result in {folder}: {failure}", file=sys.stderr, flush=True)
return Failure(f"could not keep the result in {folder}: {failure}")
return None