#!/usr/bin/env bash
set -euo pipefail
root="$(git rev-parse --show-toplevel)"
manifest="$root/x/agent-git-service.UPSTREAM"
source_url="$(sed -n 's/^source=//p' "$manifest")"
commit="$(sed -n 's/^commit=//p' "$manifest")"
"$root/guardrails/ags/check-upstream-provenance.sh"
work="$(mktemp -d "${TMPDIR:-/tmp}/agentteam-ags-upstream.XXXXXX")"
trap 'rm -rf "$work"' EXIT
git -C "$work" init -q
git -C "$work" fetch -q --depth=1 "$source_url" "$commit"
git -C "$work" archive FETCH_HEAD | tar -x -C "$work"
# This command intentionally only refreshes the canonical snapshot. Embedding
# adapters are reviewed as an explicit overlay and must not be copied blindly.
rsync -a --delete --exclude='.git' "$work/" "$root/x/agent-git-service/"
echo "refreshed x/agent-git-service from $source_url@$commit"
echo "now re-apply/review the bounded MeshX embedding overlay and run AGS + MeshX tests"
