-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
225 lines (183 loc) · 6.55 KB
/
Makefile
File metadata and controls
225 lines (183 loc) · 6.55 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
.PHONY: build run clean test fmt vet start stop restart status watch install uninstall export backup insights dream-cycle mcp benchmark benchmark-quality benchmark-compare lifecycle-test setup-hooks lint
BUILD_DIR=bin
VERSION=0.36.0 # x-release-please-version
LDFLAGS=-ldflags "-s -w -X main.Version=$(VERSION)"
TAGS=
# --- Platform detection ---
# Detect Windows via uname (works in MSYS2, Git Bash, and CI).
UNAME_S := $(shell uname -s 2>/dev/null || echo unknown)
ifneq (,$(findstring MINGW,$(UNAME_S)))
IS_WINDOWS=1
else ifneq (,$(findstring MSYS,$(UNAME_S)))
IS_WINDOWS=1
else ifneq (,$(findstring Windows,$(UNAME_S)))
IS_WINDOWS=1
endif
ifdef IS_WINDOWS
BINARY=mnemonic.exe
# MSYS2/Git Bash make does not inherit Windows env vars (USERPROFILE,
# LOCALAPPDATA) and its built-in HOME (/home/<user>) maps to the wrong
# Windows path via cygpath (e.g. C:\Program Files\Git\home\<user>).
# Read the real USERPROFILE from the registry; fall back to cygpath ~.
WIN_HOME := $(shell cat '/proc/registry/HKEY_CURRENT_USER/Volatile Environment/USERPROFILE' 2>/dev/null | tr -d '\0\r')
ifeq ($(WIN_HOME),)
WIN_HOME := $(shell cygpath -w ~)
endif
# MSYS2 make remaps TEMP to a POSIX path that native Windows tools
# (Go, GCC) cannot resolve. Convert it back to a Windows-native path.
WIN_TEMP := $(shell cygpath -w "$${TEMP:-/tmp}")
export TEMP := $(WIN_TEMP)
export TMP := $(WIN_TEMP)
# Use ?= so users can override Go tool paths from the environment.
export GOTMPDIR ?= $(WIN_TEMP)
export GOPATH ?= $(WIN_HOME)\go
export GOCACHE ?= $(WIN_HOME)\AppData\Local\go-build
export GOMODCACHE ?= $(WIN_HOME)\go\pkg\mod
else
BINARY=mnemonic
endif
build:
@mkdir -p $(BUILD_DIR)
go build $(TAGS) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY) ./cmd/mnemonic
# --- Embedded LLM (llama.cpp + Felix architecture) ---
LLAMACPP_DIR=third_party/llama.cpp
LLAMACPP_BUILD=$(LLAMACPP_DIR)/build
BRIDGE_DIR=internal/llm/llamacpp/csrc
build-llamacpp:
@if [ ! -f $(LLAMACPP_BUILD)/src/libllama.a ]; then \
cmake -B $(LLAMACPP_BUILD) -S $(LLAMACPP_DIR) \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DGGML_NATIVE=ON; \
cmake --build $(LLAMACPP_BUILD) --target llama -j$$(nproc); \
fi
build-llamacpp-rocm:
@if [ ! -f $(LLAMACPP_BUILD)/src/libllama.a ]; then \
cmake -B $(LLAMACPP_BUILD) -S $(LLAMACPP_DIR) \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DGGML_NATIVE=ON \
-DGGML_HIP=ON \
-DGGML_HIP_ROCWMMA_FATTN=ON \
-DGGML_HIP_GRAPHS=ON \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON; \
cmake --build $(LLAMACPP_BUILD) --target llama -j$$(nproc); \
fi
build-bridge:
@if [ ! -f $(BRIDGE_DIR)/bridge.o ] || [ $(BRIDGE_DIR)/bridge.cpp -nt $(BRIDGE_DIR)/bridge.o ]; then \
g++ -std=c++17 -O2 -c $(BRIDGE_DIR)/bridge.cpp -o $(BRIDGE_DIR)/bridge.o \
-I$(BRIDGE_DIR) \
-I$(LLAMACPP_DIR)/include \
-I$(LLAMACPP_DIR)/ggml/include; \
fi
ifdef ROCM
build-embedded: build-llamacpp-rocm build-bridge
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=1 go build -tags "llamacpp rocm" $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY) ./cmd/mnemonic
else
build-embedded: build-llamacpp build-bridge
@mkdir -p $(BUILD_DIR)
CGO_ENABLED=1 go build -tags llamacpp $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY) ./cmd/mnemonic
endif
build-quantize: build-llamacpp
cmake --build $(LLAMACPP_BUILD) --target llama-quantize -j$$(nproc)
quantize: build-quantize
@for f in models/*-v1.gguf; do \
q8="$${f%.gguf}-q8_0.gguf"; \
if [ ! -f "$$q8" ]; then \
echo "Quantizing $$f -> $$q8"; \
$(LLAMACPP_BUILD)/bin/llama-quantize "$$f" "$$q8" q8_0; \
fi; \
done
run: build
./$(BUILD_DIR)/$(BINARY) --config config.yaml serve
test:
go test ./... -v
fmt:
go fmt ./...
vet:
go vet ./...
clean:
rm -rf $(BUILD_DIR)
tidy:
go mod tidy
# Quick check: fmt + vet
check: fmt vet
@echo "All checks passed"
# --- Daemon Management ---
start: build
./$(BUILD_DIR)/$(BINARY) --config config.yaml start
stop:
./$(BUILD_DIR)/$(BINARY) stop
restart: build
./$(BUILD_DIR)/$(BINARY) --config config.yaml restart
# --- Monitoring ---
status: build
./$(BUILD_DIR)/$(BINARY) --config config.yaml status
watch: build
./$(BUILD_DIR)/$(BINARY) --config config.yaml watch
# --- Memory Commands ---
remember: build
./$(BUILD_DIR)/$(BINARY) --config config.yaml remember "$(TEXT)"
recall: build
./$(BUILD_DIR)/$(BINARY) --config config.yaml recall "$(QUERY)"
consolidate: build
./$(BUILD_DIR)/$(BINARY) --config config.yaml consolidate
ingest: build
./$(BUILD_DIR)/$(BINARY) --config config.yaml ingest $(DIR)
# --- Data Management ---
export: build
./$(BUILD_DIR)/$(BINARY) --config config.yaml export $(ARGS)
backup: build
./$(BUILD_DIR)/$(BINARY) --config config.yaml backup
insights: build
./$(BUILD_DIR)/$(BINARY) --config config.yaml insights
dream-cycle: build
./$(BUILD_DIR)/$(BINARY) --config config.yaml dream-cycle
meta-cycle: build
./$(BUILD_DIR)/$(BINARY) --config config.yaml meta-cycle
# --- MCP Server ---
mcp: build
./$(BUILD_DIR)/$(BINARY) --config config.yaml mcp
# --- Benchmark ---
benchmark:
go build $(TAGS) -o $(BUILD_DIR)/benchmark ./cmd/benchmark
@echo "Benchmark built. Run: ./$(BUILD_DIR)/benchmark (daemon must be running)"
benchmark-quality:
go build $(TAGS) $(LDFLAGS) -o $(BUILD_DIR)/benchmark-quality ./cmd/benchmark-quality
@echo "Quality benchmark built. Run: ./$(BUILD_DIR)/benchmark-quality"
benchmark-compare:
go build $(TAGS) $(LDFLAGS) -o $(BUILD_DIR)/benchmark-quality ./cmd/benchmark-quality
./$(BUILD_DIR)/benchmark-quality --compare --cycles 5 --verbose
lifecycle-test:
go build $(TAGS) $(LDFLAGS) -o $(BUILD_DIR)/lifecycle-test ./cmd/lifecycle-test
./$(BUILD_DIR)/lifecycle-test --verbose
# --- Lint ---
lint:
golangci-lint run
# --- Setup ---
setup-hooks:
git config core.hooksPath .githooks
@echo "Git hooks configured to use .githooks/"
install: build
./$(BUILD_DIR)/$(BINARY) --config config.yaml install
uninstall:
./$(BUILD_DIR)/$(BINARY) uninstall
# --- Release ---
# Usage: make release NEW_VERSION=0.8.0
release:
ifndef NEW_VERSION
$(error NEW_VERSION is required. Usage: make release NEW_VERSION=0.8.0)
endif
@echo "Releasing v$(NEW_VERSION)..."
@sed -i 's/^VERSION=.*/VERSION=$(NEW_VERSION)/' Makefile
@echo "Updated Makefile VERSION to $(NEW_VERSION)"
@echo ""
@echo "Next steps:"
@echo " 1. Update CHANGELOG.md with changes for $(NEW_VERSION)"
@echo " 2. git add Makefile CHANGELOG.md"
@echo " 3. git commit -m 'Release v$(NEW_VERSION)'"
@echo " 4. git tag v$(NEW_VERSION)"
@echo " 5. git push origin main --tags"
@echo ""
@echo "Pushing the tag will trigger the GitHub Actions release workflow."