wezard 2.9.0 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (477) hide show
  1. package/CLAUDE.md +43 -21
  2. package/README.md +37 -50
  3. package/cli/wezard.sh +59 -20
  4. package/config.example.jsonc +5 -8
  5. package/dist/cli/audit.js +11 -13
  6. package/dist/cli/audit.js.map +1 -1
  7. package/dist/cli/codex-hook.js +20 -17
  8. package/dist/cli/codex-hook.js.map +1 -1
  9. package/dist/cli/ext.js +271 -0
  10. package/dist/cli/ext.js.map +1 -0
  11. package/dist/cli/init.js +44 -13
  12. package/dist/cli/init.js.map +1 -1
  13. package/dist/cli/skills.js +113 -0
  14. package/dist/cli/skills.js.map +1 -0
  15. package/dist/cli/sync.js +3 -2
  16. package/dist/cli/sync.js.map +1 -1
  17. package/dist/cli/wx.js +7 -6
  18. package/dist/cli/wx.js.map +1 -1
  19. package/dist/daemon/aibot-media.js +28 -20
  20. package/dist/daemon/aibot-media.js.map +1 -1
  21. package/dist/daemon/apprentice.js +75 -0
  22. package/dist/daemon/apprentice.js.map +1 -0
  23. package/dist/daemon/approval.js +75 -33
  24. package/dist/daemon/approval.js.map +1 -1
  25. package/dist/daemon/channel-context.js +7 -0
  26. package/dist/daemon/channel-context.js.map +1 -1
  27. package/dist/daemon/channel-onboarding.js +61 -0
  28. package/dist/daemon/channel-onboarding.js.map +1 -0
  29. package/dist/daemon/channel-posts.js +93 -0
  30. package/dist/daemon/channel-posts.js.map +1 -0
  31. package/dist/daemon/channel-rebind.js +100 -0
  32. package/dist/daemon/channel-rebind.js.map +1 -0
  33. package/dist/daemon/channel-store.js.map +1 -1
  34. package/dist/daemon/channel.js +273 -409
  35. package/dist/daemon/channel.js.map +1 -1
  36. package/dist/daemon/chat-name.js +24 -161
  37. package/dist/daemon/chat-name.js.map +1 -1
  38. package/dist/daemon/claim.js +1 -45
  39. package/dist/daemon/claim.js.map +1 -1
  40. package/dist/daemon/classes.js +416 -0
  41. package/dist/daemon/classes.js.map +1 -0
  42. package/dist/daemon/config-api.js +6 -30
  43. package/dist/daemon/config-api.js.map +1 -1
  44. package/dist/daemon/control-socket.js +93 -0
  45. package/dist/daemon/control-socket.js.map +1 -0
  46. package/dist/daemon/danger-scrub.js +315 -0
  47. package/dist/daemon/danger-scrub.js.map +1 -0
  48. package/dist/daemon/danger.js +146 -16
  49. package/dist/daemon/danger.js.map +1 -1
  50. package/dist/daemon/detail.js +50 -22
  51. package/dist/daemon/detail.js.map +1 -1
  52. package/dist/daemon/exec-surface.js +108 -0
  53. package/dist/daemon/exec-surface.js.map +1 -0
  54. package/dist/daemon/external.js +595 -0
  55. package/dist/daemon/external.js.map +1 -0
  56. package/dist/daemon/handoff.js +51 -50
  57. package/dist/daemon/handoff.js.map +1 -1
  58. package/dist/daemon/http.js +119 -31
  59. package/dist/daemon/http.js.map +1 -1
  60. package/dist/daemon/idle-reap.js +30 -0
  61. package/dist/daemon/idle-reap.js.map +1 -0
  62. package/dist/daemon/inbound.js +436 -207
  63. package/dist/daemon/inbound.js.map +1 -1
  64. package/dist/daemon/index.js +3353 -2760
  65. package/dist/daemon/index.js.map +1 -1
  66. package/dist/daemon/last-response.js +51 -25
  67. package/dist/daemon/last-response.js.map +1 -1
  68. package/dist/daemon/legacy-panes.js +67 -0
  69. package/dist/daemon/legacy-panes.js.map +1 -0
  70. package/dist/daemon/mcp-http.js.map +1 -1
  71. package/dist/daemon/me-room.js +137 -0
  72. package/dist/daemon/me-room.js.map +1 -0
  73. package/dist/daemon/media.js +14 -0
  74. package/dist/daemon/media.js.map +1 -1
  75. package/dist/daemon/memory-steward.js +1 -1
  76. package/dist/daemon/memory-steward.js.map +1 -1
  77. package/dist/daemon/message-format.js +15 -2
  78. package/dist/daemon/message-format.js.map +1 -1
  79. package/dist/daemon/mirror-bridge.js +583 -488
  80. package/dist/daemon/mirror-bridge.js.map +1 -1
  81. package/dist/daemon/mirror-store.js +24 -0
  82. package/dist/daemon/mirror-store.js.map +1 -1
  83. package/dist/daemon/notices.js +5 -6
  84. package/dist/daemon/notices.js.map +1 -1
  85. package/dist/daemon/onboarding.js +459 -0
  86. package/dist/daemon/onboarding.js.map +1 -0
  87. package/dist/daemon/outbound.js +21 -11
  88. package/dist/daemon/outbound.js.map +1 -1
  89. package/dist/daemon/peers.js +39 -231
  90. package/dist/daemon/peers.js.map +1 -1
  91. package/dist/daemon/plan-http.js +2 -3
  92. package/dist/daemon/plan-http.js.map +1 -1
  93. package/dist/daemon/plans.js.map +1 -1
  94. package/dist/daemon/reach.js +1 -5
  95. package/dist/daemon/reach.js.map +1 -1
  96. package/dist/daemon/room-auto-adhoc.js +18 -0
  97. package/dist/daemon/room-auto-adhoc.js.map +1 -0
  98. package/dist/daemon/room-bind.js +297 -0
  99. package/dist/daemon/room-bind.js.map +1 -0
  100. package/dist/daemon/room-facts.js +35 -0
  101. package/dist/daemon/room-facts.js.map +1 -0
  102. package/dist/daemon/room-hub.js +569 -0
  103. package/dist/daemon/room-hub.js.map +1 -0
  104. package/dist/daemon/room-overdue.js +160 -0
  105. package/dist/daemon/room-overdue.js.map +1 -0
  106. package/dist/daemon/room-prune.js +74 -0
  107. package/dist/daemon/room-prune.js.map +1 -0
  108. package/dist/daemon/room-spawn.js +20 -0
  109. package/dist/daemon/room-spawn.js.map +1 -0
  110. package/dist/daemon/room-watchdog.js +175 -0
  111. package/dist/daemon/room-watchdog.js.map +1 -0
  112. package/dist/daemon/rooms.js +204 -0
  113. package/dist/daemon/rooms.js.map +1 -0
  114. package/dist/daemon/route.js +7 -18
  115. package/dist/daemon/route.js.map +1 -1
  116. package/dist/daemon/session-scan.js +1 -1
  117. package/dist/daemon/session-scan.js.map +1 -1
  118. package/dist/daemon/short-id-log.js +43 -0
  119. package/dist/daemon/short-id-log.js.map +1 -0
  120. package/dist/daemon/spawn-tmux.js +60 -45
  121. package/dist/daemon/spawn-tmux.js.map +1 -1
  122. package/dist/daemon/steward-guard.js +3 -3
  123. package/dist/daemon/steward-guard.js.map +1 -1
  124. package/dist/daemon/steward-model.js +17 -3
  125. package/dist/daemon/steward-model.js.map +1 -1
  126. package/dist/daemon/steward-repair.js +171 -0
  127. package/dist/daemon/steward-repair.js.map +1 -0
  128. package/dist/daemon/steward.js +171 -0
  129. package/dist/daemon/steward.js.map +1 -0
  130. package/dist/daemon/tasks.js +4 -14
  131. package/dist/daemon/tasks.js.map +1 -1
  132. package/dist/daemon/tool-face.js +31 -0
  133. package/dist/daemon/tool-face.js.map +1 -0
  134. package/dist/daemon/turn-opening.js +30 -0
  135. package/dist/daemon/turn-opening.js.map +1 -0
  136. package/dist/daemon/wake-tail.js +55 -0
  137. package/dist/daemon/wake-tail.js.map +1 -0
  138. package/dist/daemon/weixin-cmd.js +10 -14
  139. package/dist/daemon/weixin-cmd.js.map +1 -1
  140. package/dist/daemon/wezard-session.js +6 -2
  141. package/dist/daemon/wezard-session.js.map +1 -1
  142. package/dist/daemon/wizard-memory.js +4 -10
  143. package/dist/daemon/wizard-memory.js.map +1 -1
  144. package/dist/daemon/wizard-names.js +0 -22
  145. package/dist/daemon/wizard-names.js.map +1 -1
  146. package/dist/daemon/wizard.js +683 -159
  147. package/dist/daemon/wizard.js.map +1 -1
  148. package/dist/daemon/ws.js +1 -1
  149. package/dist/daemon/ws.js.map +1 -1
  150. package/dist/mcp/output.js +30 -7
  151. package/dist/mcp/output.js.map +1 -1
  152. package/dist/mcp/relay.js +152 -0
  153. package/dist/mcp/relay.js.map +1 -0
  154. package/dist/mcp/tools.js +318 -265
  155. package/dist/mcp/tools.js.map +1 -1
  156. package/dist/shared/allow-rules.js +1 -7
  157. package/dist/shared/allow-rules.js.map +1 -1
  158. package/dist/shared/charter-rearm.js +179 -0
  159. package/dist/shared/charter-rearm.js.map +1 -0
  160. package/dist/shared/chat-http.js +412 -480
  161. package/dist/shared/chat-http.js.map +1 -1
  162. package/dist/shared/chat-record.js +55 -0
  163. package/dist/shared/chat-record.js.map +1 -0
  164. package/dist/shared/chat-render.js +7 -4
  165. package/dist/shared/chat-render.js.map +1 -1
  166. package/dist/shared/chat-view.js +2 -41
  167. package/dist/shared/chat-view.js.map +1 -1
  168. package/dist/shared/cli-backends.js +13 -5
  169. package/dist/shared/cli-backends.js.map +1 -1
  170. package/dist/shared/cli-local-status.js +28 -0
  171. package/dist/shared/cli-local-status.js.map +1 -0
  172. package/dist/shared/cli-socket.js +14 -0
  173. package/dist/shared/cli-socket.js.map +1 -0
  174. package/dist/shared/codex-hooks.js +5 -2
  175. package/dist/shared/codex-hooks.js.map +1 -1
  176. package/dist/shared/config.js +90 -66
  177. package/dist/shared/config.js.map +1 -1
  178. package/dist/shared/daemon-addr.js +23 -0
  179. package/dist/shared/daemon-addr.js.map +1 -0
  180. package/dist/shared/daemon-client.js +41 -0
  181. package/dist/shared/daemon-client.js.map +1 -0
  182. package/dist/shared/daemon-token.js +2 -2
  183. package/dist/shared/daemon-token.js.map +1 -1
  184. package/dist/shared/detail-render.js +98 -21
  185. package/dist/shared/detail-render.js.map +1 -1
  186. package/dist/shared/detail-store.js.map +1 -1
  187. package/dist/shared/external.js +402 -0
  188. package/dist/shared/external.js.map +1 -0
  189. package/dist/shared/group-members.js +35 -0
  190. package/dist/shared/group-members.js.map +1 -0
  191. package/dist/shared/inject-view.js +143 -0
  192. package/dist/shared/inject-view.js.map +1 -0
  193. package/dist/shared/instance-id.js +21 -0
  194. package/dist/shared/instance-id.js.map +1 -0
  195. package/dist/shared/legacy-routes.js +199 -0
  196. package/dist/shared/legacy-routes.js.map +1 -0
  197. package/dist/shared/mem-guard.js +32 -0
  198. package/dist/shared/mem-guard.js.map +1 -0
  199. package/dist/shared/message-footer.js +11 -3
  200. package/dist/shared/message-footer.js.map +1 -1
  201. package/dist/shared/model-tiers.js +39 -1
  202. package/dist/shared/model-tiers.js.map +1 -1
  203. package/dist/shared/ports.js +56 -0
  204. package/dist/shared/ports.js.map +1 -0
  205. package/dist/shared/reminder.js +30 -38
  206. package/dist/shared/reminder.js.map +1 -1
  207. package/dist/shared/role-render.js +210 -210
  208. package/dist/shared/role-render.js.map +1 -1
  209. package/dist/shared/role-view.js +65 -300
  210. package/dist/shared/role-view.js.map +1 -1
  211. package/dist/shared/room-label.js +13 -0
  212. package/dist/shared/room-label.js.map +1 -0
  213. package/dist/shared/room-migrate.js +404 -0
  214. package/dist/shared/room-migrate.js.map +1 -0
  215. package/dist/shared/room-overdue.js +153 -0
  216. package/dist/shared/room-overdue.js.map +1 -0
  217. package/dist/shared/room-search.js +102 -0
  218. package/dist/shared/room-search.js.map +1 -0
  219. package/dist/shared/room-view.js +275 -0
  220. package/dist/shared/room-view.js.map +1 -0
  221. package/dist/shared/room.js +827 -0
  222. package/dist/shared/room.js.map +1 -0
  223. package/dist/shared/session-hooks.js +20 -8
  224. package/dist/shared/session-hooks.js.map +1 -1
  225. package/dist/shared/session-label.js +82 -84
  226. package/dist/shared/session-label.js.map +1 -1
  227. package/dist/shared/session-mcp.js +36 -40
  228. package/dist/shared/session-mcp.js.map +1 -1
  229. package/dist/shared/session-skills.js +8 -0
  230. package/dist/shared/session-skills.js.map +1 -1
  231. package/dist/shared/skill-sync.js +229 -0
  232. package/dist/shared/skill-sync.js.map +1 -0
  233. package/dist/shared/smarts.js +24 -0
  234. package/dist/shared/smarts.js.map +1 -0
  235. package/dist/shared/stream-page.js +22 -0
  236. package/dist/shared/stream-page.js.map +1 -0
  237. package/dist/shared/task-file.js +0 -5
  238. package/dist/shared/task-file.js.map +1 -1
  239. package/dist/shared/task-template.js +1 -1
  240. package/dist/shared/task-template.js.map +1 -1
  241. package/dist/shared/tool-hints.js +20 -11
  242. package/dist/shared/tool-hints.js.map +1 -1
  243. package/dist/shared/workspace-trust.js +8 -0
  244. package/dist/shared/workspace-trust.js.map +1 -1
  245. package/dist/shared/world.js +101 -166
  246. package/dist/shared/world.js.map +1 -1
  247. package/dist/svr/facts-store.js +26 -0
  248. package/dist/svr/facts-store.js.map +1 -0
  249. package/dist/svr/index.js +114 -16
  250. package/dist/svr/index.js.map +1 -1
  251. package/hooks/pre-tool-use.sh +14 -10
  252. package/hooks/stop.sh +28 -0
  253. package/launchd/com.wezard.svr.plist.template +2 -0
  254. package/package.json +9 -2
  255. package/scripts/install.sh +23 -0
  256. package/skills/LICENSE.wecom-unified.txt +21 -0
  257. package/skills/wecom-unified/SKILL.md +151 -0
  258. package/skills/wecom-unified/assets/templates/broadside/DESIGN.preset.md +172 -0
  259. package/skills/wecom-unified/assets/templates/broadside/shell/content.jsx +31 -0
  260. package/skills/wecom-unified/assets/templates/broadside/slides/01_cover.slide +48 -0
  261. package/skills/wecom-unified/assets/templates/broadside/slides/02_section.slide +58 -0
  262. package/skills/wecom-unified/assets/templates/broadside/slides/03_cards.slide +53 -0
  263. package/skills/wecom-unified/assets/templates/broadside/slides/04_image.slide +64 -0
  264. package/skills/wecom-unified/assets/templates/cartesian/DESIGN.preset.md +139 -0
  265. package/skills/wecom-unified/assets/templates/cartesian/shell/content.jsx +28 -0
  266. package/skills/wecom-unified/assets/templates/cartesian/slides/01_cover.slide +44 -0
  267. package/skills/wecom-unified/assets/templates/cartesian/slides/02_compare.slide +79 -0
  268. package/skills/wecom-unified/assets/templates/cartesian/slides/03_table.slide +79 -0
  269. package/skills/wecom-unified/assets/templates/cobalt-grid/DESIGN.preset.md +118 -0
  270. package/skills/wecom-unified/assets/templates/cobalt-grid/shell/content.jsx +24 -0
  271. package/skills/wecom-unified/assets/templates/cobalt-grid/slides/01_cover.slide +61 -0
  272. package/skills/wecom-unified/assets/templates/cobalt-grid/slides/02_structure.slide +85 -0
  273. package/skills/wecom-unified/assets/templates/cobalt-grid/slides/03_data.slide +60 -0
  274. package/skills/wecom-unified/assets/templates/editorial-forest/DESIGN.preset.md +135 -0
  275. package/skills/wecom-unified/assets/templates/editorial-forest/shell/content.jsx +19 -0
  276. package/skills/wecom-unified/assets/templates/editorial-forest/slides/01_cover.slide +29 -0
  277. package/skills/wecom-unified/assets/templates/editorial-forest/slides/02_cards.slide +60 -0
  278. package/skills/wecom-unified/assets/templates/editorial-forest/slides/03_data.slide +49 -0
  279. package/skills/wecom-unified/assets/templates/editorial-forest/slides/04_image.slide +46 -0
  280. package/skills/wecom-unified/assets/templates/emerald-editorial/DESIGN.preset.md +119 -0
  281. package/skills/wecom-unified/assets/templates/emerald-editorial/shell/content.jsx +18 -0
  282. package/skills/wecom-unified/assets/templates/emerald-editorial/slides/01_cover.slide +36 -0
  283. package/skills/wecom-unified/assets/templates/emerald-editorial/slides/02_section.slide +39 -0
  284. package/skills/wecom-unified/assets/templates/emerald-editorial/slides/03_data.slide +79 -0
  285. package/skills/wecom-unified/assets/templates/emerald-editorial/slides/04_steps.slide +53 -0
  286. package/skills/wecom-unified/assets/templates/grove/DESIGN.preset.md +159 -0
  287. package/skills/wecom-unified/assets/templates/grove/shell/content.jsx +18 -0
  288. package/skills/wecom-unified/assets/templates/grove/shell/content_light.jsx +18 -0
  289. package/skills/wecom-unified/assets/templates/grove/slides/01_cover.slide +26 -0
  290. package/skills/wecom-unified/assets/templates/grove/slides/02_compare.slide +92 -0
  291. package/skills/wecom-unified/assets/templates/grove/slides/03_table.slide +68 -0
  292. package/skills/wecom-unified/assets/templates/index.json +280 -0
  293. package/skills/wecom-unified/assets/templates/long-table/DESIGN.preset.md +135 -0
  294. package/skills/wecom-unified/assets/templates/long-table/shell/content.jsx +36 -0
  295. package/skills/wecom-unified/assets/templates/long-table/slides/01_cover.slide +71 -0
  296. package/skills/wecom-unified/assets/templates/long-table/slides/02_cards.slide +72 -0
  297. package/skills/wecom-unified/assets/templates/long-table/slides/03_timeline.slide +81 -0
  298. package/skills/wecom-unified/assets/templates/long-table/slides/04_image.slide +60 -0
  299. package/skills/wecom-unified/assets/templates/sakura-chroma/DESIGN.preset.md +121 -0
  300. package/skills/wecom-unified/assets/templates/sakura-chroma/shell/content.jsx +13 -0
  301. package/skills/wecom-unified/assets/templates/sakura-chroma/slides/01_cover.slide +54 -0
  302. package/skills/wecom-unified/assets/templates/sakura-chroma/slides/02_products.slide +134 -0
  303. package/skills/wecom-unified/assets/templates/sakura-chroma/slides/03_section.slide +30 -0
  304. package/skills/wecom-unified/assets/templates/sakura-chroma/slides/04_schedule.slide +65 -0
  305. package/skills/wecom-unified/assets/templates/signal/DESIGN.preset.md +121 -0
  306. package/skills/wecom-unified/assets/templates/signal/shell/content.jsx +18 -0
  307. package/skills/wecom-unified/assets/templates/signal/shell/content_dark.jsx +23 -0
  308. package/skills/wecom-unified/assets/templates/signal/slides/01_cover.slide +48 -0
  309. package/skills/wecom-unified/assets/templates/signal/slides/02_cards.slide +67 -0
  310. package/skills/wecom-unified/assets/templates/signal/slides/03_data.slide +68 -0
  311. package/skills/wecom-unified/references/wecomcli-calendar-agenda.md +227 -0
  312. package/skills/wecom-unified/references/wecomcli-calendar-cancel.md +108 -0
  313. package/skills/wecom-unified/references/wecomcli-calendar-create.md +238 -0
  314. package/skills/wecom-unified/references/wecomcli-calendar-freebusy.md +207 -0
  315. package/skills/wecom-unified/references/wecomcli-calendar-meeting-room.md +170 -0
  316. package/skills/wecom-unified/references/wecomcli-calendar-search.md +209 -0
  317. package/skills/wecom-unified/references/wecomcli-calendar-update.md +272 -0
  318. package/skills/wecom-unified/references/wecomcli-calendar.md +296 -0
  319. package/skills/wecom-unified/references/wecomcli-contact.md +48 -0
  320. package/skills/wecom-unified/references/wecomcli-disk.md +380 -0
  321. package/skills/wecom-unified/references/wecomcli-doc-contents-append.md +20 -0
  322. package/skills/wecom-unified/references/wecomcli-doc-contents-overwrite.md +27 -0
  323. package/skills/wecom-unified/references/wecomcli-doc-create.md +162 -0
  324. package/skills/wecom-unified/references/wecomcli-doc-manage-doc-members-update.md +24 -0
  325. package/skills/wecom-unified/references/wecomcli-doc-manage-doc-names-update.md +20 -0
  326. package/skills/wecom-unified/references/wecomcli-doc-manage-doc-rules-update.md +22 -0
  327. package/skills/wecom-unified/references/wecomcli-doc-manage.md +127 -0
  328. package/skills/wecom-unified/references/wecomcli-doc.md +135 -0
  329. package/skills/wecom-unified/references/wecomcli-email-forward-mail.md +131 -0
  330. package/skills/wecom-unified/references/wecomcli-email-get-mail.md +187 -0
  331. package/skills/wecom-unified/references/wecomcli-email-reply-mail.md +138 -0
  332. package/skills/wecom-unified/references/wecomcli-email-search-mail.md +114 -0
  333. package/skills/wecom-unified/references/wecomcli-email-security.md +52 -0
  334. package/skills/wecom-unified/references/wecomcli-email-send-mail.md +186 -0
  335. package/skills/wecom-unified/references/wecomcli-email-send-schedule.md +83 -0
  336. package/skills/wecom-unified/references/wecomcli-email.md +206 -0
  337. package/skills/wecom-unified/references/wecomcli-media.md +89 -0
  338. package/skills/wecom-unified/references/wecomcli-meeting-cancel.md +113 -0
  339. package/skills/wecom-unified/references/wecomcli-meeting-create.md +167 -0
  340. package/skills/wecom-unified/references/wecomcli-meeting-list.md +228 -0
  341. package/skills/wecom-unified/references/wecomcli-meeting-original-get.md +101 -0
  342. package/skills/wecom-unified/references/wecomcli-meeting-search.md +176 -0
  343. package/skills/wecom-unified/references/wecomcli-meeting-update.md +217 -0
  344. package/skills/wecom-unified/references/wecomcli-meeting.md +366 -0
  345. package/skills/wecom-unified/references/wecomcli-message.md +190 -0
  346. package/skills/wecom-unified/references/wecomcli-pptx-component-animation.md +62 -0
  347. package/skills/wecom-unified/references/wecomcli-pptx-component-box.md +102 -0
  348. package/skills/wecom-unified/references/wecomcli-pptx-component-chart.md +261 -0
  349. package/skills/wecom-unified/references/wecomcli-pptx-component-codeblock.md +70 -0
  350. package/skills/wecom-unified/references/wecomcli-pptx-component-diagram.md +54 -0
  351. package/skills/wecom-unified/references/wecomcli-pptx-component-faicon.md +71 -0
  352. package/skills/wecom-unified/references/wecomcli-pptx-component-hyperlink.md +55 -0
  353. package/skills/wecom-unified/references/wecomcli-pptx-component-image.md +107 -0
  354. package/skills/wecom-unified/references/wecomcli-pptx-component-math.md +65 -0
  355. package/skills/wecom-unified/references/wecomcli-pptx-component-qrcode.md +22 -0
  356. package/skills/wecom-unified/references/wecomcli-pptx-component-slide.md +74 -0
  357. package/skills/wecom-unified/references/wecomcli-pptx-component-svg.md +95 -0
  358. package/skills/wecom-unified/references/wecomcli-pptx-component-table.md +72 -0
  359. package/skills/wecom-unified/references/wecomcli-pptx-component-text.md +96 -0
  360. package/skills/wecom-unified/references/wecomcli-pptx-content-contract.md +73 -0
  361. package/skills/wecom-unified/references/wecomcli-pptx-create-from-material.md +67 -0
  362. package/skills/wecom-unified/references/wecomcli-pptx-create-from-scratch.md +178 -0
  363. package/skills/wecom-unified/references/wecomcli-pptx-create-from-template.md +123 -0
  364. package/skills/wecom-unified/references/wecomcli-pptx-design-principle.md +65 -0
  365. package/skills/wecom-unified/references/wecomcli-pptx-government-contract.md +40 -0
  366. package/skills/wecom-unified/references/wecomcli-pptx-human-alignment.md +140 -0
  367. package/skills/wecom-unified/references/wecomcli-pptx-pptx-api.md +161 -0
  368. package/skills/wecom-unified/references/wecomcli-pptx-pptx-edit.md +37 -0
  369. package/skills/wecom-unified/references/wecomcli-pptx-story-principle.md +184 -0
  370. package/skills/wecom-unified/references/wecomcli-pptx-templates-README.md +165 -0
  371. package/skills/wecom-unified/references/wecomcli-pptx-templates-anti-ai-slop.md +52 -0
  372. package/skills/wecom-unified/references/wecomcli-pptx.md +158 -0
  373. package/skills/wecom-unified/references/wecomcli-sheet-conditional-formatting.md +203 -0
  374. package/skills/wecom-unified/references/wecomcli-sheet-filter.md +179 -0
  375. package/skills/wecom-unified/references/wecomcli-sheet-float-image.md +235 -0
  376. package/skills/wecom-unified/references/wecomcli-sheet-formulas.md +71 -0
  377. package/skills/wecom-unified/references/wecomcli-sheet-history.md +118 -0
  378. package/skills/wecom-unified/references/wecomcli-sheet-protection.md +170 -0
  379. package/skills/wecom-unified/references/wecomcli-sheet-range-operations.md +306 -0
  380. package/skills/wecom-unified/references/wecomcli-sheet-read-data.md +151 -0
  381. package/skills/wecom-unified/references/wecomcli-sheet-search-replace.md +121 -0
  382. package/skills/wecom-unified/references/wecomcli-sheet-structure-operations.md +394 -0
  383. package/skills/wecom-unified/references/wecomcli-sheet-style.md +246 -0
  384. package/skills/wecom-unified/references/wecomcli-sheet-table-style.md +199 -0
  385. package/skills/wecom-unified/references/wecomcli-sheet-validation.md +217 -0
  386. package/skills/wecom-unified/references/wecomcli-sheet-visual-standards.md +166 -0
  387. package/skills/wecom-unified/references/wecomcli-sheet-workbook.md +264 -0
  388. package/skills/wecom-unified/references/wecomcli-sheet-write-cells.md +320 -0
  389. package/skills/wecom-unified/references/wecomcli-sheet-xlsx-process.md +324 -0
  390. package/skills/wecom-unified/references/wecomcli-sheet.md +96 -0
  391. package/skills/wecom-unified/references/wecomcli-smartpage-data-driven-pages.md +50 -0
  392. package/skills/wecom-unified/references/wecomcli-smartpage-edit.md +526 -0
  393. package/skills/wecom-unified/references/wecomcli-smartpage-formula-arraylist.md +369 -0
  394. package/skills/wecom-unified/references/wecomcli-smartpage-formula-datetime.md +283 -0
  395. package/skills/wecom-unified/references/wecomcli-smartpage-formula-logic.md +247 -0
  396. package/skills/wecom-unified/references/wecomcli-smartpage-formula-math.md +362 -0
  397. package/skills/wecom-unified/references/wecomcli-smartpage-formula-operators.md +246 -0
  398. package/skills/wecom-unified/references/wecomcli-smartpage-formula-pageblock.md +76 -0
  399. package/skills/wecom-unified/references/wecomcli-smartpage-formula-reference.md +192 -0
  400. package/skills/wecom-unified/references/wecomcli-smartpage-formula-templates.md +410 -0
  401. package/skills/wecom-unified/references/wecomcli-smartpage-formula-text.md +377 -0
  402. package/skills/wecom-unified/references/wecomcli-smartpage-formula-user.md +22 -0
  403. package/skills/wecom-unified/references/wecomcli-smartpage-mdx-syntax.md +739 -0
  404. package/skills/wecom-unified/references/wecomcli-smartpage.md +179 -0
  405. package/skills/wecom-unified/references/wecomcli-smartsheet-chart-types.md +95 -0
  406. package/skills/wecom-unified/references/wecomcli-smartsheet-common.md +160 -0
  407. package/skills/wecom-unified/references/wecomcli-smartsheet-edit.md +609 -0
  408. package/skills/wecom-unified/references/wecomcli-smartsheet-field-types.md +438 -0
  409. package/skills/wecom-unified/references/wecomcli-smartsheet-formula.md +845 -0
  410. package/skills/wecom-unified/references/wecomcli-smartsheet-read.md +411 -0
  411. package/skills/wecom-unified/references/wecomcli-smartsheet-record-values.md +218 -0
  412. package/skills/wecom-unified/references/wecomcli-smartsheet-template-ai_efficiency.md +709 -0
  413. package/skills/wecom-unified/references/wecomcli-smartsheet-template-connect_to_app.md +380 -0
  414. package/skills/wecom-unified/references/wecomcli-smartsheet-template-financial_accounting.md +369 -0
  415. package/skills/wecom-unified/references/wecomcli-smartsheet-template-hr_and_administration.md +475 -0
  416. package/skills/wecom-unified/references/wecomcli-smartsheet-template-ledger_records.md +156 -0
  417. package/skills/wecom-unified/references/wecomcli-smartsheet-template-manufacturing.md +395 -0
  418. package/skills/wecom-unified/references/wecomcli-smartsheet-template-marketing.md +186 -0
  419. package/skills/wecom-unified/references/wecomcli-smartsheet-template-office_essentials.md +299 -0
  420. package/skills/wecom-unified/references/wecomcli-smartsheet-template-personal_efficiency.md +70 -0
  421. package/skills/wecom-unified/references/wecomcli-smartsheet-template-procurement_logistics.md +325 -0
  422. package/skills/wecom-unified/references/wecomcli-smartsheet-template-project_management.md +564 -0
  423. package/skills/wecom-unified/references/wecomcli-smartsheet-template-rd_process_customer.md +222 -0
  424. package/skills/wecom-unified/references/wecomcli-smartsheet-template-rd_process_ops.md +105 -0
  425. package/skills/wecom-unified/references/wecomcli-smartsheet-template-rd_process_project.md +109 -0
  426. package/skills/wecom-unified/references/wecomcli-smartsheet-template-rd_process_research.md +92 -0
  427. package/skills/wecom-unified/references/wecomcli-smartsheet-template-sales_and_operations.md +446 -0
  428. package/skills/wecom-unified/references/wecomcli-smartsheet-template-store_management.md +431 -0
  429. package/skills/wecom-unified/references/wecomcli-smartsheet-template-team_tasks.md +274 -0
  430. package/skills/wecom-unified/references/wecomcli-smartsheet-template-wechat_customer.md +384 -0
  431. package/skills/wecom-unified/references/wecomcli-smartsheet-template-work_report.md +100 -0
  432. package/skills/wecom-unified/references/wecomcli-smartsheet-templates.md +53 -0
  433. package/skills/wecom-unified/references/wecomcli-smartsheet-view-types.md +373 -0
  434. package/skills/wecom-unified/references/wecomcli-smartsheet-webhook-examples.md +176 -0
  435. package/skills/wecom-unified/references/wecomcli-smartsheet-webhook.md +186 -0
  436. package/skills/wecom-unified/references/wecomcli-smartsheet.md +147 -0
  437. package/skills/wecom-unified/references/wecomcli-todo-create.md +137 -0
  438. package/skills/wecom-unified/references/wecomcli-todo-delete.md +63 -0
  439. package/skills/wecom-unified/references/wecomcli-todo-finish.md +72 -0
  440. package/skills/wecom-unified/references/wecomcli-todo-get.md +69 -0
  441. package/skills/wecom-unified/references/wecomcli-todo-list.md +136 -0
  442. package/skills/wecom-unified/references/wecomcli-todo-update.md +112 -0
  443. package/skills/wecom-unified/references/wecomcli-todo.md +68 -0
  444. package/skills/wecom-unified/scripts/build_docx.py +1274 -0
  445. package/skills/wecom-unified/scripts/build_page.py +2449 -0
  446. package/skills/wecom-unified/scripts/collect.py +868 -0
  447. package/skills/wecom-unified/scripts/doc_image_extractor.py +498 -0
  448. package/skills/wecom-unified/scripts/pptx2image.py +268 -0
  449. package/skills/wecom-unified/scripts/recalc.py +403 -0
  450. package/systemd/wezard-svr.service.template +2 -0
  451. package/systemd/wezard.service.template +6 -0
  452. package/web/chat.css +70 -273
  453. package/web/chat.js +2269 -2190
  454. package/dist/daemon/bot-mux.js +0 -161
  455. package/dist/daemon/bot-mux.js.map +0 -1
  456. package/dist/daemon/chat-log.js +0 -130
  457. package/dist/daemon/chat-log.js.map +0 -1
  458. package/dist/daemon/dispatch.js +0 -6
  459. package/dist/daemon/dispatch.js.map +0 -1
  460. package/dist/daemon/idle-nudge.js +0 -90
  461. package/dist/daemon/idle-nudge.js.map +0 -1
  462. package/dist/daemon/message-events.js +0 -1155
  463. package/dist/daemon/message-events.js.map +0 -1
  464. package/dist/daemon/pending-items.js +0 -160
  465. package/dist/daemon/pending-items.js.map +0 -1
  466. package/dist/daemon/router.js +0 -742
  467. package/dist/daemon/router.js.map +0 -1
  468. package/dist/daemon/tips.js +0 -25
  469. package/dist/daemon/tips.js.map +0 -1
  470. package/dist/daemon/wedoc.js +0 -210
  471. package/dist/daemon/wedoc.js.map +0 -1
  472. package/dist/shared/role-search.js +0 -100
  473. package/dist/shared/role-search.js.map +0 -1
  474. package/dist/shared/startup-notice.js +0 -21
  475. package/dist/shared/startup-notice.js.map +0 -1
  476. package/dist/shared/turn-state.js +0 -27
  477. package/dist/shared/turn-state.js.map +0 -1
@@ -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()