# Parallel Development Story Validation Rules
# ==========================================
# This configuration defines the 3-tier validation system for parallel development
# Each rule has a severity level that determines how it's enforced:
# - critical: Blocks execution (cannot override)
# - warning: Requires justification to override
# - suggestion: Informational only

version: "1.0"

# Global validation rules applied to all story types unless overridden
global_rules:
  # CRITICAL - These issues will block parallel execution
  - rule_id: "MISSING_TITLE"
    description: "Story must have a title"
    severity: "critical"
    applies_to: ["*"]
    message: "Cannot process story without a title"
    
  - rule_id: "INVALID_FORMAT"
    description: "Story must follow BMAD format"
    severity: "critical"
    applies_to: ["*"]
    message: "Story format is invalid. Must include required BMAD sections."
    
  - rule_id: "NO_DESCRIPTION"
    description: "Story must have a description"
    severity: "critical"
    applies_to: ["*"]
    message: "Story has no description. Cannot determine scope for parallel work."

  # WARNING - These require override justification
  - rule_id: "NO_DEV_NOTES"
    description: "Story should have detailed dev notes"
    severity: "warning"
    applies_to: ["feature", "bug", "tech-debt"]
    message: "Missing implementation details increases conflict risk in parallel development"
    risk_factors:
      - "Merge conflicts due to unclear boundaries"
      - "Duplicated work across parallel branches"
      - "Integration issues during wave merges"
    
  - rule_id: "NO_ACCEPTANCE_CRITERIA"
    description: "Story should have acceptance criteria"
    severity: "warning"
    applies_to: ["feature", "bug"]
    message: "No acceptance criteria defined. QA validation may be incomplete."
    risk_factors:
      - "Unclear completion definition"
      - "Testing gaps between parallel implementations"
      
  - rule_id: "MISSING_TEST_SPECS"
    description: "Story should include test specifications"
    severity: "warning"
    applies_to: ["feature", "bug"]
    message: "No test specifications provided"
    risk_factors:
      - "Inconsistent testing across parallel branches"
      - "Quality gates may fail during wave completion"
      
  - rule_id: "UNMAPPED_DEPENDENCIES"
    description: "Story dependencies should be documented"
    severity: "warning"
    applies_to: ["feature", "tech-debt"]
    message: "Dependencies not mapped. Parallel work may conflict."
    risk_factors:
      - "Conflicting changes to shared components"
      - "Breaking changes affecting other stories"
      
  - rule_id: "HIGH_COMPLEXITY_NO_REVIEW"
    description: "High complexity stories need architect review"
    severity: "warning"
    applies_to: ["feature", "tech-debt"]
    complexity_threshold: 8
    message: "High complexity story without architect review"
    risk_factors:
      - "Architectural conflicts between parallel implementations"
      - "Performance degradation from uncoordinated changes"

  # SUGGESTION - Informational recommendations
  - rule_id: "LARGE_STORY_SIZE"
    description: "Story seems large for parallel work"
    severity: "suggestion"
    applies_to: ["feature"]
    size_threshold: 13
    message: "Consider splitting this story for better parallel execution"
    
  - rule_id: "SIMILAR_STORY_EXISTS"
    description: "Similar story may already exist"
    severity: "suggestion"
    applies_to: ["*"]
    message: "Check for potential duplication with existing stories"
    
  - rule_id: "LEGACY_SYSTEM_IMPACT"
    description: "Story touches legacy systems"
    severity: "suggestion"
    applies_to: ["feature", "bug", "tech-debt"]
    message: "Consider additional review for legacy system changes"

# Story type specific overrides
story_type_rules:
  spike:
    # Spikes have relaxed validation
    overrides:
      - rule_id: "NO_DEV_NOTES"
        severity: "suggestion"  # Downgrade from warning
      - rule_id: "NO_ACCEPTANCE_CRITERIA"
        severity: "suggestion"  # Downgrade from warning
      - rule_id: "MISSING_TEST_SPECS"
        disabled: true  # Not applicable to spikes
    
    additional_rules:
      - rule_id: "SPIKE_MISSING_GOAL"
        description: "Spike must have clear research goal"
        severity: "warning"
        message: "Spike lacks clear goal. What question are we answering?"
        
      - rule_id: "SPIKE_NO_TIMEBOX"
        description: "Spike should be timeboxed"
        severity: "suggestion"
        message: "Consider adding a timebox to prevent scope creep"

  bug:
    additional_rules:
      - rule_id: "BUG_NO_REPRO_STEPS"
        description: "Bug must have reproduction steps"
        severity: "warning"
        message: "Cannot fix bug reliably without reproduction steps"
        
      - rule_id: "BUG_NO_ROOT_CAUSE"
        description: "Bug should identify root cause"
        severity: "suggestion"
        message: "Consider root cause analysis before parallel fix attempts"

  research:
    # Research stories are like spikes
    inherit_from: "spike"

# Team-specific overrides (can be extended)
team_overrides:
  # Example: platform_team might have stricter rules
  platform_team:
    - rule_id: "NO_ACCEPTANCE_CRITERIA"
      severity: "critical"  # Upgrade from warning
    - rule_id: "HIGH_COMPLEXITY_NO_REVIEW"
      complexity_threshold: 5  # Lower threshold

# Validation execution settings
settings:
  # Re-validate on state transitions
  revalidate_on_transitions:
    - from: "backlog"
      to: "in_progress"
    - from: "ready"
      to: "in_progress"
  
  # Log all overrides for analysis
  log_overrides: true
  override_log_path: ".bmad/parallel-dev/validation-overrides.log"
  
  # Performance settings
  validation_timeout_seconds: 30
  cache_validation_results: true
  cache_ttl_seconds: 300