Skip to content

Commit 9dabb85

Browse files
authored
Fix: Improve reasoning block formatting for better readability (#7868)
1 parent 0e1b23d commit 9dabb85

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/core/task/Task.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,10 +1944,22 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
19441944
}
19451945

19461946
switch (chunk.type) {
1947-
case "reasoning":
1947+
case "reasoning": {
19481948
reasoningMessage += chunk.text
1949-
await this.say("reasoning", reasoningMessage, undefined, true)
1949+
// Only apply formatting if the message contains sentence-ending punctuation followed by **
1950+
let formattedReasoning = reasoningMessage
1951+
if (reasoningMessage.includes("**")) {
1952+
// Add line breaks before **Title** patterns that appear after sentence endings
1953+
// This targets section headers like "...end of sentence.**Title Here**"
1954+
// Handles periods, exclamation marks, and question marks
1955+
formattedReasoning = reasoningMessage.replace(
1956+
/([.!?])\*\*([^*\n]+)\*\*/g,
1957+
"$1\n\n**$2**",
1958+
)
1959+
}
1960+
await this.say("reasoning", formattedReasoning, undefined, true)
19501961
break
1962+
}
19511963
case "usage":
19521964
inputTokens += chunk.inputTokens
19531965
outputTokens += chunk.outputTokens

0 commit comments

Comments
 (0)