session-start-codex 1.0 KB

1234567891011121314151617181920212223242526
  1. #!/usr/bin/env bash
  2. # Codex SessionStart hook for superpowers plugin
  3. set -euo pipefail
  4. SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
  5. PLUGIN_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
  6. using_superpowers_content=$(cat "${PLUGIN_ROOT}/skills/using-superpowers/SKILL.md" 2>&1 || echo "Error reading using-superpowers skill")
  7. escape_for_json() {
  8. local s="$1"
  9. s="${s//\\/\\\\}"
  10. s="${s//\"/\\\"}"
  11. s="${s//$'\n'/\\n}"
  12. s="${s//$'\r'/\\r}"
  13. s="${s//$'\t'/\\t}"
  14. printf '%s' "$s"
  15. }
  16. using_superpowers_escaped=$(escape_for_json "$using_superpowers_content")
  17. session_context="<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, follow the Codex skill-loading instructions in that skill:**\n\n${using_superpowers_escaped}\n</EXTREMELY_IMPORTANT>"
  18. printf '{\n "hookSpecificOutput": {\n "hookEventName": "SessionStart",\n "additionalContext": "%s"\n }\n}\n' "$session_context" | cat
  19. exit 0