minimal-agent 0.8.2 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -12
- package/package.json +34 -1
- package/plugins/cron-runner/.claude-plugin/plugin.json +5 -0
- package/plugins/cron-runner/commands/cron.md +26 -0
- package/plugins/cron-runner/commands/crons.md +7 -0
- package/plugins/cron-runner/plugin.js +34 -0
- package/plugins/cron-runner/src/commands.js +348 -0
- package/plugins/cron-runner/src/cronTime.js +148 -0
- package/plugins/cron-runner/src/lock.js +68 -0
- package/plugins/cron-runner/src/runs.js +89 -0
- package/plugins/cron-runner/src/scheduleEngine.js +72 -0
- package/plugins/cron-runner/src/scheduler.js +355 -0
- package/plugins/cron-runner/src/schema.js +140 -0
- package/plugins/cron-runner/src/service.js +167 -0
- package/plugins/cron-runner/src/store.js +298 -0
- package/plugins/cron-runner/src/types.js +1 -0
- package/plugins/workflow-runner/commands/workflow.md +4 -4
- package/plugins/workflow-runner/commands/workflows.md +1 -1
- package/plugins/workflow-runner/plugin.js +3 -1
- package/plugins/workflow-runner/src/agentCommon.js +249 -51
- package/plugins/workflow-runner/src/dslManifest.js +72 -0
- package/plugins/workflow-runner/src/expressions.js +198 -15
- package/plugins/workflow-runner/src/index.js +40 -8
- package/plugins/workflow-runner/src/jsonPayload.js +1 -1
- package/plugins/workflow-runner/src/loader.js +286 -72
- package/plugins/workflow-runner/src/multimodal.js +37 -0
- package/plugins/workflow-runner/src/recovery.js +49 -39
- package/plugins/workflow-runner/src/runner.js +802 -287
- package/plugins/workflow-runner/src/stepExecutors/agent.js +157 -39
- package/plugins/workflow-runner/src/stepExecutors/assert.js +16 -3
- package/plugins/workflow-runner/src/stepExecutors/llm.js +60 -111
- package/plugins/workflow-runner/src/stepExecutors/skill.js +47 -47
- package/plugins/workflow-runner/src/stepExecutors/tool.js +76 -10
- package/plugins/workflow-runner/src/stepExecutors/verify.js +27 -10
- package/plugins/workflow-runner/src/taskIdentity.js +296 -0
- package/plugins/workflow-runner/src/types.js +19 -9
- package/plugins/workflow-runner/src/workflowState.js +516 -33
- package/skills/adversarial-review/SKILL.md +0 -1
- package/skills/ai-image/SKILL.md +89 -0
- package/skills/ai-image/scripts/generate.mjs +497 -0
- package/skills/ai-image/scripts/generate_from_plan.mjs +469 -0
- package/skills/ai-image/scripts/generate_from_plan_test.mjs +223 -0
- package/skills/ai-image/scripts/generate_test.mjs +74 -0
- package/skills/browser-automation/SKILL.md +47 -0
- package/skills/docx/SKILL.md +25 -3
- package/skills/docx/scripts/office/helpers/__pycache__/__init__.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/helpers/__pycache__/merge_runs.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/helpers/__pycache__/simplify_redlines.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/validators/__pycache__/__init__.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/validators/__pycache__/base.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/validators/__pycache__/docx.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/validators/__pycache__/pptx.cpython-314.pyc +0 -0
- package/skills/docx/scripts/office/validators/__pycache__/redlining.cpython-314.pyc +0 -0
- package/skills/docx/scripts/opc_check.py +253 -0
- package/skills/image-gen-openrouter/SKILL.md +10 -2
- package/skills/image-stats/SKILL.md +65 -0
- package/skills/image-stats/scripts/__pycache__/image_stats.cpython-314.pyc +0 -0
- package/skills/image-stats/scripts/__pycache__/image_stats_test.cpython-314.pyc +0 -0
- package/skills/image-stats/scripts/image_stats.py +368 -0
- package/skills/image-stats/scripts/image_stats_test.py +181 -0
- package/skills/pptx/SKILL.md +123 -95
- package/skills/pptx/design.md +82 -0
- package/skills/pptx/examples/README.md +29 -0
- package/skills/pptx/examples/hybrid_example.mjs +107 -0
- package/skills/pptx/examples/hybrid_example.pptx +0 -0
- package/skills/pptx/pptxgenjs.md +41 -0
- package/skills/pptx/scripts/deck_helpers.mjs +224 -0
- package/skills/pptx/scripts/layout_lint.py +293 -0
- package/skills/pptx/scripts/layout_lint_test.py +160 -0
- package/skills/pptx/scripts/opc_check.py +339 -0
- package/skills/pptx/scripts/svg_fallback.mjs +145 -0
- package/skills/pptx/svg.md +67 -0
- package/skills/tts-zh/SKILL.md +19 -2
- package/skills/ui-design/SKILL.md +158 -0
- package/skills/ui-design/claude_design.md +309 -0
- package/skills/ui-design/evals/evals.json +254 -0
- package/skills/ui-design/references/aesthetic-direction.md +83 -0
- package/skills/ui-design/references/claude-design-protocol.md +36 -0
- package/skills/ui-design/references/design-context.md +53 -0
- package/skills/ui-design/references/design-execution-playbook.md +82 -0
- package/skills/ui-design/references/export-pptx.md +124 -0
- package/skills/ui-design/references/layout-composition.md +654 -0
- package/skills/ui-design/references/preview-feedback.md +37 -0
- package/skills/ui-design/references/source-image-layout.md +189 -0
- package/skills/ui-design/references/starter-components.md +78 -0
- package/skills/ui-design/references/vi-aegis-vector.md +144 -0
- package/skills/ui-design/references/vi-amber-prism.md +133 -0
- package/skills/ui-design/references/vi-aqua-glass.md +200 -0
- package/skills/ui-design/references/vi-comfort-vision.md +147 -0
- package/skills/ui-design/references/vi-ember-prism.md +140 -0
- package/skills/ui-design/references/vi-nebula-console.md +151 -0
- package/skills/ui-design/references/vi-obsidian-optics.md +139 -0
- package/skills/ui-design/references/vi-obsidian-xui.md +143 -0
- package/skills/ui-design/references/vi-precision-horizon-dark.md +117 -0
- package/skills/ui-design/references/vi-precision-horizon.md +215 -0
- package/skills/ui-design/references/vi-solar-relay.md +130 -0
- package/skills/ui-design/references/vi-template-workflow.md +48 -0
- package/skills/ui-design/references/vi-verdant-grid.md +141 -0
- package/skills/ui-design/references/vi-violet-meridian.md +172 -0
- package/skills/ui-design/scripts/__pycache__/assemble_material.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/assemble_material_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/chart_sanity_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/check_language_policy.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/check_ui_artifact.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/check_ui_artifact_pptx_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/deck_pages_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/deck_pages_check_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/deck_visual_style_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/deck_visual_style_check_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/design_budget_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/design_budget_check_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/design_repair_hints.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/design_repair_hints_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/design_style_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/design_style_check_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/draft_coverage_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/extract_source_assets.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/extract_source_assets_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/generated_image_review_collect.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/generated_image_review_collect_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/image_plan_lint.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/image_plan_lint_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/image_prompt_rewrite.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/image_prompt_rewrite_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/layout_balance.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/layout_balance_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/normalize_design_json.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/normalize_design_json_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/plan_source_layout.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/plan_source_layout_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/resolve_source_hint.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/resolve_source_hint_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/resolve_source_input.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/resolve_source_input_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/scaffold_ui_artifact.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/source_usage_check.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/source_usage_check_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/text_readability_pixel.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/visual_quality_gate.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/__pycache__/visual_quality_gate_test.cpython-314.pyc +0 -0
- package/skills/ui-design/scripts/assemble_material.py +217 -0
- package/skills/ui-design/scripts/assemble_material_test.py +149 -0
- package/skills/ui-design/scripts/browser_check_ui_artifact.mjs +221 -0
- package/skills/ui-design/scripts/chart_sanity_check.py +261 -0
- package/skills/ui-design/scripts/chart_sanity_check_test.py +165 -0
- package/skills/ui-design/scripts/check_language_policy.py +351 -0
- package/skills/ui-design/scripts/check_ui_artifact.py +435 -0
- package/skills/ui-design/scripts/check_ui_artifact_pptx_test.py +251 -0
- package/skills/ui-design/scripts/deck_pages_check.py +158 -0
- package/skills/ui-design/scripts/deck_pages_check_test.py +134 -0
- package/skills/ui-design/scripts/deck_visual_style_check.py +767 -0
- package/skills/ui-design/scripts/deck_visual_style_check_test.py +713 -0
- package/skills/ui-design/scripts/design_budget_check.py +271 -0
- package/skills/ui-design/scripts/design_budget_check_test.py +183 -0
- package/skills/ui-design/scripts/design_repair_hints.py +162 -0
- package/skills/ui-design/scripts/design_repair_hints_test.py +54 -0
- package/skills/ui-design/scripts/design_style_check.py +397 -0
- package/skills/ui-design/scripts/design_style_check_test.py +233 -0
- package/skills/ui-design/scripts/draft_coverage_check.py +184 -0
- package/skills/ui-design/scripts/draft_coverage_check_test.py +131 -0
- package/skills/ui-design/scripts/export_pptx_from_html.mjs +2367 -0
- package/skills/ui-design/scripts/extract_source_assets.py +607 -0
- package/skills/ui-design/scripts/extract_source_assets_test.py +256 -0
- package/skills/ui-design/scripts/generated_image_review_collect.py +206 -0
- package/skills/ui-design/scripts/generated_image_review_collect_test.py +91 -0
- package/skills/ui-design/scripts/image_plan_lint.py +571 -0
- package/skills/ui-design/scripts/image_plan_lint_test.py +515 -0
- package/skills/ui-design/scripts/image_prompt_rewrite.py +713 -0
- package/skills/ui-design/scripts/image_prompt_rewrite_test.py +966 -0
- package/skills/ui-design/scripts/layout_balance.py +881 -0
- package/skills/ui-design/scripts/layout_balance_test.py +927 -0
- package/skills/ui-design/scripts/normalize_design_json.py +272 -0
- package/skills/ui-design/scripts/normalize_design_json_test.py +119 -0
- package/skills/ui-design/scripts/plan_source_layout.py +1450 -0
- package/skills/ui-design/scripts/plan_source_layout_test.py +1136 -0
- package/skills/ui-design/scripts/resolve_source_input.py +270 -0
- package/skills/ui-design/scripts/resolve_source_input_test.py +98 -0
- package/skills/ui-design/scripts/scaffold_ui_artifact.py +377 -0
- package/skills/ui-design/scripts/source_usage_check.py +581 -0
- package/skills/ui-design/scripts/source_usage_check_test.py +427 -0
- package/skills/ui-design/scripts/text_readability_pixel.py +340 -0
- package/skills/ui-design/scripts/text_readability_pixel_test.py +219 -0
- package/skills/ui-design/scripts/visual_quality_gate.py +301 -0
- package/skills/ui-design/scripts/visual_quality_gate_test.py +233 -0
- package/skills/ui-design/tests/e2e/prompts/deck.md +19 -0
- package/skills/ui-design/tests/e2e/prompts/webpage.md +17 -0
- package/skills/ui-design/tests/e2e/render_check.mjs +101 -0
- package/skills/ui-design/tests/e2e/rubric.json +54 -0
- package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/checks/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/checks/language-check.txt +12 -0
- package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/checks/static-check.txt +15 -0
- package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/outputs/index.html +837 -0
- package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/prompt.md +12 -0
- package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/review.md +21 -0
- package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/screenshots/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/outputs/homepage.html +373 -0
- package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/outputs/platform.html +378 -0
- package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/prompt.md +13 -0
- package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/review.md +26 -0
- package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/screenshots/homepage/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/screenshots/homepage/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/screenshots/homepage/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/screenshots/platform/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/screenshots/platform/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/screenshots/platform/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-1/checks/static-check.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-1/outputs/index.html +656 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-1/prompt.md +12 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-1/render_check.mjs +67 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-2/checks/static-check.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-2/outputs/index.html +587 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-2/prompt.md +12 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-2/review.md +36 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/checks/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/checks/language-check.txt +8 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/checks/static-check.txt +16 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/outputs/index.html +739 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/prompt.md +11 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/review.md +22 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/screenshots/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/comfort-vision-preview-1/checks/browser-check.json +52 -0
- package/skills/ui-design/tests/e2e/runs/comfort-vision-preview-1/outputs/index.html +641 -0
- package/skills/ui-design/tests/e2e/runs/comfort-vision-preview-1/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/comfort-vision-preview-1/screenshots/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-red-preview-1/outputs/index.html +467 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-red-preview-1/screenshots/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-red-preview-1/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-red-preview-1/screenshots/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/outputs/homepage.html +373 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/outputs/platform.html +378 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/prompt.md +13 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/review.md +26 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/screenshots/homepage/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/screenshots/homepage/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/screenshots/homepage/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/screenshots/platform/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/screenshots/platform/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/screenshots/platform/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/checks/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/checks/language-check.txt +4 -0
- package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/checks/static-check.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/execution_notes.md +10 -0
- package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/outputs/index.html +587 -0
- package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/prompt.md +14 -0
- package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/review.md +13 -0
- package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/screenshots/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/deck/checks/browser-check.json +24 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/deck/checks/static-check.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/deck/execution_notes.md +21 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/deck/outputs/deck.html +451 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/deck/screenshots/slide-01.png +0 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/deck/screenshots/slide-02.png +0 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/review.md +79 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/webpage/checks/browser-check.json +26 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/webpage/checks/static-check.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/webpage/execution_notes.md +20 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/webpage/outputs/index.html +534 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/webpage/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/iteration-1/webpage/screenshots/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/checks/browser-check.json +64 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/checks/language-check.txt +7 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/checks/quick-validate.txt +1 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/checks/static-console.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/checks/static-homepage.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/outputs/console.html +600 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/outputs/homepage.html +556 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/prompt.md +29 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/review.md +57 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/screenshots/console-desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/screenshots/console-mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/screenshots/homepage-desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/screenshots/homepage-mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/checks/browser-check.json +33 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/checks/language-check.txt +6 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/checks/quick-validate.txt +1 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/checks/static-check.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/outputs/index.html +682 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/prompt.md +13 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/review.md +59 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/screenshots/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/outputs/page-01.html +466 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/outputs/page-02.html +433 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/prompt.md +13 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/screenshots/page-01/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/screenshots/page-01/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/screenshots/page-01/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/screenshots/page-02/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/screenshots/page-02/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/screenshots/page-02/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/checks/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/checks/language-check.txt +3 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/checks/static-check.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/execution_notes.md +24 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/outputs/index.html +723 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/prompt.md +15 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/review.md +26 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/screenshots/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/checks/browser-dark.json +49 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/checks/browser-light.json +49 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/checks/language-check.txt +11 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/checks/static-dark.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/checks/static-light.txt +3 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/execution_notes.md +23 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/outputs/dark.html +392 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/outputs/light.html +476 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/prompt.md +23 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/review.md +41 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/screenshots/dark/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/screenshots/dark/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/screenshots/light/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/screenshots/light/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/checks/browser-check.json +54 -0
- package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/checks/language-check.txt +5 -0
- package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/checks/quick-validate.txt +1 -0
- package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/checks/static-check.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/outputs/index.html +765 -0
- package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/prompt.md +15 -0
- package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/review.md +59 -0
- package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/screenshots/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/verdant-grid-preview-1/outputs/index.html +508 -0
- package/skills/ui-design/tests/e2e/runs/verdant-grid-preview-1/screenshots/browser-check.json +49 -0
- package/skills/ui-design/tests/e2e/runs/verdant-grid-preview-1/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/verdant-grid-preview-1/screenshots/mobile.png +0 -0
- package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/checks/browser-check.json +54 -0
- package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/checks/language-check.txt +6 -0
- package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/checks/quick-validate.txt +1 -0
- package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/checks/static-check.txt +2 -0
- package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/outputs/index.html +788 -0
- package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/prompt.md +14 -0
- package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/review.md +60 -0
- package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/screenshots/desktop.png +0 -0
- package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/screenshots/mobile.png +0 -0
- package/skills/video-compose/SKILL.md +8 -1
- package/skills/web-crawler/SKILL.md +70 -0
- package/skills/web-crawler/scripts/crawl.mjs +538 -0
- package/skills/web-crawler/scripts/crawl.test.mjs +204 -0
- package/skills/xlsx/SKILL.md +12 -0
- package/skills/xlsx/scripts/opc_check.py +253 -0
- package/src/advisorState.js +22 -0
- package/src/askBridge.js +97 -3
- package/src/bootstrap/workingDir.js +12 -1
- package/src/cli/args.js +17 -1
- package/src/cli/configMenu.js +236 -0
- package/src/cli/configWizard.js +7 -5
- package/src/cli/print.js +37 -4
- package/src/cli/streamJson.js +77 -24
- package/src/cli/wizards/advisorWizard.js +147 -0
- package/src/cli/wizards/fieldForm.js +149 -0
- package/src/cli/wizards/imageWizard.js +60 -0
- package/src/cli/wizards/openRouterWizard.js +23 -0
- package/src/cli/wizards/providerPresets.js +95 -0
- package/src/cli/wizards/providerWizard.js +219 -0
- package/src/cli/wizards/searchWizard.js +23 -0
- package/src/cli/wizards/ttsWizard.js +34 -0
- package/src/config/configFile.js +441 -83
- package/src/config/configService.js +446 -0
- package/src/config.js +24 -64
- package/src/context/agentHome.js +9 -0
- package/src/context/archive.js +7 -2
- package/src/context/compact.js +8 -5
- package/src/context/contextLock.js +81 -0
- package/src/context/persistContext.js +30 -11
- package/src/context/reactiveCompact.js +4 -2
- package/src/context/recentDirs.js +21 -61
- package/src/context/sessionPath.js +97 -23
- package/src/context/sessionRegistry.js +303 -24
- package/src/context/tokenCounter.js +18 -0
- package/src/context/workspaceIndex.js +731 -0
- package/src/infra/verification.js +28 -15
- package/src/llm/client.js +394 -159
- package/src/llm/providers/anthropicFormat.js +241 -0
- package/src/llm/providers/openaiFormat.js +190 -0
- package/src/loop.js +219 -32
- package/src/main.js +61 -11
- package/src/messageQueue.js +97 -0
- package/src/multimodal.js +203 -0
- package/src/plugin-sdk.js +15 -0
- package/src/plugins/commandRouter.js +3 -0
- package/src/plugins/hookEngine.js +5 -1
- package/src/plugins/pluginLifecycle.js +28 -0
- package/src/plugins/pluginLoader.js +2 -1
- package/src/plugins/pluginRunner.js +49 -21
- package/src/plugins/transcript.js +4 -3
- package/src/prompts/pluginList.js +5 -5
- package/src/prompts/projectInstructions.js +3 -3
- package/src/prompts/promptAssembly.js +133 -144
- package/src/prompts/skillList.js +12 -22
- package/src/prompts/system.js +0 -1
- package/src/session/runAgentTurn.js +70 -0
- package/src/session/runTurn.js +41 -6
- package/src/toolGate.js +17 -0
- package/src/tools/advisor/advisor.js +379 -0
- package/src/tools/agent/agent.js +555 -0
- package/src/tools/agent/agentTypes.js +59 -0
- package/src/tools/agent/coordinator.js +93 -0
- package/src/tools/agent/worktree.js +270 -0
- package/src/tools/ask/ask.js +7 -2
- package/src/tools/bash/bash.js +112 -18
- package/src/tools/download/download.js +144 -0
- package/src/tools/edit/edit.js +1 -0
- package/src/tools/edit/multi-edit.js +1 -0
- package/src/tools/genimage/genimage.js +242 -0
- package/src/tools/genspeech/genspeech.js +67 -0
- package/src/tools/glob/glob.js +1 -0
- package/src/tools/grep/grep.js +3 -0
- package/src/tools/grep/rgPath.js +2 -0
- package/src/tools/index.js +25 -2
- package/src/tools/read/read.js +1 -0
- package/src/tools/shared/killTree.js +52 -0
- package/src/tools/toolProgressBridge.js +48 -0
- package/src/tools/webbrowser/agentBrowserPath.js +258 -0
- package/src/tools/webbrowser/browser.js +59 -42
- package/src/tools/webbrowser/browserControl.js +118 -0
- package/src/tools/webbrowser/browserDaemon.js +97 -0
- package/src/tools/webbrowser/browserService.js +27 -0
- package/src/tools/webbrowser/browserStream.js +119 -0
- package/src/tools/webbrowser/webbrowser.js +699 -130
- package/src/tools/webfetch/webfetch.js +1 -0
- package/src/tools/websearch/websearch.js +134 -51
- package/src/tools/write/write.js +1 -0
- package/src/ui/App.js +249 -22
- package/src/ui/AskQuestion.js +29 -10
- package/src/ui/InputBox.js +104 -12
- package/src/ui/LiveArea.js +112 -19
- package/src/ui/MessageList.js +100 -14
- package/src/ui/ModelPicker.js +56 -0
- package/src/ui/QueuedMessagesBanner.js +14 -0
- package/src/ui/Root.js +18 -10
- package/src/ui/SessionPicker.js +102 -0
- package/src/ui/StatusLine.js +13 -4
- package/src/ui/WorkspacePicker.js +55 -0
- package/src/ui/figures.js +44 -0
- package/src/ui/hooks/askSlot.js +82 -0
- package/src/ui/hooks/useChat.js +358 -64
- package/src/ui/hooks/usePasteHandler.js +11 -1
- package/src/ui/hooks/useTextBuffer.js +1 -3
- package/src/ui/liveViewport.js +5 -1
- package/src/ui/markdown.js +206 -0
- package/src/ui/textBuffer.js +0 -7
- package/src/ui/theme.js +32 -0
- package/src/utils/debugLog.js +0 -4
- package/src/utils/resourcePaths.js +2 -2
- package/src/utils/stripThink.js +50 -0
- package/src/web/browserBridge.js +447 -0
- package/src/web/protocol.js +19 -0
- package/workflows/adaptive-research.yaml +13 -5
- package/workflows/book-review-short.yaml +36 -10
- package/workflows/e2e-write-greet.yaml +6 -2
- package/workflows/illustrate.yaml +227 -0
- package/workflows/plan.yaml +460 -179
- package/workflows/ppt.yaml +1659 -0
- package/workflows/ralph-loop.yaml +199 -0
- package/workflows/schema.json +81 -23
- package/workflows/webppt.yaml +496 -0
- package/workflows/word.yaml +710 -0
- package/workflows/youtube-shorts.yaml +46 -15
- package/MINIMAL-TRACE.md +0 -77
- package/plugins/HOW-TO-WRITE-A-PLUGIN.md +0 -186
- package/plugins/ralph-wiggum/.claude-plugin/plugin.json +0 -9
- package/plugins/ralph-wiggum/README.md +0 -197
- package/plugins/ralph-wiggum/commands/cancel-ralph.md +0 -18
- package/plugins/ralph-wiggum/commands/help.md +0 -137
- package/plugins/ralph-wiggum/commands/ralph-loop.md +0 -85
- package/plugins/ralph-wiggum/hooks/hooks.json +0 -15
- package/plugins/ralph-wiggum/hooks/stop-hook.sh +0 -191
- package/plugins/ralph-wiggum/plugin.js +0 -280
- package/plugins/ralph-wiggum/src/goalState.js +0 -258
- package/plugins/ralph-wiggum/src/sentinels.js +0 -76
- package/plugins/ralph-wiggum/src/stopHookRunner.js +0 -104
- package/plugins/ralph-wiggum/src/verificationGate.js +0 -202
- package/plugins/workflow-runner/src/miniReAct.js +0 -223
- package/plugins/workflow-runner/src/voteHelpers.js +0 -110
- package/skills/config/SKILL.md +0 -123
- package/skills/frontend-design/LICENSE.txt +0 -177
- package/skills/frontend-design/SKILL.md +0 -42
- package/src/ui/ProgressPanel.js +0 -54
- package/src/ui/StreamingBlock.js +0 -11
- package/src/ui/ToolStatus.js +0 -11
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* generate_from_plan.mjs —— 按 img_plan.json 确定性生成 PPT 配图。
|
|
4
|
+
*
|
|
5
|
+
* 输入 plan 条目:
|
|
6
|
+
* {file, mode:"text-to-image", aspect, prompt}
|
|
7
|
+
* {file, mode:"image-to-image", source_file, aspect, prompt}
|
|
8
|
+
*
|
|
9
|
+
* 该脚本只负责循环、校验、调用 generate.mjs;真正请求体组装仍在 generate.mjs。
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { access, copyFile, mkdir, readFile, stat, writeFile } from 'node:fs/promises';
|
|
13
|
+
import { dirname, isAbsolute, relative, resolve } from 'node:path';
|
|
14
|
+
import { spawn } from 'node:child_process';
|
|
15
|
+
import { fileURLToPath } from 'node:url';
|
|
16
|
+
import { deflateSync } from 'node:zlib';
|
|
17
|
+
|
|
18
|
+
const generateScript = fileURLToPath(new URL('./generate.mjs', import.meta.url));
|
|
19
|
+
|
|
20
|
+
function parseArgs(argv) {
|
|
21
|
+
const out = {};
|
|
22
|
+
const keys = new Set([
|
|
23
|
+
'plan',
|
|
24
|
+
'assets',
|
|
25
|
+
'timeout-ms',
|
|
26
|
+
'size',
|
|
27
|
+
'model',
|
|
28
|
+
'dry-run',
|
|
29
|
+
'dry-run-request',
|
|
30
|
+
'wall-budget-ms',
|
|
31
|
+
'retry-degraded-report',
|
|
32
|
+
'max-rounds',
|
|
33
|
+
'concurrency',
|
|
34
|
+
]);
|
|
35
|
+
for (let i = 0; i < argv.length; i++) {
|
|
36
|
+
const tok = argv[i];
|
|
37
|
+
if (!tok.startsWith('--')) continue;
|
|
38
|
+
const body = tok.slice(2);
|
|
39
|
+
const eq = body.indexOf('=');
|
|
40
|
+
let key;
|
|
41
|
+
let val;
|
|
42
|
+
if (eq !== -1) {
|
|
43
|
+
key = body.slice(0, eq);
|
|
44
|
+
val = body.slice(eq + 1);
|
|
45
|
+
} else {
|
|
46
|
+
key = body;
|
|
47
|
+
val = argv[i + 1] && !argv[i + 1].startsWith('--') ? argv[++i] : '';
|
|
48
|
+
}
|
|
49
|
+
if (keys.has(key)) out[key] = val;
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function err(msg) {
|
|
55
|
+
process.stderr.write(`${msg}\n`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function isUrlOrData(value) {
|
|
59
|
+
return /^https?:\/\//i.test(value || '') || String(value || '').startsWith('data:image/');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function resolveUnder(baseDir, value, label) {
|
|
63
|
+
if (!value) throw new Error(`${label} 不能为空`);
|
|
64
|
+
if (isAbsolute(value)) return value;
|
|
65
|
+
const absBase = resolve(baseDir);
|
|
66
|
+
const abs = resolve(absBase, value);
|
|
67
|
+
// 跨平台包含判定:用 path.relative,**不要**硬编码分隔符。
|
|
68
|
+
// 旧逻辑 `abs.startsWith(`${absBase}/`)` 用正斜杠,但 Windows 上 path.resolve 产出反斜杠 `\`,
|
|
69
|
+
// 于是 assets 下任何子文件(enhanced_src_1.jpg / img_2.png)都被误判「跳出 assets 目录」而整批失败。
|
|
70
|
+
// relative(base, abs) 在 abs 越界时以 `..` 开头、跨盘符时返回绝对路径——据此判定,三平台一致。
|
|
71
|
+
const rel = relative(absBase, abs);
|
|
72
|
+
if (rel.startsWith('..') || isAbsolute(rel)) {
|
|
73
|
+
throw new Error(`${label} 不能跳出 assets 目录:${value}`);
|
|
74
|
+
}
|
|
75
|
+
return abs;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function exists(path) {
|
|
79
|
+
try {
|
|
80
|
+
await access(path);
|
|
81
|
+
return true;
|
|
82
|
+
} catch {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function timeoutMs(args) {
|
|
88
|
+
const v = Number(args['timeout-ms']);
|
|
89
|
+
return Number.isFinite(v) && v > 0 ? Math.floor(v) : 600_000;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function validateItem(item, index) {
|
|
93
|
+
if (!item || typeof item !== 'object' || Array.isArray(item)) {
|
|
94
|
+
throw new Error(`img_plan[${index}] 必须是对象`);
|
|
95
|
+
}
|
|
96
|
+
const mode = item.mode || 'text-to-image';
|
|
97
|
+
if (mode !== 'text-to-image' && mode !== 'image-to-image') {
|
|
98
|
+
throw new Error(`img_plan[${index}].mode 非法:${mode}`);
|
|
99
|
+
}
|
|
100
|
+
if (typeof item.file !== 'string' || !item.file.trim()) {
|
|
101
|
+
throw new Error(`img_plan[${index}].file 必填`);
|
|
102
|
+
}
|
|
103
|
+
if (typeof item.prompt !== 'string' || !item.prompt.trim()) {
|
|
104
|
+
throw new Error(`img_plan[${index}].prompt 必填`);
|
|
105
|
+
}
|
|
106
|
+
if (mode === 'image-to-image' && (typeof item.source_file !== 'string' || !item.source_file.trim())) {
|
|
107
|
+
throw new Error(`img_plan[${index}] 为 image-to-image 时 source_file 必填`);
|
|
108
|
+
}
|
|
109
|
+
return mode;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function commandForItem(item, mode, assetsDir, args) {
|
|
113
|
+
const outPath = resolveUnder(assetsDir, item.file, `img_plan.file(${item.file})`);
|
|
114
|
+
const cmd = [
|
|
115
|
+
generateScript,
|
|
116
|
+
'--prompt',
|
|
117
|
+
item.prompt,
|
|
118
|
+
'--out',
|
|
119
|
+
outPath,
|
|
120
|
+
'--size',
|
|
121
|
+
args.size || '1K',
|
|
122
|
+
];
|
|
123
|
+
if (item.aspect) cmd.push('--aspect', String(item.aspect));
|
|
124
|
+
if (args.model) cmd.push('--model', args.model);
|
|
125
|
+
if (mode === 'image-to-image') {
|
|
126
|
+
const src = isUrlOrData(item.source_file)
|
|
127
|
+
? item.source_file
|
|
128
|
+
: resolveUnder(assetsDir, item.source_file, `img_plan.source_file(${item.source_file})`);
|
|
129
|
+
cmd.push('--input-image', src);
|
|
130
|
+
}
|
|
131
|
+
if (args['dry-run-request'] !== undefined) cmd.push('--dry-run-request');
|
|
132
|
+
return { cmd, outPath };
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async function filterRetryPlan(plan, reportPath) {
|
|
136
|
+
if (!reportPath) return { plan, retryOf: null };
|
|
137
|
+
let report;
|
|
138
|
+
try {
|
|
139
|
+
report = JSON.parse(await readFile(reportPath, 'utf8'));
|
|
140
|
+
} catch (e) {
|
|
141
|
+
throw new Error(`读取 retry-degraded-report 失败:${e?.message ?? e}`);
|
|
142
|
+
}
|
|
143
|
+
const degraded = Array.isArray(report?.degraded) ? report.degraded : [];
|
|
144
|
+
const files = new Set(degraded.map((item) => item?.file).filter(Boolean));
|
|
145
|
+
return {
|
|
146
|
+
plan: plan.filter((item) => files.has(item?.file)),
|
|
147
|
+
retryOf: reportPath,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// ── 降级兜底:让「期望的图片文件永远存在」,AI 配图失败也绝不让 deck 坏图、绝不报错 ──
|
|
152
|
+
// CRC32(PNG chunk 校验,避免依赖 zlib.crc32 的 Node 版本差异)。
|
|
153
|
+
const _CRC_TABLE = (() => {
|
|
154
|
+
const t = new Uint32Array(256);
|
|
155
|
+
for (let n = 0; n < 256; n++) {
|
|
156
|
+
let c = n;
|
|
157
|
+
for (let k = 0; k < 8; k++) c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
|
|
158
|
+
t[n] = c >>> 0;
|
|
159
|
+
}
|
|
160
|
+
return t;
|
|
161
|
+
})();
|
|
162
|
+
function crc32(buf) {
|
|
163
|
+
let c = 0xffffffff;
|
|
164
|
+
for (let i = 0; i < buf.length; i++) c = _CRC_TABLE[(c ^ buf[i]) & 0xff] ^ (c >>> 8);
|
|
165
|
+
return (c ^ 0xffffffff) >>> 0;
|
|
166
|
+
}
|
|
167
|
+
function pngChunk(type, data) {
|
|
168
|
+
const len = Buffer.alloc(4);
|
|
169
|
+
len.writeUInt32BE(data.length, 0);
|
|
170
|
+
const body = Buffer.concat([Buffer.from(type, 'ascii'), data]);
|
|
171
|
+
const crc = Buffer.alloc(4);
|
|
172
|
+
crc.writeUInt32BE(crc32(body), 0);
|
|
173
|
+
return Buffer.concat([len, body, crc]);
|
|
174
|
+
}
|
|
175
|
+
function dimsForAspect(aspect) {
|
|
176
|
+
const m = String(aspect || '16:9').match(/^(\d+)\s*[:x×]\s*(\d+)$/);
|
|
177
|
+
let aw = 16;
|
|
178
|
+
let ah = 9;
|
|
179
|
+
if (m) {
|
|
180
|
+
aw = Number(m[1]) || 16;
|
|
181
|
+
ah = Number(m[2]) || 9;
|
|
182
|
+
}
|
|
183
|
+
const base = 1024;
|
|
184
|
+
return aw >= ah
|
|
185
|
+
? [base, Math.max(64, Math.round((base * ah) / aw))]
|
|
186
|
+
: [Math.max(64, Math.round((base * aw) / ah)), base];
|
|
187
|
+
}
|
|
188
|
+
// 写一张确定性深色竖向渐变 PNG(纯 node:zlib,无第三方依赖、绿色版安全)作 AI 图兜底背景。
|
|
189
|
+
async function writeGradientPng(outPath, aspect) {
|
|
190
|
+
const [w, h] = dimsForAspect(aspect);
|
|
191
|
+
const top = [30, 41, 59]; // 深蓝灰
|
|
192
|
+
const bot = [8, 11, 18]; // 近黑
|
|
193
|
+
const raw = Buffer.alloc(h * (1 + w * 3));
|
|
194
|
+
for (let y = 0; y < h; y++) {
|
|
195
|
+
const rowStart = y * (1 + w * 3);
|
|
196
|
+
raw[rowStart] = 0; // filter: none
|
|
197
|
+
const tt = h === 1 ? 0 : y / (h - 1);
|
|
198
|
+
const r = Math.round(top[0] + (bot[0] - top[0]) * tt);
|
|
199
|
+
const g = Math.round(top[1] + (bot[1] - top[1]) * tt);
|
|
200
|
+
const b = Math.round(top[2] + (bot[2] - top[2]) * tt);
|
|
201
|
+
for (let x = 0; x < w; x++) {
|
|
202
|
+
const p = rowStart + 1 + x * 3;
|
|
203
|
+
raw[p] = r;
|
|
204
|
+
raw[p + 1] = g;
|
|
205
|
+
raw[p + 2] = b;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
const ihdr = Buffer.alloc(13);
|
|
209
|
+
ihdr.writeUInt32BE(w, 0);
|
|
210
|
+
ihdr.writeUInt32BE(h, 4);
|
|
211
|
+
ihdr[8] = 8; // bit depth
|
|
212
|
+
ihdr[9] = 2; // color type: RGB
|
|
213
|
+
const png = Buffer.concat([
|
|
214
|
+
Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]),
|
|
215
|
+
pngChunk('IHDR', ihdr),
|
|
216
|
+
pngChunk('IDAT', deflateSync(raw)),
|
|
217
|
+
pngChunk('IEND', Buffer.alloc(0)),
|
|
218
|
+
]);
|
|
219
|
+
await writeFile(outPath, png);
|
|
220
|
+
}
|
|
221
|
+
// 单张图生成失败 → 写降级占位资产(图生图退回原图、文生图/无原图退渐变),永不抛。
|
|
222
|
+
async function degradeFallback(item, mode, outPath, assetsDir, reason) {
|
|
223
|
+
try {
|
|
224
|
+
if (mode === 'image-to-image' && item?.source_file && !isUrlOrData(item.source_file)) {
|
|
225
|
+
const src = resolveUnder(assetsDir, item.source_file, `img_plan.source_file(${item.source_file})`);
|
|
226
|
+
if (await exists(src)) {
|
|
227
|
+
await copyFile(src, outPath);
|
|
228
|
+
return { file: item.file, source_file: item.source_file, mode, reason, fallback: 'copied-source' };
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
await writeGradientPng(outPath, item?.aspect);
|
|
232
|
+
return { file: item?.file, source_file: item?.source_file, mode, reason, fallback: 'gradient-png' };
|
|
233
|
+
} catch (e) {
|
|
234
|
+
try {
|
|
235
|
+
await writeGradientPng(outPath, item?.aspect);
|
|
236
|
+
} catch {
|
|
237
|
+
/* 兜底的兜底也失败就算了,绝不抛 */
|
|
238
|
+
}
|
|
239
|
+
return { file: item?.file, source_file: item?.source_file, mode, reason: `${reason}; fallback err ${e?.message ?? e}`, fallback: 'gradient-png' };
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function spawnNode(cmd, ms) {
|
|
244
|
+
return new Promise((resolvePromise) => {
|
|
245
|
+
const captured = process.env.MINIMAL_AGENT_CAPTURED_STDIO === '1';
|
|
246
|
+
const child = spawn(process.execPath, cmd, {
|
|
247
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
248
|
+
env: process.env,
|
|
249
|
+
});
|
|
250
|
+
let stdout = '';
|
|
251
|
+
let stderr = '';
|
|
252
|
+
const timer = setTimeout(() => {
|
|
253
|
+
child.kill('SIGTERM');
|
|
254
|
+
}, ms);
|
|
255
|
+
child.stdout.on('data', (d) => {
|
|
256
|
+
stdout += d.toString();
|
|
257
|
+
if (!captured) process.stdout.write(d);
|
|
258
|
+
});
|
|
259
|
+
child.stderr.on('data', (d) => {
|
|
260
|
+
stderr += d.toString();
|
|
261
|
+
if (!captured) process.stderr.write(d);
|
|
262
|
+
});
|
|
263
|
+
child.on('close', (code, signal) => {
|
|
264
|
+
clearTimeout(timer);
|
|
265
|
+
resolvePromise({ code: code ?? 1, signal, stdout, stderr });
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
async function main() {
|
|
271
|
+
const args = parseArgs(process.argv.slice(2));
|
|
272
|
+
const planPath = args.plan || './build/img_plan.json';
|
|
273
|
+
const assetsDir = resolve(args.assets || dirname(planPath));
|
|
274
|
+
|
|
275
|
+
if (!(await exists(planPath))) {
|
|
276
|
+
console.log(`PLAN_EMPTY: ${planPath} 不存在,跳过生图。`);
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
let plan;
|
|
281
|
+
try {
|
|
282
|
+
plan = JSON.parse(await readFile(planPath, 'utf8'));
|
|
283
|
+
} catch (e) {
|
|
284
|
+
err(`PLAN_ERROR: 读取/解析 ${planPath} 失败:${e?.message ?? e}`);
|
|
285
|
+
process.exit(2);
|
|
286
|
+
}
|
|
287
|
+
if (!Array.isArray(plan)) {
|
|
288
|
+
err(`PLAN_ERROR: ${planPath} 应是数组`);
|
|
289
|
+
process.exit(2);
|
|
290
|
+
}
|
|
291
|
+
if (plan.length === 0) {
|
|
292
|
+
console.log(`PLAN_EMPTY: ${planPath} 是空数组,跳过生图。`);
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
const retryPlan = await filterRetryPlan(plan, args['retry-degraded-report']);
|
|
296
|
+
plan = retryPlan.plan;
|
|
297
|
+
if (args['retry-degraded-report'] && plan.length === 0) {
|
|
298
|
+
console.log(`PLAN_RETRY_EMPTY: ${args['retry-degraded-report']} 没有 degraded 条目需要重试。`);
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
await mkdir(assetsDir, { recursive: true });
|
|
303
|
+
// hardErrors = 计划结构/安全校验失败(malformed plan / 路径越界)——这是计划 bug,仍响亮 exit 1。
|
|
304
|
+
// degraded = AI 生成失败(敏感内容/超时/网络/空输出)——写降级占位、恒 exit 0、绝不阻断(用户铁律:配图失败永不报错)。
|
|
305
|
+
const hardErrors = [];
|
|
306
|
+
const degraded = [];
|
|
307
|
+
const generated = [];
|
|
308
|
+
const attempts = [];
|
|
309
|
+
|
|
310
|
+
// 总时长自限:防整步耗时撞工具级超时被 SIGKILL(不够就把剩余全部降级、主动收尾)。
|
|
311
|
+
const startedAt = Date.now();
|
|
312
|
+
const wallBudgetMs = Number(args['wall-budget-ms']) > 0 ? Number(args['wall-budget-ms']) : 540_000;
|
|
313
|
+
// 成本不计、最大努力生图:单张预留放宽到 100s(原 70s),减少尾部图因预算临界被误降级。
|
|
314
|
+
const PER_IMAGE_RESERVE_MS = 100_000;
|
|
315
|
+
const maxRounds =
|
|
316
|
+
Number(args['max-rounds']) > 0
|
|
317
|
+
? Math.floor(Number(args['max-rounds']))
|
|
318
|
+
: args['retry-degraded-report']
|
|
319
|
+
? 3
|
|
320
|
+
: 1;
|
|
321
|
+
|
|
322
|
+
// 批内并发(--concurrency N,默认 1 = 顺序执行、行为与旧版一致):31 张 ≈ 15min 的串行生图是
|
|
323
|
+
// ppt 工作流最大耗时项;provider 通常允许小并发(ppt.yaml 传 2)。共享数组(degraded/generated/
|
|
324
|
+
// attempts/nextPending)的 push 在 JS 单线程事件循环下天然原子;wall-budget 检查每张开跑前各自做,
|
|
325
|
+
// 预算耗尽时并发在飞的张各自收尾、其余降级——语义与串行版一致。
|
|
326
|
+
const concurrency = Math.max(1, Math.floor(Number(args.concurrency) || 1));
|
|
327
|
+
|
|
328
|
+
let pending = plan.map((item, index) => ({ item, index }));
|
|
329
|
+
for (let round = 1; round <= maxRounds && pending.length; round++) {
|
|
330
|
+
const nextPending = [];
|
|
331
|
+
const processOne = async (pendingItem) => {
|
|
332
|
+
const item = pendingItem.item;
|
|
333
|
+
const i = pendingItem.index;
|
|
334
|
+
let mode;
|
|
335
|
+
let command;
|
|
336
|
+
let outPath;
|
|
337
|
+
// ① 结构/安全校验(失败=计划 bug,hardError、不降级)
|
|
338
|
+
try {
|
|
339
|
+
mode = validateItem(item, i);
|
|
340
|
+
({ cmd: command, outPath } = commandForItem(item, mode, assetsDir, args));
|
|
341
|
+
} catch (e) {
|
|
342
|
+
hardErrors.push({ file: item?.file || `#${i}`, reason: e?.message ?? String(e) });
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if (args['dry-run'] !== undefined) {
|
|
347
|
+
console.error(`[ai-image-plan] round ${round}/${maxRounds} ${i + 1}/${plan.length} ${mode} → ${item.file}`);
|
|
348
|
+
console.log(JSON.stringify({ file: item.file, mode, command: [process.execPath, ...command] }));
|
|
349
|
+
generated.push(item.file);
|
|
350
|
+
attempts.push({ file: item.file, mode, round, status: 'dry-run' });
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// ② 原图缺失(img2img)→ 降级(无法复制,写渐变占位)
|
|
355
|
+
if (mode === 'image-to-image' && !isUrlOrData(item.source_file)) {
|
|
356
|
+
const sourcePath = resolveUnder(assetsDir, item.source_file, `img_plan.source_file(${item.source_file})`);
|
|
357
|
+
if (!(await exists(sourcePath))) {
|
|
358
|
+
console.error(`[ai-image-plan] ${i + 1}/${plan.length} 原图不存在 → 降级占位 ${item.file}`);
|
|
359
|
+
const d = await degradeFallback(item, mode, outPath, assetsDir, `source_file 不存在:${sourcePath}`);
|
|
360
|
+
degraded.push({ ...d, round });
|
|
361
|
+
attempts.push({ file: item.file, mode, round, status: 'degraded', reason: d.reason, fallback: d.fallback });
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// ③ 总时长不足 → 剩余全部降级(绝不被 SIGKILL)
|
|
367
|
+
const remaining = wallBudgetMs - (Date.now() - startedAt);
|
|
368
|
+
if (remaining < PER_IMAGE_RESERVE_MS) {
|
|
369
|
+
console.error(`[ai-image-plan] ${i + 1}/${plan.length} 时间预算不足(剩 ${Math.round(remaining / 1000)}s)→ 降级占位 ${item.file}`);
|
|
370
|
+
const d = await degradeFallback(item, mode, outPath, assetsDir, '总时长预算耗尽');
|
|
371
|
+
degraded.push({ ...d, round });
|
|
372
|
+
attempts.push({ file: item.file, mode, round, status: 'degraded', reason: d.reason, fallback: d.fallback });
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// ④ 真正生成;失败(含敏感内容 400/超时/空输出)→ 降级,绝不 exit 1
|
|
377
|
+
console.error(`[ai-image-plan] round ${round}/${maxRounds} ${i + 1}/${plan.length} ${mode} → ${item.file}`);
|
|
378
|
+
const perImageMs = Math.min(timeoutMs(args), Math.max(30_000, remaining - 10_000));
|
|
379
|
+
const attemptStartedAt = Date.now();
|
|
380
|
+
const result = await spawnNode(command, perImageMs);
|
|
381
|
+
if (result.code !== 0) {
|
|
382
|
+
console.error(`[ai-image-plan] ${item.file} 生成失败(exit ${result.code}${result.signal ? ` ${result.signal}` : ''})→ 降级占位`);
|
|
383
|
+
const d = await degradeFallback(item, mode, outPath, assetsDir, `generate.mjs exit ${result.code}${result.signal ? ` signal ${result.signal}` : ''}`);
|
|
384
|
+
attempts.push({
|
|
385
|
+
file: item.file,
|
|
386
|
+
mode,
|
|
387
|
+
round,
|
|
388
|
+
status: 'degraded',
|
|
389
|
+
reason: d.reason,
|
|
390
|
+
fallback: d.fallback,
|
|
391
|
+
durationMs: Date.now() - attemptStartedAt,
|
|
392
|
+
});
|
|
393
|
+
if (round < maxRounds) nextPending.push(pendingItem);
|
|
394
|
+
else degraded.push({ ...d, round });
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
if (args['dry-run-request'] === undefined) {
|
|
398
|
+
try {
|
|
399
|
+
const st = await stat(outPath);
|
|
400
|
+
if (!st.isFile() || st.size <= 0) throw new Error('输出文件为空');
|
|
401
|
+
} catch (e) {
|
|
402
|
+
const d = await degradeFallback(item, mode, outPath, assetsDir, `输出校验失败:${e?.message ?? e}`);
|
|
403
|
+
attempts.push({
|
|
404
|
+
file: item.file,
|
|
405
|
+
mode,
|
|
406
|
+
round,
|
|
407
|
+
status: 'degraded',
|
|
408
|
+
reason: d.reason,
|
|
409
|
+
fallback: d.fallback,
|
|
410
|
+
durationMs: Date.now() - attemptStartedAt,
|
|
411
|
+
});
|
|
412
|
+
if (round < maxRounds) nextPending.push(pendingItem);
|
|
413
|
+
else degraded.push({ ...d, round });
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
generated.push(item.file);
|
|
418
|
+
attempts.push({ file: item.file, mode, round, status: 'generated', durationMs: Date.now() - attemptStartedAt });
|
|
419
|
+
};
|
|
420
|
+
const queue = [...pending];
|
|
421
|
+
const worker = async () => {
|
|
422
|
+
for (;;) {
|
|
423
|
+
const next = queue.shift();
|
|
424
|
+
if (!next) return;
|
|
425
|
+
await processOne(next);
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
await Promise.all(Array.from({ length: Math.max(1, Math.min(concurrency, queue.length)) }, worker));
|
|
429
|
+
pending = nextPending;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// 结构/安全失败仍响亮(计划 bug 该暴露);但 AI 生成失败只降级、恒 exit 0。
|
|
433
|
+
if (hardErrors.length) {
|
|
434
|
+
err(`IMAGE_PLAN_FAILED: ${hardErrors.length}/${plan.length} 张结构/安全校验失败(非生成失败,请修 img_plan)`);
|
|
435
|
+
for (const f of hardErrors) err(`- ${f.file}: ${f.reason}`);
|
|
436
|
+
process.exit(1);
|
|
437
|
+
}
|
|
438
|
+
if (degraded.length) {
|
|
439
|
+
err(`IMAGE_PLAN_DEGRADED: ${degraded.length}/${plan.length} 张退化(已写占位资产兜底、不阻断工作流)`);
|
|
440
|
+
for (const d of degraded) err(`- ${d.file}: ${d.reason}${d.fallback ? ` [${d.fallback}]` : ''}`);
|
|
441
|
+
}
|
|
442
|
+
const reportPath = resolve(assetsDir, '..', 'image_generation_report.json');
|
|
443
|
+
await writeFile(
|
|
444
|
+
reportPath,
|
|
445
|
+
JSON.stringify(
|
|
446
|
+
{
|
|
447
|
+
ok: hardErrors.length === 0,
|
|
448
|
+
qualityOk: hardErrors.length === 0 && degraded.length === 0,
|
|
449
|
+
retryOf: retryPlan.retryOf,
|
|
450
|
+
plan,
|
|
451
|
+
generated,
|
|
452
|
+
degraded,
|
|
453
|
+
hardErrors,
|
|
454
|
+
attempts,
|
|
455
|
+
},
|
|
456
|
+
null,
|
|
457
|
+
2,
|
|
458
|
+
),
|
|
459
|
+
'utf8',
|
|
460
|
+
);
|
|
461
|
+
console.log(
|
|
462
|
+
`IMAGE_PLAN_OK: ${generated.length}/${plan.length} 张真实生成${degraded.length ? `,${degraded.length} 张退化占位(不阻断)` : ''}`,
|
|
463
|
+
);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
main().catch((e) => {
|
|
467
|
+
err(`IMAGE_PLAN_ERROR: ${e?.message ?? e}`);
|
|
468
|
+
process.exit(1);
|
|
469
|
+
});
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { mkdtemp, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { spawnSync } from 'node:child_process';
|
|
6
|
+
import { tmpdir } from 'node:os';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
|
|
9
|
+
const script = fileURLToPath(new URL('./generate_from_plan.mjs', import.meta.url));
|
|
10
|
+
|
|
11
|
+
async function withTmp(fn) {
|
|
12
|
+
const dir = await mkdtemp(join(tmpdir(), 'ai-image-plan-'));
|
|
13
|
+
try {
|
|
14
|
+
return await fn(dir);
|
|
15
|
+
} finally {
|
|
16
|
+
await rm(dir, { recursive: true, force: true });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function run(args) {
|
|
21
|
+
return spawnSync(process.execPath, [script, ...args], {
|
|
22
|
+
encoding: 'utf8',
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function jsonLines(stdout) {
|
|
27
|
+
return stdout
|
|
28
|
+
.trim()
|
|
29
|
+
.split(/\n+/)
|
|
30
|
+
.filter((line) => line.trim().startsWith('{'))
|
|
31
|
+
.map((line) => JSON.parse(line));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
await withTmp(async (dir) => {
|
|
35
|
+
const assets = join(dir, 'assets');
|
|
36
|
+
const plan = join(dir, 'img_plan.json');
|
|
37
|
+
await mkdir(assets, { recursive: true });
|
|
38
|
+
await writeFile(
|
|
39
|
+
plan,
|
|
40
|
+
JSON.stringify([
|
|
41
|
+
{
|
|
42
|
+
file: 'hero.png',
|
|
43
|
+
mode: 'text-to-image',
|
|
44
|
+
aspect: '16:9',
|
|
45
|
+
prompt: 'clean product hero background, no text',
|
|
46
|
+
},
|
|
47
|
+
]),
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const res = run(['--plan', plan, '--assets', assets, '--dry-run']);
|
|
51
|
+
assert.equal(res.status, 0, res.stderr);
|
|
52
|
+
const [item] = jsonLines(res.stdout);
|
|
53
|
+
assert.equal(item.file, 'hero.png');
|
|
54
|
+
assert.equal(item.mode, 'text-to-image');
|
|
55
|
+
assert.ok(item.command.includes('--prompt'));
|
|
56
|
+
assert.ok(item.command.includes('--out'));
|
|
57
|
+
assert.ok(!item.command.includes('--input-image'));
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
await withTmp(async (dir) => {
|
|
61
|
+
const assets = join(dir, 'assets');
|
|
62
|
+
const plan = join(dir, 'img_plan.json');
|
|
63
|
+
const sourceRel = 'source photos/src 1.png';
|
|
64
|
+
await mkdir(join(assets, 'source photos'), { recursive: true });
|
|
65
|
+
await writeFile(join(assets, sourceRel), Buffer.from([0x89, 0x50, 0x4e, 0x47]));
|
|
66
|
+
await writeFile(
|
|
67
|
+
plan,
|
|
68
|
+
JSON.stringify([
|
|
69
|
+
{
|
|
70
|
+
file: 'enhanced_src_1.png',
|
|
71
|
+
mode: 'image-to-image',
|
|
72
|
+
source_file: sourceRel,
|
|
73
|
+
aspect: '4:3',
|
|
74
|
+
prompt: 'extend background, keep product clear, no text',
|
|
75
|
+
},
|
|
76
|
+
]),
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const res = run(['--plan', plan, '--assets', assets, '--dry-run']);
|
|
80
|
+
assert.equal(res.status, 0, res.stderr);
|
|
81
|
+
const [item] = jsonLines(res.stdout);
|
|
82
|
+
assert.equal(item.mode, 'image-to-image');
|
|
83
|
+
const idx = item.command.indexOf('--input-image');
|
|
84
|
+
assert.ok(idx > -1);
|
|
85
|
+
assert.equal(item.command[idx + 1], join(assets, sourceRel));
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
await withTmp(async (dir) => {
|
|
89
|
+
const assets = join(dir, 'assets');
|
|
90
|
+
const plan = join(dir, 'img_plan.json');
|
|
91
|
+
await mkdir(assets, { recursive: true });
|
|
92
|
+
await writeFile(
|
|
93
|
+
plan,
|
|
94
|
+
JSON.stringify([
|
|
95
|
+
{
|
|
96
|
+
file: 'bad.png',
|
|
97
|
+
mode: 'image-to-image',
|
|
98
|
+
prompt: 'missing source should fail',
|
|
99
|
+
},
|
|
100
|
+
]),
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
const res = run(['--plan', plan, '--assets', assets, '--dry-run']);
|
|
104
|
+
assert.notEqual(res.status, 0);
|
|
105
|
+
assert.match(res.stderr, /source_file 必填/);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
await withTmp(async (dir) => {
|
|
109
|
+
const assets = join(dir, 'assets');
|
|
110
|
+
const plan = join(dir, 'img_plan.json');
|
|
111
|
+
await writeFile(plan, '[]');
|
|
112
|
+
|
|
113
|
+
const res = run(['--plan', plan, '--assets', assets, '--dry-run']);
|
|
114
|
+
assert.equal(res.status, 0, res.stderr);
|
|
115
|
+
assert.match(res.stdout, /PLAN_EMPTY/);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// 跨平台路径包含判定(回归:Windows 上 path.resolve 产出反斜杠,旧逻辑硬编码 `/` 会把
|
|
119
|
+
// assets 下的 bare 文件名误判「跳出 assets 目录」整批失败)。这里锁双向语义:
|
|
120
|
+
// - bare 文件名(assets 直属)必须被接受(三平台一致);
|
|
121
|
+
// - 真正用 `../` 越界必须被拒绝。
|
|
122
|
+
await withTmp(async (dir) => {
|
|
123
|
+
const assets = join(dir, 'assets');
|
|
124
|
+
const plan = join(dir, 'img_plan.json');
|
|
125
|
+
await mkdir(assets, { recursive: true });
|
|
126
|
+
await writeFile(
|
|
127
|
+
plan,
|
|
128
|
+
JSON.stringify([
|
|
129
|
+
{ file: 'img_2.png', mode: 'text-to-image', aspect: '4:3', prompt: 'in-dir bare name must pass' },
|
|
130
|
+
{ file: '../escape.png', mode: 'text-to-image', prompt: 'must be rejected' },
|
|
131
|
+
]),
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
const res = run(['--plan', plan, '--assets', assets, '--dry-run']);
|
|
135
|
+
// 第一条产出合法命令、第二条越界 → 整批以失败收尾(status≠0),但 bare 名不是因「跳出」失败。
|
|
136
|
+
const items = jsonLines(res.stdout);
|
|
137
|
+
assert.ok(
|
|
138
|
+
items.some((it) => it.file === 'img_2.png' && it.command.includes('--out')),
|
|
139
|
+
'assets 直属的 bare 文件名应被接受并产出命令',
|
|
140
|
+
);
|
|
141
|
+
assert.match(res.stderr, /不能跳出 assets 目录:\.\.\/escape\.png/);
|
|
142
|
+
assert.doesNotMatch(res.stderr, /img_2\.png: .*不能跳出/);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// AI 生成失败 → 降级写占位资产 + 恒 exit 0(用户铁律:配图失败永不报错、绝不让 deck 坏图)。
|
|
146
|
+
// img2img 失败→复制原图;文生图失败→写渐变 PNG。
|
|
147
|
+
await withTmp(async (dir) => {
|
|
148
|
+
const assets = join(dir, 'assets');
|
|
149
|
+
const plan = join(dir, 'img_plan.json');
|
|
150
|
+
await mkdir(assets, { recursive: true });
|
|
151
|
+
await writeFile(join(assets, 'src_1.png'), Buffer.from([0x89, 0x50, 0x4e, 0x47, 1, 2, 3, 4, 5]));
|
|
152
|
+
await writeFile(
|
|
153
|
+
plan,
|
|
154
|
+
JSON.stringify([
|
|
155
|
+
{ file: 'enhanced_src_1.jpg', mode: 'image-to-image', source_file: 'src_1.png', aspect: '16:9', prompt: 'x' },
|
|
156
|
+
{ file: 'img_1.png', mode: 'text-to-image', aspect: '4:5', prompt: 'y' },
|
|
157
|
+
]),
|
|
158
|
+
);
|
|
159
|
+
// 去掉图片 API env → generate.mjs 必失败 → 触发降级路径(而非真打 API)。
|
|
160
|
+
const env = { ...process.env };
|
|
161
|
+
for (const k of [
|
|
162
|
+
'OPENAI_IMAGE_BASE_URL',
|
|
163
|
+
'OPENAI_IMAGE_API_KEY',
|
|
164
|
+
'OPENAI_IMAGE_MODEL',
|
|
165
|
+
'MINIMAL_AGENT_BASE_URL',
|
|
166
|
+
'MINIMAL_AGENT_API_KEY',
|
|
167
|
+
'MINIMAL_AGENT_MODEL',
|
|
168
|
+
]) {
|
|
169
|
+
delete env[k];
|
|
170
|
+
}
|
|
171
|
+
const res = spawnSync(process.execPath, [script, '--plan', plan, '--assets', assets], { encoding: 'utf8', env });
|
|
172
|
+
assert.equal(res.status, 0, '配图失败必须恒 exit 0、绝不报错:' + res.stderr);
|
|
173
|
+
assert.match(res.stderr, /IMAGE_PLAN_DEGRADED/);
|
|
174
|
+
const report = JSON.parse(await readFile(join(dir, 'image_generation_report.json'), 'utf8'));
|
|
175
|
+
assert.equal(report.ok, true);
|
|
176
|
+
assert.equal(report.qualityOk, false);
|
|
177
|
+
assert.ok(Array.isArray(report.attempts));
|
|
178
|
+
// img2img 降级 = 复制原图(字节一致)
|
|
179
|
+
const enh = await readFile(join(assets, 'enhanced_src_1.jpg'));
|
|
180
|
+
const src = await readFile(join(assets, 'src_1.png'));
|
|
181
|
+
assert.ok(enh.equals(src), 'img2img 降级应复制原图');
|
|
182
|
+
// 文生图降级 = 合法 PNG(魔数 89 50 4E 47)
|
|
183
|
+
const grad = await readFile(join(assets, 'img_1.png'));
|
|
184
|
+
assert.ok(
|
|
185
|
+
grad.length > 50 && grad[0] === 0x89 && grad[1] === 0x50 && grad[2] === 0x4e && grad[3] === 0x47,
|
|
186
|
+
'文生图降级应为合法渐变 PNG',
|
|
187
|
+
);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
// 重试模式:只取上一次 report 里的 degraded 文件,避免整批图反复生成。
|
|
191
|
+
await withTmp(async (dir) => {
|
|
192
|
+
const assets = join(dir, 'assets');
|
|
193
|
+
const plan = join(dir, 'img_plan.json');
|
|
194
|
+
const report = join(dir, 'image_generation_report.json');
|
|
195
|
+
await mkdir(assets, { recursive: true });
|
|
196
|
+
await writeFile(
|
|
197
|
+
plan,
|
|
198
|
+
JSON.stringify([
|
|
199
|
+
{ file: 'ok.png', mode: 'text-to-image', aspect: '16:9', prompt: 'already generated' },
|
|
200
|
+
{ file: 'bad.png', mode: 'text-to-image', aspect: '16:9', prompt: 'retry this one' },
|
|
201
|
+
]),
|
|
202
|
+
);
|
|
203
|
+
await writeFile(report, JSON.stringify({ degraded: [{ file: 'bad.png', fallback: 'gradient-png' }] }));
|
|
204
|
+
|
|
205
|
+
const res = run(['--plan', plan, '--assets', assets, '--retry-degraded-report', report, '--dry-run']);
|
|
206
|
+
assert.equal(res.status, 0, res.stderr);
|
|
207
|
+
const items = jsonLines(res.stdout);
|
|
208
|
+
assert.equal(items.length, 1);
|
|
209
|
+
assert.equal(items[0].file, 'bad.png');
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
// 结构/安全校验失败(malformed plan)仍 hardError exit 1(与生成失败区分,计划 bug 要暴露)。
|
|
213
|
+
await withTmp(async (dir) => {
|
|
214
|
+
const assets = join(dir, 'assets');
|
|
215
|
+
const plan = join(dir, 'img_plan.json');
|
|
216
|
+
await mkdir(assets, { recursive: true });
|
|
217
|
+
await writeFile(plan, JSON.stringify([{ file: '../escape.png', mode: 'text-to-image', prompt: 'z' }]));
|
|
218
|
+
const res = spawnSync(process.execPath, [script, '--plan', plan, '--assets', assets, '--dry-run'], { encoding: 'utf8' });
|
|
219
|
+
assert.notEqual(res.status, 0, '路径越界是结构/安全错误,应 hardError exit 1');
|
|
220
|
+
assert.match(res.stderr, /不能跳出 assets 目录/);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
console.log('generate_from_plan_test PASSED');
|