# ops-warden development and install targets
ROOT := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
PHASE_MEMORY_REPO ?= $(abspath $(ROOT)/../phase-memory)

.DEFAULT_GOAL := help

.PHONY: help sync install install-warden install-memory install-all check-memory verify-memory test lint

help:
	@echo "ops-warden make targets"
	@echo ""
	@echo "  make sync            # uv sync (dev dependencies)"
	@echo "  make install         # install warden CLI (SSH only, no phase-memory)"
	@echo "  make install-memory  # reinstall warden with editable phase-memory"
	@echo "  make install-all     # sync + warden + phase-memory (recommended)"
	@echo "  make check-memory    # fail unless phase-memory is importable by warden"
	@echo "  make verify-memory   # check-memory + warden memory status"
	@echo "  make test            # unit tests"
	@echo "  make lint            # ruff check"
	@echo ""
	@echo "Override phase-memory path: make install-all PHASE_MEMORY_REPO=/path/to/phase-memory"

sync:
	uv sync

install-warden:
	uv tool install . --force

install-memory:
	@test -d "$(PHASE_MEMORY_REPO)" || (echo "ERROR: phase-memory not found at $(PHASE_MEMORY_REPO). Clone it or set PHASE_MEMORY_REPO."; exit 1)
	@test -f "$(PHASE_MEMORY_REPO)/pyproject.toml" || (echo "ERROR: $(PHASE_MEMORY_REPO) is not a phase-memory checkout."; exit 1)
	uv tool install . --with-editable "$(PHASE_MEMORY_REPO)" --force

install: install-warden

install-all: sync install-memory

check-memory:
	@warden memory status --json >/dev/null 2>&1 || (echo "ERROR: phase-memory is not available to warden. Run: make install-memory"; exit 1)
	@echo "phase-memory: ok (warden memory status succeeded)"

verify-memory: check-memory
	@warden memory status

test:
	PYTHONPATH=src:$(PHASE_MEMORY_REPO)/src uv run pytest

lint:
	uv run ruff check .