/** * KnowledgeIndex — the narrow, engine-agnostic query interface (KG Req 3.7). * * The index is a derived cache of the YAML sources, never the source of * truth. Nothing outside `src/knowledge/index/` may import a concrete * engine; this seam keeps the storage engine swappable (design DD1). * * Requirements: KG 3.2, 3.4, 3.5, 3.8 * * @module */ import type { Entity, Relationship } from '../types.js'; export interface SearchOptions { type?: string; minConfidence?: number; limit?: number; } export interface EntityFilter { minConfidence?: number; } /** Thrown when the on-disk index schema is older than the CLI supports (KG Req 3.8, 11.4). */ export declare class IndexOutdatedError extends Error { constructor(found: number, expected: number); } export interface KnowledgeIndex { getEntity(id: string): Entity | undefined; upsertEntity(entity: Entity): void; deleteEntity(id: string): void; /** Ranked full-text search across name, description, and tags (KG Req 3.4, 5.7). */ fullTextSearch(term: string, options?: SearchOptions): Entity[]; getAllEntities(filter?: EntityFilter): Entity[]; getEntitiesByTypes(types: string[], filter?: EntityFilter): Entity[]; /** Entities mapped to a source file path (staleness detection, KG Req 7.3). */ getEntitiesByFilePath(path: string): Entity[]; countEntitiesByType(type: string): number; upsertRelationship(rel: Relationship): void; relationshipsFrom(id: string): Relationship[]; relationshipsTo(id: string): Relationship[]; relationshipsFor(ids: string[]): Relationship[]; countRelationshipsByType(type: string): number; /** * Replace all index contents from parsed YAML sources (KG Req 3.3). * * **An implementation MUST discard any recorded source fingerprint it is not * given**, atomically with the contents. The freshness invariant rests on it: a * fingerprint may exist only because a caller vouched for *these* contents, so * that the way to get a stale cache hit is to stamp a fingerprint you did not * earn — a much smaller thing to keep right than remembering to clear one. An * implementation that keeps the old record instead lets `compact`, which rebuilds * from deduplicated entities rather than a plain load, serve contents the * fingerprint does not describe (knowledge-index-misses-merged-yaml/AC-4). * * @param fingerprint - Source fingerprint these contents were built from, recorded * in the same transaction. Omit — or pass `null` — when the caller cannot vouch * for a source state; the record is then cleared and the next open rebuilds. */ rebuild(entities: Entity[], relationships: Relationship[], fingerprint?: string | null): void; /** * Fingerprint of the YAML sources these contents were built from, or `null` when * none is recorded. * * "Which source state am I a cache of" is a property of a cache, so it belongs on * this interface rather than beside it. `null` means rebuild, never "assume fresh" * (knowledge-index-misses-merged-yaml/AC-4). */ getSourceFingerprint(): string | null; /** Record the fingerprint the current contents were built from. */ setSourceFingerprint(fingerprint: string): void; close(): void; } //# sourceMappingURL=knowledge-index.d.ts.map