/**
 * Memory Consolidation System
 *
 * Like sleep consolidation in human brains, this system:
 * - Moves worthy short-term memories to long-term storage
 * - Strengthens frequently accessed memories
 * - Cleans up decayed/irrelevant memories
 * - Merges similar memories to reduce redundancy
 */
import { Memory, MemoryConfig, ConsolidationResult, ContextSummary } from './types.js';
/**
 * Run full consolidation process
 * This is like the brain's sleep consolidation - should be run periodically
 */
export declare function consolidate(config?: MemoryConfig): ConsolidationResult;
export interface DuplicateMemoryPair {
    memoryA: Memory;
    memoryB: Memory;
    recommendedKeepId: number;
    similarity: string;
    titleSimilarity: number;
    contentOverlap: number;
    sharedWords: number;
}
export declare function findDuplicateMemoryPairs(options?: {
    project?: string;
    limit?: number;
}): DuplicateMemoryPair[];
/**
 * De-duplicate long-term memories found as duplicate PAIRS by
 * findDuplicateMemoryPairs (same project|category, similar title + >0.5 content
 * overlap). Runs every ~4h on the auto path: server.ts setInterval → fullCleanup
 * → consolidate → deduplicateMemories.
 *
 * B11 (memory-quality fix): the previous implementation built
 * `kept.content + "\n\nMerged from duplicate:\n" + uniqueSentences` and wrote it
 * back with `UPDATE memories SET content = ?`. That was the SECOND lossy-append
 * site (mergeSimilarMemories was the first) and kept generating ever-growing
 * "frankenmemories" on this path even after the first site was fixed. The kept
 * memory's `content` is now NEVER modified.
 *
 * New policy (identical to mergeSimilarMemories — one source of truth):
 *   - KEEP the higher-EFFECTIVE-salience member of the pair (computeEffectiveSalience
 *     via the shared salience.mjs — recency/access/pin/downvote, same ranking as
 *     recall and the downvote CLI). NOTE: this can differ from the pair's raw
 *     `recommendedKeepId`, which only considered raw salience + recency.
 *   - Dispose the loser via the shared disposeLoser: combined similarity
 *     (re-measured vs the kept row) ≥ 0.85 → DELETE; below → DOWNVOTE (reversible).
 *   - Tags are unioned onto the kept row (metadata only, non-lossy). The kept
 *     content and salience are untouched.
 *
 * Defence re-scan removed (B11): the old re-scan existed ONLY to validate the
 * SYNTHESIZED concatenated merged body before persisting it (two individually-
 * clean rows could straddle a credential pattern across the join). Now that no
 * concatenation happens here, there is no synthesized content to scan — the kept
 * row's bytes are written verbatim and unchanged, exactly as they already exist
 * in `memories`. So this pass introduces no new bytes to validate. (This is a
 * narrow claim about THIS path: it does not assume every row was scanned at write
 * time — e.g. importMemories inserts rows with no scan — only that the dedup no
 * longer fabricates a new body that would need scanning.) Dropping the re-scan
 * also avoids re-auditing unchanged content on every 4h pass.
 *
 * Only rows clustered in THIS pass are acted on; historical merged rows are not
 * rewritten (effective salience demotes them over time). STM→LTM promotion is
 * handled separately by processDecay/promoteMemory in consolidate().
 */
export declare function deduplicateMemories(options?: {
    dryRun?: boolean;
}): {
    merged: number;
    pairs: Array<{
        kept: number;
        removed: number;
        similarity: string;
    }>;
};
/**
 * Group memories by topic and create summary memories for large clusters.
 */
export declare function clusterAndSummarise(options?: {
    minClusterSize?: number;
}): {
    clusters: number;
    summariesCreated: number;
};
/**
 * Enforce maximum memory limits
 * Removes lowest-priority memories when limits are exceeded
 */
export declare function enforceMemoryLimits(config?: MemoryConfig): number;
/**
 * Find clusters of similar short-term memories within each project|category,
 * KEEP the single highest-effective-salience member, and demote the rest
 * WITHOUT destroying or concatenating their content.
 *
 * B11 (memory-quality fix): the previous implementation appended every loser's
 * body into the kept memory ("Consolidated context:" bullets) and deleted the
 * losers. Over ~417 live rows this produced 188 ever-growing "frankenmemories"
 * — exactly the garbled content users complained about. The kept memory's
 * `content` is now NEVER modified.
 *
 * Disposition per loser (see NEAR_IDENTICAL_DELETE_THRESHOLD):
 *   - combined ≥ 0.85  → DELETE (near-identical; content already in the kept row)
 *   - combined < 0.85  → DOWNVOTE (reversible; sinks via effective salience)
 *
 * Why the split exists at all: NO reaping path (decay.ts shouldDelete,
 * prune.ts, expiry.ts, enforceMemoryLimits) reads `downvote_count` or effective
 * salience — they all order by raw `salience`. So downvote-ONLY would leave the
 * store unbounded (the dups sink in recall but never get pruned). Deleting the
 * near-identical losers keeps the store bounded with zero information loss; the
 * moderate near-dups are preserved and merely demoted.
 *
 * Tags are unioned onto the kept row and access counts summed (metadata only,
 * non-lossy). STM→LTM promotion is handled separately by processDecay/
 * promoteMemory in consolidate(); this function only de-duplicates.
 *
 * Returns the count of deleted (near-identical) losers.
 */
