session-start.sh 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 graphifyy; 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. REPO_DIR="${_repo_dir:-}"
  76. unset _claude_real _repo_dir
  77. # Quick passive token cost estimate (Pro session budget = ~11k tokens)
  78. _passive_t=0
  79. detect_superpowers 2>/dev/null && _passive_t=$((_passive_t + 800))
  80. detect_gstack 2>/dev/null && _passive_t=$((_passive_t + 2750))
  81. detect_frontend_design 2>/dev/null && _passive_t=$((_passive_t + 200))
  82. detect_plugin_dev 2>/dev/null && _passive_t=$((_passive_t + 100))
  83. detect_uiux_pro_max 2>/dev/null && _passive_t=$((_passive_t + 400))
  84. detect_context7 2>/dev/null && _passive_t=$((_passive_t + 200))
  85. detect_ruflo 2>/dev/null && _passive_t=$((_passive_t + 1000))
  86. detect_graphifyy 2>/dev/null && _passive_t=$((_passive_t + 300))
  87. _budget_pct=$((_passive_t * 100 / 11000))
  88. if [ "$_budget_pct" -gt 50 ]; then
  89. TOKEN_WARN="⚠️ ~${_passive_t}t passif (${_budget_pct}% budget)"
  90. elif [ "$_budget_pct" -gt 25 ]; then
  91. TOKEN_WARN="~${_passive_t}t passif (${_budget_pct}% budget)"
  92. else
  93. TOKEN_WARN=""
  94. fi
  95. unset _passive_t _budget_pct
  96. echo ""
  97. echo "┌─ Claude Code config ──────────────────────────────────┐"
  98. printf "│ ✅ ON : %-40s│\n" "security-guidance rtk superpowers"
  99. # Plugin display — all plugins shown, split across 2 lines if >4
  100. _active_count=${#TOGGLE_ACTIVE[@]}
  101. _inactive_count=${#TOGGLE_INACTIVE[@]}
  102. if [ "$_active_count" -eq 0 ]; then
  103. printf "│ 🟢 ON : %-40s│\n" "none"
  104. elif [ "$_active_count" -le 4 ]; then
  105. printf "│ 🟢 ON : %-40s│\n" "$ACTIVE_STR"
  106. else
  107. # Split: first 4 on line 1, rest on continuation line
  108. _line1="${TOGGLE_ACTIVE[0]} ${TOGGLE_ACTIVE[1]} ${TOGGLE_ACTIVE[2]} ${TOGGLE_ACTIVE[3]}"
  109. _rest=("${TOGGLE_ACTIVE[@]:4}")
  110. _line2="${_rest[*]}"
  111. printf "│ 🟢 ON : %-40s│\n" "$_line1"
  112. printf "│ %-40s│\n" "$_line2"
  113. unset _line1 _line2 _rest
  114. fi
  115. if [ "$_inactive_count" -eq 0 ]; then
  116. printf "│ ⚫ OFF : %-40s│\n" "none"
  117. elif [ "$_inactive_count" -le 4 ]; then
  118. printf "│ ⚫ OFF : %-40s│\n" "$INACTIVE_STR"
  119. else
  120. _line1="${TOGGLE_INACTIVE[0]} ${TOGGLE_INACTIVE[1]} ${TOGGLE_INACTIVE[2]} ${TOGGLE_INACTIVE[3]}"
  121. _rest=("${TOGGLE_INACTIVE[@]:4}")
  122. _line2="${_rest[*]}"
  123. printf "│ ⚫ OFF : %-40s│\n" "$_line1"
  124. printf "│ %-40s│\n" "$_line2"
  125. unset _line1 _line2 _rest
  126. fi
  127. unset _active_count _inactive_count
  128. printf "│ 🖥️ CLI : %-40s│\n" "$GSD_STATUS"
  129. [ -n "$TOKEN_WARN" ] && printf "│ 💰 %-44s│\n" "${TOKEN_WARN:0:44}"
  130. printf "│ 📦 v%-45s│\n" "$CONFIG_VERSION"
  131. # Version check: compare local vs remote (non-blocking)
  132. _remote_ver=""
  133. if [ -n "$REPO_DIR" ] && [ -d "$REPO_DIR/.git" ]; then
  134. _remote_ver=$(cd "$REPO_DIR" 2>/dev/null && git fetch origin --quiet 2>/dev/null && git show origin/master:version.txt 2>/dev/null || true)
  135. fi
  136. if [ -n "$_remote_ver" ] && [ "$_remote_ver" != "$CONFIG_VERSION" ]; then
  137. printf "│ 🔄 update available: v%-27s│\n" "$_remote_ver"
  138. fi
  139. unset _remote_ver REPO_DIR
  140. echo "│ 💡 /plugin-check before starting a new project │"
  141. echo "│ 🩺 /health to run full diagnostic │"
  142. echo "└───────────────────────────────────────────────────┘"
  143. echo ""
  144. unset TOKEN_WARN