xonecas.io
64875
Mc

mini-coder / commit dc69057

fix(cli): address code review feedback on stream-render.ts

xonecas2026-03-09 dc690573064fc4f8db334a8974d649bb946f6b54 parent 6c910ac

1 file changed

src/cli/stream-render.ts+31−16
@@ -18,6 +18,7 @@ export async function renderTurn(
1818 newMessages: CoreMessage[];
1919 }> {
2020 let inText = false;
21+ let inReasoning = false;
2122 let rawBuffer = "";
2223 let inFence = false;
2324
@@ -29,12 +30,22 @@ export async function renderTurn(
2930 function renderAndWrite(raw: string, endWithNewline: boolean): void {
3031 const rendered = renderLine(raw, inFence);
3132 inFence = rendered.inFence;
32- write(rendered.output);
33+ const finalOutput = inReasoning ? c.dim(rendered.output) : rendered.output;
34+ write(finalOutput);
3335 if (endWithNewline) {
3436 write("\n");
3537 }
3638 }
3739
40+ function flushAnyText(): void {
41+ if (inText || inReasoning) {
42+ flushAll();
43+ writeln();
44+ inText = false;
45+ inReasoning = false;
46+ }
47+ }
48+
3849 function flushCompleteLines(): void {
3950 let boundary = rawBuffer.indexOf("\n");
4051 while (boundary !== -1) {
@@ -55,6 +66,9 @@ export async function renderTurn(
5566 for await (const event of events) {
5667 switch (event.type) {
5768 case "text-delta": {
69+ if (inReasoning) {
70+ flushAnyText();
71+ }
5872 if (!inText) {
5973 spinner.stop();
6074 write(`${G.reply} `);
@@ -64,13 +78,22 @@ export async function renderTurn(
6478 flushCompleteLines();
6579 break;
6680 }
81+ case "reasoning-delta": {
82+ if (!inReasoning) {
83+ if (inText) {
84+ flushAnyText();
85+ }
86+ spinner.stop();
87+ write(`${c.dim("Thinking...")}\n`);
88+ inReasoning = true;
89+ }
90+ rawBuffer += event.delta;
91+ flushCompleteLines();
92+ break;
93+ }
6794
6895 case "tool-call-start": {
69- if (inText) {
70- flushAll();
71- writeln();
72- inText = false;
73- }
96+ flushAnyText();
7497 spinner.stop();
7598 renderToolCall(event.toolName, event.args);
7699 spinner.start(event.toolName);
@@ -85,11 +108,7 @@ export async function renderTurn(
85108 }
86109
87110 case "turn-complete": {
88- if (inText) {
89- flushAll();
90- writeln();
91- inText = false;
92- }
111+ flushAnyText();
93112 spinner.stop();
94113 inputTokens = event.inputTokens;
95114 outputTokens = event.outputTokens;
@@ -99,11 +118,7 @@ export async function renderTurn(
99118 }
100119
101120 case "turn-error": {
102- if (inText) {
103- flushAll();
104- writeln();
105- inText = false;
106- }
121+ flushAnyText();
107122 spinner.stop();
108123 const isAbort =
109124 event.error.name === "AbortError" ||