Files
infra-plugins/plugins/shared-vault-sync/hooks/pull-shared-vault.sh
Adnan Zahir 1bd000e595 feat(shared-vault-sync): sync the nested devops-shared-vault subrepo
Detection order is now SHARED_VAULT_DIR, then $PWD, then $PWD/Areas/DevOps
(the nested shared subrepo inside the personal vault). Bump to 0.1.1.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-09-01 10:15:35 +07:00

43 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# Pull only the designated shared vault; never block a new agent session.
set -u
emit() {
printf '{"continue":true,"suppressOutput":true,"hookSpecificOutput":{"additionalContext":"%s"}}\n' "$1"
}
is_shared_vault() {
[ -f "$1/AGENTS.md" ] \
&& grep -Fq 'This is the shared persistent vault' "$1/AGENTS.md" \
&& git -C "$1" rev-parse --is-inside-work-tree >/dev/null 2>&1
}
detect_vault() {
# explicit override wins
if [ -n "${SHARED_VAULT_DIR:-}" ]; then
is_shared_vault "$SHARED_VAULT_DIR" && { printf '%s' "$SHARED_VAULT_DIR"; return 0; }
return 1
fi
# session started inside the shared vault itself
if is_shared_vault "${PWD:-}"; then printf '%s' "${PWD:-}"; return 0; fi
# nested shared subrepo relative to the session dir (e.g. personal vault's Areas/DevOps)
if is_shared_vault "${PWD:-}/Areas/DevOps"; then printf '%s' "${PWD:-}/Areas/DevOps"; return 0; fi
return 1
}
vault_dir="$(detect_vault)" || {
emit 'Shared vault sync skipped: no shared vault detected (set SHARED_VAULT_DIR, or start the session from the shared vault or its Areas/DevOps subrepo).'
exit 0
}
if [ -n "$(git -C "$vault_dir" status --porcelain)" ]; then
emit 'Shared vault sync skipped: the worktree has local changes.'
exit 0
fi
if GIT_TERMINAL_PROMPT=0 git -C "$vault_dir" pull --ff-only --quiet; then
emit 'Shared vault sync completed.'
else
emit 'Shared vault sync failed; run git pull --ff-only from the vault when it is safe to do so.'
fi