maestro-flow 0.5.3 → 0.5.31

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 (259) hide show
  1. package/.agents/skills/learn-follow/SKILL.md +114 -114
  2. package/.agents/skills/learn-investigate/SKILL.md +138 -139
  3. package/.agents/skills/learn-second-opinion/SKILL.md +105 -109
  4. package/.agents/skills/maestro/SKILL.md +2 -10
  5. package/.agents/skills/maestro-amend/SKILL.md +152 -152
  6. package/.agents/skills/maestro-analyze/SKILL.md +201 -252
  7. package/.agents/skills/maestro-blueprint/SKILL.md +175 -190
  8. package/.agents/skills/maestro-brainstorm/SKILL.md +196 -200
  9. package/.agents/skills/maestro-collab/SKILL.md +159 -159
  10. package/.agents/skills/maestro-companion/SKILL.md +517 -517
  11. package/.agents/skills/maestro-composer/SKILL.md +173 -164
  12. package/.agents/skills/maestro-execute/SKILL.md +169 -170
  13. package/.agents/skills/maestro-fork/SKILL.md +97 -96
  14. package/.agents/skills/maestro-grill/SKILL.md +161 -162
  15. package/.agents/skills/maestro-guard/SKILL.md +93 -92
  16. package/.agents/skills/maestro-impeccable/SKILL.md +296 -253
  17. package/.agents/skills/maestro-init/SKILL.md +117 -118
  18. package/.agents/skills/maestro-merge/SKILL.md +73 -66
  19. package/.agents/skills/maestro-milestone-audit/SKILL.md +4 -10
  20. package/.agents/skills/maestro-milestone-complete/SKILL.md +6 -7
  21. package/.agents/skills/maestro-milestone-release/SKILL.md +122 -131
  22. package/.agents/skills/maestro-next/SKILL.md +241 -245
  23. package/.agents/skills/maestro-overlay/SKILL.md +176 -166
  24. package/.agents/skills/maestro-plan/SKILL.md +211 -197
  25. package/.agents/skills/maestro-player/SKILL.md +167 -167
  26. package/.agents/skills/maestro-quick/SKILL.md +69 -63
  27. package/.agents/skills/maestro-ralph/SKILL.md +2 -36
  28. package/.agents/skills/maestro-ralph-beta/SKILL.md +861 -872
  29. package/.agents/skills/maestro-ralph-execute/SKILL.md +234 -234
  30. package/.agents/skills/maestro-roadmap/SKILL.md +159 -172
  31. package/.agents/skills/maestro-swarm-workflow/SKILL.md +229 -250
  32. package/.agents/skills/maestro-tools-execute/SKILL.md +108 -103
  33. package/.agents/skills/maestro-tools-register/SKILL.md +148 -143
  34. package/.agents/skills/maestro-ui-codify/SKILL.md +103 -86
  35. package/.agents/skills/maestro-universal-workflow/SKILL.md +534 -547
  36. package/.agents/skills/maestro-update/SKILL.md +109 -106
  37. package/.agents/skills/manage-codebase-rebuild/SKILL.md +73 -71
  38. package/.agents/skills/manage-harvest/SKILL.md +83 -81
  39. package/.agents/skills/manage-issue/SKILL.md +59 -60
  40. package/.agents/skills/manage-issue-discover/SKILL.md +70 -68
  41. package/.agents/skills/manage-kg-extractors/SKILL.md +130 -0
  42. package/.agents/skills/manage-knowhow/SKILL.md +70 -66
  43. package/.agents/skills/manage-knowhow-capture/SKILL.md +79 -69
  44. package/.agents/skills/manage-knowledge-audit/SKILL.md +91 -74
  45. package/.agents/skills/manage-status/SKILL.md +52 -42
  46. package/.agents/skills/manage-wiki/SKILL.md +69 -58
  47. package/.agents/skills/odyssey-debug/SKILL.md +445 -459
  48. package/.agents/skills/odyssey-improve/SKILL.md +477 -491
  49. package/.agents/skills/odyssey-planex/SKILL.md +576 -587
  50. package/.agents/skills/odyssey-review-test-fix/SKILL.md +400 -413
  51. package/.agents/skills/odyssey-ui/SKILL.md +431 -448
  52. package/.agents/skills/quality-auto-test/SKILL.md +140 -123
  53. package/.agents/skills/quality-debug/SKILL.md +145 -106
  54. package/.agents/skills/quality-refactor/SKILL.md +91 -53
  55. package/.agents/skills/quality-retrospective/SKILL.md +109 -63
  56. package/.agents/skills/quality-review/SKILL.md +141 -114
  57. package/.agents/skills/quality-sync/SKILL.md +74 -38
  58. package/.agents/skills/quality-test/SKILL.md +133 -103
  59. package/.agents/skills/security-audit/SKILL.md +217 -166
  60. package/.agents/skills/spec-add/SKILL.md +66 -59
  61. package/.agents/skills/spec-load/SKILL.md +68 -68
  62. package/.agents/skills/spec-remove/SKILL.md +42 -42
  63. package/.agents/skills/spec-setup/SKILL.md +38 -41
  64. package/.agy/skills/learn-follow/SKILL.md +114 -114
  65. package/.agy/skills/learn-investigate/SKILL.md +138 -139
  66. package/.agy/skills/learn-second-opinion/SKILL.md +105 -109
  67. package/.agy/skills/maestro/SKILL.md +2 -10
  68. package/.agy/skills/maestro-amend/SKILL.md +152 -152
  69. package/.agy/skills/maestro-analyze/SKILL.md +201 -252
  70. package/.agy/skills/maestro-blueprint/SKILL.md +175 -190
  71. package/.agy/skills/maestro-brainstorm/SKILL.md +196 -200
  72. package/.agy/skills/maestro-collab/SKILL.md +159 -159
  73. package/.agy/skills/maestro-companion/SKILL.md +517 -517
  74. package/.agy/skills/maestro-composer/SKILL.md +173 -164
  75. package/.agy/skills/maestro-execute/SKILL.md +169 -170
  76. package/.agy/skills/maestro-fork/SKILL.md +97 -96
  77. package/.agy/skills/maestro-grill/SKILL.md +161 -162
  78. package/.agy/skills/maestro-guard/SKILL.md +93 -92
  79. package/.agy/skills/maestro-impeccable/SKILL.md +296 -253
  80. package/.agy/skills/maestro-init/SKILL.md +117 -118
  81. package/.agy/skills/maestro-merge/SKILL.md +73 -66
  82. package/.agy/skills/maestro-milestone-audit/SKILL.md +4 -10
  83. package/.agy/skills/maestro-milestone-complete/SKILL.md +6 -7
  84. package/.agy/skills/maestro-milestone-release/SKILL.md +122 -131
  85. package/.agy/skills/maestro-next/SKILL.md +241 -245
  86. package/.agy/skills/maestro-overlay/SKILL.md +176 -166
  87. package/.agy/skills/maestro-plan/SKILL.md +211 -197
  88. package/.agy/skills/maestro-player/SKILL.md +167 -167
  89. package/.agy/skills/maestro-quick/SKILL.md +69 -63
  90. package/.agy/skills/maestro-ralph/SKILL.md +2 -36
  91. package/.agy/skills/maestro-ralph-beta/SKILL.md +861 -872
  92. package/.agy/skills/maestro-ralph-execute/SKILL.md +234 -234
  93. package/.agy/skills/maestro-roadmap/SKILL.md +159 -172
  94. package/.agy/skills/maestro-swarm-workflow/SKILL.md +229 -250
  95. package/.agy/skills/maestro-tools-execute/SKILL.md +108 -103
  96. package/.agy/skills/maestro-tools-register/SKILL.md +148 -143
  97. package/.agy/skills/maestro-ui-codify/SKILL.md +103 -86
  98. package/.agy/skills/maestro-universal-workflow/SKILL.md +534 -547
  99. package/.agy/skills/maestro-update/SKILL.md +109 -106
  100. package/.agy/skills/manage-codebase-rebuild/SKILL.md +73 -71
  101. package/.agy/skills/manage-harvest/SKILL.md +83 -81
  102. package/.agy/skills/manage-issue/SKILL.md +59 -60
  103. package/.agy/skills/manage-issue-discover/SKILL.md +70 -68
  104. package/.agy/skills/manage-kg-extractors/SKILL.md +130 -0
  105. package/.agy/skills/manage-knowhow/SKILL.md +70 -66
  106. package/.agy/skills/manage-knowhow-capture/SKILL.md +79 -69
  107. package/.agy/skills/manage-knowledge-audit/SKILL.md +91 -74
  108. package/.agy/skills/manage-status/SKILL.md +52 -42
  109. package/.agy/skills/manage-wiki/SKILL.md +69 -58
  110. package/.agy/skills/odyssey-debug/SKILL.md +445 -459
  111. package/.agy/skills/odyssey-improve/SKILL.md +477 -491
  112. package/.agy/skills/odyssey-planex/SKILL.md +576 -587
  113. package/.agy/skills/odyssey-review-test-fix/SKILL.md +400 -413
  114. package/.agy/skills/odyssey-ui/SKILL.md +431 -448
  115. package/.agy/skills/quality-auto-test/SKILL.md +140 -123
  116. package/.agy/skills/quality-debug/SKILL.md +145 -106
  117. package/.agy/skills/quality-refactor/SKILL.md +91 -53
  118. package/.agy/skills/quality-retrospective/SKILL.md +109 -63
  119. package/.agy/skills/quality-review/SKILL.md +141 -114
  120. package/.agy/skills/quality-sync/SKILL.md +74 -38
  121. package/.agy/skills/quality-test/SKILL.md +133 -103
  122. package/.agy/skills/security-audit/SKILL.md +217 -166
  123. package/.agy/skills/spec-add/SKILL.md +66 -59
  124. package/.agy/skills/spec-load/SKILL.md +68 -68
  125. package/.agy/skills/spec-remove/SKILL.md +42 -42
  126. package/.agy/skills/spec-setup/SKILL.md +38 -41
  127. package/.claude/commands/learn-follow.md +127 -127
  128. package/.claude/commands/learn-investigate.md +151 -152
  129. package/.claude/commands/learn-second-opinion.md +118 -122
  130. package/.claude/commands/maestro-amend.md +164 -164
  131. package/.claude/commands/maestro-analyze.md +215 -266
  132. package/.claude/commands/maestro-blueprint.md +189 -204
  133. package/.claude/commands/maestro-brainstorm.md +209 -213
  134. package/.claude/commands/maestro-collab.md +172 -172
  135. package/.claude/commands/maestro-companion.md +531 -531
  136. package/.claude/commands/maestro-composer.md +188 -179
  137. package/.claude/commands/maestro-execute.md +183 -184
  138. package/.claude/commands/maestro-fork.md +111 -110
  139. package/.claude/commands/maestro-grill.md +175 -176
  140. package/.claude/commands/maestro-guard.md +103 -102
  141. package/.claude/commands/maestro-impeccable.md +311 -268
  142. package/.claude/commands/maestro-init.md +130 -131
  143. package/.claude/commands/maestro-merge.md +87 -80
  144. package/.claude/commands/maestro-milestone-audit.md +4 -10
  145. package/.claude/commands/maestro-milestone-complete.md +6 -7
  146. package/.claude/commands/maestro-milestone-release.md +136 -145
  147. package/.claude/commands/maestro-next.md +253 -257
  148. package/.claude/commands/maestro-overlay.md +188 -178
  149. package/.claude/commands/maestro-plan.md +225 -211
  150. package/.claude/commands/maestro-player.md +182 -182
  151. package/.claude/commands/maestro-quick.md +83 -77
  152. package/.claude/commands/maestro-ralph-beta.md +875 -886
  153. package/.claude/commands/maestro-ralph-execute.md +247 -247
  154. package/.claude/commands/maestro-ralph.md +2 -36
  155. package/.claude/commands/maestro-roadmap.md +173 -186
  156. package/.claude/commands/maestro-swarm-workflow.md +243 -264
  157. package/.claude/commands/maestro-tools-execute.md +122 -117
  158. package/.claude/commands/maestro-tools-register.md +162 -157
  159. package/.claude/commands/maestro-ui-codify.md +117 -100
  160. package/.claude/commands/maestro-universal-workflow.md +548 -561
  161. package/.claude/commands/maestro-update.md +122 -119
  162. package/.claude/commands/maestro.md +2 -10
  163. package/.claude/commands/manage-codebase-rebuild.md +87 -85
  164. package/.claude/commands/manage-harvest.md +97 -95
  165. package/.claude/commands/manage-issue-discover.md +83 -81
  166. package/.claude/commands/manage-issue.md +72 -73
  167. package/.claude/commands/manage-kg-extractors.md +128 -0
  168. package/.claude/commands/manage-knowhow-capture.md +92 -82
  169. package/.claude/commands/manage-knowhow.md +83 -79
  170. package/.claude/commands/manage-knowledge-audit.md +105 -88
  171. package/.claude/commands/manage-status.md +62 -52
  172. package/.claude/commands/manage-wiki.md +82 -71
  173. package/.claude/commands/odyssey-debug.md +459 -473
  174. package/.claude/commands/odyssey-improve.md +491 -505
  175. package/.claude/commands/odyssey-planex.md +590 -601
  176. package/.claude/commands/odyssey-review-test-fix.md +414 -427
  177. package/.claude/commands/odyssey-ui.md +445 -462
  178. package/.claude/commands/quality-auto-test.md +153 -136
  179. package/.claude/commands/quality-debug.md +159 -120
  180. package/.claude/commands/quality-refactor.md +105 -67
  181. package/.claude/commands/quality-retrospective.md +123 -77
  182. package/.claude/commands/quality-review.md +155 -128
  183. package/.claude/commands/quality-sync.md +88 -52
  184. package/.claude/commands/quality-test.md +147 -117
  185. package/.claude/commands/security-audit.md +230 -179
  186. package/.claude/commands/spec-add.md +77 -70
  187. package/.claude/commands/spec-load.md +78 -78
  188. package/.claude/commands/spec-remove.md +55 -55
  189. package/.claude/commands/spec-setup.md +49 -52
  190. package/dist/src/cli.js +1 -1
  191. package/dist/src/cli.js.map +1 -1
  192. package/dist/src/commands/kg.d.ts.map +1 -1
  193. package/dist/src/commands/kg.js +11 -5
  194. package/dist/src/commands/kg.js.map +1 -1
  195. package/dist/src/graph/kg/extraction/code/code-extractor.d.ts +2 -0
  196. package/dist/src/graph/kg/extraction/code/code-extractor.d.ts.map +1 -1
  197. package/dist/src/graph/kg/extraction/code/code-extractor.js +32 -3
  198. package/dist/src/graph/kg/extraction/code/code-extractor.js.map +1 -1
  199. package/dist/src/graph/kg/extraction/code/plugin-engine.d.ts +35 -0
  200. package/dist/src/graph/kg/extraction/code/plugin-engine.d.ts.map +1 -0
  201. package/dist/src/graph/kg/extraction/code/plugin-engine.js +573 -0
  202. package/dist/src/graph/kg/extraction/code/plugin-engine.js.map +1 -0
  203. package/dist/src/graph/kg/extraction/code/plugin-types.d.ts +95 -0
  204. package/dist/src/graph/kg/extraction/code/plugin-types.d.ts.map +1 -0
  205. package/dist/src/graph/kg/extraction/code/plugin-types.js +5 -0
  206. package/dist/src/graph/kg/extraction/code/plugin-types.js.map +1 -0
  207. package/dist/src/graph/kg/extraction/orchestrator.d.ts.map +1 -1
  208. package/dist/src/graph/kg/extraction/orchestrator.js +17 -5
  209. package/dist/src/graph/kg/extraction/orchestrator.js.map +1 -1
  210. package/dist/src/graph/kg/schema.sql +16 -11
  211. package/dist/src/graph/kg/surface/cli.d.ts.map +1 -1
  212. package/dist/src/graph/kg/surface/cli.js +153 -56
  213. package/dist/src/graph/kg/surface/cli.js.map +1 -1
  214. package/dist/src/hooks/workspace.d.ts +4 -2
  215. package/dist/src/hooks/workspace.d.ts.map +1 -1
  216. package/dist/src/hooks/workspace.js +6 -2
  217. package/dist/src/hooks/workspace.js.map +1 -1
  218. package/package.json +91 -91
  219. package/workflows/analyze.md +25 -49
  220. package/workflows/auto-test.md +699 -699
  221. package/workflows/blueprint.md +403 -431
  222. package/workflows/brainstorm.md +54 -195
  223. package/workflows/business-test.md +570 -570
  224. package/workflows/claude-instructions.md +23 -51
  225. package/workflows/codex-instructions.md +27 -77
  226. package/workflows/coding-philosophy.md +69 -69
  227. package/workflows/command-authoring.md +823 -823
  228. package/workflows/debug.md +43 -98
  229. package/workflows/delegate-usage.md +39 -241
  230. package/workflows/execute.md +4 -53
  231. package/workflows/grill.md +12 -56
  232. package/workflows/harvest.md +22 -68
  233. package/workflows/init.md +148 -148
  234. package/workflows/instruction-authoring-guide.md +97 -0
  235. package/workflows/issue-execute.md +110 -110
  236. package/workflows/issue-gaps-analyze.codex.md +260 -260
  237. package/workflows/issue-gaps-analyze.md +216 -216
  238. package/workflows/issue-plan.md +110 -110
  239. package/workflows/issue.md +338 -346
  240. package/workflows/knowhow.md +0 -32
  241. package/workflows/learn.md +277 -277
  242. package/workflows/maestro-chain-execute.md +20 -20
  243. package/workflows/refactor.md +22 -44
  244. package/workflows/retrospective.md +16 -65
  245. package/workflows/review.md +446 -486
  246. package/workflows/roadmap.md +35 -132
  247. package/workflows/skill-authoring.md +265 -265
  248. package/workflows/spec-generate.md +470 -470
  249. package/workflows/specs-remove.md +104 -104
  250. package/workflows/sync.md +11 -41
  251. package/workflows/test-gen.md +226 -226
  252. package/workflows/test.md +385 -475
  253. package/workflows/ui-design.md +391 -391
  254. package/workflows/ui-style.md +199 -199
  255. package/workflows/wiki-connect.md +151 -151
  256. package/workflows/wiki-digest.md +178 -178
  257. package/workflows/wiki-manage.md +109 -109
  258. package/workflows/cli-tools-usage.md +0 -252
  259. package/workflows/delegate-protocol.codex.md +0 -65
