replica-omnisciente/sync.sh

47 lines
1.3 KiB
Bash
Executable file

#!/bin/bash
# Replica-Omnisciente Fleet Sync Utility
# Version: 1.0.0
MODE=$1 # --pull or --push
# Resolve the .agent directory
AGENT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
cd "$AGENT_DIR" || exit 1
# Check if we are in a git repo
if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
echo "❌ Error: .agent is not a git repository."
exit 1
fi
case "$MODE" in
--pull)
echo "🔄 Ingesting latest consciousness from fleet..."
git fetch origin main
# Check if we are behind
BEHIND=$(git rev-list HEAD..origin/main --count)
if [ "$BEHIND" -gt 0 ]; then
git pull --rebase origin main
echo "✅ Fleet state ingested ($BEHIND commits)."
else
echo "✅ Local conscience is up to date."
fi
;;
--push)
echo "🚀 Broadcasting current realm state to fleet..."
git add .
# Only commit if there are changes
if ! git diff-index --quiet HEAD --; then
TIMESTAMP=$(date +"%Y-%m-%d %H:%M")
git commit -m "sync(chronicle): automatic update [$TIMESTAMP]"
git push origin main
echo "✅ Broadcasting complete."
else
echo "✅ No changes to broadcast."
fi
;;
*)
echo "Usage: $0 [--pull | --push]"
exit 1
;;
esac