.PHONY: bootstrap up down migrate mcp-chat mcp-chat-long lint types test e2e verify verify-all demo cli-image

bootstrap:
	cp -n .env.example .env || true
	@if grep -q '^GREFT_JWT_PRIVATE_KEY=$$' .env; then \
		KEY=$$(python -c "from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey; from cryptography.hazmat.primitives.serialization import Encoding, PrivateFormat, NoEncryption; import base64; k = Ed25519PrivateKey.generate(); print(base64.b64encode(k.private_bytes(Encoding.PEM, PrivateFormat.PKCS8, NoEncryption())).decode())"); \
		sed -i "s|^GREFT_JWT_PRIVATE_KEY=$$|GREFT_JWT_PRIVATE_KEY=$$KEY|" .env; \
		echo "Generated GREFT_JWT_PRIVATE_KEY and wrote it to .env"; \
	else \
		echo "GREFT_JWT_PRIVATE_KEY already set in .env"; \
	fi
	uv sync

up:
	docker compose up -d --wait

down:
	docker compose down

migrate:
	docker compose exec relay /app/.venv/bin/alembic upgrade head

mcp-chat:
	docker compose exec relay /app/.venv/bin/python examples/two-agent-mcp/continuous.py

mcp-chat-long:
	docker compose exec relay /app/.venv/bin/python examples/two-agent-mcp/continuous.py --turns 100 --delay 0.5

lint:
	uv run ruff check .
	uv run ruff format --check .

types:
	uv run mypy --strict server/ protocol/ sdk/ cli/ adapters/

test:
	uv run pytest tests/unit tests/integration -q --tb=short

e2e:
	uv run pytest tests/e2e -q --tb=short

verify: down
	docker compose down -v
	$(MAKE) up
	$(MAKE) migrate
	$(MAKE) lint
	$(MAKE) types
	$(MAKE) test
	$(MAKE) e2e
	@echo "VERIFY COMPLETE"

verify-all: verify
	@echo "VERIFY-ALL COMPLETE (all checks passed)"

demo:
	uv run python examples/two-agent-handoff/main.py

cli-image:
	docker build -t greft-cli .
