# gov_pipeline_interactive_write_v1.0.ps1 (v1.0.4) # Preview -> Prompt O/N -> Real write (ingest + emit) + post-hook + acceptance # 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.3.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){ $null = & powershell -NoProfile -ExecutionPolicy Bypass -File $path @argv; return [int]$LASTEXITCODE } function Run-Tool-Write([string]$path,[string[]]$argv){ try{ $null = & powershell -NoProfile -ExecutionPolicy Bypass -File $path @($argv + '-Execute'); return [int]$LASTEXITCODE }catch{} try{ $null = & powershell -NoProfile -ExecutionPolicy Bypass -File $path @($argv + '-Preview:$false'); return [int]$LASTEXITCODE }catch{} $null = & powershell -NoProfile -ExecutionPolicy Bypass -File $path @argv; return [int]$LASTEXITCODE } Write-Host '== GOV PIPELINE :: INTERACTIVE WRITE v1.0 ==' Write-Host ("Root : {0}" -f $Root) $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) Write-Host 'BootPack : PREVIEW plan ->' if(Exists $emit){ $null = Run-Tool $emit @($Root) } else { Write-Host ("[WARN] emitter not found: {0}" -f $emit) } Write-Host '----------------------------------------------------------------' if(-not $NoPrompt){ $resp = Read-Host 'Ecrire maintenant ? (O/N)'; if($resp -notmatch '^[OoYy]'){ Write-Host '[ABORT] no write.'; exit 0 } } # -- REAL EXECUTION ----------------------------------------------------- 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] nothing to ingest (empty inbox or tool missing).' } if(Exists $emit){ Write-Host '[EMIT] BootPack (real write)...' $rc = Run-Tool-Write $emit @($Root) if($rc -ne 0){ Write-Host ("[FAIL] emit rc={0}" -f $rc); exit $rc } } Write-Host '[POST] Pointer refresh + acceptance...' if(Exists $posthk){ $rc = Run-Tool $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 not found: {0}" -f $posthk) } if(Exists $accept){ Write-Host '[CHECK] final acceptance PTR...' $rc = Run-Tool $accept @($Root) if($rc -ne 0){ Write-Host ("[FAIL] acceptance rc={0}" -f $rc); exit $rc } } # -- SUMMARY ------------------------------------------------------------ $left = 0 if(Exists $inbox){ $left = (Get-ChildItem -LiteralPath $inbox -Filter 'AUTO_*.txt' -ErrorAction SilentlyContinue).Count } Write-Host ("Inbox left : {0}" -f $left) Get-Item (Join-Path $Root 'bootpack\bootpack_paste.txt'), (Join-Path $Root 'bootpack\bootpack.txt') | Select-Object Name, Length, LastWriteTime | Format-Table -AutoSize Write-Host '[DONE] interactive pipeline applied successfully.'