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,355 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
3
|
+
import { resolveSessionFile } from '../../../src/plugin-sdk.js';
|
|
4
|
+
import { releaseSchedulerLock, tryAcquireSchedulerLock } from './lock.js';
|
|
5
|
+
import { countScheduleSlots, latestScheduleRunMs, nextScheduleRunMs, } from './scheduleEngine.js';
|
|
6
|
+
import { appendMissed, appendRun, cronLockFile, getTask, listTasks, subscribeTaskChanges, updateTask, } from './store.js';
|
|
7
|
+
const RECONCILE_MS = 30_000;
|
|
8
|
+
export class Scheduler {
|
|
9
|
+
ctx;
|
|
10
|
+
dueTimer = null;
|
|
11
|
+
reconcileTimer = null;
|
|
12
|
+
unsubscribeStore = null;
|
|
13
|
+
executions = new Map();
|
|
14
|
+
executionController = new AbortController();
|
|
15
|
+
owner = `cron-runner-${process.pid}-${randomUUID()}`;
|
|
16
|
+
ownsLock = false;
|
|
17
|
+
started = false;
|
|
18
|
+
stopping = false;
|
|
19
|
+
reconciling = false;
|
|
20
|
+
initializing = false;
|
|
21
|
+
stopPromise = null;
|
|
22
|
+
constructor(ctx) {
|
|
23
|
+
this.ctx = ctx;
|
|
24
|
+
}
|
|
25
|
+
start() {
|
|
26
|
+
if (this.started)
|
|
27
|
+
return;
|
|
28
|
+
this.started = true;
|
|
29
|
+
this.stopping = false;
|
|
30
|
+
this.unsubscribeStore = subscribeTaskChanges(() => this.wake());
|
|
31
|
+
void this.startAsync();
|
|
32
|
+
}
|
|
33
|
+
async stop() {
|
|
34
|
+
if (this.stopPromise)
|
|
35
|
+
return await this.stopPromise;
|
|
36
|
+
if (!this.started && !this.ownsLock && this.executions.size === 0)
|
|
37
|
+
return;
|
|
38
|
+
this.started = false;
|
|
39
|
+
this.stopping = true;
|
|
40
|
+
this.executionController.abort('cron scheduler stopped');
|
|
41
|
+
this.clearTimers();
|
|
42
|
+
this.unsubscribeStore?.();
|
|
43
|
+
this.unsubscribeStore = null;
|
|
44
|
+
this.stopPromise = (async () => {
|
|
45
|
+
await Promise.allSettled([...this.executions.values()]);
|
|
46
|
+
if (!this.ownsLock)
|
|
47
|
+
return;
|
|
48
|
+
this.ownsLock = false;
|
|
49
|
+
await releaseSchedulerLock(cronLockFile(), this.owner);
|
|
50
|
+
})();
|
|
51
|
+
await this.stopPromise;
|
|
52
|
+
}
|
|
53
|
+
async runTaskNow(id) {
|
|
54
|
+
if (this.stopping || this.executions.has(id))
|
|
55
|
+
return;
|
|
56
|
+
const task = await getTask(id);
|
|
57
|
+
if (!task)
|
|
58
|
+
return;
|
|
59
|
+
await this.launchTask(task);
|
|
60
|
+
}
|
|
61
|
+
async isActiveScheduler() {
|
|
62
|
+
return this.ownsLock;
|
|
63
|
+
}
|
|
64
|
+
wake() {
|
|
65
|
+
if (!this.ownsLock || this.stopping || this.initializing)
|
|
66
|
+
return;
|
|
67
|
+
if (this.dueTimer)
|
|
68
|
+
clearTimeout(this.dueTimer);
|
|
69
|
+
this.dueTimer = setTimeout(() => void this.reconcile(), 0);
|
|
70
|
+
this.dueTimer.unref?.();
|
|
71
|
+
}
|
|
72
|
+
async startAsync() {
|
|
73
|
+
this.initializing = true;
|
|
74
|
+
this.ownsLock = await tryAcquireSchedulerLock(cronLockFile(), this.owner);
|
|
75
|
+
if (!this.ownsLock) {
|
|
76
|
+
this.initializing = false;
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (this.stopping) {
|
|
80
|
+
this.ownsLock = false;
|
|
81
|
+
await releaseSchedulerLock(cronLockFile(), this.owner);
|
|
82
|
+
this.initializing = false;
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
await this.recordMissedTasks();
|
|
86
|
+
this.initializing = false;
|
|
87
|
+
this.reconcileTimer = setInterval(() => void this.reconcile(), RECONCILE_MS);
|
|
88
|
+
this.reconcileTimer.unref?.();
|
|
89
|
+
await this.reconcile();
|
|
90
|
+
}
|
|
91
|
+
clearTimers() {
|
|
92
|
+
if (this.dueTimer)
|
|
93
|
+
clearTimeout(this.dueTimer);
|
|
94
|
+
if (this.reconcileTimer)
|
|
95
|
+
clearInterval(this.reconcileTimer);
|
|
96
|
+
this.dueTimer = null;
|
|
97
|
+
this.reconcileTimer = null;
|
|
98
|
+
}
|
|
99
|
+
async reconcile() {
|
|
100
|
+
if (!this.ownsLock || this.stopping || this.reconciling)
|
|
101
|
+
return;
|
|
102
|
+
this.reconciling = true;
|
|
103
|
+
try {
|
|
104
|
+
const now = Date.now();
|
|
105
|
+
const tasks = await listTasks();
|
|
106
|
+
for (const task of tasks)
|
|
107
|
+
await this.processDueTask(task, now);
|
|
108
|
+
await this.armNextTimer();
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
this.reconciling = false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async processDueTask(task, now) {
|
|
115
|
+
if (task.status !== 'active')
|
|
116
|
+
return;
|
|
117
|
+
if (task.runtime.bindingStatus !== 'bound')
|
|
118
|
+
return;
|
|
119
|
+
if (this.isExpired(task, now)) {
|
|
120
|
+
await updateTask(task.id, (latest) => ({ ...latest, status: 'completed' }));
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const baseMs = this.lastProcessedMs(task);
|
|
124
|
+
const jitterMs = task.schedule.jitterMs ?? 0;
|
|
125
|
+
const latestDue = latestScheduleRunMs(task.schedule, now - jitterMs);
|
|
126
|
+
if (!latestDue || latestDue <= baseMs)
|
|
127
|
+
return;
|
|
128
|
+
const dueCount = countScheduleSlots(task.schedule, baseMs, latestDue);
|
|
129
|
+
if (dueCount === 0)
|
|
130
|
+
return;
|
|
131
|
+
if (this.executions.has(task.id)) {
|
|
132
|
+
await this.markMissed(task, latestDue, dueCount, 'overlap');
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
// If the event loop was delayed across several slots, run only the latest
|
|
136
|
+
// and record all older slots. This keeps skip semantics deterministic.
|
|
137
|
+
if (dueCount > 1)
|
|
138
|
+
await this.appendMissed(task, latestDue, dueCount - 1, 'offline');
|
|
139
|
+
const claimed = await updateTask(task.id, (latest) => ({
|
|
140
|
+
...latest,
|
|
141
|
+
schedule: {
|
|
142
|
+
...latest.schedule,
|
|
143
|
+
lastScheduledFor: new Date(latestDue).toISOString(),
|
|
144
|
+
lastFiredAt: new Date().toISOString(),
|
|
145
|
+
},
|
|
146
|
+
stats: {
|
|
147
|
+
...latest.stats,
|
|
148
|
+
skippedCount: latest.stats.skippedCount + Math.max(0, dueCount - 1),
|
|
149
|
+
},
|
|
150
|
+
}));
|
|
151
|
+
if (claimed && !this.stopping)
|
|
152
|
+
void this.launchTask(claimed, new Date(latestDue).toISOString());
|
|
153
|
+
}
|
|
154
|
+
async recordMissedTasks() {
|
|
155
|
+
const now = Date.now();
|
|
156
|
+
for (const task of await listTasks()) {
|
|
157
|
+
if (task.status !== 'active')
|
|
158
|
+
continue;
|
|
159
|
+
const baseMs = this.lastProcessedMs(task);
|
|
160
|
+
const latestDue = latestScheduleRunMs(task.schedule, now - (task.schedule.jitterMs ?? 0));
|
|
161
|
+
if (!latestDue || latestDue <= baseMs)
|
|
162
|
+
continue;
|
|
163
|
+
const missedCount = countScheduleSlots(task.schedule, baseMs, latestDue);
|
|
164
|
+
if (missedCount > 0)
|
|
165
|
+
await this.markMissed(task, latestDue, missedCount, 'offline');
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
async markMissed(task, latestDue, missedCount, reason) {
|
|
169
|
+
await this.appendMissed(task, latestDue, missedCount, reason);
|
|
170
|
+
await updateTask(task.id, (latest) => ({
|
|
171
|
+
...latest,
|
|
172
|
+
...(latest.kind === 'once' ? { status: 'paused' } : {}),
|
|
173
|
+
schedule: {
|
|
174
|
+
...latest.schedule,
|
|
175
|
+
lastScheduledFor: new Date(latestDue).toISOString(),
|
|
176
|
+
},
|
|
177
|
+
stats: {
|
|
178
|
+
...latest.stats,
|
|
179
|
+
skippedCount: latest.stats.skippedCount + missedCount,
|
|
180
|
+
},
|
|
181
|
+
}));
|
|
182
|
+
}
|
|
183
|
+
async appendMissed(task, latestDue, missedCount, reason) {
|
|
184
|
+
await appendMissed({
|
|
185
|
+
id: `missed-${randomUUID().slice(0, 8)}`,
|
|
186
|
+
taskId: task.id,
|
|
187
|
+
taskName: task.name,
|
|
188
|
+
scheduledFor: new Date(latestDue).toISOString(),
|
|
189
|
+
detectedAt: new Date().toISOString(),
|
|
190
|
+
actionPreview: actionPreview(task),
|
|
191
|
+
reason,
|
|
192
|
+
missedCount,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
async armNextTimer() {
|
|
196
|
+
if (!this.ownsLock || this.stopping)
|
|
197
|
+
return;
|
|
198
|
+
if (this.dueTimer)
|
|
199
|
+
clearTimeout(this.dueTimer);
|
|
200
|
+
let earliest = Number.POSITIVE_INFINITY;
|
|
201
|
+
for (const task of await listTasks()) {
|
|
202
|
+
if (task.status !== 'active' || this.isExpired(task, Date.now()))
|
|
203
|
+
continue;
|
|
204
|
+
const next = nextScheduleRunMs(task.schedule, this.lastProcessedMs(task));
|
|
205
|
+
if (next)
|
|
206
|
+
earliest = Math.min(earliest, next + (task.schedule.jitterMs ?? 0));
|
|
207
|
+
}
|
|
208
|
+
if (!Number.isFinite(earliest)) {
|
|
209
|
+
this.dueTimer = null;
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const delay = Math.max(0, earliest - Date.now());
|
|
213
|
+
this.dueTimer = setTimeout(() => void this.reconcile(), delay);
|
|
214
|
+
this.dueTimer.unref?.();
|
|
215
|
+
}
|
|
216
|
+
lastProcessedMs(task) {
|
|
217
|
+
const raw = task.schedule.lastScheduledFor ?? task.createdAt;
|
|
218
|
+
const parsed = Date.parse(raw);
|
|
219
|
+
return Number.isFinite(parsed) ? parsed : Date.now();
|
|
220
|
+
}
|
|
221
|
+
isExpired(task, now) {
|
|
222
|
+
return Boolean(task.expiresAt && !task.permanent && Date.parse(task.expiresAt) <= now);
|
|
223
|
+
}
|
|
224
|
+
launchTask(task, scheduledFor) {
|
|
225
|
+
if (this.executions.has(task.id))
|
|
226
|
+
return this.executions.get(task.id);
|
|
227
|
+
const execution = this.runTask(task, scheduledFor).finally(() => {
|
|
228
|
+
this.executions.delete(task.id);
|
|
229
|
+
this.wake();
|
|
230
|
+
});
|
|
231
|
+
this.executions.set(task.id, execution);
|
|
232
|
+
return execution;
|
|
233
|
+
}
|
|
234
|
+
async runTask(task, scheduledFor) {
|
|
235
|
+
const started = Date.now();
|
|
236
|
+
// Session 绑定失效表示本次根本没有执行。它属于 missed/needs_binding,而不是一次
|
|
237
|
+
// Agent failure;否则会消耗 maxRuns,并让用户误以为模型真正跑过。
|
|
238
|
+
if (task.runtime.sessionMode !== 'fresh' && !existsSync(await resolveSessionFile(task.runtime.cwd, task.runtime.sessionId))) {
|
|
239
|
+
const detectedAt = new Date().toISOString();
|
|
240
|
+
await updateTask(task.id, (latest) => ({
|
|
241
|
+
...latest,
|
|
242
|
+
runtime: { ...latest.runtime, bindingStatus: 'needs_binding' },
|
|
243
|
+
...(latest.status === 'active' ? { status: 'paused' } : {}),
|
|
244
|
+
stats: {
|
|
245
|
+
...latest.stats,
|
|
246
|
+
skippedCount: latest.stats.skippedCount + (scheduledFor ? 1 : 0),
|
|
247
|
+
},
|
|
248
|
+
}));
|
|
249
|
+
await appendMissed({
|
|
250
|
+
id: `missed-${randomUUID().slice(0, 8)}`,
|
|
251
|
+
taskId: task.id,
|
|
252
|
+
taskName: task.name,
|
|
253
|
+
scheduledFor: scheduledFor ?? detectedAt,
|
|
254
|
+
detectedAt,
|
|
255
|
+
actionPreview: actionPreview(task),
|
|
256
|
+
reason: 'binding_unavailable',
|
|
257
|
+
missedCount: 1,
|
|
258
|
+
});
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
const run = {
|
|
262
|
+
id: `run-${randomUUID().slice(0, 8)}`,
|
|
263
|
+
taskId: task.id,
|
|
264
|
+
taskName: task.name,
|
|
265
|
+
...(scheduledFor ? { scheduledFor } : {}),
|
|
266
|
+
startedAt: new Date(started).toISOString(),
|
|
267
|
+
status: 'running',
|
|
268
|
+
cwd: task.runtime.cwd,
|
|
269
|
+
sessionId: task.runtime.sessionId,
|
|
270
|
+
...(task.runtime.model ? { model: task.runtime.model } : {}),
|
|
271
|
+
};
|
|
272
|
+
await appendRun(run);
|
|
273
|
+
try {
|
|
274
|
+
const input = task.action.type === 'workflow'
|
|
275
|
+
? `/workflow ${task.action.command}`
|
|
276
|
+
: task.action.prompt;
|
|
277
|
+
const sessionId = task.runtime.sessionId;
|
|
278
|
+
const result = await this.ctx.runAgentTurn({
|
|
279
|
+
input,
|
|
280
|
+
provider: this.ctx.provider,
|
|
281
|
+
cwd: task.runtime.cwd,
|
|
282
|
+
sessionId,
|
|
283
|
+
maxTurns: task.runtime.maxTurns,
|
|
284
|
+
model: task.runtime.model,
|
|
285
|
+
signal: combineSignals(this.ctx.signal, this.executionController.signal),
|
|
286
|
+
});
|
|
287
|
+
const executionOk = result.ok && !this.executionController.signal.aborted;
|
|
288
|
+
const executionError = this.executionController.signal.aborted
|
|
289
|
+
? 'cron scheduler stopped during execution'
|
|
290
|
+
: result.error;
|
|
291
|
+
const finishedAt = new Date().toISOString();
|
|
292
|
+
await updateTask(task.id, (latest) => ({
|
|
293
|
+
...latest,
|
|
294
|
+
...(reachedRunLimit(latest, latest.stats.runCount + 1)
|
|
295
|
+
? { status: 'completed' }
|
|
296
|
+
: {}),
|
|
297
|
+
stats: {
|
|
298
|
+
...latest.stats,
|
|
299
|
+
runCount: latest.stats.runCount + 1,
|
|
300
|
+
successCount: latest.stats.successCount + (executionOk ? 1 : 0),
|
|
301
|
+
failureCount: latest.stats.failureCount + (executionOk ? 0 : 1),
|
|
302
|
+
lastRunAt: finishedAt,
|
|
303
|
+
...(executionOk ? { lastSuccessAt: finishedAt } : { lastFailureAt: finishedAt }),
|
|
304
|
+
},
|
|
305
|
+
}));
|
|
306
|
+
await appendRun({
|
|
307
|
+
...run,
|
|
308
|
+
finishedAt,
|
|
309
|
+
status: executionOk ? 'success' : 'failure',
|
|
310
|
+
durationMs: Date.now() - started,
|
|
311
|
+
resultPreview: result.result.slice(0, 1000),
|
|
312
|
+
...(!executionOk ? { attentionReason: 'failure' } : {}),
|
|
313
|
+
...(executionError ? { error: executionError } : {}),
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
catch (err) {
|
|
317
|
+
const finishedAt = new Date().toISOString();
|
|
318
|
+
await updateTask(task.id, (latest) => ({
|
|
319
|
+
...latest,
|
|
320
|
+
...(reachedRunLimit(latest, latest.stats.runCount + 1)
|
|
321
|
+
? { status: 'completed' }
|
|
322
|
+
: {}),
|
|
323
|
+
stats: {
|
|
324
|
+
...latest.stats,
|
|
325
|
+
runCount: latest.stats.runCount + 1,
|
|
326
|
+
failureCount: latest.stats.failureCount + 1,
|
|
327
|
+
lastRunAt: finishedAt,
|
|
328
|
+
lastFailureAt: finishedAt,
|
|
329
|
+
},
|
|
330
|
+
}));
|
|
331
|
+
await appendRun({
|
|
332
|
+
...run,
|
|
333
|
+
finishedAt,
|
|
334
|
+
status: 'failure',
|
|
335
|
+
durationMs: Date.now() - started,
|
|
336
|
+
attentionReason: 'failure',
|
|
337
|
+
error: err instanceof Error ? err.message : String(err),
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
function reachedRunLimit(task, nextRunCount) {
|
|
343
|
+
if (task.kind === 'once')
|
|
344
|
+
return true;
|
|
345
|
+
return typeof task.maxRuns === 'number' && task.maxRuns > 0 && nextRunCount >= task.maxRuns;
|
|
346
|
+
}
|
|
347
|
+
function actionPreview(task) {
|
|
348
|
+
const text = task.action.type === 'workflow'
|
|
349
|
+
? `/workflow ${task.action.command}`
|
|
350
|
+
: task.action.prompt;
|
|
351
|
+
return text.length > 160 ? `${text.slice(0, 157)}...` : text;
|
|
352
|
+
}
|
|
353
|
+
function combineSignals(parent, local) {
|
|
354
|
+
return parent ? AbortSignal.any([parent, local]) : local;
|
|
355
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { cronToHuman, nextCronRunMs, parseCronExpression } from './cronTime.js';
|
|
2
|
+
import { intervalToHuman, MIN_INTERVAL_MS } from './scheduleEngine.js';
|
|
3
|
+
export function validateCron(cron) {
|
|
4
|
+
const parsed = parseCronExpression(cron);
|
|
5
|
+
if (!parsed)
|
|
6
|
+
return { ok: false, error: 'cron 必须是合法的 5 字段表达式。' };
|
|
7
|
+
if (nextCronRunMs(cron) === null) {
|
|
8
|
+
return { ok: false, error: 'cron 在未来一年内没有可运行时间。' };
|
|
9
|
+
}
|
|
10
|
+
return { ok: true };
|
|
11
|
+
}
|
|
12
|
+
export function validateIsoDate(value, field) {
|
|
13
|
+
const time = Date.parse(value);
|
|
14
|
+
if (!Number.isFinite(time))
|
|
15
|
+
return { ok: false, error: `${field} 必须是 ISO 时间。` };
|
|
16
|
+
return { ok: true };
|
|
17
|
+
}
|
|
18
|
+
export function normalizeTask(raw) {
|
|
19
|
+
if (!raw || typeof raw !== 'object')
|
|
20
|
+
return null;
|
|
21
|
+
const task = raw;
|
|
22
|
+
if (typeof task.id !== 'string' || !task.id)
|
|
23
|
+
return null;
|
|
24
|
+
if (typeof task.name !== 'string' || !task.name)
|
|
25
|
+
return null;
|
|
26
|
+
if (task.status !== 'active' && task.status !== 'paused' && task.status !== 'completed')
|
|
27
|
+
return null;
|
|
28
|
+
if (!task.schedule || typeof task.schedule !== 'object')
|
|
29
|
+
return null;
|
|
30
|
+
const schedule = task.schedule;
|
|
31
|
+
const scheduleType = schedule.type === 'interval' ? 'interval' : 'cron';
|
|
32
|
+
if (scheduleType === 'cron') {
|
|
33
|
+
if (typeof schedule.cron !== 'string' || !parseCronExpression(schedule.cron))
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
else if (typeof schedule.intervalMs !== 'number' ||
|
|
37
|
+
schedule.intervalMs < MIN_INTERVAL_MS ||
|
|
38
|
+
typeof schedule.anchorAt !== 'string' ||
|
|
39
|
+
!Number.isFinite(Date.parse(schedule.anchorAt))) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
if (!task.action || typeof task.action !== 'object')
|
|
43
|
+
return null;
|
|
44
|
+
const action = task.action;
|
|
45
|
+
if (action.type === 'prompt') {
|
|
46
|
+
if (typeof action.prompt !== 'string' || !action.prompt)
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
else if (action.type === 'workflow') {
|
|
50
|
+
if (typeof action.command !== 'string' || !action.command)
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
if (!task.runtime || typeof task.runtime !== 'object')
|
|
57
|
+
return null;
|
|
58
|
+
const runtime = task.runtime;
|
|
59
|
+
if (typeof runtime.cwd !== 'string' || !runtime.cwd)
|
|
60
|
+
return null;
|
|
61
|
+
if (runtime.environment && runtime.environment !== 'project')
|
|
62
|
+
return null;
|
|
63
|
+
const now = new Date().toISOString();
|
|
64
|
+
const kind = task.kind === 'once' ? 'once' : 'recurring';
|
|
65
|
+
const timezone = typeof schedule.timezone === 'string' && schedule.timezone
|
|
66
|
+
? schedule.timezone
|
|
67
|
+
: Intl.DateTimeFormat().resolvedOptions().timeZone || 'local';
|
|
68
|
+
const stats = task.stats ?? {
|
|
69
|
+
runCount: 0,
|
|
70
|
+
successCount: 0,
|
|
71
|
+
failureCount: 0,
|
|
72
|
+
};
|
|
73
|
+
const legacyNeedsBinding = runtime.sessionMode === 'fresh' ||
|
|
74
|
+
typeof runtime.sessionId !== 'string' ||
|
|
75
|
+
!runtime.sessionId ||
|
|
76
|
+
runtime.sessionId.startsWith('cron-');
|
|
77
|
+
const bindingStatus = runtime.bindingStatus === 'needs_binding' || legacyNeedsBinding
|
|
78
|
+
? 'needs_binding'
|
|
79
|
+
: 'bound';
|
|
80
|
+
return {
|
|
81
|
+
id: task.id,
|
|
82
|
+
name: task.name,
|
|
83
|
+
...(typeof task.description === 'string' && task.description
|
|
84
|
+
? { description: task.description }
|
|
85
|
+
: {}),
|
|
86
|
+
status: bindingStatus === 'needs_binding' && task.status === 'active' ? 'paused' : task.status,
|
|
87
|
+
kind,
|
|
88
|
+
...(task.permanent ? { permanent: true } : {}),
|
|
89
|
+
...(typeof task.expiresAt === 'string' ? { expiresAt: task.expiresAt } : {}),
|
|
90
|
+
...(typeof task.maxRuns === 'number' && task.maxRuns > 0 ? { maxRuns: task.maxRuns } : {}),
|
|
91
|
+
schedule: scheduleType === 'interval' ? {
|
|
92
|
+
type: 'interval',
|
|
93
|
+
intervalMs: schedule.intervalMs,
|
|
94
|
+
anchorAt: schedule.anchorAt,
|
|
95
|
+
human: intervalToHuman(schedule.intervalMs),
|
|
96
|
+
...(typeof schedule.nextRunAt === 'string' ? { nextRunAt: schedule.nextRunAt } : {}),
|
|
97
|
+
...(typeof schedule.lastFiredAt === 'string' ? { lastFiredAt: schedule.lastFiredAt } : {}),
|
|
98
|
+
...(typeof schedule.lastScheduledFor === 'string'
|
|
99
|
+
? { lastScheduledFor: schedule.lastScheduledFor }
|
|
100
|
+
: {}),
|
|
101
|
+
...(typeof schedule.jitterMs === 'number' ? { jitterMs: schedule.jitterMs } : {}),
|
|
102
|
+
} : {
|
|
103
|
+
type: 'cron',
|
|
104
|
+
cron: schedule.cron,
|
|
105
|
+
timezone,
|
|
106
|
+
human: cronToHuman(schedule.cron),
|
|
107
|
+
...(typeof schedule.nextRunAt === 'string' ? { nextRunAt: schedule.nextRunAt } : {}),
|
|
108
|
+
...(typeof schedule.lastFiredAt === 'string' ? { lastFiredAt: schedule.lastFiredAt } : {}),
|
|
109
|
+
...(typeof schedule.lastScheduledFor === 'string'
|
|
110
|
+
? { lastScheduledFor: schedule.lastScheduledFor }
|
|
111
|
+
: {}),
|
|
112
|
+
...(typeof schedule.jitterMs === 'number' ? { jitterMs: schedule.jitterMs } : {}),
|
|
113
|
+
},
|
|
114
|
+
action,
|
|
115
|
+
runtime: {
|
|
116
|
+
cwd: runtime.cwd,
|
|
117
|
+
environment: 'project',
|
|
118
|
+
sessionId: typeof runtime.sessionId === 'string' && runtime.sessionId
|
|
119
|
+
? runtime.sessionId
|
|
120
|
+
: `cron-${task.id}`,
|
|
121
|
+
sessionMode: bindingStatus === 'bound' ? 'persistent' : (runtime.sessionMode === 'fresh' ? 'fresh' : 'persistent'),
|
|
122
|
+
bindingStatus,
|
|
123
|
+
...(typeof runtime.model === 'string' && runtime.model ? { model: runtime.model } : {}),
|
|
124
|
+
...(typeof runtime.maxTurns === 'number' && runtime.maxTurns > 0
|
|
125
|
+
? { maxTurns: runtime.maxTurns }
|
|
126
|
+
: {}),
|
|
127
|
+
},
|
|
128
|
+
stats: {
|
|
129
|
+
runCount: typeof stats.runCount === 'number' ? stats.runCount : 0,
|
|
130
|
+
successCount: typeof stats.successCount === 'number' ? stats.successCount : 0,
|
|
131
|
+
failureCount: typeof stats.failureCount === 'number' ? stats.failureCount : 0,
|
|
132
|
+
skippedCount: typeof stats.skippedCount === 'number' ? stats.skippedCount : 0,
|
|
133
|
+
...(typeof stats.lastRunAt === 'string' ? { lastRunAt: stats.lastRunAt } : {}),
|
|
134
|
+
...(typeof stats.lastSuccessAt === 'string' ? { lastSuccessAt: stats.lastSuccessAt } : {}),
|
|
135
|
+
...(typeof stats.lastFailureAt === 'string' ? { lastFailureAt: stats.lastFailureAt } : {}),
|
|
136
|
+
},
|
|
137
|
+
createdAt: typeof task.createdAt === 'string' ? task.createdAt : now,
|
|
138
|
+
updatedAt: typeof task.updatedAt === 'string' ? task.updatedAt : now,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { parseShortcutSchedule } from './commands.js';
|
|
3
|
+
import { validateCron } from './schema.js';
|
|
4
|
+
import { createTask, listMissed, listTasks, markMissedRead, markRunsRead, patchTask, recentRuns, upsertTask, } from './store.js';
|
|
5
|
+
import { cronToHuman } from './cronTime.js';
|
|
6
|
+
import { intervalToHuman, nextScheduleRunMs } from './scheduleEngine.js';
|
|
7
|
+
export function draftCronFromText(text, context, requestId = randomUUID()) {
|
|
8
|
+
const normalized = normalizeScheduleText(text);
|
|
9
|
+
const [head = '', ...rest] = tokenize(normalized.replace(/^\/cron\s*/i, ''));
|
|
10
|
+
const parsed = parseShortcutSchedule(head, rest);
|
|
11
|
+
const missing = [];
|
|
12
|
+
if (!context.cwd)
|
|
13
|
+
missing.push('workspace');
|
|
14
|
+
if (!context.sessionId)
|
|
15
|
+
missing.push('session');
|
|
16
|
+
if (!head || !parsed)
|
|
17
|
+
missing.push('schedule');
|
|
18
|
+
if (parsed && 'error' in parsed) {
|
|
19
|
+
if (parsed.error.includes('提示词') || parsed.error.includes('workflow'))
|
|
20
|
+
missing.push('action');
|
|
21
|
+
return { requestId, task: null, missing: unique(missing), error: parsed.error };
|
|
22
|
+
}
|
|
23
|
+
if (!parsed || !context.cwd || !context.sessionId) {
|
|
24
|
+
return { requestId, task: null, missing: unique(missing) };
|
|
25
|
+
}
|
|
26
|
+
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone || 'local';
|
|
27
|
+
const task = {
|
|
28
|
+
name: parsed.name,
|
|
29
|
+
...(parsed.description ? { description: parsed.description } : {}),
|
|
30
|
+
status: 'active',
|
|
31
|
+
kind: 'recurring',
|
|
32
|
+
schedule: parsed.cron
|
|
33
|
+
? { type: 'cron', cron: parsed.cron, timezone, jitterMs: 0 }
|
|
34
|
+
: { type: 'interval', intervalMs: parsed.intervalMs, anchorAt: new Date().toISOString(), jitterMs: 0 },
|
|
35
|
+
action: parsed.action,
|
|
36
|
+
runtime: {
|
|
37
|
+
cwd: context.cwd,
|
|
38
|
+
sessionId: context.sessionId,
|
|
39
|
+
sessionMode: 'persistent',
|
|
40
|
+
...(context.model ? { model: context.model } : {}),
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
const previewSchedule = task.schedule.type === 'cron'
|
|
44
|
+
? { ...task.schedule, human: cronToHuman(task.schedule.cron) }
|
|
45
|
+
: { ...task.schedule, anchorAt: task.schedule.anchorAt, human: intervalToHuman(task.schedule.intervalMs) };
|
|
46
|
+
const next = nextScheduleRunMs(previewSchedule, Date.now());
|
|
47
|
+
return {
|
|
48
|
+
requestId,
|
|
49
|
+
task,
|
|
50
|
+
missing: [],
|
|
51
|
+
scheduleHuman: previewSchedule.human,
|
|
52
|
+
...(next ? { nextRunAt: new Date(next).toISOString() } : {}),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export async function createCronFromDraft(draft) {
|
|
56
|
+
assertDraft(draft);
|
|
57
|
+
const task = createTask({
|
|
58
|
+
name: draft.name.trim(),
|
|
59
|
+
...(draft.description?.trim() ? { description: draft.description.trim() } : {}),
|
|
60
|
+
...(draft.schedule.type === 'cron'
|
|
61
|
+
? { cron: draft.schedule.cron, timezone: draft.schedule.timezone }
|
|
62
|
+
: {
|
|
63
|
+
intervalMs: draft.schedule.intervalMs,
|
|
64
|
+
anchorAt: draft.schedule.anchorAt,
|
|
65
|
+
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone || 'local',
|
|
66
|
+
}),
|
|
67
|
+
cwd: draft.runtime.cwd,
|
|
68
|
+
sessionId: draft.runtime.sessionId,
|
|
69
|
+
sessionMode: 'persistent',
|
|
70
|
+
model: draft.runtime.model,
|
|
71
|
+
maxTurns: draft.runtime.maxTurns,
|
|
72
|
+
kind: draft.kind,
|
|
73
|
+
permanent: draft.permanent,
|
|
74
|
+
expiresAt: draft.expiresAt,
|
|
75
|
+
maxRuns: draft.maxRuns,
|
|
76
|
+
jitterMs: draft.schedule.jitterMs ?? 0,
|
|
77
|
+
action: draft.action,
|
|
78
|
+
});
|
|
79
|
+
task.status = draft.status;
|
|
80
|
+
return await upsertTask(task);
|
|
81
|
+
}
|
|
82
|
+
export async function updateCronFromPatch(patch) {
|
|
83
|
+
if (!patch.id)
|
|
84
|
+
throw new Error('缺少定时任务 ID');
|
|
85
|
+
if (patch.schedule?.type === 'cron') {
|
|
86
|
+
const checked = validateCron(patch.schedule.cron);
|
|
87
|
+
if (!checked.ok)
|
|
88
|
+
throw new Error(checked.error);
|
|
89
|
+
}
|
|
90
|
+
const task = await patchTask(patch);
|
|
91
|
+
if (!task)
|
|
92
|
+
throw new Error(`未找到定时任务:${patch.id}`);
|
|
93
|
+
if (task.runtime.bindingStatus !== 'bound' && patch.status === 'active') {
|
|
94
|
+
throw new Error('请先重新绑定工作目录会话');
|
|
95
|
+
}
|
|
96
|
+
return task;
|
|
97
|
+
}
|
|
98
|
+
export async function listCronTasks(filter = {}) {
|
|
99
|
+
const query = filter.query?.trim().toLocaleLowerCase();
|
|
100
|
+
const missed = await listMissed(500);
|
|
101
|
+
const missedTaskIds = new Set(missed.filter((item) => !item.readAt).map((item) => item.taskId));
|
|
102
|
+
const rows = await Promise.all((await listTasks()).map(async (task) => {
|
|
103
|
+
const runs = await recentRuns(task.id, 20);
|
|
104
|
+
const unreadCount = runs.filter((run) => !run.readAt && (run.status === 'failure' || run.attentionReason)).length
|
|
105
|
+
+ (missedTaskIds.has(task.id) ? 1 : 0);
|
|
106
|
+
return { task, recentRuns: runs, unreadCount };
|
|
107
|
+
}));
|
|
108
|
+
return rows.filter(({ task, unreadCount }) => {
|
|
109
|
+
if (filter.cwd && task.runtime.cwd !== filter.cwd)
|
|
110
|
+
return false;
|
|
111
|
+
if (filter.sessionId && task.runtime.sessionId !== filter.sessionId)
|
|
112
|
+
return false;
|
|
113
|
+
if (filter.status && filter.status !== 'all') {
|
|
114
|
+
if (filter.status === 'attention' ? unreadCount === 0 : task.status !== filter.status)
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
if (!query)
|
|
118
|
+
return true;
|
|
119
|
+
const haystack = [task.name, task.description, task.action.type === 'prompt' ? task.action.prompt : task.action.command]
|
|
120
|
+
.filter(Boolean).join(' ').toLocaleLowerCase();
|
|
121
|
+
return haystack.includes(query);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
export async function markCronRead(taskId) {
|
|
125
|
+
await Promise.all([markRunsRead(taskId), markMissedRead(taskId)]);
|
|
126
|
+
}
|
|
127
|
+
function assertDraft(draft) {
|
|
128
|
+
if (!draft.name.trim())
|
|
129
|
+
throw new Error('请输入任务名称');
|
|
130
|
+
if (!draft.runtime.cwd)
|
|
131
|
+
throw new Error('请选择工作目录');
|
|
132
|
+
if (!draft.runtime.sessionId)
|
|
133
|
+
throw new Error('请选择绑定会话');
|
|
134
|
+
if (draft.runtime.sessionMode === 'fresh')
|
|
135
|
+
throw new Error('新任务必须绑定原会话');
|
|
136
|
+
if (draft.schedule.type === 'cron') {
|
|
137
|
+
const checked = validateCron(draft.schedule.cron);
|
|
138
|
+
if (!checked.ok)
|
|
139
|
+
throw new Error(checked.error);
|
|
140
|
+
}
|
|
141
|
+
else if (!Number.isFinite(draft.schedule.intervalMs) || draft.schedule.intervalMs < 60_000) {
|
|
142
|
+
throw new Error('固定间隔最短为 1 分钟');
|
|
143
|
+
}
|
|
144
|
+
if (draft.action.type === 'prompt' ? !draft.action.prompt.trim() : !draft.action.command.trim()) {
|
|
145
|
+
throw new Error('请输入执行内容');
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function normalizeScheduleText(value) {
|
|
149
|
+
return value.trim()
|
|
150
|
+
.replace(/^请(?:帮我)?/u, '')
|
|
151
|
+
.replace(/每个工作日(?:的)?(?:早上|上午)?\s*/u, '工作日 ')
|
|
152
|
+
.replace(/每天(?:的)?(?:早上|上午)?\s*/u, '每天 ')
|
|
153
|
+
.replace(/每周([一二三四五六日天])(?:的)?(?:早上|上午)?\s*/u, '每周$1 ')
|
|
154
|
+
.replace(/每隔\s*(\d+)\s*分钟/u, '$1m')
|
|
155
|
+
.replace(/每隔\s*(\d+)\s*小时/u, '$1h')
|
|
156
|
+
.replace(/每隔\s*(\d+)\s*天/u, '$1d')
|
|
157
|
+
.replace(/早上\s*(\d{1,2})[点时](\d{1,2})?分?/u, (_, h, m) => `${h}:${m ?? '00'}`)
|
|
158
|
+
.replace(/(\d{1,2})[点时](\d{1,2})分/u, '$1:$2')
|
|
159
|
+
.replace(/\s+/g, ' ')
|
|
160
|
+
.trim();
|
|
161
|
+
}
|
|
162
|
+
function tokenize(input) {
|
|
163
|
+
return input.match(/"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|\S+/g)?.map((item) => item.replace(/^['"]|['"]$/g, '')) ?? [];
|
|
164
|
+
}
|
|
165
|
+
function unique(items) {
|
|
166
|
+
return [...new Set(items)];
|
|
167
|
+
}
|