From b474297b688f4f1e20fc084852eb91b1baba02d8 Mon Sep 17 00:00:00 2001 From: Geezy Date: Wed, 4 Nov 2026 13:49:08 +0100 Subject: [PATCH] fix(server): agents read RTF paragraphs that end with a backslash RTF treats a backslash followed by a carriage return or line feed as \par, and macOS TextEdit ends every paragraph that way. The document text extractor skipped the pair, so an attached TextEdit file reached the agent as one run-on paragraph. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/provider/documentTextWorker.ts | 2 ++ apps/server/src/provider/userInputAttachments.test.ts | 1 + 2 files changed, 3 insertions(+) diff --git a/apps/server/src/provider/documentTextWorker.ts b/apps/server/src/provider/documentTextWorker.ts index 4abadfbdb173b..ee7badfe9336f 100644 --- a/apps/server/src/provider/documentTextWorker.ts +++ b/apps/server/src/provider/documentTextWorker.ts @@ -408,6 +408,8 @@ function* rtf(source: string): Generator { i++; if (fallback) fallback--; else if (rest[0] === "*") state.skip = true; + // A backslash before a line break is \par; TextEdit ends paragraphs this way. + else if (!state.skip && (rest[0] === "\n" || rest[0] === "\r")) yield "\n"; else if (!state.skip && ["\\", "{", "}"].includes(rest[0]!)) yield rest[0]!; else if (!state.skip && symbols.has(rest[0]!)) yield symbols.get(rest[0]!)!; } diff --git a/apps/server/src/provider/userInputAttachments.test.ts b/apps/server/src/provider/userInputAttachments.test.ts index 90793ce3f821e..c017f5574f2cb 100644 --- a/apps/server/src/provider/userInputAttachments.test.ts +++ b/apps/server/src/provider/userInputAttachments.test.ts @@ -182,6 +182,7 @@ describe("question answer paths", () => { ], ["hyphen symbol fallback", String.raw`{\rtf1\ansi\uc3\u945\~\_\-Z}`, "αZ"], ["control word", String.raw`{\rtf1\ansi A\u9\tab X}`, "A\tX"], + ["line break paragraphs", "{\\rtf1\\ansi First\\\nSecond\\\r\nThird}", "First\nSecond\nThird"], ["group close", String.raw`{\rtf1\ansi{\u945}Z}`, "αZ"], ["group open", String.raw`{\rtf1\ansi\u945{Z}}`, "αZ"], ["hex byte", String.raw`{\rtf1\ansi\u945\'3fZ}`, "αZ"],