Skip to content

fix: preserve line breaks in thinking output#144

Open
Huarong wants to merge 1 commit intoopenclaw:mainfrom
Huarong:codex/preserve-thinking-newlines
Open

fix: preserve line breaks in thinking output#144
Huarong wants to merge 1 commit intoopenclaw:mainfrom
Huarong:codex/preserve-thinking-newlines

Conversation

@Huarong
Copy link

@Huarong Huarong commented Mar 16, 2026

Summary

This change preserves line breaks in text-mode thinking output instead of collapsing all whitespace into a single line.

Problem

agent_thought_chunk content is currently rendered through collapseWhitespace(...), which flattens \n into spaces before printing. This makes multi-line reasoning hard to read and loses structure that agents intentionally send.

Changes

  • preserve \n when flushing buffered thought text
  • normalize CRLF to LF before rendering
  • render multi-line thought output as a [thinking] block instead of a single flattened line
  • add a regression test covering blank lines and line breaks in thought chunks

Why this should be separate

This PR only fixes formatting/readability. It does not change when thought chunks are emitted.

Testing

  • ./node_modules/.bin/tsc -p tsconfig.test.json
  • node --test dist-test/test/output.test.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant