#!/bin/bash set -e # === Auto-heal pipeline === heal_files() { echo "🩺 Healing all files..." find ~/Desktop/AI_Brain -type f \( -name "*.sh" -o -name "*.py" \) | while read -r f; do chmod +x "$f" 2>/dev/null || true dos2unix "$f" 2>/dev/null || true if [[ "$f" == *.py ]]; then python3 -m py_compile "$f" 2>/dev/null || true fi done echo "✅ Healing complete" } # === GitHub sync === sync_repo() { echo "🌐 Syncing GitHub repo..." bash ~/Desktop/AI_Brain/sync_from_github.sh || echo "⚠️ GitHub sync failed, continuing with local files" } # === Launch sub-brains === launch_subbrains() { echo "🚀 Launching sub-brains..." for brain in ~/Desktop/AI_Brain/sub_brains/*/launch.sh; do name=$(basename "$(dirname "$brain")") log=~/Desktop/AI_Brain/logs/${name}.out if pgrep -f "$brain" >/dev/null; then echo "🟢 $name already running" else echo "🚀 Starting $name" nohup bash "$brain" >> "$log" 2>&1 & fi done } # === Main Loop === while true; do heal_files sync_repo launch_subbrains sleep 300 # check every 5 minutes done