@@ -79,15 +79,18 @@ export class StreamRenderContent {
7979
8080 if (this.rawBuffer) {
8181 this.spinner.stop();
82- const out = this.renderSingleLine(this.rawBuffer);
82+ const raw = this.rawBuffer;
83+ const out = this.renderSingleLine(raw);
8384 this.rawBuffer = "";
8485 if (this.partialPreview.partialWritten > 0) {
85- const clearSeq = buildClearPartialPreview(
86- this.partialPreview,
87- terminal.stdoutColumns,
88- );
89- if (out !== null) write(`${clearSeq}${this.styledPrefix}${out}`);
90- else write(clearSeq);
86+ if (!this.canKeepStreamedPartial(raw, out)) {
87+ const clearSeq = buildClearPartialPreview(
88+ this.partialPreview,
89+ terminal.stdoutColumns,
90+ );
91+ if (out !== null) write(`${clearSeq}${this.styledPrefix}${out}`);
92+ else write(clearSeq);
93+ }
9194 } else if (out !== null) {
9295 write(out);
9396 }
@@ -101,6 +104,14 @@ export class StreamRenderContent {
101104 this.resetLineState();
102105 }
103106
107+ private canKeepStreamedPartial(raw: string, out: string | null): boolean {
108+ return (
109+ this.inText &&
110+ out === raw &&
111+ this.partialPreview.partialWritten === raw.length
112+ );
113+ }
114+
104115 private renderSingleLine(raw: string): string | null {
105116 const source = this.inReasoning ? raw.replace(/[ \t]+$/g, "") : raw;
106117 if (this.inReasoning && source.trim() === "") {
@@ -138,13 +149,19 @@ export class StreamRenderContent {
138149
139150 const out = this.renderSingleLine(raw);
140151 if (firstLine && this.partialPreview.partialWritten > 0) {
141- const clearSeq = buildClearPartialPreview(
142- this.partialPreview,
143- terminal.stdoutColumns,
144- );
145- if (out !== null)
146- batchOutput += `${clearSeq}${this.styledPrefix}${out}\n`;
147- else batchOutput += `${clearSeq}\n`;
152+ if (this.canKeepStreamedPartial(raw, out)) {
153+ batchOutput += "\n";
154+ } else {
155+ const clearSeq = buildClearPartialPreview(
156+ this.partialPreview,
157+ terminal.stdoutColumns,
158+ );
159+ if (out !== null) {
160+ batchOutput += `${clearSeq}${this.styledPrefix}${out}\n`;
161+ } else {
162+ batchOutput += `${clearSeq}\n`;
163+ }
164+ }
148165 } else if (out !== null) {
149166 batchOutput += `${out}\n`;
150167 }