cyx 0.3.0

Fast, simple command-line security tool powered by AI. Install with cargo, setup in 30 seconds.
Documentation
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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
# Cyx Makefile - Cross-platform build and development automation

# Detect operating system
UNAME_S := $(shell uname -s 2>/dev/null || echo Windows)
UNAME_M := $(shell uname -m 2>/dev/null || echo unknown)

# OS-specific configuration
ifeq ($(UNAME_S),Linux)
    OS := linux
    BINARY_EXT :=
    SYMLINK_CMD := ln -sf
    INSTALL_DIR := /usr/local/bin
    SHELL_DETECT := $(shell echo $$SHELL)
endif

ifeq ($(UNAME_S),Darwin)
    OS := macos
    BINARY_EXT :=
    SYMLINK_CMD := ln -sf
    INSTALL_DIR := /usr/local/bin
    SHELL_DETECT := $(shell echo $$SHELL)
endif

ifeq ($(UNAME_S),Windows)
    OS := windows
    BINARY_EXT := .exe
    SYMLINK_CMD := copy
    INSTALL_DIR := C:\Program Files\cyx
    SHELL_DETECT := cmd
endif

ifneq (,$(findstring MINGW,$(UNAME_S)))
    OS := windows
    BINARY_EXT := .exe
    SYMLINK_CMD := cp -f
    INSTALL_DIR := /usr/local/bin
    SHELL_DETECT := bash
endif

ifneq (,$(findstring MSYS,$(UNAME_S)))
    OS := windows
    BINARY_EXT := .exe
    SYMLINK_CMD := cp -f
    INSTALL_DIR := /usr/local/bin
    SHELL_DETECT := bash
endif

ifneq (,$(findstring CYGWIN,$(UNAME_S)))
    OS := windows
    BINARY_EXT := .exe
    SYMLINK_CMD := cp -f
    INSTALL_DIR := /usr/local/bin
    SHELL_DETECT := bash
endif

# Project configuration
BINARY_NAME := cyx$(BINARY_EXT)
TARGET_DIR := target/release
BINARY_PATH := $(TARGET_DIR)/$(BINARY_NAME)
BINARY_ABS_PATH := $(shell pwd)/$(BINARY_PATH)
SYSTEM_SYMLINK := $(INSTALL_DIR)/$(BINARY_NAME)

# Cargo configuration
CARGO := cargo
CARGO_BUILD_FLAGS := --release
CARGO_FMT_FLAGS := --all
CARGO_CLIPPY_FLAGS := --all-targets --all-features -- -D warnings

