@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.
- package/.github/workflows/npm-publish.yml +63 -0
- package/AGENTS.md +58 -0
- package/PERMISSION_MODES_PLAN.md +279 -0
- package/README.md +207 -0
- package/WHAT_YOU_GET.md +153 -0
- package/eval/README.md +72 -0
- package/eval/permission-cases.json +28 -0
- package/eval/permissions.mjs +103 -0
- package/extensions/ask-question.ts +111 -0
- package/extensions/background-tasks.ts +433 -0
- package/extensions/background-worker.ts +50 -0
- package/extensions/glob.ts +32 -0
- package/extensions/mode.ts +397 -0
- package/extensions/ui.ts +134 -0
- package/lib/bash-approvals.ts +113 -0
- package/lib/bash-policy.ts +164 -0
- package/lib/mode-policy.ts +174 -0
- package/lib/path-policy.ts +182 -0
- package/lib/permission-classifier.ts +128 -0
- package/lib/permission-config.ts +91 -0
- package/lib/permission-denials.ts +32 -0
- package/lib/permission-intent.ts +128 -0
- package/lib/permission-taxonomy.ts +15 -0
- package/lib/task-broker.ts +65 -0
- package/lib/task-checkout.ts +39 -0
- package/lib/task-git.ts +44 -0
- package/lib/task-patch.ts +106 -0
- package/lib/task-permissions.ts +51 -0
- package/lib/task-report.ts +62 -0
- package/lib/task-worktree-policy.ts +56 -0
- package/package.json +51 -0
- package/prompts/commit.md +7 -0
- package/prompts/init.md +66 -0
- package/prompts/summary.md +14 -0
- package/skills/claude-api/LICENSE.txt +202 -0
- package/skills/claude-api/SKILL.md +572 -0
- package/skills/claude-api/csharp/claude-api/README.md +362 -0
- package/skills/claude-api/csharp/claude-api/batches.md +14 -0
- package/skills/claude-api/csharp/claude-api/files-api.md +25 -0
- package/skills/claude-api/csharp/claude-api/streaming.md +28 -0
- package/skills/claude-api/csharp/claude-api/tool-use.md +164 -0
- package/skills/claude-api/curl/examples.md +256 -0
- package/skills/claude-api/curl/managed-agents.md +371 -0
- package/skills/claude-api/go/claude-api/README.md +188 -0
- package/skills/claude-api/go/claude-api/files-api.md +23 -0
- package/skills/claude-api/go/claude-api/streaming.md +43 -0
- package/skills/claude-api/go/claude-api/tool-use.md +220 -0
- package/skills/claude-api/go/managed-agents/README.md +564 -0
- package/skills/claude-api/java/claude-api/README.md +238 -0
- package/skills/claude-api/java/claude-api/files-api.md +27 -0
- package/skills/claude-api/java/claude-api/streaming.md +24 -0
- package/skills/claude-api/java/claude-api/tool-use.md +228 -0
- package/skills/claude-api/java/managed-agents/README.md +443 -0
- package/skills/claude-api/php/claude-api/README.md +174 -0
- package/skills/claude-api/php/claude-api/batches.md +15 -0
- package/skills/claude-api/php/claude-api/files-api.md +13 -0
- package/skills/claude-api/php/claude-api/streaming.md +27 -0
- package/skills/claude-api/php/claude-api/tool-use.md +253 -0
- package/skills/claude-api/php/managed-agents/README.md +443 -0
- package/skills/claude-api/python/claude-api/README.md +565 -0
- package/skills/claude-api/python/claude-api/batches.md +198 -0
- package/skills/claude-api/python/claude-api/files-api.md +170 -0
- package/skills/claude-api/python/claude-api/sdk-upgrade.md +286 -0
- package/skills/claude-api/python/claude-api/streaming.md +179 -0
- package/skills/claude-api/python/claude-api/tool-use.md +627 -0
- package/skills/claude-api/python/managed-agents/README.md +335 -0
- package/skills/claude-api/ruby/claude-api/README.md +134 -0
- package/skills/claude-api/ruby/claude-api/streaming.md +16 -0
- package/skills/claude-api/ruby/claude-api/tool-use.md +41 -0
- package/skills/claude-api/ruby/managed-agents/README.md +394 -0
- package/skills/claude-api/shared/admin-api.md +179 -0
- package/skills/claude-api/shared/agent-design.md +101 -0
- package/skills/claude-api/shared/anthropic-cli.md +269 -0
- package/skills/claude-api/shared/claude-platform-on-aws.md +59 -0
- package/skills/claude-api/shared/cost-optimization.md +233 -0
- package/skills/claude-api/shared/error-codes.md +262 -0
- package/skills/claude-api/shared/live-sources.md +166 -0
- package/skills/claude-api/shared/managed-agents-api-reference.md +455 -0
- package/skills/claude-api/shared/managed-agents-client-patterns.md +220 -0
- package/skills/claude-api/shared/managed-agents-core.md +359 -0
- package/skills/claude-api/shared/managed-agents-environments.md +226 -0
- package/skills/claude-api/shared/managed-agents-events.md +290 -0
- package/skills/claude-api/shared/managed-agents-memory.md +201 -0
- package/skills/claude-api/shared/managed-agents-multiagent.md +260 -0
- package/skills/claude-api/shared/managed-agents-onboarding.md +82 -0
- package/skills/claude-api/shared/managed-agents-outcomes.md +108 -0
- package/skills/claude-api/shared/managed-agents-overview.md +77 -0
- package/skills/claude-api/shared/managed-agents-scheduled-deployments.md +156 -0
- package/skills/claude-api/shared/managed-agents-self-hosted-sandboxes.md +282 -0
- package/skills/claude-api/shared/managed-agents-tools.md +504 -0
- package/skills/claude-api/shared/managed-agents-webhooks.md +143 -0
- package/skills/claude-api/shared/model-migration.md +1872 -0
- package/skills/claude-api/shared/models.md +142 -0
- package/skills/claude-api/shared/platform-availability.md +53 -0
- package/skills/claude-api/shared/prompt-audit.md +223 -0
- package/skills/claude-api/shared/prompt-caching.md +292 -0
- package/skills/claude-api/shared/token-counting.md +56 -0
- package/skills/claude-api/shared/tool-use-concepts.md +526 -0
- package/skills/claude-api/typescript/claude-api/README.md +405 -0
- package/skills/claude-api/typescript/claude-api/batches.md +106 -0
- package/skills/claude-api/typescript/claude-api/files-api.md +98 -0
- package/skills/claude-api/typescript/claude-api/streaming.md +178 -0
- package/skills/claude-api/typescript/claude-api/tool-use.md +586 -0
- package/skills/claude-api/typescript/managed-agents/README.md +359 -0
- package/skills/code-review/SKILL.md +34 -0
- package/skills/code-review/agents/openai.yaml +3 -0
- package/skills/codebase-design/DEEPENING.md +37 -0
- package/skills/codebase-design/DESIGN-IT-TWICE.md +44 -0
- package/skills/codebase-design/SKILL.md +40 -0
- package/skills/diagnosing-bugs/SKILL.md +38 -0
- package/skills/diagnosing-bugs/agents/openai.yaml +3 -0
- package/skills/diagnosing-bugs/scripts/hitl-loop.template.sh +44 -0
- package/skills/docx/LICENSE.txt +30 -0
- package/skills/docx/SKILL.md +93 -0
- package/skills/docx/scripts/__init__.py +1 -0
- package/skills/docx/scripts/accept_changes.py +135 -0
- package/skills/docx/scripts/comment.py +368 -0
- package/skills/docx/scripts/merge_runs.py +310 -0
- package/skills/docx/scripts/office/helpers/__init__.py +111 -0
- package/skills/docx/scripts/office/helpers/pptx_chart.py +170 -0
- package/skills/docx/scripts/office/helpers/pptx_slide.py +60 -0
- package/skills/docx/scripts/office/helpers/pptx_theme.py +114 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
- package/skills/docx/scripts/office/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
- package/skills/docx/scripts/office/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
- package/skills/docx/scripts/office/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
- package/skills/docx/scripts/office/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
- package/skills/docx/scripts/office/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
- package/skills/docx/scripts/office/schemas/mce/mc.xsd +75 -0
- package/skills/docx/scripts/office/schemas/microsoft/wml-2010.xsd +560 -0
- package/skills/docx/scripts/office/schemas/microsoft/wml-2012.xsd +67 -0
- package/skills/docx/scripts/office/schemas/microsoft/wml-2018.xsd +14 -0
- package/skills/docx/scripts/office/schemas/microsoft/wml-cex-2018.xsd +20 -0
- package/skills/docx/scripts/office/schemas/microsoft/wml-cid-2016.xsd +13 -0
- package/skills/docx/scripts/office/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
- package/skills/docx/scripts/office/schemas/microsoft/wml-symex-2015.xsd +8 -0
- package/skills/docx/scripts/office/soffice.py +192 -0
- package/skills/docx/scripts/office/validate.py +173 -0
- package/skills/docx/scripts/office/validators/__init__.py +15 -0
- package/skills/docx/scripts/office/validators/base.py +875 -0
- package/skills/docx/scripts/office/validators/docx.py +466 -0
- package/skills/docx/scripts/office/validators/pptx.py +441 -0
- package/skills/docx/scripts/office/validators/redlining.py +299 -0
- package/skills/docx/scripts/templates/comments.xml +3 -0
- package/skills/docx/scripts/templates/commentsExtended.xml +3 -0
- package/skills/docx/scripts/templates/commentsExtensible.xml +3 -0
- package/skills/docx/scripts/templates/commentsIds.xml +3 -0
- package/skills/docx/scripts/templates/people.xml +3 -0
- package/skills/frontend-design/LICENSE.txt +177 -0
- package/skills/frontend-design/SKILL.md +27 -0
- package/skills/grilling/SKILL.md +41 -0
- package/skills/lean-build/SKILL.md +22 -0
- package/skills/lean-build/agents/openai.yaml +4 -0
- package/skills/mcp-builder/LICENSE.txt +202 -0
- package/skills/mcp-builder/SKILL.md +235 -0
- package/skills/mcp-builder/reference/evaluation.md +602 -0
- package/skills/mcp-builder/reference/mcp_best_practices.md +249 -0
- package/skills/mcp-builder/reference/node_mcp_server.md +970 -0
- package/skills/mcp-builder/reference/python_mcp_server.md +719 -0
- package/skills/mcp-builder/scripts/connections.py +151 -0
- package/skills/mcp-builder/scripts/evaluation.py +373 -0
- package/skills/mcp-builder/scripts/example_evaluation.xml +22 -0
- package/skills/mcp-builder/scripts/requirements.txt +2 -0
- package/skills/migration/SKILL.md +17 -0
- package/skills/migration/agents/openai.yaml +4 -0
- package/skills/pdf/LICENSE.txt +30 -0
- package/skills/pdf/SKILL.md +27 -0
- package/skills/pdf/forms.md +294 -0
- package/skills/pdf/reference.md +612 -0
- package/skills/pdf/scripts/check_bounding_boxes.py +65 -0
- package/skills/pdf/scripts/check_fillable_fields.py +11 -0
- package/skills/pdf/scripts/convert_pdf_to_images.py +33 -0
- package/skills/pdf/scripts/create_validation_image.py +37 -0
- package/skills/pdf/scripts/extract_form_field_info.py +122 -0
- package/skills/pdf/scripts/extract_form_structure.py +115 -0
- package/skills/pdf/scripts/fill_fillable_fields.py +98 -0
- package/skills/pdf/scripts/fill_pdf_form_with_annotations.py +107 -0
- package/skills/pptx/LICENSE.txt +30 -0
- package/skills/pptx/SKILL.md +240 -0
- package/skills/pptx/scripts/__init__.py +0 -0
- package/skills/pptx/scripts/add_slide.py +367 -0
- package/skills/pptx/scripts/clean.py +309 -0
- package/skills/pptx/scripts/office/helpers/__init__.py +111 -0
- package/skills/pptx/scripts/office/helpers/pptx_chart.py +170 -0
- package/skills/pptx/scripts/office/helpers/pptx_slide.py +60 -0
- package/skills/pptx/scripts/office/helpers/pptx_theme.py +114 -0
- package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
- package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
- package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
- package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
- package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
- package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
- package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
- package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
- package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
- package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
- package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
- package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
- package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
- package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
- package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
- package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
- package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
- package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
- package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
- package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
- package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
- package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
- package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
- package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
- package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
- package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
- package/skills/pptx/scripts/office/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
- package/skills/pptx/scripts/office/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
- package/skills/pptx/scripts/office/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
- package/skills/pptx/scripts/office/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
- package/skills/pptx/scripts/office/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
- package/skills/pptx/scripts/office/schemas/mce/mc.xsd +75 -0
- package/skills/pptx/scripts/office/schemas/microsoft/wml-2010.xsd +560 -0
- package/skills/pptx/scripts/office/schemas/microsoft/wml-2012.xsd +67 -0
- package/skills/pptx/scripts/office/schemas/microsoft/wml-2018.xsd +14 -0
- package/skills/pptx/scripts/office/schemas/microsoft/wml-cex-2018.xsd +20 -0
- package/skills/pptx/scripts/office/schemas/microsoft/wml-cid-2016.xsd +13 -0
- package/skills/pptx/scripts/office/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
- package/skills/pptx/scripts/office/schemas/microsoft/wml-symex-2015.xsd +8 -0
- package/skills/pptx/scripts/office/soffice.py +192 -0
- package/skills/pptx/scripts/office/validate.py +173 -0
- package/skills/pptx/scripts/office/validators/__init__.py +15 -0
- package/skills/pptx/scripts/office/validators/base.py +875 -0
- package/skills/pptx/scripts/office/validators/docx.py +466 -0
- package/skills/pptx/scripts/office/validators/pptx.py +441 -0
- package/skills/pptx/scripts/office/validators/redlining.py +299 -0
- package/skills/pptx/scripts/thumbnail.py +311 -0
- package/skills/safe-refactor/SKILL.md +16 -0
- package/skills/safe-refactor/agents/openai.yaml +4 -0
- package/skills/tdd/SKILL.md +18 -0
- package/skills/tdd/agents/openai.yaml +3 -0
- package/skills/tdd/mocking.md +59 -0
- package/skills/tdd/tests.md +77 -0
- package/skills/verify-and-stop/SKILL.md +16 -0
- package/skills/verify-and-stop/agents/openai.yaml +4 -0
- package/skills/webapp-testing/LICENSE.txt +202 -0
- package/skills/webapp-testing/SKILL.md +96 -0
- package/skills/webapp-testing/examples/console_logging.py +35 -0
- package/skills/webapp-testing/examples/element_discovery.py +40 -0
- package/skills/webapp-testing/examples/static_html_automation.py +33 -0
- package/skills/webapp-testing/scripts/with_server.py +106 -0
- package/skills/writing-for-agents/SKILL-MECHANICS.md +22 -0
- package/skills/writing-for-agents/SKILL.md +28 -0
- package/skills/writing-for-agents/agents/openai.yaml +3 -0
- package/skills/xlsx/LICENSE.txt +30 -0
- package/skills/xlsx/SKILL.md +101 -0
- package/skills/xlsx/scripts/office/helpers/__init__.py +111 -0
- package/skills/xlsx/scripts/office/helpers/pptx_chart.py +170 -0
- package/skills/xlsx/scripts/office/helpers/pptx_slide.py +60 -0
- package/skills/xlsx/scripts/office/helpers/pptx_theme.py +114 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chart.xsd +1499 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsd +146 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-diagram.xsd +1085 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsd +11 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-main.xsd +3081 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-picture.xsd +23 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsd +185 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsd +287 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/pml.xsd +1676 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsd +28 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsd +144 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsd +174 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsd +25 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsd +18 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsd +59 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsd +56 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsd +195 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-math.xsd +582 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsd +25 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/sml.xsd +4439 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-main.xsd +570 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsd +509 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsd +12 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsd +108 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsd +96 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/wml.xsd +3646 -0
- package/skills/xlsx/scripts/office/schemas/ISO-IEC29500-4_2016/xml.xsd +116 -0
- package/skills/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-contentTypes.xsd +42 -0
- package/skills/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-coreProperties.xsd +50 -0
- package/skills/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-digSig.xsd +49 -0
- package/skills/xlsx/scripts/office/schemas/ecma/fouth-edition/opc-relationships.xsd +33 -0
- package/skills/xlsx/scripts/office/schemas/mce/mc.xsd +75 -0
- package/skills/xlsx/scripts/office/schemas/microsoft/wml-2010.xsd +560 -0
- package/skills/xlsx/scripts/office/schemas/microsoft/wml-2012.xsd +67 -0
- package/skills/xlsx/scripts/office/schemas/microsoft/wml-2018.xsd +14 -0
- package/skills/xlsx/scripts/office/schemas/microsoft/wml-cex-2018.xsd +20 -0
- package/skills/xlsx/scripts/office/schemas/microsoft/wml-cid-2016.xsd +13 -0
- package/skills/xlsx/scripts/office/schemas/microsoft/wml-sdtdatahash-2020.xsd +4 -0
- package/skills/xlsx/scripts/office/schemas/microsoft/wml-symex-2015.xsd +8 -0
- package/skills/xlsx/scripts/office/soffice.py +192 -0
- package/skills/xlsx/scripts/office/validate.py +173 -0
- package/skills/xlsx/scripts/office/validators/__init__.py +15 -0
- package/skills/xlsx/scripts/office/validators/base.py +875 -0
- package/skills/xlsx/scripts/office/validators/docx.py +466 -0
- package/skills/xlsx/scripts/office/validators/pptx.py +441 -0
- package/skills/xlsx/scripts/office/validators/redlining.py +299 -0
- package/skills/xlsx/scripts/recalc.py +308 -0
- package/skills-lock.json +359 -0
- package/tests/auto-permissions.test.mjs +315 -0
- package/tests/background-tasks.test.mjs +27 -0
- package/tests/background-worker.test.mjs +60 -0
- package/tests/bash-permissions.test.mjs +276 -0
- package/tests/glob.test.mjs +31 -0
- package/tests/mode.test.mjs +62 -0
- package/tests/permission-evaluation.test.mjs +70 -0
- package/tests/permission-foundation.test.mjs +194 -0
- package/tests/permission-policy.test.mjs +158 -0
- package/tests/runtime/README.md +51 -0
- package/tests/runtime/harness.mjs +190 -0
- package/tests/runtime/permissions.test.mjs +192 -0
- package/tests/runtime/tui.test.mjs +60 -0
- package/tests/skills-routing.test.mjs +51 -0
- package/tests/task-integration.test.mjs +324 -0
- package/tests/task-permissions.test.mjs +178 -0
- package/tests/task-worktree-policy.test.mjs +53 -0
- package/themes/orange.json +82 -0
- package/tsconfig.json +13 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: docx
|
|
3
|
+
description: "Use this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', '.dotx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx or .dotx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation."
|
|
4
|
+
license: Proprietary. LICENSE.txt has complete terms
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# DOCX creation, editing, and analysis
|
|
8
|
+
|
|
9
|
+
Read only the section for the requested task; creation, editing, comments, and redlining are independent workflows.
|
|
10
|
+
|
|
11
|
+
A `.docx` is a ZIP archive of XML files. Choose your approach by task:
|
|
12
|
+
|
|
13
|
+
| Task | Approach |
|
|
14
|
+
|---|---|
|
|
15
|
+
| **Create** a new document | Write a `docx` (npm) script — see gotchas below |
|
|
16
|
+
| **Edit** an existing document | `unzip` → edit `word/document.xml` → `zip` (docx-js cannot open existing files) |
|
|
17
|
+
| **Read** content | `pandoc -t markdown file.docx` |
|
|
18
|
+
|
|
19
|
+
> Script paths below are relative to this skill's directory.
|
|
20
|
+
|
|
21
|
+
## Creating with docx-js — gotchas
|
|
22
|
+
|
|
23
|
+
`docx` is preinstalled — do not run `npm install` first; write the script and `require('docx')` directly. Only if that require fails: `npm install docx`. The model knows the API; these are the footguns:
|
|
24
|
+
|
|
25
|
+
- **Page size defaults to A4.** For US Letter set `page: { size: { width: 12240, height: 15840 } }` (DXA; 1440 = 1″).
|
|
26
|
+
- **Landscape:** pass portrait dimensions and `orientation: PageOrientation.LANDSCAPE` — docx-js swaps width/height internally.
|
|
27
|
+
- **Tables need dual widths:** set `columnWidths` on the table AND `width` on every cell, both in `WidthType.DXA` (PERCENTAGE breaks in Google Docs). Column widths must sum to the table width.
|
|
28
|
+
- **Table shading:** use `ShadingType.CLEAR`, never `SOLID` (renders black).
|
|
29
|
+
- **Lists:** never insert `•` literally; use a `numbering` config with `LevelFormat.BULLET`.
|
|
30
|
+
- **`ImageRun` requires `type:`** (`"png"`, `"jpg"`, …).
|
|
31
|
+
- **`PageBreak` must be inside a `Paragraph`.**
|
|
32
|
+
- **Never use `\n`** — use separate `Paragraph` elements.
|
|
33
|
+
- **TOC:** headings must use built-in `HeadingLevel.*`; custom heading styles need `outlineLevel` set or they won't appear.
|
|
34
|
+
- **Don't use a table as a horizontal rule** — use a paragraph bottom border instead.
|
|
35
|
+
- **Dot-leader / right-aligned-on-same-line:** use `PositionalTab` (`alignment: PositionalTabAlignment.RIGHT`, `leader: PositionalTabLeader.DOT`) inside a `TextRun`, not literal `.` or space padding.
|
|
36
|
+
|
|
37
|
+
## Verify the output
|
|
38
|
+
|
|
39
|
+
After writing a `.docx`, render it and look at it:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
python scripts/office/soffice.py --headless --convert-to pdf output.docx
|
|
43
|
+
pdftoppm -jpeg -r 100 output.pdf page
|
|
44
|
+
ls page-*.jpg # then Read the images
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
`pdftoppm` zero-pads page numbers to the width of the page count (`page-01.jpg`…`page-12.jpg`).
|
|
48
|
+
|
|
49
|
+
## Editing existing documents
|
|
50
|
+
|
|
51
|
+
Legacy `.doc` files must be converted first: `python scripts/office/soffice.py --headless --convert-to docx file.doc`.
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
unzip -q doc.docx -d unpacked/
|
|
55
|
+
find unpacked -type l -delete # strip symlink entries — docx from external parties is untrusted
|
|
56
|
+
python scripts/merge_runs.py unpacked/ # coalesce fragmented runs so text is findable
|
|
57
|
+
# edit unpacked/word/document.xml in place — do NOT reformat or pretty-print
|
|
58
|
+
(cd unpacked && rm -f ../out.docx && zip -Xr ../out.docx .)
|
|
59
|
+
python scripts/office/validate.py out.docx --original doc.docx # XSD checks; --auto-repair fixes common issues
|
|
60
|
+
# redlining? add --author "<the name you redlined under>" to check every edit is tracked
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Word splits text across many `<w:r>` runs (revision ids, spell-check markers), so a phrase you can see in the document often doesn't exist as a contiguous string in the XML. `merge_runs.py` merges adjacent identically-formatted runs in `word/document.xml` without changing content or rendering; it also accepts a `.docx` directly (`python scripts/merge_runs.py doc.docx -o merged.docx`).
|
|
64
|
+
|
|
65
|
+
**Tracked changes:** when redlining, validate with `--author "<the name you redlined under>"` (needs `--original`) — it reports any text you changed without a `<w:ins>`/`<w:del>` around it, which is easy to do by accident and invisible in the accepted view. Wrap runs in `<w:ins>`/`<w:del>` with `w:id`, `w:author`, `w:date` attributes. Inside `<w:del>`, the text element is `<w:delText>`, not `<w:t>`. A deleted paragraph mark (`<w:pPr><w:rPr><w:del w:id=".." w:author=".." w:date=".."/></w:rPr></w:pPr>`) means "merge this paragraph into the next" — so deleting a paragraph outright is that plus a `<w:del>` around every run. The `<w:del/>` must come before the rPr's other children; their order is schema-enforced.
|
|
66
|
+
|
|
67
|
+
To produce a clean copy with all tracked changes accepted: `python scripts/accept_changes.py in.docx out.docx`.
|
|
68
|
+
|
|
69
|
+
Accepting a deleted paragraph mark should join that paragraph to the one below it, so a paragraph whose runs are *all* deleted vanishes. Word does this; `accept_changes.py` and `pandoc --track-changes=accept` don't always. Both fail the same way — they strip the deleted text but leave the emptied paragraph behind, which reads as a stray empty bullet when it was auto-numbered:
|
|
70
|
+
|
|
71
|
+
- `pandoc --track-changes=accept` never joins the paragraphs.
|
|
72
|
+
- `accept_changes.py` (LibreOffice) joins them correctly, except when the deleted paragraph is followed by an empty spacer paragraph.
|
|
73
|
+
|
|
74
|
+
An empty bullet in either view is an artifact of that view, not a defect in the document. Check paragraph deletions in the XML.
|
|
75
|
+
|
|
76
|
+
## Comments
|
|
77
|
+
|
|
78
|
+
Comments require six cross-linked files. Use the helper — directory mode when you'll also be editing `document.xml` (saves an unzip/rezip cycle), `.docx`-direct mode otherwise:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# Against an already-unpacked directory (preferred when also placing markers)
|
|
82
|
+
python scripts/comment.py unpacked/ "Fees & expenses cap is too low"
|
|
83
|
+
python scripts/comment.py unpacked/ "Agreed" --parent 0
|
|
84
|
+
|
|
85
|
+
# Against a .docx directly
|
|
86
|
+
python scripts/comment.py contract.docx "This cap is too low" -o annotated.docx
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The script writes `comments.xml`, `commentsExtended.xml`, `commentsIds.xml`, `commentsExtensible.xml`, the relationships, and the content-type overrides. Comment IDs are auto-assigned. It then prints the `<w:commentRangeStart>`/`<w:commentRangeEnd>`/`<w:commentReference>` snippet to add to `word/document.xml` so the comment anchors to specific text — until you place those markers, the comment exists but is not visible.
|
|
90
|
+
|
|
91
|
+
## Dependencies
|
|
92
|
+
|
|
93
|
+
`docx` (npm, preinstalled — install only if `require('docx')` fails) · `pandoc` · LibreOffice (`soffice`) · `pdftoppm` (Poppler)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"""Accept all tracked changes in a DOCX file using LibreOffice.
|
|
2
|
+
|
|
3
|
+
Requires LibreOffice (soffice) to be installed.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import argparse
|
|
7
|
+
import logging
|
|
8
|
+
import shutil
|
|
9
|
+
import subprocess
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
from office.soffice import get_soffice_env
|
|
13
|
+
|
|
14
|
+
logger = logging.getLogger(__name__)
|
|
15
|
+
|
|
16
|
+
LIBREOFFICE_PROFILE = "/tmp/libreoffice_docx_profile"
|
|
17
|
+
MACRO_DIR = f"{LIBREOFFICE_PROFILE}/user/basic/Standard"
|
|
18
|
+
|
|
19
|
+
ACCEPT_CHANGES_MACRO = """<?xml version="1.0" encoding="UTF-8"?>
|
|
20
|
+
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
|
|
21
|
+
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Module1" script:language="StarBasic">
|
|
22
|
+
Sub AcceptAllTrackedChanges()
|
|
23
|
+
Dim document As Object
|
|
24
|
+
Dim dispatcher As Object
|
|
25
|
+
|
|
26
|
+
document = ThisComponent.CurrentController.Frame
|
|
27
|
+
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
|
|
28
|
+
|
|
29
|
+
dispatcher.executeDispatch(document, ".uno:AcceptAllTrackedChanges", "", 0, Array())
|
|
30
|
+
ThisComponent.store()
|
|
31
|
+
ThisComponent.close(True)
|
|
32
|
+
End Sub
|
|
33
|
+
</script:module>"""
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def accept_changes(
|
|
37
|
+
input_file: str,
|
|
38
|
+
output_file: str,
|
|
39
|
+
) -> tuple[None, str]:
|
|
40
|
+
input_path = Path(input_file)
|
|
41
|
+
output_path = Path(output_file)
|
|
42
|
+
|
|
43
|
+
if not input_path.exists():
|
|
44
|
+
return None, f"Error: Input file not found: {input_file}"
|
|
45
|
+
|
|
46
|
+
if not input_path.suffix.lower() == ".docx":
|
|
47
|
+
return None, f"Error: Input file is not a DOCX file: {input_file}"
|
|
48
|
+
|
|
49
|
+
try:
|
|
50
|
+
output_path.parent.mkdir(parents=True, exist_ok=True)
|
|
51
|
+
shutil.copy2(input_path, output_path)
|
|
52
|
+
except Exception as e:
|
|
53
|
+
return None, f"Error: Failed to copy input file to output location: {e}"
|
|
54
|
+
|
|
55
|
+
if not _setup_libreoffice_macro():
|
|
56
|
+
return None, "Error: Failed to setup LibreOffice macro"
|
|
57
|
+
|
|
58
|
+
cmd = [
|
|
59
|
+
"soffice",
|
|
60
|
+
"--headless",
|
|
61
|
+
f"-env:UserInstallation=file://{LIBREOFFICE_PROFILE}",
|
|
62
|
+
"--norestore",
|
|
63
|
+
"vnd.sun.star.script:Standard.Module1.AcceptAllTrackedChanges?language=Basic&location=application",
|
|
64
|
+
str(output_path.absolute()),
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
try:
|
|
68
|
+
result = subprocess.run(
|
|
69
|
+
cmd,
|
|
70
|
+
capture_output=True,
|
|
71
|
+
text=True,
|
|
72
|
+
timeout=30,
|
|
73
|
+
check=False,
|
|
74
|
+
env=get_soffice_env(),
|
|
75
|
+
)
|
|
76
|
+
except subprocess.TimeoutExpired:
|
|
77
|
+
return (
|
|
78
|
+
None,
|
|
79
|
+
f"Successfully accepted all tracked changes: {input_file} -> {output_file}",
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
if result.returncode != 0:
|
|
83
|
+
return None, f"Error: LibreOffice failed: {result.stderr}"
|
|
84
|
+
|
|
85
|
+
return (
|
|
86
|
+
None,
|
|
87
|
+
f"Successfully accepted all tracked changes: {input_file} -> {output_file}",
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _setup_libreoffice_macro() -> bool:
|
|
92
|
+
macro_dir = Path(MACRO_DIR)
|
|
93
|
+
macro_file = macro_dir / "Module1.xba"
|
|
94
|
+
|
|
95
|
+
if macro_file.exists() and "AcceptAllTrackedChanges" in macro_file.read_text():
|
|
96
|
+
return True
|
|
97
|
+
|
|
98
|
+
if not macro_dir.exists():
|
|
99
|
+
subprocess.run(
|
|
100
|
+
[
|
|
101
|
+
"soffice",
|
|
102
|
+
"--headless",
|
|
103
|
+
f"-env:UserInstallation=file://{LIBREOFFICE_PROFILE}",
|
|
104
|
+
"--terminate_after_init",
|
|
105
|
+
],
|
|
106
|
+
capture_output=True,
|
|
107
|
+
timeout=10,
|
|
108
|
+
check=False,
|
|
109
|
+
env=get_soffice_env(),
|
|
110
|
+
)
|
|
111
|
+
macro_dir.mkdir(parents=True, exist_ok=True)
|
|
112
|
+
|
|
113
|
+
try:
|
|
114
|
+
macro_file.write_text(ACCEPT_CHANGES_MACRO)
|
|
115
|
+
return True
|
|
116
|
+
except Exception as e:
|
|
117
|
+
logger.warning(f"Failed to setup LibreOffice macro: {e}")
|
|
118
|
+
return False
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
if __name__ == "__main__":
|
|
122
|
+
parser = argparse.ArgumentParser(
|
|
123
|
+
description="Accept all tracked changes in a DOCX file"
|
|
124
|
+
)
|
|
125
|
+
parser.add_argument("input_file", help="Input DOCX file with tracked changes")
|
|
126
|
+
parser.add_argument(
|
|
127
|
+
"output_file", help="Output DOCX file (clean, no tracked changes)"
|
|
128
|
+
)
|
|
129
|
+
args = parser.parse_args()
|
|
130
|
+
|
|
131
|
+
_, message = accept_changes(args.input_file, args.output_file)
|
|
132
|
+
print(message)
|
|
133
|
+
|
|
134
|
+
if "Error" in message:
|
|
135
|
+
raise SystemExit(1)
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
"""Add comments to a DOCX document.
|
|
2
|
+
|
|
3
|
+
Accepts either an unpacked directory OR a .docx/.dotx file directly.
|
|
4
|
+
|
|
5
|
+
Usage:
|
|
6
|
+
# Against an unpacked directory (writes satellite files in place)
|
|
7
|
+
python comment.py unpacked/ "Comment text"
|
|
8
|
+
python comment.py unpacked/ "Reply text" --parent 0
|
|
9
|
+
|
|
10
|
+
# Against a .docx directly (extracts, writes satellite files, rezips)
|
|
11
|
+
python comment.py contract.docx "This cap is too low" -o annotated.docx
|
|
12
|
+
python comment.py contract.docx "Comment" --id 5 # explicit ID
|
|
13
|
+
|
|
14
|
+
The comment ID is auto-assigned (max existing + 1) unless --id is given.
|
|
15
|
+
Plain text is XML-escaped automatically; if you pass already-escaped text
|
|
16
|
+
(e.g. &, ’) use --raw to skip escaping.
|
|
17
|
+
|
|
18
|
+
After running, add markers to word/document.xml so the comment is visible:
|
|
19
|
+
<w:commentRangeStart w:id="N"/>
|
|
20
|
+
... commented content ...
|
|
21
|
+
<w:commentRangeEnd w:id="N"/>
|
|
22
|
+
<w:r><w:rPr><w:rStyle w:val="CommentReference"/></w:rPr><w:commentReference w:id="N"/></w:r>
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
import argparse
|
|
26
|
+
import random
|
|
27
|
+
import shutil
|
|
28
|
+
import sys
|
|
29
|
+
import tempfile
|
|
30
|
+
import zipfile
|
|
31
|
+
from datetime import datetime, timezone
|
|
32
|
+
from pathlib import Path
|
|
33
|
+
|
|
34
|
+
import defusedxml.minidom
|
|
35
|
+
from xml.parsers.expat import ExpatError
|
|
36
|
+
from xml.sax.saxutils import escape as xml_escape
|
|
37
|
+
|
|
38
|
+
from office.helpers import opc_target, rezip as _rezip, safe_extract as _safe_extract
|
|
39
|
+
|
|
40
|
+
TEMPLATE_DIR = Path(__file__).parent / "templates"
|
|
41
|
+
NS = {
|
|
42
|
+
"w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
|
|
43
|
+
"w14": "http://schemas.microsoft.com/office/word/2010/wordml",
|
|
44
|
+
"w15": "http://schemas.microsoft.com/office/word/2012/wordml",
|
|
45
|
+
"w16cid": "http://schemas.microsoft.com/office/word/2016/wordml/cid",
|
|
46
|
+
"w16cex": "http://schemas.microsoft.com/office/word/2018/wordml/cex",
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
COMMENT_XML = """\
|
|
50
|
+
<w:comment w:id="{id}" w:author="{author}" w:date="{date}" w:initials="{initials}">
|
|
51
|
+
<w:p w14:paraId="{para_id}" w14:textId="77777777">
|
|
52
|
+
<w:r>
|
|
53
|
+
<w:rPr><w:rStyle w:val="CommentReference"/></w:rPr>
|
|
54
|
+
<w:annotationRef/>
|
|
55
|
+
</w:r>
|
|
56
|
+
<w:r>
|
|
57
|
+
<w:rPr>
|
|
58
|
+
<w:color w:val="000000"/>
|
|
59
|
+
<w:sz w:val="20"/>
|
|
60
|
+
<w:szCs w:val="20"/>
|
|
61
|
+
</w:rPr>
|
|
62
|
+
<w:t xml:space="preserve">{text}</w:t>
|
|
63
|
+
</w:r>
|
|
64
|
+
</w:p>
|
|
65
|
+
</w:comment>"""
|
|
66
|
+
|
|
67
|
+
COMMENT_MARKER_TEMPLATE = """
|
|
68
|
+
Add to word/document.xml (markers must be direct children of w:p, never inside w:r):
|
|
69
|
+
<w:commentRangeStart w:id="{cid}"/>
|
|
70
|
+
<w:r>...</w:r>
|
|
71
|
+
<w:commentRangeEnd w:id="{cid}"/>
|
|
72
|
+
<w:r><w:rPr><w:rStyle w:val="CommentReference"/></w:rPr><w:commentReference w:id="{cid}"/></w:r>"""
|
|
73
|
+
|
|
74
|
+
REPLY_MARKER_TEMPLATE = """
|
|
75
|
+
Nest markers inside parent {pid}'s markers (direct children of w:p, never inside w:r):
|
|
76
|
+
<w:commentRangeStart w:id="{pid}"/><w:commentRangeStart w:id="{cid}"/>
|
|
77
|
+
<w:r>...</w:r>
|
|
78
|
+
<w:commentRangeEnd w:id="{cid}"/><w:commentRangeEnd w:id="{pid}"/>
|
|
79
|
+
<w:r><w:rPr><w:rStyle w:val="CommentReference"/></w:rPr><w:commentReference w:id="{pid}"/></w:r>
|
|
80
|
+
<w:r><w:rPr><w:rStyle w:val="CommentReference"/></w:rPr><w:commentReference w:id="{cid}"/></w:r>"""
|
|
81
|
+
|
|
82
|
+
SMART_QUOTE_ENTITIES = {
|
|
83
|
+
"“": "“",
|
|
84
|
+
"”": "”",
|
|
85
|
+
"‘": "‘",
|
|
86
|
+
"’": "’",
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _generate_hex_id() -> str:
|
|
91
|
+
return f"{random.randint(0, 0x7FFFFFFE):08X}"
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _encode_smart_quotes(text: str) -> str:
|
|
95
|
+
for char, entity in SMART_QUOTE_ENTITIES.items():
|
|
96
|
+
text = text.replace(char, entity)
|
|
97
|
+
return text
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _append_xml(xml_path: Path, root_tag: str, content: str) -> None:
|
|
101
|
+
dom = defusedxml.minidom.parseString(xml_path.read_text(encoding="utf-8"))
|
|
102
|
+
root = dom.getElementsByTagName(root_tag)[0]
|
|
103
|
+
ns_attrs = " ".join(f'xmlns:{k}="{v}"' for k, v in NS.items())
|
|
104
|
+
wrapper_dom = defusedxml.minidom.parseString(f"<root {ns_attrs}>{content}</root>")
|
|
105
|
+
for child in wrapper_dom.documentElement.childNodes:
|
|
106
|
+
if child.nodeType == child.ELEMENT_NODE:
|
|
107
|
+
root.appendChild(dom.importNode(child, True))
|
|
108
|
+
output = _encode_smart_quotes(dom.toxml(encoding="UTF-8").decode("utf-8"))
|
|
109
|
+
xml_path.write_text(output, encoding="utf-8")
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _find_para_id(comments_path: Path, comment_id: int) -> str | None:
|
|
113
|
+
dom = defusedxml.minidom.parseString(comments_path.read_text(encoding="utf-8"))
|
|
114
|
+
for c in dom.getElementsByTagName("w:comment"):
|
|
115
|
+
if c.getAttribute("w:id") == str(comment_id):
|
|
116
|
+
for p in c.getElementsByTagName("w:p"):
|
|
117
|
+
if pid := p.getAttribute("w14:paraId"):
|
|
118
|
+
return pid
|
|
119
|
+
return None
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _next_comment_id(comments_path: Path) -> int:
|
|
123
|
+
if not comments_path.exists():
|
|
124
|
+
return 0
|
|
125
|
+
dom = defusedxml.minidom.parseString(comments_path.read_text(encoding="utf-8"))
|
|
126
|
+
ids = []
|
|
127
|
+
for c in dom.getElementsByTagName("w:comment"):
|
|
128
|
+
try:
|
|
129
|
+
ids.append(int(c.getAttribute("w:id")))
|
|
130
|
+
except ValueError:
|
|
131
|
+
pass
|
|
132
|
+
return (max(ids) + 1) if ids else 0
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _get_next_rid(rels_path: Path) -> int:
|
|
136
|
+
dom = defusedxml.minidom.parseString(rels_path.read_text(encoding="utf-8"))
|
|
137
|
+
max_rid = 0
|
|
138
|
+
for rel in dom.getElementsByTagName("Relationship"):
|
|
139
|
+
rid = rel.getAttribute("Id")
|
|
140
|
+
if rid and rid.startswith("rId"):
|
|
141
|
+
try:
|
|
142
|
+
max_rid = max(max_rid, int(rid[3:]))
|
|
143
|
+
except ValueError:
|
|
144
|
+
pass
|
|
145
|
+
return max_rid + 1
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def _has_relationship(rels_path: Path, target: str) -> bool:
|
|
149
|
+
dom = defusedxml.minidom.parseString(rels_path.read_text(encoding="utf-8"))
|
|
150
|
+
return any(
|
|
151
|
+
rel.getAttribute("Target") == target
|
|
152
|
+
for rel in dom.getElementsByTagName("Relationship")
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def _has_content_type(ct_path: Path, part_name: str) -> bool:
|
|
157
|
+
dom = defusedxml.minidom.parseString(ct_path.read_text(encoding="utf-8"))
|
|
158
|
+
return any(
|
|
159
|
+
o.getAttribute("PartName") == part_name
|
|
160
|
+
for o in dom.getElementsByTagName("Override")
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
_COMMENT_RELS = [
|
|
165
|
+
("http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments", "comments.xml"),
|
|
166
|
+
("http://schemas.microsoft.com/office/2011/relationships/commentsExtended", "commentsExtended.xml"),
|
|
167
|
+
("http://schemas.microsoft.com/office/2016/09/relationships/commentsIds", "commentsIds.xml"),
|
|
168
|
+
("http://schemas.microsoft.com/office/2018/08/relationships/commentsExtensible", "commentsExtensible.xml"),
|
|
169
|
+
]
|
|
170
|
+
_COMMENT_OVERRIDES = [
|
|
171
|
+
("/word/comments.xml", "application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml"),
|
|
172
|
+
("/word/commentsExtended.xml", "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml"),
|
|
173
|
+
("/word/commentsIds.xml", "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsIds+xml"),
|
|
174
|
+
("/word/commentsExtensible.xml", "application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtensible+xml"),
|
|
175
|
+
]
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def _ensure_comment_relationships(unpacked_dir: Path) -> None:
|
|
179
|
+
rels_path = unpacked_dir / "word" / "_rels" / "document.xml.rels"
|
|
180
|
+
if not rels_path.exists():
|
|
181
|
+
return
|
|
182
|
+
dom = defusedxml.minidom.parseString(rels_path.read_text(encoding="utf-8"))
|
|
183
|
+
root = dom.documentElement
|
|
184
|
+
comment_types = {rel_type for rel_type, _ in _COMMENT_RELS}
|
|
185
|
+
existing = set()
|
|
186
|
+
for rel in dom.getElementsByTagName("Relationship"):
|
|
187
|
+
if rel.getAttribute("Type") not in comment_types:
|
|
188
|
+
continue
|
|
189
|
+
part = opc_target(
|
|
190
|
+
rel.getAttribute("Target"),
|
|
191
|
+
"word/document.xml",
|
|
192
|
+
rel.getAttribute("TargetMode"),
|
|
193
|
+
)
|
|
194
|
+
if part is not None:
|
|
195
|
+
existing.add(part)
|
|
196
|
+
next_rid = _get_next_rid(rels_path)
|
|
197
|
+
changed = False
|
|
198
|
+
for rel_type, target in _COMMENT_RELS:
|
|
199
|
+
if opc_target(target, "word/document.xml") in existing:
|
|
200
|
+
continue
|
|
201
|
+
rel = dom.createElement("Relationship")
|
|
202
|
+
rel.setAttribute("Id", f"rId{next_rid}")
|
|
203
|
+
rel.setAttribute("Type", rel_type)
|
|
204
|
+
rel.setAttribute("Target", target)
|
|
205
|
+
root.appendChild(rel)
|
|
206
|
+
next_rid += 1
|
|
207
|
+
changed = True
|
|
208
|
+
if changed:
|
|
209
|
+
rels_path.write_bytes(dom.toxml(encoding="UTF-8"))
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def _ensure_comment_content_types(unpacked_dir: Path) -> None:
|
|
213
|
+
ct_path = unpacked_dir / "[Content_Types].xml"
|
|
214
|
+
if not ct_path.exists():
|
|
215
|
+
return
|
|
216
|
+
dom = defusedxml.minidom.parseString(ct_path.read_text(encoding="utf-8"))
|
|
217
|
+
root = dom.documentElement
|
|
218
|
+
existing = {
|
|
219
|
+
o.getAttribute("PartName")
|
|
220
|
+
for o in dom.getElementsByTagName("Override")
|
|
221
|
+
}
|
|
222
|
+
changed = False
|
|
223
|
+
for part_name, content_type in _COMMENT_OVERRIDES:
|
|
224
|
+
if part_name in existing:
|
|
225
|
+
continue
|
|
226
|
+
override = dom.createElement("Override")
|
|
227
|
+
override.setAttribute("PartName", part_name)
|
|
228
|
+
override.setAttribute("ContentType", content_type)
|
|
229
|
+
root.appendChild(override)
|
|
230
|
+
changed = True
|
|
231
|
+
if changed:
|
|
232
|
+
ct_path.write_bytes(dom.toxml(encoding="UTF-8"))
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def add_comment(
|
|
236
|
+
unpacked_dir: Path | str,
|
|
237
|
+
text: str,
|
|
238
|
+
comment_id: int | None = None,
|
|
239
|
+
author: str = "Claude",
|
|
240
|
+
initials: str = "C",
|
|
241
|
+
parent_id: int | None = None,
|
|
242
|
+
raw: bool = False,
|
|
243
|
+
) -> tuple[int, str, str]:
|
|
244
|
+
unpacked_dir = Path(unpacked_dir)
|
|
245
|
+
if not raw:
|
|
246
|
+
text = xml_escape(text)
|
|
247
|
+
author = xml_escape(author, {'"': """})
|
|
248
|
+
initials = xml_escape(initials, {'"': """})
|
|
249
|
+
word = unpacked_dir / "word"
|
|
250
|
+
if not word.exists():
|
|
251
|
+
raise FileNotFoundError(f"{word} not found (not an unpacked .docx?)")
|
|
252
|
+
|
|
253
|
+
comments = word / "comments.xml"
|
|
254
|
+
if comment_id is None:
|
|
255
|
+
comment_id = _next_comment_id(comments)
|
|
256
|
+
|
|
257
|
+
parent_para = None
|
|
258
|
+
if parent_id is not None:
|
|
259
|
+
parent_para = _find_para_id(comments, parent_id) if comments.exists() else None
|
|
260
|
+
if not parent_para:
|
|
261
|
+
raise ValueError(f"parent comment {parent_id} not found")
|
|
262
|
+
|
|
263
|
+
para_id, durable_id = _generate_hex_id(), _generate_hex_id()
|
|
264
|
+
ts = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
|
265
|
+
|
|
266
|
+
if not comments.exists():
|
|
267
|
+
shutil.copy(TEMPLATE_DIR / "comments.xml", comments)
|
|
268
|
+
_ensure_comment_relationships(unpacked_dir)
|
|
269
|
+
_ensure_comment_content_types(unpacked_dir)
|
|
270
|
+
_append_xml(
|
|
271
|
+
comments,
|
|
272
|
+
"w:comments",
|
|
273
|
+
COMMENT_XML.format(
|
|
274
|
+
id=comment_id, author=author, date=ts, initials=initials,
|
|
275
|
+
para_id=para_id, text=text,
|
|
276
|
+
),
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
ext = word / "commentsExtended.xml"
|
|
280
|
+
if not ext.exists():
|
|
281
|
+
shutil.copy(TEMPLATE_DIR / "commentsExtended.xml", ext)
|
|
282
|
+
if parent_para is not None:
|
|
283
|
+
_append_xml(
|
|
284
|
+
ext, "w15:commentsEx",
|
|
285
|
+
f'<w15:commentEx w15:paraId="{para_id}" w15:paraIdParent="{parent_para}" w15:done="0"/>',
|
|
286
|
+
)
|
|
287
|
+
else:
|
|
288
|
+
_append_xml(
|
|
289
|
+
ext, "w15:commentsEx",
|
|
290
|
+
f'<w15:commentEx w15:paraId="{para_id}" w15:done="0"/>',
|
|
291
|
+
)
|
|
292
|
+
|
|
293
|
+
ids = word / "commentsIds.xml"
|
|
294
|
+
if not ids.exists():
|
|
295
|
+
shutil.copy(TEMPLATE_DIR / "commentsIds.xml", ids)
|
|
296
|
+
_append_xml(
|
|
297
|
+
ids, "w16cid:commentsIds",
|
|
298
|
+
f'<w16cid:commentId w16cid:paraId="{para_id}" w16cid:durableId="{durable_id}"/>',
|
|
299
|
+
)
|
|
300
|
+
|
|
301
|
+
extensible = word / "commentsExtensible.xml"
|
|
302
|
+
if not extensible.exists():
|
|
303
|
+
shutil.copy(TEMPLATE_DIR / "commentsExtensible.xml", extensible)
|
|
304
|
+
_append_xml(
|
|
305
|
+
extensible, "w16cex:commentsExtensible",
|
|
306
|
+
f'<w16cex:commentExtensible w16cex:durableId="{durable_id}" w16cex:dateUtc="{ts}"/>',
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
action = "reply" if parent_id is not None else "comment"
|
|
310
|
+
return comment_id, para_id, f"Added {action} id={comment_id} (paraId={para_id})"
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
def main() -> None:
|
|
314
|
+
p = argparse.ArgumentParser(description="Add a comment to a DOCX (directory or .docx file).")
|
|
315
|
+
p.add_argument("input", help="Unpacked DOCX directory OR a .docx/.dotx file")
|
|
316
|
+
p.add_argument("text", help="Comment text (plain text; XML-escaped automatically)")
|
|
317
|
+
p.add_argument("--raw", action="store_true",
|
|
318
|
+
help="Treat text as pre-escaped XML (skip automatic escaping)")
|
|
319
|
+
p.add_argument("--id", type=int, dest="comment_id",
|
|
320
|
+
help="Comment ID (default: auto-assign as max existing + 1)")
|
|
321
|
+
p.add_argument("--author", default="Claude", help="Author name")
|
|
322
|
+
p.add_argument("--initials", default="C", help="Author initials")
|
|
323
|
+
p.add_argument("--parent", type=int, help="Parent comment ID (makes this a reply)")
|
|
324
|
+
p.add_argument("-o", "--output",
|
|
325
|
+
help="Output .docx path (only used when input is a .docx; default: overwrite input)")
|
|
326
|
+
args = p.parse_args()
|
|
327
|
+
|
|
328
|
+
src = Path(args.input)
|
|
329
|
+
|
|
330
|
+
try:
|
|
331
|
+
if src.is_dir():
|
|
332
|
+
if args.output:
|
|
333
|
+
print("Warning: --output ignored for directory input", file=sys.stderr)
|
|
334
|
+
cid, _, msg = add_comment(
|
|
335
|
+
src, args.text, comment_id=args.comment_id,
|
|
336
|
+
author=args.author, initials=args.initials,
|
|
337
|
+
parent_id=args.parent, raw=args.raw,
|
|
338
|
+
)
|
|
339
|
+
print(msg)
|
|
340
|
+
elif src.is_file() and src.suffix.lower() in (".docx", ".dotx"):
|
|
341
|
+
out = Path(args.output) if args.output else src
|
|
342
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
343
|
+
tmp_path = Path(tmp)
|
|
344
|
+
with zipfile.ZipFile(src) as zf:
|
|
345
|
+
_safe_extract(zf, tmp_path)
|
|
346
|
+
cid, _, msg = add_comment(
|
|
347
|
+
tmp_path, args.text, comment_id=args.comment_id,
|
|
348
|
+
author=args.author, initials=args.initials,
|
|
349
|
+
parent_id=args.parent, raw=args.raw,
|
|
350
|
+
)
|
|
351
|
+
_rezip(tmp_path, out)
|
|
352
|
+
print(msg)
|
|
353
|
+
print(f"Wrote {out} (comment defined; add markers to word/document.xml to make it visible)")
|
|
354
|
+
else:
|
|
355
|
+
print(f"Error: {src} is neither a directory nor a .docx/.dotx file", file=sys.stderr)
|
|
356
|
+
sys.exit(1)
|
|
357
|
+
except (FileNotFoundError, ValueError, zipfile.BadZipFile, ExpatError) as e:
|
|
358
|
+
print(f"Error: {e}", file=sys.stderr)
|
|
359
|
+
sys.exit(1)
|
|
360
|
+
|
|
361
|
+
if args.parent is not None:
|
|
362
|
+
print(REPLY_MARKER_TEMPLATE.format(pid=args.parent, cid=cid))
|
|
363
|
+
else:
|
|
364
|
+
print(COMMENT_MARKER_TEMPLATE.format(cid=cid))
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
if __name__ == "__main__":
|
|
368
|
+
main()
|