@preapexis/piexis 0.1.2

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 (348) hide show
  1. package/.github/workflows/npm-publish.yml +63 -0
  2. package/AGENTS.md +58 -0
  3. package/PERMISSION_MODES_PLAN.md +279 -0
  4. package/README.md +207 -0
  5. package/WHAT_YOU_GET.md +153 -0
  6. package/eval/README.md +72 -0
  7. package/eval/permission-cases.json +28 -0
  8. package/eval/permissions.mjs +103 -0
  9. package/extensions/ask-question.ts +111 -0
  10. package/extensions/background-tasks.ts +433 -0
  11. package/extensions/background-worker.ts +50 -0
  12. package/extensions/glob.ts +32 -0
  13. package/extensions/mode.ts +397 -0
  14. package/extensions/ui.ts +134 -0
  15. package/lib/bash-approvals.ts +113 -0
  16. package/lib/bash-policy.ts +164 -0
  17. package/lib/mode-policy.ts +174 -0
  18. package/lib/path-policy.ts +182 -0
  19. package/lib/permission-classifier.ts +128 -0
  20. package/lib/permission-config.ts +91 -0
  21. package/lib/permission-denials.ts +32 -0
  22. package/lib/permission-intent.ts +128 -0
  23. package/lib/permission-taxonomy.ts +15 -0
  24. package/lib/task-broker.ts +65 -0
  25. package/lib/task-checkout.ts +39 -0
  26. package/lib/task-git.ts +44 -0
  27. package/lib/task-patch.ts +106 -0
  28. package/lib/task-permissions.ts +51 -0
  29. package/lib/task-report.ts +62 -0
  30. package/lib/task-worktree-policy.ts +56 -0
  31. package/package.json +51 -0
  32. package/prompts/commit.md +7 -0
  33. package/prompts/init.md +66 -0
  34. package/prompts/summary.md +14 -0
  35. package/skills/claude-api/LICENSE.txt +202 -0
  36. package/skills/claude-api/SKILL.md +572 -0
  37. package/skills/claude-api/csharp/claude-api/README.md +362 -0
  38. package/skills/claude-api/csharp/claude-api/batches.md +14 -0
  39. package/skills/claude-api/csharp/claude-api/files-api.md +25 -0
  40. package/skills/claude-api/csharp/claude-api/streaming.md +28 -0
  41. package/skills/claude-api/csharp/claude-api/tool-use.md +164 -0
  42. package/skills/claude-api/curl/examples.md +256 -0
  43. package/skills/claude-api/curl/managed-agents.md +371 -0
  44. package/skills/claude-api/go/claude-api/README.md +188 -0
  45. package/skills/claude-api/go/claude-api/files-api.md +23 -0
  46. package/skills/claude-api/go/claude-api/streaming.md +43 -0
  47. package/skills/claude-api/go/claude-api/tool-use.md +220 -0
  48. package/skills/claude-api/go/managed-agents/README.md +564 -0
  49. package/skills/claude-api/java/claude-api/README.md +238 -0
  50. package/skills/claude-api/java/claude-api/files-api.md +27 -0
  51. package/skills/claude-api/java/claude-api/streaming.md +24 -0
  52. package/skills/claude-api/java/claude-api/tool-use.md +228 -0
  53. package/skills/claude-api/java/managed-agents/README.md +443 -0
  54. package/skills/claude-api/php/claude-api/README.md +174 -0
  55. package/skills/claude-api/php/claude-api/batches.md +15 -0
  56. package/skills/claude-api/php/claude-api/files-api.md +13 -0
  57. package/skills/claude-api/php/claude-api/streaming.md +27 -0
  58. package/skills/claude-api/php/claude-api/tool-use.md +253 -0
  59. package/skills/claude-api/php/managed-agents/README.md +443 -0
  60. package/skills/claude-api/python/claude-api/README.md +565 -0
  61. package/skills/claude-api/python/claude-api/batches.md +198 -0
  62. package/skills/claude-api/python/claude-api/files-api.md +170 -0
  63. package/skills/claude-api/python/claude-api/sdk-upgrade.md +286 -0
  64. package/skills/claude-api/python/claude-api/streaming.md +179 -0
  65. package/skills/claude-api/python/claude-api/tool-use.md +627 -0
  66. package/skills/claude-api/python/managed-agents/README.md +335 -0
  67. package/skills/claude-api/ruby/claude-api/README.md +134 -0
  68. package/skills/claude-api/ruby/claude-api/streaming.md +16 -0
  69. package/skills/claude-api/ruby/claude-api/tool-use.md +41 -0
  70. package/skills/claude-api/ruby/managed-agents/README.md +394 -0
  71. package/skills/claude-api/shared/admin-api.md +179 -0
  72. package/skills/claude-api/shared/agent-design.md +101 -0
  73. package/skills/claude-api/shared/anthropic-cli.md +269 -0
  74. package/skills/claude-api/shared/claude-platform-on-aws.md +59 -0
  75. package/skills/claude-api/shared/cost-optimization.md +233 -0
  76. package/skills/claude-api/shared/error-codes.md +262 -0
  77. package/skills/claude-api/shared/live-sources.md +166 -0
  78. package/skills/claude-api/shared/managed-agents-api-reference.md +455 -0
  79. package/skills/claude-api/shared/managed-agents-client-patterns.md +220 -0
  80. package/skills/claude-api/shared/managed-agents-core.md +359 -0
  81. package/skills/claude-api/shared/managed-agents-environments.md +226 -0
  82. package/skills/claude-api/shared/managed-agents-events.md +290 -0
  83. package/skills/claude-api/shared/managed-agents-memory.md +201 -0
  84. package/skills/claude-api/shared/managed-agents-multiagent.md +260 -0
  85. package/skills/claude-api/shared/managed-agents-onboarding.md +82 -0
  86. package/skills/claude-api/shared/managed-agents-outcomes.md +108 -0
  87. package/skills/claude-api/shared/managed-agents-overview.md +77 -0
  88. package/skills/claude-api/shared/managed-agents-scheduled-deployments.md +156 -0
  89. package/skills/claude-api/shared/managed-agents-self-hosted-sandboxes.md +282 -0
  90. package/skills/claude-api/shared/managed-agents-tools.md +504 -0
  91. package/skills/claude-api/shared/managed-agents-webhooks.md +143 -0
  92. package/skills/claude-api/shared/model-migration.md +1872 -0
  93. package/skills/claude-api/shared/models.md +142 -0
  94. package/skills/claude-api/shared/platform-availability.md +53 -0
  95. package/skills/claude-api/shared/prompt-audit.md +223 -0
  96. package/skills/claude-api/shared/prompt-caching.md +292 -0
  97. package/skills/claude-api/shared/token-counting.md +56 -0
  98. package/skills/claude-api/shared/tool-use-concepts.md +526 -0
  99. package/skills/claude-api/typescript/claude-api/README.md +405 -0
  100. package/skills/claude-api/typescript/claude-api/batches.md +106 -0
  101. package/skills/claude-api/typescript/claude-api/files-api.md +98 -0
  102. package/skills/claude-api/typescript/claude-api/streaming.md +178 -0
  103. package/skills/claude-api/typescript/claude-api/tool-use.md +586 -0
  104. package/skills/claude-api/typescript/managed-agents/README.md +359 -0
  105. package/skills/code-review/SKILL.md +34 -0
  106. package/skills/code-review/agents/openai.yaml +3 -0
  107. package/skills/codebase-design/DEEPENING.md +37 -0
  108. package/skills/codebase-design/DESIGN-IT-TWICE.md +44 -0
  109. package/skills/codebase-design/SKILL.md +40 -0
  110. package/skills/diagnosing-bugs/SKILL.md +38 -0
  111. package/skills/diagnosing-bugs/agents/openai.yaml +3 -0
  112. package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +44 -0
  113. package/skills/docx/LICENSE.txt +30 -0
  114. package/skills/docx/SKILL.md +93 -0
  115. package/skills/docx/scripts/__init__.py +1 -0
  116. package/skills/docx/scripts/accept_changes.py +135 -0
  117. package/skills/docx/scripts/comment.py +368 -0
  118. package/skills/docx/scripts/merge_runs.py +310 -0
  119. package/skills/docx/scripts/office/helpers/__init__.py +111 -0
  120. package/skills/docx/scripts/office/helpers/pptx_chart.py +170 -0
  121. package/skills/docx/scripts/office/helpers/pptx_slide.py +60 -0
  122. package/skills/docx/scripts/office/helpers/pptx_theme.py +114 -0
  123. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
  124. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
  125. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
  126. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
  127. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
  128. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
  129. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
  130. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
  131. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
  132. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
  133. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
  134. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
  135. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
  136. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
  137. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
  138. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
  139. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
  140. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
  141. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
  142. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
  143. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
  144. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
  145. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
  146. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
  147. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
  148. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
  149. package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
  150. package/skills/docx/scripts/office/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
  151. package/skills/docx/scripts/office/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
  152. package/skills/docx/scripts/office/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
  153. package/skills/docx/scripts/office/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
  154. package/skills/docx/scripts/office/schemas/mce/mc.xsd +75 -0
  155. package/skills/docx/scripts/office/schemas/microsoft/wml-2010.xsd +560 -0
  156. package/skills/docx/scripts/office/schemas/microsoft/wml-2012.xsd +67 -0
  157. package/skills/docx/scripts/office/schemas/microsoft/wml-2018.xsd +14 -0
  158. package/skills/docx/scripts/office/schemas/microsoft/wml-cex-2018.xsd +20 -0
  159. package/skills/docx/scripts/office/schemas/microsoft/wml-cid-2016.xsd +13 -0
  160. package/skills/docx/scripts/office/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
  161. package/skills/docx/scripts/office/schemas/microsoft/wml-symex-2015.xsd +8 -0
  162. package/skills/docx/scripts/office/soffice.py +192 -0
  163. package/skills/docx/scripts/office/validate.py +173 -0
  164. package/skills/docx/scripts/office/validators/__init__.py +15 -0
  165. package/skills/docx/scripts/office/validators/base.py +875 -0
  166. package/skills/docx/scripts/office/validators/docx.py +466 -0
  167. package/skills/docx/scripts/office/validators/pptx.py +441 -0
  168. package/skills/docx/scripts/office/validators/redlining.py +299 -0
  169. package/skills/docx/scripts/templates/comments.xml +3 -0
  170. package/skills/docx/scripts/templates/commentsExtended.xml +3 -0
  171. package/skills/docx/scripts/templates/commentsExtensible.xml +3 -0
  172. package/skills/docx/scripts/templates/commentsIds.xml +3 -0
  173. package/skills/docx/scripts/templates/people.xml +3 -0
  174. package/skills/frontend-design/LICENSE.txt +177 -0
  175. package/skills/frontend-design/SKILL.md +27 -0
  176. package/skills/grilling/SKILL.md +41 -0
  177. package/skills/lean-build/SKILL.md +22 -0
  178. package/skills/lean-build/agents/openai.yaml +4 -0
  179. package/skills/mcp-builder/LICENSE.txt +202 -0
  180. package/skills/mcp-builder/SKILL.md +235 -0
  181. package/skills/mcp-builder/reference/evaluation.md +602 -0
  182. package/skills/mcp-builder/reference/mcp_best_practices.md +249 -0
  183. package/skills/mcp-builder/reference/node_mcp_server.md +970 -0
  184. package/skills/mcp-builder/reference/python_mcp_server.md +719 -0
  185. package/skills/mcp-builder/scripts/connections.py +151 -0
  186. package/skills/mcp-builder/scripts/evaluation.py +373 -0
  187. package/skills/mcp-builder/scripts/example_evaluation.xml +22 -0
  188. package/skills/mcp-builder/scripts/requirements.txt +2 -0
  189. package/skills/migration/SKILL.md +17 -0
  190. package/skills/migration/agents/openai.yaml +4 -0
  191. package/skills/pdf/LICENSE.txt +30 -0
  192. package/skills/pdf/SKILL.md +27 -0
  193. package/skills/pdf/forms.md +294 -0
  194. package/skills/pdf/reference.md +612 -0
  195. package/skills/pdf/scripts/check_bounding_boxes.py +65 -0
  196. package/skills/pdf/scripts/check_fillable_fields.py +11 -0
  197. package/skills/pdf/scripts/convert_pdf_to_images.py +33 -0
  198. package/skills/pdf/scripts/create_validation_image.py +37 -0
  199. package/skills/pdf/scripts/extract_form_field_info.py +122 -0
  200. package/skills/pdf/scripts/extract_form_structure.py +115 -0
  201. package/skills/pdf/scripts/fill_fillable_fields.py +98 -0
  202. package/skills/pdf/scripts/fill_pdf_form_with_annotations.py +107 -0
  203. package/skills/pptx/LICENSE.txt +30 -0
  204. package/skills/pptx/SKILL.md +240 -0
  205. package/skills/pptx/scripts/__init__.py +0 -0
  206. package/skills/pptx/scripts/add_slide.py +367 -0
  207. package/skills/pptx/scripts/clean.py +309 -0
  208. package/skills/pptx/scripts/office/helpers/__init__.py +111 -0
  209. package/skills/pptx/scripts/office/helpers/pptx_chart.py +170 -0
  210. package/skills/pptx/scripts/office/helpers/pptx_slide.py +60 -0
  211. package/skills/pptx/scripts/office/helpers/pptx_theme.py +114 -0
  212. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
  213. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
  214. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
  215. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
  216. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
  217. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
  218. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
  219. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
  220. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
  221. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
  222. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
  223. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
  224. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
  225. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
  226. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
  227. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
  228. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
  229. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
  230. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
  231. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
  232. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
  233. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
  234. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
  235. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
  236. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
  237. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
  238. package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
  239. package/skills/pptx/scripts/office/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
  240. package/skills/pptx/scripts/office/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
  241. package/skills/pptx/scripts/office/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
  242. package/skills/pptx/scripts/office/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
  243. package/skills/pptx/scripts/office/schemas/mce/mc.xsd +75 -0
  244. package/skills/pptx/scripts/office/schemas/microsoft/wml-2010.xsd +560 -0
  245. package/skills/pptx/scripts/office/schemas/microsoft/wml-2012.xsd +67 -0
  246. package/skills/pptx/scripts/office/schemas/microsoft/wml-2018.xsd +14 -0
  247. package/skills/pptx/scripts/office/schemas/microsoft/wml-cex-2018.xsd +20 -0
  248. package/skills/pptx/scripts/office/schemas/microsoft/wml-cid-2016.xsd +13 -0
  249. package/skills/pptx/scripts/office/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
  250. package/skills/pptx/scripts/office/schemas/microsoft/wml-symex-2015.xsd +8 -0
  251. package/skills/pptx/scripts/office/soffice.py +192 -0
  252. package/skills/pptx/scripts/office/validate.py +173 -0
  253. package/skills/pptx/scripts/office/validators/__init__.py +15 -0
  254. package/skills/pptx/scripts/office/validators/base.py +875 -0
  255. package/skills/pptx/scripts/office/validators/docx.py +466 -0
  256. package/skills/pptx/scripts/office/validators/pptx.py +441 -0
  257. package/skills/pptx/scripts/office/validators/redlining.py +299 -0
  258. package/skills/pptx/scripts/thumbnail.py +311 -0
  259. package/skills/safe-refactor/SKILL.md +16 -0
  260. package/skills/safe-refactor/agents/openai.yaml +4 -0
  261. package/skills/tdd/SKILL.md +18 -0
  262. package/skills/tdd/agents/openai.yaml +3 -0
  263. package/skills/tdd/mocking.md +59 -0
  264. package/skills/tdd/tests.md +77 -0
  265. package/skills/verify-and-stop/SKILL.md +16 -0
  266. package/skills/verify-and-stop/agents/openai.yaml +4 -0
  267. package/skills/webapp-testing/LICENSE.txt +202 -0
  268. package/skills/webapp-testing/SKILL.md +96 -0
  269. package/skills/webapp-testing/examples/console_logging.py +35 -0
  270. package/skills/webapp-testing/examples/element_discovery.py +40 -0
  271. package/skills/webapp-testing/examples/static_html_automation.py +33 -0
  272. package/skills/webapp-testing/scripts/with_server.py +106 -0
  273. package/skills/writing-for-agents/SKILL-MECHANICS.md +22 -0
  274. package/skills/writing-for-agents/SKILL.md +28 -0
  275. package/skills/writing-for-agents/agents/openai.yaml +3 -0
  276. package/skills/xlsx/LICENSE.txt +30 -0
  277. package/skills/xlsx/SKILL.md +101 -0
  278. package/skills/xlsx/scripts/office/helpers/__init__.py +111 -0
  279. package/skills/xlsx/scripts/office/helpers/pptx_chart.py +170 -0
  280. package/skills/xlsx/scripts/office/helpers/pptx_slide.py +60 -0
  281. package/skills/xlsx/scripts/office/helpers/pptx_theme.py +114 -0
  282. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
  283. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
  284. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
  285. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
  286. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
  287. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
  288. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
  289. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
  290. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
  291. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
  292. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
  293. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
  294. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
  295. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
  296. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
  297. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
  298. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
  299. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
  300. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
  301. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
  302. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
  303. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
  304. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
  305. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
  306. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
  307. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
  308. package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
  309. package/skills/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
  310. package/skills/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
  311. package/skills/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
  312. package/skills/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
  313. package/skills/xlsx/scripts/office/schemas/mce/mc.xsd +75 -0
  314. package/skills/xlsx/scripts/office/schemas/microsoft/wml-2010.xsd +560 -0
  315. package/skills/xlsx/scripts/office/schemas/microsoft/wml-2012.xsd +67 -0
  316. package/skills/xlsx/scripts/office/schemas/microsoft/wml-2018.xsd +14 -0
  317. package/skills/xlsx/scripts/office/schemas/microsoft/wml-cex-2018.xsd +20 -0
  318. package/skills/xlsx/scripts/office/schemas/microsoft/wml-cid-2016.xsd +13 -0
  319. package/skills/xlsx/scripts/office/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
  320. package/skills/xlsx/scripts/office/schemas/microsoft/wml-symex-2015.xsd +8 -0
  321. package/skills/xlsx/scripts/office/soffice.py +192 -0
  322. package/skills/xlsx/scripts/office/validate.py +173 -0
  323. package/skills/xlsx/scripts/office/validators/__init__.py +15 -0
  324. package/skills/xlsx/scripts/office/validators/base.py +875 -0
  325. package/skills/xlsx/scripts/office/validators/docx.py +466 -0
  326. package/skills/xlsx/scripts/office/validators/pptx.py +441 -0
  327. package/skills/xlsx/scripts/office/validators/redlining.py +299 -0
  328. package/skills/xlsx/scripts/recalc.py +308 -0
  329. package/skills-lock.json +359 -0
  330. package/tests/auto-permissions.test.mjs +315 -0
  331. package/tests/background-tasks.test.mjs +27 -0
  332. package/tests/background-worker.test.mjs +60 -0
  333. package/tests/bash-permissions.test.mjs +276 -0
  334. package/tests/glob.test.mjs +31 -0
  335. package/tests/mode.test.mjs +62 -0
  336. package/tests/permission-evaluation.test.mjs +70 -0
  337. package/tests/permission-foundation.test.mjs +194 -0
  338. package/tests/permission-policy.test.mjs +158 -0
  339. package/tests/runtime/README.md +51 -0
  340. package/tests/runtime/harness.mjs +190 -0
  341. package/tests/runtime/permissions.test.mjs +192 -0
  342. package/tests/runtime/tui.test.mjs +60 -0
  343. package/tests/skills-routing.test.mjs +51 -0
  344. package/tests/task-integration.test.mjs +324 -0
  345. package/tests/task-permissions.test.mjs +178 -0
  346. package/tests/task-worktree-policy.test.mjs +53 -0
  347. package/themes/orange.json +82 -0
  348. package/tsconfig.json +13 -0
@@ -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.")