Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(windows): reuse the registered install scope on NSIS updates

Zeding Zhang7d0f4ab62837
diff --git a/apps/desktop/build/installer.nsh b/apps/desktop/build/installer.nsh
new file mode 100644
index 000000000..c348e9d4d
--- /dev/null
+++ b/apps/desktop/build/installer.nsh
@@ -0,0 +1,12 @@
+!ifndef BUILD_UNINSTALLER
+ !macro customInstallMode
+ ; Let the assisted installer apply the selected scope and handle elevation.
+ ${If} ${isUpdated}
+ ${AndIf} $hasPerMachineInstallation != $hasPerUserInstallation
+ ${AndIfNot} ${isForAllUsers}
+ ${AndIfNot} ${isForCurrentUser}
+ StrCpy $isForceMachineInstall $hasPerMachineInstallation
+ StrCpy $isForceCurrentInstall $hasPerUserInstallation
+ ${EndIf}
+ !macroend
+!endif
diff --git a/apps/desktop/test/nsis-update-scope.nsi b/apps/desktop/test/nsis-update-scope.nsi
new file mode 100644
index 000000000..5898f099f
--- /dev/null
+++ b/apps/desktop/test/nsis-update-scope.nsi
@@ -0,0 +1,51 @@
+; Compile with makensis and run the resulting executable. A nonzero exit code
+; identifies the failing case. No registry writes or elevation are needed.
+Unicode true
+Name "NSIS update scope test"
+OutFile "nsis-update-scope.exe"
+RequestExecutionLevel user
+SilentInstall silent
+!include LogicLib.nsh
+!include "..\build\installer.nsh"
+
+Var updated
+Var requestedScope
+Var hasPerMachineInstallation
+Var hasPerUserInstallation
+Var isForceMachineInstall
+Var isForceCurrentInstall
+
+!define isUpdated '$updated == "1"'
+!define isForAllUsers '$requestedScope == "all"'
+!define isForCurrentUser '$requestedScope == "current"'
+
+!macro checkScope machine user forceMachine forceCurrent
+ StrCpy $hasPerMachineInstallation ${machine}
+ StrCpy $hasPerUserInstallation ${user}
+ StrCpy $isForceMachineInstall 0
+ StrCpy $isForceCurrentInstall 0
+ !insertmacro customInstallMode
+ ${If} $isForceMachineInstall != ${forceMachine}
+ ${OrIf} $isForceCurrentInstall != ${forceCurrent}
+ SetErrorLevel ${__LINE__}
+ Quit
+ ${EndIf}
+!macroend
+
+Section
+ StrCpy $updated 1
+ !insertmacro checkScope 1 0 1 0
+ !insertmacro checkScope 0 1 0 1
+ !insertmacro checkScope 1 1 0 0
+ !insertmacro checkScope 0 0 0 0
+
+ StrCpy $requestedScope current
+ !insertmacro checkScope 1 0 0 0
+ StrCpy $requestedScope all
+ !insertmacro checkScope 0 1 0 0
+
+ StrCpy $requestedScope ""
+ StrCpy $updated 0
+ !insertmacro checkScope 1 0 0 0
+ !insertmacro checkScope 0 1 0 0
+SectionEnd
diff --git a/docs/spec/04-ux/09-interaction-patterns.md b/docs/spec/04-ux/09-interaction-patterns.md
index 0c8ba2310..cba9b08b0 100644
--- a/docs/spec/04-ux/09-interaction-patterns.md
+++ b/docs/spec/04-ux/09-interaction-patterns.md
@@ -659,6 +659,9 @@ may be retained while exactly one workspace supplies the visible shell context.
Info continues to show the available version and the Releases action.
- `downloaded` remains actionable until Restart to update or normal app quit;
later scheduled/manual checks do not replace it with `checking`.
+- On Windows, Restart to update reuses the registered NSIS install scope when
+ exactly one exists. An all-users update requests elevation when needed.
+ The installer asks for the scope when it finds no registered install or finds both.
- A compact update notice appears in the main pane's top-right safe area for
the one-time manual reminder, in-app `downloading`, or `downloaded`. It stays
clear of the bottom composer at every supported window size and draft height.
diff --git a/docs/spec/06-delivery/e2e/release-and-platform.md b/docs/spec/06-delivery/e2e/release-and-platform.md
index 9f6b3a417..7b91c6554 100644
--- a/docs/spec/06-delivery/e2e/release-and-platform.md
+++ b/docs/spec/06-delivery/e2e/release-and-platform.md
@@ -616,7 +616,11 @@
(and supervision/capture equivalents) and confirm `app.quit()` exits without a
dialog. 6) On packaged Windows NSIS or Linux AppImage, restart to install an
update; confirm no quit warning appears and the installer completes upgrade
- and relaunch.
+ and relaunch. On Windows, repeat with only a current-user install and only
+ an all-users install. Verify each update skips the scope page and updates
+ the same directory, accepting UAC if prompted for the all-users install.
+ With both scopes registered, verify the installer asks which copy to update.
+ Also verify a fresh interactive install offers both scopes.
- **Expected**: Accidental explicit quit is cancellable. Repeated quit requests
cannot duplicate or bypass an outstanding confirmation; Cancel clears the
pending decision so a later quit asks again. Tray Quit presents the dialog
@@ -635,9 +639,11 @@
shutdown lifecycle covered (`lifecycle-dialog-broker.test.mjs`,
`lifecycle-confirmation-dialog-user-path.test.mjs`,
`lifecycle-close-behavior-runtime.test.mjs`, `close-behavior-tray.test.mjs`,
- `shutdown-regenerate-persistence.test.mjs`). Full application shutdown and
- packaged update journey remains Draft; run in a capable release environment
- when lifecycle wiring changes.
+ `shutdown-regenerate-persistence.test.mjs`). For the Windows scope cases,
+ compile `apps/desktop/test/nsis-update-scope.nsi` with `makensis` and run
+ the resulting executable. Exit code 0 means all scope cases passed.
+ The full shutdown and packaged update journey remains Draft. Run it in a
+ capable release environment when lifecycle wiring changes.
## E2E-067A: Prerelease install discovers newer stable release (D120)