-
Notifications
You must be signed in to change notification settings - Fork 458
fix: windows compatible startup hook #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -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\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>" | ||||||
| fi | ||||||
|
|
||||||
| # Read using-superpowers content | ||||||
| using_superpowers_content=$(cat "${PLUGIN_ROOT}/skills/using-superpowers/SKILL.md" 2>&1 || echo "Error reading using-superpowers skill") | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix error output handling. The -using_superpowers_content=$(cat "${PLUGIN_ROOT}/skills/using-superpowers/SKILL.md" 2>&1 || echo "Error reading using-superpowers skill")
+using_superpowers_content=$(cat "${PLUGIN_ROOT}/skills/using-superpowers/SKILL.md" 2>/dev/null || echo "Error reading using-superpowers skill")📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
|
|
||||||
| # 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}') | ||||||
|
Comment on lines
+27
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainJSON escaping is insufficient and risks invalid output. The manual escaping only handles backslashes and quotes, missing critical JSON special characters:
This creates a critical cross-platform inconsistency: the Windows path uses Consider using -# 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 <<EOF
-{
- "hookSpecificOutput": {
- "hookEventName": "SessionStart",
- "additionalContext": "<EXTREMELY_IMPORTANT>\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</EXTREMELY_IMPORTANT>"
- }
-}
-EOF
+# Build additionalContext with proper newline handling
+additional_context="<EXTREMELY_IMPORTANT>\nYou have superpowers.\n\n**The content below is from skills/using-superpowers/SKILL.md - your introduction to using skills:**\n\n${using_superpowers_content}\n\n${warning_message}\n</EXTREMELY_IMPORTANT>"
+
+# Output context injection as JSON using jq for proper escaping
+jq -n --arg ctx "$additional_context" '{
+ hookSpecificOutput: {
+ hookEventName: "SessionStart",
+ additionalContext: $ctx
+ }
+}'If 🏁 Script executed: #!/bin/bash
# Check if jq is mentioned elsewhere in the codebase or if it's an available dependency
rg -i '\bjq\b' --type sh --type json --type mdLength of output: 0 I need to gather more information about the codebase environment and the actual implementation. Let me search for dependency files and examine the actual file structure. Length of output: 0 🏁 Script executed: #!/bin/bash
# Check the actual hooks/session-start.cmd file to understand context
cat hooks/session-start.cmd 2>/dev/null || echo "File not found at that location"Length of output: 3617 🏁 Script executed: #!/bin/bash
# Search more broadly for jq in all configuration and script types
rg 'jq' --type sh --type json --type md --type yaml --type toml --type xml -iLength of output: 0 Rewritten review comment: JSON escaping is insufficient and creates invalid output with multi-line content. The bash implementation (lines 27-28) only escapes backslashes and quotes, missing critical issues:
The proposed Alternative 1: Use printf with proper escaping before JSON: additional_context=$(printf '%s' "$using_superpowers_content" | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | sed 's/$/\\n/' | tr -d '\n')Alternative 2: Build the JSON structure using only variables and avoid heredoc substitution entirely. Verify that the chosen solution produces valid JSON when SKILL.md contains newlines or special characters. 🤖 Prompt for AI Agents |
||||||
|
|
||||||
| # Output context injection as JSON | ||||||
| cat <<EOF | ||||||
| { | ||||||
| "hookSpecificOutput": { | ||||||
| "hookEventName": "SessionStart", | ||||||
| "additionalContext": "<EXTREMELY_IMPORTANT>\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</EXTREMELY_IMPORTANT>" | ||||||
| } | ||||||
| } | ||||||
| EOF | ||||||
|
|
||||||
| exit 0 | ||||||
|
|
||||||
| :CMDSCRIPT | ||||||
| REM ============================================================================== | ||||||
| REM Windows cmd.exe section - runs on Windows | ||||||
| REM ============================================================================== | ||||||
|
|
||||||
| SETLOCAL EnableDelayedExpansion | ||||||
joegoldin marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
|
||||||
| 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\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>" | ||||||
| ) | ||||||
|
|
||||||
| 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 = '<EXTREMELY_IMPORTANT>\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</EXTREMELY_IMPORTANT>'; $output = @{ hookSpecificOutput = @{ hookEventName = 'SessionStart'; additionalContext = $contextContent } }; $output | ConvertTo-Json -Depth 10 -Compress:$false" | ||||||
joegoldin marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
|
||||||
joegoldin marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| EXIT /B 0 | ||||||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.