/**
 * Enhanced Memory Persistence System
 *
 * Features:
 * - Long-term memory with semantic search
 * - Project context memory
 * - User preferences learning
 * - Conversation summaries
 * - Memory categories and tags
 * - Memory decay and importance scoring
 *
 * Enables Grok to remember context across sessions.
 */
import { EventEmitter } from 'events';
export interface MemoryEntry {
    id: string;
    type: MemoryType;
    content: string;
    summary?: string;
    embedding?: number[];
    importance: number;
    accessCount: number;
    createdAt: Date;
    updatedAt: Date;
    lastAccessedAt: Date;
    expiresAt?: Date;
    tags: string[];
    metadata: Record<string, unknown>;
    projectId?: string;
    sessionId?: string;
}
export type MemoryType = 'fact' | 'preference' | 'pattern' | 'decision' | 'context' | 'summary' | 'instruction' | 'error' | 'definition';
export interface ProjectMemory {
    projectId: string;
    projectPath: string;
    name: string;
    description?: string;
    languages: string[];
    frameworks: string[];
    conventions: CodeConvention[];
    memories: string[];
    createdAt: Date;
    updatedAt: Date;
}
export interface CodeConvention {
    type: 'naming' | 'structure' | 'style' | 'testing' | 'documentation';
    rule: string;
    examples?: string[];
    confidence: number;
}
export interface ConversationSummary {
    id: string;
    sessionId: string;
    summary: string;
    topics: string[];
    decisions: string[];
    todos: string[];
    timestamp: Date;
    messageCount: number;
}
export interface UserProfile {
    id: string;
    preferences: UserPreferences;
    skills: SkillLevel[];
    interests: string[];
    history: UserHistory;
    createdAt: Date;
    updatedAt: Date;
}
export interface UserPreferences {
    codeStyle: string;
    verbosity: 'minimal' | 'moderate' | 'detailed';
    language?: string;
    editor?: string;
    themes?: string[];
    customInstructions?: string;
}
export interface SkillLevel {
    skill: string;
    level: 'beginner' | 'intermediate' | 'advanced' | 'expert';
    confidence: number;
}
export interface UserHistory {
    topLanguages: Array<{
        language: string;
        usage: number;
    }>;
    commonTasks: Array<{
        task: string;
        frequency: number;
    }>;
    lastProjects: string[];
}
export interface MemorySearchOptions {
    query?: string;
    types?: MemoryType[];
    tags?: string[];
    projectId?: string;
    minImportance?: number;
    limit?: number;
    includeExpired?: boolean;
}
export interface MemoryConfig {
    enabled: boolean;
    maxMemories: number;
    maxMemoryAge: number;
    decayRate: number;
    minImportance: number;
    autoSummarize: boolean;
    summarizeThreshold: number;
    embeddingEnabled: boolean;
    embeddingModel?: string;
    /** Use SQLite database instead of JSON files */
    useSQLite: boolean;
}
/**
 * Enhanced Memory Manager
 */
export declare class EnhancedMemory extends EventEmitter {
    private config;
    private dataDir;
    private memories;
    private projects;
    private summaries;
    private userProfile;
    private currentProjectId;
    private decayIntervalId;
    private dbRepository;
    private embeddingProvider;
    constructor(config?: Partial<MemoryConfig>);
    /**
     * Initialize memory system
     */
    private initialize;
    /**
     * Load memories from disk or SQLite
     */
    private loadMemories;
    /**
     * Load projects from disk
     */
    private loadProjects;
    /**
     * Load user profile
     */
    private loadUserProfile;
    /**
     * Load conversation summaries
     */
    private loadSummaries;
    /**
     * Save all data
     */
    private saveAll;
    /**
     * Store a memory
     */
    store(options: {
        type: MemoryType;
        content: string;
        summary?: string;
        importance?: number;
        tags?: string[];
        metadata?: Record<string, unknown>;
        projectId?: string;
        sessionId?: string;
        expiresIn?: number;
    }): Promise<MemoryEntry>;
    /**
     * Calculate importance score
     */
    private calculateImportance;
    /**
     * Generate embedding using @xenova/transformers (local) or fallback to hash
     */
    private generateEmbedding;
    /**
     * Recall memories
     */
    recall(options?: MemorySearchOptions): Promise<MemoryEntry[]>;
    /**
     * Cosine similarity
     */
    private cosineSimilarity;
    /**
     * Forget a memory
     */
    forget(id: string): Promise<boolean>;
    /**
     * Apply memory decay
     */
    private applyDecay;
    /**
     * Enforce memory limits
     */
    private enforceMemoryLimits;
    /**
     * Store project context
     */
    setProjectContext(projectPath: string): Promise<ProjectMemory>;
    /**
     * Save project
     */
    private saveProject;
    /**
     * Learn a code convention
     */
    learnConvention(options: {
        type: CodeConvention['type'];
        rule: string;
        examples?: string[];
        confidence?: number;
    }): Promise<void>;
    /**
     * Store conversation summary
     */
    storeSummary(options: {
        sessionId: string;
        summary: string;
        topics: string[];
        decisions?: string[];
        todos?: string[];
        messageCount: number;
    }): Promise<ConversationSummary>;
    /**
     * Update user profile
     */
    updateUserProfile(updates: Partial<UserProfile>): Promise<UserProfile>;
    /**
     * Get user profile
     */
    getUserProfile(): UserProfile | null;
    /**
     * Get project memory
     */
    getProjectMemory(projectId?: string): ProjectMemory | null;
    /**
     * Build context from memories
     */
    buildContext(options?: {
        maxTokens?: number;
        includeProject?: boolean;
        includePreferences?: boolean;
        includeRecentSummaries?: boolean;
        query?: string;
    }): Promise<string>;
    /**
     * Get stats
     */
    getStats(): {
        totalMemories: number;
        byType: Record<MemoryType, number>;
        projects: number;
        summaries: number;
    };
    /**
     * Format status
     */
    formatStatus(): string;
    /**
     * Clear all memories
     */
    clear(): Promise<void>;
    /**
     * Dispose
     */
    dispose(): void;
}
export declare function getEnhancedMemory(config?: Partial<MemoryConfig>): EnhancedMemory;
export declare function resetEnhancedMemory(): void;
