# SarahAI Platform Context

SarahAI (Sarah SDR) is an AI-powered sales development platform by Peliguard. It automates email outreach through two campaign phases:

1. **Mailgun mass phase** -- Bulk brochure emails sent via Mailgun
2. **Google SDR follow-up phase** -- Personalized AI-generated follow-ups sent from connected Gmail inboxes

## Core Concepts

- **Organization (Location):** Multi-tenant unit. Each org has its own campaigns, leads, inboxes, and Mailgun domain.
- **Campaign:** An outreach sequence targeting a set of leads through one or both phases.
- **Prospect List:** A named, reusable collection of contacts. Prospects become leads when assigned to a campaign.
- **Lead:** A contact assigned to a campaign. Tracked per-campaign for Mailgun and SDR engagement.
- **Inbox:** A Gmail account connected via OAuth for sending SDR emails. Each inbox has its own AI model configuration.
- **Copy Template:** Brochure HTML or opener text used in campaigns. Has version history.
- **AI SDR:** The AI system that generates personalized email responses using OpenAI or Anthropic models.

## API Design

All CLI commands map to REST API routes on the SarahAI Next.js backend:

- All responses are JSON
- Auth is via `Authorization: Bearer <supabase_token>` or `X-Auth-Token`
- Supabase Row Level Security enforces org-scoping and role permissions
- The CLI can only do what the authenticated user is permitted to do

## Context Window Discipline

Workspace APIs can return large payloads. When using the CLI:

- **Use `--fields` to limit response fields** when listing campaigns or leads
- **Process prospect list members in batches** rather than fetching the entire list at once
- **Use `sarah schema <resource.method>`** to check expected request/response shapes instead of guessing

## Environment Variables

| Variable | Required | Description |
|----------|----------|-------------|
| `SARAH_ACCESS_TOKEN` | Yes (unless service mode) | Supabase access token for the authenticated user |
| `SARAH_SERVICE_SECRET` | No | Service secret for cron/admin operations |
| `SARAH_API_URL` | No | API base URL (defaults to `http://localhost:3010`) |
| `SARAH_CONFIRM` | No | Set to `true` to skip confirmation prompts |
