/** * GraphStore - Main knowledge graph storage manager * * Manages the append-only event log and snapshot lifecycle. * Uses the FileSystemInterface for IO operations. * * Key responsibilities: * - Initialize graph storage * - Append events to JSONL * - Maintain snapshot consistency * - Generate Markdown representation */ import type { FileSystemInterface } from '../../utils/storage/FileSystemInterface.js'; import type { Entity, GraphSnapshot, GraphStats, Observation, Relation, EntityInput, ObservationInput, RelationInput, GraphOperationResult } from '../../types/graph.js'; export declare class GraphStore { private readonly fs; private readonly storeRoot; private readonly storeId; private cachedSnapshot; private cachedIndex; private lastJsonlEtag; private writeQueue; private markerVerified; constructor(fs: FileSystemInterface, storeRoot: string, storeId?: string); /** * Serializes write operations to prevent race conditions. * All operations that read-modify-write must go through this lock. */ private withWriteLock; private get graphDir(); private get jsonlPath(); private get snapshotPath(); private get markdownPath(); private get indexPath(); /** * Initializes the graph storage * Creates necessary directories and files with marker */ initialize(): Promise>; /** * Validates the marker in the JSONL file */ validateMarker(): Promise>; /** * Checks if the graph has been initialized */ isInitialized(): Promise; /** * Appends an event to the JSONL file * Uses filesystem append (O_APPEND) instead of read-modify-write. * Serialized via writeQueue to prevent concurrent-append race conditions. */ private appendEvent; /** * Upserts an entity (create or update) */ upsertEntity(input: EntityInput): Promise>; /** * Deletes an entity and its associated observations and relations */ deleteEntity(nameOrId: string): Promise>; /** * Adds an observation to an entity */ addObservation(input: ObservationInput): Promise>; /** * Deletes a specific observation by ID */ deleteObservation(observationId: string): Promise>; /** * Links two entities with a relation * Idempotent - same link won't create duplicates */ linkEntities(input: RelationInput): Promise>; /** * Removes a relation between two entities */ unlinkEntities(from: string, relationType: string, to: string): Promise>; /** * Gets the current snapshot, rebuilding if necessary */ getSnapshot(): Promise>; /** * Tries to load snapshot from disk using index for staleness check. * Returns the snapshot if it's still valid, null otherwise. */ private tryLoadCachedSnapshot; /** * Checks if snapshot needs rebuilding */ private checkNeedsRebuild; /** * Rebuilds the snapshot from JSONL */ rebuildSnapshot(): Promise>; /** * Compacts the JSONL event log by replacing it with a minimal representation: * marker + one upsert per entity + one add per observation + one add per relation * + a snapshot_written sentinel. * * This reduces log size without losing current state. */ compact(): Promise>; /** * Gets graph statistics */ getStats(): Promise>; /** * Gets the Markdown representation */ getMarkdown(): Promise>; /** * Clears the in-memory cache */ clearCache(): void; } /** * Creates a GraphStore instance for a memory bank */ export declare function createGraphStore(fs: FileSystemInterface, memoryBankRoot: string, storeId?: string): GraphStore; //# sourceMappingURL=GraphStore.d.ts.map