diff --git a/packages/coding-agent/test/transcript-streaming-commit-repro.test.ts b/packages/coding-agent/test/transcript-streaming-commit-repro.test.ts index 2fd6f8b46..d4896913b 100644 --- a/packages/coding-agent/test/transcript-streaming-commit-repro.test.ts +++ b/packages/coding-agent/test/transcript-streaming-commit-repro.test.ts @@ -219,4 +219,19 @@ describe("transcript streaming commit (assistant text)", () => { expect(codeRow).toBeGreaterThanOrEqual(0); expect(rows.slice(codeRow, codeRow + 3)).toEqual([" +a", "", " +streaming"]); }); + + it("does not duplicate a leading blank row when the streamed diff grows", () => { + const block = new StreamingMarkdownBlock(); + + block.setStreamingText("```diff\n\n+partial"); + block.render(40); + + block.setStreamingText("```diff\n\n+done\n-streaming"); + + const rows = block.render(40).map(row => Bun.stripANSI(row).trimEnd()); + const fenceRow = rows.indexOf("```diff"); + + expect(fenceRow).toBeGreaterThanOrEqual(0); + expect(rows.slice(fenceRow, fenceRow + 5)).toEqual(["```diff", "", " +done", " -streaming", "```"]); + }); }); diff --git a/packages/tui/src/components/markdown.ts b/packages/tui/src/components/markdown.ts index 9d87eac21..67789a496 100644 --- a/packages/tui/src/components/markdown.ts +++ b/packages/tui/src/components/markdown.ts @@ -1499,7 +1499,7 @@ export class Markdown implements Component { ) { if (completedText.length === cache.text.length) return cache.lines; const lines = cache.lines.slice(); - const addedText = completedText.slice(cache.text.length === 0 ? 0 : cache.text.length + 1); + const addedText = completedText.slice(cache.text.length + 1); for (const codeLine of addedText.split("\n")) { lines.push(...highlightCode(codeLine, lang)); }