vault scripts: publish canonical Obsidian vault into the repo mirror
This commit is contained in:
+17
-10
@@ -1,14 +1,17 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Zero-token vault change log
|
# Zero-token vault change log.
|
||||||
# Dumps raw git log to a file for agents to read.
|
# Reads the vault's publish history (the mirror subtree in the AgentOS repo) and
|
||||||
|
# writes it into the vault itself so agents can read it.
|
||||||
|
|
||||||
VAULT_DIR="/c/Users/fight/AgentOS/memory-systems/agent-os"
|
VAULT_DIR="/c/Users/fight/Documents/Obsidian Vault"
|
||||||
|
REPO_DIR="/c/Users/fight/AgentOS"
|
||||||
|
MIRROR_PATH="memory-systems/agent-os"
|
||||||
LOG_FILE="$VAULT_DIR/03_shared/vault-updates-log.md"
|
LOG_FILE="$VAULT_DIR/03_shared/vault-updates-log.md"
|
||||||
|
|
||||||
cd "$VAULT_DIR" || exit 1
|
cd "$REPO_DIR" || exit 1
|
||||||
|
|
||||||
# Refresh from remote first (best-effort: --rebase refuses on a dirty tree).
|
# Refresh from remote first (best-effort; --autostash so a dirty repo can't block it).
|
||||||
git pull --rebase > /dev/null 2>&1
|
git pull --rebase --autostash > /dev/null 2>&1
|
||||||
|
|
||||||
{
|
{
|
||||||
echo "# Vault Updates Log"
|
echo "# Vault Updates Log"
|
||||||
@@ -19,21 +22,25 @@ git pull --rebase > /dev/null 2>&1
|
|||||||
echo ""
|
echo ""
|
||||||
echo "## Last 24 Hours"
|
echo "## Last 24 Hours"
|
||||||
echo ""
|
echo ""
|
||||||
git log --since="24 hours ago" --oneline --no-merges 2>/dev/null || echo "No recent commits."
|
git log --since="24 hours ago" --oneline --no-merges -- "$MIRROR_PATH" 2>/dev/null \
|
||||||
|
|| echo "No recent commits."
|
||||||
echo ""
|
echo ""
|
||||||
echo "---"
|
echo "---"
|
||||||
echo ""
|
echo ""
|
||||||
echo "## Last 7 Days"
|
echo "## Last 7 Days"
|
||||||
echo ""
|
echo ""
|
||||||
git log --since="7 days ago" --oneline --no-merges 2>/dev/null | head -20
|
git log --since="7 days ago" --oneline --no-merges -- "$MIRROR_PATH" 2>/dev/null | head -20
|
||||||
echo ""
|
echo ""
|
||||||
echo "---"
|
echo "---"
|
||||||
echo ""
|
echo ""
|
||||||
echo "## Files Changed (Last 24h)"
|
echo "## Files Changed (Last 24h)"
|
||||||
echo ""
|
echo ""
|
||||||
# `HEAD@{24.hours.ago}` fails on a young reflog; derive the list from the log instead.
|
# `HEAD@{24.hours.ago}` fails on a young reflog; derive the list from the log instead.
|
||||||
git log --since="24 hours ago" --name-only --pretty=format: -- . 2>/dev/null \
|
# The mirror path prefix is stripped so the list reads as vault-relative paths.
|
||||||
| sed '/^[[:space:]]*$/d' | sort -u
|
git log --since="24 hours ago" --name-only --pretty=format: -- "$MIRROR_PATH" 2>/dev/null \
|
||||||
|
| sed '/^[[:space:]]*$/d' \
|
||||||
|
| sed "s|^$MIRROR_PATH/||" \
|
||||||
|
| sort -u
|
||||||
} > "$LOG_FILE"
|
} > "$LOG_FILE"
|
||||||
|
|
||||||
echo "Vault change log updated: $LOG_FILE"
|
echo "Vault change log updated: $LOG_FILE"
|
||||||
|
|||||||
+45
-22
@@ -1,43 +1,66 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Zero-token vault sync protocol
|
# Zero-token vault publish.
|
||||||
# Commit local changes, rebase onto the remote, push to the Gitea mirror.
|
|
||||||
#
|
#
|
||||||
# SCOPE: only the agent-os vault tree is staged. The git repo root is the PARENT
|
# SOURCE OF TRUTH : /c/Users/fight/Documents/Obsidian Vault
|
||||||
# directory (AgentOS), so a bare `git add -A` sweeps unrelated agent work into
|
# MIRROR (git) : C:/Users/fight/AgentOS/memory-systems/agent-os
|
||||||
# "vault-sync" commits. Both the status check and the add are pathspec-scoped.
|
# REMOTE : Tony_tech/personal-agent-os
|
||||||
#
|
#
|
||||||
# ORDER: commit BEFORE `git pull --rebase`. Rebase refuses to run on a dirty tree,
|
# The mirror is a generated byte copy of the vault, so the Obsidian vault is
|
||||||
# so pulling first is a silent no-op exactly when a pull is needed, and the
|
# backed up to Gitea without a second *writable* copy that could drift.
|
||||||
# subsequent push gets rejected.
|
# 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
|
# SCOPE: only the mirror subtree is staged. The AgentOS repo root holds unrelated
|
||||||
# shared by every agent profile, so a repo-local user.name attributes every agent's
|
# agent work (agent-comms/, knowledge-base/, scripts/, ...) that must not be
|
||||||
# commits to one agent. Override with VAULT_AGENT=<name>.
|
# swept into vault commits — a bare `git add -A` would do exactly that.
|
||||||
# NOTE: set VAULT_AGENT (or edit the default) in your own profile's copy.
|
# 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}"
|
AGENT_NAME="${VAULT_AGENT:-jimmy}"
|
||||||
GIT_ID=(-c "user.name=$AGENT_NAME" -c "user.email=$AGENT_NAME@hermes.local")
|
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) ==="
|
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
|
if [ -n "$(git status --porcelain .)" ]; then
|
||||||
echo "Local changes detected. Committing..."
|
|
||||||
git add -A . || exit 1
|
git add -A . || exit 1
|
||||||
git "${GIT_ID[@]}" commit -m "vault-sync: $(date '+%Y-%m-%d %H:%M') ($AGENT_NAME)" 2>&1 | tail -3
|
git "${GIT_ID[@]}" commit -q -m "vault: $(date '+%Y-%m-%d %H:%M') ($AGENT_NAME)" \
|
||||||
else
|
&& echo "Vault history: committed local changes."
|
||||||
echo "No local changes."
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 2. Rebase onto the remote. --autostash so unrelated dirty files elsewhere in the
|
# 2. Publish the vault into the git mirror.
|
||||||
# repo (AgentOS holds more than this vault) cannot block the pull.
|
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..."
|
echo "Pulling latest..."
|
||||||
git pull --rebase --autostash 2>&1 | tail -3
|
git pull --rebase --autostash 2>&1 | tail -3
|
||||||
|
|
||||||
# 3. Push to remote.
|
# 5. Push to remote.
|
||||||
echo "Pushing to Gitea..."
|
echo "Pushing to Gitea..."
|
||||||
git push 2>&1 | tail -3
|
git push 2>&1 | tail -3
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user