Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .agents/scripts/supervisor-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ source "${SUPERVISOR_MODULE_DIR}/ai-context.sh"
source "${SUPERVISOR_MODULE_DIR}/ai-reason.sh"
source "${SUPERVISOR_MODULE_DIR}/ai-actions.sh"
source "${SUPERVISOR_MODULE_DIR}/issue-audit.sh"
source "${SUPERVISOR_MODULE_DIR}/routine-scheduler.sh"

# Valid states for the state machine
# shellcheck disable=SC2034 # Used by supervisor/state.sh
Expand Down Expand Up @@ -779,6 +780,10 @@ main() {
echo " Log file: ${ai_log_file}"
echo " Reason log dir: ${AI_REASON_LOG_DIR:-$HOME/.aidevops/logs/ai-supervisor}"
;;
routine-status)
# Show Phase 14 intelligent routine scheduling state
routine_scheduler_status
;;
help | --help | -h) show_usage ;;
*)
log_error "Unknown command: $command"
Expand Down
63 changes: 51 additions & 12 deletions .agents/scripts/supervisor/pulse.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1509,35 +1509,58 @@ RULES:
done <<<"$health_repos"
fi

# Phase 14: Intelligent routine scheduling (t1093)
# Pre-computes scheduling decisions for Phases 9-13 based on project state signals.
# Decisions are exported as ROUTINE_DECISION_* env vars consumed by each phase.
# Signals: consecutive zero-findings runs, open critical issues, recent failure rate.
# Routines can be skipped (interval not met), deferred (explicit hold), or approved.
if declare -f run_phase14_routine_scheduler &>/dev/null; then
run_phase14_routine_scheduler 2>>"$SUPERVISOR_LOG" || true
fi

# Phase 9: Memory audit pulse (t185)
# Runs dedup, prune, graduate, and opportunity scan.
# The audit script self-throttles (24h interval), so calling every pulse is safe.
# Phase 14 may defer this if signals indicate it's not worth running.
local audit_script="${SCRIPT_DIR}/memory-audit-pulse.sh"
if [[ -x "$audit_script" ]]; then
log_verbose " Phase 9: Memory audit pulse"
"$audit_script" run --quiet 2>>"$SUPERVISOR_LOG" || true
local _phase9_decision="${ROUTINE_DECISION_MEMORY_AUDIT:-run}"
if [[ "$_phase9_decision" == "run" ]]; then
log_verbose " Phase 9: Memory audit pulse"
"$audit_script" run --quiet 2>>"$SUPERVISOR_LOG" || true
routine_record_run "memory_audit" 0 2>/dev/null || true
else
log_verbose " Phase 9: Memory audit pulse skipped by Phase 14 (decision: ${_phase9_decision})"
fi
fi

# Phase 10: CodeRabbit daily pulse (t166.1)
# Triggers a full codebase review via CodeRabbit CLI or GitHub API.
# The pulse script self-throttles (24h cooldown), so calling every pulse is safe.
# Phase 14 may defer this if 3+ consecutive zero-findings days or critical issues open.
local coderabbit_pulse_script="${SCRIPT_DIR}/coderabbit-pulse-helper.sh"
if [[ -x "$coderabbit_pulse_script" ]]; then
log_verbose " Phase 10: CodeRabbit daily pulse"
local pulse_repo=""
pulse_repo=$(db "$SUPERVISOR_DB" "SELECT DISTINCT repo FROM tasks LIMIT 1;" 2>/dev/null || echo "")
if [[ -z "$pulse_repo" ]]; then
pulse_repo="$(pwd)"
local _phase10_decision="${ROUTINE_DECISION_CODERABBIT:-run}"
if [[ "$_phase10_decision" == "run" ]]; then
log_verbose " Phase 10: CodeRabbit daily pulse"
local pulse_repo=""
pulse_repo=$(db "$SUPERVISOR_DB" "SELECT DISTINCT repo FROM tasks LIMIT 1;" 2>/dev/null || echo "")
if [[ -z "$pulse_repo" ]]; then
pulse_repo="$(pwd)"
fi
bash "$coderabbit_pulse_script" run --repo "$pulse_repo" --quiet 2>>"$SUPERVISOR_LOG" || true
routine_record_run "coderabbit" 0 2>/dev/null || true
else
log_verbose " Phase 10: CodeRabbit pulse skipped by Phase 14 (decision: ${_phase10_decision})"
fi
bash "$coderabbit_pulse_script" run --repo "$pulse_repo" --quiet 2>>"$SUPERVISOR_LOG" || true
fi

