-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathinstall-plugin.sh
More file actions
executable file
·922 lines (822 loc) · 33 KB
/
install-plugin.sh
File metadata and controls
executable file
·922 lines (822 loc) · 33 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
#!/bin/bash
# AI Maestro Plugin Installer — 23blocks default plugin
#
# Installs the AI Maestro plugin: all skills, scripts, and CLI tools.
# This is the default plugin configuration maintained by 23blocks.
# Users can customize their own plugin builds by forking the plugin builder:
#
# Repo: https://github.com/23blocks-OS/ai-maestro-plugins
# Website: https://ai-maestro.23blocks.com/plugin-builder.html
#
# The plugin builder lets you compose custom skill sets from any source
# (GitHub repos, local files, private repos) into a single plugin.
# This installer ships the default set that supports AI Maestro.
#
# Usage:
# ./install-plugin.sh # Interactive mode
# ./install-plugin.sh -y # Non-interactive (install all)
# ./install-plugin.sh --migrate # Migrate from old messaging system
set -e
# Parse command line arguments
NON_INTERACTIVE=false
MIGRATE_ONLY=false
while [[ $# -gt 0 ]]; do
case $1 in
-y|--yes|--non-interactive)
NON_INTERACTIVE=true
shift
;;
--migrate)
MIGRATE_ONLY=true
shift
;;
-h|--help)
echo "AI Maestro Plugin Installer (23blocks default)"
echo ""
echo "Usage: ./install-plugin.sh [OPTIONS]"
echo ""
echo "Options:"
echo " -y, --yes Non-interactive mode (install all, assume yes)"
echo " --migrate Migrate from old messaging system only"
echo " -h, --help Show this help message"
echo ""
echo "This installer sets up the Agent Messaging Protocol (AMP) which provides:"
echo " - Local messaging between agents (works immediately)"
echo " - Federation with external providers (CrabMail, etc.)"
echo " - Cryptographic message signing (Ed25519)"
echo ""
exit 0
;;
*)
echo "Unknown option: $1"
echo "Use --help for usage information"
exit 1
;;
esac
done
# 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="⚠️ "
echo ""
echo "╔════════════════════════════════════════════════════════════════╗"
echo "║ ║"
echo "║ AI Maestro Plugin Installer (23blocks default) ║"
echo "║ ║"
echo "║ Skills, scripts, and CLI tools for your AI agents ║"
echo "║ Customize: ai-maestro.23blocks.com/plugin-builder.html ║"
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}"
}
# Derive absolute path from script location so it works when called from any CWD
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PLUGIN_DIR="$SCRIPT_DIR/plugin/plugins/ai-maestro"
if [ ! -d "$PLUGIN_DIR" ] || [ ! -d "$PLUGIN_DIR/scripts" ]; then
# Try to auto-initialize the submodule
if [ -f "$SCRIPT_DIR/.gitmodules" ] && command -v git &> /dev/null; then
print_warning "Plugin submodule not initialized. Initializing now..."
git -C "$SCRIPT_DIR" submodule update --init --recursive
if [ -d "$PLUGIN_DIR" ] && [ -d "$PLUGIN_DIR/scripts" ]; then
print_success "Submodule initialized"
else
print_error "Error: Failed to initialize plugin submodule."
echo ""
echo "Try manually:"
echo " git submodule update --init --recursive"
exit 1
fi
else
print_error "Error: Plugin not found. Run from AI Maestro root directory."
echo ""
echo "If this is a fresh clone, initialize submodules:"
echo " git submodule update --init --recursive"
echo ""
echo "Then run:"
echo " ./install-plugin.sh"
exit 1
fi
fi
# Validate agent name to prevent path traversal (only alphanumeric, hyphens, underscores)
_validate_agent_name() {
local name="$1"
if [ -z "$name" ]; then
return 1
fi
if echo "$name" | grep -qE '^[a-zA-Z0-9_-]+$'; then
return 0
fi
return 1
}
# Migration function
# Extract the recipient agent name from a message JSON file (for inbox placement)
# Checks: toAlias, toSession, .to (plain name), envelope.to (extract name before @)
_extract_recipient() {
local msg_file="$1"
local recipient=""
# Try toAlias first (old flat format)
recipient=$(jq -r '.toAlias // empty' "$msg_file" 2>/dev/null)
if [ -n "$recipient" ] && _validate_agent_name "$recipient"; then echo "$recipient"; return; fi
# Try toSession (some messages have this)
recipient=$(jq -r '.toSession // empty' "$msg_file" 2>/dev/null)
if [ -n "$recipient" ] && _validate_agent_name "$recipient"; then echo "$recipient"; return; fi
# Try .to as plain agent name (old format where to is a name, not UUID)
local to_val
to_val=$(jq -r '.to // empty' "$msg_file" 2>/dev/null)
if [ -n "$to_val" ] && ! echo "$to_val" | grep -qE '^[0-9a-f]{8}-'; then
# Not a UUID, treat as agent name
# Strip @domain if present
recipient=$(echo "$to_val" | cut -d'@' -f1)
if [ -n "$recipient" ] && _validate_agent_name "$recipient"; then echo "$recipient"; return; fi
fi
# Try AMP envelope format
local env_to
env_to=$(jq -r '.envelope.to // empty' "$msg_file" 2>/dev/null)
if [ -n "$env_to" ]; then
recipient=$(echo "$env_to" | cut -d'@' -f1)
if [ -n "$recipient" ] && _validate_agent_name "$recipient"; then echo "$recipient"; return; fi
fi
echo ""
}
# Extract the sender agent name from a message JSON file (for inbox subdirectory)
# Checks: fromAlias, .from (plain name), envelope.from (extract name before @)
_extract_sender() {
local msg_file="$1"
local sender=""
# Try fromAlias first (old flat format)
sender=$(jq -r '.fromAlias // empty' "$msg_file" 2>/dev/null)
if [ -n "$sender" ] && _validate_agent_name "$sender"; then echo "$sender"; return; fi
# Try .from as plain agent name
local from_val
from_val=$(jq -r '.from // empty' "$msg_file" 2>/dev/null)
if [ -n "$from_val" ] && ! echo "$from_val" | grep -qE '^[0-9a-f]{8}-'; then
sender=$(echo "$from_val" | cut -d'@' -f1)
if [ -n "$sender" ] && _validate_agent_name "$sender"; then echo "$sender"; return; fi
fi
# Try AMP envelope format
local env_from
env_from=$(jq -r '.envelope.from // empty' "$msg_file" 2>/dev/null)
if [ -n "$env_from" ]; then
sender=$(echo "$env_from" | cut -d'@' -f1)
if [ -n "$sender" ] && _validate_agent_name "$sender"; then echo "$sender"; return; fi
fi
echo ""
}
# Distribute messages from shared directory to per-agent directories
# This is the critical Phase 2 that ensures messages end up where agents read them
# Convert old flat-format message to AMP envelope format
# If message already has .envelope, returns it unchanged
_convert_to_amp_format() {
local msg_file="$1"
local now_ts
now_ts=$(date -u +%Y-%m-%dT%H:%M:%SZ)
# Check if already in AMP envelope format
local has_envelope
has_envelope=$(jq -r 'has("envelope")' "$msg_file" 2>/dev/null)
if [ "$has_envelope" = "true" ]; then
cat "$msg_file"
return
fi
# Convert old flat format to AMP envelope
jq --arg now "$now_ts" '
{
envelope: {
version: "amp/0.1",
id: .id,
from: ((.fromAlias // .from // "unknown") + "@local"),
to: ((.toAlias // .to // "unknown") + "@local"),
subject: (.subject // ""),
priority: (.priority // "normal"),
timestamp: (.timestamp // $now),
thread_id: (.inReplyTo // .id),
in_reply_to: (.inReplyTo // null),
expires_at: null,
signature: null
},
payload: (
if (.content | type) == "object" then
{
type: (.content.type // .type // "notification"),
message: (.content.message // ""),
context: (.content.context // null)
}
elif (.content | type) == "string" then
{
type: (.type // "notification"),
message: .content,
context: null
}
else
{
type: (.type // "notification"),
message: "",
context: null
}
end
),
metadata: {
status: (.status // "unread"),
migrated_from: "flat_format",
migrated_at: $now
},
local: {
status: (.status // "unread"),
received_at: (.timestamp // $now)
}
}' "$msg_file" 2>/dev/null
}
distribute_shared_to_per_agent() {
local SHARED_INBOX="$HOME/.agent-messaging/messages/inbox"
local SHARED_SENT="$HOME/.agent-messaging/messages/sent"
local AGENTS_BASE="$HOME/.agent-messaging/agents"
local DISTRIBUTED=0
local SKIPPED=0
# Distribute inbox messages
if [ -d "$SHARED_INBOX" ]; then
while IFS= read -r msg_file; do
local recipient
recipient=$(_extract_recipient "$msg_file")
local sender
sender=$(_extract_sender "$msg_file")
if [ -n "$recipient" ] && [ -n "$sender" ]; then
local dest_dir="$AGENTS_BASE/$recipient/messages/inbox/$sender"
local msg_basename
msg_basename=$(basename "$msg_file")
# Skip if already exists in destination
if [ -f "$dest_dir/$msg_basename" ]; then
continue
fi
mkdir -p "$dest_dir"
# Convert to AMP format and write
_convert_to_amp_format "$msg_file" > "$dest_dir/$msg_basename"
DISTRIBUTED=$((DISTRIBUTED + 1))
else
SKIPPED=$((SKIPPED + 1))
fi
done < <(find "$SHARED_INBOX" -name "*.json" -type f 2>/dev/null)
fi
# Distribute sent messages
if [ -d "$SHARED_SENT" ]; then
while IFS= read -r msg_file; do
local sender
sender=$(_extract_sender "$msg_file")
local recipient
recipient=$(_extract_recipient "$msg_file")
if [ -n "$sender" ] && [ -n "$recipient" ]; then
local dest_dir="$AGENTS_BASE/$sender/messages/sent/$recipient"
local msg_basename
msg_basename=$(basename "$msg_file")
if [ -f "$dest_dir/$msg_basename" ]; then
continue
fi
mkdir -p "$dest_dir"
_convert_to_amp_format "$msg_file" > "$dest_dir/$msg_basename"
DISTRIBUTED=$((DISTRIBUTED + 1))
else
SKIPPED=$((SKIPPED + 1))
fi
done < <(find "$SHARED_SENT" -name "*.json" -type f 2>/dev/null)
fi
if [ "$DISTRIBUTED" -gt 0 ]; then
# Redirect informational output to stderr so stdout only contains the count
print_success "Distributed $DISTRIBUTED messages to per-agent directories (AMP format)" >&2
fi
if [ "$SKIPPED" -gt 0 ]; then
# Redirect informational output to stderr so stdout only contains the count
print_warning "Skipped $SKIPPED messages (could not determine recipient/sender)" >&2
fi
# Only the numeric count goes to stdout for $() capture
echo "$DISTRIBUTED"
}
migrate_old_messages() {
echo ""
print_info "Checking for messages to migrate..."
local OLD_INBOX="$HOME/.aimaestro/messages/inbox"
local OLD_SENT="$HOME/.aimaestro/messages/sent"
local SHARED_INBOX="$HOME/.agent-messaging/messages/inbox"
local SHARED_SENT="$HOME/.agent-messaging/messages/sent"
local PHASE1_DONE=false
# ── Phase 1: Migrate from old ~/.aimaestro/messages/ to shared location ──
if [ -d "$OLD_INBOX" ] || [ -d "$OLD_SENT" ]; then
local OLD_COUNT=0
if [ -d "$OLD_INBOX" ]; then
OLD_COUNT=$(find "$OLD_INBOX" -name "*.json" 2>/dev/null | wc -l | tr -d ' ')
fi
local OLD_SENT_COUNT=0
if [ -d "$OLD_SENT" ]; then
OLD_SENT_COUNT=$(find "$OLD_SENT" -name "*.json" 2>/dev/null | wc -l | tr -d ' ')
fi
if [ "$((OLD_COUNT + OLD_SENT_COUNT))" -gt 0 ]; then
print_warning "Found $((OLD_COUNT + OLD_SENT_COUNT)) messages in old format (~/.aimaestro/messages/)"
if [ "$NON_INTERACTIVE" = true ]; then
local MIGRATE_CHOICE="y"
else
echo ""
echo " Messages will be migrated to per-agent directories."
echo ""
read -p "Migrate old messages? [Y/n]: " MIGRATE_CHOICE
MIGRATE_CHOICE=${MIGRATE_CHOICE:-Y}
fi
if [[ "$MIGRATE_CHOICE" =~ ^[Yy]$ ]]; then
mkdir -p "$SHARED_INBOX" "$SHARED_SENT"
# Copy inbox messages to shared (preserving them for Phase 2)
if [ -d "$OLD_INBOX" ]; then
for agent_dir in "$OLD_INBOX"/*; do
if [ -d "$agent_dir" ]; then
for msg in "$agent_dir"/*.json; do
if [ -f "$msg" ]; then
cp -n "$msg" "$SHARED_INBOX/" 2>/dev/null || true
fi
done
fi
done
fi
# Copy sent messages to shared
if [ -d "$OLD_SENT" ]; then
for agent_dir in "$OLD_SENT"/*; do
if [ -d "$agent_dir" ]; then
for msg in "$agent_dir"/*.json; do
if [ -f "$msg" ]; then
cp -n "$msg" "$SHARED_SENT/" 2>/dev/null || true
fi
done
fi
done
fi
# Backup old messages
local BACKUP_DIR="$HOME/.aimaestro/messages.backup.$(date +%Y%m%d-%H%M%S)"
if [ -d "$HOME/.aimaestro/messages" ]; then
mv "$HOME/.aimaestro/messages" "$BACKUP_DIR"
print_info "Old messages backed up to: $BACKUP_DIR"
fi
PHASE1_DONE=true
fi
fi
fi
# ── Phase 2: Distribute from shared to per-agent directories ──
# This runs regardless of Phase 1 - catches messages that were
# previously migrated to shared but never distributed
local SHARED_COUNT=0
if [ -d "$SHARED_INBOX" ]; then
SHARED_COUNT=$(find "$SHARED_INBOX" -name "*.json" 2>/dev/null | wc -l | tr -d ' ')
fi
local SHARED_SENT_COUNT=0
if [ -d "$SHARED_SENT" ]; then
SHARED_SENT_COUNT=$(find "$SHARED_SENT" -name "*.json" 2>/dev/null | wc -l | tr -d ' ')
fi
if [ "$((SHARED_COUNT + SHARED_SENT_COUNT))" -gt 0 ]; then
print_info "Distributing $((SHARED_COUNT + SHARED_SENT_COUNT)) messages to per-agent directories..."
local result
result=$(distribute_shared_to_per_agent)
if [ "$result" -gt 0 ] 2>/dev/null; then
# Backup shared messages and clean up
local SHARED_BACKUP="$HOME/.agent-messaging/messages.backup.$(date +%Y%m%d-%H%M%S)"
mv "$HOME/.agent-messaging/messages" "$SHARED_BACKUP"
print_info "Shared messages backed up to: $SHARED_BACKUP"
print_success "Messages are now in per-agent directories (~/.agent-messaging/agents/<name>/messages/)"
fi
else
if [ "$PHASE1_DONE" != true ]; then
print_info "No messages to migrate."
fi
fi
}
# Handle migrate-only mode
if [ "$MIGRATE_ONLY" = true ]; then
migrate_old_messages
echo ""
print_success "Migration complete!"
exit 0
fi
echo "🔍 Checking prerequisites..."
echo ""
# Track what needs to be installed
INSTALL_SCRIPTS=false
INSTALL_SKILL=false
PREREQUISITES_OK=true
# Check curl
print_info "Checking for curl..."
if command -v curl &> /dev/null; then
print_success "curl installed"
else
print_error "curl not found (required)"
PREREQUISITES_OK=false
fi
# Check jq
print_info "Checking for jq..."
if command -v jq &> /dev/null; then
print_success "jq installed"
else
print_error "jq not found (required for AMP)"
echo " Install with: brew install jq"
PREREQUISITES_OK=false
fi
# Check openssl
print_info "Checking for openssl..."
if command -v openssl &> /dev/null; then
OPENSSL_VERSION=$(openssl version | cut -d' ' -f2)
print_success "openssl installed (version $OPENSSL_VERSION)"
else
print_error "openssl not found (required for cryptographic signing)"
PREREQUISITES_OK=false
fi
# Check tmux (optional but recommended)
print_info "Checking for tmux..."
if command -v tmux &> /dev/null; then
TMUX_VERSION=$(tmux -V | cut -d' ' -f2)
print_success "tmux installed (version $TMUX_VERSION)"
else
print_warning "tmux not found (optional, for terminal notifications)"
fi
# Check Claude Code (optional)
print_info "Checking for Claude Code..."
if command -v claude &> /dev/null; then
CLAUDE_VERSION=$(claude --version 2>/dev/null | head -n1 || echo "unknown")
print_success "Claude Code installed ($CLAUDE_VERSION)"
INSTALL_SKILL=true
else
print_warning "Claude Code not found"
echo " Skills will not be available (CLI still works)"
echo " Install from: https://claude.ai/download"
fi
echo ""
if [ "$PREREQUISITES_OK" = false ]; then
print_error "Missing required prerequisites. Please install them and try again."
exit 1
fi
# Migrate messages: old format → shared → per-agent directories
# Runs if old messages exist OR if shared messages need distribution
if [ -d "$HOME/.aimaestro/messages" ] || [ -d "$HOME/.agent-messaging/messages/inbox" ] || [ -d "$HOME/.agent-messaging/messages/sent" ]; then
migrate_old_messages
fi
# Ask user what to install (or auto-select in non-interactive mode)
if [ "$NON_INTERACTIVE" = true ]; then
print_info "Non-interactive mode: installing scripts and skills..."
CHOICE=3
else
echo "📦 What would you like to install?"
echo ""
echo " 1) AMP scripts only (amp-send, amp-inbox, etc.)"
echo " 2) Claude Code skills only (requires Claude Code)"
echo " 3) Both scripts and skills (recommended)"
echo " 4) Cancel installation"
echo ""
read -p "Enter your choice (1-4): " CHOICE
fi
case $CHOICE in
1)
INSTALL_SCRIPTS=true
INSTALL_SKILL=false
;;
2)
INSTALL_SCRIPTS=false
INSTALL_SKILL=true
if ! command -v claude &> /dev/null; then
print_error "Claude Code not found. Cannot install skills."
exit 1
fi
;;
3)
INSTALL_SCRIPTS=true
INSTALL_SKILL=true
if ! command -v claude &> /dev/null; then
print_warning "Claude Code not found. Will install scripts only."
INSTALL_SKILL=false
fi
;;
4)
echo "Installation cancelled."
exit 0
;;
*)
print_error "Invalid choice. Installation cancelled."
exit 1
;;
esac
echo ""
echo "🚀 Starting installation..."
echo ""
# Install AMP scripts
if [ "$INSTALL_SCRIPTS" = true ]; then
print_info "Installing AMP scripts to ~/.local/bin/..."
# Create directory if it doesn't exist
mkdir -p ~/.local/bin
# Copy AMP scripts from plugin
SCRIPT_COUNT=0
for script in "$PLUGIN_DIR"/scripts/amp-*.sh; do
if [ -f "$script" ]; then
SCRIPT_NAME=$(basename "$script")
cp "$script" ~/.local/bin/
chmod +x ~/.local/bin/"$SCRIPT_NAME"
# Create symlink without .sh extension for convenience
# e.g., amp-init -> amp-init.sh
LINK_NAME="${SCRIPT_NAME%.sh}"
if [ "$LINK_NAME" != "$SCRIPT_NAME" ]; then
ln -sf "$SCRIPT_NAME" ~/.local/bin/"$LINK_NAME"
fi
print_success "Installed: $SCRIPT_NAME"
SCRIPT_COUNT=$((SCRIPT_COUNT + 1))
fi
done
echo ""
print_success "Installed $SCRIPT_COUNT AMP scripts (with symlinks)"
# Remove old messaging scripts that have been replaced by AMP
echo ""
print_info "Cleaning up old messaging scripts..."
OLD_SCRIPTS=(
"send-aimaestro-message.sh"
"check-aimaestro-messages.sh"
"read-aimaestro-message.sh"
"aimaestro-message-send.sh"
"aimaestro-message-check.sh"
"check-and-show-messages.sh"
"check-new-messages-arrived.sh"
"send-tmux-message.sh"
"forward-aimaestro-message.sh"
"reply-aimaestro-message.sh"
"messaging-helper.sh"
)
OLD_REMOVED=0
for old_script in "${OLD_SCRIPTS[@]}"; do
if [ -f "$HOME/.local/bin/$old_script" ]; then
# Safety check: only delete if script has AI Maestro header marker
# to avoid accidentally deleting user scripts with the same name
if head -5 "$HOME/.local/bin/$old_script" | grep -qi "AI Maestro" 2>/dev/null; then
rm -f "$HOME/.local/bin/$old_script"
print_success "Removed old script: $old_script"
OLD_REMOVED=$((OLD_REMOVED + 1))
else
print_warning "Skipped $old_script (no AI Maestro header - may be a user script)"
fi
fi
done
if [ "$OLD_REMOVED" -gt 0 ]; then
print_success "Removed $OLD_REMOVED old messaging script(s)"
else
echo " No old scripts found"
fi
# Also install other AI Maestro tools (graph, memory, docs, agent management)
echo ""
print_info "Installing additional AI Maestro tools..."
TOOL_COUNT=0
for script in "$PLUGIN_DIR"/scripts/*.sh; do
if [ -f "$script" ]; then
SCRIPT_NAME=$(basename "$script")
# Skip old messaging scripts (they're replaced by AMP)
if [[ "$SCRIPT_NAME" == *"aimaestro-message"* ]] || \
[[ "$SCRIPT_NAME" == "check-and-show-messages.sh" ]] || \
[[ "$SCRIPT_NAME" == "check-new-messages-arrived.sh" ]] || \
[[ "$SCRIPT_NAME" == "send-tmux-message.sh" ]]; then
continue
fi
cp "$script" ~/.local/bin/
chmod +x ~/.local/bin/"$SCRIPT_NAME"
print_success "Installed: $SCRIPT_NAME"
TOOL_COUNT=$((TOOL_COUNT + 1))
fi
done
echo ""
print_success "Installed $TOOL_COUNT additional tools (graph, memory, docs, agent management)"
# Install shell helpers
echo ""
print_info "Installing shell helpers..."
mkdir -p ~/.local/share/aimaestro/shell-helpers
if [ -f "$SCRIPT_DIR/scripts/shell-helpers/common.sh" ]; then
cp "$SCRIPT_DIR/scripts/shell-helpers/common.sh" ~/.local/share/aimaestro/shell-helpers/
chmod +x ~/.local/share/aimaestro/shell-helpers/common.sh
print_success "Installed: shell-helpers/common.sh"
fi
# Setup PATH
echo ""
print_info "Configuring PATH..."
# Dual guard: check runtime PATH and shell config marker to avoid duplicates
if [[ ":$PATH:" == *":$HOME/.local/bin:"* ]]; then
# Already in runtime PATH - no action needed
print_info "~/.local/bin already in PATH"
else
# Detect shell config file
SHELL_RC=""
if [ -n "$ZSH_VERSION" ] || [ "$SHELL" = "/bin/zsh" ]; then
SHELL_RC="$HOME/.zshrc"
elif [ -n "$BASH_VERSION" ] || [ "$SHELL" = "/bin/bash" ]; then
SHELL_RC="$HOME/.bashrc"
fi
if [ -n "$SHELL_RC" ] && [ -f "$SHELL_RC" ]; then
# Check for AI Maestro marker OR existing PATH entry to prevent duplicates
if grep -qF "# AI Maestro" "$SHELL_RC" 2>/dev/null || grep -qF '/.local/bin' "$SHELL_RC" 2>/dev/null; then
print_info "PATH already configured in $SHELL_RC"
else
echo '' >> "$SHELL_RC"
echo '# AI Maestro PATH (added by installer)' >> "$SHELL_RC"
echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$SHELL_RC"
print_success "Added ~/.local/bin to PATH in $SHELL_RC"
fi
fi
# Also add to current session
export PATH="$HOME/.local/bin:$PATH"
fi
fi
# Install Claude Code skills
if [ "$INSTALL_SKILL" = true ]; then
echo ""
print_info "Installing Claude Code skills to ~/.claude/skills/..."
mkdir -p ~/.claude/skills
# Install AMP messaging skill from plugin
if [ -d "$PLUGIN_DIR/skills/agent-messaging" ]; then
SKILL_INSTALL_OK=true
# Back up existing skill before replacing (preserves user customizations)
if [ -d ~/.claude/skills/agent-messaging ]; then
if ! cp -r ~/.claude/skills/agent-messaging ~/.claude/skills/agent-messaging.backup-"$(date +%Y%m%d%H%M%S)" 2>/dev/null; then
print_warning "Backup failed for agent-messaging skill, skipping install (existing skill preserved)"
SKILL_INSTALL_OK=false
fi
fi
if [ "$SKILL_INSTALL_OK" = true ]; then
# Copy new version to temp location first, then swap (safe against cp failure)
TEMP_SKILL_DIR=$(mktemp -d ~/.claude/skills/agent-messaging.tmp.XXXXXX)
if cp -r "$PLUGIN_DIR/skills/agent-messaging/." "$TEMP_SKILL_DIR/"; then
# Copy succeeded - remove old and rename temp to final
rm -rf ~/.claude/skills/agent-messaging
mv "$TEMP_SKILL_DIR" ~/.claude/skills/agent-messaging
print_success "Installed: agent-messaging skill (AMP protocol)"
if [ -f ~/.claude/skills/agent-messaging/SKILL.md ]; then
SKILL_SIZE=$(wc -c < ~/.claude/skills/agent-messaging/SKILL.md)
print_success "Skill file verified (${SKILL_SIZE} bytes)"
fi
else
# Copy failed - clean up temp, restore backup if we made one
rm -rf "$TEMP_SKILL_DIR"
if [ ! -d ~/.claude/skills/agent-messaging ]; then
# Original was removed somehow, restore from latest backup
LATEST_BACKUP=$(ls -1d ~/.claude/skills/agent-messaging.backup-* 2>/dev/null | tail -1)
if [ -n "$LATEST_BACKUP" ]; then
mv "$LATEST_BACKUP" ~/.claude/skills/agent-messaging
print_warning "Install failed, restored agent-messaging from backup"
fi
fi
print_error "Failed to install agent-messaging skill"
fi
fi
else
print_error "AMP messaging skill not found in plugin"
fi
# Install all other AI Maestro skills (auto-discovered from plugin)
for skill_dir in "$PLUGIN_DIR"/skills/*/; do
[ -d "$skill_dir" ] || continue
skill=$(basename "$skill_dir")
# agent-messaging already installed above
[ "$skill" = "agent-messaging" ] && continue
if [ -d "$PLUGIN_DIR/skills/$skill" ]; then
SKILL_INSTALL_OK=true
# Back up existing skill before replacing (preserves user customizations)
if [ -d ~/.claude/skills/"$skill" ]; then
if ! cp -r ~/.claude/skills/"$skill" ~/.claude/skills/"$skill".backup-"$(date +%Y%m%d%H%M%S)" 2>/dev/null; then
print_warning "Backup failed for $skill skill, skipping install (existing skill preserved)"
SKILL_INSTALL_OK=false
fi
fi
if [ "$SKILL_INSTALL_OK" = true ]; then
# Copy new version to temp location first, then swap (safe against cp failure)
TEMP_SKILL_DIR=$(mktemp -d ~/.claude/skills/"$skill".tmp.XXXXXX)
if cp -r "$PLUGIN_DIR/skills/$skill/." "$TEMP_SKILL_DIR/"; then
# Copy succeeded - remove old and rename temp to final
rm -rf ~/.claude/skills/"$skill"
mv "$TEMP_SKILL_DIR" ~/.claude/skills/"$skill"
print_success "Installed: $skill skill"
else
# Copy failed - clean up temp, restore backup if needed
rm -rf "$TEMP_SKILL_DIR"
if [ ! -d ~/.claude/skills/"$skill" ]; then
LATEST_BACKUP=$(ls -1d ~/.claude/skills/"$skill".backup-* 2>/dev/null | tail -1)
if [ -n "$LATEST_BACKUP" ]; then
mv "$LATEST_BACKUP" ~/.claude/skills/"$skill"
print_warning "Install failed for $skill, restored from backup"
fi
fi
print_error "Failed to install $skill skill"
fi
fi
fi
done
fi
echo ""
echo "🧪 Verifying installation..."
echo ""
# Verify AMP scripts
if [ "$INSTALL_SCRIPTS" = true ]; then
print_info "Checking AMP scripts..."
SCRIPTS_OK=true
for script_path in "$PLUGIN_DIR"/scripts/amp-*.sh; do
[ -f "$script_path" ] || continue
script=$(basename "$script_path")
if [ -x ~/.local/bin/"$script" ]; then
print_success "$script"
else
print_error "$script not found"
SCRIPTS_OK=false
fi
done
echo ""
if command -v amp-init.sh &> /dev/null; then
print_success "AMP scripts accessible in PATH"
else
print_warning "Restart terminal or run: source ~/.zshrc (or ~/.bashrc)"
fi
fi
# Verify skills
if [ "$INSTALL_SKILL" = true ]; then
echo ""
print_info "Checking installed skills..."
for skill_dir in "$PLUGIN_DIR"/skills/*/; do
[ -d "$skill_dir" ] || continue
skill=$(basename "$skill_dir")
if [ -f ~/.claude/skills/"$skill"/SKILL.md ]; then
print_success "$skill"
else
print_warning "$skill not found"
fi
done
fi
# Install Claude Code status line (shows agent identity + unread count)
if [ "$INSTALL_SCRIPTS" = true ] && command -v amp-statusline.sh &> /dev/null; then
echo ""
print_info "Configuring Claude Code status line..."
if amp-statusline.sh --install 2>/dev/null; then
print_success "Status line configured (shows agent identity + unread messages)"
else
print_warning "Status line setup skipped (run 'amp-statusline.sh --install' manually)"
fi
fi
echo ""
echo "╔════════════════════════════════════════════════════════════════╗"
echo "║ Installation Complete! ║"
echo "╚════════════════════════════════════════════════════════════════╝"
echo ""
# Show next steps
echo -e "${CYAN}📚 Getting Started with AMP${NC}"
echo ""
if [ "$INSTALL_SCRIPTS" = true ]; then
echo "1️⃣ Initialize your agent identity (first time only):"
echo ""
echo " $ amp-init.sh --auto"
echo ""
echo "2️⃣ Send a message to another agent:"
echo ""
echo " $ amp-send.sh alice \"Hello\" \"How are you?\""
echo ""
echo "3️⃣ Check your inbox:"
echo ""
echo " $ amp-inbox.sh"
echo ""
echo "4️⃣ Read a message:"
echo ""
echo " $ amp-read.sh <message-id>"
echo ""
fi
if [ "$INSTALL_SKILL" = true ]; then
echo "5️⃣ Or use natural language with Claude Code:"
echo ""
echo " > \"Check my messages\""
echo " > \"Send a message to backend-api about the deployment\""
echo " > \"Reply to the last message\""
echo ""
fi
echo "📖 Documentation:"
echo ""
echo " AMP Protocol: https://agentmessaging.org"
echo " AI Maestro: https://github.com/23blocks-OS/ai-maestro"
echo ""
# External provider registration (optional)
echo -e "${CYAN}🌐 Optional: Connect to External Providers${NC}"
echo ""
echo " To send messages to agents outside your local network:"
echo ""
echo " $ amp-register.sh --provider crabmail.ai --tenant mycompany"
echo ""
if [ "$INSTALL_SCRIPTS" = true ] && ! command -v amp-init.sh &> /dev/null; then
echo ""
print_warning "Remember to restart your terminal or run: source ~/.zshrc (or ~/.bashrc)"
fi
echo ""
echo "🎉 Happy agent messaging!"
echo ""