@devries-cameron20 / t3code Mirror · read-only / commits / eb30336618
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): Word text boxes are no longer extracted twice for agents (#29827)

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

Alex Southwell committed Nov 3, 2026 at 23:26 UTC eb303366182d538409621a932a9cbc4086ab7225
2 files changed +35 -2
apps/server/src/provider/documentTextWorker.ts
+16 -2
@@ -36,6 +36,8 @@ interface XmlNode {
36 attrs: Record<string, string>;
37 children: Array<XmlNode | string>;
38 spaceCount?: number;
39 + hasText?: boolean;
40 + hasTextChoice?: boolean;
41 }
42
43 function xml(source: string, odfSpaces = false, htmlEntities = false): XmlNode {
@@ -61,10 +63,22 @@ function xml(source: string, odfSpaces = false, htmlEntities = false): XmlNode {
63 stack.push(node);
64 });
65 parser.on("closetag", () => {
64 - stack.pop();
66 + const node = stack.pop()!;
67 + const parent = stack.at(-1)!;
68 + // Markup-compatibility fallbacks repeat their mc:Choice content, e.g. Word text boxes.
69 + // Keep one when no Choice carries text, such as a chart with a VML caption.
70 + if (node.name === "Fallback" && parent.hasTextChoice) {
71 + parent.children.pop();
72 + return;
73 + }
74 + if (!node.hasText) return;
75 + parent.hasText = true;
76 + if (node.name === "Choice") parent.hasTextChoice = true;
77 });
78 const text = (value: string) => {
67 - stack.at(-1)!.children.push(value);
79 + const node = stack.at(-1)!;
80 + node.children.push(value);
81 + if (value.trim() !== "") node.hasText = true;
82 };
83 parser.on("text", text);
84 parser.on("cdata", text);
apps/server/src/provider/userInputAttachments.test.ts
+19
@@ -554,6 +554,25 @@ describe("question answer paths", () => {
554 expected: ["Start", "[Extracted text truncated at document extraction limits.]"],
555 absent: ["Unneeded"],
556 },
557 + {
558 + ext: "docx",
559 + bounded: true,
560 + parts: {
561 + "word/document.xml":
562 + '<w:document xmlns:w="urn:w" xmlns:mc="urn:mc"><w:body><w:p><w:r><w:t>Body</w:t></w:r></w:p><w:p><w:r><mc:AlternateContent><mc:Choice Requires="wps"><w:drawing><wps:wsp><wps:txbx><w:txbxContent><w:p><w:r><w:t>Callout box</w:t></w:r></w:p></w:txbxContent></wps:txbx></wps:wsp></w:drawing></mc:Choice><mc:Fallback><w:pict><v:shape><v:textbox><w:txbxContent><w:p><w:r><w:t>Callout box</w:t></w:r></w:p></w:txbxContent></v:textbox></v:shape></w:pict></mc:Fallback></mc:AlternateContent></w:r></w:p></w:body></w:document>',
563 + },
564 + expected: ["Body\nCallout box"],
565 + occurrences: { text: "Callout box", count: 1 },
566 + },
567 + {
568 + ext: "docx",
569 + bounded: true,
570 + parts: {
571 + "word/document.xml":
572 + '<w:document xmlns:w="urn:w" xmlns:mc="urn:mc"><w:body><w:p><w:r><mc:AlternateContent><mc:Choice Requires="cx"><w:drawing><cx:chart/></w:drawing></mc:Choice><mc:Fallback><w:pict><v:shape><v:textbox><w:txbxContent><w:p><w:r><w:t>Chart caption</w:t></w:r></w:p></w:txbxContent></v:textbox></v:shape></w:pict></mc:Fallback></mc:AlternateContent></w:r></w:p></w:body></w:document>',
573 + },
574 + expected: ["Chart caption"],
575 + },
576 {
577 ext: "docx",
578 bounded: true,