/**
 * Build shutdown side-effect policy from the requested restart mode.
 * Main flow: explicit bridge shutdown cleans resources; scheduler restart keeps
 * SDK/PTY processes and persisted metadata so the scheduler can restore state.
 */
export function buildGracefulShutdownPlan(preserveSessions) {
    const shouldCleanRuntimeState = !preserveSessions;
    return {
        terminateSdkSessions: shouldCleanRuntimeState,
        closePtySessions: shouldCleanRuntimeState,
        terminateResidualProcesses: shouldCleanRuntimeState,
        unregisterInstance: shouldCleanRuntimeState,
        clearPersistedSessions: shouldCleanRuntimeState,
    };
}
/**
 * Decide whether startup may destructively clean persisted runtime sessions.
 * Main flow: default bridge restart is non-destructive; operators can opt into
 * legacy cleanup with AWS_BRIDGE_CLEAN_ORPHANS_ON_STARTUP=true.
 */
export function shouldCleanupPersistedSessionsOnStartup(preserveSessions, env = process.env) {
    if (preserveSessions) {
        return false;
    }
    return env.AWS_BRIDGE_CLEAN_ORPHANS_ON_STARTUP === "true";
}
/**
 * Decide whether background orphan monitoring may terminate persisted sessions.
 * Main flow: process termination is an explicit cleanup action, not a default
 * monitoring behavior, so restart recovery cannot be undone by auto-clean mode.
 */
export function shouldAutoCleanOrphanProcesses(env = process.env) {
    return env.AWS_BRIDGE_CLEAN_ORPHANS_ON_STARTUP === "true";
}
