/** * PTYSessionManager - Unified PTY session management * * Manages all PTY sessions uniformly using the IPTYSession interface: * - LocalPTYSession: Direct node-pty control * - ProxyPTYSession: Remote sessions via transports * * NOTE: Unlike the original, this does NOT import node-pty directly. * Use #node-pty for local session spawning. The spawn() method * accepts a spawn function via constructor injection. */ import { EventEmitter } from 'events'; import type { IPTYSession, IPTYTransport, SessionSource, PTYSessionState, IPCSessionMetadata, WSSessionMetadata } from '#types'; export interface SessionDiscoveredEvent { session: IPTYSession; source: SessionSource; } export interface SessionLostEvent { sessionId: string; source: SessionSource; reason: string; } export interface SessionOutputEvent { sessionId: string; data: Buffer; } export interface SessionExitEvent { sessionId: string; exitCode: number; signal?: string; } export interface SessionResizedEvent { sessionId: string; cols: number; rows: number; } export interface SessionFocusChangedEvent { sessionId: string; focused: boolean; } /** * Function type for creating proxy sessions. * Provided externally so core doesn't need to import ProxyPTYSession directly. */ export type ProxySessionFactory = (transport: IPTYTransport, options: { id: string; source: SessionSource; remoteSessionId: string; pid: number; command: string; cwd: string; cols: number; rows: number; metadata: IPCSessionMetadata | WSSessionMetadata; }) => IPTYSession; export declare class PTYSessionManager extends EventEmitter { private sessions; private transports; private transportSessions; private proxySessionFactory; /** * Set the factory used to create proxy sessions from transport announcements. */ setProxySessionFactory(factory: ProxySessionFactory): void; /** * Register a session (local or proxy) */ registerSession(session: IPTYSession): void; /** Get a session by ID */ getSession(sessionId: string): IPTYSession | null; /** Get all sessions */ getSessions(): IPTYSession[]; /** Get sessions by source */ getSessionsBySource(source: SessionSource): IPTYSession[]; /** Get session info */ getSessionInfo(sessionId: string): PTYSessionState | null; /** Get all session infos */ getAllSessionInfos(): PTYSessionState[]; /** Write to a session */ write(sessionId: string, data: string | Buffer): boolean; /** Resize a session */ resize(sessionId: string, cols: number, rows: number): boolean; /** Kill a session */ kill(sessionId: string, signal?: string): boolean; /** Get output buffer */ getOutputBuffer(sessionId: string, maxBytes?: number): Buffer | null; /** * Register a transport * * When a transport is registered, the manager will automatically: * - Listen for session announcements * - Create proxy sessions for announced sessions * - Forward events between transport and sessions */ registerTransport(transport: IPTYTransport): void; /** Unregister a transport */ unregisterTransport(transportId: string): void; /** Get a transport by ID */ getTransport(transportId: string): IPTYTransport | null; private handleSessionAnnounced; private handleSessionEnded; private handleTransportDisconnected; /** Get the transport ID for a session */ getTransportIdForSession(sessionId: string): string | null; /** Dispose all sessions and transports */ dispose(): void; } export declare function createPTYSessionManager(): PTYSessionManager; //# sourceMappingURL=pty-session-manager.d.ts.map