mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-20 15:19:16 +00:00
* feat(terminal): disable auto-close-on-exit by default Remote graceful channel closes (VPN half-close, server-side idle kick) can be reported as a clean exit with code 0, so with auto-close enabled the tab gets destroyed exactly when the user needs it kept - bypassing the SSH auto-reconnect loop, which intentionally skips exited events. Keep tabs on exit by default; users who want close-on-exit can enable it in Settings > Terminal > Behavior. Attach-mode close behavior is unchanged. * fix(terminal): keep session tabs when the auto-close setting is unavailable The resolver's own default and the TerminalLayer call-site fallback still treated a missing terminal setting as auto-close enabled. Remote graceful channel closes (a jump host reaping an idle session) are reported as a clean exit, so before the settings store had loaded, those closes silently deleted the session tab and its scrollback. This completes the opt-in default introduced above: only an explicit autoCloseOnExit true closes tabs. * fix(terminal): migrate the materialized auto-close-on-exit default once Builds before the default flip shipped autoCloseOnExit: true as the default and materialized it into netcatty_term_settings_v1 on any settings write, so most upgraders carry a value they never chose and the new default-off never reaches them: bastion and idle-harvesting servers reporting clean exits keep silently deleting their tabs. Reset that materialized true exactly once behind a marker key before the settings blob is first ingested, then persist the marker so every later stored value is treated as the user's own choice. The cost is documented: a user who deliberately enabled auto-close before this release must re-enable it once. * fix(terminal): keep synced legacy auto-close from coming back A device that already wrote the one-shot migration marker was accepting a pre-migration cloud or backup payload with autoCloseOnExit true. Unversioned true is rewritten to false. Payloads that record the migration still sync an explicit opt-in, including across a three-way merge that would otherwise glue the local marker onto a legacy true. Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com> --------- Co-authored-by: xu <tbqyomnnnbltzxy2t@aliyun.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>
67 lines
2.3 KiB
TypeScript
67 lines
2.3 KiB
TypeScript
import type { ProviderValidationIssue } from "@netcatty/plugin-contract";
|
|
|
|
export type TerminalSessionExitEvent = {
|
|
exitCode?: number;
|
|
signal?: number;
|
|
error?: string;
|
|
reason?: "exited" | "error" | "timeout" | "closed";
|
|
// True when the remote closed the channel without sending exit-status or
|
|
// exit-signal (#3591): no numeric exit code exists, and the renderer shows
|
|
// a distinct message instead of a misleading "code 0".
|
|
remoteClosedWithoutExitStatus?: boolean;
|
|
diagnostics?: ReadonlyArray<ProviderValidationIssue>;
|
|
};
|
|
|
|
export function formatSessionClosedExitMessage(evt: TerminalSessionExitEvent): string {
|
|
if (evt?.remoteClosedWithoutExitStatus) {
|
|
return "\r\n[session closed by remote (no exit status)]";
|
|
}
|
|
return `\r\n[session closed${evt?.exitCode !== undefined ? ` (code ${evt.exitCode})` : ""}]`;
|
|
}
|
|
|
|
export type TerminalSessionExitIntent =
|
|
| { kind: "closeSession" }
|
|
| { kind: "markDisconnected" };
|
|
|
|
type TerminalPopupExitOptions = {
|
|
autoCloseOnExit?: boolean;
|
|
isAttachMode?: boolean;
|
|
};
|
|
|
|
function isConfirmedCleanExit(evt: TerminalSessionExitEvent): boolean {
|
|
return evt.reason === "exited" && evt.exitCode === 0;
|
|
}
|
|
|
|
export function resolveTerminalSessionExitIntent(
|
|
evt: TerminalSessionExitEvent,
|
|
// Keep-tab is the safe default: a caller that has not loaded the terminal
|
|
// setting yet must not silently delete a session tab. Remote graceful
|
|
// channel closes (e.g. a jump host reaping an idle session) are reported
|
|
// as a clean exit, so an unavailable setting must not re-enable closing.
|
|
autoCloseOnExit = false,
|
|
): TerminalSessionExitIntent {
|
|
if (autoCloseOnExit && isConfirmedCleanExit(evt)) {
|
|
return { kind: "closeSession" };
|
|
}
|
|
|
|
// Non-zero or unknown exits, timeouts, transport errors, and channel closes
|
|
// should keep the tab visible so the user can inspect output and reconnect.
|
|
return { kind: "markDisconnected" };
|
|
}
|
|
|
|
export function shouldCloseTerminalPopupOnExit(
|
|
evt: TerminalSessionExitEvent,
|
|
options: TerminalPopupExitOptions = {},
|
|
): boolean {
|
|
if (options.autoCloseOnExit === false) return false;
|
|
return options.isAttachMode === true || isConfirmedCleanExit(evt);
|
|
}
|
|
|
|
export function shouldRevealTerminalPopupOnExit(
|
|
_evt: TerminalSessionExitEvent,
|
|
options: TerminalPopupExitOptions = {},
|
|
): boolean {
|
|
return options.autoCloseOnExit === false &&
|
|
options.isAttachMode !== true;
|
|
}
|