session-start.sh 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #!/usr/bin/env bash
  2. # ============================================================
  3. # Claude Code — Session start plugin status
  4. # Runs once per session. Zero API calls. Filesystem only.
  5. # ============================================================
  6. # ── Quick health check (filesystem only, no subprocesses) ──
  7. BROKEN=()
  8. for f in CLAUDE.md settings.json agents skills; do
  9. [ ! -e "$HOME/.claude/$f" ] && BROKEN+=("$f")
  10. done
  11. if [ ${#BROKEN[@]} -gt 0 ]; then
  12. # Try to find the repo path from an existing symlink
  13. _repo_hint=""
  14. for _probe in CLAUDE.md settings.json; do
  15. if [ -L "$HOME/.claude/$_probe" ]; then
  16. _repo_hint="$(cd "$(dirname "$(readlink "$HOME/.claude/$_probe")")" 2>/dev/null && pwd)"
  17. break
  18. fi
  19. done
  20. _fix_cmd="${_repo_hint:+cd $_repo_hint && }bash link.sh"
  21. echo ""
  22. echo "┌─ ⚠️ CONFIG ISSUES ────────────────────────────────┐"
  23. for b in "${BROKEN[@]}"; do
  24. printf "│ MISSING: ~/.claude/%-30s│\n" "$b"
  25. done
  26. printf "│ → %-47s│\n" "$_fix_cmd"
  27. echo "│ → /health for full diagnostic │"
  28. echo "└───────────────────────────────────────────────────┘"
  29. unset _repo_hint _fix_cmd
  30. fi
  31. # ── Load shared detection library ──
  32. _lib="$(dirname "${BASH_SOURCE[0]}")/../lib/detect-plugins.sh"
  33. if [ -f "$_lib" ]; then
  34. # shellcheck source=../lib/detect-plugins.sh
  35. source "$_lib"
  36. else
  37. echo "⚠️ lib/detect-plugins.sh not found — config broken, run: bash link.sh"
  38. exit 0
  39. fi
  40. unset _lib
  41. # ── Toggle plugin detection ──
  42. TOGGLE_ACTIVE=()
  43. TOGGLE_INACTIVE=()
  44. for plugin in gstack uiux_pro_max context7 ruflo; do
  45. # Map function name to display name
  46. case "$plugin" in
  47. uiux_pro_max) display="ui-ux-pro-max" ;;
  48. *) display="$plugin" ;;
  49. esac
  50. if "detect_$plugin" 2>/dev/null; then
  51. TOGGLE_ACTIVE+=("$display")
  52. else
  53. TOGGLE_INACTIVE+=("$display")
  54. fi
  55. done
  56. # --- Format output ---
  57. ACTIVE_STR="${TOGGLE_ACTIVE[*]:-none}"
  58. INACTIVE_STR="${TOGGLE_INACTIVE[*]:-none}"
  59. # GSD v2 — standalone CLI (not a Claude Code plugin — shown separately)
  60. if detect_gsd 2>/dev/null; then
  61. GSD_STATUS="gsd v2 ✓"
  62. else
  63. GSD_STATUS="gsd v2 ✗ (npm install -g gsd-pi)"
  64. fi
  65. # Version detection: follow CLAUDE.md symlink back to repo, then read version.txt
  66. _claude_real="$(readlink "$HOME/.claude/CLAUDE.md" 2>/dev/null || true)"
  67. if [ -n "$_claude_real" ]; then
  68. _repo_dir="$(cd "$(dirname "$_claude_real")" 2>/dev/null && pwd)"
  69. CONFIG_VERSION=$(cat "$_repo_dir/version.txt" 2>/dev/null || echo "?")
  70. else
  71. CONFIG_VERSION="?"
  72. fi
  73. unset _claude_real _repo_dir
  74. # Quick passive token cost estimate (Pro session budget = ~11k tokens)
  75. _passive_t=0
  76. detect_superpowers 2>/dev/null && _passive_t=$((_passive_t + 800))
  77. detect_gstack 2>/dev/null && _passive_t=$((_passive_t + 2750))
  78. detect_uiux_pro_max 2>/dev/null && _passive_t=$((_passive_t + 400))
  79. detect_context7 2>/dev/null && _passive_t=$((_passive_t + 200))
  80. detect_ruflo 2>/dev/null && _passive_t=$((_passive_t + 1000))
  81. _budget_pct=$((_passive_t * 100 / 11000))
  82. if [ "$_budget_pct" -gt 50 ]; then
  83. TOKEN_WARN="⚠️ ~${_passive_t}t passif (${_budget_pct}% budget)"
  84. elif [ "$_budget_pct" -gt 25 ]; then
  85. TOKEN_WARN="~${_passive_t}t passif (${_budget_pct}% budget)"
  86. else
  87. TOKEN_WARN=""
  88. fi
  89. unset _passive_t _budget_pct
  90. echo ""
  91. echo "┌─ Claude Code config ──────────────────────────────────┐"
  92. printf "│ ✅ ON : %-40s│\n" "rtk superpowers"
  93. printf "│ 🔵 BUILT-IN: %-35s│\n" "frontend-design skill-creator"
  94. # Plugin display — all plugins shown, split across 2 lines if >4
  95. _active_count=${#TOGGLE_ACTIVE[@]}
  96. _inactive_count=${#TOGGLE_INACTIVE[@]}
  97. if [ "$_active_count" -eq 0 ]; then
  98. printf "│ 🟢 ON : %-40s│\n" "none"
  99. elif [ "$_active_count" -le 4 ]; then
  100. printf "│ 🟢 ON : %-40s│\n" "$ACTIVE_STR"
  101. else
  102. # Split: first 4 on line 1, rest on continuation line
  103. _line1="${TOGGLE_ACTIVE[0]} ${TOGGLE_ACTIVE[1]} ${TOGGLE_ACTIVE[2]} ${TOGGLE_ACTIVE[3]}"
  104. _rest=("${TOGGLE_ACTIVE[@]:4}")
  105. _line2="${_rest[*]}"
  106. printf "│ 🟢 ON : %-40s│\n" "$_line1"
  107. printf "│ %-40s│\n" "$_line2"
  108. unset _line1 _line2 _rest
  109. fi
  110. if [ "$_inactive_count" -eq 0 ]; then
  111. printf "│ ⚫ OFF : %-40s│\n" "none"
  112. elif [ "$_inactive_count" -le 4 ]; then
  113. printf "│ ⚫ OFF : %-40s│\n" "$INACTIVE_STR"
  114. else
  115. _line1="${TOGGLE_INACTIVE[0]} ${TOGGLE_INACTIVE[1]} ${TOGGLE_INACTIVE[2]} ${TOGGLE_INACTIVE[3]}"
  116. _rest=("${TOGGLE_INACTIVE[@]:4}")
  117. _line2="${_rest[*]}"
  118. printf "│ ⚫ OFF : %-40s│\n" "$_line1"
  119. printf "│ %-40s│\n" "$_line2"
  120. unset _line1 _line2 _rest
  121. fi
  122. unset _active_count _inactive_count
  123. printf "│ 🖥️ CLI : %-40s│\n" "$GSD_STATUS"
  124. [ -n "$TOKEN_WARN" ] && printf "│ 💰 %-44s│\n" "${TOKEN_WARN:0:44}"
  125. printf "│ 📦 v%-45s│\n" "$CONFIG_VERSION"
  126. echo "│ 💡 /plugin-check before starting a new project │"
  127. echo "│ 🩺 /health to run full diagnostic │"
  128. echo "└───────────────────────────────────────────────────┘"
  129. echo ""
  130. unset TOKEN_WARN