install.sh 9.9 KB

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