/** * Background consolidation for long-running memory quality (Phase 1). * * Phase-1 changes vs the legacy Postgres-only job: * - Removed the `isPostgresEnabled()` short-circuit. The job is now * backend-polymorphic via `getMemoryRepository()` (mirror of the * memory-repository-factory dispatch) and `getGraphStore()`. * - Decay now delegates to the pure `decayScore` (services/memory/decay.ts) * for BOTH backends; pinned memories are exempt. * - Prune is now SOFT-delete (`deleted_at` tombstone) instead of hard DELETE, * and is pinned-aware + deleted_at-aware. * - New merge phase: clusters near-duplicates via `consolidateWindow` and, * for each batch, inserts a new memory + a SUPERSEDES edge per source. * - Emits `memory:consolidated` via EventBus per batch. * - `ConsolidationStats` extended with `{ merged, batchesCreated }`. * - LLM-gated + silent-degrade: when the LLM is disabled or fails, the merge * phase is skipped and the rule-based (decay + prune) path completes with * `merged=0, batchesCreated=0` and no error propagated. */ import { type LlmSurface } from "../memory/consolidator.js"; export interface ConsolidationStats { promoted: number; decayed: number; pruned: number; edgesCleaned: number; /** Phase 1: number of source memories folded into batches. */ merged: number; /** Phase 1: number of consolidation batches created. */ batchesCreated: number; } export declare class MemoryConsolidationJob { private running; private lastRunAt; private runCount; private readonly minIntervalMs; private readonly llm; constructor(opts?: { llm?: LlmSurface; }); maybeRun(trigger?: "store" | "search"): void; private runOnce; /** * Run one consolidation cycle against the active backend. Exposed for tests. */ consolidate(): Promise; /** * Decay: for each candidate, compute the pure decayScore and write it back * as the new importance. Pinned + soft-deleted rows are excluded by the * candidate query. Errors per-row are swallowed. */ private decayStaleMemories; /** * Prune: soft-delete memories that are old + cold + low-access. Pinned and * already-tombstoned rows are excluded. Uses the soft-delete path so rows * remain restorable; a future ops job can hard-purge long-tombstoned rows. */ private pruneColdMemories; /** * Merge: cluster near-duplicates and, via the LLM, produce a consolidated * memory that SUPERSEDES its sources. LLM-gated + silent-degrade. */ private mergeMemories; /** * Phase-0 session→user promotion. Preserved for PG; on PostgreSQL this is a * no-op (the original raw-SQL used Postgres `NOW()`/CTE features). Soft-fail. */ private promoteSessionMemories; } export declare const memoryConsolidationJob: MemoryConsolidationJob; //# sourceMappingURL=memory-consolidation-job.d.ts.map