forked from jontsai/openclaw-command-center
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
141 lines (122 loc) Β· 4.82 KB
/
Makefile
File metadata and controls
141 lines (122 loc) Β· 4.82 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
# OpenClaw Command Center
# Usage: make [target]
#
# Runs dashboard in tmux for easy inspection and management
TMUX_SESSION := openclaw-dashboard
LOG_DIR := $(HOME)/.openclaw-command-center/logs
LOG_FILE := $(LOG_DIR)/dashboard.log
DASHBOARD_DIR := $(CURDIR)
PORT := 3333
.DEFAULT_GOAL := help
.PHONY: help ensure start stop restart status logs attach clean release install-hooks check test lint build
# Include local overrides if they exist (not tracked in git)
-include Makefile.local
help: ## Show this help
@echo "OpenClaw Command Center - tmux-based management"
@echo ""
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sed 's/^[^:]*://' | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
@echo ""
@echo "Quick start: make start && make attach"
ensure: ## Ensure dashboard is running (idempotent, self-healing)
@mkdir -p $(LOG_DIR)
@touch $(LOG_FILE)
@if ! command -v tmux >/dev/null 2>&1; then \
echo "β tmux not found. Please install tmux."; \
exit 1; \
fi
@if ! command -v node >/dev/null 2>&1; then \
echo "β node not found. Please install node."; \
exit 1; \
fi
@if ! tmux has-session -t $(TMUX_SESSION) 2>/dev/null; then \
echo "Creating tmux session '$(TMUX_SESSION)'..."; \
tmux new-session -d -s $(TMUX_SESSION) -c $(DASHBOARD_DIR) \
"./scripts/dashboard-loop.sh; echo '[Loop exited - shell ready]'; exec bash -l"; \
tmux split-window -h -t $(TMUX_SESSION) -c $(DASHBOARD_DIR) "exec bash -l"; \
tmux select-pane -t $(TMUX_SESSION):0.0; \
tmux split-window -v -t $(TMUX_SESSION) "tail -f $(LOG_FILE); exec bash -l"; \
tmux select-pane -t $(TMUX_SESSION):0.0; \
sleep 2; \
echo "β
Dashboard started on port $(PORT)."; \
elif ! tmux list-panes -t $(TMUX_SESSION):0 2>/dev/null | grep -q "^0:"; then \
echo "β οΈ Session exists but is malformed. Recreating..."; \
tmux kill-session -t $(TMUX_SESSION) 2>/dev/null || true; \
$(MAKE) ensure; \
elif [ "$$(tmux display-message -t $(TMUX_SESSION):0.0 -p '#{pane_dead}')" = "1" ]; then \
echo "β οΈ Dashboard pane died. Respawning..."; \
tmux respawn-pane -k -t $(TMUX_SESSION):0.0 -c $(DASHBOARD_DIR) \
"node lib/server.js 2>&1 | tee -a $(LOG_FILE); echo '[Dashboard exited - shell ready]'; exec bash -l"; \
echo "β
Dashboard respawned."; \
elif [ "$$(tmux display-message -t $(TMUX_SESSION):0.2 -p '#{pane_dead}')" = "1" ]; then \
echo "β οΈ Logs pane died. Respawning..."; \
tmux respawn-pane -k -t $(TMUX_SESSION):0.2 "tail -f $(LOG_FILE); exec bash -l"; \
echo "β
Logs pane respawned."; \
else \
echo "β
Dashboard already running on port $(PORT)."; \
fi
start: ensure ## Start dashboard in tmux (alias for ensure)
stop: ## Stop dashboard
@if tmux has-session -t $(TMUX_SESSION) 2>/dev/null; then \
echo "Stopping dashboard..."; \
tmux send-keys -t $(TMUX_SESSION) C-c; \
sleep 1; \
tmux kill-session -t $(TMUX_SESSION) 2>/dev/null || true; \
echo "β
Dashboard stopped."; \
else \
echo "Dashboard not running."; \
fi
restart: stop start ## Restart dashboard
status: ## Show dashboard status
@echo "=== tmux session ==="
@tmux has-session -t $(TMUX_SESSION) 2>/dev/null && echo "β
Running" || echo "β Not running"
@echo ""
@echo "=== Port $(PORT) ==="
@lsof -i :$(PORT) 2>/dev/null | head -5 || echo "Port $(PORT) not in use"
@echo ""
@echo "=== Recent logs ==="
@tail -5 $(LOG_FILE) 2>/dev/null || echo "No logs"
logs: ## Tail dashboard logs
@tail -f $(LOG_FILE)
attach: ## Attach to tmux session (Ctrl-B D to detach)
@if ! tmux has-session -t $(TMUX_SESSION) 2>/dev/null; then \
echo "Dashboard not running. Use 'make start' to start."; \
elif [ -n "$$TMUX" ]; then \
CURRENT=$$(tmux display-message -p '#S'); \
if [ "$$CURRENT" = "$(TMUX_SESSION)" ]; then \
echo "Already in $(TMUX_SESSION) session."; \
else \
tmux switch-client -t $(TMUX_SESSION); \
fi \
else \
tmux attach -t $(TMUX_SESSION); \
fi
clean: ## Stop dashboard and clean logs
@$(MAKE) stop
@echo "Cleaning logs..."
@rm -f $(LOG_FILE)
@echo "β
Cleaned."
release: ## Create a release (usage: make release V=0.4.0)
ifndef V
@echo "Usage: make release V=<version>"
@echo " e.g., make release V=0.4.0"
@./scripts/release.sh --current
else
@./scripts/release.sh $(V)
endif
install-hooks: ## Install git pre-commit hooks
@echo "Installing pre-commit hook..."
@cp scripts/pre-commit .git/hooks/pre-commit
@chmod +x .git/hooks/pre-commit
@echo "β
Pre-commit hook installed."
@echo "Run 'make check' to test checks manually."
check: ## Run pre-commit checks manually
@./scripts/pre-commit
# ============================================================================
# Development targets
# ============================================================================
test: ## Run tests
@npm test
lint: ## Run linter
@npm run lint
build: ## Build bundled server.js from src modules
@npm run build