2025-10-09 13:11:12 -07:00
#!/usr/bin/env bash
# SessionStart hook for superpowers plugin
2025-10-10 14:01:45 -07:00
set -euo pipefail
2025-10-11 11:14:44 -07:00
# Set SUPERPOWERS_SKILLS_ROOT environment variable
export SUPERPOWERS_SKILLS_ROOT = " ${ HOME } /.config/superpowers/skills"
# Run skills initialization script (handles clone/fetch/notification)
2025-10-10 14:01:45 -07:00
SCRIPT_DIR = " $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd ) "
2025-10-11 11:14:44 -07:00
PLUGIN_ROOT = " $( cd " ${ SCRIPT_DIR } /.." && pwd ) "
init_output = $( " ${ PLUGIN_ROOT } /lib/initialize-skills.sh" 2>& 1 || echo "" )
2025-10-10 22:59:26 -07:00
# Run find-skills to show all available skills
2025-10-11 11:14:44 -07:00
find_skills_output = $( " ${ SUPERPOWERS_SKILLS_ROOT } /skills/using-skills/find-skills" 2>& 1 || echo "Error running find-skills" )
2025-10-10 22:59:26 -07:00
2025-10-11 11:14:44 -07:00
# Read using-skills content (renamed from getting-started)
using_skills_content = $( cat " ${ SUPERPOWERS_SKILLS_ROOT } /skills/using-skills/SKILL.md" 2>& 1 || echo "Error reading using-skills" )
2025-10-10 22:59:26 -07:00
2025-10-11 11:14:44 -07:00
# Escape outputs for JSON
init_escaped = $( echo " $init_output " | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | awk '{printf "%s\\n", $0}' )
2025-10-10 22:59:26 -07:00
find_skills_escaped = $( echo " $find_skills_output " | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | awk '{printf "%s\\n", $0}' )
2025-10-11 11:14:44 -07:00
using_skills_escaped = $( echo " $using_skills_content " | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | awk '{printf "%s\\n", $0}' )
# Build initialization output message if present
init_message = ""
if [ -n " $init_escaped " ] ; then
init_message = " ${ init_escaped } \n\n"
fi
2025-10-10 22:59:26 -07:00
2025-10-09 13:11:12 -07:00
# Output context injection as JSON
2025-10-09 13:18:47 -07:00
cat <<EOF
2025-10-09 13:11:12 -07:00
{
"hookSpecificOutput": {
"hookEventName": "SessionStart",
2025-10-11 11:59:44 -07:00
"additionalContext": "<EXTREMELY_IMPORTANT>\nYou have superpowers.\n\n${init_message}**The content below is from skills/using-skills/SKILL.md - your introduction to using skills:**\n\n${using_skills_escaped}\n\n**Tool paths (use these when you need to search for or run skills):**\n- find-skills: ${SUPERPOWERS_SKILLS_ROOT}/skills/using-skills/find-skills\n- skill-run: ${SUPERPOWERS_SKILLS_ROOT}/skills/using-skills/skill-run\n\n**Skills live in:** ${SUPERPOWERS_SKILLS_ROOT}/skills/ (you work on your own branch and can edit any skill)\n\n**Available skills (output of find-skills):**\n\n${find_skills_escaped}\n</EXTREMELY_IMPORTANT>"
2025-10-09 13:11:12 -07:00
}
}
EOF
exit 0