wezard 2.8.8 → 3.0.1
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/.claude-plugin/plugin.json +0 -6
- package/CLAUDE.md +36 -16
- package/README.md +41 -54
- package/cli/wezard.sh +3 -0
- package/config.example.jsonc +6 -8
- package/dist/cli/codex-hook.js +20 -4
- package/dist/cli/codex-hook.js.map +1 -1
- package/dist/cli/init.js +45 -8
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/skills.js +113 -0
- package/dist/cli/skills.js.map +1 -0
- package/dist/cli/sync.js +32 -112
- package/dist/cli/sync.js.map +1 -1
- package/dist/daemon/apprentice.js +75 -0
- package/dist/daemon/apprentice.js.map +1 -0
- package/dist/daemon/approval.js +78 -20
- package/dist/daemon/approval.js.map +1 -1
- package/dist/daemon/channel-context.js +69 -0
- package/dist/daemon/channel-context.js.map +1 -0
- package/dist/daemon/channel-posts.js +53 -0
- package/dist/daemon/channel-posts.js.map +1 -0
- package/dist/daemon/channel-store.js +96 -0
- package/dist/daemon/channel-store.js.map +1 -0
- package/dist/daemon/channel.js +805 -0
- package/dist/daemon/channel.js.map +1 -0
- package/dist/daemon/chat-name.js +24 -161
- package/dist/daemon/chat-name.js.map +1 -1
- package/dist/daemon/classes.js +418 -0
- package/dist/daemon/classes.js.map +1 -0
- package/dist/daemon/config-api.js +11 -3
- package/dist/daemon/config-api.js.map +1 -1
- package/dist/daemon/danger.js +24 -205
- package/dist/daemon/danger.js.map +1 -1
- package/dist/daemon/detail.js +14 -8
- package/dist/daemon/detail.js.map +1 -1
- package/dist/daemon/handoff.js +266 -50
- package/dist/daemon/handoff.js.map +1 -1
- package/dist/daemon/http.js +25 -18
- package/dist/daemon/http.js.map +1 -1
- package/dist/daemon/idle-reap.js +30 -0
- package/dist/daemon/idle-reap.js.map +1 -0
- package/dist/daemon/inbound.js +366 -143
- package/dist/daemon/inbound.js.map +1 -1
- package/dist/daemon/index.js +2232 -2616
- package/dist/daemon/index.js.map +1 -1
- package/dist/daemon/last-response.js +44 -9
- package/dist/daemon/last-response.js.map +1 -1
- package/dist/daemon/memory-steward.js +1 -1
- package/dist/daemon/memory-steward.js.map +1 -1
- package/dist/daemon/message-format.js +10 -2
- package/dist/daemon/message-format.js.map +1 -1
- package/dist/daemon/mirror-bridge.js +714 -485
- package/dist/daemon/mirror-bridge.js.map +1 -1
- package/dist/daemon/mirror-store.js +24 -0
- package/dist/daemon/mirror-store.js.map +1 -1
- package/dist/daemon/notices.js +2 -2
- package/dist/daemon/notices.js.map +1 -1
- package/dist/daemon/onboarding.js +384 -0
- package/dist/daemon/onboarding.js.map +1 -0
- package/dist/daemon/outbound.js +21 -11
- package/dist/daemon/outbound.js.map +1 -1
- package/dist/daemon/peers.js +38 -230
- package/dist/daemon/peers.js.map +1 -1
- package/dist/daemon/pending.js +7 -5
- package/dist/daemon/pending.js.map +1 -1
- package/dist/daemon/picker-policy.js +27 -12
- package/dist/daemon/picker-policy.js.map +1 -1
- package/dist/daemon/plans.js.map +1 -1
- package/dist/daemon/room-auto-adhoc.js +18 -0
- package/dist/daemon/room-auto-adhoc.js.map +1 -0
- package/dist/daemon/room-facts.js +35 -0
- package/dist/daemon/room-facts.js.map +1 -0
- package/dist/daemon/room-hub.js +430 -0
- package/dist/daemon/room-hub.js.map +1 -0
- package/dist/daemon/room-overdue.js +98 -0
- package/dist/daemon/room-overdue.js.map +1 -0
- package/dist/daemon/room-prune.js +74 -0
- package/dist/daemon/room-prune.js.map +1 -0
- package/dist/daemon/room-spawn.js +20 -0
- package/dist/daemon/room-spawn.js.map +1 -0
- package/dist/daemon/room-watchdog.js +153 -0
- package/dist/daemon/room-watchdog.js.map +1 -0
- package/dist/daemon/rooms.js +107 -0
- package/dist/daemon/rooms.js.map +1 -0
- package/dist/daemon/route.js +7 -18
- package/dist/daemon/route.js.map +1 -1
- package/dist/daemon/spawn-tmux.js +171 -55
- package/dist/daemon/spawn-tmux.js.map +1 -1
- package/dist/daemon/steward-guard.js +2 -2
- package/dist/daemon/steward.js +132 -0
- package/dist/daemon/steward.js.map +1 -0
- package/dist/daemon/tasks.js +4 -14
- package/dist/daemon/tasks.js.map +1 -1
- package/dist/daemon/turn-opening.js +25 -0
- package/dist/daemon/turn-opening.js.map +1 -0
- package/dist/daemon/wake-tail.js +55 -0
- package/dist/daemon/wake-tail.js.map +1 -0
- package/dist/daemon/weixin-cmd.js +10 -14
- package/dist/daemon/weixin-cmd.js.map +1 -1
- package/dist/daemon/wezard-session.js +7 -2
- package/dist/daemon/wezard-session.js.map +1 -1
- package/dist/daemon/wizard-names.js +0 -22
- package/dist/daemon/wizard-names.js.map +1 -1
- package/dist/daemon/wizard.js +589 -145
- package/dist/daemon/wizard.js.map +1 -1
- package/dist/mcp/output.js +6 -5
- package/dist/mcp/output.js.map +1 -1
- package/dist/mcp/tools.js +258 -236
- package/dist/mcp/tools.js.map +1 -1
- package/dist/shared/allow-rules.js +32 -8
- package/dist/shared/allow-rules.js.map +1 -1
- package/dist/shared/charter-rearm.js +179 -0
- package/dist/shared/charter-rearm.js.map +1 -0
- package/dist/shared/chat-http.js +374 -459
- package/dist/shared/chat-http.js.map +1 -1
- package/dist/shared/chat-record.js +55 -0
- package/dist/shared/chat-record.js.map +1 -0
- package/dist/shared/chat-render.js +7 -4
- package/dist/shared/chat-render.js.map +1 -1
- package/dist/shared/chat-view.js +2 -41
- package/dist/shared/chat-view.js.map +1 -1
- package/dist/shared/cli-backends.js +27 -5
- package/dist/shared/cli-backends.js.map +1 -1
- package/dist/shared/config.js +122 -38
- package/dist/shared/config.js.map +1 -1
- package/dist/shared/detail-render.js +104 -21
- package/dist/shared/detail-render.js.map +1 -1
- package/dist/shared/detail-store.js.map +1 -1
- package/dist/shared/group-members.js +35 -0
- package/dist/shared/group-members.js.map +1 -0
- package/dist/shared/inject-view.js +105 -0
- package/dist/shared/inject-view.js.map +1 -0
- package/dist/shared/json-map-store.js +23 -6
- package/dist/shared/json-map-store.js.map +1 -1
- package/dist/shared/legacy-routes.js +199 -0
- package/dist/shared/legacy-routes.js.map +1 -0
- package/dist/shared/mem-guard.js +32 -0
- package/dist/shared/mem-guard.js.map +1 -0
- package/dist/shared/message-footer.js +4 -3
- package/dist/shared/message-footer.js.map +1 -1
- package/dist/shared/pricing.js +5 -0
- package/dist/shared/pricing.js.map +1 -1
- package/dist/shared/reminder.js +30 -38
- package/dist/shared/reminder.js.map +1 -1
- package/dist/shared/repl-script.js +114 -26
- package/dist/shared/repl-script.js.map +1 -1
- package/dist/shared/role-render.js +209 -210
- package/dist/shared/role-render.js.map +1 -1
- package/dist/shared/role-view.js +61 -299
- package/dist/shared/role-view.js.map +1 -1
- package/dist/shared/room-label.js +13 -0
- package/dist/shared/room-label.js.map +1 -0
- package/dist/shared/room-migrate.js +404 -0
- package/dist/shared/room-migrate.js.map +1 -0
- package/dist/shared/room-overdue.js +81 -0
- package/dist/shared/room-overdue.js.map +1 -0
- package/dist/shared/room-search.js +102 -0
- package/dist/shared/room-search.js.map +1 -0
- package/dist/shared/room-view.js +261 -0
- package/dist/shared/room-view.js.map +1 -0
- package/dist/shared/room.js +610 -0
- package/dist/shared/room.js.map +1 -0
- package/dist/shared/session-hooks.js +58 -0
- package/dist/shared/session-hooks.js.map +1 -0
- package/dist/shared/session-label.js +80 -60
- package/dist/shared/session-label.js.map +1 -1
- package/dist/shared/session-mcp.js +77 -0
- package/dist/shared/session-mcp.js.map +1 -0
- package/dist/shared/session-skills.js +63 -0
- package/dist/shared/session-skills.js.map +1 -0
- package/dist/shared/skill-sync.js +229 -0
- package/dist/shared/skill-sync.js.map +1 -0
- package/dist/shared/smarts.js +39 -0
- package/dist/shared/smarts.js.map +1 -0
- package/dist/shared/stream-page.js +22 -0
- package/dist/shared/stream-page.js.map +1 -0
- package/dist/shared/task-file.js +0 -5
- package/dist/shared/task-file.js.map +1 -1
- package/dist/shared/task-template.js +1 -1
- package/dist/shared/task-template.js.map +1 -1
- package/dist/shared/tool-hints.js +76 -17
- package/dist/shared/tool-hints.js.map +1 -1
- package/dist/shared/workspace-trust.js +8 -0
- package/dist/shared/workspace-trust.js.map +1 -1
- package/dist/shared/world.js +101 -166
- package/dist/shared/world.js.map +1 -1
- package/dist/svr/facts-store.js +26 -0
- package/dist/svr/facts-store.js.map +1 -0
- package/dist/svr/index.js +62 -6
- package/dist/svr/index.js.map +1 -1
- package/hooks/pre-tool-use.sh +18 -0
- package/hooks/stop.sh +26 -0
- package/package.json +7 -3
- package/scripts/install.sh +11 -0
- package/skills/LICENSE.wecom-unified.txt +21 -0
- package/skills/wecom-unified/SKILL.md +151 -0
- package/skills/wecom-unified/assets/templates/broadside/DESIGN.preset.md +172 -0
- package/skills/wecom-unified/assets/templates/broadside/shell/content.jsx +31 -0
- package/skills/wecom-unified/assets/templates/broadside/slides/01_cover.slide +48 -0
- package/skills/wecom-unified/assets/templates/broadside/slides/02_section.slide +58 -0
- package/skills/wecom-unified/assets/templates/broadside/slides/03_cards.slide +53 -0
- package/skills/wecom-unified/assets/templates/broadside/slides/04_image.slide +64 -0
- package/skills/wecom-unified/assets/templates/cartesian/DESIGN.preset.md +139 -0
- package/skills/wecom-unified/assets/templates/cartesian/shell/content.jsx +28 -0
- package/skills/wecom-unified/assets/templates/cartesian/slides/01_cover.slide +44 -0
- package/skills/wecom-unified/assets/templates/cartesian/slides/02_compare.slide +79 -0
- package/skills/wecom-unified/assets/templates/cartesian/slides/03_table.slide +79 -0
- package/skills/wecom-unified/assets/templates/cobalt-grid/DESIGN.preset.md +118 -0
- package/skills/wecom-unified/assets/templates/cobalt-grid/shell/content.jsx +24 -0
- package/skills/wecom-unified/assets/templates/cobalt-grid/slides/01_cover.slide +61 -0
- package/skills/wecom-unified/assets/templates/cobalt-grid/slides/02_structure.slide +85 -0
- package/skills/wecom-unified/assets/templates/cobalt-grid/slides/03_data.slide +60 -0
- package/skills/wecom-unified/assets/templates/editorial-forest/DESIGN.preset.md +135 -0
- package/skills/wecom-unified/assets/templates/editorial-forest/shell/content.jsx +19 -0
- package/skills/wecom-unified/assets/templates/editorial-forest/slides/01_cover.slide +29 -0
- package/skills/wecom-unified/assets/templates/editorial-forest/slides/02_cards.slide +60 -0
- package/skills/wecom-unified/assets/templates/editorial-forest/slides/03_data.slide +49 -0
- package/skills/wecom-unified/assets/templates/editorial-forest/slides/04_image.slide +46 -0
- package/skills/wecom-unified/assets/templates/emerald-editorial/DESIGN.preset.md +119 -0
- package/skills/wecom-unified/assets/templates/emerald-editorial/shell/content.jsx +18 -0
- package/skills/wecom-unified/assets/templates/emerald-editorial/slides/01_cover.slide +36 -0
- package/skills/wecom-unified/assets/templates/emerald-editorial/slides/02_section.slide +39 -0
- package/skills/wecom-unified/assets/templates/emerald-editorial/slides/03_data.slide +79 -0
- package/skills/wecom-unified/assets/templates/emerald-editorial/slides/04_steps.slide +53 -0
- package/skills/wecom-unified/assets/templates/grove/DESIGN.preset.md +159 -0
- package/skills/wecom-unified/assets/templates/grove/shell/content.jsx +18 -0
- package/skills/wecom-unified/assets/templates/grove/shell/content_light.jsx +18 -0
- package/skills/wecom-unified/assets/templates/grove/slides/01_cover.slide +26 -0
- package/skills/wecom-unified/assets/templates/grove/slides/02_compare.slide +92 -0
- package/skills/wecom-unified/assets/templates/grove/slides/03_table.slide +68 -0
- package/skills/wecom-unified/assets/templates/index.json +280 -0
- package/skills/wecom-unified/assets/templates/long-table/DESIGN.preset.md +135 -0
- package/skills/wecom-unified/assets/templates/long-table/shell/content.jsx +36 -0
- package/skills/wecom-unified/assets/templates/long-table/slides/01_cover.slide +71 -0
- package/skills/wecom-unified/assets/templates/long-table/slides/02_cards.slide +72 -0
- package/skills/wecom-unified/assets/templates/long-table/slides/03_timeline.slide +81 -0
- package/skills/wecom-unified/assets/templates/long-table/slides/04_image.slide +60 -0
- package/skills/wecom-unified/assets/templates/sakura-chroma/DESIGN.preset.md +121 -0
- package/skills/wecom-unified/assets/templates/sakura-chroma/shell/content.jsx +13 -0
- package/skills/wecom-unified/assets/templates/sakura-chroma/slides/01_cover.slide +54 -0
- package/skills/wecom-unified/assets/templates/sakura-chroma/slides/02_products.slide +134 -0
- package/skills/wecom-unified/assets/templates/sakura-chroma/slides/03_section.slide +30 -0
- package/skills/wecom-unified/assets/templates/sakura-chroma/slides/04_schedule.slide +65 -0
- package/skills/wecom-unified/assets/templates/signal/DESIGN.preset.md +121 -0
- package/skills/wecom-unified/assets/templates/signal/shell/content.jsx +18 -0
- package/skills/wecom-unified/assets/templates/signal/shell/content_dark.jsx +23 -0
- package/skills/wecom-unified/assets/templates/signal/slides/01_cover.slide +48 -0
- package/skills/wecom-unified/assets/templates/signal/slides/02_cards.slide +67 -0
- package/skills/wecom-unified/assets/templates/signal/slides/03_data.slide +68 -0
- package/skills/wecom-unified/references/wecomcli-calendar-agenda.md +227 -0
- package/skills/wecom-unified/references/wecomcli-calendar-cancel.md +108 -0
- package/skills/wecom-unified/references/wecomcli-calendar-create.md +238 -0
- package/skills/wecom-unified/references/wecomcli-calendar-freebusy.md +207 -0
- package/skills/wecom-unified/references/wecomcli-calendar-meeting-room.md +170 -0
- package/skills/wecom-unified/references/wecomcli-calendar-search.md +209 -0
- package/skills/wecom-unified/references/wecomcli-calendar-update.md +272 -0
- package/skills/wecom-unified/references/wecomcli-calendar.md +296 -0
- package/skills/wecom-unified/references/wecomcli-contact.md +48 -0
- package/skills/wecom-unified/references/wecomcli-disk.md +380 -0
- package/skills/wecom-unified/references/wecomcli-doc-contents-append.md +20 -0
- package/skills/wecom-unified/references/wecomcli-doc-contents-overwrite.md +27 -0
- package/skills/wecom-unified/references/wecomcli-doc-create.md +162 -0
- package/skills/wecom-unified/references/wecomcli-doc-manage-doc-members-update.md +24 -0
- package/skills/wecom-unified/references/wecomcli-doc-manage-doc-names-update.md +20 -0
- package/skills/wecom-unified/references/wecomcli-doc-manage-doc-rules-update.md +22 -0
- package/skills/wecom-unified/references/wecomcli-doc-manage.md +127 -0
- package/skills/wecom-unified/references/wecomcli-doc.md +135 -0
- package/skills/wecom-unified/references/wecomcli-email-forward-mail.md +131 -0
- package/skills/wecom-unified/references/wecomcli-email-get-mail.md +187 -0
- package/skills/wecom-unified/references/wecomcli-email-reply-mail.md +138 -0
- package/skills/wecom-unified/references/wecomcli-email-search-mail.md +114 -0
- package/skills/wecom-unified/references/wecomcli-email-security.md +52 -0
- package/skills/wecom-unified/references/wecomcli-email-send-mail.md +186 -0
- package/skills/wecom-unified/references/wecomcli-email-send-schedule.md +83 -0
- package/skills/wecom-unified/references/wecomcli-email.md +206 -0
- package/skills/wecom-unified/references/wecomcli-media.md +89 -0
- package/skills/wecom-unified/references/wecomcli-meeting-cancel.md +113 -0
- package/skills/wecom-unified/references/wecomcli-meeting-create.md +167 -0
- package/skills/wecom-unified/references/wecomcli-meeting-list.md +228 -0
- package/skills/wecom-unified/references/wecomcli-meeting-original-get.md +101 -0
- package/skills/wecom-unified/references/wecomcli-meeting-search.md +176 -0
- package/skills/wecom-unified/references/wecomcli-meeting-update.md +217 -0
- package/skills/wecom-unified/references/wecomcli-meeting.md +366 -0
- package/skills/wecom-unified/references/wecomcli-message.md +190 -0
- package/skills/wecom-unified/references/wecomcli-pptx-component-animation.md +62 -0
- package/skills/wecom-unified/references/wecomcli-pptx-component-box.md +102 -0
- package/skills/wecom-unified/references/wecomcli-pptx-component-chart.md +261 -0
- package/skills/wecom-unified/references/wecomcli-pptx-component-codeblock.md +70 -0
- package/skills/wecom-unified/references/wecomcli-pptx-component-diagram.md +54 -0
- package/skills/wecom-unified/references/wecomcli-pptx-component-faicon.md +71 -0
- package/skills/wecom-unified/references/wecomcli-pptx-component-hyperlink.md +55 -0
- package/skills/wecom-unified/references/wecomcli-pptx-component-image.md +107 -0
- package/skills/wecom-unified/references/wecomcli-pptx-component-math.md +65 -0
- package/skills/wecom-unified/references/wecomcli-pptx-component-qrcode.md +22 -0
- package/skills/wecom-unified/references/wecomcli-pptx-component-slide.md +74 -0
- package/skills/wecom-unified/references/wecomcli-pptx-component-svg.md +95 -0
- package/skills/wecom-unified/references/wecomcli-pptx-component-table.md +72 -0
- package/skills/wecom-unified/references/wecomcli-pptx-component-text.md +96 -0
- package/skills/wecom-unified/references/wecomcli-pptx-content-contract.md +73 -0
- package/skills/wecom-unified/references/wecomcli-pptx-create-from-material.md +67 -0
- package/skills/wecom-unified/references/wecomcli-pptx-create-from-scratch.md +178 -0
- package/skills/wecom-unified/references/wecomcli-pptx-create-from-template.md +123 -0
- package/skills/wecom-unified/references/wecomcli-pptx-design-principle.md +65 -0
- package/skills/wecom-unified/references/wecomcli-pptx-government-contract.md +40 -0
- package/skills/wecom-unified/references/wecomcli-pptx-human-alignment.md +140 -0
- package/skills/wecom-unified/references/wecomcli-pptx-pptx-api.md +161 -0
- package/skills/wecom-unified/references/wecomcli-pptx-pptx-edit.md +37 -0
- package/skills/wecom-unified/references/wecomcli-pptx-story-principle.md +184 -0
- package/skills/wecom-unified/references/wecomcli-pptx-templates-README.md +165 -0
- package/skills/wecom-unified/references/wecomcli-pptx-templates-anti-ai-slop.md +52 -0
- package/skills/wecom-unified/references/wecomcli-pptx.md +158 -0
- package/skills/wecom-unified/references/wecomcli-sheet-conditional-formatting.md +203 -0
- package/skills/wecom-unified/references/wecomcli-sheet-filter.md +179 -0
- package/skills/wecom-unified/references/wecomcli-sheet-float-image.md +235 -0
- package/skills/wecom-unified/references/wecomcli-sheet-formulas.md +71 -0
- package/skills/wecom-unified/references/wecomcli-sheet-history.md +118 -0
- package/skills/wecom-unified/references/wecomcli-sheet-protection.md +170 -0
- package/skills/wecom-unified/references/wecomcli-sheet-range-operations.md +306 -0
- package/skills/wecom-unified/references/wecomcli-sheet-read-data.md +151 -0
- package/skills/wecom-unified/references/wecomcli-sheet-search-replace.md +121 -0
- package/skills/wecom-unified/references/wecomcli-sheet-structure-operations.md +394 -0
- package/skills/wecom-unified/references/wecomcli-sheet-style.md +246 -0
- package/skills/wecom-unified/references/wecomcli-sheet-table-style.md +199 -0
- package/skills/wecom-unified/references/wecomcli-sheet-validation.md +217 -0
- package/skills/wecom-unified/references/wecomcli-sheet-visual-standards.md +166 -0
- package/skills/wecom-unified/references/wecomcli-sheet-workbook.md +264 -0
- package/skills/wecom-unified/references/wecomcli-sheet-write-cells.md +320 -0
- package/skills/wecom-unified/references/wecomcli-sheet-xlsx-process.md +324 -0
- package/skills/wecom-unified/references/wecomcli-sheet.md +96 -0
- package/skills/wecom-unified/references/wecomcli-smartpage-data-driven-pages.md +50 -0
- package/skills/wecom-unified/references/wecomcli-smartpage-edit.md +526 -0
- package/skills/wecom-unified/references/wecomcli-smartpage-formula-arraylist.md +369 -0
- package/skills/wecom-unified/references/wecomcli-smartpage-formula-datetime.md +283 -0
- package/skills/wecom-unified/references/wecomcli-smartpage-formula-logic.md +247 -0
- package/skills/wecom-unified/references/wecomcli-smartpage-formula-math.md +362 -0
- package/skills/wecom-unified/references/wecomcli-smartpage-formula-operators.md +246 -0
- package/skills/wecom-unified/references/wecomcli-smartpage-formula-pageblock.md +76 -0
- package/skills/wecom-unified/references/wecomcli-smartpage-formula-reference.md +192 -0
- package/skills/wecom-unified/references/wecomcli-smartpage-formula-templates.md +410 -0
- package/skills/wecom-unified/references/wecomcli-smartpage-formula-text.md +377 -0
- package/skills/wecom-unified/references/wecomcli-smartpage-formula-user.md +22 -0
- package/skills/wecom-unified/references/wecomcli-smartpage-mdx-syntax.md +739 -0
- package/skills/wecom-unified/references/wecomcli-smartpage.md +179 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-chart-types.md +95 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-common.md +160 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-edit.md +609 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-field-types.md +438 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-formula.md +845 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-read.md +411 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-record-values.md +218 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-ai_efficiency.md +709 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-connect_to_app.md +380 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-financial_accounting.md +369 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-hr_and_administration.md +475 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-ledger_records.md +156 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-manufacturing.md +395 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-marketing.md +186 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-office_essentials.md +299 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-personal_efficiency.md +70 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-procurement_logistics.md +325 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-project_management.md +564 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-rd_process_customer.md +222 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-rd_process_ops.md +105 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-rd_process_project.md +109 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-rd_process_research.md +92 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-sales_and_operations.md +446 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-store_management.md +431 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-team_tasks.md +274 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-wechat_customer.md +384 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-template-work_report.md +100 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-templates.md +53 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-view-types.md +373 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-webhook-examples.md +176 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet-webhook.md +186 -0
- package/skills/wecom-unified/references/wecomcli-smartsheet.md +147 -0
- package/skills/wecom-unified/references/wecomcli-todo-create.md +137 -0
- package/skills/wecom-unified/references/wecomcli-todo-delete.md +63 -0
- package/skills/wecom-unified/references/wecomcli-todo-finish.md +72 -0
- package/skills/wecom-unified/references/wecomcli-todo-get.md +69 -0
- package/skills/wecom-unified/references/wecomcli-todo-list.md +136 -0
- package/skills/wecom-unified/references/wecomcli-todo-update.md +112 -0
- package/skills/wecom-unified/references/wecomcli-todo.md +68 -0
- package/skills/wecom-unified/scripts/build_docx.py +1274 -0
- package/skills/wecom-unified/scripts/build_page.py +2449 -0
- package/skills/wecom-unified/scripts/collect.py +868 -0
- package/skills/wecom-unified/scripts/doc_image_extractor.py +498 -0
- package/skills/wecom-unified/scripts/pptx2image.py +268 -0
- package/skills/wecom-unified/scripts/recalc.py +403 -0
- package/systemd/wezard.service.template +6 -0
- package/web/chat.css +70 -273
- package/web/chat.js +2228 -2190
- package/dist/daemon/chat-log.js +0 -130
- package/dist/daemon/chat-log.js.map +0 -1
- package/dist/daemon/dispatch.js +0 -6
- package/dist/daemon/dispatch.js.map +0 -1
- package/dist/daemon/idle-nudge.js +0 -69
- package/dist/daemon/idle-nudge.js.map +0 -1
- package/dist/daemon/message-events.js +0 -1083
- package/dist/daemon/message-events.js.map +0 -1
- package/dist/daemon/pending-items.js +0 -160
- package/dist/daemon/pending-items.js.map +0 -1
- package/dist/daemon/router.js +0 -742
- package/dist/daemon/router.js.map +0 -1
- package/dist/daemon/tips.js +0 -25
- package/dist/daemon/tips.js.map +0 -1
- package/dist/daemon/wedoc.js +0 -210
- package/dist/daemon/wedoc.js.map +0 -1
- package/dist/shared/role-search.js +0 -100
- package/dist/shared/role-search.js.map +0 -1
- package/dist/shared/startup-notice.js +0 -21
- package/dist/shared/startup-notice.js.map +0 -1
- package/dist/shared/turn-state.js +0 -27
- package/dist/shared/turn-state.js.map +0 -1
- package/hooks/hooks.json +0 -16
|
@@ -0,0 +1,498 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
doc_image_extractor.py
|
|
4
|
+
|
|
5
|
+
从多种文档格式中提取内嵌图片。
|
|
6
|
+
支持格式:PPTX、DOCX、XLSX
|
|
7
|
+
|
|
8
|
+
依赖(直接用,不做存在性检测、不运行 pip install):
|
|
9
|
+
python-pptx / python-docx / openpyxl(按处理的格式按需导入)
|
|
10
|
+
|
|
11
|
+
用法:
|
|
12
|
+
# 单个文件
|
|
13
|
+
python doc_image_extractor.py <文档路径> [输出目录]
|
|
14
|
+
|
|
15
|
+
# 多个文件
|
|
16
|
+
python doc_image_extractor.py file1.pptx file2.docx file3.xlsx [输出目录]
|
|
17
|
+
|
|
18
|
+
# 批量扫描目录
|
|
19
|
+
python doc_image_extractor.py --dir <目录路径> [输出目录]
|
|
20
|
+
python doc_image_extractor.py -d <目录路径> [输出目录]
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
import sys
|
|
24
|
+
import os
|
|
25
|
+
import argparse
|
|
26
|
+
from pathlib import Path
|
|
27
|
+
from typing import Optional, List, Dict, Tuple
|
|
28
|
+
import struct
|
|
29
|
+
|
|
30
|
+
MIN_IMAGE_SIZE = 10 * 1024
|
|
31
|
+
MIN_IMAGE_WIDTH = 320
|
|
32
|
+
MIN_IMAGE_HEIGHT = 180
|
|
33
|
+
MIN_IMAGE_AREA = 80_000
|
|
34
|
+
MIN_IMAGE_LONG_EDGE = 480
|
|
35
|
+
MIN_IMAGE_SHORT_EDGE = 64
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def get_image_dimensions(image_bytes: bytes) -> Tuple[Optional[int], Optional[int]]:
|
|
39
|
+
"""从常见图片二进制中读取像素宽高;读取失败时返回 (None, None)。"""
|
|
40
|
+
if len(image_bytes) < 24:
|
|
41
|
+
return None, None
|
|
42
|
+
|
|
43
|
+
try:
|
|
44
|
+
# PNG: signature + IHDR width/height
|
|
45
|
+
if image_bytes.startswith(b"\x89PNG\r\n\x1a\n"):
|
|
46
|
+
width, height = struct.unpack(">II", image_bytes[16:24])
|
|
47
|
+
return width, height
|
|
48
|
+
|
|
49
|
+
# JPEG: scan SOF markers
|
|
50
|
+
if image_bytes.startswith(b"\xff\xd8"):
|
|
51
|
+
idx = 2
|
|
52
|
+
sof_markers = {
|
|
53
|
+
0xC0, 0xC1, 0xC2, 0xC3,
|
|
54
|
+
0xC5, 0xC6, 0xC7,
|
|
55
|
+
0xC9, 0xCA, 0xCB,
|
|
56
|
+
0xCD, 0xCE, 0xCF,
|
|
57
|
+
}
|
|
58
|
+
while idx < len(image_bytes) - 1:
|
|
59
|
+
while idx < len(image_bytes) and image_bytes[idx] == 0xFF:
|
|
60
|
+
idx += 1
|
|
61
|
+
if idx >= len(image_bytes):
|
|
62
|
+
break
|
|
63
|
+
|
|
64
|
+
marker = image_bytes[idx]
|
|
65
|
+
idx += 1
|
|
66
|
+
|
|
67
|
+
# standalone markers without segment length
|
|
68
|
+
if marker in (0x01, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9):
|
|
69
|
+
continue
|
|
70
|
+
|
|
71
|
+
if idx + 2 > len(image_bytes):
|
|
72
|
+
break
|
|
73
|
+
segment_length = struct.unpack(">H", image_bytes[idx:idx + 2])[0]
|
|
74
|
+
if segment_length < 2 or idx + segment_length > len(image_bytes):
|
|
75
|
+
break
|
|
76
|
+
|
|
77
|
+
if marker in sof_markers and segment_length >= 7:
|
|
78
|
+
height, width = struct.unpack(">HH", image_bytes[idx + 3:idx + 7])
|
|
79
|
+
return width, height
|
|
80
|
+
|
|
81
|
+
idx += segment_length
|
|
82
|
+
|
|
83
|
+
# GIF87a / GIF89a
|
|
84
|
+
if image_bytes[:6] in (b"GIF87a", b"GIF89a"):
|
|
85
|
+
width, height = struct.unpack("<HH", image_bytes[6:10])
|
|
86
|
+
return width, height
|
|
87
|
+
|
|
88
|
+
# BMP
|
|
89
|
+
if image_bytes.startswith(b"BM") and len(image_bytes) >= 26:
|
|
90
|
+
width, height = struct.unpack("<ii", image_bytes[18:26])
|
|
91
|
+
return abs(width), abs(height)
|
|
92
|
+
except Exception:
|
|
93
|
+
pass
|
|
94
|
+
|
|
95
|
+
return None, None
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def should_extract_image(
|
|
99
|
+
image_bytes: bytes,
|
|
100
|
+
width: Optional[int] = None,
|
|
101
|
+
height: Optional[int] = None,
|
|
102
|
+
) -> bool:
|
|
103
|
+
"""
|
|
104
|
+
综合文件体积与像素宽高判断是否提取图片。
|
|
105
|
+
|
|
106
|
+
规则意图:
|
|
107
|
+
- 压缩率高但尺寸足够大的图片要保留;
|
|
108
|
+
- 图标、装饰小图、头像等小尺寸图片要过滤;
|
|
109
|
+
- 读取不到宽高时,退回到原来的体积阈值。
|
|
110
|
+
"""
|
|
111
|
+
byte_size = len(image_bytes)
|
|
112
|
+
|
|
113
|
+
if width is None or height is None:
|
|
114
|
+
width, height = get_image_dimensions(image_bytes)
|
|
115
|
+
|
|
116
|
+
if width is None or height is None:
|
|
117
|
+
return byte_size >= MIN_IMAGE_SIZE
|
|
118
|
+
|
|
119
|
+
if width <= 0 or height <= 0:
|
|
120
|
+
return byte_size >= MIN_IMAGE_SIZE
|
|
121
|
+
|
|
122
|
+
short_edge = min(width, height)
|
|
123
|
+
long_edge = max(width, height)
|
|
124
|
+
area = width * height
|
|
125
|
+
|
|
126
|
+
# 极小尺寸通常是图标、Logo 或装饰元素,即使文件体积偏大也跳过。
|
|
127
|
+
if short_edge < MIN_IMAGE_SHORT_EDGE:
|
|
128
|
+
return False
|
|
129
|
+
|
|
130
|
+
# 体积足够且长边不太小:保留。
|
|
131
|
+
if byte_size >= MIN_IMAGE_SIZE and long_edge >= MIN_IMAGE_LONG_EDGE:
|
|
132
|
+
return True
|
|
133
|
+
|
|
134
|
+
# 体积小但像素尺寸有效:保留压缩率较高的截图、图表、照片。
|
|
135
|
+
return (
|
|
136
|
+
width >= MIN_IMAGE_WIDTH and height >= MIN_IMAGE_HEIGHT
|
|
137
|
+
) or (
|
|
138
|
+
area >= MIN_IMAGE_AREA and long_edge >= MIN_IMAGE_LONG_EDGE
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
# -------------------- 依赖检查 --------------------
|
|
142
|
+
|
|
143
|
+
def _safe_name(name: str) -> str:
|
|
144
|
+
"""清理文件名中的非法字符,只保留字母数字与 . _ -
|
|
145
|
+
|
|
146
|
+
扩展名来自文档内的 content_type / img.format,属外部可控输入,
|
|
147
|
+
可能含 / .. 等字符导致写出目录外;三个提取分支统一经此函数处理。
|
|
148
|
+
"""
|
|
149
|
+
cleaned = "".join(c if c.isalnum() or c in "._-" else "_" for c in name)
|
|
150
|
+
cleaned = cleaned.lstrip(".") or "image"
|
|
151
|
+
return cleaned[:120]
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def _require(package_name: str, feature: str):
|
|
155
|
+
"""尝试导入包,失败时报"缺依赖不可用"并退出(不自动安装)。"""
|
|
156
|
+
try:
|
|
157
|
+
__import__(package_name)
|
|
158
|
+
except ImportError:
|
|
159
|
+
print(f"❌ 缺少依赖: {package_name}({feature} 不可用)")
|
|
160
|
+
sys.exit(1)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
# -------------------- PPTX 图片提取 --------------------
|
|
164
|
+
|
|
165
|
+
def extract_images_from_pptx(filepath: str, output_dir: str) -> int:
|
|
166
|
+
"""使用 python-pptx 从 PPTX 中提取图片。"""
|
|
167
|
+
_require("pptx", "pptx 解析")
|
|
168
|
+
from pptx import Presentation
|
|
169
|
+
|
|
170
|
+
prs = Presentation(filepath)
|
|
171
|
+
image_count = 0
|
|
172
|
+
|
|
173
|
+
for slide_num, slide in enumerate(prs.slides, start=1):
|
|
174
|
+
for shape in slide.shapes:
|
|
175
|
+
if hasattr(shape, "image") and shape.image:
|
|
176
|
+
try:
|
|
177
|
+
image = shape.image
|
|
178
|
+
image_bytes = image.blob
|
|
179
|
+
width, height = getattr(image, "size", (None, None))
|
|
180
|
+
# 综合体积与像素宽高过滤小图/装饰图
|
|
181
|
+
if not should_extract_image(image_bytes, width, height):
|
|
182
|
+
continue
|
|
183
|
+
|
|
184
|
+
# 确定扩展名
|
|
185
|
+
content_type = image.content_type
|
|
186
|
+
ext = content_type.split("/")[-1] if "/" in content_type else "png"
|
|
187
|
+
if ext == "jpeg":
|
|
188
|
+
ext = "jpg"
|
|
189
|
+
|
|
190
|
+
image_count += 1
|
|
191
|
+
image_filename = _safe_name(f"pptx_s{slide_num}_img{image_count}.{ext}")
|
|
192
|
+
image_path = os.path.join(output_dir, image_filename)
|
|
193
|
+
with open(image_path, "wb") as f:
|
|
194
|
+
f.write(image_bytes)
|
|
195
|
+
except Exception:
|
|
196
|
+
continue
|
|
197
|
+
|
|
198
|
+
return image_count
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
# -------------------- DOCX 图片提取 --------------------
|
|
202
|
+
|
|
203
|
+
def extract_images_from_docx(filepath: str, output_dir: str) -> int:
|
|
204
|
+
"""使用 python-docx 从 DOCX 中提取图片。"""
|
|
205
|
+
_require("docx", "docx 解析")
|
|
206
|
+
from docx import Document
|
|
207
|
+
|
|
208
|
+
doc = Document(filepath)
|
|
209
|
+
image_count = 0
|
|
210
|
+
|
|
211
|
+
for rel in doc.part.rels.values():
|
|
212
|
+
if "image" in rel.reltype:
|
|
213
|
+
try:
|
|
214
|
+
image = rel.target_part
|
|
215
|
+
image_bytes = image.blob
|
|
216
|
+
# 综合体积与像素宽高过滤小图/装饰图
|
|
217
|
+
if not should_extract_image(image_bytes):
|
|
218
|
+
continue
|
|
219
|
+
|
|
220
|
+
# 确定扩展名
|
|
221
|
+
content_type = image.content_type if hasattr(image, "content_type") else "image/png"
|
|
222
|
+
ext = content_type.split("/")[-1] if "/" in content_type else "png"
|
|
223
|
+
if ext == "jpeg":
|
|
224
|
+
ext = "jpg"
|
|
225
|
+
|
|
226
|
+
image_count += 1
|
|
227
|
+
image_filename = _safe_name(f"docx_img{image_count}.{ext}")
|
|
228
|
+
image_path = os.path.join(output_dir, image_filename)
|
|
229
|
+
with open(image_path, "wb") as f:
|
|
230
|
+
f.write(image_bytes)
|
|
231
|
+
except Exception:
|
|
232
|
+
continue
|
|
233
|
+
|
|
234
|
+
return image_count
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
# -------------------- XLSX 图片提取 --------------------
|
|
238
|
+
|
|
239
|
+
def extract_images_from_xlsx(filepath: str, output_dir: str) -> int:
|
|
240
|
+
"""使用 openpyxl 从 XLSX 中提取图片。"""
|
|
241
|
+
_require("openpyxl", "xlsx 解析")
|
|
242
|
+
from openpyxl import load_workbook
|
|
243
|
+
|
|
244
|
+
wb = load_workbook(filepath)
|
|
245
|
+
image_count = 0
|
|
246
|
+
|
|
247
|
+
for sheet_name in wb.sheetnames:
|
|
248
|
+
sheet = wb[sheet_name]
|
|
249
|
+
if hasattr(sheet, "_images"):
|
|
250
|
+
for img in sheet._images:
|
|
251
|
+
try:
|
|
252
|
+
image_bytes = img._data()
|
|
253
|
+
width = getattr(img, "width", None)
|
|
254
|
+
height = getattr(img, "height", None)
|
|
255
|
+
if not should_extract_image(image_bytes, width, height):
|
|
256
|
+
continue
|
|
257
|
+
|
|
258
|
+
# 确定扩展名
|
|
259
|
+
ext = img.format.lower() if img.format else "png"
|
|
260
|
+
if ext == "jpeg":
|
|
261
|
+
ext = "jpg"
|
|
262
|
+
|
|
263
|
+
image_count += 1
|
|
264
|
+
image_filename = _safe_name(f"xlsx_{sheet_name}_img{image_count}.{ext}")
|
|
265
|
+
image_path = os.path.join(output_dir, image_filename)
|
|
266
|
+
with open(image_path, "wb") as f:
|
|
267
|
+
f.write(image_bytes)
|
|
268
|
+
except Exception:
|
|
269
|
+
continue
|
|
270
|
+
|
|
271
|
+
return image_count
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
# -------------------- 核心数据 --------------------
|
|
275
|
+
|
|
276
|
+
SUPPORTED_FORMATS = {
|
|
277
|
+
".pptx": extract_images_from_pptx,
|
|
278
|
+
".docx": extract_images_from_docx,
|
|
279
|
+
".xlsx": extract_images_from_xlsx,
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
def scan_directory(directory: str) -> List[str]:
|
|
284
|
+
"""扫描目录中所有支持的文档文件(不包含子目录)。"""
|
|
285
|
+
files = []
|
|
286
|
+
for entry in os.listdir(directory):
|
|
287
|
+
path = os.path.join(directory, entry)
|
|
288
|
+
if os.path.isfile(path) and Path(path).suffix.lower() in SUPPORTED_FORMATS:
|
|
289
|
+
files.append(path)
|
|
290
|
+
return files
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def extract_images_from_file(filepath: str, output_dir: str) -> int:
|
|
294
|
+
"""从单个文件中提取图片。"""
|
|
295
|
+
filepath = os.path.abspath(filepath)
|
|
296
|
+
if not os.path.exists(filepath):
|
|
297
|
+
raise FileNotFoundError(f"文件不存在: {filepath}")
|
|
298
|
+
|
|
299
|
+
ext = Path(filepath).suffix.lower()
|
|
300
|
+
if ext not in SUPPORTED_FORMATS:
|
|
301
|
+
raise ValueError(
|
|
302
|
+
f"不支持的文件格式: {ext}\n"
|
|
303
|
+
f"支持的格式: {', '.join(SUPPORTED_FORMATS.keys())}"
|
|
304
|
+
)
|
|
305
|
+
|
|
306
|
+
os.makedirs(output_dir, exist_ok=True)
|
|
307
|
+
extractor = SUPPORTED_FORMATS[ext]
|
|
308
|
+
return extractor(filepath, output_dir)
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
def extract_images(
|
|
312
|
+
inputs: List[str],
|
|
313
|
+
output_dir: str,
|
|
314
|
+
flat: bool = False
|
|
315
|
+
) -> Dict[str, int]:
|
|
316
|
+
"""
|
|
317
|
+
批量提取图片。
|
|
318
|
+
|
|
319
|
+
参数:
|
|
320
|
+
inputs: 文件路径或目录路径列表
|
|
321
|
+
output_dir: 根输出目录
|
|
322
|
+
flat: 为 True 时所有图片输出到同一目录;为 False 时按文件名分子目录
|
|
323
|
+
|
|
324
|
+
返回:
|
|
325
|
+
{文件路径: 提取图片数量}
|
|
326
|
+
"""
|
|
327
|
+
results = {}
|
|
328
|
+
|
|
329
|
+
# 收集所有文件
|
|
330
|
+
all_files = []
|
|
331
|
+
for item in inputs:
|
|
332
|
+
item = os.path.abspath(item)
|
|
333
|
+
if os.path.isdir(item):
|
|
334
|
+
files = scan_directory(item)
|
|
335
|
+
all_files.extend(files)
|
|
336
|
+
if not files:
|
|
337
|
+
print(f"⚠️ 目录中未找到支持的文档: {item}")
|
|
338
|
+
elif os.path.isfile(item):
|
|
339
|
+
all_files.append(item)
|
|
340
|
+
else:
|
|
341
|
+
print(f"⚠️ 路径不存在或不是文件/目录: {item}")
|
|
342
|
+
|
|
343
|
+
if not all_files:
|
|
344
|
+
print("⚠️ 没有找到可处理的文件")
|
|
345
|
+
return results
|
|
346
|
+
|
|
347
|
+
# 去重并保持顺序
|
|
348
|
+
seen = set()
|
|
349
|
+
unique_files = [f for f in all_files if not (f in seen or seen.add(f))]
|
|
350
|
+
|
|
351
|
+
total_files = len(unique_files)
|
|
352
|
+
print(f"📦 共发现 {total_files} 个待处理文件")
|
|
353
|
+
print("=" * 50)
|
|
354
|
+
|
|
355
|
+
# 如果输出目录不存在,提示正在创建
|
|
356
|
+
output_dir = os.path.abspath(output_dir)
|
|
357
|
+
if not os.path.exists(output_dir):
|
|
358
|
+
print(f"📁 输出目录不存在,正在创建: {output_dir}")
|
|
359
|
+
os.makedirs(output_dir, exist_ok=True)
|
|
360
|
+
total_images = 0
|
|
361
|
+
|
|
362
|
+
for idx, filepath in enumerate(unique_files, start=1):
|
|
363
|
+
basename = Path(filepath).stem
|
|
364
|
+
ext = Path(filepath).suffix.lower()
|
|
365
|
+
|
|
366
|
+
if flat:
|
|
367
|
+
# 所有图片放一起,文件名加前缀区分
|
|
368
|
+
file_output_dir = output_dir
|
|
369
|
+
prefix = f"{basename}_"
|
|
370
|
+
else:
|
|
371
|
+
# 每个文件一个子目录
|
|
372
|
+
file_output_dir = os.path.join(output_dir, basename)
|
|
373
|
+
prefix = ""
|
|
374
|
+
|
|
375
|
+
print(f"\n[{idx}/{total_files}] 📄 {filepath}")
|
|
376
|
+
print(f" 输出到: {file_output_dir}")
|
|
377
|
+
|
|
378
|
+
try:
|
|
379
|
+
# 创建临时子目录(flat 模式下不需要)
|
|
380
|
+
if not flat:
|
|
381
|
+
os.makedirs(file_output_dir, exist_ok=True)
|
|
382
|
+
|
|
383
|
+
# 提取到临时目录,再重命名(flat 模式下需要加前缀)
|
|
384
|
+
import tempfile
|
|
385
|
+
tmp_dir = tempfile.mkdtemp()
|
|
386
|
+
count = extract_images_from_file(filepath, tmp_dir)
|
|
387
|
+
|
|
388
|
+
if flat and count > 0:
|
|
389
|
+
# flat 模式:把文件移到根目录并加前缀
|
|
390
|
+
for fname in os.listdir(tmp_dir):
|
|
391
|
+
src = os.path.join(tmp_dir, fname)
|
|
392
|
+
dst = os.path.join(file_output_dir, f"{prefix}{fname}")
|
|
393
|
+
# 处理重名
|
|
394
|
+
counter = 1
|
|
395
|
+
orig_dst = dst
|
|
396
|
+
while os.path.exists(dst):
|
|
397
|
+
stem = Path(orig_dst).stem
|
|
398
|
+
suffix = Path(orig_dst).suffix
|
|
399
|
+
dst = os.path.join(file_output_dir, f"{stem}_{counter}{suffix}")
|
|
400
|
+
counter += 1
|
|
401
|
+
os.rename(src, dst)
|
|
402
|
+
os.rmdir(tmp_dir)
|
|
403
|
+
elif count > 0:
|
|
404
|
+
# 子目录模式:直接移过去
|
|
405
|
+
for fname in os.listdir(tmp_dir):
|
|
406
|
+
src = os.path.join(tmp_dir, fname)
|
|
407
|
+
dst = os.path.join(file_output_dir, fname)
|
|
408
|
+
counter = 1
|
|
409
|
+
orig_dst = dst
|
|
410
|
+
while os.path.exists(dst):
|
|
411
|
+
stem = Path(orig_dst).stem
|
|
412
|
+
suffix = Path(orig_dst).suffix
|
|
413
|
+
dst = os.path.join(file_output_dir, f"{stem}_{counter}{suffix}")
|
|
414
|
+
counter += 1
|
|
415
|
+
os.rename(src, dst)
|
|
416
|
+
os.rmdir(tmp_dir)
|
|
417
|
+
else:
|
|
418
|
+
# 没提取到图片,清理临时目录
|
|
419
|
+
import shutil
|
|
420
|
+
shutil.rmtree(tmp_dir, ignore_errors=True)
|
|
421
|
+
if not flat:
|
|
422
|
+
# 空目录也清理
|
|
423
|
+
try:
|
|
424
|
+
os.rmdir(file_output_dir)
|
|
425
|
+
except OSError:
|
|
426
|
+
pass
|
|
427
|
+
|
|
428
|
+
results[filepath] = count
|
|
429
|
+
total_images += count
|
|
430
|
+
print(f" ✅ 提取 {count} 张图片")
|
|
431
|
+
|
|
432
|
+
except Exception as e:
|
|
433
|
+
results[filepath] = 0
|
|
434
|
+
print(f" ❌ 失败: {e}")
|
|
435
|
+
|
|
436
|
+
# 汇总
|
|
437
|
+
print("\n" + "=" * 50)
|
|
438
|
+
print(f"🎉 处理完成: {total_files} 个文件, 共 {total_images} 张图片")
|
|
439
|
+
print(f"📁 输出目录: {os.path.abspath(output_dir)}")
|
|
440
|
+
return results
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
# -------------------- CLI --------------------
|
|
444
|
+
|
|
445
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
446
|
+
parser = argparse.ArgumentParser(
|
|
447
|
+
description="从文档中提取内嵌图片",
|
|
448
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
449
|
+
epilog="""
|
|
450
|
+
示例:
|
|
451
|
+
%(prog)s report.docx
|
|
452
|
+
%(prog)s report.docx slides.pptx -o ./images
|
|
453
|
+
%(prog)s --dir ./docs -o ./images
|
|
454
|
+
%(prog)s --dir ./docs --flat -o ./all_images
|
|
455
|
+
""",
|
|
456
|
+
)
|
|
457
|
+
parser.add_argument(
|
|
458
|
+
"inputs",
|
|
459
|
+
nargs="*",
|
|
460
|
+
help="要处理的文件或目录路径(可多选)",
|
|
461
|
+
)
|
|
462
|
+
parser.add_argument(
|
|
463
|
+
"-d", "--dir",
|
|
464
|
+
action="append",
|
|
465
|
+
default=[],
|
|
466
|
+
help="扫描目录中的所有支持文件(可多次使用)",
|
|
467
|
+
)
|
|
468
|
+
parser.add_argument(
|
|
469
|
+
"-o", "--output",
|
|
470
|
+
default="extracted_images",
|
|
471
|
+
help="输出目录(默认: extracted_images)",
|
|
472
|
+
)
|
|
473
|
+
parser.add_argument(
|
|
474
|
+
"--flat",
|
|
475
|
+
action="store_true",
|
|
476
|
+
help="扁平输出:所有图片放到同一目录,不按文件分目录",
|
|
477
|
+
)
|
|
478
|
+
return parser
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
def main():
|
|
482
|
+
parser = build_parser()
|
|
483
|
+
args = parser.parse_args()
|
|
484
|
+
|
|
485
|
+
# 收集所有输入
|
|
486
|
+
all_inputs = list(args.inputs) if args.inputs else []
|
|
487
|
+
for d in args.dir:
|
|
488
|
+
all_inputs.append(d)
|
|
489
|
+
|
|
490
|
+
if not all_inputs:
|
|
491
|
+
parser.print_help()
|
|
492
|
+
sys.exit(1)
|
|
493
|
+
|
|
494
|
+
extract_images(all_inputs, args.output, flat=args.flat)
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
if __name__ == "__main__":
|
|
498
|
+
main()
|