-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathMakefile
More file actions
1141 lines (1060 loc) · 47.8 KB
/
Makefile
File metadata and controls
1141 lines (1060 loc) · 47.8 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
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
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.PHONY: help dev dev-core ensure-cargo-config prod backend frontend ensure-frontend-stub build-frontend build test clean publish beta version npm check-cargo check-android-deps publish-automagik publish-automagik-quick service install update uninstall install-deps install-complete install-complete-no-pm2 setup-pm2 start-local stop-local restart-local service-status logs logs-follow health push-both pr-both
# Ensure bash is used for echo -e support
SHELL := /bin/bash
# ===========================================
# 📋 Service Configuration
# ===========================================
SERVICE_NAME := 8887: Forge
SERVICE_PORT := 8887
HEALTH_ENDPOINT := http://localhost:$(SERVICE_PORT)/health
PM2_CONFIG := ecosystem.config.cjs
# ===========================================
# 🎨 Colors & Symbols
# ===========================================
FONT_RED := $(shell tput setaf 1)
FONT_GREEN := $(shell tput setaf 2)
FONT_YELLOW := $(shell tput setaf 3)
FONT_BLUE := $(shell tput setaf 4)
FONT_PURPLE := $(shell tput setaf 5)
FONT_CYAN := $(shell tput setaf 6)
FONT_GRAY := $(shell tput setaf 7)
FONT_BOLD := $(shell tput bold)
FONT_RESET := $(shell tput sgr0)
CHECKMARK := ✅
WARNING := ⚠️
ERROR := ❌
ROCKET := 🚀
HAMMER := 🔨
INFO := ℹ️
SPARKLES := ✨
# ===========================================
# 🛠️ Utility Functions
# ===========================================
define print_status
@echo -e "$(FONT_PURPLE)$(HAMMER) $(1)$(FONT_RESET)"
endef
define print_success
@echo -e "$(FONT_GREEN)$(CHECKMARK) $(1)$(FONT_RESET)"
endef
define print_warning
@echo -e "$(FONT_YELLOW)$(WARNING) $(1)$(FONT_RESET)"
endef
define print_error
@echo -e "$(FONT_RED)$(ERROR) $(1)$(FONT_RESET)"
endef
define print_info
@echo -e "$(FONT_CYAN)$(INFO) $(1)$(FONT_RESET)"
endef
define check_pm2
@if ! command -v pm2 >/dev/null 2>&1; then \
echo -e "$(FONT_RED)$(ERROR) PM2 not found$(FONT_RESET)"; \
echo -e "$(FONT_YELLOW)💡 Install with: npm install -g pm2$(FONT_RESET)"; \
exit 1; \
fi
endef
define check_systemd
@if [[ "$$(uname -s)" != "Linux" ]]; then \
echo -e "$(FONT_CYAN)$(INFO) systemd only available on Linux$(FONT_RESET)"; \
exit 1; \
fi; \
if ! command -v systemctl >/dev/null 2>&1; then \
echo -e "$(FONT_YELLOW)$(WARNING) systemd not found$(FONT_RESET)"; \
exit 1; \
fi
endef
define ensure_env_file
@if [ ! -f ".env" ]; then \
if [ -f ".env.example" ]; then \
echo -e "$(FONT_YELLOW)$(WARNING) .env not found - creating from .env.example$(FONT_RESET)"; \
cp .env.example .env; \
echo -e "$(FONT_CYAN)$(INFO) .env created - please configure before starting$(FONT_RESET)"; \
else \
echo -e "$(FONT_YELLOW)$(WARNING) .env not found and no .env.example$(FONT_RESET)"; \
fi; \
fi
endef
# ===========================================
# 📋 Help System
# ===========================================
.PHONY: help
help: ## 🔨 Show this help message
@echo ""
@echo -e "$(FONT_BOLD)$(FONT_PURPLE)🔨 Automagik Forge$(FONT_RESET) - $(FONT_GRAY)The Vibe Coding++ Platform$(FONT_RESET)"
@echo ""
@echo -e "$(FONT_YELLOW)🏢 Building the future of autonomous software development$(FONT_RESET)"
@echo -e "$(FONT_CYAN)📦 GitHub:$(FONT_RESET) https://github.com/namastexlabs/automagik-forge"
@echo ""
@echo -e "$(FONT_CYAN)$(ROCKET) Installation & Setup:$(FONT_RESET)"
@echo -e " $(FONT_PURPLE)install$(FONT_RESET) Full interactive installation (6 phases)"
@echo -e " $(FONT_PURPLE)install-deps$(FONT_RESET) Install dependencies only (no PM2/systemd)"
@echo -e " $(FONT_PURPLE)update$(FONT_RESET) Update installation (git pull + deps + restart + health)"
@echo -e " $(FONT_PURPLE)uninstall$(FONT_RESET) Remove PM2/systemd services and clean builds"
@echo ""
@echo -e "$(FONT_CYAN)🛠️ Development:$(FONT_RESET)"
@echo -e " $(FONT_PURPLE)dev$(FONT_RESET) Start dev environment (hot reload)"
@echo -e " $(FONT_PURPLE)dev-core$(FONT_RESET) Dev with local forge-core (auto-disables on push)"
@echo -e " $(FONT_PURPLE)prod$(FONT_RESET) Build and test production package"
@echo -e " $(FONT_PURPLE)forge$(FONT_RESET) Alias for 'make prod'"
@echo -e " $(FONT_PURPLE)backend$(FONT_RESET) Backend only (use BP=port to override)"
@echo -e " $(FONT_PURPLE)frontend$(FONT_RESET) Frontend only (use FP=port to override)"
@echo -e " $(FONT_PURPLE)build$(FONT_RESET) Build production package (no launch)"
@echo -e " $(FONT_PURPLE)test$(FONT_RESET) Run full test suite"
@echo -e " $(FONT_PURPLE)clean$(FONT_RESET) Clean build artifacts"
@echo ""
@echo -e "$(FONT_CYAN)📦 Service Management:$(FONT_RESET)"
@echo -e " $(FONT_PURPLE)start-local$(FONT_RESET) Start with PM2"
@echo -e " $(FONT_PURPLE)stop-local$(FONT_RESET) Stop PM2 service"
@echo -e " $(FONT_PURPLE)restart-local$(FONT_RESET) Restart PM2 service"
@echo -e " $(FONT_PURPLE)service-status$(FONT_RESET) Check PM2 status"
@echo -e " $(FONT_PURPLE)logs$(FONT_RESET) Show recent logs (N=30)"
@echo -e " $(FONT_PURPLE)logs-follow$(FONT_RESET) Follow logs in real-time"
@echo -e " $(FONT_PURPLE)health$(FONT_RESET) Check service health"
@echo ""
@echo -e "$(FONT_CYAN)🐧 System Service (Ubuntu/Debian):$(FONT_RESET)"
@echo -e " $(FONT_PURPLE)service$(FONT_RESET) Install systemd service (interactive)"
@echo ""
@echo -e "$(FONT_CYAN)🚀 Release & Publish:$(FONT_RESET)"
@echo -e " $(FONT_PURPLE)publish$(FONT_RESET) Complete release pipeline"
@echo -e " $(FONT_PURPLE)beta$(FONT_RESET) Beta release"
@echo -e " $(FONT_PURPLE)version$(FONT_RESET) Show version info"
@echo ""
@echo -e "$(FONT_GRAY)Examples:$(FONT_RESET)"
@echo -e " $(FONT_GRAY)make install$(FONT_RESET) # Full installation"
@echo -e " $(FONT_GRAY)make dev$(FONT_RESET) # Start development"
@echo -e " $(FONT_GRAY)make update$(FONT_RESET) # Update to latest"
@echo -e " $(FONT_GRAY)make logs N=50$(FONT_RESET) # Show 50 log lines"
@echo ""
# ===========================================
# 📦 Installation & Setup
# ===========================================
.PHONY: install install-deps install-complete install-complete-no-pm2
install: ## $(ROCKET) Full interactive installation (6 phases)
$(call print_status,Starting Automagik Forge installation...)
@echo ""
# Phase 1: Prerequisites Check
$(call print_status,Phase 1/6: Checking prerequisites...)
@$(MAKE) check-android-deps
@$(MAKE) check-cargo
@$(call ensure_env_file)
$(call print_success,Prerequisites verified!)
@echo ""
# Phase 2: Node.js Dependencies
$(call print_status,Phase 2/6: Installing Node.js dependencies...)
@if ! command -v pnpm >/dev/null 2>&1; then \
echo -e "$(FONT_RED)$(ERROR) pnpm not found$(FONT_RESET)"; \
echo -e "$(FONT_YELLOW)💡 Install with: npm install -g pnpm$(FONT_RESET)"; \
exit 1; \
fi
@pnpm install
@cd frontend && pnpm install
$(call print_success,Node.js dependencies installed!)
@echo ""
# Phase 3: Build Application
$(call print_status,Phase 3/6: Building application...)
@bash scripts/build/build.sh
$(call print_success,Application built successfully!)
@echo ""
# Phase 4: PM2 Setup (Interactive)
$(call print_status,Phase 4/6: PM2 Process Manager)
@if command -v pm2 >/dev/null 2>&1; then \
PM2_VERSION=$$(pm2 --version 2>/dev/null || echo "unknown"); \
echo -e "$(FONT_GREEN)$(CHECKMARK) PM2 $$PM2_VERSION already installed$(FONT_RESET)"; \
else \
echo -e "$(FONT_YELLOW)$(WARNING) PM2 not installed$(FONT_RESET)"; \
echo -e "$(FONT_CYAN)PM2 is a process manager for production deployments.$(FONT_RESET)"; \
echo -e "$(FONT_CYAN)Features: auto-restart, log management, monitoring$(FONT_RESET)"; \
read -p "Install PM2 globally? [y/N] " -n 1 -r REPLY; echo; \
if [[ $$REPLY =~ ^[Yy]$$ ]]; then \
echo -e "$(FONT_PURPLE)$(HAMMER) Installing PM2...$(FONT_RESET)"; \
npm install -g pm2 || { \
echo -e "$(FONT_RED)$(ERROR) PM2 installation failed$(FONT_RESET)"; \
echo -e "$(FONT_YELLOW)💡 Try: sudo npm install -g pm2$(FONT_RESET)"; \
exit 1; \
}; \
PM2_VERSION=$$(pm2 --version); \
echo -e "$(FONT_GREEN)$(CHECKMARK) PM2 $$PM2_VERSION installed!$(FONT_RESET)"; \
else \
echo -e "$(FONT_YELLOW)Skipped.$(FONT_RESET)"; \
fi; \
fi
@echo ""
# Phase 5: PM2 Configuration
@if command -v pm2 >/dev/null 2>&1; then \
echo -e "$(FONT_PURPLE)$(HAMMER) Phase 5/6: Configuring PM2...$(FONT_RESET)"; \
pm2 install pm2-logrotate >/dev/null 2>&1 || true; \
pm2 set pm2-logrotate:max_size 100M >/dev/null 2>&1 || true; \
pm2 set pm2-logrotate:retain 7 >/dev/null 2>&1 || true; \
pm2 start $(PM2_CONFIG) >/dev/null 2>&1 || pm2 restart "$(SERVICE_NAME)" >/dev/null 2>&1 || true; \
pm2 save --force >/dev/null 2>&1 || true; \
echo -e "$(FONT_GREEN)$(CHECKMARK) PM2 configured and service started!$(FONT_RESET)"; \
pm2 status; \
echo ""; \
echo -e "$(FONT_PURPLE)$(HAMMER) Phase 6/6: System Service Setup$(FONT_RESET)"; \
if [[ "$$(uname -s)" == "Linux" ]] && command -v systemctl >/dev/null 2>&1; then \
read -p "Install as system service (auto-start on boot)? [y/N] " -n 1 -r REPLY; echo; \
if [[ $$REPLY =~ ^[Yy]$$ ]]; then \
echo -e "$(FONT_PURPLE)$(HAMMER) Installing systemd service...$(FONT_RESET)"; \
bash scripts/service/install-service.sh || echo -e "$(FONT_YELLOW)$(WARNING) systemd setup incomplete$(FONT_RESET)"; \
else \
echo -e "$(FONT_YELLOW)Skipped.$(FONT_RESET)"; \
fi; \
else \
echo -e "$(FONT_CYAN)$(INFO) System service setup not available (Linux + systemd required)$(FONT_RESET)"; \
fi; \
echo ""; \
$(MAKE) install-complete; \
else \
echo -e "$(FONT_GREEN)$(CHECKMARK) Phase 5/6: Skipped (no PM2)$(FONT_RESET)"; \
echo -e "$(FONT_GREEN)$(CHECKMARK) Phase 6/6: Skipped (no PM2)$(FONT_RESET)"; \
echo ""; \
$(MAKE) install-complete-no-pm2; \
fi
install-complete:
@echo ""
@echo -e "$(FONT_GREEN)========================================$(FONT_RESET)"
@echo -e "$(FONT_GREEN)$(SPARKLES) Installation Complete! 🎉$(FONT_RESET)"
@echo -e "$(FONT_GREEN)========================================$(FONT_RESET)"
@echo ""
@echo -e "$(FONT_GREEN)$(ROCKET) Automagik Forge is now running!$(FONT_RESET)"
@echo ""
@echo -e "$(FONT_CYAN)📊 Useful commands:$(FONT_RESET)"
@echo -e " $(FONT_PURPLE)make service-status$(FONT_RESET) # Check PM2 status"
@echo -e " $(FONT_PURPLE)make logs$(FONT_RESET) # View recent logs"
@echo -e " $(FONT_PURPLE)make logs-follow$(FONT_RESET) # Follow logs in real-time"
@echo -e " $(FONT_PURPLE)make restart-local$(FONT_RESET) # Restart service"
@echo -e " $(FONT_PURPLE)make health$(FONT_RESET) # Run health checks"
@echo -e " $(FONT_PURPLE)make update$(FONT_RESET) # Update to latest version"
@echo ""
@echo -e "$(FONT_CYAN)🌐 Access Forge:$(FONT_RESET)"
@echo -e " $(FONT_PURPLE)Check PM2 logs for port information$(FONT_RESET)"
@echo ""
@echo -e "$(FONT_GREEN)Happy forging! $(HAMMER)$(FONT_RESET)"
@echo ""
install-complete-no-pm2:
@echo ""
@echo -e "$(FONT_GREEN)========================================$(FONT_RESET)"
@echo -e "$(FONT_GREEN)$(SPARKLES) Installation Complete!$(FONT_RESET)"
@echo -e "$(FONT_GREEN)========================================$(FONT_RESET)"
@echo ""
@echo -e "$(FONT_CYAN)$(INFO) Dependencies installed (PM2 not installed)$(FONT_RESET)"
@echo ""
@echo -e "$(FONT_CYAN)$(ROCKET) To run Automagik Forge:$(FONT_RESET)"
@echo -e " $(FONT_PURPLE)make prod$(FONT_RESET) # Run production build"
@echo -e " $(FONT_PURPLE)make dev$(FONT_RESET) # Run development mode"
@echo ""
@echo -e "$(FONT_CYAN)💡 To install PM2 later:$(FONT_RESET)"
@echo -e " $(FONT_PURPLE)npm install -g pm2$(FONT_RESET)"
@echo -e " $(FONT_PURPLE)make start-local$(FONT_RESET) # Start with PM2"
@echo ""
install-deps: ## 📦 Install dependencies only (skip PM2/systemd)
$(call print_status,Installing dependencies...)
@$(MAKE) check-android-deps
@$(MAKE) check-cargo
@if ! command -v pnpm >/dev/null 2>&1; then \
echo -e "$(FONT_RED)$(ERROR) pnpm not found$(FONT_RESET)"; \
echo -e "$(FONT_YELLOW)💡 Install with: npm install -g pnpm$(FONT_RESET)"; \
exit 1; \
fi
@pnpm install
@cd frontend && pnpm install
@bash scripts/build/build.sh
$(call print_success,Dependencies installed!)
# ===========================================
# 🔄 Update & Maintenance
# ===========================================
.PHONY: update
update: ## 🔄 Update installation (smart detection + deps + restart + health check)
$(call print_status,Updating Automagik Forge...)
@echo ""
# Step 1: Smart update detection
$(call print_status,Step 1/5: Checking for updates...)
@git fetch origin
@LOCAL_COMMIT=$$(git rev-parse HEAD); \
REMOTE_COMMIT=$$(git rev-parse @{u} 2>/dev/null || git rev-parse origin/$$(git rev-parse --abbrev-ref HEAD)); \
if [ "$$LOCAL_COMMIT" = "$$REMOTE_COMMIT" ]; then \
echo -e "$(FONT_GREEN)$(CHECKMARK) Already up-to-date!$(FONT_RESET)"; \
echo ""; \
echo -e "$(FONT_CYAN)Running health check...$(FONT_RESET)"; \
$(MAKE) health || true; \
echo ""; \
echo -e "$(FONT_GREEN)$(SPARKLES) No update needed - service is current$(FONT_RESET)"; \
exit 0; \
fi; \
echo -e "$(FONT_CYAN)$(INFO) Updates available: $$LOCAL_COMMIT → $$REMOTE_COMMIT$(FONT_RESET)"
@echo ""
# Step 2: Git pull
$(call print_status,Step 2/5: Pulling latest changes...)
@git pull || { \
echo -e "$(FONT_RED)$(ERROR) Git pull failed$(FONT_RESET)"; \
echo -e "$(FONT_YELLOW)💡 Check for uncommitted changes: git status$(FONT_RESET)"; \
exit 1; \
}
$(call print_success,Latest changes pulled!)
@echo ""
# Step 3: Update dependencies and rebuild
$(call print_status,Step 3/5: Updating dependencies and rebuilding...)
@pnpm install
@cd frontend && pnpm install
@bash scripts/build/build.sh
$(call print_success,Dependencies updated and application rebuilt!)
@echo ""
# Step 4: Restart service
$(call print_status,Step 4/5: Restarting service...)
@if command -v pm2 >/dev/null 2>&1 && pm2 show "$(SERVICE_NAME)" >/dev/null 2>&1; then \
$(MAKE) restart-local; \
echo -e "$(FONT_CYAN)⏳ Waiting for service to restart...$(FONT_RESET)"; \
sleep 3; \
elif systemctl is-active automagik-forge >/dev/null 2>&1; then \
echo -e "$(FONT_PURPLE)Restarting systemd service...$(FONT_RESET)"; \
sudo systemctl restart automagik-forge; \
sleep 3; \
else \
echo -e "$(FONT_YELLOW)$(WARNING) No running service detected - skipping restart$(FONT_RESET)"; \
fi
@echo ""
# Step 5: Health check with retry
$(call print_status,Step 5/5: Running health checks...)
@HEALTH_OK=0; \
for i in 1 2 3 4 5; do \
sleep 3; \
if curl -sf --max-time 5 $(HEALTH_ENDPOINT) > /dev/null 2>&1; then \
HEALTH_OK=1; \
break; \
fi; \
echo -e "$(FONT_YELLOW) Attempt $$i/5 - waiting for service...$(FONT_RESET)"; \
done; \
if [ $$HEALTH_OK -eq 1 ]; then \
echo -e "$(FONT_GREEN)$(CHECKMARK) Health check passed!$(FONT_RESET)"; \
else \
echo -e "$(FONT_YELLOW)$(WARNING) Health check failed - service may need more time$(FONT_RESET)"; \
fi
# Success summary
@echo ""
@echo -e "$(FONT_GREEN)========================================$(FONT_RESET)"
@echo -e "$(FONT_GREEN)$(SPARKLES) Update Completed Successfully!$(FONT_RESET)"
@echo -e "$(FONT_GREEN)========================================$(FONT_RESET)"
@echo ""
@echo -e "$(FONT_CYAN)💡 Useful commands:$(FONT_RESET)"
@echo -e " $(FONT_PURPLE)make logs$(FONT_RESET) # View recent logs"
@echo -e " $(FONT_PURPLE)make service-status$(FONT_RESET) # Check service status"
@echo -e " $(FONT_PURPLE)make health$(FONT_RESET) # Run health check again"
@echo ""
# ===========================================
# 🗑️ Uninstall
# ===========================================
.PHONY: uninstall
uninstall: ## 🗑️ Uninstall Forge (remove PM2/systemd services, clean builds)
@# Support non-interactive mode: UNINSTALL_CONFIRM=yes make uninstall
@if [ "$(UNINSTALL_CONFIRM)" != "yes" ]; then \
echo -e "$(FONT_YELLOW)$(WARNING) This will remove Forge services$(FONT_RESET)"; \
read -p "Proceed with uninstall? [y/N] " -n 1 -r REPLY; echo; \
if [[ ! $$REPLY =~ ^[Yy]$$ ]]; then \
echo -e "$(FONT_CYAN)Uninstall cancelled$(FONT_RESET)"; \
exit 0; \
fi; \
fi
$(call print_status,Starting Automagik Forge uninstall...)
@echo ""
# Phase 1: PM2 Service Removal
$(call print_status,Phase 1/4: Checking PM2 service...)
@if command -v pm2 >/dev/null 2>&1 && pm2 show "$(SERVICE_NAME)" >/dev/null 2>&1; then \
echo -e "$(FONT_PURPLE)$(HAMMER) Removing PM2 service...$(FONT_RESET)"; \
pm2 stop "$(SERVICE_NAME)" >/dev/null 2>&1 || true; \
pm2 delete "$(SERVICE_NAME)" >/dev/null 2>&1 || true; \
pm2 save --force >/dev/null 2>&1 || true; \
echo -e "$(FONT_GREEN)$(CHECKMARK) PM2 service removed$(FONT_RESET)"; \
else \
echo -e "$(FONT_CYAN)$(INFO) No PM2 service found - skipping$(FONT_RESET)"; \
fi
@echo ""
# Phase 2: Systemd Service Removal
$(call print_status,Phase 2/4: Checking systemd service...)
@if systemctl list-unit-files 2>/dev/null | grep -q automagik-forge; then \
echo -e "$(FONT_PURPLE)$(HAMMER) Removing systemd service...$(FONT_RESET)"; \
sudo systemctl stop automagik-forge 2>/dev/null || true; \
sudo systemctl disable automagik-forge 2>/dev/null || true; \
sudo rm -f /etc/systemd/system/automagik-forge.service; \
sudo systemctl daemon-reload 2>/dev/null || true; \
sudo systemctl reset-failed 2>/dev/null || true; \
echo -e "$(FONT_GREEN)$(CHECKMARK) Systemd service removed$(FONT_RESET)"; \
else \
echo -e "$(FONT_CYAN)$(INFO) No systemd service found - skipping$(FONT_RESET)"; \
fi
@echo ""
# Phase 3: Dedicated Service Account Cleanup
$(call print_status,Phase 3/4: Checking for dedicated service account...)
@if id "forge" >/dev/null 2>&1; then \
if [ "$(UNINSTALL_CONFIRM)" = "yes" ]; then \
echo -e "$(FONT_PURPLE)$(HAMMER) Removing dedicated service account...$(FONT_RESET)"; \
[ -d "/opt/automagik-forge" ] && sudo rm -rf /opt/automagik-forge; \
[ -d "/var/lib/automagik-forge" ] && sudo rm -rf /var/lib/automagik-forge; \
[ -d "/var/log/automagik-forge" ] && sudo rm -rf /var/log/automagik-forge; \
sudo userdel forge 2>/dev/null || true; \
echo -e "$(FONT_GREEN)$(CHECKMARK) Service account removed$(FONT_RESET)"; \
else \
echo -e "$(FONT_YELLOW)$(WARNING) Dedicated 'forge' service account found$(FONT_RESET)"; \
echo -e "$(FONT_CYAN)The following will be removed:$(FONT_RESET)"; \
echo -e " - System user: forge"; \
[ -d "/opt/automagik-forge" ] && echo -e " - Directory: /opt/automagik-forge"; \
[ -d "/var/lib/automagik-forge" ] && echo -e " - Directory: /var/lib/automagik-forge"; \
[ -d "/var/log/automagik-forge" ] && echo -e " - Directory: /var/log/automagik-forge"; \
echo ""; \
read -p "Remove dedicated 'forge' user and directories? [y/N] " -n 1 -r REPLY; echo; \
if [[ $$REPLY =~ ^[Yy]$$ ]]; then \
echo -e "$(FONT_PURPLE)$(HAMMER) Removing dedicated service account...$(FONT_RESET)"; \
[ -d "/opt/automagik-forge" ] && sudo rm -rf /opt/automagik-forge; \
[ -d "/var/lib/automagik-forge" ] && sudo rm -rf /var/lib/automagik-forge; \
[ -d "/var/log/automagik-forge" ] && sudo rm -rf /var/log/automagik-forge; \
sudo userdel forge 2>/dev/null || true; \
echo -e "$(FONT_GREEN)$(CHECKMARK) Service account removed$(FONT_RESET)"; \
else \
echo -e "$(FONT_YELLOW)Skipped - service account kept$(FONT_RESET)"; \
fi; \
fi; \
else \
echo -e "$(FONT_CYAN)$(INFO) No dedicated service account found - skipping$(FONT_RESET)"; \
fi
@echo ""
# Phase 4: Build Artifacts Cleanup
$(call print_status,Phase 4/4: Cleaning build artifacts...)
@$(MAKE) clean >/dev/null 2>&1 || true
$(call print_success,Build artifacts cleaned!)
@echo ""
# Completion Summary
@echo ""
@echo -e "$(FONT_GREEN)========================================$(FONT_RESET)"
@echo -e "$(FONT_GREEN)$(SPARKLES) Uninstall Complete!$(FONT_RESET)"
@echo -e "$(FONT_GREEN)========================================$(FONT_RESET)"
@echo ""
@echo -e "$(FONT_GREEN)✓ What was removed:$(FONT_RESET)"
@echo -e " • PM2 service (if installed)"
@echo -e " • Systemd service (if installed)"
@echo -e " • Build artifacts"
@echo ""
@echo -e "$(FONT_CYAN)ℹ️ What was kept:$(FONT_RESET)"
@echo -e " • .env file (configuration)"
@echo -e " • Source code"
@echo -e " • Node dependencies (node_modules)"
@echo -e " • Global tools (PM2, pnpm, cargo)"
@echo ""
@echo -e "$(FONT_PURPLE)$(ROCKET) To reinstall:$(FONT_RESET) make install"
@echo ""
# ===========================================
# 🩺 Health Checks
# ===========================================
.PHONY: health
health: ## 🩺 Check service health
$(call print_status,Checking Automagik Forge health...)
@FAILED=0; \
\
if command -v pm2 >/dev/null 2>&1 && pm2 show "$(SERVICE_NAME)" >/dev/null 2>&1; then \
echo -e "$(FONT_CYAN)Service Status (PM2):$(FONT_RESET)"; \
pm2 describe "$(SERVICE_NAME)" | grep -E "status|uptime|restarts" || true; \
echo ""; \
fi; \
\
if systemctl is-active automagik-forge >/dev/null 2>&1; then \
echo -e "$(FONT_CYAN)Service Status (systemd):$(FONT_RESET)"; \
systemctl status automagik-forge --no-pager -l | head -15; \
echo ""; \
fi; \
\
echo -e "$(FONT_CYAN)Testing health endpoint...$(FONT_RESET)"; \
echo -e " Endpoint: $(HEALTH_ENDPOINT)"; \
\
if curl -sf --max-time 5 $(HEALTH_ENDPOINT) > /dev/null 2>&1; then \
echo -e " $(FONT_GREEN)$(CHECKMARK) Health check passed$(FONT_RESET)"; \
else \
echo -e " $(FONT_RED)$(ERROR) Health check failed$(FONT_RESET)"; \
FAILED=1; \
fi; \
\
if [ -f "forge-app/forge.db" ]; then \
if sqlite3 forge-app/forge.db "SELECT 1;" >/dev/null 2>&1; then \
echo -e " $(FONT_GREEN)$(CHECKMARK) Database connectivity OK$(FONT_RESET)"; \
else \
echo -e " $(FONT_YELLOW)$(WARNING) Database exists but may be locked$(FONT_RESET)"; \
fi; \
else \
echo -e " $(FONT_YELLOW)$(WARNING) Database not found (first run?)$(FONT_RESET)"; \
fi; \
\
exit $$FAILED
# ===========================================
# 📦 PM2 Service Management
# ===========================================
.PHONY: setup-pm2 start-local stop-local restart-local service-status logs logs-follow
setup-pm2: ## 📦 Setup PM2 ecosystem and log rotation
$(call print_status,Setting up PM2 ecosystem...)
@$(call check_pm2)
@echo -e "$(FONT_CYAN)$(INFO) Installing PM2 log rotation...$(FONT_RESET)"
@if ! pm2 list | grep -q pm2-logrotate; then \
pm2 install pm2-logrotate; \
else \
echo -e "$(FONT_GREEN)✓ PM2 logrotate already installed$(FONT_RESET)"; \
fi
@pm2 set pm2-logrotate:max_size 100M
@pm2 set pm2-logrotate:retain 7
@pm2 set pm2-logrotate:compress true
@echo -e "$(FONT_CYAN)$(INFO) Configuring PM2 startup...$(FONT_RESET)"
@pm2 startup | grep "sudo" || echo -e "$(FONT_YELLOW)Run the command above to enable auto-start$(FONT_RESET)"
$(call print_success,PM2 ecosystem configured!)
start-local: ## $(ROCKET) Start Forge with PM2
$(call print_status,Starting Automagik Forge with PM2...)
@$(call check_pm2)
@$(call ensure_env_file)
@pm2 start $(PM2_CONFIG)
@pm2 save --force
$(call print_success,Forge started with PM2!)
@echo ""
@pm2 status
stop-local: ## 🛑 Stop PM2 service
$(call print_status,Stopping Automagik Forge...)
@$(call check_pm2)
@pm2 stop "$(SERVICE_NAME)" 2>/dev/null || true
$(call print_success,Forge stopped!)
restart-local: ## 🔄 Restart PM2 service
$(call print_status,Restarting Automagik Forge...)
@$(call check_pm2)
@pm2 restart "$(SERVICE_NAME)" 2>/dev/null || pm2 start $(PM2_CONFIG)
@pm2 save --force
$(call print_success,Forge restarted!)
service-status: ## 📊 Check PM2 service status
$(call print_status,PM2 Service Status)
@$(call check_pm2)
@pm2 show "$(SERVICE_NAME)" 2>/dev/null || echo -e "$(FONT_YELLOW)Service not found or not running$(FONT_RESET)"
logs: ## 📄 Show recent service logs (N=lines, default 30)
$(eval N := $(or $(N),30))
$(call print_status,Recent logs ($(N) lines))
@if command -v pm2 >/dev/null 2>&1 && pm2 show "$(SERVICE_NAME)" >/dev/null 2>&1; then \
pm2 logs "$(SERVICE_NAME)" --lines $(N) --nostream 2>/dev/null; \
elif [ -f "logs/forge-combined.log" ]; then \
echo -e "$(FONT_CYAN)Showing direct log file:$(FONT_RESET)"; \
tail -n $(N) logs/forge-combined.log; \
else \
echo -e "$(FONT_YELLOW)$(WARNING) No logs found$(FONT_RESET)"; \
fi
logs-follow: ## 📄 Follow logs in real-time
$(call print_status,Following logs (Ctrl+C to stop))
@echo ""
@if command -v pm2 >/dev/null 2>&1 && pm2 show "$(SERVICE_NAME)" >/dev/null 2>&1; then \
pm2 logs "$(SERVICE_NAME)" 2>/dev/null; \
elif [ -f "logs/forge-combined.log" ]; then \
tail -f logs/forge-combined.log; \
else \
echo -e "$(FONT_YELLOW)$(WARNING) No logs found$(FONT_RESET)"; \
fi
# ===========================================
# 🛠️ Development & Building
# ===========================================
# Check and install cargo if needed (OS agnostic)
check-cargo:
@PATH="$$HOME/.cargo/bin:$$PATH"; \
export PATH; \
if command -v cargo >/dev/null 2>&1; then \
echo "✅ Cargo already installed: $$(cargo --version)"; \
else \
echo "🦀 Cargo not found. Installing Rust toolchain..."; \
if [ -d "/data/data/com.termux" ]; then \
echo "📱 Termux detected - installing via pkg..."; \
pkg install -y rust; \
else \
echo "🌐 Installing via rustup (Linux/macOS/WSL)..."; \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y; \
PATH="$$HOME/.cargo/bin:$$PATH"; \
export PATH; \
fi; \
echo "✅ Rust toolchain installed"; \
fi; \
if cargo watch --version >/dev/null 2>&1; then \
echo "✅ cargo-watch already installed: $$(cargo watch --version)"; \
else \
echo "🔧 Installing cargo-watch..."; \
if [ "$$(uname)" = "Darwin" ]; then \
echo "🍎 macOS detected - using Homebrew for cargo-watch..."; \
if command -v brew >/dev/null 2>&1; then \
brew install cargo-watch; \
else \
echo "⚠️ Homebrew not found, trying cargo install..."; \
cargo install cargo-watch || { echo "❌ Failed to install cargo-watch"; exit 1; }; \
fi; \
else \
cargo install cargo-watch || { echo "❌ Failed to install cargo-watch"; exit 1; }; \
fi; \
if cargo watch --version >/dev/null 2>&1; then \
echo "✅ cargo-watch installed: $$(cargo watch --version)"; \
else \
echo "❌ cargo-watch installation failed"; \
exit 1; \
fi; \
fi
# Check and install Android/Termux build dependencies
check-android-deps:
@if [ -d "/data/data/com.termux" ]; then \
echo "📱 Checking Android/Termux build dependencies..."; \
MISSING_DEPS=""; \
for dep in perl openssl pkg-config make clang; do \
if ! command -v $$dep &> /dev/null; then \
MISSING_DEPS="$$MISSING_DEPS $$dep"; \
fi; \
done; \
if [ -n "$$MISSING_DEPS" ]; then \
echo "📦 Installing missing dependencies:$$MISSING_DEPS"; \
pkg install -y$$MISSING_DEPS; \
echo "✅ Dependencies installed"; \
else \
echo "✅ All build dependencies present"; \
fi; \
else \
if command -v dpkg >/dev/null 2>&1 && command -v apt-get >/dev/null 2>&1; then \
echo "🐧 Checking Debian/Ubuntu build dependencies..."; \
NEEDS_UPDATE=0; \
if ! command -v cc >/dev/null 2>&1 || ! command -v gcc >/dev/null 2>&1; then \
echo "📦 Installing build-essential (C/C++ compiler toolchain)..."; \
NEEDS_UPDATE=1; \
fi; \
if ! dpkg -l | grep -q libclang-dev; then \
echo "📦 Installing libclang-dev..."; \
NEEDS_UPDATE=1; \
fi; \
if [ $$NEEDS_UPDATE -eq 1 ]; then \
sudo apt-get update && sudo apt-get install -y build-essential libclang-dev; \
echo "✅ Build dependencies installed"; \
else \
echo "✅ All build dependencies present"; \
fi; \
else \
echo "ℹ️ Non-Debian system detected - skipping package checks"; \
echo " (Ensure gcc/clang and build tools are installed via your package manager)"; \
fi; \
fi
# Ensure cargo config exists (uses base config by default)
ensure-cargo-config:
@if [ ! -f ".cargo/config.toml" ]; then \
cp .cargo/config.base.toml .cargo/config.toml; \
fi
# Development mode - hot reload (backend first, then frontend)
dev: check-android-deps check-cargo ensure-cargo-config
@bash scripts/dev/run-dev.sh
# =============================================================================
# Cross-Repo Development (automagik-forge + forge-core)
# =============================================================================
BRANCH ?= $(shell git branch --show-current)
# Development with local forge-core (enhanced with branch selection + safety hooks)
# ============================================================================
# DEV-CORE: Local forge-core development
# Uses Cargo [patch] in .cargo/config.toml - no file swapping needed
# ============================================================================
dev-core: check-android-deps check-cargo ## Start dev with local forge-core
@# Check if already in dev-core mode with correct branches
@if grep -q '^\[patch\.' .cargo/config.toml 2>/dev/null && [ -d "forge-core" ]; then \
FORGE_BRANCH=$$(git branch --show-current); \
CORE_BRANCH=$$(cd forge-core && git branch --show-current); \
if [ "$(BRANCH)" = "$$FORGE_BRANCH" ] && [ "$(BRANCH)" = "$$CORE_BRANCH" ]; then \
echo ""; \
echo -e "$(FONT_GREEN)✓ Dev-core mode active on branch: $(BRANCH)$(FONT_RESET)"; \
echo -e "$(FONT_CYAN)📍 forge-core @ $$(cd forge-core && git describe --tags --always 2>/dev/null || git rev-parse --short HEAD)$(FONT_RESET)"; \
echo ""; \
FORGE_WATCH_PATHS="forge-core/crates" bash scripts/dev/run-dev.sh; \
exit 0; \
fi; \
fi
@echo ""
@echo -e "$(FONT_PURPLE)🔧 Starting local forge-core development...$(FONT_RESET)"
@# Pre-flight: Check workspace compatibility (prevents cryptic cargo errors)
@if ! grep -q '^\[workspace\.package\]' Cargo.toml; then \
echo ""; \
echo -e "$(FONT_RED)❌ Missing [workspace.package] in Cargo.toml$(FONT_RESET)"; \
echo " forge-core crates use 'version.workspace = true'"; \
echo " Add this to Cargo.toml:"; \
echo ""; \
echo " [workspace.package]"; \
echo " version = \"0.8.4\""; \
echo " edition = \"2021\""; \
echo ""; \
exit 1; \
fi
@if ! grep -qE '^rmcp\s*=' Cargo.toml; then \
echo ""; \
echo -e "$(FONT_RED)❌ Missing 'rmcp' in [workspace.dependencies]$(FONT_RESET)"; \
echo " forge-core/server crate needs: rmcp = { workspace = true }"; \
echo " Add to [workspace.dependencies]:"; \
echo ""; \
echo " rmcp = { version = \"0.8.5\" }"; \
echo ""; \
exit 1; \
fi
@# Safety: Check for uncommitted changes in forge-core before branch switch
@if [ -d "forge-core" ]; then \
if [ -n "$$(cd forge-core && git status --porcelain)" ]; then \
CORE_BRANCH=$$(cd forge-core && git branch --show-current); \
if [ "$$CORE_BRANCH" != "$(BRANCH)" ]; then \
echo ""; \
echo -e "$(FONT_RED)⚠️ forge-core has uncommitted changes on branch '$$CORE_BRANCH'$(FONT_RESET)"; \
echo -e "$(FONT_YELLOW) Requested branch: $(BRANCH)$(FONT_RESET)"; \
echo -e "$(FONT_YELLOW) Commit or stash changes before switching branches$(FONT_RESET)"; \
echo ""; \
cd forge-core && git status --short; \
echo ""; \
exit 1; \
fi; \
fi; \
fi
@# Clone or update forge-core with smart branch sync
@if [ ! -d "forge-core" ]; then \
echo -e "$(FONT_CYAN)📦 Cloning forge-core...$(FONT_RESET)"; \
if ! git clone https://github.com/namastexlabs/forge-core.git forge-core; then \
echo -e "$(FONT_RED)❌ FATAL: git clone failed$(FONT_RESET)"; \
echo -e "$(FONT_YELLOW)Check network connectivity$(FONT_RESET)"; \
exit 1; \
fi; \
fi
@# Sync forge-core to requested branch (using $(BRANCH) variable)
@cd forge-core && git fetch --all --tags 2>/dev/null; \
CORE_CURRENT=$$(git branch --show-current); \
if [ "$$CORE_CURRENT" = "$(BRANCH)" ]; then \
echo -e "$(FONT_GREEN)$(CHECKMARK) forge-core already on branch '$(BRANCH)'$(FONT_RESET)"; \
elif git show-ref --verify --quiet refs/remotes/origin/$(BRANCH); then \
echo -e "$(FONT_CYAN)📥 Switching forge-core to branch: $(BRANCH)$(FONT_RESET)"; \
git checkout $(BRANCH) 2>/dev/null || git checkout -b $(BRANCH) origin/$(BRANCH); \
elif git show-ref --verify --quiet refs/heads/$(BRANCH); then \
echo -e "$(FONT_CYAN)📥 Using local branch '$(BRANCH)' (not on remote yet)$(FONT_RESET)"; \
git checkout $(BRANCH); \
else \
echo -e "$(FONT_YELLOW)⚠️ Branch '$(BRANCH)' doesn't exist in forge-core$(FONT_RESET)"; \
echo -e "$(FONT_YELLOW) Creating from current branch: $$CORE_CURRENT$(FONT_RESET)"; \
git checkout -b $(BRANCH); \
fi; \
echo -e "$(FONT_GREEN)$(CHECKMARK) forge-core synced to branch: $(BRANCH)$(FONT_RESET)"
@echo -e "$(FONT_CYAN)📍 forge-core @ $$(cd forge-core && git describe --tags --always 2>/dev/null || git rev-parse --short HEAD)$(FONT_RESET)"
@# Enable [patch] section in .cargo/config.toml
@echo -e "$(FONT_CYAN)⚙️ Enabling Cargo [patch] overrides...$(FONT_RESET)"
@sed -i 's/^# \[patch\./[patch./g' .cargo/config.toml
@sed -i 's/^# forge-core-db = /forge-core-db = /g' .cargo/config.toml
@sed -i 's/^# forge-core-services = /forge-core-services = /g' .cargo/config.toml
@sed -i 's/^# forge-core-server = /forge-core-server = /g' .cargo/config.toml
@sed -i 's/^# forge-core-deployment = /forge-core-deployment = /g' .cargo/config.toml
@sed -i 's/^# forge-core-local-deployment = /forge-core-local-deployment = /g' .cargo/config.toml
@sed -i 's/^# forge-core-executors = /forge-core-executors = /g' .cargo/config.toml
@sed -i 's/^# forge-core-utils = /forge-core-utils = /g' .cargo/config.toml
@# Regenerate Cargo.lock for path deps
@rm -f Cargo.lock
@cargo fetch 2>/dev/null || true
@# Install all git hooks for dual-repo workflow
@mkdir -p .git/hooks scripts/hooks
@for hook in pre-commit prepare-commit-msg pre-push; do \
if [ -f scripts/hooks/$$hook ]; then \
cp scripts/hooks/$$hook .git/hooks/$$hook; \
chmod +x .git/hooks/$$hook; \
fi; \
done
@echo -e "$(FONT_GREEN)$(CHECKMARK) Git hooks installed (pre-commit, prepare-commit-msg, pre-push)$(FONT_RESET)"
@# Install blocker hooks in forge-core to prevent direct commits AND pushes
@mkdir -p forge-core/.git/hooks
@cp scripts/hooks/forge-core-pre-commit forge-core/.git/hooks/pre-commit
@cp scripts/hooks/forge-core-pre-push forge-core/.git/hooks/pre-push
@chmod +x forge-core/.git/hooks/pre-commit forge-core/.git/hooks/pre-push
@echo -e "$(FONT_GREEN)$(CHECKMARK) forge-core blocker hooks installed (pre-commit + pre-push)$(FONT_RESET)"
@echo -e "$(FONT_GREEN)$(CHECKMARK) Using local forge-core at ./forge-core$(FONT_RESET)"
@echo ""
@echo -e "$(FONT_YELLOW)ℹ Workflow: edit → commit → push (auto-disables patches)$(FONT_RESET)"
@echo -e "$(FONT_YELLOW)ℹ Run 'make dev-core' again to re-enable patches$(FONT_RESET)"
@echo ""
@FORGE_WATCH_PATHS="forge-core/crates" bash scripts/dev/run-dev.sh
dev-core-status: ## Show dev-core mode status
@echo ""
@if grep -q '^\[patch\.' .cargo/config.toml 2>/dev/null; then \
echo -e "Mode: $(FONT_GREEN)LOCAL$(FONT_RESET) (Cargo [patch] active)"; \
if [ -d "forge-core" ]; then \
echo -e "Branch: $$(cd forge-core && git branch --show-current 2>/dev/null || echo 'detached')"; \
echo -e "Commit: $$(cd forge-core && git log -1 --format='%h %s' 2>/dev/null || echo 'unknown')"; \
else \
echo -e "$(FONT_RED)⚠️ WARNING: forge-core/ directory missing!$(FONT_RESET)"; \
fi; \
else \
echo -e "Mode: $(FONT_CYAN)CRATES.IO$(FONT_RESET) (using published versions)"; \
FORGE_CORE_VERSION=$$(grep -oP '^forge-core-utils\s*=\s*"\K[^"]+' Cargo.toml 2>/dev/null | head -1); \
if [ -n "$$FORGE_CORE_VERSION" ]; then \
echo -e "Version: $$FORGE_CORE_VERSION"; \
fi; \
fi
@echo ""
# Dev-core health check (diagnostics)
dev-core-check: ## Health check for dev-core workspace
@echo -e "$(FONT_BOLD)Dev-Core Health Check$(FONT_RESET)"
@echo ""
@if grep -q '^\[patch\.' .cargo/config.toml 2>/dev/null; then \
echo -e "Mode: $(FONT_GREEN)ACTIVE$(FONT_RESET) (Cargo [patch] enabled)"; \
else \
echo -e "Mode: $(FONT_YELLOW)INACTIVE$(FONT_RESET) (using git dependencies)"; \
fi
@if [ -d "forge-core" ]; then \
echo -e "Core dir: $(FONT_GREEN)EXISTS$(FONT_RESET)"; \
echo -e "Branch: $$(cd forge-core && git branch --show-current)"; \
echo -e "Version: $$(cd forge-core && git describe --tags --always 2>/dev/null || echo 'no tags')"; \
else \
echo -e "Core dir: $(FONT_RED)MISSING$(FONT_RESET)"; \
fi
@if [ -f ".git/hooks/pre-push" ]; then \
echo -e "Hook: $(FONT_GREEN)INSTALLED$(FONT_RESET)"; \
else \
echo -e "Hook: $(FONT_YELLOW)NOT INSTALLED$(FONT_RESET)"; \
fi
# Version consistency check
check-versions: ## Validate version consistency across all files
@./scripts/check-versions.sh
# Show comprehensive cross-repo status
status: ## Show comprehensive cross-repo status
@echo ""
@echo -e "$(FONT_BOLD)$(FONT_PURPLE)🔍 Cross-Repo Status$(FONT_RESET)"
@echo ""
@# Dev-core mode
@if grep -q '^\[patch\.' .cargo/config.toml 2>/dev/null; then \
echo -e "Dev-core: $(FONT_GREEN)ACTIVE$(FONT_RESET) (Cargo [patch])"; \
else \
echo -e "Dev-core: $(FONT_CYAN)OFF$(FONT_RESET) (git deps)"; \
fi
@# Branches
@echo -e "forge branch: $$(git branch --show-current)"; \
if [ -d "forge-core" ]; then \
echo -e "core branch: $$(cd forge-core && git branch --show-current)"; \
else \
echo -e "core branch: $(FONT_YELLOW)not cloned$(FONT_RESET)"; \
fi
@# Versions
@EXPECTED_TAG=$$(grep -oP 'tag\s*=\s*"\K[^"]+' forge-app/Cargo.toml 2>/dev/null | head -1); \
echo -e "Cargo.toml tag: $$EXPECTED_TAG"; \
if [ -d "forge-core" ]; then \
LOCAL_TAG=$$(cd forge-core && git describe --tags --abbrev=0 2>/dev/null || echo "unknown"); \
echo -e "Local core tag: $$LOCAL_TAG"; \
fi
@# Uncommitted changes
@echo ""; \
if [ -n "$$(git status --porcelain)" ]; then \
echo -e "forge changes: $(FONT_YELLOW)$$(git status --porcelain | wc -l) files$(FONT_RESET)"; \
else \
echo -e "forge changes: $(FONT_GREEN)clean$(FONT_RESET)"; \
fi; \
if [ -d "forge-core" ] && [ -n "$$(cd forge-core && git status --porcelain)" ]; then \
echo -e "core changes: $(FONT_YELLOW)$$(cd forge-core && git status --porcelain | wc -l) files$(FONT_RESET)"; \
elif [ -d "forge-core" ]; then \
echo -e "core changes: $(FONT_GREEN)clean$(FONT_RESET)"; \
fi
@# Ready to push?
@echo ""; \
if grep -q '^\[patch\.' .cargo/config.toml 2>/dev/null; then \
echo -e "Ready to push: $(FONT_YELLOW)HOOKS WILL AUTO-DISABLE$(FONT_RESET)"; \
elif [ -n "$$(git status --porcelain)" ] || ([ -d "forge-core" ] && [ -n "$$(cd forge-core && git status --porcelain)" ]); then \
echo -e "Ready to push: $(FONT_YELLOW)MAYBE$(FONT_RESET) (uncommitted changes)"; \
else \
echo -e "Ready to push: $(FONT_GREEN)YES$(FONT_RESET)"; \
fi
@echo ""
# Quick help for cross-repo commands
dev-help:
@echo ""
@echo -e "$(FONT_BOLD)$(FONT_PURPLE)🔗 Cross-Repo Development Commands$(FONT_RESET)"
@echo ""
@echo -e "$(FONT_CYAN)Starting:$(FONT_RESET)"
@echo " make dev-core Enable local forge-core development"
@echo " make dev-core BRANCH=x Sync to a specific branch"
@echo ""
@echo -e "$(FONT_CYAN)How it works:$(FONT_RESET)"
@echo " 1. Clones/syncs forge-core to same branch as automagik-forge"
@echo " 2. If branch doesn't exist in forge-core, creates it from dev"
@echo " 3. Enables Cargo [patch] to use local forge-core paths"
@echo " 4. Installs pre-push hook to prevent accidental pushes"
@echo ""
@echo -e "$(FONT_CYAN)During development:$(FONT_RESET)"
@echo " make status Cross-repo status (branches, versions)"
@echo " make dev-core-status Detailed dev-core status"
@echo " make dev-core-check Health check diagnostics"
@echo ""
@echo -e "$(FONT_CYAN)Before PRs:$(FONT_RESET)"
@echo " git push Pre-push hook auto-disables patches"
@echo " make push-both Push BOTH repos together"
@echo " make pr-both Create PRs in BOTH repos (with RC label)"
@echo ""
@echo -e "$(FONT_CYAN)Single-Repo Experience:$(FONT_RESET)"
@echo " 1. make dev-core BRANCH=x Sync both repos to same branch"
@echo " 2. Edit files in both repos as needed"
@echo " 3. git add . && git commit Hooks auto-sync forge-core"
@echo " 4. git push Pre-push hook auto-disables patches"
@echo " 5. make pr-both Create PRs in both repos"
@echo ""
@echo -e "$(FONT_CYAN)Automation:$(FONT_RESET)"
@echo " When your automagik-forge PR merges to dev:"
@echo " - sync-to-forge-core.yml auto-syncs changes to forge-core"
@echo " - No manual interaction with forge-core repo needed"
@echo ""
@echo -e "$(FONT_CYAN)Safety:$(FONT_RESET)"
@echo " - Pre-push hook automatically disables patches before push"
@echo " - Commits forge-core first, then amends with patch removal"
@echo ""
# =============================================================================
# Push and PR for both repos (single-repo experience)
# =============================================================================
push-both: ## Push both repos (automagik-forge + forge-core) together
@echo -e "$(FONT_CYAN)🚀 Pushing both repos...$(FONT_RESET)"
@# Safety: dev-core must be OFF (use git push to auto-disable via hook)
@if grep -q '^forge-core-.*= { path' .cargo/config.toml 2>/dev/null; then \
echo -e "$(FONT_RED)❌ dev-core is ACTIVE - use 'git push' (hook will auto-disable)$(FONT_RESET)"; \
exit 1; \
fi
@# Safety: automagik-forge must be clean
@if [ -n "$$(git status --porcelain)" ]; then \
echo -e "$(FONT_RED)❌ automagik-forge has uncommitted changes$(FONT_RESET)"; \
exit 1; \
fi
@# Safety: forge-core must be clean (if exists)
@if [ -d "forge-core/.git" ] && [ -n "$$(cd forge-core && git status --porcelain)" ]; then \
echo -e "$(FONT_RED)❌ forge-core has uncommitted changes$(FONT_RESET)"; \
exit 1; \
fi
@# Push automagik-forge
@BRANCH=$$(git branch --show-current); \
git push origin $$BRANCH && \
echo -e "$(FONT_GREEN)✅ automagik-forge pushed$(FONT_RESET)"
@# Push forge-core (if exists and has commits)
@if [ -d "forge-core/.git" ]; then \
BRANCH=$$(cd forge-core && git branch --show-current); \
cd forge-core && git push origin $$BRANCH 2>/dev/null && \
echo -e "$(FONT_GREEN)✅ forge-core pushed$(FONT_RESET)" || \
echo -e "$(FONT_CYAN)ℹ️ forge-core already up to date$(FONT_RESET)"; \
fi
@echo -e "$(FONT_GREEN)✅ Both repos pushed successfully$(FONT_RESET)"
pr-both: ## Create PRs in both repos (linked)
@echo -e "$(FONT_CYAN)📝 Creating PRs in both repos...$(FONT_RESET)"
@# Safety checks
@if grep -q '^forge-core-.*= { path' .cargo/config.toml 2>/dev/null; then \
echo -e "$(FONT_RED)❌ dev-core is ACTIVE - use 'git push' (hook will auto-disable)$(FONT_RESET)"; \
exit 1; \
fi
@# Get branch name
@BRANCH=$$(git branch --show-current); \
echo -e "$(FONT_CYAN)Branch: $$BRANCH$(FONT_RESET)"