# Makefile with phony targets

.PHONY: setup lint format setup-hooks services release
# OS := $(shell uname)

.ONESHELL:
SHELL := /opt/homebrew/bin/fish
# .SHELLFLAGS += -e
setup : ## Setup Environment
	uv sync

setup-ci: ## Setup the environment for CI
	uv sync

test: ## test
	@ENVIRONMENT=test python run pytest

lint: ## Lint Python Files
	uv run ruff check
	# pyright

format: ## Format Python Files
	uv run ruff format
	uv run ruff check --fix --unsafe-fixes

install: ## Install dependencies
	uv sync


build: ## Build the project
	@hatch build

help: ## show help message
	@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n  make \033[36m\033[0m\n"} /^[$$()% a-zA-Z_-]+:.*?##/ { printf "  \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
BUMP ?= patch

release: ## Bump version (BUMP=patch|minor|major) and commit
	set -l new_version (uv run python -c "\
import re, sys; \
f = 'src/primitive/__about__.py'; \
txt = open(f).read(); \
m = re.search(r'__version__ = \"(\d+)\.(\d+)\.(\d+)\"', txt); \
parts = [int(m.group(i)) for i in (1,2,3)]; \
bump = '$(BUMP)'; \
idx = {'major':0,'minor':1,'patch':2}.get(bump); \
assert idx is not None, f'Invalid BUMP={bump}. Use patch, minor, or major'; \
parts[idx] += 1; \
parts[idx+1:] = [0]*(2-idx); \
v = '.'.join(map(str, parts)); \
open(f,'w').write(txt[:m.start()] + f'__version__ = \"{v}\"' + txt[m.end():]); \
print(v)")
	and git add src/primitive/__about__.py
	and git commit -m "Bump version to $$new_version"
	and echo "Version bumped to $$new_version"
	and echo "Next: merge to main and CI will create the tag + release"

AGENT_TOOLING_DIR ?= ../agent-tooling
PROJECT_TYPE      ?= cli

.PHONY: claude-setup
claude-setup: ## Copy shared Claude tools into .claude/
	bash $(AGENT_TOOLING_DIR)/setup.sh $(AGENT_TOOLING_DIR) $(PROJECT_TYPE)
