/** * Client Reconnection Protocol (v0.3.1b) * * Provides delta sync against the /sync endpoint and * local fact reconciliation for agent reconnection. * * Spec: docs/specs/totalreclaw/server.md v0.3.1b section 8.2 * * Protocol: * 1. Agent comes online * 2. GET /sync?since_sequence={last_known_sequence} * 3. Build set of server fingerprints: { content_fp -> fact_id } * 4. For each local pending fact: * a. If content_fp in server set -> skip * b. Else -> POST /store (server also checks, but pre-filtering avoids round trips) * 5. Update local last_known_sequence */ /** * A fact returned by the /sync endpoint. */ export interface SyncedFact { id: string; sequence_id: number | null; encrypted_blob: string; blind_indices: string[]; decay_score: number; is_active: boolean; version: number; source: string; content_fp: string | null; agent_id: string | null; created_at?: string; updated_at?: string; } /** * A fact pending local push to the server. */ export interface LocalPendingFact { id: string; content_fp: string | undefined; plaintext: string; } /** * Result of sync. */ export interface SyncResult { facts: SyncedFact[]; latestSequence: number; hasMore: boolean; } /** * Result of local reconciliation. */ export interface ReconciliationResult { /** Local facts that match server (should be skipped) */ skip: LocalPendingFact[]; /** Local facts that are genuinely new (should be pushed) */ push: LocalPendingFact[]; } /** * Config for the sync client. */ export interface SyncClientConfig { serverUrl: string; /** Optional: inject a fetch implementation for testing */ fetchImpl?: typeof fetch; } /** * Tracks the sync watermark for an agent. */ export declare class SyncState { lastSequence: number; lastSyncAt: Date | null; constructor(lastSequence?: number); update(latestSequence: number): void; toJSON(): string; static fromJSON(json: string): SyncState; } /** * HTTP client for the /sync endpoint. */ export declare class SyncClient { private serverUrl; private fetchImpl; constructor(config: SyncClientConfig); /** * Fetch one page of facts since the given sequence. */ syncSince(sinceSequence: number, authKey: string, limit?: number): Promise; /** * Fetch ALL facts since the given sequence, auto-paginating. */ syncAllSince(sinceSequence: number, authKey: string, limit?: number): Promise; } /** * Reconcile local pending facts against server state. * * For each local fact: * - If content_fp matches a server fact -> skip (already stored) * - Otherwise -> push (genuinely new) * * @param serverFacts - Facts from the /sync response * @param localFacts - Local pending facts to reconcile * @returns Which local facts to skip and which to push */ export declare function reconcileLocalFacts(serverFacts: SyncedFact[], localFacts: LocalPendingFact[]): ReconciliationResult; //# sourceMappingURL=sync.d.ts.map