$ErrorActionPreference = 'Stop' $repositoryRoot = Split-Path -Parent $PSScriptRoot $skillName = 'upload-delivery-desk-work' $sourcePath = Join-Path $repositoryRoot ".agents\skills\$skillName" $packageDirectory = Join-Path $repositoryRoot 'skill-packages' $packagePath = Join-Path $packageDirectory "$skillName.zip" if (-not (Test-Path -LiteralPath (Join-Path $sourcePath 'SKILL.md'))) { throw "Skill not found: $sourcePath" } $previousNoBytecode = $env:PYTHONDONTWRITEBYTECODE try { $env:PYTHONDONTWRITEBYTECODE = '1' python (Join-Path $repositoryRoot 'tests\test_upload_skill.py') if ($LASTEXITCODE -ne 0) { throw 'Upload Skill regression tests failed.' } } finally { $env:PYTHONDONTWRITEBYTECODE = $previousNoBytecode } $runtimeFiles = Get-ChildItem -LiteralPath $sourcePath -Recurse -Force | Where-Object { $_.Name -eq '__pycache__' -or $_.Extension -in @('.pyc', '.pyo') } if ($runtimeFiles) { throw 'Skill contains Python runtime cache. Remove it before packaging.' } New-Item -ItemType Directory -Force -Path $packageDirectory | Out-Null if (Test-Path -LiteralPath $packagePath) { Remove-Item -LiteralPath $packagePath -Force } Add-Type -AssemblyName System.IO.Compression.FileSystem [System.IO.Compression.ZipFile]::CreateFromDirectory( $sourcePath, $packagePath, [System.IO.Compression.CompressionLevel]::Optimal, $false ) $archive = [System.IO.Compression.ZipFile]::OpenRead($packagePath) try { $entries = @($archive.Entries | ForEach-Object { $_.FullName.Replace('\', '/') }) if ($entries -notcontains 'SKILL.md') { throw 'Packaged Skill must contain SKILL.md at the ZIP root.' } if ($entries | Where-Object { $_ -like "$skillName/*" }) { throw 'Packaged Skill contains an extra top-level directory.' } } finally { $archive.Dispose() } Write-Output $packagePath