From 069fc0859a4c1fd1a6929e6f0363c8fb0a01f1cc Mon Sep 17 00:00:00 2001 From: Ayman Khan Date: Thu, 26 Nov 2026 16:49:42 +0530 Subject: [PATCH 1/2] fix(client-runtime): workflow feed lines skip fenced code to the reply's first sentence --- packages/client-runtime/src/workflows.test.ts | 13 ++++++++++ packages/client-runtime/src/workflows.ts | 25 ++++++++++++++++--- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/packages/client-runtime/src/workflows.test.ts b/packages/client-runtime/src/workflows.test.ts index 08e7e71e8f8ce..470ad15ff44a6 100644 --- a/packages/client-runtime/src/workflows.test.ts +++ b/packages/client-runtime/src/workflows.test.ts @@ -759,6 +759,19 @@ describe("workflowOneLine", () => { "Run __init__, *glob* and [api](url) now.", ); }); + + it("skips fenced code blocks to read the prose sentence after them", () => { + expect(workflowOneLine('```json\n{"ok": true}\n```\nAll good. Next.')).toBe("All good."); + expect(workflowOneLine('```json\r\n{"ok": true}\r\n```\r\nAll good. Next.')).toBe("All good."); + expect(workflowOneLine("~~~\nconst x = 1;\n~~~\nDone.")).toBe("Done."); + expect(workflowOneLine("````md\n```ts\nconst x = 1;\n```\n````\nDone.")).toBe("Done."); + expect(workflowOneLine("```\n```js\nconst x = 1;\n```\nDone.")).toBe("Done."); + expect(workflowOneLine("```ts\nconst a = 1;\n```")).toBe(""); + expect(workflowOneLine("```ts\nconst a = 1;\nStill inside an unclosed fence.")).toBe(""); + expect(workflowOneLine("```foo``` is an inline code span. Next.")).toBe( + "foo is an inline code span.", + ); + }); }); describe("workflowWithdrawal", () => { diff --git a/packages/client-runtime/src/workflows.ts b/packages/client-runtime/src/workflows.ts index 8502927021549..9a52bcdaf58c4 100644 --- a/packages/client-runtime/src/workflows.ts +++ b/packages/client-runtime/src/workflows.ts @@ -952,16 +952,33 @@ export function workflowStepTime(ms: number): string { } /** - * The first sentence of a reply, as one line of plain text: a heading, list mark, inline code, - * emphasis or link reads as its words. Code keeps its text, and an underscore inside a word, as in - * snake_case, is not emphasis. + * The first prose sentence of a reply, as one line of plain text: headings, tables, and fenced + * code blocks are skipped, and list marks, inline code, emphasis, or links read as their words. + * Code keeps its text, and an underscore inside a word, as in snake_case, is not emphasis. */ export function workflowOneLine(text: string): string { + let fence: string | null = null; const line = text .split("\n") .map((candidate) => candidate.trim()) - .find((candidate) => candidate !== "" && !/^(#|```|\|)/.test(candidate)) + .find((candidate) => { + const marker = /^(`{3,}|~{3,})/.exec(candidate)?.[1]; + if (fence !== null) { + if (candidate === marker && marker.startsWith(fence)) { + fence = null; + } + return false; + } + if ( + marker !== undefined && + !(marker[0] === "`" && candidate.slice(marker.length).includes("`")) + ) { + fence = marker; + return false; + } + return candidate !== "" && !/^(#|\|)/.test(candidate); + }) ?.replace(/^([-*>]|\d+\.)\s+/, "") ?? ""; const code: string[] = []; const plain = line From d349a1e45c6cca2e7ae9e59ee9fc98a910b26b08 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 26 Nov 2026 11:26:36 +0000 Subject: [PATCH 2/2] test(client-runtime): keep one fenced-code case per rule Co-Authored-By: Claude Opus 5.5 --- packages/client-runtime/src/workflows.test.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/client-runtime/src/workflows.test.ts b/packages/client-runtime/src/workflows.test.ts index 470ad15ff44a6..3f9da222b79fc 100644 --- a/packages/client-runtime/src/workflows.test.ts +++ b/packages/client-runtime/src/workflows.test.ts @@ -762,11 +762,8 @@ describe("workflowOneLine", () => { it("skips fenced code blocks to read the prose sentence after them", () => { expect(workflowOneLine('```json\n{"ok": true}\n```\nAll good. Next.')).toBe("All good."); - expect(workflowOneLine('```json\r\n{"ok": true}\r\n```\r\nAll good. Next.')).toBe("All good."); expect(workflowOneLine("~~~\nconst x = 1;\n~~~\nDone.")).toBe("Done."); expect(workflowOneLine("````md\n```ts\nconst x = 1;\n```\n````\nDone.")).toBe("Done."); - expect(workflowOneLine("```\n```js\nconst x = 1;\n```\nDone.")).toBe("Done."); - expect(workflowOneLine("```ts\nconst a = 1;\n```")).toBe(""); expect(workflowOneLine("```ts\nconst a = 1;\nStill inside an unclosed fence.")).toBe(""); expect(workflowOneLine("```foo``` is an inline code span. Next.")).toBe( "foo is an inline code span.",