minimal-agent 0.8.2 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (484) hide show
  1. package/README.md +14 -12
  2. package/package.json +34 -1
  3. package/plugins/cron-runner/.claude-plugin/plugin.json +5 -0
  4. package/plugins/cron-runner/commands/cron.md +26 -0
  5. package/plugins/cron-runner/commands/crons.md +7 -0
  6. package/plugins/cron-runner/plugin.js +34 -0
  7. package/plugins/cron-runner/src/commands.js +348 -0
  8. package/plugins/cron-runner/src/cronTime.js +148 -0
  9. package/plugins/cron-runner/src/lock.js +68 -0
  10. package/plugins/cron-runner/src/runs.js +89 -0
  11. package/plugins/cron-runner/src/scheduleEngine.js +72 -0
  12. package/plugins/cron-runner/src/scheduler.js +355 -0
  13. package/plugins/cron-runner/src/schema.js +140 -0
  14. package/plugins/cron-runner/src/service.js +167 -0
  15. package/plugins/cron-runner/src/store.js +298 -0
  16. package/plugins/cron-runner/src/types.js +1 -0
  17. package/plugins/workflow-runner/commands/workflow.md +4 -4
  18. package/plugins/workflow-runner/commands/workflows.md +1 -1
  19. package/plugins/workflow-runner/plugin.js +3 -1
  20. package/plugins/workflow-runner/src/agentCommon.js +249 -51
  21. package/plugins/workflow-runner/src/dslManifest.js +72 -0
  22. package/plugins/workflow-runner/src/expressions.js +198 -15
  23. package/plugins/workflow-runner/src/index.js +40 -8
  24. package/plugins/workflow-runner/src/jsonPayload.js +1 -1
  25. package/plugins/workflow-runner/src/loader.js +286 -72
  26. package/plugins/workflow-runner/src/multimodal.js +37 -0
  27. package/plugins/workflow-runner/src/recovery.js +49 -39
  28. package/plugins/workflow-runner/src/runner.js +802 -287
  29. package/plugins/workflow-runner/src/stepExecutors/agent.js +157 -39
  30. package/plugins/workflow-runner/src/stepExecutors/assert.js +16 -3
  31. package/plugins/workflow-runner/src/stepExecutors/llm.js +60 -111
  32. package/plugins/workflow-runner/src/stepExecutors/skill.js +47 -47
  33. package/plugins/workflow-runner/src/stepExecutors/tool.js +76 -10
  34. package/plugins/workflow-runner/src/stepExecutors/verify.js +27 -10
  35. package/plugins/workflow-runner/src/taskIdentity.js +296 -0
  36. package/plugins/workflow-runner/src/types.js +19 -9
  37. package/plugins/workflow-runner/src/workflowState.js +516 -33
  38. package/skills/adversarial-review/SKILL.md +0 -1
  39. package/skills/ai-image/SKILL.md +89 -0
  40. package/skills/ai-image/scripts/generate.mjs +497 -0
  41. package/skills/ai-image/scripts/generate_from_plan.mjs +469 -0
  42. package/skills/ai-image/scripts/generate_from_plan_test.mjs +223 -0
  43. package/skills/ai-image/scripts/generate_test.mjs +74 -0
  44. package/skills/browser-automation/SKILL.md +47 -0
  45. package/skills/docx/SKILL.md +25 -3
  46. package/skills/docx/scripts/office/helpers/__pycache__/__init__.cpython-314.pyc +0 -0
  47. package/skills/docx/scripts/office/helpers/__pycache__/merge_runs.cpython-314.pyc +0 -0
  48. package/skills/docx/scripts/office/helpers/__pycache__/simplify_redlines.cpython-314.pyc +0 -0
  49. package/skills/docx/scripts/office/validators/__pycache__/__init__.cpython-314.pyc +0 -0
  50. package/skills/docx/scripts/office/validators/__pycache__/base.cpython-314.pyc +0 -0
  51. package/skills/docx/scripts/office/validators/__pycache__/docx.cpython-314.pyc +0 -0
  52. package/skills/docx/scripts/office/validators/__pycache__/pptx.cpython-314.pyc +0 -0
  53. package/skills/docx/scripts/office/validators/__pycache__/redlining.cpython-314.pyc +0 -0
  54. package/skills/docx/scripts/opc_check.py +253 -0
  55. package/skills/image-gen-openrouter/SKILL.md +10 -2
  56. package/skills/image-stats/SKILL.md +65 -0
  57. package/skills/image-stats/scripts/__pycache__/image_stats.cpython-314.pyc +0 -0
  58. package/skills/image-stats/scripts/__pycache__/image_stats_test.cpython-314.pyc +0 -0
  59. package/skills/image-stats/scripts/image_stats.py +368 -0
  60. package/skills/image-stats/scripts/image_stats_test.py +181 -0
  61. package/skills/pptx/SKILL.md +123 -95
  62. package/skills/pptx/design.md +82 -0
  63. package/skills/pptx/examples/README.md +29 -0
  64. package/skills/pptx/examples/hybrid_example.mjs +107 -0
  65. package/skills/pptx/examples/hybrid_example.pptx +0 -0
  66. package/skills/pptx/pptxgenjs.md +41 -0
  67. package/skills/pptx/scripts/deck_helpers.mjs +224 -0
  68. package/skills/pptx/scripts/layout_lint.py +293 -0
  69. package/skills/pptx/scripts/layout_lint_test.py +160 -0
  70. package/skills/pptx/scripts/opc_check.py +339 -0
  71. package/skills/pptx/scripts/svg_fallback.mjs +145 -0
  72. package/skills/pptx/svg.md +67 -0
  73. package/skills/tts-zh/SKILL.md +19 -2
  74. package/skills/ui-design/SKILL.md +158 -0
  75. package/skills/ui-design/claude_design.md +309 -0
  76. package/skills/ui-design/evals/evals.json +254 -0
  77. package/skills/ui-design/references/aesthetic-direction.md +83 -0
  78. package/skills/ui-design/references/claude-design-protocol.md +36 -0
  79. package/skills/ui-design/references/design-context.md +53 -0
  80. package/skills/ui-design/references/design-execution-playbook.md +82 -0
  81. package/skills/ui-design/references/export-pptx.md +124 -0
  82. package/skills/ui-design/references/layout-composition.md +654 -0
  83. package/skills/ui-design/references/preview-feedback.md +37 -0
  84. package/skills/ui-design/references/source-image-layout.md +189 -0
  85. package/skills/ui-design/references/starter-components.md +78 -0
  86. package/skills/ui-design/references/vi-aegis-vector.md +144 -0
  87. package/skills/ui-design/references/vi-amber-prism.md +133 -0
  88. package/skills/ui-design/references/vi-aqua-glass.md +200 -0
  89. package/skills/ui-design/references/vi-comfort-vision.md +147 -0
  90. package/skills/ui-design/references/vi-ember-prism.md +140 -0
  91. package/skills/ui-design/references/vi-nebula-console.md +151 -0
  92. package/skills/ui-design/references/vi-obsidian-optics.md +139 -0
  93. package/skills/ui-design/references/vi-obsidian-xui.md +143 -0
  94. package/skills/ui-design/references/vi-precision-horizon-dark.md +117 -0
  95. package/skills/ui-design/references/vi-precision-horizon.md +215 -0
  96. package/skills/ui-design/references/vi-solar-relay.md +130 -0
  97. package/skills/ui-design/references/vi-template-workflow.md +48 -0
  98. package/skills/ui-design/references/vi-verdant-grid.md +141 -0
  99. package/skills/ui-design/references/vi-violet-meridian.md +172 -0
  100. package/skills/ui-design/scripts/__pycache__/assemble_material.cpython-314.pyc +0 -0
  101. package/skills/ui-design/scripts/__pycache__/assemble_material_test.cpython-314.pyc +0 -0
  102. package/skills/ui-design/scripts/__pycache__/chart_sanity_check.cpython-314.pyc +0 -0
  103. package/skills/ui-design/scripts/__pycache__/check_language_policy.cpython-314.pyc +0 -0
  104. package/skills/ui-design/scripts/__pycache__/check_ui_artifact.cpython-314.pyc +0 -0
  105. package/skills/ui-design/scripts/__pycache__/check_ui_artifact_pptx_test.cpython-314.pyc +0 -0
  106. package/skills/ui-design/scripts/__pycache__/deck_pages_check.cpython-314.pyc +0 -0
  107. package/skills/ui-design/scripts/__pycache__/deck_pages_check_test.cpython-314.pyc +0 -0
  108. package/skills/ui-design/scripts/__pycache__/deck_visual_style_check.cpython-314.pyc +0 -0
  109. package/skills/ui-design/scripts/__pycache__/deck_visual_style_check_test.cpython-314.pyc +0 -0
  110. package/skills/ui-design/scripts/__pycache__/design_budget_check.cpython-314.pyc +0 -0
  111. package/skills/ui-design/scripts/__pycache__/design_budget_check_test.cpython-314.pyc +0 -0
  112. package/skills/ui-design/scripts/__pycache__/design_repair_hints.cpython-314.pyc +0 -0
  113. package/skills/ui-design/scripts/__pycache__/design_repair_hints_test.cpython-314.pyc +0 -0
  114. package/skills/ui-design/scripts/__pycache__/design_style_check.cpython-314.pyc +0 -0
  115. package/skills/ui-design/scripts/__pycache__/design_style_check_test.cpython-314.pyc +0 -0
  116. package/skills/ui-design/scripts/__pycache__/draft_coverage_check.cpython-314.pyc +0 -0
  117. package/skills/ui-design/scripts/__pycache__/extract_source_assets.cpython-314.pyc +0 -0
  118. package/skills/ui-design/scripts/__pycache__/extract_source_assets_test.cpython-314.pyc +0 -0
  119. package/skills/ui-design/scripts/__pycache__/generated_image_review_collect.cpython-314.pyc +0 -0
  120. package/skills/ui-design/scripts/__pycache__/generated_image_review_collect_test.cpython-314.pyc +0 -0
  121. package/skills/ui-design/scripts/__pycache__/image_plan_lint.cpython-314.pyc +0 -0
  122. package/skills/ui-design/scripts/__pycache__/image_plan_lint_test.cpython-314.pyc +0 -0
  123. package/skills/ui-design/scripts/__pycache__/image_prompt_rewrite.cpython-314.pyc +0 -0
  124. package/skills/ui-design/scripts/__pycache__/image_prompt_rewrite_test.cpython-314.pyc +0 -0
  125. package/skills/ui-design/scripts/__pycache__/layout_balance.cpython-314.pyc +0 -0
  126. package/skills/ui-design/scripts/__pycache__/layout_balance_test.cpython-314.pyc +0 -0
  127. package/skills/ui-design/scripts/__pycache__/normalize_design_json.cpython-314.pyc +0 -0
  128. package/skills/ui-design/scripts/__pycache__/normalize_design_json_test.cpython-314.pyc +0 -0
  129. package/skills/ui-design/scripts/__pycache__/plan_source_layout.cpython-314.pyc +0 -0
  130. package/skills/ui-design/scripts/__pycache__/plan_source_layout_test.cpython-314.pyc +0 -0
  131. package/skills/ui-design/scripts/__pycache__/resolve_source_hint.cpython-314.pyc +0 -0
  132. package/skills/ui-design/scripts/__pycache__/resolve_source_hint_test.cpython-314.pyc +0 -0
  133. package/skills/ui-design/scripts/__pycache__/resolve_source_input.cpython-314.pyc +0 -0
  134. package/skills/ui-design/scripts/__pycache__/resolve_source_input_test.cpython-314.pyc +0 -0
  135. package/skills/ui-design/scripts/__pycache__/scaffold_ui_artifact.cpython-314.pyc +0 -0
  136. package/skills/ui-design/scripts/__pycache__/source_usage_check.cpython-314.pyc +0 -0
  137. package/skills/ui-design/scripts/__pycache__/source_usage_check_test.cpython-314.pyc +0 -0
  138. package/skills/ui-design/scripts/__pycache__/text_readability_pixel.cpython-314.pyc +0 -0
  139. package/skills/ui-design/scripts/__pycache__/visual_quality_gate.cpython-314.pyc +0 -0
  140. package/skills/ui-design/scripts/__pycache__/visual_quality_gate_test.cpython-314.pyc +0 -0
  141. package/skills/ui-design/scripts/assemble_material.py +217 -0
  142. package/skills/ui-design/scripts/assemble_material_test.py +149 -0
  143. package/skills/ui-design/scripts/browser_check_ui_artifact.mjs +221 -0
  144. package/skills/ui-design/scripts/chart_sanity_check.py +261 -0
  145. package/skills/ui-design/scripts/chart_sanity_check_test.py +165 -0
  146. package/skills/ui-design/scripts/check_language_policy.py +351 -0
  147. package/skills/ui-design/scripts/check_ui_artifact.py +435 -0
  148. package/skills/ui-design/scripts/check_ui_artifact_pptx_test.py +251 -0
  149. package/skills/ui-design/scripts/deck_pages_check.py +158 -0
  150. package/skills/ui-design/scripts/deck_pages_check_test.py +134 -0
  151. package/skills/ui-design/scripts/deck_visual_style_check.py +767 -0
  152. package/skills/ui-design/scripts/deck_visual_style_check_test.py +713 -0
  153. package/skills/ui-design/scripts/design_budget_check.py +271 -0
  154. package/skills/ui-design/scripts/design_budget_check_test.py +183 -0
  155. package/skills/ui-design/scripts/design_repair_hints.py +162 -0
  156. package/skills/ui-design/scripts/design_repair_hints_test.py +54 -0
  157. package/skills/ui-design/scripts/design_style_check.py +397 -0
  158. package/skills/ui-design/scripts/design_style_check_test.py +233 -0
  159. package/skills/ui-design/scripts/draft_coverage_check.py +184 -0
  160. package/skills/ui-design/scripts/draft_coverage_check_test.py +131 -0
  161. package/skills/ui-design/scripts/export_pptx_from_html.mjs +2367 -0
  162. package/skills/ui-design/scripts/extract_source_assets.py +607 -0
  163. package/skills/ui-design/scripts/extract_source_assets_test.py +256 -0
  164. package/skills/ui-design/scripts/generated_image_review_collect.py +206 -0
  165. package/skills/ui-design/scripts/generated_image_review_collect_test.py +91 -0
  166. package/skills/ui-design/scripts/image_plan_lint.py +571 -0
  167. package/skills/ui-design/scripts/image_plan_lint_test.py +515 -0
  168. package/skills/ui-design/scripts/image_prompt_rewrite.py +713 -0
  169. package/skills/ui-design/scripts/image_prompt_rewrite_test.py +966 -0
  170. package/skills/ui-design/scripts/layout_balance.py +881 -0
  171. package/skills/ui-design/scripts/layout_balance_test.py +927 -0
  172. package/skills/ui-design/scripts/normalize_design_json.py +272 -0
  173. package/skills/ui-design/scripts/normalize_design_json_test.py +119 -0
  174. package/skills/ui-design/scripts/plan_source_layout.py +1450 -0
  175. package/skills/ui-design/scripts/plan_source_layout_test.py +1136 -0
  176. package/skills/ui-design/scripts/resolve_source_input.py +270 -0
  177. package/skills/ui-design/scripts/resolve_source_input_test.py +98 -0
  178. package/skills/ui-design/scripts/scaffold_ui_artifact.py +377 -0
  179. package/skills/ui-design/scripts/source_usage_check.py +581 -0
  180. package/skills/ui-design/scripts/source_usage_check_test.py +427 -0
  181. package/skills/ui-design/scripts/text_readability_pixel.py +340 -0
  182. package/skills/ui-design/scripts/text_readability_pixel_test.py +219 -0
  183. package/skills/ui-design/scripts/visual_quality_gate.py +301 -0
  184. package/skills/ui-design/scripts/visual_quality_gate_test.py +233 -0
  185. package/skills/ui-design/tests/e2e/prompts/deck.md +19 -0
  186. package/skills/ui-design/tests/e2e/prompts/webpage.md +17 -0
  187. package/skills/ui-design/tests/e2e/render_check.mjs +101 -0
  188. package/skills/ui-design/tests/e2e/rubric.json +54 -0
  189. package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/checks/browser-check.json +49 -0
  190. package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/checks/language-check.txt +12 -0
  191. package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/checks/static-check.txt +15 -0
  192. package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/outputs/index.html +837 -0
  193. package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/prompt.md +12 -0
  194. package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/review.md +21 -0
  195. package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/screenshots/desktop.png +0 -0
  196. package/skills/ui-design/tests/e2e/runs/aegis-vector-preview-1/screenshots/mobile.png +0 -0
  197. package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/outputs/homepage.html +373 -0
  198. package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/outputs/platform.html +378 -0
  199. package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/prompt.md +13 -0
  200. package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/review.md +26 -0
  201. package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/screenshots/homepage/browser-check.json +49 -0
  202. package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/screenshots/homepage/desktop.png +0 -0
  203. package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/screenshots/homepage/mobile.png +0 -0
  204. package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/screenshots/platform/browser-check.json +49 -0
  205. package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/screenshots/platform/desktop.png +0 -0
  206. package/skills/ui-design/tests/e2e/runs/amber-prism-screenshot-check-1/screenshots/platform/mobile.png +0 -0
  207. package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-1/checks/static-check.txt +2 -0
  208. package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-1/outputs/index.html +656 -0
  209. package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-1/prompt.md +12 -0
  210. package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-1/render_check.mjs +67 -0
  211. package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-2/checks/static-check.txt +2 -0
  212. package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-2/outputs/index.html +587 -0
  213. package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-2/prompt.md +12 -0
  214. package/skills/ui-design/tests/e2e/runs/aqua-glass-iteration-2/review.md +36 -0
  215. package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/checks/browser-check.json +49 -0
  216. package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/checks/language-check.txt +8 -0
  217. package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/checks/static-check.txt +16 -0
  218. package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/outputs/index.html +739 -0
  219. package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/prompt.md +11 -0
  220. package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/review.md +22 -0
  221. package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/screenshots/desktop.png +0 -0
  222. package/skills/ui-design/tests/e2e/runs/aqua-glass-volcano-refresh-1/screenshots/mobile.png +0 -0
  223. package/skills/ui-design/tests/e2e/runs/comfort-vision-preview-1/checks/browser-check.json +52 -0
  224. package/skills/ui-design/tests/e2e/runs/comfort-vision-preview-1/outputs/index.html +641 -0
  225. package/skills/ui-design/tests/e2e/runs/comfort-vision-preview-1/screenshots/desktop.png +0 -0
  226. package/skills/ui-design/tests/e2e/runs/comfort-vision-preview-1/screenshots/mobile.png +0 -0
  227. package/skills/ui-design/tests/e2e/runs/ember-prism-red-preview-1/outputs/index.html +467 -0
  228. package/skills/ui-design/tests/e2e/runs/ember-prism-red-preview-1/screenshots/browser-check.json +49 -0
  229. package/skills/ui-design/tests/e2e/runs/ember-prism-red-preview-1/screenshots/desktop.png +0 -0
  230. package/skills/ui-design/tests/e2e/runs/ember-prism-red-preview-1/screenshots/mobile.png +0 -0
  231. package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/outputs/homepage.html +373 -0
  232. package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/outputs/platform.html +378 -0
  233. package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/prompt.md +13 -0
  234. package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/review.md +26 -0
  235. package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/screenshots/homepage/browser-check.json +49 -0
  236. package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/screenshots/homepage/desktop.png +0 -0
  237. package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/screenshots/homepage/mobile.png +0 -0
  238. package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/screenshots/platform/browser-check.json +49 -0
  239. package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/screenshots/platform/desktop.png +0 -0
  240. package/skills/ui-design/tests/e2e/runs/ember-prism-screenshot-check-1/screenshots/platform/mobile.png +0 -0
  241. package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/checks/browser-check.json +49 -0
  242. package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/checks/language-check.txt +4 -0
  243. package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/checks/static-check.txt +2 -0
  244. package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/execution_notes.md +10 -0
  245. package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/outputs/index.html +587 -0
  246. package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/prompt.md +14 -0
  247. package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/review.md +13 -0
  248. package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/screenshots/desktop.png +0 -0
  249. package/skills/ui-design/tests/e2e/runs/empty-agent-protocol-check/screenshots/mobile.png +0 -0
  250. package/skills/ui-design/tests/e2e/runs/iteration-1/deck/checks/browser-check.json +24 -0
  251. package/skills/ui-design/tests/e2e/runs/iteration-1/deck/checks/static-check.txt +2 -0
  252. package/skills/ui-design/tests/e2e/runs/iteration-1/deck/execution_notes.md +21 -0
  253. package/skills/ui-design/tests/e2e/runs/iteration-1/deck/outputs/deck.html +451 -0
  254. package/skills/ui-design/tests/e2e/runs/iteration-1/deck/screenshots/slide-01.png +0 -0
  255. package/skills/ui-design/tests/e2e/runs/iteration-1/deck/screenshots/slide-02.png +0 -0
  256. package/skills/ui-design/tests/e2e/runs/iteration-1/review.md +79 -0
  257. package/skills/ui-design/tests/e2e/runs/iteration-1/webpage/checks/browser-check.json +26 -0
  258. package/skills/ui-design/tests/e2e/runs/iteration-1/webpage/checks/static-check.txt +2 -0
  259. package/skills/ui-design/tests/e2e/runs/iteration-1/webpage/execution_notes.md +20 -0
  260. package/skills/ui-design/tests/e2e/runs/iteration-1/webpage/outputs/index.html +534 -0
  261. package/skills/ui-design/tests/e2e/runs/iteration-1/webpage/screenshots/desktop.png +0 -0
  262. package/skills/ui-design/tests/e2e/runs/iteration-1/webpage/screenshots/mobile.png +0 -0
  263. package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/checks/browser-check.json +64 -0
  264. package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/checks/language-check.txt +7 -0
  265. package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/checks/quick-validate.txt +1 -0
  266. package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/checks/static-console.txt +2 -0
  267. package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/checks/static-homepage.txt +2 -0
  268. package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/outputs/console.html +600 -0
  269. package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/outputs/homepage.html +556 -0
  270. package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/prompt.md +29 -0
  271. package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/review.md +57 -0
  272. package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/screenshots/console-desktop.png +0 -0
  273. package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/screenshots/console-mobile.png +0 -0
  274. package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/screenshots/homepage-desktop.png +0 -0
  275. package/skills/ui-design/tests/e2e/runs/nebula-console-iteration-1/screenshots/homepage-mobile.png +0 -0
  276. package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/checks/browser-check.json +33 -0
  277. package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/checks/language-check.txt +6 -0
  278. package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/checks/quick-validate.txt +1 -0
  279. package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/checks/static-check.txt +2 -0
  280. package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/outputs/index.html +682 -0
  281. package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/prompt.md +13 -0
  282. package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/review.md +59 -0
  283. package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/screenshots/desktop.png +0 -0
  284. package/skills/ui-design/tests/e2e/runs/obsidian-optics-iteration-1/screenshots/mobile.png +0 -0
  285. package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/outputs/page-01.html +466 -0
  286. package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/outputs/page-02.html +433 -0
  287. package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/prompt.md +13 -0
  288. package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/screenshots/page-01/browser-check.json +49 -0
  289. package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/screenshots/page-01/desktop.png +0 -0
  290. package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/screenshots/page-01/mobile.png +0 -0
  291. package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/screenshots/page-02/browser-check.json +49 -0
  292. package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/screenshots/page-02/desktop.png +0 -0
  293. package/skills/ui-design/tests/e2e/runs/obsidian-xui-screenshot-check-1/screenshots/page-02/mobile.png +0 -0
  294. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/checks/browser-check.json +49 -0
  295. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/checks/language-check.txt +3 -0
  296. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/checks/static-check.txt +2 -0
  297. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/execution_notes.md +24 -0
  298. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/outputs/index.html +723 -0
  299. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/prompt.md +15 -0
  300. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/review.md +26 -0
  301. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/screenshots/desktop.png +0 -0
  302. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-1/screenshots/mobile.png +0 -0
  303. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/checks/browser-dark.json +49 -0
  304. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/checks/browser-light.json +49 -0
  305. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/checks/language-check.txt +11 -0
  306. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/checks/static-dark.txt +2 -0
  307. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/checks/static-light.txt +3 -0
  308. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/execution_notes.md +23 -0
  309. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/outputs/dark.html +392 -0
  310. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/outputs/light.html +476 -0
  311. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/prompt.md +23 -0
  312. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/review.md +41 -0
  313. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/screenshots/dark/desktop.png +0 -0
  314. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/screenshots/dark/mobile.png +0 -0
  315. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/screenshots/light/desktop.png +0 -0
  316. package/skills/ui-design/tests/e2e/runs/precision-horizon-iteration-2/screenshots/light/mobile.png +0 -0
  317. package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/checks/browser-check.json +54 -0
  318. package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/checks/language-check.txt +5 -0
  319. package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/checks/quick-validate.txt +1 -0
  320. package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/checks/static-check.txt +2 -0
  321. package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/outputs/index.html +765 -0
  322. package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/prompt.md +15 -0
  323. package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/review.md +59 -0
  324. package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/screenshots/desktop.png +0 -0
  325. package/skills/ui-design/tests/e2e/runs/solar-relay-iteration-1/screenshots/mobile.png +0 -0
  326. package/skills/ui-design/tests/e2e/runs/verdant-grid-preview-1/outputs/index.html +508 -0
  327. package/skills/ui-design/tests/e2e/runs/verdant-grid-preview-1/screenshots/browser-check.json +49 -0
  328. package/skills/ui-design/tests/e2e/runs/verdant-grid-preview-1/screenshots/desktop.png +0 -0
  329. package/skills/ui-design/tests/e2e/runs/verdant-grid-preview-1/screenshots/mobile.png +0 -0
  330. package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/checks/browser-check.json +54 -0
  331. package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/checks/language-check.txt +6 -0
  332. package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/checks/quick-validate.txt +1 -0
  333. package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/checks/static-check.txt +2 -0
  334. package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/outputs/index.html +788 -0
  335. package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/prompt.md +14 -0
  336. package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/review.md +60 -0
  337. package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/screenshots/desktop.png +0 -0
  338. package/skills/ui-design/tests/e2e/runs/violet-meridian-iteration-1/screenshots/mobile.png +0 -0
  339. package/skills/video-compose/SKILL.md +8 -1
  340. package/skills/web-crawler/SKILL.md +70 -0
  341. package/skills/web-crawler/scripts/crawl.mjs +538 -0
  342. package/skills/web-crawler/scripts/crawl.test.mjs +204 -0
  343. package/skills/xlsx/SKILL.md +12 -0
  344. package/skills/xlsx/scripts/opc_check.py +253 -0
  345. package/src/advisorState.js +22 -0
  346. package/src/askBridge.js +97 -3
  347. package/src/bootstrap/workingDir.js +12 -1
  348. package/src/cli/args.js +17 -1
  349. package/src/cli/configMenu.js +236 -0
  350. package/src/cli/configWizard.js +7 -5
  351. package/src/cli/print.js +37 -4
  352. package/src/cli/streamJson.js +77 -24
  353. package/src/cli/wizards/advisorWizard.js +147 -0
  354. package/src/cli/wizards/fieldForm.js +149 -0
  355. package/src/cli/wizards/imageWizard.js +60 -0
  356. package/src/cli/wizards/openRouterWizard.js +23 -0
  357. package/src/cli/wizards/providerPresets.js +95 -0
  358. package/src/cli/wizards/providerWizard.js +219 -0
  359. package/src/cli/wizards/searchWizard.js +23 -0
  360. package/src/cli/wizards/ttsWizard.js +34 -0
  361. package/src/config/configFile.js +441 -83
  362. package/src/config/configService.js +446 -0
  363. package/src/config.js +24 -64
  364. package/src/context/agentHome.js +9 -0
  365. package/src/context/archive.js +7 -2
  366. package/src/context/compact.js +8 -5
  367. package/src/context/contextLock.js +81 -0
  368. package/src/context/persistContext.js +30 -11
  369. package/src/context/reactiveCompact.js +4 -2
  370. package/src/context/recentDirs.js +21 -61
  371. package/src/context/sessionPath.js +97 -23
  372. package/src/context/sessionRegistry.js +303 -24
  373. package/src/context/tokenCounter.js +18 -0
  374. package/src/context/workspaceIndex.js +731 -0
  375. package/src/infra/verification.js +28 -15
  376. package/src/llm/client.js +394 -159
  377. package/src/llm/providers/anthropicFormat.js +241 -0
  378. package/src/llm/providers/openaiFormat.js +190 -0
  379. package/src/loop.js +219 -32
  380. package/src/main.js +61 -11
  381. package/src/messageQueue.js +97 -0
  382. package/src/multimodal.js +203 -0
  383. package/src/plugin-sdk.js +15 -0
  384. package/src/plugins/commandRouter.js +3 -0
  385. package/src/plugins/hookEngine.js +5 -1
  386. package/src/plugins/pluginLifecycle.js +28 -0
  387. package/src/plugins/pluginLoader.js +2 -1
  388. package/src/plugins/pluginRunner.js +49 -21
  389. package/src/plugins/transcript.js +4 -3
  390. package/src/prompts/pluginList.js +5 -5
  391. package/src/prompts/projectInstructions.js +3 -3
  392. package/src/prompts/promptAssembly.js +133 -144
  393. package/src/prompts/skillList.js +12 -22
  394. package/src/prompts/system.js +0 -1
  395. package/src/session/runAgentTurn.js +70 -0
  396. package/src/session/runTurn.js +41 -6
  397. package/src/toolGate.js +17 -0
  398. package/src/tools/advisor/advisor.js +379 -0
  399. package/src/tools/agent/agent.js +555 -0
  400. package/src/tools/agent/agentTypes.js +59 -0
  401. package/src/tools/agent/coordinator.js +93 -0
  402. package/src/tools/agent/worktree.js +270 -0
  403. package/src/tools/ask/ask.js +7 -2
  404. package/src/tools/bash/bash.js +112 -18
  405. package/src/tools/download/download.js +144 -0
  406. package/src/tools/edit/edit.js +1 -0
  407. package/src/tools/edit/multi-edit.js +1 -0
  408. package/src/tools/genimage/genimage.js +242 -0
  409. package/src/tools/genspeech/genspeech.js +67 -0
  410. package/src/tools/glob/glob.js +1 -0
  411. package/src/tools/grep/grep.js +3 -0
  412. package/src/tools/grep/rgPath.js +2 -0
  413. package/src/tools/index.js +25 -2
  414. package/src/tools/read/read.js +1 -0
  415. package/src/tools/shared/killTree.js +52 -0
  416. package/src/tools/toolProgressBridge.js +48 -0
  417. package/src/tools/webbrowser/agentBrowserPath.js +258 -0
  418. package/src/tools/webbrowser/browser.js +59 -42
  419. package/src/tools/webbrowser/browserControl.js +118 -0
  420. package/src/tools/webbrowser/browserDaemon.js +97 -0
  421. package/src/tools/webbrowser/browserService.js +27 -0
  422. package/src/tools/webbrowser/browserStream.js +119 -0
  423. package/src/tools/webbrowser/webbrowser.js +699 -130
  424. package/src/tools/webfetch/webfetch.js +1 -0
  425. package/src/tools/websearch/websearch.js +134 -51
  426. package/src/tools/write/write.js +1 -0
  427. package/src/ui/App.js +249 -22
  428. package/src/ui/AskQuestion.js +29 -10
  429. package/src/ui/InputBox.js +104 -12
  430. package/src/ui/LiveArea.js +112 -19
  431. package/src/ui/MessageList.js +100 -14
  432. package/src/ui/ModelPicker.js +56 -0
  433. package/src/ui/QueuedMessagesBanner.js +14 -0
  434. package/src/ui/Root.js +18 -10
  435. package/src/ui/SessionPicker.js +102 -0
  436. package/src/ui/StatusLine.js +13 -4
  437. package/src/ui/WorkspacePicker.js +55 -0
  438. package/src/ui/figures.js +44 -0
  439. package/src/ui/hooks/askSlot.js +82 -0
  440. package/src/ui/hooks/useChat.js +358 -64
  441. package/src/ui/hooks/usePasteHandler.js +11 -1
  442. package/src/ui/hooks/useTextBuffer.js +1 -3
  443. package/src/ui/liveViewport.js +5 -1
  444. package/src/ui/markdown.js +206 -0
  445. package/src/ui/textBuffer.js +0 -7
  446. package/src/ui/theme.js +32 -0
  447. package/src/utils/debugLog.js +0 -4
  448. package/src/utils/resourcePaths.js +2 -2
  449. package/src/utils/stripThink.js +50 -0
  450. package/src/web/browserBridge.js +447 -0
  451. package/src/web/protocol.js +19 -0
  452. package/workflows/adaptive-research.yaml +13 -5
  453. package/workflows/book-review-short.yaml +36 -10
  454. package/workflows/e2e-write-greet.yaml +6 -2
  455. package/workflows/illustrate.yaml +227 -0
  456. package/workflows/plan.yaml +460 -179
  457. package/workflows/ppt.yaml +1659 -0
  458. package/workflows/ralph-loop.yaml +199 -0
  459. package/workflows/schema.json +81 -23
  460. package/workflows/webppt.yaml +496 -0
  461. package/workflows/word.yaml +710 -0
  462. package/workflows/youtube-shorts.yaml +46 -15
  463. package/MINIMAL-TRACE.md +0 -77
  464. package/plugins/HOW-TO-WRITE-A-PLUGIN.md +0 -186
  465. package/plugins/ralph-wiggum/.claude-plugin/plugin.json +0 -9
  466. package/plugins/ralph-wiggum/README.md +0 -197
  467. package/plugins/ralph-wiggum/commands/cancel-ralph.md +0 -18
  468. package/plugins/ralph-wiggum/commands/help.md +0 -137
  469. package/plugins/ralph-wiggum/commands/ralph-loop.md +0 -85
  470. package/plugins/ralph-wiggum/hooks/hooks.json +0 -15
  471. package/plugins/ralph-wiggum/hooks/stop-hook.sh +0 -191
  472. package/plugins/ralph-wiggum/plugin.js +0 -280
  473. package/plugins/ralph-wiggum/src/goalState.js +0 -258
  474. package/plugins/ralph-wiggum/src/sentinels.js +0 -76
  475. package/plugins/ralph-wiggum/src/stopHookRunner.js +0 -104
  476. package/plugins/ralph-wiggum/src/verificationGate.js +0 -202
  477. package/plugins/workflow-runner/src/miniReAct.js +0 -223
  478. package/plugins/workflow-runner/src/voteHelpers.js +0 -110
  479. package/skills/config/SKILL.md +0 -123
  480. package/skills/frontend-design/LICENSE.txt +0 -177
  481. package/skills/frontend-design/SKILL.md +0 -42
  482. package/src/ui/ProgressPanel.js +0 -54
  483. package/src/ui/StreamingBlock.js +0 -11
  484. package/src/ui/ToolStatus.js +0 -11
