.PHONY: tui gentui tui-debug tui-test web install stop

install:
	uv pip install fastapi uvicorn textual httpx tree-sitter-markdown tree-sitter-python tree-sitter-java tree-sitter-cpp tree-sitter-rust tree-sitter-go tree-sitter-javascript tree-sitter-typescript tree-sitter-c-sharp tree-sitter-html
	devbox run -- bash -c "cd frontend && npm install"

stop:
	@lsof -t -i:8000 | xargs -r kill -9 > /dev/null 2>&1 || true

tui:
	@echo "Starting TactiTerm TUI..."
	@export PYTHONPATH=. && uv run python3 src/tui/app.py

gentui:
	@echo "Starting GenTUI Challenge Generator..."
	@export PYTHONPATH=. && uv run python3 src/tui/gen_app.py

tui-debug:
	@echo "Starting TUI in Debug Mode..."
	@export PYTHONPATH=. && uv run python3 src/tui/app.py --debug

tui-test:
	@export PYTHONPATH=. && uv run python3 src/tui/app.py --test

web:
	@echo "Stopping any existing backend..."
	@make stop
	@echo "Starting Web..."
	@export PYTHONPATH=. && uv run python3 src/api/main.py &
	@sleep 3
	@devbox run -- bash -c "cd frontend && npm run dev"

