# CORI Normalized Live Event Contract Scaffold

## Purpose
This document defines the shared runtime contract that must sit between raw provider events and the dispatcher-facing CORI call surfaces.

The goal is simple:
- provider payloads stay below the UI line
- page and popup read the same truth
- facts stay short and stable
- advice only refreshes when a better fact changes the decision

## 1. Shared event rule
The UI must react to normalized events, not to raw Twilio or future provider payloads.

### Core event set
- `SESSION_READY`
- `POLICY_BLOCKED`
- `NOTICE_REQUIRED`
- `CALL_DIALING`
- `CALL_CONNECTED`
- `LISTENING_STARTED`
- `TRANSCRIPT_PARTIAL`
- `FACT_UPSERTED`
- `ADVICE_REFRESHED`
- `SAVE_READY_CHANGED`
- `SESSION_ENDED`

## 2. Listening posture store shape
The dispatcher-facing runtime store should stay small.

### Required posture fields
- listening posture
- consent gate
- best fact count
- advice mode

### Listening posture values
- `IDLE`
- `POLICY_BLOCKED`
- `NOTICE_REQUIRED`
- `READY`
- `DIALING`
- `LISTENING`
- `ENDED`

### Consent gate values
- `BLOCKED`
- `NEEDS_NOTICE`
- `READY`

## 3. Partial fact state model
Facts should move through stable lifecycle stages instead of being written directly from raw fragments.

### Fact stages
- `HEARD`
- `TENTATIVE`
- `STABLE`
- `REPLACED`
- `CONFIRMED`
- `DISCARDED`

### Shared fact keys in the first scaffold
- contact
- lane
- offer
- callback
- result
- objection

## 4. Advice refresh contract
Advice should not refresh on every transcript fragment.

Advice should refresh only when:
- a stronger fact replaces a weaker fact
- result posture changes
- objection meaning changes
- callback timing becomes usable
- save readiness changes

Dispatcher-facing advice should stay limited to:
- trigger
- one calm explanation
- save readiness rule

## 5. Runtime selectors
The first shared selectors should work the same on the full page and popup surfaces.

### Required selectors
- status strip
- best facts
- advice refresh
- save readiness

### Selector rule
A selector may summarize the state, but it should never expose raw provider payload shape to the UI.

## 6. Provider-agnostic boundary
Twilio can be the first provider, but it must not define the public runtime contract.

That means provider-specific payload details should be normalized before they reach:
- CORI’s Quotes full page
- CORI popup call shell
- future truck, load, or call-entry launchers

## 7. Why this scaffold comes before launcher expansion
If more launchers are added before the shared event contract is stable, the app will spread inconsistent call behavior across multiple pages.

This scaffold keeps the next expansion phase clean because every launcher can open into the same:
- posture model
- fact model
- advice rule set
- save boundary
