??param([string]$Root, [switch]$AutoExport=$true) $ErrorActionPreference='Stop' if([string]::IsNullOrWhiteSpace($Root)){ $Root='\\DS-918\chatgpt\ChatGPT-Gouvernance-Projets' } $reg=Join-Path $Root '_registry' $kbJson =Join-Path $reg 'BUG_KB.json' $kbJsonl=Join-Path (Join-Path $reg 'bug_kb') 'BUG_KB.json.txt' $patch =Join-Path (Join-Path $reg '_patches') 'SCRIPT_PATCH_HISTORY.txt' $rules =Join-Path $reg 'rules' $indices=Join-Path $reg 'indices' $snaps =Join-Path $reg 'snapshots' $vers =Join-Path $reg 'VERSIONS_REGISTRY.txt' $boot =Join-Path $reg 'bootpack' $bootTxt=Join-Path $boot 'BOOTPACK.TXT' if(-not ((Test-Path $kbJsonl) -or (Test-Path $kbJson))){ throw 'BOOT-PACK KB missing' } if(-not (Test-Path $patch)){ throw 'BOOT-PACK Patch History missing' } foreach($p in @($rules,$indices,$snaps,$vers)){ if(-not (Test-Path $p)){ throw ('Missing: '+$p) } } $snap=Get-ChildItem $snaps -Filter 'snapshot_*.json' -File|Sort-Object LastWriteTime -Desc|Select-Object -First 1 if(-not $snap){ throw 'No snapshot_*.json' } $times=@() if(Test-Path $kbJsonl){ $times+=(Get-Item $kbJsonl).LastWriteTime } elseif(Test-Path $kbJson){ $times+=(Get-Item $kbJson).LastWriteTime } $times+=(Get-Item $patch).LastWriteTime,(Get-Item $vers).LastWriteTime $times+= (Get-ChildItem $rules -File).LastWriteTime $times+= (Get-ChildItem $indices -File).LastWriteTime $times+= $snap.LastWriteTime $lastSrc=($times|Sort-Object -Desc)[0] if((Test-Path $bootTxt) -and ((Get-Item $bootTxt).LastWriteTime -ge $lastSrc)){ return } if($AutoExport){ $exp=Join-Path (Join-Path $reg 'scripts') 'export_bootpack_txt_v1.1.ps1' if(-not (Test-Path $exp)){ throw 'export_bootpack_txt_v1.1.ps1 not found' } & $exp -Root $Root | Out-Null Set-Content -Path (Join-Path $boot '_NEED_SEND.flag') -Value (Get-Date) -Encoding UTF8 Write-Host 'BOOTPACK.TXT re-exported. Paste it in chat to sync.' return } else { throw 'BOOTPACK.TXT stale' }