Files

68 lines
2.8 KiB
Bash

#!/usr/bin/env bash
# Zero-token vault publish.
#
# SOURCE OF TRUTH : /c/Users/fight/Documents/Obsidian Vault
# MIRROR (git) : C:/Users/fight/AgentOS/memory-systems/agent-os
# REMOTE : Tony_tech/personal-agent-os
#
# The mirror is a generated byte copy of the vault, so the Obsidian vault is
# backed up to Gitea without a second *writable* copy that could drift.
# Never edit the mirror by hand — step 2 rebuilds it from the vault.
#
# SCOPE: only the mirror subtree is staged. The AgentOS repo root holds unrelated
# agent work (agent-comms/, knowledge-base/, scripts/, ...) that must not be
# swept into vault commits — a bare `git add -A` would do exactly that.
# ORDER: commit BEFORE `git pull --rebase`; rebase refuses to run on a dirty tree,
# so pulling first is a silent no-op exactly when a pull is needed and the
# following push gets rejected.
# IDENTITY: passed per-commit with `git -c`, never repo-local config — the AgentOS
# repo is shared by every agent profile, so a repo-local user.name would
# attribute every agent's commits to one agent. Override with VAULT_AGENT=<name>.
VAULT_DIR="/c/Users/fight/Documents/Obsidian Vault"
MIRROR_DIR="/c/Users/fight/AgentOS/memory-systems/agent-os"
REPO_DIR="/c/Users/fight/AgentOS"
AGENT_NAME="${VAULT_AGENT:-jimmy}"
GIT_ID=(-c "user.name=$AGENT_NAME" -c "user.email=$AGENT_NAME@hermes.local")
[ -d "$VAULT_DIR" ] || { echo "Vault not found: $VAULT_DIR"; exit 1; }
echo "=== Vault Sync $(date '+%Y-%m-%d %H:%M') (agent: $AGENT_NAME) ==="
# 1. Keep the vault's own local history moving (its original Gitea remote is gone,
# so this is local-only history; the mirror is what gets pushed).
cd "$VAULT_DIR" || exit 1
if [ -n "$(git status --porcelain .)" ]; then
git add -A . || exit 1
git "${GIT_ID[@]}" commit -q -m "vault: $(date '+%Y-%m-%d %H:%M') ($AGENT_NAME)" \
&& echo "Vault history: committed local changes."
fi
# 2. Publish the vault into the git mirror.
echo "Mirroring vault -> AgentOS repo..."
find "$MIRROR_DIR" -mindepth 1 -maxdepth 1 -exec rm -rf {} +
tar -C "$VAULT_DIR" \
--exclude=.git --exclude=.obsidian --exclude=.zvec-grep --exclude=.trash \
-cf - . | tar -C "$MIRROR_DIR" -xf -
# 3. Commit the mirror subtree.
cd "$REPO_DIR" || exit 1
if [ -n "$(git status --porcelain -- memory-systems/agent-os)" ]; then
echo "Mirror changed. Committing..."
git add -A -- memory-systems/agent-os || exit 1
git "${GIT_ID[@]}" commit -m "vault-sync: $(date '+%Y-%m-%d %H:%M') ($AGENT_NAME)" 2>&1 | tail -3
else
echo "Mirror unchanged."
fi
# 4. Rebase onto the remote. --autostash so unrelated dirty files elsewhere in the
# repo cannot block the pull.
echo "Pulling latest..."
git pull --rebase --autostash 2>&1 | tail -3
# 5. Push to remote.
echo "Pushing to Gitea..."
git push 2>&1 | tail -3
echo "=== Sync Complete ==="