install.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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="$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; 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. # Deprecated agents (v3.0): folded into their -ops skill twins
  54. "$CLAUDE_DIR/agents/python-expert.md"
  55. "$CLAUDE_DIR/agents/typescript-expert.md"
  56. "$CLAUDE_DIR/agents/javascript-expert.md"
  57. "$CLAUDE_DIR/agents/go-expert.md"
  58. "$CLAUDE_DIR/agents/rust-expert.md"
  59. "$CLAUDE_DIR/agents/react-expert.md"
  60. "$CLAUDE_DIR/agents/vue-expert.md"
  61. "$CLAUDE_DIR/agents/astro-expert.md"
  62. "$CLAUDE_DIR/agents/laravel-expert.md"
  63. "$CLAUDE_DIR/agents/sql-expert.md"
  64. "$CLAUDE_DIR/agents/postgres-expert.md"
  65. )
  66. # Renamed skills: -patterns -> -ops (March 2026)
  67. renamed_skills=(
  68. cli-patterns
  69. mcp-patterns
  70. python-async-patterns
  71. python-cli-patterns
  72. python-database-patterns
  73. python-fastapi-patterns
  74. python-observability-patterns
  75. python-pytest-patterns
  76. python-typing-patterns
  77. rest-patterns
  78. security-patterns
  79. sql-patterns
  80. tailwind-patterns
  81. testing-patterns
  82. )
  83. for old_skill in "${renamed_skills[@]}"; do
  84. old_path="$CLAUDE_DIR/skills/$old_skill"
  85. if [ -d "$old_path" ]; then
  86. rm -rf "$old_path"
  87. echo -e " ${RED}Removed renamed: $old_skill (now ${old_skill%-patterns}-ops)${NC}"
  88. fi
  89. done
  90. for item in "${deprecated_items[@]}"; do
  91. if [ -e "$item" ]; then
  92. rm -rf "$item"
  93. echo -e " ${RED}Removed: $item${NC}"
  94. fi
  95. done
  96. echo ""
  97. # =============================================================================
  98. # COMMANDS - Only copy commands that haven't been migrated to skills
  99. # =============================================================================
  100. echo -e "${BLUE}Installing commands...${NC}"
  101. # Commands that should NOT be copied (migrated to skills)
  102. skip_commands=("review.md" "testgen.md")
  103. for file in "$PROJECT_ROOT/commands"/*.md; do
  104. [ -f "$file" ] || continue
  105. filename=$(basename "$file")
  106. # Skip migrated commands
  107. skip=false
  108. for skip_cmd in "${skip_commands[@]}"; do
  109. if [ "$filename" = "$skip_cmd" ]; then
  110. skip=true
  111. break
  112. fi
  113. done
  114. # Skip archive directory contents
  115. [[ "$file" == *"/archive/"* ]] && continue
  116. if [ "$skip" = false ]; then
  117. cp "$file" "$CLAUDE_DIR/commands/"
  118. echo -e " ${GREEN}$filename${NC}"
  119. fi
  120. done
  121. echo ""
  122. # =============================================================================
  123. # SKILLS - Copy all skill directories
  124. # =============================================================================
  125. echo -e "${BLUE}Installing skills...${NC}"
  126. for skill_dir in "$PROJECT_ROOT/skills"/*/; do
  127. [ -d "$skill_dir" ] || continue
  128. skill_name=$(basename "$skill_dir")
  129. # Skip _lib (shared library used by multiple skills, not a skill itself)
  130. [ "$skill_name" = "_lib" ] && continue
  131. # Remove existing and copy fresh. Strip trailing slash from $skill_dir
  132. # so cp creates a subdirectory rather than merging contents (the *.*/* glob
  133. # always returns paths with trailing slashes, which makes cp behave as if
  134. # asked to copy contents — that's a long-standing bug we just fixed).
  135. rm -rf "$CLAUDE_DIR/skills/$skill_name"
  136. cp -r "${skill_dir%/}" "$CLAUDE_DIR/skills/"
  137. echo -e " ${GREEN}$skill_name/${NC}"
  138. done
  139. echo ""
  140. # =============================================================================
  141. # AGENTS - Copy all agent files
  142. # =============================================================================
  143. echo -e "${BLUE}Installing agents...${NC}"
  144. for file in "$PROJECT_ROOT/agents"/*.md; do
  145. [ -f "$file" ] || continue
  146. cp "$file" "$CLAUDE_DIR/agents/"
  147. echo -e " ${GREEN}$(basename "$file")${NC}"
  148. done
  149. echo ""
  150. # =============================================================================
  151. # RULES - Copy all rule files
  152. # =============================================================================
  153. echo -e "${BLUE}Installing rules...${NC}"
  154. for file in "$PROJECT_ROOT/rules"/*.md; do
  155. [ -f "$file" ] || continue
  156. cp "$file" "$CLAUDE_DIR/rules/"
  157. echo -e " ${GREEN}$(basename "$file")${NC}"
  158. done
  159. echo ""
  160. # =============================================================================
  161. # OUTPUT STYLES - Copy all output style files
  162. # =============================================================================
  163. echo -e "${BLUE}Installing output styles...${NC}"
  164. if [ -d "$PROJECT_ROOT/output-styles" ]; then
  165. for file in "$PROJECT_ROOT/output-styles"/*.md; do
  166. [ -f "$file" ] || continue
  167. cp "$file" "$CLAUDE_DIR/output-styles/"
  168. echo -e " ${GREEN}$(basename "$file")${NC}"
  169. done
  170. fi
  171. echo ""
  172. # =============================================================================
  173. # PIGEON - Global install (scripts + hook config hint)
  174. # =============================================================================
  175. echo -e "${BLUE}Installing pigeon (pmail)...${NC}"
  176. # Clean up old agentmail install if present
  177. if [ -d "$CLAUDE_DIR/agentmail" ]; then
  178. rm -rf "$CLAUDE_DIR/agentmail"
  179. echo -e " ${RED}Removed old agentmail/ (renamed to pigeon/)${NC}"
  180. fi
  181. mkdir -p "$CLAUDE_DIR/pigeon"
  182. if [ -f "$PROJECT_ROOT/skills/pigeon/scripts/mail-db.sh" ]; then
  183. cp "$PROJECT_ROOT/skills/pigeon/scripts/mail-db.sh" "$CLAUDE_DIR/pigeon/"
  184. make_executable "$CLAUDE_DIR/pigeon/mail-db.sh"
  185. echo -e " ${GREEN}mail-db.sh${NC}"
  186. fi
  187. if [ -f "$PROJECT_ROOT/hooks/check-mail.sh" ]; then
  188. cp "$PROJECT_ROOT/hooks/check-mail.sh" "$CLAUDE_DIR/pigeon/"
  189. make_executable "$CLAUDE_DIR/pigeon/check-mail.sh"
  190. echo -e " ${GREEN}check-mail.sh${NC}"
  191. fi
  192. # Migrate stale agentmail hook path → pigeon
  193. if grep -q "agentmail/check-mail.sh" "$CLAUDE_DIR/settings.json" 2>/dev/null; then
  194. sed -i 's|agentmail/check-mail\.sh|pigeon/check-mail.sh|g' "$CLAUDE_DIR/settings.json"
  195. echo -e " ${GREEN}Migrated agentmail hook → pigeon in settings.json${NC}"
  196. fi
  197. # Check if hook is already configured (pigeon path)
  198. if grep -q "pigeon/check-mail.sh" "$CLAUDE_DIR/settings.json" 2>/dev/null; then
  199. echo -e " ${GREEN}Hook already configured in settings.json${NC}"
  200. else
  201. echo ""
  202. echo -e " ${YELLOW}To enable automatic pmail notifications, add this to ~/.claude/settings.json:${NC}"
  203. echo ""
  204. echo ' "hooks": {'
  205. echo ' "PreToolUse": [{'
  206. echo ' "matcher": "*",'
  207. echo ' "hooks": [{'
  208. echo ' "type": "command",'
  209. echo ' "command": "bash \"$HOME/.claude/pigeon/check-mail.sh\"",'
  210. echo ' "timeout": 5'
  211. echo ' }]'
  212. echo ' }]'
  213. echo ' }'
  214. echo ""
  215. echo -e " ${YELLOW}Without this, pigeon works but you must check manually (pigeon read).${NC}"
  216. fi
  217. echo ""
  218. # =============================================================================
  219. # AUTO-SKILL - Global install (tracking + evaluation hooks)
  220. # =============================================================================
  221. echo -e "${BLUE}Installing auto-skill...${NC}"
  222. mkdir -p "$CLAUDE_DIR/auto-skill"
  223. for script in track-tools.sh evaluate.sh; do
  224. if [ -f "$PROJECT_ROOT/skills/auto-skill/scripts/$script" ]; then
  225. cp "$PROJECT_ROOT/skills/auto-skill/scripts/$script" "$CLAUDE_DIR/auto-skill/"
  226. make_executable "$CLAUDE_DIR/auto-skill/$script"
  227. echo -e " ${GREEN}$script${NC}"
  228. fi
  229. done
  230. # Check if hooks are already configured
  231. if grep -q "auto-skill" "$CLAUDE_DIR/settings.json" 2>/dev/null; then
  232. echo -e " ${GREEN}Hooks already configured in settings.json${NC}"
  233. else
  234. echo ""
  235. echo -e " ${YELLOW}To enable automatic skill suggestions, add these hooks to ~/.claude/settings.json:${NC}"
  236. echo ""
  237. echo ' "PostToolUse": [{ "matcher": "*", "hooks": [{'
  238. echo ' "type": "command",'
  239. echo ' "command": "bash \"$HOME/.claude/auto-skill/track-tools.sh\"", "timeout": 2'
  240. echo ' }] }],'
  241. echo ' "Stop": [{ "hooks": [{'
  242. echo ' "type": "command",'
  243. echo ' "command": "bash \"$HOME/.claude/auto-skill/evaluate.sh\"", "timeout": 5'
  244. echo ' }] }]'
  245. echo ""
  246. echo -e " ${YELLOW}Without this, /auto-skill still works but won't suggest automatically.${NC}"
  247. fi
  248. echo ""
  249. # =============================================================================
  250. # SUMMARY
  251. # =============================================================================
  252. echo -e "${BLUE}════════════════════════════════════════════════════════════════${NC}"
  253. echo -e " ${GREEN}Installation complete!${NC}"
  254. echo -e "${BLUE}════════════════════════════════════════════════════════════════${NC}"
  255. echo ""
  256. echo -e "${YELLOW}Restart Claude Code to load the new extensions.${NC}"
  257. echo ""