.DEFAULT_GOAL := help

.PHONY: help install env build test run dev roundtrip pull clean

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

node_modules: package.json package-lock.json
	npm ci
	@touch node_modules

install: node_modules ## Install dependencies (npm ci)

env: ## Create .env from the template if missing
	@test -f .env || cp .env.example .env

build: install ## Compile TypeScript to build/
	npm run build

test: install ## Run the test suite
	npm test

run: build ## Build and run the app
	node build/index.js

dev: install ## Run in watch mode (tsx)
	npm run dev

roundtrip: build ## Run the offline round-trip idempotency harness (SPEC §11)
	npm run roundtrip

pull: build ## Mirror the configured Docmost space into the vault (read-only)
	npm run pull

clean: ## Remove build artifacts and node_modules (incl. the workspace lib)
	rm -rf build node_modules packages/*/dist
