forked from winfunc/opcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
388 lines (335 loc) · 16.9 KB
/
Makefile
File metadata and controls
388 lines (335 loc) · 16.9 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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
# Opcode - Claude Code GUI Application
# Makefile for development, build, and installation
# Configuration
SHELL := /bin/bash
.DEFAULT_GOAL := help
PROJECT_NAME := opcode
VERSION := $(shell grep '"version"' package.json | head -1 | cut -d'"' -f4)
BUILD_DIR := src-tauri/target
DIST_DIR := dist
INSTALL_DIR := /usr/local/bin
DESKTOP_DIR := /usr/share/applications
ICON_DIR := /usr/share/icons/hicolor
# Colors for output
CYAN := \033[36m
GREEN := \033[32m
YELLOW := \033[33m
RED := \033[31m
RESET := \033[0m
# Detect package manager (bun preferred, fallback to npm)
PKG_MGR := $(shell if command -v bun >/dev/null 2>&1; then echo "bun"; else echo "npm"; fi)
#==============================================================================
# HELP
#==============================================================================
.PHONY: help
help: ## Show this help message
@printf "\n"
@printf "$(CYAN)╔══════════════════════════════════════════════════════════════════╗$(RESET)\n"
@printf "$(CYAN)║$(RESET) $(GREEN)Opcode$(RESET) - Claude Code GUI Application (v$(VERSION)) $(CYAN)║$(RESET)\n"
@printf "$(CYAN)╚══════════════════════════════════════════════════════════════════╝$(RESET)\n"
@printf "\n"
@printf "$(YELLOW)Usage:$(RESET) make [target]\n"
@printf "\n"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " $(CYAN)%-20s$(RESET) %s\n", $$1, $$2}'
@printf "\n"
#==============================================================================
# DEVELOPMENT
#==============================================================================
.PHONY: dev
dev: deps ## Run in development mode with hot reload
@printf "$(GREEN)▶ Starting Tauri development server...$(RESET)\n"
$(PKG_MGR) run tauri dev
.PHONY: run
run: build-frontend ## Build frontend and run desktop app
@printf "$(GREEN)▶ Running Opcode desktop app...$(RESET)\n"
cd src-tauri && cargo run
.PHONY: web
web: build-frontend ## Run web server mode (phone access on port 8080)
@printf "$(GREEN)▶ Starting web server on http://localhost:8080$(RESET)\n"
@printf "$(YELLOW)📱 Access from phone using your local IP$(RESET)\n"
cd src-tauri && cargo run --bin opcode-web
.PHONY: web-port
web-port: build-frontend ## Run web server on custom port (usage: make web-port PORT=3000)
@printf "$(GREEN)▶ Starting web server on http://localhost:$(PORT)$(RESET)\n"
cd src-tauri && cargo run --bin opcode-web -- --port $(PORT)
#==============================================================================
# BUILD
#==============================================================================
.PHONY: deps
deps: ## Install all dependencies
@printf "$(GREEN)▶ Installing frontend dependencies...$(RESET)\n"
$(PKG_MGR) install
.PHONY: build
build: deps build-frontend build-backend ## Build everything (frontend + backend)
@printf "$(GREEN)✓ Full build complete$(RESET)\n"
.PHONY: build-frontend
build-frontend: ## Build React frontend
@printf "$(GREEN)▶ Building frontend...$(RESET)\n"
$(PKG_MGR) run build
.PHONY: build-backend
build-backend: ## Build Rust backend (debug)
@printf "$(GREEN)▶ Building backend (debug)...$(RESET)\n"
cd src-tauri && cargo build
.PHONY: build-release
build-release: deps build-frontend ## Build release version
@printf "$(GREEN)▶ Building release...$(RESET)\n"
cd src-tauri && cargo build --release
@printf "$(GREEN)✓ Release build at: src-tauri/target/release/opcode$(RESET)\n"
.PHONY: build-tauri
build-tauri: deps build-frontend ## Build Tauri app bundle
@printf "$(GREEN)▶ Building Tauri app bundle...$(RESET)\n"
$(PKG_MGR) run tauri build
@printf "$(GREEN)✓ App bundle created in src-tauri/target/release/bundle$(RESET)\n"
.PHONY: build-deb
build-deb: deps build-frontend ## Build Debian package
@printf "$(GREEN)▶ Building .deb package...$(RESET)\n"
$(PKG_MGR) run tauri build --bundles deb
@printf "$(GREEN)✓ .deb package created$(RESET)\n"
.PHONY: build-appimage
build-appimage: deps build-frontend ## Build AppImage
@printf "$(GREEN)▶ Building AppImage...$(RESET)\n"
$(PKG_MGR) run tauri build --bundles appimage
@printf "$(GREEN)✓ AppImage created$(RESET)\n"
#==============================================================================
# QUALITY ASSURANCE
#==============================================================================
.PHONY: check
check: ## Run all checks (TypeScript + Rust)
@printf "$(GREEN)▶ Running TypeScript check...$(RESET)\n"
$(PKG_MGR) run check
@printf "$(GREEN)✓ All checks passed$(RESET)\n"
.PHONY: check-ts
check-ts: ## TypeScript type check only
@printf "$(GREEN)▶ Checking TypeScript...$(RESET)\n"
bunx tsc --noEmit
.PHONY: check-rust
check-rust: ## Rust check only
@printf "$(GREEN)▶ Checking Rust...$(RESET)\n"
cd src-tauri && cargo check
.PHONY: test
test: ## Run all tests
@printf "$(GREEN)▶ Running Rust tests...$(RESET)\n"
cd src-tauri && cargo test
@printf "$(GREEN)✓ All tests passed$(RESET)\n"
.PHONY: test-verbose
test-verbose: ## Run tests with verbose output
@printf "$(GREEN)▶ Running Rust tests (verbose)...$(RESET)\n"
cd src-tauri && cargo test -- --nocapture
.PHONY: lint
lint: ## Run linters (warnings allowed)
@printf "$(GREEN)▶ Running Rust clippy...$(RESET)\n"
cd src-tauri && cargo clippy 2>&1 | tail -20
@printf "$(GREEN)✓ Linting complete$(RESET)\n"
.PHONY: lint-strict
lint-strict: ## Run linters (fail on warnings - for CI)
@printf "$(GREEN)▶ Running Rust clippy (strict)...$(RESET)\n"
cd src-tauri && cargo clippy -- -D warnings
@printf "$(GREEN)✓ Linting passed$(RESET)\n"
.PHONY: fmt
fmt: ## Format all code
@printf "$(GREEN)▶ Formatting Rust code...$(RESET)\n"
cd src-tauri && cargo fmt
@printf "$(GREEN)✓ Code formatted$(RESET)\n"
.PHONY: fmt-check
fmt-check: ## Check code formatting without changes
@printf "$(GREEN)▶ Checking code format...$(RESET)\n"
cd src-tauri && cargo fmt --check
.PHONY: validate
validate: check test lint fmt-check ## Run full validation (check + test + lint + fmt)
@printf "$(GREEN)✓ All validations passed$(RESET)\n"
.PHONY: validate-strict
validate-strict: check test lint-strict fmt-check ## Strict validation for CI (fails on warnings)
@printf "$(GREEN)✓ All strict validations passed$(RESET)\n"
#==============================================================================
# CLEAN
#==============================================================================
.PHONY: clean
clean: ## Clean all build artifacts
@printf "$(YELLOW)▶ Cleaning build artifacts...$(RESET)\n"
rm -rf node_modules $(DIST_DIR) .vite
cd src-tauri && cargo clean
@printf "$(GREEN)✓ Clean complete$(RESET)\n"
.PHONY: clean-frontend
clean-frontend: ## Clean frontend only
@printf "$(YELLOW)▶ Cleaning frontend...$(RESET)\n"
rm -rf node_modules $(DIST_DIR) .vite
.PHONY: clean-backend
clean-backend: ## Clean backend only
@printf "$(YELLOW)▶ Cleaning backend...$(RESET)\n"
cd src-tauri && cargo clean
.PHONY: rebuild
rebuild: clean build ## Full clean rebuild
#==============================================================================
# INSTALLATION (System-wide)
#==============================================================================
.PHONY: install
install: build-release ## Install to system (/usr/local/bin)
@printf "$(GREEN)▶ Installing Opcode to $(INSTALL_DIR)...$(RESET)\n"
@sudo install -Dm755 src-tauri/target/release/opcode $(INSTALL_DIR)/opcode
@sudo install -Dm755 src-tauri/target/release/opcode-web $(INSTALL_DIR)/opcode-web 2>/dev/null || true
@printf "$(GREEN)▶ Installing desktop entry...$(RESET)\n"
@sudo mkdir -p $(DESKTOP_DIR)
@printf "[Desktop Entry]\nName=Opcode\nComment=Claude Code GUI Application\nExec=$(INSTALL_DIR)/opcode\nIcon=opcode\nTerminal=false\nType=Application\nCategories=Development;IDE;\nKeywords=claude;ai;code;assistant;\n" | sudo tee $(DESKTOP_DIR)/opcode.desktop > /dev/null
@if [ -f "src-tauri/icons/icon.png" ]; then \
sudo mkdir -p $(ICON_DIR)/256x256/apps && \
sudo install -Dm644 src-tauri/icons/icon.png $(ICON_DIR)/256x256/apps/opcode.png && \
sudo gtk-update-icon-cache $(ICON_DIR) 2>/dev/null || true; \
fi
@sudo update-desktop-database $(DESKTOP_DIR) 2>/dev/null || true
@printf "$(GREEN)✓ Installation complete$(RESET)\n"
@printf "$(CYAN) Run 'opcode' to start the application$(RESET)\n"
.PHONY: install-user
install-user: build-release ## Install to user directory (~/.local/bin)
@printf "$(GREEN)▶ Installing Opcode to ~/.local/bin...$(RESET)\n"
@mkdir -p ~/.local/bin
@install -m755 src-tauri/target/release/opcode ~/.local/bin/opcode
@install -m755 src-tauri/target/release/opcode-web ~/.local/bin/opcode-web 2>/dev/null || true
@mkdir -p ~/.local/share/applications
@printf "[Desktop Entry]\nName=Opcode\nComment=Claude Code GUI Application\nExec=%s/.local/bin/opcode\nIcon=opcode\nTerminal=false\nType=Application\nCategories=Development;IDE;\n" "$$HOME" > ~/.local/share/applications/opcode.desktop
@if [ -f "src-tauri/icons/icon.png" ]; then \
mkdir -p ~/.local/share/icons/hicolor/256x256/apps && \
install -m644 src-tauri/icons/icon.png ~/.local/share/icons/hicolor/256x256/apps/opcode.png; \
fi
@printf "$(GREEN)✓ User installation complete$(RESET)\n"
@printf "$(CYAN) Ensure ~/.local/bin is in your PATH$(RESET)\n"
.PHONY: uninstall
uninstall: ## Uninstall from system
@printf "$(YELLOW)▶ Uninstalling Opcode from system...$(RESET)\n"
@sudo rm -f $(INSTALL_DIR)/opcode
@sudo rm -f $(INSTALL_DIR)/opcode-web
@sudo rm -f $(DESKTOP_DIR)/opcode.desktop
@sudo rm -f $(ICON_DIR)/256x256/apps/opcode.png
@sudo update-desktop-database $(DESKTOP_DIR) 2>/dev/null || true
@printf "$(GREEN)✓ System uninstall complete$(RESET)\n"
.PHONY: uninstall-user
uninstall-user: ## Uninstall from user directory
@printf "$(YELLOW)▶ Uninstalling Opcode from user directory...$(RESET)\n"
@rm -f ~/.local/bin/opcode
@rm -f ~/.local/bin/opcode-web
@rm -f ~/.local/share/applications/opcode.desktop
@rm -f ~/.local/share/icons/hicolor/256x256/apps/opcode.png
@printf "$(GREEN)✓ User uninstall complete$(RESET)\n"
#==============================================================================
# STATUS & INFO
#==============================================================================
.PHONY: status
status: ## Show project status and information
@printf "\n"
@printf "$(CYAN)╔══════════════════════════════════════════════════════════════════╗$(RESET)\n"
@printf "$(CYAN)║$(RESET) $(GREEN)Opcode$(RESET) - Project Status $(CYAN)║$(RESET)\n"
@printf "$(CYAN)╚══════════════════════════════════════════════════════════════════╝$(RESET)\n"
@printf "\n"
@printf "$(YELLOW)Version:$(RESET) $(VERSION)\n"
@printf "$(YELLOW)Package Manager:$(RESET) $(PKG_MGR)\n"
@printf "\n"
@printf "$(YELLOW)Installation Status:$(RESET)\n"
@if command -v opcode &>/dev/null; then \
printf " $(GREEN)✓$(RESET) System: %s\n" "$$(which opcode)"; \
else \
printf " $(RED)✗$(RESET) System: Not installed\n"; \
fi
@if [ -f ~/.local/bin/opcode ]; then \
printf " $(GREEN)✓$(RESET) User: ~/.local/bin/opcode\n"; \
else \
printf " $(RED)✗$(RESET) User: Not installed\n"; \
fi
@printf "\n"
@printf "$(YELLOW)Build Artifacts:$(RESET)\n"
@if [ -d "$(DIST_DIR)" ]; then \
printf " $(GREEN)✓$(RESET) Frontend: $(DIST_DIR)/ exists\n"; \
else \
printf " $(RED)✗$(RESET) Frontend: Not built\n"; \
fi
@if [ -f "src-tauri/target/debug/opcode" ]; then \
printf " $(GREEN)✓$(RESET) Backend (debug): exists\n"; \
else \
printf " $(RED)✗$(RESET) Backend (debug): Not built\n"; \
fi
@if [ -f "src-tauri/target/release/opcode" ]; then \
printf " $(GREEN)✓$(RESET) Backend (release): exists\n"; \
else \
printf " $(RED)✗$(RESET) Backend (release): Not built\n"; \
fi
@printf "\n"
@printf "$(YELLOW)Dependencies:$(RESET)\n"
@if [ -d "node_modules" ]; then \
printf " $(GREEN)✓$(RESET) node_modules: installed\n"; \
else \
printf " $(RED)✗$(RESET) node_modules: not installed (run 'make deps')\n"; \
fi
@printf "\n"
@printf "$(YELLOW)Git Status:$(RESET)\n"
@printf " Branch: %s\n" "$$(git branch --show-current 2>/dev/null || echo 'N/A')"
@printf " Last commit: %s\n" "$$(git log -1 --format='%h %s' 2>/dev/null || echo 'N/A')"
@printf " Uncommitted changes: %s files\n" "$$(git status --porcelain 2>/dev/null | wc -l)"
@printf "\n"
.PHONY: info
info: ## Show project information
@printf "\n"
@printf "$(CYAN)╔══════════════════════════════════════════════════════════════════╗$(RESET)\n"
@printf "$(CYAN)║$(RESET) $(GREEN)Opcode$(RESET) - Claude Code GUI Application $(CYAN)║$(RESET)\n"
@printf "$(CYAN)╚══════════════════════════════════════════════════════════════════╝$(RESET)\n"
@printf "\n"
@printf "$(YELLOW)Technology Stack:$(RESET)\n"
@printf " 📦 Frontend: React 18 + TypeScript + Vite 6 + Tailwind CSS v4\n"
@printf " 🦀 Backend: Rust + Tauri 2\n"
@printf " 🌍 i18n: 12 languages (i18next)\n"
@printf " 🗃️ Database: SQLite (agents, usage)\n"
@printf "\n"
@printf "$(YELLOW)Features:$(RESET)\n"
@printf " • Interactive Claude Code sessions\n"
@printf " • CC Agents (custom AI agents)\n"
@printf " • MCP server management\n"
@printf " • Token usage analytics\n"
@printf " • Session checkpoints\n"
@printf " • Web server mode (phone access)\n"
@printf " • Filesystem agent loading (~/.claude/agents/)\n"
@printf " • Environment variable groups\n"
@printf "\n"
@printf "$(YELLOW)Quick Start:$(RESET)\n"
@printf " make dev - Development with hot reload\n"
@printf " make run - Build and run desktop app\n"
@printf " make web - Web server for phone access\n"
@printf " make install - Install system-wide\n"
@printf "\n"
.PHONY: ip
ip: ## Show local IP for phone access
@printf "$(CYAN)🌐 Your PC's IP addresses:$(RESET)\n"
@ip route get 1.1.1.1 2>/dev/null | grep -oP 'src \K\S+' || hostname -I | awk '{print $$1}'
@printf "\n"
@printf "$(YELLOW)📱 Access from phone: http://YOUR_IP:8080$(RESET)\n"
.PHONY: doctor
doctor: ## Check system requirements
@printf "$(CYAN)🔍 Checking system requirements...$(RESET)\n"
@printf "\n"
@printf "$(YELLOW)Required Tools:$(RESET)\n"
@command -v node >/dev/null 2>&1 && printf " $(GREEN)✓$(RESET) Node.js: %s\n" "$$(node --version)" || printf " $(RED)✗$(RESET) Node.js: not found\n"
@command -v bun >/dev/null 2>&1 && printf " $(GREEN)✓$(RESET) Bun: %s\n" "$$(bun --version)" || printf " $(YELLOW)○$(RESET) Bun: not found (using npm)\n"
@command -v npm >/dev/null 2>&1 && printf " $(GREEN)✓$(RESET) npm: %s\n" "$$(npm --version)" || printf " $(RED)✗$(RESET) npm: not found\n"
@command -v cargo >/dev/null 2>&1 && printf " $(GREEN)✓$(RESET) Cargo: %s\n" "$$(cargo --version | cut -d' ' -f2)" || printf " $(RED)✗$(RESET) Cargo: not found\n"
@command -v rustc >/dev/null 2>&1 && printf " $(GREEN)✓$(RESET) Rust: %s\n" "$$(rustc --version | cut -d' ' -f2)" || printf " $(RED)✗$(RESET) Rust: not found\n"
@printf "\n"
@printf "$(YELLOW)Optional Tools:$(RESET)\n"
@command -v claude >/dev/null 2>&1 && printf " $(GREEN)✓$(RESET) Claude Code: installed\n" || printf " $(YELLOW)○$(RESET) Claude Code: not found (required at runtime)\n"
@command -v just >/dev/null 2>&1 && printf " $(GREEN)✓$(RESET) Just: %s\n" "$$(just --version | cut -d' ' -f2)" || printf " $(YELLOW)○$(RESET) Just: not found (alternative to make)\n"
@printf "\n"
@printf "$(YELLOW)Tauri Dependencies (Linux):$(RESET)\n"
@pkg-config --exists webkit2gtk-4.1 2>/dev/null && printf " $(GREEN)✓$(RESET) webkit2gtk-4.1\n" || printf " $(RED)✗$(RESET) webkit2gtk-4.1\n"
@pkg-config --exists gtk+-3.0 2>/dev/null && printf " $(GREEN)✓$(RESET) gtk+-3.0\n" || printf " $(RED)✗$(RESET) gtk+-3.0\n"
@pkg-config --exists libsoup-3.0 2>/dev/null && printf " $(GREEN)✓$(RESET) libsoup-3.0\n" || printf " $(RED)✗$(RESET) libsoup-3.0\n"
@printf "\n"
#==============================================================================
# SHORTCUTS
#==============================================================================
.PHONY: d
d: dev ## Alias for 'dev'
.PHONY: r
r: run ## Alias for 'run'
.PHONY: t
t: test ## Alias for 'test'
.PHONY: c
c: check ## Alias for 'check'
.PHONY: b
b: build ## Alias for 'build'
.PHONY: s
s: status ## Alias for 'status'