anymous 1.2.7 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (567) hide show
  1. package/bin/anymous.cjs +1 -1
  2. package/package.json +1 -1
  3. package/script/postinstall.mjs +214 -0
  4. package/skills/algorithmic-art/LICENSE.txt +202 -0
  5. package/skills/algorithmic-art/SKILL.md +405 -0
  6. package/skills/algorithmic-art/templates/generator_template.js +223 -0
  7. package/skills/algorithmic-art/templates/viewer.html +599 -0
  8. package/skills/artifacts-builder/LICENSE.txt +202 -0
  9. package/skills/artifacts-builder/SKILL.md +74 -0
  10. package/skills/artifacts-builder/scripts/bundle-artifact.sh +54 -0
  11. package/skills/artifacts-builder/scripts/init-artifact.sh +322 -0
  12. package/skills/artifacts-builder/scripts/shadcn-components.tar.gz +0 -0
  13. package/skills/brainstorming/SKILL.md +151 -0
  14. package/skills/brainstorming/scripts/frame-template.html +213 -0
  15. package/skills/brainstorming/scripts/helper.js +167 -0
  16. package/skills/brainstorming/scripts/server.cjs +723 -0
  17. package/skills/brainstorming/scripts/start-server.sh +209 -0
  18. package/skills/brainstorming/scripts/stop-server.sh +120 -0
  19. package/skills/brainstorming/spec-document-reviewer-prompt.md +49 -0
  20. package/skills/brainstorming/visual-companion.md +298 -0
  21. package/skills/brand-guidelines/LICENSE.txt +202 -0
  22. package/skills/brand-guidelines/SKILL.md +73 -0
  23. package/skills/canvas-design/LICENSE.txt +202 -0
  24. package/skills/canvas-design/SKILL.md +130 -0
  25. package/skills/canvas-design/canvas-fonts/ArsenalSC-OFL.txt +93 -0
  26. package/skills/canvas-design/canvas-fonts/ArsenalSC-Regular.ttf +0 -0
  27. package/skills/canvas-design/canvas-fonts/BigShoulders-Bold.ttf +0 -0
  28. package/skills/canvas-design/canvas-fonts/BigShoulders-OFL.txt +93 -0
  29. package/skills/canvas-design/canvas-fonts/BigShoulders-Regular.ttf +0 -0
  30. package/skills/canvas-design/canvas-fonts/Boldonse-OFL.txt +93 -0
  31. package/skills/canvas-design/canvas-fonts/Boldonse-Regular.ttf +0 -0
  32. package/skills/canvas-design/canvas-fonts/BricolageGrotesque-Bold.ttf +0 -0
  33. package/skills/canvas-design/canvas-fonts/BricolageGrotesque-OFL.txt +93 -0
  34. package/skills/canvas-design/canvas-fonts/BricolageGrotesque-Regular.ttf +0 -0
  35. package/skills/canvas-design/canvas-fonts/CrimsonPro-Bold.ttf +0 -0
  36. package/skills/canvas-design/canvas-fonts/CrimsonPro-Italic.ttf +0 -0
  37. package/skills/canvas-design/canvas-fonts/CrimsonPro-OFL.txt +93 -0
  38. package/skills/canvas-design/canvas-fonts/CrimsonPro-Regular.ttf +0 -0
  39. package/skills/canvas-design/canvas-fonts/DMMono-OFL.txt +93 -0
  40. package/skills/canvas-design/canvas-fonts/DMMono-Regular.ttf +0 -0
  41. package/skills/canvas-design/canvas-fonts/EricaOne-OFL.txt +94 -0
  42. package/skills/canvas-design/canvas-fonts/EricaOne-Regular.ttf +0 -0
  43. package/skills/canvas-design/canvas-fonts/GeistMono-Bold.ttf +0 -0
  44. package/skills/canvas-design/canvas-fonts/GeistMono-OFL.txt +93 -0
  45. package/skills/canvas-design/canvas-fonts/GeistMono-Regular.ttf +0 -0
  46. package/skills/canvas-design/canvas-fonts/Gloock-OFL.txt +93 -0
  47. package/skills/canvas-design/canvas-fonts/Gloock-Regular.ttf +0 -0
  48. package/skills/canvas-design/canvas-fonts/IBMPlexMono-Bold.ttf +0 -0
  49. package/skills/canvas-design/canvas-fonts/IBMPlexMono-OFL.txt +93 -0
  50. package/skills/canvas-design/canvas-fonts/IBMPlexMono-Regular.ttf +0 -0
  51. package/skills/canvas-design/canvas-fonts/IBMPlexSerif-Bold.ttf +0 -0
  52. package/skills/canvas-design/canvas-fonts/IBMPlexSerif-BoldItalic.ttf +0 -0
  53. package/skills/canvas-design/canvas-fonts/IBMPlexSerif-Italic.ttf +0 -0
  54. package/skills/canvas-design/canvas-fonts/IBMPlexSerif-Regular.ttf +0 -0
  55. package/skills/canvas-design/canvas-fonts/InstrumentSans-Bold.ttf +0 -0
  56. package/skills/canvas-design/canvas-fonts/InstrumentSans-BoldItalic.ttf +0 -0
  57. package/skills/canvas-design/canvas-fonts/InstrumentSans-Italic.ttf +0 -0
  58. package/skills/canvas-design/canvas-fonts/InstrumentSans-OFL.txt +93 -0
  59. package/skills/canvas-design/canvas-fonts/InstrumentSans-Regular.ttf +0 -0
  60. package/skills/canvas-design/canvas-fonts/InstrumentSerif-Italic.ttf +0 -0
  61. package/skills/canvas-design/canvas-fonts/InstrumentSerif-Regular.ttf +0 -0
  62. package/skills/canvas-design/canvas-fonts/Italiana-OFL.txt +93 -0
  63. package/skills/canvas-design/canvas-fonts/Italiana-Regular.ttf +0 -0
  64. package/skills/canvas-design/canvas-fonts/JetBrainsMono-Bold.ttf +0 -0
  65. package/skills/canvas-design/canvas-fonts/JetBrainsMono-OFL.txt +93 -0
  66. package/skills/canvas-design/canvas-fonts/JetBrainsMono-Regular.ttf +0 -0
  67. package/skills/canvas-design/canvas-fonts/Jura-Light.ttf +0 -0
  68. package/skills/canvas-design/canvas-fonts/Jura-Medium.ttf +0 -0
  69. package/skills/canvas-design/canvas-fonts/Jura-OFL.txt +93 -0
  70. package/skills/canvas-design/canvas-fonts/LibreBaskerville-OFL.txt +93 -0
  71. package/skills/canvas-design/canvas-fonts/LibreBaskerville-Regular.ttf +0 -0
  72. package/skills/canvas-design/canvas-fonts/Lora-Bold.ttf +0 -0
  73. package/skills/canvas-design/canvas-fonts/Lora-BoldItalic.ttf +0 -0
  74. package/skills/canvas-design/canvas-fonts/Lora-Italic.ttf +0 -0
  75. package/skills/canvas-design/canvas-fonts/Lora-OFL.txt +93 -0
  76. package/skills/canvas-design/canvas-fonts/Lora-Regular.ttf +0 -0
  77. package/skills/canvas-design/canvas-fonts/NationalPark-Bold.ttf +0 -0
  78. package/skills/canvas-design/canvas-fonts/NationalPark-OFL.txt +93 -0
  79. package/skills/canvas-design/canvas-fonts/NationalPark-Regular.ttf +0 -0
  80. package/skills/canvas-design/canvas-fonts/NothingYouCouldDo-OFL.txt +93 -0
  81. package/skills/canvas-design/canvas-fonts/NothingYouCouldDo-Regular.ttf +0 -0
  82. package/skills/canvas-design/canvas-fonts/Outfit-Bold.ttf +0 -0
  83. package/skills/canvas-design/canvas-fonts/Outfit-OFL.txt +93 -0
  84. package/skills/canvas-design/canvas-fonts/Outfit-Regular.ttf +0 -0
  85. package/skills/canvas-design/canvas-fonts/PixelifySans-Medium.ttf +0 -0
  86. package/skills/canvas-design/canvas-fonts/PixelifySans-OFL.txt +93 -0
  87. package/skills/canvas-design/canvas-fonts/PoiretOne-OFL.txt +93 -0
  88. package/skills/canvas-design/canvas-fonts/PoiretOne-Regular.ttf +0 -0
  89. package/skills/canvas-design/canvas-fonts/RedHatMono-Bold.ttf +0 -0
  90. package/skills/canvas-design/canvas-fonts/RedHatMono-OFL.txt +93 -0
  91. package/skills/canvas-design/canvas-fonts/RedHatMono-Regular.ttf +0 -0
  92. package/skills/canvas-design/canvas-fonts/Silkscreen-OFL.txt +93 -0
  93. package/skills/canvas-design/canvas-fonts/Silkscreen-Regular.ttf +0 -0
  94. package/skills/canvas-design/canvas-fonts/SmoochSans-Medium.ttf +0 -0
  95. package/skills/canvas-design/canvas-fonts/SmoochSans-OFL.txt +93 -0
  96. package/skills/canvas-design/canvas-fonts/Tektur-Medium.ttf +0 -0
  97. package/skills/canvas-design/canvas-fonts/Tektur-OFL.txt +93 -0
  98. package/skills/canvas-design/canvas-fonts/Tektur-Regular.ttf +0 -0
  99. package/skills/canvas-design/canvas-fonts/WorkSans-Bold.ttf +0 -0
  100. package/skills/canvas-design/canvas-fonts/WorkSans-BoldItalic.ttf +0 -0
  101. package/skills/canvas-design/canvas-fonts/WorkSans-Italic.ttf +0 -0
  102. package/skills/canvas-design/canvas-fonts/WorkSans-OFL.txt +93 -0
  103. package/skills/canvas-design/canvas-fonts/WorkSans-Regular.ttf +0 -0
  104. package/skills/canvas-design/canvas-fonts/YoungSerif-OFL.txt +93 -0
  105. package/skills/canvas-design/canvas-fonts/YoungSerif-Regular.ttf +0 -0
  106. package/skills/changelog-generator/SKILL.md +110 -0
  107. package/skills/claude-api/LICENSE.txt +202 -0
  108. package/skills/claude-api/SKILL.md +546 -0
  109. package/skills/claude-api/csharp/claude-api/README.md +362 -0
  110. package/skills/claude-api/csharp/claude-api/batches.md +14 -0
  111. package/skills/claude-api/csharp/claude-api/files-api.md +23 -0
  112. package/skills/claude-api/csharp/claude-api/streaming.md +28 -0
  113. package/skills/claude-api/csharp/claude-api/tool-use.md +164 -0
  114. package/skills/claude-api/curl/examples.md +256 -0
  115. package/skills/claude-api/curl/managed-agents.md +340 -0
  116. package/skills/claude-api/go/claude-api/README.md +188 -0
  117. package/skills/claude-api/go/claude-api/files-api.md +21 -0
  118. package/skills/claude-api/go/claude-api/streaming.md +43 -0
  119. package/skills/claude-api/go/claude-api/tool-use.md +220 -0
  120. package/skills/claude-api/go/managed-agents/README.md +564 -0
  121. package/skills/claude-api/java/claude-api/README.md +238 -0
  122. package/skills/claude-api/java/claude-api/files-api.md +25 -0
  123. package/skills/claude-api/java/claude-api/streaming.md +24 -0
  124. package/skills/claude-api/java/claude-api/tool-use.md +228 -0
  125. package/skills/claude-api/java/managed-agents/README.md +443 -0
  126. package/skills/claude-api/php/claude-api/README.md +174 -0
  127. package/skills/claude-api/php/claude-api/batches.md +15 -0
  128. package/skills/claude-api/php/claude-api/files-api.md +11 -0
  129. package/skills/claude-api/php/claude-api/streaming.md +27 -0
  130. package/skills/claude-api/php/claude-api/tool-use.md +253 -0
  131. package/skills/claude-api/php/managed-agents/README.md +443 -0
  132. package/skills/claude-api/python/claude-api/README.md +565 -0
  133. package/skills/claude-api/python/claude-api/batches.md +198 -0
  134. package/skills/claude-api/python/claude-api/files-api.md +170 -0
  135. package/skills/claude-api/python/claude-api/streaming.md +179 -0
  136. package/skills/claude-api/python/claude-api/tool-use.md +629 -0
  137. package/skills/claude-api/python/managed-agents/README.md +335 -0
  138. package/skills/claude-api/ruby/claude-api/README.md +134 -0
  139. package/skills/claude-api/ruby/claude-api/streaming.md +16 -0
  140. package/skills/claude-api/ruby/claude-api/tool-use.md +41 -0
  141. package/skills/claude-api/ruby/managed-agents/README.md +394 -0
  142. package/skills/claude-api/shared/agent-design.md +101 -0
  143. package/skills/claude-api/shared/anthropic-cli.md +246 -0
  144. package/skills/claude-api/shared/claude-platform-on-aws.md +59 -0
  145. package/skills/claude-api/shared/error-codes.md +257 -0
  146. package/skills/claude-api/shared/live-sources.md +143 -0
  147. package/skills/claude-api/shared/managed-agents-api-reference.md +448 -0
  148. package/skills/claude-api/shared/managed-agents-client-patterns.md +217 -0
  149. package/skills/claude-api/shared/managed-agents-core.md +319 -0
  150. package/skills/claude-api/shared/managed-agents-environments.md +219 -0
  151. package/skills/claude-api/shared/managed-agents-events.md +270 -0
  152. package/skills/claude-api/shared/managed-agents-memory.md +199 -0
  153. package/skills/claude-api/shared/managed-agents-multiagent.md +125 -0
  154. package/skills/claude-api/shared/managed-agents-onboarding.md +82 -0
  155. package/skills/claude-api/shared/managed-agents-outcomes.md +108 -0
  156. package/skills/claude-api/shared/managed-agents-overview.md +71 -0
  157. package/skills/claude-api/shared/managed-agents-scheduled-deployments.md +146 -0
  158. package/skills/claude-api/shared/managed-agents-self-hosted-sandboxes.md +174 -0
  159. package/skills/claude-api/shared/managed-agents-tools.md +371 -0
  160. package/skills/claude-api/shared/managed-agents-webhooks.md +143 -0
  161. package/skills/claude-api/shared/model-migration.md +1548 -0
  162. package/skills/claude-api/shared/models.md +138 -0
  163. package/skills/claude-api/shared/platform-availability.md +97 -0
  164. package/skills/claude-api/shared/prompt-caching.md +235 -0
  165. package/skills/claude-api/shared/token-counting.md +56 -0
  166. package/skills/claude-api/shared/tool-use-concepts.md +514 -0
  167. package/skills/claude-api/typescript/claude-api/README.md +405 -0
  168. package/skills/claude-api/typescript/claude-api/batches.md +106 -0
  169. package/skills/claude-api/typescript/claude-api/files-api.md +98 -0
  170. package/skills/claude-api/typescript/claude-api/streaming.md +178 -0
  171. package/skills/claude-api/typescript/claude-api/tool-use.md +589 -0
  172. package/skills/claude-api/typescript/managed-agents/README.md +358 -0
  173. package/skills/code-security-auditor/SKILL.md +164 -0
  174. package/skills/code-security-auditor/references/package_checks.md +59 -0
  175. package/skills/competitive-ads-extractor/SKILL.md +298 -0
  176. package/skills/content-research-writer/SKILL.md +538 -0
  177. package/skills/developer-growth-analysis/SKILL.md +322 -0
  178. package/skills/dispatching-parallel-agents/SKILL.md +167 -0
  179. package/skills/doc-coauthoring/SKILL.md +375 -0
  180. package/skills/docx/LICENSE.txt +30 -0
  181. package/skills/docx/SKILL.md +91 -0
  182. package/skills/docx/scripts/__init__.py +1 -0
  183. package/skills/docx/scripts/accept_changes.py +135 -0
  184. package/skills/docx/scripts/comment.py +368 -0
  185. package/skills/docx/scripts/merge_runs.py +310 -0
  186. package/skills/docx/scripts/office/helpers/__init__.py +111 -0
  187. package/skills/docx/scripts/office/helpers/pptx_chart.py +170 -0
  188. package/skills/docx/scripts/office/helpers/pptx_slide.py +60 -0
  189. package/skills/docx/scripts/office/helpers/pptx_theme.py +114 -0
  190. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
  191. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
  192. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
  193. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
  194. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
  195. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
  196. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
  197. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
  198. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
  199. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
  200. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
  201. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
  202. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
  203. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
  204. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
  205. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
  206. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
  207. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
  208. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
  209. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
  210. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
  211. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
  212. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
  213. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
  214. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
  215. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
  216. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
  217. package/skills/docx/scripts/office/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
  218. package/skills/docx/scripts/office/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
  219. package/skills/docx/scripts/office/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
  220. package/skills/docx/scripts/office/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
  221. package/skills/docx/scripts/office/schemas/mce/mc.xsd +75 -0
  222. package/skills/docx/scripts/office/schemas/microsoft/wml-2010.xsd +560 -0
  223. package/skills/docx/scripts/office/schemas/microsoft/wml-2012.xsd +67 -0
  224. package/skills/docx/scripts/office/schemas/microsoft/wml-2018.xsd +14 -0
  225. package/skills/docx/scripts/office/schemas/microsoft/wml-cex-2018.xsd +20 -0
  226. package/skills/docx/scripts/office/schemas/microsoft/wml-cid-2016.xsd +13 -0
  227. package/skills/docx/scripts/office/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
  228. package/skills/docx/scripts/office/schemas/microsoft/wml-symex-2015.xsd +8 -0
  229. package/skills/docx/scripts/office/soffice.py +192 -0
  230. package/skills/docx/scripts/office/validate.py +173 -0
  231. package/skills/docx/scripts/office/validators/__init__.py +15 -0
  232. package/skills/docx/scripts/office/validators/base.py +875 -0
  233. package/skills/docx/scripts/office/validators/docx.py +466 -0
  234. package/skills/docx/scripts/office/validators/pptx.py +441 -0
  235. package/skills/docx/scripts/office/validators/redlining.py +299 -0
  236. package/skills/docx/scripts/templates/comments.xml +3 -0
  237. package/skills/docx/scripts/templates/commentsExtended.xml +3 -0
  238. package/skills/docx/scripts/templates/commentsExtensible.xml +3 -0
  239. package/skills/docx/scripts/templates/commentsIds.xml +3 -0
  240. package/skills/docx/scripts/templates/people.xml +3 -0
  241. package/skills/domain-name-brainstormer/SKILL.md +217 -0
  242. package/skills/executing-plans/SKILL.md +64 -0
  243. package/skills/file-organizer/SKILL.md +433 -0
  244. package/skills/finishing-a-development-branch/SKILL.md +201 -0
  245. package/skills/frontend-design/LICENSE.txt +177 -0
  246. package/skills/frontend-design/SKILL.md +55 -0
  247. package/skills/image-enhancer/SKILL.md +106 -0
  248. package/skills/internal-comms/LICENSE.txt +202 -0
  249. package/skills/internal-comms/SKILL.md +32 -0
  250. package/skills/internal-comms/examples/3p-updates.md +47 -0
  251. package/skills/internal-comms/examples/company-newsletter.md +65 -0
  252. package/skills/internal-comms/examples/faq-answers.md +30 -0
  253. package/skills/internal-comms/examples/general-comms.md +16 -0
  254. package/skills/invoice-organizer/SKILL.md +452 -0
  255. package/skills/lead-research-assistant/SKILL.md +205 -0
  256. package/skills/mcp-builder/LICENSE.txt +202 -0
  257. package/skills/mcp-builder/SKILL.md +236 -0
  258. package/skills/mcp-builder/reference/evaluation.md +602 -0
  259. package/skills/mcp-builder/reference/mcp_best_practices.md +249 -0
  260. package/skills/mcp-builder/reference/node_mcp_server.md +970 -0
  261. package/skills/mcp-builder/reference/python_mcp_server.md +719 -0
  262. package/skills/mcp-builder/scripts/connections.py +151 -0
  263. package/skills/mcp-builder/scripts/evaluation.py +373 -0
  264. package/skills/mcp-builder/scripts/example_evaluation.xml +22 -0
  265. package/skills/mcp-builder/scripts/requirements.txt +2 -0
  266. package/skills/meeting-insights-analyzer/SKILL.md +327 -0
  267. package/skills/pdf/LICENSE.txt +30 -0
  268. package/skills/pdf/SKILL.md +314 -0
  269. package/skills/pdf/forms.md +294 -0
  270. package/skills/pdf/reference.md +612 -0
  271. package/skills/pdf/scripts/check_bounding_boxes.py +65 -0
  272. package/skills/pdf/scripts/check_fillable_fields.py +11 -0
  273. package/skills/pdf/scripts/convert_pdf_to_images.py +33 -0
  274. package/skills/pdf/scripts/create_validation_image.py +37 -0
  275. package/skills/pdf/scripts/extract_form_field_info.py +122 -0
  276. package/skills/pdf/scripts/extract_form_structure.py +115 -0
  277. package/skills/pdf/scripts/fill_fillable_fields.py +98 -0
  278. package/skills/pdf/scripts/fill_pdf_form_with_annotations.py +107 -0
  279. package/skills/pptx/LICENSE.txt +30 -0
  280. package/skills/pptx/SKILL.md +238 -0
  281. package/skills/pptx/scripts/__init__.py +0 -0
  282. package/skills/pptx/scripts/add_slide.py +367 -0
  283. package/skills/pptx/scripts/clean.py +309 -0
  284. package/skills/pptx/scripts/office/helpers/__init__.py +111 -0
  285. package/skills/pptx/scripts/office/helpers/pptx_chart.py +170 -0
  286. package/skills/pptx/scripts/office/helpers/pptx_slide.py +60 -0
  287. package/skills/pptx/scripts/office/helpers/pptx_theme.py +114 -0
  288. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
  289. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
  290. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
  291. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
  292. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
  293. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
  294. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
  295. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
  296. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
  297. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
  298. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
  299. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
  300. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
  301. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
  302. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
  303. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
  304. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
  305. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
  306. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
  307. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
  308. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
  309. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
  310. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
  311. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
  312. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
  313. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
  314. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
  315. package/skills/pptx/scripts/office/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
  316. package/skills/pptx/scripts/office/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
  317. package/skills/pptx/scripts/office/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
  318. package/skills/pptx/scripts/office/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
  319. package/skills/pptx/scripts/office/schemas/mce/mc.xsd +75 -0
  320. package/skills/pptx/scripts/office/schemas/microsoft/wml-2010.xsd +560 -0
  321. package/skills/pptx/scripts/office/schemas/microsoft/wml-2012.xsd +67 -0
  322. package/skills/pptx/scripts/office/schemas/microsoft/wml-2018.xsd +14 -0
  323. package/skills/pptx/scripts/office/schemas/microsoft/wml-cex-2018.xsd +20 -0
  324. package/skills/pptx/scripts/office/schemas/microsoft/wml-cid-2016.xsd +13 -0
  325. package/skills/pptx/scripts/office/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
  326. package/skills/pptx/scripts/office/schemas/microsoft/wml-symex-2015.xsd +8 -0
  327. package/skills/pptx/scripts/office/soffice.py +192 -0
  328. package/skills/pptx/scripts/office/validate.py +173 -0
  329. package/skills/pptx/scripts/office/validators/__init__.py +15 -0
  330. package/skills/pptx/scripts/office/validators/base.py +875 -0
  331. package/skills/pptx/scripts/office/validators/docx.py +466 -0
  332. package/skills/pptx/scripts/office/validators/pptx.py +441 -0
  333. package/skills/pptx/scripts/office/validators/redlining.py +299 -0
  334. package/skills/pptx/scripts/thumbnail.py +311 -0
  335. package/skills/raffle-winner-picker/SKILL.md +165 -0
  336. package/skills/receiving-code-review/SKILL.md +205 -0
  337. package/skills/requesting-code-review/SKILL.md +95 -0
  338. package/skills/requesting-code-review/code-reviewer.md +172 -0
  339. package/skills/skill-creator/LICENSE.txt +202 -0
  340. package/skills/skill-creator/SKILL.md +485 -0
  341. package/skills/skill-creator/agents/analyzer.md +274 -0
  342. package/skills/skill-creator/agents/comparator.md +202 -0
  343. package/skills/skill-creator/agents/grader.md +223 -0
  344. package/skills/skill-creator/assets/eval_review.html +146 -0
  345. package/skills/skill-creator/eval-viewer/generate_review.py +471 -0
  346. package/skills/skill-creator/eval-viewer/viewer.html +1325 -0
  347. package/skills/skill-creator/references/schemas.md +430 -0
  348. package/skills/skill-creator/scripts/__init__.py +0 -0
  349. package/skills/skill-creator/scripts/aggregate_benchmark.py +401 -0
  350. package/skills/skill-creator/scripts/generate_report.py +326 -0
  351. package/skills/skill-creator/scripts/improve_description.py +247 -0
  352. package/skills/skill-creator/scripts/package_skill.py +136 -0
  353. package/skills/skill-creator/scripts/quick_validate.py +103 -0
  354. package/skills/skill-creator/scripts/run_eval.py +310 -0
  355. package/skills/skill-creator/scripts/run_loop.py +328 -0
  356. package/skills/skill-creator/scripts/utils.py +47 -0
  357. package/skills/skill-share/SKILL.md +80 -0
  358. package/skills/slack-gif-creator/LICENSE.txt +202 -0
  359. package/skills/slack-gif-creator/SKILL.md +254 -0
  360. package/skills/slack-gif-creator/core/easing.py +234 -0
  361. package/skills/slack-gif-creator/core/frame_composer.py +176 -0
  362. package/skills/slack-gif-creator/core/gif_builder.py +269 -0
  363. package/skills/slack-gif-creator/core/validators.py +136 -0
  364. package/skills/slack-gif-creator/requirements.txt +4 -0
  365. package/skills/staff-engineer-review/SKILL.md +172 -0
  366. package/skills/subagent-driven-development/SKILL.md +503 -0
  367. package/skills/subagent-driven-development/implementer-prompt.md +142 -0
  368. package/skills/subagent-driven-development/re-review-prompt.md +106 -0
  369. package/skills/subagent-driven-development/scripts/review-package +46 -0
  370. package/skills/subagent-driven-development/scripts/sdd-workspace +40 -0
  371. package/skills/subagent-driven-development/scripts/task-brief +41 -0
  372. package/skills/subagent-driven-development/task-reviewer-prompt.md +185 -0
  373. package/skills/systematic-debugging/CREATION-LOG.md +119 -0
  374. package/skills/systematic-debugging/SKILL.md +283 -0
  375. package/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
  376. package/skills/systematic-debugging/condition-based-waiting.md +115 -0
  377. package/skills/systematic-debugging/defense-in-depth.md +122 -0
  378. package/skills/systematic-debugging/find-polluter.sh +72 -0
  379. package/skills/systematic-debugging/root-cause-tracing.md +169 -0
  380. package/skills/systematic-debugging/test-academic.md +14 -0
  381. package/skills/systematic-debugging/test-pressure-1.md +58 -0
  382. package/skills/systematic-debugging/test-pressure-2.md +68 -0
  383. package/skills/systematic-debugging/test-pressure-3.md +69 -0
  384. package/skills/test-driven-development/SKILL.md +320 -0
  385. package/skills/test-driven-development/writing-good-tests.md +198 -0
  386. package/skills/theme-factory/LICENSE.txt +202 -0
  387. package/skills/theme-factory/SKILL.md +59 -0
  388. package/skills/theme-factory/theme-showcase.pdf +0 -0
  389. package/skills/theme-factory/themes/arctic-frost.md +19 -0
  390. package/skills/theme-factory/themes/botanical-garden.md +19 -0
  391. package/skills/theme-factory/themes/desert-rose.md +19 -0
  392. package/skills/theme-factory/themes/forest-canopy.md +19 -0
  393. package/skills/theme-factory/themes/golden-hour.md +19 -0
  394. package/skills/theme-factory/themes/midnight-galaxy.md +19 -0
  395. package/skills/theme-factory/themes/modern-minimalist.md +19 -0
  396. package/skills/theme-factory/themes/ocean-depths.md +19 -0
  397. package/skills/theme-factory/themes/sunset-boulevard.md +19 -0
  398. package/skills/theme-factory/themes/tech-innovation.md +19 -0
  399. package/skills/using-git-worktrees/SKILL.md +167 -0
  400. package/skills/using-superpowers/SKILL.md +62 -0
  401. package/skills/using-superpowers/references/antigravity-tools.md +23 -0
  402. package/skills/using-superpowers/references/codex-tools.md +39 -0
  403. package/skills/using-superpowers/references/gemini-tools.md +63 -0
  404. package/skills/using-superpowers/references/pi-tools.md +16 -0
  405. package/skills/verification-before-completion/SKILL.md +120 -0
  406. package/skills/video-downloader/SKILL.md +112 -0
  407. package/skills/web-artifacts-builder/LICENSE.txt +202 -0
  408. package/skills/web-artifacts-builder/SKILL.md +74 -0
  409. package/skills/web-artifacts-builder/scripts/bundle-artifact.sh +54 -0
  410. package/skills/web-artifacts-builder/scripts/init-artifact.sh +322 -0
  411. package/skills/web-artifacts-builder/scripts/shadcn-components.tar.gz +0 -0
  412. package/skills/webapp-testing/LICENSE.txt +202 -0
  413. package/skills/webapp-testing/SKILL.md +96 -0
  414. package/skills/webapp-testing/examples/console_logging.py +35 -0
  415. package/skills/webapp-testing/examples/element_discovery.py +40 -0
  416. package/skills/webapp-testing/examples/static_html_automation.py +33 -0
  417. package/skills/webapp-testing/scripts/with_server.py +106 -0
  418. package/skills/writing-plans/SKILL.md +168 -0
  419. package/skills/writing-plans/plan-document-reviewer-prompt.md +49 -0
  420. package/skills/writing-skills/SKILL.md +679 -0
  421. package/skills/writing-skills/anthropic-best-practices.md +1150 -0
  422. package/skills/writing-skills/examples/CLAUDE_MD_TESTING.md +189 -0
  423. package/skills/writing-skills/graphviz-conventions.dot +172 -0
  424. package/skills/writing-skills/persuasion-principles.md +187 -0
  425. package/skills/writing-skills/render-graphs.js +168 -0
  426. package/skills/writing-skills/testing-skills-with-subagents.md +384 -0
  427. package/skills/xlsx/LICENSE.txt +30 -0
  428. package/skills/xlsx/SKILL.md +99 -0
  429. package/skills/xlsx/scripts/office/helpers/__init__.py +111 -0
  430. package/skills/xlsx/scripts/office/helpers/pptx_chart.py +170 -0
  431. package/skills/xlsx/scripts/office/helpers/pptx_slide.py +60 -0
  432. package/skills/xlsx/scripts/office/helpers/pptx_theme.py +114 -0
  433. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
  434. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
  435. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
  436. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
  437. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
  438. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
  439. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
  440. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
  441. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
  442. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
  443. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
  444. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
  445. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
  446. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
  447. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
  448. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
  449. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
  450. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
  451. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
  452. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
  453. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
  454. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
  455. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
  456. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
  457. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
  458. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
  459. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
  460. package/skills/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
  461. package/skills/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
  462. package/skills/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
  463. package/skills/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
  464. package/skills/xlsx/scripts/office/schemas/mce/mc.xsd +75 -0
  465. package/skills/xlsx/scripts/office/schemas/microsoft/wml-2010.xsd +560 -0
  466. package/skills/xlsx/scripts/office/schemas/microsoft/wml-2012.xsd +67 -0
  467. package/skills/xlsx/scripts/office/schemas/microsoft/wml-2018.xsd +14 -0
  468. package/skills/xlsx/scripts/office/schemas/microsoft/wml-cex-2018.xsd +20 -0
  469. package/skills/xlsx/scripts/office/schemas/microsoft/wml-cid-2016.xsd +13 -0
  470. package/skills/xlsx/scripts/office/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
  471. package/skills/xlsx/scripts/office/schemas/microsoft/wml-symex-2015.xsd +8 -0
  472. package/skills/xlsx/scripts/office/soffice.py +192 -0
  473. package/skills/xlsx/scripts/office/validate.py +173 -0
  474. package/skills/xlsx/scripts/office/validators/__init__.py +15 -0
  475. package/skills/xlsx/scripts/office/validators/base.py +875 -0
  476. package/skills/xlsx/scripts/office/validators/docx.py +466 -0
  477. package/skills/xlsx/scripts/office/validators/pptx.py +441 -0
  478. package/skills/xlsx/scripts/office/validators/redlining.py +299 -0
  479. package/skills/xlsx/scripts/recalc.py +308 -0
  480. package/src/account/account.ts +1 -2
  481. package/src/account/repo.ts +2 -1
  482. package/src/acp/content.ts +1 -1
  483. package/src/acp/directory.ts +2 -2
  484. package/src/acp/event.ts +1 -1
  485. package/src/acp/session.ts +2 -2
  486. package/src/agent/agent.ts +62 -31
  487. package/src/agent/subagent-permissions.ts +1 -1
  488. package/src/cli/cmd/account.ts +2 -1
  489. package/src/cli/cmd/debug/agent.handler.ts +1 -1
  490. package/src/cli/cmd/export.ts +1 -1
  491. package/src/cli/cmd/github.handler.ts +4 -2
  492. package/src/cli/cmd/mcp.ts +2 -2
  493. package/src/cli/cmd/run/footer.prompt.tsx +7 -2
  494. package/src/cli/cmd/stats.ts +1 -1
  495. package/src/cli/network.ts +1 -1
  496. package/src/config/config.ts +3 -5
  497. package/src/config/plugin.ts +1 -1
  498. package/src/control-plane/workspace.ts +3 -2
  499. package/src/effect/app-node-builder-v1.ts +1 -1
  500. package/src/effect/instance-state.ts +2 -1
  501. package/src/effect/runner.ts +2 -1
  502. package/src/effect/runtime-flags.ts +2 -1
  503. package/src/image/image.ts +1 -1
  504. package/src/installation/index.ts +4 -8
  505. package/src/lsp/diagnostic.ts +1 -1
  506. package/src/mcp/catalog.ts +1 -1
  507. package/src/mcp/index.ts +2 -2
  508. package/src/mcp/oauth-provider.ts +1 -1
  509. package/src/permission/index.ts +7 -3
  510. package/src/plugin/index.ts +7 -3
  511. package/src/plugin/loader.ts +1 -1
  512. package/src/plugin/tui/runtime.ts +1 -1
  513. package/src/project/bootstrap-service.ts +2 -1
  514. package/src/project/project.ts +3 -2
  515. package/src/project/vcs.ts +1 -1
  516. package/src/provider/error.ts +1 -1
  517. package/src/provider/provider.ts +3 -2
  518. package/src/question/index.ts +1 -1
  519. package/src/server/auth.ts +2 -1
  520. package/src/server/routes/instance/httpapi/groups/metadata.ts +1 -1
  521. package/src/server/routes/instance/httpapi/handlers/control-plane.ts +2 -1
  522. package/src/server/routes/instance/httpapi/handlers/control.ts +2 -2
  523. package/src/server/routes/instance/httpapi/handlers/experimental.ts +2 -1
  524. package/src/server/routes/instance/httpapi/handlers/global.ts +2 -1
  525. package/src/server/routes/instance/httpapi/handlers/mcp.ts +2 -1
  526. package/src/server/routes/instance/httpapi/handlers/permission.ts +1 -1
  527. package/src/server/routes/instance/httpapi/handlers/project-copy.ts +1 -1
  528. package/src/server/routes/instance/httpapi/handlers/provider.ts +3 -2
  529. package/src/server/routes/instance/httpapi/handlers/pty.ts +1 -1
  530. package/src/server/routes/instance/httpapi/handlers/question.ts +1 -1
  531. package/src/server/routes/instance/httpapi/handlers/session.ts +5 -5
  532. package/src/server/routes/instance/httpapi/handlers/sync.ts +2 -2
  533. package/src/server/routes/instance/httpapi/handlers/tui.ts +1 -1
  534. package/src/server/routes/instance/httpapi/handlers/workspace.ts +2 -1
  535. package/src/server/routes/instance/httpapi/lifecycle.ts +2 -1
  536. package/src/server/routes/instance/httpapi/middleware/instance-context.ts +1 -1
  537. package/src/server/routes/instance/httpapi/middleware/proxy.ts +2 -1
  538. package/src/server/routes/instance/httpapi/server.ts +2 -1
  539. package/src/server/shared/fence.ts +1 -1
  540. package/src/server/shared/ui.ts +2 -1
  541. package/src/session/compaction.ts +5 -4
  542. package/src/session/instruction.ts +1 -1
  543. package/src/session/llm/native-runtime.ts +2 -1
  544. package/src/session/llm/request.ts +2 -2
  545. package/src/session/llm.ts +2 -2
  546. package/src/session/message-v2.ts +5 -16
  547. package/src/session/overflow.ts +2 -2
  548. package/src/session/prompt.ts +4 -3
  549. package/src/session/reminders.ts +2 -2
  550. package/src/session/revert.ts +1 -1
  551. package/src/session/run-state.ts +4 -3
  552. package/src/session/session.ts +2 -1
  553. package/src/session/status.ts +1 -1
  554. package/src/session/summary.ts +1 -1
  555. package/src/session/system.ts +1 -1
  556. package/src/session/todo.ts +1 -1
  557. package/src/session/tools.ts +6 -6
  558. package/src/share/session.ts +1 -1
  559. package/src/share/share-next.ts +1 -1
  560. package/src/tool/computer.ts +195 -136
  561. package/src/tool/edit.ts +1 -1
  562. package/src/tool/mcp-websearch.ts +2 -1
  563. package/src/tool/plan.ts +1 -1
  564. package/src/tool/registry.ts +2 -2
  565. package/src/tool/task.ts +1 -1
  566. package/src/tool/tool.ts +2 -2
  567. package/src/util/bom.ts +1 -1
