session-start.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env bash
  2. # SessionStart hook for superpowers plugin
  3. set -euo pipefail
  4. # Determine plugin root directory
  5. SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
  6. PLUGIN_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
  7. # Check if legacy skills directory exists and build warning
  8. warning_message=""
  9. legacy_skills_dir="${HOME}/.config/superpowers/skills"
  10. if [ -d "$legacy_skills_dir" ]; then
  11. warning_message="\n\n<important-reminder>IN YOUR FIRST REPLY AFTER SEEING THIS MESSAGE YOU MUST TELL THE USER:⚠️ **WARNING:** Superpowers now uses Claude Code's skills system. Custom skills in ~/.config/superpowers/skills will not be read. Move custom skills to ~/.claude/skills instead. To make this message go away, remove ~/.config/superpowers/skills</important-reminder>"
  12. fi
  13. # Read using-superpowers content
  14. using_superpowers_content=$(cat "${PLUGIN_ROOT}/skills/using-superpowers/SKILL.md" 2>&1 || echo "Error reading using-superpowers skill")
  15. # Escape outputs for JSON using pure bash
  16. escape_for_json() {
  17. local input="$1"
  18. local output=""
  19. local i char
  20. for (( i=0; i<${#input}; i++ )); do
  21. char="${input:$i:1}"
  22. case "$char" in
  23. $'\\') output+='\\' ;;
  24. '"') output+='\"' ;;
  25. $'\n') output+='\n' ;;
  26. $'\r') output+='\r' ;;
  27. $'\t') output+='\t' ;;
  28. *) output+="$char" ;;
  29. esac
  30. done
  31. printf '%s' "$output"
  32. }
  33. using_superpowers_escaped=$(escape_for_json "$using_superpowers_content")
  34. warning_escaped=$(escape_for_json "$warning_message")
  35. # Output context injection as JSON
  36. cat <<EOF
  37. {
  38. "hookSpecificOutput": {
  39. "hookEventName": "SessionStart",
  40. "additionalContext": "<EXTREMELY_IMPORTANT>\nYou have superpowers.\n\n**Below is the full content of your 'superpowers:using-superpowers' skill - your introduction to using skills. For all other skills, use the 'Skill' tool:**\n\n${using_superpowers_escaped}\n\n${warning_escaped}\n</EXTREMELY_IMPORTANT>"
  41. }
  42. }
  43. EOF
  44. exit 0