#!/usr/bin/env bash

# If we are inside an internal detached worktree (.forum/worktree_meta), we must skip post-checkout
# to prevent vector sync cascades when managing Git internal states.
if [[ "$PWD" == *".forum/worktree_meta"* ]] || [[ "$GIT_DIR" == *".forum/worktree_meta"* ]]; then
    exit 0
fi

# Fetch the meta-state branch silently in the background
git fetch origin meta-state:meta-state --quiet 2>/dev/null || true

# Synchronize the vector databases using the delta replay engine
deno run -A .forum/src/core/replay_engine.ts --sync
