??# maint_mem_sync_governanceorder.ps1 # Objet : Synchroniser la r?gle [GOVERNANCE-ORDER-OF-OPERATIONS_v1.2] # Auteur : GPT-5 + USER - ChatGPT-Gouvernance-Projets # Encodage : UTF-8 sans BOM # Version : 1.1 (reconstruction + conformit? archiviste) # ========================= # [CONFIG] # ========================= $RegistryDir = "\\DS-918\chatgpt\ChatGPT-Gouvernance-Projets\_registry" $RuleFile = Join-Path $RegistryDir "rules\GOVERNANCE-ORDER-OF-OPERATIONS_v1.2.txt" $IndexGlobalFile = Join-Path $RegistryDir "INDEX_GOUVERNANCE_GLOBAL.txt" $SnapshotFile = Join-Path $RegistryDir "snapshot_2025-10-15.json" $RegistryLogPath = "C:\Logs_Gouvernance\registry_activity.log" # ========================= # [FONCTIONS] # ========================= function Get-Timestamp { (Get-Date).ToString("yyyy-MM-dd HH:mm:ss") } function Append-Log { param([string]$LogPath,[string]$Line) $dir = Split-Path -Parent $LogPath if (-not (Test-Path $dir)) { New-Item -ItemType Directory -Path $dir -Force | Out-Null } $ts = Get-Timestamp Add-Content -Path $LogPath -Value "$ts | $Line" -Encoding UTF8 } function Compute-SHA1 { param([string]$Path) if (-not (Test-Path $Path)) { return "N/A" } return (Get-FileHash -Path $Path -Algorithm SHA1).Hash } # ========================= # [PREVIEW] # ========================= Write-Host "=== [PREVIEW] SYNCHRONISATION GOVERNANCE-ORDER-OF-OPERATIONS_v1.2 ===" Write-Host "[PLAN] Fichier de r?gle : $RuleFile" Write-Host "[PLAN] Index global : $IndexGlobalFile" Write-Host "[PLAN] Snapshot JSON : $SnapshotFile" Write-Host "[PLAN] Journalisation : $RegistryLogPath" $confirm = Read-Host "Confirmer la synchronisation ? (O/N)" if ($confirm -notin @('O','o','Y','y')) { Write-Host "[ABORT] Op?ration annul?e par l'utilisateur." return } # ========================= # [EXECUTION] # ========================= try { if (-not (Test-Path $RuleFile)) { Write-Host "[ERROR] Fichier de r?gle introuvable : $RuleFile" return } $ts = Get-Timestamp $sha1 = Compute-SHA1 $RuleFile # --- Mise ? jour INDEX GLOBAL --- $entry = "[$ts] GOVERNANCE-ORDER-OF-OPERATIONS_v1.2 | SHA1=$sha1 | $RuleFile" if (Test-Path $IndexGlobalFile) { Add-Content -Path $IndexGlobalFile -Value $entry -Encoding UTF8 Write-Host "[OK] Index global mis ? jour." } else { [IO.File]::WriteAllText($IndexGlobalFile, $entry, (New-Object Text.UTF8Encoding($false))) Write-Host "[OK] Index global cr??." } # --- Mise ? jour SNAPSHOT JSON --- $utf8NoBom = New-Object System.Text.UTF8Encoding($false) $json = @{} if (Test-Path $SnapshotFile) { try { $json = Get-Content -Path $SnapshotFile -Raw -Encoding UTF8 | ConvertFrom-Json } catch { $json = @{} } } # Assurer la pr?sence de "rules" sous forme de tableau if (-not $json.PSObject.Properties.Match('rules')) { $json | Add-Member -NotePropertyName "rules" -NotePropertyValue @() } elseif ($json.rules -isnot [System.Collections.IEnumerable]) { $json.rules = @($json.rules) } # Supprimer doublon et ajouter l'entr?e $json.rules = @($json.rules | Where-Object { $_.name -ne "GOVERNANCE-ORDER-OF-OPERATIONS_v1.2" }) $json.rules += [PSCustomObject]@{ name = "GOVERNANCE-ORDER-OF-OPERATIONS_v1.2" version = "1.2" sha1 = $sha1 date_added = $ts } # Sauvegarde du JSON mis ? jour $json | ConvertTo-Json -Depth 5 | Out-File -FilePath $SnapshotFile -Encoding UTF8 Write-Host "[OK] Snapshot mis ? jour : $SnapshotFile" # --- Journalisation --- Append-Log $RegistryLogPath "MEM_SYNC | GOVERNANCE-ORDER-OF-OPERATIONS_v1.2 | sha1=$sha1" Write-Host "[DONE] Synchronisation termin?e avec succ?s." } catch { Write-Host "[ERROR] " + $_.Exception.Message }