diff --git a/CHANGELOG.md b/CHANGELOG.md index db65e201..060aa525 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,5 +10,6 @@ - `loop-claude`'s judge quotes the transcript for every verdict, and a verdict quoting nothing or interrupting without a question, or a `claude` the judge cannot start, is a failed judge run; a `claude` that cannot start for an interrupt exits 1. - `loop-claude`'s exit-2 message says what the human is needed for. - `loop-claude` counts an interrupt reply starting with `<` as typed. +- `loop-claude`'s judge sees a reply the human types while claude works, and an interrupt counts one as typed. - `loop-claude`'s archive holds the raw `.jsonl` transcript, one copy per distinct transcript, named by its SHA-256, with the verdict beside it in `.verdict.md`; a transcript it cannot archive exits 1. - `loop-claude` keeps the mode of `~/.claude.json` and of its models file when it rewrites them, and creates the models file 0600. diff --git a/bin/loop_claude/claude_code/formats.py b/bin/loop_claude/claude_code/formats.py index bb762c8e..33692f71 100644 --- a/bin/loop_claude/claude_code/formats.py +++ b/bin/loop_claude/claude_code/formats.py @@ -84,12 +84,23 @@ def user_entry_kind(entry): def human_text(entry): """What the human wrote in the entry, or None where Claude Code wrote it.""" + if (queued := queued_human_text(entry)) is not None: + return queued if entry.get("type") != "user" or user_entry_kind(entry) is not UserEntryKind.HUMAN: return None text = content(entry) return text if isinstance(text, str) else "".join(part_text(part) or "" for part in parts(entry)) +# What the human types while claude works, written only as this entry: +# {"type": "attachment", "attachment": {"type": "queued_command", "commandMode": "prompt", "origin": {"kind": "human"}, "prompt": "B"}} +def queued_human_text(entry): + attachment = entry.get("attachment") if entry.get("type") == "attachment" else None + if not isinstance(attachment, dict) or attachment.get("type") != "queued_command" or not isinstance(origin := attachment.get("origin"), dict) or origin.get("kind") != "human": + return None + return prompt if isinstance(prompt := attachment.get("prompt"), str) else None + + # {"type": "text", "text": "ok"} def part_text(part): return part["text"] if isinstance(part, dict) and part.get("type") == "text" and isinstance(part.get("text"), str) else None diff --git a/bin/test_loop_claude.py b/bin/test_loop_claude.py index 28674499..37879d6c 100644 --- a/bin/test_loop_claude.py +++ b/bin/test_loop_claude.py @@ -24,6 +24,10 @@ def human(content): return {"type": "user", "message": {"content": content}} +def queued(prompt, kind): + return {"type": "attachment", "attachment": {"type": "queued_command", "commandMode": "prompt", "origin": {"kind": kind}, "prompt": prompt}} + + class Sections(unittest.TestCase): def test_keeps_every_headed_section_with_its_bodies(self): text = "# Title\n\nintro\n\n## Goals\n\n1. one\n```sh\n# not a heading\n```\n### Later\n2. two\n#1 priority\n\n## Empty\n\n## Audience\nme\n## Audience\nagain\n# Appendix\nnot audience\n" @@ -39,9 +43,11 @@ class Render(unittest.TestCase): human([{"type": "tool_result", "content": "not typed"}]), human("/exit"), human([{"type": "text", "text": "yes, "}, {"type": "text", "text": "merge it"}]), + queued("B, while you work", "human"), + queued("origin/main moved", "coordinator"), {**human("Continue the task; the previous run stopped before it was finished."), "promptSource": "sdk"}, ]) - self.assertEqual(said, '[human] do it\n\nStarting.\n\n[tool Bash] {"command": "ls"}\n\n[human] yes, merge it') + self.assertEqual(said, '[human] do it\n\nStarting.\n\n[tool Bash] {"command": "ls"}\n\n[human] yes, merge it\n\n[human] B, while you work') class HumanTurns(unittest.TestCase): @@ -57,8 +63,11 @@ class HumanTurns(unittest.TestCase): {**human("the loop's own prompt"), "promptSource": "sdk"}, human([{"type": "text", "text": "[Request interrupted by user]"}]), human([]), + queued("typed while claude worked", "human"), + queued("done", "task-notification"), + {"type": "attachment", "attachment": {"type": "queued_command", "commandMode": "task-notification", "prompt": "done"}}, assistant({"type": "text", "text": "said"}), - ]), 3) + ]), 4) class PartLine(unittest.TestCase): diff --git a/todo.md b/todo.md index b9af9e2d..bad154ac 100644 --- a/todo.md +++ b/todo.md @@ -8,7 +8,6 @@ The rebuild lifts every dimension, one chunk per item, until the last item opens The places the panel on `rebuild` at 37edc9a named (`docs/decisions.md`), capping dimension first: -- **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. ## 0.2.0