feat(markdown): thinking blocks between hidden tool calls collapse to the first one

This commit is contained in:
hh
2026-09-02 01:44:02 +02:00
parent 2d34d488d7
commit 7a8ee0f200
2 changed files with 24 additions and 2 deletions
@@ -48,14 +48,19 @@ def render_assistant_text(text: str) -> str:
def render_assistant_message(message: Message) -> str:
"""Render an assistant ``Message`` into a turn block.
Tool-use blocks render to nothing; only text and thinking content reach
the file (see :mod:`.parser` for how the reverse strip works).
Tool-use blocks render to nothing; of the thinking blocks between two
texts only the first one reaches the file.
"""
parts: list[str] = ["### Assistant:", ""]
after_thinking = False
for block in message.content:
thinking = isinstance(block, ThinkingBlock)
if thinking and after_thinking:
continue
lines = list(_render_block(block))
if not lines:
continue
after_thinking = thinking
parts.extend(lines)
parts.append("")
return "\n".join(parts).rstrip() + "\n"