# SCX AI Accuracy Review

The planning, demand, manual layout, digital-twin, bill-of-materials and engineering tools now show an **AI Accuracy Review** button.

## Review behaviour

- Deterministic checks always run locally on the SCX server. These include invalid values, missing engineering fields, BOM completeness, capacity warnings and same-height runway/bridge crossing checks.
- When an OpenAI API key is configured, the server sends the current design artifact for a second-pass structured review of assumptions, consistency, omissions and unusual results.
- AI does not replace the SCX calculations, geometric constraints, applicable standards, independent checking or competent-person approval.
- API credentials remain on the Python server and are never returned to browser JavaScript.

## Enable the AI second pass

### Windows batch launcher (recommended for this package)

Double-click `start.bat`. If no key is already configured, the launcher prompts for it with hidden input, saves it as the current Windows user's `OPENAI_API_KEY`, and starts Python with AI review enabled. Later launches reuse the saved value automatically.

The key is not written into the batch file, project source or browser JavaScript. Windows user environment variables remain readable by processes running under the same Windows account.

### Manual session setup

PowerShell, for the current terminal session:

```powershell
$env:OPENAI_API_KEY = "your-api-key"
$env:OPENAI_MODEL = "gpt-5.6"
python server.py --host 127.0.0.1 --port 8840
```

For the clean deployment package:

```powershell
Set-Location "deployment\SCX_Crane_Planner"
$env:OPENAI_API_KEY = "your-api-key"
$env:OPENAI_MODEL = "gpt-5.6"
.\start.ps1
```

For Docker, supply the key at runtime instead of storing it in the image:

```powershell
docker run --rm -p 8840:8840 -e OPENAI_API_KEY -e OPENAI_MODEL=gpt-5.6 scx-crane-planner
```

`OPENAI_MODEL` is optional and lets an administrator select an approved model without changing the application. `OPENAI_BASE_URL` is also optional and defaults to `https://api.openai.com/v1`.

## Data handling and release control

The review is initiated by the user; the application does not automatically upload the repository or database. Only the current tool artifact and displayed inputs/results are submitted. Review findings should be resolved or formally dispositioned in the repository audit trail before design release.
