xonecas.io
64875
Mc

mini-coder / commit 8004205

fix: strip leading whitespace from assistant text to prevent empty/padded messages

Models sometimes emit text-delta events with leading newlines or
whitespace-only content. This caused:
- Empty-looking assistant messages (just the ◆ glyph)
- Excessive leading whitespace after the reply glyph

Changes:
- stream-render-content: trimStart() the first text delta when opening
  a new text block; skip if result is empty
- stream-render: use content.hasOpenContent() instead of raw delta
  truthiness for renderedVisibleOutput tracking

xonecas2026-03-16 80042053f09d8371968a5faa7f946a58a4185303 parent ac0f2c7

3 files changed

src/cli/stream-render-content.ts+3−1
@@ -27,9 +27,11 @@ export class StreamRenderContent {
2727 delta: string | undefined,
2828 renderedVisibleOutput: boolean,
2929 ): void {
30- const text = delta ?? "";
30+ let text = delta ?? "";
3131 if (!text) return;
3232 if (!this.inText) {
33+ text = text.trimStart();
34+ if (!text) return;
3335 this.spinner.stop();
3436 if (renderedVisibleOutput) writeln();
3537 write(`${G.reply} `);
src/cli/stream-render.test.ts+27−0
@@ -415,6 +415,33 @@ describe("renderTurn", () => {
415415 expect(strip(stdout)).toBe("◆ hello world\n");
416416 });
417417
418+ test("strips leading whitespace from the first text delta", async () => {
419+ captureStdout();
420+
421+ await renderTurn(
422+ eventsFrom([{ type: "text-delta", delta: "\n\n hello" }, done()]),
423+ new Spinner(),
424+ );
425+
426+ expect(simulateTerminal(stdout)).toBe("◆ hello\n");
427+ });
428+
429+ test("skips whitespace-only deltas before actual text content", async () => {
430+ captureStdout();
431+
432+ await renderTurn(
433+ eventsFrom([
434+ { type: "text-delta", delta: "\n\n" },
435+ { type: "text-delta", delta: " " },
436+ { type: "text-delta", delta: "\nhello" },
437+ done(),
438+ ]),
439+ new Spinner(),
440+ );
441+
442+ expect(simulateTerminal(stdout)).toBe("◆ hello\n");
443+ });
444+
418445 test("deduplicates repeated tool-call-start events for the same toolCallId", async () => {
419446 captureStdout();
420447
src/cli/stream-render.ts+1−1
@@ -50,7 +50,7 @@ export async function renderTurn(
5050 case "text-delta": {
5151 liveReasoning.finish();
5252 content.appendTextDelta(event.delta, renderedVisibleOutput);
53- if (event.delta) renderedVisibleOutput = true;
53+ if (content.hasOpenContent()) renderedVisibleOutput = true;
5454 break;
5555 }
5656 case "reasoning-delta": {