detect-plugins.sh 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. compgen -G "$cache_dir"/*superpowers* &>/dev/null && 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" ] && compgen -G "$cache_dir"/*security-guidance* &>/dev/null
  26. }
  27. # --- Toggle plugins ---
  28. detect_gstack() {
  29. # gstack is exposed via per-skill symlinks (browse, canary, qa, …);
  30. # the legacy top-level symlink was removed to avoid duplicate entries.
  31. # Detect by checking any of its individual skills.
  32. [ -L "$HOME/.claude/skills/browse" ] || [ -L "$HOME/.claude/skills/qa" ]
  33. }
  34. detect_gsd() {
  35. # GSD v2 (gsd-pi) is a standalone CLI, not a Claude Code plugin.
  36. # Detection: check for 'gsd' binary in PATH.
  37. command -v gsd &>/dev/null
  38. }
  39. detect_plugin_dev() {
  40. # plugin-dev replaces the old "skill-creator" reference
  41. local cache_dir="$HOME/.claude/plugins/cache"
  42. [ -d "$cache_dir" ] && compgen -G "$cache_dir"/*plugin-dev* &>/dev/null
  43. }
  44. detect_uiux_pro_max() {
  45. local cache_dir="$HOME/.claude/plugins/cache"
  46. [ -d "$cache_dir" ] && compgen -G "$cache_dir"/*ui-ux-pro-max* &>/dev/null
  47. }
  48. detect_context7() {
  49. # Context7 CLI (ctx7) — installed globally via npm
  50. command -v ctx7 &>/dev/null
  51. }
  52. detect_graphifyy() {
  53. # Graphifyy — codebase knowledge graph, installed via pipx
  54. command -v graphify &>/dev/null
  55. }
  56. # --- Plan detection ---
  57. detect_plan() {
  58. # Detect Claude plan: max, pro, or free.
  59. # Checks ~/.claude.json for model access hints.
  60. # Returns plan name on stdout, always exits 0.
  61. local claude_json="$HOME/.claude.json"
  62. if [ -f "$claude_json" ]; then
  63. # Max plan: has opus model access or max flag
  64. if grep -q '"planType".*"max"' "$claude_json" 2>/dev/null; then
  65. echo "max"; return 0
  66. fi
  67. # Check cached features for max indicators
  68. if grep -q '"tengu_cobalt_compass": true' "$claude_json" 2>/dev/null \
  69. && grep -q '"tengu_harbor": true' "$claude_json" 2>/dev/null; then
  70. echo "max"; return 0
  71. fi
  72. fi
  73. # Fallback: check if claude CLI reports plan
  74. local plan
  75. plan=$(claude config get planType 2>/dev/null || true)
  76. case "$plan" in
  77. max|Max|MAX) echo "max" ;;
  78. pro|Pro|PRO) echo "pro" ;;
  79. free|Free|FREE) echo "free" ;;
  80. *) echo "pro" ;; # default assumption
  81. esac
  82. }