# AI Foundation Validation

Last run: 2026-07-28

Phase 5 adds an OpenAI-compatible generation layer without moving source facts or
credentials into the renderer.

## Implemented Workflow

1. Configure base URL, encrypted API key, default model, and content-specific models.
2. Test provider connectivity through the provider's model-list endpoint.
3. Select Serious Newsroom, Balanced, or Chaotic Social.
4. Review the recurring beat reporter, national analyst, and fan personalities.
5. Edit save-only or screenshot-enriched prompts.
6. Save default prompt edits as dynasty-scoped custom copies.
7. Generate one format or the full article, recap, headline, social, and player-grade
   package from Game Center.
8. Publish the artifact immediately and retain its model, rendered prompt, and evidence.
9. Edit the structured output or regenerate a new artifact.

Provider calls use the OpenAI-compatible `GET /models` and
`POST /chat/completions` shapes. API keys are encrypted through Electron
`safeStorage` and are not returned to the renderer.

## Grounding

The main process builds evidence from the selected stored snapshot and game:

- Score, schedule context, quarter scoring, teams, and major-game flags.
- Parsed team and player game stats.
- Formula grades supplied by Game Center for grade explanations.
- Approved corrected screenshot stat rows.
- Approved normalized highlights.
- Neutral relationship defaults until Phase 6 initializes relationship state.

Generation mode is selected automatically:

- `save_only` when no approved screenshot evidence exists.
- `screenshot_enriched` when approved highlights or screenshot stat rows exist.

The save-only prompts prohibit play-by-play, quotes, injuries, atmosphere, and
unsupported chronology. Screenshot-enriched prompts may use only approved screenshot
evidence. Every response must be a JSON object matching the content-specific contract.

## Automated Checks

```powershell
npm test
npm run build
```

Coverage includes:

- 30 templates seeded across three packs, five content types, and two evidence modes.
- Placeholder rendering and unresolved-placeholder rejection.
- Fenced JSON response parsing and content-contract validation.
- Model discovery and generation against a local mock provider.
- Authorization header and chat request validation.
- Prompt custom-copy resolution per dynasty.
- Generated artifact persistence, audit retention, and user edits.

The live Electron smoke test loaded four prompt-pack records (including the internal
custom pack), 30 default templates, the Generation Studio, and Game Center controls
without renderer errors. No external or billable provider request was made.
