# gov_pipeline_interactive_write_v1.0.ps1 # Purpose: Passe standard gouvernance = Preview -> Confirmation O/N -> Ecriture réelle # PS 5.1-safe, UTF-8 no BOM, CRLF, ASCII-safe param( [string]$Root = '\\DS-918\chatgpt\ChatGPT-Gouvernance-Projets\_registry', [switch]$Utf8Console, [switch]$NoPrompt ) if($Utf8Console){ try{ [Console]::OutputEncoding = [Text.Encoding]::UTF8 }catch{} } $scripts = Join-Path $Root 'scripts' $inbox = Join-Path $Root 'updates\inbox\kb' $emit = Join-Path $scripts 'kb_emit_bootpack_dual_v1.1.ps1' $ingest = Join-Path $scripts 'kb_quicklog_and_sync_v1.2.1.ps1' $posthk = Join-Path $scripts 'post_bootpack_pointer_refresh_v1.0.2.ps1' $accept = Join-Path $scripts 'kb_acceptance_tests_v1.0.1.ps1' function Exists([string]$p){ return (-not [string]::IsNullOrWhiteSpace($p)) -and (Test-Path -LiteralPath $p) } function Run-Tool([string]$path,[string[]]$argv){ & powershell -NoProfile -ExecutionPolicy Bypass -File $path @argv return $LASTEXITCODE } function Run-Tool-Write([string]$path,[string[]]$argv){ # Essaie -Execute, sinon -Preview:$false, sinon sans flag $rc = 0 try{ $rc = Run-Tool $path ($argv + @('-Execute')) ; if($rc -eq 0){ return 0 } }catch{} try{ $rc = Run-Tool $path ($argv + @('-Preview:$false')) ; if($rc -eq 0){ return 0 } }catch{} $rc = Run-Tool $path $argv return $rc } Write-Host "== GOV PIPELINE :: INTERACTIVE WRITE v1.0 ==" Write-Host ("Root : {0}" -f $Root) # -- PLAN -------------------------------------------------------------- $countInbox = 0 if(Exists $inbox){ $countInbox = (Get-ChildItem -LiteralPath $inbox -Filter 'AUTO_*.txt' -ErrorAction SilentlyContinue).Count } Write-Host ("KB inbox : {0} AUTO_*.txt" -f $countInbox) if(Exists $emit){ Write-Host "BootPack : PREVIEW plan ->" Run-Tool $emit @($Root) } else { Write-Host "[WARN] Emitter introuvable: $emit" } Write-Host "----------------------------------------------------------------" if(-not $NoPrompt){ $resp = Read-Host "Écrire maintenant ? (O/N)" if($resp -notmatch '^[OoYy]'){ Write-Host "[ABORT] Aucun changement écrit."; exit 0 } } # -- EXECUTION RÉELLE --------------------------------------------------- if($countInbox -gt 0 -and (Exists $ingest)){ Get-ChildItem -LiteralPath $inbox -Filter 'AUTO_*.txt' | ForEach-Object { $f = $_.FullName Write-Host ("[INGEST] {0}" -f $f) $rc = Run-Tool $ingest @('-FromFile',$f,'-Execute') if($rc -ne 0){ Write-Host ("[FAIL] ingest rc={0} : {1}" -f $rc,$f); exit $rc } } } else{ Write-Host "[INFO] Rien à ingérer (inbox vide ou outil manquant)." } if(Exists $emit){ Write-Host "[EMIT] BootPack (écriture réelle)..." $rc = Run-Tool-Write $emit @($Root) if($rc -ne 0){ Write-Host ("[FAIL] emit rc={0}" -f $rc); exit $rc } } if(Exists $posthk){ Write-Host "[POST] Pointer refresh + acceptance..." $rc = Run-Tool-Write $posthk @('-Root',$Root,'-NoPrompt','-Verify') if($rc -ne 0){ Write-Host ("[FAIL] post-hook rc={0}" -f $rc); exit $rc } } else { Write-Host "[WARN] post-hook introuvable: $posthk" } if(Exists $accept){ Write-Host "[CHECK] Acceptance PTR finale..." $rc = Run-Tool $accept @($Root) if($rc -ne 0){ Write-Host ("[FAIL] acceptance rc={0}" -f $rc); exit $rc } } Write-Host "[DONE] Interractif : opérations appliquées avec succès."