@codemem/core 0.22.3 → 0.22.4
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/index.d.ts +1 -1
- package/dist/index.js +115 -80
- package/dist/index.js.map +1 -1
- package/dist/sync-pass.d.ts.map +1 -1
- package/dist/sync-replication.d.ts.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This package owns the SQLite store, embedding worker interface,
|
|
5
5
|
* and type definitions shared across the codemem TS backend.
|
|
6
6
|
*/
|
|
7
|
-
export declare const VERSION = "0.22.
|
|
7
|
+
export declare const VERSION = "0.22.4";
|
|
8
8
|
export * as Api from "./api-types.js";
|
|
9
9
|
export type { CreateBetterSqliteCoordinatorAppOptions } from "./better-sqlite-coordinator-runtime.js";
|
|
10
10
|
export { createBetterSqliteCoordinatorApp } from "./better-sqlite-coordinator-runtime.js";
|
package/dist/index.js
CHANGED
|
@@ -6538,7 +6538,7 @@ function vl(e, t) {
|
|
|
6538
6538
|
let n = tl(e);
|
|
6539
6539
|
if (t.generation !== n.generation) throw Error("generation_mismatch");
|
|
6540
6540
|
if (Zc(t.snapshotId) !== n.snapshot_id || Zc(t.baselineCursor) !== n.baseline_cursor) throw Error("boundary_mismatch");
|
|
6541
|
-
let r = Math.max(1, Math.min(t.limit ?? 200,
|
|
6541
|
+
let r = Math.max(1, Math.min(t.limit ?? 200, 5e3)), i = Qc(t.pageToken), a = j(e, { schema: R }), o = Math.max(r, Math.min(r * 3, 1e4)), s = (e, t) => a.select({
|
|
6542
6542
|
memory: B,
|
|
6543
6543
|
sessionProject: z.project
|
|
6544
6544
|
}).from(B).innerJoin(z, D(z.id, B.session_id)).where(E(de(B.import_key), e ? _e(O(B.import_key, e.importKey), E(D(B.import_key, e.importKey), O(B.id, e.id))) : void 0)).orderBy(B.import_key, B.id).limit(t).all(), c = [], l = i, u = null, d = !1;
|
|
@@ -6579,15 +6579,10 @@ function vl(e, t) {
|
|
|
6579
6579
|
};
|
|
6580
6580
|
}
|
|
6581
6581
|
function yl(e, t = 25) {
|
|
6582
|
-
let n =
|
|
6583
|
-
for (let e of r) {
|
|
6584
|
-
if (!e.import_key || !jl(Bl(e))) continue;
|
|
6585
|
-
let r = e.deleted_at || e.active === 0 ? "delete" : "upsert";
|
|
6586
|
-
if (!n.select({ one: A`1` }).from(W).where(E(D(W.entity_type, "memory_item"), D(W.entity_id, e.import_key), D(W.op_type, r), D(W.clock_rev, Number(e.rev ?? 0)))).limit(1).get() && (i += 1, i >= t)) break;
|
|
6587
|
-
}
|
|
6582
|
+
let n = e.prepare("\n SELECT count(*) as n FROM (\n SELECT 1 FROM memory_items m\n WHERE m.import_key IS NOT NULL\n AND COALESCE(m.visibility, '') NOT LIKE 'private%'\n AND COALESCE(m.visibility, '') NOT LIKE 'personal%'\n AND NOT EXISTS (\n SELECT 1 FROM replication_ops r\n WHERE r.entity_type = 'memory_item'\n AND r.entity_id = m.import_key\n AND r.op_type = CASE WHEN m.deleted_at IS NOT NULL OR m.active = 0 THEN 'delete' ELSE 'upsert' END\n AND r.clock_rev = COALESCE(m.rev, 0)\n )\n LIMIT ?\n )\n ").get(t), r = Number(n?.n ?? 0);
|
|
6588
6583
|
return {
|
|
6589
|
-
dirty:
|
|
6590
|
-
count:
|
|
6584
|
+
dirty: r > 0,
|
|
6585
|
+
count: r
|
|
6591
6586
|
};
|
|
6592
6587
|
}
|
|
6593
6588
|
function bl(e, t) {
|
|
@@ -8256,40 +8251,40 @@ function xu(e, t) {
|
|
|
8256
8251
|
}
|
|
8257
8252
|
//#endregion
|
|
8258
8253
|
//#region src/sync-pass.ts
|
|
8259
|
-
var Su = 1048576, Cu = 200, wu = "2";
|
|
8260
|
-
function
|
|
8254
|
+
var Su = 1048576, Cu = 200, wu = 2e3, Tu = "2";
|
|
8255
|
+
function Eu(e, t) {
|
|
8261
8256
|
return !t || !t.includes("|") ? !1 : e ? t > e : !0;
|
|
8262
8257
|
}
|
|
8263
|
-
function
|
|
8258
|
+
function Du(e) {
|
|
8264
8259
|
if (!e) return null;
|
|
8265
8260
|
let t = e.error, n = e.reason;
|
|
8266
8261
|
return typeof t == "string" && typeof n == "string" ? `${t}:${n}` : typeof t == "string" ? t : null;
|
|
8267
8262
|
}
|
|
8268
|
-
function
|
|
8263
|
+
function Ou(e) {
|
|
8269
8264
|
return e.length === 0 ? null : `all addresses failed | ${e.map((e) => `${e.address}: ${e.error}`).join(" || ")}`;
|
|
8270
8265
|
}
|
|
8271
|
-
function
|
|
8266
|
+
function ku(e) {
|
|
8272
8267
|
if (typeof e != "string") return null;
|
|
8273
8268
|
let t = e.trim();
|
|
8274
8269
|
return t.length > 0 ? t : null;
|
|
8275
8270
|
}
|
|
8276
|
-
function
|
|
8271
|
+
function Au(e) {
|
|
8277
8272
|
let t = e?.sync_reset;
|
|
8278
8273
|
if (!t || typeof t != "object" || Array.isArray(t)) return null;
|
|
8279
8274
|
let n = t;
|
|
8280
8275
|
if (!Number.isFinite(n.generation) || typeof n.snapshot_id != "string" || n.snapshot_id.trim().length === 0) return null;
|
|
8281
|
-
let r =
|
|
8276
|
+
let r = ku(n.baseline_cursor);
|
|
8282
8277
|
return {
|
|
8283
8278
|
generation: Number(n.generation),
|
|
8284
8279
|
snapshot_id: n.snapshot_id.trim(),
|
|
8285
8280
|
baseline_cursor: r,
|
|
8286
|
-
retained_floor_cursor:
|
|
8281
|
+
retained_floor_cursor: ku(n.retained_floor_cursor)
|
|
8287
8282
|
};
|
|
8288
8283
|
}
|
|
8289
|
-
function
|
|
8284
|
+
function ju(e) {
|
|
8290
8285
|
return !(!e || e.reset_required !== !1 || !Number.isFinite(e.generation) || typeof e.snapshot_id != "string" || e.snapshot_id.trim().length === 0 || !(e.baseline_cursor == null || typeof e.baseline_cursor == "string") || !(e.retained_floor_cursor == null || typeof e.retained_floor_cursor == "string") || !Array.isArray(e.ops) || !(e.next_cursor == null || typeof e.next_cursor == "string") || !Number.isFinite(e.skipped));
|
|
8291
8286
|
}
|
|
8292
|
-
function
|
|
8287
|
+
function Mu(e, t, n) {
|
|
8293
8288
|
let r = j(e, { schema: R }), i = (/* @__PURE__ */ new Date()).toISOString();
|
|
8294
8289
|
r.insert(He).values({
|
|
8295
8290
|
peer_device_id: t,
|
|
@@ -8301,7 +8296,7 @@ function ju(e, t, n) {
|
|
|
8301
8296
|
error: n.error ?? null
|
|
8302
8297
|
}).run();
|
|
8303
8298
|
}
|
|
8304
|
-
function
|
|
8299
|
+
function Nu(e, t) {
|
|
8305
8300
|
let n = j(e, { schema: R }), r = (/* @__PURE__ */ new Date()).toISOString();
|
|
8306
8301
|
n.update(G).set({
|
|
8307
8302
|
last_sync_at: r,
|
|
@@ -8309,7 +8304,7 @@ function Mu(e, t) {
|
|
|
8309
8304
|
last_error: null
|
|
8310
8305
|
}).where(D(G.peer_device_id, t)).run();
|
|
8311
8306
|
}
|
|
8312
|
-
function
|
|
8307
|
+
function Pu(e, t, n, r) {
|
|
8313
8308
|
let i = j(e, { schema: R }), { replicationOps: a } = R, o;
|
|
8314
8309
|
if (t) {
|
|
8315
8310
|
let e = t.indexOf("|"), s = e >= 0 ? t.slice(0, e) : t, c = e >= 0 ? t.slice(e + 1) : "";
|
|
@@ -8321,8 +8316,8 @@ function Nu(e, t, n, r) {
|
|
|
8321
8316
|
let c = `${s.created_at}|${s.op_id}`;
|
|
8322
8317
|
return [o, c];
|
|
8323
8318
|
}
|
|
8324
|
-
var
|
|
8325
|
-
async function
|
|
8319
|
+
var Fu = 8;
|
|
8320
|
+
async function Iu(e, t, n, r, i = 0) {
|
|
8326
8321
|
if (n.length === 0) return;
|
|
8327
8322
|
let a = { ops: n }, o = Buffer.from(JSON.stringify(a), "utf-8"), [s, c] = await mr("POST", e, {
|
|
8328
8323
|
headers: gn({
|
|
@@ -8336,19 +8331,19 @@ async function Fu(e, t, n, r, i = 0) {
|
|
|
8336
8331
|
bodyBytes: o
|
|
8337
8332
|
});
|
|
8338
8333
|
if (s === 200 && c != null) return;
|
|
8339
|
-
let l =
|
|
8340
|
-
if (s === 413 && n.length > 1 && i <
|
|
8334
|
+
let l = Du(c);
|
|
8335
|
+
if (s === 413 && n.length > 1 && i < Fu && (l === "payload_too_large" || l === "too_many_ops")) {
|
|
8341
8336
|
let a = Math.floor(n.length / 2);
|
|
8342
|
-
await
|
|
8337
|
+
await Iu(e, t, n.slice(0, a), r, i + 1), await Iu(e, t, n.slice(a), r, i + 1);
|
|
8343
8338
|
return;
|
|
8344
8339
|
}
|
|
8345
8340
|
let u = l ? ` (${s}: ${l})` : ` (${s})`;
|
|
8346
8341
|
throw Error(`peer ops push failed${u}`);
|
|
8347
8342
|
}
|
|
8348
|
-
function
|
|
8343
|
+
function Lu(e) {
|
|
8349
8344
|
Ll(e, 2e3), Rl(e, 200);
|
|
8350
8345
|
}
|
|
8351
|
-
async function
|
|
8346
|
+
async function Ru(e, t, n, r) {
|
|
8352
8347
|
let i = r?.limit ?? Cu, a = r?.keysDir, o = j(e, { schema: R }).select({ pinned_fingerprint: G.pinned_fingerprint }).from(G).where(D(G.peer_device_id, t)).get()?.pinned_fingerprint ?? "";
|
|
8353
8348
|
if (!o) return {
|
|
8354
8349
|
ok: !1,
|
|
@@ -8362,7 +8357,7 @@ async function Lu(e, t, n, r) {
|
|
|
8362
8357
|
[l] = un(e, { keysDir: a });
|
|
8363
8358
|
} catch (n) {
|
|
8364
8359
|
let r = `device identity unavailable: ${n instanceof Error ? n.message.trim() || n.constructor.name : "unknown"}`;
|
|
8365
|
-
return
|
|
8360
|
+
return Mu(e, t, {
|
|
8366
8361
|
ok: !1,
|
|
8367
8362
|
error: r
|
|
8368
8363
|
}), {
|
|
@@ -8387,13 +8382,53 @@ async function Lu(e, t, n, r) {
|
|
|
8387
8382
|
keysDir: a
|
|
8388
8383
|
}) });
|
|
8389
8384
|
if (u !== 200 || !d) {
|
|
8390
|
-
let e =
|
|
8385
|
+
let e = Du(d), t = e ? ` (${u}: ${e})` : ` (${u})`;
|
|
8391
8386
|
throw Error(`peer status failed${t}`);
|
|
8392
8387
|
}
|
|
8393
8388
|
if (d.fingerprint !== o) throw Error("peer fingerprint mismatch");
|
|
8394
|
-
if (String(d.protocol_version ?? "") !==
|
|
8395
|
-
let f =
|
|
8389
|
+
if (String(d.protocol_version ?? "") !== Tu) throw Error(`peer protocol mismatch (expected ${Tu}, got ${String(d.protocol_version ?? "missing")})`);
|
|
8390
|
+
let f = Au(d);
|
|
8396
8391
|
if (!f) throw Error("peer status missing sync_reset boundary");
|
|
8392
|
+
if (s === null && c === null && Number(e.prepare("SELECT count(*) as n FROM memory_items WHERE import_key IS NOT NULL").get()?.n ?? 0) === 0) try {
|
|
8393
|
+
let r = {
|
|
8394
|
+
generation: f.generation,
|
|
8395
|
+
snapshot_id: f.snapshot_id,
|
|
8396
|
+
baseline_cursor: f.baseline_cursor ?? null,
|
|
8397
|
+
retained_floor_cursor: f.retained_floor_cursor ?? null,
|
|
8398
|
+
reset_required: !0,
|
|
8399
|
+
reason: "initial_bootstrap"
|
|
8400
|
+
}, { items: i } = await nu(n, r, l, {
|
|
8401
|
+
keysDir: a,
|
|
8402
|
+
pageSize: wu
|
|
8403
|
+
}), o = Number(e.prepare("SELECT count(*) as n FROM memory_items WHERE import_key IS NOT NULL").get()?.n ?? 0);
|
|
8404
|
+
if (o > 0) return Mu(e, t, {
|
|
8405
|
+
ok: !1,
|
|
8406
|
+
error: "needs_attention:shared_memories_appeared_during_bootstrap"
|
|
8407
|
+
}), {
|
|
8408
|
+
ok: !1,
|
|
8409
|
+
address: n,
|
|
8410
|
+
error: `needs attention: ${o} shared memory change(s) appeared during initial bootstrap fetch`,
|
|
8411
|
+
opsIn: 0,
|
|
8412
|
+
opsOut: 0,
|
|
8413
|
+
addressErrors: []
|
|
8414
|
+
};
|
|
8415
|
+
let s = au(e, t, i, r);
|
|
8416
|
+
if (!s.ok) throw Error("initial bootstrap apply failed");
|
|
8417
|
+
return Nu(e, t), Mu(e, t, {
|
|
8418
|
+
ok: !0,
|
|
8419
|
+
opsIn: s.applied,
|
|
8420
|
+
opsOut: 0
|
|
8421
|
+
}), {
|
|
8422
|
+
ok: !0,
|
|
8423
|
+
address: n,
|
|
8424
|
+
opsIn: s.applied,
|
|
8425
|
+
opsOut: 0,
|
|
8426
|
+
addressErrors: []
|
|
8427
|
+
};
|
|
8428
|
+
} catch (e) {
|
|
8429
|
+
let t = e instanceof Error ? e.message : String(e);
|
|
8430
|
+
throw Error(`initial bootstrap failed: ${t}`);
|
|
8431
|
+
}
|
|
8397
8432
|
let p = new URLSearchParams({
|
|
8398
8433
|
since: s ?? "",
|
|
8399
8434
|
limit: String(i),
|
|
@@ -8417,7 +8452,7 @@ async function Lu(e, t, n, r) {
|
|
|
8417
8452
|
baseline_cursor: typeof g.baseline_cursor == "string" && g.baseline_cursor.trim() ? g.baseline_cursor.trim() : null,
|
|
8418
8453
|
retained_floor_cursor: typeof g.retained_floor_cursor == "string" && g.retained_floor_cursor.trim() ? g.retained_floor_cursor.trim() : null
|
|
8419
8454
|
};
|
|
8420
|
-
if (r.dirty) return
|
|
8455
|
+
if (r.dirty) return Mu(e, t, {
|
|
8421
8456
|
ok: !1,
|
|
8422
8457
|
error: `needs_attention:local_unsynced_shared_memory:${r.count}`
|
|
8423
8458
|
}), {
|
|
@@ -8431,7 +8466,7 @@ async function Lu(e, t, n, r) {
|
|
|
8431
8466
|
};
|
|
8432
8467
|
try {
|
|
8433
8468
|
let { items: r } = await nu(n, i, l, { keysDir: a }), o = yl(e);
|
|
8434
|
-
if (o.dirty) return
|
|
8469
|
+
if (o.dirty) return Mu(e, t, {
|
|
8435
8470
|
ok: !1,
|
|
8436
8471
|
error: `needs_attention:local_unsynced_shared_memory:${o.count}`
|
|
8437
8472
|
}), {
|
|
@@ -8445,7 +8480,7 @@ async function Lu(e, t, n, r) {
|
|
|
8445
8480
|
};
|
|
8446
8481
|
let s = au(e, t, r, i);
|
|
8447
8482
|
if (!s.ok) throw Error("bootstrap apply failed");
|
|
8448
|
-
return
|
|
8483
|
+
return Nu(e, t), Mu(e, t, {
|
|
8449
8484
|
ok: !0,
|
|
8450
8485
|
opsIn: s.applied,
|
|
8451
8486
|
opsOut: 0
|
|
@@ -8458,7 +8493,7 @@ async function Lu(e, t, n, r) {
|
|
|
8458
8493
|
};
|
|
8459
8494
|
} catch (r) {
|
|
8460
8495
|
let a = r instanceof Error ? r.message : String(r);
|
|
8461
|
-
return
|
|
8496
|
+
return Mu(e, t, {
|
|
8462
8497
|
ok: !1,
|
|
8463
8498
|
error: `bootstrap_failed:${a}`
|
|
8464
8499
|
}), {
|
|
@@ -8473,19 +8508,19 @@ async function Lu(e, t, n, r) {
|
|
|
8473
8508
|
}
|
|
8474
8509
|
}
|
|
8475
8510
|
if (h !== 200 || g == null) {
|
|
8476
|
-
let e =
|
|
8511
|
+
let e = Du(g), t = e ? ` (${h}: ${e})` : ` (${h})`;
|
|
8477
8512
|
throw Error(`peer ops fetch failed${t}`);
|
|
8478
8513
|
}
|
|
8479
|
-
if (!
|
|
8480
|
-
let [_, v] = Pl(e, ul(g), t), y = Vl(e, _, l), b = v ||
|
|
8481
|
-
|
|
8482
|
-
let [x, ee] =
|
|
8514
|
+
if (!ju(g)) throw Error("invalid ops response");
|
|
8515
|
+
let [_, v] = Pl(e, ul(g), t), y = Vl(e, _, l), b = v || ku(g.next_cursor);
|
|
8516
|
+
Eu(s, b) && (cl(e, t, { lastApplied: b }), s = b);
|
|
8517
|
+
let [x, ee] = Pu(e, c, l, i), [S, te] = Fl(e, x, t), C = `${n}/v1/ops`;
|
|
8483
8518
|
if (S.length > 0) {
|
|
8484
8519
|
let e = ol(S, Su);
|
|
8485
|
-
for (let t of e) await
|
|
8520
|
+
for (let t of e) await Iu(C, l, t, a);
|
|
8486
8521
|
}
|
|
8487
8522
|
let ne = te ?? ee;
|
|
8488
|
-
return ne &&
|
|
8523
|
+
return ne && Eu(c, ne) && (cl(e, t, { lastAcked: ne }), c = ne), Nu(e, t), Mu(e, t, {
|
|
8489
8524
|
ok: !0,
|
|
8490
8525
|
opsIn: y.applied,
|
|
8491
8526
|
opsOut: S.length
|
|
@@ -8505,8 +8540,8 @@ async function Lu(e, t, n, r) {
|
|
|
8505
8540
|
}
|
|
8506
8541
|
}
|
|
8507
8542
|
}
|
|
8508
|
-
let f =
|
|
8509
|
-
return d || (f = "no dialable peer addresses"), f ||= "sync failed without diagnostic detail",
|
|
8543
|
+
let f = Ou(u);
|
|
8544
|
+
return d || (f = "no dialable peer addresses"), f ||= "sync failed without diagnostic detail", Mu(e, t, {
|
|
8510
8545
|
ok: !1,
|
|
8511
8546
|
error: f
|
|
8512
8547
|
}), {
|
|
@@ -8517,15 +8552,15 @@ async function Lu(e, t, n, r) {
|
|
|
8517
8552
|
addressErrors: u
|
|
8518
8553
|
};
|
|
8519
8554
|
}
|
|
8520
|
-
async function
|
|
8555
|
+
async function zu(e, t, n) {
|
|
8521
8556
|
let r = j(e, { schema: R }).select({ addresses_json: G.addresses_json }).from(G).where(D(G.peer_device_id, t)).get(), i = [];
|
|
8522
8557
|
if (r?.addresses_json) try {
|
|
8523
8558
|
let e = JSON.parse(r.addresses_json);
|
|
8524
8559
|
Array.isArray(e) && (i = e.filter((e) => typeof e == "string"));
|
|
8525
8560
|
} catch {}
|
|
8526
|
-
return
|
|
8561
|
+
return Ru(e, t, i, n);
|
|
8527
8562
|
}
|
|
8528
|
-
var
|
|
8563
|
+
var Bu = [
|
|
8529
8564
|
"no route to host",
|
|
8530
8565
|
"connection refused",
|
|
8531
8566
|
"network is unreachable",
|
|
@@ -8536,33 +8571,33 @@ var zu = [
|
|
|
8536
8571
|
"errno 61",
|
|
8537
8572
|
"errno 60",
|
|
8538
8573
|
"errno 111"
|
|
8539
|
-
],
|
|
8540
|
-
function
|
|
8574
|
+
], Vu = 120, Hu = 1800;
|
|
8575
|
+
function Uu(e) {
|
|
8541
8576
|
if (!e) return !1;
|
|
8542
8577
|
let t = e.toLowerCase();
|
|
8543
|
-
return
|
|
8578
|
+
return Bu.some((e) => t.includes(e));
|
|
8544
8579
|
}
|
|
8545
|
-
function
|
|
8580
|
+
function Wu(e, t, n = 10) {
|
|
8546
8581
|
let r = j(e, { schema: R }).select({
|
|
8547
8582
|
ok: He.ok,
|
|
8548
8583
|
error: He.error
|
|
8549
8584
|
}).from(He).where(D(He.peer_device_id, t)).orderBy(le(He.started_at)).limit(n).all(), i = 0;
|
|
8550
8585
|
for (let e of r) {
|
|
8551
8586
|
if (e.ok) break;
|
|
8552
|
-
if (
|
|
8587
|
+
if (Uu(e.error)) i++;
|
|
8553
8588
|
else break;
|
|
8554
8589
|
}
|
|
8555
8590
|
return i;
|
|
8556
8591
|
}
|
|
8557
|
-
function
|
|
8592
|
+
function Gu(e) {
|
|
8558
8593
|
if (e <= 1) return 0;
|
|
8559
8594
|
let t = Math.min(e - 1, 8);
|
|
8560
|
-
return Math.min(
|
|
8595
|
+
return Math.min(Vu * 2 ** (t - 1), Hu) * (.5 + Math.random() * .5);
|
|
8561
8596
|
}
|
|
8562
|
-
function
|
|
8563
|
-
let n =
|
|
8597
|
+
function Ku(e, t) {
|
|
8598
|
+
let n = Wu(e, t);
|
|
8564
8599
|
if (n < 2) return !1;
|
|
8565
|
-
let r =
|
|
8600
|
+
let r = Gu(n);
|
|
8566
8601
|
if (r <= 0) return !1;
|
|
8567
8602
|
let i = j(e, { schema: R }).select({ started_at: He.started_at }).from(He).where(D(He.peer_device_id, t)).orderBy(le(He.started_at)).limit(1).get();
|
|
8568
8603
|
if (!i?.started_at) return !1;
|
|
@@ -8575,7 +8610,7 @@ function Gu(e, t) {
|
|
|
8575
8610
|
}
|
|
8576
8611
|
//#endregion
|
|
8577
8612
|
//#region src/sync-daemon.ts
|
|
8578
|
-
function
|
|
8613
|
+
function qu(e) {
|
|
8579
8614
|
let t = j(e, { schema: R }), n = (/* @__PURE__ */ new Date()).toISOString();
|
|
8580
8615
|
t.insert(q).values({
|
|
8581
8616
|
id: 1,
|
|
@@ -8589,7 +8624,7 @@ function Ku(e) {
|
|
|
8589
8624
|
}
|
|
8590
8625
|
}).run();
|
|
8591
8626
|
}
|
|
8592
|
-
function
|
|
8627
|
+
function Ju(e, t, n) {
|
|
8593
8628
|
let r = j(e, { schema: R }), i = (/* @__PURE__ */ new Date()).toISOString();
|
|
8594
8629
|
r.insert(q).values({
|
|
8595
8630
|
id: 1,
|
|
@@ -8605,11 +8640,11 @@ function qu(e, t, n) {
|
|
|
8605
8640
|
}
|
|
8606
8641
|
}).run();
|
|
8607
8642
|
}
|
|
8608
|
-
function
|
|
8643
|
+
function Yu(e) {
|
|
8609
8644
|
let t = j(e, { schema: R }).select({ phase: q.phase }).from(q).where(D(q.id, 1)).get()?.phase;
|
|
8610
8645
|
return t === "needs_attention" ? t : null;
|
|
8611
8646
|
}
|
|
8612
|
-
function
|
|
8647
|
+
function Xu(e, t) {
|
|
8613
8648
|
j(e, { schema: R }).insert(q).values({
|
|
8614
8649
|
id: 1,
|
|
8615
8650
|
phase: t
|
|
@@ -8618,21 +8653,21 @@ function Yu(e, t) {
|
|
|
8618
8653
|
set: { phase: t }
|
|
8619
8654
|
}).run();
|
|
8620
8655
|
}
|
|
8621
|
-
async function
|
|
8656
|
+
async function Zu(e, t, n) {
|
|
8622
8657
|
let r = Hr();
|
|
8623
8658
|
return Ur(r) ? (await Gr({
|
|
8624
8659
|
db: e,
|
|
8625
8660
|
dbPath: t
|
|
8626
8661
|
}, r, { keysDir: n }), !0) : !1;
|
|
8627
8662
|
}
|
|
8628
|
-
async function
|
|
8663
|
+
async function Qu(e, t) {
|
|
8629
8664
|
let n = j(e, { schema: R }).select({ peer_device_id: G.peer_device_id }).from(G).all();
|
|
8630
8665
|
if (n.length === 0) return [];
|
|
8631
|
-
|
|
8666
|
+
Lu(e);
|
|
8632
8667
|
let r = [];
|
|
8633
8668
|
for (let i of n) {
|
|
8634
8669
|
let n = i.peer_device_id;
|
|
8635
|
-
if (
|
|
8670
|
+
if (Ku(e, n)) {
|
|
8636
8671
|
r.push({
|
|
8637
8672
|
ok: !1,
|
|
8638
8673
|
skipped: !0,
|
|
@@ -8640,7 +8675,7 @@ async function Zu(e, t) {
|
|
|
8640
8675
|
});
|
|
8641
8676
|
continue;
|
|
8642
8677
|
}
|
|
8643
|
-
let a = await
|
|
8678
|
+
let a = await zu(e, n, { keysDir: t });
|
|
8644
8679
|
r.push({
|
|
8645
8680
|
ok: a.ok,
|
|
8646
8681
|
error: a.error,
|
|
@@ -8650,7 +8685,7 @@ async function Zu(e, t) {
|
|
|
8650
8685
|
}
|
|
8651
8686
|
return r;
|
|
8652
8687
|
}
|
|
8653
|
-
async function
|
|
8688
|
+
async function $u(e) {
|
|
8654
8689
|
let t = e?.intervalS ?? 120, n = Ot(e?.dbPath), r = e?.keysDir, i = e?.signal, a = e?.onPhaseChange;
|
|
8655
8690
|
a?.("starting");
|
|
8656
8691
|
let o = Nt(n), s = null;
|
|
@@ -8666,7 +8701,7 @@ async function Qu(e) {
|
|
|
8666
8701
|
}
|
|
8667
8702
|
return new Promise((e) => {
|
|
8668
8703
|
let o = !1, c = !1, l = () => {
|
|
8669
|
-
o || (o = !0,
|
|
8704
|
+
o || (o = !0, ed(n, r).finally(() => {
|
|
8670
8705
|
o = !1, c || (c = !0, a?.("running"));
|
|
8671
8706
|
}));
|
|
8672
8707
|
}, u = setInterval(l, t * 1e3);
|
|
@@ -8683,22 +8718,22 @@ async function Qu(e) {
|
|
|
8683
8718
|
}
|
|
8684
8719
|
});
|
|
8685
8720
|
}
|
|
8686
|
-
async function
|
|
8721
|
+
async function ed(e, t) {
|
|
8687
8722
|
let n = Nt(e);
|
|
8688
8723
|
try {
|
|
8689
8724
|
try {
|
|
8690
|
-
await
|
|
8725
|
+
await Zu(n, e, t);
|
|
8691
8726
|
} catch {}
|
|
8692
|
-
(await
|
|
8727
|
+
(await Qu(n, t)).some((e) => !e.ok && e.error?.includes("needs_attention")) ? Xu(n, "needs_attention") : qu(n);
|
|
8693
8728
|
} catch (e) {
|
|
8694
|
-
|
|
8729
|
+
Ju(n, e instanceof Error ? e.message : String(e), e instanceof Error ? e.stack ?? "" : "");
|
|
8695
8730
|
} finally {
|
|
8696
8731
|
n.close();
|
|
8697
8732
|
}
|
|
8698
8733
|
}
|
|
8699
8734
|
//#endregion
|
|
8700
8735
|
//#region src/sync-retention-runner.ts
|
|
8701
|
-
async function
|
|
8736
|
+
async function td(e, t) {
|
|
8702
8737
|
if (!t.syncRetentionEnabled) return;
|
|
8703
8738
|
e.exec("\n CREATE TABLE IF NOT EXISTS sync_retention_state (\n id INTEGER PRIMARY KEY,\n last_run_at TEXT,\n last_duration_ms INTEGER,\n last_deleted_ops INTEGER NOT NULL DEFAULT 0,\n last_estimated_bytes_before INTEGER,\n last_estimated_bytes_after INTEGER,\n retained_floor_cursor TEXT,\n last_error TEXT,\n last_error_at TEXT\n )\n ");
|
|
8704
8739
|
let n = j(e, { schema: R }), r = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -8760,7 +8795,7 @@ async function ed(e, t) {
|
|
|
8760
8795
|
}).run();
|
|
8761
8796
|
}
|
|
8762
8797
|
}
|
|
8763
|
-
var
|
|
8798
|
+
var nd = class {
|
|
8764
8799
|
dbPath;
|
|
8765
8800
|
signal;
|
|
8766
8801
|
active = !1;
|
|
@@ -8788,7 +8823,7 @@ var td = class {
|
|
|
8788
8823
|
if (!this.active || this.signal?.aborted) return;
|
|
8789
8824
|
let e = Hr(tt()), t = Nt(this.dbPath);
|
|
8790
8825
|
try {
|
|
8791
|
-
await
|
|
8826
|
+
await td(t, {
|
|
8792
8827
|
...e,
|
|
8793
8828
|
signal: this.signal
|
|
8794
8829
|
});
|
|
@@ -8799,17 +8834,17 @@ var td = class {
|
|
|
8799
8834
|
};
|
|
8800
8835
|
//#endregion
|
|
8801
8836
|
//#region src/test-utils.ts
|
|
8802
|
-
function
|
|
8837
|
+
function rd(e) {
|
|
8803
8838
|
Xn(e);
|
|
8804
8839
|
}
|
|
8805
|
-
function
|
|
8840
|
+
function id(e) {
|
|
8806
8841
|
let t = (/* @__PURE__ */ new Date()).toISOString(), n = e.prepare("INSERT INTO sessions(started_at, cwd, project, user, tool_version) VALUES (?, ?, ?, ?, ?)").run(t, "/tmp/test", "test-project", "test-user", "test");
|
|
8807
8842
|
return Number(n.lastInsertRowid);
|
|
8808
8843
|
}
|
|
8809
8844
|
//#endregion
|
|
8810
8845
|
//#region src/index.ts
|
|
8811
|
-
var
|
|
8846
|
+
var ad = "0.22.4";
|
|
8812
8847
|
//#endregion
|
|
8813
|
-
export { Ee as Api, Pe as BetterSqliteCoordinatorStore, $e as CODEMEM_CONFIG_ENV_OVERRIDES, I as DEFAULT_COORDINATOR_DB_PATH, Dt as DEFAULT_DB_PATH, ou as DEFAULT_SERVICE_TYPE, i as DEFAULT_TIME_WINDOW_S, qi as LOW_SIGNAL_TOOLS, xn as MAPPABLE_CLAUDE_HOOK_EVENTS, Tt as MIN_COMPATIBLE_SCHEMA, tu as MemoryStore, Ao as ObserverAuthAdapter, Ko as ObserverAuthError, us as ObserverClient, qc as RawEventSweeper, wt as SCHEMA_VERSION, dn as SIGNATURE_VERSION,
|
|
8848
|
+
export { Ee as Api, Pe as BetterSqliteCoordinatorStore, $e as CODEMEM_CONFIG_ENV_OVERRIDES, I as DEFAULT_COORDINATOR_DB_PATH, Dt as DEFAULT_DB_PATH, ou as DEFAULT_SERVICE_TYPE, i as DEFAULT_TIME_WINDOW_S, qi as LOW_SIGNAL_TOOLS, xn as MAPPABLE_CLAUDE_HOOK_EVENTS, Tt as MIN_COMPATIBLE_SCHEMA, tu as MemoryStore, Ao as ObserverAuthAdapter, Ko as ObserverAuthError, us as ObserverClient, qc as RawEventSweeper, wt as SCHEMA_VERSION, dn as SIGNATURE_VERSION, nd as SyncRetentionRunner, va as TRIVIAL_REQUESTS, ad as VERSION, ti as _resetEmbeddingClient, Nr as addressDedupeKey, yu as advertiseMdns, au as applyBootstrapSnapshot, Vl as applyReplicationOps, zt as assertSchemaReady, Rl as backfillReplicationOps, cr as backfillTagsText, Ja as backfillVectors, aa as budgetToolEvents, gn as buildAuthHeaders, pr as buildBaseUrl, fn as buildCanonicalRequest, To as buildCodexHeaders, Mi as buildFilterClauses, Ni as buildFilterClausesWithContext, fi as buildImportKey, Rn as buildIngestPayloadFromHook, Pc as buildMemoryPack, Fc as buildMemoryPackAsync, _a as buildObserverPrompt, Ln as buildRawEventEnvelopeFromHook, Vc as buildSessionContext, Ca as buildTranscript, Sl as bulkPruneReplicationOpsByAgeCutoff, ol as chunkOpsBySize, $r as chunkText, ao as cleanOrphanSessions, vn as cleanupNonces, dl as clockTuple, Nt as connect, Ne as connectCoordinator, Wu as consecutiveConnectivityFailures, xr as coordinatorCreateGroupAction, Or as coordinatorCreateInviteAction, Er as coordinatorDisableDeviceAction, Ur as coordinatorEnabled, Cr as coordinatorEnrollDeviceAction, kr as coordinatorImportInviteAction, wr as coordinatorListDevicesAction, Sr as coordinatorListGroupsAction, Ar as coordinatorListJoinRequestsAction, Dr as coordinatorRemoveDeviceAction, Tr as coordinatorRenameDeviceAction, jr as coordinatorReviewJoinRequestAction, Xr as coordinatorStatusSnapshot, yn as createBetterSqliteCoordinatorApp, o as createCoordinatorApp, Jr as createCoordinatorReciprocalApproval, Eu as cursorAdvances, fr as deactivateLowSignalMemories, dr as deactivateLowSignalObservations, t as decodeInvitePayload, Ys as dedupeOrderedIds, Sa as deriveRequest, Ha as deriveTags, bu as discoverPeersViaMdns, ri as embedTexts, e as encodeInvitePayload, un as ensureDeviceIdentity, ic as estimateTokens, Qi as eventToToolEvent, Cs as expandQuery, $s as explain, vi as exportMemories, ea as extractAdapterEvent, wa as extractAssistantMessages, Ta as extractAssistantUsage, r as extractInvitePayload, bo as extractOAuthAccess, Co as extractOAuthAccountId, wo as extractOAuthExpires, Ea as extractPrompts, xo as extractProviderApiKey, ul as extractReplicationOps, $i as extractToolEvents, nu as fetchAllSnapshotPages, Va as fileTags, Fl as filterReplicationOpsForSync, Pl as filterReplicationOpsForSyncWithStatus, n as fingerprintPublicKey, xa as firstSentence, Uc as flushRawEvents, J as fromJson, Ut as fromJsonStrict, on as generateKeypair, et as getCodememConfigPath, rt as getCodememEnvOverrides, ni as getEmbeddingClient, at as getOpenCodeProviderConfig, xt as getProviderApiKey, yt as getProviderBaseUrl, bt as getProviderHeaders, vt as getProviderOptions, er as getRawEventStatus, tr as getReliabilityMetrics, sl as getReplicationCursor, Rt as getSchemaVersion, Yu as getSyncDaemonPhase, tl as getSyncResetState, Ra as hasMeaningfulObservation, yl as hasUnsyncedSharedMemoryChanges, Qr as hashText, Ei as importMemories, ro as ingest, oo as ingestMain, Qn as initDatabase, rd as initTestSchema, id as insertTestSession, a as inviteLink, Uu as isConnectivityError, Lt as isEmbeddingDisabled, Ji as isInternalMemoryTool, Vn as isLowSignalObservation, fl as isNewerClock, Bi as isSensitiveFieldName, ba as isTrivialRequest, Ts as kindBonus, lt as listConfiguredOpenCodeProviders, Zr as listCoordinatorJoinRequests, qr as listCoordinatorReciprocalApprovals, ot as listCustomProviders, ut as listObserverProviderOptions, vl as loadMemorySnapshotPageForPeer, Go as loadObserverConfig, Ze as loadOpenCodeConfig, _o as loadOpenCodeOAuthCache, cu as loadPeerAddresses, tn as loadPrivateKey, Qt as loadPrivateKeyKeychain, en as loadPublicKey, _l as loadReplicationOpsForPeer, gl as loadReplicationOpsSince, It as loadSqliteVec, Kr as lookupCoordinatorPeers, Fn as mapClaudeHookPayload, xu as mdnsAddressesForPeer, vu as mdnsEnabled, Pr as mergeAddresses, pi as mergeSummaryMetadata, Mt as migrateLegacyDbPath, Ll as migrateLegacyImportKeys, Da as normalizeAdapterEvents, Mr as normalizeAddress, Bn as normalizeObservation, En as normalizeProjectLabel, ya as normalizeRequestText, Ba as normalizeTag, Yi as normalizeToolName, La as parseObserverResponse, uo as parsePositiveMemoryId, lo as parseStrictInteger, Gu as peerBackoffSeconds, Cl as planReplicationOpsAgePrune, So as probeAvailableCredentials, ta as projectAdapterToolEvent, Hn as projectBasename, Wn as projectClause, Un as projectColumnClause, Gn as projectMatchesFilter, bl as pruneReplicationOps, xl as pruneReplicationOpsUntilCaughtUp, nr as rawEventsGate, Do as readAuthFile, tt as readCodememConfigFile, Hr as readCoordinatorSyncConfig, yi as readImportPayload, ws as recencyScore, _n as recordNonce, du as recordPeerSuccess, pl as recordReplicationOp, uu as recordSyncAttempt, mo as redactText, Gr as registerCoordinatorPresence, Po as renderObserverHeaders, mr as requestJson, Ws as rerankResults, ft as resolveBuiltInProviderDefaultModel, dt as resolveBuiltInProviderFromModel, pt as resolveBuiltInProviderModel, St as resolveCustomProviderDefaultModel, mt as resolveCustomProviderFromModel, Ct as resolveCustomProviderModel, Ot as resolveDbPath, kn as resolveHookProject, $t as resolveKeyPaths, vo as resolveOAuthProvider, ht as resolvePlaceholder, qn as resolveProject, rr as retryRawEventFailures, Eo as runAuthCommand, $u as runSyncDaemon, zu as runSyncPass, Ui as sanitizePayload, Ki as sanitizeToolOutput, R as schema, Gs as search, su as selectDialAddresses, Ya as semanticSearch, ai as serializeFloat32, pu as setPeerLocalActorClaim, fu as setPeerProjectFilter, cl as setReplicationCursor, Ju as setSyncDaemonError, qu as setSyncDaemonOk, Xu as setSyncDaemonPhase, nl as setSyncResetState, Ku as shouldSkipOfflinePeer, pn as signRequest, Zt as storePrivateKeyKeychain, qa as storeVectors, Ye as stripJsonComments, Li as stripPrivate, Vi as stripPrivateObj, Xe as stripTrailingCommas, Qu as syncDaemonTick, Ru as syncOnce, Lu as syncPassPreflight, Bt as tableExists, qs as timeline, Y as toJson, X as toJsonNullable, lu as updatePeerAddresses, $n as vacuumDatabase, ln as validateExistingKeypair, mn as verifySignature, nt as writeCodememConfigFile };
|
|
8814
8849
|
|
|
8815
8850
|
//# sourceMappingURL=index.js.map
|