Debian Codegraph @

Makefile

raw
1 VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
2 LATEST_TAG ?= $(shell git tag -l '[0-9]*' --sort=-v:refname | head -1)
3 LDFLAGS := -s -w -X main.version=$(VERSION)
4 HUGO ?= $(or $(shell command -v hugo 2>/dev/null),$(shell go env GOPATH)/bin/hugo)
5 PANDOC ?= pandoc
6 CLANKERVAL_PINNED_VERSION := 0.4.5
7 CLANKERVAL_BINARY ?= $(CURDIR)/scripts/eval-clnkr-openai
8 CLNKR_ARGS ?=
9 CLNKR_RUN_CWD ?=
10 CLANKERVAL_PREFLIGHT = \
11 clankerval_path="$$(command -v clankerval 2>/dev/null || true)"; \
12 if [ -z "$$clankerval_path" ]; then \
13 echo "error: expected clankerval $(CLANKERVAL_PINNED_VERSION) in PATH." >&2; \
14 exit 1; \
15 fi; \
16 if ! version_output="$$("$$clankerval_path" --version 2>&1)"; then \
17 echo "error: clankerval --version failed: $$version_output" >&2; \
18 exit 1; \
19 fi; \
20 if [ "$$version_output" != "clankerval $(CLANKERVAL_PINNED_VERSION)" ]; then \
21 echo "error: expected 'clankerval $(CLANKERVAL_PINNED_VERSION)' from 'clankerval --version', got '$$version_output'" >&2; \
22 echo "download it from https://github.com/clnkr-ai/clankerval/releases" >&2; \
23 exit 1; \
24 fi; \
25
26 .DEFAULT_GOAL := build
27 .PHONY: \
28 build clean install run \
29 clnkr send readme-image \
30 check test evaluations evaluations-live evaluations-live-openai evaluations-live-anthropic \
31 thoth-critical-check architecture-shape-report semantic-cohesion-report test-fidelity-report \
32 help man docs docs-serve \
33 _build-clnkr _build-clnkrd \
34 _fmt _fmt-check _vet _lint _arch _script-tests sloc frontend-sloc _workflow-make-targets \
35 _hooks _check-docs _require-run-clnkr-tools _require-pandoc _require-readme-image-tools _site-sync _site-build
36
37 PREFIX ?= /usr/local
38 CORE_SLOC_LIMIT := 2450
39 FRONTEND_SLOC_LIMIT := 2650
40 DOC_MAN_DIR := build/docs/man
41 DOC_MAN_OUTPUTS := $(DOC_MAN_DIR)/clnkr.1 $(DOC_MAN_DIR)/clnkrd.1 $(DOC_MAN_DIR)/clnkr.3 $(DOC_MAN_DIR)/clnkr.7
42 DOC_CONTENT_DIR := site/content/docs
43 DOC_PAGE_TEMPLATE := site/pandoc/doc-page.md
44 README_IMAGE := site/static/readme-terminal.png
45 README_FONT_REPO ?= [email protected]:cosgroveb/berkeley-mono-nerd-font.git
46 README_FONT_CHECKOUT := build/deps/berkeley-mono-nerd-font
47 README_FONT := build/readme-fonts/BerkeleyMonoNerdFont-Regular.otf
48 README_FONT_PATCH_LOG := build/readme-fonts/font-patcher.log
49 GENERATED_SITE_DOCS := \
50 $(DOC_CONTENT_DIR)/clnkr.md \
51 $(DOC_CONTENT_DIR)/clnkrd.md
52
53 ##@ Build
54 build: _build-clnkr _build-clnkrd ## Build shipped binaries
55
56 clean: ## Remove build artifacts
57 rm -f clnkr clnkrd
58 rm -rf build/docs
59 rm -rf build/deps build/readme-fonts
60 find "$(DOC_CONTENT_DIR)" -maxdepth 1 -type f ! -name '_index.md' -delete
61
62 install: build ## Install shipped binaries
63 install -d $(DESTDIR)$(PREFIX)/bin
64 install -m 755 clnkr $(DESTDIR)$(PREFIX)/bin/clnkr
65 install -m 755 clnkrd $(DESTDIR)$(PREFIX)/bin/clnkrd
66
67 run: _build-clnkr ## Build and start the CLI
68 ./clnkr
69
70 clnkr: _build-clnkr _require-run-clnkr-tools ## Build and start the human clnkr wrapper
71 CLNKR_RUN_CWD="$(CLNKR_RUN_CWD)" ./scripts/run-clnkr.sh --clnkr-bin "$(CURDIR)/clnkr" -- $(CLNKR_ARGS)
72
73 send: _build-clnkr _require-run-clnkr-tools ## Build and start the human clnkr wrapper with --full-send
74 CLNKR_RUN_CWD="$(CLNKR_RUN_CWD)" ./scripts/run-clnkr.sh --clnkr-bin "$(CURDIR)/clnkr" -- --full-send $(CLNKR_ARGS)
75
76 _build-clnkr:
77 go build -trimpath -ldflags '$(LDFLAGS)' -o clnkr ./cmd/clnkr/
78
79 _build-clnkrd:
80 go build -trimpath -ldflags '$(LDFLAGS)' -o clnkrd ./cmd/clnkrd/
81
82 ##@ Quality
83 check: _fmt-check _vet _lint _arch _script-tests sloc frontend-sloc _workflow-make-targets _check-docs test evaluations ## Run formatting, vet, lint, architecture, script tests, SLOC, workflow, docs, test, and evaluation checks
84
85 test: ## Run all tests
86 go test ./... -v
87
88 evaluations: build ## Run the mock-provider evaluation suite
89 @$(CLANKERVAL_PREFLIGHT) \
90 "$$clankerval_path" run --suite default --binary "$(CLANKERVAL_BINARY)"
91
92 evaluations-live: build ## Run the live-provider evaluation suite
93 @$(CLANKERVAL_PREFLIGHT) \
94 CLNKR_EVALUATION_MODE=live-provider "$$clankerval_path" run --suite default --binary "$(CLANKERVAL_BINARY)"
95
96 evaluations-live-openai: ## Run the live-provider evaluation suite against OpenAI defaults
97 @CLNKR_EVALUATION_API_KEY="$${CLNKR_EVALUATION_OPENAI_API_KEY:-$${OPENAI_API_KEY}}" \
98 CLNKR_EVALUATION_BASE_URL="$${CLNKR_EVALUATION_OPENAI_BASE_URL:-https://api.openai.com/v1}" \
99 CLNKR_EVALUATION_MODEL="$${CLNKR_EVALUATION_OPENAI_MODEL:-gpt-5.4-nano}" \
100 $(MAKE) evaluations-live CLANKERVAL_BINARY="$(CURDIR)/scripts/eval-clnkr-openai"
101
102 evaluations-live-anthropic: ## Run the live-provider evaluation suite against Anthropic defaults
103 @CLNKR_EVALUATION_API_KEY="$${CLNKR_EVALUATION_ANTHROPIC_API_KEY:-$${ANTHROPIC_API_KEY}}" \
104 CLNKR_EVALUATION_BASE_URL="$${CLNKR_EVALUATION_ANTHROPIC_BASE_URL:-https://api.anthropic.com}" \
105 CLNKR_EVALUATION_MODEL="$${CLNKR_EVALUATION_ANTHROPIC_MODEL:-claude-haiku-4-5}" \
106 $(MAKE) evaluations-live CLANKERVAL_BINARY="$(CURDIR)/scripts/eval-clnkr-anthropic"
107
108 _fmt:
109 golangci-lint fmt ./...
110
111 _fmt-check:
112 golangci-lint fmt --diff ./...
113
114 _vet:
115 go vet ./...
116
117 _lint:
118 golangci-lint run ./...
119
120 _arch:
121 @./scripts/check-architecture-imports.sh
122
123 _script-tests:
124 ./scripts/test/check-architecture-imports.sh
125 ./scripts/test/check-thoth-critical.sh
126 ./scripts/test/release-require-green-main.sh
127
128 # Repo-root only: counts repo-local Go files in the main-module dependency closure of `.`.
129 sloc: ## Report core runtime graph SLOC and fail if it exceeds CORE_SLOC_LIMIT
130 @sloc="$$(cloc --quiet --timeout 30 --csv $$(go list -deps -f '{{if .Module}}{{if .Module.Main}}{{range .GoFiles}}{{$$.Dir}}/{{.}}{{"\n"}}{{end}}{{end}}{{end}}' . | sort -u) | awk -F, 'END { print $$5 }')"; \
131 echo "core runtime graph: $$sloc / $(CORE_SLOC_LIMIT) SLOC"; \
132 test "$$sloc" -le "$(CORE_SLOC_LIMIT)" || { echo "error: core runtime graph exceeds $(CORE_SLOC_LIMIT) SLOC limit" >&2; exit 1; }
133
134 frontend-sloc: ## Report non-test frontend SLOC and fail if it exceeds FRONTEND_SLOC_LIMIT
135 @sloc="$$(cloc --quiet --timeout 30 --csv --not-match-f='_test\.go$$' cmd | awk -F, 'END { print $$5 }')"; \
136 echo "frontend: $$sloc / $(FRONTEND_SLOC_LIMIT) SLOC"; \
137 test "$$sloc" -le "$(FRONTEND_SLOC_LIMIT)" || { echo "error: frontend exceeds $(FRONTEND_SLOC_LIMIT) SLOC limit" >&2; exit 1; }
138
139 architecture-shape-report: ## Manually report thoth architecture shape; requires thoth in PATH or THOTH_BIN
140 ./scripts/architecture-shape-report.sh .
141
142 thoth-critical-check: ## Fail when thoth reports any critical file risk; requires thoth in PATH or THOTH_BIN
143 ./scripts/check-thoth-critical.sh .
144
145 semantic-cohesion-report: ## Manually report thoth semantic cohesion; requires thoth in PATH or THOTH_BIN
146 ./scripts/semantic-cohesion-report.sh .
147
148 test-fidelity-report: ## Manually report test shape, fixtures, and mock/fake usage
149 ./scripts/test-fidelity-report.sh
150
151 _workflow-make-targets:
152 ./scripts/check-workflow-make-targets.sh
153
154 ##@ Contributing
155 help: ## Show available targets
156 @awk 'BEGIN {FS = ":.*## "; printf "Available targets:\n"} \
157 /^##@/ {printf "\n%s\n", substr($$0, 5)} \
158 /^[a-zA-Z0-9][a-zA-Z0-9_-]*:.*## / {printf " %-12s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
159
160 _hooks:
161 git config core.hooksPath .githooks
162
163 ##@ Docs
164 man: $(DOC_MAN_OUTPUTS) ## Generate man pages from markdown
165
166 docs: _site-build ## Build documentation site
167
168 docs-serve: _site-sync ## Run documentation site locally
169 HUGO_CLNKR_LATEST_TAG='$(LATEST_TAG)' $(HUGO) server --source site
170
171 readme-image: _require-readme-image-tools ## Render README terminal image
172 @mkdir -p "$(dir $(README_FONT))" "$(dir $(README_FONT_CHECKOUT))"
173 @if [ -d "$(README_FONT_CHECKOUT)/.git" ]; then \
174 git -C "$(README_FONT_CHECKOUT)" fetch --quiet origin main; \
175 git -C "$(README_FONT_CHECKOUT)" checkout --quiet main; \
176 git -C "$(README_FONT_CHECKOUT)" reset --quiet --hard origin/main; \
177 else \
178 git clone --quiet "$(README_FONT_REPO)" "$(README_FONT_CHECKOUT)"; \
179 fi
180 rm -f "$(README_FONT)" "$(README_FONT_PATCH_LOG)"
181 @fontforge -script "$(README_FONT_CHECKOUT)/font-patcher" --complete --has-no-italic \
182 -out "$(dir $(README_FONT))" "$(README_FONT_CHECKOUT)/BerkeleyMono-Regular.otf" \
183 >"$(README_FONT_PATCH_LOG)" 2>&1 || { \
184 echo "error: failed to patch README font; see $(README_FONT_PATCH_LOG)" >&2; \
185 tail -40 "$(README_FONT_PATCH_LOG)" >&2; \
186 exit 1; \
187 }
188 CLNKR_README_IMAGE_FONT="$(CURDIR)/$(README_FONT)" ./scripts/render-readme-banner-png.sh "$(README_IMAGE)"
189
190 _check-docs: man _site-build
191
192 _require-pandoc:
193 @command -v "$(PANDOC)" >/dev/null 2>&1 || { \
194 echo "error: pandoc is required for docs generation" >&2; \
195 exit 1; \
196 }
197
198 _require-run-clnkr-tools:
199 @command -v gum >/dev/null 2>&1 || { \
200 echo "error: gum is required for clnkr wrapper" >&2; \
201 exit 1; \
202 }
203 @command -v jq >/dev/null 2>&1 || { \
204 echo "error: jq is required for clnkr wrapper" >&2; \
205 exit 1; \
206 }
207
208 _require-readme-image-tools:
209 @command -v git >/dev/null 2>&1 || { \
210 echo "error: git is required for README image font checkout" >&2; \
211 exit 1; \
212 }
213 @command -v gum >/dev/null 2>&1 || { \
214 echo "error: gum is required for README image generation" >&2; \
215 echo "install it from https://github.com/charmbracelet/gum" >&2; \
216 exit 1; \
217 }
218 @command -v fontforge >/dev/null 2>&1 || { \
219 echo "error: fontforge is required for README image font patching" >&2; \
220 echo "Ubuntu: sudo apt-get install fontforge" >&2; \
221 echo "macOS: brew install fontforge" >&2; \
222 exit 1; \
223 }
224 @{ command -v magick >/dev/null 2>&1 || command -v convert >/dev/null 2>&1; } || { \
225 echo "error: ImageMagick is required for README image generation" >&2; \
226 echo "Ubuntu: sudo apt-get install imagemagick" >&2; \
227 echo "macOS: brew install imagemagick" >&2; \
228 exit 1; \
229 }
230
231 _site-sync:
232 find "$(DOC_CONTENT_DIR)" -maxdepth 1 -type f ! -name '_index.md' -delete
233 $(MAKE) --no-print-directory $(GENERATED_SITE_DOCS)
234
235 _site-build: _site-sync
236 HUGO_CLNKR_LATEST_TAG='$(LATEST_TAG)' $(HUGO) --source site
237
238 $(DOC_MAN_DIR)/%.1: doc/%.1.md | _require-pandoc
239 mkdir -p "$(DOC_MAN_DIR)"
240 "$(PANDOC)" --from=markdown-smart --to=man --standalone "$<" -o "$@"
241
242 $(DOC_MAN_DIR)/%.3: doc/%.3.md | _require-pandoc
243 mkdir -p "$(DOC_MAN_DIR)"
244 "$(PANDOC)" --from=markdown-smart --to=man --standalone "$<" -o "$@"
245
246 $(DOC_MAN_DIR)/%.7: doc/%.7.md | _require-pandoc
247 mkdir -p "$(DOC_MAN_DIR)"
248 "$(PANDOC)" --from=markdown-smart --to=man --standalone "$<" -o "$@"
249
250 $(DOC_CONTENT_DIR)/clnkr.md: DOC_TITLE = clnkr
251 $(DOC_CONTENT_DIR)/clnkr.md: DOC_DESCRIPTION = Plain CLI manual page
252 $(DOC_CONTENT_DIR)/clnkr.md: DOC_WEIGHT = 10
253 $(DOC_CONTENT_DIR)/clnkrd.md: DOC_TITLE = clnkrd
254 $(DOC_CONTENT_DIR)/clnkrd.md: DOC_DESCRIPTION = Stdio JSONL adapter manual page
255 $(DOC_CONTENT_DIR)/clnkrd.md: DOC_WEIGHT = 11
256
257 $(DOC_CONTENT_DIR)/clnkr.md $(DOC_CONTENT_DIR)/clnkrd.md: $(DOC_CONTENT_DIR)/%.md: doc/%.1.md $(DOC_PAGE_TEMPLATE) | _require-pandoc
258 mkdir -p "$(DOC_CONTENT_DIR)"
259 "$(PANDOC)" \
260 --from=markdown-smart \
261 --to=gfm \
262 --standalone \
263 --template="$(DOC_PAGE_TEMPLATE)" \
264 --metadata title="$(DOC_TITLE)" \
265 --metadata description="$(DOC_DESCRIPTION)" \
266 --metadata slug="$*" \
267 --metadata weight="$(DOC_WEIGHT)" \
268 "$<" -o "$@"