# Workflow Chain Patterns ## Command Chaining & Orchestration ```yaml Chain Types: Sequential: A→B→C (linear progression) Parallel: A&B&C (concurrent execution) Conditional: A&&B||C (success/failure paths) Loop: A→B→(condition)→A (iterative workflows) Context Propagation: Analysis Results: analyze→build|design|improve (use findings) Design Patterns: design→build|document (apply arch) Test Results: test→improve|deploy (use coverage/results) Error Context: troubleshoot→improve|fix (use root cause) ``` ## Predefined Workflow Chains ```yaml Dev Workflows: New Feature: Chain: load→analyze→design→build→test→scan→deploy Flags: --think for analysis, --magic for UI, --pup for E2E Context: Each step uses previous outputs Bug Fix: Chain: troubleshoot --investigate → troubleshoot --fix → test → commit Flags: --think-hard for complex bugs, --seq for root cause Context: Investigation findings guide fix implementation Code Review: Chain: analyze --code → improve --quality → scan --validate → test Flags: --think for comprehensive review Context: Analysis results guide improvements Quality Workflows: Performance Optimization: Chain: analyze --profile → improve --performance → test → measure Flags: --iterate --threshold 90% for continuous improvement Context: Profile results guide optimization targets Security Hardening: Chain: scan --security → improve --quality → scan --validate → test Flags: --owasp for comprehensive security scanning Context: Security findings drive improvements Tech Debt Reduction: Chain: analyze --architecture → improve --quality → design → refactor Flags: --think-hard for architectural analysis Context: Debt analysis guides refactoring strategy Deployment Workflows: Safe Production Deploy: Chain: test --coverage → scan --validate → deploy --env staging → deploy --env prod Flags: --plan for production deployment Context: All gates must pass before production Emergency Rollback: Chain: deploy --rollback → troubleshoot --investigate → git --checkpoint Flags: --ultrathink for critical analysis Context: Preserve state for post-incident analysis Blue-Green Deployment: Chain: build → test → deploy --env blue → validate → switch-traffic → monitor Flags: --think-hard for deployment strategy Context: Health checks determine traffic switching ``` ## Chain Execution Rules ```yaml Success Propagation: Continue: If command succeeds, pass context to next Enhanced: Successful results enhance subsequent commands Cache: Store intermediate results for reuse Failure Handling: Stop: Critical failures halt the chain Retry: Transient failures trigger retry with backoff Fallback: Use alternative command or skip non-critical steps Recovery: Automatic rollback for deployments Context Management: Session: Keep context for entire workflow chain Handoff: Pass specific results between commands Cleanup: Clear context after chain completion Checkpoint: Save state at critical points Performance Optimization: Parallel: Execute independent commands concurrently Skip: Avoid redundant operations based on context Cache: Reuse expensive analysis results Smart: Use previous results to inform decisions ``` ## Chain Monitoring & Reporting ```yaml Progress Tracking: Status: Show current step and overall progress Time: Estimate remaining time based on historical data Bottlenecks: Identify slow steps for optimization Error Reporting: Point of Failure: Exact command and context where chain failed Recovery Options: Available retry, rollback, or manual intervention Impact Assessment: What was completed vs. what failed Metrics Collection: Duration: Total and per-step execution time Success Rate: Chain completion percentage by workflow type Resource Usage: Token consumption and tool utilization Quality Gates: Pass/fail rates for validation steps ``` ## Usage Examples ```yaml CLI Usage: Single Chain: /user:chain "new-feature" --think Custom Chain: /user:analyze → /user:build → /user:test Conditional: /user:test && /user:deploy || /user:troubleshoot Flag Inheritance: Global: /user:chain "deploy" --plan --think-hard Specific: /user:analyze --code → /user:build --magic Override: Chain defaults can be overridden per command Context Queries: Status: /user:chain-status (show current chain progress) Results: /user:chain-results (show accumulated context) History: /user:chain-history (show previous chain executions) ``` --- *Workflow chains: Orchestrated command execution with intelligent context sharing*