PREFIX ?= $(HOME)/.local
BIN    := $(PREFIX)/bin/opencode-sandbox

.PHONY: help install uninstall plugins lint

help:
	@echo "make install     link bin/opencode-sandbox into $(PREFIX)/bin and fetch plugins"
	@echo "make uninstall   remove the link"
	@echo "make plugins     fetch or update plugins (git submodules)"
	@echo "make lint        bash -n and shellcheck"

install: plugins
	@mkdir -p $(dir $(BIN))
	ln -sfn $(CURDIR)/bin/opencode-sandbox $(BIN)
	@echo "✓ $(BIN) → $(CURDIR)/bin/opencode-sandbox"
	@case ":$$PATH:" in *":$(PREFIX)/bin:"*) ;; *) echo "⚠ $(PREFIX)/bin is not in PATH";; esac

uninstall:
	rm -f $(BIN)

plugins:
	git submodule update --init --recursive

lint:
	@for f in bin/opencode-sandbox lib/*.sh egress/entrypoint.sh shim/xdg-open templates/project/hooks/*.example; do \
		bash -n $$f || exit 1; done
	@if command -v shellcheck >/dev/null; then \
		shellcheck -x bin/opencode-sandbox lib/*.sh egress/entrypoint.sh shim/xdg-open; \
	else echo "shellcheck not installed — syntax only"; fi
	@echo "✓ lint"
