-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathMakefile
More file actions
267 lines (220 loc) · 9.88 KB
/
Copy pathMakefile
File metadata and controls
267 lines (220 loc) · 9.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
BINARY := gortex
# VERSION defaults to the nearest annotated tag (e.g. v0.1.0) or "dev" when
# no tags exist / not a git checkout. COMMIT is the short SHA; DATE is RFC
# 3339 UTC. internal/version parses main.version and treats main.commit as
# the +build slot, so `gortex version` prints canonical semver.
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
LDFLAGS := -s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE)
.PHONY: build build-onnx build-gomlx build-hugot build-windows \
test bench bench-rpi bench-rpi-quick bench-rpi-profile bench-compare \
lint fmt clean install dev-link tag-release \
deps-onnx deps-gomlx deps-hugot deps-vectors \
claude-plugin claude-plugin-check
# ---------------------------------------------------------------------------
# Build variants
# ---------------------------------------------------------------------------
build:
go build -ldflags '$(LDFLAGS)' -tags llama -o $(BINARY) ./cmd/gortex/
build-onnx: deps-onnx
go build -tags embeddings_onnx -ldflags '$(LDFLAGS)' -o $(BINARY) ./cmd/gortex/
build-gomlx: deps-gomlx
go build -tags embeddings_gomlx -ldflags '$(LDFLAGS)' -o $(BINARY) ./cmd/gortex/
# Hugot is bundled by default now — this target is kept as a compatibility
# alias and also ensures the dep is explicitly recorded in go.mod.
build-hugot: deps-hugot
go build -ldflags '$(LDFLAGS)' -o $(BINARY) ./cmd/gortex/
test:
go test -race ./...
bench:
go test -bench=. -benchmem -count=1 -benchtime=1s \
./internal/parser/languages/ \
./internal/graph/ \
./internal/search/ \
./internal/resolver/ \
./internal/query/ \
./internal/indexer/ \
./internal/analysis/
# RPi / low-resource device benchmarks
BENCH_BASELINE ?= results/bench-baseline.txt
bench-rpi:
./scripts/bench-rpi.sh
bench-rpi-quick:
./scripts/bench-rpi.sh --quick
bench-rpi-profile:
./scripts/bench-rpi.sh --profile
bench-compare:
./scripts/bench-rpi.sh --compare $(BENCH_BASELINE)
bench-save-baseline:
./scripts/bench-rpi.sh
@cp $$(ls -t results/bench-*.txt | head -1) $(BENCH_BASELINE)
@echo "✓ Baseline saved to $(BENCH_BASELINE)"
lint:
golangci-lint run --timeout=5m
fmt:
gofmt -s -w .
clean:
rm -f $(BINARY) gortex.exe gortex-linux gortex-rpi gortex-rpi32
install:
go install -ldflags '$(LDFLAGS)' ./cmd/gortex/
# dev-link builds the working tree and points the Homebrew shim at it so
# `gortex` on $PATH runs the dev binary. Restarts the daemon so the new
# binary takes over (an old daemon keeps a stale in-memory graph). Revert
# with `brew reinstall gortex`.
HOMEBREW_BIN ?= /opt/homebrew/bin/gortex
dev-link: build
ln -sfn "$(CURDIR)/$(BINARY)" "$(HOMEBREW_BIN)"
# tag-release stamps the working copy with a git tag that matches the
# version currently in cmd/gortex/main.go. Workflow:
#
# ./gortex version bump minor # edits main.go
# git commit -am "Bump version to v0.2.0"
# make tag-release # reads ./gortex, creates tag
# git push && git push origin v0.2.0
#
# Builds without VERSION ldflags on purpose so `gortex version --short`
# reflects the literal main.go value (not `git describe` drift). Strips
# the +build slot because git tags shouldn't carry build metadata. Emits
# a clear error on dev builds, duplicate tags, or a dirty tree so
# misfires don't silently create broken releases.
tag-release:
@go build -o $(BINARY) ./cmd/gortex/
@TAG=$$(./$(BINARY) version --short | sed 's/+.*//'); \
if [ "$$TAG" = "v0.0.0-dev" ]; then \
echo "refusing to tag dev build — run \`./$(BINARY) version bump …\` first"; exit 1; \
fi; \
if git rev-parse --verify "refs/tags/$$TAG" >/dev/null 2>&1; then \
echo "tag $$TAG already exists"; exit 1; \
fi; \
if ! git diff-index --quiet HEAD --; then \
echo "tracked files have uncommitted changes — commit the bump first (run \`git status\` to see them)"; exit 1; \
fi; \
git tag -a "$$TAG" -m "Release $$TAG"; \
echo "Tagged $$TAG. Push with: git push origin $$TAG"
# Cross-compile for Raspberry Pi (ARM64)
build-rpi:
CGO_ENABLED=1 GOOS=linux GOARCH=arm64 CC=aarch64-linux-gnu-gcc \
go build -ldflags '$(LDFLAGS)' -o gortex-rpi ./cmd/gortex/
@echo "✓ Built gortex-rpi (linux/arm64)"
# Cross-compile for Raspberry Pi (ARMv7 / 32-bit)
build-rpi32:
CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=7 CC=arm-linux-gnueabihf-gcc \
go build -ldflags '$(LDFLAGS)' -o gortex-rpi32 ./cmd/gortex/
@echo "✓ Built gortex-rpi32 (linux/arm/v7)"
# Cross-compile for Windows (amd64). Requires the mingw-w64 toolchain
# (`brew install mingw-w64` on macOS, `apt install gcc-mingw-w64` on
# Debian/Ubuntu). CGO stays on because tree-sitter needs a C/C++
# compiler; the llama tag is omitted — the in-process llama.cpp backend
# isn't part of the Windows build. `-extldflags -static` links the
# mingw-w64 C/C++ runtime (libstdc++, libgcc, winpthread) into the .exe
# so it runs on a stock Windows box without bundled DLLs.
build-windows:
CGO_ENABLED=1 GOOS=windows GOARCH=amd64 \
CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ \
go build -ldflags '$(LDFLAGS) -extldflags "-static"' -o gortex.exe ./cmd/gortex/
@echo "✓ Built gortex.exe (windows/amd64)"
# ---------------------------------------------------------------------------
# Marketplace plugin bundle
# ---------------------------------------------------------------------------
# claude-plugin regenerates the Anthropic Plugin Marketplace bundle at
# claude-plugin/. The bundle is checked in so the marketplace's
# "git-subdir" source can pull it directly. The CI guard
# (claude-plugin-check) asserts that re-running this target produces
# no diff against what's checked in — drift means the bundle is stale
# vs the source-of-truth content in
# internal/agents/claudecode/content.go.
claude-plugin: build
./$(BINARY) plugin emit --target ./claude-plugin --variant anthropic
@echo "✓ Regenerated claude-plugin/ from internal/agents/claudecode content"
claude-plugin-check: claude-plugin
@if ! git diff --exit-code -- claude-plugin >/dev/null 2>&1; then \
echo "claude-plugin/ is out of date — run 'make claude-plugin' and commit the result"; \
git --no-pager diff --stat -- claude-plugin; \
exit 1; \
fi
@echo "✓ claude-plugin/ matches generated output"
# ---------------------------------------------------------------------------
# Embedding backend dependencies
# ---------------------------------------------------------------------------
# ONNX Runtime — system library required for -tags embeddings_onnx
deps-onnx:
@echo "=== ONNX Runtime dependency ==="
ifeq ($(shell uname -s),Darwin)
@command -v brew >/dev/null 2>&1 || { echo "Error: Homebrew required. Install from https://brew.sh"; exit 1; }
@brew list onnxruntime >/dev/null 2>&1 || brew install onnxruntime
@echo "✓ onnxruntime installed (macOS/Homebrew)"
else ifeq ($(shell uname -s),Linux)
@dpkg -s libonnxruntime-dev >/dev/null 2>&1 || { echo "Run: sudo apt install libonnxruntime-dev"; exit 1; }
@echo "✓ libonnxruntime-dev installed (Linux/apt)"
endif
go get github.com/yalue/onnxruntime_go@latest
@echo "✓ Go ONNX bindings ready"
# GoMLX — XLA/PJRT plugin auto-downloads on first run (~100MB)
deps-gomlx:
@echo "=== GoMLX dependency ==="
go get github.com/gomlx/gomlx@latest
go get github.com/gomlx/onnx-gomlx@latest
@echo "✓ GoMLX + ONNX converter installed"
@echo " Note: XLA/PJRT plugin will auto-download on first run (~100MB)"
# Hugot — uses same XLA/PJRT backend as GoMLX
deps-hugot:
@echo "=== Hugot dependency ==="
go get github.com/knights-analytics/hugot@latest
@echo "✓ Hugot installed"
@echo " Note: XLA/PJRT plugin will auto-download on first run (~100MB)"
# Prepare GloVe word vectors for built-in static embeddings
deps-vectors:
@echo "=== Preparing GloVe word vectors ==="
@test -f internal/embedding/data/vectors.bin.gz && echo "✓ Vectors already prepared" || bash scripts/prepare_vectors.sh
# ---------------------------------------------------------------------------
# Eval framework
# ---------------------------------------------------------------------------
EVAL_DIR := eval
EVAL_VENV := $(EVAL_DIR)/.venv
EVAL_PYTHON := $(EVAL_VENV)/bin/python
EVAL_PIP := $(EVAL_VENV)/bin/pip
EVAL_CLI := $(EVAL_VENV)/bin/gortex-eval
EVAL_ANALYZE := $(EVAL_VENV)/bin/gortex-eval-analyze
MODEL ?= claude-sonnet
MODE ?= baseline
SLICE ?= 0:5
SUBSET ?= lite
.PHONY: eval-setup eval-test eval-test-all eval-list \
eval-single eval-matrix eval-debug eval-summary eval-compare eval-tools
# Setup: create venv and install deps
eval-setup: build
@test -d $(EVAL_VENV) || python3 -m venv $(EVAL_VENV)
$(EVAL_PIP) install -q -e "$(EVAL_DIR)[dev]"
@echo "✓ Eval framework ready. Binary: ./$(BINARY)"
# Build linux/amd64 binary for container injection (requires podman/docker)
eval-build-linux:
podman run --rm --platform linux/amd64 -v $(CURDIR):/src -w /src golang:1.26 \
bash -c "apt-get update -qq && apt-get install -y -qq libtree-sitter-dev && go build -ldflags '$(LDFLAGS)' -o gortex-linux ./cmd/gortex/"
@echo "✓ Built gortex-linux (linux/amd64)"
# Run Python eval tests
eval-test:
$(EVAL_PYTHON) -m pytest $(EVAL_DIR)/tests/ -q
# Run all tests (Go + Python)
eval-test-all: test eval-test
# List available configs
eval-list: eval-setup
$(EVAL_CLI) list-configs
# Single (model, mode) run
eval-single: eval-setup
$(EVAL_CLI) single -m $(MODEL) --mode $(MODE) --subset $(SUBSET) --slice $(SLICE)
# Full A/B matrix
eval-matrix: eval-setup
$(EVAL_CLI) matrix --models claude-sonnet claude-haiku \
--modes baseline native native_augment \
--subset $(SUBSET) --slice $(SLICE)
# Debug a single instance
eval-debug: eval-setup
$(EVAL_CLI) debug -m $(MODEL) --mode $(MODE) -i $(INSTANCE)
# Analyze results
eval-summary:
$(EVAL_ANALYZE) summary results/
eval-compare:
$(EVAL_ANALYZE) compare-modes results/ -m $(MODEL)
eval-tools:
$(EVAL_ANALYZE) tool-usage results/