Skip to content

First-run setup: credential preflight, cross-platform runner, Makefile - #7

Merged
anmolg1997 merged 3 commits into
mainfrom
chore/root-makefile
Jun 4, 2026
Merged

First-run setup: credential preflight, cross-platform runner, Makefile#7
anmolg1997 merged 3 commits into
mainfrom
chore/root-makefile

Conversation

@anmolg1997

@anmolg1997 anmolg1997 commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

Why

A teammate hit setup failures on a fresh clone (two screenshots). Root-causing the second one (a bare live run) found a real engine bug, not just an ergonomics gap:

  • A live run with no API key either crashes with a raw SDK TypeError ("Could not resolve authentication method"), or — if DISCOVERY_OFFLINE lingers from an earlier golden experiment — prints the misleading offline mode: no cached response … use the golden run. Neither tells you the real problem: your key isn't set.
  • The on-disk LLM cache (.cache/) is gitignored, so a fresh clone has nothing to replay live. Only the committed golden/ does, via --golden.
  • uv also warned about a stale VIRTUAL_ENV pointing at another project's venv.

This PR fixes the root cause and makes setup one command on Mac/Linux/Windows.

Engine fixes (behaviour unchanged for valid runs)

  • Credential preflight (run.py) — on any non---golden (live) path, if the selected provider has no usable credentials, stop before any work with one actionable line and exit 2:
    error: this is a LIVE run but the 'anthropic' provider has no usable credentials (missing/placeholder: ANTHROPIC_API_KEY).
      Fix one of these, then re-run:
        • Add your key to v1/.env  (cp .env.example .env, then fill it in),
        • verify it with:  uv run python scripts/doctor.py
      Or run the OFFLINE demo with no key and no cost:
        uv run python run.py --domain o2c --golden --auto-resolve
    
  • env.pymissing_credentials() / credentials_present(): provider-aware (Anthropic key or the full Azure var set), and the .env.example placeholder (sk-ant-...) counts as missing so a freshly-seeded .env fails cleanly instead of handing a bogus key to the SDK.
  • llm.py — provider calls are wrapped so any auth/network SDK error becomes a clean LLMError with the real fix (no traceback); the offline-mode messages now say it's cache-only (DISCOVERY_OFFLINE) and how to go live.

Cross-platform, single source of truth

  • tasks.py (new, stdlib-only) — python tasks.py setup|run|live|console|report|ui|open|doctor|test|clean|distclean. Works on Mac / Linux / Windows. Strips a stray VIRTUAL_ENV before every uv call (kills the "does not match .venv" warning), uses arg-list subprocess + webbrowser (space- and OS-safe), prereq-checks uv/npm with install hints.
  • Makefile — now a thin wrapper that forwards each target to tasks.py, so make <t> (Mac/Linux) and python tasks.py <t> (Windows) run identical logic.
  • README — Windows quickstart; prerequisites called out; note that a live run preflights credentials.

Default path is keyless & free

make run / python tasks.py run is a deterministic golden replay → builds the explorer → opens it. No key, no cost, no cache-miss wall.

Verified

  • Repro no key + live → clean preflight STOP (exit 2), no traceback ✓
  • Repro placeholder key + live → same clean STOP ✓
  • no key + --golden → full success (exit 0) ✓
  • make report / tasks.py report with a deliberately-stale VIRTUAL_ENV exported → no warning, golden replay completes ✓
  • tasks.py run full chain (report → build → open) ✓
  • Suite 248 passed, 100% branch coverage held, pyrefly clean (incl. tasks.py) ✓

A first-timer can now go from clone to a rendered demo with `make setup && make run`
from the repo root — no remembering the cd's, uv flags, or which env to activate.

Directly targets the two failures from the fresh-clone screenshot:
- Stale VIRTUAL_ENV warning ("does not match .venv"): every uv call runs with
  `env -u VIRTUAL_ENV` and pinned to v1/, so it always targets v1/.venv.
- "offline mode: no cached response" dead-end: the default `make run` is a golden
  replay (no key, no cost, deterministic) and can't hit that wall. Live is a
  separate, explicit `make live`.

Targets: setup / run / live / console / report / ui / open / doctor / test /
clean / distclean. Prereq checks for uv + npm print install hints instead of a
cryptic "command not found". The `live` guard is provider-aware (real Anthropic
key OR full Azure var set) and rejects the .env.example placeholder so a fresh
clone can't launch a doomed run. All paths are space-quoted — the repo dir name
contains a space. README Quickstart now leads with the make flow (manual steps
kept in a details block).
…legates to it

Root-caused the manager's second screenshot: a bare live run with no key either
crashes with a raw SDK TypeError ("Could not resolve authentication method") or,
if DISCOVERY_OFFLINE lingers, prints the misleading "use the golden run" message.
The .cache/ is gitignored, so a fresh clone has nothing to replay live — only the
committed golden/ does, via --golden.

Engine (behaviour unchanged for valid runs):
- run.py: credential PREFLIGHT on any non-golden (live) path. If the selected
  provider has no usable creds, stop before any work with one actionable line
  (add key to v1/.env / verify with doctor / or use --golden), exit 2. No
  traceback, no misleading cache talk.
- env.py: missing_credentials()/credentials_present() — provider-aware (Anthropic
  key OR full Azure set), and the .env.example placeholder (sk-ant-...) counts as
  missing so a freshly-seeded .env fails cleanly.
- llm.py: wrap the provider calls so any auth/network SDK error becomes a clean
  LLMError with the real fix; offline-mode messages now say it's cache-only
  (DISCOVERY_OFFLINE) and how to go live.

Cross-platform + single source of truth:
- tasks.py (new, stdlib-only): `python tasks.py setup|run|live|console|…` works on
  Mac/Linux/Windows. Strips a stray VIRTUAL_ENV before every uv call (the "does
  not match .venv" warning), uses arg-list subprocess + webbrowser (space- and
  OS-safe), and prereq-checks uv/npm with install hints.
- Makefile: now a thin wrapper that forwards each target to tasks.py, so make
  (Mac/Linux) and tasks.py (Windows) run identical logic.
- README: Windows quickstart + a note that live preflights credentials.

Tests: +tests/test_env.py (8 cases: provider matrix, placeholder, load_env). Suite
248 passed, 100% branch coverage held, pyrefly clean (incl. tasks.py).
@anmolg1997 anmolg1997 changed the title Root Makefile: one-command setup & run for first-timers First-run setup: credential preflight, cross-platform runner, Makefile Jun 4, 2026
…reflight

The engine README still led with a bare live `uv run python run.py --domain o2c`
(needs a key) as the first thing to run — exactly what tripped the fresh-clone
setup. Update it to match the root README:
- point at `make run` / `python tasks.py run` from the root as the easy path,
- lead Usage with the offline `--golden` demo (no key, no cost),
- mark .env / doctor as live-only,
- add the credential-preflight + gitignored-cache note.
@anmolg1997
anmolg1997 merged commit 5f0a62f into main Jun 4, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant