import type { JsonObject } from "../autonomy/contracts.ts"; import { type FaultableFs } from "../util/faultable-fs.ts"; import { type AppendOrchestrationEventInput, type OrchestrationEvent } from "./contracts.ts"; export interface OrchestrationEventStoreOptions { agentDir: string; sessionId: string; now?: () => string; createEventId?: () => string; maxTailEvents?: number; maxTailBytes?: number; maxIdempotencyEvents?: number; /** * Injection seam for this store's mutating fs primitives. Defaults to real `node:fs` — omitting * this option is a zero-behavior-change no-op. Only the destructive-testing harness passes a * fault-injecting implementation (see `src/core/util/faultable-fs.ts`). */ fs?: FaultableFs; } export interface AppendOrchestrationEventOptions { expectedLastOrdinal?: number; /** Exact event admission under the append lock, before any durable file is written. */ validateBeforeCommit?: (event: OrchestrationEvent) => void; } export declare class OrchestrationEventStoreError extends Error { constructor(message: string); } export declare class OrchestrationConcurrencyError extends OrchestrationEventStoreError { constructor(expected: number, actual: number); } export declare class OrchestrationSnapshotRequiredError extends OrchestrationEventStoreError { readonly throughOrdinal: number; constructor(throughOrdinal: number); } /** * Append-only event tail with a replaceable full-state projection snapshot. Each immutable event is * its own commit record: idempotency data is derived directly from the bounded tail, while a small * mutable cursor remains only as a corruption high-water mark. Atomic rename prevents torn event * records without multiplying one transition into per-key marker files and atomic cursor rewrites. * Snapshot publication is two-phase (payload, then small baseline pointer), after which covered event * and legacy-index files are pruned. A crash at any point leaves either the old replay prefix or the * new verified snapshot authoritative; ordinals never reset. */ export declare class OrchestrationEventStore { readonly rootDir: string; readonly eventsDir: string; readonly idempotencyDir: string; readonly cursorPath: string; readonly snapshotsDir: string; readonly baselinePath: string; private readonly now; private readonly createEventId; private readonly maxTailEvents; private readonly maxTailBytes; private readonly maxIdempotencyEvents; private readonly fs; private readonly listeners; private verifiedSnapshotBaseline; private synchronizedIndexes; constructor(options: OrchestrationEventStoreOptions); append(input: AppendOrchestrationEventInput, options?: AppendOrchestrationEventOptions): OrchestrationEvent; readAll(): OrchestrationEvent[]; readAfter(ordinal: number): OrchestrationEvent[]; readProjectionSnapshot(): { throughOrdinal: number; projection: JsonObject; } | undefined; /** Replace a large replay prefix with one verified current-state snapshot and a bounded tail. */ compactIfNeeded(throughOrdinal: number, projection: () => JsonObject): boolean; subscribe(listener: (event: OrchestrationEvent) => void): () => void; private readAllUnlocked; private eventFileNamesUnlocked; private idempotencyFileNamesUnlocked; private snapshotFileNamesUnlocked; /** Event files are a contiguous append-only tail after the published snapshot. */ private assertContiguousTailOrdinalsUnlocked; /** A valid cursor may lag a newly published snapshot, but it must never lead its committed tail. */ private assertReadableTailUnlocked; private readBaselineUnlocked; private readProjectionSnapshotUnlocked; /** * Appends need a verified snapshot baseline but must not deserialize its projection on every event. * The baseline pointer remains small and is reread each time; an immutable snapshot is reparsed only * when its pointer or filesystem identity changes. */ private readVerifiedSnapshotBaselineUnlocked; private snapshotFileSignatureUnlocked; private unlinkManagedFile; private readEventFileUnlocked; /** * Reconcile the bounded immutable tail into an in-memory index. Independent writers are detected * from new ordinals while holding the shared lock, so normal same-process appends parse only events * committed by other writers. A bounded mutable cursor remains derived corruption evidence; legacy * per-key marker files are no longer needed or rewritten. */ private synchronizeIndexesUnlocked; } //# sourceMappingURL=event-store.d.ts.map