import { TerminalSession, TerminalSessionOptions } from './terminal-session'; import type { TerminalSessionInfo, TerminalSessionMeta } from './terminal-session'; /** * Why a resume-only open could not reattach to an existing PTY. * Mirrors the `resume_failed.reason` protocol field (3-repo contract): * - 'not_found' — no session with this sessionId exists * - 'dead' — the session exists but its PTY already exited * - 'meta_mismatch' — the presented meta does not exactly match the recorded one */ export type ResumeFailureReason = 'not_found' | 'meta_mismatch' | 'dead'; export type ResumeResult = { ok: true; session: TerminalSession; } | { ok: false; reason: ResumeFailureReason; }; export declare class TerminalSessionManager { private readonly sessions; /** * Per-session grace timers scheduled by closeAllGracefully(). A timer kills * and removes its session when the grace window elapses without a reconnect. */ private readonly graceTimers; private sessionCounter; createSession(options?: TerminalSessionOptions): TerminalSession | null; /** * Resume-only lookup: NEVER spawns a new PTY (no-fallback rule). A resume * open (`resume: true`) must route here — createSessionWithId() is the * create-or-legacy-grace-resume path for non-resume opens. * * Succeeds only when the session exists, its PTY is alive, AND the presented * meta exactly matches the meta recorded at creation. On success the pending * grace timer (if any) is cancelled and the existing session is returned. */ resumeSession(sessionId: string, meta?: TerminalSessionMeta): ResumeResult; /** * Create-or-legacy-grace-resume path for NON-resume opens. A reconnect that * explicitly asks for a resume (`resume: true`) must use resumeSession() * instead — this method spawns a new PTY when no live session exists, which * a resume-only open must never do. */ createSessionWithId(sessionId: string, options?: TerminalSessionOptions): TerminalSession | null; getSession(sessionId: string): TerminalSession | undefined; closeSession(sessionId: string): boolean; listSessions(): TerminalSessionInfo[]; /** * Genuine shutdown: kill every PTY immediately and drop all sessions. * Use this on process exit, not on a transient WebSocket disconnect. */ closeAll(): void; /** * Transient-disconnect handling: keep every PTY alive and schedule a grace * timer per session. If no reconnect arrives within SESSION_GRACE_TIMEOUT_MS, * the session is killed and removed. A reconnect with the same sessionId via * createSessionWithId() cancels the timer and resumes the PTY. */ closeAllGracefully(): void; private scheduleGraceTimer; private clearGraceTimer; get size(): number; } //# sourceMappingURL=terminal-session-manager.d.ts.map