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.
Files changed (484) hide show
  1. package/README.md +14 -12
  2. package/package.json +34 -1
  3. package/plugins/cron-runner/.claude-plugin/plugin.json +5 -0
  4. package/plugins/cron-runner/commands/cron.md +26 -0
  5. package/plugins/cron-runner/commands/crons.md +7 -0
  6. package/plugins/cron-runner/plugin.js +34 -0
  7. package/plugins/cron-runner/src/commands.js +348 -0
  8. package/plugins/cron-runner/src/cronTime.js +148 -0
  9. package/plugins/cron-runner/src/lock.js +68 -0
  10. package/plugins/cron-runner/src/runs.js +89 -0
  11. package/plugins/cron-runner/src/scheduleEngine.js +72 -0
  12. package/plugins/cron-runner/src/scheduler.js +355 -0
  13. package/plugins/cron-runner/src/schema.js +140 -0
  14. package/plugins/cron-runner/src/service.js +167 -0
  15. package/plugins/cron-runner/src/store.js +298 -0
  16. package/plugins/cron-runner/src/types.js +1 -0
  17. package/plugins/workflow-runner/commands/workflow.md +4 -4
  18. package/plugins/workflow-runner/commands/workflows.md +1 -1
  19. package/plugins/workflow-runner/plugin.js +3 -1
  20. package/plugins/workflow-runner/src/agentCommon.js +249 -51
  21. package/plugins/workflow-runner/src/dslManifest.js +72 -0
  22. package/plugins/workflow-runner/src/expressions.js +198 -15
  23. package/plugins/workflow-runner/src/index.js +40 -8
  24. package/plugins/workflow-runner/src/jsonPayload.js +1 -1
  25. package/plugins/workflow-runner/src/loader.js +286 -72
  26. package/plugins/workflow-runner/src/multimodal.js +37 -0
  27. package/plugins/workflow-runner/src/recovery.js +49 -39
  28. package/plugins/workflow-runner/src/runner.js +802 -287
  29. package/plugins/workflow-runner/src/stepExecutors/agent.js +157 -39
  30. package/plugins/workflow-runner/src/stepExecutors/assert.js +16 -3
  31. package/plugins/workflow-runner/src/stepExecutors/llm.js +60 -111
  32. package/plugins/workflow-runner/src/stepExecutors/skill.js +47 -47
  33. package/plugins/workflow-runner/src/stepExecutors/tool.js +76 -10
  34. package/plugins/workflow-runner/src/stepExecutors/verify.js +27 -10
  35. package/plugins/workflow-runner/src/taskIdentity.js +296 -0
  36. package/plugins/workflow-runner/src/types.js +19 -9
  37. package/plugins/workflow-runner/src/workflowState.js +516 -33
  38. package/skills/adversarial-review/SKILL.md +0 -1
  39. package/skills/ai-image/SKILL.md +89 -0
  40. package/skills/ai-image/scripts/generate.mjs +497 -0
  41. package/skills/ai-image/scripts/generate_from_plan.mjs +469 -0
  42. package/skills/ai-image/scripts/generate_from_plan_test.mjs +223 -0
  43. package/skills/ai-image/scripts/generate_test.mjs +74 -0
  44. package/skills/browser-automation/SKILL.md +47 -0
  45. package/skills/docx/SKILL.md +25 -3
  46. package/skills/docx/scripts/office/helpers/__pycache__/__init__.cpython-314.pyc +0 -0
  47. package/skills/docx/scripts/office/helpers/__pycache__/merge_runs.cpython-314.pyc +0 -0
  48. package/skills/docx/scripts/office/helpers/__pycache__/simplify_redlines.cpython-314.pyc +0 -0
  49. package/skills/docx/scripts/office/validators/__pycache__/__init__.cpython-314.pyc +0 -0
  50. package/skills/docx/scripts/office/validators/__pycache__/base.cpython-314.pyc +0 -0
  51. package/skills/docx/scripts/office/validators/__pycache__/docx.cpython-314.pyc +0 -0
  52. package/skills/docx/scripts/office/validators/__pycache__/pptx.cpython-314.pyc +0 -0
  53. package/skills/docx/scripts/office/validators/__pycache__/redlining.cpython-314.pyc +0 -0
  54. package/skills/docx/scripts/opc_check.py +253 -0
  55. package/skills/image-gen-openrouter/SKILL.md +10 -2
  56. package/skills/image-stats/SKILL.md +65 -0
  57. package/skills/image-stats/scripts/__pycache__/image_stats.cpython-314.pyc +0 -0
  58. package/skills/image-stats/scripts/__pycache__/image_stats_test.cpython-314.pyc +0 -0
  59. package/skills/image-stats/scripts/image_stats.py +368 -0
  60. package/skills/image-stats/scripts/image_stats_test.py +181 -0
  61. package/skills/pptx/SKILL.md +123 -95
  62. package/skills/pptx/design.md +82 -0
  63. package/skills/pptx/examples/README.md +29 -0
  64. package/skills/pptx/examples/hybrid_example.mjs +107 -0
  65. package/skills/pptx/examples/hybrid_example.pptx +0 -0
  66. package/skills/pptx/pptxgenjs.md +41 -0
  67. package/skills/pptx/scripts/deck_helpers.mjs +224 -0
  68. package/skills/pptx/scripts/layout_lint.py +293 -0
  69. package/skills/pptx/scripts/layout_lint_test.py +160 -0
  70. package/skills/pptx/scripts/opc_check.py +339 -0
  71. package/skills/pptx/scripts/svg_fallback.mjs +145 -0
  72. package/skills/pptx/svg.md +67 -0
  73. package/skills/tts-zh/SKILL.md +19 -2
  74. package/skills/ui-design/SKILL.md +158 -0
  75. package/skills/ui-design/claude_design.md +309 -0
  76. package/skills/ui-design/evals/evals.json +254 -0
  77. package/skills/ui-design/references/aesthetic-direction.md +83 -0
  78. package/skills/ui-design/references/claude-design-protocol.md +36 -0
  79. package/skills/ui-design/references/design-context.md +53 -0
  80. package/skills/ui-design/references/design-execution-playbook.md +82 -0
  81. package/skills/ui-design/references/export-pptx.md +124 -0
  82. package/skills/ui-design/references/layout-composition.md +654 -0
  83. package/skills/ui-design/references/preview-feedback.md +37 -0
  84. package/skills/ui-design/references/source-image-layout.md +189 -0
  85. package/skills/ui-design/references/starter-components.md +78 -0
  86. package/skills/ui-design/references/vi-aegis-vector.md +144 -0
  87. package/skills/ui-design/references/vi-amber-prism.md +133 -0
  88. package/skills/ui-design/references/vi-aqua-glass.md +200 -0
  89. package/skills/ui-design/references/vi-comfort-vision.md +147 -0
  90. package/skills/ui-design/references/vi-ember-prism.md +140 -0
  91. package/skills/ui-design/references/vi-nebula-console.md +151 -0
  92. package/skills/ui-design/references/vi-obsidian-optics.md +139 -0
  93. package/skills/ui-design/references/vi-obsidian-xui.md +143 -0
  94. package/skills/ui-design/references/vi-precision-horizon-dark.md +117 -0
  95. package/skills/ui-design/references/vi-precision-horizon.md +215 -0
  96. package/skills/ui-design/references/vi-solar-relay.md +130 -0
  97. package/skills/ui-design/references/vi-template-workflow.md +48 -0
  98. package/skills/ui-design/references/vi-verdant-grid.md +141 -0
  99. package/skills/ui-design/references/vi-violet-meridian.md +172 -0
  100. package/skills/ui-design/scripts/__pycache__/assemble_material.cpython-314.pyc +0 -0
  101. package/skills/ui-design/scripts/__pycache__/assemble_material_test.cpython-314.pyc +0 -0
  102. package/skills/ui-design/scripts/__pycache__/chart_sanity_check.cpython-314.pyc +0 -0
  103. package/skills/ui-design/scripts/__pycache__/check_language_policy.cpython-314.pyc +0 -0
  104. package/skills/ui-design/scripts/__pycache__/check_ui_artifact.cpython-314.pyc +0 -0
  105. package/skills/ui-design/scripts/__pycache__/check_ui_artifact_pptx_test.cpython-314.pyc +0 -0
  106. package/skills/ui-design/scripts/__pycache__/deck_pages_check.cpython-314.pyc +0 -0
  107. package/skills/ui-design/scripts/__pycache__/deck_pages_check_test.cpython-314.pyc +0 -0
  108. package/skills/ui-design/scripts/__pycache__/deck_visual_style_check.cpython-314.pyc +0 -0
  109. package/skills/ui-design/scripts/__pycache__/deck_visual_style_check_test.cpython-314.pyc +0 -0
  110. package/skills/ui-design/scripts/__pycache__/design_budget_check.cpython-314.pyc +0 -0
  111. package/skills/ui-design/scripts/__pycache__/design_budget_check_test.cpython-314.pyc +0 -0
  112. package/skills/ui-design/scripts/__pycache__/design_repair_hints.cpython-314.pyc +0 -0
  113. package/skills/ui-design/scripts/__pycache__/design_repair_hints_test.cpython-314.pyc +0 -0
  114. package/skills/ui-design/scripts/__pycache__/design_style_check.cpython-314.pyc +0 -0
  115. package/skills/ui-design/scripts/__pycache__/design_style_check_test.cpython-314.pyc +0 -0
  116. package/skills/ui-design/scripts/__pycache__/draft_coverage_check.cpython-314.pyc +0 -0
  117. package/skills/ui-design/scripts/__pycache__/extract_source_assets.cpython-314.pyc +0 -0
  118. package/skills/ui-design/scripts/__pycache__/extract_source_assets_test.cpython-314.pyc +0 -0
  119. package/skills/ui-design/scripts/__pycache__/generated_image_review_collect.cpython-314.pyc +0 -0
  120. package/skills/ui-design/scripts/__pycache__/generated_image_review_collect_test.cpython-314.pyc +0 -0
  121. package/skills/ui-design/scripts/__pycache__/image_plan_lint.cpython-314.pyc +0 -0
  122. package/skills/ui-design/scripts/__pycache__/image_plan_lint_test.cpython-314.pyc +0 -0
  123. package/skills/ui-design/scripts/__pycache__/image_prompt_rewrite.cpython-314.pyc +0 -0
  124. package/skills/ui-design/scripts/__pycache__/image_prompt_rewrite_test.cpython-314.pyc +0 -0
  125. package/skills/ui-design/scripts/__pycache__/layout_balance.cpython-314.pyc +0 -0
  126. package/skills/ui-design/scripts/__pycache__/layout_balance_test.cpython-314.pyc +0 -0
  127. package/skills/ui-design/scripts/__pycache__/normalize_design_json.cpython-314.pyc +0 -0
  128. package/skills/ui-design/scripts/__pycache__/normalize_design_json_test.cpython-314.pyc +0 -0
  129. package/skills/ui-design/scripts/__pycache__/plan_source_layout.cpython-314.pyc +0 -0
  130. package/skills/ui-design/scripts/__pycache__/plan_source_layout_test.cpython-314.pyc +0 -0
  131. package/skills/ui-design/scripts/__pycache__/resolve_source_hint.cpython-314.pyc +0 -0
  132. package/skills/ui-design/scripts/__pycache__/resolve_source_hint_test.cpython-314.pyc +0 -0
  133. package/skills/ui-design/scripts/__pycache__/resolve_source_input.cpython-314.pyc +0 -0
  134. package/skills/ui-design/scripts/__pycache__/resolve_source_input_test.cpython-314.pyc +0 -0
  135. package/skills/ui-design/scripts/__pycache__/scaffold_ui_artifact.cpython-314.pyc +0 -0
  136. package/skills/ui-design/scripts/__pycache__/source_usage_check.cpython-314.pyc +0 -0
  137. package/skills/ui-design/scripts/__pycache__/source_usage_check_test.cpython-314.pyc +0 -0
  138. package/skills/ui-design/scripts/__pycache__/text_readability_pixel.cpython-314.pyc +0 -0
  139. package/skills/ui-design/scripts/__pycache__/visual_quality_gate.cpython-314.pyc +0 -0
  140. package/skills/ui-design/scripts/__pycache__/visual_quality_gate_test.cpython-314.pyc +0 -0
  141. package/skills/ui-design/scripts/assemble_material.py +217 -0
  142. package/skills/ui-design/scripts/assemble_material_test.py +149 -0
  143. package/skills/ui-design/scripts/browser_check_ui_artifact.mjs +221 -0
  144. package/skills/ui-design/scripts/chart_sanity_check.py +261 -0
  145. package/skills/ui-design/scripts/chart_sanity_check_test.py +165 -0
  146. package/skills/ui-design/scripts/check_language_policy.py +351 -0
  147. package/skills/ui-design/scripts/check_ui_artifact.py +435 -0
  148. package/skills/ui-design/scripts/check_ui_artifact_pptx_test.py +251 -0
  149. package/skills/ui-design/scripts/deck_pages_check.py +158 -0
  150. package/skills/ui-design/scripts/deck_pages_check_test.py +134 -0
  151. package/skills/ui-design/scripts/deck_visual_style_check.py +767 -0
  152. package/skills/ui-design/scripts/deck_visual_style_check_test.py +713 -0
  153. package/skills/ui-design/scripts/design_budget_check.py +271 -0
  154. package/skills/ui-design/scripts/design_budget_check_test.py +183 -0
  155. package/skills/ui-design/scripts/design_repair_hints.py +162 -0
  156. package/skills/ui-design/scripts/design_repair_hints_test.py +54 -0
  157. package/skills/ui-design/scripts/design_style_check.py +397 -0
  158. package/skills/ui-design/scripts/design_style_check_test.py +233 -0
  159. package/skills/ui-design/scripts/draft_coverage_check.py +184 -0
  160. package/skills/ui-design/scripts/draft_coverage_check_test.py +131 -0
  161. package/skills/ui-design/scripts/export_pptx_from_html.mjs +2367 -0
  162. package/skills/ui-design/scripts/extract_source_assets.py +607 -0
  163. package/skills/ui-design/scripts/extract_source_assets_test.py +256 -0
  164. package/skills/ui-design/scripts/generated_image_review_collect.py +206 -0
  165. package/skills/ui-design/scripts/generated_image_review_collect_test.py +91 -0
  166. package/skills/ui-design/scripts/image_plan_lint.py +571 -0
  167. package/skills/ui-design/scripts/image_plan_lint_test.py +515 -0
  168. package/skills/ui-design/scripts/image_prompt_rewrite.py +713 -0
  169. package/skills/ui-design/scripts/image_prompt_rewrite_test.py +966 -0
  170. package/skills/ui-design/scripts/layout_balance.py +881 -0
  171. package/skills/ui-design/scripts/layout_balance_test.py +927 -0
  172. package/skills/ui-design/scripts/normalize_design_json.py +272 -0
  173. package/skills/ui-design/scripts/normalize_design_json_test.py +119 -0
  174. package/skills/ui-design/scripts/plan_source_layout.py +1450 -0
  175. package/skills/ui-design/scripts/plan_source_layout_test.py +1136 -0
  176. package/skills/ui-design/scripts/resolve_source_input.py +270 -0
  177. package/skills/ui-design/scripts/resolve_source_input_test.py +98 -0
  178. package/skills/ui-design/scripts/scaffold_ui_artifact.py +377 -0
  179. package/skills/ui-design/scripts/source_usage_check.py +581 -0
  180. package/skills/ui-design/scripts/source_usage_check_test.py +427 -0
  181. package/skills/ui-design/scripts/text_readability_pixel.py +340 -0
  182. package/skills/ui-design/scripts/text_readability_pixel_test.py +219 -0
  183. package/skills/ui-design/scripts/visual_quality_gate.py +301 -0
  184. package/skills/ui-design/scripts/visual_quality_gate_test.py +233 -0
  185. package/skills/ui-design/tests/e2e/prompts/deck.md +19 -0
  186. package/skills/ui-design/tests/e2e/prompts/webpage.md +17 -0
  187. package/skills/ui-design/tests/e2e/render_check.mjs +101 -0
  188. package/skills/ui-design/tests/e2e/rubric.json +54 -0
  189. package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/checks/browser-check.json +49 -0
  190. package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/checks/language-check.txt +12 -0
  191. package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/checks/static-check.txt +15 -0
  192. package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/outputs/index.html +837 -0
  193. package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/prompt.md +12 -0
  194. package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/review.md +21 -0
  195. package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/screenshots/desktop.png +0 -0
  196. package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/screenshots/mobile.png +0 -0
  197. package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/outputs/homepage.html +373 -0
  198. package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/outputs/platform.html +378 -0
  199. package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/prompt.md +13 -0
  200. package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/review.md +26 -0
  201. package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/screenshots/homepage/browser-check.json +49 -0
  202. package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/screenshots/homepage/desktop.png +0 -0
  203. package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/screenshots/homepage/mobile.png +0 -0
  204. package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/screenshots/platform/browser-check.json +49 -0
  205. package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/screenshots/platform/desktop.png +0 -0
  206. package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/screenshots/platform/mobile.png +0 -0
  207. package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-1/checks/static-check.txt +2 -0
  208. package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-1/outputs/index.html +656 -0
  209. package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-1/prompt.md +12 -0
  210. package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-1/render_check.mjs +67 -0
  211. package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-2/checks/static-check.txt +2 -0
  212. package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-2/outputs/index.html +587 -0
  213. package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-2/prompt.md +12 -0
  214. package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-2/review.md +36 -0
  215. package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/checks/browser-check.json +49 -0
  216. package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/checks/language-check.txt +8 -0
  217. package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/checks/static-check.txt +16 -0
  218. package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/outputs/index.html +739 -0
  219. package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/prompt.md +11 -0
  220. package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/review.md +22 -0
  221. package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/screenshots/desktop.png +0 -0
  222. package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/screenshots/mobile.png +0 -0
  223. package/skills/ui-design/tests/e2e/runs/comfort-vision-preview-1/checks/browser-check.json +52 -0
  224. package/skills/ui-design/tests/e2e/runs/comfort-vision-preview-1/outputs/index.html +641 -0
  225. package/skills/ui-design/tests/e2e/runs/comfort-vision-preview-1/screenshots/desktop.png +0 -0
  226. package/skills/ui-design/tests/e2e/runs/comfort-vision-preview-1/screenshots/mobile.png +0 -0
  227. package/skills/ui-design/tests/e2e/runs/ember-prism-red-preview-1/outputs/index.html +467 -0
  228. package/skills/ui-design/tests/e2e/runs/ember-prism-red-preview-1/screenshots/browser-check.json +49 -0
  229. package/skills/ui-design/tests/e2e/runs/ember-prism-red-preview-1/screenshots/desktop.png +0 -0
  230. package/skills/ui-design/tests/e2e/runs/ember-prism-red-preview-1/screenshots/mobile.png +0 -0
  231. package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/outputs/homepage.html +373 -0
  232. package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/outputs/platform.html +378 -0
  233. package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/prompt.md +13 -0
  234. package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/review.md +26 -0
  235. package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/screenshots/homepage/browser-check.json +49 -0
  236. package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/screenshots/homepage/desktop.png +0 -0
  237. package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/screenshots/homepage/mobile.png +0 -0
  238. package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/screenshots/platform/browser-check.json +49 -0
  239. package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/screenshots/platform/desktop.png +0 -0
  240. package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/screenshots/platform/mobile.png +0 -0
  241. package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/checks/browser-check.json +49 -0
  242. package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/checks/language-check.txt +4 -0
  243. package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/checks/static-check.txt +2 -0
  244. package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/execution_notes.md +10 -0
  245. package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/outputs/index.html +587 -0
  246. package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/prompt.md +14 -0
  247. package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/review.md +13 -0
  248. package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/screenshots/desktop.png +0 -0
  249. package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/screenshots/mobile.png +0 -0
  250. package/skills/ui-design/tests/e2e/runs/iteration-1/deck/checks/browser-check.json +24 -0
  251. package/skills/ui-design/tests/e2e/runs/iteration-1/deck/checks/static-check.txt +2 -0
  252. package/skills/ui-design/tests/e2e/runs/iteration-1/deck/execution_notes.md +21 -0
  253. package/skills/ui-design/tests/e2e/runs/iteration-1/deck/outputs/deck.html +451 -0
  254. package/skills/ui-design/tests/e2e/runs/iteration-1/deck/screenshots/slide-01.png +0 -0
  255. package/skills/ui-design/tests/e2e/runs/iteration-1/deck/screenshots/slide-02.png +0 -0
  256. package/skills/ui-design/tests/e2e/runs/iteration-1/review.md +79 -0
  257. package/skills/ui-design/tests/e2e/runs/iteration-1/webpage/checks/browser-check.json +26 -0
  258. package/skills/ui-design/tests/e2e/runs/iteration-1/webpage/checks/static-check.txt +2 -0
  259. package/skills/ui-design/tests/e2e/runs/iteration-1/webpage/execution_notes.md +20 -0
  260. package/skills/ui-design/tests/e2e/runs/iteration-1/webpage/outputs/index.html +534 -0
  261. package/skills/ui-design/tests/e2e/runs/iteration-1/webpage/screenshots/desktop.png +0 -0
  262. package/skills/ui-design/tests/e2e/runs/iteration-1/webpage/screenshots/mobile.png +0 -0
  263. package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/checks/browser-check.json +64 -0
  264. package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/checks/language-check.txt +7 -0
  265. package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/checks/quick-validate.txt +1 -0
  266. package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/checks/static-console.txt +2 -0
  267. package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/checks/static-homepage.txt +2 -0
  268. package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/outputs/console.html +600 -0
  269. package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/outputs/homepage.html +556 -0
  270. package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/prompt.md +29 -0
  271. package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/review.md +57 -0
  272. package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/screenshots/console-desktop.png +0 -0
  273. package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/screenshots/console-mobile.png +0 -0
  274. package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/screenshots/homepage-desktop.png +0 -0
  275. package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/screenshots/homepage-mobile.png +0 -0
  276. package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/checks/browser-check.json +33 -0
  277. package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/checks/language-check.txt +6 -0
  278. package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/checks/quick-validate.txt +1 -0
  279. package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/checks/static-check.txt +2 -0
  280. package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/outputs/index.html +682 -0
  281. package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/prompt.md +13 -0
  282. package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/review.md +59 -0
  283. package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/screenshots/desktop.png +0 -0
  284. package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/screenshots/mobile.png +0 -0
  285. package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/outputs/page-01.html +466 -0
  286. package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/outputs/page-02.html +433 -0
  287. package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/prompt.md +13 -0
  288. package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/screenshots/page-01/browser-check.json +49 -0
  289. package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/screenshots/page-01/desktop.png +0 -0
  290. package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/screenshots/page-01/mobile.png +0 -0
  291. package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/screenshots/page-02/browser-check.json +49 -0
  292. package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/screenshots/page-02/desktop.png +0 -0
  293. package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/screenshots/page-02/mobile.png +0 -0
  294. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/checks/browser-check.json +49 -0
  295. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/checks/language-check.txt +3 -0
  296. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/checks/static-check.txt +2 -0
  297. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/execution_notes.md +24 -0
  298. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/outputs/index.html +723 -0
  299. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/prompt.md +15 -0
  300. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/review.md +26 -0
  301. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/screenshots/desktop.png +0 -0
  302. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/screenshots/mobile.png +0 -0
  303. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/checks/browser-dark.json +49 -0
  304. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/checks/browser-light.json +49 -0
  305. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/checks/language-check.txt +11 -0
  306. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/checks/static-dark.txt +2 -0
  307. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/checks/static-light.txt +3 -0
  308. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/execution_notes.md +23 -0
  309. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/outputs/dark.html +392 -0
  310. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/outputs/light.html +476 -0
  311. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/prompt.md +23 -0
  312. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/review.md +41 -0
  313. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/screenshots/dark/desktop.png +0 -0
  314. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/screenshots/dark/mobile.png +0 -0
  315. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/screenshots/light/desktop.png +0 -0
  316. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/screenshots/light/mobile.png +0 -0
  317. package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/checks/browser-check.json +54 -0
  318. package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/checks/language-check.txt +5 -0
  319. package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/checks/quick-validate.txt +1 -0
  320. package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/checks/static-check.txt +2 -0
  321. package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/outputs/index.html +765 -0
  322. package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/prompt.md +15 -0
  323. package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/review.md +59 -0
  324. package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/screenshots/desktop.png +0 -0
  325. package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/screenshots/mobile.png +0 -0
  326. package/skills/ui-design/tests/e2e/runs/verdant-grid-preview-1/outputs/index.html +508 -0
  327. package/skills/ui-design/tests/e2e/runs/verdant-grid-preview-1/screenshots/browser-check.json +49 -0
  328. package/skills/ui-design/tests/e2e/runs/verdant-grid-preview-1/screenshots/desktop.png +0 -0
  329. package/skills/ui-design/tests/e2e/runs/verdant-grid-preview-1/screenshots/mobile.png +0 -0
  330. package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/checks/browser-check.json +54 -0
  331. package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/checks/language-check.txt +6 -0
  332. package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/checks/quick-validate.txt +1 -0
  333. package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/checks/static-check.txt +2 -0
  334. package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/outputs/index.html +788 -0
  335. package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/prompt.md +14 -0
  336. package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/review.md +60 -0
  337. package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/screenshots/desktop.png +0 -0
  338. package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/screenshots/mobile.png +0 -0
  339. package/skills/video-compose/SKILL.md +8 -1
  340. package/skills/web-crawler/SKILL.md +70 -0
  341. package/skills/web-crawler/scripts/crawl.mjs +538 -0
  342. package/skills/web-crawler/scripts/crawl.test.mjs +204 -0
  343. package/skills/xlsx/SKILL.md +12 -0
  344. package/skills/xlsx/scripts/opc_check.py +253 -0
  345. package/src/advisorState.js +22 -0
  346. package/src/askBridge.js +97 -3
  347. package/src/bootstrap/workingDir.js +12 -1
  348. package/src/cli/args.js +17 -1
  349. package/src/cli/configMenu.js +236 -0
  350. package/src/cli/configWizard.js +7 -5
  351. package/src/cli/print.js +37 -4
  352. package/src/cli/streamJson.js +77 -24
  353. package/src/cli/wizards/advisorWizard.js +147 -0
  354. package/src/cli/wizards/fieldForm.js +149 -0
  355. package/src/cli/wizards/imageWizard.js +60 -0
  356. package/src/cli/wizards/openRouterWizard.js +23 -0
  357. package/src/cli/wizards/providerPresets.js +95 -0
  358. package/src/cli/wizards/providerWizard.js +219 -0
  359. package/src/cli/wizards/searchWizard.js +23 -0
  360. package/src/cli/wizards/ttsWizard.js +34 -0
  361. package/src/config/configFile.js +441 -83
  362. package/src/config/configService.js +446 -0
  363. package/src/config.js +24 -64
  364. package/src/context/agentHome.js +9 -0
  365. package/src/context/archive.js +7 -2
  366. package/src/context/compact.js +8 -5
  367. package/src/context/contextLock.js +81 -0
  368. package/src/context/persistContext.js +30 -11
  369. package/src/context/reactiveCompact.js +4 -2
  370. package/src/context/recentDirs.js +21 -61
  371. package/src/context/sessionPath.js +97 -23
  372. package/src/context/sessionRegistry.js +303 -24
  373. package/src/context/tokenCounter.js +18 -0
  374. package/src/context/workspaceIndex.js +731 -0
  375. package/src/infra/verification.js +28 -15
  376. package/src/llm/client.js +394 -159
  377. package/src/llm/providers/anthropicFormat.js +241 -0
  378. package/src/llm/providers/openaiFormat.js +190 -0
  379. package/src/loop.js +219 -32
  380. package/src/main.js +61 -11
  381. package/src/messageQueue.js +97 -0
  382. package/src/multimodal.js +203 -0
  383. package/src/plugin-sdk.js +15 -0
  384. package/src/plugins/commandRouter.js +3 -0
  385. package/src/plugins/hookEngine.js +5 -1
  386. package/src/plugins/pluginLifecycle.js +28 -0
  387. package/src/plugins/pluginLoader.js +2 -1
  388. package/src/plugins/pluginRunner.js +49 -21
  389. package/src/plugins/transcript.js +4 -3
  390. package/src/prompts/pluginList.js +5 -5
  391. package/src/prompts/projectInstructions.js +3 -3
  392. package/src/prompts/promptAssembly.js +133 -144
  393. package/src/prompts/skillList.js +12 -22
  394. package/src/prompts/system.js +0 -1
  395. package/src/session/runAgentTurn.js +70 -0
  396. package/src/session/runTurn.js +41 -6
  397. package/src/toolGate.js +17 -0
  398. package/src/tools/advisor/advisor.js +379 -0
  399. package/src/tools/agent/agent.js +555 -0
  400. package/src/tools/agent/agentTypes.js +59 -0
  401. package/src/tools/agent/coordinator.js +93 -0
  402. package/src/tools/agent/worktree.js +270 -0
  403. package/src/tools/ask/ask.js +7 -2
  404. package/src/tools/bash/bash.js +112 -18
  405. package/src/tools/download/download.js +144 -0
  406. package/src/tools/edit/edit.js +1 -0
  407. package/src/tools/edit/multi-edit.js +1 -0
  408. package/src/tools/genimage/genimage.js +242 -0
  409. package/src/tools/genspeech/genspeech.js +67 -0
  410. package/src/tools/glob/glob.js +1 -0
  411. package/src/tools/grep/grep.js +3 -0
  412. package/src/tools/grep/rgPath.js +2 -0
  413. package/src/tools/index.js +25 -2
  414. package/src/tools/read/read.js +1 -0
  415. package/src/tools/shared/killTree.js +52 -0
  416. package/src/tools/toolProgressBridge.js +48 -0
  417. package/src/tools/webbrowser/agentBrowserPath.js +258 -0
  418. package/src/tools/webbrowser/browser.js +59 -42
  419. package/src/tools/webbrowser/browserControl.js +118 -0
  420. package/src/tools/webbrowser/browserDaemon.js +97 -0
  421. package/src/tools/webbrowser/browserService.js +27 -0
  422. package/src/tools/webbrowser/browserStream.js +119 -0
  423. package/src/tools/webbrowser/webbrowser.js +699 -130
  424. package/src/tools/webfetch/webfetch.js +1 -0
  425. package/src/tools/websearch/websearch.js +134 -51
  426. package/src/tools/write/write.js +1 -0
  427. package/src/ui/App.js +249 -22
  428. package/src/ui/AskQuestion.js +29 -10
  429. package/src/ui/InputBox.js +104 -12
  430. package/src/ui/LiveArea.js +112 -19
  431. package/src/ui/MessageList.js +100 -14
  432. package/src/ui/ModelPicker.js +56 -0
  433. package/src/ui/QueuedMessagesBanner.js +14 -0
  434. package/src/ui/Root.js +18 -10
  435. package/src/ui/SessionPicker.js +102 -0
  436. package/src/ui/StatusLine.js +13 -4
  437. package/src/ui/WorkspacePicker.js +55 -0
  438. package/src/ui/figures.js +44 -0
  439. package/src/ui/hooks/askSlot.js +82 -0
  440. package/src/ui/hooks/useChat.js +358 -64
  441. package/src/ui/hooks/usePasteHandler.js +11 -1
  442. package/src/ui/hooks/useTextBuffer.js +1 -3
  443. package/src/ui/liveViewport.js +5 -1
  444. package/src/ui/markdown.js +206 -0
  445. package/src/ui/textBuffer.js +0 -7
  446. package/src/ui/theme.js +32 -0
  447. package/src/utils/debugLog.js +0 -4
  448. package/src/utils/resourcePaths.js +2 -2
  449. package/src/utils/stripThink.js +50 -0
  450. package/src/web/browserBridge.js +447 -0
  451. package/src/web/protocol.js +19 -0
  452. package/workflows/adaptive-research.yaml +13 -5
  453. package/workflows/book-review-short.yaml +36 -10
  454. package/workflows/e2e-write-greet.yaml +6 -2
  455. package/workflows/illustrate.yaml +227 -0
  456. package/workflows/plan.yaml +460 -179
  457. package/workflows/ppt.yaml +1659 -0
  458. package/workflows/ralph-loop.yaml +199 -0
  459. package/workflows/schema.json +81 -23
  460. package/workflows/webppt.yaml +496 -0
  461. package/workflows/word.yaml +710 -0
  462. package/workflows/youtube-shorts.yaml +46 -15
  463. package/MINIMAL-TRACE.md +0 -77
  464. package/plugins/HOW-TO-WRITE-A-PLUGIN.md +0 -186
  465. package/plugins/ralph-wiggum/.claude-plugin/plugin.json +0 -9
  466. package/plugins/ralph-wiggum/README.md +0 -197
  467. package/plugins/ralph-wiggum/commands/cancel-ralph.md +0 -18
  468. package/plugins/ralph-wiggum/commands/help.md +0 -137
  469. package/plugins/ralph-wiggum/commands/ralph-loop.md +0 -85
  470. package/plugins/ralph-wiggum/hooks/hooks.json +0 -15
  471. package/plugins/ralph-wiggum/hooks/stop-hook.sh +0 -191
  472. package/plugins/ralph-wiggum/plugin.js +0 -280
  473. package/plugins/ralph-wiggum/src/goalState.js +0 -258
  474. package/plugins/ralph-wiggum/src/sentinels.js +0 -76
  475. package/plugins/ralph-wiggum/src/stopHookRunner.js +0 -104
  476. package/plugins/ralph-wiggum/src/verificationGate.js +0 -202
  477. package/plugins/workflow-runner/src/miniReAct.js +0 -223
  478. package/plugins/workflow-runner/src/voteHelpers.js +0 -110
  479. package/skills/config/SKILL.md +0 -123
  480. package/skills/frontend-design/LICENSE.txt +0 -177
  481. package/skills/frontend-design/SKILL.md +0 -42
  482. package/src/ui/ProgressPanel.js +0 -54
  483. package/src/ui/StreamingBlock.js +0 -11
  484. package/src/ui/ToolStatus.js +0 -11
