From 6a1a1d90277042c94ab129f0739a65899fa0cf2c Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 28 Sep 2026 21:27:07 +0200 Subject: [PATCH 1/6] Pin that an edit in a folder under loop_claude reloads the loop --- bin/test_loop_claude_black_box.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/bin/test_loop_claude_black_box.py b/bin/test_loop_claude_black_box.py index 77fc4ce9..681dee0d 100644 --- a/bin/test_loop_claude_black_box.py +++ b/bin/test_loop_claude_black_box.py @@ -67,11 +67,13 @@ if role == "worker": (transcript().parent / sibling).mkdir(parents=True, exist_ok=True) (transcript().parent / f"{{session()}}.orphaned-1-ab.jsonl").write_text("{{}}\\n") if "append" in step: - with open(os.environ["FAKE_CLAUDE_EDIT"], "a") as script: - script.write(step["append"]) + edited = pathlib.Path(os.environ["FAKE_CLAUDE_EDIT"], step["append"][0]) + edited.parent.mkdir(parents=True, exist_ok=True) + with open(edited, "a") as script: + script.write(step["append"][1]) if "replace" in step: - script = pathlib.Path(os.environ["FAKE_CLAUDE_EDIT"]) - script.write_text(script.read_text().replace(*step["replace"])) + script = pathlib.Path(os.environ["FAKE_CLAUDE_EDIT"], step["replace"][0]) + script.write_text(script.read_text().replace(*step["replace"][1:])) sys.stdout.flush() sys.stdout.buffer.write(step.get("stream", "").encode("latin-1")) print(json.dumps(said)) @@ -633,19 +635,19 @@ class Reload(unittest.TestCase): copy = checkout.temp / "bin" shutil.copytree(BIN, copy, ignore=shutil.ignore_patterns("__pycache__", "test_*")) checkout.script = copy / "loop-claude" - checkout.env["FAKE_CLAUDE_EDIT"] = str(checkout.script) + checkout.env["FAKE_CLAUDE_EDIT"] = str(copy) run = checkout.run([ - worker(append="\ndef\n"), judge(), - worker(replace=["\ndef\n", "\n# edited\n"]), judge(), + worker(append=["loop-claude", "\ndef\n"]), judge(), + worker(replace=["loop-claude", "\ndef\n", "\n# edited\n"]), judge(), + worker(append=["loop_claude/nested/edited.py", "# edited\n"]), judge(), worker(), ]) self.assertEqual(run.code, 130) - self.assertEqual(run.roles(), ["worker", "judge"] * 3) + self.assertEqual(run.roles(), ["worker", "judge"] * 4) self.assertIn("keeping the running script", run.stderr) - reloads = [argv for argv in run.starts if argv[:1] == ["--reloaded"]] - self.assertEqual(len(reloads), 1) - self.assertEqual(json.loads(reloads[0][1]), {"cycle_number": 2, "failures": 0, "root": str(checkout.root), "task": TASK}) - self.assertIn("=== cycle 3 ===", run.stdout) + reloads = [json.loads(argv[1]) for argv in run.starts if argv[:1] == ["--reloaded"]] + self.assertEqual(reloads, [{"cycle_number": cycle, "failures": 0, "root": str(checkout.root), "task": TASK} for cycle in (2, 3)]) + self.assertIn("=== cycle 4 ===", run.stdout) outside = checkout.temp / "outside" outside.mkdir() -- 2.52.0 From 998cc3ac85cb33bf80c466e6b4868cc9749bbde6 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 28 Sep 2026 21:28:41 +0200 Subject: [PATCH 2/6] Group loop_claude's modules into claude_code, claude_runs and project, and move the findings document beside larv-review --- .gitignore | 2 ++ README.md | 2 +- agents/product-owner-reviewer.md | 2 +- agents/stability-reviewer.md | 2 +- agents/systems-architect.md | 2 +- bin/loop_claude/claude_code/__init__.py | 0 .../{claude_code.py => claude_code/formats.py} | 0 bin/loop_claude/{ => claude_code}/session.py | 4 ++-- bin/loop_claude/{ => claude_code}/transcript.py | 2 +- bin/loop_claude/{ => claude_code}/trust.py | 2 +- bin/loop_claude/claude_runs/__init__.py | 0 bin/loop_claude/{ => claude_runs}/interrupt.py | 6 +++--- bin/loop_claude/{ => claude_runs}/judge.py | 2 +- bin/loop_claude/{ => claude_runs}/worker.py | 4 ++-- bin/loop_claude/cycle.py | 12 ++++++------ bin/loop_claude/main.py | 8 ++++---- bin/loop_claude/paths.py | 2 +- bin/loop_claude/project/__init__.py | 0 bin/loop_claude/{ => project}/checkout.py | 0 bin/loop_claude/{ => project}/models.py | 4 ++-- bin/loop_claude/{ => project}/premises.py | 0 bin/loop_claude/reload.py | 4 ++-- bin/test_loop_claude.py | 11 +++++++---- skills/larv-review/SKILL.md | 2 +- .../larv-review}/review-findings.md | 0 todo.md | 1 - 26 files changed, 39 insertions(+), 35 deletions(-) create mode 100644 bin/loop_claude/claude_code/__init__.py rename bin/loop_claude/{claude_code.py => claude_code/formats.py} (100%) rename bin/loop_claude/{ => claude_code}/session.py (87%) rename bin/loop_claude/{ => claude_code}/transcript.py (89%) rename bin/loop_claude/{ => claude_code}/trust.py (91%) create mode 100644 bin/loop_claude/claude_runs/__init__.py rename bin/loop_claude/{ => claude_runs}/interrupt.py (85%) rename bin/loop_claude/{ => claude_runs}/judge.py (98%) rename bin/loop_claude/{ => claude_runs}/worker.py (90%) create mode 100644 bin/loop_claude/project/__init__.py rename bin/loop_claude/{ => project}/checkout.py (100%) rename bin/loop_claude/{ => project}/models.py (96%) rename bin/loop_claude/{ => project}/premises.py (100%) rename {principles => skills/larv-review}/review-findings.md (100%) diff --git a/.gitignore b/.gitignore index abba4dcf..24919d6e 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,8 @@ !bin/ !bin/* !bin/loop_claude/*.py +!bin/loop_claude/*/ +!bin/loop_claude/*/*.py !docs/ !docs/*.md !principles/ diff --git a/README.md b/README.md index 0ba7dd96..1bf70584 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Claude Code configuration -My personal `~/.claude`, version controlled: `CLAUDE.md` and `AGENTS.md` for instructions, the words under `CLAUDE.md` → "Vocabulary"; `agents/` and `skills/`; `principles/` for what the reviewer agents hold every project and every review to; `docs/` for decisions; `settings.json` for the harness and `.claude/settings.json` for the harness inside this repo; `statusline.sh`; `CHANGELOG.md` and `todo.md`; and the tools in `bin/`. +My personal `~/.claude`, version controlled: `CLAUDE.md` and `AGENTS.md` for instructions, the words under `CLAUDE.md` → "Vocabulary"; `agents/` and `skills/`; `principles/` for what the reviewer agents hold every project to; `docs/` for decisions; `settings.json` for the harness and `.claude/settings.json` for the harness inside this repo; `statusline.sh`; `CHANGELOG.md` and `todo.md`; and the tools in `bin/`. ## Goals diff --git a/agents/product-owner-reviewer.md b/agents/product-owner-reviewer.md index c253e899..9f252975 100644 --- a/agents/product-owner-reviewer.md +++ b/agents/product-owner-reviewer.md @@ -45,7 +45,7 @@ Before anything else, **read the shared principles** at `~/.claude/principles/`. ## Your Output Format -Verdict, severities, rounds and declines: ~/.claude/principles/review-findings.md. After the verdict: +Verdict, severities, rounds and declines: ~/.claude/skills/larv-review/review-findings.md. After the verdict: **Surface affected**: diff --git a/agents/stability-reviewer.md b/agents/stability-reviewer.md index 62ea2850..10be9e9f 100644 --- a/agents/stability-reviewer.md +++ b/agents/stability-reviewer.md @@ -128,7 +128,7 @@ Every PR gets at least this sweep. ## Output Format -Verdict, severities, rounds and declines: ~/.claude/principles/review-findings.md. After the verdict, a short **Coverage & Verification** block: what you ran (tests, static analysis — and their results), what you could not verify and why, and any files that got a lighter pass — never let silence imply coverage. Then the findings, most severe first, each with: +Verdict, severities, rounds and declines: ~/.claude/skills/larv-review/review-findings.md. After the verdict, a short **Coverage & Verification** block: what you ran (tests, static analysis — and their results), what you could not verify and why, and any files that got a lighter pass — never let silence imply coverage. Then the findings, most severe first, each with: - **Location**: File and line/function - **Issue**: Clear description of the problem - **Risk**: What could go wrong in production diff --git a/agents/systems-architect.md b/agents/systems-architect.md index 5266bb77..24b8bb78 100644 --- a/agents/systems-architect.md +++ b/agents/systems-architect.md @@ -151,7 +151,7 @@ How a change ships — merge gate, pipeline, deployment, dependencies — is a d You are not a per-PR reviewer. The **stability-reviewer** runs on every change for code-level safety; you run deliberately, every so often, to check the system is still aligned — right goals, right contract, right foundations, sound structure. When you do look at a specific PR, it is because the work touches architectural fundamentals or reopens foundational choices, not for routine line-level review. Stage 0 blocks review as much as design: if the project's purpose and goals are not abundantly clear from its docs, this run's output is the clarifying questions plus a short draft to confirm — not a review; the review happens in a later invocation, once the answers are recorded in the README. -**Verdict and severities: ~/.claude/principles/review-findings.md.** A violation of a non-negotiable fundamental — functional-core/shell entanglement, a unit past a Fits in a head threshold without a stated reason, a method or file carrying more than one responsibility, unreasoned duplication of a core concept, or a broken/leaky external contract — is a 🔴: lead with it, and name the concrete restructuring. The most common instance: a pure transformation (a deterministic input→output computation) entangled inside an imperative-shell or orchestration method, where it could be a named, separately-testable function. The architectural defect being real, not its line count or "how much it works today," sets the severity; rate a non-fundamental finding by its eventual cost — the recorded horizon sets that cost; fundamentals stay 🔴 at every horizon (Core Philosophy: rigor follows the horizon). +**Verdict and severities: ~/.claude/skills/larv-review/review-findings.md.** A violation of a non-negotiable fundamental — functional-core/shell entanglement, a unit past a Fits in a head threshold without a stated reason, a method or file carrying more than one responsibility, unreasoned duplication of a core concept, or a broken/leaky external contract — is a 🔴: lead with it, and name the concrete restructuring. The most common instance: a pure transformation (a deterministic input→output computation) entangled inside an imperative-shell or orchestration method, where it could be a named, separately-testable function. The architectural defect being real, not its line count or "how much it works today," sets the severity; rate a non-fundamental finding by its eventual cost — the recorded horizon sets that cost; fundamentals stay 🔴 at every horizon (Core Philosophy: rigor follows the horizon). Focus on architectural alignment: - Does it still serve the project's goals and priorities, or has it quietly drifted from them? diff --git a/bin/loop_claude/claude_code/__init__.py b/bin/loop_claude/claude_code/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/bin/loop_claude/claude_code.py b/bin/loop_claude/claude_code/formats.py similarity index 100% rename from bin/loop_claude/claude_code.py rename to bin/loop_claude/claude_code/formats.py diff --git a/bin/loop_claude/session.py b/bin/loop_claude/claude_code/session.py similarity index 87% rename from bin/loop_claude/session.py rename to bin/loop_claude/claude_code/session.py index 8198ce99..fcc33fc7 100644 --- a/bin/loop_claude/session.py +++ b/bin/loop_claude/claude_code/session.py @@ -5,8 +5,8 @@ import shutil import sys import uuid -from loop_claude.checkout import project_name -from loop_claude.claude_code import session_files, transcript_path +from loop_claude.project.checkout import project_name +from loop_claude.claude_code.formats import session_files, transcript_path NAMESPACE = uuid.UUID("64fb586b-d926-4bb3-a44c-c903e86d3eec") diff --git a/bin/loop_claude/transcript.py b/bin/loop_claude/claude_code/transcript.py similarity index 89% rename from bin/loop_claude/transcript.py rename to bin/loop_claude/claude_code/transcript.py index 2ddf768e..e73ffdbb 100644 --- a/bin/loop_claude/transcript.py +++ b/bin/loop_claude/claude_code/transcript.py @@ -1,6 +1,6 @@ import json -from loop_claude.claude_code import assistant_parts, human_text, parse, part_text, tool_call +from loop_claude.claude_code.formats import assistant_parts, human_text, parse, part_text, tool_call from loop_claude.outcome import Failure diff --git a/bin/loop_claude/trust.py b/bin/loop_claude/claude_code/trust.py similarity index 91% rename from bin/loop_claude/trust.py rename to bin/loop_claude/claude_code/trust.py index 68d9b4e7..715254d5 100644 --- a/bin/loop_claude/trust.py +++ b/bin/loop_claude/claude_code/trust.py @@ -1,7 +1,7 @@ import json import sys -from loop_claude.claude_code import mark_trusted, trust_records +from loop_claude.claude_code.formats import mark_trusted, trust_records from loop_claude.file_writes import replace_json from loop_claude.outcome import Failure diff --git a/bin/loop_claude/claude_runs/__init__.py b/bin/loop_claude/claude_runs/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/bin/loop_claude/interrupt.py b/bin/loop_claude/claude_runs/interrupt.py similarity index 85% rename from bin/loop_claude/interrupt.py rename to bin/loop_claude/claude_runs/interrupt.py index 5a965f7d..8b291b27 100644 --- a/bin/loop_claude/interrupt.py +++ b/bin/loop_claude/claude_runs/interrupt.py @@ -2,10 +2,10 @@ import subprocess import sys from loop_claude import human -from loop_claude.checkout import checkouts +from loop_claude.project.checkout import checkouts from loop_claude.outcome import Failure, Stop -from loop_claude.transcript import human_turns, read -from loop_claude.trust import trust +from loop_claude.claude_code.transcript import human_turns, read +from loop_claude.claude_code.trust import trust TO = "answer the question above" diff --git a/bin/loop_claude/judge.py b/bin/loop_claude/claude_runs/judge.py similarity index 98% rename from bin/loop_claude/judge.py rename to bin/loop_claude/claude_runs/judge.py index 943586ad..d1908bd8 100644 --- a/bin/loop_claude/judge.py +++ b/bin/loop_claude/claude_runs/judge.py @@ -2,7 +2,7 @@ import itertools import json import subprocess -from loop_claude.claude_code import structured_output +from loop_claude.claude_code.formats import structured_output from loop_claude.outcome import Failure from loop_claude.retry import stop_or_sleep_a_minute diff --git a/bin/loop_claude/worker.py b/bin/loop_claude/claude_runs/worker.py similarity index 90% rename from bin/loop_claude/worker.py rename to bin/loop_claude/claude_runs/worker.py index ec73096f..836c2b72 100644 --- a/bin/loop_claude/worker.py +++ b/bin/loop_claude/claude_runs/worker.py @@ -1,8 +1,8 @@ import subprocess -from loop_claude.claude_code import assistant_parts, ends_stream, parse +from loop_claude.claude_code.formats import assistant_parts, ends_stream, parse from loop_claude.outcome import Failure -from loop_claude.transcript import part_line +from loop_claude.claude_code.transcript import part_line def run_worker(root, args): diff --git a/bin/loop_claude/cycle.py b/bin/loop_claude/cycle.py index 14055c31..2e2997ef 100644 --- a/bin/loop_claude/cycle.py +++ b/bin/loop_claude/cycle.py @@ -1,14 +1,14 @@ import hashlib import sys -from loop_claude.checkout import project_name +from loop_claude.project.checkout import project_name from loop_claude.file_writes import make_private, replace_file -from loop_claude.interrupt import interrupt -from loop_claude.judge import judge +from loop_claude.claude_runs.interrupt import interrupt +from loop_claude.claude_runs.judge import judge from loop_claude.outcome import Continue, Failure, Stop -from loop_claude.session import delete_session, session_for, transcript_file -from loop_claude.transcript import read, render -from loop_claude.worker import run_worker, worker_args +from loop_claude.claude_code.session import delete_session, session_for, transcript_file +from loop_claude.claude_code.transcript import read, render +from loop_claude.claude_runs.worker import run_worker, worker_args def run_cycle(root, task, premises, models, paths): diff --git a/bin/loop_claude/main.py b/bin/loop_claude/main.py index 37c2c262..6d331777 100644 --- a/bin/loop_claude/main.py +++ b/bin/loop_claude/main.py @@ -30,17 +30,17 @@ and read each cycle; a project without an entry, as on its first run, is asked f LOOP_CLAUDE_JUDGE_MODEL overrides it for the judge, LOOP_CLAUDE_WORKER_MODEL for the worker and the interrupt; with both set, nothing is asked. -A change to bin/loop-claude or bin/loop_claude/*.py takes effect at the next cycle boundary, once +A change to bin/loop-claude or bin/loop_claude/**/*.py takes effect at the next cycle boundary, once loop-claude --help succeeds. """ import dataclasses import sys -from loop_claude.checkout import checkout_root +from loop_claude.project.checkout import checkout_root from loop_claude.cycle import run_cycle -from loop_claude.models import project_models +from loop_claude.project.models import project_models from loop_claude.outcome import Continue, Failure, Stop -from loop_claude.premises import read_premises +from loop_claude.project.premises import read_premises from loop_claude.reload import RELOAD_FLAG, decode_state, exec_if_edited, fingerprint from loop_claude.retry import stop_or_sleep_a_minute diff --git a/bin/loop_claude/paths.py b/bin/loop_claude/paths.py index 7f42eabe..ba1153bb 100644 --- a/bin/loop_claude/paths.py +++ b/bin/loop_claude/paths.py @@ -1,7 +1,7 @@ import dataclasses import pathlib -from loop_claude.claude_code import locations +from loop_claude.claude_code.formats import locations @dataclasses.dataclass(frozen=True) diff --git a/bin/loop_claude/project/__init__.py b/bin/loop_claude/project/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/bin/loop_claude/checkout.py b/bin/loop_claude/project/checkout.py similarity index 100% rename from bin/loop_claude/checkout.py rename to bin/loop_claude/project/checkout.py diff --git a/bin/loop_claude/models.py b/bin/loop_claude/project/models.py similarity index 96% rename from bin/loop_claude/models.py rename to bin/loop_claude/project/models.py index fa02b44a..4b3d122e 100644 --- a/bin/loop_claude/models.py +++ b/bin/loop_claude/project/models.py @@ -3,8 +3,8 @@ import json import sys from loop_claude import human -from loop_claude.checkout import project_name -from loop_claude.claude_code import catalog +from loop_claude.project.checkout import project_name +from loop_claude.claude_code.formats import catalog from loop_claude.file_writes import replace_json from loop_claude.outcome import Stop diff --git a/bin/loop_claude/premises.py b/bin/loop_claude/project/premises.py similarity index 100% rename from bin/loop_claude/premises.py rename to bin/loop_claude/project/premises.py diff --git a/bin/loop_claude/reload.py b/bin/loop_claude/reload.py index 4e8f7af6..ba23f9b5 100644 --- a/bin/loop_claude/reload.py +++ b/bin/loop_claude/reload.py @@ -23,12 +23,12 @@ def decode_state(handed, kind): def fingerprint(launcher): digest = hashlib.sha256() - for path in [launcher, *sorted((launcher.parent / "loop_claude").glob("*.py"))]: + for path in [launcher, *sorted((launcher.parent / "loop_claude").rglob("*.py"))]: try: content = path.read_bytes() except OSError as failure: content = str(failure).encode() - digest.update(f"{path.name}\0{len(content)}\0".encode() + content) + digest.update(f"{path.relative_to(launcher.parent)}\0{len(content)}\0".encode() + content) return digest.hexdigest() diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index 09e6a87b..28674499 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -7,8 +7,11 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent)) -from loop_claude import claude_code, file_writes, judge, main, premises, transcript +from loop_claude import file_writes, main +from loop_claude.claude_code import formats, transcript +from loop_claude.claude_runs import judge from loop_claude.outcome import Failure, Stop +from loop_claude.project import premises CWD = pathlib.Path("/c") @@ -68,9 +71,9 @@ class PartLine(unittest.TestCase): class Parse(unittest.TestCase): def test_yields_only_json_objects(self): - self.assertEqual(claude_code.parse('{"type": "user"}'), {"type": "user"}) - self.assertIsNone(claude_code.parse("not json")) - self.assertIsNone(claude_code.parse("[1, 2]")) + self.assertEqual(formats.parse('{"type": "user"}'), {"type": "user"}) + self.assertIsNone(formats.parse("not json")) + self.assertIsNone(formats.parse("[1, 2]")) class Grounded(unittest.TestCase): diff --git a/skills/larv-review/SKILL.md b/skills/larv-review/SKILL.md index 90b8ce99..0a48d32f 100644 --- a/skills/larv-review/SKILL.md +++ b/skills/larv-review/SKILL.md @@ -9,7 +9,7 @@ You orchestrate, fix, and ship; reviewers only report. Run every reviewer synchr **Forge-neutral.** Five PR operations recur below: read a PR's diff, open a draft PR, read check status, mark ready, merge. Resolve the tooling from the remote per `~/.claude/CLAUDE.md` → "Git, commits, and PRs"; on any other forge, achieve the same intents through its CLI or API — discover how rather than assuming. A forge without a native draft state gets the closest equivalent (a `WIP:`/`Draft:` title prefix); note any approximation in the summary. -Words: `~/.claude/CLAUDE.md` → "Vocabulary". Findings, for every reviewer: ~/.claude/principles/review-findings.md. +Words: `~/.claude/CLAUDE.md` → "Vocabulary". Findings, for every reviewer: ~/.claude/skills/larv-review/review-findings.md. ## 1. Preconditions diff --git a/principles/review-findings.md b/skills/larv-review/review-findings.md similarity index 100% rename from principles/review-findings.md rename to skills/larv-review/review-findings.md diff --git a/todo.md b/todo.md index e11ccd80..b0495a52 100644 --- a/todo.md +++ b/todo.md @@ -8,7 +8,6 @@ The rebuild lifts every dimension: each item below is one chunk on a worktree ba The places the panel on `rebuild` at 37edc9a named (`docs/decisions.md`), capping dimension first: -- **Group `bin/loop_claude/`'s 18 flat modules, and move `principles/review-findings.md` beside larv-review.** Two seats; `claude_code.py` is the first group. - **Show the judge a reply the human sends while claude works.** Claude Code 2.1.284 writes it as an `"attachment"` entry, which `render` drops, so the judge can rule on a question the human already answered during an interrupt. - **Score `rebuild` with the four-seat panel at 7.0 or above on every dimension and the overall, none below the last run, and open its PR into main for the human.** ⚠️ Leave that PR ready and unmerged: only the human merges it, after approving the whole rebuild. A dimension under the floor gets its places filed above this item. -- 2.52.0 From cca0b67b8bbae9d221849591a0631338a9b74786 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 28 Sep 2026 21:32:27 +0200 Subject: [PATCH 3/6] Name the project once in main, and give the archive its own module --- bin/loop_claude/archive.py | 23 +++++++++++++ bin/loop_claude/claude_code/session.py | 5 ++- bin/loop_claude/claude_runs/interrupt.py | 4 +-- bin/loop_claude/claude_runs/worker.py | 2 +- bin/loop_claude/cycle.py | 41 ++++++------------------ bin/loop_claude/main.py | 9 +++--- bin/loop_claude/project/models.py | 5 ++- 7 files changed, 45 insertions(+), 44 deletions(-) create mode 100644 bin/loop_claude/archive.py diff --git a/bin/loop_claude/archive.py b/bin/loop_claude/archive.py new file mode 100644 index 00000000..50843a72 --- /dev/null +++ b/bin/loop_claude/archive.py @@ -0,0 +1,23 @@ +import hashlib +import sys + +from loop_claude.file_writes import make_private, replace_file +from loop_claude.outcome import Failure + + +def archive(project, path, note, paths): + folder = paths.archive / project + try: + with open(path, "rb") as handle: + raw = handle.read() + make_private(folder) + except OSError as failure: + return Failure(f"could not archive the transcript: {failure.filename}: {failure.strerror}") + copy = folder / f"{hashlib.sha256(raw).hexdigest()}.jsonl" + # The copy lands last, so a copy on disk always has its verdict beside it. + if not copy.exists(): + for dest, data in ((copy.with_suffix(".verdict.md"), f"{note}\n".encode()), (copy, raw)): + if failure := replace_file(dest, data): + return Failure(f"could not archive the transcript: {dest}: {failure.reason}") + print(f"transcript: {copy}", file=sys.stderr) + return None diff --git a/bin/loop_claude/claude_code/session.py b/bin/loop_claude/claude_code/session.py index fcc33fc7..3c9f09e6 100644 --- a/bin/loop_claude/claude_code/session.py +++ b/bin/loop_claude/claude_code/session.py @@ -5,7 +5,6 @@ import shutil import sys import uuid -from loop_claude.project.checkout import project_name from loop_claude.claude_code.formats import session_files, transcript_path NAMESPACE = uuid.UUID("64fb586b-d926-4bb3-a44c-c903e86d3eec") @@ -18,10 +17,10 @@ class Session: projects: pathlib.Path -def session_for(root, paths): +def session_for(project, paths): """Exists while its transcript does.""" # "A " is the human's cue in the session picker that the session is the loop's. - name = f"A {project_name(root, paths.code)} loop-claude" + name = f"A {project} loop-claude" return Session(uuid.uuid5(NAMESPACE, name), name, paths.projects) diff --git a/bin/loop_claude/claude_runs/interrupt.py b/bin/loop_claude/claude_runs/interrupt.py index 8b291b27..cfff5fc9 100644 --- a/bin/loop_claude/claude_runs/interrupt.py +++ b/bin/loop_claude/claude_runs/interrupt.py @@ -2,10 +2,10 @@ import subprocess import sys from loop_claude import human -from loop_claude.project.checkout import checkouts -from loop_claude.outcome import Failure, Stop from loop_claude.claude_code.transcript import human_turns, read from loop_claude.claude_code.trust import trust +from loop_claude.outcome import Failure, Stop +from loop_claude.project.checkout import checkouts TO = "answer the question above" diff --git a/bin/loop_claude/claude_runs/worker.py b/bin/loop_claude/claude_runs/worker.py index 836c2b72..3d0c6bdc 100644 --- a/bin/loop_claude/claude_runs/worker.py +++ b/bin/loop_claude/claude_runs/worker.py @@ -1,8 +1,8 @@ import subprocess from loop_claude.claude_code.formats import assistant_parts, ends_stream, parse -from loop_claude.outcome import Failure from loop_claude.claude_code.transcript import part_line +from loop_claude.outcome import Failure def run_worker(root, args): diff --git a/bin/loop_claude/cycle.py b/bin/loop_claude/cycle.py index 2e2997ef..c4e66d37 100644 --- a/bin/loop_claude/cycle.py +++ b/bin/loop_claude/cycle.py @@ -1,35 +1,31 @@ -import hashlib -import sys - -from loop_claude.project.checkout import project_name -from loop_claude.file_writes import make_private, replace_file -from loop_claude.claude_runs.interrupt import interrupt -from loop_claude.claude_runs.judge import judge -from loop_claude.outcome import Continue, Failure, Stop +from loop_claude.archive import archive from loop_claude.claude_code.session import delete_session, session_for, transcript_file from loop_claude.claude_code.transcript import read, render +from loop_claude.claude_runs.interrupt import interrupt +from loop_claude.claude_runs.judge import judge from loop_claude.claude_runs.worker import run_worker, worker_args +from loop_claude.outcome import Continue, Failure, Stop -def run_cycle(root, task, premises, models, paths): - session = session_for(root, paths) +def run_cycle(root, project, task, premises, models, paths): + session = session_for(project, paths) resuming = bool(transcript_file(session)) if failure := run_worker(root, worker_args(task, session, models.worker, resuming)): return failure path = transcript_file(session) if not path: return Stop(1, f"claude left no transcript for session {session.id}") - verdict = judge_through_interrupts(root, task, premises, models, session, path, paths) + verdict = judge_through_interrupts(root, project, task, premises, models, session, path, paths) if isinstance(verdict, Stop): return verdict if verdict["finished"]: - if failure := archive(root, path, f"Task: {task}\n\nVerdict: finished", paths): + if failure := archive(project, path, f"Task: {task}\n\nVerdict: finished", paths): return Stop(1, failure.reason) delete_session(session) return Continue() -def judge_through_interrupts(root, task, premises, models, session, path, paths): +def judge_through_interrupts(root, project, task, premises, models, session, path, paths): # The interrupt appends to this transcript, so each pass judges and archives it anew. while True: entries = read(path) @@ -38,25 +34,8 @@ def judge_through_interrupts(root, task, premises, models, session, path, paths) verdict = judge(root, task, premises, render(entries), models.judge) if isinstance(verdict, Stop) or not verdict["interrupt"]: return verdict - if failure := archive(root, path, f"Task: {task}\n\nVerdict: interrupt\n\n{verdict['question']}", paths): + if failure := archive(project, path, f"Task: {task}\n\nVerdict: interrupt\n\n{verdict['question']}", paths): return Stop(1, failure.reason) if stop := interrupt(root, session.id, models.worker, path, verdict["question"], paths): return stop - -def archive(root, path, note, paths): - folder = paths.archive / project_name(root, paths.code) - try: - with open(path, "rb") as handle: - raw = handle.read() - make_private(folder) - except OSError as failure: - return Failure(f"could not archive the transcript: {failure.filename}: {failure.strerror}") - copy = folder / f"{hashlib.sha256(raw).hexdigest()}.jsonl" - # The copy lands last, so a copy on disk always has its verdict beside it. - if not copy.exists(): - for dest, data in ((copy.with_suffix(".verdict.md"), f"{note}\n".encode()), (copy, raw)): - if failure := replace_file(dest, data): - return Failure(f"could not archive the transcript: {dest}: {failure.reason}") - print(f"transcript: {copy}", file=sys.stderr) - return None diff --git a/bin/loop_claude/main.py b/bin/loop_claude/main.py index 6d331777..5819a626 100644 --- a/bin/loop_claude/main.py +++ b/bin/loop_claude/main.py @@ -36,10 +36,10 @@ loop-claude --help succeeds. import dataclasses import sys -from loop_claude.project.checkout import checkout_root from loop_claude.cycle import run_cycle -from loop_claude.project.models import project_models from loop_claude.outcome import Continue, Failure, Stop +from loop_claude.project.checkout import checkout_root, project_name +from loop_claude.project.models import project_models from loop_claude.project.premises import read_premises from loop_claude.reload import RELOAD_FLAG, decode_state, exec_if_edited, fingerprint from loop_claude.retry import stop_or_sleep_a_minute @@ -68,17 +68,18 @@ def run_loop(argv, env, paths, launcher, cwd): if isinstance(state, Stop): return state baseline = fingerprint(launcher) + project = project_name(state.root, paths.code) while True: exec_if_edited(launcher, baseline, state) state = dataclasses.replace(state, cycle_number=state.cycle_number + 1) premises = read_premises(state.root) if isinstance(premises, Stop): return premises - models = project_models(state.root, paths, env) + models = project_models(project, paths, env) if isinstance(models, Stop): return models print(f"\n=== cycle {state.cycle_number} ===", flush=True) - match run_cycle(state.root, state.task, premises, models, paths): + match run_cycle(state.root, project, state.task, premises, models, paths): case Stop() as stop: return stop case Failure(reason): diff --git a/bin/loop_claude/project/models.py b/bin/loop_claude/project/models.py index 4b3d122e..3a75272b 100644 --- a/bin/loop_claude/project/models.py +++ b/bin/loop_claude/project/models.py @@ -3,7 +3,6 @@ import json import sys from loop_claude import human -from loop_claude.project.checkout import project_name from loop_claude.claude_code.formats import catalog from loop_claude.file_writes import replace_json from loop_claude.outcome import Stop @@ -15,11 +14,11 @@ class Models: worker: str -def project_models(root, paths, env): +def project_models(project, paths, env): judge, worker = env.get("LOOP_CLAUDE_JUDGE_MODEL"), env.get("LOOP_CLAUDE_WORKER_MODEL") if judge and worker: return Models(judge, worker) - chosen = project_model(project_name(root, paths.code), paths) + chosen = project_model(project, paths) if isinstance(chosen, Stop): return chosen return Models(judge or chosen, worker or chosen) -- 2.52.0 From 1bcef56657919dfc96dd1f80f0c5de7f531d0160 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 28 Sep 2026 21:35:58 +0200 Subject: [PATCH 4/6] Allowlist loop_claude's modules at any depth --- .gitignore | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 24919d6e..a862cce1 100644 --- a/.gitignore +++ b/.gitignore @@ -20,8 +20,8 @@ !bin/ !bin/* !bin/loop_claude/*.py -!bin/loop_claude/*/ -!bin/loop_claude/*/*.py +!bin/loop_claude/**/ +!bin/loop_claude/**/*.py !docs/ !docs/*.md !principles/ -- 2.52.0 From 75529c8592a8ffbf586fd2eced3d325d79439cc4 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 28 Sep 2026 21:36:03 +0200 Subject: [PATCH 5/6] Drop the allowlist line the any-depth rule covers --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index a862cce1..ba2981f2 100644 --- a/.gitignore +++ b/.gitignore @@ -19,7 +19,6 @@ !agents/*.md !bin/ !bin/* -!bin/loop_claude/*.py !bin/loop_claude/**/ !bin/loop_claude/**/*.py !docs/ -- 2.52.0 From e90b7cb9d72a57d97766a981cf7ae575d4df4305 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 28 Sep 2026 21:38:04 +0200 Subject: [PATCH 6/6] Drop the plan's second statement of where a rebuild chunk's PR goes --- todo.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/todo.md b/todo.md index b0495a52..b9af9e2d 100644 --- a/todo.md +++ b/todo.md @@ -4,7 +4,7 @@ **⚠️ THE REBUILD NEVER MERGES INTO MAIN WITHOUT THE HUMAN'S EXPLICIT APPROVAL.** Every rebuild chunk is a worktree based on `origin/rebuild` with its PR into `rebuild`, never into main. Other sessions run on `~/.claude` main throughout; only the human merges `rebuild` into main, once they have approved the finished whole. -The rebuild lifts every dimension: each item below is one chunk on a worktree based on `origin/rebuild`, its PR into `rebuild`, until the last item opens `rebuild`'s PR into main. The sketches, the judges' verdicts and what to take from each: `~/code/claude-handoffs/claude-config_2026-09-28.md`. +The rebuild lifts every dimension, one chunk per item, until the last item opens `rebuild`'s PR into main. The sketches, the judges' verdicts and what to take from each: `~/code/claude-handoffs/claude-config_2026-09-28.md`. The places the panel on `rebuild` at 37edc9a named (`docs/decisions.md`), capping dimension first: -- 2.52.0