Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
169 lines (142 loc) · 7.17 KB
/
Copy pathMakefile
File metadata and controls
169 lines (142 loc) · 7.17 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
.PHONY: help build install uninstall dev test lint format clean qdrant-start qdrant-stop deps typecheck init-config
# Default target
.DEFAULT_GOAL := help
# Colors for pretty output
BLUE := \033[0;34m
GREEN := \033[0;32m
YELLOW := \033[0;33m
RED := \033[0;31m
NC := \033[0m
# Configuration paths
CONFIG_DIR := $(HOME)/.config/mgrep
CONFIG_FILE := $(CONFIG_DIR)/config.yaml
help: ## Show this help message
@printf "$(BLUE)mgrep$(NC) - Semantic grep-like search tool\n"
@printf "\n"
@printf "$(YELLOW)Usage:$(NC)\n"
@printf " make $(GREEN)<target>$(NC)\n"
@printf "\n"
@printf "$(YELLOW)Targets:$(NC)\n"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " $(GREEN)%-15s$(NC) %s\n", $$1, $$2}'
deps: ## Install dependencies
@printf "$(BLUE)Installing dependencies...$(NC)\n"
@npm install
build: ## Build the project
@printf "$(BLUE)Building mgrep...$(NC)\n"
@npm run build
@printf "$(GREEN)Build complete!$(NC)\n"
install: build init-config ## Install mgrep globally with config
@printf "$(BLUE)Installing mgrep globally...$(NC)\n"
@npm link
@printf "$(GREEN)mgrep installed! Run 'mgrep --help' to get started.$(NC)\n"
uninstall: ## Uninstall mgrep globally
@printf "$(YELLOW)Uninstalling mgrep...$(NC)\n"
@npm unlink -g mgrep 2>/dev/null || npm rm -g mgrep 2>/dev/null || true
@printf "$(GREEN)mgrep uninstalled.$(NC)\n"
reinstall: uninstall install ## Reinstall mgrep globally
dev: ## Run in development mode (build + run)
@npm run dev
test: ## Run tests
@printf "$(BLUE)Running tests...$(NC)\n"
@npm run test
lint: ## Check code with linter
@printf "$(BLUE)Linting code...$(NC)\n"
@npm run lint
format: ## Format code
@printf "$(BLUE)Formatting code...$(NC)\n"
@npm run format
typecheck: ## Run TypeScript type checking
@printf "$(BLUE)Type checking...$(NC)\n"
@npm run typecheck
clean: ## Clean build artifacts
@printf "$(YELLOW)Cleaning build artifacts...$(NC)\n"
@rm -rf dist
@rm -f tsconfig.tsbuildinfo
@printf "$(GREEN)Clean complete!$(NC)\n"
clean-all: clean ## Clean everything including node_modules
@printf "$(YELLOW)Removing node_modules...$(NC)\n"
@rm -rf node_modules
@printf "$(GREEN)Full clean complete!$(NC)\n"
qdrant-start: ## Start Qdrant in Docker
@printf "$(BLUE)Starting Qdrant...$(NC)\n"
@if docker ps -q -f name=qdrant | grep -q .; then \
printf "$(YELLOW)Qdrant is already running.$(NC)\n"; \
else \
docker run -d --name qdrant -p 6333:6333 -p 6334:6334 \
-v qdrant_storage:/qdrant/storage:z \
qdrant/qdrant; \
printf "$(GREEN)Qdrant started on http://localhost:6333$(NC)\n"; \
fi
qdrant-stop: ## Stop Qdrant Docker container
@printf "$(YELLOW)Stopping Qdrant...$(NC)\n"
@docker stop qdrant 2>/dev/null || true
@docker rm qdrant 2>/dev/null || true
@printf "$(GREEN)Qdrant stopped.$(NC)\n"
qdrant-restart: qdrant-stop qdrant-start ## Restart Qdrant
qdrant-logs: ## Show Qdrant logs
@docker logs -f qdrant
init-config: ## Generate mgrep configuration file interactively
@if [ -f "$(CONFIG_FILE)" ]; then \
printf "$(YELLOW)Config already exists at $(CONFIG_FILE)$(NC)\n"; \
printf "$(YELLOW)To regenerate, run: make init-config-force$(NC)\n"; \
else \
$(MAKE) --no-print-directory _generate-config; \
fi
init-config-force: ## Force regenerate configuration (overwrites existing)
@$(MAKE) --no-print-directory _generate-config
_generate-config:
@mkdir -p "$(CONFIG_DIR)"
@printf "$(BLUE)Generating mgrep configuration...$(NC)\n"
@printf "\n$(YELLOW)Select your LLM provider:$(NC)\n"
@printf " 1) openai (default)\n"
@printf " 2) google\n"
@printf " 3) anthropic\n"
@printf " 4) ollama (local)\n"
@printf "\nEnter choice [1-4]: " && read provider_choice; \
case "$$provider_choice" in \
2) provider="google"; emb_model="gemini-embedding-001"; llm_model="gemini-2.0-flash";; \
3) provider="anthropic"; emb_model="text-embedding-3-small"; llm_model="claude-sonnet-4-20250514";; \
4) provider="ollama"; emb_model="nomic-embed-text"; llm_model="llama3.2";; \
*) provider="openai"; emb_model="text-embedding-3-small"; llm_model="gpt-4o-mini";; \
esac; \
if [ "$$provider" = "ollama" ]; then \
printf "\n$(YELLOW)Enter Ollama base URL [http://localhost:11434/v1]:$(NC) " && read ollama_url; \
ollama_url=$${ollama_url:-http://localhost:11434/v1}; \
printf "# mgrep configuration - generated by make init-config\n\n" > "$(CONFIG_FILE)"; \
printf "qdrant:\n url: http://localhost:6333\n collectionPrefix: mgrep_\n\n" >> "$(CONFIG_FILE)"; \
printf "embeddings:\n provider: ollama\n model: $$emb_model\n baseUrl: $$ollama_url\n batchSize: 100\n timeoutMs: 30000\n maxRetries: 3\n\n" >> "$(CONFIG_FILE)"; \
printf "llm:\n provider: ollama\n model: $$llm_model\n baseUrl: $$ollama_url\n temperature: 0.7\n maxTokens: 4096\n timeoutMs: 60000\n maxRetries: 3\n\n" >> "$(CONFIG_FILE)"; \
elif [ "$$provider" = "anthropic" ]; then \
printf "\n$(YELLOW)Note: Anthropic doesn't provide embeddings, using OpenAI for embeddings.$(NC)\n"; \
printf "# mgrep configuration - generated by make init-config\n\n" > "$(CONFIG_FILE)"; \
printf "qdrant:\n url: http://localhost:6333\n collectionPrefix: mgrep_\n\n" >> "$(CONFIG_FILE)"; \
printf "embeddings:\n provider: openai\n model: $$emb_model\n batchSize: 100\n timeoutMs: 30000\n maxRetries: 3\n\n" >> "$(CONFIG_FILE)"; \
printf "llm:\n provider: anthropic\n model: $$llm_model\n temperature: 0.7\n maxTokens: 4096\n timeoutMs: 60000\n maxRetries: 3\n\n" >> "$(CONFIG_FILE)"; \
else \
printf "# mgrep configuration - generated by make init-config\n\n" > "$(CONFIG_FILE)"; \
printf "qdrant:\n url: http://localhost:6333\n collectionPrefix: mgrep_\n\n" >> "$(CONFIG_FILE)"; \
printf "embeddings:\n provider: $$provider\n model: $$emb_model\n batchSize: 100\n timeoutMs: 30000\n maxRetries: 3\n\n" >> "$(CONFIG_FILE)"; \
printf "llm:\n provider: $$provider\n model: $$llm_model\n temperature: 0.7\n maxTokens: 4096\n timeoutMs: 60000\n maxRetries: 3\n\n" >> "$(CONFIG_FILE)"; \
fi; \
printf "sync:\n concurrency: 20\n\nmaxFileSize: 10485760\n" >> "$(CONFIG_FILE)"; \
printf "\n$(GREEN)Configuration saved to $(CONFIG_FILE)$(NC)\n"; \
printf "\n$(YELLOW)Required API keys (set as environment variables):$(NC)\n"; \
case "$$provider" in \
openai) printf " export OPENAI_API_KEY=sk-...\n";; \
google) printf " export GOOGLE_API_KEY=...\n";; \
anthropic) printf " export OPENAI_API_KEY=sk-... # for embeddings\n"; \
printf " export ANTHROPIC_API_KEY=sk-ant-...\n";; \
ollama) printf " (No API key needed for local Ollama)\n";; \
esac; \
printf "\n$(YELLOW)Don't forget to start Qdrant:$(NC) make qdrant-start\n"
version: ## Show current version
@node -p "require('./package.json').version"
release-patch: ## Bump patch version (0.0.X)
@npm version patch --no-git-tag-version
@printf "$(GREEN)Version bumped to $$(node -p "require('./package.json').version")$(NC)\n"
release-minor: ## Bump minor version (0.X.0)
@npm version minor --no-git-tag-version
@printf "$(GREEN)Version bumped to $$(node -p "require('./package.json').version")$(NC)\n"
release-major: ## Bump major version (X.0.0)
@npm version major --no-git-tag-version
@printf "$(GREEN)Version bumped to $$(node -p "require('./package.json').version")$(NC)\n"