216 lines
7.1 KiB
TypeScript
216 lines
7.1 KiB
TypeScript
/**
|
|
* ControllerRegistry - Central controller lifecycle management for AgentDB v3
|
|
*
|
|
* Wraps the AgentDB class and adds CLI-specific controllers from @claude-flow/memory.
|
|
* Manages initialization (level-based ordering), health checks, and graceful shutdown.
|
|
*
|
|
* Per ADR-053: Replaces memory-initializer.js's raw sql.js usage with a unified
|
|
* controller ecosystem routing all memory operations through AgentDB v3.
|
|
*
|
|
* @module @claude-flow/memory/controller-registry
|
|
*/
|
|
import { EventEmitter } from 'node:events';
|
|
import type { IMemoryBackend, EmbeddingGenerator, SONAMode } from './types.js';
|
|
import type { LearningBridgeConfig } from './learning-bridge.js';
|
|
import type { MemoryGraphConfig } from './memory-graph.js';
|
|
import type { CacheConfig } from './types.js';
|
|
/**
|
|
* Controllers accessible via AgentDB.getController()
|
|
*/
|
|
export type AgentDBControllerName = 'reasoningBank' | 'skills' | 'reflexion' | 'causalGraph' | 'causalRecall' | 'learningSystem' | 'explainableRecall' | 'nightlyLearner' | 'graphTransformer' | 'mutationGuard' | 'attestationLog' | 'vectorBackend' | 'graphAdapter';
|
|
/**
|
|
* CLI-layer controllers (from @claude-flow/memory or new)
|
|
*/
|
|
export type CLIControllerName = 'learningBridge' | 'memoryGraph' | 'agentMemoryScope' | 'tieredCache' | 'hybridSearch' | 'federatedSession' | 'semanticRouter' | 'sonaTrajectory' | 'hierarchicalMemory' | 'memoryConsolidation' | 'batchOperations' | 'contextSynthesizer' | 'gnnService' | 'rvfOptimizer' | 'mmrDiversityRanker' | 'guardedVectorBackend';
|
|
/**
|
|
* All controller names
|
|
*/
|
|
export type ControllerName = AgentDBControllerName | CLIControllerName;
|
|
/**
|
|
* Initialization level for dependency ordering
|
|
*/
|
|
export interface InitLevel {
|
|
level: number;
|
|
controllers: ControllerName[];
|
|
}
|
|
/**
|
|
* Individual controller health status
|
|
*/
|
|
export interface ControllerHealth {
|
|
name: ControllerName;
|
|
status: 'healthy' | 'degraded' | 'unavailable';
|
|
initTimeMs: number;
|
|
error?: string;
|
|
}
|
|
/**
|
|
* Aggregated health report for all controllers
|
|
*/
|
|
export interface RegistryHealthReport {
|
|
status: 'healthy' | 'degraded' | 'unhealthy';
|
|
controllers: ControllerHealth[];
|
|
agentdbAvailable: boolean;
|
|
initTimeMs: number;
|
|
timestamp: number;
|
|
activeControllers: number;
|
|
totalControllers: number;
|
|
}
|
|
/**
|
|
* Runtime configuration for controller activation
|
|
*/
|
|
export interface RuntimeConfig {
|
|
/** Database path for AgentDB */
|
|
dbPath?: string;
|
|
/** Vector dimension (default: 384 for MiniLM) */
|
|
dimension?: number;
|
|
/** Embedding generator function */
|
|
embeddingGenerator?: EmbeddingGenerator;
|
|
/** Memory backend config */
|
|
memory?: {
|
|
enableHNSW?: boolean;
|
|
learningBridge?: Partial<LearningBridgeConfig>;
|
|
memoryGraph?: Partial<MemoryGraphConfig>;
|
|
tieredCache?: Partial<CacheConfig>;
|
|
};
|
|
/** Neural config */
|
|
neural?: {
|
|
enabled?: boolean;
|
|
modelPath?: string;
|
|
sonaMode?: SONAMode;
|
|
};
|
|
/** Controllers to explicitly enable/disable */
|
|
controllers?: Partial<Record<ControllerName, boolean>>;
|
|
/** Backend instance to use (if pre-created) */
|
|
backend?: IMemoryBackend;
|
|
}
|
|
/**
|
|
* Level-based initialization order per ADR-053.
|
|
* Controllers at each level can be initialized in parallel.
|
|
* Each level must complete before the next begins.
|
|
*/
|
|
export declare const INIT_LEVELS: InitLevel[];
|
|
/**
|
|
* Central registry for AgentDB v3 controller lifecycle management.
|
|
*
|
|
* Handles:
|
|
* - Level-based initialization ordering (levels 0-6)
|
|
* - Graceful degradation (each controller fails independently)
|
|
* - Config-driven activation (controllers only instantiate when enabled)
|
|
* - Health check aggregation across all controllers
|
|
* - Ordered shutdown (reverse initialization order)
|
|
*
|
|
* @example
|
|
* ```typescript
|
|
* const registry = new ControllerRegistry();
|
|
* await registry.initialize({
|
|
* dbPath: './data/memory.db',
|
|
* dimension: 384,
|
|
* memory: {
|
|
* enableHNSW: true,
|
|
* learningBridge: { sonaMode: 'balanced' },
|
|
* memoryGraph: { pageRankDamping: 0.85 },
|
|
* },
|
|
* });
|
|
*
|
|
* const reasoning = registry.get<ReasoningBank>('reasoningBank');
|
|
* const graph = registry.get<MemoryGraph>('memoryGraph');
|
|
*
|
|
* await registry.shutdown();
|
|
* ```
|
|
*/
|
|
export declare class ControllerRegistry extends EventEmitter {
|
|
private controllers;
|
|
private agentdb;
|
|
private backend;
|
|
private config;
|
|
private initialized;
|
|
private initTimeMs;
|
|
/**
|
|
* Initialize all controllers in level-based order.
|
|
*
|
|
* Each level's controllers are initialized in parallel within the level.
|
|
* Failures are isolated: a controller that fails to init is marked as
|
|
* unavailable but does not block other controllers.
|
|
*/
|
|
initialize(config?: RuntimeConfig): Promise<void>;
|
|
/**
|
|
* Shutdown all controllers in reverse initialization order.
|
|
*/
|
|
shutdown(): Promise<void>;
|
|
/**
|
|
* Get a controller instance by name.
|
|
* Returns null if the controller is not initialized or unavailable.
|
|
*/
|
|
get<T>(name: ControllerName): T | null;
|
|
/**
|
|
* Check if a controller is enabled and initialized.
|
|
*/
|
|
isEnabled(name: ControllerName): boolean;
|
|
/**
|
|
* Aggregate health check across all controllers.
|
|
*/
|
|
healthCheck(): Promise<RegistryHealthReport>;
|
|
/**
|
|
* Get the underlying AgentDB instance.
|
|
*/
|
|
getAgentDB(): any;
|
|
/**
|
|
* Get the memory backend.
|
|
*/
|
|
getBackend(): IMemoryBackend | null;
|
|
/**
|
|
* Check if the registry is initialized.
|
|
*/
|
|
isInitialized(): boolean;
|
|
/**
|
|
* Get the number of active (successfully initialized) controllers.
|
|
*/
|
|
getActiveCount(): number;
|
|
/**
|
|
* List all registered controller names and their status.
|
|
*/
|
|
listControllers(): Array<{
|
|
name: ControllerName;
|
|
enabled: boolean;
|
|
level: number;
|
|
}>;
|
|
/**
|
|
* Initialize AgentDB instance with dynamic import and fallback chain.
|
|
*/
|
|
private initAgentDB;
|
|
/**
|
|
* Check whether a controller should be initialized based on config.
|
|
*/
|
|
private isControllerEnabled;
|
|
/**
|
|
* Initialize a single controller with error isolation.
|
|
*/
|
|
private initController;
|
|
/**
|
|
* Factory method to create a controller instance.
|
|
* Handles CLI-layer controllers; AgentDB-internal controllers are
|
|
* accessed via agentdb.getController().
|
|
*/
|
|
private createController;
|
|
/**
|
|
* Shutdown a single controller gracefully.
|
|
*/
|
|
private shutdownController;
|
|
/**
|
|
* Create an EmbeddingService for controllers that need it.
|
|
* Uses the config's embedding generator or creates a minimal local service.
|
|
*/
|
|
private createEmbeddingService;
|
|
/**
|
|
* Lightweight in-memory tiered store (fallback when HierarchicalMemory
|
|
* cannot be initialized from agentdb).
|
|
* Enforces per-tier size limits to prevent unbounded memory growth.
|
|
*/
|
|
private createTieredMemoryStub;
|
|
/**
|
|
* No-op consolidation stub (fallback when MemoryConsolidation
|
|
* cannot be initialized from agentdb).
|
|
*/
|
|
private createConsolidationStub;
|
|
}
|
|
export default ControllerRegistry;
|
|
//# sourceMappingURL=controller-registry.d.ts.map
|