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

This commit is contained in:
2026-09-25 08:39:37 +02:00
parent ebe6bebea6
commit 13f0aae899
4 changed files with 24 additions and 6 deletions
+12 -5
View File
@@ -3,11 +3,12 @@
usage: loop-claude <task>
Run it in a project checkout whose README.md has ## Goals and ## Audience, the premises. Each cycle
a worker runs the task; a judge then reads the transcript against them. A question only the human
can answer, or a release ready to cut, is an interrupt: `claude --resume` on the terminal. 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".
Run it anywhere inside a project checkout whose README.md has ## Goals and ## Audience, the
premises; it works from the checkout root. Each cycle a worker runs the task; a judge then reads the
transcript against them. A question only the human can answer, or a release ready to cut, is an
interrupt: `claude --resume` on the terminal. 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
times running, a verdict missing a field or quoting nothing in the transcript being a judge failure.
@@ -112,6 +113,11 @@ def read_premises():
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)
return found.stdout.strip() if found.returncode == 0 else os.getcwd()
def project():
return os.getcwd().removeprefix(os.path.expanduser("~/code/")).lstrip("/")
@@ -359,6 +365,7 @@ def main():
if task in ("", "-h", "--help"):
print(__doc__.strip())
sys.exit(0 if task else 1)
os.chdir(checkout_root())
cycle_number = int(os.environ.pop(RELOAD_CYCLE, 0))
failures = int(os.environ.pop(RELOAD_FAILURES, 0))
while True:
+11
View File
@@ -5,6 +5,7 @@ import json
import os
import pathlib
import stat
import subprocess
import tempfile
import unittest
import unittest.mock
@@ -84,6 +85,16 @@ class HumanTurns(unittest.TestCase):
]), 2)
class CheckoutRoot(unittest.TestCase):
def test_is_the_checkout_from_any_directory_inside_it_and_the_directory_itself_outside_one(self):
with tempfile.TemporaryDirectory() as root, contextlib.chdir(root):
self.assertEqual(loop.checkout_root(), os.getcwd())
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):
def test_names_a_checkout_relative_to_code_and_any_other_relative_to_root(self):
with unittest.mock.patch.dict(os.environ, {"HOME": "/h"}):