Skip to content

Commit 1dfd91b

Browse files
fix(server): trim the partial line before the list-item check
A bare marker with only trailing whitespace on the partial line was a boundary while the same terminated line was not, and delivering before `- \n` turns the preceding paragraph into a setext heading. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 291e488 commit 1dfd91b

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4657,15 +4657,18 @@ describe("splitBufferedAssistantText", () => {
46574657
ready: "## Steps\n\n- one\n- two\n",
46584658
rest: "- thr",
46594659
});
4660-
expect(splitBufferedAssistantText("1. one\n2. two\n more\n3. ")).toEqual({
4660+
expect(splitBufferedAssistantText("1. one\n2. two\n more\n3. t")).toEqual({
46614661
ready: "1. one\n2. two\n more\n",
4662-
rest: "3. ",
4662+
rest: "3. t",
46634663
});
46644664
});
46654665

46664666
it("keeps a partial list marker and list-like code buffered", () => {
46674667
expect(splitBufferedAssistantText("intro\n-")).toEqual({ ready: "", rest: "intro\n-" });
46684668
expect(splitBufferedAssistantText("intro\n1.")).toEqual({ ready: "", rest: "intro\n1." });
4669+
// `intro\n- \n` would parse as a setext heading, so a bare marker with only
4670+
// trailing whitespace is not a boundary on the partial line either.
4671+
expect(splitBufferedAssistantText("intro\n- ")).toEqual({ ready: "", rest: "intro\n- " });
46694672
expect(splitBufferedAssistantText("- one\n")).toEqual({ ready: "", rest: "- one\n" });
46704673
expect(splitBufferedAssistantText("```\n- one\n- two\n")).toEqual({
46714674
ready: "",

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -215,21 +215,16 @@ export function splitBufferedAssistantText(text: string): { ready: string; rest:
215215
let lineStart = 0;
216216
for (;;) {
217217
const newline = text.indexOf("\n", lineStart);
218+
const line = text
219+
.slice(lineStart, newline === -1 ? text.length : newline)
220+
.replace(/[ \t\r]+$/, "");
221+
if (openFence === null && lineStart > 0 && LIST_ITEM_START_PATTERN.test(line)) {
222+
boundary = lineStart;
223+
}
218224
if (newline === -1) {
219-
if (
220-
openFence === null &&
221-
lineStart > 0 &&
222-
LIST_ITEM_START_PATTERN.test(text.slice(lineStart))
223-
) {
224-
boundary = lineStart;
225-
}
226225
break;
227226
}
228-
const line = text.slice(lineStart, newline).replace(/[ \t\r]+$/, "");
229227
const fenceMatch = MARKDOWN_FENCE_PATTERN.exec(line);
230-
if (openFence === null && lineStart > 0 && LIST_ITEM_START_PATTERN.test(line)) {
231-
boundary = lineStart;
232-
}
233228
if (fenceMatch) {
234229
const indent = fenceMatch[1]!.length;
235230
const marker = fenceMatch[2]!;

0 commit comments

Comments
 (0)