Skip to content

Commit a35ade2

Browse files
t3dotggclaude
andcommitted
fix(server): ship the paragraph above a heading that ends it
A heading that follows a paragraph with no blank line held that paragraph back too. An unindented ATX heading now splits before itself. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 5f6c969 commit a35ade2

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

‎apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5188,6 +5188,18 @@ describe("splitBufferedAssistantText", () => {
51885188
});
51895189
});
51905190

5191+
it("delivers the paragraph above a heading with no blank line between them", () => {
5192+
expect(splitBufferedAssistantText("para\n## Setup\n\nInstall")).toEqual({
5193+
ready: "para\n",
5194+
rest: "## Setup\n\nInstall",
5195+
});
5196+
// A bold line there continues the paragraph, so both stay buffered.
5197+
expect(splitBufferedAssistantText("para\n**Setup**\n\nInstall")).toEqual({
5198+
ready: "",
5199+
rest: "para\n**Setup**\n\nInstall",
5200+
});
5201+
});
5202+
51915203
it("holds a line of only bold text like a heading", () => {
51925204
expect(splitBufferedAssistantText("**Risk by area:**\n\n| a |\n|---|\n")).toEqual({
51935205
ready: "",

‎apps/server/src/orchestration/Layers/ProviderRuntimeIngestion.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ const LIST_ITEM_START_PATTERN = /^[ \t]*(?:[-*+]|\d{1,9}[.)])[ \t]/;
214214
// A section title: an ATX heading, or a line of only bold text, which models
215215
// often use as a heading.
216216
const SECTION_TITLE_PATTERN = /^ {0,3}(?:#{1,6}(?:[ \t]|$)|\*\*[^*]+\*\*:?$)/;
217+
// An unindented ATX heading ends the paragraph or list above it, even with no
218+
// blank line between them. A bold line would continue the paragraph instead.
219+
const TOP_LEVEL_HEADING_PATTERN = /^#{1,6}(?:[ \t]|$)/;
217220

218221
/**
219222
* Splits buffered assistant text at the last blank line, closing code fence,
@@ -271,6 +274,9 @@ export function splitBufferedAssistantText(text: string): { ready: string; rest:
271274
boundary = newline + 1;
272275
}
273276
} else if (openFence === null) {
277+
if (lineStart > 0 && !titleAwaitingContent && TOP_LEVEL_HEADING_PATTERN.test(line)) {
278+
boundary = lineStart;
279+
}
274280
titleAwaitingContent = SECTION_TITLE_PATTERN.test(line);
275281
}
276282
lineStart = newline + 1;

0 commit comments

Comments
 (0)