#!/usr/bin/env bash # Auto-sync script: commit và push mọi thay đổi trong monorepo lên GitHub # Chạy mỗi 8 tiếng qua cron job Hermes. # Chỉ chạy trong /opt/ai-os/products/ceo set -euo pipefail REPO_DIR="/opt/ai-os/products/ceo" cd "$REPO_DIR" # Đảm bảo các SOUL.md mới nhất được update nếu có thay đổi từ symlink # git sẽ tự nhận biết thay đổi nếu file SOUL.md thực sự bị thay đổi qua symlink, # miễn là symlink vẫn trỏ đúng vào repo. # Stash thay đổi cục bộ trước khi pull, pop lại sau STASHED=false if ! git diff --quiet || ! git diff --cached --quiet; then git stash push -u -m "auto-sync-temp-$(date +%s)" >/dev/null 2>&1 STASHED=true fi # Pull trước để tránh conflict if ! git pull --rebase origin main; then # Nếu pull fail, log lỗi echo "❌ Git Pull Failed" fi # Pop stash lại if [ "$STASHED" = true ]; then git stash pop || true fi # Nếu không có thay đổi thì im lặng if [ -z "$(git status --porcelain)" ]; then echo "SILENT: No changes detected." exit 0 fi # Add tất cả file (kể cả trong thư mục profiles/ mới tạo) git add -A # Bỏ qua các file nhạy cảm và DB nếu vô tình bị đưa vào git restore --staged .env || true git restore --staged 'profiles/*/state.db' || true git restore --staged 'kanban.db' || true # Nếu vẫn còn thay đổi thì commit và push if [ -z "$(git status --porcelain)" ]; then echo "SILENT: No staged changes." exit 0 fi commit_msg="chore: auto-sync $(date '+%Y-%m-%d %H:%M') [SOUL profiles included]" git commit -m "$commit_msg" git push origin main short_sha=$(git rev-parse --short HEAD) echo "✅ Git Sync: ${short_sha}" /root/.hermes/scripts/git-brief.sh || true