-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
164 lines (143 loc) · 5.03 KB
/
install.ps1
File metadata and controls
164 lines (143 loc) · 5.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# OpenClaw Guardian Safety Agent — Install Script (Windows)
# Usage: .\install.ps1 -OpenClawRoot C:\path\to\openclaw
param(
[Parameter(Mandatory=$true)]
[string]$OpenClawRoot
)
$ErrorActionPreference = "Stop"
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$PatchDir = $ScriptDir
# Resolve to absolute path.
$OpenClawRoot = Resolve-Path $OpenClawRoot
if (-not (Test-Path "$OpenClawRoot\package.json")) {
Write-Error "Error: $OpenClawRoot does not look like an OpenClaw repo (package.json not found)"
exit 1
}
if (-not (Test-Path "$OpenClawRoot\src\security")) {
Write-Error "Error: $OpenClawRoot\src\security not found. Is this a valid OpenClaw source tree?"
exit 1
}
Write-Host "=== OpenClaw Guardian Safety Agent - Install ===" -ForegroundColor Cyan
Write-Host "Target: $OpenClawRoot"
Write-Host ""
# --- Step 1: Copy new files ---
Write-Host "[1/3] Copying new guardian files..." -ForegroundColor Yellow
$NewFiles = @(
"src\security\guardian-types.ts",
"src\security\guardian-agent.ts",
"src\security\guardian-audit.ts",
"src\security\guardian-risk.ts",
"src\security\guardian-agent.test.ts",
"src\security\guardian-audit.test.ts",
"src\security\guardian-config.test.ts",
"src\security\guardian-hook.test.ts",
"src\security\guardian-risk.test.ts",
"src\security\guardian-scenario.test.ts"
)
foreach ($f in $NewFiles) {
$dest = Join-Path $OpenClawRoot $f
$src = Join-Path $PatchDir "files\$f"
if (Test-Path $dest) {
Write-Host " Warning: $f already exists, backing up to $f.bak" -ForegroundColor DarkYellow
Copy-Item $dest "$dest.bak" -Force
}
Copy-Item $src $dest -Force
Write-Host " + $f" -ForegroundColor Green
}
# --- Step 2: Apply patches to modified files ---
Write-Host ""
Write-Host "[2/3] Applying patches to existing files..." -ForegroundColor Yellow
$PatchFile = Join-Path $PatchDir "patches\modified-files.patch"
if (-not (Test-Path $PatchFile)) {
Write-Error "Error: Patch file not found: $PatchFile"
exit 1
}
Push-Location $OpenClawRoot
try {
# Check if git is available and this is a git repo.
$gitAvailable = $false
try {
git rev-parse --git-dir 2>$null | Out-Null
$gitAvailable = $LASTEXITCODE -eq 0
} catch {
$gitAvailable = $false
}
if ($gitAvailable) {
git apply --check $PatchFile 2>$null
if ($LASTEXITCODE -eq 0) {
git apply $PatchFile
Write-Host " Applied via git apply" -ForegroundColor Green
} else {
Write-Host " git apply --check failed. Trying with --3way..." -ForegroundColor DarkYellow
git apply --3way $PatchFile 2>$null
if ($LASTEXITCODE -eq 0) {
Write-Host " Applied via git apply --3way" -ForegroundColor Green
} else {
Write-Error @"
Error: Patch cannot be applied cleanly.
Your OpenClaw version may be incompatible, or the patch is already applied.
Try applying manually: cd $OpenClawRoot; git apply --reject $PatchFile
"@
exit 1
}
}
} else {
Write-Error "Error: Git is not available or this is not a git repository. Git is required for patch application."
exit 1
}
} finally {
Pop-Location
}
# --- Step 3: Verify ---
Write-Host ""
Write-Host "[3/3] Verifying installation..." -ForegroundColor Yellow
$VerifyFiles = @(
"src\security\guardian-types.ts",
"src\security\guardian-agent.ts",
"src\security\guardian-audit.ts",
"src\security\guardian-risk.ts"
)
$AllOk = $true
foreach ($f in $VerifyFiles) {
if (Test-Path (Join-Path $OpenClawRoot $f)) {
Write-Host " OK: $f" -ForegroundColor Green
} else {
Write-Host " MISSING: $f" -ForegroundColor Red
$AllOk = $false
}
}
$hookFile = Join-Path $OpenClawRoot "src\agents\pi-tools.before-tool-call.ts"
if ((Get-Content $hookFile -Raw) -match "requiresGuardianReview") {
Write-Host " OK: Guardian hook integration detected" -ForegroundColor Green
} else {
Write-Host " WARNING: Guardian hook integration not detected" -ForegroundColor Red
$AllOk = $false
}
$configFile = Join-Path $OpenClawRoot "src\config\types.openclaw.ts"
if ((Get-Content $configFile -Raw) -match "SafetyConfig") {
Write-Host " OK: SafetyConfig type detected" -ForegroundColor Green
} else {
Write-Host " WARNING: SafetyConfig not detected" -ForegroundColor Red
$AllOk = $false
}
Write-Host ""
if ($AllOk) {
Write-Host "=== Installation complete! ===" -ForegroundColor Green
Write-Host ""
Write-Host "To enable the guardian, add to your openclaw.json:" -ForegroundColor Cyan
Write-Host @"
{
"safety": {
"guardian": {
"enabled": true,
"model": "openrouter/qwen/qwen3-32b"
}
}
}
"@
Write-Host ""
Write-Host "To run guardian tests:" -ForegroundColor Cyan
Write-Host " cd $OpenClawRoot; npx vitest run src/security/guardian-"
} else {
Write-Host "=== Installation completed with warnings. Please check the output above. ===" -ForegroundColor Yellow
}