From 194601aeda5e213980f203904a82d3a019309ba8 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 28 Sep 2026 21:17:59 +0200 Subject: [PATCH] Join a human entry's text where it is classified --- bin/loop_claude/claude_code.py | 15 ++++++++++----- bin/loop_claude/transcript.py | 9 ++++----- todo.md | 1 - 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/bin/loop_claude/claude_code.py b/bin/loop_claude/claude_code.py index 527a9a68..bb762c8e 100644 --- a/bin/loop_claude/claude_code.py +++ b/bin/loop_claude/claude_code.py @@ -70,19 +70,24 @@ def user_entry_kind(entry): if isinstance(text := content(entry), str): source = entry.get("promptSource") return UserEntryKind.COMMAND if source == "system" or (source != "typed" and text.startswith("<")) else UserEntryKind.HUMAN - if not parts(entry): + texts = [part_text(part) for part in parts(entry)] + if not texts: return UserEntryKind.EMPTY # {"type": "user", "message": {"content": [{"tool_use_id": "toolu_01…", "type": "tool_result", "content": "hi"}]}} - if any(not isinstance(part, dict) or part.get("type") != "text" or not isinstance(part.get("text"), str) for part in parts(entry)): + if None in texts: return UserEntryKind.NON_TEXT # {"type": "user", "message": {"content": [{"type": "text", "text": "[Request interrupted by user]"}]}} - if any(part["text"].startswith("[Request interrupted") for part in parts(entry)): + if any(text.startswith("[Request interrupted") for text in texts): return UserEntryKind.CTRL_C return UserEntryKind.HUMAN -def typed(entry): - return entry.get("type") == "user" and user_entry_kind(entry) is UserEntryKind.HUMAN +def human_text(entry): + """What the human wrote in the entry, or None where Claude Code wrote it.""" + 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)) # {"type": "text", "text": "ok"} diff --git a/bin/loop_claude/transcript.py b/bin/loop_claude/transcript.py index 50cb7b99..36727ec6 100644 --- a/bin/loop_claude/transcript.py +++ b/bin/loop_claude/transcript.py @@ -1,6 +1,6 @@ import json -from loop_claude.claude_code import assistant_parts, content, parse, part_text, tool_call, typed +from loop_claude.claude_code import assistant_parts, human_text, parse, part_text, tool_call from loop_claude.outcome import Failure @@ -13,16 +13,15 @@ def read(path): def human_turns(entries): - return sum(1 for entry in entries if typed(entry)) + return sum(1 for entry in entries if human_text(entry) is not None) def render(entries): lines = [] for entry in entries: lines += [line for part in assistant_parts(entry) if (line := said(part))] - if typed(entry): - text = content(entry) - lines.append("[human] " + (text if isinstance(text, str) else "".join(part["text"] for part in text))) + if (text := human_text(entry)) is not None: + lines.append("[human] " + text) return "\n\n".join(lines) diff --git a/todo.md b/todo.md index c4bf5e6e..d5838e26 100644 --- a/todo.md +++ b/todo.md @@ -8,7 +8,6 @@ The rebuild lifts every dimension: each item below is one chunk on a worktree ba The places the panel on `rebuild` at 37edc9a named (`docs/decisions.md`), capping dimension first: -- **Let `render` join a human entry's text without relying on `user_entry_kind` having checked every part.** Three seats. - **Give failure one spelling: `Failure.reason` and `Retry.failure`, `replace_file`'s raw `OSError`, and `typed`/`said` named for what they test.** Keep `LoopState`'s fields: they are main's `--reloaded` state (`docs/decisions.md`). - **Group `bin/loop_claude/`'s 18 flat modules, and move `principles/review-findings.md` beside larv-review.** Two seats; `claude_code.py` is the first group. - **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.