graph TD
Start([Start: Create/Replan Epics]) --> Phase1[Phase 1: Discovery & Research
Auto-discover Team ID + Next Epic Number
Scan docs + HTML files
Infrastructure Epic decision]
Phase1 --> Phase2[Phase 2: Scope Analysis
Auto-identify domains from docs + HTML
Build Epic list Epic 0-N
Show proposed structure]
Phase2 --> UserConfirm1{User confirms
Epic structure?}
UserConfirm1 -->|No| Phase2
UserConfirm1 -->|Yes| Phase3[Phase 3: Check Existing Epics
Count rows in Epic Story Counters]
Phase3 --> Decision{Existing
Epics count?}
Decision -->|Count = 0
CREATE MODE| Phase4[Phase 4: Epic Preparation
Auto-extract Q1-Q5 for ALL domains
Generate ALL Epic documents]
Phase4 --> Phase5a[Phase 5a: Epic Creation
Show batch preview Epic 0-N]
Phase5a --> UserConfirm2{User types
'confirm'?}
UserConfirm2 -->|No| Phase4
UserConfirm2 -->|Yes| CreateAll[Create ALL Epics in Linear
Epic 0 → Epic 11: Infrastructure
Epic 1 → Epic 12: User Management
etc.]
CreateAll --> Summary1[Display summary
6 Epics created Epic 11-16]
Summary1 --> End([End])
Decision -->|Count ≥ 1
REPLAN MODE| Phase5b[Phase 5b: Epic Replan
Load existing Epics
Compare IDEAL vs EXISTING
Categorize operations]
Phase5b --> Operations[Show operations:
KEEP / UPDATE / OBSOLETE / CREATE]
Operations --> UserConfirm3{User confirms
operations?}
UserConfirm3 -->|No| End
UserConfirm3 -->|Yes| Execute[Execute operations in Linear
Update kanban_board.md]
Execute --> Summary2[Display summary
Operation results + affected URLs]
Summary2 --> End
%% Styling
classDef discovery fill:#E3F2FD,stroke:#1976D2,stroke-width:2px
classDef loop fill:#FFF9C4,stroke:#F57C00,stroke-width:2px
classDef decision fill:#FFE0B2,stroke:#E64A19,stroke-width:2px
classDef action fill:#C8E6C9,stroke:#388E3C,stroke-width:2px
class Phase1,Phase2 discovery
class Phase4,Phase5a,Phase5b,Operations,Execute loop
class Decision,UserConfirm1,UserConfirm2,UserConfirm3 decision
class Phase3,CreateAll,Summary1,Summary2 action