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
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ============================================================
|
|
3
|
-
* plugins/ralph-wiggum/plugin.ts —— ralph-wiggum 真·插件入口
|
|
4
|
-
* ------------------------------------------------------------
|
|
5
|
-
* 把原 src/plugins/pluginRunner.ts 的 do-while 循环驱动整段搬来。
|
|
6
|
-
* 对外通过 PluginApi.runCommand 暴露 /ralph-loop。
|
|
7
|
-
*
|
|
8
|
-
* 循环契约:
|
|
9
|
-
* - 每轮把 history 重置成进入循环前的快照(fresh context)
|
|
10
|
-
* - 用 GoalState.composeContext() 拼 PLAN/BUILD/VERIFY/HEAL 阶段信息
|
|
11
|
-
* - 跑 runQuery
|
|
12
|
-
* - 检测 <promise>DONE</promise> → runVerification → 通过则退出
|
|
13
|
-
* - 检测 <PROMISE>NEED_REPLAN</PROMISE> → forceSetPhase(PLAN)
|
|
14
|
-
* - executeStopHook 是咨询式:block 才把 reason 注入下一轮,pass 不退出
|
|
15
|
-
*
|
|
16
|
-
* 终止(独占):sentinel + verify 通过 / 达 max-iterations / abort / 安全天花板
|
|
17
|
-
*
|
|
18
|
-
* Windows 上 hooks/stop-hook.sh 不可用,但循环不依赖 hook,功能完整,
|
|
19
|
-
* 只是 hook 的咨询通道失效。
|
|
20
|
-
* ============================================================
|
|
21
|
-
*/
|
|
22
|
-
import { fileURLToPath } from 'node:url';
|
|
23
|
-
import { dirname } from 'node:path';
|
|
24
|
-
import { runQuery, getWorkingDir, } from '../../src/plugin-sdk.js';
|
|
25
|
-
import { parseVerifyArgs, runVerification } from '../../src/infra/verification.js';
|
|
26
|
-
import { GoalState, Phase } from './src/goalState.js';
|
|
27
|
-
import { makeCompletionMatcher, hasNeedReplanSentinel, hasNeedGoalRevisionSentinel, extractLearnings, } from './src/sentinels.js';
|
|
28
|
-
import { executeStopHook } from './src/stopHookRunner.js';
|
|
29
|
-
const PLUGIN_NAME = 'ralph-wiggum';
|
|
30
|
-
const DEFAULT_MAX_ITERATIONS = 50;
|
|
31
|
-
const SAFETY_CEILING = 200;
|
|
32
|
-
const PLUGIN_ROOT = dirname(fileURLToPath(import.meta.url));
|
|
33
|
-
function extractMaxIterations(args) {
|
|
34
|
-
const match = args.match(/--max-iterations\s+(\d+)/i);
|
|
35
|
-
return match ? parseInt(match[1], 10) : undefined;
|
|
36
|
-
}
|
|
37
|
-
/** 解析 --completion-promise "TEXT"(带引号优先)或 --completion-promise TOKEN。 */
|
|
38
|
-
function extractCompletionPromise(args) {
|
|
39
|
-
const quoted = args.match(/--completion-promise\s+"([^"]*)"/i);
|
|
40
|
-
if (quoted)
|
|
41
|
-
return quoted[1].trim() || undefined;
|
|
42
|
-
const token = args.match(/--completion-promise\s+(\S+)/i);
|
|
43
|
-
return token ? token[1].trim() || undefined : undefined;
|
|
44
|
-
}
|
|
45
|
-
/** 从 args 里剥掉控制 flag,得到喂给 LLM 的"干净目标文本"(避免 --verify 等泄漏进 prompt)。 */
|
|
46
|
-
function stripControlFlags(args) {
|
|
47
|
-
return args
|
|
48
|
-
.replace(/--max-iterations\s+\d+/gi, '')
|
|
49
|
-
.replace(/--completion-promise\s+"[^"]*"/gi, '')
|
|
50
|
-
.replace(/--completion-promise\s+\S+/gi, '')
|
|
51
|
-
.replace(/--verify\s+"[^"]*"/gi, '')
|
|
52
|
-
.replace(/--verify\s+\S+/gi, '')
|
|
53
|
-
.replace(/\s{2,}/g, ' ')
|
|
54
|
-
.trim();
|
|
55
|
-
}
|
|
56
|
-
async function* runRalphLoop(args, ctx) {
|
|
57
|
-
const { provider, history, signal } = ctx;
|
|
58
|
-
const maxIter = Math.min(extractMaxIterations(args) ?? DEFAULT_MAX_ITERATIONS, SAFETY_CEILING);
|
|
59
|
-
// 没有 args(用户只敲 /ralph-loop)→ 留个最小 goal placeholder,避免 GoalState.init 拒空串
|
|
60
|
-
// 控制 flag(--max-iterations / --verify / --completion-promise)都从原始 args 解析,
|
|
61
|
-
// userGoal 才用剥过的干净文本,避免 flag 泄漏进喂给 LLM 的 prompt
|
|
62
|
-
const userGoal = stripControlFlags(args) || '(未提供目标)';
|
|
63
|
-
yield {
|
|
64
|
-
type: 'plugin_progress',
|
|
65
|
-
pluginId: PLUGIN_NAME,
|
|
66
|
-
current: 0,
|
|
67
|
-
max: maxIter,
|
|
68
|
-
message: 'Ralph Wiggum copy-task loop 启动',
|
|
69
|
-
};
|
|
70
|
-
const checks = parseVerifyArgs(args);
|
|
71
|
-
// 完成哨兵判定器:不传 --completion-promise 只认写死集合 DONE|COMPLETE|GOAL_COMPLETE,
|
|
72
|
-
// 传了则在写死集合基础上叠加自定义短语(超集,向后兼容)
|
|
73
|
-
const completePhrase = extractCompletionPromise(args);
|
|
74
|
-
const isComplete = makeCompletionMatcher(completePhrase);
|
|
75
|
-
// sessionTag = 插件名 → 多插件可并发不打架,/new 也能扫到清掉
|
|
76
|
-
const goalState = new GoalState(getWorkingDir(), PLUGIN_NAME);
|
|
77
|
-
await goalState.reset();
|
|
78
|
-
await goalState.init(userGoal, checks);
|
|
79
|
-
await goalState.appendProgress(`=== Loop 启动 === 目标: ${userGoal.slice(0, 120)}...`);
|
|
80
|
-
// 进循环前快照 history —— 每轮 runQuery 前用它重置,保证 fresh context
|
|
81
|
-
const baseHistory = history.slice();
|
|
82
|
-
let iterationCount = 0;
|
|
83
|
-
let consecutiveFailures = 0;
|
|
84
|
-
let currentInput = userGoal;
|
|
85
|
-
let finalAssistantMsg = null;
|
|
86
|
-
try {
|
|
87
|
-
do {
|
|
88
|
-
iterationCount++;
|
|
89
|
-
if (iterationCount > maxIter) {
|
|
90
|
-
await goalState.forceSetPhase(Phase.DONE, `达到迭代上限 ${maxIter}`);
|
|
91
|
-
await goalState.appendLearning(`[迭代上限] 循环在 ${iterationCount - 1} 轮后强制终止,可能目标过大或陷入死循环`);
|
|
92
|
-
yield {
|
|
93
|
-
type: 'error',
|
|
94
|
-
error: `Loop 已达迭代上限 ${maxIter},自动停止`,
|
|
95
|
-
code: 'max_turns',
|
|
96
|
-
};
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
if (signal?.aborted) {
|
|
100
|
-
yield { type: 'interrupted' };
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
yield {
|
|
104
|
-
type: 'plugin_progress',
|
|
105
|
-
pluginId: PLUGIN_NAME,
|
|
106
|
-
current: iterationCount,
|
|
107
|
-
max: maxIter,
|
|
108
|
-
};
|
|
109
|
-
// fresh context:清空 history,重置为入循环前的快照
|
|
110
|
-
history.length = 0;
|
|
111
|
-
history.push(...baseHistory);
|
|
112
|
-
const freshContext = goalState.composeContext(iterationCount);
|
|
113
|
-
const enhancedInput = `${freshContext}\n\n${currentInput}`;
|
|
114
|
-
yield* runQuery(enhancedInput, {
|
|
115
|
-
provider,
|
|
116
|
-
history,
|
|
117
|
-
signal,
|
|
118
|
-
maxTurns: ctx.maxTurns,
|
|
119
|
-
sessionState: ctx.sessionState,
|
|
120
|
-
});
|
|
121
|
-
if (signal?.aborted) {
|
|
122
|
-
yield { type: 'interrupted' };
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
// 从本轮 history 抓最后一个 assistant 消息(runQuery 已 push 进去)
|
|
126
|
-
const lastAssistantIdx = (() => {
|
|
127
|
-
for (let i = history.length - 1; i >= 0; i--) {
|
|
128
|
-
if (history[i].role === 'assistant')
|
|
129
|
-
return i;
|
|
130
|
-
}
|
|
131
|
-
return -1;
|
|
132
|
-
})();
|
|
133
|
-
finalAssistantMsg =
|
|
134
|
-
lastAssistantIdx >= 0 ? history[lastAssistantIdx] : null;
|
|
135
|
-
const lastAssistantText = finalAssistantMsg
|
|
136
|
-
? typeof finalAssistantMsg.content === 'string'
|
|
137
|
-
? finalAssistantMsg.content
|
|
138
|
-
: JSON.stringify(finalAssistantMsg.content)
|
|
139
|
-
: '';
|
|
140
|
-
// 每轮提取 <learning> 并落盘,让经验跨 fresh-context 迭代存活
|
|
141
|
-
for (const lesson of extractLearnings(lastAssistantText)) {
|
|
142
|
-
await goalState.appendLearning(`[迭代 ${iterationCount}] ${lesson}`);
|
|
143
|
-
}
|
|
144
|
-
if (isComplete(lastAssistantText)) {
|
|
145
|
-
// 哨兵:可能来自任意阶段(包括 iter 1 的 PLAN),用 force 跳到 VERIFY
|
|
146
|
-
await goalState.forceSetPhase(Phase.VERIFY, '检测到完成哨兵,进入验证');
|
|
147
|
-
await goalState.appendProgress(`迭代 ${iterationCount}: 检测到完成哨兵,运行验证门...`);
|
|
148
|
-
if (checks.length > 0) {
|
|
149
|
-
const vResult = await runVerification(checks);
|
|
150
|
-
if (!vResult.passed) {
|
|
151
|
-
consecutiveFailures++;
|
|
152
|
-
await goalState.appendLearning(`[迭代 ${iterationCount}] 声称完成但验证未通过: ${vResult.summary}`);
|
|
153
|
-
// 验证未通过不是致命错误:降级为 warning(不映射 stop_reason),
|
|
154
|
-
// 再补一条进度保活进度条,避免 UI 误以为循环停了
|
|
155
|
-
yield {
|
|
156
|
-
type: 'warning',
|
|
157
|
-
message: `⚠️ 验证未通过: ${vResult.summary}。继续尝试...`,
|
|
158
|
-
};
|
|
159
|
-
yield {
|
|
160
|
-
type: 'plugin_progress',
|
|
161
|
-
pluginId: PLUGIN_NAME,
|
|
162
|
-
current: iterationCount,
|
|
163
|
-
max: maxIter,
|
|
164
|
-
message: '验证未通过,回到构建修复',
|
|
165
|
-
};
|
|
166
|
-
// 跨平台决策记录(不再只靠 POSIX stop-hook)
|
|
167
|
-
await goalState.recordDecision({
|
|
168
|
-
iteration: iterationCount,
|
|
169
|
-
phase: Phase.VERIFY,
|
|
170
|
-
summary: '验证门',
|
|
171
|
-
}, ['判定完成', '回退继续'], '回退继续', vResult.summary.slice(0, 200));
|
|
172
|
-
if (consecutiveFailures >= 3) {
|
|
173
|
-
await goalState.forceSetPhase(Phase.HEAL, `连续 ${consecutiveFailures} 次验证失败`);
|
|
174
|
-
}
|
|
175
|
-
else {
|
|
176
|
-
// 语义诚实:VERIFY→BUILD 不是合法边,用 force 而非借合法边
|
|
177
|
-
await goalState.forceSetPhase(Phase.BUILD, '验证未通过,回到构建修复');
|
|
178
|
-
}
|
|
179
|
-
continue;
|
|
180
|
-
}
|
|
181
|
-
await goalState.appendProgress(`✅ 验证通过: ${vResult.summary}`);
|
|
182
|
-
}
|
|
183
|
-
await goalState.setPhase(Phase.DONE, 'goal complete & verified');
|
|
184
|
-
// 成功路径决策记录(vResult 定义在 checks.length>0 块内、此处作用域不可见,
|
|
185
|
-
// 故 reasoning 统一写 '目标完成',不引用 vResult)
|
|
186
|
-
await goalState.recordDecision({
|
|
187
|
-
iteration: iterationCount,
|
|
188
|
-
phase: Phase.VERIFY,
|
|
189
|
-
summary: '验证门',
|
|
190
|
-
}, ['判定完成', '回退继续'], '判定完成', '目标完成');
|
|
191
|
-
yield {
|
|
192
|
-
type: 'plugin_progress',
|
|
193
|
-
pluginId: PLUGIN_NAME,
|
|
194
|
-
current: iterationCount,
|
|
195
|
-
max: maxIter,
|
|
196
|
-
message: '✅ 完成并通过验证',
|
|
197
|
-
};
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
// NEED_GOAL_REVISION 逃生门:目标本身不可达,干净终止请人工修订
|
|
201
|
-
// (区别于 NEED_REPLAN —— 那是换方案,这是换目标)
|
|
202
|
-
if (hasNeedGoalRevisionSentinel(lastAssistantText)) {
|
|
203
|
-
await goalState.forceSetPhase(Phase.DONE, 'agent 报告目标本身需修订');
|
|
204
|
-
await goalState.appendLearning('[NEED_GOAL_REVISION] Agent 认为目标本身有问题,需人工修订');
|
|
205
|
-
await goalState.recordDecision({
|
|
206
|
-
iteration: iterationCount,
|
|
207
|
-
phase: goalState.currentPhase,
|
|
208
|
-
summary: 'NEED_GOAL_REVISION',
|
|
209
|
-
}, ['继续硬上', '停止请人工改目标'], '停止请人工改目标', '目标本身不可达');
|
|
210
|
-
yield {
|
|
211
|
-
type: 'warning',
|
|
212
|
-
message: '🛑 Agent 判断目标本身需要人工修订,循环已停止。请检查并调整目标后重试。',
|
|
213
|
-
};
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
if (hasNeedReplanSentinel(lastAssistantText)) {
|
|
217
|
-
await goalState.forceSetPhase(Phase.PLAN, 'agent 请求重新规划');
|
|
218
|
-
await goalState.appendLearning('[NEED_REPLAN] Agent 认为当前方案不可行,需要重新规划');
|
|
219
|
-
await goalState.appendProgress('Agent 请求 NEED_REPLAN,回 PLAN 阶段');
|
|
220
|
-
await goalState.recordDecision({
|
|
221
|
-
iteration: iterationCount,
|
|
222
|
-
phase: goalState.currentPhase,
|
|
223
|
-
summary: 'NEED_REPLAN',
|
|
224
|
-
}, ['继续当前方案', '回 PLAN 重规划'], '回 PLAN 重规划', 'agent 认为方案不可行');
|
|
225
|
-
consecutiveFailures = 0;
|
|
226
|
-
continue;
|
|
227
|
-
}
|
|
228
|
-
// PLAN 阶段跑过一轮还没哨兵,认为规划已完成,自动推进 BUILD
|
|
229
|
-
if (goalState.currentPhase === Phase.PLAN && iterationCount >= 2) {
|
|
230
|
-
await goalState.setPhase(Phase.BUILD, '规划阶段已完成,进入构建');
|
|
231
|
-
}
|
|
232
|
-
// Stop-hook 咨询式调用:block 才把 reason 注入下一轮 prompt
|
|
233
|
-
// pass / 报错都不再终止循环;终止由 sentinel/maxIter/abort/NEED_REPLAN 独占
|
|
234
|
-
const hookResult = await executeStopHook(PLUGIN_ROOT, lastAssistantText);
|
|
235
|
-
if (hookResult.decision === 'block' && hookResult.reason) {
|
|
236
|
-
currentInput = hookResult.reason;
|
|
237
|
-
consecutiveFailures = 0;
|
|
238
|
-
await goalState.recordDecision({
|
|
239
|
-
iteration: iterationCount,
|
|
240
|
-
phase: goalState.currentPhase,
|
|
241
|
-
summary: 'stop-hook 反馈',
|
|
242
|
-
}, ['继续循环', '终止'], '继续循环', hookResult.reason.slice(0, 200));
|
|
243
|
-
if (hookResult.systemMessage) {
|
|
244
|
-
baseHistory.push({
|
|
245
|
-
role: 'user',
|
|
246
|
-
content: `[Plugin Stop Hook] ${hookResult.systemMessage}`,
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
await goalState.appendProgress(`迭代 ${iterationCount}: Stop hook block,注入反馈继续`);
|
|
250
|
-
}
|
|
251
|
-
else {
|
|
252
|
-
await goalState.appendProgress(`迭代 ${iterationCount}: 无哨兵 / hook pass,继续下一轮`);
|
|
253
|
-
}
|
|
254
|
-
} while (true);
|
|
255
|
-
}
|
|
256
|
-
finally {
|
|
257
|
-
// 收尾:把循环里临时累积的 history 还原成 baseHistory + 最后一轮 assistant
|
|
258
|
-
// 这样 TUI 上看到的就是"一次问答",而不是 N 轮重复
|
|
259
|
-
history.length = 0;
|
|
260
|
-
history.push(...baseHistory);
|
|
261
|
-
if (finalAssistantMsg) {
|
|
262
|
-
history.push(finalAssistantMsg);
|
|
263
|
-
}
|
|
264
|
-
await goalState.cleanup();
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
const api = {
|
|
268
|
-
async *runCommand(commandName, args, ctx) {
|
|
269
|
-
if (commandName === 'ralph-loop') {
|
|
270
|
-
yield* runRalphLoop(args, ctx);
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
// 其它命令(help / cancel-ralph)→ 不接管,让框架走声明式 fallback
|
|
274
|
-
yield {
|
|
275
|
-
type: 'error',
|
|
276
|
-
error: `ralph-wiggum: 命令 /${commandName} 未由 plugin.ts 接管`,
|
|
277
|
-
};
|
|
278
|
-
},
|
|
279
|
-
};
|
|
280
|
-
export default api;
|
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
import { mkdir, appendFile, writeFile, unlink, rmdir } from 'node:fs/promises';
|
|
2
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
export var Phase;
|
|
5
|
-
(function (Phase) {
|
|
6
|
-
Phase["PLAN"] = "plan";
|
|
7
|
-
Phase["BUILD"] = "build";
|
|
8
|
-
Phase["VERIFY"] = "verify";
|
|
9
|
-
Phase["HEAL"] = "heal";
|
|
10
|
-
Phase["DONE"] = "done";
|
|
11
|
-
})(Phase || (Phase = {}));
|
|
12
|
-
const VALID_PHASES = new Set(Object.values(Phase));
|
|
13
|
-
/**
|
|
14
|
-
* 阶段转移表使用说明(诚实注释):
|
|
15
|
-
*
|
|
16
|
-
* 这张表里的 event 名(plan_complete / tests_failing / all_pass 等)是**描述性的**,
|
|
17
|
-
* 阶段实际由驱动(plugin.ts)用启发式推进或 `forceSetPhase` 直接设置——
|
|
18
|
-
* **不是 LLM 驱动的事件状态机**。
|
|
19
|
-
*
|
|
20
|
-
* `setPhase` 只用这张表做「目标阶段是否可达」的合法性校验:
|
|
21
|
-
* 只要 PHASE_TRANSITIONS[from] 的 values 里包含 to,就视为合法,跟传入的 `reason` 字符串无关。
|
|
22
|
-
* `reason` 仅是给人看的日志文本,不参与任何匹配或校验。
|
|
23
|
-
*
|
|
24
|
-
* 想跳过校验强制切阶段,用 `forceSetPhase`。
|
|
25
|
-
*/
|
|
26
|
-
const PHASE_TRANSITIONS = {
|
|
27
|
-
[Phase.PLAN]: {
|
|
28
|
-
plan_complete: Phase.BUILD,
|
|
29
|
-
stuck: Phase.PLAN,
|
|
30
|
-
},
|
|
31
|
-
[Phase.BUILD]: {
|
|
32
|
-
task_complete: Phase.VERIFY,
|
|
33
|
-
need_replan: Phase.PLAN,
|
|
34
|
-
tests_failing: Phase.HEAL,
|
|
35
|
-
},
|
|
36
|
-
[Phase.VERIFY]: {
|
|
37
|
-
all_pass: Phase.BUILD,
|
|
38
|
-
failures: Phase.HEAL,
|
|
39
|
-
goal_complete: Phase.DONE,
|
|
40
|
-
},
|
|
41
|
-
[Phase.HEAL]: {
|
|
42
|
-
fixed: Phase.VERIFY,
|
|
43
|
-
cannot_fix_locally: Phase.PLAN,
|
|
44
|
-
},
|
|
45
|
-
[Phase.DONE]: {},
|
|
46
|
-
};
|
|
47
|
-
function isLegalTransition(from, to) {
|
|
48
|
-
if (from === to)
|
|
49
|
-
return true;
|
|
50
|
-
const allowed = PHASE_TRANSITIONS[from];
|
|
51
|
-
if (!allowed)
|
|
52
|
-
return false;
|
|
53
|
-
return Object.values(allowed).includes(to);
|
|
54
|
-
}
|
|
55
|
-
const LEARNINGS_TAIL_LINES = 20;
|
|
56
|
-
/** 每个阶段给 LLM 的一行行动指令(fresh-context 下 LLM 看不到 SKILL.md,靠这个 steer 行为)。 */
|
|
57
|
-
const PHASE_DIRECTIVES = {
|
|
58
|
-
[Phase.PLAN]: '分析任务、拆解步骤、识别风险与未知项;先想清楚再动手。',
|
|
59
|
-
[Phase.BUILD]: '按计划实现,一次只聚焦一个子任务,落到具体文件改动。',
|
|
60
|
-
[Phase.VERIFY]: '运行测试 / 检查输出 / 核对验收标准,用证据确认,别凭感觉。',
|
|
61
|
-
[Phase.HEAL]: '已多次验证失败:停止猜测,定位根因(读报错、加日志、做最小复现)再修,避免回归。',
|
|
62
|
-
[Phase.DONE]: '目标已达成。',
|
|
63
|
-
};
|
|
64
|
-
export class GoalState {
|
|
65
|
-
dir;
|
|
66
|
-
constructor(workspaceDir, sessionTag) {
|
|
67
|
-
const suffix = sessionTag ? `-${sessionTag}` : '';
|
|
68
|
-
this.dir = join(workspaceDir, `.minimal-agent${suffix}`);
|
|
69
|
-
}
|
|
70
|
-
async reset() {
|
|
71
|
-
const files = ['goal.md', 'completion.md', 'phase.md', 'progress.md', 'learnings.md', 'decisions.md'];
|
|
72
|
-
for (const f of files) {
|
|
73
|
-
try {
|
|
74
|
-
await unlink(join(this.dir, f));
|
|
75
|
-
}
|
|
76
|
-
catch {
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
async init(goal, criteria) {
|
|
81
|
-
await mkdir(this.dir, { recursive: true });
|
|
82
|
-
const files = {
|
|
83
|
-
goal: `# 不可变目标 (IMMUTABLE GOAL)\n\n${goal}\n`,
|
|
84
|
-
completion: JSON.stringify(criteria, null, 2),
|
|
85
|
-
phase: Phase.PLAN,
|
|
86
|
-
progress: '',
|
|
87
|
-
learnings: '',
|
|
88
|
-
decisions: '',
|
|
89
|
-
};
|
|
90
|
-
for (const [name, content] of Object.entries(files)) {
|
|
91
|
-
const path = join(this.dir, `${name}.md`);
|
|
92
|
-
if (!existsSync(path)) {
|
|
93
|
-
await writeFile(path, content);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
get goal() {
|
|
98
|
-
try {
|
|
99
|
-
return readFileSync(join(this.dir, 'goal.md'), 'utf8').trim();
|
|
100
|
-
}
|
|
101
|
-
catch {
|
|
102
|
-
return '';
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
get completionCriteria() {
|
|
106
|
-
try {
|
|
107
|
-
const raw = readFileSync(join(this.dir, 'completion.md'), 'utf8').trim();
|
|
108
|
-
return JSON.parse(raw);
|
|
109
|
-
}
|
|
110
|
-
catch {
|
|
111
|
-
return [];
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
get currentPhase() {
|
|
115
|
-
try {
|
|
116
|
-
const raw = readFileSync(join(this.dir, 'phase.md'), 'utf8').trim();
|
|
117
|
-
if (VALID_PHASES.has(raw)) {
|
|
118
|
-
return raw;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
catch {
|
|
122
|
-
}
|
|
123
|
-
return Phase.PLAN;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* 切换阶段。`reason` 是给人看的日志文本,不参与校验。
|
|
127
|
-
* 校验只看 from→to 是否在 PHASE_TRANSITIONS 表里有路径(任意 event 通向 to 即合法)。
|
|
128
|
-
* 想绕开 FSM 用 forceSetPhase。
|
|
129
|
-
*/
|
|
130
|
-
async setPhase(phase, reason) {
|
|
131
|
-
if (!VALID_PHASES.has(phase)) {
|
|
132
|
-
throw new Error(`Invalid phase: ${phase}`);
|
|
133
|
-
}
|
|
134
|
-
const current = this.currentPhase;
|
|
135
|
-
if (!isLegalTransition(current, phase)) {
|
|
136
|
-
throw new Error(`非法阶段切换: ${current} → ${phase}。该目标阶段不在 PHASE_TRANSITIONS[${current}] 的可达集合内,需要走 forceSetPhase。`);
|
|
137
|
-
}
|
|
138
|
-
await writeFile(join(this.dir, 'phase.md'), phase);
|
|
139
|
-
await this.appendProgress(`PHASE → ${phase}: ${reason}`);
|
|
140
|
-
}
|
|
141
|
-
async forceSetPhase(phase, reason) {
|
|
142
|
-
if (!VALID_PHASES.has(phase)) {
|
|
143
|
-
throw new Error(`Invalid phase: ${phase}`);
|
|
144
|
-
}
|
|
145
|
-
await writeFile(join(this.dir, 'phase.md'), phase);
|
|
146
|
-
await this.appendProgress(`PHASE → ${phase}: ${reason}`);
|
|
147
|
-
}
|
|
148
|
-
async appendProgress(line) {
|
|
149
|
-
const timestamp = new Date().toLocaleTimeString('en-US', { hour12: false });
|
|
150
|
-
await appendFile(join(this.dir, 'progress.md'), `[${timestamp}] ${line}\n`);
|
|
151
|
-
}
|
|
152
|
-
tailProgress(n) {
|
|
153
|
-
try {
|
|
154
|
-
const content = readFileSync(join(this.dir, 'progress.md'), 'utf8');
|
|
155
|
-
const lines = content.trim().split('\n').filter(Boolean);
|
|
156
|
-
return lines.slice(-n).join('\n');
|
|
157
|
-
}
|
|
158
|
-
catch {
|
|
159
|
-
return '';
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
async appendLearning(lesson) {
|
|
163
|
-
await appendFile(join(this.dir, 'learnings.md'), `- ${lesson}\n`);
|
|
164
|
-
}
|
|
165
|
-
get learnings() {
|
|
166
|
-
try {
|
|
167
|
-
const raw = readFileSync(join(this.dir, 'learnings.md'), 'utf8').trim();
|
|
168
|
-
if (!raw)
|
|
169
|
-
return '';
|
|
170
|
-
const lines = raw.split('\n').filter(Boolean);
|
|
171
|
-
return lines.slice(-LEARNINGS_TAIL_LINES).join('\n');
|
|
172
|
-
}
|
|
173
|
-
catch {
|
|
174
|
-
return '';
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
async recordDecision(ctx, options, chosen, reasoning) {
|
|
178
|
-
const entry = {
|
|
179
|
-
iteration: ctx.iteration,
|
|
180
|
-
phase: ctx.phase,
|
|
181
|
-
contextSummary: ctx.summary,
|
|
182
|
-
options,
|
|
183
|
-
chosen,
|
|
184
|
-
reasoning,
|
|
185
|
-
};
|
|
186
|
-
const line = JSON.stringify(entry);
|
|
187
|
-
await appendFile(join(this.dir, 'decisions.md'), `${line}\n`);
|
|
188
|
-
}
|
|
189
|
-
summarizeDecisions(maxEntries = 5) {
|
|
190
|
-
try {
|
|
191
|
-
const content = readFileSync(join(this.dir, 'decisions.md'), 'utf8');
|
|
192
|
-
const lines = content.trim().split('\n').filter(Boolean);
|
|
193
|
-
const entries = [];
|
|
194
|
-
for (const line of lines.slice(-maxEntries * 2)) {
|
|
195
|
-
try {
|
|
196
|
-
entries.push(JSON.parse(line));
|
|
197
|
-
}
|
|
198
|
-
catch {
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
const sliced = entries.slice(-maxEntries);
|
|
202
|
-
// 无有效条目(文件存在但为空)时也统一返回占位文本
|
|
203
|
-
if (sliced.length === 0)
|
|
204
|
-
return '(无决策记录)';
|
|
205
|
-
return sliced
|
|
206
|
-
.map((e) => `迭代 ${e.iteration}(${e.phase}): 在 [${e.options.join(', ')}] 中选择了 **${e.chosen}**,原因:${e.reasoning.slice(0, 80)}`)
|
|
207
|
-
.join('\n');
|
|
208
|
-
}
|
|
209
|
-
catch {
|
|
210
|
-
return '(无决策记录)';
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
composeContext(iteration) {
|
|
214
|
-
const sections = [];
|
|
215
|
-
// 不可变目标段:去掉 NEED_GOAL_REVISION 提示(已移到通信协议段统一说明)
|
|
216
|
-
sections.push(`# 不可变目标 (IMMUTABLE GOAL)\n${this.goal}\n⚠️ 你不能修改或扩大上述目标。`);
|
|
217
|
-
// 当前阶段 + 对应的一行行动指令
|
|
218
|
-
sections.push(`# 当前阶段: ${this.currentPhase.toUpperCase()}\n${PHASE_DIRECTIVES[this.currentPhase]}`);
|
|
219
|
-
// 与循环驱动的通信协议:哨兵约定 + learning 标记
|
|
220
|
-
sections.push([
|
|
221
|
-
'# 与循环驱动的通信协议(务必遵守)',
|
|
222
|
-
'- 任务**真正完成**时输出 `<promise>DONE</promise>`,驱动会运行验证门确认。',
|
|
223
|
-
'- 当前方案走不通、要换打法(目标不变)时输出 `<PROMISE>NEED_REPLAN</PROMISE>`。',
|
|
224
|
-
'- **目标本身**有问题、不改目标就无法完成时输出 `<PROMISE>NEED_GOAL_REVISION</PROMISE>`,驱动会停止并请人工修订。',
|
|
225
|
-
'- 踩到的坑 / 教训用 `<learning>一句话</learning>` 标记,驱动会自动存档供后续迭代参考。',
|
|
226
|
-
'⚠️ 切勿为逃出循环而谎报完成——只有陈述完全为真时才输出完成哨兵。',
|
|
227
|
-
].join('\n'));
|
|
228
|
-
const lrn = this.learnings;
|
|
229
|
-
if (lrn) {
|
|
230
|
-
sections.push(`# 关键教训(必须遵守,避免重复踩坑)\n${lrn}`);
|
|
231
|
-
}
|
|
232
|
-
const decisions = this.summarizeDecisions(3);
|
|
233
|
-
if (decisions !== '(无决策记录)') {
|
|
234
|
-
sections.push(`# 历史关键决策(请参考,避免重复试错)\n${decisions}`);
|
|
235
|
-
}
|
|
236
|
-
const recentProgress = this.tailProgress(10);
|
|
237
|
-
if (recentProgress) {
|
|
238
|
-
sections.push(`# 最近进度\n${recentProgress}`);
|
|
239
|
-
}
|
|
240
|
-
sections.push(`---\n\n# 本轮任务 (迭代 ${iteration})`);
|
|
241
|
-
return sections.join('\n\n---\n\n');
|
|
242
|
-
}
|
|
243
|
-
async cleanup() {
|
|
244
|
-
const files = ['goal.md', 'completion.md', 'phase.md', 'progress.md', 'learnings.md', 'decisions.md'];
|
|
245
|
-
for (const f of files) {
|
|
246
|
-
try {
|
|
247
|
-
await unlink(join(this.dir, f));
|
|
248
|
-
}
|
|
249
|
-
catch {
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
try {
|
|
253
|
-
await rmdir(this.dir);
|
|
254
|
-
}
|
|
255
|
-
catch {
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ============================================================
|
|
3
|
-
* plugins/ralph-wiggum/src/sentinels.ts —— LLM 输出哨兵协议
|
|
4
|
-
* ------------------------------------------------------------
|
|
5
|
-
* Ralph 通过"在回答里输出特定标签"与循环驱动(plugin.ts)通信:
|
|
6
|
-
*
|
|
7
|
-
* <promise>DONE</promise> / <promise>COMPLETE</promise> / <promise>GOAL_COMPLETE</promise>
|
|
8
|
-
* (或用户经 `--completion-promise "<短语>"` 指定的自定义短语)
|
|
9
|
-
* → 当前轮 LLM 认为目标完成;驱动进入验证门(--verify)确认后才真正退出。
|
|
10
|
-
*
|
|
11
|
-
* <PROMISE>NEED_REPLAN</PROMISE>
|
|
12
|
-
* → 当前方案走不通、需要换打法(**目标不变**);驱动强转回 PLAN 阶段。
|
|
13
|
-
*
|
|
14
|
-
* <PROMISE>NEED_GOAL_REVISION</PROMISE>
|
|
15
|
-
* → **目标本身**有问题,无法在不改目标的前提下完成;驱动**干净终止**,请人工修订目标
|
|
16
|
-
* (区别于 NEED_REPLAN:那是换方案,这是换目标)。
|
|
17
|
-
*
|
|
18
|
-
* <learning>一句话</learning>(可多次)
|
|
19
|
-
* → LLM 主动记录的踩坑 / 教训;驱动**每轮**提取并追加到 learnings.md,
|
|
20
|
-
* 让经验跨 fresh-context 迭代存活——这是 Ralph 能收敛的关键。
|
|
21
|
-
*
|
|
22
|
-
* 哨兵集中在这里方便审计与扩展;匹配全部 case-insensitive。
|
|
23
|
-
* ⚠️ rich 插件路径下 commands/ralph-loop.md 的 prompt body **不会**喂给 LLM
|
|
24
|
-
* (pluginRunner 命中 runCommand 即接管),故以上协议由 GoalState.composeContext
|
|
25
|
-
* 注入 prompt,本文件只负责"解析 LLM 回吐的标签"。
|
|
26
|
-
* ============================================================
|
|
27
|
-
*/
|
|
28
|
-
/** 写死的完成短语集合(不带 --completion-promise 时只认这三个,逐字节兼容旧行为)。 */
|
|
29
|
-
const BUILTIN_COMPLETE_RE = /<promise>(?:COMPLETE|DONE|GOAL_COMPLETE)<\/promise>/i;
|
|
30
|
-
const NEED_REPLAN_RE = /<PROMISE>NEED_REPLAN<\/PROMISE>/i;
|
|
31
|
-
const NEED_GOAL_REVISION_RE = /<PROMISE>NEED_GOAL_REVISION<\/PROMISE>/i;
|
|
32
|
-
const LEARNING_RE = /<learning>([\s\S]*?)<\/learning>/gi;
|
|
33
|
-
/** 转义正则元字符,让用户自定义的 promise 短语按字面量匹配(含空格 / 标点也安全)。 */
|
|
34
|
-
function escapeRegExp(s) {
|
|
35
|
-
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* 构造完成哨兵判定器。
|
|
39
|
-
* - 不传 / 空白 customPhrase → 只认写死集合(与旧行为逐字节一致)。
|
|
40
|
-
* - 传 customPhrase → 写死集合 ∪ `<promise><customPhrase></promise>`(**超集**,向后兼容)。
|
|
41
|
-
* customPhrase 内外空白裁剪;正则元字符转义;标签内允许首尾空白;大小写不敏感。
|
|
42
|
-
*
|
|
43
|
-
* 设计:始终接受写死集合,所以即便用户设了自定义短语,LLM 输出 `<promise>DONE</promise>`
|
|
44
|
-
* 仍然有效——composeContext 因此可以无脑教 LLM 用 DONE,不必知道自定义短语是什么。
|
|
45
|
-
*/
|
|
46
|
-
export function makeCompletionMatcher(customPhrase) {
|
|
47
|
-
const phrase = customPhrase?.trim();
|
|
48
|
-
if (!phrase) {
|
|
49
|
-
return (text) => BUILTIN_COMPLETE_RE.test(text);
|
|
50
|
-
}
|
|
51
|
-
const customRe = new RegExp(`<promise>\\s*${escapeRegExp(phrase)}\\s*<\\/promise>`, 'i');
|
|
52
|
-
return (text) => BUILTIN_COMPLETE_RE.test(text) || customRe.test(text);
|
|
53
|
-
}
|
|
54
|
-
/** 旧调用兼容:等价于 makeCompletionMatcher()(text),只认写死集合。 */
|
|
55
|
-
export function hasCompleteSentinel(text) {
|
|
56
|
-
return BUILTIN_COMPLETE_RE.test(text);
|
|
57
|
-
}
|
|
58
|
-
export function hasNeedReplanSentinel(text) {
|
|
59
|
-
return NEED_REPLAN_RE.test(text);
|
|
60
|
-
}
|
|
61
|
-
export function hasNeedGoalRevisionSentinel(text) {
|
|
62
|
-
return NEED_GOAL_REVISION_RE.test(text);
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* 提取 LLM 本轮输出里所有 `<learning>…</learning>` 文本。
|
|
66
|
-
* 多空白折叠成单空格、去首尾、丢弃空项;无标签返回空数组。
|
|
67
|
-
*/
|
|
68
|
-
export function extractLearnings(text) {
|
|
69
|
-
const out = [];
|
|
70
|
-
for (const m of text.matchAll(LEARNING_RE)) {
|
|
71
|
-
const lesson = m[1].replace(/\s+/g, ' ').trim();
|
|
72
|
-
if (lesson)
|
|
73
|
-
out.push(lesson);
|
|
74
|
-
}
|
|
75
|
-
return out;
|
|
76
|
-
}
|