@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,299 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Validator for tracked changes in Word documents.
|
|
3
|
+
|
|
4
|
+
Detects untracked edits in word/document.xml: text that differs from the
|
|
5
|
+
original without a <w:ins>/<w:del> wrapper recording it. The tracked changes
|
|
6
|
+
that are new relative to the original are undone, and the result is compared
|
|
7
|
+
against the original; whatever text still differs was edited without being
|
|
8
|
+
tracked.
|
|
9
|
+
|
|
10
|
+
Only the document body is compared. Headers, footers, footnotes and endnotes
|
|
11
|
+
are separate parts and are not checked.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import subprocess
|
|
15
|
+
import tempfile
|
|
16
|
+
import zipfile
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
|
|
19
|
+
import defusedxml.ElementTree as ET
|
|
20
|
+
from defusedxml.common import DefusedXmlException
|
|
21
|
+
|
|
22
|
+
from helpers import rendered_text, safe_extract
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class RedliningValidator:
|
|
26
|
+
|
|
27
|
+
def __init__(self, unpacked_dir, original_docx, verbose=False):
|
|
28
|
+
self.unpacked_dir = Path(unpacked_dir)
|
|
29
|
+
self.original_docx = Path(original_docx)
|
|
30
|
+
self.verbose = verbose
|
|
31
|
+
self.namespaces = {
|
|
32
|
+
"w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
def repair(self) -> int:
|
|
36
|
+
return 0
|
|
37
|
+
|
|
38
|
+
def validate(self):
|
|
39
|
+
modified_file = self.unpacked_dir / "word" / "document.xml"
|
|
40
|
+
if not modified_file.exists():
|
|
41
|
+
print(f"FAILED - Modified document.xml not found at {modified_file}")
|
|
42
|
+
return False
|
|
43
|
+
|
|
44
|
+
with tempfile.TemporaryDirectory() as temp_dir:
|
|
45
|
+
temp_path = Path(temp_dir)
|
|
46
|
+
|
|
47
|
+
try:
|
|
48
|
+
with zipfile.ZipFile(self.original_docx, "r") as zip_ref:
|
|
49
|
+
safe_extract(zip_ref, temp_path)
|
|
50
|
+
except Exception as e:
|
|
51
|
+
print(f"FAILED - Error unpacking original docx: {e}")
|
|
52
|
+
return False
|
|
53
|
+
|
|
54
|
+
original_file = temp_path / "word" / "document.xml"
|
|
55
|
+
if not original_file.exists():
|
|
56
|
+
print(
|
|
57
|
+
f"FAILED - Original document.xml not found in {self.original_docx}"
|
|
58
|
+
)
|
|
59
|
+
return False
|
|
60
|
+
|
|
61
|
+
try:
|
|
62
|
+
modified_tree = ET.parse(modified_file)
|
|
63
|
+
modified_root = modified_tree.getroot()
|
|
64
|
+
original_tree = ET.parse(original_file)
|
|
65
|
+
original_root = original_tree.getroot()
|
|
66
|
+
except (ET.ParseError, DefusedXmlException) as e:
|
|
67
|
+
print(f"FAILED - Error parsing XML files: {e}")
|
|
68
|
+
return False
|
|
69
|
+
|
|
70
|
+
new_changes = self._new_tracked_changes(original_root, modified_root)
|
|
71
|
+
self._remove_tracked_changes(modified_root, new_changes)
|
|
72
|
+
|
|
73
|
+
modified_text = self._extract_text_content(modified_root)
|
|
74
|
+
original_text = self._extract_text_content(original_root)
|
|
75
|
+
|
|
76
|
+
if modified_text != original_text:
|
|
77
|
+
error_message = self._generate_detailed_diff(
|
|
78
|
+
original_text, modified_text
|
|
79
|
+
)
|
|
80
|
+
print(error_message)
|
|
81
|
+
return False
|
|
82
|
+
|
|
83
|
+
if self.verbose:
|
|
84
|
+
print(
|
|
85
|
+
f"PASSED - All {len(new_changes)} change(s) against the original "
|
|
86
|
+
"are properly tracked"
|
|
87
|
+
)
|
|
88
|
+
return True
|
|
89
|
+
|
|
90
|
+
def _tracked_change_elements(self, root):
|
|
91
|
+
ins_tag = f"{{{self.namespaces['w']}}}ins"
|
|
92
|
+
del_tag = f"{{{self.namespaces['w']}}}del"
|
|
93
|
+
return [elem for elem in root.iter() if elem.tag in (ins_tag, del_tag)]
|
|
94
|
+
|
|
95
|
+
def _rendered_text(self, elem):
|
|
96
|
+
preserve = elem.get("{http://www.w3.org/XML/1998/namespace}space") == "preserve"
|
|
97
|
+
return rendered_text(elem.text or "", preserve)
|
|
98
|
+
|
|
99
|
+
def _text_elements(self, elem):
|
|
100
|
+
w = self.namespaces["w"]
|
|
101
|
+
return [
|
|
102
|
+
node
|
|
103
|
+
for node in elem.iter()
|
|
104
|
+
if node.tag in (f"{{{w}}}t", f"{{{w}}}delText")
|
|
105
|
+
]
|
|
106
|
+
|
|
107
|
+
def _tracked_change_key(self, elem):
|
|
108
|
+
w = self.namespaces["w"]
|
|
109
|
+
text = "".join(self._rendered_text(node) for node in self._text_elements(elem))
|
|
110
|
+
return (elem.tag, elem.get(f"{{{w}}}author"), elem.get(f"{{{w}}}date"), text)
|
|
111
|
+
|
|
112
|
+
def _new_tracked_changes(self, original_root, modified_root):
|
|
113
|
+
original = self._tracked_change_elements(original_root)
|
|
114
|
+
modified = self._tracked_change_elements(modified_root)
|
|
115
|
+
|
|
116
|
+
pool = {}
|
|
117
|
+
for elem in original:
|
|
118
|
+
pool.setdefault(self._tracked_change_key(elem), []).append(elem)
|
|
119
|
+
|
|
120
|
+
matched, leftover = set(), []
|
|
121
|
+
for elem in modified:
|
|
122
|
+
bucket = pool.get(self._tracked_change_key(elem))
|
|
123
|
+
if bucket:
|
|
124
|
+
matched.add(bucket.pop())
|
|
125
|
+
else:
|
|
126
|
+
leftover.append(elem)
|
|
127
|
+
|
|
128
|
+
def group(elem):
|
|
129
|
+
return self._tracked_change_key(elem)[:3]
|
|
130
|
+
|
|
131
|
+
def text_of(elems):
|
|
132
|
+
return "".join(self._tracked_change_key(e)[3] for e in elems)
|
|
133
|
+
|
|
134
|
+
unmatched_original = {}
|
|
135
|
+
for elem in original:
|
|
136
|
+
if elem not in matched:
|
|
137
|
+
unmatched_original.setdefault(group(elem), []).append(elem)
|
|
138
|
+
|
|
139
|
+
by_group = {}
|
|
140
|
+
for elem in leftover:
|
|
141
|
+
by_group.setdefault(group(elem), []).append(elem)
|
|
142
|
+
|
|
143
|
+
new = set()
|
|
144
|
+
for key, elems in by_group.items():
|
|
145
|
+
rebuilt = text_of(elems)
|
|
146
|
+
if rebuilt and rebuilt == text_of(unmatched_original.get(key, [])):
|
|
147
|
+
continue
|
|
148
|
+
new.update(elems)
|
|
149
|
+
return new
|
|
150
|
+
|
|
151
|
+
def _generate_detailed_diff(self, original_text, modified_text):
|
|
152
|
+
error_parts = [
|
|
153
|
+
"FAILED - Document text doesn't match after removing the tracked changes",
|
|
154
|
+
"",
|
|
155
|
+
"Likely causes:",
|
|
156
|
+
" 1. Modified text inside another author's <w:ins> or <w:del> tags",
|
|
157
|
+
" 2. Made edits without proper tracked changes",
|
|
158
|
+
" 3. Didn't nest <w:del> inside <w:ins> when deleting another's insertion",
|
|
159
|
+
" 4. Rewrote another author's <w:ins>/<w:del> and changed its text on",
|
|
160
|
+
" the way. A tracked change from the original is recognised by its",
|
|
161
|
+
" author, date and text; anything that doesn't reproduce one exactly",
|
|
162
|
+
" reads as new, and the text it carried is reported missing.",
|
|
163
|
+
"",
|
|
164
|
+
"For pre-redlined documents, use correct patterns:",
|
|
165
|
+
" - To reject another's INSERTION: Nest <w:del> inside their <w:ins>",
|
|
166
|
+
" - To reject PART of one: nest <w:del> around only the runs you reject.",
|
|
167
|
+
" Their <w:ins> may be split around it, so long as the pieces keep",
|
|
168
|
+
" their author and date and still spell out the same text.",
|
|
169
|
+
" - To restore another's DELETION: Add new <w:ins> AFTER their <w:del>",
|
|
170
|
+
"",
|
|
171
|
+
]
|
|
172
|
+
|
|
173
|
+
git_diff = self._get_git_word_diff(original_text, modified_text)
|
|
174
|
+
if git_diff:
|
|
175
|
+
error_parts.extend(["Differences:", "============", git_diff])
|
|
176
|
+
else:
|
|
177
|
+
error_parts.append("Unable to generate word diff (git not available)")
|
|
178
|
+
|
|
179
|
+
return "\n".join(error_parts)
|
|
180
|
+
|
|
181
|
+
def _get_git_word_diff(self, original_text, modified_text):
|
|
182
|
+
try:
|
|
183
|
+
with tempfile.TemporaryDirectory() as temp_dir:
|
|
184
|
+
temp_path = Path(temp_dir)
|
|
185
|
+
|
|
186
|
+
original_file = temp_path / "original.txt"
|
|
187
|
+
modified_file = temp_path / "modified.txt"
|
|
188
|
+
|
|
189
|
+
original_file.write_text(original_text, encoding="utf-8")
|
|
190
|
+
modified_file.write_text(modified_text, encoding="utf-8")
|
|
191
|
+
|
|
192
|
+
result = subprocess.run(
|
|
193
|
+
[
|
|
194
|
+
"git",
|
|
195
|
+
"diff",
|
|
196
|
+
"--word-diff=plain",
|
|
197
|
+
"--word-diff-regex=.",
|
|
198
|
+
"-U0",
|
|
199
|
+
"--no-index",
|
|
200
|
+
str(original_file),
|
|
201
|
+
str(modified_file),
|
|
202
|
+
],
|
|
203
|
+
capture_output=True,
|
|
204
|
+
text=True,
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
if result.stdout.strip():
|
|
208
|
+
lines = result.stdout.split("\n")
|
|
209
|
+
content_lines = []
|
|
210
|
+
in_content = False
|
|
211
|
+
for line in lines:
|
|
212
|
+
if line.startswith("@@"):
|
|
213
|
+
in_content = True
|
|
214
|
+
continue
|
|
215
|
+
if in_content and line.strip():
|
|
216
|
+
content_lines.append(line)
|
|
217
|
+
|
|
218
|
+
if content_lines:
|
|
219
|
+
return "\n".join(content_lines)
|
|
220
|
+
|
|
221
|
+
result = subprocess.run(
|
|
222
|
+
[
|
|
223
|
+
"git",
|
|
224
|
+
"diff",
|
|
225
|
+
"--word-diff=plain",
|
|
226
|
+
"-U0",
|
|
227
|
+
"--no-index",
|
|
228
|
+
str(original_file),
|
|
229
|
+
str(modified_file),
|
|
230
|
+
],
|
|
231
|
+
capture_output=True,
|
|
232
|
+
text=True,
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
if result.stdout.strip():
|
|
236
|
+
lines = result.stdout.split("\n")
|
|
237
|
+
content_lines = []
|
|
238
|
+
in_content = False
|
|
239
|
+
for line in lines:
|
|
240
|
+
if line.startswith("@@"):
|
|
241
|
+
in_content = True
|
|
242
|
+
continue
|
|
243
|
+
if in_content and line.strip():
|
|
244
|
+
content_lines.append(line)
|
|
245
|
+
return "\n".join(content_lines)
|
|
246
|
+
|
|
247
|
+
except (subprocess.CalledProcessError, FileNotFoundError, Exception):
|
|
248
|
+
pass
|
|
249
|
+
|
|
250
|
+
return None
|
|
251
|
+
|
|
252
|
+
def _remove_tracked_changes(self, root, targets):
|
|
253
|
+
ins_tag = f"{{{self.namespaces['w']}}}ins"
|
|
254
|
+
del_tag = f"{{{self.namespaces['w']}}}del"
|
|
255
|
+
|
|
256
|
+
for parent in root.iter():
|
|
257
|
+
to_remove = []
|
|
258
|
+
for child in parent:
|
|
259
|
+
if child.tag == ins_tag and child in targets:
|
|
260
|
+
to_remove.append(child)
|
|
261
|
+
for elem in to_remove:
|
|
262
|
+
parent.remove(elem)
|
|
263
|
+
|
|
264
|
+
deltext_tag = f"{{{self.namespaces['w']}}}delText"
|
|
265
|
+
t_tag = f"{{{self.namespaces['w']}}}t"
|
|
266
|
+
|
|
267
|
+
for parent in root.iter():
|
|
268
|
+
to_process = []
|
|
269
|
+
for child in parent:
|
|
270
|
+
if child.tag == del_tag and child in targets:
|
|
271
|
+
to_process.append((child, list(parent).index(child)))
|
|
272
|
+
|
|
273
|
+
for del_elem, del_index in reversed(to_process):
|
|
274
|
+
for elem in del_elem.iter():
|
|
275
|
+
if elem.tag == deltext_tag:
|
|
276
|
+
elem.tag = t_tag
|
|
277
|
+
|
|
278
|
+
for child in reversed(list(del_elem)):
|
|
279
|
+
parent.insert(del_index, child)
|
|
280
|
+
parent.remove(del_elem)
|
|
281
|
+
|
|
282
|
+
def _extract_text_content(self, root):
|
|
283
|
+
p_tag = f"{{{self.namespaces['w']}}}p"
|
|
284
|
+
t_tag = f"{{{self.namespaces['w']}}}t"
|
|
285
|
+
|
|
286
|
+
paragraphs = []
|
|
287
|
+
for p_elem in root.findall(f".//{p_tag}"):
|
|
288
|
+
text_parts = []
|
|
289
|
+
for t_elem in p_elem.findall(f".//{t_tag}"):
|
|
290
|
+
text_parts.append(self._rendered_text(t_elem))
|
|
291
|
+
paragraph_text = "".join(text_parts)
|
|
292
|
+
if paragraph_text:
|
|
293
|
+
paragraphs.append(paragraph_text)
|
|
294
|
+
|
|
295
|
+
return "\n".join(paragraphs)
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
if __name__ == "__main__":
|
|
299
|
+
raise RuntimeError("This module should not be run directly.")
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Excel Formula Recalculation Script
|
|
3
|
+
Recalculates all formulas in an Excel file using LibreOffice
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import contextlib
|
|
7
|
+
import json
|
|
8
|
+
import os
|
|
9
|
+
import platform
|
|
10
|
+
import re
|
|
11
|
+
import shutil
|
|
12
|
+
import subprocess
|
|
13
|
+
import sys
|
|
14
|
+
import tempfile
|
|
15
|
+
import time
|
|
16
|
+
import zipfile
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
|
|
19
|
+
from office.soffice import get_soffice_env, run_soffice
|
|
20
|
+
|
|
21
|
+
from openpyxl import load_workbook
|
|
22
|
+
|
|
23
|
+
MACRO_FILENAME = "Module1.xba"
|
|
24
|
+
SOFFICE_MISSING = "soffice not found on PATH; LibreOffice is required to recalculate"
|
|
25
|
+
|
|
26
|
+
MAX_LOCATIONS = 100
|
|
27
|
+
|
|
28
|
+
EXTERNAL_REF_RE = re.compile(r"""(?<![\w"\[])'?\[\d+\][^!"\[\]]*'?!""")
|
|
29
|
+
|
|
30
|
+
RECALCULATE_MACRO = """<?xml version="1.0" encoding="UTF-8"?>
|
|
31
|
+
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
|
|
32
|
+
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Module1" script:language="StarBasic">
|
|
33
|
+
Sub RecalculateAndSave()
|
|
34
|
+
ThisComponent.calculateAll()
|
|
35
|
+
ThisComponent.store()
|
|
36
|
+
ThisComponent.close(True)
|
|
37
|
+
End Sub
|
|
38
|
+
</script:module>"""
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def has_gtimeout():
|
|
42
|
+
try:
|
|
43
|
+
subprocess.run(
|
|
44
|
+
["gtimeout", "--version"], capture_output=True, timeout=1, check=False
|
|
45
|
+
)
|
|
46
|
+
return True
|
|
47
|
+
except (FileNotFoundError, subprocess.TimeoutExpired):
|
|
48
|
+
return False
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _stamp(path):
|
|
52
|
+
st = os.stat(path)
|
|
53
|
+
return st.st_mtime_ns, st.st_size
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def setup_libreoffice_macro(profile_dir: Path, timeout=30):
|
|
57
|
+
url = profile_dir.as_uri()
|
|
58
|
+
try:
|
|
59
|
+
run_soffice(
|
|
60
|
+
["--headless", "--terminate_after_init", f"-env:UserInstallation={url}"],
|
|
61
|
+
capture_output=True,
|
|
62
|
+
timeout=timeout,
|
|
63
|
+
)
|
|
64
|
+
except FileNotFoundError:
|
|
65
|
+
return None, SOFFICE_MISSING
|
|
66
|
+
except subprocess.TimeoutExpired:
|
|
67
|
+
return None, "LibreOffice timed out creating its profile; formulas were NOT recalculated"
|
|
68
|
+
|
|
69
|
+
macro_dir = profile_dir / "user" / "basic" / "Standard"
|
|
70
|
+
if not macro_dir.exists():
|
|
71
|
+
return None, "LibreOffice did not create a usable profile; formulas were NOT recalculated"
|
|
72
|
+
|
|
73
|
+
try:
|
|
74
|
+
(macro_dir / MACRO_FILENAME).write_text(RECALCULATE_MACRO)
|
|
75
|
+
except OSError as e:
|
|
76
|
+
return None, f"Could not install the recalculation macro: {e}"
|
|
77
|
+
|
|
78
|
+
return url, None
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def external_links_at_risk(filename):
|
|
82
|
+
try:
|
|
83
|
+
with zipfile.ZipFile(filename) as archive:
|
|
84
|
+
names = archive.namelist()
|
|
85
|
+
except (zipfile.BadZipFile, OSError):
|
|
86
|
+
return []
|
|
87
|
+
if not any(n.startswith("xl/externalLinks/") for n in names):
|
|
88
|
+
return []
|
|
89
|
+
|
|
90
|
+
with contextlib.ExitStack() as stack:
|
|
91
|
+
formulas = load_workbook(filename, data_only=False)
|
|
92
|
+
stack.callback(formulas.close)
|
|
93
|
+
values = load_workbook(filename, data_only=True)
|
|
94
|
+
stack.callback(values.close)
|
|
95
|
+
|
|
96
|
+
external_names = [
|
|
97
|
+
name
|
|
98
|
+
for name, dn in formulas.defined_names.items()
|
|
99
|
+
if isinstance(getattr(dn, "value", None), str) and EXTERNAL_REF_RE.search(dn.value)
|
|
100
|
+
]
|
|
101
|
+
name_re = (
|
|
102
|
+
re.compile(r"\b(" + "|".join(re.escape(n) for n in external_names) + r")\b")
|
|
103
|
+
if external_names
|
|
104
|
+
else None
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
at_risk = []
|
|
108
|
+
for sheet in formulas.sheetnames:
|
|
109
|
+
ws = formulas[sheet]
|
|
110
|
+
if not hasattr(ws, "iter_rows"):
|
|
111
|
+
continue
|
|
112
|
+
cached = values[sheet]
|
|
113
|
+
for row in ws.iter_rows():
|
|
114
|
+
for cell in row:
|
|
115
|
+
v = cell.value
|
|
116
|
+
if not (isinstance(v, str) and v.startswith("=")):
|
|
117
|
+
continue
|
|
118
|
+
reaches_out = EXTERNAL_REF_RE.search(v) or (name_re and name_re.search(v))
|
|
119
|
+
if reaches_out and cached[cell.coordinate].value is None:
|
|
120
|
+
at_risk.append(f"{sheet}!{cell.coordinate}")
|
|
121
|
+
return at_risk
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def recalc(filename, timeout=30, force=False):
|
|
125
|
+
if not Path(filename).exists():
|
|
126
|
+
return {"error": f"File {filename} does not exist"}
|
|
127
|
+
|
|
128
|
+
abs_path = str(Path(filename).absolute())
|
|
129
|
+
|
|
130
|
+
if not os.access(abs_path, os.W_OK):
|
|
131
|
+
return {"error": f"{filename} is not writable; recalculation rewrites the file in place"}
|
|
132
|
+
|
|
133
|
+
try:
|
|
134
|
+
get_soffice_env()
|
|
135
|
+
except Exception as e:
|
|
136
|
+
return {"error": f"Could not prepare the LibreOffice environment: {e}"}
|
|
137
|
+
|
|
138
|
+
if not force:
|
|
139
|
+
try:
|
|
140
|
+
at_risk = external_links_at_risk(filename)
|
|
141
|
+
except Exception as e:
|
|
142
|
+
return {"error": f"Could not inspect {filename} for external links: {e}"}
|
|
143
|
+
if at_risk:
|
|
144
|
+
shown = at_risk[:MAX_LOCATIONS]
|
|
145
|
+
return {
|
|
146
|
+
"error": (
|
|
147
|
+
"Refusing to recalculate: this workbook links to another workbook, and "
|
|
148
|
+
f"{len(at_risk)} linked cell(s) have lost their cached value (openpyxl strips "
|
|
149
|
+
"these on save). Recalculating would resolve them to #NAME? and delete the "
|
|
150
|
+
"external links for good. Copy those cells' values from the original file "
|
|
151
|
+
"before saving, or pass --force to accept the loss. Charts and conditional "
|
|
152
|
+
"formats can hold external references too, so this list may not be exhaustive."
|
|
153
|
+
),
|
|
154
|
+
"external_link_cells": shown,
|
|
155
|
+
"external_link_cells_truncated": max(0, len(at_risk) - len(shown)),
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
with tempfile.TemporaryDirectory(
|
|
159
|
+
prefix="recalc-lo-profile-", ignore_cleanup_errors=True
|
|
160
|
+
) as profile_dir:
|
|
161
|
+
return _recalc_with_profile(filename, abs_path, timeout, Path(profile_dir))
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def _recalc_with_profile(filename, abs_path, timeout, profile_dir: Path):
|
|
165
|
+
started = time.monotonic()
|
|
166
|
+
profile_url, err = setup_libreoffice_macro(profile_dir, timeout=timeout)
|
|
167
|
+
if err:
|
|
168
|
+
return {"error": err}
|
|
169
|
+
|
|
170
|
+
timeout = max(5, int(timeout - (time.monotonic() - started)))
|
|
171
|
+
|
|
172
|
+
before = _stamp(abs_path)
|
|
173
|
+
|
|
174
|
+
cmd = [
|
|
175
|
+
"soffice",
|
|
176
|
+
"--headless",
|
|
177
|
+
"--norestore",
|
|
178
|
+
f"-env:UserInstallation={profile_url}",
|
|
179
|
+
"vnd.sun.star.script:Standard.Module1.RecalculateAndSave?language=Basic&location=application",
|
|
180
|
+
abs_path,
|
|
181
|
+
]
|
|
182
|
+
|
|
183
|
+
if platform.system() == "Linux" and shutil.which("timeout"):
|
|
184
|
+
cmd = ["timeout", str(timeout)] + cmd
|
|
185
|
+
elif platform.system() == "Darwin" and has_gtimeout():
|
|
186
|
+
cmd = ["gtimeout", str(timeout)] + cmd
|
|
187
|
+
|
|
188
|
+
timed_out = f"LibreOffice timed out after {timeout}s; formulas were NOT recalculated. Re-run with a longer timeout."
|
|
189
|
+
|
|
190
|
+
try:
|
|
191
|
+
result = subprocess.run(
|
|
192
|
+
cmd, capture_output=True, text=True, env=get_soffice_env(), timeout=timeout + 15
|
|
193
|
+
)
|
|
194
|
+
except subprocess.TimeoutExpired:
|
|
195
|
+
return {"error": timed_out}
|
|
196
|
+
except FileNotFoundError:
|
|
197
|
+
return {"error": SOFFICE_MISSING}
|
|
198
|
+
|
|
199
|
+
if result.returncode == 124:
|
|
200
|
+
return {"error": timed_out}
|
|
201
|
+
|
|
202
|
+
if result.returncode != 0:
|
|
203
|
+
detail = (result.stderr or "").strip() or f"soffice exited {result.returncode}"
|
|
204
|
+
return {"error": f"LibreOffice failed to recalculate: {detail}"}
|
|
205
|
+
|
|
206
|
+
if _stamp(abs_path) == before:
|
|
207
|
+
return {
|
|
208
|
+
"error": (
|
|
209
|
+
"LibreOffice exited cleanly but never rewrote the file, so nothing was "
|
|
210
|
+
"recalculated. Check that no other LibreOffice instance is running, then retry."
|
|
211
|
+
)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
try:
|
|
215
|
+
wb = load_workbook(filename, data_only=True)
|
|
216
|
+
|
|
217
|
+
excel_errors = [
|
|
218
|
+
"#VALUE!",
|
|
219
|
+
"#DIV/0!",
|
|
220
|
+
"#REF!",
|
|
221
|
+
"#NAME?",
|
|
222
|
+
"#NULL!",
|
|
223
|
+
"#NUM!",
|
|
224
|
+
"#N/A",
|
|
225
|
+
]
|
|
226
|
+
error_details = {err: [] for err in excel_errors}
|
|
227
|
+
total_errors = 0
|
|
228
|
+
|
|
229
|
+
for sheet_name in wb.sheetnames:
|
|
230
|
+
ws = wb[sheet_name]
|
|
231
|
+
if not hasattr(ws, "iter_rows"):
|
|
232
|
+
continue
|
|
233
|
+
for row in ws.iter_rows():
|
|
234
|
+
for cell in row:
|
|
235
|
+
if cell.value is not None and isinstance(cell.value, str):
|
|
236
|
+
for err in excel_errors:
|
|
237
|
+
if err in cell.value:
|
|
238
|
+
location = f"{sheet_name}!{cell.coordinate}"
|
|
239
|
+
error_details[err].append(location)
|
|
240
|
+
total_errors += 1
|
|
241
|
+
break
|
|
242
|
+
|
|
243
|
+
result = {
|
|
244
|
+
"status": "success" if total_errors == 0 else "errors_found",
|
|
245
|
+
"total_errors": total_errors,
|
|
246
|
+
"error_summary": {},
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
for err_type, locations in error_details.items():
|
|
250
|
+
if locations:
|
|
251
|
+
entry = {"count": len(locations), "locations": locations[:MAX_LOCATIONS]}
|
|
252
|
+
if len(locations) > MAX_LOCATIONS:
|
|
253
|
+
entry["locations_truncated"] = len(locations) - MAX_LOCATIONS
|
|
254
|
+
result["error_summary"][err_type] = entry
|
|
255
|
+
|
|
256
|
+
wb.close()
|
|
257
|
+
|
|
258
|
+
wb_formulas = load_workbook(filename, data_only=False)
|
|
259
|
+
formula_count = 0
|
|
260
|
+
for sheet_name in wb_formulas.sheetnames:
|
|
261
|
+
ws = wb_formulas[sheet_name]
|
|
262
|
+
if not hasattr(ws, "iter_rows"):
|
|
263
|
+
continue
|
|
264
|
+
for row in ws.iter_rows():
|
|
265
|
+
for cell in row:
|
|
266
|
+
if (
|
|
267
|
+
cell.value
|
|
268
|
+
and isinstance(cell.value, str)
|
|
269
|
+
and cell.value.startswith("=")
|
|
270
|
+
):
|
|
271
|
+
formula_count += 1
|
|
272
|
+
wb_formulas.close()
|
|
273
|
+
|
|
274
|
+
result["total_formulas"] = formula_count
|
|
275
|
+
|
|
276
|
+
return result
|
|
277
|
+
|
|
278
|
+
except Exception as e:
|
|
279
|
+
return {"error": str(e)}
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
def main():
|
|
283
|
+
args = [a for a in sys.argv[1:] if a != "--force"]
|
|
284
|
+
force = "--force" in sys.argv[1:]
|
|
285
|
+
|
|
286
|
+
if not args:
|
|
287
|
+
print("Usage: python recalc.py <excel_file> [timeout_seconds] [--force]")
|
|
288
|
+
print("\nRecalculates all formulas in an Excel file using LibreOffice")
|
|
289
|
+
print("\nReturns JSON with error details:")
|
|
290
|
+
print(" - status: 'success' or 'errors_found'")
|
|
291
|
+
print(" - total_errors: Total number of Excel errors found")
|
|
292
|
+
print(" - total_formulas: Number of formulas in the file")
|
|
293
|
+
print(" - error_summary: Breakdown by error type with locations")
|
|
294
|
+
print(" - #VALUE!, #DIV/0!, #REF!, #NAME?, #NULL!, #NUM!, #N/A")
|
|
295
|
+
print("\nOn any failure the JSON has an 'error' key and no 'status'.")
|
|
296
|
+
print("--force recalculates even when it would destroy external links.")
|
|
297
|
+
sys.exit(1)
|
|
298
|
+
|
|
299
|
+
filename = args[0]
|
|
300
|
+
timeout = int(args[1]) if len(args) > 1 else 30
|
|
301
|
+
|
|
302
|
+
result = recalc(filename, timeout, force=force)
|
|
303
|
+
print(json.dumps(result, indent=2))
|
|
304
|
+
sys.exit(1 if "error" in result else 0)
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
if __name__ == "__main__":
|
|
308
|
+
main()
|