-
Couldn't load subscription status.
- Fork 2.3k
Fix: Improve reasoning block formatting for better readability #7868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice fix for reasoning block formatting – the regex This comment was generated because it violated a code review rule: irule_tTqpIuNs8DV0QFGj. |
||
| "$1\n\n**$2**", | ||
| ) | ||
| } | ||
| await this.say("reasoning", formattedReasoning, undefined, true) | ||
daniel-lxs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| break | ||
| } | ||
| case "usage": | ||
| inputTokens += chunk.inputTokens | ||
| outputTokens += chunk.outputTokens | ||
|
|
@@ -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() | ||
|
||
| await this.saveClineMessages() | ||
| await this.providerRef.deref()?.postStateToWebview() | ||
|
|
||
|
|
@@ -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 | ||
|
|
@@ -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 | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.