/** * Strategy Orchestrator * * Manages the lifecycle of indexing strategies: * - Creates and configures strategies based on configuration * - Handles strategy switching (flush old before starting new) * - Provides unified interface for server and tools * - Registers cleanup handlers for graceful shutdown * * The orchestrator is the single point of control for indexing strategies. * It ensures proper lifecycle management and prevents resource leaks. */ import { IndexingStrategy, StrategyStats } from './indexingStrategy.js'; import { IndexManager } from './indexManager.js'; import { DocsIndexManager } from './docsIndexManager.js'; import { IntegrityEngine } from './integrity.js'; import { IndexingPolicy } from './indexPolicy.js'; import { FingerprintsManager } from '../storage/fingerprints.js'; import { DocsFingerprintsManager } from '../storage/docsFingerprints.js'; import { Config } from '../storage/config.js'; /** * Dependencies required to create strategies */ export interface StrategyOrchestratorDependencies { /** Absolute path to the project root */ projectPath: string; /** Absolute path to the index directory */ indexPath: string; /** IndexManager for code file updates */ indexManager: IndexManager; /** DocsIndexManager for doc file updates (nullable if docs indexing disabled) */ docsIndexManager: DocsIndexManager | null; /** IntegrityEngine for drift detection and reconciliation (used by git strategy) */ integrityEngine: IntegrityEngine; /** IndexingPolicy for file filtering */ policy: IndexingPolicy; /** FingerprintsManager for code file change detection */ fingerprints: FingerprintsManager; /** DocsFingerprintsManager for doc file change detection (nullable if docs indexing disabled) */ docsFingerprints: DocsFingerprintsManager | null; } /** * Strategy Orchestrator * * Manages the lifecycle of indexing strategies. Provides a unified interface * for the server and tools to interact with the active indexing strategy. * * Key responsibilities: * - Create strategies based on configuration * - Handle strategy switching (flush before switch to prevent data loss) * - Provide flush() for tools to call before search * - Register cleanup handlers for graceful shutdown * * @example * ```typescript * const orchestrator = new StrategyOrchestrator({ * projectPath: '/path/to/project', * indexPath: '/path/to/index', * indexManager, * docsIndexManager, * integrityEngine, * policy, * fingerprints, * docsFingerprints, * }); * * // Start with realtime strategy * await orchestrator.setStrategy({ indexingStrategy: 'realtime', ... }); * * // Later, switch to lazy strategy * await orchestrator.setStrategy({ indexingStrategy: 'lazy', ... }); * * // Before search, flush pending changes * await orchestrator.flush(); * * // On shutdown * await orchestrator.stop(); * ``` */ export declare class StrategyOrchestrator { private readonly projectPath; private readonly indexPath; private readonly indexManager; private readonly docsIndexManager; private readonly integrityEngine; private readonly policy; private readonly fingerprints; private readonly docsFingerprints; private currentStrategy; private cleanupHandler; /** * Create a new StrategyOrchestrator instance * * @param deps - Dependencies required for strategy creation */ constructor(deps: StrategyOrchestratorDependencies); /** * Set and start a strategy based on configuration * * If a strategy is already running: * 1. If same strategy type, does nothing (idempotent) * 2. Otherwise, flushes current strategy, stops it, then starts new one * * This method is idempotent - calling with the same strategy type * while that strategy is active is a no-op. * * @param config - Configuration containing indexingStrategy and related options * @throws Error if strategy creation or initialization fails */ setStrategy(config: Config): Promise; /** * Get the current strategy * * @returns Current strategy instance or null if none is active */ getCurrentStrategy(): IndexingStrategy | null; /** * Flush pending changes * * Delegates to the current strategy's flush() method. * This should be called before search operations to ensure fresh results. * * For realtime strategy, this is typically a no-op. * For lazy strategy, this processes all queued dirty files. * For git strategy, this triggers a full reconciliation. * * Safe to call even if no strategy is active. */ flush(): Promise; /** * Stop the current strategy * * Gracefully stops the current strategy: * 1. Flushes pending changes * 2. Stops the strategy * 3. Unregisters cleanup handler * * Safe to call even if no strategy is active. */ stop(): Promise; /** * Get strategy statistics * * Delegates to the current strategy's getStats() method. * * @returns Strategy statistics or null if no strategy is active */ getStats(): StrategyStats | null; /** * Check if a strategy is currently active * * @returns true if a strategy is running */ isActive(): boolean; /** * Create a strategy instance based on name * * @param name - Strategy name ('realtime', 'lazy', 'git') * @param config - Configuration with strategy-specific options * @returns New strategy instance (not yet initialized or started) * @throws Error if strategy name is unknown */ private createStrategy; /** * Get the project path */ getProjectPath(): string; /** * Get the index path */ getIndexPath(): string; } /** * Create a StrategyOrchestrator for a project * * @param deps - Dependencies required for strategy creation * @returns StrategyOrchestrator instance (no strategy active yet) */ export declare function createStrategyOrchestrator(deps: StrategyOrchestratorDependencies): StrategyOrchestrator; //# sourceMappingURL=strategyOrchestrator.d.ts.map