.DEFAULT_GOAL := help
.PHONY: help sync format lint typecheck test check build clean publish

help: ## Show this help
	@grep -E '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "  %-12s %s\n", $$1, $$2}'

sync: ## Install all dependencies and extras
	uv sync --all-extras

format: ## Format code (ruff)
	uv run ruff format .

lint: ## Lint code, auto-fixing what it can (ruff)
	uv run ruff check . --fix

typecheck: ## Type-check (pyrefly)
	uv run pyrefly check

test: ## Run the test suite with the coverage gate
	uv run pytest

check: format lint typecheck test ## Run the full CI fix order

build: clean ## Build sdist and wheel into dist/
	uv build

clean: ## Remove build artifacts
	rm -rf dist build

publish: check build ## Publish to PyPI using the UV_PUBLISH_TOKEN environment variable
	@test -n "$$UV_PUBLISH_TOKEN" || { echo "UV_PUBLISH_TOKEN is not set" >&2; exit 1; }
	uv publish dist/*
