Skip to content

Commit bff22cd

Browse files
committed
Add Windows support via PowerShell scripts
This adds native Windows support to the superpowers plugin by creating PowerShell equivalents of the bash scripts. Changes: - Add hooks/session-start.ps1 for Windows SessionStart hook - Add lib/initialize-skills.ps1 for Windows skills initialization - Update hooks/hooks.json to detect platform and use appropriate script - Windows (win32): uses PowerShell scripts - macOS/Linux (darwin/linux): uses existing bash scripts The PowerShell scripts provide the same functionality as the bash versions: - Load and inject skills context on session start - Clone and update the superpowers-skills repository - Handle legacy installation migration - Offer GitHub fork option when gh CLI is available Tested on Windows 10/11 with successful JSON output generation.
1 parent 10afd4e commit bff22cd

File tree

3 files changed

+160
-1
lines changed

3 files changed

+160
-1
lines changed

hooks/hooks.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
"hooks": [
77
{
88
"type": "command",
9-
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/session-start.sh"
9+
"command": "powershell -ExecutionPolicy Bypass -File \"${CLAUDE_PLUGIN_ROOT}/hooks/session-start.ps1\"",
10+
"platforms": ["win32"]
11+
},
12+
{
13+
"type": "command",
14+
"command": "${CLAUDE_PLUGIN_ROOT}/hooks/session-start.sh",
15+
"platforms": ["darwin", "linux"]
1016
}
1117
]
1218
}

hooks/session-start.ps1

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# SessionStart hook for superpowers plugin (Windows PowerShell version)
2+
3+
# Determine plugin root directory
4+
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
5+
$pluginRoot = Split-Path -Parent $scriptDir
6+
7+
# Check if legacy skills directory exists and build warning
8+
$warningMessage = ""
9+
$legacySkillsDir = Join-Path $env:USERPROFILE ".config\superpowers\skills"
10+
if (Test-Path $legacySkillsDir) {
11+
$warningMessage = "`n`n⚠️ **WARNING:** Superpowers now uses Claude Code's skills system. Custom skills in ~/.config/superpowers/skills will not be read."
12+
}
13+
14+
# Read using-superpowers content
15+
$skillFile = Join-Path $pluginRoot "skills\using-superpowers\SKILL.md"
16+
if (-not (Test-Path $skillFile)) {
17+
$output = @{
18+
hookSpecificOutput = @{
19+
hookEventName = "SessionStart"
20+
additionalContext = "Error reading using-superpowers skill"
21+
}
22+
}
23+
$output | ConvertTo-Json -Compress
24+
exit 1
25+
}
26+
27+
$usingSuperpowersContent = Get-Content $skillFile -Raw
28+
29+
# Build the additional context
30+
$additionalContext = @"
31+
<EXTREMELY_IMPORTANT>
32+
You have superpowers.
33+
34+
**The content below is from skills/using-superpowers/SKILL.md - your introduction to using skills:**
35+
36+
$usingSuperpowersContent
37+
38+
$warningMessage
39+
</EXTREMELY_IMPORTANT>
40+
"@
41+
42+
# Output context injection as JSON
43+
$output = @{
44+
hookSpecificOutput = @{
45+
hookEventName = "SessionStart"
46+
additionalContext = $additionalContext
47+
}
48+
}
49+
50+
$output | ConvertTo-Json -Depth 10
51+
exit 0

