#!/bin/bash set -euo pipefail AGENT="${1:-horus}" VAULT_DIR="/root/.openclaw/workspace/obsidian-vault" STATE_FILE="$VAULT_DIR/agent-openclaw/vault-state.json" LOG_FILE="$VAULT_DIR/agent-shared/daily/$(date +%Y-%m-%d).md" cd "$VAULT_DIR" mkdir -p "$VAULT_DIR/agent-shared/daily" if [ ! -f "$LOG_FILE" ]; then cat > "$LOG_FILE" << EOF # Daily Log — $(date +%Y-%m-%d) ## Session Activity EOF fi if [ -n "$(git status --porcelain)" ]; then echo "[$AGENT] Committing changes..." git add -A git commit -m "chore: $AGENT sync $(date -u +%Y-%m-%dT%H:%M:%SZ)" # Push to local Gitea first (always works) git push gitea main 2>/dev/null && echo "[$AGENT] Pushed to Gitea" || echo "[$AGENT] Gitea push failed" # Push to GitHub (if account not suspended) git push origin main 2>/dev/null && echo "[$AGENT] Pushed to GitHub" || echo "[$AGENT] GitHub push failed (account suspended?)" python3 -c " import json from datetime import datetime with open('$STATE_FILE', 'r') as f: s = json.load(f) s['agents']['$AGENT']['last_commit'] = '$(git rev-parse HEAD)' s['agents']['$AGENT']['dirty'] = False s['last_sync'] = datetime.utcnow().isoformat() + 'Z' s['git_remote'] = 'gitea' with open('$STATE_FILE', 'w') as f: json.dump(s, f, indent=2) " echo "[$AGENT] Sync complete" else # Pull latest git pull gitea main 2>/dev/null && echo "[$AGENT] Pulled from Gitea" || echo "[$AGENT] Pull from Gitea failed" git pull origin main 2>/dev/null && echo "[$AGENT] Pulled from GitHub" || true fi