session-start.sh 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 frontend_design plugin_dev context7 ruflo; do
  45. # Map function name to display name
  46. case "$plugin" in
  47. uiux_pro_max) display="ui-ux-pro-max" ;;
  48. frontend_design) display="frontend-design" ;;
  49. plugin_dev) display="plugin-dev" ;;
  50. *) display="$plugin" ;;
  51. esac
  52. if "detect_$plugin" 2>/dev/null; then
  53. TOGGLE_ACTIVE+=("$display")
  54. else
  55. TOGGLE_INACTIVE+=("$display")
  56. fi
  57. done
  58. # --- Format output ---
  59. ACTIVE_STR="${TOGGLE_ACTIVE[*]:-none}"
  60. INACTIVE_STR="${TOGGLE_INACTIVE[*]:-none}"
  61. # GSD v2 — standalone CLI (not a Claude Code plugin — shown separately)
  62. if detect_gsd 2>/dev/null; then
  63. GSD_STATUS="gsd v2 ✓"
  64. else
  65. GSD_STATUS="gsd v2 ✗ (npm install -g gsd-pi)"
  66. fi
  67. # Version detection: follow CLAUDE.md symlink back to repo, then read version.txt
  68. _claude_real="$(readlink "$HOME/.claude/CLAUDE.md" 2>/dev/null || true)"
  69. if [ -n "$_claude_real" ]; then
  70. _repo_dir="$(cd "$(dirname "$_claude_real")" 2>/dev/null && pwd)"
  71. CONFIG_VERSION=$(cat "$_repo_dir/version.txt" 2>/dev/null || echo "?")
  72. else
  73. CONFIG_VERSION="?"
  74. fi
  75. unset _claude_real _repo_dir
  76. # Quick passive token cost estimate (Pro session budget = ~11k tokens)
  77. _passive_t=0
  78. detect_superpowers 2>/dev/null && _passive_t=$((_passive_t + 800))
  79. detect_gstack 2>/dev/null && _passive_t=$((_passive_t + 2750))
  80. detect_frontend_design 2>/dev/null && _passive_t=$((_passive_t + 200))
  81. detect_plugin_dev 2>/dev/null && _passive_t=$((_passive_t + 100))
  82. detect_uiux_pro_max 2>/dev/null && _passive_t=$((_passive_t + 400))
  83. detect_context7 2>/dev/null && _passive_t=$((_passive_t + 200))
  84. detect_ruflo 2>/dev/null && _passive_t=$((_passive_t + 1000))
  85. _budget_pct=$((_passive_t * 100 / 11000))
  86. if [ "$_budget_pct" -gt 50 ]; then
  87. TOKEN_WARN="⚠️ ~${_passive_t}t passif (${_budget_pct}% budget)"
  88. elif [ "$_budget_pct" -gt 25 ]; then
  89. TOKEN_WARN="~${_passive_t}t passif (${_budget_pct}% budget)"
  90. else
  91. TOKEN_WARN=""
  92. fi
  93. unset _passive_t _budget_pct
  94. echo ""
  95. echo "┌─ Claude Code config ──────────────────────────────────┐"
  96. printf "│ ✅ ON : %-40s│\n" "security-guidance rtk superpowers"
  97. # Plugin display — all plugins shown, split across 2 lines if >4
  98. _active_count=${#TOGGLE_ACTIVE[@]}
  99. _inactive_count=${#TOGGLE_INACTIVE[@]}
  100. if [ "$_active_count" -eq 0 ]; then
  101. printf "│ 🟢 ON : %-40s│\n" "none"
  102. elif [ "$_active_count" -le 4 ]; then
  103. printf "│ 🟢 ON : %-40s│\n" "$ACTIVE_STR"
  104. else
  105. # Split: first 4 on line 1, rest on continuation line
  106. _line1="${TOGGLE_ACTIVE[0]} ${TOGGLE_ACTIVE[1]} ${TOGGLE_ACTIVE[2]} ${TOGGLE_ACTIVE[3]}"
  107. _rest=("${TOGGLE_ACTIVE[@]:4}")
  108. _line2="${_rest[*]}"
  109. printf "│ 🟢 ON : %-40s│\n" "$_line1"
  110. printf "│ %-40s│\n" "$_line2"
  111. unset _line1 _line2 _rest
  112. fi
  113. if [ "$_inactive_count" -eq 0 ]; then
  114. printf "│ ⚫ OFF : %-40s│\n" "none"
  115. elif [ "$_inactive_count" -le 4 ]; then
  116. printf "│ ⚫ OFF : %-40s│\n" "$INACTIVE_STR"
  117. else
  118. _line1="${TOGGLE_INACTIVE[0]} ${TOGGLE_INACTIVE[1]} ${TOGGLE_INACTIVE[2]} ${TOGGLE_INACTIVE[3]}"
  119. _rest=("${TOGGLE_INACTIVE[@]:4}")
  120. _line2="${_rest[*]}"
  121. printf "│ ⚫ OFF : %-40s│\n" "$_line1"
  122. printf "│ %-40s│\n" "$_line2"
  123. unset _line1 _line2 _rest
  124. fi
  125. unset _active_count _inactive_count
  126. printf "│ 🖥️ CLI : %-40s│\n" "$GSD_STATUS"
  127. [ -n "$TOKEN_WARN" ] && printf "│ 💰 %-44s│\n" "${TOKEN_WARN:0:44}"
  128. printf "│ 📦 v%-45s│\n" "$CONFIG_VERSION"
  129. echo "│ 💡 /plugin-check before starting a new project │"
  130. echo "│ 🩺 /health to run full diagnostic │"
  131. echo "└───────────────────────────────────────────────────┘"
  132. echo ""
  133. unset TOKEN_WARN