@@ -14,550 +14,537 @@ allowed-tools:
14
14
  ---
15
15
  <!-- Open-standard mirror generated by scripts/build-agents-standard.mjs — do not edit; re-run after editing .claude/ source. -->
16
16
 
17
- <purpose>
18
- Dynamic workflow generator that inherits the adversarial decision philosophy.
19
- Unlike swarm-workflow (fixed 8 scripts), this command generates task-specific
20
- Workflow scripts on-the-fly with adversarial patterns baked into every decision point.
21
-
22
- Flow: Scan library → Match or Design → Generate script → Execute → Persist
23
-
24
- Generated scripts accumulate at `~/.maestro/workflows/dynamic/uwf-*.js`,
25
- building a reusable library over time.
26
-
27
- Adversarial depth levels:
28
- | Level | Decision Pattern | Agent Cost |
29
- |-------|-----------------|------------|
30
- | `shallow` | Single skeptic per decision | +1 per decision |
31
- | `standard` | 3-vote majority per decision (default) | +4 per decision |
32
- | `deep` | Cross-verify + 3-way advocacy + meta-skeptic | +8 per decision |
33
- </purpose>
34
-
35
- <context>
36
- $ARGUMENTS intent text with optional flags.
37
-
38
- **Parse:**
39
- ```
40
- --name <slug> → 指定生成脚本名(默认从 intent 自动生成)
41
- --depth <level> → shallow | standard | deep(默认 standard)
42
- --dry-run → 只生成脚本,不执行
43
- --from <script> → 基于已有脚本进行修改(uwf-xxx 或 wf-xxx)
44
- --resume <runId> → 恢复之前的运行(透传给 Workflow)
45
- Remaining → intent
46
- ```
47
-
48
- **Library locations:**
49
- - Fixed scripts: `~/.maestro/workflows/swarm/wf-*.js`
50
- - Dynamic scripts: `~/.maestro/workflows/dynamic/uwf-*.js`
51
- </context>
52
-
53
- <state_machine>
54
-
55
- <states>
56
- S_PARSE — 解析参数和意图 PERSIST:
57
- S_SCAN — 扫描现有 workflow 库匹配 PERSIST: —
58
- S_DECIDE — 用户选择:复用现有 / 生成新脚本 PERSIST:
59
- S_DESIGN — 分析任务、设计工作流结构 PERSIST:
60
- S_GENERATE — 生成脚本 写入文件 node --check 验证 PERSIST: uwf-{slug}.js
61
- S_EXECUTE — 调用 Workflow 工具执行 PERSIST: —
62
- S_PERSIST — 保存脚本到 dynamic/ 目录 PERSIST:
63
- </states>
64
-
65
- <transitions>
66
-
67
- S_PARSE:
68
- S_SCAN WHEN: intent parsed DO: A_PARSE_ARGS
69
- → END WHEN: no intent
70
-
71
- S_SCAN:
72
- S_DECIDE WHEN: matches found DO: A_SCAN_LIBRARY
73
- S_DESIGN WHEN: no matches DO: A_SCAN_LIBRARY
74
-
75
- S_DECIDE:
76
- S_EXECUTE WHEN: user picks existing script DO: —
77
- S_DESIGN WHEN: user wants new script DO:
78
- S_DESIGN WHEN: --from specified DO: —
79
-
80
- S_DESIGN:
81
- S_GENERATE DO: A_DESIGN_WORKFLOW
82
-
83
- S_GENERATE:
84
- → S_EXECUTE WHEN: Write + node --check pass AND NOT --dry-run DO: A_GENERATE_SCRIPT
85
- → S_PERSIST WHEN: --dry-run (file already written) DO: A_GENERATE_SCRIPT
86
- → S_GENERATE WHEN: node --check fails (retry ≤2) DO: A_GENERATE_SCRIPT (fix & retry)
87
- END WHEN: node --check fails after 2 retries DO: report E003
88
-
89
- S_EXECUTE:
90
- S_PERSIST WHEN: workflow completed DO: A_EXECUTE_WORKFLOW
91
- END WHEN: workflow failed
92
-
93
- S_PERSIST:
94
- → END DO: A_PERSIST_SCRIPT
95
-
96
- </transitions>
97
-
98
- <actions>
99
-
100
- ### A_PARSE_ARGS
101
-
102
- 1. 提取 flags: `--name`, `--depth`, `--dry-run`, `--from`, `--resume`
103
- 2. 剩余文本作为 intent
104
- 3. depth 默认 `standard`
105
- 4. 若有 `--resume`,跳到 S_EXECUTE(直接恢复)
106
- 5. 若有 `--from`,定位源脚本路径
107
-
108
- ### A_SCAN_LIBRARY
109
-
110
- 扫描两个目录,读取每个 `.js` 文件的 `meta` 块提取 `name`、`description`、`whenToUse`:
111
-
112
- 1. **Fixed scripts**: 展开 `~/.maestro/workflows/swarm/wf-*.js` 为绝对路径
113
- - Glob 查找所有匹配文件
114
- - 读取每个文件前 10 行,提取 `meta.name`、`meta.description`、`meta.whenToUse`
115
- 2. **Dynamic scripts**: 展开 `~/.maestro/workflows/dynamic/uwf-*.js`
116
- - 同上
117
- 3. **匹配评分**:对每个脚本,评估其 description/whenToUse 与 intent 的语义相关度
118
- 4. **输出**:
119
- - 匹配度 > 70% 的脚本列表(最多 3 个)
120
- - 每个列出:name、description、scriptPath、匹配理由
121
- - 无匹配则直接跳 S_DESIGN
122
-
123
- 若有匹配,用 ask_user 让用户选择:
124
- - 选项 1-3: 使用现有脚本(附 preview 显示脚本 meta)
125
- - 最后选项: "生成全新脚本"
126
-
127
- ### A_DESIGN_WORKFLOW
128
-
129
- 分析任务,确定工作流结构。这是核心设计步骤。
130
-
131
- **Step 1 — 任务分解**
132
-
133
- 将 intent 分解为:
134
- ```
135
- work_items: 需要完成的具体工作单元
136
- - { id, description, type: 'explore'|'analyze'|'create'|'verify'|'decide' }
137
- decision_points: 需要做出判断的节点
138
- - { id, question, type: 'go-nogo'|'pass-fail'|'select-best'|'resolve-conflict'|'assess-quality' }
139
- data_flow: 数据在工作单元间如何流动
140
- - { from, to, data_shape }
141
- ```
142
-
143
- **Step 2 阶段编排**
144
-
145
- work_items 组织为执行阶段:
146
- ```
147
- phases: [
148
- { title, work_items[], parallel: true|false },
149
- ...
150
- ]
151
- ```
152
-
153
- 规则:
154
- - 无依赖的 work_items 放同一阶段(parallel)
155
- - 有依赖的放后续阶段
156
- - 每个 decision_point 后紧跟一个对抗决策阶段
157
-
158
- **Step 3 — 对抗模式选择**
159
-
160
- 根据 decision_point.type --depth 选择对抗模式(参考 ADVERSARIAL_PATTERNS):
161
-
162
- | decision_type | shallow | standard | deep |
163
- |--------------|---------|----------|------|
164
- | go-nogo | 1 skeptic | 3-way advocacy + referee | cross-verify + 3-way advocacy + meta-skeptic |
165
- | pass-fail | 1 challenger | prosecutor/defender/judge | cross-verify + prosecutor/defender + 3-vote |
166
- | select-best | 1 critic | N proposals + judge panel | N proposals + judge + 3-critic challenge |
167
- | resolve-conflict | 1 mediator | 3 philosophy proposals + arbitrator | 3 proposals + arbitrator + meta-skeptic |
168
- | assess-quality | 1 skeptic | 3-vote (strict/lenient/objective) | cross-verify + 3-vote + meta-skeptic |
169
-
170
- **Step 4 Schema 设计**
171
-
172
- 为每个 agent 调用设计 JSON Schema:
173
- - 工作 agent: 任务特定 schema
174
- - 对抗 agent: 使用标准对抗 schema(见 ADVERSARIAL_PATTERNS)
175
-
176
- **Step 5 — 产出蓝图**
177
-
178
- ```
179
- blueprint: {
180
- name: 'uwf-{slug}',
181
- description: string,
182
- phases: [{ title, detail }],
183
- agents: [{ id, prompt_outline, schema_name, agentType?, phase }],
184
- adversarial_gates: [{ decision_id, pattern, agents[] }],
185
- estimated_agent_count: number,
186
- }
187
- ```
188
-
189
- 向用户展示蓝图摘要,包含预估 agent 数量。
190
- `--dry-run` 则在 S_GENERATE 后停止。
191
-
192
- ### A_GENERATE_SCRIPT
193
-
194
- 根据蓝图生成完整的 JavaScript 脚本。**先写文件,再通过 scriptPath 执行**(避免内联 script 字符串的编码/转义问题)。
195
-
196
- 若 `--from` 指定了基础脚本,先 Read 源脚本,然后在其基础上修改。
197
-
198
- **脚本结构模板:**
199
-
200
- ```javascript
201
- export const meta = {
202
- name: '{blueprint.name}',
203
- description: '{English description}',
204
- whenToUse: '{English usage scenario}',
205
- phases: [
206
- { title: '{EnglishTitle}', detail: '{English detail}' },
207
- ],
208
- }
209
-
210
- // --- Schemas (top-level constants, never inline) ---
211
- const WORK_SCHEMA = { type: 'object', properties: { ... }, required: [...] }
212
- const CHALLENGE_SCHEMA = { ... }
213
-
214
- // --- Args ---
215
- const target = args?.target || 'default'
216
-
217
- // --- Phase 1: {title} ---
218
- phase('{title}')
219
- const results = await parallel([
220
- () => agent('prompt text', { label: 'work:1', phase: '{title}', schema: WORK_SCHEMA }),
221
- ])
222
-
223
- // --- Phase 2: Adversarial Gate ---
224
- phase('{adversarial_phase_title}')
225
- // 对抗模式代码 ADVERSARIAL_PATTERNS 模板生成
226
-
227
- return { ... }
228
- ```
229
-
230
- **生成规则(必须全部遵守):**
231
-
232
- | # | 规则 | 原因 |
233
- |---|------|------|
234
- | 1 | **纯 JavaScript** — 无 TypeScript 类型注解(`: string`、`interface`、泛型) | 解析器不支持 TS |
235
- | 2 | **meta 块全英文** — `name`、`description`、`whenToUse`、`phases[].title/detail` 只用 ASCII 字符 | 中文在 script 字符串序列化时触发 `\uXXXX` 解析错误 |
236
- | 3 | **禁用 API** 不用 `Date.now()`、`Math.random()`、无参 `new Date()` | 破坏 resume 缓存匹配 |
237
- | 4 | **Schema 独立声明** — 所有 JSON Schema 在文件顶部声明为 `const XXX_SCHEMA = {...}`,agent 调用中用 `schema: XXX_SCHEMA` 引用 | 内联大 Schema 易出括号匹配错误 |
238
- | 5 | **字符串用 `+` 拼接** — agent prompt 中嵌入变量用 `'text ' + variable + ' more text'`,**不用模板字符串** | 反引号嵌套和 `${}` 转义是最常见的解析错误源 |
239
- | 6 | **回调用 `function`** — `array.filter(function(x) { return x })` 而非箭头函数 | 箭头函数隐式返回对象 `() => ({})` 易遗漏外层括号 |
240
- | 7 | **`phase` 不做变量名** 不遮蔽全局 `phase()` 函数 | 遮蔽后 `phase('X')` 调用会崩溃 |
241
- | 8 | **路径用正斜杠** — 字符串中路径用 `src/auth/` 不用 `src\\auth\\` | `\a`、`\u` 等被解析为转义序列 |
242
- | 9 | **`agentType`** 仅在有明确匹配时设置(如 `Explore`、`workflow-analyzer`) | 无效 agentType 导致运行时错误 |
243
- | 10 | **null 安全** 链式访问用 `?.`,数组操作前加 `.filter(Boolean)` | agent 返回 null(用户跳过)时链式调用崩溃 |
244
-
245
- **常见错误对照:**
246
-
247
- ```javascript
248
- // BAD meta 中文导致 \uXXXX 解析错误
249
- export const meta = { name: 'uwf-x', description: '参数审计' }
250
- // GOOD
251
- export const meta = { name: 'uwf-x', description: 'Parameter audit for unused/ambiguous/dead params' }
252
-
253
- // BAD模板字符串嵌套
254
- agent(`Analyze ${item.name} for ${reason}`)
255
- // GOOD — 字符串拼接
256
- agent('Analyze ' + item.name + ' for ' + reason)
257
-
258
- // BAD — Schema 内联在 agent 调用中
259
- agent('prompt', { schema: { type: 'object', properties: { a: { type: 'string' }, b: { type: 'array', items: { type: 'object', properties: { ... } } } } } })
260
- // GOOD — Schema 顶部声明
261
- const MY_SCHEMA = { type: 'object', properties: { a: { type: 'string' } }, required: ['a'] }
262
- agent('prompt', { schema: MY_SCHEMA })
263
-
264
- // BAD 箭头函数隐式返回对象
265
- results.map(r => ({ ...r, verified: true }))
266
- // GOODfunction + 显式 return
267
- results.map(function(r) { return Object.assign({}, r, { verified: true }) })
268
-
269
- // BAD — 反斜杠路径
270
- const path = 'C:\Users\project\src'
271
- // GOOD
272
- const path = 'C:/Users/project/src' // 或直接不在脚本中硬编码路径
273
- ```
274
-
275
- **Step 1生成脚本内容**
276
-
277
- 按蓝图结构 + 上述规则生成完整 JavaScript 字符串。agent prompt 内部可以使用中文(prompt 是运行时字符串,不影响解析)。
278
-
279
- **Step 2 — 写入文件**
280
-
281
- ```
282
- write_file({
283
- file_path: expandPath('~/.maestro/workflows/dynamic/uwf-{slug}.js'),
284
- content: generatedScript
285
- })
286
- ```
287
-
288
- **Step 3 — 语法验证**
289
-
290
- ```
291
- shell({ command: 'node --check "path/to/uwf-{slug}.js"' })
292
- ```
293
-
294
- 若验证失败:
295
- 1. 读取错误信息中的行号和错误类型
296
- 2. 针对性修复(常见:遗漏逗号、括号不匹配、保留字冲突)
297
- 3. 重新 Write + 验证(最多重试 2 次)
298
- 4. 仍失败则报 E003,展示脚本内容和错误信息
299
-
300
- 验证通过后进入 S_EXECUTE(若非 `--dry-run`)。
301
-
302
- ### A_EXECUTE_WORKFLOW
303
-
304
- **必须用 scriptPath 调用**(不用 script 内联字符串):
305
-
306
- ```
307
- Workflow({
308
- scriptPath: expandPath('~/.maestro/workflows/dynamic/uwf-{slug}.js'),
309
- args: taskSpecificArgs, // 从 intent 推断
310
- resumeFromRunId: resumeId // 若有
311
- })
312
- ```
313
-
314
- 记录返回的 `runId`。脚本已在 A_GENERATE_SCRIPT 中写入文件,无需再次持久化。
315
-
316
- ### A_PERSIST_SCRIPT
317
-
318
- 脚本已在 A_GENERATE_SCRIPT Step 2 写入 `~/.maestro/workflows/dynamic/uwf-{slug}.js`。
319
-
320
- 1. 确认文件存在(Glob 检查)
321
- 2. 展示保存路径和使用方式:
322
- ```
323
- Saved: ~/.maestro/workflows/dynamic/uwf-{slug}.js
324
- Reuse: /maestro-universal-workflow --from uwf-{slug} "{new intent}"
325
- Resume: /maestro-universal-workflow --resume {runId}
326
- Via swarm: /maestro-swarm-workflow --script uwf-{slug}
327
- ```
328
-
329
- </actions>
330
-
331
- </state_machine>
332
-
333
- <adversarial_patterns>
334
-
335
- 以下是对抗决策模式的代码模板库。A_GENERATE_SCRIPT 时按 decision_type depth 选用。
336
-
337
- ### PATTERN: Skeptic CrossVerify (shallow+)
338
-
339
- 用于:对并行分析结果逐项挑战。
340
-
341
- ```javascript
342
- // 每个结果被 skeptic 挑战
343
- const challenges = await pipeline(
344
- results,
345
- (result) => agent(
346
- `You are an adversarial SKEPTIC. Challenge this assessment.
347
- Original: ${JSON.stringify(result)}
348
- Your job: find counter-evidence, check for biases, verify claims against actual code.
349
- Default to challenge_result="weakened" if uncertain.`,
350
- { label: `challenge:${result.id}`, phase: '{phase}', schema: CHALLENGE_SCHEMA }
351
- )
352
- )
353
- ```
354
-
355
- CHALLENGE_SCHEMA:
356
- ```javascript
357
- const CHALLENGE_SCHEMA = {
358
- type: 'object',
359
- properties: {
360
- target: { type: 'string' },
361
- challenge_result: { type: 'string', enum: ['confirmed', 'weakened', 'overturned'] },
362
- adjusted_assessment: { type: 'string' },
363
- counter_evidence: { type: 'array', items: { type: 'string' } },
364
- confidence: { type: 'number', minimum: 0, maximum: 100 },
365
- reasoning: { type: 'string' },
366
- },
367
- required: ['target', 'challenge_result', 'confidence', 'reasoning'],
368
- }
369
- ```
370
-
371
- ### PATTERN: 3-Way Advocacy + Referee (standard+ go-nogo)
372
-
373
- 用于:go/no-go 类决策。
374
-
375
- ```javascript
376
- const advocacies = await parallel([
377
- () => agent('You are the GO ADVOCATE. Argue FOR proceeding...', { label: 'advocate:go', schema: ADVOCACY_SCHEMA }),
378
- () => agent('You are the NO-GO ADVOCATE. Argue AGAINST proceeding...', { label: 'advocate:nogo', schema: ADVOCACY_SCHEMA }),
379
- () => agent('You are the CONDITIONAL ADVOCATE. Argue for proceeding ONLY under conditions...', { label: 'advocate:conditional', schema: ADVOCACY_SCHEMA }),
380
- ])
381
- const decision = await agent('You are the REFEREE. Resolve the debate...', { label: 'referee', schema: DECISION_SCHEMA })
382
- ```
383
-
384
- ADVOCACY_SCHEMA:
385
- ```javascript
386
- const ADVOCACY_SCHEMA = {
387
- type: 'object',
388
- properties: {
389
- stance: { type: 'string' },
390
- argument: { type: 'string' },
391
- key_evidence: { type: 'array', items: { type: 'object', properties: { point: { type: 'string' }, strength: { type: 'string', enum: ['strong', 'moderate', 'weak'] } }, required: ['point'] } },
392
- weaknesses_acknowledged: { type: 'array', items: { type: 'string' } },
393
- conditions: { type: 'array', items: { type: 'string' } },
394
- confidence: { type: 'number', minimum: 0, maximum: 100 },
395
- },
396
- required: ['stance', 'argument', 'confidence'],
397
- }
398
- ```
399
-
400
- ### PATTERN: Prosecutor/Defender/Judge (standard+ pass-fail)
401
-
402
- 用于:通过/失败类判定。
403
-
404
- ```javascript
405
- const debate = await parallel([
406
- () => agent('You are the PROSECUTOR. Argue this should FAIL...', { label: 'prosecutor', schema: ARGUMENT_SCHEMA }),
407
- () => agent('You are the DEFENDER. Argue this should PASS...', { label: 'defender', schema: ARGUMENT_SCHEMA }),
408
- ])
409
- const verdict = await agent('You are the JUDGE. Resolve the debate...', { label: 'judge', schema: VERDICT_SCHEMA })
410
- ```
411
-
412
- ARGUMENT_SCHEMA:
413
- ```javascript
414
- const ARGUMENT_SCHEMA = {
415
- type: 'object',
416
- properties: {
417
- role: { type: 'string' },
418
- stance: { type: 'string', enum: ['pass', 'fail'] },
419
- argument: { type: 'string' },
420
- key_points: { type: 'array', items: { type: 'object', properties: { point: { type: 'string' }, evidence: { type: 'string' }, strength: { type: 'string', enum: ['strong', 'moderate', 'weak'] } }, required: ['point', 'evidence'] } },
421
- concessions: { type: 'array', items: { type: 'string' } },
422
- confidence: { type: 'number', minimum: 0, maximum: 100 },
423
- },
424
- required: ['role', 'stance', 'argument', 'key_points', 'confidence'],
425
- }
426
- ```
427
-
428
- ### PATTERN: 3-Vote Majority (standard+ assess-quality)
429
-
430
- 用于:质量评估、状态判定。
431
-
432
- ```javascript
433
- const votes = await parallel([
434
- () => agent('You are the STRICT voter...', { label: 'vote:strict', schema: VOTE_SCHEMA }),
435
- () => agent('You are the LENIENT voter...', { label: 'vote:lenient', schema: VOTE_SCHEMA }),
436
- () => agent('You are the OBJECTIVE voter...', { label: 'vote:objective', schema: VOTE_SCHEMA }),
437
- ])
438
- const majority = resolveVotes(votes) // majority wins, tie → objective
439
- const report = await agent('Arbitrate final report from votes...', { label: 'arbitrate', schema: REPORT_SCHEMA })
440
- ```
441
-
442
- VOTE_SCHEMA:
443
- ```javascript
444
- const VOTE_SCHEMA = {
445
- type: 'object',
446
- properties: {
447
- perspective: { type: 'string' },
448
- verdict: { type: 'string' },
449
- rationale: { type: 'string' },
450
- confidence: { type: 'number', minimum: 0, maximum: 100 },
451
- },
452
- required: ['perspective', 'verdict', 'rationale', 'confidence'],
453
- }
454
- ```
455
-
456
- ### PATTERN: Competing Proposals + Judge (standard+ select-best)
457
-
458
- 用于:方案选择。
459
-
460
- ```javascript
461
- const proposals = await parallel([
462
- () => agent('Strategy A: ...', { label: 'proposal:A', schema: PROPOSAL_SCHEMA }),
463
- () => agent('Strategy B: ...', { label: 'proposal:B', schema: PROPOSAL_SCHEMA }),
464
- () => agent('Strategy C: ...', { label: 'proposal:C', schema: PROPOSAL_SCHEMA }),
465
- ])
466
- const scores = await parallel(proposals.filter(Boolean).map(p => () =>
467
- agent(`Score this proposal: ${p.strategy}...`, { label: `judge:${p.strategy}`, schema: SCORE_SCHEMA })
468
- ))
469
- // select highest score
470
- ```
471
-
472
- ### PATTERN: Meta-Skeptic (deep only)
473
-
474
- 用于:挑战挑战者本身的发现。
475
-
476
- ```javascript
477
- const metaChallenge = await agent(
478
- `You are the META-SKEPTIC. Challenge the challengers themselves.
479
- Findings: ${digest}
480
- 1. Which findings are OVERBLOWN? (theatrical, unlikely, missing context)
481
- 2. What did they MISS? (blind spots, interactions, real risks obscured)
482
- 3. Rate overall challenge quality (1-5).`,
483
- { label: 'meta-skeptic', schema: META_CHALLENGE_SCHEMA }
484
- )
485
- ```
486
-
487
- </adversarial_patterns>
488
-
489
- <invariants>
490
- 1. **先查后建** — 必须先扫描现有库,避免重复生成相同功能的脚本
491
- 2. **对抗必选** — 每个 decision_point 必须有对应的对抗模式,不允许单 agent 决策
492
- 3. **depth 递进** — shallow ⊂ standard ⊂ deep,高 depth 包含低 depth 的所有模式
493
- 4. **纯 JS** — 生成的脚本必须是纯 JavaScript,不含 TypeScript 类型注解
494
- 5. **meta 全英文** — meta 块中 name/description/whenToUse/phases 只用 ASCII 字符(agent prompt 内可用中文)
495
- 6. **Schema 完整** — 每个 agent 调用必须有 schema,且 Schema 在文件顶部声明为独立常量
496
- 7. **先写后跑** — 脚本必须先 Write 到文件 → `node --check` 验证 → 再通过 `scriptPath` 执行(禁止内联 script 字符串)
497
- 8. **幂等命名** — 同名脚本覆盖(uwf-{slug}.js),用户可通过 --name 控制
498
- 9. **禁用 API** — 脚本内不使用 Date.now()、Math.random()、无参 new Date()
499
- 10. **变量安全** — 不使用 `phase` 作为变量名(避免遮蔽 phase() 函数)
500
- 11. **无模板字符串** agent prompt 用 `+` 拼接,不用反引号模板(避免嵌套转义错误)
501
- 12. **无反斜杠路径** — 字符串中路径用正斜杠(`\u`、`\a` 等会被解析为转义序列)
502
- </invariants>
503
-
504
- <appendix>
505
-
506
- ### 使用示例
507
-
508
- ```bash
509
- # 自动匹配或生成
510
- /maestro-universal-workflow "评估数据库迁移方案的可行性和风险"
511
-
512
- # 指定深度
513
- /maestro-universal-workflow "审查 auth 模块的安全性" --depth deep
514
-
515
- # 只生成不执行
516
- /maestro-universal-workflow "对比 3 种缓存策略" --dry-run --name cache-eval
517
-
518
- # 基于已有脚本修改
519
- /maestro-universal-workflow "类似 analyze 但加入成本维度" --from wf-analyze
520
-
521
- # 恢复之前的运行
522
- /maestro-universal-workflow --resume wf_abc123
523
- ```
524
-
525
- ### 生成脚本示例
526
-
527
- 用户 intent: "评估 3 种 API 认证方案(JWT/OAuth2/API Key),选出最优"
528
-
529
- 生成的脚本结构:
530
- ```
531
- Phase 1: Explore 探索代码库现有认证实现
532
- Phase 2: Evaluate 3agent 分别深入评估每种方案
533
- Phase 3: CrossVerify skeptic 挑战每个评估结果
534
- Phase 4: Compete 3 advocate 各持一种方案立场辩论
535
- Phase 5: Arbitrate referee 根据辩论结果选出最优方案
536
- ```
537
-
538
- 预估 agent 数: 1(explore) + 3(evaluate) + 3(cross-verify) + 3(advocates) + 1(referee) = 11
539
-
540
- ### swarm-workflow 的关系
541
-
542
- | 维度 | swarm-workflow | universal-workflow |
543
- |------|---------------|-------------------|
544
- | 脚本来源 | 固定 8 个预写脚本 | 动态生成 + 积累库 |
545
- | 适用范围 | 对应 8 maestro 命令 | 任意任务 |
546
- | 决策模式 | 脚本内硬编码 | depth 动态选择 |
547
- | 持久化 | 不生成新脚本 | 保存到 dynamic/ 复用 |
548
- | 推荐场景 | 已有匹配的标准命令 | 非标准任务、新领域 |
549
-
550
- universal-workflow 扫描时会同时检查 swarm/ 和 dynamic/ 目录,
551
- 若 swarm 脚本匹配度高则推荐使用 swarm-workflow 代替。
552
-
553
- ### Error Codes
554
-
555
- | Code | Description | Recovery |
556
- |------|-------------|----------|
557
- | E001 | 无 intent | 提示用户输入 |
558
- | E002 | 设计阶段无法分解任务 | 要求更具体的 intent |
559
- | E003 | 生成的脚本语法错误 | `node --check` 失败时:读取行号+错误类型 → 针对性修复 → 重试(最多 2 次)→ 仍失败则展示脚本+错误让用户手动修改 |
560
- | E004 | Workflow 执行失败 | 展示错误,提供 --resume |
561
- | E005 | 持久化失败 | 展示脚本内容,让用户手动保存 |
562
-
563
- </appendix>
17
+ <purpose>
18
+ Dynamic workflow generator: scan library for matches or generate task-specific Workflow scripts
19
+ on-the-fly with adversarial patterns. Scripts persist at `~/.maestro/workflows/dynamic/uwf-*.js`.
20
+ </purpose>
21
+
22
+ <context>
23
+ $ARGUMENTS — intent text with optional flags.
24
+
25
+ **Parse:**
26
+ ```
27
+ --name <slug> → 指定生成脚本名(默认从 intent 自动生成)
28
+ --depth <level> → shallow | standard | deep(默认 standard)
29
+ --dry-run → 只生成脚本,不执行
30
+ --from <script> → 基于已有脚本进行修改(uwf-xxx wf-xxx)
31
+ --resume <runId> → 恢复之前的运行(透传给 Workflow)
32
+ Remaining → intent
33
+ ```
34
+
35
+ **Library locations:**
36
+ - Fixed scripts: `~/.maestro/workflows/swarm/wf-*.js`
37
+ - Dynamic scripts: `~/.maestro/workflows/dynamic/uwf-*.js`
38
+ </context>
39
+
40
+ <state_machine>
41
+
42
+ <states>
43
+ S_PARSE — 解析参数和意图 PERSIST:
44
+ S_SCAN — 扫描现有 workflow 库匹配 PERSIST: —
45
+ S_DECIDE — 用户选择:复用现有 / 生成新脚本 PERSIST: —
46
+ S_DESIGN — 分析任务、设计工作流结构 PERSIST: —
47
+ S_GENERATE — 生成脚本 → 写入文件 → node --check 验证 PERSIST: uwf-{slug}.js
48
+ S_EXECUTE — 调用 Workflow 工具执行 PERSIST: —
49
+ S_PERSIST — 保存脚本到 dynamic/ 目录 PERSIST:
50
+ </states>
51
+
52
+ <transitions>
53
+
54
+ S_PARSE:
55
+ → S_SCAN WHEN: intent parsed DO: A_PARSE_ARGS
56
+ END WHEN: no intent
57
+
58
+ S_SCAN:
59
+ S_DECIDE WHEN: matches found DO: A_SCAN_LIBRARY
60
+ S_DESIGN WHEN: no matches DO: A_SCAN_LIBRARY
61
+
62
+ S_DECIDE:
63
+ → S_EXECUTE WHEN: user picks existing script DO: —
64
+ → S_DESIGN WHEN: user wants new script DO: —
65
+ → S_DESIGN WHEN: --from specified DO: —
66
+
67
+ S_DESIGN:
68
+ S_GENERATE DO: A_DESIGN_WORKFLOW
69
+
70
+ S_GENERATE:
71
+ → S_EXECUTE WHEN: Write + node --check pass AND NOT --dry-run DO: A_GENERATE_SCRIPT
72
+ S_PERSIST WHEN: --dry-run (file already written) DO: A_GENERATE_SCRIPT
73
+ S_GENERATE WHEN: node --check fails (retry ≤2) DO: A_GENERATE_SCRIPT (fix & retry)
74
+ → END WHEN: node --check fails after 2 retries DO: report E003
75
+
76
+ S_EXECUTE:
77
+ S_PERSIST WHEN: workflow completed DO: A_EXECUTE_WORKFLOW
78
+ END WHEN: workflow failed
79
+
80
+ S_PERSIST:
81
+ END DO: A_PERSIST_SCRIPT
82
+
83
+ </transitions>
84
+
85
+ <actions>
86
+
87
+ ### A_PARSE_ARGS
88
+
89
+ 1. 提取 flags: `--name`, `--depth`, `--dry-run`, `--from`, `--resume`
90
+ 2. 剩余文本作为 intent
91
+ 3. depth 默认 `standard`
92
+ 4. 若有 `--resume`,跳到 S_EXECUTE(直接恢复)
93
+ 5. 若有 `--from`,定位源脚本路径
94
+
95
+ ### A_SCAN_LIBRARY
96
+
97
+ 扫描两个目录,读取每个 `.js` 文件的 `meta` 块提取 `name`、`description`、`whenToUse`:
98
+
99
+ 1. **Fixed scripts**: 展开 `~/.maestro/workflows/swarm/wf-*.js` 为绝对路径
100
+ - Glob 查找所有匹配文件
101
+ - 读取每个文件前 10 行,提取 `meta.name`、`meta.description`、`meta.whenToUse`
102
+ 2. **Dynamic scripts**: 展开 `~/.maestro/workflows/dynamic/uwf-*.js`
103
+ - 同上
104
+ 3. **匹配评分**:对每个脚本,评估其 description/whenToUse 与 intent 的语义相关度
105
+ 4. **输出**:
106
+ - 匹配度 > 70% 的脚本列表(最多 3 个)
107
+ - 每个列出:name、description、scriptPath、匹配理由
108
+ - 无匹配则直接跳 S_DESIGN
109
+
110
+ 若有匹配,用 ask_user 让用户选择:
111
+ - 选项 1-3: 使用现有脚本(附 preview 显示脚本 meta)
112
+ - 最后选项: "生成全新脚本"
113
+
114
+ ### A_DESIGN_WORKFLOW
115
+
116
+ 分析任务,确定工作流结构。这是核心设计步骤。
117
+
118
+ **Step 1 — 任务分解**
119
+
120
+ intent 分解为:
121
+ ```
122
+ work_items: 需要完成的具体工作单元
123
+ - { id, description, type: 'explore'|'analyze'|'create'|'verify'|'decide' }
124
+ decision_points: 需要做出判断的节点
125
+ - { id, question, type: 'go-nogo'|'pass-fail'|'select-best'|'resolve-conflict'|'assess-quality' }
126
+ data_flow: 数据在工作单元间如何流动
127
+ - { from, to, data_shape }
128
+ ```
129
+
130
+ **Step 2 — 阶段编排**
131
+
132
+ 将 work_items 组织为执行阶段:
133
+ ```
134
+ phases: [
135
+ { title, work_items[], parallel: true|false },
136
+ ...
137
+ ]
138
+ ```
139
+
140
+ 规则:
141
+ - 无依赖的 work_items 放同一阶段(parallel)
142
+ - 有依赖的放后续阶段
143
+ - 每个 decision_point 后紧跟一个对抗决策阶段
144
+
145
+ **Step 3 — 对抗模式选择**
146
+
147
+ 根据 decision_point.type 和 --depth 选择对抗模式(参考 ADVERSARIAL_PATTERNS):
148
+
149
+ | decision_type | shallow | standard | deep |
150
+ |--------------|---------|----------|------|
151
+ | go-nogo | 1 skeptic | 3-way advocacy + referee | cross-verify + 3-way advocacy + meta-skeptic |
152
+ | pass-fail | 1 challenger | prosecutor/defender/judge | cross-verify + prosecutor/defender + 3-vote |
153
+ | select-best | 1 critic | N proposals + judge panel | N proposals + judge + 3-critic challenge |
154
+ | resolve-conflict | 1 mediator | 3 philosophy proposals + arbitrator | 3 proposals + arbitrator + meta-skeptic |
155
+ | assess-quality | 1 skeptic | 3-vote (strict/lenient/objective) | cross-verify + 3-vote + meta-skeptic |
156
+
157
+ **Step 4 — Schema 设计**
158
+
159
+ 为每个 agent 调用设计 JSON Schema:
160
+ - 工作 agent: 任务特定 schema
161
+ - 对抗 agent: 使用标准对抗 schema(见 ADVERSARIAL_PATTERNS)
162
+
163
+ **Step 5 — 产出蓝图**
164
+
165
+ ```
166
+ blueprint: {
167
+ name: 'uwf-{slug}',
168
+ description: string,
169
+ phases: [{ title, detail }],
170
+ agents: [{ id, prompt_outline, schema_name, agentType?, phase }],
171
+ adversarial_gates: [{ decision_id, pattern, agents[] }],
172
+ estimated_agent_count: number,
173
+ }
174
+ ```
175
+
176
+ 向用户展示蓝图摘要,包含预估 agent 数量。
177
+ 若 `--dry-run` 则在 S_GENERATE 后停止。
178
+
179
+ ### A_GENERATE_SCRIPT
180
+
181
+ 根据蓝图生成完整的 JavaScript 脚本。**先写文件,再通过 scriptPath 执行**(避免内联 script 字符串的编码/转义问题)。
182
+
183
+ `--from` 指定了基础脚本,先 Read 源脚本,然后在其基础上修改。
184
+
185
+ **脚本结构模板:**
186
+
187
+ ```javascript
188
+ export const meta = {
189
+ name: '{blueprint.name}',
190
+ description: '{English description}',
191
+ whenToUse: '{English usage scenario}',
192
+ phases: [
193
+ { title: '{EnglishTitle}', detail: '{English detail}' },
194
+ ],
195
+ }
196
+
197
+ // --- Schemas (top-level constants, never inline) ---
198
+ const WORK_SCHEMA = { type: 'object', properties: { ... }, required: [...] }
199
+ const CHALLENGE_SCHEMA = { ... }
200
+
201
+ // --- Args ---
202
+ const target = args?.target || 'default'
203
+
204
+ // --- Phase 1: {title} ---
205
+ phase('{title}')
206
+ const results = await parallel([
207
+ () => agent('prompt text', { label: 'work:1', phase: '{title}', schema: WORK_SCHEMA }),
208
+ ])
209
+
210
+ // --- Phase 2: Adversarial Gate ---
211
+ phase('{adversarial_phase_title}')
212
+ // 对抗模式代码 ADVERSARIAL_PATTERNS 模板生成
213
+
214
+ return { ... }
215
+ ```
216
+
217
+ **生成规则(必须全部遵守):**
218
+
219
+ | # | 规则 | 原因 |
220
+ |---|------|------|
221
+ | 1 | **纯 JavaScript** — 无 TypeScript 类型注解(`: string`、`interface`、泛型) | 解析器不支持 TS |
222
+ | 2 | **meta 块全英文** — `name`、`description`、`whenToUse`、`phases[].title/detail` 只用 ASCII 字符 | 中文在 script 字符串序列化时触发 `\uXXXX` 解析错误 |
223
+ | 3 | **禁用 API** 不用 `Date.now()`、`Math.random()`、无参 `new Date()` | 破坏 resume 缓存匹配 |
224
+ | 4 | **Schema 独立声明** — 所有 JSON Schema 在文件顶部声明为 `const XXX_SCHEMA = {...}`,agent 调用中用 `schema: XXX_SCHEMA` 引用 | 内联大 Schema 易出括号匹配错误 |
225
+ | 5 | **字符串用 `+` 拼接** agent prompt 中嵌入变量用 `'text ' + variable + ' more text'`,**不用模板字符串** | 反引号嵌套和 `${}` 转义是最常见的解析错误源 |
226
+ | 6 | **回调用 `function`** — `array.filter(function(x) { return x })` 而非箭头函数 | 箭头函数隐式返回对象 `() => ({})` 易遗漏外层括号 |
227
+ | 7 | **`phase` 不做变量名** — 不遮蔽全局 `phase()` 函数 | 遮蔽后 `phase('X')` 调用会崩溃 |
228
+ | 8 | **路径用正斜杠** — 字符串中路径用 `src/auth/` 不用 `src\\auth\\` | `\a`、`\u` 等被解析为转义序列 |
229
+ | 9 | **`agentType`** — 仅在有明确匹配时设置(如 `Explore`、`workflow-analyzer`) | 无效 agentType 导致运行时错误 |
230
+ | 10 | **null 安全** — 链式访问用 `?.`,数组操作前加 `.filter(Boolean)` | agent 返回 null(用户跳过)时链式调用崩溃 |
231
+
232
+ **常见错误对照:**
233
+
234
+ ```javascript
235
+ // BAD meta 中文导致 \uXXXX 解析错误
236
+ export const meta = { name: 'uwf-x', description: '参数审计' }
237
+ // GOOD
238
+ export const meta = { name: 'uwf-x', description: 'Parameter audit for unused/ambiguous/dead params' }
239
+
240
+ // BAD模板字符串嵌套
241
+ agent(`Analyze ${item.name} for ${reason}`)
242
+ // GOOD字符串拼接
243
+ agent('Analyze ' + item.name + ' for ' + reason)
244
+
245
+ // BAD — Schema 内联在 agent 调用中
246
+ agent('prompt', { schema: { type: 'object', properties: { a: { type: 'string' }, b: { type: 'array', items: { type: 'object', properties: { ... } } } } } })
247
+ // GOOD — Schema 顶部声明
248
+ const MY_SCHEMA = { type: 'object', properties: { a: { type: 'string' } }, required: ['a'] }
249
+ agent('prompt', { schema: MY_SCHEMA })
250
+
251
+ // BAD 箭头函数隐式返回对象
252
+ results.map(r => ({ ...r, verified: true }))
253
+ // GOODfunction + 显式 return
254
+ results.map(function(r) { return Object.assign({}, r, { verified: true }) })
255
+
256
+ // BAD 反斜杠路径
257
+ const path = 'C:\Users\project\src'
258
+ // GOOD
259
+ const path = 'C:/Users/project/src' // 或直接不在脚本中硬编码路径
260
+ ```
261
+
262
+ **Step 1 生成脚本内容**
263
+
264
+ 按蓝图结构 + 上述规则生成完整 JavaScript 字符串。agent prompt 内部可以使用中文(prompt 是运行时字符串,不影响解析)。
265
+
266
+ **Step 2写入文件**
267
+
268
+ ```
269
+ write_file({
270
+ file_path: expandPath('~/.maestro/workflows/dynamic/uwf-{slug}.js'),
271
+ content: generatedScript
272
+ })
273
+ ```
274
+
275
+ **Step 3语法验证**
276
+
277
+ ```
278
+ shell({ command: 'node --check "path/to/uwf-{slug}.js"' })
279
+ ```
280
+
281
+ 若验证失败:
282
+ 1. 读取错误信息中的行号和错误类型
283
+ 2. 针对性修复(常见:遗漏逗号、括号不匹配、保留字冲突)
284
+ 3. 重新 Write + 验证(最多重试 2 次)
285
+ 4. 仍失败则报 E003,展示脚本内容和错误信息
286
+
287
+ 验证通过后进入 S_EXECUTE(若非 `--dry-run`)。
288
+
289
+ ### A_EXECUTE_WORKFLOW
290
+
291
+ **必须用 scriptPath 调用**(不用 script 内联字符串):
292
+
293
+ ```
294
+ Workflow({
295
+ scriptPath: expandPath('~/.maestro/workflows/dynamic/uwf-{slug}.js'),
296
+ args: taskSpecificArgs, // 从 intent 推断
297
+ resumeFromRunId: resumeId // 若有
298
+ })
299
+ ```
300
+
301
+ 记录返回的 `runId`。脚本已在 A_GENERATE_SCRIPT 中写入文件,无需再次持久化。
302
+
303
+ ### A_PERSIST_SCRIPT
304
+
305
+ 脚本已在 A_GENERATE_SCRIPT Step 2 写入 `~/.maestro/workflows/dynamic/uwf-{slug}.js`。
306
+
307
+ 1. 确认文件存在(Glob 检查)
308
+ 2. 展示保存路径和使用方式:
309
+ ```
310
+ Saved: ~/.maestro/workflows/dynamic/uwf-{slug}.js
311
+ Reuse: /maestro-universal-workflow --from uwf-{slug} "{new intent}"
312
+ Resume: /maestro-universal-workflow --resume {runId}
313
+ Via swarm: /maestro-swarm-workflow --script uwf-{slug}
314
+ ```
315
+
316
+ </actions>
317
+
318
+ </state_machine>
319
+
320
+ <adversarial_patterns>
321
+
322
+ 以下是对抗决策模式的代码模板库。A_GENERATE_SCRIPT 时按 decision_type 和 depth 选用。
323
+
324
+ ### PATTERN: Skeptic CrossVerify (shallow+)
325
+
326
+ 用于:对并行分析结果逐项挑战。
327
+
328
+ ```javascript
329
+ // 每个结果被 skeptic 挑战
330
+ const challenges = await pipeline(
331
+ results,
332
+ (result) => agent(
333
+ `You are an adversarial SKEPTIC. Challenge this assessment.
334
+ Original: ${JSON.stringify(result)}
335
+ Your job: find counter-evidence, check for biases, verify claims against actual code.
336
+ Default to challenge_result="weakened" if uncertain.`,
337
+ { label: `challenge:${result.id}`, phase: '{phase}', schema: CHALLENGE_SCHEMA }
338
+ )
339
+ )
340
+ ```
341
+
342
+ CHALLENGE_SCHEMA:
343
+ ```javascript
344
+ const CHALLENGE_SCHEMA = {
345
+ type: 'object',
346
+ properties: {
347
+ target: { type: 'string' },
348
+ challenge_result: { type: 'string', enum: ['confirmed', 'weakened', 'overturned'] },
349
+ adjusted_assessment: { type: 'string' },
350
+ counter_evidence: { type: 'array', items: { type: 'string' } },
351
+ confidence: { type: 'number', minimum: 0, maximum: 100 },
352
+ reasoning: { type: 'string' },
353
+ },
354
+ required: ['target', 'challenge_result', 'confidence', 'reasoning'],
355
+ }
356
+ ```
357
+
358
+ ### PATTERN: 3-Way Advocacy + Referee (standard+ go-nogo)
359
+
360
+ 用于:go/no-go 类决策。
361
+
362
+ ```javascript
363
+ const advocacies = await parallel([
364
+ () => agent('You are the GO ADVOCATE. Argue FOR proceeding...', { label: 'advocate:go', schema: ADVOCACY_SCHEMA }),
365
+ () => agent('You are the NO-GO ADVOCATE. Argue AGAINST proceeding...', { label: 'advocate:nogo', schema: ADVOCACY_SCHEMA }),
366
+ () => agent('You are the CONDITIONAL ADVOCATE. Argue for proceeding ONLY under conditions...', { label: 'advocate:conditional', schema: ADVOCACY_SCHEMA }),
367
+ ])
368
+ const decision = await agent('You are the REFEREE. Resolve the debate...', { label: 'referee', schema: DECISION_SCHEMA })
369
+ ```
370
+
371
+ ADVOCACY_SCHEMA:
372
+ ```javascript
373
+ const ADVOCACY_SCHEMA = {
374
+ type: 'object',
375
+ properties: {
376
+ stance: { type: 'string' },
377
+ argument: { type: 'string' },
378
+ key_evidence: { type: 'array', items: { type: 'object', properties: { point: { type: 'string' }, strength: { type: 'string', enum: ['strong', 'moderate', 'weak'] } }, required: ['point'] } },
379
+ weaknesses_acknowledged: { type: 'array', items: { type: 'string' } },
380
+ conditions: { type: 'array', items: { type: 'string' } },
381
+ confidence: { type: 'number', minimum: 0, maximum: 100 },
382
+ },
383
+ required: ['stance', 'argument', 'confidence'],
384
+ }
385
+ ```
386
+
387
+ ### PATTERN: Prosecutor/Defender/Judge (standard+ pass-fail)
388
+
389
+ 用于:通过/失败类判定。
390
+
391
+ ```javascript
392
+ const debate = await parallel([
393
+ () => agent('You are the PROSECUTOR. Argue this should FAIL...', { label: 'prosecutor', schema: ARGUMENT_SCHEMA }),
394
+ () => agent('You are the DEFENDER. Argue this should PASS...', { label: 'defender', schema: ARGUMENT_SCHEMA }),
395
+ ])
396
+ const verdict = await agent('You are the JUDGE. Resolve the debate...', { label: 'judge', schema: VERDICT_SCHEMA })
397
+ ```
398
+
399
+ ARGUMENT_SCHEMA:
400
+ ```javascript
401
+ const ARGUMENT_SCHEMA = {
402
+ type: 'object',
403
+ properties: {
404
+ role: { type: 'string' },
405
+ stance: { type: 'string', enum: ['pass', 'fail'] },
406
+ argument: { type: 'string' },
407
+ key_points: { type: 'array', items: { type: 'object', properties: { point: { type: 'string' }, evidence: { type: 'string' }, strength: { type: 'string', enum: ['strong', 'moderate', 'weak'] } }, required: ['point', 'evidence'] } },
408
+ concessions: { type: 'array', items: { type: 'string' } },
409
+ confidence: { type: 'number', minimum: 0, maximum: 100 },
410
+ },
411
+ required: ['role', 'stance', 'argument', 'key_points', 'confidence'],
412
+ }
413
+ ```
414
+
415
+ ### PATTERN: 3-Vote Majority (standard+ assess-quality)
416
+
417
+ 用于:质量评估、状态判定。
418
+
419
+ ```javascript
420
+ const votes = await parallel([
421
+ () => agent('You are the STRICT voter...', { label: 'vote:strict', schema: VOTE_SCHEMA }),
422
+ () => agent('You are the LENIENT voter...', { label: 'vote:lenient', schema: VOTE_SCHEMA }),
423
+ () => agent('You are the OBJECTIVE voter...', { label: 'vote:objective', schema: VOTE_SCHEMA }),
424
+ ])
425
+ const majority = resolveVotes(votes) // majority wins, tie → objective
426
+ const report = await agent('Arbitrate final report from votes...', { label: 'arbitrate', schema: REPORT_SCHEMA })
427
+ ```
428
+
429
+ VOTE_SCHEMA:
430
+ ```javascript
431
+ const VOTE_SCHEMA = {
432
+ type: 'object',
433
+ properties: {
434
+ perspective: { type: 'string' },
435
+ verdict: { type: 'string' },
436
+ rationale: { type: 'string' },
437
+ confidence: { type: 'number', minimum: 0, maximum: 100 },
438
+ },
439
+ required: ['perspective', 'verdict', 'rationale', 'confidence'],
440
+ }
441
+ ```
442
+
443
+ ### PATTERN: Competing Proposals + Judge (standard+ select-best)
444
+
445
+ 用于:方案选择。
446
+
447
+ ```javascript
448
+ const proposals = await parallel([
449
+ () => agent('Strategy A: ...', { label: 'proposal:A', schema: PROPOSAL_SCHEMA }),
450
+ () => agent('Strategy B: ...', { label: 'proposal:B', schema: PROPOSAL_SCHEMA }),
451
+ () => agent('Strategy C: ...', { label: 'proposal:C', schema: PROPOSAL_SCHEMA }),
452
+ ])
453
+ const scores = await parallel(proposals.filter(Boolean).map(p => () =>
454
+ agent(`Score this proposal: ${p.strategy}...`, { label: `judge:${p.strategy}`, schema: SCORE_SCHEMA })
455
+ ))
456
+ // select highest score
457
+ ```
458
+
459
+ ### PATTERN: Meta-Skeptic (deep only)
460
+
461
+ 用于:挑战挑战者本身的发现。
462
+
463
+ ```javascript
464
+ const metaChallenge = await agent(
465
+ `You are the META-SKEPTIC. Challenge the challengers themselves.
466
+ Findings: ${digest}
467
+ 1. Which findings are OVERBLOWN? (theatrical, unlikely, missing context)
468
+ 2. What did they MISS? (blind spots, interactions, real risks obscured)
469
+ 3. Rate overall challenge quality (1-5).`,
470
+ { label: 'meta-skeptic', schema: META_CHALLENGE_SCHEMA }
471
+ )
472
+ ```
473
+
474
+ </adversarial_patterns>
475
+
476
+ <invariants>
477
+ 1. **先查后建** 必须先扫描现有库,避免重复生成相同功能的脚本
478
+ 2. **对抗必选** 每个 decision_point 必须有对应的对抗模式,不允许单 agent 决策
479
+ 3. **depth 递进** — shallow ⊂ standard ⊂ deep,高 depth 包含低 depth 的所有模式
480
+ 4. **纯 JS** 生成的脚本必须是纯 JavaScript,不含 TypeScript 类型注解
481
+ 5. **meta 全英文** meta 块中 name/description/whenToUse/phases 只用 ASCII 字符(agent prompt 内可用中文)
482
+ 6. **Schema 完整** 每个 agent 调用必须有 schema,且 Schema 在文件顶部声明为独立常量
483
+ 7. **先写后跑** 脚本必须先 Write 到文件 → `node --check` 验证 → 再通过 `scriptPath` 执行(禁止内联 script 字符串)
484
+ 8. **幂等命名** — 同名脚本覆盖(uwf-{slug}.js),用户可通过 --name 控制
485
+ 9. **禁用 API** — 脚本内不使用 Date.now()、Math.random()、无参 new Date()
486
+ 10. **变量安全** — 不使用 `phase` 作为变量名(避免遮蔽 phase() 函数)
487
+ 11. **无模板字符串** — agent prompt 用 `+` 拼接,不用反引号模板(避免嵌套转义错误)
488
+ 12. **无反斜杠路径** — 字符串中路径用正斜杠(`\u`、`\a` 等会被解析为转义序列)
489
+ </invariants>
490
+
491
+ <appendix>
492
+
493
+ ### 使用示例
494
+
495
+ ```bash
496
+ # 自动匹配或生成
497
+ /maestro-universal-workflow "评估数据库迁移方案的可行性和风险"
498
+
499
+ # 指定深度
500
+ /maestro-universal-workflow "审查 auth 模块的安全性" --depth deep
501
+
502
+ # 只生成不执行
503
+ /maestro-universal-workflow "对比 3 种缓存策略" --dry-run --name cache-eval
504
+
505
+ # 基于已有脚本修改
506
+ /maestro-universal-workflow "类似 analyze 但加入成本维度" --from wf-analyze
507
+
508
+ # 恢复之前的运行
509
+ /maestro-universal-workflow --resume wf_abc123
510
+ ```
511
+
512
+ ### 生成脚本示例
513
+
514
+ 用户 intent: "评估 3 种 API 认证方案(JWT/OAuth2/API Key),选出最优"
515
+
516
+ 生成的脚本结构:
517
+ ```
518
+ Phase 1: Explore — 探索代码库现有认证实现
519
+ Phase 2: Evaluate 3 个 agent 分别深入评估每种方案
520
+ Phase 3: CrossVerify — skeptic 挑战每个评估结果
521
+ Phase 4: Compete — 3 个 advocate 各持一种方案立场辩论
522
+ Phase 5: Arbitrate — referee 根据辩论结果选出最优方案
523
+ ```
524
+
525
+ 预估 agent 数: 1(explore) + 3(evaluate) + 3(cross-verify) + 3(advocates) + 1(referee) = 11
526
+
527
+ ### swarm-workflow 的关系
528
+
529
+ | 维度 | swarm-workflow | universal-workflow |
530
+ |------|---------------|-------------------|
531
+ | 脚本来源 | 固定 8 个预写脚本 | 动态生成 + 积累库 |
532
+ | 适用范围 | 对应 8maestro 命令 | 任意任务 |
533
+ | 决策模式 | 脚本内硬编码 | 按 depth 动态选择 |
534
+ | 持久化 | 不生成新脚本 | 保存到 dynamic/ 复用 |
535
+ | 推荐场景 | 已有匹配的标准命令 | 非标准任务、新领域 |
536
+
537
+ universal-workflow 扫描时会同时检查 swarm/ 和 dynamic/ 目录,
538
+ swarm 脚本匹配度高则推荐使用 swarm-workflow 代替。
539
+
540
+ ### Error Codes
541
+
542
+ | Code | Description | Recovery |
543
+ |------|-------------|----------|
544
+ | E001 | intent | 提示用户输入 |
545
+ | E002 | 设计阶段无法分解任务 | 要求更具体的 intent |
546
+ | E003 | 生成的脚本语法错误 | `node --check` 失败时:读取行号+错误类型 → 针对性修复 → 重试(最多 2 次)→ 仍失败则展示脚本+错误让用户手动修改 |
547
+ | E004 | Workflow 执行失败 | 展示错误,提供 --resume |
548
+ | E005 | 持久化失败 | 展示脚本内容,让用户手动保存 |
549
+
550
+ </appendix>