61 lines
1.6 KiB
Bash
Executable File
61 lines
1.6 KiB
Bash
Executable File
#!/bin/bash
|
|
#===============================================
|
|
# obsidian-vault sync script
|
|
# All 3 agents run this every 5 minutes
|
|
#===============================================
|
|
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"
|
|
|
|
# Update daily log
|
|
mkdir -p "$VAULT_DIR/agent-shared/daily"
|
|
if [ ! -f "$LOG_FILE" ]; then
|
|
cat > "$LOG_FILE" << EOF
|
|
# Daily Log — $(date +%Y-%m-%d)
|
|
|
|
## Agents Active Today
|
|
- Horus
|
|
- Amun
|
|
- Cleo
|
|
|
|
## Session Activity
|
|
|
|
EOF
|
|
fi
|
|
|
|
# Check if dirty
|
|
if [ -n "$(git status --porcelain)" ]; then
|
|
echo "[$AGENT] Vault has changes — committing..."
|
|
git add -A
|
|
git commit -m "chore: $AGENT sync $(date -u +%Y-%m-%dT%H:%M:%SZ)"
|
|
|
|
# Push if remote exists
|
|
if git remote get-url origin &>/dev/null; then
|
|
git pull --rebase origin master 2>/dev/null || true
|
|
git push origin master 2>/dev/null || echo "[$AGENT] Push failed (offline?)"
|
|
fi
|
|
|
|
# Update vault state
|
|
python3 -c "
|
|
import json
|
|
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'] = '$(date -u +%Y-%m-%dT%H:%M:%SZ)'
|
|
with open('$STATE_FILE', 'w') as f:
|
|
json.dump(s, f, indent=2)
|
|
"
|
|
echo "[$AGENT] Sync complete"
|
|
else
|
|
# Pull latest from others
|
|
if git remote get-url origin &>/dev/null; then
|
|
git pull origin master 2>/dev/null && echo "[$AGENT] Pulled latest" || echo "[$AGENT] Pull failed or no remote"
|
|
fi
|
|
fi
|