# ARCA development recipes — compatible with `just` command runner
# Install: cargo install just  or  pip install rust-just

default:
    @just --list

# ── Install ────────────────────────────────────────────────────────────────
install-dev:
    pip install -e ".[dev,all]"

install-cpp:
    pip install -e ".[cpp]"

install-viz:
    pip install -e ".[viz]"
    pip install dash-bootstrap-components

install-llm:
    pip install -e ".[all]"

# ── Testing ────────────────────────────────────────────────────────────────
test *args:
    python -m pytest tests/ -v --tb=short {{args}}

test-fast *args:
    python -m pytest tests/ -v --tb=short -m "not slow" {{args}}

test-cov *args:
    python -m pytest tests/ -v --tb=short --cov=arca --cov-report=html --cov-report=term {{args}}

test-unit *args:
    python -m pytest tests/ -v -m unit {{args}}

watch:
    python -m pytest tests/ -v --tb=short -f

# ── Linting & Formatting ───────────────────────────────────────────────────
lint:
    ruff check arca tests

format:
    ruff format arca tests
    ruff check --fix arca tests

typecheck:
    mypy arca --ignore-missing-imports

check-all: lint format typecheck test

# ── Security ───────────────────────────────────────────────────────────────
security:
    bandit -r arca -ll
    pip-audit

# ── Building ───────────────────────────────────────────────────────────────
build:
    rm -rf dist/ build/ *.egg-info arca_agent.egg-info
    python -m build

build-clean:
    rm -rf dist/ build/ *.egg-info arca_agent.egg-info

# ── Docker ──────────────────────────────────────────────────────────────────
docker-build:
    docker build -t arca-agent .

docker-build-cuda:
    docker build -f Dockerfile.cuda -t arca-agent:cuda .

docker-up:
    docker-compose up -d

docker-up-dashboard:
    docker-compose --profile dashboard up -d

docker-up-llm:
    docker-compose --profile llm up -d

docker-down:
    docker-compose down

docker-logs:
    docker-compose logs -f

# ── Quickstart ──────────────────────────────────────────────────────────────
quickstart:
    arca init-network --output my_net.yaml --preset office
    arca simulate my_net.yaml --mode audit --visualize
    arca dashboard --network my_net.yaml

demo-train:
    arca train --preset small_office --timesteps 10000 --save models/demo

demo-audit:
    arca audit --preset small_office --model models/demo.zip --langgraph

demo-live:
    @echo "WARNING: Only run on networks you own!"
    @echo "Usage: just demo-live CIDR=192.168.1.0/24"
    arca live-audit {{CIDR}} --dry-run --fingerprints

demo-serve:
    arca serve --host 127.0.0.1 --port 8000

demo-dashboard:
    arca dashboard --preset small_office --port 8051

demo-full: quickstart demo-train demo-audit

# ── Development ─────────────────────────────────────────────────────────────
repl:
    arca repl 2>/dev/null || python -c "from arca import *; print('ARCA loaded'); import IPython; IPython.embed()"

clean:
    rm -rf arca_outputs/ .pytest_cache/ .ruff_cache/ .mypy_cache/ __pycache__/ */__pycache__/ */*/__pycache__/ */*/*/__pycache__/
    find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
    find . -type f -name '*.pyc' -delete 2>/dev/null || true

nuke: clean build-clean
    rm -rf ~/.arca/

# ── Documentation ───────────────────────────────────────────────────────────
docs-serve:
    mkdocs serve

docs-build:
    mkdocs build

docs-deploy:
    mkdocs gh-deploy

# ── Pre-commit ──────────────────────────────────────────────────────────────
pre-commit-install:
    pre-commit install

pre-commit-run:
    pre-commit run --all-files

# ── Version bumping ─────────────────────────────────────────────────────────
bump-patch:
    @echo "Update arca/__version__.py and pyproject.toml manually for patch release"

bump-minor:
    @echo "Update arca/__version__.py and pyproject.toml manually for minor release"

# ── CI simulation ───────────────────────────────────────────────────────────
ci: lint typecheck test security
    @echo "All CI checks passed!"
