maestro-flow 0.4.20 → 0.4.21

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