.PHONY: install run test lint fmt live eval seed refresh-catalog harness-demo harness-live harness-test harness tui-install tui-test tui-check tui-build tui tui-dev

install:
	uv sync --extra dev   # dev pulls server + harness + tui for the full test suite

run:
	uv run --extra server uvicorn minima.main:app --reload --host $${MINIMA_HOST:-0.0.0.0} --port $${MINIMA_PORT:-8080}

test:
	uv run pytest -m "not live and not eval" -q

lint:
	uv run ruff check src client_sdk tests
	uv run mypy src/minima

fmt:
	uv run ruff check --fix src client_sdk tests
	uv run ruff format src client_sdk tests

live:
	uv run pytest -m live -q

eval:
	uv run pytest -m eval -q

seed:
	uv run minima-seed --limit $${LIMIT:-2000} --lane $${LANE:-minima:default}

# --- minima_harness convenience targets (creds live in gitignored .env.harness) ---

harness-demo:
	uv run python examples/harness_warmup.py

harness-live:
	uv run --env-file .env.harness python examples/harness_warmup.py --live --rounds $${ROUNDS:-1}

harness-test:
	uv run --env-file .env.harness pytest tests/harness -m live -v

harness:
	uv run --extra harness --extra tui --env-file .env.harness minima-harness $(ARGS)

# --- TS TUI (packages/tui) — run from the repo root so .env.harness auto-loads --------

TUI := packages/tui
TUI_BIN := $(TUI)/dist/minima

tui-install:
	cd $(TUI) && bun install

tui-test:
	cd $(TUI) && bun test

tui-check:
	cd $(TUI) && bun run check && bun run lint

tui-build:
	cd $(TUI) && bun run build

# Run the compiled binary (build first with `make tui-build`). Passes ARGS through, so:
#   make tui ARGS='-p "hello"'          # one-shot
#   make tui ARGS='--offline --model gpt-4o-mini -p "hi"'
#   make tui                             # interactive TUI
tui:
	@test -x $(TUI_BIN) || { echo "Run 'make tui-build' first"; exit 1; }
	./$(TUI_BIN) $(ARGS)

# Run from source via Bun (no compile step) — fastest dev loop.
tui-dev:
	cd $(TUI) && bun run src/cli/main.ts $(ARGS)
