#!/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 >/dev/null 2>&1; then # Nếu pull fail, tiếp tục với trạng thái hiện tại true fi # Pop stash lại if [ "$STASHED" = true ]; then git stash pop >/dev/null 2>&1 || 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 >/dev/null 2>&1 # Bỏ qua các file nhạy cảm và DB nếu vô tình bị đưa vào git restore --staged .env >/dev/null 2>&1 || true git restore --staged 'profiles/*/state.db' >/dev/null 2>&1 || true git restore --staged 'kanban.db' >/dev/null 2>&1 || 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" >/dev/null 2>&1 git push origin main >/dev/null 2>&1 short_sha=$(git rev-parse --short HEAD) echo "✅ Git Sync: ${short_sha}" /root/.hermes/scripts/git-brief.sh || true