Run loop-claude from the checkout root wherever inside it is started #37

Merged
lilleman merged 7 commits from checkout-root into main 2026-09-25 08:50:18 +02:00
4 changed files with 33 additions and 11 deletions
+1
View File
@@ -7,6 +7,7 @@
- `loop-claude` exits 1 when the judge fails three times running; a verdict missing a field or quoting nothing in the transcript is a failure. - `loop-claude` exits 1 when the judge fails three times running; a verdict missing a field or quoting nothing in the transcript is a failure.
- `loop-claude` exits 2 when an interrupt gets no answer, saying why: stdin or stdout is not a terminal, or nothing was typed. Rerunning resumes the session. - `loop-claude` exits 2 when an interrupt gets no answer, saying why: stdin or stdout is not a terminal, or nothing was typed. Rerunning resumes the session.
- `loop-claude` archives each session's transcript under `~/.claude/loop-claude-transcripts/`, one folder per project; `LOOP_CLAUDE_TRANSCRIPTS` overrides the root. - `loop-claude` archives each session's transcript under `~/.claude/loop-claude-transcripts/`, one folder per project; `LOOP_CLAUDE_TRANSCRIPTS` overrides the root.
- `loop-claude` runs at the checkout root wherever inside the checkout it is started.
- `loop-claude --help` names the Claude Code version its transcript, session and trust handling were observed on; check it first when an upgrade breaks a cycle. - `loop-claude --help` names the Claude Code version its transcript, session and trust handling were observed on; check it first when an upgrade breaks a cycle.
- `loop-claude` runs the model each project's settings pick; `LOOP_CLAUDE_WORKER_MODEL` and `LOOP_CLAUDE_JUDGE_MODEL` override it. This repo runs on Fable 5.1. - `loop-claude` runs the model each project's settings pick; `LOOP_CLAUDE_WORKER_MODEL` and `LOOP_CLAUDE_JUDGE_MODEL` override it. This repo runs on Fable 5.1.
- Reviewers share one protocol for verdicts, severities, rounds and declines: `agents/review-protocol.md`. - Reviewers share one protocol for verdicts, severities, rounds and declines: `agents/review-protocol.md`.
+18 -10
View File
@@ -3,17 +3,17 @@
usage: loop-claude <task> usage: loop-claude <task>
Run it in a project checkout whose README.md has ## Goals and ## Audience, the premises. Each cycle Run it anywhere inside a project checkout whose README.md has ## Goals and ## Audience, the
a worker runs the task; a judge then reads the transcript against them. A question only the human premises; the task runs at the checkout root. Each cycle a worker runs the task; a judge then reads
can answer, or a release ready to cut, is an interrupt: `claude --resume` on the terminal. An the transcript against them. A question only the human can answer, or a release ready to cut, is an
unfinished chunk resumes the same session next cycle; a finished one starts a fresh session. Cycles interrupt: `claude --resume` on the terminal, every worktree first marked trusted in ~/.claude.json.
continue until that interrupt or Ctrl-C. Words: ~/.claude/CLAUDE.md → "Vocabulary". An unfinished chunk resumes the same session next cycle; a finished one starts a fresh session.
Cycles continue until that interrupt or Ctrl-C. Words: ~/.claude/CLAUDE.md → "Vocabulary".
Exit 1: no task, no premises, claude leaves no transcript, or the worker or the judge fails three Exit 1: no task, not inside a checkout, no premises, claude leaves no transcript, or the worker or
times running, a verdict missing a field or quoting nothing in the transcript being a judge failure. the judge fails three times running. A judge fails when its verdict misses a field or quotes nothing
Exit 2: the human is needed and stdin or stdout is not a terminal, or the interrupt ended without in the transcript. Exit 2: the human is needed and stdin or stdout is not a terminal, or the
them typing anything. Rerunning resumes the session after either exit. Before an interrupt every interrupt ended without them typing anything. Rerunning resumes any open session.
worktree is marked trusted in ~/.claude.json.
Each project has one session, "A <path> loop-claude", <path> being the checkout relative to ~/code, Each project has one session, "A <path> loop-claude", <path> being the checkout relative to ~/code,
or to / outside it, deleted when the chunk finishes. Its transcript is archived under or to / outside it, deleted when the chunk finishes. Its transcript is archived under
@@ -112,6 +112,13 @@ def read_premises():
return f"## Goals\n{found['Goals'][0]}\n\n## Audience\n{found['Audience'][0]}" return f"## Goals\n{found['Goals'][0]}\n\n## Audience\n{found['Audience'][0]}"
def checkout_root():
found = subprocess.run(["git", "rev-parse", "--show-toplevel"], capture_output=True, text=True)
if found.returncode != 0:
sys.exit(found.stderr.strip())
return found.stdout.strip()
def project(): def project():
return os.getcwd().removeprefix(os.path.expanduser("~/code/")).lstrip("/") return os.getcwd().removeprefix(os.path.expanduser("~/code/")).lstrip("/")
@@ -359,6 +366,7 @@ def main():
if task in ("", "-h", "--help"): if task in ("", "-h", "--help"):
print(__doc__.strip()) print(__doc__.strip())
sys.exit(0 if task else 1) sys.exit(0 if task else 1)
os.chdir(checkout_root())
cycle_number = int(os.environ.pop(RELOAD_CYCLE, 0)) cycle_number = int(os.environ.pop(RELOAD_CYCLE, 0))
failures = int(os.environ.pop(RELOAD_FAILURES, 0)) failures = int(os.environ.pop(RELOAD_FAILURES, 0))
while True: while True:
+14
View File
@@ -5,6 +5,7 @@ import json
import os import os
import pathlib import pathlib
import stat import stat
import subprocess
import tempfile import tempfile
import unittest import unittest
import unittest.mock import unittest.mock
@@ -84,6 +85,19 @@ class HumanTurns(unittest.TestCase):
]), 2) ]), 2)
class CheckoutRoot(unittest.TestCase):
def test_is_the_checkout_from_any_directory_inside_it_and_exits_outside_one(self):
with tempfile.TemporaryDirectory() as tmp, contextlib.chdir(tmp):
root = os.getcwd()
with self.assertRaises(SystemExit) as stopped:
loop.checkout_root()
self.assertTrue(stopped.exception.code)
subprocess.run(["git", "init", "-q"], check=True)
os.makedirs("a/b")
with contextlib.chdir("a/b"):
self.assertEqual(loop.checkout_root(), root)
class Project(unittest.TestCase): class Project(unittest.TestCase):
def test_names_a_checkout_relative_to_code_and_any_other_relative_to_root(self): def test_names_a_checkout_relative_to_code_and_any_other_relative_to_root(self):
with unittest.mock.patch.dict(os.environ, {"HOME": "/h"}): with unittest.mock.patch.dict(os.environ, {"HOME": "/h"}):
-1
View File
@@ -4,7 +4,6 @@
Ordered by how many seats of the 2026-09-24 scoring panel (`docs/decisions.md`) named the place; each is one chunk. Ordered by how many seats of the 2026-09-24 scoring panel (`docs/decisions.md`) named the place; each is one chunk.
- Derive `project()` from the checkout root, today `os.getcwd()`, so `loop-claude` run from a subdirectory joins the root's session.
- Settle whether the "Expect the codebase to get smaller" bullet under `CLAUDE.md` → "One spelling per goal" names an action, and cut it if it is a forecast. - Settle whether the "Expect the codebase to get smaller" bullet under `CLAUDE.md` → "One spelling per goal" names an action, and cut it if it is a forecast.
- Re-run the four-seat scoring panel and record the score in `docs/decisions.md`; the target is every dimension at 7.0 or above. - Re-run the four-seat scoring panel and record the score in `docs/decisions.md`; the target is every dimension at 7.0 or above.
- Exit `loop-claude` with a message, today a traceback, when `README.md` is not UTF-8. - Exit `loop-claude` with a message, today a traceback, when `README.md` is not UTF-8.