From 059316cbac839dfb438f3e2e9735c3b3b9bf7817 Mon Sep 17 00:00:00 2001 From: Miguel Palhas Date: Sun, 6 Sep 2026 22:21:19 +0100 Subject: [PATCH] fix(web): normalize structured thought rows --- web/src/structuredRender.test.ts | 11 ++++++++--- web/src/structuredRender.ts | 9 +++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/web/src/structuredRender.test.ts b/web/src/structuredRender.test.ts index b85a388..d1fbec6 100644 --- a/web/src/structuredRender.test.ts +++ b/web/src/structuredRender.test.ts @@ -40,10 +40,15 @@ describe("buildTranscriptRow: user/agent/thought", () => { expect(ps[0].innerHTML).toContain("three"); }); - it("renders a thought row as plain text", () => { - const el = buildTranscriptRow(row("agent_thought", { content: { type: "text", text: "hmm" } })); + it("trims ACP framing whitespace and renders thought-row inline markdown", () => { + const el = buildTranscriptRow( + row("agent_thought", { + content: { type: "text", text: "\n\n**Planning comply tool commentary update**\n" }, + }), + ); expect(el.className).toContain("st-row-thought"); - expect(el.textContent).toBe("hmm"); + expect(el.textContent).toBe("Planning comply tool commentary update"); + expect(el.querySelector("strong")?.textContent).toBe("Planning comply tool commentary update"); }); it("falls back to a labelled placeholder for non-text content, never crashing", () => { diff --git a/web/src/structuredRender.ts b/web/src/structuredRender.ts index 3513e34..d7b65bd 100644 --- a/web/src/structuredRender.ts +++ b/web/src/structuredRender.ts @@ -196,20 +196,21 @@ function makeCopyable(node: HTMLElement, text: string, label: string): void { function buildContentRow(row: TranscriptRow, variant: "user" | "agent" | "thought"): HTMLElement { const data = row.data as { content?: AcpContentBlock; messageId?: string } | undefined; const text = contentBlockText(data?.content); + const displayText = variant === "thought" ? text.trim() : text; const wrap = el("div", `st-row st-row-${variant}`); const body = el("div", "st-body"); if (variant === "user") { const line = el("div", "st-user-text"); - line.textContent = text; + line.textContent = displayText; body.appendChild(line); } else if (variant === "agent") { - renderProse(body, text); + renderProse(body, displayText); } else { - body.textContent = text; + body.innerHTML = renderInlineMarkdown(displayText); } wrap.appendChild(body); const label = variant === "user" ? "message" : variant === "agent" ? "response" : "thought"; - makeCopyable(wrap, text, label); + makeCopyable(wrap, displayText, label); return wrap; }