trellis
Version:
Agentic State Engine — event-sourced causal graph with branching, decision traces, and realtime sync for AI-native applications
48 lines • 1.74 kB
TypeScript
/**
* CRDT Reconciler
*
* DESIGN.md §10.5 — Merges divergent op streams using causal ordering.
* Each device maintains its own causal chain. The reconciler merges
* divergent chains by:
* 1. Finding the common ancestor (fork point)
* 2. Collecting ops unique to each side
* 3. Topologically sorting the combined set by causal dependencies
* 4. Detecting conflicts using patch commutativity (§4.4)
*/
import type { VcsOp } from '../vcs/types.js';
export interface ReconcileResult {
/** The merged op stream in causal order. */
merged: VcsOp[];
/** Ops that were only on side A. */
uniqueToA: VcsOp[];
/** Ops that were only on side B. */
uniqueToB: VcsOp[];
/** Common ancestor op hash (fork point). */
forkPoint: string | null;
/** Whether the merge was clean (no causal conflicts). */
clean: boolean;
/** Conflicting op pairs (both modify same file without commutativity). */
conflicts: ReconcileConflict[];
}
export interface ReconcileConflict {
opA: VcsOp;
opB: VcsOp;
filePath: string;
reason: string;
}
/**
* Find the common ancestor (fork point) of two op streams.
* Returns the hash of the last op that appears in both streams.
*/
export declare function findForkPoint(opsA: VcsOp[], opsB: VcsOp[]): string | null;
/**
* Reconcile two divergent op streams into a single merged stream.
*
* Algorithm:
* 1. Find the fork point (last common op)
* 2. Split each stream into shared prefix + unique suffix
* 3. Check for conflicts in the unique portions
* 4. Interleave unique ops in causal (timestamp) order
*/
export declare function reconcile(opsA: VcsOp[], opsB: VcsOp[]): ReconcileResult;
//# sourceMappingURL=reconciler.d.ts.map