# ai-sandbox -- development tasks. Everything runs with the tools already on this
# machine plus podman; nothing needs to be installed system-wide.
SHELL := /bin/bash
BIN   := bin/ai-sandbox
BINS  := bin/ai-sandbox bin/ai-sandbox-autophase
SHELLCHECK_IMAGE := docker.io/koalaman/shellcheck:stable

.PHONY: help test e2e check lint style doctor build clean-demo all
help: ## show this help
	@grep -hE '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) | awk -F':.*?## ' '{printf "  %-12s %s\n", $$1, $$2}'


test: ## unit tests only (no containers, no network)
	./tests/run.sh

e2e: ## everything, including real containers and real egress tests
	./tests/run.sh --e2e

check: lint test ## lint + unit tests (what CI would run)

lint: ## shellcheck every shell file, in a container (nothing installed locally)
	@podman run --rm -v "$(CURDIR):/src:ro,z" -w /src $(SHELLCHECK_IMAGE) \
	  --severity=warning --shell=bash --exclude=SC1091 \
	  $(BINS) install.sh contrib/ai-sandbox.bash \
	  tests/run.sh tests/lib.sh tests/spike_network.sh \
	  $$(ls tests/unit/*.sh tests/e2e/*.sh tests/fixtures/*.sh tests/fixtures/phase-lib/*.sh) \
	  && echo "shellcheck: clean"

style: ## bash-style syntax check of every shell file (fast, no deps)
	@for f in $(BINS) install.sh contrib/*.bash tests/*.sh tests/unit/*.sh tests/e2e/*.sh \
	          tests/fixtures/*.sh tests/fixtures/phase-lib/*.sh; do \
	  [ -f "$$f" ] || continue; bash -n "$$f" || exit 1; \
	done; echo "bash -n: clean"

doctor: ## verify this machine can run the sandbox
	@$(BIN) doctor

build: ## build the sandbox and gate images
	@$(BIN) build --gate

clean-demo: ## remove sandbox containers, gates and stale session files
	@$(BIN) clean --all
