@codemem/core 0.35.2 → 0.36.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/api-types.d.ts +2 -1
- package/dist/api-types.d.ts.map +1 -1
- package/dist/{coordinator-api-CGi5NMw2.js → coordinator-api-CbONcz8J.js} +4 -4
- package/dist/{coordinator-api-CGi5NMw2.js.map → coordinator-api-CbONcz8J.js.map} +1 -1
- package/dist/coordinator-runtime.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +878 -826
- package/dist/index.js.map +1 -1
- package/dist/internal/cloudflare-coordinator.js +1 -1
- package/dist/internal/cloudflare-coordinator.js.map +1 -1
- package/dist/sync-bootstrap.d.ts.map +1 -1
- package/dist/sync-pass.d.ts +3 -0
- package/dist/sync-pass.d.ts.map +1 -1
- package/dist/sync-replication.d.ts +11 -4
- package/dist/sync-replication.d.ts.map +1 -1
- package/dist/sync-scope-protocol.d.ts.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, s, t as c, u as l } from "./coordinator-api-
|
|
1
|
+
import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, s, t as c, u as l } from "./coordinator-api-CbONcz8J.js";
|
|
2
2
|
import { createHash as u, createPrivateKey as d, createPublicKey as f, generateKeyPairSync as p, randomBytes as m, randomUUID as h, sign as g, verify as _ } from "node:crypto";
|
|
3
3
|
import { copyFileSync as v, existsSync as y, lstatSync as b, mkdirSync as x, readFileSync as S, renameSync as C, statSync as w, unlinkSync as ee, writeFileSync as te } from "node:fs";
|
|
4
4
|
import { arch as ne, homedir as re, networkInterfaces as ie, platform as T, release as ae, tmpdir as oe } from "node:os";
|
|
@@ -3413,7 +3413,7 @@ function va(e) {
|
|
|
3413
3413
|
let t = ga(e);
|
|
3414
3414
|
if (t.length <= da) return t;
|
|
3415
3415
|
let n = t.split(ma).map((e) => ga(e)).filter((e) => e.length >= fa && e.length <= da);
|
|
3416
|
-
return n.length > 0 ? n[n.length - 1] ?? t.slice(-
|
|
3416
|
+
return n.length > 0 ? n[n.length - 1] ?? t.slice(-250).trim() : t.slice(-250).trim();
|
|
3417
3417
|
}
|
|
3418
3418
|
function ya(e) {
|
|
3419
3419
|
let t = e.trim();
|
|
@@ -3656,18 +3656,18 @@ var Ba = {
|
|
|
3656
3656
|
observation: .1,
|
|
3657
3657
|
exploration: .1,
|
|
3658
3658
|
entities: .05
|
|
3659
|
-
}, Va = .45, Ha = .18, Ua = .12, Wa = 3, Ga = 0, Ka = 2, qa = 3, Ja = 0, Ya = 3, Xa = 2.5, Za = 6.5, Qa = .35, $a = .12, eo = .05, to = .
|
|
3659
|
+
}, Va = .45, Ha = .18, Ua = .12, Wa = 3, Ga = 0, Ka = 2, qa = 3, Ja = 0, Ya = 3, Xa = 2.5, Za = 6.5, Qa = .35, $a = .12, eo = .05, to = .08, no = 200, ro = [
|
|
3660
3660
|
/\bwhat did i\b/i,
|
|
3661
3661
|
/\bmy notes\b/i,
|
|
3662
3662
|
/\bmy last session\b/i,
|
|
3663
3663
|
/\bmy machine\b/i
|
|
3664
|
-
],
|
|
3664
|
+
], io = new Set([
|
|
3665
3665
|
"or",
|
|
3666
3666
|
"and",
|
|
3667
3667
|
"not",
|
|
3668
3668
|
"near",
|
|
3669
3669
|
"phrase"
|
|
3670
|
-
]),
|
|
3670
|
+
]), ao = new Set([
|
|
3671
3671
|
"a",
|
|
3672
3672
|
"about",
|
|
3673
3673
|
"an",
|
|
@@ -3694,26 +3694,26 @@ var Ba = {
|
|
|
3694
3694
|
"worked",
|
|
3695
3695
|
"working"
|
|
3696
3696
|
]);
|
|
3697
|
-
function
|
|
3697
|
+
function oo(e) {
|
|
3698
3698
|
let t = e.match(/[A-Za-z0-9_]+/g);
|
|
3699
3699
|
if (!t) return "";
|
|
3700
3700
|
let n = t.filter((e) => {
|
|
3701
3701
|
let t = e.toLowerCase();
|
|
3702
|
-
return !
|
|
3702
|
+
return !io.has(t);
|
|
3703
3703
|
}), r = n.filter((e) => {
|
|
3704
3704
|
let t = e.toLowerCase();
|
|
3705
|
-
return !
|
|
3705
|
+
return !ao.has(t);
|
|
3706
3706
|
}), i = r.length > 0 ? r : n;
|
|
3707
3707
|
return i.length === 0 ? "" : i.length === 1 ? i[0] : i.join(" OR ");
|
|
3708
3708
|
}
|
|
3709
|
-
function
|
|
3709
|
+
function so(e, t) {
|
|
3710
3710
|
let n = Date.parse(e);
|
|
3711
3711
|
return Number.isNaN(n) ? 0 : 1 / (1 + Math.max(0, Math.floor(((t ?? /* @__PURE__ */ new Date()).getTime() - n) / 864e5)) / 7);
|
|
3712
3712
|
}
|
|
3713
|
-
function
|
|
3713
|
+
function co(e) {
|
|
3714
3714
|
return e ? Ba[e.trim().toLowerCase()] ?? 0 : 0;
|
|
3715
3715
|
}
|
|
3716
|
-
function
|
|
3716
|
+
function lo(e) {
|
|
3717
3717
|
if (!e || e.personal_first === void 0) return !0;
|
|
3718
3718
|
let t = e.personal_first;
|
|
3719
3719
|
if (typeof t == "string") {
|
|
@@ -3733,13 +3733,13 @@ function uo(e) {
|
|
|
3733
3733
|
}
|
|
3734
3734
|
return !!t;
|
|
3735
3735
|
}
|
|
3736
|
-
function
|
|
3736
|
+
function uo(e) {
|
|
3737
3737
|
return String(e?.trust_bias ?? "off").trim().toLowerCase() === "soft" ? "soft" : "off";
|
|
3738
3738
|
}
|
|
3739
|
-
function
|
|
3740
|
-
return e === Infinity ?
|
|
3739
|
+
function fo(e) {
|
|
3740
|
+
return e === Infinity ? no : Number.isFinite(e) ? Math.min(Math.max(0, Math.trunc(e)), no) : 0;
|
|
3741
3741
|
}
|
|
3742
|
-
function
|
|
3742
|
+
function po(e) {
|
|
3743
3743
|
if (!e || e.widen_shared_when_weak === void 0) return !1;
|
|
3744
3744
|
let t = e.widen_shared_when_weak;
|
|
3745
3745
|
if (typeof t == "string") {
|
|
@@ -3759,25 +3759,25 @@ function mo(e) {
|
|
|
3759
3759
|
}
|
|
3760
3760
|
return !!t;
|
|
3761
3761
|
}
|
|
3762
|
-
function
|
|
3762
|
+
function mo(e) {
|
|
3763
3763
|
let t = e?.widen_shared_min_personal_results;
|
|
3764
3764
|
return typeof t != "number" || !Number.isFinite(t) ? Wa : Math.max(1, Math.trunc(t));
|
|
3765
3765
|
}
|
|
3766
|
-
function
|
|
3766
|
+
function ho(e) {
|
|
3767
3767
|
let t = e?.widen_shared_min_personal_score;
|
|
3768
3768
|
return typeof t != "number" || !Number.isFinite(t) ? Ga : Math.max(0, t);
|
|
3769
3769
|
}
|
|
3770
|
-
function
|
|
3771
|
-
return
|
|
3770
|
+
function go(e) {
|
|
3771
|
+
return ro.some((t) => t.test(e));
|
|
3772
3772
|
}
|
|
3773
|
-
function
|
|
3773
|
+
function _o(e) {
|
|
3774
3774
|
if (!e) return !1;
|
|
3775
3775
|
let t = String(e.ownership_scope ?? "").trim().toLowerCase();
|
|
3776
3776
|
if (t === "mine" || t === "theirs") return !0;
|
|
3777
3777
|
let n = ia(e.include_visibility ?? e.visibility), r = ia(e.exclude_visibility), i = na(e.include_workspace_ids), a = na(e.exclude_workspace_ids), o = ra(e.include_workspace_kinds), s = ra(e.exclude_workspace_kinds);
|
|
3778
3778
|
return n.length || i.length || o.length || r.includes("private") || r.includes("shared") || s.includes("shared") || s.includes("personal") ? !0 : a.some((e) => e.startsWith("personal:") || e.startsWith("shared:"));
|
|
3779
3779
|
}
|
|
3780
|
-
function
|
|
3780
|
+
function vo(e) {
|
|
3781
3781
|
return {
|
|
3782
3782
|
...e ?? {},
|
|
3783
3783
|
visibility: void 0,
|
|
@@ -3788,7 +3788,7 @@ function yo(e) {
|
|
|
3788
3788
|
widen_shared_when_weak: !1
|
|
3789
3789
|
};
|
|
3790
3790
|
}
|
|
3791
|
-
function
|
|
3791
|
+
function yo(e) {
|
|
3792
3792
|
if (!e || e.widen_project_when_weak === void 0) return !1;
|
|
3793
3793
|
let t = e.widen_project_when_weak;
|
|
3794
3794
|
if (typeof t == "string") {
|
|
@@ -3808,22 +3808,22 @@ function bo(e) {
|
|
|
3808
3808
|
}
|
|
3809
3809
|
return !!t;
|
|
3810
3810
|
}
|
|
3811
|
-
function
|
|
3811
|
+
function bo(e) {
|
|
3812
3812
|
let t = e?.widen_project_min_results;
|
|
3813
3813
|
return typeof t != "number" || !Number.isFinite(t) ? qa : Math.max(1, Math.trunc(t));
|
|
3814
3814
|
}
|
|
3815
|
-
function
|
|
3815
|
+
function xo(e) {
|
|
3816
3816
|
let t = e?.widen_project_min_score;
|
|
3817
3817
|
return typeof t != "number" || !Number.isFinite(t) ? Ja : Math.max(0, t);
|
|
3818
3818
|
}
|
|
3819
|
-
function
|
|
3819
|
+
function So(e) {
|
|
3820
3820
|
let t = e?.widen_project_max_results;
|
|
3821
3821
|
return typeof t != "number" || !Number.isFinite(t) ? Ya : Math.max(1, Math.trunc(t));
|
|
3822
3822
|
}
|
|
3823
|
-
function
|
|
3824
|
-
return
|
|
3823
|
+
function Co(e) {
|
|
3824
|
+
return Wo(e).some((e) => e.includes("/"));
|
|
3825
3825
|
}
|
|
3826
|
-
function
|
|
3826
|
+
function wo(e) {
|
|
3827
3827
|
return {
|
|
3828
3828
|
...e ?? {},
|
|
3829
3829
|
project: void 0,
|
|
@@ -3831,9 +3831,9 @@ function To(e) {
|
|
|
3831
3831
|
widen_shared_when_weak: !1
|
|
3832
3832
|
};
|
|
3833
3833
|
}
|
|
3834
|
-
function
|
|
3834
|
+
function To(e, t) {
|
|
3835
3835
|
if (t.length === 0) return t;
|
|
3836
|
-
let n =
|
|
3836
|
+
let n = cs(e, new Set(t.map((e) => e.session_id).filter((e) => !!e)));
|
|
3837
3837
|
return t.map((e) => {
|
|
3838
3838
|
let t = n.get(e.session_id) ?? null;
|
|
3839
3839
|
return {
|
|
@@ -3846,7 +3846,7 @@ function Eo(e, t) {
|
|
|
3846
3846
|
};
|
|
3847
3847
|
});
|
|
3848
3848
|
}
|
|
3849
|
-
function
|
|
3849
|
+
function Eo(e) {
|
|
3850
3850
|
return e.map((e) => ({
|
|
3851
3851
|
...e,
|
|
3852
3852
|
metadata: {
|
|
@@ -3855,10 +3855,10 @@ function Do(e) {
|
|
|
3855
3855
|
}
|
|
3856
3856
|
}));
|
|
3857
3857
|
}
|
|
3858
|
-
function
|
|
3859
|
-
return
|
|
3858
|
+
function Do(e, t, n) {
|
|
3859
|
+
return lo(n) && e(t) ? Va : 0;
|
|
3860
3860
|
}
|
|
3861
|
-
function
|
|
3861
|
+
function Oo(e) {
|
|
3862
3862
|
let t = e.toLowerCase();
|
|
3863
3863
|
for (let e of [
|
|
3864
3864
|
"what should",
|
|
@@ -3872,7 +3872,7 @@ function ko(e) {
|
|
|
3872
3872
|
]) if (t.includes(e)) return !0;
|
|
3873
3873
|
return !1;
|
|
3874
3874
|
}
|
|
3875
|
-
function
|
|
3875
|
+
function ko(e) {
|
|
3876
3876
|
let t = e.toLowerCase();
|
|
3877
3877
|
for (let e of [
|
|
3878
3878
|
"what did we decide",
|
|
@@ -3883,7 +3883,7 @@ function Ao(e) {
|
|
|
3883
3883
|
]) if (t.includes(e)) return !0;
|
|
3884
3884
|
return !1;
|
|
3885
3885
|
}
|
|
3886
|
-
function
|
|
3886
|
+
function Ao(e) {
|
|
3887
3887
|
let t = e.toLowerCase(), n = new Set(t.match(/[a-z0-9_]+/g) ?? []);
|
|
3888
3888
|
for (let e of [
|
|
3889
3889
|
"root cause",
|
|
@@ -3896,7 +3896,7 @@ function jo(e) {
|
|
|
3896
3896
|
]) if (t.includes(e)) return !0;
|
|
3897
3897
|
return !!(n.has("bug") || n.has("bugs"));
|
|
3898
3898
|
}
|
|
3899
|
-
function
|
|
3899
|
+
function jo(e) {
|
|
3900
3900
|
let t = e.toLowerCase();
|
|
3901
3901
|
for (let e of [
|
|
3902
3902
|
"what should we do next",
|
|
@@ -3908,27 +3908,27 @@ function Mo(e) {
|
|
|
3908
3908
|
]) if (t.includes(e)) return !0;
|
|
3909
3909
|
return !1;
|
|
3910
3910
|
}
|
|
3911
|
-
function
|
|
3912
|
-
let n =
|
|
3911
|
+
function Mo(e, t) {
|
|
3912
|
+
let n = ko(t), r = Ao(t), i = jo(t);
|
|
3913
3913
|
if (!n && !r && !i) return 0;
|
|
3914
3914
|
let a = 0;
|
|
3915
3915
|
return n && (e.kind === "decision" && (a += .2), e.kind === "discovery" && (a += .08)), r && (e.kind === "bugfix" && (a += .24), e.kind === "discovery" && (a += .16), e.kind === "decision" && (a += .04)), i && (e.kind === "decision" && (a += .1), e.kind === "feature" && (a += .08), e.kind === "discovery" && (a += .06)), a;
|
|
3916
3916
|
}
|
|
3917
|
-
function
|
|
3917
|
+
function No(e, t, n) {
|
|
3918
3918
|
let r = Mi({
|
|
3919
3919
|
kind: e.kind,
|
|
3920
3920
|
title: e.title,
|
|
3921
3921
|
body_text: e.body_text,
|
|
3922
3922
|
metadata: e.metadata
|
|
3923
3923
|
});
|
|
3924
|
-
return t ? r.role === "recap" ?
|
|
3924
|
+
return t ? r.role === "recap" ? to : r.role === "ephemeral" ? -.1 : 0 : r.role === "durable" ? $a : r.role === "general" ? eo : n && r.role === "ephemeral" ? 0 : r.role === "ephemeral" ? -.45 : 0;
|
|
3925
3925
|
}
|
|
3926
|
-
function
|
|
3926
|
+
function Po(e, t) {
|
|
3927
3927
|
if (t || !Da(e)) return 0;
|
|
3928
3928
|
let n = e.metadata ?? {}, r = Oa(e, t);
|
|
3929
3929
|
return n.source === "observer_summary" || typeof n.request == "string" && typeof n.completed == "string" ? Za * r : Xa * r;
|
|
3930
3930
|
}
|
|
3931
|
-
function
|
|
3931
|
+
function Fo(e) {
|
|
3932
3932
|
let t = `${e.title} ${e.body_text}`.toLowerCase();
|
|
3933
3933
|
for (let e of [
|
|
3934
3934
|
"next step",
|
|
@@ -3943,84 +3943,84 @@ function Io(e) {
|
|
|
3943
3943
|
]) if (t.includes(e)) return !0;
|
|
3944
3944
|
return !1;
|
|
3945
3945
|
}
|
|
3946
|
-
function
|
|
3947
|
-
if (
|
|
3946
|
+
function Io(e, t, n) {
|
|
3947
|
+
if (uo(n) !== "soft" || e(t)) return 0;
|
|
3948
3948
|
let r = t.metadata ?? {}, i = String(r.visibility ?? "").trim().toLowerCase(), a = String(r.workspace_kind ?? "").trim().toLowerCase();
|
|
3949
3949
|
if (i !== "shared" && a !== "shared") return 0;
|
|
3950
3950
|
let o = String(r.trust_state ?? "trusted").trim().toLowerCase();
|
|
3951
3951
|
return o === "legacy_unknown" ? Ha : o === "unreviewed" ? Ua : 0;
|
|
3952
3952
|
}
|
|
3953
|
-
function
|
|
3953
|
+
function Lo(e) {
|
|
3954
3954
|
let t = e.trim().replaceAll("\\", "/");
|
|
3955
3955
|
t.startsWith("./") && (t = t.slice(2));
|
|
3956
3956
|
let n = t.split("/").filter((e) => e && e !== ".");
|
|
3957
3957
|
return n.length === 0 ? "" : n.join("/").toLowerCase();
|
|
3958
3958
|
}
|
|
3959
|
-
function
|
|
3960
|
-
let t =
|
|
3959
|
+
function Ro(e) {
|
|
3960
|
+
let t = Lo(e);
|
|
3961
3961
|
return t ? t.split("/") : [];
|
|
3962
3962
|
}
|
|
3963
|
-
function
|
|
3964
|
-
let t =
|
|
3963
|
+
function zo(e) {
|
|
3964
|
+
let t = Ro(e);
|
|
3965
3965
|
return t.length === 0 ? "" : t[t.length - 1] ?? "";
|
|
3966
3966
|
}
|
|
3967
|
-
function
|
|
3967
|
+
function Bo(e, t) {
|
|
3968
3968
|
return e.length === 0 || t.length === 0 ? !1 : e.length <= t.length ? t.slice(t.length - e.length).join("/") === e.join("/") : e.slice(e.length - t.length).join("/") === t.join("/");
|
|
3969
3969
|
}
|
|
3970
|
-
function
|
|
3970
|
+
function Vo(e) {
|
|
3971
3971
|
if (!Array.isArray(e)) return [];
|
|
3972
3972
|
let t = [], n = /* @__PURE__ */ new Set();
|
|
3973
3973
|
for (let r of e) {
|
|
3974
3974
|
if (typeof r != "string") continue;
|
|
3975
|
-
let e =
|
|
3975
|
+
let e = Lo(r);
|
|
3976
3976
|
!e || n.has(e) || (n.add(e), t.push(e));
|
|
3977
3977
|
}
|
|
3978
3978
|
return t;
|
|
3979
3979
|
}
|
|
3980
|
-
function
|
|
3980
|
+
function Ho(e) {
|
|
3981
3981
|
let t = (e.metadata ?? {}).files_modified;
|
|
3982
3982
|
if (!Array.isArray(t)) return [];
|
|
3983
3983
|
let n = [];
|
|
3984
3984
|
for (let e of t) {
|
|
3985
3985
|
if (typeof e != "string") continue;
|
|
3986
|
-
let t =
|
|
3986
|
+
let t = Lo(e);
|
|
3987
3987
|
t && n.push(t);
|
|
3988
3988
|
}
|
|
3989
3989
|
return n;
|
|
3990
3990
|
}
|
|
3991
|
-
function
|
|
3991
|
+
function Uo(e) {
|
|
3992
3992
|
let t = e.metadata ?? {}, n = [];
|
|
3993
3993
|
for (let e of ["files_modified", "files_read"]) {
|
|
3994
3994
|
let r = t[e];
|
|
3995
3995
|
if (Array.isArray(r)) for (let e of r) {
|
|
3996
3996
|
if (typeof e != "string") continue;
|
|
3997
|
-
let t =
|
|
3997
|
+
let t = Lo(e);
|
|
3998
3998
|
t && n.push(t);
|
|
3999
3999
|
}
|
|
4000
4000
|
}
|
|
4001
4001
|
return [...new Set(n)];
|
|
4002
4002
|
}
|
|
4003
|
-
function
|
|
4003
|
+
function Wo(e) {
|
|
4004
4004
|
let t = (e.match(/[A-Za-z0-9_./-]+/g) ?? []).map((e) => e.trim()).filter((e) => e.includes("/") || e.includes("."));
|
|
4005
4005
|
return [...new Set(t)];
|
|
4006
4006
|
}
|
|
4007
|
-
function
|
|
4008
|
-
let t = (e.match(/[A-Za-z0-9_./-]+/g) ?? []).map((e) => e.trim().toLowerCase()).filter((e) => e.length > 2 && !e.includes("/") && !e.includes(".") && !
|
|
4007
|
+
function Go(e) {
|
|
4008
|
+
let t = (e.match(/[A-Za-z0-9_./-]+/g) ?? []).map((e) => e.trim().toLowerCase()).filter((e) => e.length > 2 && !e.includes("/") && !e.includes(".") && !io.has(e) && !ao.has(e)), n = [...new Set(t)];
|
|
4009
4009
|
return n.length === 1 ? n : [];
|
|
4010
4010
|
}
|
|
4011
|
-
function
|
|
4012
|
-
let n =
|
|
4011
|
+
function Ko(e, t) {
|
|
4012
|
+
let n = Wo(t).map((e) => Lo(e)).filter(Boolean);
|
|
4013
4013
|
if (n.length === 0) return 0;
|
|
4014
|
-
let r =
|
|
4014
|
+
let r = Uo(e);
|
|
4015
4015
|
if (r.length === 0) return 0;
|
|
4016
|
-
let i = r.map((e) =>
|
|
4017
|
-
for (let e of i) a.some((t) =>
|
|
4018
|
-
let s = new Set(r.map((e) =>
|
|
4016
|
+
let i = r.map((e) => Ro(e)), a = n.map((e) => Ro(e)), o = 0;
|
|
4017
|
+
for (let e of i) a.some((t) => Bo(e, t)) && (o += 1);
|
|
4018
|
+
let s = new Set(r.map((e) => zo(e)).filter(Boolean)), c = new Set(n.map((e) => zo(e)).filter(Boolean)), l = 0;
|
|
4019
4019
|
for (let e of s) c.has(e) && (l += 1);
|
|
4020
4020
|
let u = o * .18 + l * .06;
|
|
4021
4021
|
return Math.min(.18, u);
|
|
4022
4022
|
}
|
|
4023
|
-
function
|
|
4023
|
+
function qo(e, t) {
|
|
4024
4024
|
let n = { ...Gn(e.metadata_json) };
|
|
4025
4025
|
for (let t of [
|
|
4026
4026
|
"actor_id",
|
|
@@ -4062,7 +4062,7 @@ function Jo(e, t) {
|
|
|
4062
4062
|
facts: e.facts ?? null
|
|
4063
4063
|
};
|
|
4064
4064
|
}
|
|
4065
|
-
function
|
|
4065
|
+
function Jo(e, t, n, r) {
|
|
4066
4066
|
if (t.length === 0) return [];
|
|
4067
4067
|
let i = t.map(() => "?").join(", "), a = [...t], o = [`memory_items.id IN (${i})`, "memory_items.active = 1"], s = ua(n, {
|
|
4068
4068
|
actorId: e.actorId,
|
|
@@ -4074,24 +4074,24 @@ function Yo(e, t, n, r) {
|
|
|
4074
4074
|
return e.db.prepare(`SELECT memory_items.*, 0 AS score
|
|
4075
4075
|
FROM memory_items
|
|
4076
4076
|
${c}
|
|
4077
|
-
WHERE ${o.join(" AND ")}`).all(...a).map((e) =>
|
|
4077
|
+
WHERE ${o.join(" AND ")}`).all(...a).map((e) => qo(e, r));
|
|
4078
4078
|
}
|
|
4079
|
-
function
|
|
4079
|
+
function Yo(e, t) {
|
|
4080
4080
|
if (t.length === 0) return 0;
|
|
4081
|
-
let n =
|
|
4081
|
+
let n = Ho(e);
|
|
4082
4082
|
if (n.length === 0) return 0;
|
|
4083
|
-
let r = [...new Set(n)].map((e) =>
|
|
4084
|
-
for (let e of r) i.some((t) =>
|
|
4083
|
+
let r = [...new Set(n)].map((e) => Ro(e)), i = [...new Set(t)].map((e) => Ro(e)), a = new Set(n.map((e) => zo(e)).filter(Boolean)), o = new Set(t.map((e) => zo(e)).filter(Boolean)), s = 0;
|
|
4084
|
+
for (let e of r) i.some((t) => Bo(e, t)) && (s += 1);
|
|
4085
4085
|
let c = 0;
|
|
4086
4086
|
for (let e of a) o.has(e) && (c += 1);
|
|
4087
4087
|
let l = s * .16 + c * .06;
|
|
4088
4088
|
return Math.min(.32, l);
|
|
4089
4089
|
}
|
|
4090
|
-
function
|
|
4090
|
+
function Xo(e) {
|
|
4091
4091
|
return typeof e.buildOwnershipPredicate == "function" ? e.buildOwnershipPredicate() : (t) => e.memoryOwnedBySelf(t);
|
|
4092
4092
|
}
|
|
4093
|
-
function
|
|
4094
|
-
let o = a ??
|
|
4093
|
+
function Zo(e, t, n, r = "", i = /* @__PURE__ */ new Date(), a) {
|
|
4094
|
+
let o = a ?? Xo(e), s = Vo(n?.working_set_paths), c = Ea(r), l = Oo(r), u = so(t.created_at, i), d = co(t.kind), f = Mo(t, r), p = No(t, c, l), m = Yo(t, s), h = Ko(t, r), g = Do(o, t, n), _ = Io(o, t, n), v = Po(t, c), y = !l && Fo(t) ? Qa : 0, b = Number.isFinite(t.score) ? t.score : null;
|
|
4095
4095
|
return {
|
|
4096
4096
|
base_score: b,
|
|
4097
4097
|
combined_score: b == null ? null : b * 1.5 + u + d + f + p + m + h + g - _ - v - y,
|
|
@@ -4109,40 +4109,40 @@ function Qo(e, t, n, r = "", i = /* @__PURE__ */ new Date(), a) {
|
|
|
4109
4109
|
tag_overlap: 0
|
|
4110
4110
|
};
|
|
4111
4111
|
}
|
|
4112
|
-
function
|
|
4113
|
-
let a = /* @__PURE__ */ new Date(), o =
|
|
4112
|
+
function Qo(e, t, n, r, i = "") {
|
|
4113
|
+
let a = /* @__PURE__ */ new Date(), o = Xo(e), s = t.map((t) => ({
|
|
4114
4114
|
item: t,
|
|
4115
|
-
combinedScore:
|
|
4115
|
+
combinedScore: Zo(e, t, r, i, a, o).combined_score ?? -Infinity
|
|
4116
4116
|
}));
|
|
4117
4117
|
return s.sort((e, t) => t.combinedScore - e.combinedScore), s.slice(0, n).map((e) => e.item);
|
|
4118
4118
|
}
|
|
4119
|
-
function
|
|
4119
|
+
function $o(e, t, n = 10, r) {
|
|
4120
4120
|
let i = wa(t).clean_query;
|
|
4121
|
-
return
|
|
4121
|
+
return ts(e, es(e, ns(e, i, n, r), i, r), i, r);
|
|
4122
4122
|
}
|
|
4123
|
-
function
|
|
4124
|
-
if (!
|
|
4125
|
-
let i =
|
|
4126
|
-
if (a.length >=
|
|
4127
|
-
let s =
|
|
4123
|
+
function es(e, t, n, r) {
|
|
4124
|
+
if (!po(r) || !n || go(n) || _o(r)) return t;
|
|
4125
|
+
let i = Xo(e), a = t.filter((e) => i(e)), o = a[0]?.score ?? -Infinity;
|
|
4126
|
+
if (a.length >= mo(r) && o >= ho(r)) return t;
|
|
4127
|
+
let s = Eo(ns(e, n, Ka, vo(r)).filter((e) => !i(e))), c = new Set(t.map((e) => e.id)), l = [...t], u = 0;
|
|
4128
4128
|
for (let e of s) if (!c.has(e.id) && (c.add(e.id), l.push(e), u += 1, u >= Ka)) break;
|
|
4129
4129
|
return l;
|
|
4130
4130
|
}
|
|
4131
|
-
function
|
|
4131
|
+
function ts(e, t, n, r) {
|
|
4132
4132
|
let i = r?.project?.trim();
|
|
4133
|
-
if (!i || !
|
|
4133
|
+
if (!i || !yo(r) || !n || Co(n)) return t;
|
|
4134
4134
|
let a = t.filter((e) => e.metadata?.widened_from_project !== !0), o = a[0]?.score ?? -Infinity;
|
|
4135
|
-
if (a.length >=
|
|
4136
|
-
let s =
|
|
4135
|
+
if (a.length >= bo(r) && o >= xo(r)) return t;
|
|
4136
|
+
let s = So(r), c = ns(e, n, s * 4, wo(r)), l = new Set(t.map((e) => e.id)), u = cs(e, new Set(c.map((e) => e.session_id).filter((e) => !!e))), d = [];
|
|
4137
4137
|
for (let e of c) {
|
|
4138
4138
|
if (l.has(e.id)) continue;
|
|
4139
4139
|
let t = u.get(e.session_id) ?? null;
|
|
4140
4140
|
if (!(t && Li(i, t)) && (d.push(e), l.add(e.id), d.length >= s)) break;
|
|
4141
4141
|
}
|
|
4142
|
-
return d.length === 0 ? t : [...t, ...
|
|
4142
|
+
return d.length === 0 ? t : [...t, ...To(e, d)];
|
|
4143
4143
|
}
|
|
4144
|
-
function
|
|
4145
|
-
let i = Math.max(1, Math.trunc(n)), a =
|
|
4144
|
+
function ns(e, t, n = 10, r) {
|
|
4145
|
+
let i = Math.max(1, Math.trunc(n)), a = oo(t);
|
|
4146
4146
|
if (!a) return [];
|
|
4147
4147
|
let o = Math.min(Math.max(i * 4, i + 8), 200), s = [a], c = ["memory_items.active = 1", "memory_fts MATCH ?"], l = ua(r, {
|
|
4148
4148
|
actorId: e.actorId,
|
|
@@ -4162,19 +4162,19 @@ function rs(e, t, n = 10, r) {
|
|
|
4162
4162
|
LIMIT ?
|
|
4163
4163
|
`;
|
|
4164
4164
|
s.push(o);
|
|
4165
|
-
let f = e.db.prepare(d).all(...s), p = typeof r?.kind == "string" && r.kind.trim().length > 0, m = f.map((e) =>
|
|
4165
|
+
let f = e.db.prepare(d).all(...s), p = typeof r?.kind == "string" && r.kind.trim().length > 0, m = f.map((e) => qo(e, p)), h = [...Wo(t).flatMap((t) => Na(e.db, t, {
|
|
4166
4166
|
limit: o,
|
|
4167
4167
|
project: r?.project,
|
|
4168
4168
|
relation: "modified"
|
|
4169
|
-
}).map((e) => e.id)), ...
|
|
4169
|
+
}).map((e) => e.id)), ...Go(t).flatMap((t) => Pa(e.db, t, {
|
|
4170
4170
|
limit: o,
|
|
4171
4171
|
project: r?.project,
|
|
4172
4172
|
since: r?.since,
|
|
4173
4173
|
kind: r?.kind
|
|
4174
4174
|
}).map((e) => e.id))], g = new Set(m.map((e) => e.id)), _ = h.filter((e) => g.has(e) ? !1 : (g.add(e), !0));
|
|
4175
|
-
return
|
|
4175
|
+
return Qo(e, _.length > 0 ? [...m, ...Jo(e, _, r, p)] : m, i, r, t);
|
|
4176
4176
|
}
|
|
4177
|
-
function
|
|
4177
|
+
function rs(e, t, n, r = 3, i = 3, a) {
|
|
4178
4178
|
let o = null;
|
|
4179
4179
|
if (n != null) {
|
|
4180
4180
|
let t = e.get(n);
|
|
@@ -4185,7 +4185,7 @@ function is(e, t, n, r = 3, i = 3, a) {
|
|
|
4185
4185
|
});
|
|
4186
4186
|
}
|
|
4187
4187
|
if (o == null && t) {
|
|
4188
|
-
let n =
|
|
4188
|
+
let n = $o(e, t, 1, a ?? void 0);
|
|
4189
4189
|
if (n.length > 0) {
|
|
4190
4190
|
let e = n[0];
|
|
4191
4191
|
o = {
|
|
@@ -4195,10 +4195,10 @@ function is(e, t, n, r = 3, i = 3, a) {
|
|
|
4195
4195
|
};
|
|
4196
4196
|
}
|
|
4197
4197
|
}
|
|
4198
|
-
return o == null ? [] :
|
|
4198
|
+
return o == null ? [] : is(e, o, r, i, a);
|
|
4199
4199
|
}
|
|
4200
|
-
function
|
|
4201
|
-
let a = t.id, o = t.created_at, s = t.session_id, c =
|
|
4200
|
+
function is(e, t, n, r, i) {
|
|
4201
|
+
let a = t.id, o = t.created_at, s = t.session_id, c = fo(n), l = fo(r);
|
|
4202
4202
|
if (!a || !o) return [];
|
|
4203
4203
|
let u = ua(i, {
|
|
4204
4204
|
actorId: e.actorId,
|
|
@@ -4241,7 +4241,7 @@ function as(e, t, n, r, i) {
|
|
|
4241
4241
|
};
|
|
4242
4242
|
});
|
|
4243
4243
|
}
|
|
4244
|
-
function
|
|
4244
|
+
function as(e) {
|
|
4245
4245
|
let t = /* @__PURE__ */ new Set(), n = [], r = [];
|
|
4246
4246
|
for (let i of e) {
|
|
4247
4247
|
let e = Ra(i);
|
|
@@ -4256,8 +4256,8 @@ function os(e) {
|
|
|
4256
4256
|
invalid: r
|
|
4257
4257
|
};
|
|
4258
4258
|
}
|
|
4259
|
-
function
|
|
4260
|
-
let c = `${e.title} ${e.body_text} ${e.tags_text}`.toLowerCase(), l = r.filter((e) => c.includes(e)), u = t === "query" || t === "query+id_lookup" ? e.score : null, d =
|
|
4259
|
+
function os(e, t, n, r, i, a, o, s) {
|
|
4260
|
+
let c = `${e.title} ${e.body_text} ${e.tags_text}`.toLowerCase(), l = r.filter((e) => c.includes(e)), u = t === "query" || t === "query+id_lookup" ? e.score : null, d = so(e.created_at, s), f = co(e.kind), p = null;
|
|
4261
4261
|
u != null && (p = u * 1.5 + d + f);
|
|
4262
4262
|
let m = Mi({
|
|
4263
4263
|
kind: e.kind,
|
|
@@ -4299,7 +4299,7 @@ function ss(e, t, n, r, i, a, o, s) {
|
|
|
4299
4299
|
} : null
|
|
4300
4300
|
};
|
|
4301
4301
|
}
|
|
4302
|
-
function
|
|
4302
|
+
function ss(e, t, n) {
|
|
4303
4303
|
if (t.length === 0) return {
|
|
4304
4304
|
items: [],
|
|
4305
4305
|
missingNotFound: [],
|
|
@@ -4358,7 +4358,7 @@ function cs(e, t, n) {
|
|
|
4358
4358
|
missingFilterMismatch: g
|
|
4359
4359
|
};
|
|
4360
4360
|
}
|
|
4361
|
-
function
|
|
4361
|
+
function cs(e, t) {
|
|
4362
4362
|
if (t.size === 0) return /* @__PURE__ */ new Map();
|
|
4363
4363
|
let n = [...t].sort((e, t) => e - t), r = za(e.db).select({
|
|
4364
4364
|
id: U.id,
|
|
@@ -4366,8 +4366,8 @@ function ls(e, t) {
|
|
|
4366
4366
|
}).from(U).where(M(U.id, n)).all();
|
|
4367
4367
|
return new Map(r.map((e) => [e.id, e.project]));
|
|
4368
4368
|
}
|
|
4369
|
-
function
|
|
4370
|
-
let o = a?.includePackContext ?? !1, s = (t ?? "").trim(), c = s ? wa(s) : null, l = c?.clean_query ?? "", { ordered: u, invalid: d } =
|
|
4369
|
+
function ls(e, t, n, r = 10, i, a) {
|
|
4370
|
+
let o = a?.includePackContext ?? !1, s = (t ?? "").trim(), c = s ? wa(s) : null, l = c?.clean_query ?? "", { ordered: u, invalid: d } = as(n ?? []), f = [];
|
|
4371
4371
|
if (d.length > 0 && f.push({
|
|
4372
4372
|
code: "INVALID_ARGUMENT",
|
|
4373
4373
|
field: "ids",
|
|
@@ -4390,10 +4390,10 @@ function us(e, t, n, r = 10, i, a) {
|
|
|
4390
4390
|
}
|
|
4391
4391
|
};
|
|
4392
4392
|
let p = [];
|
|
4393
|
-
s && (p =
|
|
4393
|
+
s && (p = $o(e, s, Math.max(1, Math.trunc(r)), i ?? void 0));
|
|
4394
4394
|
let m = /* @__PURE__ */ new Map();
|
|
4395
4395
|
for (let e = 0; e < p.length; e++) m.set(p[e].id, e + 1);
|
|
4396
|
-
let { items: h, missingNotFound: g, missingProjectMismatch: _, missingFilterMismatch: v } =
|
|
4396
|
+
let { items: h, missingNotFound: g, missingProjectMismatch: _, missingFilterMismatch: v } = ss(e, u, i ?? {}), y = new Map(h.map((e) => [e.id, e])), b = new Set(u), x = /* @__PURE__ */ new Set(), S = [];
|
|
4397
4397
|
for (let e of p) {
|
|
4398
4398
|
x.add(e.id);
|
|
4399
4399
|
let t = b.has(e.id) ? "query+id_lookup" : "query";
|
|
@@ -4412,7 +4412,7 @@ function us(e, t, n, r = 10, i, a) {
|
|
|
4412
4412
|
rank: null
|
|
4413
4413
|
}), x.add(e));
|
|
4414
4414
|
}
|
|
4415
|
-
let C = l ? (l.match(/[A-Za-z0-9_]+/g) ?? []).map((e) => e.toLowerCase()) : [], w =
|
|
4415
|
+
let C = l ? (l.match(/[A-Za-z0-9_]+/g) ?? []).map((e) => e.toLowerCase()) : [], w = cs(e, new Set(S.map(({ item: e }) => e.session_id).filter((e) => e > 0))), ee = /* @__PURE__ */ new Date(), te = S.map(({ item: e, source: t, rank: n }) => os(e, t, n, C, i?.project ?? null, w.get(e.session_id) ?? null, o, ee)), ne = u.filter((e) => !x.has(e));
|
|
4416
4416
|
return g.length > 0 && f.push({
|
|
4417
4417
|
code: "NOT_FOUND",
|
|
4418
4418
|
field: "ids",
|
|
@@ -4444,10 +4444,10 @@ function us(e, t, n, r = 10, i, a) {
|
|
|
4444
4444
|
}
|
|
4445
4445
|
//#endregion
|
|
4446
4446
|
//#region src/embeddings.ts
|
|
4447
|
-
function
|
|
4447
|
+
function us(e) {
|
|
4448
4448
|
return u("sha256").update(e, "utf-8").digest("hex");
|
|
4449
4449
|
}
|
|
4450
|
-
function
|
|
4450
|
+
function ds(e, t = 1200) {
|
|
4451
4451
|
let n = e.trim();
|
|
4452
4452
|
if (!n) return [];
|
|
4453
4453
|
if (n.length <= t) return [n];
|
|
@@ -4478,29 +4478,29 @@ function fs(e, t = 1200) {
|
|
|
4478
4478
|
}
|
|
4479
4479
|
return a.length > 0 && i.push(a.join("\n\n")), i;
|
|
4480
4480
|
}
|
|
4481
|
-
var
|
|
4482
|
-
function
|
|
4483
|
-
|
|
4481
|
+
var fs;
|
|
4482
|
+
function ps() {
|
|
4483
|
+
fs = void 0;
|
|
4484
4484
|
}
|
|
4485
|
-
function
|
|
4485
|
+
function ms() {
|
|
4486
4486
|
return process.env.CODEMEM_EMBEDDING_MODEL || "Xenova/bge-small-en-v1.5";
|
|
4487
4487
|
}
|
|
4488
|
-
async function
|
|
4489
|
-
if (
|
|
4490
|
-
if (zn()) return
|
|
4491
|
-
let e =
|
|
4488
|
+
async function hs() {
|
|
4489
|
+
if (fs !== void 0) return fs;
|
|
4490
|
+
if (zn()) return fs = null, null;
|
|
4491
|
+
let e = ms();
|
|
4492
4492
|
try {
|
|
4493
|
-
|
|
4493
|
+
fs = await _s(e);
|
|
4494
4494
|
} catch {
|
|
4495
|
-
|
|
4495
|
+
fs = null;
|
|
4496
4496
|
}
|
|
4497
|
-
return
|
|
4497
|
+
return fs;
|
|
4498
4498
|
}
|
|
4499
|
-
async function
|
|
4500
|
-
let t = await
|
|
4499
|
+
async function gs(e) {
|
|
4500
|
+
let t = await hs();
|
|
4501
4501
|
return t ? t.embed(e) : [];
|
|
4502
4502
|
}
|
|
4503
|
-
async function
|
|
4503
|
+
async function _s(e) {
|
|
4504
4504
|
let { pipeline: t } = await import("@xenova/transformers"), n = await t("feature-extraction", e, { quantized: !1 });
|
|
4505
4505
|
return {
|
|
4506
4506
|
model: e,
|
|
@@ -4521,25 +4521,25 @@ async function vs(e) {
|
|
|
4521
4521
|
}
|
|
4522
4522
|
};
|
|
4523
4523
|
}
|
|
4524
|
-
function
|
|
4524
|
+
function vs(e) {
|
|
4525
4525
|
let t = Buffer.alloc(e.length * 4);
|
|
4526
4526
|
for (let n = 0; n < e.length; n++) t.writeFloatLE(e[n] ?? 0, n * 4);
|
|
4527
4527
|
return t;
|
|
4528
4528
|
}
|
|
4529
4529
|
//#endregion
|
|
4530
4530
|
//#region src/vectors.ts
|
|
4531
|
-
var
|
|
4532
|
-
function
|
|
4531
|
+
var ys = "vector_model_migration";
|
|
4532
|
+
function bs(e) {
|
|
4533
4533
|
return {
|
|
4534
4534
|
actorId: e?.actorId ?? "",
|
|
4535
4535
|
deviceId: e?.deviceId ?? "",
|
|
4536
4536
|
enforceScopeVisibility: !0
|
|
4537
4537
|
};
|
|
4538
4538
|
}
|
|
4539
|
-
function
|
|
4539
|
+
function xs(e) {
|
|
4540
4540
|
return e === Infinity ? 200 : Number.isFinite(e) ? Math.min(Math.max(1, Math.trunc(e)), 200) : 1;
|
|
4541
4541
|
}
|
|
4542
|
-
function
|
|
4542
|
+
function Ss(e) {
|
|
4543
4543
|
if (!X(e, "memory_vectors")) return [];
|
|
4544
4544
|
try {
|
|
4545
4545
|
return e.prepare("SELECT model, COUNT(*) AS rows FROM memory_vectors GROUP BY model ORDER BY rows DESC, model ASC").all();
|
|
@@ -4547,48 +4547,48 @@ function Cs(e) {
|
|
|
4547
4547
|
return [];
|
|
4548
4548
|
}
|
|
4549
4549
|
}
|
|
4550
|
-
function
|
|
4551
|
-
let n = Q(e,
|
|
4550
|
+
function Cs(e, t = ms()) {
|
|
4551
|
+
let n = Q(e, ys), r = n?.metadata ?? {}, i = typeof r.source_model == "string" ? r.source_model : null;
|
|
4552
4552
|
if ((n?.status === "running" || n?.status === "pending" || n?.status === "failed") && i && i !== t) return null;
|
|
4553
|
-
let a =
|
|
4553
|
+
let a = Ss(e);
|
|
4554
4554
|
return a.length === 0 ? null : a.some((e) => e.model === t) ? t : null;
|
|
4555
4555
|
}
|
|
4556
|
-
function
|
|
4557
|
-
return
|
|
4556
|
+
function ws(e) {
|
|
4557
|
+
return ds(e).map((e) => us(e));
|
|
4558
4558
|
}
|
|
4559
|
-
function
|
|
4559
|
+
function Ts(e, t) {
|
|
4560
4560
|
return `${e ?? ""}\n${t ?? ""}`.trim();
|
|
4561
4561
|
}
|
|
4562
|
-
function
|
|
4563
|
-
let r = Ts(
|
|
4562
|
+
function Es(e, t, n) {
|
|
4563
|
+
let r = ws(Ts(t.title, t.body_text));
|
|
4564
4564
|
if (r.length === 0) return !0;
|
|
4565
4565
|
let i = e.prepare("SELECT content_hash FROM memory_vectors WHERE memory_id = ? AND model = ?").all(t.id, n), a = new Set(i.map((e) => e.content_hash).filter((e) => e != null));
|
|
4566
4566
|
return r.every((e) => a.has(e));
|
|
4567
4567
|
}
|
|
4568
|
-
function
|
|
4568
|
+
function Ds(e) {
|
|
4569
4569
|
return `'${e.replaceAll("'", "''")}'`;
|
|
4570
4570
|
}
|
|
4571
|
-
function
|
|
4572
|
-
return `vec_f32(${
|
|
4571
|
+
function Os(e) {
|
|
4572
|
+
return `vec_f32(${Ds(JSON.stringify(Array.from(e)))})`;
|
|
4573
4573
|
}
|
|
4574
|
-
function
|
|
4574
|
+
function ks(e) {
|
|
4575
4575
|
if (!Number.isFinite(e)) throw TypeError(`Expected finite integer, received ${String(e)}`);
|
|
4576
4576
|
if (!Number.isInteger(e)) throw TypeError(`Expected integer, received ${String(e)}`);
|
|
4577
4577
|
return String(e);
|
|
4578
4578
|
}
|
|
4579
|
-
function
|
|
4579
|
+
function As(e, t, n, r, i, a) {
|
|
4580
4580
|
e.exec(`
|
|
4581
4581
|
INSERT INTO memory_vectors(embedding, memory_id, chunk_index, content_hash, model)
|
|
4582
4582
|
VALUES (
|
|
4583
|
-
${
|
|
4584
|
-
${
|
|
4585
|
-
${
|
|
4586
|
-
${
|
|
4587
|
-
${
|
|
4583
|
+
${Os(t)},
|
|
4584
|
+
${ks(n)},
|
|
4585
|
+
${ks(r)},
|
|
4586
|
+
${Ds(i)},
|
|
4587
|
+
${Ds(a)}
|
|
4588
4588
|
)
|
|
4589
4589
|
`);
|
|
4590
4590
|
}
|
|
4591
|
-
function
|
|
4591
|
+
function js(e, t) {
|
|
4592
4592
|
if (process.env.CODEMEM_TRACE_SEMANTIC_DIAGNOSTICS !== "1") return t();
|
|
4593
4593
|
let n = Date.now();
|
|
4594
4594
|
console.warn(`[codemem semantic] ${e} start`);
|
|
@@ -4598,54 +4598,54 @@ function Ms(e, t) {
|
|
|
4598
4598
|
console.warn(`[codemem semantic] ${e} ${Date.now() - n}ms`);
|
|
4599
4599
|
}
|
|
4600
4600
|
}
|
|
4601
|
-
function
|
|
4601
|
+
function Ms(e) {
|
|
4602
4602
|
let t = e.prepare("SELECT COUNT(*) AS c\n FROM memory_items\n WHERE active = 1\n AND TRIM(COALESCE(title, '') || COALESCE(body_text, '')) != ''").get();
|
|
4603
4603
|
return Number(t?.c ?? 0);
|
|
4604
4604
|
}
|
|
4605
|
-
function
|
|
4605
|
+
function Ns(e) {
|
|
4606
4606
|
if (!(e instanceof Error)) return !1;
|
|
4607
4607
|
let t = e.message ?? "";
|
|
4608
4608
|
return /no such module:\s*vec0/i.test(t);
|
|
4609
4609
|
}
|
|
4610
|
-
function
|
|
4610
|
+
function Ps(e, t) {
|
|
4611
4611
|
if (zn() || !X(e, "memory_vectors")) return 0;
|
|
4612
4612
|
let n;
|
|
4613
4613
|
try {
|
|
4614
4614
|
n = e.prepare("SELECT id, title, body_text\n FROM memory_items\n WHERE active = 1\n AND TRIM(COALESCE(title, '') || COALESCE(body_text, '')) != ''\n ORDER BY id ASC").all();
|
|
4615
4615
|
} catch (e) {
|
|
4616
|
-
if (
|
|
4616
|
+
if (Ns(e)) return 0;
|
|
4617
4617
|
throw e;
|
|
4618
4618
|
}
|
|
4619
4619
|
try {
|
|
4620
|
-
return n.filter((n) =>
|
|
4620
|
+
return n.filter((n) => Es(e, n, t)).length;
|
|
4621
4621
|
} catch (e) {
|
|
4622
|
-
if (
|
|
4622
|
+
if (Ns(e)) return 0;
|
|
4623
4623
|
throw e;
|
|
4624
4624
|
}
|
|
4625
4625
|
}
|
|
4626
|
-
function
|
|
4626
|
+
function Fs(e, t) {
|
|
4627
4627
|
if (zn() || !X(e, "memory_vectors")) return 0;
|
|
4628
4628
|
try {
|
|
4629
4629
|
let n = e.prepare("SELECT COUNT(DISTINCT mi.id) AS c\n FROM memory_items mi\n JOIN memory_vectors mv ON mv.memory_id = mi.id\n WHERE mi.active = 1\n AND mv.model = ?\n AND TRIM(COALESCE(mi.title, '') || COALESCE(mi.body_text, '')) != ''").get(t);
|
|
4630
4630
|
return Number(n?.c ?? 0);
|
|
4631
4631
|
} catch (e) {
|
|
4632
|
-
if (
|
|
4632
|
+
if (Ns(e)) return 0;
|
|
4633
4633
|
throw e;
|
|
4634
4634
|
}
|
|
4635
4635
|
}
|
|
4636
|
-
function
|
|
4636
|
+
function Is(e, t) {
|
|
4637
4637
|
if (!(t?.status === "pending" || t?.status === "running" || t?.status === "failed")) return e;
|
|
4638
4638
|
let n = t?.metadata ?? {}, r = Number(n.embeddable_total ?? t?.progress.total ?? NaN), i = Number(n.processed_embeddable ?? t?.progress.current ?? NaN);
|
|
4639
4639
|
return Number.isFinite(r) && Number.isFinite(i) ? Math.max(r - i, 0) : e;
|
|
4640
4640
|
}
|
|
4641
|
-
function
|
|
4641
|
+
function Ls(e, t, n) {
|
|
4642
4642
|
return e === "failed" ? n?.error ?? n?.message ?? "Semantic-index catch-up failed" : e === "degraded" ? zn() ? "Embeddings are disabled; sync data is available in keyword-only mode" : "Semantic-index coverage is unavailable; sync data is effectively running in keyword-only mode" : e === "pending" ? n?.message ?? `${t.pending} memory(s) still need semantic indexing` : t.embeddable === 0 ? "No embeddable memories need semantic indexing" : `Semantic index is current for ${t.indexed} embeddable mem${t.indexed === 1 ? "ory" : "ories"}`;
|
|
4643
4643
|
}
|
|
4644
|
-
function
|
|
4645
|
-
let n = t.fastCounts !== !1, r =
|
|
4644
|
+
function Rs(e, t = {}) {
|
|
4645
|
+
let n = t.fastCounts !== !1, r = js("resolveEmbeddingModel", () => ms()), i = js("resolveSemanticSearchModel", () => Cs(e, r)), a = js("isEmbeddingDisabled", () => zn()), o = js("countEmbeddableActiveMemories", () => Ms(e)), s = js(n ? "countIndexedActiveMemoriesFast" : "countIndexedActiveMemories", () => n ? Fs(e, r) : Ps(e, r)), c = Math.max(o - s, 0), l = js("getMaintenanceJob", () => Q(e, ys)), u = Is(c, l), d = o > 0 && (a || i == null), f = l?.status === "pending" || l?.status === "running", p = l?.status === "failed" ? "failed" : f ? "pending" : d ? "degraded" : u > 0 ? "pending" : "healthy";
|
|
4646
4646
|
return {
|
|
4647
4647
|
state: p,
|
|
4648
|
-
summary:
|
|
4648
|
+
summary: Ls(p, {
|
|
4649
4649
|
embeddable: o,
|
|
4650
4650
|
indexed: s,
|
|
4651
4651
|
pending: u
|
|
@@ -4665,19 +4665,19 @@ function zs(e, t = {}) {
|
|
|
4665
4665
|
} : null
|
|
4666
4666
|
};
|
|
4667
4667
|
}
|
|
4668
|
-
function
|
|
4668
|
+
function zs(e) {
|
|
4669
4669
|
return [...new Set(e.filter((e) => Number.isInteger(e) && e > 0))];
|
|
4670
4670
|
}
|
|
4671
|
-
function
|
|
4671
|
+
function Bs(e, t) {
|
|
4672
4672
|
if (!X(e, "memory_vectors") || t.length === 0) return 0;
|
|
4673
4673
|
let n = t.map(() => "?").join(", ");
|
|
4674
4674
|
return e.prepare(`DELETE FROM memory_vectors WHERE memory_id IN (${n})`).run(...t).changes;
|
|
4675
4675
|
}
|
|
4676
|
-
function
|
|
4676
|
+
function Vs(e, t, n) {
|
|
4677
4677
|
if (t.length === 0) return 0;
|
|
4678
4678
|
let r = t.map(() => "?").join(", "), i = e.prepare(`SELECT id, title, body_text FROM memory_items WHERE id IN (${r}) ORDER BY id ASC`).all(...t), a = 0;
|
|
4679
4679
|
for (let t of i) {
|
|
4680
|
-
let r = Ts(
|
|
4680
|
+
let r = ws(Ts(t.title, t.body_text));
|
|
4681
4681
|
if (r.length === 0) {
|
|
4682
4682
|
a += e.prepare("DELETE FROM memory_vectors WHERE memory_id = ? AND model = ?").run(t.id, n).changes;
|
|
4683
4683
|
continue;
|
|
@@ -4690,49 +4690,49 @@ function Hs(e, t, n) {
|
|
|
4690
4690
|
}
|
|
4691
4691
|
return a;
|
|
4692
4692
|
}
|
|
4693
|
-
async function
|
|
4693
|
+
async function Hs(e, t) {
|
|
4694
4694
|
let n = {
|
|
4695
4695
|
deleted: 0,
|
|
4696
4696
|
inserted: 0,
|
|
4697
4697
|
errors: []
|
|
4698
|
-
}, r =
|
|
4698
|
+
}, r = zs(t.deleteMemoryIds), i = zs(t.upsertMemoryIds);
|
|
4699
4699
|
if (!X(e, "memory_vectors")) return n;
|
|
4700
4700
|
try {
|
|
4701
|
-
n.deleted +=
|
|
4701
|
+
n.deleted += Bs(e, r);
|
|
4702
4702
|
} catch (e) {
|
|
4703
4703
|
n.errors.push(`delete vectors failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
4704
4704
|
}
|
|
4705
4705
|
if (i.length === 0) return n;
|
|
4706
4706
|
try {
|
|
4707
|
-
let t = await
|
|
4708
|
-
n.inserted = t.inserted, t.checked > 0 && (n.deleted +=
|
|
4707
|
+
let t = await Ws(e, { memoryIds: i });
|
|
4708
|
+
n.inserted = t.inserted, t.checked > 0 && (n.deleted += Vs(e, i, ms()));
|
|
4709
4709
|
} catch (e) {
|
|
4710
4710
|
n.errors.push(`backfill vectors failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
4711
4711
|
}
|
|
4712
4712
|
return n;
|
|
4713
4713
|
}
|
|
4714
|
-
async function
|
|
4715
|
-
let i = await
|
|
4714
|
+
async function Us(e, t, n, r) {
|
|
4715
|
+
let i = await hs();
|
|
4716
4716
|
if (!i) return;
|
|
4717
|
-
let a =
|
|
4717
|
+
let a = ds(`${n}\n${r}`.trim());
|
|
4718
4718
|
if (a.length === 0) return;
|
|
4719
|
-
let o = await
|
|
4719
|
+
let o = await gs(a);
|
|
4720
4720
|
if (o.length === 0) return;
|
|
4721
4721
|
let s = i.model, c = e.transaction((n) => {
|
|
4722
|
-
for (let r of n)
|
|
4722
|
+
for (let r of n) As(e, r.vector, t, r.chunkIndex, r.contentHash, s);
|
|
4723
4723
|
}), l = [];
|
|
4724
4724
|
for (let e = 0; e < a.length && e < o.length; e++) {
|
|
4725
4725
|
let t = o[e], n = a[e];
|
|
4726
4726
|
!t || t.length === 0 || n && l.push({
|
|
4727
4727
|
vector: t,
|
|
4728
4728
|
chunkIndex: e,
|
|
4729
|
-
contentHash:
|
|
4729
|
+
contentHash: us(n)
|
|
4730
4730
|
});
|
|
4731
4731
|
}
|
|
4732
4732
|
l.length > 0 && c(l);
|
|
4733
4733
|
}
|
|
4734
|
-
async function
|
|
4735
|
-
let n = await
|
|
4734
|
+
async function Ws(e, t = {}) {
|
|
4735
|
+
let n = await hs();
|
|
4736
4736
|
if (!n) return {
|
|
4737
4737
|
checked: 0,
|
|
4738
4738
|
embedded: 0,
|
|
@@ -4757,11 +4757,11 @@ async function Gs(e, t = {}) {
|
|
|
4757
4757
|
for (let t of h) {
|
|
4758
4758
|
if (l?.aborted) break;
|
|
4759
4759
|
_++;
|
|
4760
|
-
let n =
|
|
4760
|
+
let n = ds(Ts(t.title, t.body_text));
|
|
4761
4761
|
if (n.length === 0) continue;
|
|
4762
4762
|
let r = e.prepare("SELECT content_hash FROM memory_vectors WHERE memory_id = ? AND model = ?").all(t.id, g), i = new Set(r.map((e) => e.content_hash).filter((e) => e != null)), a = [], o = [], c = [];
|
|
4763
4763
|
for (let [e, t] of n.entries()) {
|
|
4764
|
-
let n =
|
|
4764
|
+
let n = us(t);
|
|
4765
4765
|
if (i.has(n)) {
|
|
4766
4766
|
b++;
|
|
4767
4767
|
continue;
|
|
@@ -4769,14 +4769,14 @@ async function Gs(e, t = {}) {
|
|
|
4769
4769
|
a.push(t), o.push(n), c.push(e);
|
|
4770
4770
|
}
|
|
4771
4771
|
if (a.length === 0) continue;
|
|
4772
|
-
let u = await
|
|
4772
|
+
let u = await gs(a);
|
|
4773
4773
|
if (u.length === 0) continue;
|
|
4774
4774
|
if (v += u.length, s) {
|
|
4775
4775
|
y += u.length;
|
|
4776
4776
|
continue;
|
|
4777
4777
|
}
|
|
4778
4778
|
let d = e.transaction((n) => {
|
|
4779
|
-
for (let r of n)
|
|
4779
|
+
for (let r of n) As(e, r.vector, t.id, r.chunkIndex, r.contentHash, g);
|
|
4780
4780
|
}), f = [];
|
|
4781
4781
|
for (let e = 0; e < u.length; e++) {
|
|
4782
4782
|
let t = u[e], n = o[e], r = c[e];
|
|
@@ -4795,16 +4795,16 @@ async function Gs(e, t = {}) {
|
|
|
4795
4795
|
skipped: b
|
|
4796
4796
|
};
|
|
4797
4797
|
}
|
|
4798
|
-
async function
|
|
4798
|
+
async function Gs(e, t, n, r, i) {
|
|
4799
4799
|
if (t.trim().length < 3) return [];
|
|
4800
|
-
let a =
|
|
4800
|
+
let a = Cs(e, ms());
|
|
4801
4801
|
if (!a) return [];
|
|
4802
4802
|
if (!i?.deviceId?.trim()) throw Error("semantic_search_scope_context_required");
|
|
4803
|
-
let o = await
|
|
4803
|
+
let o = await gs([t]);
|
|
4804
4804
|
if (o.length === 0) return [];
|
|
4805
4805
|
let s = o[0];
|
|
4806
4806
|
if (!s) return [];
|
|
4807
|
-
let c =
|
|
4807
|
+
let c = vs(s), l = xs(n), u = ["memory_items.active = 1"], d = ua(r, bs(i));
|
|
4808
4808
|
u.push(...d.clauses);
|
|
4809
4809
|
let f = u.join(" AND "), p = `
|
|
4810
4810
|
WITH scoped_vectors AS (
|
|
@@ -4844,7 +4844,7 @@ async function Ks(e, t, n, r, i) {
|
|
|
4844
4844
|
}
|
|
4845
4845
|
//#endregion
|
|
4846
4846
|
//#region src/pack.ts
|
|
4847
|
-
var
|
|
4847
|
+
var Ks = {
|
|
4848
4848
|
decision: 0,
|
|
4849
4849
|
feature: 1,
|
|
4850
4850
|
bugfix: 2,
|
|
@@ -4853,11 +4853,11 @@ var qs = {
|
|
|
4853
4853
|
discovery: 5,
|
|
4854
4854
|
exploration: 6,
|
|
4855
4855
|
note: 7
|
|
4856
|
-
},
|
|
4857
|
-
function
|
|
4856
|
+
}, qs = 365, Js = "todo todos task tasks pending follow up follow-up next resume continue backlog pick up pick-up", Ys = "session summary recap remember last time previous work", Xs = 25, Zs = 250, Qs = 200, $s = 20, ec = 160;
|
|
4857
|
+
function tc(e) {
|
|
4858
4858
|
return Math.ceil(e.length / 4);
|
|
4859
4859
|
}
|
|
4860
|
-
function
|
|
4860
|
+
function nc(e) {
|
|
4861
4861
|
if (!e) return null;
|
|
4862
4862
|
try {
|
|
4863
4863
|
let t = JSON.parse(e);
|
|
@@ -4868,8 +4868,8 @@ function rc(e) {
|
|
|
4868
4868
|
} catch {}
|
|
4869
4869
|
return null;
|
|
4870
4870
|
}
|
|
4871
|
-
var
|
|
4872
|
-
function
|
|
4871
|
+
var rc = "CODEMEM_PACK_COMPRESSION", ic = "compact";
|
|
4872
|
+
function ac(e) {
|
|
4873
4873
|
let t = e?.trim().toLowerCase();
|
|
4874
4874
|
return t ? [
|
|
4875
4875
|
"0",
|
|
@@ -4891,34 +4891,34 @@ function oc(e) {
|
|
|
4891
4891
|
"legacy"
|
|
4892
4892
|
].includes(t) ? "ids" : null : null;
|
|
4893
4893
|
}
|
|
4894
|
-
function
|
|
4895
|
-
return e ??
|
|
4894
|
+
function oc(e) {
|
|
4895
|
+
return e ?? ac(process.env[rc]) ?? ic;
|
|
4896
4896
|
}
|
|
4897
|
-
function
|
|
4897
|
+
function sc(e, t, n = {}) {
|
|
4898
4898
|
let r = t?.compressedByRepresentative.get(e.id), i = r?.size ?? 0;
|
|
4899
4899
|
return i === 0 ? "" : n.includeIds ? ` (+${i} related: ${[...r ?? []].sort((e, t) => e - t).map((e) => `[${e}]`).join(", ")})` : ` (+${i} related)`;
|
|
4900
4900
|
}
|
|
4901
|
-
function
|
|
4902
|
-
let r = `[${e.id}] (${e.kind}) ${e.title}${
|
|
4901
|
+
function cc(e, t, n = {}) {
|
|
4902
|
+
let r = `[${e.id}] (${e.kind}) ${e.title}${sc(e, t, { includeIds: n.includeRelatedIds })}`, i = e.narrative || null, a = nc(e.facts);
|
|
4903
4903
|
if (i || a) {
|
|
4904
4904
|
let e = r;
|
|
4905
4905
|
return i && (e += `\n${i}`), a && (e += `\n\n${a.map((e) => `- ${e}`).join("\n")}`), e;
|
|
4906
4906
|
}
|
|
4907
4907
|
return e.body_text ? `${r} - ${e.body_text}` : r;
|
|
4908
4908
|
}
|
|
4909
|
-
function
|
|
4909
|
+
function lc(e, t, n, r = {}) {
|
|
4910
4910
|
let i = `## ${e}`;
|
|
4911
|
-
return t.length === 0 ? `${i}\n` : [i, ...t.map((e) =>
|
|
4911
|
+
return t.length === 0 ? `${i}\n` : [i, ...t.map((e) => cc(e, n, r))].join("\n");
|
|
4912
4912
|
}
|
|
4913
|
-
var
|
|
4914
|
-
function
|
|
4915
|
-
return `[${e.id}] (${e.kind}) ${e.title}${
|
|
4913
|
+
var uc = 3, dc = "Use `memory_get` for one item, or `memory_get_observations(ids=[...])` for related IDs shown in the index.";
|
|
4914
|
+
function fc(e, t) {
|
|
4915
|
+
return `[${e.id}] (${e.kind}) ${e.title}${sc(e, t, { includeIds: !0 })}`;
|
|
4916
4916
|
}
|
|
4917
|
-
function
|
|
4918
|
-
let r = `## Index\n${e.length > 0 ? e.map((e) =>
|
|
4919
|
-
return `${r}\n\n${i.length > 0 ? `## Detail\n${i.map((e) =>
|
|
4917
|
+
function pc(e, t, n) {
|
|
4918
|
+
let r = `## Index\n${e.length > 0 ? e.map((e) => fc(e, n)).join("\n") : "(no items)"}`, i = e.filter((e) => t.has(e.id));
|
|
4919
|
+
return `${r}\n\n${i.length > 0 ? `## Detail\n${i.map((e) => cc(e, n, { includeRelatedIds: !0 })).join("\n\n")}` : "## Detail\n(no items)"}\n\n${dc}`;
|
|
4920
4920
|
}
|
|
4921
|
-
function
|
|
4921
|
+
function mc(e, t, n) {
|
|
4922
4922
|
let r = t?.duplicateIds.get(e.id), i = n?.compressedByRepresentative.get(e.id), a = {
|
|
4923
4923
|
id: e.id,
|
|
4924
4924
|
kind: e.kind,
|
|
@@ -4930,18 +4930,18 @@ function hc(e, t, n) {
|
|
|
4930
4930
|
}, o = 1 + (r?.size ?? 0) + (i?.size ?? 0);
|
|
4931
4931
|
return o > 1 && (a.support_count = o), r && r.size > 0 && (a.duplicate_ids = [...r].sort((e, t) => e - t)), i && i.size > 0 && (a.compressed_ids = [...i].sort((e, t) => e - t)), a;
|
|
4932
4932
|
}
|
|
4933
|
-
function
|
|
4933
|
+
function hc(e) {
|
|
4934
4934
|
return e.trim().toLowerCase().split(/\s+/).join(" ");
|
|
4935
4935
|
}
|
|
4936
|
-
function
|
|
4937
|
-
if (
|
|
4938
|
-
let t =
|
|
4936
|
+
function gc(e) {
|
|
4937
|
+
if ($c(e)) return null;
|
|
4938
|
+
let t = hc(e.title), n = hc(e.body_text);
|
|
4939
4939
|
return !t && !n ? null : `${e.kind.length}:${e.kind}|${t.length}:${t}|${n.length}:${n}`;
|
|
4940
4940
|
}
|
|
4941
|
-
function
|
|
4941
|
+
function _c(e, t) {
|
|
4942
4942
|
let n = [];
|
|
4943
4943
|
for (let r of e) {
|
|
4944
|
-
let e =
|
|
4944
|
+
let e = gc(r);
|
|
4945
4945
|
if (e === null) {
|
|
4946
4946
|
n.push(r);
|
|
4947
4947
|
continue;
|
|
@@ -4960,7 +4960,7 @@ function vc(e, t) {
|
|
|
4960
4960
|
}
|
|
4961
4961
|
return n;
|
|
4962
4962
|
}
|
|
4963
|
-
var
|
|
4963
|
+
var vc = new Set([
|
|
4964
4964
|
"the",
|
|
4965
4965
|
"a",
|
|
4966
4966
|
"an",
|
|
@@ -4983,13 +4983,13 @@ var yc = new Set([
|
|
|
4983
4983
|
"not",
|
|
4984
4984
|
"no"
|
|
4985
4985
|
]);
|
|
4986
|
-
function
|
|
4987
|
-
return new Set((e.toLowerCase().match(/\w+/g) ?? []).filter((e) => e.length > 2 && !
|
|
4986
|
+
function yc(e) {
|
|
4987
|
+
return new Set((e.toLowerCase().match(/\w+/g) ?? []).filter((e) => e.length > 2 && !vc.has(e)));
|
|
4988
4988
|
}
|
|
4989
|
-
function
|
|
4989
|
+
function bc(e, t) {
|
|
4990
4990
|
return [...e].filter((e) => t.has(e)).sort();
|
|
4991
4991
|
}
|
|
4992
|
-
function
|
|
4992
|
+
function xc(e) {
|
|
4993
4993
|
let t = [...e].sort((e, t) => {
|
|
4994
4994
|
if (t.confidence !== e.confidence) return t.confidence - e.confidence;
|
|
4995
4995
|
if (t.created_at !== e.created_at) return t.created_at.localeCompare(e.created_at);
|
|
@@ -4999,8 +4999,8 @@ function Sc(e) {
|
|
|
4999
4999
|
if (!t) throw Error("expected non-empty cluster");
|
|
5000
5000
|
return t;
|
|
5001
5001
|
}
|
|
5002
|
-
function
|
|
5003
|
-
return e.some((e) =>
|
|
5002
|
+
function Sc(e) {
|
|
5003
|
+
return e.some((e) => $c(e)) && e.some((e) => !$c(e)) ? "session_echo" : e.every((e) => e.kind === "bugfix") ? "recurring_failure" : e.some((e) => e.kind === "decision") ? "operational_rule" : e.some((e) => [
|
|
5004
5004
|
"change",
|
|
5005
5005
|
"feature",
|
|
5006
5006
|
"discovery",
|
|
@@ -5008,10 +5008,10 @@ function Cc(e) {
|
|
|
5008
5008
|
"decision"
|
|
5009
5009
|
].includes(e.kind)) ? "related_work" : "thematic_overlap";
|
|
5010
5010
|
}
|
|
5011
|
-
function
|
|
5011
|
+
function Cc(e, t, n) {
|
|
5012
5012
|
if (t === "task" || e.length < 2) return e;
|
|
5013
5013
|
let r = /* @__PURE__ */ new Map();
|
|
5014
|
-
for (let t of e) r.set(t.id,
|
|
5014
|
+
for (let t of e) r.set(t.id, yc(t.title));
|
|
5015
5015
|
let i = /* @__PURE__ */ new Map();
|
|
5016
5016
|
for (let t of e) i.set(t.id, t.id);
|
|
5017
5017
|
let a = (e) => {
|
|
@@ -5026,7 +5026,7 @@ function wc(e, t, n) {
|
|
|
5026
5026
|
};
|
|
5027
5027
|
for (let t = 0; t < e.length; t++) for (let n = t + 1; n < e.length; n++) {
|
|
5028
5028
|
let i = e[t], a = e[n];
|
|
5029
|
-
!i || !a ||
|
|
5029
|
+
!i || !a || bc(r.get(i.id) ?? /* @__PURE__ */ new Set(), r.get(a.id) ?? /* @__PURE__ */ new Set()).length >= 3 && o(i.id, a.id);
|
|
5030
5030
|
}
|
|
5031
5031
|
let s = /* @__PURE__ */ new Map();
|
|
5032
5032
|
for (let t of e) {
|
|
@@ -5036,59 +5036,59 @@ function wc(e, t, n) {
|
|
|
5036
5036
|
let c = /* @__PURE__ */ new Set();
|
|
5037
5037
|
for (let e of s.values()) {
|
|
5038
5038
|
if (e.length < 2) continue;
|
|
5039
|
-
let t =
|
|
5039
|
+
let t = xc(e), i = e.filter((e) => e.id !== t.id).map((e) => e.id).sort((e, t) => e - t), a = e.map((e) => r.get(e.id) ?? /* @__PURE__ */ new Set()), o = [...a[0] ?? /* @__PURE__ */ new Set()].filter((e) => a.every((t) => t.has(e))).sort();
|
|
5040
5040
|
n.compressedByRepresentative.set(t.id, new Set(i));
|
|
5041
5041
|
for (let e of i) c.add(e), n.representativeByCompressedId.set(e, t.id);
|
|
5042
5042
|
n.clusters.push({
|
|
5043
5043
|
representative_id: t.id,
|
|
5044
5044
|
compressed_ids: i,
|
|
5045
5045
|
overlap_words: o,
|
|
5046
|
-
pattern:
|
|
5046
|
+
pattern: Sc(e)
|
|
5047
5047
|
});
|
|
5048
5048
|
}
|
|
5049
5049
|
return e.filter((e) => !c.has(e.id));
|
|
5050
5050
|
}
|
|
5051
|
-
function
|
|
5051
|
+
function wc(e, t) {
|
|
5052
5052
|
let n = new Set((t.toLowerCase().match(/[a-z0-9_]+/g) ?? []).filter(Boolean));
|
|
5053
5053
|
return n.size === 0 ? e : [...e].sort((e, t) => {
|
|
5054
|
-
let r =
|
|
5054
|
+
let r = Tc(e.tags_text, n), i = Tc(t.tags_text, n);
|
|
5055
5055
|
return i === r ? (t.created_at ?? "").localeCompare(e.created_at ?? "") : i - r;
|
|
5056
5056
|
});
|
|
5057
5057
|
}
|
|
5058
|
-
function
|
|
5058
|
+
function Tc(e, t) {
|
|
5059
5059
|
let n = new Set(e.split(/\s+/).filter(Boolean)), r = 0;
|
|
5060
5060
|
for (let e of t) n.has(e) && r++;
|
|
5061
5061
|
return r;
|
|
5062
5062
|
}
|
|
5063
|
-
function
|
|
5063
|
+
function Ec(e) {
|
|
5064
5064
|
let t = e.trim().replace(/\s+/g, " ");
|
|
5065
|
-
return t.length <=
|
|
5065
|
+
return t.length <= ec ? t : `${t.slice(0, ec - 1).trimEnd()}…`;
|
|
5066
5066
|
}
|
|
5067
|
-
function
|
|
5067
|
+
function Dc(e, t, n) {
|
|
5068
5068
|
let r = [];
|
|
5069
5069
|
return t === "task" ? r.push("query matched task hints") : t === "recall" ? r.push("query matched recap or recall hints") : r.push("using default retrieval mode"), (n?.working_set_paths?.length ?? 0) > 0 && r.push("working set present"), r;
|
|
5070
5070
|
}
|
|
5071
|
-
function
|
|
5071
|
+
function Oc(e) {
|
|
5072
5072
|
return [...e.duplicateIds.values()].flatMap((e) => [...e]).sort((e, t) => e - t);
|
|
5073
5073
|
}
|
|
5074
|
-
function
|
|
5074
|
+
function kc(e) {
|
|
5075
5075
|
return [...e.compressedByRepresentative.values()].flatMap((e) => [...e]).sort((e, t) => e - t);
|
|
5076
5076
|
}
|
|
5077
|
-
function
|
|
5077
|
+
function Ac(e) {
|
|
5078
5078
|
return [...e.duplicateIds.entries()].map(([e, t]) => ({
|
|
5079
5079
|
kept: e,
|
|
5080
5080
|
dropped: [...t].sort((e, t) => e - t),
|
|
5081
5081
|
support_count: 1 + t.size
|
|
5082
5082
|
})).sort((e, t) => e.kept - t.kept);
|
|
5083
5083
|
}
|
|
5084
|
-
function
|
|
5084
|
+
function jc(e, t) {
|
|
5085
5085
|
return t.summary.includes(e) ? "summary" : t.timeline.includes(e) ? "timeline" : t.observations.includes(e) ? "observations" : null;
|
|
5086
5086
|
}
|
|
5087
|
-
function
|
|
5087
|
+
function Mc(e, t, n, r) {
|
|
5088
5088
|
let i = [];
|
|
5089
|
-
return (t.text_overlap ?? 0) > 0 && i.push("matched query terms"), (t.tag_overlap ?? 0) > 0 && i.push("matched tag overlap"), (t.working_set_overlap ?? 0) > 0 && i.push("working-set overlap"), (t.query_path_overlap ?? 0) > 0 && i.push("matched file path hints"),
|
|
5089
|
+
return (t.text_overlap ?? 0) > 0 && i.push("matched query terms"), (t.tag_overlap ?? 0) > 0 && i.push("matched tag overlap"), (t.working_set_overlap ?? 0) > 0 && i.push("working-set overlap"), (t.query_path_overlap ?? 0) > 0 && i.push("matched file path hints"), $c(e) && i.push("summary-like memory"), n && i.push(`selected for ${n}`), r === "deduped" && i.push("removed by exact dedupe"), r === "compressed" && i.push("compressed into a related representative item"), r === "trimmed" && i.push("trimmed by token budget"), r === "dropped" && i.push("not selected for final pack"), i.length > 0 ? i : ["included in retrieval pool"];
|
|
5090
5090
|
}
|
|
5091
|
-
function
|
|
5091
|
+
function Nc(e) {
|
|
5092
5092
|
return e.map((e) => {
|
|
5093
5093
|
let t = {};
|
|
5094
5094
|
if (e.metadata_json) try {
|
|
@@ -5112,18 +5112,18 @@ function Pc(e) {
|
|
|
5112
5112
|
};
|
|
5113
5113
|
});
|
|
5114
5114
|
}
|
|
5115
|
-
function
|
|
5115
|
+
function Pc(e) {
|
|
5116
5116
|
let t = new Set(/* @__PURE__ */ "a.about.an.and.catch.continue.did.do.for.happened.how.i.last.me.next.on.previous.recall.recap.remember.remind.session.summarize.summary.the.time.up.we.what.where.work.worked.working".split("."));
|
|
5117
5117
|
return new Set((e.toLowerCase().match(/[a-z0-9_]+/g) ?? []).filter((e) => e.length > 2 && !t.has(e)));
|
|
5118
5118
|
}
|
|
5119
|
-
function
|
|
5120
|
-
let n =
|
|
5119
|
+
function Fc(e, t) {
|
|
5120
|
+
let n = Pc(t);
|
|
5121
5121
|
if (n.size === 0) return 0;
|
|
5122
5122
|
let r = `${e.title} ${e.body_text} ${e.tags_text}`.toLowerCase(), i = 0;
|
|
5123
5123
|
for (let e of n) r.includes(e) && (i += 1);
|
|
5124
5124
|
return i;
|
|
5125
5125
|
}
|
|
5126
|
-
function
|
|
5126
|
+
function Ic(e) {
|
|
5127
5127
|
let t = `${e.title} ${e.body_text}`.toLowerCase();
|
|
5128
5128
|
for (let e of [
|
|
5129
5129
|
"task:",
|
|
@@ -5136,7 +5136,7 @@ function Lc(e) {
|
|
|
5136
5136
|
]) if (t.includes(e)) return !0;
|
|
5137
5137
|
return !1;
|
|
5138
5138
|
}
|
|
5139
|
-
function
|
|
5139
|
+
function Lc(e) {
|
|
5140
5140
|
let t = e.toLowerCase();
|
|
5141
5141
|
for (let e of [
|
|
5142
5142
|
"todo",
|
|
@@ -5163,7 +5163,7 @@ function Rc(e) {
|
|
|
5163
5163
|
]) if (t.includes(e)) return !0;
|
|
5164
5164
|
return !1;
|
|
5165
5165
|
}
|
|
5166
|
-
function
|
|
5166
|
+
function Rc(e) {
|
|
5167
5167
|
let t = e.toLowerCase();
|
|
5168
5168
|
for (let e of [
|
|
5169
5169
|
"remember",
|
|
@@ -5187,7 +5187,7 @@ function zc(e) {
|
|
|
5187
5187
|
]) if (t.includes(e)) return !0;
|
|
5188
5188
|
return !1;
|
|
5189
5189
|
}
|
|
5190
|
-
function
|
|
5190
|
+
function zc(e) {
|
|
5191
5191
|
let t = e.toLowerCase();
|
|
5192
5192
|
for (let e of [
|
|
5193
5193
|
"what did we do",
|
|
@@ -5203,22 +5203,22 @@ function Bc(e) {
|
|
|
5203
5203
|
]) if (t.includes(e)) return !0;
|
|
5204
5204
|
return !1;
|
|
5205
5205
|
}
|
|
5206
|
-
function
|
|
5206
|
+
function Bc(e, t, n) {
|
|
5207
5207
|
let r = Ea(n), i = [...e];
|
|
5208
5208
|
return i.sort((e, t) => {
|
|
5209
5209
|
if (!r) {
|
|
5210
5210
|
let n = Number(Da(e)) - Number(Da(t));
|
|
5211
5211
|
if (n !== 0) return n;
|
|
5212
|
-
let r = Number(
|
|
5212
|
+
let r = Number(Ic(e)) - Number(Ic(t));
|
|
5213
5213
|
if (r !== 0) return r;
|
|
5214
5214
|
let i = (e) => e.kind === "decision" ? 0 : e.kind === "bugfix" ? 1 : e.kind === "discovery" ? 2 : e.kind === "refactor" ? 3 : e.kind === "feature" ? 4 : e.kind === "exploration" ? 5 : e.kind === "note" ? 6 : e.kind === "observation" ? 7 : e.kind === "change" ? 8 : e.kind === "entities" ? 9 : 10, a = i(e) - i(t);
|
|
5215
5215
|
if (a !== 0) return a;
|
|
5216
5216
|
}
|
|
5217
|
-
let i =
|
|
5217
|
+
let i = Fc(t, n) - Fc(e, n);
|
|
5218
5218
|
return i === 0 ? 0 : i;
|
|
5219
5219
|
}), i.slice(0, t);
|
|
5220
5220
|
}
|
|
5221
|
-
function
|
|
5221
|
+
function Vc(e) {
|
|
5222
5222
|
return {
|
|
5223
5223
|
id: e.id,
|
|
5224
5224
|
kind: Oi(e.kind, e.metadata_json),
|
|
@@ -5235,65 +5235,65 @@ function Hc(e) {
|
|
|
5235
5235
|
facts: e.facts ?? null
|
|
5236
5236
|
};
|
|
5237
5237
|
}
|
|
5238
|
-
function
|
|
5238
|
+
function Hc(e) {
|
|
5239
5239
|
let t = Date.parse(e);
|
|
5240
5240
|
return Number.isNaN(t) ? -Infinity : t;
|
|
5241
5241
|
}
|
|
5242
|
-
function
|
|
5242
|
+
function Uc(e, t) {
|
|
5243
5243
|
let n = Date.now() - t * 864e5;
|
|
5244
|
-
return e.filter((e) =>
|
|
5244
|
+
return e.filter((e) => Hc(e.created_at) >= n);
|
|
5245
5245
|
}
|
|
5246
|
-
function
|
|
5246
|
+
function Wc(e, t, n = "") {
|
|
5247
5247
|
let r = [...e].sort((e, t) => (t.created_at ?? "").localeCompare(e.created_at ?? ""));
|
|
5248
5248
|
return r.sort((e, t) => {
|
|
5249
|
-
let r =
|
|
5249
|
+
let r = Fc(t, n) - Fc(e, n);
|
|
5250
5250
|
if (r !== 0) return r;
|
|
5251
|
-
let i = Number(
|
|
5251
|
+
let i = Number(Ic(t)) - Number(Ic(e));
|
|
5252
5252
|
if (i !== 0) return i;
|
|
5253
5253
|
let a = (e) => e === "note" ? 0 : e === "decision" ? 1 : e === "observation" ? 2 : 3;
|
|
5254
5254
|
return a(e.kind) - a(t.kind);
|
|
5255
5255
|
}), r.slice(0, t);
|
|
5256
5256
|
}
|
|
5257
|
-
function
|
|
5257
|
+
function Gc(e, t, n, r) {
|
|
5258
5258
|
let i = [...e].sort((e, t) => (t.created_at ?? "").localeCompare(e.created_at ?? ""));
|
|
5259
5259
|
return i.sort((e, t) => {
|
|
5260
|
-
let i = (e) => n ?
|
|
5260
|
+
let i = (e) => n ? $c(e) ? 0 : e.kind === "decision" ? 1 : e.kind === "note" ? 2 : e.kind === "observation" ? 3 : e.kind === "entities" ? 4 : 5 : Ic(e) ? 8 : e.kind === "decision" ? 0 : e.kind === "bugfix" ? 1 : e.kind === "discovery" ? 2 : e.kind === "exploration" ? 3 : $c(e) ? 4 : e.kind === "note" ? 5 : e.kind === "observation" ? 6 : e.kind === "entities" ? 7 : 5;
|
|
5261
5261
|
if (!n) {
|
|
5262
5262
|
let n = i(e) - i(t);
|
|
5263
5263
|
if (n !== 0) return n;
|
|
5264
5264
|
let r = Number(Da(e)) - Number(Da(t));
|
|
5265
5265
|
if (r !== 0) return r;
|
|
5266
5266
|
}
|
|
5267
|
-
let a =
|
|
5267
|
+
let a = Fc(t, r) - Fc(e, r);
|
|
5268
5268
|
return a === 0 ? i(e) - i(t) : a;
|
|
5269
5269
|
}), i.slice(0, t);
|
|
5270
5270
|
}
|
|
5271
|
-
function
|
|
5271
|
+
function Kc(e, t, n) {
|
|
5272
5272
|
let r = Math.max(t * 3, t);
|
|
5273
|
-
return
|
|
5273
|
+
return Wc(e.recent(r, n ?? null).map(Vc), t);
|
|
5274
5274
|
}
|
|
5275
|
-
function
|
|
5276
|
-
let r = Math.max(t * 4, t), i = e.recent(r, n ?? null).map(
|
|
5275
|
+
function qc(e, t, n) {
|
|
5276
|
+
let r = Math.max(t * 4, t), i = e.recent(r, n ?? null).map(Vc), a = i.filter($c).slice(0, t);
|
|
5277
5277
|
if (a.length >= t) return a.slice(0, t);
|
|
5278
|
-
let o = new Set(a.map((e) => e.id)), s =
|
|
5278
|
+
let o = new Set(a.map((e) => e.id)), s = Wc(i.filter((e) => !o.has(e.id)), t - a.length);
|
|
5279
5279
|
return [...a, ...s];
|
|
5280
5280
|
}
|
|
5281
|
-
function
|
|
5281
|
+
function Jc(e) {
|
|
5282
5282
|
if (e == null || typeof e == "boolean") return null;
|
|
5283
5283
|
let t = Number(e);
|
|
5284
5284
|
if (!Number.isFinite(t)) return null;
|
|
5285
5285
|
let n = Math.trunc(t);
|
|
5286
5286
|
return n < 0 ? null : n;
|
|
5287
5287
|
}
|
|
5288
|
-
function
|
|
5288
|
+
function Yc(e) {
|
|
5289
5289
|
let t = [], n = /* @__PURE__ */ new Set();
|
|
5290
5290
|
for (let r of e) {
|
|
5291
|
-
let e =
|
|
5291
|
+
let e = Jc(r);
|
|
5292
5292
|
e == null || e <= 0 || n.has(e) || (n.add(e), t.push(e));
|
|
5293
5293
|
}
|
|
5294
5294
|
return t;
|
|
5295
5295
|
}
|
|
5296
|
-
function
|
|
5296
|
+
function Xc(e) {
|
|
5297
5297
|
if (!Array.isArray(e)) return {
|
|
5298
5298
|
ids: [],
|
|
5299
5299
|
valid: !1
|
|
@@ -5303,14 +5303,14 @@ function Zc(e) {
|
|
|
5303
5303
|
valid: !1
|
|
5304
5304
|
};
|
|
5305
5305
|
return {
|
|
5306
|
-
ids:
|
|
5306
|
+
ids: Yc(e),
|
|
5307
5307
|
valid: !0
|
|
5308
5308
|
};
|
|
5309
5309
|
}
|
|
5310
|
-
function
|
|
5310
|
+
function Zc(e) {
|
|
5311
5311
|
return Ti(e);
|
|
5312
5312
|
}
|
|
5313
|
-
function
|
|
5313
|
+
function Qc(e, t, n) {
|
|
5314
5314
|
if (t.length === 0) return null;
|
|
5315
5315
|
let r = ua(n, {
|
|
5316
5316
|
actorId: e.actorId,
|
|
@@ -5326,10 +5326,10 @@ function $c(e, t, n) {
|
|
|
5326
5326
|
].join(" AND ")}`).all(...t, ...r.params), s = new Set(o.map((e) => e.id));
|
|
5327
5327
|
return s.size === t.length ? t.filter((e) => s.has(e)) : null;
|
|
5328
5328
|
}
|
|
5329
|
-
function
|
|
5329
|
+
function $c(e) {
|
|
5330
5330
|
return Ei(e);
|
|
5331
5331
|
}
|
|
5332
|
-
function
|
|
5332
|
+
function el(e, t) {
|
|
5333
5333
|
let n = ua(t ?? null, {
|
|
5334
5334
|
actorId: e.actorId,
|
|
5335
5335
|
deviceId: e.deviceId,
|
|
@@ -5344,12 +5344,12 @@ function tl(e, t) {
|
|
|
5344
5344
|
WHERE ${r.join(" AND ")}
|
|
5345
5345
|
ORDER BY memory_items.created_at DESC, memory_items.id DESC
|
|
5346
5346
|
LIMIT 1`).get(...n.params);
|
|
5347
|
-
return a ?
|
|
5347
|
+
return a ? Vc(a) : null;
|
|
5348
5348
|
}
|
|
5349
|
-
function
|
|
5349
|
+
function tl(e, t) {
|
|
5350
5350
|
let n = t?.project ?? null, r = n ? Ni(n) : null, i = "CASE WHEN json_valid(metadata_json) = 1 THEN json_extract(metadata_json, '$.project') ELSE NULL END", a = 0;
|
|
5351
|
-
for (; a <
|
|
5352
|
-
let o = Math.min(
|
|
5351
|
+
for (; a < Zs;) {
|
|
5352
|
+
let o = Math.min(Xs, Zs - a), s = n ? e.db.prepare(`SELECT metadata_json, tokens_read
|
|
5353
5353
|
FROM usage_events
|
|
5354
5354
|
WHERE event = 'pack'
|
|
5355
5355
|
AND (${i} = ? OR ${i} = ?)
|
|
@@ -5357,17 +5357,17 @@ function nl(e, t) {
|
|
|
5357
5357
|
LIMIT ? OFFSET ?`).all(n, r ?? n, o, a) : e.db.prepare("SELECT metadata_json, tokens_read\n FROM usage_events\n WHERE event = 'pack'\n ORDER BY created_at DESC\n LIMIT ? OFFSET ?").all(o, a);
|
|
5358
5358
|
if (s.length === 0) break;
|
|
5359
5359
|
for (let i of s) {
|
|
5360
|
-
let a =
|
|
5360
|
+
let a = Zc(i.metadata_json);
|
|
5361
5361
|
if (n != null) {
|
|
5362
5362
|
let e = typeof a.project == "string" ? a.project : null;
|
|
5363
5363
|
if (e !== n && e !== r) continue;
|
|
5364
5364
|
}
|
|
5365
5365
|
if (!("pack_item_ids" in a)) continue;
|
|
5366
|
-
let { ids: o, valid: s } =
|
|
5366
|
+
let { ids: o, valid: s } = Xc(a.pack_item_ids);
|
|
5367
5367
|
if (!s) continue;
|
|
5368
|
-
let c =
|
|
5368
|
+
let c = Qc(e, o, t);
|
|
5369
5369
|
if (c == null) continue;
|
|
5370
|
-
let l =
|
|
5370
|
+
let l = Jc(a.pack_tokens) ?? Jc(i.tokens_read);
|
|
5371
5371
|
if (l != null) return {
|
|
5372
5372
|
previousPackIds: c,
|
|
5373
5373
|
previousPackTokens: l
|
|
@@ -5380,20 +5380,20 @@ function nl(e, t) {
|
|
|
5380
5380
|
previousPackTokens: null
|
|
5381
5381
|
};
|
|
5382
5382
|
}
|
|
5383
|
-
function
|
|
5383
|
+
function nl(e, t) {
|
|
5384
5384
|
if (!t) return null;
|
|
5385
5385
|
let n = Ni(t);
|
|
5386
5386
|
return e.db.prepare("SELECT id\n FROM sessions\n WHERE project = ? OR project = ?\n ORDER BY started_at DESC, id DESC\n LIMIT 1").get(t, n)?.id ?? null;
|
|
5387
5387
|
}
|
|
5388
|
-
function
|
|
5389
|
-
return
|
|
5388
|
+
function rl(e) {
|
|
5389
|
+
return Jc(Zc(e.metadata).discovery_tokens) ?? Math.max(2e3, tc(`${e.title} ${e.body_text}`.trim()));
|
|
5390
5390
|
}
|
|
5391
|
-
function
|
|
5392
|
-
let t =
|
|
5391
|
+
function il(e) {
|
|
5392
|
+
let t = Zc(e.metadata).discovery_group;
|
|
5393
5393
|
return typeof t == "string" && t.trim().length > 0 ? t.trim() : `memory:${e.id}`;
|
|
5394
5394
|
}
|
|
5395
|
-
function
|
|
5396
|
-
let t =
|
|
5395
|
+
function al(e) {
|
|
5396
|
+
let t = Zc(e.metadata), n = Jc(t.discovery_tokens);
|
|
5397
5397
|
return n != null && n > 0 ? {
|
|
5398
5398
|
tokens: n,
|
|
5399
5399
|
source: typeof t.discovery_source == "string" && t.discovery_source ? t.discovery_source : "known"
|
|
@@ -5402,34 +5402,34 @@ function ol(e) {
|
|
|
5402
5402
|
source: "unknown"
|
|
5403
5403
|
};
|
|
5404
5404
|
}
|
|
5405
|
-
function
|
|
5406
|
-
return
|
|
5405
|
+
function ol(e) {
|
|
5406
|
+
return Zc(e.metadata).discovery_source === "usage" ? "usage" : "estimate";
|
|
5407
5407
|
}
|
|
5408
|
-
function
|
|
5409
|
-
let n = (/* @__PURE__ */ new Date()).toISOString(), r =
|
|
5408
|
+
function sl(e, t) {
|
|
5409
|
+
let n = (/* @__PURE__ */ new Date()).toISOString(), r = Jc(t.pack_tokens) ?? 0, i = Jc(t.tokens_saved) ?? 0, a = nl(e, typeof t.project == "string" ? t.project : null);
|
|
5410
5410
|
try {
|
|
5411
5411
|
e.db.prepare("INSERT INTO usage_events(session_id, event, tokens_read, tokens_written, tokens_saved, created_at, metadata_json)\n VALUES (?, 'pack', ?, 0, ?, ?, ?)").run(a, r, i, n, JSON.stringify(t));
|
|
5412
5412
|
} catch {}
|
|
5413
5413
|
}
|
|
5414
|
-
function
|
|
5414
|
+
function cl(e, t, n, r, i, a) {
|
|
5415
5415
|
let o = /* @__PURE__ */ new Map();
|
|
5416
5416
|
for (let e of t) {
|
|
5417
5417
|
let t = o.get(e.id);
|
|
5418
5418
|
(!t || e.score > t.score) && o.set(e.id, e);
|
|
5419
5419
|
}
|
|
5420
|
-
let s =
|
|
5420
|
+
let s = ll(e, n, a), c = 0;
|
|
5421
5421
|
for (let e of s) {
|
|
5422
5422
|
o.has(e.id) || c++;
|
|
5423
5423
|
let t = o.get(e.id);
|
|
5424
5424
|
(!t || e.score > t.score) && o.set(e.id, e);
|
|
5425
5425
|
}
|
|
5426
5426
|
return {
|
|
5427
|
-
merged:
|
|
5427
|
+
merged: Qo(e, [...o.values()], r, a, i),
|
|
5428
5428
|
ftsCount: t.length,
|
|
5429
5429
|
semanticCount: c
|
|
5430
5430
|
};
|
|
5431
5431
|
}
|
|
5432
|
-
function
|
|
5432
|
+
function ll(e, t, n) {
|
|
5433
5433
|
if (t.length === 0) return [];
|
|
5434
5434
|
let r = /* @__PURE__ */ new Map();
|
|
5435
5435
|
for (let e of t) !Number.isSafeInteger(e.id) || e.id <= 0 || r.has(e.id) || r.set(e.id, e);
|
|
@@ -5440,8 +5440,8 @@ function ul(e, t, n) {
|
|
|
5440
5440
|
deviceId: e.deviceId,
|
|
5441
5441
|
enforceScopeVisibility: !0
|
|
5442
5442
|
}), o = a.joinSessions ? "JOIN sessions ON sessions.id = memory_items.session_id" : "", s = /* @__PURE__ */ new Map();
|
|
5443
|
-
for (let t = 0; t < i.length; t +=
|
|
5444
|
-
let n = i.slice(t, t +
|
|
5443
|
+
for (let t = 0; t < i.length; t += Qs) {
|
|
5444
|
+
let n = i.slice(t, t + Qs), c = n.map(() => "?").join(", "), l = e.db.prepare(`SELECT memory_items.*
|
|
5445
5445
|
FROM memory_items
|
|
5446
5446
|
${o}
|
|
5447
5447
|
WHERE ${[
|
|
@@ -5472,7 +5472,7 @@ function ul(e, t, n) {
|
|
|
5472
5472
|
}
|
|
5473
5473
|
return i.map((e) => s.get(e)).filter((e) => !!e);
|
|
5474
5474
|
}
|
|
5475
|
-
function
|
|
5475
|
+
function ul(e, t, n, r) {
|
|
5476
5476
|
let i = n?.working_set_paths;
|
|
5477
5477
|
if (!i || !Array.isArray(i) || i.length === 0) return t;
|
|
5478
5478
|
let a = i.filter((e) => typeof e == "string" && e.length > 0);
|
|
@@ -5483,7 +5483,7 @@ function dl(e, t, n, r) {
|
|
|
5483
5483
|
relation: "modified"
|
|
5484
5484
|
}).map((e) => e.id)).filter((e) => !o.has(e));
|
|
5485
5485
|
if (s.length === 0) return t;
|
|
5486
|
-
let c =
|
|
5486
|
+
let c = ll(e, s.map((e) => ({
|
|
5487
5487
|
id: e,
|
|
5488
5488
|
kind: "discovery",
|
|
5489
5489
|
title: "",
|
|
@@ -5500,50 +5500,50 @@ function dl(e, t, n, r) {
|
|
|
5500
5500
|
})), n);
|
|
5501
5501
|
return [...t, ...c];
|
|
5502
5502
|
}
|
|
5503
|
-
function
|
|
5504
|
-
let s = Math.max(1, Math.trunc(n)), c = wa(t), l = c.clean_query, u = !1, d = 0, f = 0, p = [], m = l, h, g =
|
|
5503
|
+
function dl(e, t, n = 10, r = null, i, a, o = { recordUsage: !0 }) {
|
|
5504
|
+
let s = Math.max(1, Math.trunc(n)), c = wa(t), l = c.clean_query, u = !1, d = 0, f = 0, p = [], m = l, h, g = Lc(l), _ = !g && Rc(l);
|
|
5505
5505
|
if (g) {
|
|
5506
|
-
let t = `${l} ${
|
|
5506
|
+
let t = `${l} ${Js}`.trim();
|
|
5507
5507
|
m = t;
|
|
5508
|
-
let n =
|
|
5508
|
+
let n = $o(e, t, s, i);
|
|
5509
5509
|
if (d = n.length, a && a.length > 0) {
|
|
5510
|
-
let r =
|
|
5510
|
+
let r = cl(e, n, a, s, t, i);
|
|
5511
5511
|
n = r.merged, f = r.semanticCount;
|
|
5512
5512
|
}
|
|
5513
|
-
if (n =
|
|
5513
|
+
if (n = ul(e, n, i, s), p = [...n], n.length === 0) u = !0, h = Kc(e, s, i);
|
|
5514
5514
|
else {
|
|
5515
|
-
let e = n.filter((e) =>
|
|
5516
|
-
h =
|
|
5515
|
+
let e = n.filter((e) => !$c(e)), t = Uc(e.length > 0 ? e : n, qs);
|
|
5516
|
+
h = Wc(t.length > 0 ? t : e.length > 0 ? e : n, s, l);
|
|
5517
5517
|
}
|
|
5518
5518
|
} else if (_) {
|
|
5519
|
-
let t = l.trim().length > 0 ? l :
|
|
5519
|
+
let t = l.trim().length > 0 ? l : Ys;
|
|
5520
5520
|
m = t;
|
|
5521
|
-
let n = Ea(t), r =
|
|
5522
|
-
if (d = c.length, !n && o && (c.length === 0 || c.every((e) =>
|
|
5523
|
-
let t =
|
|
5521
|
+
let n = Ea(t), r = zc(t), o = [...Pc(t)].join(" "), c = $o(e, t, s, i);
|
|
5522
|
+
if (d = c.length, !n && o && (c.length === 0 || c.every((e) => $c(e) || Fc(e, o) === 0))) {
|
|
5523
|
+
let t = $o(e, o, s, i);
|
|
5524
5524
|
t.length > 0 && (c = t, d = t.length, m = o);
|
|
5525
5525
|
}
|
|
5526
|
-
if (c.length === 0 && (c =
|
|
5527
|
-
let n =
|
|
5526
|
+
if (c.length === 0 && (c = $o(e, Ys, s, i).filter($c), d = c.length, m = Ys), a && a.length > 0) {
|
|
5527
|
+
let n = cl(e, c, a, s, t, i);
|
|
5528
5528
|
c = n.merged, f = n.semanticCount;
|
|
5529
5529
|
}
|
|
5530
|
-
c =
|
|
5531
|
-
let g = (n ? h[0] : h.find((e) =>
|
|
5530
|
+
c = ul(e, c, i, s), p = [...c], h = Gc(c, s, n, l), h.length === 0 && (u = !0, h = qc(e, s, i));
|
|
5531
|
+
let g = (n ? h[0] : h.find((e) => !$c(e)) ?? h[0])?.id;
|
|
5532
5532
|
if (r && g != null) {
|
|
5533
|
-
let t = Math.max(0, Math.floor(s / 2)), n =
|
|
5534
|
-
n.length > 0 && (h = n.map(
|
|
5533
|
+
let t = Math.max(0, Math.floor(s / 2)), n = rs(e, void 0, g, t, Math.max(0, s - t - 1), i ?? null);
|
|
5534
|
+
n.length > 0 && (h = n.map(Vc));
|
|
5535
5535
|
}
|
|
5536
5536
|
} else {
|
|
5537
|
-
let t =
|
|
5537
|
+
let t = $o(e, l, s, i);
|
|
5538
5538
|
if (a && a.length > 0) {
|
|
5539
|
-
let n =
|
|
5540
|
-
h =
|
|
5541
|
-
} else h =
|
|
5542
|
-
h =
|
|
5539
|
+
let n = cl(e, t, a, s, l, i);
|
|
5540
|
+
h = Bc(n.merged, s, l), d = n.ftsCount, f = n.semanticCount, p = [...n.merged];
|
|
5541
|
+
} else h = Bc(t, s, l), d = h.length, p = [...t];
|
|
5542
|
+
h = ul(e, h, i, s), h = Bc(h, s, l), h.length === 0 && (u = !0, h = e.recent(s, i ?? null).map(Vc));
|
|
5543
5543
|
}
|
|
5544
|
-
let v = (_ && !Ea(l) ? h.filter((e) => Di(e)) : h.filter(
|
|
5544
|
+
let v = (_ && !Ea(l) ? h.filter((e) => Di(e)) : h.filter($c)).slice(0, 1), y = !_ || Ea(l);
|
|
5545
5545
|
if (v.length === 0 && y) {
|
|
5546
|
-
let t =
|
|
5546
|
+
let t = el(e, i);
|
|
5547
5547
|
t && (v = [{
|
|
5548
5548
|
id: t.id,
|
|
5549
5549
|
kind: t.kind,
|
|
@@ -5560,8 +5560,8 @@ function fl(e, t, n = 10, r = null, i, a, o = { recordUsage: !0 }) {
|
|
|
5560
5560
|
facts: t.facts
|
|
5561
5561
|
}]);
|
|
5562
5562
|
}
|
|
5563
|
-
let b = h.filter((e) =>
|
|
5564
|
-
_ && C.length === 0 && (C = h.filter((e) =>
|
|
5563
|
+
let b = h.filter((e) => !$c(e)).slice(0, 3), x = new Set(b.map((e) => e.id)), S = Object.keys(Ks), C = [...h].filter((e) => !$c(e) && !x.has(e.id)).sort((e, t) => (Ks[e.kind] ?? 99) - (Ks[t.kind] ?? 99));
|
|
5564
|
+
_ && C.length === 0 && (C = h.filter((e) => !$c(e))), C.length === 0 && (C = e.recentByKinds(S, Math.max(s * 3, 10), i ?? null).map((e) => ({
|
|
5565
5565
|
id: e.id,
|
|
5566
5566
|
kind: e.kind,
|
|
5567
5567
|
title: e.title,
|
|
@@ -5575,13 +5575,13 @@ function fl(e, t, n = 10, r = null, i, a, o = { recordUsage: !0 }) {
|
|
|
5575
5575
|
metadata: e.metadata_json,
|
|
5576
5576
|
narrative: e.narrative ?? null,
|
|
5577
5577
|
facts: e.facts ?? null
|
|
5578
|
-
}))), C.length === 0 && (C = [...b]), C =
|
|
5578
|
+
}))), C.length === 0 && (C = [...b]), C = wc(C, t);
|
|
5579
5579
|
let w = {
|
|
5580
5580
|
canonicalByKey: /* @__PURE__ */ new Map(),
|
|
5581
5581
|
duplicateIds: /* @__PURE__ */ new Map()
|
|
5582
5582
|
}, ee = g ? "task" : _ ? "recall" : "default";
|
|
5583
|
-
v =
|
|
5584
|
-
let te = o.compact ?? !1, ne = o.compactDetailCount ??
|
|
5583
|
+
v = _c(v, w), b = _c(b, w), C = _c(C, w);
|
|
5584
|
+
let te = o.compact ?? !1, ne = o.compactDetailCount ?? uc, re = oc(o.compressionMode), ie = re === "ids" || re === "compact" && te, T = {
|
|
5585
5585
|
compressedByRepresentative: /* @__PURE__ */ new Map(),
|
|
5586
5586
|
representativeByCompressedId: /* @__PURE__ */ new Map(),
|
|
5587
5587
|
clusters: []
|
|
@@ -5593,9 +5593,9 @@ function fl(e, t, n = 10, r = null, i, a, o = { recordUsage: !0 }) {
|
|
|
5593
5593
|
...b,
|
|
5594
5594
|
...C
|
|
5595
5595
|
]) e.has(n.id) || (e.add(n.id), t.push(n));
|
|
5596
|
-
|
|
5596
|
+
Cc(t, ee, T);
|
|
5597
5597
|
}
|
|
5598
|
-
let ae = new Set(
|
|
5598
|
+
let ae = new Set(kc(T));
|
|
5599
5599
|
v = v.filter((e) => !ae.has(e.id)), b = b.filter((e) => !ae.has(e.id)), C = C.filter((e) => !ae.has(e.id));
|
|
5600
5600
|
let oe, E, D, se;
|
|
5601
5601
|
if (te) {
|
|
@@ -5609,9 +5609,9 @@ function fl(e, t, n = 10, r = null, i, a, o = { recordUsage: !0 }) {
|
|
|
5609
5609
|
if (r != null && r > 0) {
|
|
5610
5610
|
let e = 0, a = ne;
|
|
5611
5611
|
for (let o of t) {
|
|
5612
|
-
let t =
|
|
5612
|
+
let t = tc(fc(o, T));
|
|
5613
5613
|
if (a > 0) {
|
|
5614
|
-
let s = t +
|
|
5614
|
+
let s = t + tc(cc(o, T, { includeRelatedIds: !0 }));
|
|
5615
5615
|
if (e + s <= r) {
|
|
5616
5616
|
e += s, n.push(o), i.add(o.id), a--;
|
|
5617
5617
|
continue;
|
|
@@ -5623,36 +5623,36 @@ function fl(e, t, n = 10, r = null, i, a, o = { recordUsage: !0 }) {
|
|
|
5623
5623
|
n.push(...t);
|
|
5624
5624
|
for (let e of t.slice(0, ne)) i.add(e.id);
|
|
5625
5625
|
}
|
|
5626
|
-
se =
|
|
5626
|
+
se = pc(n, i, T), oe = [], E = n, D = [];
|
|
5627
5627
|
} else {
|
|
5628
5628
|
if (oe = v, E = b, D = C, r != null && r > 0) {
|
|
5629
5629
|
let e = 0, t = { includeRelatedIds: re === "ids" };
|
|
5630
5630
|
oe = [];
|
|
5631
5631
|
for (let n of v) {
|
|
5632
|
-
let i =
|
|
5632
|
+
let i = tc(cc(n, T, t));
|
|
5633
5633
|
if (e + i > r) break;
|
|
5634
5634
|
e += i, oe.push(n);
|
|
5635
5635
|
}
|
|
5636
5636
|
E = [];
|
|
5637
5637
|
for (let n of b) {
|
|
5638
|
-
let i =
|
|
5638
|
+
let i = tc(cc(n, T, t));
|
|
5639
5639
|
if (e + i > r) break;
|
|
5640
5640
|
e += i, E.push(n);
|
|
5641
5641
|
}
|
|
5642
5642
|
D = [];
|
|
5643
5643
|
for (let n of C) {
|
|
5644
|
-
let i =
|
|
5644
|
+
let i = tc(cc(n, T, t));
|
|
5645
5645
|
if (e + i > r) break;
|
|
5646
5646
|
e += i, D.push(n);
|
|
5647
5647
|
}
|
|
5648
5648
|
}
|
|
5649
5649
|
se = [
|
|
5650
|
-
|
|
5651
|
-
|
|
5652
|
-
|
|
5650
|
+
lc("Summary", oe, T, { includeRelatedIds: re === "ids" }),
|
|
5651
|
+
lc("Timeline", E, T, { includeRelatedIds: re === "ids" }),
|
|
5652
|
+
lc("Observations", D, T, { includeRelatedIds: re === "ids" })
|
|
5653
5653
|
].join("\n\n");
|
|
5654
5654
|
}
|
|
5655
|
-
let O =
|
|
5655
|
+
let O = tc(se), ce = /* @__PURE__ */ new Set(), le = /* @__PURE__ */ new Map();
|
|
5656
5656
|
for (let e of [
|
|
5657
5657
|
...oe,
|
|
5658
5658
|
...E,
|
|
@@ -5690,19 +5690,19 @@ function fl(e, t, n = 10, r = null, i, a, o = { recordUsage: !0 }) {
|
|
|
5690
5690
|
j.push(e.representative_id), de.delete(e.representative_id);
|
|
5691
5691
|
for (let t of e.compressed_ids) de.has(t) && (j.push(t), de.delete(t));
|
|
5692
5692
|
}
|
|
5693
|
-
let M = ue.map((e) =>
|
|
5693
|
+
let M = ue.map((e) => mc(e, w, T)), fe = new Set(j);
|
|
5694
5694
|
for (let e of M) for (let t of e.compressed_ids ?? []) fe.has(t) || (fe.add(t), j.push(t));
|
|
5695
|
-
let { previousPackIds: pe, previousPackTokens: me } =
|
|
5695
|
+
let { previousPackIds: pe, previousPackTokens: me } = tl(e, i ?? null), he = pe != null && me != null, ge = new Set(pe ?? []), _e = new Set(j), ve = he ? j.filter((e) => !ge.has(e)) : [], N = he ? (pe ?? []).filter((e) => !_e.has(e)) : [], P = he ? j.filter((e) => ge.has(e)) : [], F = he ? O - (me ?? 0) : 0, I = ue.reduce((e, t) => e + rl(t), 0), ye = /* @__PURE__ */ new Map();
|
|
5696
5696
|
for (let e of ue) {
|
|
5697
|
-
let t =
|
|
5697
|
+
let t = il(e), n = rl(e);
|
|
5698
5698
|
n > (ye.get(t) ?? 0) && ye.set(t, n);
|
|
5699
5699
|
}
|
|
5700
5700
|
let be = [...ye.values()].reduce((e, t) => e + t, 0), L = Math.max(0, be - O), R = 0, xe = 0, Se = 0, Ce = {};
|
|
5701
5701
|
for (let e of ue) {
|
|
5702
|
-
let t =
|
|
5702
|
+
let t = al(e);
|
|
5703
5703
|
t.tokens > 0 ? (R += t.tokens, xe += 1, Ce[t.source] = (Ce[t.source] ?? 0) + 1) : Se += 1;
|
|
5704
5704
|
}
|
|
5705
|
-
let we = Math.max(0, R - O), Te = R > 0 ? R / Math.max(O, 1) : null, Ee = ue.map(
|
|
5705
|
+
let we = Math.max(0, R - O), Te = R > 0 ? R / Math.max(O, 1) : null, Ee = ue.map(ol), De = Ee.filter((e) => e === "usage").length, Oe = Ee.length - De, ke = De > 0 && Oe > 0 ? "mixed" : De > 0 ? "usage" : "estimate", Ae = be > 0 ? O / be : null, je = be > 0 ? O - be : null, Me = u ? "recent" : null, z = {
|
|
5706
5706
|
total_items: M.length,
|
|
5707
5707
|
pack_tokens: O,
|
|
5708
5708
|
fallback_used: u,
|
|
@@ -5751,11 +5751,11 @@ function fl(e, t, n = 10, r = null, i, a, o = { recordUsage: !0 }) {
|
|
|
5751
5751
|
...v,
|
|
5752
5752
|
...b,
|
|
5753
5753
|
...C
|
|
5754
|
-
].map((e) => e.id).filter((e) => !Fe.has(e)).sort((e, t) => e - t), Le =
|
|
5755
|
-
let r =
|
|
5756
|
-
...
|
|
5757
|
-
text_overlap:
|
|
5758
|
-
tag_overlap:
|
|
5754
|
+
].map((e) => e.id).filter((e) => !Fe.has(e)).sort((e, t) => e - t), Le = Oc(w), B = new Set(Le), Re = kc(T), ze = new Set(Re), V = new Set(Ie), Be = /* @__PURE__ */ new Date(), Ve = p.slice(0, $s).map((t, n) => {
|
|
5755
|
+
let r = jc(t.id, Pe), a = r ? "selected" : B.has(t.id) ? "deduped" : ze.has(t.id) ? "compressed" : V.has(t.id) ? "trimmed" : "dropped", o = {
|
|
5756
|
+
...Zo(e, t, i, m, Be),
|
|
5757
|
+
text_overlap: Fc(t, m),
|
|
5758
|
+
tag_overlap: Tc(t.tags_text, Pc(m))
|
|
5759
5759
|
}, s = Mi({
|
|
5760
5760
|
kind: t.kind,
|
|
5761
5761
|
title: t.title,
|
|
@@ -5767,9 +5767,9 @@ function fl(e, t, n = 10, r = null, i, a, o = { recordUsage: !0 }) {
|
|
|
5767
5767
|
rank: n + 1,
|
|
5768
5768
|
kind: t.kind,
|
|
5769
5769
|
title: t.title,
|
|
5770
|
-
preview:
|
|
5770
|
+
preview: Ec(t.narrative || t.body_text),
|
|
5771
5771
|
scores: o,
|
|
5772
|
-
reasons:
|
|
5772
|
+
reasons: Mc(t, o, r, a),
|
|
5773
5773
|
disposition: a,
|
|
5774
5774
|
section: r,
|
|
5775
5775
|
inferred_role: s.role,
|
|
@@ -5787,7 +5787,7 @@ function fl(e, t, n = 10, r = null, i, a, o = { recordUsage: !0 }) {
|
|
|
5787
5787
|
},
|
|
5788
5788
|
mode: {
|
|
5789
5789
|
selected: ee,
|
|
5790
|
-
reasons:
|
|
5790
|
+
reasons: Dc(t, ee, i)
|
|
5791
5791
|
},
|
|
5792
5792
|
retrieval: {
|
|
5793
5793
|
candidate_count: Ve.length,
|
|
@@ -5795,7 +5795,7 @@ function fl(e, t, n = 10, r = null, i, a, o = { recordUsage: !0 }) {
|
|
|
5795
5795
|
},
|
|
5796
5796
|
assembly: {
|
|
5797
5797
|
deduped_ids: Le,
|
|
5798
|
-
collapsed_groups:
|
|
5798
|
+
collapsed_groups: Ac(w),
|
|
5799
5799
|
compressed_clusters: T.clusters,
|
|
5800
5800
|
trimmed_ids: Ie,
|
|
5801
5801
|
trim_reasons: Ie.length > 0 ? ["token budget exceeded; lower-priority items dropped after section ordering"] : [],
|
|
@@ -5812,51 +5812,51 @@ function fl(e, t, n = 10, r = null, i, a, o = { recordUsage: !0 }) {
|
|
|
5812
5812
|
pack_text: se
|
|
5813
5813
|
}
|
|
5814
5814
|
};
|
|
5815
|
-
return o.recordUsage &&
|
|
5815
|
+
return o.recordUsage && sl(e, z), {
|
|
5816
5816
|
response: Ne,
|
|
5817
5817
|
trace: He
|
|
5818
5818
|
};
|
|
5819
5819
|
}
|
|
5820
|
-
function
|
|
5821
|
-
return
|
|
5820
|
+
function fl(e, t, n = 10, r = null, i, a, o) {
|
|
5821
|
+
return dl(e, t, n, r, i, a, {
|
|
5822
5822
|
recordUsage: !0,
|
|
5823
5823
|
compact: o?.compact,
|
|
5824
5824
|
compactDetailCount: o?.compactDetailCount,
|
|
5825
5825
|
compressionMode: o?.compressionMode
|
|
5826
5826
|
}).response;
|
|
5827
5827
|
}
|
|
5828
|
-
function
|
|
5829
|
-
return
|
|
5828
|
+
function pl(e, t, n = 10, r = null, i, a, o) {
|
|
5829
|
+
return dl(e, t, n, r, i, a, {
|
|
5830
5830
|
recordUsage: !1,
|
|
5831
5831
|
compact: o?.compact,
|
|
5832
5832
|
compactDetailCount: o?.compactDetailCount,
|
|
5833
5833
|
compressionMode: o?.compressionMode
|
|
5834
5834
|
}).trace;
|
|
5835
5835
|
}
|
|
5836
|
-
async function
|
|
5836
|
+
async function ml(e, t, n = 10, r = null, i, a) {
|
|
5837
5837
|
let o = [], s = wa(t).clean_query;
|
|
5838
5838
|
try {
|
|
5839
|
-
o =
|
|
5839
|
+
o = Nc(await Gs(e.db, s, n, i ?? null, {
|
|
5840
5840
|
actorId: e.actorId,
|
|
5841
5841
|
deviceId: e.deviceId
|
|
5842
5842
|
}));
|
|
5843
5843
|
} catch {}
|
|
5844
|
-
return
|
|
5844
|
+
return dl(e, t, n, r, i, o, {
|
|
5845
5845
|
recordUsage: !0,
|
|
5846
5846
|
compact: a?.compact,
|
|
5847
5847
|
compactDetailCount: a?.compactDetailCount,
|
|
5848
5848
|
compressionMode: a?.compressionMode
|
|
5849
5849
|
}).response;
|
|
5850
5850
|
}
|
|
5851
|
-
async function
|
|
5851
|
+
async function hl(e, t, n = 10, r = null, i, a) {
|
|
5852
5852
|
let o = [], s = wa(t).clean_query;
|
|
5853
5853
|
try {
|
|
5854
|
-
o =
|
|
5854
|
+
o = Nc(await Gs(e.db, s, n, i ?? null, {
|
|
5855
5855
|
actorId: e.actorId,
|
|
5856
5856
|
deviceId: e.deviceId
|
|
5857
5857
|
}));
|
|
5858
5858
|
} catch {}
|
|
5859
|
-
return
|
|
5859
|
+
return dl(e, t, n, r, i, o, {
|
|
5860
5860
|
recordUsage: !1,
|
|
5861
5861
|
compact: a?.compact,
|
|
5862
5862
|
compactDetailCount: a?.compactDetailCount,
|
|
@@ -5865,26 +5865,26 @@ async function gl(e, t, n = 10, r = null, i, a) {
|
|
|
5865
5865
|
}
|
|
5866
5866
|
//#endregion
|
|
5867
5867
|
//#region src/memory-dedup.ts
|
|
5868
|
-
function
|
|
5868
|
+
function gl(e) {
|
|
5869
5869
|
return e.toLowerCase().replace(/\b(?:pr|pull\s+request|issue)\s*#?\d+\b/gi, " ").replace(/^\s*#\d+\s*/g, " ").replace(/^[\s\p{P}]+|[\s\p{P}]+$/gu, "").replace(/\s+/g, " ").trim();
|
|
5870
5870
|
}
|
|
5871
|
-
function
|
|
5872
|
-
let t =
|
|
5871
|
+
function _l(e) {
|
|
5872
|
+
let t = gl(e), n = e.toLowerCase().replace(/\s+/g, " ").trim(), r = t || n;
|
|
5873
5873
|
return r ? u("sha256").update(r).digest("hex") : null;
|
|
5874
5874
|
}
|
|
5875
5875
|
//#endregion
|
|
5876
5876
|
//#region src/scope-stamping.ts
|
|
5877
|
-
function
|
|
5877
|
+
function vl(e) {
|
|
5878
5878
|
return e?.trim() || null;
|
|
5879
5879
|
}
|
|
5880
|
-
function
|
|
5880
|
+
function yl(e) {
|
|
5881
5881
|
return e.prepare("SELECT id, workspace_identity, project_pattern, scope_id, priority, source, updated_at\n FROM project_scope_mappings\n WHERE scope_id IS NOT NULL AND TRIM(scope_id) != ''\n ORDER BY priority DESC, id ASC").all();
|
|
5882
5882
|
}
|
|
5883
|
-
function
|
|
5883
|
+
function bl(e, t) {
|
|
5884
5884
|
return e.prepare("SELECT cwd, project, git_remote, git_branch FROM sessions WHERE id = ? LIMIT 1").get(t) ?? null;
|
|
5885
5885
|
}
|
|
5886
|
-
function
|
|
5887
|
-
let n =
|
|
5886
|
+
function xl(e, t) {
|
|
5887
|
+
let n = bl(e, t.sessionId);
|
|
5888
5888
|
return ta({
|
|
5889
5889
|
gitRemote: n?.git_remote ?? null,
|
|
5890
5890
|
gitBranch: n?.git_branch ?? null,
|
|
@@ -5893,16 +5893,16 @@ function Sl(e, t) {
|
|
|
5893
5893
|
workspaceId: t.workspaceId ?? null,
|
|
5894
5894
|
explicitScopeId: t.explicitScopeId ?? null,
|
|
5895
5895
|
localDefaultScopeId: t.localDefaultScopeId ?? "local-default",
|
|
5896
|
-
mappings:
|
|
5896
|
+
mappings: yl(e)
|
|
5897
5897
|
}).scopeId;
|
|
5898
5898
|
}
|
|
5899
|
-
function
|
|
5899
|
+
function Sl(e, t) {
|
|
5900
5900
|
return e.prepare("SELECT\n mi.id,\n mi.session_id,\n mi.workspace_id,\n mi.scope_id,\n s.cwd,\n s.project,\n s.git_remote,\n s.git_branch\n FROM memory_items mi\n LEFT JOIN sessions s ON s.id = mi.session_id\n WHERE mi.id = ?\n LIMIT 1").get(t) ?? null;
|
|
5901
5901
|
}
|
|
5902
|
-
function
|
|
5903
|
-
let n =
|
|
5902
|
+
function Cl(e, t) {
|
|
5903
|
+
let n = Sl(e, t);
|
|
5904
5904
|
if (!n) return null;
|
|
5905
|
-
let r =
|
|
5905
|
+
let r = vl(n.scope_id);
|
|
5906
5906
|
if (r) return r;
|
|
5907
5907
|
let i = ta({
|
|
5908
5908
|
gitRemote: n.git_remote,
|
|
@@ -5911,13 +5911,13 @@ function wl(e, t) {
|
|
|
5911
5911
|
project: n.project,
|
|
5912
5912
|
workspaceId: n.workspace_id,
|
|
5913
5913
|
localDefaultScopeId: Bi,
|
|
5914
|
-
mappings:
|
|
5914
|
+
mappings: yl(e)
|
|
5915
5915
|
});
|
|
5916
5916
|
return e.prepare("UPDATE memory_items\n SET scope_id = ?\n WHERE id = ?\n AND (scope_id IS NULL OR TRIM(scope_id) = '')").run(i.scopeId, t), i.scopeId;
|
|
5917
5917
|
}
|
|
5918
5918
|
//#endregion
|
|
5919
5919
|
//#region src/secret-scanner.ts
|
|
5920
|
-
var
|
|
5920
|
+
var wl = /^(?:secret|token|password|passwd|pwd|auth|bearer|credential|api[_-]?key|access[_-]?key|client[_-]?secret|private[_-]?key|access[_-]?token|refresh[_-]?token|id[_-]?token|bearer[_-]?token|api[_-]?token)$/i, Tl = [
|
|
5921
5921
|
{
|
|
5922
5922
|
kind: "aws_access_key_id",
|
|
5923
5923
|
pattern: /\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g
|
|
@@ -5991,7 +5991,7 @@ var Tl = /^(?:secret|token|password|passwd|pwd|auth|bearer|credential|api[_-]?ke
|
|
|
5991
5991
|
redactGroup: 1
|
|
5992
5992
|
}
|
|
5993
5993
|
];
|
|
5994
|
-
function
|
|
5994
|
+
function El(e) {
|
|
5995
5995
|
if (e.length === 0) return 0;
|
|
5996
5996
|
let t = /* @__PURE__ */ new Map();
|
|
5997
5997
|
for (let n of e) t.set(n, (t.get(n) ?? 0) + 1);
|
|
@@ -6002,24 +6002,24 @@ function Dl(e) {
|
|
|
6002
6002
|
}
|
|
6003
6003
|
return n;
|
|
6004
6004
|
}
|
|
6005
|
-
function
|
|
6005
|
+
function Dl(e) {
|
|
6006
6006
|
return e.flags.includes("g") ? e : new RegExp(e.source, `${e.flags}g`);
|
|
6007
6007
|
}
|
|
6008
|
-
function
|
|
6008
|
+
function Ol(e, t) {
|
|
6009
6009
|
for (let n of t) if (typeof n == "string") {
|
|
6010
6010
|
if (n === e) return !0;
|
|
6011
6011
|
} else if ((n.global || n.sticky) && (n.lastIndex = 0), n.test(e)) return !0;
|
|
6012
6012
|
return !1;
|
|
6013
6013
|
}
|
|
6014
|
-
function
|
|
6014
|
+
function kl(e) {
|
|
6015
6015
|
let t = Object.getPrototypeOf(e);
|
|
6016
6016
|
return t === null || t === Object.prototype;
|
|
6017
6017
|
}
|
|
6018
|
-
var
|
|
6018
|
+
var Al = class {
|
|
6019
6019
|
rules;
|
|
6020
6020
|
allowlist;
|
|
6021
6021
|
constructor(e = {}) {
|
|
6022
|
-
this.rules = [...
|
|
6022
|
+
this.rules = [...Tl, ...e.rules ?? []], this.allowlist = e.allowlist ?? [];
|
|
6023
6023
|
}
|
|
6024
6024
|
scan(e) {
|
|
6025
6025
|
if (!e || typeof e != "string") return {
|
|
@@ -6028,10 +6028,10 @@ var jl = class {
|
|
|
6028
6028
|
};
|
|
6029
6029
|
let t = e, n = /* @__PURE__ */ new Map();
|
|
6030
6030
|
for (let e of this.rules) {
|
|
6031
|
-
let r =
|
|
6031
|
+
let r = Dl(e.pattern);
|
|
6032
6032
|
t = t.replace(r, (...t) => {
|
|
6033
6033
|
let r = t[0], i = e.redactGroup == null ? r : t[e.redactGroup] ?? "";
|
|
6034
|
-
if (!i ||
|
|
6034
|
+
if (!i || Ol(i, this.allowlist) || e.minEntropy != null && El(i) < e.minEntropy) return r;
|
|
6035
6035
|
n.set(e.kind, (n.get(e.kind) ?? 0) + 1);
|
|
6036
6036
|
let a = `[REDACTED:${e.kind}]`;
|
|
6037
6037
|
return e.redactGroup == null ? a : r.replace(i, a);
|
|
@@ -6051,7 +6051,7 @@ var jl = class {
|
|
|
6051
6051
|
}
|
|
6052
6052
|
redactValueInternal(e, t, n) {
|
|
6053
6053
|
if (typeof e == "string") {
|
|
6054
|
-
if (t &&
|
|
6054
|
+
if (t && wl.test(t) && this.looksLikeSecretValue(e)) return Ol(e, this.allowlist) ? {
|
|
6055
6055
|
value: e,
|
|
6056
6056
|
detections: []
|
|
6057
6057
|
} : {
|
|
@@ -6081,11 +6081,11 @@ var jl = class {
|
|
|
6081
6081
|
}
|
|
6082
6082
|
return {
|
|
6083
6083
|
value: r,
|
|
6084
|
-
detections:
|
|
6084
|
+
detections: jl(i)
|
|
6085
6085
|
};
|
|
6086
6086
|
}
|
|
6087
6087
|
if (typeof e == "object" && e) {
|
|
6088
|
-
if (n.has(e) || !
|
|
6088
|
+
if (n.has(e) || !kl(e)) return {
|
|
6089
6089
|
value: e,
|
|
6090
6090
|
detections: []
|
|
6091
6091
|
};
|
|
@@ -6098,7 +6098,7 @@ var jl = class {
|
|
|
6098
6098
|
}
|
|
6099
6099
|
return {
|
|
6100
6100
|
value: r,
|
|
6101
|
-
detections:
|
|
6101
|
+
detections: jl(i)
|
|
6102
6102
|
};
|
|
6103
6103
|
}
|
|
6104
6104
|
return {
|
|
@@ -6110,13 +6110,13 @@ var jl = class {
|
|
|
6110
6110
|
return !(e.length < 8 || /^(?:https?|ftp|file):\/\//i.test(e) || /^(?:\[REDACTED:|<.*>|\{\{.*\}\}|null|undefined)$/i.test(e.trim()));
|
|
6111
6111
|
}
|
|
6112
6112
|
};
|
|
6113
|
-
function
|
|
6113
|
+
function jl(e) {
|
|
6114
6114
|
return Array.from(e.entries()).map(([e, t]) => ({
|
|
6115
6115
|
kind: e,
|
|
6116
6116
|
count: t
|
|
6117
6117
|
}));
|
|
6118
6118
|
}
|
|
6119
|
-
function
|
|
6119
|
+
function Ml(e) {
|
|
6120
6120
|
let t = {};
|
|
6121
6121
|
if (!e || typeof e != "object") return t;
|
|
6122
6122
|
let n = e.secret_scanner;
|
|
@@ -6147,14 +6147,14 @@ function Nl(e) {
|
|
|
6147
6147
|
let e = [];
|
|
6148
6148
|
for (let t of a) {
|
|
6149
6149
|
if (typeof t != "string" || t.length === 0) continue;
|
|
6150
|
-
let n =
|
|
6150
|
+
let n = Nl(t);
|
|
6151
6151
|
e.push(n ?? t);
|
|
6152
6152
|
}
|
|
6153
6153
|
e.length > 0 && (r.allowlist = e);
|
|
6154
6154
|
}
|
|
6155
6155
|
return r;
|
|
6156
6156
|
}
|
|
6157
|
-
function
|
|
6157
|
+
function Nl(e) {
|
|
6158
6158
|
if (e.length < 2 || e[0] !== "/") return null;
|
|
6159
6159
|
let t = e.lastIndexOf("/");
|
|
6160
6160
|
if (t <= 0) return null;
|
|
@@ -6167,12 +6167,12 @@ function Pl(e) {
|
|
|
6167
6167
|
return null;
|
|
6168
6168
|
}
|
|
6169
6169
|
}
|
|
6170
|
-
function
|
|
6170
|
+
function Pl(...e) {
|
|
6171
6171
|
let t = /* @__PURE__ */ new Map();
|
|
6172
6172
|
for (let n of e) for (let e of n) t.set(e.kind, (t.get(e.kind) ?? 0) + e.count);
|
|
6173
|
-
return
|
|
6173
|
+
return jl(t);
|
|
6174
6174
|
}
|
|
6175
|
-
function
|
|
6175
|
+
function Fl(e, t) {
|
|
6176
6176
|
let n = [], r = (r) => {
|
|
6177
6177
|
let i = e[r];
|
|
6178
6178
|
if (typeof i == "string" && i.length > 0) {
|
|
@@ -6212,12 +6212,12 @@ function Il(e, t) {
|
|
|
6212
6212
|
}
|
|
6213
6213
|
return {
|
|
6214
6214
|
target: e,
|
|
6215
|
-
detections:
|
|
6215
|
+
detections: Pl(...n)
|
|
6216
6216
|
};
|
|
6217
6217
|
}
|
|
6218
6218
|
//#endregion
|
|
6219
6219
|
//#region src/address-utils.ts
|
|
6220
|
-
function
|
|
6220
|
+
function Il(e, t) {
|
|
6221
6221
|
let n = e.trim();
|
|
6222
6222
|
if (!n) return "";
|
|
6223
6223
|
let r = n.includes("://"), i = r ? n : `http://${n}`, a = /^http:\/\/(?:\[[^\]]+\]|[^/?#:]+):0*80(?:[/?#]|$)/i.test(i);
|
|
@@ -6234,13 +6234,13 @@ function Ll(e, t) {
|
|
|
6234
6234
|
return "";
|
|
6235
6235
|
}
|
|
6236
6236
|
}
|
|
6237
|
-
function
|
|
6237
|
+
function Ll(e, t) {
|
|
6238
6238
|
let n = e.trim();
|
|
6239
6239
|
if (!n) return "";
|
|
6240
6240
|
let r = Math.trunc(t);
|
|
6241
6241
|
return r <= 0 || r > 65535 ? "" : `${n.includes(":") && !n.startsWith("[") ? `[${n}]` : n}:${r}`;
|
|
6242
6242
|
}
|
|
6243
|
-
function
|
|
6243
|
+
function Rl(e) {
|
|
6244
6244
|
if (!e) return "";
|
|
6245
6245
|
try {
|
|
6246
6246
|
let t = new URL(e), n = t.hostname.toLowerCase();
|
|
@@ -6249,25 +6249,25 @@ function zl(e) {
|
|
|
6249
6249
|
} catch {}
|
|
6250
6250
|
return e;
|
|
6251
6251
|
}
|
|
6252
|
-
function
|
|
6252
|
+
function zl(e, t, n) {
|
|
6253
6253
|
let r = [], i = /* @__PURE__ */ new Set();
|
|
6254
6254
|
for (let a of [...e, ...t]) {
|
|
6255
|
-
let e =
|
|
6255
|
+
let e = Il(a, n), t = Rl(e);
|
|
6256
6256
|
!e || i.has(t) || (i.add(t), r.push(e));
|
|
6257
6257
|
}
|
|
6258
6258
|
return r;
|
|
6259
6259
|
}
|
|
6260
|
-
function
|
|
6261
|
-
return
|
|
6260
|
+
function Bl(e, t, n) {
|
|
6261
|
+
return zl(t, e, n);
|
|
6262
6262
|
}
|
|
6263
6263
|
//#endregion
|
|
6264
6264
|
//#region src/sync-http-client.ts
|
|
6265
|
-
function
|
|
6265
|
+
function Vl(e) {
|
|
6266
6266
|
let t = e.length;
|
|
6267
6267
|
for (; t > 0 && e.charCodeAt(t - 1) === 47;) t--;
|
|
6268
6268
|
return t === e.length ? e : e.slice(0, t);
|
|
6269
6269
|
}
|
|
6270
|
-
function
|
|
6270
|
+
function Hl(e) {
|
|
6271
6271
|
let t = e.indexOf("://");
|
|
6272
6272
|
if (t <= 0) return !1;
|
|
6273
6273
|
let n = e.charCodeAt(0);
|
|
@@ -6278,11 +6278,11 @@ function Ul(e) {
|
|
|
6278
6278
|
}
|
|
6279
6279
|
return !0;
|
|
6280
6280
|
}
|
|
6281
|
-
function
|
|
6282
|
-
let t =
|
|
6283
|
-
return t ?
|
|
6281
|
+
function Ul(e) {
|
|
6282
|
+
let t = Vl(e.trim());
|
|
6283
|
+
return t ? Hl(t) ? t : `http://${t}` : "";
|
|
6284
6284
|
}
|
|
6285
|
-
async function
|
|
6285
|
+
async function Wl(e, t, n = {}) {
|
|
6286
6286
|
let { headers: r, body: i, timeoutS: a = 3 } = n, { bodyBytes: o } = n;
|
|
6287
6287
|
o == null && i != null && (o = new TextEncoder().encode(JSON.stringify(i)));
|
|
6288
6288
|
let s = { Accept: "application/json" };
|
|
@@ -6305,13 +6305,13 @@ async function Gl(e, t, n = {}) {
|
|
|
6305
6305
|
}
|
|
6306
6306
|
//#endregion
|
|
6307
6307
|
//#region src/coordinator-runtime.ts
|
|
6308
|
-
function
|
|
6308
|
+
function Gl(e) {
|
|
6309
6309
|
return typeof e == "string" ? e.trim() : "";
|
|
6310
6310
|
}
|
|
6311
|
-
function
|
|
6311
|
+
function Kl(e, t) {
|
|
6312
6312
|
return typeof e == "number" && Number.isFinite(e) ? Math.trunc(e) : typeof e == "string" && /^-?\d+$/.test(e.trim()) ? Number.parseInt(e.trim(), 10) : t;
|
|
6313
6313
|
}
|
|
6314
|
-
function
|
|
6314
|
+
function ql(e, t) {
|
|
6315
6315
|
if (typeof e == "boolean") return e;
|
|
6316
6316
|
if (typeof e == "string") {
|
|
6317
6317
|
let t = e.trim().toLowerCase();
|
|
@@ -6330,10 +6330,10 @@ function Jl(e, t) {
|
|
|
6330
6330
|
}
|
|
6331
6331
|
return t;
|
|
6332
6332
|
}
|
|
6333
|
-
function
|
|
6333
|
+
function Jl(e) {
|
|
6334
6334
|
return Array.isArray(e) ? e.filter((e) => typeof e == "string").map((e) => e.trim()).filter(Boolean) : typeof e == "string" ? e.split(",").map((e) => e.trim()).filter(Boolean) : [];
|
|
6335
6335
|
}
|
|
6336
|
-
function
|
|
6336
|
+
function Yl(e, t) {
|
|
6337
6337
|
let n = [], r = /* @__PURE__ */ new Set();
|
|
6338
6338
|
for (let i of [...e, ...t]) {
|
|
6339
6339
|
let e = i.trim();
|
|
@@ -6341,21 +6341,21 @@ function Xl(e, t) {
|
|
|
6341
6341
|
}
|
|
6342
6342
|
return n;
|
|
6343
6343
|
}
|
|
6344
|
-
var
|
|
6345
|
-
function
|
|
6344
|
+
var Xl = /* @__PURE__ */ new Map(), Zl = /* @__PURE__ */ new Map(), Ql = 5e3;
|
|
6345
|
+
function $l(e, t) {
|
|
6346
6346
|
let n = [...t.syncCoordinatorGroups].sort().join(",");
|
|
6347
6347
|
return [
|
|
6348
6348
|
e.dbPath,
|
|
6349
6349
|
t.syncCoordinatorUrl,
|
|
6350
6350
|
n,
|
|
6351
|
-
|
|
6351
|
+
eu(e),
|
|
6352
6352
|
t.syncHost,
|
|
6353
6353
|
t.syncPort,
|
|
6354
6354
|
t.syncAdvertise,
|
|
6355
6355
|
t.syncCoordinatorPresenceTtlS
|
|
6356
6356
|
].join("|");
|
|
6357
6357
|
}
|
|
6358
|
-
function
|
|
6358
|
+
function eu(e) {
|
|
6359
6359
|
let t = process.env.CODEMEM_KEYS_DIR?.trim() || "";
|
|
6360
6360
|
try {
|
|
6361
6361
|
let n = e.db.prepare("SELECT device_id, fingerprint FROM sync_device LIMIT 1").get();
|
|
@@ -6364,81 +6364,82 @@ function tu(e) {
|
|
|
6364
6364
|
return t;
|
|
6365
6365
|
}
|
|
6366
6366
|
}
|
|
6367
|
-
function
|
|
6367
|
+
function tu(e, t) {
|
|
6368
6368
|
return [
|
|
6369
|
-
|
|
6369
|
+
$l(e, t),
|
|
6370
|
+
t.syncEnabled ? "sync-enabled" : "sync-disabled",
|
|
6370
6371
|
t.syncHost,
|
|
6371
6372
|
t.syncPort,
|
|
6372
6373
|
t.syncAdvertise,
|
|
6373
6374
|
t.syncCoordinatorPresenceTtlS
|
|
6374
6375
|
].join("|");
|
|
6375
6376
|
}
|
|
6376
|
-
function
|
|
6377
|
+
function nu(e) {
|
|
6377
6378
|
return Number(e.db.prepare("SELECT COUNT(1) AS total FROM sync_peers").get()?.total ?? 0);
|
|
6378
6379
|
}
|
|
6379
|
-
function
|
|
6380
|
+
function ru(e) {
|
|
6380
6381
|
let t = Math.max(1, e.syncCoordinatorPresenceTtlS), n = Math.floor(t / 2);
|
|
6381
6382
|
return Math.max(5, Math.min(60, n > 0 ? n : 1)) * 1e3;
|
|
6382
6383
|
}
|
|
6383
|
-
function
|
|
6384
|
+
function iu() {
|
|
6384
6385
|
return 3e4;
|
|
6385
6386
|
}
|
|
6386
|
-
function
|
|
6387
|
+
function au(e) {
|
|
6387
6388
|
let t = { ...e ?? Bt() }, n = Wt();
|
|
6388
6389
|
for (let e of Object.keys(n)) {
|
|
6389
6390
|
let r = process.env[n[e]];
|
|
6390
6391
|
r != null && (t[e] = r);
|
|
6391
6392
|
}
|
|
6392
|
-
let r =
|
|
6393
|
+
let r = Gl(t.sync_coordinator_group), i = Jl(t.sync_coordinator_groups);
|
|
6393
6394
|
return {
|
|
6394
|
-
syncEnabled:
|
|
6395
|
-
syncHost:
|
|
6396
|
-
syncPort:
|
|
6397
|
-
syncIntervalS:
|
|
6398
|
-
syncAdvertise:
|
|
6399
|
-
syncMdns:
|
|
6400
|
-
syncRetentionEnabled:
|
|
6401
|
-
syncRetentionMaxAgeDays: Math.max(1,
|
|
6402
|
-
syncRetentionMaxSizeMb: Math.max(1,
|
|
6403
|
-
syncRetentionIntervalS: Math.max(5,
|
|
6404
|
-
syncRetentionMaxRuntimeMs: Math.max(100,
|
|
6405
|
-
syncRetentionMaxOpsPerPass: Math.max(1,
|
|
6406
|
-
syncProjectsInclude:
|
|
6407
|
-
syncProjectsExclude:
|
|
6408
|
-
syncOpsLimit: Math.max(1, Math.min(1e3,
|
|
6409
|
-
syncCoordinatorUrl:
|
|
6395
|
+
syncEnabled: ql(t.sync_enabled, !1),
|
|
6396
|
+
syncHost: Gl(t.sync_host) || "0.0.0.0",
|
|
6397
|
+
syncPort: Kl(t.sync_port, 7337),
|
|
6398
|
+
syncIntervalS: Kl(t.sync_interval_s, 120),
|
|
6399
|
+
syncAdvertise: Gl(t.sync_advertise) || "auto",
|
|
6400
|
+
syncMdns: ql(t.sync_mdns, !1),
|
|
6401
|
+
syncRetentionEnabled: ql(t.sync_retention_enabled, !1),
|
|
6402
|
+
syncRetentionMaxAgeDays: Math.max(1, Kl(t.sync_retention_max_age_days, 30)),
|
|
6403
|
+
syncRetentionMaxSizeMb: Math.max(1, Kl(t.sync_retention_max_size_mb, 512)),
|
|
6404
|
+
syncRetentionIntervalS: Math.max(5, Kl(t.sync_retention_interval_s, 300)),
|
|
6405
|
+
syncRetentionMaxRuntimeMs: Math.max(100, Kl(t.sync_retention_max_runtime_ms, 2e3)),
|
|
6406
|
+
syncRetentionMaxOpsPerPass: Math.max(1, Kl(t.sync_retention_max_ops_per_pass, 5e3)),
|
|
6407
|
+
syncProjectsInclude: Jl(t.sync_projects_include),
|
|
6408
|
+
syncProjectsExclude: Jl(t.sync_projects_exclude),
|
|
6409
|
+
syncOpsLimit: Math.max(1, Math.min(1e3, Kl(t.sync_ops_limit, 500))),
|
|
6410
|
+
syncCoordinatorUrl: Gl(t.sync_coordinator_url),
|
|
6410
6411
|
syncCoordinatorGroup: r,
|
|
6411
6412
|
syncCoordinatorGroups: i.length > 0 ? i : r ? [r] : [],
|
|
6412
|
-
syncCoordinatorTimeoutS:
|
|
6413
|
-
syncCoordinatorPresenceTtlS:
|
|
6414
|
-
syncCoordinatorAdminSecret:
|
|
6413
|
+
syncCoordinatorTimeoutS: Kl(t.sync_coordinator_timeout_s, 3),
|
|
6414
|
+
syncCoordinatorPresenceTtlS: Kl(t.sync_coordinator_presence_ttl_s, 180),
|
|
6415
|
+
syncCoordinatorAdminSecret: Gl(t.sync_coordinator_admin_secret)
|
|
6415
6416
|
};
|
|
6416
6417
|
}
|
|
6417
|
-
function
|
|
6418
|
+
function ou(e) {
|
|
6418
6419
|
return !!(e.syncCoordinatorUrl && e.syncCoordinatorGroups.length > 0);
|
|
6419
6420
|
}
|
|
6420
|
-
function
|
|
6421
|
+
function su(e) {
|
|
6421
6422
|
let t = e.syncAdvertise.toLowerCase();
|
|
6422
|
-
if (t && t !== "auto" && t !== "default") return
|
|
6423
|
-
if (e.syncHost && e.syncHost !== "0.0.0.0") return [Ll(
|
|
6424
|
-
let n = Object.values(ie()).flatMap((e) => e ?? []).filter((e) => !e.internal).map((e) => e.address).filter((e) => e && e !== "127.0.0.1" && e !== "::1").map((t) => Ll(
|
|
6423
|
+
if (t && t !== "auto" && t !== "default") return zl([], t.split(",").map((e) => e.trim()).filter(Boolean), { defaultHttpPort: e.syncPort });
|
|
6424
|
+
if (e.syncHost && e.syncHost !== "0.0.0.0") return [Il(Ll(e.syncHost, e.syncPort))].filter(Boolean);
|
|
6425
|
+
let n = Object.values(ie()).flatMap((e) => e ?? []).filter((e) => !e.internal).map((e) => e.address).filter((e) => e && e !== "127.0.0.1" && e !== "::1").map((t) => Il(Ll(t, e.syncPort))).filter(Boolean);
|
|
6425
6426
|
return [...new Set(n)];
|
|
6426
6427
|
}
|
|
6427
|
-
async function
|
|
6428
|
-
if (!
|
|
6428
|
+
async function cu(e, t, n) {
|
|
6429
|
+
if (!ou(t)) return null;
|
|
6429
6430
|
let r = n?.keysDir ?? (process.env.CODEMEM_KEYS_DIR?.trim() || void 0), [i, a] = pr(e.db, { keysDir: r }), o = ir(r);
|
|
6430
6431
|
if (!o) throw Error("public key missing");
|
|
6431
|
-
let s =
|
|
6432
|
+
let s = Ul(t.syncCoordinatorUrl), c = {
|
|
6432
6433
|
fingerprint: a,
|
|
6433
6434
|
public_key: o,
|
|
6434
|
-
addresses:
|
|
6435
|
+
addresses: su(t),
|
|
6435
6436
|
ttl_s: Math.max(1, t.syncCoordinatorPresenceTtlS)
|
|
6436
6437
|
}, l = [];
|
|
6437
6438
|
for (let e of t.syncCoordinatorGroups) {
|
|
6438
6439
|
let n = {
|
|
6439
6440
|
...c,
|
|
6440
6441
|
group_id: e
|
|
6441
|
-
}, a = Buffer.from(JSON.stringify(n), "utf8"), o = `${s}/v1/presence`, [u, d] = await
|
|
6442
|
+
}, a = Buffer.from(JSON.stringify(n), "utf8"), o = `${s}/v1/presence`, [u, d] = await Wl("POST", o, {
|
|
6442
6443
|
headers: yr({
|
|
6443
6444
|
deviceId: i,
|
|
6444
6445
|
method: "POST",
|
|
@@ -6461,11 +6462,11 @@ async function lu(e, t, n) {
|
|
|
6461
6462
|
responses: l
|
|
6462
6463
|
};
|
|
6463
6464
|
}
|
|
6464
|
-
async function
|
|
6465
|
-
if (!
|
|
6466
|
-
let r = n?.keysDir ?? (process.env.CODEMEM_KEYS_DIR?.trim() || void 0), [i] = pr(e.db, { keysDir: r }), a =
|
|
6465
|
+
async function lu(e, t, n) {
|
|
6466
|
+
if (!ou(t)) return [];
|
|
6467
|
+
let r = n?.keysDir ?? (process.env.CODEMEM_KEYS_DIR?.trim() || void 0), [i] = pr(e.db, { keysDir: r }), a = Ul(t.syncCoordinatorUrl), o = /* @__PURE__ */ new Map();
|
|
6467
6468
|
for (let e of t.syncCoordinatorGroups) {
|
|
6468
|
-
let n = `${a}/v1/peers?group_id=${encodeURIComponent(e)}`, [s, c] = await
|
|
6469
|
+
let n = `${a}/v1/peers?group_id=${encodeURIComponent(e)}`, [s, c] = await Wl("GET", n, {
|
|
6469
6470
|
headers: yr({
|
|
6470
6471
|
deviceId: i,
|
|
6471
6472
|
method: "GET",
|
|
@@ -6482,74 +6483,74 @@ async function uu(e, t, n) {
|
|
|
6482
6483
|
let l = Array.isArray(c.items) ? c.items : [];
|
|
6483
6484
|
for (let t of l) {
|
|
6484
6485
|
if (!t || typeof t != "object") continue;
|
|
6485
|
-
let n = t, r =
|
|
6486
|
+
let n = t, r = Gl(n.device_id), i = Gl(n.fingerprint);
|
|
6486
6487
|
if (!r) continue;
|
|
6487
6488
|
let a = n.stale ? [] : Array.isArray(n.addresses) ? n.addresses.filter((e) => typeof e == "string") : [], s = `${r}:${i}`, c = o.get(s);
|
|
6488
6489
|
if (!c) {
|
|
6489
6490
|
o.set(s, {
|
|
6490
6491
|
...n,
|
|
6491
|
-
addresses:
|
|
6492
|
+
addresses: zl([], a),
|
|
6492
6493
|
groups: [e],
|
|
6493
6494
|
fresh_groups: n.stale ? [] : [e]
|
|
6494
6495
|
});
|
|
6495
6496
|
continue;
|
|
6496
6497
|
}
|
|
6497
|
-
c.addresses =
|
|
6498
|
+
c.addresses = zl(Array.isArray(c.addresses) ? c.addresses : [], a), c.groups = Yl(Array.isArray(c.groups) ? c.groups : [], [e]), c.fresh_groups = Yl(Array.isArray(c.fresh_groups) ? c.fresh_groups : [], n.stale ? [] : [e]);
|
|
6498
6499
|
let l = !!c.stale, u = !!n.stale;
|
|
6499
|
-
c.stale = l && u, (!u && (l ||
|
|
6500
|
+
c.stale = l && u, (!u && (l || Gl(n.last_seen_at) > Gl(c.last_seen_at)) || u && l && Gl(n.last_seen_at) > Gl(c.last_seen_at)) && (c.last_seen_at = n.last_seen_at, c.expires_at = n.expires_at);
|
|
6500
6501
|
}
|
|
6501
6502
|
}
|
|
6502
6503
|
return [...o.values()];
|
|
6503
6504
|
}
|
|
6504
|
-
function
|
|
6505
|
+
function uu(e) {
|
|
6505
6506
|
return Array.isArray(e) ? e.filter((e) => typeof e == "string" && e.trim().length > 0) : [];
|
|
6506
6507
|
}
|
|
6507
|
-
function
|
|
6508
|
+
function du(e) {
|
|
6508
6509
|
if (typeof e != "string" || e.trim().length === 0) return [];
|
|
6509
6510
|
try {
|
|
6510
|
-
return
|
|
6511
|
+
return uu(JSON.parse(e));
|
|
6511
6512
|
} catch {
|
|
6512
6513
|
return [];
|
|
6513
6514
|
}
|
|
6514
6515
|
}
|
|
6515
|
-
function
|
|
6516
|
+
function fu(e, t) {
|
|
6516
6517
|
let n = /* @__PURE__ */ new Map();
|
|
6517
6518
|
for (let e of t) {
|
|
6518
6519
|
if (e.stale) continue;
|
|
6519
|
-
let t =
|
|
6520
|
+
let t = Gl(e.device_id), r = Gl(e.fingerprint);
|
|
6520
6521
|
if (!t || !r) continue;
|
|
6521
|
-
let i =
|
|
6522
|
+
let i = uu(e.addresses);
|
|
6522
6523
|
if (i.length === 0) continue;
|
|
6523
6524
|
let a = `${t}:${r}`;
|
|
6524
|
-
n.set(a,
|
|
6525
|
+
n.set(a, zl(n.get(a) ?? [], i));
|
|
6525
6526
|
}
|
|
6526
6527
|
if (n.size === 0) return 0;
|
|
6527
6528
|
let r = e.prepare("SELECT peer_device_id, pinned_fingerprint, addresses_json FROM sync_peers").all(), i = e.prepare("UPDATE sync_peers SET addresses_json = ? WHERE peer_device_id = ? AND pinned_fingerprint = ?"), a = 0;
|
|
6528
6529
|
return e.transaction(() => {
|
|
6529
6530
|
for (let e of r) {
|
|
6530
|
-
let t =
|
|
6531
|
+
let t = Gl(e.peer_device_id), r = Gl(e.pinned_fingerprint);
|
|
6531
6532
|
if (!t || !r) continue;
|
|
6532
6533
|
let o = n.get(`${t}:${r}`);
|
|
6533
6534
|
if (!o?.length) continue;
|
|
6534
|
-
let s =
|
|
6535
|
+
let s = zl(du(e.addresses_json), []), c = Bl(s, o);
|
|
6535
6536
|
JSON.stringify(c) !== JSON.stringify(s) && (i.run(JSON.stringify(c), t, r), a += 1);
|
|
6536
6537
|
}
|
|
6537
6538
|
}).immediate(), a;
|
|
6538
6539
|
}
|
|
6539
|
-
async function
|
|
6540
|
-
let r =
|
|
6541
|
-
if (!
|
|
6540
|
+
async function pu(e, t, n) {
|
|
6541
|
+
let r = au();
|
|
6542
|
+
if (!ou(r)) return /* @__PURE__ */ new Set();
|
|
6542
6543
|
try {
|
|
6543
|
-
let i = await
|
|
6544
|
+
let i = await lu({
|
|
6544
6545
|
db: e,
|
|
6545
6546
|
dbPath: t
|
|
6546
6547
|
}, r, { keysDir: n });
|
|
6547
|
-
|
|
6548
|
+
fu(e, i);
|
|
6548
6549
|
let a = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set(), s = /* @__PURE__ */ new Set(), c = /* @__PURE__ */ new Set();
|
|
6549
6550
|
for (let e of i) {
|
|
6550
|
-
let t =
|
|
6551
|
+
let t = Gl(e.device_id);
|
|
6551
6552
|
if (!t) continue;
|
|
6552
|
-
let n =
|
|
6553
|
+
let n = Gl(e.fingerprint), r = n ? `${t}:${n}` : "";
|
|
6553
6554
|
e.stale ? (o.add(t), r && c.add(r)) : (a.add(t), r && s.add(r));
|
|
6554
6555
|
}
|
|
6555
6556
|
for (let e of a) o.delete(e);
|
|
@@ -6559,15 +6560,15 @@ async function mu(e, t, n) {
|
|
|
6559
6560
|
return /* @__PURE__ */ new Set();
|
|
6560
6561
|
}
|
|
6561
6562
|
}
|
|
6562
|
-
async function
|
|
6563
|
-
if (!
|
|
6564
|
-
let r = process.env.CODEMEM_KEYS_DIR?.trim() || void 0, [i] = pr(e.db, { keysDir: r }), a =
|
|
6563
|
+
async function mu(e, t, n) {
|
|
6564
|
+
if (!ou(t)) return [];
|
|
6565
|
+
let r = process.env.CODEMEM_KEYS_DIR?.trim() || void 0, [i] = pr(e.db, { keysDir: r }), a = Ul(t.syncCoordinatorUrl), o = /* @__PURE__ */ new Map();
|
|
6565
6566
|
for (let e of t.syncCoordinatorGroups) {
|
|
6566
6567
|
let s = `${a}/v1/reciprocal-approvals?${new URLSearchParams({
|
|
6567
6568
|
group_id: e,
|
|
6568
6569
|
direction: n.direction,
|
|
6569
6570
|
status: n.status?.trim() || "pending"
|
|
6570
|
-
}).toString()}`, [c, l] = await
|
|
6571
|
+
}).toString()}`, [c, l] = await Wl("GET", s, {
|
|
6571
6572
|
headers: yr({
|
|
6572
6573
|
deviceId: i,
|
|
6573
6574
|
method: "GET",
|
|
@@ -6584,20 +6585,20 @@ async function hu(e, t, n) {
|
|
|
6584
6585
|
let u = Array.isArray(l.items) ? l.items : [];
|
|
6585
6586
|
for (let e of u) {
|
|
6586
6587
|
if (!e || typeof e != "object") continue;
|
|
6587
|
-
let t = e, n =
|
|
6588
|
+
let t = e, n = Gl(t.request_id);
|
|
6588
6589
|
n && o.set(n, t);
|
|
6589
6590
|
}
|
|
6590
6591
|
}
|
|
6591
6592
|
return [...o.values()];
|
|
6592
6593
|
}
|
|
6593
|
-
async function
|
|
6594
|
-
if (!
|
|
6594
|
+
async function hu(e, t, n) {
|
|
6595
|
+
if (!ou(t)) throw Error("Coordinator not configured.");
|
|
6595
6596
|
let r = n.groupId.trim(), i = n.requestedDeviceId.trim();
|
|
6596
6597
|
if (!r || !i) throw Error("groupId and requestedDeviceId are required.");
|
|
6597
|
-
let a = process.env.CODEMEM_KEYS_DIR?.trim() || void 0, [o] = pr(e.db, { keysDir: a }), s = `${
|
|
6598
|
+
let a = process.env.CODEMEM_KEYS_DIR?.trim() || void 0, [o] = pr(e.db, { keysDir: a }), s = `${Ul(t.syncCoordinatorUrl)}/v1/reciprocal-approvals`, c = {
|
|
6598
6599
|
group_id: r,
|
|
6599
6600
|
requested_device_id: i
|
|
6600
|
-
}, l = Buffer.from(JSON.stringify(c), "utf8"), [u, d] = await
|
|
6601
|
+
}, l = Buffer.from(JSON.stringify(c), "utf8"), [u, d] = await Wl("POST", s, {
|
|
6601
6602
|
headers: yr({
|
|
6602
6603
|
deviceId: o,
|
|
6603
6604
|
method: "POST",
|
|
@@ -6615,32 +6616,35 @@ async function gu(e, t, n) {
|
|
|
6615
6616
|
}
|
|
6616
6617
|
return d.request;
|
|
6617
6618
|
}
|
|
6618
|
-
function
|
|
6619
|
+
function gu(e, t) {
|
|
6619
6620
|
let n = /* @__PURE__ */ new Map();
|
|
6620
6621
|
for (let r of e) {
|
|
6621
|
-
let e =
|
|
6622
|
+
let e = Gl(r[t]);
|
|
6622
6623
|
e && n.set(e, r);
|
|
6623
6624
|
}
|
|
6624
6625
|
return n;
|
|
6625
6626
|
}
|
|
6626
|
-
async function
|
|
6627
|
-
let n =
|
|
6628
|
-
if (!
|
|
6627
|
+
async function _u(e, t) {
|
|
6628
|
+
let n = nu(e);
|
|
6629
|
+
if (!ou(t)) return {
|
|
6629
6630
|
enabled: !1,
|
|
6630
6631
|
configured: !1,
|
|
6632
|
+
sync_enabled: t.syncEnabled,
|
|
6633
|
+
coordinator_url: t.syncCoordinatorUrl || null,
|
|
6631
6634
|
groups: t.syncCoordinatorGroups,
|
|
6632
6635
|
paired_peer_count: n
|
|
6633
6636
|
};
|
|
6634
6637
|
let r = process.env.CODEMEM_KEYS_DIR?.trim() || void 0;
|
|
6635
6638
|
pr(e.db, { keysDir: r });
|
|
6636
|
-
let i =
|
|
6639
|
+
let i = tu(e, t), a = Date.now(), o = Zl.get(i);
|
|
6637
6640
|
if (o && a < o.nextRefreshAtMs) return {
|
|
6638
6641
|
...structuredClone(o.snapshot),
|
|
6639
|
-
paired_peer_count:
|
|
6642
|
+
paired_peer_count: nu(e)
|
|
6640
6643
|
};
|
|
6641
6644
|
let s = {
|
|
6642
6645
|
enabled: !0,
|
|
6643
6646
|
configured: !0,
|
|
6647
|
+
sync_enabled: t.syncEnabled,
|
|
6644
6648
|
coordinator_url: t.syncCoordinatorUrl,
|
|
6645
6649
|
groups: t.syncCoordinatorGroups,
|
|
6646
6650
|
paired_peer_count: n,
|
|
@@ -6651,19 +6655,19 @@ async function vu(e, t) {
|
|
|
6651
6655
|
stale_peer_count: 0,
|
|
6652
6656
|
discovered_peer_count: 0,
|
|
6653
6657
|
discovered_devices: []
|
|
6654
|
-
}, c =
|
|
6658
|
+
}, c = $l(e, t), l = Xl.get(c);
|
|
6655
6659
|
if (l && a < l.nextRefreshAtMs) s.presence_status = l.status, s.presence_error = l.error, s.advertised_addresses = l.advertisedAddresses;
|
|
6656
6660
|
else try {
|
|
6657
|
-
let n = (await
|
|
6658
|
-
s.presence_status = "posted", s.advertised_addresses = r,
|
|
6661
|
+
let n = (await cu(e, t))?.responses?.[0], r = n && typeof n == "object" ? n.addresses ?? [] : [];
|
|
6662
|
+
s.presence_status = "posted", s.advertised_addresses = r, Xl.set(c, {
|
|
6659
6663
|
status: "posted",
|
|
6660
6664
|
error: null,
|
|
6661
6665
|
advertisedAddresses: r,
|
|
6662
|
-
nextRefreshAtMs: a +
|
|
6666
|
+
nextRefreshAtMs: a + ru(t)
|
|
6663
6667
|
});
|
|
6664
6668
|
} catch (e) {
|
|
6665
|
-
let t = e instanceof Error ? e.message : String(e), n = t.includes("unknown_device") ? "not_enrolled" : "error", r = n === "not_enrolled" ? a : a +
|
|
6666
|
-
s.presence_status = n, s.presence_error = t,
|
|
6669
|
+
let t = e instanceof Error ? e.message : String(e), n = t.includes("unknown_device") ? "not_enrolled" : "error", r = n === "not_enrolled" ? a : a + iu();
|
|
6670
|
+
s.presence_status = n, s.presence_error = t, Xl.set(c, {
|
|
6667
6671
|
status: n,
|
|
6668
6672
|
error: t,
|
|
6669
6673
|
advertisedAddresses: [],
|
|
@@ -6671,15 +6675,15 @@ async function vu(e, t) {
|
|
|
6671
6675
|
});
|
|
6672
6676
|
}
|
|
6673
6677
|
try {
|
|
6674
|
-
let n = await
|
|
6675
|
-
|
|
6678
|
+
let n = await lu(e, t);
|
|
6679
|
+
fu(e.db, n);
|
|
6676
6680
|
let r = [], i = [];
|
|
6677
6681
|
try {
|
|
6678
|
-
r = await
|
|
6682
|
+
r = await mu(e, t, { direction: "incoming" }), i = await mu(e, t, { direction: "outgoing" });
|
|
6679
6683
|
} catch (e) {
|
|
6680
6684
|
s.reciprocal_approval_error = e instanceof Error ? e.message : String(e);
|
|
6681
6685
|
}
|
|
6682
|
-
let a =
|
|
6686
|
+
let a = gu(r, "requesting_device_id"), o = gu(i, "requested_device_id");
|
|
6683
6687
|
s.discovered_peer_count = n.length, s.fresh_peer_count = n.filter((e) => !e.stale).length, s.stale_peer_count = n.filter((e) => !!e.stale).length, s.reciprocal_approvals = {
|
|
6684
6688
|
incoming: r,
|
|
6685
6689
|
outgoing: i
|
|
@@ -6692,23 +6696,23 @@ async function vu(e, t) {
|
|
|
6692
6696
|
last_seen_at: e.last_seen_at ?? null,
|
|
6693
6697
|
expires_at: e.expires_at ?? null,
|
|
6694
6698
|
stale: !!e.stale,
|
|
6695
|
-
needs_local_approval: a.has(
|
|
6696
|
-
waiting_for_peer_approval: o.has(
|
|
6697
|
-
incoming_reciprocal_request_id: a.get(
|
|
6698
|
-
outgoing_reciprocal_request_id: o.get(
|
|
6699
|
+
needs_local_approval: a.has(Gl(e.device_id)),
|
|
6700
|
+
waiting_for_peer_approval: o.has(Gl(e.device_id)),
|
|
6701
|
+
incoming_reciprocal_request_id: a.get(Gl(e.device_id))?.request_id ?? null,
|
|
6702
|
+
outgoing_reciprocal_request_id: o.get(Gl(e.device_id))?.request_id ?? null
|
|
6699
6703
|
}));
|
|
6700
6704
|
} catch (e) {
|
|
6701
6705
|
s.lookup_error = e instanceof Error ? e.message : String(e);
|
|
6702
6706
|
}
|
|
6703
|
-
return s.presence_status !== "not_enrolled" &&
|
|
6707
|
+
return s.presence_status !== "not_enrolled" && Zl.set(i, {
|
|
6704
6708
|
snapshot: structuredClone(s),
|
|
6705
|
-
nextRefreshAtMs: Date.now() +
|
|
6709
|
+
nextRefreshAtMs: Date.now() + Ql
|
|
6706
6710
|
}), s;
|
|
6707
6711
|
}
|
|
6708
|
-
async function
|
|
6712
|
+
async function vu(e) {
|
|
6709
6713
|
let t = e.syncCoordinatorGroup || e.syncCoordinatorGroups[0] || "";
|
|
6710
6714
|
if (!t || !e.syncCoordinatorUrl || !e.syncCoordinatorAdminSecret) return [];
|
|
6711
|
-
let [n, r] = await
|
|
6715
|
+
let [n, r] = await Wl("GET", `${Ul(e.syncCoordinatorUrl)}/v1/admin/join-requests?group_id=${encodeURIComponent(t)}`, {
|
|
6712
6716
|
headers: { "X-Codemem-Coordinator-Admin": e.syncCoordinatorAdminSecret },
|
|
6713
6717
|
timeoutS: Math.max(1, e.syncCoordinatorTimeoutS)
|
|
6714
6718
|
});
|
|
@@ -6716,39 +6720,39 @@ async function yu(e) {
|
|
|
6716
6720
|
}
|
|
6717
6721
|
//#endregion
|
|
6718
6722
|
//#region src/scope-membership-cache.ts
|
|
6719
|
-
var
|
|
6720
|
-
function
|
|
6723
|
+
var yu = 6e4;
|
|
6724
|
+
function bu(e) {
|
|
6721
6725
|
return e?.trim() || null;
|
|
6722
6726
|
}
|
|
6723
|
-
function
|
|
6727
|
+
function xu(e) {
|
|
6724
6728
|
return (e ?? /* @__PURE__ */ new Date()).toISOString();
|
|
6725
6729
|
}
|
|
6726
|
-
function
|
|
6730
|
+
function Su(e) {
|
|
6727
6731
|
return [...new Set(e.map((e) => e.trim()).filter(Boolean))].toSorted();
|
|
6728
6732
|
}
|
|
6729
|
-
function
|
|
6730
|
-
let t =
|
|
6733
|
+
function Cu(e) {
|
|
6734
|
+
let t = bu(e);
|
|
6731
6735
|
if (!t) return "local";
|
|
6732
6736
|
try {
|
|
6733
|
-
return
|
|
6737
|
+
return Ul(t);
|
|
6734
6738
|
} catch {
|
|
6735
6739
|
return t;
|
|
6736
6740
|
}
|
|
6737
6741
|
}
|
|
6738
|
-
function
|
|
6742
|
+
function wu(e) {
|
|
6739
6743
|
return e instanceof Error ? e.message : String(e ?? "unknown");
|
|
6740
6744
|
}
|
|
6741
|
-
function
|
|
6745
|
+
function Tu(e) {
|
|
6742
6746
|
e.exec("\n CREATE TABLE IF NOT EXISTS scope_membership_cache_state (\n coordinator_id TEXT NOT NULL,\n group_id TEXT NOT NULL,\n last_refresh_at TEXT NOT NULL,\n last_success_at TEXT,\n last_error TEXT,\n updated_at TEXT NOT NULL,\n PRIMARY KEY (coordinator_id, group_id)\n )\n ");
|
|
6743
6747
|
}
|
|
6744
|
-
function
|
|
6745
|
-
let t =
|
|
6748
|
+
function Eu(e) {
|
|
6749
|
+
let t = bu(e.remoteUrl);
|
|
6746
6750
|
if (!t) throw Error("Coordinator URL required.");
|
|
6747
|
-
return
|
|
6751
|
+
return Ul(t);
|
|
6748
6752
|
}
|
|
6749
|
-
function
|
|
6753
|
+
function Du(e, t, n) {
|
|
6750
6754
|
let [r] = pr(e, { keysDir: n ?? void 0 });
|
|
6751
|
-
return
|
|
6755
|
+
return Wl("GET", t, { headers: yr({
|
|
6752
6756
|
deviceId: r,
|
|
6753
6757
|
method: "GET",
|
|
6754
6758
|
url: t,
|
|
@@ -6762,18 +6766,18 @@ function Ou(e, t, n) {
|
|
|
6762
6766
|
return t;
|
|
6763
6767
|
});
|
|
6764
6768
|
}
|
|
6765
|
-
function
|
|
6769
|
+
function Ou(e) {
|
|
6766
6770
|
return Array.isArray(e?.items) ? e.items.filter((e) => !!e && typeof e == "object") : [];
|
|
6767
6771
|
}
|
|
6768
|
-
function
|
|
6769
|
-
let n =
|
|
6772
|
+
function ku(e, t) {
|
|
6773
|
+
let n = Eu(t);
|
|
6770
6774
|
return {
|
|
6771
|
-
listScopes: async (r) =>
|
|
6772
|
-
listMemberships: async (r, i) =>
|
|
6775
|
+
listScopes: async (r) => Ou(await Du(e, `${n}/v1/scopes?group_id=${encodeURIComponent(r)}`, t.keysDir)),
|
|
6776
|
+
listMemberships: async (r, i) => Ou(await Du(e, `${n}/v1/scopes/${encodeURIComponent(i)}/members?group_id=${encodeURIComponent(r)}`, t.keysDir))
|
|
6773
6777
|
};
|
|
6774
6778
|
}
|
|
6775
|
-
function
|
|
6776
|
-
return t.remoteUrl && !t.adminSecret ?
|
|
6779
|
+
function Au(e, t) {
|
|
6780
|
+
return t.remoteUrl && !t.adminSecret ? ku(e, t) : {
|
|
6777
6781
|
listScopes: (e) => $h({
|
|
6778
6782
|
groupId: e,
|
|
6779
6783
|
includeInactive: !0,
|
|
@@ -6789,28 +6793,28 @@ function ju(e, t) {
|
|
|
6789
6793
|
})
|
|
6790
6794
|
};
|
|
6791
6795
|
}
|
|
6792
|
-
function
|
|
6796
|
+
function ju(e, t) {
|
|
6793
6797
|
e.prepare("INSERT INTO replication_scopes(\n scope_id, label, kind, authority_type, coordinator_id, group_id,\n manifest_issuer_device_id, membership_epoch, manifest_hash, status, created_at, updated_at\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\n ON CONFLICT(scope_id) DO UPDATE SET\n label = excluded.label,\n kind = excluded.kind,\n authority_type = excluded.authority_type,\n coordinator_id = excluded.coordinator_id,\n group_id = excluded.group_id,\n manifest_issuer_device_id = excluded.manifest_issuer_device_id,\n membership_epoch = excluded.membership_epoch,\n manifest_hash = excluded.manifest_hash,\n status = excluded.status,\n updated_at = excluded.updated_at\n WHERE excluded.membership_epoch >= replication_scopes.membership_epoch").run(t.scope_id, t.label, t.kind, t.authority_type, t.coordinator_id, t.group_id, t.manifest_issuer_device_id, t.membership_epoch, t.manifest_hash, t.status, t.created_at, t.updated_at);
|
|
6794
6798
|
}
|
|
6795
|
-
function
|
|
6799
|
+
function Mu(e, t) {
|
|
6796
6800
|
return {
|
|
6797
6801
|
...e,
|
|
6798
|
-
coordinator_id:
|
|
6799
|
-
group_id:
|
|
6802
|
+
coordinator_id: bu(e.coordinator_id) ?? t.coordinatorId,
|
|
6803
|
+
group_id: bu(e.group_id) ?? t.groupId
|
|
6800
6804
|
};
|
|
6801
6805
|
}
|
|
6802
|
-
function
|
|
6806
|
+
function Nu(e, t, n) {
|
|
6803
6807
|
return {
|
|
6804
6808
|
...e,
|
|
6805
|
-
coordinator_id:
|
|
6806
|
-
group_id:
|
|
6809
|
+
coordinator_id: bu(e.coordinator_id) ?? bu(t.coordinator_id) ?? n.coordinatorId,
|
|
6810
|
+
group_id: bu(e.group_id) ?? bu(t.group_id) ?? n.groupId
|
|
6807
6811
|
};
|
|
6808
6812
|
}
|
|
6809
|
-
function
|
|
6813
|
+
function Pu(e) {
|
|
6810
6814
|
return Array.from({ length: e }, () => "?").join(", ");
|
|
6811
6815
|
}
|
|
6812
|
-
function
|
|
6813
|
-
let a = n.map((e) => e.device_id), o = a.length > 0 ? `AND device_id NOT IN (${
|
|
6816
|
+
function Fu(e, t, n, r, i) {
|
|
6817
|
+
let a = n.map((e) => e.device_id), o = a.length > 0 ? `AND device_id NOT IN (${Pu(a.length)})` : "";
|
|
6814
6818
|
e.prepare(`UPDATE scope_memberships
|
|
6815
6819
|
SET status = 'revoked',
|
|
6816
6820
|
membership_epoch = CASE WHEN membership_epoch > ? THEN membership_epoch ELSE ? END,
|
|
@@ -6823,8 +6827,8 @@ function Iu(e, t, n, r, i) {
|
|
|
6823
6827
|
AND status != 'revoked'
|
|
6824
6828
|
${o}`).run(t.membership_epoch, t.membership_epoch, r.coordinatorId, r.groupId, i, t.scope_id, r.coordinatorId, r.coordinatorId, r.groupId, r.groupId, ...a);
|
|
6825
6829
|
}
|
|
6826
|
-
function
|
|
6827
|
-
let i = n.map((e) => e.scope_id), a = i.length > 0 ? `AND scope_id NOT IN (${
|
|
6830
|
+
function Iu(e, t, n, r) {
|
|
6831
|
+
let i = n.map((e) => e.scope_id), a = i.length > 0 ? `AND scope_id NOT IN (${Pu(i.length)})` : "", o = e.prepare(`SELECT scope_id
|
|
6828
6832
|
FROM replication_scopes
|
|
6829
6833
|
WHERE coordinator_id = ?
|
|
6830
6834
|
AND group_id = ?
|
|
@@ -6835,35 +6839,35 @@ function Lu(e, t, n, r) {
|
|
|
6835
6839
|
SET status = 'archived', updated_at = ?
|
|
6836
6840
|
WHERE coordinator_id = ?
|
|
6837
6841
|
AND group_id = ?
|
|
6838
|
-
AND scope_id IN (${
|
|
6842
|
+
AND scope_id IN (${Pu(s.length)})`).run(r, t.coordinatorId, t.groupId, ...s), e.prepare(`UPDATE scope_memberships
|
|
6839
6843
|
SET status = 'revoked', updated_at = ?
|
|
6840
6844
|
WHERE COALESCE(coordinator_id, ?) = ?
|
|
6841
6845
|
AND COALESCE(group_id, ?) = ?
|
|
6842
|
-
AND scope_id IN (${
|
|
6846
|
+
AND scope_id IN (${Pu(s.length)})
|
|
6843
6847
|
AND status != 'revoked'`).run(r, t.coordinatorId, t.coordinatorId, t.groupId, t.groupId, ...s);
|
|
6844
6848
|
}
|
|
6845
|
-
function
|
|
6849
|
+
function Lu(e, t) {
|
|
6846
6850
|
let n = e.prepare("INSERT INTO scope_memberships(\n scope_id, device_id, role, status, membership_epoch, coordinator_id, group_id,\n manifest_issuer_device_id, manifest_hash, signed_manifest_json, updated_at\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\n ON CONFLICT(scope_id, device_id) DO UPDATE SET\n role = excluded.role,\n status = excluded.status,\n membership_epoch = excluded.membership_epoch,\n coordinator_id = excluded.coordinator_id,\n group_id = excluded.group_id,\n manifest_issuer_device_id = excluded.manifest_issuer_device_id,\n manifest_hash = excluded.manifest_hash,\n signed_manifest_json = excluded.signed_manifest_json,\n updated_at = excluded.updated_at\n WHERE excluded.membership_epoch > scope_memberships.membership_epoch\n OR (\n excluded.membership_epoch = scope_memberships.membership_epoch\n AND scope_memberships.status != 'revoked'\n )"), r = 0;
|
|
6847
6851
|
return e.transaction(() => {
|
|
6848
6852
|
for (let e of t) n.run(e.scope_id, e.device_id, e.role, e.status, e.membership_epoch, e.coordinator_id, e.group_id, e.manifest_issuer_device_id, e.manifest_hash, e.signed_manifest_json, e.updated_at), r += 1;
|
|
6849
6853
|
})(), r;
|
|
6850
6854
|
}
|
|
6855
|
+
function Ru(e, t) {
|
|
6856
|
+
Tu(e), e.prepare("INSERT INTO scope_membership_cache_state(\n coordinator_id, group_id, last_refresh_at, last_success_at, last_error, updated_at\n ) VALUES (?, ?, ?, ?, ?, ?)\n ON CONFLICT(coordinator_id, group_id) DO UPDATE SET\n last_refresh_at = excluded.last_refresh_at,\n last_success_at = COALESCE(excluded.last_success_at, scope_membership_cache_state.last_success_at),\n last_error = excluded.last_error,\n updated_at = excluded.updated_at").run(t.coordinatorId, t.groupId, t.now, t.ok ? t.now : null, t.ok ? null : t.error ?? "unknown", t.now);
|
|
6857
|
+
}
|
|
6851
6858
|
function zu(e, t) {
|
|
6852
|
-
|
|
6859
|
+
return Tu(e), t ? e.prepare("SELECT coordinator_id, group_id, last_refresh_at, last_success_at, last_error, updated_at\n FROM scope_membership_cache_state\n WHERE coordinator_id = ? AND group_id = ?").all(t.coordinatorId, t.groupId) : e.prepare("SELECT coordinator_id, group_id, last_refresh_at, last_success_at, last_error, updated_at\n FROM scope_membership_cache_state\n ORDER BY coordinator_id ASC, group_id ASC").all();
|
|
6853
6860
|
}
|
|
6854
6861
|
function Bu(e, t) {
|
|
6855
|
-
return Eu(e), t ? e.prepare("SELECT coordinator_id, group_id, last_refresh_at, last_success_at, last_error, updated_at\n FROM scope_membership_cache_state\n WHERE coordinator_id = ? AND group_id = ?").all(t.coordinatorId, t.groupId) : e.prepare("SELECT coordinator_id, group_id, last_refresh_at, last_success_at, last_error, updated_at\n FROM scope_membership_cache_state\n ORDER BY coordinator_id ASC, group_id ASC").all();
|
|
6856
|
-
}
|
|
6857
|
-
function Vu(e, t) {
|
|
6858
6862
|
if (e.length === 0) return "unknown";
|
|
6859
|
-
if (e.some((e) =>
|
|
6863
|
+
if (e.some((e) => bu(e.last_error) != null)) return "stale";
|
|
6860
6864
|
let n = t.maxAgeMs ?? 6e4, r = (t.now ?? /* @__PURE__ */ new Date()).getTime();
|
|
6861
6865
|
return e.some((e) => {
|
|
6862
6866
|
let t = Date.parse(e.last_success_at ?? "");
|
|
6863
6867
|
return !Number.isFinite(t) || r - t > n;
|
|
6864
6868
|
}) ? "stale" : "fresh";
|
|
6865
6869
|
}
|
|
6866
|
-
function
|
|
6870
|
+
function Vu(e) {
|
|
6867
6871
|
return !e.scope_label || !e.scope_kind || !e.scope_authority_type ? null : {
|
|
6868
6872
|
scope_id: e.scope_id,
|
|
6869
6873
|
label: e.scope_label,
|
|
@@ -6879,7 +6883,7 @@ function Hu(e) {
|
|
|
6879
6883
|
updated_at: e.scope_updated_at ?? e.updated_at
|
|
6880
6884
|
};
|
|
6881
6885
|
}
|
|
6882
|
-
function
|
|
6886
|
+
function Hu(e, t, n) {
|
|
6883
6887
|
let r = n ? " AND coordinator_id = ? AND group_id = ?" : "", i = n ? [
|
|
6884
6888
|
t,
|
|
6885
6889
|
n.coordinatorId,
|
|
@@ -6891,7 +6895,7 @@ function Uu(e, t, n) {
|
|
|
6891
6895
|
WHERE scope_id = ?${r}
|
|
6892
6896
|
LIMIT 1`).get(...i) ?? null;
|
|
6893
6897
|
}
|
|
6894
|
-
function
|
|
6898
|
+
function Uu(e) {
|
|
6895
6899
|
return {
|
|
6896
6900
|
scope_id: e.scope_id,
|
|
6897
6901
|
device_id: e.device_id,
|
|
@@ -6906,7 +6910,7 @@ function Wu(e) {
|
|
|
6906
6910
|
updated_at: e.updated_at
|
|
6907
6911
|
};
|
|
6908
6912
|
}
|
|
6909
|
-
function
|
|
6913
|
+
function Wu(e) {
|
|
6910
6914
|
return `SELECT
|
|
6911
6915
|
sm.scope_id,
|
|
6912
6916
|
sm.device_id,
|
|
@@ -6934,44 +6938,44 @@ function Gu(e) {
|
|
|
6934
6938
|
LEFT JOIN replication_scopes rs ON rs.scope_id = sm.scope_id
|
|
6935
6939
|
${e}`;
|
|
6936
6940
|
}
|
|
6937
|
-
function
|
|
6938
|
-
let n =
|
|
6941
|
+
function Gu(e, t) {
|
|
6942
|
+
let n = bu(e?.coordinator_id) ?? t?.coordinatorId, r = bu(e?.group_id) ?? t?.groupId;
|
|
6939
6943
|
return n && r ? {
|
|
6940
6944
|
coordinatorId: n,
|
|
6941
6945
|
groupId: r
|
|
6942
6946
|
} : null;
|
|
6943
6947
|
}
|
|
6944
|
-
function
|
|
6945
|
-
let t =
|
|
6948
|
+
function Ku(e) {
|
|
6949
|
+
let t = bu(e?.coordinator_id), n = bu(e?.group_id);
|
|
6946
6950
|
return t && n ? {
|
|
6947
6951
|
coordinatorId: t,
|
|
6948
6952
|
groupId: n
|
|
6949
6953
|
} : null;
|
|
6950
6954
|
}
|
|
6951
|
-
async function
|
|
6952
|
-
let n =
|
|
6955
|
+
async function qu(e, t) {
|
|
6956
|
+
let n = Su(t.groupIds);
|
|
6953
6957
|
if (n.length === 0) return {
|
|
6954
6958
|
status: "skipped",
|
|
6955
6959
|
coordinatorId: null,
|
|
6956
6960
|
groups: []
|
|
6957
6961
|
};
|
|
6958
|
-
let r =
|
|
6962
|
+
let r = bu(t.coordinatorId) ?? Cu(t.remoteUrl), i = (e) => ({
|
|
6959
6963
|
coordinatorId: r,
|
|
6960
6964
|
groupId: e
|
|
6961
|
-
}), a = t.fetchers ??
|
|
6965
|
+
}), a = t.fetchers ?? Au(e, t), o = xu(t.now), s = [];
|
|
6962
6966
|
for (let t of n) try {
|
|
6963
|
-
let n = i(t), c = (await a.listScopes(t)).map((e) =>
|
|
6967
|
+
let n = i(t), c = (await a.listScopes(t)).map((e) => Mu(e, n)), l = [];
|
|
6964
6968
|
for (let e of c) {
|
|
6965
|
-
let r = (await a.listMemberships(t, e.scope_id)).map((t) =>
|
|
6969
|
+
let r = (await a.listMemberships(t, e.scope_id)).map((t) => Nu(t, e, n));
|
|
6966
6970
|
l.push({
|
|
6967
6971
|
scope: e,
|
|
6968
6972
|
memberships: r
|
|
6969
6973
|
});
|
|
6970
6974
|
}
|
|
6971
6975
|
e.transaction(() => {
|
|
6972
|
-
for (let t of c)
|
|
6973
|
-
for (let t of l)
|
|
6974
|
-
|
|
6976
|
+
for (let t of c) ju(e, t);
|
|
6977
|
+
for (let t of l) Lu(e, t.memberships), Fu(e, t.scope, t.memberships, n, o);
|
|
6978
|
+
Iu(e, n, c, o), Ru(e, {
|
|
6975
6979
|
coordinatorId: r,
|
|
6976
6980
|
groupId: t,
|
|
6977
6981
|
ok: !0,
|
|
@@ -6987,8 +6991,8 @@ async function Ju(e, t) {
|
|
|
6987
6991
|
error: null
|
|
6988
6992
|
});
|
|
6989
6993
|
} catch (n) {
|
|
6990
|
-
let i =
|
|
6991
|
-
|
|
6994
|
+
let i = wu(n);
|
|
6995
|
+
Ru(e, {
|
|
6992
6996
|
coordinatorId: r,
|
|
6993
6997
|
groupId: t,
|
|
6994
6998
|
ok: !1,
|
|
@@ -7009,11 +7013,11 @@ async function Ju(e, t) {
|
|
|
7009
7013
|
groups: s
|
|
7010
7014
|
};
|
|
7011
7015
|
}
|
|
7012
|
-
async function
|
|
7013
|
-
let r = t ??
|
|
7014
|
-
return
|
|
7016
|
+
async function Ju(e, t, n) {
|
|
7017
|
+
let r = t ?? au();
|
|
7018
|
+
return ou(r) ? qu(e, {
|
|
7015
7019
|
groupIds: r.syncCoordinatorGroups,
|
|
7016
|
-
coordinatorId:
|
|
7020
|
+
coordinatorId: Cu(r.syncCoordinatorUrl),
|
|
7017
7021
|
remoteUrl: r.syncCoordinatorUrl,
|
|
7018
7022
|
adminSecret: r.syncCoordinatorAdminSecret,
|
|
7019
7023
|
keysDir: n?.keysDir ?? null
|
|
@@ -7023,33 +7027,33 @@ async function Yu(e, t, n) {
|
|
|
7023
7027
|
groups: []
|
|
7024
7028
|
};
|
|
7025
7029
|
}
|
|
7026
|
-
function
|
|
7027
|
-
let r =
|
|
7030
|
+
function Yu(e, t, n = {}) {
|
|
7031
|
+
let r = bu(t);
|
|
7028
7032
|
if (!r) throw Error("device_id is required.");
|
|
7029
|
-
|
|
7033
|
+
Tu(e);
|
|
7030
7034
|
let i = [r], a = n.authority ? " AND COALESCE(sm.coordinator_id, rs.coordinator_id) = ? AND COALESCE(sm.group_id, rs.group_id) = ?" : "";
|
|
7031
7035
|
n.authority && i.push(n.authority.coordinatorId, n.authority.groupId);
|
|
7032
|
-
let o = e.prepare(`${
|
|
7036
|
+
let o = e.prepare(`${Wu(`WHERE sm.device_id = ? AND sm.status = 'active' AND rs.scope_id IS NOT NULL AND rs.status = 'active' AND sm.membership_epoch >= rs.membership_epoch${a}`)} ORDER BY sm.scope_id ASC`).all(...i), s = zu(e, n.authority ?? null);
|
|
7033
7037
|
return {
|
|
7034
7038
|
deviceId: r,
|
|
7035
|
-
freshness:
|
|
7039
|
+
freshness: Bu(s, n),
|
|
7036
7040
|
memberships: o.map((e) => ({
|
|
7037
|
-
...
|
|
7038
|
-
scope:
|
|
7041
|
+
...Uu(e),
|
|
7042
|
+
scope: Vu(e)
|
|
7039
7043
|
})),
|
|
7040
7044
|
cacheStates: s
|
|
7041
7045
|
};
|
|
7042
7046
|
}
|
|
7043
|
-
function
|
|
7044
|
-
let r =
|
|
7047
|
+
function Xu(t, n) {
|
|
7048
|
+
let r = bu(n.deviceId), i = bu(n.scopeId);
|
|
7045
7049
|
if (!r || !i) throw Error("device_id and scope_id are required.");
|
|
7046
|
-
|
|
7050
|
+
Tu(t);
|
|
7047
7051
|
let o = n.authority ? " AND COALESCE(sm.coordinator_id, rs.coordinator_id) = ? AND COALESCE(sm.group_id, rs.group_id) = ?" : "", s = n.authority ? [
|
|
7048
7052
|
r,
|
|
7049
7053
|
i,
|
|
7050
7054
|
n.authority.coordinatorId,
|
|
7051
7055
|
n.authority.groupId
|
|
7052
|
-
] : [r, i], c = t.prepare(`${
|
|
7056
|
+
] : [r, i], c = t.prepare(`${Wu(`WHERE sm.device_id = ? AND sm.scope_id = ?${o} LIMIT 1`)}`).get(...s), l = c ? Uu(c) : null, u = c ? Vu(c) : Hu(t, i, n.authority ?? null), d = zu(t, Gu(l, n.authority ?? Ku(u))), f = Bu(d, n), p = a({
|
|
7053
7057
|
membershipEpoch: l?.membership_epoch ?? null,
|
|
7054
7058
|
requiredEpoch: u?.membership_epoch ?? null
|
|
7055
7059
|
});
|
|
@@ -7127,47 +7131,47 @@ function Zu(t, n) {
|
|
|
7127
7131
|
}
|
|
7128
7132
|
//#endregion
|
|
7129
7133
|
//#region src/tags.ts
|
|
7130
|
-
var
|
|
7131
|
-
function
|
|
7134
|
+
var Zu = new Set(/* @__PURE__ */ "the.and.for.with.this.that.from.are.was.were.has.have.had.not.but.can.will.all.been.each.which.their.said.its.into.than.other.some.could.them.about.then.made.after.many.also.did.just.should.over.such.there.would.more.now.very.when.what.your.how.out.our.his.her.she.him.most".split("."));
|
|
7135
|
+
function Qu(e, t) {
|
|
7132
7136
|
let n = (e || "").trim().toLowerCase();
|
|
7133
|
-
return !n || (n = n.replace(/[^a-z0-9_]+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, ""), !n) || (t ??
|
|
7137
|
+
return !n || (n = n.replace(/[^a-z0-9_]+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, ""), !n) || (t ?? Zu).has(n) ? "" : (n.length > 40 && (n = n.slice(0, 40).replace(/-$/, "")), n);
|
|
7134
7138
|
}
|
|
7135
|
-
function
|
|
7139
|
+
function $u(e, t) {
|
|
7136
7140
|
let n = (e || "").trim();
|
|
7137
7141
|
if (!n) return [];
|
|
7138
7142
|
let r = n.split(/[\\/]+/).filter((e) => !!e && e !== "." && e !== "..");
|
|
7139
7143
|
if (!r.length) return [];
|
|
7140
7144
|
let i = [], a = r.at(-1);
|
|
7141
7145
|
if (a) {
|
|
7142
|
-
let e =
|
|
7146
|
+
let e = Qu(a, t);
|
|
7143
7147
|
e && i.push(e);
|
|
7144
7148
|
}
|
|
7145
7149
|
if (r.length >= 2) {
|
|
7146
7150
|
let e = r.at(-2);
|
|
7147
7151
|
if (e) {
|
|
7148
|
-
let n =
|
|
7152
|
+
let n = Qu(e, t);
|
|
7149
7153
|
n && i.push(n);
|
|
7150
7154
|
}
|
|
7151
7155
|
}
|
|
7152
7156
|
if (r.length >= 3) {
|
|
7153
7157
|
let e = r.at(0);
|
|
7154
7158
|
if (e) {
|
|
7155
|
-
let n =
|
|
7159
|
+
let n = Qu(e, t);
|
|
7156
7160
|
n && i.push(n);
|
|
7157
7161
|
}
|
|
7158
7162
|
}
|
|
7159
7163
|
return i;
|
|
7160
7164
|
}
|
|
7161
|
-
function
|
|
7162
|
-
let t = e.stopwords ??
|
|
7165
|
+
function ed(e) {
|
|
7166
|
+
let t = e.stopwords ?? Zu, n = [], r = Qu(e.kind, t);
|
|
7163
7167
|
r && n.push(r);
|
|
7164
7168
|
for (let r of e.concepts ?? []) {
|
|
7165
|
-
let e =
|
|
7169
|
+
let e = Qu(r, t);
|
|
7166
7170
|
e && n.push(e);
|
|
7167
7171
|
}
|
|
7168
|
-
for (let r of [...e.filesRead ?? [], ...e.filesModified ?? []]) n.push(
|
|
7172
|
+
for (let r of [...e.filesRead ?? [], ...e.filesModified ?? []]) n.push(...$u(r, t));
|
|
7169
7173
|
if (!n.length && e.title) for (let r of e.title.toLowerCase().matchAll(/[a-z0-9_]+/g)) {
|
|
7170
|
-
let e =
|
|
7174
|
+
let e = Qu(r[0], t);
|
|
7171
7175
|
e && n.push(e);
|
|
7172
7176
|
}
|
|
7173
7177
|
let i = [], a = /* @__PURE__ */ new Set();
|
|
@@ -7176,7 +7180,7 @@ function td(e) {
|
|
|
7176
7180
|
}
|
|
7177
7181
|
//#endregion
|
|
7178
7182
|
//#region src/sync-replication.ts
|
|
7179
|
-
var
|
|
7183
|
+
var td = "local-default", nd = "access_cleanup", rd = "__codemem_scoped_null_baseline_bootstrap__";
|
|
7180
7184
|
function id(e) {
|
|
7181
7185
|
let t = lf(e.payload_json);
|
|
7182
7186
|
return {
|
|
@@ -7257,7 +7261,7 @@ function dd(e) {
|
|
|
7257
7261
|
let t = (e.tags_text ?? "").trim();
|
|
7258
7262
|
if (t) return t;
|
|
7259
7263
|
let n = Array.isArray(e.concepts) ? e.concepts.map(String) : [], r = Array.isArray(e.files_read) ? e.files_read.map(String) : [], i = Array.isArray(e.files_modified) ? e.files_modified.map(String) : [];
|
|
7260
|
-
return
|
|
7264
|
+
return ed({
|
|
7261
7265
|
kind: e.kind ?? "",
|
|
7262
7266
|
title: e.title ?? void 0,
|
|
7263
7267
|
concepts: n,
|
|
@@ -7271,7 +7275,7 @@ function fd(e) {
|
|
|
7271
7275
|
}
|
|
7272
7276
|
function pd(e) {
|
|
7273
7277
|
let t = String(e ?? "").trim();
|
|
7274
|
-
return t.length > 0 ? t :
|
|
7278
|
+
return t.length > 0 ? t : td;
|
|
7275
7279
|
}
|
|
7276
7280
|
function md(e) {
|
|
7277
7281
|
return e !== void 0;
|
|
@@ -7306,7 +7310,7 @@ function yd(e) {
|
|
|
7306
7310
|
e.exec(`
|
|
7307
7311
|
INSERT OR IGNORE INTO sync_reset_state_v2
|
|
7308
7312
|
(scope_id, generation, snapshot_id, baseline_cursor, retained_floor_cursor, updated_at)
|
|
7309
|
-
SELECT '${
|
|
7313
|
+
SELECT '${td}', generation, snapshot_id, baseline_cursor, retained_floor_cursor, updated_at
|
|
7310
7314
|
FROM sync_reset_state
|
|
7311
7315
|
WHERE id = 1
|
|
7312
7316
|
`);
|
|
@@ -7412,7 +7416,7 @@ function Od(e) {
|
|
|
7412
7416
|
e.exec(`
|
|
7413
7417
|
INSERT OR IGNORE INTO replication_cursors_v2
|
|
7414
7418
|
(peer_device_id, scope_id, last_applied_cursor, last_acked_cursor, updated_at)
|
|
7415
|
-
SELECT peer_device_id, '${
|
|
7419
|
+
SELECT peer_device_id, '${td}', last_applied_cursor, last_acked_cursor, updated_at
|
|
7416
7420
|
FROM replication_cursors
|
|
7417
7421
|
`);
|
|
7418
7422
|
}
|
|
@@ -7465,19 +7469,11 @@ function jd(e, t, n = {}, r) {
|
|
|
7465
7469
|
function Md(e, t, n) {
|
|
7466
7470
|
Dd(e);
|
|
7467
7471
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = pd(n);
|
|
7468
|
-
P(e, { schema: H }).
|
|
7469
|
-
peer_device_id: t,
|
|
7470
|
-
scope_id: i,
|
|
7472
|
+
P(e, { schema: H }).update(dt).set({
|
|
7471
7473
|
last_applied_cursor: null,
|
|
7472
7474
|
last_acked_cursor: null,
|
|
7473
7475
|
updated_at: r
|
|
7474
|
-
}).
|
|
7475
|
-
target: [dt.peer_device_id, dt.scope_id],
|
|
7476
|
-
set: {
|
|
7477
|
-
last_applied_cursor: null,
|
|
7478
|
-
updated_at: N`excluded.updated_at`
|
|
7479
|
-
}
|
|
7480
|
-
}).run();
|
|
7476
|
+
}).where(k(A(dt.peer_device_id, t), A(dt.scope_id, i))).run();
|
|
7481
7477
|
}
|
|
7482
7478
|
var Nd = [
|
|
7483
7479
|
"op_id",
|
|
@@ -7510,7 +7506,7 @@ function Id(e, t) {
|
|
|
7510
7506
|
return e[0] === t[0] ? e[1] === t[1] ? e[2] > t[2] : e[1] > t[1] : e[0] > t[0];
|
|
7511
7507
|
}
|
|
7512
7508
|
function Ld(e, t) {
|
|
7513
|
-
let n = P(e, { schema: H }), r = t.opId ?? h(), i = t.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(), a = n.select().from(W).where(A(W.id, t.memoryId)).get(), o = t.clockRev ?? Number(a?.rev ?? 0), s = t.clockUpdatedAt ?? a?.updated_at ?? i, c = a?.import_key ?? String(t.memoryId), l = Gn(a?.metadata_json), u = t.scopeId === void 0 ? a ?
|
|
7509
|
+
let n = P(e, { schema: H }), r = t.opId ?? h(), i = t.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(), a = n.select().from(W).where(A(W.id, t.memoryId)).get(), o = t.clockRev ?? Number(a?.rev ?? 0), s = t.clockUpdatedAt ?? a?.updated_at ?? i, c = a?.import_key ?? String(t.memoryId), l = Gn(a?.metadata_json), u = t.scopeId === void 0 ? a ? Cl(e, t.memoryId) : null : t.scopeId, d = typeof t.clockDeviceId == "string" && t.clockDeviceId.trim().length > 0 ? t.clockDeviceId.trim() : typeof l.clock_device_id == "string" && l.clock_device_id.trim().length > 0 ? l.clock_device_id : t.deviceId, f = a?.session_id ? n.select({ project: U.project }).from(U).where(A(U.id, a.session_id)).get()?.project ?? null : null, p;
|
|
7514
7510
|
if (t.payload) p = Z(a && t.opType === "upsert" ? {
|
|
7515
7511
|
...t.payload,
|
|
7516
7512
|
scope_id: u
|
|
@@ -7580,14 +7576,14 @@ function Rd(e, t) {
|
|
|
7580
7576
|
op_id: r,
|
|
7581
7577
|
entity_type: "memory_item",
|
|
7582
7578
|
entity_id: t.importKey,
|
|
7583
|
-
op_type:
|
|
7579
|
+
op_type: nd,
|
|
7584
7580
|
payload_json: Z(a),
|
|
7585
7581
|
clock_rev: t.clockRev,
|
|
7586
7582
|
clock_updated_at: t.clockUpdatedAt,
|
|
7587
7583
|
clock_device_id: t.clockDeviceId ?? t.deviceId,
|
|
7588
7584
|
device_id: t.deviceId,
|
|
7589
7585
|
created_at: i,
|
|
7590
|
-
scope_id:
|
|
7586
|
+
scope_id: td
|
|
7591
7587
|
}).run(), r;
|
|
7592
7588
|
}
|
|
7593
7589
|
function zd(e) {
|
|
@@ -7606,7 +7602,7 @@ function Vd(e, t, n = 100, r, i) {
|
|
|
7606
7602
|
s.push(ve(j(o.created_at, t), k(A(o.created_at, t), j(o.op_id, n))));
|
|
7607
7603
|
}
|
|
7608
7604
|
}
|
|
7609
|
-
r && s.push(ve(A(o.device_id, r), A(o.device_id, "local"))), c && s.push(l === "local-default" ? ve(pe(o.scope_id), A(o.scope_id,
|
|
7605
|
+
r && s.push(ve(k(A(o.device_id, r), A(o.clock_device_id, r)), A(o.device_id, "local"))), c && s.push(l === "local-default" ? ve(pe(o.scope_id), A(o.scope_id, td)) : A(o.scope_id, l));
|
|
7610
7606
|
let u = s.length > 0 ? k(...s) : void 0, d = a.select().from(o).where(u).orderBy(o.created_at, o.op_id).limit(n).all(), f = d.map((e) => ({
|
|
7611
7607
|
op_id: e.op_id,
|
|
7612
7608
|
entity_type: e.entity_type,
|
|
@@ -7647,7 +7643,7 @@ function Ud(e, t) {
|
|
|
7647
7643
|
let a = Math.max(1, Math.min(t.limit ?? 200, 5e3)), o = gd(t.pageToken), s = P(e, { schema: H }), c = Math.max(a, Math.min(a * 3, 1e4)), l = (e, t) => s.select({
|
|
7648
7644
|
memory: W,
|
|
7649
7645
|
sessionProject: U.project
|
|
7650
|
-
}).from(W).innerJoin(U, A(U.id, W.session_id)).where(k(fe(W.import_key), r === "local-default" ? ve(pe(W.scope_id), A(W.scope_id,
|
|
7646
|
+
}).from(W).innerJoin(U, A(U.id, W.session_id)).where(k(fe(W.import_key), r === "local-default" ? ve(pe(W.scope_id), A(W.scope_id, td)) : A(W.scope_id, r), e ? ve(j(W.import_key, e.importKey), k(A(W.import_key, e.importKey), j(W.id, e.id))) : void 0)).orderBy(W.import_key, W.id).limit(t).all(), u = [], d = o, f = null, p = !1;
|
|
7651
7647
|
for (; u.length < a;) {
|
|
7652
7648
|
let n = l(d, c);
|
|
7653
7649
|
if (n.length === 0) break;
|
|
@@ -7913,7 +7909,7 @@ function af(e, t) {
|
|
|
7913
7909
|
authorized: !1,
|
|
7914
7910
|
state: "missing_peer_or_actor"
|
|
7915
7911
|
};
|
|
7916
|
-
let i = `personal:${r}`, a =
|
|
7912
|
+
let i = `personal:${r}`, a = Xu(e, {
|
|
7917
7913
|
deviceId: n,
|
|
7918
7914
|
scopeId: i
|
|
7919
7915
|
});
|
|
@@ -8008,14 +8004,14 @@ function hf(e, t, n, r, i) {
|
|
|
8008
8004
|
if (a === "local-default") return !1;
|
|
8009
8005
|
let o = $(r);
|
|
8010
8006
|
if (!o) return !1;
|
|
8011
|
-
let s =
|
|
8007
|
+
let s = Xu(e, {
|
|
8012
8008
|
deviceId: o,
|
|
8013
8009
|
scopeId: a
|
|
8014
8010
|
});
|
|
8015
8011
|
if (!s.authorized || s.scope?.authority_type === "local") return !1;
|
|
8016
8012
|
let c = $(i);
|
|
8017
8013
|
if (!c) return !0;
|
|
8018
|
-
let l =
|
|
8014
|
+
let l = Xu(e, {
|
|
8019
8015
|
deviceId: c,
|
|
8020
8016
|
scopeId: a
|
|
8021
8017
|
});
|
|
@@ -8179,7 +8175,7 @@ function Sf(e, t, n) {
|
|
|
8179
8175
|
}));
|
|
8180
8176
|
continue;
|
|
8181
8177
|
}
|
|
8182
|
-
let u =
|
|
8178
|
+
let u = Xu(e, {
|
|
8183
8179
|
deviceId: r,
|
|
8184
8180
|
scopeId: l
|
|
8185
8181
|
});
|
|
@@ -8253,13 +8249,13 @@ function Of(e, t, n, r) {
|
|
|
8253
8249
|
if (!s) return Cf(t, "missing_scope", i, null);
|
|
8254
8250
|
if (s === "local-default" || Ef(s, lf(t.payload_json))) return Cf(t, "scope_mismatch", i, s);
|
|
8255
8251
|
if (!a || $(t.device_id) !== a || $(t.clock_device_id) !== a) return Cf(t, "sender_not_member", i, s);
|
|
8256
|
-
let c = Df(
|
|
8252
|
+
let c = Df(Xu(e, {
|
|
8257
8253
|
deviceId: a,
|
|
8258
8254
|
scopeId: s
|
|
8259
8255
|
}), "sender_not_member");
|
|
8260
8256
|
if (c) return Cf(t, c, i, s);
|
|
8261
8257
|
if (!o) return Cf(t, "receiver_not_member", i, s);
|
|
8262
|
-
let l = Df(
|
|
8258
|
+
let l = Df(Xu(e, {
|
|
8263
8259
|
deviceId: o,
|
|
8264
8260
|
scopeId: s
|
|
8265
8261
|
}), "receiver_not_member");
|
|
@@ -8424,7 +8420,7 @@ function zf(e, t = 200) {
|
|
|
8424
8420
|
if (n.select({ one: N`1` }).from(J).where(A(J.op_id, m)).limit(1).get()) continue;
|
|
8425
8421
|
let h = s;
|
|
8426
8422
|
if (!h) continue;
|
|
8427
|
-
let g =
|
|
8423
|
+
let g = Cl(e, r), _ = Vf({
|
|
8428
8424
|
...t,
|
|
8429
8425
|
scope_id: g
|
|
8430
8426
|
});
|
|
@@ -8492,7 +8488,7 @@ function Vf(e) {
|
|
|
8492
8488
|
};
|
|
8493
8489
|
}
|
|
8494
8490
|
function Hf(e, t, n, r, i = {}) {
|
|
8495
|
-
let a = P(e, { schema: H }), o = r ?? new
|
|
8491
|
+
let a = P(e, { schema: H }), o = r ?? new Al(), s = Mf(), c = i.inboundScopeValidation;
|
|
8496
8492
|
if (c) {
|
|
8497
8493
|
let r = Nf(e, t, n, c);
|
|
8498
8494
|
if (r) return r;
|
|
@@ -8547,7 +8543,7 @@ function Hf(e, t, n, r, i = {}) {
|
|
|
8547
8543
|
}
|
|
8548
8544
|
let u = ud(r, s.errors);
|
|
8549
8545
|
if (!u) continue;
|
|
8550
|
-
|
|
8546
|
+
Fl(u, o);
|
|
8551
8547
|
let p = wd(u.metadata_json, r.clock_device_id), m = od(u.title, i.title), h = od(u.body_text, i.body_text), g = m !== (i.title ?? "") || h !== (i.body_text ?? ""), _ = Number(i.active ?? 1) === 0 || i.deleted_at != null, v = u.active == null ? Number(i.active ?? 1) : Number(u.active), y = u.has_deleted_at ? u.deleted_at : i.deleted_at ?? null, b = v !== 0 && y == null, x = u.deleted_at != null || u.active != null && Number(u.active) === 0, S = !x && (g || _ && b);
|
|
8552
8548
|
a.update(W).set({
|
|
8553
8549
|
kind: N`COALESCE(${u.kind}, ${W.kind})`,
|
|
@@ -8582,7 +8578,7 @@ function Hf(e, t, n, r, i = {}) {
|
|
|
8582
8578
|
} else {
|
|
8583
8579
|
let i = ud(r, s.errors);
|
|
8584
8580
|
if (!i) continue;
|
|
8585
|
-
|
|
8581
|
+
Fl(i, o);
|
|
8586
8582
|
let c = typeof i.project == "string" && i.project.trim() ? i.project.trim() : null, l = Wf(a, null, r.clock_updated_at, c), u = wd(i.metadata_json, r.clock_device_id), p = a.insert(W).values({
|
|
8587
8583
|
session_id: l,
|
|
8588
8584
|
kind: i.kind ?? "discovery",
|
|
@@ -8743,7 +8739,7 @@ function $f(e) {
|
|
|
8743
8739
|
}
|
|
8744
8740
|
var ep = "Legacy synced peer", tp = "shared:legacy", np = 36e5, rp = "CODEMEM_MEMORY_CROSS_SESSION_DEDUP_WINDOW_MS", ip = 864e13, ap = "CODEMEM_DEBUG";
|
|
8745
8741
|
function op(e) {
|
|
8746
|
-
let t =
|
|
8742
|
+
let t = gl(e), n = e.toLowerCase().replace(/\s+/g, " ").trim();
|
|
8747
8743
|
return t || n || null;
|
|
8748
8744
|
}
|
|
8749
8745
|
function sp() {
|
|
@@ -8784,7 +8780,7 @@ var up = class {
|
|
|
8784
8780
|
throw this.db.close(), e;
|
|
8785
8781
|
}
|
|
8786
8782
|
let t = Bt();
|
|
8787
|
-
this.scanner = new
|
|
8783
|
+
this.scanner = new Al(Ml(t));
|
|
8788
8784
|
let n = process.env.CODEMEM_DEVICE_ID?.trim();
|
|
8789
8785
|
if (n) this.deviceId = n;
|
|
8790
8786
|
else {
|
|
@@ -8825,7 +8821,7 @@ var up = class {
|
|
|
8825
8821
|
enqueueVectorWrite(e, t, n) {
|
|
8826
8822
|
if (this.db.inTransaction) return;
|
|
8827
8823
|
let r = null;
|
|
8828
|
-
r =
|
|
8824
|
+
r = Us(this.db, e, t, n).catch(() => {}).finally(() => {
|
|
8829
8825
|
r && this.pendingVectorWrites.delete(r);
|
|
8830
8826
|
}), this.pendingVectorWrites.add(r);
|
|
8831
8827
|
}
|
|
@@ -8902,11 +8898,11 @@ var up = class {
|
|
|
8902
8898
|
let s = Kf(t), c = qf(), l = this.scanner, u = l.scan(n), d = l.scan(r), f = u.redacted, p = d.redacted, m = [], g = a ? a.map((e) => {
|
|
8903
8899
|
let t = l.scan(e);
|
|
8904
8900
|
return m.push(...t.detections), t.redacted;
|
|
8905
|
-
}) : void 0, _ = g ? [...new Set(g)].sort().join(" ") : "", v = l.redactValue(o ?? {}), y = { ...v.value }, b =
|
|
8901
|
+
}) : void 0, _ = g ? [...new Set(g)].sort().join(" ") : "", v = l.redactValue(o ?? {}), y = { ...v.value }, b = _l(f);
|
|
8906
8902
|
y.clock_device_id ??= this.deviceId;
|
|
8907
8903
|
let x = y.import_key || h();
|
|
8908
8904
|
y.import_key = x;
|
|
8909
|
-
let S = typeof y.subtitle == "string" ? y.subtitle : null, C = typeof y.narrative == "string" ? y.narrative : null, w = Array.isArray(y.facts) ? y.facts : null, ee = Array.isArray(y.concepts) ? y.concepts : null, te = Array.isArray(y.files_read) ? y.files_read : null, ne = Array.isArray(y.files_modified) ? y.files_modified : null, re = typeof y.prompt_number == "number" ? y.prompt_number : null, ie = typeof y.user_prompt_id == "number" ? y.user_prompt_id : null, T = this.resolveProvenance(y), ae =
|
|
8905
|
+
let S = typeof y.subtitle == "string" ? y.subtitle : null, C = typeof y.narrative == "string" ? y.narrative : null, w = Array.isArray(y.facts) ? y.facts : null, ee = Array.isArray(y.concepts) ? y.concepts : null, te = Array.isArray(y.files_read) ? y.files_read : null, ne = Array.isArray(y.files_modified) ? y.files_modified : null, re = typeof y.prompt_number == "number" ? y.prompt_number : null, ie = typeof y.user_prompt_id == "number" ? y.user_prompt_id : null, T = this.resolveProvenance(y), ae = xl(this.db, {
|
|
8910
8906
|
sessionId: e,
|
|
8911
8907
|
workspaceId: T.workspace_id
|
|
8912
8908
|
}), oe = this.d.select({ project: U.project }).from(U).where(A(U.id, e)).get()?.project ?? null, E = this.findExistingDuplicateMemory(e, s, f, b, ae, T, c);
|
|
@@ -8967,7 +8963,7 @@ var up = class {
|
|
|
8967
8963
|
throw t;
|
|
8968
8964
|
}
|
|
8969
8965
|
this.enqueueVectorWrite(D, f, p);
|
|
8970
|
-
let se =
|
|
8966
|
+
let se = Pl(u.detections, d.detections, v.detections);
|
|
8971
8967
|
return se.length > 0 && this.logSecretRedactions(D, s, se), D;
|
|
8972
8968
|
}
|
|
8973
8969
|
logSecretRedactions(e, t, n) {
|
|
@@ -9160,7 +9156,7 @@ var up = class {
|
|
|
9160
9156
|
if (!t) throw Error("memory not found");
|
|
9161
9157
|
if (!this.memoryOwnedBySelf(t)) throw Error("memory not owned by this device");
|
|
9162
9158
|
if (!this.d.select({ scope_id: $e.scope_id }).from($e).where(k(A($e.scope_id, n), A($e.status, "active"))).get()) throw Error(`scope not found or inactive: ${n}`);
|
|
9163
|
-
let r =
|
|
9159
|
+
let r = Cl(this.db, e);
|
|
9164
9160
|
if (!r) throw Error("memory scope could not be resolved");
|
|
9165
9161
|
if (r === n) {
|
|
9166
9162
|
let t = this.get(e);
|
|
@@ -9223,25 +9219,25 @@ var up = class {
|
|
|
9223
9219
|
}).immediate();
|
|
9224
9220
|
}
|
|
9225
9221
|
search(e, t = 10, n) {
|
|
9226
|
-
return
|
|
9222
|
+
return $o(this, e, t, n);
|
|
9227
9223
|
}
|
|
9228
9224
|
timeline(e, t, n = 3, r = 3, i) {
|
|
9229
|
-
return
|
|
9225
|
+
return rs(this, e, t, n, r, i);
|
|
9230
9226
|
}
|
|
9231
9227
|
explain(e, t, n = 10, r, i) {
|
|
9232
|
-
return
|
|
9228
|
+
return ls(this, e, t, n, r, i);
|
|
9233
9229
|
}
|
|
9234
9230
|
buildMemoryPack(e, t, n, r) {
|
|
9235
|
-
return
|
|
9231
|
+
return fl(this, e, t, n ?? null, r);
|
|
9236
9232
|
}
|
|
9237
9233
|
buildMemoryPackTrace(e, t, n, r) {
|
|
9238
|
-
return
|
|
9234
|
+
return pl(this, e, t, n ?? null, r);
|
|
9239
9235
|
}
|
|
9240
9236
|
async buildMemoryPackAsync(e, t, n, r, i) {
|
|
9241
|
-
return
|
|
9237
|
+
return ml(this, e, t, n ?? null, r, i);
|
|
9242
9238
|
}
|
|
9243
9239
|
async buildMemoryPackTraceAsync(e, t, n, r, i) {
|
|
9244
|
-
return
|
|
9240
|
+
return hl(this, e, t, n ?? null, r, i);
|
|
9245
9241
|
}
|
|
9246
9242
|
normalizeStreamIdentity(e, t) {
|
|
9247
9243
|
let n = e.trim().toLowerCase() || "opencode", r = t.trim();
|
|
@@ -9951,7 +9947,7 @@ function yp(e, t = {}) {
|
|
|
9951
9947
|
let e = new up(n);
|
|
9952
9948
|
try {
|
|
9953
9949
|
for (let n of t.probes ?? []) {
|
|
9954
|
-
let t = bi(n), i =
|
|
9950
|
+
let t = bi(n), i = fl(e, n, 10, null, r ? { project: r } : void 0), a = i.items.map((e) => {
|
|
9955
9951
|
let t = s.find((t) => t.id === e.id), n = t ? vp(t) : Oi(e.kind, e.metadata) === "session_summary" ? {
|
|
9956
9952
|
role: "recap",
|
|
9957
9953
|
reason: "session_summary_kind"
|
|
@@ -10318,7 +10314,7 @@ function kp(e, t = {}) {
|
|
|
10318
10314
|
${f}
|
|
10319
10315
|
WHERE ${d}
|
|
10320
10316
|
ORDER BY memory_items.created_at ASC
|
|
10321
|
-
${p}`).all(...c), h = t.scanner ?? new
|
|
10317
|
+
${p}`).all(...c), h = t.scanner ?? new Al(), g = 0, _ = 0, v = 0, y = (/* @__PURE__ */ new Date()).toISOString(), b = e.prepare("UPDATE memory_items SET tags_text = ?, updated_at = ? WHERE id = ?"), x = [];
|
|
10322
10318
|
for (let e of m) {
|
|
10323
10319
|
g += 1;
|
|
10324
10320
|
let t = Op({
|
|
@@ -10491,7 +10487,7 @@ function zp(e, t = {}) {
|
|
|
10491
10487
|
AND body_text IS NOT NULL
|
|
10492
10488
|
AND LENGTH(body_text) > 0
|
|
10493
10489
|
ORDER BY created_at ASC
|
|
10494
|
-
${n}`).all(), i = t.scanner ?? new
|
|
10490
|
+
${n}`).all(), i = t.scanner ?? new Al(), a = 0, o = 0, s = 0, c = [];
|
|
10495
10491
|
for (let e of r) {
|
|
10496
10492
|
a++;
|
|
10497
10493
|
let t = Rp(e.body_text);
|
|
@@ -10544,7 +10540,7 @@ function Hp(e, t = {}) {
|
|
|
10544
10540
|
}), i = t.updateLimit != null && t.updateLimit > 0 ? t.updateLimit : null, a = 0, o = 0, s = 0, c = 0, l = [], u = /* @__PURE__ */ new Set(), d = e.prepare("SELECT 1 AS ok\n FROM memory_items\n WHERE id != ?\n AND active = 1\n AND session_id = ?\n AND kind = ?\n AND visibility IS ?\n AND workspace_id IS ?\n AND dedup_key = ?\n LIMIT 1");
|
|
10545
10541
|
for (let e of r) {
|
|
10546
10542
|
a++;
|
|
10547
|
-
let t =
|
|
10543
|
+
let t = _l(e.title);
|
|
10548
10544
|
if (!t) {
|
|
10549
10545
|
s++;
|
|
10550
10546
|
continue;
|
|
@@ -12107,7 +12103,7 @@ async function Ah(e, t = {}) {
|
|
|
12107
12103
|
${i}`).all(...n).filter((e) => !Ei({
|
|
12108
12104
|
kind: e.kind,
|
|
12109
12105
|
metadata: e.metadata_json
|
|
12110
|
-
})), s = t.observer ?? wh(), c = t.scanner ?? new
|
|
12106
|
+
})), s = t.observer ?? wh(), c = t.scanner ?? new Al(), l = o.length;
|
|
12111
12107
|
si(e, {
|
|
12112
12108
|
kind: xh,
|
|
12113
12109
|
title: "Backfilling structured content",
|
|
@@ -12239,7 +12235,7 @@ function Nh(e, t) {
|
|
|
12239
12235
|
} else i.push(e);
|
|
12240
12236
|
return {
|
|
12241
12237
|
json: a ? JSON.stringify(i) : e,
|
|
12242
|
-
detections:
|
|
12238
|
+
detections: Pl(...r),
|
|
12243
12239
|
changed: a
|
|
12244
12240
|
};
|
|
12245
12241
|
}
|
|
@@ -12288,7 +12284,7 @@ function Fh(e, t) {
|
|
|
12288
12284
|
}
|
|
12289
12285
|
return {
|
|
12290
12286
|
text: a ? i.join(" ") : e,
|
|
12291
|
-
detections:
|
|
12287
|
+
detections: Pl(...r),
|
|
12292
12288
|
changed: a
|
|
12293
12289
|
};
|
|
12294
12290
|
}
|
|
@@ -12315,7 +12311,7 @@ function Lh(e) {
|
|
|
12315
12311
|
}
|
|
12316
12312
|
}
|
|
12317
12313
|
function Rh(e, t = {}) {
|
|
12318
|
-
let n = t.scanner ?? new
|
|
12314
|
+
let n = t.scanner ?? new Al(), r = t.dryRun === !0, i = t.maxRowBytes ?? jh, a = typeof t.limit == "number" && Number.isInteger(t.limit) && t.limit > 0 ? `LIMIT ${Number(t.limit)}` : "", o = e.prepare(`SELECT id, rev, title, subtitle, body_text, narrative, tags_text,
|
|
12319
12315
|
facts, concepts, files_read, files_modified, metadata_json,
|
|
12320
12316
|
actor_display_name, origin_source
|
|
12321
12317
|
FROM memory_items
|
|
@@ -12332,7 +12328,7 @@ function Rh(e, t = {}) {
|
|
|
12332
12328
|
if (!(a.changed || o.changed || c.changed || h.changed || g.changed || _.changed || v.changed || y.changed || b.changed || x.changed || S.changed || C.changed)) continue;
|
|
12333
12329
|
let w = () => {
|
|
12334
12330
|
l(a.detections), l(o.detections), l(c.detections), l(h.detections), l(g.detections), l(_.detections), l(v.detections), l(y.detections), l(b.detections), l(x.detections), l(S.detections), l(C.detections);
|
|
12335
|
-
let e =
|
|
12331
|
+
let e = Pl(a.detections, o.detections, c.detections, h.detections, g.detections, _.detections, v.detections, y.detections, b.detections, x.detections, S.detections, C.detections);
|
|
12336
12332
|
u.push({
|
|
12337
12333
|
id: t.id,
|
|
12338
12334
|
redactedTitle: a.value,
|
|
@@ -12394,7 +12390,7 @@ function Hh(e = Bt()) {
|
|
|
12394
12390
|
async function Uh(e, t, n, r, i) {
|
|
12395
12391
|
let a = { "X-Codemem-Coordinator-Admin": n }, o = String(i ?? "").trim();
|
|
12396
12392
|
o && (a["X-Codemem-Coordinator-Admin-Actor"] = o);
|
|
12397
|
-
let [s, c] = await
|
|
12393
|
+
let [s, c] = await Wl(e, t, {
|
|
12398
12394
|
headers: a,
|
|
12399
12395
|
body: r,
|
|
12400
12396
|
timeoutS: 3
|
|
@@ -12410,7 +12406,7 @@ function Wh(e) {
|
|
|
12410
12406
|
if (!t) return [];
|
|
12411
12407
|
let n = "";
|
|
12412
12408
|
try {
|
|
12413
|
-
n = new URL(
|
|
12409
|
+
n = new URL(Ul(t)).hostname.trim().toLowerCase();
|
|
12414
12410
|
} catch {
|
|
12415
12411
|
return ["Coordinator URL could not be parsed. Double-check that teammates can reach it before sharing this invite."];
|
|
12416
12412
|
}
|
|
@@ -12443,7 +12439,7 @@ async function Kh(e, t, n) {
|
|
|
12443
12439
|
})).find((e) => e.scope_id === n) ?? null;
|
|
12444
12440
|
}
|
|
12445
12441
|
function qh(e, t) {
|
|
12446
|
-
let n = typeof e == "object" && e && "name" in e ? String(e.name) : "", r = e instanceof Error ? e.message : String(e ?? ""), i =
|
|
12442
|
+
let n = typeof e == "object" && e && "name" in e ? String(e.name) : "", r = e instanceof Error ? e.message : String(e ?? ""), i = Ul(t);
|
|
12447
12443
|
return n === "TimeoutError" || /timed? out/i.test(r) ? /* @__PURE__ */ Error(`Invite import timed out contacting the coordinator at ${i}. Check that this machine can reach that URL and try again.`) : n === "TypeError" || /fetch failed|network/i.test(r) ? /* @__PURE__ */ Error(`Invite import could not reach the coordinator at ${i}. Check the invite URL and this machine's network access before retrying.`) : e instanceof Error ? e : Error(r);
|
|
12448
12444
|
}
|
|
12449
12445
|
async function Jh(e) {
|
|
@@ -12949,7 +12945,7 @@ async function fg(e) {
|
|
|
12949
12945
|
if (m && m !== h) throw Error(`This device is already enrolled with coordinator ${m}. Multi-team joining is only supported across groups on the same coordinator.`);
|
|
12950
12946
|
let g = 0, _ = null;
|
|
12951
12947
|
try {
|
|
12952
|
-
[g, _] = await
|
|
12948
|
+
[g, _] = await Wl("POST", `${Vh(u)}/v1/join`, {
|
|
12953
12949
|
body: {
|
|
12954
12950
|
token: String(t.token),
|
|
12955
12951
|
device_id: o,
|
|
@@ -13439,7 +13435,7 @@ function t_(e, t, n) {
|
|
|
13439
13435
|
if (!Ig(e, r, n)) throw Error(`unauthorized_scope: ${r}`);
|
|
13440
13436
|
return r;
|
|
13441
13437
|
}
|
|
13442
|
-
return
|
|
13438
|
+
return xl(e, {
|
|
13443
13439
|
sessionId: Number(t.session_id),
|
|
13444
13440
|
workspaceId: Ng(t.workspace_id)
|
|
13445
13441
|
});
|
|
@@ -15112,7 +15108,7 @@ async function $v(e, t, n) {
|
|
|
15112
15108
|
for (let e of de) {
|
|
15113
15109
|
let n = e.kind.trim().toLowerCase(), r = [];
|
|
15114
15110
|
e.narrative && r.push(e.narrative), e.facts.length > 0 && r.push(e.facts.map((e) => `- ${e}`).join("\n"));
|
|
15115
|
-
let i = r.join("\n\n"), a = e.title || e.narrative, o =
|
|
15111
|
+
let i = r.join("\n\n"), a = e.title || e.narrative, o = ed({
|
|
15116
15112
|
kind: n,
|
|
15117
15113
|
title: a,
|
|
15118
15114
|
concepts: e.concepts,
|
|
@@ -15149,7 +15145,7 @@ async function $v(e, t, n) {
|
|
|
15149
15145
|
});
|
|
15150
15146
|
}
|
|
15151
15147
|
if (M) {
|
|
15152
|
-
let { summary: e, request: n, body: r } = M, i = n || "Session summary", a =
|
|
15148
|
+
let { summary: e, request: n, body: r } = M, i = n || "Session summary", a = ed({
|
|
15153
15149
|
kind: "session_summary",
|
|
15154
15150
|
title: i,
|
|
15155
15151
|
filesRead: e.filesRead,
|
|
@@ -15217,7 +15213,7 @@ async function $v(e, t, n) {
|
|
|
15217
15213
|
}).run();
|
|
15218
15214
|
})();
|
|
15219
15215
|
for (let e of me) try {
|
|
15220
|
-
await
|
|
15216
|
+
await Us(t.db, e.memoryId, e.title, e.bodyText);
|
|
15221
15217
|
} catch {}
|
|
15222
15218
|
ey(t, m, i.length, a, {
|
|
15223
15219
|
session_class: fe,
|
|
@@ -15802,7 +15798,7 @@ function Iy(e) {
|
|
|
15802
15798
|
let t = Fy(e), n = Q(e, Dy);
|
|
15803
15799
|
if (n?.status === "running") return !0;
|
|
15804
15800
|
if (t === 0) return !1;
|
|
15805
|
-
if (
|
|
15801
|
+
if (n?.status !== "completed") return !0;
|
|
15806
15802
|
let r = n.metadata ?? {}, i = r.unstamped_replication_ops_at_completion;
|
|
15807
15803
|
if (typeof i != "number" || t > i) return !0;
|
|
15808
15804
|
let a = r.max_stamped_memory_id_at_completion;
|
|
@@ -16076,14 +16072,14 @@ async function ub(e, t, n, r, i) {
|
|
|
16076
16072
|
o.length > 0 && ob(e, o);
|
|
16077
16073
|
let c = s.slice(0, r);
|
|
16078
16074
|
if (c.length > 0) {
|
|
16079
|
-
if (await
|
|
16075
|
+
if (await Ws(e, {
|
|
16080
16076
|
memoryIds: c,
|
|
16081
16077
|
signal: i
|
|
16082
16078
|
}), i?.aborted) return {
|
|
16083
16079
|
completed: !1,
|
|
16084
16080
|
metadata: a
|
|
16085
16081
|
};
|
|
16086
|
-
|
|
16082
|
+
Vs(e, c, n);
|
|
16087
16083
|
}
|
|
16088
16084
|
let l = {
|
|
16089
16085
|
...a,
|
|
@@ -16167,7 +16163,7 @@ async function yb(e, t = {}) {
|
|
|
16167
16163
|
r && ui(e, Qy, "Embeddings are disabled", { message: "Vector re-indexing is waiting for embeddings to be enabled" });
|
|
16168
16164
|
return;
|
|
16169
16165
|
}
|
|
16170
|
-
let i = await
|
|
16166
|
+
let i = await hs();
|
|
16171
16167
|
if (!i) {
|
|
16172
16168
|
r && ui(e, Qy, "Embedding client unavailable", { message: "Vector re-indexing is waiting for the embedding client" });
|
|
16173
16169
|
return;
|
|
@@ -16249,7 +16245,7 @@ async function yb(e, t = {}) {
|
|
|
16249
16245
|
});
|
|
16250
16246
|
let g = mb(e, h.last_cursor_id ?? 0, o), _ = g.map((e) => e.id), v = g.filter(hb).length, y = g.at(-1)?.id ?? h.last_cursor_id ?? 0, b = Math.min(p, (h.processed_embeddable ?? 0) + v);
|
|
16251
16247
|
if (_.length > 0) {
|
|
16252
|
-
if (await
|
|
16248
|
+
if (await Ws(e, {
|
|
16253
16249
|
memoryIds: _,
|
|
16254
16250
|
signal: t.signal
|
|
16255
16251
|
}), t.signal?.aborted) return;
|
|
@@ -16354,7 +16350,7 @@ var bb = class {
|
|
|
16354
16350
|
let e = t.metadata ?? {};
|
|
16355
16351
|
return !(ib(e.pending_upsert_memory_ids).length + ib(e.pending_delete_memory_ids).length > 0);
|
|
16356
16352
|
}
|
|
16357
|
-
let n =
|
|
16353
|
+
let n = ms();
|
|
16358
16354
|
try {
|
|
16359
16355
|
let t = e.prepare("SELECT COUNT(*) AS c FROM memory_items\n WHERE active = 1\n AND TRIM(COALESCE(title, '') || COALESCE(body_text, '')) != ''\n AND id NOT IN (SELECT DISTINCT memory_id FROM memory_vectors WHERE model = ?)").get(n);
|
|
16360
16356
|
return Number(t?.c ?? 0) > 0 ? !1 : vb(e, n) === null;
|
|
@@ -16372,7 +16368,7 @@ async function Sb(e, t, n, r) {
|
|
|
16372
16368
|
limit: String(i)
|
|
16373
16369
|
});
|
|
16374
16370
|
t.baseline_cursor && r.set("baseline_cursor", t.baseline_cursor), t.scope_id && r.set("scope_id", t.scope_id), u && r.set("page_token", u);
|
|
16375
|
-
let f = `${e}/v1/snapshot?${r.toString()}`, [p, m] = await
|
|
16371
|
+
let f = `${e}/v1/snapshot?${r.toString()}`, [p, m] = await Wl("GET", f, {
|
|
16376
16372
|
headers: {
|
|
16377
16373
|
...yr({
|
|
16378
16374
|
deviceId: n,
|
|
@@ -16387,8 +16383,8 @@ async function Sb(e, t, n, r) {
|
|
|
16387
16383
|
timeoutS: a
|
|
16388
16384
|
});
|
|
16389
16385
|
if (p !== 200 || !m) {
|
|
16390
|
-
let e = m?.error ? String(m.error) : `status ${p}`;
|
|
16391
|
-
throw Error(`snapshot fetch failed: ${
|
|
16386
|
+
let e = m?.error ? String(m.error) : "", t = m?.reason ? String(m.reason) : "", n = e ? t ? `${e}:${t}` : e : `status ${p}`;
|
|
16387
|
+
throw Error(`snapshot fetch failed: ${n}`);
|
|
16392
16388
|
}
|
|
16393
16389
|
let h = m;
|
|
16394
16390
|
if (!Array.isArray(h.items) || h.generation == null) throw Error("invalid snapshot response shape");
|
|
@@ -16446,14 +16442,14 @@ function kb(e, t, n, r, i) {
|
|
|
16446
16442
|
ok: !1,
|
|
16447
16443
|
applied: 0,
|
|
16448
16444
|
deleted: 0
|
|
16449
|
-
}, o = i ?? new
|
|
16445
|
+
}, o = i ?? new Al(), s = Tb(r.scope_id), c = s ? A(W.scope_id, s) : ve(pe(W.scope_id), A(W.scope_id, td));
|
|
16450
16446
|
return e.transaction(() => {
|
|
16451
16447
|
let i = P(e, { schema: H }), l = 0;
|
|
16452
16448
|
a.deleted = i.delete(W).where(k(fe(W.import_key), c, _e(N`COALESCE(${W.visibility}, '')`, "private"))).run().changes, Db.clear();
|
|
16453
16449
|
for (let e of n) {
|
|
16454
16450
|
let t = Cb(e);
|
|
16455
16451
|
if (!t) continue;
|
|
16456
|
-
|
|
16452
|
+
Fl(t, o);
|
|
16457
16453
|
let n = Eb(t, s), r = typeof t.project == "string" && t.project.trim() ? t.project.trim() : null, c = Ob(i, (/* @__PURE__ */ new Date()).toISOString(), r), u = t.metadata_json, d = u && typeof u == "object" && !Array.isArray(u) ? u : {};
|
|
16458
16454
|
d.clock_device_id = e.clock_device_id;
|
|
16459
16455
|
let f = e.op_type === "delete";
|
|
@@ -16491,7 +16487,10 @@ function kb(e, t, n, r, i) {
|
|
|
16491
16487
|
project: r
|
|
16492
16488
|
}).run(), a.applied++;
|
|
16493
16489
|
}
|
|
16494
|
-
r.baseline_cursor &&
|
|
16490
|
+
(r.baseline_cursor || r.scope_id) && (r.scope_id && !r.baseline_cursor && Md(e, t, r.scope_id), jd(e, t, {
|
|
16491
|
+
lastApplied: r.baseline_cursor,
|
|
16492
|
+
lastAcked: r.baseline_cursor ? void 0 : rd
|
|
16493
|
+
}, r.scope_id)), Sd(e, {
|
|
16495
16494
|
generation: r.generation,
|
|
16496
16495
|
snapshot_id: r.snapshot_id,
|
|
16497
16496
|
baseline_cursor: r.baseline_cursor
|
|
@@ -17791,7 +17790,7 @@ var Zx = class {
|
|
|
17791
17790
|
}
|
|
17792
17791
|
}, Qx = De(import.meta.url), $x = "_codemem._tcp.local.";
|
|
17793
17792
|
function eS(e) {
|
|
17794
|
-
return e.mdns.length === 0 ?
|
|
17793
|
+
return e.mdns.length === 0 ? zl(e.stored, []) : zl(e.mdns, e.stored);
|
|
17795
17794
|
}
|
|
17796
17795
|
function tS(e, t) {
|
|
17797
17796
|
let n = P(e, { schema: H }).select({ addresses_json: Y.addresses_json }).from(Y).where(A(Y.peer_device_id, t)).get();
|
|
@@ -17804,7 +17803,7 @@ function tS(e, t) {
|
|
|
17804
17803
|
}
|
|
17805
17804
|
}
|
|
17806
17805
|
function nS(e, t, n, r) {
|
|
17807
|
-
let i =
|
|
17806
|
+
let i = zl(tS(e, t), n), a = (/* @__PURE__ */ new Date()).toISOString(), o = JSON.stringify(i);
|
|
17808
17807
|
return P(e, { schema: H }).insert(Y).values({
|
|
17809
17808
|
peer_device_id: t,
|
|
17810
17809
|
name: r?.name ?? null,
|
|
@@ -17840,9 +17839,9 @@ function rS(e, t, n) {
|
|
|
17840
17839
|
}).where(A(Y.peer_device_id, t)).run() : r.update(Y).set({ last_error: n.error ?? null }).where(A(Y.peer_device_id, t)).run();
|
|
17841
17840
|
}
|
|
17842
17841
|
function iS(e, t, n) {
|
|
17843
|
-
let r =
|
|
17842
|
+
let r = Il(n ?? ""), i = (/* @__PURE__ */ new Date()).toISOString();
|
|
17844
17843
|
return e.transaction((t, n, r) => {
|
|
17845
|
-
let i = tS(e, t), a = n ? i.filter((e) =>
|
|
17844
|
+
let i = tS(e, t), a = n ? i.filter((e) => Il(e) !== n) : i, o = n ? [n, ...a] : i;
|
|
17846
17845
|
return P(e, { schema: H }).update(Y).set({
|
|
17847
17846
|
addresses_json: JSON.stringify(o),
|
|
17848
17847
|
last_sync_at: r,
|
|
@@ -17871,7 +17870,7 @@ function lS() {
|
|
|
17871
17870
|
let e = process.env.CODEMEM_SYNC_MDNS;
|
|
17872
17871
|
if (e) return e === "1" || e.toLowerCase() === "true";
|
|
17873
17872
|
try {
|
|
17874
|
-
return
|
|
17873
|
+
return au().syncMdns;
|
|
17875
17874
|
} catch {
|
|
17876
17875
|
return !1;
|
|
17877
17876
|
}
|
|
@@ -17965,7 +17964,7 @@ function _S(e, t) {
|
|
|
17965
17964
|
if (!a) continue;
|
|
17966
17965
|
let o = r.address, s = r.host ?? "", c = o && !o.includes(".local") ? o : s;
|
|
17967
17966
|
if (c && !c.includes("_tcp.local") && !c.includes("_udp.local")) {
|
|
17968
|
-
let e = Ll(
|
|
17967
|
+
let e = Il(Ll(c, a));
|
|
17969
17968
|
e && n.push(e);
|
|
17970
17969
|
}
|
|
17971
17970
|
}
|
|
@@ -18005,7 +18004,7 @@ function DS(e) {
|
|
|
18005
18004
|
};
|
|
18006
18005
|
}
|
|
18007
18006
|
function OS(e) {
|
|
18008
|
-
return !(
|
|
18007
|
+
return !(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));
|
|
18009
18008
|
}
|
|
18010
18009
|
function kS(e) {
|
|
18011
18010
|
let t = Xy(e);
|
|
@@ -18054,7 +18053,7 @@ async function FS(e, t, n, r, i = 0) {
|
|
|
18054
18053
|
let a = {
|
|
18055
18054
|
ops: n,
|
|
18056
18055
|
sync_capability: qy
|
|
18057
|
-
}, o = Buffer.from(JSON.stringify(a), "utf-8"), [s, c] = await
|
|
18056
|
+
}, o = Buffer.from(JSON.stringify(a), "utf-8"), [s, c] = await Wl("POST", e, {
|
|
18058
18057
|
headers: {
|
|
18059
18058
|
...yr({
|
|
18060
18059
|
deviceId: t,
|
|
@@ -18109,7 +18108,33 @@ function IS(e) {
|
|
|
18109
18108
|
function LS(e, t) {
|
|
18110
18109
|
return e.prepare("SELECT 1 FROM memory_items WHERE import_key IS NOT NULL AND scope_id = ? LIMIT 1").get(t) !== void 0;
|
|
18111
18110
|
}
|
|
18112
|
-
|
|
18111
|
+
function RS(e) {
|
|
18112
|
+
let t = String(e ?? "").toLowerCase();
|
|
18113
|
+
return t ? t.includes("401") && t.includes("unauthorized") || t.includes("fingerprint mismatch") || t.includes("peer not pinned") ? "trust" : t.includes("scope_rejected") || t.includes("scope rejected") || t.includes("missing_scope") || t.includes("stale_epoch") || t.includes("scope_inactive") ? "scope" : t.includes("no dialable peer addresses") || t.includes("fetch failed") || t.includes("connection refused") || t.includes("network") || t.includes("timeout") || t.includes("503") || t.includes("502") || t.includes("504") || t.includes("peer status failed") || t.includes("peer ops fetch failed") || t.includes("snapshot fetch failed") ? "connectivity" : "other" : "other";
|
|
18114
|
+
}
|
|
18115
|
+
function zS(e) {
|
|
18116
|
+
return RS(e);
|
|
18117
|
+
}
|
|
18118
|
+
function BS(e) {
|
|
18119
|
+
switch (e) {
|
|
18120
|
+
case "missing_scope":
|
|
18121
|
+
case "scope_inactive":
|
|
18122
|
+
case "stale_epoch": return "scope";
|
|
18123
|
+
case "boundary_mismatch":
|
|
18124
|
+
case "generation_mismatch":
|
|
18125
|
+
case "initial_bootstrap":
|
|
18126
|
+
case "stale_cursor":
|
|
18127
|
+
case "unsupported_scope": return "other";
|
|
18128
|
+
}
|
|
18129
|
+
return "other";
|
|
18130
|
+
}
|
|
18131
|
+
function VS(e) {
|
|
18132
|
+
let t = e.filter((e) => !e.ok);
|
|
18133
|
+
if (t.length === 0) return;
|
|
18134
|
+
let n = new Set(t.map((e) => e.failureCategory ?? zS(e.error)));
|
|
18135
|
+
return n.size === 1 ? Array.from(n)[0] : "other";
|
|
18136
|
+
}
|
|
18137
|
+
async function HS(e, t) {
|
|
18113
18138
|
let n = IS(t.statusPayload.authorized_scopes);
|
|
18114
18139
|
if (n.length === 0) return {
|
|
18115
18140
|
results: [],
|
|
@@ -18117,7 +18142,7 @@ async function RS(e, t) {
|
|
|
18117
18142
|
};
|
|
18118
18143
|
let r = [], i = 0;
|
|
18119
18144
|
for (let a of n) {
|
|
18120
|
-
let n = await
|
|
18145
|
+
let n = await US(e, {
|
|
18121
18146
|
peerDeviceId: t.peerDeviceId,
|
|
18122
18147
|
baseUrl: t.baseUrl,
|
|
18123
18148
|
deviceId: t.deviceId,
|
|
@@ -18133,9 +18158,9 @@ async function RS(e, t) {
|
|
|
18133
18158
|
totalOpsIn: i
|
|
18134
18159
|
};
|
|
18135
18160
|
}
|
|
18136
|
-
async function
|
|
18137
|
-
let { peerDeviceId: n, baseUrl: r, deviceId: i, scope: a, keysDir: o, scanner: s, limit: c } = t, l = a.scope_id, [u] = Ad(e, n, l), d = LS(e, l);
|
|
18138
|
-
if (u == null && !
|
|
18161
|
+
async function US(e, t) {
|
|
18162
|
+
let { peerDeviceId: n, baseUrl: r, deviceId: i, scope: a, keysDir: o, scanner: s, limit: c } = t, l = a.scope_id, [u, d] = Ad(e, n, l), f = d === rd, p = f && a.sync_reset.baseline_cursor == null, m = LS(e, l);
|
|
18163
|
+
if (u == null && !m && !p) try {
|
|
18139
18164
|
let t = {
|
|
18140
18165
|
scope_id: l,
|
|
18141
18166
|
generation: a.sync_reset.generation,
|
|
@@ -18152,6 +18177,7 @@ async function zS(e, t) {
|
|
|
18152
18177
|
scope_id: l,
|
|
18153
18178
|
label: a.label,
|
|
18154
18179
|
ok: !1,
|
|
18180
|
+
failureCategory: "other",
|
|
18155
18181
|
opsIn: 0,
|
|
18156
18182
|
opsOut: 0,
|
|
18157
18183
|
error: "needs_attention:shared_memories_appeared_during_bootstrap",
|
|
@@ -18169,20 +18195,22 @@ async function zS(e, t) {
|
|
|
18169
18195
|
scope_id: l,
|
|
18170
18196
|
label: a.label,
|
|
18171
18197
|
ok: !1,
|
|
18198
|
+
failureCategory: "other",
|
|
18172
18199
|
opsIn: 0,
|
|
18173
18200
|
opsOut: 0,
|
|
18174
18201
|
error: "bootstrap apply failed",
|
|
18175
18202
|
bootstrapped: !0
|
|
18176
18203
|
};
|
|
18177
18204
|
} catch (e) {
|
|
18178
|
-
let t = e instanceof Error ? e.message.trim() || e.constructor.name : "unknown"
|
|
18205
|
+
let t = `scoped bootstrap failed: ${e instanceof Error ? e.message.trim() || e.constructor.name : "unknown"}`;
|
|
18179
18206
|
return {
|
|
18180
18207
|
scope_id: l,
|
|
18181
18208
|
label: a.label,
|
|
18182
18209
|
ok: !1,
|
|
18210
|
+
failureCategory: zS(t),
|
|
18183
18211
|
opsIn: 0,
|
|
18184
18212
|
opsOut: 0,
|
|
18185
|
-
error:
|
|
18213
|
+
error: t,
|
|
18186
18214
|
bootstrapped: !0
|
|
18187
18215
|
};
|
|
18188
18216
|
}
|
|
@@ -18195,7 +18223,7 @@ async function zS(e, t) {
|
|
|
18195
18223
|
snapshot_id: a.sync_reset.snapshot_id
|
|
18196
18224
|
});
|
|
18197
18225
|
a.sync_reset.baseline_cursor && t.set("baseline_cursor", a.sync_reset.baseline_cursor);
|
|
18198
|
-
let d = `${r}/v1/ops?${t.toString()}`, [
|
|
18226
|
+
let d = `${r}/v1/ops?${t.toString()}`, [p, m] = await Wl("GET", d, { headers: {
|
|
18199
18227
|
...yr({
|
|
18200
18228
|
deviceId: i,
|
|
18201
18229
|
method: "GET",
|
|
@@ -18205,127 +18233,142 @@ async function zS(e, t) {
|
|
|
18205
18233
|
}),
|
|
18206
18234
|
...AS()
|
|
18207
18235
|
} });
|
|
18208
|
-
if (
|
|
18236
|
+
if (p === 409 && m?.reset_required === !0) {
|
|
18209
18237
|
Md(e, n, l);
|
|
18210
18238
|
let t = (() => {
|
|
18211
|
-
switch (
|
|
18239
|
+
switch (m.reason) {
|
|
18212
18240
|
case "generation_mismatch":
|
|
18213
18241
|
case "boundary_mismatch":
|
|
18214
18242
|
case "missing_scope":
|
|
18215
|
-
case "
|
|
18243
|
+
case "scope_inactive":
|
|
18244
|
+
case "stale_epoch":
|
|
18245
|
+
case "unsupported_scope": return m.reason;
|
|
18216
18246
|
default: return "stale_cursor";
|
|
18217
18247
|
}
|
|
18218
|
-
})()
|
|
18248
|
+
})(), r = `reset_required:${t}`;
|
|
18219
18249
|
return {
|
|
18220
18250
|
scope_id: l,
|
|
18221
18251
|
label: a.label,
|
|
18222
18252
|
ok: !1,
|
|
18253
|
+
failureCategory: BS(t),
|
|
18223
18254
|
opsIn: 0,
|
|
18224
18255
|
opsOut: 0,
|
|
18225
|
-
error:
|
|
18256
|
+
error: r,
|
|
18226
18257
|
resetRequired: {
|
|
18227
18258
|
reset_required: !0,
|
|
18228
18259
|
reason: t,
|
|
18229
|
-
scope_id: typeof
|
|
18230
|
-
generation: Number(
|
|
18231
|
-
snapshot_id: String(
|
|
18232
|
-
baseline_cursor: typeof
|
|
18233
|
-
retained_floor_cursor: typeof
|
|
18260
|
+
scope_id: typeof m.scope_id == "string" ? m.scope_id : l,
|
|
18261
|
+
generation: Number(m.generation ?? a.sync_reset.generation),
|
|
18262
|
+
snapshot_id: String(m.snapshot_id ?? a.sync_reset.snapshot_id),
|
|
18263
|
+
baseline_cursor: typeof m.baseline_cursor == "string" ? m.baseline_cursor.trim() : null,
|
|
18264
|
+
retained_floor_cursor: typeof m.retained_floor_cursor == "string" ? m.retained_floor_cursor.trim() : null
|
|
18234
18265
|
},
|
|
18235
18266
|
bootstrapped: !1
|
|
18236
18267
|
};
|
|
18237
18268
|
}
|
|
18238
|
-
if (
|
|
18239
|
-
let e = wS(
|
|
18269
|
+
if (p !== 200 || m == null) {
|
|
18270
|
+
let e = wS(m), t = `peer scoped ops fetch failed${e ? ` (${p}: ${e})` : ` (${p})`}`;
|
|
18240
18271
|
return {
|
|
18241
18272
|
scope_id: l,
|
|
18242
18273
|
label: a.label,
|
|
18243
18274
|
ok: !1,
|
|
18275
|
+
failureCategory: zS(t),
|
|
18244
18276
|
opsIn: 0,
|
|
18245
18277
|
opsOut: 0,
|
|
18246
|
-
error:
|
|
18278
|
+
error: t,
|
|
18247
18279
|
bootstrapped: !1
|
|
18248
18280
|
};
|
|
18249
18281
|
}
|
|
18250
|
-
if (!OS(
|
|
18282
|
+
if (!OS(m)) return {
|
|
18251
18283
|
scope_id: l,
|
|
18252
18284
|
label: a.label,
|
|
18253
18285
|
ok: !1,
|
|
18286
|
+
failureCategory: "other",
|
|
18254
18287
|
opsIn: 0,
|
|
18255
18288
|
opsOut: 0,
|
|
18256
18289
|
error: "invalid scoped ops response",
|
|
18257
18290
|
bootstrapped: !1
|
|
18258
18291
|
};
|
|
18259
|
-
let
|
|
18260
|
-
if (
|
|
18261
|
-
|
|
18262
|
-
label: a.label,
|
|
18263
|
-
ok: !1,
|
|
18264
|
-
opsIn: 0,
|
|
18265
|
-
opsOut: 0,
|
|
18266
|
-
error: `inbound op device mismatch:${h.op_id}`,
|
|
18267
|
-
bootstrapped: !1
|
|
18268
|
-
};
|
|
18269
|
-
let g = Hf(e, m, i, s, { inboundScopeValidation: { peerDeviceId: n } });
|
|
18270
|
-
if (g.rejected > 0) {
|
|
18271
|
-
let e = g.rejections[0]?.reason ?? "scope_rejected";
|
|
18292
|
+
let h = Pd(m), g = h.find((e) => e.device_id !== n || e.clock_device_id !== n);
|
|
18293
|
+
if (g) {
|
|
18294
|
+
let e = `inbound op device mismatch:${g.op_id}`;
|
|
18272
18295
|
return {
|
|
18273
18296
|
scope_id: l,
|
|
18274
18297
|
label: a.label,
|
|
18275
18298
|
ok: !1,
|
|
18299
|
+
failureCategory: "other",
|
|
18276
18300
|
opsIn: 0,
|
|
18277
18301
|
opsOut: 0,
|
|
18278
|
-
error:
|
|
18302
|
+
error: e,
|
|
18279
18303
|
bootstrapped: !1
|
|
18280
18304
|
};
|
|
18281
18305
|
}
|
|
18282
|
-
let _ =
|
|
18283
|
-
|
|
18284
|
-
|
|
18285
|
-
|
|
18286
|
-
upsertMemoryIds: g.vectorWork.upsertMemoryIds,
|
|
18287
|
-
deleteMemoryIds: [...g.vectorWork.deleteMemoryIds, ..._.deleted_memory_ids]
|
|
18288
|
-
};
|
|
18289
|
-
try {
|
|
18290
|
-
lb(e, v);
|
|
18291
|
-
} catch (t) {
|
|
18292
|
-
let n = await Us(e, v);
|
|
18293
|
-
if (n.errors.length > 0) return {
|
|
18306
|
+
let _ = Hf(e, h, i, s, { inboundScopeValidation: { peerDeviceId: n } });
|
|
18307
|
+
if (_.rejected > 0) {
|
|
18308
|
+
let e = `inbound scope rejected:${_.rejections[0]?.reason ?? "scope_rejected"}`;
|
|
18309
|
+
return {
|
|
18294
18310
|
scope_id: l,
|
|
18295
18311
|
label: a.label,
|
|
18296
18312
|
ok: !1,
|
|
18313
|
+
failureCategory: "scope",
|
|
18297
18314
|
opsIn: 0,
|
|
18298
18315
|
opsOut: 0,
|
|
18299
|
-
error:
|
|
18316
|
+
error: e,
|
|
18300
18317
|
bootstrapped: !1
|
|
18301
18318
|
};
|
|
18302
18319
|
}
|
|
18303
|
-
let
|
|
18304
|
-
|
|
18320
|
+
let v = bf(e, {
|
|
18321
|
+
localDeviceId: i,
|
|
18322
|
+
peerDeviceId: n
|
|
18323
|
+
}), y = {
|
|
18324
|
+
upsertMemoryIds: _.vectorWork.upsertMemoryIds,
|
|
18325
|
+
deleteMemoryIds: [..._.vectorWork.deleteMemoryIds, ...v.deleted_memory_ids]
|
|
18326
|
+
};
|
|
18327
|
+
try {
|
|
18328
|
+
lb(e, y);
|
|
18329
|
+
} catch (t) {
|
|
18330
|
+
let n = await Hs(e, y);
|
|
18331
|
+
if (n.errors.length > 0) {
|
|
18332
|
+
let e = `vector catch-up failed: ${t instanceof Error ? t.message : String(t)}; fallback failed: ${n.errors.join("; ")}`;
|
|
18333
|
+
return {
|
|
18334
|
+
scope_id: l,
|
|
18335
|
+
label: a.label,
|
|
18336
|
+
ok: !1,
|
|
18337
|
+
failureCategory: "other",
|
|
18338
|
+
opsIn: 0,
|
|
18339
|
+
opsOut: 0,
|
|
18340
|
+
error: e,
|
|
18341
|
+
bootstrapped: !1
|
|
18342
|
+
};
|
|
18343
|
+
}
|
|
18344
|
+
}
|
|
18345
|
+
let b = ES(m.next_cursor);
|
|
18346
|
+
return CS(u, b) && jd(e, n, { lastApplied: b }, l), {
|
|
18305
18347
|
scope_id: l,
|
|
18306
18348
|
label: a.label,
|
|
18307
18349
|
ok: !0,
|
|
18308
|
-
opsIn:
|
|
18350
|
+
opsIn: _.applied,
|
|
18309
18351
|
opsOut: 0,
|
|
18310
|
-
bootstrapped:
|
|
18352
|
+
bootstrapped: f
|
|
18311
18353
|
};
|
|
18312
18354
|
} catch (e) {
|
|
18313
|
-
let t = e instanceof Error ? e.message.trim() || e.constructor.name : "unknown"
|
|
18355
|
+
let t = `scoped incremental failed: ${e instanceof Error ? e.message.trim() || e.constructor.name : "unknown"}`;
|
|
18314
18356
|
return {
|
|
18315
18357
|
scope_id: l,
|
|
18316
18358
|
label: a.label,
|
|
18317
18359
|
ok: !1,
|
|
18360
|
+
failureCategory: zS(t),
|
|
18318
18361
|
opsIn: 0,
|
|
18319
18362
|
opsOut: 0,
|
|
18320
|
-
error:
|
|
18363
|
+
error: t,
|
|
18321
18364
|
bootstrapped: !1
|
|
18322
18365
|
};
|
|
18323
18366
|
}
|
|
18324
18367
|
}
|
|
18325
|
-
function
|
|
18368
|
+
function WS(e) {
|
|
18326
18369
|
Wn(e), Rf(e, 2e3), zf(e, 200);
|
|
18327
18370
|
}
|
|
18328
|
-
async function
|
|
18371
|
+
async function GS(e, t, n, r) {
|
|
18329
18372
|
Wn(e);
|
|
18330
18373
|
let i = r?.limit ?? bS, a = r?.keysDir, o = r?.scanner;
|
|
18331
18374
|
!o && !yS && (yS = !0, process.stderr.write("[codemem] sync apply running without explicit scanner — workspace-level secret rules will not apply to inbound peer content\n"));
|
|
@@ -18333,6 +18376,7 @@ async function VS(e, t, n, r) {
|
|
|
18333
18376
|
if (!s) return {
|
|
18334
18377
|
ok: !1,
|
|
18335
18378
|
error: "peer not pinned",
|
|
18379
|
+
failureCategory: "trust",
|
|
18336
18380
|
opsIn: 0,
|
|
18337
18381
|
opsOut: 0,
|
|
18338
18382
|
addressErrors: []
|
|
@@ -18348,6 +18392,7 @@ async function VS(e, t, n, r) {
|
|
|
18348
18392
|
}), {
|
|
18349
18393
|
ok: !1,
|
|
18350
18394
|
error: r,
|
|
18395
|
+
failureCategory: "other",
|
|
18351
18396
|
opsIn: 0,
|
|
18352
18397
|
opsOut: 0,
|
|
18353
18398
|
addressErrors: []
|
|
@@ -18355,11 +18400,11 @@ async function VS(e, t, n, r) {
|
|
|
18355
18400
|
}
|
|
18356
18401
|
let d = [], f = !1, p;
|
|
18357
18402
|
for (let r of n) {
|
|
18358
|
-
let n =
|
|
18403
|
+
let n = Ul(r);
|
|
18359
18404
|
if (n) {
|
|
18360
18405
|
f = !0;
|
|
18361
18406
|
try {
|
|
18362
|
-
let r = `${n}/v1/status`, [d, f] = await
|
|
18407
|
+
let r = `${n}/v1/status`, [d, f] = await Wl("GET", r, { headers: {
|
|
18363
18408
|
...yr({
|
|
18364
18409
|
deviceId: u,
|
|
18365
18410
|
method: "GET",
|
|
@@ -18398,13 +18443,14 @@ async function VS(e, t, n, r) {
|
|
|
18398
18443
|
ok: !1,
|
|
18399
18444
|
address: n,
|
|
18400
18445
|
error: `needs attention: ${c} shared memory change(s) appeared during initial bootstrap fetch`,
|
|
18446
|
+
failureCategory: "other",
|
|
18401
18447
|
opsIn: 0,
|
|
18402
18448
|
opsOut: 0,
|
|
18403
18449
|
addressErrors: []
|
|
18404
18450
|
};
|
|
18405
18451
|
let l = kb(e, t, s, r, o);
|
|
18406
18452
|
if (!l.ok) throw Error("initial bootstrap apply failed");
|
|
18407
|
-
let d = p?.negotiated === "scoped" ? await
|
|
18453
|
+
let d = p?.negotiated === "scoped" ? await HS(e, {
|
|
18408
18454
|
peerDeviceId: t,
|
|
18409
18455
|
baseUrl: n,
|
|
18410
18456
|
deviceId: u,
|
|
@@ -18425,6 +18471,7 @@ async function VS(e, t, n, r) {
|
|
|
18425
18471
|
}), {
|
|
18426
18472
|
ok: h,
|
|
18427
18473
|
address: n,
|
|
18474
|
+
failureCategory: VS(d.results),
|
|
18428
18475
|
opsIn: l.applied + d.totalOpsIn,
|
|
18429
18476
|
opsOut: 0,
|
|
18430
18477
|
addressErrors: [],
|
|
@@ -18441,7 +18488,7 @@ async function VS(e, t, n, r) {
|
|
|
18441
18488
|
snapshot_id: m.snapshot_id
|
|
18442
18489
|
});
|
|
18443
18490
|
m.baseline_cursor && h.set("baseline_cursor", m.baseline_cursor);
|
|
18444
|
-
let g = `${n}/v1/ops?${h.toString()}`, [_, v] = await
|
|
18491
|
+
let g = `${n}/v1/ops?${h.toString()}`, [_, v] = await Wl("GET", g, { headers: {
|
|
18445
18492
|
...yr({
|
|
18446
18493
|
deviceId: u,
|
|
18447
18494
|
method: "GET",
|
|
@@ -18469,6 +18516,7 @@ async function VS(e, t, n, r) {
|
|
|
18469
18516
|
ok: !1,
|
|
18470
18517
|
address: n,
|
|
18471
18518
|
error: `needs attention: ${r.count} unsynced shared memory change(s) block automatic reset`,
|
|
18519
|
+
failureCategory: "other",
|
|
18472
18520
|
opsIn: 0,
|
|
18473
18521
|
opsOut: 0,
|
|
18474
18522
|
addressErrors: [],
|
|
@@ -18484,6 +18532,7 @@ async function VS(e, t, n, r) {
|
|
|
18484
18532
|
ok: !1,
|
|
18485
18533
|
address: n,
|
|
18486
18534
|
error: `needs attention: ${s.count} unsynced shared memory change(s) appeared during bootstrap fetch`,
|
|
18535
|
+
failureCategory: "other",
|
|
18487
18536
|
opsIn: 0,
|
|
18488
18537
|
opsOut: 0,
|
|
18489
18538
|
addressErrors: [],
|
|
@@ -18513,6 +18562,7 @@ async function VS(e, t, n, r) {
|
|
|
18513
18562
|
ok: !1,
|
|
18514
18563
|
address: n,
|
|
18515
18564
|
error: `bootstrap failed: ${a}`,
|
|
18565
|
+
failureCategory: "other",
|
|
18516
18566
|
opsIn: 0,
|
|
18517
18567
|
opsOut: 0,
|
|
18518
18568
|
addressErrors: [],
|
|
@@ -18545,7 +18595,7 @@ async function VS(e, t, n, r) {
|
|
|
18545
18595
|
try {
|
|
18546
18596
|
lb(e, w);
|
|
18547
18597
|
} catch (t) {
|
|
18548
|
-
let n = await
|
|
18598
|
+
let n = await Hs(e, w);
|
|
18549
18599
|
if (n.errors.length > 0) {
|
|
18550
18600
|
let e = n.errors.join("; ");
|
|
18551
18601
|
throw Error(`vector catch-up queue failed: ${t instanceof Error ? t.message : String(t)}; fallback failed: ${e}`);
|
|
@@ -18560,7 +18610,7 @@ async function VS(e, t, n, r) {
|
|
|
18560
18610
|
}
|
|
18561
18611
|
let E = ie ?? ne;
|
|
18562
18612
|
E && CS(l, E) && (jd(e, t, { lastAcked: E }), l = E);
|
|
18563
|
-
let D = p?.negotiated === "scoped" ? await
|
|
18613
|
+
let D = p?.negotiated === "scoped" ? await HS(e, {
|
|
18564
18614
|
peerDeviceId: t,
|
|
18565
18615
|
baseUrl: n,
|
|
18566
18616
|
deviceId: u,
|
|
@@ -18581,6 +18631,7 @@ async function VS(e, t, n, r) {
|
|
|
18581
18631
|
}), {
|
|
18582
18632
|
ok: se,
|
|
18583
18633
|
address: n,
|
|
18634
|
+
failureCategory: VS(D.results),
|
|
18584
18635
|
opsIn: S.applied + D.totalOpsIn,
|
|
18585
18636
|
opsOut: re.length,
|
|
18586
18637
|
opsSkipped: ae,
|
|
@@ -18605,20 +18656,21 @@ async function VS(e, t, n, r) {
|
|
|
18605
18656
|
}), {
|
|
18606
18657
|
ok: !1,
|
|
18607
18658
|
error: m,
|
|
18659
|
+
failureCategory: RS(m),
|
|
18608
18660
|
opsIn: 0,
|
|
18609
18661
|
opsOut: 0,
|
|
18610
18662
|
addressErrors: d
|
|
18611
18663
|
};
|
|
18612
18664
|
}
|
|
18613
|
-
async function
|
|
18665
|
+
async function KS(e, t, n) {
|
|
18614
18666
|
let r = P(e, { schema: H }).select({ addresses_json: Y.addresses_json }).from(Y).where(A(Y.peer_device_id, t)).get(), i = [];
|
|
18615
18667
|
if (r?.addresses_json) try {
|
|
18616
18668
|
let e = JSON.parse(r.addresses_json);
|
|
18617
18669
|
Array.isArray(e) && (i = e.filter((e) => typeof e == "string"));
|
|
18618
18670
|
} catch {}
|
|
18619
|
-
return
|
|
18671
|
+
return GS(e, t, i, n);
|
|
18620
18672
|
}
|
|
18621
|
-
var
|
|
18673
|
+
var qS = [
|
|
18622
18674
|
"no route to host",
|
|
18623
18675
|
"connection refused",
|
|
18624
18676
|
"network is unreachable",
|
|
@@ -18629,33 +18681,33 @@ var US = [
|
|
|
18629
18681
|
"errno 61",
|
|
18630
18682
|
"errno 60",
|
|
18631
18683
|
"errno 111"
|
|
18632
|
-
],
|
|
18633
|
-
function
|
|
18684
|
+
], JS = 120, YS = 1800;
|
|
18685
|
+
function XS(e) {
|
|
18634
18686
|
if (!e) return !1;
|
|
18635
18687
|
let t = e.toLowerCase();
|
|
18636
|
-
return
|
|
18688
|
+
return qS.some((e) => t.includes(e));
|
|
18637
18689
|
}
|
|
18638
|
-
function
|
|
18690
|
+
function ZS(e, t, n = 10) {
|
|
18639
18691
|
let r = P(e, { schema: H }).select({
|
|
18640
18692
|
ok: mt.ok,
|
|
18641
18693
|
error: mt.error
|
|
18642
18694
|
}).from(mt).where(A(mt.peer_device_id, t)).orderBy(ue(mt.started_at)).limit(n).all(), i = 0;
|
|
18643
18695
|
for (let e of r) {
|
|
18644
18696
|
if (e.ok) break;
|
|
18645
|
-
if (
|
|
18697
|
+
if (XS(e.error)) i++;
|
|
18646
18698
|
else break;
|
|
18647
18699
|
}
|
|
18648
18700
|
return i;
|
|
18649
18701
|
}
|
|
18650
|
-
function
|
|
18702
|
+
function QS(e) {
|
|
18651
18703
|
if (e <= 1) return 0;
|
|
18652
18704
|
let t = Math.min(e - 1, 8);
|
|
18653
|
-
return Math.min(
|
|
18705
|
+
return Math.min(JS * 2 ** (t - 1), YS) * (.5 + Math.random() * .5);
|
|
18654
18706
|
}
|
|
18655
|
-
function
|
|
18656
|
-
let n =
|
|
18707
|
+
function $S(e, t) {
|
|
18708
|
+
let n = ZS(e, t);
|
|
18657
18709
|
if (n < 2) return !1;
|
|
18658
|
-
let r =
|
|
18710
|
+
let r = QS(n);
|
|
18659
18711
|
if (r <= 0) return !1;
|
|
18660
18712
|
let i = P(e, { schema: H }).select({ started_at: mt.started_at }).from(mt).where(A(mt.peer_device_id, t)).orderBy(ue(mt.started_at)).limit(1).get();
|
|
18661
18713
|
if (!i?.started_at) return !1;
|
|
@@ -18668,13 +18720,13 @@ function YS(e, t) {
|
|
|
18668
18720
|
}
|
|
18669
18721
|
//#endregion
|
|
18670
18722
|
//#region src/sync-daemon.ts
|
|
18671
|
-
function
|
|
18723
|
+
function eC(e) {
|
|
18672
18724
|
return e?.trim() || process.env.CODEMEM_KEYS_DIR?.trim() || void 0;
|
|
18673
18725
|
}
|
|
18674
|
-
function
|
|
18726
|
+
function tC(e, t, n) {
|
|
18675
18727
|
return e.prepare(`PRAGMA table_info(${t})`).all().some((e) => e.name === n);
|
|
18676
18728
|
}
|
|
18677
|
-
function
|
|
18729
|
+
function nC(e) {
|
|
18678
18730
|
let t = P(e, { schema: H }), n = (/* @__PURE__ */ new Date()).toISOString();
|
|
18679
18731
|
t.insert(gt).values({
|
|
18680
18732
|
id: 1,
|
|
@@ -18688,7 +18740,7 @@ function QS(e) {
|
|
|
18688
18740
|
}
|
|
18689
18741
|
}).run();
|
|
18690
18742
|
}
|
|
18691
|
-
function
|
|
18743
|
+
function rC(e, t, n) {
|
|
18692
18744
|
let r = P(e, { schema: H }), i = (/* @__PURE__ */ new Date()).toISOString();
|
|
18693
18745
|
r.insert(gt).values({
|
|
18694
18746
|
id: 1,
|
|
@@ -18704,11 +18756,11 @@ function $S(e, t, n) {
|
|
|
18704
18756
|
}
|
|
18705
18757
|
}).run();
|
|
18706
18758
|
}
|
|
18707
|
-
function
|
|
18759
|
+
function iC(e) {
|
|
18708
18760
|
let t = P(e, { schema: H }).select({ phase: gt.phase }).from(gt).where(A(gt.id, 1)).get()?.phase;
|
|
18709
18761
|
return t === "needs_attention" ? t : null;
|
|
18710
18762
|
}
|
|
18711
|
-
function
|
|
18763
|
+
function aC(e, t) {
|
|
18712
18764
|
P(e, { schema: H }).insert(gt).values({
|
|
18713
18765
|
id: 1,
|
|
18714
18766
|
phase: t
|
|
@@ -18717,18 +18769,18 @@ function tC(e, t) {
|
|
|
18717
18769
|
set: { phase: t }
|
|
18718
18770
|
}).run();
|
|
18719
18771
|
}
|
|
18720
|
-
async function
|
|
18721
|
-
let r =
|
|
18722
|
-
return
|
|
18772
|
+
async function oC(e, t, n) {
|
|
18773
|
+
let r = au();
|
|
18774
|
+
return ou(r) ? (await cu({
|
|
18723
18775
|
db: e,
|
|
18724
18776
|
dbPath: t
|
|
18725
|
-
}, r, { keysDir: n }), await
|
|
18777
|
+
}, r, { keysDir: n }), await Ju(e, r, { keysDir: n }), !0) : !1;
|
|
18726
18778
|
}
|
|
18727
|
-
async function
|
|
18728
|
-
let i =
|
|
18779
|
+
async function sC(e, t, n, r) {
|
|
18780
|
+
let i = tC(e, "sync_peers", "pinned_fingerprint"), a = e.prepare(i ? "SELECT peer_device_id, pinned_fingerprint FROM sync_peers" : "SELECT peer_device_id, NULL AS pinned_fingerprint FROM sync_peers").all();
|
|
18729
18781
|
if (a.length === 0) return [];
|
|
18730
|
-
let o =
|
|
18731
|
-
|
|
18782
|
+
let o = au().syncOpsLimit;
|
|
18783
|
+
WS(e);
|
|
18732
18784
|
let s = [];
|
|
18733
18785
|
for (let i of a) {
|
|
18734
18786
|
let a = i.peer_device_id, c = String(i.pinned_fingerprint ?? "").trim(), l = c ? `${a}:${c}` : "";
|
|
@@ -18740,7 +18792,7 @@ async function rC(e, t, n, r) {
|
|
|
18740
18792
|
});
|
|
18741
18793
|
continue;
|
|
18742
18794
|
}
|
|
18743
|
-
if (
|
|
18795
|
+
if ($S(e, a)) {
|
|
18744
18796
|
s.push({
|
|
18745
18797
|
ok: !1,
|
|
18746
18798
|
skipped: !0,
|
|
@@ -18748,7 +18800,7 @@ async function rC(e, t, n, r) {
|
|
|
18748
18800
|
});
|
|
18749
18801
|
continue;
|
|
18750
18802
|
}
|
|
18751
|
-
let u = await
|
|
18803
|
+
let u = await KS(e, a, {
|
|
18752
18804
|
keysDir: t,
|
|
18753
18805
|
limit: o,
|
|
18754
18806
|
scanner: r
|
|
@@ -18762,8 +18814,8 @@ async function rC(e, t, n, r) {
|
|
|
18762
18814
|
}
|
|
18763
18815
|
return s;
|
|
18764
18816
|
}
|
|
18765
|
-
async function
|
|
18766
|
-
let t = e?.intervalS ?? 120, n = kn(e?.dbPath), r =
|
|
18817
|
+
async function cC(e) {
|
|
18818
|
+
let t = e?.intervalS ?? 120, n = kn(e?.dbPath), r = eC(e?.keysDir), i = e?.signal, a = e?.onPhaseChange, o = e?.scanner;
|
|
18767
18819
|
a?.("starting");
|
|
18768
18820
|
let s = Pn(n), c = null;
|
|
18769
18821
|
try {
|
|
@@ -18778,7 +18830,7 @@ async function iC(e) {
|
|
|
18778
18830
|
}
|
|
18779
18831
|
return new Promise((e) => {
|
|
18780
18832
|
let s = !1, l = !1, u = () => {
|
|
18781
|
-
s || (s = !0,
|
|
18833
|
+
s || (s = !0, lC(n, r, o).finally(() => {
|
|
18782
18834
|
s = !1, l || (l = !0, a?.("running"));
|
|
18783
18835
|
}));
|
|
18784
18836
|
}, d = setInterval(u, t * 1e3);
|
|
@@ -18795,38 +18847,38 @@ async function iC(e) {
|
|
|
18795
18847
|
}
|
|
18796
18848
|
});
|
|
18797
18849
|
}
|
|
18798
|
-
async function
|
|
18799
|
-
let r =
|
|
18850
|
+
async function lC(e, t, n) {
|
|
18851
|
+
let r = eC(t), i = Pn(e);
|
|
18800
18852
|
try {
|
|
18801
18853
|
Wn(i);
|
|
18802
18854
|
try {
|
|
18803
|
-
await
|
|
18855
|
+
await oC(i, e, r);
|
|
18804
18856
|
} catch {}
|
|
18805
|
-
(await
|
|
18857
|
+
(await sC(i, r, await pu(i, e, r), n)).some((e) => !e.ok && e.error?.includes("needs_attention")) ? aC(i, "needs_attention") : nC(i);
|
|
18806
18858
|
} catch (e) {
|
|
18807
|
-
|
|
18859
|
+
rC(i, e instanceof Error ? e.message : String(e), e instanceof Error ? e.stack ?? "" : "");
|
|
18808
18860
|
} finally {
|
|
18809
18861
|
i.close();
|
|
18810
18862
|
}
|
|
18811
18863
|
}
|
|
18812
18864
|
//#endregion
|
|
18813
18865
|
//#region src/sync-retention-runner.ts
|
|
18814
|
-
function
|
|
18866
|
+
function uC(e) {
|
|
18815
18867
|
let t = String(e ?? "").trim();
|
|
18816
|
-
return t.length > 0 ? t :
|
|
18868
|
+
return t.length > 0 ? t : td;
|
|
18817
18869
|
}
|
|
18818
|
-
function
|
|
18870
|
+
function dC(e) {
|
|
18819
18871
|
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 CREATE TABLE IF NOT EXISTS sync_retention_state_v2 (\n scope_id TEXT PRIMARY KEY NOT NULL,\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 ");
|
|
18820
18872
|
}
|
|
18821
|
-
function
|
|
18822
|
-
let t = e.prepare("SELECT scope_id FROM (\n SELECT COALESCE(NULLIF(TRIM(scope_id), ''), ?) AS scope_id FROM replication_ops\n UNION\n SELECT COALESCE(NULLIF(TRIM(scope_id), ''), ?) AS scope_id FROM sync_reset_state_v2\n UNION\n SELECT COALESCE(NULLIF(TRIM(scope_id), ''), ?) AS scope_id FROM sync_retention_state_v2\n )\n ORDER BY CASE WHEN scope_id = ? THEN 0 ELSE 1 END, scope_id").all(
|
|
18873
|
+
function fC(e) {
|
|
18874
|
+
let t = e.prepare("SELECT scope_id FROM (\n SELECT COALESCE(NULLIF(TRIM(scope_id), ''), ?) AS scope_id FROM replication_ops\n UNION\n SELECT COALESCE(NULLIF(TRIM(scope_id), ''), ?) AS scope_id FROM sync_reset_state_v2\n UNION\n SELECT COALESCE(NULLIF(TRIM(scope_id), ''), ?) AS scope_id FROM sync_retention_state_v2\n )\n ORDER BY CASE WHEN scope_id = ? THEN 0 ELSE 1 END, scope_id").all(td, td, td, td), n = new Set([td]);
|
|
18823
18875
|
for (let e of t) {
|
|
18824
|
-
let t =
|
|
18876
|
+
let t = uC(e.scope_id);
|
|
18825
18877
|
n.add(t);
|
|
18826
18878
|
}
|
|
18827
18879
|
return Array.from(n);
|
|
18828
18880
|
}
|
|
18829
|
-
function
|
|
18881
|
+
function pC(e, t, n, r) {
|
|
18830
18882
|
e.insert(bt).values({
|
|
18831
18883
|
scope_id: t,
|
|
18832
18884
|
...n
|
|
@@ -18841,8 +18893,8 @@ function lC(e, t, n, r) {
|
|
|
18841
18893
|
set: n
|
|
18842
18894
|
}).run();
|
|
18843
18895
|
}
|
|
18844
|
-
function
|
|
18845
|
-
let a = i ===
|
|
18896
|
+
function mC(e, t, n, r, i) {
|
|
18897
|
+
let a = i === td;
|
|
18846
18898
|
try {
|
|
18847
18899
|
let o = Xd(e, i), s = Kd(e, {
|
|
18848
18900
|
maxAgeDays: n.syncRetentionMaxAgeDays,
|
|
@@ -18853,7 +18905,7 @@ function uC(e, t, n, r, i) {
|
|
|
18853
18905
|
maxPasses: n.maxCatchUpPasses,
|
|
18854
18906
|
signal: n.signal
|
|
18855
18907
|
});
|
|
18856
|
-
|
|
18908
|
+
pC(t, i, {
|
|
18857
18909
|
last_run_at: r,
|
|
18858
18910
|
last_duration_ms: Date.now() - Date.parse(r),
|
|
18859
18911
|
last_deleted_ops: s.totalDeleted,
|
|
@@ -18864,7 +18916,7 @@ function uC(e, t, n, r, i) {
|
|
|
18864
18916
|
last_error_at: null
|
|
18865
18917
|
}, a);
|
|
18866
18918
|
} catch (e) {
|
|
18867
|
-
|
|
18919
|
+
pC(t, i, {
|
|
18868
18920
|
last_run_at: r,
|
|
18869
18921
|
last_duration_ms: Date.now() - Date.parse(r),
|
|
18870
18922
|
last_deleted_ops: 0,
|
|
@@ -18876,13 +18928,13 @@ function uC(e, t, n, r, i) {
|
|
|
18876
18928
|
}, a);
|
|
18877
18929
|
}
|
|
18878
18930
|
}
|
|
18879
|
-
async function
|
|
18931
|
+
async function hC(e, t) {
|
|
18880
18932
|
if (!t.syncRetentionEnabled) return;
|
|
18881
|
-
|
|
18882
|
-
let n = P(e, { schema: H }), r = (/* @__PURE__ */ new Date()).toISOString(), i = t.scopeId === void 0 ?
|
|
18883
|
-
for (let a of i)
|
|
18933
|
+
dC(e);
|
|
18934
|
+
let n = P(e, { schema: H }), r = (/* @__PURE__ */ new Date()).toISOString(), i = t.scopeId === void 0 ? fC(e) : [uC(t.scopeId)];
|
|
18935
|
+
for (let a of i) mC(e, n, t, r, a);
|
|
18884
18936
|
}
|
|
18885
|
-
var
|
|
18937
|
+
var gC = class {
|
|
18886
18938
|
dbPath;
|
|
18887
18939
|
signal;
|
|
18888
18940
|
active = !1;
|
|
@@ -18901,16 +18953,16 @@ var fC = class {
|
|
|
18901
18953
|
!this.active || this.signal?.aborted || (this.timer = setTimeout(() => {
|
|
18902
18954
|
this.timer = null, this.currentRun = this.runOnce().catch(() => {}).finally(() => {
|
|
18903
18955
|
this.currentRun = null;
|
|
18904
|
-
let e =
|
|
18956
|
+
let e = au(Bt());
|
|
18905
18957
|
this.schedule(e.syncRetentionIntervalS * 1e3);
|
|
18906
18958
|
});
|
|
18907
18959
|
}, e), typeof this.timer == "object" && "unref" in this.timer && this.timer.unref());
|
|
18908
18960
|
}
|
|
18909
18961
|
async runOnce() {
|
|
18910
18962
|
if (!this.active || this.signal?.aborted) return;
|
|
18911
|
-
let e =
|
|
18963
|
+
let e = au(Bt()), t = Pn(this.dbPath);
|
|
18912
18964
|
try {
|
|
18913
|
-
await
|
|
18965
|
+
await hC(t, {
|
|
18914
18966
|
...e,
|
|
18915
18967
|
signal: this.signal
|
|
18916
18968
|
});
|
|
@@ -18918,8 +18970,8 @@ var fC = class {
|
|
|
18918
18970
|
t.close();
|
|
18919
18971
|
}
|
|
18920
18972
|
}
|
|
18921
|
-
},
|
|
18922
|
-
function
|
|
18973
|
+
}, _C = "scope_id";
|
|
18974
|
+
function vC(e, t, n) {
|
|
18923
18975
|
if (!t) return {
|
|
18924
18976
|
ok: !0,
|
|
18925
18977
|
mode: "legacy",
|
|
@@ -18940,7 +18992,7 @@ function mC(e, t, n) {
|
|
|
18940
18992
|
ok: !1,
|
|
18941
18993
|
reason: "missing_scope"
|
|
18942
18994
|
};
|
|
18943
|
-
let c =
|
|
18995
|
+
let c = yC(Xu(a, {
|
|
18944
18996
|
deviceId: o,
|
|
18945
18997
|
scopeId: r
|
|
18946
18998
|
}));
|
|
@@ -18948,7 +19000,7 @@ function mC(e, t, n) {
|
|
|
18948
19000
|
ok: !1,
|
|
18949
19001
|
reason: c
|
|
18950
19002
|
};
|
|
18951
|
-
let l =
|
|
19003
|
+
let l = yC(Xu(a, {
|
|
18952
19004
|
deviceId: s,
|
|
18953
19005
|
scopeId: r
|
|
18954
19006
|
}));
|
|
@@ -18961,7 +19013,7 @@ function mC(e, t, n) {
|
|
|
18961
19013
|
scope_id: r
|
|
18962
19014
|
};
|
|
18963
19015
|
}
|
|
18964
|
-
function
|
|
19016
|
+
function yC(e) {
|
|
18965
19017
|
if (e.authorized) return null;
|
|
18966
19018
|
switch (e.state) {
|
|
18967
19019
|
case "stale_epoch": return "stale_epoch";
|
|
@@ -18970,22 +19022,22 @@ function hC(e) {
|
|
|
18970
19022
|
default: return "missing_scope";
|
|
18971
19023
|
}
|
|
18972
19024
|
}
|
|
18973
|
-
function
|
|
19025
|
+
function bC(e, t) {
|
|
18974
19026
|
return {
|
|
18975
19027
|
...e,
|
|
18976
19028
|
scope_id: t
|
|
18977
19029
|
};
|
|
18978
19030
|
}
|
|
18979
|
-
function
|
|
19031
|
+
function xC(e, t, n, r) {
|
|
18980
19032
|
return {
|
|
18981
19033
|
error: "reset_required",
|
|
18982
19034
|
reset_required: !0,
|
|
18983
19035
|
sync_capability: n,
|
|
18984
19036
|
reason: t,
|
|
18985
|
-
...
|
|
19037
|
+
...bC(e, r ?? null)
|
|
18986
19038
|
};
|
|
18987
19039
|
}
|
|
18988
|
-
function
|
|
19040
|
+
function SC(e, t) {
|
|
18989
19041
|
let n = t.localDeviceId.trim(), r = t.peerDeviceId.trim();
|
|
18990
19042
|
if (!n || !r || n === r) return [];
|
|
18991
19043
|
let i = P(e, { schema: H }).select({
|
|
@@ -18996,7 +19048,7 @@ function vC(e, t) {
|
|
|
18996
19048
|
let a = [];
|
|
18997
19049
|
for (let t of i) {
|
|
18998
19050
|
if (!t.scope_id || t.scope_id === "local-default") continue;
|
|
18999
|
-
let n =
|
|
19051
|
+
let n = Xu(e, {
|
|
19000
19052
|
deviceId: r,
|
|
19001
19053
|
scopeId: t.scope_id
|
|
19002
19054
|
});
|
|
@@ -19018,34 +19070,34 @@ function vC(e, t) {
|
|
|
19018
19070
|
}
|
|
19019
19071
|
return a.sort((e, t) => e.scope_id.localeCompare(t.scope_id)), a;
|
|
19020
19072
|
}
|
|
19021
|
-
function
|
|
19073
|
+
function CC(e, t) {
|
|
19022
19074
|
let n = t.localDeviceId?.trim() ?? "", r = t.peerDeviceId.trim();
|
|
19023
|
-
return !n || !r ? [] :
|
|
19075
|
+
return !n || !r ? [] : SC(e, {
|
|
19024
19076
|
localDeviceId: n,
|
|
19025
19077
|
peerDeviceId: r
|
|
19026
19078
|
}).map((t) => {
|
|
19027
|
-
let [n, i] = Ad(e, r, t.scope_id);
|
|
19079
|
+
let [n, i] = Ad(e, r, t.scope_id), a = i === rd;
|
|
19028
19080
|
return {
|
|
19029
19081
|
scope_id: t.scope_id,
|
|
19030
19082
|
label: t.label,
|
|
19031
19083
|
authority_type: t.authority_type,
|
|
19032
19084
|
membership_epoch: t.membership_epoch,
|
|
19033
19085
|
last_applied_cursor: n,
|
|
19034
|
-
last_acked_cursor: i,
|
|
19035
|
-
bootstrapped: n != null
|
|
19086
|
+
last_acked_cursor: a ? null : i,
|
|
19087
|
+
bootstrapped: n != null || a
|
|
19036
19088
|
};
|
|
19037
19089
|
});
|
|
19038
19090
|
}
|
|
19039
19091
|
//#endregion
|
|
19040
19092
|
//#region src/test-utils.ts
|
|
19041
|
-
function
|
|
19093
|
+
function wC(e) {
|
|
19042
19094
|
_n(e);
|
|
19043
19095
|
}
|
|
19044
|
-
function
|
|
19096
|
+
function TC(e) {
|
|
19045
19097
|
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");
|
|
19046
19098
|
return Number(n.lastInsertRowid);
|
|
19047
19099
|
}
|
|
19048
|
-
function
|
|
19100
|
+
function EC(e, t = "local") {
|
|
19049
19101
|
let n = "2026-04-01T00:00:00.000Z", r = "fixture-work-authorized", i = "fixture-oss-hidden", a = "mixedscopeleak";
|
|
19050
19102
|
e.prepare("INSERT OR IGNORE INTO sync_device(device_id, public_key, fingerprint, created_at) VALUES (?, ?, ?, ?)").run(t, "fixture-public-key", "fixture-fingerprint", n), e.prepare("INSERT OR REPLACE INTO replication_scopes(\n scope_id, label, kind, authority_type, coordinator_id, group_id,\n membership_epoch, status, created_at, updated_at\n ) VALUES (?, ?, 'team', 'coordinator', 'fixture-coordinator', 'fixture-group', 0, 'active', ?, ?)").run(r, "Authorized work fixture", n, n), e.prepare("INSERT OR REPLACE INTO replication_scopes(\n scope_id, label, kind, authority_type, coordinator_id, group_id,\n membership_epoch, status, created_at, updated_at\n ) VALUES (?, ?, 'team', 'coordinator', 'fixture-coordinator', 'fixture-group', 0, 'active', ?, ?)").run(i, "Hidden OSS fixture", n, n), e.prepare("INSERT OR REPLACE INTO scope_memberships(\n scope_id, device_id, role, status, membership_epoch,\n coordinator_id, group_id, updated_at\n ) VALUES (?, ?, 'member', 'active', 0, 'fixture-coordinator', 'fixture-group', ?)").run(r, t, n);
|
|
19051
19103
|
let o = e.prepare("INSERT INTO sessions(started_at, cwd, project, user, tool_version, metadata_json, import_key)\n VALUES (?, '/tmp/mixed-domain-fixture', 'mixed-domain-fixture', 'test-user', 'test', '{}', 'fixture-session')").run(n), s = Number(o.lastInsertRowid), c = (t) => {
|
|
@@ -19094,8 +19146,8 @@ function SC(e, t = "local") {
|
|
|
19094
19146
|
}
|
|
19095
19147
|
//#endregion
|
|
19096
19148
|
//#region src/index.ts
|
|
19097
|
-
var
|
|
19149
|
+
var DC = "0.36.0";
|
|
19098
19150
|
//#endregion
|
|
19099
|
-
export { rd as ACCESS_CLEANUP_OP_TYPE, Ae as Api, Qe as BetterSqliteCoordinatorStore, Lt as CODEMEM_CONFIG_ENV_OVERRIDES, Tg as DEDUP_KEY_BACKFILL_JOB, z as DEFAULT_COORDINATOR_DB_PATH, On as DEFAULT_DB_PATH, bu as DEFAULT_SCOPE_MEMBERSHIP_CACHE_MAX_AGE_MS, $x as DEFAULT_SERVICE_TYPE, nd as DEFAULT_SYNC_SCOPE_ID, o as DEFAULT_TIME_WINDOW_S, kg as DedupKeyBackfillRunner, xi as INJECTION_EVAL_SCENARIO_PACKS, Ey as LEGACY_SHARED_REVIEW_SCOPE_ID, Bi as LOCAL_DEFAULT_SCOPE_ID, qy as LOCAL_SYNC_CAPABILITY, H_ as LOW_SIGNAL_TOOLS, wr as MAPPABLE_CLAUDE_HOOK_EVENTS, Hr as MAPPABLE_CODEX_HOOK_EVENTS, Tn as MIN_COMPATIBLE_SCHEMA, je as MUTATING_TOOL_NAMES, up as MemoryStore, um as ObserverAuthAdapter, Hm as ObserverAuthError, hh as ObserverClient, Cx as REF_BACKFILL_JOB, v_ as RICH_TIER_DEFAULTS, Sx as RawEventSweeper, kx as RefBackfillRunner, wn as SCHEMA_VERSION, Dy as SCOPE_BACKFILL_JOB, n as SCOPE_MEMBERSHIP_REVOCATION_LIMITATION, Ax as SESSION_CONTEXT_BACKFILL_JOB, mr as SIGNATURE_VERSION, __ as SIMPLE_TIER_DEFAULTS, Wx as SUMMARY_DEDUP_BACKFILL_JOB, Gy as SYNC_CAPABILITIES, Ky as SYNC_CAPABILITY_HEADER, pC as SYNC_SCOPE_QUERY_PARAM, Uy as ScopeBackfillRunner, Ux as SessionContextBackfillRunner, Zx as SummaryDedupBackfillRunner, fC as SyncRetentionRunner, gv as TRIVIAL_REQUESTS, Qy as VECTOR_MODEL_MIGRATION_JOB, CC as VERSION, bb as VectorModelMigrationRunner, ms as _resetEmbeddingClient, gC as addSyncScopeToBoundary, zl as addressDedupeKey, hS as advertiseMdns, Ah as aiBackfillStructuredContent, px as analyzeProjectScopeMappingChangeGuardrails, kb as applyBootstrapSnapshot, Hf as applyReplicationOps, Vn as assertSchemaReady, Wp as backfillMemoryDedupKeys, zp as backfillNarrativeFromBody, zf as backfillReplicationOps, zy as backfillScopeIds, kp as backfillTagsText, Gs as backfillVectors, _n as bootstrapSchema, ev as budgetToolEvents, yr as buildAuthHeaders, Wl as buildBaseUrl, hr as buildCanonicalRequest, im as buildCodexHeaders, la as buildFilterClauses, ua as buildFilterClausesWithContext, Bg as buildImportKey, $r as buildIngestPayloadFromCodexHook, Vr as buildIngestPayloadFromHook, pl as buildMemoryPack, hl as buildMemoryPackAsync, ml as buildMemoryPackTrace, gl as buildMemoryPackTraceAsync, mv as buildObserverPrompt, Qr as buildRawEventEnvelopeFromCodexHook, Br as buildRawEventEnvelopeFromHook, cy as buildSessionContext, Tv as buildTranscript, qd as bulkPruneReplicationOpsByAgeCutoff, Oi as canonicalMemoryKind, Ki as canonicalWorkspaceIdentity, Ed as chunkOpsBySize, fs as chunkText, Ay as classifyLegacyMemoryScope, ty as cleanOrphanSessions, xr as cleanupNonces, Aa as clearMemoryRefs, Fd as clockTuple, bp as compareMemoryRoleReports, li as completeMaintenanceJob, Pn as connect, Ze as connectCoordinator, qS as consecutiveConnectivityFailures, Xh as coordinatorArchiveGroupAction, Jh as coordinatorCreateGroupAction, dg as coordinatorCreateInviteAction, eg as coordinatorCreateScopeAction, cg as coordinatorDisableDeviceAction, lg as coordinatorEnableDeviceAction, su as coordinatorEnabled, ag as coordinatorEnrollDeviceAction, rg as coordinatorGrantScopeMembershipAction, fg as coordinatorImportInviteAction, hg as coordinatorListBootstrapGrantsAction, og as coordinatorListDevicesAction, Qh as coordinatorListGroupsAction, pg as coordinatorListJoinRequestsAction, ng as coordinatorListScopeMembershipsAction, $h as coordinatorListScopesAction, ug as coordinatorRemoveDeviceAction, sg as coordinatorRenameDeviceAction, Yh as coordinatorRenameGroupAction, mg as coordinatorReviewJoinRequestAction, gg as coordinatorRevokeBootstrapGrantAction, ig as coordinatorRevokeScopeMembershipAction, vu as coordinatorStatusSnapshot, Zh as coordinatorUnarchiveGroupAction, tg as coordinatorUpdateScopeAction, Sr as createBetterSqliteCoordinatorApp, c as createCoordinatorApp, gu as createCoordinatorReciprocalApproval, CS as cursorAdvances, Ip as deactivateLowSignalMemories, Fp as deactivateLowSignalObservations, k_ as decideExtractionReplayTier, s as decodeInvitePayload, Lp as dedupNearDuplicateMemories, os as dedupeOrderedIds, _g as defaultSpaceScopeIdForGroup, wg as deleteCoordinatorGroupPreference, vx as deleteProjectScopeSettingsMapping, wv as deriveRequest, td as deriveTags, xf as diagnoseStalePeerReceivedRows, gS as discoverPeersViaMdns, _s as embedTexts, t as encodeInvitePayload, pr as ensureDeviceIdentity, di as ensureMaintenanceJobsSchema, xn as ensureSchemaBootstrapped, My as ensureScopeBackfillScopes, Eu as ensureScopeMembershipCacheStateTable, nc as estimateTokens, h_ as evaluateSessionExtractionItems, q_ as eventToToolEvent, so as expandQuery, us as explain, e as explainScopeMembershipRevocation, Yg as exportMemories, Y_ as extractAdapterEvent, Me as extractApplyPatchPaths, Ev as extractAssistantMessages, Dv as extractAssistantUsage, r as extractInvitePayload, Rp as extractNarrativeFromBody, $p as extractOAuthAccess, nm as extractOAuthAccountId, rm as extractOAuthExpires, Ov as extractPrompts, em as extractProviderApiKey, Pd as extractReplicationOps, J_ as extractToolEvents, ui as failMaintenanceJob, Sb as fetchAllSnapshotPages, mu as fetchCoordinatorStalePeers, ed as fileTags, _f as filterReplicationOpsForSync, gf as filterReplicationOpsForSyncWithStatus, Pa as findByConcept, Na as findByFile, i as fingerprintPublicKey, Cv as firstSentence, uy as flushRawEvents, Rl as formatHostPort, Gn as fromJson, Kn as fromJsonStrict, lr as generateKeypair, Zu as getCachedScopeAuthorization, zt as getCodememConfigPath, Wt as getCodememEnvOverrides, xg as getCoordinatorGroupPreference, gs as getEmbeddingClient, s_ as getExtractionBenchmarkProfile, bi as getInjectionEvalScenarioByPrompt, Si as getInjectionEvalScenarioPack, Ci as getInjectionEvalScenarioPrompts, Q as getMaintenanceJob, yp as getMemoryRoleReport, Kt as getOpenCodeProviderConfig, ln as getProviderApiKey, sn as getProviderBaseUrl, cn as getProviderHeaders, on as getProviderOptions, _i as getRawEventRelinkPlan, gi as getRawEventRelinkReport, xp as getRawEventStatus, Cp as getReliabilityMetrics, Ad as getReplicationCursor, Bn as getSchemaVersion, zs as getSemanticIndexDiagnostics, g_ as getSessionExtractionEval, m_ as getSessionExtractionEvalScenario, Ti as getSummaryMetadata, eC as getSyncDaemonPhase, xd as getSyncResetState, Mt as getWorkspaceCodememConfigPath, Nt as getWorkspaceScopedCodememConfigPath, Vv as hasMeaningfulObservation, Eg as hasPendingDedupKeyBackfill, Tx as hasPendingRefBackfill, Iy as hasPendingScopeBackfill, Bx as hasPendingSessionContextBackfill, Kx as hasPendingSummaryDedupBackfill, Wd as hasUnsyncedSharedMemoryChanges, ds as hashText, a_ as importMemories, $v as ingest, ny as ingestMain, vi as initDatabase, bC as initTestSchema, xC as insertTestSession, l as inviteLink, KS as isConnectivityError, zn as isEmbeddingDisabled, U_ as isInternalMemoryTool, Mp as isLowSignalObservation, Id as isNewerClock, Yy as isScopedSyncCapability, F_ as isSensitiveFieldName, Ei as isSummaryLikeMemory, Sv as isTrivialRequest, lo as kindBonus, vC as listAuthorizedScopesForPeer, Xu as listCachedScopesForDevice, Xt as listConfiguredOpenCodeProviders, Sg as listCoordinatorGroupPreferences, yu as listCoordinatorJoinRequests, hu as listCoordinatorReciprocalApprovals, qt as listCustomProviders, c_ as listExtractionBenchmarkProfiles, Ff as listInboundScopeRejections, oi as listMaintenanceJobs, Zt as listObserverProviderOptions, yC as listPerPeerScopeSyncState, mx as listProjectScopeCandidates, hx as listProjectScopeInventory, ox as listProjectScopeSettingsMappings, ax as listSharingDomainSettingsScopes, Ud as loadMemorySnapshotPageForPeer, Vm as loadObserverConfig, kt as loadOpenCodeConfig, Xp as loadOpenCodeOAuthCache, tS as loadPeerAddresses, ar as loadPrivateKey, nr as loadPrivateKeyKeychain, ir as loadPublicKey, Hd as loadReplicationOpsForPeer, Vd as loadReplicationOpsSince, Rn as loadSqliteVec, uu as lookupCoordinatorPeers, Rr as mapClaudeHookPayload, Zr as mapCodexHookPayload, _S as mdnsAddressesForPeer, lS as mdnsEnabled, Bl as mergeAddresses, Vg as mergeSummaryMetadata, Nn as migrateLegacyDbPath, Rf as migrateLegacyImportKeys, Zy as negotiateSyncCapability, Av as normalizeAdapterEvents, Ll as normalizeAddress, ka as normalizeConcept, kv as normalizeEventsForSessionContext, jp as normalizeObservation, kr as normalizeProjectLabel, xv as normalizeRequestText, Xy as normalizeSyncCapability, $u as normalizeTag, W_ as normalizeToolName, Bv as parseObserverResponse, Ra as parsePositiveMemoryId, La as parseStrictInteger, mC as parseSyncScopeRequest, JS as peerBackoffSeconds, cf as peerCanSyncPrivateOpByPersonalScopeGrant, af as personalScopeGrantStatusForPeer, Jd as planReplicationOpsAgePrune, ja as populateMemoryRefs, tm as probeAvailableCredentials, X_ as projectAdapterToolEvent, Ni as projectBasename, Ii as projectClause, Fi as projectColumnClause, Li as projectMatchesFilter, Gd as pruneReplicationOps, Kd as pruneReplicationOpsUntilCaughtUp, wp as rawEventsGate, sm as readAuthFile, Bt as readCodememConfigFile, Vt as readCodememConfigFileAtPath, ou as readCoordinatorSyncConfig, Xg as readImportPayload, It as readWorkspaceCodememConfigFile, gx as reassignProjectScopeInventoryProject, co as recencyScore, bf as reconcileStalePeerReceivedRows, Rd as recordAccessCleanupOp, br as recordNonce, iS as recordPeerSuccess, Ld as recordReplicationOp, rS as recordSyncAttempt, qp as redactText, Yu as refreshConfiguredScopeMembershipCache, Ju as refreshScopeMembershipCache, pu as refreshStoredCoordinatorPeerAddresses, lu as registerCoordinatorPresence, Nf as rejectInboundScopeFailures, mm as renderObserverHeaders, wy as replayBatchExtraction, Ty as replayBatchExtractionWithTierRouting, sf as replicationOpRequiresPersonalScopeAuthorization, Gl as requestJson, $o as rerankResults, $t as resolveBuiltInProviderDefaultModel, Qt as resolveBuiltInProviderFromModel, en as resolveBuiltInProviderModel, Rt as resolveCodememConfigPath, un as resolveCustomProviderDefaultModel, tn as resolveCustomProviderFromModel, dn as resolveCustomProviderModel, kn as resolveDbPath, Mr as resolveHookProject, rr as resolveKeyPaths, Zp as resolveOAuthProvider, nn as resolvePlaceholder, zi as resolveProject, ta as resolveProjectScope, Sp as retryRawEventFailures, am as runAuthCommand, Og as runDedupKeyBackfillPass, Ox as runRefBackfillPass, Hy as runScopeBackfillPass, Vx as runSessionContextBackfillPass, Xx as runSummaryDedupBackfillPass, iC as runSyncDaemon, HS as runSyncPass, yb as runVectorMigrationPass, R_ as sanitizePayload, V_ as sanitizeToolOutput, Rh as scanSecretsRetroactive, H as schema, hC as scopeAuthorizationFailureReason, a as scopeMembershipEpochStatus, es as search, SC as seedMixedScopeFixture, eS as selectDialAddresses, Ks as semanticSearch, ys as serializeFloat32, oS as setPeerLocalActorClaim, aS as setPeerProjectFilter, jd as setReplicationCursor, $S as setSyncDaemonError, QS as setSyncDaemonOk, tC as setSyncDaemonPhase, Sd as setSyncResetState, YS as shouldSkipOfflinePeer, gr as signRequest, si as startMaintenanceJob, tr as storePrivateKeyKeychain, Ws as storeVectors, Dt as stripJsonComments, M_ as stripPrivate, I_ as stripPrivateObj, Ot as stripTrailingCommas, Pf as summarizeInboundScopeRejections, rC as syncDaemonTick, VS as syncOnce, BS as syncPassPreflight, nf as syncProjectAllowedByFilters, _C as syncScopeResetRequiredPayload, rf as syncVisibilityAllowed, X as tableExists, is as timeline, Z as toJson, qn as toJsonNullable, ci as updateMaintenanceJob, nS as updatePeerAddresses, Ru as upsertCachedScopeMemberships, Cg as upsertCoordinatorGroupPreference, _x as upsertProjectScopeSettingsMapping, yi as vacuumDatabase, fr as validateExistingKeypair, _r as verifySignature, Ht as writeCodememConfigFile, Ut as writeWorkspaceCodememConfigFile };
|
|
19151
|
+
export { nd as ACCESS_CLEANUP_OP_TYPE, Ae as Api, Qe as BetterSqliteCoordinatorStore, Lt as CODEMEM_CONFIG_ENV_OVERRIDES, Tg as DEDUP_KEY_BACKFILL_JOB, z as DEFAULT_COORDINATOR_DB_PATH, On as DEFAULT_DB_PATH, yu as DEFAULT_SCOPE_MEMBERSHIP_CACHE_MAX_AGE_MS, $x as DEFAULT_SERVICE_TYPE, td as DEFAULT_SYNC_SCOPE_ID, o as DEFAULT_TIME_WINDOW_S, kg as DedupKeyBackfillRunner, xi as INJECTION_EVAL_SCENARIO_PACKS, Ey as LEGACY_SHARED_REVIEW_SCOPE_ID, Bi as LOCAL_DEFAULT_SCOPE_ID, qy as LOCAL_SYNC_CAPABILITY, H_ as LOW_SIGNAL_TOOLS, wr as MAPPABLE_CLAUDE_HOOK_EVENTS, Hr as MAPPABLE_CODEX_HOOK_EVENTS, Tn as MIN_COMPATIBLE_SCHEMA, je as MUTATING_TOOL_NAMES, up as MemoryStore, um as ObserverAuthAdapter, Hm as ObserverAuthError, hh as ObserverClient, Cx as REF_BACKFILL_JOB, v_ as RICH_TIER_DEFAULTS, Sx as RawEventSweeper, kx as RefBackfillRunner, wn as SCHEMA_VERSION, Dy as SCOPE_BACKFILL_JOB, n as SCOPE_MEMBERSHIP_REVOCATION_LIMITATION, Ax as SESSION_CONTEXT_BACKFILL_JOB, mr as SIGNATURE_VERSION, __ as SIMPLE_TIER_DEFAULTS, Wx as SUMMARY_DEDUP_BACKFILL_JOB, Gy as SYNC_CAPABILITIES, Ky as SYNC_CAPABILITY_HEADER, _C as SYNC_SCOPE_QUERY_PARAM, Uy as ScopeBackfillRunner, Ux as SessionContextBackfillRunner, Zx as SummaryDedupBackfillRunner, gC as SyncRetentionRunner, gv as TRIVIAL_REQUESTS, Qy as VECTOR_MODEL_MIGRATION_JOB, DC as VERSION, bb as VectorModelMigrationRunner, ps as _resetEmbeddingClient, bC as addSyncScopeToBoundary, Rl as addressDedupeKey, hS as advertiseMdns, Ah as aiBackfillStructuredContent, px as analyzeProjectScopeMappingChangeGuardrails, kb as applyBootstrapSnapshot, Hf as applyReplicationOps, Vn as assertSchemaReady, Wp as backfillMemoryDedupKeys, zp as backfillNarrativeFromBody, zf as backfillReplicationOps, zy as backfillScopeIds, kp as backfillTagsText, Ws as backfillVectors, _n as bootstrapSchema, ev as budgetToolEvents, yr as buildAuthHeaders, Ul as buildBaseUrl, hr as buildCanonicalRequest, im as buildCodexHeaders, la as buildFilterClauses, ua as buildFilterClausesWithContext, Bg as buildImportKey, $r as buildIngestPayloadFromCodexHook, Vr as buildIngestPayloadFromHook, fl as buildMemoryPack, ml as buildMemoryPackAsync, pl as buildMemoryPackTrace, hl as buildMemoryPackTraceAsync, mv as buildObserverPrompt, Qr as buildRawEventEnvelopeFromCodexHook, Br as buildRawEventEnvelopeFromHook, cy as buildSessionContext, Tv as buildTranscript, qd as bulkPruneReplicationOpsByAgeCutoff, Oi as canonicalMemoryKind, Ki as canonicalWorkspaceIdentity, Ed as chunkOpsBySize, ds as chunkText, Ay as classifyLegacyMemoryScope, ty as cleanOrphanSessions, xr as cleanupNonces, Aa as clearMemoryRefs, Fd as clockTuple, bp as compareMemoryRoleReports, li as completeMaintenanceJob, Pn as connect, Ze as connectCoordinator, ZS as consecutiveConnectivityFailures, Xh as coordinatorArchiveGroupAction, Jh as coordinatorCreateGroupAction, dg as coordinatorCreateInviteAction, eg as coordinatorCreateScopeAction, cg as coordinatorDisableDeviceAction, lg as coordinatorEnableDeviceAction, ou as coordinatorEnabled, ag as coordinatorEnrollDeviceAction, rg as coordinatorGrantScopeMembershipAction, fg as coordinatorImportInviteAction, hg as coordinatorListBootstrapGrantsAction, og as coordinatorListDevicesAction, Qh as coordinatorListGroupsAction, pg as coordinatorListJoinRequestsAction, ng as coordinatorListScopeMembershipsAction, $h as coordinatorListScopesAction, ug as coordinatorRemoveDeviceAction, sg as coordinatorRenameDeviceAction, Yh as coordinatorRenameGroupAction, mg as coordinatorReviewJoinRequestAction, gg as coordinatorRevokeBootstrapGrantAction, ig as coordinatorRevokeScopeMembershipAction, _u as coordinatorStatusSnapshot, Zh as coordinatorUnarchiveGroupAction, tg as coordinatorUpdateScopeAction, Sr as createBetterSqliteCoordinatorApp, c as createCoordinatorApp, hu as createCoordinatorReciprocalApproval, CS as cursorAdvances, Ip as deactivateLowSignalMemories, Fp as deactivateLowSignalObservations, k_ as decideExtractionReplayTier, s as decodeInvitePayload, Lp as dedupNearDuplicateMemories, as as dedupeOrderedIds, _g as defaultSpaceScopeIdForGroup, wg as deleteCoordinatorGroupPreference, vx as deleteProjectScopeSettingsMapping, wv as deriveRequest, ed as deriveTags, xf as diagnoseStalePeerReceivedRows, gS as discoverPeersViaMdns, gs as embedTexts, t as encodeInvitePayload, pr as ensureDeviceIdentity, di as ensureMaintenanceJobsSchema, xn as ensureSchemaBootstrapped, My as ensureScopeBackfillScopes, Tu as ensureScopeMembershipCacheStateTable, tc as estimateTokens, h_ as evaluateSessionExtractionItems, q_ as eventToToolEvent, oo as expandQuery, ls as explain, e as explainScopeMembershipRevocation, Yg as exportMemories, Y_ as extractAdapterEvent, Me as extractApplyPatchPaths, Ev as extractAssistantMessages, Dv as extractAssistantUsage, r as extractInvitePayload, Rp as extractNarrativeFromBody, $p as extractOAuthAccess, nm as extractOAuthAccountId, rm as extractOAuthExpires, Ov as extractPrompts, em as extractProviderApiKey, Pd as extractReplicationOps, J_ as extractToolEvents, ui as failMaintenanceJob, Sb as fetchAllSnapshotPages, pu as fetchCoordinatorStalePeers, $u as fileTags, _f as filterReplicationOpsForSync, gf as filterReplicationOpsForSyncWithStatus, Pa as findByConcept, Na as findByFile, i as fingerprintPublicKey, Cv as firstSentence, uy as flushRawEvents, Ll as formatHostPort, Gn as fromJson, Kn as fromJsonStrict, lr as generateKeypair, Xu as getCachedScopeAuthorization, zt as getCodememConfigPath, Wt as getCodememEnvOverrides, xg as getCoordinatorGroupPreference, hs as getEmbeddingClient, s_ as getExtractionBenchmarkProfile, bi as getInjectionEvalScenarioByPrompt, Si as getInjectionEvalScenarioPack, Ci as getInjectionEvalScenarioPrompts, Q as getMaintenanceJob, yp as getMemoryRoleReport, Kt as getOpenCodeProviderConfig, ln as getProviderApiKey, sn as getProviderBaseUrl, cn as getProviderHeaders, on as getProviderOptions, _i as getRawEventRelinkPlan, gi as getRawEventRelinkReport, xp as getRawEventStatus, Cp as getReliabilityMetrics, Ad as getReplicationCursor, Bn as getSchemaVersion, Rs as getSemanticIndexDiagnostics, g_ as getSessionExtractionEval, m_ as getSessionExtractionEvalScenario, Ti as getSummaryMetadata, iC as getSyncDaemonPhase, xd as getSyncResetState, Mt as getWorkspaceCodememConfigPath, Nt as getWorkspaceScopedCodememConfigPath, Vv as hasMeaningfulObservation, Eg as hasPendingDedupKeyBackfill, Tx as hasPendingRefBackfill, Iy as hasPendingScopeBackfill, Bx as hasPendingSessionContextBackfill, Kx as hasPendingSummaryDedupBackfill, Wd as hasUnsyncedSharedMemoryChanges, us as hashText, a_ as importMemories, $v as ingest, ny as ingestMain, vi as initDatabase, wC as initTestSchema, TC as insertTestSession, l as inviteLink, XS as isConnectivityError, zn as isEmbeddingDisabled, U_ as isInternalMemoryTool, Mp as isLowSignalObservation, Id as isNewerClock, Yy as isScopedSyncCapability, F_ as isSensitiveFieldName, Ei as isSummaryLikeMemory, Sv as isTrivialRequest, co as kindBonus, SC as listAuthorizedScopesForPeer, Yu as listCachedScopesForDevice, Xt as listConfiguredOpenCodeProviders, Sg as listCoordinatorGroupPreferences, vu as listCoordinatorJoinRequests, mu as listCoordinatorReciprocalApprovals, qt as listCustomProviders, c_ as listExtractionBenchmarkProfiles, Ff as listInboundScopeRejections, oi as listMaintenanceJobs, Zt as listObserverProviderOptions, CC as listPerPeerScopeSyncState, mx as listProjectScopeCandidates, hx as listProjectScopeInventory, ox as listProjectScopeSettingsMappings, ax as listSharingDomainSettingsScopes, Ud as loadMemorySnapshotPageForPeer, Vm as loadObserverConfig, kt as loadOpenCodeConfig, Xp as loadOpenCodeOAuthCache, tS as loadPeerAddresses, ar as loadPrivateKey, nr as loadPrivateKeyKeychain, ir as loadPublicKey, Hd as loadReplicationOpsForPeer, Vd as loadReplicationOpsSince, Rn as loadSqliteVec, lu as lookupCoordinatorPeers, Rr as mapClaudeHookPayload, Zr as mapCodexHookPayload, _S as mdnsAddressesForPeer, lS as mdnsEnabled, zl as mergeAddresses, Vg as mergeSummaryMetadata, Nn as migrateLegacyDbPath, Rf as migrateLegacyImportKeys, Zy as negotiateSyncCapability, Av as normalizeAdapterEvents, Il as normalizeAddress, ka as normalizeConcept, kv as normalizeEventsForSessionContext, jp as normalizeObservation, kr as normalizeProjectLabel, xv as normalizeRequestText, Xy as normalizeSyncCapability, Qu as normalizeTag, W_ as normalizeToolName, Bv as parseObserverResponse, Ra as parsePositiveMemoryId, La as parseStrictInteger, vC as parseSyncScopeRequest, QS as peerBackoffSeconds, cf as peerCanSyncPrivateOpByPersonalScopeGrant, af as personalScopeGrantStatusForPeer, Jd as planReplicationOpsAgePrune, ja as populateMemoryRefs, tm as probeAvailableCredentials, X_ as projectAdapterToolEvent, Ni as projectBasename, Ii as projectClause, Fi as projectColumnClause, Li as projectMatchesFilter, Gd as pruneReplicationOps, Kd as pruneReplicationOpsUntilCaughtUp, wp as rawEventsGate, sm as readAuthFile, Bt as readCodememConfigFile, Vt as readCodememConfigFileAtPath, au as readCoordinatorSyncConfig, Xg as readImportPayload, It as readWorkspaceCodememConfigFile, gx as reassignProjectScopeInventoryProject, so as recencyScore, bf as reconcileStalePeerReceivedRows, Rd as recordAccessCleanupOp, br as recordNonce, iS as recordPeerSuccess, Ld as recordReplicationOp, rS as recordSyncAttempt, qp as redactText, Ju as refreshConfiguredScopeMembershipCache, qu as refreshScopeMembershipCache, fu as refreshStoredCoordinatorPeerAddresses, cu as registerCoordinatorPresence, Nf as rejectInboundScopeFailures, mm as renderObserverHeaders, wy as replayBatchExtraction, Ty as replayBatchExtractionWithTierRouting, sf as replicationOpRequiresPersonalScopeAuthorization, Wl as requestJson, Qo as rerankResults, $t as resolveBuiltInProviderDefaultModel, Qt as resolveBuiltInProviderFromModel, en as resolveBuiltInProviderModel, Rt as resolveCodememConfigPath, un as resolveCustomProviderDefaultModel, tn as resolveCustomProviderFromModel, dn as resolveCustomProviderModel, kn as resolveDbPath, Mr as resolveHookProject, rr as resolveKeyPaths, Zp as resolveOAuthProvider, nn as resolvePlaceholder, zi as resolveProject, ta as resolveProjectScope, Sp as retryRawEventFailures, am as runAuthCommand, Og as runDedupKeyBackfillPass, Ox as runRefBackfillPass, Hy as runScopeBackfillPass, Vx as runSessionContextBackfillPass, Xx as runSummaryDedupBackfillPass, cC as runSyncDaemon, KS as runSyncPass, yb as runVectorMigrationPass, R_ as sanitizePayload, V_ as sanitizeToolOutput, Rh as scanSecretsRetroactive, H as schema, yC as scopeAuthorizationFailureReason, a as scopeMembershipEpochStatus, $o as search, EC as seedMixedScopeFixture, eS as selectDialAddresses, Gs as semanticSearch, vs as serializeFloat32, oS as setPeerLocalActorClaim, aS as setPeerProjectFilter, jd as setReplicationCursor, rC as setSyncDaemonError, nC as setSyncDaemonOk, aC as setSyncDaemonPhase, Sd as setSyncResetState, $S as shouldSkipOfflinePeer, gr as signRequest, si as startMaintenanceJob, tr as storePrivateKeyKeychain, Us as storeVectors, Dt as stripJsonComments, M_ as stripPrivate, I_ as stripPrivateObj, Ot as stripTrailingCommas, Pf as summarizeInboundScopeRejections, sC as syncDaemonTick, GS as syncOnce, WS as syncPassPreflight, nf as syncProjectAllowedByFilters, xC as syncScopeResetRequiredPayload, rf as syncVisibilityAllowed, X as tableExists, rs as timeline, Z as toJson, qn as toJsonNullable, ci as updateMaintenanceJob, nS as updatePeerAddresses, Lu as upsertCachedScopeMemberships, Cg as upsertCoordinatorGroupPreference, _x as upsertProjectScopeSettingsMapping, yi as vacuumDatabase, fr as validateExistingKeypair, _r as verifySignature, Ht as writeCodememConfigFile, Ut as writeWorkspaceCodememConfigFile };
|
|
19100
19152
|
|
|
19101
19153
|
//# sourceMappingURL=index.js.map
|