Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.
Rust agentai-agentapplecomputer-usecomputer-use-agentcontainerizationcuadesktop-automationhacktoberfestlumemacosmanusoperatorswiftvirtualizationvirtualization-frameworkwindowswindows-sandbox
fix(spaces-desktop): uninstall stops and removes the Windows host service (CUA-1740) (#5276)
Francesco Bonaccia76a0283aaf8
diff --git a/apps/cua-spaces-desktop/packaging/installer.nsh b/apps/cua-spaces-desktop/packaging/installer.nshindex 01c1a7f1e9..598fa8a391 100644--- a/apps/cua-spaces-desktop/packaging/installer.nsh+++ b/apps/cua-spaces-desktop/packaging/installer.nsh@@ -17,8 +17,13 @@; Uninstalling (not upgrading) also removes what the app added outside its; folder: launch at login (the Run entry, src/login-item.ts) and the `cua`; it put on PATH, when the app's record says it did (WINDOWS_APP_KEY,-; src/model/environment.ts). The user's ~/.cua and app data stay, as with-; the SwiftUI app.+; src/model/environment.ts), and turns off unattended access (CUA-1740): the+; host service (the per-user scheduled task Cua\SpacesdHost, or its logon+; entry, running ~/.cua/host/bin/cua-spacesd.exe) would otherwise keep the PC+; online and shared on the relay. An upgrade runs this uninstaller too (as+; --updated, so isUpdated holds) and keeps the host running. The user's ~/.cua (apart from+; ~/.cua/host, the service's own files) and app data stay, as with the+; SwiftUI app.!include "FileFunc.nsh"@@ -28,6 +33,9 @@ Var pid!define CUA_SPACES_KEY "Software\ai.cua.spaces.desktop"!define CUA_SPACES_RUN_NAME "ai.cua.spaces.desktop"+; cua-host's Windows service (libs/cua/crates/cua-host/src/service.rs).+!define CUA_HOST_TASK "Cua\SpacesdHost"+!define CUA_HOST_RUN_NAME "CuaSpacesdHost"!macro customCheckAppRunning!insertmacro IS_POWERSHELL_AVAILABLE@@ -53,6 +61,7 @@ Var pid!macro customUnInstall${ifNot} ${isUpdated}+ !insertmacro removeHostServiceDeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "${CUA_SPACES_RUN_NAME}"DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Explorer\StartupApproved\Run" "${CUA_SPACES_RUN_NAME}"!insertmacro removeAppCli@@ -81,3 +90,32 @@ Var pid${endIf}${endIf}!macroend++; Unattended access, as the .deb's prerm.sh turns it off: `cua host remove+; --force --uninstalling` (a no-op on a machine never set up; it follows+; CUA_HOME) unregisters this machine and the Spaces it provides from the relay, deletes the scheduled task (or logon entry) and removes+; ~/.cua/host. Bounded, and best effort: an offline relay is reported by cua+; after the local cleanup and never stops the uninstall. Then, whatever it+; could not reach: the task, the logon entry, a driver still running from+; ~/.cua (or a CUA_HOME), and ~/.cua/host. cua may have started the daemon+; again to turn the provided Spaces off, so it is stopped once more before+; the app's files are removed.+!macro removeHostService+ ${if} ${FileExists} "$INSTDIR\resources\native\cua.exe"+ DetailPrint "Turning off unattended access"+ nsExec::Exec /TIMEOUT=90000 '"$INSTDIR\resources\native\cua.exe" host remove --force --uninstalling'+ Pop $0+ !insertmacro stopCuaDaemon+ ${endIf}+ nsExec::Exec '"$SYSDIR\schtasks.exe" /End /TN "${CUA_HOST_TASK}"'+ Pop $0+ nsExec::Exec '"$SYSDIR\schtasks.exe" /Delete /TN "${CUA_HOST_TASK}" /F'+ Pop $0+ DeleteRegValue HKCU "Software\Microsoft\Windows\CurrentVersion\Run" "${CUA_HOST_RUN_NAME}"+ ${if} $IsPowerShellAvailable == 0+ nsExec::Exec `"$SYSDIR\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -NonInteractive -C "Get-CimInstance -ClassName Win32_Process | ? {$$_.Path -and $$_.Path -like '*\host\bin\cua-spacesd.exe'} | % { Stop-Process -Id $$_.ProcessId -Force -ErrorAction SilentlyContinue }"`+ Pop $0+ ${endIf}+ Sleep 500+ RMDir /r "$PROFILE\.cua\host"+!macroenddiff --git a/apps/cua-spaces-desktop/test/uninstall.test.ts b/apps/cua-spaces-desktop/test/uninstall.test.tsindex da8509e703..e591d251b5 100644--- a/apps/cua-spaces-desktop/test/uninstall.test.ts+++ b/apps/cua-spaces-desktop/test/uninstall.test.ts@@ -2,8 +2,8 @@// Copyright (c) 2026 Cua AI, Inc.// What an upgrade or an uninstall leaves: the daemon stopped before files-// are replaced, launch at login and the app's own CLI copy removed with the-// app, the user's data kept; and an AppImage's daemon runs from a copy, so+// are replaced, launch at login, the app's own CLI copy and the host service+// removed with the app, the user's data kept; and an AppImage's daemon runs from a copy, so// it does not keep the AppImage mounted.import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";import { createRequire } from "node:module";@@ -70,8 +70,41 @@ describe("the Windows installer and uninstaller", () => {expect(nsh).toContain(`!define CUA_SPACES_RUN_NAME "${WINDOWS_RUN_NAME}"`);expect(`HKCU\\${/!define CUA_SPACES_KEY "([^"]+)"/.exec(nsh)![1]}`).toBe(WINDOWS_APP_KEY);expect(macro("removeAppCli")).toContain('ReadRegStr $0 HKCU "${CUA_SPACES_KEY}" "CliInstalled"');+ // Of the user's files, only the host service's own folder goes.const code = nsh.split("\n").filter((l) => !l.trim().startsWith(";")).join("\n");- expect(code).not.toMatch(/[\\/]\.cua\b|\$APPDATA|\$PROFILE|RMDir \/r/);+ const home = code.split("\n").filter((l) => /[\\/]\.cua\b|\$APPDATA|\$PROFILE|RMDir \/r/.test(l)).map((l) => l.trim());+ expect(home).toEqual(['RMDir /r "$PROFILE\\.cua\\host"']);+ });++ it("turn off unattended access on uninstall, not on upgrade (CUA-1740)", () => {+ const un = macro("customUnInstall").trim().split("\n").map((l) => l.trim());+ // Inside the ${ifNot} ${isUpdated} block: an upgrade keeps the host running.+ expect(un[0]).toBe("${ifNot} ${isUpdated}");+ expect(un.indexOf("!insertmacro removeHostService")).toBeGreaterThan(0);+ expect(un.indexOf("!insertmacro removeHostService")).toBeLessThan(un.lastIndexOf("${endIf}"));++ const host = macro("removeHostService");+ // The removal the .deb uses: unregister from the relay, delete the task, remove ~/.cua/host.+ expect(host).toContain(`"$INSTDIR\\resources\\native\\cua.exe" host remove --force --uninstalling`);+ // Bounded, and its result is popped and ignored: an offline relay never blocks the uninstall.+ expect(host).toMatch(/nsExec::Exec \/TIMEOUT=\d+ '"\$INSTDIR\\resources\\native\\cua\.exe" host remove/);+ expect(host).not.toMatch(/Abort|Quit|MessageBox/);+ // cua may start the daemon to turn provided Spaces off: stopped again before files go.+ expect(host.indexOf("host remove")).toBeLessThan(host.indexOf("!insertmacro stopCuaDaemon"));+ // The fallback for what cua could not reach.+ expect(host).toContain('/End /TN "${CUA_HOST_TASK}"');+ expect(host).toContain('/Delete /TN "${CUA_HOST_TASK}" /F');+ expect(host).toContain('DeleteRegValue HKCU "Software\\Microsoft\\Windows\\CurrentVersion\\Run" "${CUA_HOST_RUN_NAME}"');+ expect(host).toContain("\\host\\bin\\cua-spacesd.exe");+ expect(host.trim().split("\n").at(-1)!.trim()).toBe('RMDir /r "$PROFILE\\.cua\\host"');+ });++ it("name the task and logon entry cua-host creates", () => {+ const service = readFileSync(path.join(root, "../../libs/cua/crates/cua-host/src/service.rs"), "utf8");+ const task = /!define CUA_HOST_TASK "([^"]+)"/.exec(nsh)![1]!;+ const run = /!define CUA_HOST_RUN_NAME "([^"]+)"/.exec(nsh)![1]!;+ expect(service).toContain(`pub const WINDOWS_TASK_NAME: &str = "${task.replaceAll("\\", "\\\\")}";`);+ expect(service).toContain(`pub const WINDOWS_RUN_VALUE: &str = "${run}";`);});});