.PHONY: all build install setup run-server run-cli test clean

all: build

# Initial setup (creates venv in ~/.config/syui/ai/shell)
setup:
	@./scripts/setup.sh

# Build Rust CLI
build:
	cargo build --release

# Run MCP server (after setup)
run-server:
	@if [ ! -d "$$HOME/.config/syui/ai/shell/venv" ]; then \
		echo "Please run 'make setup' first"; \
		exit 1; \
	fi
	@$$HOME/.config/syui/ai/shell/bin/mcp-server

# Run CLI in development mode
run-cli:
	cargo run

# Run aishell (after setup)
run:
	@if [ ! -d "$$HOME/.config/syui/ai/shell/venv" ]; then \
		echo "Please run 'make setup' first"; \
		exit 1; \
	fi
	@$$HOME/.config/syui/ai/shell/bin/aishell

# Run tests
test:
	cargo test
	@if [ -d "$$HOME/.config/syui/ai/shell/venv" ]; then \
		source $$HOME/.config/syui/ai/shell/venv/bin/activate && python -m pytest tests/; \
	fi

# Clean build artifacts
clean:
	cargo clean
	find . -type d -name __pycache__ -exec rm -rf {} +
	find . -type f -name "*.pyc" -delete

# Remove all installed files (complete uninstall)
uninstall:
	rm -rf $$HOME/.config/syui/ai/shell
	@echo "ai.shell has been uninstalled"