-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathaidevops.sh
More file actions
executable file
·3919 lines (3465 loc) · 125 KB
/
aidevops.sh
File metadata and controls
executable file
·3919 lines (3465 loc) · 125 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
#!/usr/bin/env bash
# AI DevOps Framework CLI
# Usage: aidevops <command> [options]
#
# Version: 3.1.0
set -euo pipefail
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m' # No Color
# Paths
INSTALL_DIR="$HOME/Git/aidevops"
AGENTS_DIR="$HOME/.aidevops/agents"
CONFIG_DIR="$HOME/.config/aidevops"
REPOS_FILE="$CONFIG_DIR/repos.json"
# shellcheck disable=SC2034 # Used in fresh install fallback
REPO_URL="https://github.com/marcusquinn/aidevops.git"
VERSION_FILE="$INSTALL_DIR/VERSION"
# Portable sed in-place edit (macOS BSD sed vs GNU sed)
sed_inplace() { if [[ "$(uname)" == "Darwin" ]]; then sed -i '' "$@"; else sed -i "$@"; fi; }
# Portable timeout (macOS has no coreutils timeout)
_timeout_cmd() {
local secs="$1"
shift
if command -v timeout &>/dev/null; then
timeout "$secs" "$@"
elif command -v gtimeout &>/dev/null; then
gtimeout "$secs" "$@"
elif command -v perl &>/dev/null; then
perl -e 'alarm shift; exec @ARGV' "$secs" "$@"
else
echo "[WARN] No timeout command available - running without timeout" >&2
"$@"
fi
}
print_info() { echo -e "${BLUE}[INFO]${NC} $1"; }
print_success() { echo -e "${GREEN}[OK]${NC} $1"; }
print_warning() { echo -e "${YELLOW}[WARN]${NC} $1"; }
print_error() { echo -e "${RED}[ERROR]${NC} $1"; }
print_header() { echo -e "${BOLD}${CYAN}$1${NC}"; }
# Get current version
get_version() {
if [[ -f "$VERSION_FILE" ]]; then
cat "$VERSION_FILE"
else
echo "unknown"
fi
}
# Get remote version
get_remote_version() {
# Use GitHub API (not cached) instead of raw.githubusercontent.com (cached 5 min)
local version
if command -v jq &>/dev/null; then
version=$(curl -fsSL "https://api.github.com/repos/marcusquinn/aidevops/contents/VERSION" 2>/dev/null | jq -r '.content // empty' 2>/dev/null | base64 -d 2>/dev/null | tr -d '\n')
if [[ -n "$version" ]]; then
echo "$version"
return 0
fi
fi
# Fallback to raw (cached) if jq unavailable or API fails
curl -fsSL "https://raw.githubusercontent.com/marcusquinn/aidevops/main/VERSION" 2>/dev/null || echo "unknown"
}
get_public_release_tag() {
local repo="$1"
local tag=""
tag=$(_timeout_cmd 15 curl -fsSL "https://api.github.com/repos/${repo}/releases/latest" 2>/dev/null |
grep -oE '"tag_name"[[:space:]]*:[[:space:]]*"v?[^"]+"' |
head -1 |
sed -E 's/.*"v?([^"]+)"/\1/' || true)
printf '%s\n' "$tag"
return 0
}
# Check if a command exists
check_cmd() {
command -v "$1" >/dev/null 2>&1
}
# Check if a directory exists
check_dir() {
[[ -d "$1" ]]
}
# Check if a file exists
check_file() {
[[ -f "$1" ]]
}
# Ensure file ends with a trailing newline (prevents malformed appends)
ensure_trailing_newline() {
local file="$1"
local last
last="$(tail -c 1 "$file"; printf x)"
[[ -s "$file" ]] && [[ "$last" != $'\n'x ]] && printf '\n' >>"$file"
}
# Initialize repos.json if it doesn't exist
init_repos_file() {
if [[ ! -f "$REPOS_FILE" ]]; then
mkdir -p "$CONFIG_DIR"
echo '{"initialized_repos": [], "git_parent_dirs": ["~/Git"]}' >"$REPOS_FILE"
elif command -v jq &>/dev/null; then
# Migrate: add git_parent_dirs if missing from existing repos.json
if ! jq -e '.git_parent_dirs' "$REPOS_FILE" &>/dev/null; then
local temp_file="${REPOS_FILE}.tmp"
if jq '. + {"git_parent_dirs": ["~/Git"]}' "$REPOS_FILE" >"$temp_file"; then
mv "$temp_file" "$REPOS_FILE"
else
rm -f "$temp_file"
fi
fi
# Migrate: backfill slug for entries missing it (detect from git remote)
local needs_slug
needs_slug=$(jq '[.initialized_repos[] | select(.slug == null or .slug == "")] | length' "$REPOS_FILE" 2>/dev/null) || needs_slug="0"
if [[ "$needs_slug" -gt 0 ]]; then
local temp_file="${REPOS_FILE}.tmp"
local repo_path slug
# Build a map of path->slug for repos missing slugs
while IFS= read -r repo_path; do
# Expand ~ to $HOME for git operations
local expanded_path="${repo_path/#\~/$HOME}"
slug=$(get_repo_slug "$expanded_path" 2>/dev/null) || slug=""
if [[ -n "$slug" ]]; then
jq --arg path "$repo_path" --arg slug "$slug" \
'(.initialized_repos[] | select(.path == $path and (.slug == null or .slug == ""))) |= . + {slug: $slug}' \
"$REPOS_FILE" >"$temp_file" && mv "$temp_file" "$REPOS_FILE"
fi
done < <(jq -r '.initialized_repos[] | select(.slug == null or .slug == "") | .path' "$REPOS_FILE" 2>/dev/null)
fi
fi
return 0
}
# Detect GitHub slug (owner/repo) from git remote origin
# Usage: get_repo_slug <path>
get_repo_slug() {
local repo_path="$1"
local remote_url
remote_url=$(git -C "$repo_path" remote get-url origin 2>/dev/null) || return 1
# Strip protocol/host prefix and .git suffix to get owner/repo
local slug
slug=$(echo "$remote_url" | sed 's|.*github\.com[:/]||;s|\.git$||')
if [[ -n "$slug" && "$slug" == *"/"* ]]; then
echo "$slug"
return 0
fi
return 1
}
# Register a repo in repos.json
# Usage: register_repo <path> <version> <features>
register_repo() {
local repo_path="$1"
local version="$2"
local features="$3"
init_repos_file
# Normalize path (resolve symlinks, remove trailing slash)
if ! repo_path=$(cd "$repo_path" 2>/dev/null && pwd -P); then
print_warning "Cannot access path: $repo_path"
return 1
fi
if ! command -v jq &>/dev/null; then
print_warning "jq not installed - repo tracking disabled"
return 0
fi
# Auto-detect GitHub slug from git remote
local slug=""
local is_local_only="false"
if ! slug=$(get_repo_slug "$repo_path" 2>/dev/null); then
slug=""
# No remote origin — mark as local_only
if ! git -C "$repo_path" remote get-url origin &>/dev/null; then
is_local_only="true"
fi
fi
# Auto-detect maintainer from gh API (current authenticated user)
# Only runs once per registration — preserved on subsequent updates
local maintainer=""
if command -v gh &>/dev/null; then
maintainer=$(gh api user --jq '.login' 2>/dev/null) || maintainer=""
fi
# Check if repo already registered
if jq -e --arg path "$repo_path" '.initialized_repos[] | select(.path == $path)' "$REPOS_FILE" &>/dev/null; then
# Update existing entry, preserving pulse/priority/local_only/maintainer if already set
local temp_file="${REPOS_FILE}.tmp"
jq --arg path "$repo_path" --arg version "$version" --arg features "$features" \
--arg slug "$slug" --argjson local_only "$is_local_only" --arg maintainer "$maintainer" \
'(.initialized_repos[] | select(.path == $path)) |= (
. + {path: $path, version: $version, features: ($features | split(",")), updated: (now | strftime("%Y-%m-%dT%H:%M:%SZ"))}
| if $slug != "" then .slug = $slug else . end
| if $local_only then .local_only = true else . end
| if (.maintainer == null or .maintainer == "") and $maintainer != "" then .maintainer = $maintainer else . end
)' \
"$REPOS_FILE" >"$temp_file" && mv "$temp_file" "$REPOS_FILE"
else
# Add new entry with slug and maintainer
local temp_file="${REPOS_FILE}.tmp"
local new_entry
# shellcheck disable=SC2016 # jq expressions use $var syntax, not shell expansion
if [[ -n "$slug" ]]; then
new_entry='{path: $path, slug: $slug, maintainer: $maintainer, version: $version, features: ($features | split(",")), initialized: (now | strftime("%Y-%m-%dT%H:%M:%SZ"))}'
elif [[ "$is_local_only" == "true" ]]; then
new_entry='{path: $path, local_only: true, maintainer: $maintainer, version: $version, features: ($features | split(",")), initialized: (now | strftime("%Y-%m-%dT%H:%M:%SZ"))}'
else
new_entry='{path: $path, maintainer: $maintainer, version: $version, features: ($features | split(",")), initialized: (now | strftime("%Y-%m-%dT%H:%M:%SZ"))}'
fi
jq --arg path "$repo_path" --arg version "$version" --arg features "$features" \
--arg slug "$slug" --arg maintainer "$maintainer" \
".initialized_repos += [$new_entry]" \
"$REPOS_FILE" >"$temp_file" && mv "$temp_file" "$REPOS_FILE"
fi
return 0
}
# Get list of registered repos
get_registered_repos() {
init_repos_file
if ! command -v jq &>/dev/null; then
echo "[]"
return 0
fi
jq -r '.initialized_repos[] | .path' "$REPOS_FILE" 2>/dev/null || echo ""
return 0
}
# Get the maintainer GitHub username for a repo
# Fallback chain: maintainer field > slug owner > empty string
# Usage: get_repo_maintainer <slug>
get_repo_maintainer() {
local slug="$1"
if ! command -v jq &>/dev/null; then
echo ""
return 0
fi
local maintainer
maintainer=$(jq -r --arg slug "$slug" \
'.initialized_repos[] | select(.slug == $slug) | .maintainer // empty' \
"$REPOS_FILE" 2>/dev/null) || maintainer=""
if [[ -n "$maintainer" ]]; then
echo "$maintainer"
return 0
fi
# Fallback: extract owner from slug (owner/repo -> owner)
if [[ -n "$slug" && "$slug" == *"/"* ]]; then
echo "${slug%%/*}"
return 0
fi
echo ""
return 0
}
# Check if a repo needs upgrade (version behind current)
check_repo_needs_upgrade() {
local repo_path="$1"
local current_version
current_version=$(get_version)
if ! command -v jq &>/dev/null; then
return 1
fi
local repo_version
repo_version=$(jq -r --arg path "$repo_path" '.initialized_repos[] | select(.path == $path) | .version' "$REPOS_FILE" 2>/dev/null)
if [[ -z "$repo_version" || "$repo_version" == "null" ]]; then
return 1
fi
# Compare versions (simple string comparison works for semver)
if [[ "$repo_version" != "$current_version" ]]; then
return 0 # needs upgrade
fi
return 1 # up to date
}
# Check if a planning file needs upgrading (version mismatch or missing TOON markers)
# Usage: check_planning_file_version <file> <template>
# Returns 0 if upgrade needed, 1 if up to date
check_planning_file_version() {
local file="$1" template="$2"
if [[ -f "$file" ]]; then
if ! grep -q "TOON:meta" "$file" 2>/dev/null; then
return 0
fi
local current_ver template_ver
current_ver=$(grep -A1 "TOON:meta" "$file" 2>/dev/null | tail -1 | cut -d',' -f1)
template_ver=$(grep -A1 "TOON:meta" "$template" 2>/dev/null | tail -1 | cut -d',' -f1)
if [[ -n "$template_ver" ]] && [[ "$current_ver" != "$template_ver" ]]; then
return 0
fi
return 1
else
# No file = no upgrade needed (init would create it)
return 1
fi
}
# Check if a repo's planning templates need upgrading
# Returns 0 if any planning file needs upgrade
check_planning_needs_upgrade() {
local repo_path="$1"
local todo_file="$repo_path/TODO.md"
local plans_file="$repo_path/todo/PLANS.md"
local todo_template="$AGENTS_DIR/templates/todo-template.md"
local plans_template="$AGENTS_DIR/templates/plans-template.md"
[[ ! -f "$todo_template" ]] && return 1
if check_planning_file_version "$todo_file" "$todo_template"; then
return 0
fi
if [[ -f "$plans_template" ]] && check_planning_file_version "$plans_file" "$plans_template"; then
return 0
fi
return 1
}
# Detect if current directory has aidevops but isn't registered
detect_unregistered_repo() {
local project_root
# Check if in a git repo
if ! git rev-parse --is-inside-work-tree &>/dev/null; then
return 1
fi
project_root=$(git rev-parse --show-toplevel 2>/dev/null)
# Check for .aidevops.json
if [[ ! -f "$project_root/.aidevops.json" ]]; then
return 1
fi
init_repos_file
if ! command -v jq &>/dev/null; then
return 1
fi
# Check if already registered
if jq -e --arg path "$project_root" '.initialized_repos[] | select(.path == $path)' "$REPOS_FILE" &>/dev/null; then
return 1 # already registered
fi
# Not registered - return the path
echo "$project_root"
return 0
}
# Check if on protected branch and offer worktree creation
# Returns 0 if safe to proceed, 1 if user cancelled
# Sets WORKTREE_PATH if worktree was created
check_protected_branch() {
local branch_type="${1:-chore}"
local branch_suffix="${2:-aidevops-setup}"
# Not in a git repo - skip check
if ! git rev-parse --is-inside-work-tree &>/dev/null; then
return 0
fi
local current_branch
current_branch=$(git branch --show-current 2>/dev/null || echo "")
# Not on a protected branch - safe to proceed
if [[ ! "$current_branch" =~ ^(main|master)$ ]]; then
return 0
fi
local project_root
project_root=$(git rev-parse --show-toplevel)
local repo_name
repo_name=$(basename "$project_root")
local suggested_branch="$branch_type/$branch_suffix"
echo ""
print_warning "On protected branch '$current_branch'"
echo ""
echo "Options:"
echo " 1. Create worktree: $suggested_branch (recommended)"
echo " 2. Continue on $current_branch (commits directly to main)"
echo " 3. Cancel"
echo ""
local choice
read -r -p "Choice [1]: " choice
choice="${choice:-1}"
case "$choice" in
1)
# Create worktree
local worktree_dir
worktree_dir="$(dirname "$project_root")/${repo_name}-${branch_type}-${branch_suffix}"
print_info "Creating worktree at $worktree_dir..."
if [[ -f "$AGENTS_DIR/scripts/worktree-helper.sh" ]]; then
if bash "$AGENTS_DIR/scripts/worktree-helper.sh" add "$suggested_branch" 2>/dev/null; then
export WORKTREE_PATH="$worktree_dir"
echo ""
print_success "Worktree created!"
print_info "Switching to: $worktree_dir"
echo ""
# Change to worktree directory
cd "$worktree_dir" || return 1
return 0
else
print_error "Failed to create worktree"
return 1
fi
else
# Fallback without helper script
if git worktree add -b "$suggested_branch" "$worktree_dir" 2>/dev/null; then
export WORKTREE_PATH="$worktree_dir"
echo ""
print_success "Worktree created!"
print_info "Switching to: $worktree_dir"
echo ""
cd "$worktree_dir" || return 1
return 0
else
print_error "Failed to create worktree"
return 1
fi
fi
;;
2)
print_warning "Continuing on $current_branch - changes will commit directly"
return 0
;;
3 | *)
print_info "Cancelled"
return 1
;;
esac
}
# Status command - check all installations
cmd_status() {
print_header "AI DevOps Framework Status"
echo "=========================="
echo ""
local current_version
current_version=$(get_version)
local remote_version
remote_version=$(get_remote_version)
# Version info
print_header "Version"
echo " Installed: $current_version"
echo " Latest: $remote_version"
if [[ "$current_version" != "$remote_version" && "$remote_version" != "unknown" ]]; then
print_warning "Update available! Run: aidevops update"
elif [[ "$current_version" == "$remote_version" ]]; then
print_success "Up to date"
fi
echo ""
# Installation paths
print_header "Installation"
if check_dir "$INSTALL_DIR"; then
print_success "Repository: $INSTALL_DIR"
else
print_error "Repository: Not found at $INSTALL_DIR"
fi
if check_dir "$AGENTS_DIR"; then
local agent_count
agent_count=$(find "$AGENTS_DIR" -name "*.md" -type f 2>/dev/null | wc -l | tr -d ' ')
print_success "Agents: $AGENTS_DIR ($agent_count files)"
else
print_error "Agents: Not deployed"
fi
echo ""
# Required dependencies
print_header "Required Dependencies"
for cmd in git curl jq ssh; do
if check_cmd "$cmd"; then
print_success "$cmd"
else
print_error "$cmd - not installed"
fi
done
echo ""
# Optional dependencies
print_header "Optional Dependencies"
if check_cmd sshpass; then
print_success "sshpass"
else
print_warning "sshpass - not installed (needed for password SSH)"
fi
echo ""
# Recommended tools
print_header "Recommended Tools"
# Tabby
if [[ "$(uname)" == "Darwin" ]]; then
if check_dir "/Applications/Tabby.app"; then
print_success "Tabby terminal"
else
print_warning "Tabby terminal - not installed"
fi
else
if check_cmd tabby; then
print_success "Tabby terminal"
else
print_warning "Tabby terminal - not installed"
fi
fi
# Zed
if [[ "$(uname)" == "Darwin" ]]; then
if check_dir "/Applications/Zed.app"; then
print_success "Zed editor"
# Check OpenCode extension
if check_dir "$HOME/Library/Application Support/Zed/extensions/installed/opencode"; then
print_success " └─ OpenCode extension"
else
print_warning " └─ OpenCode extension - not installed"
fi
else
print_warning "Zed editor - not installed"
fi
else
if check_cmd zed; then
print_success "Zed editor"
if check_dir "$HOME/.local/share/zed/extensions/installed/opencode"; then
print_success " └─ OpenCode extension"
else
print_warning " └─ OpenCode extension - not installed"
fi
else
print_warning "Zed editor - not installed"
fi
fi
echo ""
# Git CLI tools
print_header "Git CLI Tools"
if check_cmd gh; then
print_success "GitHub CLI (gh)"
else
print_warning "GitHub CLI (gh) - not installed"
fi
if check_cmd glab; then
print_success "GitLab CLI (glab)"
else
print_warning "GitLab CLI (glab) - not installed"
fi
if check_cmd tea; then
print_success "Gitea CLI (tea)"
else
print_warning "Gitea CLI (tea) - not installed"
fi
echo ""
# AI Tools
print_header "AI Tools & MCPs"
if check_cmd opencode; then
print_success "OpenCode CLI"
else
print_warning "OpenCode CLI - not installed"
fi
if check_cmd auggie; then
if check_file "$HOME/.augment/session.json"; then
print_success "Augment Context Engine (authenticated)"
else
print_warning "Augment Context Engine (not authenticated)"
fi
else
print_warning "Augment Context Engine - not installed"
fi
if check_cmd bd; then
print_success "Beads CLI (task graph)"
else
print_warning "Beads CLI (bd) - not installed"
fi
echo ""
# Python/Node environments
print_header "Development Environments"
if check_dir "$INSTALL_DIR/python-env/dspy-env"; then
print_success "DSPy Python environment"
else
print_warning "DSPy Python environment - not created"
fi
if check_cmd dspyground; then
print_success "DSPyGround"
else
print_warning "DSPyGround - not installed"
fi
echo ""
# AI Assistant configs
print_header "AI Assistant Configurations"
local ai_configs=(
"$HOME/.config/opencode/opencode.json:OpenCode"
"$HOME/.claude/commands:Claude Code CLI"
"$HOME/CLAUDE.md:Claude Code memory"
)
for config in "${ai_configs[@]}"; do
local path="${config%%:*}"
local name="${config##*:}"
if [[ -e "$path" ]]; then
print_success "$name"
else
print_warning "$name - not configured"
fi
done
echo ""
# SSH key
print_header "SSH Configuration"
if check_file "$HOME/.ssh/id_ed25519"; then
print_success "Ed25519 SSH key"
else
print_warning "Ed25519 SSH key - not found"
fi
echo ""
}
# Update/upgrade command
cmd_update() {
print_header "Updating AI DevOps Framework"
echo ""
local current_version
current_version=$(get_version)
print_info "Current version: $current_version"
print_info "Fetching latest version..."
if check_dir "$INSTALL_DIR/.git"; then
cd "$INSTALL_DIR" || exit 1
# Ensure we're on the main branch (detached HEAD or stale branch blocks pull)
local current_branch
current_branch=$(git branch --show-current 2>/dev/null || echo "")
if [[ "$current_branch" != "main" ]]; then
print_info "Switching to main branch..."
git checkout main --quiet 2>/dev/null || git checkout -b main origin/main --quiet 2>/dev/null || true
fi
# Clean up any working tree changes left by a previous update
# (e.g. chmod on tracked scripts, scan results written to repo)
# This ensures git pull --ff-only won't be blocked.
# Handles both staged and unstaged changes.
# See: https://github.com/marcusquinn/aidevops/issues/2286
if ! git diff --quiet 2>/dev/null || ! git diff --cached --quiet 2>/dev/null; then
print_info "Cleaning up stale working tree changes..."
git reset HEAD -- . 2>/dev/null || true
git checkout -- . 2>/dev/null || true
fi
# Fetch latest from origin (include tags for version consistency)
git fetch origin main --tags --quiet
local local_hash
local_hash=$(git rev-parse HEAD)
local remote_hash
remote_hash=$(git rev-parse origin/main)
if [[ "$local_hash" == "$remote_hash" ]]; then
print_success "Framework already up to date!"
# Even when repo is current, deployed agents may be stale
# (e.g., previous setup.sh was interrupted or failed)
local repo_version deployed_version
repo_version=$(cat "$INSTALL_DIR/VERSION" 2>/dev/null || echo "unknown")
deployed_version=$(cat "$HOME/.aidevops/agents/VERSION" 2>/dev/null || echo "none")
if [[ "$repo_version" != "$deployed_version" ]]; then
print_warning "Deployed agents ($deployed_version) don't match repo ($repo_version)"
print_info "Re-running setup to sync agents..."
bash "$INSTALL_DIR/setup.sh" --non-interactive
fi
# Safety net: discard any working tree changes setup.sh may have introduced
# (e.g. chmod on tracked scripts, scan results written to repo)
# See: https://github.com/marcusquinn/aidevops/issues/2286
git checkout -- . 2>/dev/null || true
else
print_info "Pulling latest changes..."
local old_hash
old_hash=$(git rev-parse HEAD)
if git pull --ff-only origin main --quiet; then
: # fast-forward succeeded
else
# Fast-forward failed (dirty tree, diverged history, or other issue).
# Since we just fetched origin/main, reset to it — the repo is managed
# by aidevops and should always track origin/main exactly.
# See: https://github.com/marcusquinn/aidevops/issues/2288
print_warning "Fast-forward pull failed — resetting to origin/main..."
git reset --hard origin/main --quiet 2>/dev/null || {
print_error "Failed to reset to origin/main"
print_info "Try: cd $INSTALL_DIR && git fetch origin && git reset --hard origin/main"
return 1
}
fi
local new_version new_hash
new_version=$(get_version)
new_hash=$(git rev-parse HEAD)
# Print bounded summary of meaningful changes
if [[ "$old_hash" != "$new_hash" ]]; then
local total_commits
total_commits=$(git rev-list --count "$old_hash..$new_hash" 2>/dev/null || echo "0")
if [[ "$total_commits" -gt 0 ]]; then
echo ""
print_info "Changes since $current_version ($total_commits commits):"
git log --oneline "$old_hash..$new_hash" |
grep -E '^[a-f0-9]+ (feat|fix|refactor|perf|docs):' |
head -20
if [[ "$total_commits" -gt 20 ]]; then
echo " ... and more (run 'git log --oneline' in $INSTALL_DIR for full list)"
fi
fi
fi
echo ""
print_info "Running setup to apply changes..."
local setup_exit=0
bash "$INSTALL_DIR/setup.sh" --non-interactive || setup_exit=$?
# Safety net: discard any working tree changes setup.sh may have introduced
# (e.g. chmod on tracked scripts, scan results written to repo)
# See: https://github.com/marcusquinn/aidevops/issues/2286
git checkout -- . 2>/dev/null || true
# Verify deployment: compare repo VERSION with deployed agents VERSION
# This catches silent setup.sh failures (e.g., non-interactive mode in
# environments where setup.sh exits early without deploying agents)
# See: https://github.com/marcusquinn/aidevops/issues/3980
local repo_version deployed_version
repo_version=$(cat "$INSTALL_DIR/VERSION" 2>/dev/null || echo "unknown")
deployed_version=$(cat "$HOME/.aidevops/agents/VERSION" 2>/dev/null || echo "none")
if [[ "$setup_exit" -ne 0 ]]; then
print_warning "Setup exited with code $setup_exit"
fi
if [[ "$repo_version" != "$deployed_version" ]]; then
print_warning "Agent deployment incomplete: repo=$repo_version, deployed=$deployed_version"
print_info "Run 'bash $INSTALL_DIR/setup.sh' manually to deploy agents"
else
print_success "Updated to version $new_version (agents deployed)"
fi
fi
else
print_warning "Repository not found, performing fresh install..."
# Download setup script to temp file first (not piped to shell)
local tmp_setup
tmp_setup=$(mktemp "${TMPDIR:-/tmp}/aidevops-setup-XXXXXX.sh") || {
print_error "Failed to create temp file for setup script"
return 1
}
trap 'rm -f "${tmp_setup:-}"' RETURN
if curl -fsSL "https://raw.githubusercontent.com/marcusquinn/aidevops/main/setup.sh" -o "$tmp_setup" 2>/dev/null && [[ -s "$tmp_setup" ]]; then
chmod +x "$tmp_setup"
bash "$tmp_setup"
local setup_exit=$?
rm -f "$tmp_setup"
[[ $setup_exit -ne 0 ]] && return 1
else
rm -f "$tmp_setup"
print_error "Failed to download setup script"
print_info "Try: git clone https://github.com/marcusquinn/aidevops.git $INSTALL_DIR && bash $INSTALL_DIR/setup.sh"
return 1
fi
fi
# Check registered repos for updates
echo ""
print_header "Checking Initialized Projects"
local repos_needing_upgrade=()
local current_ver
current_ver=$(get_version)
while IFS= read -r repo_path; do
[[ -z "$repo_path" ]] && continue
if [[ -d "$repo_path" ]]; then
if check_repo_needs_upgrade "$repo_path"; then
repos_needing_upgrade+=("$repo_path")
fi
fi
done < <(get_registered_repos)
if [[ ${#repos_needing_upgrade[@]} -eq 0 ]]; then
print_success "All registered projects are up to date"
else
echo ""
print_warning "${#repos_needing_upgrade[@]} project(s) may need updates:"
for repo in "${repos_needing_upgrade[@]}"; do
local repo_name
repo_name=$(basename "$repo")
echo " - $repo_name ($repo)"
done
echo ""
read -r -p "Update .aidevops.json version in these projects? [y/N] " response
if [[ "$response" =~ ^[Yy]$ ]]; then
for repo in "${repos_needing_upgrade[@]}"; do
if [[ -f "$repo/.aidevops.json" ]]; then
print_info "Updating $repo..."
# Update version in .aidevops.json
if command -v jq &>/dev/null; then
local temp_file="${repo}/.aidevops.json.tmp"
jq --arg version "$current_ver" '.version = $version' "$repo/.aidevops.json" >"$temp_file" &&
mv "$temp_file" "$repo/.aidevops.json"
# Update repos.json entry
local features
features=$(jq -r '[.features | to_entries[] | select(.value == true) | .key] | join(",")' "$repo/.aidevops.json" 2>/dev/null || echo "")
register_repo "$repo" "$current_ver" "$features"
print_success "Updated $(basename "$repo")"
else
print_warning "jq not installed - manual update needed for $repo"
fi
fi
done
fi
fi
# Check planning templates in registered repos
echo ""
print_header "Checking Planning Templates"
local repos_needing_planning=()
while IFS= read -r repo_path; do
[[ -z "$repo_path" ]] && continue
[[ ! -d "$repo_path" ]] && continue
# Only check repos with planning enabled
if [[ -f "$repo_path/.aidevops.json" ]]; then
local has_planning
has_planning=$(grep -o '"planning": *true' "$repo_path/.aidevops.json" 2>/dev/null || true)
if [[ -n "$has_planning" ]] && check_planning_needs_upgrade "$repo_path"; then
repos_needing_planning+=("$repo_path")
fi
fi
done < <(get_registered_repos)
if [[ ${#repos_needing_planning[@]} -eq 0 ]]; then
print_success "All planning templates are up to date"
else
echo ""
print_warning "${#repos_needing_planning[@]} project(s) have outdated planning templates:"
for repo in "${repos_needing_planning[@]}"; do
local repo_name
repo_name=$(basename "$repo")
local todo_ver
todo_ver=$(grep -A1 "TOON:meta" "$repo/TODO.md" 2>/dev/null | tail -1 | cut -d',' -f1)
echo " - $repo_name (v${todo_ver:-none})"
done
local template_ver
template_ver=$(grep -A1 "TOON:meta" "$AGENTS_DIR/templates/todo-template.md" 2>/dev/null | tail -1 | cut -d',' -f1)
echo ""
echo " Latest template: v${template_ver} (adds risk field, active session time estimates)"
echo ""
read -r -p "Upgrade planning templates in these projects? [y/N] " response
if [[ "$response" =~ ^[Yy]$ ]]; then
for repo in "${repos_needing_planning[@]}"; do
print_info "Upgrading $(basename "$repo")..."
# Run upgrade-planning in the repo context
(cd "$repo" && cmd_upgrade_planning --force) || print_warning "Failed to upgrade $(basename "$repo")"
done
else
print_info "Run 'aidevops upgrade-planning' in each project to upgrade manually"
fi
fi
# Quick tool staleness check (key tools only, <5s)
echo ""
print_header "Checking Key Tools"
local tool_check_script="$AGENTS_DIR/scripts/tool-version-check.sh"
if [[ -f "$tool_check_script" ]]; then
local stale_count=0
local stale_tools=""
# Check a few key tools quickly via npm view (parallel, ~2-3s total)
# bash 3.2-compatible: parallel arrays instead of associative array
local key_tool_cmds="opencode gh"
local key_tool_pkgs="opencode-ai brew:gh"
local idx=0
for cmd_name in $key_tool_cmds; do
local pkg_ref
pkg_ref=$(echo "$key_tool_pkgs" | cut -d' ' -f$((idx + 1)))
idx=$((idx + 1))
local installed=""
local latest=""
# Get installed version
if command -v "$cmd_name" &>/dev/null; then
installed=$("$cmd_name" --version 2>/dev/null | head -1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
else
continue
fi
[[ -z "$installed" ]] && continue
# Get latest version (npm, brew, or GitHub API) — timeout prevents hangs on slow registries
if [[ "$pkg_ref" == brew:* ]]; then
local brew_pkg="${pkg_ref#brew:}"
local brew_bin=""
brew_bin=$(command -v brew 2>/dev/null || true)
if [[ -n "$brew_bin" && -x "$brew_bin" ]]; then
latest=$(_timeout_cmd 30 "$brew_bin" info --json=v2 "$brew_pkg" | jq -r '.formulae[0].versions.stable // empty' || true)
elif [[ "$brew_pkg" == "gh" ]] && command -v gh &>/dev/null; then
# Fallback: use the public GitHub API so update still works when brew
# is unavailable or gh auth refresh is unhealthy.
latest=$(get_public_release_tag "cli/cli")
fi
else
latest=$(_timeout_cmd 30 npm view "$pkg_ref" version || true)
fi
[[ -z "$latest" ]] && continue
if [[ "$installed" != "$latest" ]]; then
stale_tools="${stale_tools:+$stale_tools, }$cmd_name ($installed -> $latest)"
((++stale_count))
fi
done
if [[ "$stale_count" -eq 0 ]]; then
print_success "Key tools are up to date"
else
print_warning "$stale_count tool(s) have updates: $stale_tools"
echo ""
read -r -p "Run full tool update check? [y/N] " response
if [[ "$response" =~ ^[Yy]$ ]]; then
bash "$tool_check_script" --update
else
print_info "Run 'aidevops update-tools --update' to update later"
fi
fi
else
print_info "Tool version check not available (run setup first)"
fi
return 0
}
# Uninstall command
cmd_uninstall() {
print_header "Uninstall AI DevOps Framework"
echo ""
print_warning "This will remove:"
echo " - $AGENTS_DIR (deployed agents)"
echo " - $INSTALL_DIR (repository)"
echo " - AI assistant configuration references"
echo " - Shell aliases (if added)"
echo ""
print_warning "This will NOT remove:"
echo " - Installed tools (Tabby, Zed, gh, glab, etc.)"
echo " - SSH keys"