lib/initialize-skills.ps1

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Initialize or update superpowers skills repository (Windows PowerShell version)
2+
3+
$skillsDir = Join-Path $env:USERPROFILE ".config\superpowers\skills"
4+
$skillsRepo = "https://github.com/obra/superpowers-skills.git"
5+
6+
# Check if skills directory exists and is a valid git repo
7+
if (Test-Path (Join-Path $skillsDir ".git")) {
8+
Set-Location $skillsDir
9+
10+
# Get the remote name for the current tracking branch
11+
$trackingFull = git rev-parse --abbrev-ref --symbolic-full-name '@{u}' 2>$null
12+
$trackingRemote = ""
13+
if ($trackingFull) {
14+
$trackingRemote = ($trackingFull -split '/')[0]
15+
}
16+
17+
# Fetch from tracking remote if set, otherwise try upstream then origin
18+
if ($trackingRemote) {
19+
git fetch $trackingRemote 2>$null | Out-Null
20+
} else {
21+
git fetch upstream 2>$null | Out-Null
22+
if ($LASTEXITCODE -ne 0) {
23+
git fetch origin 2>$null | Out-Null
24+
}
25+
}
26+
27+
# Check if we can fast-forward
28+
$local = git rev-parse '@' 2>$null
29+
$remote = git rev-parse '@{u}' 2>$null
30+
$base = git merge-base '@' '@{u}' 2>$null
31+
32+
# Try to fast-forward merge first
33+
if ($local -and $remote -and ($local -ne $remote)) {
34+
# Check if we can fast-forward (local is ancestor of remote)
35+
if ($local -eq $base) {
36+
# Fast-forward merge is possible - local is behind
37+
Write-Host "Updating skills to latest version..."
38+
$mergeOutput = git merge --ff-only '@{u}' 2>&1
39+
if ($LASTEXITCODE -eq 0) {
40+
Write-Host "✓ Skills updated successfully"
41+
Write-Host "SKILLS_UPDATED=true"
42+
} else {
43+
Write-Host "Failed to update skills"
44+
}
45+
} elseif ($remote -ne $base) {
46+
# Remote has changes (local is behind or diverged)
47+
Write-Host "SKILLS_BEHIND=true"
48+
}
49+
# If REMOTE = BASE, local is ahead - no action needed
50+
}
51+
52+
exit 0
53+
}
54+
55+
# Skills directory doesn't exist or isn't a git repo - initialize it
56+
Write-Host "Initializing skills repository..."
57+
58+
# Handle migration from old installation
59+
$oldGitDir = Join-Path $env:USERPROFILE ".config\superpowers\.git"
60+
if (Test-Path $oldGitDir) {
61+
Write-Host "Found existing installation. Backing up..."
62+
Move-Item $oldGitDir "$oldGitDir.bak" -Force -ErrorAction SilentlyContinue
63+
64+
$oldSkillsDir = Join-Path $env:USERPROFILE ".config\superpowers\skills"
65+
if (Test-Path $oldSkillsDir) {
66+
Move-Item $oldSkillsDir "$oldSkillsDir.bak" -Force -ErrorAction SilentlyContinue
67+
Write-Host "Your old skills are in $env:USERPROFILE\.config\superpowers\skills.bak"
68+
}
69+
}
70+
71+
# Clone the skills repository
72+
$configDir = Join-Path $env:USERPROFILE ".config\superpowers"
73+
if (-not (Test-Path $configDir)) {
74+
New-Item -ItemType Directory -Path $configDir -Force | Out-Null
75+
}
76+
77+
git clone $skillsRepo $skillsDir
78+
79+
Set-Location $skillsDir
80+
81+
# Check if gh CLI is installed
82+
$ghExists = Get-Command gh -ErrorAction SilentlyContinue
83+
if ($ghExists) {
84+
Write-Host ""
85+
Write-Host "GitHub CLI detected. Would you like to fork superpowers-skills?"
86+
Write-Host "Forking allows you to share skill improvements with the community."
87+
Write-Host ""
88+
$reply = Read-Host "Fork superpowers-skills? (y/N)"
89+
90+
if ($reply -match '^[Yy]$') {
91+
gh repo fork obra/superpowers-skills --remote=true
92+
Write-Host "Forked! You can now contribute skills back to the community."
93+
} else {
94+
git remote add upstream $skillsRepo
95+
}
96+
} else {
97+
# No gh, just set up upstream remote
98+
git remote add upstream $skillsRepo
99+
}
100+
101+
Write-Host "Skills repository initialized at $skillsDir"
102+
exit 0

0 commit comments

Comments
 (0)