From a62b68a909a0a5fb30992eb5ebd8e129ed208ae0 Mon Sep 17 00:00:00 2001 From: jon Date: Wed, 22 Jul 2026 15:17:59 -0500 Subject: [PATCH] feat(install-windows): close the terminal at the end, since its PATH is stale A process reads PATH once, at startup, so the shell the installer ran in can never resolve ncp. The ending now says that and closes the window. Uses Stop-Process -Id $PID rather than 'exit', which only closes the window when the host was started with -File. Co-Authored-By: Claude Opus 4.8 --- install-windows.ps1 | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/install-windows.ps1 b/install-windows.ps1 index 7994190..0bc62f3 100644 --- a/install-windows.ps1 +++ b/install-windows.ps1 @@ -13,11 +13,11 @@ Requires Windows 10/11 with winget (App Installer). No reboot needed. .PARAMETER OwnsWindow - Internal. Set only on the elevated run this script starts for itself, which - gets a console window of its own - so it is allowed to close that window when - it finishes. Without it we assume we are a guest in someone's existing shell - and must not kill it (closing would take their session, and any transcript - they were recording, with it). Not meant to be passed by hand. + Internal. Set only on the elevated run this script starts for itself. That + run has a console of its own, so a fatal error has to pause before the window + disappears with the message on it. In a shell the user already had open the + text stays on screen, and a prompt there is a keystroke nobody asked for. + Not meant to be passed by hand. #> param( [switch]$OwnsWindow @@ -283,10 +283,22 @@ Write-Host " The app opens at http://localhost:8000" -ForegroundColor White Write-Host " The AI starts OFF - click 'Start AI' in the sidebar to turn it on." -ForegroundColor White Write-Host "" Write-Host " Terminal: open a NEW terminal (PowerShell or cmd), then run ncp help" -ForegroundColor White -Write-Host " (PATH is read at process start, so open windows lack it)" -ForegroundColor DarkGray Write-Host " ==========================================================" -ForegroundColor Green Write-Host "" -if ($OwnsWindow) { - Read-Host "Press Enter to close" - exit 0 # -File means the script ending ends powershell.exe, closing the window -} +Write-Host " This window has to close for ncp to work." -ForegroundColor Yellow +Write-Host " A process reads PATH once, when it starts. This shell started before" -ForegroundColor DarkGray +Write-Host " the installer put management\ on PATH, so it will never see ncp no" -ForegroundColor DarkGray +Write-Host " matter what you run here. The next terminal you open will." -ForegroundColor DarkGray +Write-Host "" +Read-Host " Press Enter to close this window (Ctrl+C works too)" + +# Stop-Process on our own PID, not `exit`: `exit` only ends the window when the +# host was started with -File. Run interactively - `& .\install-windows.ps1` from +# a shell already open, which is the common case - it would just return to the +# prompt in a session whose PATH is permanently stale. Killing the host closes +# the window either way, which is the point: the user cannot accidentally keep +# using a shell where ncp will never resolve. +# Caveat: a Start-Transcript in this window never reaches Stop-Transcript. The +# transcript is flushed as it is written, so the content survives without the +# closing footer. +Stop-Process -Id $PID