/**
 * Session Tracker for CLIProxy Multi-Instance Support
 *
 * Manages reference counting for shared CLIProxy instances.
 * Multiple CCS sessions can share a single proxy on the same port.
 * Proxy only terminates when ALL sessions exit (count reaches 0).
 *
 * Lock file format: ~/.ccs/cliproxy/sessions.json
 * {
 *   "port": 8317,
 *   "pid": 12345,        // CLIProxy process PID
 *   "sessions": ["abc123", "def456"],  // Active session IDs
 *   "startedAt": "2024-01-01T00:00:00Z"
 * }
 */
/** Session lock file structure */
interface SessionLock {
    port: number;
    pid: number;
    sessions: string[];
    startedAt: string;
    /** CLIProxy version running (added for version mismatch detection) */
    version?: string;
    /** Backend type running (original vs plus) */
    backend?: 'original' | 'plus';
    /** Target summary for active sessions ('mixed' when multiple targets share the proxy) */
    target?: string;
    /** Per-session target metadata */
    sessionTargets?: Record<string, string>;
}
/** Get path to session lock file (default port) - kept for future use */
declare function _getSessionLockPath(): string;
export { _getSessionLockPath as getSessionLockPath };
export { deleteSessionLockForPort };
/** Delete session lock file for specific port */
declare function deleteSessionLockForPort(port: number): void;
/**
 * Check if there's an existing proxy running that we can reuse.
 * Returns the existing lock if proxy is healthy, null otherwise.
 */
export declare function getExistingProxy(port: number): SessionLock | null;
/**
 * Register a new session with the proxy.
 * Call this when starting a new CCS session that will use an existing proxy.
 * @param port Port the proxy is running on
 * @param proxyPid PID of the proxy process
 * @param version Optional CLIProxy version (stored when spawning new proxy)
 * @param backend Optional backend type (original vs plus)
 * @returns Session ID for this session
 */
export declare function registerSession(port: number, proxyPid: number, version?: string, backend?: 'original' | 'plus', target?: string): string;
/**
 * Unregister a session from the proxy.
 * @param sessionId Session ID to unregister
 * @param port Port to unregister from (optional, searches default port if not provided)
 * @returns true if this was the last session (proxy should be killed)
 */
export declare function unregisterSession(sessionId: string, port?: number): boolean;
/**
 * Get current session count for the proxy.
 * @param port Port to check (defaults to CLIPROXY_DEFAULT_PORT)
 */
export declare function getSessionCount(port?: number): number;
/**
 * Check if proxy has any active sessions.
 * Used to determine if a "zombie" proxy should be killed.
 * @param port Port to check (defaults to CLIPROXY_DEFAULT_PORT)
 */
export declare function hasActiveSessions(port?: number): boolean;
/**
 * Clean up orphaned sessions (when proxy crashes).
 * Called on startup to ensure clean state.
 */
export declare function cleanupOrphanedSessions(port: number): void;
/**
 * Stop the CLIProxy process and clean up session lock.
 * Falls back to port-based detection if no session lock exists.
 * @param port Port to stop (defaults to CLIPROXY_DEFAULT_PORT)
 * @returns Object with success status and details
 */
export declare function stopProxy(port?: number): Promise<{
    stopped: boolean;
    port?: number;
    pid?: number;
    sessionCount?: number;
    error?: string;
}>;
/**
 * Get proxy status information for specific port.
 */
export declare function getProxyStatus(port?: number): {
    running: boolean;
    port?: number;
    pid?: number;
    sessionCount?: number;
    startedAt?: string;
    version?: string;
    target?: string;
};
/**
 * Get the version of the running proxy from session lock.
 * @param port Port to check (defaults to CLIPROXY_DEFAULT_PORT)
 * @returns Version string if available, null otherwise
 */
export declare function getRunningProxyVersion(port?: number): string | null;
//# sourceMappingURL=session-tracker.d.ts.map