# Task: Validate Parallel Setup

> ✅ **Works with any IDE** - Pre-flight validation checklist for parallel development

## Description

Comprehensive validation of system readiness for parallel story development, checking prerequisites, dependencies, and potential issues.

## Validation Steps

### 1. Git Environment Check

```bash
# Check Git version (needs 2.7+ for worktrees)
git_version=$(git --version | awk '{print $3}')
echo "Git version: $git_version"

# Verify worktree support
if git worktree list >/dev/null 2>&1; then
    echo "✅ Git worktree support available"
else
    echo "❌ Git worktree not supported"
    exit 1
fi

# Check for clean working directory
if [ -n "$(git status --porcelain)" ]; then
    echo "❌ Working directory has uncommitted changes"
    exit 1
else
    echo "✅ Working directory clean"
fi

# Verify on main branch
current_branch=$(git branch --show-current)
if [[ "$current_branch" == "main" || "$current_branch" == "develop" ]]; then
    echo "✅ On main branch: $current_branch"
else
    echo "⚠️  Not on main branch: $current_branch"
fi
```

### 2. BMAD Story Validation

```bash
# Check story directory exists
if [ -d "docs/stories" ]; then
    echo "✅ Story directory found"
    story_count=$(find docs/stories -name "user-story-*.md" | wc -l)
    echo "   Found $story_count stories"
else
    echo "❌ No docs/stories directory"
    exit 1
fi

# Validate story format
for story in docs/stories/user-story-*.md; do
    if [ -f "$story" ]; then
        # Check required sections
        has_status=$(grep -c "^## Status:" "$story")
        has_story=$(grep -c "^## Story" "$story")
        has_ac=$(grep -c "^## Acceptance Criteria" "$story")
        has_tasks=$(grep -c "^## Tasks" "$story")
        has_dev_notes=$(grep -c "^## Dev Notes" "$story")

        if [[ $has_status -eq 0 || $has_story -eq 0 || $has_ac -eq 0 || $has_tasks -eq 0 || $has_dev_notes -eq 0 ]]; then
            echo "❌ Invalid story format: $(basename $story)"
        else
            echo "✅ Valid format: $(basename $story)"
        fi
    fi
done
```

### 3. System Resource Check

```bash
# Check available disk space
available_space=$(df -h . | awk 'NR==2 {print $4}')
echo "Available disk space: $available_space"

# Check memory (macOS/Linux compatible)
if [[ "$OSTYPE" == "darwin"* ]]; then
    total_mem=$(sysctl -n hw.memsize | awk '{print $1/1024/1024/1024 "GB"}')
    echo "Total memory: $total_mem"
else
    total_mem=$(free -h | awk '/^Mem:/ {print $2}')
    echo "Total memory: $total_mem"
fi

# Count CPU cores
if [[ "$OSTYPE" == "darwin"* ]]; then
    cpu_cores=$(sysctl -n hw.ncpu)
else
    cpu_cores=$(nproc)
fi
echo "CPU cores: $cpu_cores"
echo "Recommended max agents: $((cpu_cores * 2))"
```

### 4. Development Environment Check

```bash
# Check Node.js
if command -v node &> /dev/null; then
    node_version=$(node --version)
    echo "✅ Node.js installed: $node_version"
else
    echo "❌ Node.js not found"
fi

# Check npm
if command -v npm &> /dev/null; then
    npm_version=$(npm --version)
    echo "✅ npm installed: $npm_version"
else
    echo "❌ npm not found"
fi

# Check for test framework
if [ -f "package.json" ]; then
    has_jest=$(grep -c "jest" package.json)
    has_mocha=$(grep -c "mocha" package.json)
    has_vitest=$(grep -c "vitest" package.json)

    if [[ $has_jest -gt 0 || $has_mocha -gt 0 || $has_vitest -gt 0 ]]; then
        echo "✅ Test framework found"
    else
        echo "⚠️  No test framework detected"
    fi
fi

# Check for linting
if [ -f ".eslintrc" ] || [ -f ".eslintrc.js" ] || [ -f ".eslintrc.json" ]; then
    echo "✅ ESLint configuration found"
else
    echo "⚠️  No ESLint configuration"
fi
```

### 5. Claude-Specific Validation (if using Claude)

```bash
# Check for Claude commands directory
if [ -d ".claude/commands" ]; then
    echo "✅ Claude commands directory exists"
else
    echo "⚠️  Claude commands directory missing"
    echo "   Run: mkdir -p .claude/commands"
fi

# Check for Task tool availability
echo "ℹ️  Claude Task tool availability can only be verified at runtime"
echo "   The /stories command will fail gracefully if unavailable"
```

### 6. Parallel Configuration Check

```bash
# Check for configuration file
if [ -f ".claude/parallel-config.json" ]; then
    echo "✅ Parallel configuration found"
    # Validate JSON syntax
    if python -m json.tool .claude/parallel-config.json >/dev/null 2>&1; then
        echo "✅ Configuration syntax valid"
    else
        echo "❌ Invalid JSON in configuration"
    fi
else
    echo "⚠️  No parallel configuration file"
    echo "   Using defaults"
fi
```

### 7. Generate Validation Report

```bash
cat > parallel-validation-report.md << EOF
# Parallel Development Validation Report

Generated: $(date)

## System Readiness
- Git Version: $git_version
- Worktree Support: ✅
- Clean Working Directory: ✅
- CPU Cores: $cpu_cores
- Recommended Agents: $((cpu_cores * 2))

## Story Validation
- Stories Found: $story_count
- Valid Format: X/Y
- Ready for Development: X

## Environment
- Node.js: $node_version
- Test Framework: ✅
- Linting: ✅

## Recommendations
1. [Specific recommendations based on findings]

## Command to Execute
\`\`\`bash
/stories --waves X,Y,Z --quality-gates
\`\`\`
EOF

echo "✅ Validation complete. See parallel-validation-report.md"
```

## Integration

This validation can be run:

1. Manually before starting parallel development
2. As part of `/stories:analyze` mode
3. In CI/CD pipeline before deployment
4. As a pre-commit hook

## Success Criteria

System is ready when:

- All Git checks pass
- Stories are properly formatted
- Sufficient system resources
- Development environment configured
- No blocking issues identified
