Skip to main content
ClaudeWave
Slash Command475 repo starsupdated 2d ago

maestro-swarm-workflow

Parallel workflow accelerator — route intent to fixed Workflow scripts for multi-agent concurrent execution

Install in Claude Code
Copy
mkdir -p ~/.claude/commands && curl -fsSL https://raw.githubusercontent.com/catlog22/maestro-flow/HEAD/.claude/commands/maestro-swarm-workflow.md -o ~/.claude/commands/maestro-swarm-workflow.md
Then start a new Claude Code session; the slash command loads automatically.

maestro-swarm-workflow.md

<purpose>
Parallel accelerator: route intent to pre-built Workflow scripts (`wf-*.js`) for multi-agent
concurrent execution with adversarial decision patterns. Complements ralph's sequential chain.
</purpose>

<context>
$ARGUMENTS — intent text with optional flags.

**Parse:**
```
--script <name>  → 强制指定脚本(wf-analyze, wf-brainstorm, wf-review, wf-verify)
--dims <d1,d2>   → 限定分析维度(analyze: architecture,complexity,patterns,risk,testability,performance)
--roles <r1,r2>  → 限定角色(brainstorm: system-architect,product-manager,test-strategist,ux-expert,security-analyst,data-architect)
--count N        → 角色数量(brainstorm 默认 3)
--tier <level>   → review 层级(quick=2 维度, standard=4 维度)
--resume <runId> → 从之前的 workflow 运行恢复(增量重跑)
Remaining        → intent
```

**Script inventory** (`~/.maestro/workflows/swarm/`):

| Script | args 接口 |
|--------|-----------|
| `wf-analyze` | `{ target, scope, context, phase?, dimensions? }` |
| `wf-brainstorm` | `{ topic, context, count?, roles? }` |
| `wf-review` | `{ target, scope, specs?, tier?, dimensions? }` |
| `wf-verify` | `{ goals, plan_dir?, scope?, task_files?, must_haves?, skip_antipattern? }` |
| `wf-grill` | `{ topic, context?, depth?: "shallow"\|"standard"\|"deep" }` |
| `wf-plan` | `{ context_dir?, from?, phase?, scope?, specs?, gaps?, quick? }` |
| `wf-execute` | `{ plan_dir, specs?, codebase_context?, wiki_context?, auto_commit? }` |
| `wf-milestone-audit` | `{ milestone?, is_adhoc? }` |
</context>

<state_machine>

<states>
S_PARSE        — 解析参数和意图                    PERSIST: —
S_ROUTE        — 路由到目标脚本                    PERSIST: —
S_CONTEXT      — 组装 context payload             PERSIST: —
S_DISPATCH     — 调用 Workflow 工具                PERSIST: —
S_INGEST       — 处理返回结果                      PERSIST: —
S_FALLBACK     — 无法路由                         PERSIST: —
</states>

<transitions>

S_PARSE:
  → S_ROUTE     WHEN: intent parsed                DO: A_PARSE_ARGS
  → S_FALLBACK  WHEN: no intent

S_ROUTE:
  → S_CONTEXT   WHEN: script resolved              DO: A_ROUTE_SCRIPT
  → S_FALLBACK  WHEN: ambiguous intent              DO: AskUserQuestion

S_CONTEXT:
  → S_DISPATCH  DO: A_ASSEMBLE_CONTEXT

S_DISPATCH:
  → S_INGEST    WHEN: workflow completed            DO: A_DISPATCH_WORKFLOW
  → S_FALLBACK  WHEN: workflow failed

S_INGEST:
  → END         DO: A_INGEST_RESULTS

S_FALLBACK:
  → S_PARSE     WHEN: user provides input
  → END         WHEN: user cancels

</transitions>

<actions>

### A_PARSE_ARGS

1. 提取 flags(--script, --dims, --roles, --count, --tier, --resume)
2. 剩余文本作为 intent
3. 若有 --resume,记录 resumeRunId

### A_ROUTE_SCRIPT

Intent-to-script routing(按关键词匹配,--script 优先级最高):

