detect-plugins.sh 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. # --- Toggle plugins ---
  24. detect_gstack() {
  25. [ -d "$HOME/.claude/skills/gstack" ]
  26. }
  27. detect_gsd() {
  28. # GSD v2 (gsd-pi) is a standalone CLI, not a Claude Code plugin.
  29. # Detection: check for 'gsd' binary in PATH.
  30. command -v gsd &>/dev/null
  31. }
  32. # NOTE: frontend-design is a built-in Claude Code skill (/mnt/skills/public/frontend-design/).
  33. # It is always available and does not need detection. No detect_frontend_design() function needed.
  34. # NOTE: skill-creator is a built-in Claude Code skill (/mnt/skills/examples/skill-creator/).
  35. # It is always available and does not need detection. No detect_skill_creator() function needed.
  36. # NOTE: security-guidance does not exist as a plugin. RTK covers security hooks.
  37. # NOTE: pr-review-toolkit does not exist as a marketplace plugin.
  38. detect_uiux_pro_max() {
  39. local cache_dir="$HOME/.claude/plugins/cache"
  40. [ -d "$cache_dir" ] && ls "$cache_dir" 2>/dev/null | grep -qi "ui-ux-pro-max"
  41. }
  42. detect_context7() {
  43. # Fast check: read ~/.claude.json (MCP config) without spawning the claude CLI
  44. local cfg="$HOME/.claude.json"
  45. if [ -f "$cfg" ]; then
  46. grep -q "context7" "$cfg" 2>/dev/null && return 0
  47. fi
  48. # Fallback: ~/.mcp.json (project-scoped MCP config at user level)
  49. local mcp="$HOME/.mcp.json"
  50. if [ -f "$mcp" ]; then
  51. grep -q "context7" "$mcp" 2>/dev/null && return 0
  52. fi
  53. return 1
  54. }
  55. detect_ruflo() {
  56. # 1. Fast: check npm global binary
  57. command -v ruflo &>/dev/null && return 0
  58. # 2. Fast: check MCP config files (ruflo or ruvnet/claude-flow variants)
  59. for _cfg in "$HOME/.claude.json" "$HOME/.mcp.json"; do
  60. [ -f "$_cfg" ] && grep -qi "ruflo\|ruvnet\|claude-flow" "$_cfg" 2>/dev/null && return 0
  61. done
  62. # 3. Slow fallback: claude mcp list (only if fast checks fail, spawns subprocess)
  63. command -v claude &>/dev/null && claude mcp list 2>/dev/null | grep -qi "ruflo" && return 0
  64. return 1
  65. }