install.ps1 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <#
  2. .SYNOPSIS
  3. Install claude-mods extensions to ~/.claude/
  4. .DESCRIPTION
  5. Copies commands, skills, agents, and rules to the global Claude Code config.
  6. Handles cleanup of deprecated items and command-to-skill migrations.
  7. .NOTES
  8. Run from the claude-mods directory:
  9. .\scripts\install.ps1
  10. #>
  11. $ErrorActionPreference = "Stop"
  12. Write-Host "================================================================" -ForegroundColor Cyan
  13. Write-Host " claude-mods Installer (Windows) " -ForegroundColor Cyan
  14. Write-Host "================================================================" -ForegroundColor Cyan
  15. Write-Host ""
  16. $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
  17. $projectRoot = Split-Path -Parent $scriptDir
  18. if ($env:CLAUDE_DIR) {
  19. $claudeDir = $env:CLAUDE_DIR
  20. } else {
  21. $claudeDir = "$env:USERPROFILE\.claude"
  22. }
  23. # Ensure ~/.claude directories exist
  24. $dirs = @("commands", "skills", "agents", "rules", "output-styles", "hooks")
  25. foreach ($dir in $dirs) {
  26. $path = Join-Path $claudeDir $dir
  27. if (-not (Test-Path $path)) {
  28. New-Item -ItemType Directory -Path $path -Force | Out-Null
  29. Write-Host " Created $path" -ForegroundColor Green
  30. }
  31. }
  32. # =============================================================================
  33. # DEPRECATED ITEMS - Remove these from user config
  34. # =============================================================================
  35. $deprecated = @(
  36. "$claudeDir\commands\review.md",
  37. "$claudeDir\commands\testgen.md",
  38. "$claudeDir\commands\conclave.md",
  39. "$claudeDir\commands\pulse.md",
  40. "$claudeDir\skills\conclave",
  41. "$claudeDir\skills\claude-code-templates", # Replaced by skill-creator
  42. "$claudeDir\skills\agentmail", # Renamed to pigeon (v2.3.0)
  43. "$claudeDir\skills\claude-code-debug", # Merged into claude-code-ops (v3.0)
  44. "$claudeDir\skills\claude-code-headless", # Merged into claude-code-ops (v3.0)
  45. "$claudeDir\skills\claude-code-hooks", # Merged into claude-code-ops (v3.0)
  46. # Deprecated agents (v3.0): folded into their -ops skill twins
  47. "$claudeDir\agents\python-expert.md",
  48. "$claudeDir\agents\typescript-expert.md",
  49. "$claudeDir\agents\javascript-expert.md",
  50. "$claudeDir\agents\go-expert.md",
  51. "$claudeDir\agents\rust-expert.md",
  52. "$claudeDir\agents\react-expert.md",
  53. "$claudeDir\agents\vue-expert.md",
  54. "$claudeDir\agents\astro-expert.md",
  55. "$claudeDir\agents\laravel-expert.md",
  56. "$claudeDir\agents\sql-expert.md",
  57. "$claudeDir\agents\postgres-expert.md",
  58. "$claudeDir\agents\cypress-expert.md", # -> skills/cypress-ops
  59. "$claudeDir\agents\cloudflare-expert.md", # -> skills/cloudflare-ops
  60. "$claudeDir\agents\wrangler-expert.md", # -> skills/cloudflare-ops
  61. "$claudeDir\agents\bash-expert.md", # -> skills/bash-ops
  62. "$claudeDir\agents\claude-architect.md", # -> skills/claude-code-ops
  63. "$claudeDir\agents\aws-fargate-ecs-expert.md", # -> skills/container-orchestration
  64. "$claudeDir\agents\craftcms-expert.md", # -> skills/craftcms-ops
  65. "$claudeDir\agents\payloadcms-expert.md", # -> skills/payloadcms-ops
  66. "$claudeDir\agents\asus-router-expert.md" # -> skills/asus-router-ops
  67. )
  68. # Renamed skills: -patterns -> -ops (March 2026)
  69. $renamedSkills = @(
  70. "cli-patterns",
  71. "mcp-patterns",
  72. "python-async-patterns",
  73. "python-cli-patterns",
  74. "python-database-patterns",
  75. "python-fastapi-patterns",
  76. "python-observability-patterns",
  77. "python-pytest-patterns",
  78. "python-typing-patterns",
  79. "rest-patterns",
  80. "security-patterns",
  81. "sql-patterns",
  82. "tailwind-patterns",
  83. "testing-patterns"
  84. )
  85. foreach ($oldSkill in $renamedSkills) {
  86. $oldPath = "$claudeDir\skills\$oldSkill"
  87. if (Test-Path $oldPath) {
  88. Remove-Item -Path $oldPath -Recurse -Force
  89. $newName = $oldSkill -replace '-patterns$', '-ops'
  90. Write-Host " Removed renamed: $oldSkill (now $newName)" -ForegroundColor Red
  91. }
  92. }
  93. Write-Host "Cleaning up deprecated items..." -ForegroundColor Yellow
  94. foreach ($item in $deprecated) {
  95. if (Test-Path $item) {
  96. Remove-Item -Path $item -Recurse -Force
  97. Write-Host " Removed: $item" -ForegroundColor Red
  98. }
  99. }
  100. Write-Host ""
  101. # =============================================================================
  102. # COMMANDS - Only copy commands that have not been migrated to skills
  103. # =============================================================================
  104. Write-Host "Installing commands..." -ForegroundColor Cyan
  105. $skipCommands = @("review.md", "testgen.md")
  106. $commandsDir = Join-Path $projectRoot "commands"
  107. Get-ChildItem -Path $commandsDir -Filter "*.md" | ForEach-Object {
  108. if ($_.Name -notin $skipCommands -and $_.Name -notlike "archive*") {
  109. Copy-Item $_.FullName -Destination "$claudeDir\commands\" -Force
  110. Write-Host " $($_.Name)" -ForegroundColor Green
  111. }
  112. }
  113. Write-Host ""
  114. # =============================================================================
  115. # SKILLS - Copy all skill directories
  116. # =============================================================================
  117. Write-Host "Installing skills..." -ForegroundColor Cyan
  118. $skillsDir = Join-Path $projectRoot "skills"
  119. Get-ChildItem -Path $skillsDir -Directory | ForEach-Object {
  120. $dest = "$claudeDir\skills\$($_.Name)"
  121. if (Test-Path $dest) {
  122. Remove-Item -Path $dest -Recurse -Force
  123. }
  124. Copy-Item $_.FullName -Destination $dest -Recurse -Force
  125. Write-Host " $($_.Name)/" -ForegroundColor Green
  126. }
  127. Write-Host ""
  128. # =============================================================================
  129. # AGENTS - Copy all agent files
  130. # =============================================================================
  131. Write-Host "Installing agents..." -ForegroundColor Cyan
  132. $agentsDir = Join-Path $projectRoot "agents"
  133. Get-ChildItem -Path $agentsDir -Filter "*.md" | ForEach-Object {
  134. Copy-Item $_.FullName -Destination "$claudeDir\agents\" -Force
  135. Write-Host " $($_.Name)" -ForegroundColor Green
  136. }
  137. Write-Host ""
  138. # =============================================================================
  139. # RULES - Copy all rule files
  140. # =============================================================================
  141. Write-Host "Installing rules..." -ForegroundColor Cyan
  142. $rulesDir = Join-Path $projectRoot "rules"
  143. Get-ChildItem -Path $rulesDir -Filter "*.md" | ForEach-Object {
  144. Copy-Item $_.FullName -Destination "$claudeDir\rules\" -Force
  145. Write-Host " $($_.Name)" -ForegroundColor Green
  146. }
  147. Write-Host ""
  148. # =============================================================================
  149. # OUTPUT STYLES - Copy all output style files
  150. # =============================================================================
  151. Write-Host "Installing output styles..." -ForegroundColor Cyan
  152. $stylesDir = Join-Path $projectRoot "output-styles"
  153. if (Test-Path $stylesDir) {
  154. Get-ChildItem -Path $stylesDir -Filter "*.md" | ForEach-Object {
  155. Copy-Item $_.FullName -Destination "$claudeDir\output-styles\" -Force
  156. Write-Host " $($_.Name)" -ForegroundColor Green
  157. }
  158. }
  159. Write-Host ""
  160. # =============================================================================
  161. # HOOKS - Copy scripts and merge plugin-equivalent wiring into settings.json
  162. # =============================================================================
  163. Write-Host "Installing hooks..." -ForegroundColor Cyan
  164. $hooksDir = Join-Path $projectRoot "hooks"
  165. Get-ChildItem -Path $hooksDir -Filter "*.sh" | ForEach-Object {
  166. Copy-Item $_.FullName -Destination "$claudeDir\hooks\" -Force
  167. }
  168. $settingsPath = Join-Path $claudeDir "settings.json"
  169. if (Test-Path $settingsPath) {
  170. $settings = Get-Content $settingsPath -Raw | ConvertFrom-Json
  171. } else {
  172. $settings = [PSCustomObject]@{}
  173. }
  174. if (-not $settings.PSObject.Properties["hooks"]) {
  175. $settings | Add-Member -MemberType NoteProperty -Name hooks -Value ([PSCustomObject]@{})
  176. }
  177. $desired = Get-Content (Join-Path $hooksDir "hooks.json") -Raw | ConvertFrom-Json
  178. foreach ($eventProperty in $desired.hooks.PSObject.Properties) {
  179. $eventName = $eventProperty.Name
  180. if (-not $settings.hooks.PSObject.Properties[$eventName]) {
  181. $settings.hooks | Add-Member -MemberType NoteProperty -Name $eventName -Value @()
  182. }
  183. $eventGroups = @($settings.hooks.$eventName)
  184. foreach ($group in @($eventProperty.Value)) {
  185. $missingHooks = @()
  186. foreach ($hook in @($group.hooks)) {
  187. $command = $hook.command.Replace('${CLAUDE_PLUGIN_ROOT}/hooks', (Join-Path $claudeDir "hooks"))
  188. # Dedup on the script NAME under hooks/, not the resolved path: a
  189. # hook wired by a plugin install carries the
  190. # ${CLAUDE_PLUGIN_ROOT}/hooks/ form and must still count as
  191. # already-wired (mixed-method double-fire). Separator-tolerant:
  192. # Join-Path yields \hooks while plugin form uses /hooks.
  193. $hookName = ($command -replace '^.*hooks[/\\]', '') -replace '"$', ''
  194. $alreadyWired = $false
  195. foreach ($existingGroup in $eventGroups) {
  196. foreach ($existingHook in @($existingGroup.hooks)) {
  197. if ($existingHook.command -and ($existingHook.command.Contains("hooks/$hookName") -or $existingHook.command.Contains("hooks\$hookName"))) {
  198. $alreadyWired = $true
  199. }
  200. }
  201. }
  202. if (-not $alreadyWired) {
  203. $copy = $hook.PSObject.Copy()
  204. $copy.command = $command
  205. $missingHooks += $copy
  206. }
  207. }
  208. if ($missingHooks.Count -gt 0) {
  209. $newGroup = $group.PSObject.Copy()
  210. $newGroup.hooks = $missingHooks
  211. $eventGroups += $newGroup
  212. }
  213. }
  214. $settings.hooks.$eventName = $eventGroups
  215. }
  216. $settings | ConvertTo-Json -Depth 20 | Set-Content $settingsPath -Encoding UTF8
  217. Write-Host " Security and peer-guard hooks wired in settings.json" -ForegroundColor Green
  218. Write-Host ""
  219. # =============================================================================
  220. # PIGEON - Global install (scripts + hook config hint)
  221. # =============================================================================
  222. Write-Host "Installing pigeon (pmail)..." -ForegroundColor Cyan
  223. # Clean up old agentmail install if present
  224. $oldAgentmailDir = Join-Path $claudeDir "agentmail"
  225. if (Test-Path $oldAgentmailDir) {
  226. Remove-Item -Path $oldAgentmailDir -Recurse -Force
  227. Write-Host " Removed old agentmail/ (renamed to pigeon/)" -ForegroundColor Red
  228. }
  229. $pigeonDir = Join-Path $claudeDir "pigeon"
  230. New-Item -ItemType Directory -Force -Path $pigeonDir | Out-Null
  231. $mailDbSrc = Join-Path $projectRoot "skills\pigeon\scripts\mail-db.sh"
  232. $checkMailSrc = Join-Path $projectRoot "hooks\check-mail.sh"
  233. if (Test-Path $mailDbSrc) {
  234. Copy-Item $mailDbSrc -Destination "$pigeonDir\" -Force
  235. Write-Host " mail-db.sh" -ForegroundColor Green
  236. }
  237. if (Test-Path $checkMailSrc) {
  238. Copy-Item $checkMailSrc -Destination "$pigeonDir\" -Force
  239. Write-Host " check-mail.sh" -ForegroundColor Green
  240. }
  241. $settingsPath = Join-Path $claudeDir "settings.json"
  242. # Migrate stale agentmail hook path -> pigeon
  243. if ((Test-Path $settingsPath) -and (Select-String -Path $settingsPath -Pattern "agentmail/check-mail\.sh" -Quiet)) {
  244. $content = Get-Content $settingsPath -Raw
  245. $content = $content -replace 'agentmail/check-mail\.sh', 'pigeon/check-mail.sh'
  246. Set-Content $settingsPath -Value $content -NoNewline
  247. Write-Host " Migrated agentmail hook -> pigeon in settings.json" -ForegroundColor Green
  248. }
  249. # Check if hook is already configured (pigeon path)
  250. if ((Test-Path $settingsPath) -and (Select-String -Path $settingsPath -Pattern "pigeon/check-mail\.sh" -Quiet)) {
  251. Write-Host " Hook already configured in settings.json" -ForegroundColor Green
  252. } else {
  253. Write-Host ""
  254. Write-Host ' To enable automatic pmail notifications, add this to ~/.claude/settings.json:' -ForegroundColor Yellow
  255. Write-Host ""
  256. Write-Host ' "hooks": {'
  257. Write-Host ' "PreToolUse": [{'
  258. Write-Host ' "matcher": "*",'
  259. Write-Host ' "hooks": [{'
  260. Write-Host ' "type": "command",'
  261. Write-Host ' "command": "bash \"$HOME/.claude/pigeon/check-mail.sh\"",'
  262. Write-Host ' "timeout": 5'
  263. Write-Host ' }]'
  264. Write-Host ' }]'
  265. Write-Host ' }'
  266. Write-Host ""
  267. Write-Host " Without this, pigeon works but you must check manually (pigeon read)." -ForegroundColor Yellow
  268. }
  269. Write-Host ""
  270. # =============================================================================
  271. # AUTO-SKILL - Global install (tracking + evaluation hooks)
  272. # =============================================================================
  273. Write-Host "Installing auto-skill..." -ForegroundColor Cyan
  274. $autoSkillDir = Join-Path $claudeDir "auto-skill"
  275. New-Item -ItemType Directory -Force -Path $autoSkillDir | Out-Null
  276. $scripts = @("track-tools.sh", "evaluate.sh")
  277. foreach ($script in $scripts) {
  278. $src = Join-Path $projectRoot "skills\auto-skill\scripts\$script"
  279. if (Test-Path $src) {
  280. Copy-Item $src -Destination "$autoSkillDir\" -Force
  281. Write-Host " $script" -ForegroundColor Green
  282. }
  283. }
  284. $settingsPath = Join-Path $claudeDir "settings.json"
  285. if ((Test-Path $settingsPath) -and (Select-String -Path $settingsPath -Pattern "auto-skill" -Quiet)) {
  286. Write-Host " Hooks already configured in settings.json" -ForegroundColor Green
  287. } else {
  288. Write-Host ""
  289. Write-Host ' To enable automatic skill suggestions, add these hooks to ~/.claude/settings.json:' -ForegroundColor Yellow
  290. Write-Host ""
  291. Write-Host ' "PostToolUse": [{ "matcher": "*", "hooks": [{'
  292. Write-Host ' "type": "command",'
  293. Write-Host ' "command": "bash \"$HOME/.claude/auto-skill/track-tools.sh\"", "timeout": 2'
  294. Write-Host ' }] }],'
  295. Write-Host ' "Stop": [{ "hooks": [{'
  296. Write-Host ' "type": "command",'
  297. Write-Host ' "command": "bash \"$HOME/.claude/auto-skill/evaluate.sh\"", "timeout": 5'
  298. Write-Host ' }] }]'
  299. Write-Host ""
  300. Write-Host " Without this, /auto-skill still works but won't suggest automatically." -ForegroundColor Yellow
  301. }
  302. Write-Host ""
  303. # =============================================================================
  304. # SUMMARY
  305. # =============================================================================
  306. Write-Host "================================================================" -ForegroundColor Cyan
  307. Write-Host " Installation complete!" -ForegroundColor Green
  308. Write-Host "================================================================" -ForegroundColor Cyan
  309. Write-Host ""
  310. Write-Host "Restart Claude Code to load the new extensions." -ForegroundColor Yellow
  311. Write-Host ""