vault scripts: publish canonical Obsidian vault into the repo mirror

This commit is contained in:
jimmy
2026-09-13 12:07:50 -07:00
parent aa52eecb5c
commit e8ee99f046
2 changed files with 62 additions and 32 deletions
+45 -22
View File
@@ -1,43 +1,66 @@
#!/usr/bin/env bash
# Zero-token vault sync protocol
# Commit local changes, rebase onto the remote, push to the Gitea mirror.
# Zero-token vault publish.
#
# SCOPE: only the agent-os vault tree is staged. The git repo root is the PARENT
# directory (AgentOS), so a bare `git add -A` sweeps unrelated agent work into
# "vault-sync" commits. Both the status check and the add are pathspec-scoped.
# 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
#
# 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
# subsequent push gets rejected.
# 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.
#
# IDENTITY: passed per-commit with `git -c`, never repo-local config — the repo is
# shared by every agent profile, so a repo-local user.name attributes every agent's
# commits to one agent. Override with VAULT_AGENT=<name>.
# NOTE: set VAULT_AGENT (or edit the default) in your own profile's copy.
# 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/AgentOS/memory-systems/agent-os"
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")
cd "$VAULT_DIR" || exit 1
[ -d "$VAULT_DIR" ] || { echo "Vault not found: $VAULT_DIR"; exit 1; }
echo "=== Vault Sync $(date '+%Y-%m-%d %H:%M') (agent: $AGENT_NAME) ==="
# 1. Stage + commit local changes (vault tree only).
# 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
echo "Local changes detected. Committing..."
git add -A . || exit 1
git "${GIT_ID[@]}" commit -m "vault-sync: $(date '+%Y-%m-%d %H:%M') ($AGENT_NAME)" 2>&1 | tail -3
else
echo "No local changes."
git "${GIT_ID[@]}" commit -q -m "vault: $(date '+%Y-%m-%d %H:%M') ($AGENT_NAME)" \
&& echo "Vault history: committed local changes."
fi
# 2. Rebase onto the remote. --autostash so unrelated dirty files elsewhere in the
# repo (AgentOS holds more than this vault) cannot block the pull.
# 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
# 3. Push to remote.
# 5. Push to remote.
echo "Pushing to Gitea..."
git push 2>&1 | tail -3