| Keywords | Script |
|----------|--------|
| 分析 / analyze / 探索 / explore / 架构 / architecture / 复杂度 / 风险 | `wf-analyze` |
| 头脑风暴 / brainstorm / 方案 / 设计 / 评估 / evaluate / 多角度 | `wf-brainstorm` |
| 审查 / review / 代码审查 / code review / 质量 / quality | `wf-review` |
| 验证 / verify / 检查 / check / 反模式 / antipattern | `wf-verify` |
| 拷问 / grill / 压力测试 / stress-test / 挑战 / challenge | `wf-grill` |
| 规划 / plan / 任务分解 / decompose / 分波 / wave | `wf-plan` |
| 执行 / execute / 实现 / implement / 开发 / develop | `wf-execute` |
| 里程碑审计 / milestone-audit / 集成检查 / integration | `wf-milestone-audit` |

多命中 → AskUserQuestion 让用户选择。

### A_ASSEMBLE_CONTEXT

根据目标脚本组装 args payload:

**wf-analyze:**
1. Read `.workflow/state.json` 获取当前 phase/milestone 信息
2. `target` = intent 中的目标描述
3. `scope` = 从 intent 推断文件范围,或读 roadmap 获取 phase scope
4. `context` = 拼接相关上下文(上游 artifact 摘要、specs)
5. `dimensions` = --dims 解析结果(可选)

**wf-brainstorm:**
1. `topic` = intent 文本
2. `context` = 读取相关代码文件摘要 + 已有 specs
3. `count` = --count 或默认 3
4. `roles` = --roles 解析结果(可选)

**wf-review:**
1. `target` = 读 git diff 描述变更范围
2. `scope` = 变更文件列表
3. `tier` = --tier 或 "standard"
4. `dimensions` = --dims 解析结果(可选)

**wf-verify:**
1. `goals` = 读最近的 plan artifact 提取目标列表
2. `plan_dir` = 定位最近的 plan scratch 目录
3. `scope` = plan 涉及的文件范围
4. `skip_tests` / `skip_antipattern` = 从 flags 提取

### A_DISPATCH_WORKFLOW

1. 确定 scriptPath = `~/.maestro/workflows/swarm/{script}.js`(展开为绝对路径)
2. 构建 Workflow 调用:
   ```
   Workflow({
     scriptPath: absoluteScriptPath,
     args: assembledArgs,
     resumeFromRunId: resumeRunId  // 若有
   })
   ```
3. 等待 Workflow 返回结果
4. 记录 runId 用于潜在的后续 resume

### A_INGEST_RESULTS

Workflow 返回 JSON 后:

1. **摘要输出**:按脚本类型格式化关键指标(含对抗决策结果)
   - analyze: overall_score, scope_verdict, adversarial_outcome (go/no-go/conditional advocacy + referee), scores_challenged count
   - brainstorm: role count, conflict/synergy count, 3-proposal competition result, arbitration notes
   - review: verdict (APPROVE/REQUEST_CHANGES/BLOCK), 3-vote tally, confirmed vs false-positive count, adversarial_verdict
   - verify: overall_status, prosecutor vs defender confidence, adversarial_outcome, gap count
   - grill: overall_verdict, meta-skeptic quality rating, 3-vote verdict tally, overblown findings count
   - plan: selected_strategy (breadth/depth/risk), judge panel scores, 3-critic adversarial check verdict
   - execute: 3-vote status (DONE/DONE_WITH_CONCERNS/NEEDS_RETRY), convergence trust %, discrepancy count
   - milestone-audit: 3-vote verdict, dimensions_overturned count, next_step

2. **Artifact 写入**(可选):
   - 若当前在 ralph session 中(检测 `.workflow/.maestro/ralph-*/status.json` 状态为 running):
     将结果写入对应 step 的 scratch 目录,格式兼容命令产出
   - 否则写入 `.workflow/scratch/{YYYYMMDD}-swarm-{script}-{slug}/results.json`

3. **Ralph 兼容产出**:
   - analyze → `analysis.md` + `context.md`(decisions)+ `conclusions.json` + `adversarial-debate.json`
   - brainstorm → `guidance-specification.md` + `proposals-competition.json`
   - review → `review.json`(含 adversarial_verdict + 3-vote tally)
   - verify → `verification.json`(含 adversarial_outcome: prosecutor/defender debate)
   - grill → `grill-results.json`(含 meta-challenge + 3-vote verdict)
   - plan → `plan.json`(含 competition scores + critic feedback)
   - execute → `execution-report.json`(含 convergence_checks + 3-vote status)