# Lexi Platform — Les Sidebottom Handoff

**Audience:** Les Sidebottom / Data & Analytics  
**Purpose:** Bolt Lexi onto the Comp Intelligence app as a test/demo assistant.  
**Current status:** Working sandbox package. Not production. Synthetic data only. No PHI. No real provider compensation data.

---

## 1. What this is

Lexi is now packaged as a bolt-on assistant that can be mounted into a host application.

For Comp Intelligence, the host app provides a compensation snapshot to the page, Lexi builds a context prompt from that snapshot, and the sandbox Worker returns deployment-aware answers through the mock adapter.

The key point: **Les does not need to redesign the Comp Intelligence app around Lexi.** Lexi can be added as a side panel, drawer, or embedded card.

---

## 2. Current live sandbox assumptions

Use these while testing:

```text
Pages sandbox:
https://lexi-platform-sandbox.pages.dev

Worker sandbox:
https://lexi-api-sandbox.ctcaw259.workers.dev

Primary Comp Intelligence demo:
https://lexi-platform-sandbox.pages.dev/hosts/comp-intelligence-test.html?worker=https://lexi-api-sandbox.ctcaw259.workers.dev
```

Expected Worker health:

```json
{
  "ok": true,
  "workerVersion": "0.2.2",
  "environment": "sandbox",
  "bootWarnings": [],
  "bootCritical": []
}
```

If the Worker version is older, redeploy `worker/dist/worker-bundle.js`.

---

## 3. Files Les needs to understand

| Folder/File | Purpose |
|---|---|
| `/index.html` | Landing page for demo and handoff |
| `/hosts/comp-intelligence-test.html` | Working Comp Intelligence synthetic test page |
| `/embed/lexi-embed.js` | Core embed engine; exposes `window.Lexi` |
| `/embed/lexi-widget.js` | Optional default widget UI |
| `/embed/lexi.css` | Optional widget styling |
| `/lexi/context-builders/comp-intelligence-context.stub.js` | Reads `window.CompIntelSnapshot` and builds Lexi context |
| `/worker/dist/worker-bundle.js` | Dashboard-deployable Cloudflare Worker bundle |
| `/INTEGRATION.md` | Technical integration guide |
| `/SPRINT-2.2.md` | Sprint dossier and acceptance proof |

---

## 4. The Comp Intelligence data contract

The host app should define `window.CompIntelSnapshot` before Lexi initializes.

Minimum shape:

```js
window.CompIntelSnapshot = {
  period: 'Q2 2026',
  totalWrvus: 304611,
  totalCompPaid: 16200000,
  avgWrvuPerProvider: 2160,
  providerCount: 141,
  fmvExceptions: 0,
  specialties: [
    { id: 'syn-cards', label: 'Cardiology', n: 14, medianWrvu: 5800, mgmaPct: 62 },
    { id: 'syn-ortho', label: 'Orthopedics', n: 11, medianWrvu: 7100, mgmaPct: 71 }
  ]
};
```

For the current sandbox, keep the data synthetic.

When production gets closer, the same object can be populated from the real Comp Intelligence app state after Tabor/Chapman governance gates are cleared.

---

## 5. Minimal embed pattern

```html
<link rel="stylesheet" href="/embed/lexi.css">

<script>
window.LEXI_ENVIRONMENT = 'sandbox';
window.LEXI_DEPLOYMENT = 'comp-intelligence';

window.CompIntelSnapshot = {
  period: 'Q2 2026 (SYNTHETIC)',
  totalWrvus: 304611,
  totalCompPaid: 16200000,
  avgWrvuPerProvider: 2160,
  providerCount: 141,
  fmvExceptions: 0,
  specialties: [
    { id: 'syn-cards', label: 'Cardiology', n: 14, medianWrvu: 5800, mgmaPct: 62 },
    { id: 'syn-ortho', label: 'Orthopedics', n: 11, medianWrvu: 7100, mgmaPct: 71 }
  ]
};
</script>

<div id="lexiPanel"></div>

<script src="/embed/lexi-embed.js"></script>
<script src="/embed/lexi-widget.js"></script>
<script>
Lexi.init({
  workerUrl: 'https://lexi-api-sandbox.ctcaw259.workers.dev',
  deployment: 'comp-intelligence',
  environment: 'sandbox',
  jwt: () => null,
  basePath: '/lexi'
}).then(() => {
  Lexi.mountWidget({
    target: '#lexiPanel',
    title: 'Ask Lexi about Comp Intelligence',
    mode: 'inline',
    suggestedPrompts: [
      'What was our total wRVU output this quarter?',
      'Which specialty has the highest median wRVU?',
      'How many FMV exceptions are there?',
      'Compare cardiology to orthopedics on wRVU output.'
    ]
  });
});
</script>
```

---

## 6. What Lexi can answer in the sandbox

Comp Intelligence test prompts:

```text
What was our total wRVU output this quarter?
Which specialty has the highest median wRVU?
How many FMV exceptions are there?
Compare cardiology to orthopedics on wRVU output.
How many providers are represented?
What was total compensation paid?
```

Public FAQ test prompts:

```text
How do I schedule an appointment?
What insurance plans do you accept?
How do I contact Lexington Clinic?
Where are locations listed?
```

---

## 7. Boundaries

This package is intentionally test-only.

Allowed now:

```text
Synthetic Comp Intelligence snapshot
Mock Worker route
Sandbox unauthenticated mode
Public FAQ test content
Local/Cloudflare Pages demo
```

Not allowed yet:

```text
Real provider compensation data
PHI
Production Foundry route
Persistent audit storage
Production Cloudflare Access policy
Production release
```

Future gates:

```text
Tabor: production infrastructure, Cloudflare Access, routing, secrets, deployment ownership
Chapman: real comp data, PHI posture, retention/audit, BAA handling
Microsoft: Foundry credential activation and model route confirmation
```

---

## 8. Les acceptance checklist

For the Comp Intelligence bolt-on demo:

```text
[ ] Page loads with TEST MODE / synthetic-data banner
[ ] Lexi panel appears in the Comp Intelligence layout
[ ] Suggested prompts are visible
[ ] User can ask a wRVU total question and receive a useful answer
[ ] User can ask highest-specialty question and receive a useful answer
[ ] User can ask FMV exceptions question and receive a useful answer
[ ] User can compare Cardiology vs Orthopedics
[ ] Assistant response shows source/context indicator
[ ] Copy response works
[ ] Clear chat works
[ ] No real provider names or real comp data appear
```

---

## 9. Recommended next build after Les review

If Les accepts the integration shape, the next sprint should be:

**Sprint 2.3 — Comp Intelligence Native Integration**

Scope:

```text
Mount Lexi into Les's actual Comp Intelligence app shell.
Replace synthetic snapshot with app-generated synthetic fixture first.
Map real app state to window.CompIntelSnapshot.
Keep Worker in sandbox/mock mode.
Add visual styling to match Comp Intelligence UI.
No real provider data yet.
```

That gets the product into the real app without crossing production or real-data boundaries.
