xonecas.io
64875
Mc

mini-coder / commit 7c0fb09

fix(ui): preserve markdown continuity and preview alignment

xonecas2026-04-12 7c0fb09317a00a613b746cc61140e0fd52550e49 parent 04ecf26

2 files changed

src/ui/conversation.test.ts+74−0
@@ -302,6 +302,49 @@ describe("ui/conversation", () => {
302302 ).toBe(true);
303303 });
304304
305+ test("renderAssistantMessage with adjacent text blocks preserves markdown structure across the block boundary", async () => {
306+ // Arrange
307+ const singleBlock = {
308+ content: [fauxText("```js\nconst x = 1;\n```")],
309+ };
310+ const splitBlocks = {
311+ content: [fauxText("```js\n"), fauxText("const x = 1;\n```")],
312+ };
313+
314+ // Act
315+ const singleRows = await renderBufferRows(
316+ renderAssistantMessage(singleBlock, RENDER_OPTS),
317+ 40,
318+ 12,
319+ );
320+ const splitRows = await renderBufferRows(
321+ renderAssistantMessage(splitBlocks, RENDER_OPTS),
322+ 40,
323+ 12,
324+ );
325+ const singleHeight = measureRenderedHeight(
326+ renderAssistantMessage(singleBlock, RENDER_OPTS),
327+ 40,
328+ );
329+ const splitHeight = measureRenderedHeight(
330+ renderAssistantMessage(splitBlocks, RENDER_OPTS),
331+ 40,
332+ );
333+ const singleRow = singleRows.find((row) =>
334+ row.text.includes("const x = 1;"),
335+ );
336+ const splitRow = splitRows.find((row) => row.text.includes("const x = 1;"));
337+
338+ // Assert
339+ expect(singleRow).toBeDefined();
340+ expect(splitRow).toBeDefined();
341+ expect(singleHeight).toBe(splitHeight);
342+ expect(singleRow?.fgColors[singleRow.text.indexOf("const")]).not.toBe(null);
343+ expect(splitRow?.fgColors[splitRow.text.indexOf("const")]).toBe(
344+ singleRow?.fgColors[singleRow.text.indexOf("const")],
345+ );
346+ });
347+
305348 test("buildConversationLogNodes with a pending shell result keeps the streamed call and result append-only", () => {
306349 // Arrange
307350 const pendingToolResults: PendingToolResult[] = [
@@ -1018,6 +1061,37 @@ describe("ui/conversation", () => {
10181061 expect(text).not.toContain("seq 1 25");
10191062 });
10201063
1064+ test("renderToolResult for a wrapped shell preview keeps the summary directly below the visible tail", async () => {
1065+ // Arrange
1066+ const output = [
1067+ "line 1",
1068+ "line 2",
1069+ "line 3",
1070+ "line 4",
1071+ "this is a very long wrapped line that will take more than six rendered rows in the preview width so it gets dropped entirely",
1072+ "tail A",
1073+ "tail B",
1074+ ].join("\n");
1075+
1076+ // Act
1077+ const rows = await renderBufferRows(
1078+ renderToolResult("shell", { command: "demo" }, output, false, {
1079+ ...RENDER_OPTS,
1080+ previewWidth: 24,
1081+ }),
1082+ 24,
1083+ 20,
1084+ );
1085+ const tailRowIndex = rows.findIndex((row) => row.text.includes("tail B"));
1086+ const summaryRowIndex = rows.findIndex(
1087+ (row) => row.text.includes("And ") && row.text.includes(" lines more"),
1088+ );
1089+
1090+ // Assert
1091+ expect(tailRowIndex).toBeGreaterThan(-1);
1092+ expect(summaryRowIndex).toBe(tailRowIndex + 1);
1093+ });
1094+
10211095 test("renderToolResult for shell output in verbose mode shows the full stored output", () => {
10221096 // Arrange
10231097 const output = Array.from({ length: 25 }, (_, i) => `line ${i + 1}`).join(
src/ui/conversation.ts+28−1
@@ -282,6 +282,32 @@ function renderThinkingBlock(
282282 ]);
283283 }
284284
285+function coalesceAdjacentTextBlocks(
286+ content: AssistantMessage["content"],
287+): AssistantMessage["content"] {
288+ const coalesced: AssistantMessage["content"] = [];
289+
290+ for (const block of content) {
291+ if (block.type !== "text") {
292+ coalesced.push(block);
293+ continue;
294+ }
295+
296+ const previous = coalesced.at(-1);
297+ if (previous?.type === "text") {
298+ coalesced[coalesced.length - 1] = {
299+ ...previous,
300+ text: previous.text + block.text,
301+ };
302+ continue;
303+ }
304+
305+ coalesced.push({ ...block });
306+ }
307+
308+ return coalesced;
309+}
310+
285311 function renderAssistantContentBlock(
286312 block: AssistantMessage["content"][number],
287313 opts: ConversationRenderOpts,
@@ -309,7 +335,7 @@ export function renderAssistantMessage(
309335 assistant: AssistantMessage | AssistantRenderState,
310336 opts: ConversationRenderOpts,
311337 ): Node | null {
312- const children = assistant.content
338+ const children = coalesceAdjacentTextBlocks(assistant.content)
313339 .map((block) => {
314340 return renderAssistantContentBlock(block, opts);
315341 })
@@ -694,6 +720,7 @@ function renderToolBodyFromNodes(
694720 body: VStack(
695721 {
696722 height: UI_TOOL_PREVIEW_ROWS,
723+ justifyContent: "end",
697724 },
698725 [...previewLines],
699726 ),