Require every verdict field, treat an interrupted handoff as unanswered, and tighten the --help contract
This commit is contained in:
@@ -26,7 +26,7 @@ Test: `python3 -m unittest bin/test_loop_claude.py`
|
||||
|
||||
## Tracking a new file
|
||||
|
||||
`.gitignore` is an allowlist: everything is ignored, and a file is tracked only by being named. Add it as a negation, with its parent directories un-ignored too, then confirm with `git check-ignore -v <path>`:
|
||||
`.gitignore` is an allowlist. Track a file by negating it and its parent directories, then confirm with `git check-ignore -v <path>`:
|
||||
|
||||
```
|
||||
!docs/
|
||||
|
||||
+14
-10
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Run a task as headless claude rounds; a judge stops the loop only when a decision is the human's.
|
||||
"""Run a task as headless claude rounds; a judge interrupts only when a decision is the human's.
|
||||
|
||||
usage: loop-claude <task>
|
||||
|
||||
@@ -8,14 +8,15 @@ the task; a judge then reads the transcript against the README. A question only
|
||||
opens `claude --resume` on the terminal. An unfinished chunk resumes the same session next round; a
|
||||
finished one starts a fresh session. Rounds continue until Ctrl-C.
|
||||
|
||||
Exit 1: the README gate blocks, or claude fails three rounds running. Exit 2: the human is needed and
|
||||
no terminal is attached, or the handoff ended without them typing anything.
|
||||
Exit 1: no task, the README gate blocks, claude leaves no transcript, or claude fails three rounds
|
||||
running. Exit 2: the human is needed and no terminal is attached, or the handoff ended without them
|
||||
typing anything. Before a handoff every worktree is marked trusted in ~/.claude.json.
|
||||
|
||||
Each project has one session, "A ~/code/<path> auto-mode", at an id derived from that name; it is
|
||||
Each project has one session, "A ~/code/<path> auto-mode" (the absolute path outside ~/code),
|
||||
resumed while present and deleted when the chunk finishes. Its transcript is archived under
|
||||
$AUTO_MODE_TRANSCRIPTS (default ~/.claude/auto-mode-transcripts/<path>/) whenever the human is asked
|
||||
and when the chunk finishes. JUDGE_MODEL and WORKER_MODEL override the models. A change to this
|
||||
file takes effect at the next round boundary.
|
||||
and when the chunk finishes. JUDGE_MODEL and WORKER_MODEL override the models (default
|
||||
claude-opus-5-5). A change to this file takes effect at the next round boundary.
|
||||
"""
|
||||
import glob
|
||||
import json
|
||||
@@ -159,7 +160,7 @@ def human_turns(entries):
|
||||
content = entry.get("message", {}).get("content")
|
||||
if isinstance(content, str) and not content.startswith("<"):
|
||||
spoken += 1
|
||||
elif isinstance(content, list) and not any(part.get("type") == "tool_result" for part in content if isinstance(part, dict)):
|
||||
elif isinstance(content, list) and not any(said(part) == "" or said(part).startswith("[Request interrupted") for part in content):
|
||||
spoken += 1
|
||||
return spoken
|
||||
|
||||
@@ -188,7 +189,6 @@ def checkouts():
|
||||
|
||||
|
||||
def trust(paths):
|
||||
# No CLI flag skips the trust dialog, and the interactive resume would stall on it in every worktree the round created.
|
||||
config = os.path.expanduser("~/.claude.json")
|
||||
try:
|
||||
data = json.load(open(config, encoding="utf-8"))
|
||||
@@ -221,7 +221,7 @@ def worker_args(task, name, session_id, resuming):
|
||||
"--output-format", "stream-json",
|
||||
"--permission-mode", "bypassPermissions",
|
||||
"--verbose",
|
||||
*(["--model", WORKER_MODEL] if WORKER_MODEL else []),
|
||||
"--model", WORKER_MODEL,
|
||||
]
|
||||
|
||||
|
||||
@@ -248,6 +248,10 @@ def judge_prompt(task, premises, transcript):
|
||||
)
|
||||
|
||||
|
||||
def complete(verdict):
|
||||
return isinstance(verdict, dict) and set(JUDGE_SCHEMA["required"]) <= verdict.keys()
|
||||
|
||||
|
||||
def grounded(verdict, transcript):
|
||||
return not verdict["ask"] or bool(verdict["evidence"]) and verdict["evidence"] in transcript
|
||||
|
||||
@@ -265,7 +269,7 @@ def judge(task, premises, transcript):
|
||||
for attempt in range(2):
|
||||
proc = subprocess.run(["claude", *args], capture_output=True, input=judge_prompt(task, premises, transcript), text=True)
|
||||
verdict = (parse(proc.stdout) or {}).get("structured_output") if proc.returncode == 0 else None
|
||||
if not isinstance(verdict, dict) or "ask" not in verdict:
|
||||
if not complete(verdict):
|
||||
print(proc.stderr.strip() or "the judge returned no verdict", file=sys.stderr)
|
||||
return {}
|
||||
if grounded(verdict, transcript):
|
||||
|
||||
@@ -48,6 +48,7 @@ class HumanTurns(unittest.TestCase):
|
||||
human([{"type": "tool_result", "content": "not typed"}]),
|
||||
human("<command-name>/model</command-name>"),
|
||||
{**human("peer message"), "isMeta": True},
|
||||
human([{"type": "text", "text": "[Request interrupted by user]"}]),
|
||||
assistant({"type": "text", "text": "said"}),
|
||||
]), 2)
|
||||
|
||||
@@ -122,5 +123,12 @@ class Grounded(unittest.TestCase):
|
||||
self.assertFalse(loop.grounded({"ask": True, "evidence": ""}, "the transcript"))
|
||||
|
||||
|
||||
class Verdict(unittest.TestCase):
|
||||
def test_needs_every_field_the_schema_requires(self):
|
||||
self.assertTrue(loop.complete({"ask": False, "evidence": "", "finished": True, "question": ""}))
|
||||
self.assertFalse(loop.complete({"ask": False}))
|
||||
self.assertFalse(loop.complete(None))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
|
||||
## loop-claude: one session per project, at a fixed id
|
||||
|
||||
2026-09-21, lilleman. Serves goal 4. The id is uuid5 of the session name under the script's own namespace, so the session picker holds one entry per project and any transcript under that id is the script's own: resumed while present, deleted when the chunk finishes. Valid while the picker lists sessions by id.
|
||||
2026-09-21, lilleman. Serves goal 4. One fixed id per project keeps the session picker at one entry per project and makes any transcript under that id the script's own to delete. Valid while the picker lists sessions by id.
|
||||
|
||||
## loop-claude: the trust file is rewritten before a handoff
|
||||
|
||||
|
||||
Reference in New Issue
Block a user