diff --git a/.agents/scripts/supervisor-helper.sh b/.agents/scripts/supervisor-helper.sh index e81926b98..d5d1811d3 100755 --- a/.agents/scripts/supervisor-helper.sh +++ b/.agents/scripts/supervisor-helper.sh @@ -163,9 +163,32 @@ unset _gh_token_cache # Configuration - resolve relative to this script's location SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" || exit +readonly SCRIPT_DIR source "${SCRIPT_DIR}/shared-constants.sh" -# Source all supervisor module files +# Define all globals BEFORE sourcing modules — modules reference these in +# functions and traps. With set -u, any reference to an undefined variable +# is a fatal error. The t1031 modularisation moved functions into modules +# but left the globals defined after the source block, causing +# "PULSE_LOCK_DIR: unbound variable" errors in cron pulse (t1031 regression). +readonly SUPERVISOR_DIR="${AIDEVOPS_SUPERVISOR_DIR:-$HOME/.aidevops/.agent-workspace/supervisor}" +readonly SUPERVISOR_DB="$SUPERVISOR_DIR/supervisor.db" +readonly MAIL_HELPER="${SCRIPT_DIR}/mail-helper.sh" # Used by pulse command (t128.2) +readonly MEMORY_HELPER="${SCRIPT_DIR}/memory-helper.sh" # Used by pulse command (t128.6) +readonly SESSION_REVIEW_HELPER="${SCRIPT_DIR}/session-review-helper.sh" # Used by batch completion (t128.9) +readonly SESSION_DISTILL_HELPER="${SCRIPT_DIR}/session-distill-helper.sh" # Used by batch completion (t128.9) +readonly MEMORY_AUDIT_HELPER="${SCRIPT_DIR}/memory-audit-pulse.sh" # Used by pulse Phase 9 (t185) +readonly SESSION_CHECKPOINT_HELPER="${SCRIPT_DIR}/session-checkpoint-helper.sh" # Used by respawn (t264.1) +readonly RESPAWN_LOG="${HOME}/.aidevops/logs/respawn-history.log" # Persistent respawn log (t264.1) +SUPERVISOR_LOG_DIR="${HOME}/.aidevops/logs" +mkdir -p "$SUPERVISOR_LOG_DIR" 2>/dev/null || true +SUPERVISOR_LOG="${SUPERVISOR_LOG_DIR}/supervisor.log" +readonly PULSE_LOCK_DIR="${SUPERVISOR_DIR}/pulse.lock" +readonly PULSE_LOCK_TIMEOUT="${SUPERVISOR_PULSE_LOCK_TIMEOUT:-600}" +export MAIL_HELPER MEMORY_HELPER SESSION_REVIEW_HELPER SESSION_DISTILL_HELPER MEMORY_AUDIT_HELPER SESSION_CHECKPOINT_HELPER +export SUPERVISOR_LOG SUPERVISOR_LOG_DIR PULSE_LOCK_DIR PULSE_LOCK_TIMEOUT + +# Source all supervisor module files (globals must be defined above) SUPERVISOR_MODULE_DIR="${SCRIPT_DIR}/supervisor" source "${SUPERVISOR_MODULE_DIR}/_common.sh" source "${SUPERVISOR_MODULE_DIR}/database.sh" @@ -186,24 +209,6 @@ source "${SUPERVISOR_MODULE_DIR}/issue-sync.sh" source "${SUPERVISOR_MODULE_DIR}/memory-integration.sh" source "${SUPERVISOR_MODULE_DIR}/todo-sync.sh" -readonly SCRIPT_DIR -readonly SUPERVISOR_DIR="${AIDEVOPS_SUPERVISOR_DIR:-$HOME/.aidevops/.agent-workspace/supervisor}" -readonly SUPERVISOR_DB="$SUPERVISOR_DIR/supervisor.db" -readonly MAIL_HELPER="${SCRIPT_DIR}/mail-helper.sh" # Used by pulse command (t128.2) -readonly MEMORY_HELPER="${SCRIPT_DIR}/memory-helper.sh" # Used by pulse command (t128.6) -readonly SESSION_REVIEW_HELPER="${SCRIPT_DIR}/session-review-helper.sh" # Used by batch completion (t128.9) -readonly SESSION_DISTILL_HELPER="${SCRIPT_DIR}/session-distill-helper.sh" # Used by batch completion (t128.9) -readonly MEMORY_AUDIT_HELPER="${SCRIPT_DIR}/memory-audit-pulse.sh" # Used by pulse Phase 9 (t185) -readonly SESSION_CHECKPOINT_HELPER="${SCRIPT_DIR}/session-checkpoint-helper.sh" # Used by respawn (t264.1) -readonly RESPAWN_LOG="${HOME}/.aidevops/logs/respawn-history.log" # Persistent respawn log (t264.1) -SUPERVISOR_LOG_DIR="${HOME}/.aidevops/logs" -mkdir -p "$SUPERVISOR_LOG_DIR" 2>/dev/null || true -SUPERVISOR_LOG="${SUPERVISOR_LOG_DIR}/supervisor.log" -readonly PULSE_LOCK_DIR="${SUPERVISOR_DIR}/pulse.lock" -readonly PULSE_LOCK_TIMEOUT="${SUPERVISOR_PULSE_LOCK_TIMEOUT:-600}" -export MAIL_HELPER MEMORY_HELPER SESSION_REVIEW_HELPER SESSION_DISTILL_HELPER MEMORY_AUDIT_HELPER SESSION_CHECKPOINT_HELPER -export SUPERVISOR_LOG SUPERVISOR_LOG_DIR PULSE_LOCK_DIR PULSE_LOCK_TIMEOUT - # Valid states for the state machine readonly VALID_STATES="queued dispatched running evaluating retrying complete pr_review review_triage merging merged deploying deployed verifying verified verify_failed blocked failed cancelled"