type TrustLevel = 'high' | 'medium' | 'low' | 'unverified'; type Visibility = 'private' | 'namespace' | 'global'; type MemorySource = 'user' | 'auto' | 'consolidation' | 'claude-code' | 'hook' | 'error'; type ConsolidationAction = 'merge' | 'prune' | 'decay' | 'reindex' | 'tombstone'; type OperationType = 'consolidate' | 'reindex' | 'import' | 'export'; type OperationStatus = 'running' | 'completed' | 'failed' | 'cancelled'; type RelationType = 'causes' | 'fixes' | 'contradicts' | 'relates_to' | 'part_of' | 'depends_on' | 'supersedes' | 'similar_to'; interface Entity { readonly id: string; readonly name: string; readonly entity_type: string; readonly namespace: string; readonly metadata: string; readonly created_at: string; readonly updated_at: string; readonly is_deleted: number; } interface Relation { readonly id: string; readonly source_entity_id: string; readonly target_entity_id: string; readonly relation_type: string; readonly weight: number; readonly metadata: string; readonly namespace: string; readonly valid_from: string | null; readonly valid_to: string | null; readonly created_at: string; readonly is_deleted: number; } interface MemoryEntity { readonly memory_id: string; readonly entity_id: string; readonly role: string; } interface Contradiction { readonly existing_id: string; readonly new_content: string; readonly existing_content: string; readonly similarity: number; readonly resolution: 'supersede' | 'coexist' | 'flag'; } interface Memory { readonly id: string; readonly content: string; readonly summary: string | null; readonly content_hash: string; readonly embedding_model: string; readonly embedding_dim: number; readonly namespace: string; readonly project_id: string | null; readonly agent_id: string | null; readonly source: MemorySource; readonly source_trust: TrustLevel; readonly visibility: Visibility; readonly schema_version: number; readonly category: string; readonly tags: string; readonly importance: number; /** v14: computed importance (surprise/dedup/adaptive/decay writers). * `importance` is the user-supplied value and is never system-mutated; * read COALESCE(effective_importance, importance). */ readonly effective_importance: number | null; readonly access_count: number; readonly created_at: string; readonly updated_at: string; readonly last_accessed_at: string | null; readonly expires_at: string | null; readonly is_deleted: number; readonly tombstoned_at: string | null; readonly supersedes_id: string | null; readonly superseded_by_id: string | null; readonly metadata: string; readonly valid_from: string | null; readonly valid_to: string | null; readonly surprise_score: number; readonly episode_id: string | null; readonly cluster_id: string | null; readonly review_interval_days: number | null; readonly ease_factor: number; readonly next_review_at: string | null; readonly review_count: number; } interface MemoryWithScore extends Memory { readonly similarity_score: number; /** * v0.26: cross-encoder relevance score when a reranker ran. Kept SEPARATE * from similarity_score (which stays on the RRF scale that explain.ts is * calibrated to); the final ordering is by rerank_score when present. */ readonly rerank_score?: number; } interface StoreResult { readonly id: string; readonly matched: boolean; readonly similarity?: number; } interface ForgetResult { readonly count: number; readonly ids: readonly string[]; readonly dry_run: boolean; } interface ProposedMerge { readonly keep_id: string; readonly tombstone_id: string; readonly similarity: number; readonly merged_tags: readonly string[]; readonly merged_importance: number; readonly reason: string; } interface ProposedDecay { readonly id: string; readonly current_importance: number; readonly new_importance: number; readonly days_since_access: number; } interface ProposedPrune { readonly id: string; readonly importance: number; readonly access_count: number; readonly age_days: number; readonly reason: string; } interface ProposedSweep { readonly id: string; readonly expired_at: string; } interface ConsolidationPlan { readonly operation_id: string; readonly namespace: string; readonly created_at: string; readonly proposed_merges: readonly ProposedMerge[]; readonly proposed_decays: readonly ProposedDecay[]; readonly proposed_prunes: readonly ProposedPrune[]; readonly proposed_ttl_sweeps: readonly ProposedSweep[]; readonly summary: { readonly merge_count: number; readonly decay_count: number; readonly prune_count: number; readonly sweep_count: number; }; } interface ConsolidationResult { readonly operation_id: string; readonly merged: number; readonly decayed: number; readonly pruned: number; readonly swept: number; } interface MemoryStats { /** Non-deleted memories (is_deleted=0). Includes superseded/window-closed. */ readonly total: number; /** * v0.29: currently-valid memories — non-deleted AND not superseded AND * validity window still open. This is what default reads return. */ readonly current: number; readonly by_category: Record; readonly by_source: Record; readonly by_trust: Record; readonly avg_importance: number; readonly oldest: string | null; readonly newest: string | null; readonly embedding_model: string; readonly db_size_bytes: number; readonly last_consolidation: string | null; readonly tombstone_count: number; } interface OperationRecord { readonly id: string; readonly type: OperationType; readonly status: OperationStatus; readonly namespace: string | null; readonly started_at: string; readonly completed_at: string | null; readonly items_total: number | null; readonly items_processed: number; readonly error: string | null; readonly metadata: string; } interface GraphNode { readonly entity: Entity; readonly memory_count: number; } interface GraphEdge { readonly relation: Relation; readonly source_name: string; readonly target_name: string; } interface GraphQueryResult { readonly nodes: readonly GraphNode[]; readonly edges: readonly GraphEdge[]; readonly traversal_depth: number; readonly mode?: 'overview' | 'traversal'; } interface Episode { readonly id: string; readonly title: string; readonly namespace: string; readonly started_at: string; readonly ended_at: string | null; readonly summary: string | null; readonly metadata: string; } interface EpisodeWithStats extends Episode { readonly memory_count: number; } interface VerbatimEntry { readonly id: string; readonly content: string; readonly content_hash: string; readonly namespace: string; readonly agent_id: string | null; readonly episode_id: string | null; readonly metadata: string; readonly created_at: string; } interface VerbatimWithScore extends VerbatimEntry { readonly relevance_score: number; readonly source: 'verbatim'; } interface VerbatimStats { readonly total: number; readonly by_namespace: Record; readonly oldest: string | null; readonly newest: string | null; readonly total_size_bytes: number; } interface BackfillResult { readonly total: number; readonly embedded: number; readonly skipped: number; readonly errors: number; } interface StoreResultExtended extends StoreResult { readonly contradictions?: readonly Contradiction[]; readonly surprise_score?: number; readonly entities_extracted?: readonly string[]; } export type { BackfillResult, ConsolidationAction, ConsolidationPlan, ConsolidationResult, Contradiction, Entity, Episode, EpisodeWithStats, ForgetResult, GraphEdge, GraphNode, GraphQueryResult, Memory, MemoryEntity, MemorySource, MemoryStats, MemoryWithScore, OperationRecord, OperationStatus, OperationType, ProposedDecay, ProposedMerge, ProposedPrune, ProposedSweep, Relation, RelationType, StoreResult, StoreResultExtended, TrustLevel, VerbatimEntry, VerbatimStats, VerbatimWithScore, Visibility };