mirror of
https://github.com/instructkr/claw-code.git
synced 2026-10-28 00:05:50 +08:00
Fixes #3259: When rendering markdown in streaming mode, block-level elements (code blocks, lists, tables, etc.) were losing trailing newlines due to render_markdown() calling trim_end(). This caused improper spacing when chunks were split at block boundaries. Solution: - Track last_output_ends_with_newline in MarkdownStreamState to detect when previous output ended without proper spacing - In push(): add leading newlines before block elements if previous chunk didn't end with newlines - In push(): restore trailing newlines after code block/table closings that were trimmed by render_markdown() - Add ensure_newlines() helper to prepare spacing before block starts - Add comprehensive streaming tests that verify idempotence across all possible chunk split positions This ensures that streaming renders produce byte-identical output regardless of where the input is split into chunks, which is critical for displaying markdown as it arrives from the API while maintaining proper formatting.