ROOT_DIR := $(shell pwd)
PYTHON ?= python3

.PHONY: help install uninstall sync-skill test

help:
	@echo "Usage: make [target]"
	@echo ""
	@echo "  install     Install mytoolkit in editable mode (current Python) and sync skill"
	@echo "  sync-skill  Copy the bundled agent skill to ~/.agents/skills/mytoolkit/"
	@echo "  test        Run the pytest suite"
	@echo "  uninstall   Uninstall mytoolkit and remove shell completions"

install:
	$(PYTHON) -m pip install -e "$(ROOT_DIR)" --upgrade
	@echo "Installing shell completions…"
	@mytoolkit completion install || echo "Warning: completion install failed"
	@$(MAKE) -s sync-skill

sync-skill:
	@echo "Syncing agent skill to ~/.agents/skills/mytoolkit/ ..."
	@mkdir -p "$(HOME)/.agents/skills"
	@if command -v rsync >/dev/null 2>&1; then \
		rsync -av --delete "$(ROOT_DIR)/.agents/skills/mytoolkit/" "$(HOME)/.agents/skills/mytoolkit/"; \
	else \
		rm -rf "$(HOME)/.agents/skills/mytoolkit"; \
		cp -R "$(ROOT_DIR)/.agents/skills/mytoolkit" "$(HOME)/.agents/skills/mytoolkit"; \
	fi

uninstall:
	@mytoolkit uninstall || $(PYTHON) -m pip uninstall mytoolkit -y

test:
	@cd "$(ROOT_DIR)" && \
	if command -v uv >/dev/null 2>&1; then \
		uv run pytest tests/ -q; \
	else \
		$(PYTHON) -m pytest tests/ -q; \
	fi
