-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
183 lines (156 loc) · 6.92 KB
/
Makefile
File metadata and controls
183 lines (156 loc) · 6.92 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
# Prerequisites:
# - Go 1.25+
# - sqlc (go install github.com/sqlc-dev/sqlc/cmd/sqlc@v1.30.0)
# - golang-migrate (brew install golang-migrate)
# - CompileDaemon for `make dev` (go install github.com/githubnemo/CompileDaemon@latest)
#
# Database:
# Targets that touch the database read DATABASE_URL from .env.development
# (and .env.local if present). Start Postgres via `make db` or point
# DATABASE_URL at any Postgres you already have running.
.PHONY: generate generate-statusline build test test-verbose initdb migrate-up migrate-down migrate-create seed setup full-setup db dev check fmt vet precommit install-hooks help install-cc uninstall-cc up down logs
# Load DATABASE_URL from .env files (matches docker-compose defaults).
-include .env.development
-include .env.local
export
help: ## Show available targets
@grep -E '^[a-zA-Z_-]+:.*?## ' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf " %-20s %s\n", $$1, $$2}'
generate: generate-statusline ## Regenerate all generated files (SQLC + statusline prices)
cd db && sqlc generate
generate-statusline: ## Sync cc-statusline.sh prices block from pricing.go
go run ./cmd/genprices
build: ## Typecheck the entire module
go build -o /dev/null ./...
test: ## Run all tests
go test ./...
test-verbose: ## Run all tests with verbose output
go test -v ./...
initdb: ## Create the database and router schema (idempotent)
@go run ./cmd/initdb
migrate-up: initdb ## Apply all pending migrations
migrate -path db/migrations \
-database "$(DATABASE_URL)&search_path=router" up
migrate-down: ## Roll back the last migration
migrate -path db/migrations \
-database "$(DATABASE_URL)&search_path=router" down 1
migrate-create: ## Create a new migration (usage: make migrate-create NAME=add-foo)
@if [ -z "$(NAME)" ]; then echo "Usage: make migrate-create NAME=add-foo"; exit 1; fi
migrate create -ext sql -dir db/migrations $(NAME)
seed: ## Create a local dev installation + API key and print usage instructions
go run ./cmd/seed
setup: migrate-up seed ## Bootstrap (host DB): init DB, run migrations, seed an API key
full-setup: generate-statusline ## Bootstrap router: docker compose + seed + interactively wire Claude Code
@if [ -n "$(KEY)" ] && [ -n "$(BASE_URL)" ]; then \
INSTALL_CMD='WEAVE_ROUTER_KEY="$(KEY)" ./install/install.sh --claude --base-url "$(BASE_URL)"'; \
[ -n "$(SCOPE)" ] && INSTALL_CMD="$$INSTALL_CMD --scope $(SCOPE)"; \
[ -n "$(DIR)" ] && INSTALL_CMD="$$INSTALL_CMD --dir $(DIR)"; \
[ "$(NON_INTERACTIVE)" = "1" ] && INSTALL_CMD="$$INSTALL_CMD --non-interactive"; \
echo "==> Wiring Claude Code → $(BASE_URL)..."; \
eval "$$INSTALL_CMD"; \
else \
if [ -n "$(KEY)" ] || [ -n "$(BASE_URL)" ]; then \
echo "error: KEY and BASE_URL must both be provided together."; \
exit 1; \
fi; \
./install/spin "Building docker compose stack (postgres, migrate, server)" \
docker compose up --build -d || exit 1; \
./install/spin "Waiting for router /health" bash -c '\
for i in $$(seq 1 60); do \
curl -fsS --max-time 2 http://localhost:8080/health >/dev/null 2>&1 && exit 0; \
sleep 1; \
done; \
echo "router did not become healthy within 60s. Tail with: make logs" >&2; \
exit 1' || exit 1; \
SEED_CAPTURE="$$(mktemp -t full-setup-seed.XXXXXX.log)"; \
WEAVE_SPIN_CAPTURE="$$SEED_CAPTURE" ./install/spin "Seeding Weave Router API key" \
docker compose run --rm seed || { rm -f "$$SEED_CAPTURE"; exit 1; }; \
WEAVE_KEY=$$(grep -oE "^ rk_[a-zA-Z0-9_-]+$$" "$$SEED_CAPTURE" | head -1 | xargs); \
rm -f "$$SEED_CAPTURE"; \
if [ -z "$$WEAVE_KEY" ]; then \
echo "error: failed to extract router key from seed output."; \
exit 1; \
fi; \
echo " key: $$WEAVE_KEY"; \
echo ""; \
WEAVE_ROUTER_KEY="$$WEAVE_KEY" ./install/install.sh --claude --base-url http://localhost:8080; \
echo ""; \
echo "Done. Router on http://localhost:8080. Share with teammates: make full-setup KEY=$$WEAVE_KEY BASE_URL=<reachable-url>"; \
fi
db: ## Start the compose Postgres only (port 5433)
docker compose up -d postgres
@echo ""
@echo "Postgres is running on localhost:5433."
@echo "Add this to .env.local if not already set:"
@echo ' DATABASE_URL=postgresql://router:router@localhost:5433/router?sslmode=disable'
dev: ## Run with hot-reload (CompileDaemon)
# `-tags ORT` is required for hugot v0.7+ to enable the ONNX Runtime
# backend. Without it, cluster.NewEmbedder fails at boot and the
# router falls open to the heuristic (Anthropic-only) — which silently
# breaks any eval that expects v0.X-cluster routing. The Dockerfile
# already builds with this tag; do not drop it from any production-
# bound build either. See router/CLAUDE.md "Cluster routing (P0)".
#
# CGO_LDFLAGS (libtokenizers) and ROUTER_ONNX_LIBRARY_DIR
# (libonnxruntime) come from .env.local on macOS — see the comments
# there for setup. On Linux the brew/.local paths don't apply; the
# Dockerfile is the production path.
CompileDaemon \
-build="go build -tags ORT -o ./bin/server ./cmd/router" \
-command="./bin/server" \
-exclude-dir="vendor" \
-exclude-dir=".vscode" \
-exclude-dir="bin" \
-exclude-dir=".venv" \
-exclude-dir="__pycache__" \
-exclude-dir=".pytest_cache" \
-exclude-dir=".mypy_cache" \
-exclude-dir=".ruff_cache" \
-exclude-dir=".bench-cache" \
-exclude-dir=".embedding-cache" \
-exclude-dir="node_modules" \
-exclude-dir="results" \
-exclude-dir="logs" \
-exclude-dir="assets" \
-exclude-dir=".git" \
-exclude-dir="eval" \
-exclude-dir="scripts" \
-exclude-dir="docs" \
-exclude-dir=".local" \
-exclude-dir="install" \
-pattern="(.+\.go|.+\.sql)$$" \
-graceful-kill=true \
-log-prefix=false
up: ## Start the compose stack in the background (no install.sh wiring)
docker compose up --build -d
down: ## Stop the compose stack (keeps the postgres volume)
docker compose down
logs: ## Tail the server logs
docker compose logs -f server
install-cc: generate-statusline ## Wire only Claude Code at the local docker-compose router (assumes it's already running)
./install/install.sh --claude --local
uninstall-cc: ## Remove the local Claude Code → router config
./install/uninstall.sh
fmt: ## Check gofmt (fails on unformatted files)
@UNFORMATTED=$$(gofmt -l .); \
if [ -n "$$UNFORMATTED" ]; then \
echo "error: Go files are not formatted. Run 'gofmt -w .'"; \
echo "$$UNFORMATTED"; \
exit 1; \
fi
vet: ## Run go vet
go vet ./...
precommit: fmt vet build test ## Fast pre-commit check (no codegen, no DB)
install-hooks: ## Install git pre-commit hook
@HOOK_DIR=$$(git rev-parse --git-common-dir)/hooks; \
mkdir -p "$$HOOK_DIR"; \
cp scripts/pre-commit "$$HOOK_DIR/pre-commit"; \
chmod +x "$$HOOK_DIR/pre-commit"; \
echo "Pre-commit hook installed at $$HOOK_DIR/pre-commit"
check: generate fmt vet build test ## Full CI-equivalent check
@if ! git diff --quiet internal/sqlc/; then \
echo "error: sqlc generation produced uncommitted changes"; \
git diff internal/sqlc/; \
exit 1; \
fi
@echo "All checks passed."