# Live Intel During Calls - 0.1% Plan

## Overview
Surface company and person intelligence directly in the LiveCopilot during active calls. Currently all intel exists but is hidden away - the agent has to leave the call screen to see it.

**Status:** COMPLETE
**Priority:** #3
**Target:** Missing → 0.1%

---

## 0.1% Vision

**The best sales call experience would:**
- Show company context at a glance: industry, size, hiring signals
- Display person's job title and tenure
- Surface the sales angle (why RateRight fits THEM)
- Show similar wins: "You closed 3 formwork companies this month"
- Display previous objections from THIS lead
- Highlight effective responses for their industry

**User Experience:**
```
┌─────────────────────────────────────────────────────────────┐
│ LIVE CALL: Mike @ Built Construction                        │
├─────────────────────────────────────────────────────────────┤
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ 🏢 COMPANY: Built Construction                          │ │
│ │ Formwork • 50-100 employees • Sydney                    │ │
│ │ 🔥 Hiring: 12 jobs posted this month                    │ │
│ │                                                         │ │
│ │ 💡 SALES ANGLE: Growing fast - pain point is finding    │ │
│ │ reliable subbies. Mention your pre-vetted network.      │ │
│ └─────────────────────────────────────────────────────────┘ │
│                                                             │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ 👤 PERSON: Mike Davidson                                │ │
│ │ Operations Manager • 3 years at company                 │ │
│ │ Previously: Site Supervisor at Lendlease               │ │
│ └─────────────────────────────────────────────────────────┘ │
│                                                             │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ 🏆 SIMILAR WINS (Formwork)                              │ │
│ │ • ABC Formwork - converted in 2 calls                   │ │
│ │ • XYZ Concrete - "loved the pre-vetted workers"         │ │
│ └─────────────────────────────────────────────────────────┘ │
│                                                             │
│ [Transcript...]                                             │
│ [Objection handling...]                                     │
└─────────────────────────────────────────────────────────────┘
```

---

## Solution Design

### Architecture

```
┌─────────────────────────────────────────────────────────────┐
│                     FRONTEND                                 │
├─────────────────────────────────────────────────────────────┤
│  LiveCopilot.jsx                                            │
│  ├── NEW: IntelPanel component (collapsible)                │
│  ├── Fetches intel on mount (parallel API calls)            │
│  └── Shows company + person + similar wins                  │
│                                                             │
│  NEW: LiveIntelPanel.jsx                                    │
│  ├── CompanyCard: industry, size, location, hiring signals  │
│  ├── PersonCard: job title, tenure, previous companies      │
│  ├── SalesAngleCard: tailored pitch for this lead           │
│  ├── SimilarWinsCard: recent wins in same industry          │
│  └── PreviousObjectionsCard: if they've objected before     │
└─────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────┐
│                     BACKEND                                  │
├─────────────────────────────────────────────────────────────┤
│  NEW endpoint: GET /api/ai/live-intel/:leadId               │
│  ├── Fetches company intel (cached)                         │
│  ├── Fetches person intel (cached)                          │
│  ├── Fetches similar wins                                   │
│  ├── Fetches previous objections for this lead              │
│  └── Returns consolidated intel package                     │
└─────────────────────────────────────────────────────────────┘
```

---

## Data Already Available

| Intel Type | Source | Currently Shown |
|------------|--------|-----------------|
| Company summary | company_intel table | No |
| Company industry | company_intel.industry | No |
| Company size | company_intel.size | No |
| Hiring signals | company_intel.hiring_signals | No |
| Sales angle | company_intel.sales_angle | No |
| Person job title | lead_intel.job_title | No |
| Person years at company | lead_intel.years_at_company | No |
| Person previous companies | lead_intel.previous_companies | No |
| Talking points | lead.ai_intel_brief | Yes |
| Opening line | lead.ai_intel_brief | Yes |
| Objection responses | Real-time API | Yes |
| Similar wins | similar-wins endpoint | No |
| Previous objections | copilot_sessions table | No |

---

## Implementation Steps

### Step 1: Create Live Intel API Endpoint ✅ DONE
**File:** `src/routes/ai.js`

New endpoint `GET /api/ai/live-intel/:leadId`:
```javascript
// Returns consolidated intel for live call display
{
  company: {
    name: "Built Construction",
    industry: "Formwork",
    size: "50-100",
    location: "Sydney, NSW",
    hiring_signals: "12 jobs posted this month",
    sales_angle: "Growing fast - pain point is finding reliable subbies..."
  },
  person: {
    job_title: "Operations Manager",
    years_at_company: 3,
    previous_companies: ["Lendlease"],
    summary: "..."
  },
  similar_wins: [
    { name: "ABC Formwork", outcome: "converted", key_factor: "pre-vetted workers" },
    { name: "XYZ Concrete", outcome: "converted", key_factor: "reliability" }
  ],
  previous_objections: [
    { type: "price", date: "2026-01-10", resolved: true }
  ]
}
```

