microsoft/hve-core
Publicmirrored fromhttps://github.com/microsoft/hve-coreAvailable
scripts/extension/Prepare-Extension.ps1
715lines ยท modecode
| 1 | #!/usr/bin/env pwsh |
| 2 | |
| 3 | <# |
| 4 | .SYNOPSIS |
| 5 | Prepares the HVE Core VS Code extension for packaging. |
| 6 | |
| 7 | .DESCRIPTION |
| 8 | This script prepares the VS Code extension by: |
| 9 | - Auto-discovering chat agents, prompts, and instruction files |
| 10 | - Filtering agents by maturity level based on channel |
| 11 | - Updating package.json with discovered components |
| 12 | - Updating changelog if provided |
| 13 | |
| 14 | The package.json version is not modified. |
| 15 | |
| 16 | .PARAMETER ChangelogPath |
| 17 | Optional. Path to a changelog file to include in the package. |
| 18 | |
| 19 | .PARAMETER Channel |
| 20 | Optional. Release channel controlling which maturity levels are included. |
| 21 | 'Stable' (default): Only includes agents with maturity 'stable'. |
| 22 | 'PreRelease': Includes 'stable', 'preview', and 'experimental' maturity levels. |
| 23 | |
| 24 | .PARAMETER DryRun |
| 25 | Optional. If specified, shows what would be done without making changes. |
| 26 | |
| 27 | .EXAMPLE |
| 28 | ./Prepare-Extension.ps1 |
| 29 | # Prepares stable channel using existing version from package.json |
| 30 | |
| 31 | .EXAMPLE |
| 32 | ./Prepare-Extension.ps1 -Channel PreRelease |
| 33 | # Prepares pre-release channel including experimental agents |
| 34 | |
| 35 | .EXAMPLE |
| 36 | ./Prepare-Extension.ps1 -ChangelogPath "./CHANGELOG.md" |
| 37 | # Prepares with changelog |
| 38 | |
| 39 | .NOTES |
| 40 | Dependencies: PowerShell-Yaml module |
| 41 | #> |
| 42 | |
| 43 | [CmdletBinding()] |
| 44 | param( |
| 45 | [Parameter(Mandatory = $false)] |
| 46 | [string]$ChangelogPath = "", |
| 47 | |
| 48 | [Parameter(Mandatory = $false)] |
| 49 | [ValidateSet('Stable', 'PreRelease')] |
| 50 | [string]$Channel = 'Stable', |
| 51 | |
| 52 | [Parameter(Mandatory = $false)] |
| 53 | [switch]$DryRun |
| 54 | ) |
| 55 | |
| 56 | $ErrorActionPreference = "Stop" |
| 57 | |
| 58 | #region Pure Functions |
| 59 | |
| 60 | function Get-AllowedMaturities { |
| 61 | <# |
| 62 | .SYNOPSIS |
| 63 | Returns allowed maturity levels based on release channel. |
| 64 | .DESCRIPTION |
| 65 | Pure function that determines which maturity levels (stable, preview, experimental) |
| 66 | are included in the extension package based on the specified channel. |
| 67 | .PARAMETER Channel |
| 68 | Release channel. 'Stable' returns only stable; 'PreRelease' includes all levels. |
| 69 | .OUTPUTS |
| 70 | [string[]] Array of allowed maturity level strings. |
| 71 | #> |
| 72 | [CmdletBinding()] |
| 73 | [OutputType([string[]])] |
| 74 | param( |
| 75 | [Parameter(Mandatory = $true)] |
| 76 | [ValidateSet('Stable', 'PreRelease')] |
| 77 | [string]$Channel |
| 78 | ) |
| 79 | |
| 80 | if ($Channel -eq 'PreRelease') { |
| 81 | return @('stable', 'preview', 'experimental') |
| 82 | } |
| 83 | return @('stable') |
| 84 | } |
| 85 | |
| 86 | function Get-FrontmatterData { |
| 87 | <# |
| 88 | .SYNOPSIS |
| 89 | Extracts description and maturity from YAML frontmatter. |
| 90 | .DESCRIPTION |
| 91 | Function that parses YAML frontmatter from a markdown file |
| 92 | and returns a hashtable with description and maturity values. |
| 93 | .PARAMETER FilePath |
| 94 | Path to the markdown file to parse. |
| 95 | .PARAMETER FallbackDescription |
| 96 | Default description if none found in frontmatter. |
| 97 | .OUTPUTS |
| 98 | [hashtable] With description and maturity keys. |
| 99 | #> |
| 100 | [CmdletBinding()] |
| 101 | [OutputType([hashtable])] |
| 102 | param( |
| 103 | [Parameter(Mandatory = $true)] |
| 104 | [string]$FilePath, |
| 105 | |
| 106 | [Parameter(Mandatory = $false)] |
| 107 | [string]$FallbackDescription = "" |
| 108 | ) |
| 109 | |
| 110 | $content = Get-Content -Path $FilePath -Raw |
| 111 | $description = "" |
| 112 | $maturity = "stable" |
| 113 | |
| 114 | if ($content -match '(?s)^---\s*\r?\n(.*?)\r?\n---') { |
| 115 | $yamlContent = $Matches[1] -replace '\r\n', "`n" -replace '\r', "`n" |
| 116 | try { |
| 117 | $data = ConvertFrom-Yaml -Yaml $yamlContent |
| 118 | if ($data.ContainsKey('description')) { |
| 119 | $description = $data.description |
| 120 | } |
| 121 | if ($data.ContainsKey('maturity')) { |
| 122 | $maturity = $data.maturity |
| 123 | } |
| 124 | } |
| 125 | catch { |
| 126 | Write-Warning "Failed to parse YAML frontmatter in $(Split-Path -Leaf $FilePath): $_" |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | return @{ |
| 131 | description = if ($description) { $description } else { $FallbackDescription } |
| 132 | maturity = $maturity |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | function Test-PathsExist { |
| 137 | <# |
| 138 | .SYNOPSIS |
| 139 | Validates that required paths exist for extension preparation. |
| 140 | .DESCRIPTION |
| 141 | Validation function that checks whether extension directory, package.json, |
| 142 | and .github directory exist at the specified locations. |
| 143 | .PARAMETER ExtensionDir |
| 144 | Path to the extension directory. |
| 145 | .PARAMETER PackageJsonPath |
| 146 | Path to package.json file. |
| 147 | .PARAMETER GitHubDir |
| 148 | Path to .github directory. |
| 149 | .OUTPUTS |
| 150 | [hashtable] With IsValid bool, MissingPaths array, and ErrorMessages array. |
| 151 | #> |
| 152 | [CmdletBinding()] |
| 153 | [OutputType([hashtable])] |
| 154 | param( |
| 155 | [Parameter(Mandatory = $true)] |
| 156 | [string]$ExtensionDir, |
| 157 | |
| 158 | [Parameter(Mandatory = $true)] |
| 159 | [string]$PackageJsonPath, |
| 160 | |
| 161 | [Parameter(Mandatory = $true)] |
| 162 | [string]$GitHubDir |
| 163 | ) |
| 164 | |
| 165 | $missingPaths = @() |
| 166 | $errorMessages = @() |
| 167 | |
| 168 | if (-not (Test-Path $ExtensionDir)) { |
| 169 | $missingPaths += $ExtensionDir |
| 170 | $errorMessages += "Extension directory not found: $ExtensionDir" |
| 171 | } |
| 172 | if (-not (Test-Path $PackageJsonPath)) { |
| 173 | $missingPaths += $PackageJsonPath |
| 174 | $errorMessages += "package.json not found: $PackageJsonPath" |
| 175 | } |
| 176 | if (-not (Test-Path $GitHubDir)) { |
| 177 | $missingPaths += $GitHubDir |
| 178 | $errorMessages += ".github directory not found: $GitHubDir" |
| 179 | } |
| 180 | |
| 181 | return @{ |
| 182 | IsValid = ($missingPaths.Count -eq 0) |
| 183 | MissingPaths = $missingPaths |
| 184 | ErrorMessages = $errorMessages |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | function Get-DiscoveredAgents { |
| 189 | <# |
| 190 | .SYNOPSIS |
| 191 | Discovers chat agent files from the agents directory. |
| 192 | .DESCRIPTION |
| 193 | Discovery function that scans the agents directory for .agent.md files, |
| 194 | extracts frontmatter data, filters by maturity and exclusion list, |
| 195 | and returns structured agent objects. |
| 196 | .PARAMETER AgentsDir |
| 197 | Path to the agents directory. |
| 198 | .PARAMETER AllowedMaturities |
| 199 | Array of maturity levels to include. |
| 200 | .PARAMETER ExcludedAgents |
| 201 | Array of agent names to exclude from packaging. |
| 202 | .OUTPUTS |
| 203 | [hashtable] With Agents array, Skipped array, and DirectoryExists bool. |
| 204 | #> |
| 205 | [CmdletBinding()] |
| 206 | [OutputType([hashtable])] |
| 207 | param( |
| 208 | [Parameter(Mandatory = $true)] |
| 209 | [string]$AgentsDir, |
| 210 | |
| 211 | [Parameter(Mandatory = $true)] |
| 212 | [string[]]$AllowedMaturities, |
| 213 | |
| 214 | [Parameter(Mandatory = $false)] |
| 215 | [string[]]$ExcludedAgents = @() |
| 216 | ) |
| 217 | |
| 218 | $result = @{ |
| 219 | Agents = @() |
| 220 | Skipped = @() |
| 221 | DirectoryExists = (Test-Path $AgentsDir) |
| 222 | } |
| 223 | |
| 224 | if (-not $result.DirectoryExists) { |
| 225 | return $result |
| 226 | } |
| 227 | |
| 228 | $agentFiles = Get-ChildItem -Path $AgentsDir -Filter "*.agent.md" | Sort-Object Name |
| 229 | |
| 230 | foreach ($agentFile in $agentFiles) { |
| 231 | $agentName = $agentFile.BaseName -replace '\.agent$', '' |
| 232 | |
| 233 | if ($ExcludedAgents -contains $agentName) { |
| 234 | $result.Skipped += @{ Name = $agentName; Reason = 'excluded' } |
| 235 | continue |
| 236 | } |
| 237 | |
| 238 | $frontmatter = Get-FrontmatterData -FilePath $agentFile.FullName -FallbackDescription "AI agent for $agentName" |
| 239 | $maturity = $frontmatter.maturity |
| 240 | |
| 241 | if ($AllowedMaturities -notcontains $maturity) { |
| 242 | $result.Skipped += @{ Name = $agentName; Reason = "maturity: $maturity" } |
| 243 | continue |
| 244 | } |
| 245 | |
| 246 | $result.Agents += [PSCustomObject]@{ |
| 247 | name = $agentName |
| 248 | path = "./.github/agents/$($agentFile.Name)" |
| 249 | description = $frontmatter.description |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | return $result |
| 254 | } |
| 255 | |
| 256 | function Get-DiscoveredPrompts { |
| 257 | <# |
| 258 | .SYNOPSIS |
| 259 | Discovers prompt files from the prompts directory. |
| 260 | .DESCRIPTION |
| 261 | Discovery function that scans the prompts directory for .prompt.md files, |
| 262 | extracts frontmatter data, filters by maturity, and returns structured |
| 263 | prompt objects with relative paths. |
| 264 | .PARAMETER PromptsDir |
| 265 | Path to the prompts directory. |
| 266 | .PARAMETER GitHubDir |
| 267 | Path to the .github directory for relative path calculation. |
| 268 | .PARAMETER AllowedMaturities |
| 269 | Array of maturity levels to include. |
| 270 | .OUTPUTS |
| 271 | [hashtable] With Prompts array, Skipped array, and DirectoryExists bool. |
| 272 | #> |
| 273 | [CmdletBinding()] |
| 274 | [OutputType([hashtable])] |
| 275 | param( |
| 276 | [Parameter(Mandatory = $true)] |
| 277 | [string]$PromptsDir, |
| 278 | |
| 279 | [Parameter(Mandatory = $true)] |
| 280 | [string]$GitHubDir, |
| 281 | |
| 282 | [Parameter(Mandatory = $true)] |
| 283 | [string[]]$AllowedMaturities |
| 284 | ) |
| 285 | |
| 286 | $result = @{ |
| 287 | Prompts = @() |
| 288 | Skipped = @() |
| 289 | DirectoryExists = (Test-Path $PromptsDir) |
| 290 | } |
| 291 | |
| 292 | if (-not $result.DirectoryExists) { |
| 293 | return $result |
| 294 | } |
| 295 | |
| 296 | $promptFiles = Get-ChildItem -Path $PromptsDir -Filter "*.prompt.md" -Recurse | Sort-Object Name |
| 297 | |
| 298 | foreach ($promptFile in $promptFiles) { |
| 299 | $promptName = $promptFile.BaseName -replace '\.prompt$', '' |
| 300 | $displayName = ($promptName -replace '-', ' ') -replace '(\b\w)', { $_.Groups[1].Value.ToUpper() } |
| 301 | $frontmatter = Get-FrontmatterData -FilePath $promptFile.FullName -FallbackDescription "Prompt for $displayName" |
| 302 | $maturity = $frontmatter.maturity |
| 303 | |
| 304 | if ($AllowedMaturities -notcontains $maturity) { |
| 305 | $result.Skipped += @{ Name = $promptName; Reason = "maturity: $maturity" } |
| 306 | continue |
| 307 | } |
| 308 | |
| 309 | $relativePath = [System.IO.Path]::GetRelativePath($GitHubDir, $promptFile.FullName) -replace '\\', '/' |
| 310 | |
| 311 | $result.Prompts += [PSCustomObject]@{ |
| 312 | name = $promptName |
| 313 | path = "./.github/$relativePath" |
| 314 | description = $frontmatter.description |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | return $result |
| 319 | } |
| 320 | |
| 321 | function Get-DiscoveredInstructions { |
| 322 | <# |
| 323 | .SYNOPSIS |
| 324 | Discovers instruction files from the instructions directory. |
| 325 | .DESCRIPTION |
| 326 | Discovery function that scans the instructions directory for .instructions.md files, |
| 327 | extracts frontmatter data, filters by maturity, and returns structured |
| 328 | instruction objects with normalized paths. |
| 329 | .PARAMETER InstructionsDir |
| 330 | Path to the instructions directory. |
| 331 | .PARAMETER GitHubDir |
| 332 | Path to the .github directory for relative path calculation. |
| 333 | .PARAMETER AllowedMaturities |
| 334 | Array of maturity levels to include. |
| 335 | .OUTPUTS |
| 336 | [hashtable] With Instructions array, Skipped array, and DirectoryExists bool. |
| 337 | #> |
| 338 | [CmdletBinding()] |
| 339 | [OutputType([hashtable])] |
| 340 | param( |
| 341 | [Parameter(Mandatory = $true)] |
| 342 | [string]$InstructionsDir, |
| 343 | |
| 344 | [Parameter(Mandatory = $true)] |
| 345 | [string]$GitHubDir, |
| 346 | |
| 347 | [Parameter(Mandatory = $true)] |
| 348 | [string[]]$AllowedMaturities |
| 349 | ) |
| 350 | |
| 351 | $result = @{ |
| 352 | Instructions = @() |
| 353 | Skipped = @() |
| 354 | DirectoryExists = (Test-Path $InstructionsDir) |
| 355 | } |
| 356 | |
| 357 | if (-not $result.DirectoryExists) { |
| 358 | return $result |
| 359 | } |
| 360 | |
| 361 | $instructionFiles = Get-ChildItem -Path $InstructionsDir -Filter "*.instructions.md" -Recurse | Sort-Object Name |
| 362 | |
| 363 | foreach ($instrFile in $instructionFiles) { |
| 364 | $baseName = $instrFile.BaseName -replace '\.instructions$', '' |
| 365 | $instrName = "$baseName-instructions" |
| 366 | $displayName = ($baseName -replace '-', ' ') -replace '(\b\w)', { $_.Groups[1].Value.ToUpper() } |
| 367 | $frontmatter = Get-FrontmatterData -FilePath $instrFile.FullName -FallbackDescription "Instructions for $displayName" |
| 368 | $maturity = $frontmatter.maturity |
| 369 | |
| 370 | if ($AllowedMaturities -notcontains $maturity) { |
| 371 | $result.Skipped += @{ Name = $instrName; Reason = "maturity: $maturity" } |
| 372 | continue |
| 373 | } |
| 374 | |
| 375 | $relativePathFromGitHub = [System.IO.Path]::GetRelativePath($GitHubDir, $instrFile.FullName) |
| 376 | $normalizedRelativePath = (Join-Path ".github" $relativePathFromGitHub) -replace '\\', '/' |
| 377 | |
| 378 | $result.Instructions += [PSCustomObject]@{ |
| 379 | name = $instrName |
| 380 | path = "./$normalizedRelativePath" |
| 381 | description = $frontmatter.description |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | return $result |
| 386 | } |
| 387 | |
| 388 | function Update-PackageJsonContributes { |
| 389 | <# |
| 390 | .SYNOPSIS |
| 391 | Updates package.json contributes section with discovered components. |
| 392 | .DESCRIPTION |
| 393 | Pure function that takes a package.json object and discovered components, |
| 394 | returning a new object with the contributes section updated. |
| 395 | .PARAMETER PackageJson |
| 396 | The package.json object to update. |
| 397 | .PARAMETER ChatAgents |
| 398 | Array of discovered chat agent objects. |
| 399 | .PARAMETER ChatPromptFiles |
| 400 | Array of discovered prompt objects. |
| 401 | .PARAMETER ChatInstructions |
| 402 | Array of discovered instruction objects. |
| 403 | .OUTPUTS |
| 404 | [PSCustomObject] Updated package.json object. |
| 405 | #> |
| 406 | [CmdletBinding()] |
| 407 | [OutputType([PSCustomObject])] |
| 408 | param( |
| 409 | [Parameter(Mandatory = $true)] |
| 410 | [PSCustomObject]$PackageJson, |
| 411 | |
| 412 | [Parameter(Mandatory = $true)] |
| 413 | [AllowEmptyCollection()] |
| 414 | [array]$ChatAgents, |
| 415 | |
| 416 | [Parameter(Mandatory = $true)] |
| 417 | [AllowEmptyCollection()] |
| 418 | [array]$ChatPromptFiles, |
| 419 | |
| 420 | [Parameter(Mandatory = $true)] |
| 421 | [AllowEmptyCollection()] |
| 422 | [array]$ChatInstructions |
| 423 | ) |
| 424 | |
| 425 | # Clone the object to avoid modifying the original |
| 426 | $updated = $PackageJson | ConvertTo-Json -Depth 10 | ConvertFrom-Json |
| 427 | |
| 428 | # Ensure contributes section exists |
| 429 | if (-not $updated.contributes) { |
| 430 | $updated | Add-Member -NotePropertyName "contributes" -NotePropertyValue ([PSCustomObject]@{}) |
| 431 | } |
| 432 | |
| 433 | # Add or update contributes properties |
| 434 | if ($null -eq $updated.contributes.chatAgents) { |
| 435 | $updated.contributes | Add-Member -NotePropertyName "chatAgents" -NotePropertyValue $ChatAgents -Force |
| 436 | } else { |
| 437 | $updated.contributes.chatAgents = $ChatAgents |
| 438 | } |
| 439 | |
| 440 | if ($null -eq $updated.contributes.chatPromptFiles) { |
| 441 | $updated.contributes | Add-Member -NotePropertyName "chatPromptFiles" -NotePropertyValue $ChatPromptFiles -Force |
| 442 | } else { |
| 443 | $updated.contributes.chatPromptFiles = $ChatPromptFiles |
| 444 | } |
| 445 | |
| 446 | if ($null -eq $updated.contributes.chatInstructions) { |
| 447 | $updated.contributes | Add-Member -NotePropertyName "chatInstructions" -NotePropertyValue $ChatInstructions -Force |
| 448 | } else { |
| 449 | $updated.contributes.chatInstructions = $ChatInstructions |
| 450 | } |
| 451 | |
| 452 | return $updated |
| 453 | } |
| 454 | |
| 455 | #endregion Pure Functions |
| 456 | |
| 457 | #region Entry Point |
| 458 | |
| 459 | if ($MyInvocation.InvocationName -ne '.') { |
| 460 | # Verify PowerShell-Yaml module is available (runtime check instead of #Requires) |
| 461 | if (-not (Get-Module -ListAvailable -Name PowerShell-Yaml)) { |
| 462 | Write-Error "Required module 'PowerShell-Yaml' is not installed. Install with: Install-Module -Name PowerShell-Yaml -Scope CurrentUser" |
| 463 | exit 1 |
| 464 | } |
| 465 | Import-Module PowerShell-Yaml -ErrorAction Stop |
| 466 | |
| 467 | # Define allowed maturity levels based on channel |
| 468 | $allowedMaturities = Get-AllowedMaturities -Channel $Channel |
| 469 | |
| 470 | # Determine script and repo paths |
| 471 | $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path |
| 472 | $RepoRoot = (Get-Item "$ScriptDir/../..").FullName |
| 473 | $ExtensionDir = Join-Path $RepoRoot "extension" |
| 474 | $GitHubDir = Join-Path $RepoRoot ".github" |
| 475 | $PackageJsonPath = Join-Path $ExtensionDir "package.json" |
| 476 | |
| 477 | Write-Host "๐ฆ HVE Core Extension Preparer" -ForegroundColor Cyan |
| 478 | Write-Host "==============================" -ForegroundColor Cyan |
| 479 | Write-Host " Channel: $Channel" -ForegroundColor Cyan |
| 480 | Write-Host "" |
| 481 | |
| 482 | # Verify paths exist |
| 483 | if (-not (Test-Path $ExtensionDir)) { |
| 484 | Write-Error "Extension directory not found: $ExtensionDir" |
| 485 | exit 1 |
| 486 | } |
| 487 | |
| 488 | if (-not (Test-Path $PackageJsonPath)) { |
| 489 | Write-Error "package.json not found: $PackageJsonPath" |
| 490 | exit 1 |
| 491 | } |
| 492 | |
| 493 | if (-not (Test-Path $GitHubDir)) { |
| 494 | Write-Error ".github directory not found: $GitHubDir" |
| 495 | exit 1 |
| 496 | } |
| 497 | |
| 498 | # Read current package.json |
| 499 | Write-Host "๐ Reading package.json..." -ForegroundColor Yellow |
| 500 | try { |
| 501 | $packageJson = Get-Content -Path $PackageJsonPath -Raw | ConvertFrom-Json |
| 502 | } catch { |
| 503 | Write-Error "Failed to parse package.json: $_`nPlease check $PackageJsonPath for JSON syntax errors." |
| 504 | exit 1 |
| 505 | } |
| 506 | |
| 507 | # Validate package.json has required version field |
| 508 | if (-not $packageJson.PSObject.Properties['version']) { |
| 509 | Write-Error "package.json is missing required 'version' field" |
| 510 | exit 1 |
| 511 | } |
| 512 | |
| 513 | # Use existing version from package.json |
| 514 | $version = $packageJson.version |
| 515 | |
| 516 | # Validate version format |
| 517 | if ($version -notmatch '^\d+\.\d+\.\d+$') { |
| 518 | Write-Error "Invalid version format in package.json: '$version'. Expected semantic version format (e.g., 1.0.0)" |
| 519 | exit 1 |
| 520 | } |
| 521 | |
| 522 | Write-Host " Using version: $version" -ForegroundColor Green |
| 523 | |
| 524 | # Discover chat agents (excluding hve-core-installer which is for manual installation only) |
| 525 | Write-Host "" |
| 526 | Write-Host "๐ Discovering chat agents..." -ForegroundColor Yellow |
| 527 | $agentsDir = Join-Path $GitHubDir "agents" |
| 528 | $chatAgents = @() |
| 529 | |
| 530 | # Agents to exclude from extension packaging |
| 531 | $excludedAgents = @('hve-core-installer') |
| 532 | |
| 533 | if (Test-Path $agentsDir) { |
| 534 | $agentFiles = Get-ChildItem -Path $agentsDir -Filter "*.agent.md" | Sort-Object Name |
| 535 | |
| 536 | foreach ($agentFile in $agentFiles) { |
| 537 | # Extract agent name from filename (e.g., hve-core-installer.agent.md -> hve-core-installer) |
| 538 | $agentName = $agentFile.BaseName -replace '\.agent$', '' |
| 539 | |
| 540 | # Skip excluded agents |
| 541 | if ($excludedAgents -contains $agentName) { |
| 542 | Write-Host " โญ๏ธ $agentName (excluded)" -ForegroundColor DarkGray |
| 543 | continue |
| 544 | } |
| 545 | |
| 546 | # Extract frontmatter data |
| 547 | $frontmatter = Get-FrontmatterData -FilePath $agentFile.FullName -FallbackDescription "AI agent for $agentName" |
| 548 | $description = $frontmatter.description |
| 549 | $maturity = $frontmatter.maturity |
| 550 | |
| 551 | # Filter by maturity based on channel |
| 552 | if ($allowedMaturities -notcontains $maturity) { |
| 553 | Write-Host " โญ๏ธ $agentName (maturity: $maturity, skipped for $Channel)" -ForegroundColor DarkGray |
| 554 | continue |
| 555 | } |
| 556 | |
| 557 | $agent = [PSCustomObject]@{ |
| 558 | name = $agentName |
| 559 | path = "./.github/agents/$($agentFile.Name)" |
| 560 | description = $description |
| 561 | } |
| 562 | |
| 563 | $chatAgents += $agent |
| 564 | Write-Host " โ
$agentName" -ForegroundColor Green |
| 565 | } |
| 566 | } else { |
| 567 | Write-Warning "Agents directory not found: $agentsDir" |
| 568 | } |
| 569 | |
| 570 | # Discover prompts |
| 571 | Write-Host "" |
| 572 | Write-Host "๐ Discovering prompts..." -ForegroundColor Yellow |
| 573 | $promptsDir = Join-Path $GitHubDir "prompts" |
| 574 | $chatPromptFiles = @() |
| 575 | |
| 576 | if (Test-Path $promptsDir) { |
| 577 | $promptFiles = Get-ChildItem -Path $promptsDir -Filter "*.prompt.md" -Recurse | Sort-Object Name |
| 578 | |
| 579 | foreach ($promptFile in $promptFiles) { |
| 580 | # Extract prompt name from filename (e.g., git-commit.prompt.md -> git-commit) |
| 581 | $promptName = $promptFile.BaseName -replace '\.prompt$', '' |
| 582 | |
| 583 | # Extract frontmatter data |
| 584 | $displayName = ($promptName -replace '-', ' ') -replace '(\b\w)', { $_.Groups[1].Value.ToUpper() } |
| 585 | $frontmatter = Get-FrontmatterData -FilePath $promptFile.FullName -FallbackDescription "Prompt for $displayName" |
| 586 | $description = $frontmatter.description |
| 587 | $maturity = $frontmatter.maturity |
| 588 | |
| 589 | # Filter by maturity based on channel |
| 590 | if ($allowedMaturities -notcontains $maturity) { |
| 591 | Write-Host " โญ๏ธ $promptName (maturity: $maturity, skipped for $Channel)" -ForegroundColor DarkGray |
| 592 | continue |
| 593 | } |
| 594 | |
| 595 | # Calculate relative path from .github |
| 596 | $relativePath = [System.IO.Path]::GetRelativePath($GitHubDir, $promptFile.FullName) -replace '\\', '/' |
| 597 | |
| 598 | $prompt = [PSCustomObject]@{ |
| 599 | name = $promptName |
| 600 | path = "./.github/$relativePath" |
| 601 | description = $description |
| 602 | } |
| 603 | |
| 604 | $chatPromptFiles += $prompt |
| 605 | Write-Host " โ
$promptName" -ForegroundColor Green |
| 606 | } |
| 607 | } else { |
| 608 | Write-Warning "Prompts directory not found: $promptsDir" |
| 609 | } |
| 610 | |
| 611 | # Discover instruction files |
| 612 | Write-Host "" |
| 613 | Write-Host "๐ Discovering instruction files..." -ForegroundColor Yellow |
| 614 | $instructionsDir = Join-Path $GitHubDir "instructions" |
| 615 | $chatInstructions = @() |
| 616 | |
| 617 | if (Test-Path $instructionsDir) { |
| 618 | $instructionFiles = Get-ChildItem -Path $instructionsDir -Filter "*.instructions.md" -Recurse | Sort-Object Name |
| 619 | |
| 620 | foreach ($instrFile in $instructionFiles) { |
| 621 | # Extract instruction name from filename (e.g., commit-message.instructions.md -> commit-message-instructions) |
| 622 | $baseName = $instrFile.BaseName -replace '\.instructions$', '' |
| 623 | $instrName = "$baseName-instructions" |
| 624 | |
| 625 | # Extract frontmatter data |
| 626 | $displayName = ($baseName -replace '-', ' ') -replace '(\b\w)', { $_.Groups[1].Value.ToUpper() } |
| 627 | $frontmatter = Get-FrontmatterData -FilePath $instrFile.FullName -FallbackDescription "Instructions for $displayName" |
| 628 | $description = $frontmatter.description |
| 629 | $maturity = $frontmatter.maturity |
| 630 | |
| 631 | # Filter by maturity based on channel |
| 632 | if ($allowedMaturities -notcontains $maturity) { |
| 633 | Write-Host " โญ๏ธ $instrName (maturity: $maturity, skipped for $Channel)" -ForegroundColor DarkGray |
| 634 | continue |
| 635 | } |
| 636 | |
| 637 | # Calculate relative path from .github using cross-platform APIs |
| 638 | $relativePathFromGitHub = [System.IO.Path]::GetRelativePath($GitHubDir, $instrFile.FullName) |
| 639 | $normalizedRelativePath = (Join-Path ".github" $relativePathFromGitHub) -replace '\\', '/' |
| 640 | |
| 641 | $instruction = [PSCustomObject]@{ |
| 642 | name = $instrName |
| 643 | path = "./$normalizedRelativePath" |
| 644 | description = $description |
| 645 | } |
| 646 | |
| 647 | $chatInstructions += $instruction |
| 648 | Write-Host " โ
$instrName" -ForegroundColor Green |
| 649 | } |
| 650 | } else { |
| 651 | Write-Warning "Instructions directory not found: $instructionsDir" |
| 652 | } |
| 653 | |
| 654 | # Update package.json |
| 655 | Write-Host "" |
| 656 | Write-Host "๐ Updating package.json..." -ForegroundColor Yellow |
| 657 | |
| 658 | # Ensure contributes section exists |
| 659 | if (-not $packageJson.contributes) { |
| 660 | $packageJson | Add-Member -NotePropertyName "contributes" -NotePropertyValue ([PSCustomObject]@{}) |
| 661 | } |
| 662 | |
| 663 | # Update chatAgents |
| 664 | $packageJson.contributes.chatAgents = $chatAgents |
| 665 | Write-Host " Updated chatAgents: $($chatAgents.Count) agents" -ForegroundColor Green |
| 666 | |
| 667 | # Update chatPromptFiles |
| 668 | $packageJson.contributes.chatPromptFiles = $chatPromptFiles |
| 669 | Write-Host " Updated chatPromptFiles: $($chatPromptFiles.Count) prompts" -ForegroundColor Green |
| 670 | |
| 671 | # Update chatInstructions |
| 672 | $packageJson.contributes.chatInstructions = $chatInstructions |
| 673 | Write-Host " Updated chatInstructions: $($chatInstructions.Count) files" -ForegroundColor Green |
| 674 | |
| 675 | if ($DryRun) { |
| 676 | Write-Host "" |
| 677 | Write-Host "๐ DRY RUN - Would write the following package.json:" -ForegroundColor Magenta |
| 678 | Write-Host ($packageJson | ConvertTo-Json -Depth 10) |
| 679 | Write-Host "" |
| 680 | Write-Host "๐ DRY RUN - No changes made" -ForegroundColor Magenta |
| 681 | exit 0 |
| 682 | } |
| 683 | |
| 684 | # Write updated package.json |
| 685 | $packageJson | ConvertTo-Json -Depth 10 | Set-Content -Path $PackageJsonPath -Encoding UTF8NoBOM |
| 686 | Write-Host " Saved package.json" -ForegroundColor Green |
| 687 | |
| 688 | # Handle changelog if provided |
| 689 | if ($ChangelogPath) { |
| 690 | Write-Host "" |
| 691 | Write-Host "๐ Processing changelog..." -ForegroundColor Yellow |
| 692 | |
| 693 | if (Test-Path $ChangelogPath) { |
| 694 | $changelogDest = Join-Path $ExtensionDir "CHANGELOG.md" |
| 695 | Copy-Item -Path $ChangelogPath -Destination $changelogDest -Force |
| 696 | Write-Host " Copied changelog to extension directory" -ForegroundColor Green |
| 697 | } else { |
| 698 | Write-Warning "Changelog file not found: $ChangelogPath" |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | Write-Host "" |
| 703 | Write-Host "๐ Done!" -ForegroundColor Green |
| 704 | Write-Host "" |
| 705 | Write-Host "๐ Summary:" -ForegroundColor Cyan |
| 706 | Write-Host " Version: $version" -ForegroundColor White |
| 707 | Write-Host " Channel: $Channel" -ForegroundColor White |
| 708 | Write-Host " Agents: $($chatAgents.Count)" -ForegroundColor White |
| 709 | Write-Host " Prompts: $($chatPromptFiles.Count)" -ForegroundColor White |
| 710 | Write-Host " Instructions: $($chatInstructions.Count)" -ForegroundColor White |
| 711 | Write-Host "" |
| 712 | |
| 713 | exit 0 |
| 714 | } |
| 715 | #endregion Entry Point |
| 716 | |