# Matches the JolaApps Python contract: `make lint` and `make test`.
VENV := .venv
PY   := $(VENV)/bin/python

.PHONY: help venv lint test test-py test-web build start run desktop release install-mac clean

help:
	@echo "make start       launch JolaCode desktop app"
	@echo "make install-mac install JolaCode.app into /Applications"
	@echo "make release     build standalone distribution archive"
	@echo "make test        run test suite (pytest + vitest)"
	@echo "make clean       remove build output and caches"

start:
	./start.sh desktop

run:
	./start.sh desktop

venv:
	python3 -m venv $(VENV)
	$(VENV)/bin/python3 -m pip install --upgrade pip
	$(VENV)/bin/python3 -m pip install -r requirements-dev.txt

lint:
	$(PY) -m compileall -q agent app.py scripts/mock-llm.py

test:
	$(PY) -m pytest tests/ -q
	cd web && npm test

# The Python half alone, for a fast loop while working on the agent.
test-py:
	$(PY) -m pytest tests/ -q

test-web:
	cd web && npm test

build:
	cd web && npm install --no-fund --no-audit && npm run build

# jcds.config is the single source of truth for ports; start.sh enforces that
# and this used to keep its own copy of the number, which is the drift the rule
# exists to prevent.
PORT = $(shell $(PY) -c "import json;print(json.load(open('jcds.config'))['ports']['dev'])")

serve:
	$(PY) -m uvicorn app:app --host 127.0.0.1 --port $(PORT)

desktop:
	./start.sh desktop

icons:
	python3 scripts/generate_icons.py

pack: build icons
	python3 scripts/build_app.py

release:
	./scripts/build_and_install_mac.sh --release

install-mac:
	./scripts/build_and_install_mac.sh

mock:
	python3 -u scripts/mock-llm.py --port 8080

clean:
	rm -rf web/dist .pytest_cache desktop/dist-desktop.noindex desktop/dist-desktop
	find . -name __pycache__ -type d -prune -exec rm -rf {} +


