/** * SONA Optimizer * * Processes trajectory outcomes to learn optimal routing patterns. * Integrates with keyword router and persistence layer. * * Features: * - Processes trajectory outcomes from hooksTrajectoryEnd * - Extracts keywords from tasks for pattern matching * - Maintains learned routing patterns with confidence scoring * - Persists patterns to .swarm/sona-patterns.json * * File-size sweep: split into sibling modules (sona-optimizer-types.ts, * sona-optimizer-keywords.ts, sona-optimizer-singleton.ts). This file remains * the entry point and re-exports everything that used to live here so every * existing import keeps working. * @module v1/cli/memory/sona-optimizer */ import type { LearnedPattern, RoutingSuggestion, SONAStats, TrajectoryOutcome } from './sona-optimizer-types.js'; /** * SONA Optimizer for adaptive routing based on trajectory outcomes * * Learns from past task outcomes to improve future routing decisions. */ export declare class SONAOptimizer { private patterns; private trajectoriesProcessed; private successfulRoutings; private failedRoutings; private lastUpdate; private persistencePath; /** Set when in-memory state diverges from disk — triggers next debounced write */ private dirty; /** NodeJS timeout handle for debounced disk flush */ private saveTimer; /** Debounce window for disk writes (ms) — batches rapid trajectory bursts */ private static readonly SAVE_DEBOUNCE_MS; constructor(options?: { persistencePath?: string; }); /** * Initialize the optimizer and load persisted state */ initialize(): Promise<{ success: boolean; patternsLoaded: number; }>; /** * Process a trajectory outcome and learn from it * Called by hooksTrajectoryEnd */ processTrajectoryOutcome(outcome: TrajectoryOutcome): { learned: boolean; patternKey: string; confidence: number; keywordsExtracted: string[]; }; /** * Get routing suggestion based on learned patterns */ getRoutingSuggestion(task: string): RoutingSuggestion; /** * Get optimizer statistics */ getStats(): SONAStats; /** * Apply temporal decay to pattern confidence * Reduces confidence of unused patterns */ applyTemporalDecay(): number; /** * Reset all learned patterns */ reset(): void; /** * Export patterns for analysis */ exportPatterns(): Record; /** * Import patterns (for migration or testing) */ importPatterns(patterns: Record): number; /** * Find the best matching pattern for given keywords */ private findBestPatternMatch; /** * Prune old/low-confidence patterns if over limit */ private prunePatterns; /** * Load patterns from disk */ private loadFromDisk; /** * Schedule a debounced disk flush. * Multiple calls within SAVE_DEBOUNCE_MS coalesce into a single write, * preventing blocking I/O on every trajectory event during swarm bursts. */ private scheduleSave; /** * Save patterns to disk */ private saveToDisk; } export { default, getSONAOptimizer, getSONAStats, getSuggestion, processTrajectory, resetSONAOptimizer, } from './sona-optimizer-singleton.js'; export type { LearnedPattern, RoutingSuggestion, SONAStats, TrajectoryOutcome, } from './sona-optimizer-types.js'; //# sourceMappingURL=sona-optimizer.d.ts.map