Join a human entry's text where it is classified

This commit is contained in:
2026-09-28 21:17:59 +02:00
parent 089d8fa1dc
commit 194601aeda
3 changed files with 14 additions and 11 deletions
+10 -5
View File
@@ -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"}