11# PowerShell script for Windows setup
22# Run with: powershell -ExecutionPolicy Bypass -File setup.ps1
33
4- Write-Host " Cupcake Evaluation Setup (Windows)" - ForegroundColor Green
5- Write-Host " ==================================`n "
4+ Write-Host " Cupcake Claude Code Evaluation Setup (Windows)" - ForegroundColor Green
5+ Write-Host " =============================================== `n "
66
77# Check if Rust/Cargo is installed
88try {
2525 exit 1
2626}
2727
28- # Check if OPA is installed
29- try {
30- $uvVersion = uv -- version 2> $null
31- Write-Host " ✅ uv found: $uvVersion " - ForegroundColor Green
32- } catch {
33- Write-Host " ❌ uv not found in PATH. Please install OPA:" - ForegroundColor Red
34- Write-Host " https://docs.astral.sh/uv/" - ForegroundColor Yellow
35- exit 1
36- }
28+ # Save current directory
29+ $originalDir = Get-Location
3730
3831# Build Cupcake binary
3932Write-Host " `n Building Cupcake binary..."
@@ -46,23 +39,31 @@ if ($LASTEXITCODE -ne 0) {
4639}
4740Write-Host " ✅ Build complete" - ForegroundColor Green
4841
49- # Add to PATH for this session
50- $cupcakePath = Join-Path (Get-Location ) " target\release"
51- $env: PATH = " $cupcakePath ;$env: PATH "
52- Write-Host " ✅ Added cupcake to PATH for this session" - ForegroundColor Green
42+ # Store the cupcake binary path
43+ $cupcakeBin = Join-Path (Get-Location ) " target\release\cupcake.exe"
44+ Write-Host " ✅ Using cupcake binary at: $cupcakeBin " - ForegroundColor Green
5345
54- # Return to eval directory
55- Pop -Location
46+ # Return to original directory
47+ Set -Location $originalDir
5648
57- # Initialize Cupcake project
58- Write-Host " `n Initializing Cupcake project..."
59- cupcake init -- harness claude
49+ # Initialize Cupcake project using the explicit path
50+ Write-Host " `n Initializing Cupcake project with Claude Code harness ..."
51+ & $cupcakeBin init -- harness claude
6052if ($LASTEXITCODE -ne 0 ) {
6153 Write-Host " ❌ Project initialization failed" - ForegroundColor Red
6254 exit 1
6355}
6456Write-Host " ✅ Project initialized" - ForegroundColor Green
6557
58+ # Update settings.json to use the full path to the cupcake binary
59+ # This ensures Claude Code can find cupcake even if it's not in PATH
60+ Write-Host " `n Updating settings.json with full binary path..."
61+ $settingsPath = " .claude\settings.json"
62+ $settingsContent = Get-Content $settingsPath - Raw
63+ $settingsContent = $settingsContent -replace " cupcake eval" , " $cupcakeBin eval"
64+ $settingsContent | Out-File - FilePath $settingsPath - Encoding UTF8 - NoNewline
65+ Write-Host " ✅ Hooks configured with: $cupcakeBin " - ForegroundColor Green
66+
6667# Copy example policies to Claude Code policies directory
6768Write-Host " `n Copying example policies..."
6869Copy-Item - Path " ..\..\fixtures\security_policy.rego" - Destination " .cupcake\policies\claude\" - Force
@@ -72,85 +73,18 @@ Write-Host "✅ Example policies copied" -ForegroundColor Green
7273
7374Write-Host " ✅ Builtins configured (protected_paths, git_pre_check, rulebook_security_guardrails)" - ForegroundColor Green
7475
75- # Compile policies to WASM (Claude Code policies + shared helpers)
76- Write-Host " `n Compiling Claude Code policies to WASM..."
77- opa build - t wasm - e cupcake/ system/ evaluate .cupcake/ policies/ claude/ .cupcake/ policies/ helpers/
78- if ($LASTEXITCODE -ne 0 ) {
79- Write-Host " ❌ Policy compilation failed" - ForegroundColor Red
80- exit 1
81- }
82- Write-Host " ✅ Policies compiled to bundle.tar.gz" - ForegroundColor Green
83-
84- # Create Claude Code settings directory and hooks integration
85- Write-Host " `n Setting up Claude Code hooks integration..."
86- New-Item - ItemType Directory - Force - Path " .claude" | Out-Null
87-
88- # Get absolute paths
89- $manifestPath = Resolve-Path " ..\..\..\Cargo.toml"
90- $opaDir = Split-Path (Get-Command opa).Source - Parent
91-
92- # Create Claude Code settings with Windows paths
93- $settingsContent = @"
94- {
95- "hooks": {
96- "PreToolUse": [
97- {
98- "matcher": "*",
99- "hooks": [
100- {
101- "type": "command",
102- "command": "cargo run --manifest-path `" $manifestPath `" -- eval --harness claude --log-level info --debug-files",
103- "timeout": 120,
104- "env": {
105- "PATH": "$opaDir ;%PATH%"
106- }
107- }
108- ]
109- }
110- ],
111- "PostToolUse": [
112- {
113- "matcher": "*",
114- "hooks": [
115- {
116- "type": "command",
117- "command": "cargo run --manifest-path `" $manifestPath `" -- eval --harness claude --log-level info --debug-files",
118- "timeout": 120,
119- "env": {
120- "PATH": "$opaDir ;%PATH%"
121- }
122- }
123- ]
124- }
125- ],
126- "UserPromptSubmit": [
127- {
128- "hooks": [
129- {
130- "type": "command",
131- "command": "cargo run --manifest-path `" $manifestPath `" -- eval --harness claude --log-level info --debug-files",
132- "timeout": 120,
133- "env": {
134- "PATH": "$opaDir ;%PATH%"
135- }
136- }
137- ]
138- }
139- ]
140- }
141- }
142- "@
143-
144- $settingsContent | Out-File - FilePath " .claude\settings.json" - Encoding UTF8
145- Write-Host " ✅ Claude Code hooks configured" - ForegroundColor Green
76+ # Note: WASM compilation is handled automatically by 'cupcake eval' at runtime
77+ # No manual 'opa build' step needed - cupcake compiles policies including helpers
14678
14779Write-Host " `n 🎉 Setup complete!" - ForegroundColor Green
14880Write-Host " `n Next steps:" - ForegroundColor Cyan
14981Write-Host " 1. Add cupcake to your PATH:" - ForegroundColor White
15082Write-Host " `$ env:PATH = `" $ ( Resolve-Path ..\..\..\target\release) ;`$ env:PATH`" " - ForegroundColor Yellow
151- Write-Host " 2. Start Claude Code in this directory " - ForegroundColor White
83+ Write-Host " 2. Open this directory in Claude Code " - ForegroundColor White
15284Write-Host " 3. Try running commands that trigger policies" - ForegroundColor White
153- Write-Host " `n Example commands to test:" - ForegroundColor Cyan
85+ Write-Host " `n Manual testing with test events:" - ForegroundColor Cyan
86+ Write-Host " cupcake eval --harness claude < test-events/shell-rm.json" - ForegroundColor Yellow
87+ Write-Host " `n Example commands to test in Claude Code:" - ForegroundColor Cyan
15488Write-Host " - ls (safe, should work)" - ForegroundColor White
15589Write-Host " - Remove-Item -Recurse -Force C:\temp\test (dangerous, should block)" - ForegroundColor White
15690Write-Host " - Edit C:\Windows\System32\drivers\etc\hosts (system file, should block)" - ForegroundColor White
0 commit comments