Skip to content

fix: preserve line breaks in thinking output#144

Closed
Huarong wants to merge 2 commits intoopenclaw:mainfrom
Huarong:codex/preserve-thinking-newlines
Closed

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

Conversation

@Huarong
Copy link
Copy Markdown
Contributor

@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

@dutifulbob
Copy link
Copy Markdown
Collaborator

Triage result

Human attention: ⚠️ Required
Recommendation: 🏁 escalate to a human
Human decision needed: ready for human landing decision

Quick read

PR intent: preserve multi-line [thinking] output in text mode instead of flattening agent_thought_chunk content into one line.
Status: the solution is right-shaped, targeted validation reproduced the regression and verified the fix, Codex review is clear, CI is green, and the final conflict check is clean.

Intent

Make the text-mode CLI output preserve multi-line agent thinking exactly enough to stay readable, instead of flattening it into one line.

Why

agent_thought_chunk text is currently passed through whitespace-collapsing formatting, so line breaks and blank lines turn into spaces and structured reasoning becomes hard to read. This PR updates the implicated flushThoughtBuffer() path in src/output.ts to preserve normalized newlines and adds a regression test in test/output.test.ts.

Codex review

No GitHub Codex review findings were collected for the current head. The established local Codex review reported no discrete correctness issue that would warrant a follow-up fix.

Targeted validation reproduced and confirmed the fix:

  • Passed on the PR head.
  • Failed after local-only ablation of the non-test code change.
  • Passed again after restoring the PR branch state.

CI/CD

The initial CI workflow run was approval-blocked with action_required. Workflow approval was attempted and succeeded. The rerun of workflow 23142640688 completed successfully with all relevant jobs green. Initial and final conflict checks against origin/main were both clean.

Recommendation

This PR is ready for human landing decision. If the change aligns with maintainer expectations for text-mode thought rendering, it can proceed through normal human review and landing.

@osolmaz osolmaz self-assigned this Mar 29, 2026
osolmaz added a commit to Huarong/acpx that referenced this pull request Mar 29, 2026
@osolmaz osolmaz force-pushed the codex/preserve-thinking-newlines branch from 8c115ef to 7858125 Compare March 29, 2026 09:33
@osolmaz osolmaz closed this in #194 Mar 29, 2026
osolmaz added a commit that referenced this pull request Mar 29, 2026
* fix: preserve line breaks in thinking output

* docs(changelog): note thinking output line-break fix (#144)

---------

Co-authored-by: huohuarong <huohuarong@zuoshouyisheng.com>
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.

3 participants