detect-plugins.sh 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/usr/bin/env bash
  2. # ============================================================
  3. # lib/detect-plugins.sh — Single source of truth for plugin detection
  4. # Sourced by: session-start.sh, doctor.sh, install-plugins.sh
  5. #
  6. # Each function returns 0 (detected) or 1 (not detected).
  7. # No output — callers handle messaging.
  8. # ============================================================
  9. # --- Always-on plugins ---
  10. detect_rtk() {
  11. command -v rtk &>/dev/null
  12. }
  13. detect_superpowers() {
  14. # Fast check: filesystem (plugin cache)
  15. local cache_dir="$HOME/.claude/plugins/cache"
  16. if [ -d "$cache_dir" ]; then
  17. ls "$cache_dir" 2>/dev/null | grep -qi "superpowers" && return 0
  18. fi
  19. # Slow fallback: CLI (only if fast check fails)
  20. claude plugin list 2>/dev/null | grep -qi "superpowers" && return 0
  21. return 1
  22. }
  23. detect_security_guidance() {
  24. local cache_dir="$HOME/.claude/plugins/cache"
  25. [ -d "$cache_dir" ] && ls "$cache_dir" 2>/dev/null | grep -qi "security-guidance"
  26. }
  27. # --- Toggle plugins ---
  28. detect_gstack() {
  29. [ -d "$HOME/.claude/skills/gstack" ]
  30. }
  31. detect_gsd() {
  32. # GSD v2 (gsd-pi) is a standalone CLI, not a Claude Code plugin.
  33. # Detection: check for 'gsd' binary in PATH.
  34. command -v gsd &>/dev/null
  35. }
  36. detect_frontend_design() {
  37. local cache_dir="$HOME/.claude/plugins/cache"
  38. [ -d "$cache_dir" ] && ls "$cache_dir" 2>/dev/null | grep -qi "frontend-design"
  39. }
  40. detect_plugin_dev() {
  41. # plugin-dev replaces the old "skill-creator" reference
  42. local cache_dir="$HOME/.claude/plugins/cache"
  43. [ -d "$cache_dir" ] && ls "$cache_dir" 2>/dev/null | grep -qi "plugin-dev"
  44. }
  45. detect_uiux_pro_max() {
  46. local cache_dir="$HOME/.claude/plugins/cache"
  47. [ -d "$cache_dir" ] && ls "$cache_dir" 2>/dev/null | grep -qi "ui-ux-pro-max"
  48. }
  49. detect_context7() {
  50. # Fast check: read ~/.claude.json (MCP config) without spawning the claude CLI
  51. local cfg="$HOME/.claude.json"
  52. if [ -f "$cfg" ]; then
  53. grep -q "context7" "$cfg" 2>/dev/null && return 0
  54. fi
  55. # Fallback: ~/.mcp.json (project-scoped MCP config at user level)
  56. local mcp="$HOME/.mcp.json"
  57. if [ -f "$mcp" ]; then
  58. grep -q "context7" "$mcp" 2>/dev/null && return 0
  59. fi
  60. return 1
  61. }
  62. detect_ruflo() {
  63. # 1. Fast: check npm global binary
  64. command -v ruflo &>/dev/null && return 0
  65. # 2. Fast: check MCP config files (ruflo or ruvnet/claude-flow variants)
  66. for _cfg in "$HOME/.claude.json" "$HOME/.mcp.json"; do
  67. [ -f "$_cfg" ] && grep -qi "ruflo\|ruvnet\|claude-flow" "$_cfg" 2>/dev/null && return 0
  68. done
  69. # 3. Slow fallback: claude mcp list (only if fast checks fail, spawns subprocess)
  70. command -v claude &>/dev/null && claude mcp list 2>/dev/null | grep -qi "ruflo" && return 0
  71. return 1
  72. }