### Step 2: Create LiveIntelPanel Component ✅ DONE
**File:** `admin/src/components/LiveIntelPanel.jsx`

Compact, collapsible panel with:
- Company card (industry badge, size, location, hiring signals)
- Person card (job title, tenure)
- Sales angle highlight
- Similar wins (top 2-3)
- Previous objections (if any)

### Step 3: Integrate into LiveCopilot ✅ DONE
**File:** `admin/src/components/LiveCopilot.jsx`

- Import LiveIntelPanel
- Fetch live-intel on mount
- Show panel above transcript (collapsible to save space)
- Cache in component state to avoid re-fetches

### Step 4: Add Previous Objections Query ✅ DONE
**File:** `src/routes/ai.js`

Query copilot_sessions for this lead's previous objection types:
```sql
SELECT DISTINCT objection_type, MAX(created_at) as last_seen
FROM copilot_sessions
WHERE lead_id = ? AND objection_type IS NOT NULL
GROUP BY objection_type
```

### Step 5: Frontend API Client ✅ DONE
**File:** `admin/src/api/client.js`

Add to aiApi:
```javascript
getLiveIntel: (leadId) => request(`/api/ai/live-intel/${leadId}`),
```

### Step 6: Build & Deploy ✅ DONE
- Build frontend
- Deploy to production
- Verify intel appears during calls

### Step 7: Documentation ✅ DONE
- Update SYSTEM-INTEL.md
- Update this plan file
- Add build history entry

---

## Files to Modify/Create

| File | Action |
|------|--------|
| `src/routes/ai.js` | ADD `/api/ai/live-intel/:leadId` endpoint |
| `admin/src/components/LiveIntelPanel.jsx` | CREATE new component |
| `admin/src/components/LiveCopilot.jsx` | INTEGRATE LiveIntelPanel |
| `admin/src/api/client.js` | ADD getLiveIntel function |
| `docs/SYSTEM-INTEL.md` | UPDATE status |

---

## UI Design

### LiveIntelPanel Layout

```
┌────────────────────────────────────────────────┐
│ 📊 INTEL                              [−]      │
├────────────────────────────────────────────────┤
│ 🏢 Built Construction                          │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐        │
│ │ Formwork │ │ 50-100   │ │ Sydney   │        │
│ └──────────┘ └──────────┘ └──────────┘        │
│ 🔥 Hiring: 12 jobs posted                      │
│                                                │
│ 👤 Mike Davidson                               │
│ Operations Manager • 3 years                   │
│                                                │
│ 💡 ANGLE: Growing fast, need reliable subbies  │
│                                                │
│ 🏆 WINS: ABC Formwork, XYZ Concrete (2 this mo)│
│                                                │
│ ⚠️ PREVIOUS: Objected on price (Jan 10)        │
└────────────────────────────────────────────────┘
```

### Collapsed State
```
┌────────────────────────────────────────────────┐
│ 📊 Built Construction • Formwork • Ops Mgr [+] │
└────────────────────────────────────────────────┘
```

---

## Success Criteria

1. **Company context visible** - Industry, size, hiring signals shown during call
2. **Person context visible** - Job title and tenure shown
3. **Sales angle prominent** - Tailored pitch visible at a glance
4. **Similar wins shown** - Agent knows what worked for similar leads
5. **Previous objections flagged** - Agent prepared for repeat objections
6. **Minimal latency** - Intel loads within 500ms (uses cached data)
7. **Non-intrusive** - Collapsible so it doesn't block transcript

---

## Testing Scenarios

| Scenario | Expected Result |
|----------|-----------------|
| Start call with lead that has company intel | Intel panel shows company data |
| Start call with lead that has person intel | Panel shows job title, tenure |
| Start call with lead in industry with previous wins | Similar wins card populated |
| Start call with lead who objected before | Previous objections warning shown |
| Start call with new lead (no intel) | Panel shows "No intel yet" state |
| Collapse panel | Shows one-line summary with expand button |

---

**Ready for Phase 3: Execute**

Build order:
1. Live intel API endpoint
2. LiveIntelPanel component
3. LiveCopilot integration
4. API client update
5. Build & deploy
6. Test all scenarios
7. Document
