Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions src/core/task/Task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1941,10 +1941,22 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
}

switch (chunk.type) {
case "reasoning":
case "reasoning": {
reasoningMessage += chunk.text
await this.say("reasoning", reasoningMessage, undefined, true)
// Only apply formatting if the message contains sentence-ending punctuation followed by **
let formattedReasoning = reasoningMessage
if (reasoningMessage.includes("**")) {
// Add line breaks before **Title** patterns that appear after sentence endings
// This targets section headers like "...end of sentence.**Title Here**"
// Handles periods, exclamation marks, and question marks
formattedReasoning = reasoningMessage.replace(
/([.!?])\*\*([^*\n]+)\*\*/g,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix for reasoning block formatting – the regex /([.!?])\*\*([^*\n]+)\*\*/g inserts double newlines before bold headers following sentence-ending punctuation, which should improve readability. Consider extracting this formatting logic into a helper (e.g. formatReasoningMessage) for better testability and reuse. Also, the preliminary check if (reasoningMessage.includes("**")) may be redundant since the regex replace safely does nothing if no match is found.

This comment was generated because it violated a code review rule: irule_tTqpIuNs8DV0QFGj.

"$1\n\n**$2**",
)
}
await this.say("reasoning", formattedReasoning, undefined, true)
break
}
case "usage":
inputTokens += chunk.inputTokens
outputTokens += chunk.outputTokens
Expand Down Expand Up @@ -2238,7 +2250,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
// Note: updateApiReqMsg() is now called from within drainStreamInBackgroundToFindAllUsage
// to ensure usage data is captured even when the stream is interrupted. The background task
// uses local variables to accumulate usage data before atomically updating the shared state.
await this.persistGpt5Metadata(reasoningMessage)
await this.persistGpt5Metadata()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup! Since reasoning is now sent as separate blocks, removing the reasoningMessage parameter makes the code cleaner and more maintainable.

await this.saveClineMessages()
await this.providerRef.deref()?.postStateToWebview()

Expand Down Expand Up @@ -2824,10 +2836,11 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
}

/**
* Persist GPT-5 per-turn metadata (previous_response_id, instructions, reasoning_summary)
* Persist GPT-5 per-turn metadata (previous_response_id, instructions)
* onto the last complete assistant say("text") message.
* Note: reasoning_summary is no longer persisted as reasoning is now sent as separate delta blocks.
*/
private async persistGpt5Metadata(reasoningMessage?: string): Promise<void> {
private async persistGpt5Metadata(): Promise<void> {
try {
const modelId = this.api.getModel().id
if (!modelId || !modelId.startsWith("gpt-5")) return
Expand All @@ -2848,7 +2861,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
...(msg.metadata.gpt5 ?? {}),
previous_response_id: lastResponseId,
instructions: this.lastUsedInstructions,
reasoning_summary: (reasoningMessage ?? "").trim() || undefined,
// reasoning_summary is no longer stored as reasoning is sent as separate blocks
}
msg.metadata.gpt5 = gpt5Metadata
}
Expand Down
Loading