diff --git a/tools/observer/autosync.sh b/tools/observer/autosync.sh new file mode 100755 index 000000000..48cb9b05f --- /dev/null +++ b/tools/observer/autosync.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# Keeps the shared checkout's observer and public API in step with origin/master, so a change an agent pushed to +# tools/observer or site/api is running here within five minutes (4 October 2026: the live API said "observer has +# not reported the proving layer" for an hour because the shared checkout was three commits behind origin). +# Fast-forwards only; if the shared checkout is ahead or dirty in those paths it logs and waits for a human. +# Loop: tools/observer/autosync.sh (log: /tmp/igneum-devnet/autosync.out) +cd "$(dirname "$0")/../.." || exit 1 +LOG=/tmp/igneum-devnet/autosync.out; mkdir -p "$(dirname "$LOG")"; exec >>"$LOG" 2>&1 +PATHS="tools/observer site/api" +while :; do + git fetch -q origin master 2>/dev/null + local_sha=$(git rev-parse HEAD); remote_sha=$(git rev-parse origin/master) + if [ "$local_sha" != "$remote_sha" ]; then + if [ -z "$(git status --porcelain -- $PATHS)" ] && git merge-base --is-ancestor HEAD origin/master; then + changed=$(git diff --name-only HEAD origin/master -- $PATHS) + if git merge -q --ff-only origin/master; then + echo "$(date -u +%FT%TZ) fast-forwarded to $(git rev-parse --short HEAD)" + if [ -n "$changed" ]; then + pid=$(pgrep -f "node tools/observer/observer.mjs" | head -1) + if [ -n "$pid" ]; then kill "$pid" && echo "$(date -u +%FT%TZ) observer $pid restarted for: $(echo "$changed" | tr '\n' ' ')"; fi + fi + else + echo "$(date -u +%FT%TZ) fast-forward failed (local $local_sha, origin $remote_sha)" + fi + else + echo "$(date -u +%FT%TZ) not fast-forwardable or dirty in $PATHS (local $local_sha, origin $remote_sha); waiting" + fi + fi + sleep 300 +done