@@ -6,6 +6,10 @@ import { logError } from "./error-log.ts";
66 import { parseAppError } from "./error-parse.ts";
77 import { renderLine } from "./markdown.ts";
88 import { G, write, writeln } from "./output.ts";
9+import {
10+ normalizeReasoningDelta,
11+ normalizeReasoningText,
12+} from "./reasoning.ts";
913 import type { Spinner } from "./spinner.ts";
1014 import { renderToolCall, renderToolResult } from "./tool-render.ts";
1115
@@ -28,6 +32,7 @@ export async function renderTurn(
2832 let accumulatedReasoning = "";
2933
3034 let inFence = false;
35+ let reasoningBlankLineRun = 0;
3136
3237 let inputTokens = 0;
3338 let outputTokens = 0;
@@ -38,9 +43,20 @@ export async function renderTurn(
3843 // Defensive stop: some providers stream tiny chunks and spinner ticks can
3944 // interleave with stdout writes unless we stop right before each render.
4045 spinner.stop();
41- const rendered = renderLine(raw, inFence);
46+
47+ const source = inReasoning ? raw.replace(/[ \t]+$/g, "") : raw;
48+ if (inReasoning && source.trim() === "") {
49+ reasoningBlankLineRun += 1;
50+ if (reasoningBlankLineRun > 1) return;
51+ } else if (inReasoning) {
52+ reasoningBlankLineRun = 0;
53+ }
54+
55+ const rendered = renderLine(source, inFence);
4256 inFence = rendered.inFence;
43- const finalOutput = inReasoning ? c.dim(rendered.output) : rendered.output;
57+ const finalOutput = inReasoning
58+ ? `${c.dim("│ ")}${rendered.output}`
59+ : rendered.output;
4460 write(finalOutput);
4561 if (endWithNewline) {
4662 write("\n");
@@ -53,6 +69,7 @@ export async function renderTurn(
5369 writeln();
5470 inText = false;
5571 inReasoning = false;
72+ reasoningBlankLineRun = 0;
5673 }
5774 }
5875
@@ -91,7 +108,8 @@ export async function renderTurn(
91108 break;
92109 }
93110 case "reasoning-delta": {
94- accumulatedReasoning += event.delta;
111+ const delta = normalizeReasoningDelta(event.delta);
112+ accumulatedReasoning += delta;
95113 if (!showReasoning) {
96114 break;
97115 }
@@ -100,9 +118,10 @@ export async function renderTurn(
100118 flushAnyText();
101119 }
102120 spinner.stop();
121+ writeln(`${G.info} ${c.dim("reasoning")}`);
103122 inReasoning = true;
104123 }
105- rawBuffer += event.delta;
124+ rawBuffer += delta;
106125 flushCompleteLines();
107126 break;
108127 }
@@ -174,6 +193,6 @@ export async function renderTurn(
174193 outputTokens,
175194 contextTokens,
176195 newMessages,
177- reasoningText: accumulatedReasoning,
196+ reasoningText: normalizeReasoningText(accumulatedReasoning),
178197 };
179198 }