Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

Merge branch 'win-host-outside-installdir' into win-prepare-update

reviewa6519c0941c8
diff --cc CLAUDE.md
index 1eebac9ee,54656b3e9..94b4cdc93
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@@ -8573,36 -8573,35 +8573,65 @@@ verify and stop any remaining host. Nev
resume depends on supported, saved conversation history; it does not preserve running tasks.
See `docs/windows-session-host.md` for the user-controlled preparation/recovery steps and limits.
+**Prepare for update (#829 step 2).** The in-app answer to the refusal above, Windows only.
+Rules a refactor must not undo:
+- **The host's `shutdown` command is the only thing that stops the host**, and only on a connection
+ that negotiated the `shutdown` hello feature (`SESSION_HOST_FEATURES`). An older host answers
+ `host-unsupported` and the dialog shows `MANUAL_UPDATE_STEPS` — never a taskkill/name-based
+ fallback from the app. The host ends every session through the SAME `handleKill` path (taskkill
+ of the tree, then node-pty's onExit as proof), refuses attach/attachExisting/executeLaunch while
+ it runs, bounds each kill at 20 s, and on ANY unconfirmed kill answers `ok:false` naming the
+ sessions and keeps serving. It exits only after the success reply is flushed (`socket.end`), and
+ removes its state/token files. It touches no node metadata; nodes cold-restore next launch.
+- **Inspection never launches a host** (`SessionHostClient.inspectForUpdate` /
+ `shutdownForUpdate` read the published state first; absent = `no-host`). Once `shutdown` is
+ sent the client latches `shutDownForUpdate` so a dropped connection cannot reconnect into a
+ freshly launched host that re-locks the install dir; only the host's explicit refusal (or a frame
+ provably never sent) clears it. "Shut down" means reply AND state file gone AND pid dead.
+- **Busy blocks, from either source**: `planUpdatePrep` (`renderer/lib/updatePrep.ts`, pure)
+ refuses on working / waiting / blocked / a held question or approval ticket, read from the
+ renderer store AND core's mirror (`app:update-prep-inspect` carries `mirror` per session) — an
+ unmounted node's renderer state is cleared, so the mirror is the only witness for closed/other
+ projects. Only a MOUNTED node can be asked to quit (`registerAgentUpdateExit` in TerminalNode:
+ Pause's exit half with its refusals, marking SLEEPING not PAUSED so cold restore resumes it);
+ every other agent is disclosed as "stopped without a clean exit".
+- The confirm is a danger `ConfirmDialog` with `enterConfirms={false}` (Cancel focused) and says
+ plainly that shells and their unsaved work stop and that nodes are kept. Never route anything
+ through End session / node deletion.
+- IPC (`app:update-prep-*`) is raw `ipcMain`, main-window senders only, and in
+ `HOST_ONLY_CHANNELS`. Server Edition: the bridge stub answers `unsupported` (Linux tmux, no
+ installer; a browser must never end every session on the server). Mobile: N/A — a phone cannot
+ authorize an update shutdown; it sees its sessions end like any other end.
+
+ **Staged host runtime (#829 step 3).** The host used to run as a hard link of `nodeterm.exe` INSIDE
+ the install dir, so it mapped the installed exe/DLLs/`resources.pak` and every update stopped until
+ the user ended it (and every session). Packaged Windows builds now copy what the host needs into
+ `%LOCALAPPDATA%\nodeterm\session-host\<version>-<fingerprint>\` and launch
+ `nodeterm-sessionhost-v2.exe` from there (`core/session-host-runtime.ts`, wired in
+ `session-host-backend.ts`; the client waits at most `STAGED_RUNTIME_WAIT_MS` for the first staging
+ of a version). Rules a refactor must not undo:
+ - **Only a published, verified copy is launched.** Files are copied into `.staging-<uuid>`, each
+ re-read and compared by SHA-256, the copy is smoke-run once (`ELECTRON_RUN_AS_NODE`, requires its
+ node-pty, must exit `SMOKE_OK`), the marker is written LAST, and the dir is published by one
+ `renameAtomic`. A dir without a valid marker (sizes checked on reuse) is moved aside, never run.
+ - **A new image name.** Old uninstallers match `nodeterm.exe`/`nodeterm-session-host.exe` by NAME
+ machine-wide; the staged host must never answer to either. The preflight deliberately does not
+ match it by name (path test still applies).
+ - **Fail-safe, not fail-open.** Any staging failure, or a staged host that dies within 10 s with a
+ code other than the host's own 0/1 (`stagedExitWantsFallback` — a missing DLL, a policy block),
+ falls back to the legacy hard-link launch for the rest of the run. That host still blocks the
+ installer through the unchanged read-only preflight.
+ - **GC is fail-closed.** An old version dir is deleted only when a successful Win32_Process query
+ shows nothing running under it, no staged-host process has an unreadable path, it is older than
+ 10 min, AND a rename aside succeeds (Windows refuses while an image inside is mapped). The
+ uninstaller leaves the staged runtimes alone (never kills a host); `docs/uninstall.md` lists them.
+ - **The file set is not measured yet** (written on Linux): exe, top-level `*.dll`, `icudtl.dat`
+ (required), `resources.pak`, snapshot blobs, `locales/`, `resources/session-host/**`. The smoke
+ run is what proves it per machine; device checklist in docs/windows-session-host.md.
+ - **Protocol is additive-only across versions.** A newer app keeps using an older staged host
+ (protocol v1/v2 + `hello` features); an unsupported one is left running and reported
+ (`SessionHostProtocolCompatibilityError`), never killed. ~250 MB of disk per staged version.
+
**Follow-ups, in order:** code signing, then Windows auto-update wiring (electron-updater NSIS leg
+ `latest.yml` on the nodeterm.dev feed — blocked on signing: an unsigned auto-update is a
downgrade in trust), and the fork's PE-identity polish (electron-builder leaves `OriginalFilename`
diff --cc CONTRIBUTING.md
index 66a258c63,384ab0dfd..992e68aea
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@@ -93,15 -93,17 +93,26 @@@ verify and stop any remaining host. Nev
resume depends on supported, saved conversation history; it does not preserve running tasks.
See `docs/windows-session-host.md` for the user-controlled preparation/recovery steps and limits.
+**Prepare for update** (#829 step 2, Windows only): ⌘K / the update card run
+`components/PrepareUpdateDialog.tsx` over the pure `lib/updatePrep.ts` plan. It refuses while any
+session's agent is working or waiting on the user (renderer store OR core mirror — unmounted nodes
+have no renderer state), asks idle mounted agents to `/exit` through `registerAgentUpdateExit`,
+confirms what still stops (Cancel focused), then sends the host's `shutdown` command and quits only
+once the host process is confirmed gone. `shutdown` is a negotiated hello feature: never send it to
+a host that did not advertise it, and never add a taskkill/name-kill fallback — an older host gets
+the manual steps. The flow never deletes a node. Server Edition: degraded stub (`unsupported`).
+
+ Staged host runtime (#829 step 3): a packaged Windows build launches the host from a private
+ copy, `%LOCALAPPDATA%\nodeterm\session-host\<version>-<fingerprint>\nodeterm-sessionhost-v2.exe`
+ (`src/core/session-host-runtime.ts`), so it maps no installed file and no longer blocks updates.
+ Rules: a copy is launched only after it was published by one rename of a hash-verified,
+ smoke-tested temp dir (marker written last); the image name must stay unlike `nodeterm.exe` /
+ `nodeterm-session-host.exe` (old uninstallers match those by name machine-wide); every staging
+ failure falls back to the legacy in-install-dir launch, which the preflight still blocks on; old
+ copies are deleted only after a SUCCESSFUL process query shows nothing runs from them and the
+ directory can be renamed aside. The host protocol stays additive-only — an older host is kept and
+ used, an incompatible one is left running and reported, never killed.
+
## Three surfaces
A feature is not done until you have decided how it behaves on each — even if the decision is "not
diff --cc src/core/session-host-backend.ts
index 8e9ee810c,8eeb8ba15..821497f6a
--- a/src/core/session-host-backend.ts
+++ b/src/core/session-host-backend.ts
@@@ -8,11 -10,10 +10,12 @@@ import path from 'path
import { platform } from './platform'
import {
SessionHostClient,
- SessionHostProtocolCompatibilityError
+ SessionHostProtocolCompatibilityError,
+ type HostShutdownOutcome,
+ type HostUpdateInspection
} from './session-host-client'
import { SessionHostPty } from './session-host-pty'
+ import { ensureStagedHostRuntime } from './session-host-runtime'
import type { ExecuteLaunchResult, SessionHostSpawnOptions } from '../session-host/protocol'
import type { PreparedAgentLaunch } from './agent-launch'
import type { PaneOwner } from '../shared/agents/pane-owner-predicate'
diff --cc src/core/session-host-client.ts
index 48052ce38,6d3379326..451882439
--- a/src/core/session-host-client.ts
+++ b/src/core/session-host-client.ts
@@@ -34,10 -33,13 +34,14 @@@ import
type CaptureResult,
type KillSessionResult,
type ExecuteLaunchResult,
- type ListSessionsResult
+ type ListSessionsResult,
+ type ShutdownResult
} from '../session-host/protocol'
import { resolveSessionHostScript, spawnSessionHost } from './session-host-launcher'
+
+ /** How long a host launch waits for the first staging of a new version (copy + hash + smoke run)
+ * before launching from the installed binary instead. */
+ export const STAGED_RUNTIME_WAIT_MS = 45_000
import { latestClaimSize, type SizeClaim } from './pty-size'
import { isTerminalReport } from './terminal-reports'
import type { PreparedAgentLaunch } from './agent-launch'