# Flynn Makefile
# Self-hosted personal AI agent

.PHONY: build dev start stop restart status logs tui tui-fs tui-dev test test-run lint typecheck help daemon-start daemon-stop daemon-restart daemon-status daemon-logs enable disable

# Default target
.DEFAULT_GOAL := help

# Build and development
build: ## Compile TypeScript to dist/
	pnpm build

dev: ## Run daemon with watch mode
	pnpm dev

start: ## Start production build (foreground)
	node dist/cli/index.js start

# Systemd daemon management
daemon-start: ## Start the systemd service
	systemctl --user start flynn.service
	@echo "Flynn daemon started"

daemon-stop: ## Stop the systemd service
	systemctl --user stop flynn.service
	@echo "Flynn daemon stopped"

daemon-restart: ## Restart the systemd service
	systemctl --user restart flynn.service
	@echo "Flynn daemon restarted"

daemon-status: ## Check systemd service status
	systemctl --user status flynn.service

daemon-logs: ## Show systemd service logs
	journalctl --user -u flynn.service -f

enable: ## Enable Flynn to start on boot
	systemctl --user enable flynn.service
	@echo "Flynn enabled to start on boot"

disable: ## Disable Flynn from starting on boot
	systemctl --user disable flynn.service
	@echo "Flynn disabled from starting on boot"

# Aliases for convenience
stop: daemon-stop ## Alias for daemon-stop
restart: daemon-restart ## Alias for daemon-restart
status: daemon-status ## Alias for daemon-status
logs: daemon-logs ## Alias for daemon-logs

# TUI commands
tui: ## Run TUI in minimal mode (readline)
	pnpm tui

tui-fs: ## Run TUI in fullscreen mode (React/Ink)
	pnpm tui:fs

tui-dev: ## Run TUI with watch mode
	pnpm tui:dev

# Testing
test: ## Run tests in watch mode
	pnpm test

test-run: ## Run tests once (no watch)
	pnpm test:run

# Quality checks
lint: ## Run ESLint
	pnpm lint

typecheck: ## Run TypeScript compiler (no emit)
	pnpm typecheck

check: lint typecheck test-run ## Run all checks (lint, typecheck, test)

# Dependencies
install: ## Install dependencies
	pnpm install

# Utilities
help: ## Show this help message
	@echo "Flynn - Self-hosted personal AI agent"
	@echo ""
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "  \033[36m%-15s\033[0m %s\n", $$1, $$2}'
