minimal-agent 0.8.2 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -12
- package/package.json +34 -1
- package/plugins/cron-runner/.claude-plugin/plugin.json +5 -0
- package/plugins/cron-runner/commands/cron.md +26 -0
- package/plugins/cron-runner/commands/crons.md +7 -0
- package/plugins/cron-runner/plugin.js +34 -0
- package/plugins/cron-runner/src/commands.js +348 -0
- package/plugins/cron-runner/src/cronTime.js +148 -0
- package/plugins/cron-runner/src/lock.js +68 -0
- package/plugins/cron-runner/src/runs.js +89 -0
- package/plugins/cron-runner/src/scheduleEngine.js +72 -0
- package/plugins/cron-runner/src/scheduler.js +355 -0
- package/plugins/cron-runner/src/schema.js +140 -0
- package/plugins/cron-runner/src/service.js +167 -0
- package/plugins/cron-runner/src/store.js +298 -0
- package/plugins/cron-runner/src/types.js +1 -0
- package/plugins/workflow-runner/commands/workflow.md +4 -4
- package/plugins/workflow-runner/commands/workflows.md +1 -1
- package/plugins/workflow-runner/plugin.js +3 -1
- package/plugins/workflow-runner/src/agentCommon.js +249 -51
- package/plugins/workflow-runner/src/dslManifest.js +72 -0
- package/plugins/workflow-runner/src/expressions.js +198 -15
- package/plugins/workflow-runner/src/index.js +40 -8
- package/plugins/workflow-runner/src/jsonPayload.js +1 -1
- package/plugins/workflow-runner/src/loader.js +286 -72
- package/plugins/workflow-runner/src/multimodal.js +37 -0
- package/plugins/workflow-runner/src/recovery.js +49 -39
- package/plugins/workflow-runner/src/runner.js +802 -287
- package/plugins/workflow-runner/src/stepExecutors/agent.js +157 -39
- package/plugins/workflow-runner/src/stepExecutors/assert.js +16 -3
- package/plugins/workflow-runner/src/stepExecutors/llm.js +60 -111
- package/plugins/workflow-runner/src/stepExecutors/skill.js +47 -47
- package/plugins/workflow-runner/src/stepExecutors/tool.js +76 -10
- package/plugins/workflow-runner/src/stepExecutors/verify.js +27 -10
- package/plugins/workflow-runner/src/taskIdentity.js +296 -0
- package/plugins/workflow-runner/src/types.js +19 -9
- package/plugins/workflow-runner/src/workflowState.js +516 -33
- package/skills/adversarial-review/SKILL.md +0 -1
- package/skills/ai-image/SKILL.md +89 -0
- package/skills/ai-image/scripts/generate.mjs +497 -0
- package/skills/ai-image/scripts/generate_from_plan.mjs +469 -0
- package/skills/ai-image/scripts/generate_from_plan_test.mjs +223 -0
- package/skills/ai-image/scripts/generate_test.mjs +74 -0
- package/skills/browser-automation/SKILL.md +47 -0
- package/skills/docx/SKILL.md +25 -3
- package/skills/docx/scripts/office/helpers/__pycache__/__init__.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/helpers/__pycache__/merge_runs.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/helpers/__pycache__/simplify_redlines.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/validators/__pycache__/__init__.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/validators/__pycache__/base.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/validators/__pycache__/docx.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/validators/__pycache__/pptx.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/validators/__pycache__/redlining.cpython-314.pyc +0 -0
- package/skills/docx/scripts/opc_check.py +253 -0
- package/skills/image-gen-openrouter/SKILL.md +10 -2
- package/skills/image-stats/SKILL.md +65 -0
- package/skills/image-stats/scripts/__pycache__/image_stats.cpython-314.pyc +0 -0
- package/skills/image-stats/scripts/__pycache__/image_stats_test.cpython-314.pyc +0 -0
- package/skills/image-stats/scripts/image_stats.py +368 -0
- package/skills/image-stats/scripts/image_stats_test.py +181 -0
- package/skills/pptx/SKILL.md +123 -95
- package/skills/pptx/design.md +82 -0
- package/skills/pptx/examples/README.md +29 -0
- package/skills/pptx/examples/hybrid_example.mjs +107 -0
- package/skills/pptx/examples/hybrid_example.pptx +0 -0
- package/skills/pptx/pptxgenjs.md +41 -0
- package/skills/pptx/scripts/deck_helpers.mjs +224 -0
- package/skills/pptx/scripts/layout_lint.py +293 -0
- package/skills/pptx/scripts/layout_lint_test.py +160 -0
- package/skills/pptx/scripts/opc_check.py +339 -0
- package/skills/pptx/scripts/svg_fallback.mjs +145 -0
- package/skills/pptx/svg.md +67 -0
- package/skills/tts-zh/SKILL.md +19 -2
- package/skills/ui-design/SKILL.md +158 -0
- package/skills/ui-design/claude_design.md +309 -0
- package/skills/ui-design/evals/evals.json +254 -0
- package/skills/ui-design/references/aesthetic-direction.md +83 -0
- package/skills/ui-design/references/claude-design-protocol.md +36 -0
- package/skills/ui-design/references/design-context.md +53 -0
- package/skills/ui-design/references/design-execution-playbook.md +82 -0
- package/skills/ui-design/references/export-pptx.md +124 -0
- package/skills/ui-design/references/layout-composition.md +654 -0
- package/skills/ui-design/references/preview-feedback.md +37 -0
- package/skills/ui-design/references/source-image-layout.md +189 -0
- package/skills/ui-design/references/starter-components.md +78 -0
- package/skills/ui-design/references/vi-aegis-vector.md +144 -0
- package/skills/ui-design/references/vi-amber-prism.md +133 -0
- package/skills/ui-design/references/vi-aqua-glass.md +200 -0
- package/skills/ui-design/references/vi-comfort-vision.md +147 -0
- package/skills/ui-design/references/vi-ember-prism.md +140 -0
- package/skills/ui-design/references/vi-nebula-console.md +151 -0
- package/skills/ui-design/references/vi-obsidian-optics.md +139 -0
- package/skills/ui-design/references/vi-obsidian-xui.md +143 -0
- package/skills/ui-design/references/vi-precision-horizon-dark.md +117 -0
- package/skills/ui-design/references/vi-precision-horizon.md +215 -0
- package/skills/ui-design/references/vi-solar-relay.md +130 -0
- package/skills/ui-design/references/vi-template-workflow.md +48 -0
- package/skills/ui-design/references/vi-verdant-grid.md +141 -0
- package/skills/ui-design/references/vi-violet-meridian.md +172 -0
- package/skills/ui-design/scripts/__pycache__/assemble_material.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/assemble_material_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/chart_sanity_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/check_language_policy.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/check_ui_artifact.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/check_ui_artifact_pptx_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/deck_pages_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/deck_pages_check_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/deck_visual_style_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/deck_visual_style_check_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/design_budget_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/design_budget_check_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/design_repair_hints.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/design_repair_hints_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/design_style_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/design_style_check_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/draft_coverage_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/extract_source_assets.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/extract_source_assets_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/generated_image_review_collect.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/generated_image_review_collect_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/image_plan_lint.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/image_plan_lint_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/image_prompt_rewrite.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/image_prompt_rewrite_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/layout_balance.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/layout_balance_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/normalize_design_json.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/normalize_design_json_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/plan_source_layout.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/plan_source_layout_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/resolve_source_hint.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/resolve_source_hint_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/resolve_source_input.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/resolve_source_input_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/scaffold_ui_artifact.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/source_usage_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/source_usage_check_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/text_readability_pixel.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/visual_quality_gate.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/visual_quality_gate_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/assemble_material.py +217 -0
- package/skills/ui-design/scripts/assemble_material_test.py +149 -0
- package/skills/ui-design/scripts/browser_check_ui_artifact.mjs +221 -0
- package/skills/ui-design/scripts/chart_sanity_check.py +261 -0
- package/skills/ui-design/scripts/chart_sanity_check_test.py +165 -0
- package/skills/ui-design/scripts/check_language_policy.py +351 -0
- package/skills/ui-design/scripts/check_ui_artifact.py +435 -0
- package/skills/ui-design/scripts/check_ui_artifact_pptx_test.py +251 -0
- package/skills/ui-design/scripts/deck_pages_check.py +158 -0
- package/skills/ui-design/scripts/deck_pages_check_test.py +134 -0
- package/skills/ui-design/scripts/deck_visual_style_check.py +767 -0
- package/skills/ui-design/scripts/deck_visual_style_check_test.py +713 -0
- package/skills/ui-design/scripts/design_budget_check.py +271 -0
- package/skills/ui-design/scripts/design_budget_check_test.py +183 -0
- package/skills/ui-design/scripts/design_repair_hints.py +162 -0
- package/skills/ui-design/scripts/design_repair_hints_test.py +54 -0
- package/skills/ui-design/scripts/design_style_check.py +397 -0
- package/skills/ui-design/scripts/design_style_check_test.py +233 -0
- package/skills/ui-design/scripts/draft_coverage_check.py +184 -0
- package/skills/ui-design/scripts/draft_coverage_check_test.py +131 -0
- package/skills/ui-design/scripts/export_pptx_from_html.mjs +2367 -0
- package/skills/ui-design/scripts/extract_source_assets.py +607 -0
- package/skills/ui-design/scripts/extract_source_assets_test.py +256 -0
- package/skills/ui-design/scripts/generated_image_review_collect.py +206 -0
- package/skills/ui-design/scripts/generated_image_review_collect_test.py +91 -0
- package/skills/ui-design/scripts/image_plan_lint.py +571 -0
- package/skills/ui-design/scripts/image_plan_lint_test.py +515 -0
- package/skills/ui-design/scripts/image_prompt_rewrite.py +713 -0
- package/skills/ui-design/scripts/image_prompt_rewrite_test.py +966 -0
- package/skills/ui-design/scripts/layout_balance.py +881 -0
- package/skills/ui-design/scripts/layout_balance_test.py +927 -0
- package/skills/ui-design/scripts/normalize_design_json.py +272 -0
- package/skills/ui-design/scripts/normalize_design_json_test.py +119 -0
- package/skills/ui-design/scripts/plan_source_layout.py +1450 -0
- package/skills/ui-design/scripts/plan_source_layout_test.py +1136 -0
- package/skills/ui-design/scripts/resolve_source_input.py +270 -0
- package/skills/ui-design/scripts/resolve_source_input_test.py +98 -0
- package/skills/ui-design/scripts/scaffold_ui_artifact.py +377 -0
- package/skills/ui-design/scripts/source_usage_check.py +581 -0
- package/skills/ui-design/scripts/source_usage_check_test.py +427 -0
- package/skills/ui-design/scripts/text_readability_pixel.py +340 -0
- package/skills/ui-design/scripts/text_readability_pixel_test.py +219 -0
- package/skills/ui-design/scripts/visual_quality_gate.py +301 -0
- package/skills/ui-design/scripts/visual_quality_gate_test.py +233 -0
- package/skills/ui-design/tests/e2e/prompts/deck.md +19 -0
- package/skills/ui-design/tests/e2e/prompts/webpage.md +17 -0
- package/skills/ui-design/tests/e2e/render_check.mjs +101 -0
- package/skills/ui-design/tests/e2e/rubric.json +54 -0
- package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/checks/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/checks/language-check.txt +12 -0
- package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/checks/static-check.txt +15 -0
- package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/outputs/index.html +837 -0
- package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/prompt.md +12 -0
- package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/review.md +21 -0
- package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/screenshots/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/outputs/homepage.html +373 -0
- package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/outputs/platform.html +378 -0
- package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/prompt.md +13 -0
- package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/review.md +26 -0
- package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/screenshots/homepage/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/screenshots/homepage/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/screenshots/homepage/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/screenshots/platform/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/screenshots/platform/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/screenshots/platform/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-1/checks/static-check.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-1/outputs/index.html +656 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-1/prompt.md +12 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-1/render_check.mjs +67 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-2/checks/static-check.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-2/outputs/index.html +587 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-2/prompt.md +12 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-2/review.md +36 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/checks/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/checks/language-check.txt +8 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/checks/static-check.txt +16 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/outputs/index.html +739 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/prompt.md +11 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/review.md +22 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/screenshots/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/comfort-vision-preview-1/checks/browser-check.json +52 -0
- package/skills/ui-design/tests/e2e/runs/comfort-vision-preview-1/outputs/index.html +641 -0
- package/skills/ui-design/tests/e2e/runs/comfort-vision-preview-1/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/comfort-vision-preview-1/screenshots/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-red-preview-1/outputs/index.html +467 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-red-preview-1/screenshots/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-red-preview-1/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-red-preview-1/screenshots/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/outputs/homepage.html +373 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/outputs/platform.html +378 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/prompt.md +13 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/review.md +26 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/screenshots/homepage/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/screenshots/homepage/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/screenshots/homepage/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/screenshots/platform/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/screenshots/platform/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/screenshots/platform/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/checks/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/checks/language-check.txt +4 -0
- package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/checks/static-check.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/execution_notes.md +10 -0
- package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/outputs/index.html +587 -0
- package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/prompt.md +14 -0
- package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/review.md +13 -0
- package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/screenshots/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/deck/checks/browser-check.json +24 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/deck/checks/static-check.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/deck/execution_notes.md +21 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/deck/outputs/deck.html +451 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/deck/screenshots/slide-01.png +0 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/deck/screenshots/slide-02.png +0 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/review.md +79 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/webpage/checks/browser-check.json +26 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/webpage/checks/static-check.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/webpage/execution_notes.md +20 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/webpage/outputs/index.html +534 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/webpage/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/webpage/screenshots/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/checks/browser-check.json +64 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/checks/language-check.txt +7 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/checks/quick-validate.txt +1 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/checks/static-console.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/checks/static-homepage.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/outputs/console.html +600 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/outputs/homepage.html +556 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/prompt.md +29 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/review.md +57 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/screenshots/console-desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/screenshots/console-mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/screenshots/homepage-desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/screenshots/homepage-mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/checks/browser-check.json +33 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/checks/language-check.txt +6 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/checks/quick-validate.txt +1 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/checks/static-check.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/outputs/index.html +682 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/prompt.md +13 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/review.md +59 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/screenshots/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/outputs/page-01.html +466 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/outputs/page-02.html +433 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/prompt.md +13 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/screenshots/page-01/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/screenshots/page-01/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/screenshots/page-01/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/screenshots/page-02/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/screenshots/page-02/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/screenshots/page-02/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/checks/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/checks/language-check.txt +3 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/checks/static-check.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/execution_notes.md +24 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/outputs/index.html +723 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/prompt.md +15 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/review.md +26 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/screenshots/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/checks/browser-dark.json +49 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/checks/browser-light.json +49 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/checks/language-check.txt +11 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/checks/static-dark.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/checks/static-light.txt +3 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/execution_notes.md +23 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/outputs/dark.html +392 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/outputs/light.html +476 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/prompt.md +23 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/review.md +41 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/screenshots/dark/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/screenshots/dark/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/screenshots/light/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/screenshots/light/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/checks/browser-check.json +54 -0
- package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/checks/language-check.txt +5 -0
- package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/checks/quick-validate.txt +1 -0
- package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/checks/static-check.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/outputs/index.html +765 -0
- package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/prompt.md +15 -0
- package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/review.md +59 -0
- package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/screenshots/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/verdant-grid-preview-1/outputs/index.html +508 -0
- package/skills/ui-design/tests/e2e/runs/verdant-grid-preview-1/screenshots/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/verdant-grid-preview-1/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/verdant-grid-preview-1/screenshots/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/checks/browser-check.json +54 -0
- package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/checks/language-check.txt +6 -0
- package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/checks/quick-validate.txt +1 -0
- package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/checks/static-check.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/outputs/index.html +788 -0
- package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/prompt.md +14 -0
- package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/review.md +60 -0
- package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/screenshots/mobile.png +0 -0
- package/skills/video-compose/SKILL.md +8 -1
- package/skills/web-crawler/SKILL.md +70 -0
- package/skills/web-crawler/scripts/crawl.mjs +538 -0
- package/skills/web-crawler/scripts/crawl.test.mjs +204 -0
- package/skills/xlsx/SKILL.md +12 -0
- package/skills/xlsx/scripts/opc_check.py +253 -0
- package/src/advisorState.js +22 -0
- package/src/askBridge.js +97 -3
- package/src/bootstrap/workingDir.js +12 -1
- package/src/cli/args.js +17 -1
- package/src/cli/configMenu.js +236 -0
- package/src/cli/configWizard.js +7 -5
- package/src/cli/print.js +37 -4
- package/src/cli/streamJson.js +77 -24
- package/src/cli/wizards/advisorWizard.js +147 -0
- package/src/cli/wizards/fieldForm.js +149 -0
- package/src/cli/wizards/imageWizard.js +60 -0
- package/src/cli/wizards/openRouterWizard.js +23 -0
- package/src/cli/wizards/providerPresets.js +95 -0
- package/src/cli/wizards/providerWizard.js +219 -0
- package/src/cli/wizards/searchWizard.js +23 -0
- package/src/cli/wizards/ttsWizard.js +34 -0
- package/src/config/configFile.js +441 -83
- package/src/config/configService.js +446 -0
- package/src/config.js +24 -64
- package/src/context/agentHome.js +9 -0
- package/src/context/archive.js +7 -2
- package/src/context/compact.js +8 -5
- package/src/context/contextLock.js +81 -0
- package/src/context/persistContext.js +30 -11
- package/src/context/reactiveCompact.js +4 -2
- package/src/context/recentDirs.js +21 -61
- package/src/context/sessionPath.js +97 -23
- package/src/context/sessionRegistry.js +303 -24
- package/src/context/tokenCounter.js +18 -0
- package/src/context/workspaceIndex.js +731 -0
- package/src/infra/verification.js +28 -15
- package/src/llm/client.js +394 -159
- package/src/llm/providers/anthropicFormat.js +241 -0
- package/src/llm/providers/openaiFormat.js +190 -0
- package/src/loop.js +219 -32
- package/src/main.js +61 -11
- package/src/messageQueue.js +97 -0
- package/src/multimodal.js +203 -0
- package/src/plugin-sdk.js +15 -0
- package/src/plugins/commandRouter.js +3 -0
- package/src/plugins/hookEngine.js +5 -1
- package/src/plugins/pluginLifecycle.js +28 -0
- package/src/plugins/pluginLoader.js +2 -1
- package/src/plugins/pluginRunner.js +49 -21
- package/src/plugins/transcript.js +4 -3
- package/src/prompts/pluginList.js +5 -5
- package/src/prompts/projectInstructions.js +3 -3
- package/src/prompts/promptAssembly.js +133 -144
- package/src/prompts/skillList.js +12 -22
- package/src/prompts/system.js +0 -1
- package/src/session/runAgentTurn.js +70 -0
- package/src/session/runTurn.js +41 -6
- package/src/toolGate.js +17 -0
- package/src/tools/advisor/advisor.js +379 -0
- package/src/tools/agent/agent.js +555 -0
- package/src/tools/agent/agentTypes.js +59 -0
- package/src/tools/agent/coordinator.js +93 -0
- package/src/tools/agent/worktree.js +270 -0
- package/src/tools/ask/ask.js +7 -2
- package/src/tools/bash/bash.js +112 -18
- package/src/tools/download/download.js +144 -0
- package/src/tools/edit/edit.js +1 -0
- package/src/tools/edit/multi-edit.js +1 -0
- package/src/tools/genimage/genimage.js +242 -0
- package/src/tools/genspeech/genspeech.js +67 -0
- package/src/tools/glob/glob.js +1 -0
- package/src/tools/grep/grep.js +3 -0
- package/src/tools/grep/rgPath.js +2 -0
- package/src/tools/index.js +25 -2
- package/src/tools/read/read.js +1 -0
- package/src/tools/shared/killTree.js +52 -0
- package/src/tools/toolProgressBridge.js +48 -0
- package/src/tools/webbrowser/agentBrowserPath.js +258 -0
- package/src/tools/webbrowser/browser.js +59 -42
- package/src/tools/webbrowser/browserControl.js +118 -0
- package/src/tools/webbrowser/browserDaemon.js +97 -0
- package/src/tools/webbrowser/browserService.js +27 -0
- package/src/tools/webbrowser/browserStream.js +119 -0
- package/src/tools/webbrowser/webbrowser.js +699 -130
- package/src/tools/webfetch/webfetch.js +1 -0
- package/src/tools/websearch/websearch.js +134 -51
- package/src/tools/write/write.js +1 -0
- package/src/ui/App.js +249 -22
- package/src/ui/AskQuestion.js +29 -10
- package/src/ui/InputBox.js +104 -12
- package/src/ui/LiveArea.js +112 -19
- package/src/ui/MessageList.js +100 -14
- package/src/ui/ModelPicker.js +56 -0
- package/src/ui/QueuedMessagesBanner.js +14 -0
- package/src/ui/Root.js +18 -10
- package/src/ui/SessionPicker.js +102 -0
- package/src/ui/StatusLine.js +13 -4
- package/src/ui/WorkspacePicker.js +55 -0
- package/src/ui/figures.js +44 -0
- package/src/ui/hooks/askSlot.js +82 -0
- package/src/ui/hooks/useChat.js +358 -64
- package/src/ui/hooks/usePasteHandler.js +11 -1
- package/src/ui/hooks/useTextBuffer.js +1 -3
- package/src/ui/liveViewport.js +5 -1
- package/src/ui/markdown.js +206 -0
- package/src/ui/textBuffer.js +0 -7
- package/src/ui/theme.js +32 -0
- package/src/utils/debugLog.js +0 -4
- package/src/utils/resourcePaths.js +2 -2
- package/src/utils/stripThink.js +50 -0
- package/src/web/browserBridge.js +447 -0
- package/src/web/protocol.js +19 -0
- package/workflows/adaptive-research.yaml +13 -5
- package/workflows/book-review-short.yaml +36 -10
- package/workflows/e2e-write-greet.yaml +6 -2
- package/workflows/illustrate.yaml +227 -0
- package/workflows/plan.yaml +460 -179
- package/workflows/ppt.yaml +1659 -0
- package/workflows/ralph-loop.yaml +199 -0
- package/workflows/schema.json +81 -23
- package/workflows/webppt.yaml +496 -0
- package/workflows/word.yaml +710 -0
- package/workflows/youtube-shorts.yaml +46 -15
- package/MINIMAL-TRACE.md +0 -77
- package/plugins/HOW-TO-WRITE-A-PLUGIN.md +0 -186
- package/plugins/ralph-wiggum/.claude-plugin/plugin.json +0 -9
- package/plugins/ralph-wiggum/README.md +0 -197
- package/plugins/ralph-wiggum/commands/cancel-ralph.md +0 -18
- package/plugins/ralph-wiggum/commands/help.md +0 -137
- package/plugins/ralph-wiggum/commands/ralph-loop.md +0 -85
- package/plugins/ralph-wiggum/hooks/hooks.json +0 -15
- package/plugins/ralph-wiggum/hooks/stop-hook.sh +0 -191
- package/plugins/ralph-wiggum/plugin.js +0 -280
- package/plugins/ralph-wiggum/src/goalState.js +0 -258
- package/plugins/ralph-wiggum/src/sentinels.js +0 -76
- package/plugins/ralph-wiggum/src/stopHookRunner.js +0 -104
- package/plugins/ralph-wiggum/src/verificationGate.js +0 -202
- package/plugins/workflow-runner/src/miniReAct.js +0 -223
- package/plugins/workflow-runner/src/voteHelpers.js +0 -110
- package/skills/config/SKILL.md +0 -123
- package/skills/frontend-design/LICENSE.txt +0 -177
- package/skills/frontend-design/SKILL.md +0 -42
- package/src/ui/ProgressPanel.js +0 -54
- package/src/ui/StreamingBlock.js +0 -11
- package/src/ui/ToolStatus.js +0 -11
|
@@ -0,0 +1,607 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
extract_source_assets.py —— 从用户提供的 Word/PPT/PDF/Excel/图片 抽取「文字 + 图片」作为 PPT 生成的高权重素材。
|
|
5
|
+
|
|
6
|
+
为什么需要
|
|
7
|
+
==========
|
|
8
|
+
ppt 工作流(workflows/ppt.yaml)支持「一段描述 + 任意素材(Word/PPT/Excel/PDF/图片,可多种混合)」→ 生成 PPT。客户素材里的
|
|
9
|
+
**文字是内容主干、图片要高权重复用**。这类机械抽取(unzip/遍历 shape/关联章节/取原始宽高比)
|
|
10
|
+
交给弱模型手搓不可靠,故收归确定性脚本——同 image_plan_lint.py / deck_pages_check.py 的哲学:
|
|
11
|
+
确定性的活脚本干,LLM 只做判断。
|
|
12
|
+
|
|
13
|
+
抽什么
|
|
14
|
+
======
|
|
15
|
+
- 文字:pptx 逐 slide / docx 逐 heading 段落(老 .doc 先转 docx)/ pdf 逐页 / xlsx 逐 sheet(openpyxl)/ csv·tsv(pandas)→ markdown 表,
|
|
16
|
+
落 `source.md`(保留章节标题层级)。
|
|
17
|
+
- 图片:pptx 逐 picture shape / docx 的 word/media(按文档顺序关联最近 heading)/ pdf 逐页内嵌图 /
|
|
18
|
+
xlsx 的 xl/media(纯 zipfile、免 openpyxl)/ **独立图片文件**(用户直接给的 png/jpg/…),
|
|
19
|
+
落 `assets/src_K.png`(K 从 1 连续编号;与 AI 图 img_K.png 同目录、src_ 前缀区分)。
|
|
20
|
+
- 每张图记 **原始宽高比 + 朝向 + 所属章节 + 邻近文案**(manifest),供下游「等比不裁切 + 按朝向图文混排」。
|
|
21
|
+
|
|
22
|
+
产物(落到 --out 目录,默认 ./build)
|
|
23
|
+
====================================
|
|
24
|
+
- source.md : 抽取正文(markdown,按 slide/heading/page 分节)
|
|
25
|
+
- assets/src_K.<ext> : 抽取图片(保留原生扩展名,不重编码不失真)
|
|
26
|
+
- source_assets.json : manifest(机读,驱动下游 design/build):
|
|
27
|
+
{"has_source":bool, "sources":[...], "text_file":"source.md",
|
|
28
|
+
"images":[{"file":"src_1.png","w":1600,"h":900,"aspect_ratio":1.78,
|
|
29
|
+
"orient":"landscape|portrait|square","section":"产品概览",
|
|
30
|
+
"near_text":"…","origin":"brief.pptx#slide3"}]}
|
|
31
|
+
|
|
32
|
+
用法
|
|
33
|
+
====
|
|
34
|
+
python extract_source_assets.py <doc-or-dir> [--out ./build] [-v]
|
|
35
|
+
python extract_source_assets.py --scan <dir> [--out ./build] # 目录里自动找 *.pptx/*.doc/*.docx/*.pdf
|
|
36
|
+
找不到任何源素材 → 写 has_source:false 的 manifest,**退出 0**(不报错,下游据此走纯 topic 路径)。
|
|
37
|
+
|
|
38
|
+
依赖:python-pptx / python-docx / Pillow(pptx+docx+图片,已就绪);pandas(csv/tsv,已就绪);
|
|
39
|
+
openpyxl(xlsx 文字可选,缺则跳过文字仍抽内嵌图 + 提示安装);pypdf(pdf 可选,缺则跳过 + 提示安装)。
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
import argparse
|
|
43
|
+
import glob
|
|
44
|
+
import hashlib
|
|
45
|
+
import io
|
|
46
|
+
import json
|
|
47
|
+
import os
|
|
48
|
+
import shutil
|
|
49
|
+
import subprocess
|
|
50
|
+
import sys
|
|
51
|
+
import tempfile
|
|
52
|
+
import zipfile
|
|
53
|
+
|
|
54
|
+
# 文档类(抽文字 + 内嵌图)+ 表格类 + 独立图片类。三类都参与 --scan / 单文件识别。
|
|
55
|
+
DOC_EXTS = (".pptx", ".doc", ".docx", ".pdf", ".xlsx", ".csv", ".tsv")
|
|
56
|
+
IMAGE_EXTS = (".png", ".jpg", ".jpeg", ".gif", ".webp", ".bmp", ".tif", ".tiff")
|
|
57
|
+
SUPPORTED_EXTS = DOC_EXTS + IMAGE_EXTS
|
|
58
|
+
LANDSCAPE_MIN = 1.25 # w/h ≥ 此值 = 横图
|
|
59
|
+
PORTRAIT_MAX = 0.80 # w/h ≤ 此值 = 竖图(之间 = 近方图)
|
|
60
|
+
NEAR_TEXT_LIMIT = 240 # 邻近文案截断长度(manifest 不灌长文)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _log(verbose: bool, msg: str) -> None:
|
|
64
|
+
if verbose:
|
|
65
|
+
print(f"[extract] {msg}", file=sys.stderr)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _orient(w: int, h: int) -> str:
|
|
69
|
+
if not w or not h:
|
|
70
|
+
return "square"
|
|
71
|
+
ar = w / h
|
|
72
|
+
if ar >= LANDSCAPE_MIN:
|
|
73
|
+
return "landscape"
|
|
74
|
+
if ar <= PORTRAIT_MAX:
|
|
75
|
+
return "portrait"
|
|
76
|
+
return "square"
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def _image_size(blob: bytes):
|
|
80
|
+
"""用 PIL 读原生宽高(失败返回 (0,0),不让单张坏图拖垮整体)。"""
|
|
81
|
+
try:
|
|
82
|
+
from PIL import Image # 延迟导入:缺 Pillow 时仍能抽文字
|
|
83
|
+
with Image.open(io.BytesIO(blob)) as im:
|
|
84
|
+
return int(im.width), int(im.height)
|
|
85
|
+
except Exception:
|
|
86
|
+
return 0, 0
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _save_image(blob: bytes, ext: str, out_assets: str, index: int):
|
|
90
|
+
"""把图片 blob 落盘为 assets/src_K.<ext>(保留原生格式,不重编码避免失真)。返回 (file, w, h)。"""
|
|
91
|
+
ext = (ext or "png").lower().lstrip(".")
|
|
92
|
+
if ext == "jpeg":
|
|
93
|
+
ext = "jpg"
|
|
94
|
+
if ext not in ("png", "jpg", "gif", "bmp", "tiff", "webp", "emf", "wmf"):
|
|
95
|
+
ext = "png"
|
|
96
|
+
fname = f"src_{index}.{ext}"
|
|
97
|
+
with open(os.path.join(out_assets, fname), "wb") as f:
|
|
98
|
+
f.write(blob)
|
|
99
|
+
w, h = _image_size(blob)
|
|
100
|
+
return fname, w, h
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def _truncate(text: str) -> str:
|
|
104
|
+
text = " ".join((text or "").split())
|
|
105
|
+
return text[:NEAR_TEXT_LIMIT]
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
# ---------------------------------------------------------------------------
|
|
109
|
+
# pptx:逐 slide 抽文字 + picture shape 抽图
|
|
110
|
+
# ---------------------------------------------------------------------------
|
|
111
|
+
def _extract_pptx(path, out_assets, md_lines, images, start_index, verbose):
|
|
112
|
+
from pptx import Presentation
|
|
113
|
+
from pptx.enum.shapes import MSO_SHAPE_TYPE
|
|
114
|
+
|
|
115
|
+
prs = Presentation(path)
|
|
116
|
+
base = os.path.basename(path)
|
|
117
|
+
idx = start_index
|
|
118
|
+
|
|
119
|
+
def walk_pictures(shapes):
|
|
120
|
+
"""递归收集 picture(含 group 内嵌套图)。"""
|
|
121
|
+
for sh in shapes:
|
|
122
|
+
if sh.shape_type == MSO_SHAPE_TYPE.GROUP:
|
|
123
|
+
yield from walk_pictures(sh.shapes)
|
|
124
|
+
elif sh.shape_type == MSO_SHAPE_TYPE.PICTURE:
|
|
125
|
+
yield sh
|
|
126
|
+
|
|
127
|
+
for sn, slide in enumerate(prs.slides, 1):
|
|
128
|
+
# 该页文字(标题优先)
|
|
129
|
+
title = ""
|
|
130
|
+
texts = []
|
|
131
|
+
for sh in slide.shapes:
|
|
132
|
+
if not sh.has_text_frame:
|
|
133
|
+
continue
|
|
134
|
+
t = sh.text_frame.text.strip()
|
|
135
|
+
if not t:
|
|
136
|
+
continue
|
|
137
|
+
if not title and sh == getattr(slide.shapes, "title", None):
|
|
138
|
+
title = t.splitlines()[0]
|
|
139
|
+
texts.append(t)
|
|
140
|
+
section = title or f"第 {sn} 页"
|
|
141
|
+
md_lines.append(f"\n## Slide {sn}:{section}\n")
|
|
142
|
+
for t in texts:
|
|
143
|
+
for line in t.splitlines():
|
|
144
|
+
line = line.strip()
|
|
145
|
+
if line:
|
|
146
|
+
md_lines.append(f"- {line}")
|
|
147
|
+
near = _truncate(" ".join(texts))
|
|
148
|
+
|
|
149
|
+
# 该页图片
|
|
150
|
+
for sh in walk_pictures(slide.shapes):
|
|
151
|
+
try:
|
|
152
|
+
img = sh.image
|
|
153
|
+
fname, w, h = _save_image(img.blob, img.ext, out_assets, idx)
|
|
154
|
+
images.append({
|
|
155
|
+
"file": fname, "w": w, "h": h,
|
|
156
|
+
"aspect_ratio": round(w / h, 4) if w and h else 0,
|
|
157
|
+
"orient": _orient(w, h),
|
|
158
|
+
"section": section, "near_text": near,
|
|
159
|
+
"origin": f"{base}#slide{sn}",
|
|
160
|
+
})
|
|
161
|
+
_log(verbose, f"pptx slide{sn} 图 {fname} {w}x{h} {_orient(w, h)}")
|
|
162
|
+
idx += 1
|
|
163
|
+
except Exception as e: # 单张坏图不拖垮整体
|
|
164
|
+
_log(verbose, f"pptx slide{sn} 跳过一张图:{e}")
|
|
165
|
+
return idx
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
# ---------------------------------------------------------------------------
|
|
169
|
+
# docx:按文档顺序遍历段落,跟踪当前 heading,blip 关联最近 heading
|
|
170
|
+
# ---------------------------------------------------------------------------
|
|
171
|
+
def _extract_docx(path, out_assets, md_lines, images, start_index, verbose):
|
|
172
|
+
from docx import Document
|
|
173
|
+
|
|
174
|
+
doc = Document(path)
|
|
175
|
+
base = os.path.basename(path)
|
|
176
|
+
idx = start_index
|
|
177
|
+
seen_hashes = set()
|
|
178
|
+
ns_r = "{http://schemas.openxmlformats.org/officeDocument/2006/relationships}"
|
|
179
|
+
ns_a = "{http://schemas.openxmlformats.org/drawingml/2006/main}"
|
|
180
|
+
current_section = "正文"
|
|
181
|
+
recent_text = [] # 最近几段正文(给图片当 near_text)
|
|
182
|
+
|
|
183
|
+
for para in doc.paragraphs:
|
|
184
|
+
style = (para.style.name or "") if para.style else ""
|
|
185
|
+
text = para.text.strip()
|
|
186
|
+
if style.lower().startswith("heading") and text:
|
|
187
|
+
current_section = text
|
|
188
|
+
level = "".join(ch for ch in style if ch.isdigit()) or "2"
|
|
189
|
+
md_lines.append(f"\n{'#' * min(int(level) + 1, 6)} {text}\n")
|
|
190
|
+
recent_text = []
|
|
191
|
+
elif text:
|
|
192
|
+
md_lines.append(text)
|
|
193
|
+
recent_text.append(text)
|
|
194
|
+
recent_text = recent_text[-3:]
|
|
195
|
+
|
|
196
|
+
# 该段内嵌图(a:blip r:embed → rId → image part)
|
|
197
|
+
for blip in para._p.findall(f".//{ns_a}blip"):
|
|
198
|
+
rid = blip.get(f"{ns_r}embed")
|
|
199
|
+
if not rid or rid not in doc.part.related_parts:
|
|
200
|
+
continue
|
|
201
|
+
try:
|
|
202
|
+
part = doc.part.related_parts[rid]
|
|
203
|
+
blob = part.blob
|
|
204
|
+
seen_hashes.add(hashlib.sha1(blob).hexdigest())
|
|
205
|
+
ext = os.path.splitext(part.partname)[1] or ".png"
|
|
206
|
+
fname, w, h = _save_image(blob, ext, out_assets, idx)
|
|
207
|
+
images.append({
|
|
208
|
+
"file": fname, "w": w, "h": h,
|
|
209
|
+
"aspect_ratio": round(w / h, 4) if w and h else 0,
|
|
210
|
+
"orient": _orient(w, h),
|
|
211
|
+
"section": current_section,
|
|
212
|
+
"near_text": _truncate(" ".join(recent_text) or text),
|
|
213
|
+
"origin": f"{base}#{current_section}",
|
|
214
|
+
})
|
|
215
|
+
_log(verbose, f"docx 图 {fname} {w}x{h} {_orient(w, h)} @ {current_section}")
|
|
216
|
+
idx += 1
|
|
217
|
+
except Exception as e:
|
|
218
|
+
_log(verbose, f"docx 跳过一张图:{e}")
|
|
219
|
+
|
|
220
|
+
# 兜底:部分 Word 里的浮动图、形状图或兼容模式转换图不一定出现在段落
|
|
221
|
+
# blip 遍历里,但会存在于 word/media。补扫一次并按 hash 去重。
|
|
222
|
+
try:
|
|
223
|
+
with zipfile.ZipFile(path) as z:
|
|
224
|
+
names = sorted(
|
|
225
|
+
n for n in z.namelist()
|
|
226
|
+
if n.startswith("word/media/") and not n.endswith("/")
|
|
227
|
+
)
|
|
228
|
+
for n in names:
|
|
229
|
+
try:
|
|
230
|
+
blob = z.read(n)
|
|
231
|
+
hsh = hashlib.sha1(blob).hexdigest()
|
|
232
|
+
if hsh in seen_hashes:
|
|
233
|
+
continue
|
|
234
|
+
seen_hashes.add(hsh)
|
|
235
|
+
ext = os.path.splitext(n)[1] or ".png"
|
|
236
|
+
fname, w, h = _save_image(blob, ext, out_assets, idx)
|
|
237
|
+
images.append({
|
|
238
|
+
"file": fname, "w": w, "h": h,
|
|
239
|
+
"aspect_ratio": round(w / h, 4) if w and h else 0,
|
|
240
|
+
"orient": _orient(w, h),
|
|
241
|
+
"section": current_section or "文档内嵌图",
|
|
242
|
+
"near_text": _truncate(" ".join(recent_text)),
|
|
243
|
+
"origin": f"{base}#{os.path.basename(n)}",
|
|
244
|
+
})
|
|
245
|
+
_log(verbose, f"docx word/media 兜底图 {fname} {w}x{h} {_orient(w, h)}")
|
|
246
|
+
idx += 1
|
|
247
|
+
except Exception as e:
|
|
248
|
+
_log(verbose, f"docx word/media 跳过一张图:{e}")
|
|
249
|
+
except Exception as e:
|
|
250
|
+
_log(verbose, f"docx word/media 兜底读取失败:{e}")
|
|
251
|
+
return idx
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def _find_soffice():
|
|
255
|
+
"""定位 LibreOffice/soffice 可执行文件。
|
|
256
|
+
|
|
257
|
+
为什么不能只 shutil.which:LibreOffice 在 Windows 默认装到
|
|
258
|
+
`C:\\Program Files\\LibreOffice\\program\\soffice.exe` 但**不会自动进 PATH**,
|
|
259
|
+
macOS 装进 .app 包内、Linux 有时落 /opt——`which` 只查 PATH 全都漏掉,
|
|
260
|
+
于是「明明装了却报未找到」(真机 K1 同款:bash.ts 探 Git Bash 也是这套路)。
|
|
261
|
+
顺序:env 显式覆盖 → PATH → 各平台标准安装位置(含通配)。找不到返回 None。
|
|
262
|
+
"""
|
|
263
|
+
env = os.environ.get("MINIMAL_AGENT_SOFFICE") or os.environ.get("SOFFICE_PATH")
|
|
264
|
+
if env and os.path.isfile(env):
|
|
265
|
+
return env
|
|
266
|
+
found = shutil.which("soffice") or shutil.which("libreoffice")
|
|
267
|
+
if found:
|
|
268
|
+
return found
|
|
269
|
+
candidates = [
|
|
270
|
+
# Windows
|
|
271
|
+
r"C:\Program Files\LibreOffice\program\soffice.exe",
|
|
272
|
+
r"C:\Program Files (x86)\LibreOffice\program\soffice.exe",
|
|
273
|
+
# macOS
|
|
274
|
+
"/Applications/LibreOffice.app/Contents/MacOS/soffice",
|
|
275
|
+
# Linux 常见落点
|
|
276
|
+
"/usr/bin/soffice",
|
|
277
|
+
"/usr/bin/libreoffice",
|
|
278
|
+
"/snap/bin/libreoffice",
|
|
279
|
+
]
|
|
280
|
+
# Linux /opt 下带版本号目录用通配兜底
|
|
281
|
+
candidates.extend(sorted(glob.glob("/opt/libreoffice*/program/soffice")))
|
|
282
|
+
for c in candidates:
|
|
283
|
+
if os.path.isfile(c):
|
|
284
|
+
return c
|
|
285
|
+
return None
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
def _convert_doc_to_docx(path, verbose):
|
|
289
|
+
"""用 LibreOffice headless 把老 .doc 转成临时 .docx。返回临时 docx 路径。"""
|
|
290
|
+
soffice = _find_soffice()
|
|
291
|
+
if not soffice:
|
|
292
|
+
raise RuntimeError(
|
|
293
|
+
"无法转换 .doc:未找到 LibreOffice/soffice(PATH 与标准安装位置均无)。"
|
|
294
|
+
"请安装 LibreOffice,或设环境变量 MINIMAL_AGENT_SOFFICE 指向 soffice 可执行文件,"
|
|
295
|
+
"或先把 .doc 另存为 .docx 再试。"
|
|
296
|
+
)
|
|
297
|
+
tmp = tempfile.mkdtemp(prefix="extract-doc-")
|
|
298
|
+
cmd = [
|
|
299
|
+
soffice,
|
|
300
|
+
"--headless",
|
|
301
|
+
"--convert-to",
|
|
302
|
+
"docx",
|
|
303
|
+
"--outdir",
|
|
304
|
+
tmp,
|
|
305
|
+
path,
|
|
306
|
+
]
|
|
307
|
+
_log(verbose, f"转换 .doc → .docx: {' '.join(cmd)}")
|
|
308
|
+
try:
|
|
309
|
+
result = subprocess.run(
|
|
310
|
+
cmd,
|
|
311
|
+
stdout=subprocess.PIPE,
|
|
312
|
+
stderr=subprocess.PIPE,
|
|
313
|
+
text=True,
|
|
314
|
+
encoding="utf-8", # soffice 中文输出:不显式 UTF-8 则中文 Windows 走 GBK 解码崩
|
|
315
|
+
errors="replace",
|
|
316
|
+
timeout=120,
|
|
317
|
+
check=False,
|
|
318
|
+
)
|
|
319
|
+
except subprocess.TimeoutExpired as e:
|
|
320
|
+
raise RuntimeError("转换 .doc 超时(LibreOffice 120s 未返回)") from e
|
|
321
|
+
if result.returncode != 0:
|
|
322
|
+
detail = (result.stderr or result.stdout or "").strip()
|
|
323
|
+
raise RuntimeError(f"转换 .doc 失败(exit {result.returncode}):{detail}")
|
|
324
|
+
base = os.path.splitext(os.path.basename(path))[0] + ".docx"
|
|
325
|
+
converted = os.path.join(tmp, base)
|
|
326
|
+
if not os.path.isfile(converted):
|
|
327
|
+
matches = [
|
|
328
|
+
os.path.join(tmp, f)
|
|
329
|
+
for f in os.listdir(tmp)
|
|
330
|
+
if f.lower().endswith(".docx")
|
|
331
|
+
]
|
|
332
|
+
if matches:
|
|
333
|
+
converted = matches[0]
|
|
334
|
+
else:
|
|
335
|
+
detail = (result.stdout or result.stderr or "").strip()
|
|
336
|
+
raise RuntimeError(f"转换 .doc 后未找到 docx 产物:{detail}")
|
|
337
|
+
return converted
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
def _extract_doc(path, out_assets, md_lines, images, start_index, verbose):
|
|
341
|
+
converted = _convert_doc_to_docx(path, verbose)
|
|
342
|
+
md_lines.append(f"\n> 老 Word `.doc` 已通过 LibreOffice 转换为 `.docx` 后抽取:{os.path.basename(converted)}\n")
|
|
343
|
+
return _extract_docx(converted, out_assets, md_lines, images, start_index, verbose)
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
# ---------------------------------------------------------------------------
|
|
347
|
+
# pdf:pypdf 可选;缺库优雅跳过 + 提示安装
|
|
348
|
+
# ---------------------------------------------------------------------------
|
|
349
|
+
def _extract_pdf(path, out_assets, md_lines, images, start_index, verbose):
|
|
350
|
+
try:
|
|
351
|
+
from pypdf import PdfReader
|
|
352
|
+
except ImportError:
|
|
353
|
+
print(
|
|
354
|
+
"[extract] 跳过 PDF(未装 pypdf)。如需支持 PDF 素材:pip install pypdf",
|
|
355
|
+
file=sys.stderr,
|
|
356
|
+
)
|
|
357
|
+
return start_index
|
|
358
|
+
|
|
359
|
+
reader = PdfReader(path)
|
|
360
|
+
base = os.path.basename(path)
|
|
361
|
+
idx = start_index
|
|
362
|
+
for pn, page in enumerate(reader.pages, 1):
|
|
363
|
+
try:
|
|
364
|
+
text = (page.extract_text() or "").strip()
|
|
365
|
+
except Exception:
|
|
366
|
+
text = ""
|
|
367
|
+
md_lines.append(f"\n## 第 {pn} 页\n")
|
|
368
|
+
if text:
|
|
369
|
+
md_lines.append(text)
|
|
370
|
+
near = _truncate(text)
|
|
371
|
+
try:
|
|
372
|
+
page_images = list(page.images)
|
|
373
|
+
except Exception:
|
|
374
|
+
page_images = []
|
|
375
|
+
for im in page_images:
|
|
376
|
+
try:
|
|
377
|
+
blob = im.data
|
|
378
|
+
ext = os.path.splitext(im.name or "")[1] or ".png"
|
|
379
|
+
fname, w, h = _save_image(blob, ext, out_assets, idx)
|
|
380
|
+
images.append({
|
|
381
|
+
"file": fname, "w": w, "h": h,
|
|
382
|
+
"aspect_ratio": round(w / h, 4) if w and h else 0,
|
|
383
|
+
"orient": _orient(w, h),
|
|
384
|
+
"section": f"第 {pn} 页", "near_text": near,
|
|
385
|
+
"origin": f"{base}#page{pn}",
|
|
386
|
+
})
|
|
387
|
+
_log(verbose, f"pdf page{pn} 图 {fname} {w}x{h}")
|
|
388
|
+
idx += 1
|
|
389
|
+
except Exception as e:
|
|
390
|
+
_log(verbose, f"pdf page{pn} 跳过一张图:{e}")
|
|
391
|
+
return idx
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
# ---------------------------------------------------------------------------
|
|
395
|
+
# OOXML 内嵌图通用抽取(zip 里的 media 目录)——免第三方库,xlsx 缺 openpyxl 时仍能抽图
|
|
396
|
+
# ---------------------------------------------------------------------------
|
|
397
|
+
def _extract_ooxml_media(path, base, media_prefix, section, out_assets, images, start_index, verbose):
|
|
398
|
+
idx = start_index
|
|
399
|
+
try:
|
|
400
|
+
with zipfile.ZipFile(path) as z:
|
|
401
|
+
names = sorted(
|
|
402
|
+
n for n in z.namelist() if n.startswith(media_prefix) and not n.endswith("/")
|
|
403
|
+
)
|
|
404
|
+
for n in names:
|
|
405
|
+
try:
|
|
406
|
+
blob = z.read(n)
|
|
407
|
+
ext = os.path.splitext(n)[1] or ".png"
|
|
408
|
+
fname, w, h = _save_image(blob, ext, out_assets, idx)
|
|
409
|
+
images.append({
|
|
410
|
+
"file": fname, "w": w, "h": h,
|
|
411
|
+
"aspect_ratio": round(w / h, 4) if w and h else 0,
|
|
412
|
+
"orient": _orient(w, h),
|
|
413
|
+
"section": section, "near_text": "",
|
|
414
|
+
"origin": f"{base}#{os.path.basename(n)}",
|
|
415
|
+
})
|
|
416
|
+
_log(verbose, f"{base} 内嵌图 {fname} {w}x{h} {_orient(w, h)}")
|
|
417
|
+
idx += 1
|
|
418
|
+
except Exception as e:
|
|
419
|
+
_log(verbose, f"{base} 跳过一张内嵌图:{e}")
|
|
420
|
+
except Exception as e:
|
|
421
|
+
_log(verbose, f"{base} 读取内嵌图失败:{e}")
|
|
422
|
+
return idx
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
# ---------------------------------------------------------------------------
|
|
426
|
+
# csv / tsv:pandas → markdown 表(无图)
|
|
427
|
+
# ---------------------------------------------------------------------------
|
|
428
|
+
def _extract_csv(path, out_assets, md_lines, images, start_index, verbose):
|
|
429
|
+
import pandas as pd
|
|
430
|
+
|
|
431
|
+
base = os.path.basename(path)
|
|
432
|
+
sep = "\t" if path.lower().endswith(".tsv") else ","
|
|
433
|
+
df = pd.read_csv(path, sep=sep, dtype=str, keep_default_na=False)
|
|
434
|
+
cap = 50
|
|
435
|
+
md_lines.append(f"\n## 表格:{base}({len(df)} 行 × {len(df.columns)} 列)\n")
|
|
436
|
+
cols = [str(c) for c in df.columns]
|
|
437
|
+
md_lines.append("| " + " | ".join(cols) + " |")
|
|
438
|
+
md_lines.append("| " + " | ".join("---" for _ in cols) + " |")
|
|
439
|
+
for _, row in df.head(cap).iterrows():
|
|
440
|
+
cells = [str(v).replace("|", "\\|").replace("\n", " ") for v in row]
|
|
441
|
+
md_lines.append("| " + " | ".join(cells) + " |")
|
|
442
|
+
if len(df) > cap:
|
|
443
|
+
md_lines.append(f"\n(共 {len(df)} 行,上表仅前 {cap} 行)")
|
|
444
|
+
_log(verbose, f"csv/tsv {base} {len(df)}x{len(df.columns)}")
|
|
445
|
+
return start_index
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
# ---------------------------------------------------------------------------
|
|
449
|
+
# xlsx:openpyxl 抽表文字(缺则跳过文字、仍用 zipfile 抽内嵌图)
|
|
450
|
+
# ---------------------------------------------------------------------------
|
|
451
|
+
def _extract_xlsx(path, out_assets, md_lines, images, start_index, verbose):
|
|
452
|
+
base = os.path.basename(path)
|
|
453
|
+
try:
|
|
454
|
+
from openpyxl import load_workbook
|
|
455
|
+
|
|
456
|
+
wb = load_workbook(path, read_only=True, data_only=True)
|
|
457
|
+
cap = 50
|
|
458
|
+
for ws in wb.worksheets:
|
|
459
|
+
md_lines.append(f"\n## 工作表:{ws.title}\n")
|
|
460
|
+
rows = list(ws.iter_rows(values_only=True))
|
|
461
|
+
header_done = False
|
|
462
|
+
for row in rows[:cap]:
|
|
463
|
+
cells = ["" if v is None else str(v) for v in row]
|
|
464
|
+
if not any(c.strip() for c in cells):
|
|
465
|
+
continue
|
|
466
|
+
safe = [c.replace("|", "\\|").replace("\n", " ") for c in cells]
|
|
467
|
+
md_lines.append("| " + " | ".join(safe) + " |")
|
|
468
|
+
if not header_done:
|
|
469
|
+
md_lines.append("| " + " | ".join("---" for _ in safe) + " |")
|
|
470
|
+
header_done = True
|
|
471
|
+
if len(rows) > cap:
|
|
472
|
+
md_lines.append(f"\n(共 {len(rows)} 行,上表仅前 {cap} 行)")
|
|
473
|
+
wb.close()
|
|
474
|
+
except ImportError:
|
|
475
|
+
print(
|
|
476
|
+
"[extract] xlsx 文字跳过(未装 openpyxl)。如需表格文字:pip install openpyxl",
|
|
477
|
+
file=sys.stderr,
|
|
478
|
+
)
|
|
479
|
+
md_lines.append(f"\n## 表格:{base}(未装 openpyxl,未抽文字;如需 pip install openpyxl)\n")
|
|
480
|
+
except Exception as e:
|
|
481
|
+
_log(verbose, f"xlsx 文字抽取失败:{e}")
|
|
482
|
+
# 内嵌图:xlsx 是 OOXML zip,xl/media/* 即内嵌图(免 openpyxl)
|
|
483
|
+
return _extract_ooxml_media(
|
|
484
|
+
path, base, "xl/media/", "工作簿", out_assets, images, start_index, verbose
|
|
485
|
+
)
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
# ---------------------------------------------------------------------------
|
|
489
|
+
# 独立图片:用户直接给的 png/jpg/…(每张当一个 source 图,section=文件名)
|
|
490
|
+
# ---------------------------------------------------------------------------
|
|
491
|
+
def _extract_image(path, out_assets, md_lines, images, start_index, verbose):
|
|
492
|
+
base = os.path.basename(path)
|
|
493
|
+
section = os.path.splitext(base)[0]
|
|
494
|
+
idx = start_index
|
|
495
|
+
try:
|
|
496
|
+
with open(path, "rb") as f:
|
|
497
|
+
blob = f.read()
|
|
498
|
+
ext = os.path.splitext(path)[1] or ".png"
|
|
499
|
+
fname, w, h = _save_image(blob, ext, out_assets, idx)
|
|
500
|
+
images.append({
|
|
501
|
+
"file": fname, "w": w, "h": h,
|
|
502
|
+
"aspect_ratio": round(w / h, 4) if w and h else 0,
|
|
503
|
+
"orient": _orient(w, h),
|
|
504
|
+
"section": section, "near_text": "",
|
|
505
|
+
"origin": base,
|
|
506
|
+
})
|
|
507
|
+
md_lines.append(f"\n## 图片:{base}\n")
|
|
508
|
+
md_lines.append(f"(用户提供的图片,见 assets/{fname})")
|
|
509
|
+
_log(verbose, f"独立图片 {fname} {w}x{h} {_orient(w, h)}")
|
|
510
|
+
idx += 1
|
|
511
|
+
except Exception as e:
|
|
512
|
+
_log(verbose, f"图片 {base} 抽取失败:{e}")
|
|
513
|
+
return idx
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
_EXTRACTORS = {
|
|
517
|
+
".pptx": _extract_pptx,
|
|
518
|
+
".doc": _extract_doc,
|
|
519
|
+
".docx": _extract_docx,
|
|
520
|
+
".pdf": _extract_pdf,
|
|
521
|
+
".xlsx": _extract_xlsx,
|
|
522
|
+
".csv": _extract_csv,
|
|
523
|
+
".tsv": _extract_csv,
|
|
524
|
+
}
|
|
525
|
+
# 独立图片各扩展名都走 _extract_image
|
|
526
|
+
for _ie in IMAGE_EXTS:
|
|
527
|
+
_EXTRACTORS[_ie] = _extract_image
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
def discover_sources(target: str, scan: bool):
|
|
531
|
+
"""target 是文件 → [它];是目录或 --scan → 目录内所有受支持文档(排序,稳定)。"""
|
|
532
|
+
if os.path.isfile(target):
|
|
533
|
+
return [target] if target.lower().endswith(SUPPORTED_EXTS) else []
|
|
534
|
+
if os.path.isdir(target) or scan:
|
|
535
|
+
d = target if os.path.isdir(target) else "."
|
|
536
|
+
found = [
|
|
537
|
+
os.path.join(d, f)
|
|
538
|
+
for f in sorted(os.listdir(d))
|
|
539
|
+
if f.lower().endswith(SUPPORTED_EXTS) and not f.startswith("~$")
|
|
540
|
+
]
|
|
541
|
+
return found
|
|
542
|
+
return []
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
def extract(target: str, out_dir: str, scan: bool = False, verbose: bool = False):
|
|
546
|
+
"""主流程。返回 manifest dict(同时落盘 source.md / assets/ / source_assets.json)。"""
|
|
547
|
+
out_dir = os.path.abspath(out_dir)
|
|
548
|
+
out_assets = os.path.join(out_dir, "assets")
|
|
549
|
+
os.makedirs(out_assets, exist_ok=True)
|
|
550
|
+
|
|
551
|
+
sources = discover_sources(target, scan)
|
|
552
|
+
md_lines = []
|
|
553
|
+
images = []
|
|
554
|
+
idx = 1
|
|
555
|
+
used_sources = []
|
|
556
|
+
|
|
557
|
+
for src in sources:
|
|
558
|
+
ext = os.path.splitext(src)[1].lower()
|
|
559
|
+
fn = _EXTRACTORS.get(ext)
|
|
560
|
+
if not fn:
|
|
561
|
+
continue
|
|
562
|
+
md_lines.append(f"\n# 来源:{os.path.basename(src)}\n")
|
|
563
|
+
try:
|
|
564
|
+
idx = fn(src, out_assets, md_lines, images, idx, verbose)
|
|
565
|
+
used_sources.append(os.path.basename(src))
|
|
566
|
+
except Exception as e:
|
|
567
|
+
print(f"[extract] 抽取 {src} 失败(跳过该文档):{e}", file=sys.stderr)
|
|
568
|
+
|
|
569
|
+
has_source = bool(used_sources)
|
|
570
|
+
if has_source:
|
|
571
|
+
with open(os.path.join(out_dir, "source.md"), "w", encoding="utf-8") as f:
|
|
572
|
+
f.write("\n".join(md_lines).strip() + "\n")
|
|
573
|
+
|
|
574
|
+
manifest = {
|
|
575
|
+
"has_source": has_source,
|
|
576
|
+
"sources": used_sources,
|
|
577
|
+
"text_file": "source.md" if has_source else None,
|
|
578
|
+
"images": images,
|
|
579
|
+
}
|
|
580
|
+
with open(os.path.join(out_dir, "source_assets.json"), "w", encoding="utf-8") as f:
|
|
581
|
+
json.dump(manifest, f, ensure_ascii=False, indent=2)
|
|
582
|
+
return manifest
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
def main() -> int:
|
|
586
|
+
parser = argparse.ArgumentParser(
|
|
587
|
+
description="从 Word/PPT/Excel/PDF/图片 抽取文字+图片作为 PPT 生成素材(确定性)"
|
|
588
|
+
)
|
|
589
|
+
parser.add_argument("target", help="源素材路径(文档/表格/图片),或含素材的目录")
|
|
590
|
+
parser.add_argument("--out", default="./build", help="输出目录(默认 ./build)")
|
|
591
|
+
parser.add_argument("--scan", action="store_true", help="把 target 当目录扫描所有受支持文档")
|
|
592
|
+
parser.add_argument("-v", "--verbose", action="store_true", help="打印逐张图/逐节进度到 stderr")
|
|
593
|
+
args = parser.parse_args()
|
|
594
|
+
|
|
595
|
+
manifest = extract(args.target, args.out, args.scan, args.verbose)
|
|
596
|
+
if manifest["has_source"]:
|
|
597
|
+
print(
|
|
598
|
+
f"SOURCE_EXTRACTED: {len(manifest['sources'])} 个文档、"
|
|
599
|
+
f"{len(manifest['images'])} 张图片 → {os.path.join(args.out, 'source_assets.json')}"
|
|
600
|
+
)
|
|
601
|
+
else:
|
|
602
|
+
print("NO_SOURCE: 未发现可抽取的素材(Word/PPT/Excel/PDF/图片)(下游按纯 topic 生成)")
|
|
603
|
+
return 0
|
|
604
|
+
|
|
605
|
+
|
|
606
|
+
if __name__ == "__main__":
|
|
607
|
+
sys.exit(main())
|