From b0afa2c7ebd42644d385f73466a643f3cd4e77ca Mon Sep 17 00:00:00 2001 From: joegoldin Date: Sat, 18 Oct 2025 12:32:16 -0700 Subject: [PATCH] fix: windows compatible startup hook --- hooks/hooks.json | 2 +- hooks/session-start.cmd | 63 +++++++++++++++++++++++++++++++++++++++++ hooks/session-start.sh | 34 ---------------------- 3 files changed, 64 insertions(+), 35 deletions(-) create mode 100755 hooks/session-start.cmd delete mode 100755 hooks/session-start.sh diff --git a/hooks/hooks.json b/hooks/hooks.json index 17e0ac8..b0a7fe7 100644 --- a/hooks/hooks.json +++ b/hooks/hooks.json @@ -6,7 +6,7 @@ "hooks": [ { "type": "command", - "command": "${CLAUDE_PLUGIN_ROOT}/hooks/session-start.sh" + "command": "\"${CLAUDE_PLUGIN_ROOT}/hooks/session-start.cmd\"" } ] } diff --git a/hooks/session-start.cmd b/hooks/session-start.cmd new file mode 100755 index 0000000..4234f7c --- /dev/null +++ b/hooks/session-start.cmd @@ -0,0 +1,63 @@ +:<<"::CMDLITERAL" +@ECHO OFF +GOTO :CMDSCRIPT +::CMDLITERAL + +# ============================================================================== +# Bash/sh section - runs on Unix/Linux/macOS +# ============================================================================== + +set -euo pipefail + +# Determine plugin root directory +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)" +PLUGIN_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" + +# Check if legacy skills directory exists and build warning +warning_message="" +legacy_skills_dir="${HOME}/.config/superpowers/skills" +if [ -d "$legacy_skills_dir" ]; then + warning_message="\n\nIN 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" +fi + +# Read using-superpowers content +using_superpowers_content=$(cat "${PLUGIN_ROOT}/skills/using-superpowers/SKILL.md" 2>&1 || echo "Error reading using-superpowers skill") + +# Escape outputs for JSON +using_superpowers_escaped=$(echo "$using_superpowers_content" | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | awk '{printf "%s\\n", $0}') +warning_escaped=$(echo "$warning_message" | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | awk '{printf "%s\\n", $0}') + +# Output context injection as JSON +cat <\nYou have superpowers.\n\n**The content below is from skills/using-superpowers/SKILL.md - your introduction to using skills:**\n\n${using_superpowers_escaped}\n\n${warning_escaped}\n" + } +} +EOF + +exit 0 + +:CMDSCRIPT +REM ============================================================================== +REM Windows cmd.exe section - runs on Windows +REM ============================================================================== + +SETLOCAL EnableDelayedExpansion + +REM Determine plugin root directory +SET "SCRIPT_DIR=%~dp0" +SET "PLUGIN_ROOT=%SCRIPT_DIR%.." + +REM Check if legacy skills directory exists and build warning +SET "warning_message=" +SET "legacy_skills_dir=%USERPROFILE%\.config\superpowers\skills" +IF EXIST "%legacy_skills_dir%" ( + SET "warning_message=\n\nIN 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" +) + +REM Call PowerShell to handle the JSON generation (it's much better at this) +powershell -NoProfile -ExecutionPolicy Bypass -Command "$scriptDir = '%SCRIPT_DIR%'; $pluginRoot = '%PLUGIN_ROOT%'; $warningMessage = '%warning_message%'; $skillFile = Join-Path $pluginRoot 'skills\using-superpowers\SKILL.md'; if (Test-Path $skillFile) { $skillContent = Get-Content -Path $skillFile -Raw -Encoding UTF8 } else { $skillContent = 'Error: using-superpowers skill file not found' }; $contextContent = '\nYou have superpowers.\n\n**The content below is from skills/using-superpowers/SKILL.md - your introduction to using skills:**\n\n' + $skillContent + '\n\n' + $warningMessage + '\n'; $output = @{ hookSpecificOutput = @{ hookEventName = 'SessionStart'; additionalContext = $contextContent } }; $output | ConvertTo-Json -Depth 10 -Compress:$false" + +EXIT /B 0 diff --git a/hooks/session-start.sh b/hooks/session-start.sh deleted file mode 100755 index b864540..0000000 --- a/hooks/session-start.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env bash -# SessionStart hook for superpowers plugin - -set -euo pipefail - -# Determine plugin root directory -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)" -PLUGIN_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" - -# Check if legacy skills directory exists and build warning -warning_message="" -legacy_skills_dir="${HOME}/.config/superpowers/skills" -if [ -d "$legacy_skills_dir" ]; then - warning_message="\n\nIN 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" -fi - -# Read using-superpowers content -using_superpowers_content=$(cat "${PLUGIN_ROOT}/skills/using-superpowers/SKILL.md" 2>&1 || echo "Error reading using-superpowers skill") - -# Escape outputs for JSON -using_superpowers_escaped=$(echo "$using_superpowers_content" | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | awk '{printf "%s\\n", $0}') -warning_escaped=$(echo "$warning_message" | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | awk '{printf "%s\\n", $0}') - -# Output context injection as JSON -cat <\nYou have superpowers.\n\n**The content below is from skills/using-superpowers/SKILL.md - your introduction to using skills:**\n\n${using_superpowers_escaped}\n\n${warning_escaped}\n" - } -} -EOF - -exit 0