diff --git a/CHANGELOG.md b/CHANGELOG.md index 47648c7b..6f997fe4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,6 @@ - `loop-claude` retries a failed worker within its cycle. - `loop-claude` counts an interrupt reply starting with `<` as typed. - `loop-claude`'s judge sees a reply the human types while claude works, and an interrupt counts one as typed. -- `loop-claude` archives the raw `.jsonl` transcript at every interrupt and as every cycle ends, Ctrl-C and a failure included: one copy per distinct transcript, named by its SHA-256, with the verdict or the stop beside it in `.verdict.md`, and the session folder's files, the subagents' transcripts among them, in `/` beside them; a transcript it cannot archive exits 1. +- `loop-claude` archives the raw `.jsonl` transcript at every interrupt and as every cycle ends, Ctrl-C and failures included. Each distinct transcript is kept once, named by its SHA-256, with `.verdict.md` beside it holding the verdict or why the loop stopped. The subagents' transcripts and the session's other files go in `/` beside them. `loop-claude` exits 1 when it cannot archive. - `loop-claude` exits 1 when it cannot delete a finished chunk's session, naming what to delete before rerunning; the next chunk would otherwise resume it. - `loop-claude` keeps the mode of `~/.claude.json` and of its models file when it rewrites them, and creates the models file 0600. diff --git a/bin/loop_claude/cycle/archive.py b/bin/loop_claude/cycle/archive.py index 695c504b..d5925ee1 100644 --- a/bin/loop_claude/cycle/archive.py +++ b/bin/loop_claude/cycle/archive.py @@ -47,7 +47,7 @@ def mirror(source: pathlib.Path, dest: pathlib.Path) -> Failure | None: return None -# Every chunk of a project reuses its session id, so a name can recur with other content: only a file that grew from its copy replaces it. +# Every chunk of a project reuses its session id, so an earlier chunk's file can share a name with this one's. def copy_for(copy: pathlib.Path, data: bytes) -> pathlib.Path | None: if not copy.is_file(): return copy diff --git a/bin/loop_claude/cycle/run.py b/bin/loop_claude/cycle/run.py index 074e4ec6..9acfa3cb 100644 --- a/bin/loop_claude/cycle/run.py +++ b/bin/loop_claude/cycle/run.py @@ -45,7 +45,7 @@ def run_cycle(cycle: Cycle) -> Stop | None: def stopped(cycle: Cycle, stop: Stop) -> Stop: path = transcript_file(cycle.session) failure = archive(cycle.project_key, path, f"Task: {cycle.task}\n\nStopped: {'Ctrl-C' if stop.code == 130 else stop.reason}", cycle.paths) if path else None - # A stop for a failed archive has just failed the same way again. + # When the stop is itself a failed archive, archiving again fails the same way: say it once. return Stop(1, f"{failure.reason}\n{stop.reason}".rstrip()) if failure and failure.reason != stop.reason else stop @@ -80,7 +80,7 @@ def rule(cycle: Cycle, transcript_path: str) -> Ruled | Stop: def ask(cycle: Cycle, transcript_path: str, question: str) -> Answered | Stop: - # Archived before the interrupt appends to the transcript, so the copy carries the question beside it. + # Archived now, so the transcript the question was asked on is kept with it; the interrupt appends the answer. if failure := archive(cycle.project_key, transcript_path, f"Task: {cycle.task}\n\nVerdict: interrupt\n\n{question}", 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 Answered() diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index 740b5113..a6f64f57 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -14,10 +14,11 @@ Each project has one session, named "A loop-claude", where is the ch relative to ~/code, or to / outside it. The session is deleted when its chunk finishes. At every interrupt, and as every cycle ends, Ctrl-C and a failure included, the session's transcript is copied to $LOOP_CLAUDE_TRANSCRIPTS//.jsonl (default ~/.claude/loop-claude-transcripts), -the verdict or the stop beside it in .verdict.md, and the files of its session folder, the -subagents' transcripts among them, to //; a file that does not extend its earlier -copy, such as one an earlier chunk left, lands beside it as ., and keeps the -first copy. +named by its hash. Beside it, .verdict.md holds the verdict, or why the loop stopped. +Claude Code keeps a folder per session beside its transcript, holding the subagents' transcripts +among other files; those files are copied to //. A file there is replaced only by +a version that grew from it. A file with other content under the same name, such as one an earlier +chunk left, lands beside it as .. Every claude loop-claude starts runs the project's model, saved per in ~/.claude/loop-claude-models.json and read each cycle; a project without an entry, as on its first diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index ca07529e..05a9fcbe 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -157,7 +157,7 @@ class Cycles(unittest.TestCase): self.assertEqual(self.archived_verdicts(), ["Task: Do it.\n\nVerdict: finished\n"]) self.assertIsNone(session.transcript_file(self.session)) - def test_an_unfinished_chunk_is_archived_and_keeps_its_session_and_the_next_cycle_resumes_it(self): + def test_an_unfinished_chunks_transcript_is_archived_and_the_next_cycle_resumes_its_session(self): fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)] * 2, claude=[judged("unfinished")] * 2) self.assertIsNone(run.run_cycle(self.cycle(fake))) self.assertTrue(session.transcript_file(self.session)) @@ -167,7 +167,7 @@ class Cycles(unittest.TestCase): self.assertIn("--resume", workers[1]) self.assertEqual(self.archived_verdicts(), ["Task: Do it.\n\nVerdict: unfinished\n"] * 2) - def test_a_stopped_or_interrupted_cycle_archives_what_its_session_holds(self): + 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()]) diff --git a/todo.md b/todo.md index 0d753c45..c424e35a 100644 --- a/todo.md +++ b/todo.md @@ -58,4 +58,6 @@ - **Clean up the rules, skills, agents, plan and decision log.** Goal 4.1. - `docs/decisions.md`: order the entries and the `AGENTS.md` index by one key. - `docs/decisions.md`: give the comprehension-floor and vocabulary entries a premise that has not expired. Both say "Valid until the next scoring run", and every run since has passed it. Put the floor's rule first and its runs' scores in a table. + - `docs/decisions.md`: have "the archive keeps the raw transcript" cover the session-folder copy, which keeps files by name and replaces one only with a version that grew from it. + - `session.py`: say in `delete_session`'s comment that the `.superseded-*` and `.orphaned-*` names come from older Claude Code versions. - `systems-architect.md`: cut the "one home" line, and break Reasonability Review's steps 4 and 5 into shorter points each.