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
+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>.