Run the claude children at the root, and pin the root the tests hand on

This commit is contained in:
2026-09-25 18:11:27 +02:00
parent d64eaef9e7
commit 24ebeb0f94
2 changed files with 16 additions and 12 deletions
+8 -9
View File
@@ -261,8 +261,8 @@ def worker_args(task, name, session_id, resuming):
]
def run_worker(args):
proc = subprocess.Popen(["claude", *args], stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, text=True)
def run_worker(root, args):
proc = subprocess.Popen(["claude", *args], cwd=root, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, text=True)
done = False
for raw in proc.stdout:
event = parse(raw) or {}
@@ -297,7 +297,7 @@ def grounded(verdict, transcript):
return not verdict["ask"] or bool(verdict["evidence"]) and verdict["evidence"] in transcript
def judge(task, premises, transcript):
def judge(root, task, premises, transcript):
args = [
"-p",
"--json-schema", json.dumps(JUDGE_SCHEMA),
@@ -309,7 +309,7 @@ def judge(task, premises, transcript):
]
prompt = judge_prompt(task, premises, transcript)
for attempt in range(3):
proc = subprocess.run(["claude", *args], capture_output=True, input=prompt, text=True)
proc = subprocess.run(["claude", *args], capture_output=True, cwd=root, input=prompt, text=True)
verdict = (parse(proc.stdout) or {}).get("structured_output") if proc.returncode == 0 else None
if not complete(verdict):
failure = proc.stderr.strip() or "the judge returned no verdict"
@@ -329,23 +329,23 @@ def interrupt(root, session_id, path, question):
return "stdin or stdout is not a terminal"
trust(checkouts(root))
before = human_turns(entries(path))
subprocess.run(["claude", "--permission-mode", "bypassPermissions", "--resume", str(session_id)])
subprocess.run(["claude", "--permission-mode", "bypassPermissions", "--resume", str(session_id)], cwd=root)
return "" if human_turns(entries(path)) > before else "the interrupt ended without the human typing anything"
def run_cycle(root, task, premises, name, session_id):
if failure := run_worker(worker_args(task, name, session_id, resuming=session_open(session_id))):
if failure := run_worker(root, worker_args(task, name, session_id, resuming=session_open(session_id))):
return failure
path = session_file(session_id)
if not path:
sys.exit(f"claude left no transcript for session {session_id}")
verdict = judge(task, premises, render(entries(path)))
verdict = judge(root, task, premises, render(entries(path)))
while verdict["ask"]:
archive(root, path, f"Task: {task}\n\nVerdict: needs input\n\n{verdict['question']}")
if failure := interrupt(root, session_id, path, verdict["question"]):
print(failure, file=sys.stderr)
sys.exit(2)
verdict = judge(task, premises, render(entries(path)))
verdict = judge(root, task, premises, render(entries(path)))
if verdict["finished"]:
archive(root, path, f"Task: {task}\n\nVerdict: finished")
end_session(path)
@@ -377,7 +377,6 @@ def main():
print(__doc__.strip())
sys.exit(0 if task else 1)
root = checkout_root()
os.chdir(root)
while True:
reload_if_edited(task, cycle_number, failures)
cycle_number += 1