@devries-cameron20 / t3code Mirror · read-only / commits / b8fb45eb4c
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 05:45 UTC

fix(server): document text skips tracked deletions and field codes (#29796)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Alex Southwell committed Nov 3, 2026 at 23:26 UTC b8fb45eb4ccab968051cd41f04ca7f3785bd4469
2 files changed +37 -7
apps/server/src/provider/documentTextWorker.ts
+17 -7
@@ -14,6 +14,20 @@ const CELL_END = Symbol("cell-end");
14 type TextPart = string | typeof CELL_START | typeof CELL_END | { fallback: string };
15
16 const TRUNCATED = "\n\n[Extracted text truncated at document extraction limits.]";
17 +// Parts the document never displays: tracked deletions and moves, field codes, phonetic guides,
18 +// paragraph properties such as tab-stop definitions.
19 +const HIDDEN = new Set([
20 + "script",
21 + "style",
22 + "binary-data",
23 + "rPh",
24 + "delText",
25 + "moveFrom",
26 + "instrText",
27 + "delInstrText",
28 + "tracked-changes",
29 + "pPr",
30 +]);
31
32 class Truncation extends Error {}
33
@@ -67,7 +81,7 @@ function* all(node: XmlNode, name: string | readonly string[]): Generator<XmlNod
81 }
82 }
83 function* text(node: XmlNode): Generator<string, void> {
70 - if (["script", "style", "binary-data", "rPh"].includes(node.name)) return;
84 + if (HIDDEN.has(node.name)) return;
85 if (["tab", "cell"].includes(node.name)) yield "\t";
86 else if (["br", "line-break", "cr"].includes(node.name)) yield "\n";
87 else if (node.spaceCount !== undefined) {
@@ -80,7 +94,7 @@ function* text(node: XmlNode): Generator<string, void> {
94 }
95 }
96 function* paragraphs(node: XmlNode): Generator<TextPart, void> {
83 - if (["script", "style", "binary-data"].includes(node.name)) return;
97 + if (HIDDEN.has(node.name)) return;
98 for (const child of node.children) {
99 if (typeof child === "string") yield child;
100 else if (["br", "line-break", "cr"].includes(child.name)) yield "\n";
@@ -137,11 +151,7 @@ function odfValue(cell: XmlNode): string {
151 function hasCellText(cell: XmlNode): boolean {
152 if (odfValue(cell).trim()) return true;
153 // Space markers can have enormous repeat counts; emptiness never requires expanding them.
140 - if (
141 - ["script", "style", "binary-data", "rPh"].includes(cell.name) ||
142 - cell.spaceCount !== undefined
143 - )
144 - return false;
154 + if (HIDDEN.has(cell.name) || cell.spaceCount !== undefined) return false;
155 return cell.children.some((child) =>
156 typeof child === "string" ? !!child.trim() : hasCellText(child),
157 );
apps/server/src/provider/userInputAttachments.test.ts
+20
@@ -572,6 +572,26 @@ describe("question answer paths", () => {
572 },
573 expected: ["First\nSecond\nThird"],
574 },
575 + {
576 + ext: "docx",
577 + bounded: true,
578 + parts: {
579 + "word/document.xml":
580 + '<w:document xmlns:w="urn:w"><w:body><w:p><w:r><w:t>Intro</w:t></w:r><w:r><w:fldChar w:fldCharType="begin"/></w:r><w:r><w:instrText> PAGEREF _Toc1 \\h </w:instrText></w:r><w:r><w:fldChar w:fldCharType="separate"/></w:r><w:r><w:t> 3</w:t></w:r><w:r><w:fldChar w:fldCharType="end"/></w:r></w:p><w:p><w:pPr><w:tabs><w:tab w:val="right" w:pos="9350"/></w:tabs></w:pPr><w:r><w:t xml:space="preserve">Fee </w:t></w:r><w:del><w:r><w:delText>$500</w:delText></w:r></w:del><w:ins><w:r><w:t>$700</w:t></w:r></w:ins><w:moveFrom><w:r><w:t>Moved</w:t></w:r></w:moveFrom><w:r><w:tab/><w:t>due</w:t></w:r></w:p></w:body></w:document>',
581 + },
582 + expected: ["Intro 3\nFee $700\tdue"],
583 + absent: ["PAGEREF", "$500", "Moved"],
584 + },
585 + {
586 + ext: "odt",
587 + bounded: true,
588 + parts: {
589 + "content.xml":
590 + "<document><text><tracked-changes><changed-region><deletion><change-info><creator>Reviewer</creator></change-info><p>$500</p></deletion></changed-region></tracked-changes><p>Fee <change/>$700</p></text></document>",
591 + },
592 + expected: ["Fee $700"],
593 + absent: ["Reviewer", "$500"],
594 + },
595 {
596 ext: "docx",
597 bounded: true,