Files

154 lines
4.8 KiB
PowerShell

# Target directory defaults to .cursor/rules in the current working directory,
# but can be overridden by passing an argument.
param (
[string]$TargetDir = ".cursor/rules"
)
# Ensure path is absolute and clean
$absoluteTargetDir = [System.IO.Path]::GetFullPath((Join-Path (Get-Location) $TargetDir))
$baseUrl = "https://raw.githubusercontent.com/addyosmani/agent-skills/main/skills"
# Array of all 24 skills in the repository
$skills = @(
"api-and-interface-design",
"browser-testing-with-devtools",
"ci-cd-and-automation",
"code-review-and-quality",
"code-simplification",
"context-engineering",
"debugging-and-error-recovery",
"deprecation-and-migration",
"documentation-and-adrs",
"doubt-driven-development",
"frontend-ui-engineering",
"git-workflow-and-versioning",
"idea-refine",
"incremental-implementation",
"interview-me",
"observability-and-instrumentation",
"performance-optimization",
"planning-and-task-breakdown",
"security-and-hardening",
"shipping-and-launch",
"source-driven-development",
"spec-driven-development",
"test-driven-development",
"using-agent-skills"
)
# Initialize active status hashtable
$active = [ordered]@{}
foreach ($s in $skills) {
$active[$s] = $false
}
# Auto-detect existing skills in the target directory
$anyExists = $false
if (Test-Path -Path $absoluteTargetDir) {
foreach ($s in $skills) {
$filePath = Join-Path -Path $absoluteTargetDir -ChildPath "$s.md"
if (Test-Path -Path $filePath) {
$anyExists = $true
$active[$s] = $true
}
}
}
# If no skills are currently present, enable the 3 default recommended skills
if (-not $anyExists) {
$active["test-driven-development"] = $true
$active["code-review-and-quality"] = $true
$active["incremental-implementation"] = $true
}
# Interactive selection menu loop
while ($true) {
Clear-Host
Write-Host "===================================================="
Write-Host " Cursor Agent-Skills Setup "
Write-Host "===================================================="
Write-Host "Target Directory: $absoluteTargetDir"
Write-Host ""
Write-Host "Select skills to activate (toggle with number):"
Write-Host ""
for ($i = 0; $i -lt $skills.Count; $i++) {
$slug = $skills[$i]
$status = if ($active[$slug]) { "[x]" } else { "[ ]" }
$idx = $i + 1
Write-Host ("{0,2}) {1} {2}" -f $idx, $status, $slug)
}
Write-Host ""
Write-Host "Commands:"
Write-Host " a - Select ALL skills"
Write-Host " n - Select NONE (clear all)"
Write-Host " d - Confirm and apply changes (or press Enter)"
Write-Host " q - Quit/Cancel without changes"
Write-Host ""
$choice = Read-Host "Your choice"
if ($null -ne $choice) { $choice = $choice.Trim() }
if ($choice -eq "" -or $choice -eq "d" -or $choice -eq "D") {
break
}
elseif ($choice -eq "a" -or $choice -eq "A") {
foreach ($s in $skills) { $active[$s] = $true }
}
elseif ($choice -eq "n" -or $choice -eq "N") {
foreach ($s in $skills) { $active[$s] = $false }
}
elseif ($choice -eq "q" -or $choice -eq "Q") {
Write-Host "Cancelled. No changes made."
exit 0
}
elseif ($choice -match '^\d+$') {
$num = [int]$choice
if ($num -ge 1 -and $num -le $skills.Count) {
$slug = $skills[$num - 1]
$active[$slug] = -not $active[$slug]
}
else {
Write-Host "Invalid number. Redrawing..." -ForegroundColor Yellow
Start-Sleep -Seconds 1
}
}
else {
Write-Host "Invalid option. Redrawing..." -ForegroundColor Yellow
Start-Sleep -Seconds 1
}
}
# Ensure target directory exists if we have active skills or just to be safe
if (-not (Test-Path -Path $absoluteTargetDir)) {
Write-Host "`nCreating target directory: $absoluteTargetDir"
New-Item -ItemType Directory -Path $absoluteTargetDir -Force | Out-Null
}
Write-Host "`nApplying changes..."
foreach ($s in $skills) {
$destPath = Join-Path -Path $absoluteTargetDir -ChildPath "$s.md"
if ($active[$s]) {
$url = "$baseUrl/$s/SKILL.md"
Write-Host "Downloading $s..."
try {
Invoke-WebRequest -Uri $url -OutFile $destPath -UseBasicParsing -ErrorAction Stop
Write-Host "Successfully activated/updated $s.md" -ForegroundColor Green
}
catch {
Write-Error "Failed to download $s.md: $_"
}
}
else {
if (Test-Path -Path $destPath) {
Write-Host "Deactivating/removing $s.md..." -ForegroundColor Yellow
Remove-Item -Path $destPath -Force
}
}
}
Write-Host "`nDone!"