.PHONY: run dev serve cli runtime test-hello install sync clean help

# Run the Kiwi TUI application
run:
	uv run kiwi

# Run the Kiwi TUI application in development mode (with live reload and debugging)
dev:
	uv run --dev kiwi

# Serve the Kiwi TUI in the browser via textual serve (e.g. make serve PORT=8566)
serve:
	uv run textual serve --port $(or $(PORT),8566) -c "python -m kiwi_tui.main"

# Run the Kiwi CLI
cli:
	uv run kiwicli

# Run the Kiwi Runtime agent (pass ARGS, e.g. make runtime ARGS="connect --server app")
runtime:
	uv run kiwi-runtime $(ARGS)

# Test the hello API connection
test-hello:
	uv run python test_hello.py

# Install/sync dependencies
install:
	uv sync

# Sync dependencies
sync:
	uv sync

# Clean up temporary files and caches
clean:
	find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
	find . -type f -name "*.pyc" -delete
	find . -type f -name "*.pyo" -delete
	find . -type f -name "*.log" -delete
	rm -rf .pytest_cache
	rm -rf .ruff_cache
	rm -rf dist/
	rm -rf build/
	rm -rf *.egg-info

# Build the package
build:
	uv build

# Show help
help:
	@echo "Kiwi Code - Makefile Commands"
	@echo ""
	@echo "Usage: make [command]"
	@echo ""
	@echo "Commands:"
	@echo "  run          - Run the Kiwi TUI application (kiwi)"
	@echo "  dev          - Run TUI in development mode (with live reload)"
	@echo "  serve        - Serve the TUI in the browser (PORT=8566 make serve)"
	@echo "  cli          - Run the Kiwi CLI (kiwicli)"
	@echo "  runtime      - Run the Kiwi Runtime agent (kiwi-runtime)"
	@echo "                 e.g. make runtime ARGS=\"connect --server app\""
	@echo "  test-hello   - Test connection to backend (hello API)"
	@echo "  install      - Install/sync project dependencies"
	@echo "  sync         - Sync dependencies"
	@echo "  build        - Build the package"
	@echo "  clean        - Clean up temporary files and caches"
	@echo "  help         - Show this help message"
