Orchestrate multi-stage agent pipelines with dependency management {project-root}/_bmad/core/pipeline/pipeline-config.yaml {project-root}/_bmad-output/pipelines Ask user for pipeline source: 1. Use template (show available templates) 2. Define custom pipeline List templates from config: full_sdlc, quick_flow, analysis_only, design_review, test_suite User selects template Copy template stages to new pipeline definition Ask for pipeline name Ask for stages (agent, parallel, depends_on, outputs) Build pipeline definition Sanitize {name} to {sanitized_name}: - Convert to lowercase - Replace spaces and special chars with hyphens - Remove any chars not in [a-z0-9-_] - Collapse multiple hyphens to single hyphen - Trim leading/trailing hyphens HALT with error: "Pipeline name is required and must contain at least one alphanumeric character" Generate pipeline_id: "PIPE-{YYYYMMDD}-{sanitized_name}-{HHmmss}" Create pipeline file at {pipeline_dir}/{pipeline_id}.yaml: - MUST fail if file already exists (no overwrite) - Use exclusive create mode (O_CREAT | O_EXCL or equivalent) Retry with new timestamp or append random 4-char suffix Initialize all stages as "pending" Pipeline created: {pipeline_id} Stages: {stage_count} Estimated duration: {estimate} Run with: PIPELINE run {pipeline_id} Validate {pipeline_id} format: - Must match pattern: PIPE-[0-9]{8}-[a-z0-9_-]+-[0-9]{6} - Must not contain path separators (/, \, ..) - Must not be empty HALT with error: "Invalid pipeline_id format" Load pipeline from {pipeline_dir}/{pipeline_id}.yaml Validate pipeline definition (agents exist, dependencies valid) Default error_handling to "halt" if not set in pipeline definition Set pipeline status to "running" Initialize execution state tracking (track has_failures flag = false) Find stages where: - Status == "pending" AND - All depends_on stages are "completed" Collect names of all stages still in "pending" status Mark pipeline status as "failed" Update pipeline file with failed state HALT with error: "Deadlock detected (cycle or unmet dependencies). Pending stages: {pending_stage_names}" Mark found stages as "queued" Launch agents in parallel using Task tool with run_in_background=true Track agent_ids for each stage Launch agent using Task tool with run_in_background=false Wait for completion For parallel stages: Use TaskOutput to collect results Update stage status based on result (completed/failed) Store outputs in {pipeline_dir}/outputs/{stage_name}/ Set has_failures = true Mark pipeline as "failed" Mark dependent stages as "skipped" Update pipeline file with failed state HALT: "Pipeline failed at stage: {stage_name}" Set has_failures = true Mark dependent stages as "skipped" Continue with non-dependent stages Update pipeline file with current state Mark pipeline as "completed_with_failures" Mark pipeline as "completed" Update pipeline file with final state Pipeline {final_status}: {pipeline_id} Results: {for each stage} - {stage_name}: {status} ({duration}) {end for} {if has_failures} Warning: Pipeline completed with failures in some stages. {end if} Outputs saved to: {pipeline_dir}/outputs/ Validate {pipeline_id} format: - Must match pattern: PIPE-[0-9]{8}-[a-z0-9_-]+-[0-9]{6} - Must not contain path separators (/, \, ..) HALT with error: "Invalid pipeline_id format" Load pipeline from {pipeline_dir}/{pipeline_id}.yaml (or active-pipeline.yaml if no id) Calculate progress percentage Pipeline: {pipeline_id} Status: {overall_status} Progress: [{progress_bar}] {percentage}% Stages: {for each stage} [{status_icon}] {stage_name} Agents: {agents} Duration: {duration or "pending"} Output: {output_path or "n/a"} {end for} {if running} Currently executing: {current_stage} Estimated remaining: {remaining_estimate} {end if} Scan {pipeline_dir} for pipeline files Load templates from config Available Templates: {for each template} - {template_name}: {description} Stages: {stage_names} {end for} Existing Pipelines: {for each pipeline} - {pipeline_id}: {status} ({created_date}) {end for} Validate {pipeline_id} format: - Must match pattern: PIPE-[0-9]{8}-[a-z0-9_-]+-[0-9]{6} - Must not contain path separators (/, \, ..) HALT with error: "Invalid pipeline_id format" Load running pipeline from {pipeline_dir}/{pipeline_id}.yaml (or active-pipeline.yaml) Send abort signal to running agents Mark running stages as "aborted" Mark pipeline as "aborted" Pipeline {pipeline_id} aborted. Completed stages: {completed_count} Aborted stages: {aborted_count} Validate {pipeline_id} format: - Must match pattern: PIPE-[0-9]{8}-[a-z0-9_-]+-[0-9]{6} - Must not contain path separators (/, \, ..) HALT with error: "Invalid pipeline_id format" Load failed/aborted pipeline from {pipeline_dir}/{pipeline_id}.yaml Identify failed/aborted stages Ask user: Retry failed stages or skip? Reset failed stages to "pending" Continue with run logic Mark failed stages as "skipped" Continue with remaining stages