microsoft/hve-core
Publicmirrored from https://github.com/microsoft/hve-coreAvailable
.github/skills/installer/hve-core-installer/scripts/agent-copy.ps1
84lines · modecode
| 1 | # Copyright (c) Microsoft Corporation. |
| 2 | # SPDX-License-Identifier: MIT |
| 3 | <# |
| 4 | .SYNOPSIS |
| 5 | Copies selected HVE-Core agents to the target repository. |
| 6 | .DESCRIPTION |
| 7 | Creates .github/agents/ directory, copies agent files, computes SHA256 hashes, |
| 8 | and writes .hve-tracking.json manifest for upgrade tracking. |
| 9 | .PARAMETER HveCoreBasePath |
| 10 | Root path of the local HVE-Core clone used as the copy source. |
| 11 | .PARAMETER CollectionId |
| 12 | Collection identifier recorded in the tracking manifest. |
| 13 | .PARAMETER FilesToCopy |
| 14 | Array of agent file paths relative to the source agents directory. |
| 15 | .PARAMETER KeepExisting |
| 16 | When set, existing files listed in Collisions are preserved instead of overwritten. |
| 17 | .PARAMETER Collisions |
| 18 | Array of target file paths that already exist and may conflict. |
| 19 | .EXAMPLE |
| 20 | ./scripts/agent-copy.ps1 -HveCoreBasePath ../hve-core -CollectionId hve-core -FilesToCopy @('hve-core/task-researcher.agent.md') |
| 21 | .OUTPUTS |
| 22 | Per-file copy status and manifest creation confirmation. |
| 23 | #> |
| 24 | [CmdletBinding()] |
| 25 | param( |
| 26 | [Parameter(Mandatory)] |
| 27 | [ValidateScript({ Test-Path $_ })] |
| 28 | [string]$HveCoreBasePath, |
| 29 | |
| 30 | [Parameter(Mandatory)] |
| 31 | [ValidateNotNullOrEmpty()] |
| 32 | [string]$CollectionId, |
| 33 | |
| 34 | [Parameter(Mandatory)] |
| 35 | [ValidateNotNullOrEmpty()] |
| 36 | [string[]]$FilesToCopy, |
| 37 | |
| 38 | [Parameter()] |
| 39 | [switch]$KeepExisting, |
| 40 | |
| 41 | [Parameter()] |
| 42 | [string[]]$Collisions = @() |
| 43 | ) |
| 44 | |
| 45 | $ErrorActionPreference = 'Stop' |
| 46 | |
| 47 | $sourceBase = "$hveCoreBasePath/.github/agents" |
| 48 | $targetDir = ".github/agents" |
| 49 | $manifestPath = ".hve-tracking.json" |
| 50 | |
| 51 | # Create target directory |
| 52 | if (-not (Test-Path $targetDir)) { |
| 53 | New-Item -ItemType Directory -Path $targetDir -Force | Out-Null |
| 54 | Write-Host "✅ Created $targetDir" |
| 55 | } |
| 56 | |
| 57 | # Initialize manifest |
| 58 | $manifest = @{ |
| 59 | source = "microsoft/hve-core" |
| 60 | version = (Get-Content "$hveCoreBasePath/package.json" | ConvertFrom-Json).version |
| 61 | installed = (Get-Date -Format "o") |
| 62 | collection = $collectionId # "hve-core" or collection id(s) e.g. "developer" or "developer,devops" |
| 63 | files = @{}; skip = @() |
| 64 | } |
| 65 | |
| 66 | # Copy files (source paths are relative to agents/, target is flat) |
| 67 | foreach ($file in $filesToCopy) { |
| 68 | $fileName = Split-Path $file -Leaf |
| 69 | $sourcePath = Join-Path $sourceBase $file |
| 70 | $targetPath = Join-Path $targetDir $fileName |
| 71 | $relPath = ".github/agents/$fileName" |
| 72 | |
| 73 | if ($keepExisting -and $collisions -contains $targetPath) { |
| 74 | Write-Host "⏭️ Kept existing: $fileName"; continue |
| 75 | } |
| 76 | |
| 77 | Set-Content -Path $targetPath -Value (Get-Content $sourcePath -Raw) -NoNewline |
| 78 | $hash = (Get-FileHash -Path $targetPath -Algorithm SHA256).Hash.ToLower() |
| 79 | $manifest.files[$relPath] = @{ version = $manifest.version; sha256 = $hash; status = "managed" } |
| 80 | Write-Host "✅ Copied $fileName" |
| 81 | } |
| 82 | |
| 83 | $manifest | ConvertTo-Json -Depth 10 | Set-Content $manifestPath |
| 84 | Write-Host "✅ Created $manifestPath" |
| 85 | |