const TERMINAL_RUN_STATUSES = new Set(['completed', 'failed', 'cancelled', 'lost']);
import { isProcessAlive } from '../providers/outputParser.js';
export { isProcessAlive };
export function isACPBackedSlot(slot) {
    return (slot.transport === 'acp-sdk' ||
        slot.mode === 'acp' ||
        slot.mode === 'acp-sdk');
}
export function extractPersistedSessionPid(session) {
    if (session?.pid && session.pid > 0)
        return session.pid;
    return null;
}
export function getPersistedRunStatus(slot, session) {
    if (session?.pendingInput) {
        return session.pendingInput.type === 'input' ? 'waiting_input' : 'needs_confirmation';
    }
    return session?.currentRun?.status || slot.remoteStatus || null;
}
export function isTerminalRunStatus(status) {
    return !status || TERMINAL_RUN_STATUSES.has(status);
}
export function isPersistedSessionAlive(_slot, session) {
    if (!session || session.sessionState === 'offline')
        return false;
    // Check if the backing process is alive
    const pid = extractPersistedSessionPid(session);
    if (pid)
        return isProcessAlive(pid);
    return true;
}
export function hasPersistedActiveRun(slot, session) {
    const runStatus = getPersistedRunStatus(slot, session);
    return isPersistedSessionAlive(slot, session) && !isTerminalRunStatus(runStatus);
}
//# sourceMappingURL=sessionLiveness.js.map