/** * Memory Knowledge Graph — the K7 derived index: status, adjacency entries, * origin-support entries, the dual-write hooks that keep them in sync, and * the indexed reads used once a scope is `ready`. Split out of * memory-kg.ts, which re-exports the public symbols. */ import type { KgNamespaces, KgScope } from './memory-kg-model.js'; import type { KgReferenceEdge, ScannedEntry } from './memory-kg-scan.js'; export type KgIndexState = 'absent' | 'building' | 'validating' | 'ready' | 'failed'; export interface KgIndexStatus { state: KgIndexState; schemaVersion: number; /** Resume point for an interrupted `kgRebuildIndex`. */ cursor?: { phase: 'nodes' | 'edges' | 'rules'; offset: number; }; counts?: { nodes: number; edges: number; rules: number; }; startedAt?: number; updatedAt?: number; error?: string; /** Only meaningful when `state === 'failed'`. True for a build-phase * failure (the backend went unavailable mid-scan, or a dual-write hook * hit an error after `ready`): everything already written is still * correct, just incomplete, so the next call RESUMES from `cursor`. False * for a validation-phase failure (the built index disagreed with an * independent reference read): something already written is wrong, not * merely incomplete, so the next call restarts a fresh scan — resuming * would re-derive the same mistake instead of correcting it. */ resumable?: boolean; } export declare const KG_INDEX_SCHEMA_VERSION = 1; export declare function readIndexStatus(ns: KgNamespaces, dbPath: string | undefined): Promise; export declare function writeIndexStatus(ns: KgNamespaces, status: KgIndexStatus, dbPath: string | undefined): Promise; /** This scope's derived-index build/readiness state. `absent` means no one * has ever called `kgRebuildIndex` for it — every read behaves exactly as * it did before this index existed. */ export declare function kgIndexStatus(options?: { scope?: KgScope; dbPath?: string; }): Promise; interface KgAdjEntry { edgeKeys: string[]; } export declare function readAdj(ns: KgNamespaces, entityId: string, dbPath: string | undefined): Promise; export declare function addToAdj(ns: KgNamespaces, entityId: string, edgeKey: string, dbPath: string | undefined): Promise; interface KgOriginIndexRef { ns: string; key: string; } export declare function addToOriginIndex(ns: KgNamespaces, originRef: string, ref: KgOriginIndexRef, dbPath: string | undefined): Promise; /** After a node/edge/rule write lands, record that `originRef` supports it. */ export declare function onEntrySupported(ns: KgNamespaces, entryNs: string, entryKey: string, originRef: string, dbPath: string | undefined): Promise; /** After an edge write lands, record it in both endpoints' adjacency. */ export declare function onEdgeWritten(ns: KgNamespaces, edgeKey: string, src: string, dst: string, dbPath: string | undefined): Promise; /** After `kgRollback` deletes an entry outright (no origin left to support * it), remove it from every index it could appear in. */ export declare function onEntryDeleted(ns: KgNamespaces, entryKey: string, dbPath: string | undefined, endpoints?: { src: string; dst: string; }): Promise; /** After `kgRollback` withdraws one origin's support from an entry that * survives (another origin still supports it), drop just that origin's ref. */ export declare function onOriginWithdrawn(ns: KgNamespaces, entryNs: string, entryKey: string, originRef: string, dbPath: string | undefined): Promise; /** The indexed equivalent of `kgReferenceEdges({ endpointId })`: edges * touching one entity, read via its adjacency entry instead of a namespace * scan. Returns `null` when any edge key it names cannot be resolved — a * torn index must never be presented as a complete answer. */ export declare function kgIndexedEdgesByEndpoint(ns: KgNamespaces, entityId: string, dbPath: string | undefined): Promise; /** The indexed equivalent of `collectByOrigin`: every {namespace,key} entry * one origin supports, read via its origin-index entry instead of scanning * every namespace. Returns `null` on any unresolvable ref, same reasoning * as `kgIndexedEdgesByEndpoint`. */ /** Returns each entry paired with the namespace it was read from (from the * index's own ref, not trusted from the entry itself) so a caller can sort * results back into per-namespace buckets without guessing. */ export declare function kgIndexedByOrigin(ns: KgNamespaces, originRef: string, dbPath: string | undefined): Promise<{ ns: string; entry: ScannedEntry; }[] | null>; export {}; //# sourceMappingURL=memory-kg-index.d.ts.map