From 89591edae0a3f1259a42d339d615419a2449ec14 Mon Sep 17 00:00:00 2001 From: nullStack65 <112618179+nullStack65@users.noreply.github.com> Date: Fri, 20 Nov 2026 08:34:42 +0000 Subject: [PATCH] fix(web): keep lettered and bullet-character lines apart in assistant replies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Markdown has no lettered lists. An assistant reply that wrote "A. …" and "B. …" on consecutive lines rendered as one solid paragraph, because CommonMark treats single newlines as spaces. Assistant messages now keep line breaks when two or more consecutive lines start with a letter marker (A. / b) / (c)) or a bullet character (•), outside code fences. Model: claude-opus-5-5 Task: fix Agent: claude-code Lane: CLO-977 Co-Authored-By: Claude Opus 5.5 --- packages/shared/src/markdownPipeline.test.ts | 31 ++++++++++++++++++++ packages/shared/src/markdownPipeline.ts | 23 ++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/packages/shared/src/markdownPipeline.test.ts b/packages/shared/src/markdownPipeline.test.ts index 9671225731e22..dfe2471bf206c 100644 --- a/packages/shared/src/markdownPipeline.test.ts +++ b/packages/shared/src/markdownPipeline.test.ts @@ -10,6 +10,7 @@ import { CHAT_MARKDOWN_REMARK_PLUGINS_WITH_BREAKS, remarkAssistantInsights, remarkEnableOrderedListNumbers, + shouldPreserveAssistantLineBreaks, } from "./markdownPipeline.ts"; it.each([ @@ -712,3 +713,33 @@ it("links complete absolute paths in prose and skips shortened ones", () => { expect(links(`[notes](${path}) and \`${path}\``)).toEqual([path]); expect(links(`\`\`\`\n${path}\n\`\`\``)).toEqual([]); }); + +it.each([ + [ + "lettered lines", + "Three calls:\nA. Merge the gateway PR.\nB. Hold the window.\nC. Retire Go.", + true, + ], + ["parenthesized letters", "a) one\nb) two", true], + ["bullet characters", "• one\n• two", true], + ["insight block", "★ Insight ─────\nfirst\nsecond", true], + ["one lettered line", "A. Only one item here.\nThen prose.", false], + ["lettered paragraphs", "A. one\n\nB. two", false], + ["real markdown list", "- one\n- two\n1. three", false], + ["plain paragraph", "A normal\nmarkdown paragraph", false], + ["inside a code fence", "```\nA. one\nB. two\n```", false], +] as const)("preserves assistant line breaks for %s: %s", (_, text, expected) => { + expect(shouldPreserveAssistantLineBreaks(text)).toBe(expected); +}); + +it("keeps lettered lines apart once breaks are on", () => { + const text = "A. Merge the gateway PR.\nB. Hold the window."; + const tree = unified() + .use(remarkParse) + .use(CHAT_MARKDOWN_REMARK_PLUGINS_WITH_BREAKS) + .runSync(unified().use(remarkParse).parse(text)) as Root; + const paragraph = tree.children[0]; + expect(paragraph?.type).toBe("paragraph"); + const kinds = paragraph && "children" in paragraph ? paragraph.children.map((c) => c.type) : []; + expect(kinds).toContain("break"); +}); diff --git a/packages/shared/src/markdownPipeline.ts b/packages/shared/src/markdownPipeline.ts index ad77b6d928aee..66225aabdbdee 100644 --- a/packages/shared/src/markdownPipeline.ts +++ b/packages/shared/src/markdownPipeline.ts @@ -744,8 +744,29 @@ function remarkNormalizeLinksAndTagInlineCode() { }; } +// Markdown has no lettered or "•" lists, so lines such as "A. merge it" and +// "B. hold it" are one paragraph to CommonMark and render as a solid block. +const PSEUDO_LIST_LINE = /^ {0,3}(?:\(?[A-Za-z]\)|[A-Za-z]\.|[•·▪◦‣])[ \t]+\S/u; +const FENCE_LINE = /^ {0,3}(?:`{3,}|~{3,})/u; + +function hasPseudoListLines(text: string): boolean { + let inFence = false; + let previousMarked = false; + for (const line of text.split(/\r?\n/u)) { + if (FENCE_LINE.test(line)) { + inFence = !inFence; + previousMarked = false; + continue; + } + const marked = !inFence && PSEUDO_LIST_LINE.test(line); + if (marked && previousMarked) return true; + previousMarked = marked; + } + return false; +} + export function shouldPreserveAssistantLineBreaks(text: string): boolean { - return /^★ Insight(?:\s|─)/mu.test(text); + return /^★ Insight(?:\s|─)/mu.test(text) || hasPseudoListLines(text); } export function remarkAssistantInsights(this: Processor) {