Answer the stability and product-owner reviews' first round
This commit is contained in:
+1
-1
@@ -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 `<sha256>.verdict.md`, and the session folder's files, the subagents' transcripts among them, in `<session id>/`; 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 a failure included: one copy per distinct transcript, named by its SHA-256, with the verdict or the stop beside it in `<sha256>.verdict.md`, and the session folder's files, the subagents' transcripts among them, in `<session id>/` beside them; a transcript it cannot archive exits 1.
|
||||
- `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.
|
||||
|
||||
@@ -30,15 +30,14 @@ def archive(project_key: str, path: str, note: str, paths: Paths) -> Failure | N
|
||||
return None
|
||||
|
||||
|
||||
# Claude Code only appends to a session folder's files, so overwriting a copy loses nothing.
|
||||
def mirror(source: pathlib.Path, dest: pathlib.Path) -> Failure | None:
|
||||
for file in sorted(source.rglob("*")):
|
||||
copy = dest / file.relative_to(source)
|
||||
try:
|
||||
if not file.is_file():
|
||||
continue
|
||||
data = file.read_bytes()
|
||||
if copy.is_file() and copy.read_bytes() == data:
|
||||
copy = copy_for(dest / file.relative_to(source), data)
|
||||
if copy is None:
|
||||
continue
|
||||
make_private(copy.parent)
|
||||
except OSError as failure:
|
||||
@@ -46,3 +45,14 @@ def mirror(source: pathlib.Path, dest: pathlib.Path) -> Failure | None:
|
||||
if unwritten := replace_file(copy, data):
|
||||
return Failure(f"could not archive the transcript: {copy}: {unwritten.reason}")
|
||||
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.
|
||||
def copy_for(copy: pathlib.Path, data: bytes) -> pathlib.Path | None:
|
||||
if not copy.is_file():
|
||||
return copy
|
||||
kept = copy.read_bytes()
|
||||
if data.startswith(kept):
|
||||
return copy if data != kept else None
|
||||
beside = copy.with_name(f"{copy.name}.{hashlib.sha256(data).hexdigest()}")
|
||||
return None if beside.exists() else beside
|
||||
|
||||
@@ -7,7 +7,7 @@ from loop_claude.cycle.archive import archive
|
||||
from loop_claude.cycle.interrupt import interrupt
|
||||
from loop_claude.cycle.judge import judge
|
||||
from loop_claude.cycle.retry import retried
|
||||
from loop_claude.cycle.states import Active, Answered, Archived, Ended, Event, Finishing, Interrupting, Judging, Ruled, State, WorkerRan, Working, transition
|
||||
from loop_claude.cycle.states import Active, Answered, Archived, Closing, Ended, Event, Interrupting, Judging, Ruled, State, WorkerRan, Working, transition
|
||||
from loop_claude.cycle.verdicts import Finished, Unfinished
|
||||
from loop_claude.cycle.worker import run_worker, worker_args
|
||||
from loop_claude.effects import Effects
|
||||
@@ -57,7 +57,7 @@ def step(cycle: Cycle, state: Active) -> Event | Stop:
|
||||
return rule(cycle, transcript_path)
|
||||
case Interrupting(transcript_path, question):
|
||||
return ask(cycle, transcript_path, question)
|
||||
case Finishing(transcript_path, verdict):
|
||||
case Closing(transcript_path, verdict):
|
||||
return close(cycle, transcript_path, verdict)
|
||||
case _:
|
||||
typing.assert_never(state)
|
||||
|
||||
@@ -20,7 +20,7 @@ class Interrupting:
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class Finishing:
|
||||
class Closing:
|
||||
transcript_path: str
|
||||
verdict: Finished | Unfinished
|
||||
|
||||
@@ -30,7 +30,7 @@ class Ended:
|
||||
"""The cycle is over."""
|
||||
|
||||
|
||||
Active = Working | Judging | Interrupting | Finishing
|
||||
Active = Working | Judging | Interrupting | Closing
|
||||
State = Active | Ended
|
||||
|
||||
|
||||
@@ -64,10 +64,10 @@ def transition(state: State, event: Event) -> State:
|
||||
case Judging(transcript_path), Ruled(Interrupt(question=question)):
|
||||
return Interrupting(transcript_path, question)
|
||||
case Judging(transcript_path), Ruled(Finished() | Unfinished() as verdict):
|
||||
return Finishing(transcript_path, verdict)
|
||||
return Closing(transcript_path, verdict)
|
||||
# The human works in the interrupt's claude session, so the judge rules again on the transcript it leaves.
|
||||
case Interrupting(transcript_path), Answered():
|
||||
return Judging(transcript_path)
|
||||
case Finishing(), Archived():
|
||||
case Closing(), Archived():
|
||||
return Ended()
|
||||
raise ValueError(f"no transition from {state} on {event}")
|
||||
|
||||
@@ -15,7 +15,8 @@ relative to ~/code, or to / outside it. The session is deleted when its chunk fi
|
||||
interrupt, and as every cycle ends, Ctrl-C and a failure included, the session's transcript is
|
||||
copied to $LOOP_CLAUDE_TRANSCRIPTS/<key>/<sha256>.jsonl (default ~/.claude/loop-claude-transcripts),
|
||||
the verdict or the stop beside it in <sha256>.verdict.md, and the files of its session folder, the
|
||||
subagents' transcripts among them, to <key>/<session id>/.
|
||||
subagents' transcripts among them, to <key>/<session id>/; a file that does not extend its earlier
|
||||
copy, such as one an earlier chunk left, lands beside it as <name>.<sha256>.
|
||||
|
||||
Every claude loop-claude starts runs the project's model, saved per <key> in
|
||||
~/.claude/loop-claude-models.json and read each cycle; a project without an entry, as on its first
|
||||
|
||||
+11
-6
@@ -120,15 +120,15 @@ class Transitions(unittest.TestCase):
|
||||
legal = (
|
||||
(states.Working(), states.WorkerRan("/t"), states.Judging("/t")),
|
||||
(states.Judging("/t"), states.Ruled(Interrupt("e", "Which one?")), states.Interrupting("/t", "Which one?")),
|
||||
(states.Judging("/t"), states.Ruled(Finished("e")), states.Finishing("/t", Finished("e"))),
|
||||
(states.Judging("/t"), states.Ruled(Unfinished("e")), states.Finishing("/t", Unfinished("e"))),
|
||||
(states.Judging("/t"), states.Ruled(Finished("e")), states.Closing("/t", Finished("e"))),
|
||||
(states.Judging("/t"), states.Ruled(Unfinished("e")), states.Closing("/t", Unfinished("e"))),
|
||||
(states.Interrupting("/t", "q"), states.Answered(), states.Judging("/t")),
|
||||
(states.Finishing("/t", Finished("e")), states.Archived(), states.Ended()),
|
||||
(states.Closing("/t", Finished("e")), states.Archived(), states.Ended()),
|
||||
)
|
||||
for state, event, after in legal:
|
||||
with self.subTest(state=state, event=event):
|
||||
self.assertEqual(states.transition(state, event), after)
|
||||
every_state = (states.Working(), states.Judging("/t"), states.Interrupting("/t", "q"), states.Finishing("/t", Finished("e")), states.Ended())
|
||||
every_state = (states.Working(), states.Judging("/t"), states.Interrupting("/t", "q"), states.Closing("/t", Finished("e")), states.Ended())
|
||||
every_event = (states.WorkerRan("/t"), states.Ruled(Interrupt("e", "Which one?")), states.Ruled(Finished("e")), states.Ruled(Unfinished("e")), states.Answered(), states.Archived())
|
||||
for state in every_state:
|
||||
for event in every_event:
|
||||
@@ -174,13 +174,14 @@ class Cycles(unittest.TestCase):
|
||||
self.assertEqual(run.run_cycle(self.cycle(fake)), Stop(130, ""))
|
||||
self.assertEqual(self.archived_verdicts(), ["Task: Do it.\n\nStopped: Ctrl-C\n", "Task: Do it.\n\nStopped: the judge failed three times running: the judge exited 1\n"])
|
||||
|
||||
def test_archives_the_session_folder_and_overwrites_only_a_changed_copy(self):
|
||||
def test_archives_the_session_folder_replacing_a_copy_only_with_what_grew_from_it(self):
|
||||
folder = self.paths.claude_code_transcripts / "-fake" / str(self.session.id)
|
||||
(folder / "subagents" / "workflows").mkdir(parents=True)
|
||||
(folder / "subagents" / "agent-a.jsonl").write_text("a\n")
|
||||
(folder / "subagents" / "workflows" / "journal.jsonl").write_text("j\n")
|
||||
(folder / "custom-title.json").write_text("first")
|
||||
kept = self.paths.transcript_archive / "proj" / str(self.session.id)
|
||||
fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)] * 2, claude=[judged("unfinished"), judged("finished")])
|
||||
fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)] * 3, claude=[judged("unfinished"), judged("finished"), judged("unfinished")])
|
||||
self.assertIsNone(run.run_cycle(self.cycle(fake)))
|
||||
os.utime(kept / "subagents" / "workflows" / "journal.jsonl", (0, 0))
|
||||
with open(folder / "subagents" / "agent-a.jsonl", "a") as handle:
|
||||
@@ -190,6 +191,10 @@ class Cycles(unittest.TestCase):
|
||||
self.assertEqual((kept / "subagents" / "agent-a.jsonl").read_text(), "a\nmore\n")
|
||||
self.assertEqual((kept / "subagents" / "workflows" / "journal.jsonl").stat().st_mtime, 0)
|
||||
self.assertEqual(stat.S_IMODE((kept / "subagents" / "agent-a.jsonl").stat().st_mode), 0o600)
|
||||
folder.mkdir()
|
||||
(folder / "custom-title.json").write_text("second")
|
||||
self.assertIsNone(run.run_cycle(self.cycle(fake)))
|
||||
self.assertEqual(sorted(path.read_text() for path in kept.glob("custom-title.json*")), ["first", "second"])
|
||||
|
||||
def test_an_interrupt_is_archived_answered_and_judged_again(self):
|
||||
def answer(args):
|
||||
|
||||
@@ -356,6 +356,7 @@ class Cycles(unittest.TestCase):
|
||||
run = checkout.run([worker(say="landed-it"), judge(finished=True, evidence="landed-it")])
|
||||
self.assertEqual((run.code, run.roles()), (1, ["worker", "judge"]))
|
||||
self.assertRegex(run.stderr.strip().splitlines()[-1], r"^could not archive the transcript: .*/loop-claude-transcripts/proj: Not a directory$")
|
||||
self.assertEqual(run.stderr.count("could not archive the transcript"), 1)
|
||||
session = argument(run.calls[0], "--session-id")
|
||||
checkout.archive().unlink()
|
||||
run = checkout.run([worker(), judge(finished=True)])
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
- **Move the judge's transcript rendering from `claude_code/transcript.py` into `cycle/`.** `render`, `part_line` and `JUDGED_TOOL_INPUT` shape what the judge sees, so what the judge sees is shaped in two packages: those three in `claude_code/`, and `JUDGED_TRANSCRIPT_TAIL` in `cycle/judge.py`; and `claude_code/` no longer holds only Claude Code's shapes as its docstring says. Goal 4.1.
|
||||
- **Make `JUDGE_RULES` and the Claude Code flags `loop-claude` passes readable without `CLAUDE.md` or Claude Code's docs open.** The 2026-10-02 scoring runs on PR #191 named both under Self-sufficiency: the judge's rules use "chunk" and "a release ready to cut" from `CLAUDE.md` with no link, and `--resume`, `--session-id`, `--no-session-persistence`, `--json-schema` and stream-json's result event go unexplained in `worker.py` and `judge.py`. Goal 4.1.
|
||||
- **Encode, decode and check the reload handover in `loop/reload.py` alone.** `reload.py` encodes `LoopRun` and decodes it, but `main.py`'s `loop_run_from` checks the decoded fields and words the error, so changing `LoopRun`'s fields means editing both files. The 2026-10-02 scoring runs on PR #191 named it under Locality. Goal 4.1.
|
||||
- **Give each cycle phase one name across its state, step and event.** Today `Judging` runs `rule` and yields `Ruled`, and `Finishing` runs `close`, which also deletes the session, and yields `Archived`. Goal 4.1.
|
||||
- **Give each cycle phase one name across its state, step and event.** Today `Judging` runs `rule` and yields `Ruled`, and `Closing` runs `close`, which also deletes a finished chunk's session, and yields `Archived`. Goal 4.1.
|
||||
- **Enable the `claude-security` plugin in `settings.json`, or drop larv-review's full-scan row.** No machine has it enabled, so every chunk that fires the pass skips it. Goal 4.1.
|
||||
- **Give `settings.json`'s model one writer, and sort its keys.** Claude Code rewrites `"model"` in this tracked file whenever a model is picked, so one `/model` dirties the checkout and overrides the synced choice. Goal 4.3.
|
||||
- **Say in `systems-architect.md` that a REST API's `/v1/` prefix is not versioning machinery to defer.** Its "defer the versioning story" can be read against `principles/rest-apis.md`, which requires the prefix from the start. Goal 4.3.
|
||||
|
||||
Reference in New Issue
Block a user