From 7b6907ab105b05946afccef7f216ba3f28aff93e Mon Sep 17 00:00:00 2001 From: marcusquinn <6428977+marcusquinn@users.noreply.github.com> Date: Thu, 19 Feb 2026 21:33:35 +0000 Subject: [PATCH] fix: resolve symlink SCRIPT_DIR for launchd agents (t1262) When supervisor-helper.sh and auto-update-helper.sh are invoked via symlinks in ~/.aidevops/bin/ (created by t1260 launchd setup), BASH_SOURCE[0] resolves to the symlink path, not the target. This causes SCRIPT_DIR to be ~/.aidevops/bin/ instead of the actual scripts directory, breaking shared-constants.sh sourcing (exit code 1). Fix: add _resolve_script_path() that follows symlink chain before determining SCRIPT_DIR. Works for both direct invocation and symlinks. --- .agents/scripts/auto-update-helper.sh | 16 +++++++++++++++- .agents/scripts/supervisor-helper.sh | 18 ++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/.agents/scripts/auto-update-helper.sh b/.agents/scripts/auto-update-helper.sh index 984ecb435..8d3d63bb0 100755 --- a/.agents/scripts/auto-update-helper.sh +++ b/.agents/scripts/auto-update-helper.sh @@ -26,7 +26,21 @@ set -euo pipefail -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || exit +# Resolve symlinks to find real script location (t1262) +# When invoked via symlink (e.g. ~/.aidevops/bin/aidevops-auto-update), +# BASH_SOURCE[0] is the symlink path. We must resolve it to find sibling scripts. +_resolve_script_path() { + local src="${BASH_SOURCE[0]}" + while [[ -L "$src" ]]; do + local dir + dir="$(cd "$(dirname "$src")" && pwd)" || return 1 + src="$(readlink "$src")" + [[ "$src" != /* ]] && src="$dir/$src" + done + cd "$(dirname "$src")" && pwd +} +SCRIPT_DIR="$(_resolve_script_path)" || exit +unset -f _resolve_script_path source "${SCRIPT_DIR}/shared-constants.sh" init_log_file diff --git a/.agents/scripts/supervisor-helper.sh b/.agents/scripts/supervisor-helper.sh index e226eb664..a7b4a5aea 100755 --- a/.agents/scripts/supervisor-helper.sh +++ b/.agents/scripts/supervisor-helper.sh @@ -164,8 +164,22 @@ if [[ -z "${GH_TOKEN:-}" ]]; then fi unset _gh_token_cache -# Configuration - resolve relative to this script's location -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || exit +# Configuration - resolve relative to this script's real location (not symlink) +# When invoked via symlink (e.g. ~/.aidevops/bin/aidevops-supervisor-pulse), +# BASH_SOURCE[0] is the symlink path. We must resolve it to find sibling scripts. +_resolve_script_path() { + local src="${BASH_SOURCE[0]}" + while [[ -L "$src" ]]; do + local dir + dir="$(cd "$(dirname "$src")" && pwd)" || return 1 + src="$(readlink "$src")" + # Handle relative symlinks + [[ "$src" != /* ]] && src="$dir/$src" + done + cd "$(dirname "$src")" && pwd +} +SCRIPT_DIR="$(_resolve_script_path)" || exit +unset -f _resolve_script_path readonly SCRIPT_DIR source "${SCRIPT_DIR}/shared-constants.sh"