.PHONY: help install format lint typecheck test test-fast test-fast-parallel test-resilience check clean

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

install: ## Install dependencies and dev tools using uv
	uv sync --extra dev

format: ## Auto-format Python code using ruff
	uv run ruff check --fix .
	uv run ruff format .

lint: ## Run ruff to check for linting errors
	uv run ruff check .

typecheck: ## Run mypy for strict type checking
	uv run mypy src/ tests/

sandbox-read-check: ## Ensure graph reads use read_graph_file_text (v1.9.9 security)
	uv run python scripts/check_graph_read_sandbox.py

test: ## Run the pytest suite (parallel via pytest-xdist)
	uv run pytest -n auto -q

test-fast: ## Fast local/release gate: no coverage, skip security soak hang
	uv run pytest -n auto --no-cov --ignore=tests/test_security_remediation.py -q

test-fast-parallel: ## test-fast with pytest-xdist (-n auto); daemon tests may flake
	uv run pytest -n auto --no-cov --ignore=tests/test_security_remediation.py -q

test-resilience: ## LLM JSON resilience + semantic cache tests (no coverage gate)
	uv run pytest -q tests/test_json_repair.py tests/test_llm_client_adaptive.py tests/test_semantic_cache_router.py --no-cov

perf: ## Run slow performance/memory tests (no coverage gate)
	uv run pytest -q -m slow tests/slow --no-cov

format-check: ## Verify formatting without modifying files
	uv run ruff format --check .

check: lint typecheck sandbox-read-check test ## Run linting, typechecking, sandbox read gate, and tests

ci: format-check lint typecheck sandbox-read-check test ## CI gate: format check + lint + types + sandbox + tests

clean: ## Remove python caches, virtual envs, and build artifacts
	rm -rf .venv/
	rm -rf .pytest_cache/
	rm -rf .mypy_cache/
	rm -rf .ruff_cache/
	find . -type d -name "__pycache__" -exec rm -rf {} +
