-include .env
export

.PHONY: install test lint typecheck start help

UV ?= $(shell command -v uv 2>/dev/null || if [ -x "$$HOME/.local/bin/uv" ]; then printf "%s" "$$HOME/.local/bin/uv"; else printf "%s" "uv"; fi)

LLM_CONNECT_HOST ?= 127.0.0.1
LLM_CONNECT_PORT ?= 8080
LLM_CONNECT_PROVIDER ?= mock
LLM_CONNECT_MODEL ?=
SERVER_ARGS ?=

install:  ## Install dependencies (dev group)
	$(UV) sync --group dev

test:  ## Run test suite
	$(UV) run pytest

lint:  ## Run ruff linter
	$(UV) run ruff check .

typecheck:  ## Run mypy type checker
	$(UV) run mypy llm_connect

start:  ## Start llm-connect HTTP server (reads .env and LLM_CONNECT_* overrides)
	$(UV) run python -m llm_connect.server \
		--host $(LLM_CONNECT_HOST) \
		--port $(LLM_CONNECT_PORT) \
		--provider $(LLM_CONNECT_PROVIDER) \
		$(if $(LLM_CONNECT_MODEL),--model $(LLM_CONNECT_MODEL),) \
		$(SERVER_ARGS)

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