Answer architecture round 2: 0 🔴, 2 🟡; archive each verdict's judge rung, list the archive through transcript_archive alone, and say how the replay's retry differs from the loop's
This commit is contained in:
@@ -3,6 +3,8 @@ import re
|
||||
from markdown_text import quoted
|
||||
from utc_stamp import STAMPED
|
||||
|
||||
# What an outcomes file's name ends with, in place of its transcript copy's .jsonl.
|
||||
FILE_SUFFIX = ".outcomes.md"
|
||||
TASK = "Task: "
|
||||
FINISHED = "Verdict: finished"
|
||||
UNFINISHED = "Verdict: unfinished"
|
||||
@@ -19,22 +21,24 @@ VERDICT_AT = re.compile(rf"^{STAMPED} (?:{re.escape(FINISHED)}|{re.escape(UNFINI
|
||||
OUTCOME_AT = re.compile(rf"^({STAMPED}) ", re.MULTILINE)
|
||||
NAMES_A_WORKER = ("Verdict: finished\n", "Verdict: unfinished\n", "Stopped: ", "Stepped up\n")
|
||||
WORKER = "Worker: "
|
||||
# The rung that judged a verdict.
|
||||
JUDGE = "Judge: "
|
||||
|
||||
|
||||
def finished(worker: str, evidence: str) -> str:
|
||||
return f"{FINISHED}\n\nEvidence:\n{quoted(evidence)}\n\n{WORKER}{worker}"
|
||||
def finished(worker: str, evidence: str, judge: str) -> str:
|
||||
return f"{FINISHED}\n\nEvidence:\n{quoted(evidence)}\n\n{JUDGE}{judge}\n{WORKER}{worker}"
|
||||
|
||||
|
||||
def unfinished(worker: str, evidence: str) -> str:
|
||||
return f"{UNFINISHED}\n\nEvidence:\n{quoted(evidence)}\n\n{WORKER}{worker}"
|
||||
def unfinished(worker: str, evidence: str, judge: str) -> str:
|
||||
return f"{UNFINISHED}\n\nEvidence:\n{quoted(evidence)}\n\n{JUDGE}{judge}\n{WORKER}{worker}"
|
||||
|
||||
|
||||
def interrupted(question: str, evidence: str) -> str:
|
||||
return f"{INTERRUPTED}\n\n{question}\n\nEvidence:\n{quoted(evidence)}"
|
||||
def interrupted(question: str, evidence: str, judge: str) -> str:
|
||||
return f"{INTERRUPTED}\n\n{question}\n\nEvidence:\n{quoted(evidence)}\n\n{JUDGE}{judge}"
|
||||
|
||||
|
||||
def answered(question: str, sources: str, answer: str, evidence: str) -> str:
|
||||
return f"{ANSWERED}\n\n{question}\n\n{sources} says:\n{quoted(answer)}\n\nEvidence:\n{quoted(evidence)}"
|
||||
def answered(question: str, sources: str, answer: str, evidence: str, judge: str) -> str:
|
||||
return f"{ANSWERED}\n\n{question}\n\n{sources} says:\n{quoted(answer)}\n\nEvidence:\n{quoted(evidence)}\n\n{JUDGE}{judge}"
|
||||
|
||||
|
||||
def stepped_up(worker: str) -> str:
|
||||
|
||||
@@ -3,7 +3,7 @@ import pathlib
|
||||
|
||||
from transcript_archive.location import chunk_folder
|
||||
from failure import Failure
|
||||
from transcript_archive.outcomes import FINISHED_AT, workers
|
||||
from transcript_archive.outcomes import FILE_SUFFIX, FINISHED_AT, workers
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
@@ -19,7 +19,7 @@ def finished_chunks(project_archive: pathlib.Path) -> list[FinishedChunk] | Fail
|
||||
found = []
|
||||
try:
|
||||
for folder in sorted(path for path in project_archive.glob("*") if path.is_dir()):
|
||||
copies = sorted((stamps[-1], outcomes) for outcomes in folder.glob("*.outcomes.md") if (stamps := FINISHED_AT.findall(outcomes.read_text(encoding="utf-8"))))
|
||||
copies = sorted((stamps[-1], outcomes) for outcomes in chunk_outcomes(folder) if (stamps := FINISHED_AT.findall(outcomes.read_text(encoding="utf-8"))))
|
||||
if copies:
|
||||
finished, outcomes = copies[-1]
|
||||
found.append(FinishedChunk(folder.name, finished, transcript_of(outcomes), sorted(folder.glob("session/*/subagents/*.jsonl"))))
|
||||
@@ -31,14 +31,19 @@ def finished_chunks(project_archive: pathlib.Path) -> list[FinishedChunk] | Fail
|
||||
def archived_outcomes(root: pathlib.Path) -> list[tuple[str, pathlib.Path]] | Failure:
|
||||
"""Each outcomes file in the archive at root, with the key of the project it belongs to, sorted."""
|
||||
try:
|
||||
return sorted((str(path.parent.parent.relative_to(root)), path) for path in root.rglob("*.outcomes.md"))
|
||||
return sorted((str(path.parent.parent.relative_to(root)), path) for path in root.rglob(f"*{FILE_SUFFIX}"))
|
||||
except OSError as failure:
|
||||
return Failure(f"could not read the archive {root}: {failure}")
|
||||
|
||||
|
||||
def chunk_outcomes(folder: pathlib.Path) -> list[pathlib.Path]:
|
||||
"""The outcomes file of each transcript copy in a chunk's folder, sorted."""
|
||||
return sorted(folder.glob(f"*{FILE_SUFFIX}"))
|
||||
|
||||
|
||||
def transcript_of(outcomes: pathlib.Path) -> pathlib.Path:
|
||||
"""The transcript copy an outcomes file sits beside."""
|
||||
return outcomes.with_name(outcomes.name.removesuffix(".outcomes.md") + ".jsonl")
|
||||
return outcomes.with_name(outcomes.name.removesuffix(FILE_SUFFIX) + ".jsonl")
|
||||
|
||||
|
||||
def read_threads(chunk: FinishedChunk) -> list[bytes] | Failure:
|
||||
@@ -59,7 +64,7 @@ def latest_worker(project_archive: pathlib.Path, transcript: str) -> str | Failu
|
||||
folder = chunk_folder(project_archive, handle.read())
|
||||
if not folder.is_dir():
|
||||
return None
|
||||
files = sorted((path for path in folder.iterdir() if path.name.endswith(".outcomes.md")), key=lambda path: path.stat().st_mtime_ns, reverse=True)
|
||||
files = sorted((path for path in folder.iterdir() if path.name.endswith(FILE_SUFFIX)), key=lambda path: path.stat().st_mtime_ns, reverse=True)
|
||||
for path in files:
|
||||
if found := workers(path.read_text(encoding="utf-8")):
|
||||
return found[-1][1]
|
||||
|
||||
@@ -24,7 +24,7 @@ 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(write.archive(kept, str(transcript), "Do it.", outcomes.unfinished("m", "working"), NOW))
|
||||
self.assertIsNone(write.archive(kept, str(transcript), "Do it.", outcomes.unfinished("m", "working", "j"), NOW))
|
||||
(kept_outcomes,) = kept.glob("*/*.outcomes.md")
|
||||
kept_outcomes.unlink()
|
||||
self.assertIsNone(write.archive(kept, str(transcript), "Do it.", outcomes.stopped("m", "Ctrl-C"), NOW))
|
||||
@@ -45,14 +45,14 @@ class CopyFor(unittest.TestCase):
|
||||
|
||||
class Outcomes(unittest.TestCase):
|
||||
def test_the_archive_stamps_what_it_reads_back(self):
|
||||
self.assertRegex(f"{utc(NOW)} {outcomes.finished('m', 'merged')}", outcomes.FINISHED_AT)
|
||||
self.assertRegex(f"{utc(NOW)} {outcomes.finished('m', 'merged', 'j')}", outcomes.FINISHED_AT)
|
||||
|
||||
def test_reads_back_the_worker_of_each_outcome_that_closes_a_cycle(self):
|
||||
kept = "Task: Do it.\n\n" + "\n".join(f"{utc(NOW + offset)} {outcome}\n" for offset, outcome in enumerate([
|
||||
outcomes.unfinished("w1", "Worker: not this"),
|
||||
outcomes.interrupted("Which one?\nWorker: nor this", "e"),
|
||||
outcomes.unfinished("w1", "Worker: not this", "j"),
|
||||
outcomes.interrupted("Which one?\nWorker: nor this", "e", "j"),
|
||||
outcomes.stopped("w2", "the judge failed\nthree times"),
|
||||
outcomes.finished("w3", "merged"),
|
||||
outcomes.finished("w3", "merged", "j"),
|
||||
]))
|
||||
self.assertEqual(outcomes.workers(kept), [(utc(NOW), "w1"), (utc(NOW + 2), "w2"), (utc(NOW + 3), "w3")])
|
||||
|
||||
@@ -68,7 +68,7 @@ class Outcomes(unittest.TestCase):
|
||||
transcript.write_text('{"timestamp": "2026-10-03T00:00:00Z"}\n')
|
||||
with contextlib.redirect_stderr(io.StringIO()):
|
||||
for worker in ("z-first", "a-last"):
|
||||
self.assertIsNone(write.archive(kept, str(transcript), "Do it.", outcomes.unfinished(worker, "working"), NOW))
|
||||
self.assertIsNone(write.archive(kept, str(transcript), "Do it.", outcomes.unfinished(worker, "working", "j"), NOW))
|
||||
self.assertEqual(read.latest_worker(kept, str(transcript)), "a-last")
|
||||
|
||||
def test_names_the_worker_the_latest_outcome_of_the_transcripts_chunk_records(self):
|
||||
@@ -78,7 +78,7 @@ class Outcomes(unittest.TestCase):
|
||||
transcript.write_text('{"timestamp": "2026-10-03T00:00:00Z"}\n')
|
||||
self.assertIsNone(read.latest_worker(kept, str(transcript)))
|
||||
with contextlib.redirect_stderr(io.StringIO()):
|
||||
self.assertIsNone(write.archive(kept, str(transcript), "Do it.", outcomes.unfinished("w1", "working"), NOW))
|
||||
self.assertIsNone(write.archive(kept, str(transcript), "Do it.", outcomes.unfinished("w1", "working", "j"), NOW))
|
||||
transcript.write_text('{"timestamp": "2026-10-03T00:00:00Z"}\n{"more": 1}\n')
|
||||
self.assertIsNone(write.archive(kept, str(transcript), "Do it.", outcomes.stopped("w2", "Ctrl-C"), NOW + 1))
|
||||
self.assertEqual(read.latest_worker(kept, str(transcript)), "w2")
|
||||
|
||||
@@ -5,9 +5,9 @@ import sys
|
||||
|
||||
from transcript_archive.location import chunk_folder
|
||||
from failure import Failure
|
||||
from transcript_archive.outcomes import FILE_SUFFIX, TASK
|
||||
from file_writes import make_private, replace_file
|
||||
from claude_code.session import session_files
|
||||
from transcript_archive.outcomes import TASK
|
||||
from utc_stamp import utc
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ def archive(project_archive: pathlib.Path, path: str, task: str, outcome: str, a
|
||||
if sibling != path and (unkept := mirror(pathlib.Path(sibling), folder / "session" / os.path.basename(sibling))):
|
||||
return unkept
|
||||
copy = folder / f"{hashlib.sha256(raw).hexdigest()}.jsonl"
|
||||
outcomes = copy.with_suffix(".outcomes.md")
|
||||
outcomes = copy.with_suffix(FILE_SUFFIX)
|
||||
stamped = f"{utc(at)} {outcome}"
|
||||
if copy.exists() and outcomes.exists():
|
||||
return add_outcome(outcomes, stamped)
|
||||
|
||||
Reference in New Issue
Block a user