|
| 1 | +#Requires -Version 5.1 |
| 2 | +<# |
| 3 | +.SYNOPSIS |
| 4 | + Repo Analyzer Skill Installer for Windows. |
| 5 | +
|
| 6 | +.DESCRIPTION |
| 7 | + Installs the repo-analyzer skill to system or project agent skill directories. |
| 8 | +
|
| 9 | +.PARAMETER System |
| 10 | + Install to system directories |
| 11 | +
|
| 12 | +.PARAMETER Project |
| 13 | + Install to current project directory |
| 14 | +
|
| 15 | +.PARAMETER Agent |
| 16 | + Target specific agent (claude-code, kimi, codex, opencode) |
| 17 | +
|
| 18 | +.EXAMPLE |
| 19 | + .\install.ps1 -System |
| 20 | + Install to all system agent directories |
| 21 | +
|
| 22 | +.EXAMPLE |
| 23 | + .\install.ps1 -System -Agent kimi |
| 24 | + Install to kimi system directory only |
| 25 | +
|
| 26 | +.EXAMPLE |
| 27 | + .\install.ps1 -Project |
| 28 | + Install to current project |
| 29 | +#> |
| 30 | + |
| 31 | +param( |
| 32 | + [switch]$System, |
| 33 | + [switch]$Project, |
| 34 | + [string]$Agent = "" |
| 35 | +) |
| 36 | + |
| 37 | +$ErrorActionPreference = "Stop" |
| 38 | +$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path |
| 39 | +$SkillRoot = Split-Path -Parent $ScriptDir |
| 40 | +$SkillName = Split-Path -Leaf $SkillRoot |
| 41 | + |
| 42 | +function Write-ColorOutput { |
| 43 | + param([string]$Message, [string]$Color = "White") |
| 44 | + Write-Host $Message -ForegroundColor $Color |
| 45 | +} |
| 46 | +function Write-Success { param([string]$Message) Write-ColorOutput $Message "Green" } |
| 47 | +function Write-Warning { param([string]$Message) Write-ColorOutput $Message "Yellow" } |
| 48 | +function Write-ErrorMsg { param([string]$Message) Write-ColorOutput $Message "Red" } |
| 49 | +function Write-Info { param([string]$Message) Write-ColorOutput $Message "Cyan" } |
| 50 | + |
| 51 | +function Test-PythonDeps { |
| 52 | + Write-Info "Checking Python dependencies..." |
| 53 | + |
| 54 | + try { |
| 55 | + python --version 2>$null | Out-Null |
| 56 | + Write-Success "[OK] Python available (no external dependencies required)" |
| 57 | + } |
| 58 | + catch { |
| 59 | + Write-ErrorMsg "Error: Python not found. Please install Python 3.8+" |
| 60 | + exit 1 |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +function Get-SystemTargetDirs { |
| 65 | + $dirs = @() |
| 66 | + $homePath = $env:USERPROFILE |
| 67 | + |
| 68 | + switch ($Agent) { |
| 69 | + "" { |
| 70 | + $dirs += Join-Path $homePath ".config\agents\skills" |
| 71 | + $dirs += Join-Path $homePath ".claude\skills" |
| 72 | + $dirs += Join-Path $homePath ".kimi\skills" |
| 73 | + $dirs += Join-Path $homePath ".codex\skills" |
| 74 | + $dirs += Join-Path $homePath ".opencode\skills" |
| 75 | + } |
| 76 | + "claude-code" { |
| 77 | + $dirs += Join-Path $homePath ".claude\skills" |
| 78 | + } |
| 79 | + "kimi" { |
| 80 | + $dirs += Join-Path $homePath ".kimi\skills" |
| 81 | + $dirs += Join-Path $homePath ".config\agents\skills" |
| 82 | + } |
| 83 | + "codex" { |
| 84 | + $dirs += Join-Path $homePath ".codex\skills" |
| 85 | + } |
| 86 | + "opencode" { |
| 87 | + $dirs += Join-Path $homePath ".opencode\skills" |
| 88 | + } |
| 89 | + default { |
| 90 | + Write-ErrorMsg "Error: Unknown agent '$Agent'" |
| 91 | + Write-Host "Supported agents: claude-code, kimi, codex, opencode" |
| 92 | + exit 1 |
| 93 | + } |
| 94 | + } |
| 95 | + return $dirs |
| 96 | +} |
| 97 | + |
| 98 | +function Get-ProjectTargetDirs { |
| 99 | + $dirs = @() |
| 100 | + $dirs += Join-Path $PWD ".agents\skills" |
| 101 | + $dirs += Join-Path $PWD ".kimi\skills" |
| 102 | + $dirs += Join-Path $PWD ".claude\skills" |
| 103 | + return $dirs |
| 104 | +} |
| 105 | + |
| 106 | +function Test-SymlinkCapability { |
| 107 | + $testPath = Join-Path $env:TEMP "symlink_test_$(Get-Random)" |
| 108 | + $testTarget = Join-Path $env:TEMP "symlink_test_target_$(Get-Random)" |
| 109 | + try { |
| 110 | + New-Item -ItemType Directory -Path $testTarget -Force | Out-Null |
| 111 | + New-Item -ItemType SymbolicLink -Path $testPath -Target $testTarget -Force | Out-Null |
| 112 | + Remove-Item $testPath -Force |
| 113 | + Remove-Item $testTarget -Force |
| 114 | + return $true |
| 115 | + } |
| 116 | + catch { |
| 117 | + return $false |
| 118 | + } |
| 119 | +} |
| 120 | + |
| 121 | +function New-SkillLink { |
| 122 | + param([string]$TargetDir) |
| 123 | + $linkPath = Join-Path $TargetDir $SkillName |
| 124 | + |
| 125 | + if ((Test-Path $linkPath) -or (Get-Item $linkPath -ErrorAction SilentlyContinue)) { |
| 126 | + Write-Warning " [SKIP] $SkillName already exists at $linkPath" |
| 127 | + return $false |
| 128 | + } |
| 129 | + |
| 130 | + $parentDir = Split-Path -Parent $linkPath |
| 131 | + if (-not (Test-Path $parentDir)) { |
| 132 | + New-Item -ItemType Directory -Path $parentDir -Force | Out-Null |
| 133 | + } |
| 134 | + |
| 135 | + if (Test-SymlinkCapability) { |
| 136 | + try { |
| 137 | + New-Item -ItemType SymbolicLink -Path $linkPath -Target $SkillRoot -Force | Out-Null |
| 138 | + Write-Success " [OK] $SkillName -> $linkPath" |
| 139 | + return $true |
| 140 | + } |
| 141 | + catch { |
| 142 | + # fall through to junction |
| 143 | + } |
| 144 | + } |
| 145 | + |
| 146 | + try { |
| 147 | + New-Item -ItemType Junction -Path $linkPath -Target $SkillRoot -Force | Out-Null |
| 148 | + Write-Success " [OK] $SkillName -> $linkPath (junction)" |
| 149 | + return $true |
| 150 | + } |
| 151 | + catch { |
| 152 | + Write-ErrorMsg " [ERROR] Failed to create link: $_" |
| 153 | + return $false |
| 154 | + } |
| 155 | +} |
| 156 | + |
| 157 | +function Install-System { |
| 158 | + Write-Info "Installing $SkillName to system directories..." |
| 159 | + $targetDirs = Get-SystemTargetDirs |
| 160 | + $installed = 0 |
| 161 | + $skipped = 0 |
| 162 | + |
| 163 | + foreach ($targetDir in $targetDirs) { |
| 164 | + $result = New-SkillLink -TargetDir $targetDir |
| 165 | + if ($result) { |
| 166 | + $installed++ |
| 167 | + } |
| 168 | + else { |
| 169 | + $skipped++ |
| 170 | + } |
| 171 | + } |
| 172 | + |
| 173 | + Write-Host "" |
| 174 | + Write-Success "System installation complete." |
| 175 | + Write-Host " Installed: $installed" |
| 176 | + Write-Host " Skipped: $skipped" |
| 177 | +} |
| 178 | + |
| 179 | +function Install-Project { |
| 180 | + Write-Info "Installing $SkillName to project directories..." |
| 181 | + |
| 182 | + if (-not (Test-Path ".git")) { |
| 183 | + Write-Warning "Warning: Current directory is not a git repository." |
| 184 | + $response = Read-Host "Continue anyway? (y/N)" |
| 185 | + if ($response -notmatch "^[Yy]$") { |
| 186 | + exit 1 |
| 187 | + } |
| 188 | + } |
| 189 | + |
| 190 | + $targetDirs = Get-ProjectTargetDirs |
| 191 | + $installed = 0 |
| 192 | + $skipped = 0 |
| 193 | + |
| 194 | + foreach ($targetDir in $targetDirs) { |
| 195 | + $result = New-SkillLink -TargetDir $targetDir |
| 196 | + if ($result) { |
| 197 | + $installed++ |
| 198 | + } |
| 199 | + else { |
| 200 | + $skipped++ |
| 201 | + } |
| 202 | + } |
| 203 | + |
| 204 | + Write-Host "" |
| 205 | + Write-Success "Project installation complete." |
| 206 | + Write-Host " Installed: $installed" |
| 207 | + Write-Host " Skipped: $skipped" |
| 208 | +} |
| 209 | + |
| 210 | +function Main { |
| 211 | + if (-not $System -and -not $Project) { |
| 212 | + Write-ErrorMsg "Error: Must specify -System or -Project" |
| 213 | + Write-Host "" |
| 214 | + Write-Host "Usage:" |
| 215 | + Write-Host " .\install.ps1 -System" |
| 216 | + Write-Host " .\install.ps1 -System -Agent kimi" |
| 217 | + Write-Host " .\install.ps1 -Project" |
| 218 | + exit 1 |
| 219 | + } |
| 220 | + |
| 221 | + Write-Info "Detected OS: Windows" |
| 222 | + Write-Host "" |
| 223 | + |
| 224 | + Test-PythonDeps |
| 225 | + Write-Host "" |
| 226 | + |
| 227 | + if ($System) { |
| 228 | + Install-System |
| 229 | + } |
| 230 | + elseif ($Project) { |
| 231 | + Install-Project |
| 232 | + } |
| 233 | + |
| 234 | + Write-Host "" |
| 235 | + Write-Host "Skill installed: $SkillName" |
| 236 | + Write-Host "" |
| 237 | + Write-Host "Usage:" |
| 238 | + Write-Host " python $SkillRoot\scripts\analyze_repo.py https://github.com/user/repo" |
| 239 | +} |
| 240 | + |
| 241 | +Main |
0 commit comments