detect-plugins.sh 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. [ -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_plugin_dev() {
  37. # plugin-dev replaces the old "skill-creator" reference
  38. local cache_dir="$HOME/.claude/plugins/cache"
  39. [ -d "$cache_dir" ] && compgen -G "$cache_dir"/*plugin-dev* &>/dev/null
  40. }
  41. detect_uiux_pro_max() {
  42. local cache_dir="$HOME/.claude/plugins/cache"
  43. [ -d "$cache_dir" ] && compgen -G "$cache_dir"/*ui-ux-pro-max* &>/dev/null
  44. }
  45. detect_context7() {
  46. # Context7 CLI (ctx7) — installed globally via npm
  47. command -v ctx7 &>/dev/null
  48. }
  49. detect_graphifyy() {
  50. # Graphifyy — codebase knowledge graph, installed via pipx
  51. command -v graphify &>/dev/null
  52. }
  53. # --- Plan detection ---
  54. detect_plan() {
  55. # Detect Claude plan: max, pro, or free.
  56. # Checks ~/.claude.json for model access hints.
  57. # Returns plan name on stdout, always exits 0.
  58. local claude_json="$HOME/.claude.json"
  59. if [ -f "$claude_json" ]; then
  60. # Max plan: has opus model access or max flag
  61. if grep -q '"planType".*"max"' "$claude_json" 2>/dev/null; then
  62. echo "max"; return 0
  63. fi
  64. # Check cached features for max indicators
  65. if grep -q '"tengu_cobalt_compass": true' "$claude_json" 2>/dev/null \
  66. && grep -q '"tengu_harbor": true' "$claude_json" 2>/dev/null; then
  67. echo "max"; return 0
  68. fi
  69. fi
  70. # Fallback: check if claude CLI reports plan
  71. local plan
  72. plan=$(claude config get planType 2>/dev/null || true)
  73. case "$plan" in
  74. max|Max|MAX) echo "max" ;;
  75. pro|Pro|PRO) echo "pro" ;;
  76. free|Free|FREE) echo "free" ;;
  77. *) echo "pro" ;; # default assumption
  78. esac
  79. }