/**
 * Episodic Memory System - Cross-session pattern learning with semantic indexing
 *
 * Features:
 * 1. Episode detection and boundary marking
 * 2. Semantic indexing via vector embeddings (pluggable providers)
 * 3. Cross-session pattern learning and retrieval
 * 4. Task-specific memory with temporal decay
 * 5. Memory consolidation and pruning
 *
 * Storage: ~/.agi/episodic-memory/
 *   - episodes.json     (episode metadata index)
 *   - embeddings.bin    (vector embeddings cache)
 *   - patterns.json     (learned patterns)
 */
export interface Episode {
    id: string;
    sessionId: string;
    startTime: number;
    endTime: number;
    /** User's original intent/prompt that started this episode */
    intent: string;
    /** Category of work performed */
    category: EpisodeCategory;
    /** Tools used during this episode */
    toolsUsed: string[];
    /** Key files touched */
    filesModified: string[];
    /** Whether the episode was successful */
    success: boolean;
    /** Summary of what was accomplished */
    summary: string;
    /** Tags for semantic grouping */
    tags: string[];
    /** Embedding vector for semantic search (optional) */
    embedding?: number[];
    /** Parent episode if this is a sub-task */
    parentId?: string;
    /** Retrieval count for popularity weighting */
    retrievalCount: number;
    /** Last time this episode was retrieved */
    lastRetrieved: number;
}
export type EpisodeCategory = 'bug_fix' | 'feature_add' | 'refactor' | 'test_write' | 'documentation' | 'analysis' | 'configuration' | 'debugging' | 'optimization' | 'migration' | 'unknown';
export interface LearnedApproach {
    id: string;
    /** Pattern that triggers this approach (normalized) */
    triggerPattern: string;
    /** Keywords for fast matching */
    keywords: string[];
    /** Step-by-step approach that worked */
    approach: string[];
    /** Tools typically used */
    tools: string[];
    /** Success rate (0-1) */
    successRate: number;
    /** Number of times this approach was used */
    useCount: number;
    /** Episode IDs that contributed to this pattern */
    sourceEpisodes: string[];
    /** Embedding for semantic matching */
    embedding?: number[];
    /** Last update timestamp */
    updatedAt: number;
}
export interface MemoryQuery {
    /** Natural language query */
    query: string;
    /** Filter by category */
    category?: EpisodeCategory;
    /** Filter by tags */
    tags?: string[];
    /** Filter by time range (ms since epoch) */
    since?: number;
    /** Filter by success status */
    successOnly?: boolean;
    /** Maximum results */
    limit?: number;
    /** Minimum similarity threshold (0-1) */
    minSimilarity?: number;
}
export interface MemorySearchResult {
    episode: Episode;
    similarity: number;
    matchReason: string;
}
export interface EmbeddingProvider {
    /** Generate embedding vector for text */
    embed(text: string): Promise<number[]>;
    /** Dimension of embedding vectors */
    dimension: number;
    /** Provider name for tracking */
    name: string;
}
export interface EpisodicMemoryConfig {
    /** Maximum episodes to keep */
    maxEpisodes: number;
    /** Maximum learned approaches to keep */
    maxApproaches: number;
    /** Temporal decay factor (0-1, lower = faster decay) */
    decayFactor: number;
    /** Minimum similarity for semantic search (0-1) */
    minSimilarity: number;
    /** Enable embedding-based search */
    useEmbeddings: boolean;
    /** Embedding provider (optional) */
    embeddingProvider?: EmbeddingProvider;
    /** Storage directory */
    storageDir: string;
}
/**
 * Optimization profile for task-specific settings.
 * Used to configure RL tournament behavior, validation, and execution strategies
 * based on learned patterns from successful episodes.
 */
