# Copyright (c) 2026 Philippe Charrière — Sidekicks Source-Available License 1.0, see LICENSE
#
# Single entry point for the project's commands. `make help` lists them.
# Building and packaging delegate to the Wails Taskfile through the wails3 CLI.

GOLANGCI_LINT := go tool -modfile=tools/go.mod golangci-lint
PNPM := pnpm --dir frontend

.PHONY: help install bindings frontend dev build package install-test-config \
	check test test-go test-frontend test-scripts test-real \
	lint lint-go lint-frontend lint-headers bindings-check

help: ## List the available targets
	@grep -E '^[a-z-]+:.*## ' $(MAKEFILE_LIST) | awk -F':.*## ' '{printf "  %-16s %s\n", $$1, $$2}'

# ---------------------------------------------------------------- build

install: ## Install the frontend dependencies (pnpm, both macOS and Linux binaries)
	@$(PNPM) install

bindings: ## Regenerate the TypeScript bindings of the Go services and events
	@wails3 generate bindings -clean=true -ts -i

frontend: install ## Build the frontend into frontend/dist (embedded in the binary)
	@$(PNPM) run build

# go build / go test need frontend/dist to embed: build it once if missing.
frontend/dist/index.html:
	@$(MAKE) --no-print-directory frontend

dev: ## Run the application with hot reload
	@wails3 dev

build: ## Build the application into bin/
	@wails3 build

package: ## Package the application (macOS: bin/sidekicks.app)
	@wails3 package

install-test-config: ## Write the test agents configuration at the default location (absolute paths)
	@scripts/install-test-config.sh

# ---------------------------------------------------------------- tests

check: lint test ## Everything the CI runs: lint, then all the tests

test: test-go test-frontend test-scripts ## Run all the tests (no real agent, no network)

test-go: frontend/dist/index.html ## Go unit tests
	@go test ./...

test-frontend: ## Frontend unit tests (vitest)
	@$(PNPM) test

test-scripts: ## Tests of the shell tooling
	@scripts/agents_test.sh
	@scripts/check-license-headers_test.sh

test-real: ## Tests against the real mm agents (needs mm and llmman; 2 agents at most)
	@go test -tags realagents -count=1 ./...

# ---------------------------------------------------------------- lint

lint: lint-go lint-frontend lint-headers ## Run every linter

lint-go: frontend/dist/index.html ## golangci-lint (version pinned in tools/go.mod)
	@$(GOLANGCI_LINT) run ./...

lint-frontend: ## svelte-check (types and Svelte warnings)
	@$(PNPM) run check

lint-headers: ## Check the licence header of every source file
	@scripts/check-license-headers.sh

bindings-check: bindings ## Fail when the committed bindings are not up to date
	@git diff --exit-code -- frontend/bindings
