Skip to content

Commit bc58df8

Browse files
author
cellwebb
committed
fix(agent): preserve spaces while stripping only newlines for alignment
Previous fix used lstrip() which removed ALL leading whitespace, including spaces between words when streaming content chunk by chunk. This caused words to run together, e.g., 'test' + ' here' became 'testhere'. Now we only strip newline and carriage return characters (\n\r) while preserving spaces and other whitespace that are part of the actual content. This ensures: - Content appears on same line as [📎] header - Proper spacing between words is maintained - Only problematic leading newlines are removed for alignment Fixes the word spacing regression introduced in the alignment fix.
1 parent 8138528 commit bc58df8

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/clippy/agent/loop.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,16 +317,18 @@ def _process_streaming_response(
317317
# Handle streaming content deltas
318318
if chunk.get("delta") and chunk.get("content"):
319319
# Print the chunk directly for real-time display
320-
# Strip leading whitespace for display to prevent content appearing on wrong line
321-
display_content = chunk["content"].lstrip()
320+
# Strip only leading newlines to prevent content appearing on wrong line
321+
# but preserve other whitespace like spaces between words
322+
display_content = chunk["content"].lstrip('\n\r')
322323
console.print(escape(display_content), end="")
323324
accumulated_content += chunk["content"]
324325
elif chunk.get("content") and not chunk.get("delta"):
325326
# Final full content (for non-streaming models like codex)
326327
# Only print if we haven't already been streaming content
327328
if not accumulated_content:
328-
# Strip leading whitespace for display to prevent content appearing on wrong line
329-
display_content = chunk["content"].lstrip()
329+
# Strip only leading newlines to prevent content appearing on wrong line
330+
# but preserve other whitespace like spaces between words
331+
display_content = chunk["content"].lstrip('\n\r')
330332
console.print(escape(display_content), end="")
331333
accumulated_content = chunk["content"]
332334
elif not chunk.get("delta"):

0 commit comments

Comments
 (0)