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