@@ -1,112 +1,470 @@
1
- /**
2
- * ============================================================
3
- * src/config/configFile.ts —— 模式 B 向导写的 provider 配置
4
- * ------------------------------------------------------------
5
- * 与 src/config.ts 的关系:
6
- * - config.ts 负责"读取 process.env 拼装 Provider"(模式 A)
7
- * - 本文件负责"读写 ~/.minimal-agent/config.json"(模式 B)
8
- * - 上层(loadProviderLayered)先看 env、再看本文件
9
- *
10
- * 与 src/context/persistContext.ts 的关系:
11
- * - 复用同一个目录 ~/.minimal-agent/
12
- * - 同样"解析失败返回 null、写失败静默"模式
13
- *
14
- * 为什么用 JSON 而非 .env 格式:
15
- * - 解析无歧义(dotenv 各家行为略有差异)
16
- * - 显式区分"向导写的" vs "用户写的 .env",避免互相覆盖
17
- * - JSON 还可以放结构化扩展(如 savedAt 用于排查)
18
- * ============================================================
19
- */
20
- import { chmod, mkdir, readFile, writeFile } from 'node:fs/promises';
1
+ import { randomUUID } from 'node:crypto';
2
+ import { chmod, copyFile, mkdir, readFile, rename, rm, stat, unlink, writeFile } from 'node:fs/promises';
21
3
  import { homedir } from 'node:os';
