aidevops 3.39.271 → 3.39.273

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -25,7 +25,7 @@ token efficiency, and quality control built in.**
25
25
  [![Maintainability](https://qlty.sh/gh/marcusquinn/projects/aidevops/maintainability.svg)](https://qlty.sh/gh/marcusquinn/projects/aidevops)
26
26
  [![Codacy Badge](https://app.codacy.com/project/badge/Grade/2b1adbd66c454dae92234341e801b984)](https://app.codacy.com/gh/marcusquinn/aidevops/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
27
27
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
28
- [![Version](https://img.shields.io/badge/Version-3.39.271-blue.svg)](https://github.com/marcusquinn/aidevops/releases)
28
+ [![Version](https://img.shields.io/badge/Version-3.39.273-blue.svg)](https://github.com/marcusquinn/aidevops/releases)
29
29
  [![npm version](https://img.shields.io/npm/v/aidevops)](https://www.npmjs.com/package/aidevops)
30
30
  [![Homebrew](https://img.shields.io/badge/homebrew-marcusquinn%2Ftap-orange)](https://github.com/marcusquinn/homebrew-tap)
31
31
 
package/VERSION CHANGED
@@ -1 +1 @@
1
- 3.39.271
1
+ 3.39.273
package/aidevops.sh CHANGED
@@ -5,7 +5,7 @@
5
5
  # AI DevOps Framework CLI
6
6
  # Usage: aidevops <command> [options]
7
7
  #
8
- # Version: 3.39.271
8
+ # Version: 3.39.273
9
9
 
10
10
  set -euo pipefail
11
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aidevops",
3
- "version": "3.39.271",
3
+ "version": "3.39.273",
4
4
  "description": "AI DevOps Framework - AI-assisted development workflows, code quality, and deployment automation",
5
5
  "type": "module",
6
6
  "packageManager": "bun@1.3.11",
package/setup.sh CHANGED
@@ -17,7 +17,7 @@ fi
17
17
  # AI Assistant Server Access Framework Setup Script
18
18
  # Helps developers set up the framework for their infrastructure
19
19
  #
20
- # Version: 3.39.271
20
+ # Version: 3.39.273
21
21
  #
22
22
  # Quick Install:
23
23
  # npm install -g aidevops && aidevops update (recommended)
@@ -375,6 +375,15 @@ source "${SETUP_IMPL_MODULES_DIR}/plugins.sh"
375
375
  source "${SETUP_IMPL_MODULES_DIR}/schedulers.sh"
376
376
  # shellcheck disable=SC1091
377
377
  source "${SETUP_IMPL_MODULES_DIR}/post-setup.sh"
378
+ # shellcheck source=.agents/scripts/setup/modules/setup-interface.sh
379
+ # shellcheck disable=SC1091 # Resolved after bootstrap via the setup module directory
380
+ source "${SETUP_IMPL_MODULES_DIR}/setup-interface.sh"
381
+ # shellcheck source=.agents/scripts/setup/modules/setup-execution.sh
382
+ # shellcheck disable=SC1091 # Resolved after bootstrap via the setup module directory
383
+ source "${SETUP_IMPL_MODULES_DIR}/setup-execution.sh"
384
+ # shellcheck source=.agents/scripts/setup/modules/setup-postflight.sh
385
+ # shellcheck disable=SC1091 # Resolved after bootstrap via the setup module directory
386
+ source "${SETUP_IMPL_MODULES_DIR}/setup-postflight.sh"
378
387
 
379
388
  parse_args() {
380
389
  while [[ $# -gt 0 ]]; do
@@ -452,135 +461,6 @@ parse_args() {
452
461
  return 0
453
462
  }
454
463
 
455
- _setup_print_stage_help() {
456
- printf '%s\n' "Supported setup stages/scopes:"
457
- printf ' opencode | %s Repair/install OpenCode CLI only\n' "$SETUP_STAGE_OPENCODE"
458
- printf ' agents | %s Deploy .agents scripts/prompts only\n' "$SETUP_STAGE_AGENTS"
459
- printf ' runtime-config | %s Reconcile generated runtime commands/configuration\n' "$SETUP_STAGE_RUNTIME_CONFIG"
460
- printf ' source-access | %s Install/verify the signed root broker\n' "$SETUP_STAGE_SOURCE_ACCESS"
461
- printf ' hooks | %s Install safety hooks only\n' "$SETUP_STAGE_HOOKS"
462
- printf ' tabby | %s Sync Tabby profiles only\n' "$SETUP_STAGE_TABBY"
463
- printf ' pulse | %s Install/refresh pulse scheduler only\n' "$SETUP_STAGE_PULSE"
464
- printf ' gui-desktop | gui | app | %s Install native macOS %s only\n' "$SETUP_STAGE_GUI_DESKTOP" "$SETUP_GUI_APP_NAME"
465
- printf ' ai-session | ai | %s Run changed deploy stages, then full setup on failure\n' "$SETUP_STAGE_AI_SESSION"
466
- printf '%s\n' " full Run the default full setup path"
467
- return 0
468
- }
469
-
470
- _setup_canonical_stage() {
471
- local stage="$1"
472
- case "$stage" in
473
- opencode | "$SETUP_STAGE_OPENCODE") printf '%s' "$SETUP_STAGE_OPENCODE" ;;
474
- agents | "$SETUP_STAGE_AGENTS") printf '%s' "$SETUP_STAGE_AGENTS" ;;
475
- runtime-config | runtime | "$SETUP_STAGE_RUNTIME_CONFIG") printf '%s' "$SETUP_STAGE_RUNTIME_CONFIG" ;;
476
- source-access | "$SETUP_STAGE_SOURCE_ACCESS") printf '%s' "$SETUP_STAGE_SOURCE_ACCESS" ;;
477
- hooks | "$SETUP_STAGE_HOOKS") printf '%s' "$SETUP_STAGE_HOOKS" ;;
478
- tabby | "$SETUP_STAGE_TABBY") printf '%s' "$SETUP_STAGE_TABBY" ;;
479
- pulse | "$SETUP_STAGE_PULSE") printf '%s' "$SETUP_STAGE_PULSE" ;;
480
- gui-desktop | gui | app | "$SETUP_STAGE_GUI_DESKTOP") printf '%s' "$SETUP_STAGE_GUI_DESKTOP" ;;
481
- ai-session | ai | "$SETUP_STAGE_AI_SESSION") printf '%s' "$SETUP_STAGE_AI_SESSION" ;;
482
- full) printf '%s' "full" ;;
483
- *) return 1 ;;
484
- esac
485
- return 0
486
- }
487
-
488
- _setup_validate_stage() {
489
- local stage="$1"
490
- if _setup_canonical_stage "$stage" >/dev/null; then
491
- return 0
492
- fi
493
- print_error "Unknown setup stage/scope: $stage"
494
- _setup_print_stage_help
495
- return 1
496
- }
497
-
498
- _setup_gui_desktop_install_opted_in() {
499
- local flag="${AIDEVOPS_GUI_DESKTOP_INSTALL:-false}"
500
- case "$flag" in
501
- 1 | true | TRUE | yes | YES | on | ON)
502
- return 0
503
- ;;
504
- esac
505
- return 1
506
- }
507
-
508
- _setup_gui_desktop_app_dir() {
509
- printf '%s' "${AIDEVOPS_GUI_DESKTOP_APP_DIR:-/Applications}"
510
- return 0
511
- }
512
-
513
- _setup_gui_desktop_app_exists() {
514
- local app_dir="$1"
515
- [[ -d "${app_dir}/${SETUP_GUI_APP_NAME}" ]]
516
- return $?
517
- }
518
-
519
- setup_gui_desktop_app() {
520
- local installer="${INSTALL_DIR}/packages/gui-desktop/scripts/install-macos-app.sh"
521
- local app_dir=""
522
- local os=""
523
- local rc=0
524
-
525
- os="$(uname -s)"
526
- if [[ "$os" != "$SETUP_OS_DARWIN" ]]; then
527
- print_skip "$SETUP_GUI_APP_NAME" "macOS only" "Run this stage from macOS when the desktop app is needed."
528
- setup_track_skipped "$SETUP_GUI_APP_NAME" "macOS only"
529
- return 0
530
- fi
531
-
532
- if [[ ! -f "$installer" ]]; then
533
- print_warning "${SETUP_GUI_APP_NAME} installer not found at: $installer"
534
- setup_track_deferred "$SETUP_GUI_APP_NAME" "Update aidevops, then run: aidevops setup --scope gui-desktop"
535
- return 0
536
- fi
537
-
538
- app_dir="$(_setup_gui_desktop_app_dir)"
539
- bash "$installer" --app-dir "$app_dir" || rc=$?
540
- if [[ "$rc" -eq 0 ]]; then
541
- setup_track_configured "$SETUP_GUI_APP_NAME"
542
- return 0
543
- fi
544
-
545
- print_warning "${SETUP_GUI_APP_NAME} install skipped after installer exit $rc (non-fatal)"
546
- setup_track_deferred "$SETUP_GUI_APP_NAME" "Install requirements, then run: aidevops setup --scope gui-desktop"
547
- return 0
548
- }
549
-
550
- _setup_offer_gui_desktop_app() {
551
- local answer=""
552
- local app_dir=""
553
-
554
- if _setup_gui_desktop_install_opted_in; then
555
- setup_gui_desktop_app
556
- return 0
557
- fi
558
-
559
- app_dir="$(_setup_gui_desktop_app_dir)"
560
- if [[ "$(uname -s)" == "$SETUP_OS_DARWIN" ]] && _setup_gui_desktop_app_exists "$app_dir"; then
561
- print_info "Refreshing existing macOS ${SETUP_GUI_APP_NAME} in ${app_dir}"
562
- setup_gui_desktop_app
563
- return 0
564
- fi
565
-
566
- if [[ "$INTERACTIVE_MODE" == "true" ]]; then
567
- echo ""
568
- echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
569
- echo -e "${BLUE}Optional preview:${NC} Install native macOS ${SETUP_GUI_APP_NAME}"
570
- echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
571
- setup_prompt answer "Install ${SETUP_GUI_APP_NAME} now? [y/N]: " "N"
572
- case "$answer" in
573
- y | Y | yes | YES)
574
- setup_gui_desktop_app
575
- return 0
576
- ;;
577
- esac
578
- fi
579
-
580
- setup_track_skipped "$SETUP_GUI_APP_NAME" "opt-in: run aidevops setup --scope gui-desktop or set AIDEVOPS_GUI_DESKTOP_INSTALL=true"
581
- return 0
582
- }
583
-
584
464
  # Initialize ~/.config/aidevops/settings.json with documented defaults.
585
465
  # Idempotent — merges missing keys without overwriting existing values.
586
466
  init_settings_json() {
@@ -623,121 +503,6 @@ _setup_print_header() {
623
503
  return 0
624
504
  }
625
505
 
626
- # GH#18950 (t2087) + GH#18965 (t2094): ensure modern bash is installed
627
- # and up to date on macOS. Runs after platform detection, before deploy.
628
- # Uses the canonical `ensure` subcommand which combines install + upgrade:
629
- # - Missing → interactive prompt for install (or silent with --yes)
630
- # - Installed but drifted → silent upgrade (brew upgrade bash)
631
- # - Current → no-op
632
- # Rate-limits `brew update` to 24h internally. Always fail-open — never
633
- # blocks setup on a bash upgrade failure.
634
- #
635
- # Opt-out: AIDEVOPS_AUTO_UPGRADE_BASH=0 disables install + upgrade entirely.
636
- _setup_check_bash_upgrade() {
637
- # Only applies to macOS; Linux bash is already modern on any current distro.
638
- if [[ "${AIDEVOPS_PLATFORM:-}" != "macos" ]]; then
639
- return 0
640
- fi
641
-
642
- local helper="${INSTALL_DIR}/.agents/scripts/bash-upgrade-helper.sh"
643
- [[ -x "$helper" ]] || return 0
644
-
645
- if [[ "$NON_INTERACTIVE" == "true" ]]; then
646
- # Non-interactive: ensure does everything silently (install with
647
- # --yes, upgrade on drift, no-op when current). Same pattern as
648
- # `aidevops update` — fire-and-forget.
649
- "$helper" ensure --yes --quiet || print_warning "bash ensure failed (non-fatal) — advisory written"
650
- return 0
651
- fi
652
-
653
- # Interactive: ensure prompts on first install (inherited from
654
- # _bu_cmd_install's read path), runs silently on upgrade. Users don't
655
- # see a prompt on every `./setup.sh` run — only the first one.
656
- "$helper" ensure || print_warning "bash ensure failed (non-fatal) — advisory written"
657
- return 0
658
- }
659
-
660
- # GH#17769: Comment out deprecated model env vars in a single credentials file.
661
- _comment_out_deprecated_model_vars() {
662
- local file="$1"
663
- local deprecated_vars="AIDEVOPS_HEADLESS_MODELS|PULSE_MODEL"
664
- local deprecation_note="# DEPRECATED by aidevops v3.7+ — model routing is now automatic (GH#17769)"
665
- [[ -f "$file" ]] || return 0
666
- # Only process active assignments/exports (not already commented). Some old
667
- # credentials used VAR=... followed by export VAR, so clean both shapes.
668
- if grep -qE "^[[:space:]]*(export[[:space:]]+)?(${deprecated_vars})=" "$file" 2>/dev/null; then
669
- sed -i.bak -E "s/^([[:space:]]*)((export[[:space:]]+)?(${deprecated_vars})=.*)$/\\1${deprecation_note}\\
670
- \\1# \\2/" "$file"
671
- rm -f "${file}.bak"
672
- print_info "Commented out deprecated model env vars in $(basename "$file")"
673
- fi
674
- return 0
675
- }
676
-
677
- # GH#17769: Comment out deprecated model env vars from credentials.sh.
678
- # Runs on every `aidevops update`. Uses sed to comment out (not delete) lines
679
- # so the user's file history is preserved.
680
- _cleanup_legacy_model_config() {
681
- local creds_file="${HOME}/.config/aidevops/credentials.sh"
682
- _comment_out_deprecated_model_vars "$creds_file"
683
-
684
- # Clean up tenant credentials files
685
- local tenant_dir="${HOME}/.config/aidevops/tenants"
686
- if [[ -d "$tenant_dir" ]]; then
687
- local tenant_creds=""
688
- while IFS= read -r -d '' tenant_creds; do
689
- _comment_out_deprecated_model_vars "$tenant_creds"
690
- done < <(find "$tenant_dir" -name "credentials.sh" -print0 2>/dev/null)
691
- fi
692
- return 0
693
- }
694
-
695
- # Deploy auto-hotfix.conf template to user-level configs if not already present.
696
- # The template ships in .agents/configs/; this copies to ~/.aidevops/configs/
697
- # where user edits survive `aidevops update`. Existing user config is preserved.
698
- _deploy_hotfix_config() {
699
- local source_conf="${INSTALL_DIR:-.}/.agents/configs/auto-hotfix.conf"
700
- local target_dir="$HOME/.aidevops/configs"
701
- local target_conf="$target_dir/auto-hotfix.conf"
702
-
703
- if [[ ! -f "$source_conf" ]]; then
704
- return 0
705
- fi
706
-
707
- # Only deploy if the user doesn't have one yet (preserve user edits)
708
- if [[ -f "$target_conf" ]]; then
709
- return 0
710
- fi
711
-
712
- mkdir -p "$target_dir"
713
- cp "$source_conf" "$target_conf"
714
- chmod 600 "$target_conf"
715
- return 0
716
- }
717
-
718
- # t2919: Early pulse plist install. The pulse launchd agent is critical
719
- # infrastructure — without it, every other pulse-driven feature (worker
720
- # dispatch, issue routing, cross-repo coordination) is dead. Previously,
721
- # setup_supervisor_pulse only ran inside _setup_post_setup_steps which
722
- # executes AFTER ~25 other migration/setup steps. When `aidevops update`
723
- # runs unattended and any earlier step times out (e.g. brew taps, MCP
724
- # installs, slow repo scans), the pulse plist never gets installed/refreshed
725
- # and the runner falls behind.
726
- #
727
- # Install immediately after deploy_aidevops_agents (so the scripts the plist
728
- # references already exist on disk). The late install in _setup_post_setup_steps
729
- # remains as the canonical regenerate-on-change path — _launchd_install_if_changed
730
- # compares content and skips reload when identical, so the second call is a
731
- # no-op when nothing changed. Failure here is non-fatal: the late path retries.
732
- _setup_install_pulse_plist_early() {
733
- local _early_os
734
- _early_os="$(uname -s)"
735
- if _should_setup_noninteractive_supervisor_pulse; then
736
- setup_supervisor_pulse "$_early_os" || print_warning "Early pulse plist install failed (will retry late)"
737
- fi
738
- return 0
739
- }
740
-
741
506
  # GH#35788: surface stale/missing JS dependency install approvals for
742
507
  # dispatch-enabled repos so headless workers are not stranded with
743
508
  # runner_capability_unmet. Interactive setup offers renewal per repo;
@@ -1277,802 +1042,6 @@ _setup_init_stage_timing_log() {
1277
1042
  return 0
1278
1043
  }
1279
1044
 
1280
- _setup_ai_session_reset_plan() {
1281
- _SETUP_AI_SESSION_NEEDS_AGENTS=0
1282
- _SETUP_AI_SESSION_NEEDS_CLI=0
1283
- _SETUP_AI_SESSION_NEEDS_HOOKS=0
1284
- _SETUP_AI_SESSION_NEEDS_REPO_VERIFY=0
1285
- _SETUP_AI_SESSION_NEEDS_PULSE=0
1286
- _SETUP_AI_SESSION_NEEDS_SCHEDULERS=0
1287
- _SETUP_AI_SESSION_NEEDS_GUI=0
1288
- _SETUP_AI_SESSION_REQUIRES_FULL=0
1289
- return 0
1290
- }
1291
-
1292
- _setup_ai_session_setup_sh_version_only() {
1293
- local deployed_sha="$1"
1294
- local current_sha="$2"
1295
- local diff_output=""
1296
- local line=""
1297
- local payload=""
1298
- local version_prefix=""
1299
- version_prefix="# ""Version:"
1300
-
1301
- diff_output=$(git -C "$INSTALL_DIR" diff --unified=0 "$deployed_sha" "$current_sha" -- setup.sh 2>/dev/null) || return 1
1302
- while IFS= read -r line; do
1303
- case "$line" in
1304
- "diff --git "* | "index "* | "--- "* | "+++ "* | "@@"*)
1305
- continue
1306
- ;;
1307
- +* | -*)
1308
- payload="${line#?}"
1309
- if [[ "$payload" != "$version_prefix "* ]]; then
1310
- return 1
1311
- fi
1312
- ;;
1313
- esac
1314
- done <<<"$diff_output"
1315
-
1316
- return 0
1317
- }
1318
-
1319
- _setup_ai_session_plan_file() {
1320
- local filepath="$1"
1321
- local deployed_sha="$2"
1322
- local current_sha="$3"
1323
-
1324
- case "$filepath" in
1325
- setup.sh)
1326
- if _setup_ai_session_setup_sh_version_only "$deployed_sha" "$current_sha"; then
1327
- print_info "setup.sh drift is release-version metadata only; incremental setup can continue"
1328
- else
1329
- print_warning "setup.sh changed beyond the release-version header; full setup required"
1330
- _SETUP_AI_SESSION_REQUIRES_FULL=1
1331
- fi
1332
- ;;
1333
- aidevops.sh)
1334
- _SETUP_AI_SESSION_NEEDS_CLI=1
1335
- ;;
1336
- .agents/hooks/*)
1337
- _SETUP_AI_SESSION_NEEDS_HOOKS=1
1338
- [[ "$filepath" == ".agents/hooks/repo-verify-pre-push.sh" ]] && _SETUP_AI_SESSION_NEEDS_REPO_VERIFY=1
1339
- ;;
1340
- .agents/scripts/repo-verify-config-lib.sh | .agents/scripts/lint-helper.sh | \
1341
- .agents/scripts/install-pre-push-guards.sh | .agents/configs/repo-verify-defaults.conf | \
1342
- .agents/scripts/aidevops-cli/aidevops-init-lib.sh | .agents/scripts/aidevops-cli/aidevops-update-lib.sh)
1343
- _SETUP_AI_SESSION_NEEDS_REPO_VERIFY=1
1344
- ;;
1345
- .agents/scripts/setup/modules/schedulers-pulse.sh)
1346
- _SETUP_AI_SESSION_NEEDS_PULSE=1
1347
- ;;
1348
- .agents/scripts/setup/modules/schedulers*.sh | .agents/scripts/setup/_scheduler_runtime.sh | \
1349
- .agents/scripts/runtime-env.sh | .agents/scripts/plist-env-overrides-lib.sh)
1350
- # Shared scheduler modules define non-pulse schedulers too (e.g. the
1351
- # Linux screen-activity sampler); refresh every installed one (GH#36709).
1352
- # runtime-env.sh renders every service PATH (aidevops_service_path), so
1353
- # its changes reach installed units only through this refresh (GH#37888);
1354
- # plist-env-overrides-lib.sh renders the plist env overrides (GH#38661).
1355
- _SETUP_AI_SESSION_NEEDS_SCHEDULERS=1
1356
- ;;
1357
- .agents/scripts/setup/modules/agent-deploy.sh | .agents/scripts/setup/modules/plugins.sh)
1358
- :
1359
- ;;
1360
- .agents/scripts/setup/*)
1361
- print_warning "Setup implementation changed ($filepath); full setup required"
1362
- _SETUP_AI_SESSION_REQUIRES_FULL=1
1363
- ;;
1364
- packages/gui-api/* | packages/gui-desktop/* | packages/gui-shared/* | packages/gui-web/*)
1365
- _SETUP_AI_SESSION_NEEDS_GUI=1
1366
- ;;
1367
- esac
1368
-
1369
- return 0
1370
- }
1371
-
1372
- _setup_ai_session_build_plan() {
1373
- local changed_files="$1"
1374
- local deployed_sha="$2"
1375
- local current_sha="$3"
1376
- local filepath=""
1377
-
1378
- _setup_ai_session_reset_plan
1379
- # Deploying agents is the cheap, atomic baseline: it copies .agents/, writes
1380
- # VERSION, writes .deployed-sha, and restarts pulse asynchronously.
1381
- _SETUP_AI_SESSION_NEEDS_AGENTS=1
1382
- while IFS= read -r filepath; do
1383
- [[ -n "$filepath" ]] || continue
1384
- _setup_ai_session_plan_file "$filepath" "$deployed_sha" "$current_sha"
1385
- done <<<"$changed_files"
1386
-
1387
- return 0
1388
- }
1389
-
1390
- _setup_reconcile_runtime_config() {
1391
- pin_aidevops_active_runtime_bundle_root || {
1392
- print_warning "Runtime configuration reconciliation could not resolve the active agents bundle"
1393
- return 1
1394
- }
1395
- update_runtime_configs || return $?
1396
- deploy_commands_to_all_runtimes || return $?
1397
- return 0
1398
- }
1399
-
1400
- _setup_git_checkout_available() {
1401
- local checkout_root="$1"
1402
- local git_dir=""
1403
- local git_common_dir=""
1404
-
1405
- git_dir=$(git -C "$checkout_root" rev-parse --git-dir 2>/dev/null) || return 1
1406
- git_common_dir=$(git -C "$checkout_root" rev-parse --git-common-dir 2>/dev/null) || return 1
1407
- [[ -n "$git_dir" && -n "$git_common_dir" ]] || return 1
1408
- return 0
1409
- }
1410
-
1411
- # _setup_ai_session_verify_deploy <floor_sha>
1412
- # floor_sha is the checkout commit when this setup began. Canonical main can
1413
- # fast-forward during a multi-minute deploy (t19058: 36 logged convergence
1414
- # failures, each rolling back a consistent bundle and repeating the deploy as a
1415
- # full setup). Accept the activated bundle's commit when it lies between the
1416
- # floor and the current HEAD; the verifier still pins manifest, stamp, VERSION
1417
- # and sentinels to that commit. The next update cycle deploys the newer HEAD.
1418
- _setup_ai_session_verify_deploy() {
1419
- local floor_sha="$1"
1420
- local expected_sha="$floor_sha"
1421
- local stamp_sha=""
1422
- local _AIDEVOPS_RUNTIME_VERIFY_ALLOW_SOURCE_ADVANCE=1
1423
-
1424
- stamp_sha=$(tr -d '[:space:]' <"$HOME/.aidevops/.deployed-sha" 2>/dev/null) || stamp_sha=""
1425
- if [[ -n "$stamp_sha" && "$stamp_sha" != "$floor_sha" ]] &&
1426
- git -C "$INSTALL_DIR" merge-base --is-ancestor "$floor_sha" "$stamp_sha" 2>/dev/null; then
1427
- expected_sha="$stamp_sha"
1428
- fi
1429
- verify_aidevops_runtime_bundle_convergence \
1430
- "$INSTALL_DIR" \
1431
- "$expected_sha" \
1432
- "$HOME/.aidevops/agents" \
1433
- "$HOME/.aidevops/.deployed-sha" || {
1434
- _runtime_bundle_rollback "$HOME/.aidevops/agents" ||
1435
- print_error "Failed to roll back the runtime bundle after convergence failure"
1436
- return 1
1437
- }
1438
- if [[ -n "${_AIDEVOPS_RUNTIME_VERIFY_SOURCE_ADVANCED_TO:-}" ]]; then
1439
- print_info "Checkout advanced to ${_AIDEVOPS_RUNTIME_VERIFY_SOURCE_ADVANCED_TO:0:12} during deploy; runtime ${expected_sha:0:12} is consistent and the next update deploys the newer commit"
1440
- fi
1441
- return 0
1442
- }
1443
-
1444
- # OpenCode DB archive (daily) and maintenance (weekly) schedulers keep the
1445
- # session DB small enough to avoid "database is locked" stalls (GH#35492).
1446
- # Both installers are idempotent content-diffs, so every auto-update ensures
1447
- # they exist even when the incremental plan would not otherwise touch them.
1448
- _setup_ensure_opencode_db_schedulers() {
1449
- _time_step "setup_opencode_db_maintenance" setup_opencode_db_maintenance ||
1450
- print_warning "OpenCode DB maintenance scheduler refresh failed (non-fatal)"
1451
- _time_step "setup_opencode_db_archive" setup_opencode_db_archive ||
1452
- print_warning "OpenCode DB archive scheduler refresh failed (non-fatal)"
1453
- return 0
1454
- }
1455
-
1456
- _setup_run_ai_session_incremental() {
1457
- local os="$1"
1458
- local stamp_file="$HOME/.aidevops/.deployed-sha"
1459
- local deployed_sha=""
1460
- local current_sha=""
1461
- local changed_files=""
1462
-
1463
- # Updates must heal scheduler drift even when no deploy stage changed.
1464
- if [[ "$os" != "Darwin" ]]; then
1465
- _reconcile_linux_scheduler_duplicates
1466
- fi
1467
- print_info "AI-session setup mode: applying changed deploy stages only"
1468
- if ! _setup_git_checkout_available "$INSTALL_DIR" || [[ ! -f "$stamp_file" ]]; then
1469
- print_warning "AI-session incremental setup needs a git checkout and deployed SHA stamp"
1470
- return 1
1471
- fi
1472
-
1473
- deployed_sha=$(tr -d '[:space:]' <"$stamp_file" 2>/dev/null) || deployed_sha=""
1474
- current_sha=$(git -C "$INSTALL_DIR" rev-parse HEAD 2>/dev/null) || current_sha=""
1475
- if [[ -z "$deployed_sha" || -z "$current_sha" ]]; then
1476
- print_warning "AI-session incremental setup could not resolve deployed/current SHAs"
1477
- return 1
1478
- fi
1479
-
1480
- if [[ "$deployed_sha" == "$current_sha" ]]; then
1481
- print_success "AI-session setup: deployed SHA already matches current checkout"
1482
- _setup_ensure_opencode_db_schedulers
1483
- _time_step "$SETUP_STAGE_TABBY" setup_tabby
1484
- _setup_ai_session_verify_deploy "$current_sha" || return $?
1485
- return 0
1486
- fi
1487
-
1488
- changed_files=$(git -C "$INSTALL_DIR" diff --name-only "$deployed_sha" "$current_sha" 2>/dev/null) || {
1489
- print_warning "AI-session incremental setup could not diff ${deployed_sha:0:7}..${current_sha:0:7}"
1490
- return 1
1491
- }
1492
-
1493
- _setup_ai_session_build_plan "$changed_files" "$deployed_sha" "$current_sha"
1494
- if [[ "$_SETUP_AI_SESSION_REQUIRES_FULL" -eq 1 ]]; then
1495
- return 1
1496
- fi
1497
-
1498
- _setup_init_stage_timing_log
1499
- if [[ "$_SETUP_AI_SESSION_NEEDS_AGENTS" -eq 1 ]]; then
1500
- _time_step "$SETUP_STAGE_AGENTS" deploy_aidevops_agents || return $?
1501
- _time_step "$SETUP_STAGE_OPENCODE_PLUGINS" setup_opencode_runtime_plugins || return $?
1502
- _time_step "$SETUP_STAGE_OPENCODE_SERVICE" setup_opencode_service
1503
- _time_step "$SETUP_STAGE_HOTFIX_CONFIG" _deploy_hotfix_config || return $?
1504
- _time_step "$SETUP_STAGE_RUNTIME_CONFIG" _setup_reconcile_runtime_config || return $?
1505
- fi
1506
- if [[ "$_SETUP_AI_SESSION_NEEDS_CLI" -eq 1 ]]; then
1507
- _time_step "install_aidevops_cli" install_aidevops_cli || return $?
1508
- fi
1509
- if [[ "$_SETUP_AI_SESSION_NEEDS_HOOKS" -eq 1 ]]; then
1510
- _time_step "$SETUP_STAGE_HOOKS" setup_safety_hooks || return $?
1511
- fi
1512
- if [[ "$_SETUP_AI_SESSION_NEEDS_REPO_VERIFY" -eq 1 ]]; then
1513
- _time_step "setup_repo_verify_guard" setup_repo_verify_guard || return $?
1514
- fi
1515
- if [[ "$_SETUP_AI_SESSION_NEEDS_SCHEDULERS" -eq 1 ]]; then
1516
- # Includes the consent-gated pulse refresh; each step is time-stepped.
1517
- _setup_noninteractive_schedulers "$os"
1518
- elif [[ "$_SETUP_AI_SESSION_NEEDS_PULSE" -eq 1 ]]; then
1519
- _time_step "$SETUP_STAGE_PULSE" setup_supervisor_pulse "$os" || return $?
1520
- fi
1521
- if [[ "$_SETUP_AI_SESSION_NEEDS_GUI" -eq 1 ]]; then
1522
- _time_step "setup_gui_desktop_app_opt_in" _setup_offer_gui_desktop_app || return $?
1523
- fi
1524
- # After agent deploy so the schedulers point at the freshly deployed helpers.
1525
- _setup_ensure_opencode_db_schedulers
1526
-
1527
- _time_step "$SETUP_STAGE_TABBY" setup_tabby
1528
- _setup_ai_session_verify_deploy "$current_sha" || return $?
1529
- print_success "AI-session incremental setup complete (${deployed_sha:0:7}→${current_sha:0:7})"
1530
- return 0
1531
- }
1532
-
1533
- _setup_run_scoped_stage() {
1534
- local os="$1"
1535
- local stage
1536
- local current_sha=""
1537
- stage="$(_setup_canonical_stage "$SETUP_STAGE")" || return 1
1538
-
1539
- if [[ "$stage" == "full" ]]; then
1540
- _setup_run_non_interactive
1541
- _setup_post_setup_steps "$os"
1542
- return 0
1543
- fi
1544
-
1545
- print_info "Scoped setup mode: running ${stage} only"
1546
- _setup_init_stage_timing_log
1547
- case "$stage" in
1548
- "$SETUP_STAGE_OPENCODE")
1549
- _time_step "$SETUP_STAGE_OPENCODE" setup_opencode_runtimes
1550
- _time_step "$SETUP_STAGE_OPENCODE_SERVICE" setup_opencode_service
1551
- _time_step "setup_opencode_desktop_launcher" setup_opencode_desktop_launcher
1552
- ;;
1553
- "$SETUP_STAGE_AGENTS")
1554
- _time_step "$SETUP_STAGE_AGENTS" deploy_aidevops_agents
1555
- _time_step "$SETUP_STAGE_OPENCODE_PLUGINS" setup_opencode_runtime_plugins
1556
- _time_step "$SETUP_STAGE_OPENCODE_SERVICE" setup_opencode_service
1557
- _time_step "$SETUP_STAGE_HOTFIX_CONFIG" _deploy_hotfix_config
1558
- ;;
1559
- "$SETUP_STAGE_RUNTIME_CONFIG")
1560
- _time_step "$SETUP_STAGE_RUNTIME_CONFIG" _setup_reconcile_runtime_config
1561
- ;;
1562
- "$SETUP_STAGE_SOURCE_ACCESS")
1563
- if [[ "$SETUP_EXPLICIT_NON_INTERACTIVE" == "true" ]]; then
1564
- _time_step "$SETUP_STAGE_SOURCE_ACCESS" setup_source_access_broker
1565
- else
1566
- AIDEVOPS_SOURCE_ACCESS_INTERACTIVE=true \
1567
- _time_step "$SETUP_STAGE_SOURCE_ACCESS" setup_source_access_broker
1568
- fi
1569
- ;;
1570
- "$SETUP_STAGE_HOOKS")
1571
- _time_step "$SETUP_STAGE_HOOKS" setup_safety_hooks
1572
- ;;
1573
- "$SETUP_STAGE_TABBY")
1574
- _time_step "$SETUP_STAGE_TABBY" setup_tabby
1575
- ;;
1576
- "$SETUP_STAGE_PULSE")
1577
- _time_step "$SETUP_STAGE_PULSE" setup_supervisor_pulse "$os"
1578
- _time_step "setup_pulse_merge_routine" setup_pulse_merge_routine
1579
- ;;
1580
- "$SETUP_STAGE_GUI_DESKTOP")
1581
- _time_step "$SETUP_STAGE_GUI_DESKTOP" setup_gui_desktop_app
1582
- ;;
1583
- "$SETUP_STAGE_AI_SESSION")
1584
- if ! _setup_run_ai_session_incremental "$os"; then
1585
- print_warning "AI-session incremental setup unavailable or failed; falling back to full setup"
1586
- # Floor for verification: the deploy below reads HEAD at its own
1587
- # start, which may be later than this point but never earlier.
1588
- current_sha=$(git -C "$INSTALL_DIR" rev-parse HEAD 2>/dev/null) || current_sha=""
1589
- [[ -n "$current_sha" ]] || return 1
1590
- _setup_run_non_interactive || return $?
1591
- _setup_post_setup_steps "$os" || return $?
1592
- _setup_ai_session_verify_deploy "$current_sha" || return $?
1593
- fi
1594
- ;;
1595
- *)
1596
- print_error "Unsupported canonical setup stage: $stage"
1597
- return 1
1598
- ;;
1599
- esac
1600
- return 0
1601
- }
1602
-
1603
- reconcile_buzz_desktop_compatibility() {
1604
- local helper="${INSTALL_DIR}/agents/scripts/buzz-desktop-helper.sh"
1605
- [[ -x "$helper" ]] || return 0
1606
- local rc=0
1607
- bash "$helper" reconcile --quiet || rc=$?
1608
- case "$rc" in
1609
- 0) return 0 ;;
1610
- 2)
1611
- print_warning "Buzz Desktop compatibility reconciliation deferred until Buzz is closed; run: aidevops buzz apply"
1612
- return 0
1613
- ;;
1614
- *)
1615
- print_warning "Buzz Desktop compatibility reconciliation failed; inspect with: aidevops buzz status"
1616
- return 0
1617
- ;;
1618
- esac
1619
- }
1620
-
1621
- # GH#33249: best-effort one-shot cleanup; a refusal must not abort deployment.
1622
- _setup_cleanup_retired_prompt_tooling_nonfatal() {
1623
- cleanup_retired_prompt_tooling || print_warning "Retired prompt tooling cleanup incomplete; setup will retry next time"
1624
- return 0
1625
- }
1626
-
1627
- _setup_run_noninteractive_migrations() {
1628
- _time_step "migrate_old_backups" migrate_old_backups
1629
- _time_step "migrate_loop_state_directories" migrate_loop_state_directories
1630
- _time_step "migrate_agent_to_agents_folder" migrate_agent_to_agents_folder
1631
- _time_step "migrate_mcp_env_to_credentials" migrate_mcp_env_to_credentials
1632
- _time_step "migrate_pulse_repos_to_repos_json" migrate_pulse_repos_to_repos_json
1633
- _time_step "cleanup_deprecated_paths" cleanup_deprecated_paths
1634
- _time_step "cleanup_retired_prompt_tooling" _setup_cleanup_retired_prompt_tooling_nonfatal
1635
- _time_step "migrate_orphaned_supervisor" migrate_orphaned_supervisor
1636
- _time_step "migrate_custom_model_routing_reasoning_defaults" migrate_custom_model_routing_reasoning_defaults
1637
- _time_step "migrate_obsolete_settings_model_routing" migrate_obsolete_settings_model_routing
1638
- _time_step "migrate_worker_capacity_reset" migrate_worker_capacity_reset
1639
- _time_step "migrate_compaction_target_240k" migrate_compaction_target_240k
1640
- _time_step "migrate_sonnet_5_5_settings" migrate_sonnet_5_5_settings
1641
- _time_step "migrate_haiku_5_5_settings" migrate_haiku_5_5_settings
1642
- _time_step "backfill_issue_relationships" backfill_issue_relationships
1643
- _time_step "cleanup_deprecated_mcps" cleanup_deprecated_mcps
1644
- _time_step "cleanup_stale_bun_opencode" cleanup_stale_bun_opencode
1645
- _time_step "cleanup_stale_health_issue_caches" cleanup_stale_health_issue_caches
1646
- _time_step "cleanup_legacy_aidevops_temp_artifacts" cleanup_legacy_aidevops_temp_artifacts
1647
- _time_step "cleanup_worktree_entries_in_repos_json" cleanup_worktree_entries_in_repos_json
1648
- _time_step "migrate_routines_repo_purpose_marker" migrate_routines_repo_purpose_marker
1649
- _time_step "_cleanup_legacy_model_config" _cleanup_legacy_model_config
1650
- _time_step "cleanup_legacy_dashboard_launchagent" cleanup_legacy_dashboard_launchagent
1651
- _time_step "cleanup_legacy_agents_md_templates" cleanup_legacy_agents_md_templates
1652
- _time_step "review_js_dependency_policies" review_js_dependency_policies
1653
- return 0
1654
- }
1655
-
1656
- # Optional user tools refreshed on every non-interactive setup/update. Each
1657
- # stage is bounded and non-critical.
1658
- _setup_run_noninteractive_optional_tools() {
1659
- # Update-if-installed only; never installs Nostr VPN (GH#23846).
1660
- _time_step "setup_nostr_vpn" _setup_run_noncritical_stage_bounded "Nostr VPN update check" "${AIDEVOPS_SETUP_NOSTR_VPN_TIMEOUT:-120}" setup_nostr_vpn
1661
- # Install-if-missing for supported browsers; browse self-updates (GH#37155).
1662
- _time_step "setup_opencode_browse" _setup_run_noncritical_stage_bounded "OpenCode browse setup" "${AIDEVOPS_SETUP_OPENCODE_BROWSE_TIMEOUT:-120}" setup_opencode_browse
1663
- return 0
1664
- }
1665
-
1666
- _setup_run_non_interactive() {
1667
- print_info "Non-interactive mode: deploying agents and running safe migrations only"
1668
-
1669
- _setup_init_stage_timing_log
1670
-
1671
- _time_step "protect_current_setup_worktree" protect_current_setup_worktree
1672
- _time_step "verify_location" verify_location
1673
- _time_step "check_requirements" check_requirements
1674
- _time_step "check_quality_tools" check_quality_tools
1675
- _time_step "setup_setsid_advisory" setup_setsid_advisory
1676
- _time_step "check_python_upgrade_available" check_python_upgrade_available
1677
- _time_step "setup_vault_python_env" setup_vault_python_env || print_warning "Vault crypto runtime setup encountered issues; Vault status remains metadata-only"
1678
- _time_step "set_permissions" set_permissions
1679
- _setup_run_noninteractive_migrations
1680
- _time_step "$SETUP_STAGE_OPENCODE" setup_opencode_runtimes
1681
- _time_step "validate_opencode_config" validate_opencode_config
1682
- _time_step "$SETUP_STAGE_AGENTS" deploy_aidevops_agents
1683
- _time_step "$SETUP_STAGE_OPENCODE_PLUGINS" setup_opencode_runtime_plugins
1684
- _time_step "$SETUP_STAGE_OPENCODE_SERVICE" setup_opencode_service
1685
- _time_step "reconcile_buzz_desktop_compatibility" reconcile_buzz_desktop_compatibility
1686
- _time_step "_setup_install_pulse_plist_early" _setup_install_pulse_plist_early
1687
- _time_step "$SETUP_STAGE_HOTFIX_CONFIG" _deploy_hotfix_config
1688
- _time_step "setup_opencode_desktop_launcher" setup_opencode_desktop_launcher
1689
- _time_step "sync_agent_sources" sync_agent_sources
1690
- _time_step "install_aidevops_cli" install_aidevops_cli || print_warning "aidevops CLI installation encountered issues; continuing configuration reconciliation"
1691
- _time_step "setup_source_access_broker" setup_source_access_broker_nonfatal
1692
- _time_step "setup_shellcheck_wrapper" setup_shellcheck_wrapper
1693
- if is_feature_enabled safety_hooks 2>/dev/null; then
1694
- _time_step "$SETUP_STAGE_HOOKS" setup_safety_hooks
1695
- fi
1696
- _time_step "init_settings_json" init_settings_json
1697
-
1698
- local _pid_symlinks=""
1699
- if _time_step "generate_agent_skills" generate_agent_skills; then
1700
- _time_step "create_skill_symlinks" create_skill_symlinks &
1701
- _pid_symlinks=$!
1702
- _setup_register_child_pid "$_pid_symlinks"
1703
- else
1704
- print_warning "Agent skills generation failed — skipping skill symlinks"
1705
- fi
1706
-
1707
- _time_step "scan_imported_skills" scan_imported_skills &
1708
- local _pid_scan=$!
1709
- _setup_register_child_pid "$_pid_scan"
1710
-
1711
- if [[ -n "$_pid_symlinks" ]]; then
1712
- wait "$_pid_symlinks" 2>/dev/null || print_warning "Skill symlink creation encountered issues (non-critical)"
1713
- fi
1714
- wait "$_pid_scan" 2>/dev/null || print_warning "Skill security scan encountered issues (non-critical)"
1715
-
1716
- _time_step "inject_agents_reference" inject_agents_reference
1717
- # Use the bounded wrapper so a slow file-system traversal across many agent
1718
- # files does not consume the remaining postflight budget and trip the outer
1719
- # timeout (GH#22087). AIDEVOPS_DEPLOY_RUNTIMES_TIMEOUT controls the deadline.
1720
- _time_step "deploy_agents_to_runtimes" _deploy_agents_to_runtimes_bounded || true
1721
- _time_step "update_opencode_config" _setup_run_noncritical_stage_bounded "OpenCode config update" "${AIDEVOPS_UPDATE_OPENCODE_CONFIG_TIMEOUT:-60}" update_opencode_config
1722
- _time_step "update_claude_config" update_claude_config
1723
- _time_step "update_codex_config" update_codex_config_noncritical
1724
- _time_step "update_cursor_config" update_cursor_config
1725
- _time_step "disable_ondemand_mcps" disable_ondemand_mcps
1726
- _setup_run_noninteractive_optional_tools
1727
- # Scaffold personal routines repo if not already present (idempotent).
1728
- # Creates local git repo + private GitHub remote for personal repo only.
1729
- # Org repos require explicit: aidevops init-routines --org <name>
1730
- _time_step "setup_routines" _setup_run_noncritical_stage_bounded "Routine setup" "${AIDEVOPS_SETUP_ROUTINES_TIMEOUT:-120}" setup_routines
1731
- # Install/refresh the privacy-guard pre-push hook in every initialized
1732
- # repo so TODO/todo/README/ISSUE_TEMPLATE pushes to public GitHub repos
1733
- # are scanned for private slug leaks (t1968).
1734
- _time_step "setup_privacy_guard" setup_privacy_guard
1735
- # Install/refresh the complexity-regression pre-push hook in every
1736
- # initialized repo so pushes that introduce new function-complexity,
1737
- # nesting-depth, or file-size violations are caught before CI (t2198).
1738
- _time_step "setup_complexity_guard" setup_complexity_guard
1739
- # Migrate exact repository-native lint policy and install/refresh repo-verify
1740
- # for eligible registered repositories. Explicit opt-outs are preserved.
1741
- _time_step "setup_repo_verify_guard" setup_repo_verify_guard
1742
- # Install/refresh the canonical-on-main post-checkout hook in every
1743
- # initialized repo so branch switches away from main in the canonical
1744
- # directory are warned against (t1995). Complements pre-edit-check.sh's
1745
- # t1990 edit-time check by catching the branch switch itself.
1746
- _time_step "setup_canonical_guard" setup_canonical_guard
1747
- # Install/refresh the task-id collision guard commit-msg hook in every
1748
- # initialized repo so invented t-IDs in commit subjects are rejected
1749
- # at commit time (t2047). Belt-and-braces with the CI check in
1750
- # .github/workflows/task-id-collision-check.yml.
1751
- _time_step "setup_task_id_guard" setup_task_id_guard
1752
- # Configure the centralized flat linked-worktree directory used by helpers.
1753
- _time_step "setup_worktree_location" setup_worktree_location
1754
- # Apply Spotlight + Time Machine exclusions to every worktree across
1755
- # registered repos so the backup/index cascade triggered by node_modules
1756
- # copies doesn't burn CPU (t2885). Idempotent. macOS only — Linux
1757
- # indexers tracked separately.
1758
- _time_step "setup_worktree_exclusions" setup_worktree_exclusions
1759
- # Provision knowledge planes for repos where knowledge != "off" (idempotent).
1760
- _time_step "setup_knowledge_planes" setup_knowledge_planes
1761
- # Provision cases planes for repos where cases != "off" (idempotent).
1762
- _time_step "setup_cases_planes" setup_cases_planes
1763
- _time_step "setup_gui_desktop_app_opt_in" _setup_offer_gui_desktop_app
1764
- return 0
1765
- }
1766
-
1767
- # Interactive runtime/tool setup prompts. Extracted so the parent interactive
1768
- # setup function stays below the function-complexity gate while preserving the
1769
- # prompt order around runtime-specific installers and config updates.
1770
- _setup_run_interactive_runtime_tools() {
1771
- confirm_step "Deploy aidevops agents to runtime agent directories" && deploy_agents_to_runtimes
1772
- confirm_step "Setup isolated Vault crypto runtime" && setup_vault_python_env
1773
- confirm_step "Install MCP packages globally (fast startup)" && install_mcp_packages
1774
- confirm_step "Setup LocalWP MCP server" && setup_localwp_mcp
1775
- confirm_step "Setup SEO integrations (curl subagents)" && setup_seo_mcps
1776
- confirm_step "Setup Google Analytics MCP" && setup_google_analytics_mcp
1777
- confirm_step "Setup QuickFile MCP (UK accounting)" && setup_quickfile_mcp
1778
- confirm_step "Setup browser automation tools" && setup_browser_tools
1779
- confirm_step "Setup AI orchestration frameworks info" && setup_ai_orchestration
1780
- confirm_step "Setup Ollama (local LLM for knowledge plane pii/sensitive/privileged tiers)" && setup_ollama_for_knowledge
1781
- confirm_step "Setup Google Workspace CLI (Gmail, Calendar, Drive)" && setup_google_workspace_cli
1782
- confirm_step "Setup Cloudflare cf CLI (full Cloudflare API)" && setup_cloudflare_cf_cli
1783
- confirm_step "Setup OpenCode V1 and isolated V2 preview CLIs" && setup_opencode_runtimes
1784
- confirm_step "Install OpenCode AIDevOps Desktop app wrapper" && setup_opencode_desktop_launcher
1785
- confirm_step "Setup OpenCode plugins" && setup_opencode_runtime_plugins
1786
- confirm_step "Setup persistent OpenCode owner (preserve existing histories)" && setup_opencode_service
1787
- confirm_step "Setup Codex CLI (OpenAI AI coding tool)" && setup_codex_cli
1788
- confirm_step "Setup Droid CLI (Factory.AI coding tool)" && setup_droid_cli
1789
- confirm_step "Update Nostr VPN nvpn CLI (only if Nostr VPN is installed)" && setup_nostr_vpn
1790
- return 0
1791
- }
1792
-
1793
- # Silent one-shot migrations for the interactive path (idempotent, flag-guarded
1794
- # — no prompt needed). The non-interactive path times the same steps in
1795
- # _setup_run_noninteractive_migrations.
1796
- _setup_run_interactive_silent_migrations() {
1797
- _setup_cleanup_retired_prompt_tooling_nonfatal
1798
- cleanup_stale_health_issue_caches
1799
- cleanup_legacy_aidevops_temp_artifacts
1800
- cleanup_worktree_entries_in_repos_json
1801
- migrate_routines_repo_purpose_marker
1802
- _cleanup_legacy_model_config
1803
- cleanup_legacy_dashboard_launchagent
1804
- cleanup_legacy_agents_md_templates
1805
- # Prompts (default No) only when a dispatch repo's JS install approval is stale.
1806
- review_js_dependency_policies
1807
- return 0
1808
- }
1809
-
1810
- # Interactive path: all optional steps gated behind confirm_step prompts.
1811
- _setup_run_interactive() {
1812
- # Required steps (always run)
1813
- verify_location
1814
- check_requirements
1815
-
1816
- # Quality tools check (optional but recommended)
1817
- confirm_step "Check quality tools (shellcheck, shfmt)" && check_quality_tools
1818
-
1819
- # Core runtime setup (early - many later steps depend on these)
1820
- confirm_step "Setup Node.js runtime (required for OpenCode and tools)" && setup_nodejs
1821
-
1822
- # Shell environment setup (early, so later tools benefit from zsh/Oh My Zsh)
1823
- confirm_step "Setup Oh My Zsh (optional, enhances zsh)" && setup_oh_my_zsh
1824
- confirm_step "Setup cross-shell compatibility (preserve bash config in zsh)" && setup_shell_compatibility
1825
-
1826
- # OrbStack (macOS only - offer VM option early)
1827
- confirm_step "Setup OrbStack (lightweight Linux VMs on macOS)" && setup_orbstack_vm
1828
-
1829
- # Optional steps with confirmation in interactive mode
1830
- confirm_step "Check optional dependencies (bun, node, python)" && check_optional_deps
1831
- confirm_step "Check Python version (recommend upgrade if outdated)" && check_python_upgrade_available
1832
- confirm_step "Setup recommended tools (Tabby, Zed, etc.)" && setup_recommended_tools
1833
- confirm_step "Setup PIM tools (Reminders, Calendar, Contacts)" && setup_pim_tools
1834
- confirm_step "Setup mobile tools (optional adb, Xcode guidance, MiniSim, serve-sim, Mobile MCP)" && setup_mobile_simulator_tools
1835
- confirm_step "Setup ClaudeBar (AI quota monitor in menu bar)" && setup_claudebar
1836
- confirm_step "Setup Git CLIs (gh, glab, tea)" && setup_git_clis
1837
- confirm_step "Setup file discovery tools (fd, ripgrep, ripgrep-all)" && setup_file_discovery_tools
1838
- confirm_step "Setup rtk (token-optimized CLI output, 60-90% savings)" && setup_rtk
1839
- confirm_step "Setup shell linting tools (shellcheck, shfmt)" && {
1840
- setup_shell_linting_tools
1841
- setup_shellcheck_wrapper
1842
- }
1843
- confirm_step "Setup Qlty CLI (multi-linter code quality)" && setup_qlty_cli
1844
- confirm_step "Rosetta audit (Apple Silicon x86 migration)" && setup_rosetta_audit
1845
- confirm_step "Setup Worktrunk (git worktree management)" && setup_worktrunk
1846
- confirm_step "Setup SSH key" && setup_ssh_key
1847
- confirm_step "Setup configuration files" && setup_configs
1848
- confirm_step "Set secure permissions on config files" && set_permissions
1849
- confirm_step "Setup shell aliases" && setup_aliases
1850
- confirm_step "Setup terminal title integration" && setup_terminal_title
1851
- confirm_step "Deploy agent workspace template" && deploy_ai_templates
1852
- confirm_step "Migrate old backups to new structure" && migrate_old_backups
1853
- confirm_step "Migrate loop state from .claude/.agent/ to .agents/loop-state/" && migrate_loop_state_directories
1854
- confirm_step "Migrate .agent -> .agents in user projects" && migrate_agent_to_agents_folder
1855
- confirm_step "Migrate mcp-env.sh -> credentials.sh" && migrate_mcp_env_to_credentials
1856
- confirm_step "Migrate pulse-repos.json into repos.json" && migrate_pulse_repos_to_repos_json
1857
- confirm_step "Cleanup deprecated agent paths" && cleanup_deprecated_paths
1858
- confirm_step "Migrate orphaned supervisor to pulse-wrapper" && migrate_orphaned_supervisor
1859
- migrate_custom_model_routing_reasoning_defaults
1860
- migrate_obsolete_settings_model_routing
1861
- migrate_worker_capacity_reset
1862
- migrate_compaction_target_240k
1863
- migrate_sonnet_5_5_settings
1864
- migrate_haiku_5_5_settings
1865
- confirm_step "Backfill GitHub issue relationships (blocked-by, sub-issues)" && backfill_issue_relationships
1866
- confirm_step "Cleanup deprecated MCP entries (hetzner, serper, etc.)" && cleanup_deprecated_mcps
1867
- confirm_step "Cleanup stale bun opencode install" && cleanup_stale_bun_opencode
1868
- _setup_run_interactive_silent_migrations
1869
- confirm_step "Validate and repair OpenCode config schema" && validate_opencode_config
1870
- confirm_step "Extract OpenCode prompts" && extract_opencode_prompts
1871
- confirm_step "Check OpenCode prompt drift" && check_opencode_prompt_drift
1872
- confirm_step "Deploy aidevops agents to ~/.aidevops/agents/" && {
1873
- deploy_aidevops_agents
1874
- _deploy_hotfix_config
1875
- }
1876
- reconcile_buzz_desktop_compatibility
1877
- # Launcher verification reads the deployed VERSION, so it must follow agent
1878
- # deployment on first-run interactive setup as it already does non-interactively.
1879
- confirm_step "Install and verify aidevops CLI command" && install_aidevops_cli
1880
- if confirm_step "Install the secure source-access approval broker"; then
1881
- AIDEVOPS_SOURCE_ACCESS_INTERACTIVE=true setup_source_access_broker_nonfatal
1882
- fi
1883
- confirm_step "Sync agents from private repositories" && sync_agent_sources
1884
- confirm_step "Set up routines repo (private repo for recurring operational jobs)" && setup_routines
1885
- is_feature_enabled safety_hooks 2>/dev/null && confirm_step "Install Claude Code safety hooks (block destructive commands)" && setup_safety_hooks
1886
- confirm_step "Initialize settings.json (canonical config file)" && init_settings_json
1887
- confirm_step "Setup multi-tenant credential storage" && setup_multi_tenant_credentials
1888
- confirm_step "Generate agent skills (SKILL.md files)" && generate_agent_skills
1889
- confirm_step "Create symlinks for imported skills" && create_skill_symlinks
1890
- confirm_step "Check for skill updates from upstream" && check_skill_updates
1891
- confirm_step "Security scan imported skills" && scan_imported_skills
1892
- confirm_step "Inject agents reference into AI configs" && inject_agents_reference
1893
- _setup_run_interactive_runtime_tools
1894
- _setup_offer_gui_desktop_app
1895
- # Run AFTER CLI installs so config dirs may exist for agent config
1896
- confirm_step "Update OpenCode configuration" && update_opencode_config
1897
- # Run AFTER OpenCode config so Claude Code gets equivalent setup
1898
- confirm_step "Update Claude Code configuration (slash commands, MCPs, settings)" && update_claude_config
1899
- # Run AFTER Claude Code config so Codex/Cursor get equivalent setup
1900
- confirm_step "Update Codex configuration (MCPs, instructions)" && update_codex_config_noncritical
1901
- confirm_step "Update Cursor configuration (MCPs)" && update_cursor_config
1902
- # Deploy slash commands to the other installed runtimes (Codex, Cursor,
1903
- # Droid, Gemini CLI, Continue, Kiro, Kimi, Qwen) via the unified generator.
1904
- # OpenCode and Claude Code are already handled by their update_*_config
1905
- # functions above. Closes GH#18106 / t15474.
1906
- confirm_step "Deploy slash commands to remaining runtimes" && deploy_commands_to_all_runtimes
1907
- # Run AFTER all MCP setup functions to ensure disabled state persists
1908
- confirm_step "Disable on-demand MCPs globally" && disable_ondemand_mcps
1909
- return 0
1910
- }
1911
-
1912
- # Post-setup steps: schedulers, final instructions, optional tool update check.
1913
- # Non-interactive scheduler installation. Extracted from
1914
- # `_setup_post_setup_steps` (t2903) to keep the parent under the
1915
- # function-complexity gate threshold. Each `_should_setup_noninteractive_*`
1916
- # guard returns 0 when the corresponding scheduler is already installed
1917
- # (regenerate on update) or first-time install is consented via config.
1918
- _setup_noninteractive_schedulers() {
1919
- local os="$1"
1920
-
1921
- # GH#22012: Wrap every scheduler step with _time_step so the stage-timing
1922
- # log ($HOME/.aidevops/logs/setup-stage-timings.log) covers post-deploy
1923
- # scheduler setup — the same visibility _setup_run_non_interactive has.
1924
-
1925
- # Auto-update handles non-interactive internally (systemd detection fixed in GH#17861)
1926
- _time_step "setup_auto_update" setup_auto_update
1927
- if _should_setup_noninteractive_supervisor_pulse; then
1928
- _time_step "$SETUP_STAGE_PULSE" setup_supervisor_pulse "$os"
1929
- fi
1930
- # t2939: pulse-watchdog (independent revival mechanism). Always installed
1931
- # alongside the pulse — it is a no-op when pulse is disabled. Skipping the
1932
- # `_should_setup_noninteractive_*` guard intentionally: this is layered
1933
- # defense, the cost of installing it is one plist file, and the user opts
1934
- # in by enabling the pulse itself.
1935
- _time_step "setup_pulse_watchdog" setup_pulse_watchdog "${PULSE_ENABLED:-}"
1936
- # Regenerate other schedulers if already installed (GH#17695 Finding B).
1937
- # Stats wrapper is a pulse dependency — also install on first run when
1938
- # the supervisor pulse is consented (t2418, GH#20016).
1939
- if _should_setup_noninteractive_stats_wrapper; then
1940
- _time_step "setup_stats_wrapper" setup_stats_wrapper "${PULSE_ENABLED:-}"
1941
- fi
1942
- if _should_setup_noninteractive_failure_miner; then
1943
- _time_step "setup_failure_miner" setup_failure_miner "${PULSE_ENABLED:-}"
1944
- fi
1945
- if _should_setup_noninteractive_scheduler "Process guard" "sh.aidevops.process-guard" "aidevops: process-guard" "aidevops-process-guard"; then
1946
- _time_step "setup_process_guard" setup_process_guard
1947
- fi
1948
- if _should_setup_noninteractive_scheduler "Memory pressure" "sh.aidevops.memory-pressure-monitor" "aidevops: memory-pressure-monitor" "aidevops-memory-pressure-monitor"; then
1949
- _time_step "setup_memory_pressure_monitor" setup_memory_pressure_monitor
1950
- fi
1951
- # GH#36709: Linux profile README installs also need the activity sampler.
1952
- if _should_setup_noninteractive_screen_time; then
1953
- _time_step "setup_screen_time_snapshot" setup_screen_time_snapshot
1954
- fi
1955
- if _should_setup_noninteractive_scheduler "Contribution watch" "sh.aidevops.contribution-watch" "aidevops: contribution-watch" "aidevops-contribution-watch"; then
1956
- _time_step "setup_contribution_watch" setup_contribution_watch
1957
- fi
1958
- # t2903 (#21049): complexity scan — extracted from pulse dispatch preflight.
1959
- # GH#24841: use a pulse-dependency escape hatch so non-interactive updates
1960
- # backfill the standalone timer for existing pulse-enabled installs.
1961
- if _should_setup_noninteractive_complexity_scan; then
1962
- _time_step "setup_complexity_scan" setup_complexity_scan
1963
- fi
1964
- # t2862 (GH#20919): pulse merge routine — fast 120s standalone merge pass.
1965
- # t3036 (GH#21616): use the pulse-dependency escape hatch instead of the
1966
- # generic chicken-and-egg gate so the routine installs on existing systems
1967
- # whenever the supervisor pulse is consented.
1968
- if _should_setup_noninteractive_pulse_merge_routine; then
1969
- _time_step "setup_pulse_merge_routine" _setup_run_noncritical_stage_bounded "Pulse merge routine setup" "${AIDEVOPS_SETUP_PULSE_MERGE_ROUTINE_TIMEOUT:-30}" setup_pulse_merge_routine
1970
- # t19030: a timeout kill can leave the merge scheduler unregenerated
1971
- # before the child reaches its own deferral.
1972
- if [[ "${_SETUP_NONCRITICAL_STAGE_TIMED_OUT:-false}" == "true" ]]; then
1973
- _schedulers_defer_template_hash "pulse merge routine setup timed out"
1974
- fi
1975
- fi
1976
- # t2932 (GH#21125): peer productivity monitor — adaptive cross-runner
1977
- # dispatch coordination, runs every 30 min.
1978
- if _should_setup_noninteractive_scheduler "Peer productivity monitor" "sh.aidevops.peer-productivity-monitor" "aidevops: peer-productivity-monitor" "aidevops-peer-productivity-monitor"; then
1979
- _time_step "setup_peer_productivity_monitor" setup_peer_productivity_monitor
1980
- fi
1981
- # Repo sync handles non-interactive mode internally (systemd detection fixed in GH#17861)
1982
- _time_step "setup_repo_sync" setup_repo_sync
1983
- _time_step "setup_mirror_sync" setup_mirror_sync
1984
- # r914 repo-aidevops-health — daily drift keeper (t2366)
1985
- _time_step "setup_repo_aidevops_health" setup_repo_aidevops_health
1986
- if _should_setup_noninteractive_scheduler "Profile README" "sh.aidevops.profile-readme-update" "aidevops: profile-readme-update" "aidevops-profile-readme-update"; then
1987
- _time_step "setup_profile_readme" setup_profile_readme
1988
- fi
1989
- if _should_setup_noninteractive_scheduler "OAuth token refresh" "sh.aidevops.token-refresh" "aidevops: token-refresh" "aidevops-token-refresh"; then
1990
- _time_step "setup_oauth_token_refresh" setup_oauth_token_refresh
1991
- fi
1992
- # opencode DB maintenance (r913, t2183). Helper self-noops on missing
1993
- # DB — safe to install unconditionally in non-interactive mode too.
1994
- _time_step "setup_opencode_db_maintenance" setup_opencode_db_maintenance
1995
- # opencode DB archive/VACUUM (GH#25136). Dedicated low-priority scheduler;
1996
- # not tied to pulse preflight cadence.
1997
- _time_step "setup_opencode_db_archive" setup_opencode_db_archive
1998
- # r922 storage hygiene (GH#35245). Daily owning-cleaner run, Pulse-independent.
1999
- _time_step "setup_storage_hygiene" setup_storage_hygiene
2000
- # Migrate cron entries to systemd after schedulers are installed (GH#17695 Finding D)
2001
- _time_step "migrate_cron_to_systemd" migrate_cron_to_systemd
2002
- # t19030: only a full scheduler pass records the plist drift template hash.
2003
- _schedulers_record_template_hash
2004
- _time_step "$SETUP_STAGE_TABBY" setup_tabby
2005
- return 0
2006
- }
2007
-
2008
- _setup_post_setup_steps() {
2009
- local os="$1"
2010
-
2011
- # Non-interactive mode still has post-deploy scheduler and pulse-restart
2012
- # work to do. Do not print the human "Setup complete!" marker until those
2013
- # bounded postflight steps and the final child-process drain have finished;
2014
- # callers treat that line as a completion signal.
2015
- if [[ "$NON_INTERACTIVE" == "true" ]]; then
2016
- _setup_noninteractive_schedulers "$os"
2017
- return 0
2018
- fi
2019
-
2020
- # Print setup summary before final success message (GH#5240)
2021
- print_setup_summary
2022
-
2023
- echo ""
2024
- print_success "Setup complete!"
2025
-
2026
- # Cache client request format constants if CLI is installed (~50ms)
2027
- if command -v claude &>/dev/null && [[ -x "${INSTALL_DIR}/.agents/scripts/cch-extract.sh" ]]; then
2028
- "${INSTALL_DIR}/.agents/scripts/cch-extract.sh" --cache >/dev/null 2>&1 || true
2029
- else
2030
- echo ""
2031
- echo -e "${YELLOW}[TIP]${NC} Install Claude CLI for automatic request format alignment:"
2032
- echo " npm install -g @anthropic-ai/claude-code"
2033
- fi
2034
-
2035
- # Post-setup: auto-update, schedulers, final instructions (GH#5793)
2036
- setup_auto_update
2037
- setup_supervisor_pulse "$os"
2038
- # t2939: pulse-watchdog — independent revival mechanism, layered defense.
2039
- setup_pulse_watchdog "${PULSE_ENABLED:-}"
2040
- setup_stats_wrapper "${PULSE_ENABLED:-}"
2041
- setup_failure_miner "${PULSE_ENABLED:-}"
2042
- setup_repo_sync
2043
- setup_mirror_sync
2044
- # r914 repo-aidevops-health — daily drift keeper (t2366)
2045
- setup_repo_aidevops_health
2046
- setup_process_guard
2047
- setup_memory_pressure_monitor
2048
- setup_screen_time_snapshot
2049
- setup_contribution_watch
2050
- setup_complexity_scan
2051
- setup_pulse_merge_routine
2052
- setup_peer_productivity_monitor
2053
- setup_draft_responses
2054
- setup_profile_readme
2055
- setup_oauth_token_refresh
2056
- setup_opencode_db_maintenance
2057
- setup_opencode_db_archive
2058
- setup_storage_hygiene
2059
- # Migrate cron entries to systemd after schedulers are installed (GH#17695 Finding D)
2060
- migrate_cron_to_systemd
2061
- # t19030: only a full scheduler pass records the plist drift template hash.
2062
- _schedulers_record_template_hash
2063
- setup_tabby
2064
- print_final_instructions
2065
-
2066
- # Check for tool updates if --update flag was passed
2067
- if [[ "$UPDATE_TOOLS_MODE" == "true" ]]; then
2068
- echo ""
2069
- check_tool_updates
2070
- fi
2071
-
2072
- setup_onboarding_prompt
2073
- return 0
2074
- }
2075
-
2076
1045
  _setup_restart_pulse_if_running() {
2077
1046
  # Reconcile only after scheduler setup has established the effective consent
2078
1047
  # state. The activated helper serializes with deployment, resolves the active
@@ -2129,16 +1098,6 @@ _setup_restart_pulse_if_running() {
2129
1098
  return 0
2130
1099
  }
2131
1100
 
2132
- _setup_print_noninteractive_success() {
2133
- # Ensure every tracked or discovered child has either exited or been
2134
- # intentionally terminated before emitting the caller-visible success line.
2135
- _setup_cleanup_noninteractive_children
2136
- print_setup_summary
2137
- echo ""
2138
- print_success "Setup complete!"
2139
- return 0
2140
- }
2141
-
2142
1101
  # Print the completion sentinel. This is the canonical "setup.sh finished all
2143
1102
  # phases" marker — any caller that needs to detect silent early-termination
2144
1103
  # (e.g., t2022-class bugs where a sourced helper's set -e propagates a