# ATLAS — build, lint, test, release.
#
# Most one-time-per-machine setup lives in `make bootstrap`. Day-to-day:
#
#   make build         # rebuild React frontend + copy into src/atlas/dash/static
#   make wheel         # build the pipx-installable wheel
#   make binary        # PyInstaller one-file binary in dist/atlas
#   make release       # full chain: build + wheel + binary
#   make smoke         # run the regression smoke test
#   make clean         # nuke build artifacts
#
# `release` is what GitHub Actions runs on tag push — see .github/workflows/.

PYTHON ?= python3
PIP    ?= $(PYTHON) -m pip

.PHONY: bootstrap build wheel binary release smoke clean install dev


bootstrap:
	$(PIP) install --upgrade pip
	$(PIP) install -e '.[dev]' pyinstaller
	cd apps/web && npm install


# Build the React frontend, then copy the bundle into the Python package so the
# wheel + PyInstaller binary both include it.
build:
	cd apps/web && npm run build
	rm -rf src/atlas/dash/static
	mkdir -p src/atlas/dash/static
	cp -R apps/web/dist/. src/atlas/dash/static/


wheel: build
	$(PIP) install --upgrade build
	$(PYTHON) -m build --wheel
	@echo
	@echo "wheel in dist/:"
	@ls -lh dist/*.whl


# Single-file standalone binary. The shipped spec pulls in every provider
# SDK (anthropic, openai), the FastAPI stack, prompt_toolkit, and the React
# bundle. Output: dist/atlas (macOS / linux) or dist/atlas.exe (Windows).
binary: build
	$(PIP) install pyinstaller >/dev/null
	pyinstaller --noconfirm packaging/atlas.spec
	@echo
	@echo "binary at:"
	@ls -lh dist/atlas* 2>/dev/null || echo "  (build failed?)"


release: build wheel binary
	@echo
	@echo "release artifacts:"
	@ls -lh dist/


# Quick health check: install -e, run a few subcommands, verify they don't
# regress. Used in CI as the post-build sanity gate.
smoke:
	$(PIP) install -e . >/dev/null
	atlas version
	atlas init
	atlas workspace ls
	atlas project ls
	printf 'hi\n/quit\n' | ATLAS_PROVIDER=mock atlas


clean:
	rm -rf dist build src/*.egg-info
	rm -rf src/atlas/dash/static
	rm -rf apps/web/dist


install:
	pipx install -e . --force


dev:
	./app dev