# Colors for output (using tput if available)
RED := \033[0;31m
GREEN := \033[0;32m
YELLOW := \033[0;33m
BLUE := \033[0;34m
MAGENTA := \033[0;35m
CYAN := \033[0;36m
DIMMED := \033[2m
RESET := \033[0m

# Default target
.DEFAULT_GOAL := help

.PHONY: help
help: ## Show this help message
	@echo "$(CYAN)╔════════════════════════════════════════════════════════════╗$(RESET)"
	@echo "$(CYAN)$(RESET)  $(MAGENTA)Cyx - Cybersecurity Companion Makefile$(RESET)              $(CYAN)$(RESET)"
	@echo "$(CYAN)╚════════════════════════════════════════════════════════════╝$(RESET)"
	@echo ""
	@echo "$(BLUE)Detected OS:$(RESET) $(GREEN)$(OS)$(RESET) ($(UNAME_S))"
	@echo "$(BLUE)Architecture:$(RESET) $(GREEN)$(UNAME_M)$(RESET)"
	@echo "$(BLUE)Binary:$(RESET) $(GREEN)$(BINARY_NAME)$(RESET)"
	@echo ""
	@echo "$(YELLOW)Available targets:$(RESET)"
	@echo ""
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "  $(GREEN)%-15s$(RESET) %s\n", $$1, $$2}'
	@echo ""

.PHONY: info
info: ## Display system and project information
	@echo "$(CYAN)═══════════════════════════════════════════════════════════$(RESET)"
	@echo "$(MAGENTA)System Information$(RESET)"
	@echo "$(CYAN)═══════════════════════════════════════════════════════════$(RESET)"
	@echo "$(BLUE)Operating System:$(RESET)     $(GREEN)$(OS)$(RESET)"
	@echo "$(BLUE)Platform:$(RESET)             $(GREEN)$(UNAME_S)$(RESET)"
	@echo "$(BLUE)Architecture:$(RESET)         $(GREEN)$(UNAME_M)$(RESET)"
	@echo "$(BLUE)Shell:$(RESET)                $(GREEN)$(SHELL_DETECT)$(RESET)"
	@echo ""
	@echo "$(CYAN)═══════════════════════════════════════════════════════════$(RESET)"
	@echo "$(MAGENTA)Project Configuration$(RESET)"
	@echo "$(CYAN)═══════════════════════════════════════════════════════════$(RESET)"
	@echo "$(BLUE)Binary Name:$(RESET)          $(GREEN)$(BINARY_NAME)$(RESET)"
	@echo "$(BLUE)Binary Path:$(RESET)          $(GREEN)$(BINARY_PATH)$(RESET)"
	@echo "$(BLUE)System Symlink:$(RESET)       $(GREEN)$(SYSTEM_SYMLINK)$(RESET) $(BLUE)$(RESET) $(GREEN)$(BINARY_ABS_PATH)$(RESET)"
	@echo "$(BLUE)Install Directory:$(RESET)    $(GREEN)$(INSTALL_DIR)$(RESET)"
	@echo ""
	@echo "$(CYAN)═══════════════════════════════════════════════════════════$(RESET)"
	@echo "$(MAGENTA)Rust Toolchain$(RESET)"
	@echo "$(CYAN)═══════════════════════════════════════════════════════════$(RESET)"
	@which rustc > /dev/null && rustc --version || echo "$(RED)Rust not found!$(RESET)"
	@which cargo > /dev/null && cargo --version || echo "$(RED)Cargo not found!$(RESET)"
	@echo ""

.PHONY: check-rust
check-rust: ## Check if Rust is installed
	@echo "$(BLUE)Checking Rust installation...$(RESET)"
	@which rustc > /dev/null || (echo "$(RED)Error: Rust is not installed. Install from https://rustup.rs/$(RESET)" && exit 1)
	@which cargo > /dev/null || (echo "$(RED)Error: Cargo is not installed.$(RESET)" && exit 1)
	@echo "$(GREEN)✓ Rust is installed$(RESET)"
	@rustc --version
	@cargo --version

.PHONY: deps
deps: check-rust ## Check and install dependencies
	@echo "$(BLUE)Checking dependencies...$(RESET)"
	@$(CARGO) --version > /dev/null 2>&1 || (echo "$(RED)Error: Cargo not found$(RESET)" && exit 1)
	@echo "$(GREEN)✓ All dependencies satisfied$(RESET)"

.PHONY: build
build: deps ## Build the release binary and update symlink
	@echo "$(CYAN)╔════════════════════════════════════════════════════════════╗$(RESET)"
	@echo "$(CYAN)$(RESET)  $(MAGENTA)Building Cyx (Release Mode)$(RESET)                          $(CYAN)$(RESET)"
	@echo "$(CYAN)╚════════════════════════════════════════════════════════════╝$(RESET)"
	@echo ""
	@$(CARGO) build $(CARGO_BUILD_FLAGS)
	@echo ""
	@echo "$(GREEN)✓ Build completed successfully!$(RESET)"
	@echo ""
	@$(MAKE) --no-print-directory symlink

.PHONY: build-dev
build-dev: deps ## Build the debug binary (faster compilation)
	@echo "$(CYAN)╔════════════════════════════════════════════════════════════╗$(RESET)"
	@echo "$(CYAN)$(RESET)  $(MAGENTA)Building Cyx (Debug Mode)$(RESET)                            $(CYAN)$(RESET)"
	@echo "$(CYAN)╚════════════════════════════════════════════════════════════╝$(RESET)"
	@echo ""
	@$(CARGO) build
	@echo ""
	@echo "$(GREEN)✓ Debug build completed!$(RESET)"

.PHONY: symlink
symlink: ## Create/update system symlink to development binary
	@echo "$(BLUE)Creating system symlink: $(RESET)$(SYSTEM_SYMLINK) $(BLUE)$(RESET) $(BINARY_ABS_PATH)"
	@if [ ! -f "$(BINARY_PATH)" ]; then \
		echo "$(RED)Error: Binary not found at $(BINARY_PATH)$(RESET)"; \
		echo "$(YELLOW)Run 'make build' first$(RESET)"; \
		exit 1; \
	fi
	@if [ ! -d "$(INSTALL_DIR)" ]; then \
		echo "$(YELLOW)Creating directory: $(INSTALL_DIR)$(RESET)"; \
		sudo mkdir -p $(INSTALL_DIR); \
	fi
	@sudo rm -f $(SYSTEM_SYMLINK)
	@sudo ln -sf $(BINARY_ABS_PATH) $(SYSTEM_SYMLINK)
	@echo "$(GREEN)✓ System symlink created: $(SYSTEM_SYMLINK)$(RESET)"
	@echo ""
	@echo "$(YELLOW)You can now run: $(RESET)$(GREEN)cyx$(RESET) $(YELLOW)from anywhere!$(RESET)"
	@echo "$(YELLOW)Changes to $(BINARY_PATH) will be used immediately$(RESET)"
	@echo ""

.PHONY: path-info
path-info: ## Show symlink status and installation info
	@echo "$(CYAN)╔════════════════════════════════════════════════════════════╗$(RESET)"
	@echo "$(CYAN)$(RESET)  $(MAGENTA)Cyx Installation Status$(RESET)                             $(CYAN)$(RESET)"
	@echo "$(CYAN)╚════════════════════════════════════════════════════════════╝$(RESET)"
	@echo ""
	@echo "$(BLUE)System Symlink:$(RESET)"
	@if [ -L "$(SYSTEM_SYMLINK)" ]; then \
		echo "  $(GREEN)✓ Installed$(RESET) at $(SYSTEM_SYMLINK)"; \
		echo "  $(BLUE)$(RESET) Points to: $$(readlink $(SYSTEM_SYMLINK))"; \
	else \
		echo "  $(YELLOW)✗ Not installed$(RESET)"; \
		echo "  Run $(GREEN)make build$(RESET) to create development symlink"; \
	fi
	@echo ""
	@echo "$(BLUE)Cargo Install:$(RESET)"
	@if command -v cyx >/dev/null 2>&1 && [ "$$(command -v cyx)" != "$(SYSTEM_SYMLINK)" ]; then \
		echo "  $(GREEN)✓ Installed$(RESET) at $$(command -v cyx)"; \
	else \
		echo "  $(YELLOW)✗ Not installed$(RESET)"; \
		echo "  Run $(GREEN)make install$(RESET) for production installation"; \
	fi
	@echo ""

.PHONY: install
install: ## Complete installation - builds, installs binary and dependencies
	@echo "$(CYAN)╔════════════════════════════════════════════════════════════╗$(RESET)"
	@echo "$(CYAN)$(RESET)  $(MAGENTA)Installing Cyx - Complete Setup$(RESET)                     $(CYAN)$(RESET)"
	@echo "$(CYAN)╚════════════════════════════════════════════════════════════╝$(RESET)"
	@echo ""
	@echo "$(BLUE)Step 1/4: Building release binary...$(RESET)"
	@$(CARGO) build $(CARGO_BUILD_FLAGS)
	@echo "$(GREEN)✓ Build complete$(RESET)"
	@echo ""
	@echo "$(BLUE)Step 2/4: Installing binary to system PATH...$(RESET)"
	@$(CARGO) install --path . --force
	@echo "$(GREEN)✓ Binary installed$(RESET)"
	@echo ""
	@echo "$(BLUE)Step 3/4: Installing ONNX Runtime library...$(RESET)"
	@INSTALL_DIR=$$(dirname $$(which cyx 2>/dev/null || echo "$$HOME/.cargo/bin/cyx")) && \
	echo "  Installation directory: $$INSTALL_DIR" && \
	if [ -f "$(TARGET_DIR)/libonnxruntime.1.16.0.dylib" ]; then \
		cp "$(TARGET_DIR)/libonnxruntime.1.16.0.dylib" "$$INSTALL_DIR/" && \
		cp "$(TARGET_DIR)/libonnxruntime.dylib" "$$INSTALL_DIR/" 2>/dev/null || true && \
		echo "$(GREEN)  ✓ Copied ONNX Runtime library (macOS)$(RESET)"; \
	elif [ -f "$(TARGET_DIR)/libonnxruntime.so.1.16.0" ]; then \
		cp "$(TARGET_DIR)/libonnxruntime.so.1.16.0" "$$INSTALL_DIR/" && \
		cp "$(TARGET_DIR)/libonnxruntime.so" "$$INSTALL_DIR/" 2>/dev/null || true && \
		echo "$(GREEN)  ✓ Copied ONNX Runtime library (Linux)$(RESET)"; \
	elif [ -f "$(TARGET_DIR)/onnxruntime.dll" ]; then \
		cp "$(TARGET_DIR)/onnxruntime.dll" "$$INSTALL_DIR/" && \
		echo "$(GREEN)  ✓ Copied ONNX Runtime library (Windows)$(RESET)"; \
	else \
		echo "$(YELLOW)  ⚠ ONNX Runtime library not found in build directory$(RESET)"; \
		echo "$(YELLOW)  → Will be auto-fixed when you run 'cyx setup'$(RESET)"; \
	fi
	@echo ""
	@echo "$(BLUE)Step 4/4: Verifying installation...$(RESET)"
	@if command -v cyx >/dev/null 2>&1; then \
		INSTALLED_PATH=$$(which cyx) && \
		echo "$(GREEN)  ✓ Binary location: $$INSTALLED_PATH$(RESET)" && \
		cyx --version && \
		echo ""; \
	else \
		echo "$(RED)  ✗ cyx not found in PATH$(RESET)"; \
		echo "$(YELLOW)  → Add ~/.cargo/bin to your PATH$(RESET)"; \
		exit 1; \
	fi
	@echo "$(CYAN)═══════════════════════════════════════════════════════════$(RESET)"
	@echo "$(GREEN)✓ Installation Complete!$(RESET)"
	@echo "$(CYAN)═══════════════════════════════════════════════════════════$(RESET)"
	@echo ""
	@echo "$(MAGENTA)Next steps:$(RESET)"
	@echo "  1. Run: $(CYAN)cyx setup$(RESET)"
	@echo "     $(DIMMED)(Configure API keys - auto-fixes any ONNX issues)$(RESET)"
	@echo ""
	@echo "  2. Test: $(CYAN)cyx doctor$(RESET)"
	@echo "     $(DIMMED)(Check system health)$(RESET)"
	@echo ""
	@echo "  3. Try: $(CYAN)cyx \"nmap stealth scan\"$(RESET)"
	@echo ""
	@echo "$(YELLOW)The binary works from anywhere in your system!$(RESET)"
	@echo "$(YELLOW)All data files are embedded - no external dependencies needed.$(RESET)"
	@echo ""

.PHONY: uninstall
uninstall: ## Remove symlink and uninstall from system
	@echo "$(YELLOW)Removing system symlink and installed binary...$(RESET)"
	@sudo rm -f $(SYSTEM_SYMLINK) && echo "$(GREEN)✓ Symlink removed$(RESET)" || echo "$(YELLOW)No symlink found$(RESET)"
	@$(CARGO) uninstall cyx 2>/dev/null && echo "$(GREEN)✓ Binary uninstalled$(RESET)" || echo "$(YELLOW)No installed binary found$(RESET)"
	@echo "$(GREEN)✓ Uninstall complete$(RESET)"

.PHONY: check
check: ## Run cargo fmt and clippy with detailed reports
	@echo "$(CYAN)╔════════════════════════════════════════════════════════════╗$(RESET)"
	@echo "$(CYAN)$(RESET)  $(MAGENTA)Code Quality Check$(RESET)                                   $(CYAN)$(RESET)"
	@echo "$(CYAN)╚════════════════════════════════════════════════════════════╝$(RESET)"
	@echo ""
	@echo "$(YELLOW)┌─ Running cargo fmt check...$(RESET)"
	@echo "$(YELLOW)└────────────────────────────────────────────────────────────$(RESET)"
	@$(CARGO) fmt $(CARGO_FMT_FLAGS) -- --check && \
		echo "$(GREEN)✓ Code formatting is correct$(RESET)" || \
		(echo "$(RED)✗ Code formatting issues found!$(RESET)" && \
		 echo "$(YELLOW)  Run 'make fmt' to fix formatting$(RESET)" && \
		 echo "" && exit 1)
	@echo ""
	@echo "$(YELLOW)┌─ Running cargo clippy...$(RESET)"
	@echo "$(YELLOW)└────────────────────────────────────────────────────────────$(RESET)"
	@$(CARGO) clippy $(CARGO_CLIPPY_FLAGS) && \
		echo "$(GREEN)✓ No clippy warnings$(RESET)" || \
		(echo "$(RED)✗ Clippy found issues!$(RESET)" && \
		 echo "$(YELLOW)  Review the warnings above and fix them$(RESET)" && \
		 echo "" && exit 1)
	@echo ""
	@echo "$(CYAN)═══════════════════════════════════════════════════════════$(RESET)"
	@echo "$(GREEN)✓ All checks passed!$(RESET)"
	@echo "$(CYAN)═══════════════════════════════════════════════════════════$(RESET)"
	@echo ""

.PHONY: check-verbose
check-verbose: ## Run detailed code quality checks with full output
	@echo "$(CYAN)╔════════════════════════════════════════════════════════════╗$(RESET)"
	@echo "$(CYAN)$(RESET)  $(MAGENTA)Detailed Code Quality Report$(RESET)                        $(CYAN)$(RESET)"
	@echo "$(CYAN)╚════════════════════════════════════════════════════════════╝$(RESET)"
	@echo ""
	@echo "$(YELLOW)┌─────────────────────────────────────────────────────────┐$(RESET)"
	@echo "$(YELLOW)$(RESET) 1/3 Checking code formatting...                      $(YELLOW)$(RESET)"
	@echo "$(YELLOW)└─────────────────────────────────────────────────────────┘$(RESET)"
	@$(CARGO) fmt $(CARGO_FMT_FLAGS) -- --check --verbose && \
		echo "$(GREEN)✓ All files are properly formatted$(RESET)" || \
		(echo "$(RED)✗ Formatting issues detected:$(RESET)" && \
		 echo "" && \
		 echo "$(YELLOW)Files that need formatting:$(RESET)" && \
		 $(CARGO) fmt $(CARGO_FMT_FLAGS) -- --check --files-with-diff 2>&1 || true && \
		 echo "" && \
		 echo "$(YELLOW)Run 'make fmt' to auto-fix these issues$(RESET)" && \
		 echo "" && exit 1)
	@echo ""
	@echo "$(YELLOW)┌─────────────────────────────────────────────────────────┐$(RESET)"
	@echo "$(YELLOW)$(RESET) 2/3 Running clippy (all targets)...                  $(YELLOW)$(RESET)"
	@echo "$(YELLOW)└─────────────────────────────────────────────────────────┘$(RESET)"
	@$(CARGO) clippy $(CARGO_CLIPPY_FLAGS) -v
	@echo ""
	@echo "$(YELLOW)┌─────────────────────────────────────────────────────────┐$(RESET)"
	@echo "$(YELLOW)$(RESET) 3/3 Checking for outdated dependencies...            $(YELLOW)$(RESET)"
	@echo "$(YELLOW)└─────────────────────────────────────────────────────────┘$(RESET)"
	@$(CARGO) outdated || echo "$(YELLOW)Note: Install cargo-outdated for this check: cargo install cargo-outdated$(RESET)"
	@echo ""
	@echo "$(CYAN)═══════════════════════════════════════════════════════════$(RESET)"
	@echo "$(GREEN)✓ Detailed check complete!$(RESET)"
	@echo "$(CYAN)═══════════════════════════════════════════════════════════$(RESET)"
	@echo ""

.PHONY: fmt
fmt: ## Auto-fix code formatting issues
	@echo "$(BLUE)Running cargo fmt to fix formatting...$(RESET)"
	@$(CARGO) fmt $(CARGO_FMT_FLAGS)
	@echo "$(GREEN)✓ Code formatted successfully!$(RESET)"

.PHONY: fix
fix: ## Auto-fix clippy warnings where possible
	@echo "$(BLUE)Running clippy with auto-fix...$(RESET)"
	@$(CARGO) clippy --fix --allow-dirty --allow-staged $(CARGO_CLIPPY_FLAGS) || true
	@echo "$(GREEN)✓ Auto-fix complete!$(RESET)"
	@echo "$(YELLOW)Note: Some issues may require manual fixes$(RESET)"

.PHONY: test
test: ## Run all tests
	@echo "$(CYAN)╔════════════════════════════════════════════════════════════╗$(RESET)"
	@echo "$(CYAN)$(RESET)  $(MAGENTA)Running Tests$(RESET)                                        $(CYAN)$(RESET)"
	@echo "$(CYAN)╚════════════════════════════════════════════════════════════╝$(RESET)"
	@echo ""
	@$(CARGO) test --all
	@echo ""
	@echo "$(GREEN)✓ All tests passed!$(RESET)"

.PHONY: test-verbose
test-verbose: ## Run tests with verbose output
	@echo "$(CYAN)Running tests (verbose mode)...$(RESET)"
	@$(CARGO) test --all --verbose -- --nocapture

.PHONY: clean
clean: ## Complete system cleanup - removes ALL cyx files, config, cache, and models
	@echo "$(RED)╔════════════════════════════════════════════════════════════╗$(RESET)"
	@echo "$(RED)$(RESET)  $(YELLOW)Complete Cyx System Cleanup$(RESET)                         $(RED)$(RESET)"
	@echo "$(RED)╚════════════════════════════════════════════════════════════╝$(RESET)"
	@echo ""
	@echo "$(YELLOW)⚠ WARNING: This will remove:$(RESET)"
	@echo "  - Build artifacts (target/)"
	@echo "  - Installed binary (~/.cargo/bin/cyx or /usr/local/bin/cyx)"
	@echo "  - ONNX Runtime libraries"
	@echo "  - Configuration (~/.config/cyx/)"
	@echo "  - Cache and downloaded models (~/.cache/cyx/)"
	@echo "  - System symlinks"
	@echo ""
	@bash -c 'read -p "Are you sure? [y/N] " -n 1 -r; \
	echo; \
	if [[ $$REPLY =~ ^[Yy]$$ ]]; then \
		echo "$(BLUE)Step 1/6: Cleaning build artifacts...$(RESET)"; \
		$(CARGO) clean && echo "$(GREEN)  ✓ Build artifacts removed$(RESET)" || true; \
		rm -f cyx 2>/dev/null || true; \
		echo ""; \
		echo "$(BLUE)Step 2/6: Removing installed binary...$(RESET)"; \
		if command -v cyx >/dev/null 2>&1; then \
			INSTALL_PATH=$$(which cyx); \
			rm -f "$$INSTALL_PATH" && echo "$(GREEN)  ✓ Removed: $$INSTALL_PATH$(RESET)" || echo "$(YELLOW)  ⚠ Failed to remove: $$INSTALL_PATH$(RESET)"; \
		else \
			echo "$(DIMMED)  Binary not found in PATH$(RESET)"; \
		fi; \
		rm -f ~/.cargo/bin/cyx 2>/dev/null && echo "$(GREEN)  ✓ Removed: ~/.cargo/bin/cyx$(RESET)" || true; \
		rm -f /usr/local/bin/cyx 2>/dev/null && echo "$(GREEN)  ✓ Removed: /usr/local/bin/cyx$(RESET)" || true; \
		echo ""; \
		echo "$(BLUE)Step 3/6: Removing ONNX Runtime libraries...$(RESET)"; \
		rm -f ~/.cargo/bin/libonnxruntime* 2>/dev/null && echo "$(GREEN)  ✓ Removed from ~/.cargo/bin/$(RESET)" || true; \
		rm -f /usr/local/bin/libonnxruntime* 2>/dev/null && echo "$(GREEN)  ✓ Removed from /usr/local/bin/$(RESET)" || true; \
		sudo rm -f /usr/local/lib/libonnxruntime* 2>/dev/null && echo "$(GREEN)  ✓ Removed from /usr/local/lib/$(RESET)" || true; \
		echo ""; \
		echo "$(BLUE)Step 4/6: Removing configuration...$(RESET)"; \
		if [ -d ~/.config/cyx ]; then \
			rm -rf ~/.config/cyx && echo "$(GREEN)  ✓ Removed: ~/.config/cyx/$(RESET)"; \
		else \
			echo "$(DIMMED)  No config directory found$(RESET)"; \
		fi; \
		echo ""; \
		echo "$(BLUE)Step 5/6: Removing cache and models...$(RESET)"; \
		if [ -d ~/.cache/cyx ]; then \
			CACHE_SIZE=$$(du -sh ~/.cache/cyx 2>/dev/null | cut -f1); \
			rm -rf ~/.cache/cyx && echo "$(GREEN)  ✓ Removed: ~/.cache/cyx/ ($$CACHE_SIZE)$(RESET)"; \
		else \
			echo "$(DIMMED)  No cache directory found$(RESET)"; \
		fi; \
		echo ""; \
		echo "$(BLUE)Step 6/6: Removing symlinks...$(RESET)"; \
		if [ -L "$(SYSTEM_SYMLINK)" ]; then \
			sudo rm -f $(SYSTEM_SYMLINK) && echo "$(GREEN)  ✓ Removed: $(SYSTEM_SYMLINK)$(RESET)"; \
		else \
			echo "$(DIMMED)  No symlink found$(RESET)"; \
		fi; \
		echo ""; \
		echo "$(GREEN)═══════════════════════════════════════════════════════════$(RESET)"; \
		echo "$(GREEN)✓ Complete cleanup finished!$(RESET)"; \
		echo "$(GREEN)═══════════════════════════════════════════════════════════$(RESET)"; \
		echo ""; \
		echo "$(CYAN)Cyx has been completely removed from your system.$(RESET)"; \
		echo "$(DIMMED)To reinstall: make install$(RESET)"; \
	else \
		echo "$(YELLOW)Cleanup cancelled.$(RESET)"; \
	fi'

.PHONY: clean-build
clean-build: ## Clean only build artifacts (keeps config and cache)
	@echo "$(YELLOW)Cleaning build artifacts...$(RESET)"
	@$(CARGO) clean
	@rm -f cyx 2>/dev/null || true
	@echo "$(GREEN)✓ Build artifacts cleaned!$(RESET)"

.PHONY: setup
setup: build ## Build and run initial setup wizard
	@echo "$(CYAN)╔════════════════════════════════════════════════════════════╗$(RESET)"
	@echo "$(CYAN)$(RESET)  $(MAGENTA)Running Cyx Setup Wizard$(RESET)                            $(CYAN)$(RESET)"
	@echo "$(CYAN)╚════════════════════════════════════════════════════════════╝$(RESET)"
	@echo ""
	@cyx setup

.PHONY: run
run: build ## Build and run cyx with interactive mode
	@cyx

.PHONY: dev
dev: build-dev ## Quick dev build and run
	@./target/debug/$(BINARY_NAME)

.PHONY: watch
watch: ## Watch for changes and rebuild (requires cargo-watch)
	@which cargo-watch > /dev/null || (echo "$(RED)Error: cargo-watch not installed$(RESET)" && echo "$(YELLOW)Install with: cargo install cargo-watch$(RESET)" && exit 1)
	@echo "$(BLUE)Watching for changes...$(RESET)"
	@cargo watch -x 'build --release' -s 'make symlink'

.PHONY: bench
bench: ## Run benchmarks
	@echo "$(BLUE)Running benchmarks...$(RESET)"
	@$(CARGO) bench

.PHONY: doc
doc: ## Generate and open documentation
	@echo "$(BLUE)Generating documentation...$(RESET)"
	@$(CARGO) doc --open --no-deps

.PHONY: audit
audit: ## Check for security vulnerabilities in dependencies
	@echo "$(BLUE)Auditing dependencies for security vulnerabilities...$(RESET)"
	@which cargo-audit > /dev/null || (echo "$(YELLOW)Installing cargo-audit...$(RESET)" && cargo install cargo-audit)
	@cargo audit

.PHONY: bloat
bloat: ## Analyze binary size (requires cargo-bloat)
	@which cargo-bloat > /dev/null || (echo "$(YELLOW)Installing cargo-bloat...$(RESET)" && cargo install cargo-bloat)
	@echo "$(BLUE)Analyzing binary size...$(RESET)"
	@cargo bloat --release -n 20

.PHONY: size
size: build ## Show binary size
	@echo "$(BLUE)Binary size:$(RESET)"
	@ls -lh $(BINARY_PATH) | awk '{print "  " $$5 " - " $$9}'
	@echo ""
	@file $(BINARY_PATH)

.PHONY: pre-commit
pre-commit: fmt check test ## Run all pre-commit checks (fmt, check, test)
	@echo ""
	@echo "$(CYAN)═══════════════════════════════════════════════════════════$(RESET)"
	@echo "$(GREEN)✓ All pre-commit checks passed!$(RESET)"
	@echo "$(CYAN)═══════════════════════════════════════════════════════════$(RESET)"
	@echo "$(GREEN)Ready to commit!$(RESET)"
	@echo ""

.PHONY: build-release-only
build-release-only: deps ## Build the release binary without symlink
	@echo "$(CYAN)╔════════════════════════════════════════════════════════════╗$(RESET)"
	@echo "$(CYAN)$(RESET)  $(MAGENTA)Building Cyx (Release Mode)$(RESET)                          $(CYAN)$(RESET)"
	@echo "$(CYAN)╚════════════════════════════════════════════════════════════╝$(RESET)"
	@echo ""
	@$(CARGO) build $(CARGO_BUILD_FLAGS)
	@echo ""
	@echo "$(GREEN)✓ Build completed successfully!$(RESET)"
	@echo ""

.PHONY: package
package: build-release-only ## Create distributable release package with bundled libraries
	@echo "$(CYAN)╔════════════════════════════════════════════════════════════╗$(RESET)"
	@echo "$(CYAN)$(RESET)  $(MAGENTA)Creating Release Package$(RESET)                           $(CYAN)$(RESET)"
	@echo "$(CYAN)╚════════════════════════════════════════════════════════════╝$(RESET)"
	@echo ""
	@bash scripts/package-release.sh

.PHONY: release
release: pre-commit build package ## Full release build with all checks and packaging
	@echo ""
	@echo "$(CYAN)╔════════════════════════════════════════════════════════════╗$(RESET)"
	@echo "$(CYAN)$(RESET)  $(MAGENTA)Release Build Complete!$(RESET)                             $(CYAN)$(RESET)"
	@echo "$(CYAN)╚════════════════════════════════════════════════════════════╝$(RESET)"
	@echo ""
	@$(MAKE) --no-print-directory size
	@echo ""
	@echo "$(GREEN)Release package created in dist/ directory$(RESET)"
	@echo "$(GREEN)Ready for distribution!$(RESET)"
	@echo ""

.PHONY: all
all: clean build test check ## Clean, build, test, and check everything
	@echo ""
	@echo "$(CYAN)═══════════════════════════════════════════════════════════$(RESET)"
	@echo "$(GREEN)✓ Full build pipeline complete!$(RESET)"
	@echo "$(CYAN)═══════════════════════════════════════════════════════════$(RESET)"
	@echo ""