maestro-ralph
Use when the optimal command sequence is unclear and needs automated state-based determination
mkdir -p ~/.claude/commands && curl -fsSL https://raw.githubusercontent.com/catlog22/maestro-flow/HEAD/.claude/commands/maestro-ralph.md -o ~/.claude/commands/maestro-ralph.mdmaestro-ralph.md
<purpose>
Closed-loop decision engine: read project state → infer position → build adaptive chain → delegate execution.
Ralph builds/evaluates; ralph-execute runs steps. Session: `.workflow/.maestro/ralph-{YYYYMMDD-HHmmss}/status.json`.
</purpose>
<deferred_reading>
- [ralph-amend-goal.md](~/.maestro/workflows/ralph-amend-goal.md) — read when `--amend` flag active for goal amendment flow
</deferred_reading>
<context>
$ARGUMENTS — intent text, flags, or keywords.
**Parse:**
```
-y flag → auto_confirm = true # 唯一来源:用户显式传入;ralph 不内部推断(invariant 14)
--roadmap → wants_roadmap = true (强制多发布 roadmap 路径;roadmap 默认 opt-in)
--amend / -a → amend_mode = true (running session 存在时触发目标修改流程)
.md/.txt path → input_doc (supplementary context only, NEVER substitutes lifecycle stages)
Remaining → intent (amend_mode 时为 change_request)
```
**State files:**
- `.workflow/state.json` — artifact registry, milestones, phases
- `.workflow/roadmap.md` — milestone/phase structure
- `.workflow/.maestro/ralph-*/status.json` — ralph session state
</context>
<invariants>
1. **Ralph never executes steps** — only creates sessions and evaluates decisions
2. **Handoff via Skill("maestro-ralph-execute")** — 创建 session 后始终自动 handoff;decision 评估后始终 handoff
3. **Decision delegates read-only** — `maestro delegate --role analyze --mode analysis`
4. **执行 step 通过 `maestro ralph next` CLI 加载并内联执行**(详见 invariant 8)
5. **status.json 是唯一真源** — 不生成 markdown 清单或侧文件
6. **每个 step 必须 `completion_confirmed: true`** — 由 `maestro ralph complete N --status DONE`(或 DONE_WITH_CONCERNS)写入;CLI 是唯一合法写入路径
7. **command_path 在 A_BUILD_STEPS 解析** — 通过 `maestro ralph skills --platform claude --json --quiet` 预校验(project 覆盖 global,限定 `.claude/commands/` + `.claude/skills/`),命中即写绝对路径到 status.json;未命中标 `command_scope = "missing"`
8. **执行 step 加载契约** — 由 `maestro ralph next` CLI 在执行期完成:解析 frontmatter + `<required_reading>` + `<deferred_reading>`,自动读取 required 文件全文并拼入 prompt;缺失 required → 退出码 1(E007),pause session。ralph build 阶段只通过 `maestro ralph skills --platform claude` 校验路径存在性,不读 .md 内容
9. **Decomposition is outcome-oriented** — sub-goals 为可观测交付,禁止 lifecycle 复刻;`/goal` 用户绑定,ralph 输出提示词后继续 handoff,用户可在执行过程中随时输入 `/goal`
10. **planning_mode governs arg granularity** — `unified` → skill args 无 `{phase}`;`independent` → 含 `{phase}`
11. **task_decomposition 驱动 steps[] 动态生长** — `post-goal-audit` 按 unmet 子目标插入 scoped mini-loop;字段可选/累加,既有字段不删不改
12. **Invariant violation = BLOCK** — 违反上述任一 invariant 即阻断当前操作。不得以 "效率" 或 "意图明确" 为由绕过。特别是 invariant 1(ralph 不执行 step)和 invariant 6(completion_confirmed 由 CLI 写入)不可隐性违反。
13. **Delegate fallback 必须标记** — A_DELEGATE_EVALUATE 解析 verdict 失败时 fallback 为 "fix",但 MUST 在 decisions.ndjson 记录 `"parse_failed": true, "confidence_score": 0`,后续 step 继承 LOW CONFIDENCE 标记。
14. **auto_confirm 单一来源** — `auto_confirm` 仅由用户 `-y` 标志设定;ralph 不得内部推断。`session.auto_mode` 仅反映用户输入。
15. **分解契约单一所有者** — `boundary_contract` / `task_decomposition` 由 session 创建者拥有(`source=="ralph"` → `decomposition_owner="ralph"`;`source=="maestro"` → `"maestro"`)。contract 已存在时,后续 S_DECOMPOSE MUST 跳过 AskUserQuestion,仅做 shape 校验 + 缺省补齐;goal-audit 只更新 `task_decomposition[*].status/completion_confirmed/completed_at`,禁止改 `goal/done_when/boundary`。
16. **控制权优先级(范式治理)** — FSM 独占 session 生命周期 + step 排序 + retry/fix/escalate + cross-step decision 节点;Pipeline 命令只拥有自身 artifact GATE(GATE 失败 → `maestro ralph complete <idx> --status BLOCKED|NEEDS_RETRY`,自身 GATE 全过 → DONE);Router 命令不得出现在 FSM step 内。
</invariants>
<state_machine>
<states>
S_PARSE_ROUTE — 解析参数、路由入口 PERSIST: —
S_STATUS — 显示 session 进度 PERSIST: —
S_CONTINUE — 恢复执行 PERSIST: —
S_RESOLVE_PHASE — 解析 phase + phase_is_new + D-007 milestone PERSIST: session.phase, session.phase_is_new, session.milestone
S_INFER — 基于已解析 phase 推断 lifecycle_position PERSIST: session.lifecycle_position, session.wants_roadmap
S_RESOLVE_SCOPE — 读 macro analyze conclusions.scope_verdict PERSIST: session.scope_verdict, session.analyze_macro_id
S_QUALITY_MODE — 决定质量管线模式 PERSIST: session.quality_mode
S_PLANNING_MODE — 决定统一/独立规划模式 PERSIST: session.planning_mode
S_DECOMPOSE — 边界澄清、写执行准则+子目标清单 PERSIST: session.boundary_contract, .execution_criteria, .task_decomposition
S_BUILD_CHAIN — 构建步骤链 PERSIST: session.steps[]
S_CREATE_SESSION — 写 status.json PERSIST: session (全量)
S_CONFIRM — 用户确认 PERSIST: —
S_DISPATCH — 移交 maestro-ralph-execute PERSIST: —
S_DECISION_EVAL — 委托评估质量门 PERSIST: —
S_APPLY_VERDICT — 应用裁决 + 插入命令 PERSIST: session.steps[], session.passed_gates[]
S_AMEND_GOAL — 修改 running session 目标 PERSIST: session.task_decomposition, .boundary_contract, .goal_changelog, .steps[]
S_FALLBACK — 请求用户输入 PERSIST: —
</states>
<transitions>
S_PARSE_ROUTE:
→ S_STATUS WHEN: intent == "status"
→ S_CONTINUE WHEN: intent == "continue"
→ S_AMEND_GOAL WHEN: amend_mode == true AND running session exists
→ S_FALLBACK WHEN: amend_mode == true AND no running session DO: Display: "无运行中的 ralph 会话,--amend 需要活跃 session"
→ S_DECISION_EVAL WHEN: running session with decision step in "running" status
→ S_RESOLVE_PHASE WHEN: intent is non-empty ← phase 必须先于 position
→ S_FALLBACK WHEN: no intent AND no running session
S_STATUS:
→ END DO: A_SHOW_STATUS
S_CONTINUE:
→ S_DISPATCH WHEN: running session found
→ S_FALLBACK WHEN: no running session DO: display "无运行中的 ralph 会话"
S_RESOLVE_PHASE:
→ S_INFER WHEN: phase resolved or null DO: A_RESOLVE_PHASE
→ S_FALLBACK WHEN: ambiguous
GUARD: auto_confirm does NOT skip phase ambiguity
S_INFER:
→ S_RESOLVE_SCOPE WHEN: position resolvedRead-only code exploration via Bash + CLI semantic dual-source analysis, with schema-validated structured output.
Compares Decision Digests across role analysis files in a brainstorm session to surface conflicts, gaps, and synergies. Read-only — returns structured text for the orchestrator to apply.
Autonomous executor for non-interactive impeccable commands. Runs audit, polish, harden, layout, typeset, and other automatable design operations without user interaction.
Generates multi-file role analysis for a brainstorm session — analysis.md index + per-feature files + optional findings under {output_dir}/{role}/.
Resident pipeline supervisor agent. Message-driven lifecycle for cross-checkpoint quality observation and health monitoring.
Unified worker agent for team pipelines. Executes role-specific logic loaded from a role_spec file within a built-in task lifecycle (discover, execute, report).
UI design token management and prototype generation — W3C Design Tokens Format, state-based components, WCAG AA validation, responsive layout templates.
Evaluates technical topics, proposals, or decisions across multiple dimensions with evidence-based scoring and recommendations.