install.sh 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. # Skip _lib (shared library used by multiple skills, not a skill itself)
  115. [ "$skill_name" = "_lib" ] && continue
  116. # Remove existing and copy fresh. Strip trailing slash from $skill_dir
  117. # so cp creates a subdirectory rather than merging contents (the *.*/* glob
  118. # always returns paths with trailing slashes, which makes cp behave as if
  119. # asked to copy contents — that's a long-standing bug we just fixed).
  120. rm -rf "$CLAUDE_DIR/skills/$skill_name"
  121. cp -r "${skill_dir%/}" "$CLAUDE_DIR/skills/"
  122. echo -e " ${GREEN}$skill_name/${NC}"
  123. done
  124. echo ""
  125. # =============================================================================
  126. # AGENTS - Copy all agent files
  127. # =============================================================================
  128. echo -e "${BLUE}Installing agents...${NC}"
  129. for file in "$PROJECT_ROOT/agents"/*.md; do
  130. [ -f "$file" ] || continue
  131. cp "$file" "$CLAUDE_DIR/agents/"
  132. echo -e " ${GREEN}$(basename "$file")${NC}"
  133. done
  134. echo ""
  135. # =============================================================================
  136. # RULES - Copy all rule files
  137. # =============================================================================
  138. echo -e "${BLUE}Installing rules...${NC}"
  139. for file in "$PROJECT_ROOT/rules"/*.md; do
  140. [ -f "$file" ] || continue
  141. cp "$file" "$CLAUDE_DIR/rules/"
  142. echo -e " ${GREEN}$(basename "$file")${NC}"
  143. done
  144. echo ""
  145. # =============================================================================
  146. # OUTPUT STYLES - Copy all output style files
  147. # =============================================================================
  148. echo -e "${BLUE}Installing output styles...${NC}"
  149. if [ -d "$PROJECT_ROOT/output-styles" ]; then
  150. for file in "$PROJECT_ROOT/output-styles"/*.md; do
  151. [ -f "$file" ] || continue
  152. cp "$file" "$CLAUDE_DIR/output-styles/"
  153. echo -e " ${GREEN}$(basename "$file")${NC}"
  154. done
  155. fi
  156. echo ""
  157. # =============================================================================
  158. # PIGEON - Global install (scripts + hook config hint)
  159. # =============================================================================
  160. echo -e "${BLUE}Installing pigeon (pmail)...${NC}"
  161. # Clean up old agentmail install if present
  162. if [ -d "$CLAUDE_DIR/agentmail" ]; then
  163. rm -rf "$CLAUDE_DIR/agentmail"
  164. echo -e " ${RED}Removed old agentmail/ (renamed to pigeon/)${NC}"
  165. fi
  166. mkdir -p "$CLAUDE_DIR/pigeon"
  167. if [ -f "$PROJECT_ROOT/skills/pigeon/scripts/mail-db.sh" ]; then
  168. cp "$PROJECT_ROOT/skills/pigeon/scripts/mail-db.sh" "$CLAUDE_DIR/pigeon/"
  169. make_executable "$CLAUDE_DIR/pigeon/mail-db.sh"
  170. echo -e " ${GREEN}mail-db.sh${NC}"
  171. fi
  172. if [ -f "$PROJECT_ROOT/hooks/check-mail.sh" ]; then
  173. cp "$PROJECT_ROOT/hooks/check-mail.sh" "$CLAUDE_DIR/pigeon/"
  174. make_executable "$CLAUDE_DIR/pigeon/check-mail.sh"
  175. echo -e " ${GREEN}check-mail.sh${NC}"
  176. fi
  177. # Migrate stale agentmail hook path → pigeon
  178. if grep -q "agentmail/check-mail.sh" "$CLAUDE_DIR/settings.json" 2>/dev/null; then
  179. sed -i 's|agentmail/check-mail\.sh|pigeon/check-mail.sh|g' "$CLAUDE_DIR/settings.json"
  180. echo -e " ${GREEN}Migrated agentmail hook → pigeon in settings.json${NC}"
  181. fi
  182. # Check if hook is already configured (pigeon path)
  183. if grep -q "pigeon/check-mail.sh" "$CLAUDE_DIR/settings.json" 2>/dev/null; then
  184. echo -e " ${GREEN}Hook already configured in settings.json${NC}"
  185. else
  186. echo ""
  187. echo -e " ${YELLOW}To enable automatic pmail notifications, add this to ~/.claude/settings.json:${NC}"
  188. echo ""
  189. echo ' "hooks": {'
  190. echo ' "PreToolUse": [{'
  191. echo ' "matcher": "*",'
  192. echo ' "hooks": [{'
  193. echo ' "type": "command",'
  194. echo ' "command": "bash \"$HOME/.claude/pigeon/check-mail.sh\"",'
  195. echo ' "timeout": 5'
  196. echo ' }]'
  197. echo ' }]'
  198. echo ' }'
  199. echo ""
  200. echo -e " ${YELLOW}Without this, pigeon works but you must check manually (pigeon read).${NC}"
  201. fi
  202. echo ""
  203. # =============================================================================
  204. # AUTO-SKILL - Global install (tracking + evaluation hooks)
  205. # =============================================================================
  206. echo -e "${BLUE}Installing auto-skill...${NC}"
  207. mkdir -p "$CLAUDE_DIR/auto-skill"
  208. for script in track-tools.sh evaluate.sh; do
  209. if [ -f "$PROJECT_ROOT/skills/auto-skill/scripts/$script" ]; then
  210. cp "$PROJECT_ROOT/skills/auto-skill/scripts/$script" "$CLAUDE_DIR/auto-skill/"
  211. make_executable "$CLAUDE_DIR/auto-skill/$script"
  212. echo -e " ${GREEN}$script${NC}"
  213. fi
  214. done
  215. # Check if hooks are already configured
  216. if grep -q "auto-skill" "$CLAUDE_DIR/settings.json" 2>/dev/null; then
  217. echo -e " ${GREEN}Hooks already configured in settings.json${NC}"
  218. else
  219. echo ""
  220. echo -e " ${YELLOW}To enable automatic skill suggestions, add these hooks to ~/.claude/settings.json:${NC}"
  221. echo ""
  222. echo ' "PostToolUse": [{ "matcher": "*", "hooks": [{'
  223. echo ' "type": "command",'
  224. echo ' "command": "bash \"$HOME/.claude/auto-skill/track-tools.sh\"", "timeout": 2'
  225. echo ' }] }],'
  226. echo ' "Stop": [{ "hooks": [{'
  227. echo ' "type": "command",'
  228. echo ' "command": "bash \"$HOME/.claude/auto-skill/evaluate.sh\"", "timeout": 5'
  229. echo ' }] }]'
  230. echo ""
  231. echo -e " ${YELLOW}Without this, /auto-skill still works but won't suggest automatically.${NC}"
  232. fi
  233. echo ""
  234. # =============================================================================
  235. # SUMMARY
  236. # =============================================================================
  237. echo -e "${BLUE}════════════════════════════════════════════════════════════════${NC}"
  238. echo -e " ${GREEN}Installation complete!${NC}"
  239. echo -e "${BLUE}════════════════════════════════════════════════════════════════${NC}"
  240. echo ""
  241. echo -e "${YELLOW}Restart Claude Code to load the new extensions.${NC}"
  242. echo ""