session-start.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env bash
  2. # SessionStart hook for superpowers plugin
  3. set -euo pipefail
  4. # Run personal superpowers setup
  5. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  6. setup_output=$("${SCRIPT_DIR}/setup-personal-superpowers.sh" 2>&1 || echo "setup_failed=true")
  7. # Use same directory resolution as setup script
  8. SUPERPOWERS_DIR="${PERSONAL_SUPERPOWERS_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/superpowers}"
  9. # Check if GitHub CLI is available and setup succeeded
  10. github_recommendation=""
  11. if echo "$setup_output" | grep -q "github_cli_available=true"; then
  12. if [[ ! -d "$SUPERPOWERS_DIR/.git" ]]; then
  13. # This should not happen, but handle gracefully
  14. github_recommendation=""
  15. else
  16. # Check if remote already exists
  17. if ! (cd "$SUPERPOWERS_DIR" && git remote get-url origin &>/dev/null); then
  18. github_recommendation="\n\n💡 Want to share your personal skills on GitHub? Superpowers are best when everyone can learn from them! I can create a 'personal-superpowers' repo for you."
  19. fi
  20. fi
  21. elif echo "$setup_output" | grep -q "setup_failed=true"; then
  22. github_recommendation="\n\n⚠️ Personal superpowers setup encountered an issue. Please file a bug at https://github.com/obra/superpowers/issues"
  23. fi
  24. # Output context injection as JSON
  25. cat <<EOF
  26. {
  27. "hookSpecificOutput": {
  28. "hookEventName": "SessionStart",
  29. "additionalContext": "<EXTREMELY_IMPORTANT>\nYou have superpowers.\n\n**RIGHT NOW, go read**: @${CLAUDE_PLUGIN_ROOT}/skills/getting-started/SKILL.md${github_recommendation}\n</EXTREMELY_IMPORTANT>"
  30. }
  31. }
  32. EOF
  33. exit 0