@codemem/core 0.20.0-alpha.6 → 0.20.0-alpha.7
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/coordinator-runtime.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +775 -754
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3454,7 +3454,19 @@ function Pi(e, t) {
|
|
|
3454
3454
|
function Fi(e) {
|
|
3455
3455
|
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) : [];
|
|
3456
3456
|
}
|
|
3457
|
-
|
|
3457
|
+
var Ii = /* @__PURE__ */ new Map();
|
|
3458
|
+
function Li(e, t) {
|
|
3459
|
+
let n = [...t.syncCoordinatorGroups].sort().join(",");
|
|
3460
|
+
return `${e.dbPath}|${t.syncCoordinatorUrl}|${n}`;
|
|
3461
|
+
}
|
|
3462
|
+
function Ri(e) {
|
|
3463
|
+
let t = Math.max(1, e.syncCoordinatorPresenceTtlS), n = Math.floor(t / 2);
|
|
3464
|
+
return Math.max(5, Math.min(60, n > 0 ? n : 1)) * 1e3;
|
|
3465
|
+
}
|
|
3466
|
+
function zi() {
|
|
3467
|
+
return 3e4;
|
|
3468
|
+
}
|
|
3469
|
+
function Bi(e) {
|
|
3458
3470
|
let t = { ...e ?? et() }, n = nt();
|
|
3459
3471
|
for (let e of Object.keys(n)) {
|
|
3460
3472
|
let r = process.env[n[e]];
|
|
@@ -3477,24 +3489,24 @@ function Ii(e) {
|
|
|
3477
3489
|
syncCoordinatorAdminSecret: Mi(t.sync_coordinator_admin_secret)
|
|
3478
3490
|
};
|
|
3479
3491
|
}
|
|
3480
|
-
function
|
|
3492
|
+
function Vi(e) {
|
|
3481
3493
|
return !!(e.syncCoordinatorUrl && e.syncCoordinatorGroups.length > 0);
|
|
3482
3494
|
}
|
|
3483
|
-
function
|
|
3495
|
+
function Hi(e) {
|
|
3484
3496
|
let t = e.syncAdvertise.toLowerCase();
|
|
3485
3497
|
if (t && t !== "auto" && t !== "default") return ji([], t.split(",").map((e) => e.trim()).filter(Boolean));
|
|
3486
3498
|
if (e.syncHost && e.syncHost !== "0.0.0.0") return [`${e.syncHost}:${e.syncPort}`];
|
|
3487
3499
|
let n = Object.values(y()).flatMap((e) => e ?? []).filter((e) => !e.internal).map((e) => e.address).filter((e) => e && e !== "127.0.0.1" && e !== "::1").map((t) => `${t}:${e.syncPort}`);
|
|
3488
3500
|
return [...new Set(n)];
|
|
3489
3501
|
}
|
|
3490
|
-
async function
|
|
3491
|
-
if (!
|
|
3502
|
+
async function Ui(e, t) {
|
|
3503
|
+
if (!Vi(t)) return null;
|
|
3492
3504
|
let n = process.env.CODEMEM_KEYS_DIR?.trim() || void 0, [r, i] = qn(e.db, { keysDir: n }), a = Rn(n);
|
|
3493
3505
|
if (!a) throw Error("public key missing");
|
|
3494
3506
|
let o = Tn(t.syncCoordinatorUrl), s = {
|
|
3495
3507
|
fingerprint: i,
|
|
3496
3508
|
public_key: a,
|
|
3497
|
-
addresses:
|
|
3509
|
+
addresses: Hi(t),
|
|
3498
3510
|
ttl_s: Math.max(1, t.syncCoordinatorPresenceTtlS)
|
|
3499
3511
|
}, c = [];
|
|
3500
3512
|
for (let e of t.syncCoordinatorGroups) {
|
|
@@ -3524,8 +3536,8 @@ async function zi(e, t) {
|
|
|
3524
3536
|
responses: c
|
|
3525
3537
|
};
|
|
3526
3538
|
}
|
|
3527
|
-
async function
|
|
3528
|
-
if (!
|
|
3539
|
+
async function Wi(e, t) {
|
|
3540
|
+
if (!Vi(t)) return [];
|
|
3529
3541
|
let n = process.env.CODEMEM_KEYS_DIR?.trim() || void 0, [r] = qn(e.db, { keysDir: n }), i = Tn(t.syncCoordinatorUrl), a = /* @__PURE__ */ new Map();
|
|
3530
3542
|
for (let e of t.syncCoordinatorGroups) {
|
|
3531
3543
|
let o = `${i}/v1/peers?group_id=${encodeURIComponent(e)}`, [s, c] = await En("GET", o, {
|
|
@@ -3561,9 +3573,9 @@ async function Bi(e, t) {
|
|
|
3561
3573
|
}
|
|
3562
3574
|
return [...a.values()];
|
|
3563
3575
|
}
|
|
3564
|
-
async function
|
|
3576
|
+
async function Gi(e, t) {
|
|
3565
3577
|
let n = Number(e.db.prepare("SELECT COUNT(1) AS total FROM sync_peers").get()?.total ?? 0);
|
|
3566
|
-
if (!
|
|
3578
|
+
if (!Vi(t)) return {
|
|
3567
3579
|
enabled: !1,
|
|
3568
3580
|
configured: !1,
|
|
3569
3581
|
groups: t.syncCoordinatorGroups,
|
|
@@ -3581,25 +3593,34 @@ async function Vi(e, t) {
|
|
|
3581
3593
|
fresh_peer_count: 0,
|
|
3582
3594
|
stale_peer_count: 0,
|
|
3583
3595
|
discovered_peer_count: 0
|
|
3584
|
-
};
|
|
3585
|
-
|
|
3586
|
-
|
|
3587
|
-
|
|
3588
|
-
|
|
3589
|
-
|
|
3596
|
+
}, i = Li(e, t), a = Date.now(), o = Ii.get(i);
|
|
3597
|
+
if (o && a < o.nextRefreshAtMs) r.presence_status = o.status, r.presence_error = o.error, r.advertised_addresses = o.advertisedAddresses;
|
|
3598
|
+
else try {
|
|
3599
|
+
let n = (await Ui(e, t))?.responses?.[0], o = n && typeof n == "object" ? n.addresses ?? [] : [];
|
|
3600
|
+
r.presence_status = "posted", r.advertised_addresses = o, Ii.set(i, {
|
|
3601
|
+
status: "posted",
|
|
3602
|
+
error: null,
|
|
3603
|
+
advertisedAddresses: o,
|
|
3604
|
+
nextRefreshAtMs: a + Ri(t)
|
|
3605
|
+
});
|
|
3590
3606
|
} catch (e) {
|
|
3591
|
-
let t = e instanceof Error ? e.message : String(e);
|
|
3592
|
-
r.presence_status =
|
|
3607
|
+
let t = e instanceof Error ? e.message : String(e), n = t.includes("unknown_device") ? "not_enrolled" : "error", o = n === "not_enrolled" ? a : a + zi();
|
|
3608
|
+
r.presence_status = n, r.presence_error = t, Ii.set(i, {
|
|
3609
|
+
status: n,
|
|
3610
|
+
error: t,
|
|
3611
|
+
advertisedAddresses: [],
|
|
3612
|
+
nextRefreshAtMs: o
|
|
3613
|
+
});
|
|
3593
3614
|
}
|
|
3594
3615
|
try {
|
|
3595
|
-
let n = await
|
|
3616
|
+
let n = await Wi(e, t);
|
|
3596
3617
|
r.discovered_peer_count = n.length, r.fresh_peer_count = n.filter((e) => !e.stale).length, r.stale_peer_count = n.filter((e) => !!e.stale).length;
|
|
3597
3618
|
} catch (e) {
|
|
3598
3619
|
r.lookup_error = e instanceof Error ? e.message : String(e);
|
|
3599
3620
|
}
|
|
3600
3621
|
return r;
|
|
3601
3622
|
}
|
|
3602
|
-
async function
|
|
3623
|
+
async function Ki(e) {
|
|
3603
3624
|
let t = e.syncCoordinatorGroup || e.syncCoordinatorGroups[0] || "";
|
|
3604
3625
|
if (!t || !e.syncCoordinatorUrl || !e.syncCoordinatorAdminSecret) return [];
|
|
3605
3626
|
let [n, r] = await En("GET", `${Tn(e.syncCoordinatorUrl)}/v1/admin/join-requests?group_id=${encodeURIComponent(t)}`, {
|
|
@@ -3610,10 +3631,10 @@ async function Hi(e) {
|
|
|
3610
3631
|
}
|
|
3611
3632
|
//#endregion
|
|
3612
3633
|
//#region src/embeddings.ts
|
|
3613
|
-
function
|
|
3634
|
+
function qi(t) {
|
|
3614
3635
|
return e("sha256").update(t, "utf-8").digest("hex");
|
|
3615
3636
|
}
|
|
3616
|
-
function
|
|
3637
|
+
function Ji(e, t = 1200) {
|
|
3617
3638
|
let n = e.trim();
|
|
3618
3639
|
if (!n) return [];
|
|
3619
3640
|
if (n.length <= t) return [n];
|
|
@@ -3644,26 +3665,26 @@ function Wi(e, t = 1200) {
|
|
|
3644
3665
|
}
|
|
3645
3666
|
return a.length > 0 && i.push(a.join("\n\n")), i;
|
|
3646
3667
|
}
|
|
3647
|
-
var
|
|
3648
|
-
function
|
|
3649
|
-
|
|
3668
|
+
var Yi;
|
|
3669
|
+
function Xi() {
|
|
3670
|
+
Yi = void 0;
|
|
3650
3671
|
}
|
|
3651
|
-
async function
|
|
3652
|
-
if (
|
|
3653
|
-
if (Ft()) return
|
|
3672
|
+
async function Zi() {
|
|
3673
|
+
if (Yi !== void 0) return Yi;
|
|
3674
|
+
if (Ft()) return Yi = null, null;
|
|
3654
3675
|
let e = process.env.CODEMEM_EMBEDDING_MODEL || "BAAI/bge-small-en-v1.5";
|
|
3655
3676
|
try {
|
|
3656
|
-
|
|
3677
|
+
Yi = await $i(e);
|
|
3657
3678
|
} catch {
|
|
3658
|
-
|
|
3679
|
+
Yi = null;
|
|
3659
3680
|
}
|
|
3660
|
-
return
|
|
3681
|
+
return Yi;
|
|
3661
3682
|
}
|
|
3662
|
-
async function
|
|
3663
|
-
let t = await
|
|
3683
|
+
async function Qi(e) {
|
|
3684
|
+
let t = await Zi();
|
|
3664
3685
|
return t ? t.embed(e) : [];
|
|
3665
3686
|
}
|
|
3666
|
-
async function
|
|
3687
|
+
async function $i(e) {
|
|
3667
3688
|
let { pipeline: t } = await import("@xenova/transformers"), n = await t("feature-extraction", e, { quantized: !0 });
|
|
3668
3689
|
return {
|
|
3669
3690
|
model: e,
|
|
@@ -3684,14 +3705,14 @@ async function Yi(e) {
|
|
|
3684
3705
|
}
|
|
3685
3706
|
};
|
|
3686
3707
|
}
|
|
3687
|
-
function
|
|
3708
|
+
function ea(e) {
|
|
3688
3709
|
let t = Buffer.alloc(e.length * 4);
|
|
3689
3710
|
for (let n = 0; n < e.length; n++) t.writeFloatLE(e[n] ?? 0, n * 4);
|
|
3690
3711
|
return t;
|
|
3691
3712
|
}
|
|
3692
3713
|
//#endregion
|
|
3693
3714
|
//#region src/export-import.ts
|
|
3694
|
-
var
|
|
3715
|
+
var ta = [
|
|
3695
3716
|
"request",
|
|
3696
3717
|
"investigated",
|
|
3697
3718
|
"learned",
|
|
@@ -3705,13 +3726,13 @@ var Zi = [
|
|
|
3705
3726
|
"discovery_tokens",
|
|
3706
3727
|
"discovery_source"
|
|
3707
3728
|
];
|
|
3708
|
-
function
|
|
3729
|
+
function na() {
|
|
3709
3730
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
3710
3731
|
}
|
|
3711
|
-
function
|
|
3732
|
+
function ra() {
|
|
3712
3733
|
return Date.now();
|
|
3713
3734
|
}
|
|
3714
|
-
function
|
|
3735
|
+
function ia(e) {
|
|
3715
3736
|
if (typeof e != "string" || e.trim().length === 0) return null;
|
|
3716
3737
|
try {
|
|
3717
3738
|
return JSON.parse(e);
|
|
@@ -3719,12 +3740,12 @@ function ea(e) {
|
|
|
3719
3740
|
return B(e);
|
|
3720
3741
|
}
|
|
3721
3742
|
}
|
|
3722
|
-
function
|
|
3743
|
+
function aa(e, t) {
|
|
3723
3744
|
let n = { ...e };
|
|
3724
|
-
for (let r of t) n[r] =
|
|
3745
|
+
for (let r of t) n[r] = ia(e[r]);
|
|
3725
3746
|
return n;
|
|
3726
3747
|
}
|
|
3727
|
-
function
|
|
3748
|
+
function oa(e) {
|
|
3728
3749
|
if (e == null) return null;
|
|
3729
3750
|
if (typeof e == "string") try {
|
|
3730
3751
|
let t = JSON.parse(e);
|
|
@@ -3734,7 +3755,7 @@ function na(e) {
|
|
|
3734
3755
|
}
|
|
3735
3756
|
return typeof e == "object" && !Array.isArray(e) ? { ...e } : null;
|
|
3736
3757
|
}
|
|
3737
|
-
function
|
|
3758
|
+
function sa(e, t, n, r) {
|
|
3738
3759
|
let i = [
|
|
3739
3760
|
e,
|
|
3740
3761
|
t,
|
|
@@ -3742,18 +3763,18 @@ function ra(e, t, n, r) {
|
|
|
3742
3763
|
];
|
|
3743
3764
|
return r?.project && i.push(r.project), r?.createdAt && i.push(r.createdAt), r?.sourceDb && i.push(r.sourceDb), i.join("|");
|
|
3744
3765
|
}
|
|
3745
|
-
function
|
|
3746
|
-
let n =
|
|
3766
|
+
function ca(e, t) {
|
|
3767
|
+
let n = oa(t);
|
|
3747
3768
|
if (!n) return e;
|
|
3748
3769
|
let r = { ...e };
|
|
3749
|
-
for (let e of
|
|
3770
|
+
for (let e of ta) {
|
|
3750
3771
|
if (!(e in n)) continue;
|
|
3751
3772
|
let t = r[e], i = !(e in r);
|
|
3752
3773
|
i ||= e === "discovery_tokens" || e === "prompt_number" ? t == null : typeof t == "string" ? t.trim().length === 0 : Array.isArray(t) ? t.length === 0 : t == null, i && (r[e] = n[e]);
|
|
3753
3774
|
}
|
|
3754
3775
|
return r.import_metadata = t, r;
|
|
3755
3776
|
}
|
|
3756
|
-
function
|
|
3777
|
+
function la(e) {
|
|
3757
3778
|
if (typeof e != "string") return null;
|
|
3758
3779
|
let t = e.trim();
|
|
3759
3780
|
if (!t) return null;
|
|
@@ -3763,44 +3784,44 @@ function aa(e) {
|
|
|
3763
3784
|
}
|
|
3764
3785
|
return t;
|
|
3765
3786
|
}
|
|
3766
|
-
function
|
|
3787
|
+
function ua(e) {
|
|
3767
3788
|
return e.allProjects ? null : Yt(e.cwd ?? process.cwd(), e.project ?? null);
|
|
3768
3789
|
}
|
|
3769
|
-
function
|
|
3790
|
+
function da(e, t, n) {
|
|
3770
3791
|
let r = "SELECT * FROM sessions", i = [], a = [];
|
|
3771
3792
|
if (t) {
|
|
3772
3793
|
let e = Gt("project", t);
|
|
3773
3794
|
e.clause && (a.push(e.clause), i.push(...e.params));
|
|
3774
3795
|
}
|
|
3775
|
-
return n && (a.push("started_at >= ?"), i.push(n)), a.length > 0 && (r += ` WHERE ${a.join(" AND ")}`), r += " ORDER BY started_at ASC", e.prepare(r).all(...i).map((e) =>
|
|
3796
|
+
return n && (a.push("started_at >= ?"), i.push(n)), a.length > 0 && (r += ` WHERE ${a.join(" AND ")}`), r += " ORDER BY started_at ASC", e.prepare(r).all(...i).map((e) => aa(e, ["metadata_json"]));
|
|
3776
3797
|
}
|
|
3777
|
-
function
|
|
3798
|
+
function fa(e, t, n, r, i = "") {
|
|
3778
3799
|
if (n.length === 0) return [];
|
|
3779
3800
|
let a = `SELECT * FROM ${t} WHERE session_id IN (${n.map(() => "?").join(",")})${i} ORDER BY ${r}`;
|
|
3780
3801
|
return e.prepare(a).all(...n);
|
|
3781
3802
|
}
|
|
3782
|
-
function
|
|
3803
|
+
function pa(e = {}) {
|
|
3783
3804
|
let t = Nt(Ot(e.dbPath));
|
|
3784
3805
|
try {
|
|
3785
3806
|
Rt(t);
|
|
3786
|
-
let n =
|
|
3807
|
+
let n = ua(e), r = {};
|
|
3787
3808
|
n && (r.project = n), e.since && (r.since = e.since);
|
|
3788
|
-
let i =
|
|
3809
|
+
let i = da(t, n, e.since ?? null), a = i.map((e) => Number(e.id)).filter(Number.isFinite), o = fa(t, "memory_items", a, "created_at ASC", e.includeInactive ? "" : " AND active = 1").map((e) => aa(e, [
|
|
3789
3810
|
"metadata_json",
|
|
3790
3811
|
"facts",
|
|
3791
3812
|
"concepts",
|
|
3792
3813
|
"files_read",
|
|
3793
3814
|
"files_modified"
|
|
3794
|
-
])), s =
|
|
3815
|
+
])), s = fa(t, "session_summaries", a, "created_at_epoch ASC").map((e) => aa(e, [
|
|
3795
3816
|
"metadata_json",
|
|
3796
3817
|
"files_read",
|
|
3797
3818
|
"files_edited"
|
|
3798
|
-
])), c =
|
|
3819
|
+
])), c = fa(t, "user_prompts", a, "created_at_epoch ASC").map((e) => aa(e, ["metadata_json"])), l = /* @__PURE__ */ new Map();
|
|
3799
3820
|
for (let e of c) typeof e.id == "number" && typeof e.import_key == "string" && l.set(e.id, e.import_key);
|
|
3800
3821
|
for (let e of o) typeof e.user_prompt_id == "number" && (e.user_prompt_import_key = l.get(e.user_prompt_id) ?? null);
|
|
3801
3822
|
return {
|
|
3802
3823
|
version: "1.0",
|
|
3803
|
-
exported_at:
|
|
3824
|
+
exported_at: na(),
|
|
3804
3825
|
export_metadata: {
|
|
3805
3826
|
tool_version: "codemem",
|
|
3806
3827
|
projects: [...new Set(i.map((e) => String(e.project ?? "")).filter(Boolean))],
|
|
@@ -3818,28 +3839,28 @@ function la(e = {}) {
|
|
|
3818
3839
|
t.close();
|
|
3819
3840
|
}
|
|
3820
3841
|
}
|
|
3821
|
-
function
|
|
3842
|
+
function ma(e) {
|
|
3822
3843
|
let t = f(e === "-" ? 0 : Ze(e), "utf8"), n = JSON.parse(t);
|
|
3823
3844
|
if (typeof n != "object" || !n || Array.isArray(n)) throw Error("Import payload must be a JSON object");
|
|
3824
3845
|
let r = n;
|
|
3825
3846
|
if (r.version !== "1.0") throw Error(`Unsupported export version: ${String(n.version ?? "unknown")}`);
|
|
3826
3847
|
return r;
|
|
3827
3848
|
}
|
|
3828
|
-
function
|
|
3849
|
+
function ha(e, t, n) {
|
|
3829
3850
|
return e.prepare(`SELECT id FROM ${t} WHERE import_key = ? LIMIT 1`).get(n)?.id ?? null;
|
|
3830
3851
|
}
|
|
3831
|
-
function
|
|
3852
|
+
function ga() {
|
|
3832
3853
|
return process.env.USER?.trim() || process.env.USERNAME?.trim() || "import";
|
|
3833
3854
|
}
|
|
3834
|
-
function
|
|
3855
|
+
function _a(e, t) {
|
|
3835
3856
|
let n = e.insert(W).values({
|
|
3836
|
-
started_at: typeof t.started_at == "string" ? t.started_at :
|
|
3857
|
+
started_at: typeof t.started_at == "string" ? t.started_at : na(),
|
|
3837
3858
|
ended_at: typeof t.ended_at == "string" ? t.ended_at : null,
|
|
3838
3859
|
cwd: String(t.cwd ?? process.cwd()),
|
|
3839
3860
|
project: t.project == null ? null : String(t.project),
|
|
3840
3861
|
git_remote: t.git_remote == null ? null : String(t.git_remote),
|
|
3841
3862
|
git_branch: t.git_branch == null ? null : String(t.git_branch),
|
|
3842
|
-
user: String(t.user ??
|
|
3863
|
+
user: String(t.user ?? ga()),
|
|
3843
3864
|
tool_version: String(t.tool_version ?? "import"),
|
|
3844
3865
|
metadata_json: V(t.metadata_json ?? null),
|
|
3845
3866
|
import_key: String(t.import_key)
|
|
@@ -3847,22 +3868,22 @@ function pa(e, t) {
|
|
|
3847
3868
|
if (n == null) throw Error("session insert returned no id");
|
|
3848
3869
|
return n;
|
|
3849
3870
|
}
|
|
3850
|
-
function
|
|
3871
|
+
function va(e, t) {
|
|
3851
3872
|
let n = e.insert($t).values({
|
|
3852
3873
|
session_id: Number(t.session_id),
|
|
3853
3874
|
project: t.project == null ? null : String(t.project),
|
|
3854
3875
|
prompt_text: String(t.prompt_text ?? ""),
|
|
3855
3876
|
prompt_number: t.prompt_number == null ? null : Number(t.prompt_number),
|
|
3856
|
-
created_at: typeof t.created_at == "string" ? t.created_at :
|
|
3857
|
-
created_at_epoch: typeof t.created_at_epoch == "number" ? t.created_at_epoch :
|
|
3877
|
+
created_at: typeof t.created_at == "string" ? t.created_at : na(),
|
|
3878
|
+
created_at_epoch: typeof t.created_at_epoch == "number" ? t.created_at_epoch : ra(),
|
|
3858
3879
|
metadata_json: V(t.metadata_json ?? null),
|
|
3859
3880
|
import_key: String(t.import_key)
|
|
3860
3881
|
}).returning({ id: $t.id }).all()[0]?.id;
|
|
3861
3882
|
if (n == null) throw Error("prompt insert returned no id");
|
|
3862
3883
|
return n;
|
|
3863
3884
|
}
|
|
3864
|
-
function
|
|
3865
|
-
let n =
|
|
3885
|
+
function ya(e, t) {
|
|
3886
|
+
let n = na(), r = e.insert(G).values({
|
|
3866
3887
|
session_id: Number(t.session_id),
|
|
3867
3888
|
kind: String(t.kind ?? "observation"),
|
|
3868
3889
|
title: String(t.title ?? "Untitled"),
|
|
@@ -3896,7 +3917,7 @@ function ha(e, t) {
|
|
|
3896
3917
|
if (r == null) throw Error("memory insert returned no id");
|
|
3897
3918
|
return r;
|
|
3898
3919
|
}
|
|
3899
|
-
function
|
|
3920
|
+
function ba(e, t) {
|
|
3900
3921
|
let n = e.insert(en).values({
|
|
3901
3922
|
session_id: Number(t.session_id),
|
|
3902
3923
|
project: t.project == null ? null : String(t.project),
|
|
@@ -3909,15 +3930,15 @@ function ga(e, t) {
|
|
|
3909
3930
|
files_read: H(t.files_read),
|
|
3910
3931
|
files_edited: H(t.files_edited),
|
|
3911
3932
|
prompt_number: t.prompt_number == null ? null : Number(t.prompt_number),
|
|
3912
|
-
created_at: typeof t.created_at == "string" ? t.created_at :
|
|
3913
|
-
created_at_epoch: typeof t.created_at_epoch == "number" ? t.created_at_epoch :
|
|
3933
|
+
created_at: typeof t.created_at == "string" ? t.created_at : na(),
|
|
3934
|
+
created_at_epoch: typeof t.created_at_epoch == "number" ? t.created_at_epoch : ra(),
|
|
3914
3935
|
metadata_json: V(t.metadata_json ?? null),
|
|
3915
3936
|
import_key: String(t.import_key)
|
|
3916
3937
|
}).returning({ id: en.id }).all()[0]?.id;
|
|
3917
3938
|
if (n == null) throw Error("summary insert returned no id");
|
|
3918
3939
|
return n;
|
|
3919
3940
|
}
|
|
3920
|
-
function
|
|
3941
|
+
function xa(e, t = {}) {
|
|
3921
3942
|
let n = Array.isArray(e.sessions) ? e.sessions : [], r = Array.isArray(e.memory_items) ? e.memory_items : [], i = Array.isArray(e.session_summaries) ? e.session_summaries : [], a = Array.isArray(e.user_prompts) ? e.user_prompts : [];
|
|
3922
3943
|
if (t.dryRun) return {
|
|
3923
3944
|
sessions: n.length,
|
|
@@ -3933,10 +3954,10 @@ function _a(e, t = {}) {
|
|
|
3933
3954
|
return o.transaction(() => {
|
|
3934
3955
|
let s = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), u = 0, d = 0, f = 0, p = 0;
|
|
3935
3956
|
for (let r of n) {
|
|
3936
|
-
let n = Number(r.id), i = t.remapProject ||
|
|
3957
|
+
let n = Number(r.id), i = t.remapProject || la(r.project), a = sa("export", "session", r.id, {
|
|
3937
3958
|
project: i,
|
|
3938
3959
|
createdAt: typeof r.started_at == "string" ? r.started_at : null
|
|
3939
|
-
}), c =
|
|
3960
|
+
}), c = ha(o, "sessions", a);
|
|
3940
3961
|
if (c != null) {
|
|
3941
3962
|
s.set(n, c);
|
|
3942
3963
|
continue;
|
|
@@ -3948,7 +3969,7 @@ function _a(e, t = {}) {
|
|
|
3948
3969
|
original_ended_at: r.ended_at ?? null,
|
|
3949
3970
|
import_metadata: r.metadata_json ?? null,
|
|
3950
3971
|
import_key: a
|
|
3951
|
-
}, d =
|
|
3972
|
+
}, d = _a(e, {
|
|
3952
3973
|
...r,
|
|
3953
3974
|
project: i,
|
|
3954
3975
|
metadata_json: l,
|
|
@@ -3959,10 +3980,10 @@ function _a(e, t = {}) {
|
|
|
3959
3980
|
for (let n of a) {
|
|
3960
3981
|
let r = Number(n.session_id), i = s.get(r);
|
|
3961
3982
|
if (i == null) continue;
|
|
3962
|
-
let a = t.remapProject ||
|
|
3983
|
+
let a = t.remapProject || la(n.project), u = typeof n.import_key == "string" && n.import_key.trim() ? n.import_key.trim() : sa("export", "prompt", n.id, {
|
|
3963
3984
|
project: a,
|
|
3964
3985
|
createdAt: typeof n.created_at == "string" ? n.created_at : null
|
|
3965
|
-
}), f =
|
|
3986
|
+
}), f = ha(o, "user_prompts", u);
|
|
3966
3987
|
if (f != null) {
|
|
3967
3988
|
typeof n.id == "number" && c.set(n.id, f), l.set(u, f);
|
|
3968
3989
|
continue;
|
|
@@ -3973,7 +3994,7 @@ function _a(e, t = {}) {
|
|
|
3973
3994
|
original_created_at: n.created_at ?? null,
|
|
3974
3995
|
import_metadata: n.metadata_json ?? null,
|
|
3975
3996
|
import_key: u
|
|
3976
|
-
}, m =
|
|
3997
|
+
}, m = va(e, {
|
|
3977
3998
|
...n,
|
|
3978
3999
|
session_id: i,
|
|
3979
4000
|
project: a,
|
|
@@ -3985,13 +4006,13 @@ function _a(e, t = {}) {
|
|
|
3985
4006
|
for (let n of r) {
|
|
3986
4007
|
let r = Number(n.session_id), i = s.get(r);
|
|
3987
4008
|
if (i == null) continue;
|
|
3988
|
-
let a = t.remapProject ||
|
|
4009
|
+
let a = t.remapProject || la(n.project), u = typeof n.import_key == "string" && n.import_key.trim() ? n.import_key.trim() : sa("export", "memory", n.id, {
|
|
3989
4010
|
project: a,
|
|
3990
4011
|
createdAt: typeof n.created_at == "string" ? n.created_at : null
|
|
3991
4012
|
});
|
|
3992
|
-
if (
|
|
4013
|
+
if (ha(o, "memory_items", u) != null) continue;
|
|
3993
4014
|
let d = null;
|
|
3994
|
-
typeof n.user_prompt_import_key == "string" && n.user_prompt_import_key.trim() ? d = l.get(n.user_prompt_import_key.trim()) ??
|
|
4015
|
+
typeof n.user_prompt_import_key == "string" && n.user_prompt_import_key.trim() ? d = l.get(n.user_prompt_import_key.trim()) ?? ha(o, "user_prompts", n.user_prompt_import_key.trim()) : typeof n.user_prompt_id == "number" && (d = c.get(n.user_prompt_id) ?? null);
|
|
3995
4016
|
let p = {
|
|
3996
4017
|
source: "export",
|
|
3997
4018
|
original_memory_id: n.id ?? null,
|
|
@@ -4000,8 +4021,8 @@ function _a(e, t = {}) {
|
|
|
4000
4021
|
import_key: u
|
|
4001
4022
|
};
|
|
4002
4023
|
typeof n.user_prompt_import_key == "string" && n.user_prompt_import_key.trim() && (p.user_prompt_import_key = n.user_prompt_import_key.trim());
|
|
4003
|
-
let m = n.kind === "session_summary" ?
|
|
4004
|
-
|
|
4024
|
+
let m = n.kind === "session_summary" ? ca(p, n.metadata_json ?? null) : p;
|
|
4025
|
+
ya(e, {
|
|
4005
4026
|
...n,
|
|
4006
4027
|
session_id: i,
|
|
4007
4028
|
project: a,
|
|
@@ -4013,11 +4034,11 @@ function _a(e, t = {}) {
|
|
|
4013
4034
|
for (let n of i) {
|
|
4014
4035
|
let r = Number(n.session_id), i = s.get(r);
|
|
4015
4036
|
if (i == null) continue;
|
|
4016
|
-
let a = t.remapProject ||
|
|
4037
|
+
let a = t.remapProject || la(n.project), c = typeof n.import_key == "string" && n.import_key.trim() ? n.import_key.trim() : sa("export", "summary", n.id, {
|
|
4017
4038
|
project: a,
|
|
4018
4039
|
createdAt: typeof n.created_at == "string" ? n.created_at : null
|
|
4019
4040
|
});
|
|
4020
|
-
if (
|
|
4041
|
+
if (ha(o, "session_summaries", c) != null) continue;
|
|
4021
4042
|
let l = {
|
|
4022
4043
|
source: "export",
|
|
4023
4044
|
original_summary_id: n.id ?? null,
|
|
@@ -4025,7 +4046,7 @@ function _a(e, t = {}) {
|
|
|
4025
4046
|
import_metadata: n.metadata_json ?? null,
|
|
4026
4047
|
import_key: c
|
|
4027
4048
|
};
|
|
4028
|
-
|
|
4049
|
+
ba(e, {
|
|
4029
4050
|
...n,
|
|
4030
4051
|
session_id: i,
|
|
4031
4052
|
project: a,
|
|
@@ -4047,7 +4068,7 @@ function _a(e, t = {}) {
|
|
|
4047
4068
|
}
|
|
4048
4069
|
//#endregion
|
|
4049
4070
|
//#region src/filters.ts
|
|
4050
|
-
function
|
|
4071
|
+
function Sa(e) {
|
|
4051
4072
|
if (e == null) return [];
|
|
4052
4073
|
let t = Array.isArray(e) ? e : [e], n = /* @__PURE__ */ new Set(), r = [];
|
|
4053
4074
|
for (let e of t) {
|
|
@@ -4056,16 +4077,16 @@ function va(e) {
|
|
|
4056
4077
|
}
|
|
4057
4078
|
return r;
|
|
4058
4079
|
}
|
|
4059
|
-
function
|
|
4060
|
-
return
|
|
4080
|
+
function Ca(e) {
|
|
4081
|
+
return Sa(e).map((e) => e.toLowerCase()).filter((e, t, n) => (e === "personal" || e === "shared") && n.indexOf(e) === t);
|
|
4061
4082
|
}
|
|
4062
|
-
function
|
|
4063
|
-
return
|
|
4083
|
+
function wa(e) {
|
|
4084
|
+
return Sa(e).map((e) => e.toLowerCase()).filter((e, t, n) => (e === "private" || e === "shared") && n.indexOf(e) === t);
|
|
4064
4085
|
}
|
|
4065
|
-
function
|
|
4066
|
-
return
|
|
4086
|
+
function Ta(e) {
|
|
4087
|
+
return Sa(e).map((e) => e.toLowerCase()).filter((e, t, n) => (e === "trusted" || e === "legacy_unknown" || e === "unreviewed") && n.indexOf(e) === t);
|
|
4067
4088
|
}
|
|
4068
|
-
function
|
|
4089
|
+
function Ea(e, t, n, r, i) {
|
|
4069
4090
|
if (r.length > 0) {
|
|
4070
4091
|
let i = r.map(() => "?").join(", ");
|
|
4071
4092
|
e.push(`${n} IN (${i})`), t.push(...r);
|
|
@@ -4075,10 +4096,10 @@ function Sa(e, t, n, r, i) {
|
|
|
4075
4096
|
e.push(`(${n} IS NULL OR ${n} NOT IN (${r}))`), t.push(...i);
|
|
4076
4097
|
}
|
|
4077
4098
|
}
|
|
4078
|
-
function
|
|
4079
|
-
return
|
|
4099
|
+
function Da(e) {
|
|
4100
|
+
return Oa(e);
|
|
4080
4101
|
}
|
|
4081
|
-
function
|
|
4102
|
+
function Oa(e, t) {
|
|
4082
4103
|
let n = {
|
|
4083
4104
|
clauses: [],
|
|
4084
4105
|
params: [],
|
|
@@ -4092,48 +4113,48 @@ function wa(e, t) {
|
|
|
4092
4113
|
let { clause: t, params: a } = Kt(e.project);
|
|
4093
4114
|
t && (r.push(t), i.push(...a), n.joinSessions = !0);
|
|
4094
4115
|
}
|
|
4095
|
-
return
|
|
4116
|
+
return Ea(r, i, "memory_items.visibility", wa(e.include_visibility ?? e.visibility), wa(e.exclude_visibility)), Ea(r, i, "memory_items.workspace_id", Sa(e.include_workspace_ids), Sa(e.exclude_workspace_ids)), Ea(r, i, "memory_items.workspace_kind", Ca(e.include_workspace_kinds), Ca(e.exclude_workspace_kinds)), Ea(r, i, "memory_items.actor_id", Sa(e.include_actor_ids), Sa(e.exclude_actor_ids)), Ea(r, i, "memory_items.trust_state", Ta(e.include_trust_states), Ta(e.exclude_trust_states)), n;
|
|
4096
4117
|
}
|
|
4097
4118
|
//#endregion
|
|
4098
4119
|
//#region src/ingest-sanitize.ts
|
|
4099
|
-
var
|
|
4100
|
-
function
|
|
4120
|
+
var ka = /<private>.*?<\/private>/gis, Aa = /<private>/i, ja = /<\/private>/gi;
|
|
4121
|
+
function Ma(e) {
|
|
4101
4122
|
if (!e) return "";
|
|
4102
|
-
let t = e.replace(
|
|
4103
|
-
return n && (t = t.slice(0, n.index)), t = t.replace(
|
|
4123
|
+
let t = e.replace(ka, ""), n = Aa.exec(t);
|
|
4124
|
+
return n && (t = t.slice(0, n.index)), t = t.replace(ja, ""), t;
|
|
4104
4125
|
}
|
|
4105
|
-
var
|
|
4106
|
-
function
|
|
4126
|
+
var Na = /(?:^|_|-)(?:token|secret|password|passwd|api[_-]?key|authorization|private[_-]?key|cookie)(?:$|_|-)/i, Pa = "[REDACTED]";
|
|
4127
|
+
function Fa(e) {
|
|
4107
4128
|
let t = e.trim().toLowerCase();
|
|
4108
|
-
return t ?
|
|
4129
|
+
return t ? Na.test(t) : !1;
|
|
4109
4130
|
}
|
|
4110
|
-
function
|
|
4111
|
-
if (typeof e == "string") return
|
|
4112
|
-
if (Array.isArray(e)) return e.map(
|
|
4131
|
+
function Ia(e) {
|
|
4132
|
+
if (typeof e == "string") return Ma(e);
|
|
4133
|
+
if (Array.isArray(e)) return e.map(Ia);
|
|
4113
4134
|
if (typeof e == "object" && e) {
|
|
4114
4135
|
let t = {};
|
|
4115
|
-
for (let [n, r] of Object.entries(e))
|
|
4136
|
+
for (let [n, r] of Object.entries(e)) Fa(n) ? t[n] = Pa : t[n] = Ia(r);
|
|
4116
4137
|
return t;
|
|
4117
4138
|
}
|
|
4118
4139
|
return e;
|
|
4119
4140
|
}
|
|
4120
|
-
function
|
|
4141
|
+
function La(e, t) {
|
|
4121
4142
|
return t <= 0 ? "" : e.length <= t ? e : `${e.slice(0, t)}... (truncated)`;
|
|
4122
4143
|
}
|
|
4123
|
-
function
|
|
4144
|
+
function Ra(e, t) {
|
|
4124
4145
|
if (e == null) return null;
|
|
4125
|
-
if (typeof e == "string") return
|
|
4126
|
-
let n =
|
|
4146
|
+
if (typeof e == "string") return La(Ma(e), t);
|
|
4147
|
+
let n = Ia(e);
|
|
4127
4148
|
try {
|
|
4128
4149
|
let e = JSON.stringify(n);
|
|
4129
|
-
if (t > 0 && e.length > t) return
|
|
4150
|
+
if (t > 0 && e.length > t) return La(e, t);
|
|
4130
4151
|
} catch {
|
|
4131
4152
|
let e = String(n);
|
|
4132
|
-
if (t > 0 && e.length > t) return
|
|
4153
|
+
if (t > 0 && e.length > t) return La(e, t);
|
|
4133
4154
|
}
|
|
4134
4155
|
return n;
|
|
4135
4156
|
}
|
|
4136
|
-
var
|
|
4157
|
+
var za = new Set([
|
|
4137
4158
|
"wrote file successfully.",
|
|
4138
4159
|
"wrote file successfully",
|
|
4139
4160
|
"file written successfully.",
|
|
@@ -4142,19 +4163,19 @@ var Fa = new Set([
|
|
|
4142
4163
|
"<file>",
|
|
4143
4164
|
"<image>"
|
|
4144
4165
|
]);
|
|
4145
|
-
function
|
|
4166
|
+
function Ba(e) {
|
|
4146
4167
|
if (!e) return !0;
|
|
4147
4168
|
let t = e.split("\n").map((e) => e.trim()).filter(Boolean);
|
|
4148
|
-
return t.length === 0 ? !0 : t.every((e) =>
|
|
4169
|
+
return t.length === 0 ? !0 : t.every((e) => za.has(e.toLowerCase()));
|
|
4149
4170
|
}
|
|
4150
|
-
function
|
|
4171
|
+
function Va(e, t, n) {
|
|
4151
4172
|
if (t == null) return null;
|
|
4152
|
-
let r =
|
|
4153
|
-
return
|
|
4173
|
+
let r = Ra(t, n);
|
|
4174
|
+
return Ba(String(r ?? "")) ? "" : r;
|
|
4154
4175
|
}
|
|
4155
4176
|
//#endregion
|
|
4156
4177
|
//#region src/ingest-events.ts
|
|
4157
|
-
var
|
|
4178
|
+
var Ha = new Set([
|
|
4158
4179
|
"tui",
|
|
4159
4180
|
"shell",
|
|
4160
4181
|
"cmd",
|
|
@@ -4164,48 +4185,48 @@ var Ra = new Set([
|
|
|
4164
4185
|
"todowrite",
|
|
4165
4186
|
"askuserquestion"
|
|
4166
4187
|
]);
|
|
4167
|
-
function
|
|
4188
|
+
function Ua(e) {
|
|
4168
4189
|
return e.startsWith("codemem_memory_");
|
|
4169
4190
|
}
|
|
4170
|
-
function
|
|
4191
|
+
function Wa(e) {
|
|
4171
4192
|
let t = String(e.tool ?? e.type ?? "tool").toLowerCase();
|
|
4172
4193
|
return t.includes(".") && (t = t.split(".").pop() ?? t), t.includes(":") && (t = t.split(":").pop() ?? t), t;
|
|
4173
4194
|
}
|
|
4174
|
-
function
|
|
4195
|
+
function Ga(e, t = 80, n = 2e3) {
|
|
4175
4196
|
if (!e) return "";
|
|
4176
4197
|
let r = e.split("\n"), i = r;
|
|
4177
4198
|
i.length > t && (i = [...i.slice(0, t), `... (+${r.length - t} more lines)`]);
|
|
4178
4199
|
let a = i.join("\n");
|
|
4179
4200
|
return n > 0 && a.length > n && (a = `${a.slice(0, n)}\n... (truncated)`), a;
|
|
4180
4201
|
}
|
|
4181
|
-
function
|
|
4182
|
-
return
|
|
4202
|
+
function Ka(e) {
|
|
4203
|
+
return Ga(e, 120, 2400);
|
|
4183
4204
|
}
|
|
4184
|
-
function
|
|
4205
|
+
function qa(e, t, n = Ha) {
|
|
4185
4206
|
if (e.type !== "tool.execute.after") return null;
|
|
4186
|
-
let r =
|
|
4187
|
-
if (
|
|
4188
|
-
let i = e.args, a = typeof i == "object" && i && !Array.isArray(i) ? i : {}, o =
|
|
4189
|
-
r === "read" && typeof o == "string" && (o =
|
|
4190
|
-
let s =
|
|
4207
|
+
let r = Wa(e);
|
|
4208
|
+
if (Ua(r) || n.has(r)) return null;
|
|
4209
|
+
let i = e.args, a = typeof i == "object" && i && !Array.isArray(i) ? i : {}, o = Va(r, e.result, t);
|
|
4210
|
+
r === "read" && typeof o == "string" && (o = Ga(o)), r === "bash" && typeof o == "string" && (o = Ga(o)), (r === "glob" || r === "grep") && typeof o == "string" && (o = Ka(o));
|
|
4211
|
+
let s = Ra(e.error, t);
|
|
4191
4212
|
return {
|
|
4192
4213
|
toolName: r,
|
|
4193
|
-
toolInput:
|
|
4214
|
+
toolInput: Ra(a, t),
|
|
4194
4215
|
toolOutput: o,
|
|
4195
4216
|
toolError: s,
|
|
4196
4217
|
timestamp: typeof e.timestamp == "string" ? e.timestamp : null,
|
|
4197
4218
|
cwd: (typeof e.cwd == "string" ? e.cwd : null) ?? (typeof a.cwd == "string" ? a.cwd : null)
|
|
4198
4219
|
};
|
|
4199
4220
|
}
|
|
4200
|
-
function
|
|
4221
|
+
function Ja(e, t) {
|
|
4201
4222
|
let n = [];
|
|
4202
4223
|
for (let r of e) {
|
|
4203
|
-
let e =
|
|
4224
|
+
let e = qa(r, t);
|
|
4204
4225
|
e && n.push(e);
|
|
4205
4226
|
}
|
|
4206
4227
|
return n;
|
|
4207
4228
|
}
|
|
4208
|
-
function
|
|
4229
|
+
function Ya(e) {
|
|
4209
4230
|
let t = e._adapter;
|
|
4210
4231
|
if (typeof t != "object" || !t || Array.isArray(t)) return null;
|
|
4211
4232
|
let n = t;
|
|
@@ -4228,7 +4249,7 @@ function Ga(e) {
|
|
|
4228
4249
|
}
|
|
4229
4250
|
return n;
|
|
4230
4251
|
}
|
|
4231
|
-
function
|
|
4252
|
+
function Xa(e, t) {
|
|
4232
4253
|
let n = String(e.event_type ?? ""), r = e.payload;
|
|
4233
4254
|
if (!r || typeof r != "object" || n !== "tool_result") return null;
|
|
4234
4255
|
let i = r.tool_input;
|
|
@@ -4246,7 +4267,7 @@ function Ka(e, t) {
|
|
|
4246
4267
|
cwd: t.cwd
|
|
4247
4268
|
};
|
|
4248
4269
|
}
|
|
4249
|
-
function
|
|
4270
|
+
function Za(e) {
|
|
4250
4271
|
if (e.toolName === "bash" && e.toolInput != null && typeof e.toolInput == "object") {
|
|
4251
4272
|
let t = e.toolInput, n = String(t.command ?? "").trim().toLowerCase();
|
|
4252
4273
|
if ((n === "git status" || n === "git diff") && !e.toolError) return `bash:${n}`;
|
|
@@ -4259,26 +4280,26 @@ function qa(e) {
|
|
|
4259
4280
|
}
|
|
4260
4281
|
return e.toolError && t.push(String(e.toolError).slice(0, 200)), typeof e.toolOutput == "string" && e.toolOutput && t.push(e.toolOutput.slice(0, 200)), t.join("|");
|
|
4261
4282
|
}
|
|
4262
|
-
function
|
|
4283
|
+
function Qa(e) {
|
|
4263
4284
|
let t = 0;
|
|
4264
4285
|
e.toolError && (t += 100);
|
|
4265
4286
|
let n = (e.toolName || "").toLowerCase();
|
|
4266
4287
|
return n === "edit" || n === "write" ? t += 50 : n === "bash" ? t += 30 : n === "read" ? t += 20 : t += 10, t;
|
|
4267
4288
|
}
|
|
4268
|
-
function
|
|
4289
|
+
function $a(e) {
|
|
4269
4290
|
try {
|
|
4270
4291
|
return JSON.stringify(e).length;
|
|
4271
4292
|
} catch {
|
|
4272
4293
|
return String(e).length;
|
|
4273
4294
|
}
|
|
4274
4295
|
}
|
|
4275
|
-
function
|
|
4296
|
+
function eo(e, t, n) {
|
|
4276
4297
|
if (!e.length || t <= 0 || n <= 0) return [];
|
|
4277
4298
|
let r = /* @__PURE__ */ new Set(), i = [];
|
|
4278
4299
|
for (let t = e.length - 1; t >= 0; t--) {
|
|
4279
4300
|
let n = e[t];
|
|
4280
4301
|
if (!n) continue;
|
|
4281
|
-
let a =
|
|
4302
|
+
let a = Za(n);
|
|
4282
4303
|
r.has(a) || (r.add(a), i.push(n));
|
|
4283
4304
|
}
|
|
4284
4305
|
i.reverse();
|
|
@@ -4289,32 +4310,32 @@ function Xa(e, t, n) {
|
|
|
4289
4310
|
idx: t
|
|
4290
4311
|
}));
|
|
4291
4312
|
e.sort((e, t) => {
|
|
4292
|
-
let n =
|
|
4313
|
+
let n = Qa(t.event) - Qa(e.event);
|
|
4293
4314
|
return n === 0 ? e.idx - t.idx : n;
|
|
4294
4315
|
});
|
|
4295
4316
|
let t = new Set(e.slice(0, n).map((e) => e.idx));
|
|
4296
4317
|
a = a.filter((e, n) => t.has(n));
|
|
4297
4318
|
}
|
|
4298
|
-
if (a.reduce((e, t) => e +
|
|
4319
|
+
if (a.reduce((e, t) => e + $a(t), 0) <= t) return a;
|
|
4299
4320
|
let o = a.map((e, t) => ({
|
|
4300
4321
|
event: e,
|
|
4301
4322
|
idx: t
|
|
4302
4323
|
}));
|
|
4303
4324
|
o.sort((e, t) => {
|
|
4304
|
-
let n =
|
|
4325
|
+
let n = Qa(t.event) - Qa(e.event);
|
|
4305
4326
|
return n === 0 ? e.idx - t.idx : n;
|
|
4306
4327
|
});
|
|
4307
4328
|
let s = [], c = 0;
|
|
4308
4329
|
for (let e of o) {
|
|
4309
|
-
let n =
|
|
4330
|
+
let n = $a(e.event);
|
|
4310
4331
|
if (!(c + n > t && s.length > 0) && (s.push(e), c += n, c >= t)) break;
|
|
4311
4332
|
}
|
|
4312
4333
|
return s.sort((e, t) => e.idx - t.idx), s.map((e) => e.event);
|
|
4313
4334
|
}
|
|
4314
4335
|
//#endregion
|
|
4315
4336
|
//#region src/ingest-prompts.ts
|
|
4316
|
-
var
|
|
4317
|
-
<type>[ ${
|
|
4337
|
+
var to = "bugfix, feature, refactor, change, discovery, decision, exploration", no = "You are a memory observer creating searchable records of development work FOR FUTURE SESSIONS. Record what was BUILT/FIXED/DEPLOYED/CONFIGURED/LEARNED, not what you (the observer) are doing. These memories help developers recall past work, decisions, learnings, and investigations.", ro = "Focus on deliverables, capabilities, AND learnings:\n- What the system NOW DOES differently (new capabilities)\n- What shipped to users/production (features, fixes, configs, docs)\n- What was LEARNED through debugging, investigation, or testing\n- How systems work and why they behave the way they do\n- Changes in technical domains (auth, data, UI, infra, DevOps)\n\nUse outcome-focused verbs: implemented, fixed, deployed, configured, migrated, optimized, added, refactored, discovered, learned, debugged.\nOnly describe actions that are clearly supported by the observed context.\nNever invent file changes, API behavior, or code edits that are not explicitly present in the session evidence.\n\nGOOD examples (describes what was built or learned):\n- \"Authentication now supports OAuth2 with PKCE flow\"\n- \"Deployment pipeline runs canary releases with auto-rollback\"\n- \"Fixed race condition in session handler causing duplicate events\"\n- \"Discovered flush timing strategy needed adaptation for multi-session environment\"\n- \"Learned transcript building was broken - empty strings passed instead of conversation\"\n\nBAD examples (describes observation process - DO NOT DO THIS):\n- \"Analyzed authentication implementation and stored findings in database\"\n- \"Tracked deployment steps and logged outcomes to memory system\"\n- \"Recorded investigation results for later reference\"", io = "Skip routine operations WITHOUT learnings:\n- Empty status checks or listings (unless revealing important state)\n- Package installations with no errors or insights\n- Simple file reads with no discoveries\n- Repetitive operations already documented with no new findings\nIf nothing meaningful happened AND nothing was learned:\n- Output no <observation> blocks\n- Output <skip_summary reason=\"low-signal\"/> instead of a <summary> block.", ao = "Create narratives that tell the complete story:\n- Context: What was the problem or goal? What prompted this work?\n- Investigation: What was examined? What was discovered?\n- Learning: How does it work? Why does it exist? Any gotchas?\n- Implementation: What was changed? What does the code do now?\n- Impact: What's better? What does the system do differently?\n- Next steps: What remains? What should future sessions know?\n\nAim for ~120-400 words per significant work item.\nPrefer fewer, higher-signal observations over many small ones.\nInclude specific details when present: file paths, function names, configuration values.", oo = "Output only XML. Do not include commentary outside XML.\n\nALWAYS emit at least one <observation> block for any meaningful work. Observations are the PRIMARY output - they capture what was built, fixed, learned, or decided. Also emit a <summary> block to track session progress.\n\nPrefer fewer, more comprehensive observations over many small ones.", so = `<observation>
|
|
4338
|
+
<type>[ ${to} ]</type>
|
|
4318
4339
|
<!--
|
|
4319
4340
|
type MUST be EXACTLY one of these 7 options:
|
|
4320
4341
|
- bugfix: something was broken, now fixed
|
|
@@ -4362,11 +4383,11 @@ var Za = "bugfix, feature, refactor, change, discovery, decision, exploration",
|
|
|
4362
4383
|
<files_modified>
|
|
4363
4384
|
<file>[full path from project root]</file>
|
|
4364
4385
|
</files_modified>
|
|
4365
|
-
</observation>`,
|
|
4366
|
-
function
|
|
4386
|
+
</observation>`, co = "<summary>\n <request>[What did the user request? What was the goal of this work session?]</request>\n\n <investigated>[What was explored or examined? What files, systems, logs were reviewed?\n What questions were asked? What did you try to understand?]</investigated>\n\n <learned>[What was learned about how things work? Any discoveries about the codebase,\n architecture, or domain? Gotchas or surprises? Understanding gained?]</learned>\n\n <completed>[What work was done? What shipped? What does the system do now that it\n didn't before? Be specific: files changed, features added, bugs fixed.]</completed>\n\n <next_steps>[What are the logical next steps? What remains to be done? What should\n the next session pick up? Any blockers or dependencies?]</next_steps>\n\n <notes>[Additional context, insights, or warnings. Anything future sessions should\n know that doesn't fit above. Design decisions, trade-offs, alternatives considered.]</notes>\n\n <files_read>\n <file>[path]</file>\n </files_read>\n <files_modified>\n <file>[path]</file>\n </files_modified>\n</summary>\n\nIf nothing meaningful happened, emit <skip_summary reason=\"low-signal\"/> and do not emit <summary>.\nOtherwise, write a summary that explains the current state of the PRIMARY work (not your observation process).\n\nIf the user prompt is a short approval or acknowledgement (\"yes\", \"ok\", \"approved\"),\ninfer the request from the observed work and the completed/learned sections instead.\n\nOnly summarize what is evidenced in the session context. Do not infer or fabricate\nfile edits, behaviors, or outcomes that are not explicitly observed.\n\nKeep summaries concise (aim for ~150-450 words total across all fields).\n\nThis summary helps future sessions understand where this work left off.";
|
|
4387
|
+
function lo(e) {
|
|
4367
4388
|
return e.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
4368
4389
|
}
|
|
4369
|
-
function
|
|
4390
|
+
function uo(e) {
|
|
4370
4391
|
if (e == null) return "";
|
|
4371
4392
|
if (typeof e == "string") return e;
|
|
4372
4393
|
try {
|
|
@@ -4375,43 +4396,43 @@ function oo(e) {
|
|
|
4375
4396
|
return String(e);
|
|
4376
4397
|
}
|
|
4377
4398
|
}
|
|
4378
|
-
function
|
|
4399
|
+
function fo(e) {
|
|
4379
4400
|
let t = ["<observed_from_primary_session>"];
|
|
4380
|
-
t.push(` <what_happened>${
|
|
4381
|
-
let n =
|
|
4401
|
+
t.push(` <what_happened>${lo(e.toolName)}</what_happened>`), e.timestamp && t.push(` <occurred_at>${lo(e.timestamp)}</occurred_at>`), e.cwd && t.push(` <working_directory>${lo(e.cwd)}</working_directory>`);
|
|
4402
|
+
let n = lo(uo(e.toolInput)), r = lo(uo(e.toolOutput)), i = lo(uo(e.toolError));
|
|
4382
4403
|
return n && t.push(` <parameters>${n}</parameters>`), r && t.push(` <outcome>${r}</outcome>`), i && t.push(` <error>${i}</error>`), t.push("</observed_from_primary_session>"), t.join("\n");
|
|
4383
4404
|
}
|
|
4384
|
-
function
|
|
4405
|
+
function po(e) {
|
|
4385
4406
|
let t = [
|
|
4386
|
-
|
|
4407
|
+
no,
|
|
4387
4408
|
"",
|
|
4388
|
-
|
|
4409
|
+
ro,
|
|
4389
4410
|
"",
|
|
4390
|
-
|
|
4411
|
+
io,
|
|
4391
4412
|
"",
|
|
4392
|
-
|
|
4413
|
+
ao,
|
|
4393
4414
|
"",
|
|
4394
|
-
|
|
4415
|
+
oo,
|
|
4395
4416
|
"",
|
|
4396
4417
|
"Observation XML schema:",
|
|
4397
|
-
|
|
4418
|
+
so
|
|
4398
4419
|
];
|
|
4399
|
-
e.includeSummary && t.push("", "Summary XML schema:",
|
|
4420
|
+
e.includeSummary && t.push("", "Summary XML schema:", co);
|
|
4400
4421
|
let n = t.join("\n\n").trim(), r = ["Observed session context:"];
|
|
4401
4422
|
if (e.userPrompt) {
|
|
4402
4423
|
let t = ["<observed_from_primary_session>"];
|
|
4403
|
-
t.push(` <user_request>${
|
|
4424
|
+
t.push(` <user_request>${lo(e.userPrompt)}</user_request>`), e.promptNumber != null && t.push(` <prompt_number>${e.promptNumber}</prompt_number>`), e.project && t.push(` <project>${lo(e.project)}</project>`), t.push("</observed_from_primary_session>"), r.push(t.join("\n"));
|
|
4404
4425
|
}
|
|
4405
|
-
e.diffSummary && r.push(`<observed_from_primary_session>\n <diff_summary>${
|
|
4406
|
-
for (let t of e.toolEvents) r.push(
|
|
4407
|
-
return e.includeSummary && e.lastAssistantMessage && (r.push("Summary context:"), r.push(`<summary_context>\n <assistant_response>${
|
|
4426
|
+
e.diffSummary && r.push(`<observed_from_primary_session>\n <diff_summary>${lo(e.diffSummary)}</diff_summary>\n</observed_from_primary_session>`), e.recentFiles && r.push(`<observed_from_primary_session>\n <recent_files>${lo(e.recentFiles)}</recent_files>\n</observed_from_primary_session>`);
|
|
4427
|
+
for (let t of e.toolEvents) r.push(fo(t));
|
|
4428
|
+
return e.includeSummary && e.lastAssistantMessage && (r.push("Summary context:"), r.push(`<summary_context>\n <assistant_response>${lo(e.lastAssistantMessage)}</assistant_response>\n</summary_context>`)), {
|
|
4408
4429
|
system: n,
|
|
4409
4430
|
user: r.join("\n\n").trim()
|
|
4410
4431
|
};
|
|
4411
4432
|
}
|
|
4412
4433
|
//#endregion
|
|
4413
4434
|
//#region src/ingest-transcript.ts
|
|
4414
|
-
var
|
|
4435
|
+
var mo = new Set([
|
|
4415
4436
|
"yes",
|
|
4416
4437
|
"y",
|
|
4417
4438
|
"ok",
|
|
@@ -4426,20 +4447,20 @@ var lo = new Set([
|
|
|
4426
4447
|
"go ahead",
|
|
4427
4448
|
"proceed"
|
|
4428
4449
|
]);
|
|
4429
|
-
function
|
|
4450
|
+
function ho(e) {
|
|
4430
4451
|
if (!e) return "";
|
|
4431
4452
|
let t = e.trim().replace(/^["']+|["']+$/g, "").trim();
|
|
4432
4453
|
return t = t.replace(/\s+/g, " "), t.toLowerCase();
|
|
4433
4454
|
}
|
|
4434
|
-
function
|
|
4435
|
-
let t =
|
|
4436
|
-
return t ?
|
|
4455
|
+
function go(e) {
|
|
4456
|
+
let t = ho(e);
|
|
4457
|
+
return t ? mo.has(t) : !0;
|
|
4437
4458
|
}
|
|
4438
|
-
function
|
|
4459
|
+
function _o(e) {
|
|
4439
4460
|
let t = e.split("\n").map((e) => e.trim()).filter(Boolean).join(" ");
|
|
4440
4461
|
return t = t.replace(/^[#*\-\d.\s]+/, ""), (t.split(/(?<=[.!?])\s+/)[0] ?? t).trim();
|
|
4441
4462
|
}
|
|
4442
|
-
function
|
|
4463
|
+
function vo(e) {
|
|
4443
4464
|
let t = [
|
|
4444
4465
|
e.completed,
|
|
4445
4466
|
e.learned,
|
|
@@ -4447,24 +4468,24 @@ function mo(e) {
|
|
|
4447
4468
|
e.nextSteps,
|
|
4448
4469
|
e.notes
|
|
4449
4470
|
];
|
|
4450
|
-
for (let e of t) if (e) return
|
|
4471
|
+
for (let e of t) if (e) return _o(e);
|
|
4451
4472
|
return "";
|
|
4452
4473
|
}
|
|
4453
|
-
function
|
|
4474
|
+
function yo(e) {
|
|
4454
4475
|
let t = [];
|
|
4455
4476
|
for (let n of e) {
|
|
4456
4477
|
let e = n.type;
|
|
4457
4478
|
if (e === "user_prompt") {
|
|
4458
|
-
let e =
|
|
4479
|
+
let e = Ma(String(n.prompt_text ?? "")).trim();
|
|
4459
4480
|
e && t.push(`User: ${e}`);
|
|
4460
4481
|
} else if (e === "assistant_message") {
|
|
4461
|
-
let e =
|
|
4482
|
+
let e = Ma(String(n.assistant_text ?? "")).trim();
|
|
4462
4483
|
e && t.push(`Assistant: ${e}`);
|
|
4463
4484
|
}
|
|
4464
4485
|
}
|
|
4465
4486
|
return t.join("\n\n");
|
|
4466
4487
|
}
|
|
4467
|
-
function
|
|
4488
|
+
function bo(e) {
|
|
4468
4489
|
let t = [];
|
|
4469
4490
|
for (let n of e) {
|
|
4470
4491
|
if (n.type !== "assistant_message") continue;
|
|
@@ -4473,7 +4494,7 @@ function go(e) {
|
|
|
4473
4494
|
}
|
|
4474
4495
|
return t;
|
|
4475
4496
|
}
|
|
4476
|
-
function
|
|
4497
|
+
function xo(e) {
|
|
4477
4498
|
let t = [];
|
|
4478
4499
|
for (let n of e) {
|
|
4479
4500
|
if (n.type !== "assistant_usage") continue;
|
|
@@ -4490,7 +4511,7 @@ function _o(e) {
|
|
|
4490
4511
|
}
|
|
4491
4512
|
return t;
|
|
4492
4513
|
}
|
|
4493
|
-
function
|
|
4514
|
+
function So(e) {
|
|
4494
4515
|
let t = [];
|
|
4495
4516
|
for (let n of e) {
|
|
4496
4517
|
if (n.type !== "user_prompt") continue;
|
|
@@ -4503,7 +4524,7 @@ function vo(e) {
|
|
|
4503
4524
|
}
|
|
4504
4525
|
return t;
|
|
4505
4526
|
}
|
|
4506
|
-
function
|
|
4527
|
+
function Co(e) {
|
|
4507
4528
|
return e.map((e) => {
|
|
4508
4529
|
let t = e._adapter;
|
|
4509
4530
|
if (typeof t != "object" || !t || Array.isArray(t)) return e;
|
|
@@ -4534,15 +4555,15 @@ function yo(e) {
|
|
|
4534
4555
|
}
|
|
4535
4556
|
//#endregion
|
|
4536
4557
|
//#region src/ingest-xml-parser.ts
|
|
4537
|
-
var
|
|
4538
|
-
function
|
|
4539
|
-
return e.replace(
|
|
4558
|
+
var wo = /<observation[^>]*>.*?<\/observation>/gs, To = /<summary[^>]*>.*?<\/summary>/gs, Eo = /<skip_summary(?:\s+reason="(?<reason>[^"]+)")?\s*\/>/i, Do = /```(?:xml)?/gi;
|
|
4559
|
+
function Oo(e) {
|
|
4560
|
+
return e.replace(Do, "").trim();
|
|
4540
4561
|
}
|
|
4541
|
-
function
|
|
4562
|
+
function ko(e, t) {
|
|
4542
4563
|
let n = RegExp(`<${t}[^>]*>([\\s\\S]*?)</${t}>`, "i").exec(e);
|
|
4543
4564
|
return n?.[1] ? n[1].trim() : "";
|
|
4544
4565
|
}
|
|
4545
|
-
function
|
|
4566
|
+
function Ao(e, t, n) {
|
|
4546
4567
|
let r = RegExp(`<${t}[^>]*>([\\s\\S]*?)</${t}>`, "i").exec(e);
|
|
4547
4568
|
if (!r?.[1]) return [];
|
|
4548
4569
|
let i = RegExp(`<${n}[^>]*>([\\s\\S]*?)</${n}>`, "gi"), a = [];
|
|
@@ -4552,21 +4573,21 @@ function Eo(e, t, n) {
|
|
|
4552
4573
|
}
|
|
4553
4574
|
return a;
|
|
4554
4575
|
}
|
|
4555
|
-
function
|
|
4556
|
-
let t =
|
|
4576
|
+
function jo(e) {
|
|
4577
|
+
let t = ko(e, "type"), n = ko(e, "title");
|
|
4557
4578
|
return !t && !n ? null : {
|
|
4558
4579
|
kind: t,
|
|
4559
4580
|
title: n,
|
|
4560
|
-
narrative:
|
|
4561
|
-
subtitle:
|
|
4562
|
-
facts:
|
|
4563
|
-
concepts:
|
|
4564
|
-
filesRead:
|
|
4565
|
-
filesModified:
|
|
4581
|
+
narrative: ko(e, "narrative"),
|
|
4582
|
+
subtitle: ko(e, "subtitle") || null,
|
|
4583
|
+
facts: Ao(e, "facts", "fact"),
|
|
4584
|
+
concepts: Ao(e, "concepts", "concept"),
|
|
4585
|
+
filesRead: Ao(e, "files_read", "file"),
|
|
4586
|
+
filesModified: Ao(e, "files_modified", "file")
|
|
4566
4587
|
};
|
|
4567
4588
|
}
|
|
4568
|
-
function
|
|
4569
|
-
let t =
|
|
4589
|
+
function Mo(e) {
|
|
4590
|
+
let t = ko(e, "request"), n = ko(e, "investigated"), r = ko(e, "learned"), i = ko(e, "completed"), a = ko(e, "next_steps"), o = ko(e, "notes");
|
|
4570
4591
|
return !t && !n && !r && !i && !a && !o ? null : {
|
|
4571
4592
|
request: t,
|
|
4572
4593
|
investigated: n,
|
|
@@ -4574,45 +4595,45 @@ function Oo(e) {
|
|
|
4574
4595
|
completed: i,
|
|
4575
4596
|
nextSteps: a,
|
|
4576
4597
|
notes: o,
|
|
4577
|
-
filesRead:
|
|
4578
|
-
filesModified:
|
|
4598
|
+
filesRead: Ao(e, "files_read", "file"),
|
|
4599
|
+
filesModified: Ao(e, "files_modified", "file")
|
|
4579
4600
|
};
|
|
4580
4601
|
}
|
|
4581
|
-
function
|
|
4582
|
-
let t =
|
|
4602
|
+
function No(e) {
|
|
4603
|
+
let t = Oo(e), n = [], r = t.match(wo) ?? [];
|
|
4583
4604
|
for (let e of r) {
|
|
4584
|
-
let t =
|
|
4605
|
+
let t = jo(e);
|
|
4585
4606
|
t && n.push(t);
|
|
4586
4607
|
}
|
|
4587
|
-
let i = null, a = (t.match(
|
|
4588
|
-
a && (i =
|
|
4589
|
-
let o =
|
|
4608
|
+
let i = null, a = (t.match(To) ?? []).at(-1);
|
|
4609
|
+
a && (i = Mo(a));
|
|
4610
|
+
let o = Eo.exec(t)?.groups?.reason ?? null;
|
|
4590
4611
|
return {
|
|
4591
4612
|
observations: n,
|
|
4592
4613
|
summary: i,
|
|
4593
4614
|
skipSummaryReason: o
|
|
4594
4615
|
};
|
|
4595
4616
|
}
|
|
4596
|
-
function
|
|
4617
|
+
function Po(e) {
|
|
4597
4618
|
return e.some((e) => e.title || e.narrative);
|
|
4598
4619
|
}
|
|
4599
4620
|
//#endregion
|
|
4600
4621
|
//#region src/vectors.ts
|
|
4601
|
-
async function
|
|
4602
|
-
let i = await
|
|
4622
|
+
async function Fo(e, t, n, r) {
|
|
4623
|
+
let i = await Zi();
|
|
4603
4624
|
if (!i) return;
|
|
4604
|
-
let a =
|
|
4625
|
+
let a = Ji(`${n}\n${r}`.trim());
|
|
4605
4626
|
if (a.length === 0) return;
|
|
4606
|
-
let o = await
|
|
4627
|
+
let o = await Qi(a);
|
|
4607
4628
|
if (o.length === 0) return;
|
|
4608
4629
|
let s = i.model, c = e.prepare("INSERT INTO memory_vectors(embedding, memory_id, chunk_index, content_hash, model) VALUES (?, ?, ?, ?, ?)");
|
|
4609
4630
|
for (let e = 0; e < a.length && e < o.length; e++) {
|
|
4610
4631
|
let n = o[e];
|
|
4611
|
-
!n || n.length === 0 || c.run(
|
|
4632
|
+
!n || n.length === 0 || c.run(ea(n), t, e, qi(a[e]), s);
|
|
4612
4633
|
}
|
|
4613
4634
|
}
|
|
4614
|
-
async function
|
|
4615
|
-
let n = await
|
|
4635
|
+
async function Io(e, t = {}) {
|
|
4636
|
+
let n = await Zi();
|
|
4616
4637
|
if (!n) return {
|
|
4617
4638
|
checked: 0,
|
|
4618
4639
|
embedded: 0,
|
|
@@ -4636,11 +4657,11 @@ async function Mo(e, t = {}) {
|
|
|
4636
4657
|
ORDER BY memory_items.created_at ASC ${p}`).all(...l), h = n.model, g = 0, _ = 0, v = 0, y = 0;
|
|
4637
4658
|
for (let t of m) {
|
|
4638
4659
|
g++;
|
|
4639
|
-
let n =
|
|
4660
|
+
let n = Ji(`${t.title ?? ""}\n${t.body_text ?? ""}`.trim());
|
|
4640
4661
|
if (n.length === 0) continue;
|
|
4641
4662
|
let r = e.prepare("SELECT content_hash FROM memory_vectors WHERE memory_id = ? AND model = ?").all(t.id, h), i = new Set(r.map((e) => e.content_hash).filter((e) => e != null)), a = [], o = [];
|
|
4642
4663
|
for (let e of n) {
|
|
4643
|
-
let t =
|
|
4664
|
+
let t = qi(e);
|
|
4644
4665
|
if (i.has(t)) {
|
|
4645
4666
|
y++;
|
|
4646
4667
|
continue;
|
|
@@ -4648,7 +4669,7 @@ async function Mo(e, t = {}) {
|
|
|
4648
4669
|
a.push(e), o.push(t);
|
|
4649
4670
|
}
|
|
4650
4671
|
if (a.length === 0) continue;
|
|
4651
|
-
let c = await
|
|
4672
|
+
let c = await Qi(a);
|
|
4652
4673
|
if (c.length === 0) continue;
|
|
4653
4674
|
if (_ += c.length, s) {
|
|
4654
4675
|
v += c.length;
|
|
@@ -4657,7 +4678,7 @@ async function Mo(e, t = {}) {
|
|
|
4657
4678
|
let l = e.prepare("INSERT INTO memory_vectors(embedding, memory_id, chunk_index, content_hash, model) VALUES (?, ?, ?, ?, ?)");
|
|
4658
4679
|
for (let e = 0; e < c.length; e++) {
|
|
4659
4680
|
let n = c[e];
|
|
4660
|
-
!n || n.length === 0 || (l.run(
|
|
4681
|
+
!n || n.length === 0 || (l.run(ea(n), t.id, e, o[e], h), v++);
|
|
4661
4682
|
}
|
|
4662
4683
|
}
|
|
4663
4684
|
return {
|
|
@@ -4667,13 +4688,13 @@ async function Mo(e, t = {}) {
|
|
|
4667
4688
|
skipped: y
|
|
4668
4689
|
};
|
|
4669
4690
|
}
|
|
4670
|
-
async function
|
|
4691
|
+
async function Lo(e, t, n = 10, r) {
|
|
4671
4692
|
if (t.trim().length < 3) return [];
|
|
4672
|
-
let i = await
|
|
4693
|
+
let i = await Qi([t]);
|
|
4673
4694
|
if (i.length === 0) return [];
|
|
4674
4695
|
let a = i[0];
|
|
4675
4696
|
if (!a) return [];
|
|
4676
|
-
let o = [
|
|
4697
|
+
let o = [ea(a), n], s = ["memory_items.active = 1"], c = !1;
|
|
4677
4698
|
if (r?.project) {
|
|
4678
4699
|
let e = Kt(r.project);
|
|
4679
4700
|
e.clause && (s.push(e.clause), o.push(...e.params), c = !0);
|
|
@@ -4705,7 +4726,7 @@ async function No(e, t, n = 10, r) {
|
|
|
4705
4726
|
}
|
|
4706
4727
|
//#endregion
|
|
4707
4728
|
//#region src/ingest-pipeline.ts
|
|
4708
|
-
var
|
|
4729
|
+
var Ro = new Set([
|
|
4709
4730
|
"bugfix",
|
|
4710
4731
|
"feature",
|
|
4711
4732
|
"refactor",
|
|
@@ -4714,17 +4735,17 @@ var Po = new Set([
|
|
|
4714
4735
|
"decision",
|
|
4715
4736
|
"exploration"
|
|
4716
4737
|
]);
|
|
4717
|
-
function
|
|
4738
|
+
function zo(e, t) {
|
|
4718
4739
|
if (!e) return "";
|
|
4719
4740
|
let n = e.trim();
|
|
4720
4741
|
if (!t) return n;
|
|
4721
4742
|
let r = t.replace(/\/+$/, "");
|
|
4722
4743
|
return n === r ? "." : n.startsWith(`${r}/`) ? n.slice(r.length + 1) : n;
|
|
4723
4744
|
}
|
|
4724
|
-
function
|
|
4725
|
-
return e.map((e) =>
|
|
4745
|
+
function Bo(e, t) {
|
|
4746
|
+
return e.map((e) => zo(e, t)).filter(Boolean);
|
|
4726
4747
|
}
|
|
4727
|
-
function
|
|
4748
|
+
function Vo(e) {
|
|
4728
4749
|
return [
|
|
4729
4750
|
["Request", e.request],
|
|
4730
4751
|
["Completed", e.completed],
|
|
@@ -4734,27 +4755,27 @@ function Lo(e) {
|
|
|
4734
4755
|
["Notes", e.notes]
|
|
4735
4756
|
].filter(([, e]) => e).map(([e, t]) => `## ${e}\n${t}`).join("\n\n");
|
|
4736
4757
|
}
|
|
4737
|
-
function
|
|
4758
|
+
function Ho(e, t) {
|
|
4738
4759
|
let n = [];
|
|
4739
4760
|
for (let r of e) {
|
|
4740
|
-
let e =
|
|
4761
|
+
let e = Ya(r);
|
|
4741
4762
|
if (e) {
|
|
4742
4763
|
if (e.event_type === "tool_call") continue;
|
|
4743
|
-
let i =
|
|
4764
|
+
let i = Xa(e, r);
|
|
4744
4765
|
if (i) {
|
|
4745
|
-
let e =
|
|
4766
|
+
let e = qa(i, t);
|
|
4746
4767
|
if (e) {
|
|
4747
4768
|
n.push(e);
|
|
4748
4769
|
continue;
|
|
4749
4770
|
}
|
|
4750
4771
|
}
|
|
4751
4772
|
}
|
|
4752
|
-
let i =
|
|
4773
|
+
let i = Ja([r], t);
|
|
4753
4774
|
n.push(...i);
|
|
4754
4775
|
}
|
|
4755
4776
|
return n;
|
|
4756
4777
|
}
|
|
4757
|
-
async function
|
|
4778
|
+
async function Uo(e, t, n) {
|
|
4758
4779
|
let r = e.cwd ?? process.cwd(), i = e.events ?? [];
|
|
4759
4780
|
if (!Array.isArray(i) || i.length === 0) return;
|
|
4760
4781
|
let a = e.sessionContext ?? {}, o = n.storeSummary ?? !0, s = n.storeTyped ?? !0, c = n.maxChars ?? 12e3, l = n.observerMaxChars ?? 12e3, u = N(t.db, { schema: U }), d = (/* @__PURE__ */ new Date()).toISOString(), f = Ce(e.project) ?? Yt(r) ?? null, p = u.insert(W).values({
|
|
@@ -4772,14 +4793,14 @@ async function zo(e, t, n) {
|
|
|
4772
4793
|
}).returning({ id: W.id }).all()[0]?.id;
|
|
4773
4794
|
if (p == null) throw Error("session insert returned no id");
|
|
4774
4795
|
try {
|
|
4775
|
-
let e =
|
|
4776
|
-
h =
|
|
4777
|
-
let _ =
|
|
4778
|
-
if (b &&
|
|
4779
|
-
|
|
4796
|
+
let e = Co(i), d = So(e), m = d.length > 0 ? d[d.length - 1]?.promptNumber ?? d.length : null, h = Ho(i, c), g = Math.max(2e3, Math.min(8e3, l - 5e3));
|
|
4797
|
+
h = eo(h, g, 30);
|
|
4798
|
+
let _ = bo(e), v = xo(e), y = _.at(-1) ?? null, b = a.firstPrompt ?? (d.length > 0 ? d[d.length - 1]?.promptText : null) ?? null, x = h.length > 0 || !!b || o && !!y;
|
|
4799
|
+
if (b && go(b) && h.length === 0 && !y && (x = !1), !x) {
|
|
4800
|
+
Wo(t, p, i.length, a);
|
|
4780
4801
|
return;
|
|
4781
4802
|
}
|
|
4782
|
-
let S =
|
|
4803
|
+
let S = yo(e), C = [];
|
|
4783
4804
|
if ((a.promptCount ?? 0) > 1 && C.push(`Session had ${a.promptCount} prompts`), (a.toolCount ?? 0) > 0 && C.push(`${a.toolCount} tool executions`), (a.durationMs ?? 0) > 0) {
|
|
4784
4805
|
let e = (a.durationMs ?? 0) / 6e4;
|
|
4785
4806
|
C.push(`~${e.toFixed(1)} minutes of work`);
|
|
@@ -4787,7 +4808,7 @@ async function zo(e, t, n) {
|
|
|
4787
4808
|
a.filesModified?.length && C.push(`Modified: ${a.filesModified.slice(0, 5).join(", ")}`), a.filesRead?.length && C.push(`Read: ${a.filesRead.slice(0, 5).join(", ")}`);
|
|
4788
4809
|
let w = C.join("; "), T = b ?? "";
|
|
4789
4810
|
w && (T = T ? `${T}\n\n[Session context: ${w}]` : `[Session context: ${w}]`);
|
|
4790
|
-
let { system: E, user: ee } =
|
|
4811
|
+
let { system: E, user: ee } = po({
|
|
4791
4812
|
project: f,
|
|
4792
4813
|
userPrompt: T,
|
|
4793
4814
|
promptNumber: m,
|
|
@@ -4800,26 +4821,26 @@ async function zo(e, t, n) {
|
|
|
4800
4821
|
if (!te.raw) {
|
|
4801
4822
|
if (a?.flusher === "raw_events") throw Error("observer failed during raw-event flush");
|
|
4802
4823
|
let e = n.observer.getStatus();
|
|
4803
|
-
console.warn(`[codemem] Observer returned no output (provider=${te.provider}, model=${te.model}${e.lastError ? `, error=${e.lastError}` : ""}). No memories will be created for this session.`),
|
|
4824
|
+
console.warn(`[codemem] Observer returned no output (provider=${te.provider}, model=${te.model}${e.lastError ? `, error=${e.lastError}` : ""}). No memories will be created for this session.`), Wo(t, p, i.length, a);
|
|
4804
4825
|
return;
|
|
4805
4826
|
}
|
|
4806
|
-
let D = te.raw, O =
|
|
4807
|
-
if (s &&
|
|
4827
|
+
let D = te.raw, O = No(D), k = [];
|
|
4828
|
+
if (s && Po(O.observations)) for (let e of O.observations) {
|
|
4808
4829
|
let t = e.kind.trim().toLowerCase();
|
|
4809
|
-
|
|
4830
|
+
Ro.has(t) && (!e.title && !e.narrative || Ut(e.title) || Ut(e.narrative) || (e.filesRead = Bo(e.filesRead, r), e.filesModified = Bo(e.filesModified, r), k.push(e)));
|
|
4810
4831
|
}
|
|
4811
4832
|
let A = null;
|
|
4812
4833
|
if (o && O.summary && !O.skipSummaryReason) {
|
|
4813
4834
|
let e = O.summary;
|
|
4814
4835
|
if (e.request || e.investigated || e.learned || e.completed || e.nextSteps || e.notes) {
|
|
4815
|
-
e.filesRead =
|
|
4836
|
+
e.filesRead = Bo(e.filesRead, r), e.filesModified = Bo(e.filesModified, r);
|
|
4816
4837
|
let t = e.request;
|
|
4817
|
-
if (
|
|
4818
|
-
let n =
|
|
4838
|
+
if (go(t)) {
|
|
4839
|
+
let n = vo(e);
|
|
4819
4840
|
n && (t = n);
|
|
4820
4841
|
}
|
|
4821
|
-
let n =
|
|
4822
|
-
n && !Ut(
|
|
4842
|
+
let n = Vo(e);
|
|
4843
|
+
n && !Ut(_o(n)) && (A = {
|
|
4823
4844
|
summary: e,
|
|
4824
4845
|
request: t,
|
|
4825
4846
|
body: n
|
|
@@ -4885,17 +4906,17 @@ async function zo(e, t, n) {
|
|
|
4885
4906
|
}).run();
|
|
4886
4907
|
})();
|
|
4887
4908
|
for (let e of ne) try {
|
|
4888
|
-
await
|
|
4909
|
+
await Fo(t.db, e.memoryId, e.title, e.bodyText);
|
|
4889
4910
|
} catch {}
|
|
4890
|
-
|
|
4911
|
+
Wo(t, p, i.length, a);
|
|
4891
4912
|
} catch (e) {
|
|
4892
4913
|
try {
|
|
4893
|
-
|
|
4914
|
+
Wo(t, p, i.length, a);
|
|
4894
4915
|
} catch {}
|
|
4895
4916
|
throw e;
|
|
4896
4917
|
}
|
|
4897
4918
|
}
|
|
4898
|
-
function
|
|
4919
|
+
function Wo(e, t, n, r) {
|
|
4899
4920
|
e.endSession(t, {
|
|
4900
4921
|
post: {},
|
|
4901
4922
|
source: "plugin",
|
|
@@ -4903,11 +4924,11 @@ function Bo(e, t, n, r) {
|
|
|
4903
4924
|
session_context: r
|
|
4904
4925
|
});
|
|
4905
4926
|
}
|
|
4906
|
-
function
|
|
4927
|
+
function Go(e, t = 24) {
|
|
4907
4928
|
let n = N(e.db, { schema: U }), r = (/* @__PURE__ */ new Date(Date.now() - t * 36e5)).toISOString();
|
|
4908
4929
|
return n.update(W).set({ ended_at: r }).where(D(ie(W.ended_at), oe(W.started_at, r))).run().changes;
|
|
4909
4930
|
}
|
|
4910
|
-
async function
|
|
4931
|
+
async function Ko(e, t) {
|
|
4911
4932
|
let n = [];
|
|
4912
4933
|
for await (let e of process.stdin) n.push(String(e));
|
|
4913
4934
|
let r = n.join("");
|
|
@@ -4918,30 +4939,30 @@ async function Ho(e, t) {
|
|
|
4918
4939
|
} catch (e) {
|
|
4919
4940
|
throw Error(`codemem: invalid payload: ${e}`);
|
|
4920
4941
|
}
|
|
4921
|
-
await
|
|
4942
|
+
await Uo(i, e, { observer: t });
|
|
4922
4943
|
}
|
|
4923
4944
|
//#endregion
|
|
4924
4945
|
//#region src/integers.ts
|
|
4925
|
-
var
|
|
4926
|
-
function
|
|
4946
|
+
var qo = BigInt(2 ** 53 - 1), Jo = BigInt(-(2 ** 53 - 1));
|
|
4947
|
+
function Yo(e) {
|
|
4927
4948
|
if (e == null) return null;
|
|
4928
4949
|
let t = e.trim();
|
|
4929
4950
|
if (!/^[+-]?\d+$/.test(t)) return null;
|
|
4930
4951
|
try {
|
|
4931
4952
|
let e = BigInt(t);
|
|
4932
|
-
return e <
|
|
4953
|
+
return e < Jo || e > qo ? null : Number(e);
|
|
4933
4954
|
} catch {
|
|
4934
4955
|
return null;
|
|
4935
4956
|
}
|
|
4936
4957
|
}
|
|
4937
|
-
function
|
|
4958
|
+
function Xo(e) {
|
|
4938
4959
|
if (typeof e == "boolean") return null;
|
|
4939
4960
|
if (typeof e == "number") return !Number.isInteger(e) || !Number.isSafeInteger(e) || e <= 0 ? null : e;
|
|
4940
4961
|
if (typeof e == "string") {
|
|
4941
4962
|
if (!/^\d+$/.test(e)) return null;
|
|
4942
4963
|
try {
|
|
4943
4964
|
let t = BigInt(e);
|
|
4944
|
-
return t <= 0n || t >
|
|
4965
|
+
return t <= 0n || t > qo ? null : Number(t);
|
|
4945
4966
|
} catch {
|
|
4946
4967
|
return null;
|
|
4947
4968
|
}
|
|
@@ -4950,24 +4971,24 @@ function Ko(e) {
|
|
|
4950
4971
|
}
|
|
4951
4972
|
//#endregion
|
|
4952
4973
|
//#region src/observer-auth.ts
|
|
4953
|
-
var
|
|
4954
|
-
function
|
|
4974
|
+
var Zo = "0.0.1", Qo = [/sk-[A-Za-z0-9]{10,}/g, /Bearer\s+[A-Za-z0-9._-]{10,}/g];
|
|
4975
|
+
function $o(e, t = 400) {
|
|
4955
4976
|
let n = e;
|
|
4956
|
-
for (let e of
|
|
4977
|
+
for (let e of Qo) n = n.replace(new RegExp(e.source, e.flags), "[redacted]");
|
|
4957
4978
|
return n.length > t ? `${n.slice(0, t)}…` : n;
|
|
4958
4979
|
}
|
|
4959
|
-
function
|
|
4980
|
+
function es() {
|
|
4960
4981
|
return {
|
|
4961
4982
|
token: null,
|
|
4962
4983
|
authType: "none",
|
|
4963
4984
|
source: "none"
|
|
4964
4985
|
};
|
|
4965
4986
|
}
|
|
4966
|
-
function
|
|
4987
|
+
function ts() {
|
|
4967
4988
|
return T(v(), ".local", "share", "opencode", "auth.json");
|
|
4968
4989
|
}
|
|
4969
|
-
function
|
|
4970
|
-
let e =
|
|
4990
|
+
function ns() {
|
|
4991
|
+
let e = ts();
|
|
4971
4992
|
if (!l(e)) return {};
|
|
4972
4993
|
try {
|
|
4973
4994
|
let t = JSON.parse(f(e, "utf-8"));
|
|
@@ -4976,55 +4997,55 @@ function Qo() {
|
|
|
4976
4997
|
return {};
|
|
4977
4998
|
}
|
|
4978
4999
|
}
|
|
4979
|
-
function
|
|
5000
|
+
function rs(e, t) {
|
|
4980
5001
|
return e && ["openai", "anthropic"].includes(e.toLowerCase()) ? e.toLowerCase() : t.toLowerCase().startsWith("claude") ? "anthropic" : "openai";
|
|
4981
5002
|
}
|
|
4982
|
-
function
|
|
5003
|
+
function is(e, t) {
|
|
4983
5004
|
let n = e[t];
|
|
4984
5005
|
return typeof n == "object" && n && !Array.isArray(n) ? n : null;
|
|
4985
5006
|
}
|
|
4986
|
-
function
|
|
4987
|
-
let n =
|
|
5007
|
+
function as(e, t) {
|
|
5008
|
+
let n = is(e, t);
|
|
4988
5009
|
if (!n) return null;
|
|
4989
5010
|
let r = n.access;
|
|
4990
5011
|
return typeof r == "string" && r ? r : null;
|
|
4991
5012
|
}
|
|
4992
|
-
function
|
|
4993
|
-
let n =
|
|
5013
|
+
function os(e, t) {
|
|
5014
|
+
let n = is(e, t);
|
|
4994
5015
|
if (!n) return null;
|
|
4995
5016
|
let r = n.key;
|
|
4996
5017
|
return typeof r == "string" && r ? r : null;
|
|
4997
5018
|
}
|
|
4998
|
-
function
|
|
4999
|
-
let e =
|
|
5019
|
+
function ss() {
|
|
5020
|
+
let e = ns(), t = Date.now(), n = !!process.env.CODEMEM_OBSERVER_API_KEY, r = [
|
|
5000
5021
|
["openai", "OPENAI_API_KEY"],
|
|
5001
5022
|
["anthropic", "ANTHROPIC_API_KEY"],
|
|
5002
5023
|
["opencode", null]
|
|
5003
5024
|
], i = {};
|
|
5004
5025
|
for (let [a, o] of r) {
|
|
5005
|
-
let r =
|
|
5026
|
+
let r = as(e, a), s = ls(e, a);
|
|
5006
5027
|
i[a] = {
|
|
5007
|
-
oauth: a === "opencode" ? !!
|
|
5028
|
+
oauth: a === "opencode" ? !!os(e, a) : !!r && (s == null || s > t),
|
|
5008
5029
|
api_key: n,
|
|
5009
5030
|
env_var: o ? !!process.env[o] : !1
|
|
5010
5031
|
};
|
|
5011
5032
|
}
|
|
5012
5033
|
return i;
|
|
5013
5034
|
}
|
|
5014
|
-
function
|
|
5015
|
-
let n =
|
|
5035
|
+
function cs(e, t) {
|
|
5036
|
+
let n = is(e, t);
|
|
5016
5037
|
if (!n) return null;
|
|
5017
5038
|
let r = n.accountId;
|
|
5018
5039
|
return typeof r == "string" && r ? r : null;
|
|
5019
5040
|
}
|
|
5020
|
-
function
|
|
5021
|
-
let n =
|
|
5041
|
+
function ls(e, t) {
|
|
5042
|
+
let n = is(e, t);
|
|
5022
5043
|
if (!n) return null;
|
|
5023
5044
|
let r = n.expires;
|
|
5024
5045
|
return typeof r == "number" ? r : null;
|
|
5025
5046
|
}
|
|
5026
|
-
function
|
|
5027
|
-
let n = process.env.CODEMEM_CODEX_ORIGINATOR ?? "opencode", r = process.env.CODEMEM_CODEX_USER_AGENT ?? `codemem/${
|
|
5047
|
+
function us(e, t) {
|
|
5048
|
+
let n = process.env.CODEMEM_CODEX_ORIGINATOR ?? "opencode", r = process.env.CODEMEM_CODEX_USER_AGENT ?? `codemem/${Zo} (${b()} ${x()}; ${_()})`, i = {
|
|
5028
5049
|
authorization: `Bearer ${e}`,
|
|
5029
5050
|
originator: n,
|
|
5030
5051
|
"User-Agent": r,
|
|
@@ -5032,7 +5053,7 @@ function os(e, t) {
|
|
|
5032
5053
|
};
|
|
5033
5054
|
return t && (i["ChatGPT-Account-Id"] = t), i;
|
|
5034
5055
|
}
|
|
5035
|
-
function
|
|
5056
|
+
function ds(e, t) {
|
|
5036
5057
|
let n = e[0];
|
|
5037
5058
|
if (!n) return null;
|
|
5038
5059
|
let r = Math.max(100, t);
|
|
@@ -5050,7 +5071,7 @@ function ss(e, t) {
|
|
|
5050
5071
|
return null;
|
|
5051
5072
|
}
|
|
5052
5073
|
}
|
|
5053
|
-
function
|
|
5074
|
+
function fs(e) {
|
|
5054
5075
|
if (!e) return null;
|
|
5055
5076
|
let t = e.replace(/^~/, v());
|
|
5056
5077
|
t = t.replace(/\$\{([^}]+)\}|\$([A-Za-z_][A-Za-z0-9_]*)/g, (e, t, n) => {
|
|
@@ -5063,7 +5084,7 @@ function cs(e) {
|
|
|
5063
5084
|
return null;
|
|
5064
5085
|
}
|
|
5065
5086
|
}
|
|
5066
|
-
var
|
|
5087
|
+
var ps = new Set([
|
|
5067
5088
|
"",
|
|
5068
5089
|
"auto",
|
|
5069
5090
|
"env",
|
|
@@ -5071,47 +5092,47 @@ var ls = new Set([
|
|
|
5071
5092
|
"command",
|
|
5072
5093
|
"none"
|
|
5073
5094
|
]);
|
|
5074
|
-
function
|
|
5095
|
+
function ms(e) {
|
|
5075
5096
|
let t = (e ?? "").trim().toLowerCase();
|
|
5076
|
-
return
|
|
5097
|
+
return ps.has(t) && t || "auto";
|
|
5077
5098
|
}
|
|
5078
|
-
var
|
|
5099
|
+
var hs = class {
|
|
5079
5100
|
source;
|
|
5080
5101
|
filePath;
|
|
5081
5102
|
command;
|
|
5082
5103
|
timeoutMs;
|
|
5083
5104
|
cacheTtlS;
|
|
5084
|
-
cached =
|
|
5105
|
+
cached = es();
|
|
5085
5106
|
cachedAtMs = 0;
|
|
5086
5107
|
constructor(e) {
|
|
5087
5108
|
this.source = e?.source ?? "auto", this.filePath = e?.filePath ?? null, this.command = e?.command ?? [], this.timeoutMs = e?.timeoutMs ?? 1500, this.cacheTtlS = e?.cacheTtlS ?? 300;
|
|
5088
5109
|
}
|
|
5089
5110
|
resolve(e) {
|
|
5090
|
-
let t =
|
|
5091
|
-
if (t === "none") return
|
|
5111
|
+
let t = ms(this.source), n = e?.explicitToken ?? null, r = e?.envTokens ?? [], i = e?.oauthToken ?? null, a = e?.forceRefresh ?? !1;
|
|
5112
|
+
if (t === "none") return es();
|
|
5092
5113
|
if (!a && (t === "command" || t === "file") && this.cacheTtlS > 0) {
|
|
5093
5114
|
let e = performance.now() - this.cachedAtMs;
|
|
5094
5115
|
if (this.cachedAtMs > 0 && e <= this.cacheTtlS * 1e3) return this.cached;
|
|
5095
5116
|
}
|
|
5096
5117
|
let o = null, s = "none";
|
|
5097
|
-
t === "auto" ? (n && (o = n, s = "explicit"), o || (o = r.find((e) => !!e) ?? null, o && (s = "env")), !o && i && (o = i, s = "oauth")) : t === "env" && (o = r.find((e) => !!e) ?? null, o && (s = "env")), (t === "auto" || t === "file") && !o && (o =
|
|
5118
|
+
t === "auto" ? (n && (o = n, s = "explicit"), o || (o = r.find((e) => !!e) ?? null, o && (s = "env")), !o && i && (o = i, s = "oauth")) : t === "env" && (o = r.find((e) => !!e) ?? null, o && (s = "env")), (t === "auto" || t === "file") && !o && (o = fs(this.filePath), o && (s = "file")), (t === "auto" || t === "command") && !o && (o = ds(this.command, this.timeoutMs), o && (s = "command"));
|
|
5098
5119
|
let c = o ? {
|
|
5099
5120
|
token: o,
|
|
5100
5121
|
authType: "bearer",
|
|
5101
5122
|
source: s
|
|
5102
|
-
} :
|
|
5123
|
+
} : es(), l = t === "command" || t === "file";
|
|
5103
5124
|
return l && c.token ? (this.cached = c, this.cachedAtMs = performance.now()) : l && this.invalidateCache(), c;
|
|
5104
5125
|
}
|
|
5105
5126
|
invalidateCache() {
|
|
5106
|
-
this.cached =
|
|
5127
|
+
this.cached = es(), this.cachedAtMs = 0;
|
|
5107
5128
|
}
|
|
5108
|
-
},
|
|
5109
|
-
function
|
|
5129
|
+
}, gs = /\$\{auth\.token\}/g, _s = /\$\{auth\.type\}/g, vs = /\$\{auth\.source\}/g;
|
|
5130
|
+
function ys(e, t) {
|
|
5110
5131
|
let n = t.token ?? "", r = {};
|
|
5111
5132
|
for (let [i, a] of Object.entries(e)) {
|
|
5112
5133
|
if (typeof i != "string" || typeof a != "string") continue;
|
|
5113
|
-
let e = a.replace(
|
|
5114
|
-
if (e = e.replace(
|
|
5134
|
+
let e = a.replace(gs, n);
|
|
5135
|
+
if (e = e.replace(_s, t.authType), e = e.replace(vs, t.source), a.includes("${auth.token}") && !n) continue;
|
|
5115
5136
|
let o = e.trim();
|
|
5116
5137
|
o && (r[i] = o);
|
|
5117
5138
|
}
|
|
@@ -5119,7 +5140,7 @@ function hs(e, t) {
|
|
|
5119
5140
|
}
|
|
5120
5141
|
//#endregion
|
|
5121
5142
|
//#region src/observer-client.ts
|
|
5122
|
-
var
|
|
5143
|
+
var bs = "claude-sonnet-4-20250514", xs = "gpt-5.1-codex-mini", Ss = "https://api.anthropic.com/v1/messages", Cs = "2023-06-01", ws = "https://chatgpt.com/backend-api/codex/responses", Ts = 6e4, Es = {
|
|
5123
5144
|
"claude-4.5-haiku": "claude-haiku-4-5",
|
|
5124
5145
|
"claude-4.5-sonnet": "claude-sonnet-4-5",
|
|
5125
5146
|
"claude-4.5-opus": "claude-opus-4-5",
|
|
@@ -5129,12 +5150,12 @@ var gs = "claude-sonnet-4-20250514", _s = "gpt-5.1-codex-mini", vs = "https://ap
|
|
|
5129
5150
|
"claude-4.0-sonnet": "claude-sonnet-4-0",
|
|
5130
5151
|
"claude-4.0-opus": "claude-opus-4-0"
|
|
5131
5152
|
};
|
|
5132
|
-
function
|
|
5153
|
+
function Ds(e, t) {
|
|
5133
5154
|
if (e == null) return t;
|
|
5134
5155
|
let n = typeof e == "string" ? Number.parseInt(e, 10) : Number(e);
|
|
5135
5156
|
return Number.isFinite(n) ? n : t;
|
|
5136
5157
|
}
|
|
5137
|
-
function
|
|
5158
|
+
function Os(e) {
|
|
5138
5159
|
if (e == null) return null;
|
|
5139
5160
|
if (typeof e == "string") {
|
|
5140
5161
|
let t = e.trim();
|
|
@@ -5148,7 +5169,7 @@ function ws(e) {
|
|
|
5148
5169
|
}
|
|
5149
5170
|
return typeof e == "object" && !Array.isArray(e) ? e : null;
|
|
5150
5171
|
}
|
|
5151
|
-
function
|
|
5172
|
+
function ks(e) {
|
|
5152
5173
|
if (e == null) return null;
|
|
5153
5174
|
if (Array.isArray(e)) return e.every((e) => typeof e == "string") ? e : null;
|
|
5154
5175
|
if (typeof e == "string") {
|
|
@@ -5162,7 +5183,7 @@ function Ts(e) {
|
|
|
5162
5183
|
}
|
|
5163
5184
|
return null;
|
|
5164
5185
|
}
|
|
5165
|
-
function
|
|
5186
|
+
function As() {
|
|
5166
5187
|
let e = {
|
|
5167
5188
|
observerProvider: null,
|
|
5168
5189
|
observerModel: null,
|
|
@@ -5194,41 +5215,41 @@ function Es() {
|
|
|
5194
5215
|
i = {};
|
|
5195
5216
|
}
|
|
5196
5217
|
let a = { ...e };
|
|
5197
|
-
typeof i.observer_provider == "string" && (a.observerProvider = i.observer_provider), typeof i.observer_model == "string" && (a.observerModel = i.observer_model), typeof i.observer_runtime == "string" && (a.observerRuntime = i.observer_runtime), typeof i.observer_api_key == "string" && (a.observerApiKey = i.observer_api_key), typeof i.observer_base_url == "string" && (a.observerBaseUrl = i.observer_base_url), a.observerMaxChars =
|
|
5198
|
-
let o =
|
|
5218
|
+
typeof i.observer_provider == "string" && (a.observerProvider = i.observer_provider), typeof i.observer_model == "string" && (a.observerModel = i.observer_model), typeof i.observer_runtime == "string" && (a.observerRuntime = i.observer_runtime), typeof i.observer_api_key == "string" && (a.observerApiKey = i.observer_api_key), typeof i.observer_base_url == "string" && (a.observerBaseUrl = i.observer_base_url), a.observerMaxChars = Ds(i.observer_max_chars, a.observerMaxChars), a.observerMaxTokens = Ds(i.observer_max_tokens, a.observerMaxTokens), typeof i.observer_auth_source == "string" && (a.observerAuthSource = i.observer_auth_source), typeof i.observer_auth_file == "string" && (a.observerAuthFile = i.observer_auth_file), a.observerAuthTimeoutMs = Ds(i.observer_auth_timeout_ms, a.observerAuthTimeoutMs), a.observerAuthCacheTtlS = Ds(i.observer_auth_cache_ttl_s, a.observerAuthCacheTtlS);
|
|
5219
|
+
let o = Os(i.observer_headers);
|
|
5199
5220
|
o && (a.observerHeaders = o);
|
|
5200
|
-
let s =
|
|
5201
|
-
s && (a.observerAuthCommand = s), a.observerProvider = process.env.CODEMEM_OBSERVER_PROVIDER ?? a.observerProvider, a.observerModel = process.env.CODEMEM_OBSERVER_MODEL ?? a.observerModel, a.observerRuntime = process.env.CODEMEM_OBSERVER_RUNTIME ?? a.observerRuntime, a.observerApiKey = process.env.CODEMEM_OBSERVER_API_KEY ?? a.observerApiKey, a.observerBaseUrl = process.env.CODEMEM_OBSERVER_BASE_URL ?? a.observerBaseUrl, a.observerAuthSource = process.env.CODEMEM_OBSERVER_AUTH_SOURCE ?? a.observerAuthSource, a.observerAuthFile = process.env.CODEMEM_OBSERVER_AUTH_FILE ?? a.observerAuthFile, a.observerMaxChars =
|
|
5202
|
-
let c =
|
|
5221
|
+
let s = ks(i.observer_auth_command);
|
|
5222
|
+
s && (a.observerAuthCommand = s), a.observerProvider = process.env.CODEMEM_OBSERVER_PROVIDER ?? a.observerProvider, a.observerModel = process.env.CODEMEM_OBSERVER_MODEL ?? a.observerModel, a.observerRuntime = process.env.CODEMEM_OBSERVER_RUNTIME ?? a.observerRuntime, a.observerApiKey = process.env.CODEMEM_OBSERVER_API_KEY ?? a.observerApiKey, a.observerBaseUrl = process.env.CODEMEM_OBSERVER_BASE_URL ?? a.observerBaseUrl, a.observerAuthSource = process.env.CODEMEM_OBSERVER_AUTH_SOURCE ?? a.observerAuthSource, a.observerAuthFile = process.env.CODEMEM_OBSERVER_AUTH_FILE ?? a.observerAuthFile, a.observerMaxChars = Ds(process.env.CODEMEM_OBSERVER_MAX_CHARS, a.observerMaxChars), a.observerMaxTokens = Ds(process.env.CODEMEM_OBSERVER_MAX_TOKENS, a.observerMaxTokens), a.observerAuthTimeoutMs = Ds(process.env.CODEMEM_OBSERVER_AUTH_TIMEOUT_MS, a.observerAuthTimeoutMs), a.observerAuthCacheTtlS = Ds(process.env.CODEMEM_OBSERVER_AUTH_CACHE_TTL_S, a.observerAuthCacheTtlS);
|
|
5223
|
+
let c = Os(process.env.CODEMEM_OBSERVER_HEADERS);
|
|
5203
5224
|
c && (a.observerHeaders = c);
|
|
5204
|
-
let u =
|
|
5225
|
+
let u = ks(process.env.CODEMEM_OBSERVER_AUTH_COMMAND);
|
|
5205
5226
|
return u && (a.observerAuthCommand = u), a;
|
|
5206
5227
|
}
|
|
5207
|
-
var
|
|
5228
|
+
var js = class extends Error {
|
|
5208
5229
|
constructor(e) {
|
|
5209
5230
|
super(e), this.name = "ObserverAuthError";
|
|
5210
5231
|
}
|
|
5211
5232
|
};
|
|
5212
|
-
function
|
|
5233
|
+
function Ms(e) {
|
|
5213
5234
|
return e === 401 || e === 403;
|
|
5214
5235
|
}
|
|
5215
|
-
function
|
|
5236
|
+
function Ns(e) {
|
|
5216
5237
|
let t = e.trim();
|
|
5217
|
-
return t && (
|
|
5238
|
+
return t && (Es[t.toLowerCase()] ?? t);
|
|
5218
5239
|
}
|
|
5219
|
-
function
|
|
5220
|
-
return process.env.CODEMEM_ANTHROPIC_ENDPOINT ??
|
|
5240
|
+
function Ps() {
|
|
5241
|
+
return process.env.CODEMEM_ANTHROPIC_ENDPOINT ?? Ss;
|
|
5221
5242
|
}
|
|
5222
|
-
function
|
|
5243
|
+
function Fs(e, t) {
|
|
5223
5244
|
let n = {
|
|
5224
|
-
"anthropic-version":
|
|
5245
|
+
"anthropic-version": Cs,
|
|
5225
5246
|
"content-type": "application/json"
|
|
5226
5247
|
};
|
|
5227
5248
|
return t ? (n.authorization = `Bearer ${e}`, n["anthropic-beta"] = "oauth-2025-04-20") : n["x-api-key"] = e, n;
|
|
5228
5249
|
}
|
|
5229
|
-
function
|
|
5250
|
+
function Is(e, t, n, r) {
|
|
5230
5251
|
return {
|
|
5231
|
-
model:
|
|
5252
|
+
model: Ns(e),
|
|
5232
5253
|
max_tokens: r,
|
|
5233
5254
|
system: t,
|
|
5234
5255
|
messages: [{
|
|
@@ -5237,7 +5258,7 @@ function Ms(e, t, n, r) {
|
|
|
5237
5258
|
}]
|
|
5238
5259
|
};
|
|
5239
5260
|
}
|
|
5240
|
-
function
|
|
5261
|
+
function Ls(e) {
|
|
5241
5262
|
let t = e.content;
|
|
5242
5263
|
if (!Array.isArray(t)) return console.warn(`[codemem] Anthropic response has no content array (stop_reason=${e.stop_reason ?? "unknown"}, keys=${Object.keys(e).join(",")})`), null;
|
|
5243
5264
|
let n = [];
|
|
@@ -5251,13 +5272,13 @@ function Ns(e) {
|
|
|
5251
5272
|
}
|
|
5252
5273
|
return n.length > 0 ? n.join("") : null;
|
|
5253
5274
|
}
|
|
5254
|
-
function
|
|
5275
|
+
function Rs(e) {
|
|
5255
5276
|
return {
|
|
5256
5277
|
authorization: `Bearer ${e}`,
|
|
5257
5278
|
"content-type": "application/json"
|
|
5258
5279
|
};
|
|
5259
5280
|
}
|
|
5260
|
-
function
|
|
5281
|
+
function zs(e, t, n, r) {
|
|
5261
5282
|
return {
|
|
5262
5283
|
model: e,
|
|
5263
5284
|
max_tokens: r,
|
|
@@ -5271,7 +5292,7 @@ function Fs(e, t, n, r) {
|
|
|
5271
5292
|
}]
|
|
5272
5293
|
};
|
|
5273
5294
|
}
|
|
5274
|
-
function
|
|
5295
|
+
function Bs(e) {
|
|
5275
5296
|
let t = e.choices;
|
|
5276
5297
|
if (!Array.isArray(t) || t.length === 0) return null;
|
|
5277
5298
|
let n = t[0];
|
|
@@ -5281,10 +5302,10 @@ function Is(e) {
|
|
|
5281
5302
|
let i = r.content;
|
|
5282
5303
|
return typeof i == "string" ? i : null;
|
|
5283
5304
|
}
|
|
5284
|
-
function
|
|
5285
|
-
return process.env.CODEMEM_CODEX_ENDPOINT ??
|
|
5305
|
+
function Vs() {
|
|
5306
|
+
return process.env.CODEMEM_CODEX_ENDPOINT ?? ws;
|
|
5286
5307
|
}
|
|
5287
|
-
function
|
|
5308
|
+
function Hs(e, t) {
|
|
5288
5309
|
return {
|
|
5289
5310
|
model: e,
|
|
5290
5311
|
instructions: "You are a memory observer.",
|
|
@@ -5299,7 +5320,7 @@ function Rs(e, t) {
|
|
|
5299
5320
|
stream: !0
|
|
5300
5321
|
};
|
|
5301
5322
|
}
|
|
5302
|
-
function
|
|
5323
|
+
function Us(e, t) {
|
|
5303
5324
|
let n = [];
|
|
5304
5325
|
for (let r of e.split("\n")) {
|
|
5305
5326
|
if (!r.startsWith("data:")) continue;
|
|
@@ -5311,14 +5332,14 @@ function zs(e, t) {
|
|
|
5311
5332
|
}
|
|
5312
5333
|
return n.length > 0 ? n.join("").trim() : null;
|
|
5313
5334
|
}
|
|
5314
|
-
function
|
|
5335
|
+
function Ws(e) {
|
|
5315
5336
|
if (e.type === "response.output_text.delta") {
|
|
5316
5337
|
let t = e.delta;
|
|
5317
5338
|
return typeof t == "string" && t ? t : null;
|
|
5318
5339
|
}
|
|
5319
5340
|
return null;
|
|
5320
5341
|
}
|
|
5321
|
-
function
|
|
5342
|
+
function Gs(e) {
|
|
5322
5343
|
if (e.type === "content_block_delta") {
|
|
5323
5344
|
let t = e.delta;
|
|
5324
5345
|
if (t && t.type === "text_delta") {
|
|
@@ -5328,10 +5349,10 @@ function Vs(e) {
|
|
|
5328
5349
|
}
|
|
5329
5350
|
return null;
|
|
5330
5351
|
}
|
|
5331
|
-
function
|
|
5352
|
+
function Ks() {
|
|
5332
5353
|
return Date.now();
|
|
5333
5354
|
}
|
|
5334
|
-
var
|
|
5355
|
+
var qs = class {
|
|
5335
5356
|
provider;
|
|
5336
5357
|
model;
|
|
5337
5358
|
runtime;
|
|
@@ -5348,7 +5369,7 @@ var Us = class {
|
|
|
5348
5369
|
_lastErrorCode = null;
|
|
5349
5370
|
_lastErrorMessage = null;
|
|
5350
5371
|
constructor(e) {
|
|
5351
|
-
let t = e ??
|
|
5372
|
+
let t = e ?? As(), n = (t.observerProvider ?? "").toLowerCase(), r = (t.observerModel ?? "").trim(), i = ct();
|
|
5352
5373
|
n && n !== "openai" && n !== "anthropic" && i.add(n);
|
|
5353
5374
|
let a = n;
|
|
5354
5375
|
if (!a) {
|
|
@@ -5359,11 +5380,11 @@ var Us = class {
|
|
|
5359
5380
|
let e = ut(r);
|
|
5360
5381
|
e && (a = e);
|
|
5361
5382
|
}
|
|
5362
|
-
a ||=
|
|
5383
|
+
a ||= rs(null, r || xs), a !== "openai" && a !== "anthropic" && a !== "opencode" && !i.has(a) && (a = "openai"), this.provider = a;
|
|
5363
5384
|
let o = t.observerRuntime;
|
|
5364
|
-
this.runtime = (typeof o == "string" && o.trim().toLowerCase(), "api_http"), r ? this.model = r : a === "anthropic" ? this.model =
|
|
5385
|
+
this.runtime = (typeof o == "string" && o.trim().toLowerCase(), "api_http"), r ? this.model = r : a === "anthropic" ? this.model = bs : a === "openai" ? this.model = xs : this.model = dt(a) ?? xt(a) ?? "", this.maxChars = t.observerMaxChars, this.maxTokens = t.observerMaxTokens, this._observerHeaders = { ...t.observerHeaders }, this._apiKey = t.observerApiKey ?? null;
|
|
5365
5386
|
let s = t.observerBaseUrl;
|
|
5366
|
-
this._customBaseUrl = typeof s == "string" && s.trim() ? s.trim() : null, this.authAdapter = new
|
|
5387
|
+
this._customBaseUrl = typeof s == "string" && s.trim() ? s.trim() : null, this.authAdapter = new hs({
|
|
5367
5388
|
source: t.observerAuthSource,
|
|
5368
5389
|
filePath: t.observerAuthFile,
|
|
5369
5390
|
command: t.observerAuthCommand,
|
|
@@ -5402,18 +5423,18 @@ var Us = class {
|
|
|
5402
5423
|
let e = await this._callOnce(a, s);
|
|
5403
5424
|
return e && this._clearLastError(), {
|
|
5404
5425
|
raw: e,
|
|
5405
|
-
parsed: e ?
|
|
5426
|
+
parsed: e ? Ys(e) : null,
|
|
5406
5427
|
provider: this.provider,
|
|
5407
5428
|
model: this.model
|
|
5408
5429
|
};
|
|
5409
5430
|
} catch (e) {
|
|
5410
|
-
if (e instanceof
|
|
5431
|
+
if (e instanceof js) {
|
|
5411
5432
|
if (this.refreshAuth(), !this.auth.token) throw e;
|
|
5412
5433
|
try {
|
|
5413
5434
|
let e = await this._callOnce(a, s);
|
|
5414
5435
|
return e && this._clearLastError(), {
|
|
5415
5436
|
raw: e,
|
|
5416
|
-
parsed: e ?
|
|
5437
|
+
parsed: e ? Ys(e) : null,
|
|
5417
5438
|
provider: this.provider,
|
|
5418
5439
|
model: this.model
|
|
5419
5440
|
};
|
|
@@ -5426,11 +5447,11 @@ var Us = class {
|
|
|
5426
5447
|
}
|
|
5427
5448
|
_initProvider(e) {
|
|
5428
5449
|
this._codexAccess = null, this._codexAccountId = null, this._anthropicOAuthAccess = null;
|
|
5429
|
-
let t =
|
|
5450
|
+
let t = ns(), n = null, r = null;
|
|
5430
5451
|
if (this.provider === "openai" || this.provider === "anthropic") {
|
|
5431
|
-
r =
|
|
5432
|
-
let e =
|
|
5433
|
-
n && e != null && e <=
|
|
5452
|
+
r = rs(this.provider, this.model), n = as(t, r);
|
|
5453
|
+
let e = ls(t, r);
|
|
5454
|
+
n && e != null && e <= Ks() && (n = null);
|
|
5434
5455
|
}
|
|
5435
5456
|
if (this.provider !== "openai" && this.provider !== "anthropic") {
|
|
5436
5457
|
let n = it(this.provider), [r, i, a] = Object.keys(n).length > 0 ? St(this.provider, this.model) : ft(this.provider, this.model);
|
|
@@ -5438,7 +5459,7 @@ var Us = class {
|
|
|
5438
5459
|
...this._observerHeaders,
|
|
5439
5460
|
...a
|
|
5440
5461
|
}), !this._customBaseUrl) return;
|
|
5441
|
-
let o = this.provider === "opencode" ?
|
|
5462
|
+
let o = this.provider === "opencode" ? os(t, this.provider) : null, s = bt(n) || this._apiKey || o;
|
|
5442
5463
|
this.auth = this.authAdapter.resolve({
|
|
5443
5464
|
explicitToken: s,
|
|
5444
5465
|
envTokens: [process.env.CODEMEM_OBSERVER_API_KEY ?? ""],
|
|
@@ -5458,7 +5479,7 @@ var Us = class {
|
|
|
5458
5479
|
],
|
|
5459
5480
|
oauthToken: n,
|
|
5460
5481
|
forceRefresh: e
|
|
5461
|
-
}), this.auth.source === "oauth" && n && (this._codexAccess = n, this._codexAccountId =
|
|
5482
|
+
}), this.auth.source === "oauth" && n && (this._codexAccess = n, this._codexAccountId = cs(t, r ?? "openai")));
|
|
5462
5483
|
}
|
|
5463
5484
|
async _callOnce(e, t) {
|
|
5464
5485
|
if (this._codexAccess) return this._callCodexConsumer(t);
|
|
@@ -5466,17 +5487,17 @@ var Us = class {
|
|
|
5466
5487
|
if (!this.auth.token) {
|
|
5467
5488
|
if (this._initProvider(!0), this._codexAccess) return this._callCodexConsumer(t);
|
|
5468
5489
|
if (this._anthropicOAuthAccess) return this._callAnthropicConsumer(e, t);
|
|
5469
|
-
if (!this.auth.token) return this._setLastError(`${
|
|
5490
|
+
if (!this.auth.token) return this._setLastError(`${Js(this.provider)} credentials are missing.`, "auth_missing"), null;
|
|
5470
5491
|
}
|
|
5471
5492
|
return this.provider === "anthropic" ? this._callAnthropicDirect(e, t) : this._callOpenAIDirect(e, t);
|
|
5472
5493
|
}
|
|
5473
5494
|
async _callAnthropicDirect(e, t) {
|
|
5474
|
-
let n =
|
|
5475
|
-
...
|
|
5476
|
-
...
|
|
5477
|
-
}, i =
|
|
5495
|
+
let n = Ps(), r = {
|
|
5496
|
+
...Fs(this.auth.token ?? "", !1),
|
|
5497
|
+
...ys(this._observerHeaders, this.auth)
|
|
5498
|
+
}, i = Is(this.model, e, t, this.maxTokens);
|
|
5478
5499
|
return this._fetchJSON(n, r, i, {
|
|
5479
|
-
parseResponse:
|
|
5500
|
+
parseResponse: Ls,
|
|
5480
5501
|
providerLabel: "Anthropic"
|
|
5481
5502
|
});
|
|
5482
5503
|
}
|
|
@@ -5484,47 +5505,47 @@ var Us = class {
|
|
|
5484
5505
|
let n;
|
|
5485
5506
|
n = this._customBaseUrl ? `${this._customBaseUrl.replace(/\/+$/, "")}/chat/completions` : "https://api.openai.com/v1/chat/completions";
|
|
5486
5507
|
let r = {
|
|
5487
|
-
...
|
|
5488
|
-
...
|
|
5489
|
-
}, i =
|
|
5508
|
+
...Rs(this.auth.token ?? ""),
|
|
5509
|
+
...ys(this._observerHeaders, this.auth)
|
|
5510
|
+
}, i = zs(this.model, e, t, this.maxTokens);
|
|
5490
5511
|
return this._fetchJSON(n, r, i, {
|
|
5491
|
-
parseResponse:
|
|
5492
|
-
providerLabel:
|
|
5512
|
+
parseResponse: Bs,
|
|
5513
|
+
providerLabel: Js(this.provider)
|
|
5493
5514
|
});
|
|
5494
5515
|
}
|
|
5495
5516
|
async _callCodexConsumer(e) {
|
|
5496
5517
|
if (!this._codexAccess) return null;
|
|
5497
|
-
let t =
|
|
5518
|
+
let t = us(this._codexAccess, this._codexAccountId);
|
|
5498
5519
|
if (Object.keys(this._observerHeaders).length > 0) {
|
|
5499
5520
|
let e = {
|
|
5500
5521
|
token: this._codexAccess,
|
|
5501
5522
|
authType: "bearer",
|
|
5502
5523
|
source: this.auth.source
|
|
5503
5524
|
};
|
|
5504
|
-
Object.assign(t,
|
|
5525
|
+
Object.assign(t, ys(this._observerHeaders, e));
|
|
5505
5526
|
}
|
|
5506
5527
|
t["content-type"] = "application/json";
|
|
5507
|
-
let n =
|
|
5508
|
-
return this._fetchSSE(r, t, n,
|
|
5528
|
+
let n = Hs(this.model, e), r = Vs();
|
|
5529
|
+
return this._fetchSSE(r, t, n, Ws, {
|
|
5509
5530
|
providerLabel: "OpenAI",
|
|
5510
5531
|
authErrorMessage: "OpenAI authentication failed. Refresh credentials and retry."
|
|
5511
5532
|
});
|
|
5512
5533
|
}
|
|
5513
5534
|
async _callAnthropicConsumer(e, t) {
|
|
5514
5535
|
if (!this._anthropicOAuthAccess) return null;
|
|
5515
|
-
let n =
|
|
5536
|
+
let n = Fs(this._anthropicOAuthAccess, !0);
|
|
5516
5537
|
if (Object.keys(this._observerHeaders).length > 0) {
|
|
5517
5538
|
let e = {
|
|
5518
5539
|
token: this._anthropicOAuthAccess,
|
|
5519
5540
|
authType: "bearer",
|
|
5520
5541
|
source: this.auth.source
|
|
5521
5542
|
};
|
|
5522
|
-
Object.assign(n,
|
|
5543
|
+
Object.assign(n, ys(this._observerHeaders, e));
|
|
5523
5544
|
}
|
|
5524
|
-
let r =
|
|
5545
|
+
let r = Ps(), i = new URL(r);
|
|
5525
5546
|
i.searchParams.set("beta", "true");
|
|
5526
5547
|
let a = i.toString(), o = {
|
|
5527
|
-
model:
|
|
5548
|
+
model: Ns(this.model),
|
|
5528
5549
|
max_tokens: this.maxTokens,
|
|
5529
5550
|
stream: !0,
|
|
5530
5551
|
messages: [{
|
|
@@ -5533,7 +5554,7 @@ var Us = class {
|
|
|
5533
5554
|
}],
|
|
5534
5555
|
system: e
|
|
5535
5556
|
};
|
|
5536
|
-
return this._fetchSSE(a, n, o,
|
|
5557
|
+
return this._fetchSSE(a, n, o, Gs, {
|
|
5537
5558
|
providerLabel: "Anthropic",
|
|
5538
5559
|
authErrorMessage: "Anthropic authentication failed. Refresh credentials and retry."
|
|
5539
5560
|
});
|
|
@@ -5544,7 +5565,7 @@ var Us = class {
|
|
|
5544
5565
|
method: "POST",
|
|
5545
5566
|
headers: t,
|
|
5546
5567
|
body: JSON.stringify(n),
|
|
5547
|
-
signal: AbortSignal.timeout(
|
|
5568
|
+
signal: AbortSignal.timeout(Ts)
|
|
5548
5569
|
});
|
|
5549
5570
|
if (!i.ok) {
|
|
5550
5571
|
let e = await i.text().catch(() => "");
|
|
@@ -5553,7 +5574,7 @@ var Us = class {
|
|
|
5553
5574
|
let a = await i.json(), o = r.parseResponse(a);
|
|
5554
5575
|
return o === null && this._setLastError(`${r.providerLabel} returned 200 but response contained no extractable text.`, "empty_response"), o;
|
|
5555
5576
|
} catch (e) {
|
|
5556
|
-
if (e instanceof
|
|
5577
|
+
if (e instanceof js) throw e;
|
|
5557
5578
|
return this._setLastError(`${r.providerLabel} processing failed during observer inference.`, "observer_call_failed"), null;
|
|
5558
5579
|
}
|
|
5559
5580
|
}
|
|
@@ -5563,21 +5584,21 @@ var Us = class {
|
|
|
5563
5584
|
method: "POST",
|
|
5564
5585
|
headers: t,
|
|
5565
5586
|
body: JSON.stringify(n),
|
|
5566
|
-
signal: AbortSignal.timeout(
|
|
5587
|
+
signal: AbortSignal.timeout(Ts)
|
|
5567
5588
|
});
|
|
5568
5589
|
if (!a.ok) {
|
|
5569
|
-
if (await a.text().catch(() => ""),
|
|
5590
|
+
if (await a.text().catch(() => ""), Ms(a.status)) throw this._setLastError(i.authErrorMessage, "auth_failed"), new js(`${i.providerLabel} auth error: ${a.status}`);
|
|
5570
5591
|
return this._setLastError(`${i.providerLabel} request failed during observer processing.`, "provider_request_failed"), null;
|
|
5571
5592
|
}
|
|
5572
|
-
return
|
|
5593
|
+
return Us(await a.text(), r);
|
|
5573
5594
|
} catch (e) {
|
|
5574
|
-
if (e instanceof
|
|
5595
|
+
if (e instanceof js) throw e;
|
|
5575
5596
|
return this._setLastError(`${i.providerLabel} processing failed during observer inference.`, "observer_call_failed"), null;
|
|
5576
5597
|
}
|
|
5577
5598
|
}
|
|
5578
5599
|
_handleHttpError(e, t, n) {
|
|
5579
|
-
let r =
|
|
5580
|
-
if (
|
|
5600
|
+
let r = $o(t);
|
|
5601
|
+
if (Ms(e)) throw this._setLastError(`${n} authentication failed. Refresh credentials and retry.`, "auth_failed"), new js(`${n} auth error: ${e}: ${r}`);
|
|
5581
5602
|
if (e === 429) {
|
|
5582
5603
|
this._setLastError(`${n} rate limited. Retry later.`, "rate_limited");
|
|
5583
5604
|
return;
|
|
@@ -5602,10 +5623,10 @@ var Us = class {
|
|
|
5602
5623
|
this._lastErrorCode = null, this._lastErrorMessage = null;
|
|
5603
5624
|
}
|
|
5604
5625
|
};
|
|
5605
|
-
function
|
|
5626
|
+
function Js(e) {
|
|
5606
5627
|
return e.charAt(0).toUpperCase() + e.slice(1);
|
|
5607
5628
|
}
|
|
5608
|
-
function
|
|
5629
|
+
function Ys(e) {
|
|
5609
5630
|
try {
|
|
5610
5631
|
let t = JSON.parse(e);
|
|
5611
5632
|
return typeof t == "object" && t && !Array.isArray(t) ? t : null;
|
|
@@ -5615,10 +5636,10 @@ function Gs(e) {
|
|
|
5615
5636
|
}
|
|
5616
5637
|
//#endregion
|
|
5617
5638
|
//#region src/search.ts
|
|
5618
|
-
function
|
|
5639
|
+
function Xs(e) {
|
|
5619
5640
|
return N(e, { schema: U });
|
|
5620
5641
|
}
|
|
5621
|
-
var
|
|
5642
|
+
var Zs = {
|
|
5622
5643
|
session_summary: .25,
|
|
5623
5644
|
decision: .2,
|
|
5624
5645
|
feature: .18,
|
|
@@ -5630,32 +5651,32 @@ var qs = {
|
|
|
5630
5651
|
observation: .1,
|
|
5631
5652
|
exploration: .1,
|
|
5632
5653
|
entities: .05
|
|
5633
|
-
},
|
|
5654
|
+
}, Qs = .45, $s = .18, ec = .12, tc = 3, nc = 0, rc = 2, ic = [
|
|
5634
5655
|
/\bwhat did i\b/i,
|
|
5635
5656
|
/\bmy notes\b/i,
|
|
5636
5657
|
/\bmy last session\b/i,
|
|
5637
5658
|
/\bmy machine\b/i
|
|
5638
|
-
],
|
|
5659
|
+
], ac = new Set([
|
|
5639
5660
|
"or",
|
|
5640
5661
|
"and",
|
|
5641
5662
|
"not",
|
|
5642
5663
|
"near",
|
|
5643
5664
|
"phrase"
|
|
5644
5665
|
]);
|
|
5645
|
-
function
|
|
5666
|
+
function oc(e) {
|
|
5646
5667
|
let t = e.match(/[A-Za-z0-9_]+/g);
|
|
5647
5668
|
if (!t) return "";
|
|
5648
|
-
let n = t.filter((e) => !
|
|
5669
|
+
let n = t.filter((e) => !ac.has(e.toLowerCase()));
|
|
5649
5670
|
return n.length === 0 ? "" : n.length === 1 ? n[0] : n.join(" OR ");
|
|
5650
5671
|
}
|
|
5651
|
-
function
|
|
5672
|
+
function sc(e, t) {
|
|
5652
5673
|
let n = Date.parse(e);
|
|
5653
5674
|
return Number.isNaN(n) ? 0 : 1 / (1 + Math.max(0, Math.floor(((t ?? /* @__PURE__ */ new Date()).getTime() - n) / 864e5)) / 7);
|
|
5654
5675
|
}
|
|
5655
|
-
function
|
|
5656
|
-
return e ?
|
|
5676
|
+
function cc(e) {
|
|
5677
|
+
return e ? Zs[e.trim().toLowerCase()] ?? 0 : 0;
|
|
5657
5678
|
}
|
|
5658
|
-
function
|
|
5679
|
+
function lc(e) {
|
|
5659
5680
|
if (!e || e.personal_first === void 0) return !0;
|
|
5660
5681
|
let t = e.personal_first;
|
|
5661
5682
|
if (typeof t == "string") {
|
|
@@ -5675,10 +5696,10 @@ function ac(e) {
|
|
|
5675
5696
|
}
|
|
5676
5697
|
return !!t;
|
|
5677
5698
|
}
|
|
5678
|
-
function
|
|
5699
|
+
function uc(e) {
|
|
5679
5700
|
return String(e?.trust_bias ?? "off").trim().toLowerCase() === "soft" ? "soft" : "off";
|
|
5680
5701
|
}
|
|
5681
|
-
function
|
|
5702
|
+
function dc(e) {
|
|
5682
5703
|
if (!e || e.widen_shared_when_weak === void 0) return !1;
|
|
5683
5704
|
let t = e.widen_shared_when_weak;
|
|
5684
5705
|
if (typeof t == "string") {
|
|
@@ -5698,25 +5719,25 @@ function sc(e) {
|
|
|
5698
5719
|
}
|
|
5699
5720
|
return !!t;
|
|
5700
5721
|
}
|
|
5701
|
-
function
|
|
5722
|
+
function fc(e) {
|
|
5702
5723
|
let t = e?.widen_shared_min_personal_results;
|
|
5703
|
-
return typeof t != "number" || !Number.isFinite(t) ?
|
|
5724
|
+
return typeof t != "number" || !Number.isFinite(t) ? tc : Math.max(1, Math.trunc(t));
|
|
5704
5725
|
}
|
|
5705
|
-
function
|
|
5726
|
+
function pc(e) {
|
|
5706
5727
|
let t = e?.widen_shared_min_personal_score;
|
|
5707
|
-
return typeof t != "number" || !Number.isFinite(t) ?
|
|
5728
|
+
return typeof t != "number" || !Number.isFinite(t) ? nc : Math.max(0, t);
|
|
5708
5729
|
}
|
|
5709
|
-
function
|
|
5710
|
-
return
|
|
5730
|
+
function mc(e) {
|
|
5731
|
+
return ic.some((t) => t.test(e));
|
|
5711
5732
|
}
|
|
5712
|
-
function
|
|
5733
|
+
function hc(e) {
|
|
5713
5734
|
if (!e) return !1;
|
|
5714
5735
|
let t = String(e.ownership_scope ?? "").trim().toLowerCase();
|
|
5715
5736
|
if (t === "mine" || t === "theirs") return !0;
|
|
5716
|
-
let n =
|
|
5737
|
+
let n = wa(e.include_visibility ?? e.visibility), r = wa(e.exclude_visibility), i = Sa(e.include_workspace_ids), a = Sa(e.exclude_workspace_ids), o = Ca(e.include_workspace_kinds), s = Ca(e.exclude_workspace_kinds);
|
|
5717
5738
|
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:"));
|
|
5718
5739
|
}
|
|
5719
|
-
function
|
|
5740
|
+
function gc(e) {
|
|
5720
5741
|
return {
|
|
5721
5742
|
...e ?? {},
|
|
5722
5743
|
visibility: void 0,
|
|
@@ -5727,7 +5748,7 @@ function fc(e) {
|
|
|
5727
5748
|
widen_shared_when_weak: !1
|
|
5728
5749
|
};
|
|
5729
5750
|
}
|
|
5730
|
-
function
|
|
5751
|
+
function _c(e) {
|
|
5731
5752
|
return e.map((e) => ({
|
|
5732
5753
|
...e,
|
|
5733
5754
|
metadata: {
|
|
@@ -5736,85 +5757,85 @@ function pc(e) {
|
|
|
5736
5757
|
}
|
|
5737
5758
|
}));
|
|
5738
5759
|
}
|
|
5739
|
-
function
|
|
5740
|
-
return
|
|
5760
|
+
function vc(e, t, n) {
|
|
5761
|
+
return lc(n) && e.memoryOwnedBySelf(t) ? Qs : 0;
|
|
5741
5762
|
}
|
|
5742
|
-
function
|
|
5743
|
-
if (
|
|
5763
|
+
function yc(e, t, n) {
|
|
5764
|
+
if (uc(n) !== "soft" || e.memoryOwnedBySelf(t)) return 0;
|
|
5744
5765
|
let r = t.metadata ?? {}, i = String(r.visibility ?? "").trim().toLowerCase(), a = String(r.workspace_kind ?? "").trim().toLowerCase();
|
|
5745
5766
|
if (i !== "shared" && a !== "shared") return 0;
|
|
5746
5767
|
let o = String(r.trust_state ?? "trusted").trim().toLowerCase();
|
|
5747
|
-
return o === "legacy_unknown" ?
|
|
5768
|
+
return o === "legacy_unknown" ? $s : o === "unreviewed" ? ec : 0;
|
|
5748
5769
|
}
|
|
5749
|
-
function
|
|
5770
|
+
function bc(e) {
|
|
5750
5771
|
let t = e.trim().replaceAll("\\", "/");
|
|
5751
5772
|
t.startsWith("./") && (t = t.slice(2));
|
|
5752
5773
|
let n = t.split("/").filter((e) => e && e !== ".");
|
|
5753
5774
|
return n.length === 0 ? "" : n.join("/").toLowerCase();
|
|
5754
5775
|
}
|
|
5755
|
-
function
|
|
5756
|
-
let t =
|
|
5776
|
+
function xc(e) {
|
|
5777
|
+
let t = bc(e);
|
|
5757
5778
|
return t ? t.split("/") : [];
|
|
5758
5779
|
}
|
|
5759
|
-
function
|
|
5760
|
-
let t =
|
|
5780
|
+
function Sc(e) {
|
|
5781
|
+
let t = xc(e);
|
|
5761
5782
|
return t.length === 0 ? "" : t[t.length - 1] ?? "";
|
|
5762
5783
|
}
|
|
5763
|
-
function
|
|
5784
|
+
function Cc(e, t) {
|
|
5764
5785
|
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("/");
|
|
5765
5786
|
}
|
|
5766
|
-
function
|
|
5787
|
+
function wc(e) {
|
|
5767
5788
|
if (!Array.isArray(e)) return [];
|
|
5768
5789
|
let t = [], n = /* @__PURE__ */ new Set();
|
|
5769
5790
|
for (let r of e) {
|
|
5770
5791
|
if (typeof r != "string") continue;
|
|
5771
|
-
let e =
|
|
5792
|
+
let e = bc(r);
|
|
5772
5793
|
!e || n.has(e) || (n.add(e), t.push(e));
|
|
5773
5794
|
}
|
|
5774
5795
|
return t;
|
|
5775
5796
|
}
|
|
5776
|
-
function
|
|
5797
|
+
function Tc(e) {
|
|
5777
5798
|
let t = (e.metadata ?? {}).files_modified;
|
|
5778
5799
|
if (!Array.isArray(t)) return [];
|
|
5779
5800
|
let n = [];
|
|
5780
5801
|
for (let e of t) {
|
|
5781
5802
|
if (typeof e != "string") continue;
|
|
5782
|
-
let t =
|
|
5803
|
+
let t = bc(e);
|
|
5783
5804
|
t && n.push(t);
|
|
5784
5805
|
}
|
|
5785
5806
|
return n;
|
|
5786
5807
|
}
|
|
5787
|
-
function
|
|
5808
|
+
function Ec(e, t) {
|
|
5788
5809
|
if (t.length === 0) return 0;
|
|
5789
|
-
let n =
|
|
5810
|
+
let n = Tc(e);
|
|
5790
5811
|
if (n.length === 0) return 0;
|
|
5791
|
-
let r = [...new Set(n)].map((e) =>
|
|
5792
|
-
for (let e of r) i.some((t) =>
|
|
5812
|
+
let r = [...new Set(n)].map((e) => xc(e)), i = [...new Set(t)].map((e) => xc(e)), a = new Set(n.map((e) => Sc(e)).filter(Boolean)), o = new Set(t.map((e) => Sc(e)).filter(Boolean)), s = 0;
|
|
5813
|
+
for (let e of r) i.some((t) => Cc(e, t)) && (s += 1);
|
|
5793
5814
|
let c = 0;
|
|
5794
5815
|
for (let e of a) o.has(e) && (c += 1);
|
|
5795
5816
|
let l = s * .16 + c * .06;
|
|
5796
5817
|
return Math.min(.32, l);
|
|
5797
5818
|
}
|
|
5798
|
-
function
|
|
5799
|
-
let i = /* @__PURE__ */ new Date(), a =
|
|
5819
|
+
function Dc(e, t, n, r) {
|
|
5820
|
+
let i = /* @__PURE__ */ new Date(), a = wc(r?.working_set_paths), o = t.map((t) => ({
|
|
5800
5821
|
item: t,
|
|
5801
|
-
combinedScore: t.score * 1.5 +
|
|
5822
|
+
combinedScore: t.score * 1.5 + sc(t.created_at, i) + cc(t.kind) + Ec(t, a) + vc(e, t, r) - yc(e, t, r)
|
|
5802
5823
|
}));
|
|
5803
5824
|
return o.sort((e, t) => t.combinedScore - e.combinedScore), o.slice(0, n).map((e) => e.item);
|
|
5804
5825
|
}
|
|
5805
|
-
function
|
|
5806
|
-
let i =
|
|
5807
|
-
if (!
|
|
5826
|
+
function Oc(e, t, n = 10, r) {
|
|
5827
|
+
let i = kc(e, t, n, r);
|
|
5828
|
+
if (!dc(r) || !t || mc(t) || hc(r)) return i;
|
|
5808
5829
|
let a = i.filter((t) => e.memoryOwnedBySelf(t)), o = a[0]?.score ?? -Infinity;
|
|
5809
|
-
if (a.length >=
|
|
5810
|
-
let s =
|
|
5811
|
-
for (let e of s) if (!c.has(e.id) && (c.add(e.id), l.push(e), u += 1, u >=
|
|
5830
|
+
if (a.length >= fc(r) && o >= pc(r)) return i;
|
|
5831
|
+
let s = _c(kc(e, t, rc, gc(r)).filter((t) => !e.memoryOwnedBySelf(t))), c = new Set(i.map((e) => e.id)), l = [...i], u = 0;
|
|
5832
|
+
for (let e of s) if (!c.has(e.id) && (c.add(e.id), l.push(e), u += 1, u >= rc)) break;
|
|
5812
5833
|
return l;
|
|
5813
5834
|
}
|
|
5814
|
-
function
|
|
5815
|
-
let i = Math.max(1, Math.trunc(n)), a =
|
|
5835
|
+
function kc(e, t, n = 10, r) {
|
|
5836
|
+
let i = Math.max(1, Math.trunc(n)), a = oc(t);
|
|
5816
5837
|
if (!a) return [];
|
|
5817
|
-
let o = Math.min(Math.max(i * 4, i + 8), 200), s = [a], c = ["memory_items.active = 1", "memory_fts MATCH ?"], l =
|
|
5838
|
+
let o = Math.min(Math.max(i * 4, i + 8), 200), s = [a], c = ["memory_items.active = 1", "memory_fts MATCH ?"], l = Oa(r, {
|
|
5818
5839
|
actorId: e.actorId,
|
|
5819
5840
|
deviceId: e.deviceId
|
|
5820
5841
|
});
|
|
@@ -5830,7 +5851,7 @@ function Tc(e, t, n = 10, r) {
|
|
|
5830
5851
|
ORDER BY (score * 1.5 + recency) DESC, memory_items.created_at DESC, memory_items.id DESC
|
|
5831
5852
|
LIMIT ?
|
|
5832
5853
|
`;
|
|
5833
|
-
return s.push(o),
|
|
5854
|
+
return s.push(o), Dc(e, e.db.prepare(d).all(...s).map((e) => {
|
|
5834
5855
|
let t = { ...B(e.metadata_json) };
|
|
5835
5856
|
for (let n of [
|
|
5836
5857
|
"actor_id",
|
|
@@ -5864,7 +5885,7 @@ function Tc(e, t, n = 10, r) {
|
|
|
5864
5885
|
};
|
|
5865
5886
|
}), i, r);
|
|
5866
5887
|
}
|
|
5867
|
-
function
|
|
5888
|
+
function Ac(e, t, n, r = 3, i = 3, a) {
|
|
5868
5889
|
let o = null;
|
|
5869
5890
|
if (n != null) {
|
|
5870
5891
|
let t = e.get(n);
|
|
@@ -5875,7 +5896,7 @@ function Ec(e, t, n, r = 3, i = 3, a) {
|
|
|
5875
5896
|
});
|
|
5876
5897
|
}
|
|
5877
5898
|
if (o == null && t) {
|
|
5878
|
-
let n =
|
|
5899
|
+
let n = Oc(e, t, 1, a ?? void 0);
|
|
5879
5900
|
if (n.length > 0) {
|
|
5880
5901
|
let e = n[0];
|
|
5881
5902
|
o = {
|
|
@@ -5885,12 +5906,12 @@ function Ec(e, t, n, r = 3, i = 3, a) {
|
|
|
5885
5906
|
};
|
|
5886
5907
|
}
|
|
5887
5908
|
}
|
|
5888
|
-
return o == null ? [] :
|
|
5909
|
+
return o == null ? [] : jc(e, o, r, i, a);
|
|
5889
5910
|
}
|
|
5890
|
-
function
|
|
5911
|
+
function jc(e, t, n, r, i) {
|
|
5891
5912
|
let a = t.id, o = t.created_at, s = t.session_id;
|
|
5892
5913
|
if (!a || !o) return [];
|
|
5893
|
-
let c =
|
|
5914
|
+
let c = Oa(i, {
|
|
5894
5915
|
actorId: e.actorId,
|
|
5895
5916
|
deviceId: e.deviceId
|
|
5896
5917
|
}), l = ["memory_items.active = 1", ...c.clauses], u = [...c.params];
|
|
@@ -5905,7 +5926,7 @@ function Dc(e, t, n, r, i) {
|
|
|
5905
5926
|
${f}
|
|
5906
5927
|
WHERE ${d} AND memory_items.created_at > ?
|
|
5907
5928
|
ORDER BY memory_items.created_at ASC
|
|
5908
|
-
LIMIT ?`).all(...u, o, r), h =
|
|
5929
|
+
LIMIT ?`).all(...u, o, r), h = Xs(e.db).select().from(G).where(D(k(G.id, a), k(G.active, 1))).get(), g = [...p.reverse()];
|
|
5909
5930
|
return h && g.push(h), g.push(...m), g.map((e) => {
|
|
5910
5931
|
let { metadata_json: t, ...n } = e;
|
|
5911
5932
|
return {
|
|
@@ -5915,10 +5936,10 @@ function Dc(e, t, n, r, i) {
|
|
|
5915
5936
|
};
|
|
5916
5937
|
});
|
|
5917
5938
|
}
|
|
5918
|
-
function
|
|
5939
|
+
function Mc(e) {
|
|
5919
5940
|
let t = /* @__PURE__ */ new Set(), n = [], r = [];
|
|
5920
5941
|
for (let i of e) {
|
|
5921
|
-
let e =
|
|
5942
|
+
let e = Xo(i);
|
|
5922
5943
|
if (e == null) {
|
|
5923
5944
|
r.push(String(i));
|
|
5924
5945
|
continue;
|
|
@@ -5930,8 +5951,8 @@ function Oc(e) {
|
|
|
5930
5951
|
invalid: r
|
|
5931
5952
|
};
|
|
5932
5953
|
}
|
|
5933
|
-
function
|
|
5934
|
-
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 =
|
|
5954
|
+
function Nc(e, t, n, r, i, a, o, s) {
|
|
5955
|
+
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 = sc(e.created_at, s), f = cc(e.kind), p = null;
|
|
5935
5956
|
return u != null && (p = u * 1.5 + d + f), {
|
|
5936
5957
|
id: e.id,
|
|
5937
5958
|
kind: e.kind,
|
|
@@ -5962,16 +5983,16 @@ function kc(e, t, n, r, i, a, o, s) {
|
|
|
5962
5983
|
} : null
|
|
5963
5984
|
};
|
|
5964
5985
|
}
|
|
5965
|
-
function
|
|
5986
|
+
function Pc(e, t, n) {
|
|
5966
5987
|
if (t.length === 0) return {
|
|
5967
5988
|
items: [],
|
|
5968
5989
|
missingNotFound: [],
|
|
5969
5990
|
missingProjectMismatch: [],
|
|
5970
5991
|
missingFilterMismatch: []
|
|
5971
5992
|
};
|
|
5972
|
-
let r =
|
|
5993
|
+
let r = Xs(e.db).select().from(G).where(D(k(G.active, 1), j(G.id, t))).all(), i = new Set(r.map((e) => e.id)), a = t.map(() => "?").join(", "), o = r, s = new Set(i);
|
|
5973
5994
|
if (n.project) {
|
|
5974
|
-
let r =
|
|
5995
|
+
let r = Oa({ project: n.project }, {
|
|
5975
5996
|
actorId: e.actorId,
|
|
5976
5997
|
deviceId: e.deviceId
|
|
5977
5998
|
});
|
|
@@ -5985,7 +6006,7 @@ function Ac(e, t, n) {
|
|
|
5985
6006
|
AND ${r.clauses.join(" AND ")}`).all(...t, ...r.params), s = new Set(o.map((e) => e.id));
|
|
5986
6007
|
}
|
|
5987
6008
|
}
|
|
5988
|
-
let c =
|
|
6009
|
+
let c = Oa(n, {
|
|
5989
6010
|
actorId: e.actorId,
|
|
5990
6011
|
deviceId: e.deviceId
|
|
5991
6012
|
}), l = c.joinSessions ? "JOIN sessions ON sessions.id = memory_items.session_id" : "", u = e.db.prepare(`SELECT memory_items.*
|
|
@@ -6015,16 +6036,16 @@ function Ac(e, t, n) {
|
|
|
6015
6036
|
missingFilterMismatch: m
|
|
6016
6037
|
};
|
|
6017
6038
|
}
|
|
6018
|
-
function
|
|
6039
|
+
function Fc(e, t) {
|
|
6019
6040
|
if (t.size === 0) return /* @__PURE__ */ new Map();
|
|
6020
|
-
let n = [...t].sort((e, t) => e - t), r =
|
|
6041
|
+
let n = [...t].sort((e, t) => e - t), r = Xs(e.db).select({
|
|
6021
6042
|
id: W.id,
|
|
6022
6043
|
project: W.project
|
|
6023
6044
|
}).from(W).where(j(W.id, n)).all();
|
|
6024
6045
|
return new Map(r.map((e) => [e.id, e.project]));
|
|
6025
6046
|
}
|
|
6026
|
-
function
|
|
6027
|
-
let o = a?.includePackContext ?? !1, s = (t ?? "").trim(), { ordered: c, invalid: l } =
|
|
6047
|
+
function Ic(e, t, n, r = 10, i, a) {
|
|
6048
|
+
let o = a?.includePackContext ?? !1, s = (t ?? "").trim(), { ordered: c, invalid: l } = Mc(n ?? []), u = [];
|
|
6028
6049
|
if (l.length > 0 && u.push({
|
|
6029
6050
|
code: "INVALID_ARGUMENT",
|
|
6030
6051
|
field: "ids",
|
|
@@ -6047,10 +6068,10 @@ function Mc(e, t, n, r = 10, i, a) {
|
|
|
6047
6068
|
}
|
|
6048
6069
|
};
|
|
6049
6070
|
let d = [];
|
|
6050
|
-
s && (d =
|
|
6071
|
+
s && (d = Oc(e, s, Math.max(1, Math.trunc(r)), i ?? void 0));
|
|
6051
6072
|
let f = /* @__PURE__ */ new Map();
|
|
6052
6073
|
for (let e = 0; e < d.length; e++) f.set(d[e].id, e + 1);
|
|
6053
|
-
let { items: p, missingNotFound: m, missingProjectMismatch: h, missingFilterMismatch: g } =
|
|
6074
|
+
let { items: p, missingNotFound: m, missingProjectMismatch: h, missingFilterMismatch: g } = Pc(e, c, i ?? {}), _ = new Map(p.map((e) => [e.id, e])), v = new Set(c), y = /* @__PURE__ */ new Set(), b = [];
|
|
6054
6075
|
for (let e of d) {
|
|
6055
6076
|
y.add(e.id);
|
|
6056
6077
|
let t = v.has(e.id) ? "query+id_lookup" : "query";
|
|
@@ -6069,7 +6090,7 @@ function Mc(e, t, n, r = 10, i, a) {
|
|
|
6069
6090
|
rank: null
|
|
6070
6091
|
}), y.add(e));
|
|
6071
6092
|
}
|
|
6072
|
-
let x = s ? (s.match(/[A-Za-z0-9_]+/g) ?? []).map((e) => e.toLowerCase()) : [], S =
|
|
6093
|
+
let x = s ? (s.match(/[A-Za-z0-9_]+/g) ?? []).map((e) => e.toLowerCase()) : [], S = Fc(e, new Set(b.map(({ item: e }) => e.session_id).filter((e) => e > 0))), C = /* @__PURE__ */ new Date(), w = b.map(({ item: e, source: t, rank: n }) => Nc(e, t, n, x, i?.project ?? null, S.get(e.session_id) ?? null, o, C)), T = c.filter((e) => !y.has(e));
|
|
6073
6094
|
return m.length > 0 && u.push({
|
|
6074
6095
|
code: "NOT_FOUND",
|
|
6075
6096
|
field: "ids",
|
|
@@ -6100,7 +6121,7 @@ function Mc(e, t, n, r = 10, i, a) {
|
|
|
6100
6121
|
}
|
|
6101
6122
|
//#endregion
|
|
6102
6123
|
//#region src/pack.ts
|
|
6103
|
-
var
|
|
6124
|
+
var Lc = {
|
|
6104
6125
|
decision: 0,
|
|
6105
6126
|
feature: 1,
|
|
6106
6127
|
bugfix: 2,
|
|
@@ -6109,11 +6130,11 @@ var Nc = {
|
|
|
6109
6130
|
discovery: 5,
|
|
6110
6131
|
exploration: 6,
|
|
6111
6132
|
note: 7
|
|
6112
|
-
},
|
|
6113
|
-
function
|
|
6133
|
+
}, Rc = 365, zc = "todo todos task tasks pending follow up follow-up next resume continue backlog pick up pick-up", Bc = "session summary recap remember last time previous work";
|
|
6134
|
+
function Vc(e) {
|
|
6114
6135
|
return Math.ceil(e.length / 4);
|
|
6115
6136
|
}
|
|
6116
|
-
function
|
|
6137
|
+
function Hc(e) {
|
|
6117
6138
|
let t = [
|
|
6118
6139
|
`[${e.id}]`,
|
|
6119
6140
|
`(${e.kind})`,
|
|
@@ -6121,11 +6142,11 @@ function Rc(e) {
|
|
|
6121
6142
|
];
|
|
6122
6143
|
return e.body_text && t.push("-", e.body_text), t.join(" ");
|
|
6123
6144
|
}
|
|
6124
|
-
function
|
|
6145
|
+
function Uc(e, t) {
|
|
6125
6146
|
let n = `## ${e}`;
|
|
6126
|
-
return t.length === 0 ? `${n}\n` : [n, ...t.map(
|
|
6147
|
+
return t.length === 0 ? `${n}\n` : [n, ...t.map(Hc)].join("\n");
|
|
6127
6148
|
}
|
|
6128
|
-
function
|
|
6149
|
+
function Wc(e, t) {
|
|
6129
6150
|
let n = t?.duplicateIds.get(e.id), r = {
|
|
6130
6151
|
id: e.id,
|
|
6131
6152
|
kind: e.kind,
|
|
@@ -6137,18 +6158,18 @@ function Bc(e, t) {
|
|
|
6137
6158
|
};
|
|
6138
6159
|
return n && n.size > 0 && (r.support_count = 1 + n.size, r.duplicate_ids = [...n].sort((e, t) => e - t)), r;
|
|
6139
6160
|
}
|
|
6140
|
-
function
|
|
6161
|
+
function Gc(e) {
|
|
6141
6162
|
return e.trim().toLowerCase().split(/\s+/).join(" ");
|
|
6142
6163
|
}
|
|
6143
|
-
function
|
|
6164
|
+
function Kc(e) {
|
|
6144
6165
|
if (e.kind === "session_summary") return null;
|
|
6145
|
-
let t =
|
|
6166
|
+
let t = Gc(e.title), n = Gc(e.body_text);
|
|
6146
6167
|
return !t && !n ? null : `${e.kind.length}:${e.kind}|${t.length}:${t}|${n.length}:${n}`;
|
|
6147
6168
|
}
|
|
6148
|
-
function
|
|
6169
|
+
function qc(e, t) {
|
|
6149
6170
|
let n = [];
|
|
6150
6171
|
for (let r of e) {
|
|
6151
|
-
let e =
|
|
6172
|
+
let e = Kc(r);
|
|
6152
6173
|
if (e === null) {
|
|
6153
6174
|
n.push(r);
|
|
6154
6175
|
continue;
|
|
@@ -6167,19 +6188,19 @@ function Uc(e, t) {
|
|
|
6167
6188
|
}
|
|
6168
6189
|
return n;
|
|
6169
6190
|
}
|
|
6170
|
-
function
|
|
6191
|
+
function Jc(e, t) {
|
|
6171
6192
|
let n = new Set((t.toLowerCase().match(/[a-z0-9_]+/g) ?? []).filter(Boolean));
|
|
6172
6193
|
return n.size === 0 ? e : [...e].sort((e, t) => {
|
|
6173
|
-
let r =
|
|
6194
|
+
let r = Yc(e.tags_text, n), i = Yc(t.tags_text, n);
|
|
6174
6195
|
return i === r ? (t.created_at ?? "").localeCompare(e.created_at ?? "") : i - r;
|
|
6175
6196
|
});
|
|
6176
6197
|
}
|
|
6177
|
-
function
|
|
6198
|
+
function Yc(e, t) {
|
|
6178
6199
|
let n = new Set(e.split(/\s+/).filter(Boolean)), r = 0;
|
|
6179
6200
|
for (let e of t) n.has(e) && r++;
|
|
6180
6201
|
return r;
|
|
6181
6202
|
}
|
|
6182
|
-
function
|
|
6203
|
+
function Xc(e) {
|
|
6183
6204
|
let t = e.toLowerCase();
|
|
6184
6205
|
for (let e of [
|
|
6185
6206
|
"todo",
|
|
@@ -6206,7 +6227,7 @@ function Kc(e) {
|
|
|
6206
6227
|
]) if (t.includes(e)) return !0;
|
|
6207
6228
|
return !1;
|
|
6208
6229
|
}
|
|
6209
|
-
function
|
|
6230
|
+
function Zc(e) {
|
|
6210
6231
|
let t = e.toLowerCase();
|
|
6211
6232
|
for (let e of [
|
|
6212
6233
|
"remember",
|
|
@@ -6230,7 +6251,7 @@ function qc(e) {
|
|
|
6230
6251
|
]) if (t.includes(e)) return !0;
|
|
6231
6252
|
return !1;
|
|
6232
6253
|
}
|
|
6233
|
-
function
|
|
6254
|
+
function Qc(e) {
|
|
6234
6255
|
return {
|
|
6235
6256
|
id: e.id,
|
|
6236
6257
|
kind: e.kind,
|
|
@@ -6245,57 +6266,57 @@ function Jc(e) {
|
|
|
6245
6266
|
metadata: e.metadata_json
|
|
6246
6267
|
};
|
|
6247
6268
|
}
|
|
6248
|
-
function
|
|
6269
|
+
function $c(e) {
|
|
6249
6270
|
let t = Date.parse(e);
|
|
6250
6271
|
return Number.isNaN(t) ? -Infinity : t;
|
|
6251
6272
|
}
|
|
6252
|
-
function
|
|
6273
|
+
function el(e, t) {
|
|
6253
6274
|
let n = Date.now() - t * 864e5;
|
|
6254
|
-
return e.filter((e) =>
|
|
6275
|
+
return e.filter((e) => $c(e.created_at) >= n);
|
|
6255
6276
|
}
|
|
6256
|
-
function
|
|
6277
|
+
function tl(e, t) {
|
|
6257
6278
|
let n = [...e].sort((e, t) => (t.created_at ?? "").localeCompare(e.created_at ?? ""));
|
|
6258
6279
|
return n.sort((e, t) => {
|
|
6259
6280
|
let n = (e) => e === "note" ? 0 : e === "decision" ? 1 : e === "observation" ? 2 : 3;
|
|
6260
6281
|
return n(e.kind) - n(t.kind);
|
|
6261
6282
|
}), n.slice(0, t);
|
|
6262
6283
|
}
|
|
6263
|
-
function
|
|
6284
|
+
function nl(e, t) {
|
|
6264
6285
|
let n = [...e].sort((e, t) => (t.created_at ?? "").localeCompare(e.created_at ?? ""));
|
|
6265
6286
|
return n.sort((e, t) => {
|
|
6266
6287
|
let n = (e) => e === "session_summary" ? 0 : e === "decision" ? 1 : e === "note" ? 2 : e === "observation" ? 3 : e === "entities" ? 4 : 5;
|
|
6267
6288
|
return n(e.kind) - n(t.kind);
|
|
6268
6289
|
}), n.slice(0, t);
|
|
6269
6290
|
}
|
|
6270
|
-
function
|
|
6291
|
+
function rl(e, t, n) {
|
|
6271
6292
|
let r = Math.max(t * 3, t);
|
|
6272
|
-
return
|
|
6293
|
+
return tl(e.recent(r, n ?? null).map(Qc), t);
|
|
6273
6294
|
}
|
|
6274
|
-
function
|
|
6295
|
+
function il(e, t, n) {
|
|
6275
6296
|
let r = {
|
|
6276
6297
|
...n ?? {},
|
|
6277
6298
|
kind: "session_summary"
|
|
6278
|
-
}, i = e.recent(t, r).map(
|
|
6299
|
+
}, i = e.recent(t, r).map(Qc);
|
|
6279
6300
|
if (i.length >= t) return i.slice(0, t);
|
|
6280
|
-
let a = Math.max(t * 3, t), o = e.recent(a, n ?? null).map(
|
|
6301
|
+
let a = Math.max(t * 3, t), o = e.recent(a, n ?? null).map(Qc), s = new Set(i.map((e) => e.id)), c = tl(o.filter((e) => !s.has(e.id)), t - i.length);
|
|
6281
6302
|
return [...i, ...c];
|
|
6282
6303
|
}
|
|
6283
|
-
function
|
|
6304
|
+
function al(e) {
|
|
6284
6305
|
if (e == null || typeof e == "boolean") return null;
|
|
6285
6306
|
let t = Number(e);
|
|
6286
6307
|
if (!Number.isFinite(t)) return null;
|
|
6287
6308
|
let n = Math.trunc(t);
|
|
6288
6309
|
return n < 0 ? null : n;
|
|
6289
6310
|
}
|
|
6290
|
-
function
|
|
6311
|
+
function ol(e) {
|
|
6291
6312
|
let t = [], n = /* @__PURE__ */ new Set();
|
|
6292
6313
|
for (let r of e) {
|
|
6293
|
-
let e =
|
|
6314
|
+
let e = al(r);
|
|
6294
6315
|
e == null || e <= 0 || n.has(e) || (n.add(e), t.push(e));
|
|
6295
6316
|
}
|
|
6296
6317
|
return t;
|
|
6297
6318
|
}
|
|
6298
|
-
function
|
|
6319
|
+
function sl(e) {
|
|
6299
6320
|
if (!Array.isArray(e)) return {
|
|
6300
6321
|
ids: [],
|
|
6301
6322
|
valid: !1
|
|
@@ -6305,11 +6326,11 @@ function rl(e) {
|
|
|
6305
6326
|
valid: !1
|
|
6306
6327
|
};
|
|
6307
6328
|
return {
|
|
6308
|
-
ids:
|
|
6329
|
+
ids: ol(e),
|
|
6309
6330
|
valid: !0
|
|
6310
6331
|
};
|
|
6311
6332
|
}
|
|
6312
|
-
function
|
|
6333
|
+
function cl(e) {
|
|
6313
6334
|
if (!e) return {};
|
|
6314
6335
|
if (typeof e == "string") try {
|
|
6315
6336
|
let t = JSON.parse(e);
|
|
@@ -6319,7 +6340,7 @@ function il(e) {
|
|
|
6319
6340
|
}
|
|
6320
6341
|
return typeof e == "object" && !Array.isArray(e) ? e : {};
|
|
6321
6342
|
}
|
|
6322
|
-
function
|
|
6343
|
+
function ll(e, t) {
|
|
6323
6344
|
let n = t ? Wt(t) : null, r = "CASE WHEN json_valid(metadata_json) = 1 THEN json_extract(metadata_json, '$.project') ELSE NULL END", i = t ? e.db.prepare(`SELECT metadata_json, tokens_read
|
|
6324
6345
|
FROM usage_events
|
|
6325
6346
|
WHERE event = 'pack'
|
|
@@ -6327,15 +6348,15 @@ function al(e, t) {
|
|
|
6327
6348
|
ORDER BY created_at DESC
|
|
6328
6349
|
LIMIT 25`).all(t, n ?? t) : e.db.prepare("SELECT metadata_json, tokens_read\n FROM usage_events\n WHERE event = 'pack'\n ORDER BY created_at DESC\n LIMIT 25").all();
|
|
6329
6350
|
for (let e of i) {
|
|
6330
|
-
let r =
|
|
6351
|
+
let r = cl(e.metadata_json);
|
|
6331
6352
|
if (t != null) {
|
|
6332
6353
|
let e = typeof r.project == "string" ? r.project : null;
|
|
6333
6354
|
if (e !== t && e !== n) continue;
|
|
6334
6355
|
}
|
|
6335
6356
|
if (!("pack_item_ids" in r)) continue;
|
|
6336
|
-
let { ids: i, valid: a } =
|
|
6357
|
+
let { ids: i, valid: a } = sl(r.pack_item_ids);
|
|
6337
6358
|
if (!a) continue;
|
|
6338
|
-
let o =
|
|
6359
|
+
let o = al(r.pack_tokens) ?? al(e.tokens_read);
|
|
6339
6360
|
if (o != null) return {
|
|
6340
6361
|
previousPackIds: i,
|
|
6341
6362
|
previousPackTokens: o
|
|
@@ -6346,20 +6367,20 @@ function al(e, t) {
|
|
|
6346
6367
|
previousPackTokens: null
|
|
6347
6368
|
};
|
|
6348
6369
|
}
|
|
6349
|
-
function
|
|
6370
|
+
function ul(e, t) {
|
|
6350
6371
|
if (!t) return null;
|
|
6351
6372
|
let n = Wt(t);
|
|
6352
6373
|
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;
|
|
6353
6374
|
}
|
|
6354
|
-
function
|
|
6355
|
-
return
|
|
6375
|
+
function dl(e) {
|
|
6376
|
+
return al(cl(e.metadata).discovery_tokens) ?? Math.max(2e3, Vc(`${e.title} ${e.body_text}`.trim()));
|
|
6356
6377
|
}
|
|
6357
|
-
function
|
|
6358
|
-
let t =
|
|
6378
|
+
function fl(e) {
|
|
6379
|
+
let t = cl(e.metadata).discovery_group;
|
|
6359
6380
|
return typeof t == "string" && t.trim().length > 0 ? t.trim() : `memory:${e.id}`;
|
|
6360
6381
|
}
|
|
6361
|
-
function
|
|
6362
|
-
let t =
|
|
6382
|
+
function pl(e) {
|
|
6383
|
+
let t = cl(e.metadata), n = al(t.discovery_tokens);
|
|
6363
6384
|
return n != null && n > 0 ? {
|
|
6364
6385
|
tokens: n,
|
|
6365
6386
|
source: typeof t.discovery_source == "string" && t.discovery_source ? t.discovery_source : "known"
|
|
@@ -6368,16 +6389,16 @@ function ll(e) {
|
|
|
6368
6389
|
source: "unknown"
|
|
6369
6390
|
};
|
|
6370
6391
|
}
|
|
6371
|
-
function
|
|
6372
|
-
return
|
|
6392
|
+
function ml(e) {
|
|
6393
|
+
return cl(e.metadata).discovery_source === "usage" ? "usage" : "estimate";
|
|
6373
6394
|
}
|
|
6374
|
-
function
|
|
6375
|
-
let n = (/* @__PURE__ */ new Date()).toISOString(), r =
|
|
6395
|
+
function hl(e, t) {
|
|
6396
|
+
let n = (/* @__PURE__ */ new Date()).toISOString(), r = al(t.pack_tokens) ?? 0, i = al(t.tokens_saved) ?? 0, a = ul(e, typeof t.project == "string" ? t.project : null);
|
|
6376
6397
|
try {
|
|
6377
6398
|
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));
|
|
6378
6399
|
} catch {}
|
|
6379
6400
|
}
|
|
6380
|
-
function
|
|
6401
|
+
function gl(e, t, n, r, i) {
|
|
6381
6402
|
let a = /* @__PURE__ */ new Map();
|
|
6382
6403
|
for (let e of t) {
|
|
6383
6404
|
let t = a.get(e.id);
|
|
@@ -6390,46 +6411,46 @@ function fl(e, t, n, r, i) {
|
|
|
6390
6411
|
(!t || e.score > t.score) && a.set(e.id, e);
|
|
6391
6412
|
}
|
|
6392
6413
|
return {
|
|
6393
|
-
merged:
|
|
6414
|
+
merged: Dc(e, [...a.values()], r, i),
|
|
6394
6415
|
ftsCount: t.length,
|
|
6395
6416
|
semanticCount: o
|
|
6396
6417
|
};
|
|
6397
6418
|
}
|
|
6398
|
-
function
|
|
6399
|
-
let o = Math.max(1, Math.trunc(n)), s = !1, c = 0, l = 0, u, d =
|
|
6419
|
+
function _l(e, t, n = 10, r = null, i, a) {
|
|
6420
|
+
let o = Math.max(1, Math.trunc(n)), s = !1, c = 0, l = 0, u, d = Xc(t), f = !d && Zc(t);
|
|
6400
6421
|
if (d) {
|
|
6401
|
-
let n =
|
|
6422
|
+
let n = Oc(e, `${t} ${zc}`.trim(), o, i);
|
|
6402
6423
|
if (c = n.length, a && a.length > 0) {
|
|
6403
|
-
let t =
|
|
6424
|
+
let t = gl(e, n, a, o, i);
|
|
6404
6425
|
n = t.merged, l = t.semanticCount;
|
|
6405
6426
|
}
|
|
6406
|
-
if (n.length === 0) s = !0, u =
|
|
6427
|
+
if (n.length === 0) s = !0, u = rl(e, o, i);
|
|
6407
6428
|
else {
|
|
6408
|
-
let e =
|
|
6409
|
-
u =
|
|
6429
|
+
let e = el(n, Rc);
|
|
6430
|
+
u = tl(e.length > 0 ? e : n, o);
|
|
6410
6431
|
}
|
|
6411
6432
|
} else if (f) {
|
|
6412
|
-
let n =
|
|
6413
|
-
if (c = n.length, n.length === 0 && (n =
|
|
6433
|
+
let n = Oc(e, t.trim().length > 0 ? t : Bc, o, i);
|
|
6434
|
+
if (c = n.length, n.length === 0 && (n = Oc(e, Bc, o, {
|
|
6414
6435
|
...i ?? {},
|
|
6415
6436
|
kind: "session_summary"
|
|
6416
6437
|
}), c = n.length), a && a.length > 0) {
|
|
6417
|
-
let t =
|
|
6438
|
+
let t = gl(e, n, a, o, i);
|
|
6418
6439
|
n = t.merged, l = t.semanticCount;
|
|
6419
6440
|
}
|
|
6420
|
-
u =
|
|
6441
|
+
u = nl(n, o), u.length === 0 && (s = !0, u = il(e, o, i));
|
|
6421
6442
|
let r = u[0]?.id;
|
|
6422
6443
|
if (r != null) {
|
|
6423
|
-
let t = Math.max(0, Math.floor(o / 2)), n =
|
|
6424
|
-
n.length > 0 && (u = n.map(
|
|
6444
|
+
let t = Math.max(0, Math.floor(o / 2)), n = Ac(e, void 0, r, t, Math.max(0, o - t - 1), i ?? null);
|
|
6445
|
+
n.length > 0 && (u = n.map(Qc));
|
|
6425
6446
|
}
|
|
6426
6447
|
} else {
|
|
6427
|
-
let n =
|
|
6448
|
+
let n = Oc(e, t, o, i);
|
|
6428
6449
|
if (a && a.length > 0) {
|
|
6429
|
-
let t =
|
|
6450
|
+
let t = gl(e, n, a, o, i);
|
|
6430
6451
|
u = t.merged, c = t.ftsCount, l = t.semanticCount;
|
|
6431
6452
|
} else u = n, c = u.length;
|
|
6432
|
-
u.length === 0 && (s = !0, u = e.recent(o, i ?? null).map(
|
|
6453
|
+
u.length === 0 && (s = !0, u = e.recent(o, i ?? null).map(Qc));
|
|
6433
6454
|
}
|
|
6434
6455
|
let p = u.filter((e) => e.kind === "session_summary").slice(0, 1);
|
|
6435
6456
|
if (p.length === 0) {
|
|
@@ -6454,7 +6475,7 @@ function pl(e, t, n = 10, r = null, i, a) {
|
|
|
6454
6475
|
}];
|
|
6455
6476
|
}
|
|
6456
6477
|
}
|
|
6457
|
-
let m = u.filter((e) => e.kind !== "session_summary").slice(0, 3), h = new Set(m.map((e) => e.id)), g = Object.keys(
|
|
6478
|
+
let m = u.filter((e) => e.kind !== "session_summary").slice(0, 3), h = new Set(m.map((e) => e.id)), g = Object.keys(Lc), _ = [...u].filter((e) => e.kind !== "session_summary" && !h.has(e.id)).sort((e, t) => (Lc[e.kind] ?? 99) - (Lc[t.kind] ?? 99));
|
|
6458
6479
|
f && _.length === 0 && (_ = u.filter((e) => e.kind !== "session_summary")), _.length === 0 && (_ = e.recentByKinds(g, Math.max(o * 3, 10), i ?? null).map((e) => ({
|
|
6459
6480
|
id: e.id,
|
|
6460
6481
|
kind: e.kind,
|
|
@@ -6467,55 +6488,55 @@ function pl(e, t, n = 10, r = null, i, a) {
|
|
|
6467
6488
|
score: 0,
|
|
6468
6489
|
session_id: e.session_id,
|
|
6469
6490
|
metadata: e.metadata_json
|
|
6470
|
-
}))), _.length === 0 && (_ = [...m]), _ =
|
|
6491
|
+
}))), _.length === 0 && (_ = [...m]), _ = Jc(_, t);
|
|
6471
6492
|
let v = {
|
|
6472
6493
|
canonicalByKey: /* @__PURE__ */ new Map(),
|
|
6473
6494
|
duplicateIds: /* @__PURE__ */ new Map()
|
|
6474
6495
|
};
|
|
6475
|
-
p =
|
|
6496
|
+
p = qc(p, v), m = qc(m, v), _ = qc(_, v);
|
|
6476
6497
|
let y = p, b = m, x = _;
|
|
6477
6498
|
if (r != null && r > 0) {
|
|
6478
6499
|
let e = 0;
|
|
6479
6500
|
y = [];
|
|
6480
6501
|
for (let t of p) {
|
|
6481
|
-
let n =
|
|
6502
|
+
let n = Vc(Hc(t));
|
|
6482
6503
|
if (e + n > r) break;
|
|
6483
6504
|
e += n, y.push(t);
|
|
6484
6505
|
}
|
|
6485
6506
|
b = [];
|
|
6486
6507
|
for (let t of m) {
|
|
6487
|
-
let n =
|
|
6508
|
+
let n = Vc(Hc(t));
|
|
6488
6509
|
if (e + n > r) break;
|
|
6489
6510
|
e += n, b.push(t);
|
|
6490
6511
|
}
|
|
6491
6512
|
x = [];
|
|
6492
6513
|
for (let t of _) {
|
|
6493
|
-
let n =
|
|
6514
|
+
let n = Vc(Hc(t));
|
|
6494
6515
|
if (e + n > r) break;
|
|
6495
6516
|
e += n, x.push(t);
|
|
6496
6517
|
}
|
|
6497
6518
|
}
|
|
6498
6519
|
let S = [
|
|
6499
|
-
|
|
6500
|
-
|
|
6501
|
-
|
|
6502
|
-
].join("\n\n"), C =
|
|
6520
|
+
Uc("Summary", y),
|
|
6521
|
+
Uc("Timeline", b),
|
|
6522
|
+
Uc("Observations", x)
|
|
6523
|
+
].join("\n\n"), C = Vc(S), w = /* @__PURE__ */ new Set(), T = [], E = [], ee = [];
|
|
6503
6524
|
for (let e of [
|
|
6504
6525
|
...y,
|
|
6505
6526
|
...b,
|
|
6506
6527
|
...x
|
|
6507
|
-
]) w.has(e.id) || (w.add(e.id), E.push(e), T.push(
|
|
6508
|
-
let { previousPackIds: te, previousPackTokens: D } =
|
|
6528
|
+
]) w.has(e.id) || (w.add(e.id), E.push(e), T.push(Wc(e, v)), ee.push(e.id));
|
|
6529
|
+
let { previousPackIds: te, previousPackTokens: D } = ll(e, i?.project ?? null), O = te != null && D != null, k = new Set(te ?? []), A = new Set(ee), ne = O ? ee.filter((e) => !k.has(e)) : [], j = O ? (te ?? []).filter((e) => !A.has(e)) : [], re = O ? ee.filter((e) => k.has(e)) : [], ie = O ? C - (D ?? 0) : 0, ae = E.reduce((e, t) => e + dl(t), 0), oe = /* @__PURE__ */ new Map();
|
|
6509
6530
|
for (let e of E) {
|
|
6510
|
-
let t =
|
|
6531
|
+
let t = fl(e), n = dl(e);
|
|
6511
6532
|
n > (oe.get(t) ?? 0) && oe.set(t, n);
|
|
6512
6533
|
}
|
|
6513
6534
|
let se = [...oe.values()].reduce((e, t) => e + t, 0), ce = Math.max(0, se - C), M = 0, N = 0, P = 0, F = {};
|
|
6514
6535
|
for (let e of E) {
|
|
6515
|
-
let t =
|
|
6536
|
+
let t = pl(e);
|
|
6516
6537
|
t.tokens > 0 ? (M += t.tokens, N += 1, F[t.source] = (F[t.source] ?? 0) + 1) : P += 1;
|
|
6517
6538
|
}
|
|
6518
|
-
let le = Math.max(0, M - C), ue = M > 0 ? M / Math.max(C, 1) : null, I = E.map(
|
|
6539
|
+
let le = Math.max(0, M - C), ue = M > 0 ? M / Math.max(C, 1) : null, I = E.map(ml), L = I.filter((e) => e === "usage").length, de = I.length - L, fe = L > 0 && de > 0 ? "mixed" : L > 0 ? "usage" : "estimate", pe = se > 0 ? C / se : null, me = se > 0 ? C - se : null, he = s ? "recent" : null, ge = d ? "task" : f ? "recall" : "default", _e = {
|
|
6519
6540
|
total_items: T.length,
|
|
6520
6541
|
pack_tokens: C,
|
|
6521
6542
|
fallback_used: s,
|
|
@@ -6551,7 +6572,7 @@ function pl(e, t, n = 10, r = null, i, a) {
|
|
|
6551
6572
|
fuzzy: 0
|
|
6552
6573
|
}
|
|
6553
6574
|
};
|
|
6554
|
-
return
|
|
6575
|
+
return hl(e, _e), {
|
|
6555
6576
|
context: t,
|
|
6556
6577
|
items: T,
|
|
6557
6578
|
item_ids: ee,
|
|
@@ -6559,10 +6580,10 @@ function pl(e, t, n = 10, r = null, i, a) {
|
|
|
6559
6580
|
metrics: _e
|
|
6560
6581
|
};
|
|
6561
6582
|
}
|
|
6562
|
-
async function
|
|
6583
|
+
async function vl(e, t, n = 10, r = null, i) {
|
|
6563
6584
|
let a = [];
|
|
6564
6585
|
try {
|
|
6565
|
-
a = (await
|
|
6586
|
+
a = (await Lo(e.db, t, n, { project: i?.project })).map((e) => {
|
|
6566
6587
|
let t = {};
|
|
6567
6588
|
if (e.metadata_json) try {
|
|
6568
6589
|
let n = JSON.parse(e.metadata_json);
|
|
@@ -6583,24 +6604,24 @@ async function ml(e, t, n = 10, r = null, i) {
|
|
|
6583
6604
|
};
|
|
6584
6605
|
});
|
|
6585
6606
|
} catch {}
|
|
6586
|
-
return
|
|
6607
|
+
return _l(e, t, n, r, i, a);
|
|
6587
6608
|
}
|
|
6588
6609
|
//#endregion
|
|
6589
6610
|
//#region src/raw-event-flush.ts
|
|
6590
|
-
var
|
|
6591
|
-
function
|
|
6611
|
+
var yl = "raw_events_v1";
|
|
6612
|
+
function bl(e, t = 280) {
|
|
6592
6613
|
let n = e.replace(/\s+/g, " ").trim();
|
|
6593
6614
|
return n.length <= t ? n : `${n.slice(0, t - 3).trimEnd()}...`;
|
|
6594
6615
|
}
|
|
6595
|
-
function
|
|
6616
|
+
function xl(e) {
|
|
6596
6617
|
let t = (e ?? "").trim().toLowerCase();
|
|
6597
6618
|
return t === "openai" ? "OpenAI" : t === "anthropic" ? "Anthropic" : t ? t.charAt(0).toUpperCase() + t.slice(1) : "Observer";
|
|
6598
6619
|
}
|
|
6599
|
-
function
|
|
6600
|
-
let n =
|
|
6601
|
-
return e instanceof
|
|
6620
|
+
function Sl(e, t) {
|
|
6621
|
+
let n = xl(t), r = String(e.message ?? "").trim().toLowerCase();
|
|
6622
|
+
return e instanceof js ? `${n} authentication failed. Refresh credentials and retry.` : e.name === "TimeoutError" || r.includes("timeout") ? `${n} request timed out during raw-event processing.` : r === "observer failed during raw-event flush" || r === "observer produced no storable output for raw-event flush" ? `${n} returned no usable output for raw-event processing.` : /parse|xml|json/i.test(r) ? `${n} response could not be processed.` : `${n} processing failed during raw-event ingestion.`;
|
|
6602
6623
|
}
|
|
6603
|
-
function
|
|
6624
|
+
function Cl(e) {
|
|
6604
6625
|
let t = 0, n = 0;
|
|
6605
6626
|
for (let r of e) r.type === "user_prompt" && t++, r.type === "tool.execute.after" && n++;
|
|
6606
6627
|
let r = [];
|
|
@@ -6645,7 +6666,7 @@ function yl(e) {
|
|
|
6645
6666
|
filesRead: [...o].sort()
|
|
6646
6667
|
};
|
|
6647
6668
|
}
|
|
6648
|
-
async function
|
|
6669
|
+
async function wl(e, t, n) {
|
|
6649
6670
|
let { source: r = "opencode", cwd: i, project: a, startedAt: o } = n, { opencodeSessionId: s, maxEvents: c } = n, l = n.allowEmptyFlush ?? !1;
|
|
6650
6671
|
r = (r ?? "").trim().toLowerCase() || "opencode";
|
|
6651
6672
|
let u = e.rawEventSessionMeta(s, r);
|
|
@@ -6675,7 +6696,7 @@ async function bl(e, t, n) {
|
|
|
6675
6696
|
flushed: 0,
|
|
6676
6697
|
updatedState: 0
|
|
6677
6698
|
};
|
|
6678
|
-
let { batchId: g, status: _ } = e.getOrCreateRawEventFlushBatch(s, r, m, h,
|
|
6699
|
+
let { batchId: g, status: _ } = e.getOrCreateRawEventFlushBatch(s, r, m, h, yl);
|
|
6679
6700
|
if (_ === "completed") return e.updateRawEventFlushState(s, h, r), {
|
|
6680
6701
|
flushed: 0,
|
|
6681
6702
|
updatedState: 1
|
|
@@ -6684,7 +6705,7 @@ async function bl(e, t, n) {
|
|
|
6684
6705
|
flushed: 0,
|
|
6685
6706
|
updatedState: 0
|
|
6686
6707
|
};
|
|
6687
|
-
let v =
|
|
6708
|
+
let v = Cl(f);
|
|
6688
6709
|
v.opencodeSessionId = s, v.source = r, v.streamId = s, v.flusher = "raw_events", v.flushBatch = {
|
|
6689
6710
|
batch_id: g,
|
|
6690
6711
|
start_event_seq: m,
|
|
@@ -6698,17 +6719,17 @@ async function bl(e, t, n) {
|
|
|
6698
6719
|
sessionContext: v
|
|
6699
6720
|
};
|
|
6700
6721
|
try {
|
|
6701
|
-
await
|
|
6722
|
+
await Uo(y, e, t);
|
|
6702
6723
|
} catch (n) {
|
|
6703
6724
|
let i = n instanceof Error ? n : Error(String(n));
|
|
6704
6725
|
if (l && i.message === "observer produced no storable output for raw-event flush") return e.updateRawEventFlushBatchStatus(g, "completed"), e.updateRawEventFlushState(s, h, r), {
|
|
6705
6726
|
flushed: f.length,
|
|
6706
6727
|
updatedState: 1
|
|
6707
6728
|
};
|
|
6708
|
-
let a = t.observer?.getStatus?.()?.provider, o =
|
|
6729
|
+
let a = t.observer?.getStatus?.()?.provider, o = bl(Sl(i, a));
|
|
6709
6730
|
throw e.recordRawEventFlushBatchFailure(g, {
|
|
6710
6731
|
message: o,
|
|
6711
|
-
errorType: i instanceof
|
|
6732
|
+
errorType: i instanceof js ? "ObserverAuthError" : i.name,
|
|
6712
6733
|
observerProvider: a ?? null,
|
|
6713
6734
|
observerModel: t.observer?.getStatus?.()?.model ?? null,
|
|
6714
6735
|
observerRuntime: null
|
|
@@ -6721,18 +6742,18 @@ async function bl(e, t, n) {
|
|
|
6721
6742
|
}
|
|
6722
6743
|
//#endregion
|
|
6723
6744
|
//#region src/raw-event-sweeper.ts
|
|
6724
|
-
var
|
|
6725
|
-
function
|
|
6745
|
+
var Tl = 60;
|
|
6746
|
+
function El(e, t) {
|
|
6726
6747
|
let n = process.env[e];
|
|
6727
6748
|
if (n == null) return t;
|
|
6728
6749
|
let r = Number.parseInt(n, 10);
|
|
6729
6750
|
return Number.isFinite(r) ? r : t;
|
|
6730
6751
|
}
|
|
6731
|
-
function
|
|
6752
|
+
function Dl(e) {
|
|
6732
6753
|
let t = (process.env[e] ?? "1").trim().toLowerCase();
|
|
6733
6754
|
return t === "0" || t === "false" || t === "off";
|
|
6734
6755
|
}
|
|
6735
|
-
var
|
|
6756
|
+
var Ol = class {
|
|
6736
6757
|
store;
|
|
6737
6758
|
ingestOpts;
|
|
6738
6759
|
active = !1;
|
|
@@ -6750,7 +6771,7 @@ var wl = class {
|
|
|
6750
6771
|
this.store = e, this.ingestOpts = t;
|
|
6751
6772
|
}
|
|
6752
6773
|
enabled() {
|
|
6753
|
-
return !
|
|
6774
|
+
return !Dl("CODEMEM_RAW_EVENTS_SWEEPER");
|
|
6754
6775
|
}
|
|
6755
6776
|
intervalMs() {
|
|
6756
6777
|
let e = process.env.CODEMEM_RAW_EVENTS_SWEEPER_INTERVAL_MS;
|
|
@@ -6762,31 +6783,31 @@ var wl = class {
|
|
|
6762
6783
|
return Number.isFinite(n) && n > 0 ? Math.max(1e3, n * 1e3) : 3e4;
|
|
6763
6784
|
}
|
|
6764
6785
|
idleMs() {
|
|
6765
|
-
return
|
|
6786
|
+
return El("CODEMEM_RAW_EVENTS_SWEEPER_IDLE_MS", 12e4);
|
|
6766
6787
|
}
|
|
6767
6788
|
limit() {
|
|
6768
|
-
return
|
|
6789
|
+
return El("CODEMEM_RAW_EVENTS_SWEEPER_LIMIT", 25);
|
|
6769
6790
|
}
|
|
6770
6791
|
workerMaxEvents() {
|
|
6771
|
-
let e =
|
|
6792
|
+
let e = El("CODEMEM_RAW_EVENTS_WORKER_MAX_EVENTS", 250);
|
|
6772
6793
|
return e <= 0 ? null : e;
|
|
6773
6794
|
}
|
|
6774
6795
|
retentionMs() {
|
|
6775
|
-
return
|
|
6796
|
+
return El("CODEMEM_RAW_EVENTS_RETENTION_MS", 0);
|
|
6776
6797
|
}
|
|
6777
6798
|
autoFlushEnabled() {
|
|
6778
6799
|
return (process.env.CODEMEM_RAW_EVENTS_AUTO_FLUSH ?? "").trim() === "1";
|
|
6779
6800
|
}
|
|
6780
6801
|
debounceMs() {
|
|
6781
|
-
return
|
|
6802
|
+
return El("CODEMEM_RAW_EVENTS_DEBOUNCE_MS", 6e4);
|
|
6782
6803
|
}
|
|
6783
6804
|
stuckBatchMs() {
|
|
6784
|
-
return
|
|
6805
|
+
return El("CODEMEM_RAW_EVENTS_STUCK_BATCH_MS", 3e5);
|
|
6785
6806
|
}
|
|
6786
6807
|
handleAuthError(e) {
|
|
6787
|
-
if (this.authBackoffUntil = Date.now() / 1e3 +
|
|
6808
|
+
if (this.authBackoffUntil = Date.now() / 1e3 + Tl, !this.authErrorLogged) {
|
|
6788
6809
|
this.authErrorLogged = !0;
|
|
6789
|
-
let t = `codemem: observer auth error — backing off for ${
|
|
6810
|
+
let t = `codemem: observer auth error — backing off for ${Tl}s. Refresh your provider credentials or update observer_provider in settings. (${e.message})`;
|
|
6790
6811
|
console.error(t);
|
|
6791
6812
|
}
|
|
6792
6813
|
}
|
|
@@ -6866,7 +6887,7 @@ var wl = class {
|
|
|
6866
6887
|
let r = this.autoFlushTimers.get(n);
|
|
6867
6888
|
r && (clearTimeout(r), this.autoFlushTimers.delete(n));
|
|
6868
6889
|
try {
|
|
6869
|
-
await
|
|
6890
|
+
await wl(this.store, this.ingestOpts, {
|
|
6870
6891
|
opencodeSessionId: e,
|
|
6871
6892
|
source: t,
|
|
6872
6893
|
cwd: null,
|
|
@@ -6876,7 +6897,7 @@ var wl = class {
|
|
|
6876
6897
|
allowEmptyFlush: !0
|
|
6877
6898
|
});
|
|
6878
6899
|
} catch (t) {
|
|
6879
|
-
if (t instanceof
|
|
6900
|
+
if (t instanceof js) {
|
|
6880
6901
|
this.handleAuthError(t);
|
|
6881
6902
|
return;
|
|
6882
6903
|
}
|
|
@@ -6924,7 +6945,7 @@ var wl = class {
|
|
|
6924
6945
|
if (!this.sessionFlushing.has(r)) {
|
|
6925
6946
|
this.sessionFlushing.add(r);
|
|
6926
6947
|
try {
|
|
6927
|
-
await
|
|
6948
|
+
await wl(this.store, this.ingestOpts, {
|
|
6928
6949
|
opencodeSessionId: n,
|
|
6929
6950
|
source: t,
|
|
6930
6951
|
cwd: null,
|
|
@@ -6934,7 +6955,7 @@ var wl = class {
|
|
|
6934
6955
|
allowEmptyFlush: !0
|
|
6935
6956
|
}), o.add(`${t}:${n}`);
|
|
6936
6957
|
} catch (e) {
|
|
6937
|
-
if (e instanceof
|
|
6958
|
+
if (e instanceof js) {
|
|
6938
6959
|
this.handleAuthError(e);
|
|
6939
6960
|
return;
|
|
6940
6961
|
}
|
|
@@ -6952,7 +6973,7 @@ var wl = class {
|
|
|
6952
6973
|
if (!this.sessionFlushing.has(r)) {
|
|
6953
6974
|
this.sessionFlushing.add(r);
|
|
6954
6975
|
try {
|
|
6955
|
-
await
|
|
6976
|
+
await wl(this.store, this.ingestOpts, {
|
|
6956
6977
|
opencodeSessionId: n,
|
|
6957
6978
|
source: t,
|
|
6958
6979
|
cwd: null,
|
|
@@ -6962,7 +6983,7 @@ var wl = class {
|
|
|
6962
6983
|
allowEmptyFlush: !0
|
|
6963
6984
|
});
|
|
6964
6985
|
} catch (e) {
|
|
6965
|
-
if (e instanceof
|
|
6986
|
+
if (e instanceof js) {
|
|
6966
6987
|
this.handleAuthError(e);
|
|
6967
6988
|
return;
|
|
6968
6989
|
}
|
|
@@ -6976,7 +6997,7 @@ var wl = class {
|
|
|
6976
6997
|
};
|
|
6977
6998
|
//#endregion
|
|
6978
6999
|
//#region src/sync-replication.ts
|
|
6979
|
-
function
|
|
7000
|
+
function kl(e, t) {
|
|
6980
7001
|
let n = new TextEncoder(), r = [], i = [], a = 9;
|
|
6981
7002
|
for (let o of e) {
|
|
6982
7003
|
let e = n.encode(JSON.stringify(o)).byteLength, s = i.length === 0 ? e : e + 1;
|
|
@@ -6988,14 +7009,14 @@ function Tl(e, t) {
|
|
|
6988
7009
|
}
|
|
6989
7010
|
return i.length > 0 && r.push(i), r;
|
|
6990
7011
|
}
|
|
6991
|
-
function
|
|
7012
|
+
function Al(e, t) {
|
|
6992
7013
|
let n = N(e, { schema: U }).select({
|
|
6993
7014
|
last_applied_cursor: nn.last_applied_cursor,
|
|
6994
7015
|
last_acked_cursor: nn.last_acked_cursor
|
|
6995
7016
|
}).from(nn).where(k(nn.peer_device_id, t)).get();
|
|
6996
7017
|
return n ? [n.last_applied_cursor, n.last_acked_cursor] : [null, null];
|
|
6997
7018
|
}
|
|
6998
|
-
function
|
|
7019
|
+
function jl(e, t, n = {}) {
|
|
6999
7020
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = n.lastApplied ?? null, a = n.lastAcked ?? null;
|
|
7000
7021
|
N(e, { schema: U }).insert(nn).values({
|
|
7001
7022
|
peer_device_id: t,
|
|
@@ -7011,7 +7032,7 @@ function Dl(e, t, n = {}) {
|
|
|
7011
7032
|
}
|
|
7012
7033
|
}).run();
|
|
7013
7034
|
}
|
|
7014
|
-
var
|
|
7035
|
+
var Ml = [
|
|
7015
7036
|
"op_id",
|
|
7016
7037
|
"entity_type",
|
|
7017
7038
|
"entity_id",
|
|
@@ -7022,26 +7043,26 @@ var Ol = [
|
|
|
7022
7043
|
"device_id",
|
|
7023
7044
|
"created_at"
|
|
7024
7045
|
];
|
|
7025
|
-
function
|
|
7046
|
+
function Nl(e) {
|
|
7026
7047
|
if (typeof e != "object" || !e) return [];
|
|
7027
7048
|
let t = e.ops;
|
|
7028
7049
|
return Array.isArray(t) ? t.filter((e) => {
|
|
7029
7050
|
if (typeof e != "object" || !e) return !1;
|
|
7030
7051
|
let t = e;
|
|
7031
|
-
return
|
|
7052
|
+
return Ml.every((e) => t[e] !== void 0 && t[e] !== null);
|
|
7032
7053
|
}) : [];
|
|
7033
7054
|
}
|
|
7034
|
-
function
|
|
7055
|
+
function Pl(e, t, n) {
|
|
7035
7056
|
return [
|
|
7036
7057
|
e,
|
|
7037
7058
|
t,
|
|
7038
7059
|
n
|
|
7039
7060
|
];
|
|
7040
7061
|
}
|
|
7041
|
-
function
|
|
7062
|
+
function Fl(e, t) {
|
|
7042
7063
|
return e[0] === t[0] ? e[1] === t[1] ? e[2] > t[2] : e[1] > t[1] : e[0] > t[0];
|
|
7043
7064
|
}
|
|
7044
|
-
function
|
|
7065
|
+
function Il(e, t) {
|
|
7045
7066
|
let n = N(e, { schema: U }), r = a(), i = (/* @__PURE__ */ new Date()).toISOString(), o = n.select().from(G).where(k(G.id, t.memoryId)).get(), s = Number(o?.rev ?? 0), c = o?.updated_at ?? i, l = o?.import_key ?? String(t.memoryId), u = B(o?.metadata_json).clock_device_id || t.deviceId, d;
|
|
7046
7067
|
if (t.payload) d = V(t.payload);
|
|
7047
7068
|
else if (o && t.opType === "upsert") {
|
|
@@ -7096,17 +7117,17 @@ function Ml(e, t) {
|
|
|
7096
7117
|
created_at: i
|
|
7097
7118
|
}).run(), r;
|
|
7098
7119
|
}
|
|
7099
|
-
function
|
|
7120
|
+
function Ll(e) {
|
|
7100
7121
|
let t = e.indexOf("|");
|
|
7101
7122
|
return t < 0 ? null : [e.slice(0, t), e.slice(t + 1)];
|
|
7102
7123
|
}
|
|
7103
|
-
function
|
|
7124
|
+
function Rl(e, t) {
|
|
7104
7125
|
return `${e}|${t}`;
|
|
7105
7126
|
}
|
|
7106
|
-
function
|
|
7127
|
+
function zl(e, t, n = 100, r) {
|
|
7107
7128
|
let i = N(e, { schema: U }), a = tn, o = [];
|
|
7108
7129
|
if (t) {
|
|
7109
|
-
let e =
|
|
7130
|
+
let e = Ll(t);
|
|
7110
7131
|
if (e) {
|
|
7111
7132
|
let [t, n] = e;
|
|
7112
7133
|
o.push(ce(A(a.created_at, t), D(k(a.created_at, t), A(a.op_id, n))));
|
|
@@ -7127,11 +7148,11 @@ function Fl(e, t, n = 100, r) {
|
|
|
7127
7148
|
})), u = null;
|
|
7128
7149
|
if (c.length > 0) {
|
|
7129
7150
|
let e = c.at(-1);
|
|
7130
|
-
e && (u =
|
|
7151
|
+
e && (u = Rl(e.created_at, e.op_id));
|
|
7131
7152
|
}
|
|
7132
7153
|
return [l, u];
|
|
7133
7154
|
}
|
|
7134
|
-
function
|
|
7155
|
+
function Bl(e) {
|
|
7135
7156
|
if (!Array.isArray(e)) return [];
|
|
7136
7157
|
let t = [];
|
|
7137
7158
|
for (let n of e) {
|
|
@@ -7140,25 +7161,25 @@ function Il(e) {
|
|
|
7140
7161
|
}
|
|
7141
7162
|
return t;
|
|
7142
7163
|
}
|
|
7143
|
-
function
|
|
7144
|
-
return Array.isArray(e) ?
|
|
7164
|
+
function Vl(e) {
|
|
7165
|
+
return Array.isArray(e) ? Bl(e) : typeof e == "string" ? e.split(",").map((e) => e.trim()).filter(Boolean) : [];
|
|
7145
7166
|
}
|
|
7146
|
-
function
|
|
7167
|
+
function Hl(e) {
|
|
7147
7168
|
if (!e) return [];
|
|
7148
7169
|
try {
|
|
7149
|
-
return
|
|
7170
|
+
return Bl(JSON.parse(e));
|
|
7150
7171
|
} catch {
|
|
7151
7172
|
return [];
|
|
7152
7173
|
}
|
|
7153
7174
|
}
|
|
7154
|
-
function
|
|
7175
|
+
function Ul(e) {
|
|
7155
7176
|
let t = String(e ?? "").trim().replaceAll("\\", "/");
|
|
7156
7177
|
if (!t) return "";
|
|
7157
7178
|
let n = t.split("/").filter(Boolean);
|
|
7158
7179
|
return n.length > 0 ? n[n.length - 1] ?? "" : "";
|
|
7159
7180
|
}
|
|
7160
|
-
function
|
|
7161
|
-
let n = N(e, { schema: U }), r = et(), i = process.env.CODEMEM_SYNC_PROJECTS_INCLUDE, a = process.env.CODEMEM_SYNC_PROJECTS_EXCLUDE, o =
|
|
7181
|
+
function Wl(e, t) {
|
|
7182
|
+
let n = N(e, { schema: U }), r = et(), i = process.env.CODEMEM_SYNC_PROJECTS_INCLUDE, a = process.env.CODEMEM_SYNC_PROJECTS_EXCLUDE, o = Vl(i === void 0 ? r.sync_projects_include : i), s = Vl(a === void 0 ? r.sync_projects_exclude : a);
|
|
7162
7183
|
if (!t) return {
|
|
7163
7184
|
include: o,
|
|
7164
7185
|
exclude: s
|
|
@@ -7171,15 +7192,15 @@ function Bl(e, t) {
|
|
|
7171
7192
|
include: o,
|
|
7172
7193
|
exclude: s
|
|
7173
7194
|
} : {
|
|
7174
|
-
include:
|
|
7175
|
-
exclude:
|
|
7195
|
+
include: Hl(c.projects_include_json),
|
|
7196
|
+
exclude: Hl(c.projects_exclude_json)
|
|
7176
7197
|
};
|
|
7177
7198
|
}
|
|
7178
|
-
function
|
|
7179
|
-
let { include: r, exclude: i } =
|
|
7199
|
+
function Gl(e, t, n) {
|
|
7200
|
+
let { include: r, exclude: i } = Wl(e, n), a = String(t ?? "").trim(), o = Ul(a);
|
|
7180
7201
|
return i.some((e) => e === a || e === o) ? !1 : r.length === 0 ? !0 : r.some((e) => e === a || e === o);
|
|
7181
7202
|
}
|
|
7182
|
-
function
|
|
7203
|
+
function Kl(e) {
|
|
7183
7204
|
if (!e) return !1;
|
|
7184
7205
|
let t = String(e.visibility ?? "").trim().toLowerCase(), n = e.metadata_json && typeof e.metadata_json == "object" && !Array.isArray(e.metadata_json) ? e.metadata_json : {}, r = String(n.visibility ?? "").trim().toLowerCase();
|
|
7185
7206
|
if (!t && r && (t = r), !t) {
|
|
@@ -7189,10 +7210,10 @@ function Hl(e) {
|
|
|
7189
7210
|
}
|
|
7190
7211
|
return t === "shared";
|
|
7191
7212
|
}
|
|
7192
|
-
function
|
|
7213
|
+
function ql(e, t) {
|
|
7193
7214
|
return t ? !!N(e, { schema: U }).select({ claimed_local_actor: Y.claimed_local_actor }).from(Y).where(k(Y.peer_device_id, t)).limit(1).get()?.claimed_local_actor : !1;
|
|
7194
7215
|
}
|
|
7195
|
-
function
|
|
7216
|
+
function Jl(e) {
|
|
7196
7217
|
if (!e || !e.trim()) return null;
|
|
7197
7218
|
try {
|
|
7198
7219
|
let t = JSON.parse(e);
|
|
@@ -7201,16 +7222,16 @@ function Wl(e) {
|
|
|
7201
7222
|
return null;
|
|
7202
7223
|
}
|
|
7203
7224
|
}
|
|
7204
|
-
function
|
|
7225
|
+
function Yl(e, t, n) {
|
|
7205
7226
|
let r = [], i = null, a = 0, o = null;
|
|
7206
7227
|
for (let s of t) {
|
|
7207
7228
|
if (s.entity_type === "memory_item") {
|
|
7208
|
-
let t =
|
|
7229
|
+
let t = Jl(s.payload_json);
|
|
7209
7230
|
if (s.op_type === "delete" && t == null) {
|
|
7210
|
-
r.push(s), i =
|
|
7231
|
+
r.push(s), i = Rl(s.created_at, s.op_id);
|
|
7211
7232
|
continue;
|
|
7212
7233
|
}
|
|
7213
|
-
if (!
|
|
7234
|
+
if (!Kl(t) && !ql(e, n)) {
|
|
7214
7235
|
a += 1, o ||= {
|
|
7215
7236
|
reason: "visibility_filter",
|
|
7216
7237
|
op_id: s.op_id,
|
|
@@ -7219,11 +7240,11 @@ function Gl(e, t, n) {
|
|
|
7219
7240
|
entity_id: s.entity_id,
|
|
7220
7241
|
visibility: typeof t?.visibility == "string" ? String(t.visibility) : null,
|
|
7221
7242
|
skipped_count: 0
|
|
7222
|
-
}, i =
|
|
7243
|
+
}, i = Rl(s.created_at, s.op_id);
|
|
7223
7244
|
continue;
|
|
7224
7245
|
}
|
|
7225
7246
|
let c = typeof t?.project == "string" && t.project.trim() ? t.project.trim() : null;
|
|
7226
|
-
if (!
|
|
7247
|
+
if (!Gl(e, c, n)) {
|
|
7227
7248
|
a += 1, o ||= {
|
|
7228
7249
|
reason: "project_filter",
|
|
7229
7250
|
op_id: s.op_id,
|
|
@@ -7232,11 +7253,11 @@ function Gl(e, t, n) {
|
|
|
7232
7253
|
entity_id: s.entity_id,
|
|
7233
7254
|
project: c,
|
|
7234
7255
|
skipped_count: 0
|
|
7235
|
-
}, i =
|
|
7256
|
+
}, i = Rl(s.created_at, s.op_id);
|
|
7236
7257
|
continue;
|
|
7237
7258
|
}
|
|
7238
7259
|
}
|
|
7239
|
-
r.push(s), i =
|
|
7260
|
+
r.push(s), i = Rl(s.created_at, s.op_id);
|
|
7240
7261
|
}
|
|
7241
7262
|
return o && (o.skipped_count = a), [
|
|
7242
7263
|
r,
|
|
@@ -7244,12 +7265,12 @@ function Gl(e, t, n) {
|
|
|
7244
7265
|
o
|
|
7245
7266
|
];
|
|
7246
7267
|
}
|
|
7247
|
-
function
|
|
7248
|
-
let [r, i] =
|
|
7268
|
+
function Xl(e, t, n) {
|
|
7269
|
+
let [r, i] = Yl(e, t, n);
|
|
7249
7270
|
return [r, i];
|
|
7250
7271
|
}
|
|
7251
|
-
var
|
|
7252
|
-
function
|
|
7272
|
+
var Zl = /^legacy:memory_item:(.+)$/;
|
|
7273
|
+
function Ql(e, t = 2e3) {
|
|
7253
7274
|
let n = N(e, { schema: U }), r = n.select({ device_id: X.device_id }).from(X).limit(1).get(), i = String(r?.device_id ?? "").trim();
|
|
7254
7275
|
if (!i) return 0;
|
|
7255
7276
|
let a = n.select({
|
|
@@ -7263,7 +7284,7 @@ function Jl(e, t = 2e3) {
|
|
|
7263
7284
|
let t = Number(e.id), r = String(e.import_key ?? "").trim(), a = B(e.metadata_json), s = String(a.clock_device_id ?? "").trim(), c = "";
|
|
7264
7285
|
if (!r) c = `legacy:${i}:memory_item:${t}`;
|
|
7265
7286
|
else {
|
|
7266
|
-
let e = r.match(
|
|
7287
|
+
let e = r.match(Zl);
|
|
7267
7288
|
if (!e) continue;
|
|
7268
7289
|
let t = e[1] ?? "", n = s && s !== "local" ? s : i;
|
|
7269
7290
|
c = n ? `legacy:${n}:memory_item:${t}` : "";
|
|
@@ -7274,9 +7295,9 @@ function Jl(e, t = 2e3) {
|
|
|
7274
7295
|
}
|
|
7275
7296
|
return o;
|
|
7276
7297
|
}
|
|
7277
|
-
function
|
|
7298
|
+
function $l(e, t = 200) {
|
|
7278
7299
|
if (t <= 0) return 0;
|
|
7279
|
-
|
|
7300
|
+
Ql(e, 2e3);
|
|
7280
7301
|
let n = N(e, { schema: U }), r = n.select({ device_id: X.device_id }).from(X).limit(1).get(), i = String(r?.device_id ?? "").trim(), a = n.select().from(G).where(D(ce(re(G.deleted_at), k(G.active, 0)), M`NOT EXISTS (
|
|
7281
7302
|
SELECT 1
|
|
7282
7303
|
FROM replication_ops ro
|
|
@@ -7301,7 +7322,7 @@ function Yl(e, t = 200) {
|
|
|
7301
7322
|
for (let e of s) {
|
|
7302
7323
|
let t = Number(e.id ?? 0);
|
|
7303
7324
|
if (!t) continue;
|
|
7304
|
-
let r = typeof e.metadata_json == "string" ? B(e.metadata_json) :
|
|
7325
|
+
let r = typeof e.metadata_json == "string" ? B(e.metadata_json) : eu(e.metadata_json), a = String(r.clock_device_id ?? "").trim(), o = a && a !== "local" ? a : i, s = String(e.import_key ?? "").trim();
|
|
7305
7326
|
if (!s) {
|
|
7306
7327
|
if (!o) continue;
|
|
7307
7328
|
s = `legacy:${o}:memory_item:${t}`, n.update(G).set({ import_key: s }).where(k(G.id, t)).run();
|
|
@@ -7310,7 +7331,7 @@ function Yl(e, t = 200) {
|
|
|
7310
7331
|
if (n.select({ one: M`1` }).from(tn).where(k(tn.op_id, p)).limit(1).get()) continue;
|
|
7311
7332
|
let m = o;
|
|
7312
7333
|
if (!m) continue;
|
|
7313
|
-
let h =
|
|
7334
|
+
let h = tu(e);
|
|
7314
7335
|
n.insert(tn).values({
|
|
7315
7336
|
op_id: p,
|
|
7316
7337
|
entity_type: "memory_item",
|
|
@@ -7326,10 +7347,10 @@ function Yl(e, t = 200) {
|
|
|
7326
7347
|
}
|
|
7327
7348
|
return l;
|
|
7328
7349
|
}
|
|
7329
|
-
function
|
|
7350
|
+
function eu(e) {
|
|
7330
7351
|
return typeof e == "string" ? B(e) : e && typeof e == "object" ? e : {};
|
|
7331
7352
|
}
|
|
7332
|
-
function
|
|
7353
|
+
function tu(e) {
|
|
7333
7354
|
let t = (e) => {
|
|
7334
7355
|
if (typeof e != "string") return e ?? null;
|
|
7335
7356
|
try {
|
|
@@ -7370,7 +7391,7 @@ function Zl(e) {
|
|
|
7370
7391
|
import_key: e.import_key ?? null
|
|
7371
7392
|
};
|
|
7372
7393
|
}
|
|
7373
|
-
function
|
|
7394
|
+
function nu(e, t, n) {
|
|
7374
7395
|
let r = N(e, { schema: U }), i = {
|
|
7375
7396
|
applied: 0,
|
|
7376
7397
|
skipped: 0,
|
|
@@ -7402,9 +7423,9 @@ function Ql(e, t, n) {
|
|
|
7402
7423
|
}
|
|
7403
7424
|
};
|
|
7404
7425
|
if (n) {
|
|
7405
|
-
let o = B(n.metadata_json).clock_device_id ?? "", s =
|
|
7406
|
-
if (!
|
|
7407
|
-
i.conflicts++,
|
|
7426
|
+
let o = B(n.metadata_json).clock_device_id ?? "", s = Pl(n.rev ?? 0, n.updated_at ?? "", o);
|
|
7427
|
+
if (!Fl(Pl(e.clock_rev, e.clock_updated_at, e.clock_device_id), s)) {
|
|
7428
|
+
i.conflicts++, ru(r, e);
|
|
7408
7429
|
continue;
|
|
7409
7430
|
}
|
|
7410
7431
|
let c = a(e.payload_json);
|
|
@@ -7439,7 +7460,7 @@ function Ql(e, t, n) {
|
|
|
7439
7460
|
} else {
|
|
7440
7461
|
let n = a(e.payload_json);
|
|
7441
7462
|
if (!n) continue;
|
|
7442
|
-
let i =
|
|
7463
|
+
let i = iu(r, null, e.clock_updated_at), o = n.metadata_json ?? {}, s = typeof o == "object" && o ? o : {};
|
|
7443
7464
|
s.clock_device_id = e.clock_device_id, r.insert(G).values({
|
|
7444
7465
|
session_id: i,
|
|
7445
7466
|
kind: n.kind ?? "discovery",
|
|
@@ -7478,9 +7499,9 @@ function Ql(e, t, n) {
|
|
|
7478
7499
|
metadata_json: G.metadata_json
|
|
7479
7500
|
}).from(G).where(k(G.import_key, t)).limit(1).get();
|
|
7480
7501
|
if (n) {
|
|
7481
|
-
let t = B(n.metadata_json), a =
|
|
7482
|
-
if (!
|
|
7483
|
-
i.conflicts++,
|
|
7502
|
+
let t = B(n.metadata_json), a = Pl(n.rev ?? 1, n.updated_at ?? "", String(t.clock_device_id ?? ""));
|
|
7503
|
+
if (!Fl(Pl(e.clock_rev, e.clock_updated_at, e.clock_device_id), a)) {
|
|
7504
|
+
i.conflicts++, ru(r, e);
|
|
7484
7505
|
continue;
|
|
7485
7506
|
}
|
|
7486
7507
|
let o = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -7492,16 +7513,16 @@ function Ql(e, t, n) {
|
|
|
7492
7513
|
}).where(k(G.id, n.id)).run();
|
|
7493
7514
|
}
|
|
7494
7515
|
} else {
|
|
7495
|
-
i.skipped++,
|
|
7516
|
+
i.skipped++, ru(r, e);
|
|
7496
7517
|
continue;
|
|
7497
7518
|
}
|
|
7498
|
-
|
|
7519
|
+
ru(r, e), i.applied++;
|
|
7499
7520
|
} catch (t) {
|
|
7500
7521
|
i.errors.push(`op ${e.op_id}: ${t instanceof Error ? t.message : String(t)}`);
|
|
7501
7522
|
}
|
|
7502
7523
|
})(), i;
|
|
7503
7524
|
}
|
|
7504
|
-
function
|
|
7525
|
+
function ru(e, t) {
|
|
7505
7526
|
e.insert(tn).values({
|
|
7506
7527
|
op_id: t.op_id,
|
|
7507
7528
|
entity_type: t.entity_type,
|
|
@@ -7515,7 +7536,7 @@ function $l(e, t) {
|
|
|
7515
7536
|
created_at: t.created_at
|
|
7516
7537
|
}).onConflictDoNothing().run();
|
|
7517
7538
|
}
|
|
7518
|
-
function
|
|
7539
|
+
function iu(e, t, n) {
|
|
7519
7540
|
if (t != null && e.select({ id: W.id }).from(W).where(k(W.id, t)).get()) return t;
|
|
7520
7541
|
let r = n || (/* @__PURE__ */ new Date()).toISOString(), i = e.insert(W).values({
|
|
7521
7542
|
started_at: r,
|
|
@@ -7528,7 +7549,7 @@ function eu(e, t, n) {
|
|
|
7528
7549
|
}
|
|
7529
7550
|
//#endregion
|
|
7530
7551
|
//#region src/store.ts
|
|
7531
|
-
var
|
|
7552
|
+
var au = new Set([
|
|
7532
7553
|
"discovery",
|
|
7533
7554
|
"change",
|
|
7534
7555
|
"feature",
|
|
@@ -7537,27 +7558,27 @@ var tu = new Set([
|
|
|
7537
7558
|
"decision",
|
|
7538
7559
|
"exploration"
|
|
7539
7560
|
]);
|
|
7540
|
-
function
|
|
7561
|
+
function ou(e) {
|
|
7541
7562
|
let t = e.trim().toLowerCase();
|
|
7542
|
-
if (!
|
|
7563
|
+
if (!au.has(t)) throw Error(`Invalid memory kind "${e}". Allowed: ${[...au].join(", ")}`);
|
|
7543
7564
|
return t;
|
|
7544
7565
|
}
|
|
7545
|
-
function
|
|
7566
|
+
function su() {
|
|
7546
7567
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
7547
7568
|
}
|
|
7548
|
-
function
|
|
7569
|
+
function cu(e) {
|
|
7549
7570
|
return (e.match(/\?/g) ?? []).length;
|
|
7550
7571
|
}
|
|
7551
|
-
function
|
|
7572
|
+
function lu(e, t) {
|
|
7552
7573
|
let n = e.split("?"), r = M.raw(n[0] ?? "");
|
|
7553
7574
|
for (let e = 1; e < n.length; e++) r = M`${r}${t[e - 1]}${M.raw(n[e] ?? "")}`;
|
|
7554
7575
|
return r;
|
|
7555
7576
|
}
|
|
7556
|
-
function
|
|
7577
|
+
function uu(e, t) {
|
|
7557
7578
|
let n = [], r = 0;
|
|
7558
7579
|
for (let i of e) {
|
|
7559
|
-
let e =
|
|
7560
|
-
n.push(
|
|
7580
|
+
let e = cu(i), a = t.slice(r, r + e);
|
|
7581
|
+
n.push(lu(i, a)), r += e;
|
|
7561
7582
|
}
|
|
7562
7583
|
if (r !== t.length) throw Error("filter parameter mismatch while building SQL clauses");
|
|
7563
7584
|
if (n.length === 1) return n[0] ?? M`1=1`;
|
|
@@ -7570,7 +7591,7 @@ function $(e) {
|
|
|
7570
7591
|
let t = e.trim();
|
|
7571
7592
|
return t.length > 0 ? t : null;
|
|
7572
7593
|
}
|
|
7573
|
-
function
|
|
7594
|
+
function du(e) {
|
|
7574
7595
|
if (typeof e != "string" || !e.trim()) return [];
|
|
7575
7596
|
try {
|
|
7576
7597
|
let t = JSON.parse(e);
|
|
@@ -7579,21 +7600,21 @@ function su(e) {
|
|
|
7579
7600
|
return [];
|
|
7580
7601
|
}
|
|
7581
7602
|
}
|
|
7582
|
-
function
|
|
7603
|
+
function fu(e) {
|
|
7583
7604
|
let t = $(e);
|
|
7584
7605
|
if (!t) return "";
|
|
7585
7606
|
let n = t.replace(/\\/g, "/").split("/").filter(Boolean);
|
|
7586
7607
|
return n[n.length - 1] ?? t;
|
|
7587
7608
|
}
|
|
7588
|
-
var
|
|
7589
|
-
function
|
|
7609
|
+
var pu = "Legacy synced peer", mu = "shared:legacy";
|
|
7610
|
+
function hu(e) {
|
|
7590
7611
|
let { metadata_json: t, ...n } = e;
|
|
7591
7612
|
return {
|
|
7592
7613
|
...n,
|
|
7593
7614
|
metadata_json: B(t)
|
|
7594
7615
|
};
|
|
7595
7616
|
}
|
|
7596
|
-
var
|
|
7617
|
+
var gu = class {
|
|
7597
7618
|
db;
|
|
7598
7619
|
dbPath;
|
|
7599
7620
|
deviceId;
|
|
@@ -7626,7 +7647,7 @@ var fu = class {
|
|
|
7626
7647
|
enqueueVectorWrite(e, t, n) {
|
|
7627
7648
|
if (this.db.inTransaction) return;
|
|
7628
7649
|
let r = null;
|
|
7629
|
-
r =
|
|
7650
|
+
r = Fo(this.db, e, t, n).catch(() => {}).finally(() => {
|
|
7630
7651
|
r && this.pendingVectorWrites.delete(r);
|
|
7631
7652
|
}), this.pendingVectorWrites.add(r);
|
|
7632
7653
|
}
|
|
@@ -7635,10 +7656,10 @@ var fu = class {
|
|
|
7635
7656
|
}
|
|
7636
7657
|
get(e) {
|
|
7637
7658
|
let t = this.d.select().from(G).where(k(G.id, e)).get();
|
|
7638
|
-
return t ?
|
|
7659
|
+
return t ? hu(t) : null;
|
|
7639
7660
|
}
|
|
7640
7661
|
startSession(e) {
|
|
7641
|
-
let t =
|
|
7662
|
+
let t = su(), n = this.d.insert(W).values({
|
|
7642
7663
|
started_at: t,
|
|
7643
7664
|
cwd: e.cwd ?? process.cwd(),
|
|
7644
7665
|
project: e.project ?? null,
|
|
@@ -7652,7 +7673,7 @@ var fu = class {
|
|
|
7652
7673
|
return n;
|
|
7653
7674
|
}
|
|
7654
7675
|
endSession(e, t) {
|
|
7655
|
-
let n =
|
|
7676
|
+
let n = su();
|
|
7656
7677
|
if (t) {
|
|
7657
7678
|
let r = {
|
|
7658
7679
|
...B(this.d.select({ metadata_json: W.metadata_json }).from(W).where(k(W.id, e)).get()?.metadata_json),
|
|
@@ -7665,7 +7686,7 @@ var fu = class {
|
|
|
7665
7686
|
} else this.d.update(W).set({ ended_at: n }).where(k(W.id, e)).run();
|
|
7666
7687
|
}
|
|
7667
7688
|
remember(e, t, n, r, i = .5, o, s) {
|
|
7668
|
-
let c =
|
|
7689
|
+
let c = ou(t), l = su(), u = o ? [...new Set(o)].sort().join(" ") : "", d = { ...s ?? {} };
|
|
7669
7690
|
d.clock_device_id ??= this.deviceId;
|
|
7670
7691
|
let f = d.import_key || a();
|
|
7671
7692
|
d.import_key = f;
|
|
@@ -7702,7 +7723,7 @@ var fu = class {
|
|
|
7702
7723
|
}).returning({ id: G.id }).all()[0]?.id;
|
|
7703
7724
|
if (S == null) throw Error("memory insert returned no id");
|
|
7704
7725
|
try {
|
|
7705
|
-
|
|
7726
|
+
Il(this.db, {
|
|
7706
7727
|
memoryId: S,
|
|
7707
7728
|
opType: "upsert",
|
|
7708
7729
|
deviceId: this.deviceId
|
|
@@ -7750,7 +7771,7 @@ var fu = class {
|
|
|
7750
7771
|
if (!t) return;
|
|
7751
7772
|
let n = B(t.metadata_json);
|
|
7752
7773
|
n.clock_device_id = this.deviceId;
|
|
7753
|
-
let r =
|
|
7774
|
+
let r = su(), i = (t.rev ?? 0) + 1;
|
|
7754
7775
|
this.d.update(G).set({
|
|
7755
7776
|
active: 0,
|
|
7756
7777
|
deleted_at: r,
|
|
@@ -7759,7 +7780,7 @@ var fu = class {
|
|
|
7759
7780
|
rev: i
|
|
7760
7781
|
}).where(k(G.id, e)).run();
|
|
7761
7782
|
try {
|
|
7762
|
-
|
|
7783
|
+
Il(this.db, {
|
|
7763
7784
|
memoryId: e,
|
|
7764
7785
|
opType: "delete",
|
|
7765
7786
|
deviceId: this.deviceId
|
|
@@ -7768,20 +7789,20 @@ var fu = class {
|
|
|
7768
7789
|
}).immediate();
|
|
7769
7790
|
}
|
|
7770
7791
|
recent(e = 10, t, n = 0) {
|
|
7771
|
-
let r = ["memory_items.active = 1"], i =
|
|
7792
|
+
let r = ["memory_items.active = 1"], i = Da(t), a = uu([...r, ...i.clauses], i.params), o = i.joinSessions ? M.raw("memory_items JOIN sessions ON sessions.id = memory_items.session_id") : M.raw("memory_items");
|
|
7772
7793
|
return this.d.all(M`SELECT memory_items.* FROM ${o}
|
|
7773
7794
|
WHERE ${a}
|
|
7774
7795
|
ORDER BY created_at DESC
|
|
7775
|
-
LIMIT ${e} OFFSET ${Math.max(n, 0)}`).map((e) =>
|
|
7796
|
+
LIMIT ${e} OFFSET ${Math.max(n, 0)}`).map((e) => hu(e));
|
|
7776
7797
|
}
|
|
7777
7798
|
recentByKinds(e, t = 10, n, r = 0) {
|
|
7778
7799
|
let i = e.filter((e) => e.length > 0);
|
|
7779
7800
|
if (i.length === 0) return [];
|
|
7780
|
-
let a = ["memory_items.active = 1", `memory_items.kind IN (${i.map(() => "?").join(", ")})`], o =
|
|
7801
|
+
let a = ["memory_items.active = 1", `memory_items.kind IN (${i.map(() => "?").join(", ")})`], o = Da(n), s = uu([...a, ...o.clauses], [...i, ...o.params]), c = o.joinSessions ? M.raw("memory_items JOIN sessions ON sessions.id = memory_items.session_id") : M.raw("memory_items");
|
|
7781
7802
|
return this.d.all(M`SELECT memory_items.* FROM ${c}
|
|
7782
7803
|
WHERE ${s}
|
|
7783
7804
|
ORDER BY created_at DESC
|
|
7784
|
-
LIMIT ${t} OFFSET ${Math.max(r, 0)}`).map((e) =>
|
|
7805
|
+
LIMIT ${t} OFFSET ${Math.max(r, 0)}`).map((e) => hu(e));
|
|
7785
7806
|
}
|
|
7786
7807
|
stats() {
|
|
7787
7808
|
let e = (e) => this.d.select({ c: M`COUNT(*)` }).from(e).get()?.c ?? 0, t = e(G), n = this.d.select({ c: M`COUNT(*)` }).from(G).where(k(G.active, 1)).get()?.c ?? 0, r = e(W), i = e(Xt), a = e(K), o = 0;
|
|
@@ -7846,7 +7867,7 @@ var fu = class {
|
|
|
7846
7867
|
if (!this.memoryOwnedBySelf(t)) throw Error("memory not owned by this device");
|
|
7847
7868
|
let r = $(t.actor_id) ?? this.actorId, i = n === "shared" ? "shared" : "personal", a = n === "shared" && t.workspace_id?.startsWith("shared:") ? t.workspace_id : i === "personal" ? `personal:${r}` : "shared:default", o = B(t.metadata_json);
|
|
7848
7869
|
o.visibility = n, o.workspace_kind = i, o.workspace_id = a, o.clock_device_id = this.deviceId;
|
|
7849
|
-
let s =
|
|
7870
|
+
let s = su(), c = (t.rev ?? 0) + 1;
|
|
7850
7871
|
this.d.update(G).set({
|
|
7851
7872
|
visibility: n,
|
|
7852
7873
|
workspace_kind: i,
|
|
@@ -7856,7 +7877,7 @@ var fu = class {
|
|
|
7856
7877
|
rev: c
|
|
7857
7878
|
}).where(k(G.id, e)).run();
|
|
7858
7879
|
try {
|
|
7859
|
-
|
|
7880
|
+
Il(this.db, {
|
|
7860
7881
|
memoryId: e,
|
|
7861
7882
|
opType: "upsert",
|
|
7862
7883
|
deviceId: this.deviceId
|
|
@@ -7868,19 +7889,19 @@ var fu = class {
|
|
|
7868
7889
|
}).immediate();
|
|
7869
7890
|
}
|
|
7870
7891
|
search(e, t = 10, n) {
|
|
7871
|
-
return
|
|
7892
|
+
return Oc(this, e, t, n);
|
|
7872
7893
|
}
|
|
7873
7894
|
timeline(e, t, n = 3, r = 3, i) {
|
|
7874
|
-
return
|
|
7895
|
+
return Ac(this, e, t, n, r, i);
|
|
7875
7896
|
}
|
|
7876
7897
|
explain(e, t, n = 10, r, i) {
|
|
7877
|
-
return
|
|
7898
|
+
return Ic(this, e, t, n, r, i);
|
|
7878
7899
|
}
|
|
7879
7900
|
buildMemoryPack(e, t, n, r) {
|
|
7880
|
-
return
|
|
7901
|
+
return _l(this, e, t, n ?? null, r);
|
|
7881
7902
|
}
|
|
7882
7903
|
async buildMemoryPackAsync(e, t, n, r) {
|
|
7883
|
-
return
|
|
7904
|
+
return vl(this, e, t, n ?? null, r);
|
|
7884
7905
|
}
|
|
7885
7906
|
normalizeStreamIdentity(e, t) {
|
|
7886
7907
|
let n = e.trim().toLowerCase() || "opencode", r = t.trim();
|
|
@@ -8064,7 +8085,7 @@ var fu = class {
|
|
|
8064
8085
|
}).run();
|
|
8065
8086
|
}
|
|
8066
8087
|
updateRawEventIngestStats(e, t, n, r) {
|
|
8067
|
-
let i =
|
|
8088
|
+
let i = su(), a = t + n + r;
|
|
8068
8089
|
this.d.insert(an).values({
|
|
8069
8090
|
created_at: i,
|
|
8070
8091
|
inserted_events: e,
|
|
@@ -8097,7 +8118,7 @@ var fu = class {
|
|
|
8097
8118
|
if (!e.eventType.trim()) throw Error("event_type is required");
|
|
8098
8119
|
let [t, n] = this.normalizeStreamIdentity(e.source ?? "opencode", e.opencodeSessionId);
|
|
8099
8120
|
return this.db.transaction(() => {
|
|
8100
|
-
let r =
|
|
8121
|
+
let r = su();
|
|
8101
8122
|
if (this.d.select({ one: M`1` }).from(K).where(D(k(K.source, t), k(K.stream_id, n), k(K.event_id, e.eventId))).get() != null) return this.updateRawEventIngestStats(0, 0, 1, 0), !1;
|
|
8102
8123
|
this.d.select({ one: M`1` }).from(q).where(D(k(q.source, t), k(q.stream_id, n))).get() ?? this.d.insert(q).values({
|
|
8103
8124
|
opencode_session_id: n,
|
|
@@ -8129,7 +8150,7 @@ var fu = class {
|
|
|
8129
8150
|
if (!e.trim()) throw Error("opencode_session_id is required");
|
|
8130
8151
|
let [n, r] = this.normalizeStreamIdentity("opencode", e);
|
|
8131
8152
|
return this.db.transaction(() => {
|
|
8132
|
-
let e =
|
|
8153
|
+
let e = su();
|
|
8133
8154
|
this.d.select({ one: M`1` }).from(q).where(D(k(q.source, n), k(q.stream_id, r))).get() ?? this.d.insert(q).values({
|
|
8134
8155
|
opencode_session_id: r,
|
|
8135
8156
|
source: n,
|
|
@@ -8198,7 +8219,7 @@ var fu = class {
|
|
|
8198
8219
|
})();
|
|
8199
8220
|
}
|
|
8200
8221
|
updateRawEventSessionMeta(e) {
|
|
8201
|
-
let [t, n] = this.normalizeStreamIdentity(e.source ?? "opencode", e.opencodeSessionId), r =
|
|
8222
|
+
let [t, n] = this.normalizeStreamIdentity(e.source ?? "opencode", e.opencodeSessionId), r = su(), i = q;
|
|
8202
8223
|
this.d.insert(i).values({
|
|
8203
8224
|
opencode_session_id: n,
|
|
8204
8225
|
source: t,
|
|
@@ -8298,8 +8319,8 @@ var fu = class {
|
|
|
8298
8319
|
${G.actor_id} IS NULL
|
|
8299
8320
|
OR TRIM(${G.actor_id}) = ''
|
|
8300
8321
|
OR ${G.actor_id} LIKE 'legacy-sync:%'
|
|
8301
|
-
OR ${G.actor_display_name} = ${
|
|
8302
|
-
OR ${G.workspace_id} = ${
|
|
8322
|
+
OR ${G.actor_display_name} = ${pu}
|
|
8323
|
+
OR ${G.workspace_id} = ${mu}
|
|
8303
8324
|
OR ${G.trust_state} = 'legacy_unknown'
|
|
8304
8325
|
)
|
|
8305
8326
|
)`, M`${G.origin_device_id} != ${this.deviceId}`, M`${G.origin_device_id} NOT IN (
|
|
@@ -8313,13 +8334,13 @@ var fu = class {
|
|
|
8313
8334
|
}));
|
|
8314
8335
|
}
|
|
8315
8336
|
effectiveSyncProjectFilters(e) {
|
|
8316
|
-
let t = et(), n =
|
|
8337
|
+
let t = et(), n = du(JSON.stringify(t.sync_projects_include ?? [])), r = du(JSON.stringify(t.sync_projects_exclude ?? []));
|
|
8317
8338
|
if (e) {
|
|
8318
8339
|
let t = this.d.select({
|
|
8319
8340
|
projects_include_json: Y.projects_include_json,
|
|
8320
8341
|
projects_exclude_json: Y.projects_exclude_json
|
|
8321
8342
|
}).from(Y).where(k(Y.peer_device_id, e)).limit(1).get();
|
|
8322
|
-
t && (t.projects_include_json != null && (n =
|
|
8343
|
+
t && (t.projects_include_json != null && (n = du(t.projects_include_json)), t.projects_exclude_json != null && (r = du(t.projects_exclude_json)));
|
|
8323
8344
|
}
|
|
8324
8345
|
return {
|
|
8325
8346
|
include: n,
|
|
@@ -8327,7 +8348,7 @@ var fu = class {
|
|
|
8327
8348
|
};
|
|
8328
8349
|
}
|
|
8329
8350
|
syncProjectAllowed(e, t) {
|
|
8330
|
-
let { include: n, exclude: r } = this.effectiveSyncProjectFilters(t), i = $(e), a =
|
|
8351
|
+
let { include: n, exclude: r } = this.effectiveSyncProjectFilters(t), i = $(e), a = fu(i);
|
|
8331
8352
|
return !(n.length > 0 && !n.some((e) => e === i || e === a) || r.some((e) => e === i || e === a));
|
|
8332
8353
|
}
|
|
8333
8354
|
sharingReviewSummary(e) {
|
|
@@ -8347,7 +8368,7 @@ var fu = class {
|
|
|
8347
8368
|
if (!n || !r || r === this.actorId) continue;
|
|
8348
8369
|
let i = $(e.project);
|
|
8349
8370
|
if (t) {
|
|
8350
|
-
let e =
|
|
8371
|
+
let e = fu(t), n = fu(i);
|
|
8351
8372
|
if (i !== t && n !== e) continue;
|
|
8352
8373
|
}
|
|
8353
8374
|
if (!this.syncProjectAllowed(i, n)) continue;
|
|
@@ -8371,11 +8392,11 @@ var fu = class {
|
|
|
8371
8392
|
close() {
|
|
8372
8393
|
this.db.close();
|
|
8373
8394
|
}
|
|
8374
|
-
},
|
|
8375
|
-
function
|
|
8395
|
+
}, _u = "_codemem._tcp.local.";
|
|
8396
|
+
function vu(e) {
|
|
8376
8397
|
return e.mdns.length === 0 ? ji(e.stored, []) : ji(e.mdns, e.stored);
|
|
8377
8398
|
}
|
|
8378
|
-
function
|
|
8399
|
+
function yu(e, t) {
|
|
8379
8400
|
let n = N(e, { schema: U }).select({ addresses_json: Y.addresses_json }).from(Y).where(k(Y.peer_device_id, t)).get();
|
|
8380
8401
|
if (!n?.addresses_json) return [];
|
|
8381
8402
|
try {
|
|
@@ -8385,8 +8406,8 @@ function hu(e, t) {
|
|
|
8385
8406
|
return [];
|
|
8386
8407
|
}
|
|
8387
8408
|
}
|
|
8388
|
-
function
|
|
8389
|
-
let i = ji(
|
|
8409
|
+
function bu(e, t, n, r) {
|
|
8410
|
+
let i = ji(yu(e, t), n), a = (/* @__PURE__ */ new Date()).toISOString(), o = JSON.stringify(i);
|
|
8390
8411
|
return N(e, { schema: U }).insert(Y).values({
|
|
8391
8412
|
peer_device_id: t,
|
|
8392
8413
|
name: r?.name ?? null,
|
|
@@ -8406,7 +8427,7 @@ function gu(e, t, n, r) {
|
|
|
8406
8427
|
}
|
|
8407
8428
|
}).run(), i;
|
|
8408
8429
|
}
|
|
8409
|
-
function
|
|
8430
|
+
function xu(e, t, n) {
|
|
8410
8431
|
let r = N(e, { schema: U }), i = (/* @__PURE__ */ new Date()).toISOString();
|
|
8411
8432
|
r.insert(Z).values({
|
|
8412
8433
|
peer_device_id: t,
|
|
@@ -8421,32 +8442,32 @@ function _u(e, t, n) {
|
|
|
8421
8442
|
last_error: null
|
|
8422
8443
|
}).where(k(Y.peer_device_id, t)).run() : r.update(Y).set({ last_error: n.error ?? null }).where(k(Y.peer_device_id, t)).run();
|
|
8423
8444
|
}
|
|
8424
|
-
function
|
|
8425
|
-
let r =
|
|
8445
|
+
function Su(e, t, n) {
|
|
8446
|
+
let r = yu(e, t), i = ki(n ?? ""), a = r;
|
|
8426
8447
|
return i && (a = [i, ...r.filter((e) => ki(e) !== i)], N(e, { schema: U }).update(Y).set({
|
|
8427
8448
|
addresses_json: JSON.stringify(a),
|
|
8428
8449
|
last_sync_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
8429
8450
|
last_error: null
|
|
8430
8451
|
}).where(k(Y.peer_device_id, t)).run()), a;
|
|
8431
8452
|
}
|
|
8432
|
-
function
|
|
8453
|
+
function Cu(e, t, n) {
|
|
8433
8454
|
let r = n.include === null ? null : JSON.stringify(n.include), i = n.exclude === null ? null : JSON.stringify(n.exclude);
|
|
8434
8455
|
N(e, { schema: U }).update(Y).set({
|
|
8435
8456
|
projects_include_json: r,
|
|
8436
8457
|
projects_exclude_json: i
|
|
8437
8458
|
}).where(k(Y.peer_device_id, t)).run();
|
|
8438
8459
|
}
|
|
8439
|
-
function
|
|
8460
|
+
function wu(e, t, n) {
|
|
8440
8461
|
N(e, { schema: U }).update(Y).set({ claimed_local_actor: n ? 1 : 0 }).where(k(Y.peer_device_id, t)).run();
|
|
8441
8462
|
}
|
|
8442
|
-
function
|
|
8463
|
+
function Tu(e) {
|
|
8443
8464
|
try {
|
|
8444
8465
|
return fe("which", [e], { stdio: "pipe" }), !0;
|
|
8445
8466
|
} catch {
|
|
8446
8467
|
return !1;
|
|
8447
8468
|
}
|
|
8448
8469
|
}
|
|
8449
|
-
function
|
|
8470
|
+
function Eu(e, t = 1200) {
|
|
8450
8471
|
try {
|
|
8451
8472
|
return fe("dns-sd", e, {
|
|
8452
8473
|
encoding: "utf8",
|
|
@@ -8465,8 +8486,8 @@ function Su(e, t = 1200) {
|
|
|
8465
8486
|
return "";
|
|
8466
8487
|
}
|
|
8467
8488
|
}
|
|
8468
|
-
function
|
|
8469
|
-
let e =
|
|
8489
|
+
function Du() {
|
|
8490
|
+
let e = Eu([
|
|
8470
8491
|
"-B",
|
|
8471
8492
|
"_codemem._tcp",
|
|
8472
8493
|
"local."
|
|
@@ -8485,8 +8506,8 @@ function Cu() {
|
|
|
8485
8506
|
}
|
|
8486
8507
|
return [...t];
|
|
8487
8508
|
}
|
|
8488
|
-
function
|
|
8489
|
-
let t =
|
|
8509
|
+
function Ou(e) {
|
|
8510
|
+
let t = Eu([
|
|
8490
8511
|
"-L",
|
|
8491
8512
|
e,
|
|
8492
8513
|
"_codemem._tcp",
|
|
@@ -8503,12 +8524,12 @@ function wu(e) {
|
|
|
8503
8524
|
properties: s
|
|
8504
8525
|
};
|
|
8505
8526
|
}
|
|
8506
|
-
function
|
|
8527
|
+
function ku() {
|
|
8507
8528
|
let e = process.env.CODEMEM_SYNC_MDNS;
|
|
8508
8529
|
return e ? e === "1" || e.toLowerCase() === "true" : !1;
|
|
8509
8530
|
}
|
|
8510
|
-
function
|
|
8511
|
-
if (!
|
|
8531
|
+
function Au(e, t) {
|
|
8532
|
+
if (!ku() || process.platform !== "darwin" || !Tu("dns-sd")) return { close() {} };
|
|
8512
8533
|
let n = pe("dns-sd", [
|
|
8513
8534
|
"-R",
|
|
8514
8535
|
`codemem-${e.slice(0, 12)}`,
|
|
@@ -8526,18 +8547,18 @@ function Eu(e, t) {
|
|
|
8526
8547
|
} catch {}
|
|
8527
8548
|
} };
|
|
8528
8549
|
}
|
|
8529
|
-
function
|
|
8530
|
-
if (!
|
|
8531
|
-
let e =
|
|
8550
|
+
function ju() {
|
|
8551
|
+
if (!ku() || process.platform !== "darwin" || !Tu("dns-sd")) return [];
|
|
8552
|
+
let e = Du();
|
|
8532
8553
|
if (e.length === 0) return [];
|
|
8533
8554
|
let t = [];
|
|
8534
8555
|
for (let n of e) {
|
|
8535
|
-
let e =
|
|
8556
|
+
let e = Ou(n);
|
|
8536
8557
|
e && t.push(e);
|
|
8537
8558
|
}
|
|
8538
8559
|
return t;
|
|
8539
8560
|
}
|
|
8540
|
-
function
|
|
8561
|
+
function Mu(e, t) {
|
|
8541
8562
|
let n = [];
|
|
8542
8563
|
for (let r of t) {
|
|
8543
8564
|
let t = r.properties ?? {}, i = t.device_id ?? t.device_id;
|
|
@@ -8551,19 +8572,19 @@ function Ou(e, t) {
|
|
|
8551
8572
|
}
|
|
8552
8573
|
//#endregion
|
|
8553
8574
|
//#region src/sync-pass.ts
|
|
8554
|
-
var
|
|
8555
|
-
function
|
|
8575
|
+
var Nu = 1048576, Pu = 200;
|
|
8576
|
+
function Fu(e, t) {
|
|
8556
8577
|
return !t || !t.includes("|") ? !1 : e ? t > e : !0;
|
|
8557
8578
|
}
|
|
8558
|
-
function
|
|
8579
|
+
function Iu(e) {
|
|
8559
8580
|
if (!e) return null;
|
|
8560
8581
|
let t = e.error, n = e.reason;
|
|
8561
8582
|
return typeof t == "string" && typeof n == "string" ? `${t}:${n}` : typeof t == "string" ? t : null;
|
|
8562
8583
|
}
|
|
8563
|
-
function
|
|
8584
|
+
function Lu(e) {
|
|
8564
8585
|
return e.length === 0 ? null : `all addresses failed | ${e.map((e) => `${e.address}: ${e.error}`).join(" || ")}`;
|
|
8565
8586
|
}
|
|
8566
|
-
function
|
|
8587
|
+
function Ru(e, t, n) {
|
|
8567
8588
|
let r = N(e, { schema: U }), i = (/* @__PURE__ */ new Date()).toISOString();
|
|
8568
8589
|
r.insert(Z).values({
|
|
8569
8590
|
peer_device_id: t,
|
|
@@ -8575,7 +8596,7 @@ function Pu(e, t, n) {
|
|
|
8575
8596
|
error: n.error ?? null
|
|
8576
8597
|
}).run();
|
|
8577
8598
|
}
|
|
8578
|
-
function
|
|
8599
|
+
function zu(e, t) {
|
|
8579
8600
|
let n = N(e, { schema: U }), r = (/* @__PURE__ */ new Date()).toISOString();
|
|
8580
8601
|
n.update(Y).set({
|
|
8581
8602
|
last_sync_at: r,
|
|
@@ -8583,7 +8604,7 @@ function Fu(e, t) {
|
|
|
8583
8604
|
last_error: null
|
|
8584
8605
|
}).where(k(Y.peer_device_id, t)).run();
|
|
8585
8606
|
}
|
|
8586
|
-
function
|
|
8607
|
+
function Bu(e, t, n, r) {
|
|
8587
8608
|
let i = N(e, { schema: U }), { replicationOps: a } = U, o;
|
|
8588
8609
|
if (t) {
|
|
8589
8610
|
let e = t.indexOf("|"), s = e >= 0 ? t.slice(0, e) : t, c = e >= 0 ? t.slice(e + 1) : "";
|
|
@@ -8595,8 +8616,8 @@ function Iu(e, t, n, r) {
|
|
|
8595
8616
|
let c = `${s.created_at}|${s.op_id}`;
|
|
8596
8617
|
return [o, c];
|
|
8597
8618
|
}
|
|
8598
|
-
var
|
|
8599
|
-
async function
|
|
8619
|
+
var Vu = 8;
|
|
8620
|
+
async function Hu(e, t, n, r, i = 0) {
|
|
8600
8621
|
if (n.length === 0) return;
|
|
8601
8622
|
let a = { ops: n }, o = Buffer.from(JSON.stringify(a), "utf-8"), [s, c] = await En("POST", e, {
|
|
8602
8623
|
headers: gi({
|
|
@@ -8610,20 +8631,20 @@ async function Ru(e, t, n, r, i = 0) {
|
|
|
8610
8631
|
bodyBytes: o
|
|
8611
8632
|
});
|
|
8612
8633
|
if (s === 200 && c != null) return;
|
|
8613
|
-
let l =
|
|
8614
|
-
if (s === 413 && n.length > 1 && i <
|
|
8634
|
+
let l = Iu(c);
|
|
8635
|
+
if (s === 413 && n.length > 1 && i < Vu && (l === "payload_too_large" || l === "too_many_ops")) {
|
|
8615
8636
|
let a = Math.floor(n.length / 2);
|
|
8616
|
-
await
|
|
8637
|
+
await Hu(e, t, n.slice(0, a), r, i + 1), await Hu(e, t, n.slice(a), r, i + 1);
|
|
8617
8638
|
return;
|
|
8618
8639
|
}
|
|
8619
8640
|
let u = l ? ` (${s}: ${l})` : ` (${s})`;
|
|
8620
8641
|
throw Error(`peer ops push failed${u}`);
|
|
8621
8642
|
}
|
|
8622
|
-
function
|
|
8623
|
-
|
|
8643
|
+
function Uu(e) {
|
|
8644
|
+
Ql(e, 2e3), $l(e, 200);
|
|
8624
8645
|
}
|
|
8625
|
-
async function
|
|
8626
|
-
let i = r?.limit ??
|
|
8646
|
+
async function Wu(e, t, n, r) {
|
|
8647
|
+
let i = r?.limit ?? Pu, a = r?.keysDir, o = N(e, { schema: U }).select({ pinned_fingerprint: Y.pinned_fingerprint }).from(Y).where(k(Y.peer_device_id, t)).get()?.pinned_fingerprint ?? "";
|
|
8627
8648
|
if (!o) return {
|
|
8628
8649
|
ok: !1,
|
|
8629
8650
|
error: "peer not pinned",
|
|
@@ -8631,12 +8652,12 @@ async function Bu(e, t, n, r) {
|
|
|
8631
8652
|
opsOut: 0,
|
|
8632
8653
|
addressErrors: []
|
|
8633
8654
|
};
|
|
8634
|
-
let [s, c] =
|
|
8655
|
+
let [s, c] = Al(e, t), l;
|
|
8635
8656
|
try {
|
|
8636
8657
|
[l] = qn(e, { keysDir: a });
|
|
8637
8658
|
} catch (n) {
|
|
8638
8659
|
let r = `device identity unavailable: ${n instanceof Error ? n.message.trim() || n.constructor.name : "unknown"}`;
|
|
8639
|
-
return
|
|
8660
|
+
return Ru(e, t, {
|
|
8640
8661
|
ok: !1,
|
|
8641
8662
|
error: r
|
|
8642
8663
|
}), {
|
|
@@ -8661,7 +8682,7 @@ async function Bu(e, t, n, r) {
|
|
|
8661
8682
|
keysDir: a
|
|
8662
8683
|
}) });
|
|
8663
8684
|
if (u !== 200 || !d) {
|
|
8664
|
-
let e =
|
|
8685
|
+
let e = Iu(d), t = e ? ` (${u}: ${e})` : ` (${u})`;
|
|
8665
8686
|
throw Error(`peer status failed${t}`);
|
|
8666
8687
|
}
|
|
8667
8688
|
if (d.fingerprint !== o) throw Error("peer fingerprint mismatch");
|
|
@@ -8676,19 +8697,19 @@ async function Bu(e, t, n, r) {
|
|
|
8676
8697
|
keysDir: a
|
|
8677
8698
|
}) });
|
|
8678
8699
|
if (p !== 200 || m == null) {
|
|
8679
|
-
let e =
|
|
8700
|
+
let e = Iu(m), t = e ? ` (${p}: ${e})` : ` (${p})`;
|
|
8680
8701
|
throw Error(`peer ops fetch failed${t}`);
|
|
8681
8702
|
}
|
|
8682
8703
|
if (!Array.isArray(m.ops)) throw Error("invalid ops response");
|
|
8683
|
-
let [h, g] =
|
|
8684
|
-
|
|
8685
|
-
let [y, b] =
|
|
8704
|
+
let [h, g] = Yl(e, Nl(m), t), _ = nu(e, h, l), v = g || (typeof m.next_cursor == "string" ? m.next_cursor.trim() : "");
|
|
8705
|
+
Fu(s, v) && (jl(e, t, { lastApplied: v }), s = v);
|
|
8706
|
+
let [y, b] = Bu(e, c, l, i), [x, S] = Xl(e, y, t), C = `${n}/v1/ops`;
|
|
8686
8707
|
if (x.length > 0) {
|
|
8687
|
-
let e =
|
|
8688
|
-
for (let t of e) await
|
|
8708
|
+
let e = kl(x, Nu);
|
|
8709
|
+
for (let t of e) await Hu(C, l, t, a);
|
|
8689
8710
|
}
|
|
8690
8711
|
let w = S ?? b;
|
|
8691
|
-
return w &&
|
|
8712
|
+
return w && Fu(c, w) && (jl(e, t, { lastAcked: w }), c = w), zu(e, t), Ru(e, t, {
|
|
8692
8713
|
ok: !0,
|
|
8693
8714
|
opsIn: _.applied,
|
|
8694
8715
|
opsOut: x.length
|
|
@@ -8708,8 +8729,8 @@ async function Bu(e, t, n, r) {
|
|
|
8708
8729
|
}
|
|
8709
8730
|
}
|
|
8710
8731
|
}
|
|
8711
|
-
let f =
|
|
8712
|
-
return d || (f = "no dialable peer addresses"), f ||= "sync failed without diagnostic detail",
|
|
8732
|
+
let f = Lu(u);
|
|
8733
|
+
return d || (f = "no dialable peer addresses"), f ||= "sync failed without diagnostic detail", Ru(e, t, {
|
|
8713
8734
|
ok: !1,
|
|
8714
8735
|
error: f
|
|
8715
8736
|
}), {
|
|
@@ -8720,15 +8741,15 @@ async function Bu(e, t, n, r) {
|
|
|
8720
8741
|
addressErrors: u
|
|
8721
8742
|
};
|
|
8722
8743
|
}
|
|
8723
|
-
async function
|
|
8744
|
+
async function Gu(e, t, n) {
|
|
8724
8745
|
let r = N(e, { schema: U }).select({ addresses_json: Y.addresses_json }).from(Y).where(k(Y.peer_device_id, t)).get(), i = [];
|
|
8725
8746
|
if (r?.addresses_json) try {
|
|
8726
8747
|
let e = JSON.parse(r.addresses_json);
|
|
8727
8748
|
Array.isArray(e) && (i = e.filter((e) => typeof e == "string"));
|
|
8728
8749
|
} catch {}
|
|
8729
|
-
return
|
|
8750
|
+
return Wu(e, t, i, n);
|
|
8730
8751
|
}
|
|
8731
|
-
var
|
|
8752
|
+
var Ku = [
|
|
8732
8753
|
"no route to host",
|
|
8733
8754
|
"connection refused",
|
|
8734
8755
|
"network is unreachable",
|
|
@@ -8739,33 +8760,33 @@ var Hu = [
|
|
|
8739
8760
|
"errno 61",
|
|
8740
8761
|
"errno 60",
|
|
8741
8762
|
"errno 111"
|
|
8742
|
-
],
|
|
8743
|
-
function
|
|
8763
|
+
], qu = 120, Ju = 1800;
|
|
8764
|
+
function Yu(e) {
|
|
8744
8765
|
if (!e) return !1;
|
|
8745
8766
|
let t = e.toLowerCase();
|
|
8746
|
-
return
|
|
8767
|
+
return Ku.some((e) => t.includes(e));
|
|
8747
8768
|
}
|
|
8748
|
-
function
|
|
8769
|
+
function Xu(e, t, n = 10) {
|
|
8749
8770
|
let r = N(e, { schema: U }).select({
|
|
8750
8771
|
ok: Z.ok,
|
|
8751
8772
|
error: Z.error
|
|
8752
8773
|
}).from(Z).where(k(Z.peer_device_id, t)).orderBy(O(Z.started_at)).limit(n).all(), i = 0;
|
|
8753
8774
|
for (let e of r) {
|
|
8754
8775
|
if (e.ok) break;
|
|
8755
|
-
if (
|
|
8776
|
+
if (Yu(e.error)) i++;
|
|
8756
8777
|
else break;
|
|
8757
8778
|
}
|
|
8758
8779
|
return i;
|
|
8759
8780
|
}
|
|
8760
|
-
function
|
|
8781
|
+
function Zu(e) {
|
|
8761
8782
|
if (e <= 1) return 0;
|
|
8762
8783
|
let t = Math.min(e - 1, 8);
|
|
8763
|
-
return Math.min(
|
|
8784
|
+
return Math.min(qu * 2 ** (t - 1), Ju) * (.5 + Math.random() * .5);
|
|
8764
8785
|
}
|
|
8765
|
-
function
|
|
8766
|
-
let n =
|
|
8786
|
+
function Qu(e, t) {
|
|
8787
|
+
let n = Xu(e, t);
|
|
8767
8788
|
if (n < 2) return !1;
|
|
8768
|
-
let r =
|
|
8789
|
+
let r = Zu(n);
|
|
8769
8790
|
if (r <= 0) return !1;
|
|
8770
8791
|
let i = N(e, { schema: U }).select({ started_at: Z.started_at }).from(Z).where(k(Z.peer_device_id, t)).orderBy(O(Z.started_at)).limit(1).get();
|
|
8771
8792
|
if (!i?.started_at) return !1;
|
|
@@ -8778,7 +8799,7 @@ function Ju(e, t) {
|
|
|
8778
8799
|
}
|
|
8779
8800
|
//#endregion
|
|
8780
8801
|
//#region src/sync-daemon.ts
|
|
8781
|
-
function
|
|
8802
|
+
function $u(e) {
|
|
8782
8803
|
let t = N(e, { schema: U }), n = (/* @__PURE__ */ new Date()).toISOString();
|
|
8783
8804
|
t.insert(Q).values({
|
|
8784
8805
|
id: 1,
|
|
@@ -8788,7 +8809,7 @@ function Yu(e) {
|
|
|
8788
8809
|
set: { last_ok_at: M`excluded.last_ok_at` }
|
|
8789
8810
|
}).run();
|
|
8790
8811
|
}
|
|
8791
|
-
function
|
|
8812
|
+
function ed(e, t, n) {
|
|
8792
8813
|
let r = N(e, { schema: U }), i = (/* @__PURE__ */ new Date()).toISOString();
|
|
8793
8814
|
r.insert(Q).values({
|
|
8794
8815
|
id: 1,
|
|
@@ -8804,12 +8825,12 @@ function Xu(e, t, n) {
|
|
|
8804
8825
|
}
|
|
8805
8826
|
}).run();
|
|
8806
8827
|
}
|
|
8807
|
-
async function
|
|
8808
|
-
|
|
8828
|
+
async function td(e, t) {
|
|
8829
|
+
Uu(e);
|
|
8809
8830
|
let n = N(e, { schema: U }).select({ peer_device_id: Y.peer_device_id }).from(Y).all(), r = [];
|
|
8810
8831
|
for (let i of n) {
|
|
8811
8832
|
let n = i.peer_device_id;
|
|
8812
|
-
if (
|
|
8833
|
+
if (Qu(e, n)) {
|
|
8813
8834
|
r.push({
|
|
8814
8835
|
ok: !1,
|
|
8815
8836
|
skipped: !0,
|
|
@@ -8817,7 +8838,7 @@ async function Zu(e, t) {
|
|
|
8817
8838
|
});
|
|
8818
8839
|
continue;
|
|
8819
8840
|
}
|
|
8820
|
-
let a = await
|
|
8841
|
+
let a = await Gu(e, n, { keysDir: t });
|
|
8821
8842
|
r.push({
|
|
8822
8843
|
ok: a.ok,
|
|
8823
8844
|
error: a.error,
|
|
@@ -8827,11 +8848,11 @@ async function Zu(e, t) {
|
|
|
8827
8848
|
}
|
|
8828
8849
|
return r;
|
|
8829
8850
|
}
|
|
8830
|
-
async function
|
|
8851
|
+
async function nd(e) {
|
|
8831
8852
|
let t = e?.intervalS ?? 120, n = Ot(e?.dbPath), r = e?.keysDir, i = e?.signal, a = Nt(n), o = null;
|
|
8832
8853
|
try {
|
|
8833
8854
|
let [t] = qn(a, { keysDir: r });
|
|
8834
|
-
|
|
8855
|
+
ku() && e?.port && (o = Au(t, e.port));
|
|
8835
8856
|
} finally {
|
|
8836
8857
|
a.close();
|
|
8837
8858
|
}
|
|
@@ -8839,13 +8860,13 @@ async function Qu(e) {
|
|
|
8839
8860
|
o?.close();
|
|
8840
8861
|
return;
|
|
8841
8862
|
}
|
|
8842
|
-
if (await
|
|
8863
|
+
if (await rd(n, r), i?.aborted) {
|
|
8843
8864
|
o?.close();
|
|
8844
8865
|
return;
|
|
8845
8866
|
}
|
|
8846
8867
|
return new Promise((e) => {
|
|
8847
8868
|
let a = !1, s = setInterval(() => {
|
|
8848
|
-
a || (a = !0,
|
|
8869
|
+
a || (a = !0, rd(n, r).finally(() => {
|
|
8849
8870
|
a = !1;
|
|
8850
8871
|
}));
|
|
8851
8872
|
}, t * 1e3), c = () => {
|
|
@@ -8860,30 +8881,30 @@ async function Qu(e) {
|
|
|
8860
8881
|
}
|
|
8861
8882
|
});
|
|
8862
8883
|
}
|
|
8863
|
-
async function
|
|
8884
|
+
async function rd(e, t) {
|
|
8864
8885
|
let n = Nt(e);
|
|
8865
8886
|
try {
|
|
8866
|
-
await
|
|
8887
|
+
await td(n, t), $u(n);
|
|
8867
8888
|
} catch (e) {
|
|
8868
|
-
|
|
8889
|
+
ed(n, e instanceof Error ? e.message : String(e), e instanceof Error ? e.stack ?? "" : "");
|
|
8869
8890
|
} finally {
|
|
8870
8891
|
n.close();
|
|
8871
8892
|
}
|
|
8872
8893
|
}
|
|
8873
8894
|
//#endregion
|
|
8874
8895
|
//#region src/test-schema.generated.ts
|
|
8875
|
-
var ed = "CREATE TABLE IF NOT EXISTS `sessions` (\n `id` integer PRIMARY KEY NOT NULL,\n `started_at` text NOT NULL,\n `ended_at` text,\n `cwd` text,\n `project` text,\n `git_remote` text,\n `git_branch` text,\n `user` text,\n `tool_version` text,\n `metadata_json` text,\n `import_key` text\n);\n\nCREATE TABLE IF NOT EXISTS `artifacts` (\n `id` integer PRIMARY KEY NOT NULL,\n `session_id` integer NOT NULL,\n `kind` text NOT NULL,\n `path` text,\n `content_text` text,\n `content_hash` text,\n `created_at` text NOT NULL,\n `metadata_json` text,\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_artifacts_session_kind` ON `artifacts` (`session_id`,`kind`);\nCREATE TABLE IF NOT EXISTS `memory_items` (\n `id` integer PRIMARY KEY NOT NULL,\n `session_id` integer NOT NULL,\n `kind` text NOT NULL,\n `title` text NOT NULL,\n `subtitle` text,\n `body_text` text NOT NULL,\n `confidence` real DEFAULT 0.5,\n `tags_text` text DEFAULT '',\n `active` integer DEFAULT 1,\n `created_at` text NOT NULL,\n `updated_at` text NOT NULL,\n `metadata_json` text,\n `actor_id` text,\n `actor_display_name` text,\n `visibility` text,\n `workspace_id` text,\n `workspace_kind` text,\n `origin_device_id` text,\n `origin_source` text,\n `trust_state` text,\n `facts` text,\n `narrative` text,\n `concepts` text,\n `files_read` text,\n `files_modified` text,\n `user_prompt_id` integer,\n `prompt_number` integer,\n `deleted_at` text,\n `rev` integer DEFAULT 0,\n `import_key` text,\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_memory_items_active_created` ON `memory_items` (`active`,`created_at`);\nCREATE INDEX IF NOT EXISTS `idx_memory_items_session` ON `memory_items` (`session_id`);\nCREATE TABLE IF NOT EXISTS `usage_events` (\n `id` integer PRIMARY KEY NOT NULL,\n `session_id` integer,\n `event` text NOT NULL,\n `tokens_read` integer DEFAULT 0,\n `tokens_written` integer DEFAULT 0,\n `tokens_saved` integer DEFAULT 0,\n `created_at` text NOT NULL,\n `metadata_json` text,\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE set null\n);\n\nCREATE INDEX IF NOT EXISTS `idx_usage_events_event_created` ON `usage_events` (`event`,`created_at`);\nCREATE INDEX IF NOT EXISTS `idx_usage_events_session` ON `usage_events` (`session_id`);\nCREATE TABLE IF NOT EXISTS `raw_events` (\n `id` integer PRIMARY KEY NOT NULL,\n `source` text DEFAULT 'opencode' NOT NULL,\n `stream_id` text DEFAULT '' NOT NULL,\n `opencode_session_id` text NOT NULL,\n `event_id` text,\n `event_seq` integer NOT NULL,\n `event_type` text NOT NULL,\n `ts_wall_ms` integer,\n `ts_mono_ms` real,\n `payload_json` text NOT NULL,\n `created_at` text NOT NULL\n);\n\nCREATE UNIQUE INDEX IF NOT EXISTS `idx_raw_events_source_stream_seq` ON `raw_events` (`source`,`stream_id`,`event_seq`);\nCREATE UNIQUE INDEX IF NOT EXISTS `idx_raw_events_source_stream_event_id` ON `raw_events` (`source`,`stream_id`,`event_id`);\nCREATE INDEX IF NOT EXISTS `idx_raw_events_session_seq` ON `raw_events` (`opencode_session_id`,`event_seq`);\nCREATE INDEX IF NOT EXISTS `idx_raw_events_created` ON `raw_events` (`created_at`);\nCREATE TABLE IF NOT EXISTS `raw_event_sessions` (\n `source` text DEFAULT 'opencode' NOT NULL,\n `stream_id` text DEFAULT '' NOT NULL,\n `opencode_session_id` text NOT NULL,\n `cwd` text,\n `project` text,\n `started_at` text,\n `last_seen_ts_wall_ms` integer,\n `last_received_event_seq` integer DEFAULT -1 NOT NULL,\n `last_flushed_event_seq` integer DEFAULT -1 NOT NULL,\n `updated_at` text NOT NULL,\n PRIMARY KEY(`source`, `stream_id`)\n);\n\nCREATE TABLE IF NOT EXISTS `opencode_sessions` (\n `source` text DEFAULT 'opencode' NOT NULL,\n `stream_id` text DEFAULT '' NOT NULL,\n `opencode_session_id` text NOT NULL,\n `session_id` integer,\n `created_at` text NOT NULL,\n PRIMARY KEY(`source`, `stream_id`),\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_opencode_sessions_session` ON `opencode_sessions` (`session_id`);\nCREATE TABLE IF NOT EXISTS `raw_event_flush_batches` (\n `id` integer PRIMARY KEY NOT NULL,\n `source` text DEFAULT 'opencode' NOT NULL,\n `stream_id` text DEFAULT '' NOT NULL,\n `opencode_session_id` text NOT NULL,\n `start_event_seq` integer NOT NULL,\n `end_event_seq` integer NOT NULL,\n `extractor_version` text NOT NULL,\n `status` text NOT NULL,\n `error_message` text,\n `error_type` text,\n `observer_provider` text,\n `observer_model` text,\n `observer_runtime` text,\n `attempt_count` integer DEFAULT 0 NOT NULL,\n `created_at` text NOT NULL,\n `updated_at` text NOT NULL\n);\n\nCREATE UNIQUE INDEX IF NOT EXISTS `idx_flush_batches_source_stream_seq_ver` ON `raw_event_flush_batches` (`source`,`stream_id`,`start_event_seq`,`end_event_seq`,`extractor_version`);\nCREATE INDEX IF NOT EXISTS `idx_flush_batches_session_created` ON `raw_event_flush_batches` (`opencode_session_id`,`created_at`);\nCREATE INDEX IF NOT EXISTS `idx_flush_batches_status_updated` ON `raw_event_flush_batches` (`status`,`updated_at`);\nCREATE TABLE IF NOT EXISTS `user_prompts` (\n `id` integer PRIMARY KEY NOT NULL,\n `session_id` integer,\n `project` text,\n `prompt_text` text NOT NULL,\n `prompt_number` integer,\n `created_at` text NOT NULL,\n `created_at_epoch` integer NOT NULL,\n `metadata_json` text,\n `import_key` text,\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_user_prompts_session` ON `user_prompts` (`session_id`);\nCREATE INDEX IF NOT EXISTS `idx_user_prompts_project` ON `user_prompts` (`project`);\nCREATE INDEX IF NOT EXISTS `idx_user_prompts_epoch` ON `user_prompts` (`created_at_epoch`);\nCREATE TABLE IF NOT EXISTS `session_summaries` (\n `id` integer PRIMARY KEY NOT NULL,\n `session_id` integer,\n `project` text,\n `request` text,\n `investigated` text,\n `learned` text,\n `completed` text,\n `next_steps` text,\n `notes` text,\n `files_read` text,\n `files_edited` text,\n `prompt_number` integer,\n `created_at` text NOT NULL,\n `created_at_epoch` integer NOT NULL,\n `metadata_json` text,\n `import_key` text,\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_session_summaries_session` ON `session_summaries` (`session_id`);\nCREATE INDEX IF NOT EXISTS `idx_session_summaries_project` ON `session_summaries` (`project`);\nCREATE INDEX IF NOT EXISTS `idx_session_summaries_epoch` ON `session_summaries` (`created_at_epoch`);\nCREATE TABLE IF NOT EXISTS `replication_ops` (\n `op_id` text PRIMARY KEY NOT NULL,\n `entity_type` text NOT NULL,\n `entity_id` text NOT NULL,\n `op_type` text NOT NULL,\n `payload_json` text,\n `clock_rev` integer NOT NULL,\n `clock_updated_at` text NOT NULL,\n `clock_device_id` text NOT NULL,\n `device_id` text NOT NULL,\n `created_at` text NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS `idx_replication_ops_created` ON `replication_ops` (`created_at`,`op_id`);\nCREATE INDEX IF NOT EXISTS `idx_replication_ops_entity` ON `replication_ops` (`entity_type`,`entity_id`);\nCREATE TABLE IF NOT EXISTS `replication_cursors` (\n `peer_device_id` text PRIMARY KEY NOT NULL,\n `last_applied_cursor` text,\n `last_acked_cursor` text,\n `updated_at` text NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `sync_peers` (\n `peer_device_id` text PRIMARY KEY NOT NULL,\n `name` text,\n `pinned_fingerprint` text,\n `public_key` text,\n `addresses_json` text,\n `claimed_local_actor` integer DEFAULT 0 NOT NULL,\n `actor_id` text,\n `projects_include_json` text,\n `projects_exclude_json` text,\n `created_at` text NOT NULL,\n `last_seen_at` text,\n `last_sync_at` text,\n `last_error` text\n);\n\nCREATE TABLE IF NOT EXISTS `sync_nonces` (\n `nonce` text PRIMARY KEY NOT NULL,\n `device_id` text NOT NULL,\n `created_at` text NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `sync_device` (\n `device_id` text PRIMARY KEY NOT NULL,\n `public_key` text NOT NULL,\n `fingerprint` text NOT NULL,\n `created_at` text NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `sync_attempts` (\n `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,\n `peer_device_id` text NOT NULL,\n `started_at` text NOT NULL,\n `finished_at` text,\n `ok` integer NOT NULL,\n `ops_in` integer NOT NULL,\n `ops_out` integer NOT NULL,\n `error` text\n);\n\nCREATE INDEX IF NOT EXISTS `idx_sync_attempts_peer_started` ON `sync_attempts` (`peer_device_id`,`started_at`);\nCREATE TABLE IF NOT EXISTS `sync_daemon_state` (\n `id` integer PRIMARY KEY NOT NULL,\n `last_error` text,\n `last_traceback` text,\n `last_error_at` text,\n `last_ok_at` text\n);\n\nCREATE TABLE IF NOT EXISTS `raw_event_ingest_samples` (\n `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,\n `created_at` text NOT NULL,\n `inserted_events` integer DEFAULT 0 NOT NULL,\n `skipped_invalid` integer DEFAULT 0 NOT NULL,\n `skipped_duplicate` integer DEFAULT 0 NOT NULL,\n `skipped_conflict` integer DEFAULT 0 NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `raw_event_ingest_stats` (\n `id` integer PRIMARY KEY NOT NULL,\n `inserted_events` integer DEFAULT 0 NOT NULL,\n `skipped_events` integer DEFAULT 0 NOT NULL,\n `skipped_invalid` integer DEFAULT 0 NOT NULL,\n `skipped_duplicate` integer DEFAULT 0 NOT NULL,\n `skipped_conflict` integer DEFAULT 0 NOT NULL,\n `updated_at` text NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `actors` (\n `actor_id` text PRIMARY KEY NOT NULL,\n `display_name` text NOT NULL,\n `is_local` integer DEFAULT 0 NOT NULL,\n `status` text DEFAULT 'active' NOT NULL,\n `merged_into_actor_id` text,\n `created_at` text NOT NULL,\n `updated_at` text NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS `idx_actors_is_local` ON `actors` (`is_local`);\nCREATE INDEX IF NOT EXISTS `idx_actors_status` ON `actors` (`status`);", td = "\nCREATE INDEX IF NOT EXISTS idx_sync_peers_actor_id ON sync_peers(actor_id);\n\nCREATE VIRTUAL TABLE IF NOT EXISTS memory_fts USING fts5(\n title, body_text, tags_text,\n content='memory_items',\n content_rowid='id'\n);\n\nCREATE TRIGGER IF NOT EXISTS memory_items_ai AFTER INSERT ON memory_items BEGIN\n INSERT INTO memory_fts(rowid, title, body_text, tags_text)\n VALUES (new.id, new.title, new.body_text, new.tags_text);\nEND;\n\nDROP TRIGGER IF EXISTS memory_items_au;\nCREATE TRIGGER memory_items_au AFTER UPDATE ON memory_items BEGIN\n INSERT INTO memory_fts(memory_fts, rowid, title, body_text, tags_text)\n VALUES('delete', old.id, old.title, old.body_text, old.tags_text);\n INSERT INTO memory_fts(rowid, title, body_text, tags_text)\n VALUES (new.id, new.title, new.body_text, new.tags_text);\nEND;\n\nDROP TRIGGER IF EXISTS memory_items_ad;\nCREATE TRIGGER memory_items_ad AFTER DELETE ON memory_items BEGIN\n INSERT INTO memory_fts(memory_fts, rowid, title, body_text, tags_text)\n VALUES('delete', old.id, old.title, old.body_text, old.tags_text);\nEND;\n";
|
|
8876
|
-
function
|
|
8877
|
-
e.exec(
|
|
8896
|
+
var id = "CREATE TABLE IF NOT EXISTS `sessions` (\n `id` integer PRIMARY KEY NOT NULL,\n `started_at` text NOT NULL,\n `ended_at` text,\n `cwd` text,\n `project` text,\n `git_remote` text,\n `git_branch` text,\n `user` text,\n `tool_version` text,\n `metadata_json` text,\n `import_key` text\n);\n\nCREATE TABLE IF NOT EXISTS `artifacts` (\n `id` integer PRIMARY KEY NOT NULL,\n `session_id` integer NOT NULL,\n `kind` text NOT NULL,\n `path` text,\n `content_text` text,\n `content_hash` text,\n `created_at` text NOT NULL,\n `metadata_json` text,\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_artifacts_session_kind` ON `artifacts` (`session_id`,`kind`);\nCREATE TABLE IF NOT EXISTS `memory_items` (\n `id` integer PRIMARY KEY NOT NULL,\n `session_id` integer NOT NULL,\n `kind` text NOT NULL,\n `title` text NOT NULL,\n `subtitle` text,\n `body_text` text NOT NULL,\n `confidence` real DEFAULT 0.5,\n `tags_text` text DEFAULT '',\n `active` integer DEFAULT 1,\n `created_at` text NOT NULL,\n `updated_at` text NOT NULL,\n `metadata_json` text,\n `actor_id` text,\n `actor_display_name` text,\n `visibility` text,\n `workspace_id` text,\n `workspace_kind` text,\n `origin_device_id` text,\n `origin_source` text,\n `trust_state` text,\n `facts` text,\n `narrative` text,\n `concepts` text,\n `files_read` text,\n `files_modified` text,\n `user_prompt_id` integer,\n `prompt_number` integer,\n `deleted_at` text,\n `rev` integer DEFAULT 0,\n `import_key` text,\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_memory_items_active_created` ON `memory_items` (`active`,`created_at`);\nCREATE INDEX IF NOT EXISTS `idx_memory_items_session` ON `memory_items` (`session_id`);\nCREATE TABLE IF NOT EXISTS `usage_events` (\n `id` integer PRIMARY KEY NOT NULL,\n `session_id` integer,\n `event` text NOT NULL,\n `tokens_read` integer DEFAULT 0,\n `tokens_written` integer DEFAULT 0,\n `tokens_saved` integer DEFAULT 0,\n `created_at` text NOT NULL,\n `metadata_json` text,\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE set null\n);\n\nCREATE INDEX IF NOT EXISTS `idx_usage_events_event_created` ON `usage_events` (`event`,`created_at`);\nCREATE INDEX IF NOT EXISTS `idx_usage_events_session` ON `usage_events` (`session_id`);\nCREATE TABLE IF NOT EXISTS `raw_events` (\n `id` integer PRIMARY KEY NOT NULL,\n `source` text DEFAULT 'opencode' NOT NULL,\n `stream_id` text DEFAULT '' NOT NULL,\n `opencode_session_id` text NOT NULL,\n `event_id` text,\n `event_seq` integer NOT NULL,\n `event_type` text NOT NULL,\n `ts_wall_ms` integer,\n `ts_mono_ms` real,\n `payload_json` text NOT NULL,\n `created_at` text NOT NULL\n);\n\nCREATE UNIQUE INDEX IF NOT EXISTS `idx_raw_events_source_stream_seq` ON `raw_events` (`source`,`stream_id`,`event_seq`);\nCREATE UNIQUE INDEX IF NOT EXISTS `idx_raw_events_source_stream_event_id` ON `raw_events` (`source`,`stream_id`,`event_id`);\nCREATE INDEX IF NOT EXISTS `idx_raw_events_session_seq` ON `raw_events` (`opencode_session_id`,`event_seq`);\nCREATE INDEX IF NOT EXISTS `idx_raw_events_created` ON `raw_events` (`created_at`);\nCREATE TABLE IF NOT EXISTS `raw_event_sessions` (\n `source` text DEFAULT 'opencode' NOT NULL,\n `stream_id` text DEFAULT '' NOT NULL,\n `opencode_session_id` text NOT NULL,\n `cwd` text,\n `project` text,\n `started_at` text,\n `last_seen_ts_wall_ms` integer,\n `last_received_event_seq` integer DEFAULT -1 NOT NULL,\n `last_flushed_event_seq` integer DEFAULT -1 NOT NULL,\n `updated_at` text NOT NULL,\n PRIMARY KEY(`source`, `stream_id`)\n);\n\nCREATE TABLE IF NOT EXISTS `opencode_sessions` (\n `source` text DEFAULT 'opencode' NOT NULL,\n `stream_id` text DEFAULT '' NOT NULL,\n `opencode_session_id` text NOT NULL,\n `session_id` integer,\n `created_at` text NOT NULL,\n PRIMARY KEY(`source`, `stream_id`),\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_opencode_sessions_session` ON `opencode_sessions` (`session_id`);\nCREATE TABLE IF NOT EXISTS `raw_event_flush_batches` (\n `id` integer PRIMARY KEY NOT NULL,\n `source` text DEFAULT 'opencode' NOT NULL,\n `stream_id` text DEFAULT '' NOT NULL,\n `opencode_session_id` text NOT NULL,\n `start_event_seq` integer NOT NULL,\n `end_event_seq` integer NOT NULL,\n `extractor_version` text NOT NULL,\n `status` text NOT NULL,\n `error_message` text,\n `error_type` text,\n `observer_provider` text,\n `observer_model` text,\n `observer_runtime` text,\n `attempt_count` integer DEFAULT 0 NOT NULL,\n `created_at` text NOT NULL,\n `updated_at` text NOT NULL\n);\n\nCREATE UNIQUE INDEX IF NOT EXISTS `idx_flush_batches_source_stream_seq_ver` ON `raw_event_flush_batches` (`source`,`stream_id`,`start_event_seq`,`end_event_seq`,`extractor_version`);\nCREATE INDEX IF NOT EXISTS `idx_flush_batches_session_created` ON `raw_event_flush_batches` (`opencode_session_id`,`created_at`);\nCREATE INDEX IF NOT EXISTS `idx_flush_batches_status_updated` ON `raw_event_flush_batches` (`status`,`updated_at`);\nCREATE TABLE IF NOT EXISTS `user_prompts` (\n `id` integer PRIMARY KEY NOT NULL,\n `session_id` integer,\n `project` text,\n `prompt_text` text NOT NULL,\n `prompt_number` integer,\n `created_at` text NOT NULL,\n `created_at_epoch` integer NOT NULL,\n `metadata_json` text,\n `import_key` text,\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_user_prompts_session` ON `user_prompts` (`session_id`);\nCREATE INDEX IF NOT EXISTS `idx_user_prompts_project` ON `user_prompts` (`project`);\nCREATE INDEX IF NOT EXISTS `idx_user_prompts_epoch` ON `user_prompts` (`created_at_epoch`);\nCREATE TABLE IF NOT EXISTS `session_summaries` (\n `id` integer PRIMARY KEY NOT NULL,\n `session_id` integer,\n `project` text,\n `request` text,\n `investigated` text,\n `learned` text,\n `completed` text,\n `next_steps` text,\n `notes` text,\n `files_read` text,\n `files_edited` text,\n `prompt_number` integer,\n `created_at` text NOT NULL,\n `created_at_epoch` integer NOT NULL,\n `metadata_json` text,\n `import_key` text,\n FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE cascade\n);\n\nCREATE INDEX IF NOT EXISTS `idx_session_summaries_session` ON `session_summaries` (`session_id`);\nCREATE INDEX IF NOT EXISTS `idx_session_summaries_project` ON `session_summaries` (`project`);\nCREATE INDEX IF NOT EXISTS `idx_session_summaries_epoch` ON `session_summaries` (`created_at_epoch`);\nCREATE TABLE IF NOT EXISTS `replication_ops` (\n `op_id` text PRIMARY KEY NOT NULL,\n `entity_type` text NOT NULL,\n `entity_id` text NOT NULL,\n `op_type` text NOT NULL,\n `payload_json` text,\n `clock_rev` integer NOT NULL,\n `clock_updated_at` text NOT NULL,\n `clock_device_id` text NOT NULL,\n `device_id` text NOT NULL,\n `created_at` text NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS `idx_replication_ops_created` ON `replication_ops` (`created_at`,`op_id`);\nCREATE INDEX IF NOT EXISTS `idx_replication_ops_entity` ON `replication_ops` (`entity_type`,`entity_id`);\nCREATE TABLE IF NOT EXISTS `replication_cursors` (\n `peer_device_id` text PRIMARY KEY NOT NULL,\n `last_applied_cursor` text,\n `last_acked_cursor` text,\n `updated_at` text NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `sync_peers` (\n `peer_device_id` text PRIMARY KEY NOT NULL,\n `name` text,\n `pinned_fingerprint` text,\n `public_key` text,\n `addresses_json` text,\n `claimed_local_actor` integer DEFAULT 0 NOT NULL,\n `actor_id` text,\n `projects_include_json` text,\n `projects_exclude_json` text,\n `created_at` text NOT NULL,\n `last_seen_at` text,\n `last_sync_at` text,\n `last_error` text\n);\n\nCREATE TABLE IF NOT EXISTS `sync_nonces` (\n `nonce` text PRIMARY KEY NOT NULL,\n `device_id` text NOT NULL,\n `created_at` text NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `sync_device` (\n `device_id` text PRIMARY KEY NOT NULL,\n `public_key` text NOT NULL,\n `fingerprint` text NOT NULL,\n `created_at` text NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `sync_attempts` (\n `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,\n `peer_device_id` text NOT NULL,\n `started_at` text NOT NULL,\n `finished_at` text,\n `ok` integer NOT NULL,\n `ops_in` integer NOT NULL,\n `ops_out` integer NOT NULL,\n `error` text\n);\n\nCREATE INDEX IF NOT EXISTS `idx_sync_attempts_peer_started` ON `sync_attempts` (`peer_device_id`,`started_at`);\nCREATE TABLE IF NOT EXISTS `sync_daemon_state` (\n `id` integer PRIMARY KEY NOT NULL,\n `last_error` text,\n `last_traceback` text,\n `last_error_at` text,\n `last_ok_at` text\n);\n\nCREATE TABLE IF NOT EXISTS `raw_event_ingest_samples` (\n `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,\n `created_at` text NOT NULL,\n `inserted_events` integer DEFAULT 0 NOT NULL,\n `skipped_invalid` integer DEFAULT 0 NOT NULL,\n `skipped_duplicate` integer DEFAULT 0 NOT NULL,\n `skipped_conflict` integer DEFAULT 0 NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `raw_event_ingest_stats` (\n `id` integer PRIMARY KEY NOT NULL,\n `inserted_events` integer DEFAULT 0 NOT NULL,\n `skipped_events` integer DEFAULT 0 NOT NULL,\n `skipped_invalid` integer DEFAULT 0 NOT NULL,\n `skipped_duplicate` integer DEFAULT 0 NOT NULL,\n `skipped_conflict` integer DEFAULT 0 NOT NULL,\n `updated_at` text NOT NULL\n);\n\nCREATE TABLE IF NOT EXISTS `actors` (\n `actor_id` text PRIMARY KEY NOT NULL,\n `display_name` text NOT NULL,\n `is_local` integer DEFAULT 0 NOT NULL,\n `status` text DEFAULT 'active' NOT NULL,\n `merged_into_actor_id` text,\n `created_at` text NOT NULL,\n `updated_at` text NOT NULL\n);\n\nCREATE INDEX IF NOT EXISTS `idx_actors_is_local` ON `actors` (`is_local`);\nCREATE INDEX IF NOT EXISTS `idx_actors_status` ON `actors` (`status`);", ad = "\nCREATE INDEX IF NOT EXISTS idx_sync_peers_actor_id ON sync_peers(actor_id);\n\nCREATE VIRTUAL TABLE IF NOT EXISTS memory_fts USING fts5(\n title, body_text, tags_text,\n content='memory_items',\n content_rowid='id'\n);\n\nCREATE TRIGGER IF NOT EXISTS memory_items_ai AFTER INSERT ON memory_items BEGIN\n INSERT INTO memory_fts(rowid, title, body_text, tags_text)\n VALUES (new.id, new.title, new.body_text, new.tags_text);\nEND;\n\nDROP TRIGGER IF EXISTS memory_items_au;\nCREATE TRIGGER memory_items_au AFTER UPDATE ON memory_items BEGIN\n INSERT INTO memory_fts(memory_fts, rowid, title, body_text, tags_text)\n VALUES('delete', old.id, old.title, old.body_text, old.tags_text);\n INSERT INTO memory_fts(rowid, title, body_text, tags_text)\n VALUES (new.id, new.title, new.body_text, new.tags_text);\nEND;\n\nDROP TRIGGER IF EXISTS memory_items_ad;\nCREATE TRIGGER memory_items_ad AFTER DELETE ON memory_items BEGIN\n INSERT INTO memory_fts(memory_fts, rowid, title, body_text, tags_text)\n VALUES('delete', old.id, old.title, old.body_text, old.tags_text);\nEND;\n";
|
|
8897
|
+
function od(e) {
|
|
8898
|
+
e.exec(id), e.exec(ad), e.pragma("user_version = 6");
|
|
8878
8899
|
}
|
|
8879
|
-
function
|
|
8900
|
+
function sd(e) {
|
|
8880
8901
|
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");
|
|
8881
8902
|
return Number(n.lastInsertRowid);
|
|
8882
8903
|
}
|
|
8883
8904
|
//#endregion
|
|
8884
8905
|
//#region src/index.ts
|
|
8885
|
-
var
|
|
8906
|
+
var cd = "0.20.0-alpha.7";
|
|
8886
8907
|
//#endregion
|
|
8887
|
-
export { ge as Api, Qe as CODEMEM_CONFIG_ENV_OVERRIDES, z as CoordinatorStore, Be as DEFAULT_COORDINATOR_DB_PATH, Dt as DEFAULT_DB_PATH,
|
|
8908
|
+
export { ge as Api, Qe as CODEMEM_CONFIG_ENV_OVERRIDES, z as CoordinatorStore, Be as DEFAULT_COORDINATOR_DB_PATH, Dt as DEFAULT_DB_PATH, _u as DEFAULT_SERVICE_TYPE, di as DEFAULT_TIME_WINDOW_S, Ha as LOW_SIGNAL_TOOLS, ve as MAPPABLE_CLAUDE_HOOK_EVENTS, wt as MIN_COMPATIBLE_SCHEMA, gu as MemoryStore, hs as ObserverAuthAdapter, js as ObserverAuthError, qs as ObserverClient, Ol as RawEventSweeper, Ct as SCHEMA_VERSION, ui as SIGNATURE_VERSION, mo as TRIVIAL_REQUESTS, cd as VERSION, Xi as _resetEmbeddingClient, Ai as addressDedupeKey, Au as advertiseMdns, nu as applyReplicationOps, Rt as assertSchemaReady, $l as backfillReplicationOps, bn as backfillTagsText, Io as backfillVectors, Lt as backupOnFirstAccess, eo as budgetToolEvents, gi as buildAuthHeaders, Tn as buildBaseUrl, fi as buildCanonicalRequest, us as buildCodexHeaders, Da as buildFilterClauses, Oa as buildFilterClausesWithContext, sa as buildImportKey, Fe as buildIngestPayloadFromHook, _l as buildMemoryPack, vl as buildMemoryPackAsync, po as buildObserverPrompt, Pe as buildRawEventEnvelopeFromHook, Cl as buildSessionContext, yo as buildTranscript, kl as chunkOpsBySize, Ji as chunkText, Go as cleanOrphanSessions, vi as cleanupNonces, Pl as clockTuple, Nt as connect, qe as connectCoordinator, Xu as consecutiveConnectivityFailures, Zn as coordinatorCreateInviteAction, Vi as coordinatorEnabled, Qn as coordinatorImportInviteAction, $n as coordinatorListJoinRequestsAction, er as coordinatorReviewJoinRequestAction, Gi as coordinatorStatusSnapshot, Di as createCoordinatorApp, Fu as cursorAdvances, wn as deactivateLowSignalMemories, Cn as deactivateLowSignalObservations, Le as decodeInvitePayload, Mc as dedupeOrderedIds, vo as deriveRequest, ju as discoverPeersViaMdns, Qi as embedTexts, Ie as encodeInvitePayload, qn as ensureDeviceIdentity, Vc as estimateTokens, qa as eventToToolEvent, oc as expandQuery, Ic as explain, pa as exportMemories, Ya as extractAdapterEvent, bo as extractAssistantMessages, xo as extractAssistantUsage, ze as extractInvitePayload, as as extractOAuthAccess, cs as extractOAuthAccountId, ls as extractOAuthExpires, So as extractPrompts, os as extractProviderApiKey, Nl as extractReplicationOps, Ja as extractToolEvents, Xl as filterReplicationOpsForSync, Yl as filterReplicationOpsForSyncWithStatus, jn as fingerprintPublicKey, _o as firstSentence, wl as flushRawEvents, B as fromJson, Bt as fromJsonStrict, Un as generateKeypair, $e as getCodememConfigPath, nt as getCodememEnvOverrides, Zi as getEmbeddingClient, it as getOpenCodeProviderConfig, bt as getProviderApiKey, vt as getProviderBaseUrl, yt as getProviderHeaders, _t as getProviderOptions, fn as getRawEventStatus, pn as getReliabilityMetrics, Al as getReplicationCursor, It as getSchemaVersion, Po as hasMeaningfulObservation, qi as hashText, xa as importMemories, Uo as ingest, Ko as ingestMain, un as initDatabase, od as initTestSchema, sd as insertTestSession, Re as inviteLink, Yu as isConnectivityError, Ft as isEmbeddingDisabled, Ua as isInternalMemoryTool, Ut as isLowSignalObservation, Fl as isNewerClock, Fa as isSensitiveFieldName, go as isTrivialRequest, cc as kindBonus, ct as listConfiguredOpenCodeProviders, Ki as listCoordinatorJoinRequests, at as listCustomProviders, lt as listObserverProviderOptions, As as loadObserverConfig, Xe as loadOpenCodeConfig, ns as loadOpenCodeOAuthCache, yu as loadPeerAddresses, zn as loadPrivateKey, In as loadPrivateKeyKeychain, Rn as loadPublicKey, zl as loadReplicationOpsSince, Pt as loadSqliteVec, Wi as lookupCoordinatorPeers, Me as mapClaudeHookPayload, Mu as mdnsAddressesForPeer, ku as mdnsEnabled, ji as mergeAddresses, ca as mergeSummaryMetadata, Mt as migrateLegacyDbPath, Ql as migrateLegacyImportKeys, Co as normalizeAdapterEvents, ki as normalizeAddress, Ht as normalizeObservation, Ce as normalizeProjectLabel, ho as normalizeRequestText, Wa as normalizeToolName, No as parseObserverResponse, Xo as parsePositiveMemoryId, Yo as parseStrictInteger, Zu as peerBackoffSeconds, ss as probeAvailableCredentials, Xa as projectAdapterToolEvent, Wt as projectBasename, Kt as projectClause, Gt as projectColumnClause, qt as projectMatchesFilter, mn as rawEventsGate, fs as readAuthFile, et as readCodememConfigFile, Bi as readCoordinatorSyncConfig, ma as readImportPayload, sc as recencyScore, _i as recordNonce, Su as recordPeerSuccess, Il as recordReplicationOp, xu as recordSyncAttempt, $o as redactText, Ui as registerCoordinatorPresence, ys as renderObserverHeaders, En as requestJson, Dc as rerankResults, dt as resolveBuiltInProviderDefaultModel, ut as resolveBuiltInProviderFromModel, ft as resolveBuiltInProviderModel, xt as resolveCustomProviderDefaultModel, pt as resolveCustomProviderFromModel, St as resolveCustomProviderModel, Ot as resolveDbPath, Ee as resolveHookProject, Ln as resolveKeyPaths, rs as resolveOAuthProvider, mt as resolvePlaceholder, Yt as resolveProject, hn as retryRawEventFailures, ds as runAuthCommand, nd as runSyncDaemon, Gu as runSyncPass, Ra as sanitizePayload, Va as sanitizeToolOutput, U as schema, Oc as search, vu as selectDialAddresses, Lo as semanticSearch, ea as serializeFloat32, wu as setPeerLocalActorClaim, Cu as setPeerProjectFilter, jl as setReplicationCursor, ed as setSyncDaemonError, $u as setSyncDaemonOk, Qu as shouldSkipOfflinePeer, pi as signRequest, Fn as storePrivateKeyKeychain, Fo as storeVectors, Je as stripJsonComments, Ma as stripPrivate, Ia as stripPrivateObj, Ye as stripTrailingCommas, td as syncDaemonTick, Wu as syncOnce, Uu as syncPassPreflight, zt as tableExists, Ac as timeline, V as toJson, H as toJsonNullable, bu as updatePeerAddresses, dn as vacuumDatabase, Kn as validateExistingKeypair, mi as verifySignature, tt as writeCodememConfigFile };
|
|
8888
8909
|
|
|
8889
8910
|
//# sourceMappingURL=index.js.map
|