-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathupdate-aimaestro.sh
More file actions
executable file
·366 lines (321 loc) · 12.2 KB
/
update-aimaestro.sh
File metadata and controls
executable file
·366 lines (321 loc) · 12.2 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
#!/bin/bash
# AI Maestro - Full Update Script
# Updates AI Maestro to the latest version including code, scripts, and skills
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Icons
CHECK="✅"
CROSS="❌"
INFO="ℹ️ "
WARN="⚠️ "
ROCKET="🚀"
DOWNLOAD="📥"
BUILD="🔨"
RESTART="🔄"
# Parse command line arguments
NON_INTERACTIVE=false
SKIP_MEMORY=false
SKIP_GRAPH=false
SKIP_DOCS=false
SKIP_HOOKS=false
SKIP_AGENT_CLI=false
while [[ $# -gt 0 ]]; do
case $1 in
-y|--yes|--non-interactive)
NON_INTERACTIVE=true
shift
;;
-h|--help)
echo "Usage: ./update-aimaestro.sh [OPTIONS]"
echo ""
echo "Options:"
echo " -y, --yes, --non-interactive Run without prompts (auto-accept all)"
echo " -h, --help Show this help message"
exit 0
;;
--skip-memory)
SKIP_MEMORY=true
shift
;;
--skip-graph)
SKIP_GRAPH=true
shift
;;
--skip-docs)
SKIP_DOCS=true
shift
;;
--skip-hooks)
SKIP_HOOKS=true
shift
;;
--skip-agent-cli)
SKIP_AGENT_CLI=true
shift
;;
*)
echo "Unknown option: $1"
echo "Use --help for usage information"
exit 1
;;
esac
done
echo ""
echo "╔════════════════════════════════════════════════════════════════╗"
echo "║ ║"
echo "║ AI Maestro - Full Updater ║"
echo "║ ║"
echo "╚════════════════════════════════════════════════════════════════╝"
echo ""
# Function to print colored messages
print_success() {
echo -e "${GREEN}${CHECK} $1${NC}"
}
print_error() {
echo -e "${RED}${CROSS} $1${NC}"
}
print_warning() {
echo -e "${YELLOW}${WARN} $1${NC}"
}
print_info() {
echo -e "${BLUE}${INFO}$1${NC}"
}
print_step() {
echo -e "${CYAN}${1} ${2}${NC}"
}
# Check if we're in the right directory
if [ ! -f "package.json" ] || [ ! -f "server.mjs" ]; then
print_error "Error: This script must be run from the AI Maestro root directory"
echo ""
echo "Usage:"
echo " cd /path/to/ai-maestro"
echo " ./update-aimaestro.sh"
exit 1
fi
# Get current version
CURRENT_VERSION=$(grep '"version"' package.json | head -1 | sed 's/.*"version": "\([^"]*\)".*/\1/')
echo "Current version: ${CYAN}${CURRENT_VERSION}${NC}"
echo ""
# Check for uncommitted changes
if [ -n "$(git status --porcelain)" ]; then
print_warning "You have uncommitted changes in your working directory"
echo ""
echo "Options:"
echo " 1) Stash changes and continue (git stash)"
echo " 2) Abort update"
echo ""
if [ "$NON_INTERACTIVE" = true ]; then
print_info "Non-interactive mode: auto-stashing changes..."
STASH_CHOICE="1"
else
read -p "Choose option (1/2): " STASH_CHOICE
fi
if [ "$STASH_CHOICE" = "1" ]; then
print_info "Stashing changes..."
git stash push -m "ai-maestro-update-$(date +%Y%m%d-%H%M%S)"
print_success "Changes stashed (use 'git stash pop' to restore)"
else
print_warning "Update cancelled"
exit 0
fi
fi
echo ""
print_step "$DOWNLOAD" "Fetching latest changes from GitHub..."
echo ""
# Fetch and show what's new
git fetch origin main
COMMITS_BEHIND=$(git rev-list HEAD..origin/main --count 2>/dev/null || echo "0")
if [ "$COMMITS_BEHIND" = "0" ]; then
print_success "You're already on the latest version!"
echo ""
# Ask if user wants to reinstall scripts/skills anyway
if [ "$NON_INTERACTIVE" = true ]; then
print_info "Non-interactive mode: reinstalling scripts and skills..."
REINSTALL="y"
else
read -p "Would you like to reinstall scripts and skills anyway? (y/n): " REINSTALL
fi
if [[ ! "$REINSTALL" =~ ^[Yy]$ ]]; then
exit 0
fi
else
echo "New commits available: ${GREEN}${COMMITS_BEHIND}${NC}"
echo ""
echo "Recent changes:"
git log HEAD..origin/main --oneline | head -10
echo ""
if [ "$NON_INTERACTIVE" = true ]; then
print_info "Non-interactive mode: proceeding with update..."
CONFIRM="y"
else
read -p "Continue with update? (y/n): " CONFIRM
fi
if [[ ! "$CONFIRM" =~ ^[Yy]$ ]]; then
print_warning "Update cancelled"
exit 0
fi
echo ""
print_step "$DOWNLOAD" "Pulling latest changes..."
BEFORE_SHA=$(git rev-parse HEAD)
git pull origin main
print_success "Code updated"
# Detect ecosystem.config.js changes that require PM2 config reload
if ! git diff --quiet "$BEFORE_SHA" HEAD -- ecosystem.config.js ecosystem.config.cjs 2>/dev/null; then
ECOSYSTEM_CHANGED=true
fi
fi
# Get new version
NEW_VERSION=$(grep '"version"' package.json | head -1 | sed 's/.*"version": "\([^"]*\)".*/\1/')
echo ""
print_step "$BUILD" "Installing dependencies..."
# Issue 7.1: Don't let yarn install failure abort the entire update under set -e
yarn install --frozen-lockfile 2>/dev/null || yarn install || { print_warning "yarn install had warnings but continuing..."; }
print_success "Dependencies installed"
# Issue 7.2: Track build failure so tool reinstallation still proceeds under set -e
BUILD_FAILED=false
VERIFICATION_WARNINGS=false
ECOSYSTEM_CHANGED=${ECOSYSTEM_CHANGED:-false}
echo ""
print_step "$BUILD" "Building application..."
if yarn build; then
print_success "Build complete"
else
print_warning "Build failed - continuing with tool reinstallation"
BUILD_FAILED=true
fi
echo ""
print_step "$ROCKET" "Reinstalling scripts and skills..."
# ── v0.21.26 fix: delegate to component installers ──────────────────────
# Previously this section iterated separate script directories.
# Scripts now live in plugin/plugins/ai-maestro/scripts/ (submodule).
# The component installers are the single source of truth for each tool category.
# ─────────────────────────────────────────────────────────────────────────
# 1. AMP messaging scripts + all plugin/scripts/* tools + skills
if [ -f "install-plugin.sh" ]; then
print_info "Reinstalling AMP messaging & CLI tools..."
./install-plugin.sh -y
print_success "Messaging & CLI tools reinstalled"
else
print_warning "install-plugin.sh not found - skipping messaging tools"
fi
# 2. Memory tools (optional — skip with --skip-memory)
if [ "$SKIP_MEMORY" != true ] && [ -f "install-memory-tools.sh" ]; then
print_info "Reinstalling memory tools..."
./install-memory-tools.sh -y
print_success "Memory tools reinstalled"
fi
# 3. Graph tools (optional — skip with --skip-graph)
if [ "$SKIP_GRAPH" != true ] && [ -f "install-graph-tools.sh" ]; then
print_info "Reinstalling graph tools..."
./install-graph-tools.sh -y
print_success "Graph tools reinstalled"
fi
# 4. Doc tools (optional — skip with --skip-docs)
if [ "$SKIP_DOCS" != true ] && [ -f "install-doc-tools.sh" ]; then
print_info "Reinstalling doc tools..."
./install-doc-tools.sh -y
print_success "Doc tools reinstalled"
fi
# 5. Agent CLI (optional — skip with --skip-agent-cli)
if [ "$SKIP_AGENT_CLI" != true ] && [ -f "install-agent-cli.sh" ]; then
print_info "Reinstalling agent management CLI..."
./install-agent-cli.sh -y
print_success "Agent CLI reinstalled"
fi
# 6. Claude Code hooks (optional — skip with --skip-hooks)
if [ "$SKIP_HOOKS" != true ] && [ -f "scripts/claude-hooks/install-hooks.sh" ]; then
print_info "Reinstalling Claude Code hooks..."
./scripts/claude-hooks/install-hooks.sh -y
print_success "Claude Code hooks reinstalled"
fi
# 7. Marketplace plugin auto-updates via Claude Code /install update
# No manual sync needed — the ai-maestro-plugins repo is the single source
# Issue 7.12: Capture verification exit code instead of piping to || true
if [ -f "verify-installation.sh" ]; then
echo ""
print_info "Running installation verification..."
if ! ./verify-installation.sh; then
print_warning "Some verification checks failed. Review the output above."
VERIFICATION_WARNINGS=true
fi
fi
# Check if PM2 is managing ai-maestro
echo ""
if command -v pm2 &> /dev/null; then
if pm2 list | grep -q "ai-maestro"; then
if [[ "$BUILD_FAILED" != "true" ]]; then
if [ "$ECOSYSTEM_CHANGED" = true ]; then
print_warning "ecosystem.config.js changed — reloading PM2 config..."
pm2 delete ai-maestro 2>/dev/null || true
pm2 start ecosystem.config.js 2>/dev/null || pm2 start ecosystem.config.cjs 2>/dev/null || {
print_error "Failed to start with ecosystem config — falling back to pm2 restart"
pm2 start "yarn start" --name ai-maestro
}
else
print_step "$RESTART" "Restarting AI Maestro via PM2..."
pm2 restart ai-maestro
fi
print_success "AI Maestro restarted"
# Wait a moment for startup
sleep 2
# Check status
if pm2 list | grep "ai-maestro" | grep -q "online"; then
print_success "AI Maestro is running"
else
print_warning "AI Maestro may not have started correctly"
echo " Check logs with: pm2 logs ai-maestro"
fi
else
print_warning "Skipping PM2 restart due to build failure"
echo " Fix the build errors and run: pm2 restart ai-maestro"
fi
else
print_info "AI Maestro not found in PM2 process list"
echo " Start it with: pm2 start ecosystem.config.js"
fi
else
print_info "PM2 not installed - skipping automatic restart"
echo " Start manually with: yarn start"
fi
# Report accumulated warnings from build/verification at the end
if [ "$BUILD_FAILED" = true ]; then
echo ""
print_error "Build failed during update - please check TypeScript errors and run 'yarn build' manually"
fi
if [ "$VERIFICATION_WARNINGS" = true ]; then
echo ""
print_warning "Installation verification reported issues - review the warnings above"
fi
echo ""
echo "╔════════════════════════════════════════════════════════════════╗"
if [ "$BUILD_FAILED" = true ] || [ "$VERIFICATION_WARNINGS" = true ]; then
echo "║ Update Complete (with warnings) ║"
else
echo "║ Update Complete! ║"
fi
echo "╚════════════════════════════════════════════════════════════════╝"
echo ""
if [ "$CURRENT_VERSION" != "$NEW_VERSION" ]; then
echo "Updated: ${YELLOW}${CURRENT_VERSION}${NC} → ${GREEN}${NEW_VERSION}${NC}"
else
echo "Version: ${GREEN}${NEW_VERSION}${NC} (reinstalled)"
fi
echo ""
print_info "What's updated:"
echo " • Application code and dependencies (git pull + yarn build)"
echo " • AMP messaging scripts (amp-*.sh)"
echo " • Agent CLI (aimaestro-agent.sh, agent-helper.sh)"
echo " • Memory, graph, and docs CLI tools"
echo " • Claude Code skills and hooks"
echo ""
print_warning "IMPORTANT: Restart your Claude Code sessions to reload updated skills"
echo " In each tmux session:"
echo " 1. Exit Claude Code (type 'exit' or Ctrl+D)"
echo " 2. Restart Claude Code (type 'claude')"
echo ""