22
4
  import { dirname, join } from 'node:path';
23
5
  import { execSiblingDir } from '../utils/greenRoot.js';
6
+ export const DEFAULT_SUBAGENTS_CONFIG = {
7
+ enabled: true,
8
+ maxCallsPerTurn: 6,
9
+ maxConcurrent: 3,
10
+ defaultWriteIsolation: 'none',
11
+ timeoutMs: 1_800_000,
12
+ exploreMaxTurns: 50,
13
+ generalMaxTurns: 100,
14
+ };
15
+ export const DEFAULT_BROWSER_CONFIG = {
16
+ enabled: true,
17
+ profileId: 'default',
18
+ developerMode: false,
19
+ allowedCdpOrigins: [],
20
+ };
21
+ const DEFAULT_CONTEXT_WINDOW = 128_000;
22
+ const LOCK_STALE_MS = 120_000;
23
+ const LOCK_WAIT_MS = 15_000;
24
24
  /**
25
- * 配置文件的**写**路径(带环境变量覆盖,主要给测试用)。
26
- * `saveConfig()` / 首次配置向导只写这里——env override 或 home,**绝不写 exe 同级**
27
- * (U 盘可能只读,且不该污染产品目录)。读路径见 readSavedConfig 的分层。
25
+ * 建议的单次输出 token 上限:min(32768, max(4096, contextWindow×0.25))。
26
+ * 上限 32768(非更保守的 16384)呼应 .env.example 的实测教训——16384 偏紧,写大 JSON
27
+ * 输出时会被截断;maxTokens 是上限不是预订额度,设大不额外花钱。
28
28
  */
