@indigoai-us/hq-cloud 6.18.72 → 6.18.73-alpha.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.
- package/dist/bin/sync-runner-watch-loop.d.ts.map +1 -1
- package/dist/bin/sync-runner-watch-loop.js +1 -81
- package/dist/bin/sync-runner-watch-loop.js.map +1 -1
- package/dist/bin/sync-runner.d.ts +0 -21
- package/dist/bin/sync-runner.d.ts.map +1 -1
- package/dist/bin/sync-runner.js +1 -58
- package/dist/bin/sync-runner.js.map +1 -1
- package/dist/cli/rescue-core.d.ts +0 -12
- package/dist/cli/rescue-core.d.ts.map +1 -1
- package/dist/cli/rescue-core.js +0 -54
- package/dist/cli/rescue-core.js.map +1 -1
- package/dist/cli/share.d.ts.map +1 -1
- package/dist/cli/share.js +29 -164
- package/dist/cli/share.js.map +1 -1
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +0 -68
- package/dist/cli/sync.js.map +1 -1
- package/dist/cloud-placeholder.d.ts +48 -0
- package/dist/cloud-placeholder.d.ts.map +1 -1
- package/dist/cloud-placeholder.js +299 -9
- package/dist/cloud-placeholder.js.map +1 -1
- package/dist/ignore.d.ts +0 -14
- package/dist/ignore.d.ts.map +1 -1
- package/dist/ignore.js +2 -99
- package/dist/ignore.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/sync/state-store.d.ts +1 -29
- package/dist/sync/state-store.d.ts.map +1 -1
- package/dist/sync/state-store.js +4 -87
- package/dist/sync/state-store.js.map +1 -1
- package/dist/watcher.d.ts +17 -0
- package/dist/watcher.d.ts.map +1 -1
- package/dist/watcher.js +81 -6
- package/dist/watcher.js.map +1 -1
- package/package.json +1 -1
- package/dist/bin/sync-pass-request.d.ts +0 -81
- package/dist/bin/sync-pass-request.d.ts.map +0 -1
- package/dist/bin/sync-pass-request.js +0 -269
- package/dist/bin/sync-pass-request.js.map +0 -1
- package/dist/lib/append-only-merge.d.ts +0 -21
- package/dist/lib/append-only-merge.d.ts.map +0 -1
- package/dist/lib/append-only-merge.js +0 -107
- package/dist/lib/append-only-merge.js.map +0 -1
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
export type PassRequestSource = "desktop" | "cli";
|
|
2
|
-
export interface SyncPassRequest {
|
|
3
|
-
version: 1;
|
|
4
|
-
company: string | null;
|
|
5
|
-
requestedAt: string;
|
|
6
|
-
source: PassRequestSource;
|
|
7
|
-
}
|
|
8
|
-
export type PassRequestDisposition = "accepted" | "coalesced";
|
|
9
|
-
export type PassRequestEvent = {
|
|
10
|
-
type: "capabilities";
|
|
11
|
-
passRequests: 1;
|
|
12
|
-
} | {
|
|
13
|
-
type: "pass-request";
|
|
14
|
-
company: string | null;
|
|
15
|
-
source: PassRequestSource;
|
|
16
|
-
status: "accepted" | "coalesced" | "rejected";
|
|
17
|
-
reason?: string;
|
|
18
|
-
} | {
|
|
19
|
-
type: "error";
|
|
20
|
-
path: "(pass-request)";
|
|
21
|
-
message: string;
|
|
22
|
-
diagnostic: true;
|
|
23
|
-
};
|
|
24
|
-
/** Build a one-shot selection without changing any shared run options. */
|
|
25
|
-
export declare function buildPassRequestArgv(passArgv: readonly string[], company: string | null): string[];
|
|
26
|
-
/**
|
|
27
|
-
* Pass-level admission state. A scoped request remains distinct while a full
|
|
28
|
-
* pass is already running, so the runner can hand off at its next completed
|
|
29
|
-
* company leg. A queued full pass covers every queued scoped pass instead.
|
|
30
|
-
*/
|
|
31
|
-
export declare class PassRequestQueue {
|
|
32
|
-
private readonly scoped;
|
|
33
|
-
private full;
|
|
34
|
-
private fullPassRunning;
|
|
35
|
-
enqueue(request: SyncPassRequest): PassRequestDisposition;
|
|
36
|
-
/** Internal roster-refresh request; it deliberately has no file event. */
|
|
37
|
-
enqueueMembership(company: string): PassRequestDisposition;
|
|
38
|
-
takeNext(): SyncPassRequest | undefined;
|
|
39
|
-
/** Used at a durable full-fanout boundary, where only scopes may overtake. */
|
|
40
|
-
takeNextScoped(): SyncPassRequest | undefined;
|
|
41
|
-
/** A full request waits for the current full fanout to settle. */
|
|
42
|
-
takeFull(): SyncPassRequest | undefined;
|
|
43
|
-
/** A full fanout covers any scopes that were waiting before it was admitted. */
|
|
44
|
-
absorbScopedByFullPass(): void;
|
|
45
|
-
markFullPassStarted(): void;
|
|
46
|
-
markFullPassFinished(): void;
|
|
47
|
-
get hasQueued(): boolean;
|
|
48
|
-
get isFullPassRunning(): boolean;
|
|
49
|
-
}
|
|
50
|
-
/** Tracks roster snapshots without introducing a second membership poller. */
|
|
51
|
-
export declare class MembershipPassRequestTracker {
|
|
52
|
-
private readonly queue;
|
|
53
|
-
private previous;
|
|
54
|
-
constructor(queue: PassRequestQueue);
|
|
55
|
-
/** Queue newly active memberships after the initial full-pass baseline. */
|
|
56
|
-
observe(companyUids: readonly string[]): boolean;
|
|
57
|
-
}
|
|
58
|
-
export declare class SyncPassRequestDirectory {
|
|
59
|
-
private readonly options;
|
|
60
|
-
private watcher;
|
|
61
|
-
private poller;
|
|
62
|
-
private draining;
|
|
63
|
-
private disposed;
|
|
64
|
-
constructor(options: {
|
|
65
|
-
directory: string;
|
|
66
|
-
queue: PassRequestQueue;
|
|
67
|
-
emit: (event: PassRequestEvent) => void;
|
|
68
|
-
onWake: () => void;
|
|
69
|
-
});
|
|
70
|
-
static fromEnvironment(options: {
|
|
71
|
-
env?: NodeJS.ProcessEnv;
|
|
72
|
-
queue: PassRequestQueue;
|
|
73
|
-
emit: (event: PassRequestEvent) => void;
|
|
74
|
-
onWake: () => void;
|
|
75
|
-
}): SyncPassRequestDirectory | undefined;
|
|
76
|
-
start(): Promise<void>;
|
|
77
|
-
drain(): Promise<void>;
|
|
78
|
-
dispose(): void;
|
|
79
|
-
private drainOnce;
|
|
80
|
-
}
|
|
81
|
-
//# sourceMappingURL=sync-pass-request.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
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I,CAAC;IAS5B,OAAO,IAAI,IAAI;YAQD,SAAS;CAgExB"}
|
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
import * as fs from "node:fs";
|
|
2
|
-
import * as path from "node:path";
|
|
3
|
-
/** Build a one-shot selection without changing any shared run options. */
|
|
4
|
-
export function buildPassRequestArgv(passArgv, company) {
|
|
5
|
-
if (company === null)
|
|
6
|
-
return [...passArgv];
|
|
7
|
-
const scopedArgv = [];
|
|
8
|
-
for (let index = 0; index < passArgv.length; index++) {
|
|
9
|
-
const argument = passArgv[index];
|
|
10
|
-
if (argument === "--companies" || argument === "--personal")
|
|
11
|
-
continue;
|
|
12
|
-
if (argument === "--company") {
|
|
13
|
-
index += 1;
|
|
14
|
-
continue;
|
|
15
|
-
}
|
|
16
|
-
scopedArgv.push(argument);
|
|
17
|
-
}
|
|
18
|
-
return [...scopedArgv, "--company", company];
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Pass-level admission state. A scoped request remains distinct while a full
|
|
22
|
-
* pass is already running, so the runner can hand off at its next completed
|
|
23
|
-
* company leg. A queued full pass covers every queued scoped pass instead.
|
|
24
|
-
*/
|
|
25
|
-
export class PassRequestQueue {
|
|
26
|
-
scoped = new Map();
|
|
27
|
-
full;
|
|
28
|
-
fullPassRunning = false;
|
|
29
|
-
enqueue(request) {
|
|
30
|
-
if (request.company === null) {
|
|
31
|
-
if (this.full)
|
|
32
|
-
return "coalesced";
|
|
33
|
-
this.full = request;
|
|
34
|
-
this.scoped.clear();
|
|
35
|
-
return "accepted";
|
|
36
|
-
}
|
|
37
|
-
if (this.full || this.scoped.has(request.company))
|
|
38
|
-
return "coalesced";
|
|
39
|
-
this.scoped.set(request.company, request);
|
|
40
|
-
return "accepted";
|
|
41
|
-
}
|
|
42
|
-
/** Internal roster-refresh request; it deliberately has no file event. */
|
|
43
|
-
enqueueMembership(company) {
|
|
44
|
-
return this.enqueue({
|
|
45
|
-
version: 1,
|
|
46
|
-
company,
|
|
47
|
-
requestedAt: new Date().toISOString(),
|
|
48
|
-
source: "cli",
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
takeNext() {
|
|
52
|
-
return this.takeNextScoped() ?? this.takeFull();
|
|
53
|
-
}
|
|
54
|
-
/** Used at a durable full-fanout boundary, where only scopes may overtake. */
|
|
55
|
-
takeNextScoped() {
|
|
56
|
-
const scoped = this.scoped.entries().next();
|
|
57
|
-
if (scoped.done)
|
|
58
|
-
return undefined;
|
|
59
|
-
this.scoped.delete(scoped.value[0]);
|
|
60
|
-
return scoped.value[1];
|
|
61
|
-
}
|
|
62
|
-
/** A full request waits for the current full fanout to settle. */
|
|
63
|
-
takeFull() {
|
|
64
|
-
const full = this.full;
|
|
65
|
-
this.full = undefined;
|
|
66
|
-
return full;
|
|
67
|
-
}
|
|
68
|
-
/** A full fanout covers any scopes that were waiting before it was admitted. */
|
|
69
|
-
absorbScopedByFullPass() {
|
|
70
|
-
this.scoped.clear();
|
|
71
|
-
}
|
|
72
|
-
markFullPassStarted() {
|
|
73
|
-
this.fullPassRunning = true;
|
|
74
|
-
}
|
|
75
|
-
markFullPassFinished() {
|
|
76
|
-
this.fullPassRunning = false;
|
|
77
|
-
}
|
|
78
|
-
get hasQueued() {
|
|
79
|
-
return this.full !== undefined || this.scoped.size > 0;
|
|
80
|
-
}
|
|
81
|
-
get isFullPassRunning() {
|
|
82
|
-
return this.fullPassRunning;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
/** Tracks roster snapshots without introducing a second membership poller. */
|
|
86
|
-
export class MembershipPassRequestTracker {
|
|
87
|
-
queue;
|
|
88
|
-
previous;
|
|
89
|
-
constructor(queue) {
|
|
90
|
-
this.queue = queue;
|
|
91
|
-
}
|
|
92
|
-
/** Queue newly active memberships after the initial full-pass baseline. */
|
|
93
|
-
observe(companyUids) {
|
|
94
|
-
const current = new Set(companyUids);
|
|
95
|
-
let enqueued = false;
|
|
96
|
-
if (this.previous) {
|
|
97
|
-
for (const companyUid of current) {
|
|
98
|
-
if (this.previous.has(companyUid))
|
|
99
|
-
continue;
|
|
100
|
-
if (this.queue.enqueueMembership(companyUid) === "accepted")
|
|
101
|
-
enqueued = true;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
this.previous = current;
|
|
105
|
-
return enqueued;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
function fileRequest(value) {
|
|
109
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
110
|
-
return { reason: "malformed", company: null, source: "cli" };
|
|
111
|
-
}
|
|
112
|
-
const candidate = value;
|
|
113
|
-
const company = typeof candidate.company === "string" || candidate.company === null
|
|
114
|
-
? candidate.company
|
|
115
|
-
: null;
|
|
116
|
-
const source = candidate.source === "desktop" || candidate.source === "cli"
|
|
117
|
-
? candidate.source
|
|
118
|
-
: "cli";
|
|
119
|
-
if (candidate.version !== 1) {
|
|
120
|
-
return { reason: "unsupported-version", company, source };
|
|
121
|
-
}
|
|
122
|
-
if (typeof candidate.company !== "string" && candidate.company !== null) {
|
|
123
|
-
return { reason: "malformed", company, source };
|
|
124
|
-
}
|
|
125
|
-
if (typeof candidate.requestedAt !== "string" || Number.isNaN(Date.parse(candidate.requestedAt))) {
|
|
126
|
-
return { reason: "malformed", company, source };
|
|
127
|
-
}
|
|
128
|
-
if (candidate.source !== "desktop" && candidate.source !== "cli") {
|
|
129
|
-
return { reason: "malformed", company, source };
|
|
130
|
-
}
|
|
131
|
-
return {
|
|
132
|
-
version: 1,
|
|
133
|
-
company: candidate.company,
|
|
134
|
-
requestedAt: candidate.requestedAt,
|
|
135
|
-
source: candidate.source,
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
function isRequest(value) {
|
|
139
|
-
return "version" in value;
|
|
140
|
-
}
|
|
141
|
-
export class SyncPassRequestDirectory {
|
|
142
|
-
options;
|
|
143
|
-
watcher;
|
|
144
|
-
poller;
|
|
145
|
-
draining;
|
|
146
|
-
disposed = false;
|
|
147
|
-
constructor(options) {
|
|
148
|
-
this.options = options;
|
|
149
|
-
}
|
|
150
|
-
static fromEnvironment(options) {
|
|
151
|
-
const directory = options.env?.HQ_SYNC_PASS_REQUEST_DIR?.trim();
|
|
152
|
-
return directory
|
|
153
|
-
? new SyncPassRequestDirectory({ ...options, directory })
|
|
154
|
-
: undefined;
|
|
155
|
-
}
|
|
156
|
-
async start() {
|
|
157
|
-
await fs.promises.mkdir(this.options.directory, { recursive: true, mode: 0o700 });
|
|
158
|
-
this.options.emit({ type: "capabilities", passRequests: 1 });
|
|
159
|
-
await this.drain();
|
|
160
|
-
try {
|
|
161
|
-
this.watcher = fs.watch(this.options.directory, () => {
|
|
162
|
-
void this.drain();
|
|
163
|
-
});
|
|
164
|
-
this.watcher.on("error", (error) => {
|
|
165
|
-
this.options.emit({
|
|
166
|
-
type: "error",
|
|
167
|
-
path: "(pass-request)",
|
|
168
|
-
message: `pass request directory watch failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
169
|
-
diagnostic: true,
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
catch (error) {
|
|
174
|
-
this.options.emit({
|
|
175
|
-
type: "error",
|
|
176
|
-
path: "(pass-request)",
|
|
177
|
-
message: `pass request directory watch failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
178
|
-
diagnostic: true,
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
this.poller = setInterval(() => void this.drain(), 2_000);
|
|
182
|
-
this.poller.unref?.();
|
|
183
|
-
}
|
|
184
|
-
async drain() {
|
|
185
|
-
if (this.disposed)
|
|
186
|
-
return;
|
|
187
|
-
if (this.draining)
|
|
188
|
-
return this.draining;
|
|
189
|
-
this.draining = this.drainOnce().finally(() => {
|
|
190
|
-
this.draining = undefined;
|
|
191
|
-
});
|
|
192
|
-
return this.draining;
|
|
193
|
-
}
|
|
194
|
-
dispose() {
|
|
195
|
-
this.disposed = true;
|
|
196
|
-
this.watcher?.close();
|
|
197
|
-
if (this.poller)
|
|
198
|
-
clearInterval(this.poller);
|
|
199
|
-
this.watcher = undefined;
|
|
200
|
-
this.poller = undefined;
|
|
201
|
-
}
|
|
202
|
-
async drainOnce() {
|
|
203
|
-
let names;
|
|
204
|
-
try {
|
|
205
|
-
names = (await fs.promises.readdir(this.options.directory))
|
|
206
|
-
.filter((name) => name.endsWith(".json"))
|
|
207
|
-
.sort();
|
|
208
|
-
}
|
|
209
|
-
catch (error) {
|
|
210
|
-
this.options.emit({
|
|
211
|
-
type: "error",
|
|
212
|
-
path: "(pass-request)",
|
|
213
|
-
message: `pass request directory read failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
214
|
-
diagnostic: true,
|
|
215
|
-
});
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
for (const name of names) {
|
|
219
|
-
const file = path.join(this.options.directory, name);
|
|
220
|
-
let parsed;
|
|
221
|
-
try {
|
|
222
|
-
parsed = fileRequest(JSON.parse(await fs.promises.readFile(file, "utf8")));
|
|
223
|
-
}
|
|
224
|
-
catch {
|
|
225
|
-
parsed = { reason: "malformed", company: null, source: "cli" };
|
|
226
|
-
}
|
|
227
|
-
try {
|
|
228
|
-
await fs.promises.unlink(file);
|
|
229
|
-
}
|
|
230
|
-
catch (error) {
|
|
231
|
-
if (error.code === "ENOENT")
|
|
232
|
-
continue;
|
|
233
|
-
this.options.emit({
|
|
234
|
-
type: "error",
|
|
235
|
-
path: "(pass-request)",
|
|
236
|
-
message: `pass request file delete failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
237
|
-
diagnostic: true,
|
|
238
|
-
});
|
|
239
|
-
continue;
|
|
240
|
-
}
|
|
241
|
-
if (!isRequest(parsed)) {
|
|
242
|
-
this.options.emit({
|
|
243
|
-
type: "pass-request",
|
|
244
|
-
company: parsed.company,
|
|
245
|
-
source: parsed.source,
|
|
246
|
-
status: "rejected",
|
|
247
|
-
reason: parsed.reason,
|
|
248
|
-
});
|
|
249
|
-
this.options.emit({
|
|
250
|
-
type: "error",
|
|
251
|
-
path: "(pass-request)",
|
|
252
|
-
message: `pass request rejected: ${parsed.reason}`,
|
|
253
|
-
diagnostic: true,
|
|
254
|
-
});
|
|
255
|
-
continue;
|
|
256
|
-
}
|
|
257
|
-
const status = this.options.queue.enqueue(parsed);
|
|
258
|
-
this.options.emit({
|
|
259
|
-
type: "pass-request",
|
|
260
|
-
company: parsed.company,
|
|
261
|
-
source: parsed.source,
|
|
262
|
-
status,
|
|
263
|
-
});
|
|
264
|
-
if (status === "accepted")
|
|
265
|
-
this.options.onWake();
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
//# sourceMappingURL=sync-pass-request.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sync-pass-request.js","sourceRoot":"","sources":["../../src/bin/sync-pass-request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAwBlC,0EAA0E;AAC1E,MAAM,UAAU,oBAAoB,CAClC,QAA2B,EAC3B,OAAsB;IAEtB,IAAI,OAAO,KAAK,IAAI;QAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC;IAC3C,MAAM,UAAU,GAAa,EAAE,CAAC;IAChC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QACrD,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAE,CAAC;QAClC,IAAI,QAAQ,KAAK,aAAa,IAAI,QAAQ,KAAK,YAAY;YAAE,SAAS;QACtE,IAAI,QAAQ,KAAK,WAAW,EAAE,CAAC;YAC7B,KAAK,IAAI,CAAC,CAAC;YACX,SAAS;QACX,CAAC;QACD,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5B,CAAC;IACD,OAAO,CAAC,GAAG,UAAU,EAAE,WAAW,EAAE,OA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MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAClD,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;gBAChB,IAAI,EAAE,cAAc;gBACpB,OAAO,EAAE,MAAM,CAAC,OAAO;gBACvB,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,MAAM;aACP,CAAC,CAAC;YACH,IAAI,MAAM,KAAK,UAAU;gBAAE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QACnD,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/** True for a path whose body is append-only lines (`*.jsonl`, any depth). */
|
|
2
|
-
export declare function isAppendOnlyPath(relativePath: string): boolean;
|
|
3
|
-
/**
|
|
4
|
-
* Merge two append-only bodies: the local body, then the cloud lines it lacks.
|
|
5
|
-
* The result always begins with the local body's exact bytes. Returns the
|
|
6
|
-
* local body itself when the cloud has no line it lacks, the cloud body itself
|
|
7
|
-
* when the merge equals it, and null when either body is not UTF-8 text.
|
|
8
|
-
*/
|
|
9
|
-
export declare function mergeAppendOnly(localBody: Buffer, remoteBody: Buffer): Buffer | null;
|
|
10
|
-
/**
|
|
11
|
-
* Append the merge's new bytes to `file`, but only while the file still holds
|
|
12
|
-
* exactly `expected`, the body the merge read. The file is opened for append
|
|
13
|
-
* and never replaced, so a writer holding it open keeps writing to it.
|
|
14
|
-
*
|
|
15
|
-
* Returns "appended" when the file now ends with the merge (or already equals
|
|
16
|
-
* it), and "changed" when another writer changed the file after the merge read
|
|
17
|
-
* it; the next pass then merges again from the new body. Filesystem failures
|
|
18
|
-
* are thrown so the caller can report them.
|
|
19
|
-
*/
|
|
20
|
-
export declare function appendIfUnchanged(file: string, expected: Buffer, merged: Buffer): "appended" | "changed";
|
|
21
|
-
//# sourceMappingURL=append-only-merge.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"append-only-merge.d.ts","sourceRoot":"","sources":["../../src/lib/append-only-merge.ts"],"names":[],"mappings":"AAmBA,8EAA8E;AAC9E,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAG9D;AA+BD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CA0BpF;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS,CASxG"}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Line merge for append-only files.
|
|
3
|
-
*
|
|
4
|
-
* Several machines append to the same `.jsonl` files (the handoff index, event
|
|
5
|
-
* logs). When two of them append between syncs, both bodies changed since the
|
|
6
|
-
* journal and sync used to park one of them. Their lines can always be combined
|
|
7
|
-
* without loss, so a conflict on such a file is merged instead.
|
|
8
|
-
*
|
|
9
|
-
* The merge keeps the local body exactly as it is and adds the cloud lines it
|
|
10
|
-
* lacks after it, in cloud order. The local file is therefore only ever
|
|
11
|
-
* appended to, never replaced: a program that holds the file open for append
|
|
12
|
-
* keeps writing to the same file, and nothing it writes is lost.
|
|
13
|
-
*
|
|
14
|
-
* Machines converge through the push fence: a merged body holds every line of
|
|
15
|
-
* both sides, it is published under an If-Match on the cloud version it was
|
|
16
|
-
* merged against, and a machine with no new lines of its own simply pulls.
|
|
17
|
-
*/
|
|
18
|
-
import * as fs from "node:fs";
|
|
19
|
-
/** True for a path whose body is append-only lines (`*.jsonl`, any depth). */
|
|
20
|
-
export function isAppendOnlyPath(relativePath) {
|
|
21
|
-
const base = relativePath.split(/[\\/]/).pop() ?? "";
|
|
22
|
-
return base.length > ".jsonl".length && base.toLowerCase().endsWith(".jsonl");
|
|
23
|
-
}
|
|
24
|
-
function splitLines(body) {
|
|
25
|
-
const lines = [];
|
|
26
|
-
const pattern = /([^\r\n]*)(\r\n|\n|\r)?/g;
|
|
27
|
-
let match;
|
|
28
|
-
while ((match = pattern.exec(body)) !== null) {
|
|
29
|
-
if (match[0] === "")
|
|
30
|
-
break;
|
|
31
|
-
lines.push({ text: match[1], eol: match[2] ?? "" });
|
|
32
|
-
}
|
|
33
|
-
return lines;
|
|
34
|
-
}
|
|
35
|
-
function decodeText(body) {
|
|
36
|
-
if (body.includes(0))
|
|
37
|
-
return null;
|
|
38
|
-
try {
|
|
39
|
-
return new TextDecoder("utf-8", { fatal: true }).decode(body);
|
|
40
|
-
}
|
|
41
|
-
catch {
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
function defaultEol(lines) {
|
|
46
|
-
return lines.find((line) => line.eol !== "")?.eol ?? "\n";
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Merge two append-only bodies: the local body, then the cloud lines it lacks.
|
|
50
|
-
* The result always begins with the local body's exact bytes. Returns the
|
|
51
|
-
* local body itself when the cloud has no line it lacks, the cloud body itself
|
|
52
|
-
* when the merge equals it, and null when either body is not UTF-8 text.
|
|
53
|
-
*/
|
|
54
|
-
export function mergeAppendOnly(localBody, remoteBody) {
|
|
55
|
-
const localText = decodeText(localBody);
|
|
56
|
-
const remoteText = decodeText(remoteBody);
|
|
57
|
-
if (localText === null || remoteText === null)
|
|
58
|
-
return null;
|
|
59
|
-
const localLines = splitLines(localText);
|
|
60
|
-
const remoteLines = splitLines(remoteText);
|
|
61
|
-
const remaining = new Map();
|
|
62
|
-
for (const line of localLines)
|
|
63
|
-
remaining.set(line.text, (remaining.get(line.text) ?? 0) + 1);
|
|
64
|
-
const remoteOnly = [];
|
|
65
|
-
for (const line of remoteLines) {
|
|
66
|
-
const count = remaining.get(line.text) ?? 0;
|
|
67
|
-
if (count > 0)
|
|
68
|
-
remaining.set(line.text, count - 1);
|
|
69
|
-
else
|
|
70
|
-
remoteOnly.push(line);
|
|
71
|
-
}
|
|
72
|
-
if (remoteOnly.length === 0)
|
|
73
|
-
return localBody;
|
|
74
|
-
const localEol = defaultEol(localLines);
|
|
75
|
-
const remoteEol = defaultEol(remoteLines);
|
|
76
|
-
// Terminate an unterminated final local line, then add the cloud lines.
|
|
77
|
-
const lastLocal = localLines[localLines.length - 1];
|
|
78
|
-
let suffix = lastLocal && lastLocal.eol === "" ? localEol : "";
|
|
79
|
-
for (const line of remoteOnly)
|
|
80
|
-
suffix += line.text + (line.eol || remoteEol);
|
|
81
|
-
const merged = Buffer.concat([localBody, Buffer.from(suffix, "utf8")]);
|
|
82
|
-
return merged.equals(remoteBody) ? remoteBody : merged;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Append the merge's new bytes to `file`, but only while the file still holds
|
|
86
|
-
* exactly `expected`, the body the merge read. The file is opened for append
|
|
87
|
-
* and never replaced, so a writer holding it open keeps writing to it.
|
|
88
|
-
*
|
|
89
|
-
* Returns "appended" when the file now ends with the merge (or already equals
|
|
90
|
-
* it), and "changed" when another writer changed the file after the merge read
|
|
91
|
-
* it; the next pass then merges again from the new body. Filesystem failures
|
|
92
|
-
* are thrown so the caller can report them.
|
|
93
|
-
*/
|
|
94
|
-
export function appendIfUnchanged(file, expected, merged) {
|
|
95
|
-
if (merged.length < expected.length || !merged.subarray(0, expected.length).equals(expected)) {
|
|
96
|
-
throw new Error("append-only merge does not extend the local body");
|
|
97
|
-
}
|
|
98
|
-
if (!fs.lstatSync(file).isFile())
|
|
99
|
-
return "changed";
|
|
100
|
-
if (!fs.readFileSync(file).equals(expected))
|
|
101
|
-
return "changed";
|
|
102
|
-
if (merged.length === expected.length)
|
|
103
|
-
return "appended";
|
|
104
|
-
fs.appendFileSync(file, merged.subarray(expected.length));
|
|
105
|
-
return "appended";
|
|
106
|
-
}
|
|
107
|
-
//# sourceMappingURL=append-only-merge.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"append-only-merge.js","sourceRoot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