# Context Vault — developer tasks.  Run `make` (or `make help`) to list targets.
.DEFAULT_GOAL := help
DIAGRAMS_DIR := docs/diagrams

.PHONY: help diagrams diagrams-check diagrams-install hooks test harness-validate harness-install bench verify sandbox deploy

help: ## list available targets
	@grep -hE '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) \
		| awk 'BEGIN{FS=":.*?## "}{printf "  \033[36m%-18s\033[0m %s\n", $$1, $$2}'

diagrams: ## render §17 SVG + PNG from docs/SYSTEM_DESIGN.md (needs system Chrome)
	python3 $(DIAGRAMS_DIR)/render.py

diagrams-check: ## verify committed diagrams are in sync (browser-free; CI / pre-commit)
	python3 $(DIAGRAMS_DIR)/render.py --check

diagrams-install: ## install the mermaid CLI locally (reuses system Chrome, no Chromium dl)
	cd $(DIAGRAMS_DIR) && PUPPETEER_SKIP_DOWNLOAD=true npm install --no-fund --no-audit

hooks: ## activate committed git hooks (pre-commit auto-refreshes §17 diagrams)
	@git rev-parse --is-inside-work-tree >/dev/null 2>&1 || { \
		echo "not a git repository yet — run 'git init' first, then 'make hooks'"; exit 1; }
	git config core.hooksPath scripts/git-hooks
	@echo "git hooks active → scripts/git-hooks (pre-commit refreshes §17 diagrams)"

test: ## run the python test suite
	uv run --extra dev pytest -q

harness-validate: ## validate the dev-team harness (agents/commands/skills/rules/hooks well-formed + wired)
	python3 scripts/ci/validate_harness.py

harness-install: ## wire the harness into Claude Code (.claude/{agents,commands,skills} → the root catalog)
	@for d in agents commands skills; do rm -rf ".claude/$$d"; ln -s "../$$d" ".claude/$$d"; done
	@echo "harness wired → .claude/{agents,commands,skills}; Claude Code loads the agents/skills/commands next session"

bench: ## silent-corruption backstop (offline heuristic judge, the make-or-break metric)
	uv run python eval/bench.py --subject heuristic --gold core \
		--max-silent-corruption 0.30 --min-accuracy 0.45

sandbox: ## seed an ephemeral evaluation sandbox (synthetic data) into the local stack
	uv run python eval/seed_sandbox.py

deploy: ## one-command self-host: generate secrets (first run) + bring up the production stack
	./scripts/deploy.sh

verify: ## the one-shot green check: harness + tests + diagrams + bench backstop
	@echo "==> harness" && $(MAKE) -s harness-validate
	@echo "==> diagrams" && $(MAKE) -s diagrams-check
	@echo "==> tests" && uv run --extra dev pytest -q
	@echo "==> bench (heuristic backstop)" && $(MAKE) -s bench
	@echo "verify: all checks passed"