@@ -0,0 +1,875 @@
1
+ """
2
+ Base validator with common validation logic for document files.
3
+ """
4
+
5
+ import re
6
+ from pathlib import Path
7
+
8
+ import defusedxml.minidom
9
+ from functools import lru_cache
10
+
11
+ import lxml.etree
12
+
13
+ from helpers import safe_extract
14
+
15
+
16
+ @lru_cache(maxsize=None)
17
+ def _load_schema(schema_path: str):
18
+ with open(schema_path, "rb") as xsd_file:
19
+ xsd_doc = lxml.etree.parse(
20
+ xsd_file, parser=lxml.etree.XMLParser(), base_url=schema_path
21
+ )
22
+ return lxml.etree.XMLSchema(xsd_doc)
23
+
24
+ class BaseSchemaValidator:
25
+
26
+ IGNORED_VALIDATION_ERRORS = [
27
+ "hyphenationZone",
28
+ "purl.org/dc/terms",
29
+ ]
30
+
31
+ UNIQUE_ID_REQUIREMENTS = {
32
+ "comment": ("id", "file"),
33
+ "commentrangestart": ("id", "file"),
34
+ "commentrangeend": ("id", "file"),
35
+ "bookmarkstart": ("id", "file"),
36
+ "bookmarkend": ("id", "file"),
37
+ "sldid": ("id", "file"),
38
+ "sldmasterid": ("id", "global"),
39
+ "sldlayoutid": ("id", "global"),
40
+ "cm": ("authorid", "file"),
41
+ "sheet": ("sheetid", "file"),
42
+ "definedname": ("id", "file"),
43
+ "cxnsp": ("id", "file"),
44
+ "sp": ("id", "file"),
45
+ "pic": ("id", "file"),
46
+ "grpsp": ("id", "file"),
47
+ }
48
+
49
+ EXCLUDED_ID_CONTAINERS = {
50
+ "sectionlst",
51
+ }
52
+
53
+ ELEMENT_RELATIONSHIP_TYPES = {}
54
+
55
+ SCHEMA_MAPPINGS = {
56
+ "word": "ISO-IEC29500-4_2016/wml.xsd",
57
+ "ppt": "ISO-IEC29500-4_2016/pml.xsd",
58
+ "xl": "ISO-IEC29500-4_2016/sml.xsd",
59
+ "[Content_Types].xml": "ecma/fouth-edition/opc-contentTypes.xsd",
60
+ "app.xml": "ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd",
61
+ "core.xml": "ecma/fouth-edition/opc-coreProperties.xsd",
62
+ "custom.xml": "ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd",
63
+ ".rels": "ecma/fouth-edition/opc-relationships.xsd",
64
+ "people.xml": "microsoft/wml-2012.xsd",
65
+ "commentsIds.xml": "microsoft/wml-cid-2016.xsd",
66
+ "commentsExtensible.xml": "microsoft/wml-cex-2018.xsd",
67
+ "commentsExtended.xml": "microsoft/wml-2012.xsd",
68
+ "chart": "ISO-IEC29500-4_2016/dml-chart.xsd",
69
+ "theme": "ISO-IEC29500-4_2016/dml-main.xsd",
70
+ "drawing": "ISO-IEC29500-4_2016/dml-main.xsd",
71
+ }
72
+
73
+ MC_NAMESPACE = "http://schemas.openxmlformats.org/markup-compatibility/2006"
74
+ XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace"
75
+
76
+ PACKAGE_RELATIONSHIPS_NAMESPACE = (
77
+ "http://schemas.openxmlformats.org/package/2006/relationships"
78
+ )
79
+ OFFICE_RELATIONSHIPS_NAMESPACE = (
80
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships"
81
+ )
82
+ CONTENT_TYPES_NAMESPACE = (
83
+ "http://schemas.openxmlformats.org/package/2006/content-types"
84
+ )
85
+
86
+ MAIN_CONTENT_FOLDERS = {"word", "ppt", "xl"}
87
+
88
+ OOXML_NAMESPACES = {
89
+ "http://schemas.openxmlformats.org/officeDocument/2006/math",
90
+ "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
91
+ "http://schemas.openxmlformats.org/schemaLibrary/2006/main",
92
+ "http://schemas.openxmlformats.org/drawingml/2006/main",
93
+ "http://schemas.openxmlformats.org/drawingml/2006/chart",
94
+ "http://schemas.openxmlformats.org/drawingml/2006/chartDrawing",
95
+ "http://schemas.openxmlformats.org/drawingml/2006/diagram",
96
+ "http://schemas.openxmlformats.org/drawingml/2006/picture",
97
+ "http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing",
98
+ "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",
99
+ "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
100
+ "http://schemas.openxmlformats.org/presentationml/2006/main",
101
+ "http://schemas.openxmlformats.org/spreadsheetml/2006/main",
102
+ "http://schemas.openxmlformats.org/officeDocument/2006/sharedTypes",
103
+ "http://www.w3.org/XML/1998/namespace",
104
+ }
105
+
106
+ def __init__(self, unpacked_dir, original_file=None, verbose=False):
107
+ self.unpacked_dir = Path(unpacked_dir).resolve()
108
+ self.original_file = Path(original_file) if original_file else None
109
+ self.verbose = verbose
110
+
111
+ self.schemas_dir = Path(__file__).parent.parent / "schemas"
112
+
113
+ patterns = ["*.xml", "*.rels"]
114
+ self.xml_files = [
115
+ f for pattern in patterns for f in self.unpacked_dir.rglob(pattern)
116
+ ]
117
+
118
+ if not self.xml_files:
119
+ print(f"Warning: No XML files found in {self.unpacked_dir}")
120
+
121
+ def validate(self):
122
+ raise NotImplementedError("Subclasses must implement the validate method")
123
+
124
+ def repair(self) -> int:
125
+ return self.repair_whitespace_preservation()
126
+
127
+ def repair_whitespace_preservation(self) -> int:
128
+ repairs = 0
129
+
130
+ for xml_file in self.xml_files:
131
+ try:
132
+ content = xml_file.read_text(encoding="utf-8")
133
+ dom = defusedxml.minidom.parseString(content)
134
+ pending = []
135
+
136
+ for elem in dom.getElementsByTagName("*"):
137
+ local_name = elem.tagName.rsplit(":", 1)[-1]
138
+ if local_name in ("t", "delText", "instrText", "delInstrText"):
139
+ text = "".join(
140
+ child.data
141
+ for child in elem.childNodes
142
+ if child.nodeType in (child.TEXT_NODE, child.CDATA_SECTION_NODE)
143
+ )
144
+ ws = (" ", "\t", "\n", "\r")
145
+ if text and (text.startswith(ws) or text.endswith(ws)):
146
+ if elem.getAttribute("xml:space") != "preserve":
147
+ elem.setAttribute("xml:space", "preserve")
148
+ text_preview = repr(text[:30]) + "..." if len(text) > 30 else repr(text)
149
+ pending.append(f" Repaired: {xml_file.name}: Added xml:space='preserve' to {elem.tagName}: {text_preview}")
150
+
151
+ if pending:
152
+ xml_file.write_bytes(dom.toxml(encoding="UTF-8"))
153
+ for message in pending:
154
+ print(message)
155
+ repairs += len(pending)
156
+
157
+ except Exception:
158
+ pass
159
+
160
+ return repairs
161
+
162
+ def validate_xml(self):
163
+ errors = []
164
+
165
+ for xml_file in self.xml_files:
166
+ try:
167
+ lxml.etree.parse(str(xml_file))
168
+ except lxml.etree.XMLSyntaxError as e:
169
+ errors.append(
170
+ f" {xml_file.relative_to(self.unpacked_dir)}: "
171
+ f"Line {e.lineno}: {e.msg}"
172
+ )
173
+ except Exception as e:
174
+ errors.append(
175
+ f" {xml_file.relative_to(self.unpacked_dir)}: "
176
+ f"Unexpected error: {str(e)}"
177
+ )
178
+
179
+ if errors:
180
+ print(f"FAILED - Found {len(errors)} XML violations:")
181
+ for error in errors:
182
+ print(error)
183
+ return False
184
+ else:
185
+ if self.verbose:
186
+ print("PASSED - All XML files are well-formed")
187
+ return True
188
+
189
+ def validate_namespaces(self):
190
+ errors = []
191
+
192
+ for xml_file in self.xml_files:
193
+ try:
194
+ root = lxml.etree.parse(str(xml_file)).getroot()
195
+ declared = set(root.nsmap.keys()) - {None}
196
+
197
+ for attr_val in [
198
+ v for k, v in root.attrib.items() if k.endswith("Ignorable")
199
+ ]:
200
+ undeclared = set(attr_val.split()) - declared
201
+ errors.extend(
202
+ f" {xml_file.relative_to(self.unpacked_dir)}: "
203
+ f"Namespace '{ns}' in Ignorable but not declared"
204
+ for ns in undeclared
205
+ )
206
+ except lxml.etree.XMLSyntaxError:
207
+ continue
208
+
209
+ if errors:
210
+ print(f"FAILED - {len(errors)} namespace issues:")
211
+ for error in errors:
212
+ print(error)
213
+ return False
214
+ if self.verbose:
215
+ print("PASSED - All namespace prefixes properly declared")
216
+ return True
217
+
218
+ def validate_unique_ids(self):
219
+ errors = []
220
+ global_ids = {}
221
+
222
+ for xml_file in self.xml_files:
223
+ try:
224
+ root = lxml.etree.parse(str(xml_file)).getroot()
225
+ file_ids = {}
226
+
227
+ mc_elements = root.xpath(
228
+ ".//mc:AlternateContent", namespaces={"mc": self.MC_NAMESPACE}
229
+ )
230
+ for elem in mc_elements:
231
+ elem.getparent().remove(elem)
232
+
233
+ for elem in root.iter():
234
+ if not hasattr(elem, "tag") or callable(elem.tag):
235
+ continue
236
+ tag = (
237
+ elem.tag.split("}")[-1].lower()
238
+ if "}" in elem.tag
239
+ else elem.tag.lower()
240
+ )
241
+
242
+ if tag in self.UNIQUE_ID_REQUIREMENTS:
243
+ in_excluded_container = any(
244
+ ancestor.tag.split("}")[-1].lower() in self.EXCLUDED_ID_CONTAINERS
245
+ for ancestor in elem.iterancestors()
246
+ )
247
+ if in_excluded_container:
248
+ continue
249
+
250
+ attr_name, scope = self.UNIQUE_ID_REQUIREMENTS[tag]
251
+
252
+ id_value = None
253
+ for attr, value in elem.attrib.items():
254
+ attr_local = (
255
+ attr.split("}")[-1].lower()
256
+ if "}" in attr
257
+ else attr.lower()
258
+ )
259
+ if attr_local == attr_name:
260
+ id_value = value
261
+ break
262
+
263
+ if id_value is not None:
264
+ if scope == "global":
265
+ if id_value in global_ids:
266
+ prev_file, prev_line, prev_tag = global_ids[
267
+ id_value
268
+ ]
269
+ errors.append(
270
+ f" {xml_file.relative_to(self.unpacked_dir)}: "
271
+ f"Line {elem.sourceline}: Global ID '{id_value}' in <{tag}> "
272
+ f"already used in {prev_file} at line {prev_line} in <{prev_tag}>"
273
+ )
274
+ else:
275
+ global_ids[id_value] = (
276
+ xml_file.relative_to(self.unpacked_dir),
277
+ elem.sourceline,
278
+ tag,
279
+ )
280
+ elif scope == "file":
281
+ key = (tag, attr_name)
282
+ if key not in file_ids:
283
+ file_ids[key] = {}
284
+
285
+ if id_value in file_ids[key]:
286
+ prev_line = file_ids[key][id_value]
287
+ errors.append(
288
+ f" {xml_file.relative_to(self.unpacked_dir)}: "
289
+ f"Line {elem.sourceline}: Duplicate {attr_name}='{id_value}' in <{tag}> "
290
+ f"(first occurrence at line {prev_line})"
291
+ )
292
+ else:
293
+ file_ids[key][id_value] = elem.sourceline
294
+
295
+ except (lxml.etree.XMLSyntaxError, Exception) as e:
296
+ errors.append(
297
+ f" {xml_file.relative_to(self.unpacked_dir)}: Error: {e}"
298
+ )
299
+
300
+ if errors:
301
+ print(f"FAILED - Found {len(errors)} ID uniqueness violations:")
302
+ for error in errors:
303
+ print(error)
304
+ return False
305
+ else:
306
+ if self.verbose:
307
+ print("PASSED - All required IDs are unique")
308
+ return True
309
+
310
+ def validate_file_references(self):
311
+ errors = []
312
+
313
+ rels_files = list(self.unpacked_dir.rglob("*.rels"))
314
+
315
+ if not rels_files:
316
+ if self.verbose:
317
+ print("PASSED - No .rels files found")
318
+ return True
319
+
320
+ all_files = []
321
+ for file_path in self.unpacked_dir.rglob("*"):
322
+ if (
323
+ file_path.is_file()
324
+ and file_path.name != "[Content_Types].xml"
325
+ and not file_path.name.endswith(".rels")
326
+ ):
327
+ all_files.append(file_path.resolve())
328
+
329
+ all_referenced_files = set()
330
+
331
+ if self.verbose:
332
+ print(
333
+ f"Found {len(rels_files)} .rels files and {len(all_files)} target files"
334
+ )
335
+
336
+ for rels_file in rels_files:
337
+ try:
338
+ rels_root = lxml.etree.parse(str(rels_file)).getroot()
339
+
340
+ rels_dir = rels_file.parent
341
+
342
+ referenced_files = set()
343
+ broken_refs = []
344
+
345
+ for rel in rels_root.findall(
346
+ ".//ns:Relationship",
347
+ namespaces={"ns": self.PACKAGE_RELATIONSHIPS_NAMESPACE},
348
+ ):
349
+ target = rel.get("Target")
350
+ if rel.get("TargetMode") == "External":
351
+ continue
352
+ if target and not target.startswith(
353
+ ("http", "mailto:")
354
+ ):
355
+ if target.startswith("/"):
356
+ target_path = self.unpacked_dir / target.lstrip("/")
357
+ elif rels_file.name == ".rels":
358
+ target_path = self.unpacked_dir / target
359
+ else:
360
+ base_dir = rels_dir.parent
361
+ target_path = base_dir / target
362
+
363
+ try:
364
+ target_path = target_path.resolve()
365
+ if target_path.exists() and target_path.is_file():
366
+ referenced_files.add(target_path)
367
+ all_referenced_files.add(target_path)
368
+ else:
369
+ broken_refs.append((target, rel.sourceline))
370
+ except (OSError, ValueError):
371
+ broken_refs.append((target, rel.sourceline))
372
+
373
+ if broken_refs:
374
+ rel_path = rels_file.relative_to(self.unpacked_dir)
375
+ for broken_ref, line_num in broken_refs:
376
+ errors.append(
377
+ f" {rel_path}: Line {line_num}: Broken reference to {broken_ref}"
378
+ )
379
+
380
+ except Exception as e:
381
+ rel_path = rels_file.relative_to(self.unpacked_dir)
382
+ errors.append(f" Error parsing {rel_path}: {e}")
383
+
384
+ unreferenced_files = set(all_files) - all_referenced_files
385
+
386
+ if unreferenced_files:
387
+ for unref_file in sorted(unreferenced_files):
388
+ unref_rel_path = unref_file.relative_to(self.unpacked_dir)
389
+ errors.append(f" Unreferenced file: {unref_rel_path}")
390
+
391
+ if errors:
392
+ print(f"FAILED - Found {len(errors)} relationship validation errors:")
393
+ for error in errors:
394
+ print(error)
395
+ print(
396
+ "CRITICAL: These errors will cause the document to appear corrupt. "
397
+ + "Broken references MUST be fixed, "
398
+ + "and unreferenced files MUST be referenced or removed."
399
+ )
400
+ return False
401
+ else:
402
+ if self.verbose:
403
+ print(
404
+ "PASSED - All references are valid and all files are properly referenced"
405
+ )
406
+ return True
407
+
408
+ def validate_all_relationship_ids(self):
409
+ import lxml.etree
410
+
411
+ errors = []
412
+
413
+ for xml_file in self.xml_files:
414
+ if xml_file.suffix == ".rels":
415
+ continue
416
+
417
+ rels_dir = xml_file.parent / "_rels"
418
+ rels_file = rels_dir / f"{xml_file.name}.rels"
419
+
420
+ if not rels_file.exists():
421
+ continue
422
+
423
+ try:
424
+ rels_root = lxml.etree.parse(str(rels_file)).getroot()
425
+ rid_to_type = {}
426
+
427
+ for rel in rels_root.findall(
428
+ f".//{{{self.PACKAGE_RELATIONSHIPS_NAMESPACE}}}Relationship"
429
+ ):
430
+ rid = rel.get("Id")
431
+ rel_type = rel.get("Type", "")
432
+ if rid:
433
+ if rid in rid_to_type:
434
+ rels_rel_path = rels_file.relative_to(self.unpacked_dir)
435
+ errors.append(
436
+ f" {rels_rel_path}: Line {rel.sourceline}: "
437
+ f"Duplicate relationship ID '{rid}' (IDs must be unique)"
438
+ )
439
+ type_name = (
440
+ rel_type.split("/")[-1] if "/" in rel_type else rel_type
441
+ )
442
+ rid_to_type[rid] = type_name
443
+
444
+ xml_root = lxml.etree.parse(str(xml_file)).getroot()
445
+
446
+ r_ns = self.OFFICE_RELATIONSHIPS_NAMESPACE
447
+ rid_attrs_to_check = ["id", "embed", "link"]
448
+ for elem in xml_root.iter():
449
+ if not hasattr(elem, "tag") or callable(elem.tag):
450
+ continue
451
+ for attr_name in rid_attrs_to_check:
452
+ rid_attr = elem.get(f"{{{r_ns}}}{attr_name}")
453
+ if not rid_attr:
454
+ continue
455
+ xml_rel_path = xml_file.relative_to(self.unpacked_dir)
456
+ elem_name = (
457
+ elem.tag.split("}")[-1] if "}" in elem.tag else elem.tag
458
+ )
459
+
460
+ if rid_attr not in rid_to_type:
461
+ errors.append(
462
+ f" {xml_rel_path}: Line {elem.sourceline}: "
463
+ f"<{elem_name}> r:{attr_name} references non-existent relationship '{rid_attr}' "
464
+ f"(valid IDs: {', '.join(sorted(rid_to_type.keys())[:5])}{'...' if len(rid_to_type) > 5 else ''})"
465
+ )
466
+ elif attr_name == "id" and self.ELEMENT_RELATIONSHIP_TYPES:
467
+ expected_type = self._get_expected_relationship_type(
468
+ elem_name
469
+ )
470
+ if expected_type:
471
+ actual_type = rid_to_type[rid_attr]
472
+ if expected_type not in actual_type.lower():
473
+ errors.append(
474
+ f" {xml_rel_path}: Line {elem.sourceline}: "
475
+ f"<{elem_name}> references '{rid_attr}' which points to '{actual_type}' "
476
+ f"but should point to a '{expected_type}' relationship"
477
+ )
478
+
479
+ except Exception as e:
480
+ xml_rel_path = xml_file.relative_to(self.unpacked_dir)
481
+ errors.append(f" Error processing {xml_rel_path}: {e}")
482
+
483
+ if errors:
484
+ print(f"FAILED - Found {len(errors)} relationship ID reference errors:")
485
+ for error in errors:
486
+ print(error)
487
+ print("\nThese ID mismatches will cause the document to appear corrupt!")
488
+ return False
489
+ else:
490
+ if self.verbose:
491
+ print("PASSED - All relationship ID references are valid")
492
+ return True
493
+
494
+ def _get_expected_relationship_type(self, element_name):
495
+ elem_lower = element_name.lower()
496
+
497
+ if elem_lower in self.ELEMENT_RELATIONSHIP_TYPES:
498
+ return self.ELEMENT_RELATIONSHIP_TYPES[elem_lower]
499
+
500
+ if elem_lower.endswith("id") and len(elem_lower) > 2:
501
+ prefix = elem_lower[:-2]
502
+ if prefix.endswith("master"):
503
+ return prefix.lower()
504
+ elif prefix.endswith("layout"):
505
+ return prefix.lower()
506
+ else:
507
+ if prefix == "sld":
508
+ return "slide"
509
+ return prefix.lower()
510
+
511
+ if elem_lower.endswith("reference") and len(elem_lower) > 9:
512
+ prefix = elem_lower[:-9]
513
+ return prefix.lower()
514
+
515
+ return None
516
+
517
+ def validate_content_types(self):
518
+ errors = []
519
+
520
+ content_types_file = self.unpacked_dir / "[Content_Types].xml"
521
+ if not content_types_file.exists():
522
+ print("FAILED - [Content_Types].xml file not found")
523
+ return False
524
+
525
+ try:
526
+ root = lxml.etree.parse(str(content_types_file)).getroot()
527
+ declared_parts = set()
528
+ declared_extensions = set()
529
+
530
+ for override in root.findall(
531
+ f".//{{{self.CONTENT_TYPES_NAMESPACE}}}Override"
532
+ ):
533
+ part_name = override.get("PartName")
534
+ if part_name is not None:
535
+ declared_parts.add(part_name.lstrip("/"))
536
+
537
+ for default in root.findall(
538
+ f".//{{{self.CONTENT_TYPES_NAMESPACE}}}Default"
539
+ ):
540
+ extension = default.get("Extension")
541
+ if extension is not None:
542
+ declared_extensions.add(extension.lower())
543
+
544
+ declarable_roots = {
545
+ "sld",
546
+ "sldLayout",
547
+ "sldMaster",
548
+ "presentation",
549
+ "document",
550
+ "workbook",
551
+ "worksheet",
552
+ "theme",
553
+ }
554
+
555
+ media_extensions = {
556
+ "png": "image/png",
557
+ "jpg": "image/jpeg",
558
+ "jpeg": "image/jpeg",
559
+ "gif": "image/gif",
560
+ "bmp": "image/bmp",
561
+ "tiff": "image/tiff",
562
+ "wmf": "image/x-wmf",
563
+ "emf": "image/x-emf",
564
+ }
565
+
566
+ all_files = list(self.unpacked_dir.rglob("*"))
567
+ all_files = [f for f in all_files if f.is_file()]
568
+
569
+ for xml_file in self.xml_files:
570
+ path_str = str(xml_file.relative_to(self.unpacked_dir)).replace(
571
+ "\\", "/"
572
+ )
573
+
574
+ if any(
575
+ skip in path_str
576
+ for skip in [".rels", "[Content_Types]", "docProps/", "_rels/"]
577
+ ):
578
+ continue
579
+
580
+ try:
581
+ root_tag = lxml.etree.parse(str(xml_file)).getroot().tag
582
+ root_name = root_tag.split("}")[-1] if "}" in root_tag else root_tag
583
+
584
+ if root_name in declarable_roots and path_str not in declared_parts:
585
+ errors.append(
586
+ f" {path_str}: File with <{root_name}> root not declared in [Content_Types].xml"
587
+ )
588
+
589
+ except Exception:
590
+ continue
591
+
592
+ for file_path in all_files:
593
+ if file_path.suffix.lower() in {".xml", ".rels"}:
594
+ continue
595
+ if file_path.name == "[Content_Types].xml":
596
+ continue
597
+ if "_rels" in file_path.parts or "docProps" in file_path.parts:
598
+ continue
599
+
600
+ extension = file_path.suffix.lstrip(".").lower()
601
+ if extension and extension not in declared_extensions:
602
+ if extension in media_extensions:
603
+ relative_path = file_path.relative_to(self.unpacked_dir)
604
+ errors.append(
605
+ f' {relative_path}: File with extension \'{extension}\' not declared in [Content_Types].xml - should add: <Default Extension="{extension}" ContentType="{media_extensions[extension]}"/>'
606
+ )
607
+
608
+ except Exception as e:
609
+ errors.append(f" Error parsing [Content_Types].xml: {e}")
610
+
611
+ if errors:
612
+ print(f"FAILED - Found {len(errors)} content type declaration errors:")
613
+ for error in errors:
614
+ print(error)
615
+ return False
616
+ else:
617
+ if self.verbose:
618
+ print(
619
+ "PASSED - All content files are properly declared in [Content_Types].xml"
620
+ )
621
+ return True
622
+
623
+ def validate_file_against_xsd(self, xml_file, verbose=False):
624
+ xml_file = Path(xml_file).resolve()
625
+ unpacked_dir = self.unpacked_dir.resolve()
626
+
627
+ is_valid, current_errors = self._validate_single_file_xsd(
628
+ xml_file, unpacked_dir
629
+ )
630
+
631
+ if is_valid is None:
632
+ return None, set()
633
+ elif is_valid:
634
+ return True, set()
635
+
636
+ original_errors = self._get_original_file_errors(xml_file)
637
+
638
+ assert current_errors is not None
639
+ new_errors = current_errors - original_errors
640
+
641
+ new_errors = {
642
+ e for e in new_errors
643
+ if not any(pattern in e for pattern in self.IGNORED_VALIDATION_ERRORS)
644
+ }
645
+
646
+ if new_errors:
647
+ if verbose:
648
+ relative_path = xml_file.relative_to(unpacked_dir)
649
+ print(f"FAILED - {relative_path}: {len(new_errors)} new error(s)")
650
+ for error in list(new_errors)[:3]:
651
+ truncated = error[:250] + "..." if len(error) > 250 else error
652
+ print(f" - {truncated}")
653
+ return False, new_errors
654
+ else:
655
+ if verbose:
656
+ print(
657
+ f"PASSED - No new errors (original had {len(current_errors)} errors)"
658
+ )
659
+ return True, set()
660
+
661
+ def validate_against_xsd(self):
662
+ new_errors = []
663
+ original_error_count = 0
664
+ valid_count = 0
665
+ skipped_count = 0
666
+
667
+ for xml_file in self.xml_files:
668
+ relative_path = str(xml_file.relative_to(self.unpacked_dir))
669
+ is_valid, new_file_errors = self.validate_file_against_xsd(
670
+ xml_file, verbose=False
671
+ )
672
+
673
+ if is_valid is None:
674
+ skipped_count += 1
675
+ continue
676
+ elif is_valid and not new_file_errors:
677
+ valid_count += 1
678
+ continue
679
+ elif is_valid:
680
+ original_error_count += 1
681
+ valid_count += 1
682
+ continue
683
+
684
+ new_errors.append(f" {relative_path}: {len(new_file_errors)} new error(s)")
685
+ for error in list(new_file_errors)[:3]:
686
+ new_errors.append(
687
+ f" - {error[:250]}..." if len(error) > 250 else f" - {error}"
688
+ )
689
+
690
+ if self.verbose:
691
+ print(f"Validated {len(self.xml_files)} files:")
692
+ print(f" - Valid: {valid_count}")
693
+ print(f" - Skipped (no schema): {skipped_count}")
694
+ if original_error_count:
695
+ print(f" - With original errors (ignored): {original_error_count}")
696
+ print(
697
+ f" - With NEW errors: {len(new_errors) > 0 and len([e for e in new_errors if not e.startswith(' ')]) or 0}"
698
+ )
699
+
700
+ if new_errors:
701
+ print("\nFAILED - Found NEW validation errors:")
702
+ for error in new_errors:
703
+ print(error)
704
+ return False
705
+ else:
706
+ if self.verbose:
707
+ print("\nPASSED - No new XSD validation errors introduced")
708
+ return True
709
+
710
+ def _get_schema_path(self, xml_file):
711
+ if xml_file.name in self.SCHEMA_MAPPINGS:
712
+ return self.schemas_dir / self.SCHEMA_MAPPINGS[xml_file.name]
713
+
714
+ if xml_file.suffix == ".rels":
715
+ return self.schemas_dir / self.SCHEMA_MAPPINGS[".rels"]
716
+
717
+ if "charts/" in str(xml_file) and xml_file.name.startswith("chart"):
718
+ return self.schemas_dir / self.SCHEMA_MAPPINGS["chart"]
719
+
720
+ if "theme/" in str(xml_file) and xml_file.name.startswith("theme"):
721
+ return self.schemas_dir / self.SCHEMA_MAPPINGS["theme"]
722
+
723
+ if xml_file.parent.name in self.MAIN_CONTENT_FOLDERS:
724
+ return self.schemas_dir / self.SCHEMA_MAPPINGS[xml_file.parent.name]
725
+
726
+ return None
727
+
728
+ def _clean_ignorable_namespaces(self, xml_doc):
729
+ xml_string = lxml.etree.tostring(xml_doc, encoding="unicode")
730
+ xml_copy = lxml.etree.fromstring(xml_string)
731
+
732
+ for elem in xml_copy.iter():
733
+ attrs_to_remove = []
734
+
735
+ for attr in elem.attrib:
736
+ if "{" in attr:
737
+ ns = attr.split("}")[0][1:]
738
+ if ns not in self.OOXML_NAMESPACES:
739
+ attrs_to_remove.append(attr)
740
+
741
+ for attr in attrs_to_remove:
742
+ del elem.attrib[attr]
743
+
744
+ self._remove_ignorable_elements(xml_copy)
745
+
746
+ return lxml.etree.ElementTree(xml_copy)
747
+
748
+ def _remove_ignorable_elements(self, root):
749
+ elements_to_remove = []
750
+
751
+ for elem in list(root):
752
+ if not hasattr(elem, "tag") or callable(elem.tag):
753
+ continue
754
+
755
+ tag_str = str(elem.tag)
756
+ if tag_str.startswith("{"):
757
+ ns = tag_str.split("}")[0][1:]
758
+ if ns not in self.OOXML_NAMESPACES:
759
+ elements_to_remove.append(elem)
760
+ continue
761
+
762
+ self._remove_ignorable_elements(elem)
763
+
764
+ for elem in elements_to_remove:
765
+ root.remove(elem)
766
+
767
+ def _preprocess_for_mc_ignorable(self, xml_doc):
768
+ root = xml_doc.getroot()
769
+
770
+ if f"{{{self.MC_NAMESPACE}}}Ignorable" in root.attrib:
771
+ del root.attrib[f"{{{self.MC_NAMESPACE}}}Ignorable"]
772
+
773
+ return xml_doc
774
+
775
+ def _preprocess_for_schema(self, xml_doc, relative_path):
776
+ return xml_doc
777
+
778
+ def _validate_single_file_xsd(self, xml_file, base_path, schema_path=None):
779
+ schema_path = schema_path or self._get_schema_path(xml_file)
780
+ if not schema_path:
781
+ return None, None
782
+
783
+ try:
784
+ schema = _load_schema(str(schema_path))
785
+
786
+ with open(xml_file, "r") as f:
787
+ xml_doc = lxml.etree.parse(f)
788
+
789
+ xml_doc, _ = self._remove_template_tags_from_text_nodes(xml_doc)
790
+ xml_doc = self._preprocess_for_mc_ignorable(xml_doc)
791
+
792
+ relative_path = xml_file.relative_to(base_path)
793
+ if (
794
+ relative_path.parts
795
+ and relative_path.parts[0] in self.MAIN_CONTENT_FOLDERS
796
+ ):
797
+ xml_doc = self._clean_ignorable_namespaces(xml_doc)
798
+
799
+ xml_doc = self._preprocess_for_schema(xml_doc, relative_path)
800
+
801
+ if schema.validate(xml_doc):
802
+ return True, set()
803
+ else:
804
+ errors = set()
805
+ for error in schema.error_log:
806
+ errors.add(error.message)
807
+ return False, errors
808
+
809
+ except Exception as e:
810
+ return False, {str(e)}
811
+
812
+ def _get_original_file_errors(self, xml_file, schema_path=None):
813
+ if self.original_file is None:
814
+ return set()
815
+
816
+ import tempfile
817
+ import zipfile
818
+
819
+ xml_file = Path(xml_file).resolve()
820
+ unpacked_dir = self.unpacked_dir.resolve()
821
+ relative_path = xml_file.relative_to(unpacked_dir)
822
+
823
+ with tempfile.TemporaryDirectory() as temp_dir:
824
+ temp_path = Path(temp_dir)
825
+
826
+ try:
827
+ with zipfile.ZipFile(self.original_file, "r") as zip_ref:
828
+ safe_extract(zip_ref, temp_path)
829
+ except (zipfile.BadZipFile, ValueError, OSError):
830
+ return set()
831
+
832
+ original_xml_file = temp_path / relative_path
833
+
834
+ if not original_xml_file.exists():
835
+ return set()
836
+
837
+ is_valid, errors = self._validate_single_file_xsd(
838
+ original_xml_file, temp_path, schema_path=schema_path
839
+ )
840
+ return errors if errors else set()
841
+
842
+ def _remove_template_tags_from_text_nodes(self, xml_doc):
843
+ warnings = []
844
+ template_pattern = re.compile(r"\{\{[^}]*\}\}")
845
+
846
+ xml_string = lxml.etree.tostring(xml_doc, encoding="unicode")
847
+ xml_copy = lxml.etree.fromstring(xml_string)
848
+
849
+ def process_text_content(text, content_type):
850
+ if not text:
851
+ return text
852
+ matches = list(template_pattern.finditer(text))
853
+ if matches:
854
+ for match in matches:
855
+ warnings.append(
856
+ f"Found template tag in {content_type}: {match.group()}"
857
+ )
858
+ return template_pattern.sub("", text)
859
+ return text
860
+
861
+ for elem in xml_copy.iter():
862
+ if not hasattr(elem, "tag") or callable(elem.tag):
863
+ continue
864
+ tag_str = str(elem.tag)
865
+ if tag_str.endswith("}t") or tag_str == "t":
866
+ continue
867
+
868
+ elem.text = process_text_content(elem.text, "text content")
869
+ elem.tail = process_text_content(elem.tail, "tail content")
870
+
871
+ return lxml.etree.ElementTree(xml_copy), warnings
872
+
873
+
874
+ if __name__ == "__main__":
875
+ raise RuntimeError("This module should not be run directly.")