Exclude the loop's own prompts from human turns by promptSource sdk

This commit was merged in pull request #55.
This commit is contained in:
2026-09-26 13:28:18 +02:00
parent bd7a41a57b
commit 64a752c76b
+5 -4
View File
@@ -26,7 +26,8 @@ boundary, once the new file answers --help.
Claude Code internals this rests on, observed on 2.1.282:
- The transcript is ~/.claude/projects/*/<session-id>.jsonl, one JSON object per line. A <session-id>/
folder and <session-id>.superseded-*/ and .orphaned-*.jsonl siblings belong to the same session.
- Claude Code writes "user" entries of its own into the transcript; typed() tells a human's from them.
- Claude Code writes "user" entries of its own into the transcript, and a `claude -p` prompt lands as one
with promptSource "sdk"; typed() tells a human's from them.
- An "assistant" entry, in the transcript and in --output-format stream-json, carries message.content
parts of type "text" (text) and "tool_use" (name, input); stream-json ends with a "result" event.
- `claude -p --output-format json --json-schema` returns the verdict under "structured_output".
@@ -173,13 +174,13 @@ def render(entries):
lines += [line for part in entry.get("message", {}).get("content", []) if (line := said(part))]
elif typed(entry):
content = entry["message"]["content"]
lines.append("[human] " + (content if isinstance(content, str) else "".join(part["text"] for part in content)))
lines.append("[human] " + (content if isinstance(content, str) else "".join(part.get("text", "") for part in content)))
return "\n\n".join(lines)
def typed(entry):
"""A human turn: a "user" entry, not isMeta, whose message.content is a string not starting with "<" (<command-name> and its kind) or one or more text parts, none starting with "[Request interrupted"."""
if entry.get("type") != "user" or entry.get("isMeta"):
"""A human turn: a "user" entry, not isMeta, not promptSource "sdk" (the loop's own prompts), whose message.content is a string not starting with "<" (<command-name> and its kind) or one or more text parts, none starting with "[Request interrupted"."""
if entry.get("type") != "user" or entry.get("isMeta") or entry.get("promptSource") == "sdk":
return False
content = entry.get("message", {}).get("content")
if isinstance(content, str):