# Phase 10b: Auto-create TODO tasks from quality findings (t299, t1032.5)
# Unified audit orchestrator: collects findings from all configured services
# (CodeRabbit, Codacy, SonarCloud, CodeFactor) via code-audit-helper.sh, then
# creates tasks via audit-task-creator-helper.sh. Falls back to CodeRabbit-only
# coderabbit-task-creator-helper.sh if the unified scripts are not yet available.
# Self-throttles with 24h cooldown.
# Self-throttles with 24h cooldown. Phase 14 may defer if consecutive empty runs.
local audit_collect_script="${SCRIPT_DIR}/code-audit-helper.sh"
local unified_task_creator="${SCRIPT_DIR}/audit-task-creator-helper.sh"
local legacy_task_creator="${SCRIPT_DIR}/coderabbit-task-creator-helper.sh"
Expand All @@ -1552,7 +1575,12 @@ RULES:
local task_creation_cooldown=86400 # 24 hours
if [[ -n "$task_creator_script" ]]; then
local should_run_task_creation=true
if [[ -f "$task_creation_cooldown_file" ]]; then
# Phase 14 intelligent scheduling check
local _phase10b_decision="${ROUTINE_DECISION_TASK_CREATION:-run}"
if [[ "$_phase10b_decision" != "run" ]]; then
should_run_task_creation=false
log_verbose " Phase 10b: Task creation skipped by Phase 14 (decision: ${_phase10b_decision})"
elif [[ -f "$task_creation_cooldown_file" ]]; then
local last_run
last_run=$(cat "$task_creation_cooldown_file" 2>/dev/null || echo "0")
local now
Expand Down Expand Up @@ -1696,6 +1724,7 @@ RULES:
else
log_verbose " Phase 10b: No new tasks to create"
fi
routine_record_run "task_creation" "$tasks_added" 2>/dev/null || true
fi
fi
fi
Expand Down Expand Up @@ -1759,6 +1788,7 @@ RULES:
# Phase 12: Regenerate MODELS.md leaderboard (t1012)
# Throttled to once per hour — only regenerates when pattern data may have changed.
# Iterates over known repos and updates MODELS.md in each repo root.
# Phase 14 may defer this when critical issues are open (cosmetic update).
local models_md_interval=3600 # seconds (1 hour)
local models_md_stamp="$SUPERVISOR_DIR/models-md-last-regen"
local models_md_now
Expand All @@ -1768,7 +1798,10 @@ RULES:
models_md_last=$(cat "$models_md_stamp" 2>/dev/null || echo 0)
fi
local models_md_elapsed=$((models_md_now - models_md_last))
if [[ "$models_md_elapsed" -ge "$models_md_interval" ]]; then
local _phase12_decision="${ROUTINE_DECISION_MODELS_MD:-run}"
if [[ "$_phase12_decision" != "run" ]]; then
log_verbose " Phase 12: MODELS.md regen skipped by Phase 14 (decision: ${_phase12_decision})"
elif [[ "$models_md_elapsed" -ge "$models_md_interval" ]]; then
local generate_script="${SCRIPT_DIR}/generate-models-md.sh"
if [[ -x "$generate_script" ]]; then
local models_repos
Expand Down Expand Up @@ -1796,6 +1829,7 @@ RULES:
fi
fi
echo "$models_md_now" >"$models_md_stamp" 2>/dev/null || true
routine_record_run "models_md" -1 2>/dev/null || true
else
local models_md_remaining=$((models_md_interval - models_md_elapsed))
log_verbose " Phase 12: MODELS.md regen skipped (${models_md_remaining}s until next run)"
Expand All @@ -1807,6 +1841,7 @@ RULES:
# Only runs for repos where the authenticated user has write/admin permission,
# ensuring PRs are only created where the user is a maintainer.
# Batch mode: SUPERVISOR_SKILL_UPDATE_BATCH_MODE (one-per-skill|single-pr, default: one-per-skill)
# Phase 14 may defer this when failure rate is high or critical issues are open.
local skill_update_pr_enabled="${SUPERVISOR_SKILL_UPDATE_PR:-false}"
if [[ "$skill_update_pr_enabled" == "true" ]]; then
local skill_update_interval="${SUPERVISOR_SKILL_UPDATE_INTERVAL:-86400}" # seconds (24h default)
Expand All @@ -1818,7 +1853,10 @@ RULES:
skill_update_last=$(cat "$skill_update_stamp" 2>/dev/null || echo 0)
fi
local skill_update_elapsed=$((skill_update_now - ${skill_update_last:-0}))
if [[ "$skill_update_elapsed" -ge "$skill_update_interval" ]]; then
local _phase13_decision="${ROUTINE_DECISION_SKILL_UPDATE:-run}"
if [[ "$_phase13_decision" != "run" ]]; then
log_verbose " Phase 13: Skill update PR skipped by Phase 14 (decision: ${_phase13_decision})"
elif [[ "$skill_update_elapsed" -ge "$skill_update_interval" ]]; then
local skill_update_script="${SCRIPT_DIR}/skill-update-helper.sh"
if [[ -x "$skill_update_script" ]]; then
# Determine the repo root to check maintainer permission
Expand Down Expand Up @@ -1856,6 +1894,7 @@ RULES:
log_verbose " Phase 13: Skipped (skill-update-helper.sh not found)"
fi
echo "$skill_update_now" >"$skill_update_stamp" 2>/dev/null || true
routine_record_run "skill_update" -1 2>/dev/null || true
else
local skill_update_remaining=$((skill_update_interval - skill_update_elapsed))
log_verbose " Phase 13: Skill update PR skipped (${skill_update_remaining}s until next run)"
Expand Down
Loading
Loading