29
+ export function defaultMaxTokens(contextWindow) {
30
+ return Math.min(32_768, Math.max(4_096, Math.round(contextWindow * 0.25)));
31
+ }
32
+ function homeConfigPath() {
33
+ return join(process.env.MINIMAL_AGENT_HOME ?? homedir(), '.minimal-agent', 'config.json');
34
+ }
29
35
  export function getConfigFilePath() {
30
36
  return process.env.MINIMAL_AGENT_CONFIG_FILE ?? homeConfigPath();
31
37
  }
32
- /** home 默认配置路径(读分层的最后一档;也是 getConfigFilePath 的默认写入位置)。 */
33
- function homeConfigPath() {
34
- return join(homedir(), '.minimal-agent', 'config.json');
38
+ function positiveNumber(value) {
39
+ return typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : undefined;
40
+ }
41
+ function boundedNumber(value, fallback, min, max) {
42
+ return Math.min(max, Math.max(min, positiveNumber(value) ?? fallback));
43
+ }
44
+ function nonEmpty(value) {
45
+ return typeof value === 'string' && value.trim() ? value.trim() : undefined;
46
+ }
47
+ // ---------------- v4(当前)解析 ----------------
48
+ function parseModel(value) {
49
+ if (!value || typeof value !== 'object' || Array.isArray(value))
50
+ return null;
51
+ const raw = value;
52
+ const id = nonEmpty(raw.id);
53
+ const baseURL = nonEmpty(raw.baseURL);
54
+ const model = nonEmpty(raw.model);
55
+ if (!id || !baseURL || !model)
56
+ return null;
57
+ const apiKey = typeof raw.apiKey === 'string' ? raw.apiKey.trim() : '';
58
+ const displayName = nonEmpty(raw.displayName);
59
+ const now = Date.now();
60
+ return {
61
+ id,
62
+ apiFormat: raw.apiFormat === 'anthropic' ? 'anthropic' : 'openai',
63
+ ...(displayName ? { displayName } : {}),
64
+ baseURL,
65
+ apiKey,
66
+ model,
67
+ contextWindow: positiveNumber(raw.contextWindow) ?? DEFAULT_CONTEXT_WINDOW,
68
+ ...(positiveNumber(raw.maxTokens) !== undefined ? { maxTokens: positiveNumber(raw.maxTokens) } : {}),
69
+ supportsVision: raw.supportsVision !== false,
70
+ enabled: raw.enabled !== false,
71
+ createdAt: positiveNumber(raw.createdAt) ?? now,
72
+ updatedAt: positiveNumber(raw.updatedAt) ?? now,
73
+ };
74
+ }
75
+ function parseModels(value) {
76
+ if (!Array.isArray(value))
77
+ return [];
78
+ const out = [];
79
+ for (const item of value) {
80
+ const model = parseModel(item);
81
+ if (model)
82
+ out.push(model);
83
+ }
84
+ return out;
85
+ }
86
+ function parseTools(value) {
87
+ if (!value || typeof value !== 'object' || Array.isArray(value))
88
+ return {};
89
+ const raw = value;
90
+ const out = {};
91
+ const search = raw.webSearch;
92
+ const searchKey = nonEmpty(search?.apiKey);
93
+ if (searchKey)
94
+ out.webSearch = { provider: 'tavily', apiKey: searchKey };
95
+ const image = raw.imageGeneration;
96
+ const imageBaseURL = nonEmpty(image?.baseURL);
97
+ const imageApiKey = nonEmpty(image?.apiKey);
98
+ const imageModel = nonEmpty(image?.model);
99
+ if (imageBaseURL && imageApiKey && imageModel) {
100
+ const protocol = image?.protocol === 'chat' || image?.protocol === 'images' ? image.protocol : 'auto';
101
+ out.imageGeneration = {
102
+ provider: nonEmpty(image?.provider) ?? 'openai',
103
+ baseURL: imageBaseURL,
104
+ apiKey: imageApiKey,
105
+ model: imageModel,
106
+ protocol,
107
+ };
108
+ }
109
+ const openRouterKey = nonEmpty(raw.openRouter?.apiKey);
110
+ if (openRouterKey)
111
+ out.openRouter = { apiKey: openRouterKey };
112
+ const speech = raw.textToSpeech;
113
+ const speechKey = nonEmpty(speech?.apiKey);
114
+ const groupId = nonEmpty(speech?.groupId);
115
+ if (speechKey && groupId)
116
+ out.textToSpeech = { provider: 'minimax', apiKey: speechKey, groupId };
117
+ return out;
118
+ }
119
+ function parseAdvisor(value) {
120
+ if (!value || typeof value !== 'object' || Array.isArray(value))
121
+ return undefined;
122
+ const raw = value;
123
+ return {
124
+ enabled: raw.enabled !== false,
125
+ mode: raw.mode === 'manual' ? 'manual' : 'auto',
126
+ modelId: nonEmpty(raw.modelId) ?? null,
127
+ contextPolicy: 'full-relevant',
128
+ shareSensitive: raw.shareSensitive === true,
129
+ inputTokenBudget: boundedNumber(raw.inputTokenBudget, 128_000, 8_000, 128_000),
130
+ timeoutMs: boundedNumber(raw.timeoutMs, 180_000, 15_000, 300_000),
131
+ };
132
+ }
133
+ function parseSubagents(value) {
134
+ const raw = value && typeof value === 'object' && !Array.isArray(value) ? value : {};
135
+ return {
136
+ enabled: raw.enabled !== false,
137
+ maxCallsPerTurn: boundedNumber(raw.maxCallsPerTurn, 6, 1, 12),
138
+ maxConcurrent: boundedNumber(raw.maxConcurrent, 3, 1, 6),
139
+ defaultWriteIsolation: raw.defaultWriteIsolation === 'worktree' ? 'worktree' : 'none',
140
+ timeoutMs: boundedNumber(raw.timeoutMs, 1_800_000, 60_000, 3_600_000),
141
+ exploreMaxTurns: boundedNumber(raw.exploreMaxTurns, 50, 5, 100),
142
+ generalMaxTurns: boundedNumber(raw.generalMaxTurns, 100, 10, 200),
143
+ };
144
+ }
145
+ function parseBrowser(value) {
146
+ const raw = value && typeof value === 'object' && !Array.isArray(value) ? value : {};
147
+ return {
148
+ enabled: raw.enabled !== false,
149
+ profileId: 'default',
150
+ developerMode: raw.developerMode === true,
151
+ allowedCdpOrigins: Array.isArray(raw.allowedCdpOrigins)
152
+ ? raw.allowedCdpOrigins.filter((item) => typeof item === 'string' && /^https?:\/\//i.test(item)).slice(0, 100)
153
+ : [],
154
+ };
155
+ }
156
+ function parseCurrent(data) {
157
+ if (data.version !== 4)
158
+ return null;
159
+ const advisor = parseAdvisor(data.advisor);
160
+ const compactRatio = typeof data.compactRatio === 'number' && data.compactRatio > 0 && data.compactRatio <= 1
161
+ ? data.compactRatio
162
+ : undefined;
163
+ return {
164
+ version: 4,
165
+ models: parseModels(data.models),
166
+ baseModelId: nonEmpty(data.baseModelId) ?? null,
167
+ ...(compactRatio !== undefined ? { compactRatio } : {}),
168
+ ...(advisor ? { advisor } : {}),
169
+ subagents: parseSubagents(data.subagents),
170
+ browser: parseBrowser(data.browser),
171
+ tools: parseTools(data.tools),
172
+ ...(data.drafts && typeof data.drafts === 'object' && !Array.isArray(data.drafts)
173
+ ? { drafts: structuredClone(data.drafts) }
174
+ : {}),
175
+ savedAt: typeof data.savedAt === 'number' ? data.savedAt : 0,
176
+ };
177
+ }
178
+ function parseLegacyProviderConfig(value) {
179
+ if (!value || typeof value !== 'object' || Array.isArray(value))
180
+ return null;
181
+ const raw = value;
182
+ const baseURL = nonEmpty(raw.baseURL);
183
+ const apiKey = typeof raw.apiKey === 'string' ? raw.apiKey.trim() : undefined;
184
+ const model = nonEmpty(raw.model);
185
+ if (!baseURL || apiKey === undefined || !model)
186
+ return null;
187
+ const compactRatio = typeof raw.compactRatio === 'number' && raw.compactRatio > 0 && raw.compactRatio <= 1
188
+ ? raw.compactRatio
189
+ : undefined;
190
+ return {
191
+ name: nonEmpty(raw.name) ?? 'env',
192
+ baseURL,
193
+ apiKey,
194
+ model,
195
+ contextWindow: positiveNumber(raw.contextWindow) ?? DEFAULT_CONTEXT_WINDOW,
196
+ ...(compactRatio !== undefined ? { compactRatio } : {}),
197
+ ...(positiveNumber(raw.maxTokens) !== undefined ? { maxTokens: positiveNumber(raw.maxTokens) } : {}),
198
+ };
199
+ }
200
+ function parseLegacyAdvisorConfig(value) {
201
+ if (!value || typeof value !== 'object' || Array.isArray(value))
202
+ return undefined;
203
+ const raw = value;
204
+ const provider = parseLegacyProviderConfig(raw.provider);
205
+ if (!provider)
206
+ return undefined;
207
+ return {
208
+ enabled: raw.enabled !== false,
209
+ mode: raw.mode === 'manual' ? 'manual' : 'auto',
210
+ provider,
211
+ supportsVision: raw.supportsVision === true,
212
+ shareSensitive: raw.shareSensitive === true,
213
+ inputTokenBudget: boundedNumber(raw.inputTokenBudget, 128_000, 8_000, 128_000),
214
+ timeoutMs: boundedNumber(raw.timeoutMs, 180_000, 15_000, 300_000),
215
+ };
35
216
  }
36
217
  /**
37
- * 解析单个 config.json:不存在 / JSON 损坏 / 必填字段缺失 → null;成功 → SavedConfig。
218
+ * 把「单一基座 provider + 可选单一顾问 provider」的旧形状构造成 v4 的模型列表形状。
219
+ * v1(无 version 字段的扁平文件)与 v2/v3(provider/advisor 单对象)迁移路径共用这一个函数。
38
220
  */
221
+ function buildV4FromLegacy(legacyProvider, legacyAdvisor, subagents, tools, savedAt) {
222
+ const now = Date.now();
223
+ const baseModel = {
224
+ id: 'migrated-base',
225
+ apiFormat: 'openai',
226
+ ...(legacyProvider.name !== 'env' ? { displayName: legacyProvider.name } : {}),
227
+ baseURL: legacyProvider.baseURL,
228
+ apiKey: legacyProvider.apiKey,
229
+ model: legacyProvider.model,
230
+ contextWindow: legacyProvider.contextWindow,
231
+ ...(legacyProvider.maxTokens !== undefined ? { maxTokens: legacyProvider.maxTokens } : {}),
232
+ enabled: true,
233
+ createdAt: now,
234
+ updatedAt: now,
235
+ };
236
+ const models = [baseModel];
237
+ let advisor;
238
+ if (legacyAdvisor) {
239
+ const sameAsBase = legacyAdvisor.provider.baseURL === baseModel.baseURL
240
+ && legacyAdvisor.provider.apiKey === baseModel.apiKey
241
+ && legacyAdvisor.provider.model === baseModel.model;
242
+ let advisorModelId;
243
+ if (sameAsBase) {
244
+ if (legacyAdvisor.supportsVision)
245
+ baseModel.supportsVision = true;
246
+ advisorModelId = baseModel.id;
247
+ }
248
+ else {
249
+ const advisorModel = {
250
+ id: 'migrated-advisor',
251
+ apiFormat: 'openai',
252
+ ...(legacyAdvisor.provider.name !== 'advisor' ? { displayName: legacyAdvisor.provider.name } : {}),
253
+ baseURL: legacyAdvisor.provider.baseURL,
254
+ apiKey: legacyAdvisor.provider.apiKey,
255
+ model: legacyAdvisor.provider.model,
256
+ contextWindow: legacyAdvisor.provider.contextWindow,
257
+ ...(legacyAdvisor.provider.maxTokens !== undefined ? { maxTokens: legacyAdvisor.provider.maxTokens } : {}),
258
+ ...(legacyAdvisor.supportsVision ? { supportsVision: true } : {}),
259
+ enabled: true,
260
+ createdAt: now,
261
+ updatedAt: now,
262
+ };
263
+ models.push(advisorModel);
264
+ advisorModelId = advisorModel.id;
265
+ }
266
+ advisor = {
267
+ enabled: legacyAdvisor.enabled,
268
+ mode: legacyAdvisor.mode,
269
+ modelId: advisorModelId,
270
+ contextPolicy: 'full-relevant',
271
+ shareSensitive: legacyAdvisor.shareSensitive,
272
+ inputTokenBudget: legacyAdvisor.inputTokenBudget,
273
+ timeoutMs: legacyAdvisor.timeoutMs,
274
+ };
275
+ }
276
+ return {
277
+ version: 4,
278
+ models,
279
+ baseModelId: baseModel.id,
280
+ ...(legacyProvider.compactRatio !== undefined ? { compactRatio: legacyProvider.compactRatio } : {}),
281
+ ...(advisor ? { advisor } : {}),
282
+ subagents,
283
+ browser: DEFAULT_BROWSER_CONFIG,
284
+ tools,
285
+ savedAt,
286
+ };
287
+ }
288
+ function migrateV1(data) {
289
+ const provider = parseLegacyProviderConfig({
290
+ name: data.provider,
291
+ baseURL: data.baseURL,
292
+ apiKey: data.apiKey,
293
+ model: data.model,
294
+ contextWindow: data.contextWindow,
295
+ compactRatio: data.compactRatio,
296
+ maxTokens: data.maxTokens,
297
+ });
298
+ if (!provider)
299
+ return null;
300
+ const tools = {};
301
+ const tavilyApiKey = nonEmpty(data.tavilyApiKey);
302
+ if (tavilyApiKey)
303
+ tools.webSearch = { provider: 'tavily', apiKey: tavilyApiKey };
304
+ return buildV4FromLegacy(provider, undefined, DEFAULT_SUBAGENTS_CONFIG, tools, typeof data.savedAt === 'number' ? data.savedAt : 0);
305
+ }
306
+ function migrateV3(data) {
307
+ const provider = parseLegacyProviderConfig(data.provider);
308
+ if (!provider)
309
+ return null;
310
+ const advisor = parseLegacyAdvisorConfig(data.advisor);
311
+ return buildV4FromLegacy(provider, advisor, parseSubagents(data.subagents), parseTools(data.tools), typeof data.savedAt === 'number' ? data.savedAt : 0);
312
+ }
39
313
  async function parseConfigFile(file) {
40
314
  try {
41
- const raw = await readFile(file, 'utf8');
42
- const data = JSON.parse(raw);
43
- if (typeof data.baseURL !== 'string' ||
44
- typeof data.apiKey !== 'string' ||
45
- typeof data.model !== 'string' ||
46
- data.baseURL.length === 0 ||
47
- data.apiKey.length === 0 ||
48
- data.model.length === 0) {
315
+ const data = JSON.parse(await readFile(file, 'utf8'));
316
+ if (!data || typeof data !== 'object' || Array.isArray(data))
49
317
  return null;
318
+ const object = data;
319
+ const current = parseCurrent(object);
320
+ if (current)
321
+ return { config: current, migrated: object.version !== 4, fromVersion: 4 };
322
+ if (object.version === 2 || object.version === 3) {
323
+ const migrated = migrateV3(object);
324
+ if (migrated)
325
+ return { config: migrated, migrated: true, fromVersion: object.version };
50
326
  }
51
- return {
52
- baseURL: data.baseURL,
53
- apiKey: data.apiKey,
54
- model: data.model,
55
- provider: typeof data.provider === 'string' ? data.provider : undefined,
56
- contextWindow: typeof data.contextWindow === 'number' && data.contextWindow > 0
57
- ? data.contextWindow
58
- : undefined,
59
- compactRatio: typeof data.compactRatio === 'number' &&
60
- data.compactRatio > 0 &&
61
- data.compactRatio <= 1
62
- ? data.compactRatio
63
- : undefined,
64
- tavilyApiKey: typeof data.tavilyApiKey === 'string' && data.tavilyApiKey.length > 0
65
- ? data.tavilyApiKey
66
- : undefined,
67
- savedAt: typeof data.savedAt === 'number' ? data.savedAt : 0,
68
- };
327
+ const migrated = migrateV1(object);
328
+ return migrated ? { config: migrated, migrated: true, fromVersion: 1 } : null;
69
329
  }
70
330
  catch {
71
331
  return null;
72
332
  }
73
333
  }
74
- /**
75
- * 读取已保存的 provider 配置(**分层**,按优先级返回第一个有效的):
76
- * 1. `MINIMAL_AGENT_CONFIG_FILE` 显式覆盖 —— **只读这一个,不 fallthrough**
77
- * (保持既有语义 + 测试隔离)
78
- * 2. exe 同级 `config.json` —— **绿色版 / U 盘的卖家预置配置**(compile 后
79
- * `execSiblingDir()` = 真实 exe 目录;dev/npm 下是 node/bun 二进制目录、无此文件 → 跳过)
80
- * 3. `~/.minimal-agent/config.json` —— 首次配置向导写出的(原行为)
81
- *
82
- * 这层让卖家把配好的 config.json 放进绿色目录即完成预配置,客户端零配置开箱即用
83
- * (loadProviderLayered 拿到 provider → 不进向导、`-p` 不报 config_error)。
84
- *
85
- * 加性保证:dev / npm 模式无 override 时,exe 同级无 config.json → 只命中 home → 行为不变。
86
- */
87
- export async function readSavedConfig() {
334
+ function processIsAlive(pid) {
335
+ try {
336
+ process.kill(pid, 0);
337
+ return true;
338
+ }
339
+ catch (error) {
340
+ return error.code === 'EPERM';
341
+ }
342
+ }
343
+ async function acquireConfigLock(file) {
344
+ const lockDir = `${file}.lock`;
345
+ const ownerFile = join(lockDir, 'owner.json');
346
+ const startedAt = Date.now();
347
+ await mkdir(dirname(file), { recursive: true, mode: 0o700 });
348
+ while (true) {
349
+ try {
350
+ await mkdir(lockDir, { mode: 0o700 });
351
+ await writeFile(ownerFile, JSON.stringify({ pid: process.pid, createdAt: Date.now() }), { mode: 0o600 });
352
+ return async () => { await rm(lockDir, { recursive: true, force: true }); };
353
+ }
354
+ catch (error) {
355
+ if (error.code !== 'EEXIST')
356
+ throw error;
357
+ let stale = false;
358
+ try {
359
+ const [ownerRaw, info] = await Promise.all([readFile(ownerFile, 'utf8'), stat(lockDir)]);
360
+ const owner = JSON.parse(ownerRaw);
361
+ stale = typeof owner.pid === 'number' ? !processIsAlive(owner.pid) : Date.now() - info.mtimeMs > LOCK_STALE_MS;
362
+ }
363
+ catch {
364
+ try {
365
+ const info = await stat(lockDir);
366
+ stale = Date.now() - info.mtimeMs > LOCK_STALE_MS;
367
+ }
368
+ catch {
369
+ stale = false;
370
+ }
371
+ }
372
+ if (stale) {
373
+ await rm(lockDir, { recursive: true, force: true });
374
+ continue;
375
+ }
376
+ if (Date.now() - startedAt > LOCK_WAIT_MS)
377
+ throw new Error('等待配置文件锁超时');
378
+ await new Promise((resolve) => setTimeout(resolve, 40));
379
+ }
380
+ }
381
+ }
382
+ async function writeConfigFile(file, config) {
383
+ const release = await acquireConfigLock(file);
384
+ try {
385
+ await writeConfigFileUnlocked(file, config);
386
+ }
387
+ finally {
388
+ await release();
389
+ }
390
+ }
391
+ async function writeConfigFileUnlocked(file, config) {
392
+ const tmp = `${file}.${process.pid}.${randomUUID()}.tmp`;
393
+ try {
394
+ await mkdir(dirname(file), { recursive: true, mode: 0o700 });
395
+ await writeFile(tmp, JSON.stringify(config, null, 2), { encoding: 'utf8', mode: 0o600 });
396
+ await rename(tmp, file);
397
+ await chmod(file, 0o600).catch(() => { });
398
+ }
399
+ finally {
400
+ await unlink(tmp).catch(() => { });
401
+ }
402
+ }
403
+ function configCandidates() {
88
404
  const override = process.env.MINIMAL_AGENT_CONFIG_FILE;
89
- if (override)
90
- return parseConfigFile(override);
91
- for (const file of [join(execSiblingDir(), 'config.json'), homeConfigPath()]) {
92
- const cfg = await parseConfigFile(file);
93
- if (cfg)
94
- return cfg;
405
+ return override ? [override] : [homeConfigPath(), join(execSiblingDir(), 'config.json')];
406
+ }
407
+ export async function readMinimalAgentConfig(options = {}) {
408
+ for (const file of configCandidates()) {
409
+ const parsed = await parseConfigFile(file);
410
+ if (!parsed)
411
+ continue;
412
+ if (options.migrate !== false && (parsed.migrated || file !== getConfigFilePath())) {
413
+ // 备份只在「原地迁移会覆盖源文件」时才有意义(file == 权威写入位)。
414
+ // exe 同级(U 盘预置)源文件永不被覆盖,且「绝不写 U 盘」是产品红线——
415
+ // 曾在此给 U 盘目录写出 config.json.v1.backup(绿色版冒烟实测抓到)。
416
+ // 备份文件名按来源版本号命名(而非固定 .v1.backup):一台机器可能先后经历
417
+ // v1→v3、又 v3→v4 两次迁移,固定文件名会让第二次覆盖第一次的备份。
418
+ if (parsed.migrated && file === getConfigFilePath()) {
419
+ await copyFile(file, `${file}.v${parsed.fromVersion}.backup`).catch(() => { });
420
+ }
421
+ // A schema-only migration must not invalidate a revision already returned to
422
+ // another process during startup.
423
+ await writeConfigFile(getConfigFilePath(), parsed.config);
424
+ }
425
+ return parsed.config;
95
426
  }
96
427
  return null;
97
428
  }
98
- /**
99
- * 写入向导收集到的配置。
100
- * unix 上 chmod 600(仅本人可读写),Windows 上 chmod 是 no-op,靠 NTFS ACL。
101
- */
102
- export async function saveConfig(cfg) {
429
+ export async function saveMinimalAgentConfig(config) {
430
+ const next = {
431
+ version: 4,
432
+ models: config.models,
433
+ baseModelId: config.baseModelId,
434
+ ...(config.compactRatio !== undefined ? { compactRatio: config.compactRatio } : {}),
435
+ advisor: config.advisor,
436
+ subagents: config.subagents ?? DEFAULT_SUBAGENTS_CONFIG,
437
+ browser: config.browser ?? DEFAULT_BROWSER_CONFIG,
438
+ tools: config.tools,
439
+ drafts: config.drafts,
440
+ savedAt: Date.now(),
441
+ };
442
+ await writeConfigFile(getConfigFilePath(), next);
443
+ return next;
444
+ }
445
+ /** Cross-process read-modify-write. The mutator never sees a partially written file. */
446
+ export async function updateMinimalAgentConfig(mutate) {
103
447
  const file = getConfigFilePath();
104
- await mkdir(dirname(file), { recursive: true });
105
- const data = { ...cfg, savedAt: Date.now() };
106
- await writeFile(file, JSON.stringify(data, null, 2), 'utf8');
448
+ const release = await acquireConfigLock(file);
107
449
  try {
108
- await chmod(file, 0o600);
450
+ const current = (await parseConfigFile(file))?.config ?? null;
451
+ const value = mutate(current);
452
+ const next = {
453
+ version: 4,
454
+ models: value.models,
455
+ baseModelId: value.baseModelId,
456
+ ...(value.compactRatio !== undefined ? { compactRatio: value.compactRatio } : {}),
457
+ advisor: value.advisor,
458
+ subagents: value.subagents ?? current?.subagents ?? DEFAULT_SUBAGENTS_CONFIG,
459
+ browser: value.browser ?? current?.browser ?? DEFAULT_BROWSER_CONFIG,
460
+ tools: value.tools,
461
+ drafts: value.drafts,
462
+ savedAt: Math.max(Date.now(), (current?.savedAt ?? 0) + 1),
463
+ };
464
+ await writeConfigFileUnlocked(file, next);
465
+ return next;
109
466
  }
110
- catch {
467
+ finally {
468
+ await release();
111
469
  }
112
470
  }