export declare function mergeSimilarMemories(project?: string, similarityThreshold?: number): number;
/**
 * Generate a context summary for session start
 * Provides a high-level view of relevant memories
 */
export declare function generateContextSummary(project?: string, config?: MemoryConfig): Promise<ContextSummary>;
/**
 * Format context summary as a readable string
 */
export declare function formatContextSummary(summary: ContextSummary): string;
/**
 * Start a new session
 * Creates a session record and returns relevant context
 */
export declare function startSession(project?: string): Promise<{
    sessionId: number;
    context: ContextSummary;
}>;
/**
 * End a session
 * Updates session record with summary
 */
export declare function endSession(sessionId: number, summary?: string): void;
/**
 * Get suggested context for the current query
 * Returns memories that might be relevant to what the user is working on
 */
export declare function getSuggestedContext(currentContext: string, project?: string, limit?: number): Promise<Memory[]>;
/**
 * Export memories as JSON (for backup/transfer)
 */
export declare function exportMemories(project?: string): string;
/**
 * Import memories from JSON
 */
export declare function importMemories(json: string): number;
/**
 * Vacuum database to reclaim space after deletions
 * Run periodically or after major cleanup operations
 */
export declare function vacuumDatabase(): {
    success: boolean;
    message: string;
};
/**
 * Preview what consolidation would do without actually doing it
 * Useful for dry-run mode
 */
export declare function previewConsolidation(config?: MemoryConfig): {
    toPromote: Memory[];
    toDelete: Memory[];
    totalShortTerm: number;
    totalLongTerm: number;
};
/**
 * Check if consolidation should be triggered based on memory state
 * Returns true if consolidation is recommended
 */
export declare function shouldTriggerConsolidation(config?: MemoryConfig): {
    shouldRun: boolean;
    reason: string;
};
/**
 * Full cleanup: consolidate + vacuum
 * Best run periodically to keep database healthy
 */
export declare function fullCleanup(config?: MemoryConfig): {
    consolidation: ConsolidationResult;
    vacuumed: boolean;
    merged: number;
    quarantineExpired: number;
};
export interface DreamModeResult {
    nearDuplicatesMerged: number;
    archivalCandidates: number;
    contradictionsDetected: number;
    totalProcessed: number;
}
/**
 * "Dream Mode" — comprehensive memory consolidation.
 *
 * 1. Find near-duplicates by embedding similarity >0.9, merge them
 * 2. Flag memories >30 days old with no access as archival candidates
 * 3. Detect and flag contradictions
 *
 * DISPOSAL POLICY — deliberately DIVERGES from the auto path:
 * This is the EXPLICIT, user-invoked `shieldcortex consolidate` command (and the
 * public `consolidateMemories` export). Because the user has actively asked for a
 * consolidation, aggressive cleanup is the intended behaviour: the loser of every
 * duplicate pair is HARD-DELETED. This is on purpose and must NOT be replaced with
 * the gentle `disposeLoser` policy.
 *
 * Contrast with the 4-hourly AUTO path (deduplicateMemories / mergeSimilarMemories),
 * which runs UNATTENDED and therefore uses the conservative `disposeLoser`: it only
 * deletes near-identical losers (combined ≥ 0.85, content already contained in the
 * kept row) and merely DOWNVOTES (reversible) the moderate near-dups. That caution
 * is right for an unsupervised background job, but wrong for a deliberate manual
 * cleanup the user explicitly triggered.
 *
 * The two paths DO share keep-selection: both pick the kept row by EFFECTIVE
 * salience (effectiveSalienceOfRow — recency/access/pin/downvote), so the row that
 * survives is consistent across all three dedup sites. Effective salience also
 * discriminates where the pair's raw `recommendedKeepId` (raw salience + recency)
 * ties at 1.0.
 */
export declare function consolidateMemories(): DreamModeResult;
