/** * memory-consolidation.ts, idle-time memory consolidation policy (HOISTED to the SDK). * * PROVENANCE. Promoted verbatim (semantics-preserving) from the agent surface * (`src/agent/memory-consolidation.ts`) so every consumer shares ONE * consolidation contract with injectable I/O, rather than each re-deriving it. * The only surface-coupled part, the record writes, is expressed as an * injected `MemoryConsolidationRegistry` seam; `MemoryRegistry` satisfies it * structurally. * * The pass performs only REVERSIBLE operations on existing records: it merges * duplicate records into a survivor and marks the losers stale (never deletes), * and it decays never-referenced, aged records (lowering confidence, then marking * stale once the confidence floor is crossed). Anything that would require a NEW * standing memory or a destructive delete is emitted as a PROPOSAL routed to the * existing confirmation-gated path, this pass never silently writes a new memory * or deletes a record. Every run returns a RECEIPT describing exactly what it * merged, archived, decayed, and proposed. */ import type { MemoryRecord, MemoryReviewPatch, MemoryScope } from './memory-store.js'; import type { ResolvedMemoryConsolidationConfig } from './memory-consolidation-config.js'; /** Honest per-memory usage signal consumed by the decay ordering. */ export interface MemoryConsolidationUsageSignal { readonly injectedCount: number; readonly referencedCount: number; readonly lastReferencedAt: number | null; } /** Lookup of the usage signal for a memory id; undefined when never instrumented. */ export type MemoryConsolidationUsageLookup = (memoryId: string) => MemoryConsolidationUsageSignal | undefined; export type MemoryConsolidationTrigger = 'idle' | 'schedule' | 'manual'; /** * The record-mutation seam the pass writes through. Structural, so a concrete * MemoryRegistry (or any equivalent wrapper) satisfies it and the policy stays * decoupled from the store implementation. Only reversible writes are used: * `review` (mark stale / lower confidence) and `update` (merge tag unions). */ export interface MemoryConsolidationRegistry { getAll(): readonly MemoryRecord[]; review(id: string, patch: MemoryReviewPatch): MemoryRecord | null; update(id: string, patch: { scope?: MemoryScope; summary?: string; detail?: string; tags?: string[]; }): MemoryRecord | null; } export interface MemoryConsolidationInput { readonly memoryRegistry: MemoryConsolidationRegistry; readonly config: ResolvedMemoryConsolidationConfig; readonly now: number; readonly trigger: MemoryConsolidationTrigger; readonly idle: boolean; /** Optional usage instrumentation. When present, never-referenced records decay first. */ readonly usageLookup?: MemoryConsolidationUsageLookup; /** * Optional deterministic random-suffix seam for the receipt `runId`. Defaults * to `Math.random()`-derived. Injected only so tests can assert a stable id; * production leaves it unset for the same behavior as the agent original. */ readonly randomSuffix?: () => string; } export interface MemoryConsolidationMergeEntry { readonly survivorId: string; readonly duplicateIds: readonly string[]; readonly scope: string; readonly cls: string; } export interface MemoryConsolidationArchiveEntry { readonly id: string; readonly reason: string; readonly previousConfidence: number; } export interface MemoryConsolidationDecayEntry { readonly id: string; readonly fromConfidence: number; readonly toConfidence: number; readonly referencedCount: number; } export interface MemoryConsolidationProposal { readonly kind: 'contradiction' | 'cross-scope-duplicate' | 'stale-delete'; readonly ids: readonly string[]; readonly route: string; readonly reason: string; } export interface MemoryConsolidationRunReceipt { readonly runId: string; readonly ranAt: string; readonly trigger: MemoryConsolidationTrigger; readonly idle: boolean; readonly scanned: number; readonly merged: readonly MemoryConsolidationMergeEntry[]; readonly archived: readonly MemoryConsolidationArchiveEntry[]; readonly decayed: readonly MemoryConsolidationDecayEntry[]; readonly proposed: readonly MemoryConsolidationProposal[]; readonly usageSignalAvailable: boolean; readonly note: string; } export declare function runMemoryConsolidation(input: MemoryConsolidationInput): MemoryConsolidationRunReceipt; //# sourceMappingURL=memory-consolidation.d.ts.map