Live sessions: user-controlled startup restore - #198
Merged
Merged
Conversation
Launch no longer reattaches silently. Two settings (Config → Sessions): Startup restore (Ask by default, Always, Never) and Multiple detached sessions (Ask which by default, Open all). With one detached session and Ask, a prompt shows its directory, command and age, and offers Resume (R/Enter), Not now (N/Esc), Always resume (A) or Don't resume at startup (D); A and D save the setting. With several, a picker selects which to resume (Space, A for all, Enter, Esc for none). Neither has a destructive key, and Never only skips restoring at launch. This window attaches the first chosen session; each other one opens in a new host window through a small TerminalHost abstraction (Ghostty, Terminal.app, kitty). Hosts that cannot open windows, or launcher failures, leave those sessions running and name their nmsh --attach command. Also: show the launch notice after a reattached transcript is restored (it was being erased), treat a read ending in a lone ESC as Esc in the startup screens, and wait for the specific gated command in a lifecycle test instead of any running command.
The next command was typed right after Ctrl+C, before the interrupted job's prompt returned; the tty can flush input queued around an interrupt, so the command was sometimes lost (seen in CI). Wait until the sleep has exited and NMSh has recorded the interruption.
Replace open -na Ghostty.app, which started a separate Ghostty instance per window, with Ghostty's AppleScript API: a new surface configuration whose command is the nmsh --attach line, then new window with that configuration. The script is fixed text; the command words are passed as osascript argv and shell-quoted with quoted form of, so no path or session id is interpolated into AppleScript. A disabled scripting interface, denied Automation permission or a Ghostty error exits non-zero, which keeps the existing fallback: the session stays detached and its attach command is named.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #197
Behavior
liveSessionStartup= Ask (default) / Always / Never;liveSessionMultiple= Ask which (default) / Open all. Unknown values fall back to the defaults./resume.--newand--attach <id>are unchanged. Attached sessions are never candidates, since attach is exclusive at the service.Opening more than one
This window attaches the first chosen session. Each other one runs
nmsh --attach <id>in a new host window, viasrc/host/terminalHost.ts:detectTerminalHostreturns an optionalnewWindow(argv)launcher: Ghostty on macOS (AppleScript:new surface configuration+new window with configuration, a normal window in the running app, with the command words passed as osascript argv), Ghostty on Linux (ghostty -e), Terminal.app (AppleScriptdo script), and kitty (kitten @ launch --type=os-window).openWindowstakes an injectable spawner and reports every command it could not open. The current window then names each remaining session'snmsh --attachcommand. Nothing selected is dropped or ended.Also fixed
echowas still marked running. It now waits for the gated command.Tests
tests/startupRestore.test.ts: config defaults and validation, the launch plan for every policy combination, prompt and picker keys and rendering, host detection and command construction (including quoting),openWindowswith a fake spawner, and orchestration (persisting, not-now, Never, selection, Open all, unsupported and failing hosts).tests/startupDiscovery.test.ts(real PTY, nmshd and zsh):/resumestill lists the skipped session.git diff --checkare clean. The combined live PTY files passed 10 consecutive runs, and a full-suite run passed 568/568.Limitations
nmsh --attachcommand.allow_remote_control./resume.