export interface OptimizationProfile {
    id: string;
    /** Category this profile applies to */
    category: EpisodeCategory;
    /** Policy name for human reference */
    policyName: string;
    /** Preferred upgrade mode for this category */
    preferredMode: 'single-continuous' | 'dual-rl-continuous' | 'dual-rl-tournament';
    /** Whether to use git worktrees for isolation */
    useGitWorktrees: boolean;
    /** Custom reward weights for RL tournament */
    rewardWeights: {
        executionSuccess: number;
        testsPassed: number;
        staticAnalysis: number;
        codeQuality: number;
        blastRadius: number;
        selfAssessment: number;
        speedBonus: number;
    };
    /** Tools that perform well for this category */
    preferredTools: string[];
    /** Success rate threshold for auto-approval */
    autoApprovalThreshold: number;
    /** Number of successful executions */
    successCount: number;
    /** Number of failed executions */
    failureCount: number;
    /** Last update timestamp */
    updatedAt: number;
}
export declare class EpisodicMemory {
    private config;
    private episodes;
    private approaches;
    private optimizationProfiles;
    private embeddingProvider;
    private dirty;
    private currentEpisode;
    private episodeToolsUsed;
    private episodeFilesModified;
    constructor(config?: Partial<EpisodicMemoryConfig>);
    /**
     * Start recording a new episode
     */
    startEpisode(intent: string, sessionId: string, category?: EpisodeCategory): string;
    /**
     * Record tool usage within current episode
     */
    recordToolUse(toolName: string): void;
    /**
     * Record file modification within current episode
     */
    recordFileModification(filePath: string): void;
    /**
     * End current episode and save to memory
     */
    endEpisode(success: boolean, summary: string): Promise<Episode | null>;
    /**
     * Abort current episode without saving
     */
    abortEpisode(): void;
    /**
     * Search for similar past episodes
     */
    search(query: MemoryQuery): Promise<MemorySearchResult[]>;
    /**
     * Get learned approach for a task
     */
    getApproach(intent: string): Promise<LearnedApproach | null>;
    /**
     * Get recent episodes for context
     */
    getRecentEpisodes(limit?: number, sessionId?: string): Episode[];
    /**
     * Learn patterns from a successful episode
     */
    private learnFromEpisode;
    /**
     * Record approach failure to update success rate
     */
    recordApproachFailure(approachId: string): void;
    private generateId;
    private inferCategory;
    private extractTags;
    private extractKeywords;
    private cosineSimilarity;
    private keywordSimilarity;
    /**
     * Get or create an optimization profile for a category.
     * Used by the RL tournament system to get task-specific settings.
     */
    getOptimizationProfile(category: EpisodeCategory, policyName?: string): OptimizationProfile;
    /**
     * Update optimization profile based on episode outcome.
     * Called after an episode completes to adjust learned settings.
     */
    updateOptimizationProfile(category: EpisodeCategory, success: boolean, options?: {
        toolsUsed?: string[];
        mode?: 'single-continuous' | 'dual-rl-continuous' | 'dual-rl-tournament';
        usedGitWorktrees?: boolean;
    }): void;
    /**
     * Get reward weights for a category, adjusted based on learned patterns.
     */
    getRewardWeights(category: EpisodeCategory): OptimizationProfile['rewardWeights'];
    /**
     * Update reward weights based on tournament outcomes.
     * Adjusts weights to favor signals that correlated with successful outcomes.
     */
    adjustRewardWeights(category: EpisodeCategory, winningSignals: Partial<OptimizationProfile['rewardWeights']>, success: boolean): void;
    /**
     * Get all optimization profiles for inspection.
     */
    getAllOptimizationProfiles(): OptimizationProfile[];
    private inferPreferredMode;
    private inferPreferredTools;
    private pruneEpisodes;
    private pruneApproaches;
    private load;
    save(): void;
    getStats(): {
        totalEpisodes: number;
        successfulEpisodes: number;
        totalApproaches: number;
        totalProfiles: number;
        categoryCounts: Record<string, number>;
        topTags: string[];
        profileSummary: {
            category: string;
            successRate: number;
            preferredMode: string;
        }[];
    };
}
/**
 * Get or create the default episodic memory instance
 */
export declare function getEpisodicMemory(config?: Partial<EpisodicMemoryConfig>): EpisodicMemory;
/**
 * Create a new episodic memory instance with custom config
 */
export declare function createEpisodicMemory(config?: Partial<EpisodicMemoryConfig>): EpisodicMemory;
//# sourceMappingURL=episodicMemory.d.ts.map