Archive each verdict's evidence, and stamp each outcome with its UTC time

This commit is contained in:
2026-10-03 20:44:36 +02:00
parent 8e1cd07402
commit 69ffd6c1a1
7 changed files with 28 additions and 33 deletions
+1
View File
@@ -2,6 +2,7 @@
## Unreleased
- `loop-claude`'s `<sha256>.outcomes.md` gives each verdict the transcript passage the judge rested it on, and stamps each outcome with its UTC time.
- larv-review keeps its three-round cap across a resumed session. It closes each review round with a commit naming the pass and the round, empty when the round changed nothing, and counts rounds from the branch's own commits.
- larv-review runs `/security-review` in a subagent, so the run goes on to the next pass without you prompting it.
- larv-review asks once before the full security scan: it states the evidence and its recommendation, and `claude-security`'s cost prompt is the ask.
+5 -3
View File
@@ -2,6 +2,7 @@ import hashlib
import os
import pathlib
import sys
import time
from failure import Failure
from loop_claude.claude_code.transcript import first_timestamped_line
@@ -10,7 +11,7 @@ from loop_claude.paths import Paths
from loop_claude.claude_code.session import session_files
def archive(project_key: str, path: str, task: str, outcome: str, paths: Paths) -> Failure | None:
def archive(project_key: str, path: str, task: str, outcome: str, at: float, paths: Paths) -> Failure | None:
try:
with open(path, "rb") as handle:
raw = handle.read()
@@ -24,10 +25,11 @@ def archive(project_key: str, path: str, task: str, outcome: str, paths: Paths)
return unkept
copy = folder / f"{hashlib.sha256(raw).hexdigest()}.jsonl"
outcomes = copy.with_suffix(".outcomes.md")
stamped = f"{time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime(at))} {outcome}"
if copy.exists() and outcomes.exists():
return add_outcome(outcomes, outcome)
return add_outcome(outcomes, stamped)
# The copy lands last, so a copy on disk always has its outcomes and its session's files beside it.
for dest, data in ((outcomes, f"Task: {task}\n\n{outcome}\n".encode()), (copy, raw)):
for dest, data in ((outcomes, f"Task: {task}\n\n{stamped}\n".encode()), (copy, raw)):
if unwritten := replace_file(dest, data):
return unarchived(dest, unwritten.reason)
print(f"transcript: {copy}", file=sys.stderr)
+3 -3
View File
@@ -46,7 +46,7 @@ def run_cycle(cycle: Cycle) -> Stop | None:
def stopped(cycle: Cycle, stop: Stop, why: str) -> Stop:
path = transcript_file(cycle.session)
failure = archive(cycle.project_key, path, cycle.task, f"Stopped: {why}", cycle.paths) if path else None
failure = archive(cycle.project_key, path, cycle.task, f"Stopped: {why}", cycle.effects.now(), cycle.paths) if path else None
# A failed archive exits 1 whatever the stop; when the stop was this archive failing, its reason is said once.
return Stop(1, f"{failure.reason}\n{stop.reason}".rstrip()) if failure and failure.reason != stop.reason else stop
@@ -86,7 +86,7 @@ def rule(cycle: Cycle, transcript_path: str) -> Ruled | Stop:
def ask(cycle: Cycle, transcript_path: str, ruling: Interrupt | QuotedAnswer) -> HumanAnswered | Stop:
question = question_for(ruling)
# Archived now, so the transcript the question was asked on is kept with it; the human's answer then grows the transcript.
if failure := archive(cycle.project_key, transcript_path, cycle.task, f"Verdict: interrupt\n\n{question}", cycle.paths):
if failure := archive(cycle.project_key, transcript_path, cycle.task, f"Verdict: interrupt\n\n{question}\n\nEvidence:\n{ruling.evidence}", cycle.effects.now(), cycle.paths):
return Stop(1, failure.reason)
return interrupt(cycle.root, cycle.session.id, cycle.models.worker, transcript_path, question, cycle.paths, cycle.effects) or HumanAnswered()
@@ -99,7 +99,7 @@ def question_for(ruling: Interrupt | QuotedAnswer) -> str:
def close(cycle: Cycle, transcript_path: str, verdict: Finished | Unfinished) -> Archived | Stop:
finished = isinstance(verdict, Finished)
if failure := archive(cycle.project_key, transcript_path, cycle.task, f"Verdict: {'finished' if finished else 'unfinished'}", cycle.paths):
if failure := archive(cycle.project_key, transcript_path, cycle.task, f"Verdict: {'finished' if finished else 'unfinished'}\n\nEvidence:\n{verdict.evidence}", cycle.effects.now(), cycle.paths):
return Stop(1, failure.reason)
if finished and (failure := delete_session(cycle.session)):
return Stop(1, failure.reason)
+4 -3
View File
@@ -22,9 +22,10 @@ interrupt, and as every cycle ends, Ctrl-C and a failure included, the session's
copied to $LOOP_CLAUDE_TRANSCRIPTS/<key>/<chunk>/<sha256>.jsonl (default
~/.claude/loop-claude-transcripts), named by its hash. <chunk> is the hash of the transcript's first
line with a timestamp, the same for every cycle of a chunk. Beside the copy, <sha256>.outcomes.md
holds the verdict, and why the loop stopped. Claude Code keeps a folder per session beside its
transcript, holding the subagents' transcripts among other files; that folder, and every other file
named after the session except the transcript, are copied into <chunk>/session/. A file there is
holds the verdict with the transcript passage the judge rested it on, and why the loop stopped, each
after its UTC time. Claude Code keeps a folder per session beside its transcript, holding the
subagents' transcripts among other files; that folder, and every other file named after the session
except the transcript, are copied into <chunk>/session/. A file there is
replaced only by a version that grew from it. A file Claude Code rewrote lands beside its copy as
<name>.<hash of its content>.
+8 -8
View File
@@ -179,7 +179,7 @@ class Cycles(unittest.TestCase):
def test_a_finished_chunk_is_archived_and_its_session_deleted(self):
fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[judged("finished")])
self.assertIsNone(run.run_cycle(self.cycle(fake)))
self.assertEqual(self.archived_outcomes(), ["Task: Do it.\n\nVerdict: finished\n"])
self.assertEqual(self.archived_outcomes(), ["Task: Do it.\n\n2026-09-21T14:13:20Z Verdict: finished\n\nEvidence:\nworking\n"])
self.assertIsNone(session.transcript_file(self.session))
def test_an_unfinished_chunks_transcript_is_archived_and_the_next_cycle_resumes_its_session(self):
@@ -190,14 +190,14 @@ class Cycles(unittest.TestCase):
workers = fake.made("stream_claude")
self.assertIn("--session-id", workers[0])
self.assertIn("--resume", workers[1])
self.assertEqual(self.archived_outcomes(), ["Task: Do it.\n\nVerdict: unfinished\n"] * 2)
self.assertEqual(self.archived_outcomes(), ["Task: Do it.\n\n2026-09-21T14:13:20Z Verdict: unfinished\n\nEvidence:\nworking\n"] * 2)
def test_a_cycle_stopped_by_a_failure_or_ctrl_c_archives_what_its_session_holds(self):
fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[ran(code=1)] * 3)
self.assertEqual(run.run_cycle(self.cycle(fake)).code, 1)
fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[KeyboardInterrupt()])
self.assertEqual(run.run_cycle(self.cycle(fake)), Stop(130, ""))
self.assertEqual(self.archived_outcomes(), ["Task: Do it.\n\nStopped: Ctrl-C\n", "Task: Do it.\n\nStopped: the judge failed three times running: the judge exited 1\n"])
self.assertEqual(self.archived_outcomes(), ["Task: Do it.\n\n2026-09-21T14:13:20Z Stopped: Ctrl-C\n", "Task: Do it.\n\n2026-09-21T14:13:20Z Stopped: the judge failed three times running: the judge exited 1\n"])
def test_archives_each_chunks_session_folder_replacing_a_copy_only_with_what_grew_from_it(self):
folder = self.paths.claude_code_transcripts / "-fake" / str(self.session.id)
@@ -243,7 +243,7 @@ class Cycles(unittest.TestCase):
return 0
fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[judged("interrupt"), judged("unfinished")], on_terminal_claude=[answer], git=[ran()])
self.assertIsNone(run.run_cycle(self.cycle(fake)))
self.assertEqual(self.archived_outcomes(), ["Task: Do it.\n\nVerdict: interrupt\n\nWhich one?\n", "Task: Do it.\n\nVerdict: unfinished\n"])
self.assertEqual(self.archived_outcomes(), ["Task: Do it.\n\n2026-09-21T14:13:20Z Verdict: interrupt\n\nWhich one?\n\nEvidence:\nworking\n", "Task: Do it.\n\n2026-09-21T14:13:20Z Verdict: unfinished\n\nEvidence:\nworking\n"])
self.assertIn(str(self.session.id), fake.made("claude_on_terminal")[0])
prompts = [stdin for args, stdin in fake.made("claude")]
self.assertEqual(len(prompts), 2)
@@ -279,7 +279,7 @@ class Cycles(unittest.TestCase):
stop = run.run_cycle(self.cycle(fake))
self.assertEqual(stop, Stop(1, f"could not delete {folder}: Permission denied; delete every file and folder matching {folder}*, then rerun loop-claude; a rerun before that resumes the finished chunk's session"))
self.assertTrue(session.session_open(self.session))
self.assertEqual(self.archived_outcomes(), [f"Task: Do it.\n\nVerdict: finished\n\nStopped: {stop.reason}\n"])
self.assertEqual(self.archived_outcomes(), [f"Task: Do it.\n\n2026-09-21T14:13:20Z Verdict: finished\n\nEvidence:\nworking\n\n2026-09-21T14:13:20Z Stopped: {stop.reason}\n"])
def test_stops_when_the_worker_leaves_no_transcript(self):
fake = FakeEffects(streams=[Streamed(0)])
@@ -423,11 +423,11 @@ class Archive(unittest.TestCase):
transcript = pathlib.Path(root, "t.jsonl")
transcript.write_text('{"timestamp": "2026-10-03T00:00:00Z"}\n')
with contextlib.redirect_stderr(io.StringIO()):
self.assertIsNone(archive.archive("proj", str(transcript), "Do it.", "Verdict: unfinished", kept))
self.assertIsNone(archive.archive("proj", str(transcript), "Do it.", "Verdict: unfinished", NOW, kept))
(outcomes,) = kept.transcript_archive.glob("proj/*/*.outcomes.md")
outcomes.unlink()
self.assertIsNone(archive.archive("proj", str(transcript), "Do it.", "Stopped: Ctrl-C", kept))
self.assertEqual(outcomes.read_text(), "Task: Do it.\n\nStopped: Ctrl-C\n")
self.assertIsNone(archive.archive("proj", str(transcript), "Do it.", "Stopped: Ctrl-C", NOW, kept))
self.assertEqual(outcomes.read_text(), "Task: Do it.\n\n2026-09-21T14:13:20Z Stopped: Ctrl-C\n")
class CopyFor(unittest.TestCase):
+7 -6
View File
@@ -5,6 +5,7 @@ import json
import os
import pathlib
import pty
import re
import select
import shutil
import stat
@@ -250,7 +251,7 @@ class Checkout:
return pathlib.Path(self.env.get("LOOP_CLAUDE_TRANSCRIPTS", self.home / ".claude" / "loop-claude-transcripts"))
def archived(self):
"""Each archived transcript's outcomes, after checking the copy is named by its content hash."""
"""Each archived transcript's outcomes, each UTC stamp read as <UTC>, after checking the copy is named by its content hash."""
outcomes = {}
for folder in (self.archive(), self.archive() / "proj", *(self.archive() / "proj").iterdir()):
self.test.assertEqual(stat.S_IMODE(folder.stat().st_mode), 0o700, folder)
@@ -259,7 +260,7 @@ class Checkout:
kept = copy.with_suffix(".outcomes.md")
for archived in (copy, kept):
self.test.assertEqual(stat.S_IMODE(archived.stat().st_mode), 0o600)
outcomes[copy.read_text()] = kept.read_text()
outcomes[copy.read_text()] = re.sub(r"^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ ", "<UTC> ", kept.read_text(), flags=re.MULTILINE)
return outcomes
@@ -351,9 +352,9 @@ class Cycles(unittest.TestCase):
self.assertEqual([path.name for path in checkout.transcripts()[0].parent.iterdir()], [checkout.transcripts()[0].name])
self.assertIn("=== cycle 3 ===", run.stdout)
copies = {verdict.removeprefix(f"Task: {TASK}\n\n"): copy for copy, verdict in checkout.archived().items()}
self.assertEqual(sorted(copies), ["Stopped: Ctrl-C\n", "Verdict: finished\n", "Verdict: unfinished\n"])
self.assertIn('"text": "landed-it"', copies["Verdict: finished\n"])
self.assertIn('"text": "next chunk"', copies["Stopped: Ctrl-C\n"])
self.assertEqual(sorted(copies), ["<UTC> Stopped: Ctrl-C\n", "<UTC> Verdict: finished\n\nEvidence:\nlanded-it\n", "<UTC> Verdict: unfinished\n\nEvidence:\nstarted\n"])
self.assertIn('"text": "landed-it"', copies["<UTC> Verdict: finished\n\nEvidence:\nlanded-it\n"])
self.assertIn('"text": "next chunk"', copies["<UTC> Stopped: Ctrl-C\n"])
self.assertEqual(len(list(checkout.archive().glob(f"proj/*/session/{session}.orphaned-1-ab.jsonl"))), 1)
def test_exits_1_when_the_transcript_cannot_be_archived_and_resumes_on_the_next_run(self):
@@ -478,7 +479,7 @@ class Interrupt(unittest.TestCase):
self.assertEqual(run.stderr.strip().splitlines()[-2:], ["A or B?", "the human is needed to answer the question above, but stdin or stdout is not a terminal; rerun loop-claude on a terminal"])
[(copy, verdict)] = checkout.archived().items()
self.assertEqual(copy, (checkout.transcripts()[0]).read_text())
self.assertEqual(verdict, f"Task: {TASK}\n\nVerdict: interrupt\n\nA or B?\n\nStopped: the human is needed to answer the question above, but stdin or stdout is not a terminal; rerun loop-claude on a terminal\n")
self.assertEqual(verdict, f"Task: {TASK}\n\n<UTC> Verdict: interrupt\n\nA or B?\n\nEvidence:\nShall I use A or B?\n\n<UTC> Stopped: the human is needed to answer the question above, but stdin or stdout is not a terminal; rerun loop-claude on a terminal\n")
self.assertEqual(stat.S_IMODE((checkout.temp / "deep").stat().st_mode), 0o700)
self.assertIn(f"transcript: {checkout.archive() / 'proj'}/", run.stderr)
session = argument(run.calls[0], "--session-id")
-10
View File
@@ -25,12 +25,10 @@
| ID | Release | Exempt | Item | R | S | A | G | Goals | Score |
|---|---|---|---|---|---|---|---|---|---|
| 1 | 0.1.0 | question | **Say in README → Install how the transcript archive is backed up, once bender-infra backs up ai-sandbox's data volume.** | 3 | 5 | 8 | 9 | 2, 3 | 27.8 |
| 47 | 0.1.0 | | **Archive the judge's evidence with each verdict, so a wrong finish shows what it rested on.** | 1 | 1 | 6 | 6 | 2, 4 | 21.4 |
| 56 | 0.1.0 | | **Have the judge rule a chunk finished only once every answer the human typed in it is recorded in `README.md`, `AGENTS.md` or `docs/decisions.md`.** | 3 | 3 | 7 | 8 | 4, 4.2 | 21.0 |
| 46 | 0.1.0 | decision | **Let the judge read and quote `~/.claude/CLAUDE.md` whole, beside the project's records.** | 4 | 3 | 7 | 8 | 4, 4.2 | 20.0 |
| 54 | 0.1.0 | | **Give each review pass a fixed name in larv-review §3's table, and count its rounds by that name.** | 2 | 1 | 6 | 6 | 4, 4.1 | 17.8 |
| 55 | 0.1.0 | | **Make larv-review's comprehension floor readable without opening the panel skill, its scoring-run file and `AGENTS.md` in turn.** | 2 | 3 | 5 | 6 | 4, 4.1 | 15.3 |
| 48 | 0.1.0 | | **Stamp each archived outcome with its UTC time.** | 1 | 1 | 4 | 4 | 2 | 13.9 |
| 23 | 0.1.0 | | **Launch a principles auditor only for a principles file the project shows applies, and rerun only the reviewer whose finding a fix answers.** | 3 | 4 | 7 | 8 | 4.4 | 13.5 |
| 21 | 0.1.0 | | **Give `settings.json`'s model one writer, and sort its keys.** | 3 | 3 | 6 | 7 | 4.3 | 12.9 |
| 49 | 0.1.0 | principle | **Check that `AGENTS.md` lists exactly the titles of `docs/decisions.md`.** | 1 | 2 | 5 | 6 | 4.3 | 12.5 |
@@ -54,10 +52,6 @@ It lives under `~/.claude`, which `.gitignore` keeps from the remote, so a lost
The README line covers the bench's transcripts in `workflow-bench/logs/` too (goal 2).
### 47. Archive the judge's evidence with each verdict, so a wrong finish shows what it rested on.
The judge runs without session persistence, and `close` and `ask` archive only the verdict and the question. A wrong `finished` deletes the session, and nothing then shows the passage the judge quoted.
### 56. Have the judge rule a chunk finished only once every answer the human typed in it is recorded in `README.md`, `AGENTS.md` or `docs/decisions.md`.
2026-10-03, the human, answering the principles audit on PR #208: a finished chunk's session is deleted, and its `[human]` answers with it, so an answer recorded nowhere is asked again in a later chunk (goal 4.2).
@@ -74,10 +68,6 @@ Named under Shape by the PR #208 scoring runs: "Count" keys on `Answer <pass> ro
Named under Self-sufficiency by the PR #208 scoring runs, as the worst of the skills' leans on other documents.
### 48. Stamp each archived outcome with its UTC time.
After an overnight exit 1, `<sha>.outcomes.md` holds each outcome without saying when it happened.
### 23. Launch a principles auditor only for a principles file the project shows applies, and rerun only the reviewer whose finding a fix answers.
On this repo the frontend, REST and logging auditors each read the whole project to report "does not apply", and one 🟢 fix reruns ten whole-project reads.