# Avatar MCP Server - Octopize
#
# Privacy-preserving data anonymization and augmentation via MCP protocol

# Show available commands (default recipe)
default:
    @echo "🐙 Octopize Avatar MCP Server"
    @echo ""
    @echo "📦 Setup:"
    @echo "  just install          # Install dependencies"
    @echo "  just compile          # Compile Python bytecode"
    @echo ""
    @echo "🚀 Server:"
    @echo "  just start            # Start server (port 8081)"
    @echo "  just start 3000       # Start on custom port"
    @echo ""
    @echo "🤖 CLI (for LLM agents):"
    @echo "  just cli anonymize <file> -o <out>  # Anonymize data"
    @echo "  just cli augment <file> -o <out> -s minority --target col"
    @echo "  just cli info <file>                # Inspect file"
    @echo ""
    @echo "🧪 Testing:"
    @echo "  just test             # Run all tests (184 tests)"
    @echo "  just test-unit        # Unit tests only"
    @echo "  just test-integration # Integration tests only"
    @echo "  just lci              # Full CI (lint + typecheck + test)"
    @echo ""
    @echo "🔧 Quality:"
    @echo "  just lint             # Check code style"
    @echo "  just lint-fix         # Auto-fix issues"
    @echo "  just typecheck        # Type checking"
    @echo ""
    @echo "🧹 Cleanup:"
    @echo "  just clean            # Remove caches"
    @echo "  just clean-all        # Deep clean (inc. .venv)"

# Compile Python bytecode for optimal performance
compile:
    @echo "⚙️  Compiling Python bytecode..."
    @uv run python -m compileall -q src/ 2>/dev/null || true
    @echo "✅ Compilation complete"

# Start the Avatar MCP server (HTTP mode)
start port="8081": compile
    @echo "🚀 Starting server on port {{port}}..."
    PYTHONPATH=. uv run python src/server.py --http {{port}}

# Run CLI commands (e.g., just cli anonymize data.csv -o out.csv)
cli *args: compile
    PYTHONPATH=. uv run python -m src.cli {{args}}

# Install dependencies
install:
    uv sync

# Run all tests
test:
    uv run pytest tests/ -v

# Run unit tests only
test-unit:
    uv run pytest tests/unit/ -v

# Run integration tests only
test-integration:
    uv run pytest tests/integration/ -v

# Check code style
lint:
    uv run ruff check src/ tests/

# Auto-fix linting issues
lint-fix:
    uv run ruff check --fix src/ tests/
    uv run ruff format src/ tests/

# Type check with mypy
typecheck:
    uv run mypy src/ --ignore-missing-imports

# Run full local CI
lci:
    @echo "🔄 Running Local CI..."
    @just lint
    @just typecheck
    @just test
    @echo "✅ All checks passed!"

# Build the package (wheel + sdist)
build:
    uv build

# Check the package with twine
check: build
    uv run twine check dist/*

# Publish the package to PyPI
publish: check
    #!/usr/bin/env bash
    set -euo pipefail
    if [ -n "${UV_PUBLISH_TOKEN:-}" ]; then
        uv publish --token "$UV_PUBLISH_TOKEN"
    else
        uv publish
    fi

# Clean up temporary files
clean:
    rm -rf .pytest_cache .mypy_cache .ruff_cache __pycache__
    find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
    find . -type f -name "*.pyc" -delete 2>/dev/null || true
    rm -rf /tmp/avatar-mcp

# Deep clean including virtual environment
clean-all: clean
    rm -rf .venv
    @echo "🧹 Clean complete. Run 'just install' to reinstall."
