@rljson/fs-agent 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,385 +0,0 @@
1
- import { Conflict } from '@rljson/db';
2
- import { InsertHistoryRow } from '@rljson/rljson';
3
- import { FsTree } from './fs-scanner.js';
4
- /**
5
- * Nextcloud-style conflict resolution for forked FS-tree DAGs.
6
- *
7
- * When two peers edit a shared tree while one is offline, the InsertHistory
8
- * DAG forks into two tips (B and C, both descending from a common ancestor A).
9
- * `@rljson/db` fires a `dagBranch` conflict. This module resolves it on the
10
- * **client** by performing a deterministic three-way file-level merge and
11
- * writing a single **merge revision D** whose `InsertHistory.previous`
12
- * references *both* tips — collapsing the fork back to one tip.
13
- *
14
- * The pure functions (merge, naming, ancestor walk, winner selection) are
15
- * deterministic: every peer resolving the same fork produces the identical D,
16
- * so resolution converges instead of forking again.
17
- *
18
- * See `README.architecture.md`, "Conflicts".
19
- */
20
- /** relativePath → blobId. Directories are recorded as {@link DIR_MARKER}. */
21
- export type ContentMap = Map<string, string>;
22
- /** Sentinel blobId used for directory entries in a {@link ContentMap}. */
23
- export declare const DIR_MARKER = "<dir>";
24
- /**
25
- * Builds a {@link ContentMap} (relativePath → blobId) from an FsTree, ignoring
26
- * mtime so two trees with identical content compare equal regardless of when
27
- * they were written.
28
- * @param tree - The FsTree to flatten
29
- * @returns A map of relativePath → blobId (directories use {@link DIR_MARKER})
30
- */
31
- export declare function fsTreeToContentMap(tree: FsTree): ContentMap;
32
- /** A branch tip's identity, used for deterministic winner selection. */
33
- export interface BranchTip {
34
- /**
35
- * The EDIT CHAIN's `timeId` for this tip, when the chain has an entry for
36
- * it — `<millis>:<nanoid>`, minted by the authoring node and carried with
37
- * the row, so it is identical on every node.
38
- *
39
- * This is the primary ordering key, and it has to be, because the two that
40
- * used to be are not populated. Measured end to end on two nodes editing
41
- * one file: the conflict copy came out named
42
- *
43
- * shared (conflicted copy db.insertTrees 1970-01-01 000000).txt
44
- *
45
- * `db.insertTrees` is the DB's label for its own operation, not a client, and
46
- * the epoch is `clientTimestamp` never being set — `Db.insertTrees` accepts
47
- * neither, so no caller can supply them. With `timestamp` equal at 0 and
48
- * `clientId` equal for everybody, both top comparisons collapsed and the
49
- * winner fell through to *whichever content hash sorts higher*. Deterministic,
50
- * so the fleet converged; but unrelated to who edited last, which is what
51
- * `§11.1` says decides.
52
- *
53
- * The chain's stamp is what the agent already mints for exactly this kind of
54
- * question, so nothing new has to be transported. Absent only for a tip no
55
- * chain entry covers (a peer on an older build), which is why it is optional
56
- * and why the old keys stay below it as a fallback.
57
- */
58
- chainTimeId?: string;
59
- /** InsertHistory timeId of the tip (per-db; used only for local lookups). */
60
- timeId: string;
61
- /** Shared content ref of the tip — the cross-client deterministic tiebreak. */
62
- ref: string;
63
- /** Originating client id (InsertHistory `origin`). Empty string if unknown. */
64
- clientId: string;
65
- /** InsertHistory client timestamp (ms). 0 if unknown. */
66
- timestamp: number;
67
- }
68
- /**
69
- * Total, deterministic order over two tips. Returns a positive number when `a`
70
- * outranks `b`.
71
- *
72
- * The keys, in order:
73
- *
74
- * 1. the EDIT CHAIN's `timeId` — the newer edit outranks the older. See
75
- * {@link BranchTip.chainTimeId} for why this had to become the first key:
76
- * the two below it are not populated by `Db.insertTrees`, so without it
77
- * the decision fell through to a content hash comparison.
78
- * 2. greater InsertHistory `clientTimestamp`;
79
- * 3. greater `clientId`;
80
- * 4. greater **content ref**.
81
- *
82
- * The last tiebreak is the ref rather than the InsertHistory timeId because
83
- * timeIds are per-db — using one would make different peers pick different
84
- * winners and never converge. The ref is shared, so every peer agrees; and
85
- * that claim is only true now that mtime is out of the content identity, which
86
- * is what made two peers derive different refs for identical content.
87
- *
88
- * `compareTimeId` is a total order over `<millis>:<nanoid>` and is identical
89
- * on every node, so key 1 preserves the property the rest of this function
90
- * exists for. A tip with no chain entry compares as "not comparable" and falls
91
- * through, so a peer on an older build is ordered exactly as before.
92
- * @param a - First tip
93
- * @param b - Second tip
94
- * @returns Positive if `a` outranks `b`, negative if `b` outranks `a`, else 0
95
- */
96
- export declare function compareTips(a: BranchTip, b: BranchTip): number;
97
- /**
98
- * Picks the path-owning winner of a conflict. Per design decision §11.1 the
99
- * revision with the greater InsertHistory timestamp keeps the original path;
100
- * the loser's content is preserved under a renamed conflict copy.
101
- * @param a - First tip
102
- * @param b - Second tip
103
- * @returns The winning and losing tips
104
- */
105
- export declare function decideWinner(a: BranchTip, b: BranchTip): {
106
- winner: BranchTip;
107
- loser: BranchTip;
108
- };
109
- /**
110
- * Finds the nearest common ancestor timeId of two tips by walking the
111
- * InsertHistory `previous` chains. Returns null when the tips share no
112
- * ancestor (treat as an empty ancestor — everything is an add/add).
113
- * @param rows - All InsertHistory rows for the table
114
- * @param tipA - First tip timeId
115
- * @param tipB - Second tip timeId
116
- * @returns The nearest common ancestor timeId, or null if none
117
- */
118
- export declare function findCommonAncestor(rows: InsertHistoryRow<string>[], tipA: string, tipB: string): string | null;
119
- /**
120
- * What `Db.insertTrees` writes into an InsertHistory row's `origin`: the name
121
- * of its own operation, not an identity.
122
- *
123
- * `Db.insertTrees` accepts no `origin`, so every row this agent writes carries
124
- * this, on every node. It is the reason a conflict copy came out named
125
- * `shared (conflicted copy db.insertTrees 1970-01-01 000000).txt` — see
126
- * {@link BranchTip.chainTimeId}.
127
- */
128
- export declare const DB_OPERATION_ORIGIN = "db.insertTrees";
129
- /**
130
- * The wall-clock millisecond a tip was authored, as well as it can be known.
131
- *
132
- * The chain's `timeId` is `<millis>:<nanoid>` and its millisecond half is the
133
- * authoring node's clock at the moment of the edit — which is the only real
134
- * time available here, because `clientTimestamp` is never set (see
135
- * {@link BranchTip.chainTimeId}). Without this a conflict copy was dated
136
- * `1970-01-01 000000`.
137
- *
138
- * Used ONLY for the copy's human-readable name. Ordering uses
139
- * {@link compareTimeId} on the whole id, never this number, so two edits in
140
- * the same millisecond are still totally ordered.
141
- * @param tip - The tip to date.
142
- * @returns Milliseconds since the epoch, or `0` when nothing knows.
143
- */
144
- export declare function tipTimestamp(tip: BranchTip): number;
145
- /**
146
- * An `origin` only when it identifies a client, else the empty string.
147
- *
148
- * A name in a filename a user has to read must be true or absent. Printing the
149
- * DB's operation label as the machine that made the edit is worse than
150
- * printing nothing: it reads as information and is not.
151
- *
152
- * Carrying the real author needs `Db.insertTrees` to accept an origin, which
153
- * it does not — a follow-up outside this package. Until then the copy is named
154
- * by its time alone.
155
- * @param origin - The InsertHistory row's origin, if any.
156
- * @returns A usable client id, or `''`.
157
- */
158
- export declare function usableClientId(origin: string | undefined): string;
159
- /**
160
- * Formats a timestamp as a stable UTC `YYYY-MM-DD HHMMSS` string. UTC keeps the
161
- * conflict-copy name identical across peers in different timezones.
162
- * @param ms - Milliseconds since the epoch
163
- * @returns The formatted UTC timestamp
164
- */
165
- export declare function formatConflictTimestamp(ms: number): string;
166
- /**
167
- * Derives a Nextcloud-style conflict-copy path:
168
- * `document.txt` → `document (conflicted copy <clientId> <ts>).txt`.
169
- *
170
- * - The suffix is inserted before the final extension; dotfiles / extensionless
171
- * names get it appended.
172
- * - Identity + timestamp come from the *losing* revision, so every peer derives
173
- * the same name (determinism).
174
- * - If the candidate name is already taken, a numeric ` (n)` is appended; the
175
- * chosen name is added to `taken`.
176
- *
177
- * **The name has to distinguish distinct losing CONTENT, and without an
178
- * identity it did not.** `usableClientId` returns empty whenever the origin is
179
- * the DB's own label, which is the ordinary case, and the timestamp has
180
- * second granularity — so two nodes losing DIFFERENT content in the same
181
- * second derived the same copy name. The copies then conflicted with each
182
- * other, producing a copy of a copy:
183
- *
184
- * two (conflicted copy 2026-10-03 142610) (conflicted copy 2026-10-03 142611).txt
185
- *
186
- * Measured on the seeded fuzz run as up to 14 nested copies, and present
187
- * before this session's work as well (0–5 on the same four runs). The losing
188
- * revision's content ref is carried in only when there is no identity to use:
189
- * it is identical on every peer for the same losing revision and differs
190
- * whenever the content does, which is exactly the property that was missing.
191
- * A name that is already readable stays readable.
192
- * @param relativePath - The original conflicting path
193
- * @param clientId - The losing revision's client id
194
- * @param timestamp - The losing revision's InsertHistory timestamp (ms)
195
- * @param taken - Set of already-used paths; the chosen name is added to it
196
- * @param loserRef - The losing revision's content ref, used to tell two
197
- * same-second losers apart when neither has a usable identity.
198
- * @returns A unique conflict-copy path
199
- */
200
- export declare function conflictCopyName(relativePath: string, clientId: string, timestamp: number, taken: Set<string>, loserRef?: string): string;
201
- /**
202
- * Derives the name a file is set aside under when the history DELETED its path.
203
- *
204
- * `document.txt` → `document (recovered).txt`.
205
- *
206
- * **Not a conflict copy, and the difference is who is told.** A conflict copy
207
- * is live work on a live path and is announced, because the network needs it.
208
- * A recovered file is content the fleet deliberately removed — a folder
209
- * restored from last month's backup, or a client that was away while a
210
- * directory was deleted — and announcing it would push every one of those
211
- * deletions back to every node, under names nobody deleted. So it is kept
212
- * where its owner can see it and nothing is said about it.
213
- *
214
- * That is a deliberate, visible local divergence, chosen over the two
215
- * alternatives: resurrecting a deletion, or destroying a file somebody may
216
- * still want. No timestamp and no identity, because unlike a conflict there is
217
- * nothing to tell apart — the path is simply gone from the history, and one
218
- * name per path is what a user can act on.
219
- * @param relativePath - The path the history removed
220
- * @param taken - Paths already used; the chosen name is added to it
221
- * @returns A unique set-aside path
222
- */
223
- export declare function recoveredName(relativePath: string, taken: Set<string>): string;
224
- /**
225
- * One same-file conflict, in the terms a user needs to see it in.
226
- *
227
- * WHY THIS EXISTS. A fork on two DIFFERENT files is merged as a union and
228
- * nobody should be asked about it. A fork on the SAME file is a real conflict,
229
- * and until now resolving one produced a renamed file and silence: nothing was
230
- * lost, but the only evidence was a strange filename appearing in a folder,
231
- * with no statement of what happened, which version is live, or where the
232
- * other one went.
233
- *
234
- * Deliberately NOT an error. Two people editing one document at the same time
235
- * is ordinary, both versions are kept, and the folder converges. It is an event
236
- * to report, which is why it does not go through `_writeSyncError`.
237
- *
238
- * And deliberately not a question. The winner is already decided — it has to
239
- * be, or peers would not converge — so this says what was decided and leaves
240
- * reversing it to whoever looks: the losing content is on disk under
241
- * {@link copyPath}, so swapping the two files is all it takes.
242
- */
243
- export interface FsConflictReport {
244
- /** The path both sides edited. The winner's content is here. */
245
- path: string;
246
- /** Where the losing version was kept, intact. */
247
- copyPath: string;
248
- /** Content ref of the branch that keeps {@link path}. */
249
- winnerRef: string;
250
- /** Content ref of the branch whose version moved to {@link copyPath}. */
251
- loserRef: string;
252
- /**
253
- * When the losing edit was made, in epoch ms, or `0` when nothing knows —
254
- * see {@link tipTimestamp} for why that is not always answerable.
255
- */
256
- loserAt: number;
257
- /** When this node resolved the conflict, in epoch ms. */
258
- resolvedAt: number;
259
- }
260
- /** A conflict copy to materialise: the losing content under a renamed path. */
261
- export interface ConflictCopy {
262
- /** The renamed path the losing content is written to. */
263
- path: string;
264
- /** The losing blobId (content preserved, nothing lost). */
265
- blobId: string;
266
- /**
267
- * The path the two sides actually disagreed about.
268
- *
269
- * Recoverable from {@link path} only by un-parsing a filename, which is the
270
- * kind of thing that works until somebody's document is called
271
- * `report (conflicted copy ...).txt`.
272
- */
273
- originalPath: string;
274
- }
275
- /** The result of a three-way merge. */
276
- export interface MergePlan {
277
- /** Final tree content (winner-resolved): relativePath → blobId. */
278
- merged: ContentMap;
279
- /** Extra files to write beside the merged set (the renamed losers). */
280
- copies: ConflictCopy[];
281
- /** Original paths that genuinely conflicted (both sides changed differently). */
282
- conflictPaths: string[];
283
- }
284
- /**
285
- * Three-way file-level merge of ancestor `o`, branch `ours`, branch `theirs`.
286
- * `winnerSide` decides who keeps the path on a real conflict; the loser's
287
- * content is preserved under a {@link conflictCopyName}. Pure & deterministic.
288
- *
289
- * Per relative path (see design §4.4):
290
- * - both sides equal → keep it (covers unchanged + add-same + delete-both)
291
- * - only theirs changed (`ours === o`) → take theirs
292
- * - only ours changed (`theirs === o`) → take ours
293
- * - both changed differently → CONFLICT: winner keeps path, loser renamed
294
- * @param o - Ancestor content map
295
- * @param ours - Our branch content map
296
- * @param theirs - Their branch content map
297
- * @param winnerSide - Which side keeps the path on a real conflict, when
298
- * nothing more specific is known. The BRANCH-level answer, and a fallback:
299
- * see `winnerFor`.
300
- * @param loserClientId - The losing revision's client id (for copy names)
301
- * @param loserTimestamp - The losing revision's timestamp (for copy names)
302
- * @param winnerFor - Per-path verdict, asked of the edit chain: *who last
303
- * changed THIS path?* `undefined` for a path means the chain could not say
304
- * and `winnerSide` decides it.
305
- *
306
- * **This is the difference between ordering a branch and ordering a file.**
307
- * Without it one verdict covers every path the two branches disagree about,
308
- * so a tip wins paths it never touched — measured as a node that came back
309
- * from being offline, wrote one unrelated file, and took `doc.txt` with it,
310
- * rolling the writer's own folder from v8 back to v5.
311
- * @returns The merge plan (merged set, conflict copies, conflicting paths)
312
- */
313
- export declare function threeWayMerge(o: ContentMap, ours: ContentMap, theirs: ContentMap, winnerSide: 'ours' | 'theirs', loserClientId: string, loserTimestamp: number, winnerFor?: (path: string) => 'ours' | 'theirs' | undefined): MergePlan;
314
- /**
315
- * The capabilities the resolver needs from its host FsAgent + Db. Injected so
316
- * the orchestration is unit-testable with in-memory fakes (no real db/fs).
317
- */
318
- export interface ConflictResolverDeps {
319
- /** The tree table key (route is `/${treeKey}`). */
320
- treeKey: string;
321
- /** All InsertHistory rows for `treeKey`. */
322
- getInsertHistory: (table: string) => Promise<InsertHistoryRow<string>[]>;
323
- /** Resolve a tip timeId to its tree root ref. */
324
- getRefOfTimeId: (table: string, timeId: string) => Promise<string | null>;
325
- /**
326
- * The edit chain's `timeId` for a tree ref, if the chain covers it.
327
- *
328
- * Optional: a host without a chain, or a tip authored by a peer on an older
329
- * build, simply has no answer — and {@link compareTips} falls back to the
330
- * keys it used before. See {@link BranchTip.chainTimeId}.
331
- */
332
- chainTimeIdOfRef?: (treeRef: string) => Promise<string | undefined>;
333
- /**
334
- * The `timeId` of the newest edit on `treeRef`'s lineage that touched `path`.
335
- *
336
- * Who last changed THIS file? — the question that decides a conflict per
337
- * path instead of per branch. `undefined` means the chain cannot say: the
338
- * lineage never named the path, or the walk could not be read to the end.
339
- * Absent entirely means an older peer, and the branch order decides
340
- * everything as before.
341
- */
342
- lastEditOfPath?: (treeRef: string, path: string) => Promise<string | undefined>;
343
- /** Fetch a full FsTree by its root ref. */
344
- fetchTree: (rootRef: string) => Promise<FsTree>;
345
- /** Read a blob's bytes by blobId. */
346
- getBlobContent: (blobId: string) => Promise<Buffer>;
347
- /** Restore an FsTree onto the working dir, pruning extraneous entries. */
348
- restoreTree: (tree: FsTree) => Promise<void>;
349
- /** Write bytes to a relative path under the working dir (mkdir -p). */
350
- writeFileAt: (relativePath: string, content: Buffer) => Promise<void>;
351
- /** Remove a relative path under the working dir (best effort). */
352
- deleteFileAt: (relativePath: string) => Promise<void>;
353
- /** Re-scan the working dir into a fresh, hashed FsTree. */
354
- scan: () => Promise<FsTree>;
355
- /** Store the merge revision with explicit predecessors; returns its root ref. */
356
- storeMerge: (tree: FsTree, previous: string[]) => Promise<string>;
357
- /** Notified with the stored merge ref so the host can suppress the echo. */
358
- onMergeStored?: (ref: string) => void;
359
- /**
360
- * Notified once per merge with every same-file conflict it resolved.
361
- *
362
- * Never called with an empty list, so a host can treat any call as "there is
363
- * something to tell the user about".
364
- */
365
- onConflicts?: (reports: FsConflictReport[]) => void;
366
- /** Optional structured logger. */
367
- log?: (level: 'info' | 'warn' | 'error', msg: string) => void;
368
- }
369
- /**
370
- * Resolves a single `dagBranch` conflict into a merge revision. For more than
371
- * two tips it merges the two lowest-identity tips per call; the resulting
372
- * smaller fork re-fires the observer and converges in further rounds.
373
- */
374
- export declare class FsConflictResolver {
375
- private readonly deps;
376
- constructor(deps: ConflictResolverDeps);
377
- private _log;
378
- /**
379
- * Resolves the conflict, returning the stored merge ref, or null when the
380
- * conflict is not ours / not actionable.
381
- * @param conflict - The detected DAG-branch conflict
382
- * @returns The stored merge revision's root ref, or null
383
- */
384
- resolve(conflict: Conflict): Promise<string | null>;
385
- }
@@ -1,159 +0,0 @@
1
- /**
2
- * How many buckets a manifest is divided into.
3
- *
4
- * **Must be identical on every node**, so it is a constant and never scaled to
5
- * folder size: two nodes that bucketed differently cannot compare anything.
6
- */
7
- export declare const BUCKET_COUNT = 4096;
8
- /** The blob id a TOMBSTONED path is advertised with. */
9
- export declare const TOMBSTONE_BLOB = "";
10
- /**
11
- * One manifest entry: a path, the blob holding its content, and whether the
12
- * sender's own HISTORY says it edited that path.
13
- *
14
- * **The claim is the whole point of the third element.** Without it a same-path
15
- * conflict is settled by comparing content hashes (see `reconcile`), which
16
- * converges on the greater hash and has nothing to do with who edited last —
17
- * measured as a writer at version 8 and a peer still holding version 5 ending
18
- * up on version 5, about half the time, the writer's own folder included.
19
- *
20
- * **It is deliberately NOT part of {@link digestOf}.** The bucket roots must
21
- * depend on content alone: two nodes holding identical bytes have to agree
22
- * their buckets match, whatever either of them claims about who wrote them.
23
- * Folding the claim in would make a node see differences that are not there,
24
- * which is the one failure the roots exist to avoid.
25
- *
26
- * Absent means "the sender did not say", which is how an older peer's two-element
27
- * entry arrives — and then the hash rule decides, exactly as before.
28
- */
29
- export type ManifestEntry = readonly [
30
- path: string,
31
- blobId: string,
32
- claimed?: 0 | 1,
33
- /**
34
- * `timeId` of the newest edit the sender knows of for this path — the write
35
- * that produced the blob, or the removal that produced the tombstone.
36
- *
37
- * WHAT A MANIFEST COULD NOT SAY BEFORE. A manifest states what a node
38
- * HOLDS; it never stated when the node decided. So a tombstone was authority
39
- * on its own, and a deletion made before a re-creation still won. Measured
40
- * by `I7b: a delivered deletion does not beat a later re-creation`.
41
- *
42
- * It is not the claim: a claim says WHO, and two nodes that both claim a
43
- * path still need to know which claim is later. It is also not a wall-clock
44
- * reading taken here — it is the identity of an edit in the chain, minted
45
- * once by whoever made it, so both sides of a round order it identically.
46
- *
47
- * Absent means "the sender did not say", exactly as for {@link claimed}: an
48
- * older peer sends two or three elements and the rules that shipped before
49
- * decide, unchanged. **Deliberately not part of {@link digestOf}**, for the
50
- * same reason the claim is not — bucket roots must depend on content alone.
51
- */
52
- editedAt?: string
53
- ];
54
- /** `bucketIndex → root`, non-empty buckets only. */
55
- export type BucketRoots = Readonly<Record<number, string>>;
56
- /**
57
- * Which bucket a path belongs to.
58
- *
59
- * On the PATH alone, never on the content: a file whose content changes must
60
- * stay in the same bucket, or a modification would look like a delete in one
61
- * bucket and an add in another — two differences where there is one.
62
- * @param path - The relative path, `/`-separated.
63
- * @returns A bucket index in `[0, BUCKET_COUNT)`.
64
- */
65
- export declare const bucketOf: (path: string) => number;
66
- /**
67
- * The per-bucket roots of a manifest.
68
- *
69
- * XOR, so a root does not depend on the order its entries were visited in —
70
- * two nodes that walked their folders differently must still agree.
71
- *
72
- * Sparse: a bucket with no entries is ABSENT rather than zero. An empty bucket
73
- * and a bucket whose digests happen to cancel are not the same thing, and only
74
- * one of them is worth a slot on the wire.
75
- * @param manifest - `path → blobId`, tombstones included with
76
- * {@link TOMBSTONE_BLOB}.
77
- * @returns `bucketIndex → root`, non-empty buckets only.
78
- */
79
- export declare const bucketRoots: (manifest: ReadonlyMap<string, string>) => BucketRoots;
80
- /**
81
- * The buckets two sides disagree about.
82
- *
83
- * A bucket present on one side and absent on the other differs: absent means
84
- * empty, and empty is not equal to anything with content in it.
85
- * @param ours - Our roots.
86
- * @param theirs - The peer's roots.
87
- * @returns Bucket indices to exchange entries for, ascending.
88
- */
89
- export declare const differingBuckets: (ours: BucketRoots, theirs: BucketRoots) => number[];
90
- /**
91
- * The entries of a manifest that fall in the given buckets.
92
- * @param manifest - `path → blobId`.
93
- * @param buckets - Bucket indices wanted.
94
- * @param claimed - Paths this node's history says it EDITED. Marked on the
95
- * entry so a peer can settle a same-path conflict by who wrote the file
96
- * rather than by which content hash sorts higher. Never folded into the
97
- * bucket digest — see {@link ManifestEntry}.
98
- * @returns The entries, sorted by path so two nodes serialise them alike.
99
- * @param editTimes - `path → timeId` of the newest edit known for each path,
100
- * which fills `ManifestEntry.editedAt`. Empty means the sender cannot date
101
- * its edits, and the entries then carry no time.
102
- */
103
- export declare const entriesInBuckets: (manifest: ReadonlyMap<string, string>, buckets: readonly number[], claimed?: ReadonlySet<string>, editTimes?: ReadonlyMap<string, string>) => ManifestEntry[];
104
- /** What one side should do about a peer's entries. */
105
- export interface ReconcilePlan {
106
- /**
107
- * Paths to fetch from the peer, with the blob to fetch.
108
- *
109
- * Additive, always: the peer has content we lack. Nothing here overwrites
110
- * anything — a path we hold with DIFFERENT content is a conflict, not a
111
- * fetch, and it is reported separately.
112
- */
113
- fetch: ManifestEntry[];
114
- /**
115
- * Paths the peer has TOMBSTONED that we still hold live.
116
- *
117
- * The delete-wins direction. Applying them is destructive and therefore
118
- * bounded elsewhere; this function only says which they are.
119
- */
120
- drop: string[];
121
- /**
122
- * Paths WE have tombstoned that the peer still holds live.
123
- *
124
- * The other delete-wins direction. Our tombstone has to be re-advertised, or
125
- * the two sides sit at different manifests for ever whenever a delete is
126
- * missed — mongo's `redelete`, and the exact failure its demo hit.
127
- */
128
- redelete: string[];
129
- /**
130
- * Paths both sides hold with DIFFERENT content.
131
- *
132
- * Reported for every conflict, whether or not this side adopts the peer's
133
- * version, so a caller can preserve the losing content as a conflict copy
134
- * and so the event is visible rather than silent.
135
- *
136
- * It is also RESOLVED, deterministically — see {@link reconcile}. Naming it
137
- * and doing nothing was tried: three clients editing one file then never
138
- * converge, because nothing decides and an additive step cannot. A sync
139
- * engine that leaves three versions in place has not reconciled anything.
140
- */
141
- conflict: string[];
142
- }
143
- /**
144
- * What to do about a peer's entries for the buckets we disagreed about.
145
- *
146
- * **Additive by construction.** The only outcomes it can produce are "fetch
147
- * something we lack", "adopt the peer's side of a conflict", "drop something
148
- * the peer proved it deleted" and "re-assert a deletion of our own". There is
149
- * no outcome in which one side's FOLDER replaces the other's, which is the
150
- * property that makes the two measured failures impossible instead of merely
151
- * rarer — a conflict is resolved one path at a time, never by wholesale.
152
- * @param ours - Our entries for those buckets, tombstones included.
153
- * @param theirs - The peer's entries for those buckets.
154
- * @param claimed - Paths THIS node's history says it edited. The peer's own
155
- * claims ride in its entries, so both sides are known here and the rule is
156
- * symmetric — see the conflict branch.
157
- * @returns The plan. Every list is sorted, so two nodes agree on its contents.
158
- */
159
- export declare const reconcile: (ours: readonly ManifestEntry[], theirs: readonly ManifestEntry[], claimed?: ReadonlySet<string>) => ReconcilePlan;