# Refresh the MACHINE-LOCAL mirror of the Curabis BCQuality knowledge base. # # v2 - GIT-BASED (privat repo): al konsumtion sker via en kanal-klon i # %USERPROFILE%\.claude\QualityHub (pinned til stable-branchen) # Autentificering haandteres af Git Credential Manager - ingen raw-URLs, # ingen GitHub API, ingen CDN-cache. Foerste koersel udloeser evt. et # GCM-login i browseren; det ER onboarding-autentificeringen. # # Mirrors three layers into %USERPROFILE%\.claude\bcquality-knowledge: # custom/ - Curabis org-specific rules (ALWAYS read in full each session) # community/ - BC community patterns (loaded on relevance via INDEX.md) # microsoft/ - platform guardrails (loaded on relevance via INDEX.md) # ...plus INDEX.md (domain + keywords per fil) og opdaterer versionsmarkoeren. # # Mirroren committes ALDRIG til et projekt-repo - se BCQuality-reglen # bcquality-knowledge-must-mirror-to-machine-not-repo. Koer periodisk: # powershell -ExecutionPolicy Bypass -File "$env:USERPROFILE\.claude\sync-bcquality-knowledge.ps1" $ErrorActionPreference = 'Stop' $repoUrl = 'https://github.com/Curabis/QualityHub.git' $clone = Join-Path $env:USERPROFILE '.claude\QualityHub' $dest = Join-Path $env:USERPROFILE '.claude\bcquality-knowledge' $marker = Join-Path $env:USERPROFILE '.claude\.bcquality-version' $staging = "$dest.tmp" # --- 1. Kanal-klon: opret eller opdater (pinned til stable) --- if (-not (Test-Path (Join-Path $clone '.git'))) { Write-Host "Kanal-klon mangler - kloner stable fra $repoUrl ..." git clone --branch stable --single-branch $repoUrl $clone if ($LASTEXITCODE -ne 0) { throw "git clone fejlede - er du autentificeret (GCM), og har du adgang til repoet?" } } else { git -C $clone fetch origin stable --quiet if ($LASTEXITCODE -ne 0) { throw "git fetch fejlede - tjek netvaerk/adgang." } git -C $clone checkout -B stable origin/stable --quiet } $sha = (git -C $clone rev-parse HEAD).Trim() Write-Host "Kanal-klon paa stable @ $($sha.Substring(0,7))" # --- 2. Byg mirror fra klonens filer (ingen netvaerk herfra) --- $layerMap = [ordered]@{ 'custom\knowledge' = 'custom' 'community\knowledge' = 'community' 'microsoft\knowledge' = 'microsoft' } function Get-Frontmatter { param([string]$Path) $lines = Get-Content -Path $Path $fm = @{} if ($lines.Count -eq 0 -or $lines[0].Trim() -ne '---') { return $fm } for ($i = 1; $i -lt $lines.Count; $i++) { if ($lines[$i].Trim() -eq '---') { break } if ($lines[$i] -match '^\s*([\w-]+):\s*(.*)$') { $fm[$matches[1]] = $matches[2].Trim() } } return $fm } if (Test-Path $staging) { Remove-Item -Recurse -Force $staging } New-Item -ItemType Directory -Force $staging | Out-Null $files = @() foreach ($prefix in $layerMap.Keys) { $srcDir = Join-Path $clone $prefix if (-not (Test-Path $srcDir)) { continue } $layer = $layerMap[$prefix] Get-ChildItem $srcDir -Recurse -Filter *.md | ForEach-Object { $relative = $_.FullName.Substring($srcDir.Length + 1) $localPath = Join-Path $staging (Join-Path $layer $relative) New-Item -ItemType Directory -Force (Split-Path $localPath) | Out-Null Copy-Item $_.FullName $localPath $files += [pscustomobject]@{ Layer = $layer; Relative = $relative; LocalPath = $localPath } } } if ($files.Count -eq 0) { throw 'Ingen knowledge-filer fundet i kanal-klonen - afbryder.' } # --- 3. INDEX.md (relevans-indeks for alle lag) --- $idx = [System.Collections.Generic.List[string]]::new() $idx.Add('# BCQuality Knowledge Index') $idx.Add('') $idx.Add('') $idx.Add('') $idx.Add('Layers: `custom` is ALWAYS read in full each session. For `community` and') $idx.Add('`microsoft`, scan this index and read only the files whose domain/keywords') $idx.Add('match the task at hand.') $idx.Add('') foreach ($layer in @('custom', 'community', 'microsoft')) { $layerFiles = $files | Where-Object { $_.Layer -eq $layer } | Sort-Object Relative if (-not $layerFiles) { continue } $note = if ($layer -eq 'custom') { ' (always-on)' } else { ' (load on relevance)' } $idx.Add("## $layer$note") $idx.Add('') foreach ($f in $layerFiles) { $fm = Get-Frontmatter $f.LocalPath $domain = if ($fm.ContainsKey('domain')) { $fm['domain'] } else { '' } $keywords = if ($fm.ContainsKey('keywords')) { $fm['keywords'].Trim('[', ']') } else { '' } $rel = ($f.Relative -replace '\.md$', '') -replace '\\', '/' $idx.Add("- ``$layer/$rel`` - domain: $domain; keywords: $keywords") } $idx.Add('') } Set-Content -Path (Join-Path $staging 'INDEX.md') -Value $idx -Encoding utf8 # --- 4. Swap + markoer --- if (Test-Path $dest) { Remove-Item -Recurse -Force $dest } Rename-Item -Path $staging -NewName (Split-Path $dest -Leaf) Set-Content -Path $marker -Value $sha -Encoding ascii Write-Host '' Write-Host "Done. $($files.Count) filer, 3 lag, stable @ $($sha.Substring(0,7))." Write-Host "Machine-local mirror updated: $dest"