# ===================================================================== # Trae CN 技能安装器(Windows) # 作用:把本项目 skills\ 下全部技能安装到用户级技能目录 # %USERPROFILE%\.trae-cn\skills\ # 用法:双击同目录下的 install-skills.bat(推荐),或 # powershell -NoProfile -ExecutionPolicy Bypass -File install-skills.ps1 # ===================================================================== $ErrorActionPreference = "Stop" # --- 1. 定位源目录与目标目录 --- $ScriptDir = $PSScriptRoot $ProjectRoot = Split-Path -Parent $ScriptDir $SkillsSource = Join-Path $ProjectRoot "skills" $TraeSkills = Join-Path $env:USERPROFILE ".trae-cn\skills" # 备份放在技能目录外,避免被 Trae 当成技能重复扫描 $BackupRoot = Join-Path $env:USERPROFILE ".trae-cn\skills-backup" Write-Host "=== Trae CN 技能安装器 ===" -ForegroundColor Cyan Write-Host "技能源目录: $SkillsSource" Write-Host "安装目标: $TraeSkills" Write-Host "" # --- 2. 校验源目录并收集技能(含 SKILL.md 的子目录才算) --- if (-not (Test-Path $SkillsSource)) { Write-Host "[错误] 找不到技能源目录: $SkillsSource" -ForegroundColor Red exit 1 } $skills = @(Get-ChildItem -Path $SkillsSource -Directory | Where-Object { Test-Path (Join-Path $_.FullName "SKILL.md") }) if ($skills.Count -eq 0) { Write-Host "[错误] 源目录下没有可用技能(每个技能文件夹需包含 SKILL.md)。" -ForegroundColor Red exit 1 } Write-Host ("发现 {0} 个技能: {1}" -f $skills.Count, ($skills.Name -join ", ")) Write-Host "" # --- 3. 逐个安装:旧版先备份,再复制新版 --- New-Item -ItemType Directory -Force -Path $TraeSkills | Out-Null $timestamp = Get-Date -Format "yyyyMMdd-HHmmss" $backupCount = 0 foreach ($skill in $skills) { $dest = Join-Path $TraeSkills $skill.Name if (Test-Path $dest) { New-Item -ItemType Directory -Force -Path $BackupRoot | Out-Null $backupPath = Join-Path $BackupRoot ("{0}-{1}" -f $skill.Name, $timestamp) Move-Item -Path $dest -Destination $backupPath $backupCount++ Write-Host "[备份] $($skill.Name) 旧版 -> $backupPath" -ForegroundColor Yellow } Copy-Item -Path $skill.FullName -Destination $dest -Recurse -Force Write-Host "[安装] $($skill.Name)" -ForegroundColor Green } # --- 4. 校验安装结果 --- Write-Host "" Write-Host "=== 校验结果 ===" $failed = @() foreach ($skill in $skills) { if (Test-Path (Join-Path $TraeSkills "$($skill.Name)\SKILL.md")) { Write-Host " [OK] $($skill.Name)" -ForegroundColor Green } else { Write-Host " [FAIL] $($skill.Name)" -ForegroundColor Red $failed += $skill.Name } } # --- 5. 汇总与后续提示 --- Write-Host "" if ($failed.Count -gt 0) { Write-Host ("安装失败: {0}" -f ($failed -join ", ")) -ForegroundColor Red exit 2 } Write-Host "全部安装成功。" -ForegroundColor Green if ($backupCount -gt 0) { Write-Host "旧版本备份于: $BackupRoot(确认新版可用后可手动删除)" -ForegroundColor Yellow } Write-Host "" Write-Host "下一步: 重启 Trae CN 或新建会话后,在对话中提及技能名或相关意图即可触发:" foreach ($s in $skills) { Write-Host " - $($s.Name)" }