Sync agent state from PC at 2026-05-15 16:32:18

This commit is contained in:
wangzhendong
2026-05-15 16:32:18 +08:00
parent 8e12d018dd
commit c090ee8359
11 changed files with 71 additions and 86 deletions

View File

@@ -14,7 +14,6 @@ ERROR_FILE="$PUBLIC_STATE_DIR/error-vps.md"
ALLOWED_PATHS=(
"AGENT_BOARD.md"
"USER_STATUS.md"
"README.md"
".cursor/rules"
"handoff"
@@ -110,6 +109,23 @@ has_conflicts() {
[[ -n "$(git diff --name-only --diff-filter=U)" ]]
}
remove_stale_sync_error() {
rm -f "$ERROR_FILE"
}
push_with_retry() {
if git push; then
return 0
fi
# Another agent may have pushed between our pull and push. Rebase once and retry.
git pull --rebase --autostash
if has_conflicts; then
return 20
fi
git push
}
sync_once() {
cd "$REPO_ROOT"
ensure_state_dir
@@ -120,6 +136,7 @@ sync_once() {
return 20
fi
remove_stale_sync_error
write_heartbeat
if ! has_allowed_changes; then
@@ -138,13 +155,11 @@ sync_once() {
fi
git commit -m "Sync agent state from VPS at $(date '+%Y-%m-%d %H:%M:%S')"
git push
push_with_retry
}
while true; do
if sync_once; then
rm -f "$ERROR_FILE"
else
if ! sync_once; then
exit_code="$?"
write_sync_error "sync failed with exit code $exit_code"
echo "sync failed with exit code $exit_code" >&2