autosnippet
Version:
Extract code patterns into a knowledge base for AI coding assistants
46 lines (45 loc) • 1.48 kB
JavaScript
/**
* Shared BootstrapSessionManager singleton management.
*
* Previously duplicated (with identical logic) in:
* - bootstrap-internal.ts → getOrCreateSessionManager()
* - bootstrap-external.ts → getSessionManager()
* - rescan-external.ts → getSessionManager()
*
* @module bootstrap/shared/session-helpers
*/
import { BootstrapSessionManager } from '../BootstrapSession.js';
// ── Process-level singleton ──────────────────────────────
let _sessionManager = null;
/**
* Get or create the process-level BootstrapSessionManager singleton.
*
* Resolution order:
* 1. Check container for registered instance
* 2. Fall back to module-level singleton
* 3. Register into container for cross-handler access
*/
export function getOrCreateSessionManager(container) {
// Check container first
try {
const mgr = container.get('bootstrapSessionManager');
if (mgr) {
return mgr;
}
}
catch {
/* not registered yet */
}
// Fall back to module-level singleton
if (!_sessionManager) {
_sessionManager = new BootstrapSessionManager();
}
// Register into container for cross-handler access
try {
container.register?.('bootstrapSessionManager', () => _sessionManager);
}
catch {
/* already registered or container doesn't support register */
}
return _sessionManager;
}