@@ -0,0 +1,224 @@
1
+ /* eslint-disable */
2
+ // ============================================================================
3
+ // skills/pptx/scripts/deck_helpers.mjs
4
+ // ----------------------------------------------------------------------------
5
+ // 可复用的「原生 addShape 矢量原语」库(结构图路线)。import 即用,省得每次重写
6
+ // 并重新踩 PptxGenJS 的坑。这些图形是 **PowerPoint 原生对象**,天然每个独立可选中、
7
+ // 可改色、可移动、内部文字可重排 —— 比 SVG 还省事(连「转换为形状」都不用)。
8
+ //
9
+ // 用法(Node,不要 Bun —— 见 pptxgenjs.md 文首铁律):
10
+ // import PptxGenJS from 'pptxgenjs';
11
+ // import { drawCard, drawNode, drawArrow, connect, drawTitle, drawFooter, inkFor } from './deck_helpers.mjs';
12
+ // const pres = new PptxGenJS(); pres.layout = 'LAYOUT_WIDE';
13
+ // const s = pres.addSlide(); s.background = { color: '0F172A' };
14
+ // drawTitle(s, '§1', '架构全景', { bg: '0F172A' }); // 深底 → 标题自动取白字
15
+ // const a = { x: 1, y: 3, w: 2.5, h: 1.2 }, b = { x: 5, y: 3, w: 2.5, h: 1.2 };
16
+ // drawNode(s, a.x, a.y, a.w, a.h, '输入'); drawNode(s, b.x, b.y, b.w, b.h, '输出');
17
+ // connect(s, a, b); // 由两形状边框自动算端点,绝不残桩
18
+ //
19
+ // 说明:位置/尺寸默认值按 LAYOUT_WIDE(13.3" × 7.5")调好;其它 layout 自己传坐标。
20
+ // 颜色一律 6 位 hex、不带 '#'、不带 8 位透明度(透明度走 opacity/transparency 字段)。
21
+ //
22
+ // 内嵌的 PptxGenJS 踩坑防御(每条都曾真实损坏文件或产出难看页,别绕过):
23
+ // - 阴影/option 对象 **每次新建**:PptxGenJS 会 in-place 把值转成 EMU,复用同一对象损坏后续形状。
24
+ // - 颜色禁 '#' 前缀、禁 8 位 hex(assertColor 兜底)。
25
+ // - roundRect 不要叠矩形 accent 条当左边框(盖不住圆角);要精确对齐色条用 rect。
26
+ // - 标题下不画双下划线 accent line(AI 生成 PPT 的典型痕迹,用留白/底色代替)。
27
+ // - **文字对比**:drawTitle / drawNode / drawSectionBadge 会按背景断言可读(assertReadable),
28
+ // 暗字暗底直接抛错 —— 别绕过去手写不检查的 addText。不确定字色就用 inkFor(bg) 自动取。
29
+ // - **连线**:drawArrow 守卫最短长度(< 0.25" 抛错,杜绝残桩箭头);连两个形状一律用
30
+ // connect(from, to)(自动算边到边端点),别手填易飘/易残桩的坐标。
31
+ // ============================================================================
32
+
33
+ const MIN_CONNECTOR_LEN = 0.25; // 英寸:短于此基本是端点重合/算错的残桩箭头(AI PPT 典型缺陷)
34
+
35
+ function assertColor(c) {
36
+ if (typeof c === 'string' && (c.startsWith('#') || c.length === 8)) {
37
+ throw new Error(`bad color "${c}": 用 6 位 hex、不带 #;透明度用 opacity/transparency 字段`);
38
+ }
39
+ return c;
40
+ }
41
+
42
+ // ──────────────── 对比度原语(WCAG 2.1):把「强对比」从口号变成生成期断言 ────────────────
43
+
44
+ function hexToRgb(hex) {
45
+ const h = String(hex).replace(/^#/, '');
46
+ if (!/^[0-9a-fA-F]{6}$/.test(h)) throw new Error(`bad hex "${hex}": 需 6 位十六进制`);
47
+ return [0, 2, 4].map((i) => parseInt(h.slice(i, i + 2), 16));
48
+ }
49
+
50
+ // 相对亮度(WCAG 2.1):0(纯黑)~ 1(纯白)。
51
+ export function relLuminance(hex) {
52
+ const [r, g, b] = hexToRgb(hex)
53
+ .map((v) => v / 255)
54
+ .map((c) => (c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4));
55
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;
56
+ }
57
+
58
+ // 对比比(WCAG):1(同色,最差)~ 21(黑白,最佳)。
59
+ export function contrastRatio(a, b) {
60
+ const la = relLuminance(a);
61
+ const lb = relLuminance(b);
62
+ const hi = Math.max(la, lb);
63
+ const lo = Math.min(la, lb);
64
+ return (hi + 0.05) / (lo + 0.05);
65
+ }
66
+
67
+ // 给定背景,返回 dark / light 里与之对比更高的一个(自动选可读字色)。
68
+ export function inkFor(bg, { dark = '0F172A', light = 'FFFFFF' } = {}) {
69
+ return contrastRatio(dark, bg) >= contrastRatio(light, bg) ? dark : light;
70
+ }
71
+
72
+ // 对比不足直接抛错(生成期就炸,附自救提示):把「画不出不可读文字」变成硬约束。
73
+ export function assertReadable(fg, bg, { min = 4.5, label = '' } = {}) {
74
+ const r = contrastRatio(fg, bg);
75
+ if (r < min) {
76
+ throw new Error(
77
+ `文字对比度不足:字色 ${fg} / 底色 ${bg} = ${r.toFixed(2)}:1 < ${min}:1` +
78
+ `${label ? `(${label})` : ''}。用 inkFor(bg) 自动取可读字色,或换背景。`,
79
+ );
80
+ }
81
+ return r;
82
+ }
83
+
84
+ // 尽力从 slide 读已设置的背景色(标准 s.background = { color } 写法);读不到返回 undefined。
85
+ function readSlideBg(slide) {
86
+ try {
87
+ const b = slide && slide.background;
88
+ if (b && typeof b.color === 'string') return b.color;
89
+ const bk = slide && slide.bkgd;
90
+ if (bk && typeof bk.color === 'string') return bk.color;
91
+ } catch {
92
+ /* 内部结构因版本而异,读不到就算了:契约是显式传 bg */
93
+ }
94
+ return undefined;
95
+ }
96
+
97
+ // 阴影:⚠️ 每次返回新对象,绝不复用(PptxGenJS in-place mutate 会损坏第二个形状)。
98
+ export const makeShadow = (o = {}) => ({
99
+ type: 'outer', blur: 8, offset: 2, angle: 90, color: '000000', opacity: 0.12, ...o,
100
+ });
101
+
102
+ // 矩形(无圆角):用于需要精确对齐的标题底色/分隔条/色块。
103
+ export function drawRect(slide, x, y, w, h, { fill = '1E2761', line, lineWidth = 0, shadow = false } = {}) {
104
+ slide.addShape('rect', {
105
+ x, y, w, h,
106
+ fill: { color: assertColor(fill) },
107
+ ...(line ? { line: { color: assertColor(line), width: lineWidth } } : { line: { type: 'none' } }),
108
+ ...(shadow ? { shadow: makeShadow() } : {}),
109
+ });
110
+ }
111
+
112
+ // 圆角卡片:内容卡/分组容器。
113
+ export function drawCard(slide, x, y, w, h, { fill = 'F8FAFC', border = 'E2E8F0', borderWidth = 1, radius = 0.08, shadow = true } = {}) {
114
+ slide.addShape('roundRect', {
115
+ x, y, w, h,
116
+ fill: { color: assertColor(fill) },
117
+ line: { color: assertColor(border), width: borderWidth },
118
+ rectRadius: radius,
119
+ ...(shadow ? { shadow: makeShadow() } : {}),
120
+ });
121
+ }
122
+
123
+ // 架构图节点(圆角矩形/矩形/椭圆 + 居中文字)。kind ∈ round | rect | oval。
124
+ // 文字色与填充色对比不足直接抛错(节点字多为大字,按 AA 大字 3:1 把关)。
125
+ export function drawNode(slide, x, y, w, h, label, { kind = 'round', fill = '1E2761', textColor = 'FFFFFF', fontFace = 'Calibri', fontSize = 12, bold = true, radius = 0.06 } = {}) {
126
+ const shape = kind === 'oval' ? 'ellipse' : kind === 'rect' ? 'rect' : 'roundRect';
127
+ slide.addShape(shape, {
128
+ x, y, w, h,
129
+ fill: { color: assertColor(fill) },
130
+ line: { color: 'FFFFFF', width: 1 },
131
+ ...(shape === 'roundRect' ? { rectRadius: radius } : {}),
132
+ });
133
+ if (label) {
134
+ assertReadable(textColor, fill, { min: 3, label: `node "${String(label).replace(/\n/g, ' ')}"` });
135
+ slide.addText(label, { x, y, w, h, fontFace, fontSize, bold, color: assertColor(textColor), align: 'center', valign: 'middle', margin: 0 });
136
+ }
137
+ }
138
+
139
+ // 连线(带可选箭头)。支持任意方向(用 flipV 处理向上)。
140
+ // ⚠️ 守卫最短长度:端点几乎重合(< 0.25")时抛错,杜绝「残桩/无连接箭头」这一 AI PPT 典型缺陷。
141
+ // 要连两个形状请用 connect(slide, from, to)——由形状边框自动算端点,永不残桩、永不飘。
142
+ export function drawArrow(slide, x1, y1, x2, y2, { color = '94A3B8', width = 1.5, dashed = false, arrow = true } = {}) {
143
+ const dx = x2 - x1;
144
+ const dy = y2 - y1;
145
+ const len = Math.hypot(dx, dy);
146
+ if (len < MIN_CONNECTOR_LEN) {
147
+ throw new Error(
148
+ `连线过短:长度 ${len.toFixed(3)}" < ${MIN_CONNECTOR_LEN}"(端点 (${x1},${y1})→(${x2},${y2}) 几乎重合)。` +
149
+ '残桩/无连接箭头是 AI PPT 的典型缺陷;连两个形状请用 connect(slide, from, to)。',
150
+ );
151
+ }
152
+ const x = Math.min(x1, x2);
153
+ const y = Math.min(y1, y2);
154
+ const w = Math.abs(dx) || 0.001; // 垂直线给 PptxGenJS 一个极小正宽;总长已由 len 守卫保证
155
+ const h = Math.abs(dy) || 0.001;
156
+ slide.addShape('line', {
157
+ x, y, w, h,
158
+ flipV: y2 < y1,
159
+ line: { color: assertColor(color), width, ...(dashed ? { dashType: 'dash' } : {}), ...(arrow ? { endArrowType: 'triangle' } : {}) },
160
+ });
161
+ }
162
+
163
+ // 连接两个形状:传两个矩形 {x,y,w,h}(英寸),算「中心连线裁到各自边框」得到边到边端点再画箭头。
164
+ // → 端点永远贴住两个真实锚点,杜绝飘移/残桩。两矩形重叠时抛错(没有合理的可见连线)。
165
+ export function connect(slide, from, to, opts = {}) {
166
+ for (const [n, r] of [['from', from], ['to', to]]) {
167
+ if (!r || ['x', 'y', 'w', 'h'].some((k) => typeof r[k] !== 'number')) {
168
+ throw new Error(`connect(): ${n} 需为 {x,y,w,h} 数值矩形(英寸)`);
169
+ }
170
+ }
171
+ const overlap = !(
172
+ from.x + from.w <= to.x ||
173
+ to.x + to.w <= from.x ||
174
+ from.y + from.h <= to.y ||
175
+ to.y + to.h <= from.y
176
+ );
177
+ if (overlap) {
178
+ throw new Error('connect(): 两个形状重叠,无法画出有意义的连线(先检查布局是否叠加)。');
179
+ }
180
+ const center = (r) => ({ cx: r.x + r.w / 2, cy: r.y + r.h / 2 });
181
+ // 从矩形中心朝 (tx,ty) 方向射线与该矩形边框的交点。
182
+ const edge = (r, tx, ty) => {
183
+ const { cx, cy } = center(r);
184
+ const dx = tx - cx;
185
+ const dy = ty - cy;
186
+ const hw = r.w / 2;
187
+ const hh = r.h / 2;
188
+ const tdx = dx === 0 ? Infinity : hw / Math.abs(dx);
189
+ const tdy = dy === 0 ? Infinity : hh / Math.abs(dy);
190
+ const t = Math.min(tdx, tdy);
191
+ return { x: cx + dx * t, y: cy + dy * t };
192
+ };
193
+ const a = center(from);
194
+ const b = center(to);
195
+ const p1 = edge(from, b.cx, b.cy);
196
+ const p2 = edge(to, a.cx, a.cy);
197
+ drawArrow(slide, p1.x, p1.y, p2.x, p2.y, opts);
198
+ }
199
+
200
+ // 章节徽章(小色块 + 文字),放在标题左上。文字落在 slide 背景上,按背景把可读性把关。
201
+ export function drawSectionBadge(slide, x, y, label, { color = '00A896', textColor, fontFace = 'Consolas', fontSize = 14, bg } = {}) {
202
+ drawRect(slide, x, y, 0.35, 0.32, { fill: color });
203
+ const background = bg ?? readSlideBg(slide);
204
+ const ink = textColor ?? (background ? inkFor(background) : '0F172A');
205
+ if (background) assertReadable(ink, background, { min: 3, label: 'section badge label' });
206
+ slide.addText(label, { x: x + 0.4, y: y - 0.02, w: 4, h: 0.36, fontFace, fontSize, bold: true, color: assertColor(ink), valign: 'middle', margin: 0 });
207
+ }
208
+
209
+ // 标题栏(徽章 + 大标题)。⚠️ 不画标题下的双下划线。
210
+ // 传 bg(或 slide 已设 background)时:标题色默认按背景自动取可读色(inkFor),并断言对比 ≥3:1(大字)。
211
+ // 不传也读不到背景时:保持近黑默认、不断言(向后兼容;但深色页务必传 bg,否则暗字暗底看不清)。
212
+ export function drawTitle(slide, badge, title, { x = 0.5, badgeColor = '00A896', titleColor, titleSize = 28, fontFace = 'Consolas', w = 12.3, bg } = {}) {
213
+ const background = bg ?? readSlideBg(slide);
214
+ const ink = titleColor ?? (background ? inkFor(background) : '0F172A');
215
+ if (background) assertReadable(ink, background, { min: 3, label: 'title' });
216
+ drawSectionBadge(slide, x, 0.35, badge, { color: badgeColor, bg: background });
217
+ slide.addText(title, { x, y: 0.75, w, h: 0.7, fontFace, fontSize: titleSize, bold: true, color: assertColor(ink), valign: 'middle', margin: 0 });
218
+ }
219
+
220
+ // 页脚(左侧文档名 + 右侧页码)。次要文字,按设计可较弱,不强制对比断言。
221
+ export function drawFooter(slide, text, pageLabel, { y = 7.15, x = 0.5, leftW = 8, rightX = 11.3, color = '94A3B8', fontFace = 'Calibri' } = {}) {
222
+ if (text) slide.addText(text, { x, y, w: leftW, h: 0.25, fontFace, fontSize: 9, color: assertColor(color), align: 'left', valign: 'middle', margin: 0 });
223
+ if (pageLabel) slide.addText(pageLabel, { x: rightX, y, w: 1.5, h: 0.25, fontFace, fontSize: 9, color: assertColor(color), align: 'right', valign: 'middle', margin: 0 });
224
+ }
@@ -0,0 +1,293 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ layout_lint.py —— PPTX「布局/对比」确定性质量闸门(与 opc_check.py 互补)。
5
+
6
+ 为什么需要这个脚本?
7
+ ====================
8
+ opc_check.py 管「OPC 合规 = PowerPoint 能否干净打开」(硬阻断)。但合规的包仍可能
9
+ 「能打开却难看」:文字与背景对比过低看不清、形状互相叠加、极短/无连接的残桩箭头。
10
+ 这些缺陷此前只靠「soffice 截图 + 子 agent 眼检」的视觉 QA 抓——对**其他 agent / 弱模型**
11
+ 不可靠(会跳过、会看漏)。
12
+
13
+ 本脚本做**不依赖渲染、纯解析 OOXML** 的确定性检查:只读 slide xml 的坐标/颜色,把
14
+ 「可计算」的三类缺陷在产物上拦下,给弱模型一道绕不过的防呆门槛。它**不替代**视觉 QA
15
+ (主题色/跨形状层叠/文字截断等仍需眼睛),是其前置硬门槛。
16
+
17
+ 和 opc_check.py 一样:只用标准库(zipfile / xml.etree / math / re),忠实于最终消费者
18
+ (Office),不依赖任何宽容的高层库。
19
+
20
+ 检查项(任一命中 → 非零退出码 + 人话问题 + 修复提示)
21
+ ====================================================
22
+ A. 残桩/过短连线:连接符或 line 类形状长度 < 0.2"(端点重合/算错的残桩箭头,AI PPT 典型缺陷)。
23
+ B. 形状叠加:两个非背景、非包含、非连线形状的包围盒显著相交。
24
+ C. 低对比文字(限可靠场景):形状有显式 solidFill 且其文字 run 有显式颜色时,二者对比
25
+ 低于阈值(大字 3:1 / 正文 4.5:1,WCAG)。
26
+
27
+ 局限(诚实声明):不解析 theme/scheme 引用色,也不解析「文字浮于其它背景形状之上」的
28
+ 跨形状 z-order 层叠——那些由 deck_helpers 的 assertReadable / drawTitle(bg) 与视觉 QA
29
+ 覆盖。本脚本只抓「能确定、误报近零」的场景,避免像宽容库一样用噪声侵蚀信任。
30
+
31
+ 用法
32
+ ====
33
+ python layout_lint.py <file.pptx> # 校验,无缺陷退出 0,有缺陷退出 1
34
+ python layout_lint.py <file.pptx> --verbose # 额外打印 PASSED 明细
35
+ """
36
+
37
+ import argparse
38
+ import math
39
+ import re
40
+ import sys
41
+ import zipfile
42
+ import xml.etree.ElementTree as ET
43
+
44
+ EMU_PER_INCH = 914400.0
45
+
46
+ # OOXML 命名空间(presentationml / drawingml),固定不变。
47
+ P = "{http://schemas.openxmlformats.org/presentationml/2006/main}"
48
+ A = "{http://schemas.openxmlformats.org/drawingml/2006/main}"
49
+
50
+ # 判定「连线/连接符」用的 prstGeom 前缀(line 类原语)。
51
+ LINE_PREFIXES = ("straightConnector", "bentConnector", "curvedConnector")
52
+
53
+ # 阈值
54
+ MIN_CONNECTOR_IN = 0.2 # 短于此判残桩连线
55
+ OVERLAP_MIN_AREA = 0.02 # 叠加最小绝对面积(in²),压住浮点/贴边噪声
56
+ OVERLAP_MIN_FRAC = 0.10 # 叠加须 > 较小形状面积的 10%,才算「显著」
57
+ BIG_BG_FRAC = 0.80 # 面积 ≥ 画布 80% 视为满铺背景,不参与叠加判定
58
+
59
+
60
+ # ──────────────── 对比度(WCAG 2.1,与 deck_helpers.mjs 同一套公式) ────────────────
61
+
62
+ def _hex_to_rgb(h: str):
63
+ h = h.strip().lstrip("#")
64
+ if not re.fullmatch(r"[0-9a-fA-F]{6}", h):
65
+ raise ValueError(f"非 6 位 hex:{h}")
66
+ return tuple(int(h[i:i + 2], 16) for i in (0, 2, 4))
67
+
68
+
69
+ def _rel_luminance(h: str) -> float:
70
+ def chan(c: float) -> float:
71
+ c = c / 255.0
72
+ return c / 12.92 if c <= 0.03928 else ((c + 0.055) / 1.055) ** 2.4
73
+
74
+ r, g, b = _hex_to_rgb(h)
75
+ return 0.2126 * chan(r) + 0.7152 * chan(g) + 0.0722 * chan(b)
76
+
77
+
78
+ def _contrast(a: str, b: str) -> float:
79
+ la, lb = _rel_luminance(a), _rel_luminance(b)
80
+ hi, lo = max(la, lb), min(la, lb)
81
+ return (hi + 0.05) / (lo + 0.05)
82
+
83
+
84
+ # ──────────────── XML 提取小工具 ────────────────
85
+
86
+ def _local(el) -> str:
87
+ return el.tag.split("}")[-1]
88
+
89
+
90
+ def _xfrm(el):
91
+ """返回该形状自身的 (x, y, w, h)(英寸),取不到返回 None。只看自身 xfrm,不下钻子形状。"""
92
+ holder = el.find(P + "spPr")
93
+ if holder is None:
94
+ holder = el.find(P + "grpSpPr")
95
+ xf = holder.find(A + "xfrm") if holder is not None else None
96
+ if xf is None:
97
+ xf = el.find(P + "xfrm") # graphicFrame 用 p:xfrm
98
+ if xf is None:
99
+ return None
100
+ off = xf.find(A + "off")
101
+ ext = xf.find(A + "ext")
102
+ if off is None or ext is None:
103
+ return None
104
+ try:
105
+ return (
106
+ int(off.get("x")) / EMU_PER_INCH,
107
+ int(off.get("y")) / EMU_PER_INCH,
108
+ int(ext.get("cx")) / EMU_PER_INCH,
109
+ int(ext.get("cy")) / EMU_PER_INCH,
110
+ )
111
+ except (TypeError, ValueError):
112
+ return None
113
+
114
+
115
+ def _name(el) -> str:
116
+ c = el.find(".//" + P + "cNvPr")
117
+ if c is not None and c.get("name"):
118
+ return c.get("name")
119
+ return _local(el)
120
+
121
+
122
+ def _is_connector(el) -> bool:
123
+ if _local(el) == "cxnSp":
124
+ return True
125
+ if _local(el) == "sp":
126
+ g = el.find(P + "spPr/" + A + "prstGeom")
127
+ prst = g.get("prst") if g is not None else None
128
+ if prst == "line" or (prst and prst.startswith(LINE_PREFIXES)):
129
+ return True
130
+ return False
131
+
132
+
133
+ def _shape_fill(el):
134
+ sf = el.find(P + "spPr/" + A + "solidFill/" + A + "srgbClr")
135
+ return sf.get("val") if sf is not None and sf.get("val") else None
136
+
137
+
138
+ def _low_contrast_runs(el, fill):
139
+ """形状有显式 fill 时,逐文字 run 检查显式字色与 fill 的对比,返回不达标项。"""
140
+ out = []
141
+ for r in el.findall(".//" + A + "r"):
142
+ rpr = r.find(A + "rPr")
143
+ if rpr is None:
144
+ continue
145
+ clr = rpr.find(A + "solidFill/" + A + "srgbClr")
146
+ if clr is None or not clr.get("val"):
147
+ continue # 主题/方案色不在 v1 范围(局限已在文首声明)
148
+ run_color = clr.get("val")
149
+ try:
150
+ ratio = _contrast(run_color, fill)
151
+ except ValueError:
152
+ continue
153
+ try:
154
+ sz = int(rpr.get("sz")) if rpr.get("sz") else 0
155
+ except ValueError:
156
+ sz = 0
157
+ bold = rpr.get("b") in ("1", "true")
158
+ large = sz >= 1800 or (sz >= 1400 and bold) # WCAG 大字:≥18pt 或 ≥14pt 粗体
159
+ min_ratio = 3.0 if large else 4.5
160
+ if ratio < min_ratio:
161
+ t = r.find(A + "t")
162
+ snippet = (t.text or "").strip()[:20] if t is not None else ""
163
+ out.append((run_color, fill, ratio, min_ratio, snippet))
164
+ return out
165
+
166
+
167
+ def check_layout(path: str, verbose: bool = False) -> list:
168
+ """对 pptx 做布局/对比检查,返回问题列表(空 = 无可计算缺陷)。"""
169
+ problems = []
170
+
171
+ if not zipfile.is_zipfile(path):
172
+ return [f"不是合法的 zip/OOXML 包:{path}"]
173
+
174
+ with zipfile.ZipFile(path, "r") as zf:
175
+ names = zf.namelist()
176
+
177
+ # 画布尺寸(取不到则按 LAYOUT_WIDE 13.333"×7.5" 兜底)。
178
+ slide_w, slide_h = 13.333, 7.5
179
+ if "ppt/presentation.xml" in names:
180
+ try:
181
+ pres = ET.fromstring(zf.read("ppt/presentation.xml"))
182
+ sz = pres.find(P + "sldSz")
183
+ if sz is not None and sz.get("cx") and sz.get("cy"):
184
+ slide_w = int(sz.get("cx")) / EMU_PER_INCH
185
+ slide_h = int(sz.get("cy")) / EMU_PER_INCH
186
+ except (ET.ParseError, ValueError):
187
+ pass
188
+ slide_area = slide_w * slide_h
189
+
190
+ slide_names = sorted(
191
+ (n for n in names if re.fullmatch(r"ppt/slides/slide\d+\.xml", n)),
192
+ key=lambda n: int(re.search(r"(\d+)", n.rsplit("/", 1)[-1]).group(1)),
193
+ )
194
+
195
+ for sn in slide_names:
196
+ try:
197
+ root = ET.fromstring(zf.read(sn))
198
+ except ET.ParseError:
199
+ continue # 良构由 opc_check 负责,这里跳过
200
+ tree = root.find(P + "cSld/" + P + "spTree")
201
+ if tree is None:
202
+ continue
203
+ label = sn.rsplit("/", 1)[-1]
204
+ rects = [] # 非连线、非满铺背景形状的 (x, y, w, h, name)
205
+
206
+ for el in list(tree):
207
+ if _local(el) not in ("sp", "cxnSp", "pic", "graphicFrame", "grpSp"):
208
+ continue
209
+ box = _xfrm(el)
210
+
211
+ # ── A. 残桩/过短连线 ──
212
+ if _is_connector(el):
213
+ if box is not None:
214
+ length = math.hypot(box[2], box[3])
215
+ if length < MIN_CONNECTOR_IN:
216
+ problems.append(
217
+ f'{label}: 残桩/过短连线「{_name(el)}」长度 {length:.3f}" '
218
+ f'< {MIN_CONNECTOR_IN}"(端点几乎重合,疑似无连接的残桩箭头)'
219
+ )
220
+ continue # 连线不参与叠加判定(穿过形状属正常)
221
+
222
+ # ── C. 低对比文字(仅 sp,限显式色对) ──
223
+ if _local(el) == "sp":
224
+ fill = _shape_fill(el)
225
+ if fill:
226
+ for rc, fc, ratio, minr, snippet in _low_contrast_runs(el, fill):
227
+ tip = f"「{snippet}…」" if snippet else ""
228
+ problems.append(
229
+ f"{label}: 低对比文字{tip}字色 {rc} / 底色 {fc} = "
230
+ f"{ratio:.2f}:1 < {minr}:1(看不清;改字色或底色,用 inkFor(bg))"
231
+ )
232
+
233
+ # ── B. 收集叠加候选 rect ──
234
+ if box is not None:
235
+ x, y, w, h = box
236
+ if w * h >= BIG_BG_FRAC * slide_area:
237
+ continue # 满铺背景,不参与叠加
238
+ rects.append((x, y, w, h, _name(el)))
239
+
240
+ # ── B. 两两包围盒比对 ──
241
+ for i in range(len(rects)):
242
+ ax, ay, aw, ah, an = rects[i]
243
+ for j in range(i + 1, len(rects)):
244
+ bx, by, bw, bh, bn = rects[j]
245
+ ix, iy = max(ax, bx), max(ay, by)
246
+ ix2, iy2 = min(ax + aw, bx + bw), min(ay + ah, by + bh)
247
+ if ix2 <= ix or iy2 <= iy:
248
+ continue # 不相交
249
+ # 包含关系 = 正常(如卡片内文字),跳过
250
+ a_in_b = ax >= bx and ay >= by and ax + aw <= bx + bw and ay + ah <= by + bh
251
+ b_in_a = bx >= ax and by >= ay and bx + bw <= ax + aw and by + bh <= ay + ah
252
+ if a_in_b or b_in_a:
253
+ continue
254
+ inter = (ix2 - ix) * (iy2 - iy)
255
+ smaller = min(aw * ah, bw * bh)
256
+ if inter > OVERLAP_MIN_AREA and inter > OVERLAP_MIN_FRAC * smaller:
257
+ problems.append(
258
+ f'{label}: 形状叠加「{an}」×「{bn}」重叠 {inter:.2f} in²'
259
+ f"(约占较小形状 {inter / smaller * 100:.0f}%;拉开间距 ≥0.3\")"
260
+ )
261
+
262
+ if verbose and not problems:
263
+ print("PASSED 布局/对比检查:无残桩连线 / 无显著叠加 / 无低对比文字")
264
+
265
+ return problems
266
+
267
+
268
+ def main() -> int:
269
+ parser = argparse.ArgumentParser(
270
+ description="PPTX 布局/对比 确定性质量闸门(与 opc_check.py 互补,仅依赖标准库)"
271
+ )
272
+ parser.add_argument("file", help="要校验的 .pptx 文件")
273
+ parser.add_argument("-v", "--verbose", action="store_true", help="打印 PASSED 明细")
274
+ args = parser.parse_args()
275
+
276
+ problems = check_layout(args.file, verbose=args.verbose)
277
+ if problems:
278
+ print(f"布局/对比检查 FAILED —— {args.file} 存在 {len(problems)} 处问题:")
279
+ for p in problems:
280
+ print(" - " + p)
281
+ print(
282
+ "提示:对比用 deck_helpers 的 inkFor(bg)/assertReadable;"
283
+ "连线用 connect(from, to);叠加拉开间距 ≥0.3\"。"
284
+ "(本检查不替代视觉 QA。)"
285
+ )
286
+ return 1
287
+
288
+ print(f"布局/对比检查 PASSED —— {args.file} 无可计算的布局/对比缺陷(视觉 QA 仍需进行)。")
289
+ return 0
290
+
291
+
292
+ if __name__ == "__main__":
293
+ sys.exit(main())
@@ -0,0 +1,160 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ """
4
+ layout_lint_test.py —— layout_lint.py 的回归锚(stdlib unittest,仿 opc_check 测试风格)。
5
+
6
+ 手搓最小 OOXML(只含 presentation.xml + 一张 slide)分别命中 A/B/C 三类缺陷,
7
+ 外加一个「干净例」与一个「卡内文字(包含关系)不应误报」例,断言标记/通过。
8
+ 不依赖 PptxGenJS / python-pptx,只用标准库 zip 出最小包喂给 check_layout。
9
+
10
+ 运行:python skills/pptx/scripts/layout_lint_test.py
11
+ """
12
+
13
+ import os
14
+ import sys
15
+ import tempfile
16
+ import unittest
17
+ import zipfile
18
+
19
+ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
20
+ from layout_lint import check_layout # noqa: E402
21
+
22
+ EMU = 914400 # 每英寸
23
+
24
+
25
+ def emu(inches):
26
+ return int(round(inches * EMU))
27
+
28
+
29
+ PRESENTATION = (
30
+ '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
31
+ '<p:presentation xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" '
32
+ 'xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">'
33
+ '<p:sldSz cx="12192000" cy="6858000" type="screen16x9"/>'
34
+ '</p:presentation>'
35
+ )
36
+
37
+
38
+ def filled_text_sp(x, y, w, h, fill, text_color, text="文字", sz=2800, bold=True, name="Box"):
39
+ """带显式 solidFill + 显式字色文字 run 的矩形 sp。"""
40
+ bold_attr = ' b="1"' if bold else "" # 别在 f-string 表达式里写反斜杠(Py<3.12 报错)
41
+ return (
42
+ f'<p:sp><p:nvSpPr><p:cNvPr id="2" name="{name}"/><p:cNvSpPr/><p:nvPr/></p:nvSpPr>'
43
+ f'<p:spPr><a:xfrm><a:off x="{emu(x)}" y="{emu(y)}"/>'
44
+ f'<a:ext cx="{emu(w)}" cy="{emu(h)}"/></a:xfrm>'
45
+ f'<a:prstGeom prst="rect"><a:avLst/></a:prstGeom>'
46
+ f'<a:solidFill><a:srgbClr val="{fill}"/></a:solidFill></p:spPr>'
47
+ f'<p:txBody><a:bodyPr/><a:p><a:r>'
48
+ f'<a:rPr lang="zh-CN" sz="{sz}"{bold_attr}>'
49
+ f'<a:solidFill><a:srgbClr val="{text_color}"/></a:solidFill></a:rPr>'
50
+ f'<a:t>{text}</a:t></a:r></a:p></p:txBody></p:sp>'
51
+ )
52
+
53
+
54
+ def plain_rect_sp(x, y, w, h, name="Plain"):
55
+ """无填充、无文字的矩形(纯叠加候选)。"""
56
+ return (
57
+ f'<p:sp><p:nvSpPr><p:cNvPr id="9" name="{name}"/><p:cNvSpPr/><p:nvPr/></p:nvSpPr>'
58
+ f'<p:spPr><a:xfrm><a:off x="{emu(x)}" y="{emu(y)}"/>'
59
+ f'<a:ext cx="{emu(w)}" cy="{emu(h)}"/></a:xfrm>'
60
+ f'<a:prstGeom prst="rect"><a:avLst/></a:prstGeom></p:spPr>'
61
+ f'<p:txBody><a:bodyPr/><a:p/></p:txBody></p:sp>'
62
+ )
63
+
64
+
65
+ def connector(x, y, w, h, name="Conn"):
66
+ return (
67
+ f'<p:cxnSp><p:nvCxnSpPr><p:cNvPr id="5" name="{name}"/><p:cNvCxnSpPr/><p:nvPr/></p:nvCxnSpPr>'
68
+ f'<p:spPr><a:xfrm><a:off x="{emu(x)}" y="{emu(y)}"/>'
69
+ f'<a:ext cx="{emu(w)}" cy="{emu(h)}"/></a:xfrm>'
70
+ f'<a:prstGeom prst="straightConnector1"><a:avLst/></a:prstGeom></p:spPr></p:cxnSp>'
71
+ )
72
+
73
+
74
+ def slide_xml(*shapes):
75
+ body = "".join(shapes)
76
+ return (
77
+ '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
78
+ '<p:sld xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main" '
79
+ 'xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">'
80
+ f'<p:cSld><p:spTree>{body}</p:spTree></p:cSld></p:sld>'
81
+ )
82
+
83
+
84
+ def build_pptx(slide_body):
85
+ fd, path = tempfile.mkstemp(suffix=".pptx")
86
+ os.close(fd)
87
+ with zipfile.ZipFile(path, "w", zipfile.ZIP_DEFLATED) as z:
88
+ z.writestr("ppt/presentation.xml", PRESENTATION)
89
+ z.writestr("ppt/slides/slide1.xml", slide_body)
90
+ return path
91
+
92
+
93
+ class LayoutLintTest(unittest.TestCase):
94
+ def setUp(self):
95
+ self._paths = []
96
+
97
+ def tearDown(self):
98
+ for p in self._paths:
99
+ try:
100
+ os.remove(p)
101
+ except OSError:
102
+ pass
103
+
104
+ def _run(self, slide_body):
105
+ path = build_pptx(slide_body)
106
+ self._paths.append(path)
107
+ return check_layout(path)
108
+
109
+ def test_clean_deck_passes(self):
110
+ # 两个不重叠、高对比的填充框 + 一条正常长度连线 → 零问题。
111
+ problems = self._run(
112
+ slide_xml(
113
+ filled_text_sp(1, 1, 3, 1.2, "F8FAFC", "0F172A", name="A"), # 深字浅底
114
+ filled_text_sp(6, 1, 3, 1.2, "1E2761", "FFFFFF", name="B"), # 白字深底
115
+ connector(4.1, 1.6, 1.8, 0.0, name="A→B"), # 1.8" 长,正常
116
+ )
117
+ )
118
+ self.assertEqual(problems, [], f"干净例不应报问题:{problems}")
119
+
120
+ def test_short_connector_flagged(self):
121
+ problems = self._run(slide_xml(connector(2, 2, 0.05, 0.0, name="Stub")))
122
+ self.assertTrue(any("残桩" in p or "过短连线" in p for p in problems), problems)
123
+
124
+ def test_overlap_flagged(self):
125
+ # A=(1,1,3,3) 与 B=(3,3,3,3) 重叠 1in²,互不包含 → 标记。
126
+ problems = self._run(
127
+ slide_xml(plain_rect_sp(1, 1, 3, 3, name="A"), plain_rect_sp(3, 3, 3, 3, name="B"))
128
+ )
129
+ self.assertTrue(any("叠加" in p for p in problems), problems)
130
+
131
+ def test_low_contrast_flagged(self):
132
+ # 深底(1E2761) + 深字(0F172A) ≈ 1.3:1 < 3 → 标记。
133
+ problems = self._run(
134
+ slide_xml(filled_text_sp(1, 1, 4, 1.5, "1E2761", "0F172A", text="看不清的标题"))
135
+ )
136
+ self.assertTrue(any("低对比" in p for p in problems), problems)
137
+
138
+ def test_containment_not_flagged_as_overlap(self):
139
+ # 小文字框完全落在大卡片内(= 卡内文字),不应被当成叠加。
140
+ problems = self._run(
141
+ slide_xml(
142
+ plain_rect_sp(1, 1, 5, 3, name="Card"),
143
+ filled_text_sp(1.3, 1.3, 3, 1, "F8FAFC", "0F172A", name="Label"),
144
+ )
145
+ )
146
+ self.assertFalse(any("叠加" in p for p in problems), problems)
147
+
148
+ def test_full_bleed_background_not_overlap(self):
149
+ # 满铺背景(0,0,13.333,7.5) 不参与叠加,即便上面压着内容框也不报叠加。
150
+ problems = self._run(
151
+ slide_xml(
152
+ plain_rect_sp(0, 0, 13.333, 7.5, name="BG"),
153
+ filled_text_sp(1, 1, 4, 1.2, "F8FAFC", "0F172A", name="Content"),
154
+ )
155
+ )
156
+ self.assertFalse(any("叠加" in p for p in problems), problems)
157
+
158
+
159
+ if __name__ == "__main__":
160
+ unittest.main(verbosity=2)