# /pipeline-review — Analyze Pipeline Health & Deal Priority

Analyze the lead pipeline's campaign results, prioritize deals, flag risks, and generate an action plan.

## Usage

```
/pipeline-review                          # Review all recent campaigns
/pipeline-review <campaign_id>            # Review specific campaign
/pipeline-review --format table|json|csv  # Output format
```

## What This Command Does

### Step 1: Load Pipeline Data
- Scan `~/.lead_pipeline/data/` for campaign result files
- Load leads with their current statuses from `LeadStore`
- If campaign_id provided, focus on that specific campaign

### Step 2: Pipeline Health Scoring

Score each lead/deal on four dimensions (25 points each, 100 total):

| Dimension | What It Measures | Scoring |
|-----------|-----------------|---------|
| **Stage Progression** | Has the lead moved through pipeline stages? | NEW=5, ENRICHED=10, EMAIL_DRAFTED=15, SENT=20, Replied=25 |
| **Data Quality** | How complete is the lead's data? | Email+Phone+LinkedIn+Website = 25 |
| **Engagement Recency** | How recently was there activity? | Today=25, <3d=20, <7d=15, <14d=10, <30d=5 |
| **Contact Coverage** | Do we have the right contacts? | Decision-maker=25, Manager=15, Generic=5 |

### Step 3: Risk Identification

Flag leads with these risk patterns:
- **Stale leads** — enriched but no email drafted for 7+ days
- **Incomplete data** — missing email AND phone after enrichment
- **Failed sends** — status=FAILED with unresolved errors
- **Single-source** — data from only one registry/search engine
- **GDPR risk** — no audit trail or questionable legal basis

### Step 4: Generate Review Output

```markdown
## Pipeline Review — [Date]

### Summary Metrics
| Metric | Count |
|--------|-------|
| Total leads | [N] |
| New (unprocessed) | [N] |
| Enriched | [N] |
| Emails drafted | [N] |
| Sent | [N] |
| Failed | [N] |
| Skipped | [N] |

### Health Score Distribution
- 🟢 Healthy (75-100): [N] leads
- 🟡 Needs attention (50-74): [N] leads
- 🔴 At risk (0-49): [N] leads

### Priority Actions (This Week)
1. **[Action]** — [Lead/Company] — [Why it matters]
2. **[Action]** — [Lead/Company] — [Why it matters]
3. **[Action]** — [Lead/Company] — [Why it matters]

### Risk Alerts
⚠️ [N] stale leads need follow-up
⚠️ [N] leads with incomplete contact data
⚠️ [N] failed sends to investigate
⚠️ [N] leads with GDPR compliance gaps

### Conversion Funnel
Scraped [N] → Enriched [N] ([%]) → Drafted [N] ([%]) → Sent [N] ([%])

### Top Leads by Score
| Company | Contact | Score | Stage | Next Action |
|---------|---------|-------|-------|-------------|
| [Co 1]  | [Name]  | [85]  | SENT  | Follow up   |
| [Co 2]  | [Name]  | [72]  | ENRICHED | Draft email |
| [Co 3]  | [Name]  | [68]  | NEW | Enrich data |

### Campaign Performance (if multiple campaigns)
| Campaign | Date | Leads | Sent | Success Rate |
|----------|------|-------|------|-------------|
| [ID 1]   | [Date] | [N] | [N] | [%] |
| [ID 2]   | [Date] | [N] | [N] | [%] |
```

## Integration

- Uses `LeadStore` from `lead_pipeline/types.py` to load data
- References `CampaignResult` metrics for conversion analysis
- Checks `GDPRAuditEntry` for compliance status
- Can trigger follow-up actions: re-enrich, re-compose, re-send
