Files
小唯 82ef904257 chore(gofmt): 配套——.gitignore 收 cron_raw.txt + Makefile 加 fmt-check 校验
- cron_raw.txt(10-09 hermes cron list dump,无引用/从未入库/可随时重现)
  → 进 .gitignore 忽略,保留数据不删
- Makefile 加 fmt-check target:gofmt -l 非空即 fail,日常/CI 一键查格式
  (只在已有 Makefile 载体上加,不新建机制;go fmt 不支持 -l,用独立 gofmt)
独立于格式化 commit 886c0c2,避免夹带。
2026-10-10 15:55:31 +08:00

212 lines
9.2 KiB
Makefile
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 织忆 MemoryWeave — Makefile
# Go daemon (zhiyid) + Rust sidecar (zhiyi-consolidate)
.PHONY: all build test bench eval deploy clean
# ─── 变量 ────────────────────────────────────────────
GO_CMD := go
RUST_CMD := cargo
GOFMT_CMD := gofmt
GO_DIR := go
RUST_DIR := rust
BINARY_GO := $(GO_DIR)/cmd/zhiyid/zhiyid
BINARY_RUST := $(RUST_DIR)/target/release/zhiyi-consolidate
# ─── 构建 ────────────────────────────────────────────
all: build-go build-rust
build-go:
cd $(GO_DIR) && CGO_ENABLED=1 $(GO_CMD) build -o cmd/zhiyid/zhiyid ./cmd/zhiyid
build-rust:
cd $(RUST_DIR) && $(RUST_CMD) build --release
build: build-go ## 只构建 Go (Rust 需单独 build-rust)
# ─── Obsidian 插件 ────────────────────────────────────
OBSIDIAN_PLUGIN := plugins/obsidian
OBSIDIAN_DEST := $(HOME)/.obsidian/plugins/zhiyi-memory
build-obsidian:
cd $(OBSIDIAN_PLUGIN) && node esbuild.config.mjs
install-obsidian: build-obsidian
cp $(OBSIDIAN_PLUGIN)/main.js $(OBSIDIAN_DEST)/
cp $(OBSIDIAN_PLUGIN)/manifest.json $(OBSIDIAN_DEST)/
cp $(OBSIDIAN_PLUGIN)/styles.css $(OBSIDIAN_DEST)/
# ─── 增强 CLI ─────────────────────────────────────────────
build-cli:
cd $(GO_DIR) && $(GO_CMD) build -o $(HOME)/.local/bin/zhiyi-cli ./cmd/zhiyi-cli
# ─── Web UI ─────────────────────────────────────────────
build-web:
@echo "Web UI 使用静态 HTML(无需构建)"
@echo " - 前端入口: web-ui/index.html"
@echo " - 访问地址: http://localhost:7821/"
@echo " - API 地址: http://localhost:7821/api/v1/"
VERSION := $(shell cat VERSION)
REGISTRY ?= localhost:5000
# ─── 版本信息 ──────────────────────────────────────────
version:
@echo "$(VERSION)"
# ─── 一键安装所有 ───────────────────────────────────────
install-all: build-go build-cli install-obsidian
@echo "版本: $(VERSION)"
@echo "二进制: $(HOME)/.local/bin/zhiyid"
@echo "全部安装完成(重启服务: systemctl --user restart zhiyid)"
# ─── 镜像构建 & 推送 ─────────────────────────────────────
docker-build:
docker build -t zhiyid:$(VERSION) -t zhiyid:latest .
docker-tag:
docker tag zhiyid:$(VERSION) $(REGISTRY)/zhiyid:$(VERSION)
docker tag zhiyid:$(VERSION) $(REGISTRY)/zhiyid:latest
docker-push: docker-build docker-tag
docker push $(REGISTRY)/zhiyid:$(VERSION)
docker push $(REGISTRY)/zhiyid:latest
# ─── 一键部署(Docker Compose)────────────────────────────
deploy-compose: docker-build
docker compose up -d --remove-orphans
@echo "部署完成: curl http://localhost:7821/health"</
# ─── 测试 ────────────────────────────────────────────
test:
cd $(GO_DIR) && $(GO_CMD) test ./... -v -count=1
# 格式校验:gofmt 不合规即报错(gofmt -l 列出文件 → 非空则 exit 1)
fmt-check:
@cd $(GO_DIR) && $(GOFMT_CMD) -l . | tee /tmp/.gofmt_files > /dev/null; \
if [ -s /tmp/.gofmt_files ]; then \
echo "❌ gofmt 不合规文件($(GOFMT_CMD) -l . 非空):"; \
$(GOFMT_CMD) -l . ; \
echo " 修复: cd $(GO_DIR) && $(GOFMT_CMD) -w ."; exit 1; \
else echo "✅ gofmt 合规(0 文件)"; fi
test-go: test
test-rust:
cd $(RUST_DIR) && $(RUST_CMD) test
# ─── 性能基准 ────────────────────────────────────────
bench:
cd $(GO_DIR) && $(GO_CMD) test ./internal/storage -bench=. -benchmem -count=3
# ─── 评估 ────────────────────────────────────────────
eval:
@echo "=== 织忆评估链路 ==="
@curl -s -X POST http://localhost:7821/api/v1/eval/generate \
-H "Content-Type: application/json" \
-H "X-API-Key: $$API_KEY" \
-d '{"namespace":"shared","count":12}' | jq '.count'
@echo "---"
@curl -s -X POST http://localhost:7821/api/v1/eval/run \
-H "Content-Type: application/json" \
-H "X-API-Key: $$API_KEY" \
-d '{"queries":[]}' | jq '{recall_at_5,precision_at_5,mean_reciprocal_rank}'
# ─── CI/CD 自动评估 ──────────────────────────────────
ci-eval:
@echo "--- CI/CD 自动评估 ---"
@TIMESTAMP=$$(date -Iseconds); \
RESULT=$$(curl -s -X POST http://localhost:7821/api/v1/eval/run \
-H "Content-Type: application/json" \
-H "X-API-Key: $$API_KEY" \
-d '{"queries":[]}'); \
RECALL=$$(echo $$RESULT | jq -r '.recall_at_5 // 0'); \
echo "$$TIMESTAMP | recall@5=$$RECALL"; \
PREV=$$(curl -s http://localhost:7821/api/v1/eval/history \
-H "X-API-Key: $$API_KEY" | jq -r '.trend // "first_run"'); \
echo "Trend: $$PREV"; \
if [ "$$PREV" = "degrading" ]; then \
echo "⚠️ ALERT: Eval degradation detected!"; \
exit 1; \
fi
# ─── 部署 ────────────────────────────────────────────
# 统一部署:构建两 + 装两 + 重启两 + 校验(scripts/deploy.sh,用户级 systemd)
# 2026-10-08 t_f57b8bbf:替换旧的 /usr/local/bin 系统级过期目标(与实际用户级部署完全不符)
# deploy.sh 内部完成全部(build+install+restart+verify),脚本可用 --verify-only 单跑校验
deploy:
./scripts/deploy.sh
# 只跑校验(不构建/不安装/不重启)——反例测试/人工体检
deploy-verify:
./scripts/deploy.sh --verify-only
# ⚠️ 已废弃(2026-10-08 t_f57b8bbf):旧 oneshot+timer 设计残留,实际 sidecar 是 simple 常驻,
# 由 zhiyid.service 的 Wants= + 其 PartOf= 生命周期耦合管理,不再单独装 timer/系统级 unit。
deploy-rust:
@echo "已废弃:sidecar 由 scripts/deploy.sh 统一部署(simple 常驻),勿用旧的 oneshot+timer 系统级目标"
deploy-nginx:
sudo cp deploy/nginx-zhiyi.conf /etc/nginx/sites-enabled/zhiyi.conf
sudo nginx -t && sudo systemctl reload nginx
deploy-prometheus:
sudo cp deploy/prometheus-alerts.yml /etc/prometheus/rules/zhiyi.yml
sudo systemctl reload prometheus
# ─── 健康检查 ────────────────────────────────────────
health:
@curl -sf http://localhost:7821/health > /dev/null && echo "✅ zhiyid: OK" || echo "❌ zhiyid: DOWN"
@curl -sf http://localhost:8000/v1/embeddings -H "Content-Type: application/json" -d '{"input":["test"]}' > /dev/null 2>&1 && echo "✅ BGE-M3 ONNX: OK" || echo "⚠️ BGE-M3 ONNX: NOT REACHABLE"
@redis-cli PING > /dev/null 2>&1 && echo "✅ Redis: OK" || echo "⚠️ Redis: NOT REACHABLE"
@curl -sf http://localhost:7821/api/v1/stats -H "X-API-Key: $$API_KEY" | jq '{total_memories,total_episodes}'
# ─── 清理 ────────────────────────────────────────────
clean:
cd $(GO_DIR) && $(GO_CMD) clean
cd $(RUST_DIR) && $(RUST_CMD) clean
# ─── 迁移 ────────────────────────────────────────────
migrate:
cd $(GO_DIR) && $(GO_CMD) run ../scripts/migrate_faiss_to_lance.go \
--faiss-path ~/projects/zhiyi/memory_faiss.index \
--metadata-path ~/projects/zhiyi/memory_metadata.json \
--target sqlite \
--db-path /var/lib/memoryweave/memoryweave.db
migrate-dry-run:
cd $(GO_DIR) && $(GO_CMD) run ../scripts/migrate_faiss_to_lance.go \
--faiss-path ~/projects/zhiyi/memory_faiss.index \
--metadata-path ~/projects/zhiyi/memory_metadata.json \
--dry-run
# ─── 帮助 ────────────────────────────────────────────
help:
@echo "织忆 MemoryWeave — Build & Deploy"
@echo ""
@echo "Usage:"
@echo " make build 构建 Go daemon"
@echo " make build-rust 构建 Rust sidecar"
@echo " make build-cli 构建 CLI 工具"
@echo " make version 显示版本"
@echo " make install-all 一键安装全部(构建+CLI+Obsidian插件)"
@echo " make docker-build 构建 Docker 镜像"
@echo " make docker-push 推送 Docker 镜像"
@echo " make deploy-compose 一键 Docker Compose 部署"
@echo " make test 运行测试"
@echo " make bench 性能基准"
@echo " make eval 运行评估"
@echo " make ci-eval CI/CD 自动评估 (含退化检测)"
@echo " make health 健康检查"
@echo " make deploy 部署 Go daemon(systemd 全局)"
@echo " make clean 清理"