Skip to content

Commit 223db1f

Browse files
feat(uninstall): add WSL gateway uninstall
Adds the local WSL gateway uninstall engine, CLI/Inno hooks, settings UI, postcondition-gated cleanup, and maintainer fixes for node-token cleanup plus localhost SSH tunnel preservation. Local required validation passed. GitHub rerun passed repo-hygiene/test/MSIX/extension jobs; build (win-x64) compiled and published successfully but failed during Upload Tray Artifact, so this was merged with admin override as an artifact-upload CI failure. Co-authored-by: Copilot <[email protected]>
1 parent fd8ff7d commit 223db1f

23 files changed

Lines changed: 6479 additions & 17 deletions

‎.gitignore‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,3 +352,8 @@ visual-test-output/
352352

353353
# Local squad agent state
354354
.squad/
355+
356+
# MSIX and packaging test output
357+
msix-validation-evidence/
358+
packaging-test-output/
359+
uninstall-validation-output/

‎docs/uninstall-msix.md‎

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Uninstalling OpenClaw Tray — MSIX Package
2+
3+
> **Date:** 2026-05-07
4+
> **Branch:** feat/wsl-gateway-uninstall
5+
6+
---
7+
8+
## MSIX Cannot Auto-Clean WSL State
9+
10+
**Feasibility verdict:** `runFullTrust` MSIX packages do **not** support a
11+
`CustomInstall` / `CustomUninstall` extension that runs an arbitrary EXE
12+
at uninstall time. The supported extension points
13+
(`windows.startupTask`, `windows.appExecutionAlias`, `com.extension`,
14+
`windows.protocol`, etc.) do not include an uninstall hook.
15+
16+
Therefore, removing the MSIX package via **Settings → Apps → OpenClaw Tray
17+
→ Uninstall** will silently leave behind:
18+
19+
- **WSL distro** — `OpenClawGateway` remains in `wsl --list`.
20+
- **Roaming app data** under `%APPDATA%\OpenClawTray\` (device key, settings,
21+
mcp-token).
22+
- **Local app data** under `%LOCALAPPDATA%\OpenClawTray\` (setup state, logs,
23+
VHD parent directory).
24+
25+
> **Note:** If the tray was installed with MSIX and the data landed in the
26+
> package-virtualized path (`%LOCALAPPDATA%\Packages\OpenClaw.Tray_<hash>\...`)
27+
> instead of real `%APPDATA%`, those directories are removed automatically by
28+
> MSIX on uninstall. Bostick's commit 7 validation test (Path A vs Path B)
29+
> confirms which layout applies.
30+
31+
---
32+
33+
## Recommended: Run "Remove Local Gateway" Before Uninstalling MSIX
34+
35+
1. Open the tray icon.
36+
2. Navigate to **Settings → Local Gateway**.
37+
3. Click **"Remove Local Gateway"** (Mattingly's warning banner in commit 4
38+
surfaces this step for MSIX users).
39+
4. Wait for the engine to complete — it stops keepalive processes, unregisters
40+
the WSL distro, nulls the device token, removes autostart, and cleans up app
41+
data.
42+
5. Uninstall the MSIX package via **Settings → Apps**.
43+
44+
---
45+
46+
## Manual Recovery (After MSIX Removed Without In-Tray Cleanup)
47+
48+
If the MSIX was already removed and the WSL distro / app data remains:
49+
50+
```powershell
51+
# 1. Unregister the distro (removes .vhdx from wsl's internal store)
52+
wsl --unregister OpenClawGateway
53+
54+
# 2. Remove VHD parent directory (wsl --unregister may leave the folder)
55+
Remove-Item "$env:LOCALAPPDATA\OpenClawTray\wsl\OpenClawGateway" `
56+
-Recurse -Force -ErrorAction SilentlyContinue
57+
58+
# 3. Remove autostart registry entry
59+
Remove-ItemProperty `
60+
-Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" `
61+
-Name "OpenClawTray" -ErrorAction SilentlyContinue
62+
63+
# 4. Remove local app data (setup state, logs)
64+
Remove-Item "$env:LOCALAPPDATA\OpenClawTray" -Recurse -Force -ErrorAction SilentlyContinue
65+
66+
# 5. Remove roaming app data (settings, device key — only if you want full purge)
67+
# NOTE: mcp-token.txt is intentionally preserved here; delete manually if needed.
68+
Remove-Item "$env:APPDATA\OpenClawTray\setup-state.json" -Force -ErrorAction SilentlyContinue
69+
```
70+
71+
Or use the validation script if it is available separately:
72+
73+
```powershell
74+
.\validate-wsl-gateway-uninstall.ps1 -Mode Full -ConfirmDestructive
75+
```

‎docs/uninstall-portable.md‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Uninstalling OpenClaw Tray — Portable ZIP
2+
3+
> **Date:** 2026-05-07
4+
> **Branch:** feat/wsl-gateway-uninstall
5+
6+
Portable (ZIP) installations have **no automatic uninstall hook**.
7+
Simply deleting the folder leaves the WSL distro, app data, and autostart
8+
entry behind. Follow one of the two paths below for a clean removal.
9+
10+
---
11+
12+
## Recommended: In-Tray Removal (Requires the Tray Running)
13+
14+
1. Open the tray icon.
15+
2. Navigate to **Settings → Local Gateway**.
16+
3. Click **"Remove Local Gateway"**.
17+
4. The engine stops keepalive processes, unregisters the WSL distro, nulls
18+
the device token, removes autostart, and cleans up app data.
19+
5. After the operation completes, delete the portable folder.
20+
21+
---
22+
23+
## CLI: Headless Removal (No Tray UI Required)
24+
25+
Run from the portable folder:
26+
27+
```powershell
28+
# Destructive — removes the local WSL gateway cleanly, then print result to stdout
29+
.\OpenClaw.Tray.WinUI.exe --uninstall --confirm-destructive
30+
31+
# With JSON output for programmatic consumption (tokens redacted in output):
32+
.\OpenClaw.Tray.WinUI.exe --uninstall --confirm-destructive --json-output .\uninstall-result.json
33+
34+
# Dry-run — records what would happen without any destruction:
35+
.\OpenClaw.Tray.WinUI.exe --uninstall --dry-run
36+
```
37+
38+
**Exit codes:**
39+
40+
| Code | Meaning |
41+
|------|---------|
42+
| 0 | Success — all steps completed, postconditions satisfied |
43+
| 1 | Partial failure — one or more steps failed (see JSON output or stderr) |
44+
| 2 | Bad arguments — `--confirm-destructive` or `--dry-run` missing |
45+
46+
After the CLI command exits 0, delete the portable folder.
47+
48+
---
49+
50+
## WARNING: Deleting the Folder Without Running Uninstall
51+
52+
Deleting the portable folder **without** running the uninstall first leaves:
53+
54+
- **WSL distro orphaned** — `OpenClawGateway` remains in `wsl --list`.
55+
Manual cleanup: `wsl --unregister OpenClawGateway`
56+
57+
- **App data** remains under:
58+
- `%APPDATA%\OpenClawTray\` — device key, settings, mcp-token
59+
- `%LOCALAPPDATA%\OpenClawTray\` — setup state, logs, exec policy, VHD parent dir
60+
61+
- **Autostart entry** may remain in
62+
`HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\OpenClawTray`
63+
64+
Manual WSL + registry cleanup:
65+
66+
```powershell
67+
wsl --unregister OpenClawGateway
68+
Remove-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" `
69+
-Name "OpenClawTray" -ErrorAction SilentlyContinue
70+
Remove-Item "$env:LOCALAPPDATA\OpenClawTray\wsl\OpenClawGateway" -Recurse -Force -ErrorAction SilentlyContinue
71+
```

‎installer.iss‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ WizardStyle=modern
2727
PrivilegesRequired=lowest
2828
SetupIconFile=src\OpenClaw.Tray.WinUI\Assets\openclaw.ico
2929
UninstallDisplayIcon={app}\{#MyAppExeName}
30+
; Round 2 (Scott #5): block install/uninstall while the tray is running.
31+
; Mutex name matches App.xaml.cs (`new Mutex(true, "OpenClawTray", …)`).
32+
; Tray and Inno run in the same user session, so the bare name resolves
33+
; against Local\OpenClawTray — no Global\ prefix needed.
34+
AppMutex=OpenClawTray
3035
#if MyAppArch == "arm64"
3136
ArchitecturesInstallIn64BitMode=arm64
3237
ArchitecturesAllowed=arm64
@@ -51,8 +56,12 @@ Name: "cmdpalette"; Description: "Install PowerToys Command Palette extension";
5156
[Files]
5257
; WinUI Tray app - include all files (WinUI needs DLLs, not single-file)
5358
Source: "{#publish}\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs
54-
; Command Palette extension (all files from build output)
55-
Source: "{#publish}\cmdpal\*"; DestDir: "{app}\CommandPalette"; Flags: ignoreversion recursesubdirs; Tasks: cmdpalette
59+
; Command Palette extension (all files from build output).
60+
; skipifsourcedoesntexist: prevents ISCC compile error when the cmdpal publish
61+
; dir is absent (e.g. developer builds that skip the cmdpalette task).
62+
Source: "{#publish}\cmdpal\*"; DestDir: "{app}\CommandPalette"; Flags: ignoreversion recursesubdirs skipifsourcedoesntexist; Tasks: cmdpalette
63+
; WSL gateway uninstall helper — invoked by [UninstallRun] to drive clean removal
64+
Source: "scripts\Uninstall-LocalGateway.ps1"; DestDir: "{app}"; Flags: ignoreversion
5665

5766
[Icons]
5867
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
@@ -66,5 +75,16 @@ Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChang
6675
Filename: "powershell.exe"; Parameters: "-ExecutionPolicy Bypass -Command ""Add-AppxPackage -Register '{app}\CommandPalette\AppxManifest.xml' -ForceApplicationShutdown"""; Flags: runhidden; Tasks: cmdpalette
6776

6877
[UninstallRun]
78+
; ORDERING NOTE: Inno Setup runs [UninstallRun] entries BEFORE deleting {app}
79+
; directory contents. This guarantees OpenClawTray.exe is still present when
80+
; the script executes. See Inno docs: "[UninstallRun] section".
81+
; Fallback: if OpenClawTray.exe is missing for any reason, Uninstall-LocalGateway.ps1
82+
; logs the error to {app}\uninstall-gateway-error.log and exits 0 so Inno continues.
83+
; *** DO NOT COMMENT OUT OR REMOVE THE Flags LINE BELOW ***
84+
; waituntilterminated is non-negotiable: without it Inno races ahead and deletes
85+
; {app} while the PowerShell hook (and the CLI engine it invokes) is still running,
86+
; leaving 279+ application files behind after unins000.exe reports exit 0.
87+
; runhidden suppresses the console window that would otherwise flash briefly.
88+
Filename: "powershell.exe"; Parameters: "-NoProfile -ExecutionPolicy Bypass -File ""{app}\Uninstall-LocalGateway.ps1"""; Flags: shellexec waituntilterminated runhidden; StatusMsg: "Removing local WSL gateway..."
6989
; Unregister Command Palette extension on uninstall
7090
Filename: "powershell.exe"; Parameters: "-ExecutionPolicy Bypass -Command ""Get-AppxPackage -Name '*OpenClaw*' | Remove-AppxPackage"""; Flags: runhidden

‎scripts/Uninstall-LocalGateway.ps1‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<#
2+
.SYNOPSIS
3+
Inno Setup [UninstallRun] helper — removes the local WSL gateway via the
4+
OpenClaw tray CLI flag.
5+
6+
.DESCRIPTION
7+
INNO ORDERING CONTRACT
8+
----------------------
9+
Per Inno Setup documentation, [UninstallRun] entries execute BEFORE the
10+
{app} directory is deleted. OpenClawTray.exe is therefore guaranteed to
11+
be present when this script runs.
12+
13+
WHAT THIS SCRIPT DOES
14+
---------------------
15+
1. Locates OpenClawTray.exe in the same directory as this script ({app}).
16+
2. Invokes: OpenClawTray.exe --uninstall --confirm-destructive --json-output <log>
17+
3. Logs success or failure to {app}\uninstall-gateway-result.json.
18+
4. If the EXE is missing (e.g., partial install), logs the error and exits 0
19+
so the Inno uninstaller continues. The user may need to clean up manually
20+
(see docs\uninstall-portable.md for manual steps).
21+
22+
FALLBACK
23+
--------
24+
Exit 0 in all error cases so Inno does not abort the uninstall if gateway
25+
cleanup fails. The result JSON captures the failure for post-mortem.
26+
27+
.NOTES
28+
Date: 2026-05-07
29+
Author: Aaron (Backend / Infrastructure Engineer)
30+
Branch: feat/wsl-gateway-uninstall
31+
Commit: 5 of 7
32+
33+
Token / key material is NEVER written to the result log; the engine
34+
and CLI layer both redact sensitive fields before serializing.
35+
#>
36+
37+
[CmdletBinding()]
38+
param()
39+
40+
$ErrorActionPreference = 'Stop'
41+
42+
$scriptDir = $PSScriptRoot
43+
$exePath = Join-Path $scriptDir 'OpenClaw.Tray.WinUI.exe'
44+
$resultPath = Join-Path $scriptDir 'uninstall-gateway-result.json'
45+
$errorPath = Join-Path $scriptDir 'uninstall-gateway-error.log'
46+
47+
# ---------------------------------------------------------------------------
48+
# EXE presence check — fallback if somehow missing
49+
# ---------------------------------------------------------------------------
50+
if (-not (Test-Path -LiteralPath $exePath)) {
51+
$msg = "[$(Get-Date -Format 'o')] Uninstall-LocalGateway.ps1: " +
52+
"OpenClawTray.exe not found at '$exePath'. " +
53+
"WSL gateway cleanup skipped. Manual cleanup may be required."
54+
try { $msg | Out-File -LiteralPath $errorPath -Encoding UTF8 -Force } catch {}
55+
Write-Warning $msg
56+
exit 0
57+
}
58+
59+
# ---------------------------------------------------------------------------
60+
# Invoke CLI uninstall
61+
# ---------------------------------------------------------------------------
62+
$exitCode = 0
63+
try {
64+
& $exePath --uninstall --confirm-destructive --json-output $resultPath
65+
$exitCode = if ($null -eq $global:LASTEXITCODE) { 0 } else { $global:LASTEXITCODE }
66+
67+
if ($exitCode -eq 0) {
68+
Write-Host "OpenClaw local WSL gateway removed successfully." -ForegroundColor Green
69+
} else {
70+
Write-Warning "OpenClaw gateway uninstall exited $exitCode; see '$resultPath' for details."
71+
}
72+
} catch {
73+
$msg = "[$(Get-Date -Format 'o')] Uninstall-LocalGateway.ps1 error: $($_.Exception.Message)"
74+
try { $msg | Out-File -LiteralPath $errorPath -Encoding UTF8 -Force } catch {}
75+
Write-Warning $msg
76+
}
77+
78+
# Always exit 0 so Inno does not abort the broader uninstall.
79+
exit 0

0 commit comments

Comments
 (0)