install.sh 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. #!/usr/bin/env bash
  2. #
  3. # claude-mods Installer (Linux / macOS / Windows Git Bash)
  4. # Copies commands, skills, agents, and rules to ~/.claude/
  5. # Handles cleanup of deprecated items and command-to-skill migrations.
  6. #
  7. # Usage:
  8. # Linux/macOS: ./scripts/install.sh
  9. # Windows Git Bash: bash scripts/install.sh
  10. set -e
  11. BLUE='\033[0;34m'
  12. GREEN='\033[0;32m'
  13. YELLOW='\033[1;33m'
  14. RED='\033[0;31m'
  15. NC='\033[0m'
  16. echo -e "${BLUE}╔══════════════════════════════════════════════════════════════╗${NC}"
  17. echo -e "${BLUE}║ claude-mods Installer (Linux / macOS / Git Bash) ║${NC}"
  18. echo -e "${BLUE}╚══════════════════════════════════════════════════════════════╝${NC}"
  19. echo ""
  20. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  21. PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
  22. CLAUDE_DIR="${CLAUDE_DIR:-$HOME/.claude}"
  23. # Detect Windows (Git Bash / MINGW / MSYS) — chmod is a no-op on NTFS
  24. IS_WINDOWS=false
  25. case "$(uname -s)" in
  26. MINGW*|MSYS*|CYGWIN*) IS_WINDOWS=true ;;
  27. esac
  28. # Wrapper: chmod is meaningful only on Unix
  29. make_executable() {
  30. $IS_WINDOWS || chmod +x "$1"
  31. }
  32. # Ensure ~/.claude directories exist
  33. for dir in commands skills agents rules output-styles hooks; do
  34. mkdir -p "$CLAUDE_DIR/$dir"
  35. done
  36. # =============================================================================
  37. # DEPRECATED ITEMS - Remove these from user's config
  38. # =============================================================================
  39. echo -e "${YELLOW}Cleaning up deprecated items...${NC}"
  40. deprecated_items=(
  41. # Removed commands (migrated to skills or deleted)
  42. "$CLAUDE_DIR/commands/review.md" # Migrated to skill
  43. "$CLAUDE_DIR/commands/testgen.md" # Migrated to skill
  44. "$CLAUDE_DIR/commands/conclave.md" # Deprecated
  45. "$CLAUDE_DIR/commands/pulse.md" # Now a skill only
  46. # Removed skills
  47. "$CLAUDE_DIR/skills/conclave" # Deprecated
  48. "$CLAUDE_DIR/skills/claude-code-templates" # Replaced by skill-creator
  49. "$CLAUDE_DIR/skills/agentmail" # Renamed to pigeon (v2.3.0)
  50. "$CLAUDE_DIR/skills/claude-code-debug" # Merged into claude-code-ops (v3.0)
  51. "$CLAUDE_DIR/skills/claude-code-headless" # Merged into claude-code-ops (v3.0)
  52. "$CLAUDE_DIR/skills/claude-code-hooks" # Merged into claude-code-ops (v3.0)
  53. "$CLAUDE_DIR/skills/dsp-launch" # Superseded by fleet-worker + native background agents (2026-07)
  54. # Deprecated agents (v3.0): folded into their -ops skill twins
  55. "$CLAUDE_DIR/agents/python-expert.md"
  56. "$CLAUDE_DIR/agents/typescript-expert.md"
  57. "$CLAUDE_DIR/agents/javascript-expert.md"
  58. "$CLAUDE_DIR/agents/go-expert.md"
  59. "$CLAUDE_DIR/agents/rust-expert.md"
  60. "$CLAUDE_DIR/agents/react-expert.md"
  61. "$CLAUDE_DIR/agents/vue-expert.md"
  62. "$CLAUDE_DIR/agents/astro-expert.md"
  63. "$CLAUDE_DIR/agents/laravel-expert.md"
  64. "$CLAUDE_DIR/agents/sql-expert.md"
  65. "$CLAUDE_DIR/agents/postgres-expert.md"
  66. "$CLAUDE_DIR/agents/cypress-expert.md" # -> skills/cypress-ops
  67. "$CLAUDE_DIR/agents/cloudflare-expert.md" # -> skills/cloudflare-ops
  68. "$CLAUDE_DIR/agents/wrangler-expert.md" # -> skills/cloudflare-ops
  69. "$CLAUDE_DIR/agents/bash-expert.md" # -> skills/bash-ops
  70. "$CLAUDE_DIR/agents/claude-architect.md" # -> skills/claude-code-ops
  71. "$CLAUDE_DIR/agents/aws-fargate-ecs-expert.md" # -> skills/container-orchestration
  72. "$CLAUDE_DIR/agents/craftcms-expert.md" # -> skills/craftcms-ops
  73. "$CLAUDE_DIR/agents/payloadcms-expert.md" # -> skills/payloadcms-ops
  74. "$CLAUDE_DIR/agents/asus-router-expert.md" # -> skills/asus-router-ops
  75. )
  76. # Renamed skills: -patterns -> -ops (March 2026)
  77. renamed_skills=(
  78. cli-patterns
  79. mcp-patterns
  80. python-async-patterns
  81. python-cli-patterns
  82. python-database-patterns
  83. python-fastapi-patterns
  84. python-observability-patterns
  85. python-pytest-patterns
  86. python-typing-patterns
  87. rest-patterns
  88. security-patterns
  89. sql-patterns
  90. tailwind-patterns
  91. testing-patterns
  92. )
  93. for old_skill in "${renamed_skills[@]}"; do
  94. old_path="$CLAUDE_DIR/skills/$old_skill"
  95. if [ -d "$old_path" ]; then
  96. rm -rf "$old_path"
  97. echo -e " ${RED}Removed renamed: $old_skill (now ${old_skill%-patterns}-ops)${NC}"
  98. fi
  99. done
  100. for item in "${deprecated_items[@]}"; do
  101. if [ -e "$item" ]; then
  102. rm -rf "$item"
  103. echo -e " ${RED}Removed: $item${NC}"
  104. fi
  105. done
  106. echo ""
  107. # =============================================================================
  108. # COMMANDS - Only copy commands that haven't been migrated to skills
  109. # =============================================================================
  110. echo -e "${BLUE}Installing commands...${NC}"
  111. # Commands that should NOT be copied (migrated to skills)
  112. skip_commands=("review.md" "testgen.md")
  113. for file in "$PROJECT_ROOT/commands"/*.md; do
  114. [ -f "$file" ] || continue
  115. filename=$(basename "$file")
  116. # Skip migrated commands
  117. skip=false
  118. for skip_cmd in "${skip_commands[@]}"; do
  119. if [ "$filename" = "$skip_cmd" ]; then
  120. skip=true
  121. break
  122. fi
  123. done
  124. # Skip archive directory contents
  125. [[ "$file" == *"/archive/"* ]] && continue
  126. if [ "$skip" = false ]; then
  127. cp "$file" "$CLAUDE_DIR/commands/"
  128. echo -e " ${GREEN}$filename${NC}"
  129. fi
  130. done
  131. echo ""
  132. # =============================================================================
  133. # SKILLS - Copy all skill directories
  134. # =============================================================================
  135. echo -e "${BLUE}Installing skills...${NC}"
  136. for skill_dir in "$PROJECT_ROOT/skills"/*/; do
  137. [ -d "$skill_dir" ] || continue
  138. skill_name=$(basename "$skill_dir")
  139. # _lib is the shared terminal library (skills/_lib/term.sh) that many skill
  140. # scripts source. It is NOT a skill, but it MUST be refreshed — scripts that
  141. # use newer term.sh features (TERM_DOT, brand glyphs, term_pip_bar) break with
  142. # an "unbound variable" under `set -u` against a stale copy.
  143. if [ "$skill_name" = "_lib" ]; then
  144. rm -rf "$CLAUDE_DIR/skills/_lib"
  145. cp -r "${skill_dir%/}" "$CLAUDE_DIR/skills/"
  146. echo -e " ${GREEN}_lib/${NC} (shared term library)"
  147. continue
  148. fi
  149. # Remove existing and copy fresh. Strip trailing slash from $skill_dir
  150. # so cp creates a subdirectory rather than merging contents (the *.*/* glob
  151. # always returns paths with trailing slashes, which makes cp behave as if
  152. # asked to copy contents — that's a long-standing bug we just fixed).
  153. rm -rf "$CLAUDE_DIR/skills/$skill_name"
  154. cp -r "${skill_dir%/}" "$CLAUDE_DIR/skills/"
  155. echo -e " ${GREEN}$skill_name/${NC}"
  156. done
  157. echo ""
  158. # =============================================================================
  159. # AGENTS - Copy all agent files
  160. # =============================================================================
  161. echo -e "${BLUE}Installing agents...${NC}"
  162. for file in "$PROJECT_ROOT/agents"/*.md; do
  163. [ -f "$file" ] || continue
  164. cp "$file" "$CLAUDE_DIR/agents/"
  165. echo -e " ${GREEN}$(basename "$file")${NC}"
  166. done
  167. echo ""
  168. # =============================================================================
  169. # RULES - Copy all rule files
  170. # =============================================================================
  171. echo -e "${BLUE}Installing rules...${NC}"
  172. for file in "$PROJECT_ROOT/rules"/*.md; do
  173. [ -f "$file" ] || continue
  174. cp "$file" "$CLAUDE_DIR/rules/"
  175. echo -e " ${GREEN}$(basename "$file")${NC}"
  176. done
  177. echo ""
  178. # =============================================================================
  179. # OUTPUT STYLES - Copy all output style files
  180. # =============================================================================
  181. echo -e "${BLUE}Installing output styles...${NC}"
  182. if [ -d "$PROJECT_ROOT/output-styles" ]; then
  183. for file in "$PROJECT_ROOT/output-styles"/*.md; do
  184. [ -f "$file" ] || continue
  185. cp "$file" "$CLAUDE_DIR/output-styles/"
  186. echo -e " ${GREEN}$(basename "$file")${NC}"
  187. done
  188. fi
  189. echo ""
  190. # =============================================================================
  191. # HOOKS - Copy scripts and merge plugin-equivalent wiring into settings.json
  192. # =============================================================================
  193. echo -e "${BLUE}Installing hooks...${NC}"
  194. for file in "$PROJECT_ROOT/hooks"/*.sh; do
  195. [ -f "$file" ] || continue
  196. cp "$file" "$CLAUDE_DIR/hooks/"
  197. make_executable "$CLAUDE_DIR/hooks/$(basename "$file")"
  198. done
  199. # Capability probe, not existence probe: walk/1 needs jq >= 1.6, and a 1.5 jq
  200. # passes `command -v` then crashes mid-install under set -e, leaving hooks
  201. # copied but settings.json unwired (adversarial-review finding, 2026-07).
  202. if echo '{}' | jq -e 'walk(.) | true' >/dev/null 2>&1; then
  203. settings_path="$CLAUDE_DIR/settings.json"
  204. [ -f "$settings_path" ] || printf '{}\n' > "$settings_path"
  205. tmp_settings="$(mktemp)"
  206. jq --arg hook_dir "$CLAUDE_DIR/hooks" --slurpfile desired "$PROJECT_ROOT/hooks/hooks.json" '
  207. # Dedup on the script NAME under hooks/, not the resolved path: a hook
  208. # wired by a plugin install carries the ${CLAUDE_PLUGIN_ROOT}/hooks/
  209. # form and must still count as already-wired (mixed-method double-fire).
  210. def script_name:
  211. .command | sub("^.*hooks[/\\\\]"; "") | sub("\\\"$"; "");
  212. ($desired[0]
  213. | walk(if type == "string" then gsub("\\$\\{CLAUDE_PLUGIN_ROOT\\}/hooks"; $hook_dir) else . end)
  214. ) as $wanted
  215. | .hooks = (.hooks // {})
  216. | reduce ($wanted.hooks | to_entries[]) as $event (.;
  217. reduce $event.value[] as $group (.;
  218. ([.hooks[$event.key][]?.hooks[]?.command // ""]) as $existing
  219. |
  220. ($group.hooks | map(
  221. . as $hook
  222. | ($hook | script_name) as $name
  223. | select(any($existing[]; contains("hooks/" + $name) or contains("hooks\\" + $name)) | not)
  224. )) as $missing
  225. | if ($missing | length) > 0 then
  226. .hooks[$event.key] = ((.hooks[$event.key] // []) + [($group | .hooks = $missing)])
  227. else . end
  228. )
  229. )
  230. ' "$settings_path" > "$tmp_settings"
  231. mv "$tmp_settings" "$settings_path"
  232. echo -e " ${GREEN}Security and peer-guard hooks wired in settings.json${NC}"
  233. else
  234. echo -e " ${YELLOW}jq with walk/1 (>=1.6) not available, skipping hook wiring (plugin installs unaffected)${NC}"
  235. fi
  236. echo ""
  237. # =============================================================================
  238. # PIGEON - Global install (scripts + hook config hint)
  239. # =============================================================================
  240. echo -e "${BLUE}Installing pigeon (pmail)...${NC}"
  241. # Clean up old agentmail install if present
  242. if [ -d "$CLAUDE_DIR/agentmail" ]; then
  243. rm -rf "$CLAUDE_DIR/agentmail"
  244. echo -e " ${RED}Removed old agentmail/ (renamed to pigeon/)${NC}"
  245. fi
  246. mkdir -p "$CLAUDE_DIR/pigeon"
  247. if [ -f "$PROJECT_ROOT/skills/pigeon/scripts/mail-db.sh" ]; then
  248. cp "$PROJECT_ROOT/skills/pigeon/scripts/mail-db.sh" "$CLAUDE_DIR/pigeon/"
  249. make_executable "$CLAUDE_DIR/pigeon/mail-db.sh"
  250. echo -e " ${GREEN}mail-db.sh${NC}"
  251. fi
  252. if [ -f "$PROJECT_ROOT/hooks/check-mail.sh" ]; then
  253. cp "$PROJECT_ROOT/hooks/check-mail.sh" "$CLAUDE_DIR/pigeon/"
  254. make_executable "$CLAUDE_DIR/pigeon/check-mail.sh"
  255. echo -e " ${GREEN}check-mail.sh${NC}"
  256. fi
  257. # Migrate stale agentmail hook path → pigeon
  258. if grep -q "agentmail/check-mail.sh" "$CLAUDE_DIR/settings.json" 2>/dev/null; then
  259. sed -i 's|agentmail/check-mail\.sh|pigeon/check-mail.sh|g' "$CLAUDE_DIR/settings.json"
  260. echo -e " ${GREEN}Migrated agentmail hook → pigeon in settings.json${NC}"
  261. fi
  262. # Check if hook is already configured (pigeon path)
  263. if grep -q "pigeon/check-mail.sh" "$CLAUDE_DIR/settings.json" 2>/dev/null; then
  264. echo -e " ${GREEN}Hook already configured in settings.json${NC}"
  265. else
  266. echo ""
  267. echo -e " ${YELLOW}To enable automatic pmail notifications, add this to ~/.claude/settings.json:${NC}"
  268. echo ""
  269. echo ' "hooks": {'
  270. echo ' "PreToolUse": [{'
  271. echo ' "matcher": "*",'
  272. echo ' "hooks": [{'
  273. echo ' "type": "command",'
  274. echo ' "command": "bash \"$HOME/.claude/pigeon/check-mail.sh\"",'
  275. echo ' "timeout": 5'
  276. echo ' }]'
  277. echo ' }]'
  278. echo ' }'
  279. echo ""
  280. echo -e " ${YELLOW}Without this, pigeon works but you must check manually (pigeon read).${NC}"
  281. fi
  282. echo ""
  283. # =============================================================================
  284. # AUTO-SKILL - Global install (tracking + evaluation hooks)
  285. # =============================================================================
  286. echo -e "${BLUE}Installing auto-skill...${NC}"
  287. mkdir -p "$CLAUDE_DIR/auto-skill"
  288. for script in track-tools.sh evaluate.sh; do
  289. if [ -f "$PROJECT_ROOT/skills/auto-skill/scripts/$script" ]; then
  290. cp "$PROJECT_ROOT/skills/auto-skill/scripts/$script" "$CLAUDE_DIR/auto-skill/"
  291. make_executable "$CLAUDE_DIR/auto-skill/$script"
  292. echo -e " ${GREEN}$script${NC}"
  293. fi
  294. done
  295. # Check if hooks are already configured
  296. if grep -q "auto-skill" "$CLAUDE_DIR/settings.json" 2>/dev/null; then
  297. echo -e " ${GREEN}Hooks already configured in settings.json${NC}"
  298. else
  299. echo ""
  300. echo -e " ${YELLOW}To enable automatic skill suggestions, add these hooks to ~/.claude/settings.json:${NC}"
  301. echo ""
  302. echo ' "PostToolUse": [{ "matcher": "*", "hooks": [{'
  303. echo ' "type": "command",'
  304. echo ' "command": "bash \"$HOME/.claude/auto-skill/track-tools.sh\"", "timeout": 2'
  305. echo ' }] }],'
  306. echo ' "Stop": [{ "hooks": [{'
  307. echo ' "type": "command",'
  308. echo ' "command": "bash \"$HOME/.claude/auto-skill/evaluate.sh\"", "timeout": 5'
  309. echo ' }] }]'
  310. echo ""
  311. echo -e " ${YELLOW}Without this, /auto-skill still works but won't suggest automatically.${NC}"
  312. fi
  313. echo ""
  314. # =============================================================================
  315. # SUMMARY
  316. # =============================================================================
  317. echo -e "${BLUE}════════════════════════════════════════════════════════════════${NC}"
  318. echo -e " ${GREEN}Installation complete!${NC}"
  319. echo -e "${BLUE}════════════════════════════════════════════════════════════════${NC}"
  320. echo ""
  321. echo -e "${YELLOW}Restart Claude Code to load the new extensions.${NC}"
  322. echo ""