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

@@ -13,7 +13,6 @@ $HeartbeatFile = Join-Path $PublicStateDir "heartbeat-pc.json"
$ErrorFile = Join-Path $PublicStateDir "error-pc.md"
$AllowedPaths = @(
"AGENT_BOARD.md",
"USER_STATUS.md",
"README.md",
".cursor/rules",
"handoff",
@@ -67,6 +66,26 @@ function Invoke-Git {
}
}
function Remove-StaleSyncError {
if (Test-Path $ErrorFile) {
Remove-Item $ErrorFile -Force
}
}
function Push-WithRetry {
& git push
if ($LASTEXITCODE -eq 0) {
return
}
# Another agent may have pushed between our pull and push. Rebase once and retry.
Invoke-Git @("pull", "--rebase", "--autostash")
if (Test-ConflictMarkers) {
throw "merge or rebase conflicts detected after push retry"
}
Invoke-Git @("push")
}
function Get-AllowedChanges {
$changes = & git -C $RepoRoot status --porcelain
if ($LASTEXITCODE -ne 0) {
@@ -148,6 +167,7 @@ function Sync-Once {
throw "merge or rebase conflicts detected"
}
Remove-StaleSyncError
Write-Heartbeat
$allowedChanges = @(Get-AllowedChanges)
@@ -171,15 +191,12 @@ function Sync-Once {
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
Invoke-Git @("commit", "-m", "Sync agent state from PC at $timestamp")
Invoke-Git @("push")
Push-WithRetry
}
do {
try {
Sync-Once
if (Test-Path $ErrorFile) {
Remove-Item $ErrorFile -Force
}
}
catch {
Write-SyncError $_.Exception.Message