# Task: Analyze Story Dependencies (LLM-Native)

> 🤖 **LLM-Native Analysis** - Uses intelligent semantic analysis instead of script-based scanning

## Description

Performs deep semantic analysis of user stories using LLM reasoning to identify dependencies, architectural impacts, and optimal parallelization strategies. Goes beyond file-level conflicts to understand business logic, API contracts, and system interactions.

## LLM-Native Analysis Process

### 1. Story Content Extraction

Gather all story information for analysis:

```markdown
Story Analysis Input:

- Story descriptions and acceptance criteria
- Technical implementation notes
- Referenced components and services
- Test requirements and coverage needs
```

### 2. Semantic Dependency Analysis

Use LLM to understand deep dependencies:

```json
{
  "analysisPrompt": "Analyze these stories for semantic dependencies:",
  "dimensions": [
    "file_modifications",
    "api_contract_changes",
    "data_model_impacts",
    "business_logic_conflicts",
    "architectural_patterns",
    "test_dependencies",
    "performance_implications"
  ]
}
```

### 3. Intelligent Conflict Detection

#### Direct Conflicts

- Files that will be modified by multiple stories
- Shared database tables or schemas
- Common API endpoints

#### Semantic Conflicts

- Business logic that interacts
- State management overlaps
- Event flow dependencies
- Security boundary changes

#### Architectural Conflicts

- Design pattern violations
- Service boundary conflicts
- Infrastructure dependencies
- Deployment order requirements

### 4. Risk-Based Wave Planning

```yaml
Wave Planning Strategy:
  Wave 1 - Independent Stories:
    - No shared dependencies
    - Different architectural layers
    - Isolated business domains
    Risk: LOW

  Wave 2 - Loosely Coupled:
    - Minimal shared interfaces
    - Clear API contracts
    - Non-overlapping data
    Risk: MEDIUM

  Wave 3 - Tightly Integrated:
    - Shared core components
    - Dependent business logic
    - Sequential requirements
    Risk: HIGH
```

### 5. Generate Comprehensive Execution Plan

```json
{
  "executionPlan": {
    "strategy": "risk-optimized-waves",
    "waves": [
      {
        "wave": 1,
        "stories": ["auth-service", "logging-infra"],
        "parallelSafe": true,
        "reasoning": "Independent domains, no shared code",
        "estimatedDuration": "2 hours",
        "qualityGates": ["unit-tests", "integration-tests"]
      }
    ],
    "riskMitigation": {
      "conflictPrevention": "Semantic boundaries enforced",
      "coordinationPoints": "After each wave completion",
      "rollbackStrategy": "Per-wave reversal capability"
    }
  }
}
```

## LLM Analysis Prompt Template

```markdown
You are an expert software architect analyzing story dependencies for parallel development.

## Stories to Analyze:

[List each story with full details]

## Analysis Requirements:

1. **Semantic Dependencies**
   - Identify logical relationships between stories
   - Find hidden dependencies not obvious from file names
   - Detect business rule interactions

2. **Technical Dependencies**
   - API contracts affected
   - Database schema changes
   - Shared services or utilities
   - Infrastructure requirements

3. **Risk Assessment**
   - Probability of merge conflicts
   - Integration complexity
   - Testing dependencies
   - Deployment order constraints

4. **Parallelization Strategy**
   - Optimal wave composition
   - Maximum safe parallelization
   - Risk mitigation approach
   - Quality gate placement

Provide a structured execution plan optimized for parallel development.
```

## Output Format

### Dependency Analysis Report

```markdown
# Story Dependency Analysis

## Semantic Dependency Matrix

| Story A | Story B | Dependency Type | Risk Level | Resolution    |
| ------- | ------- | --------------- | ---------- | ------------- |
| Auth    | Profile | User Model      | HIGH       | Sequence A→B  |
| Logging | Cache   | None            | LOW        | Parallel safe |

## Execution Waves

### Wave 1 (Parallel - 3 stories)

- Stories: Logging, Cache, Metrics
- Reasoning: Independent infrastructure components
- Duration: 2.5 hours
- Risk: LOW

### Wave 2 (Parallel - 2 stories)

- Stories: Auth, Admin
- Reasoning: Separate user domains
- Duration: 3 hours
- Risk: MEDIUM

### Wave 3 (Sequential)

- Stories: Profile (depends on Auth)
- Duration: 2 hours
- Risk: LOW

## Risk Mitigation

- API contracts frozen during execution
- Feature flags for gradual rollout
- Automated conflict detection
- Per-wave rollback capability
```

## Benefits Over Script-Based Analysis

1. **Deeper Understanding**: Comprehends code purpose and business logic
2. **Hidden Dependencies**: Finds non-obvious relationships
3. **Architectural Awareness**: Understands system design impacts
4. **Risk-Based Planning**: Prioritizes based on actual impact
5. **Adaptive Strategy**: Adjusts based on discovered insights
6. **Platform Agnostic**: Works with any LLM provider

## Integration with Parallel Workflow

```bash
# Use LLM analyzer utility
./utils/llm-dependency-analyzer \
  --stories "auth,profile,logging,cache" \
  --output "dependency-analysis.json"

# Generate execution plan
./utils/llm-execution-orchestrator \
  --input "dependency-analysis.json" \
  --strategy "risk-optimized" \
  --output "execution-plan.json"
```
