/** * Active Sessions Registry (GIT-19) * * CRUD operations for .gitmem/active-sessions.json — the multi-session * registry that tracks all running MCP server sessions. * * Key design decisions: * - Atomic writes (write-temp-rename) because multiple processes may * register/unregister concurrently. * - Sync I/O to match codebase convention (fs.writeFileSync etc). * - Graceful degradation: corrupted registry = start fresh. */ import type { ActiveSessionEntry } from "../types/index.js"; /** * A cheap fingerprint of the registry's current state (GIT-51). * * Session recovery needs to know whether it is worth retrying. The registry is * written by OTHER processes — notably the SessionStart hook, which runs as its * own CLI process (scar 55d1bccd) — so "I already failed to recover" is only * valid until someone else touches the file. * * Returns null when neither the registry nor the sessions directory exists, * which is itself a stable state worth caching against. * * GIT-89: covers the sessions directory as well as the registry. Identity now * resolves from sessions//session.json, so a fingerprint that watched only * active-sessions.json would keep the "already failed" latch closed over a * session that had since appeared on disk — reintroducing the permanent * fail-closed behaviour the fingerprint was introduced to prevent. */ export declare function getRegistryFingerprint(): number | null; /** * Register a new session in the active-sessions registry. * Idempotent: re-registering the same session_id replaces the entry. * Returns session IDs that were displaced (different session_id, same hostname+pid). */ export declare function registerSession(entry: ActiveSessionEntry): string[]; /** * Unregister a session from the active-sessions registry. * Returns true if the session was found and removed. */ export declare function unregisterSession(sessionId: string): boolean; /** * List all active sessions from the registry. */ export declare function listActiveSessions(): ActiveSessionEntry[]; /** * Find a session by hostname and PID. * Used by session_start to detect if this process already has a registered session. */ export declare function findSessionByHostPid(hostname: string, pid: number): ActiveSessionEntry | null; /** * Find a session by session_id. */ export declare function findSessionById(sessionId: string): ActiveSessionEntry | null; export declare function findResumableSessionOnDisk(): ActiveSessionEntry | null; /** * Prune stale sessions from the registry (GIT-22 enhanced). * * A session is stale if: * 1. Its started_at is older than 24 hours, OR * 2. Its per-session directory/session.json is missing (orphaned registry entry) * * GIT-51: A dead PID is NOT on its own grounds for pruning. The MCP server * restarting mid-session leaves exactly that signature, and deleting the entry * (and its session directory) destroys a live session's state. Dead-PID entries * are left for adoptSessionForCurrentProcess() to recover, and fall out on the * 24h age path if nobody claims them. * * Also cleans up per-session directories for pruned sessions, * and removes orphaned session directories with no registry entry. * Returns the number of sessions pruned. */ export declare function pruneStale(): number; /** * GIT-23: Migrate from old active-session.json (singular) to new multi-session format. * * Runs once per process. If old file exists and new registry does not: * 1. Read old file * 2. Create per-session directory with session.json * 3. Create active-sessions.json registry with single entry * 4. Rename old file to active-session.json.migrated (backup) * * Idempotent: skips if new registry already exists or old file is absent. */ export declare function migrateFromLegacy(): boolean; /** * Reset migration flag (for testing only). */ export declare function resetMigrationFlag(): void; //# sourceMappingURL=active-sessions.d.ts.map